summaryrefslogtreecommitdiff
path: root/utils/pages.php
diff options
context:
space:
mode:
authordeva <deva>2008-10-24 10:20:04 +0000
committerdeva <deva>2008-10-24 10:20:04 +0000
commit96b8bc5ff5882f33114137d6b07db32e17b8ad87 (patch)
tree24ee6be2390627fc005b0e2ec12829c0fc5aef47 /utils/pages.php
parent9bca27c9342bd4f34bed77dd3eb8c51dd686cdf1 (diff)
Did a lot of work on the page and module systems.
Diffstat (limited to 'utils/pages.php')
-rw-r--r--utils/pages.php101
1 files changed, 101 insertions, 0 deletions
diff --git a/utils/pages.php b/utils/pages.php
new file mode 100644
index 0000000..60156b8
--- /dev/null
+++ b/utils/pages.php
@@ -0,0 +1,101 @@
+<?php
+
+include_once("convert.php");
+include_once($UTIL_DIR . "/markdown.php");
+include_once($UTIL_DIR . "/modules.php");
+
+class Page {
+ public $title;
+ public $content;
+
+ public function write($fp)
+ {
+ fwrite($fp, " <page title=\"" .
+ htmlspecialchars($this->title, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " content=\"" .
+ htmlspecialchars($this->content, ENT_QUOTES, "UTF-8") . "\">\n");
+ fwrite($fp, " </page>\n");
+ }
+
+ public function show()
+ {
+ global $DATA_DIR, $modules;
+
+ $str = Markdown($this->content);
+
+ if(preg_match_all("/\[\[([a-zA-Z0-9_]+)\]\]/", $str, $res)) {
+
+ $modulecodes = array_unique($res[1]);
+ foreach($modulecodes as $modulecode) {
+ if($modules[$modulecode]) {
+ $modulestr = $modules[$modulecode]->run($modulecode);
+ } else {
+ $modulestr = "<p><strong>CMS ERROR: Could not find module: [[" . $modulecode . "]]</strong></p>";
+ }
+
+ $str = str_replace("[[" . $modulecode . "]]", $modulestr, $str);
+
+ }
+ }
+
+ echo $str;
+ }
+
+ public function Page($title, $content)
+ {
+ $this->title = $title;
+ $this->content = $content;
+ }
+}
+
+class Pages {
+
+ private $file;
+ private $pages = array();
+
+ public function getPage($title)
+ {
+ return $this->pages[$title];
+ }
+
+ public function add($page) {
+ $key = $page->title;
+ $this->pages[$key] = $page;
+ }
+
+ public function write()
+ {
+ $fp = fopen($this->file, "w");
+ fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+
+ fwrite($fp, "<pages>\n");
+ foreach($this->pages as $page) {
+ $page->write($fp);
+ }
+ fwrite($fp, "</pages>\n");
+
+ fclose($fp);
+ }
+
+ private function read()
+ {
+ $dom = new DomDocument;
+ $dom->preserveWhiteSpace = TRUE;
+ $dom->load($this->file);
+ $pages = $dom->getElementsByTagName('page');
+
+ foreach ($pages as $p) {
+ $page = new Page($p->getAttribute('title'),
+ $p->textContent);
+ $this->add($page);
+ }
+ }
+
+ public function Pages($file)
+ {
+ $this->file = $file;
+ if(file_exists($file)) $this->read();
+ }
+
+}
+?> \ No newline at end of file