]> git.mxchange.org Git - friendica.git/blob - src/Module/Bookmarklet.php
Merge pull request #8272 from MrPetovan/bug/8254-regex-url-img
[friendica.git] / src / Module / Bookmarklet.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\Core\ACL;
26 use Friendica\DI;
27 use Friendica\Module\Security\Login;
28 use Friendica\Network\HTTPException;
29 use Friendica\Util\Strings;
30
31 /**
32  * Creates a bookmarklet
33  * Shows either a editor browser or adds the given bookmarklet to the current user
34  */
35 class Bookmarklet extends BaseModule
36 {
37         public static function content(array $parameters = [])
38         {
39                 $_GET['mode'] = 'minimal';
40
41                 $app = DI::app();
42                 $config = DI::config();
43
44                 if (!local_user()) {
45                         $output = '<h2>' . DI::l10n()->t('Login') . '</h2>';
46                         $output .= Login::form(DI::args()->getQueryString(), intval($config->get('config', 'register_policy')) === Register::CLOSED ? false : true);
47                         return $output;
48                 }
49
50                 $referer = Strings::normaliseLink($_SERVER['HTTP_REFERER'] ?? '');
51                 $page = Strings::normaliseLink(DI::baseUrl()->get() . "/bookmarklet");
52
53                 if (!strstr($referer, $page)) {
54                         if (empty($_REQUEST["url"])) {
55                                 throw new HTTPException\BadRequestException(DI::l10n()->t('This page is missing a url parameter.'));
56                         }
57
58                         $content = add_page_info($_REQUEST["url"]);
59
60                         $x = [
61                                 'is_owner'         => true,
62                                 'allow_location'   => $app->user['allow_location'],
63                                 'default_location' => $app->user['default-location'],
64                                 'nickname'         => $app->user['nickname'],
65                                 'lockstate'        => ((is_array($app->user) && ((strlen($app->user['allow_cid'])) || (strlen($app->user['allow_gid'])) || (strlen($app->user['deny_cid'])) || (strlen($app->user['deny_gid'])))) ? 'lock' : 'unlock'),
66                                 'default_perms'    => ACL::getDefaultUserPermissions($app->user),
67                                 'acl'              => ACL::getFullSelectorHTML(DI::page(), $app->user, true),
68                                 'bang'             => '',
69                                 'visitor'          => 'block',
70                                 'profile_uid'      => local_user(),
71                                 'title'            => trim($_REQUEST['title'] ?? '', '*'),
72                                 'content'          => $content
73                         ];
74                         $output = status_editor($app, $x, 0, false);
75                         $output .= "<script>window.resizeTo(800,550);</script>";
76                 } else {
77                         $output = '<h2>' . DI::l10n()->t('The post was created') . '</h2>';
78                         $output .= "<script>window.close()</script>";
79                 }
80
81                 return $output;
82         }
83 }