1: <?php
2: class QRssFeed extends QBaseClass {
3:
4: protected $strTitle;
5: protected $strLink;
6: protected $strDescription;
7:
8:
9:
10:
11: protected $strLanguage;
12: protected $strCopyright;
13: protected $strManagingEditor;
14: protected $strWebMaster;
15: protected $dttPubDate;
16: protected $dttLastBuildDate;
17:
18: protected $strGenerator;
19: protected $strDocs = 'http://blogs.law.harvard.edu/tech/rss';
20:
21: protected $strTtl;
22: protected $objImage;
23:
24:
25:
26:
27:
28: protected $objItemArray = array();
29:
30: public function __construct($strTitle, $strLink, $strDescription) {
31: $this->strTitle = $strTitle;
32: $this->strLink = $strLink;
33: $this->strDescription = $strDescription;
34:
35: $this->strGenerator = 'QCubed Development Framework ' . QCUBED_VERSION;
36: }
37:
38: public function GetXml() {
39: $strToReturn = "<rss version=\"2.0\">\r\n<channel>\r\n";
40: $strToReturn .= sprintf(" <title>%s</title>\r\n", $this->strTitle);
41: $strToReturn .= sprintf(" <link>%s</link>\r\n", $this->strLink);
42: $strToReturn .= sprintf(" <description>%s</description>\r\n", $this->strDescription);
43:
44: if ($this->strLanguage)
45: $strToReturn .= sprintf(" <language>%s</language>\r\n", $this->strLanguage);
46: if ($this->strCopyright)
47: $strToReturn .= sprintf(" <copyright>%s</copyright>\r\n", $this->strCopyright);
48: if ($this->strManagingEditor)
49: $strToReturn .= sprintf(" <managingEditor>%s</managingEditor>\r\n", $this->strManagingEditor);
50: if ($this->strWebMaster)
51: $strToReturn .= sprintf(" <webMaster>%s</webMaster>\r\n", $this->strWebMaster);
52: if ($this->dttPubDate)
53: $strToReturn .= sprintf(" <pubDate>%s</pubDate>\r\n", $this->dttPubDate->qFormat(QDateTime::FormatRfc822));
54: if ($this->dttLastBuildDate)
55: $strToReturn .= sprintf(" <lastBuildDate>%s</lastBuildDate>\r\n", $this->dttLastBuildDate->qFormat(QDateTime::FormatRfc822));
56: if ($this->strGenerator)
57: $strToReturn .= sprintf(" <generator>%s</generator>\r\n", $this->strGenerator);
58: if ($this->strDocs)
59: $strToReturn .= sprintf(" <docs>%s</docs>\r\n", $this->strDocs);
60: if ($this->strTtl)
61: $strToReturn .= sprintf(" <ttl>%s</ttl>\r\n", $this->strTtl);
62: if ($this->objImage)
63: $strToReturn .= $this->objImage->GetXml($this->strTitle, $this->strLink);
64:
65: foreach ($this->objItemArray as $objItem)
66: $strToReturn .= $objItem->GetXml();
67:
68: $strToReturn .= "</channel>\r\n</rss>\r\n";
69:
70: return $strToReturn;
71: }
72:
73: public function Run() {
74: ob_clean();
75: QApplication::$ContentType = 'text/xml';
76:
77: if (QApplication::$EncodingType)
78: printf("<?xml version=\"1.0\" encoding=\"%s\" ?>\r\n", QApplication::$EncodingType);
79: else
80: _p("<?xml version=\"1.0\" ?>\r\n", false);
81:
82: _p($this->GetXml(), false);
83: }
84:
85: public function AddItem(QRssItem $objItem) {
86: array_push($this->objItemArray, $objItem);
87: }
88:
89: public function __get($strName) {
90: try {
91: switch ($strName) {
92: case 'Title': return $this->strTitle;
93: case 'Link': return $this->strLink;
94: case 'Description': return $this->strDescription;
95: case 'Language': return $this->strLanguage;
96: case 'Copyright': return $this->strCopyright;
97: case 'ManagingEditor': return $this->strManagingEditor;
98: case 'WebMaster': return $this->strWebMaster;
99: case 'PubDate': return $this->dttPubDate;
100: case 'LastBuildDate': return $this->dttLastBuildDate;
101: case 'Generator': return $this->strGenerator;
102: case 'Docs': return $this->strDocs;
103: case 'Ttl': return $this->strTtl;
104: case 'Image': return $this->objImage;
105: default: return parent::__get($strName);
106: }
107: } catch (QCallerException $objExc) {
108: $objExc->IncrementOffset();
109: throw $objExc;
110: }
111: }
112:
113: public function __set($strName, $mixValue) {
114: try {
115: switch ($strName) {
116: case 'Title': return ($this->strTitle = QType::Cast($mixValue, QType::String));
117: case 'Link': return ($this->strLink = QType::Cast($mixValue, QType::String));
118: case 'Description': return ($this->strDescription = QType::Cast($mixValue, QType::String));
119: case 'Language': return ($this->strLanguage = QType::Cast($mixValue, QType::String));
120: case 'Copyright': return ($this->strCopyright = QType::Cast($mixValue, QType::String));
121: case 'ManagingEditor': return ($this->strManagingEditor = QType::Cast($mixValue, QType::String));
122: case 'WebMaster': return ($this->strWebMaster = QType::Cast($mixValue, QType::String));
123: case 'PubDate': return ($this->dttPubDate = QType::Cast($mixValue, QType::DateTime));
124: case 'LastBuildDate': return ($this->dttLastBuildDate = QType::Cast($mixValue, QType::DateTime));
125: case 'Generator': return ($this->strGenerator = QType::Cast($mixValue, QType::String));
126: case 'Docs': return ($this->strDocs= QType::Cast($mixValue, QType::String));
127: case 'Ttl': return ($this->strTtl = QType::Cast($mixValue, QType::String));
128: case 'Image': return ($this->objImage = QType::Cast($mixValue, 'QRssImage'));
129: default: return parent::__set($strName, $mixValue);
130: }
131: } catch (QCallerException $objExc) {
132: $objExc->IncrementOffset();
133: throw $objExc;
134: }
135: }
136: }
137:
138: class QRssImage extends QBaseClass {
139: protected $strUrl;
140: protected $strTitle;
141: protected $strLink;
142:
143: public function __construct($strUrl, $strTitle = null, $strLink = null) {
144: $this->strUrl = $strUrl;
145: $this->strTitle = $strTitle;
146: $this->strLink = $strLink;
147: }
148:
149: public function GetXml($strTitle, $strLink) {
150: $strToReturn = " <image>\r\n";
151: $strToReturn .= sprintf(" <url>%s</url>\r\n", $this->strUrl);
152: $strToReturn .= sprintf(" <title>%s</title>\r\n", ($this->strTitle) ? $this->strTitle : $strTitle);
153: $strToReturn .= sprintf(" <link>%s</link>\r\n", ($this->strLink) ? $this->strLink : $strLink);
154:
155: $intErrorLevel = error_reporting(0);
156: set_error_handler('QcubedHandleError', 0);
157: $objImageSize = getimagesize($this->strUrl);
158: restore_error_handler();
159: error_reporting($intErrorLevel);
160:
161: if ($objImageSize) {
162: $strToReturn .= sprintf(" <width>%s</width>\r\n", $objImageSize[0]);
163: $strToReturn .= sprintf(" <height>%s</height>\r\n", $objImageSize[1]);
164: }
165:
166: $strToReturn .= " </image>\r\n";
167:
168: return $strToReturn;
169: }
170: }
171:
172: class QRssCategory extends QBaseClass {
173: protected $strCategory;
174: protected $strDomain;
175:
176: public function __construct($strCategory, $strDomain = null) {
177: $this->strCategory = $strCategory;
178: $this->strDomain = $strDomain;
179: }
180:
181: public function GetXml() {
182: if ($this->strDomain)
183: return sprintf(" <category domain=\"%s\">%s</category>\r\n", $this->strDomain, $this->strCategory);
184: else
185: return sprintf(" <category>%s</category>\r\n", $this->strCategory);
186: }
187: }
188:
189: class QRssItem extends QBaseClass {
190:
191: protected $strTitle;
192: protected $strLink;
193: protected $strDescription;
194:
195:
196:
197:
198: protected $strAuthor;
199: protected $objCategoryArray = array();
200: protected $strComments;
201:
202: protected $strGuid;
203: protected $blnGuidPermaLink;
204: protected $dttPubDate;
205:
206:
207: public function __construct($strTitle, $strLink, $strDescription = null) {
208: $this->strTitle = $strTitle;
209: $this->strLink = $strLink;
210: $this->strDescription = $strDescription;
211: }
212:
213: public function GetXml() {
214: $strToReturn = " <item>\r\n";
215: $strToReturn .= sprintf(" <title>%s</title>\r\n", QString::XmlEscape($this->strTitle));
216: $strToReturn .= sprintf(" <link>%s</link>\r\n", QString::XmlEscape($this->strLink));
217: $strToReturn .= sprintf(" <description>%s</description>\r\n", QString::XmlEscape($this->strDescription));
218:
219: if ($this->strAuthor)
220: $strToReturn .= sprintf(" <author>%s</author>\r\n", QString::XmlEscape($this->strAuthor));
221: foreach ($this->objCategoryArray as $objCategory)
222: $strToReturn .= $objCategory->GetXml();
223: if ($this->strComments)
224: $strToReturn .= sprintf(" <comments>%s</comments>\r\n", QString::XmlEscape($this->strComments));
225: if ($this->strGuid)
226: $strToReturn .= sprintf(" <guid isPermaLink=\"%s\">%s</guid>\r\n", ($this->blnGuidPermaLink) ? 'true' : 'false', $this->strGuid);
227: if ($this->dttPubDate)
228: $strToReturn .= sprintf(" <pubDate>%s</pubDate>\r\n", $this->dttPubDate->qFormat(QDateTime::FormatRfc822));
229:
230: $strToReturn .= " </item>\r\n";
231:
232: return $strToReturn;
233: }
234:
235: public function AddCategory(QRssCategory $objCategory) {
236: array_push($this->objCategoryArray, $objCategory);
237: }
238:
239: public function __get($strName) {
240: try {
241: switch ($strName) {
242: case 'Title': return $this->strTitle;
243: case 'Link': return $this->strLink;
244: case 'Description': return $this->strDescription;
245: case 'Author': return $this->strAuthor;
246: case 'Comments': return $this->strComments;
247: case 'Guid': return $this->strGuid;
248: case 'GuidPermaLink': return $this->blnGuidPermaLink;
249: case 'PubDate': return $this->dttPubDate;
250: default: return parent::__get($strName);
251: }
252: } catch (QCallerException $objExc) {
253: $objExc->IncrementOffset();
254: throw $objExc;
255: }
256: }
257:
258: public function __set($strName, $mixValue) {
259: try {
260: switch ($strName) {
261: case 'Title': return ($this->strTitle = QType::Cast($mixValue, QType::String));
262: case 'Link': return ($this->strLink = QType::Cast($mixValue, QType::String));
263: case 'Description': return ($this->strDescription = QType::Cast($mixValue, QType::String));
264: case 'Author': return ($this->strAuthor = QType::Cast($mixValue, QType::String));
265: case 'Comments': return ($this->strComments = QType::Cast($mixValue, QType::String));
266: case 'Guid': return ($this->strGuid = QType::Cast($mixValue, QType::String));
267: case 'GuidPermaLink': return ($this->blnGuidPermaLink = QType::Cast($mixValue, QType::Boolean));
268: case 'PubDate': return ($this->dttPubDate = QType::Cast($mixValue, QType::DateTime));
269: default: return parent::__set($strName, $mixValue);
270: }
271: } catch (QCallerException $objExc) {
272: $objExc->IncrementOffset();
273: throw $objExc;
274: }
275: }
276: }