b2evolution PHP Cross Reference Blogging Systems

Source: /inc/links/model/_linkitem.class.php - 179 lines - 4697 bytes - Summary - Text - Print

Description: This file implements the LinkItem class, which is a wrapper class for Item class to handle linked files. 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 LinkItem class, which is a wrapper class for Item class to handle linked files.

   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   * @package evocore

  11   *

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

  13   * @author efy-asimo: Attila Simo.

  14   *

  15   * @version $Id: $

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

  20   * LinkItem Class

  21   *

  22   * @package evocore

  23   */
  24  class LinkItem extends LinkOwner
  25  {
  26      /**

  27       * @var Item

  28       */
  29      var $Item;
  30  
  31      /**

  32       * Constructor

  33       */
  34  	function LinkItem( $Item )
  35      {
  36          // call parent contsructor

  37          parent::LinkOwner( $Item, 'item' );
  38          $this->Item = & $this->link_Object;
  39  
  40          $this->_trans = array(
  41              'Link this image to your owner' => NT_( 'Link this image to your item.' ),
  42              'Link this file to your owner' => NT_( 'Link this file to your item.'),
  43              'The file will be linked for download at the end of the owner' => NT_( 'The file will be appended for linked at the end of the item.' ),
  44              'Insert the following code snippet into your owner' => NT_( 'Insert the following code snippet into your item.' ),
  45              'View this owner...' => NT_( 'View this item...' ),
  46              'Edit this owner...' => NT_( 'Edit this item...' ),
  47              'Click on link %s icons below to link additional files to $ownerTitle$.' => NT_( 'Click on link %s icons below to link additional files to <strong>item</strong>.' ),
  48              'Link files to current owner' => NT_( 'Link files to current item' ),
  49              'Selected files have been linked to owner.' => NT_( 'Selected files have been linked to item.' ),
  50              'Link has been deleted from $ownerTitle$.' => NT_( 'Link has been deleted from &laquo;item&raquo;.' ),
  51          );
  52      }
  53  
  54      /**

  55       * Check current User Item permission

  56       *

  57       * @param string permission level

  58       * @param boolean true to assert if user dosn't have the required permission

  59       */
  60  	function check_perm( $permlevel, $assert = false )
  61      {
  62          global $current_User;
  63          return $current_User->check_perm( 'item_post!CURSTATUS', $permlevel, $assert, $this->Item );
  64      }
  65  
  66      /**

  67       * Get all positions ( key, display ) pairs where link can be displayed

  68       *

  69       * @return array

  70       */
  71  	function get_positions()
  72      {
  73          return array(
  74              'teaser' => T_( 'Teaser' ),
  75              'aftermore' => T_( 'After "more"' ),
  76              'inline' => T_( 'Inline' ),
  77              );
  78      }
  79  
  80      /**

  81       * Load all links of owner Item if it was not loaded yet

  82       */
  83  	function load_Links()
  84      {
  85          if( is_null( $this->Links ) )
  86          { // Links have not been loaded yet:
  87              $LinkCache = & get_LinkCache();
  88              $this->Links = $LinkCache->get_by_item_ID( $this->Item->ID );
  89          }
  90      }
  91  
  92      /**

  93       * Add new link to owner Item

  94       *

  95       * @param integer file ID

  96       * @param integer link position ( 'teaser', 'aftermore' )

  97       * @param int order of the link

  98       */
  99  	function add_link( $file_ID, $position, $order = 1 )
 100      {
 101          $edited_Link = new Link();
 102          $edited_Link->set( 'itm_ID', $this->Item->ID );
 103          $edited_Link->set( 'file_ID', $file_ID );
 104          $edited_Link->set( 'position', $position );
 105          $edited_Link->set( 'order', $order );
 106          $edited_Link->dbinsert();
 107  
 108          // New link was added to the item, invalidate blog's media BlockCache

 109          BlockCache::invalidate_key( 'media_coll_ID', $this->Item->get_blog_ID() );
 110  
 111          // Update last touched date of the Item

 112          $this->item_update_last_touched_date();
 113      }
 114  
 115      /**

 116       * Set Blog

 117       */
 118  	function load_Blog()
 119      {
 120          if( is_null( $this->Blog ) )
 121          {
 122              $this->Blog = & $this->Item->get_Blog();
 123          }
 124      }
 125  
 126      /**

 127       * Get where condition for select query to get Item links

 128       */
 129  	function get_where_condition() {
 130          return 'link_itm_ID = '.$this->Item->ID;
 131      }
 132  
 133      /**

 134       * Get Item parameter

 135       *

 136       * @param string parameter name to get

 137       */
 138  	function get( $parname )
 139      {
 140          switch( $parname )
 141          {
 142              case 'name':
 143                  return 'post';
 144          }
 145          return parent::get( $parname );
 146      }
 147  
 148      /**

 149       * Get Item edit url

 150       */
 151  	function get_edit_url()
 152      {
 153          $this->load_Blog();
 154          return '?ctrl=items&amp;blog='.$this->Blog->ID.'&amp;action=edit&amp;p='.$this->Item->ID;
 155      }
 156  
 157      /**

 158       * Get Item view url

 159       */
 160  	function get_view_url()
 161      {
 162          $this->load_Blog();
 163          return '?ctrl=items&amp;blog='.$this->Blog->ID.'&amp;p='.$this->Item->ID;
 164      }
 165  
 166  
 167      /**

 168       * Update field last_touched_ts of Item

 169       */
 170  	function item_update_last_touched_date()
 171      {
 172          if( !empty( $this->Item ) )
 173          {    // Update Item if it exists
 174              $this->Item->update_last_touched_date();
 175          }
 176      }
 177  }
 178  
 179  ?>

title

Description

title

Description

title

Description

title

title

Body