From 9774f5644cde1b35e6b53afe954c434354467fd7 Mon Sep 17 00:00:00 2001 From: Colin Smith Date: Wed, 15 Jun 2005 03:47:14 +0000 Subject: Add notices facility. You may now: * File a new notice. * Dump notices to an XML file. * Close notices by timestamp or ID. * Get all notices or those in certain categories. * Print a list of notices (for print_info_box()). --- etc/inc/notices.inc | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 etc/inc/notices.inc (limited to 'etc/inc') diff --git a/etc/inc/notices.inc b/etc/inc/notices.inc new file mode 100644 index 0000000..d26eb68 --- /dev/null +++ b/etc/inc/notices.inc @@ -0,0 +1,153 @@ + $id, + 'notice' => $notice, + 'url' => $url, + 'category' => $category, + 'priority' => $priority, + ); + $queue[$queuekey] = $toqueue; + $queueout = fopen($notice_path, "w"); + fwrite($queueout, serialize($queue)); + fclose($queueout); + return; +} + +function get_notices($category = "all") { + global $notice_path; + if(file_exists($notice_path)) { + $queue = unserialize(file_get_contents($notice_path)); + if($category != 'all') { + foreach($queue as $time => $notice) { + if(strtolower($notice['category']) == strtolower($category)) + $toreturn[$time] = $notice; + } + return $toreturn; + } else { + return $queue; + } + } else { + return false; + } +} + +function close_notice($id) { + global $notice_path; + require_once("util.inc"); + if(!$notices = get_notices()) return; + if($id == "all") { + unlink_if_exists($notice_path); + return; + } + foreach(array_keys($notices) as $time) { + if($id == $time) { + unset($notices[$id]); + break; + } + } + foreach($notices as $key => $notice) { + $ids[$key] = $notice['id']; + } + foreach($ids as $time => $tocheck) { + if($id == $tocheck) { + unset($notices[$time]); + break; + } + } + $queueout = fopen($notice_path, "w"); + fwrite($queueout, serialize($queue)); + fclose($queueout); + return; +} + +function dump_xml_notices() { + require_once("xmlparse.inc"); + global $notice_path, $listtags; + $listtags[] = 'notice'; + if(!$notices = get_notices()) return; + foreach($notices as $time => $notice) { + $notice['time'] = $time; + $toput['notice'][] = $notice; + } + $xml = dump_xml_config($toput, 'notices'); + return $xml; +} + +function print_notices($notices, $category = "all") { + foreach($notices as $notice) { + if($category != "all") { + if(in_array($notice['category'], $category)) $categories[] = $notice['category']; + } else { + $categories[] = $notice['category']; + } + } + $categories = array_unique($categories); + sort($categories); + foreach($categories as $category) { + $toreturn .= ""; + } + return $toreturn; +} + +?> -- cgit v1.1