VFS
[ class tree: VFS ] [ index: VFS ] [ all elements ]

Source for file horde.php

Documentation is available at horde.php

  1. <?php
  2. /**
  3.  * VFS implementation for the Horde Application Framework.
  4.  *
  5.  * Required parameters:<pre>
  6.  *   'horde_base'  Filesystem location of a local Horde installation.</pre>
  7.  *
  8.  * Optional parameters:<pre>
  9.  *   'user'      A valid Horde user name.
  10.  *   'password'  The user's password.</pre>
  11.  *
  12.  * $Horde: framework/VFS/lib/VFS/horde.php,v 1.1.2.3 2009/01/06 15:23:47 jan Exp $
  13.  *
  14.  * Copyright 2006-2009 The Horde Project (http://www.horde.org/)
  15.  *
  16.  * See the enclosed file COPYING for license information (LGPL). If you
  17.  * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  18.  *
  19.  * @author  Jan Schneider <jan@horde.org>
  20.  * @since   Horde 3.2
  21.  * @package VFS
  22.  */
  23. class VFS_horde extends VFS {
  24.  
  25.     /**
  26.      * Reference to a Horde Registry instance.
  27.      *
  28.      * @var Registry 
  29.      */
  30.     var $_registry;
  31.  
  32.     /**
  33.      * Constructor.
  34.      *
  35.      * @param array $params  A hash containing connection parameters.
  36.      */
  37.     function VFS_horde($params = array())
  38.     {
  39.         parent::VFS($params);
  40.         if (!isset($this->_params['horde_base'])) {
  41.             $this->_registry = PEAR::raiseError(sprintf(_("Required \"%s\" not specified in VFS configuration.")'horde_base'));
  42.             return;
  43.         }
  44.  
  45.         // Define path to Horde.
  46.         @define('HORDE_BASE'$this->_params['horde_base']);
  47.  
  48.         // Load the Horde Framework core, and set up inclusion paths.
  49.         require_once HORDE_BASE . '/lib/core.php';
  50.  
  51.         // Create the Registry object.
  52.         $this->_registry &Registry::singleton();
  53.     }
  54.  
  55.     function _connect()
  56.     {
  57.         if (!empty($this->_params['user']&&
  58.             !empty($this->_params['password'])) {
  59.             include HORDE_BASE . '/config/conf.php';
  60.             $auth_driver = empty($conf['auth']['driver']'none' $conf['auth']['driver'];
  61.             $auth &Auth::singleton($auth_driver);
  62.             $auth->setAuth($this->_params['user'],
  63.                            array('password' => $this->_params['password']));
  64.         }
  65.     }
  66.  
  67.     /**
  68.      * Retrieves the size of a file from the VFS.
  69.      *
  70.      * @abstract
  71.      *
  72.      * @param string $path  The pathname to the file.
  73.      * @param string $name  The filename to retrieve.
  74.      *
  75.      * @return integer The file size.
  76.      */
  77.     function size($path$name)
  78.     {
  79.         if (is_a($this->_registry'PEAR_Error')) {
  80.             return $this->_registry;
  81.         }
  82.         return PEAR::raiseError(_("Not supported."));
  83.     }
  84.  
  85.     /**
  86.      * Retrieves a file from the VFS.
  87.      *
  88.      * @abstract
  89.      *
  90.      * @param string $path  The pathname to the file.
  91.      * @param string $name  The filename to retrieve.
  92.      *
  93.      * @return string The file data.
  94.      */
  95.     function read($path$name)
  96.     {
  97.         if (is_a($this->_registry'PEAR_Error')) {
  98.             return $this->_registry;
  99.         }
  100.  
  101.         if (substr($path01== '/'{
  102.             $path substr($path1);
  103.         }
  104.         $pieces explode('/'$path);
  105.         $data $this->_registry->callByPackage($pieces[0]'browse'array('path' => $path '/' $name));
  106.  
  107.         if (is_object($data)) {
  108.             return $data;
  109.         }
  110.         return $data['data'];
  111.     }
  112.  
  113.     /**
  114.      * Stores a file in the VFS.
  115.      *
  116.      * @abstract
  117.      *
  118.      * @param string $path         The path to store the file in.
  119.      * @param string $name         The filename to use.
  120.      * @param string $tmpFile      The temporary file containing the data to
  121.      *                              be stored.
  122.      * @param boolean $autocreate  Automatically create directories?
  123.      *
  124.      * @return mixed  True on success or a PEAR_Error object on failure.
  125.      */
  126.     function write($path$name$tmpFile$autocreate = false)
  127.     {
  128.         if (is_a($this->_registry'PEAR_Error')) {
  129.             return $this->_registry;
  130.         }
  131.         return PEAR::raiseError(_("Not supported."));
  132.     }
  133.  
  134.     /**
  135.      * Stores a file in the VFS from raw data.
  136.      *
  137.      * @abstract
  138.      *
  139.      * @param string $path         The path to store the file in.
  140.      * @param string $name         The filename to use.
  141.      * @param string $data         The file data.
  142.      * @param boolean $autocreate  Automatically create directories?
  143.      *
  144.      * @return mixed  True on success or a PEAR_Error object on failure.
  145.      */
  146.     function writeData($path$name$data$autocreate = false)
  147.     {
  148.         if (is_a($this->_registry'PEAR_Error')) {
  149.             return $this->_registry;
  150.         }
  151.         return PEAR::raiseError(_("Not supported."));
  152.     }
  153.  
  154.     /**
  155.      * Moves a file through the backend.
  156.      *
  157.      * @abstract
  158.      *
  159.      * @param string $path  The path of the original file.
  160.      * @param string $name  The name of the original file.
  161.      * @param string $dest  The destination file name.
  162.      *
  163.      * @return mixed  True on success or a PEAR_Error object on failure.
  164.      */
  165.     function move($path$name$dest)
  166.     {
  167.         if (is_a($this->_registry'PEAR_Error')) {
  168.             return $this->_registry;
  169.         }
  170.         return PEAR::raiseError(_("Not supported."));
  171.     }
  172.  
  173.     /**
  174.      * Copies a file through the backend.
  175.      *
  176.      * @abstract
  177.      *
  178.      * @param string $path  The path of the original file.
  179.      * @param string $name  The name of the original file.
  180.      * @param string $dest  The name of the destination directory.
  181.      *
  182.      * @return mixed  True on success or a PEAR_Error object on failure.
  183.      */
  184.     function copy($path$name$dest)
  185.     {
  186.         if (is_a($this->_registry'PEAR_Error')) {
  187.             return $this->_registry;
  188.         }
  189.         return PEAR::raiseError(_("Not supported."));
  190.     }
  191.  
  192.     /**
  193.      * Deletes a file from the VFS.
  194.      *
  195.      * @abstract
  196.      *
  197.      * @param string $path  The path to delete the file from.
  198.      * @param string $name  The filename to delete.
  199.      *
  200.      * @return mixed  True on success or a PEAR_Error object on failure.
  201.      */
  202.     function deleteFile($path$name)
  203.     {
  204.         if (is_a($this->_registry'PEAR_Error')) {
  205.             return $this->_registry;
  206.         }
  207.         return PEAR::raiseError(_("Not supported."));
  208.     }
  209.  
  210.     /**
  211.      * Renames a file in the VFS.
  212.      *
  213.      * @abstract
  214.      *
  215.      * @param string $oldpath  The old path to the file.
  216.      * @param string $oldname  The old filename.
  217.      * @param string $newpath  The new path of the file.
  218.      * @param string $newname  The new filename.
  219.      *
  220.      * @return mixed  True on success or a PEAR_Error object on failure.
  221.      */
  222.     function rename($oldpath$oldname$newpath$newname)
  223.     {
  224.         if (is_a($this->_registry'PEAR_Error')) {
  225.             return $this->_registry;
  226.         }
  227.         return PEAR::raiseError(_("Not supported."));
  228.     }
  229.  
  230.     /**
  231.      * Returns an an unsorted file list of the specified directory.
  232.      *
  233.      * @abstract
  234.      *
  235.      * @param string $path       The path of the directory.
  236.      * @param mixed $filter      String/hash to filter file/dirname on.
  237.      * @param boolean $dotfiles  Show dotfiles?
  238.      * @param boolean $dironly   Show only directories?
  239.      *
  240.      * @return array  File list on success or PEAR_Error on failure.
  241.      */
  242.     function _listFolder($path$filter = null$dotfiles = true,
  243.                          $dironly = false)
  244.     {
  245.         if (is_a($this->_registry'PEAR_Error')) {
  246.             return $this->_registry;
  247.         }
  248.         $list = array();
  249.         if ($path == '/'{
  250.             $apps $this->_registry->listApps(nullfalsePERMS_READ);
  251.             if (is_a($apps'PEAR_Error')) {
  252.                 return $apps;
  253.             }
  254.             foreach ($apps as $app{
  255.                 if ($this->_registry->hasMethod('browse'$app)) {
  256.                     $file = array(
  257.                         //'name' => $this->_registry->get('name', $app),
  258.                         'name' => $app,
  259.                         'date' => time(),
  260.                         'type' => '**dir',
  261.                         'size' => -1
  262.                     );
  263.                     $list[$file;
  264.                 }
  265.             }
  266.             return $list;
  267.         }
  268.  
  269.         if (substr($path01== '/'{
  270.             $path substr($path1);
  271.         }
  272.         $pieces explode('/'$path);
  273.         $items $this->_registry->callByPackage($pieces[0]'browse'array('path' => $path'properties' => array('name''browseable''contenttype''contentlength''modified')));
  274.         if (is_a($items'PEAR_Error')) {
  275.             return $items;
  276.         }
  277.         if (!is_array(reset($items))) {
  278.             /* We return an object's content. */
  279.             return PEAR::raiseError(_("unknown error"));
  280.         }
  281.  
  282.         include_once 'Horde/MIME/Magic.php';
  283.         foreach ($items as $sub_path => $i{
  284.             if ($dironly && !$i['browseable']{
  285.                 continue;
  286.             }
  287.  
  288.             $name basename($sub_path);
  289.             if ($this->_filterMatch($filter$name)) {
  290.                 continue;
  291.             }
  292.  
  293.             if (class_exists('MIME_Magic')) {
  294.                 $type = empty($i['contenttype']'application/octet-stream' $i['contenttype'];
  295.                 $type = MIME_Magic::MIMEToExt($type);
  296.             else {
  297.                 $type '**none';
  298.             }
  299.  
  300.             $file = array(
  301.                 //'name' => $i['name'],
  302.                 'name' => $name,
  303.                 'date' => empty($i['modified']? 0 : $i['modified'],
  304.                 'type' => $i['browseable''**dir' $type,
  305.                 'size' => empty($i['contentlength']? 0 : $i['contentlength']
  306.             );
  307.             $list[$file;
  308.         }
  309.  
  310.         return $list;
  311.     }
  312.  
  313.     /**
  314.      * Returns a sorted list of folders in the specified directory.
  315.      *
  316.      * @abstract
  317.      *
  318.      * @param string $path         The path of the directory to get the
  319.      *                              directory list for.
  320.      * @param mixed $filter        Hash of items to filter based on folderlist.
  321.      * @param boolean $dotfolders  Include dotfolders?
  322.      *
  323.      * @return mixed  Folder list on success or a PEAR_Error object on failure.
  324.      */
  325.     function listFolders($path ''$filter = null$dotfolders = true)
  326.     {
  327.         if (is_a($this->_registry'PEAR_Error')) {
  328.             return $this->_registry;
  329.         }
  330.         return PEAR::raiseError(_("Not supported."));
  331.     }
  332.  
  333. }

Documentation generated on Mon, 11 Mar 2019 15:34:54 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.