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); }
/** * 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()); } } }
/** * Find all plugins defined in your Kohana codebase */ public function find_plugins() { $paths = Kohana::include_paths(); foreach ($paths as $path) { $dir = $path . self::$plugins_dir; //if there's no plugin dir skip to the next path if (!file_exists($dir)) { continue; } // Instantiate a new directory iterator object $directory = new DirectoryIterator($dir); if ($directory->isDir()) { foreach ($directory as $plugin) { // Is directory? if ($plugin->isDir() && !$plugin->isDot()) { // if there's no plugin.php in this folder, ignore it if (!file_exists($plugin->getPath() . DIRECTORY_SEPARATOR . $directory->getBasename() . DIRECTORY_SEPARATOR . 'plugin.php')) { continue; } // Store plugin in our pool self::$plugins_pool[$plugin->getFilename()]['plugin'] = ucfirst($plugin->getFilename()); self::$plugins_pool[$plugin->getFilename()]['path'] = $plugin->getPath() . DIRECTORY_SEPARATOR . $directory->getBasename(); } } } } return $this; }
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; }
public function valid() { if (parent::valid()) { if (!parent::isDir()) { parent::next(); return $this->valid(); } return TRUE; } return FALSE; }
/** * valid * * @access public * @return bool */ public function valid() { if (parent::valid()) { if (parent::isDir()) { parent::next(); return $this->valid(); } return true; } return false; }
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; }
function getTestDirs($dir = './') { $file = new DirectoryIterator($dir); $res = array(); while ($file->valid()) { if ($file->isDir() && !$file->isDot()) { $res[] = $file->getPathName(); } $file->next(); } return $res; }
/** * @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; }
public function getPlugins() { $output = array(); $it = new DirectoryIterator(BASE . 'plugins/'); while ($it->valid()) { $xml_path = $it->getPath() . $it->getFilename() . '/'; $xml_file = $xml_path . "plugin.xml"; if ($it->isReadable() && $it->isDir() && file_exists($xml_file)) { $output[] = new PapyrinePlugin($xml_path); } $it->next(); } return $output; }
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; }
private static function load_plugin(ContextManager $context, DirectoryIterator $plugin_path) { $plugin_load_file = $plugin_path->getPathname() . DIRECTORY_SEPARATOR . 'init.php'; if ($plugin_path->isDir() && is_file($plugin_load_file) && (require $plugin_load_file)) { $class = Plugins::plugin_class_name($plugin_path); try { $klass = new ReflectionClass($class); Plugins::add($klass->newInstance($context)); $context->logger()->debugf('%s --> %s', str_replace(MEDICK_PATH, '${' . $context->config()->application_name() . '}', $plugin_load_file), $class); } catch (ReflectionException $rfEx) { $context->logger()->warn('failed to load plugin `' . $plugin_path->getFilename() . '`: ' . $rfEx->getMessage()); } } }
/** * 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(); } }
/** * Returns the available languages for this documentation format * * @return array Array of string language codes * @api */ public function getAvailableLanguages() { $languages = array(); $languagesDirectoryIterator = new \DirectoryIterator($this->formatPath); $languagesDirectoryIterator->rewind(); while ($languagesDirectoryIterator->valid()) { $filename = $languagesDirectoryIterator->getFilename(); if ($filename[0] != '.' && $languagesDirectoryIterator->isDir()) { $language = $filename; $languages[] = $language; } $languagesDirectoryIterator->next(); } return $languages; }
/** * Returns a list of all template names. * * @return string[] */ protected function getTemplateNames() { /** @var \RecursiveDirectoryIterator $files */ $files = new \DirectoryIterator(dirname(__FILE__) . '/../../../../data/templates'); $template_names = array(); while ($files->valid()) { $name = $files->getBasename(); // skip abstract files if (!$files->isDir() || in_array($name, array('.', '..'))) { $files->next(); continue; } $template_names[] = $name; $files->next(); } return $template_names; }
/** * Returns a list of all template names. * * @return string[] */ public function getAllNames() { /** @var \RecursiveDirectoryIterator $files */ $files = new \DirectoryIterator($this->getTemplatePath()); $template_names = array(); while ($files->valid()) { $name = $files->getBasename(); // skip abstract files if (!$files->isDir() || in_array($name, array('.', '..'))) { $files->next(); continue; } $template_names[] = $name; $files->next(); } return $template_names; }
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; }
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); }
/** * 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); } }
/** * Executes the transformation process. * * @throws Zend_Console_Getopt_Exception * * @return void */ public function execute() { if ($this->getQuiet()) { return; } echo 'Available themes:' . PHP_EOL; /** @var RecursiveDirectoryIterator $files */ $files = new DirectoryIterator(dirname(__FILE__) . '/../../../../data/themes'); while ($files->valid()) { $name = $files->getBasename(); // skip abstract files if (!$files->isDir() || in_array($name, array('.', '..'))) { $files->next(); continue; } echo '* ' . $name . PHP_EOL; $files->next(); } echo PHP_EOL; }
/** * Iteratively remove/delete a directory and its contents * * @param DirectoryIterator $path base directory (inclusive) to recursively delete. */ function recursivelyDeleteDirectory(DirectoryIterator $path) { // echo $path . " being deleted?"; if ($path->isDir()) { $directory = new DirectoryIterator($path->getPath() . DIRECTORY_SEPARATOR . $path->getFilename()); // For each element within this directory, delete it or recurse into next directory foreach ($directory as $object) { if (!$object->isDot()) { if ($object->isDir()) { recursivelyDeleteDirectory($object); } else { unlink($object->getPathname()); } } } rmdir($path->getPathname()); } else { // Not a directory... // Do nothing } }
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; }
function getDirInfo($dir) { $iterator = new DirectoryIterator($dir); #先输出文件夹 while ($iterator->valid()) { if ($iterator->isDir() && $iterator->getFilename() != '.' && $iterator->getFilename() != '..' && $iterator->getFilename() != '.git') { echo '<li class="flist filedir"><i class="fa fa-folder-open"></i> ' . $iterator->getFilename(); echo '<ul class="dirlist">'; getDirInfo($iterator->getPathname()); echo '</ul></li>'; } $iterator->next(); } #再输出文件 $iterator->Rewind(); while ($iterator->valid()) { if ($iterator->isFile()) { echo '<li class="flist file"><i class="fa fa-file-text"></i> ' . $iterator->getFilename() . '</li>'; } $iterator->next(); } }
/** * Returns a list of all template names. * * @return string[] */ protected function getTemplateNames() { // TODO: this directory needs to come from the parameter set in the DIC in the ServiceProvider $template_dir = dirname(__FILE__) . '/../../../../data/templates'; if (!file_exists($template_dir)) { //Vendored installation $template_dir = dirname(__FILE__) . '/../../../../../../templates'; } /** @var \RecursiveDirectoryIterator $files */ $files = new \DirectoryIterator($template_dir); $template_names = array(); while ($files->valid()) { $name = $files->getBasename(); // skip abstract files if (!$files->isDir() || in_array($name, array('.', '..'))) { $files->next(); continue; } $template_names[] = $name; $files->next(); } return $template_names; }
/** * 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; }
/** * Automatically find and create drush aliases on the server. * @param array $aliases array of drush aliases */ function _elmsln_alises_build_server(&$aliases, &$authorities = array()) { // static cache assembled aliases as this can get tripped often static $pulledaliases = array(); static $pulledauthorities = array(); static $config = array(); // check for pervasive cache if static is empty if (empty($pulledaliases)) { // assumption here is that it lives where we expect // change this line if that's not the case though we really don't // support changes to that part of the install routine $cfg = file_get_contents('/var/www/elmsln/config/scripts/drush-create-site/config.cfg'); $lines = explode("\n", $cfg); // read each line of the config file foreach ($lines as $line) { // make sure this line isn't a comment and has a = in it if (strpos($line, '#') !== 0 && strpos($line, '=')) { $tmp = explode('=', $line); // ensure we have 2 settings before doing this if (count($tmp) == 2) { // never pass around the dbsu if (!in_array($tmp[0], array('dbsu', 'dbsupw'))) { // strip encapsulation if it exists $config[$tmp[0]] = str_replace('"', '', str_replace("'", '', $tmp[1])); } } } } // support the fact that $elmsln is used to reference in many bash vars foreach ($config as $key => $value) { if (strpos($value, '$elmsln') !== FALSE) { $config[$key] = str_replace('$elmsln', $config['elmsln'], $value); } } // base address of all domains $address = $config['address']; // your web root $root = $config['stacks'] . '/'; // calculate the stacks we have $stacks = array(); $stackfinder = new DirectoryIterator("{$root}"); while ($stackfinder->valid()) { // Look for directories that are stacks if ($stackfinder->isDir() && !$stackfinder->isDot() && !$stackfinder->isLink()) { $stacks[] = $stackfinder->getBasename(); } $stackfinder->next(); } // loop through known stacks foreach ($stacks as $stack) { // step through sites directory assuming it isn't the 'default' if ($stack != 'default' && is_dir("{$root}{$stack}/sites/{$stack}")) { try { $stackdir = new DirectoryIterator("{$root}{$stack}/sites/{$stack}"); while ($stackdir->valid()) { // Look for directories containing a 'settings.php' file if ($stackdir->isDir() && !$stackdir->isDot() && !$stackdir->isLink()) { $group = $stackdir->getBasename(); // only include stack if it has things we can step through // this helps avoid issues of unused stacks throwing errors if (file_exists("{$root}{$stack}/sites/{$stack}/{$group}")) { // build root alias for the stack $pulledauthorities[$stack] = array('root' => $root . $stack, 'uri' => "{$stack}.{$address}"); // step through sites directory if (is_dir("{$root}{$stack}/sites/{$stack}/{$group}")) { $site = new DirectoryIterator("{$root}{$stack}/sites/{$stack}/{$group}"); while ($site->valid()) { // Look for directories containing a 'settings.php' file if ($site->isDir() && !$site->isDot() && !$site->isLink()) { if (file_exists($site->getPathname() . '/settings.php')) { // Add site alias $basename = $site->getBasename(); // test that this isn't actually something like coursename = host if ($basename == $config['host'] && !is_dir("{$root}{$stack}/sites/{$stack}/{$group}/{$group}")) { $pulledaliases["{$stack}.{$basename}"] = array('root' => $root . $stack, 'uri' => "{$stack}.{$address}"); } else { $pulledaliases["{$stack}.{$basename}"] = array('root' => $root . $stack, 'uri' => "{$stack}.{$address}.{$basename}"); } } } $site->next(); } } } } $stackdir->next(); } } catch (Exception $e) { // that tool doesn't have a directory, oh well } } } } $aliases = $pulledaliases; $authorities = $pulledauthorities; return $config; }
/** * Returns the available documentations for this package * * @return array Array of \TYPO3\Flow\Package\Documentation * @api */ public function getPackageDocumentations() { $documentations = array(); $documentationPath = $this->getDocumentationPath(); if (is_dir($documentationPath)) { $documentationsDirectoryIterator = new \DirectoryIterator($documentationPath); $documentationsDirectoryIterator->rewind(); while ($documentationsDirectoryIterator->valid()) { $filename = $documentationsDirectoryIterator->getFilename(); if ($filename[0] != '.' && $documentationsDirectoryIterator->isDir()) { $filename = $documentationsDirectoryIterator->getFilename(); $documentation = new Documentation($this, $filename, $documentationPath . $filename . '/'); $documentations[$filename] = $documentation; } $documentationsDirectoryIterator->next(); } } return $documentations; }
function disney_zip() { $input = 'D:\\Comic\\!Disney'; $output = 'D:\\Temp\\Disney'; $dir = new DirectoryIterator($input); while ($dir->valid()) { if ($dir->isDir() && !$dir->isDot()) { $author = $dir->getFilename(); $author_path = $output . '/' . $author; if (!is_dir($author_path)) { mkdir($author_path); } $bat = "cd {$dir->getPathname()}" . PHP_EOL; $dir_comic = new DirectoryIterator($dir->getPathname()); while ($dir_comic->valid()) { if ($dir_comic->isDir() && !$dir_comic->isDot()) { $comic = $dir_comic->getFilename(); $comic_path = $author_path . '/' . $comic; $bat .= "7z a \"{$comic_path}.zip\" \".\\{$comic}\\*\" -tzip -mx0" . PHP_EOL; } $dir_comic->next(); } echo $bat; } $dir->next(); } }
/** * Get the context menu items for a specific object in the list view * * @param DirectoryIterator $file * @param array $fileArray * @return array */ public function getListContextMenu(DirectoryIterator $file, array $fileArray) { $menu = array(); if (!$file->isDir()) { /* files */ if ($this->hasPermission('file_update')) { if (!empty($fileArray['page'])) { $menu[] = array('text' => $this->xpdo->lexicon('file_edit'), 'handler' => 'this.editFile'); } $menu[] = array('text' => $this->xpdo->lexicon('rename'), 'handler' => 'this.renameFile'); } if ($this->hasPermission('file_view')) { $menu[] = array('text' => $this->xpdo->lexicon('file_download'), 'handler' => 'this.downloadFile'); } if ($this->hasPermission('file_remove')) { if (!empty($menu)) { $menu[] = '-'; } $menu[] = array('text' => $this->xpdo->lexicon('file_remove'), 'handler' => 'this.removeFile'); } } else { /* directories */ if ($this->hasPermission('directory_create')) { $menu[] = array('text' => $this->xpdo->lexicon('file_folder_create_here'), 'handler' => 'this.createDirectory'); } if ($this->hasPermission('directory_chmod')) { $menu[] = array('text' => $this->xpdo->lexicon('file_folder_chmod'), 'handler' => 'this.chmodDirectory'); } if ($this->hasPermission('directory_update')) { $menu[] = array('text' => $this->xpdo->lexicon('rename'), 'handler' => 'this.renameDirectory'); } $menu[] = array('text' => $this->xpdo->lexicon('directory_refresh'), 'handler' => 'this.refreshActiveNode'); if ($this->hasPermission('file_upload')) { $menu[] = '-'; $menu[] = array('text' => $this->xpdo->lexicon('upload_files'), 'handler' => 'this.uploadFiles'); } if ($this->hasPermission('file_create')) { $menu[] = array('text' => $this->xpdo->lexicon('file_create'), 'handler' => 'this.createFile'); } if ($this->hasPermission('directory_remove')) { $menu[] = '-'; $menu[] = array('text' => $this->xpdo->lexicon('file_folder_remove'), 'handler' => 'this.removeDirectory'); } } return $menu; }
/** * @param \DirectoryIterator $fileInfo * * @return bool */ private function isValidDir(\DirectoryIterator $fileInfo) { return $fileInfo->isDir() && !$fileInfo->isDot() && stripos($fileInfo->getBasename(), '.') !== 0; }