From a2dfd1417502558a9470335a41170f05ca3477cd Mon Sep 17 00:00:00 2001 From: Amol Thite Date: Thu, 9 Nov 2017 12:05:57 +0530 Subject: [PATCH 1/2] Task #113298 feat: [API] : Rewrite the groups resource to support ACL and filters --- easysocial/easysocial/groups.php | 219 +++++++++++++++---------------- 1 file changed, 103 insertions(+), 116 deletions(-) diff --git a/easysocial/easysocial/groups.php b/easysocial/easysocial/groups.php index 474987a..52b0adc 100644 --- a/easysocial/easysocial/groups.php +++ b/easysocial/easysocial/groups.php @@ -9,17 +9,13 @@ * Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API) * and the com_api extension by Brian Edgerton (http://www.edgewebworks.com) */ - defined('_JEXEC') or die('Restricted access'); jimport('joomla.plugin.plugin'); jimport('joomla.html.html'); -require_once JPATH_ADMINISTRATOR . '/components/com_easysocial/includes/foundry.php'; -require_once JPATH_ADMINISTRATOR . '/components/com_easysocial/models/groups.php'; -require_once JPATH_ADMINISTRATOR . '/components/com_easysocial/models/covers.php'; -require_once JPATH_ADMINISTRATOR . '/components/com_easysocial/models/fields.php'; -require_once JPATH_SITE . '/plugins/api/easysocial/libraries/mappingHelper.php'; +// @TODO - must be include at bootsraping +JLoader::register("EasySocialApiMappingHelper", JPATH_SITE . '/plugins/api/easysocial/libraries/mappingHelper.php'); /** * API class EasysocialApiResourceGroups @@ -29,151 +25,142 @@ class EasysocialApiResourceGroups extends ApiResource { /** - * Method description + * Method to get groups list * * @return mixed * + * @deprecated 2.0 use post instead + * * @since 1.0 */ public function get() { - $this->getGroups(); + $app = JFactory::getApplication(); + $mygroups = $app->input->get('mygroups', false, 'BOOLEAN'); + $inputArray = $app->input->getArray(); + + // Set values for post + foreach ($inputArray as $key => $value) + { + $app->input->post->set($key, $value); + } + + // Special case for my groups + if ($mygroups) + { + $app->input->post->set('mine', true); + } + + $this->post(); } /** - * Method description + * Method to get groups list * - * @return mixed + * @return ApiPlugin response object * - * @since 1.0 + * @since 2.0 */ public function post() { - $this->plugin->err_code = 405; - $this->plugin->err_message = JText::_('PLG_API_EASYSOCIAL_USE_GET_METHOD_MESSAGE'); - $this->plugin->setResponse(null); - } + $app = JFactory::getApplication(); + $input = $app->input; + $filters = $input->post->getArray(); + $user = ES::user(); - /** - * Method function use for get friends data - * - * @return mixed - * - * @since 1.0 - */ - public function getGroups() - { - $app = JFactory::getApplication(); - $log_user = JFactory::getUser($this->plugin->get('user')->id); - $search = $app->input->get('search', '', 'STRING'); + $apiResponse = new stdclass; + $apiResponse->result = array(); + $apiResponse->empty_message = JText::_('COM_API_GROUPS_EMPTY_ALL'); - $userid = $log_user->id; - $mapp = new EasySocialApiMappingHelper; + $limit = $app->input->get('limit', 10, 'INT'); + $filters['limit'] = $limit; - $filters = array(); - $filters['category'] = $app->input->get('category', 0, 'INT'); - $filters['uid'] = $app->input->get('target_user', 0, 'INT'); + // Set default filters + $options['state'] = isset($filters['state']) ? $filters['state'] : SOCIAL_CLUSTER_PUBLISHED; + $options['types'] = isset($filters['types']) ? $filters['types'] : $user->isSiteAdmin() ? 'all' : 'user'; + $options['ordering'] = isset($filters['ordering']) ? $filters['ordering'] : 'latest'; - $res = new stdclass; - $res->result = array(); - $res->empty_message = ''; + $model = ES::model('Groups'); + $MappingHelper = new EasySocialApiMappingHelper; + $groups = array(); - // Change target user - if ($filters['uid'] != 0) + if (isset($filters['mine'])) { - $userid = $filters['uid']; + $options['userid'] = $user->id; + $options['types'] = 'participated'; + $options['featured'] = ''; + $apiResponse->empty_message = JText::_('COM_API_GROUPS_EMPTY_CREATED'); } - - $filters['types'] = $app->input->get('type', 0, 'INT'); - $filters['state'] = $app->input->get('state', 0, 'INT'); - - $filters['all'] = $app->input->get('all', false, 'BOOLEAN'); - $filters['featured'] = $app->input->get('featured', false, 'BOOLEAN'); - $filters['mygroups'] = $app->input->get('mygroups', false, 'BOOLEAN'); - $filters['invited'] = $app->input->get('invited', false, 'BOOLEAN'); - - $filters['uid'] = ($filters['mygroups']) ? $log_user->id : $filters['uid']; - - $limit = $app->input->get('limit', 10, 'INT'); - $limitstart = $app->input->get('limitstart', 0, 'INT'); - - $model = FD::model('Groups'); - $userObj = FD::user($userid); - $options = array('state' => SOCIAL_STATE_PUBLISHED,'ordering' => 'latest','types' => $userObj->isSiteAdmin() ? 'all' : 'user'); - $groups = array(); - - if ($filters['featured']) + elseif (isset($filters['invited'])) { - $options['featured'] = true; - $featured = $model->getGroups($options); - $groups = $mapp->mapItem($featured, 'group', $log_user->id); - - if (count($groups) > 0 && $groups != false && is_array($groups)) - { - $res->result = array_slice($groups, $limitstart, $limit); - $this->plugin->setResponse($res); - } - $res->empty_message = JText::_('COM_EASYSOCIAL_GROUPS_EMPTY_FEATURED'); + $options['invited'] = $user->id; + $options['types'] = 'all'; + $apiResponse->empty_message = JText::_('COM_API_GROUPS_EMPTY_INVITED'); } - else + elseif (isset($filters['pending'])) { - if ($filters['all']){ - $res->empty_message = JText::_('COM_EASYSOCIAL_GROUPS_EMPTY_ALL'); - } - - if ($filters['mygroups']) - { - $options['uid'] = $log_user->id; - $options['types'] = 'all'; - $res->empty_message = JText::_('COM_EASYSOCIAL_GROUPS_EMPTY_MINE'); - } - - if ($filters['invited']) - { - $options['invited'] = $userid; - $options['types'] = 'all'; - $res->empty_message = JText::_('COM_EASYSOCIAL_GROUPS_EMPTY_INVITED'); - } - - if ($filters['category']) - { - $options['category'] = $categoryId; - $res->empty_message = JText::_('COM_EASYSOCIAL_GROUPS_EMPTY_CATEGORY'); - } + $options['uid'] = $user->id; + $options['state'] = SOCIAL_CLUSTER_DRAFT; + $options['types'] = 'user'; + $apiResponse->empty_message = JText::_('COM_API_CLUSTER_NO_PENDING_MODERATION_GROUP'); + } + elseif (isset($filters['featured'])) + { + $options['featured'] = true; + $apiResponse->empty_message = JText::_('COM_API_GROUPS_EMPTY_FEATURED'); + } + elseif (isset($filters['participated']) && $user->id) + { + $options['userid'] = $user->id; + $options['types'] = 'participated'; + } + elseif (isset($filters['category'])) + { + $categoryId = $filters['category']; + $category = ES::table('GroupCategory'); + $category->load($categoryId); - if ($filters['uid'] == 0) + // Check if this category is a container or not + if ($category->container) { - $groups = $model->getGroups($options); - } - elseif ($search) - { - // Get exclusion list - $exclusion = $app->input->get('exclusion', array(), 'array'); - $options = array('unpublished' => false, 'exclusion' => $exclusion); - $groups = $model->getGroups($search, $options); + // Get all child ids from this category + $categoryModel = ES::model('ClusterCategory'); + $childs = $categoryModel->getChildCategories($category->id); + + $childIds = array(); + + foreach ($childs as $child) + { + $childIds[] = $child->id; + } + + // If the childs is empty, we assign the parent itself + if (empty($childIds)) + { + $options['category'] = $categoryId; + } + else + { + $options['category'] = $childIds; + } } else { - $groups = $model->getUserGroups($filters['uid']); + $options['category'] = $categoryId; } - if ($limit) - { - $groups = array_slice($groups, $limitstart, $limit); - } - - $groups = $mapp->mapItem($groups, 'group', $log_user->id); - } - if ($groups == null && $res->empty_message == '' ) - { - $res->empty_message = JText::_('PLG_API_EASYSOCIAL_GROUP_NOT_FOUND'); + $apiResponse->empty_message = JText::_('COM_API_GROUPS_EMPTY_CATEGORY'); } - if ($groups != null) + + $groups = $model->getGroups($options); + $groups = $MappingHelper->mapItem($groups, 'group', $user->id); + + if (! empty($groups)) { - $res->empty_message = ''; - $res->result = $groups; + $apiResponse->empty_message = ''; + $apiResponse->result = $groups; } - $this->plugin->setResponse($res); + $this->plugin->setResponse($apiResponse); } } From 6b88e0a0d85a7f6485eba9356578e0df4fbfb2a8 Mon Sep 17 00:00:00 2001 From: Amol Thite Date: Fri, 1 Dec 2017 14:38:22 +0530 Subject: [PATCH 2/2] Feature #113672 --- easyblog/easyblog5/latest.php | 202 +++++++++--------- easyblog/helper/simpleschema.php | 342 +++++++++++++++++-------------- 2 files changed, 291 insertions(+), 253 deletions(-) diff --git a/easyblog/easyblog5/latest.php b/easyblog/easyblog5/latest.php index 5706ed0..e5d33a2 100644 --- a/easyblog/easyblog5/latest.php +++ b/easyblog/easyblog5/latest.php @@ -1,124 +1,122 @@ - * @link http://www.techjoomla.com -*/ -defined('_JEXEC') or die( 'Restricted access' ); -jimport('joomla.user.user'); -jimport( 'simpleschema.easyblog.category' ); -jimport( 'simpleschema.easyblog.person' ); -jimport( 'simpleschema.easyblog.blog.post' ); -/* -require_once( EBLOG_HELPERS . '/date.php' ); -require_once( EBLOG_HELPERS . '/string.php' ); -require_once( EBLOG_CLASSES . '/adsense.php' ); -*/ -require_once( JPATH_ADMINISTRATOR.'/components/com_easyblog/includes'. '/date/date.php' ); -require_once( JPATH_ADMINISTRATOR.'/components/com_easyblog/includes'. '/string/string.php' ); -require_once( JPATH_ADMINISTRATOR.'/components/com_easyblog/includes'. '/adsense/adsense.php' ); -require_once( JPATH_ADMINISTRATOR.'/components/com_easyblog/includes'. '/formatter/formatter.php' ); + * @package Joomla.Site + * @subpackage Com_api-plugins + * + * @copyright Copyright (C) 2009-2014 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved. + * @license GNU GPLv2 + * @link http://techjoomla.com + * Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API) + * and the com_api extension by Brian Edgerton (http://www.edgewebworks.com) + */ +defined('_JEXEC') or die('Restricted access'); +/** + * API class EasyblogApiResourceLatest + * + * @since 1.0 + */ class EasyblogApiResourceLatest extends ApiResource { - - public function __construct( &$ubject, $config = array()) { - parent::__construct( $ubject, $config = array() ); - - } - - public function get() { - + /** + * Method to get the list of available logs on site + * + * @return ApiPlugin response object + * + * @since 1.0 + */ + public function get() + { $input = JFactory::getApplication()->input; - $model = EasyBlogHelper::getModel( 'Blog' ); - - //$id = $input->get('id', null, 'INT'); - $id = 0; $search = $input->get('search', '', 'STRING'); - $featured = $input->get('featured',0,'INT'); - $tags = $input->get('tags',0,'INT'); - $user_id = $input->get('user_id',0,'INT'); - $limitstart = $input->get('limitstart',0,'INT'); - $limit = $input->get('limit',10,'INT'); + $featuredRequested = $input->get('featured', 0, 'INT'); + $tags = $input->get('tags', 0, 'INT'); + $userId = $input->get('user_id', 0, 'INT'); + $limitstart = $input->get('limitstart', 0, 'INT'); + $limit = $input->get('limit', 10, 'INT'); + + /* + * @FIXME add proper paginagioon support once the stackideas support it + * for now it won't support limit if the limitstart is 0 and will take the limit from easyblog config + */ + $pagination = $limitstart . ' , ' . $limit; $posts = array(); - // If we have an id try to fetch the user - $blog = EasyBlogHelper::table( 'Blog' ); - $blog->load( $id ); - $modelPT = EasyBlogHelper::getModel( 'PostTag' ); - - if($tags) - { - $rows = $model->getTaggedBlogs( $tags ); - }//for get featured blog - else if($featured) + $model = EB::model('Blog'); + $blogs = array(); + $latestData = array(); + + $featured = $model->getFeaturedBlog('', EBLOG_MAX_FEATURED_POST); + $excludeIds = array(); + + if ($featuredRequested) + { + $blogs = $featured; + } + elseif ($tags) { - $rows = $this->getfeature_Blog(); - $sorting = $this->plugin->params->get( 'sorting' , 'featured' ); - }//for get users blog - else if($user_id) - { $blogs = EasyBlogHelper::getModel( 'Blog' ); - $rows = $blogs->getBlogsBy('blogger', $user_id, 'latest'); + // @TODO add limit support + $blogs = $model->getTaggedBlogs($tags); + } + elseif ($userId) + { + // @TODO Add ACL support + $blogs = $model->getBlogsBy('blogger', $userId, 'latest', $pagination, EBLOG_FILTER_PUBLISHED, $search, true, null, false, false, true, '', '', + null, 'listlength', false, '', '', false, '', ''); } else - { //to get latest blog - //$sorting = $this->plugin->params->get( 'sorting' , 'latest' ); - //$rows = $model->getBlogsBy( $sorting , '' , $sorting , 0, EBLOG_FILTER_PUBLISHED, $search ); - $rows = $model->getBlogsBy('', '', 'latest', 0, EBLOG_FILTER_PUBLISHED, $search, true, array(), false, false, true, '', '', null, 'listlength', false); - //$rows = EB::formatter('list', $rows, false); + { + foreach ($featured as $item) + { + $excludeIds[] = $item->id; + } + + $blogs = $model->getBlogsBy('', '', 'latest', $pagination, EBLOG_FILTER_PUBLISHED, $search, true, $excludeIds, false, false, true, '', '', + null, 'listlength', false, '', '', false, '', ''); } - $rows = EB::formatter('list', $rows, false); - //data mapping - foreach ($rows as $k => $v) + + $blogs = EB::formatter('list', $blogs, false); + $schemaObject = new EasyBlogSimpleSchema_Plg; + $model = EB::model('Ratings'); + + foreach ($blogs as $blog) { - //$item = EB::helper( 'simpleschema' )->mapPost($v,'', 100, array('text')); - $scm_obj = new EasyBlogSimpleSchema_plg(); - $item = $scm_obj->mapPost($v,'', 100, array('text')); - - $item->tags = $modelPT->getBlogTags($item->postid); - $item->isowner = ( $v->created_by == $this->plugin->get('user')->id )?true:false; - - if($v->blogpassword != '') + $item = $schemaObject->mapPost($blog, '', 100); + $ratingValue = $model->getRatingValues($item->postid, 'entry'); + $item->rate = $ratingValue; + + if ($item->rate->ratings == 0) { - $item->ispassword = true; - } - else - { - $item->ispassword = false; - } - - $item->blogpassword = $v->blogpassword; - $model = EasyBlogHelper::getModel( 'Ratings' ); - $ratingValue = $model->getRatingValues( $item->postid, 'entry'); - $item->rate = $ratingValue; - $item->isVoted = $model->hasVoted($item->postid,'entry',$this->plugin->get('user')->id); - if($item->rate->ratings==0) - { - $item->rate->ratings=-2; + $item->rate->ratings = - 2; } - + $posts[] = $item; } - $posts = array_slice($posts, $limitstart,$limit); - $this->plugin->setResponse( $posts ); + + $apiResponse = new stdClass; + $apiResponse->result = $posts; + $this->plugin->setResponse($apiResponse); + } + + /** + * Method + * + * @return void + * + * @since 1.0 + */ + public static function getName() + { } - // get feature blog function. - public function getfeature_Blog() + + /** + * Method + * + * @return void + * + * @since 1.0 + */ + public static function describe() { - $app = JFactory::getApplication(); - $limit = $app->input->get('limit',10,'INT'); - $categories = $app->input->get('categories','','STRING'); - $blogss = new EasyBlogModelBlog(); - $blogss->setState('limit',$limit); - $res = $blogss->getFeaturedBlog(array(),$limit); - return $res; - } - public static function getName() { - } - - public static function describe() { - - } } diff --git a/easyblog/helper/simpleschema.php b/easyblog/helper/simpleschema.php index 65399d7..2e27661 100644 --- a/easyblog/helper/simpleschema.php +++ b/easyblog/helper/simpleschema.php @@ -1,229 +1,269 @@ - * @link http://www.techjoomla.com -*/ + * @package Joomla.Site + * @subpackage Com_api-plugins + * + * @copyright Copyright (C) 2009-2014 Techjoomla, Tekdi Technologies Pvt. Ltd. All rights reserved. + * @license GNU GPLv2 + * @link http://techjoomla.com + * Work derived from the original RESTful API by Techjoomla (https://github.com/techjoomla/Joomla-REST-API) + * and the com_api extension by Brian Edgerton (http://www.edgewebworks.com) + */ defined('_JEXEC') or die('Restricted access'); -jimport( 'simpleschema.easyblog.blog.post' ); - -class EasyBlogSimpleSchema_plg -{ - public function mapPost($row, $strip_tags='', $text_length=0, $skip=array()) { - $config = EasyBlogHelper::getConfig(); - $blog = EB::table( 'Blog' ); - $blog->load( $row->id ); +use Joomla\String\StringHelper; +jimport('simpleschema.easyblog.blog.post'); - $profile = EB::table( 'Profile', 'Table' ); - $profile->load( $row->created_by ); +/** + * API class EasyBlogSimpleSchema_Plg + * + * @since 5.0 + */ +class EasyBlogSimpleSchema_Plg +{ + /** + * Map the post fields as per mobile app requirement + * + * @param Object $row The EasyBlogPost class object + * @param Array $stripTags Tags to strip + * @param string $textLength The maximum text length allowed to show + * @param Array $skip The array of tag which should be skip. + * + * @return object + * + * @since 5.0 + */ + public function mapPost($row, $stripTags = '', $textLength = 0, $skip = array()) + { + $blogsMeta = new stdClass; + $blogsMeta->text = $row->intro . $row->content; + $blogsMeta->text = EasyBlogHelper::helper('Videos')->processVideos($blogsMeta->text); + $row->contributionDisplay = JText::_('COM_EASYBLOG_BLOGS_WIDE'); + $contribution = $row->getBlogContribution(); - $created = EasyBlogDate::dateWithOffSet( $row->created ); - $formatDate = true; - - if(EasyBlogHelper::getJoomlaVersion() >= '1.6') + if ($contribution !== false) { - $eb_lang = new EasyBlogString(); - $langCode = $eb_lang->getLangCode(); - if($langCode != 'en-GB' || $langCode != 'en-US') - $formatDate = false; + $row->contributionDisplay = $contribution->getTitle(); } - $blog->created = $created->toMySQL(); - $blog->text = $row->intro . $row->content; - - $config->set('max_video_width', 320); - $config->set('max_video_width', 180); - $blog->text = EasyBlogHelper::helper( 'Videos' )->processVideos( $blog->text ); - - $adsnc = new EasyBlogAdsense(); - $blog->text = $adsnc->stripAdsenseCode( $blog->text ); - - $category = EB::table( 'Category', 'Table' ); - $category->load( $row->category_id ); - - $item = new PostSimpleSchema; - $item->textplain = $blog->text; - - // @TODO : Take care of a case when strip tags and length are used together - if ($strip_tags) { - $item->textplain = strip_tags($blog->text, $strip_tags); - } - - if ($text_length > 0) { - $pos = JString::strpos(strip_tags($item->textplain), ' ', false); - $item->textplain = JString::substr(strip_tags($blog->text), 0, $pos); - } - //$image_data = json_decode($blog->image); - $item->postid = $blog->id; - $item->title = $blog->title; - $item->text = $blog->text; - $item->textplain = $this->sanitize($item->textplain); + $row->featured = $row->isFeatured; + $adsense = new EasyBlogAdsense; + $blogsMeta->text = $adsense->strip($blogsMeta->text); - $item->image = new stdClass(); - if($row->image) + $item = new PostSimpleSchema; + $item->textplain = $blogsMeta->text; + + // @TODO : Take care of a case when strip tags and length are used together + if ($stripTags) { - //$item->image->url = $blog->getImage(); - $item->image->url = $row->getImage('large'); - $item->image->url = 'http:'.$item->image->url; - //$item->image->url = ltrim($item->image->url,'//'); + $item->textplain = strip_tags($item->textplain, $stripTags); } - else + + if ($textLength > 0) { - $item->image->url = null; + $pos = StringHelper::strpos(strip_tags($item->textplain), ' ', false); + $item->textplain = StringHelper::substr(strip_tags($item->textplain), 0, $pos); } - //$item->image->url = ($image_data->url)?$image_data->url:''; - //$item->image->url = null; - - $item->created_date = $blog->created; - $ebdate = new EasyBlogDate(); - $item->created_date_elapsed = $ebdate->getLapsedTime( $blog->created ); - - $item->author->name = $profile->nickname; - $item->author->photo = JURI::root() . $profile->avatar; - - $item->category->categoryid = $category->id; - $item->category->title = $category->title; - - $item->url = JURI::root() . trim(EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $blog->id ), '/'); - - // Tags - $modelPT = EasyBlogHelper::getModel( 'PostTag' ); - $item->tags = $modelPT->getBlogTags($blog->id); - foreach ($skip as $v) { - unset($item->$v); - } - //handle image path - if(strpos($item->text,'src="data:image') == false) - { - - if (strpos($item->text,'href="index')) + $item->image = new stdClass; + $item->postid = $row->id; + $item->title = $row->title; + $item->text = $blogsMeta->text; + $item->textplain = $this->sanitize($item->textplain); + $item->tags = $row->tags; + $item->created_date = EB::date($row->created)->format(); + $item->created_date_elapsed = EB::date()->getLapsedTime($row->created); + $item->author->name = $row->author->getName(); + $item->author->photo = $row->author->getAvatar(); + $item->author->email = $row->author->user->email; + $item->category->categoryid = $row->category->id; + $item->category->title = $row->category->title; + $item->category->description = $row->category->description; + $item->category->created_date = $row->category->created; + $item->url = $row->getPermalink(true, true); + $item->ispassword = $row->isPasswordProtected(); + $item->blogpassword = $row->blogpassword; + $item->isowner = ($row->created_by == jfactory::getUser()->id); + $item->isVoted = $row->hasVoted(); + $item->featured = boolval($row->isFeatured); + $item->image->url = $row->getImage('large', true, true); + + // @TODO Optimize this code + if (strpos($item->text, 'src="data:image') == false) + { + if (strpos($item->text, 'href="index')) { - $item->introtext = str_replace('href="index','href="'.JURI::root().'index',$item->introtext); - $item->text = str_replace('href="index','href="'.JURI::root().'index',$item->text); - //$item->text = str_replace('src="','src="'.JURI::root(),$item->text); + // $item->introtext = str_replace('href="index', 'href="' . JURI::root() . 'index', $item->introtext); + $item->text = str_replace('href="index', 'href="' . JURI::root() . 'index', $item->text); } - - if (strpos($item->text,'href="images')) + + if (strpos($item->text, 'href="images')) { - $item->introtext = str_replace('href="images','href="'.JURI::root().'images',$item->introtext); - $item->text = str_replace('href="images','href="'.JURI::root().'images',$item->text); - //$item->text = str_replace('src="','src="'.JURI::root(),$item->text); + // $item->introtext = str_replace('href="images', 'href="' . JURI::root() . 'images', $item->introtext); + $item->text = str_replace('href="images', 'href="' . JURI::root() . 'images', $item->text); } - if ( strpos($item->text,'src="images') || strpos($item->introtext,'src="images') ) - { - $item->introtext = str_replace('src="','src="'.JURI::root(),$item->introtext); - $item->text = str_replace('src="','src="'.JURI::root(),$item->text); + if (strpos($item->text, 'src="images')) // || strpos($item->introtext, 'src="images')) + { + // $item->introtext = str_replace('src="', 'src="' . JURI::root(), $item->introtext); + $item->text = str_replace('src="', 'src="' . JURI::root(), $item->text); } - if ( strpos($item->text,'src="/')) - { - $item->introtext = str_replace('src="/','src="'.'http://',$item->introtext); - $item->text = str_replace('src="/','src="'.'http://',$item->text); + if (strpos($item->text, 'src="/')) + { + // $item->introtext = str_replace('src="/', 'src="' . 'http://', $item->introtext); + $item->text = str_replace('src="/', 'src="' . 'http://', $item->text); } - - if ( strpos($item->text,'href="/')) - { - $item->introtext = str_replace('href="/','href="'.'http://',$item->introtext); - $item->text = str_replace('href="/','href="'.'http://',$item->text); + + if (strpos($item->text, 'href="/')) + { + // $item->introtext = str_replace('href="/', 'href="' . 'http://', $item->introtext); + $item->text = str_replace('href="/', 'href="' . 'http://', $item->text); } } + foreach ($skip as $v) + { + unset($item->$v); + } + return $item; } - - public function sanitize($text) { + + /** + * Method to sanitize string + * + * @param string $text String to sanitize + * + * @return string + * + * @since 1.0 + */ + public function sanitize($text) + { $text = htmlspecialchars_decode($text); $text = str_ireplace(' ', ' ', $text); - + return $text; } - } -class EasyBlogSimpleSchema_4 +/** + * API class EasyBlogSimpleSchema_4 + * + * @since 4.0 + */ +class EasyBlogSimpleSchema_4 { - public function mapPost($row, $strip_tags='', $text_length=0, $skip=array()) { - $config = EasyBlogHelper::getConfig(); - - $blog = EasyBlogHelper::getTable( 'Blog' ); - $blog->load( $row->id ); + /** + * Map the post fields as per mobile app requirement + * + * @param Object $row The EasyBlogPost class object + * @param Array $strip_tags Tags to strip + * @param string $text_length The maximum text length allowed to show + * @param Array $skip The array of tag which should be skip. + * + * @return object + * + * @since 4.0 + */ + public function mapPost($row, $strip_tags = '', $text_length = 0, $skip = array()) + { + $config = EasyBlogHelper::getConfig(); + + $blog = EasyBlogHelper::getTable('Blog'); + $blog->load($row->id); - $profile = EasyBlogHelper::getTable( 'Profile', 'Table' ); - $profile->load( $row->created_by ); + $profile = EasyBlogHelper::getTable('Profile', 'Table'); + $profile->load($row->created_by); - $created = EasyBlogDateHelper::dateWithOffSet( $row->created ); + $created = EasyBlogDateHelper::dateWithOffSet($row->created); $formatDate = true; - if(EasyBlogHelper::getJoomlaVersion() >= '1.6') + + if (EasyBlogHelper::getJoomlaVersion() >= '1.6') { $langCode = EasyBlogStringHelper::getLangCode(); - if($langCode != 'en-GB' || $langCode != 'en-US') + + if ($langCode != 'en-GB' || $langCode != 'en-US') + { $formatDate = false; + } } + $blog->created = $created->toMySQL(); - $blog->text = $row->intro . $row->content; - + $blog->text = $row->intro . $row->content; + $config->set('max_video_width', 320); $config->set('max_video_width', 180); - $blog->text = EasyBlogHelper::getHelper( 'Videos' )->processVideos( $blog->text ); - $blog->text = EasyBlogGoogleAdsense::stripAdsenseCode( $blog->text ); - - $category = EasyBlogHelper::getTable( 'Category', 'Table' ); - $category->load( $row->category_id ); - + $blog->text = EasyBlogHelper::getHelper('Videos')->processVideos($blog->text); + $blog->text = EasyBlogGoogleAdsense::stripAdsenseCode($blog->text); + + $category = EasyBlogHelper::getTable('Category', 'Table'); + $category->load($row->category_id); + $item = new PostSimpleSchema; $item->textplain = $blog->text; - + // @TODO : Take care of a case when strip tags and length are used together - if ($strip_tags) { + if ($strip_tags) + { $item->textplain = strip_tags($blog->text, $strip_tags); } - - if ($text_length > 0) { + + if ($text_length > 0) + { $pos = JString::strpos(strip_tags($item->textplain), ' ', $text_length); $item->textplain = JString::substr(strip_tags($blog->text), 0, $pos); } $image_data = json_decode($blog->image); - + $item->postid = $blog->id; - $item->title = $blog->title; + $item->title = $blog->title; $item->text = $blog->text; $item->textplain = $this->sanitize($item->textplain); - + $item->image = $blog->getImage(); $item->image->url = $image_data->url; $item->created_date = $blog->created; - $item->created_date_elapsed = EasyBlogDateHelper::getLapsedTime( $blog->created ); - + $item->created_date_elapsed = EasyBlogDateHelper::getLapsedTime($blog->created); + $item->author->name = $profile->nickname; $item->author->photo = JURI::root() . $profile->avatar; - + $item->author->email = $profile->email; + $item->category->categoryid = $category->id; $item->category->title = $category->title; - - $item->url = JURI::root() . trim(EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $blog->id ), '/'); - + + $item->url = JURI::root() . trim(EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $blog->id), '/'); + // Tags - $modelPT = EasyBlogHelper::getModel( 'PostTag' ); - $item->tags = $modelPT->getBlogTags($blog->id); + $modelPT = EasyBlogHelper::getModel('PostTag'); + $item->tags = $modelPT->getBlogTags($blog->id); - foreach ($skip as $v) { + foreach ($skip as $v) + { unset($item->$v); } return $item; } - - public function sanitize($text) { + + /** + * Method to sanitize string + * + * @param string $text String to sanitize + * + * @return string + * + * @since 1.0 + */ + public function sanitize($text) + { $text = htmlspecialchars_decode($text); $text = str_ireplace(' ', ' ', $text); - + return $text; } }