Campustream 1.0
A social network MQP for WPI
|
00001 <? 00002 require_once 'XML/Serializer.php'; 00003 00007 class xml { 00008 00016 public static function encode_array($array, $root, $name) { 00017 foreach ($array as $i=>$val) { 00018 if ($val instanceof ActiveRecord) { 00019 $array[$i] = $val->limited_object(false); 00020 } 00021 } 00022 00023 $options = array( 00024 "indent" => " ", 00025 "linebreak" => "\n", 00026 "typeHints" => false, 00027 "addDecl" => true, 00028 "encoding" => "UTF-8", 00029 "rootName" => $root, 00030 "defaultTagName" => $name 00031 ); 00032 00033 $serializer = new XML_Serializer( $options ); 00034 $serializer->serialize( $array ); 00035 return $serializer->getSerializedData(); 00036 } 00037 00041 public static function encode_rss($stories) { 00042 $options = array( 00043 "indent" => " ", 00044 "linebreak" => "\n", 00045 "typeHints" => false, 00046 "addDecl" => true, 00047 "encoding" => "UTF-8", 00048 "rootName" => "rdf:RDF", 00049 "defaultTagName" => "item" 00050 ); 00051 00052 $data = array( 00053 'channel' => array( 00054 'title' => 'Campustream News', 00055 'link' => 'http://campustream.com', 00056 $stories 00057 ) 00058 ); 00059 00060 $serializer = new XML_Serializer($options); 00061 if ($serializer->serialize($data)) { 00062 return $serializer->getSerializedData(); 00063 } 00064 } 00065 }