b2evolution

Multilingual multiuser multiblog engine

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

Source for file _fileroot.class.php

Documentation is available at _fileroot.class.php

  1. <?php
  2. /**
  3.  * This file implements the FileRoot 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: _fileroot.class.php,v 1.12 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. /**
  33.  * This class provides info about a File Root.
  34.  *
  35.  * A FileRoot describes a directory available for media file storage, under access permission.
  36.  *
  37.  * @package evocore
  38.  */
  39. class FileRoot
  40. {
  41.     /**
  42.      * Type: 'user', 'group' or 'collection'.
  43.      *
  44.      * Note: group is not implemented yet. Absolute will probably be deprecated.
  45.      */
  46.     var $type;
  47.  
  48.     /**
  49.      * ID of user, group or collection.
  50.      */
  51.     var $in_type_ID;
  52.  
  53.     /**
  54.      * Unique Root ID constructed from type and in_type_ID
  55.      * @var string 
  56.      */
  57.     var $ID;
  58.  
  59.     /**
  60.      * Name of the root
  61.      */
  62.     var $name;
  63.  
  64.     /**
  65.      * Absolute path, ending with slash
  66.      */
  67.     var $ads_path;
  68.  
  69.     /**
  70.      * Absolute URL, ending with slash
  71.      */
  72.     var $ads_url;
  73.  
  74.  
  75.     /**
  76.      * Constructor
  77.      *
  78.      * Will fail if non existent User or Blog is requested.
  79.      * But specific access permissions on (threfore existence of) this User or Blog should have been tested before anyway.
  80.      *
  81.      * @param string Root type: 'user', 'group' or 'collection'
  82.      * @param integer ID of the user, the group or the collection the file belongs to...
  83.      * @param boolean Create the directory, if it does not exist yet?
  84.      */
  85.     function FileRoot$root_type$root_in_type_ID$create true )
  86.     {
  87.         /**
  88.          * @var User
  89.          */
  90.         global $current_User;
  91.         global $Messages;
  92.          global $Settings$Debuglog;
  93.  
  94.         // Store type:
  95.         $this->type = $root_type;
  96.         // Store ID in type:
  97.         $this->in_type_ID = $root_in_type_ID;
  98.         // Generate unique ID:
  99.         $this->ID = FileRoot::gen_ID$root_type$root_in_type_ID );
  100.  
  101.         switch$root_type )
  102.         {
  103.             case 'user':
  104.                 $UserCache get_UserCache();
  105.                 $User $UserCache->get_by_ID$root_in_type_ID );
  106.                 $this->name = $User->get'preferredname' )//.' ('. /* TRANS: short for "user" */ T_('u').')';
  107.                 $this->ads_path = $User->get_media_dir$create );
  108.                 $this->ads_url = $User->get_media_url();
  109.                 return;
  110.  
  111.             case 'collection':
  112.                 $BlogCache get_BlogCache();
  113.                 /**
  114.                  * @var Blog
  115.                  */
  116.                 $Blog $BlogCache->get_by_ID$root_in_type_ID );
  117.                 $this->name = $Blog->get'shortname' )//.' ('. /* TRANS: short for "blog" */ T_('b').')';
  118.                 $this->ads_path = $Blog->get_media_dir$create );
  119.                 $this->ads_url = $Blog->get_media_url();
  120.                 return;
  121.  
  122.             case 'shared':
  123.                 // fp> TODO: handle multiple shared directories
  124.                 global $media_path$media_url;
  125.                 $rds_shared_subdir 'shared/global/';
  126.                 $ads_shared_dir $media_path.$rds_shared_subdir;
  127.  
  128.                 if$Settings->get'fm_enable_roots_shared' ) )
  129.                 // Shared dir is disabled:
  130.                     $Debuglog->add'Attempt to access shared dir, but this feature is globally disabled''files' );
  131.                 }
  132.                 /* Try to create shared directory if it doesn't exist.
  133.                  * Note: mkdir_r() already checks if the dir to create exists.
  134.                  */
  135.                 elseifmkdir_r$ads_shared_dir ) )
  136.                 {
  137.                     // Only display error on an admin page:
  138.                     ifis_admin_page() )
  139.                     {
  140.                         $Messages->addsprintfT_('The directory &laquo;%s&raquo; could not be created.')$rds_shared_subdir ).get_manual_link('directory_creation_error')'error' );
  141.                     }
  142.                 }
  143.                 else
  144.                 {
  145.                     $this->name = T_('Shared');
  146.                     $this->ads_path = $ads_shared_dir;
  147.                     $this->ads_url = $media_url.'shared/global/';
  148.                 }
  149.                 return;
  150.  
  151.         case 'skins':
  152.             // fp> some stuff here should go out of here... but I don't know where to put it yet. I'll see after the Skin refactoring.
  153.              if$Settings->get'fm_enable_roots_skins' ) )
  154.                 // Skins root is disabled:
  155.                     $Debuglog->add'Attempt to access skins dir, but this feature is globally disabled''files' );
  156.                 }
  157.                 elseif$current_User->check_perm'templates' ) )
  158.                 {    // No perm to access templates:
  159.                     $Debuglog->add'Attempt to access skins dir, but no permission''files' );
  160.                 }
  161.                 else
  162.                 {
  163.                     global $skins_path$skins_url;
  164.                     $this->name = T_('Skins');
  165.                     $this->ads_path = $skins_path;
  166.                     $this->ads_url = $skins_url;
  167.                 }
  168.                 return;
  169.         }
  170.  
  171.         debug_die"Root_type=$root_type not supported);
  172.     }
  173.  
  174.  
  175.     function get_typegroupname()
  176.     {
  177.         switch$this->type )
  178.         {
  179.             case 'user':
  180.                 return NT_('User roots');
  181.  
  182.             case 'collection':
  183.                 return NT_('Blog roots');
  184.  
  185.             default:
  186.                 return NT_('Special roots');
  187.         }
  188.     }
  189.  
  190.     /**
  191.      * @static
  192.      */
  193.     function gen_ID$root_type$root_in_type_ID )
  194.     {
  195.         switch$root_type )
  196.         {
  197.             case 'user':
  198.             case 'shared':
  199.             case 'collection':
  200.             case 'skins':
  201.                 return $root_type.'_'.$root_in_type_ID;
  202.         }
  203.  
  204.         debug_die"Root_type=$root_type not supported);
  205.     }
  206.  
  207. }
  208.  
  209.  
  210. /*
  211.  * $Log: _fileroot.class.php,v $
  212.  * Revision 1.12  2010/02/08 17:52:18  efy-yury
  213.  * copyright 2009 -> 2010
  214.  *
  215.  * Revision 1.11  2009/09/26 12:00:42  tblue246
  216.  * Minor/coding style
  217.  *
  218.  * Revision 1.10  2009/09/25 07:32:52  efy-cantor
  219.  * replace get_cache to get_*cache
  220.  *
  221.  * Revision 1.9  2009/09/05 19:16:05  tblue246
  222.  * Correct (?) if condition.
  223.  *
  224.  * Revision 1.8  2009/08/31 16:56:10  fplanque
  225.  * if-conditions did not seem right
  226.  *
  227.  * Revision 1.7  2009/08/22 15:27:38  tblue246
  228.  * - FileRoot::FileRoot():
  229.  *     - Only try to create shared dir if enabled.
  230.  * - Hit::extract_serprank_from_referer():
  231.  *     - Do not explode() $ref string, but use a (dynamically generated) RegExp instead. Tested and should work.
  232.  *
  233.  * Revision 1.6  2009/08/17 05:50:33  sam2kb
  234.  * Create shared/global/  directories if not exist yet
  235.  * See http://forums.b2evolution.net/viewtopic.php?t=19411
  236.  *
  237.  * Revision 1.5  2009/03/08 23:57:43  fplanque
  238.  * 2009
  239.  *
  240.  * Revision 1.4  2008/09/23 06:18:37  fplanque
  241.  * File manager now supports a shared directory (/media/shared/global/)
  242.  *
  243.  * Revision 1.3  2008/01/21 09:35:29  fplanque
  244.  * (c) 2008
  245.  *
  246.  * Revision 1.2  2007/11/01 04:31:25  fplanque
  247.  * Better root browsing (roots are groupes by type + only one root is shown at a time)
  248.  *
  249.  * Revision 1.1  2007/06/25 10:59:56  fplanque
  250.  * MODULES (refactored MVC)
  251.  *
  252.  * Revision 1.14  2007/04/26 00:11:10  fplanque
  253.  * (c) 2007
  254.  *
  255.  * Revision 1.13  2007/02/11 15:16:49  fplanque
  256.  * doc
  257.  *
  258.  * Revision 1.11  2006/12/10 03:04:16  blueyed
  259.  * TRANS note for "u" and "b"
  260.  *
  261.  * Revision 1.10  2006/12/08 01:53:18  fplanque
  262.  * Added missing skin access switch
  263.  *
  264.  * Revision 1.9  2006/12/07 15:23:42  fplanque
  265.  * filemanager enhanced, refactored, extended to skins directory
  266.  *
  267.  * Revision 1.8  2006/11/24 18:27:24  blueyed
  268.  * Fixed link to b2evo CVS browsing interface in file docblocks
  269.  */
  270. ?>

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