Witam... korzystam ze skryptu do odczytu RSS i teraz jesli w skrocie wiadomosci jest " to sie sypie mi wyswietlanie poprzez overlib.js :/ gdzie musze dodac htmlspecialchars aby mi #{description} dzialalo odpowiednio?

  1. <?php
  2. /************************************************************
  3. RSS Fetch 0.4.1
  4. RSS Feed Reader
  5. Author: Drew Phillips
  6. www.neoprogrammers.com
  7. Copyright 2005 Drew Phillips
  8.  
  9. This program is free software; you can redistribute it and/or
  10. modify it under the terms of the GNU General Public License
  11. as published by the Free Software Foundation; either version 2
  12. of the License, or (at your option) any later version.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  22.  
  23.  
  24.  
  25. ************************************************************/
  26.  
  27.  
  28.  
  29. class rss_parser {
  30. var $update_interval = 60;
  31. /* How often to fetch the rss file
  32.  A cached version will be used between updates */
  33.  
  34. var $data_directory = "/home/public_html/forum/portal";
  35. /* Where to store the rss data from the feeds
  36.  Note: an absolute path is better than a relative path here
  37.  unless you plan on keeping the script to display the feeds
  38.  in the same folder as this file and the feeds.  */
  39.  
  40.  
  41.  
  42. /* NO NEED TO EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING */
  43.  
  44.  
  45. var $rss_url;
  46. var $num_to_show;
  47. var $do_update;
  48. var $tags = array();
  49. var $content;
  50. var $rss = array();
  51.  
  52. var $feed_title;
  53. var $feed_link;
  54. var $feed_description;
  55.  
  56. var $my_html;
  57.  
  58. function rss_parser($url, $numtoshow = 10, $html = "", $update = 0)
  59. {
  60. $this->rss_url = $url;
  61. $this->num_to_show = $numtoshow;
  62. $this->do_update = $update;
  63. $this->my_html = preg_replace("/(#{.*?):(.*?})/", "\\1__\\2", $html); //xx:xx tag workaround
  64.  
  65. $this->content = $this->fetch_feed();
  66. $this->parse_feed();
  67. $this->show();
  68. }
  69.  
  70.  
  71. /* string */
  72. function fetch_feed()
  73. { 
  74. $url_parts = parse_url($this->rss_url);
  75.  
  76. $filename = $url_parts['host'] . str_replace("/", ",", $url_parts['path']) . "_" . @$url_parts['query'];
  77. if(file_exists($this->data_directory . "/$filename")) {
  78. $last = filemtime($this->data_directory . "/$filename");
  79. if(time() - $last > $this->update_interval * 60 || $this->update_interval == 0) {
  80. $update = 1;
  81. }
  82. } else {
  83. $create= 1;
  84. }
  85.  
  86. if($create == 1 || ($this->do_update == TRUE && $update == 1)) {
  87. $fp = @fsockopen($url_parts['host'], 80, $errno, $errstr, 5);
  88. if (!$fp) {
  89. echo "Couldn't open rss feed {$this->feed_url} in {$_SERVER['PHP_SELF']}<br />\n";
  90. return;
  91. }
  92.  
  93. fputs($fp, "GET " . $url_parts['path'] . "?" . @$url_parts['query'] . " HTTP/1.0\r\n"
  94. ."Host: " . $url_parts['host'] . "\r\n"
  95. ."User-Agent: Drew's RSS Reader 0.1\r\n"
  96. ."Connection: Close\r\n\r\n");
  97.  
  98. while(!feof($fp)) {
  99. $rss_data .= @fgets($fp, 1024);
  100. }
  101.  
  102. list(, $rss_data) = explode("\r\n\r\n", $rss_data, 2);
  103.  
  104. $output = @fopen($this->data_directory . "/$filename", "w+");
  105. if(!$output) {
  106. return $rss_data;
  107. } else {
  108. flock($output, LOCK_EX);
  109. fputs($output, $rss_data);
  110. flock($output, LOCK_UN);
  111. fclose($output);
  112. }
  113. } //update
  114.  
  115. return file_get_contents($this->data_directory . "/$filename");
  116. }
  117.  
  118. /* void */
  119. function parse_feed()
  120. {
  121. preg_match("/<title>(.*?)<\/title>/", $this->content, $title);
  122. $this->feed_title = @$title[1];
  123.  
  124. preg_match("/<link>(.*?)<\/link>/", $this->content, $link);
  125. $this->feed_link = @$link[1];
  126.  
  127. preg_match("/<description>(.*?)<\/description>/", $this->content, $description);
  128. $this->feed_description = @$description[1];
  129.  
  130. preg_match_all("/<item[^>]*>(.*?)<\/item>/s", $this->content, $items);
  131. if (sizeof($items[0]) == 0) {
  132. echo "No item elements found in rss feed.<br />\n";
  133. }
  134.  
  135. for($i = 0; $i < sizeof($items[0]); ++$i) {
  136. preg_match_all("/(?:<([\w:]*)[^>]*>(?:<!\[CDATA\[)?(.*?)(?:]]>)?<\/\\1>)+?/si", preg_replace("/<item[^>]*>/", "", $items[0][$i]), $elements);
  137. for($j = 0; $j < sizeof($elements[0]); ++$j) {
  138. $elements[1][$j] = str_replace(":", "__", $elements[1][$j]); //regex fix for items with : like dc:date
  139. $this->rss[$i][$elements[1][$j]] = trim(html_entity_decode(($elements[2][$j]));
  140. }
  141. }
  142. }
  143.  
  144.  
  145. /* void */
  146. function show()
  147. {
  148. if($this->my_html == "") {
  149. $this->show_html();
  150. } else {
  151. $this->show_user_html();
  152. }
  153. }
  154.  
  155. function show_html()
  156. {
  157. $show = (sizeof($this->rss) > $this->num_to_show ? $this->num_to_show : sizeof($this->rss));
  158. for($i = 0; $i < $show; ++$i) {
  159. echo "- <a href=\"{$this->rss[$i]['link']}\" target=\"_new\">{$this->rss[$i]['title']}</a><br />\n";
  160. }
  161. }
  162.  
  163. function show_user_html()
  164. {
  165. $show = (sizeof($this->rss) > $this->num_to_show ? $this->num_to_show : sizeof($this->rss));
  166. for($i = 0; $i < $show; ++$i) {
  167. extract($this->rss[$i]);
  168. $item = preg_replace("/#\{([^}]+)}/e", "$\\1", $this->my_html);
  169. echo $item;
  170. }
  171. }
  172.  
  173. } // end class
  174. ?>