Dotclear

source: inc/admin/lib.admincombos.php @ 3082:c2a6b6a3afac

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

Will not fix webkit/chrome css rendering bug on mac for option this way. Need to find something working on every browser (firefox displayed bullet twice, label and css)

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

Sites map