public function map(&$file, $index, &$contents) { // Store the file to a temporary location $file['tmp_name'] = $this->tmp . '/' . md5($file['name']); JFile::write($file['tmp_name'], $file['data']); // Load up media manager now $mm = EB::mediamanager(); $result = $mm->upload($file, 'user:'******'name']; $url = $this->absoluteUrl . '/' . $file['name']; // Get the properties from media manager result if (is_object($result) && property_exists($result, 'title')) { $title = $result->title; $url = $result->url; } // Once the attachment is already uploaded, we want to delete the temporary file now JFile::delete($file['tmp_name']); // Check if a file id is provided in the email if (isset($file['id']) && !empty($file['id'])) { $fileId = $file['id']; $fileId = str_replace('<', '', $fileId); $fileId = str_replace('>', '', $fileId); $patterns = array('/<div><img[^>]*src="[A-Za-z0-9:^>]*' . $fileId . '"[^>]*\\/><\\/div>/si', '/<img[^>]*src="[A-Za-z0-9:^>]*' . $fileId . '"[^>]*\\/>/si'); $replace = array('', ''); $contents = preg_replace($patterns, $replace, $contents); } // Now we need to insert the pdf links into the content $template = EB::template(); $template->set('title', $title); $template->set('url', $url); $output = $template->output('site/mailpublishing/template.pdf'); $contents .= $output; }
public function map(&$file, $index, &$contents) { // Get the attachment's extension $extension = JFile::getExt($file['name']); // Store the file to a temporary location $file['tmp_name'] = $this->tmp . '/' . md5($file['name']); JFile::write($file['tmp_name'], $file['data']); // Load up media manager now $mm = EB::mediamanager(); $result = $mm->upload($file, 'user:'******'name']; $url = $this->absoluteUrl . '/' . $file['name']; // Get the properties from media manager result if (is_object($result) && property_exists($result, 'title')) { $title = $result->title; $url = $result->url; } // Since the image is already uploaded, we want to set the first image as the blog image if ($index == 0 && $this->config->get('main_remotepublishing_mailbox_blogimage')) { $blogimage = new stdClass(); $blogimage->place = $result->place; $blogimage->path = $result->path; $this->blog->image = json_encode($blogimage); } // Once the attachment is already uploaded, we want to delete the temporary file now JFile::delete($file['tmp_name']); // Check if a file id is provided in the email if (isset($file['id']) && !empty($file['id'])) { $fileId = $file['id']; $fileId = str_replace('<', '', $fileId); $fileId = str_replace('>', '', $fileId); $patterns = array('/<div><img[^>]*src="[A-Za-z0-9:^>]*' . $fileId . '"[^>]*\\/><\\/div>/si', '/<img[^>]*src="[A-Za-z0-9:^>]*' . $fileId . '"[^>]*\\/>/si'); $replace = array('', ''); $contents = preg_replace($patterns, $replace, $contents); } // Now we need to insert these image tags into the content if ($index != 0 || !$this->config->get('main_remotepublishing_mailbox_blogimage')) { $template = EB::template(); $template->set('title', $title); $template->set('url', $url); $contents .= $template->output('site/mailpublishing/template.image'); } }
/** * Handles uploads from media manager. * * @since 4.0 * @access public * @param string * @return */ public function upload() { // Ensure that the user is logged in EB::requireLogin(); // Only allowed users who are allowed to upload images if (!$this->acl->get('upload_image')) { $this->output(EB::exception('COM_EASYBLOG_NOT_ALLOWED', EASYBLOG_MSG_ERROR)); } // Load up media manager $mm = EB::mediamanager(); // Get uri $key = $this->input->getRaw('key'); // Get the target folder $placeId = EBMM::getUri($key); // Get the file input $file = $this->input->files->get('file'); // Check if the file is really allowed to be uploaded to the site. $state = EB::image()->canUploadFile($file); if ($state instanceof Exception) { return $this->output($state); } // MM should check if the user really has access to upload to the target folder $allowed = EBMM::hasAccess($placeId); if ($allowed instanceof Exception) { return $this->output($allowed); } // Check the image name is it got contain space, if yes need to replace to '-' $fileName = $file['name']; $file['name'] = str_replace(' ', '-', $fileName); // Upload the file now $file = $mm->upload($file, $placeId); // Response object is intended to also include // other properties like status message and status code. // Right now it only inclues the media item. $response = new stdClass(); $response->media = EBMM::getMedia($file->uri); return $this->output($response); }
/** * Stores the media object that is sent from the xmlrpc client * * @since 5.0 * @access public * @param string * @return */ public static function uploadMedia($blogid, $username, $password, $file) { global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue; // Login the user $state = self::login($username, $password); if ($state !== true) { return $state; } // Get the config $config = EB::config(); // Get the user's acl $acl = EB::acl(); // Get the current user $my = JFactory::getUser(); // Check if user has permissions to upload images if (!$acl->get('upload_image')) { return new xmlrpcresp(0, $xmlrpcerruser + 2, JText::_('You do not have permissions to upload files to the site.')); } // Get the main image storage path $path = rtrim($config->get('main_image_path'), '/'); $relativePath = $path . '/' . $my->id; $absolutePath = JPATH_ROOT . '/' . $path . '/' . $my->id; $absolutePath = JPath::clean($absolutePath); $absoluteUri = rtrim(JURI::root(), '/') . '/' . str_ireplace('\\', '/', $relativePath) . '/' . $my->id; // If the user's folder doesn't exist yet, create it first. if (!JFolder::exists($absolutePath)) { JFolder::create($absolutePath); } // Set the temporary folder $tmp = JPATH_ROOT . '/tmp'; $mediamanager = EB::mediamanager(); // Normalize the file name $file['name'] = $mediamanager->normalizeFileName($file['name']); // Write the file to the $tmpFile = $tmp . '/' . $file['name']; JFile::write($tmpFile, $file['bits']); // Enter some dummy data so we can run some sanity checks on the file $file['tmp_name'] = $tmpFile; $file['size'] = 0; $error = ''; $allowed = EB::image()->canUploadFile($file, $error); // If file uploads aren't allowed for some reasons, we need to revert if ($allowed !== true) { JFile::delete($file['tmp_name']); return new xmlrpcresp(0, $xmlrpcerruser + 1, $error); } // Ensure that the image goes through the media manager resizing format $result = $mediamanager->upload($file); // Once it's gone through media manager, delete the temporary file JFile::delete($file['tmp_name']); // Build the url for the xmlrpc client so that they can replace the links accordingly within the content $url = rtrim(JURI::root(), '/') . '/' . $relativePath . '/' . $file['name']; return new xmlrpcresp(new xmlrpcval(array('url' => new xmlrpcval($url)), 'struct')); }
/** * Given a json string, locate all images in the respective folder * * @since 5.0 * @access public * @param string * @return */ public function getImages($gallery) { // For posts created in 5.x with legacy editor if (isset($gallery->uri)) { $storage = EB::mediamanager()->getPath($gallery->uri); $url = EB::mediamanager()->getUrl($gallery->uri); } // For posts created in 3.x if (!isset($gallery->place) && !isset($gallery->uri)) { $storage = rtrim($this->config->get('main_image_path'), '/'); $url = rtrim(JURI::root(), '/') . '/' . $storage . '/' . $userId . $gallery->path; } // For posts created in 3.x if (isset($gallery->place) && $gallery->place) { $folder = trim($gallery->file, '/\\'); $storage = ''; if ($gallery->place == 'shared') { $storage = JPATH_ROOT . '/' . $this->config->get('main_shared_path') . '/' . $folder; $url = rtrim(JURI::root(), '/') . '/' . $this->config->get('main_shared_path') . '/' . $folder; } else { // Get the user id $parts = explode(':', $gallery->place); $storage = JPATH_ROOT . '/' . rtrim($this->config->get('main_image_path'), '/') . '/' . $parts[1] . '/' . $folder; $url = rtrim(JURI::root(), '/') . '/' . rtrim($this->config->get('main_image_path'), '/') . '/' . $parts[1] . '/' . $folder; } } // Replace all / and \ from storage to the directory separator $storage = str_ireplace(array('\\', '/'), '/', $storage); // Let's test if the folder really exists. if (!JFolder::exists($storage)) { return false; } // Do not include image variations in the list. $exclusion = array(EBLOG_MEDIA_THUMBNAIL_PREFIX, EBLOG_BLOG_IMAGE_PREFIX . '_*', EBLOG_USER_VARIATION_PREFIX, EBLOG_SYSTEM_VARIATION_PREFIX); // Only allow specific file types here. $allowed = EBLOG_GALLERY_EXTENSION; // Get a list of images within this folder. $items = JFolder::files($storage, $allowed, false, false, array('.svn', 'CVS', '.DS_Store', '__MACOSX', 'index.html'), $exclusion); $images = array(); if ($items) { foreach ($items as $item) { $block = new stdClass(); $block->nested = true; $block->isolated = true; $block->data = new stdClass(); $block->data->width = "100%"; $block->data->element_width = "100%"; // Get the meta about the image $imageMeta = $this->getImageMeta($storage, $url, $item); $block->data->url = $imageMeta->thumbnail; $block->data->popup_url = $imageMeta->original; $images[] = $block; } } return $images; }
/** * Binds the user's webcam photo * * @since 5.0 * @access public * @param string * @return */ public function bindWebcam(EasyBlogPost &$blog) { // Get the title $title = $this->input->get('title', '', 'default'); if (!$title) { $post->title = JText::_('COM_EASYBLOG_DEFAULT_WEBCAM_PHOTO_TITLE'); } $fileName = $this->input->get('fileName', '', 'default'); $tmpPath = JPATH_ROOT . '/tmp/' . $fileName; $tmpPath = JPath::clean($tmpPath); // Construct a dummy file object $file = array('name' => $fileName, 'tmp_name' => $tmpPath); // Upload this file into the user's images folder. // Load up media manager now $mm = EB::mediamanager(); $result = $mm->upload($file, 'user:' . $this->my->id); $post->image = $result->uri; }
/** * Allows uploading of an audio file to the server temporarily. * * @since 4.0 * @access public * @param string * @return */ public function uploadAudio() { // Check for request forgeries // EB::checkToken(); // Ensure that the user is logged in EB::requireLogin(); // Ensure that the user really has permissions to create blog posts on the site if (!$this->acl->get('add_entry')) { EB::exception('COM_EASYBLOG_NO_PERMISSION_TO_CREATE_BLOG', EASYBLOG_MSG_ERROR)->setGlobal(); return $this->ajax->reject(); } $file = $this->input->files->get('file'); if (!isset($file['tmp_name']) || empty($file['tmp_name'])) { echo JText::_("COM_EASYBLOG_COMPOSER_UNABLE_TO_LOCATE_TEMPORARY_FILE"); exit; } // Upload this file into their respective images folder. $mm = EB::mediamanager(); $path = $mm->getAbsolutePath('/', 'user:'******'/', 'user:'******'user:' . $this->my->id); // Get the audio player which needs to be embedded on the composer. $player = EB::audio()->getPlayer($result->url); $obj = new stdClass(); $obj->title = $result->title; $obj->player = $player; $obj->file = $result->url; $obj->path = $result->path; echo json_encode($obj); exit; }
/** * Creates a new variation on the site * * @since 5.0 * @access public * @param string * @return */ public function createVariation() { $name = $this->input->getCmd('name'); $key = $this->input->getRaw('key'); // Convert the key into uri $uri = EBMM::getUri($key); // Get the width and height $width = $this->input->get('width'); $height = $this->input->get('height'); $params = new stdClass(); $params->width = $width; $params->height = $height; $media = EB::mediamanager(); $item = $media->createVariation($uri, $name, $params); if ($item instanceof EasyBlogException) { return $this->ajax->reject($state); } // Response object is intended to also include // other properties like status message and status code. // Right now it only inclues the media item. $info = EBMM::getMedia($uri); return $this->ajax->resolve($info); }
/** * Retrieves the blog image for this blog post * * @since 5.0 * @access public * @param string * @return */ public function getImage($size = 'original', $showPlaceholder = true, $protocol = false) { static $cache = array(); $index = $this->id . '-' . $size . $protocol; // Default blog image $default = false; // Display a default place holder if ($showPlaceholder) { $default = EB::getPlaceholderImage(); } if (!isset($cache[$index])) { // If there's no image data for this post, skip this altogether if (!$this->image) { $cache[$index] = $default; return $cache[$index]; } // Ensure that the image is normalized $this->normalizeBlogImage(); // Load up the media manager library $mm = EB::mediamanager(); $url = $mm->getUrl($this->image); $path = $mm->getPath($this->image); $fileName = $mm->getFilename($this->image); // Ensure that the item really exist before even going to do anything on the original image. // If the image was manually removed from FTP or any file explorer, this shouldn't yield any errors. $exists = JFile::exists($path); // If the blog image file doesn't exist, we use the default if (!$exists) { $cache[$index] = $default; return $cache[$index]; } $image = EB::blogimage($path, $url); $cache[$index] = $image->getSource($size, false, $protocol); } return $cache[$index]; }
public function uploadImage($key) { // Load up media manager $mm = EB::mediamanager(); // Get the target folder $placeId = EBMM::getUri($key); // Get the file input $file = JRequest::getVar('file', '', 'FILES', 'array'); // Check if the file is really allowed to be uploaded to the site. $state = EB::image()->canUploadFile($file); if ($state instanceof Exception) { //add error code return $state; //return $this->output($state); } // MM should check if the user really has access to upload to the target folder $allowed = EBMM::hasAccess($placeId); if ($allowed instanceof Exception) { //add error code return $state; //return $this->output($allowed); } // Check the image name is it got contain space, if yes need to replace to '-' $fileName = $file['name']; $file['name'] = str_replace(' ', '-', $fileName); // Upload the file now $file = $mm->upload($file, $placeId); // Response object is intended to also include // other properties like status message and status code. // Right now it only inclues the media item. $response = new stdClass(); $response->media = EBMM::getMedia($file->uri); //code for future use //header('Content-type: text/x-json; UTF-8'); //$resp = json_encode($response, JSON_HEX_TAG); return $response; }
/** * Search and replace videos that are uploaded to the site. * * @since 5.0 * @access public * @param string * @return */ public function processUploadedVideos($content, $isPlain = false, $findText = '', $result = '') { $cfg = EB::config(); // Since 3.0 uses a different video format, we need to do some tests here. if ($result) { $data = json_decode($result); // New EasyBlog 5 legacy codes if (isset($data->uri)) { $mm = EB::mediamanager(); $file = $mm->getFile($data->uri); $url = $file->url; } else { // This is the video codes used on EB3.9 or older $file = trim($data->file, '/\\'); $place = $data->place; if ($place == 'shared') { $url = rtrim(JURI::root(), '/') . '/' . trim(str_ireplace('\\', '/', $cfg->get('main_shared_path')), '/\\') . '/' . $file; } else { $place = explode(':', $place); $url = rtrim(JURI::root(), '/') . '/' . trim($cfg->get('main_image_path'), '/\\') . '/' . $place[1] . '/' . $file; } } $options = array(); $options['width'] = $data->width; $options['height'] = $data->height; $options['autostart'] = isset($data->autostart) ? $data->autostart : false; $player = EB::media()->renderVideoPlayer($url, $options); $content = str_ireplace($findText, $player, $content); return $content; } return $content; }
/** * Load media configuration * * @since 4.0 * @access public * @param string * @return */ public function mediaConfiguration() { $ajax = EB::ajax(); // Require login EB::requireLogin(); $user = EB::user($this->my->id); $tpl = EB::template(); $blogger_id = $user->id; $tpl->set('blogger_id', $blogger_id); // @since: 3.6 // Media manager options $tpl->set('session', JFactory::getSession()); $mediamanager = EB::mediamanager(); $userFolders = $mediamanager->getInfo(EasyBlogMediaManager::getAbsolutePath('', 'user'), 'folders'); $userFiles = $mediamanager->getInfo(EasyBlogMediaManager::getAbsolutePath('', 'user'), 'files'); $sharedFolders = $mediamanager->getInfo(EasyBlogMediaManager::getAbsolutePath('', 'shared'), 'folders'); $sharedFiles = $mediamanager->getInfo(EasyBlogMediaManager::getAbsolutePath('', 'shared'), 'files'); $tpl->set('userFolders', $userFolders); $tpl->set('userFiles', $userFiles); $tpl->set('sharedFolders', $sharedFolders); $tpl->set('sharedFiles', $sharedFiles); // @rule: Test if the user is already associated with Flickr $oauth = EB::table('OAuth'); $associated = $oauth->loadByUser($this->my->id, EBLOG_OAUTH_FLICKR); $tpl->set('flickrAssociated', $associated); // Retrieve flickr's data $flickr = $this->getFlickrData(); // Retrieve dropbox's data $dropbox = $this->getDropboxData(); $tpl->set('flickr', $flickr); $tpl->set('dropbox', $dropbox); $html = $tpl->output('site/media/configuration'); $ajax->resolve($html); }
public function migrateZooImages($path, &$blog, $author) { jimport('joomla.filesystem.file'); $path = JPATH_ROOT . '/' . $path; $config = EB::getConfig(); $configStorage = str_ireplace('\\', '/', $config->get('main_image_path')); $newPath = JPATH_ROOT . '/' . rtrim($configStorage, '/') . '/' . $author->id; if (!JFolder::exists($newPath)) { JFolder::create($newPath); } if (JFile::exists($path)) { // Copy the full scaled image $large = $path; $targetURL = rtrim(JURI::root(), '/') . '/' . str_ireplace('\\', '/', $configStorage) . '/' . $author->id; $file = getimagesize($large); $file['name'] = basename($large); $file['tmp_name'] = $large; $result = EB::mediamanager()->upload($file, 'user:'******'/' . $file['name']; $result->path = $relativeImagePath; } $result = json_encode($result); $blog->image = $result; } }
<?php /** * @package EasyBlog * @copyright Copyright (C) 2010 - 2015 Stack Ideas Sdn Bhd. All rights reserved. * @license GNU/GPL, see LICENSE.php * EasyBlog is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */ defined('_JEXEC') or die('Unauthorized Access'); ?> <div class="eb-composer-view eb-composer-media" data-name="media" data-eb-composer-view data-eb-composer-media> <?php echo EB::mediamanager()->render(); ?> </div>
function migrateBloggerImage($image, $userid, $content) { jimport('joomla.utilities.error'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $config = EB::getConfig(); $main_image_path = $config->get('main_image_path'); $main_image_path = rtrim($main_image_path, '/'); $rel_upload_path = $main_image_path . '/' . $userid; $userUploadPath = JPATH_ROOT . DIRECTORY_SEPARATOR . str_ireplace('/', DIRECTORY_SEPARATOR, $main_image_path . DIRECTORY_SEPARATOR . $userid); $folder = JPath::clean($userUploadPath); $dir = $userUploadPath . DIRECTORY_SEPARATOR; $tmp_dir = JPATH_ROOT . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR; if (!JFolder::exists($dir)) { JFolder::create($dir); } //now let get the image from remove url. $segments = explode('/', $image); $fileName = $segments[count($segments) - 1]; $fileName = JFile::makesafe($fileName); $tmpFileName = $tmp_dir . $fileName; $file['name'] = $fileName; $file['tmp_name'] = $tmpFileName; // write to JOOMLA tmp folder file_put_contents($tmpFileName, file_get_contents($image)); $media = EB::mediamanager(); $result = $media->upload($file, 'user:'******'tmp_name']); if (isset($result->type)) { $relativeImagePath = $rel_upload_path . '/' . $file['name']; // lets replace the image from the content to this uploaded one. $content = str_replace($image, $relativeImagePath, $content); } return $content; }
public function migrateK2Images(&$item, &$blog, $author) { jimport('joomla.filesystem.file'); $name = md5('Image' . $item->id); $path = JPATH_ROOT . '/media/k2/items/src/' . $name . '.jpg'; $config = EB::getConfig(); $configStorage = str_ireplace('\\', '/', $config->get('main_image_path')); $newPath = JPATH_ROOT . '/' . rtrim($configStorage, '/') . '/' . $author->id; if (!JFolder::exists($newPath)) { JFolder::create($newPath); } if (JFile::exists($path)) { // Copy the full scaled image $large = JPATH_ROOT . '/media/k2/items/cache/' . $name . '_XL.jpg'; $targetLarge = $newPath . '/' . $name . '.jpg'; $targetURL = rtrim(JURI::root(), '/') . '/' . str_ireplace('\\', '/', $configStorage) . '/' . $author->id; $largeSrc = rtrim(JURI::root(), '/') . '/' . str_ireplace('\\', '/', $configStorage) . '/' . $author->id . '/' . $name . '.jpg'; $file = getimagesize($large); $file['name'] = basename($large); $file['tmp_name'] = $large; $media = EB::mediamanager(); $result = $media->upload($file, 'user:' . $author->id); $result = json_encode($result); $blog->image = $result; } }
/** * @param $raw_item * @param int $dborder * * @return \RokSprocket_Item */ protected function convertRawToItem($raw_item, $dborder = 0) { //$textfield = $this->params->get('easyblog_articletext_field', ''); $provider_version = $this->providerVersion(); if ($provider_version < "5.0.0") { $helper_file = JPATH_ROOT . '/components/com_easyblog/helpers/helper.php'; $router_file = JPATH_ROOT . '/components/com_easyblog/helpers/router.php'; } elseif ($provider_version >= "5.0.0") { $helper_file = JPATH_ADMINISTRATOR . '/components/com_easyblog/includes/easyblog.php'; $router_file = JPATH_ADMINISTRATOR . '/components/com_easyblog/includes/router.php'; } if (file_exists($helper_file)) { require_once $helper_file; } if (file_exists($router_file)) { require_once $router_file; } /* isset(require_once(JPATH_ROOT . '/components/com_easyblog/helpers/helper.php')); isset(require_once(JPATH_ROOT . '/components/com_easyblog/helpers/router.php'));*/ //suppress easyblog code errors $cfg = @EasyBlogHelper::getConfig(); $item = new RokSprocket_Item(); $item->setProvider($this->provider_name); $item->setId($raw_item->id); $item->setAlias(JApplication::stringURLSafe($raw_item->title)); $item->setAuthor($raw_item->author_name); $item->setTitle($raw_item->title); $item->setDate($raw_item->created); $item->setPublished($raw_item->published == 1 ? true : false); $item->setText($raw_item->intro); $item->setCategory($raw_item->category_title); $item->setHits($raw_item->hits); $item->setRating($raw_item->rating); $item->setMetaKey($raw_item->metakey); $item->setMetaDesc($raw_item->metadesc); if ($provider_version < "5.0.0") { $item->setMetaData(array("robots" => "'.{$raw_item->robots}.'", "author" => "'.{$raw_item->source}.'", "rights" => "'.{$raw_item->copyrights}.'", "xreference" => "")); } elseif ($provider_version >= "5.0.0") { $item->setMetaData(array("robots" => "'.{$raw_item->robots}.'", "author" => "'.{$raw_item->posttype}.'", "rights" => "'.{$raw_item->copyrights}.'", "xreference" => "")); } $item->setPublishUp($raw_item->publish_up); $item->setPublishDown($raw_item->publish_down); $images = array(); if (isset($raw_item->image) && !empty($raw_item->image)) { try { if (isset($raw_item->doctype) && !empty($raw_item->doctype)) { // EB5 // normalize blog image $image = json_decode($raw_item->image); // @legacy fix // We only want to store the URI for blog images. if (is_object($image)) { $raw_item->image = $image->place . $image->path; } // Load up the media manager library $mm = EB::mediamanager(); $url = $mm->getUrl($raw_item->image); $path = $mm->getPath($raw_item->image); if (JFile::exists($path)) { $image = EB::blogimage($path, $url); $item_image = new RokSprocket_Item_Image(); $item_image->setSource($image->getSource('medium')); $item_image->setIdentifier('image_item'); $item_image->setCaption(null); $item_image->setAlttext(null); $images[$item_image->getIdentifier()] = $item_image; $item->setPrimaryImage($item_image); // full image $item_image = new RokSprocket_Item_Image(); $item_image->setSource($image->getSource('large')); $item_image->setIdentifier('image_full'); $item_image->setCaption(null); $item_image->setAlttext(null); $images[$item_image->getIdentifier()] = $item_image; //thumbnail $item_image = new RokSprocket_Item_Image(); $item_image->setSource($image->getSource('thumbnail')); $item_image->setIdentifier('image_thumb'); $item_image->setCaption(null); $item_image->setAlttext(null); $images[$item_image->getIdentifier()] = $item_image; //thumbnail $item_image = new RokSprocket_Item_Image(); $item_image->setSource($image->getSource('icon')); $item_image->setIdentifier('image_icon'); $item_image->setCaption(null); $item_image->setAlttext(null); $images[$item_image->getIdentifier()] = $item_image; } } else { $raw_image = RokCommon_JSON::decode($raw_item->image); if (isset($raw_image) && !empty($raw_image)) { $item_image = new RokSprocket_Item_Image(); if (isset($raw_image->place) && $raw_image->place == 'shared') { $item_image->setSource(JPath::clean(JURI::root(true) . '/' . $cfg->get('main_shared_path') . $raw_image->path)); } else { $folder = explode(':', $raw_image->place); $item_image->setSource(JPath::clean(JURI::root(true) . '/' . $cfg->get('main_image_path') . $folder[1] . $raw_image->path)); } $item_image->setIdentifier('image_item'); $item_image->setCaption(null); $item_image->setAlttext(null); $images[$item_image->getIdentifier()] = $item_image; $item->setPrimaryImage($item_image); //full image $item_image = new RokSprocket_Item_Image(); $item_image->setSource(JPath::clean(str_replace(JURI::root(), JURI::root(true) . '/', $raw_image->url))); $item_image->setIdentifier('image_full'); $item_image->setCaption(null); $item_image->setAlttext(null); $images[$item_image->getIdentifier()] = $item_image; //thumbnail $item_image = new RokSprocket_Item_Image(); $item_image->setSource(JPath::clean(str_replace(JURI::root(), JURI::root(true) . '/', $raw_image->thumbnail->url))); $item_image->setIdentifier('image_thumb'); $item_image->setCaption(null); $item_image->setAlttext(null); $images[$item_image->getIdentifier()] = $item_image; //icon $item_image = new RokSprocket_Item_Image(); $item_image->setSource(JPath::clean(str_replace(JURI::root(), JURI::root(true) . '/', $raw_image->icon->url))); $item_image->setIdentifier('image_icon'); $item_image->setCaption(null); $item_image->setAlttext(null); $images[$item_image->getIdentifier()] = $item_image; } } } catch (RokCommon_JSON_Exception $jse) { $this->container->roksprocket_logger->warning('Unable to decode image JSON for article ' . $item->getArticleId()); } $item->setImages($images); } $primary_link = new RokSprocket_Item_Link(); $itemId = EasyBlogRouter::getItemIdByCategories($raw_item->category_id); $primary_link->setUrl(EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $raw_item->id . '&Itemid=' . $itemId)); $primary_link->getIdentifier('article_link'); $item->setPrimaryLink($primary_link); $item->setPrimaryLink($primary_link); $links = array(); $link = new RokSprocket_Item_Link(); $link->setUrl(EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $raw_item->id . '&Itemid=' . $itemId)); $link->setText(''); $link->setIdentifier('article_link'); $links[$link->getIdentifier()] = $link; $item->setLinks($links); $texts = array(); $texts['text_content'] = $raw_item->content; $texts['text_intro'] = $raw_item->intro; $texts['text_excerpt'] = $raw_item->excerpt; $texts['text_title'] = $raw_item->title; $texts['text_metadesc'] = $raw_item->metadesc; $texts = $this->processPlugins($texts); $item->setTextFields($texts); if ($provider_version < "5.0.0") { $item->setText($texts['text_intro']); } elseif ($provider_version >= "5.0.0") { $item->setText($texts['text_content']); } $item->setDbOrder($dborder); // unknown joomla items $item->setCommentCount($raw_item->comment_count); if (isset($raw_item->tags)) { $tags = explode(',', $raw_item->tags) ? explode(',', $raw_item->tags) : array(); $item->setTags($tags); } return $item; }
public function getImage($blog) { static $image = array(); if (!isset($image[$blog->id])) { if (!$blog->image) { $image[$blog->id] = false; return false; } if (version_compare($this->easyBlogVersion, '5.0', 'ge')) { $mm = EB::mediamanager(); $uri = JUri::getInstance(); return $uri->getScheme() . ':' . $mm->getUrl($blog->image); } else { $imageObject = json_decode($blog->image); if (!$imageObject) { $image = false; return false; } // Get the configuration object. $cfg = EasyBlogHelper::getConfig(); // Let's see where should we find for this. $storagePath = ''; $storageURI = ''; if (isset($imageObject->place) && $imageObject->place == 'shared') { $storagePath = JPATH_ROOT . DIRECTORY_SEPARATOR . trim($cfg->get('main_shared_path'), '/\\'); $storageURI = rtrim(JURI::root(), '/') . '/' . trim(str_ireplace('\\', '/', $cfg->get('main_shared_path')), '/\\'); } else { $place = $imageObject->place; $place = explode(':', $place); $place[1] = (int) $place[1]; $path = $imageObject->path; // Set the storage path $storagePath = JPATH_ROOT . DIRECTORY_SEPARATOR . trim($cfg->get('main_image_path'), '/\\') . DIRECTORY_SEPARATOR . $place[1]; // @task: Set the storage URI $storageURI = rtrim(JURI::root(), '/') . '/' . trim($cfg->get('main_image_path'), '/\\') . '/' . $place[1]; } // Ensure that the item really exist before even going to do anything on the original image. // If the image was manually removed from FTP or any file explorer, this shouldn't yield any errors. $itemPath = $storagePath . DIRECTORY_SEPARATOR . trim($imageObject->path, '/\\'); if (!JFile::exists($itemPath)) { // @TODO: Perhaps we should update $this->image with an empty value since image no longer exists. $image[$blog->id] = false; return false; } $image[$blog->id] = new EasyBlogImage($imageObject->path, $storagePath, $storageURI); return $image[$blog->id]->getSource('original'); } } }