[1719] | 1 | <?php |
---|
[3731] | 2 | /** |
---|
| 3 | * @package Dotclear |
---|
| 4 | * @subpackage Backend |
---|
| 5 | * |
---|
| 6 | * @copyright Olivier Meunier & Association Dotclear |
---|
| 7 | * @copyright GPL-2.0-only |
---|
| 8 | */ |
---|
| 9 | |
---|
[3730] | 10 | if (!defined('DC_RC_PATH')) {return;} |
---|
[1719] | 11 | /** |
---|
[2566] | 12 | @brief Admin combo library |
---|
[1719] | 13 | |
---|
| 14 | Dotclear utility class that provides reuseable combos across all admin |
---|
| 15 | |
---|
[3730] | 16 | */ |
---|
| 17 | class dcAdminCombos |
---|
| 18 | { |
---|
[1719] | 19 | |
---|
[3730] | 20 | /** @var dcCore dcCore instance */ |
---|
| 21 | public static $core; |
---|
[2566] | 22 | |
---|
[3730] | 23 | /** |
---|
| 24 | Returns an hierarchical categories combo from a category record |
---|
[2566] | 25 | |
---|
[3730] | 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 = array(); |
---|
| 32 | if ($include_empty) { |
---|
| 33 | $categories_combo = array(new formSelectOption(__('(No cat)'), '')); |
---|
| 34 | } |
---|
| 35 | while ($categories->fetch()) { |
---|
| 36 | $categories_combo[] = new formSelectOption( |
---|
| 37 | str_repeat(' ', ($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 | } |
---|
[2566] | 45 | |
---|
[3730] | 46 | /** |
---|
| 47 | Returns available post status combo |
---|
[2566] | 48 | |
---|
[3730] | 49 | @return <b>array</b> the combo box (form::combo -compatible format) |
---|
| 50 | */ |
---|
| 51 | public static function getPostStatusesCombo() |
---|
| 52 | { |
---|
| 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 | |
---|
[3730] | 60 | /** |
---|
| 61 | Returns an users combo from a users record |
---|
[2566] | 62 | |
---|
[3730] | 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 = array(); |
---|
| 69 | while ($users->fetch()) { |
---|
| 70 | $user_cn = dcUtils::getUserCN($users->user_id, $users->user_name, |
---|
| 71 | $users->user_firstname, $users->user_displayname); |
---|
[2566] | 72 | |
---|
[3730] | 73 | if ($user_cn != $users->user_id) { |
---|
| 74 | $user_cn .= ' (' . $users->user_id . ')'; |
---|
| 75 | } |
---|
[2566] | 76 | |
---|
[3730] | 77 | $users_combo[$user_cn] = $users->user_id; |
---|
| 78 | } |
---|
| 79 | return $users_combo; |
---|
| 80 | } |
---|
[2566] | 81 | |
---|
[3730] | 82 | /** |
---|
| 83 | Returns an date combo from a date record |
---|
[2566] | 84 | |
---|
[3730] | 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 = array(); |
---|
| 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 | } |
---|
[2566] | 96 | |
---|
[3730] | 97 | /** |
---|
| 98 | Returns an lang combo from a lang record |
---|
[2566] | 99 | |
---|
[3730] | 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 = array('' => '', __('Most used') => array(), __('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 = array(); |
---|
| 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 | } |
---|
[2566] | 128 | |
---|
[3730] | 129 | /** |
---|
| 130 | Returns a combo containing all available and installed languages for administration pages |
---|
[2566] | 131 | |
---|
[3730] | 132 | @return <b>array</b> the combo box (form::combo -compatible format) |
---|
| 133 | */ |
---|
| 134 | public static function getAdminLangsCombo() |
---|
| 135 | { |
---|
| 136 | $lang_combo = array(); |
---|
| 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 | } |
---|
[2566] | 144 | |
---|
[3730] | 145 | /** |
---|
| 146 | Returns a combo containing all available editors in admin |
---|
[2566] | 147 | |
---|
[3730] | 148 | @return <b>array</b> the combo box (form::combo -compatible format) |
---|
| 149 | */ |
---|
| 150 | public static function getEditorsCombo() |
---|
| 151 | { |
---|
| 152 | $editors_combo = array(); |
---|
[2679] | 153 | |
---|
[3730] | 154 | foreach (self::$core->getEditors() as $v) { |
---|
| 155 | $editors_combo[$v] = $v; |
---|
| 156 | } |
---|
[3082] | 157 | |
---|
[3730] | 158 | return $editors_combo; |
---|
| 159 | } |
---|
[2679] | 160 | |
---|
[3730] | 161 | /** |
---|
| 162 | Returns a combo containing all available formaters by editor in admin |
---|
[2679] | 163 | |
---|
[3730] | 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 = array(); |
---|
[2679] | 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 | |
---|
[3730] | 183 | return $formaters_combo; |
---|
| 184 | } |
---|
[2566] | 185 | |
---|
[3730] | 186 | /** |
---|
| 187 | Returns a combo containing available blog statuses |
---|
[2566] | 188 | |
---|
[3730] | 189 | @return <b>array</b> the combo box (form::combo -compatible format) |
---|
| 190 | */ |
---|
| 191 | public static function getBlogStatusesCombo() |
---|
| 192 | { |
---|
| 193 | $status_combo = array(); |
---|
| 194 | foreach (self::$core->getAllBlogStatus() as $k => $v) { |
---|
| 195 | $status_combo[$v] = (string) $k; |
---|
| 196 | } |
---|
| 197 | return $status_combo; |
---|
| 198 | } |
---|
[2566] | 199 | |
---|
[3730] | 200 | /** |
---|
| 201 | Returns a combo containing available comment statuses |
---|
[2566] | 202 | |
---|
[3730] | 203 | @return <b>array</b> the combo box (form::combo -compatible format) |
---|
| 204 | */ |
---|
| 205 | public static function getCommentStatusescombo() |
---|
| 206 | { |
---|
| 207 | $status_combo = array(); |
---|
| 208 | foreach (self::$core->blog->getAllCommentStatus() as $k => $v) { |
---|
| 209 | $status_combo[$v] = (string) $k; |
---|
| 210 | } |
---|
| 211 | return $status_combo; |
---|
| 212 | } |
---|
[1719] | 213 | } |
---|
[2566] | 214 | dcAdminCombos::$core = $GLOBALS['core']; |
---|