Skip to content

Commit 6a31bd4

Browse files
committed
List comments for native comments
1 parent af62274 commit 6a31bd4

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

easyblog/easyblog/comments.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//ini_set('display_errors', 1);
55

66
jimport('joomla.user.user');
7-
jimport( 'simpleschema.category' );
87
jimport( 'simpleschema.person' );
98
jimport( 'simpleschema.blog.post' );
109
jimport( 'simpleschema.blog.comment' );
@@ -16,23 +15,40 @@
1615
class EasyblogApiResourceComments extends ApiResource
1716
{
1817

19-
public function __construct( &$ubject, $config = array()) {
20-
parent::__construct( $ubject, $config = array() );
21-
22-
}
23-
2418
public function get() {
2519
$input = JFactory::getApplication()->input;
2620
$model = EasyBlogHelper::getModel( 'Blog' );
2721
$id = $input->get('id', null, 'INT');
2822
$comments = array();
2923

24+
// If we have an id try to fetch the blog
25+
$blog = EasyBlogHelper::getTable( 'Blog' );
26+
$blog->load( $id );
27+
28+
if (!$blog->id) {
29+
$this->plugin->setResponse( $this->getErrorResponse(404, 'Invalid Blog') );
30+
return;
31+
}
32+
3033
$rows = $model->getBlogComment($id);
3134

3235
foreach ($rows as $row) {
33-
$item = new CommentSchema;
34-
$item->commentid = $row->;
35-
$item->postid = $id;
36+
$item = new CommentSimpleSchema;
37+
$item->commentid = $row->id;
38+
$item->postid = $row->post_id;
39+
$item->title = $row->title;
40+
$item->text = EasyBlogCommentHelper::parseBBCode($row->comment);
41+
$item->textplain = strip_tags(EasyBlogCommentHelper::parseBBCode($row->comment));
42+
$item->created_date = $row->created;
43+
$item->created_date_elapsed = EasyBlogDateHelper::getLapsedTime( $row->created );
44+
$item->updated_date = $row->modified;
45+
46+
// Author
47+
$item->author->name = isset($row->poster->nickname) ? $row->poster->nickname : $row->name;
48+
$item->author->photo = isset($row->poster->avatar) ? $row->poster->avatar : 'default_blogger.png';
49+
$item->author->photo = JURI::root() . 'components/com_easyblog/assets/images/' . $item->author->photo;
50+
$item->author->email = $row->email;
51+
$item->author->website = isset($row->poster->url) ? $row->poster->url : $row->url;
3652

3753
$comments[] = $item;
3854
}

easyblog/libraries/simpleschema/blog/comment.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ class CommentSimpleSchema {
1616

1717
public $updated_date;
1818

19+
public $created_date_elapsed;
20+
1921
public $author;
22+
23+
public function __construct() {
24+
$this->author = new PersonSimpleSchema;
25+
}
2026

2127
}

0 commit comments

Comments
 (0)