]> git.mxchange.org Git - friendica.git/blob - src/Module/Oembed.php
remove default from welcome.php
[friendica.git] / src / Module / Oembed.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
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         public static function content(array $parameters = [])
41         {
42                 $a = DI::app();
43
44                 // Unused form: /oembed/b2h?url=...
45                 if ($a->argv[1] == 'b2h') {
46                         $url = ["", trim(hex2bin($_REQUEST['url']))];
47                         echo Content\OEmbed::replaceCallback($url);
48                         exit();
49                 }
50
51                 // Unused form: /oembed/h2b?text=...
52                 if ($a->argv[1] == 'h2b') {
53                         $text = trim(hex2bin($_REQUEST['text']));
54                         echo Content\OEmbed::HTML2BBCode($text);
55                         exit();
56                 }
57
58                 // @TODO: Replace with parameter from router
59                 if ($a->argc == 2) {
60                         echo '<html><body>';
61                         $url = Strings::base64UrlDecode($a->argv[1]);
62                         $j = Content\OEmbed::fetchURL($url);
63
64                         // workaround for media.ccc.de (and any other endpoint that return size 0)
65                         if (substr($j->html, 0, 7) == "<iframe" && strstr($j->html, 'width="0"')) {
66                                 $j->html = '<style>html,body{margin:0;padding:0;} iframe{width:100%;height:100%;}</style>' . $j->html;
67                                 $j->html = str_replace('width="0"', '', $j->html);
68                                 $j->html = str_replace('height="0"', '', $j->html);
69                         }
70                         echo $j->html;
71                         echo '</body></html>';
72                 }
73                 exit();
74         }
75 }