asset_rss_renderer.class.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * Rss renderer. Display RSS thanks to Google feed control.
  4. *
  5. * @see http://www.google.com/uds/solutions/dynamicfeed/reference.html
  6. * @see http://code.google.com/apis/ajax/playground/#dynamic_feed_control_-_vertical
  7. *
  8. * @copyright (c) 2011 University of Geneva
  9. * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
  10. * @author Laurent Opprecht
  11. */
  12. class AssetRssRenderer extends AssetRenderer
  13. {
  14. /**
  15. *
  16. * @param HttpResource $asset
  17. */
  18. public function render($asset)
  19. {
  20. if (!$asset->is_rss())
  21. {
  22. return;
  23. }
  24. $url = $asset->url();
  25. $title = $asset->title();
  26. $id = 'a' . md5($url);
  27. $embed = <<<EOT
  28. <style type="text/css">
  29. .gfg-root {
  30. border: none;
  31. font-family: inherit;
  32. }
  33. </style>
  34. <script type="text/javascript" src="http://www.google.com/jsapi"></script>
  35. <script src="http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.js" type="text/javascript"></script>
  36. <script type="text/javascript">
  37. function init()
  38. {
  39. if (typeof this.has_run == 'undefined' )
  40. {
  41. this.has_run = true;
  42. }
  43. else
  44. {
  45. return;
  46. }
  47. var head = document.getElementsByTagName('head')[0];
  48. var element = document.createElement('link');
  49. element.type = 'text/css';
  50. element.rel = 'stylesheet';
  51. element.href = 'http://www.google.com/uds/solutions/dynamicfeed/gfdynamicfeedcontrol.css';
  52. head.appendChild(element);
  53. }
  54. function load_$id() {
  55. var feeds = [
  56. {
  57. title: ' ',
  58. url: '$url'
  59. }
  60. ];
  61. var options = {
  62. stacked : false,
  63. horizontal : false,
  64. title : '',
  65. numResults : 10
  66. };
  67. new GFdynamicFeedControl(feeds, '$id', options);
  68. document.getElementById('content').style.width = "500px";
  69. }
  70. init();
  71. google.load('feeds', '1');
  72. google.setOnLoadCallback(load_$id);
  73. </script>
  74. <div id="$id" style="min-height:271px;">Loading...</div>
  75. EOT;
  76. $result = array();
  77. $result[self::EMBED_SNIPPET] = $embed;
  78. $result[self::TITLE] = $title;
  79. return $result;
  80. }
  81. }