b2evolution PHP Cross Reference Blogging Systems

Source: /inc/links/model/_linkuser.class.php - 172 lines - 4285 bytes - Summary - Text - Print

Description: This file implements the LinkUser class, which is a wrapper class for User 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 LinkUser class, which is a wrapper class for User 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   * LinkUser Class

  21   *

  22   * @package evocore

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

  27       * @var User

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

  32       * Constructor

  33       */
  34  	function LinkUser( $User )
  35      {
  36          // call parent contsructor

  37          parent::LinkOwner( $User, 'user' );
  38          $this->User = & $this->link_Object;
  39  
  40          $this->_trans = array(
  41              'Link this image to your owner' => NT_( 'Link this image to the user.' ),
  42              'Link this file to your owner' => NT_( 'Link this file to the user.'),
  43              'View this owner...' => NT_( 'View this user...' ),
  44              'Edit this owner...' => NT_( 'Edit this user...' ),
  45              '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>user</strong>.' ),
  46              'Link files to current owner' => NT_( 'Link files to current user' ),
  47              'Link has been deleted from $ownerTitle$.' => NT_( 'Link has been deleted from &laquo;user&raquo;.' ),
  48          );
  49      }
  50  
  51      /**

  52       * Check current User users permission

  53       *

  54       * @param string permission level

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

  56       */
  57  	function check_perm( $permlevel, $assert = false )
  58      {
  59          global $current_User;
  60          return $current_User->ID == $this->User->ID || $current_User->check_perm( 'users', $permlevel, $assert );
  61      }
  62  
  63      /**

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

  65       *

  66       * @return array

  67       */
  68  	function get_positions()
  69      {
  70          return array();
  71      }
  72  
  73      /**

  74       * Load all links of owner User if it was not loaded yet

  75       */
  76  	function load_Links()
  77      {
  78          if( is_null( $this->Links ) )
  79          { // Links have not been loaded yet:
  80              $LinkCache = & get_LinkCache();
  81              $this->Links = $LinkCache->get_by_user_ID( $this->User->ID );
  82          }
  83      }
  84  
  85      /**

  86       * Clear all links of owner User

  87       */
  88  	function clear_Links()
  89      {
  90          if( ! is_null( $this->Links ) )
  91          { // Links have been loaded:
  92              $this->Links = NULL;
  93              $LinkCache = & get_LinkCache();
  94              $LinkCache->clear( false, 'user', $this->User->ID );
  95          }
  96      }
  97  
  98      /**

  99       * Add new link to owner User

 100       *

 101       * @param integer file ID

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

 103       * @param int order of the link

 104       */
 105  	function add_link( $file_ID, $position, $order = 1 )
 106      {
 107          global $current_User;
 108  
 109          $edited_Link = new Link();
 110          $edited_Link->set( 'usr_ID', $this->User->ID );
 111          $edited_Link->set( 'file_ID', $file_ID );
 112          $edited_Link->set( 'position', $position );
 113          $edited_Link->set( 'order', $order );
 114  
 115          if( empty( $current_User ) )
 116          { // Current User not is set because probably we are creating links from upgrade script. Set the owner as creator and last editor.
 117              $edited_Link->set( 'creator_user_ID', $this->User->ID );
 118              $edited_Link->set( 'lastedit_user_ID', $this->User->ID );
 119          }
 120          $edited_Link->dbinsert();
 121      }
 122  
 123      /**

 124       * Set Blog

 125       */
 126  	function load_Blog()
 127      {
 128          // User has no blog

 129      }
 130  
 131      /**

 132       * Get where condition for select query to get User links

 133       */
 134  	function get_where_condition() {
 135          return 'link_usr_ID = '.$this->User->ID;
 136      }
 137  
 138      /**

 139       * Get User parameter

 140       *

 141       * @param string parameter name to get

 142       */
 143  	function get( $parname )
 144      {
 145          switch( $parname )
 146          {
 147              case 'name':
 148                  return 'user';
 149              case 'title':
 150                  return $this->User->login;
 151          }
 152          return parent::get( $parname );
 153      }
 154  
 155      /**

 156       * Get User edit url

 157       */
 158  	function get_edit_url()
 159      {
 160          return '?ctrl=user&amp;user_tab=avatar&amp;user_ID='.$this->User->ID;
 161      }
 162  
 163      /**

 164       * Get User view url

 165       */
 166  	function get_view_url()
 167      {
 168          return '?ctrl=user&amp;user_tab=profile&amp;user_ID='.$this->User->ID;
 169      }
 170  }
 171  
 172  ?>

title

Description

title

Description

title

Description

title

title

Body