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) { } } }
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; }
public function custom() { $kirby = kirby(); $root = $kirby->roots()->widgets(); foreach (dir::read($root) as $dir) { $kirby->registry->set('widget', $dir, $root . DS . $dir, true); } }
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); }
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); } }
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'); } }
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); } }
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; } } }
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())); }
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); } }
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; }
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; }
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())); }
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); } }
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); } }
function randomimage($dir) { $files = dir::read(c::get('root') . '/' . $dir); shuffle($files); return url($dir . '/' . a::first($files)); }
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; }
/** * 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); } }
/** * 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; }
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); } }
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; }
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; }
protected function selection() { return array_map(function ($filename) { return f::name($filename); }, dir::read($this->root())); }
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; }
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; }
<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>
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; }
/** * 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; }
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; }
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; }