Search:

# CWIS Developers Documentation

- Main Page
- Classes
- Files

- File List
- File Members

# Axis--RSS.php

Go to the documentation of this file.

    00001 <?PHP
    00002
    00003 #
    00004 #   Axis--RSS.php
    00005 #   An Object to Support RSS 0.92 (Rich Site Summary) Output
    00006 #
    00007 #   Copyright 2002 Axis Data
    00008 #   This code is free software that can be used or redistributed under the
    00009 #   terms of Version 2 of the GNU General Public License, as published by the
    00010 #   Free Software Foundation (http://www.fsf.org).
    00011 #
    00012 #   Author:  Edward Almasy (almasy@axisdata.com)
    00013 #
    00014 #   Part of the AxisPHP library v1.2.5
    00015 #   For more information see http://www.axisdata.com/AxisPHP/
    00016 #
    00017
    00018
    00019 class RSS {
    00020
    00021     # ---- PUBLIC INTERFACE --------------------------------------------------
    00022
    00023     function RSS()
    00024     {
    00025         $this->ChannelCount = -1;
    00026
    00027         # default encoding is UTF-8
    00028         $this->Encoding = "UTF-8";
    00029     }
    00030
    00031     # required channel values
    00032     function AddChannel($Title, $Link, $Description)
    00033     {
    00034         $this->ChannelCount++;
    00035         $this->ItemCounts[$this->ChannelCount] = -1;
    00036         $this->Channels[$this->ChannelCount]["Title"] = $Title;
    00037         $this->Channels[$this->ChannelCount]["Link"] = $Link;
    00038         $this->Channels[$this->ChannelCount]["Description"] = $Description;
    00039     }
    00040     function SetImage($Url, $Title, $Link,
    00041             $Height = NULL, $Width = NULL, $Description = NULL)
    00042     {
    00043         $this->Channels[$this->ChannelCount]["ImageUrl"] = $Url;
    00044         $this->Channels[$this->ChannelCount]["ImageTitle"] = $Title;
    00045         $this->Channels[$this->ChannelCount]["ImageLink"] = $Link;
    00046         $this->Channels[$this->ChannelCount]["ImageHeight"] = $Height;
    00047         $this->Channels[$this->ChannelCount]["ImageWidth"] = $Width;
    00048         $this->Channels[$this->ChannelCount]["ImageDescription"] = $Description;
    00049     }
    00050
    00051     # optional channel values
    00052     function SetEncoding($Value) { $this->Encoding = $Value; }
    00053     function SetLanguage($Value) {  $this->Channels[$this->ChannelCount]["Language"] = $Value;  }
    00054     function SetCopyright($Value) {  $this->Channels[$this->ChannelCount]["Copyright"] = $Value;  }
    00055     function SetManagingEditor($Value) {  $this->Channels[$this->ChannelCount]["ManagingEditor"] = $Value;  }
    00056     function SetWebmaster($Value) {  $this->Channels[$this->ChannelCount]["Webmaster"] = $Value;  }
    00057     function SetPicsRating($Value) {  $this->Channels[$this->ChannelCount]["PicsRating"] = $Value;  }
    00058     function SetPublicationDate($Value) {  $this->Channels[$this->ChannelCount]["PublicationDate"] = $this->FormatDate($Value);  }
    00059     function SetLastChangeDate($Value) {  $this->Channels[$this->ChannelCount]["LastChangeDate"] = $this->FormatDate($Value);  }
    00060     function SetTextInput($Title, $Description, $Name)
    00061     {
    00062         $this->Channels[$this->ChannelCount]["TextInputTitle"] = $Title;
    00063         $this->Channels[$this->ChannelCount]["TextInputDescription"] = $Description;
    00064         $this->Channels[$this->ChannelCount]["TextInputName"] = $Name;
    00065     }
    00066     function SetSkipTimes($Days, $Hours)
    00067     {
    00068         # ???
    00069     }
    00070     function SetCloud($Domain, $Port, $Path, $Procedure, $Protocol)
    00071     {
    00072         # ???
    00073     }
    00074
    00075     # add item to channel
    00076     function AddItem($Title = NULL, $Link = NULL, $Description = NULL, $Date = NULL)
    00077     {
    00078         $this->ItemCounts[$this->ChannelCount]++;
    00079         $this->Items[$this->ChannelCount][$this->ItemCounts[$this->ChannelCount]]["Title"] = $Title;
    00080         $this->Items[$this->ChannelCount][$this->ItemCounts[$this->ChannelCount]]["Link"] = $Link;
    00081         $this->Items[$this->ChannelCount][$this->ItemCounts[$this->ChannelCount]]["Description"] = $Description;
    00082         $this->Items[$this->ChannelCount][$this->ItemCounts[$this->ChannelCount]]["Date"] = $this->FormatDate($Date);
    00083     }
    00084     function AddItemCategory($Category, $Url)
    00085     {
    00086         $this->Items[$this->ChannelCount][$this->ItemCounts[$this->ChannelCount]]["Category"] = $Category;
    00087         $this->Items[$this->ChannelCount][$this->ItemCounts[$this->ChannelCount]]["CategoryUrl"] = $Url;
    00088     }
    00089     function AddItemEnclosure($Url, $Length, $Type)
    00090     {
    00091         $this->Items[$this->ChannelCount][$this->ItemCounts[$this->ChannelCount]]["EnclosureUrl"] = $Url;
    00092         $this->Items[$this->ChannelCount][$this->ItemCounts[$this->ChannelCount]]["EnclosureLength"] = $Length;
    00093         $this->Items[$this->ChannelCount][$this->ItemCounts[$this->ChannelCount]]["EnclosureType"] = $Type;
    00094     }
    00095     function AddItemSource($Source, $Url)
    00096     {
    00097         $this->Items[$this->ChannelCount][$this->ItemCounts[$this->ChannelCount]]["Source"] = $Source;
    00098         $this->Items[$this->ChannelCount][$this->ItemCounts[$this->ChannelCount]]["SourceUrl"] = $Url;
    00099     }
    00100
    00101     # write out and RSS page
    00102     function PrintRSS()
    00103     {
    00104         # print opening elements
    00105         header("Content-type: text/xml; charset=".$this->Encoding, TRUE);
    00106         FTOut("<?xml version='1.0' encoding='".$this->Encoding."' ?>");
    00107         FTOut("<rss version='0.92' encoding='".$this->Encoding."'>", 0);
    00108
    00109         # for each channel
    00110         for ($this->ChannelIndex = 0;  $this->ChannelIndex <= $this->ChannelCount;  $this->ChannelIndex++)
    00111         {
    00112             # open channel element
    00113             FTOut("<channel>");
    00114
    00115             # print required channel elements
    00116             $this->PrintChannelElement("Title", "title");
    00117             $this->PrintChannelElement("Link", "link");
    00118             $this->PrintChannelElement("Description", "description");
    00119
    00120             # print image element (url, title, link required)
    00121             FTOut("<image>");
    00122             $this->PrintChannelElement("ImageUrl", "url");
    00123             $this->PrintChannelElement("ImageTitle", "title");
    00124             $this->PrintChannelElement("ImageLink", "link");
    00125             $this->PrintChannelElement("ImageWidth", "width");
    00126             $this->PrintChannelElement("ImageHeight", "height");
    00127             $this->PrintChannelElement("ImageDescription", "description");
    00128             FTOut("</image>");
    00129
    00130             # print optional channel elements
    00131             $this->PrintChannelElement("Language", "language");
    00132             $this->PrintChannelElement("Copyright", "copyright");
    00133             $this->PrintChannelElement("ManagingEditor", "managingEditor");
    00134             $this->PrintChannelElement("Webmaster", "webMaster");
    00135             $this->PrintChannelElement("PicsRating", "rating");
    00136             $this->PrintChannelElement("PublicationDate", "pubDate");
    00137             $this->PrintChannelElement("LastChangeDate", "lastBuildDate");
    00138             # ???  STILL TO DO:  SkipDays, SkipHours, Cloud
    00139             FTOut("<docs>http://backend.userland.com/rss092</docs>");
    00140
    00141             # for each item in this channel
    00142             for ($this->ItemIndex = 0;  $this->ItemIndex <= $this->ItemCounts[$this->ChannelCount];  $this->ItemIndex++)
    00143             {
    00144                 # open item element
    00145                 FTOut("<item>");
    00146
    00147                 # print item elements
    00148                 $this->PrintItemElement("Title", "title");
    00149                 $this->PrintItemElement("Link", "link");
    00150                 $this->PrintItemElement("Description", "description");
    00151                 $this->PrintItemElement("Date", "pubDate");
    00152                 if (isset($this->Items[$this->ChannelIndex][$this->ItemIndex]["Category"])
    00153                         && ($this->Items[$this->ChannelIndex][$this->ItemIndex]["Category"] != NULL))
    00154                 {
    00155                     FTOut("<category url='".$this->Items[$this->ChannelIndex][$this->ItemIndex]["CategoryUrl"]."'>");
    00156                     FTOut($this->Items[$this->ChannelIndex][$this->ItemIndex]["Category"]);
    00157                     FTOut("</category>");
    00158                 }
    00159                 if (isset($this->Items[$this->ChannelIndex][$this->ItemIndex]["EnclosureUrl"])
    00160                         && ($this->Items[$this->ChannelIndex][$this->ItemIndex]["EnclosureUrl"] != NULL))
    00161                 {
    00162                     FTOut("<enclosure "
    00163                         ."url='".$this->Items[$this->ChannelIndex][$this->ItemIndex]["EnclosureUrl"]."' "
    00164                         ."length='".$this->Items[$this->ChannelIndex][$this->ItemIndex]["EnclosureLength"]."' "
    00165                         ."type='".$this->Items[$this->ChannelIndex][$this->ItemIndex]["EnclosureType"]."' />");
    00166                 }
    00167                 if (isset($this->Items[$this->ChannelIndex][$this->ItemIndex]["Source"])
    00168                         && ($this->Items[$this->ChannelIndex][$this->ItemIndex]["Source"] != NULL))
    00169                 {
    00170                     FTOut("<source url='".$this->Items[$this->ChannelIndex][$this->ItemIndex]["SourceUrl"]."'>");
    00171                     FTOut($this->Items[$this->ChannelIndex][$this->ItemIndex]["Source"]);
    00172                     FTOut("</source>");
    00173                 }
    00174
    00175                 # close item element
    00176                 FTOut("</item>");
    00177             }
    00178
    00179             # close channel element
    00180             FTOut("</channel>");
    00181         }
    00182
    00183         # print closing elements
    00184         FTOut("</rss>");
    00185     }
    00186
    00187
    00188     # ---- PRIVATE INTERFACE -------------------------------------------------
    00189
    00190     var $Encoding;
    00191     var $Channels;
    00192     var $Items;
    00193     var $ChannelCount;
    00194     var $ItemCounts;
    00195     var $ChannelIndex;
    00196     var $ItemIndex;
    00197
    00198     function PrintChannelElement($VarName, $TagName)
    00199     {
    00200         if (isset($this->Channels[$this->ChannelIndex][$VarName])
    00201                 && ($this->Channels[$this->ChannelIndex][$VarName] != NULL)
    00202                 && (strlen($this->Channels[$this->ChannelIndex][$VarName])))
    00203         {
    00204             FTOut("<${TagName}>"
    00205                   .htmlspecialchars(preg_replace("/[\\x00-\\x1F]+/", "", $this->Channels[$this->ChannelIndex][$VarName]))
    00206                   ."</${TagName}>");
    00207         }
    00208     }
    00209     function PrintItemElement($VarName, $TagName)
    00210     {
    00211         if (isset($this->Items[$this->ChannelIndex][$this->ItemIndex][$VarName])
    00212                 && ($this->Items[$this->ChannelIndex][$this->ItemIndex][$VarName] != NULL))
    00213         {
    00214             FTOut("<${TagName}>"
    00215                   .htmlspecialchars(preg_replace("/[\\x00-\\x1F]+/", "", $this->Items[$this->ChannelIndex][$this->ItemIndex][$VarName]))
    00216                   ."</${TagName}>");
    00217         }
    00218     }
    00219
    00220     function FormatDate($DateValue)
    00221     {
    00222         # convert date to timestamp
    00223         $TimeStamp = strtotime($DateValue);
    00224
    00225         # convert timestamp to properly-formatted date
    00226         $DateString = date("r", $TimeStamp);
    00227
    00228         # return properly-formatted date to caller
    00229         return $DateString;
    00230     }
    00231 }
    00232
    00233 # (FTOut == Formatted Tag Output)
    00234 function FTOut($String, $NewIndent = NULL)
    00235 {
    00236     static $Indent = 0;
    00237
    00238     $IndentSize = 4;
    00239
    00240     # decrease indent if string contains end tag and does not start with begin tag
    00241     if (preg_match("/<\/[A-Za-z0-9]+>/", $String) && !preg_match("/^<[^\/]+/", $String)) {  $Indent--;  }
    00242
    00243     # reset indent if value is supplied
    00244     if ($NewIndent != NULL) {  $Indent = $NewIndent;  }
    00245
    00246     # print string
    00247     print(substr("                                                                                                                        ",
    00248             0, ($Indent * $IndentSize)).$String."\n");
    00249
    00250     # inrease indent if string starts with begin tag and does not contain end tag
    00251     if (preg_match("/^<[^\/]+/", $String)
    00252             && !preg_match("/<\/[A-Za-z0-9]+>/", $String)
    00253             && !preg_match("/\/>$/", $String))
    00254     {
    00255         $Indent++;
    00256     }
    00257 }
    00258
    00259
    00260 ?>