Skip to content

Commit a4fdc81

Browse files
committed
Added library and helper for blogs
1 parent 8b446b0 commit a4fdc81

File tree

5 files changed

+194
-0
lines changed

5 files changed

+194
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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('&nbsp;', ' ', $text);
97+
98+
return $text;
99+
}
100+
101+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
class CommentSchema {
4+
5+
public $commentid;
6+
7+
public $postid;
8+
9+
public $title;
10+
11+
public $text;
12+
13+
public $textplain;
14+
15+
public $created_date;
16+
17+
public $updated_date;
18+
19+
public $author
20+
21+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
jimport('simpleschema.person');
3+
jimport('simpleschema.category');
4+
5+
class PostSimpleSchema {
6+
7+
public $postid;
8+
9+
public $title;
10+
11+
public $text;
12+
13+
public $textplain;
14+
15+
public $image = array();
16+
17+
public $created_date;
18+
19+
public $created_date_elapsed;
20+
21+
public $updated_date;
22+
23+
public $author;
24+
25+
public $comments;
26+
27+
public $url;
28+
29+
public $tags = array();
30+
31+
public $rating;
32+
33+
public $category;
34+
35+
public function __construct() {
36+
$this->author = new PersonSimpleSchema;
37+
$this->category = new CategorySimpleSchema;
38+
}
39+
40+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
class CategorySimpleSchema {
4+
5+
public $categoryid;
6+
7+
public $title;
8+
9+
public $description;
10+
11+
public $created_date;
12+
13+
public $updated_date;
14+
15+
public $scope;
16+
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
class PersonSimpleSchema {
4+
5+
public $name;
6+
7+
public $email;
8+
9+
public $photo;
10+
11+
public $website;
12+
13+
public $bio;
14+
15+
}

0 commit comments

Comments
 (0)