public function getThumbnail($obj) { $config = CFactory::getConfig(); $file = $obj->thumb; // Site origin if (JString::substr($file, 0, 4) == 'http') { $uri = $file; return $uri; } // Remote storage if ($obj->storage != 'file') { $storage = CStorage::getStorage($obj->storage); $uri = $storage->getURI($file); return $uri; } // Default thumbnail if (empty($file) || !JFile::exists(JPATH_ROOT . '/' . $file)) { $template = new CTemplateHelper(); $asset = $template->getTemplateAsset('video_thumb.png', 'images'); $uri = $asset->url; return $uri; } // Strip cdn path if exists. // Note: At one point, cdn path was stored along with the thumbnail path // in the db which is the mistake we are trying to rectify here. $file = str_ireplace($config->get('videocdnpath'), '', $file); // CDN or local $baseUrl = $config->get('videobaseurl') or $baseUrl = JURI::root(); $uri = str_replace('\\', '/', rtrim($baseUrl, '/') . '/' . ltrim($file, '/')); return $uri; }
/** * Get large avatar use for cropping * @return string */ public function getLargeAvatar() { $config = CFactory::getConfig(); $largeAvatar = $config->getString('imagefolder') . '/avatar/profile-' . JFile::getName($this->avatar); $current = CStorage::getStorage($this->storage); if ($current->exists($largeAvatar)) { return $current->getURI($largeAvatar); } else { return $this->getAvatar(); } }
/** * Get large avatar use for cropping * @return string */ public function getLargeAvatar() { $config = CFactory::getConfig(); /* Some profile type avatar are stored directly to the avatar with this format avatar_[id] * So, if we have this kind of format, we will take this as priority * Used by JSPT */ if (count(explode('_', $this->avatar)) > 1) { $largeAvatar = $this->avatar; } else { $largeAvatar = $config->getString('imagefolder') . '/avatar/profile-' . JFile::getName($this->avatar); } $current = CStorage::getStorage($this->storage); if ($current->exists($largeAvatar)) { return $current->getURI($largeAvatar); } else { return $this->getAvatar(); } }
public function delete($pk = null) { $storage = CStorage::getStorage($this->storage); $storage->delete($this->filepath); return parent::delete(); }
public function _processVideoStorage($updateNum = 5) { $config = CFactory::getConfig(); $jconfig = JFactory::getConfig(); $videoStorage = $config->getString('videostorage'); CFactory::load('libraries', 'storage'); CFactory::load('models', 'videos'); CFactory::load('helpers', 'videos'); $db = JFactory::getDBO(); $query = ' SELECT * FROM ' . $db->nameQuote('#__community_videos') . ' WHERE ' . $db->nameQuote('storage') . ' != ' . $db->quote($videoStorage) . ' AND ' . $db->nameQuote('status') . ' = ' . $db->quote('ready') . ' ORDER BY rand() limit ' . $updateNum; $db->setQuery($query); $result = $db->loadObjectList(); if (!$result) { $this->message[] = JText::_('No Videos to transfer.'); return; } $storage = CStorage::getStorage($videoStorage); $tempFolder = $jconfig->getValue('tmp_path'); $fileTransferCount = 0; foreach ($result as $videoEntry) { $currentStorage = CStorage::getStorage($videoEntry->storage); if ($videoEntry->type == 'file') { // If it exist on current storage, we can transfer it to preferred storage if ($currentStorage->exists($videoEntry->path)) { // File exist on remote storage, move it locally first $tempFilename = JPATH::clean($tempFolder . DS . md5($videoEntry->path)); $tempThumbname = JPATH::clean($tempFolder . DS . md5($videoEntry->thumb)); $currentStorage->get($videoEntry->path, $tempFilename); $currentStorage->get($videoEntry->thumb, $tempThumbname); if (JFile::exists($tempFilename) && JFile::exists($tempThumbname)) { // we assume thumbnails is always there // put both video and thumbnails remotely if ($storage->put($videoEntry->path, $tempFilename) && $storage->put($videoEntry->thumb, $tempThumbname)) { // if the put is successful, update storage type $video = JTable::getInstance('Video', 'CTable'); $video->load($videoEntry->id); $video->storage = $videoStorage; $video->store(); // remove files on storage and temporary files $currentStorage->delete($videoEntry->path); $currentStorage->delete($videoEntry->thumb); JFile::delete($tempFilename); JFile::delete($tempThumbname); $fileTransferCount++; } } } } else { // This is for non-upload video file type e.g. YouTube etc // We'll just process the video thumbnail only if ($currentStorage->exists($videoEntry->thumb)) { $tempThumbname = JPATH::clean($tempFolder . DS . md5($videoEntry->thumb)); $currentStorage->get($videoEntry->thumb, $tempThumbname); if (JFile::exists($tempThumbname)) { if ($storage->put($videoEntry->thumb, $tempThumbname)) { $video = JTable::getInstance('Video', 'CTable'); $video->load($videoEntry->id); $video->storage = $videoStorage; $video->store(); $currentStorage->delete($videoEntry->thumb); JFile::delete($tempThumbname); $fileTransferCount++; } } } } } $this->message[] = $fileTransferCount . ' video file(s) transferred'; }
public function S3DownloadFile($obj) { $storage = CStorage::getStorage($obj->storage); $file_extension = strtolower(substr(strrchr($obj->filepath, "."), 1)); $name = rawurldecode($obj->name . '.' . $file_extension); header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename=' . $name . ';'); readfile($storage->getURI($obj->filepath)); }
/** * Setting Photo COver * @param [String] $type [Profile/Group/Event] * @param [Int] $photoid [photo id] * @param [Int] $parentId [Profile/Group/Event id] * @return [JSON object] [description] */ public function ajaxSetPhotoCover($type = null, $photoid = null, $parentId = null) { $album = JTable::getInstance('Album', 'CTable'); $addStream = true; $config = CFactory::getConfig(); if (!($albumId = $album->isCoverExist($type, $parentId))) { $albumId = $album->addCoverAlbum($type, $parentId); } if ($photoid) { $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($photoid); if (!JFolder::exists(JPATH_ROOT . '/' . $config->getString('imagefolder') . '/cover/' . $type . '/' . $parentId . '/')) { JFolder::create(JPATH_ROOT . '/' . $config->getString('imagefolder') . '/cover/' . $type . '/' . $parentId . '/'); } $ext = JFile::getExt($photo->image); $dest = $photo->albumid == $albumId ? $photo->image : JPATH_ROOT . '/' . $config->getString('imagefolder') . '/cover/' . $type . '/' . $parentId . '/' . md5($type . '_cover' . time()) . CImageHelper::getExtension($photo->image); $cTable = JTable::getInstance(ucfirst($type), 'CTable'); $cTable->load($parentId); if ($cTable->setCover(str_replace(JPATH_ROOT . '/', '', $dest))) { $storage = CStorage::getStorage($photo->storage); $storage->get($photo->image, $dest); if ($photo->albumid != $albumId) { $photo->id = ''; $photo->albumid = $albumId; $photo->image = str_replace(JPATH_ROOT . '/', '', $dest); if ($photo->store()) { $album->load($albumId); $album->photoid = $photo->id; $album->store(); } } $my = CFactory::getUser(); //assign points based on types. switch ($type) { case 'group': $addStream = CUserPoints::assignPoint('group.cover.upload'); break; case 'event': $addStream = CUserPoints::assignPoint('event.cover.upload'); break; default: $addStream = CUserPoints::assignPoint('profile.cover.upload'); } if ($cTable->cover == str_replace(JPATH_ROOT . '/', '', $dest)) { $addStream = false; } if ($type == 'event') { $group = JTable::getInstance('Group', 'CTable'); $group->load($cTable->contentid); if ($group->approvals == 1) { $addStream = false; } } // Generate activity stream if user points are enabled. if ($addStream) { $act = new stdClass(); $act->cmd = 'cover.upload'; $act->actor = $my->id; $act->target = 0; $act->title = ''; $act->content = ''; $act->access = $type == 'profile' ? $my->_cparams->get("privacyPhotoView") : 0; $act->app = 'cover.upload'; $act->cid = $photo->id; $act->comment_id = CActivities::COMMENT_SELF; $act->comment_type = 'cover.upload'; $act->groupid = $type == 'group' ? $parentId : 0; $act->eventid = $type == 'event' ? $parentId : 0; $act->group_access = $type == 'group' ? $cTable->approvals : 0; $act->event_access = $type == 'event' ? $cTable->permission : 0; $act->like_id = CActivities::LIKE_SELF; $act->like_type = 'cover.upload'; $params = new JRegistry(); $params->set('attachment', str_replace(JPATH_ROOT . '/', '', $dest)); $params->set('photo_id', $photo->id); $params->set('album_id', $photo->albumid); $params->set('type', $type); // Add activity logging if ($type != 'profile' || $type == 'profile' && $parentId == $my->id) { //admin can change user profile cover, so, do not generate any if the cover is changed by admin CActivityStream::add($act, $params->toString()); } } $json = array(); $json['path'] = JURI::root() . str_replace(JPATH_ROOT . '/', '', $dest); die(json_encode($json)); } } }
public function getThumbAvatar() { if ($this->thumb == 'components/com_community/assets/group_thumb.jpg') { $this->thumb = ''; $this->store(); } // For group avatars that are stored in a remote location, we should return the proper path. if ($this->storage != 'file' && !empty($this->thumb)) { $storage = CStorage::getStorage($this->storage); return $storage->getURI($this->thumb); } CFactory::load('helpers', 'url'); $thumb = CUrlHelper::avatarURI($this->thumb, 'group_thumb.png'); return $thumb; }
if (count($users) > 1) { if (count($users) == 2) { $activityString = JText::sprintf('COM_COMMUNITY_ACTIVITIES_COMMENT_OTHERS_VIDEO_TWO', CUrlHelper::userLink($user->id), $user->getDisplayName(), CUrlHelper::userLink($users[count($users) - 1]), CFactory::getUser($users[count($users) - 1])->getDisplayName(), $targetUrl, $target->getDisplayName(), $url); } else { $activityString = JText::sprintf('COM_COMMUNITY_ACTIVITIES_COMMENT_OTHERS_VIDEO_MORE', CUrlHelper::userLink($user->id), $user->getDisplayName(), 'onclick="joms.api.streamShowOthers(' . $act->id . ');return false;"', count($users) - 1, $targetUrl, $target->getDisplayName(), $url); } } else { $activityString = Jtext::sprintf('COM_COMMUNITY_ACTIVITIES_COMMENT_OTHERS_VIDEO', $ownerUrl, $targetName, $targetUrl, $target->getDisplayName(), $url); } } else { //user comment on his own photo $activityString = Jtext::sprintf('COM_COMMUNITY_ACTIVITIES_COMMENT_OWN_VIDEO', CUrlHelper::userLink($user->id), $user->getDisplayName(), $url); } $isVideoModal = $config->get('video_mode') == 1; if ($video->type === 'file') { $storage = CStorage::getStorage($video->storage); $path = $storage->getURI($video->path); } else { $path = $video->path; } ?> <div class="joms-stream__header"> <div class= "joms-avatar--stream"> <a href="<?php echo CUrlHelper::userLink($user->id); ?> "> <img data-author="<?php echo $user->id; ?>
<div id="cGallery"> <script type="text/javascript"> joms.gallery.bindKeys(); var jsPlaylist = { album: <?php echo $album->id; ?> , photos: [ <?php if ($photos) { CFactory::load('libraries', 'storage'); CFactory::load('helpers', 'image'); for ($i = 0; $i < count($photos); $i++) { $photo =& $photos[$i]; $storage = CStorage::getStorage($photo->storage); $imgpath = str_replace('/', DS, $photo->original); ?> {id: <?php echo $photo->id; ?> , loaded: false, caption: '<?php echo addslashes($photo->caption); ?> ', thumbnail: '<?php echo $photo->getThumbURI(); ?> ',
$url = CUrlHelper::eventLink($cTable->id); } } else { $extraMessage = ''; } } $messageHTML = JText::sprintf('COM_COMMUNITY_PHOTOS_COVER_UPLOAD', strtolower(Jtext::_('COM_COMMUNITY_COVER_' . strtoupper($type)))) . $extraMessage; } else { $messageHTML = JText::_('COM_COMMUNITY_PHOTOS_COVER_UPLOAD_PROFILE'); } /** * Get cover path */ $coverPath = $params->get('attachment'); if (!file_exists($coverPath)) { $s3 = CStorage::getStorage('s3'); $coverPath = $s3->getURI($coverPath); } else { $coverPath = JURI::root() . $coverPath; } $isPhotoModal = $config->get('album_mode') == 1; ?> <div class="joms-stream__header"> <div class= "joms-avatar--stream"> <a href="<?php echo CUrlHelper::userLink($user->id); ?> "> <img data-author="<?php echo $user->id;
/** * @todo get coverUri and avatarUri should use same function to prevent duplicate code * @param type $file * @param type $default * @return string */ public static function coverURI($file = '', $default = '') { $config = CFactory::getConfig(); $storage = CStorage::getStorage($config->get('photostorage')); /* Default cover */ if (empty($file) || !$storage->exists($file)) { $template = new CTemplateHelper(); $asset = $template->getTemplateAsset($default, 'images'); $uri = $asset->url; return $uri; } if ($config->get('photostorage') == 'file') { $file = str_ireplace($config->get('imagecdnpath'), '', $file); // CDN or local $baseUrl = $config->get('imagebaseurl') or $baseUrl = JURI::root(); $uri = str_replace('\\', '/', rtrim($baseUrl, '/') . '/' . ltrim($file, '/')); return $uri; } else { return $storage->getURI($file); } }
/** * Method to display video * @return void */ public function video() { $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $document = JFactory::getDocument(); $config = CFactory::getConfig(); $my = CFactory::getUser(); $requestUser = CFactory::getRequestUser(); $videoId = $jinput->get('videoid', '', 'INT'); $task = $jinput->getCmd('task'); // Get show video location map by default $videoMapsDefault = $config->get('videosmapdefault'); // Load window library CWindow::load(); $video = JTable::getInstance('Video', 'CTable'); if (empty($videoId)) { if ($jinput->get('videoid', '', 'INT')) { $videoId = $jinput->get('videoid', '', 'INT'); } else { $url = CRoute::_('index.php?option=com_community&view=videos', false); $mainframe->redirect($url, JText::_('COM_COMMUNITY_VIDEOS_ID_ERROR'), 'warning'); } } if (!$video->load($videoId)) { $url = CRoute::_('index.php?option=com_community&view=videos', false); $mainframe->redirect($url, JText::_('COM_COMMUNITY_VIDEOS_NOT_AVAILABLE'), 'warning'); } if ($video->groupid) { JRequest::setVar('groupid', $video->groupid); } elseif ($video->eventid) { JRequest::setVar('eventid', $video->eventid); } // Setting up the sub menu if (COwnerHelper::isCommunityAdmin() || $my->id == $video->creator && $my->id != 0) { $this->addSubmenuItem('', JText::_('COM_COMMUNITY_VIDEOS_FETCH_THUMBNAIL'), "joms.api.videoFetchThumbnail('" . $video->id . "');", true); // Only add the set as profile video for video owner if ($my->id == $video->creator && $config->get('enableprofilevideo')) { $this->addSubmenuItem('', JText::_('COM_COMMUNITY_VIDEOS_SET_AS_PROFILE'), "joms.api.videoLinkToProfile('" . $video->id . "');", true); } $redirectUrl = CRoute::getURI(false); $this->addSubmenuItem('', JText::_('COM_COMMUNITY_EDIT'), "joms.api.videoEdit('" . $video->id . "');", true); $this->addSubmenuItem('', JText::_('COM_COMMUNITY_DELETE'), "joms.api.videoRemove('" . $video->id . "');", true); } $this->_addSubmenu(); // Show the mini header when viewing other's photos if ($video->creator_type == VIDEO_USER_TYPE && $my->id != $video->creator) { // $this->attachMiniHeaderUser($video->creator); } // Check permission $user = CFactory::getUser($video->creator); $blocked = $user->isBlocked(); if ($blocked && !COwnerHelper::isCommunityAdmin()) { $tmpl = new CTemplate(); echo $tmpl->fetch('profile.blocked'); return; } $sorted = $jinput->get('sort', 'latest', 'STRING'); $limit = $jinput->get('limitstart', 6, 'INT'); $permissions = $my->id == 0 ? 0 : 20; $cat_id = $jinput->get('cat_id', '', 'INT'); $model = CFactory::getModel('videos'); /* We get groupid from video table instead user input */ $groupId = $video->groupid; if ($video->creator_type == VIDEO_GROUP_TYPE) { if (!CGroupHelper::allowViewMedia($groupId)) { /** * Opengraph */ CHeadHelper::setType('website', JText::_('COM_COMMUNITY_RESTRICTED_ACCESS')); $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_RESTRICTED_ACCESS', 'notice')); echo JText::_('COM_COMMUNITY_GROUPS_VIDEO_MEMBER_PERMISSION'); return; } $group = JTable::getInstance('Group', 'CTable'); $group->load($groupId); // Set pathway $pathway = $mainframe->getPathway(); $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_VIDEOS'), CRoute::_('index.php?option=com_community&view=videos&task=display&groupid=' . $groupId)); $pathway->addItem($video->getTitle(), ''); $otherVideos = $model->getGroupVideos($groupId, $cat_id, $limit); } else { if (!$this->isPermitted($my->id, $video->creator, $video->permissions)) { /** * Opengraph */ CHeadHelper::setType('website', JText::_('COM_COMMUNITY_RESTRICTED_ACCESS')); $mainframe->enqueueMessage(JText::_('COM_COMMUNITY_RESTRICTED_ACCESS', 'notice')); switch ($video->permissions) { case '40': $this->noAccess(JText::_('COM_COMMUNITY_VIDEOS_OWNER_ONLY', 'notice')); break; case '30': $owner = CFactory::getUser($video->creator); $this->noAccess(JText::sprintf('COM_COMMUNITY_VIDEOS_FRIEND_PERMISSION_MESSAGE', $owner->getDisplayName())); break; default: $this->noAccess(); break; } return; } // Set pathway $pathway = $mainframe->getPathway(); $pathway->addItem('Video', CRoute::_('index.php?option=com_community&view=videos')); $pathway->addItem($video->getTitle(), ''); $filters = array('status' => 'ready', 'category_id' => $cat_id, 'creator' => $user->id, 'permissions' => $permissions, 'or_group_privacy' => 0, 'sorting' => $sorted, 'limit' => $limit); $otherVideos = $model->getVideos($filters); } // Set the current user's active profile CFactory::setActiveProfile($video->creator); // Hit counter + 1 $video->hit(); // Get reporting html $reportHTML = ''; $report = new CReportingLibrary(); if ($user->id != $my->id) { $reportHTML = $report->getReportingHTML(JText::_('COM_COMMUNITY_VIDEOS_REPORT_VIDEOS'), 'videos,reportVideo', array($video->id)); } // Get bookmark html $bookmarks = new CBookmarks($video->getPermalink()); $bookmarksHTML = $bookmarks->getHTML(); // Get the walls $wallContent = CWallLibrary::getWallContents('videos', $video->id, COwnerHelper::isCommunityAdmin() || $my->id == $video->creator && $my->id != 0, $config->get('stream_default_comments'), 0, 'wall/content', 'videos,video'); $wallCount = CWallLibrary::getWallCount('videos', $video->id); $viewAllLink = CRoute::_('index.php?option=com_community&view=videos&task=app&videoid=' . $video->id . '&app=walls'); $wallViewAll = ''; if ($wallCount > $config->get('stream_default_comments')) { $wallViewAll = CWallLibrary::getViewAllLinkHTML($viewAllLink, $wallCount); } $wallForm = ''; if ($this->isPermitted($my->id, $video->creator, PRIVACY_FRIENDS) || !$config->get('lockvideoswalls')) { $wallForm = CWallLibrary::getWallInputForm($video->id, 'videos,ajaxSaveWall', 'videos,ajaxRemoveWall', $viewAllLink); } $redirectUrl = CRoute::getURI(false); // Get like information. $like = new CLike(); $likeCount = $like->getLikeCount('videos', $video->id); $likeLiked = $like->userLiked('videos', $video->id, $my->id) === COMMUNITY_LIKE; $tmpl = new CTemplate(); if ($video->creator_type == VIDEO_GROUP_TYPE) { $group = JTable::getInstance('Group', 'CTable'); $group->load($groupId); $document = JFactory::getDocument(); $document->addHeadLink($group->getThumbAvatar(), 'image_src', 'rel'); } if ($video->location !== '' && $videoMapsDefault) { $zoomableMap = CMapping::drawZoomableMap($video->location, 220, 150, $video->longitude, $video->latitude); } else { $zoomableMap = ""; } //friend list for video tag $tagging = new CVideoTagging(); $taggedList = $tagging->getTaggedList($video->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 video 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, $video->creator) || COwnerHelper::isMine($my->id, $tagItem->created_by) || COwnerHelper::isMine($my->id, $tagItem->userid)) { $canRemoveTag = 1; } $tagItem->user = $tagUser; $tagItem->canRemoveTag = $canRemoveTag; } if ($video->type == "file") { $storage = CStorage::getStorage($video->storage); $video->path = $storage->getURI($video->path); } $config = CFactory::getConfig(); $canSearch = 1; if ($my->id == 0 && !$config->get('enableguestsearchvideos')) { $canSearch = 0; } CHeadHelper::addOpengraph('og:image', JUri::root() . $video->thumb, true); CHeadHelper::setType('website', $video->title); $video->tagged = $taggedList; echo $tmpl->setMetaTags('video', $video)->set('user', $user)->set('zoomableMap', $zoomableMap)->set('likeCount', $likeCount)->set('canSearch', $canSearch)->set('likeLiked', $likeLiked)->set('redirectUrl', $redirectUrl)->set('wallContent', $wallContent)->set('wallForm', $wallForm)->set('wallCount', $wallCount)->set('wallViewAll', $wallViewAll)->set('bookmarksHTML', $bookmarksHTML)->set('reportHTML', $reportHTML)->set('video', $video)->set('otherVideos', $otherVideos)->set('videoMapsDefault', $videoMapsDefault)->set('wallCount', $wallCount)->set('isGroup', $groupId ? true : false)->set('groupId', $groupId ? $groupId : null)->set('submenu', $this->showSubmenu(false))->fetch('videos/single'); }
public function getThumbAvatar($obj) { // For group avatars that are stored in a remote location, we should return the proper path. if ($obj->storage != 'file' && !empty($obj->thumb)) { $storage = CStorage::getStorage($obj->storage); return $storage->getURI($obj->thumb); } $thumb = CUrlHelper::avatarURI($obj->thumb, 'group_thumb.png'); return $thumb; }
/** * Delete video's files and thumbnails * * @params object $video The video object * @return True on success * @since 1.2 * * */ private function _deleteVideoFiles($video) { // We passed in the video object because of // the table row of $video->id coud be deleted // thus, there's no way to retrive the thumbnail path // and also the flv file path if (!$video) { return; } if (!COwnerHelper::isRegisteredUser()) { return; } $storage = CStorage::getStorage($video->storage); if ($storage->exists($video->thumb)) { $storage->delete($video->thumb); } if ($storage->exists($video->path)) { $storage->delete($video->path); } /* jimport('joomla.filesystem.file'); $files = array(); $thumb = JPATH::clean(JPATH_ROOT .'/'. $video->thumb); if (JFile::exists( $thumb )) { $files[]= $thumb; } if ($video->type == 'file') { $flv = JPATH::clean(JPATH_ROOT .'/'. $video->path); if (JFile::exists($flv)) { $files[]= $flv; } } if (!empty($files)) { return JFile::delete($files); } */ return true; }
private function _processFileStorage($updateNum = 5) { $config = CFactory::getConfig(); //$jconfig = JFactory::getConfig(); $app = JFactory::getApplication(); $fileStorage = $config->getString('file_storage'); if ($fileStorage != 'file') { $fileTranferCount = 0; $storage = CStorage::getStorage($fileStorage); $db = JFactory::getDBO(); $sql = 'SELECT * FROM ' . $db->quoteName('#__community_files') . ' WHERE ' . $db->quoteName('storage') . '!=' . $db->Quote($fileStorage) . ' ORDER BY rand() limit ' . $updateNum; $db->setQuery($sql); $result = $db->loadObjectList(); if (!$result) { $this->_message[] = JText::_('No files to transfer.'); return; } foreach ($result as $row) { $currentStorage = CStorage::getStorage($row->storage); if ($currentStorage->exists($row->filepath)) { // File exist on remote storage, move it locally first //$tempFilename = $jconfig->getValue('tmp_path').'/'. md5($row->filepath); $tempFilename = $app->getCfg('tmp_path') . '/' . md5($row->filepath); $currentStorage->get($row->filepath, $tempFilename); if (JFile::exists($tempFilename)) { if ($storage->put($row->filepath, $tempFilename)) { // if the put is successful, update storage type $file = JTable::getInstance('File', 'CTable'); $file->load($row->id); $file->storage = $fileStorage; $file->store(); $currentStorage->delete($row->filepath); // remove temporary file JFile::delete($tempFilename); $fileTranferCount++; } } } } $this->_message[] = $fileTranferCount . ' files transferred. to s3'; } }
/** * Delete video's files and thumbnails * * @params object $video The video object * @return True on success * @since 1.2 * **/ private function _deleteVideoFiles($video) { if (!$video) { return; } if (!COwnerHelper::isRegisteredUser()) { return; } CFactory::load('libraries', 'storage'); $storage = CStorage::getStorage($video->storage); if ($storage->exists($video->thumb)) { $storage->delete($video->thumb); } if ($storage->exists($video->path)) { $storage->delete($video->path); } /* jimport('joomla.filesystem.file'); $files = array(); $thumb = JPATH::clean(JPATH_ROOT . DS . $video->thumb); if (JFile::exists( $thumb )) { $files[]= $thumb; } if ($video->type == 'file') { $flv = JPATH::clean(JPATH_ROOT . DS . $video->path); if (JFile::exists($flv)) { $files[]= $flv; } } if (!empty($files)) { return JFile::delete($files); } */ return true; }
/** * Get current Group cover * @return [string] [url] */ public function getCover() { if (empty($this->cover)) { $this->cover = ''; } else { /* if not local than get remote storage */ $storage = CStorage::getStorage($this->storage); return $storage->getURI($this->cover); } return CUrlHelper::coverURI($this->cover, 'cover-group-default.png'); }
/** * This function will regenerate the thumbnail of videos * @param int $id * @param bool $returnThumb * @return bool */ public function _fetchThumbnail($id = 0, $returnThumb = false) { if (!COwnerHelper::isRegisteredUser()) { return; } if (!$id) { return false; } $table = JTable::getInstance('Video', 'CTable'); $table->load($id); $config = CFactory::getConfig(); if ($table->type == 'file') { // We can only recreate the thumbnail for local video file only // it's not possible to process remote video file with ffmpeg if ($table->storage != 'file') { $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . 'FFmpeg cannot process remote video.'); return false; } $videoLib = new CVideoLibrary(); $videoFullPath = JPATH::clean(JPATH_ROOT . '/' . $table->path); if (!JFile::exists($videoFullPath)) { return false; } // Read duration $videoInfo = $videoLib->getVideoInfo($videoFullPath); if (!$videoInfo) { return false; } else { $videoFrame = CVideosHelper::formatDuration((int) ($videoInfo['duration']['sec'] / 2), 'HH:MM:SS'); // Create thumbnail $oldThumb = $table->thumb; $thumbFolder = CVideoLibrary::getPath($table->creator, 'thumb'); $thumbSize = CVideoLibrary::thumbSize(); $thumbFilename = $videoLib->createVideoThumb($videoFullPath, $thumbFolder, $videoFrame, $thumbSize); } if (!$thumbFilename) { return false; } } else { if (!CRemoteHelper::curlExists()) { $this->setError(JText::_('COM_COMMUNITY_CURL_NOT_EXISTS')); return false; } $videoLib = new CVideoLibrary(); $videoObj = $videoLib->getProvider($table->path); if ($videoObj == false) { $this->setError($videoLib->getError()); return false; } if (!$videoObj->isValid()) { $this->setError($videoObj->getError()); return false; } $remoteThumb = $videoObj->getThumbnail(); $thumbData = CRemoteHelper::getContent($remoteThumb, true); if (empty($thumbData)) { $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . $remoteThumb); return false; } // split the header and body list($headers, $body) = explode("\r\n\r\n", $thumbData, 2); preg_match('/Content-Type: image\\/(.*)/i', $headers, $matches); if (!empty($matches)) { $thumbPath = CVideoLibrary::getPath($table->creator, 'thumb'); $thumbFileName = CFileHelper::getRandomFilename($thumbPath); $tmpThumbPath = $thumbPath . '/' . $thumbFileName; if (!JFile::write($tmpThumbPath, $body)) { $this->setError(JText::_('COM_COMMUNITY_INVALID_FILE_REQUEST') . ': ' . $thumbFileName); return false; } // We'll remove the old or none working thumbnail after this $oldThumb = $table->thumb; // Get the image type first so we can determine what extensions to use $info = getimagesize($tmpThumbPath); $mime = image_type_to_mime_type($info[2]); $thumbExtension = CImageHelper::getExtension($mime); $thumbFilename = $thumbFileName . $thumbExtension; $thumbPath = $thumbPath . '/' . $thumbFilename; if (!JFile::move($tmpThumbPath, $thumbPath)) { $this->setError(JText::_('WARNFS_ERR02') . ': ' . $thumbFileName); return false; } // Resize the thumbnails //CImageHelper::resizeProportional( $thumbPath , $thumbPath , $mime , CVideoLibrary::thumbSize('width') , CVideoLibrary::thumbSize('height') ); list($width, $height) = explode('x', $config->get('videosThumbSize')); CImageHelper::resizeAspectRatio($thumbPath, $thumbPath, $width, $height); } else { $this->setError(JText::_('COM_COMMUNITY_PHOTOS_IMAGE_NOT_PROVIDED_ERROR')); return false; } } // Update the DB with new thumbnail $thumb = $config->get('videofolder') . '/' . VIDEO_FOLDER_NAME . '/' . $table->creator . '/' . VIDEO_THUMB_FOLDER_NAME . '/' . $thumbFilename; $table->set('thumb', $thumb); $table->store(); // If this video storage is not on local, we move it to remote storage // and remove the old thumb if existed if ($table->storage != 'file') { // && ($table->storage == $storageType)) $config = CFactory::getConfig(); $storageType = $config->getString('videostorage'); $storage = CStorage::getStorage($storageType); $storage->delete($oldThumb); $localThumb = JPATH::clean(JPATH_ROOT . '/' . $table->thumb); $tempThumbname = JPATH::clean(JPATH_ROOT . '/' . md5($table->thumb)); if (JFile::exists($localThumb)) { JFile::copy($localThumb, $tempThumbname); } if (JFile::exists($tempThumbname)) { $storage->put($table->thumb, $tempThumbname); JFile::delete($localThumb); JFile::delete($tempThumbname); } } else { if (JFile::exists(JPATH_ROOT . '/' . $oldThumb)) { JFile::delete(JPATH_ROOT . '/' . $oldThumb); } } if ($returnThumb) { return $table->getThumbnail(); } return true; }
/** * Delete group's media * * param string id The id of the group. * **/ public static function deleteGroupMedia($gid) { $db = JFactory::getDBO(); $photosModel = CFactory::getModel('photos'); $videoModel = CFactory::getModel('videos'); $fileModel = CFactory::getModel('files'); // group's photos removal. $albums = $photosModel->getGroupAlbums($gid, false, false, 0); foreach ($albums as $item) { $photos = $photosModel->getAllPhotos($item->id, PHOTOS_GROUP_TYPE); foreach ($photos as $row) { $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($row->id); $photo->delete(); } //now we delete group photo album folder $album = JTable::getInstance('Album', 'CTable'); $album->load($item->id); $album->delete(); } //group's videos $featuredVideo = new CFeatured(FEATURED_VIDEOS); $videos = $videoModel->getGroupVideos($gid); foreach ($videos as $vitem) { if (!$vitem) { continue; } $video = JTable::getInstance('Video', 'CTable'); $videaId = (int) $vitem->id; $video->load($videaId); if ($video->delete()) { // Delete all videos related data $videoModel->deleteVideoWalls($videaId); $videoModel->deleteVideoActivities($videaId); //remove featured video $featuredVideo->delete($videaId); //remove the physical file $storage = CStorage::getStorage($video->storage); if ($storage->exists($video->thumb)) { $storage->delete($video->thumb); } if ($storage->exists($video->path)) { $storage->delete($video->path); } } } $fileModel->alldelete($gid, 'group'); return true; }
/** * возвращает основной массив со значениями параметров командной строки * @param string $structTableName - имя таблицы с информацией о структуре параметров командной строки * @param bool $post - true, если брать значения из POST-переменных * @param string $dirName - путь к каталогу с таблицей командной строки * @param bool $useStructBlock - если true, то для загрузки структуры использовать блок <struct> xml-файла * @return MainArray - значения параметров командной строки */ function getFileParameters_($structTableName, $post, $dirName, $useStructBlock = false) { $getType = "get"; if ($post) { $getType = "post"; } $fullFName = $dirName . "/{$structTableName}.xml"; if ($dirName == "") { $fullFName = "{$structTableName}.xml"; } $key = $fullFName . "-" . $getType; $instanceName = "<b>{$structTableName}</b> from {$getType}"; $MA1 = $this->m_cacheAr[$key]; if (is_object($MA1)) { $MA = new CFW_XML_Table($instanceName); $MA1->copyStructureInto($MA); $MA->m_xml = $MA1->m_xml; //копирование древовидной xml-структуры данных файла. Она может быть полезна при низкоуровневом чтении блока STRUCT основного массива $MA->copyFrom($MA1, 1, 1, $MA1->getRecordsNumber()); return $MA; } $httpVarsArray = array(); if ($post) { foreach ($_POST as $var => $val) { $httpVarsArray[$var] = $val; } } else { foreach ($_GET as $var => $val) { $httpVarsArray[$var] = $val; } } if (!$useStructBlock) { $paramsStruct = $this->m_storage->getMA($structTableName, $dirName, "CFW_XML_Table"); $FP = new CMainArray("CMainArray"); for ($i = 1; $i <= $paramsStruct->getRecordsNumber(); $i++) { $dbFieldName = $paramsStruct->getVal(SYS_FW_FP__NAME, $i); $dbFieldType = $paramsStruct->getVal(SYS_FW_FP__TYPE, $i); $VB_id = $paramsStruct->getVal(SYS_FW_FP__VB_ID, $i); //data type for i-nth field $FP->_setFieldType($i, $dbFieldName, $dbFieldType, $VB_id); // /data type for i-nth field //value for for i-nth field $val = $httpVarsArray[$dbFieldName]; $val = str_replace("\\\"", "\"", $val); $val = STARTER_sequreUrl($val); $FP->setVal($i, $val); // /value for for i-nth field } $FP->setFieldsNumber($paramsStruct->getRecordsNumber()); $FP->setRecordsNumber(1); } else { $FP = new CFW_XML_Table("<b>{$structTableName}</b> from {$getType}"); $FP->setDebugMode(true); $code = $FP->load($fullFName, true); for ($i = 1; $i <= $FP->getFieldsNumber(); $i++) { $dbFieldName = $FP->getDBFieldName($i); $val = $httpVarsArray[$dbFieldName]; $val = str_replace("\\\"", "\"", $val); $val = STARTER_sequreUrl($val); $FP->setVal($i, $val); } $FP->setRecordsNumber(1); } $this->m_cacheAr[$key] = $FP; return $FP; }
/** * Return the exist URL to be displayed. * @param size string, (normal, origianl, small) */ public function getImageURI($size = 'normal') { $uri = ''; if ($this->storage != 'file') { $storage = CStorage::getStorage($this->storage); $uri = $storage->getURI($this->image); } else { $config = CFactory::getConfig(); $baseUrl = $config->get('photobaseurl'); if (!empty($baseUrl)) { if (JFile::exists(JPATH_ROOT . '/' . $this->image)) { //$uri = rtrim( $baseUrl , '/' ) . '/' . $this->image; // Strip cdn path if necessary $path = $this->image; $cdnpath = $config->get('photocdnpath'); if ($cdnpath) { $path = str_replace($cdnpath, '', $path); } $path = ltrim($path, '/'); $uri = rtrim($baseUrl, '/') . '/' . $path; } else { $uri = JURI::root() . 'index.php?option=com_community&view=photos&task=showimage&tmpl=component&imgid=' . $this->image; } } else { // If the resized photos exist, use it instead if (JFile::exists(JPATH_ROOT . '/' . $this->image)) { $uri = JURI::root() . $this->image; } else { $uri = JURI::root() . 'index.php?option=com_community&view=photos&task=showimage&tmpl=component&imgid=' . $this->image; } } } return $uri; }
/** * Return path to thumb image */ public function getThumbAvatar() { // @rule: Check if the current user's watermark matches the current system's watermark. $multiprofile =& JTable::getInstance('MultiProfile', 'CTable'); $match = $multiprofile->isHashMatched($this->_profile_id, $this->_watermark_hash); if (!$match) { // @rule: Since the admin may have changed the watermark for the specific user profile type, we need to also update // the user's watermark as well. CFactory::load('helpers', 'image'); $hashName = CImageHelper::getHashName($this->id . time()); $multiprofile->updateUserAvatar($this, $hashName); $multiprofile->updateUserThumb($this, $hashName); } if (JString::stristr($this->_thumb, 'default_thumb.jpg')) { $this->_thumb = ''; } // For user avatars that are stored in a remote location, we should return the proper path. // @rule: For default avatars and watermark avatars we don't want to alter the url behavior. // as it should be stored locally. if ($this->_storage != 'file' && !empty($this->_thumb) && JString::stristr($this->_thumb, 'images/watermarks') === false) { $storage = CStorage::getStorage($this->_storage); return $storage->getURI($this->_thumb); } CFactory::load('helpers', 'url'); $thumb = CUrlHelper::avatarURI($this->_thumb, 'user_thumb.png'); return $thumb; }
public function getFlv() { $flv = ''; if ($this->type != 'file') { return $flv; } $config = CFactory::getConfig(); $baseUrl = $config->get('videobaseurl'); if ($config->get('enablevideopseudostream') && $this->storage == 'file' && empty($baseUrl)) { $flv = JURI::root() . 'components/com_community/libraries/streamer.php/' . urlencode($this->path); } else { if (!empty($baseUrl)) { $flv = rtrim($baseUrl, '/') . '/' . $this->path; } else { $storage = CStorage::getStorage($this->storage); $flv = $storage->getURI($this->path); } } return $flv; }
public function ajaxRotatePhoto($photoId, $orientation) { CFactory::load('helpers', 'owner'); if (!COwnerHelper::isRegisteredUser()) { return $this->ajaxBlockUnregister(); } $photo =& JTable::getInstance('Photo', 'CTable'); $photo->load($photoId); if ($photo->storage != 'file') { // we don't want to support s3 return false; } if ($photo->storage != 'file') { // download the image files to local server CFactory::load('libraries', 'storage'); $storage = CStorage::getStorage($photoStorage); $currentStorage = CStorage::getStorage($photo->storage); if ($currentStorage->exists($photo->image)) { $jconfig = JFactory::getConfig(); $jTempPath = $jconfig->getValue('tmp_path'); $tempFilename = $jTempPath . DS . md5($photo->image); $currentStorage->get($photo->image, $tempFilename); $thumbsTemp = $jTempPath . DS . 'thumb_' . md5($photo->thumbnail); $currentStorage->get($photo->thumbnail, $thumbsTemp); if (JFile::exists($tempFilename) && JFile::exists($thumbsTemp) && $storage->put($row->image, $tempFilename) && $storage->put($photo->thumbnail, $thumbsTemp)) { $currentStorage->delete($photo->image); $currentStorage->delete($photo->thumbnail); JFile::delete($tempFilename); JFile::delete($thumbsTemp); } } } $photoPath = JPath::clean(JPATH_ROOT . DS . $photo->image); $thumbPath = JPath::clean(JPATH_ROOT . DS . $photo->thumbnail); // Hash the image file name so that it gets as unique possible $fileName = JUtility::getHash($photo->image . time()); $fileName = JString::substr($fileName, 0, 24); $fileName = $fileName . '.' . JFile::getExt($photo->image); $fileNameLength = strlen($photo->image) - strrpos($photo->image, '/') - 1; $newPhotoPath = substr_replace($photoPath, $fileName, -$fileNameLength); $newThumbPath = substr_replace($photoPath, 'thumb_' . $fileName, -$fileNameLength); $degrees = 0; if (JFile::exists($photoPath) && JFile::exists($thumbPath)) { switch ($orientation) { case 'left': $degrees = 90; break; case 'right': $degrees = -90; break; default: $degrees = 0; break; } if ($degrees !== 0) { CFactory::load('helpers', 'image'); CImageHelper::rotate($photoPath, $newPhotoPath, $degrees); CImageHelper::rotate($thumbPath, $newThumbPath, $degrees); $newPhotoPath = JString::str_ireplace(JPATH_ROOT . DS, '', $newPhotoPath); $newThumbPath = JString::str_ireplace(JPATH_ROOT . DS, '', $newThumbPath); $newPhotoPath = JString::str_ireplace('\\', '/', $newPhotoPath); $newThumbPath = JString::str_ireplace('\\', '/', $newThumbPath); $photo->storage = 'file'; //just to make sure it's in the local server $photo->image = $newPhotoPath; $photo->thumbnail = $newThumbPath; $photo->store(); } } $response = new JAXResponse(); $response->addScriptCall('__callback', $photo->id, $photo->getImageURI(), $photo->getThumbURI()); return $response->sendResponse(); }
function manage_storage_by_dir($dir) { $root_patt = prepare_pattern(config_get('storage-root')); if (!preg_match('/' . $root_patt . '/', $dir)) { return null; } $dir = preg_replace('/' . $root_patt . '/', '', $dir); $id = db_field_value('storage', 'id', '`path`="' . addslashes($dir) . '"'); if ($id > 0) { $storage = new CStorage(); $storage->Init($id); return $storage; } return null; }
/** * Get user cover Url * @return string */ public function getCover() { $config = CFactory::getConfig(); $storage = CStorage::getStorage($config->get('user_avatar_storage')); $storages['file'] = 'file'; $storages['s3'] = 's3'; if (!$storage->exists($this->_cover)) { unset($storages[$config->get('user_avatar_storage')]); $storages = array_pop($storages); $storage = CStorage::getStorage($storages); } if (empty($this->_cover) || !$storage->exists($this->_cover)) { $profileModel = CFactory::getModel('Profile'); $gender = $profileModel->getGender($this->id); $tGender = strtoupper($gender); /* Not use translate string yet */ if (strpos($tGender, 'COM_COMMUNITY_') === false) { /* But it must be default English string */ $tGender = 'COM_COMMUNITY_' . $tGender; /* Adding prefix translate string */ } /* Now we have translate string already. Let's determine gender ( No shemale here ) */ // theme designer files first switch ($tGender) { case 'COM_COMMUNITY_MALE': $gender = 'male-default'; $td_cover = 'default-cover-male'; break; case 'COM_COMMUNITY_FEMALE': $gender = 'female-default'; $td_cover = 'default-cover-female'; break; default: $gender = 'undefined-default'; $td_cover = 'default-cover'; break; } $template = new CTemplateHelper(); // Theme designer cover if (file_exists(COMMUNITY_PATH_ASSETS . $td_cover . '.png')) { return JUri::root() . str_replace(JPATH_ROOT, '', COMMUNITY_PATH_ASSETS) . "{$td_cover}.png"; } if (file_exists(COMMUNITY_PATH_ASSETS . $td_cover . '.jpg')) { return JUri::root() . str_replace(JPATH_ROOT, '', COMMUNITY_PATH_ASSETS) . "{$td_cover}.jpg"; } // Default cover if (file_exists(COMMUNITY_PATH_ASSETS . 'cover-' . $gender . '.png')) { return JUri::root() . str_replace(JPATH_ROOT, '', COMMUNITY_PATH_ASSETS) . 'cover-' . $gender . '.png'; } if (file_exists(COMMUNITY_PATH_ASSETS . 'cover-' . $gender . '.jpg')) { return JUri::root() . str_replace(JPATH_ROOT, '', COMMUNITY_PATH_ASSETS) . 'cover-' . $gender . '.jpg'; } // Template cover $asset = $template->getTemplateAsset('cover-' . $gender . '.jpg', 'images'); $uri = $asset->url; if (strlen($uri)) { return $uri; } $asset = $template->getTemplateAsset('cover-' . $gender . '.png', 'images'); $uri = $asset->url; if (strlen($uri)) { return $uri; } } else { /* if not local storage than get remote storage */ $storage = CStorage::getStorage($this->_storage); return $storage->getURI($this->_cover); } $avatar = CUrlHelper::coverURI($this->_cover, ''); return $avatar; }