Dotclear

source: plugins/dotajax/class.blogrest.php @ 1679

Revision 1679, 5.6 KB checked in by kozlika, 14 years ago (diff)

suppression lignes vides en fin de fichiers PHP.

Line 
1<?php
2# ***** BEGIN LICENSE BLOCK *****
3# This file is part of DotClear REST plugin.
4# Copyright (c) 2007 Bruno Hondelatte,  and contributors.
5# Many, many thanks to Olivier Meunier and the Dotclear Team.
6# All rights reserved.
7#
8# DotClear is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 2 of the License, or
11# (at your option) any later version.
12#
13# DotClear is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with DotClear; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21#
22# ***** END LICENSE BLOCK *****
23
24class blogRest 
25{
26     public static function getPosts($core,$get)
27     {
28          $allowed_params=array('post_id','post_url','user_id','cat_id','cat_url',
29               'post_selected','post_year','post_month','post_day','post_lang',
30               'search','order','limit','post_type');
31          $no_content=isset($get['no_content']);
32          $count_only = isset($get['count_only']);
33
34
35          $params = jsonRestServer::getFilteredParams($allowed_params,$get);
36          if (!isset($params['post_type']))
37               $params['post_type']='post';
38
39          if ($no_content)
40               $params['no_content']=1;
41
42
43          $rs = $core->blog->getPosts($params,$count_only);
44          if ($count_only)
45               return (int)$rs->f(0);
46          $rsp = array();
47          while ($rs->fetch())
48          {
49               $post=array();
50               $post['id'] = $rs->post_id;
51               $post['title'] = $rs->post_title;
52               if (!$no_content) {
53                    $post['excerpt'] = $rs->post_excerpt_xhtml;
54                    $post['content'] = $rs->post_content_xhtml;
55               }
56               $post['user'] = $rs->user_id;
57               $post['creadt'] = $rs->post_creadt;
58               $post['upddt'] = $rs->post_upddt;
59               $post['url'] = $rs->post_url;
60               $post['selected'] = ($rs->post_selected == 1);
61               $post['nb_comments'] = (int)$rs->nb_comment;
62               $post['nb_trackbacks'] = (int)$rs->nb_trackback;
63               $post['category'] = (int)$rs->cat_id;
64
65               $rsp[]=$post;
66          }
67          return $rsp;
68     }
69
70     public static function getCategories($core,$get)
71     {
72          $allowed_params=array('post_type','cat_url','cat_id','id'=>'cat_id');
73          $params = jsonRestServer::getFilteredParams($allowed_params,$get);
74          if (!isset($params['post_type']))
75               $params['post_type']='post';
76
77          $rs = $core->blog->getCategories($params);
78          $rsp = array();
79          while ($rs->fetch())
80          {
81               $cat=array();
82               $cat['id'] = (int)$rs->cat_id;
83               $cat['title'] = $rs->cat_title;
84               $cat['url'] = $rs->cat_url;
85               $cat['desc'] = $rs->cat_desc;
86               $cat['nb_post'] = (int)$rs->nb_post;
87               $cat['position'] = (int)$rs->cat_position;
88               $rsp[]=$cat;
89          }
90          return $rsp;
91     }
92
93     public static function getLangs($core,$get)
94     {
95          $allowed_params=array('post_type','lang');
96          $params = jsonRestServer::getFilteredParams($allowed_params,$get);
97
98          $rs = $core->blog->getLangs($params);
99          $rsp = array();
100          while ($rs->fetch())
101          {
102               $lang=array();
103               $lang['lang'] = $rs->post_lang;
104               $lang['nb_post'] = (int)$rs->nb_post;
105               $rsp[]=$lang;
106          }
107          return $rsp;
108     }
109
110     public static function getDates($core,$get)
111     {
112          $allowed_params=array('post_type','year','month','day','cat_id','cat_url',
113               'post_lang','next','previous','order');
114          $params = jsonRestServer::getFilteredParams($allowed_params,$get);
115          if (!isset($params['post_type']))
116               $params['post_type']='post';
117
118          $rs = $core->blog->getDates($params);
119          $rsp = array();
120          while ($rs->fetch())
121          {
122               $date=array();
123               $date['date'] = $rs->dt;
124               $date['nb_post'] = (int)$rs->nb_post;
125               $rsp[]=$date;
126          }
127          return $rsp;
128     }
129
130     public static function getPostsUsers($core,$get)
131     {
132          $post_type = isset($get['post_type'])?$get['post_type']:null;
133
134          $rs = $core->blog->getPostsUsers($post_type);
135          $rsp = array();
136          while ($rs->fetch())
137          {
138               $user=array();
139               $user['id'] = $rs->user_id;
140               $user['name'] = $rs->user_name;
141               $user['displayname'] = $rs->user_displayname;
142               $rsp[]=$user;
143          }
144          return $rsp;
145     }
146
147     public static function getComments($core,$get)
148     {
149          $allowed_params=array('post_type','post_id','cat_id','comment_id',
150               'comment_trackback','post_url','user_id','q_author','order',
151               'limit');
152          $no_content=isset($get['no_content']);
153          $count_only = isset($get['count_only']);
154
155
156          $params = jsonRestServer::getFilteredParams($allowed_params,$get);
157          if (!isset($params['post_type']))
158               $params['post_type']='post';
159
160          if ($no_content)
161               $params['no_content']=1;
162
163
164          $rs = $core->blog->getComments($params,$count_only);
165          if ($count_only)
166               return (int)$rs->f(0);
167          $rsp = array();
168          while ($rs->fetch())
169          {
170               $comment=array();
171               $comment['id'] = $rs->comment_id;
172               if (!$no_content) {
173                    $comment['content'] = $rs->comment_content;
174               }
175               $comment['date'] = $rs->comment_dt;
176               $comment['upddt'] = $rs->comment_upddt;
177               $comment['author'] = $rs->comment_author;
178               $comment['site'] = $rs->comment_site;
179               $comment['post_title'] = $rs->post_title;
180               $comment['post_title'] = $rs->post_title;
181               $comment['post_title'] = $rs->post_title;
182               $comment['post_title'] = $rs->post_title;
183               $comment['post_title'] = $rs->post_title;
184               $comment['upddt'] = $rs->comment_upddt;
185               $comment['upddt'] = $rs->comment_upddt;
186               $comment['upddt'] = $rs->comment_upddt;
187
188               $comment['user'] = $rs->user_id;
189               $comment['url'] = $rs->comment_url;
190               $comment['selected'] = ($rs->comment_selected == 1);
191               $comment['nb_comments'] = (int)$rs->nb_comment;
192               $comment['nb_trackbacks'] = (int)$rs->nb_trackback;
193               $comment['category'] = (int)$rs->cat_id;
194
195               $rsp[]=$comment;
196          }
197          return $rsp;
198     }
199
200}
201?>
Note: See TracBrowser for help on using the repository browser.

Sites map