예제 #1
0
 /**
  * @param $aid
  * @return \Response
  * @throws \Exception
  */
 public function loadAudio($aid)
 {
     $attachment = Attachment::findOrFail($aid);
     $response = Vk::call('audio.getById', ['audios' => $attachment->external_id]);
     $audio = reset($response['response']);
     return response()->json(['url' => $audio['url']]);
 }
예제 #2
0
파일: Review.php 프로젝트: stcoder/uf-vova
 /**
  * @param array $userIds
  * @return mixed
  * @throws \Exception
  */
 public static function getUsers(array $userIds)
 {
     $response = Vk::call('users.get', ['user_ids' => $userIds, 'fields' => 'first_name,last_name,deactivated,photo_200_orig,photo_400_orig,domain']);
     $response = $response['response'];
     $users = array_values(array_filter($response, function ($user) {
         return !isset($user['deactivated']);
     }));
     return $users;
 }
예제 #3
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     setlocale(LC_ALL, 'ru_RU.UTF-8');
     Carbon::setLocale(config('app.locale'));
     \Shortcode::register('slider', '\\App\\Shortcode\\Slider');
     \Shortcode::register('section', '\\App\\Shortcode\\Section');
     \Shortcode::register('iframe', '\\App\\Shortcode\\Iframe');
     \Shortcode::register('timeline', '\\App\\Shortcode\\Timeline');
     if (\DB::getDoctrineSchemaManager()->tablesExist('options')) {
         Option::observe(new OptionObserver());
         if (Option::has('vk-user-token')) {
             Vk::setAccessToken(Option::get('vk-user-token'));
         }
     }
 }
예제 #4
0
 /**
  * @param $topic_id
  * @return mixed
  * @throws \Exception
  */
 public function boardTopicSet($topic_id)
 {
     $response = Vk::call('board.getComments', ['group_id' => Option::get('vk-group-id'), 'topic_id' => $topic_id, 'count' => 0]);
     $comments = $response['response']['comments'][0];
     Option::set('vk-board-topic-id', $topic_id);
     Option::set('vk-board-integrated-date', time());
     Option::set('vk-reviews-count', $comments);
     Session::flash('flash_message', 'vk-board-topic-integrated');
     Session::flash('flash_type', 'success');
     return redirect(route('admin.integration'));
 }
예제 #5
0
파일: Post.php 프로젝트: stcoder/uf-vova
 /**
  * @param $data
  */
 protected static function __albumLoadPhotos(&$data)
 {
     list($owner_id, $album_id) = explode('_', $data['id']);
     if (!isset($owner_id) && empty($owner_id) && !isset($album_id) && empty($album_id)) {
         throw new InvalidArgumentException('Не удалось получить идентификатор альбома');
     }
     $response = Vk::call('photos.get', ['owner_id' => $owner_id, 'album_id' => $album_id]);
     $response = $response['response'];
     $photos = [];
     foreach ($response as $photo) {
         $photos[] = self::_prepareAttachment(['type' => 'photo', 'photo' => $photo]);
     }
     $data['photos'] = $photos;
 }
