Ejemplo n.º 1
0
 /**
  * Get a list of files.
  *
  * @access public
  * @param int $num : The number of files to list. 0 means all the files.
  * @param bool $new_list : If the user want to get two lists from the same instance, he can ask to use the list previously generated instead of generating a new list.
  * @return bool|array : List of files. False on error.
  * @author Aziz Light
  */
 public function get_files($num = 0, $options = array())
 {
     $order = array_key_exists('order', $options) ? $options['order'] : 'lastmodified';
     $new_list = array_key_exists('new_list', $options) ? $options['new_list'] : true;
     $recursive_size = array_key_exists('recursive_size', $options) ? $options['recursive_size'] : false;
     // What the f**k does return false mean?
     // FIXME: throw an exception, or log an error message or something...
     if (!is_int($num) || !is_bool($new_list)) {
         return false;
     }
     if ($new_list === false && isset($this->files) && count($this->files >= $num)) {
         return array_slice($this->files, 0, $num);
     }
     if ($handle = opendir($this->folder)) {
         while (($file = readdir($handle)) !== false) {
             if (!in_array($file, self::$excluded_files)) {
                 // Get the modification time of folders recursively
                 if (is_dir($this->folder . $file) && !DashboardHelpers::is_empty_dir($this->folder . $file)) {
                     $modification_date = DashboardHelpers::get_highest_file_timestamp($this->folder . $file);
                     $modification_date = DashboardHelpers::timespan($modification_date);
                     if ($recursive_size) {
                         $size = DashboardHelpers::recursive_directory_size($this->folder . $file);
                         $size = DashboardHelpers::format_file_size($size);
                     } else {
                         $size = DashboardHelpers::format_file_size(filesize($this->folder . $file));
                     }
                 } else {
                     $modification_date = DashboardHelpers::timespan(filemtime($this->folder . $file));
                     $size = DashboardHelpers::format_file_size(filesize($this->folder . $file));
                 }
                 $this->files[$file] = array('filename' => $file, 'path' => $this->folder . $file, 'folderpath' => $this->folder, 'url' => $this->url . $file, 'folderurl' => $this->url, 'modification_date' => $modification_date, 'size' => $size);
             }
         }
         closedir($handle);
     }
     if (!$this->order_files($order)) {
         // TODO: Do something to notify the user that the sort operation failed.
     }
     return array_slice($this->files, 0, $num);
 }