Dotclear

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

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

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

RevLine 
[1719]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
[2566]16@brief Admin combo library
[1719]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;
[2566]25
[1719]26     /**
27     Returns an hierarchical categories combo from a category record
[2566]28
[1719]29     @param    categories          <b>record</b>       the category record
30     @return   <b>array</b> the combo box (form::combo -compatible format)
31     */
[2154]32     public static function getCategoriesCombo($categories,$include_empty = true,$use_url = false) {
[1775]33          $categories_combo = array();
34          if ($include_empty) {
[1780]35               $categories_combo = array(new formSelectOption(__('(No cat)'),''));
[1775]36          }
[1719]37          while ($categories->fetch()) {
[1774]38               $categories_combo[] = new formSelectOption (
[3206]39                    str_repeat('&nbsp;',($categories->level-1)*4).
[3082]40                html::escapeHTML($categories->cat_title).' ('.$categories->nb_post.')',
[2154]41                    ($use_url ? $categories->cat_url : $categories->cat_id),
[2040]42                    ($categories->level-1 ? 'sub-option'.($categories->level-1) : '')
[1774]43               );
[1719]44          }
45          return $categories_combo;
46     }
[2566]47
[1719]48     /**
[2566]49     Returns available post status combo
50
[1719]51     @return   <b>array</b> the combo box (form::combo -compatible format)
52     */
53     public static function getPostStatusesCombo() {
[2679]54          $status_combo =      array();
[1719]55          foreach (self::$core->blog->getAllPostStatus() as $k => $v) {
56               $status_combo[$v] = (string) $k;
57          }
58          return $status_combo;
59     }
[2566]60
[1719]61     /**
62     Returns an users combo from a users record
[2566]63
[1719]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);
[2566]73
[1719]74               if ($user_cn != $users->user_id) {
75                    $user_cn .= ' ('.$users->user_id.')';
76               }
[2566]77
78               $users_combo[$user_cn] = $users->user_id;
[1719]79          }
80          return $users_combo;
81     }
[2566]82
[1719]83     /**
84     Returns an date combo from a date record
[2566]85
[1719]86     @param    dates          <b>record</b>       the dates record
87     @return   <b>array</b> the combo box (form::combo -compatible format)
[2566]88     */
[1719]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();
[2566]93          }
[1719]94          return $dt_m_combo;
95     }
[2566]96
[1719]97     /**
98     Returns an lang combo from a lang record
[2566]99
[1719]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)
[2566]104     */
[1719]105     public static function getLangsCombo($langs,$with_available=false) {
[1722]106          $all_langs = l10n::getISOcodes(0,1);
[1719]107          if ($with_available) {
[1722]108               $langs_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1));
[1719]109               while ($langs->fetch()) {
110                    if (isset($all_langs[$langs->post_lang])) {
[1722]111                         $langs_combo[__('Most used')][$all_langs[$langs->post_lang]] = $langs->post_lang;
112                         unset($langs_combo[__('Available')][$all_langs[$langs->post_lang]]);
[1719]113                    } else {
[1722]114                         $langs_combo[__('Most used')][$langs->post_lang] = $langs->post_lang;
[1719]115                    }
116               }
117          } else {
[1722]118               $langs_combo = array();
[1719]119               while ($langs->fetch()) {
[1722]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;
[1719]122               }
123          }
[1722]124          unset($all_langs);
125          return $langs_combo;
[1719]126     }
[2566]127
[1719]128     /**
129     Returns a combo containing all available and installed languages for administration pages
[2566]130
[1719]131     @return   <b>array</b> the combo box (form::combo -compatible format)
[2566]132     */
[1719]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     }
[2566]142
[1719]143     /**
[2679]144     Returns a combo containing all available editors in admin
[2566]145
[1719]146     @return   <b>array</b> the combo box (form::combo -compatible format)
[2566]147     */
[2679]148     public static function getEditorsCombo()
149     {
150          $editors_combo = array();
151
152          foreach (self::$core->getEditors() as $v) {
153               $editors_combo[$v] = $v;
[1719]154          }
[3082]155
[2679]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
[1719]181          return $formaters_combo;
182     }
[2566]183
[1719]184     /**
185     Returns a combo containing available blog statuses
[2566]186
[1719]187     @return   <b>array</b> the combo box (form::combo -compatible format)
[2566]188     */
[1719]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     }
[2566]196
[1719]197     /**
198     Returns a combo containing available comment statuses
[2566]199
[1719]200     @return   <b>array</b> the combo box (form::combo -compatible format)
[2566]201     */
[1719]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}
[2566]210dcAdminCombos::$core = $GLOBALS['core'];
Note: See TracBrowser for help on using the repository browser.

Sites map