| 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,$use_url = false) { | 
|---|
| 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 |                     html::escapeHTML($categories->cat_title).' ('.$categories->nb_post.')', | 
|---|
| 40 |                     ($use_url ? $categories->cat_url : $categories->cat_id), | 
|---|
| 41 |                     ($categories->level-1 ? 'sub-option'.($categories->level-1) : '') | 
|---|
| 42 |                ); | 
|---|
| 43 |           } | 
|---|
| 44 |           return $categories_combo; | 
|---|
| 45 |      } | 
|---|
| 46 |       | 
|---|
| 47 |      /** | 
|---|
| 48 |      Returns available post status combo  | 
|---|
| 49 |       | 
|---|
| 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 |      } | 
|---|
| 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 |           $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); | 
|---|
| 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 |           $dt_m_combo= array(); | 
|---|
| 90 |           while ($dates->fetch()) { | 
|---|
| 91 |                $dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month(); | 
|---|
| 92 |           }          | 
|---|
| 93 |           return $dt_m_combo; | 
|---|
| 94 |      } | 
|---|
| 95 |       | 
|---|
| 96 |      /** | 
|---|
| 97 |      Returns an lang combo from a lang record | 
|---|
| 98 |       | 
|---|
| 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) | 
|---|
| 103 |      */    | 
|---|
| 104 |      public static function getLangsCombo($langs,$with_available=false) { | 
|---|
| 105 |           $all_langs = l10n::getISOcodes(0,1); | 
|---|
| 106 |           if ($with_available) { | 
|---|
| 107 |                $langs_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1)); | 
|---|
| 108 |                while ($langs->fetch()) { | 
|---|
| 109 |                     if (isset($all_langs[$langs->post_lang])) { | 
|---|
| 110 |                          $langs_combo[__('Most used')][$all_langs[$langs->post_lang]] = $langs->post_lang; | 
|---|
| 111 |                          unset($langs_combo[__('Available')][$all_langs[$langs->post_lang]]); | 
|---|
| 112 |                     } else { | 
|---|
| 113 |                          $langs_combo[__('Most used')][$langs->post_lang] = $langs->post_lang; | 
|---|
| 114 |                     } | 
|---|
| 115 |                } | 
|---|
| 116 |           } else { | 
|---|
| 117 |                $langs_combo = array(); | 
|---|
| 118 |                while ($langs->fetch()) { | 
|---|
| 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; | 
|---|
| 121 |                } | 
|---|
| 122 |           } | 
|---|
| 123 |           unset($all_langs); | 
|---|
| 124 |           return $langs_combo; | 
|---|
| 125 |      } | 
|---|
| 126 |       | 
|---|
| 127 |      /** | 
|---|
| 128 |      Returns a combo containing all available and installed languages for administration pages | 
|---|
| 129 |       | 
|---|
| 130 |      @return   <b>array</b> the combo box (form::combo -compatible format) | 
|---|
| 131 |      */    | 
|---|
| 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 |      } | 
|---|
| 141 |       | 
|---|
| 142 |      /** | 
|---|
| 143 |      Returns a combo containing all available formaters in admin | 
|---|
| 144 |       | 
|---|
| 145 |      @return   <b>array</b> the combo box (form::combo -compatible format) | 
|---|
| 146 |      */    | 
|---|
| 147 |      public static function getFormatersCombo() { | 
|---|
| 148 |           foreach (self::$core->getFormaters() as $v) { | 
|---|
| 149 |                $formaters_combo[$v] = $v; | 
|---|
| 150 |           } | 
|---|
| 151 |           return $formaters_combo; | 
|---|
| 152 |      } | 
|---|
| 153 |       | 
|---|
| 154 |      /** | 
|---|
| 155 |      Returns a combo containing available blog statuses | 
|---|
| 156 |       | 
|---|
| 157 |      @return   <b>array</b> the combo box (form::combo -compatible format) | 
|---|
| 158 |      */    | 
|---|
| 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 |      } | 
|---|
| 166 |       | 
|---|
| 167 |      /** | 
|---|
| 168 |      Returns a combo containing available comment statuses | 
|---|
| 169 |       | 
|---|
| 170 |      @return   <b>array</b> the combo box (form::combo -compatible format) | 
|---|
| 171 |      */    | 
|---|
| 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 | } | 
|---|
| 180 | dcAdminCombos::$core = $GLOBALS['core']; | 
|---|