From fbec175cb8798d56a45b53f599e619f20bb617b4 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 23 Jul 2009 17:13:53 -0400 Subject: [PATCH] set up layout information --- classes/ComicPress.inc | 23 +++++++++++++++++------ test/ComicPressTest.php | 6 +++++- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/classes/ComicPress.inc b/classes/ComicPress.inc index 8b22393..2b3e18c 100644 --- a/classes/ComicPress.inc +++ b/classes/ComicPress.inc @@ -24,6 +24,7 @@ class ComicPress { var $category_tree = array(); var $partial_paths = array(); + var $layouts = null; /** * Load ComicPress options. @@ -360,14 +361,24 @@ class ComicPress { function _file_get_contents($file) { return file_get_contents($file); } function get_layout_choices() { - $layouts = array(); - foreach ($this->_glob(get_template_directory() . '/layouts/*') as $file) { - $content = $this->_file_get_contents($file); - if (preg_match('#/\*.*Layout Name: ([^\n]+).*\*/#s', $content, $matches) > 0) { - $layouts[pathinfo($file, PATHINFO_BASENAME)] = $matches[1]; + if (!is_array($this->layouts)) { + $this->layouts = array(); + foreach ($this->_glob(get_template_directory() . '/layouts/*') as $file) { + $content = $this->_file_get_contents($file); + $basename = pathinfo($file, PATHINFO_BASENAME); + foreach (array( + "Layout Name", "Sidebars" + ) as $field) { + if (preg_match('#/\*.*' . $field . ': ([^\n]+).*\*/#s', $content, $matches) > 0) { + if (!is_array($this->layouts[$basename])) { + $this->layouts[$basename] = array(); + } + $this->layouts[$basename][$field] = $matches[1]; + } + } } } - return $layouts; + return $this->layouts; } } diff --git a/test/ComicPressTest.php b/test/ComicPressTest.php index 8f976b2..d077992 100644 --- a/test/ComicPressTest.php +++ b/test/ComicPressTest.php @@ -192,10 +192,14 @@ FILE 'layout.php' => << 'Test') + array('layout.php' => array( + 'Layout Name' => 'Test', + 'Sidebars' => 'left,right', + )) ), ); }