Dotclear

source: inc/admin/lib.admincombos.php @ 2566:9bf417837888

Revision 2566:9bf417837888, 5.2 KB checked in by franck <carnet.franck.paul@…>, 12 years ago (diff)

Add some people in CREDITS, remove trailing spaces and tabs.

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 (
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() {
53          $status_combo =  array();
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     /**
143     Returns a combo containing all available formaters in admin
[2566]144
[1719]145     @return   <b>array</b> the combo box (form::combo -compatible format)
[2566]146     */
[1719]147     public static function getFormatersCombo() {
148          foreach (self::$core->getFormaters() as $v) {
149               $formaters_combo[$v] = $v;
150          }
151          return $formaters_combo;
152     }
[2566]153
[1719]154     /**
155     Returns a combo containing available blog statuses
[2566]156
[1719]157     @return   <b>array</b> the combo box (form::combo -compatible format)
[2566]158     */
[1719]159     public static function getBlogStatusesCombo() {
160          $status_combo = array();
161          foreach (self::$core->getAllBlogStatus() as $k => $v) {
162               $status_combo[$v] = (string) $k;
163          }
164          return $status_combo;
165     }
[2566]166
[1719]167     /**
168     Returns a combo containing available comment statuses
[2566]169
[1719]170     @return   <b>array</b> the combo box (form::combo -compatible format)
[2566]171     */
[1719]172     public static function getCommentStatusescombo() {
173          $status_combo = array();
174          foreach (self::$core->blog->getAllCommentStatus() as $k => $v) {
175               $status_combo[$v] = (string) $k;
176          }
177          return $status_combo;
178     }
179}
[2566]180dcAdminCombos::$core = $GLOBALS['core'];
Note: See TracBrowser for help on using the repository browser.

Sites map