read() 정적인 공개 메소드

It skips unwanted invisible stuff.
static public read ( string $dir ) : mixed
$dir string The path of directory
리턴 mixed An array of filenames or false
예제 #1
0
파일: mentions.php 프로젝트: aizlewood/2016
 public function __construct($params = array())
 {
     $defaults = array('page' => page(), 'headline' => 'Mentions');
     if (is_a($params, 'Page')) {
         $params = array('page' => $params);
     } else {
         if (is_string($params)) {
             $params = array('headline' => $params);
         }
     }
     $this->options = array_merge($defaults, $params);
     $this->page = $this->options['page'];
     $this->root = $this->page->root() . DS . '.webmentions';
     $this->headline = new Field($this->page, 'headline', $this->options['headline']);
     if (!is_dir($this->root)) {
         return;
     }
     $files = dir::read($this->root);
     // flip direction
     rsort($files);
     foreach ($files as $file) {
         // skip the pings cache
         if ($file == 'pings.json') {
             continue;
         }
         // register a new webmention
         try {
             $mention = new Mention($this->page, $this->root . DS . $file);
             $this->append($mention->id(), $mention);
         } catch (Exception $e) {
         }
     }
 }
예제 #2
0
 public function read($url = '', $recursive = false, $format = 'flat')
 {
     if (substr($url, -1) !== Application::DS) {
         $url .= Application::DS;
     }
     if ($this->ignore('find', $url)) {
         return array();
     }
     $list = array();
     $cwd = getcwd();
     chdir($url);
     if ($handle = opendir($url)) {
         while (false !== ($entry = readdir($handle))) {
             $recursiveList = array();
             if ($entry == '.' || $entry == '..') {
                 continue;
             }
             $file = new stdClass();
             $file->url = $url . $entry;
             if (is_dir($file->url)) {
                 $file->url .= Application::DS;
                 $file->type = 'dir';
             }
             if ($this->ignore('find', $file->url)) {
                 continue;
             }
             $file->name = $entry;
             if (isset($file->type)) {
                 if (!empty($recursive)) {
                     $directory = new dir();
                     $directory->ignore('list', $this->ignore());
                     $recursiveList = $directory->read($file->url, $recursive, $format);
                     if ($format !== 'flat') {
                         $file->list = $recursiveList;
                         unset($recursiveList);
                     }
                 }
             } else {
                 $file->type = 'file';
             }
             if (is_link($entry)) {
                 $file->link = true;
             }
             /* absolute url is_link wont work probably the targeting type
             			if(is_link($file->url)){
             				$file->link = true;
             			}
             			*/
             $list[] = $file;
             if (!empty($recursiveList)) {
                 foreach ($recursiveList as $recursive_nr => $recursive_file) {
                     $list[] = $recursive_file;
                 }
             }
         }
     }
     closedir($handle);
     return $list;
 }
예제 #3
0
파일: widgets.php 프로젝트: nsteiner/kdoc
 public function custom()
 {
     $kirby = kirby();
     $root = $kirby->roots()->widgets();
     foreach (dir::read($root) as $dir) {
         $kirby->registry->set('widget', $dir, $root . DS . $dir, true);
     }
 }
예제 #4
0
 public function testClean()
 {
     dir::make($this->tmpDir);
     f::write($this->tmpDir . DS . 'testfile.txt', '');
     $this->assertTrue(dir::clean($this->tmpDir));
     $files = dir::read($this->tmpDir);
     $this->assertEquals(0, count($files));
     dir::remove($this->tmpDir);
 }
예제 #5
0
 public function runTests($result)
 {
     $root = TEST_ROOT_ETC . DS . 'kirbytext';
     $dirs = dir::read($root);
     foreach ($dirs as $dir) {
         $testFile = $root . DS . $dir . DS . 'test.txt';
         $expectedFile = $root . DS . $dir . DS . 'expected.html';
         $this->assertEquals(f::read($expectedFile), $result(f::read($testFile)), 'test: ' . $dir);
     }
 }
예제 #6
0
 public function custom()
 {
     $root = kirby()->roots()->widgets();
     foreach (dir::read($root) as $dir) {
         // add missing widgets to the order array
         if (!array_key_exists($dir, $this->order)) {
             $this->order[$dir] = true;
         }
         $this->load($dir, $root . DS . $dir . DS . $dir . '.php');
     }
 }
