[Changed] Replaced glob_recursive with get_files
This commit is contained in:
Gilbert Pellegrom 2013-05-07 16:27:39 +01:00
parent f9ebb4d75c
commit b145ea7d23
2 changed files with 26 additions and 13 deletions

View File

@ -1,5 +1,8 @@
*** Pico Changelog *** *** Pico Changelog ***
2013.05.07 - version 0.6.2
* [Changed] Replaced glob_recursive with get_files
2013.05.07 - version 0.6.1 2013.05.07 - version 0.6.1
* [New] Added "content" and "excerpt" fields to pages * [New] Added "content" and "excerpt" fields to pages
* [New] Added excerpt_length config setting * [New] Added excerpt_length config setting

View File

@ -6,7 +6,7 @@
* @author Gilbert Pellegrom * @author Gilbert Pellegrom
* @link http://pico.dev7studios.com * @link http://pico.dev7studios.com
* @license http://opensource.org/licenses/MIT * @license http://opensource.org/licenses/MIT
* @version 0.6.1 * @version 0.6.2
*/ */
class Pico { class Pico {
@ -109,7 +109,7 @@ class Pico {
private function load_plugins() private function load_plugins()
{ {
$this->plugins = array(); $this->plugins = array();
$plugins = $this->glob_recursive(PLUGINS_DIR .'*.php'); $plugins = $this->get_files(PLUGINS_DIR, '.php');
if(!empty($plugins)){ if(!empty($plugins)){
foreach($plugins as $plugin){ foreach($plugins as $plugin){
include_once($plugin); include_once($plugin);
@ -209,7 +209,7 @@ class Pico {
{ {
global $config; global $config;
$pages = $this->glob_recursive(CONTENT_DIR .'*'. CONTENT_EXT); $pages = $this->get_files(CONTENT_DIR, CONTENT_EXT);
$sorted_pages = array(); $sorted_pages = array();
foreach($pages as $key=>$page){ foreach($pages as $key=>$page){
// Skip 404 // Skip 404
@ -292,19 +292,29 @@ class Pico {
} }
/** /**
* Helper function to make glob recursive * Helper function to recusively get all files in a directory
* *
* @param string $pattern glob pattern * @param string $directory start directory
* @param int $flags glob flags * @param string $ext optional limit to file extensions
* @return array the matched files/directories * @return array the matched files
*/ */
private function glob_recursive($pattern, $flags = 0) private function get_files($directory, $ext = '')
{ {
$files = glob($pattern, $flags); $array_items = array();
foreach(glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir){ if($handle = opendir($directory)){
$files = array_merge($files, $this->glob_recursive($dir.'/'.basename($pattern), $flags)); while(false !== ($file = readdir($handle))){
} if($file != "." && $file != ".."){
return $files; if(is_dir($directory. "/" . $file)){
$array_items = array_merge($array_items, $this->get_files($directory. "/" . $file, $ext));
} else {
$file = $directory . "/" . $file;
if(!$ext || strstr($file, $ext)) $array_items[] = preg_replace("/\/\//si", "/", $file);
}
}
}
closedir($handle);
}
return $array_items;
} }
/** /**