b2evolution

Multilingual multiuser multiblog engine

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

Source for file _filerootcache.class.php

Documentation is available at _filerootcache.class.php

  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-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.  *  {@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,v 1.9 2010/02/08 17:52:18 efy-yury Exp $
  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. {
  43.     /**
  44.      * Internal cache
  45.      * @var array 
  46.      */
  47.     var $cache = array();
  48.  
  49.  
  50.     /**
  51.      * Get an array of ALL available Fileroots (not just the cached ones).
  52.      *
  53.      * @todo fp> it would probably make sense to refactor this as the constructor for the file roots
  54.      *  and initialize the whole cache at construction time
  55.      *
  56.      * @static
  57.      *
  58.      * @return array of FileRoots (key being the FileRoot's ID)
  59.      */
  60.     function get_available_FileRoots()
  61.     {
  62.         global $current_User;
  63.         global $collections_Module;
  64.  
  65.         $r array();
  66.  
  67.         // The user's blog (if available) is the default/first one:
  68.         $user_FileRoot $this->get_by_type_and_ID'user'$current_User->IDtrue );
  69.         if$user_FileRoot )
  70.         // We got a user media dir:
  71.             $r$user_FileRoot->ID $user_FileRoot;
  72.         }
  73.  
  74.         ifisset($collections_Module) )
  75.         {    // Blog/collection media dirs:
  76.             $BlogCache get_BlogCache();
  77.             $bloglist $BlogCache->load_user_blogs'blog_media_browse'$current_User->ID );
  78.             foreach$bloglist as $blog_ID )
  79.             {
  80.                 if$Root $this->get_by_type_and_ID'collection'$blog_IDtrue ) )
  81.                 {
  82.                     $r$Root->ID $Root;
  83.                 }
  84.             }
  85.         }
  86.  
  87.         // Shared root:
  88.         $shared_FileRoot $this->get_by_type_and_ID'shared'0true );
  89.         if$shared_FileRoot )
  90.         // We got a shared dir:
  91.             $r$shared_FileRoot->ID $shared_FileRoot;
  92.         }
  93.  
  94.         ifisset($collections_Module) )
  95.         // Skins root:
  96.             $skins_FileRoot $this->get_by_type_and_ID'skins'0false );
  97.             if$skins_FileRoot )
  98.             // We got a skins dir:
  99.                 $r$skins_FileRoot->ID $skins_FileRoot;
  100.             }
  101.         }
  102.         
  103.         return $r;
  104.     }
  105.  
  106.  
  107.     /**
  108.      * Get a FileRoot (cached) by ID.
  109.      *
  110.      * @uses FileRootCache::get_by_type_and_ID()
  111.      * @param string ID of the FileRoot (e.g. 'user_X' or 'collection_X')
  112.      * @param boolean Create the directory, if it does not exist yet?
  113.      * @return FileRoot|falseFileRoot on success, false on failure (ads_path is false).
  114.      */
  115.     function get_by_ID$id$create false )
  116.     {
  117.         $part explode'_'$id );
  118.         $root_type $part[0];
  119.         $root_in_type_ID $part[1];
  120.  
  121.         return $this->get_by_type_and_ID$root_type$root_in_type_ID$create );
  122.     }
  123.  
  124.  
  125.     /**
  126.      * Get a FileRoot (cached).
  127.      *
  128.      * @param string Root type: 'user', 'group', 'collection' or 'absolute'
  129.      * @param integer ID of the user, the group or the collection the file belongs to...
  130.      * @param boolean Create the directory, if it does not exist yet?
  131.      * @return FileRoot|falseFileRoot on success, false on failure (ads_path is false).
  132.      */
  133.     function get_by_type_and_ID$root_type$root_in_type_ID$create false )
  134.     {
  135.         $root_ID FileRoot::gen_ID$root_type$root_in_type_ID );
  136.  
  137.         ifisset$this->cache[$root_ID) )
  138.         {    // Not in Cache, let's instantiate:
  139.             $Root new FileRoot$root_type$root_in_type_ID$create )// COPY (func)
  140.             ifempty($Root->ads_path) ) // false
  141.             {
  142.                 $Root false;
  143.             }
  144.             $this->cache[$root_ID$Root;
  145.         }
  146.  
  147.         return $this->cache[$root_ID];
  148.     }
  149.  
  150.  
  151.     /**
  152.      * Get the absolute path (FileRoot::ads_path) to a given root (with ending slash).
  153.      *
  154.      * @deprecated since 1.9
  155.      * @param boolean Create the directory, if it does not exist yet?
  156.      * @return string 
  157.      */
  158.     function get_root_dir$root_type$root_in_type_ID$create false )
  159.     {
  160.         $tmp_FileRoot $this->get_by_type_and_ID$root_type$root_in_type_ID$create );
  161.         return $tmp_FileRoot->ads_path;
  162.     }
  163. }
  164.  
  165.  
  166. /*
  167.  * $Log: _filerootcache.class.php,v $
  168.  * Revision 1.9  2010/02/08 17:52:18  efy-yury
  169.  * copyright 2009 -> 2010
  170.  *
  171.  * Revision 1.8  2009/09/26 12:00:42  tblue246
  172.  * Minor/coding style
  173.  *
  174.  * Revision 1.7  2009/09/25 07:32:52  efy-cantor
  175.  * replace get_cache to get_*cache
  176.  *
  177.  * Revision 1.6  2009/09/14 13:04:53  efy-arrin
  178.  * Included the ClassName in load_class() call with proper UpperCase
  179.  *
  180.  * Revision 1.5  2009/08/30 00:30:52  fplanque
  181.  * increased modularity
  182.  *
  183.  * Revision 1.4  2009/03/08 23:57:43  fplanque
  184.  * 2009
  185.  *
  186.  * Revision 1.3  2008/09/23 06:18:38  fplanque
  187.  * File manager now supports a shared directory (/media/shared/global/)
  188.  *
  189.  * Revision 1.2  2008/01/21 09:35:29  fplanque
  190.  * (c) 2008
  191.  *
  192.  * Revision 1.1  2007/06/25 10:59:56  fplanque
  193.  * MODULES (refactored MVC)
  194.  *
  195.  * Revision 1.9  2007/05/09 01:01:32  fplanque
  196.  * permissions cleanup
  197.  *
  198.  * Revision 1.8  2007/04/26 00:11:10  fplanque
  199.  * (c) 2007
  200.  *
  201.  * Revision 1.7  2006/12/07 23:13:10  fplanque
  202.  * @var needs to have only one argument: the variable type
  203.  * Otherwise, I can't code!
  204.  *
  205.  * Revision 1.6  2006/12/07 15:23:42  fplanque
  206.  * filemanager enhanced, refactored, extended to skins directory
  207.  *
  208.  * Revision 1.5  2006/11/24 18:27:24  blueyed
  209.  * Fixed link to b2evo CVS browsing interface in file docblocks
  210.  */
  211. ?>

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