asset_page_renderer.class.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Generic HTML page renderer. Process any html page.
  4. *
  5. * @copyright (c) 2011 University of Geneva
  6. * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
  7. * @author Laurent Opprecht
  8. */
  9. class AssetPageRenderer extends AssetRenderer
  10. {
  11. /**
  12. *
  13. * @param HttpResource $asset
  14. */
  15. public function render($asset)
  16. {
  17. global $THEME;
  18. $url = $asset->url();
  19. $title = $asset->title();
  20. $title = $title ? $title : $asset->name();
  21. $description = $asset->get_meta('description');
  22. $description = $description;
  23. $keywords = $asset->get_meta('keywords');
  24. $image_src = $asset->get_link('rel', 'image_src');
  25. $image_src = $image_src ? $image_src['href'] : false;
  26. if (empty($image_src))
  27. {
  28. $image_src = $this->get_icon($asset);
  29. }
  30. $icon = $this->get_icon($asset);
  31. $image_src = $asset->canonic_url($image_src);
  32. $icon = $asset->canonic_url($icon);
  33. $embed = <<<EOT
  34. <a href="$url">
  35. <img src="{$image_src}" alt="{$title}" title="{$title}" style="float:left; margin-right:5px; margin-bottom:5px; " >
  36. </a>
  37. $description
  38. <span style="clear:both;"></span>
  39. EOT;
  40. $result = array();
  41. $result[self::EMBED_SNIPPET] = $embed;
  42. $result[self::TITLE] = $title;
  43. $result[self::THUMBNAIL] = $image_src;
  44. $result[self::DESCRIPTION] = $description;
  45. $result[self::ICON] = $icon;
  46. $result[self::TAGS] = $keywords;
  47. return $result;
  48. }
  49. function get_icon($asset)
  50. {
  51. $icon = $asset->get_link('rel', 'apple-touch-icon');
  52. $icon = $icon ? $icon['href'] : false;
  53. if (empty($icon))
  54. {
  55. $icon = $asset->get_link('rel', 'fluid-icon');
  56. $icon = $icon ? $icon['href'] : false;
  57. }
  58. if (empty($icon))
  59. {
  60. $icon = $asset->get_link('rel', 'shortcut icon');
  61. $icon = $icon ? $icon['href'] : false;
  62. }
  63. if (empty($icon))
  64. {
  65. $icon = $asset->get_link('rel', 'icon');
  66. $icon = $icon ? $icon['href'] : false;
  67. }
  68. return $icon;
  69. }
  70. }