From b2ff31da7416f9809ac9e83010b0a90305b468d4 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Thu, 2 May 2019 22:17:09 +0200 Subject: [PATCH] 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 f15d12d6d1..0000000000 --- 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 e2a6719f6c..db40599dd2 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 0000000000..de1de41735 --- /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; + } +} -- 2.39.5