private function findBlueprints($paths) { $options = ['compare' => 'Filename', 'pattern' => '|\\.yaml$|', 'filters' => ['key' => '|\\.yaml$|'], 'key' => 'SubPathName', 'value' => 'PathName']; foreach ((array) $paths as $path) { return Folder::all($path, $options); } }
public function scanTemplates($path) { $options = ['compare' => 'Filename', 'pattern' => '|\\.html\\.twig$|', 'filters' => ['value' => '|\\.html\\.twig$|'], 'value' => 'Filename', 'recursive' => false]; foreach (Folder::all($path, $options) as $type) { $this->register($type); } if (file_exists($path . 'modular/')) { foreach (Folder::all($path . 'modular/', $options) as $type) { $this->register('modular/' . $type); } } }
/** * Detects all plugins with a configuration file and returns last modification time. * * @param string $lookup Location to look up from. * @param bool $blueprints * @return array * @internal */ protected function detectConfig($lookup = SYSTEM_DIR, $blueprints = false) { $location = $blueprints ? 'blueprintFiles' : 'configFiles'; $path = trim(Folder::getRelativePath($lookup), '/'); if (isset($this->{$location}[$path])) { return [$path => $this->{$location}[$path]]; } if (is_dir($lookup)) { // Find all system and user configuration files. $options = ['compare' => 'Filename', 'pattern' => '|\\.yaml$|', 'filters' => ['key' => '|\\.yaml$|', 'value' => function (\RecursiveDirectoryIterator $file) use($path) { return ['file' => "{$path}/{$file->getSubPathname()}", 'modified' => $file->getMTime()]; }], 'key' => 'SubPathname']; $list = Folder::all($lookup, $options); } else { $list = []; } $this->{$location}[$path] = $list; return [$path => $list]; }
/** * Get the next available ordering number in a folder * * @param $path * * @return string the correct order string to prepend */ private function getNextOrderInFolder($path) { $files = Folder::all($path, ['recursive' => false]); $highestOrder = 0; foreach ($files as $file) { preg_match(PAGE_ORDER_PREFIX_REGEX, $file, $order); if (isset($order[0])) { $theOrder = intval(trim($order[0], '.')); } else { $theOrder = 0; } if ($theOrder >= $highestOrder) { $highestOrder = $theOrder; } } $orderOfNewFolder = $highestOrder + 1; if ($orderOfNewFolder < 10) { $orderOfNewFolder = '0' . $orderOfNewFolder; } return $orderOfNewFolder; }
/** * Detects all plugins with a configuration file and returns them with last modification time. * * @param string $folder Location to look up from. * @param string $pattern Pattern to match the file. Pattern will also be removed from the key. * @param int $levels Maximum number of recursive directories. * @return array * @internal */ protected function detectAll($folder, $pattern, $levels) { $path = trim(Folder::getRelativePath($folder), '/'); if (is_dir($folder)) { // Find all system and user configuration files. $options = ['levels' => $levels, 'compare' => 'Filename', 'pattern' => $pattern, 'filters' => ['pre-key' => $this->base, 'key' => $pattern, 'value' => function (\RecursiveDirectoryIterator $file) use($path) { return ["{$path}/{$file->getSubPathname()}" => $file->getMTime()]; }], 'key' => 'SubPathname']; $list = Folder::all($folder, $options); ksort($list); } else { $list = []; } return $list; }
/** * Build a list of configuration files with their timestamps. Used for loading settings and caching them. * * @return array * @internal */ protected function build() { // Find all plugins with default configuration options. $plugins = array(); $iterator = new \DirectoryIterator(PLUGINS_DIR); /** @var \DirectoryIterator $plugin */ foreach ($iterator as $plugin) { $name = $plugin->getBasename(); $file = $plugin->getPathname() . DS . $name . YAML_EXT; if (!is_file($file)) { continue; } $modified = filemtime($file); $plugins["plugins/{$name}"] = $modified; } // Find all system and user configuration files. $options = array('compare' => 'Filename', 'pattern' => '|\\.yaml$|', 'filters' => array('key' => '|\\.yaml$|'), 'key' => 'SubPathname', 'value' => 'MTime'); $system = Folder::all(SYSTEM_DIR . 'config', $options); $user = Folder::all(USER_DIR . 'config', $options); return array('system' => $system, 'plugins' => $plugins, 'user' => $user); }
/** * Detects all plugins with a configuration file and returns them with last modification time. * * @param string $folder Location to look up from. * @return array * @internal */ protected function detectRecursive($folder) { $path = trim(Folder::getRelativePath($folder), '/'); if (is_dir($folder)) { // Find all system and user configuration files. $options = ['compare' => 'Filename', 'pattern' => '|\\.yaml$|', 'filters' => ['key' => '|\\.yaml$|', 'value' => function (\RecursiveDirectoryIterator $file) use($path) { return ['file' => "{$path}/{$file->getSubPathname()}", 'modified' => $file->getMTime()]; }], 'key' => 'SubPathname']; $list = Folder::all($folder, $options); } else { $list = []; } return [$path => $list]; }
private function findBlueprints($path) { $options = [ 'compare' => 'Filename', 'pattern' => '|\.yaml$|', 'filters' => [ 'key' => '|\.yaml$|' ], 'key' => 'SubPathName', 'value' => 'PathName', ]; return Folder::all($path, $options); }
private function findBlueprints($uri) { $options = ['compare' => 'Filename', 'pattern' => '|\\.yaml$|', 'filters' => ['key' => '|\\.yaml$|'], 'key' => 'SubPathName', 'value' => 'PathName']; /** @var UniformResourceLocator $locator */ $locator = Grav::instance()['locator']; if ($locator->isStream($uri)) { $options['value'] = 'Url'; } $list = Folder::all($uri, $options); return $list; }
/** * Handles creating an empty page folder (without markdown file) * * @return bool True if the action was performed. */ public function taskSaveNewFolder() { if (!$this->authorizeTask('save', $this->dataPermissions())) { return; } $data = $this->post; if ($data['route'] == '/') { $path = $this->grav['locator']->findResource('page://'); } else { $path = $page = $this->grav['page']->find($data['route'])->path(); } $files = Folder::all($path, ['recursive' => false]); $highestOrder = 0; foreach ($files as $file) { preg_match(PAGE_ORDER_PREFIX_REGEX, $file, $order); if (isset($order[0])) { $theOrder = intval(trim($order[0], '.')); } else { $theOrder = 0; } if ($theOrder >= $highestOrder) { $highestOrder = $theOrder; } } $orderOfNewFolder = $highestOrder + 1; if ($orderOfNewFolder < 10) { $orderOfNewFolder = '0' . $orderOfNewFolder; } Folder::mkdir($path . '/' . $orderOfNewFolder . '.' . $data['folder']); $this->admin->setMessage($this->admin->translate('PLUGIN_ADMIN.SUCCESSFULLY_SAVED'), 'info'); $multilang = $this->isMultilang(); $admin_route = $this->grav['config']->get('plugins.admin.route'); $redirect_url = '/' . ($multilang ? $this->grav['session']->admin_lang : '') . $admin_route . '/' . $this->view; $this->setRedirect($redirect_url); return true; }