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