b2evolution PHP Cross Reference Blogging Systems

Source: /inc/widgets/widgets/_user_tools.widget.php - 370 lines - 12248 bytes - Summary - Text - Print

Description: This file implements the xyz Widget class. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the xyz Widget class.
   4   *
   5   * This file is part of the evoCore framework - {@link http://evocore.net/}
   6   * See also {@link http://sourceforge.net/projects/evocms/}.
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   *
  10   * {@internal License choice
  11   * - If you have received this file as part of a package, please find the license.txt file in
  12   *   the same folder or the closest folder above for complete license terms.
  13   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  14   *   then you must choose one of the following licenses before using the file:
  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  17   * }}
  18   *
  19   * @package evocore
  20   *
  21   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  22   * @author fplanque: Francois PLANQUE.
  23   *
  24   * @version $Id: _user_tools.widget.php 6136 2014-03-08 07:59:48Z manuel $
  25   */
  26  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  27  
  28  load_class( 'widgets/model/_widget.class.php', 'ComponentWidget' );
  29  
  30  /**
  31   * ComponentWidget Class
  32   *
  33   * A ComponentWidget is a displayable entity that can be placed into a Container on a web page.
  34   *
  35   * @package evocore
  36   */
  37  class user_tools_Widget extends ComponentWidget
  38  {
  39      /**
  40       * Constructor
  41       */
  42  	function user_tools_Widget( $db_row = NULL )
  43      {
  44          // Call parent constructor:
  45          parent::ComponentWidget( $db_row, 'core', 'user_tools' );
  46      }
  47  
  48  
  49    /**
  50     * Get definitions for editable params
  51     *
  52       * @see Plugin::GetDefaultSettings()
  53       * @param local params like 'for_editing' => true
  54       */
  55  	function get_param_definitions( $params )
  56      {
  57          $r = array_merge( array(
  58              'title' => array(
  59                  'label' => T_('Block title'),
  60                  'note' => T_( 'Title to display in your skin.' ),
  61                  'size' => 40,
  62                  'defaultvalue' => T_('User tools'),
  63              ),
  64              // Write new post - disp=edit
  65              'user_postnew_link_show' => array(
  66                  'label' => T_( 'Write a new post link'),
  67                  'note' => T_( 'Show link' ),
  68                  'type' => 'checkbox',
  69                  'defaultvalue' => 1,
  70              ),
  71              'user_postnew_link' => array(
  72                  'size' => 30,
  73                  'note' => T_( 'Link text to display' ),
  74                  'type' => 'text',
  75                  'defaultvalue' => T_( 'Write a new post...' ),
  76              ),
  77              // Messaging - disp=threads
  78              'user_messaging_link_show' => array(
  79                  'label' => T_( 'Messaging area link'),
  80                  'note' => T_( 'Show link' ),
  81                  'type' => 'checkbox',
  82                  'defaultvalue' => 1,
  83              ),
  84              'show_badge' => array(
  85                  'label' => T_( 'Show Badge' ),
  86                  'note' => T_( 'Show a badge with the count of unread messages.' ),
  87                  'type' => 'checkbox',
  88                  'defaultvalue' => true,
  89              ),
  90              'user_messaging_link' => array(
  91                  'size' => 30,
  92                  'note' => T_( 'Link text to display' ),
  93                  'type' => 'text',
  94                  'defaultvalue' => T_( 'My messages' ),
  95              ),
  96              // Contacts - disp=contacts
  97              'user_contacts_link_show' => array(
  98                  'label' => T_( 'Contacts link'),
  99                  'note' => T_( 'Show link' ),
 100                  'type' => 'checkbox',
 101                  'defaultvalue' => 1,
 102              ),
 103              'user_contacts_link' => array(
 104                  'size' => 30,
 105                  'note' => T_( 'Link text to display' ),
 106                  'type' => 'text',
 107                  'defaultvalue' => T_( 'My contacts' ),
 108              ),
 109              // See profile - disp=user
 110              'user_view_link_show' => array(
 111                  'label' => T_( 'See profile link'),
 112                  'note' => T_( 'Show link' ),
 113                  'type' => 'checkbox',
 114                  'defaultvalue' => 1,
 115              ),
 116              'user_view_link' => array(
 117                  'size' => 30,
 118                  'note' => T_( 'Link text to display' ),
 119                  'type' => 'text',
 120                  'defaultvalue' => T_( 'My profile' ),
 121              ),
 122              // Edit profile - disp=profile
 123              'user_profile_link_show' => array(
 124                  'label' => T_( 'Edit profile link'),
 125                  'note' => T_( 'Show link' ),
 126                  'type' => 'checkbox',
 127                  'defaultvalue' => 1,
 128              ),
 129              'user_profile_link' => array(
 130                  'size' => 30,
 131                  'note' => T_( 'Link text to display' ),
 132                  'type' => 'text',
 133                  'defaultvalue' => T_( 'Edit my profile' ),
 134              ),
 135              // Edit picture - disp=avatar
 136              'user_picture_link_show' => array(
 137                  'label' => T_( 'Edit profile picture link'),
 138                  'note' => T_( 'Show link' ),
 139                  'type' => 'checkbox',
 140                  'defaultvalue' => 1,
 141              ),
 142              'user_picture_link' => array(
 143                  'size' => 30,
 144                  'note' => T_( 'Link text to display' ),
 145                  'type' => 'text',
 146                  'defaultvalue' => T_( 'Change my picture' ),
 147              ),
 148              // Edit password - disp=pwdchange
 149              'user_password_link_show' => array(
 150                  'label' => T_( 'Edit password link'),
 151                  'note' => T_( 'Show link' ),
 152                  'type' => 'checkbox',
 153                  'defaultvalue' => 0,
 154              ),
 155              'user_password_link' => array(
 156                  'size' => 30,
 157                  'note' => T_( 'Link text to display' ),
 158                  'type' => 'text',
 159                  'defaultvalue' => T_( 'Change my password' ),
 160              ),
 161              // Edit preferences - disp=userprefs
 162              'user_preferences_link_show' => array(
 163                  'label' => T_( 'Edit preferences link'),
 164                  'note' => T_( 'Show link' ),
 165                  'type' => 'checkbox',
 166                  'defaultvalue' => 0,
 167              ),
 168              'user_preferences_link' => array(
 169                  'size' => 30,
 170                  'note' => T_( 'Link text to display' ),
 171                  'type' => 'text',
 172                  'defaultvalue' => T_( 'Change my preferences' ),
 173              ),
 174              // Edit notifications - disp=subs
 175              'user_subs_link_show' => array(
 176                  'label' => T_( 'Edit notifications link'),
 177                  'note' => T_( 'Show link' ),
 178                  'type' => 'checkbox',
 179                  'defaultvalue' => 0,
 180              ),
 181              'user_subs_link' => array(
 182                  'size' => 30,
 183                  'note' => T_( 'Link text to display' ),
 184                  'type' => 'text',
 185                  'defaultvalue' => T_( 'Notifications &amp; Subscriptions' ),
 186              ),
 187              // Admin
 188              'user_admin_link_show' => array(
 189                  'label' => T_( 'Admin link'),
 190                  'note' => T_( 'Show link' ),
 191                  'type' => 'checkbox',
 192                  'defaultvalue' => 1,
 193              ),
 194              'user_admin_link' => array(
 195                  'size' => 30,
 196                  'note' => T_( 'Link text to display' ),
 197                  'type' => 'text',
 198                  'defaultvalue' => T_( 'Admin area' ),
 199              ),
 200              // Logout
 201              'user_logout_link_show' => array(
 202                  'label' => T_( 'Logout link'),
 203                  'note' => T_( 'Show link' ),
 204                  'type' => 'checkbox',
 205                  'defaultvalue' => 1,
 206              ),
 207              'user_logout_link' => array(
 208                  'size' => 30,
 209                  'note' => T_( 'Link text to display' ),
 210                  'type' => 'text',
 211                  'defaultvalue' => T_( 'Logout' ),
 212              ),
 213          ), parent::get_param_definitions( $params )    );
 214  
 215          if( isset( $r['allow_blockcache'] ) )
 216          { // Set default blockcache to false and disable this setting because caching is never allowed for this widget
 217              $r['allow_blockcache']['defaultvalue'] = false;
 218              $r['allow_blockcache']['disabled'] = 'disabled';
 219              if( ! empty( $this->params ) && ( ! isset( $params['infinite_loop'] ) ) )
 220              { // Force allow_blockache to false! It is never allowed to be on, no matter what was set in the database.
 221                  $this->set( 'allow_blockcache', false );
 222              }
 223          }
 224  
 225          return $r;
 226      }
 227  
 228      /**
 229       * Get name of widget
 230       */
 231  	function get_name()
 232      {
 233          return T_('User Tools');
 234      }
 235  
 236  
 237      /**
 238       * Get a very short desc. Used in the widget list.
 239       */
 240  	function get_short_desc()
 241      {
 242          return format_to_output($this->disp_params['title']);
 243      }
 244  
 245  
 246    /**
 247       * Get short description
 248       */
 249  	function get_desc()
 250      {
 251          return T_('Display user tools: Log in, Admin, Profile, Subscriptions, Log out');
 252      }
 253  
 254  
 255      /**
 256       * Display the widget!
 257       *
 258       * @param array MUST contain at least the basic display params
 259       */
 260  	function display( $params )
 261      {
 262          if( !is_logged_in() )
 263          {    // Only logged in users can see this tools panel
 264              return false;
 265          }
 266  
 267          $this->init_display( $params ); // just in case it hasn't been done before
 268  
 269          $this->disp_params['item_start'] .= '<strong>';
 270          $this->disp_params['item_end'] = '</strong>'.$this->disp_params['item_end'];
 271  
 272          $tools_links = '';
 273          if( $this->get_param('user_postnew_link_show') )
 274          {    // Write new post - disp=edit
 275              $tools_links .= get_item_new_link( $this->disp_params['item_start'], $this->disp_params['item_end'], $this->disp_params[ 'user_postnew_link' ] );
 276          }
 277          if( $this->get_param('user_messaging_link_show') )
 278          {    // Messaging - disp=threads
 279              $tools_links .= get_user_messaging_link( $this->disp_params['item_start'], $this->disp_params['item_end'], $this->disp_params[ 'user_messaging_link' ], $this->disp_params[ 'user_messaging_link' ], $this->disp_params[ 'show_badge' ] );
 280          }
 281          if( $this->get_param('user_contacts_link_show') )
 282          {    // Contacts - disp=contacts
 283              $tools_links .= get_user_contacts_link( $this->disp_params['item_start'], $this->disp_params['item_end'], $this->disp_params[ 'user_contacts_link' ], $this->disp_params[ 'user_contacts_link' ] );
 284          }
 285          if( $this->get_param('user_view_link_show') )
 286          {    // See profile - disp=user
 287              $tools_links .= get_user_tab_link( 'user', $this->disp_params['item_start'], $this->disp_params['item_end'], $this->disp_params[ 'user_view_link' ], $this->disp_params[ 'user_view_link' ] );
 288          }
 289          if( $this->get_param('user_profile_link_show') )
 290          {    // Edit profile - disp=profile
 291              $tools_links .= get_user_profile_link( $this->disp_params['item_start'], $this->disp_params['item_end'], $this->disp_params[ 'user_profile_link' ], $this->disp_params[ 'user_profile_link' ] );
 292          }
 293          if( $this->get_param('user_picture_link_show') )
 294          {    // Edit picture - disp=avatar
 295              $tools_links .= get_user_tab_link( 'avatar', $this->disp_params['item_start'], $this->disp_params['item_end'], $this->disp_params[ 'user_picture_link' ], $this->disp_params[ 'user_picture_link' ] );
 296          }
 297          if( $this->get_param('user_password_link_show') )
 298          {    // Edit password - disp=pwdchange
 299              $tools_links .= get_user_tab_link( 'pwdchange', $this->disp_params['item_start'], $this->disp_params['item_end'], $this->disp_params[ 'user_password_link' ], $this->disp_params[ 'user_password_link' ] );
 300          }
 301          if( $this->get_param('user_preferences_link_show') )
 302          {    // Edit preferences - disp=userprefs
 303              $tools_links .= get_user_tab_link( 'userprefs', $this->disp_params['item_start'], $this->disp_params['item_end'], $this->disp_params[ 'user_preferences_link' ], $this->disp_params[ 'user_preferences_link' ] );
 304          }
 305          if( $this->get_param('user_subs_link_show') )
 306          {    // Edit notifications - disp=subs
 307              $tools_links .= get_user_subs_link( $this->disp_params['item_start'], $this->disp_params['item_end'], $this->disp_params[ 'user_subs_link' ], $this->disp_params[ 'user_subs_link' ] );
 308          }
 309          if( $this->get_param('user_admin_link_show') )
 310          {    // Admin
 311              $tools_links .= get_user_admin_link( $this->disp_params['item_start'], $this->disp_params['item_end'], $this->disp_params[ 'user_admin_link' ] );
 312          }
 313          if( $this->get_param('user_logout_link_show') )
 314          {    // Logout
 315              $tools_links .= get_user_logout_link( $this->disp_params['item_start'], $this->disp_params['item_end'], $this->disp_params[ 'user_logout_link' ] );
 316          }
 317  
 318          if( empty( $tools_links ) )
 319          {    // No available links to display
 320              return false;
 321          }
 322  
 323          // User tools:
 324          echo $this->disp_params['block_start'];
 325  
 326          if( !empty( $this->disp_params['title'] ) )
 327          {    // Display title
 328              echo $this->disp_params['block_title_start'];
 329              echo $this->disp_params['title'];
 330              echo $this->disp_params['block_title_end'];
 331          }
 332  
 333          echo $this->disp_params['list_start'];
 334  
 335          echo $tools_links;
 336  
 337          if( isset($this->BlockCache) )
 338          {    // Do NOT cache because some of these links are using a redirect_to param, which makes it page dependent.
 339              // Note: also beware of the source param.
 340              // so this will be cached by the PageCache; there is no added benefit to cache it in the BlockCache
 341              // (which could have been shared between several pages):
 342              $this->BlockCache->abort_collect();
 343          }
 344  
 345          echo $this->disp_params['list_end'];
 346  
 347          echo $this->disp_params['block_end'];
 348      }
 349  
 350  
 351      /**
 352       * Maybe be overriden by some widgets, depending on what THEY depend on..
 353       *
 354       * @return array of keys this widget depends on
 355       */
 356  	function get_cache_keys()
 357      {
 358          global $Blog, $current_User;
 359  
 360          return array(
 361                  'wi_ID'   => $this->ID,                    // Have the widget settings changed ?
 362                  'set_coll_ID' => $Blog->ID,            // Have the settings of the blog changed ? (ex: new owner, new skin)
 363                  'loggedin' => (is_logged_in() ? 1 : 0),
 364                  // fp> note: if things get tough in the future, use a per User caching scheme:
 365                  // 'user_ID' => (is_logged_in() ? $current_User->ID : 0), // Has the current User changed?
 366              );
 367      }
 368  }
 369  
 370  ?>

title

Description

title

Description

title

Description

title

title

Body