Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.4 KiB

  1. <?php
  2. namespace Friendica\Module;
  3. use Friendica\BaseModule;
  4. use Friendica\Content;
  5. use Friendica\Util\Strings;
  6. /**
  7. * Oembed module
  8. *
  9. * Displays stored embed content based on a base64 hash of a remote URL
  10. *
  11. * Example: /oembed/aHR0cHM6Ly9...
  12. *
  13. * @author Hypolite Petovan <hypolite@mrpetovan.com>
  14. */
  15. class Oembed extends BaseModule
  16. {
  17. public static function content()
  18. {
  19. $a = self::getApp();
  20. // Unused form: /oembed/b2h?url=...
  21. if ($a->argv[1] == 'b2h') {
  22. $url = ["", trim(hex2bin($_REQUEST['url']))];
  23. echo Content\OEmbed::replaceCallback($url);
  24. exit();
  25. }
  26. // Unused form: /oembed/h2b?text=...
  27. if ($a->argv[1] == 'h2b') {
  28. $text = trim(hex2bin($_REQUEST['text']));
  29. echo Content\OEmbed::HTML2BBCode($text);
  30. exit();
  31. }
  32. // @TODO: Replace with parameter from router
  33. if ($a->argc == 2) {
  34. echo '<html><body>';
  35. $url = Strings::base64UrlDecode($a->argv[1]);
  36. $j = Content\OEmbed::fetchURL($url);
  37. // workaround for media.ccc.de (and any other endpoint that return size 0)
  38. if (substr($j->html, 0, 7) == "<iframe" && strstr($j->html, 'width="0"')) {
  39. $j->html = '<style>html,body{margin:0;padding:0;} iframe{width:100%;height:100%;}</style>' . $j->html;
  40. $j->html = str_replace('width="0"', '', $j->html);
  41. $j->html = str_replace('height="0"', '', $j->html);
  42. }
  43. echo $j->html;
  44. echo '</body></html>';
  45. }
  46. exit();
  47. }
  48. }