Changeset 3730:5c45a5df9a59 for inc/admin/class.dc.favorites.php
- Timestamp:
- 03/08/18 17:58:39 (7 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note: See TracChangeset
for help on using the changeset viewer.