diff options
author | Mario <mario@mariovavti.com> | 2024-05-15 08:28:19 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-05-15 08:28:19 +0000 |
commit | a10402a7883efd4886ad17c8133c10237f443181 (patch) | |
tree | eca3f5a3ba34d40d1e7d0766a59d3494c9db47ad /Zotlabs | |
parent | 2145207ad2feedde9a1fe73807ef6365664aad79 (diff) | |
parent | 5da0cc138f4330fd07e9c117b3f4261dc1bcbc19 (diff) | |
download | volse-hubzilla-a10402a7883efd4886ad17c8133c10237f443181.tar.gz volse-hubzilla-a10402a7883efd4886ad17c8133c10237f443181.tar.bz2 volse-hubzilla-a10402a7883efd4886ad17c8133c10237f443181.zip |
Merge branch 'refactor-module-rbmark' into 'dev'
Refactor and cleanup Rbmark module + add tests
See merge request hubzilla/core!2126
Diffstat (limited to 'Zotlabs')
-rw-r--r-- | Zotlabs/Module/Rbmark.php | 77 |
1 files changed, 30 insertions, 47 deletions
diff --git a/Zotlabs/Module/Rbmark.php b/Zotlabs/Module/Rbmark.php index 87b774495..b1aea2590 100644 --- a/Zotlabs/Module/Rbmark.php +++ b/Zotlabs/Module/Rbmark.php @@ -1,5 +1,5 @@ <?php -namespace Zotlabs\Module; /** @file */ +namespace Zotlabs\Module; require_once('include/acl_selectors.php'); require_once('include/crypto.php'); @@ -23,11 +23,9 @@ require_once('include/bookmarks.php'); * remote_return= absolute URL to return after posting is finished * */ - - class Rbmark extends \Zotlabs\Web\Controller { - function post() { + public function post(): void { if($_POST['submit'] !== t('Save')) return; @@ -36,22 +34,21 @@ class Rbmark extends \Zotlabs\Web\Controller { $channel = \App::get_channel(); $t = array('url' => escape_tags($_REQUEST['url']),'term' => escape_tags($_REQUEST['title'])); + bookmark_add($channel,$channel,$t,((x($_REQUEST,'private')) ? intval($_REQUEST['private']) : 0), array('menu_id' => ((x($_REQUEST,'menu_id')) ? intval($_REQUEST['menu_id']) : 0), - 'menu_name' => ((x($_REQUEST,'menu_name')) ? escape_tags($_REQUEST['menu_name']) : ''), - 'ischat' => ((x($_REQUEST['ischat'])) ? intval($_REQUEST['ischat']) : 0) + 'menu_name' => ((x($_REQUEST,'menu_name')) ? escape_tags($_REQUEST['menu_name']) : ''), + 'ischat' => ((x($_REQUEST['ischat'])) ? intval($_REQUEST['ischat']) : 0) )); goaway(z_root() . '/bookmarks'); - } - function get() { + public function get(): string { - $o = ''; - - if(! local_channel()) { + $channel_id = local_channel(); + if($channel_id === false) { // The login procedure is going to bugger our $_REQUEST variables // so save them in the session. @@ -62,59 +59,45 @@ class Rbmark extends \Zotlabs\Web\Controller { return login(); } - // If we have saved rbmark session variables, but nothing in the current $_REQUEST, recover the saved variables + // If we have saved rbmark session variables, but nothing in the + // current $_REQUEST, recover the saved variables if((! array_key_exists('url',$_REQUEST)) && (array_key_exists('bookmark',$_SESSION))) { $_REQUEST = $_SESSION['bookmark']; unset($_SESSION['bookmark']); } - if($_REQUEST['remote_return']) { - $_SESSION['remote_return'] = $_REQUEST['remote_return']; - } - if(argc() > 1 && argv(1) === 'return') { - if($_SESSION['remote_return']) - goaway($_SESSION['remote_return']); - goaway(z_root() . '/bookmarks'); - } - - $channel = \App::get_channel(); - - - $m = menu_list($channel['channel_id'],'',MENU_BOOKMARK); - - $menus = array(); - if($m) { - $menus = array(0 => ''); - foreach($m as $n) { - $menus[$n['menu_id']] = $n['menu_name']; - } - } - $menu_select = array('menu_id',t('Select a bookmark folder'),false,'',$menus); - - - $o .= replace_macros(get_markup_template('rbmark.tpl'), array( + $menu_select = [ + 'menu_id', + t('Select a bookmark folder'), + false, + '', + $this->get_bookmark_folders(intval($channel_id)), + ]; + return replace_macros(get_markup_template('rbmark.tpl'), array( '$header' => t('Save Bookmark'), - '$url' => array('url',t('URL of bookmark'),escape_tags($_REQUEST['url'])), - '$title' => array('title',t('Description'),escape_tags($_REQUEST['title'])), + '$url' => array('url',t('URL of bookmark'),$_REQUEST['url']), + '$title' => array('title',t('Description'),$_REQUEST['title']), '$ischat' => ((x($_REQUEST,'ischat')) ? intval($_REQUEST['ischat']) : 0), '$private' => ((x($_REQUEST,'private')) ? intval($_REQUEST['private']) : 0), '$submit' => t('Save'), '$menu_name' => array('menu_name',t('Or enter new bookmark folder name'),'',''), '$menus' => $menu_select - )); + } + private function get_bookmark_folders(int $channel_id): array { + $menu_list = menu_list($channel_id, '', MENU_BOOKMARK); + $menus = [ 0 => '' ]; + if ($menu_list !== false) { + foreach($menu_list as $n) { + $menus[$n['menu_id']] = $n['menu_name']; + } + } - - - return $o; - + return $menus; } - - - } |