| [ Index ] |
|
Code source de b2evolution 2.1.0-beta |
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-2007 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.1 2007/06/25 10:59:56 fplanque 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'); 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 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->ID, true ); 69 if( $user_FileRoot ) 70 { // We got a user media dir: 71 $r[ $user_FileRoot->ID ] = & $user_FileRoot; 72 } 73 74 // blog/collection media dirs: 75 $BlogCache = & get_Cache( 'BlogCache' ); 76 $bloglist = $BlogCache->load_user_blogs( 'blog_media_browse', $current_User->ID ); 77 foreach( $bloglist as $blog_ID ) 78 { 79 if( $Root = & $this->get_by_type_and_ID( 'collection', $blog_ID, true ) ) 80 { 81 $r[ $Root->ID ] = & $Root; 82 } 83 } 84 85 // skins root: 86 $skins_FileRoot = & $this->get_by_type_and_ID( 'skins', 0, false ); 87 if( $skins_FileRoot ) 88 { // We got a skins dir: 89 $r[ $skins_FileRoot->ID ] = & $skins_FileRoot; 90 } 91 92 return $r; 93 } 94 95 96 /** 97 * Get a FileRoot (cached) by ID. 98 * 99 * @uses FileRootCache::get_by_type_and_ID() 100 * @param string ID of the FileRoot (e.g. 'user_X' or 'collection_X') 101 * @param boolean Create the directory, if it does not exist yet? 102 * @return FileRoot|false FileRoot on success, false on failure (ads_path is false). 103 */ 104 function & get_by_ID( $id, $create = false ) 105 { 106 $part = explode( '_', $id ); 107 $root_type = $part[0]; 108 $root_in_type_ID = $part[1]; 109 110 return $this->get_by_type_and_ID( $root_type, $root_in_type_ID, $create ); 111 } 112 113 114 /** 115 * Get a FileRoot (cached). 116 * 117 * @param string Root type: 'user', 'group', 'collection' or 'absolute' 118 * @param integer ID of the user, the group or the collection the file belongs to... 119 * @param boolean Create the directory, if it does not exist yet? 120 * @return FileRoot|false FileRoot on success, false on failure (ads_path is false). 121 */ 122 function & get_by_type_and_ID( $root_type, $root_in_type_ID, $create = false ) 123 { 124 $root_ID = FileRoot::gen_ID( $root_type, $root_in_type_ID ); 125 126 if( ! isset( $this->cache[$root_ID] ) ) 127 { // Not in Cache, let's instantiate: 128 $Root = new FileRoot( $root_type, $root_in_type_ID, $create ); // COPY (func) 129 if( empty($Root->ads_path) ) // false 130 { 131 $Root = false; 132 } 133 $this->cache[$root_ID] = & $Root; 134 } 135 136 return $this->cache[$root_ID]; 137 } 138 139 140 /** 141 * Get the absolute path (FileRoot::ads_path) to a given root (with ending slash). 142 * 143 * @deprecated since 1.9 144 * @param boolean Create the directory, if it does not exist yet? 145 * @return string 146 */ 147 function get_root_dir( $root_type, $root_in_type_ID, $create = false ) 148 { 149 $tmp_FileRoot = & $this->get_by_type_and_ID( $root_type, $root_in_type_ID, $create ); 150 return $tmp_FileRoot->ads_path; 151 } 152 } 153 154 155 /* 156 * $Log: _filerootcache.class.php,v $ 157 * Revision 1.1 2007/06/25 10:59:56 fplanque 158 * MODULES (refactored MVC) 159 * 160 * Revision 1.9 2007/05/09 01:01:32 fplanque 161 * permissions cleanup 162 * 163 * Revision 1.8 2007/04/26 00:11:10 fplanque 164 * (c) 2007 165 * 166 * Revision 1.7 2006/12/07 23:13:10 fplanque 167 * @var needs to have only one argument: the variable type 168 * Otherwise, I can't code! 169 * 170 * Revision 1.6 2006/12/07 15:23:42 fplanque 171 * filemanager enhanced, refactored, extended to skins directory 172 * 173 * Revision 1.5 2006/11/24 18:27:24 blueyed 174 * Fixed link to b2evo CVS browsing interface in file docblocks 175 */ 176 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
|