Changeset 3730:5c45a5df9a59 for inc/admin
- Timestamp:
- 03/08/18 17:58:39 (7 years ago)
- Branch:
- default
- Location:
- inc/admin
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/admin/actions/class.dcaction.php
r3707 r3730 362 362 'checked' => true 363 363 )) . 364 '</td>' .365 '<td>' . $title . '</td></tr>';364 '</td>' . 365 '<td>' . $title . '</td></tr>'; 366 366 } 367 367 $ret .= '</table>'; -
inc/admin/actions/class.dcactionblogs.php
r3707 r3730 78 78 'checked' => true 79 79 )) . 80 '</td>' .81 '<td>' . $res['blog'] . '</td>' .82 '<td>' . $res['name'] . '</td>' .83 '</tr>';80 '</td>' . 81 '<td>' . $res['blog'] . '</td>' . 82 '<td>' . $res['name'] . '</td>' . 83 '</tr>'; 84 84 } 85 85 -
inc/admin/actions/class.dcactioncomments.php
r3707 r3730 91 91 'checked' => true 92 92 )) . 93 '</td>' .94 '<td>' . $title['author'] . '</td><td>' . $title['title'] . '</td></tr>';93 '</td>' . 94 '<td>' . $title['author'] . '</td><td>' . $title['title'] . '</td></tr>'; 95 95 } 96 96 $ret .= '</table>'; -
inc/admin/class.dc.favorites.php
r3394 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 /** 15 * dcFavorites -- Favorites handling facilities16 *17 */15 * dcFavorites -- Favorites handling facilities 16 * 17 */ 18 18 class dcFavorites 19 19 { 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 20 /** @var dcCore dotclear core instance */ 21 protected $core; 22 23 /** @var array list of favorite definitions */ 24 protected $fav_defs; 25 26 /** @var dcWorkspace current favorite landing workspace */ 27 protected $ws; 28 29 /** @var array list of user-defined favorite ids */ 30 protected $local_prefs; 31 32 /** @var array list of globally-defined favorite ids */ 33 protected $global_prefs; 34 35 /** @var array list of user preferences (either one of the 2 above, or not!) */ 36 protected $user_prefs; 37 37 38 38 /** … … 45 45 * @return mixed Value. 46 46 */ 47 public function __construct($core) { 48 $this->core = $core; 49 $this->fav_defs = new ArrayObject();50 $this->ws = $core->auth->user_prefs->addWorkspace('dashboard');51 $this->user_prefs = array();52 53 if ($this->ws->prefExists('favorites')) { 54 $this->local_prefs = $this->ws->getLocal('favorites'); 55 $this->global_prefs = $this->ws->getGlobal('favorites');56 // Since we never know what user puts through user:preferences ... 57 if (!is_array($this->local_prefs)) { 58 $this->local_prefs = array(); 59 } 60 if (!is_array($this->global_prefs)) { 61 $this->global_prefs = array(); 62 } 63 } else { 64 // No favorite defined ? Huhu, let's go for a migration 65 $this->migrateFavorites(); 66 } 67 68 47 public function __construct($core) 48 { 49 $this->core = $core; 50 $this->fav_defs = new ArrayObject(); 51 $this->ws = $core->auth->user_prefs->addWorkspace('dashboard'); 52 $this->user_prefs = array(); 53 54 if ($this->ws->prefExists('favorites')) { 55 $this->local_prefs = $this->ws->getLocal('favorites'); 56 $this->global_prefs = $this->ws->getGlobal('favorites'); 57 // Since we never know what user puts through user:preferences ... 58 if (!is_array($this->local_prefs)) { 59 $this->local_prefs = array(); 60 } 61 if (!is_array($this->global_prefs)) { 62 $this->global_prefs = array(); 63 } 64 } else { 65 // No favorite defined ? Huhu, let's go for a migration 66 $this->migrateFavorites(); 67 } 68 } 69 69 70 70 /** 71 71 * setup - sets up favorites, fetch user favorites (against his permissions) 72 * This method is to be called after loading plugins 73 * 74 * @access public 75 * 76 */ 77 public function setup() { 78 defaultFavorites::initDefaultFavorites($this); 79 $this->legacyFavorites(); 80 $this->core->callBehavior('adminDashboardFavorites', $this->core, $this); 81 $this->setUserPrefs(); 82 } 83 84 /** 72 * This method is to be called after loading plugins 73 * 74 * @access public 75 * 76 */ 77 public function setup() 78 { 79 defaultFavorites::initDefaultFavorites($this); 80 $this->legacyFavorites(); 81 $this->core->callBehavior('adminDashboardFavorites', $this->core, $this); 82 $this->setUserPrefs(); 83 } 84 85 /** 85 86 * getFavorite - retrieves a favorite (complete description) from its id. 86 87 * … … 91 92 * @return array the favorite, false if not found (or not permitted) 92 93 */ 93 public function getFavorite($p) { 94 if (is_array($p)) { 95 $fname=$p['name']; 96 if (!isset($this->fav_defs[$fname])) { 97 return false; 98 } 99 $fattr = $p; 100 unset($fattr['name']); 101 $fattr = array_merge($this->fav_defs[$fname],$fattr); 102 } else { 103 if (!isset($this->fav_defs[$p])) { 104 return false; 105 } 106 $fattr = $this->fav_defs[$p]; 107 } 108 $fattr = array_merge(array('id' => null,'class' => null),$fattr); 109 if (isset($fattr['permissions'])) { 110 if (is_bool($fattr['permissions']) && !$fattr['permissions'] ) { 111 return false; 112 } 113 if (!$this->core->auth->check($fattr['permissions'],$this->core->blog->id)) { 114 return false; 115 } 116 } 117 return $fattr; 118 } 119 120 /** 94 public function getFavorite($p) 95 { 96 if (is_array($p)) { 97 $fname = $p['name']; 98 if (!isset($this->fav_defs[$fname])) { 99 return false; 100 } 101 $fattr = $p; 102 unset($fattr['name']); 103 $fattr = array_merge($this->fav_defs[$fname], $fattr); 104 } else { 105 if (!isset($this->fav_defs[$p])) { 106 return false; 107 } 108 $fattr = $this->fav_defs[$p]; 109 } 110 $fattr = array_merge(array('id' => null, 'class' => null), $fattr); 111 if (isset($fattr['permissions'])) { 112 if (is_bool($fattr['permissions']) && !$fattr['permissions']) { 113 return false; 114 } 115 if (!$this->core->auth->check($fattr['permissions'], $this->core->blog->id)) { 116 return false; 117 } 118 } 119 return $fattr; 120 } 121 122 /** 121 123 * getFavorites - retrieves a list of favorites. 122 124 * … … 127 129 * @return array array of favorites, can be empty if ids are not found (or not permitted) 128 130 */ 129 public function getFavorites($ids) { 130 $prefs = array(); 131 foreach ($ids as $id) { 132 $f = $this->getFavorite($id); 133 if ($f !== false) { 134 $prefs[$id]=$f; 135 } 136 } 137 return $prefs; 138 } 139 140 /** 131 public function getFavorites($ids) 132 { 133 $prefs = array(); 134 foreach ($ids as $id) { 135 $f = $this->getFavorite($id); 136 if ($f !== false) { 137 $prefs[$id] = $f; 138 } 139 } 140 return $prefs; 141 } 142 143 /** 141 144 * setUserPrefs - get user favorites from settings. These are complete favorites, not ids only 142 * 143 ** user-defined favorites144 ** globally-defined favorites145 ** a failback list "new post" (shall never be empty)146 *This method is called by ::setup()145 * returned favorites are the first non-empty list from : 146 * * user-defined favorites 147 * * globally-defined favorites 148 * * a failback list "new post" (shall never be empty) 149 * This method is called by ::setup() 147 150 * @access protected 148 151 * 149 152 */ 150 protected function setUserPrefs() { 151 $this->user_prefs = $this->getFavorites($this->local_prefs); 152 if (!count($this->user_prefs)) { 153 $this->user_prefs = $this->getFavorites($this->global_prefs); 154 } 155 if (!count($this->user_prefs)) { 156 $this->user_prefs = $this->getFavorites(array('new_post')); 157 } 158 $u = explode('?',$_SERVER['REQUEST_URI']); 159 // Loop over prefs to enable active favorites 160 foreach ($this->user_prefs as $k => &$v) { 161 if (isset($v['active_cb']) && is_callable($v['active_cb'])) { 162 // Use callback if defined to match whether favorite is active or not 163 $v['active'] = call_user_func($v['active_cb'],$u[0],$_REQUEST); 164 } else { 165 // Failback active detection. We test against URI name & parameters 166 $v['active'] = true; // true until something proves it is false 167 $u = explode('?',$v['url'],2); 168 if (!preg_match('/'.preg_quote($u[0],"/").'/',$_SERVER['REQUEST_URI'])) { 169 $v['active'] = false; // no URI match 170 } 171 if (count($u) == 2) { 172 parse_str($u[1],$p); 173 // test against each request parameter. 174 foreach ($p as $k2 => $v2) { 175 if (!isset($_REQUEST[$k2]) || $_REQUEST[$k2] !== $v2) { 176 $v['active'] = false; 177 } 178 } 179 } 180 } 181 } 182 183 } 184 185 /** 153 protected function setUserPrefs() 154 { 155 $this->user_prefs = $this->getFavorites($this->local_prefs); 156 if (!count($this->user_prefs)) { 157 $this->user_prefs = $this->getFavorites($this->global_prefs); 158 } 159 if (!count($this->user_prefs)) { 160 $this->user_prefs = $this->getFavorites(array('new_post')); 161 } 162 $u = explode('?', $_SERVER['REQUEST_URI']); 163 // Loop over prefs to enable active favorites 164 foreach ($this->user_prefs as $k => &$v) { 165 if (isset($v['active_cb']) && is_callable($v['active_cb'])) { 166 // Use callback if defined to match whether favorite is active or not 167 $v['active'] = call_user_func($v['active_cb'], $u[0], $_REQUEST); 168 } else { 169 // Failback active detection. We test against URI name & parameters 170 $v['active'] = true; // true until something proves it is false 171 $u = explode('?', $v['url'], 2); 172 if (!preg_match('/' . preg_quote($u[0], "/") . '/', $_SERVER['REQUEST_URI'])) { 173 $v['active'] = false; // no URI match 174 } 175 if (count($u) == 2) { 176 parse_str($u[1], $p); 177 // test against each request parameter. 178 foreach ($p as $k2 => $v2) { 179 if (!isset($_REQUEST[$k2]) || $_REQUEST[$k2] !== $v2) { 180 $v['active'] = false; 181 } 182 } 183 } 184 } 185 } 186 187 } 188 189 /** 186 190 * migrateFavorites - migrate dc < 2.6 favorites to new format 187 191 * 188 192 * @access protected 189 193 * 190 194 */ 191 protected function migrateFavorites() { 192 $fav_ws = $this->core->auth->user_prefs->addWorkspace('favorites'); 193 $this->local_prefs=array(); 194 $this->global_prefs=array(); 195 foreach ($fav_ws->dumpPrefs() as $k => $v) { 196 $fav = @unserialize($v['value']); 197 if (is_array($fav)) { 198 if ($v['global']) { 199 $this->global_prefs[] = $fav['name']; 200 } else { 201 $this->local_prefs[] = $fav['name']; 202 } 203 } 204 } 205 $this->ws->put('favorites',$this->global_prefs,'array','User favorites',true,true); 206 $this->ws->put('favorites',$this->local_prefs); 207 $this->user_prefs = $this->getFavorites($this->local_prefs); 208 } 209 210 211 212 /** 195 protected function migrateFavorites() 196 { 197 $fav_ws = $this->core->auth->user_prefs->addWorkspace('favorites'); 198 $this->local_prefs = array(); 199 $this->global_prefs = array(); 200 foreach ($fav_ws->dumpPrefs() as $k => $v) { 201 $fav = @unserialize($v['value']); 202 if (is_array($fav)) { 203 if ($v['global']) { 204 $this->global_prefs[] = $fav['name']; 205 } else { 206 $this->local_prefs[] = $fav['name']; 207 } 208 } 209 } 210 $this->ws->put('favorites', $this->global_prefs, 'array', 'User favorites', true, true); 211 $this->ws->put('favorites', $this->local_prefs); 212 $this->user_prefs = $this->getFavorites($this->local_prefs); 213 } 214 215 /** 213 216 * legacyFavorites - handle legacy favorites using adminDashboardFavs behavior 214 217 * 215 218 * @access protected 216 219 * 217 220 */ 218 protected function legacyFavorites() { 219 $f = new ArrayObject(); 220 $this->core->callBehavior('adminDashboardFavs', $this->core, $f); 221 foreach ($f as $k => $v) { 222 $fav = array ( 223 'title' => __($v[1]), 224 'url' => $v[2], 225 'small-icon' => $v[3], 226 'large-icon' => $v[4], 227 'permissions' => $v[5], 228 'id' => $v[6], 229 'class' => $v[7] 230 ); 231 $this->register ($v[0], $fav); 232 } 233 234 } 235 236 /** 221 protected function legacyFavorites() 222 { 223 $f = new ArrayObject(); 224 $this->core->callBehavior('adminDashboardFavs', $this->core, $f); 225 foreach ($f as $k => $v) { 226 $fav = array( 227 'title' => __($v[1]), 228 'url' => $v[2], 229 'small-icon' => $v[3], 230 'large-icon' => $v[4], 231 'permissions' => $v[5], 232 'id' => $v[6], 233 'class' => $v[7] 234 ); 235 $this->register($v[0], $fav); 236 } 237 238 } 239 240 /** 237 241 * getUserFavorites - returns favorites that correspond to current user 238 239 242 * (may be local, global, or failback favorites) 243 * 240 244 * @access public 241 245 * 242 246 * @return array array of favorites (enriched) 243 247 */ 244 public function getUserFavorites() { 245 return $this->user_prefs; 246 } 247 248 249 /**248 public function getUserFavorites() 249 { 250 return $this->user_prefs; 251 } 252 253 /** 250 254 * getFavoriteIDs - returns user-defined or global favorites ids list 251 *shall not be called outside preferences.php...252 255 * shall not be called outside preferences.php... 256 * 253 257 * @param boolean $global if true, retrieve global favs, user favs otherwise 254 258 * 255 259 * @access public 256 260 * 257 261 * @return array array of favorites ids (only ids, not enriched) 258 262 */ 259 public function getFavoriteIDs ($global=false) { 260 return $global?$this->global_prefs:$this->local_prefs; 261 } 262 263 /** 263 public function getFavoriteIDs($global = false) 264 { 265 return $global ? $this->global_prefs : $this->local_prefs; 266 } 267 268 /** 264 269 * setFavoriteIDs - stores user-defined or global favorites ids list 265 *shall not be called outside preferences.php...266 270 * shall not be called outside preferences.php... 271 * 267 272 * @param array $ids list of fav ids 268 273 * @param boolean $global if true, retrieve global favs, user favs otherwise 269 * 270 * @access public 271 */ 272 public function setFavoriteIDs($ids,$global=false) { 273 $this->ws->put('favorites',$ids,'array',null,true,$global); 274 } 275 276 /** 274 * 275 * @access public 276 */ 277 public function setFavoriteIDs($ids, $global = false) 278 { 279 $this->ws->put('favorites', $ids, 'array', null, true, $global); 280 } 281 282 /** 277 283 * getAvailableFavoritesIDs - returns all available fav ids 278 284 * 279 285 * @access public 280 286 * 281 287 * @return array array of favorites ids (only ids, not enriched) 282 288 */ 283 public function getAvailableFavoritesIDs () { 284 return array_keys($this->fav_defs->getArrayCopy()); 285 } 286 287 /** 289 public function getAvailableFavoritesIDs() 290 { 291 return array_keys($this->fav_defs->getArrayCopy()); 292 } 293 294 /** 288 295 * appendMenuTitle - adds favorites section title to sidebar menu 289 *shall not be called outside admin/prepend.php...290 296 * shall not be called outside admin/prepend.php... 297 * 291 298 * @param dcMenu $menu admin menu instance 292 * 293 * @access public 294 */ 295 public function appendMenuTitle($menu) { 296 $menu['Favorites'] = new dcMenu('favorites-menu','My favorites'); 297 $menu['Favorites']->title = __('My favorites'); 298 } 299 300 /** 299 * 300 * @access public 301 */ 302 public function appendMenuTitle($menu) 303 { 304 $menu['Favorites'] = new dcMenu('favorites-menu', 'My favorites'); 305 $menu['Favorites']->title = __('My favorites'); 306 } 307 308 /** 301 309 * appendMenu - adds favorites items title to sidebar menu 302 *shall not be called outside admin/prepend.php...303 310 * shall not be called outside admin/prepend.php... 311 * 304 312 * @param dcMenu $menu admin menu instance 305 * 306 * @access public 307 */ 308 public function appendMenu($menu) { 309 foreach ($this->user_prefs as $k => $v) { 310 $menu['Favorites']->addItem( 311 $v['title'], 312 $v['url'], 313 $v['small-icon'], 314 $v['active'], 315 true, 316 $v['id'], 317 $v['class'], 318 true 319 ); 320 } 321 } 322 323 /** 313 * 314 * @access public 315 */ 316 public function appendMenu($menu) 317 { 318 foreach ($this->user_prefs as $k => $v) { 319 $menu['Favorites']->addItem( 320 $v['title'], 321 $v['url'], 322 $v['small-icon'], 323 $v['active'], 324 true, 325 $v['id'], 326 $v['class'], 327 true 328 ); 329 } 330 } 331 332 /** 324 333 * appendDashboardIcons - adds favorites icons to index page 325 *shall not be called outside admin/index.php...326 334 * shall not be called outside admin/index.php... 335 * 327 336 * @param array $icons dashboard icon list to enrich 328 * 329 * @access public 330 */ 331 public function appendDashboardIcons($icons) { 332 foreach ($this->user_prefs as $k => $v) { 333 if (isset($v['dashboard_cb']) && is_callable($v['dashboard_cb'])) { 334 $v = new ArrayObject($v); 335 call_user_func($v['dashboard_cb'],$this->core,$v); 336 } 337 $icons[$k]=new ArrayObject(array($v['title'],$v['url'],$v['large-icon'])); 338 $this->core->callBehavior('adminDashboardFavsIcon',$this->core,$k,$icons[$k]); 339 } 340 } 341 342 /** 337 * 338 * @access public 339 */ 340 public function appendDashboardIcons($icons) 341 { 342 foreach ($this->user_prefs as $k => $v) { 343 if (isset($v['dashboard_cb']) && is_callable($v['dashboard_cb'])) { 344 $v = new ArrayObject($v); 345 call_user_func($v['dashboard_cb'], $this->core, $v); 346 } 347 $icons[$k] = new ArrayObject(array($v['title'], $v['url'], $v['large-icon'])); 348 $this->core->callBehavior('adminDashboardFavsIcon', $this->core, $k, $icons[$k]); 349 } 350 } 351 352 /** 343 353 * register - registers a new favorite definition 344 354 * 345 355 * @param string $id favorite id 346 * @param array $data favorite information. Array keys are : 347 * 'title' => favorite title (localized) 348 * 'url' => favorite URL, 349 * 'small-icon' => favorite small icon (for menu) 350 * 'large-icon' => favorite large icon (for dashboard) 351 * 'permissions' => (optional) comma-separated list of permissions for thie fav, if not set : no restriction 352 * 'dashboard_cb' => (optional) callback to modify title if dynamic, if not set : title is taken as is 353 * 'active_cb' => (optional) callback to tell whether current page matches favorite or not, for complex pages 354 * 355 * @access public 356 */ 357 public function register($id,$data) { 358 $this->fav_defs[$id] = $data; 359 return $this; 360 } 361 362 /** 356 * @param array $data favorite information. Array keys are : 357 * 'title' => favorite title (localized) 358 * 'url' => favorite URL, 359 * 'small-icon' => favorite small icon (for menu) 360 * 'large-icon' => favorite large icon (for dashboard) 361 * 'permissions' => (optional) comma-separated list of permissions for thie fav, if not set : no restriction 362 * 'dashboard_cb' => (optional) callback to modify title if dynamic, if not set : title is taken as is 363 * 'active_cb' => (optional) callback to tell whether current page matches favorite or not, for complex pages 364 * 365 * @access public 366 */ 367 public function register($id, $data) 368 { 369 $this->fav_defs[$id] = $data; 370 return $this; 371 } 372 373 /** 363 374 * registerMultiple - registers a list of favorites definition 364 375 * 365 376 * @param array an array defining all favorites key is the id, value is the data. 366 * see register method for data format 367 * @access public 368 */ 369 public function registerMultiple($data) { 370 foreach ($data as $k => $v) { 371 $this->register($k,$v); 372 } 373 return $this; 374 } 375 376 /** 377 * see register method for data format 378 * @access public 379 */ 380 public function registerMultiple($data) 381 { 382 foreach ($data as $k => $v) { 383 $this->register($k, $v); 384 } 385 return $this; 386 } 387 388 /** 377 389 * exists - tells whether a fav definition exists or not 378 390 * 379 391 * @param string $id : the fav id to test 380 * 381 * @access public 382 * 383 * @return true if the fav definition exists, false otherwise 384 */ 385 public function exists($id) { 386 return isset($this->fav_defs[$id]); 387 } 392 * 393 * @access public 394 * 395 * @return true if the fav definition exists, false otherwise 396 */ 397 public function exists($id) 398 { 399 return isset($this->fav_defs[$id]); 400 } 388 401 389 402 } 390 403 391 392 404 /** 393 * defaultFavorites -- default favorites definition394 *395 */405 * defaultFavorites -- default favorites definition 406 * 407 */ 396 408 class defaultFavorites 397 409 { 398 public static function initDefaultFavorites($favs) { 399 $core =& $GLOBALS['core']; 400 $favs->registerMultiple(array( 401 'prefs' => array( 402 'title' => __('My preferences'), 403 'url' => $core->adminurl->get("admin.user.preferences"), 404 'small-icon' => 'images/menu/user-pref.png', 405 'large-icon' => 'images/menu/user-pref-b.png'), 406 'new_post' => array( 407 'title' => __('New entry'), 408 'url' => $core->adminurl->get("admin.post"), 409 'small-icon' => 'images/menu/edit.png', 410 'large-icon' => 'images/menu/edit-b.png', 411 'permissions' =>'usage,contentadmin'), 412 'posts' => array( 413 'title' => __('Posts'), 414 'url' => $core->adminurl->get("admin.posts"), 415 'small-icon' => 'images/menu/entries.png', 416 'large-icon' => 'images/menu/entries-b.png', 417 'permissions' => 'usage,contentadmin', 418 'dashboard_cb' => array('defaultFavorites','postsDashboard')), 419 'comments' => array( 420 'title' => __('Comments'), 421 'url' => $core->adminurl->get("admin.comments"), 422 'small-icon' => 'images/menu/comments.png', 423 'large-icon' => 'images/menu/comments-b.png', 424 'permissions' => 'usage,contentadmin', 425 'dashboard_cb' => array('defaultFavorites','commentsDashboard')), 426 'search' => array( 427 'title' => __('Search'), 428 'url' => $core->adminurl->get("admin.search"), 429 'small-icon' => 'images/menu/search.png', 430 'large-icon' => 'images/menu/search-b.png', 431 'permissions' => 'usage,contentadmin'), 432 'categories' => array( 433 'title' => __('Categories'), 434 'url' => $core->adminurl->get("admin.categories"), 435 'small-icon' => 'images/menu/categories.png', 436 'large-icon' => 'images/menu/categories-b.png', 437 'permissions' =>'categories'), 438 'media' => array( 439 'title' => __('Media manager'), 440 'url' => $core->adminurl->get("admin.media"), 441 'small-icon' => 'images/menu/media.png', 442 'large-icon' => 'images/menu/media-b.png', 443 'permissions' => 'media,media_admin'), 444 'blog_pref' => array( 445 'title' => __('Blog settings'), 446 'url' => $core->adminurl->get("admin.blog.pref"), 447 'small-icon' => 'images/menu/blog-pref.png', 448 'large-icon' => 'images/menu/blog-pref-b.png', 449 'permissions' => 'admin'), 450 'blog_theme' => array( 451 'title' => __('Blog appearance'), 452 'url' => $core->adminurl->get("admin.blog.theme"), 453 'small-icon' => 'images/menu/themes.png', 454 'large-icon' => 'images/menu/blog-theme-b.png', 455 'permissions' => 'admin'), 456 'blogs' => array( 457 'title' => __('Blogs'), 458 'url' => $core->adminurl->get("admin.blogs"), 459 'small-icon' => 'images/menu/blogs.png', 460 'large-icon' => 'images/menu/blogs-b.png', 461 'permissions' =>'usage,contentadmin'), 462 'users' => array( 463 'title' => __('Users'), 464 'url' => $core->adminurl->get("admin.users"), 465 'small-icon' => 'images/menu/users.png', 466 'large-icon' => 'images/menu/users-b.png'), 467 'plugins' => array( 468 'title' => __('Plugins management'), 469 'url' => $core->adminurl->get("admin.plugins"), 470 'small-icon' => 'images/menu/plugins.png', 471 'large-icon' => 'images/menu/plugins-b.png'), 472 'langs' => array( 473 'title' => __('Languages'), 474 'url' => $core->adminurl->get("admin.langs"), 475 'small-icon' => 'images/menu/langs.png', 476 'large-icon' => 'images/menu/langs-b.png'), 477 'help' => array( 478 'title' => __('Global help'), 479 'url' => $core->adminurl->get("admin.help"), 480 'small-icon' => 'images/menu/help.png', 481 'large-icon' => 'images/menu/help-b.png') 482 )); 483 } 484 485 public static function postsDashboard($core,$v) 486 { 487 $post_count = $core->blog->getPosts(array(),true)->f(0); 488 $str_entries = __('%d post', '%d posts',$post_count); 489 $v['title'] = sprintf($str_entries,$post_count); 490 } 491 492 public static function commentsDashboard($core,$v) 493 { 494 $comment_count = $core->blog->getComments(array(),true)->f(0); 495 $str_comments = __('%d comment', '%d comments',$comment_count); 496 $v['title']= sprintf($str_comments,$comment_count); 497 } 410 public static function initDefaultFavorites($favs) 411 { 412 $core = &$GLOBALS['core']; 413 $favs->registerMultiple(array( 414 'prefs' => array( 415 'title' => __('My preferences'), 416 'url' => $core->adminurl->get("admin.user.preferences"), 417 'small-icon' => 'images/menu/user-pref.png', 418 'large-icon' => 'images/menu/user-pref-b.png'), 419 'new_post' => array( 420 'title' => __('New entry'), 421 'url' => $core->adminurl->get("admin.post"), 422 'small-icon' => 'images/menu/edit.png', 423 'large-icon' => 'images/menu/edit-b.png', 424 'permissions' => 'usage,contentadmin'), 425 'posts' => array( 426 'title' => __('Posts'), 427 'url' => $core->adminurl->get("admin.posts"), 428 'small-icon' => 'images/menu/entries.png', 429 'large-icon' => 'images/menu/entries-b.png', 430 'permissions' => 'usage,contentadmin', 431 'dashboard_cb' => array('defaultFavorites', 'postsDashboard')), 432 'comments' => array( 433 'title' => __('Comments'), 434 'url' => $core->adminurl->get("admin.comments"), 435 'small-icon' => 'images/menu/comments.png', 436 'large-icon' => 'images/menu/comments-b.png', 437 'permissions' => 'usage,contentadmin', 438 'dashboard_cb' => array('defaultFavorites', 'commentsDashboard')), 439 'search' => array( 440 'title' => __('Search'), 441 'url' => $core->adminurl->get("admin.search"), 442 'small-icon' => 'images/menu/search.png', 443 'large-icon' => 'images/menu/search-b.png', 444 'permissions' => 'usage,contentadmin'), 445 'categories' => array( 446 'title' => __('Categories'), 447 'url' => $core->adminurl->get("admin.categories"), 448 'small-icon' => 'images/menu/categories.png', 449 'large-icon' => 'images/menu/categories-b.png', 450 'permissions' => 'categories'), 451 'media' => array( 452 'title' => __('Media manager'), 453 'url' => $core->adminurl->get("admin.media"), 454 'small-icon' => 'images/menu/media.png', 455 'large-icon' => 'images/menu/media-b.png', 456 'permissions' => 'media,media_admin'), 457 'blog_pref' => array( 458 'title' => __('Blog settings'), 459 'url' => $core->adminurl->get("admin.blog.pref"), 460 'small-icon' => 'images/menu/blog-pref.png', 461 'large-icon' => 'images/menu/blog-pref-b.png', 462 'permissions' => 'admin'), 463 'blog_theme' => array( 464 'title' => __('Blog appearance'), 465 'url' => $core->adminurl->get("admin.blog.theme"), 466 'small-icon' => 'images/menu/themes.png', 467 'large-icon' => 'images/menu/blog-theme-b.png', 468 'permissions' => 'admin'), 469 'blogs' => array( 470 'title' => __('Blogs'), 471 'url' => $core->adminurl->get("admin.blogs"), 472 'small-icon' => 'images/menu/blogs.png', 473 'large-icon' => 'images/menu/blogs-b.png', 474 'permissions' => 'usage,contentadmin'), 475 'users' => array( 476 'title' => __('Users'), 477 'url' => $core->adminurl->get("admin.users"), 478 'small-icon' => 'images/menu/users.png', 479 'large-icon' => 'images/menu/users-b.png'), 480 'plugins' => array( 481 'title' => __('Plugins management'), 482 'url' => $core->adminurl->get("admin.plugins"), 483 'small-icon' => 'images/menu/plugins.png', 484 'large-icon' => 'images/menu/plugins-b.png'), 485 'langs' => array( 486 'title' => __('Languages'), 487 'url' => $core->adminurl->get("admin.langs"), 488 'small-icon' => 'images/menu/langs.png', 489 'large-icon' => 'images/menu/langs-b.png'), 490 'help' => array( 491 'title' => __('Global help'), 492 'url' => $core->adminurl->get("admin.help"), 493 'small-icon' => 'images/menu/help.png', 494 'large-icon' => 'images/menu/help-b.png') 495 )); 496 } 497 498 public static function postsDashboard($core, $v) 499 { 500 $post_count = $core->blog->getPosts(array(), true)->f(0); 501 $str_entries = __('%d post', '%d posts', $post_count); 502 $v['title'] = sprintf($str_entries, $post_count); 503 } 504 505 public static function commentsDashboard($core, $v) 506 { 507 $comment_count = $core->blog->getComments(array(), true)->f(0); 508 $str_comments = __('%d comment', '%d comments', $comment_count); 509 $v['title'] = sprintf($str_comments, $comment_count); 510 } 498 511 } -
inc/admin/class.dc.menu.php
r3075 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 class dcMenu 15 15 { 16 17 16 private $id; 17 public $title; 18 18 19 public function __construct($id,$title,$itemSpace='')20 21 $this->id= $id;22 $this->title= $title;23 24 $this->pinned= array();25 $this->items= array();26 19 public function __construct($id, $title, $itemSpace = '') 20 { 21 $this->id = $id; 22 $this->title = $title; 23 $this->itemSpace = $itemSpace; 24 $this->pinned = array(); 25 $this->items = array(); 26 } 27 27 28 public function addItem($title,$url,$img,$active,$show=true,$id=null,$class=null,$pinned=false)29 30 if($show) {31 $item = $this->itemDef($title,$url,$img,$active,$id,$class);32 33 34 35 36 37 38 28 public function addItem($title, $url, $img, $active, $show = true, $id = null, $class = null, $pinned = false) 29 { 30 if ($show) { 31 $item = $this->itemDef($title, $url, $img, $active, $id, $class); 32 if ($pinned) { 33 $this->pinned[] = $item; 34 } else { 35 $this->items[$title] = $item; 36 } 37 } 38 } 39 39 40 public function prependItem($title,$url,$img,$active,$show=true,$id=null,$class=null,$pinned=false)41 42 43 $item = $this->itemDef($title,$url,$img,$active,$id,$class);44 45 array_unshift($this->pinned,$item);46 47 48 49 50 40 public function prependItem($title, $url, $img, $active, $show = true, $id = null, $class = null, $pinned = false) 41 { 42 if ($show) { 43 $item = $this->itemDef($title, $url, $img, $active, $id, $class); 44 if ($pinned) { 45 array_unshift($this->pinned, $item); 46 } else { 47 $this->items[$title] = $item; 48 } 49 } 50 } 51 51 52 53 54 55 56 52 public function draw() 53 { 54 if (count($this->items) + count($this->pinned) == 0) { 55 return ''; 56 } 57 57 58 59 '<div id="'.$this->id.'">'.60 ($this->title ? '<h3>'.$this->title.'</h3>' : '').61 '<ul>'."\n";58 $res = 59 '<div id="' . $this->id . '">' . 60 ($this->title ? '<h3>' . $this->title . '</h3>' : '') . 61 '<ul>' . "\n"; 62 62 63 // 1. Display pinned items (unsorted) 64 for ($i=0; $i<count($this->pinned); $i++) 65 { 66 if ($i+1 < count($this->pinned) && $this->itemSpace != '') { 67 $res .= preg_replace('|</li>$|',$this->itemSpace.'</li>',$this->pinned[$i]); 68 $res .= "\n"; 69 } else { 70 $res .= $this->pinned[$i]."\n"; 71 } 72 } 63 // 1. Display pinned items (unsorted) 64 for ($i = 0; $i < count($this->pinned); $i++) { 65 if ($i + 1 < count($this->pinned) && $this->itemSpace != '') { 66 $res .= preg_replace('|</li>$|', $this->itemSpace . '</li>', $this->pinned[$i]); 67 $res .= "\n"; 68 } else { 69 $res .= $this->pinned[$i] . "\n"; 70 } 71 } 73 72 74 // 2. Display unpinned itmes (sorted) 75 $i = 0; 76 dcUtils::lexicalKeySort($this->items); 77 foreach ($this->items as $title => $item) 78 { 79 if ($i+1 < count($this->items) && $this->itemSpace != '') { 80 $res .= preg_replace('|</li>$|',$this->itemSpace.'</li>',$item); 81 $res .= "\n"; 82 } else { 83 $res .= $item."\n"; 84 } 85 $i++; 86 } 73 // 2. Display unpinned itmes (sorted) 74 $i = 0; 75 dcUtils::lexicalKeySort($this->items); 76 foreach ($this->items as $title => $item) { 77 if ($i + 1 < count($this->items) && $this->itemSpace != '') { 78 $res .= preg_replace('|</li>$|', $this->itemSpace . '</li>', $item); 79 $res .= "\n"; 80 } else { 81 $res .= $item . "\n"; 82 } 83 $i++; 84 } 87 85 88 $res .= '</ul></div>'."\n";86 $res .= '</ul></div>' . "\n"; 89 87 90 91 88 return $res; 89 } 92 90 93 protected function itemDef($title,$url,$img,$active,$id=null,$class=null)94 95 96 $link= $url[0];97 $ahtml = (!empty($url[1])) ? ' '.$url[1] : '';98 99 $link= $url;100 101 91 protected function itemDef($title, $url, $img, $active, $id = null, $class = null) 92 { 93 if (is_array($url)) { 94 $link = $url[0]; 95 $ahtml = (!empty($url[1])) ? ' ' . $url[1] : ''; 96 } else { 97 $link = $url; 98 $ahtml = ''; 99 } 102 100 103 101 $img = dc_admin_icon_url($img); 104 102 105 106 '<li'.(($active || $class) ? ' class="'.(($active) ? 'active ' : '').(($class) ? $class : '').'"' : '').107 (($id) ? ' id="'.$id.'"' : '').108 (($img) ? ' style="background-image: url('.$img.');"' : '').109 '>'.103 return 104 '<li' . (($active || $class) ? ' class="' . (($active) ? 'active ' : '') . (($class) ? $class : '') . '"' : '') . 105 (($id) ? ' id="' . $id . '"' : '') . 106 (($img) ? ' style="background-image: url(' . $img . ');"' : '') . 107 '>' . 110 108 111 '<a href="'.$link.'"'.$ahtml.'>'.$title.'</a></li>'."\n";112 109 '<a href="' . $link . '"' . $ahtml . '>' . $title . '</a></li>' . "\n"; 110 } 113 111 } -
inc/admin/lib.admincombos.php
r3206 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 /** 14 14 @ingroup DC_CORE … … 18 18 Dotclear utility class that provides reuseable combos across all admin 19 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 str_repeat(' ',($categories->level-1)*4). 40 html::escapeHTML($categories->cat_title).' ('.$categories->nb_post.')', 41 ($use_url ? $categories->cat_url : $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 editors in admin 145 146 @return <b>array</b> the combo box (form::combo -compatible format) 147 */ 148 public static function getEditorsCombo() 149 { 150 $editors_combo = array(); 151 152 foreach (self::$core->getEditors() as $v) { 153 $editors_combo[$v] = $v; 154 } 155 156 return $editors_combo; 157 } 158 159 /** 160 Returns a combo containing all available formaters by editor in admin 161 162 @param editor_id <b>string</b> Editor id (dcLegacyEditor, dcCKEditor, ...) 163 @return <b>array</b> the combo box (form::combo -compatible format) 164 */ 165 public static function getFormatersCombo($editor_id='') 166 { 167 $formaters_combo = array(); 20 */ 21 class dcAdminCombos 22 { 23 24 /** @var dcCore dcCore instance */ 25 public static $core; 26 27 /** 28 Returns an hierarchical categories combo from a category record 29 30 @param categories <b>record</b> the category record 31 @return <b>array</b> the combo box (form::combo -compatible format) 32 */ 33 public static function getCategoriesCombo($categories, $include_empty = true, $use_url = false) 34 { 35 $categories_combo = array(); 36 if ($include_empty) { 37 $categories_combo = array(new formSelectOption(__('(No cat)'), '')); 38 } 39 while ($categories->fetch()) { 40 $categories_combo[] = new formSelectOption( 41 str_repeat(' ', ($categories->level - 1) * 4) . 42 html::escapeHTML($categories->cat_title) . ' (' . $categories->nb_post . ')', 43 ($use_url ? $categories->cat_url : $categories->cat_id), 44 ($categories->level - 1 ? 'sub-option' . ($categories->level - 1) : '') 45 ); 46 } 47 return $categories_combo; 48 } 49 50 /** 51 Returns available post status combo 52 53 @return <b>array</b> the combo box (form::combo -compatible format) 54 */ 55 public static function getPostStatusesCombo() 56 { 57 $status_combo = array(); 58 foreach (self::$core->blog->getAllPostStatus() as $k => $v) { 59 $status_combo[$v] = (string) $k; 60 } 61 return $status_combo; 62 } 63 64 /** 65 Returns an users combo from a users record 66 67 @param users <b>record</b> the users record 68 @return <b>array</b> the combo box (form::combo -compatible format) 69 */ 70 public static function getUsersCombo($users) 71 { 72 $users_combo = array(); 73 while ($users->fetch()) { 74 $user_cn = dcUtils::getUserCN($users->user_id, $users->user_name, 75 $users->user_firstname, $users->user_displayname); 76 77 if ($user_cn != $users->user_id) { 78 $user_cn .= ' (' . $users->user_id . ')'; 79 } 80 81 $users_combo[$user_cn] = $users->user_id; 82 } 83 return $users_combo; 84 } 85 86 /** 87 Returns an date combo from a date record 88 89 @param dates <b>record</b> the dates record 90 @return <b>array</b> the combo box (form::combo -compatible format) 91 */ 92 public static function getDatesCombo($dates) 93 { 94 $dt_m_combo = array(); 95 while ($dates->fetch()) { 96 $dt_m_combo[dt::str('%B %Y', $dates->ts())] = $dates->year() . $dates->month(); 97 } 98 return $dt_m_combo; 99 } 100 101 /** 102 Returns an lang combo from a lang record 103 104 @param langs <b>record</b> the langs record 105 @param with_available <b>boolean</b> if false, only list items from record 106 if true, also list available languages 107 @return <b>array</b> the combo box (form::combo -compatible format) 108 */ 109 public static function getLangsCombo($langs, $with_available = false) 110 { 111 $all_langs = l10n::getISOcodes(0, 1); 112 if ($with_available) { 113 $langs_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1, 1)); 114 while ($langs->fetch()) { 115 if (isset($all_langs[$langs->post_lang])) { 116 $langs_combo[__('Most used')][$all_langs[$langs->post_lang]] = $langs->post_lang; 117 unset($langs_combo[__('Available')][$all_langs[$langs->post_lang]]); 118 } else { 119 $langs_combo[__('Most used')][$langs->post_lang] = $langs->post_lang; 120 } 121 } 122 } else { 123 $langs_combo = array(); 124 while ($langs->fetch()) { 125 $lang_name = isset($all_langs[$langs->post_lang]) ? $all_langs[$langs->post_lang] : $langs->post_lang; 126 $langs_combo[$lang_name] = $langs->post_lang; 127 } 128 } 129 unset($all_langs); 130 return $langs_combo; 131 } 132 133 /** 134 Returns a combo containing all available and installed languages for administration pages 135 136 @return <b>array</b> the combo box (form::combo -compatible format) 137 */ 138 public static function getAdminLangsCombo() 139 { 140 $lang_combo = array(); 141 $langs = l10n::getISOcodes(1, 1); 142 foreach ($langs as $k => $v) { 143 $lang_avail = $v == 'en' || is_dir(DC_L10N_ROOT . '/' . $v); 144 $lang_combo[] = new formSelectOption($k, $v, $lang_avail ? 'avail10n' : ''); 145 } 146 return $lang_combo; 147 } 148 149 /** 150 Returns a combo containing all available editors in admin 151 152 @return <b>array</b> the combo box (form::combo -compatible format) 153 */ 154 public static function getEditorsCombo() 155 { 156 $editors_combo = array(); 157 158 foreach (self::$core->getEditors() as $v) { 159 $editors_combo[$v] = $v; 160 } 161 162 return $editors_combo; 163 } 164 165 /** 166 Returns a combo containing all available formaters by editor in admin 167 168 @param editor_id <b>string</b> Editor id (dcLegacyEditor, dcCKEditor, ...) 169 @return <b>array</b> the combo box (form::combo -compatible format) 170 */ 171 public static function getFormatersCombo($editor_id = '') 172 { 173 $formaters_combo = array(); 168 174 169 175 if (!empty($editor_id)) { … … 179 185 } 180 186 181 return $formaters_combo; 182 } 183 184 /** 185 Returns a combo containing available blog statuses 186 187 @return <b>array</b> the combo box (form::combo -compatible format) 188 */ 189 public static function getBlogStatusesCombo() { 190 $status_combo = array(); 191 foreach (self::$core->getAllBlogStatus() as $k => $v) { 192 $status_combo[$v] = (string) $k; 193 } 194 return $status_combo; 195 } 196 197 /** 198 Returns a combo containing available comment statuses 199 200 @return <b>array</b> the combo box (form::combo -compatible format) 201 */ 202 public static function getCommentStatusescombo() { 203 $status_combo = array(); 204 foreach (self::$core->blog->getAllCommentStatus() as $k => $v) { 205 $status_combo[$v] = (string) $k; 206 } 207 return $status_combo; 208 } 187 return $formaters_combo; 188 } 189 190 /** 191 Returns a combo containing available blog statuses 192 193 @return <b>array</b> the combo box (form::combo -compatible format) 194 */ 195 public static function getBlogStatusesCombo() 196 { 197 $status_combo = array(); 198 foreach (self::$core->getAllBlogStatus() as $k => $v) { 199 $status_combo[$v] = (string) $k; 200 } 201 return $status_combo; 202 } 203 204 /** 205 Returns a combo containing available comment statuses 206 207 @return <b>array</b> the combo box (form::combo -compatible format) 208 */ 209 public static function getCommentStatusescombo() 210 { 211 $status_combo = array(); 212 foreach (self::$core->blog->getAllCommentStatus() as $k => $v) { 213 $status_combo[$v] = (string) $k; 214 } 215 return $status_combo; 216 } 209 217 } 210 218 dcAdminCombos::$core = $GLOBALS['core']; -
inc/admin/lib.dc.adminurl.php
r2921 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_RC_PATH')) { return;}12 if (!defined('DC_RC_PATH')) {return;} 13 13 14 14 /** … … 17 17 @brief URL Handler for admin urls 18 18 19 */19 */ 20 20 class dcAdminURL 21 21 { 22 23 24 22 /** @var dcCore dcCore instance */ 23 protected $core; 24 protected $urls; 25 25 26 27 26 /** 27 Inits dcAdminURL object 28 28 29 @param core <b>dcCore</b>Dotclear core reference30 31 32 33 34 35 29 @param core <b>dcCore</b> Dotclear core reference 30 */ 31 public function __construct($core) 32 { 33 $this->core = $core; 34 $this->urls = new ArrayObject(); 35 } 36 36 37 38 39 40 41 42 43 public function register($name,$url,$params=array())44 45 46 37 /** 38 * Registers a new url 39 * @param string $name the url name 40 * @param string $url url value 41 * @param array $params query string params (optional) 42 */ 43 public function register($name, $url, $params = array()) 44 { 45 $this->urls[$name] = array('url' => $url, 'qs' => $params); 46 } 47 47 48 49 50 51 52 53 54 55 public function registercopy($name,$orig,$params=array(),$newurl='')56 57 58 throw new exception ('Unknown URL handler for '.$orig);59 60 $url= $this->urls[$orig];61 $url['qs'] = array_merge($url['qs'],$params);62 63 64 65 66 48 /** 49 * Registers a new url as a copy of an existing one 50 * @param string $name url name 51 * @param streing $orig url to copy information from 52 * @param array $params extra parameters to add 53 * @param string $newurl new url if different from the original 54 */ 55 public function registercopy($name, $orig, $params = array(), $newurl = '') 56 { 57 if (!isset($this->urls[$orig])) { 58 throw new exception('Unknown URL handler for ' . $orig); 59 } 60 $url = $this->urls[$orig]; 61 $url['qs'] = array_merge($url['qs'], $params); 62 if ($newurl != '') { 63 $url['url'] = $newurl; 64 } 65 $this->urls[$name] = $url; 66 } 67 67 68 69 70 71 72 73 74 75 76 77 78 public function get($name,$params=array(),$separator='&',$parametric=false)79 80 81 throw new exception ('Unknown URL handler for '.$name);82 83 84 $p = array_merge($url['qs'],$params);85 $u= $url['url'];86 87 $u .= '?'.http_build_query($p,'',$separator);88 89 90 91 $u = preg_replace('/\%25(([0-9])+?\%24)*?s/','%$2s',$u);92 93 94 68 /** 69 * retrieves a URL given its name, and optional parameters 70 * 71 * @param string $name URL Name 72 * @param array $params query string parameters, given as an associative array 73 * @param boolean $urlencode set to true if url may not be encoded 74 * @param string $separator separator to use between QS parameters 75 * @param boolean $parametric set to true if url will be used as (s)printf() format. 76 * @return string the forged url 77 */ 78 public function get($name, $params = array(), $separator = '&', $parametric = false) 79 { 80 if (!isset($this->urls[$name])) { 81 throw new exception('Unknown URL handler for ' . $name); 82 } 83 $url = $this->urls[$name]; 84 $p = array_merge($url['qs'], $params); 85 $u = $url['url']; 86 if (!empty($p)) { 87 $u .= '?' . http_build_query($p, '', $separator); 88 } 89 if ($parametric) { 90 // Dirty hack to get back %[n$]s instead of %25[{0..9}%24]s in URLs used with (s)printf(), as http_build_query urlencode() its result. 91 $u = preg_replace('/\%25(([0-9])+?\%24)*?s/', '%$2s', $u); 92 } 93 return $u; 94 } 95 95 96 97 98 99 100 101 102 103 104 105 public function redirect($name,$params=array(),$suffix="")106 107 108 throw new exception ('Unknown URL handler for '.$name);109 110 http::redirect($this->get($name,$params,'&').$suffix);111 96 /** 97 * retrieves a URL given its name, and optional parameters 98 * 99 * @param string $name URL Name 100 * @param array $params query string parameters, given as an associative array 101 * @param boolean $urlencode set to true if url may not be encoded 102 * @param string $suffix suffix to be added to the QS parameters 103 * @return string the forged url 104 */ 105 public function redirect($name, $params = array(), $suffix = "") 106 { 107 if (!isset($this->urls[$name])) { 108 throw new exception('Unknown URL handler for ' . $name); 109 } 110 http::redirect($this->get($name, $params, '&') . $suffix); 111 } 112 112 113 114 115 116 117 118 119 120 121 122 123 throw new exception ('Unknown URL handler for '.$name);124 125 126 113 /** 114 * retrieves a php page given its name, and optional parameters 115 * acts like get, but without the query string, should be used within forms actions 116 * 117 * @param string $name URL Name 118 * @return string the forged url 119 */ 120 public function getBase($name) 121 { 122 if (!isset($this->urls[$name])) { 123 throw new exception('Unknown URL handler for ' . $name); 124 } 125 return $this->urls[$name]['url']; 126 } 127 127 128 129 130 131 132 133 134 135 136 public function getHiddenFormFields($name,$params=array())137 138 139 throw new exception ('Unknown URL handler for '.$name);140 141 142 $p = array_merge($url['qs'],$params);143 144 foreach ((array)$p as $k => $v) {145 $str .= form::hidden(array($k),$v);146 147 148 128 /** 129 * forges form hidden fields to pass to a generated <form>. Should be used in combination with 130 * form action retrieved from getBase() 131 * 132 * @param string $name URL Name 133 * @param array $params query string parameters, given as an associative array 134 * @return string the forged form data 135 */ 136 public function getHiddenFormFields($name, $params = array()) 137 { 138 if (!isset($this->urls[$name])) { 139 throw new exception('Unknown URL handler for ' . $name); 140 } 141 $url = $this->urls[$name]; 142 $p = array_merge($url['qs'], $params); 143 $str = ''; 144 foreach ((array) $p as $k => $v) { 145 $str .= form::hidden(array($k), $v); 146 } 147 return $str; 148 } 149 149 150 151 152 153 * @deprecatedshould be used carefully, parameters are no more escaped154 155 156 157 158 159 160 public function decode($name,$params=array(),$separator='&')161 162 return urldecode($this->get($name,$params,false,$separator));163 150 /** 151 * retrieves a URL (decoded — useful for echoing) given its name, and optional parameters 152 * 153 * @deprecated should be used carefully, parameters are no more escaped 154 * 155 * @param string $name URL Name 156 * @param array $params query string parameters, given as an associative array 157 * @param string $separator separator to use between QS parameters 158 * @return string the forged decoded url 159 */ 160 public function decode($name, $params = array(), $separator = '&') 161 { 162 return urldecode($this->get($name, $params, false, $separator)); 163 } 164 164 165 166 167 168 169 170 171 172 173 165 /** 166 * Returns $urls property content. 167 * 168 * @return ArrayObject 169 */ 170 public function dumpUrls() 171 { 172 return $this->urls; 173 } 174 174 } -
inc/admin/lib.themeconfig.php
r3340 r3730 10 10 # 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 if (!defined('DC_ADMIN_CONTEXT')) { return;}12 if (!defined('DC_ADMIN_CONTEXT')) {return;} 13 13 14 14 /** … … 30 30 * @return float computed ratio 31 31 */ 32 public static function computeContrastRatio($color,$background) 33 { 34 // Compute contrast ratio between two colors 35 36 $color = self::adjustColor($color); 37 if (($color == '') || (strlen($color) != 7)) return 0; 38 $background = self::adjustColor($background); 39 if (($background == '') || (strlen($background) != 7)) return 0; 40 41 $l1 = (0.2126 * pow(hexdec(substr($color,1,2))/255,2.2)) + 42 (0.7152 * pow(hexdec(substr($color,3,2))/255,2.2)) + 43 (0.0722 * pow(hexdec(substr($color,5,2))/255,2.2)); 44 45 $l2 = (0.2126 * pow(hexdec(substr($background,1,2))/255,2.2)) + 46 (0.7152 * pow(hexdec(substr($background,3,2))/255,2.2)) + 47 (0.0722 * pow(hexdec(substr($background,5,2))/255,2.2)); 48 49 if ($l1 > $l2) { 50 $ratio = ($l1 + 0.05) / ($l2 + 0.05); 51 } else { 52 $ratio = ($l2 + 0.05) / ($l1 + 0.05); 53 } 54 return $ratio; 55 } 32 public static function computeContrastRatio($color, $background) 33 { 34 // Compute contrast ratio between two colors 35 36 $color = self::adjustColor($color); 37 if (($color == '') || (strlen($color) != 7)) { 38 return 0; 39 } 40 41 $background = self::adjustColor($background); 42 if (($background == '') || (strlen($background) != 7)) { 43 return 0; 44 } 45 46 $l1 = (0.2126 * pow(hexdec(substr($color, 1, 2)) / 255, 2.2)) + 47 (0.7152 * pow(hexdec(substr($color, 3, 2)) / 255, 2.2)) + 48 (0.0722 * pow(hexdec(substr($color, 5, 2)) / 255, 2.2)); 49 50 $l2 = (0.2126 * pow(hexdec(substr($background, 1, 2)) / 255, 2.2)) + 51 (0.7152 * pow(hexdec(substr($background, 3, 2)) / 255, 2.2)) + 52 (0.0722 * pow(hexdec(substr($background, 5, 2)) / 255, 2.2)); 53 54 if ($l1 > $l2) { 55 $ratio = ($l1 + 0.05) / ($l2 + 0.05); 56 } else { 57 $ratio = ($l2 + 0.05) / ($l1 + 0.05); 58 } 59 return $ratio; 60 } 56 61 57 62 /** … … 64 69 * @return string WCAG contrast ratio level (AAA, AA or <nothing>) 65 70 */ 66 public static function contrastRatioLevel($ratio,$size,$bold=false)67 68 69 70 71 72 73 if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex|rem)?$/',$size,$m)) {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 71 public static function contrastRatioLevel($ratio, $size, $bold = false) 72 { 73 if ($size == '') { 74 return ''; 75 } 76 77 // Eval font size in em (assume base font size in pixels equal to 16) 78 if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex|rem)?$/', $size, $m)) { 79 if (empty($m[2])) { 80 $m[2] = 'em'; 81 } 82 } else { 83 return ''; 84 } 85 switch ($m[2]) { 86 case '%': 87 $s = (float) $m[1] / 100; 88 break; 89 case 'pt': 90 $s = (float) $m[1] / 12; 91 break; 92 case 'px': 93 $s = (float) $m[1] / 16; 94 break; 95 case 'em': 96 $s = (float) $m[1]; 97 break; 98 case 'ex': 99 $s = (float) $m[1] / 2; 100 break; 101 default: 102 return ''; 103 } 104 105 $large = ((($s > 1.5) && ($bold == false)) || (($s > 1.2) && ($bold == true))); 106 107 // Check ratio 108 if ($ratio > 7) { 109 return 'AAA'; 110 } elseif (($ratio > 4.5) && $large) { 111 return 'AAA'; 112 } elseif ($ratio > 4.5) { 113 return 'AA'; 114 } elseif (($ratio > 3) && $large) { 115 return 'AA'; 116 } 117 return ''; 118 } 114 119 115 120 /** … … 123 128 * @return string contrast ratio including WCAG level 124 129 */ 125 public static function contrastRatio($color,$background,$size='',$bold=false)126 127 128 $ratio = self::computeContrastRatio($color,$background);129 $level = self::contrastRatioLevel($ratio,$size,$bold);130 131 sprintf(__('ratio %.1f'),$ratio).132 ($level != '' ? ' '.sprintf(__('(%s)'),$level) : '');133 134 135 130 public static function contrastRatio($color, $background, $size = '', $bold = false) 131 { 132 if (($color != '') && ($background != '')) { 133 $ratio = self::computeContrastRatio($color, $background); 134 $level = self::contrastRatioLevel($ratio, $size, $bold); 135 return 136 sprintf(__('ratio %.1f'), $ratio) . 137 ($level != '' ? ' ' . sprintf(__('(%s)'), $level) : ''); 138 } 139 return ''; 140 } 136 141 137 142 /** … … 142 147 * @return string checked font size 143 148 */ 144 145 146 if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex|rem)?$/',$s,$m)) {147 148 149 150 return $m[1].$m[2];151 152 return null;153 149 public static function adjustFontSize($s) 150 { 151 if (preg_match('/^([0-9.]+)\s*(%|pt|px|em|ex|rem)?$/', $s, $m)) { 152 if (empty($m[2])) { 153 $m[2] = 'em'; 154 } 155 return $m[1] . $m[2]; 156 } 157 return; 158 } 154 159 155 160 /** … … 160 165 * @return string checked position 161 166 */ 162 163 164 if (!preg_match('/^[0-9]+(:[0-9]+)?$/',$p)) {165 return null;166 167 $p = explode(':',$p);168 169 return $p[0].(count($p) == 1 ? ':0' : ':'.$p[1]);170 167 public static function adjustPosition($p) 168 { 169 if (!preg_match('/^[0-9]+(:[0-9]+)?$/', $p)) { 170 return; 171 } 172 $p = explode(':', $p); 173 174 return $p[0] . (count($p) == 1 ? ':0' : ':' . $p[1]); 175 } 171 176 172 177 /** … … 177 182 * @return string checked CSS color 178 183 */ 179 180 181 182 183 184 185 186 187 if (preg_match('/^[A-F0-9]{3,6}$/',$c)) {188 $c = '#'.$c;189 190 if (preg_match('/^#[A-F0-9]{6}$/',$c)) {191 192 193 if (preg_match('/^#[A-F0-9]{3,}$/',$c)) {194 return '#'.substr($c,1,1).substr($c,1,1).substr($c,2,1).substr($c,2,1).substr($c,3,1).substr($c,3,1);195 196 197 198 184 public static function adjustColor($c) 185 { 186 if ($c === '') { 187 return ''; 188 } 189 190 $c = strtoupper($c); 191 192 if (preg_match('/^[A-F0-9]{3,6}$/', $c)) { 193 $c = '#' . $c; 194 } 195 if (preg_match('/^#[A-F0-9]{6}$/', $c)) { 196 return $c; 197 } 198 if (preg_match('/^#[A-F0-9]{3,}$/', $c)) { 199 return '#' . substr($c, 1, 1) . substr($c, 1, 1) . substr($c, 2, 1) . substr($c, 2, 1) . substr($c, 3, 1) . substr($c, 3, 1); 200 } 201 202 return ''; 203 } 199 204 200 205 /** … … 205 210 * @return string checked CSS 206 211 */ 207 208 209 210 211 212 public static function cleanCSS($css) 213 { 214 // TODO ? 215 return $css; 216 } 212 217 213 218 /** … … 218 223 * @return string real path of CSS 219 224 */ 220 221 222 223 return path::real($core->blog->public_path).'/'.$folder;224 225 public static function cssPath($folder) 226 { 227 global $core; 228 return path::real($core->blog->public_path) . '/' . $folder; 229 } 225 230 226 231 /** … … 231 236 * @return string CSS URL 232 237 */ 233 234 235 236 return $core->blog->settings->system->public_url.'/'.$folder;237 238 public static function cssURL($folder) 239 { 240 global $core; 241 return $core->blog->settings->system->public_url . '/' . $folder; 242 } 238 243 239 244 /** … … 245 250 * @return boolean true if CSS folder exists and may be written, else false 246 251 */ 247 public static function canWriteCss($folder,$create=false)248 249 250 251 252 $css= self::cssPath($folder);253 254 255 256 257 258 259 260 261 $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public'));262 263 264 265 266 267 268 269 270 271 $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public/'.$folder));272 273 274 275 276 252 public static function canWriteCss($folder, $create = false) 253 { 254 global $core; 255 256 $public = path::real($core->blog->public_path); 257 $css = self::cssPath($folder); 258 259 if (!is_dir($public)) { 260 $core->error->add(__('The \'public\' directory does not exist.')); 261 return false; 262 } 263 264 if (!is_dir($css)) { 265 if (!is_writable($public)) { 266 $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'), 'public')); 267 return false; 268 } 269 if ($create) { 270 files::makeDir($css); 271 } 272 return true; 273 } 274 275 if (!is_writable($css)) { 276 $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'), 'public/' . $folder)); 277 return false; 278 } 279 280 return true; 281 } 277 282 278 283 /** … … 284 289 * @param string $value value 285 290 */ 286 public static function prop(&$css,$selector,$prop,$value)287 288 289 290 291 291 public static function prop(&$css, $selector, $prop, $value) 292 { 293 if ($value) { 294 $css[$selector][$prop] = $value; 295 } 296 } 292 297 293 298 /** … … 300 305 * @param string $image image filename 301 306 */ 302 public static function backgroundImg($folder,&$css,$selector,$value,$image)303 304 $file = self::imagesPath($folder).'/'.$image;305 if ($value && file_exists($file)){306 $css[$selector]['background-image'] = 'url('.self::imagesURL($folder).'/'.$image.')';307 308 307 public static function backgroundImg($folder, &$css, $selector, $value, $image) 308 { 309 $file = self::imagesPath($folder) . '/' . $image; 310 if ($value && file_exists($file)) { 311 $css[$selector]['background-image'] = 'url(' . self::imagesURL($folder) . '/' . $image . ')'; 312 } 313 } 309 314 310 315 /** … … 315 320 * @param string $css CSS file content 316 321 */ 317 public static function writeCss($folder,$theme,$css)318 319 file_put_contents(self::cssPath($folder).'/'.$theme.'.css', $css);320 322 public static function writeCss($folder, $theme, $css) 323 { 324 file_put_contents(self::cssPath($folder) . '/' . $theme . '.css', $css); 325 } 321 326 322 327 /** … … 326 331 * @param string $theme CSS filename to be removed 327 332 */ 328 public static function dropCss($folder,$theme)329 330 $file = path::real(self::cssPath($folder).'/'.$theme.'.css');331 332 333 334 333 public static function dropCss($folder, $theme) 334 { 335 $file = path::real(self::cssPath($folder) . '/' . $theme . '.css'); 336 if (is_writable(dirname($file))) { 337 @unlink($file); 338 } 339 } 335 340 336 341 /** … … 341 346 * @return string CSS file URL 342 347 */ 343 344 345 346 $url= self::cssURL($folder);347 $path= self::cssPath($folder);348 349 if (file_exists($path.'/'.$theme.'.css')) {350 return $url.'/'.$theme.'.css';351 352 353 return null;354 348 public static function publicCssUrlHelper($folder) 349 { 350 $theme = $GLOBALS['core']->blog->settings->system->theme; 351 $url = self::cssURL($folder); 352 $path = self::cssPath($folder); 353 354 if (file_exists($path . '/' . $theme . '.css')) { 355 return $url . '/' . $theme . '.css'; 356 } 357 358 return; 359 } 355 360 356 361 /** … … 361 366 * @return string real path of folder 362 367 */ 363 364 365 366 return path::real($core->blog->public_path).'/'.$folder;367 368 public static function imagesPath($folder) 369 { 370 global $core; 371 return path::real($core->blog->public_path) . '/' . $folder; 372 } 368 373 369 374 /** … … 374 379 * @return string URL of images folder 375 380 */ 376 377 378 379 return $core->blog->settings->system->public_url.'/'.$folder;380 381 public static function imagesURL($folder) 382 { 383 global $core; 384 return $core->blog->settings->system->public_url . '/' . $folder; 385 } 381 386 382 387 /** … … 388 393 * @return boolean true if folder exists and may be written 389 394 */ 390 public static function canWriteImages($folder,$create=false)391 392 393 394 395 $imgs= self::imagesPath($folder);396 397 398 $core->error->add(__('At least one of the following functions is not available: '.399 400 401 402 403 404 405 406 407 408 409 410 $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public'));411 412 413 414 415 416 417 418 419 420 $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'),'public/'.$folder));421 422 423 424 425 395 public static function canWriteImages($folder, $create = false) 396 { 397 global $core; 398 399 $public = path::real($core->blog->public_path); 400 $imgs = self::imagesPath($folder); 401 402 if (!function_exists('imagecreatetruecolor') || !function_exists('imagepng') || !function_exists('imagecreatefrompng')) { 403 $core->error->add(__('At least one of the following functions is not available: ' . 404 'imagecreatetruecolor, imagepng & imagecreatefrompng.')); 405 return false; 406 } 407 408 if (!is_dir($public)) { 409 $core->error->add(__('The \'public\' directory does not exist.')); 410 return false; 411 } 412 413 if (!is_dir($imgs)) { 414 if (!is_writable($public)) { 415 $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'), 'public')); 416 return false; 417 } 418 if ($create) { 419 files::makeDir($imgs); 420 } 421 return true; 422 } 423 424 if (!is_writable($imgs)) { 425 $core->error->add(sprintf(__('The \'%s\' directory cannot be modified.'), 'public/' . $folder)); 426 return false; 427 } 428 429 return true; 430 } 426 431 427 432 /** … … 434 439 * @return string full pathname of uploaded image 435 440 */ 436 public static function uploadImage($folder,$f,$width=0)437 438 if (!self::canWriteImages($folder,true)) {439 440 441 442 443 444 445 446 447 448 449 $dest = self::imagesPath($folder).'/uploaded'.($type == 'image/png' ? '.png' : '.jpg');450 451 if (@move_uploaded_file($f['tmp_name'],$dest) === false) {452 453 454 455 456 457 458 throw new Exception(sprintf(__('Uploaded image is not %s pixels wide.'),$width));459 460 461 462 463 441 public static function uploadImage($folder, $f, $width = 0) 442 { 443 if (!self::canWriteImages($folder, true)) { 444 throw new Exception(__('Unable to create images.')); 445 } 446 447 $name = $f['name']; 448 $type = files::getMimeType($name); 449 450 if ($type != 'image/jpeg' && $type != 'image/png') { 451 throw new Exception(__('Invalid file type.')); 452 } 453 454 $dest = self::imagesPath($folder) . '/uploaded' . ($type == 'image/png' ? '.png' : '.jpg'); 455 456 if (@move_uploaded_file($f['tmp_name'], $dest) === false) { 457 throw new Exception(__('An error occurred while writing the file.')); 458 } 459 460 if ($width) { 461 $s = getimagesize($dest); 462 if ($s[0] != $width) { 463 throw new Exception(sprintf(__('Uploaded image is not %s pixels wide.'), $width)); 464 } 465 } 466 467 return $dest; 468 } 464 469 465 470 /** … … 469 474 * @param string $img image filename 470 475 */ 471 public static function dropImage($folder,$img)472 473 474 475 $img = path::real(self::imagesPath($folder).'/'.$img);476 477 478 479 480 481 482 483 484 485 486 487 476 public static function dropImage($folder, $img) 477 { 478 global $core; 479 480 $img = path::real(self::imagesPath($folder) . '/' . $img); 481 if (is_writable(dirname($img))) { 482 // Delete thumbnails if any 483 try { 484 $media = new dcMedia($core); 485 $media->imageThumbRemove($img); 486 } catch (Exception $e) { 487 $core->error->add($e->getMessage()); 488 } 489 // Delete image 490 @unlink($img); 491 } 492 } 488 493 } -
inc/admin/prepend.php
r3375 r3730 11 11 # -- END LICENSE BLOCK ----------------------------------------- 12 12 13 define('DC_CONTEXT_ADMIN', true);14 15 require_once dirname(__FILE__) .'/../prepend.php';13 define('DC_CONTEXT_ADMIN', true); 14 15 require_once dirname(__FILE__) . '/../prepend.php'; 16 16 17 17 // HTTP/1.1 … … 22 22 header("Pragma: no-cache"); 23 23 24 function dc_load_locales() { 25 global $_lang, $core; 26 27 $_lang = $core->auth->getInfo('user_lang'); 28 $_lang = preg_match('/^[a-z]{2}(-[a-z]{2})?$/',$_lang) ? $_lang : 'en'; 29 30 l10n::lang($_lang); 31 if (l10n::set(dirname(__FILE__).'/../../locales/'.$_lang.'/date') === false && $_lang != 'en') { 32 l10n::set(dirname(__FILE__).'/../../locales/en/date'); 33 } 34 l10n::set(dirname(__FILE__).'/../../locales/'.$_lang.'/main'); 35 l10n::set(dirname(__FILE__).'/../../locales/'.$_lang.'/public'); 36 l10n::set(dirname(__FILE__).'/../../locales/'.$_lang.'/plugins'); 37 38 // Set lexical lang 39 dcUtils::setlexicalLang('admin',$_lang); 24 function dc_load_locales() 25 { 26 global $_lang, $core; 27 28 $_lang = $core->auth->getInfo('user_lang'); 29 $_lang = preg_match('/^[a-z]{2}(-[a-z]{2})?$/', $_lang) ? $_lang : 'en'; 30 31 l10n::lang($_lang); 32 if (l10n::set(dirname(__FILE__) . '/../../locales/' . $_lang . '/date') === false && $_lang != 'en') { 33 l10n::set(dirname(__FILE__) . '/../../locales/en/date'); 34 } 35 l10n::set(dirname(__FILE__) . '/../../locales/' . $_lang . '/main'); 36 l10n::set(dirname(__FILE__) . '/../../locales/' . $_lang . '/public'); 37 l10n::set(dirname(__FILE__) . '/../../locales/' . $_lang . '/plugins'); 38 39 // Set lexical lang 40 dcUtils::setlexicalLang('admin', $_lang); 40 41 } 41 42 42 43 function dc_admin_icon_url($img) 43 44 { 44 45 46 47 48 49 50 if ((preg_match('/^images\/menu\/(.+)$/',$img,$m)) ||51 (preg_match('/^index\.php\?pf=(.+)$/',$img,$m))) {52 53 $icon = path::real(dirname(__FILE__).'/../../admin/images/iconset/'.$user_ui_iconset.'/'.$m[1],false);54 55 $allow_types = array('png','jpg','jpeg','gif');56 if (is_file($icon) && is_readable($icon) && in_array(files::getExtension($icon),$allow_types)) {57 return DC_ADMIN_URL.'images/iconset/'.$user_ui_iconset.'/'.$m[1];58 59 60 61 62 63 64 } 65 66 function addMenuItem($section, $desc,$adminurl,$icon,$perm,$pinned=false)45 global $core; 46 47 $core->auth->user_prefs->addWorkspace('interface'); 48 $user_ui_iconset = @$core->auth->user_prefs->interface->iconset; 49 if (($user_ui_iconset) && ($img)) { 50 $icon = false; 51 if ((preg_match('/^images\/menu\/(.+)$/', $img, $m)) || 52 (preg_match('/^index\.php\?pf=(.+)$/', $img, $m))) { 53 if ($m[1]) { 54 $icon = path::real(dirname(__FILE__) . '/../../admin/images/iconset/' . $user_ui_iconset . '/' . $m[1], false); 55 if ($icon !== false) { 56 $allow_types = array('png', 'jpg', 'jpeg', 'gif'); 57 if (is_file($icon) && is_readable($icon) && in_array(files::getExtension($icon), $allow_types)) { 58 return DC_ADMIN_URL . 'images/iconset/' . $user_ui_iconset . '/' . $m[1]; 59 } 60 } 61 } 62 } 63 } 64 return $img; 65 } 66 67 function addMenuItem($section, $desc, $adminurl, $icon, $perm, $pinned = false) 67 68 { 68 global $core,$_menu; 69 70 $url = $core->adminurl->get($adminurl); 71 $_menu[$section]->prependItem($desc,$url,$icon, 72 preg_match('/'.preg_quote($url).'(\?.*)?$/',$_SERVER['REQUEST_URI']),$perm,null,null,$pinned); 73 } 74 75 if (defined('DC_AUTH_SESS_ID') && defined('DC_AUTH_SESS_UID')) 76 { 77 # We have session information in constants 78 $_COOKIE[DC_SESSION_NAME] = DC_AUTH_SESS_ID; 79 80 if (!$core->auth->checkSession(DC_AUTH_SESS_UID)) { 81 throw new Exception('Invalid session data.'); 82 } 83 84 # Check nonce from POST requests 85 if (!empty($_POST)) 86 { 87 if (empty($_POST['xd_check']) || !$core->checkNonce($_POST['xd_check'])) { 88 throw new Exception('Precondition Failed.'); 89 } 90 } 91 92 if (empty($_SESSION['sess_blog_id'])) { 93 throw new Exception('Permission denied.'); 94 } 95 96 # Loading locales 97 dc_load_locales(); 98 99 $core->setBlog($_SESSION['sess_blog_id']); 100 if (!$core->blog->id) { 101 throw new Exception('Permission denied.'); 102 } 103 } 104 elseif ($core->auth->sessionExists()) 105 { 106 # If we have a session we launch it now 107 try { 108 if (!$core->auth->checkSession()) 109 { 110 # Avoid loop caused by old cookie 111 $p = $core->session->getCookieParameters(false,-600); 112 $p[3] = '/'; 113 call_user_func_array('setcookie',$p); 114 115 http::redirect('auth.php'); 116 } 117 } catch (Exception $e) { 118 __error(__('Database error') 119 ,__('There seems to be no Session table in your database. Is Dotclear completly installed?') 120 ,20); 121 } 122 123 # Check nonce from POST requests 124 if (!empty($_POST)) 125 { 126 if (empty($_POST['xd_check']) || !$core->checkNonce($_POST['xd_check'])) { 127 http::head(412); 128 header('Content-Type: text/plain'); 129 echo 'Precondition Failed'; 130 exit; 131 } 132 } 133 134 if (!empty($_REQUEST['switchblog']) 135 && $core->auth->getPermissions($_REQUEST['switchblog']) !== false) 136 { 137 $_SESSION['sess_blog_id'] = $_REQUEST['switchblog']; 138 if (isset($_SESSION['media_manager_dir'])) { 139 unset($_SESSION['media_manager_dir']); 140 } 141 if (isset($_SESSION['media_manager_page'])) { 142 unset($_SESSION['media_manager_page']); 143 } 144 145 # Removing switchblog from URL 146 $redir = $_SERVER['REQUEST_URI']; 147 $redir = preg_replace('/switchblog=(.*?)(&|$)/','',$redir); 148 $redir = preg_replace('/\?$/','',$redir); 149 http::redirect($redir); 150 exit; 151 } 152 153 # Check blog to use and log out if no result 154 if (isset($_SESSION['sess_blog_id'])) 155 { 156 if ($core->auth->getPermissions($_SESSION['sess_blog_id']) === false) { 157 unset($_SESSION['sess_blog_id']); 158 } 159 } 160 else 161 { 162 if (($b = $core->auth->findUserBlog($core->auth->getInfo('user_default_blog'))) !== false) { 163 $_SESSION['sess_blog_id'] = $b; 164 unset($b); 165 } 166 } 167 168 # Loading locales 169 dc_load_locales(); 170 171 if (isset($_SESSION['sess_blog_id'])) { 172 $core->setBlog($_SESSION['sess_blog_id']); 173 } else { 174 $core->session->destroy(); 175 http::redirect('auth.php'); 176 } 69 global $core, $_menu; 70 71 $url = $core->adminurl->get($adminurl); 72 $_menu[$section]->prependItem($desc, $url, $icon, 73 preg_match('/' . preg_quote($url) . '(\?.*)?$/', $_SERVER['REQUEST_URI']), $perm, null, null, $pinned); 74 } 75 76 if (defined('DC_AUTH_SESS_ID') && defined('DC_AUTH_SESS_UID')) { 77 # We have session information in constants 78 $_COOKIE[DC_SESSION_NAME] = DC_AUTH_SESS_ID; 79 80 if (!$core->auth->checkSession(DC_AUTH_SESS_UID)) { 81 throw new Exception('Invalid session data.'); 82 } 83 84 # Check nonce from POST requests 85 if (!empty($_POST)) { 86 if (empty($_POST['xd_check']) || !$core->checkNonce($_POST['xd_check'])) { 87 throw new Exception('Precondition Failed.'); 88 } 89 } 90 91 if (empty($_SESSION['sess_blog_id'])) { 92 throw new Exception('Permission denied.'); 93 } 94 95 # Loading locales 96 dc_load_locales(); 97 98 $core->setBlog($_SESSION['sess_blog_id']); 99 if (!$core->blog->id) { 100 throw new Exception('Permission denied.'); 101 } 102 } elseif ($core->auth->sessionExists()) { 103 # If we have a session we launch it now 104 try { 105 if (!$core->auth->checkSession()) { 106 # Avoid loop caused by old cookie 107 $p = $core->session->getCookieParameters(false, -600); 108 $p[3] = '/'; 109 call_user_func_array('setcookie', $p); 110 111 http::redirect('auth.php'); 112 } 113 } catch (Exception $e) { 114 __error(__('Database error') 115 , __('There seems to be no Session table in your database. Is Dotclear completly installed?') 116 , 20); 117 } 118 119 # Check nonce from POST requests 120 if (!empty($_POST)) { 121 if (empty($_POST['xd_check']) || !$core->checkNonce($_POST['xd_check'])) { 122 http::head(412); 123 header('Content-Type: text/plain'); 124 echo 'Precondition Failed'; 125 exit; 126 } 127 } 128 129 if (!empty($_REQUEST['switchblog']) 130 && $core->auth->getPermissions($_REQUEST['switchblog']) !== false) { 131 $_SESSION['sess_blog_id'] = $_REQUEST['switchblog']; 132 if (isset($_SESSION['media_manager_dir'])) { 133 unset($_SESSION['media_manager_dir']); 134 } 135 if (isset($_SESSION['media_manager_page'])) { 136 unset($_SESSION['media_manager_page']); 137 } 138 139 # Removing switchblog from URL 140 $redir = $_SERVER['REQUEST_URI']; 141 $redir = preg_replace('/switchblog=(.*?)(&|$)/', '', $redir); 142 $redir = preg_replace('/\?$/', '', $redir); 143 http::redirect($redir); 144 exit; 145 } 146 147 # Check blog to use and log out if no result 148 if (isset($_SESSION['sess_blog_id'])) { 149 if ($core->auth->getPermissions($_SESSION['sess_blog_id']) === false) { 150 unset($_SESSION['sess_blog_id']); 151 } 152 } else { 153 if (($b = $core->auth->findUserBlog($core->auth->getInfo('user_default_blog'))) !== false) { 154 $_SESSION['sess_blog_id'] = $b; 155 unset($b); 156 } 157 } 158 159 # Loading locales 160 dc_load_locales(); 161 162 if (isset($_SESSION['sess_blog_id'])) { 163 $core->setBlog($_SESSION['sess_blog_id']); 164 } else { 165 $core->session->destroy(); 166 http::redirect('auth.php'); 167 } 177 168 } 178 169 179 170 $core->adminurl = new dcAdminURL($core); 180 171 181 $core->adminurl->register('admin.posts','posts.php'); 182 $core->adminurl->register('admin.popup_posts','popup_posts.php'); 183 $core->adminurl->register('admin.post','post.php'); 184 $core->adminurl->register('admin.post.media','post_media.php'); 185 $core->adminurl->register('admin.blog.theme','blog_theme.php'); 186 $core->adminurl->register('admin.blog.pref','blog_pref.php'); 187 $core->adminurl->register('admin.blog.del','blog_del.php'); 188 $core->adminurl->register('admin.blog','blog.php'); 189 $core->adminurl->register('admin.blogs','blogs.php'); 190 $core->adminurl->register('admin.categories','categories.php'); 191 $core->adminurl->register('admin.category','category.php'); 192 $core->adminurl->register('admin.comments','comments.php'); 193 $core->adminurl->register('admin.comment','comment.php'); 194 $core->adminurl->register('admin.help','help.php'); 195 $core->adminurl->register('admin.home','index.php'); 196 $core->adminurl->register('admin.langs','langs.php'); 197 $core->adminurl->register('admin.media','media.php'); 198 $core->adminurl->register('admin.media.item','media_item.php'); 199 $core->adminurl->register('admin.plugins','plugins.php'); 200 $core->adminurl->register('admin.plugin','plugin.php'); 201 $core->adminurl->register('admin.search','search.php'); 202 $core->adminurl->register('admin.user.preferences','preferences.php'); 203 $core->adminurl->register('admin.user','user.php'); 204 $core->adminurl->register('admin.user.actions','users_actions.php'); 205 $core->adminurl->register('admin.users','users.php'); 206 $core->adminurl->register('admin.auth','auth.php'); 207 $core->adminurl->register('admin.help','help.php'); 208 $core->adminurl->register('admin.update','update.php'); 209 210 $core->adminurl->registercopy('load.plugin.file','admin.home',array('pf' => 'dummy.css')); 211 $core->adminurl->registercopy('load.var.file','admin.home',array('vf' => 'dummy.json')); 212 213 if ($core->auth->userID() && $core->blog !== null) 214 { 215 # Loading resources and help files 216 $locales_root = dirname(__FILE__).'/../../locales/'; 217 require $locales_root.'/en/resources.php'; 218 if (($f = l10n::getFilePath($locales_root,'resources.php',$_lang))) { 219 require $f; 220 } 221 unset($f); 222 223 if (($hfiles = @scandir($locales_root.$_lang.'/help')) !== false) 224 { 225 foreach ($hfiles as $hfile) { 226 if (preg_match('/^(.*)\.html$/',$hfile,$m)) { 227 $GLOBALS['__resources']['help'][$m[1]] = $locales_root.$_lang.'/help/'.$hfile; 228 } 229 } 230 } 231 unset($hfiles,$locales_root); 232 // Contextual help flag 233 $GLOBALS['__resources']['ctxhelp'] = false; 234 235 $core->auth->user_prefs->addWorkspace('interface'); 236 $user_ui_nofavmenu = $core->auth->user_prefs->interface->nofavmenu; 237 238 $core->favs = new dcFavorites($core); 239 240 # [] : Title, URL, small icon, large icon, permissions, id, class 241 # NB : '*' in permissions means any, null means super admin only 242 243 # Menus creation 244 $_menu = new ArrayObject(); 245 $_menu['Dashboard'] = new dcMenu('dashboard-menu',null); 246 if (!$user_ui_nofavmenu) { 247 $core->favs->appendMenuTitle($_menu); 248 } 249 $_menu['Blog'] = new dcMenu('blog-menu','Blog'); 250 $_menu['System'] = new dcMenu('system-menu','System'); 251 $_menu['Plugins'] = new dcMenu('plugins-menu','Plugins'); 252 # Loading plugins 253 $core->plugins->loadModules(DC_PLUGINS_ROOT,'admin',$_lang); 254 $core->favs->setup(); 255 256 if (!$user_ui_nofavmenu) { 257 $core->favs->appendMenu($_menu); 258 } 259 260 # Set menu titles 261 262 $_menu['System']->title = __('System settings'); 263 $_menu['Blog']->title = __('Blog'); 264 $_menu['Plugins']->title = __('Plugins'); 265 266 addMenuItem('Blog',__('Blog appearance'),'admin.blog.theme','images/menu/themes.png', 267 $core->auth->check('admin',$core->blog->id)); 268 addMenuItem('Blog',__('Blog settings'),'admin.blog.pref','images/menu/blog-pref.png', 269 $core->auth->check('admin',$core->blog->id)); 270 addMenuItem('Blog',__('Media manager'),'admin.media','images/menu/media.png', 271 $core->auth->check('media,media_admin',$core->blog->id)); 272 addMenuItem('Blog',__('Categories'),'admin.categories','images/menu/categories.png', 273 $core->auth->check('categories',$core->blog->id)); 274 addMenuItem('Blog',__('Search'),'admin.search','images/menu/search.png', 275 $core->auth->check('usage,contentadmin',$core->blog->id)); 276 addMenuItem('Blog',__('Comments'),'admin.comments','images/menu/comments.png', 277 $core->auth->check('usage,contentadmin',$core->blog->id)); 278 addMenuItem('Blog',__('Entries'),'admin.posts','images/menu/entries.png', 279 $core->auth->check('usage,contentadmin',$core->blog->id)); 280 addMenuItem('Blog',__('New entry'),'admin.post','images/menu/edit.png', 281 $core->auth->check('usage,contentadmin',$core->blog->id),true); 282 283 addMenuItem('System',__('Update'),'admin.update','images/menu/update.png', 284 $core->auth->isSuperAdmin() && is_readable(DC_DIGESTS)); 285 addMenuItem('System',__('Languages'),'admin.langs','images/menu/langs.png', 286 $core->auth->isSuperAdmin()); 287 addMenuItem('System',__('Plugins management'),'admin.plugins','images/menu/plugins.png', 288 $core->auth->isSuperAdmin()); 289 addMenuItem('System',__('Users'),'admin.users','images/menu/users.png', 290 $core->auth->isSuperAdmin()); 291 addMenuItem('System',__('Blogs'),'admin.blogs','images/menu/blogs.png', 292 $core->auth->isSuperAdmin() || 293 $core->auth->check('usage,contentadmin',$core->blog->id) && $core->auth->getBlogCount() > 1); 294 295 if (empty($core->blog->settings->system->jquery_migrate_mute)) { 296 $core->blog->settings->system->put('jquery_migrate_mute', true, 'boolean', 'Mute warnings for jquery migrate plugin ?', false); 297 } 298 } 299 172 $core->adminurl->register('admin.posts', 'posts.php'); 173 $core->adminurl->register('admin.popup_posts', 'popup_posts.php'); 174 $core->adminurl->register('admin.post', 'post.php'); 175 $core->adminurl->register('admin.post.media', 'post_media.php'); 176 $core->adminurl->register('admin.blog.theme', 'blog_theme.php'); 177 $core->adminurl->register('admin.blog.pref', 'blog_pref.php'); 178 $core->adminurl->register('admin.blog.del', 'blog_del.php'); 179 $core->adminurl->register('admin.blog', 'blog.php'); 180 $core->adminurl->register('admin.blogs', 'blogs.php'); 181 $core->adminurl->register('admin.categories', 'categories.php'); 182 $core->adminurl->register('admin.category', 'category.php'); 183 $core->adminurl->register('admin.comments', 'comments.php'); 184 $core->adminurl->register('admin.comment', 'comment.php'); 185 $core->adminurl->register('admin.help', 'help.php'); 186 $core->adminurl->register('admin.home', 'index.php'); 187 $core->adminurl->register('admin.langs', 'langs.php'); 188 $core->adminurl->register('admin.media', 'media.php'); 189 $core->adminurl->register('admin.media.item', 'media_item.php'); 190 $core->adminurl->register('admin.plugins', 'plugins.php'); 191 $core->adminurl->register('admin.plugin', 'plugin.php'); 192 $core->adminurl->register('admin.search', 'search.php'); 193 $core->adminurl->register('admin.user.preferences', 'preferences.php'); 194 $core->adminurl->register('admin.user', 'user.php'); 195 $core->adminurl->register('admin.user.actions', 'users_actions.php'); 196 $core->adminurl->register('admin.users', 'users.php'); 197 $core->adminurl->register('admin.auth', 'auth.php'); 198 $core->adminurl->register('admin.help', 'help.php'); 199 $core->adminurl->register('admin.update', 'update.php'); 200 201 $core->adminurl->registercopy('load.plugin.file', 'admin.home', array('pf' => 'dummy.css')); 202 $core->adminurl->registercopy('load.var.file', 'admin.home', array('vf' => 'dummy.json')); 203 204 if ($core->auth->userID() && $core->blog !== null) { 205 # Loading resources and help files 206 $locales_root = dirname(__FILE__) . '/../../locales/'; 207 require $locales_root . '/en/resources.php'; 208 if (($f = l10n::getFilePath($locales_root, 'resources.php', $_lang))) { 209 require $f; 210 } 211 unset($f); 212 213 if (($hfiles = @scandir($locales_root . $_lang . '/help')) !== false) { 214 foreach ($hfiles as $hfile) { 215 if (preg_match('/^(.*)\.html$/', $hfile, $m)) { 216 $GLOBALS['__resources']['help'][$m[1]] = $locales_root . $_lang . '/help/' . $hfile; 217 } 218 } 219 } 220 unset($hfiles, $locales_root); 221 // Contextual help flag 222 $GLOBALS['__resources']['ctxhelp'] = false; 223 224 $core->auth->user_prefs->addWorkspace('interface'); 225 $user_ui_nofavmenu = $core->auth->user_prefs->interface->nofavmenu; 226 227 $core->favs = new dcFavorites($core); 228 229 # [] : Title, URL, small icon, large icon, permissions, id, class 230 # NB : '*' in permissions means any, null means super admin only 231 232 # Menus creation 233 $_menu = new ArrayObject(); 234 $_menu['Dashboard'] = new dcMenu('dashboard-menu', null); 235 if (!$user_ui_nofavmenu) { 236 $core->favs->appendMenuTitle($_menu); 237 } 238 $_menu['Blog'] = new dcMenu('blog-menu', 'Blog'); 239 $_menu['System'] = new dcMenu('system-menu', 'System'); 240 $_menu['Plugins'] = new dcMenu('plugins-menu', 'Plugins'); 241 # Loading plugins 242 $core->plugins->loadModules(DC_PLUGINS_ROOT, 'admin', $_lang); 243 $core->favs->setup(); 244 245 if (!$user_ui_nofavmenu) { 246 $core->favs->appendMenu($_menu); 247 } 248 249 # Set menu titles 250 251 $_menu['System']->title = __('System settings'); 252 $_menu['Blog']->title = __('Blog'); 253 $_menu['Plugins']->title = __('Plugins'); 254 255 addMenuItem('Blog', __('Blog appearance'), 'admin.blog.theme', 'images/menu/themes.png', 256 $core->auth->check('admin', $core->blog->id)); 257 addMenuItem('Blog', __('Blog settings'), 'admin.blog.pref', 'images/menu/blog-pref.png', 258 $core->auth->check('admin', $core->blog->id)); 259 addMenuItem('Blog', __('Media manager'), 'admin.media', 'images/menu/media.png', 260 $core->auth->check('media,media_admin', $core->blog->id)); 261 addMenuItem('Blog', __('Categories'), 'admin.categories', 'images/menu/categories.png', 262 $core->auth->check('categories', $core->blog->id)); 263 addMenuItem('Blog', __('Search'), 'admin.search', 'images/menu/search.png', 264 $core->auth->check('usage,contentadmin', $core->blog->id)); 265 addMenuItem('Blog', __('Comments'), 'admin.comments', 'images/menu/comments.png', 266 $core->auth->check('usage,contentadmin', $core->blog->id)); 267 addMenuItem('Blog', __('Entries'), 'admin.posts', 'images/menu/entries.png', 268 $core->auth->check('usage,contentadmin', $core->blog->id)); 269 addMenuItem('Blog', __('New entry'), 'admin.post', 'images/menu/edit.png', 270 $core->auth->check('usage,contentadmin', $core->blog->id), true); 271 272 addMenuItem('System', __('Update'), 'admin.update', 'images/menu/update.png', 273 $core->auth->isSuperAdmin() && is_readable(DC_DIGESTS)); 274 addMenuItem('System', __('Languages'), 'admin.langs', 'images/menu/langs.png', 275 $core->auth->isSuperAdmin()); 276 addMenuItem('System', __('Plugins management'), 'admin.plugins', 'images/menu/plugins.png', 277 $core->auth->isSuperAdmin()); 278 addMenuItem('System', __('Users'), 'admin.users', 'images/menu/users.png', 279 $core->auth->isSuperAdmin()); 280 addMenuItem('System', __('Blogs'), 'admin.blogs', 'images/menu/blogs.png', 281 $core->auth->isSuperAdmin() || 282 $core->auth->check('usage,contentadmin', $core->blog->id) && $core->auth->getBlogCount() > 1); 283 284 if (empty($core->blog->settings->system->jquery_migrate_mute)) { 285 $core->blog->settings->system->put('jquery_migrate_mute', true, 'boolean', 'Mute warnings for jquery migrate plugin ?', false); 286 } 287 }
Note: See TracChangeset
for help on using the changeset viewer.