/** * Initialize the video with a new url */ public function init($url) { // create the provider // $this->_provider should be null here $videoLib = new CVideoLibrary(); $this->_provider = $videoLib->getProvider($url); $isValid = $this->_provider->isValid(); if ($isValid) { $this->title = $this->_provider->getTitle(); $this->type = $this->_provider->getType(); $this->video_id = $this->_provider->getId(); $this->duration = $this->_provider->getDuration(); $this->status = 'ready'; $this->thumb = $this->_provider->getThumbnail(); $this->path = $url; $this->description = str_replace(array("\r", "\n"), " ", $this->_provider->getDescription()); // remove line break from description $this->status = 'ready'; } return $isValid; }
/** * Ajax function to save a new wall entry * * @param message A message that is submitted by the user * @param uniqueId The unique id for this group * **/ function ajaxSaveWall($response, $message, $uniqueId, $cache_id = "") { $my = CFactory::getUser(); $user = CFactory::getUser($uniqueId); $config = CFactory::getConfig(); JPlugin::loadLanguage('plg_walls', JPATH_ADMINISTRATOR); // Load libraries CFactory::load('models', 'photos'); CFactory::load('libraries', 'wall'); CFactory::load('helpers', 'url'); CFactory::load('libraries', 'activities'); $message = JString::trim($message); $message = strip_tags($message); if (empty($message)) { $response->addAlert(JText::_('PLG_WALLS_PLEASE_ADD_MESSAGE')); } else { $maxchar = $this->params->get('charlimit', 0); if (!empty($maxchar)) { $msglength = strlen($message); if ($msglength > $maxchar) { $message = substr($message, 0, $maxchar); } } // @rule: Spam checks if ($config->get('antispam_akismet_walls')) { CFactory::load('libraries', 'spamfilter'); $filter = CSpamFilter::getFilter(); $filter->setAuthor($my->getDisplayName()); $filter->setMessage($message); $filter->setEmail($my->email); $filter->setURL(CRoute::_('index.php?option=com_community&view=profile&userid=' . $user->id)); $filter->setType('message'); $filter->setIP($_SERVER['REMOTE_ADDR']); if ($filter->isSpam()) { $response->addAlert(JText::_('COM_COMMUNITY_WALLS_MARKED_SPAM')); return $response->sendResponse(); } } $wall = CWallLibrary::saveWall($uniqueId, $message, 'user', $my, $my->id == $user->id, 'profile,profile'); CFactory::load('libraries', 'activities'); CFactory::load('helpers', 'videos'); $matches = cGetVideoLinkMatches($message); $activityParams = ''; // We only want the first result of the video to be in the activity if ($matches) { $videoLink = $matches[0]; CFactory::load('libraries', 'videos'); $videoLib = new CVideoLibrary(); $provider = $videoLib->getProvider($videoLink); $activityParams .= 'videolink=' . $videoLink . "\r\n"; if ($provider->isValid()) { $activityParams .= 'url=' . $provider->getThumbnail(); } } $act = new stdClass(); $act->cmd = 'profile.wall.create'; $act->actor = $my->id; $act->target = $uniqueId; $act->title = JText::_('COM_COMMUNITY_ACTIVITIES_WALL_POST_PROFILE'); $act->content = ''; $act->app = 'walls'; $act->cid = $wall->id; // Allow comments on all these $act->comment_id = CActivities::COMMENT_SELF; $act->comment_type = 'walls'; CActivityStream::add($act, $activityParams); // @rule: Send notification to the profile user. if ($my->id != $user->id) { CFactory::load('libraries', 'notification'); $params = new CParameter(''); $params->set('url', 'index.php?option=com_community&view=profile&userid=' . $user->id); $params->set('message', $message); CNotificationLibrary::add('etype_profile_submit_wall', $my->id, $user->id, JText::sprintf('PLG_WALLS_NOTIFY_EMAIL_SUBJECT', $my->getDisplayName()), '', 'profile.wall', $params); } //add user points CFactory::load('libraries', 'userpoints'); CUserPoints::assignPoint('profile.wall.create'); $response->addScriptCall('joms.walls.insert', $wall->content); $response->addScriptCall('if(joms.jQuery(".content-nopost").length){ joms.jQuery("#wall-empty-container").remove(); }'); $cache =& JFactory::getCache('plgCommunityWalls'); $cache->remove($cache_id); $cache =& JFactory::getCache('plgCommunityWalls_fullview'); $cache->remove($cache_id); } return $response; }
/** * 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; }
/** * Initialize the video with a new url */ public function init($url) { // create the provider // $this->_provider should be null here CFactory::load('libraries', 'videos'); $videoLib = new CVideoLibrary(); $this->_provider = $videoLib->getProvider($url); $isValid = $this->_provider->isValid(); if ($isValid) { $this->title = $this->_provider->getTitle(); $this->type = $this->_provider->getType(); $this->video_id = $this->_provider->getId(); $this->duration = $this->_provider->getDuration(); $this->status = 'ready'; $this->thumb = $this->_provider->getThumbnail(); $this->path = $url; $this->description = $this->_provider->getDescription(); $this->status = 'ready'; } return $isValid; }
/** * Ajax function to save a new wall entry * * @param message A message that is submitted by the user * @param uniqueId The unique id for this group * **/ function ajaxSaveWall($response, $message, $uniqueId, $cache_id = "") { $my = CFactory::getUser(); $user = CFactory::getUser($uniqueId); JPlugin::loadLanguage('plg_walls', JPATH_ADMINISTRATOR); // Load libraries CFactory::load('models', 'photos'); CFactory::load('libraries', 'wall'); CFactory::load('helpers', 'url'); CFactory::load('libraries', 'activities'); $message = JString::trim($message); $message = strip_tags($message); if (empty($message)) { $response->addAlert(JText::_('PLG_WALLS PLEASE ADD MESSAGE')); } else { $maxchar = $this->params->get('charlimit', 0); if (!empty($maxchar)) { $msglength = strlen($message); if ($msglength > $maxchar) { $message = substr($message, 0, $maxchar); } } $wall = CWallLibrary::saveWall($uniqueId, $message, 'user', $my, $my->id == $user->id, 'profile,profile'); CFactory::load('libraries', 'activities'); CFactory::load('helpers', 'videos'); $matches = cGetVideoLinkMatches($message); $activityParams = ''; // We only want the first result of the video to be in the activity if ($matches) { $videoLink = $matches[0]; CFactory::load('libraries', 'videos'); $videoLib = new CVideoLibrary(); $provider = $videoLib->getProvider($videoLink); $activityParams .= 'videolink=' . $videoLink . "\r\n"; if ($provider->isValid()) { $activityParams .= 'url=' . $provider->getThumbnail(); } } $act = new stdClass(); $act->cmd = 'profile.wall.create'; $act->actor = $my->id; $act->target = $uniqueId; $act->title = JText::_('CC ACTIVITIES WALL POST PROFILE'); $act->content = '{plugins,walls,getWallActivityContent}'; $act->app = 'walls'; $act->cid = $wall->id; CActivityStream::add($act, $activityParams); // @rule: Send notification to the profile user. if ($my->id != $user->id) { CFactory::load('libraries', 'notification'); $params = new JParameter(''); $params->set('url', 'index.php?option=com_community&view=profile&userid=' . $user->id); $params->set('message', $message); CNotificationLibrary::add('profile.submit.wall', $my->id, $user->id, JText::sprintf('PLG_WALLS NOTIFY EMAIL SUBJECT', $my->getDisplayName()), '', 'profile.wall', $params); } //add user points CFactory::load('libraries', 'userpoints'); CUserPoints::assignPoint('profile.wall.create'); $response->addScriptCall('joms.walls.insert', $wall->content); $response->addScriptCall('if(joms.jQuery(".content-nopost").length){ joms.jQuery("#wall-empty-container").remove(); }'); $cache =& JFactory::getCache('plgCommunityWalls'); $cache->remove($cache_id); $cache =& JFactory::getCache('plgCommunityWalls_fullview'); $cache->remove($cache_id); } return $response; }