예제 #6
0
파일: Imports.php 프로젝트: stcoder/uf-vova
 /**
  * @param array $attachmentsRaw
  * @return array
  */
 public function __attachmentsPost($attachmentsRaw)
 {
     $attachments = [];
     $videoIds = [];
     $albumIds = [];
     $attachmentsRaw = array_map(function ($attachmentRaw) use(&$videoIds, &$albumIds) {
         $id = null;
         $title = '';
         $description = '';
         $srcs = '';
         $date = null;
         $access_key = '';
         switch ($attachmentRaw['type']) {
             case 'photo':
                 $id = sprintf('%s_%s', $attachmentRaw['photo']['owner_id'], $attachmentRaw['photo']['pid']);
                 $access_key = $attachmentRaw['photo']['access_key'];
                 $date = $attachmentRaw['photo']['created'];
                 $description = $attachmentRaw['photo']['text'];
                 $srcs = ['src' => $attachmentRaw['photo']['src'], 'src_big' => $attachmentRaw['photo']['src_big']];
                 break;
             case 'video':
                 $id = sprintf('%s_%s', $attachmentRaw['video']['owner_id'], $attachmentRaw['video']['vid']);
                 $access_key = $attachmentRaw['video']['access_key'];
                 $date = $attachmentRaw['video']['date'];
                 $title = $attachmentRaw['video']['title'];
                 $description = $attachmentRaw['video']['description'];
                 $srcs = ['image' => $attachmentRaw['video']['image'], 'image_big' => $attachmentRaw['video']['image_big']];
                 array_push($videoIds, $id . '_' . $access_key);
                 break;
             case 'audio':
                 $id = sprintf('%s_%s', $attachmentRaw['audio']['owner_id'], $attachmentRaw['audio']['aid']);
                 $title = $attachmentRaw['audio']['artist'];
                 $description = $attachmentRaw['audio']['title'];
                 $srcs = ['url' => $attachmentRaw['audio']['url'], 'duration' => $attachmentRaw['audio']['duration']];
                 break;
             case 'album':
                 $id = sprintf('%s_%s', $attachmentRaw['album']['owner_id'], $attachmentRaw['album']['aid']);
                 $title = $attachmentRaw['album']['title'];
                 $description = $attachmentRaw['album']['description'];
                 $date = $attachmentRaw['album']['created'];
                 $srcs = ['updated' => $attachmentRaw['album']['updated'], 'thumb' => ['src' => $attachmentRaw['album']['thumb']['src'], 'src_big' => $attachmentRaw['album']['thumb']['src_big']]];
                 array_push($albumIds, $id);
                 break;
         }
         if (is_null($id)) {
             return null;
         }
         return ['id' => $id, 'type' => $attachmentRaw['type'], 'title' => $title, 'description' => $description, 'date' => $date, 'srcs' => $srcs, 'access_key' => $access_key];
     }, $attachmentsRaw);
     if (sizeof($videoIds) > 0) {
         $videosResponse = Vk::call('video.get', ['videos' => implode(',', $videoIds)]);
         $videos = array_slice($videosResponse['response'], 1);
         foreach ($videos as $video) {
             $id = $video['owner_id'] . '_' . $video['vid'];
             $index = array_search($id, array_column($attachmentsRaw, 'id'));
             if (is_bool($index) && $index === false) {
                 continue;
             }
             $attachmentsRaw[$index]['srcs']['player'] = $video['player'];
         }
     }
     if (sizeof($albumIds) > 0) {
         foreach ($albumIds as $albumId) {
             $part = explode('_', $albumId);
             $owner_id = $part[0];
             $album_id = $part[1];
             $index = array_search($albumId, array_column($attachmentsRaw, 'id'));
             if (is_bool($index) && $index === false) {
                 continue;
             }
             $photosResponse = Vk::call('photos.get', ['owner_id' => $owner_id, 'album_id' => $album_id]);
             $photos = array_slice($photosResponse['response'], 1);
             $normalizePhotos = [];
             foreach ($photos as $photo) {
                 $normalizePhotos[] = ['external_id' => $photo['owner_id'] . '_' . $photo['pid'], 'srcs' => ['src' => $photo['src'], 'src_big' => $photo['src_big']], 'description' => $photo['text']];
             }
             $attachmentsRaw[$index]['photos'] = $normalizePhotos;
         }
     }
     $attachments = array_map(function ($attachmentRaw) {
         if (is_null($attachmentRaw)) {
             return null;
         }
         $attachmentRaw['external_id'] = $attachmentRaw['id'];
         unset($attachmentRaw['id']);
         $attachment = Attachment::firstOrNew(['external_id' => $attachmentRaw['external_id'], 'type' => $attachmentRaw['type']]);
         $attachment->access_key = $attachmentRaw['access_key'];
         $attachment->title = $attachmentRaw['title'];
         $attachment->description = $attachmentRaw['description'];
         $attachment->srcs = $attachmentRaw['srcs'];
         $attachment->save();
         if ($attachmentRaw['type'] === 'album' && isset($attachmentRaw['photos']) && sizeof($attachmentRaw['photos']) > 0) {
             $photoIds = [];
             foreach ($attachmentRaw['photos'] as $photo) {
                 $attachmentPhoto = Attachment::firstOrNew(['external_id' => $photo['external_id']]);
                 $attachmentPhoto->description = $photo['description'];
                 $attachmentPhoto->srcs = $photo['srcs'];
                 $attachmentPhoto->save();
                 array_push($photoIds, $attachmentPhoto->id);
             }
             if (sizeof($photoIds) > 0) {
                 $attachment->childs()->sync($photoIds, false);
             }
         }
         return $attachment->id;
     }, $attachmentsRaw);
     $attachments = array_filter($attachments, function ($attachment) {
         return !is_null($attachment);
     });
     return $attachments;
 }