Example #1
0
 /**
  * Returns a listing of contained directories and files, as well as their
  * exclusion status
  * @param string $root The root directory
  * @param string $node The subdirectory to scan
  * @return array
  */
 private function &get_listing($root, $node)
 {
     // Initialize the absolute directory root
     $directory = substr($root, 0);
     // Replace stock directory tags, like [SITEROOT]
     $stock_dirs = AEPlatform::getInstance()->get_stock_directories();
     if (!empty($stock_dirs)) {
         foreach ($stock_dirs as $key => $replacement) {
             $directory = str_replace($key, $replacement, $directory);
         }
     }
     $directory = AEUtilFilesystem::TranslateWinPath($directory);
     // Clean and add the node
     $node = AEUtilFilesystem::TranslateWinPath($node);
     if ($node == '/') {
         $node = '';
     }
     // Just a dir. sep. is treated as no dir at all
     // Trim leading and trailing slashes
     $node = trim($node, '/');
     // Add node to directory
     if (!empty($node)) {
         $directory .= '/' . $node;
     }
     // Add any required trailing slash to the node to be used below
     if (!empty($node)) {
         $node .= '/';
     }
     // Get a filters instance
     $filters = AEFactory::getFilters();
     // Detect PHP 5.2.5or earlier, with broken json_decode implementation
     $phpversion = PHP_VERSION;
     $vparts = explode('.', $phpversion);
     if ($vparts[0] == 5 && $vparts[1] == 2 && $vparts[2] <= 5 || $vparts[0] == 5 && $vparts[1] == 1) {
         define('AKEEBA_SAFE_JSON', false);
         require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/jsonlib.php';
     } else {
         $test = '-test-';
         $tj = json_encode($test);
         $test = json_decode($test);
         if ($test == '-test-') {
             define('AKEEBA_SAFE_JSON', true);
         } else {
             define('AKEEBA_SAFE_JSON', false);
             require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/jsonlib.php';
         }
     }
     // Get a listing of folders and process it
     $folders = AEUtilScanner::getFolders($directory);
     asort($folders);
     $folders_out = array();
     if (!empty($folders)) {
         foreach ($folders as $folder) {
             $folder = AEUtilFilesystem::TranslateWinPath($folder);
             // Filter out files whose names result to an empty JSON representation
             if (AKEEBA_SAFE_JSON) {
                 $json_folder = json_encode($folder);
                 $folder = json_decode($json_folder);
             } else {
                 $jsonobj = new Akeeba_Services_JSON(0);
                 $json_folder = $jsonobj->encode($folder);
                 $folder = $jsonobj->decode($json_folder);
             }
             if (empty($folder)) {
                 continue;
             }
             $test = $node . $folder;
             $status = array();
             // Check dir/all filter (exclude)
             $result = $filters->isFilteredExtended($test, $root, 'dir', 'all', $byFilter);
             $status['directories'] = !$result ? 0 : ($byFilter == 'directories' ? 1 : 2);
             // Check dir/content filter (skip_files)
             $result = $filters->isFilteredExtended($test, $root, 'dir', 'content', $byFilter);
             $status['skipfiles'] = !$result ? 0 : ($byFilter == 'skipfiles' ? 1 : 2);
             // Check dir/children filter (skip_dirs)
             $result = $filters->isFilteredExtended($test, $root, 'dir', 'children', $byFilter);
             $status['skipdirs'] = !$result ? 0 : ($byFilter == 'skipdirs' ? 1 : 2);
             // Add to output array
             $folders_out[$folder] = $status;
         }
     }
     unset($folders);
     $folders = $folders_out;
     // Get a listing of files and process it
     $files = AEUtilScanner::getFiles($directory);
     asort($files);
     $files_out = array();
     if (!empty($files)) {
         foreach ($files as $file) {
             // Filter out files whose names result to an empty JSON representation
             if (AKEEBA_SAFE_JSON) {
                 $json_file = json_encode($file);
                 $file = json_decode($json_file);
             } else {
                 $jsonobj = new Akeeba_Services_JSON(0);
                 $json_file = $jsonobj->encode($file);
                 $file = $jsonobj->decode($json_file);
             }
             if (empty($file)) {
                 continue;
             }
             $test = $node . $file;
             $status = array();
             // Check file/all filter (exclude)
             $result = $filters->isFilteredExtended($test, $root, 'file', 'all', $byFilter);
             $status['files'] = !$result ? 0 : ($byFilter == 'files' ? 1 : 2);
             $status['size'] = @filesize($directory . '/' . $file);
             // Add to output array
             $files_out[$file] = $status;
         }
     }
     unset($files);
     $files = $files_out;
     // Return a compiled array
     $retarray = array('folders' => $folders, 'files' => $files);
     return $retarray;
     /* Return array format
      * [array] :
      * 		'folders' [array] :
      * 			(folder_name) => [array]:
      *				'directories'	=> 0|1|2
      *				'skipfiles'		=> 0|1|2
      *				'skipdirs'		=> 0|1|2
      *		'files' [array] :
      *			(file_name) => [array]:
      *				'files'			=> 0|1|2
      *
      * Legend:
      * 0 -> Not excluded
      * 1 -> Excluded by the direct filter
      * 2 -> Excluded by another filter (regex, api, an unknown plugin filter...)
      */
 }
Example #2
0
 /**
  * array-walking function for use in generating JSON-formatted name-value pairs
  *
  * @param    string  $name   name of key to use
  * @param    mixed   $value  reference to an array element to be encoded
  *
  * @return   string  JSON-formatted name-value pair, like '"name":value'
  * @access   private
  */
 function name_value($name, $value)
 {
     $encoded_value = $this->encode($value);
     if (Akeeba_Services_JSON::isError($encoded_value)) {
         return $encoded_value;
     }
     return $this->encode(strval($name)) . ':' . $encoded_value;
 }
Example #3
0
 /**
  * Decodes a JSON string to a variable using PEAR's Services_JSON
  *
  * @param string $value The JSON-encoded string
  * @param bool   $assoc True to return an associative array instead of an object
  *
  * @return mixed The decoded variable
  */
 private function json_decode($value, $assoc = false)
 {
     $flags = 0;
     if ($assoc) {
         $flags = SERVICES_JSON_LOOSE_TYPE;
     }
     $decoder = new Akeeba_Services_JSON($flags);
     return $decoder->decode($value);
 }