]> git.mxchange.org Git - friendica.git/blob - src/Module/Oembed.php
Merge pull request #13070 from xundeenergie/fix-share-via
[friendica.git] / src / Module / Oembed.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, 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\Core\System;
27 use Friendica\DI;
28 use Friendica\Util\Strings;
29
30 /**
31  * Oembed module
32  *
33  * Displays stored embed content based on a base64 hash of a remote URL
34  *
35  * Example: /oembed/aHR0cHM6Ly9...
36  *
37  * @author Hypolite Petovan <hypolite@mrpetovan.com>
38  */
39 class Oembed extends BaseModule
40 {
41         protected function content(array $request = []): string
42         {
43                 // Unused form: /oembed/b2h?url=...
44                 if (DI::args()->getArgv()[1] == 'b2h') {
45                         $url = ["", trim(hex2bin($_REQUEST['url']))];
46                         echo Content\OEmbed::replaceCallback($url);
47                         System::exit();
48                 }
49
50                 // Unused form: /oembed/h2b?text=...
51                 if (DI::args()->getArgv()[1] == 'h2b') {
52                         $text = trim(hex2bin($_REQUEST['text']));
53                         echo Content\OEmbed::HTML2BBCode($text);
54                         System::exit();
55                 }
56
57                 // @TODO: Replace with parameter from router
58                 if (DI::args()->getArgc() == 2) {
59                         echo '<html><body>';
60                         $url = Strings::base64UrlDecode(DI::args()->getArgv()[1]);
61                         $j = Content\OEmbed::fetchURL($url);
62
63                         // workaround for media.ccc.de (and any other endpoint that return size 0)
64                         if (substr($j->html, 0, 7) == "<iframe" && strstr($j->html, 'width="0"')) {
65                                 $j->html = '<style>html,body{margin:0;padding:0;} iframe{width:100%;height:100%;}</style>' . $j->html;
66                                 $j->html = str_replace('width="0"', '', $j->html);
67                                 $j->html = str_replace('height="0"', '', $j->html);
68                         }
69                         echo $j->html;
70                         echo '</body></html>';
71                 }
72                 System::exit();
73         }
74 }