51 var $channel = Array();
99 if (!is_array($items)) {
100 trigger_error(
'You can assign Associative Arrays only to the items', E_USER_ERROR);
103 $this->items = $items;
122 if (empty($channel)) {
123 trigger_error(
'You cannot set empty values to channel', E_USER_ERROR);
127 if (!is_array($channel)) {
128 trigger_error(
'You can assign Associative Arrays only to the items', E_USER_ERROR);
131 $this->channel = $channel;
151 trigger_error(
'You cannot set empty values to image ', E_USER_ERROR);
155 if (!is_array($image)) {
156 trigger_error(
'You can assign Associative Arrays only to the items', E_USER_ERROR);
159 $this->image = $image;
179 if (empty($type) || empty($version)) {
180 trigger_error(
'You Have To Set The Type And The Version Of RSS Before Adding the element', E_USER_WARNING);
183 if (!is_string($type) || !is_string($version)) {
184 trigger_error(
'The Type And Version Of The RSS Feed To Be Generated Have To Be Strings', E_USER_WARNING);
187 $type_version = $type.
'_'.$version;
188 switch ($type_version) {
196 trigger_error(
'The Type The RSS Feed Can Only Be Either rss Or atom', E_USER_ERROR);
200 $this->version = $version;
218 $channel = $this->channel;
219 $image = $this->image;
220 $items = $this->items;
222 $version = $this->version;
225 if (empty($type) || empty($version)) {
226 trigger_error(
'There Is No Type Or Version Set.. Please Set the Type And Version And Try Again', E_USER_WARNING);
230 if (empty($channel)) {
231 trigger_error(
'Channel Info Required As Per The RSS Standards', E_USER_WARNING);
237 if ($header) header(
'Content-type: text/xml');
238 echo
'<?xml version="1.0" encoding="'.$encoding.
'"?>';
243 if (strcasecmp($type,
'atom') == 0) {
247 if (($type ==
'rss') && ($version ==
'1.0')) {
248 echo
'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/">';
251 if ($type ==
'feed') {
252 echo
' xml:lang="en" xmlns="http://www.w3.org/2005/Atom"';
254 echo
' version="'.$version.
'"';
259 if ($type !=
'feed') {
260 $type .=
' '.$version;
262 if ($type ==
'rss 2.0') {
265 if (isset($channel[
'rdf:about'])) {
266 echo
'<channel rdf:about="'.$channel[
'rdf:about'].
'">';
268 trigger_error(
'A required attribute "rdf:about" is undefined for the Channel tag', E_USER_ERROR);
275 foreach ($channel as $key => $info) {
276 if ($key ==
'rdf:about')
continue;
277 if (is_array($info)) {
278 if ($type !=
'feed') {
279 trigger_error(
'Attributes And SubTags In Channel Not Allowed For RSS Versions', E_USER_ERROR);
283 $keys = array_keys($info);
284 if (in_array(
'ATTRIBUTES', $keys)) {
286 $attributes = $info[
'ATTRIBUTES'];
287 foreach ($attributes as $sub => $sub_info) {
289 $sub_info = str_replace(
'&',
'&', $sub_info);
290 $sub_info = str_replace(
'<',
'<', $sub_info);
291 $sub_info = str_replace(
'>',
'>', $sub_info);
292 echo $sub.
'="'.$sub_info.
'" ';
296 if (in_array(
'SUBTAGS', $keys)) {
298 $sub_tags = $info[
'SUBTAGS'];
299 foreach ($sub_tags as $sub => $sub_info) {
301 $sub_info = str_replace(
'&',
'&', $sub_info);
302 $sub_info = str_replace(
'<',
'<', $sub_info);
303 $sub_info = str_replace(
'>',
'>', $sub_info);
304 echo
'<'.$sub.
'>'.$sub_info.
'</'.$sub.
'>';
310 $info = str_replace(
'&',
'&', $info);
311 $info = str_replace(
'<',
'<', $info);
312 $info = str_replace(
'>',
'>', $info);
313 echo
'<'.$key.
'>'.$info.
'</'.$key.
'>';
317 if ($type ==
'rss 1.0') {
318 echo
'<items><rdf:Seq>';
319 foreach ($items as $item) {
320 echo
'<rdf:li rdf:resource="'.$item[
'rdf:about'].
'"/>';
322 echo
'</rdf:Seq></items></channel>';
325 if (!empty($image)) {
326 if ($type ==
'feed') {
331 foreach ($image as $key => $info) {
333 $info = str_replace(
'&',
'&', $info);
334 $info = str_replace(
'<',
'<', $info);
335 $info = str_replace(
'>',
'>', $info);
336 if (is_array($info)) {
338 foreach ($info as $sub => $sub_info) {
339 echo
'<'.$sub.
'>'.$sub_info.
'</'.$sub.
'>';
343 echo
'<'.$key.
'>'.$info.
'</'.$key.
'>';
346 if ($type ==
'feed') {
353 foreach ($items as $item) {
354 if ($type !=
'rss 1.0') {
357 echo
'<item rdf:about="'.$item[
'rdf:about'].
'">';
358 unset($item[
'rdf:about']);
360 foreach ($item as $key => $info) {
361 if (is_array($info)) {
362 $keys = array_keys($info);
363 if (in_array(
'ATTRIBUTES', $keys)) {
365 $attributes = $info[
'ATTRIBUTES'];
366 foreach ($attributes as $sub => $sub_info) {
368 $sub_info = str_replace(
'&',
'&', $sub_info);
369 $sub_info = str_replace(
'<',
'<', $sub_info);
370 $sub_info = str_replace(
'>',
'>', $sub_info);
371 echo $sub.
'="'.$sub_info.
'" ';
375 if (in_array(
'SUBTAGS', $keys)) {
377 $sub_tags = $info[
'SUBTAGS'];
378 foreach ($sub_tags as $sub => $sub_info) {
380 $sub_info = str_replace(
'&',
'&', $sub_info);
381 $sub_info = str_replace(
'<',
'<', $sub_info);
382 $sub_info = str_replace(
'>',
'>', $sub_info);
383 echo
'<'.$sub.
'>'.$sub_info.
'</'.$sub.
'>';
389 $info = str_replace(
'&',
'&', $info);
390 $info = str_replace(
'<',
'<', $info);
391 $info = str_replace(
'>',
'>', $info);
392 echo
'<'.$key.
'>'.$info.
'</'.$key.
'>';
398 if ($type !=
'rss 1.0') {
399 if ($type !=
'feed') {
402 echo
'</'.$this->type.
'>';
412 $rss = ob_get_contents();
430 if (!empty($this->type) && (!empty($this->version))) {
433 trigger_error(
'You Have To Set The Type And The Version Of RSS Before Adding the element', E_USER_WARNING);