[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 <?php 2 /****************************************************************************/ 3 /* rdf.feed.class.php */ 4 /* */ 5 /****************************************************************************/ 6 /* Copyright (c) 2004 Michael Jervis (mike@fuckingbrit.com) */ 7 /* */ 8 /* This software is licensed under the terms of the ZLIB License: */ 9 /* */ 10 /* This software is provided 'as-is', without any express or implied */ 11 /* warranty. In no event will the authors be held liable for any damages */ 12 /* arising from the use of this software. */ 13 /* */ 14 /* Permission is granted to anyone to use this software for any purpose, */ 15 /* including commercial applications, and to alter it and redistribute it */ 16 /* freely, subject to the following restrictions: */ 17 /* */ 18 /* 1. The origin of this software must not be misrepresented; you must not */ 19 /* claim that you wrote the original software. If you use this software */ 20 /* in a product, an acknowledgment in the product documentation would be*/ 21 /* appreciated but is not required. */ 22 /* */ 23 /* 2. Altered source versions must be plainly marked as such, and must not */ 24 /* be misrepresented as being the original software. */ 25 /* */ 26 /* 3. This notice may not be removed or altered from any source */ 27 /* distribution. */ 28 /****************************************************************************/ 29 30 /** 31 * Provides feed handlers for RDF 1.0 32 * 33 * @author Michael Jervis (mike@fuckingbrit.com) 34 * @version 1.0 35 */ 36 37 /** 38 * RDF provides reading and writing of RDF 1.0 format syndication feeds. 39 * 40 * @author Michael Jervis (mike@fuckingbrit.com) 41 * @copyright Michael Jervis 2004 42 * @abstract 43 */ 44 class RDF extends FeedParserBase 45 { 46 /** 47 * @access private 48 * @var boolean 49 */ 50 var $_inItem; 51 52 /** 53 * @access private 54 * @var array 55 */ 56 var $_currentItem; 57 58 function RDF() 59 { 60 $this->FeedParserBase(); 61 $this->_inItem = false; 62 } 63 64 /** 65 * Format an article into an Atom 0.3 <entry> tag. 66 * 67 * Takes an associative article array and turns it into an XML definition 68 * of an article. Uses merely title, link and summary. 69 * 70 * @param array $article Associative array describing an article. 71 */ 72 function _formatArticle( $article ) 73 { 74 $xml = "<item rdf:about=\"{$article['link']}\">\n"; 75 $xml .= '<title>'.$this->_safeXML( $article['title'] )."</title>\n"; 76 $xml .= '<link>'.$this->_safeXML( $article['link'] )."</link>\n"; 77 if( array_key_exists( 'author', $article ) ) 78 { 79 $xml .= '<dc:creator>'.$article['author']."</dc:creator>\n"; 80 } 81 if( array_key_exists( 'summary', $article ) ) 82 { 83 if( strlen( $article['summary'] ) > 0 ) 84 { 85 $xml .= '<content:encoded>' 86 . $this->_safeXML ($article['summary']) 87 . "</content:encoded>\n"; 88 } 89 } 90 if( is_array( $article->extensions ) ) 91 { 92 foreach( $article->extensions as $extendingTag ) 93 { 94 $xml .= "$extendingTag\n"; 95 } 96 } 97 $xml .= "</item>\n"; 98 return $xml; 99 } 100 101 /** 102 * Return the formatted start of a feed. 103 * 104 * This will start the xml and create header information about the feed 105 * itself. 106 */ 107 function _feedHeader() 108 { 109 $xml = "<?xml version=\"1.0\" encoding=\"{$this->encoding}\"?>\n\n"; 110 $this->namespaces[] = 'xmlns:dc="http://purl.org/dc/elements/1.1/"'; 111 $this->namespaces[] = 'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'; 112 $this->namespaces[] = 'xmlns="http://purl.org/rss/1.0/"'; 113 $xml .= '<rdf:RDF'.$this->_injectNamespaces().">\n"; 114 $xml .= "<channel rdf:about=\"{$this->feedlogo}\">\n"; 115 $xml .= "<title>".$this->_safeXML( $this->title )."</title>\n"; 116 $xml .= '<link>'.$this->_safeXML( $this->sitelink )."</link>\n"; 117 $xml .= '<description>'.$this->_safeXML( $this->description )."</description>\n"; 118 $xml .= '<dc:language>'.$this->lang."</dc:language>\n"; 119 if( strlen($this->feedlogo) > 0 ) 120 { 121 $xml .= '<image rdf:resource="'.$this->_safeXML( $this->feedlogo )."\"/>\n"; 122 } 123 124 if( strlen($this->sitecontact) > 0 ) 125 { 126 $xml .= '<dc:creator>'.$this->sitecontact."</dc:creator>\n"; 127 } 128 $xml .= "<items>\n<rdf:Seq/>\n</items>\n"; 129 if( strlen($this->feedlogo) > 0 ) 130 { 131 $xml .= "<image rdf:about=\"{$this->feedlogo}\">\n"; 132 $xml .= '<url>'.$this->_safeXML( $this->feedlogo )."</url>\n"; 133 $xml .= '<title>'.$this->_safeXML( $this->title )."</title>\n"; 134 $xml .= '<link>'.$this->_safeXML( $this->sitelink )."</link>\n"; 135 $xml .= "</image>\n"; 136 } 137 if( is_array( $this->extensions ) ) 138 { 139 foreach( $this->extensions as $extendingTag ) 140 { 141 $xml .= "$extendingTag\n"; 142 } 143 } 144 $xml .= "</channel>\n"; 145 146 return $xml; 147 } 148 149 /** 150 * Return the formatted end of a feed. 151 * 152 * just closes things off nicely. 153 */ 154 function _feedFooter() 155 { 156 $xml = "</rdf:RDF>\n"; 157 return $xml; 158 } 159 160 /** 161 * Handle the begining of an XML element 162 * 163 * This is called from the parserfactory once the type of data has been 164 * determined. Standard XML_PARSER element handler. 165 * 166 * @author Michael Jervis (mike@fuckingbrit.com) 167 * @copyright Michael Jervis 2004 168 */ 169 function startElement($parser, $name, $attributes) 170 { 171 if( $name == 'ITEM' ) 172 { 173 $this->_inItem = true; 174 $this->_currentItem = array(); 175 } 176 $this->_currentTag = $name; 177 } 178 179 /** 180 * Handle the close of an XML element 181 * 182 * Called by the parserfactory during parsing. 183 */ 184 function endElement($parser, $name) 185 { 186 if( $name == 'ITEM' ) 187 { 188 $this->_inItem = false; 189 $this->articles[] = $this->_currentItem; 190 } 191 $this->_currentTag = ''; 192 } 193 194 /** 195 * Handles character data. 196 * 197 * Called by the parserfactory during parsing. 198 */ 199 function charData($parser, $data) 200 { 201 if( $this->_inItem ) 202 { 203 if( $this->_currentTag == 'TITLE' ) 204 { 205 if( empty( $this->_currentItem['title'] ) ) 206 { 207 $this->_currentItem['title'] = $data; 208 } else { 209 $this->_currentItem['title'] .= $data; 210 } 211 } else if( $this->_currentTag == 'LINK' ) { 212 if( empty( $this->_currentItem['link'] ) ) 213 { 214 $this->_currentItem['link'] = $data; 215 } else { 216 $this->_currentItem['link'] .= $data; 217 } 218 } else if( $this->_currentTag == 'CONTENT:ENCODED' ) { 219 if( empty( $this->_currentItem['summary'] ) ) 220 { 221 $this->_currentItem['summary'] = $data; 222 } else { 223 $this->_currentItem['summary'] .= $data; 224 } 225 } 226 } else { 227 if( $this->_currentTag == 'TITLE' ) 228 { 229 $this->title .= $data; 230 } else if( $this->_currentTag == 'LINK' ) { 231 $this->sitelink .= $data; 232 } else if( $this->_currentTag == 'DESCRIPTION' ) { 233 $this->description .= $data; 234 } 235 } 236 } 237 }
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 |
![]() |