예제 #7
0
 public function __construct()
 {
     $root = kirby::instance()->roots()->accounts();
     foreach (dir::read($root) as $file) {
         // skip invalid account files
         if (f::extension($file) != 'php') {
             continue;
         }
         $user = new User(f::name($file));
         $this->append($user->username(), $user);
     }
 }
예제 #8
0
 public function find($type)
 {
     $root = form::$root[$type];
     $dirs = dir::read($root);
     foreach ($dirs as $dir) {
         $name = strtolower($dir);
         $file = $root . DS . $name . DS . $name . '.php';
         if (file_exists($file)) {
             $this->{$type}[$name . 'field'] = $file;
         }
     }
 }
예제 #9
0
 public function index()
 {
     $widgets = array();
     $wroot = c::get('root.site') . DS . 'widgets';
     $wdirs = dir::read($wroot);
     foreach ($wdirs as $dir) {
         $file = $wroot . DS . $dir . DS . $dir . '.php';
         if (file_exists($file)) {
             $widgets[$dir] = (require $file);
         }
     }
     return view('dashboard/index', array('topbar' => new Snippet('pages/topbar', array('breadcrumb' => new Snippet('breadcrumb'), 'search' => purl('pages/search/'))), 'history' => history::get(), 'site' => site(), 'widgets' => $widgets, 'user' => site()->user()));
 }
예제 #10
0
파일: load.php 프로젝트: 04x10/04x10.com
 static function plugins()
 {
     $root = c::get('root.plugins');
     $files = dir::read($root);
     if (!is_array($files)) {
         return false;
     }
     foreach ($files as $file) {
         if (f::extension($file) != 'php') {
             continue;
         }
         self::file($root . '/' . $file);
     }
 }
예제 #11
0
파일: blueprint.php 프로젝트: nsteiner/kdoc
 public static function all()
 {
     $files = dir::read(static::$root);
     $result = array_keys(kirby()->get('blueprint'));
     $home = kirby()->option('home', 'home');
     $error = kirby()->option('error', 'error');
     foreach ($files as $file) {
         $name = f::name($file);
         if ($name != 'site' and $name != $home and $name != $error) {
             $result[] = $name;
         }
     }
     return $result;
 }
예제 #12
0
 public static function all()
 {
     $files = dir::read(static::$root);
     $result = array();
     $home = site()->homePage()->uid();
     $error = site()->errorPage()->uid();
     foreach ($files as $file) {
         $name = f::name($file);
         if ($name != 'site' and $name != $home and $name != $error) {
             $result[] = $name;
         }
     }
     return $result;
 }
예제 #13
0
 public function index()
 {
     $site = site();
     $widgets = array();
     $wroot = kirby()->roots()->widgets();
     $wdirs = dir::read($wroot);
     // fetch all top-level pages in the right order
     $blueprint = blueprint::find($site);
     $pages = api::subpages($site->children(), $blueprint);
     foreach ($wdirs as $dir) {
         $file = $wroot . DS . $dir . DS . $dir . '.php';
         if (file_exists($file)) {
             $widgets[$dir] = (require $file);
         }
     }
     return view('dashboard/index', array('topbar' => new Snippet('pages/topbar', array('breadcrumb' => new Snippet('breadcrumb'), 'search' => purl('pages/search/'))), 'history' => history::get(), 'site' => $site, 'pages' => $pages, 'addbutton' => !api::maxPages($site, $blueprint->pages()->max()), 'widgets' => $widgets, 'user' => site()->user(), 'license' => panel()->license()));
 }
예제 #14
0
 public function find()
 {
     $kirby = kirby();
     // store all fields coming from plugins and load
     // them between the default fields and the custom fields
     $pluginfields = $kirby->get('field');
     // load the default panel fields first, because they can be overwritten
     foreach (dir::read(form::$root['default']) as $name) {
         $kirby->set('field', $name, form::$root['default'] . DS . $name);
     }
     // load the plugin fields again. A bit hacky, but works
     foreach ($pluginfields as $name => $field) {
         $kirby->set('field', $name, $field->root());
     }
     // load all custom fields, which can overwrite all the others
     foreach (dir::read(form::$root['custom']) as $name) {
         $kirby->set('field', $name, form::$root['custom'] . DS . $name);
     }
 }
