b2evolution PHP Cross Reference Blogging Systems

Source: /inc/files/model/_filerootcache.class.php - 175 lines - 4919 bytes - Summary - Text - Print

Description: This file implements the FileRootCache 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 FileRootCache 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   * {@internal Open Source relicensing agreement:
  20   * }}
  21   *
  22   * @package evocore
  23   *
  24   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  25   * @author fplanque: Francois PLANQUE.
  26   *
  27   * @version $Id: _filerootcache.class.php 6136 2014-03-08 07:59:48Z manuel $
  28   */
  29  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  30  
  31  
  32  load_class( '/files/model/_fileroot.class.php', 'FileRoot' );
  33  
  34  
  35  /**
  36   * This class provides info about File Roots.
  37   *
  38   * These are root directories available for media file storage, under access permission.
  39   *
  40   * @package evocore
  41   */
  42  class FileRootCache
  43  {
  44      /**
  45       * Internal cache
  46       * @var array
  47       */
  48      var $cache = array();
  49  
  50  
  51      /**
  52       * Get an array of ALL available Fileroots (not just the cached ones).
  53       *
  54       * @todo fp> it would probably make sense to refactor this as the constructor for the file roots
  55       * and initialize the whole cache at construction time
  56       *
  57       * @static
  58       *
  59       * @return array of FileRoots (key being the FileRoot's ID)
  60       */
  61  	function get_available_FileRoots()
  62      {
  63          global $current_User;
  64          global $collections_Module;
  65  
  66          $r = array();
  67  
  68          // The user's blog (if available) is the default/first one:
  69          $user_FileRoot = & $this->get_by_type_and_ID( 'user', $current_User->ID, true );
  70          if( $user_FileRoot )
  71          { // We got a user media dir:
  72              $r[ $user_FileRoot->ID ] = & $user_FileRoot;
  73          }
  74  
  75          if( isset($collections_Module) )
  76          {    // Blog/collection media dirs:
  77              $BlogCache = & get_BlogCache();
  78              $bloglist = $BlogCache->load_user_blogs( 'blog_media_browse', $current_User->ID );
  79              foreach( $bloglist as $blog_ID )
  80              {
  81                  if( $Root = & $this->get_by_type_and_ID( 'collection', $blog_ID, true ) )
  82                  {
  83                      $r[ $Root->ID ] = & $Root;
  84                  }
  85              }
  86          }
  87  
  88          // Shared root:
  89          $shared_FileRoot = & $this->get_by_type_and_ID( 'shared', 0, true );
  90          if( $shared_FileRoot )
  91          { // We got a shared dir:
  92              $r[ $shared_FileRoot->ID ] = & $shared_FileRoot;
  93          }
  94  
  95          if( isset($collections_Module) )
  96          { // Skins root:
  97              $skins_FileRoot = & $this->get_by_type_and_ID( 'skins', 0, false );
  98              if( $skins_FileRoot )
  99              { // We got a skins dir:
 100                  $r[ $skins_FileRoot->ID ] = & $skins_FileRoot;
 101              }
 102          }
 103  
 104          return $r;
 105      }
 106  
 107  
 108      /**
 109       * Get a FileRoot (cached) by ID.
 110       *
 111       * @uses FileRootCache::get_by_type_and_ID()
 112       * @param string ID of the FileRoot (e.g. 'user_X' or 'collection_X')
 113       * @param boolean Create the directory, if it does not exist yet?
 114       * @return FileRoot|false FileRoot on success, false on failure (ads_path is false).
 115       */
 116      function & get_by_ID( $id, $create = false )
 117      {
 118          $part = explode( '_', $id );
 119          $root_type = $part[0];
 120          $root_in_type_ID = $part[1];
 121  
 122          return $this->get_by_type_and_ID( $root_type, $root_in_type_ID, $create );
 123      }
 124  
 125  
 126      /**
 127       * Get a FileRoot (cached).
 128       *
 129       * @param string Root type: 'user', 'group', 'collection' or 'absolute'
 130       * @param integer ID of the user, the group or the collection the file belongs to...
 131       * @param boolean Create the directory, if it does not exist yet?
 132       * @return FileRoot|false FileRoot on success, false on failure (ads_path is false).
 133       */
 134      function & get_by_type_and_ID( $root_type, $root_in_type_ID, $create = false )
 135      {
 136          $root_ID = FileRoot::gen_ID( $root_type, $root_in_type_ID );
 137  
 138          if( ! isset( $this->cache[$root_ID] ) )
 139          {    // Not in Cache, let's instantiate:
 140              $Root = new FileRoot( $root_type, $root_in_type_ID, $create ); // COPY (func)
 141              if( empty($Root->ads_path) ) // false
 142              {
 143                  $Root = false;
 144              }
 145              $this->cache[$root_ID] = & $Root;
 146          }
 147  
 148          return $this->cache[$root_ID];
 149      }
 150  
 151  
 152      /**
 153       * Get the absolute path (FileRoot::ads_path) to a given root (with ending slash).
 154       *
 155       * @deprecated since 1.9
 156       * @param boolean Create the directory, if it does not exist yet?
 157       * @return string
 158       */
 159  	function get_root_dir( $root_type, $root_in_type_ID, $create = false )
 160      {
 161          $tmp_FileRoot = & $this->get_by_type_and_ID( $root_type, $root_in_type_ID, $create );
 162          return $tmp_FileRoot->ads_path;
 163      }
 164  
 165  
 166      /**
 167       * Clear the cache
 168       */
 169  	function clear()
 170      {
 171          $this->cache = array();
 172      }
 173  }
 174  
 175  ?>

title

Description

title

Description

title

Description

title

title

Body