From aa88165383b14c35114549334567f362e9c83e54 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 13 Nov 2012 19:32:59 -0800 Subject: mood mostly working --- done | 2 +- include/conversation.php | 88 +++++++++++++++++++++++------------------------- include/notify.php | 6 ++-- include/text.php | 10 +++--- mod/mood.php | 59 ++++++++++++++------------------ 5 files changed, 78 insertions(+), 87 deletions(-) diff --git a/done b/done index 2dbb63cfb..867890ba0 100644 --- a/done +++ b/done @@ -127,7 +127,7 @@ mod/ match.php message.php modexp.php - mood.php +? mood.php msearch.php ? network.php nogroup.php diff --git a/include/conversation.php b/include/conversation.php index 74160c309..1d068f424 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -83,7 +83,7 @@ function item_redir_and_replace_images($body, $images, $cid) { * Render actions localized */ -function localize_item(&$item,$brief = false){ +function localize_item(&$item){ $extracted = item_extract_images($item['body']); if($extracted['images']) @@ -93,18 +93,16 @@ function localize_item(&$item,$brief = false){ if (activity_match($item['verb'],ACTIVITY_LIKE) || activity_match($item['verb'],ACTIVITY_DISLIKE)){ - $obj= json_decode($item['object']); + $obj= json_decode($item['object'],true); -// logger('object: ' . print_r($obj,true)); - - if($obj->author && $obj->author->link) - $author_link = get_json_rel_link($obj->author->link,'alternate'); + if($obj['author'] && $obj['author']['link']) + $author_link = get_rel_link($obj['author']['link'],'alternate'); else $author_link = ''; - $author_name = (($obj->author && $obj->author->name) ? $obj->author->name : ''); + $author_name = (($obj['author'] && $obj['author']['name']) ? $obj['author']['name'] : ''); - $item_url = get_json_rel_link($obj->link,'alternate'); + $item_url = get_rel_link($obj['link'],'alternate'); // If we couldn't parse something useful, don't bother translating. @@ -139,7 +137,7 @@ function localize_item(&$item,$brief = false){ elseif(activity_match($item['verb'],ACTIVITY_DISLIKE)) { $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s'); } - $item['body'] = sprintf($bodyverb, $author, $objauthor, $plink); + $item['body'] = $item['localize'] = sprintf($bodyverb, $author, $objauthor, $plink); } @@ -149,56 +147,48 @@ function localize_item(&$item,$brief = false){ if ($item['obj_type']=="" || $item['obj_type']!== ACTIVITY_OBJ_PERSON) return; - $Aname = $item['author-name']; - $Alink = $item['author-link']; + $Aname = $item['author']['xchan_name']; + $Alink = $item['author']['xchan_url']; - $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; - $obj = parse_xml_string($xmlhead.$item['object']); - $links = parse_xml_string($xmlhead."".unxmlify($obj->link).""); - - $Bname = $obj->title; - $Blink = ""; $Bphoto = ""; - foreach ($links->link as $l){ - $atts = $l->attributes(); - switch($atts['rel']){ - case "alternate": $Blink = $atts['href']; - case "photo": $Bphoto = $atts['href']; - } + $obj= json_decode($item['object'],true); + + $Blink = $Bphoto = ''; + if($obj['link']) { + $Blink = get_rel_link($obj['link'],'alternate'); + $Bphoto = get_rel_link($obj['link'],'photo'); } + $Bname = $obj['title']; + $A = '[url=' . zid($Alink) . ']' . $Aname . '[/url]'; $B = '[url=' . zid($Blink) . ']' . $Bname . '[/url]'; - if ($Bphoto!="") $Bphoto = '[url=' . zid($Blink) . '][img]' . $Bphoto . '[/img][/url]'; - - $item['body'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$Bphoto; + if ($Bphoto!="") $Bphoto = '[url=' . zid($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]'; + $item['body'] = $item['localize'] = sprintf( t('%1$s is now friends with %2$s'), $A, $B); + $item['body'] .= "\n\n\n" . $Bphoto; } + if (stristr($item['verb'],ACTIVITY_POKE)) { $verb = urldecode(substr($item['verb'],strpos($item['verb'],'#')+1)); if(! $verb) return; if ($item['obj_type']=="" || $item['obj_type']!== ACTIVITY_OBJ_PERSON) return; - $Aname = $item['author-name']; - $Alink = $item['author-link']; + $Aname = $item['author']['xchan_name']; + $Alink = $item['author']['xchan_url']; - $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; - $obj = parse_xml_string($xmlhead.$item['object']); - $links = parse_xml_string($xmlhead."".unxmlify($obj->link).""); - - $Bname = $obj->title; - $Blink = ""; $Bphoto = ""; - foreach ($links->link as $l){ - $atts = $l->attributes(); - switch($atts['rel']){ - case "alternate": $Blink = $atts['href']; - case "photo": $Bphoto = $atts['href']; - } + $obj= json_decode($item['object'],true); + + $Blink = $Bphoto = ''; + if($obj['link']) { + $Blink = get_rel_link($obj['link'],'alternate'); + $Bphoto = get_rel_link($obj['link'],'photo'); } + $Bname = $obj['title']; $A = '[url=' . zid($Alink) . ']' . $Aname . '[/url]'; $B = '[url=' . zid($Blink) . ']' . $Bname . '[/url]'; @@ -215,7 +205,8 @@ function localize_item(&$item,$brief = false){ // then do the sprintf on the translation string - $item['body'] = sprintf($txt, $A, $B). "\n\n\n" . $Bphoto; + $item['body'] = $item['localize'] = sprintf($txt, $A, $B); + $item['body'] .= "\n\n\n" . $Bphoto; } if (stristr($item['verb'],ACTIVITY_MOOD)) { @@ -223,14 +214,18 @@ function localize_item(&$item,$brief = false){ if(! $verb) return; - $Aname = $item['author-name']; - $Alink = $item['author-link']; + $Aname = $item['author']['xchan_name']; + $Alink = $item['author']['xchan_url']; + $A = '[url=' . zid($Alink) . ']' . $Aname . '[/url]'; $txt = t('%1$s is currently %2$s'); $item['body'] = sprintf($txt, $A, t($verb)); } +/* +// FIXME store parent item as object or target +// (and update to json storage) if (activity_match($item['verb'],ACTIVITY_TAG)) { $r = q("SELECT * from `item`,`contact` WHERE @@ -269,13 +264,14 @@ function localize_item(&$item,$brief = false){ $item['body'] = sprintf( t('%1$s tagged %2$s\'s %3$s with %4$s'), $author, $objauthor, $plink, $tag ); } + if (activity_match($item['verb'],ACTIVITY_FAVORITE)){ if ($item['obj_type']== "") return; - $Aname = $item['author-name']; - $Alink = $item['author-link']; + $Aname = $item['author']['xchan_name']; + $Alink = $item['author']['xchan_url']; $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; @@ -297,6 +293,8 @@ function localize_item(&$item,$brief = false){ } } } +*/ + $matches = null; if(preg_match_all('/@\[url=(.*?)\]/is',$item['body'],$matches,PREG_SET_ORDER)) { foreach($matches as $mtch) { diff --git a/include/notify.php b/include/notify.php index 468c31558..a551444ee 100644 --- a/include/notify.php +++ b/include/notify.php @@ -13,17 +13,17 @@ return array(); // Call localize_item with the "brief" flag to get a one line status for activities. // This should set $item['localized'] to indicate we have a brief summary. - localize_item($item,true); + localize_item($item); // FIXME - we may need the parent - if(! $item['localized']) { + if(! $item['localize']) { $itemem_text = (($item['item_flags'] & ITEM_THREAD_TOP) ? sprintf( t("%s created a new post"), $item['author']['xchan_name']) : sprintf( t("%s commented on %s's post"), $item['author']['xchan_name'], $item['pname'])); } else - $itemem_text = $item['body']; + $itemem_text = $item['localize']; // convert this logic into a json array just like the system notifications diff --git a/include/text.php b/include/text.php index ee7595c01..4458cdaa4 100644 --- a/include/text.php +++ b/include/text.php @@ -364,7 +364,7 @@ function item_message_id() { $dups = false; $hash = random_string(); - $uri = $hash . '@' . $hostname; + $uri = $hash . '@' . get_app()->get_hostname(); $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($uri)); @@ -527,8 +527,8 @@ function contact_block() { $o = ''; $a = get_app(); -logger('contact block'); $shown = get_pconfig($a->profile['uid'],'system','display_friend_count'); + if($shown === false) $shown = 24; if($shown == 0) @@ -1730,11 +1730,11 @@ function find_xchan_in_array($xchan,$arr) { return array(); } -function get_json_rel_link($j,$rel) { +function get_rel_link($j,$rel) { if(count($j)) foreach($j as $l) - if($l->rel === $rel) - return $l->href; + if($l['rel'] === $rel) + return $l['href']; return ''; } diff --git a/mod/mood.php b/mod/mood.php index 8992c55e3..ddd721823 100755 --- a/mod/mood.php +++ b/mod/mood.php @@ -30,7 +30,7 @@ function mood_init(&$a) { if($parent) { - $r = q("select uri, private, allow_cid, allow_gid, deny_cid, deny_gid + $r = q("select uri, owner_xchan, private, allow_cid, allow_gid, deny_cid, deny_gid from item where id = %d and parent = %d and uid = %d limit 1", intval($parent), intval($parent), @@ -47,62 +47,55 @@ function mood_init(&$a) { } else { - $private = 0; + $private = 0; + $channel = $a->get_channel(); - $allow_cid = $a->user['allow_cid']; - $allow_gid = $a->user['allow_gid']; - $deny_cid = $a->user['deny_cid']; - $deny_gid = $a->user['deny_gid']; + $allow_cid = $channel['channel_allow_cid']; + $allow_gid = $channel['channel_allow_gid']; + $deny_cid = $channel['channel_deny_cid']; + $deny_gid = $channel['channel_deny_gid']; } - $poster = $a->contact; + $poster = $a->get_observer(); $uri = item_message_id(); - $action = sprintf( t('%1$s is currently %2$s'), '[url=' . $poster['url'] . ']' . $poster['name'] . '[/url]' , $verbs[$verb]); + $action = sprintf( t('%1$s is currently %2$s'), '[url=' . $poster['xchan_url'] . ']' . $poster['xchan_name'] . '[/url]' , $verbs[$verb]); + $item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN; + if(! $parent_uri) + $item_flags |= ITEM_THREAD_TOP; + $arr = array(); + $arr['aid'] = get_account_id(); $arr['uid'] = $uid; $arr['uri'] = $uri; - $arr['parent-uri'] = (($parent_uri) ? $parent_uri : $uri); - $arr['type'] = 'activity'; - $arr['wall'] = 1; - $arr['contact-id'] = $poster['id']; - $arr['owner-name'] = $poster['name']; - $arr['owner-link'] = $poster['url']; - $arr['owner-avatar'] = $poster['thumb']; - $arr['author-name'] = $poster['name']; - $arr['author-link'] = $poster['url']; - $arr['author-avatar'] = $poster['thumb']; + $arr['parent_uri'] = (($parent_uri) ? $parent_uri : $uri); + $arr['item_flags'] = $item_flags; + $arr['author_xchan'] = $poster['xchan_hash']; + $arr['owner_xchan'] = (($parent_uri) ? $r[0]['owner_xchan'] : $poster['xchan_hash']); $arr['title'] = ''; $arr['allow_cid'] = $allow_cid; $arr['allow_gid'] = $allow_gid; $arr['deny_cid'] = $deny_cid; $arr['deny_gid'] = $deny_gid; - $arr['last-child'] = 1; - $arr['visible'] = 1; $arr['verb'] = $activity; - $arr['private'] = $private; - - $arr['origin'] = 1; $arr['body'] = $action; $item_id = item_store($arr); if($item_id) { - q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", - dbesc($a->get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id), - intval($uid), - intval($item_id) - ); - proc_run('php',"include/notifier.php","tag","$item_id"); - } +// q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", +// dbesc($a->get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id), +// intval($uid), +// intval($item_id) +// ); + proc_run('php',"include/notifier.php","activity", $item_id); - call_hooks('post_local_end', $arr); - - proc_run('php',"include/notifier.php","like","$post_id"); + } + call_hooks('post_local_end', $arr); return; } -- cgit v1.2.3