From 24e070a294aba51f85bc0120fd25e16426347d64 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 25 Jan 2010 15:44:05 +0000 Subject: Added links module (no admin yet...) --- utils/links.php | 128 ------------------------------------- utils/modules/links.php | 164 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 164 insertions(+), 128 deletions(-) delete mode 100644 utils/links.php create mode 100644 utils/modules/links.php diff --git a/utils/links.php b/utils/links.php deleted file mode 100644 index d9ed1d9..0000000 --- a/utils/links.php +++ /dev/null @@ -1,128 +0,0 @@ -title = $title; - $this->href = $href; - $this->icon = $icon; - } - - public function show() - { - echo "
\n"; - if($this->icon != "") { - echo " href . "\">\n"; - echo " \""title . "\" src=\"" . $this->icon . "\"/>\n"; - echo " \n"; - } - echo " href . "\">\n"; - echo " " . htmlspecialchars_decode($this->title, ENT_QUOTES) . "\n"; - echo " \n"; - echo "
\n"; - } -} - -class LinkGroup { - public $title; - public $id; - private $links = array(); - - public function LinkGroup($title, $id) { - $this->title = $title; - $this->id = $id; - } - - public function add($link) { - $key = $link->title; - $this->links[$key] = $link; - } - - public function show() - { - echo "
\n"; - echo "
". htmlspecialchars_decode($this->title, ENT_QUOTES) . "
\n"; - foreach($this->links as $link) { - $link->show(); - } - echo "
\n"; - } -} - -class Links { - private $file; - private $groups = array(); - - public function add($group) { - $key = $group->title; - $this->groups[$key] = $group; - } - /* - public function write() - { - $fp = fopen($this->file, "w"); - fwrite($fp, "\n"); - - fwrite($fp, "\n"); - foreach($this->links as $link) { - fwrite($fp, " title, ENT_QUOTES, "UTF-8") . "\"\n"); - fwrite($fp, " href=\"" . - htmlspecialchars($link->href, ENT_QUOTES, "UTF-8") . "\">\n"); - fwrite($fp, " icon=\"" . - htmlspecialchars($link->icon, ENT_QUOTES, "UTF-8") . "\">\n"); - fwrite($fp, " \n"); - } - fwrite($fp, "\n"); - - fclose($fp); - } - */ - public function show($groupid) - { - foreach($this->groups as $group) { - if($groupid == $group->id || $groupid == "all") $group->show(); - } - } - - private function read() - { - - $dom = new DomDocument; - $dom->preserveWhiteSpace = FALSE; - $dom->load($this->file); - - $xmlgroups = $dom->getElementsByTagName('group'); - - foreach ($xmlgroups as $xmlgroup) { - - $group = new LinkGroup($xmlgroup->getAttribute('name'), - $xmlgroup->getAttribute('id')); - $xmllinks = $xmlgroup->getElementsByTagName('link'); - - foreach ($xmllinks as $xmllink) { - $link = new Link($xmllink->getAttribute('title'), - $xmllink->getAttribute('href'), - $xmllink->getAttribute('icon')); - - $group->add($link); - } - - $this->add($group); - } - - // Key sort - // ksort($this->events); - } - - public function Links($file) - { - $this->file = $file; - if(file_exists($file)) $this->read(); - } -} - -?> \ No newline at end of file diff --git a/utils/modules/links.php b/utils/modules/links.php new file mode 100644 index 0000000..cf0cfed --- /dev/null +++ b/utils/modules/links.php @@ -0,0 +1,164 @@ +title = $title; + $this->href = $href; + $this->icon = $icon; + } + + public function show() + { + $str = ""; + + $str .= "
\n"; + if($this->icon != "") { + $str .= " href . "\">\n"; + $str .= " \""title . "\" src=\"" . $this->icon . "\"/>\n"; + $str .= " \n"; + } + $str .= " href . "\">\n"; + $str .= " " . htmlspecialchars_decode($this->title, ENT_QUOTES) . "\n"; + $str .= " \n"; + $str .= "
\n"; + + return $str; + } +} + +class LinkGroup { + public $title; + public $id; + private $links = array(); + + public function LinkGroup($title, $id) { + $this->title = $title; + $this->id = $id; + } + + public function add($link) { + $key = $link->title; + $this->links[$key] = $link; + } + + public function show() + { + $str = ""; + $str .= "
\n"; + $str .= "
". + htmlspecialchars_decode($this->title, ENT_QUOTES) . "
\n"; + foreach($this->links as $link) { + $str .= $link->show(); + } + $str .= "
\n"; + return $str; + } +} + +class Links { + private $file; + private $groups = array(); + + public function add($group) { + $key = $group->title; + $this->groups[$key] = $group; + } + + /* + public function write() + { + $fp = fopen($this->file, "w"); + fwrite($fp, "\n"); + + fwrite($fp, "\n"); + foreach($this->links as $link) { + fwrite($fp, " title, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " href=\"" . + htmlspecialchars($link->href, ENT_QUOTES, "UTF-8") . "\">\n"); + fwrite($fp, " icon=\"" . + htmlspecialchars($link->icon, ENT_QUOTES, "UTF-8") . "\">\n"); + fwrite($fp, " \n"); + } + fwrite($fp, "\n"); + + fclose($fp); + } + */ + // public function show($groupid) + public function run($params) + { + $str = ""; + + $groupid = "all"; + + foreach($params as $param) { + if(!$param) continue; + switch($param) { + case "all": + $groupid = "all"; + break; + + default: + $groupid = $param; + break; + } + } + + $str .= "
\n"; + foreach($this->groups as $group) { + if($groupid == $group->id || $groupid == "all") $str .= $group->show(); + } + $str .= "
\n"; + + return $str; + } + + private function read() + { + + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + + $xmlgroups = $dom->getElementsByTagName('group'); + + foreach ($xmlgroups as $xmlgroup) { + + $group = new LinkGroup($xmlgroup->getAttribute('name'), + $xmlgroup->getAttribute('id')); + $xmllinks = $xmlgroup->getElementsByTagName('link'); + + foreach ($xmllinks as $xmllink) { + $link = new Link($xmllink->getAttribute('title'), + $xmllink->getAttribute('href'), + $xmllink->getAttribute('icon')); + + $group->add($link); + } + + $this->add($group); + } + + // Key sort + // ksort($this->events); + } + + public function Links($file) + { + $this->file = $file; + if(file_exists($file)) $this->read(); + } +} + +function links_init() +{ + global $DATA_DIR; + return new Links($DATA_DIR . "/links.xml"); +} + +?> \ No newline at end of file -- cgit v1.2.3