1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
3 | # |
---|
4 | # This file is part of Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
12 | |
---|
13 | #if (isset($_GET['dcxd'])) { |
---|
14 | # $_COOKIE['dcxd'] = $_GET['dcxd']; |
---|
15 | #} |
---|
16 | |
---|
17 | require dirname(__FILE__).'/../inc/admin/prepend.php'; |
---|
18 | |
---|
19 | $core->rest->addFunction('checkNewsUpdate',array('dcRestMethods','checkNewsUpdate')); |
---|
20 | $core->rest->addFunction('checkCoreUpdate',array('dcRestMethods','checkCoreUpdate')); |
---|
21 | $core->rest->addFunction('getPostById',array('dcRestMethods','getPostById')); |
---|
22 | $core->rest->addFunction('getCommentById',array('dcRestMethods','getCommentById')); |
---|
23 | $core->rest->addFunction('quickPost',array('dcRestMethods','quickPost')); |
---|
24 | $core->rest->addFunction('validatePostMarkup',array('dcRestMethods','validatePostMarkup')); |
---|
25 | $core->rest->addFunction('getZipMediaContent',array('dcRestMethods','getZipMediaContent')); |
---|
26 | $core->rest->addFunction('getMeta',array('dcRestMethods','getMeta')); |
---|
27 | $core->rest->addFunction('delMeta',array('dcRestMethods','delMeta')); |
---|
28 | $core->rest->addFunction('setPostMeta',array('dcRestMethods','setPostMeta')); |
---|
29 | $core->rest->addFunction('searchMeta',array('dcRestMethods','searchMeta')); |
---|
30 | $core->rest->addFunction('setSectionFold',array('dcRestMethods','setSectionFold')); |
---|
31 | $core->rest->addFunction('getModuleById',array('dcRestMethods','getModuleById')); |
---|
32 | |
---|
33 | $core->rest->serve(); |
---|
34 | |
---|
35 | /* Common REST methods */ |
---|
36 | class dcRestMethods |
---|
37 | { |
---|
38 | public static function checkNewsUpdate($core,$get) |
---|
39 | { |
---|
40 | # Dotclear news |
---|
41 | |
---|
42 | $rsp = new xmlTag('news'); |
---|
43 | $rsp->check = false; |
---|
44 | $ret = __('Dotclear news not available'); |
---|
45 | |
---|
46 | if ($core->auth->user_prefs->dashboard->dcnews) { |
---|
47 | try |
---|
48 | { |
---|
49 | |
---|
50 | if (empty($GLOBALS['__resources']['rss_news'])) { |
---|
51 | throw new Exception(); |
---|
52 | } |
---|
53 | $feed_reader = new feedReader; |
---|
54 | $feed_reader->setCacheDir(DC_TPL_CACHE); |
---|
55 | $feed_reader->setTimeout(2); |
---|
56 | $feed_reader->setUserAgent('Dotclear - http://www.dotclear.org/'); |
---|
57 | $feed = $feed_reader->parse($GLOBALS['__resources']['rss_news']); |
---|
58 | if ($feed) |
---|
59 | { |
---|
60 | $ret = '<div class="box medium dc-box"><h3>'.__('Dotclear news').'</h3><dl id="news">'; |
---|
61 | $i = 1; |
---|
62 | foreach ($feed->items as $item) |
---|
63 | { |
---|
64 | $dt = isset($item->link) ? '<a href="'.$item->link.'" class="outgoing" title="'.$item->title.'">'. |
---|
65 | $item->title.' <img src="images/outgoing-blue.png" alt="" /></a>' : $item->title; |
---|
66 | |
---|
67 | if ($i < 3) { |
---|
68 | $ret .= |
---|
69 | '<dt>'.$dt.'</dt>'. |
---|
70 | '<dd><p><strong>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</strong> '. |
---|
71 | '<em>'.text::cutString(html::clean($item->content),120).'...</em></p></dd>'; |
---|
72 | } else { |
---|
73 | $ret .= |
---|
74 | '<dt>'.$dt.'</dt>'. |
---|
75 | '<dd>'.dt::dt2str(__('%d %B %Y:'),$item->pubdate,'Europe/Paris').'</dd>'; |
---|
76 | } |
---|
77 | $i++; |
---|
78 | if ($i > 2) { break; } |
---|
79 | } |
---|
80 | $ret .= '</dl></div>'; |
---|
81 | $rsp->check = true; |
---|
82 | } |
---|
83 | } |
---|
84 | catch (Exception $e) {} |
---|
85 | } |
---|
86 | $rsp->ret = $ret; |
---|
87 | return $rsp; |
---|
88 | } |
---|
89 | |
---|
90 | public static function checkCoreUpdate($core,$get) |
---|
91 | { |
---|
92 | # Dotclear updates notifications |
---|
93 | |
---|
94 | $rsp = new xmlTag('update'); |
---|
95 | $rsp->check = false; |
---|
96 | $ret = __('Dotclear update not available'); |
---|
97 | |
---|
98 | if ($core->auth->isSuperAdmin() && !DC_NOT_UPDATE && is_readable(DC_DIGESTS) && |
---|
99 | !$core->auth->user_prefs->dashboard->nodcupdate) |
---|
100 | { |
---|
101 | $updater = new dcUpdate(DC_UPDATE_URL,'dotclear',DC_UPDATE_VERSION,DC_TPL_CACHE.'/versions'); |
---|
102 | $new_v = $updater->check(DC_VERSION); |
---|
103 | $version_info = $new_v ? $updater->getInfoURL() : ''; |
---|
104 | |
---|
105 | if ($updater->getNotify() && $new_v) { |
---|
106 | // Check PHP version required |
---|
107 | if (version_compare(phpversion(),$updater->getPHPVersion()) >= 0) { |
---|
108 | $ret = |
---|
109 | '<div class="dc-update"><h3>'.sprintf(__('Dotclear %s is available!'),$new_v).'</h3> '. |
---|
110 | '<p><a class="button submit" href="'.$core->adminurl->get("admin.update").'">'.sprintf(__('Upgrade now'),$new_v).'</a> '. |
---|
111 | '<a class="button" href="'.$core->adminurl->get("admin.update", array('hide_msg' => 1)).'">'.__('Remind me later').'</a>'. |
---|
112 | ($version_info ? ' </p>'. |
---|
113 | '<p class="updt-info"><a href="'.$version_info.'">'.__('Information about this version').'</a>' : '').'</p>'. |
---|
114 | '</div>'; |
---|
115 | } else { |
---|
116 | $ret = '<p class="info">'. |
---|
117 | sprintf(__('A new version of Dotclear is available but needs PHP version ≥ %s, your\'s is currently %s'), |
---|
118 | $updater->getPHPVersion(),phpversion()). |
---|
119 | '</p>'; |
---|
120 | } |
---|
121 | $rsp->check = true; |
---|
122 | } else { |
---|
123 | if (version_compare(phpversion(),DC_NEXT_REQUIRED_PHP,'<')) { |
---|
124 | $ret = '<p class="info">'. |
---|
125 | sprintf(__('The next versions of Dotclear will not support PHP version < %s, your\'s is currently %s'), |
---|
126 | DC_NEXT_REQUIRED_PHP,phpversion()). |
---|
127 | '</p>'; |
---|
128 | $rsp->check = true; |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | $rsp->ret = $ret; |
---|
133 | return $rsp; |
---|
134 | } |
---|
135 | |
---|
136 | public static function getPostById($core,$get) |
---|
137 | { |
---|
138 | if (empty($get['id'])) { |
---|
139 | throw new Exception('No post ID'); |
---|
140 | } |
---|
141 | |
---|
142 | $params = array('post_id' => (integer) $get['id']); |
---|
143 | |
---|
144 | if (isset($get['post_type'])) { |
---|
145 | $params['post_type'] = $get['post_type']; |
---|
146 | } |
---|
147 | |
---|
148 | $rs = $core->blog->getPosts($params); |
---|
149 | |
---|
150 | if ($rs->isEmpty()) { |
---|
151 | throw new Exception('No post for this ID'); |
---|
152 | } |
---|
153 | |
---|
154 | $rsp = new xmlTag('post'); |
---|
155 | $rsp->id = $rs->post_id; |
---|
156 | |
---|
157 | $rsp->blog_id($rs->blog_id); |
---|
158 | $rsp->user_id($rs->user_id); |
---|
159 | $rsp->cat_id($rs->cat_id); |
---|
160 | $rsp->post_dt($rs->post_dt); |
---|
161 | $rsp->post_creadt($rs->post_creadt); |
---|
162 | $rsp->post_upddt($rs->post_upddt); |
---|
163 | $rsp->post_format($rs->post_format); |
---|
164 | $rsp->post_url($rs->post_url); |
---|
165 | $rsp->post_lang($rs->post_lang); |
---|
166 | $rsp->post_title($rs->post_title); |
---|
167 | $rsp->post_excerpt($rs->post_excerpt); |
---|
168 | $rsp->post_excerpt_xhtml($rs->post_excerpt_xhtml); |
---|
169 | $rsp->post_content($rs->post_content); |
---|
170 | $rsp->post_content_xhtml($rs->post_content_xhtml); |
---|
171 | $rsp->post_notes($rs->post_notes); |
---|
172 | $rsp->post_status($rs->post_status); |
---|
173 | $rsp->post_selected($rs->post_selected); |
---|
174 | $rsp->post_open_comment($rs->post_open_comment); |
---|
175 | $rsp->post_open_tb($rs->post_open_tb); |
---|
176 | $rsp->nb_comment($rs->nb_comment); |
---|
177 | $rsp->nb_trackback($rs->nb_trackback); |
---|
178 | $rsp->user_name($rs->user_name); |
---|
179 | $rsp->user_firstname($rs->user_firstname); |
---|
180 | $rsp->user_displayname($rs->user_displayname); |
---|
181 | $rsp->user_email($rs->user_email); |
---|
182 | $rsp->user_url($rs->user_url); |
---|
183 | $rsp->cat_title($rs->cat_title); |
---|
184 | $rsp->cat_url($rs->cat_url); |
---|
185 | |
---|
186 | $rsp->post_display_content($rs->getContent(true)); |
---|
187 | $rsp->post_display_excerpt($rs->getExcerpt(true)); |
---|
188 | |
---|
189 | $metaTag = new xmlTag('meta'); |
---|
190 | if (($meta = @unserialize($rs->post_meta)) !== false) |
---|
191 | { |
---|
192 | foreach ($meta as $K => $V) |
---|
193 | { |
---|
194 | foreach ($V as $v) { |
---|
195 | $metaTag->$K($v); |
---|
196 | } |
---|
197 | } |
---|
198 | } |
---|
199 | $rsp->post_meta($metaTag); |
---|
200 | |
---|
201 | return $rsp; |
---|
202 | } |
---|
203 | |
---|
204 | public static function getCommentById($core,$get) |
---|
205 | { |
---|
206 | if (empty($get['id'])) { |
---|
207 | throw new Exception('No comment ID'); |
---|
208 | } |
---|
209 | |
---|
210 | $rs = $core->blog->getComments(array('comment_id' => (integer) $get['id'])); |
---|
211 | |
---|
212 | if ($rs->isEmpty()) { |
---|
213 | throw new Exception('No comment for this ID'); |
---|
214 | } |
---|
215 | |
---|
216 | $rsp = new xmlTag('post'); |
---|
217 | $rsp->id = $rs->comment_id; |
---|
218 | |
---|
219 | $rsp->comment_dt($rs->comment_dt); |
---|
220 | $rsp->comment_upddt($rs->comment_upddt); |
---|
221 | $rsp->comment_author($rs->comment_author); |
---|
222 | $rsp->comment_site($rs->comment_site); |
---|
223 | $rsp->comment_content($rs->comment_content); |
---|
224 | $rsp->comment_trackback($rs->comment_trackback); |
---|
225 | $rsp->comment_status($rs->comment_status); |
---|
226 | $rsp->post_title($rs->post_title); |
---|
227 | $rsp->post_url($rs->post_url); |
---|
228 | $rsp->post_id($rs->post_id); |
---|
229 | $rsp->post_dt($rs->post_dt); |
---|
230 | $rsp->user_id($rs->user_id); |
---|
231 | |
---|
232 | $rsp->comment_display_content($rs->getContent(true)); |
---|
233 | |
---|
234 | if ($core->auth->userID()) { |
---|
235 | $rsp->comment_ip($rs->comment_ip); |
---|
236 | $rsp->comment_email($rs->comment_email); |
---|
237 | $rsp->comment_spam_disp(dcAntispam::statusMessage($rs)); |
---|
238 | } |
---|
239 | |
---|
240 | return $rsp; |
---|
241 | } |
---|
242 | |
---|
243 | public static function quickPost($core,$get,$post) |
---|
244 | { |
---|
245 | # Create category |
---|
246 | if (!empty($post['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) { |
---|
247 | |
---|
248 | $cur_cat = $core->con->openCursor($core->prefix.'category'); |
---|
249 | $cur_cat->cat_title = $post['new_cat_title']; |
---|
250 | $cur_cat->cat_url = ''; |
---|
251 | |
---|
252 | $parent_cat = !empty($post['new_cat_parent']) ? $post['new_cat_parent'] : ''; |
---|
253 | |
---|
254 | # --BEHAVIOR-- adminBeforeCategoryCreate |
---|
255 | $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); |
---|
256 | |
---|
257 | $post['cat_id'] = $core->blog->addCategory($cur_cat, (integer) $parent_cat); |
---|
258 | |
---|
259 | # --BEHAVIOR-- adminAfterCategoryCreate |
---|
260 | $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $post['cat_id']); |
---|
261 | } |
---|
262 | |
---|
263 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
264 | |
---|
265 | $cur->post_title = !empty($post['post_title']) ? $post['post_title'] : ''; |
---|
266 | $cur->user_id = $core->auth->userID(); |
---|
267 | $cur->post_content = !empty($post['post_content']) ? $post['post_content'] : ''; |
---|
268 | $cur->cat_id = !empty($post['cat_id']) ? (integer) $post['cat_id'] : null; |
---|
269 | $cur->post_format = !empty($post['post_format']) ? $post['post_format'] : 'xhtml'; |
---|
270 | $cur->post_lang = !empty($post['post_lang']) ? $post['post_lang'] : ''; |
---|
271 | $cur->post_status = !empty($post['post_status']) ? (integer) $post['post_status'] : 0; |
---|
272 | $cur->post_open_comment = (integer) $core->blog->settings->system->allow_comments; |
---|
273 | $cur->post_open_tb = (integer) $core->blog->settings->system->allow_trackbacks; |
---|
274 | |
---|
275 | # --BEHAVIOR-- adminBeforePostCreate |
---|
276 | $core->callBehavior('adminBeforePostCreate',$cur); |
---|
277 | |
---|
278 | $return_id = $core->blog->addPost($cur); |
---|
279 | |
---|
280 | # --BEHAVIOR-- adminAfterPostCreate |
---|
281 | $core->callBehavior('adminAfterPostCreate',$cur,$return_id); |
---|
282 | |
---|
283 | $rsp = new xmlTag('post'); |
---|
284 | $rsp->id = $return_id; |
---|
285 | |
---|
286 | $post = $core->blog->getPosts(array('post_id' => $return_id)); |
---|
287 | |
---|
288 | $rsp->post_status = $post->post_status; |
---|
289 | $rsp->post_url = $post->getURL(); |
---|
290 | return $rsp; |
---|
291 | } |
---|
292 | |
---|
293 | public static function validatePostMarkup($core,$get,$post) |
---|
294 | { |
---|
295 | if (!isset($post['excerpt'])) { |
---|
296 | throw new Exception('No entry excerpt'); |
---|
297 | } |
---|
298 | |
---|
299 | if (!isset($post['content'])) { |
---|
300 | throw new Exception('No entry content'); |
---|
301 | } |
---|
302 | |
---|
303 | if (empty($post['format'])) { |
---|
304 | throw new Exception('No entry format'); |
---|
305 | } |
---|
306 | |
---|
307 | if (!isset($post['lang'])) { |
---|
308 | throw new Exception('No entry lang'); |
---|
309 | } |
---|
310 | |
---|
311 | $excerpt = $post['excerpt']; |
---|
312 | $excerpt_xhtml = ''; |
---|
313 | $content = $post['content']; |
---|
314 | $content_xhtml = ''; |
---|
315 | $format = $post['format']; |
---|
316 | $lang = $post['lang']; |
---|
317 | |
---|
318 | $core->blog->setPostContent(0,$format,$lang,$excerpt,$excerpt_xhtml,$content,$content_xhtml); |
---|
319 | |
---|
320 | $rsp = new xmlTag('result'); |
---|
321 | |
---|
322 | $v = htmlValidator::validate($excerpt_xhtml.$content_xhtml); |
---|
323 | |
---|
324 | $rsp->valid($v['valid']); |
---|
325 | $rsp->errors($v['errors']); |
---|
326 | |
---|
327 | return $rsp; |
---|
328 | } |
---|
329 | |
---|
330 | public static function getZipMediaContent($core,$get,$post) |
---|
331 | { |
---|
332 | if (empty($get['id'])) { |
---|
333 | throw new Exception('No media ID'); |
---|
334 | } |
---|
335 | |
---|
336 | $id = (integer) $get['id']; |
---|
337 | |
---|
338 | if (!$core->auth->check('media,media_admin',$core->blog)) { |
---|
339 | throw new Exception('Permission denied'); |
---|
340 | } |
---|
341 | |
---|
342 | try { |
---|
343 | $core->media = new dcMedia($core); |
---|
344 | $file = $core->media->getFile($id); |
---|
345 | } catch (Exception $e) {} |
---|
346 | |
---|
347 | if ($file === null || $file->type != 'application/zip' || !$file->editable) { |
---|
348 | throw new Exception('Not a valid file'); |
---|
349 | } |
---|
350 | |
---|
351 | $rsp = new xmlTag('result'); |
---|
352 | $content = $core->media->getZipContent($file); |
---|
353 | |
---|
354 | foreach ($content as $k => $v) { |
---|
355 | $rsp->file($k); |
---|
356 | } |
---|
357 | |
---|
358 | return $rsp; |
---|
359 | } |
---|
360 | |
---|
361 | public static function getMeta($core,$get) |
---|
362 | { |
---|
363 | $postid = !empty($get['postId']) ? $get['postId'] : null; |
---|
364 | $limit = !empty($get['limit']) ? $get['limit'] : null; |
---|
365 | $metaId = !empty($get['metaId']) ? $get['metaId'] : null; |
---|
366 | $metaType = !empty($get['metaType']) ? $get['metaType'] : null; |
---|
367 | |
---|
368 | $sortby = !empty($get['sortby']) ? $get['sortby'] : 'meta_type,asc'; |
---|
369 | |
---|
370 | $rs = $core->meta->getMetadata(array( |
---|
371 | 'meta_type' => $metaType, |
---|
372 | 'limit' => $limit, |
---|
373 | 'meta_id' => $metaId, |
---|
374 | 'post_id' => $postid)); |
---|
375 | $rs = $core->meta->computeMetaStats($rs); |
---|
376 | |
---|
377 | $sortby = explode(',',$sortby); |
---|
378 | $sort = $sortby[0]; |
---|
379 | $order = isset($sortby[1]) ? $sortby[1] : 'asc'; |
---|
380 | |
---|
381 | switch ($sort) { |
---|
382 | case 'metaId': |
---|
383 | $sort = 'meta_id_lower'; |
---|
384 | break; |
---|
385 | case 'count': |
---|
386 | $sort = 'count'; |
---|
387 | break; |
---|
388 | case 'metaType': |
---|
389 | $sort = 'meta_type'; |
---|
390 | break; |
---|
391 | default: |
---|
392 | $sort = 'meta_type'; |
---|
393 | } |
---|
394 | |
---|
395 | $rs->sort($sort,$order); |
---|
396 | |
---|
397 | $rsp = new xmlTag(); |
---|
398 | |
---|
399 | while ($rs->fetch()) |
---|
400 | { |
---|
401 | $metaTag = new xmlTag('meta'); |
---|
402 | $metaTag->type = $rs->meta_type; |
---|
403 | $metaTag->uri = rawurlencode($rs->meta_id); |
---|
404 | $metaTag->count = $rs->count; |
---|
405 | $metaTag->percent = $rs->percent; |
---|
406 | $metaTag->roundpercent = $rs->roundpercent; |
---|
407 | $metaTag->CDATA($rs->meta_id); |
---|
408 | |
---|
409 | $rsp->insertNode($metaTag); |
---|
410 | } |
---|
411 | |
---|
412 | return $rsp; |
---|
413 | } |
---|
414 | |
---|
415 | public static function setPostMeta($core,$get,$post) |
---|
416 | { |
---|
417 | if (empty($post['postId'])) { |
---|
418 | throw new Exception('No post ID'); |
---|
419 | } |
---|
420 | |
---|
421 | if (empty($post['meta']) && $post['meta'] != '0') { |
---|
422 | throw new Exception('No meta'); |
---|
423 | } |
---|
424 | |
---|
425 | if (empty($post['metaType'])) { |
---|
426 | throw new Exception('No meta type'); |
---|
427 | } |
---|
428 | |
---|
429 | # Get previous meta for post |
---|
430 | $post_meta = $core->meta->getMetadata(array( |
---|
431 | 'meta_type' => $post['metaType'], |
---|
432 | 'post_id' => $post['postId'])); |
---|
433 | $pm = array(); |
---|
434 | while ($post_meta->fetch()) { |
---|
435 | $pm[] = $post_meta->meta_id; |
---|
436 | } |
---|
437 | |
---|
438 | foreach ($core->meta->splitMetaValues($post['meta']) as $m) |
---|
439 | { |
---|
440 | if (!in_array($m,$pm)) { |
---|
441 | $core->meta->setPostMeta($post['postId'],$post['metaType'],$m); |
---|
442 | } |
---|
443 | } |
---|
444 | |
---|
445 | return true; |
---|
446 | } |
---|
447 | |
---|
448 | public static function delMeta($core,$get,$post) |
---|
449 | { |
---|
450 | if (empty($post['postId'])) { |
---|
451 | throw new Exception('No post ID'); |
---|
452 | } |
---|
453 | |
---|
454 | if (empty($post['metaId']) && $post['metaId'] != '0') { |
---|
455 | throw new Exception('No meta ID'); |
---|
456 | } |
---|
457 | |
---|
458 | if (empty($post['metaType'])) { |
---|
459 | throw new Exception('No meta type'); |
---|
460 | } |
---|
461 | |
---|
462 | $core->meta->delPostMeta($post['postId'],$post['metaType'],$post['metaId']); |
---|
463 | |
---|
464 | return true; |
---|
465 | } |
---|
466 | |
---|
467 | public static function searchMeta($core,$get) |
---|
468 | { |
---|
469 | $q = !empty($get['q']) ? $get['q'] : null; |
---|
470 | $metaType = !empty($get['metaType']) ? $get['metaType'] : null; |
---|
471 | |
---|
472 | $sortby = !empty($get['sortby']) ? $get['sortby'] : 'meta_type,asc'; |
---|
473 | |
---|
474 | $rs = $core->meta->getMetadata(array('meta_type' => $metaType)); |
---|
475 | $rs = $core->meta->computeMetaStats($rs); |
---|
476 | |
---|
477 | $sortby = explode(',',$sortby); |
---|
478 | $sort = $sortby[0]; |
---|
479 | $order = isset($sortby[1]) ? $sortby[1] : 'asc'; |
---|
480 | |
---|
481 | switch ($sort) { |
---|
482 | case 'metaId': |
---|
483 | $sort = 'meta_id_lower'; |
---|
484 | break; |
---|
485 | case 'count': |
---|
486 | $sort = 'count'; |
---|
487 | break; |
---|
488 | case 'metaType': |
---|
489 | $sort = 'meta_type'; |
---|
490 | break; |
---|
491 | default: |
---|
492 | $sort = 'meta_type'; |
---|
493 | } |
---|
494 | |
---|
495 | $rs->sort($sort,$order); |
---|
496 | |
---|
497 | $rsp = new xmlTag(); |
---|
498 | |
---|
499 | while ($rs->fetch()) |
---|
500 | { |
---|
501 | if (stripos($rs->meta_id,$q) === 0) { |
---|
502 | $metaTag = new xmlTag('meta'); |
---|
503 | $metaTag->type = $rs->meta_type; |
---|
504 | $metaTag->uri = rawurlencode($rs->meta_id); |
---|
505 | $metaTag->count = $rs->count; |
---|
506 | $metaTag->percent = $rs->percent; |
---|
507 | $metaTag->roundpercent = $rs->roundpercent; |
---|
508 | $metaTag->CDATA($rs->meta_id); |
---|
509 | |
---|
510 | $rsp->insertNode($metaTag); |
---|
511 | } |
---|
512 | } |
---|
513 | |
---|
514 | return $rsp; |
---|
515 | } |
---|
516 | |
---|
517 | public static function setSectionFold($core,$get,$post) |
---|
518 | { |
---|
519 | if (empty($post['section'])) { |
---|
520 | throw new Exception('No section name'); |
---|
521 | } |
---|
522 | if ($core->auth->user_prefs->toggles === null) { |
---|
523 | $core->auth->user_prefs->addWorkspace('toggles'); |
---|
524 | } |
---|
525 | $section = $post['section']; |
---|
526 | $status = isset($post['value']) && ($post['value'] != 0); |
---|
527 | if ($core->auth->user_prefs->toggles->prefExists('unfolded_sections')) { |
---|
528 | $toggles = explode(',',trim($core->auth->user_prefs->toggles->unfolded_sections)); |
---|
529 | } else { |
---|
530 | $toggles = array(); |
---|
531 | } |
---|
532 | $k = array_search($section,$toggles); |
---|
533 | if ($status) { // true == Fold section ==> remove it from unfolded list |
---|
534 | if ($k !== false) { |
---|
535 | unset($toggles[$k]); |
---|
536 | } |
---|
537 | } else { // false == unfold section ==> add it to unfolded list |
---|
538 | if ($k === false) { |
---|
539 | $toggles[]=$section; |
---|
540 | }; |
---|
541 | } |
---|
542 | $core->auth->user_prefs->toggles->put('unfolded_sections',join(',',$toggles)); |
---|
543 | return true; |
---|
544 | } |
---|
545 | |
---|
546 | public static function getModuleById($core, $get, $post) |
---|
547 | { |
---|
548 | if (empty($get['id'])) { |
---|
549 | throw new Exception('No module ID'); |
---|
550 | } |
---|
551 | if (empty($get['list'])) { |
---|
552 | throw new Exception('No list ID'); |
---|
553 | } |
---|
554 | |
---|
555 | $id = $get['id']; |
---|
556 | $list = $get['list']; |
---|
557 | $module = array(); |
---|
558 | |
---|
559 | if ($list == 'plugin-activate') { |
---|
560 | $modules = $core->plugins->getModules(); |
---|
561 | if (empty($modules) || !isset($modules[$id])) { |
---|
562 | throw new Exception('Unknow module ID'); |
---|
563 | } |
---|
564 | $module = $modules[$id]; |
---|
565 | } |
---|
566 | elseif ($list == 'plugin-new') { |
---|
567 | $store = new dcStore( |
---|
568 | $core->plugins, |
---|
569 | $core->blog->settings->system->store_plugin_url |
---|
570 | ); |
---|
571 | $store->check(); |
---|
572 | |
---|
573 | $modules = $store->get(); |
---|
574 | if (empty($modules) || !isset($modules[$id])) { |
---|
575 | throw new Exception('Unknow module ID'); |
---|
576 | } |
---|
577 | $module = $modules[$id]; |
---|
578 | } |
---|
579 | else { |
---|
580 | // behavior not implemented yet |
---|
581 | } |
---|
582 | |
---|
583 | if (empty($module)) { |
---|
584 | throw new Exception('Unknow module ID'); |
---|
585 | } |
---|
586 | |
---|
587 | $module = adminModulesList::sanitizeModule($id, $module); |
---|
588 | |
---|
589 | $rsp = new xmlTag('module'); |
---|
590 | $rsp->id = $id; |
---|
591 | |
---|
592 | foreach($module as $k => $v) { |
---|
593 | $rsp->{$k}((string) $v); |
---|
594 | } |
---|
595 | |
---|
596 | return $rsp; |
---|
597 | } |
---|
598 | } |
---|