b2evolution PHP Cross Reference Blogging Systems

Source: /inc/collections/_collections.init.php - 989 lines - 28336 bytes - Summary - Text - Print

Description: This is the init file for the collections module

   1  <?php
   2  /**
   3   * This is the init file for the collections module
   4   *
   5   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   6   *
   7   * @package admin
   8   *
   9   * @version _collections.init.php,v 1.20 2010/05/02 19:50:50 fplanque Exp
  10   */
  11  if( !defined('EVO_CONFIG_LOADED') ) die( 'Please, do not access this page directly.' );
  12  
  13  /**
  14   * Make this omething useful:
  15   */
  16  $default_ctrl = 'dashboard';
  17  
  18  /**
  19   * Minimum PHP version required for collections module to function properly
  20   */
  21  $required_php_version[ 'collections' ] = '5.0';
  22  
  23  /**
  24   * Minimum MYSQL version required for collections module to function properly
  25   */
  26  $required_mysql_version[ 'collections' ] = '5.0.3';
  27  
  28  /**
  29   * Aliases for table names:
  30   *
  31   * (You should not need to change them.
  32   *  If you want to have multiple b2evo installations in a single database you should
  33   *  change {@link $tableprefix} in _basic_config.php)
  34   */
  35  $db_config['aliases'] = array_merge( $db_config['aliases'], array(
  36          'T_blogs'                  => $tableprefix.'blogs',
  37          'T_categories'             => $tableprefix.'categories',
  38          'T_coll_group_perms'       => $tableprefix.'bloggroups',
  39          'T_coll_user_perms'        => $tableprefix.'blogusers',
  40          'T_coll_settings'          => $tableprefix.'coll_settings',
  41          'T_comments'               => $tableprefix.'comments',
  42          'T_comments__votes'        => $tableprefix.'comments__votes',
  43          'T_comments__prerendering' => $tableprefix.'comments__prerendering',
  44          'T_items__item'            => $tableprefix.'items__item',
  45          'T_items__item_settings'   => $tableprefix.'items__item_settings',
  46          'T_items__itemtag'         => $tableprefix.'items__itemtag',
  47          'T_items__prerendering'    => $tableprefix.'items__prerendering',
  48          'T_items__status'          => $tableprefix.'items__status',
  49          'T_items__tag'             => $tableprefix.'items__tag',
  50          'T_items__type'            => $tableprefix.'items__type',
  51          'T_items__subscriptions'   => $tableprefix.'items__subscriptions',
  52          'T_items__version'         => $tableprefix.'items__version',
  53          'T_links'                  => $tableprefix.'links',
  54          'T_postcats'             => $tableprefix.'postcats',
  55          'T_skins__container'     => $tableprefix.'skins__container',
  56          'T_skins__skin'          => $tableprefix.'skins__skin',
  57          'T_subscriptions'        => $tableprefix.'subscriptions',
  58          'T_widget'               => $tableprefix.'widget',
  59      ) );
  60  
  61  /**
  62   * Controller mappings.
  63   *
  64   * For each controller name, we associate a controller file to be found in /inc/ .
  65   * The advantage of this indirection is that it is easy to reorganize the controllers into
  66   * subdirectories by modules. It is also easy to deactivate some controllers if you don't
  67   * want to provide this functionality on a given installation.
  68   *
  69   * Note: while the controller mappings might more or less follow the menu structure, we do not merge
  70   * the two tables since we could, at any time, decide to make a skin with a different menu structure.
  71   * The controllers however would most likely remain the same.
  72   *
  73   * @global array
  74   */
  75  $ctrl_mappings = array_merge( $ctrl_mappings, array(
  76          'chapters'     => 'chapters/chapters.ctrl.php',
  77          'collections'  => 'collections/collections.ctrl.php',
  78          'coll_settings'=> 'collections/coll_settings.ctrl.php',
  79          'comments'     => 'comments/_comments.ctrl.php',
  80          'dashboard'    => 'dashboard/dashboard.ctrl.php',
  81          'items'        => 'items/items.ctrl.php',
  82          'itemstatuses' => 'items/item_statuses.ctrl.php',
  83          'itemtypes'    => 'items/item_types.ctrl.php',
  84          'links'        => 'links/links.ctrl.php',
  85          'mtimport'     => 'tools/mtimport.ctrl.php',
  86          'skins'        => 'skins/skins.ctrl.php',
  87          'tools'        => 'tools/tools.ctrl.php',
  88          'widgets'      => 'widgets/widgets.ctrl.php',
  89          'wpimport'     => 'tools/wpimport.ctrl.php',
  90          'wpimportxml'  => 'tools/wpimportxml.ctrl.php',
  91          'phpbbimport'  => 'tools/phpbbimport.ctrl.php',
  92      ) );
  93  
  94  
  95  /**
  96   * Get the BlogCache
  97   *
  98   * @return BlogCache
  99   */
 100  function & get_BlogCache()
 101  {
 102      global $BlogCache;
 103  
 104      if( ! isset( $BlogCache ) )
 105      {    // Cache doesn't exist yet:
 106          load_class( 'collections/model/_blogcache.class.php', 'BlogCache' );
 107          $BlogCache = new BlogCache(); // COPY (FUNC)
 108      }
 109  
 110      return $BlogCache;
 111  }
 112  
 113  
 114  /**
 115   * Get the ChapterCache
 116   *
 117   * @return ChapterCache
 118   */
 119  function & get_ChapterCache()
 120  {
 121      global $ChapterCache;
 122  
 123      if( ! isset( $ChapterCache ) )
 124      {    // Cache doesn't exist yet:
 125          load_class( 'chapters/model/_chaptercache.class.php', 'ChapterCache' );
 126          $ChapterCache = new ChapterCache(); // COPY (FUNC)
 127      }
 128  
 129      return $ChapterCache;
 130  }
 131  
 132  
 133  /**
 134   * Get the ItemCacheLight
 135   *
 136   * @return ItemCacheLight
 137   */
 138  function & get_ItemCacheLight()
 139  {
 140      global $ItemCacheLight;
 141  
 142      if( ! isset( $ItemCacheLight ) )
 143      {    // Cache doesn't exist yet:
 144          $ItemCacheLight = new DataObjectCache( 'ItemLight', false, 'T_items__item', 'post_', 'post_ID' ); // COPY (FUNC)
 145      }
 146  
 147      return $ItemCacheLight;
 148  }
 149  
 150  /**
 151   * Get the ItemCache
 152   *
 153   * @return ItemCache
 154   */
 155  function & get_ItemCache()
 156  {
 157      global $ItemCache;
 158  
 159      if( ! isset( $ItemCache ) )
 160      {    // Cache doesn't exist yet:
 161          load_class( 'items/model/_itemcache.class.php', 'ItemCache' );
 162          $ItemCache = new ItemCache(); // COPY (FUNC)
 163      }
 164  
 165      return $ItemCache;
 166  }
 167  
 168  /**
 169   * Get the ItemPrerenderingCache
 170   *
 171   * @return ItemPrerenderingCache
 172   */
 173  function & get_ItemPrerenderingCache()
 174  {
 175      global $ItemPrerenderingCache;
 176  
 177      if( ! isset( $ItemPrerenderingCache ) )
 178      {    // Cache doesn't exist yet:
 179          $ItemPrerenderingCache = array();
 180      }
 181  
 182      return $ItemPrerenderingCache;
 183  }
 184  
 185  /**
 186   * Get the ItemTagsCache
 187   *
 188   * @return ItemTagsCache
 189   */
 190  function & get_ItemTagsCache()
 191  {
 192      global $ItemTagsCache;
 193  
 194      if( ! isset( $ItemTagsCache ) )
 195      {    // Cache doesn't exist yet:
 196          $ItemTagsCache = array();
 197      }
 198  
 199      return $ItemTagsCache;
 200  }
 201  
 202  /**
 203   * Get the ItemStatusCache
 204   *
 205   * @return ItemStatusCache
 206   */
 207  function & get_ItemStatusCache()
 208  {
 209      global $Plugins;
 210      global $ItemStatusCache;
 211  
 212      if( ! isset( $ItemStatusCache ) )
 213      {    // Cache doesn't exist yet:
 214          $Plugins->get_object_from_cacheplugin_or_create( 'ItemStatusCache', 'new GenericCache( \'GenericElement\', true, \'T_items__status\', \'pst_\', \'pst_ID\', NULL, \'\', T_(\'No status\') )' );
 215      }
 216  
 217      return $ItemStatusCache;
 218  }
 219  
 220  /**
 221   * Get the ItemTypeCache
 222   *
 223   * @return ItemTypeCache
 224   */
 225  function & get_ItemTypeCache()
 226  {
 227      global $Plugins;
 228      global $ItemTypeCache;
 229  
 230      if( ! isset( $ItemTypeCache ) )
 231      {    // Cache doesn't exist yet:
 232          load_class( 'items/model/_itemtypecache.class.php', 'ItemTypeCache' );
 233          $Plugins->get_object_from_cacheplugin_or_create( 'ItemTypeCache', 'new ItemTypeCache( \'ptyp_\', \'ptyp_ID\' )' );
 234      }
 235  
 236      return $ItemTypeCache;
 237  }
 238  
 239  /**
 240   * Get the CommentCache
 241   *
 242   * @return CommentCache
 243   */
 244  function & get_CommentCache()
 245  {
 246      global $Plugins;
 247      global $CommentCache;
 248  
 249      if( ! isset( $CommentCache ) )
 250      {    // Cache doesn't exist yet:
 251          load_class( 'comments/model/_commentcache.class.php', 'CommentCache' );
 252          $Plugins->get_object_from_cacheplugin_or_create( 'CommentCache', 'new CommentCache()' );
 253      }
 254  
 255      return $CommentCache;
 256  }
 257  
 258  /**
 259   * Get the CommentPrerenderingCache
 260   *
 261   * @return CommentPrerenderingCache
 262   */
 263  function & get_CommentPrerenderingCache()
 264  {
 265      global $CommentPrerenderingCache;
 266  
 267      if( ! isset( $CommentPrerenderingCache ) )
 268      {    // Cache doesn't exist yet:
 269          $CommentPrerenderingCache = array();
 270      }
 271  
 272      return $CommentPrerenderingCache;
 273  }
 274  
 275  
 276  /**
 277   * Get the LinkCache
 278   *
 279   * @return LinkCache
 280   */
 281  function & get_LinkCache()
 282  {
 283      global $LinkCache;
 284  
 285      if( ! isset( $LinkCache ) )
 286      {    // Cache doesn't exist yet:
 287          load_class( 'links/model/_linkcache.class.php', 'LinkCache' );
 288          $LinkCache = new LinkCache(); // COPY (FUNC)
 289      }
 290  
 291      return $LinkCache;
 292  }
 293  
 294  /**
 295   * Get the SkinCache
 296   *
 297   * @return SkinCache
 298   */
 299  function & get_SkinCache()
 300  {
 301      global $SkinCache;
 302  
 303      if( ! isset( $SkinCache ) )
 304      {    // Cache doesn't exist yet:
 305          load_class( 'skins/model/_skincache.class.php', 'SkinCache' );
 306          $SkinCache = new SkinCache(); // COPY (FUNC)
 307      }
 308  
 309      return $SkinCache;
 310  }
 311  
 312  
 313  /**
 314   * Get the WidgetCache
 315   *
 316   * @return WidgetCache
 317   */
 318  function & get_WidgetCache()
 319  {
 320      global $WidgetCache;
 321  
 322      if( ! isset( $WidgetCache ) )
 323      {    // Cache doesn't exist yet:
 324          load_class( 'widgets/model/_widgetcache.class.php', 'WidgetCache' );
 325          $WidgetCache = new WidgetCache(); // COPY (FUNC)
 326      }
 327  
 328      return $WidgetCache;
 329  }
 330  
 331  /**
 332   * Get the EnabledWidgetCache
 333   *
 334   * @return EnabledWidgetCache
 335   */
 336  function & get_EnabledWidgetCache()
 337  {
 338      global $EnabledWidgetCache;
 339  
 340      if( ! isset( $EnabledWidgetCache ) )
 341      {    // Cache doesn't exist yet:
 342          // This simply instantiates a WidgetCache object, setting the
 343          // $enabled_only parameter to true. Using a member variable
 344          // instead of per-method parameters to load only the enabled
 345          // widgets should be cleaner when there will be more methods
 346          // in the WidgetCache class in the future.
 347          load_class( 'widgets/model/_widgetcache.class.php', 'WidgetCache' );
 348          $EnabledWidgetCache = new WidgetCache( true );
 349      }
 350  
 351      return $EnabledWidgetCache;
 352  }
 353  
 354  
 355  /**
 356   * adsense_Module definition
 357   */
 358  class collections_Module extends Module
 359  {
 360      /**
 361       * Do the initializations. Called from in _main.inc.php.
 362       * This is typically where classes matching DB tables for this module are registered/loaded.
 363       *
 364       * Note: this should only load/register things that are going to be needed application wide,
 365       * for example: for constructing menus.
 366       * Anything that is needed only in a specific controller should be loaded only there.
 367       * Anything that is needed only in a specific view should be loaded only there.
 368       */
 369  	function init()
 370      {
 371          $this->check_required_php_version( 'collections' );
 372  
 373          load_class( 'collections/model/_blog.class.php', 'Blog' );
 374          load_funcs( 'collections/model/_blog.funcs.php' );
 375          load_funcs( 'collections/model/_category.funcs.php' );
 376          load_funcs( 'items/model/_item.funcs.php' );
 377          load_class( 'items/model/_itemtype.class.php', 'ItemType' );
 378          load_class( 'links/model/_link.class.php', 'Link' );
 379          load_funcs( 'links/model/_link.funcs.php' );
 380          load_funcs( 'comments/model/_comment.funcs.php');
 381          load_class( 'comments/model/_commentlist.class.php', 'CommentList2' );
 382          load_class( 'items/model/_itemquery.class.php', 'ItemQuery' );
 383          load_class( 'comments/model/_commentquery.class.php', 'CommentQuery' );
 384      }
 385  
 386      /**
 387       * Get default module permissions
 388       *
 389       * @param integer Group ID
 390       * @return array
 391       */
 392  	function get_default_group_permissions( $grp_ID )
 393      {
 394          switch( $grp_ID )
 395          {
 396              case 1:        // Administrators (group ID 1) have permission by default:
 397                  $permname = 'always';
 398                  $permcreateblog = 'allowed';
 399                  $permgetblog = 'denied';
 400                  break;
 401  
 402              case 2:        // Privileged bloggers (group ID 2) have permission by default:
 403                  $permname = 'always';
 404                  $permcreateblog = 'allowed';
 405                  $permgetblog = 'allowed';
 406                  break;
 407  
 408              case 3:        // Bloggers (group ID 3) have permission by default:
 409                  $permname = 'always';
 410                  $permcreateblog = 'denied';
 411                  $permgetblog = 'denied';
 412                  break;
 413  
 414              default:
 415                  // Other groups have no permission by default
 416                  $permname = 'never';
 417                  $permcreateblog = 'denied';
 418                  $permgetblog = 'denied';
 419                  break;
 420          }
 421  
 422          // We can return as many default permissions as we want:
 423          // e.g. array ( permission_name => permission_value, ... , ... )
 424          return $permissions = array( 'perm_api' => $permname, 'perm_createblog' => $permcreateblog, 'perm_getblog' => $permgetblog );
 425      }
 426  
 427  
 428      /**
 429       * Get available group permissions
 430       *
 431       * @return array
 432       */
 433  	function get_available_group_permissions()
 434      {
 435          // 'label' is used in the group form as label for radio buttons group
 436          // 'user_func' function used to check user permission. This function should be defined in Module.
 437          // 'group_func' function used to check group permission. This function should be defined in Module.
 438          // 'perm_block' group form block where this permissions will be displayed. Now available, the following blocks: additional, system
 439          // 'options' is permission options
 440          $permissions = array(
 441              'perm_api' => array(
 442                  'label' => T_('Can use APIs'),
 443                  'user_func'  => 'check_api_user_perm',
 444                  'group_func' => 'check_api_group_perm',
 445                  'perm_block' => 'blogging',
 446                  'options'  => array(
 447                          // format: array( radio_button_value, radio_button_label, radio_button_note )
 448                          array( 'never', T_( 'Never' ), '' ),
 449                          array( 'always', T_( 'Always' ), '' ),
 450                      ),
 451                  ),
 452              'perm_createblog' => array(
 453                  'label' => T_( 'Creating new blogs' ),
 454                  'user_func'  => 'check_createblog_user_perm',
 455                  'group_func' => 'check_createblog_group_perm',
 456                  'perm_block' => 'blogging',
 457                  'perm_type' => 'checkbox',
 458                  'note' => T_( 'Users can create new blogs for themselves'),
 459                  ),
 460              'perm_getblog' => array(
 461                  'label' => '',
 462                  'user_func'  => 'check_getblog_user_perm',
 463                  'group_func' => 'check_getblog_group_perm',
 464                  'perm_block' => 'blogging',
 465                  'perm_type' => 'checkbox',
 466                  'note' => T_( 'New users automatically get a new blog'),
 467                  ),
 468              );
 469          return $permissions;
 470      }
 471  
 472  
 473      /**
 474       * Check a permission for the user. ( see 'user_func' in get_available_group_permissions() function  )
 475       *
 476       * @param string Requested permission level
 477       * @param string Permission value
 478       * @param mixed Permission target (blog ID, array of cat IDs...)
 479       * @return boolean True on success (permission is granted), false if permission is not granted
 480       */
 481  	function check_api_user_perm( $permlevel, $permvalue, $permtarget )
 482      {
 483          return true;
 484      }
 485  
 486  
 487      /**
 488       * Check a permission for the group. ( see 'group_func' in get_available_group_permissions() function )
 489       *
 490       * @param string Requested permission level
 491       * @param string Permission value
 492       * @param mixed Permission target (blog ID, array of cat IDs...)
 493       * @return boolean True on success (permission is granted), false if permission is not granted
 494       */
 495  	function check_api_group_perm( $permlevel, $permvalue, $permtarget )
 496      {
 497          $perm = false;
 498          switch ( $permvalue )
 499          {
 500              case 'always':
 501                  // Users can use APIs
 502                  if( $permlevel == 'always' )
 503                  {
 504                      $perm = true;
 505                      break;
 506                  }
 507  
 508              case 'never':
 509                  // Users can`t use APIs
 510                  if( $permlevel == 'never' )
 511                  {
 512                      $perm = false;
 513                      break;
 514                  }
 515          }
 516  
 517          return $perm;
 518      }
 519  
 520  
 521  	function check_createblog_group_perm( $permlevel, $permvalue, $permtarget )
 522      {
 523          return $permvalue == 'allowed';
 524      }
 525  
 526  	function check_getblog_group_perm( $permlevel, $permvalue, $permtarget )
 527      {
 528          return $permvalue == 'allowed';
 529      }
 530  
 531  
 532      /**
 533       * Build teh evobar menu
 534       */
 535  	function build_evobar_menu()
 536      {
 537          /**
 538           * @var Menu
 539           */
 540          global $topleft_Menu, $topright_Menu;
 541          global $current_User;
 542          global $home_url, $admin_url, $dispatcher, $debug, $seo_page_type, $robots_index;
 543          global $Blog, $blog;
 544  
 545          global $Settings;
 546  
 547          if( !$current_User->check_perm( 'admin', 'restricted' ) )
 548          {
 549              return;
 550          }
 551  
 552          $entries = array();
 553          if( $current_User->check_perm( 'blogs', 'create' ) )
 554          {
 555              $entries['newblog_sep'] = array(
 556                      'separator' => true,
 557                  );
 558  
 559              $entries['newblog'] = array(
 560                      'text' => T_('Create new blog').'&hellip;',
 561                      'href' => $admin_url.'?ctrl=collections&amp;action=new',
 562                  );
 563          }
 564          $topleft_Menu->add_menu_entries( 'blog', $entries );
 565  
 566          if( !$current_User->check_perm( 'admin', 'normal' ) )
 567          {
 568              return;
 569          }
 570  
 571          $entries = array();
 572          $entries['b2evonet'] = array(
 573                                  'text' => T_('Open b2evolution.net'),
 574                                  'href' => 'http://b2evolution.net/',
 575                                  'target' => '_blank',
 576                              );
 577          $entries['forums'] = array(
 578                                  'text' => T_('Open Support forums'),
 579                                  'href' => 'http://forums.b2evolution.net/',
 580                                  'target' => '_blank',
 581                              );
 582          $entries['manual'] = array(
 583                                  'text' => T_('Open Online manual'),
 584                                  'href' => 'http://b2evolution.net/man/',
 585                                  'target' => '_blank',
 586                              );
 587          $entries['info_sep'] = array(
 588                                  'separator' => true,
 589                              );
 590          $entries['twitter'] = array(
 591                                  'text' => T_('b2evolution on twitter'),
 592                                  'href' => 'http://twitter.com/b2evolution',
 593                                  'target' => '_blank',
 594                              );
 595          $entries['facebook'] = array(
 596                                  'text' => T_('b2evolution on facebook'),
 597                                  'href' => 'http://www.facebook.com/b2evolution',
 598                                  'target' => '_blank',
 599                              );
 600  
 601          $topleft_Menu->add_menu_entries( 'b2evo', $entries );
 602      }
 603  
 604  
 605      /**
 606       * Builds the 1st half of the menu. This is the one with the most important features
 607       */
 608  	function build_menu_1()
 609      {
 610          global $blog, $dispatcher;
 611          /**
 612           * @var User
 613           */
 614          global $current_User;
 615          global $Blog;
 616          global $Settings;
 617          /**
 618           * @var AdminUI_general
 619           */
 620          global $AdminUI;
 621  
 622          if( !$current_User->check_perm( 'admin', 'restricted' ) )
 623          { // don't show these menu entries if user hasn't at least admin restricted permission
 624              return;
 625          }
 626  
 627          if( !$current_User->check_perm( 'admin', 'normal' ) && !$current_User->check_role( 'member' ) )
 628          { // don't show these menu entries if user has only admin restricted permission, and he is not member of any blog
 629              return;
 630          }
 631  
 632          $AdminUI->add_menu_entries(
 633                  NULL, // root
 634                  array(
 635                      'dashboard' => array(
 636                          'text' => T_('Dashboard'),
 637                          'href' => $dispatcher.'?ctrl=dashboard&amp;blog='.$blog,
 638                          'style' => 'font-weight: bold;'
 639                          ),
 640  
 641                      'items' => array(
 642                          'text' => T_('Contents'),
 643                          'href' => $dispatcher.'?ctrl=items&amp;blog='.$blog.'&amp;filter=restore',
 644                          // Controller may add subtabs
 645                          ),
 646                      ) );
 647      }
 648  
 649    /**
 650       * Builds the 2nd half of the menu. This is the one with the configuration features
 651       *
 652       * At some point this might be displayed differently than the 1st half.
 653       */
 654  	function build_menu_2()
 655      {
 656          global $blog, $loc_transinfo, $ctrl, $dispatcher;
 657          /**
 658           * @var User
 659           */
 660          global $current_User;
 661          global $Blog;
 662          /**
 663           * @var AdminUI_general
 664           */
 665          global $AdminUI;
 666  
 667          if( !$current_User->check_perm( 'admin', 'normal' ) )
 668          {
 669              return;
 670          }
 671  
 672          // BLOG SETTINGS:
 673          if( $ctrl == 'collections' )
 674          { // We are viewing the blog list, nothing fancy involved:
 675              $AdminUI->add_menu_entries(
 676                      NULL, // root
 677                      array(
 678                          'blogs' => array(
 679                              'text' => T_('Blogs'),
 680                              'href' => $dispatcher.'?ctrl=collections',
 681                              'entries' => array(
 682                                  'list' => array(
 683                                      'text' => T_('List'),
 684                                      'href' => $dispatcher.'?ctrl=collections',
 685                                  ),
 686                              )
 687                          ),
 688                      ), 'dashboard' );
 689              if( $current_User->check_perm( 'options', 'view' ) )
 690              {
 691                  $AdminUI->add_menu_entries( 'blogs', array(
 692                          'settings' => array(
 693                              'text' => T_('Settings'),
 694                              'href' => $dispatcher.'?ctrl=collections&amp;tab=settings',
 695                          ),
 696                      ) );
 697              }
 698          }
 699          else
 700          {    // We're on any other page, we may have a direct destination
 701            // + we have subtabs (fp > maybe the subtabs should go into the controller as for _items ?)
 702  
 703              // What perms do we have?
 704              $coll_settings_perm = $current_User->check_perm( 'blog_properties', 'any', false, $blog );
 705  
 706              // Determine default page based on permissions:
 707              if( $coll_settings_perm )
 708              {    // Default: show General Blog Settings
 709                  $default_page = $dispatcher.'?ctrl=coll_settings&amp;blog='.$blog;
 710              }
 711              else
 712              {    // Default: Show list of blogs
 713                  $default_page = $dispatcher.'?ctrl=collections';
 714              }
 715  
 716              $AdminUI->add_menu_entries(
 717                      NULL, // root
 718                      array(
 719                          'blogs' => array(
 720                              'text' => T_('Blogs'),
 721                              'href' => $default_page,
 722                              ),
 723                          ), 'dashboard' );
 724  
 725              if( $coll_settings_perm )
 726              {
 727                  $skin_entries['current_skin'] = array(
 728                              'text' => T_('Skins for this blog'),
 729                              'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=skin&amp;blog='.$blog );
 730  
 731                  if( $current_User->check_perm( 'options', 'view' ) )
 732                  {
 733                      $skin_entries['manage_skins'] = array(
 734                              'text' => T_('Manage skins'),
 735                              'href' => $dispatcher.'?ctrl=skins&amp;blog='.$blog );
 736                  }
 737  
 738                  $AdminUI->add_menu_entries( 'blogs',    array(
 739                              'general' => array(
 740                                  'text' => T_('General'),
 741                                  'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=general&amp;blog='.$blog, ),
 742                              'features' => array(
 743                                  'text' => T_('Features'),
 744                                  'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=features&amp;blog='.$blog,
 745                                  'entries' => array(
 746                                      'features' => array(
 747                                          'text' => T_('Posts'),
 748                                          'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=features&amp;blog='.$blog ),
 749                                      'comments' => array(
 750                                          'text' => T_('Comments'),
 751                                          'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=comments&amp;blog='.$blog ),
 752                                      'other' => array(
 753                                          'text' => T_('Other'),
 754                                          'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=other&amp;blog='.$blog ),
 755                                  ),
 756                              ),
 757                              'skin' => array(
 758                                  'text' => T_('Skin'),
 759                                  'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=skin&amp;blog='.$blog,
 760                                  'entries' => $skin_entries,
 761                              ),
 762                              'plugin_settings' => array(
 763                                  'text' => T_('Plugins'),
 764                                  'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=plugin_settings&amp;blog='.$blog, ),
 765                              'widgets' => array(
 766                                  'text' => T_('Widgets'),
 767                                  'href' => $dispatcher.'?ctrl=widgets&amp;blog='.$blog, ),
 768                              'urls' => array(
 769                                  'text' => T_('URLs'),
 770                                  'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=urls&amp;blog='.$blog, ),
 771                              'seo' => array(
 772                                  'text' => T_('SEO'),
 773                                  'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=seo&amp;blog='.$blog, ),
 774                              'advanced' => array(
 775                                  'text' => T_('Advanced'),
 776                                  'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=advanced&amp;blog='.$blog, ),
 777                          ) );
 778  
 779                  if( $Blog && $Blog->advanced_perms )
 780                  {
 781                      $AdminUI->add_menu_entries( 'blogs', array(
 782                                  'perm' => array(
 783                                      'text' => T_('User perms'), // keep label short
 784                                      'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=perm&amp;blog='.$blog, ),
 785                                  'permgroup' => array(
 786                                      'text' => T_('Group perms'), // keep label short
 787                                      'href' => $dispatcher.'?ctrl=coll_settings&amp;tab=permgroup&amp;blog='.$blog, ),
 788                              ) );
 789                  }
 790              }
 791          }
 792      }
 793  
 794  
 795      /**
 796       * Builds the 3rd half of the menu. This is the one with the configuration features
 797       *
 798       * At some point this might be displayed differently than the 1st half.
 799       */
 800  	function build_menu_3()
 801      {
 802          global $blog, $loc_transinfo, $ctrl, $dispatcher;
 803          /**
 804           * @var User
 805           */
 806          global $current_User;
 807          global $Blog;
 808          /**
 809           * @var AdminUI_general
 810           */
 811          global $AdminUI;
 812  
 813          if( !$current_User->check_perm( 'admin', 'normal' ) )
 814          {
 815              return;
 816          }
 817  
 818          if( $current_User->check_perm( 'options', 'view' ) )
 819          {    // Permission to view settings:
 820              $AdminUI->add_menu_entries( 'options', array(
 821                      'misc' => array(
 822                          'text' => T_('Maintenance'),
 823                          'href' => $dispatcher.'?ctrl=tools',
 824                          'entries' => array(
 825                              'tools' => array(
 826                                  'text' => T_('Tools'),
 827                                  'href' => $dispatcher.'?ctrl=tools' ),
 828                              'import' => array(
 829                                  'text' => T_('Import'),
 830                                  'href' => $dispatcher.'?ctrl=tools&amp;tab3=import' ),
 831                              'test' => array(
 832                                  'text' => T_('Testing'),
 833                                  'href' => $dispatcher.'?ctrl=tools&amp;tab3=test' ),
 834                              'backup' => array(
 835                                  'text' => T_('Backup'),
 836                                  'href' => $dispatcher.'?ctrl=backup' ),
 837                              'upgrade' => array(
 838                                  'text' => T_('Check for updates'),
 839                                  'href' => $dispatcher.'?ctrl=upgrade' ),
 840                              ),
 841                  ) ) );
 842  
 843          }
 844  
 845      }
 846  
 847  
 848      /**
 849       * Handle collections module htsrv actions
 850       */
 851  	function handle_htsrv_action()
 852      {
 853          global $demo_mode, $current_User, $DB, $Session, $Messages;
 854          global $UserSettings, $samedomain_htsrv_url;
 855  
 856          if( !is_logged_in() )
 857          { // user must be logged in
 858              bad_request_die( $this->T_( 'You are not logged in.' ) );
 859          }
 860  
 861          // Init the objects we want to work on.
 862          $action = param_action( true );
 863  
 864          // Check that this action request is not a CSRF hacked request:
 865          $Session->assert_received_crumb( 'collections_'.$action );
 866  
 867          switch( $action )
 868          {
 869              case 'unlink':
 870                  // Unlink a file from a LinkOwner ( Item, Comment ) object, and delete that file if it's not linked to any other object
 871  
 872                  $link_ID = param( 'link_ID', 'integer', true );
 873                  $redirect_to = param( 'redirect_to', 'url', '' );
 874                  $LinkCache = & get_LinkCache();
 875                  $edited_Link = & $LinkCache->get_by_ID( $link_ID, false );
 876  
 877                  if( !$edited_Link )
 878                  { // the edited Link object doesn't exists
 879                      $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('Link') ), 'error' );
 880                      header_redirect();
 881                  }
 882  
 883                  // We have a link, get the LinkOwner it is attached to:
 884                  $LinkOwner = & $edited_Link->get_LinkOwner();
 885                  $linked_File = & $edited_Link->get_File();
 886  
 887                  // Load the blog we're in:
 888                  $Blog = & $LinkOwner->get_Blog();
 889                  set_working_blog( $Blog->ID );
 890  
 891                  // Check permission:
 892                  $LinkOwner->check_perm( 'edit', true );
 893  
 894                  $confirmed = param( 'confirmed', 'integer', 0 );
 895                  if( $confirmed )
 896                  { // Unlink File from Item:
 897                      $edited_Link->dbdelete( true );
 898                      unset($edited_Link);
 899                      $Messages->add( $LinkOwner->translate( 'Link has been deleted from $ownerTitle$.' ), 'success' );
 900                      if( $current_User->check_perm( 'files', 'edit' ) )
 901                      { // current User has permission to edit/delete files
 902                          $file_name = $linked_File->get_name();
 903                          // Get number of objects where this file is attahced to
 904                          // TODO: attila>this must be handled with a different function
 905                          $file_links = get_file_links( $linked_File->ID, array( 'separator' => '<br />' ) );
 906                          $links_count = ( strlen( $file_links ) > 0 ) ? substr_count( $file_links, '<br />' ) + 1 : 0;
 907                          if( $links_count > 0 )
 908                          { // File is linked to other objects
 909                              $Messages->add( sprintf( T_('File %s is still linked to %d other objects'), $file_name, $links_count ), 'note' );
 910                          }
 911                          else
 912                          { // File is not linked to other objects
 913                              if( $linked_File->unlink() )
 914                              { // File removed successful ( removed from db and from storage device also )
 915                                  $Messages->add( sprintf( T_('File %s has been deleted.'), $file_name ), 'success' );
 916                              }
 917                              else
 918                              { // Could not completly remove the file
 919                                  $Messages->add( sprintf( T_('File %s could not be deleted.'), $file_name ), 'error' );
 920                              }
 921                          }
 922                      }
 923                  }
 924                  else
 925                  { // Display confirm unlink/delete message
 926                      $delete_url = $samedomain_htsrv_url.'action.php?mname=collections&action=unlink&link_ID='.$edited_Link->ID.'&confirmed=1&crumb_collections_unlink='.get_crumb( 'collections_unlink' );
 927                      $ok_button = '<span class="linkbutton"><a href="'.$delete_url.'">'.T_( 'I am sure!' ).'!</a></span>';
 928                      $cancel_button = '<span class="linkbutton"><a href="'.$redirect_to.'">CANCEL</a></span>';
 929                      $msg = sprintf( T_( 'You are about to unlink and delete the attached file from %s path.' ), $linked_File->get_root_and_rel_path() );
 930                      $msg .= '<br />'.T_( 'This CANNOT be undone!').'<br />'.T_( 'Are you sure?' ).'<br /><br />'.$ok_button."\t".$cancel_button;
 931                      $Messages->add( $msg, 'error' );
 932                  }
 933                  header_redirect( $redirect_to );
 934                  break;
 935  
 936              case 'isubs_update':
 937                  // Subscribe/Unsubscribe user on the selected item
 938  
 939                  if( $demo_mode && ( $current_User->ID <= 3 ) )
 940                  { // don't allow default users profile change on demo mode
 941                      bad_request_die( 'Demo mode: you can\'t edit the admin and demo users profile!<br />[<a href="javascript:history.go(-1)">'
 942                                  . T_('Back to profile') . '</a>]' );
 943                  }
 944  
 945                  // Get params
 946                  $item_ID = param( 'p', 'integer', true );
 947                  $notify = param( 'notify', 'integer', 0 );
 948  
 949                  if( ( $notify < 0 ) || ( $notify > 1 ) )
 950                  { // Invalid notify param. It should be 0 for unsubscribe and 1 for subscribe.
 951                      $Messages->add( 'Invalid params!', 'error' );
 952                  }
 953  
 954                  if( ! is_email( $current_User->get( 'email' ) ) )
 955                  { // user doesn't have a valid email address
 956                      $Messages->add( T_( 'Your email address is invalid. Please set your email address first.' ), 'error' );
 957                  }
 958  
 959                  if( $Messages->has_errors() )
 960                  { // errors detected
 961                      header_redirect();
 962                      // already exited here
 963                  }
 964  
 965                  if( set_user_isubscription( $current_User->ID, $item_ID, $notify ) )
 966                  {
 967                      if( $notify == 0 )
 968                      {
 969                          $Messages->add( T_( 'You have successfully unsubscribed.' ), 'success' );
 970                      }
 971                      else
 972                      {
 973                          $Messages->add( T_( 'You have successfully subscribed to notifications.' ), 'success' );
 974                      }
 975                  }
 976                  else
 977                  {
 978                      $Messages->add( T_( 'Could not subscribe to notifications.' ), 'error' );
 979                  }
 980  
 981                  header_redirect();
 982                  break; // already exited here
 983          }
 984      }
 985  }
 986  
 987  $collections_Module = new collections_Module();
 988  
 989  ?>

title

Description

title

Description

title

Description

title

title

Body