Dotclear

source: inc/admin/lib.admincombos.php @ 1722:63591a096fb3

Revision 1722:63591a096fb3, 5.0 KB checked in by Dsls, 12 years ago (diff)

Improved lang combo, updated simpleMenu accordingly, see #1599

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

Sites map