b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _coll_media_index.widget.php

Documentation is available at _coll_media_index.widget.php

  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-2010 by Francois PLANQUE - {@link http://fplanque.net/}
  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,v 1.22 2010/02/08 17:54:48 efy-yury Exp $
  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. {
  40.     /**
  41.      * Constructor
  42.      */
  43.     function coll_media_index_Widget$db_row NULL )
  44.     {
  45.         // Call parent constructor:
  46.         parent::ComponentWidget$db_row'core''coll_media_index' );
  47.     }
  48.  
  49.  
  50.   /**
  51.    * Get definitions for editable params
  52.    *
  53.      * @see Plugin::GetDefaultSettings()
  54.      * @param local params like 'for_editing' => true
  55.      */
  56.     function get_param_definitions$params )
  57.     {
  58.         load_funcs'files/model/_image.funcs.php' );
  59.  
  60.         $r array_mergearray(
  61.             'title' => array(
  62.                 'label' => T_('Block title'),
  63.                 'note' => T_'Title to display in your skin.' ),
  64.                 'size' => 40,
  65.                 'defaultvalue' => T_('Recent photos'),
  66.             ),
  67.             'thumb_size' => array(
  68.                 'label' => T_('Thumbnail size'),
  69.                 'note' => T_('Cropping and sizing of thumbnails'),
  70.                 'type' => 'select',
  71.                 'options' => get_available_thumb_sizes(),
  72.                 'defaultvalue' => 'crop-80x80',
  73.             ),
  74.             'thumb_layout' => array(
  75.                 'label' => T_('Layout'),
  76.                 'note' => T_('How to lay out the thumbnails'),
  77.                 'type' => 'select',
  78.                 'options' => array'grid' => T_'Grid' )'list' => T_'List' ) ),
  79.                 'defaultvalue' => 'grid',
  80.             ),
  81.             'grid_nb_cols' => array(
  82.                 'label' => T_'Columns' ),
  83.                 'note' => T_'Number of columns in grid mode.' ),
  84.                 'size' => 4,
  85.                 'defaultvalue' => 2,
  86.             ),
  87.             'limit' => array(
  88.                 'label' => T_'Max items' ),
  89.                 'note' => T_'Maximum number of items to display.' ),
  90.                 'size' => 4,
  91.                 'defaultvalue' => 3,
  92.             ),
  93.             'order_by' => array(
  94.                 'label' => T_('Order by'),
  95.                 'note' => T_('How to sort the items'),
  96.                 'type' => 'select',
  97.                 'options' => get_available_sort_options(),
  98.                 'defaultvalue' => 'datestart',
  99.             ),
  100.             'order_dir' => array(
  101.                 'label' => T_('Direction'),
  102.                 'note' => T_('How to sort the items'),
  103.                 'type' => 'radio',
  104.                 'options' => arrayarray'ASC'T_('Ascending') ),
  105.                                     array'DESC'T_('Descending') ) ),
  106.                 'defaultvalue' => 'DESC',
  107.             ),
  108.             'blog_ID' => array(
  109.                 'label' => T_'Blogs' ),
  110.                 'note' => T_'IDs of the blogs to use, leave empty for the current blog. Separate multiple blogs by commas.' ),
  111.                 'size' => 4,
  112.             ),
  113.         )parent::get_param_definitions$params )    );
  114.  
  115.         return $r;
  116.     }
  117.  
  118.  
  119.     /**
  120.      * Get name of widget
  121.      */
  122.     function get_name()
  123.     {
  124.         return T_('Photo index');
  125.     }
  126.  
  127.  
  128.     /**
  129.      * Get a very short desc. Used in the widget list.
  130.      */
  131.     function get_short_desc()
  132.     {
  133.         return format_to_output($this->disp_params['title']);
  134.     }
  135.  
  136.  
  137.     /**
  138.      * Get short description
  139.      */
  140.     function get_desc()
  141.     {
  142.         return T_('Index of photos; click goes to original image post.');
  143.     }
  144.  
  145.  
  146.     /**
  147.      * Display the widget!
  148.      *
  149.      * @param array MUST contain at least the basic display params
  150.      */
  151.     function display$params )
  152.     {
  153.         global $localtimenow;
  154.  
  155.         $this->init_display$params );
  156.  
  157.         if$this->disp_params'order_by' == 'RAND' && isset($this->BlockCache) )
  158.         {    // Do NOT cache if display order is random
  159.             $this->BlockCache->abort_collect();
  160.         }
  161.  
  162.         global $Blog;
  163.         $list_blogs $this->disp_params'blog_ID' $this->disp_params'blog_ID' $Blog->ID );
  164.         //pre_dump( $list_blogs );
  165.  
  166.         echo $this->disp_params'block_start'];
  167.  
  168.         // Display title if requested
  169.         $this->disp_title();
  170.  
  171.         // Display photos:
  172.         // TODO: permissions, complete statuses...
  173.         // TODO: A FileList object based on ItemListLight but adding File data into the query?
  174.         //          overriding ItemListLigth::query() for starters ;)
  175.  
  176.  
  177.         $FileCache get_FileCache();
  178.  
  179.         $FileList new DataObjectList2$FileCache );
  180.  
  181.         // Query list of files:
  182.         $SQL new SQL();
  183.         $SQL->SELECT'post_ID, post_datestart, post_datemodified, post_main_cat_ID, post_urltitle, post_ptyp_ID, post_title, post_excerpt, post_url,
  184.                                     file_ID, file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc' );
  185.         $SQL->FROM'T_categories INNER JOIN T_postcats ON cat_ID = postcat_cat_ID
  186.                                     INNER JOIN T_items__item ON postcat_post_ID = post_ID
  187.                                     INNER JOIN T_links ON post_ID = link_itm_ID
  188.                                     INNER JOIN T_files ON link_file_ID = file_ID' );
  189.         $SQL->WHERE'cat_blog_ID IN ('.$list_blogs.')' )// fp> TODO: want to restrict on images :]
  190.         $SQL->WHERE_and'post_status = "published"' );    // TODO: this is a dirty hack. More should be shown.
  191.         $SQL->WHERE_and'post_datestart <= \''.remove_seconds$localtimenow ).'\'' );
  192.         $SQL->GROUP_BY'link_ID' );
  193.         $SQL->LIMIT$this->disp_params'limit' ]*)// 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 :/
  194.         $SQL->ORDER_BY(    gen_order_clause$this->disp_params['order_by']$this->disp_params['order_dir'],
  195.                                             'post_''post_ID '.$this->disp_params['order_dir'].', link_ID' ) );
  196.  
  197.         $FileList->sql $SQL->get();
  198.  
  199.         $FileList->queryfalsefalsefalse'Media index widget' );
  200.  
  201.         $layout $this->disp_params'thumb_layout' ];
  202.  
  203.         if$layout == 'grid' )
  204.         {
  205.             echo $this->disp_params'grid_start' ];
  206.         }
  207.         else
  208.         {
  209.             echo $this->disp_params'list_start' ];
  210.         }
  211.  
  212.         $nb_cols $this->disp_params'grid_nb_cols' ];
  213.         $count 0;
  214.         /**
  215.          * @var File
  216.          */
  217.         while$File $FileList->get_next() )
  218.         {
  219.             if$count >= $this->disp_params'limit' )
  220.             {    // We have enough images already!
  221.                 break;
  222.             }
  223.  
  224.             if$File->is_image() )
  225.             {    // Skip anything that is not an image
  226.                 // fp> TODO: maybe this property should be stored in link_ltype_ID or in the files table
  227.                 continue;
  228.             }
  229.  
  230.             if$layout == 'grid' )
  231.             {
  232.                 if$count $nb_cols == )
  233.                 {
  234.                     echo $this->disp_params'grid_colstart' ];
  235.                 }
  236.                 echo $this->disp_params'grid_cellstart' ];
  237.             }
  238.             else
  239.             {
  240.                 echo $this->disp_params'item_start' ];
  241.             }
  242.  
  243.             // 1/ Hack a dirty permalink( will redirect to canonical):
  244.             // $link = url_add_param( $Blog->get('url'), 'p='.$post_ID );
  245.  
  246.             // 2/ Hack a link to the right "page". Very daring!!
  247.             // $link = url_add_param( $Blog->get('url'), 'paged='.$count );
  248.  
  249.             // 3/ Instantiate a light object in order to get permamnent url:
  250.             $ItemLight new ItemLight$FileList->get_row_by_idx$FileList->current_idx ) );    // index had already been incremented
  251.  
  252.             echo '<a href="'.$ItemLight->get_permanent_url().'">';
  253.             // Generate the IMG THUMBNAIL tag with all the alt, title and desc if available
  254.             echo $File->get_thumb_imgtag$this->disp_params['thumb_size');
  255.             echo '</a>';
  256.  
  257.             ++$count;
  258.  
  259.             if$layout == 'grid' )
  260.             {
  261.                 echo $this->disp_params'grid_cellend' ];
  262.                 if$count $nb_cols == )
  263.                 {
  264.                     echo $this->disp_params'grid_colend' ];
  265.                 }
  266.             }
  267.             else
  268.             {
  269.                 echo $this->disp_params'item_end' ];
  270.             }
  271.         }
  272.  
  273.         if$layout == 'grid' )
  274.         {
  275.             if$count && $count $nb_cols != ) )
  276.             {
  277.                 echo $this->disp_params'grid_colend' ];
  278.             }
  279.  
  280.             echo $this->disp_params'grid_end' ];
  281.         }
  282.         else
  283.         {
  284.             echo $this->disp_params'list_end' ];
  285.         }
  286.  
  287.         echo $this->disp_params'block_end' ];
  288.  
  289.         return true;
  290.     }
  291. }
  292.  
  293.  
  294. /*
  295.  * $Log: _coll_media_index.widget.php,v $
  296.  * Revision 1.22  2010/02/08 17:54:48  efy-yury
  297.  * copyright 2009 -> 2010
  298.  *
  299.  * Revision 1.21  2010/01/30 18:55:36  blueyed
  300.  * Fix "Assigning the return value of new by reference is deprecated" (PHP 5.3)
  301.  *
  302.  * Revision 1.20  2010/01/27 15:20:08  efy-asimo
  303.  * Change select list to radio button
  304.  *
  305.  * Revision 1.19  2009/12/23 01:38:46  fplanque
  306.  * one server was missing this...
  307.  *
  308.  * Revision 1.18  2009/12/13 02:28:36  fplanque
  309.  * dirty fix / better than nothing
  310.  *
  311.  * Revision 1.17  2009/11/30 04:31:38  fplanque
  312.  * BlockCache Proof Of Concept
  313.  *
  314.  * Revision 1.16  2009/09/27 15:59:13  tblue246
  315.  * Photo index widget: Allow specifying multiple blogs
  316.  *
  317.  * Revision 1.15  2009/09/26 12:00:44  tblue246
  318.  * Minor/coding style
  319.  *
  320.  * Revision 1.14  2009/09/25 07:33:31  efy-cantor
  321.  * replace get_cache to get_*cache
  322.  *
  323.  * Revision 1.13  2009/09/19 13:02:51  tblue246
  324.  * Media index: Do not show images from posts in the future, fixes: http://forums.b2evolution.net/viewtopic.php?t=19659
  325.  *
  326.  * Revision 1.12  2009/09/14 13:54:13  efy-arrin
  327.  * Included the ClassName in load_class() call with proper UpperCase
  328.  *
  329.  * Revision 1.11  2009/09/12 11:03:13  efy-arrin
  330.  * Included the ClassName in the loadclass() with proper UpperCase
  331.  *
  332.  * Revision 1.10  2009/08/27 13:15:28  tblue246
  333.  * Removed left over pre_dump()...
  334.  *
  335.  * Revision 1.9  2009/08/27 13:13:54  tblue246
  336.  * - Doc/todo
  337.  * - Minor bugfix
  338.  *
  339.  * Revision 1.8  2009/07/07 04:52:54  sam2kb
  340.  * Made some strings translatable
  341.  *
  342.  * Revision 1.7  2009/03/31 18:28:25  tblue246
  343.  * Fixing http://forums.b2evolution.net/viewtopic.php?t=18387
  344.  *
  345.  * Revision 1.6  2009/03/13 02:32:07  fplanque
  346.  * Cleaned up widgets.
  347.  * Removed stupid widget_name param.
  348.  *
  349.  * Revision 1.5  2009/03/08 23:57:46  fplanque
  350.  * 2009
  351.  *
  352.  * Revision 1.4  2009/02/08 11:31:56  yabs
  353.  * Minor
  354.  *
  355.  * Revision 1.3  2008/09/29 08:30:36  fplanque
  356.  * Avatar support
  357.  *
  358.  * Revision 1.2  2008/09/24 08:44:11  fplanque
  359.  * Fixed and normalized order params for widgets (Comments not done yet)
  360.  *
  361.  * Revision 1.1  2008/09/23 09:04:33  fplanque
  362.  * moved media index to a widget
  363.  *
  364.  * Revision 1.7  2008/05/06 23:35:47  fplanque
  365.  * The correct way to add linebreaks to widgets is to add them to $disp_params when the container is called, right after the array_merge with defaults.
  366.  *
  367.  * Revision 1.5  2008/01/21 09:35:37  fplanque
  368.  * (c) 2008
  369.  *
  370.  * Revision 1.4  2007/12/26 23:12:48  yabs
  371.  * changing RANDOM to RAND
  372.  *
  373.  * Revision 1.3  2007/12/26 20:04:54  fplanque
  374.  * minor
  375.  *
  376.  * Revision 1.2  2007/12/24 12:05:31  yabs
  377.  * bugfix "order" is a reserved name, used by wi_order
  378.  *
  379.  * Revision 1.1  2007/12/24 11:02:42  yabs
  380.  * added to cvs
  381.  *
  382.  */
  383. ?>

Documentation generated on Sat, 06 Mar 2010 04:05:13 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).