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/admin.php | 4 +- utils/forms.php | 66 ++++-- utils/imagecache.php | 56 +++-- utils/mail.php | 4 +- utils/modules.php | 4 +- utils/modules/config.php | 23 +- utils/modules/discography.php | 480 +++++++++++++++++++++++++----------------- utils/modules/downloads.php | 33 ++- utils/modules/events.php | 47 ++++- utils/modules/gallery.php | 131 +++++++++++- utils/modules/guestbook.php | 2 +- utils/modules/members.php | 3 +- utils/modules/reviews.php | 221 +++++++++++++++++++ utils/refs.php | 139 ++++++++++++ 14 files changed, 955 insertions(+), 258 deletions(-) create mode 100644 utils/modules/reviews.php create mode 100644 utils/refs.php (limited to 'utils') diff --git a/utils/admin.php b/utils/admin.php index df3a9df..6b8b8e0 100644 --- a/utils/admin.php +++ b/utils/admin.php @@ -1,6 +1,6 @@
- Admin + Admin findUser($UID); ?> Logout -\n"; + + return $str; } - public function addTrack($track) - { - $key = $track->number; - $this->tracks[$key] = $track; - } + public function addTrack($track) + { + $key = $track->number; + $this->tracks[$key] = $track; + } + /* + public function addReview($review) + { + $key = $review->id; + $this->reviews[$key] = $review; + } + */ + + public function addRefs($refs) + { + $this->refs = $refs; + } public function Disc($title, $releasetime, $description, $cover, $releaser) { @@ -195,8 +252,8 @@ class Discography { // Admin config public $admin_title = "Discography"; public $admin_submodules = array("Add Disc" => "add", - "Edit Disc" => "edit", - "Delete Disc" => "delete"); + "Edit Disc" => "edit", + "Delete Disc" => "delete"); public function admin($sub, $action, $vars) { switch($sub) { @@ -211,36 +268,55 @@ class Discography { public function run($params) { - global $GLOBALS; + global $GLOBALS; - $str = "
\n"; + $str = "
\n"; - $lyrics = $GLOBALS["lyrics"]; - $number = $GLOBALS["track"]; + foreach($params as $param => $value) { + switch($param) { + case "latest": + $id = -1; + foreach($this->discs as $disc) { + if($disc->releasetime > $id) $id = $disc->releasetime; + } + if($id != -1) { + $disc = $this->discs[$id]; + return $str .= $disc->showCompact(); + } + break; + + default: + $lyrics = $GLOBALS["lyrics"]; + $number = $GLOBALS["track"]; + + //foreach($params as $param => $value) {} + + if($lyrics && $number) { + if($this->discs) { + foreach($this->discs as $disc) { + if($disc->releasetime == $lyrics) { + $str .= $disc->showLyrics($number); + break; + } + } + } + } else { + if($this->discs) { + foreach($this->discs as $disc) { + $str .= $disc->show(); + } + } + } - //foreach($params as $param => $value) {} + break; + } + } - if($lyrics && $number) { - if($this->discs) { - foreach($this->discs as $disc) { - if($disc->releasetime == $lyrics) { - $str .= $disc->showLyrics($number); - break; - } - } - } - } else { - if($this->discs) { - foreach($this->discs as $disc) { - $str .= $disc->show(); - } - } - } - $str .= "
\n"; + $str .= "
\n"; - return $str; + return $str; } public function add($disc) { @@ -248,15 +324,18 @@ class Discography { $this->discs[$key] = $disc; } - public function getImageSize($cat) - { - switch($cat) { - case "cover": - return new ImageSize($this->coverwidth, $this->coverheight); - default: - die(404); - } - } + public function getImageSize($cat) + { + switch($cat) { + case "cover": + return new ImageSize($this->coverwidth, $this->coverheight, true); + case "compactcover": + // return new ImageSize($this->compactcoverwidth, $this->compactcoverheight, true); + return new ImageSize(150, 150, true); + default: + die(404); + } + } public function write() { @@ -265,7 +344,7 @@ class Discography { fwrite($fp, "\n"); foreach($this->discs as $disc) { - $disc->write($fp); + $disc->write($fp); } fwrite($fp, "\n"); @@ -274,32 +353,34 @@ class Discography { private function read() { + $reviews = loadModule("reviews"); + $dom = new DomDocument; $dom->preserveWhiteSpace = FALSE; $dom->load($this->file); - $discography = $dom->documentElement; + $discography = $dom->documentElement; - $this->coverwidth = $discography->getAttribute('coverwidth'); - $this->coverheight = $discography->getAttribute('coverheight'); + $this->coverwidth = $discography->getAttribute('coverwidth'); + $this->coverheight = $discography->getAttribute('coverheight'); $discs = $dom->getElementsByTagName('disc'); foreach($discs as $d) { - $description = ""; - $dess = $d->getElementsByTagName('description'); - foreach($dess as $des) { + $description = ""; + $dess = $d->getElementsByTagName('description'); + foreach($dess as $des) { $description = $des->textContent; - } + } $disc = new Disc($d->getAttribute('title'), - $d->getAttribute('releasetime'), - $description, - $d->getAttribute('cover'), - $d->getAttribute('releaser')); + $d->getAttribute('releasetime'), + $description, + $d->getAttribute('cover'), + $d->getAttribute('releaser')); - $tracks = $d->getElementsByTagName('track'); - foreach($tracks as $t) { + $tracks = $d->getElementsByTagName('track'); + foreach($tracks as $t) { $lyrics = ""; $ls = $t->getElementsByTagName('lyrics'); foreach($ls as $l) { @@ -311,9 +392,16 @@ class Discography { $t->getAttribute('playtime'), $t->getAttribute('previewurl'), $lyrics); - + $disc->addTrack($track); - } + } + + $rs = $d->getElementsByTagName('refs'); + foreach($rs as $r) { + $refs = new Refs($r); + $disc->addRefs($refs); + break; + } $this->add($disc); } diff --git a/utils/modules/downloads.php b/utils/modules/downloads.php index 99e9962..52c6736 100644 --- a/utils/modules/downloads.php +++ b/utils/modules/downloads.php @@ -68,6 +68,21 @@ class DownloadItem { */ } + public function showRef() + { + $str = ""; + + if($this->type == "youtube") { + $str .= "value."\">Video: " . $this->title.""; + } + + if($this->type == "vimeo") { + $str .= "value."\">Video: " . $this->title.""; + } + + return $str; + } + public function show() { global $VIDEO_WIDTH; @@ -254,6 +269,20 @@ class Downloads { */ } + public function showRef($id) + { + $bleh = explode(",", $id); + $gid = $bleh[0]; + $iid = $bleh[1]; + + $str = ""; + if($this->groups[$gid] && $this->groups[$gid]->items[$iid]) { + $str .= $this->groups[$gid]->items[$iid]->showRef(); + } + + return $str; + } + private function read() { $dom = new DomDocument; @@ -284,12 +313,12 @@ class Downloads { } } - ksort($item->sources); + // ksort($item->sources); $group->addItem($item); } } - ksort($group->items); + // ksort($group->items); $this->add($group); } } diff --git a/utils/modules/events.php b/utils/modules/events.php index 3bccce6..1bfcd5c 100644 --- a/utils/modules/events.php +++ b/utils/modules/events.php @@ -5,20 +5,23 @@ global $UTIL_DIR, $MODULES_DIR; include_once($UTIL_DIR . "/convert.php"); include_once($UTIL_DIR . "/markdown.php"); include_once($MODULES_DIR . "/icons.php"); +include_once($UTIL_DIR . "/refs.php"); class Event { public $title; public $time; public $description; public $flyer; + public $refs; public function write($fp) { fwrite($fp, " title) . "\"\n"); fwrite($fp, " time=\"" . xmlenc($this->time) . "\"\n"); - fwrite($fp, " flyer=\"" . xmlenc($this->flyer) . "\">"); - fwrite($fp, xmlenc($this->description)); - fwrite($fp, "\n"); + fwrite($fp, " flyer=\"" . xmlenc($this->flyer) . "\">\n"); + fwrite($fp, " ".xmlenc($this->description)."\n"); + if($this->refs) $this->refs->write($fp, " "); + fwrite($fp, " \n"); } public function show($eventpage) @@ -40,10 +43,17 @@ class Event { $str .= " \"flyer\"prefix.$icon->file."\"/>\n"; } */ + if($this->refs) $str .= $this->refs->show(); + $str .= "
\n"; return $str; } + public function addRefs($refs) + { + $this->refs = $refs; + } + public function Event($title, $time, $description, $flyer = "") { $this->title = $title; @@ -144,6 +154,8 @@ class Events { $this->events[$vars["eventid"]]->time = DateTimeEdit::toTimestamp($vars, "time"); $this->events[$vars["eventid"]]->description = $vars["description"]; $this->events[$vars["eventid"]]->flyer = $vars["icon"]; + $refs = refsGetRefsFromHidden($vars); + $this->events[$vars["eventid"]]->refs = $refs; $this->write(); echo "\"" . $this->events[$vars["eventid"]]->title . "\" has now been edited."; break; @@ -151,6 +163,9 @@ class Events { case "preview": $event = new Event($vars["title"], DatetimeEdit::toTimestamp($vars, "time"), $vars["description"], $vars["icon"]); + $refs = refsGetRefsFromWidget(); + $event->addRefs($refs); + echo "
\n"; echo "
\n"; echo $event->show($this->eventpage); @@ -159,11 +174,13 @@ class Events { echo "

Looking ok?

"; $form = new Form("add"); $form->addWidget(new Hidden($vars)); + refsAddHiddenWidget($form, $refs); $form->addWidget(new Button("yes")); $form->render(); $form = new Form("retry"); $form->addWidget(new Hidden($vars)); + refsAddHiddenWidget($form, $refs); $form->addWidget(new Button("no")); $form->render(); break; @@ -178,13 +195,18 @@ class Events { else $description = $this->events[$vars["eventid"]]->description; if(isset($vars["icon"])) $icon = $vars["icon"]; else $icon = $this->events[$vars["eventid"]]->flyer; - + if(isset($vars["refslist_hidden"])) $refs = refsGetFromHidden($vars); + else { + $refs = refsGetCommaListFromRefs($this->events[$vars["eventid"]]->refs); + } + $form = new Form("preview"); $form->addWidget(new Hidden($vars)); $form->addWidget(new LineEdit("Title", "title", $title)); $form->addWidget(new DateTimeEdit("Time", "time", $time)); $form->addWidget(new TextEdit("Description", "description", $description)); $form->addWidget(new ImageComboBox("Icon", "icon", $icon, new Icons($ICONS_DIR."/"))); + refsAddWidget($form, $refs); $form->addWidget(new Button("Update event")); $form->render(); break; @@ -415,10 +437,25 @@ class Events { $this->eventpage = $events->getAttribute('eventpage'); foreach ($params as $param) { + + $description = ""; + $dess = $param->getElementsByTagName('description'); + foreach($dess as $des) { + $description = $des->textContent; + } + $event = new Event($param->getAttribute('title'), $param->getAttribute('time'), - $param->textContent, + $description, $param->getAttribute('flyer')); + + $rs = $param->getElementsByTagName('refs'); + foreach($rs as $r) { + $refs = new Refs($r); + $event->addRefs($refs); + break; + } + $this->add($event); } } diff --git a/utils/modules/gallery.php b/utils/modules/gallery.php index 3915a90..396cfd7 100644 --- a/utils/modules/gallery.php +++ b/utils/modules/gallery.php @@ -58,6 +58,15 @@ class Photo { return $str; } + public function showRef() + { + $str = ""; + $str .= " \"".$this-title."\"\n"; + $str .= " src=\"?mode=imagecache&uri=" + . $this->path . "/" . $this->image . "&mod=gallery&cat=reficon\"/>\n"; + return $str; + } + public function Photo($path, $id, $title, $image) { $this->path = $path; @@ -103,16 +112,33 @@ class Album { { global $page; + if(!$this->enabled) return ""; + $str = ""; $str .= $indent."\n"; + // $str .= $indent."   ← Back to albums\n"; $str .= $indent." " . $this->title . "\n"; + $str .= $indent." Copyright: " . $this->copyright . "\n"; foreach($this->photos as $photo) { $str .= $indent." id."&p=".$photo->id."\">\n"; $str .= $photo->show($indent." ", "albumicon"); $str .= $indent." \n"; } - $str .= $indent."\n"; + $str .= $indent."
  ← Back to albums\n"; + // Back to gallery + /* + $str .= $indent." \n"; + $str .= $indent."\n"; + $str .= $indent." \n"; + $str .= $indent." \"Back\n"; + $str .= $indent." \n"; + $str .= $indent." " . $this->title . "\n"; + $str .= $indent."\n"; + $str .= $indent." \n"; + $str .= $indent."\n"; + */ return $str; } @@ -132,6 +158,20 @@ class Album { return $str; } + public function showRef() + { + global $page; + + $str = ""; + + $str .= $indent."id."\">\n"; + $str .= $this->photos[$this->icon]->showRef() . + " " .$this->title . "\n"; + $str .= $indent."\n"; + + return $str; + } + public function showPhoto($indent, $photo) { global $GLOBALS; @@ -192,7 +232,7 @@ class Album { $this->title = $title; $this->copyright = $copyright; $this->icon = $icon; - $this->enabled = $enabled == 'on'; + $this->enabled = $enabled == "true" || $enabled == "on" || $enabled == "yes"; } } @@ -266,11 +306,20 @@ class Gallery { global $ALBUMS_DIR; switch($action) { case "create": - $album = new Album($this->getNextID(), $vars['title'], $vars['copyright'], "1", $vars['enabled']); + $baseid = $vars['id']; + $id = $baseid; + $idcnt = 1; + while(!$this->checkUniqueID($id)) { + $id = $baseid . "-" . $idcnt; + $idcnt++; + } + + $album = new Album($id, $vars['title'], $vars['copyright'], "1", $vars['enabled']); unpackImages($_FILES['images'], $album); - $this->add($album); + $this->add($album); $this->write(); echo $album->show("", "albumicon"); + break; case "select": @@ -278,7 +327,8 @@ class Gallery { $form = new Form("create"); $form->addWidget(new LineEdit("Album title:", "title")); $form->addWidget(new LineEdit("Album copyright:", "copyright")); - $form->addWidget(new CheckBox("Album enabled:", "enabled")); + $form->addWidget(new LineEdit("Album ID:", "id", $this->getNextID())); + $form->addWidget(new CheckBox("Album enabled:", "enabled")); $form->addWidget(new FileUpload("Select image archive:", "images", "application/zip")); $form->addWidget(new Button("Create")); $form->render(); @@ -286,6 +336,48 @@ class Gallery { } } + public function admin_edit($action, $vars) + { + global $ALBUMS_DIR; + switch($action) { + case "update": + $album = $this->albums[$vars["id"]]; + + $album->title = $vars["title"]; + $album->copyright = $vars["copyright"]; + $album->enabled = $vars["enabled"] == "on"; + + $this->write(); + break; + + case "edit": + $album = $this->albums[$vars["id"]]; + + $form = new Form("update"); + $form->addWidget(new LineEdit("Album title:", "title", $album->title)); + $form->addWidget(new LineEdit("Album copyright:", "copyright", $album->copyright)); + $form->addWidget(new LineEdit("Album ID:", "id", $album->id)); + $form->addWidget(new CheckBox("Album enabled:", "enabled", $album->enabled)); + $form->addWidget(new Button("Update")); + $form->render(); + break; + + case "select": + default: + $albumlist = array(); + foreach($this->albums as $album) { + $albumlist[$album->title . " (".$album->id.")"] = $album->id; + } + krsort($albumlist); + + $form = new Form("edit"); + $form->addWidget(new ComboBox("Select album:", "id", "", $albumlist)); + $form->addWidget(new Button("Edit")); + $form->render(); + break; + } + } + public function admin_options($action, $vars) { switch($action) { @@ -325,7 +417,7 @@ class Gallery { $this->admin_new($action, $vars); break; case "edit": - $this->admin_new($action, $vars); + $this->admin_edit($action, $vars); break; case "delete": $this->admin_new($action, $vars); @@ -356,7 +448,7 @@ class Gallery { $str .= "\n\n"; foreach($this->albums as $album) { - $str .= $album->showIcon(" "); + if($album->enabled) $str .= $album->showIcon(" "); } $str .= "\n"; @@ -374,6 +466,12 @@ class Gallery { return $str; } + public function showRef($id) + { + if(!$this->albums[$id]) return ""; + return $this->albums[$id]->showRef(); + } + public function run($params) { global $a, $p; @@ -413,17 +511,28 @@ class Gallery { return $maxid + 1; } + public function checkUniqueID($id) + { + foreach($this->albums as $album) { + if($album->id == $id) return false; + } + return true; + } + public function getImageSize($cat) { switch($cat) { case "photo": - return new ImageSize($this->maxwidth, $this->maxheight); + return new ImageSize($this->maxwidth, $this->maxheight, false); case "randomimage": - return new ImageSize($this->maxwidth_rand, $this->maxheight_rand); + return new ImageSize($this->maxwidth_rand, $this->maxheight_rand, true); case "navicon": - return new ImageSize($this->maxwidth_navicon, $this->maxheight_navicon); + return new ImageSize($this->maxwidth_navicon, $this->maxheight_navicon, true); case "albumicon": - return new ImageSize($this->maxwidth_icon, $this->maxheight_icon); + return new ImageSize($this->maxwidth_icon, $this->maxheight_icon, true); + case "reficon": + // return new ImageSize($this->maxwidth_reficon, $this->maxheight_reficon, true); + return new ImageSize(32, 24, true); default: die(404); } diff --git a/utils/modules/guestbook.php b/utils/modules/guestbook.php index 92fe732..039cd2c 100644 --- a/utils/modules/guestbook.php +++ b/utils/modules/guestbook.php @@ -339,7 +339,7 @@ class Guestbook { default: if($show == "all") $showposts = -1; - else $showposts = 7; + else $showposts = 12; break; } } diff --git a/utils/modules/members.php b/utils/modules/members.php index 670de53..41f1979 100644 --- a/utils/modules/members.php +++ b/utils/modules/members.php @@ -1,5 +1,4 @@ -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"); +} + +?> diff --git a/utils/refs.php b/utils/refs.php new file mode 100644 index 0000000..0589cff --- /dev/null +++ b/utils/refs.php @@ -0,0 +1,139 @@ +mod); + if($module && method_exists($module, "showRef")) { + $str .= "
\n"; + $str .= /*"[".$this->mod."] - ".*/$module->showRef($this->id); + $str .= "
\n"; + } + return $str; + } + + function Ref($mod, $id) + { + $this->mod = $mod; + $this->id = $id; + } +} + +class Refs { + public $refs = array(); + + function show() + { + $str = ""; + $str .= "
\n"; + $str .= "
References:
\n"; + foreach($this->refs as $ref) { + $str .= $ref->show(); + } + $str .= "
"; + return $str; + } + + public function write($fp, $indent) + { + if($this->refs) { + fwrite($fp, $indent."\n"); + foreach($this->refs as $ref) { + fwrite($fp, $indent." mod."\" id=\"".$ref->id."\"/>\n"); + } + fwrite($fp, $indent."\n"); + } + } + + public function add($ref) + { + array_push($this->refs, $ref); + } + + public function Refs($refsnode = NULL) + { + if(!$refsnode) return; + + $refs = $refsnode->getElementsByTagName('ref'); + foreach($refs as $r) { + $ref = new Ref($r->getAttribute('mod'), + $r->getAttribute('id')); + $this->add($ref); + } + + } + +} + +function refsAddWidget($form, $refslist) +{ + $form->addWidget(new ListEditor("References:", "refslist", + new LineEdit("ID", "ref_id"), + new LineEdit("Module", "ref_mod"), + $refslist, true)); +} + +function refsAddHiddenWidget($form, $lst) +{ + $vallst = array(); + $vallst["refslist_hidden"] = serialize(refsGetCommaListFromRefs($lst)); + $form->addWidget(new Hidden($vallst)); +} + +function refsGetFromHidden($vals) +{ + $refslist = unserialize($vals["refslist_hidden"]); + return $refslist; +} + +function refsGetCommaListFromRefs($refs) +{ + $lst = array(); + foreach($refs->refs as $ref) { + array_push($lst, $ref->mod.":".$ref->id); + } + return $lst; +} + +function refsGetRefsFromHidden($vals) +{ + $r = refsGetFromHidden($vals); + + $refs = new Refs(); + foreach($r as $k => $val) { + $v = explode(":", $val); + $refmod = $v[0]; + $refid = $v[1]; + $ref = new Ref($refmod, $refid); + $refs->add($ref); + } + + return $refs; +} + +function refsGetRefsFromWidget() +{ + $lst = refsGetValuesFromWidget(); + $refs = new Refs(); + foreach($lst as $val) { + $v = explode(":", $val); + $refmod = $v[0]; + $refid = $v[1]; + $ref = new Ref($refmod, $refid); + $refs->add($ref); + } + return $refs; +} + +function refsGetValuesFromWidget() +{ + global $GLOBALS; + return $GLOBALS["refslist"]; +} +?> \ No newline at end of file -- cgit v1.2.3