diff options
-rw-r--r-- | utils/modules.php | 50 | ||||
-rw-r--r-- | utils/modules/discography.php | 2 | ||||
-rw-r--r-- | utils/modules/events.php | 2 | ||||
-rw-r--r-- | utils/modules/gallery.php | 2 | ||||
-rw-r--r-- | utils/modules/guestbook.php | 3 | ||||
-rw-r--r-- | utils/modules/icons.php | 3 | ||||
-rw-r--r-- | utils/modules/members.php | 2 | ||||
-rw-r--r-- | utils/modules/news.php | 35 | ||||
-rw-r--r-- | utils/modules/pages.php | 14 |
9 files changed, 83 insertions, 30 deletions
diff --git a/utils/modules.php b/utils/modules.php index 4c34228..54682a4 100644 --- a/utils/modules.php +++ b/utils/modules.php @@ -2,14 +2,48 @@ $modules = array(); -/** - * Iterate all defined modules, and load them into the global array. - * FIXME: Make this lazy (load on demand) - */ -foreach($MODULES as $modulename) { - include_once($MODULES_DIR . "/" . $modulename . ".php"); - $module = call_user_func($modulename . "_init"); - $modules[$modulename] = $module; +function loadModule($modulename) +{ + global $MODULES_DIR; + global $modules; + + $modulefile = $MODULES_DIR . "/" . $modulename . ".php"; + if(!$modules[$modulename]) { + if(file_exists($modulefile)) { + include_once($modulefile); + $module = call_user_func($modulename . "_init"); + $modules[$modulename] = $module; + } else { + // Module does not exist. + } + } +} + +function getModuleParams($code) +{ + return explode(",", $code); +} + +function runModule($code) +{ + global $modules; + + $str = ""; + + $m = explode("?", $code); + $module = $m[0]; + $params = getModuleParams($m[1]); + + loadModule($module); + + if($modules[$module]) { + $str .= $modules[$module]->run($params); + } else { + $str .= "<p><strong>CMS ERROR: Could not find module:"; + $str .= " [[" . $modulecode . "]]</strong></p>\n"; + } + + return $str; } ?> diff --git a/utils/modules/discography.php b/utils/modules/discography.php index 478fdc0..fe5a353 100644 --- a/utils/modules/discography.php +++ b/utils/modules/discography.php @@ -1,6 +1,8 @@ <?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +global $UTIL_DIR; + include_once($UTIL_DIR . "/convert.php"); include_once($UTIL_DIR . "/markdown.php"); diff --git a/utils/modules/events.php b/utils/modules/events.php index 8be8f5e..d8631ec 100644 --- a/utils/modules/events.php +++ b/utils/modules/events.php @@ -1,6 +1,8 @@ <?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +global $UTIL_DIR; + include_once($UTIL_DIR . "/convert.php"); include_once($UTIL_DIR . "/markdown.php"); diff --git a/utils/modules/gallery.php b/utils/modules/gallery.php index 308f10a..6b2f384 100644 --- a/utils/modules/gallery.php +++ b/utils/modules/gallery.php @@ -1,6 +1,8 @@ <?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +global $UTIL_DIR; + include_once($UTIL_DIR . "/convert.php"); function isJpeg($file) diff --git a/utils/modules/guestbook.php b/utils/modules/guestbook.php index 45fb4c5..2d5db8a 100644 --- a/utils/modules/guestbook.php +++ b/utils/modules/guestbook.php @@ -1,5 +1,8 @@ <?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +global $UTIL_DIR; + include_once($UTIL_DIR . "/forms.php"); include_once($UTIL_DIR . "/convert.php"); diff --git a/utils/modules/icons.php b/utils/modules/icons.php index 3a9d716..d916ec4 100644 --- a/utils/modules/icons.php +++ b/utils/modules/icons.php @@ -1,5 +1,8 @@ <?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +global $UTIL_DIR; + include_once($UTIL_DIR . "/modules.php"); class Icon { diff --git a/utils/modules/members.php b/utils/modules/members.php index fcc627c..c1822d2 100644 --- a/utils/modules/members.php +++ b/utils/modules/members.php @@ -1,6 +1,8 @@ <?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +global $UTIL_DIR; + include_once($UTIL_DIR . "/convert.php"); include_once($UTIL_DIR . "/forms.php"); include_once($UTIL_DIR . "/markdown.php"); diff --git a/utils/modules/news.php b/utils/modules/news.php index d4eee3e..75cb748 100644 --- a/utils/modules/news.php +++ b/utils/modules/news.php @@ -1,6 +1,8 @@ <?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +global $UTIL_DIR, $MODULES_DIR; + include_once($UTIL_DIR . "/convert.php"); include_once($UTIL_DIR . "/forms.php"); include_once($UTIL_DIR . "/user.php"); @@ -28,10 +30,13 @@ class NewsEntry { $str = "<div class=\"news_entry\">\n"; $str .= " <div class=\"news_title\">" . htmlspecialchars_decode($this->title, ENT_QUOTES) . "</div>\n"; - $str .= " <div class=\"news_time\">" . date("D M jS Y G:i", $this->time) . "</div>\n"; - $str .= " <div class=\"news_user\">By: " . $users->findUser($this->userid)->userid . "</div>\n"; + $str .= " <div class=\"news_time\">" . + date("D M jS Y G:i", $this->time) . "</div>\n"; + $str .= " <div class=\"news_user\">By: " . + $users->findUser($this->userid)->userid . "</div>\n"; $str .= " <div class=\"news_description\">\n"; - if($this->icon) $str .= " <img alt=\"icon\" class=\"news_icon\" src=\"" . $icon->prefix.$icon->file . "\"/>\n"; + if($this->icon) $str .= " <img alt=\"icon\" class=\"news_icon\" src=\"" . + $icon->prefix.$icon->file . "\"/>\n"; $str .= " ".$content. "\n"; $str .= " </div>\n"; $str .= "</div>\n"; @@ -56,7 +61,8 @@ class NewsEntry { return $this->title; } - public function NewsEntry($title, $time, $category, $description, $userid, $icon) + public function NewsEntry($title, $time, $category, + $description, $userid, $icon) { $this->title = $title; $this->time = $time; @@ -84,16 +90,20 @@ class News { switch($action) { case "add": - $n = new NewsEntry($vars["title"], DateTimeEdit::toTimestamp($vars, "time"), - $vars["category"], $vars["description"], $UID, $vars["icon"]); + $n = new NewsEntry($vars["title"], + DateTimeEdit::toTimestamp($vars, "time"), + $vars["category"], $vars["description"], + $UID, $vars["icon"]); echo "\"" .$n->title . "\" has now been added."; $this->add($n); $this->write(); break; case "preview": - $n = new NewsEntry($vars["title"], DateTimeEdit::toTimestamp($vars, "time"), - $vars["category"], $vars["description"], $UID, $vars["icon"]); + $n = new NewsEntry($vars["title"], + DateTimeEdit::toTimestamp($vars, "time"), + $vars["category"], $vars["description"], + $UID, $vars["icon"]); echo "<div class=\"preview\">\n"; echo "<div class=\"content\">\n"; echo $n->show(); @@ -120,9 +130,11 @@ class News { $form = new Form("preview"); $form->addWidget(new LineEdit("Title", "title", $title)); $form->addWidget(new DateTimeEdit("Time", "time", $time)); - $form->addWidget(new ComboBox("Category", "category", $category, array("Main" => "main", "Site" => "site"))); + $form->addWidget(new ComboBox("Category", "category", $category, + array("Main" => "main", "Site" => "site"))); $form->addWidget(new TextEdit("Description", "description", $description)); - $form->addWidget(new ImageComboBox("Icon", "icon", $icon, new Icons($ICONS_DIR."/"))); + $form->addWidget(new ImageComboBox("Icon", "icon", $icon, + new Icons($ICONS_DIR."/"))); $form->addWidget(new Button("Post news")); $form->render(); break; @@ -146,7 +158,8 @@ class News { break; case "preview": - $n = new NewsEntry($vars["title"], DatetimeEdit::toTimestamp($vars, "time"), $vars["category"], $vars["description"], $UID, $vars["icon"]); + $n = new NewsEntry($vars["title"], DatetimeEdit::toTimestamp($vars, "time"), + $vars["category"], $vars["description"], $UID, $vars["icon"]); echo "<div class=\"preview\">\n"; echo "<div class=\"content\">\n"; echo $n->show(); diff --git a/utils/modules/pages.php b/utils/modules/pages.php index 99c8142..d3ee0aa 100644 --- a/utils/modules/pages.php +++ b/utils/modules/pages.php @@ -1,6 +1,8 @@ <?php /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +global $UTIL_DIR; + include_once($UTIL_DIR . "/convert.php"); include_once($UTIL_DIR . "/markdown.php"); include_once($UTIL_DIR . "/modules.php"); @@ -26,17 +28,7 @@ class Page { $modulecodes = array_unique($res[1]); foreach($modulecodes as $modulecode) { - $m = explode("?", $modulecode); - $module = $m[0]; - $params = explode(",", $m[1]); - if($modules[$module]) { - $modulestr = $modules[$module]->run($params); - } else { - $modulestr = "<p><strong>CMS ERROR: Could not find module: [[" . $modulecode . "]]</strong></p>"; - } - - $str = str_replace("[[" . $modulecode . "]]", $modulestr, $str); - + $str = str_replace("[[" . $modulecode . "]]", runModule($modulecode), $str); } } |