Skip to content

Commit

Permalink
its work)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodluckhf committed Dec 10, 2015
1 parent f92aec7 commit 344bb04
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 37 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ <h4>
</li>
<li>

<button class="btn btn-primary saveConfig" >Сохранить</button>
<center><button class="btn btn-primary saveConfig" >Сохранить</button></center>

</li>

Expand Down
3 changes: 2 additions & 1 deletion js/PostProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var PostProvider = (new function() {
this.startDate = data.startDate;
this.currentDate = data.startDate;
this.dateInterval = data.interval || 30;
this.publicId = data.publicId || 'meal4real';
this.publicId = data.publicId || -107952301;

}

Expand All @@ -37,6 +37,7 @@ var PostProvider = (new function() {
return Request.send(data).done(function(r) {
if(r.response) {
console.log(r.response);
me.inc();
}
else {
toastr["error"]('Что-то пошло не так!', 'Ой');
Expand Down
43 changes: 20 additions & 23 deletions js/Posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,26 @@ var Posts = function(group) {
containerSelector = App.contentSelector;

$(containerSelector).on('click', '.accept-post', function(e) {
//console.log($(this).data());
var $this = $(this);
var block = $this.parents('.box-widget');
me.loadingBlock(block);

// при загрузки другой группы событие срабатывает 2 раза
var $this = $(this);

var key = $this.data('id');
//console.log(e);
console.log(posts[key]);
//return;
// var attachments = posts[key].attachments;
// var attachAr = [];
// for(var i in attachments) {
// attachAr.push(getVkatachment(attachments[i].photo));
// }

// Request.send({
// url: '/upload.php',
// data: {
// post: posts[key],
// group_id: PostProvider.publicId,
// publish_date: $('.date-picker').data('DateTimePicker').date().unix()
// }
// }).done(function(data) {
// console.log(data);
// });
//
// return;
console.log(posts[key]);

PostProvider.post({
post: posts[key]
}).done(function(data) {
if(data.response) {
toastr["success"]("Пост отправлен!", 'Ура');
$this.parents('.box-widget').fadeOut();
block.fadeOut();
}
else {
toastr["error"]('Что-то пошло не так!', 'Ой');
block.find('.ajax-loader').remove();
}
});

Expand Down Expand Up @@ -158,4 +142,17 @@ var Posts = function(group) {

return time;
}
this.loadingBlock = function (block) {
var $block = $(block);
var div = $('<div class="ajax-loader" style="position:absolute; background-color:rgba(255,255,255,0.8); z-index:10;"><center><img src="/img/ajax-loader.gif"></center></div>');

div.width($block.width());
div.height($block.height());
div.position().left = $block.position().left;
div.position().top = $block.position().top;

$block.prepend(div);

div.find('img').css({'margin-top': div.height() / 2 - 25 + 'px'});
}
}
6 changes: 3 additions & 3 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ $(function () {
bootbox.hideAll();
$('.date-picker').datetimepicker({
locale: 'ru',
stepping: 1,
stepping: 5,
toolbarPlacement: 'bottom'
//sideBySide: true
});
$('.saveConfig').click(function() {
PostProvider.start({
startDate: $('.date-picker').data('DateTimePicker').date().unix(),
dateInterval: 45,
publicId : -107952301,
interval: 45,
publicId : -77686561,
});
});

Expand Down
55 changes: 46 additions & 9 deletions upload.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class VkApi {
const IMG_DIR = __DIR__ . '/vk-images/';
const API_URL = 'https://api.vk.com/method/';

//private $uploadUrl;
private $uploadServer;
private $token;
private $groupId;
private $userId;
Expand Down Expand Up @@ -97,10 +97,13 @@ public function callApi($method, $data, $httpMethod = 'get') {
}

public function getUploadServer() {
return $this->callApi('photos.getWallUploadServer', [
'group_id' => $this->groupId * (-1),
'access_token' => $this->token,
]);
if(!isset($this->uploadServer)) {
$this->uploadServer = $this->callApi('photos.getWallUploadServer', [
'group_id' => $this->groupId * (-1),
'access_token' => $this->token,
]);
}
return $this->uploadServer;
}

public function sendImgs($uploadUrl, $imgs) {
Expand All @@ -120,6 +123,7 @@ public function sendImgs($uploadUrl, $imgs) {
public function curlPost() {
$photos = $this->post['attachments'];
$imgs = [];
$resultPhotoResponse = [];
foreach($photos as $key => $photo) {
if($photo['type'] != 'photo') {
continue;
Expand All @@ -129,8 +133,39 @@ public function curlPost() {
$imgs['file' . ($key + 1) ] = curl_file_create($imgFile, 'image/jpeg','test_name.jpg');
}
$uploadResult = $this->getUploadServer();
$result = $this->sendImgs($uploadResult['response']['upload_url'], $imgs);
return $result;
// PR($imgs);
// die();
if(count($imgs) > 6) {
$firstImgs = [];
$lastImgs = [];

$i = 1;
foreach($imgs as $key => $val) {
if($i <= 6) {
$firstImgs[$key] = $val;
}
else if($i > 6) {
$lastImgs['file' . ($i - 6)] = $val;
}
$i++;
}
$result = $this->sendImgs($uploadResult['response']['upload_url'], $firstImgs);
$photosResponse1 = $this->saveWallPhoto($result['photo'], $result['server'], $result['hash']);
// PR([$firstImgs, $lastImgs]);
// die();
$result2 = $this->sendImgs($uploadResult['response']['upload_url'], $lastImgs);
$photosResponse2 = $this->saveWallPhoto($result2['photo'], $result2['server'], $result2['hash']);
// PR([$photosResponse1, $photosResponse2]);
// die();
$resultPhotoResponseList = array_merge($photosResponse1['response'], $photosResponse2['response']);
$resultPhotoResponse['response'] = $resultPhotoResponseList;
}
else {
$result = $this->sendImgs($uploadResult['response']['upload_url'], $imgs);
$resultPhotoResponse = $this->saveWallPhoto($result['photo'], $result['server'], $result['hash']);
}

return $resultPhotoResponse;
}

public function saveWallPhoto($photo, $server, $hash) {
Expand Down Expand Up @@ -170,8 +205,10 @@ public function getPhotosByResponse($response) {
$vk = new VkApi($_COOKIE['vk-token'], $_REQUEST['group_id'], $_COOKIE['vk-user-id']);
$vk->setPost($_REQUEST['post']);
$result = $vk->curlPost();
$photosResponse = $vk->saveWallPhoto($result['photo'], $result['server'], $result['hash']);
$resPost = $vk->post($_REQUEST['publish_date'], $vk->getPhotosByResponse($photosResponse));
// PR($result);
// die();
//$photosResponse = $vk->saveWallPhoto($result['photo'], $result['server'], $result['hash']);
$resPost = $vk->post($_REQUEST['publish_date'], $vk->getPhotosByResponse($result));
echo json_encode($resPost);

die();
Expand Down
Binary file removed vk-images/img-1-0a285eed9288b3a3b51e00e1d4eb271d.jpg
Binary file not shown.
Binary file not shown.
Binary file removed vk-images/img-2-1216ffa955bc5b8204854e8d07275b70.jpg
Binary file not shown.
Binary file removed vk-images/img-2-d3a5a0affac00a1b108b95fffadf840a.jpg
Binary file not shown.
Binary file removed vk-images/img-3-4325f4203278dec18d0349b0c92ce089.jpg
Binary file not shown.
Binary file removed vk-images/img-3-b8f0751e59043f2e1b673be2bf4d5565.jpg
Binary file not shown.
Binary file removed vk-images/img-4-824a55ffd3de55f37c63690880eb2565.jpg
Binary file not shown.
Binary file removed vk-images/img-5-5f0817b77737fae13ee047ad53050859.jpg
Binary file not shown.
Binary file removed vk-images/img-6-50fadb04ecc6b9fb96710db825f22ec7.jpg
Binary file not shown.

0 comments on commit 344bb04

Please sign in to comment.