b2evolution PHP Cross Reference Blogging Systems

Source: /inc/links/model/_linkowner.class.php - 341 lines - 8042 bytes - Summary - Text - Print

Description: This file implements the abstract Link Owner class, which is a wrapper class for objects which can have linked files. Important: This class is abstract must never be instantiated. 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 abstract Link Owner class, which is a wrapper class for objects which can have linked files.

   4   * Important: This class is abstract must never be instantiated.

   5   * 

   6   * This file is part of the evoCore framework - {@link http://evocore.net/}

   7   * See also {@link http://sourceforge.net/projects/evocms/}.

   8   *

   9   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}

  10   * 

  11   * @package evocore

  12   *

  13   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  14   * @author efy-asimo: Attila Simo.

  15   *

  16   * @version $Id: $

  17   */
  18  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  19  
  20  /**

  21   * LinkOwner Abstract Class

  22   *

  23   * @package evocore

  24   */
  25  class LinkOwner
  26  {
  27      /**

  28       * Type of the Link Owner object

  29       * 

  30       * @var string

  31       */
  32      var $type;
  33  
  34      /**

  35       * The link owner object

  36       * 

  37       * @var DataObject

  38       */
  39      var $link_Object;
  40  
  41      /**

  42       * Array of Links attached to this object.

  43       *

  44       * NULL when not initialized.

  45       *

  46       * @var array

  47       * @access public

  48       */
  49      var $Links = NULL;
  50  
  51      /**

  52       * The link owner Blog

  53       * 

  54       * @var Blog

  55       */
  56      var $Blog = NULL;
  57  
  58      /**

  59       * The translation map, and it must be initialized in every subclass constructor

  60       * 

  61       * @var array

  62       */
  63      var $_trans = NULL;
  64  
  65      /**

  66       * Abstract methods that needs to be overriden in every subclass

  67       * 

  68       * function check_perm( $perm_name, $assert = false ); // check link owner object ( item, comment, ... ) edit/view permission

  69       * function get_where_condition(); // get where condition for select query to get link owner links

  70       * function get_positions(); // get all positions where link can be displayed ( 'teaser', 'aftermore' )

  71       * function get_edit_url(); // get link owner edit url

  72       * function get_view_url(); // get link owner view url

  73       * function load_Links(); // load link owner all links

  74       * function add_link( $file_ID, $position, $order ); // add a new link to link owner

  75       * function load_Blog(); // set Link Owner Blog

  76       */
  77  
  78      /**

  79       * Constructor

  80       * 

  81       * @protected It is allowed to be called only from subclasses

  82       *  

  83       * @param object the link owner object

  84       * @param string the link type ( item, comment, ... )

  85       */
  86  	function LinkOwner( $link_Object, $type )
  87      {
  88          $this->link_Object = $link_Object;
  89          $this->type = $type;
  90      }
  91  
  92      /**

  93       * Get all links

  94       */
  95      function & get_Links()
  96      {
  97          $this->load_Links();
  98  
  99          return $this->Links;
 100      }
 101  
 102      /**

 103       * Remove link from the owner

 104       *

 105       * @param object Link

 106       * @return boolean true on success

 107       */
 108  	function remove_link( & $Link )
 109      {
 110          $this->load_Links();
 111  
 112          $index = array_search( $Link, $this->Links );
 113          if( $index !== false )
 114          {
 115              unset( $this->Links[ $index ] );
 116          }
 117          $LinkCacche = & get_LinkCache();
 118          $LinkCacche->remove( $Link );
 119          return $Link->dbdelete();
 120      }
 121  
 122      /**

 123       * Get Link by File ID

 124       */
 125      function & get_link_by_file_ID( $file_ID )
 126      {
 127          $this->load_Links();
 128  
 129          $r = NULL;
 130          foreach( $this->Links as $Link )
 131          {
 132              if( $Link->file_ID == $file_ID )
 133              {
 134                  $r = $Link;
 135                  break;
 136              }
 137          }
 138  
 139          return $r;
 140      }
 141  
 142      /**

 143       * Count how many files are attached to this link owner owner object

 144       * 

 145       * @return int the number of attachments

 146       */
 147  	function count_links()
 148      {
 149          $this->load_Links();
 150  
 151          return count( $this->Links );
 152      }
 153  
 154      /**

 155       * Get Blog

 156       */
 157      function & get_Blog()
 158      {
 159          $this->load_Blog();
 160  
 161          return $this->Blog;
 162      }
 163  
 164      /**

 165       * Get SQL query to select all links attached to this owner

 166       * 

 167       * @param string links order by

 168       * @return object SQL

 169       */
 170  	function get_SQL( $order_by = NULL )
 171      {
 172          $SQL = new SQL();
 173  
 174          /**

 175           * asimo> Replace in select query the link_cmt_ID, link_itm_ID with the following ( it can be used only after MySQL 5.0)

 176           * (CASE

 177              WHEN (link_cmt_ID IS NOT NULL) THEN 'comment'

 178              WHEN (link_itm_ID IS NOT NULL) THEN 'item'

 179              END) as owner_type

 180           */
 181          if( $order_by == NULL )
 182          {
 183              $order_by = 'link_order, link_ID';
 184          }
 185  
 186          $SQL->SELECT( 'link_ID, link_ltype_ID, link_position, link_cmt_ID, link_itm_ID, file_ID, file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc' );
 187          $SQL->FROM( 'T_links LEFT JOIN T_files ON link_file_ID = file_ID' );
 188          $SQL->WHERE( $this->get_where_condition() );
 189          $SQL->ORDER_BY( $order_by );
 190  
 191          return $SQL;
 192      }
 193  
 194      /**

 195       * Get link owner object ID

 196       */
 197  	function get_ID()
 198      {
 199          return $this->link_Object->ID;
 200      }
 201  
 202      /**

 203       * Get link owner object parameter

 204       * 

 205       * @param string parameter name to get

 206       */
 207  	function get( $parname )
 208      {
 209          return $this->link_Object->dget( $parname );
 210      }
 211  
 212      /**

 213       * Get a ready-to-display position name by key value

 214       * 

 215       * @param string link position

 216       */
 217  	function dget_position( $position )
 218      {
 219          $positions = $this->get_positions();
 220          if( isset( $positions[ $position ] ) )
 221          {
 222              return $positions[ $position ];
 223          }
 224          return NULL;
 225      }
 226  
 227      /**

 228       * Get default position for a new link

 229       * 

 230       * @param boolean new link file is image or not

 231       */
 232  	function get_default_position( $is_image = false )
 233      {
 234          $this->load_Links();
 235  
 236          if( $this->Links )
 237          {
 238              $position = NULL;
 239              $last_Link = array_pop( $this->Links );
 240              $last_File = & $last_Link->get_File();
 241  
 242              if( $last_File && $is_image && $last_File->is_image() && ! count( $this->Links ) )
 243              { // there's only one image attached yet, the second becomes "aftermore"
 244                  $position = 'aftermore';
 245              }
 246              else
 247              { // default: use position of previous link/attachment
 248                  $position = $last_Link->get('position');
 249              }
 250  
 251              // Re-add popped link.

 252              $this->Links[] = $last_Link;
 253          }
 254          else
 255          { // no attachment yet
 256              $position = $is_image ? 'teaser' : 'aftermore';
 257          }
 258  
 259          return $position;
 260      }
 261  
 262  
 263      /**

 264       * Get list of attached files

 265       * 

 266       * INNER JOIN on files ensures we only get back file links

 267       * 

 268       * @param integer Limit max result

 269       * @param string Restrict to files/images linked to a specific position.

 270       *               Position can be 'teaser'|'aftermore'|'inline'

 271       *               Use comma as separator

 272       * @param string order by

 273       * @return DataObjectList2 on success or NULL if no linked files found

 274       */
 275  	function get_attachment_FileList( $limit = 1000, $position = NULL, $order = 'link_ID' )
 276      {
 277          if( ! isset($GLOBALS['files_Module']) )
 278          {
 279              return NULL;
 280          }
 281  
 282          load_class( '_core/model/dataobjects/_dataobjectlist2.class.php', 'DataObjectList2' );
 283  
 284          $FileCache = & get_FileCache();
 285  
 286          $FileList = new DataObjectList2( $FileCache ); // IN FUNC

 287  
 288          $SQL = new SQL();
 289          $SQL->SELECT( 'file_ID, file_title, file_root_type, file_root_ID, file_path, file_alt, file_desc, link_ID' );
 290          $SQL->FROM( 'T_links INNER JOIN T_files ON link_file_ID = file_ID' );
 291          $SQL->WHERE( $this->get_where_condition() );
 292          if( !empty($position) )
 293          {
 294              global $DB;
 295              $position = explode( ',', $position );
 296              $SQL->WHERE_and( 'link_position IN ( '.$DB->quote( $position ).' )' );
 297          }
 298          //$SQL->ORDER_BY( $order );

 299          $SQL->ORDER_BY( 'link_order' );
 300          $SQL->LIMIT( $limit );
 301  
 302          $FileList->sql = $SQL->get();
 303  
 304          $FileList->query( false, false, false, 'get_attachment_FileList' );
 305  
 306          if( $FileList->result_num_rows == 0 )
 307          {    // Nothing found
 308              $FileList = NULL;
 309          }
 310  
 311          return $FileList;
 312      }
 313  
 314  
 315      /**

 316       * Get translated text for the specific link owner class

 317       * 

 318       * @param string text key in the translation map

 319       */
 320  	function translate( $text_key, $text_params = NULL )
 321      {
 322          if( empty( $this->_trans ) || empty( $text_key ) || ( !array_key_exists( $text_key, $this->_trans ) ) )
 323          { // This text was not listed in translation map
 324              return NULL;
 325          }
 326  
 327          return sprintf( T_( $this->_trans[ $text_key ] ), $text_params );
 328      }
 329  
 330  
 331      /**

 332       * Update owner last_touched_ts if exists 

 333       * This must be override in the subclasses if the owner object has last_touched_ts field

 334       */
 335  	function item_update_last_touched_date()
 336      {
 337          return;
 338      }
 339  }
 340  
 341  ?>

title

Description

title

Description

title

Description

title

title

Body