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