Posted By

rfbn on 10/24/10


Tagged

rss feed news aggregator football


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

superman


Football News Aggregator


 / Published in: PHP
 

URL: http://github.com/downloads/recentfootballnews/Recent-Football-News/rfbn.rar

  1. <?php
  2. /**************************************************************************
  3. This PHP script allow you to parse multiple feeds from different sources
  4. into separate pages using SimplePie class. A fast and efficient way to
  5. serve fresh content to your site as to provides the most up-to-date
  6. information to the readers.
  7.  
  8. This is also a basic guide on how to create an RSS Aggregator like the one
  9. on recentfootballnews.com. To improve the script functionality, you might
  10. need to be familiar with using SimplePie.
  11.  
  12. Requirements: http://simplepie.org/wiki/setup/requirements
  13.  
  14. Documentation: http://simplepie.org/wiki/
  15.  
  16. Copyright (c) 2010, recentfootballnews.com
  17. All rights reserved.
  18.  
  19. Redistribution and use in source and binary forms, with or without
  20. modification, are permitted provided that the following conditions are met:
  21.  
  22.  * Redistributions of source code must retain the above copyright notice,
  23.   this list of conditions and the following disclaimer.
  24.  * Redistributions in binary form must reproduce the above copyright
  25.   notice, this list of conditions and the following disclaimer in the
  26.   documentation and/or other materials provided with the distribution.
  27.  * Neither the name of Recent Football News nor the names of its
  28.   contributors may be used to endorse or promote products derived from
  29.   this software without specific prior written permission.
  30.  
  31. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  32. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  35. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  36. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  37. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  38. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  39. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. POSSIBILITY OF SUCH DAMAGE.
  42. ***************************************************************************/
  43. require 'simplepie.inc';
  44. $feed = new SimplePie();
  45. $feed->set_feed_url(array('http://feeds.feedburner.com/recentfootballnews',
  46. 'http://www.fifa.com/rss/index.xml')); // Add your favorites RSS feeds
  47. $success = $feed->init();
  48. $feed->handle_content_type();
  49. if(!isset($_GET['page'])){
  50. $page = 1;
  51. } else {
  52. $page = $_GET['page'];
  53. }
  54. $limit = 10; // Configure how many items to display per page
  55. $start = (($page * $limit) );
  56. $end = (($page * $limit) + $limit);
  57. ?><html>
  58. <head>
  59. <title>Recent Football News</title>
  60. </head>
  61. <body>
  62. <?php if($success): ?>
  63. <?php
  64. $new = array();
  65. $new2 = array();
  66. foreach($feed->get_items() as $item)
  67. {
  68. $yesterday = time() - (24*60*60);
  69. if($item->get_date('U') > $yesterday)
  70. {
  71. $new[] = $item;
  72. }
  73. }
  74. $max = ceil(count($new) / $limit);
  75. foreach($new AS $key => $val)
  76. {
  77. if($key >= $start && $key < $end)
  78. $new2[] = $new[$key];
  79. }
  80. foreach($new2 as $item): ?>
  81. <div>
  82. <h2><?php echo $item->get_title(); ?></h2>
  83. <p><small><?php echo $item->get_date('r'); ?></small></p>
  84. <p><?php echo $item->get_description(); ?></p>
  85. <p><a href='<?php echo $item->get_permalink(); ?>' target='_blank'>Read more &rarr;</a></p>
  86. </div>
  87. <?php endforeach; ?>
  88. <?php endif; ?>
  89. <div>
  90. <?php
  91. $max = $max -1;
  92. if($page > 1)
  93. {
  94. $back = ($page - 1);
  95. echo "<a href='&#63;page=$back'>Back</a>";
  96. }
  97. for($i = 1; $i <= $max; $i++){
  98. if(($page) == $i){
  99. echo "<span class='current'>$i</span>";
  100. } else {
  101. echo "<a href='&#63;page=$i'>$i</a>";
  102. }
  103. }
  104. if($page < $max){
  105. $next = ($page + 1);
  106. echo "<a href='&#63;page=$next'>Next</a>";
  107. }
  108. ?>
  109. </div>
  110. </body>
  111. </html>

Report this snippet  

You need to login to post a comment.