b2evolution PHP Cross Reference Blogging Systems

Source: /inc/widgets/widgets/_coll_item_list.widget.php - 577 lines - 17043 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: _coll_item_list.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 coll_item_list_Widget extends ComponentWidget
  38  {
  39      /**
  40       * Constructor
  41       */
  42  	function coll_item_list_Widget( $db_row = NULL )
  43      {
  44          // Call parent constructor:
  45          parent::ComponentWidget( $db_row, 'core', 'coll_item_list' );
  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          load_funcs( 'files/model/_image.funcs.php' );
  58  
  59          /**
  60           * @var ItemTypeCache
  61           */
  62          $ItemTypeCache = & get_ItemTypeCache();
  63          $item_type_options =
  64              array(
  65                  '#' => T_('Default'),
  66                  ''  => T_('All'),
  67              ) + $ItemTypeCache->get_option_array() ;
  68  
  69          $r = array_merge( array(
  70                  'title' => array(
  71                      'label' => T_('Block title'),
  72                      'note' => T_('Title to display in your skin.'),
  73                      'size' => 60,
  74                      'defaultvalue' => T_('Items'),
  75                  ),
  76                  'title_link' => array(
  77                      'label' => T_('Link to blog'),
  78                      'note' => T_('Link the block title to the blog?'),
  79                      'type' => 'checkbox',
  80                      'defaultvalue' => false,
  81                  ),
  82                  'item_type' => array(
  83                      'label' => T_('Item type'),
  84                      'note' => T_('What kind of items do you want to list?'),
  85                      'type' => 'select',
  86                      'options' => $item_type_options,
  87                      'defaultvalue' => '#',
  88                  ),
  89                  'thumb_size' => array(
  90                      'label' => T_('Thumbnail size'),
  91                      'note' => T_('Cropping and sizing of thumbnails'),
  92                      'type' => 'select',
  93                      'options' => get_available_thumb_sizes(),
  94                      'defaultvalue' => 'crop-80x80',
  95                  ),
  96                  'follow_mainlist' => array(
  97                      'label' => T_('Follow Main List'),
  98                      'note' => T_('Do you want to restrict to contents related to what is displayed in the main area?'),
  99                      'type' => 'radio',
 100                      'options' => array( array ('no', T_('No') ),
 101                                          array ('tags', T_('By tags') ) ), // may be extended
 102                      'defaultvalue' => 'no',
 103                  ),
 104                  'blog_ID' => array(
 105                      'label' => T_( 'Blog' ),
 106                      'note' => T_( 'ID of the blog to use, leave empty for the current blog.' ),
 107                      'size' => 4,
 108                  ),
 109  /* TODO: filter this out from all "SIMPLE" lists and keep it only in universal list
 110                  'cat_IDs' => array(
 111                      'label' => T_( 'Categories' ),
 112                      'note' => T_( 'List category IDs separated by ,' ),
 113                      'size' => 15,
 114                  ),
 115  */
 116                  'item_group_by' => array(
 117                      'label' => T_('Group by'),
 118                      'note' => T_('Do you want to group the Items?'),
 119                      'type' => 'radio',
 120                      'options' => array( array( 'none', T_('None') ),
 121                                          array( 'chapter', T_('By category/chapter') ) ),
 122                      'defaultvalue' => 'none',
 123                  ),
 124                  'order_by' => array(
 125                      'label' => T_('Order by'),
 126                      'note' => T_('How to sort the items'),
 127                      'type' => 'select',
 128                      'options' => get_available_sort_options(),
 129                      'defaultvalue' => 'datestart',
 130                  ),
 131                  'order_dir' => array(
 132                      'label' => T_('Direction'),
 133                      'note' => T_('How to sort the items'),
 134                      'type' => 'radio',
 135                      'options' => array( array( 'ASC', T_('Ascending') ),
 136                                          array( 'DESC', T_('Descending') ) ),
 137                      'defaultvalue' => 'DESC',
 138                  ),
 139                  'limit' => array(
 140                      'label' => T_( 'Max items' ),
 141                      'note' => T_( 'Maximum number of items to display.' ),
 142                      'size' => 4,
 143                      'defaultvalue' => 20,
 144                  ),
 145                  'disp_title' => array(
 146                      'label' => T_( 'Titles' ),
 147                      'note' => T_( 'Display title.' ),
 148                      'type' => 'checkbox',
 149                      'defaultvalue' => true,
 150                  ),
 151                  'item_title_link_type' => array(
 152                      'label' => T_('Link titles'),
 153                      'note' => T_('Where should titles be linked to?'),
 154                      'type' => 'select',
 155                      'options' => array(
 156                              'auto'        => T_('Automatic'),
 157                              'permalink'   => T_('Item permalink'),
 158                              'linkto_url'  => T_('Item URL'),
 159                              'none'        => T_('Nowhere'),
 160                          ),
 161                      'defaultvalue' => 'auto',
 162                  ),
 163                  'attached_pics' => array(
 164                      'label' => T_('Attached pictures'),
 165                      'note' => '',
 166                      'type' => 'radio',
 167                      'options' => array(
 168                              array( 'none', T_('None') ),
 169                              array( 'first', T_('Display first') ),
 170                              array( 'all', T_('Display all') ) ),
 171                      'defaultvalue' => 'none',
 172                  ),
 173                  'item_pic_link_type' => array(
 174                      'label' => T_('Link pictures'),
 175                      'note' => T_('Where should pictures be linked to?'),
 176                      'type' => 'select',
 177                      'options' => array(
 178                              'auto'        => T_('Automatic'),
 179                              'permalink'   => T_('Item permalink'),
 180                              'linkto_url'  => T_('Item URL'),
 181                              'none'        => T_('Nowhere'),
 182                          ),
 183                      'defaultvalue' => 'auto',
 184                  ),
 185                  'disp_excerpt' => array(
 186                      'label' => T_( 'Excerpt' ),
 187                      'note' => T_( 'Display excerpt for each item.' ),
 188                      'type' => 'checkbox',
 189                      'defaultvalue' => false,
 190                  ),
 191                  'disp_teaser' => array(
 192                      'label' => T_( 'Content teaser' ),
 193                      'type' => 'checkbox',
 194                      'defaultvalue' => false,
 195                      'note' => T_( 'Display content teaser for each item.' ),
 196                  ),
 197                  'disp_teaser_maxwords' => array(
 198                      'label' => T_( 'Max Words' ),
 199                      'type' => 'integer',
 200                      'defaultvalue' => 20,
 201                      'note' => T_( 'Max number of words for the teasers.' ),
 202                  ),
 203              ), parent::get_param_definitions( $params )    );
 204  
 205          // pre_dump( $r['item_type']['options'] );
 206  
 207          return $r;
 208      }
 209  
 210  
 211      /**
 212       * Get name of widget
 213       */
 214  	function get_name()
 215      {
 216          return T_('Universal Item list');
 217      }
 218  
 219  
 220      /**
 221       * Get a very short desc. Used in the widget list.
 222       */
 223  	function get_short_desc()
 224      {
 225          return format_to_output($this->disp_params['title']);
 226      }
 227  
 228  
 229      /**
 230       * Get short description
 231       */
 232  	function get_desc()
 233      {
 234          return T_('Can list Items (Posts/Pages/Links...) in a variety of ways.');
 235      }
 236  
 237  
 238      /**
 239       * Display the widget!
 240       *
 241       * @param array MUST contain at least the basic display params
 242       */
 243  	function display( $params )
 244      {
 245          /**
 246           * @var ItemList2
 247           */
 248          global $MainList;
 249          global $BlogCache, $Blog;
 250          global $Item;
 251  
 252          $this->init_display( $params );
 253  
 254          $listBlog = ( $this->disp_params[ 'blog_ID' ] ? $BlogCache->get_by_ID( $this->disp_params[ 'blog_ID' ], false ) : $Blog );
 255  
 256          if( empty($listBlog) )
 257          {
 258              echo $this->disp_params['block_start'];
 259              echo T_('The requested Blog doesn\'t exist any more!');
 260              echo $this->disp_params['block_end'];
 261              return;
 262          }
 263  
 264          // Create ItemList
 265          // Note: we pass a widget specific prefix in order to make sure to never interfere with the mainlist
 266          $limit = $this->disp_params[ 'limit' ];
 267  
 268          if( $this->disp_params['disp_teaser'] )
 269          { // We want to show some of the post content, we need to load more info: use ItemList2
 270              $ItemList = new ItemList2( $listBlog, $listBlog->get_timestamp_min(), $listBlog->get_timestamp_max(), $limit, 'ItemCache', $this->code.'_' );
 271          }
 272          else
 273          { // no excerpts, use ItemListLight
 274              load_class( 'items/model/_itemlistlight.class.php', 'ItemListLight' );
 275              $ItemList = new ItemListLight( $listBlog, $listBlog->get_timestamp_min(), $listBlog->get_timestamp_max(), $limit, 'ItemCacheLight', $this->code.'_' );
 276          }
 277  
 278          //$cat_array = sanitize_id_list($this->disp_params['cat_IDs'], true);
 279  
 280          // Filter list:
 281          $filters = array(
 282  //                'cat_array' => $cat_array, // Restrict to selected categories
 283                  'orderby' => $this->disp_params[ 'order_by' ],
 284                  'order' => $this->disp_params[ 'order_dir' ],
 285                  'unit' => 'posts', // We want to advertise all items (not just a page or a day)
 286              );
 287  
 288          if( isset( $this->disp_params['page'] ) )
 289          {
 290              $filters['page'] = $this->disp_params['page'];
 291          }
 292  
 293          if( $this->disp_params['item_type'] != '#' )
 294          {    // Not "default", restrict to a specific type (or '' for all)
 295              $filters['types'] = $this->disp_params['item_type'];
 296          }
 297  
 298          if( $this->disp_params['follow_mainlist'] == 'tags' )
 299          {    // Restrict to Item tagged with some tag used in the Mainlist:
 300  
 301              if( ! isset($MainList) )
 302              {    // Nothing to follow, don't display anything
 303                  return false;
 304              }
 305  
 306              $all_tags = $MainList->get_all_tags();
 307              if( empty($all_tags) )
 308              {    // Nothing to follow, don't display anything
 309                  return false;
 310              }
 311  
 312              $filters['tags'] = implode(',',$all_tags);
 313  
 314              if( !empty($Item) )
 315              {    // Exclude current Item
 316                  $filters['post_ID'] = '-'.$Item->ID;
 317              }
 318  
 319              // fp> TODO: in addition to just filtering, offer ordering in a way where the posts with the most matching tags come first
 320          }
 321  
 322          $chapter_mode = false;
 323          if( $this->disp_params['item_group_by'] == 'chapter' )
 324          {    // Group by chapter:
 325              $chapter_mode = true;
 326  
 327              # This is the list of categories to restrict the linkblog to (cats will be displayed recursively)
 328              # Example: $linkblog_cat = '4,6,7';
 329              $linkblog_cat = '';
 330  
 331              # This is the array if categories to restrict the linkblog to (non recursive)
 332              # Example: $linkblog_catsel = array( 4, 6, 7 );
 333              $linkblog_catsel = array(); // $cat_array;
 334  
 335              // Compile cat array stuff:
 336              $linkblog_cat_array = array();
 337              $linkblog_cat_modifier = '';
 338  
 339              compile_cat_array( $linkblog_cat, $linkblog_catsel, /* by ref */ $linkblog_cat_array, /* by ref */  $linkblog_cat_modifier, $listBlog->ID );
 340  
 341              $filters['cat_array'] = $linkblog_cat_array;
 342              $filters['cat_modifier'] = $linkblog_cat_modifier;
 343              $filters['orderby'] = 'main_cat_ID '.$filters['orderby'];
 344          }
 345  
 346          $ItemList->set_filters( $filters, false ); // we don't want to memorize these params
 347  
 348          // Run the query:
 349          $ItemList->query();
 350  
 351          if( ! $ItemList->result_num_rows )
 352          {    // Nothing to display:
 353              return;
 354          }
 355  
 356          // Start to capture display content here in order to solve the issue to don't display empty widget
 357          ob_start();
 358          // This variable used to display widget. Will be set to true when content is displayed
 359          $content_is_displayed = false;
 360  
 361          if( !$this->disp_params['disp_title'] && in_array( $this->disp_params[ 'attached_pics' ], array( 'first', 'all' ) ) )
 362          { // Don't display bullets when we show only the pictures
 363              $block_css_class = 'nobullets';
 364          }
 365  
 366          if( empty( $block_css_class ) )
 367          {
 368              echo $this->disp_params['block_start'];
 369          }
 370          else
 371          { // Additional class for widget block
 372              echo preg_replace( '/ class="([^"]+)"/', ' class="$1 '.$block_css_class.'"', $this->disp_params['block_start'] );
 373          }
 374  
 375          $title = sprintf( ( $this->disp_params[ 'title_link' ] ? '<a href="'.$listBlog->gen_blogurl().'" rel="nofollow">%s</a>' : '%s' ), $this->disp_params[ 'title' ] );
 376          $this->disp_title( $title );
 377  
 378          echo $this->disp_params['list_start'];
 379  
 380          if( $chapter_mode )
 381          {    // List grouped by chapter/category:
 382              /**
 383               * @var ItemLight (or Item)
 384               */
 385              while( $Item = & $ItemList->get_category_group() )
 386              {
 387                  // Open new cat:
 388                  $Chapter = & $Item->get_main_Chapter();
 389  
 390                  echo $this->disp_params['item_start'];
 391                  echo '<a href="'.$Chapter->get_permanent_url().'">'.$Chapter->get('name').'</a>';
 392                  echo $this->disp_params['group_start'];
 393  
 394                  while( $Item = & $ItemList->get_item() )
 395                  {    // Display contents of the Item depending on widget params:
 396                      $content_is_displayed = $this->disp_contents( $Item ) || $content_is_displayed;
 397                  }
 398  
 399                  // Close cat
 400                  echo $this->disp_params['group_end'];
 401                  echo $this->disp_params['item_end'];
 402              }
 403          }
 404          else
 405          {    // Plain list:
 406              /**
 407               * @var ItemLight (or Item)
 408               */
 409              while( $Item = & $ItemList->get_item() )
 410              { // Display contents of the Item depending on widget params:
 411                  $content_is_displayed = $this->disp_contents( $Item ) || $content_is_displayed;
 412              }
 413          }
 414  
 415          if( isset( $this->disp_params['page'] ) )
 416          {
 417              $ItemList->page_links();
 418          }
 419  
 420          echo $this->disp_params['list_end'];
 421  
 422          echo $this->disp_params['block_end'];
 423  
 424          if( $content_is_displayed )
 425          { // Some content is displayed, Print out widget
 426              ob_end_flush();
 427          }
 428          else
 429          { // No content, Don't display widget
 430              ob_end_clean();
 431          }
 432      }
 433  
 434  
 435      /**
 436       * Support function for above
 437       *
 438       * @param Item
 439       * @return boolean TRUE - if content is displayed
 440       */
 441  	function disp_contents( & $disp_Item )
 442      {
 443          // Check if only the title was displayed before the first picture
 444          $displayed_only_title = false;
 445  
 446          // Set this var to TRUE when some content(title, excerpt or picture) is displayed
 447          $content_is_displayed = false;
 448  
 449          echo $this->disp_params['item_start'];
 450  
 451          // Is this the current item?
 452          global $disp, $Item;
 453          if( !empty($Item) && $disp_Item->ID == $Item->ID )
 454          {    // The current page is currently displaying the Item this link is pointing to
 455              // Let's display it as selected
 456              $link_class = $this->disp_params['link_selected_class'];
 457          }
 458          else
 459          {    // Default link class
 460              $link_class = $this->disp_params['link_default_class'];
 461          }
 462  
 463          if( $this->disp_params[ 'disp_title' ] )
 464          {    // Display title
 465              $disp_Item->title( array(
 466                      'link_type'  => $this->disp_params['item_title_link_type'],
 467                      'link_class' => $link_class,
 468                  ) );
 469              $displayed_only_title = true;
 470              $content_is_displayed = true;
 471          }
 472  
 473          if( $this->disp_params[ 'disp_excerpt' ] )
 474          {
 475              $excerpt = $disp_Item->dget( 'excerpt', 'htmlbody' );
 476              if( !empty($excerpt) )
 477              {    // Note: Excerpts are plain text -- no html (at least for now)
 478                  echo '<div class="item_excerpt">'.$excerpt.'</div>';
 479                  $displayed_only_title = false;
 480                  $content_is_displayed = true;
 481              }
 482          }
 483  
 484          if( $this->disp_params['disp_teaser'] )
 485          { // we want to show some or all of the post content
 486              $content = $disp_Item->get_content_teaser( 1, false, 'htmlbody' );
 487  
 488              if( $words = $this->disp_params['disp_teaser_maxwords'] )
 489              { // limit number of words
 490                  $content = strmaxwords( $content, $words, array(
 491                          'continued_link' => $disp_Item->get_permanent_url(),
 492                          'continued_text' => '&hellip;',
 493                       ) );
 494              }
 495              echo '<div class="item_content">'.$content.'</div>';
 496              $displayed_only_title = false;
 497              $content_is_displayed = true;
 498  
 499              /* fp> does that really make sense?
 500                  we're no longer in a linkblog/linkroll use case here, are we?
 501              $disp_Item->more_link( array(
 502                      'before'    => '',
 503                      'after'     => '',
 504                      'link_text' => T_('more').' &raquo;',
 505                  ) );
 506                  */
 507          }
 508  
 509          if( in_array( $this->disp_params[ 'attached_pics' ], array( 'first', 'all' ) ) )
 510          {    // Display attached pictures
 511              $picture_limit = $this->disp_params[ 'attached_pics' ] == 'first' ? 1 : 1000;
 512              $LinkOnwer = new LinkItem( $disp_Item );
 513              if( $FileList = $LinkOnwer->get_attachment_FileList( $picture_limit ) )
 514              {    // Get list of attached files
 515                  while( $File = & $FileList->get_next() )
 516                  {
 517                      if( $File->is_image() )
 518                      {    // Get only images
 519                          switch( $this->disp_params[ 'item_pic_link_type' ] )
 520                          {    // Set url for picture link
 521                              case 'none':
 522                                  $pic_url = NULL;
 523                                  break;
 524  
 525                              case 'permalink':
 526                                  $pic_url = $disp_Item->get_permanent_url();
 527                                  break;
 528  
 529                              case 'linkto_url':
 530                                  $pic_url = $disp_Item->url;
 531                                  break;
 532  
 533                              case 'auto':
 534                              default:
 535                                  $pic_url = ( empty( $disp_Item->url ) ? $disp_Item->get_permanent_url() : $disp_Item->url );
 536                                  break;
 537                          }
 538  
 539                          if( $displayed_only_title )
 540                          { // If only the title was displayed - Insert new line before the first picture
 541                              echo '<br />';
 542                              $displayed_only_title = false;
 543                          }
 544  
 545                          // Print attached picture
 546                          echo $File->get_tag( '', '', '', '', $this->disp_params['thumb_size'], $pic_url );
 547  
 548                          $content_is_displayed = true;
 549                      }
 550                  }
 551              }
 552          }
 553  
 554          echo $this->disp_params['item_end'];
 555  
 556          return $content_is_displayed;
 557      }
 558  
 559  
 560      /**
 561       * Maybe be overriden by some widgets, depending on what THEY depend on..
 562       *
 563       * @return array of keys this widget depends on
 564       */
 565  	function get_cache_keys()
 566      {
 567          global $Blog;
 568  
 569          return array(
 570                  'wi_ID'   => $this->ID,                    // Have the widget settings changed ?
 571                  'set_coll_ID' => $Blog->ID,            // Have the settings of the blog changed ? (ex: new skin)
 572                  'cont_coll_ID' => empty($this->disp_params['blog_ID']) ? $Blog->ID : $this->disp_params['blog_ID'],     // Has the content of the displayed blog changed ?
 573              );
 574      }
 575  }
 576  
 577  ?>

title

Description

title

Description

title

Description

title

title

Body