Advertisement
Guest User

Untitled

a guest
Jan 6th, 2019
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.99 KB | None | 0 0
  1. <?php
  2.  
  3.     //header('Content-type: image/jpg');
  4.     require_once('conf.php');
  5.  
  6. use VK\Client\VKApiClient;
  7.  
  8. $flag_draw_user = 0;
  9.  
  10. //$image->readImage('/images/cover/cover_orig.jpg');
  11. //$image->thumbnailImage(795, 0);
  12.  
  13. //Настройки для чисел (комменты и смартфоны)
  14. //$draw->setFillColor('white');
  15. //$draw->setFont('Roboto-Medium.ttf');
  16. //$draw->setFontSize( 29 );
  17. $draw = new ImagickDraw();
  18.  
  19. $draw->setFillColor('white');
  20. $draw->setFont(__DIR__.'/ttf/CalibriB.ttf');
  21. $draw->setFontSize(37);
  22.  
  23. $vk = new VKApiClient();
  24. if (htmlspecialchars($_GET['pass']) == md5('pass:Zhjckfd12')
  25.     && htmlspecialchars($_GET['task']) == "upd_count") {
  26.         $posts = $vk->wall()->get($token_ser, array(
  27.         'owner_id' => '-73015740',
  28.         'offset' => '0',
  29.         'count' => '1',
  30.         'extended' => '0',
  31.         'v' => '5.92',
  32.         ));
  33.     $cc = $posts['count']; //Количество записей
  34. }
  35.  
  36. if (htmlspecialchars($_GET['pass']) == md5('pass:Zhjckfd12')
  37.     && htmlspecialchars($_GET['task']) == "new_user") {
  38.     $userId = htmlspecialchars($_GET['id']);
  39.     $query = "SELECT n, id, time FROM followers WHERE id = $userId";
  40.     $result = mysqli_query($link, $query);
  41.     $flag = 1;
  42.     if ($result) {
  43.         //file_put_contents("oo.txt", "$userId");
  44.         while ($row = mysqli_fetch_row($result)) {
  45.             $n = $row[0];
  46.             $flag = 0;
  47.         }
  48.  
  49.         mysqli_free_result($result);
  50.     }
  51.  
  52.     if($flag == 1) {
  53.         $user = $vk->users()->get($token_ser, array(
  54.             'user_ids' => $userId,
  55.             'lang' => 'ru',
  56.             'fields' => 'crop_photo, photo_max, first_name_nom, last_name_nom, photo_604',
  57.             'v' => '5.92',
  58.         ));
  59.         //Add to database
  60.         $time = time();
  61.         $query = "INSERT INTO `groups.workjob_ufa`.`followers` (`id`, `time`) VALUES ($userId, $time);";
  62.         $result = mysqli_query($link, $query);
  63.  
  64.         $user = $user[0];
  65.         $firstname = $user['first_name_nom'];
  66.         $lastname = $user['last_name_nom'];
  67.  
  68.         if (strlen($firstname) <= 14 && strlen($lastname) <= 14) {
  69.  
  70.             $crop_photo = $user['crop_photo'];
  71.             $crop = $crop_photo['crop'];
  72.             $crop_x = $crop['x'];
  73.             $crop_y = $crop['y'];
  74.             $crop_x2 = $crop['x2'];
  75.             $crop_y2 = $crop['y2'];
  76.             $rect = $crop_photo['rect'];
  77.             $rect_x = $rect['x'];
  78.             $rect_y = $rect['y'];
  79.             $rect_x2 = $rect['x2'];
  80.             $rect_y2 = $rect['y2'];
  81.             $photo_url = $user['photo_max'];
  82. //        $photo = $crop_photo['photo'];
  83. //        $photoId = $photo['id'];
  84. //        $photo_src = $vk->photos()->getById($token_ser, array(
  85. //            'photos' => $photoId,
  86. //            'extended' => '0',
  87. //            'photo_sizes' => '0',
  88. //            'v' => '5.92',
  89. //        ));
  90.             require(__DIR__ . '/nano.php');
  91.             if ($nsfw_label == 'NSFW' && $nsfw_probability < 0.6 || $nsfw_label == 'SFW' && $nsfw_probability > 0.5) {
  92.                 $host = __DIR__ . "/images/cover/user.jpg";
  93.                 copy($photo_url, $host);
  94.                 chmod($host, 0777);
  95.  
  96.                 //Рисуем аватарку и имя
  97.                 $image = new Imagick(__DIR__ . "/images/cover/cover_orig2.jpg");
  98.                 $imageUser = new Imagick($host);
  99.  
  100.                 //Уменьшаем картинку и закругляем углы
  101.                 $imageUser->thumbnailImage(110, 110);
  102.                 $imageUser->roundCorners(110, 110);
  103.                 $image->compositeImage($imageUser, Imagick::COMPOSITE_DEFAULT, 655, 200);
  104.  
  105.                 $draw->setTextAlignment(\Imagick::ALIGN_CENTER);
  106.                 if (strlen($firstname) > 9 || strlen($lastname) > 9) $px = 809;
  107.                 $image->annotateImage($draw, 890, 250, 0, "$firstname");
  108.                 $image->annotateImage($draw, 890, 289, 0, "$lastname");
  109.  
  110.  
  111.                 $image->writeImage(__DIR__ . '/images/cover/cover_user.jpg');
  112.                
  113.             }
  114.         }
  115.     }
  116. }
  117. //Количество объявлений из бд
  118. $query = "SELECT count FROM wall_count WHERE n = 1";
  119. $result = mysqli_query($link, $query);
  120. if ($result) {
  121.     //file_put_contents("oo.txt",time());
  122.     while ($row = mysqli_fetch_row($result)) {
  123.         $count = $row[0];
  124.     }
  125.     mysqli_free_result($result);
  126. }
  127. //Рисуем дату и числа
  128. $image = new Imagick(__DIR__."/images/cover/cover_user.jpg");
  129.  
  130. setlocale(LC_ALL, 'ru_RU.UTF-8');
  131. $date = time() + 3*3600;
  132. $month = strftime("%B", $date);
  133. $day = date('d', $date);
  134. $hour = date('H', $date);
  135. $minute = date('i', $date);
  136.  
  137. $draw->setTextAlignment(\Imagick::ALIGN_LEFT);
  138. $draw->setFontSize(35);
  139. $image->annotateImage($draw, 1197, 325, 0, "$count");
  140.  
  141. $draw->setFontSize(50);
  142. $image->annotateImage($draw, 1169, 210, 0, "$hour:$minute");
  143.  
  144.  
  145. $draw->setTextAlignment(\Imagick::ALIGN_CENTER);
  146. $draw->setFontSize(33);
  147. $image->annotateImage($draw, 1230, 160, 0, "$month, $day");
  148. $image->writeImage(__DIR__.'/images/cover/cover_upload.jpg');
  149.  
  150. //Получение ссылки и загрузка изображения       
  151.  
  152.     $cover_path = dirname(__FILE__).'/images/cover/cover_upload.jpg';
  153.    
  154.    
  155.    
  156.     $post = array('photo' => new CURLFile($cover_path, 'image/jpeg', 'image0'));
  157. $upload = $vk->photos()->getOwnerCoverPhotoUploadServer($token, array(
  158.     'group_id' => $GroupId,
  159.     'crop_x2' => '1590',
  160.     'v' => '5.92',
  161.     ));
  162.  
  163.  
  164. $url = $upload['upload_url'];
  165.  
  166.     $ch = curl_init();
  167. curl_setopt($ch, CURLOPT_URL, $url);
  168. curl_setopt($ch, CURLOPT_POST, true);
  169. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  170. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  171. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  172. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  173. $result = json_decode(curl_exec($ch),true);
  174.  
  175. //Сохранение обложки
  176.  
  177. $save = $vk->photos()->saveOwnerCoverPhoto($token, array(
  178.     'hash' => $result['hash'],
  179.     'photo' => $result['photo'],
  180.     'v' => '5.92',
  181.     ));
  182. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement