function _userPhoto() { $mainframe =& JFactory::getApplication(); $document =& JFactory::getDocument(); // Get necessary properties and load the libraries CFactory::load('models', 'photos'); CFactory::load('helpers', 'friends'); $my = CFactory::getUser(); $model = CFactory::getModel('photos'); $albumId = JRequest::getVar('albumid', '', 'GET'); $defaultId = JRequest::getVar('photoid', '', 'GET'); if (empty($albumId)) { echo JText::_('CC NO PROPER ALBUM ID'); return; } // Load the album table $album =& JTable::getInstance('Album', 'CTable'); $album->load($albumId); // Since the URL might not contain userid, we need to get the user object from the creator $user = CFactory::getUser($album->creator); if (!$user->block || COwnerHelper::isCommunityAdmin($my->id)) { // Set the current user's active profile CFactory::setActiveProfile($album->creator); // Get list of photos and set some limit to be displayed. // @todo: make limit configurable? set to 1000, unlimited? $photos = $model->getPhotos($albumId, 1000); $pagination = $model->getPagination(); CFactory::load('helpers', 'pagination'); // @todo: make limit configurable? $paging = CPaginationLibrary::getLinks($pagination, 'photos,ajaxPagination', $albumId, 10); // Set document title CFactory::load('helpers', 'string'); $document->setTitle($album->name); // @checks: Test if album doesnt have any default photo id. We need to get the first row // of the photos to be the default if ($album->photoid == '0') { $album->photoid = count($photos) >= 1 ? $photos[0]->id : '0'; } // Try to see if there is any photo id in the query $defaultId = !empty($defaultId) ? $defaultId : $album->photoid; // Load the default photo $photo =& JTable::getInstance('Photo', 'CTable'); $photo->load($defaultId); // If default has an id of 0, we need to tell the template to dont process anything $default = $photo->id == 0 ? false : $photo; // Load User params $params =& $user->getParams(); // site visitor $relation = 10; // site members if ($my->id != 0) { $relation = 20; } // friends if (CFriendsHelper::isConnected($my->id, $user->id)) { $relation = 30; } // mine if (COwnerHelper::isMine($my->id, $user->id)) { $relation = 40; } if ($my->id != $user->id) { $this->attachMiniHeaderUser($user->id); } CFactory::load('helpers', 'owner'); // @todo: respect privacy settings if ($relation < $params->get('privacyPhotoView') && !COwnerHelper::isCommunityAdmin()) { echo JText::_('CC ACCESS FORBIDDEN'); return; } CFactory::load('helpers', 'owner'); //friend list for photo tag CFactory::load('libraries', 'phototagging'); $tagging = new CPhotoTagging(); for ($i = 0; $i < count($photos); $i++) { $item = JTable::getInstance('Photo', 'CTable'); $item->bind($photos[$i]); $photos[$i] = $item; $row =& $photos[$i]; $taggedList = $tagging->getTaggedList($row->id); for ($t = 0; $t < count($taggedList); $t++) { $tagItem =& $taggedList[$t]; $tagUser = CFactory::getUser($tagItem->userid); $canRemoveTag = 0; // 1st we check the tagged user is the photo owner. // If yes, canRemoveTag == true. // If no, then check on user is the tag creator or not. // If yes, canRemoveTag == true // If no, then check on user whether user is being tagged if (COwnerHelper::isMine($my->id, $row->creator) || COwnerHelper::isMine($my->id, $tagItem->created_by) || COwnerHelper::isMine($my->id, $tagItem->userid)) { $canRemoveTag = 1; } $tagItem->user = $tagUser; $tagItem->canRemoveTag = $canRemoveTag; } $row->tagged = $taggedList; } $friendModel = CFactory::getModel('friends'); $friends = $friendModel->getFriends($my->id, '', false); array_unshift($friends, $my); // Show wall contents CFactory::load('helpers', 'friends'); // Load up required objects. $user = CFactory::getUser($photo->creator); $config = CFactory::getConfig(); $isConnected = CFriendsHelper::isConnected($my->id, $user->id); $isMe = COwnerHelper::isMine($my->id, $user->id); $showWall = false; $allowTag = false; // Check if user is really allowed to post walls on this photo. if ($isMe || !$config->get('lockprofilewalls') || $config->get('lockprofilewalls') && $isConnected) { $showWall = true; } //check if we can allow the current viewing user to tag the photos if ($isMe || $isConnected) { $allowTag = true; } $tmpl = new CTemplate(); CFactory::load('libraries', 'bookmarks'); $bookmarks = new CBookmarks(CRoute::getExternalURL('index.php?option=com_community&view=photos&task=album&albumid=' . $album->id . '&userid=' . $user->id)); $bookmarksHTML = $bookmarks->getHTML(); $tmpl->set('showWall', $showWall); $tmpl->set('allowTag', $allowTag); $tmpl->set('isOwner', COwnerHelper::isMine($my->id, $user->id)); $tmpl->set('photos', $photos); $tmpl->set('pagination', $paging); $tmpl->set('default', $default); $tmpl->set('album', $album); $tmpl->set('config', $config); //echo $tmpl->fetch('photos.photo'); } else { CFactory::load('helpers', 'owner'); $tmpl = new CTemplate(); echo $tmpl->fetch('profile.blocked'); return; } }
private function getPhotoTags($photo) { $tagging = new CPhotoTagging(); $taggedList = $tagging->getTaggedList($photo->id); $tags = array(); $my = CFactory::getUser(); for ($i = 0, $count = count($taggedList); $i < $count; $i++) { $tagItem = $taggedList[$i]; $tagUser = CFactory::getUser($tagItem->userid); // Check if user can remove tag. // 1st we check the tagged user is the photo owner. // If yes, canRemoveTag == true. // If no, then check on user is the tag creator or not. // If yes, canRemoveTag == true // If no, then check on user whether user is being tagged $canRemoveTag = 0; if (COwnerHelper::isMine($my->id, $photo->creator) || COwnerHelper::isMine($my->id, $tagItem->created_by) || COwnerHelper::isMine($my->id, $tagItem->userid)) { $canRemoveTag = 1; } $tagItem->user = $tagUser; $tagItem->canRemoveTag = $canRemoveTag; $tags[] = array('id' => $tagItem->id, 'userId' => $tagItem->userid, 'displayName' => $tagItem->user->getDisplayName(), 'profileUrl' => CRoute::_('index.php?option=com_community&view=profile&userid=' . $tagItem->userid, false), 'top' => $tagItem->posx, 'left' => $tagItem->posy, 'width' => $tagItem->width, 'height' => $tagItem->height, 'canRemove' => $tagItem->canRemoveTag); } return $tags; }
/** * Delete the photo, the original and the actual resized photos and thumbnails */ public function delete($pk = null) { $storage = CStorage::getStorage($this->storage); $storage->delete($this->image); $storage->delete($this->thumbnail); /* We did store original than now time to remove it */ if (!empty($this->original)) { /* Original do not sync with 3rd storage than we don't need to use $storage->delete; even it would be same */ if (JFile::exists(JPATH_ROOT . '/' . $this->original)) { JFile::delete(JPATH_ROOT . '/' . $this->original); } $originalDir = dirname(JPATH_ROOT . '/' . $this->original); $files = JFolder::files($originalDir); /* If the original path is empty, we can delete it too */ if (empty($files)) { JFolder::delete($originalDir); } } // if the photo is the album cover, set the album cover as default 0 $album = JTable::getInstance('Album', 'CTable'); $album->load($this->albumid); $album->set('photoid', 0); $album->store(); // delete the tags CFactory::load('libraries', 'phototagging'); $phototagging = new CPhotoTagging(); $phototagging->removeTagByPhoto($this->id); // delete the activities CActivities::remove('photos', $this->id); //Remove photo from activity stream CActivityStream::remove('photo.like', $this->id); // delete the comments $wall = CFactory::getModel('wall'); $wall->deleteAllChildPosts($this->id, 'photos'); /* And now finally we do delete this photo in database */ /* return parent::delete(); */ /** * @since 3.2 * We do not delete database record for now. Leave it for cron ! * @todo Considering local files should be deleted this time or not ? */ $this->published = 0; $this->status = 'delete'; $this->store(); }
/** * Displays single photo view * **/ public function photo() { $mainframe =& JFactory::getApplication(); $document = JFactory::getDocument(); $my = CFactory::getUser(); $config = CFactory::getConfig(); // Load window library CFactory::load('libraries', 'window'); CWindow::load(); // Get the configuration object. $config = CFactory::getConfig(); $css = JURI::root() . 'components/com_community/assets/album.css'; $document->addStyleSheet($css); $css = JURI::root() . 'components/com_community/assets/photos.css'; $document->addStyleSheet($css); $js = 'assets/gallery'; $js .= $config->getBool('usepackedjavascript') ? '.pack.js' : '.js'; CAssets::attach($js, 'js'); $albumId = JRequest::getVar('albumid', '', 'GET'); $defaultId = JRequest::getVar('photoid', '', 'GET'); $userId = JRequest::getVar('userid', '', 'GET'); $user = CFactory::getUser($userId); $handler = $this->_getHandler(); $handler->setMiniHeader(); if (empty($albumId)) { echo JText::_('COM_COMMUNITY_PHOTOS_NO_ALBUMID_ERROR'); return; } CFactory::load('models', 'photos'); CFactory::load('helpers', 'friends'); $album =& JTable::getInstance('Album', 'CTable'); $album->load($albumId); // Set pathway $pathway =& $mainframe->getPathway(); // Set pathway for group photos // Community > Groups > Group Name > Photos > Album Name $groupId = JRequest::getVar('groupid', '', 'GET'); if (!empty($groupId)) { $group =& JTable::getInstance('Group', 'CTable'); $group->load($groupId); $pathway->addItem(JText::_('COM_COMMUNITY_GROUPS'), CRoute::_('index.php?option=com_community&view=groups')); $pathway->addItem($group->name, CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $groupId)); $pathway->addItem(JText::_('COM_COMMUNITY_PHOTOS'), CRoute::_('index.php?option=com_community&view=photos&groupid=' . $groupId)); } else { $pathway->addItem(JText::_('COM_COMMUNITY_PHOTOS'), CRoute::_('index.php?option=com_community&view=photos')); $pathway->addItem(JText::sprintf('COM_COMMUNITY_PHOTOS_USER_PHOTOS_TITLE', $user->getDisplayName()), CRoute::_('index.php?option=com_community&view=photos&task=myphotos&userid=' . $userId)); } $pathway->addItem($album->name, ''); // Set document title CFactory::load('helpers', 'string'); $document->setTitle($album->name); if (!$handler->isAlbumBrowsable($albumId)) { return; } $model =& CFactory::getModel('photos'); $photos = $model->getPhotos($albumId, 1000); // @checks: Test if album doesnt have any default photo id. We need to get the first row // of the photos to be the default if ($album->photoid == '0') { $album->photoid = count($photos) >= 1 ? $photos[0]->id : '0'; } // Try to see if there is any photo id in the query $defaultId = !empty($defaultId) ? $defaultId : $album->photoid; // Load the default photo $photo =& JTable::getInstance('Photo', 'CTable'); $photo->load($defaultId); $document->addHeadLink($photo->getThumbURI(), 'image_src', 'rel'); // If default has an id of 0, we need to tell the template to dont process anything $default = $photo->id == 0 ? false : $photo; //friend list for photo tag CFactory::load('libraries', 'phototagging'); $tagging = new CPhotoTagging(); for ($i = 0; $i < count($photos); $i++) { $item =& JTable::getInstance('Photo', 'CTable'); $item->bind($photos[$i]); $photos[$i] = $item; $row =& $photos[$i]; $taggedList = $tagging->getTaggedList($row->id); for ($t = 0; $t < count($taggedList); $t++) { $tagItem =& $taggedList[$t]; $tagUser = CFactory::getUser($tagItem->userid); $canRemoveTag = 0; // 1st we check the tagged user is the photo owner. // If yes, canRemoveTag == true. // If no, then check on user is the tag creator or not. // If yes, canRemoveTag == true // If no, then check on user whether user is being tagged if (COwnerHelper::isMine($my->id, $row->creator) || COwnerHelper::isMine($my->id, $tagItem->created_by) || COwnerHelper::isMine($my->id, $tagItem->userid)) { $canRemoveTag = 1; } $tagItem->user = $tagUser; $tagItem->canRemoveTag = $canRemoveTag; } $row->tagged = $taggedList; } //$friends = $handler->getTaggingUsers(); // Show wall contents CFactory::load('helpers', 'friends'); CFactory::load('helpers', 'owner'); CFactory::load('libraries', 'bookmarks'); // Load up required objects. $isMine = $handler->isAlbumOwner($album->id); $bookmarks = new CBookmarks($handler->getPhotoExternalURI($photo->id, $album->id)); //Performance issues: blocked users should be handle in sql statment /** * Get ban list */ //$block = CFactory::getModel( 'block' ); //$friendlist = array(); //foreach($friends as $friend){ // Exclude blocked user // if( !$block->getBlockStatus($my->id,$friend->id) ){ // $friendlist[] = $friend; // } //} $this->showSubmenu(); $tmpl = new CTemplate(); echo $tmpl->set('bookmarksHTML', $bookmarks->getHTML())->set('showWall', $handler->isWallAllowed())->set('allowTag', $handler->isTaggable())->set('isOwner', $isMine)->set('isAdmin', COwnerHelper::isCommunityAdmin())->set('photos', $photos)->set('default', $default)->set('album', $album)->set('config', $config)->set('photoCreator', CFactory::getUser($photo->creator))->fetch('photos.photo'); }
public function ajaxRemovePhotoTag($photoId, $userId) { if (!COwnerHelper::isRegisteredUser()) { return $this->ajaxBlockUnregister(); } $my = CFactory::getUser(); $response = new JAXResponse(); $photo =& JTable::getInstance('Photo', 'CTable'); $photo->load($photoId); if ($my->id != $userId && $my->id != $photo->creator) { $response->addScriptCall('alert', JText::_('ACCESS FORBIDDEN')); return $response->sendResponse(); } CFactory::load('libraries', 'phototagging'); $tagging = new CPhotoTagging(); if (!$tagging->removeTag($photoId, $userId)) { $html = $tagging->getError(); $response->addScriptCall('cWindowShow', '', 'Notice', 450, 200, 'warning'); $response->addAssign('cWindowContent', 'innerHTML', $html); } return $response->sendResponse(); }
/** * Delete the photo, the original and the actual resized photos and thumbnails */ public function delete() { CFactory::load('libraries', 'storage'); $storage = CStorage::getStorage($this->storage); $storage->delete($this->image); $storage->delete($this->thumbnail); JFile::delete(JPATH_ROOT . DS . $this->original); // If the original path is empty, we can delete it too $files = JFolder::files(dirname(JPATH_ROOT . DS . $this->original)); if (empty($files)) { JFolder::delete(dirname(JPATH_ROOT . DS . $this->original)); } // if the photo is the album cover, set the album cover as default 0 $album =& JTable::getInstance('Album', 'CTable'); $album->load($this->albumid); $album->set('photoid', 0); $album->store(); // delete the tags CFactory::load('libraries', 'phototagging'); CPhotoTagging::removeTagByPhoto($this->id); // delete the activities CFactory::load('libraries', 'activities'); CActivities::remove('photos', $this->id); // delete the comments $wall = CFactory::getModel('wall'); $wall->deleteAllChildPosts($this->id, 'photos'); return parent::delete(); }
public function ajaxRemovePhotoTag($photoId, $userId) { $filter = JFilterInput::getInstance(); $photoId = $filter->clean($photoId, 'int'); $userId = $filter->clean($userId, 'int'); if (!COwnerHelper::isRegisteredUser()) { return $this->ajaxBlockUnregister(); } $my = CFactory::getUser(); $response = new JAXResponse(); if (!$my->authorise('community.remove', 'photos.tag.' . $photoId)) { $response->addScriptCall('alert', JText::_('ACCESS FORBIDDEN')); return $response->sendResponse(); } CFactory::load('libraries', 'phototagging'); $tagging = new CPhotoTagging(); if (!$tagging->removeTag($photoId, $userId)) { $html = $tagging->getError(); $response->addScriptCall('cWindowShow', '', JText::_('COM_COMMUNITY_NOTICE'), 450, 200, 'warning'); $reponse->addAssign('cWindowAddContent', $html); } return $response->sendResponse(); }