diff options
-rwxr-xr-x | boot.php | 6 | ||||
-rw-r--r-- | include/bookmarks.php | 33 | ||||
-rw-r--r-- | mod/rbmark.php | 112 | ||||
-rw-r--r-- | mod/rpost.php | 2 | ||||
-rw-r--r-- | view/tpl/rbmark.tpl | 16 |
5 files changed, 156 insertions, 13 deletions
@@ -307,9 +307,9 @@ define ( 'ATTACH_FLAG_OS', 0x0002); -define ( 'MENU_ITEM_ZID', 0x0001); -define ( 'MENU_ITEM_NEWWIN', 0x0002); - +define ( 'MENU_ITEM_ZID', 0x0001); +define ( 'MENU_ITEM_NEWWIN', 0x0002); +define ( 'MENU_ITEM_CHATROOM', 0x0004); /** * Poll/Survey types diff --git a/include/bookmarks.php b/include/bookmarks.php index 99cb60e64..895dedaff 100644 --- a/include/bookmarks.php +++ b/include/bookmarks.php @@ -2,7 +2,17 @@ require_once('include/menu.php'); -function bookmark_add($channel,$sender,$taxonomy,$private) { +function bookmark_add($channel,$sender,$taxonomy,$private,$opts = null) { + + $menu_id = 0; + $menu_name = ''; + $ischat = false; + + if(is_array($opts)) { + $menu_id = ((x($opts,'menu_id')) ? intval($opt['menu_id']) : 0); + $menu_name = ((x($opts,'menu_name')) ? escape_tags($opts['menu_name']) : ''); + $ischat = ((x($opts,'ischat')) ? intval($opts['ischat']) : 0); + } $iarr = array(); $channel_id = $channel['channel_id']; @@ -11,7 +21,7 @@ function bookmark_add($channel,$sender,$taxonomy,$private) { $iarr['contact_allow'] = array($channel['channel_hash']); $iarr['mitem_link'] = $taxonomy['url']; $iarr['mitem_desc'] = $taxonomy['term']; - $iarr['mitem_flags'] = 0; + $iarr['mitem_flags'] = (($ischat) ? MENU_ITEM_CHATROOM : 0); $m = @parse_url($taxonomy['url']); $zrl = false; @@ -27,16 +37,20 @@ function bookmark_add($channel,$sender,$taxonomy,$private) { $iarr['mitem_flags'] |= MENU_ITEM_ZID; $arr = array(); - $arr['menu_name'] = substr($sender['xchan_hash'],0,16) . ' ' . $sender['xchan_name']; + if(! $menu_name) + $arr['menu_name'] = substr($sender['xchan_hash'],0,16) . ' ' . $sender['xchan_name']; $arr['menu_desc'] = sprintf( t('%1$s\'s bookmarks'), $sender['xchan_name']); $arr['menu_flags'] = (($sender['xchan_hash'] === $channel['channel_hash']) ? MENU_BOOKMARK : MENU_SYSTEM|MENU_BOOKMARK); $arr['menu_channel_id'] = $channel_id; - $x = menu_list($arr['menu_channel_id'],$arr['menu_name'],$arr['menu_flags']); - if($x) - $menu_id = $x[0]['menu_id']; - else - $menu_id = menu_create($arr); + if(! $menu_id) { + $x = menu_list($arr['menu_channel_id'],$arr['menu_name'],$arr['menu_flags']); + if($x) + $menu_id = $x[0]['menu_id']; + else + $menu_id = menu_create($arr); + } + if(! $menu_id) { logger('bookmark_add: unable to create menu ' . $arr['menu_name']); return; @@ -51,5 +65,6 @@ function bookmark_add($channel,$sender,$taxonomy,$private) { logger('add_bookmark: duplicate menu entry', LOGGER_DEBUG); if(! $r) $r = menu_add_item($menu_id,$channel_id,$iarr); + return $r; -}
\ No newline at end of file +} diff --git a/mod/rbmark.php b/mod/rbmark.php new file mode 100644 index 000000000..1c962152c --- /dev/null +++ b/mod/rbmark.php @@ -0,0 +1,112 @@ +<?php /** @file */ + +require_once('acl_selectors.php'); +require_once('include/crypto.php'); +require_once('include/items.php'); +require_once('include/taxonomy.php'); +require_once('include/conversation.php'); +require_once('include/zot.php'); +require_once('include/bookmarks.php'); + +/** + * remote bookmark + * + * https://yoursite/rbmark?f=&title=&url=&private=&remote_return= + * + * This can be called via either GET or POST, use POST for long body content as suhosin often limits GET parameter length + * + * f= placeholder, often required + * title= link text + * url= URL to bookmark + * ischat=1 if this bookmark is a chatroom + * private= Don't share this link + * remote_return= absolute URL to return after posting is finished + * + */ + +function rbmark_post(&$a) { + if($_POST['submit'] !== t('Save')) + return; + + logger('rbmark_post: ' . print_r($_REQUEST,true)); + + $channel = $a->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']) : '') + )); + + goaway(z_root() . '/bookmarks'); + +} + + +function rbmark_content(&$a) { + + $o = ''; + + if(! local_user()) { + + // The login procedure is going to bugger our $_REQUEST variables + // so save them in the session. + + if(array_key_exists('url',$_REQUEST)) { + $_SESSION['bookmark'] = $_REQUEST; + } + return login(); + } + + // 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 = $a->get_channel(); + + $m = menu_list($channel,'',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( + + '$header' => t('Save Bookmark'), + '$url' => array('url',t('URL of bookmark'),escape_tags($_REQUEST['url'])), + '$title' => array('title',t('Description'),escape_tags($_REQUEST['title'])), + '$ischat' => (($ischat) ? 1 : 0), + '$private' => (($private) ? 1 : 0), + '$submit' => t('Save'), + '$menu_name' => array('menu_name',t('Or enter new bookmark folder name'),'',''), + '$menus' => $menu_select + + )); + + + + + + + return $o; + +} + + diff --git a/mod/rpost.php b/mod/rpost.php index 852a57d78..18d4c86cd 100644 --- a/mod/rpost.php +++ b/mod/rpost.php @@ -33,7 +33,7 @@ function rpost_content(&$a) { if(remote_user()) { // redirect to your own site. // We can only do this with a GET request so you'll need to keep the text short or risk getting truncated - // by the wretched beast called 'shusoin'. All the browsers now allow long GET requests, but suhosin + // by the wretched beast called 'suhosin'. All the browsers now allow long GET requests, but suhosin // blocks them. $url = get_rpost_path($a->get_observer()); diff --git a/view/tpl/rbmark.tpl b/view/tpl/rbmark.tpl new file mode 100644 index 000000000..bead1de2f --- /dev/null +++ b/view/tpl/rbmark.tpl @@ -0,0 +1,16 @@ +<h3>{{$header}}</h3> + + +<form action="rbmark" method="post" > + +<input type="hidden" name="private" value="{{$private}}" /> +<input type="hidden" name="ischat" value="{{$ischat}}" /> + +{{include file="field_input.tpl" field=$url}} +{{include file="field_input.tpl" field=$title}} +{{include file="field_select.tpl" field=$menus}} +{{include file="field_input.tpl" field=$menu_name}} + +<input type="submit" name="submit" value="{{$submit}}" /> + +</form> |