예제 #15
0
 static function plugins($folder = false)
 {
     $root = c::get('root.plugins');
     $folder = $folder ? $folder : $root;
     $files = dir::read($folder);
     if (!is_array($files)) {
         return false;
     }
     foreach ($files as $file) {
         if (is_dir($folder . '/' . $file) && $folder == $root) {
             self::plugins($folder . '/' . $file);
             continue;
         }
         if (f::extension($file) != 'php') {
             continue;
         }
         self::file($folder . '/' . $file);
     }
 }
예제 #16
0
function randomimage($dir)
{
    $files = dir::read(c::get('root') . '/' . $dir);
    shuffle($files);
    return url($dir . '/' . a::first($files));
}
예제 #17
0
 public static function files()
 {
     if (!is_null(static::$files)) {
         return static::$files;
     }
     static::$files = array();
     $files = dir::read(static::$root['default']);
     if (isset(static::$root['custom'])) {
         $files = array_merge($files, dir::read(static::$root['custom']));
     }
     foreach ($files as $file) {
         $name = strtolower($file) . 'field';
         if (isset(static::$root['custom']) and is_dir(static::$root['custom'] . DS . $file)) {
             static::$files[$name] = static::$root['custom'] . DS . $file . DS . $file . '.php';
         } else {
             static::$files[$name] = static::$root['default'] . DS . $file . DS . $file . '.php';
         }
     }
     return static::$files;
 }
예제 #18
0
 /**
  * Autoloads all page models
  */
 public function models()
 {
     if (!is_dir($this->roots()->models())) {
         return false;
     }
     $root = $this->roots()->models();
     $files = dir::read($root);
     $load = array();
     foreach ($files as $file) {
         if (f::extension($file) != 'php') {
             continue;
         }
         $name = f::name($file);
         $classname = str_replace(array('.', '-', '_'), '', $name . 'page');
         $load[$classname] = $root . DS . $file;
         // register the model
         page::$models[$name] = $classname;
     }
     // start the autoloader
     if (!empty($load)) {
         load($load);
     }
 }
예제 #19
0
파일: kirby.php 프로젝트: sdvig/kirbycms
 /**
  * Reads a directory and returns a full set of info about it
  * 
  * @param   string  $dir The path of directory
  * @param   array   $ignore Optional array with filenames, which should be ignored
  * @return  mixed   An info array or false
  */
 static function inspect($dir, $ignore = array())
 {
     if (!is_dir($dir)) {
         return array();
     }
     $files = dir::read($dir, $ignore);
     $modified = filemtime($dir);
     $data = array('name' => basename($dir), 'root' => $dir, 'modified' => $modified, 'files' => array(), 'children' => array());
     foreach ($files as $file) {
         if (is_dir($dir . '/' . $file)) {
             $data['children'][] = $file;
         } else {
             $data['files'][] = $file;
         }
     }
     return $data;
 }
예제 #20
0
파일: library.php 프로젝트: Zegnat/library
 public function clean($root)
 {
     if (!is_dir($root)) {
         throw new Exception('The given directory does not exist');
     }
     if (!str::startsWith($root, $this->root)) {
         throw new Exception('Invalid directory. Must be within the library');
     }
     while ($root != $this->root) {
         $files = dir::read($root);
         if (count($files) === 0) {
             dir::remove($root);
         } else {
             break;
         }
         $root = dirname($root);
     }
 }
예제 #21
0
 static function findTemplates()
 {
     global $settings, $pages, $page, $site;
     $templates = array();
     if (@$settings->pages['template'] && !$site->isHome) {
         $templates[] = $settings->pages['template'];
     } else {
         $files = dir::read(c::get('root.site') . '/templates');
         foreach ($files as $file) {
             $name = f::name($file);
             // check if it is valid or already there.
             if (empty($name) || in_array($name, $templates)) {
                 continue;
             }
             // add it to the list of templates
             $templates[] = $name;
         }
     }
     return $templates;
 }
