public function mapAvatar($avatarUrl = '', $joomlaUserId, $addWaterMark) { $image = ''; if (!empty($avatarUrl)) { // Make sure user is properly added into the database table first $user = CFactory::getUser($joomlaUserId); $fbUser = $this->getUser(); // Store image on a temporary folder. $tmpPath = JPATH_ROOT . '/images/originalphotos/facebook_connect_' . $fbUser; // Need to extract the non-https version since it will cause // certificate issue $avatarUrl = str_replace('https://', 'http://', $avatarUrl); $source = CRemoteHelper::getContent($avatarUrl, true); list($headers, $source) = explode("\r\n\r\n", $source, 2); JFile::write($tmpPath, $source); // @todo: configurable width? $imageMaxWidth = 160; // Get a hash for the file name. $fileName = JApplication::getHash($fbUser . time()); $hashFileName = JString::substr($fileName, 0, 24); $uri_parts = explode('?', $avatarUrl, 2); $extension = JString::substr($uri_parts[0], JString::strrpos($uri_parts[0], '.')); $type = 'image/jpg'; if ($extension == '.png') { $type = 'image/png'; } if ($extension == '.gif') { $type = 'image/gif'; } //@todo: configurable path for avatar storage? $config = CFactory::getConfig(); $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar'; $storageImage = $storage . '/' . $hashFileName . $extension; $storageThumbnail = $storage . '/thumb_' . $hashFileName . $extension; $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . $extension; $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . $extension; $userModel = CFactory::getModel('user'); // Only resize when the width exceeds the max. CImageHelper::resizeProportional($tmpPath, $storageImage, $type, $imageMaxWidth); CImageHelper::createThumb($tmpPath, $storageThumbnail, $type); if ($addWaterMark) { // Get the width and height so we can calculate where to place the watermark. list($watermarkWidth, $watermarkHeight) = getimagesize(FACEBOOK_FAVICON); list($imageWidth, $imageHeight) = getimagesize($storageImage); list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail); CImageHelper::addWatermark($storageImage, $storageImage, $type, FACEBOOK_FAVICON, $imageWidth - $watermarkWidth, $imageHeight - $watermarkHeight); CImageHelper::addWatermark($storageThumbnail, $storageThumbnail, $type, FACEBOOK_FAVICON, $thumbWidth - $watermarkWidth, $thumbHeight - $watermarkHeight); } // Update the CUser object with the correct avatar. $user->set('_thumb', $thumbnail); $user->set('_avatar', $image); // @rule: once user changes their profile picture, storage method should always be file. $user->set('_storage', 'file'); $userModel->setImage($joomlaUserId, $image, 'avatar'); $userModel->setImage($joomlaUserId, $thumbnail, 'thumb'); $user->save(); } }
/** * Fetch google map data refere to * http://code.google.com/apis/maps/documentation/geocoding/#Geocoding */ public static function getAddressData($address) { $url = CMapping::GEOCODE_URL . 'address=' . urlencode($address) . '&sensor=false'; $content = CRemoteHelper::getContent($url); $status = null; if (!empty($content)) { $json = new Services_JSON(); $status = $json->decode($content); } return $status; }
function isValid() { // Connect and get the remote video CFactory::load('helpers', 'remote'); $this->xmlContent = CRemoteHelper::getContent($this->getFeedUrl()); if (empty($this->videoId)) { $this->setError(JText::_('CC INVALID VIDEO ID')); return false; } if ($this->xmlContent == false) { $this->setError(JText::_('CC ERROR FETCHING VIDEO')); return false; } return true; }
function isValid() { // Connect and get the remote video CFactory::load('helpers', 'remote'); $this->xmlContent = CRemoteHelper::getContent($this->getFeedUrl()); $videoId = $this->getId(); if (empty($videoId) || $this->xmlContent == 'Invalid id') { $this->setError(JText::_('CC INVALID VIDEO ID')); return false; } if ($this->xmlContent == false) { $this->setError(JText::_('CC ERROR FETCHING VIDEO')); return false; } if ($this->xmlContent == 'Video not found') { $this->setError(JText::_('CC YOUTUBE VIDEO NOT FOUND')); return false; } return true; }
function isValid() { // Connect and get the remote video CFactory::load('helpers', 'remote'); $xmlContent = CRemoteHelper::getContent($this->getFeedUrl()); if (empty($this->videoId)) { $this->setError(JText::_('CC INVALID VIDEO ID')); return false; } if ($xmlContent == FALSE) { $this->setError(JText::_('CC ERROR FETCHING VIDEO')); return false; } $options['rssUrl'] = $this->getFeedUrl(); $rssDoc = JFactory::getXMLParser('RSS', $options); foreach ($rssDoc->get_items() as $item) { $enclosures = $item->get_enclosures(); $this->duration = $enclosures[0]->get_duration(); $this->title = $item->get_title(); $this->description = $item->get_description(); } return true; }
/** * Links an existing photo in the system and use it as the profile picture * * */ public function linkPhoto() { $id = JRequest::getInt('id', 0, 'POST'); $photoModel = CFactory::getModel('Photos'); $my = CFactory::getUser(); if ($my->id == 0) { return $this->blockUnregister(); } if ($id == 0) { echo JText::_('COM_COMMUNITY_PHOTOS_INVALID_PHOTO_ID'); return; } $photo = JTable::getInstance('Photo', 'CTable'); $photo->load($id); if ($my->id != $photo->creator) { echo JText::_('COM_COMMUNITY_ACCESS_DENIED'); return; } jimport('joomla.filesystem.file'); jimport('joomla.utilities.utility'); $view = $this->getView('profile'); //CFactory::load( 'helpers' , 'image' ); $my = CFactory::getUser(); if ($my->id == 0) { return $this->blockUnregister(); } $mainframe = JFactory::getApplication(); // @todo: configurable width? $imageMaxWidth = 160; // Get a hash for the file name. $fileName = JApplication::getHash($photo->id . time()); $hashFileName = JString::substr($fileName, 0, 24); $photoPath = JPATH_ROOT . '/' . $photo->image; //$photo->original; if ($photo->storage == 'file') { // @rule: If photo original file still exists, we will use the original file. if (!JFile::exists($photoPath)) { $photoPath = JPATH_ROOT . '/' . $photo->image; } // @rule: If photo still doesn't exists, we should not allow the photo to be changed. if (!JFile::exists($photoPath)) { $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=uploadAvatar', false), JText::_('COM_COMMUNITY_PHOTOS_SET_AVATAR_ERROR'), 'error'); return; } } else { //CFactory::load( 'helpers' , 'remote' ); $content = CRemoteHelper::getContent($photo->getImageURI()); if (!$content) { $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=uploadAvatar', false), JText::_('COM_COMMUNITY_PHOTOS_SET_AVATAR_ERROR'), 'error'); return; } //$jConfig = JFactory::getConfig(); //$photoPath = $jConfig->getValue('tmp_path').'/'.md5( $photo->image); $photoPath = $mainframe->getCfg('tmp_path') . '/' . md5($photo->image); // Store image on temporary location JFile::write($photoPath, $content); } $info = getimagesize($photoPath); $extension = CImageHelper::getExtension($info['mime']); $config = CFactory::getConfig(); $storage = JPATH_ROOT . '/' . $config->getString('imagefolder') . '/avatar'; $storageImage = $storage . '/' . $hashFileName . $extension; $storageThumbnail = $storage . '/thumb_' . $hashFileName . $extension; $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . $extension; $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . $extension; $userModel = CFactory::getModel('user'); // Only resize when the width exceeds the max. if (!CImageHelper::resizeProportional($photoPath, $storageImage, $info['mime'], $imageMaxWidth)) { $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error'); } // Generate avatar if (!CImageHelper::createThumb($photoPath, $storageImage, $info['mime'], COMMUNITY_AVATAR_PROFILE_WIDTH, COMMUNITY_AVATAR_PROFILE_HEIGHT)) { $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageImage), 'error'); } // Generate thumbnail if (!CImageHelper::createThumb($photoPath, $storageThumbnail, $info['mime'])) { $mainframe->enqueueMessage(JText::sprintf('COM_COMMUNITY_ERROR_MOVING_UPLOADED_FILE', $storageThumbnail), 'error'); } if ($photo->storage != 'file') { //@rule: For non local storage, we need to remove the temporary photo JFile::delete($photoPath); } $userModel->setImage($my->id, $image, 'avatar'); $userModel->setImage($my->id, $thumbnail, 'thumb'); // Update the user object so that the profile picture gets updated. $my->set('_avatar', $image); $my->set('_thumb', $thumbnail); // Set album's default photo. $album = JTable::getInstance('Album', 'CTable'); $album->load($photo->albumid); if ($album->id) { $album->photoid = $photo->id; $album->setParam('thumbnail', $photo->thumbnail); $album->store(); } // Generate activity stream. $this->_addAvatarUploadActivity($my->id, $thumbnail); $mainframe->redirect(CRoute::_('index.php?option=com_community&view=profile&task=uploadAvatar', false), JText::_('COM_COMMUNITY_PHOTOS_SET_AVATAR_SUCCESS')); }
/** * Deprecated since 1.8 */ function cRemoteGetContent($url) { return CRemoteHelper::getContent($url); }
/** * 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; }
/** * * * @return $embedvideo specific embeded code to play the video */ public function getViewHTML($videoId, $videoWidth, $videoHeight) { if (!$videoId) { $videoId = $this->videoId; } $remoteFile = 'http://www.break.com/' . $videoId; $xmlContent = CRemoteHelper::getContent($remoteFile); $pattern = "'<meta name=\"embed_video_url\" content=\"(.*?)\"( /)?(>)'s"; preg_match_all($pattern, $xmlContent, $matches); if ($matches) { $videoUrl = $matches[1][0]; } //break.com must always be redirected to their own site $html = '<span style="color: #ffffff;"><a href="' . $remoteFile . '" target="_blank" style="color: #ffffff; text-decoration: underline;">' . JText::_('COM_COMMUNITY_VIDEO_BREAK_NOTICE') . '</a></span>'; return $html; }
public function execute($url) { $response = CRemoteHelper::getContent($url, true); list($headers, $body) = explode("\r\n\r\n", $response, 2); return $body; }
/** * * * @return $embedvideo specific embeded code to play the video */ public function getViewHTML($videoId, $videoWidth, $videoHeight) { if (!$videoId) { $videoId = $this->videoId; } $this->videoId = $videoId; $xmlContent = CRemoteHelper::getContent($this->getFeedUrl()); $pattern = "'<link rel=\"video_src\"(.*?)\\/>'s"; preg_match_all($pattern, $xmlContent, $matches); if ($matches) { $pattern = "'href=\"(.*?)\"'s"; preg_match_all($pattern, $matches[1][0], $matches); $videoUrl = rawurldecode($matches[1][0]); } return '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' . $videoWidth . '" height="' . $videoHeight . '" id="viddler"><param name="movie" value="' . CVideosHelper::getIURL($videoUrl) . '" /><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="true" /><param name="wmode" value="transparent"/><embed src="' . CVideosHelper::getIURL($videoUrl) . '" width="' . $videoWidth . '" height="' . $videoHeight . '" type="application/x-shockwave-flash" allowScriptAccess="always" allowFullScreen="true" name="viddler" wmode="transparent"></embed></object>'; }
/** * * * @return $embedvideo specific embeded code to play the video */ public function getViewHTML($videoId, $videoWidth, $videoHeight) { if (!$videoId) { $videoId = $this->videoId; } CFactory::load('helpers', 'remote'); $remoteFile = 'http://www.break.com/' . $videoId; $xmlContent = CRemoteHelper::getContent($remoteFile); $pattern = "'<meta name=\"embed_video_url\" content=\"(.*?)\"( /)?(>)'s"; preg_match_all($pattern, $xmlContent, $matches); if ($matches) { $videoUrl = $matches[1][0]; } return "<embed src=\"" . $videoUrl . "\" width=\"" . $videoWidth . "\" height=\"" . $videoHeight . "\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" allowFullScreen=\"true\"> </embed>"; }
/** * * * @return $embedvideo specific embeded code to play the video */ public function getViewHTML($videoId, $videoWidth, $videoHeight) { if (!$videoId) { $videoId = $this->videoId; } $file = 'http://media.photobucket.com/video/' . CString::str_ireplace(" ", "%20", $videoId); $xmlContent = CRemoteHelper::getContent($file); if ($xmlContent == FALSE) { return false; } $pattern = "'<link rel=\"video_src\" href=\"(.*?)\" \\/>'s"; preg_match_all($pattern, $xmlContent, $matches); if ($matches) { $videoUrl = rawurldecode($matches[1][0]); } $embedCode = '<embed width="' . $videoWidth . '" height="' . $videoHeight . '" type="application/x-shockwave-flash" wmode="transparent" src="' . CVideosHelper::getIURL($videoUrl) . '">'; return $embedCode; }
/** * Method to display import event form * **/ public function import() { $document = JFactory::getDocument(); $viewType = $document->getType(); $viewName = JRequest::getCmd('view', $this->getName()); $view = $this->getView($viewName, '', $viewType); $events = array(); $mainframe =& JFactory::getApplication(); $config = CFactory::getConfig(); if (!$config->get('event_import_ical')) { $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events', false), JText::_('COM_COMMUNITY_EVENTS_IMPORT_DISABLED'), 'error'); } if (JRequest::getMethod() == 'POST') { $type = JRequest::getVar('type', 'file'); $valid = false; if ($type == 'file') { $file = JRequest::getVar('file', '', 'FILES'); $valid = $file['type'] == 'text/calendar' || $file['type'] == 'application/octet-stream'; $path = $file['tmp_name']; if ($valid && JFile::exists($path)) { $contents = JFile::read($path); } } if ($type == 'url') { CFactory::load('helpers', 'remote'); $file = JRequest::getVar('url', ''); $contents = CRemoteHelper::getContent($file, true); preg_match('/Content-Type: (.*)/im', $contents, $matches); $valid = isset($matches[1]) && stripos(JString::trim($matches[1]), 'text/calendar') !== false; } CFactory::load('libraries', 'ical'); $ical = new CICal($contents); if ($ical->init() && $valid) { $events = $ical->getItems(); } else { $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events&task=import', false), JText::_('Unable to load .ics file'), 'error'); } } echo $view->get(__FUNCTION__, $events); }
/** * * * @return $embedvideo specific embeded code to play the video */ public function getViewHTML($videoId, $videoWidth, $videoHeight) { if (!$videoId) { $videoId = $this->videoId; } $xmlContent = CRemoteHelper::getContent('http://www.flickr.com/photos/' . $videoId); $pattern = "'<link rel=\"video_src\" href=\"(.*?)\"( \\/)?(>)'s"; preg_match_all($pattern, $xmlContent, $matches); if ($matches) { $videoUrl = rawurldecode($matches[1][0]); } return '<embed width="' . $videoWidth . '" height="' . $videoHeight . '" wmode="transparent" allowFullScreen="true" type="application/x-shockwave-flash" src="' . CVideosHelper::getIURL($videoUrl) . '"/>'; }
/** * * * @return $embedvideo specific embeded code to play the video */ function getViewHTML($videoId, $videoWidth, $videoHeight) { if (!$videoId) { $videoId = $this->videoId; } CFactory::load('helpers', 'remote'); $remoteFile = 'http://www.blip.tv/file/' . $videoId . '?skin=rss'; $xmlContent = CRemoteHelper::getContent($remoteFile); // get embedFile $pattern = "'<blip:embedLookup>(.*?)<\\/blip:embedLookup>'s"; $embedFile = ''; preg_match_all($pattern, $xmlContent, $matches); if ($matches) { $embedFile = $matches[1][0]; } return '<object width="' . $videoWidth . '" height="' . $videoHeight . '"><param name="movie" value="http://blip.tv/play/' . $embedFile . '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://blip.tv/play/' . $embedFile . '" type="application/x-shockwave-flash" width="' . $videoWidth . '" height="' . $videoHeight . '" allowscriptaccess="always" allowfullscreen="true" wmode="transparent"></embed></object>'; }
public function saveAvatarFromURL($url) { $tmpPath = JPATH_ROOT . DS . 'images'; $my = CFactory::getUser(); // Need to extract the non-https version since it will cause // certificate issue $avatarUrl = str_replace('https://', 'http://', $url); CFactory::load('helpers', 'remote'); $source = CRemoteHelper::getContent($url, true); JFile::write($tmpPath, $source); // @todo: configurable width? $imageMaxWidth = 160; // Get a hash for the file name. $fileName = JUtility::getHash($my->getDisplayName() . time()); $hashFileName = JString::substr($fileName, 0, 24); $extension = JString::substr($url, JString::strrpos($url, '.')); $type = 'image/jpg'; if ($extension == '.png') { $type = 'image/png'; } if ($extension == '.gif') { $type = 'image/gif'; } //@todo: configurable path for avatar storage? $config = CFactory::getConfig(); $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar'; $storageImage = $storage . DS . $hashFileName . $extension; $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . $extension; $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . $extension; $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . $extension; $userModel = CFactory::getModel('user'); // Only resize when the width exceeds the max. CImageHelper::resizeProportional($tmpPath, $storageImage, $type, $imageMaxWidth); CImageHelper::createThumb($tmpPath, $storageThumbnail, $type); $removeOldImage = false; $userModel->setImage($my->id, $image, 'avatar', $removeOldImage); $userModel->setImage($my->id, $thumbnail, 'thumb', $removeOldImage); // Update the user object so that the profile picture gets updated. $my->set('_avatar', $image); $my->set('_thumb', $thumbnail); return true; }
/** * Return true if the video is valid. * This function uses a typical video privider method where they normally provide * a XML feed file to extract all the video info * @return type Boolean */ public function isValid() { // Connect and get the remote video // Simple check, make sure video id exist if (empty($this->videoId)) { $this->setError(JText::_('COM_COMMUNITY_VIDEOS_INVALID_VIDEO_ID_ERROR')); return false; } // Youtube might return 'Video not found' in the content file $this->xmlContent = CRemoteHelper::getContent($this->getFeedUrl()); if ($this->xmlContent == false) { $this->setError(JText::_('COM_COMMUNITY_VIDEOS_FETCHING_VIDEO_ERROR')); return false; } return true; }
/** * Method to display import event form * * */ public function import() { $mainframe = JFactory::getApplication(); $jinput = $mainframe->input; $document = JFactory::getDocument(); $viewType = $document->getType(); $viewName = $jinput->get('view', $this->getName(), 'String'); $view = $this->getView($viewName, '', $viewType); $events = array(); $config = CFactory::getConfig(); $groupId = $jinput->get->get('groupid', 0, 'Int'); $groupLink = $groupId > 0 ? '&groupid=' . $groupId : ''; $my = CFactory::getUser(); if (!$config->get('event_import_ical')) { $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events' . $groupLink, false), JText::_('COM_COMMUNITY_EVENTS_IMPORT_DISABLED'), 'error'); } if (!$my->canCreateEvents()) { $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events' . $groupLink, false), JText::_('COM_COMMUNITY_EVENTS_IMPORT_DISABLED'), 'error'); } if ($jinput->getMethod() == 'POST') { CFactory::load('libraries', 'ical'); $type = $jinput->get('type', 'file', 'NONE'); $valid = false; if ($type == 'file') { $fileFilter = new JInput($_FILES); $file = $fileFilter->get('file', '', 'array'); $valid = $file['type'] == 'text/calendar' || $file['type'] == 'application/octet-stream'; $path = $file['tmp_name']; if ($valid && JFile::exists($path)) { $contents = JFile::read($path); } $icalParser = new ICal($path); } if ($type == 'url') { //CFactory::load( 'helpers' , 'remote' ); $file = $jinput->get('url', '', 'STRING'); $contents = CRemoteHelper::getContent($file, true); preg_match('/Content-Type: (.*)/im', $contents, $matches); $valid = isset($matches[1]) && stripos(JString::trim($matches[1]), 'text/calendar') !== false; $icalParser = new ICal($file); } $ical = new CICal($contents); if ($ical->init() && $valid) { $events = $ical->getItems(); } else { $mainframe->redirect(CRoute::_('index.php?option=com_community&view=events&task=import' . $groupLink, false), JText::_('Unable to load .ics file'), 'error'); } } $data['events'] = $events; if (isset($icalParser)) { $data['icalParser'] = $icalParser; } echo $view->get(__FUNCTION__, $data); }
/** * * @param $videoId * @return unknown_type */ function getDescription() { $description = ''; CFactory::load('helpers', 'remote'); $str = CRemoteHelper::getContent($this->url); //TODO: Replace the code below with a regular expression //Return the numeric position of the first occurrence of the needle(<div id = "description">) in the string if (strpos($str, "<div id=\"description\">") != 0) { $pos = strpos($str, "<div id=\"description\">") + 22; $post = strpos($str, "</div>", $pos) - $pos; $itemcomment = substr($str, $pos, $post); $description = trim($itemcomment); //strip HTML Tag $description = strip_tags($description); } else { $description = JText::_('CC NOT AVAILABLE'); } return $description; }
/** * * * @return $embedvideo specific embeded code to play the video */ public function getViewHTML($videoId, $videoWidth, $videoHeight) { if (!$videoId) { $videoId = $this->videoId; } $videoId = explode("/", $videoId); $xmlContent = CRemoteHelper::getContent('http://xml.truveo.com/apiv3?appid=1x1jhj64466mi12ia&method=truveo.videos.getVideos&query=' . $videoId[2]); $parser = JFactory::getXMLParser('Simple'); $parser->loadString($xmlContent); $videoElement = $parser->document; //get Video embed code $element = $videoElement->getElementByPath('videoset/video/videoresultembedtag'); $embedTag = $element->data(); $pattern = "'src=\"(.*?)\"'s"; preg_match_all($pattern, $embedTag, $matches); if ($matches) { $flashUrl = ' src="' . rawurldecode($matches[1][0]) . '" '; $src = $matches[1][0]; } // $pattern = "'FlashVars=\'(.*?)\''s"; // $pattern = ''; // preg_match_all($pattern, $embedTag, $matches); // if(!empty($matches)) // { // echo JUtility::dump($matches); // echo count($matches); // exit; // $flashVar = ' FlashVars=\''.rawurldecode($matches[1][0]).'\' '; // } // $embedCode = "<embed ".$flashUrl.$flashVar." allowFullScreen='true' width='".$videoWidth."' height='".$videoHeight."' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' allowScriptAccess='always'></embed>"; $embedCode = "<embed flashvars='fs=1' allowfullscreen='true' src='" . CVideosHelper::getIURL($src) . "' type='application/x-shockwave-flash' width='{$videoWidth}' height='{$videoHeight}' wmode='transparent'></embed>"; return $embedCode; }
public function createVideoThumbFromRemote(&$videoObj) { $thumbData = CRemoteHelper::getContent($video->thumb); if ($thumbData) { jimport('joomla.filesystem.file'); $thumbPath = CVideos::getPath($table->creator, 'thumb'); $thumbFileName = CFileHelper::getRandomFilename($thumbPath); $tmpThumbPath = $thumbPath . '/' . $thumbFileName; if (JFile::write($tmpThumbPath, $thumbData)) { // 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; JFile::move($tmpThumbPath, $thumbPath); // Resize the thumbnails //CFactory::load( 'libraries', 'videos' ); CImageHelper::resizeProportional($thumbPath, $thumbPath, $mime, CVideos::thumbSize('width'), CVideo::thumbSize('height')); // Save $config = CFactory::getConfig(); $thumb = $config->get('videofolder') . '/' . VIDEO_FOLDER_NAME . '/' . $table->creator . '/' . VIDEO_THUMB_FOLDER_NAME . '/' . $thumbFilename; $table->set('thumb', $thumb); $table->store(); } } }
public function mapAvatar($avatarUrl = '', $joomlaUserId, $addWaterMark) { $image = ''; if (!empty($avatarUrl)) { // Make sure user is properly added into the database table first $user = CFactory::getUser($joomlaUserId); $fbUser = $this->getUser(); // Load image helper library as it is needed. CFactory::load('helpers', 'image'); // Store image on a temporary folder. $tmpPath = JPATH_ROOT . DS . 'images' . DS . 'originalphotos' . DS . 'facebook_connect_' . $fbUser; /* print_r($avatarUrl); exit; $url = parse_url( $avatarUrl ); $host = $url[ 'host' ]; $fp = fsockopen("profile.ak.fbcdn.net", 80, $errno, $errstr, 30); $path = CString::str_ireplace( $url['scheme'] . '://' . $host , '' , $avatarUrl ); $source = ''; if( $fp ) { $out = "GET $path HTTP/1.1\r\n"; $out .= "Host: " . $host . "\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); $body = false; while( !feof( $fp ) ) { $return = fgets( $fp , 1024 ); if( $body ) { $source .= $return; } if( $return == "\r\n" ) { $body = true; } } fclose($fp); } */ // Need to extract the non-https version since it will cause // certificate issue $avatarUrl = str_replace('https://', 'http://', $avatarUrl); CFactory::load('helpers', 'remote'); $source = CRemoteHelper::getContent($avatarUrl, true); list($headers, $source) = explode("\r\n\r\n", $source, 2); JFile::write($tmpPath, $source); // @todo: configurable width? $imageMaxWidth = 160; // Get a hash for the file name. $fileName = JUtility::getHash($fbUser . time()); $hashFileName = JString::substr($fileName, 0, 24); $extension = JString::substr($avatarUrl, JString::strrpos($avatarUrl, '.')); $type = 'image/jpg'; if ($extension == '.png') { $type = 'image/png'; } if ($extension == '.gif') { $type = 'image/gif'; } //@todo: configurable path for avatar storage? $config = CFactory::getConfig(); $storage = JPATH_ROOT . DS . $config->getString('imagefolder') . DS . 'avatar'; $storageImage = $storage . DS . $hashFileName . $extension; $storageThumbnail = $storage . DS . 'thumb_' . $hashFileName . $extension; $image = $config->getString('imagefolder') . '/avatar/' . $hashFileName . $extension; $thumbnail = $config->getString('imagefolder') . '/avatar/' . 'thumb_' . $hashFileName . $extension; $userModel = CFactory::getModel('user'); // Only resize when the width exceeds the max. CImageHelper::resizeProportional($tmpPath, $storageImage, $type, $imageMaxWidth); CImageHelper::createThumb($tmpPath, $storageThumbnail, $type); if ($addWaterMark) { // Get the width and height so we can calculate where to place the watermark. list($watermarkWidth, $watermarkHeight) = getimagesize(FACEBOOK_FAVICON); list($imageWidth, $imageHeight) = getimagesize($storageImage); list($thumbWidth, $thumbHeight) = getimagesize($storageThumbnail); CImageHelper::addWatermark($storageImage, $storageImage, $type, FACEBOOK_FAVICON, $imageWidth - $watermarkWidth, $imageHeight - $watermarkHeight); CImageHelper::addWatermark($storageThumbnail, $storageThumbnail, $type, FACEBOOK_FAVICON, $thumbWidth - $watermarkWidth, $thumbHeight - $watermarkHeight); } // Update the CUser object with the correct avatar. $user->set('_thumb', $thumbnail); $user->set('_avatar', $image); // @rule: once user changes their profile picture, storage method should always be file. $user->set('_storage', 'file'); $userModel->setImage($joomlaUserId, $image, 'avatar'); $userModel->setImage($joomlaUserId, $thumbnail, 'thumb'); $user->save(); } }
/** * * * @return $embedCode specific embeded code to play the video */ public function getViewHTML($videoId, $videoWidth, $videoHeight) { $videoId = !empty($videoId) ? $videoId : $this->url; $xmlContent = CRemoteHelper::getContent('http://www.mtv.com/videos/' . $videoId); $videoPath = explode('/', $videoId); if ($xmlContent == FALSE) { return false; } // Get Embeded Code $pattern = "/http:\\/\\/media.mtvnservices.com\\/mgid:uma:(.*?)\"/i"; preg_match_all($pattern, $xmlContent, $matches); if ($matches[1][0]) { $path = $matches[1][0]; $getId = explode(':', $matches[1][0]); } if ($getId[0] == 'video') { $flashVars = 'flashVars="configParams=vid=' . $getId[2]; } else { $id = explode('=', $videoPath[2]); $flashVars = $videoPath[0] == 'movie-trailers' ? NULL : 'flashVars="configParams=id=' . $id[1] . '"'; } $embedCode = '<embed src="' . CVideosHelper::getIURL('http://media.mtvnservices.com/mgid:uma:' . $path) . '" width="' . $videoWidth . '" height="' . $videoHeight . '" ' . $flashVars . '" type="application/x-shockwave-flash" allowFullScreen="true" allowScriptAccess="always" base="." wmode="transparent"></embed>'; return $embedCode; }
/** * Get video's thumbnail URL from videoid * * @access public * @param videoid * @return url */ function getThumbnail() { $thumbnail = ''; // Connect and get the remote video CFactory::load('helpers', 'remote'); $this->xmlContent = CRemoteHelper::getContent($this->getFeedUrl()); // Get thumbnail $this->thumbnail = ''; $pattern = "'addVariable\\(\"thumbUrl\", \"(.*?)\"\\);'s"; preg_match_all($pattern, $this->xmlContent, $matches); if ($matches) { $thumbnail = rawurldecode($matches[1][0]); } return $thumbnail; }
public function execute($url) { CFactory::load('helpers', 'remote'); $response = CRemoteHelper::getContent($url, true); list($headers, $body) = explode("\r\n\r\n", $response, 2); return $body; }
/** * * * @return $embedvideo specific embeded code to play the video */ public function getViewHTML($videoId, $videoWidth, $videoHeight) { if (!$videoId) { $videoId = $this->videoId; } $remoteFile = 'http://blip.tv/file/' . $videoId . '?skin=rss'; $xmlContent = CRemoteHelper::getContent($remoteFile); // get embedFile $pattern = "'<blip:embedLookup>(.*?)<\\/blip:embedLookup>'s"; $embedFile = ''; preg_match_all($pattern, $xmlContent, $matches); if ($matches) { $embedFile = $matches[1][0]; } return '<iframe src="' . CVideosHelper::getIURL('http://blip.tv/play/' . $embedFile . '.x?p=1') . '" width="' . $videoWidth . '" height="' . $videoHeight . '" frameborder="0" allowfullscreen></iframe><embed type="application/x-shockwave-flash" src="' . CVideosHelper::getIURL('http://a.blip.tv/api.swf#' . $embedFile) . '" style="display:none"></embed>'; }
function _remoteInstaller($url) { if (!$url) { return false; } $config =& JFactory::getConfig(); require_once $this->frontendPath . 'helpers' . DS . 'remote.php'; if (!CRemoteHelper::curlExists()) { // opst.. curl not installed return false; } $rawPackage = CRemoteHelper::getContent($url, true); // capture the header list($headers, $contents) = explode("\r\n\r\n", $rawPackage, 2); if (!JString::strpos($headers, '200 OK')) { // something went wrong with the server or the url return false; } $regex = '/filename="([a-zA-Z0-9].+?)"/'; $count = preg_match($regex, $headers, $matches); if (isset($matches[1]) && !empty($matches[1])) { $filename = $matches[1]; } else { $parts = explode('/', $url); $filename = $parts[count($parts) - 1]; } $target = $config->getValue('config.tmp_path') . DS . basename($filename); // Write buffer to file JFile::write($target, $contents); jimport('joomla.installer.installer'); jimport('joomla.installer.helper'); // Unpack $package = JInstallerHelper::unpack($target); if (!$package) { // unable to find install package } // Install the package $msg = ''; $installer =& JInstaller::getInstance(); if (!$installer->install($package['dir'])) { // There was an error installing the package $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Error')); $result = false; } else { // Package installed sucessfully $msg = JText::sprintf('INSTALLEXT', JText::_($package['type']), JText::_('Success')); $result = true; } // Clean up the install files if (!is_file($package['packagefile'])) { $package['packagefile'] = $config->getValue('config.tmp_path') . DS . $package['packagefile']; } JInstallerHelper::cleanupInstall($package['packagefile'], $package['extractdir']); return $result; }