| 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 ----------------------------------------- | 
|---|
| 12 | if (!defined('DC_RC_PATH')) { return; } | 
|---|
| 13 | /** | 
|---|
| 14 | @ingroup DC_CORE | 
|---|
| 15 | @nosubgrouping | 
|---|
| 16 | @brief Admin combo library | 
|---|
| 17 |  | 
|---|
| 18 | Dotclear utility class that provides reuseable combos across all admin | 
|---|
| 19 |  | 
|---|
| 20 | */ | 
|---|
| 21 | class 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,$include_empty = true) { | 
|---|
| 33 | $categories_combo = array(); | 
|---|
| 34 | if ($include_empty) { | 
|---|
| 35 | $categories_combo = array(new formSelectOption(__('(No cat)'),'')); | 
|---|
| 36 | } | 
|---|
| 37 | while ($categories->fetch()) { | 
|---|
| 38 | $categories_combo[] = new formSelectOption ( | 
|---|
| 39 | //                  str_repeat('  ',$categories->level-1).($categories->level-1 == 0 ? '' : '• '). | 
|---|
| 40 | html::escapeHTML($categories->cat_title).' ('.$categories->nb_post.')', | 
|---|
| 41 | $categories->cat_id, | 
|---|
| 42 | ($categories->level-1 ? 'sub-option'.($categories->level-1) : '') | 
|---|
| 43 | ); | 
|---|
| 44 | } | 
|---|
| 45 | return $categories_combo; | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | /** | 
|---|
| 49 | Returns available post status combo | 
|---|
| 50 |  | 
|---|
| 51 | @return   <b>array</b> the combo box (form::combo -compatible format) | 
|---|
| 52 | */ | 
|---|
| 53 | public static function getPostStatusesCombo() { | 
|---|
| 54 | $status_combo =  array(); | 
|---|
| 55 | foreach (self::$core->blog->getAllPostStatus() as $k => $v) { | 
|---|
| 56 | $status_combo[$v] = (string) $k; | 
|---|
| 57 | } | 
|---|
| 58 | return $status_combo; | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 | /** | 
|---|
| 62 | Returns an users combo from a users record | 
|---|
| 63 |  | 
|---|
| 64 | @param    users          <b>record</b>       the users record | 
|---|
| 65 | @return   <b>array</b> the combo box (form::combo -compatible format) | 
|---|
| 66 | */ | 
|---|
| 67 | public static function getUsersCombo($users) { | 
|---|
| 68 | $users_combo = array(); | 
|---|
| 69 | while ($users->fetch()) | 
|---|
| 70 | { | 
|---|
| 71 | $user_cn = dcUtils::getUserCN($users->user_id,$users->user_name, | 
|---|
| 72 | $users->user_firstname,$users->user_displayname); | 
|---|
| 73 |  | 
|---|
| 74 | if ($user_cn != $users->user_id) { | 
|---|
| 75 | $user_cn .= ' ('.$users->user_id.')'; | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | $users_combo[$user_cn] = $users->user_id; | 
|---|
| 79 | } | 
|---|
| 80 | return $users_combo; | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | /** | 
|---|
| 84 | Returns an date combo from a date record | 
|---|
| 85 |  | 
|---|
| 86 | @param    dates          <b>record</b>       the dates record | 
|---|
| 87 | @return   <b>array</b> the combo box (form::combo -compatible format) | 
|---|
| 88 | */ | 
|---|
| 89 | public static function getDatesCombo($dates) { | 
|---|
| 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 | } | 
|---|
| 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 | $all_langs = l10n::getISOcodes(0,1); | 
|---|
| 107 | if ($with_available) { | 
|---|
| 108 | $langs_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); | 
|---|
| 109 | while ($langs->fetch()) { | 
|---|
| 110 | if (isset($all_langs[$langs->post_lang])) { | 
|---|
| 111 | $langs_combo[__('Most used')][$all_langs[$langs->post_lang]] = $langs->post_lang; | 
|---|
| 112 | unset($langs_combo[__('Available')][$all_langs[$langs->post_lang]]); | 
|---|
| 113 | } else { | 
|---|
| 114 | $langs_combo[__('Most used')][$langs->post_lang] = $langs->post_lang; | 
|---|
| 115 | } | 
|---|
| 116 | } | 
|---|
| 117 | } else { | 
|---|
| 118 | $langs_combo = array(); | 
|---|
| 119 | while ($langs->fetch()) { | 
|---|
| 120 | $lang_name = isset($all_langs[$langs->post_lang]) ? $all_langs[$langs->post_lang] : $langs->post_lang; | 
|---|
| 121 | $langs_combo[$lang_name] = $langs->post_lang; | 
|---|
| 122 | } | 
|---|
| 123 | } | 
|---|
| 124 | unset($all_langs); | 
|---|
| 125 | return $langs_combo; | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|
| 128 | /** | 
|---|
| 129 | Returns a combo containing all available and installed languages for administration pages | 
|---|
| 130 |  | 
|---|
| 131 | @return   <b>array</b> the combo box (form::combo -compatible format) | 
|---|
| 132 | */ | 
|---|
| 133 | public static function getAdminLangsCombo() { | 
|---|
| 134 | $lang_combo = array(); | 
|---|
| 135 | $langs = l10n::getISOcodes(1,1); | 
|---|
| 136 | foreach ($langs as $k => $v) { | 
|---|
| 137 | $lang_avail = $v == 'en' || is_dir(DC_L10N_ROOT.'/'.$v); | 
|---|
| 138 | $lang_combo[] = new formSelectOption($k,$v,$lang_avail ? 'avail10n' : ''); | 
|---|
| 139 | } | 
|---|
| 140 | return $lang_combo; | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | /** | 
|---|
| 144 | Returns a combo containing all available formaters in admin | 
|---|
| 145 |  | 
|---|
| 146 | @return   <b>array</b> the combo box (form::combo -compatible format) | 
|---|
| 147 | */ | 
|---|
| 148 | public static function getFormatersCombo() { | 
|---|
| 149 | foreach (self::$core->getFormaters() as $v) { | 
|---|
| 150 | $formaters_combo[$v] = $v; | 
|---|
| 151 | } | 
|---|
| 152 | return $formaters_combo; | 
|---|
| 153 | } | 
|---|
| 154 |  | 
|---|
| 155 | /** | 
|---|
| 156 | Returns a combo containing available blog statuses | 
|---|
| 157 |  | 
|---|
| 158 | @return   <b>array</b> the combo box (form::combo -compatible format) | 
|---|
| 159 | */ | 
|---|
| 160 | public static function getBlogStatusesCombo() { | 
|---|
| 161 | $status_combo = array(); | 
|---|
| 162 | foreach (self::$core->getAllBlogStatus() as $k => $v) { | 
|---|
| 163 | $status_combo[$v] = (string) $k; | 
|---|
| 164 | } | 
|---|
| 165 | return $status_combo; | 
|---|
| 166 | } | 
|---|
| 167 |  | 
|---|
| 168 | /** | 
|---|
| 169 | Returns a combo containing available comment statuses | 
|---|
| 170 |  | 
|---|
| 171 | @return   <b>array</b> the combo box (form::combo -compatible format) | 
|---|
| 172 | */ | 
|---|
| 173 | public static function getCommentStatusescombo() { | 
|---|
| 174 | $status_combo = array(); | 
|---|
| 175 | foreach (self::$core->blog->getAllCommentStatus() as $k => $v) { | 
|---|
| 176 | $status_combo[$v] = (string) $k; | 
|---|
| 177 | } | 
|---|
| 178 | return $status_combo; | 
|---|
| 179 | } | 
|---|
| 180 | } | 
|---|
| 181 | dcAdminCombos::$core = $GLOBALS['core']; | 
|---|