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