|
4 | 4 | //ini_set('display_errors', 1); |
5 | 5 |
|
6 | 6 | jimport('joomla.user.user'); |
7 | | -jimport( 'simpleschema.category' ); |
8 | 7 | jimport( 'simpleschema.person' ); |
9 | 8 | jimport( 'simpleschema.blog.post' ); |
10 | 9 | jimport( 'simpleschema.blog.comment' ); |
|
16 | 15 | class EasyblogApiResourceComments extends ApiResource |
17 | 16 | { |
18 | 17 |
|
19 | | - public function __construct( &$ubject, $config = array()) { |
20 | | - parent::__construct( $ubject, $config = array() ); |
21 | | - |
22 | | - } |
23 | | - |
24 | 18 | public function get() { |
25 | 19 | $input = JFactory::getApplication()->input; |
26 | 20 | $model = EasyBlogHelper::getModel( 'Blog' ); |
27 | 21 | $id = $input->get('id', null, 'INT'); |
28 | 22 | $comments = array(); |
29 | 23 |
|
| 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 | + |
30 | 33 | $rows = $model->getBlogComment($id); |
31 | 34 |
|
32 | 35 | 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; |
36 | 52 |
|
37 | 53 | $comments[] = $item; |
38 | 54 | } |
|
0 commit comments