public function loadMigrations() { $result = array('mgrs' => array(), 'headers' => array(array('id' => 'id', 'content' => Loc::getMessage('MIGRATION_ID'), 'sort' => 'id', 'align' => 'left', 'default' => true), array('id' => 'status', 'content' => Loc::getMessage('MIGRATION_STATUS'), 'align' => 'right', 'default' => true), array('id' => 'date_c', 'content' => Loc::getMessage('MIGRATION_DATE_CHANGED'), 'align' => 'right', 'default' => true), array('id' => 'date_a', 'content' => Loc::getMessage('MIGRATION_DATE_ADDED'), 'align' => 'right', 'default' => true))); $db_mgrs = $this->loadDBMigrations(); $mgr_path = Option::get(UM_BM_MODULE_NAME, 'migration_folder', UM_BM_MGR_PATH); $di = new \DirectoryIterator($_SERVER['DOCUMENT_ROOT'] . $mgr_path); while ($di->valid()) { if (!$di->isDot() && $this->hasProperFilename($di->getFilename())) { $filename = $di->getFilename(); if (!array_key_exists($filename, $db_mgrs)) { $mgr = new BixMigBase(); $mgr->setCode($filename)->setStatus('UNKNOWN')->setAddDate(date('d.m.Y H:i:s'))->setChangeDate()->add(); $result['mgrs'][] = $mgr; } else { $result['mgrs'][] = $db_mgrs[$filename]; unset($db_mgrs[$filename]); } } $di->next(); } if (!empty($db_mgrs)) { $this->deleteOrphans($db_mgrs); } return $result; }
public function logAction() { $pageSize = 4096; $overlapSize = 128; $dir = APPLICATION_PATH . '/../data/logs/'; $file = $this->_getParam('file', null); $this->view->page = $this->_getParam('page', 0); if ($file === null) { $file = sprintf('%s_application.log', Zend_Date::now()->toString('yyyy.MM.dd')); } $fp = fopen($dir . $file, 'r'); fseek($fp, -$pageSize * ($this->view->page + 1) + $overlapSize, SEEK_END); $this->view->errorLog = fread($fp, $pageSize + $overlapSize * 2); fclose($fp); $iterator = new DirectoryIterator($dir); while ($iterator->valid()) { if (!$iterator->isDot()) { if ($iterator->isFile()) { $files[$iterator->getFilename()] = $iterator->getPathName(); } } $iterator->next(); } $this->view->itemCountPerPage = $pageSize; $this->view->totalItemCount = filesize($dir . $file); $this->view->files = $files; }
/** * Obtem um array de ImgObject com todos os arquivos de imagens dos * diretórios especificados * * @param int|null $limit * @return array */ public function getImgArray($limit = null) { $imgArray = array(); foreach ($this->getDir() as $diretorio) { $imgArray = array(); $d = new DirectoryIterator($diretorio); while ($d->valid()) { if (!$d->isDot()) { $fileName = $d->getFilename(); if ($this->validateFormat($fileName)) { $imgObj = new ImgObject($fileName, $diretorio); $imgArray[] = $imgObj; ++$this->imgCount; if ($limit != null) { if ($this->imgCount >= $limit) { break; } } } } $d->next(); } } return $imgArray; }
/** * Método recursivo que busca o arquivo em todas as pastadas dentro do * diretorio específicado * * @param string $dir * @param string $file * @return boolean */ public static function searchInDir($dir, $file) { if (is_file($dir . "/" . $file)) { require_once $dir . "/" . $file; self::$find = true; if (self::$sugests) { $fileName = $dir . "/" . $file; $fileName = str_replace(self::$currentPath, "", $fileName); echo "require_once '" . $fileName . "';<br>\n"; } return true; } if (is_dir($dir)) { $d = new DirectoryIterator($dir); while (!self::$find && $d->valid()) { if (is_dir($d->getPath() . '/' . $d->getFilename())) { //testa se o arquivo pode ser incluido $inc = true; foreach (self::$blockedDirs as $bDir) { if ($d->getFilename() == $bDir) { $inc = false; break; } } if (!$d->isDot() && $inc) { self::searchInDir($d->getPath() . '/' . $d->getFilename(), $file); } } $d->next(); } } return self::$find; }
/** * Collect schema from wordpress active theme * * @return boolean true on success false if color schema folder is not exists * in the active theme folder */ public function collectSchema() { $options = $this->getOptions(); $path = get_template_directory() . $options['path']; // make sure that the color schema folder exsists if (!file_exists($path) || !is_dir($path)) { return; // just ignore } // register the new color schema $contents = new \DirectoryIterator($path); foreach ($contents as $content) { if ($contents->isDot()) { continue; } if ($contents->isDir()) { $name = $content->getFilename(); $init = parse_ini_file($content->getPathname() . '/schema.ini'); if (!is_array($init)) { trigger_error('Unbale Admin Color Schema Config File', E_USER_ERROR); } $suffix = is_rtl() ? '-rtl' : ''; $url = get_template_directory_uri() . $options['path'] . '/' . $name . "/colors{$suffix}.css"; wp_admin_css_color($name, __(isset($init['name']) && !empty($init['name']) ? $init['name'] : $name, isset($init['domain']) && !empty($init['domain']) ? $init['domain'] : 'default'), $url, isset($init['colors']) && is_array($init['colors']) ? $init['colors'] : array(), isset($init['icons']) && is_array($init['icons']) ? $init['icons'] : array()); } } }
function exportpluginAction() { $aExtDir = array('ALYS.Report.Dictionary', 'ALYS.Report.Plugin'); // var_dump(LIB_PATH_ALYS); // var_dump(EXT_PATH_ALYS); $LIB_PATH_ALYS = "D:\\htdocs\\work\\apps\\code\\l_project_web\\module\\ycheukf\\Report\\src\\Report\\Lib"; $EXT_PATH_ALYS = "D:\\htdocs\\work\\apps\\code\\l_project_web\\module\\Application\\src\\Application\\YcheukfReportExt"; foreach ($aExtDir as $sTmp) { $path = str_replace(".", '/', $sTmp); $sDirPath = $LIB_PATH_ALYS . '/' . $path; $sExtDirPath = $EXT_PATH_ALYS . '/' . str_replace("ALYS/", "", (string) $path); //扩展目录, 若需要改路径请改此处 // var_export($sDirPath); $it = new \DirectoryIterator($sDirPath); foreach ($it as $file) { if (!$it->isDot() && $file != '.svn' && $file != '.git') { $this->recursiveMkdir($sExtDirPath, '0700'); copy($sDirPath . '/' . $file, $sExtDirPath . '/' . $file); $sContent = file_get_contents($sExtDirPath . '/' . $file); // $sContent = preg_replace("/require_once\(\"".str_replace(".", '\/', $sTmp).".php\"\);/s", ' ', $sContent); $sClassName = str_replace(".php", "", (string) $file); preg_match_all('/namespace (.*);/', $sContent, $aMatch); // var_dump((string)$file); // var_dump($aMatch[1][0]); $sContent = str_replace("namespace YcheukfReport\\Lib\\ALYS", 'namespace YcheukfReportExt', $sContent); $sContent = preg_replace("/class ([^\\s]+?) extends ([^}]+?)\\{/s", 'class \\1 extends \\2\\' . $sClassName . '{', $sContent); // echo $sContent; file_put_contents($sExtDirPath . '/' . $file, $sContent); } } } echo "\n\n export file to ext ... DONE\n\n"; exit; }
public function index($args) { $t = Registry::getInstance()->twig->loadTemplate('form/filepicker.tpl'); $c = array(); $localpath = Functions::nz($args['path'], ''); $mediapath = SITE_PATH . '/media/'; $dir = new \DirectoryIterator($mediapath . $localpath); $picformats = array('png', 'jpg', 'gif'); $files = array(); foreach ($dir as $file) { if (!$dir->isDot()) { $path = URL_PATH . '/media/' . $localpath . $file; $f = new \stdClass(); if (strlen($file) > 4 && in_array(substr($file, -3), $picformats)) { $picture = $path; } elseif ($dir->isDir()) { $picture = TEMPLATE_PATH . 'form/pics/folder.png'; } else { $picture = TEMPLATE_PATH . 'form/pics/file.png'; } $f->path = $localpath; $f->picture = $picture; $f->name = (string) $file; $f->type = $dir->isDir() ? 'dir' : 'file'; $files[] = $f; } } $c['files'] = $files; $t->display($c); }
/** * Fills the list of available files, with DirectoryIterator object as value */ protected function scanFileObjects() { // value is cached if (!empty($this->fileObjects)) { return; } if ($this->recursive) { $it = new \RecursiveIteratorIterator($this->obj, \RecursiveIteratorIterator::CHILD_FIRST); foreach ($it as $filename => $obj) { // ignore . and .. if ($it->isDot()) { continue; } $this->fileObjects[FileUtil::unifyDirSeperator($filename)] = $obj; } } else { foreach ($this->obj as $obj) { // ignore . and .. if ($this->obj->isDot()) { continue; } $this->fileObjects[FileUtil::unifyDirSeperator($obj->getFilename())] = $obj; } } // add the directory itself $this->fileObjects[$this->directory] = new \SPLFileInfo($this->directory); }
protected function scanFolder($folder, &$position, $forFolders = true, $threshold_key = 'dir', $threshold_default = 50) { $registry = AEFactory::getConfiguration(); // Initialize variables $arr = array(); $false = false; if (!is_dir($folder) && !is_dir($folder . '/')) { return $false; } try { $di = new DirectoryIterator($folder); } catch (Exception $e) { $this->setWarning('Unreadable directory ' . $folder); return $false; } if (!$di->valid()) { $this->setWarning('Unreadable directory ' . $folder); return $false; } if (!empty($position)) { $di->seek($position); if ($di->key() != $position) { $position = null; return $arr; } } $counter = 0; $maxCounter = $registry->get("engine.scan.large.{$threshold_key}_threshold", $threshold_default); while ($di->valid()) { if ($di->isDot()) { $di->next(); continue; } if ($di->isDir() != $forFolders) { $di->next(); continue; } $ds = $folder == '' || $folder == '/' || @substr($folder, -1) == '/' || @substr($folder, -1) == DIRECTORY_SEPARATOR ? '' : DIRECTORY_SEPARATOR; $dir = $folder . $ds . $di->getFilename(); $data = _AKEEBA_IS_WINDOWS ? AEUtilFilesystem::TranslateWinPath($dir) : $dir; if ($data) { $counter++; $arr[] = $data; } if ($counter == $maxCounter) { break; } else { $di->next(); } } // Determine the new value for the position $di->next(); if ($di->valid()) { $position = $di->key() - 1; } else { $position = null; } return $arr; }
/** * Move forward to the next cache entry * * @return void * @api */ public function next() { if ($this->cacheFilesIterator === null) { $this->rewind(); } $this->cacheFilesIterator->next(); while ($this->cacheFilesIterator->isDot() && $this->cacheFilesIterator->valid()) { $this->cacheFilesIterator->next(); } }
public function valid() { if (parent::valid()) { if ($this->dirsOnly && !parent::isDir() || parent::isDot() || parent::getFileName() == '.svn') { parent::next(); return $this->valid(); } return true; } return false; }
/** * * @param string $Floder * @param string $app */ public static function IncFloder($Floder, $app = '') { $app_name = $app == '' ? APP_NAME : $app; $Floderpath = 'Lang' . DS . $app_name . DS . \getlang() . DS . $Floder; $it = new \DirectoryIterator($Floderpath); foreach ($it as $file) { if (!$it->isDot()) { $langfile = $Floderpath . DS . $file; self::IncFile($langfile); } } }
function getTestDirs($dir = './') { $file = new DirectoryIterator($dir); $res = array(); while ($file->valid()) { if ($file->isDir() && !$file->isDot()) { $res[] = $file->getPathName(); } $file->next(); } return $res; }
public function pushItem(&$listing, DirectoryIterator $item) { // dot would be for morse code locale? if (!$item->isDot() && $item->isFile()) { // explode and extract name & type list($name, $type) = explode('.', $item->getFilename()); assert('!empty($name) && !empty($type); // invalid locale files'); // push name to stack if ($type == 'yml') { array_push($listing, $name); } } }
/** * @desc Iterates the components directory and returns list of it subdirectories * * @return array */ public static function loadComponentsFromFileSystem() { $componentsNames = []; $directory = new DirectoryIterator(\Wikia\UI\Factory::getComponentsDir()); while ($directory->valid()) { if (!$directory->isDot() && $directory->isDir()) { $componentName = $directory->getFilename(); $componentsNames[] = $componentName; } $directory->next(); } return $componentsNames; }
function indexAction() { setcookie("previewTemplateName", false, 0, "/"); $templates = array(); $dir = new DirectoryIterator(Config::get('TEMPLATES_PATH')); while ($dir->valid()) { if (!$dir->isDot()) { $templates[] = (string) $dir->current(); } $dir->next(); } $this->set("alltemplates", $templates); }
public function indexAction() { // Get path $this->view->path = $path = $this->_getPath(); $this->view->relPath = $relPath = $this->_getRelPath($path); // List files $files = array(); $dirs = array(); $contents = array(); $it = new DirectoryIterator($path); foreach ($it as $key => $file) { $filename = $file->getFilename(); if ($it->isDot() && $this->_basePath == $path || $filename == '.' || $filename != '..' && $filename[0] == '.') { continue; } $relPath = trim(str_replace($this->_basePath, '', realpath($file->getPathname())), '/\\'); $ext = strtolower(ltrim(strrchr($file->getFilename(), '.'), '.')); if ($file->isDir()) { $ext = null; } $type = 'generic'; switch (true) { case in_array($ext, array('jpg', 'png', 'gif', 'jpeg', 'bmp', 'tif', 'svg')): $type = 'image'; break; case in_array($ext, array('txt', 'log', 'js')): $type = 'text'; break; case in_array($ext, array('html', 'htm')): $type = 'markup'; break; } $dat = array('name' => $file->getFilename(), 'path' => $file->getPathname(), 'info' => $file->getPathInfo(), 'rel' => $relPath, 'ext' => $ext, 'type' => $type, 'is_dir' => $file->isDir(), 'is_file' => $file->isFile(), 'is_image' => $type == 'image', 'is_text' => $type == 'text', 'is_markup' => $type == 'markup'); if ($it->isDir()) { $dirs[$relPath] = $dat; } else { if ($it->isFile()) { $files[$relPath] = $dat; } } $contents[$relPath] = $dat; } ksort($contents); $this->view->paginator = $paginator = Zend_Paginator::factory($contents); $paginator->setItemCountPerPage(20); $paginator->setCurrentPageNumber($this->_getParam('page', 1)); $this->view->files = $files; $this->view->dirs = $dirs; $this->view->contents = $contents; }
/** * Compacta todos os arquivos .php de um diretório removendo comentários, * espaços e quebras de linhas desnecessárias. * motivos de desempenho e segurança esse método so interage em um diretório * de cada vez. * * @param string $directoryPath * @param string $newFilesDirectory * @param string $newFilesPrefix * @param string $newFilesSufix */ public static function cleanDir($directoryPath, $newFilesDirectory = "packed", $newFilesPrefix = "", $newFilesSufix = "") { $dir = new DirectoryIterator($directoryPath); mkdir($directoryPath . "/{$newFilesDirectory}/"); while ($dir->valid()) { if (!$dir->isDir() and !$dir->isDot() and substr($dir->getFilename(), -3, 3) == 'php') { $str = self::cleanFile($dir->getPathname()); $fp = fopen($dir->getPath() . "/packed/" . $newFilesPrefix . $dir->getFilename() . $newFilesSufix, "w"); fwrite($fp, $str); fclose($fp); echo $dir->getPathname() . ' - Renomeado com sucesso <br />'; } $dir->next(); } }
/** * doExecute * * @return mixed */ public function doExecute() { try { $lanDir = new \DirectoryIterator($this->config['dir.src'] . '/language'); } catch (\UnexpectedValueException $e) { return; } // Each languages foreach ($lanDir as $dir) { if ($lanDir->isDot() || $lanDir->isFile()) { continue; } $this->handleINIFile($dir->getBasename()); } }
function getList($max = null) { $dir = new DirectoryIterator($this->file_path); $fileList = array(); while ($dir->valid()) { if ($dir->isDot()) { $dir->next(); continue; } $file_name = $dir->getFilename(); $fileList[] = $file_name; $dir->next(); } return $fileList; }
public function readDir($dirPath) { $di = new DirectoryIterator($dirPath); $array = array(); while ($di->valid()) { if (!$di->isDot() && $this->validateDir($di->getFilename())) { if ($di->isDir()) { $dir = $di->getPath() . '/' . $di->getFilename(); $array[$di->getFilename()] = $this->readDir($di->getPath() . '/' . $di->getFilename()); } else { $array[$di->getFilename()] = $di->getPath() . "/" . $di->getFilename(); } } $di->next(); } return $array; }
public function getPackages(array $srcDirs) { $pkgs = array(); foreach ($srcDirs as $dir) { $di = new DirectoryIterator($dir); foreach ($di as $val) { $pathname = $val->getPathname(); if ($val->isDir() && !$di->isDot() && file_exists($pathname . '/package.xml')) { $pkgs[basename($val)] = $pathname; } elseif ($val->isFile() && $val == 'package.xml') { $pkgs[basename($val->getPath())] = $val->getPath(); } } } asort($pkgs); return $pkgs; }
function rm_recursive($path) { if (!is_dir($path)) { return; } $dir = new DirectoryIterator($path); while ($dir->valid()) { if (!$dir->isDot()) { if ($dir->isDir()) { rm_recursive($path . DIRECTORY_SEPARATOR . $dir->current()); } else { unlink($path . DIRECTORY_SEPARATOR . $dir->current()); } } $dir->next(); } rmdir($path); }
/** * Console constructor. * * @param string $name Console name. * @param Input\Cli $input Cli input object. * @param CliOutput $output Cli output object. * @param AbstractCommand $parent Parent Console. * * @throws \LogicException */ public function __construct($name = null, Input\Cli $input = null, CliOutput $output = null, AbstractCommand $parent = null) { $this->globalOptions = OptionSet::getInstance(); parent::__construct($name, $input, $output, $parent); $ref = new \ReflectionClass($this); // Register sub commands $dirs = new \DirectoryIterator(dirname($ref->getFileName())); foreach ($dirs as $dir) { if (!$dir->isDir() || $dirs->isDot()) { continue; } $name = ucfirst($dir->getBasename()); $class = $ref->getNamespaceName() . '\\' . $name . "\\" . $name . 'Command'; if (class_exists($class) && $class::$isEnabled) { $this->addCommand(new $class()); } } }
/** * scan folders recursive and returns all folders * @param string $directory * @param string exclude * @return array|string */ public function scanRecursiveDir($directory, $exclude = '') { try { $file = ''; $it = new DirectoryIterator($directory); for ($it->rewind(); $it->valid(); $it->next()) { if ($it->isDir() && !$it->isDot()) { if ($it->getFilename() == $exclude) { continue; } $file[] = $it->getFilename(); } } return $file; } catch (Exception $e) { $logger = new debug_logger(MP_LOG_DIR); $logger->log('error', 'php', 'An error has occured : ' . $e->getMessage(), debug_logger::LOG_VOID); } }
/** * Iterates over a directory and returns file objects. * * @param string $dir * @param mixed $filter * @param bool $recursive defaults to false * @param bool $addDirs return directories as well as files - defaults to false * @return array * */ function getFilesInDir($dir, $filter = '', $recursive = false, $addDirs = false) { $res = array(); $dirIterator = new DirectoryIterator($dir); while ($dirIterator->valid()) { if (!$dirIterator->isDot()) { $file = $dirIterator->getPathname(); $isDir = is_dir($file); if (!$isDir || $addDirs) { if (empty($filter) || fnmatch($filter, $file)) { $res[] = $file; } } if ($isDir && $recursive) { $res = array_merge($res, getFilesInDir($file, $filter = '', $recursive)); } } $dirIterator->next(); } return $res; }
protected function method1($dir, $padLength = 0) { $thisDir = new \DirectoryIterator($dir); foreach ($thisDir as $value) { if ($thisDir->isDot()) { // Skip the dot directories continue; } else { if ($thisDir->isDir()) { if ($thisDir->isReadable()) { // if this is a new directory AND we have permission to read it, recurse into it. echo str_repeat(' ', $padLength * 2) . $value . "\\\n"; $this->method1($dir . '/' . $value, $padLength + 1); } } else { // output the file echo str_repeat(' ', $padLength * 2) . $value . "\n"; } } } return; }
protected static function move_dir($source, $destination, $overwrite) { if (!self::is_dir($source)) { throw new Exception('Only directory must be passed to move_dir() as source'); } if (!self::is_dir($destination)) { throw new Exception('Only directory must be passed to move_dir() as destination'); } $basename = pathinfo($source, PATHINFO_BASENAME); if (!self::is_dir($destination . '/' . $basename)) { if (!mkdir($destination . '/' . $basename, fileperms($source), TRUE)) { throw new Exception('Can not create directory ' . $destination . '/' . $basename); } } $dir = new DirectoryIterator($source); while ($dir->valid()) { if (!$dir->isDot()) { self::move($dir->getRealPath(), $destination . '/' . $basename, $overwrite); } $dir->next(); } self::delete_dir($source); }
/** * Delete empty directories (directories which contains only directories) starting from $dir * @static * @param string $dir * @param Closure|string|null $log * @return void */ static function deleteEmptyDirectories($dir, $log = null) { $iterator = new DirectoryIterator($dir); $files_in_dir = 0; foreach ($iterator as $node) { if ($iterator->isDot()) { continue; } $pathname = $iterator->getPathName(); $filename = $iterator->getFilename(); if ($iterator->isDir()) { $files_in_dir += self::deleteEmptyDirectories($iterator->getPathName(), $log); } else { $files_in_dir++; } } if ($files_in_dir == 0) { if (null !== $log) { $log("Remove empty dir '{$dir}'"); } rmdir($dir); } return $files_in_dir; }
/** * ULTIMATE Seo Urls 5 PRO by FWR Media * Reset the various cache systems * @param string $action */ function tep_reset_cache_data_usu5($action = false) { if ($action == 'reset') { $usu5_path = realpath(dirname(__FILE__) . '/../../../') . '/' . DIR_WS_MODULES . 'ultimate_seo_urls5/'; switch (USU5_CACHE_SYSTEM) { case 'file': $path_to_cache = $usu5_path . 'cache_system/cache/'; $it = new DirectoryIterator($path_to_cache); while ($it->valid()) { if (!$it->isDot() && is_readable($path_to_cache . $it->getFilename()) && substr($it->getFilename(), -6) == '.cache') { @unlink($path_to_cache . $it->getFilename()); } $it->next(); } break; case 'mysql': tep_db_query('TRUNCATE TABLE `usu_cache`'); break; case 'memcache': if (class_exists('Memcache')) { include $usu5_path . 'interfaces/cache_interface.php'; include $usu5_path . 'cache_system/memcache.php'; Memcache_Cache_Module::iAdmin()->initiate()->flushOut(); } break; case 'sqlite': include $usu5_path . 'interfaces/cache_interface.php'; include $usu5_path . 'cache_system/sqlite.php'; Sqlite_Cache_Module::admini()->gc(); break; } tep_db_query("UPDATE " . TABLE_CONFIGURATION . " SET configuration_value='false' WHERE configuration_key='USU5_RESET_CACHE'"); } }