From b2ff31da7416f9809ac9e83010b0a90305b468d4 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Thu, 2 May 2019 22:17:09 +0200 Subject: [PATCH 1/2] Move mod/bookmarklet to src/Module/BookMarklet --- mod/bookmarklet.php | 59 ---------------------------------- src/App/Router.php | 1 + src/Module/BookMarklet.php | 66 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 59 deletions(-) delete mode 100644 mod/bookmarklet.php create mode 100644 src/Module/BookMarklet.php diff --git a/mod/bookmarklet.php b/mod/bookmarklet.php deleted file mode 100644 index f15d12d6d..000000000 --- a/mod/bookmarklet.php +++ /dev/null @@ -1,59 +0,0 @@ -' . L10n::t('Login') . ''; - $o .= Login::form($a->query_string, intval(Config::get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? false : true); - return $o; - } - - $referer = Strings::normaliseLink(defaults($_SERVER, 'HTTP_REFERER', '')); - $page = Strings::normaliseLink(System::baseUrl() . "/bookmarklet"); - - if (!strstr($referer, $page)) { - if (empty($_REQUEST["url"])) { - throw new \Friendica\Network\HTTPException\BadRequestException(L10n::t('This page is missing a url parameter.')); - } - - $content = add_page_info($_REQUEST["url"]); - - $x = [ - 'is_owner' => true, - 'allow_location' => $a->user['allow_location'], - 'default_location' => $a->user['default-location'], - 'nickname' => $a->user['nickname'], - 'lockstate' => ((is_array($a->user) && ((strlen($a->user['allow_cid'])) || (strlen($a->user['allow_gid'])) || (strlen($a->user['deny_cid'])) || (strlen($a->user['deny_gid'])))) ? 'lock' : 'unlock'), - 'default_perms' => ACL::getDefaultUserPermissions($a->user), - 'acl' => ACL::getFullSelectorHTML($a->user, true), - 'bang' => '', - 'visitor' => 'block', - 'profile_uid' => local_user(), - 'title' => trim(defaults($_REQUEST, 'title', ''), "*"), - 'content' => $content - ]; - $o = status_editor($a, $x, 0, false); - $o .= ""; - } else { - $o = '

' . L10n::t('The post was created') . '

'; - $o .= ""; - } - - return $o; -} diff --git a/src/App/Router.php b/src/App/Router.php index e2a6719f6..db40599dd 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -52,6 +52,7 @@ class Router $this->routeCollector->addRoute(['GET'], '/apps', Module\Apps::class); $this->routeCollector->addRoute(['GET'], '/attach/{item:\d+}', Module\Attach::class); $this->routeCollector->addRoute(['GET'], '/babel', Module\Babel::class); + $this->routeCollector->addRoute(['GET'], '/bookmarklet', Module\BookMarklet::class); $this->routeCollector->addGroup('/contact', function (RouteCollector $collector) { $collector->addRoute(['GET'], '[/]', Module\Contact::class); $collector->addRoute(['GET'], '/{id:\d+}[/posts|conversations]', Module\Contact::class); diff --git a/src/Module/BookMarklet.php b/src/Module/BookMarklet.php new file mode 100644 index 000000000..de1de4173 --- /dev/null +++ b/src/Module/BookMarklet.php @@ -0,0 +1,66 @@ +getConfig(); + + if (!local_user()) { + $output = '

' . L10n::t('Login') . '

'; + $output .= Login::form($app->query_string, intval($config->get('config', 'register_policy')) === Register::CLOSED ? false : true); + return $output; + } + + $referer = Strings::normaliseLink(defaults($_SERVER, 'HTTP_REFERER', '')); + $page = Strings::normaliseLink($app->getBaseURL() . "/bookmarklet"); + + if (!strstr($referer, $page)) { + if (empty($_REQUEST["url"])) { + throw new HTTPException\BadRequestException(L10n::t('This page is missing a url parameter.')); + } + + $content = add_page_info($_REQUEST["url"]); + + $x = [ + 'is_owner' => true, + 'allow_location' => $app->user['allow_location'], + 'default_location' => $app->user['default-location'], + 'nickname' => $app->user['nickname'], + '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'), + 'default_perms' => ACL::getDefaultUserPermissions($app->user), + 'acl' => ACL::getFullSelectorHTML($app->user, true), + 'bang' => '', + 'visitor' => 'block', + 'profile_uid' => local_user(), + 'title' => trim(defaults($_REQUEST, 'title', ''), '*'), + 'content' => $content + ]; + $output = status_editor($app, $x, 0, false); + $output .= ""; + } else { + $output = '

' . L10n::t('The post was created') . '

'; + $output .= ""; + } + + return $output; + } +} From a9f701b9d62ff66ef512cc1dd0256be356954fb5 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Thu, 2 May 2019 23:28:13 +0200 Subject: [PATCH 2/2] merge init() and content() --- src/Module/BookMarklet.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Module/BookMarklet.php b/src/Module/BookMarklet.php index de1de4173..51feb25d7 100644 --- a/src/Module/BookMarklet.php +++ b/src/Module/BookMarklet.php @@ -14,13 +14,10 @@ use Friendica\Util\Strings; */ class BookMarklet extends BaseModule { - public static function init() - { - $_GET['mode'] = 'minimal'; - } - public static function content() { + $_GET['mode'] = 'minimal'; + $app = self::getApp(); $config = $app->getConfig();