Ejemplo n.º 1
0
 /**
  * Main constructor
  *
  * @param array  $conf         Viewer configuration
  * @param string $path         Series path
  * @param string $app_base_url Application base URL
  * @param string $start        Sub series start point (optional)
  * @param string $end          Sub series end point (optional)
  */
 public function __construct($conf, $path, $app_base_url, $start = null, $end = null)
 {
     $this->_path = $path;
     $this->_conf = $conf;
     $this->_start = $start;
     $this->_end = $end;
     $roots = $conf->getRoots();
     foreach ($roots as $root) {
         if (file_exists($root . $path) && is_dir($root . $path)) {
             $this->_full_path = $root . $path;
             Analog::log(str_replace('%path', $this->_full_path, _('Series path set to "%path"')));
             break;
         }
     }
     if ($this->_full_path === null) {
         throw new \RuntimeException(_('No matching root found!'));
     } else {
         $this->_content = array();
         $handle = opendir($this->_full_path);
         $all_entries = array();
         $finfo = new \finfo(FILEINFO_MIME_TYPE);
         $go = $this->_start === null ? true : false;
         if ($go === true) {
             while (false !== ($entry = readdir($handle))) {
                 if ($entry != "." && $entry != ".." && !is_dir($this->_full_path . '/' . $entry)) {
                     $mimetype = $finfo->file($this->_full_path . '/' . $entry);
                     if ($mimetype != '' && strpos($mimetype, 'image') === 0) {
                         $all_entries[] = $entry;
                     }
                 }
             }
             closedir($handle);
             sort($all_entries, SORT_STRING);
         } else {
             $listFiles = scandir($this->_full_path);
             sort($listFiles, SORT_STRING);
             $begin = array_search($this->_start, $listFiles);
             $end = array_search($this->_end, $listFiles);
             $diff = $end + 1 - $begin;
             $arrayDif = array_slice($listFiles, $begin, $diff);
             foreach ($arrayDif as $entry) {
                 $mimetype = $finfo->file($this->_full_path . '/' . $entry);
                 if ($mimetype != '' && strpos($mimetype, 'image') === 0) {
                     $all_entries[] = $entry;
                 }
             }
         }
         foreach ($all_entries as $entry) {
             //check for subseries start
             if (!$go && substr($entry, -strlen($this->_start)) === $this->_start) {
                 $go = true;
             }
             if ($go) {
                 try {
                     $picture = new Picture($this->_conf, $entry, $app_base_url, $this->_full_path);
                     $this->_content[] = $entry;
                 } catch (\RuntimeException $re) {
                     Analog::warning('Image type for ' . $entry . ' is not supported!');
                 }
                 if ($this->_end !== false && substr($entry, -strlen($this->_end)) === $this->_end) {
                     $go = false;
                 }
             } else {
                 Analog::info(str_replace('%img', $entry, 'Image %img is out of subseries.'));
             }
         }
     }
 }