Dotclear

source: inc/admin/lib.admincombos.php @ 3874:ab8368569446

Revision 3874:ab8368569446, 6.7 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

short notation for array (array() → [])

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

Sites map