summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2010-02-11 19:53:35 +0000
committerdeva <deva>2010-02-11 19:53:35 +0000
commit5b90e2158808ce4b17510ca4835a4e4af337b9c1 (patch)
tree8f9394575fd2d2081ef82958119235933914fc58
parentd2e5170c02c7d88053bf081da3e9deaf1eb4522e (diff)
First attempt on a downloads/media module.
-rw-r--r--utils/modules/downloads.php311
1 files changed, 311 insertions, 0 deletions
diff --git a/utils/modules/downloads.php b/utils/modules/downloads.php
new file mode 100644
index 0000000..1356fc1
--- /dev/null
+++ b/utils/modules/downloads.php
@@ -0,0 +1,311 @@
+<?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");
+
+class DownloadSource {
+ public $id;
+ public $title;
+ public $url;
+
+ public function write($fp)
+ {
+ /*
+ fwrite($fp, " <shopitem title=\"" .
+ htmlspecialchars($this->title, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " description=\"" .
+ htmlspecialchars($this->description, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " image=\"" . $this->image . "\">\n");
+
+ fwrite($fp, " type=\"" . $this->type . "\"\n");
+ fwrite($fp, " paypalkey=\"" . $this->paypalkey . "\">\n");
+ fwrite($fp, " </shopitem>\n");
+ */
+ }
+
+ public function show()
+ {
+ $str = "";
+
+ $str .= " <a class=\"download_item_source\" href=\"" . $this->url . "\">\n";
+ $str .= " <span class=\"download_item_source_title\">". $this->title . "</span>\n";
+ $str .= " </a>\n";
+
+ return $str;
+ }
+
+ public function DownloadSource($id, $title, $url)
+ {
+ $this->id = $id;
+ $this->title = $title;
+ $this->url = $url;
+ }
+}
+
+class DownloadItem {
+ public $id;
+ public $title;
+ public $description;
+ public $type;
+ public $value;
+ public $sources = array();
+
+ public function write($fp)
+ {
+ /*
+ fwrite($fp, " <shopitem title=\"" .
+ htmlspecialchars($this->title, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " description=\"" .
+ htmlspecialchars($this->description, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " image=\"" . $this->image . "\">\n");
+
+ fwrite($fp, " type=\"" . $this->type . "\"\n");
+ fwrite($fp, " paypalkey=\"" . $this->paypalkey . "\">\n");
+ fwrite($fp, " </shopitem>\n");
+ */
+ }
+
+ public function show()
+ {
+ global $VIDEO_WIDTH;
+ global $VIDEO_HEIGHT;
+
+ $VIDEO_WIDTH = 530;
+ $VIDEO_HEIGHT = 400;
+
+ $str = "";
+
+ $str .= " <div class=\"download_item\">\n";
+ $str .= " <span class=\"download_item_title\">".$this->title."</span>\n";
+
+ if($this->type == "image") {
+ $str .= " <img class=\"download_item_image\" alt=\"".$this->title.
+ "\" src=\"".$this->value."\"/>\n";
+ }
+
+ if($this->type == "youtube") {
+ $str .= "<object width=\"".$VIDEO_WIDTH."\" height=\"".$VIDEO_HEIGHT."\">\n";
+ $str .= "<param name=\"movie\" value=\"http://www.youtube.com/v/".$this->value."\"></param>\n";
+ $str .= "<embed src=\"http://www.youtube.com/v/".$this->value."\" ".
+ "type=\"application/x-shockwave-flash\" width=\"".$VIDEO_WIDTH."\" height=\"400\">\n";
+ $str .= "</embed>\n";
+ $str .= "</object>\n";
+ }
+
+ if($this->type == "vimeo") {
+ $str .= "<object width=\"".$VIDEO_WIDTH."\" height=\"".$VIDEO_HEIGHT."\">\n";
+ $str .= " <param name=\"allowfullscreen\" value=\"true\" /> \n";
+ $str .= " <param name=\"allowscriptaccess\" value=\"always\" />\n";
+ $str .= " <param name=\"movie\" value=\"http://www.vimeo.com/moogaloop.swf?clip_id=".$this->value."&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\" /> \n";
+ $str .= " <embed src=\"http://www.vimeo.com/moogaloop.swf?clip_id=".$this->value."&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1\"\n";
+ $str .= " type=\"application/x-shockwave-flash\"\n";
+ $str .= " allowfullscreen=\"true\"\n";
+ $str .= " allowscriptaccess=\"always\"\n";
+ $str .= " width=\"".$VIDEO_WIDTH."\" height=\"".$VIDEO_HEIGHT."\"> \n";
+ $str .= " </embed> \n";
+ $str .= "</object>\n";
+ }
+
+ $str .= " <div class=\"download_item_description\">".$this->description."</div>\n";
+ $str .= " <div class=\"download_item_sources\">\n";
+ foreach($this->sources as $s) {
+ $str .= $s->show();
+ }
+ $str .= " </div>\n";
+ $str .= " </div>\n";
+
+ return $str;
+ }
+
+ public function addSource($source)
+ {
+ $key = $source->id;
+ $this->sources[$key] = $source;
+ }
+
+ public function DownloadItem($id, $title, $description, $type, $value)
+ {
+ $this->id = $id;
+ $this->title = $title;
+ $this->description = $description;
+ $this->type = $type;
+ $this->value = $value;
+ }
+}
+
+class DownloadGroup {
+ public $id;
+ public $title;
+ public $items = array();
+
+ public function write($fp)
+ {
+ /*
+ fwrite($fp, " <shopitem title=\"" .
+ htmlspecialchars($this->title, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " description=\"" .
+ htmlspecialchars($this->description, ENT_QUOTES, "UTF-8") . "\"\n");
+ fwrite($fp, " image=\"" . $this->image . "\">\n");
+
+ fwrite($fp, " type=\"" . $this->type . "\"\n");
+ fwrite($fp, " paypalkey=\"" . $this->paypalkey . "\">\n");
+ fwrite($fp, " </shopitem>\n");
+ */
+ }
+
+ public function show()
+ {
+ $str = "";
+
+
+ $str .= " <div class=\"download_group\">\n";
+ $str .= " <span class=\"download_group_title\">".$this->title."</span>\n";
+ $str .= " <div class=\"download_items\">\n";
+ if($this->items) {
+ foreach($this->items as $i) {
+ $str .= $i->show();
+ }
+ }
+ $str .= " </div>\n";
+ $str .= " </div>\n";
+
+ return $str;
+ }
+
+ public function addItem($item)
+ {
+ $key = $item->id;
+ $this->items[$key] = $item;
+ }
+
+ public function DownloadGroup($id, $title)
+ {
+ $this->id = $id;
+ $this->title = $title;
+ $this->url = $url;
+ }
+}
+
+class Downloads {
+
+ private $file;
+ private $groups = array();
+
+ // Admin config
+ public $admin_title = "Downloads";
+ public $admin_submodules = array("Add Item" => "add",
+ "Edit Item" => "edit",
+ "Delete Item" => "delete");
+
+ public function admin($sub, $action, $vars)
+ {
+ switch($sub) {
+ case "add":
+ break;
+ case "edit":
+ break;
+ case "delete":
+ break;
+ }
+ }
+
+ public function run($params)
+ {
+ global $GLOBALS;
+
+ $str = "<div class=\"downloads\">\n";
+
+ //foreach($params as $param => $value) {}
+
+ if($this->groups) {
+ foreach($this->groups as $group) {
+ $str .= $group->show();
+ }
+ }
+
+ $str .= "</div>\n";
+
+ return $str;
+ }
+
+ public function add($group) {
+ $key = $group->id;
+ $this->groups[$key] = $group;
+ }
+
+ public function write()
+ {
+ /*
+ $fp = fopen($this->file, "w");
+ fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+
+ fwrite($fp, "<discography>\n");
+ foreach($this->discs as $disc) {
+ $disc->write($fp);
+ }
+ fwrite($fp, "</discography>\n");
+
+ fclose($fp);
+ */
+ }
+
+ private function read()
+ {
+ $dom = new DomDocument;
+ $dom->preserveWhiteSpace = FALSE;
+ $dom->load($this->file);
+ $groups = $dom->getElementsByTagName('group');
+
+ if($groups) {
+ foreach($groups as $g) {
+ $group = new DownloadGroup($g->getAttribute('id'),
+ $g->getAttribute('title'));
+
+ $items = $g->getElementsByTagName('item');
+ if($items) {
+ foreach($items as $i) {
+ $item = new DownloadItem($i->getAttribute('id'),
+ $i->getAttribute('title'),
+ $i->getAttribute('description'),
+ $i->getAttribute('type'),
+ $i->getAttribute('value'));
+ $sources = $i->getElementsByTagName('source');
+ if($sources) {
+ foreach($sources as $s) {
+ $source = new DownloadSource($s->getAttribute('id'),
+ $s->getAttribute('title'),
+ $s->getAttribute('url'));
+ $item->addSource($source);
+ }
+ }
+
+ ksort($item->sources);
+ $group->addItem($item);
+ }
+ }
+
+ ksort($group->items);
+ $this->add($group);
+ }
+ }
+ ksort($this->groups);
+ }
+
+ public function Downloads($file)
+ {
+ $this->file = $file;
+ if(file_exists($file)) $this->read();
+ }
+
+}
+
+function downloads_init()
+{
+ global $DATA_DIR;
+ return new Downloads($DATA_DIR . "/downloads.xml");
+}
+
+?>