Dotclear

source: inc/admin/lib.admincombos.php @ 3206:bcf11daf3abb

Revision 3206:bcf11daf3abb, 6.0 KB checked in by franck <carnet.franck.paul@…>, 9 years ago (diff)

Add pseudo-indentation on hierarchical list of categories, still looking for a better way to fix this.

Line 
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 -----------------------------------------
12if (!defined('DC_RC_PATH')) { return; }
13/**
14@ingroup DC_CORE
15@nosubgrouping
16@brief Admin combo library
17
18Dotclear utility class that provides reuseable combos across all admin
19
20*/
21class dcAdminCombos {
22
23     /** @var dcCore dcCore instance */
24     public static $core;
25
26     /**
27     Returns an hierarchical categories combo from a category record
28
29     @param    categories          <b>record</b>       the category record
30     @return   <b>array</b> the combo box (form::combo -compatible format)
31     */
32     public static function getCategoriesCombo($categories,$include_empty = true,$use_url = false) {
33          $categories_combo = array();
34          if ($include_empty) {
35               $categories_combo = array(new formSelectOption(__('(No cat)'),''));
36          }
37          while ($categories->fetch()) {
38               $categories_combo[] = new formSelectOption (
39                    str_repeat('&nbsp;',($categories->level-1)*4).
40                html::escapeHTML($categories->cat_title).' ('.$categories->nb_post.')',
41                    ($use_url ? $categories->cat_url : $categories->cat_id),
42                    ($categories->level-1 ? 'sub-option'.($categories->level-1) : '')
43               );
44          }
45          return $categories_combo;
46     }
47
48     /**
49     Returns available post status combo
50
51     @return   <b>array</b> the combo box (form::combo -compatible format)
52     */
53     public static function getPostStatusesCombo() {
54          $status_combo =      array();
55          foreach (self::$core->blog->getAllPostStatus() as $k => $v) {
56               $status_combo[$v] = (string) $k;
57          }
58          return $status_combo;
59     }
60
61     /**
62     Returns an users combo from a users record
63
64     @param    users          <b>record</b>       the users record
65     @return   <b>array</b> the combo box (form::combo -compatible format)
66     */
67     public static function getUsersCombo($users) {
68          $users_combo = array();
69          while ($users->fetch())
70          {
71               $user_cn = dcUtils::getUserCN($users->user_id,$users->user_name,
72               $users->user_firstname,$users->user_displayname);
73
74               if ($user_cn != $users->user_id) {
75                    $user_cn .= ' ('.$users->user_id.')';
76               }
77
78               $users_combo[$user_cn] = $users->user_id;
79          }
80          return $users_combo;
81     }
82
83     /**
84     Returns an date combo from a date record
85
86     @param    dates          <b>record</b>       the dates record
87     @return   <b>array</b> the combo box (form::combo -compatible format)
88     */
89     public static function getDatesCombo($dates) {
90          $dt_m_combo= array();
91          while ($dates->fetch()) {
92               $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month();
93          }
94          return $dt_m_combo;
95     }
96
97     /**
98     Returns an lang combo from a lang record
99
100     @param    langs          <b>record</b>       the langs record
101     @param    with_available <b>boolean</b> if false, only list items from record
102                                                       if true, also list available languages
103     @return   <b>array</b> the combo box (form::combo -compatible format)
104     */
105     public static function getLangsCombo($langs,$with_available=false) {
106          $all_langs = l10n::getISOcodes(0,1);
107          if ($with_available) {
108               $langs_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1));
109               while ($langs->fetch()) {
110                    if (isset($all_langs[$langs->post_lang])) {
111                         $langs_combo[__('Most used')][$all_langs[$langs->post_lang]] = $langs->post_lang;
112                         unset($langs_combo[__('Available')][$all_langs[$langs->post_lang]]);
113                    } else {
114                         $langs_combo[__('Most used')][$langs->post_lang] = $langs->post_lang;
115                    }
116               }
117          } else {
118               $langs_combo = array();
119               while ($langs->fetch()) {
120                    $lang_name = isset($all_langs[$langs->post_lang]) ? $all_langs[$langs->post_lang] : $langs->post_lang;
121                    $langs_combo[$lang_name] = $langs->post_lang;
122               }
123          }
124          unset($all_langs);
125          return $langs_combo;
126     }
127
128     /**
129     Returns a combo containing all available and installed languages for administration pages
130
131     @return   <b>array</b> the combo box (form::combo -compatible format)
132     */
133     public static function getAdminLangsCombo() {
134          $lang_combo = array();
135          $langs = l10n::getISOcodes(1,1);
136          foreach ($langs as $k => $v) {
137               $lang_avail = $v == 'en' || is_dir(DC_L10N_ROOT.'/'.$v);
138               $lang_combo[] = new formSelectOption($k,$v,$lang_avail ? 'avail10n' : '');
139          }
140          return $lang_combo;
141     }
142
143     /**
144     Returns a combo containing all available editors in admin
145
146     @return   <b>array</b> the combo box (form::combo -compatible format)
147     */
148     public static function getEditorsCombo()
149     {
150          $editors_combo = array();
151
152          foreach (self::$core->getEditors() as $v) {
153               $editors_combo[$v] = $v;
154          }
155
156          return $editors_combo;
157     }
158
159     /**
160     Returns a combo containing all available formaters by editor in admin
161
162     @param    editor_id <b>string</b>  Editor id (dcLegacyEditor, dcCKEditor, ...)
163     @return   <b>array</b> the combo box (form::combo -compatible format)
164     */
165     public static function getFormatersCombo($editor_id='')
166     {
167          $formaters_combo = array();
168
169        if (!empty($editor_id)) {
170            foreach (self::$core->getFormaters($editor_id) as $formater) {
171                $formaters_combo[$formater] = $formater;
172            }
173        } else {
174            foreach (self::$core->getFormaters() as $editor => $formaters) {
175                foreach ($formaters as $formater) {
176                    $formaters_combo[$editor][$formater] = $formater;
177                }
178            }
179        }
180
181          return $formaters_combo;
182     }
183
184     /**
185     Returns a combo containing available blog statuses
186
187     @return   <b>array</b> the combo box (form::combo -compatible format)
188     */
189     public static function getBlogStatusesCombo() {
190          $status_combo = array();
191          foreach (self::$core->getAllBlogStatus() as $k => $v) {
192               $status_combo[$v] = (string) $k;
193          }
194          return $status_combo;
195     }
196
197     /**
198     Returns a combo containing available comment statuses
199
200     @return   <b>array</b> the combo box (form::combo -compatible format)
201     */
202     public static function getCommentStatusescombo() {
203          $status_combo = array();
204          foreach (self::$core->blog->getAllCommentStatus() as $k => $v) {
205               $status_combo[$v] = (string) $k;
206          }
207          return $status_combo;
208     }
209}
210dcAdminCombos::$core = $GLOBALS['core'];
Note: See TracBrowser for help on using the repository browser.

Sites map