asset_wiki_renderer.class.php 1009 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * Wiki renderer.
  4. *
  5. * @see http://en.wikipedia.org/w/api.php
  6. *
  7. * @copyright (c) 2012 University of Geneva
  8. * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html
  9. * @author Laurent Opprecht
  10. */
  11. class AssetWikiRenderer extends AssetRenderer
  12. {
  13. /**
  14. *
  15. * @param HttpResource $asset
  16. */
  17. public function accept($asset)
  18. {
  19. return $asset->url_match('wikipedia.org/wiki', 'mediawiki.org/wiki');
  20. }
  21. /**
  22. *
  23. * @param HttpResource $asset
  24. *
  25. */
  26. public function render($asset)
  27. {
  28. if (!$this->accept($asset))
  29. {
  30. return;
  31. }
  32. $domain = $asset->url_domain();
  33. $description = $asset->findx('//div[@id="bodyContent"]/p');
  34. $result = array();
  35. $result[self::EMBED_SNIPPET] = $description;
  36. $result[self::TITLE] = $title;
  37. $result[self::DESCRIPTION] = $description;
  38. $result[self::TAGS] = $keywords;
  39. return $result;
  40. }
  41. }