b2evolution PHP Cross Reference Blogging Systems

Source: /inc/widgets/widgets/_msg_menu_link.widget.php - 281 lines - 8218 bytes - Summary - Text - Print

Description: This file implements the msg_menu_link_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 msg_menu_link_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 efy-asimo: Attila Simo
  23   *
  24   * @version $Id: _msg_menu_link.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  global $msg_menu_link_widget_link_types;
  31  $msg_menu_link_widget_link_types = array(
  32          'messages' => T_( 'Messages' ),
  33          'contacts' => T_( 'Contacts' ),
  34      );
  35  
  36  /**
  37   * ComponentWidget Class
  38   *
  39   * A ComponentWidget is a displayable entity that can be placed into a Container on a web page.
  40   *
  41   * @package evocore
  42   */
  43  class msg_menu_link_Widget extends ComponentWidget
  44  {
  45      /**
  46       * Constructor
  47       */
  48  	function msg_menu_link_Widget( $db_row = NULL )
  49      {
  50          // Call parent constructor:
  51          parent::ComponentWidget( $db_row, 'core', 'msg_menu_link' );
  52      }
  53  
  54  
  55      /**
  56       * Get name of widget
  57       */
  58  	function get_name()
  59      {
  60          return T_('Messaging Menu link');
  61      }
  62  
  63  
  64      /**
  65       * Get a very short desc. Used in the widget list.
  66       */
  67  	function get_short_desc()
  68      {
  69          global $msg_menu_link_widget_link_types;
  70  
  71          $this->load_param_array();
  72  
  73          if( !empty($this->param_array['link_type']) )
  74          {    // Messaging or Contacts
  75              return sprintf( T_( '%s link' ), $msg_menu_link_widget_link_types[$this->param_array['link_type']] );
  76          }
  77  
  78          return $this->get_name();
  79      }
  80  
  81  
  82      /**
  83       * Get short description
  84       */
  85  	function get_desc()
  86      {
  87          return T_('Messages or Contacts menu entry/link');
  88      }
  89  
  90  
  91      /**
  92       * Get definitions for editable params
  93       *
  94       * @see Plugin::GetDefaultSettings()
  95       * @param local params like 'for_editing' => true
  96       */
  97  	function get_param_definitions( $params )
  98      {
  99          global $msg_menu_link_widget_link_types;
 100  
 101          $r = array_merge( array(
 102                  'link_type' => array(
 103                      'label' => T_( 'Link Type' ),
 104                      'note' => T_('What do you want to link to?'),
 105                      'type' => 'select',
 106                      'options' => $msg_menu_link_widget_link_types,
 107                      'defaultvalue' => 'messages',
 108                      'onchange' => '
 109                          var curr_link_type = this.value;
 110                          var allow_blockcache = jQuery("[id$=\'_set_allow_blockcache\']");
 111                          var show_badge = jQuery("[id$=\'_set_show_badge\']");
 112                          if( curr_link_type == "messages" )
 113                          {
 114                              allow_blockcache.removeAttr(\'checked\');
 115                              allow_blockcache.attr( \'disabled\', \'disabled\' );
 116                              show_badge.removeAttr(\'disabled\');
 117                              show_badge.attr( \'checked\', \'checked\' );
 118                          }
 119                          else
 120                          {
 121                              allow_blockcache.removeAttr(\'disabled\');
 122                              show_badge.attr( \'disabled\', \'disabled\' );
 123                              allow_blockcache.attr( \'checked\', \'checked\' );
 124                              show_badge.removeAttr(\'checked\');
 125                          };'
 126                  ),
 127                  'link_text' => array(
 128                      'label' => T_( 'Link text' ),
 129                      'note' => T_('Text to use for the link (leave empty for default).'),
 130                      'type' => 'text',
 131                      'size' => 20,
 132                      'defaultvalue' => '',
 133                  ),
 134                  'show_to' => array(
 135                      'label' => T_( 'Show to' ),
 136                      'note' => '',
 137                      'type' => 'radio',
 138                      'options' => array( array( 'any', T_( 'All users') ),
 139                                          array( 'loggedin', T_( 'Logged in users' ) ),
 140                                          array( 'perms', T_( 'Users with messaging permissions only' ) ) ),
 141                      'defaultvalue' => 'perms',
 142                  ),
 143                  'show_badge' => array(
 144                      'label' => T_( 'Show Badge' ),
 145                      'note' => T_( 'Show a badge with the count of unread messages.' ),
 146                      'type' => 'checkbox',
 147                      'defaultvalue' => true,
 148                  ),
 149              ), parent::get_param_definitions( $params )    );
 150  
 151          // Do not modify anything during update because the editing form contains all of the required modifications
 152          if( !isset( $params['for_updating'] ) )
 153          { // Not called from the update process
 154              // Turn off allow blockcache by default, because it is forbidden in case of messages
 155              // Note: we may call $this->get_param() only if this function was not called from there. This way we prevent infinite recursion/loop.
 156              $link_type = ( empty( $this->params ) || isset( $params['infinite_loop'] ) ) ? 'messages' : $this->get_param( 'link_type', true );
 157              if( $link_type == 'contacts' )
 158              {
 159                  $r['show_badge']['defaultvalue'] = false;
 160                  $r['show_badge']['disabled'] = 'disabled';
 161                  if( ! empty( $this->params ) && ! isset( $params['infinite_loop'] ) )
 162                  { // Force show_badge to false! It is never allowed to be on, no matter what was set in the database.
 163                      $this->set( 'show_badge', false );
 164                  }
 165              }
 166              else
 167              {
 168                  $r['allow_blockcache']['defaultvalue'] = false;
 169                  $r['allow_blockcache']['disabled'] = 'disabled';
 170                  if( ! empty( $this->params ) && ! isset( $params['infinite_loop'] ) )
 171                  { // Force allow_blockache to false! It is never allowed to be on, no matter what was set in the database.
 172                      $this->set( 'allow_blockcache', false );
 173                  }
 174              }
 175          }
 176  
 177          return $r;
 178      }
 179  
 180      /**
 181       * Display the widget!
 182       *
 183       * @param array MUST contain at least the basic display params
 184       */
 185  	function display( $params )
 186      {
 187          /**
 188          * @var Blog
 189          */
 190          global $Blog;
 191  
 192          global $current_User, $unread_messages_count;
 193          global $disp;
 194  
 195          $this->init_display( $params );
 196  
 197          switch( $this->disp_params['show_to'] )
 198          {
 199              case 'any':
 200                  break;
 201              case 'loggedin':
 202                  if( !is_logged_in() )
 203                  {
 204                      return false;
 205                  }
 206                  break;
 207              case 'perms':
 208                  if( !is_logged_in() || !$current_User->check_perm( 'perm_messaging', 'reply', false ) )
 209                  {
 210                      return false;
 211                  }
 212                  break; // display
 213              case 'default':
 214                  debug_die( 'Invalid params!' );
 215          }
 216  
 217          // Default link class
 218          $link_class = $this->disp_params['link_default_class'];
 219  
 220          switch(    $this->disp_params[ 'link_type' ] )
 221          {
 222              case 'messages':
 223                  $url = get_dispctrl_url( 'threads' );
 224                  $text = T_( 'Messages' );
 225                  // set allow blockcache to 0, this way make sure block cache is never allowed for messages
 226                  $this->disp_params[ 'allow_blockcache' ] = 0;
 227                  // Is this the current display?
 228                  if( $disp == 'threads' )
 229                  {    // The current page is currently displaying the messages:
 230                      // Let's display it as selected
 231                      $link_class = $this->disp_params['link_selected_class'];
 232                  }
 233                  break;
 234  
 235              case 'contacts':
 236                  $url = get_dispctrl_url( 'contacts' );
 237                  $text = T_( 'Contacts' );
 238                  // set show badge to 0, this way make sure badge won't be displayed
 239                  $this->disp_params[ 'show_badge' ] = 0;
 240                  // Is this the current display?
 241                  if( $disp == 'contacts' )
 242                  {    // The current page is currently displaying the contacts:
 243                      // Let's display it as selected
 244                      $link_class = $this->disp_params['link_selected_class'];
 245                  }
 246                  break;
 247          }
 248  
 249          if( !empty( $this->disp_params[ 'link_text' ] ) )
 250          {
 251              $text = $this->disp_params[ 'link_text' ];
 252          }
 253  
 254          if( ( $this->disp_params[ 'show_badge' ] ) && ( $unread_messages_count > 0 ) )
 255          {
 256              $badge = ' <span class="badge">'.$unread_messages_count.'</span>';
 257              if( isset( $this->BlockCache ) )
 258              { // Do not cache if bage is displayed because the number of unread messages are always changing
 259                  $this->BlockCache->abort_collect();
 260              }
 261          }
 262          else
 263          {
 264              $badge = '';
 265          }
 266  
 267          echo $this->disp_params['block_start'];
 268          echo $this->disp_params['list_start'];
 269  
 270          echo $this->disp_params['item_start'];
 271          echo '<a href="'.$url.'" class="'.$link_class.'">'.$text.$badge.'</a>';
 272          echo $this->disp_params['item_end'];
 273  
 274          echo $this->disp_params['list_end'];
 275          echo $this->disp_params['block_end'];
 276  
 277          return true;
 278      }
 279  }
 280  
 281  ?>

title

Description

title

Description

title

Description

title

title

Body