Esempio n. 1
0
 public function ajaxUpdateThumbnail($type, $id, $sourceX, $sourceY, $width, $height)
 {
     CPhotosHelper::updateAvatar($type, $id, $sourceX, $sourceY, $width, $height);
     switch ($type) {
         case 'profile':
             $url = CRoute::_('index.php?option=com_community&view=' . $type . '&userid=' . $id);
             break;
         case 'group':
             $url = CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $id);
             break;
         case 'event':
             $url = CRoute::_('index.php?option=com_community&view=events&task=viewevent&eventid=' . $id);
             break;
     }
     $json = array('success' => true, 'redirUrl' => $url);
     die(json_encode($json));
 }
Esempio n. 2
0
 /**
  * Resize user's thumbnail from the source image
  *
  * @param Object $imgObj
  * @param String $src
  *
  */
 public function ajaxUpdateThumbnail($sourceX, $sourceY, $width, $height, $hideSave = false)
 {
     $filter = JFilterInput::getInstance();
     $sourceX = $filter->clean($sourceX, 'float');
     $sourceY = $filter->clean($sourceY, 'float');
     $width = $filter->clean($width, 'float');
     $height = $filter->clean($height, 'float');
     $hideSave = $filter->clean($hideSave, 'bool');
     // Fetch the thumbnail remotely. This is necessary since the user
     // profile picture might not be stored locally
     $objResponse = new JAXResponse();
     $my = CFactory::getUser();
     if ($my->id && $my->_avatar != '') {
         CPhotosHelper::updateAvatar('profile', $my->id, $sourceX, $sourceY, $width, $height);
         $objResponse->addScriptCall('refreshThumbnail');
     } else {
         return $this->ajaxBlockUnregister();
     }
     return $objResponse->sendResponse();
 }
