bookmarking

This commit is contained in:
friendica 2014-02-04 16:06:56 -08:00
parent 46b9352a84
commit 3665bc38ef
7 changed files with 126 additions and 15 deletions

View File

@ -270,7 +270,7 @@ define ( 'PERMS_W_STORAGE', 0x02000);
define ( 'PERMS_R_PAGES', 0x04000);
define ( 'PERMS_W_PAGES', 0x08000);
define ( 'PERMS_A_REPUBLISH', 0x10000);
define ( 'PERMS_A_BOOMARK', 0x20000);
define ( 'PERMS_A_BOOKMARK', 0x20000);
// General channel permissions

53
include/bookmarks.php Normal file
View File

@ -0,0 +1,53 @@
<?php /** @file */
require_once('include/menu.php');
function bookmark_add($channel,$sender,$taxonomy,$private) {
$iarr = array();
$channel_id = $channel['channel_id'];
if($private)
$iarr['contact_allow'] = array($channel['channel_hash']);
$iarr['mitem_link'] = $taxonomy['url'];
$iarr['mitem_desc'] = $taxonomy['term'];
$iarr['mitem_flags'] = 0;
$m = @parse_url($taxonomy['url']);
$zrl = false;
if($m['host']) {
$r = q("select hubloc_url from hubloc where hubloc_host = '%s' limit 1",
dbesc($m['host'])
);
if($r)
$zrl = true;
}
if($zrl)
$iarr['mitem_flags'] |= MENU_ITEM_ZID;
$arr = array();
$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'] = 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) {
logger('bookmark_add: unable to create menu ' . $arr['menu_name']);
return;
}
$r = q("select * from menu_item where mitem_link = '%s' and mitem_menu_id = %d and mitem_channel_id = %d limit 1",
dbesc($iarr['mitem_link']),
intval($menu_id),
intval($channel_id)
);
if(! $r)
$r = menu_add_item($menu_id,$channel_id,$iarr);
return $r;
}

View File

