Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. <?php
  2.  
  3. $RSS_Content = array();
  4.  
  5. function RSS_Tags($item, $type = 1, $channel_name="", $image="")
  6. {
  7. $y = array();
  8. $tnl = $item->getElementsByTagName("title");
  9. $tnl = $tnl->item(0);
  10. $title = $tnl->firstChild->textContent;
  11.  
  12. $tnl = $item->getElementsByTagName("link");
  13. $tnl = $tnl->item(0);
  14. $link = $tnl->firstChild->textContent;
  15.  
  16. $tnl = $item->getElementsByTagName("pubDate");
  17. $tnl = $tnl->item(0);
  18. $date = $tnl->firstChild->textContent;
  19.  
  20. if( $type )
  21. {
  22. $tnl = $item->getElementsByTagName("description");
  23. $tnl = $tnl->item(0);
  24. $description = $tnl->firstChild->textContent;
  25. $y["description"] = $description;
  26. }
  27.  
  28. $y["channel"] = $channel_name;
  29. $y["title"] = $title;
  30. $y["link"] = $link;
  31. $y["date"] = $date;
  32. $y["type"] = $type;
  33. $y["image"] = $image;
  34.  
  35. return $y;
  36. }
  37.  
  38. function RSS_Channel( $channel, $key )
  39. {
  40. global $RSS_Content;
  41.  
  42. $items = $channel->getElementsByTagName("item");
  43.  
  44. $y = RSS_Tags($channel, 0);
  45. $channel_name = $y['title'];
  46.  
  47. foreach($items as $item)
  48. {
  49. $y = RSS_Tags($item, 1, $channel_name, $key);
  50.  
  51. array_push($RSS_Content, $y);
  52. }
  53. }
  54.  
  55. function RSS_Retrieve( $urls = array() )
  56. {
  57. global $RSS_Content;
  58. $RSS_Content = array();
  59.  
  60. foreach ( $urls as $key => $url )
  61. {
  62. $doc_{$key} = new DOMDocument();
  63. $doc_{$key}->load( $url );
  64. $channels_{$key} = $doc_{$key}->getElementsByTagName("channel");
  65.  
  66. foreach( $channels_{$key} as $channel )
  67. {
  68. RSS_Channel( $channel, $key );
  69. }
  70. }
  71.  
  72. }
  73.  
  74. function RSS_RetrieveLinks($url)
  75. {
  76. global $RSS_Content;
  77.  
  78. $doc = new DOMDocument();
  79. $doc->load($url);
  80.  
  81. $channels = $doc->getElementsByTagName("channel");
  82.  
  83. $RSS_Content = array();
  84.  
  85. foreach($channels as $channel)
  86. {
  87. $items = $channel->getElementsByTagName("item");
  88. foreach($items as $item)
  89. {
  90. $y = RSS_Tags($item, 1);
  91. array_push($RSS_Content, $y);
  92. }
  93. }
  94.  
  95. }
  96.  
  97. function NO_EDIT( $urls=array(), $size = 15, $site = 0 )
  98. {
  99. echo "<p align=right></p>";
  100. }
  101.  
  102. function RSS_Links($url, $size = 15)
  103. {
  104. global $RSS_Content;
  105.  
  106. $page = "<ul>";
  107.  
  108. RSS_RetrieveLinks($url);
  109. if($size > 0)
  110. $recents = array_slice($RSS_Content, 0, $size + 1);
  111.  
  112. foreach($recents as $article)
  113. {
  114. $type = $article["type"];
  115. if($type == 0) continue;
  116. $title = $article["title"];
  117. $link = $article["link"];
  118. $page .= "<li><a href=\"$link\">$title</a></li>\n";
  119. }
  120.  
  121. $page .="</ul>\n";
  122.  
  123. return $page;
  124. }
  125.  
  126.  
  127. function RSS_Display( $urls=array(), $size = 15, $site = 0 )
  128. {
  129. global $RSS_Content;
  130.  
  131. $site = 0;
  132. $opened = false;
  133. $page = "";
  134. $site = (intval($site) == 0) ? 1 : 0;
  135.  
  136. RSS_Retrieve( $urls );
  137. //RSS_Sort();
  138. @uksort($RSS_Content, 'mySort');
  139.  
  140. if($size > 0)
  141. {
  142. $recents = array_slice($RSS_Content, 0, $size);
  143. }
  144.  
  145. $page .= "<table cellpadding=\"5\" cellspacing=\"5\">";
  146. foreach($recents as $article)
  147. {
  148. $channel = $article["channel"];
  149. $title = $article["title"];
  150. $link = $article["link"];
  151. $description = $article["description"];
  152. $date = $article["date"];
  153. $image = $article["image"];
  154. $page .= "<tr class=\"row_1\">
  155. <td class=\"news\" width='50'><img src=\"status/img/$image.png\" /></td>
  156. <td class=\"title\" width='100'>
  157. <a target=\"_blank\" href=\"$link\">".substr($title, 0, 40)."...</a>
  158. </td>
  159. <td class=\"date\">
  160. <span class=\"date\">" . strftime('%d %b, %Y', strtotime( $date ) ) . "</span>
  161. </td>
  162. </tr>
  163. ";
  164. }
  165. $page .= "</table>";
  166. return $page."\n";
  167. }
  168.  
  169. function mySort($a, $b){
  170. global $RSS_Content;
  171. return strcmp($RSS_Content[$a]['date'], $RSS_Content[$b]['date']);
  172. }
  173.  
  174. function RSS_Sort()
  175. {
  176. global $RSS_Content;
  177.  
  178. for( $i =0; $i < count( $RSS_Content ); $i++ )
  179. {
  180. $array = array();
  181. for( $j =$i+1; $j < count( $RSS_Content ) - $i; $j++ )
  182. {
  183. if( strtotime($RSS_Content[$i]['date']) < strtotime($RSS_Content[$j]['date']) )
  184. {
  185. $temp = array(
  186. 'channel' => $RSS_Content[$i]['channel'],
  187. 'title' => $RSS_Content[$i]['title'],
  188. 'link' => $RSS_Content[$i]['link'],
  189. 'date' => $RSS_Content[$i]['date'],
  190. 'description' => $RSS_Content[$i]['description'],
  191. 'image' => $RSS_Content[$i]['image'],
  192. 'type' => $RSS_Content[$i]['type'],
  193. );
  194.  
  195. $temp2 = array(
  196. 'channel' => $RSS_Content[$j]['channel'],
  197. 'title' => $RSS_Content[$j]['title'],
  198. 'link' => $RSS_Content[$j]['link'],
  199. 'date' => $RSS_Content[$j]['date'],
  200. 'description' => $RSS_Content[$j]['description'],
  201. 'type' => $RSS_Content[$j]['type'],
  202. 'image' => $RSS_Content[$j]['image'],
  203. );
  204.  
  205. $RSS_Content[$i] = $temp2;
  206. $RSS_Content[$j] = $temp;
  207.  
  208.  
  209.  
  210. }
  211. }
  212. }
  213. }
  214.  
  215. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement