Dotclear

source: plugins/quickcat/_admin.php @ 2407

Revision 2407, 2.8 KB checked in by bruno, 13 years ago (diff)

QuickCat? plugin

Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3#
4# This file is part of Dotclear 2 "QuickCat" plugin.
5#
6# Copyright (c) 2010 Bruno Hondelatte, and contributors.
7# Many, many thanks to Olivier Meunier and the Dotclear Team.
8# Licensed under the GPL version 2.0 license.
9# See LICENSE file or
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11#
12# -- END LICENSE BLOCK ------------------------------------
13if (!defined('DC_RC_PATH')) { return; }
14$core->addBehavior('adminPostHeaders',array('quickCatBehaviors', 'adminPostHeaders'));
15$core->rest->addFunction('createCategory',array('quickCatBehaviors','createCategory'));
16$core->rest->addFunction('getCategoriesAsSelect',array('quickCatBehaviors','getCategoriesAsSelect'));
17
18
19class quickCatBehaviors {
20
21     public static function adminPostHeaders() {
22          return
23               '<script type="text/javascript">'."\n".
24               "//<![CDATA[\n".
25               "dotclear.msg.new_category = '".html::escapeJS(__('New category...'))."';\n".
26               "dotclear.msg.cat_title = '".html::escapeJS(__('Title :'))."';\n".
27               "dotclear.msg.parent_category = '".html::escapeJS(__('Parent category :'))."';\n".
28               "dotclear.msg.create_cat = '".html::escapeJS(__('Create category'))."';\n".
29               "\n//]]>\n".
30               '</script>'.
31               '<script type="text/javascript" src="index.php?pf=quickcat/quickcat.js"></script>'."\n";
32     }
33     
34     public static function createCategory($core,$get,$post) {
35          if (empty($post['cat_title'])) {
36               throw new Exception(__('No category title provided'));
37          }
38          $cur = $core->con->openCursor($core->prefix.'category');
39          $cur->cat_title = $cat_title = $post['cat_title'];
40         
41          if (isset($post['cat_desc'])) {
42               $cur->cat_desc = $post['cat_desc'];
43          }
44         
45          if (isset($post['cat_url'])) {
46               $cur->cat_url = $post['cat_url'];
47          } else {
48               $cur->cat_url = '';
49          }
50          if (isset($post['parent_cat'])) {
51               $parent_cat = $post['parent_cat'];
52          } else {
53               $parent_cat = '';
54          }
55         
56          # --BEHAVIOR-- adminBeforeCategoryCreate
57          $core->callBehavior('adminBeforeCategoryCreate',$cur);
58               
59          $id = $core->blog->addCategory($cur,(integer) $parent_cat);
60               
61          # --BEHAVIOR-- adminAfterCategoryCreate
62          $core->callBehavior('adminAfterCategoryCreate',$cur,$id);
63          return $id;
64         
65     }
66
67     public static function getCategoriesAsSelect($core,$get) {
68          if (!empty($get['select'])) {
69               $selected = (integer) $get['select'];
70          } else {
71               $selected=0;
72          }
73          $categories_combo = array('&nbsp;' => '');
74          $categories = $core->blog->getCategories(array('post_type'=>'post'));
75          while ($categories->fetch()) {
76               $categories_combo[] = new formSelectOption(
77                    str_repeat('&nbsp;&nbsp;',$categories->level-1).'&bull; '.html::escapeHTML($categories->cat_title),
78                    $categories->cat_id
79               );
80          }
81          return    form::combo('cat_id',$categories_combo,$selected,'maximal',3);
82     }
83}
84
85?>
Note: See TracBrowser for help on using the repository browser.

Sites map