]> git.mxchange.org Git - friendica.git/blob - src/Module/BookMarklet.php
de1de41735c1263279a786e6d29adbd0e4a25804
[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 init()
18         {
19                 $_GET['mode'] = 'minimal';
20         }
21
22         public static function content()
23         {
24                 $app = self::getApp();
25                 $config = $app->getConfig();
26
27                 if (!local_user()) {
28                         $output = '<h2>' . L10n::t('Login') . '</h2>';
29                         $output .= Login::form($app->query_string, intval($config->get('config', 'register_policy')) === Register::CLOSED ? false : true);
30                         return $output;
31                 }
32
33                 $referer = Strings::normaliseLink(defaults($_SERVER, 'HTTP_REFERER', ''));
34                 $page = Strings::normaliseLink($app->getBaseURL() . "/bookmarklet");
35
36                 if (!strstr($referer, $page)) {
37                         if (empty($_REQUEST["url"])) {
38                                 throw new HTTPException\BadRequestException(L10n::t('This page is missing a url parameter.'));
39                         }
40
41                         $content = add_page_info($_REQUEST["url"]);
42
43                         $x = [
44                                 'is_owner'         => true,
45                                 'allow_location'   => $app->user['allow_location'],
46                                 'default_location' => $app->user['default-location'],
47                                 'nickname'         => $app->user['nickname'],
48                                 'lockstate'        => ((is_array($app->user) && ((strlen($app->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($app->user['deny_cid'])) || (strlen($app->user['deny_gid'])))) ? 'lock' : 'unlock'),
49                                 'default_perms'    => ACL::getDefaultUserPermissions($app->user),
50                                 'acl'              => ACL::getFullSelectorHTML($app->user, true),
51                                 'bang'             => '',
52                                 'visitor'          => 'block',
53                                 'profile_uid'      => local_user(),
54                                 'title'            => trim(defaults($_REQUEST, 'title', ''), '*'),
55                                 'content'          => $content
56                         ];
57                         $output = status_editor($app, $x, 0, false);
58                         $output .= "<script>window.resizeTo(800,550);</script>";
59                 } else {
60                         $output = '<h2>' . L10n::t('The post was created') . '</h2>';
61                         $output .= "<script>window.close()</script>";
62                 }
63
64                 return $output;
65         }
66 }