3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Module;
24 use Friendica\BaseModule;
25 use Friendica\Content;
26 use Friendica\Core\System;
28 use Friendica\Util\Strings;
33 * Displays stored embed content based on a base64 hash of a remote URL
35 * Example: /oembed/aHR0cHM6Ly9...
37 * @author Hypolite Petovan <hypolite@mrpetovan.com>
39 class Oembed extends BaseModule
41 protected function content(array $request = []): string
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);
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);
57 // @TODO: Replace with parameter from router
58 if (DI::args()->getArgc() == 2) {
60 $url = Strings::base64UrlDecode(DI::args()->getArgv()[1]);
61 $j = Content\OEmbed::fetchURL($url);
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);
70 echo '</body></html>';