/mods/bloxx_rssdisplay.php

https://github.com/telmomenezes/bloxx · PHP · 158 lines · 106 code · 31 blank · 21 comment · 14 complexity · a505dd0ffd8eb93c04f1dc84ce8a28a0 MD5 · raw file

  1. <?php
  2. // Bloxx - Open Source Content Management System
  3. //
  4. // Copyright (c) 2002 - 2005 The Bloxx Team. All rights reserved.
  5. //
  6. // Bloxx is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation; either version 2 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // Bloxx is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. // You should have received a copy of the GNU General Public License
  16. // along with Bloxx; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. //
  19. // Authors: Telmo Menezes <telmo@cognitiva.net>
  20. //
  21. // $Id: bloxx_rssdisplay.php,v 1.6 2005-08-08 16:38:35 tmenezes Exp $
  22. require_once 'defines.php';
  23. require_once(CORE_DIR.'bloxx_module.php');
  24. class Bloxx_RssDisplay extends Bloxx_Module
  25. {
  26. function Bloxx_RssDisplay()
  27. {
  28. $this->_BLOXX_MOD_PARAM['name'] = 'rssdisplay';
  29. $this->_BLOXX_MOD_PARAM['module_version'] = 1;
  30. $this->_BLOXX_MOD_PARAM['use_init_file'] = false;
  31. $this->Bloxx_Module();
  32. }
  33. function tableDefinition()
  34. {
  35. return array();
  36. }
  37. function getLocalRenderTrusts()
  38. {
  39. return array(
  40. 'rss_display' => TRUST_GUEST
  41. );
  42. }
  43. function getStyleList()
  44. {
  45. return array(
  46. 'Title' => 'NormalTitle',
  47. 'Text' => 'NormalText',
  48. 'Link' => 'NormalLink'
  49. );
  50. }
  51. function doRender($mode, $id, $target)
  52. {
  53. $this->style = new Bloxx_Style();
  54. $this->style_title = $this->getGlobalStyle('Title');
  55. $this->style_text = $this->getGlobalStyle('Text');
  56. $this->style_link = $this->getGlobalStyle('Link');
  57. $this->html_out = '';
  58. if($mode == 'rss_display'){
  59. $parser = xml_parser_create();
  60. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
  61. xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, 'ISO-8859-1');
  62. xml_set_object($parser, $this);
  63. xml_set_element_handler($parser, "tag_open", "tag_close");
  64. xml_set_character_data_handler($parser, "cdata");
  65. if(!($fp = fopen("http://www.wired.com/news/feeds/rss2/0,2610,3,00.xml", "r"))){
  66. //could not open XML input
  67. return false;
  68. }
  69. while ($data = fread($fp, 4096)) {
  70. if (!xml_parse($parser, $data, feof($fp))) {
  71. die(sprintf("XML error: %s at line %d",
  72. xml_error_string(xml_get_error_code($parser)),
  73. xml_get_current_line_number($parser)));
  74. }
  75. }
  76. xml_parser_free($parser);
  77. return $this->html_out;
  78. }
  79. }
  80. function tag_open($parser, $tag, $attributes)
  81. {
  82. $this->current_tag = $tag;
  83. if($tag == 'item'){
  84. $this->in_item = true;
  85. $this->parser_item = false;
  86. }
  87. else if($this->in_item){
  88. $this->parser_item = true;
  89. }
  90. else{
  91. $this->in_item = false;
  92. $this->parser_item = false;
  93. }
  94. }
  95. function cdata($parser, $cdata)
  96. {
  97. if($this->parser_item){
  98. $this->last_field = $this->current_field;
  99. $field = $this->current_tag;
  100. $this->current_field = $field;
  101. if($this->last_field == $this->current_field){
  102. $this->$field .= $cdata;
  103. }
  104. else{
  105. $this->$field = $cdata;
  106. }
  107. }
  108. }
  109. function tag_close($parser, $tag)
  110. {
  111. $this->parser_item = false;
  112. if($tag == 'item'){
  113. $this->in_item = false;
  114. $this->html_out .= $this->style->renderStyleHeader($this->style_title);
  115. $this->html_out .= $this->title;
  116. $this->html_out .= $this->style->renderStyleFooter($this->style_title);
  117. $this->html_out .= $this->style->renderStyleHeader($this->style_text);
  118. $this->html_out .= $this->description;
  119. $this->html_out .= $this->style->renderStyleFooter($this->style_text);
  120. $this->html_out .= $this->style->renderStyleHeader($this->style_link);
  121. $this->html_out .= '&nbsp;<a href="' . $this->link . '">>></a>';
  122. $this->html_out .= $this->style->renderStyleFooter($this->style_link);
  123. $this->html_out .= '<br><br>';
  124. }
  125. }
  126. }
  127. ?>