/**
  * Method to send notification
  *
  * @param int $toUserid
  * @param array $details
  * @param int $userid
  * @param bool $withPrivacy
  * @param string $privacyId
  * @param \App\\Models\\User $privacyUser
  * @return boolean
  */
 public function send($toUserid, $details = [], $userid = null, $withPrivacy = false, $privacyId = null, $privacyUser = null)
 {
     $userid = empty($userid) ? \Auth::user()->id : $userid;
     if ($withPrivacy) {
         //check if the notification receiver has disabled receiving from this notification type
         if (!$privacyUser->present()->privacy($privacyId, 1)) {
             return false;
         }
     }
     $expectedDetails = ['title' => '', 'content' => '', 'seen' => 0, 'data' => []];
     /**
      * @var $title
      * @var $content
      * @var $seen
      * @var $data
      */
     extract($allDetails = array_merge($expectedDetails, $details));
     $notification = $this->model->newInstance();
     $notification->user_id = $userid;
     $notification->to_user_id = $toUserid;
     $notification->title = sanitizeText($title);
     $notification->content = $content;
     $notification->data = empty($details) ? '' : perfectSerialize($details);
     $notification->save();
     $this->realTimeRepository->add($toUserid, 'notification');
     $this->event->fire('notification.send', [$notification, $details]);
     return $notification;
 }
示例#2
0
 public function update($userid, $info)
 {
     foreach ($this->types as $type) {
         $this->file->makeDirectory($this->path . '/' . $type . '/', 0777, true, true);
         $userFilePath = $this->path . '/' . $type . '/' . $userid . '.php';
         if (!$this->file->exists($userFilePath)) {
             $handle = fopen($userFilePath, 'a+');
             fwrite($handle, perfectSerialize($info));
             fclose($handle);
         }
         $this->file->put($userFilePath, perfectSerialize($info));
     }
 }
示例#3
0
 /**
  * Get widgets for a base
  *
  * @param string $base
  * @return string
  */
 public function get($base)
 {
     if (!isset(static::$widgets[$base])) {
         return false;
     }
     $paglets = [];
     $content = '';
     foreach (static::$widgets[$base] as $widget) {
         $paglets[] = $widget;
         if (!\Config::get('enable-bigpipe')) {
             $content .= \Theme::section($widget['view'], $widget['data']);
         }
     }
     if (\Config::get('enable-bigpipe')) {
         echo "<div class='pagelets' data-id='" . $base . "' data-content='" . perfectSerialize($paglets) . "'></div>";
     }
     return $content;
 }
示例#4
0
 /**
  * save user privacy info
  *
  * @param array $val
  * @param \App\Models\User $user
  * @return boolean
  */
 public function savePrivacy($val, $user = null)
 {
     $user = empty($user) ? \Auth::user() : $user;
     $privacy = empty($user->privacy_info) ? [] : perfectUnserialize($user->privacy_info);
     $privacy = array_merge($privacy, $val);
     $user->privacy_info = perfectSerialize(sanitizeUserInfo($privacy));
     $user->save();
     $this->event->fire('user.save.privacy', [$user]);
     return true;
 }
示例#5
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;
 }
示例#6
0
 public function removeModerator($id, $userid)
 {
     $community = $this->get($id);
     if ($community and $community->isOwner()) {
         $moderators = $community->getModerators();
         $newModerators = [];
         foreach ($moderators as $m) {
             if ($m != $userid) {
                 $newModerators[] = $m;
             }
         }
         $community->moderators = perfectSerialize($newModerators);
         $community->save();
     }
     return false;
 }