With over !NaN! hits and counting!

SuperSimpleLifeTracker

Here's a snippet I wrote to merge RSS feeds using SimplePie. It's used on the right of this page.

Code

Download.
  1. <?php
  2. // SuperSimpleLifeTracker 1.0
  3. // Produces a combined feed from several RSS feeds as a DIV you can include
  4. // Copyright 2010, David Hayes
  5. // http://euri.ca/code/SuperSimpleLifeTracker
  6.  
  7. $feeds = array(
  8. 'http://url',
  9. 'http://url',
  10. 'http://url',
  11. 'http://url',
  12. );
  13. $cacheLocation = './cache'; //needs to be somewhere writeable
  14. $cacheTimeInHours = 2;
  15. $pathToSimplePie = 'simplepie_1.2/simplepie.inc';
  16. $itemsPerRSSFeed = 2; //Looks best when this is about 15/sizeof($feeds)
  17.  
  18. /* This file is part of SuperSimpleLifeTracker.
  19.  
  20.   SuperSimpleLifeTracker is free software: you can redistribute it and/or modify
  21.   it under the terms of the GNU General Public License as published by
  22.   the Free Software Foundation, either version 3 of the License, or
  23.   (at your option) any later version.
  24.  
  25.   SuperSimpleLifeTracker is distributed in the hope that it will be useful,
  26.   but WITHOUT ANY WARRANTY; without even the implied warranty of
  27.   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28.   GNU General Public License for more details.
  29.  
  30.   You may have received a copy of the GNU General Public License
  31.   along with Foobar. If not, see <http://www.gnu.org/licenses/>.
  32. */
  33.  
  34. //SimplePie 1.2 throws DEPRECATED about 100 times on PHP 5.2
  35. $current_error_reporting_level = error_reporting();
  36. if(defined('E_DEPRECATED'))
  37. error_reporting($current_error_reporting_level ^ E_DEPRECATED);
  38.  
  39. function shorten($summary, $length=200) {
  40. $summary = strip_tags($summary); //For XSS, I'm going to run everything we print out through here.
  41. if(strlen($summary) > $length) {
  42. $summary = substr($summary, 0, $length-3)."...";
  43. }
  44. return $summary;
  45. }
  46.  
  47. require_once($pathToSimplePie);
  48. $feed = new SimplePie();
  49. $feed->set_feed_url($feeds);
  50. $feed->enable_cache(true);
  51. $feed->set_cache_location($cacheLocation );
  52. $feed->set_cache_duration($cacheTimeInHours * 3600);
  53. $feed->set_item_limit($itemsPerRSSFeed);
  54. $feed->init();
  55. $feed->handle_content_type();
  56. if ($feed->error())
  57. {
  58. echo $feed->error();
  59. }
  60. ?>
  61.  
  62. <style>
  63. .rssitem img.favicon { height: 32px; width: 32px; border:0;}
  64. .rssitem .rssdesc { font-size: 80%; color: #555; text-decoration: none !important;}
  65. .rssitem a { text-decoration: none; color: #007; display: block; opacity: .5;}
  66. .rssitem a:visited { color: #007; }
  67. .rssitem a:hover { color: #00f; background-color: #ffd; opacity: 1.0 !important;}
  68. .rssitem {margin-bottom: 8px; font-size: 80%; }
  69. div.rssfeed { }
  70. </style>
  71.  
  72. <h4>What I've said lately</h4>
  73. <div class="rssfeed"><!-- SuperSimpleLifeTracker, http://euri.ca --> <?/* <-- Please leave this comment in if you use the script :) */?>
  74. <?php
  75. $opacity = 1;
  76. $opacityDecrement = .95/(sizeof($feed->get_items())+1);
  77. foreach ($feed->get_items() as $item) {
  78. $thisfeed = $item->get_feed();
  79. $opacity -= $opacityDecrement;
  80. ?>
  81. <div class="rssitem">
  82. <a href="<?php echo shorten($item->get_permalink(),512); ?>" title="From <?php echo shorten($thisfeed->get_title()); ?>, <?php echo $item->get_date('j F Y, g:i a'); ?>"
  83. style="opacity: <?php echo $opacity; ?>"
  84. ><img src="<?php echo $thisfeed->get_favicon(); ?>" alt="From <?php echo $thisfeed->get_title(); ?>" class='favicon' align="left" /> <?php echo shorten($item->get_title(), 140)?>
  85. <?php if(shorten($item->get_description()) != shorten($item->get_title())) { /*aka: Twitter feeds */?>
  86. <span class="rssdesc"><?php echo shorten($item->get_description(),80); ?></span>
  87. <?php } ?>
  88. </a>
  89. </div>
  90. <?php } ?>
  91. </div>
  92.  
  93. <?
  94. error_reporting($current_error_reporting_level);
  95. ?>
  96.  


Programming Math etc

What I've said lately

Loading feeds

More of me on the web