Esempio n. 3
0
 public function addLike($element, $itemId)
 {
     $my = CFactory::getUser();
     $like = JTable::getInstance('Like', 'CTable');
     $like->loadInfo($element, $itemId);
     $like->element = $element;
     $like->uid = $itemId;
     // Check if user already like
     $likesInArray = explode(',', trim($like->like, ','));
     /* Like once time */
     if (in_array($my->id, $likesInArray)) {
         return;
     }
     array_push($likesInArray, $my->id);
     $likesInArray = array_unique($likesInArray);
     $like->like = ltrim(implode(',', $likesInArray), ',');
     // Check if the user already dislike
     $dislikesInArray = explode(',', trim($like->dislike, ','));
     if (in_array($my->id, $dislikesInArray)) {
         // Remove user dislike from array
         $key = array_search($my->id, $dislikesInArray);
         unset($dislikesInArray[$key]);
         $like->dislike = implode(',', $dislikesInArray);
     }
     switch ($element) {
         case 'comment':
             //get the instance of the wall
             $wall = JTable::getInstance('Wall', 'CTable');
             $wall->load($itemId);
             if (!$wall->id) {
                 break;
             }
             if ($wall->type == "profile.status") {
                 $wall->type = "profile";
             }
             //load the stream id from activity stream
             $stream = JTable::getInstance('Activity', 'CTable');
             $stream->load(array('comment_id' => $wall->contentid, 'app' => $wall->type));
             if ($stream->id) {
                 $profile = CFactory::getUser($stream->actor);
                 $url = 'index.php?option=com_community&view=profile&userid=' . $profile->id . '&actid=' . $stream->id . '#activity-stream-container';
                 $params = new CParameter('');
                 $params->set('url', $url);
                 $params->set('comment', JText::_('COM_COMMUNITY_SINGULAR_COMMENT'));
                 $params->set('comment_url', $url);
                 $params->set('actor', $my->getDisplayName());
                 //add to notifications
                 CNotificationLibrary::add('comments_like', $my->id, $wall->post_by, JText::sprintf('COM_COMMUNITY_PROFILE_WALL_LIKE_EMAIL_SUBJECT'), '', 'comments.like', $params);
             }
             break;
         case 'photo':
             $photo = JTable::getInstance('Photo', 'CTable');
             $photo->load($itemId);
             if ($photo->id) {
                 $url = $photo->getRawPhotoURI();
                 $params = new CParameter('');
                 $params->set('url', $url);
                 $params->set('photo', JText::_('COM_COMMUNITY_SINGULAR_PHOTO'));
                 $params->set('photo_url', $url);
                 CNotificationLibrary::add('photos_like', $my->id, $photo->creator, JText::sprintf('COM_COMMUNITY_PHOTO_LIKE_EMAIL_SUBJECT'), '', 'photos.like', $params);
                 /* Adding user points */
                 CUserPoints::assignPoint('photos.like');
             }
             break;
         case 'album':
             $album = JTable::getInstance('Album', 'CTable');
             $album->load($itemId);
             if ($album->id) {
                 if ($album->groupid) {
                     $url = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&groupid=' . $album->groupid;
                 } else {
                     $url = 'index.php?option=com_community&view=photos&task=album&albumid=' . $album->id;
                 }
                 $params = new CParameter('');
                 $params->set('url', $url);
                 $params->set('album', $album->name);
                 $params->set('album_url', $url);
                 CNotificationLibrary::add('photos_like', $my->id, $album->creator, JText::sprintf('COM_COMMUNITY_ALBUM_LIKE_EMAIL_SUBJECT'), '', 'album.like', $params);
                 /* Adding user points */
                 CUserPoints::assignPoint('album.like');
             }
             break;
         case 'videos':
             $video = JTable::getInstance('Video', 'CTable');
             $video->load($itemId);
             if ($video->id) {
                 if ($video->groupid) {
                     $url = 'index.php?option=com_community&view=videos&task=video&groupid=' . $video->groupid . '&videoid=' . $video->id;
                 } else {
                     $url = 'index.php?option=com_community&view=videos&task=video&videoid=' . $video->id;
                 }
                 $params = new CParameter('');
                 $params->set('url', $url);
                 $params->set('video', $video->title);
                 $params->set('video_url', $url);
                 CNotificationLibrary::add('videos_like', $my->id, $video->creator, JText::sprintf('COM_COMMUNITY_VIDEO_LIKE_EMAIL_SUBJECT'), '', 'videos.like', $params);
                 /* Adding user points */
                 CUserPoints::assignPoint('videos.like');
             }
             break;
         case 'profile':
             $profile = CFactory::getUser($itemId);
             if ($profile->id) {
                 $url = 'index.php?option=com_community&view=profile&userid=' . $profile->id;
                 $params = new CParameter('');
                 $params->set('url', $url);
                 $params->set('profile', strtolower(JText::_('COM_COMMUNITY_NOTIFICATIONGROUP_PROFILE')));
                 $params->set('profile_url', $url);
                 CNotificationLibrary::add('profile_like', $my->id, $profile->id, JText::sprintf('COM_COMMUNITY_PROFILE_LIKE_EMAIL_SUBJECT'), '', 'profile.like', $params);
                 /* Adding user points */
                 CUserPoints::assignPoint('profile.like');
             }
             break;
         case 'profile.status':
             $stream = JTable::getInstance('Activity', 'CTable');
             $stream->load($itemId);
             if ($stream->id) {
                 $profile = CFactory::getUser($stream->actor);
                 $url = 'index.php?option=com_community&view=profile&userid=' . $profile->id . '&actid=' . $stream->id;
                 $params = new CParameter('');
                 $params->set('url', $url);
                 $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM'));
                 $params->set('stream_url', $url);
                 CNotificationLibrary::add('profile_stream_like', $my->id, $profile->id, JText::sprintf('COM_COMMUNITY_PROFILE_STREAM_LIKE_EMAIL_SUBJECT'), '', 'profile.stream.like', $params);
                 /* Adding user points */
                 CUserPoints::assignPoint('profile.stream.like');
             }
             break;
         case 'cover.upload':
             $photo = JTable::getInstance('Photo', 'CTable');
             $photo->load(CPhotosHelper::getPhotoOfStream($itemId));
             if ($photo->id) {
                 $url = $photo->getRawPhotoURI();
                 $params = new CParameter('');
                 $params->set('url', $url);
                 $params->set('photo', JText::_('COM_COMMUNITY_SINGULAR_PHOTO'));
                 $params->set('photo_url', $url);
                 CNotificationLibrary::add('photos_like', $my->id, $photo->creator, JText::sprintf('COM_COMMUNITY_COVER_LIKE_EMAIL_SUBJECT'), '', 'photos.like', $params);
                 /* Adding user points */
                 CUserPoints::assignPoint('photos.like');
             }
             break;
         case 'profile.avatar.upload':
             $stream = JTable::getInstance('Activity', 'CTable');
             $stream->load($itemId);
             if ($stream->id) {
                 $profile = CFactory::getUser($stream->actor);
                 $url = 'index.php?option=com_community&view=profile&userid=' . $profile->id . '&actid=' . $stream->id;
                 $params = new CParameter('');
                 $params->set('url', $url);
                 $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM'));
                 $params->set('stream_url', $url);
                 CNotificationLibrary::add('profile_stream_like', $my->id, $profile->id, JText::sprintf('COM_COMMUNITY_PROFILE_AVATAR_LIKE_EMAIL_SUBJECT'), '', 'profile.stream.like', $params);
                 /* Adding user points */
                 CUserPoints::assignPoint('profile.stream.like');
             }
             break;
         case 'album.self.share':
             $stream = JTable::getInstance('Activity', 'CTable');
             $stream->load($itemId);
             $profile = CFactory::getUser($stream->actor);
             //get total photo(s) uploaded and determine the string
             $actParam = new CParameter($stream->params);
             if ($actParam->get('batchcount') > 1) {
                 $content = JText::sprintf('COM_COMMUNITY_ACTIVITY_ALBUM_PICTURES_LIKE_SUBJECT');
             } else {
                 $content = JText::sprintf('COM_COMMUNITY_ACTIVITY_ALBUM_PICTURE_LIKE_SUBJECT');
             }
             $url = 'index.php?option=com_community&view=profile&userid=' . $profile->id . '&actid=' . $stream->id;
             $params = new CParameter('');
             $params->set('url', $url);
             $params->set('stream', JText::_('COM_COMMUNITY_SINGULAR_STREAM'));
             $params->set('stream_url', $url);
             CNotificationLibrary::add('profile_stream_like', $my->id, $profile->id, $content, '', 'profile.stream.like', $params);
         default:
             CUserPoints::assignPoint($element . '.like');
     }
     // Log user engagement
     CEngagement::log($element . '.like', $my->id);
     $like->store();
 }