@ -2169,6 +2169,21 @@ function tag_deliver($uid,$item_id) {
$item = $i[0];
$terms = get_terms_oftype($item['term'],TERM_BOOKMARK);
if($terms && (! $i[0]['item_restrict'])) {
logger('tag_deliver: found bookmark');
if(perm_is_allowed($u[0]['channel_id'],$i[0]['author_xchan'],'bookmark') && ($i[0]['author_xchan'] != $u[0]['channel_hash'])) {
require_once('include/bookmarks.php');
require_once('include/Contact.php');
$s = channelx_by_hash($i[0]['author_xchan']);
foreach($terms as $t) {
bookmark_add($u[0],$s[0],$t,$i[0]['item_private']);
}
}
}
if(($item['source_xchan']) && ($item['item_flags'] & ITEM_UPLINK) && ($item['item_flags'] & ITEM_THREAD_TOP) && ($item['edited'] != $item['created'])) {
// this is an update to a post which was already processed by us and has a second delivery chain
// Just start the second delivery chain to deliver the updated post

View File

@ -26,11 +26,12 @@ function menu_fetch($name,$uid,$observer_xchan) {
function menu_render($menu) {
if(! $menu)
return '';
for($x = 0; $x < count($menu['items']); $x ++)
if($menu['items']['mitem_flags'] & MENU_ITEM_ZID)
$menu['items']['mitem_link'] = zid($menu['items']['mitem_link']);
if($menu['items']['mitem_flags'] & MENU_ITEM_NEWWIN)
$menu['items']['newwin'] = '1';
if($menu['items'][$x]['mitem_flags'] & MENU_ITEM_ZID)
$menu['items'][$x]['mitem_link'] = zid($menu['items'][$x]['mitem_link']);
if($menu['items'][$x]['mitem_flags'] & MENU_ITEM_NEWWIN)
$menu['items'][$x]['newwin'] = '1';
return replace_macros(get_markup_template('usermenu.tpl'),array(
'$menu' => $menu['menu'],
@ -74,7 +75,7 @@ function menu_create($arr) {
$r = q("select * from menu where menu_name = '%s' and menu_channel_id = %d limit 1",
dbesc($menu_name),
intval($menu_channel_id),
intval($menu_channel_id)
);
if($r)
@ -106,9 +107,11 @@ function menu_create($arr) {
* bits set. We will use this to find system generated bookmarks.
*/
function menu_list($channel_id, $flags = 0) {
function menu_list($channel_id, $name = '', $flags = 0) {
$sel_options = (($flags) ? " and ( menu_flags & " . intval($flags) . " ) = " . intval($flags) . " " : '');
$sel_options = '';
$sel_options .= (($name) ? " and name = '" . protect_sprintf(dbesc($name)) . "' " : '');
$sel_options .= (($flags) ? " and menu_flags = " . intval($flags) . " " : '');
$r = q("select * from menu where menu_channel_id = %d $sel_options order by menu_name",
intval($channel_id)
@ -229,11 +232,11 @@ function menu_add_item($menu_id, $uid, $arr) {
$str_contact_deny = perms2str($arr['contact_deny']);
}
$allow_cid = perms2str($arr['allow_cid']);
$allow_gid = perms2str($arr['allow_gid']);
$deny_cid = perms2str($arr['deny_cid']);
$deny_gid = perms2str($arr['deny_gid']);
// unused
// $allow_cid = perms2str($arr['allow_cid']);
// $allow_gid = perms2str($arr['allow_gid']);
// $deny_cid = perms2str($arr['deny_cid']);
// $deny_gid = perms2str($arr['deny_gid']);
$r = q("insert into menu_item ( mitem_link, mitem_desc, mitem_flags, allow_cid, allow_gid, deny_cid, deny_gid, mitem_channel_id, mitem_menu_id, mitem_order ) values ( '%s', '%s', %d, '%s', '%s', '%s', '%s', %d, %d, %d ) ",
dbesc($mitem_link),

View File

@ -29,7 +29,7 @@ function get_perms() {
'write_pages' => array('channel_w_pages', intval(PERMS_W_PAGES), false, t('Can edit my "public" pages'), ''),
'republish' => array('channel_a_republish', intval(PERMS_A_REPUBLISH), false, t('Can source my "public" posts in derived channels'), t('Somewhat advanced - very useful in open communities')),
'bookmark' => array('channel_a_bookmark', intval(PERMS_A_BOOKMARK), false, t('Can send me bookmarks'), ''),
'bookmark' => array('channel_a_bookmark', intval(PERMS_A_BOOKMARK), false, t('Can send me bookmarks'), 'Bookmarks from this person will automatically be saved'),
'delegate' => array('channel_a_delegate', intval(PERMS_A_DELEGATE), false, t('Can administer my channel resources'), t('Extremely advanced. Leave this alone unless you know what you are doing')),
);
$ret = array('global_permissions' => $global_perms);

40
mod/bookmarks.php Normal file
View File

@ -0,0 +1,40 @@
<?php
function bookmarks_content(&$a) {
if(! local_user()) {
notice( t('Permission denied.') . EOL);
return;
}
require_once('include/menu.php');
$o = '<h3>' . t('My Bookmarks') . '</h3>';
$x = menu_list(local_user(),'',MENU_BOOKMARK);
if($x) {
foreach($x as $xx) {
$y = menu_fetch($xx['menu_name'],local_user(),get_observer_hash());
$o .= menu_render($y);
}
}
$o .= '<h3>' . t('My Connections Bookmarks') . '</h3>';
$x = menu_list(local_user(),'',MENU_SYSTEM|MENU_BOOKMARK);
if($x) {
foreach($x as $xx) {
$y = menu_fetch($xx['menu_name'],local_user(),get_observer_hash());
$o .= menu_render($y);
}
}
return $o;
}

View File

@ -252,7 +252,7 @@ function parse_url_content(&$a) {
logger('parse_url: ' . $url);
$template = $br . '[url=%s]%s[/url]%s' . $br;
$template = $br . '#^[url=%s]%s[/url]%s' . $br;
$arr = array('url' => $url, 'text' => '');