start on tag deliver rewrite

This commit is contained in:
friendica 2013-01-12 18:06:34 -08:00
parent f24ce35603
commit d5c71e5691
3 changed files with 49 additions and 53 deletions

View File

@ -389,6 +389,7 @@ define ( 'ITEM_THREAD_TOP', 0x0040);
define ( 'ITEM_NOTSHOWN', 0x0080); // technically visible but not normally shown (e.g. like/dislike) define ( 'ITEM_NOTSHOWN', 0x0080); // technically visible but not normally shown (e.g. like/dislike)
define ( 'ITEM_NSFW', 0x0100); define ( 'ITEM_NSFW', 0x0100);
define ( 'ITEM_RELAY', 0x0200); // used only in the communication layers, not stored define ( 'ITEM_RELAY', 0x0200); // used only in the communication layers, not stored
define ( 'ITEM_MENTIONSME', 0x0400);
/** /**

View File

@ -1525,55 +1525,48 @@ function tag_deliver($uid,$item_id) {
if(! count($i)) if(! count($i))
return; return;
$i = fetch_post_tags($i);
$item = $i[0]; $item = $i[0];
$terms = get_terms_oftype($item['term'],TERM_MENTION);
$link = normalise_link($a->get_baseurl() . '/channel/' . $u[0]['nickname']); $link = normalise_link($a->get_baseurl() . '/channel/' . $u[0]['nickname']);
$body = preg_replace("/\[share\](.*?)\[\/share\]/ism", '', $item['body']); if($terms) {
foreach($terms as $term) {
$cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism',$body,$matches,PREG_SET_ORDER); if(($term['term'] == $u[0]['channel_name']) && link_compare($term['url'],$link)) {
if($cnt) {
foreach($matches as $mtch) {
if(link_compare($link,$mtch[1])) {
$mention = true; $mention = true;
logger('tag_deliver: mention found: ' . $mtch[2]); break;
} }
} }
} }
if(! $mention) if($mention) {
$r = q("update item set item_flags = ( item_flags | %d ) where id = %d limit 1",
intval(ITEM_MENTIONSME),
intval($item_id)
);
}
else
return; return;
// send a notification // send a notification
// use a local photo if we have one
$r = q("select thumb from contact where uid = %d and nurl = '%s' limit 1",
intval($u[0]['uid']),
dbesc(normalise_link($item['author-link']))
);
$photo = (($r && count($r)) ? $r[0]['thumb'] : $item['author-avatar']);
// fixme for channels
require_once('include/enotify.php'); require_once('include/enotify.php');
notification(array( notification(array(
'to_xchan' => $u[0]['channel_hash'],
'from_xchan' => $item['author_xchan'],
'type' => NOTIFY_TAGSELF, 'type' => NOTIFY_TAGSELF,
'notify_flags' => $u[0]['notify-flags'],
'language' => $u[0]['language'],
'to_name' => $u[0]['username'],
'to_email' => $u[0]['email'],
'uid' => $u[0]['uid'],
'item' => $item, 'item' => $item,
'link' => $a->get_baseurl() . '/display/' . $u[0]['nickname'] . '/' . $item['id'], 'link' => $i[0]['llink'],
'source_name' => $item['author-name'],
'source_link' => $item['author-link'],
'source_photo' => $photo,
'verb' => ACTIVITY_TAG, 'verb' => ACTIVITY_TAG,
'otype' => 'item' 'otype' => 'item'
)); ));
if((! $community_page) && (! $prvgroup))
if(! perm_is_allowed($uid,$item['author_xchan'],'tag_deliver'))
return; return;
@ -1581,39 +1574,41 @@ function tag_deliver($uid,$item_id) {
// prevent delivery looping - only proceed // prevent delivery looping - only proceed
// if the message originated elsewhere and is a top-level post // if the message originated elsewhere and is a top-level post
if(($item['wall']) || ($item['origin']) || ($item['id'] != $item['parent'])) // FIXME
return;
// if(($item['wall']) || ($item['origin']) || ($item['id'] != $item['parent']))
// return;
// now change this copy of the post to a forum head message and deliver to all the tgroup members // now change this copy of the post to a forum head message and deliver to all the tgroup members
$c = q("select name, url, thumb from contact where self = 1 and uid = %d limit 1", // $c = q("select name, url, thumb from contact where self = 1 and uid = %d limit 1",
intval($u[0]['uid']) // intval($u[0]['uid'])
); // );
if(! count($c)) // if(! count($c))
return; // return;
// also reset all the privacy bits to the forum default permissions // also reset all the privacy bits to the forum default permissions
$private = ($u[0]['allow_cid'] || $u[0]['allow_gid'] || $u[0]['deny_cid'] || $u[0]['deny_gid']) ? 1 : 0; $private = ($u[0]['allow_cid'] || $u[0]['allow_gid'] || $u[0]['deny_cid'] || $u[0]['deny_gid']) ? 1 : 0;
$forum_mode = (($prvgroup) ? 2 : 1); // $forum_mode = (($prvgroup) ? 2 : 1);
q("update item set wall = 1, origin = 1, forum_mode = %d, `owner-name` = '%s', `owner-link` = '%s', `owner-avatar` = '%s', // q("update item set wall = 1, origin = 1, forum_mode = %d, `owner-name` = '%s', `owner-link` = '%s', `owner-avatar` = '%s',
`private` = %d, `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' where id = %d limit 1", // `private` = %d, `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' where id = %d limit 1",
intval($forum_mode), // intval($forum_mode),
dbesc($c[0]['name']), // dbesc($c[0]['name']),
dbesc($c[0]['url']), // dbesc($c[0]['url']),
dbesc($c[0]['thumb']), // dbesc($c[0]['thumb']),
intval($private), // intval($private),
dbesc($u[0]['allow_cid']), // dbesc($u[0]['allow_cid']),
dbesc($u[0]['allow_gid']), // dbesc($u[0]['allow_gid']),
dbesc($u[0]['deny_cid']), // dbesc($u[0]['deny_cid']),
dbesc($u[0]['deny_gid']), // dbesc($u[0]['deny_gid']),
intval($item_id) // intval($item_id)
); // );
proc_run('php','include/notifier.php','tgroup',$item_id); // proc_run('php','include/notifier.php','tgroup',$item_id);
} }

View File

@ -64,7 +64,7 @@ function process_command($line) {
if(argv(1)) { if(argv(1)) {
$x = zot_finger(argv(1),$channel); $x = zot_finger(argv(1),$channel);
if($x['success']) if($x['success'])
print_r(json_decode($x['body'],true)); echo jindent($x['body']);
} }
break; break;