Esempio n. 1
0
 public function getVideoUrl()
 {
     $content = perfectUnserialize($this->entity->type_content);
     if (!empty($content)) {
         $link = $content[0];
         $youTube = parseYouTube($link);
         if (\Config::get('enable-https', false)) {
             $youTube = str_replace('http://', 'https://', $youTube);
         }
         if (!empty($youTube)) {
             return $youTube;
         }
         $vimeoURL = parseVimeo($link);
         if (\Config::get('enable-https', false)) {
             $vimeoURL = str_replace('http://', 'https://', $vimeoURL);
         }
         if (!empty($vimeoURL)) {
             return $vimeoURL;
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Method to add post
  *
  * @param array $val
  * @param \App\Models\User $user
  * @return \App\Models\Post
  */
 public function add($val, $user = null)
 {
     $expected = ['text' => '', 'content_type' => '', 'type_content' => [], 'to_userid' => '', 'type' => '', 'type_id' => '', 'community_id' => '', 'page_id' => '', 'privacy' => 2, 'tags' => [], 'link_title', 'link_description', 'link_image', 'the_link', 'video_path' => '', 'auto_like_id' => '', 'file_path' => '', 'file_path_name' => ''];
     $user = empty($user) ? \Auth::user() : $user;
     $CDNRepository = app('App\\Repositories\\CDNRepository');
     /**
      * @var $text
      * @var $content_type
      * @var $to_userid
      * @var $type
      * @var $type_id
      * @var $community_id
      * @var $page_id
      * @var $type_content
      * @var $image
      * @var $privacy
      * @var $tags
      * @var $link_title
      * @var $link_description
      * @var $link_image,
      * @var $the_link
      * @var $video_path
      * @var $auto_like_id
      * @var $file_path
      * @var $file_path_name
      */
     extract($val = array_merge($expected, $val));
     //we need to make sure that if its page, user is page owner
     if ($page_id) {
         $page = app('App\\Repositories\\EventRepository')->get($page_id);
         if ($page) {
             $user = $page->user;
         }
     }
     if ($to_userid) {
         $toUser = app('App\\Repositories\\UserRepository')->findById($to_userid);
         if ($toUser and !$toUser->present()->canPost()) {
             return false;
         }
     }
     $imageAttachPostId = false;
     if ($content_type == 'image') {
         if (\Input::hasFile('image') and empty($type_content)) {
             $images = \Input::file('image');
             //send back once one of the images does not met allowed size by admin
             if (!$this->photoRepository->imagesMetSizes($images)) {
                 return false;
             }
             $image = [];
             if (!$page_id and !$community_id) {
                 $album = $this->photoAlbum->add('posts', $user->id, true);
             }
             $param = ['path' => 'users/' . $user->id . '/posts', 'slug' => (!$page_id and !$community_id) ? 'album-' . $album->id : 'post', 'userid' => $user->id];
             if ($community_id) {
                 $community = app('App\\Repositories\\CommunityRepository')->get($community_id);
                 if ($community and $community->privacy == 0) {
                     $param['privacy'] = 5;
                 }
             }
             if ($page_id) {
                 $param['privacy'] = 5;
                 //prevent it from showing on this user profile
                 $param['page_id'] = $page_id;
             }
             foreach ($images as $im) {
                 $theImage = $this->photoRepository->upload($im, $param);
                 if (!$page_id and !$community_id) {
                     if ($album->default_photo == '') {
                         $album->default_photo = $theImage;
                         $album->save();
                     }
                 }
                 $image[] = $theImage;
             }
             $type_content = $image;
         }
         if (count($type_content) == 1 and isset($type_content[0])) {
             $imageAttachPostId = $this->photoRepository->get($type_content[0]);
         }
     }
     if ($content_type == 'link' and empty($link_title)) {
         //append the link to the post text
         $text .= ' ' . $type_content;
         if (empty($type_content)) {
             return false;
         }
     } elseif ($content_type == 'location') {
         $type_content = sanitizeText($type_content);
     }
     if (\Input::hasFile('video')) {
         $videoMaxSize = \Config::get('max-size-upload-video');
         $videoFile = \Input::file('video');
         $videoExt = $videoFile->getClientOriginalExtension();
         if ($videoFile->getSize() > $videoMaxSize or strtolower($videoExt) != 'mp4') {
             return false;
         }
         $userid = \Auth::user()->id;
         $filePath = "uploads/videos/" . $userid . '/';
         //ensure the folder exists
         $this->file->makeDirectory(public_path() . '/' . $filePath, 0777, true, true);
         $fileName = md5($videoFile->getClientOriginalName() . time()) . '.mp4';
         $video_path = $filePath . $fileName;
         $videoFile->move(public_path() . '/' . $filePath, $fileName);
         $newFileName = $CDNRepository->upload(public_path() . '/' . $video_path, $video_path);
         if ($newFileName != $video_path) {
             //that means file has been succcessfully uploaded to a CDN Server so
             $video_path = $newFileName;
         }
     }
     if (\Input::hasFile('share_file')) {
         $fileMaxSize = \Config::get('max-upload-files');
         $mainFile = \Input::file('share_file');
         $fileExt = $mainFile->getClientOriginalExtension();
         $allowedExts = explode(',', \Config::get('allow-files-types'));
         if ($mainFile->getSize() > $fileMaxSize or !in_array(strtolower($fileExt), $allowedExts)) {
             return false;
         }
         $userid = \Auth::user()->id;
         $filePath = "uploads/files/" . $userid . '/';
         //ensure the folder exists
         $this->file->makeDirectory(public_path() . '/' . $filePath, 0777, true, true);
         $fileName = md5($mainFile->getClientOriginalName() . time()) . '.' . $fileExt;
         $file_path = $filePath . $fileName;
         $file_path_name = $mainFile->getClientOriginalName();
         $mainFile->move(public_path() . '/' . $filePath, $fileName);
         $newFileName = $CDNRepository->upload(public_path() . '/' . $file_path, $file_path);
         if ($newFileName != $file_path) {
             //that means file has been succcessfully uploaded to a CDN Server so
             $file_path = $newFileName;
         }
     }
     if ($content_type == 'auto-post') {
         $autoPostType = $type_content['type'];
         if ($autoPostType == 'change-avatar') {
             $imageAttachPostId = $this->photoRepository->get($type_content['avatar']);
         } elseif ($autoPostType == 'add-photos') {
             $autoPostPhotosCount = $type_content['photo-count'];
             if ($autoPostPhotosCount == 1) {
                 $imageAttachPostId = $this->photoRepository->get($type_content['photos'][0]);
             }
         }
     }
     //now validate post
     if (empty($text) and empty($type_content) and empty($video_path) and empty($file_path)) {
         return false;
     }
     $linksContained = $this->getLinks($text);
     if (!empty($linksContained)) {
         $containMedia = false;
         $containType = '';
         $containLink = '';
         foreach ($linksContained as $mediaLink) {
             if (!$containLink) {
                 if ($youtube = parseYouTube($mediaLink)) {
                     $containLink = $youtube;
                     $containType = 'video';
                     $containMedia = true;
                 } elseif ($vimeo = parseVimeo($mediaLink)) {
                     $containLink = $vimeo;
                     $containType = 'video';
                     $containMedia = true;
                 } elseif (preg_match("#soundcloud.com/([a-zA-Z0-9\\-\\_]+)/([a-zA-Z0-9\\-\\_]+)#", $mediaLink)) {
                     $containLink = $mediaLink;
                     $containType = 'audio';
                     $containMedia = true;
                 }
             } else {
                 break;
             }
         }
         if ($containMedia) {
             $type_content = $containLink;
             $content_type = $containType;
         }
     }
     $type_content = (array) $type_content;
     if ($auto_like_id) {
         //lets delete the auto like before
         $this->model->where('auto_like_id', '=', $auto_like_id)->where('user_id', '=', $user->id)->delete();
     }
     $to_userid = sanitizeText($to_userid);
     $content_type = sanitizeText($content_type);
     $type = sanitizeText($type);
     $type_id = sanitizeText($type_id);
     $community_id = sanitizeText($community_id);
     $page_id = sanitizeText($page_id);
     $post = $this->model->newInstance();
     $post->text = \Hook::fire('filter-text', sanitizeText($text));
     $post->user_id = $user->id;
     $post->to_user_id = $to_userid == $user->id ? 0 : $to_userid;
     $post->content_type = $content_type;
     $post->type_content = perfectSerialize($type_content);
     $post->type = $type;
     $post->type_id = $type_id;
     $post->community_id = $community_id;
     $post->page_id = $page_id;
     $post->tags = perfectSerialize($tags);
     $post->privacy = sanitizeText($privacy);
     $post->video_path = $video_path;
     $post->auto_like_id = $auto_like_id;
     $post->file_path = $file_path;
     $post->file_path_name = $file_path_name;
     if (!empty($link_title)) {
         /**Search for links in post because lin**/
         $details = ['link' => $the_link, 'title' => $link_title, 'description' => $link_description, 'image' => $link_image];
         $post->link = perfectSerialize($details);
     }
     $post->save();
     if ($imageAttachPostId) {
         $imageAttachPostId->post_id = $post->id;
         $imageAttachPostId->save();
     }
     /**
      * Automatically add this user to notification receiver of this post
      */
     $this->notificationReceiver->add($user->id, 'post', $post->id);
     //lets add all the user that are admins if the post is a page post
     if ($post->page_id != 0) {
         $adminsIds = app('App\\Repositories\\PageAdminRepository')->getUserListId($post->page_id);
         foreach ($adminsIds as $adminId) {
             $this->notificationReceiver->add($adminId, 'post', $post->id);
         }
     }
     /**For community posting we need to send a notification to the community notifications receivers***/
     if ($type == "community") {
         $this->notification->sendToReceivers('community', $community_id, ['path' => 'notification.post.community', 'communityId' => $community_id, 'postId' => $post->id]);
     }
     //we are to send notification to the profile owner incase user is posting to him
     if ($post->to_user_id) {
         $this->notification->send($post->to_user_id, ['path' => 'notification.post.profile', 'postId' => $post->id]);
     }
     $this->event->fire('post.add', [$post, $val]);
     return $post;
 }