Esempio n. 4
0
 /**
  * Overrides parent store function as we need to clean up some variables
  * */
 public function store($updateNulls = false)
 {
     if (!$this->check()) {
         return false;
     }
     $this->image = CString::str_ireplace('\\', '/', $this->image);
     $this->thumbnail = CString::str_ireplace('\\', '/', $this->thumbnail);
     $this->original = CString::str_ireplace('\\', '/', $this->original);
     // Store params
     $this->params = $this->_params->toString();
     //lets add watermark if there is any and only for new photos
     if (CPhotosHelper::photoWatermarkEnabled() && !$this->id) {
         $config = CFactory::getConfig();
         $watermark = JPATH_ROOT . '/' . COMMUNITY_WATERMARKS_PATH . '/' . WATERMARK_DEFAULT_NAME . '.png';
         list($watermarkWidth, $watermarkHeight) = getimagesize($watermark);
         //original photo
         $thumbPath = JPATH_ROOT . '/' . $this->original;
         if (file_exists($thumbPath)) {
             $thumbInfo = getimagesize($thumbPath);
             $thumbWidth = $thumbInfo[0];
             $thumbHeight = $thumbInfo[1];
             $thumbMime = $thumbInfo['mime'];
             if ($config->get('min_width_img_watermark') <= $thumbWidth && $config->get('min_height_img_watermark') <= $thumbHeight && $thumbHeight >= $watermarkHeight && $thumbWidth >= $watermarkWidth) {
                 $thumbPosition = $this->_getPositions($config->get('watermark_position'), $thumbWidth, $thumbHeight, $watermarkWidth, $watermarkHeight);
                 CImageHelper::addWatermark($thumbPath, $thumbPath, $thumbMime, $watermark, $thumbPosition->x, $thumbPosition->y);
             }
         }
     }
     //do not use the photo name as the caption for the first time when uploaded
     if (!$this->id) {
         $this->caption = '';
     }
     $result = parent::store();
     if ($this->status != 'temp' && $result) {
         // Changes in photos will affect the album. Do a store on album
         $album = JTable::getInstance('Album', 'CTable');
         $album->load($this->albumid);
         $album->store();
     }
     return $result;
 }