|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @package EasyBlog |
| 4 | + * @copyright Copyright (C) 2011 Stack Ideas Private Limited. All rights reserved. |
| 5 | + * @license GNU/GPL, see LICENSE.php |
| 6 | + * |
| 7 | + * EasyBlog is free software. This version may have been modified pursuant |
| 8 | + * to the GNU General Public License, and as distributed it includes or |
| 9 | + * is derivative of works licensed under the GNU General Public License or |
| 10 | + * other free or open source software licenses. |
| 11 | + * See COPYRIGHT.php for copyright notices and details. |
| 12 | + */ |
| 13 | + |
| 14 | +defined('_JEXEC') or die('Restricted access'); |
| 15 | +jimport( 'simpleschema.blog.post' ); |
| 16 | + |
| 17 | +class EasyBlogSimpleSchemaHelper |
| 18 | +{ |
| 19 | + public function mapPost($row, $strip_tags='', $text_length=0, $skip=array()) { |
| 20 | + $config = EasyBlogHelper::getConfig(); |
| 21 | + |
| 22 | + $blog = EasyBlogHelper::getTable( 'Blog' ); |
| 23 | + $blog->load( $row->id ); |
| 24 | + |
| 25 | + $profile = EasyBlogHelper::getTable( 'Profile', 'Table' ); |
| 26 | + $profile->load( $row->created_by ); |
| 27 | + |
| 28 | + $created = EasyBlogDateHelper::dateWithOffSet( $row->created ); |
| 29 | + $formatDate = true; |
| 30 | + if(EasyBlogHelper::getJoomlaVersion() >= '1.6') |
| 31 | + { |
| 32 | + $langCode = EasyBlogStringHelper::getLangCode(); |
| 33 | + if($langCode != 'en-GB' || $langCode != 'en-US') |
| 34 | + $formatDate = false; |
| 35 | + } |
| 36 | + $blog->created = $created->toMySQL(); |
| 37 | + |
| 38 | + if( $config->get( 'main_rss_content' ) == 'introtext' ) |
| 39 | + { |
| 40 | + $blog->text = ( !empty( $row->intro ) ) ? $row->intro : $row->content; |
| 41 | + } |
| 42 | + else |
| 43 | + { |
| 44 | + $blog->text = $row->intro . $row->content; |
| 45 | + |
| 46 | + } |
| 47 | + $blog->text = EasyBlogHelper::getHelper( 'Videos' )->strip( $blog->text ); |
| 48 | + $blog->text = EasyBlogGoogleAdsense::stripAdsenseCode( $blog->text ); |
| 49 | + |
| 50 | + $category = EasyBlogHelper::getTable( 'Category', 'Table' ); |
| 51 | + $category->load( $row->category_id ); |
| 52 | + |
| 53 | + $item = new PostSimpleSchema; |
| 54 | + $item->textplain = $blog->text; |
| 55 | + |
| 56 | + // @TODO : Take care of a case when strip tags and length are used together |
| 57 | + if ($strip_tags) { |
| 58 | + $item->textplain = strip_tags($blog->text, $strip_tags); |
| 59 | + } |
| 60 | + |
| 61 | + if ($text_length > 0) { |
| 62 | + $pos = JString::strpos(strip_tags($item->textplain), ' ', $text_length); |
| 63 | + $item->textplain = JString::substr(strip_tags($blog->text), 0, $pos); |
| 64 | + } |
| 65 | + |
| 66 | + $image_data = json_decode($blog->image); |
| 67 | + |
| 68 | + $item->postid = $blog->id; |
| 69 | + $item->title = $blog->title; |
| 70 | + |
| 71 | + $item->text = $blog->text; |
| 72 | + $item->textplain = $this->sanitize($item->textplain); |
| 73 | + |
| 74 | + $item->image = $blog->getImage(); |
| 75 | + $item->image->url = $image_data->url; |
| 76 | + $item->created_date = $blog->created; |
| 77 | + $item->created_date_elapsed = EasyBlogDateHelper::getLapsedTime( $blog->created ); |
| 78 | + |
| 79 | + $item->author->name = $profile->nickname; |
| 80 | + $item->author->photo = JURI::root() . $profile->avatar; |
| 81 | + |
| 82 | + $item->category->categoryid = $category->id; |
| 83 | + $item->category->title = $category->title; |
| 84 | + |
| 85 | + $item->url = JURI::root() . trim(EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $blog->id ), '/'); |
| 86 | + |
| 87 | + foreach ($skip as $v) { |
| 88 | + unset($item->$v); |
| 89 | + } |
| 90 | + |
| 91 | + return $item; |
| 92 | + } |
| 93 | + |
| 94 | + public function sanitize($text) { |
| 95 | + $text = htmlspecialchars_decode($text); |
| 96 | + $text = str_ireplace(' ', ' ', $text); |
| 97 | + |
| 98 | + return $text; |
| 99 | + } |
| 100 | + |
| 101 | +} |
0 commit comments