]> git.mxchange.org Git - friendica.git/blob - src/Module/Bookmarklet.php
Remove deprecated App::query_string - replace with DI::args()->getQueryString()
[friendica.git] / src / Module / Bookmarklet.php
1 <?php
2
3 namespace Friendica\Module;
4
5 use Friendica\BaseModule;
6 use Friendica\Core\ACL;
7 use Friendica\Core\L10n;
8 use Friendica\DI;
9 use Friendica\Module\Security\Login;
10 use Friendica\Network\HTTPException;
11 use Friendica\Util\Strings;
12
13 /**
14  * Creates a bookmarklet
15  * Shows either a editor browser or adds the given bookmarklet to the current user
16  */
17 class Bookmarklet extends BaseModule
18 {
19         public static function content(array $parameters = [])
20         {
21                 $_GET['mode'] = 'minimal';
22
23                 $app = DI::app();
24                 $config = DI::config();
25
26                 if (!local_user()) {
27                         $output = '<h2>' . L10n::t('Login') . '</h2>';
28                         $output .= Login::form(DI::args()->getQueryString(), intval($config->get('config', 'register_policy')) === Register::CLOSED ? false : true);
29                         return $output;
30                 }
31
32                 $referer = Strings::normaliseLink($_SERVER['HTTP_REFERER'] ?? '');
33                 $page = Strings::normaliseLink(DI::baseUrl()->get() . "/bookmarklet");
34
35                 if (!strstr($referer, $page)) {
36                         if (empty($_REQUEST["url"])) {
37                                 throw new HTTPException\BadRequestException(L10n::t('This page is missing a url parameter.'));
38                         }
39
40                         $content = add_page_info($_REQUEST["url"]);
41
42                         $x = [
43                                 'is_owner'         => true,
44                                 'allow_location'   => $app->user['allow_location'],
45                                 'default_location' => $app->user['default-location'],
46                                 'nickname'         => $app->user['nickname'],
47                                 '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'),
48                                 'default_perms'    => ACL::getDefaultUserPermissions($app->user),
49                                 'acl'              => ACL::getFullSelectorHTML($app->page, $app->user, true),
50                                 'bang'             => '',
51                                 'visitor'          => 'block',
52                                 'profile_uid'      => local_user(),
53                                 'title'            => trim($_REQUEST['title'] ?? '', '*'),
54                                 'content'          => $content
55                         ];
56                         $output = status_editor($app, $x, 0, false);
57                         $output .= "<script>window.resizeTo(800,550);</script>";
58                 } else {
59                         $output = '<h2>' . L10n::t('The post was created') . '</h2>';
60                         $output .= "<script>window.close()</script>";
61                 }
62
63                 return $output;
64         }
65 }