public static function getImage(&$blog, $rawIntroText = '') { $cfg = EasyBlogHelper::getConfig(); // @task: First, we try to search to see if there's a blog image. If there is already, just ignore the rest. if ($blog->getImage()) { return $blog->getImage()->getSource('thumbnail'); } // @legacy: If there's no image for this blog post, then we do this the legacy way. // First let's try to find for an image. $img = ''; $pattern = '#<img[^>]*>#i'; preg_match($pattern, $blog->content, $matches); if ($matches) { $img = $matches[0]; } else { $text = $cfg->get('main_hideintro_entryview') ? $rawIntroText : $blog->intro; preg_match($pattern, $text, $matches); if ($matches) { $img = $matches[0]; } } // Default image $source = ''; //image found. now we process further to get the absolute image path. if ($img) { //get the img source $pattern = '/src=[\\"\']?([^\\"\']?.*(png|jpg|jpeg|gif))[\\"\']?/i'; preg_match($pattern, $img, $matches); if ($matches) { $imgPath = $matches[1]; $source = EasyImageHelper::rel2abs($imgPath, JURI::root()); } } return $source; }
function getAvatar() { $avatar_link = ''; if ($this->avatar == 'default.png' || $this->avatar == 'default_blogger.png' || $this->avatar == 'components/com_easyblog/assets/images/default_blogger.png' || $this->avatar == 'components/com_easyblog/assets/images/default.png' || empty($this->avatar)) { $avatar_link = 'components/com_easyblog/assets/images/default_blogger.png'; } else { $avatar_link = EasyImageHelper::getAvatarRelativePath() . '/' . $this->avatar; } return $avatar_link; }
public function upload() { $app = JFactory::getApplication(); $my = JFactory::getUser(); $cfg = EasyBlogHelper::getConfig(); $acl = EasyBlogACLHelper::getRuleSet(); // @rule: Only allowed users are allowed to upload images. if ($my->id == 0 || empty($acl->rules->upload_image)) { $sessionid = JRequest::getVar('sessionid'); if ($sessionid) { $session = JTable::getInstance('Session'); $session->load($sessionid); if (!$session->userid) { $this->output($this->getMessageObj(EBLOG_MEDIA_SECURITY_ERROR, JText::_('COM_EASYBLOG_NOT_ALLOWED'))); } $my = JFactory::getUser($session->userid); } else { $this->output($this->getMessageObj(EBLOG_MEDIA_SECURITY_ERROR, JText::_('COM_EASYBLOG_NOT_ALLOWED'))); } } // Let's get the path for the current request. $file = JRequest::getVar('file', '', 'FILES', 'array'); $place = JRequest::getVar('place'); // The user might be from a subfolder? $source = urldecode(JRequest::getVar('path', '/')); // @task: Let's find the exact path first as there could be 3 possibilities here. // 1. Shared folder // 2. User folder $absolutePath = EasyBlogMediaManager::getAbsolutePath($source, $place); $absoluteURI = EasyBlogMediaManager::getAbsoluteURI($source, $place); // @TODO: Test if user is allowed to upload this image $message = $this->getMessageObj(); $allowed = EasyImageHelper::canUploadFile($file, $message); if ($allowed !== true) { return $this->output($message); } $media = new EasyBlogMediaManager(); $result = $media->upload($absolutePath, $absoluteURI, $file, $source, $place); // This should be an error if the $result is not an MMIM object. if (!is_object($result)) { $message = $this->getMessageObj('404', $result); } else { $message = $this->getMessageObj(EBLOG_MEDIA_UPLOAD_SUCCESS, JText::_('COM_EASYBLOG_IMAGE_MANAGER_UPLOAD_SUCCESS'), $result); } return $this->output($message); }
function _getAvatar($profile) { $path = JPATH_ROOT . DIRECTORY_SEPARATOR . EasyImageHelper::getAvatarRelativePath() . DIRECTORY_SEPARATOR . $profile->avatar; $image = EasyImageHelper::getAvatarRelativePath() . '/' . $profile->avatar; $mainframe = JFactory::getApplication(); $override = JPATH_ROOT . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $mainframe->getTemplate() . DIRECTORY_SEPARATOR . 'html' . DIRECTORY_SEPARATOR . 'com_easyblog' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'default_blogger.png'; if (!JFile::exists($path) || empty($profile->avatar)) { if (JFile::exists($override)) { $image = 'templates/' . $mainframe->getTemplate() . '/html/com_easyblog/assets/images/default_blogger.png'; } else { $image = 'components/com_easyblog/assets/images/default_blogger.png'; } } $avatar = new stdClass(); $avatar->link = rtrim(JURI::root(), '/') . '/' . $image; return $avatar; }
public function post() { //old code /*$controller = new EasyBlogControllerMedia; $op = $controller->upload(); */ $input = JFactory::getApplication()->input; $log_user = $this->plugin->get('user')->id; $res = new stdClass(); // Let's get the path for the current request. $file = JRequest::getVar('file', '', 'FILES', 'array'); if ($file['name']) { $place = 'user:'******'user')->id; // The user might be from a subfolder? $source = urldecode('/' . $file['name']); // @task: Let's find the exact path first as there could be 3 possibilities here. // 1. Shared folder // 2. User folder //$absolutePath = EasyBlogMediaManager::getAbsolutePath( $source , $place ); //$absoluteURI = EasyBlogMediaManager::getAbsoluteURI( $source , $place ); $absolutePath = EasyBlogMediaManager::getPath($source); $absoluteURI = EasyBlogMediaManager::getUrl($source); $allowed = EasyImageHelper::canUploadFile($file, $message); if ($allowed !== true) { $res->status = 0; $res->message = 'Upload is not allowed'; return $res; } $media = new EasyBlogMediaManager(); $upload_result = $media->upload($absolutePath, $absoluteURI, $file, $source, $place); //adjustment $upload_result->key = $place . $source; $upload_result->group = 'files'; $upload_result->parentKey = $place . '|/'; $upload_result->friendlyPath = 'My Media/' . $source; unset($upload_result->variations); $this->plugin->setResponse($upload_result); return $upload_result; } else { $this->plugin->setResponse($this->getErrorResponse(404, __FUNCTION__ . ' Upload unsuccessfull.')); } }
function newMediaObject($blogid, $username, $password, $file) { jimport('joomla.utilities.error'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); global $xmlrpcerruser, $xmlrpcI4, $xmlrpcInt, $xmlrpcBoolean, $xmlrpcDouble, $xmlrpcString, $xmlrpcDateTime, $xmlrpcBase64, $xmlrpcArray, $xmlrpcStruct, $xmlrpcValue; EasyBlogXMLRPCHelper::loginUser($username, $password); $user = JUser::getInstance($username); $acl = EasyBlogACLHelper::getRuleSet($user->id); if (empty($acl->rules->upload_image)) { return new xmlrpcresp(0, $xmlrpcerruser + 2, JText::_('YOU DO NOT HAVE IMAGE UPLOAD RIGHT')); } $config = EasyBlogHelper::getConfig(); $main_image_path = $config->get('main_image_path'); $main_image_path = rtrim($main_image_path, '/'); $rel_upload_path = $main_image_path . '/' . $user->id; $userUploadPath = JPATH_ROOT . DIRECTORY_SEPARATOR . str_ireplace('/', DIRECTORY_SEPARATOR, $main_image_path . DIRECTORY_SEPARATOR . $user->id); $folder = JPath::clean($userUploadPath); $dir = $userUploadPath . DIRECTORY_SEPARATOR; $tmp_dir = JPATH_ROOT . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR; if (!JFolder::exists($dir)) { JFolder::create($dir); } if (strpos($file['name'], '/') !== FALSE) { $file['name'] = substr($file['name'], strrpos($file['name'], '/') + 1); } elseif (strpos($file['name'], '\\' !== FALSE)) { $file['name'] = substr($file['name'], strrpos($file['name'], '\\') + 1); } // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); $ftp = JClientHelper::getCredentials('ftp'); $file['name'] = JFile::makesafe($file['name']); //$file['name'] = substr($file['name'], 0, -4) . rand() . '.' . JFile::getExt($file['name']); $file['name'] = substr($file['name'], 0, -4) . '.' . JFile::getExt($file['name']); // write to temp folder $file['tmp_name'] = $tmp_dir . $file['name']; @JFile::write($file['tmp_name'], $file['bits']); $file['size'] = 0; $error = ''; $allowed = EasyImageHelper::canUploadFile($file); if ($allowed !== true) { @JFile::delete($file['tmp_name']); return new xmlrpcresp(0, $xmlrpcerruser + 1, 'The file is not valid'); } // @JFile::write( $dir . $file['name'], $file['bits']); // @task: Ensure that images goes through the same resizing format when uploading via media manager. require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'mediamanager.php'; $media = new EasyBlogMediaManager(); $result = $media->upload($dir, $userUploadPath, $file, '/', 'user'); @JFile::delete($file['tmp_name']); $file['name'] = EasyBlogXMLRPCHelper::cleanImageName($file['name']); $fileUrl = rtrim(JURI::root(), '/') . '/' . $rel_upload_path . '/' . $file['name']; return new xmlrpcresp(new xmlrpcval(array('url' => new xmlrpcval($fileUrl)), 'struct')); }
/** * Handles photo uploads via the microblogging page. * * @access public * @param null **/ public function uploadPhoto() { $my = JFactory::getUser(); $config = EasyBlogHelper::getConfig(); if (!$my->id) { return $this->outputJSON(array('type' => 'error', 'message' => JText::_('You need to be logged in first'))); } $file = JRequest::getVar('photo-source', '', 'files', 'array'); if (!isset($file['tmp_name'])) { return $this->outputJSON(array('type' => 'error', 'message' => JText::_('There is an error when uploading the image to the server. Perhaps the temporary folder <strong>upload_tmp_path</strong> was not configured correctly.'))); } require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'image.php'; // @rule: Photos should be stored in the user's home folder by default. $imagePath = str_ireplace(array("/", "\\"), DIRECTORY_SEPARATOR, rtrim($config->get('main_image_path'), '/')); $userUploadPath = JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $imagePath . DIRECTORY_SEPARATOR . $my->id); $storageFolder = JPath::clean($userUploadPath); // @rule: Get the image URI $imageURI = rtrim(str_ireplace('\\', '/', $config->get('main_image_path')), '/') . '/' . $my->id; $imageURI = rtrim(JURI::root(), '/') . '/' . $imageURI; // Set FTP credentials, if given jimport('joomla.client.helper'); JClientHelper::setCredentialsFromRequest('ftp'); // Make the filename safe jimport('joomla.filesystem.file'); $file['name'] = JFile::makeSafe($file['name']); // After making the filename safe, and the first character begins with . , we need to rename this file. Perhaps it's a unicode character $file['name'] = trim($file['name']); $filename = strtolower($file['name']); if (strpos($filename, '.') === false) { $filename = EB::date()->toFormat("%Y%m%d-%H%M%S") . '.' . $filename; } else { if (strpos($filename, '.') == 0) { $filename = EB::date()->toFormat("%Y%m%d-%H%M%S") . $filename; } } // remove the spacing in the filename. $filename = str_ireplace(' ', '-', $filename); $storagePath = JPath::clean($storageFolder . DIRECTORY_SEPARATOR . $filename); // // @task: try to rename the file if another image with the same name exists // if( JFile::exists( $storagePath ) ) // { // $i = 1; // while( JFile::exists( $storagePath ) ) // { // $tmpName = $i . '_' . EB::date()->toFormat( "%Y%m%d-%H%M%S" ) . '_' . $filename; // $storagePath = JPath::clean( $storageFolder . DIRECTORY_SEPARATOR . $tmpName ); // $i++; // } // $filename = $tmpName; // } $allowed = EasyImageHelper::canUploadFile($file); if ($allowed !== true) { return $this->outputJSON(array('type' => 'error', 'message' => $allowed)); } // @rule: Pass to EasyBlogImageHelper to upload the image // $result = EasyImageHelper::upload( $storageFolder , $filename , $file , $imageURI , $storagePath ); // // @task: Ensure that images goes through the same resizing format when uploading via media manager. $result = new stdClass(); $result->message = JText::_('COM_EASYBLOG_IMAGE_MANAGER_UPLOAD_ERROR'); $result->item = ''; require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'mediamanager.php'; $media = new EasyBlogMediaManager(); $uploaded = $media->upload($file, 'user:'******'COM_EASYBLOG_IMAGE_MANAGER_UPLOAD_SUCCESS'); $result->item = $uploaded; } else { // failed. $result->item->url = ''; } return $this->outputJSON(array('type' => 'success', 'message' => $result->message, 'uri' => $result->item->url)); }
public static function getFirstImage($content) { //try to search for the 1st img in the blog $img = ''; $pattern = '#<img[^>]*>#i'; preg_match($pattern, $content, $matches); if ($matches) { $img = $matches[0]; } //image found. now we process further to get the absolute image path. if (!empty($img)) { //get the img src $pattern = '/src\\s*=\\s*"(.+?)"/i'; preg_match($pattern, $img, $matches); if ($matches) { $imgPath = $matches[1]; $imgSrc = EasyImageHelper::rel2abs($imgPath, JURI::root()); return $imgSrc; } } return false; }
function _processWPXMLAttachment($wpPostId, $content, $attachments, $authorId) { require_once EBLOG_HELPERS . DIRECTORY_SEPARATOR . 'connectors.php'; foreach ($attachments as $attachment) { $link = $attachment['link']; $attachementURL = $attachment['attachment_url']; if (EasyImageHelper::isImage($attachementURL)) { $filname = EasyImageHelper::getFileName($attachementURL); $extension = EasyImageHelper::getFileExtension($attachementURL); $folder = JPATH_ROOT . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'blogs' . DIRECTORY_SEPARATOR . $wpPostId; if (!JFolder::exists($folder)) { JFolder::create($folder); } // new image location $newFile = $folder . DIRECTORY_SEPARATOR . $filname; $connector = EB::connector(); $connector->addUrl($attachementURL); $connector->execute(); $imageraw = $connector->getResult($attachementURL); if ($imageraw) { if (JFile::write($newFile, $imageraw)) { //replace the string in the content. $absImagePath = rtrim(JURI::root(), '/') . '/images/blogs/' . $wpPostId . '/' . $filname; $content = str_ireplace('href="' . $link . '"', 'href="' . $absImagePath . '"', $content); $pattern = '/src=[\\"\']?([^\\"\']?.*(png|jpg|jpeg|gif))[\\"\']?/i'; $content = preg_replace($pattern, 'src="' . $absImagePath . '"', $content); } } // if( file_put_contents( $newFile, file_get_contents($attachementURL) ) !== false ) // { // //replace the string in the content. // $absImagePath = rtrim( JURI::root(), '/' ) . '/images/blogs/' . $wpPostId . '/' . $filname; // $content = JString::str_ireplace( 'href="' . $link . '"' , 'href="' . $absImagePath . '"' , $content ); // // $pattern = '/src=[\"\']?([^\"\']?.*(png|jpg|jpeg|gif))[\"\']?/i'; // $content = preg_replace( $pattern , 'src="'.$absImagePath.'"' , $content ); // } } } return $content; }
public static function getAvatarDimension($avatar) { $config = EasyBlogHelper::getConfig(); //resize the avatar image $avatar = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $avatar); $info = @getimagesize($avatar); if (!$info === false) { $thumb = EasyImageHelper::imageResize($info[0], $info[1], 60); } else { $thumb = array(EBLOG_AVATAR_THUMB_WIDTH, EBLOG_AVATAR_THUMB_HEIGHT); } return $thumb; }
function getAvatar() { $avatar_link = ''; if ($this->avatar == 'cdefault.png' || $this->avatar == 'default_category.png' || $this->avatar == 'components/com_easyblog/assets/images/default_category.png' || $this->avatar == 'components/com_easyblog/assets/images/cdefault.png' || empty($this->avatar)) { $avatar_link = 'components/com_easyblog/assets/images/default_category.png'; } else { require_once EBLOG_HELPERS . '/image.php'; $avatar_link = EasyImageHelper::getAvatarRelativePath('category') . '/' . $this->avatar; } return rtrim(JURI::root(), '/') . '/' . $avatar_link; }
public function getUniqueName($storagePath, $fileName) { jimport('joomla.filesystem.file'); $i = 1; $itemPath = JPath::clean($storagePath . DIRECTORY_SEPARATOR . $fileName); // @task: Now, we need to ensure that this file doesn't exist on the system. if (JFile::exists($itemPath)) { while (JFile::exists($itemPath)) { // get file extension here: $ext = EasyImageHelper::getFileExtension($fileName); $ext = '.' . $ext; $tmpFileName = str_replace($ext, '', $fileName); $tmp = $tmpFileName . '_' . EasyBlogHelper::getDate()->toFormat("%Y%m%d-%H%M%S") . '_' . $i . $ext; // Reset the itempath. $itemPath = JPath::clean($storagePath . DIRECTORY_SEPARATOR . $tmp); $i++; } // Get the new file name for this item. $fileName = $tmp; } return $fileName; }
public function onPrepareAvatars(&$comments) { $db = JFactory::getDBO(); $avatar_type = $this->params->get('avatar_type', 'gravatar'); $avatar_default_avatar = $this->params->get('avatar_default_avatar'); $avatar_custom_default_avatar = $this->params->get('avatar_custom_default_avatar'); $avatar_link = $this->params->get('avatar_link', 0); $avatar_link_target = $this->params->get('avatar_link_target'); $avatar_link_target = $avatar_link_target != '_self' ? ' target="' . $avatar_link_target . '"' : ''; $users = array(); foreach ($comments as &$comment) { if ($comment->userid != 0) { $users[] = (int)$comment->userid; } $comment->avatar = ''; } $users = array_unique($users); $avatars = array(); switch ($avatar_type) { case 'aup': if (count($users)) { $db->setQuery('SELECT userid, avatar, referreid FROM #__alpha_userpoints WHERE userid in (' . implode(',', $users) . ')'); $avatars = $db->loadObjectList('userid'); } $Itemid = self::getItemid('index.php?option=com_alphauserpoints&view=users'); if (empty($Itemid)) { $Itemid = self::getItemid('index.php?option=com_alphauserpoints&view=account'); } $avatarA = JPATH_SITE . '/components/com_alphauserpoints/assets/images/avatars/'; $avatarL = JURI::base() . 'components/com_alphauserpoints/assets/images/avatars/'; foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = $uid ? JRoute::_('index.php?option=com_alphauserpoints&view=account&userid=' . $avatars[$uid]->referreid . $Itemid) : ''; if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') { if (is_file($avatarA . $avatars[$uid]->avatar)) { $comment->avatar = $avatarL . $avatars[$uid]->avatar; } } } break; case 'cb': if (count($users)) { $db->setQuery('SELECT user_id, avatar FROM #__comprofiler WHERE user_id in (' . implode(',', $users) . ') AND avatarapproved = 1'); $avatars = $db->loadObjectList('user_id'); } $Itemid = self::getItemid('index.php?option=com_comprofiler&task=profile'); if (empty($Itemid)) { $Itemid = self::getItemid('index.php?option=com_comprofiler&task=userslist'); if (empty($Itemid)) { $Itemid = self::getItemid('index.php?option=com_comprofiler'); } } foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = $uid ? JRoute::_('index.php?option=com_comprofiler&task=userProfile&user='******''; if (isset($avatars[$uid]) && !empty($avatars[$uid]->avatar)) { $tn = strpos($avatars[$uid]->avatar, 'gallery') === 0 ? '' : 'tn'; $comment->avatar = JURI::base() . 'images/comprofiler/' . $tn . $avatars[$uid]->avatar; } } break; case 'contacts': if (count($users)) { $query = 'SELECT cd.user_id as userid, cd.image as avatar' . ' , CASE WHEN CHAR_LENGTH(cd.alias) THEN CONCAT_WS(":", cd.id, cd.alias) ELSE cd.id END as slug' . ' , CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(":", cc.id, cc.alias) ELSE cc.id END as catslug' . ' FROM #__contact_details AS cd ' . ' INNER JOIN #__categories AS cc on cd.catid = cc.id' . ' WHERE cd.user_id in (' . implode(',', $users) . ')'; $db->setQuery($query); $avatars = $db->loadObjectList('userid'); } foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = $uid ? JRoute::_('index.php?option=com_contact&view=contact&id=' . $avatars[$uid]->slug . '&catid=' . $avatars[$uid]->catslug) : ''; if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') { $comment->avatar = JURI::base() . '/' . $avatars[$uid]->avatar; } } break; case 'discussions': if (count($users)) { $db->setQuery('SELECT id as userid, avatar FROM #__discussions_users WHERE id in (' . implode(',', $users) . ')'); $avatars = $db->loadObjectList('userid'); } $avatarA = JPATH_SITE . '/images/discussions/users/'; $avatarL = JURI::base() . 'images/discussions/users/'; foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = ''; if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') { if (file_exists($avatarA . $uid . '/large/' . $avatars[$uid]->avatar)) { $comment->avatar = $avatarL . $uid . '/large/' . $avatars[$uid]->avatar; } } } break; case 'easyblog': $router = JPATH_SITE . '/components/com_easyblog/helpers/router.php'; if (is_file($router)) { require_once($router); require_once(EBLOG_HELPERS . '/image.php'); if (count($users)) { $db->setQuery('SELECT id as userid, avatar FROM #__easyblog_users WHERE id in (' . implode(',', $users) . ')'); $avatars = $db->loadObjectList('userid'); } $avatarA = JPATH_ROOT . DS . EasyImageHelper::getAvatarRelativePath() . DS; $avatarL = JURI::base() . EasyImageHelper::getAvatarRelativePath() . '/'; foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = EasyBlogRouter::_('index.php?option=com_easyblog&view=blogger&layout=listings&id=' . $uid, false); if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') { if (file_exists($avatarA . $avatars[$uid]->avatar)) { $comment->avatar = $avatarL . $avatars[$uid]->avatar; } } } } break; case 'easydiscuss': $router = JPATH_SITE . '/components/com_easydiscuss/helpers/router.php'; if (is_file($router)) { require_once($router); require_once(JPATH_SITE . '/components/com_easydiscuss/helpers/helper.php'); require_once(JPATH_SITE . '/components/com_easydiscuss/helpers/image.php'); if (count($users)) { $db->setQuery('SELECT id as userid, avatar FROM #__discuss_users WHERE id in (' . implode(',', $users) . ')'); $avatars = $db->loadObjectList('userid'); } $avatarA = JPATH_ROOT . DS . DiscussImageHelper::getAvatarRelativePath() . DS; $avatarL = JURI::base() . DiscussImageHelper::getAvatarRelativePath() . '/'; foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = DiscussRouter::_('index.php?option=com_easydiscuss&view=profile&id=' . $uid, false); if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') { if (file_exists($avatarA . $avatars[$uid]->avatar)) { $comment->avatar = $avatarL . $avatars[$uid]->avatar; } } } } break; case 'jomsocial': if (count($users)) { $db->setQuery('SELECT userid, thumb as avatar FROM #__community_users WHERE userid in (' . implode(',', $users) . ')'); $avatars = $db->loadObjectList('userid'); } $avatarA = JPATH_SITE . DS; $avatarL = JURI::base() . '/'; foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = $uid ? JRoute::_('index.php?option=com_community&view=profile&userid=' . $uid) : ''; if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '' && $avatars[$uid]->avatar != 'components/com_community/assets/default_thumb.jpg') { if (file_exists($avatarA . $avatars[$uid]->avatar)) { $comment->avatar = $avatarL . $avatars[$uid]->avatar; } } } break; case 'joobb': $cfgFile = JPATH_SITE . '/components/com_joobb/system/joobbconfig.php'; if (is_file($cfgFile)) { include_once($cfgFile); if (count($users)) { $db->setQuery('SELECT id, avatar_file as avatar FROM #__joobb_users WHERE id in (' . implode(',', $users) . ')'); $avatars = $db->loadObjectList('id'); } $Itemid = self::getItemid('index.php?option=com_joobb'); $config = JoobbConfig::getInstance(); $avatarsPath = $config->getAvatarSettings('avatar_path'); $avatarA = JPATH_SITE . DS . $avatarsPath . DS; $avatarL = JURI::root() . '/' . $avatarsPath . '/'; foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = $uid ? JRoute::_('index.php?option=com_joobb&view=profile&id=' . $avatars[$uid]->id . $Itemid) : ''; if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') { if (file_exists($avatarA . $avatars[$uid]->avatar)) { $comment->avatar = $avatarL . $avatars[$uid]->avatar; } } } } break; case 'k2': $router = JPATH_SITE . '/components/com_k2/helpers/route.php'; if (is_file($router)) { require_once($router); require_once(JPATH_SITE . '/components/com_k2/helpers/utilities.php'); if (count($users)) { $db->setQuery('SELECT userid, image as avatar FROM #__k2_users WHERE userid in (' . implode(',', $users) . ')'); $avatars = $db->loadObjectList('userid'); } $avatarA = JPATH_SITE . '/media/k2/users/'; $avatarL = JURI::base() . 'media/k2/users/'; foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = $uid ? JRoute::_(K2HelperRoute::getUserRoute($uid)) : ''; if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') { if (file_exists($avatarA . $avatars[$uid]->avatar)) { $comment->avatar = $avatarL . $avatars[$uid]->avatar; } } } } break; case 'kunena': $api = JPATH_ADMINISTRATOR . '/components/com_kunena/api.php'; if (is_file($api)) { require_once($api); if (count($users)) { $db->setQuery('SELECT userid, avatar FROM #__kunena_users WHERE userid in (' . implode(',', $users) . ')'); $avatars = $db->loadObjectList('userid'); } $avatarA = JPATH_SITE . '/media/kunena/avatars/'; $avatarL = JURI::base() . 'media/kunena/avatars/'; foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = $uid ? KunenaRoute::_('index.php?option=com_kunena&func=profile&userid=' . $uid) : ''; if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') { if (is_file($avatarA . $avatars[$uid]->avatar)) { $comment->avatar = $avatarL . $avatars[$uid]->avatar; } } } } break; case 'phocagallery': $helper = JPATH_SITE . '/components/com_phocagallery/libraries/phocagallery/path/path.php'; if (is_file($helper)) { require_once($helper); if (count($users)) { $db->setQuery('SELECT userid, avatar FROM #__phocagallery_user WHERE userid in (' . implode(',', $users) . ')'); $avatars = $db->loadObjectList('userid'); } $path = PhocaGalleryPath::getPath(); $avatarA = $path->avatar_abs; $avatarL = $path->avatar_rel; foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = ''; if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') { if (is_file($avatarA . $avatars[$uid]->avatar)) { $comment->avatar = $avatarL . $avatars[$uid]->avatar; } } } } break; case 'slogin': $helper = JPATH_SITE . '/plugins/slogin_integration/profile/profile.php'; if (is_file($helper)) { if (count($users)) { $db->setQuery('SELECT user_id as userid, social_profile_link as link, avatar FROM #__plg_slogin_profile WHERE current_profile = 1 AND user_id in (' . implode(',', $users) . ')'); $avatars = $db->loadObjectList('userid'); } $plugin = JPluginHelper::getPlugin('slogin_integration', 'profile'); $pluginParams = new JRegistry(); $pluginParams->loadString($plugin->params); $folder = $pluginParams->get('rootfolder', 'images/avatar'); $avatarA = JPATH_SITE . '/' . $folder . '/'; $avatarL = JURI::base() . $folder . '/'; foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = $avatars[$uid]->link; if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') { if (file_exists($avatarA . $avatars[$uid]->avatar)) { $comment->avatar = $avatarL . $avatars[$uid]->avatar; } } } } else { $helper = JPATH_SITE . '/plugins/slogin_integration/slogin_avatar/slogin_avatar.php'; if (is_file($helper)) { if (count($users)) { $db->setQuery('SELECT userid, photo_src as avatar FROM #__plg_slogin_avatar WHERE main = 1 AND userid in (' . implode(',', $users) . ')'); $avatars = $db->loadObjectList('userid'); } $plugin = JPluginHelper::getPlugin('slogin_integration', 'slogin_avatar'); $pluginParams = new JRegistry(); $pluginParams->loadString($plugin->params); $folder = $pluginParams->get('rootfolder', 'images/avatar'); $avatarA = JPATH_SITE . '/' . $folder . '/'; $avatarL = JURI::base() . $folder . '/'; foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = ''; if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') { if (file_exists($avatarA . $avatars[$uid]->avatar)) { $comment->avatar = $avatarL . $avatars[$uid]->avatar; } } } } } break; case 'easyprofile': $api = JPATH_ADMINISTRATOR . '/components/com_jsn/jsn.php'; if (is_file($api)) { if (count($users)) { $db->setQuery('SELECT id as userid, avatar FROM #__jsn_users WHERE id in (' . implode(',', $users) . ')'); $avatars = $db->loadObjectList('userid'); } foreach ($comments as &$comment) { $uid = (int)$comment->userid; $comment->profileLink = $uid ? JRoute::_('index.php?option=com_jsn&view=profile&id=' . $uid) : ''; if (isset($avatars[$uid]) && $avatars[$uid]->avatar != '') { if (is_file(JPATH_SITE . '/' . $avatars[$uid]->avatar)) { $comment->avatar = JURI::base() . $avatars[$uid]->avatar; } } } } break; case 'gravatar': default: foreach ($comments as &$comment) { $comment->profileLink = ''; $comment->avatar = $this->getGravatar($comment->email); } break; } if ($avatar_default_avatar == 'custom' && empty($avatar_custom_default_avatar)) { $avatar_default_avatar = 'default'; } foreach ($comments as &$comment) { if (empty($comment->avatar)) { switch ($avatar_default_avatar) { case 'gravatar': $comment->avatar = $this->getGravatar($comment->email); break; case 'custom': $comment->avatar = JURI::base() . ltrim($avatar_custom_default_avatar, '/'); break; case 'default': $comment->avatar = JURI::base() . 'components/com_jcomments/images/no_avatar.png'; break; } } $comment->avatar = self::createImg($comment->avatar, JComments::getCommentAuthorName($comment)); if ($avatar_link && !empty($comment->profileLink)) { $comment->avatar = self::createLink($comment->avatar, $comment->profileLink, $avatar_link_target); } } return; }
function getAvatar() { $avatar_link = ''; if ($this->avatar == 'tdefault.png' || $this->avatar == 'default_teamblog.png' || $this->avatar == 'components/com_easyblog/assets/images/default_teamblog.png' || $this->avatar == 'components/com_easyblog/assets/images/tdefault.png' || empty($this->avatar)) { $avatar_link = 'components/com_easyblog/assets/images/default_teamblog.png'; } else { $avatar_link = EasyImageHelper::getAvatarRelativePath('team') . '/' . $this->avatar; } return rtrim(JURI::root(), '/') . '/' . $avatar_link; }
public static function getAndRemoveImages($content) { //try to search for the 1st img in the blog $img = ''; $pattern = '#<img[^>]*>#i'; $result = array(); preg_match($pattern, $content, $matches); if (isset($matches[0]) && !empty($matches[0])) { $images = $matches[0]; if (!is_array($images)) { $images = array($images); } foreach ($images as $image) { $content = str_ireplace($image, '', $content); // Get the URL to the image $pattern = '/src=[\\"\']?([^\\"\']?.*(png|jpg|jpeg|gif))[\\"\']?/i'; preg_match($pattern, $image, $matches); if ($matches) { $imgPath = $matches[1]; $source = EasyImageHelper::rel2abs($imgPath, JURI::root()); $result[] = $source; } } } $obj = new stdClass(); $obj->content = $content; $obj->images = $result; return $obj; }