protected function smazatAdresar($adresar) { if (file_exists($adresar)) { foreach (NFinder::findFiles('*.*')->in($adresar) as $soubor) { unlink($adresar . '/' . $soubor->getFileName()); } rmdir($adresar); } }
private function scanDirectory($dir) { if (is_dir($dir)) { $disallow = array(); $iterator = NFinder::findFiles(NString::split($this->acceptFiles, '#[,\\s]+#'))->filter(create_function('$file', 'extract(NClosureFix::$vars[' . NClosureFix::uses(array('disallow' => &$disallow)) . '], EXTR_REFS); return !isset($disallow[$file->getPathname()]); '))->from($dir)->exclude(NString::split($this->ignoreDirs, '#[,\\s]+#'))->filter($filter = create_function('$dir', 'extract(NClosureFix::$vars[' . NClosureFix::uses(array('disallow' => &$disallow)) . '], EXTR_REFS); $path = $dir->getPathname(); if (is_file("$path/netterobots.txt")) { foreach (file("$path/netterobots.txt") as $s) { if ($matches = NString::match($s, \'#^disallow\\\\s*:\\\\s*(\\\\S+)#i\')) { $disallow[$path . str_replace(\'/\', DIRECTORY_SEPARATOR, rtrim(\'/\' . ltrim($matches[1], \'/\'), \'/\'))] = TRUE; } } } return !isset($disallow[$path]); ')); $filter(new SplFileInfo($dir)); } else { $iterator = new ArrayIterator(array(new SplFileInfo($dir))); } foreach ($iterator as $entry) { $path = $entry->getPathname(); if (!isset($this->files[$path]) || $this->files[$path] !== $entry->getMTime()) { $this->scanScript($path); } } }
/** * Seznam obrázků určených k zobrazení na hlavní stránce * @param type $id_clanku * @return FALSE/array */ public function obrTopClanek($id_clanku) { $adresare = $this->najit_adresare($id_clanku); $tt_adresar = $adresare['tt_adresar']; if ($this->je_adresar_prazdny($tt_adresar)) { return array($this->neurceny_tt_nahled => 'neurčeno'); } foreach ($this->obrazky as $pripona => $typ) { $masky[] = "*.{$pripona}"; } foreach (NFinder::findFiles($masky)->in($tt_adresar) as $key => $file) { $nahledy[$key] = $file; } return $nahledy; }
/** * Vyhledá všechny neobrázkové přílohy k článku a přidá k nim adresu náhledu (ikona nastavená v Prilohy::nahledy) * @param type $id_clanku * @return array, ve tvaru [adresa]=> array klíče:nazev, typ, nahled, je_obrazek */ public function seznamOstatnichPriloh($id_clanku) { $adresare = $this->najit_adresare($id_clanku); $prilohy = array(); $prilohy_tmp = array(); foreach ($this->obrazky as $pripona => $typ) { $masky[] = "*.{$pripona}"; } if (is_dir($adresare['target_adresar'])) { $nazvy = array(); foreach (NFinder::findFiles('*.*')->exclude($masky)->in($adresare['target_adresar']) as $key => $file) { $cesta = $file->getPath(); $nazev = rawurlencode($file->getBasename()); $key = $cesta . '/' . $nazev; $nazvy[$file->getFileName()] = $key; //použije se pro řazení podle názvu $prilohy_tmp[$key]['nazev'] = $file->getFileName(); $path = pathinfo($file->getFileName()); $pripona = strtolower($path['extension']); $pripona = NStrings::lower($pripona); $prilohy_tmp[$key]['typ'] = $pripona; $prilohy_tmp[$key]['je_obrazek'] = FALSE; if (array_key_exists($pripona, $this->nahledy)) { $nahled = $this->nahledy[$pripona]; if (!$this->overitNahled($nahled)) { $nahled = $this->neurceny_nahled_bez_obr; } } else { $nahled = $this->neurceny_nahled_bez_obr; } $prilohy_tmp[$key]['nahled'] = $nahled; } ksort($nazvy); dd($nazvy, 'nazvy'); foreach ($nazvy as $nazev => $cesta) { $prilohy[$cesta] = $prilohy_tmp[$cesta]; } } return $prilohy; }
/** * Creates an iterator scaning directory for PHP files, subdirectories and 'netterobots.txt' files. * @return Iterator */ private function createFileIterator($dir) { if (!is_dir($dir)) { return new ArrayIterator(array(new SplFileInfo($dir))); } $ignoreDirs = is_array($this->ignoreDirs) ? $this->ignoreDirs : preg_split('#[,\s]+#', $this->ignoreDirs); $disallow = array(); foreach ($ignoreDirs as $item) { if ($item = realpath($item)) { $disallow[$item] = TRUE; } } $iterator = NFinder::findFiles(is_array($this->acceptFiles) ? $this->acceptFiles : preg_split('#[,\s]+#', $this->acceptFiles)) ->filter(create_function('$file', 'extract($GLOBALS[0]['.array_push($GLOBALS[0], array('disallow'=>& $disallow)).'-1], EXTR_REFS); return !isset($disallow[$file->getPathname()]); ')) ->from($dir) ->exclude($ignoreDirs) ->filter($filter = create_function('$dir', 'extract($GLOBALS[0]['.array_push($GLOBALS[0], array('disallow'=>& $disallow)).'-1], EXTR_REFS); $path = $dir->getPathname(); if (is_file("$path/netterobots.txt")) { foreach (file("$path/netterobots.txt") as $s) { if (preg_match(\'#^(?:disallow\\\\s*:)?\\\\s*(\\\\S+)#i\', $s, $matches)) { $disallow[$path . str_replace(\'/\', DIRECTORY_SEPARATOR, rtrim(\'/\' . ltrim($matches[1], \'/\'), \'/\'))] = TRUE; } } } return !isset($disallow[$path]); ')); $filter(new SplFileInfo($dir)); return $iterator; }