\n"; $str .= "
" . htmlspecialchars_decode($this->title, ENT_QUOTES) . "
\n"; $str .= "
" . date("D M jS Y", $this->time) . "
\n"; $str .= "
" . htmlspecialchars_decode($this->description, ENT_QUOTES) . "
\n"; if($this->flyer) { $str .= " \"flyer\"flyer . "\"/>\n"; } $str .= "\n"; return $str; } public function Event($title, $time, $description, $flyer = "") { $this->title = $title; $this->time = $time; $this->description = $description; $this->flyer = $flyer; } } class Events { private $file; private $events = array(); // Admin config public $admin_title = "Events"; public $admin_submodules = array("New Event" => "new", "Edit Event" => "edit", "Delete Event" => "delete"); public function admin($sub, $action, $vars) { switch($sub) { case "new": echo "New"; break; case "edit": echo "Edit"; break; case "delete": echo "Delete"; break; } } public function run($params) { foreach($params as $param) { switch($param) { case "coming": return $this->showcoming(-1); break; case "old": default: return $this->showold(-1); break; } } } public function showcoming($number) { $str = ""; $foundany = false; // Key sort ksort($this->events); // If number is -1 show all shows. if($number == -1) $number = 100000; foreach($this->events as $event) { if($event->time >= time()) { $foundany = true; $str .= $event->show(); $number--; } if(!$number) return $str; } if($foundany == false) return "No shows available at the moment."; return $str; } public function showold($number) { $str = ""; // Key sort krsort($this->events); // If number is -1 show all shows. if($number == -1) $number = 100000; foreach($this->events as $event) { if($event->time <= time()) { $str .= $event->show(); $number--; } if(!$number) return $str; } return $str; } public function add($event) { $key = $event->time; // array_push($this->events, $event); $this->events[$key] = $event; } public function write() { $fp = fopen($this->file, "w"); fwrite($fp, "\n"); fwrite($fp, "\n"); foreach($this->events as $event) { fwrite($fp, " title, ENT_QUOTES, "UTF-8") . "\"\n"); fwrite($fp, " time=\"" . $event->time . "\"\n"); fwrite($fp, " description=\"" . htmlspecialchars($event->description, ENT_QUOTES, "UTF-8") . "\"\n"); fwrite($fp, " flyer=\"" . $event->flyer . "\">\n"); fwrite($fp, " \n"); } fwrite($fp, "\n"); fclose($fp); } private function read() { $dom = new DomDocument; $dom->preserveWhiteSpace = FALSE; $dom->load($this->file); $params = $dom->getElementsByTagName('event'); foreach ($params as $param) { $event = new Event($param->getAttribute('title'), $param->getAttribute('time'), $param->getAttribute('description'), $param->getAttribute('flyer')); $this->add($event); } } public function Events($file) { $this->file = $file; if(file_exists($file)) $this->read(); } } function events_init() { global $DATA_DIR; return new Events($DATA_DIR . "/events.xml"); } ?>