/PHPKit/SSUtil/class.rss.php

https://github.com/stopassola/SlideshareAPIExamples · PHP · 255 lines · 200 code · 40 blank · 15 comment · 37 complexity · 3be7faf0183da37354b06be8167b58dc MD5 · raw file

  1. <?php
  2. /***************************************************************************
  3. * RSS 2.0 generation class
  4. * ------------------------
  5. *
  6. * copyright : (C) 2006 Marijo Galesic
  7. * email : mgalesic@gmail.com
  8. *
  9. * Id: class.rss.php, v 1.1 2006/08/25
  10. *
  11. * www.starmont.net
  12. *
  13. * Redistribution and use in source and binary forms,
  14. * with or without modification must retain the above copyright notice
  15. *
  16. ***************************************************************************/
  17. class rss {
  18. var $rss;
  19. var $encoding;
  20. var $title;
  21. var $link;
  22. var $description;
  23. var $language;
  24. var $copyright;
  25. var $managingEditor;
  26. var $webMaster;
  27. var $pubDate;
  28. var $lastBuildDate;
  29. var $category;
  30. var $generator;
  31. var $docs;
  32. var $cloud;
  33. var $ttl;
  34. var $image;
  35. var $textinput;
  36. var $skipHours = array();
  37. var $skipDays = array();
  38. var $itemTitle;
  39. var $itemLink;
  40. var $itemDescription;
  41. var $itemAuthor;
  42. var $itemCategory;
  43. var $itemComments;
  44. var $itemEnclosure;
  45. var $itemGuid;
  46. var $itemPubDate;
  47. var $itemSource;
  48. var $path;
  49. var $filename;
  50. function rss($encoding = ''){
  51. $this->generator = 'SlideShare API library';
  52. $this->docs = 'http://developer.slideshare.net';
  53. if(!empty($encoding)){ $this->encoding = $encoding; }
  54. }
  55. function channel($title, $link, $description){
  56. $this->title = $title;
  57. $this->link = $link;
  58. $this->description = $description;
  59. }
  60. function language($language){ $this->language = $language; }
  61. function copyright($copyright){ $this->copyright = $copyright; }
  62. function managingEditor($managingEditor){ $this->managingEditor = $managingEditor; }
  63. function webMaster($webMaster){ $this->webMaster = $webMaster; }
  64. function pubDate($pubDate){ $this->pubDate = $pubDate; }
  65. function lastBuildDate($lastBuildDate){ $this->lastBuildDate = $lastBuildDate; }
  66. function category($category, $domain = ''){
  67. $this->category .= $this->s(2) . '<category';
  68. if(!empty($domain)){ $this->category .= ' domain="' . $domain . '"'; }
  69. $this->category .= '>' . $category . '</category>' . "\n";
  70. }
  71. function cloud($domain, $port, $path, $registerProcedure, $protocol){
  72. $this->cloud .= $this->s(2) . '<cloud domain="' . $domain . '" port="' . $port . '" registerProcedure="' . $registerProcedure . '" protocol="' . $protocol . '" />';
  73. }
  74. function ttl($ttl){ $this->ttl = $ttl; }
  75. function image($url, $title, $link, $width = '', $height = '', $description = ''){
  76. $this->image = $this->s(2) . '<image>' . "\n";
  77. $this->image .= $this->s(3) . '<url>' . $url . '</url>' . "\n";
  78. $this->image .= $this->s(3) . '<title>' . $title . '</title>' . "\n";
  79. $this->image .= $this->s(3) . '<link>' . $link . '</link>' . "\n";
  80. if($width != ''){ $this->s(3) . '<width>' . $width . '</width>' . "\n"; }
  81. if($height != ''){ $this->s(3) . '<height>' . $height . '</height>' . "\n"; }
  82. if($description != ''){ $this->s(3) . '<description>' . $description . '</description>' . "\n"; }
  83. $this->image .= $this->s(2) . '</image>' . "\n";
  84. }
  85. function textInput($title, $description, $name, $link){
  86. $this->textInput = $this->s(2) . '<textInput>' . "\n";
  87. $this->textInput .= $this->s(3) . '<title>' . $title . '</title>' . "\n";
  88. $this->textInput .= $this->s(3) . '<description>' . $description . '</description>' . "\n";
  89. $this->textInput .= $this->s(3) . '<name>' . $name . '</name>' . "\n";
  90. $this->textInput .= $this->s(3) . '<link>' . $link . '</link>' . "\n";
  91. $this->textInput .= $this->s(2) . '</textInput>' . "\n";
  92. }
  93. function skipHours(){
  94. $this->skipHours = array();
  95. $args = func_get_args();
  96. $this->skipHours = array_values($args);
  97. }
  98. function skipDays(){
  99. $this->skipDays = array();
  100. $args = func_get_args();
  101. $this->skipDays = array_values($args);
  102. }
  103. function startRSS($path = '.', $filename = 'rss'){
  104. $this->path = $path;
  105. $this->filename = $filename;
  106. $this->rss = '<?xml version="1.0"';
  107. if(!empty($this->encoding)){ $this->rss .= ' encoding="' . $this->encoding . '"'; }
  108. $this->rss .= '?>' . "\n";
  109. $this->rss .= '<rss version="2.0">' . "\n";
  110. $this->rss .= $this->s(1) . '<channel>' . "\n";
  111. $this->rss .= $this->s(2) . '<title>' . $this->title . '</title>' . "\n";
  112. $this->rss .= $this->s(2) . '<link>' . $this->link . '</link>' . "\n";
  113. $this->rss .= $this->s(2) . '<description>' . $this->description . '</description>' . "\n";
  114. if(!empty($this->language)){ $this->rss .= $this->s(2) . '<language>' . $this->language . '</language>' . "\n"; }
  115. if(!empty($this->copyright)){ $this->rss .= $this->s(2) . '<copyright>' . $this->copyright . '</copyright>' . "\n"; }
  116. if(!empty($this->managingEditor)){ $this->rss .= $this->s(2) . '<managingEditor>' . $this->managingEditor . '</managingEditor>' . "\n"; }
  117. if(!empty($this->webMaster)){ $this->rss .= $this->s(2) . '<webMaster>' . $this->webMaster . '</webMaster>' . "\n"; }
  118. if(!empty($this->pubDate)){ $this->rss .= $this->s(2) . '<pubDate>' . $this->pubDate . '</pubDate>' . "\n"; }
  119. if(!empty($this->lastBuildDate)){ $this->rss .= $this->s(2) . '<lastBuildDate>' . $this->lastBuildDate . '</lastBuildDate>' . "\n"; }
  120. if(!empty($this->category)){ $this->rss .= $this->category; }
  121. $this->rss .= $this->s(2) . '<generator>' . $this->generator . '</generator>' . "\n";
  122. $this->rss .= $this->s(2) . '<docs>' . $this->docs . '</docs>' . "\n";
  123. if(!empty($this->cloud)){ $this->rss .= $this->cloud; }
  124. if(!empty($this->ttl)){ $this->rss .= $this->s(2) . '<ttl>' . $this->ttl . '</ttl>' . "\n"; }
  125. if(!empty($this->image)){ $this->rss .= $this->image; }
  126. if(!empty($this->textInput)){ $this->rss .= $this->textInput; }
  127. if(count($this->skipHours) > 0){
  128. $this->rss .= $this->s(2) . '<skipHours>' . "\n";
  129. for($i = 0; $i < count($this->skipHours); $i++){
  130. $this->rss .= $this->s(3) . '<hour>' . $this->skipHours[$i] . '</hour>' . "\n";
  131. }
  132. $this->rss .= $this->s(2) . '</skipHours>' . "\n";
  133. }
  134. if(count($this->skipDays) > 0){
  135. $this->rss .= $this->s(2) . '<skipDays>' . "\n";
  136. for($i = 0; $i < count($this->skipDays); $i++){
  137. $this->rss .= $this->s(3) . '<day>' . $this->skipHours[$i] . '</day>' . "\n";
  138. }
  139. $this->rss .= $this->s(2) . '</skipDays>' . "\n";
  140. }
  141. }
  142. function itemTitle($title){ $this->itemTitle = $title; }
  143. function itemLink($link){ $this->itemLink = $link; }
  144. function itemDescription($description){ $this->itemDescription = $description; }
  145. function itemAuthor($author){ $this->itemAuthor = $author; }
  146. function itemCategory($category, $domain = ''){
  147. $this->itemCategory .= $this->s(3) . '<category';
  148. if(!empty($domain)){ $this->itemCategory .= ' domain="' . $domain . '"'; }
  149. $this->itemCategory .= '>' . $category . '</category>' . "\n";
  150. }
  151. function itemComments($comments){ $this->itemComments = $comments; }
  152. function itemEnclosure($enclosure){ $this->itemEnclosure = $enclosure; }
  153. function itemGuid($guid, $isPermaLink = ''){
  154. $this->itemGuid = $this->s(3) . '<guid';
  155. if(!empty($isPermaLink)){ $this->itemGuid .= ' isPermaLink="' . $isPermaLink . '"'; }
  156. $this->itemGuid .= '>' . $guid . '</guid>' . "\n";
  157. }
  158. function itemPubDate($pubDate){ $this->itemPubDate = $pubDate; }
  159. function itemSource($source, $url){
  160. $this->itemSource = $this->s(3) . '<source url="' . $url . '">' . $source . '</source>' . "\n";
  161. }
  162. function addItem(){
  163. $this->rss .= $this->s(2) . '<item>' . "\n";
  164. if(!empty($this->itemTitle)){ $this->rss .= $this->s(3) . '<title>' . $this->itemTitle . '</title>' . "\n"; }
  165. if(!empty($this->itemLink)){ $this->rss .= $this->s(3) . '<link>' . $this->itemLink . '</link>' . "\n"; }
  166. if(!empty($this->itemDescription)){ $this->rss .= $this->s(3) . '<description>' . $this->itemDescription . '</description>' . "\n"; }
  167. if(!empty($this->itemAuthor)){ $this->rss .= $this->s(3) . '<author>' . $this->itemAuthor . '</author>' . "\n"; }
  168. if(!empty($this->itemCategory)){ $this->rss .= $this->itemCategory; }
  169. if(!empty($this->itemComments)){ $this->rss .= $this->s(3) . '<comments>' . $this->itemComments . '</comments>' . "\n"; }
  170. if(!empty($this->itemEnclosure)){ $this->rss .= $this->s(3) . '<enclosure>' . $this->itemEnclosure . '</enclosure>' . "\n"; }
  171. if(!empty($this->itemGuid)){ $this->rss .= $this->itemGuid; }
  172. if(!empty($this->itemPubDate)){ $this->rss .= $this->s(3) . '<pubDate>' . $this->itemPubDate . '</pubDate>' . "\n"; }
  173. if(!empty($this->itemSource)){ $this->rss .= $this->itemSource; }
  174. $this->rss .= $this->s(2) . '</item>' . "\n";
  175. $this->itemTitle = '';
  176. $this->itemLink = '';
  177. $this->itemDescription = '';
  178. $this->itemAuthor = '';
  179. $this->itemCategory = '';
  180. $this->itemComments = '';
  181. $this->itemEnclosure = '';
  182. $this->itemGuid = '';
  183. $this->itemPubDate = '';
  184. $this->itemSource = '';
  185. }
  186. function RSSdone(){
  187. $this->rss .= $this->s(1) . '</channel>' . "\n";
  188. $this->rss .= '</rss>';
  189. $handle = fopen($this->path . '/'. $this->filename . '.xml', "w");
  190. fwrite($handle, $this->rss);
  191. fclose($handle);
  192. }
  193. function clearRSS(){
  194. $this->title = '';
  195. $this->link = '';
  196. $this->description = '';
  197. $this->language = '';
  198. $this->copyright = '';
  199. $this->managingEditor = '';
  200. $this->webMaster = '';
  201. $this->pubDate = '';
  202. $this->lastBuildDate = '';
  203. $this->category = '';
  204. $this->cloud = '';
  205. $this->ttl = '';
  206. $this->skipHours = array();
  207. $this->skipDays = array();
  208. }
  209. function s($space){
  210. $s = '';
  211. for($i = 0; $i < $space; $i++){ $s .= ' '; }
  212. return $s;
  213. }
  214. }
  215. ?>