예제 #22
0
파일: panel.php 프로젝트: nsteiner/kdoc
 public function translations()
 {
     if (!is_null($this->translations)) {
         return $this->translations;
     }
     $this->translations = new Collection();
     foreach (dir::read($this->roots()->translations()) as $dir) {
         // filter out everything but directories
         if (!is_dir($this->roots()->translations() . DS . $dir)) {
             continue;
         }
         // create the translation object
         $translation = new Translation($this, $dir);
         $this->translations->append($translation->code(), $translation);
     }
     return $this->translations;
 }
예제 #23
0
파일: Delete.php 프로젝트: getkirby/cli
 protected function selection()
 {
     return array_map(function ($filename) {
         return f::name($filename);
     }, dir::read($this->root()));
 }
예제 #24
0
파일: app.php 프로젝트: kompuser/panel
 public static function languages()
 {
     $languages = new Collection();
     foreach (dir::read(root('panel.app.languages')) as $file) {
         $language = new Obj(require root('panel.app.languages') . DS . $file);
         $language->code = str_replace('.php', '', $file);
         $languages->set($language->code, $language);
     }
     return $languages;
 }
예제 #25
0
 static function stillHasDefaultAccount()
 {
     $file = c::get('root.site') . '/' . c::get('panel.folder') . '/accounts/admin.php';
     if (file_exists($file)) {
         return true;
     }
     $dir = c::get('root.site') . '/' . c::get('panel.folder') . '/accounts';
     $files = dir::read($dir);
     $default = array('username' => 'admin', 'password' => 'adminpassword', 'language' => 'en');
     foreach ($files as $file) {
         $username = f::name($file);
         $user = user::load($username);
         $diff = array_diff($user, $default);
         if (empty($diff)) {
             return true;
         }
     }
     return false;
 }
예제 #26
0
  <dt>Installed Plugins</dt>
  <dd><?php 
a::show(dir::read(c::get('root.plugins')));
?>
</dd>
    
  <dt>Installed Snippets</dt>
  <dd><?php 
a::show(dir::read(c::get('root.snippets')));
?>
</dd>

  <dt>Your config files</dt>
  <dd><?php 
a::show(dir::read(c::get('root.site') . '/config'));
?>
</dd>
    
  <dt>Your entire config</dt>
  <dd><?php 
a::show(c::get());
?>
</dd>

  <dt>PHP Error Reporting</dt>
  <dd><?php 
echo ini_get('display_errors') ? 'yes' : 'no';
?>
</dd>
예제 #27
0
파일: panel.php 프로젝트: v1m0/kirby-f6
 public function languages()
 {
     $languages = new Collection();
     $root = $this->roots()->languages();
     foreach (dir::read($root) as $file) {
         // skip invalid language files
         if (f::extension($file) != 'php') {
             continue;
         }
         // fetch all strings from the language file
         $strings = (require $root . DS . $file);
         // skip invalid language files
         if (!is_array($strings)) {
             continue;
         }
         // create the language object
         $language = new Obj($strings);
         $language->code = str_replace('.php', '', $file);
         $languages->set($language->code, $language);
     }
     return $languages;
 }
예제 #28
0
 /**
  * Checks if the directory or any subdirectory has been
  * modified after the given timestamp
  *
  * @param string $dir
  * @param int $time
  * @return boolean
  */
 public static function wasModifiedAfter($dir, $time)
 {
     if (filemtime($dir) > $time) {
         return true;
     }
     $content = dir::read($dir);
     foreach ($content as $item) {
         $subdir = $dir . DS . $item;
         if (filemtime($subdir) > $time) {
             return true;
         }
         if (is_dir($subdir) and dir::wasModifiedAfter($subdir, $time)) {
             return true;
         }
     }
     return false;
 }
예제 #29
0
 public function translations()
 {
     if (!is_null($this->translations)) {
         return $this->translations;
     }
     $this->translations = new Collection();
     foreach (dir::read($this->roots()->translations()) as $dir) {
         // create the translation object
         $translation = new Translation($this, $dir);
         $this->translations->append($translation->code(), $translation);
     }
     return $this->translations;
 }
예제 #30
0
 public function children()
 {
     $children = new Collection();
     foreach (dir::read($this->root) as $dir) {
         if (!is_dir($this->root . DS . $dir)) {
             continue;
         }
         $pattern = new Pattern($this->path . '/' . $dir);
         $children->append($pattern->path(), $pattern);
     }
     return $children;
 }