[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 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 | |
---|
[3614] | 19 | $core->rest->addFunction('checkNewsUpdate',array('dcRestMethods','checkNewsUpdate')); |
---|
[3613] | 20 | $core->rest->addFunction('checkCoreUpdate',array('dcRestMethods','checkCoreUpdate')); |
---|
[0] | 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')); |
---|
[1699] | 30 | $core->rest->addFunction('setSectionFold',array('dcRestMethods','setSectionFold')); |
---|
[2156] | 31 | $core->rest->addFunction('getModuleById',array('dcRestMethods','getModuleById')); |
---|
[0] | 32 | |
---|
| 33 | $core->rest->serve(); |
---|
| 34 | |
---|
| 35 | /* Common REST methods */ |
---|
| 36 | class dcRestMethods |
---|
| 37 | { |
---|
[3614] | 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 | |
---|
[3613] | 90 | public static function checkCoreUpdate($core,$get) |
---|
| 91 | { |
---|
| 92 | # Dotclear updates notifications |
---|
| 93 | |
---|
| 94 | $rsp = new xmlTag('update'); |
---|
| 95 | $rsp->check = false; |
---|
[3614] | 96 | $ret = __('Dotclear update not available'); |
---|
[3613] | 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 | |
---|
[0] | 136 | public static function getPostById($core,$get) |
---|
| 137 | { |
---|
| 138 | if (empty($get['id'])) { |
---|
| 139 | throw new Exception('No post ID'); |
---|
| 140 | } |
---|
[2566] | 141 | |
---|
[0] | 142 | $params = array('post_id' => (integer) $get['id']); |
---|
[2566] | 143 | |
---|
[0] | 144 | if (isset($get['post_type'])) { |
---|
| 145 | $params['post_type'] = $get['post_type']; |
---|
| 146 | } |
---|
[2566] | 147 | |
---|
[0] | 148 | $rs = $core->blog->getPosts($params); |
---|
[2566] | 149 | |
---|
[0] | 150 | if ($rs->isEmpty()) { |
---|
| 151 | throw new Exception('No post for this ID'); |
---|
| 152 | } |
---|
[2566] | 153 | |
---|
[0] | 154 | $rsp = new xmlTag('post'); |
---|
| 155 | $rsp->id = $rs->post_id; |
---|
[2566] | 156 | |
---|
[0] | 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); |
---|
[2566] | 185 | |
---|
[0] | 186 | $rsp->post_display_content($rs->getContent(true)); |
---|
| 187 | $rsp->post_display_excerpt($rs->getExcerpt(true)); |
---|
[2566] | 188 | |
---|
[0] | 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); |
---|
[2566] | 200 | |
---|
[0] | 201 | return $rsp; |
---|
| 202 | } |
---|
[2566] | 203 | |
---|
[0] | 204 | public static function getCommentById($core,$get) |
---|
| 205 | { |
---|
| 206 | if (empty($get['id'])) { |
---|
| 207 | throw new Exception('No comment ID'); |
---|
| 208 | } |
---|
[2566] | 209 | |
---|
[0] | 210 | $rs = $core->blog->getComments(array('comment_id' => (integer) $get['id'])); |
---|
[2566] | 211 | |
---|
[0] | 212 | if ($rs->isEmpty()) { |
---|
| 213 | throw new Exception('No comment for this ID'); |
---|
| 214 | } |
---|
[2566] | 215 | |
---|
[0] | 216 | $rsp = new xmlTag('post'); |
---|
| 217 | $rsp->id = $rs->comment_id; |
---|
[2566] | 218 | |
---|
[0] | 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); |
---|
[2566] | 231 | |
---|
[0] | 232 | $rsp->comment_display_content($rs->getContent(true)); |
---|
[2566] | 233 | |
---|
[0] | 234 | if ($core->auth->userID()) { |
---|
| 235 | $rsp->comment_ip($rs->comment_ip); |
---|
| 236 | $rsp->comment_email($rs->comment_email); |
---|
[323] | 237 | $rsp->comment_spam_disp(dcAntispam::statusMessage($rs)); |
---|
[0] | 238 | } |
---|
[2566] | 239 | |
---|
[0] | 240 | return $rsp; |
---|
| 241 | } |
---|
[2566] | 242 | |
---|
[0] | 243 | public static function quickPost($core,$get,$post) |
---|
| 244 | { |
---|
[1500] | 245 | # Create category |
---|
| 246 | if (!empty($post['new_cat_title']) && $core->auth->check('categories', $core->blog->id)) { |
---|
[2566] | 247 | |
---|
[1500] | 248 | $cur_cat = $core->con->openCursor($core->prefix.'category'); |
---|
| 249 | $cur_cat->cat_title = $post['new_cat_title']; |
---|
| 250 | $cur_cat->cat_url = ''; |
---|
[2566] | 251 | |
---|
[1500] | 252 | $parent_cat = !empty($post['new_cat_parent']) ? $post['new_cat_parent'] : ''; |
---|
[2566] | 253 | |
---|
[1500] | 254 | # --BEHAVIOR-- adminBeforeCategoryCreate |
---|
| 255 | $core->callBehavior('adminBeforeCategoryCreate', $cur_cat); |
---|
[2566] | 256 | |
---|
[1500] | 257 | $post['cat_id'] = $core->blog->addCategory($cur_cat, (integer) $parent_cat); |
---|
[2566] | 258 | |
---|
[1500] | 259 | # --BEHAVIOR-- adminAfterCategoryCreate |
---|
| 260 | $core->callBehavior('adminAfterCategoryCreate', $cur_cat, $post['cat_id']); |
---|
| 261 | } |
---|
[2566] | 262 | |
---|
[0] | 263 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
[2566] | 264 | |
---|
[0] | 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; |
---|
[2566] | 274 | |
---|
[0] | 275 | # --BEHAVIOR-- adminBeforePostCreate |
---|
| 276 | $core->callBehavior('adminBeforePostCreate',$cur); |
---|
[2566] | 277 | |
---|
[0] | 278 | $return_id = $core->blog->addPost($cur); |
---|
[2566] | 279 | |
---|
[0] | 280 | # --BEHAVIOR-- adminAfterPostCreate |
---|
| 281 | $core->callBehavior('adminAfterPostCreate',$cur,$return_id); |
---|
[2566] | 282 | |
---|
[0] | 283 | $rsp = new xmlTag('post'); |
---|
| 284 | $rsp->id = $return_id; |
---|
[2566] | 285 | |
---|
[0] | 286 | $post = $core->blog->getPosts(array('post_id' => $return_id)); |
---|
[2566] | 287 | |
---|
[0] | 288 | $rsp->post_status = $post->post_status; |
---|
| 289 | $rsp->post_url = $post->getURL(); |
---|
| 290 | return $rsp; |
---|
| 291 | } |
---|
[2566] | 292 | |
---|
[0] | 293 | public static function validatePostMarkup($core,$get,$post) |
---|
| 294 | { |
---|
| 295 | if (!isset($post['excerpt'])) { |
---|
| 296 | throw new Exception('No entry excerpt'); |
---|
| 297 | } |
---|
[2566] | 298 | |
---|
[0] | 299 | if (!isset($post['content'])) { |
---|
| 300 | throw new Exception('No entry content'); |
---|
| 301 | } |
---|
[2566] | 302 | |
---|
[0] | 303 | if (empty($post['format'])) { |
---|
| 304 | throw new Exception('No entry format'); |
---|
| 305 | } |
---|
[2566] | 306 | |
---|
[0] | 307 | if (!isset($post['lang'])) { |
---|
| 308 | throw new Exception('No entry lang'); |
---|
| 309 | } |
---|
[2566] | 310 | |
---|
[0] | 311 | $excerpt = $post['excerpt']; |
---|
| 312 | $excerpt_xhtml = ''; |
---|
| 313 | $content = $post['content']; |
---|
| 314 | $content_xhtml = ''; |
---|
| 315 | $format = $post['format']; |
---|
| 316 | $lang = $post['lang']; |
---|
[2566] | 317 | |
---|
[0] | 318 | $core->blog->setPostContent(0,$format,$lang,$excerpt,$excerpt_xhtml,$content,$content_xhtml); |
---|
[2566] | 319 | |
---|
[0] | 320 | $rsp = new xmlTag('result'); |
---|
[2566] | 321 | |
---|
[0] | 322 | $v = htmlValidator::validate($excerpt_xhtml.$content_xhtml); |
---|
[2566] | 323 | |
---|
[0] | 324 | $rsp->valid($v['valid']); |
---|
| 325 | $rsp->errors($v['errors']); |
---|
[2566] | 326 | |
---|
[0] | 327 | return $rsp; |
---|
| 328 | } |
---|
[2566] | 329 | |
---|
[0] | 330 | public static function getZipMediaContent($core,$get,$post) |
---|
| 331 | { |
---|
| 332 | if (empty($get['id'])) { |
---|
| 333 | throw new Exception('No media ID'); |
---|
| 334 | } |
---|
[2566] | 335 | |
---|
[0] | 336 | $id = (integer) $get['id']; |
---|
[2566] | 337 | |
---|
[0] | 338 | if (!$core->auth->check('media,media_admin',$core->blog)) { |
---|
| 339 | throw new Exception('Permission denied'); |
---|
| 340 | } |
---|
[2566] | 341 | |
---|
[1537] | 342 | try { |
---|
| 343 | $core->media = new dcMedia($core); |
---|
| 344 | $file = $core->media->getFile($id); |
---|
| 345 | } catch (Exception $e) {} |
---|
[2566] | 346 | |
---|
[0] | 347 | if ($file === null || $file->type != 'application/zip' || !$file->editable) { |
---|
| 348 | throw new Exception('Not a valid file'); |
---|
| 349 | } |
---|
[2566] | 350 | |
---|
[0] | 351 | $rsp = new xmlTag('result'); |
---|
| 352 | $content = $core->media->getZipContent($file); |
---|
[2566] | 353 | |
---|
[0] | 354 | foreach ($content as $k => $v) { |
---|
| 355 | $rsp->file($k); |
---|
| 356 | } |
---|
[2566] | 357 | |
---|
[0] | 358 | return $rsp; |
---|
| 359 | } |
---|
[2566] | 360 | |
---|
[0] | 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; |
---|
[2566] | 367 | |
---|
[0] | 368 | $sortby = !empty($get['sortby']) ? $get['sortby'] : 'meta_type,asc'; |
---|
[2566] | 369 | |
---|
[0] | 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); |
---|
[2566] | 376 | |
---|
[0] | 377 | $sortby = explode(',',$sortby); |
---|
| 378 | $sort = $sortby[0]; |
---|
| 379 | $order = isset($sortby[1]) ? $sortby[1] : 'asc'; |
---|
[2566] | 380 | |
---|
[0] | 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 | } |
---|
[2566] | 394 | |
---|
[0] | 395 | $rs->sort($sort,$order); |
---|
[2566] | 396 | |
---|
[0] | 397 | $rsp = new xmlTag(); |
---|
[2566] | 398 | |
---|
[0] | 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); |
---|
[2566] | 408 | |
---|
[0] | 409 | $rsp->insertNode($metaTag); |
---|
| 410 | } |
---|
[2566] | 411 | |
---|
[0] | 412 | return $rsp; |
---|
| 413 | } |
---|
[2566] | 414 | |
---|
[0] | 415 | public static function setPostMeta($core,$get,$post) |
---|
| 416 | { |
---|
| 417 | if (empty($post['postId'])) { |
---|
| 418 | throw new Exception('No post ID'); |
---|
| 419 | } |
---|
[2566] | 420 | |
---|
[0] | 421 | if (empty($post['meta']) && $post['meta'] != '0') { |
---|
| 422 | throw new Exception('No meta'); |
---|
| 423 | } |
---|
[2566] | 424 | |
---|
[0] | 425 | if (empty($post['metaType'])) { |
---|
| 426 | throw new Exception('No meta type'); |
---|
| 427 | } |
---|
[2566] | 428 | |
---|
[0] | 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 | } |
---|
[2566] | 437 | |
---|
[0] | 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 | } |
---|
[2566] | 444 | |
---|
[0] | 445 | return true; |
---|
| 446 | } |
---|
[2566] | 447 | |
---|
[0] | 448 | public static function delMeta($core,$get,$post) |
---|
| 449 | { |
---|
| 450 | if (empty($post['postId'])) { |
---|
| 451 | throw new Exception('No post ID'); |
---|
| 452 | } |
---|
[2566] | 453 | |
---|
[0] | 454 | if (empty($post['metaId']) && $post['metaId'] != '0') { |
---|
| 455 | throw new Exception('No meta ID'); |
---|
| 456 | } |
---|
[2566] | 457 | |
---|
[0] | 458 | if (empty($post['metaType'])) { |
---|
| 459 | throw new Exception('No meta type'); |
---|
| 460 | } |
---|
[2566] | 461 | |
---|
[0] | 462 | $core->meta->delPostMeta($post['postId'],$post['metaType'],$post['metaId']); |
---|
[2566] | 463 | |
---|
[0] | 464 | return true; |
---|
| 465 | } |
---|
[2566] | 466 | |
---|
[0] | 467 | public static function searchMeta($core,$get) |
---|
| 468 | { |
---|
| 469 | $q = !empty($get['q']) ? $get['q'] : null; |
---|
| 470 | $metaType = !empty($get['metaType']) ? $get['metaType'] : null; |
---|
[2566] | 471 | |
---|
[0] | 472 | $sortby = !empty($get['sortby']) ? $get['sortby'] : 'meta_type,asc'; |
---|
[2566] | 473 | |
---|
[0] | 474 | $rs = $core->meta->getMetadata(array('meta_type' => $metaType)); |
---|
| 475 | $rs = $core->meta->computeMetaStats($rs); |
---|
[2566] | 476 | |
---|
[0] | 477 | $sortby = explode(',',$sortby); |
---|
| 478 | $sort = $sortby[0]; |
---|
| 479 | $order = isset($sortby[1]) ? $sortby[1] : 'asc'; |
---|
[2566] | 480 | |
---|
[0] | 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 | } |
---|
[2566] | 494 | |
---|
[0] | 495 | $rs->sort($sort,$order); |
---|
[2566] | 496 | |
---|
[0] | 497 | $rsp = new xmlTag(); |
---|
[2566] | 498 | |
---|
[0] | 499 | while ($rs->fetch()) |
---|
| 500 | { |
---|
[2572] | 501 | if (stripos($rs->meta_id,$q) === 0) { |
---|
[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); |
---|
[2566] | 509 | |
---|
[0] | 510 | $rsp->insertNode($metaTag); |
---|
| 511 | } |
---|
| 512 | } |
---|
[2566] | 513 | |
---|
[0] | 514 | return $rsp; |
---|
| 515 | } |
---|
[2566] | 516 | |
---|
[1699] | 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]); |
---|
[2566] | 536 | } |
---|
[1699] | 537 | } else { // false == unfold section ==> add it to unfolded list |
---|
| 538 | if ($k === false) { |
---|
| 539 | $toggles[]=$section; |
---|
[2566] | 540 | }; |
---|
[1699] | 541 | } |
---|
| 542 | $core->auth->user_prefs->toggles->put('unfolded_sections',join(',',$toggles)); |
---|
| 543 | return true; |
---|
| 544 | } |
---|
[2566] | 545 | |
---|
[2156] | 546 | public static function getModuleById($core, $get, $post) |
---|
| 547 | { |
---|
| 548 | if (empty($get['id'])) { |
---|
[2215] | 549 | throw new Exception('No module ID'); |
---|
[2156] | 550 | } |
---|
| 551 | if (empty($get['list'])) { |
---|
[2215] | 552 | throw new Exception('No list ID'); |
---|
[2156] | 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') { |
---|
[2216] | 567 | $store = new dcStore( |
---|
[2566] | 568 | $core->plugins, |
---|
[2216] | 569 | $core->blog->settings->system->store_plugin_url |
---|
[2156] | 570 | ); |
---|
[2216] | 571 | $store->check(); |
---|
[2156] | 572 | |
---|
[2216] | 573 | $modules = $store->get(); |
---|
[2156] | 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)) { |
---|
[2215] | 584 | throw new Exception('Unknow module ID'); |
---|
[2156] | 585 | } |
---|
| 586 | |
---|
[2227] | 587 | $module = adminModulesList::sanitizeModule($id, $module); |
---|
[2156] | 588 | |
---|
| 589 | $rsp = new xmlTag('module'); |
---|
| 590 | $rsp->id = $id; |
---|
[2215] | 591 | |
---|
[2156] | 592 | foreach($module as $k => $v) { |
---|
| 593 | $rsp->{$k}((string) $v); |
---|
| 594 | } |
---|
| 595 | |
---|
| 596 | return $rsp; |
---|
| 597 | } |
---|
[0] | 598 | } |
---|