From 5b90e2158808ce4b17510ca4835a4e4af337b9c1 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 11 Feb 2010 19:53:35 +0000 Subject: First attempt on a downloads/media module. --- utils/modules/downloads.php | 311 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 311 insertions(+) create mode 100644 utils/modules/downloads.php (limited to 'utils/modules/downloads.php') 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 @@ +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, " \n"); + */ + } + + public function show() + { + $str = ""; + + $str .= " url . "\">\n"; + $str .= " ". $this->title . "\n"; + $str .= " \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, " 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, " \n"); + */ + } + + public function show() + { + global $VIDEO_WIDTH; + global $VIDEO_HEIGHT; + + $VIDEO_WIDTH = 530; + $VIDEO_HEIGHT = 400; + + $str = ""; + + $str .= "
\n"; + $str .= " ".$this->title."\n"; + + if($this->type == "image") { + $str .= " \"".$this-title. + "\" src=\"".$this->value."\"/>\n"; + } + + if($this->type == "youtube") { + $str .= "\n"; + $str .= "value."\">\n"; + $str .= "value."\" ". + "type=\"application/x-shockwave-flash\" width=\"".$VIDEO_WIDTH."\" height=\"400\">\n"; + $str .= "\n"; + $str .= "\n"; + } + + if($this->type == "vimeo") { + $str .= "\n"; + $str .= " \n"; + $str .= " \n"; + $str .= " value."&server=www.vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1\" /> \n"; + $str .= " value."&server=www.vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&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 .= " \n"; + $str .= "\n"; + } + + $str .= "
".$this->description."
\n"; + $str .= "
\n"; + foreach($this->sources as $s) { + $str .= $s->show(); + } + $str .= "
\n"; + $str .= "
\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, " 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, " \n"); + */ + } + + public function show() + { + $str = ""; + + + $str .= "
\n"; + $str .= " ".$this->title."\n"; + $str .= "
\n"; + if($this->items) { + foreach($this->items as $i) { + $str .= $i->show(); + } + } + $str .= "
\n"; + $str .= "
\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 = "
\n"; + + //foreach($params as $param => $value) {} + + if($this->groups) { + foreach($this->groups as $group) { + $str .= $group->show(); + } + } + + $str .= "
\n"; + + return $str; + } + + public function add($group) { + $key = $group->id; + $this->groups[$key] = $group; + } + + 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); + $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"); +} + +?> -- cgit v1.2.3