From 42c62cb041a2b2b95c9cda0c20fcf70334fd244c Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 1 Nov 2011 09:32:21 +0000 Subject: Rewl og krat... needs cleaning up - after port to GIT. --- utils/modules/reviews.php | 221 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 utils/modules/reviews.php (limited to 'utils/modules/reviews.php') diff --git a/utils/modules/reviews.php b/utils/modules/reviews.php new file mode 100644 index 0000000..8fa97b5 --- /dev/null +++ b/utils/modules/reviews.php @@ -0,0 +1,221 @@ +original) $prefix = "Translated"; + + $str .= "

".$prefix." ".lang2text($this->lang)." text

\n"; + $str .= markdown($this->text) . "\n"; + return $str; + } + + public function Text($text, $lang, $original) + { + $this->text = $text; + $this->lang = $lang; + $this->original = $original; + } +} + +class Review { + public $title; + public $id; + public $src; + public $url; + public $texts = array(); + + public function write($fp) + { +/* + fwrite($fp, " title, ENT_QUOTES, "UTF-8") . "\"\n"); + fwrite($fp, " number=\"" . $this->number . "\"\n"); + fwrite($fp, " playtime=\"" . $this->playtime . "\"\n"); + fwrite($fp, " previewurl=\"" . $this->previewurl . "\">\n"); + fwrite($fp, " ".htmlspecialchars($this->lyrics, ENT_QUOTES, "UTF-8")."\n"); + fwrite($fp, " \n"); +*/ + } + + public function show() + { + $str = ""; + + // $str .= $this->id . "\n"; + $str .= "

".$this->title."

\n"; + $str .= "

Origin: ".$this->src." url."\">".$this->url."

\n"; + + foreach($this->texts as $text) { + if($text->original) { + $str .= $text->show(); + break; + } + } + + foreach($this->texts as $text) { + if(!$text->original) { + $str .= $text->show(); + } + } + + return $str; + } + + public function showRef() + { + $str = ""; + $str .= "id."\">".$this->title." from ".$this->src."\n"; + return $str; + } + + public function add($text) + { + array_push($this->texts, $text); + } + + public function Review($id, $title, $src, $url) + { + $this->id = $id; + $this->title = $title; + $this->src = $src; + $this->url = $url; + } +} + +class Reviews { + + private $file; + private $reviews = array(); + + // Admin config + public $admin_title = "Reviews"; + public $admin_submodules = array(); + + public function admin($sub, $action, $vars) + { + switch($sub) { + case "delete": + break; + } + } + + public function run($params) + { + global $GLOBALS; + $str = ""; + foreach($this->reviews as $review) { + if($GLOBALS['rid'] == $review->id) { + $str .= $review->show(); + } + } + + return $str; + } + + public function get($id) + { + return $this->reviews[$id]; + } + + public function showRef($id) + { + if(!$this->reviews[$id]) return ""; + return $this->reviews[$id]->showRef(); + } + + public function add($review) { + $key = $review->id; + $this->reviews[$key] = $review; + } + + public function write() + { + /* + $fp = fopen($this->file, "w"); + fwrite($fp, "\n"); + + fwrite($fp, "\n"); + foreach($this->discs as $disc) { + $disc->write($fp); + } + fwrite($fp, "\n"); + + fclose($fp); + */ + } + + private function read() + { + $dom = new DomDocument; + $dom->preserveWhiteSpace = FALSE; + $dom->load($this->file); + + $discography = $dom->documentElement; + + $revs = $dom->getElementsByTagName('review'); + + foreach($revs as $rev) { + $review = new Review($rev->getAttribute('id'), + $rev->getAttribute('title'), + $rev->getAttribute('src'), + $rev->getAttribute('url')); + + $ts = $rev->getElementsByTagName('text'); + foreach($ts as $t) { + $text = new Text($t->textContent, + $t->getAttribute('lang'), + $t->getAttribute('original')); + $review->add($text); + } + + $this->add($review); + } + } + + public function Reviews($file) + { + $this->file = $file; + if(file_exists($file)) $this->read(); + } + +} + +function reviews_init() +{ + global $DATA_DIR; + return new Reviews($DATA_DIR . "/reviews.xml"); +} + +?> -- cgit v1.2.3