b2evolution PHP Cross Reference Blogging Systems

Source: /inc/widgets/widgets/_coll_media_index.widget.php - 345 lines - 10190 bytes - Summary - Text - Print

Description: This file implements the Media Index 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 Media Index 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   * @author Yabba    - {@link http://www.astonishme.co.uk/}
  24   *
  25   * @version $Id: _coll_media_index.widget.php 6136 2014-03-08 07:59:48Z manuel $
  26   */
  27  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  28  
  29  load_class( 'widgets/model/_widget.class.php', 'ComponentWidget' );
  30  load_class( '_core/model/dataobjects/_dataobjectlist2.class.php', 'DataObjectList2' );
  31  
  32  /**
  33   * ComponentWidget Class
  34   *
  35   * A ComponentWidget is a displayable entity that can be placed into a Container on a web page.
  36   *
  37   * @package evocore
  38   */
  39  class coll_media_index_Widget extends ComponentWidget
  40  {
  41      /**
  42       * Constructor
  43       */
  44  	function coll_media_index_Widget( $db_row = NULL )
  45      {
  46          // Call parent constructor:
  47          parent::ComponentWidget( $db_row, 'core', 'coll_media_index' );
  48      }
  49  
  50  
  51    /**
  52     * Get definitions for editable params
  53     *
  54       * @see Plugin::GetDefaultSettings()
  55       * @param local params like 'for_editing' => true
  56       */
  57  	function get_param_definitions( $params )
  58      {
  59          load_funcs( 'files/model/_image.funcs.php' );
  60  
  61          /**
  62           * @var ItemTypeCache
  63           */
  64          $ItemTypeCache = & get_ItemTypeCache();
  65          $item_type_options =
  66              array(
  67                  ''  => T_('All'),
  68              ) + $ItemTypeCache->get_option_array() ;
  69  
  70          $r = array_merge( array(
  71              'title' => array(
  72                  'label' => T_('Block title'),
  73                  'note' => T_( 'Title to display in your skin.' ),
  74                  'size' => 40,
  75                  'defaultvalue' => T_('Recent photos'),
  76              ),
  77              'item_type' => array(
  78                  'label' => T_('Item type'),
  79                  'note' => T_('What kind of items do you want to list?'),
  80                  'type' => 'select',
  81                  'options' => $item_type_options,
  82                  'defaultvalue' => '1',
  83              ),
  84              'thumb_size' => array(
  85                  'label' => T_('Thumbnail size'),
  86                  'note' => T_('Cropping and sizing of thumbnails'),
  87                  'type' => 'select',
  88                  'options' => get_available_thumb_sizes(),
  89                  'defaultvalue' => 'crop-80x80',
  90              ),
  91              'thumb_layout' => array(
  92                  'label' => T_('Layout'),
  93                  'note' => T_('How to lay out the thumbnails'),
  94                  'type' => 'select',
  95                  'options' => array( 'grid' => T_( 'Grid' ), 'list' => T_( 'List' ) ),
  96                  'defaultvalue' => 'grid',
  97              ),
  98              'disp_image_title' => array(
  99                  'label' => T_( 'Display image title' ),
 100                  'note' => T_( 'Check this to display image title. This falls back to post title if image title is not set.' ),
 101                  'type' => 'checkbox',
 102                  'defaultvalue' => false,
 103              ),
 104              'grid_nb_cols' => array(
 105                  'label' => T_( 'Columns' ),
 106                  'note' => T_( 'Number of columns in grid mode.' ),
 107                  'size' => 4,
 108                  'defaultvalue' => 2,
 109              ),
 110              'limit' => array(
 111                  'label' => T_( 'Max items' ),
 112                  'note' => T_( 'Maximum number of items to display.' ),
 113                  'size' => 4,
 114                  'defaultvalue' => 3,
 115              ),
 116              'order_by' => array(
 117                  'label' => T_('Order by'),
 118                  'note' => T_('How to sort the items'),
 119                  'type' => 'select',
 120                  'options' => get_available_sort_options(),
 121                  'defaultvalue' => 'datestart',
 122              ),
 123              'order_dir' => array(
 124                  'label' => T_('Direction'),
 125                  'note' => T_('How to sort the items'),
 126                  'type' => 'radio',
 127                  'options' => array( array( 'ASC', T_('Ascending') ),
 128                                      array( 'DESC', T_('Descending') ) ),
 129                  'defaultvalue' => 'DESC',
 130              ),
 131              'blog_ID' => array(
 132                  'label' => T_( 'Blogs' ),
 133                  'note' => T_( 'IDs of the blogs to use, leave empty for the current blog. Separate multiple blogs by commas.' ),
 134                  'size' => 4,
 135              ),
 136          ), parent::get_param_definitions( $params )    );
 137  
 138          return $r;
 139      }
 140  
 141  
 142      /**
 143       * Get name of widget
 144       */
 145  	function get_name()
 146      {
 147          return T_('Photo index');
 148      }
 149  
 150  
 151      /**
 152       * Get a very short desc. Used in the widget list.
 153       */
 154  	function get_short_desc()
 155      {
 156          return format_to_output($this->disp_params['title']);
 157      }
 158  
 159  
 160      /**
 161       * Get short description
 162       */
 163  	function get_desc()
 164      {
 165          return T_('Index of photos; click goes to original image post.');
 166      }
 167  
 168  
 169      /**
 170       * Display the widget!
 171       *
 172       * @param array MUST contain at least the basic display params
 173       */
 174  	function display( $params )
 175      {
 176          global $localtimenow;
 177  
 178          $this->init_display( $params );
 179  
 180          global $Blog;
 181          $list_blogs = ( $this->disp_params[ 'blog_ID' ] ? $this->disp_params[ 'blog_ID' ] : $Blog->ID );
 182          //pre_dump( $list_blogs );
 183  
 184          // Display photos:
 185          // TODO: permissions, complete statuses...
 186          // TODO: A FileList object based on ItemListLight but adding File data into the query?
 187          //          overriding ItemListLigth::query() for starters ;)
 188  
 189  
 190          $FileCache = & get_FileCache();
 191  
 192          $FileList = new DataObjectList2( $FileCache );
 193  
 194          // Query list of files:
 195          $SQL = new SQL();
 196          $SQL->SELECT( 'post_ID, post_datestart, post_datemodified, post_main_cat_ID, post_urltitle, post_canonical_slug_ID,
 197                                      post_tiny_slug_ID, post_ptyp_ID, post_title, post_excerpt, post_url, file_ID,
 198                                      file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc' );
 199          $SQL->FROM( 'T_categories INNER JOIN T_postcats ON cat_ID = postcat_cat_ID
 200                                      INNER JOIN T_items__item ON postcat_post_ID = post_ID
 201                                      INNER JOIN T_links ON post_ID = link_itm_ID
 202                                      INNER JOIN T_files ON link_file_ID = file_ID' );
 203          $SQL->WHERE( 'cat_blog_ID IN ('.$list_blogs.')' ); // fp> TODO: want to restrict on images :]
 204          $SQL->WHERE_and( 'post_status = "published"' );    // TODO: this is a dirty hack. More should be shown.
 205          $SQL->WHERE_and( 'post_datestart <= \''.remove_seconds( $localtimenow ).'\'' );
 206          if( !empty( $this->disp_params[ 'item_type' ] ) )
 207          { // Get items only with specified type
 208              $SQL->WHERE_and( 'post_ptyp_ID = '.intval( $this->disp_params[ 'item_type' ] ) );
 209          }
 210          $SQL->GROUP_BY( 'link_ID' );
 211          $SQL->LIMIT( $this->disp_params[ 'limit' ]*4 ); // fp> TODO: because we have no way of getting images only, we get 4 times more data than requested and hope that 25% at least will be images :/
 212          $SQL->ORDER_BY(    gen_order_clause( $this->disp_params['order_by'], $this->disp_params['order_dir'],
 213                                              'post_', 'post_ID '.$this->disp_params['order_dir'].', link_ID' ) );
 214  
 215          $FileList->sql = $SQL->get();
 216  
 217          $FileList->query( false, false, false, 'Media index widget' );
 218  
 219          $layout = $this->disp_params[ 'thumb_layout' ];
 220  
 221          $nb_cols = $this->disp_params[ 'grid_nb_cols' ];
 222          $count = 0;
 223          $r = '';
 224          /**
 225           * @var File
 226           */
 227          while( $File = & $FileList->get_next() )
 228          {
 229              if( $count >= $this->disp_params[ 'limit' ] )
 230              {    // We have enough images already!
 231                  break;
 232              }
 233  
 234              if( ! $File->is_image() )
 235              {    // Skip anything that is not an image
 236                  // fp> TODO: maybe this property should be stored in link_ltype_ID or in the files table
 237                  continue;
 238              }
 239  
 240              if( $layout == 'grid' )
 241              {
 242                  if( $count % $nb_cols == 0 )
 243                  {
 244                      $r .= $this->disp_params[ 'grid_colstart' ];
 245                  }
 246                  $r .= $this->disp_params[ 'grid_cellstart' ];
 247              }
 248              else
 249              {
 250                  $r .= $this->disp_params[ 'item_start' ];
 251              }
 252  
 253              // 1/ Hack a dirty permalink( will redirect to canonical):
 254              // $link = url_add_param( $Blog->get('url'), 'p='.$post_ID );
 255  
 256              // 2/ Hack a link to the right "page". Very daring!!
 257              // $link = url_add_param( $Blog->get('url'), 'paged='.$count );
 258  
 259              // 3/ Instantiate a light object in order to get permamnent url:
 260              $ItemLight = new ItemLight( $FileList->get_row_by_idx( $FileList->current_idx - 1 ) );    // index had already been incremented
 261  
 262              $r .= '<a href="'.$ItemLight->get_permanent_url().'">';
 263              // Generate the IMG THUMBNAIL tag with all the alt, title and desc if available
 264              $r .= $File->get_thumb_imgtag( $this->disp_params['thumb_size'], '', '', $ItemLight->title );
 265              $r .= '</a>';
 266              if( $this->disp_params[ 'disp_image_title' ] )
 267              {
 268                  $title = ($File->get('title')) ? $this->get('title') : $ItemLight->title;
 269                  $r .= '<span class="note">'.$title.'</span>';
 270              }
 271  
 272              ++$count;
 273  
 274              if( $layout == 'grid' )
 275              {
 276                  $r .= $this->disp_params[ 'grid_cellend' ];
 277                  if( $count % $nb_cols == 0 )
 278                  {
 279                      $r .= $this->disp_params[ 'grid_colend' ];
 280                  }
 281              }
 282              else
 283              {
 284                  $r .= $this->disp_params[ 'item_end' ];
 285              }
 286          }
 287  
 288          // Exit if no files found
 289          if( empty($r) ) return;
 290  
 291          echo $this->disp_params[ 'block_start'];
 292  
 293          // Display title if requested
 294          $this->disp_title();
 295  
 296          if( $layout == 'grid' )
 297          {
 298              echo $this->disp_params[ 'grid_start' ];
 299          }
 300          else
 301          {
 302              echo $this->disp_params[ 'list_start' ];
 303          }
 304  
 305          echo $r;
 306  
 307          if( $layout == 'grid' )
 308          {
 309              if( $count && ( $count % $nb_cols != 0 ) )
 310              {
 311                  echo $this->disp_params[ 'grid_colend' ];
 312              }
 313  
 314              echo $this->disp_params[ 'grid_end' ];
 315          }
 316          else
 317          {
 318              echo $this->disp_params[ 'list_end' ];
 319          }
 320  
 321          echo $this->disp_params[ 'block_end' ];
 322  
 323          return true;
 324      }
 325  
 326  
 327      /**
 328       * Maybe be overriden by some widgets, depending on what THEY depend on..
 329       *
 330       * @return array of keys this widget depends on
 331       */
 332  	function get_cache_keys()
 333      {
 334          global $Blog;
 335  
 336          return array(
 337                  'wi_ID'         => $this->ID,  // Have the widget settings changed?
 338                  'set_coll_ID'   => $Blog->ID,  // Have the settings of the blog changed? (ex: new skin)
 339                  'cont_coll_ID'  => empty($this->disp_params['blog_ID']) ? $Blog->ID : $this->disp_params['blog_ID'],  // Has the content of the displayed blog changed?
 340                  'media_coll_ID' => empty( $this->disp_params['blog_ID'] ) ? $Blog->ID : $this->disp_params['blog_ID'],     // Have some media files attached to one of the blogs item?
 341              );
 342      }
 343  }
 344  
 345  ?>

title

Description

title

Description

title

Description

title

title

Body