| [ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 3 /** 4 * Create the Spam-X rss feed 5 * 6 * @param items $ array of blacklisted sites 7 * 8 * $Id: rss.inc.php,v 1.3 2005/04/10 10:02:46 dhaun Exp $ 9 */ 10 11 function Spamx_rss($items) 12 { 13 global $_CONF; 14 // Basic Data 15 $about = $_CONF['site_url'] . '/spamx/index.php'; 16 $title = 'Spam-X Blacklist'; 17 $description = 'Personal Spamx Blacklist from site ' . $_CONF['site_name']; 18 // Dublic Core Data 19 $dc = array('dc:publisher' => $_CONF['site_name'], 20 'dc:creator' => $_CONF['site_name'], 21 'dc:date' => time()); 22 $rssfile = new RSSWriter($about, $title, $description, $dc); 23 // Add items 24 foreach($items as $item) { 25 $about = $_CONF['site_url'] . '/spamx/index.php'; 26 $title = $item; 27 $description = $item; 28 $dc = array('dc:subject' => 'Personal Blacklist', 29 'dc:author' => $_CONF['site_name']); 30 $rssfile->addItem($about, $title, $dc); 31 } 32 // Now write the file 33 $buff = $rssfile->serialize(); 34 $rdfpath = dirname($_CONF['rdf_file']); 35 $rdffile = $rdfpath . '/spamx.rdf'; 36 $fp = fopen($rdffile, "w"); 37 fputs($fp, $buff); 38 fclose($fp); 39 } 40 41 // A convenience class to make it easy to write RSS classes 42 // Edd Dumbill <mailto:edd+rsswriter@usefulinc.com> 43 44 // Revision 1.4 2004/06/11 11:00 towm 45 // Changed output to string 46 47 // Revision 1.3 2001/05/20 17:58:02 edmundd 48 // Final distribution tweaks. 49 50 // Revision 1.2 2001/05/20 17:41:30 edmundd 51 // Ready for distribution. 52 53 // Revision 1.1 2001/05/20 17:01:43 edmundd 54 // First functional draft of code working. 55 56 // Revision 1.1 2001/05/17 18:17:46 edmundd 57 // Start of a convenience library to help RSS1.0 creation 58 59 class RSSWriter { 60 function RSSWriter($uri, $title, $description, $meta = array()) 61 { 62 $this->chaninfo = array(); 63 $this->website = $uri; 64 $this->chaninfo["link"] = $uri; 65 $this->chaninfo["description"] = $description; 66 $this->chaninfo["title"] = $title; 67 $this->items = array(); 68 $this->modules = array("dc" => "http://purl.org/dc/elements/1.1/"); 69 $this->channelURI = str_replace("&", "&", "http://" . $GLOBALS["SERVER_NAME"] . $GLOBALS["REQUEST_URI"]); 70 foreach ($meta as $key => $value) { 71 $this->chaninfo[$key] = $value; 72 } 73 } 74 75 function useModule($prefix, $uri) 76 { 77 $this->modules[$prefix] = $uri; 78 } 79 80 function setImage($imgURI, $imgAlt, $imgWidth = 88, $imgHeight = 31) 81 { 82 $this->image = array("uri" => $imgURI, "title" => $imgAlt, "width" => $imgWidth, 83 "height" => $imgHeight); 84 } 85 86 function addItem($uri, $title, $meta = array()) 87 { 88 $item = array("uri" => $uri, "link" => $uri, 89 "title" => $this->deTag($title)); 90 foreach ($meta as $key => $value) { 91 if ($key == "description" || $key == "dc:description") { 92 $value = $this->deTag($value); 93 } 94 $item[$key] = $value; 95 } 96 $this->items[] = $item; 97 } 98 99 function serialize() 100 { 101 $buff = $this->preamble(); 102 $buff .= $this->channelinfo(); 103 $buff .= $this->image(); 104 $buff .= $this->items(); 105 $buff .= $this->postamble(); 106 return $buff; 107 } 108 109 function deTag($in) 110 { 111 while (ereg('<[^>]+>', $in)) { 112 $in = ereg_replace('<[^>]+>', '', $in); 113 } 114 return $in; 115 } 116 117 function preamble() 118 { 119 // header("Content-type: text/xml"); 120 $display = '<?xml version="1.0" encoding="iso-8859-1"?> 121 <rdf:RDF 122 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 123 xmlns="http://purl.org/rss/1.0/" 124 xmlns:mn="http://usefulinc.com/rss/manifest/" 125 '; 126 foreach ($this->modules as $prefix => $uri) { 127 $display .= " xmlns:$prefix}=\"$uri}\"\n"; 128 } 129 $display .= ">\n\n"; 130 return $display; 131 } 132 133 function channelinfo() 134 { 135 $display = ' <channel rdf:about="' . $this->channelURI . '">'; 136 $i = $this->chaninfo; 137 foreach (array("title", "link", "dc:source", "description", "dc:language", "dc:publisher", 138 "dc:creator", "dc:rights") as $f) { 139 if (isset($i[$f])) { 140 $display .= " <$f}>" . htmlspecialchars($i[$f]) . "</$f}>\n"; 141 } 142 } 143 if (isset($this->image)) { 144 $display .= " <image rdf:resource=\"" . htmlspecialchars($this->image["uri"]) . "\" />\n"; 145 } 146 $display .= " <items>\n"; 147 $display .= " <rdf:Seq>\n"; 148 foreach ($this->items as $i) { 149 $display .= " <rdf:li rdf:resource=\"" . htmlspecialchars($i["uri"]) . "\" />\n"; 150 } 151 $display .= " </rdf:Seq>\n"; 152 $display .= " </items>\n"; 153 $display .= " </channel>\n\n"; 154 return $display; 155 } 156 157 function image() 158 { 159 $display = ''; 160 if (isset($this->image)) { 161 $display .= " <image rdf:about=\"" . htmlspecialchars($this->image["uri"]) . "\">\n"; 162 $display .= " <title>" . htmlspecialchars($this->image["title"]) . "</title>\n"; 163 $display .= " <url>" . htmlspecialchars($this->image["uri"]) . "</url>\n"; 164 $display .= " <link>" . htmlspecialchars($this->website) . "</link>\n"; 165 if ($this->chaninfo["description"]) 166 $display .= " <dc:description>" . htmlspecialchars($this->chaninfo["description"]) . "</dc:description>\n"; 167 $display .= " </image>\n\n"; 168 } 169 return $display; 170 } 171 172 function postamble() 173 { 174 $display = ' <rdf:Description rdf:ID="manifest"> 175 <mn:channels> 176 <rdf:Seq> 177 <rdf:li rdf:resource="' . $this->channelURI . '" /> 178 </rdf:Seq> 179 </mn:channels> 180 </rdf:Description> 181 182 </rdf:RDF> 183 '; 184 return $display; 185 } 186 187 function items() 188 { 189 $display = ''; 190 foreach ($this->items as $item) { 191 $display .= " <item rdf:about=\"" . htmlspecialchars($item["uri"]) . "\">\n"; 192 foreach ($item as $key => $value) { 193 if ($key != "uri") { 194 if (is_array($value)) { 195 foreach ($value as $v1) { 196 $display .= " <$key}>" . htmlspecialchars($v1) . "</$key}>\n"; 197 } 198 } else { 199 $display .= " <$key}>" . htmlspecialchars($value) . "</$key}>\n"; 200 } 201 } 202 } 203 $display .= " </item>\n\n"; 204 } 205 return $display; 206 } 207 } 208 209 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
|