]> git.mxchange.org Git - friendica.git/blob - src/Module/Oembed.php
Use rawContent for Special Options to avoid a protected options() method
[friendica.git] / src / Module / Oembed.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module;
23
24 use Friendica\BaseModule;
25 use Friendica\Content;
26 use Friendica\DI;
27 use Friendica\Util\Strings;
28
29 /**
30  * Oembed module
31  *
32  * Displays stored embed content based on a base64 hash of a remote URL
33  *
34  * Example: /oembed/aHR0cHM6Ly9...
35  *
36  * @author Hypolite Petovan <hypolite@mrpetovan.com>
37  */
38 class Oembed extends BaseModule
39 {
40         protected function content(array $request = []): string
41         {
42                 // Unused form: /oembed/b2h?url=...
43                 if (DI::args()->getArgv()[1] == 'b2h') {
44                         $url = ["", trim(hex2bin($_REQUEST['url']))];
45                         echo Content\OEmbed::replaceCallback($url);
46                         exit();
47                 }
48
49                 // Unused form: /oembed/h2b?text=...
50                 if (DI::args()->getArgv()[1] == 'h2b') {
51                         $text = trim(hex2bin($_REQUEST['text']));
52                         echo Content\OEmbed::HTML2BBCode($text);
53                         exit();
54                 }
55
56                 // @TODO: Replace with parameter from router
57                 if (DI::args()->getArgc() == 2) {
58                         echo '<html><body>';
59                         $url = Strings::base64UrlDecode(DI::args()->getArgv()[1]);
60                         $j = Content\OEmbed::fetchURL($url);
61
62                         // workaround for media.ccc.de (and any other endpoint that return size 0)
63                         if (substr($j->html, 0, 7) == "<iframe" && strstr($j->html, 'width="0"')) {
64                                 $j->html = '<style>html,body{margin:0;padding:0;} iframe{width:100%;height:100%;}</style>' . $j->html;
65                                 $j->html = str_replace('width="0"', '', $j->html);
66                                 $j->html = str_replace('height="0"', '', $j->html);
67                         }
68                         echo $j->html;
69                         echo '</body></html>';
70                 }
71                 exit();
72         }
73 }