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 | |
---|
24 | class 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','offset'); |
---|
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 | if (isset($params['offset']) && isset($params['limit'])) { |
---|
43 | $params['limit'] = array($params['offset'],$params['limit']); |
---|
44 | unset($params['offset']); |
---|
45 | } |
---|
46 | |
---|
47 | |
---|
48 | $rs = $core->blog->getPosts($params,$count_only); |
---|
49 | if ($count_only) |
---|
50 | return (int)$rs->f(0); |
---|
51 | $rsp = array(); |
---|
52 | while ($rs->fetch()) |
---|
53 | { |
---|
54 | $post=array(); |
---|
55 | $post['id'] = $rs->post_id; |
---|
56 | $post['title'] = $rs->post_title; |
---|
57 | if (!$no_content) { |
---|
58 | $post['excerpt'] = $rs->post_excerpt_xhtml; |
---|
59 | $post['content'] = $rs->post_content_xhtml; |
---|
60 | } |
---|
61 | $post['user'] = $rs->user_id; |
---|
62 | $post['creadt'] = $rs->post_creadt; |
---|
63 | $post['upddt'] = $rs->post_upddt; |
---|
64 | $post['url'] = $rs->post_url; |
---|
65 | $post['selected'] = ($rs->post_selected == 1); |
---|
66 | $post['nb_comments'] = (int)$rs->nb_comment; |
---|
67 | $post['nb_trackbacks'] = (int)$rs->nb_trackback; |
---|
68 | $post['category'] = (int)$rs->cat_id; |
---|
69 | |
---|
70 | $rsp[]=$post; |
---|
71 | } |
---|
72 | return $rsp; |
---|
73 | } |
---|
74 | |
---|
75 | public static function getCategories($core,$get) |
---|
76 | { |
---|
77 | $allowed_params=array('post_type','cat_url','cat_id','id'=>'cat_id'); |
---|
78 | $params = jsonRestServer::getFilteredParams($allowed_params,$get); |
---|
79 | if (!isset($params['post_type'])) |
---|
80 | $params['post_type']='post'; |
---|
81 | |
---|
82 | $rs = $core->blog->getCategories($params); |
---|
83 | $rsp = array(); |
---|
84 | while ($rs->fetch()) |
---|
85 | { |
---|
86 | $cat=array(); |
---|
87 | $cat['id'] = (int)$rs->cat_id; |
---|
88 | $cat['title'] = $rs->cat_title; |
---|
89 | $cat['url'] = $rs->cat_url; |
---|
90 | $cat['desc'] = $rs->cat_desc; |
---|
91 | $cat['nb_post'] = (int)$rs->nb_post; |
---|
92 | $cat['position'] = (int)$rs->cat_position; |
---|
93 | $rsp[]=$cat; |
---|
94 | } |
---|
95 | return $rsp; |
---|
96 | } |
---|
97 | |
---|
98 | public static function getLangs($core,$get) |
---|
99 | { |
---|
100 | $allowed_params=array('post_type','lang'); |
---|
101 | $params = jsonRestServer::getFilteredParams($allowed_params,$get); |
---|
102 | |
---|
103 | $rs = $core->blog->getLangs($params); |
---|
104 | $rsp = array(); |
---|
105 | while ($rs->fetch()) |
---|
106 | { |
---|
107 | $lang=array(); |
---|
108 | $lang['lang'] = $rs->post_lang; |
---|
109 | $lang['nb_post'] = (int)$rs->nb_post; |
---|
110 | $rsp[]=$lang; |
---|
111 | } |
---|
112 | return $rsp; |
---|
113 | } |
---|
114 | |
---|
115 | public static function getDates($core,$get) |
---|
116 | { |
---|
117 | $allowed_params=array('post_type','year','month','day','cat_id','cat_url', |
---|
118 | 'post_lang','next','previous','order'); |
---|
119 | $params = jsonRestServer::getFilteredParams($allowed_params,$get); |
---|
120 | if (!isset($params['post_type'])) |
---|
121 | $params['post_type']='post'; |
---|
122 | |
---|
123 | $rs = $core->blog->getDates($params); |
---|
124 | $rsp = array(); |
---|
125 | while ($rs->fetch()) |
---|
126 | { |
---|
127 | $date=array(); |
---|
128 | $date['date'] = $rs->dt; |
---|
129 | $date['nb_post'] = (int)$rs->nb_post; |
---|
130 | $rsp[]=$date; |
---|
131 | } |
---|
132 | return $rsp; |
---|
133 | } |
---|
134 | |
---|
135 | public static function getPostsUsers($core,$get) |
---|
136 | { |
---|
137 | $post_type = isset($get['post_type'])?$get['post_type']:null; |
---|
138 | |
---|
139 | $rs = $core->blog->getPostsUsers($post_type); |
---|
140 | $rsp = array(); |
---|
141 | while ($rs->fetch()) |
---|
142 | { |
---|
143 | $user=array(); |
---|
144 | $user['id'] = $rs->user_id; |
---|
145 | $user['name'] = $rs->user_name; |
---|
146 | $user['displayname'] = $rs->user_displayname; |
---|
147 | $rsp[]=$user; |
---|
148 | } |
---|
149 | return $rsp; |
---|
150 | } |
---|
151 | |
---|
152 | public static function getComments($core,$get) |
---|
153 | { |
---|
154 | $allowed_params=array('post_type','post_id','cat_id','comment_id', |
---|
155 | 'comment_trackback','post_url','user_id','q_author','order', |
---|
156 | 'limit'); |
---|
157 | $no_content=isset($get['no_content']); |
---|
158 | $count_only = isset($get['count_only']); |
---|
159 | |
---|
160 | |
---|
161 | $params = jsonRestServer::getFilteredParams($allowed_params,$get); |
---|
162 | if (!isset($params['post_type'])) |
---|
163 | $params['post_type']='post'; |
---|
164 | |
---|
165 | if ($no_content) |
---|
166 | $params['no_content']=1; |
---|
167 | |
---|
168 | |
---|
169 | $rs = $core->blog->getComments($params,$count_only); |
---|
170 | if ($count_only) |
---|
171 | return (int)$rs->f(0); |
---|
172 | $rsp = array(); |
---|
173 | while ($rs->fetch()) |
---|
174 | { |
---|
175 | $comment=array(); |
---|
176 | $comment['id'] = $rs->comment_id; |
---|
177 | if (!$no_content) { |
---|
178 | $comment['content'] = $rs->comment_content; |
---|
179 | } |
---|
180 | $comment['date'] = $rs->comment_dt; |
---|
181 | $comment['upddt'] = $rs->comment_upddt; |
---|
182 | $comment['author'] = $rs->comment_author; |
---|
183 | $comment['site'] = $rs->comment_site; |
---|
184 | $comment['post_title'] = $rs->post_title; |
---|
185 | $comment['post_title'] = $rs->post_title; |
---|
186 | $comment['post_title'] = $rs->post_title; |
---|
187 | $comment['post_title'] = $rs->post_title; |
---|
188 | $comment['post_title'] = $rs->post_title; |
---|
189 | $comment['upddt'] = $rs->comment_upddt; |
---|
190 | $comment['upddt'] = $rs->comment_upddt; |
---|
191 | $comment['upddt'] = $rs->comment_upddt; |
---|
192 | |
---|
193 | $comment['user'] = $rs->user_id; |
---|
194 | $comment['url'] = $rs->comment_url; |
---|
195 | $comment['selected'] = ($rs->comment_selected == 1); |
---|
196 | $comment['nb_comments'] = (int)$rs->nb_comment; |
---|
197 | $comment['nb_trackbacks'] = (int)$rs->nb_trackback; |
---|
198 | $comment['category'] = (int)$rs->cat_id; |
---|
199 | |
---|
200 | $rsp[]=$comment; |
---|
201 | } |
---|
202 | return $rsp; |
---|
203 | } |
---|
204 | |
---|
205 | } |
---|
206 | ?> |
---|