1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
<?php
# -- BEGIN LICENSE BLOCK ---------------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK -----------------------------------------
if (!defined('DC_RC_PATH')) { return; }
/**
@ingroup DC_CORE
@nosubgrouping
@brief Admin combo library
Dotclear utility class that provides reuseable combos across all admin
*/
class dcAdminCombos {
/** @var dcCore dcCore instance */
public static $core;
/**
Returns an hierarchical categories combo from a category record
@param categories <b>record</b> the category record
@return <b>array</b> the combo box (form::combo -compatible format)
*/
public static function getCategoriesCombo($categories,$include_empty = true,$use_url = false) {
$categories_combo = array();
if ($include_empty) {
$categories_combo = array(new formSelectOption(__('(No cat)'),''));
}
while ($categories->fetch()) {
$categories_combo[] = new formSelectOption (
html::escapeHTML($categories->cat_title).' ('.$categories->nb_post.')',
($use_url ? $categories->cat_url : $categories->cat_id),
($categories->level-1 ? 'sub-option'.($categories->level-1) : '')
);
}
return $categories_combo;
}
/**
Returns available post status combo
@return <b>array</b> the combo box (form::combo -compatible format)
*/
public static function getPostStatusesCombo() {
$status_combo = array();
foreach (self::$core->blog->getAllPostStatus() as $k => $v) {
$status_combo[$v] = (string) $k;
}
return $status_combo;
}
/**
Returns an users combo from a users record
@param users <b>record</b> the users record
@return <b>array</b> the combo box (form::combo -compatible format)
*/
public static function getUsersCombo($users) {
$users_combo = array();
while ($users->fetch())
{
$user_cn = dcUtils::getUserCN($users->user_id,$users->user_name,
$users->user_firstname,$users->user_displayname);
if ($user_cn != $users->user_id) {
$user_cn .= ' ('.$users->user_id.')';
}
$users_combo[$user_cn] = $users->user_id;
}
return $users_combo;
}
/**
Returns an date combo from a date record
@param dates <b>record</b> the dates record
@return <b>array</b> the combo box (form::combo -compatible format)
*/
public static function getDatesCombo($dates) {
$dt_m_combo= array();
while ($dates->fetch()) {
$dt_m_combo[dt::str('%B %Y',$dates->ts())] = $dates->year().$dates->month();
}
return $dt_m_combo;
}
/**
Returns an lang combo from a lang record
@param langs <b>record</b> the langs record
@param with_available <b>boolean</b> if false, only list items from record
if true, also list available languages
@return <b>array</b> the combo box (form::combo -compatible format)
*/
public static function getLangsCombo($langs,$with_available=false) {
$all_langs = l10n::getISOcodes(0,1);
if ($with_available) {
$langs_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1));
while ($langs->fetch()) {
if (isset($all_langs[$langs->post_lang])) {
$langs_combo[__('Most used')][$all_langs[$langs->post_lang]] = $langs->post_lang;
unset($langs_combo[__('Available')][$all_langs[$langs->post_lang]]);
} else {
$langs_combo[__('Most used')][$langs->post_lang] = $langs->post_lang;
}
}
} else {
$langs_combo = array();
while ($langs->fetch()) {
$lang_name = isset($all_langs[$langs->post_lang]) ? $all_langs[$langs->post_lang] : $langs->post_lang;
$langs_combo[$lang_name] = $langs->post_lang;
}
}
unset($all_langs);
return $langs_combo;
}
/**
Returns a combo containing all available and installed languages for administration pages
@return <b>array</b> the combo box (form::combo -compatible format)
*/
public static function getAdminLangsCombo() {
$lang_combo = array();
$langs = l10n::getISOcodes(1,1);
foreach ($langs as $k => $v) {
$lang_avail = $v == 'en' || is_dir(DC_L10N_ROOT.'/'.$v);
$lang_combo[] = new formSelectOption($k,$v,$lang_avail ? 'avail10n' : '');
}
return $lang_combo;
}
/**
Returns a combo containing all available formaters in admin
@return <b>array</b> the combo box (form::combo -compatible format)
*/
public static function getFormatersCombo() {
foreach (self::$core->getFormaters() as $v) {
$formaters_combo[$v] = $v;
}
return $formaters_combo;
}
/**
Returns a combo containing available blog statuses
@return <b>array</b> the combo box (form::combo -compatible format)
*/
public static function getBlogStatusesCombo() {
$status_combo = array();
foreach (self::$core->getAllBlogStatus() as $k => $v) {
$status_combo[$v] = (string) $k;
}
return $status_combo;
}
/**
Returns a combo containing available comment statuses
@return <b>array</b> the combo box (form::combo -compatible format)
*/
public static function getCommentStatusescombo() {
$status_combo = array();
foreach (self::$core->blog->getAllCommentStatus() as $k => $v) {
$status_combo[$v] = (string) $k;
}
return $status_combo;
}
}
dcAdminCombos::$core = $GLOBALS['core'];
|