Source for file helper.php

Documentation is available at helper.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  FileSystem
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * File system helper
  14.  *
  15.  * Holds support functions for the filesystem, particularly the stream
  16.  *
  17.  * @package     Joomla.Platform
  18.  * @subpackage  FileSystem
  19.  * @since       11.1
  20.  */
  21. {
  22.     /**
  23.      * Remote file size function for streams that don't support it
  24.      *
  25.      * @param   string  $url  TODO Add text
  26.      *
  27.      * @return  mixed 
  28.      *
  29.      * @see     http://www.php.net/manual/en/function.filesize.php#71098
  30.      * @since   11.1
  31.      */
  32.     public static function remotefsize($url)
  33.     {
  34.         $sch parse_url($urlPHP_URL_SCHEME);
  35.  
  36.         if (($sch != 'http'&& ($sch != 'https'&& ($sch != 'ftp'&& ($sch != 'ftps'))
  37.         {
  38.             return false;
  39.         }
  40.  
  41.         if (($sch == 'http'|| ($sch == 'https'))
  42.         {
  43.             $headers get_headers($url1);
  44.  
  45.             if ((!array_key_exists('Content-Length'$headers)))
  46.             {
  47.                 return false;
  48.             }
  49.  
  50.             return $headers['Content-Length'];
  51.         }
  52.  
  53.         if (($sch == 'ftp'|| ($sch == 'ftps'))
  54.         {
  55.             $server parse_url($urlPHP_URL_HOST);
  56.             $port parse_url($urlPHP_URL_PORT);
  57.             $path parse_url($urlPHP_URL_PATH);
  58.             $user parse_url($urlPHP_URL_USER);
  59.             $pass parse_url($urlPHP_URL_PASS);
  60.  
  61.             if ((!$server|| (!$path))
  62.             {
  63.                 return false;
  64.             }
  65.  
  66.             if (!$port)
  67.             {
  68.                 $port 21;
  69.             }
  70.  
  71.             if (!$user)
  72.             {
  73.                 $user 'anonymous';
  74.             }
  75.  
  76.             if (!$pass)
  77.             {
  78.                 $pass '';
  79.             }
  80.  
  81.             switch ($sch)
  82.             {
  83.                 case 'ftp':
  84.                     $ftpid ftp_connect($server$port);
  85.                     break;
  86.  
  87.                 case 'ftps':
  88.                     $ftpid ftp_ssl_connect($server$port);
  89.                     break;
  90.             }
  91.  
  92.             if (!$ftpid)
  93.             {
  94.                 return false;
  95.             }
  96.  
  97.             $login ftp_login($ftpid$user$pass);
  98.  
  99.             if (!$login)
  100.             {
  101.                 return false;
  102.             }
  103.  
  104.             $ftpsize ftp_size($ftpid$path);
  105.             ftp_close($ftpid);
  106.  
  107.             if ($ftpsize == -1)
  108.             {
  109.                 return false;
  110.             }
  111.  
  112.             return $ftpsize;
  113.         }
  114.     }
  115.  
  116.     /**
  117.      * Quick FTP chmod
  118.      *
  119.      * @param   string   $url   Link identifier
  120.      * @param   integer  $mode  The new permissions, given as an octal value.
  121.      *
  122.      * @return  mixed 
  123.      *
  124.      * @see     http://www.php.net/manual/en/function.ftp-chmod.php
  125.      * @since   11.1
  126.      */
  127.     public static function ftpChmod($url$mode)
  128.     {
  129.         $sch parse_url($urlPHP_URL_SCHEME);
  130.  
  131.         if (($sch != 'ftp'&& ($sch != 'ftps'))
  132.         {
  133.             return false;
  134.         }
  135.  
  136.         $server parse_url($urlPHP_URL_HOST);
  137.         $port parse_url($urlPHP_URL_PORT);
  138.         $path parse_url($urlPHP_URL_PATH);
  139.         $user parse_url($urlPHP_URL_USER);
  140.         $pass parse_url($urlPHP_URL_PASS);
  141.  
  142.         if ((!$server|| (!$path))
  143.         {
  144.             return false;
  145.         }
  146.  
  147.         if (!$port)
  148.         {
  149.             $port 21;
  150.         }
  151.  
  152.         if (!$user)
  153.         {
  154.             $user 'anonymous';
  155.         }
  156.  
  157.         if (!$pass)
  158.         {
  159.             $pass '';
  160.         }
  161.  
  162.         switch ($sch)
  163.         {
  164.             case 'ftp':
  165.                 $ftpid ftp_connect($server$port);
  166.                 break;
  167.  
  168.             case 'ftps':
  169.                 $ftpid ftp_ssl_connect($server$port);
  170.                 break;
  171.         }
  172.  
  173.         if (!$ftpid)
  174.         {
  175.             return false;
  176.         }
  177.  
  178.         $login ftp_login($ftpid$user$pass);
  179.  
  180.         if (!$login)
  181.         {
  182.             return false;
  183.         }
  184.  
  185.         $res ftp_chmod($ftpid$mode$path);
  186.         ftp_close($ftpid);
  187.  
  188.         return $res;
  189.     }
  190.  
  191.     /**
  192.      * Modes that require a write operation
  193.      *
  194.      * @return  array 
  195.      *
  196.      * @since   11.1
  197.      */
  198.     public static function getWriteModes()
  199.     {
  200.         return array('w''w+''a''a+''r+''x''x+');
  201.     }
  202.  
  203.     /**
  204.      * Stream and Filter Support Operations
  205.      *
  206.      * Returns the supported streams, in addition to direct file access
  207.      * Also includes Joomla! streams as well as PHP streams
  208.      *
  209.      * @return  array  Streams
  210.      *
  211.      * @since   11.1
  212.      */
  213.     public static function getSupported()
  214.     {
  215.         // Really quite cool what php can do with arrays when you let it...
  216.         static $streams;
  217.  
  218.         if (!$streams)
  219.         {
  220.             $streams array_merge(stream_get_wrappers()self::getJStreams());
  221.         }
  222.  
  223.         return $streams;
  224.     }
  225.  
  226.     /**
  227.      * Returns a list of transports
  228.      *
  229.      * @return  array 
  230.      *
  231.      * @since   11.1
  232.      */
  233.     public static function getTransports()
  234.     {
  235.         // Is this overkill?
  236.         return stream_get_transports();
  237.     }
  238.  
  239.     /**
  240.      * Returns a list of filters
  241.      *
  242.      * @return  array 
  243.      *
  244.      * @since   11.1
  245.      */
  246.     public static function getFilters()
  247.     {
  248.         // Note: This will look like the getSupported() function with J! filters.
  249.         // TODO: add user space filter loading like user space stream loading
  250.         return stream_get_filters();
  251.     }
  252.  
  253.     /**
  254.      * Returns a list of J! streams
  255.      *
  256.      * @return  array 
  257.      *
  258.      * @since   11.1
  259.      */
  260.     public static function getJStreams()
  261.     {
  262.         static $streams array();
  263.  
  264.         if (!$streams)
  265.         {
  266.             $files new DirectoryIterator(__DIR__ . '/streams');
  267.  
  268.             foreach ($files as $file)
  269.             {
  270.                 $filename $file->getFilename();
  271.  
  272.                 // Only load for php files.
  273.                 // Note: DirectoryIterator::getExtension only available PHP >= 5.3.6
  274.                 if (!$file->isFile(|| substr($filenamestrrpos($filename'.'1!= 'php')
  275.                 {
  276.                     continue;
  277.                 }
  278.  
  279.                 $streams[$file->getBasename('.php');
  280.             }
  281.         }
  282.  
  283.         return $streams;
  284.     }
  285.  
  286.     /**
  287.      * Determine if a stream is a Joomla stream.
  288.      *
  289.      * @param   string  $streamname  The name of a stream
  290.      *
  291.      * @return  boolean  True for a Joomla Stream
  292.      *
  293.      * @since   11.1
  294.      */
  295.     public static function isJoomlaStream($streamname)
  296.     {
  297.         return in_array($streamnameself::getJStreams());
  298.     }
  299. }

Documentation generated on Tue, 19 Nov 2013 15:04:30 +0100 by phpDocumentor 1.4.3