PageRenderTime 52ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/rss/include/P_BLOG_RSS.class.php

https://github.com/kaz6120/P_BLOG
PHP | 220 lines | 162 code | 20 blank | 38 comment | 17 complexity | d9559d06fb60afaacc92efbc382b492a MD5 | raw file
  1. <?php
  2. /**
  3. * RSS 2.0 Class
  4. *
  5. * @author P_BLOG Project
  6. * @since 2005-11-28 09:59:34
  7. * updated 2006-03-23 00:06:36
  8. */
  9. // P_BLOG RSS Class
  10. class P_BLOG_RSS {
  11. // Get Items
  12. function getItems($link, $title, $row)
  13. {
  14. global $cfg;
  15. $enclosures = $this->getEnclosure($row['comment']);
  16. $row['comment'] = $this->convertEnclosure($row['comment']);
  17. // Article Content
  18. $row['comment'] = str_replace(
  19. './resources/',
  20. 'http://' . $_SERVER['HTTP_HOST'] . $cfg['root_path'] . 'resources/',
  21. $row['comment']
  22. );
  23. // Description
  24. $description = htmlspecialchars(mb_substr(strip_tags($row['comment']), 0, 120, 'UTF-8')) . '...';
  25. return '<item>
  26. <title>'. $title.'</title>
  27. <link>'. $link .'</link>
  28. <pubDate>'.date('D, d M Y H:i:s ', strtotime($row['date'])).tz().'</pubDate>
  29. <description>' . $description . '</description>'.$enclosures.'
  30. <content:encoded>
  31. <![CDATA['. $row['comment'] . ']]>
  32. </content:encoded>
  33. </item>';
  34. }
  35. /**
  36. * Get Enclosure Information
  37. *
  38. * @param string $enclosure_name
  39. * @return array $item
  40. */
  41. function getEnclosureInfo($enclosure_name)
  42. {
  43. global $cd, $cfg;
  44. $filename = 'resources/'.$enclosure_name;
  45. $enclosure_path = $cd . '/' . $filename;
  46. if (file_exists($enclosure_path)) {
  47. $enclosure_name = $enclosure_name;
  48. $enclosure_size = filesize($enclosure_path);
  49. $enclosure_uri = 'http://' . $_SERVER['HTTP_HOST'] . $cfg['root_path'] . $filename;
  50. } else {
  51. $enclosure_name = '';
  52. $enclosure_size = '';
  53. $enclosure_uri = '';
  54. }
  55. $item['enclosure_name'] = $enclosure_name;
  56. $item['enclosure_size'] = $enclosure_size;
  57. $item['enclosure_uri'] = $enclosure_uri;
  58. return $item;
  59. }
  60. /**
  61. * Get Enclosure Node
  62. *
  63. * @param string $enclosure_name
  64. * @return string
  65. */
  66. function getEnclosureNode($enclosure_name)
  67. {
  68. global $cd;
  69. $item = $this->getEnclosureInfo($enclosure_name);
  70. if (($item['enclosure_name'] != '') &&
  71. ($item['enclosure_size'] != '') &&
  72. ($item['enclosure_uri'] != '')) {
  73. $enclosure = '<enclosure '.
  74. 'url="'.$item['enclosure_uri'].'" '.
  75. 'length="'.$item['enclosure_size'].'" '.
  76. 'type="audio/mpeg" />'."\n";
  77. } else {
  78. $enclosure = '';
  79. }
  80. return $enclosure;
  81. }
  82. /**
  83. * Get Enclosure
  84. *
  85. * @param string $comment
  86. * @return string $enclosure
  87. */
  88. function getEnclosure($comment)
  89. {
  90. global $cd;
  91. preg_match_all('/<!-- ?PODCAST=.*\.(mp3|m4a|m4v|mov|wav) ?-->/', $comment, $matches);
  92. $enclosure = '';
  93. for ($i = 0; $i < count($matches[0]); $i++) {
  94. $enclosure_name = substr($matches[0][$i], 13, strpos($matches[0][$i], ' -->')-13);
  95. $enclosure .= $this->getEnclosureNode($enclosure_name);
  96. }
  97. return $enclosure;
  98. }
  99. /**
  100. * Convert Enclosure
  101. *
  102. * @param string $comment
  103. * @return string $comment
  104. */
  105. function convertEnclosure($comment)
  106. {
  107. global $cd;
  108. preg_match_all('/<!-- ?PODCAST=.*\.(mp3|m4a|m4v|mov|wav) ?-->/', $comment, $matches);
  109. $enclosure = '';
  110. for ($i = 0; $i < count($matches[0]); $i++) {
  111. $enclosure_name = substr($matches[0][$i], 13, strpos($matches[0][$i], ' -->')-13);
  112. $item = $this->getEnclosureInfo($enclosure_name);
  113. if (($item['enclosure_name'] != '') &&
  114. ($item['enclosure_size'] != '') &&
  115. ($item['enclosure_uri'] != '')) {
  116. $item['enclosure_size'] = toMB($item['enclosure_size']);
  117. if (stristr($item['enclosure_name'], '.mov')) {
  118. $item['enclosure_class'] = 'mov';
  119. $item['enclosure_mime'] = 'video/quicktime';
  120. } elseif (stristr($item['enclosure_name'], '.m4')) {
  121. $item['enclosure_class'] = 'm4';
  122. $item['enclosure_mime'] = 'audio/mpeg';
  123. } elseif (stristr($item['enclosure_name'], '.wav')) {
  124. $item['enclosure_class'] = 'wav';
  125. $item['enclosure_mime'] = 'audio/mpeg';
  126. } else {
  127. $item['enclosure_class'] = 'mp3';
  128. $item['enclosure_mime'] = 'audio/mpeg';
  129. }
  130. $enclosure_text = '<div class="podcast '.$item['enclosure_class'].'">
  131. <p><strong><a href="'.$item['enclosure_uri'].'">'.$item['enclosure_name'].'</a></strong></p>
  132. <p>( '.$item['enclosure_mime'].' : '. $item['enclosure_size'].' )</p>
  133. </div>';
  134. $comment = preg_replace('/' .$matches[0][$i].'/', $enclosure_text, $comment);
  135. }
  136. }
  137. return $comment;
  138. }
  139. /**
  140. * Feed RSS
  141. */
  142. function feedRSS2()
  143. {
  144. global $cfg, $id, $tid, $row, $row2, $items, $item,
  145. $tz, $log_table, $f_index, $forum_table;
  146. if (isset($tid)) {
  147. $link = 'http://' . $_SERVER['HTTP_HOST'] . $cfg['root_path'] .
  148. 'forum/topic.php?tid=' . $tid . '&amp;p=0';
  149. $topic_title = ' - Forum Topic No:' . $tid;
  150. $d_sql = "SELECT DATE_FORMAT(`date`, '%Y-%m-%dT%T') as `date` ".
  151. "FROM `{$forum_table}` ORDER BY `date` desc LIMIT 1";
  152. $d_res = mysql_query($d_sql);
  153. $d_row = mysql_fetch_array($d_res);
  154. $date = date('D, d M Y H:i:s ', strtotime($d_row['date'])).$tz;
  155. } elseif (isset($id)) {
  156. $link = 'http://' . $_SERVER['HTTP_HOST'] . $cfg['root_path'] . $cfg['top_page'];
  157. $topic_title = '';
  158. $date = date('D, d M Y H:i:s ', strtotime($row['date'])).$tz;
  159. } elseif (isset($f_index)) {
  160. $link = 'http://' . $_SERVER['HTTP_HOST'] . $cfg['root_path'] . 'forum/index.php';
  161. $topic_title = ' - Forum Index';
  162. $d_sql = "SELECT DATE_FORMAT(`date`, '%Y-%m-%dT%T') as `date` ".
  163. "FROM `{$forum_table}` WHERE `parent_key` = 1 ORDER BY `date` DESC LIMIT 1";
  164. $d_res = mysql_query($d_sql);
  165. $d_row = mysql_fetch_array($d_res);
  166. $date = date('D, d M Y H:i:s ', strtotime($d_row['date'])).$tz;
  167. } else {
  168. $link = 'http://' . $_SERVER['HTTP_HOST'] . $cfg['root_path'] . $cfg['top_page'];
  169. $topic_title = '';
  170. $d_sql = "SELECT DATE_FORMAT(`date`, '%Y-%m-%dT%T') as `date` ".
  171. "FROM `{$log_table}` ".
  172. "WHERE `draft` = '0' ORDER BY `date` desc LIMIT 1";
  173. $d_res = mysql_query($d_sql);
  174. $d_row = mysql_fetch_array($d_res);
  175. $date = date('D, d M Y H:i:s ', strtotime($d_row['date'])).$tz;
  176. }
  177. $blog_title = $cfg['blog_title'];
  178. header("Content-type: application/xml");
  179. echo <<<RSS_FEED
  180. <?xml version="1.0" encoding="{$cfg['charset']}"?>
  181. <rss version="2.0"
  182. xmlns:dc="http://purl.org/dc/elements/1.1/"
  183. xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  184. xmlns:admin="http://webns.net/mvcb/"
  185. xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  186. xmlns:content="http://purl.org/rss/1.0/modules/content/">
  187. <channel>
  188. <title>{$cfg['blog_title']}{$topic_title}</title>
  189. <link>{$link}</link>
  190. <pubDate>{$date}</pubDate>
  191. <description>
  192. {$cfg['blog_title']} - RSS 2.0 (Really Simple Syndication).
  193. </description>
  194. {$item}
  195. </channel>
  196. </rss>
  197. RSS_FEED;
  198. }
  199. }
  200. ?>