From c462ed9fc50e2c2a60e8cb01314a7d5fa498b412 Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Thu, 1 Mar 2012 11:32:49 +0100 Subject: template proc: avoid a notice and allow template name to include to be passed with a variable value --- include/template_processor.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/template_processor.php b/include/template_processor.php index 28c3f07dd..b4d444e1c 100755 --- a/include/template_processor.php +++ b/include/template_processor.php @@ -116,7 +116,15 @@ * {{ inc [with $var1=$var2] }}{{ endinc }} */ private function _replcb_inc($args){ - list($tplfile, $newctx) = array_map('trim', explode("with",$args[2])); + if (strpos($args[2],"with")) { + list($tplfile, $newctx) = array_map('trim', explode("with",$args[2])); + } else { + $tplfile = trim($args[2]); + $newctx = null; + } + + if ($tplfile[0]=="$") $tplfile = $this->_get_var($tplfile); + $this->_push_stack(); $r = $this->r; if (!is_null($newctx)) { -- cgit v1.2.3 From ed42fa7d59f0eb979b3b5c86b6969c53d6b6573b Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Thu, 1 Mar 2012 11:46:08 +0100 Subject: conversation: remove templating items in code and move it to template. --- include/conversation.php | 197 +++++++++++++++++++++++++---------------------- 1 file changed, 103 insertions(+), 94 deletions(-) (limited to 'include') diff --git a/include/conversation.php b/include/conversation.php index 2ef37694d..f4740688c 100755 --- a/include/conversation.php +++ b/include/conversation.php @@ -6,11 +6,6 @@ function localize_item(&$item){ $Text = $item['body']; - - - // find private image (w/data url) if present and convert image - // link to a magic-auth redirect. - $saved_image = ''; $img_start = strpos($Text,'[img]data:'); $img_end = strpos($Text,'[/img]'); @@ -184,6 +179,7 @@ function localize_item(&$item){ * that are based on unique features of the calling module. * */ + if(!function_exists('conversation')){ function conversation(&$a, $items, $mode, $update, $preview = false) { require_once('bbcode.php'); @@ -231,13 +227,13 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $items = $cb['items']; $cmnt_tpl = get_markup_template('comment_item.tpl'); - $tpl = get_markup_template('wall_item.tpl'); - $wallwall = get_markup_template('wallwall_item.tpl'); + $tpl = 'wall_item.tpl'; + $wallwall = 'wallwall_item.tpl'; $hide_comments_tpl = get_markup_template('hide_comments.tpl'); $alike = array(); $dlike = array(); - $o = ""; + // array with html for each thread (parent+comments) $threads = array(); @@ -250,7 +246,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { // "New Item View" on network page or search page results // - just loop through the items and format them minimally for display - $tpl = get_markup_template('search_item.tpl'); + //$tpl = get_markup_template('search_item.tpl'); + $tpl = 'search_item.tpl'; foreach($items as $item) { $threadsid++; @@ -316,43 +313,46 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $body = prepare_body($item,true); - $tmp_item = replace_macros($tpl,array( - '$id' => (($preview) ? 'P0' : $item['item_id']), - '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), - '$profile_url' => $profile_link, - '$item_photo_menu' => item_photo_menu($item), - '$name' => template_escape($profile_name), - '$sparkle' => $sparkle, - '$lock' => $lock, - '$thumb' => $profile_avatar, - '$title' => template_escape($item['title']), - '$body' => template_escape($body), - '$ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), - '$lock' => $lock, - '$location' => template_escape($location), - '$indent' => '', - '$owner_name' => template_escape($owner_name), - '$owner_url' => $owner_url, - '$owner_photo' => $owner_photo, - '$plink' => get_plink($item), - '$edpost' => false, - '$isstarred' => $isstarred, - '$star' => $star, - '$drop' => $drop, - '$vote' => $likebuttons, - '$like' => '', - '$dislike' => '', - '$comment' => '', - '$conv' => (($preview) ? '' : array('href'=> $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))), - '$previewing' => $previewing, - '$wait' => t('Please wait'), - )); + //$tmp_item = replace_macros($tpl,array( + $tmp_item = array( + 'template' => $tpl, + 'id' => (($preview) ? 'P0' : $item['item_id']), + 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), + 'profile_url' => $profile_link, + 'item_photo_menu' => item_photo_menu($item), + 'name' => template_escape($profile_name), + 'sparkle' => $sparkle, + 'lock' => $lock, + 'thumb' => $profile_avatar, + 'title' => template_escape($item['title']), + 'body' => template_escape($body), + 'text' => strip_tags(template_escape($body)), + 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), + 'lock' => $lock, + 'location' => template_escape($location), + 'indent' => '', + 'owner_name' => template_escape($owner_name), + 'owner_url' => $owner_url, + 'owner_photo' => $owner_photo, + 'plink' => get_plink($item), + 'edpost' => false, + 'isstarred' => $isstarred, + 'star' => $star, + 'drop' => $drop, + 'vote' => $likebuttons, + 'like' => '', + 'dislike' => '', + 'comment' => '', + 'conv' => (($preview) ? '' : array('href'=> $a->get_baseurl() . '/display/' . $nickname . '/' . $item['id'], 'title'=> t('View in context'))), + 'previewing' => $previewing, + 'wait' => t('Please wait'), + ); $arr = array('item' => $item, 'output' => $tmp_item); call_hooks('display_item', $arr); $threads[$threadsid]['id'] = $item['item_id']; - $threads[$threadsid]['html'] .= $arr['output']; + $threads[$threadsid]['items'] = array($arr['output']); } @@ -385,6 +385,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { } $comments_collapsed = false; + $comment_lastcollapsed = false; + $comment_firstcollapsed = false; $blowhard = 0; $blowhard_count = 0; @@ -438,10 +440,12 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { $comments_seen = 0; $comments_collapsed = false; + $comment_lastcollapsed = false; + $comment_firstcollapsed = false; $threadsid++; $threads[$threadsid]['id'] = $item['item_id']; - $threads[$threadsid]['html'] = ""; + $threads[$threadsid]['items'] = array(); } else { @@ -449,6 +453,8 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { if((! $toplevelpost) && (! $toplevelprivate) && ($item['private']) && ($profile_owner != local_user())) continue; $comments_seen ++; + $comment_lastcollapsed = false; + $comment_firstcollapsed = false; } $override_comment_box = ((($page_writeable) && ($item_writeable)) ? true : false); @@ -456,23 +462,17 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { if(($comments[$item['parent']] > 2) && ($comments_seen <= ($comments[$item['parent']] - 2)) && ($item['gravity'] == 6)) { - if(! $comments_collapsed) { - - // IMPORTANT: the closing in the hide_comments template - // is supplied below in code. - $threads[$threadsid]['html'] .= replace_macros($hide_comments_tpl,array( - '$id' => $item['parent'], - '$num_comments' => sprintf( tt('%d comment','%d comments',$comments[$item['parent']]), - $comments[$item['parent']]), - '$display' => 'none', - '$hide_text' => t('show more') - )); + if (!$comments_collapsed){ + $threads[$threadsid]['num_comments'] = sprintf( tt('%d comment','%d comments',$comments[$item['parent']]),$comments[$item['parent']] ); + $threads[$threadsid]['hide_text'] = t('show more'); $comments_collapsed = true; + $comment_firstcollapsed = true; } } if(($comments[$item['parent']] > 2) && ($comments_seen == ($comments[$item['parent']] - 1))) { - $threads[$threadsid]['html'] .= ''; + + $comment_lastcollapsed = true; } $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ; @@ -649,63 +649,72 @@ function conversation(&$a, $items, $mode, $update, $preview = false) { // Build the HTML $body = prepare_body($item,true); + //$tmp_item = replace_macros($template, + $tmp_item = array( + // collapse comments in template. I don't like this much... + 'comment_firstcollapsed' => $comment_firstcollapsed, + 'comment_lastcollapsed' => $comment_lastcollapsed, + // template to use to render item (wall, walltowall, search) + 'template' => $template, + + 'type' => implode("",array_slice(split("/",$item['verb']),-1)), + 'tags' => $tags, + 'body' => template_escape($body), + 'text' => strip_tags(template_escape($body)), + 'id' => $item['item_id'], + 'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), + 'olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), + 'to' => t('to'), + 'wall' => t('Wall-to-Wall'), + 'vwall' => t('via Wall-To-Wall:'), + 'profile_url' => $profile_link, + 'item_photo_menu' => item_photo_menu($item), + 'name' => template_escape($profile_name), + 'thumb' => $profile_avatar, + 'osparkle' => $osparkle, + 'sparkle' => $sparkle, + 'title' => template_escape($item['title']), + 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), + 'lock' => $lock, + 'location' => template_escape($location), + 'indent' => $indent, + 'owner_url' => $owner_url, + 'owner_photo' => $owner_photo, + 'owner_name' => template_escape($owner_name), + 'plink' => get_plink($item), + 'edpost' => $edpost, + 'isstarred' => $isstarred, + 'star' => $star, + 'drop' => $drop, + 'vote' => $likebuttons, + 'like' => $like, + 'dislike' => $dislike, + 'comment' => $comment, + 'previewing' => $previewing, + 'wait' => t('Please wait'), - $tmp_item = replace_macros($template,array( - '$type' => implode("",array_slice(explode("/",$item['verb']),-1)), - '$tags' => $tags, - '$body' => template_escape($body), - '$id' => $item['item_id'], - '$linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])), - '$olinktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), - '$to' => t('to'), - '$wall' => t('Wall-to-Wall'), - '$vwall' => t('via Wall-To-Wall:'), - '$profile_url' => $profile_link, - '$item_photo_menu' => item_photo_menu($item), - '$name' => template_escape($profile_name), - '$thumb' => $profile_avatar, - '$osparkle' => $osparkle, - '$sparkle' => $sparkle, - '$title' => template_escape($item['title']), - '$ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), - '$lock' => $lock, - '$location' => template_escape($location), - '$indent' => $indent, - '$owner_url' => $owner_url, - '$owner_photo' => $owner_photo, - '$owner_name' => template_escape($owner_name), - '$plink' => get_plink($item), - '$edpost' => $edpost, - '$isstarred' => $isstarred, - '$star' => $star, - '$drop' => $drop, - '$vote' => $likebuttons, - '$like' => $like, - '$dislike' => $dislike, - '$comment' => $comment, - '$previewing' => $previewing, - '$wait' => t('Please wait'), - - )); + ); $arr = array('item' => $item, 'output' => $tmp_item); call_hooks('display_item', $arr); - $threads[$threadsid]['html'] .= $arr['output']; + $threads[$threadsid]['items'][] = $arr['output']; } } } - $page_template = get_markup_template("conversation.tpl"); $o .= replace_macros($page_template, array( + '$baseurl' => $a->get_baseurl(), + '$mode' => $mode, + '$user' => $a->user, '$threads' => $threads, '$dropping' => ($dropping?t('Delete Selected Items'):False), )); return $o; -} +}} function best_link_url($item,&$sparkle) { -- cgit v1.2.3 From 58e3372b23b286334e5195b1b8f70448715ed493 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 1 Mar 2012 18:49:23 -0800 Subject: probe for very old (0.97 or 1.0) RSS feed with an incorrect or generic content-type --- include/Scrape.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/Scrape.php b/include/Scrape.php index 4c4ad3cdb..8344aa737 100755 --- a/include/Scrape.php +++ b/include/Scrape.php @@ -255,6 +255,11 @@ function scrape_feed($url) { } } } + // perhaps an RSS version 1 feed with a generic or incorrect content-type? + if(stristr($s,'')) { + $ret['feed_rss'] = $url; + return $ret; + } } try { -- cgit v1.2.3 From f1bf6dcdfb89bf3c21e498ba3d76c600dafed934 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 2 Mar 2012 01:24:20 -0800 Subject: expand multiple heart smilies e.g. <3333 --- include/text.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'include') diff --git a/include/text.php b/include/text.php index 81e22527a..4276b7fcb 100755 --- a/include/text.php +++ b/include/text.php @@ -786,6 +786,7 @@ function smilies($s, $sample = false) { } } else { + $params['string'] = preg_replace_callback('/<(3+)/','preg_heart',$params['string']); $s = str_replace($params['texts'],$params['icons'],$params['string']); } @@ -804,7 +805,18 @@ function smile_decode($m) { return(str_replace($m[1],base64url_decode($m[1]),$m[0])); } +// expand <3333 to the correct number of hearts +function preg_heart($x) { + $a = get_app(); + if(strlen($x[1]) == 1) + return $x[0]; + $t = ''; + for($cnt = 0; $cnt < strlen($x[1]); $cnt ++) + $t .= '<3'; + $r = str_replace($x[0],$t,$x[0]); + return $r; +} if(! function_exists('day_translate')) { -- cgit v1.2.3 From 60e5dda1b5e1be36a15c45ded2635340087a0b0f Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Fri, 2 Mar 2012 12:24:35 +0100 Subject: template proc: first optimization --- include/template_processor.php | 31 ++++++++++++++++++++++--------- include/text.php | 8 +++++++- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/template_processor.php b/include/template_processor.php index b4d444e1c..a80a3997a 100755 --- a/include/template_processor.php +++ b/include/template_processor.php @@ -1,5 +1,5 @@ stack[] = array($this->r, $this->search, $this->replace, $this->nodes); + $this->stack[] = array($this->r, $this->nodes); } private function _pop_stack(){ - list($this->r, $this->search, $this->replace, $this->nodes) = array_pop($this->stack); + list($this->r, $this->nodes) = array_pop($this->stack); } - private function _get_var($name){ - $keys = array_map('trim',explode(".",$name)); + private function _get_var($name, $retNoKey=false){ + $keys = array_map('trim',explode(".",$name)); + if ($retNoKey && !array_key_exists($keys[0], $this->r)) return KEY_NOT_EXISTS; $val = $this->r; foreach($keys as $k) { $val = (isset($val[$k]) ? $val[$k] : null); @@ -194,13 +195,24 @@ return str_replace($this->search,$this->replace, $str); }*/ + private function var_replace($s){ + $m = array(); + if (preg_match_all('/\$([a-zA-Z0-9-_]+\.*)+/', $s,$m)){ + foreach($m[0] as $var){ + $val = $this->_get_var($var, true); + if ($val!=KEY_NOT_EXISTS) + $s = str_replace($var, $val, $s); + } + } + return $s; + } public function replace($s, $r) { $this->r = $r; - $this->search = array(); - $this->replace = array(); + /*$this->search = array(); + $this->replace = array();*/ - $this->_build_replace($r, ""); + //$this->_build_replace($r, ""); #$s = str_replace(array("\n","\r"),array("§n§","§r§"),$s); $s = $this->_build_nodes($s); @@ -215,7 +227,8 @@ while($os!=$s && $count<10){ $os=$s; $count++; //$s = $this->_str_replace($s); - $s = str_replace($this->search, $this->replace, $s); + $s = $this->var_replace($s); + //$s = str_replace($this->search, $this->replace, $s); } return template_unescape($s); } diff --git a/include/text.php b/include/text.php index 4276b7fcb..042ee982c 100755 --- a/include/text.php +++ b/include/text.php @@ -14,7 +14,13 @@ if(! function_exists('replace_macros')) { function replace_macros($s,$r) { global $t; - return $t->replace($s,$r); + //$ts = microtime(); + $r = $t->replace($s,$r); + //$tt = microtime() - $ts; + + //$a = get_app(); + //$a->page['debug'] .= "$tt
\n"; + return $r; }} -- cgit v1.2.3 From 0bf087c8957ba28b76b7bc96345908735418a71f Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Fri, 2 Mar 2012 12:36:22 +0100 Subject: template proc: remove unused function and commented out code --- include/template_processor.php | 45 +----------------------------------------- 1 file changed, 1 insertion(+), 44 deletions(-) (limited to 'include') diff --git a/include/template_processor.php b/include/template_processor.php index a80a3997a..9ac0a1313 100755 --- a/include/template_processor.php +++ b/include/template_processor.php @@ -28,19 +28,6 @@ die(); } - private function _build_replace($r, $prefix){ - - if(is_array($r) && count($r)) { - foreach ($r as $k => $v ) { - if (is_array($v)) { - $this->_build_replace($v, "$prefix$k."); - } else { - $this->search[] = $prefix . $k; - $this->replace[] = $v; - } - } - } - } private function _push_stack(){ $this->stack[] = array($this->r, $this->nodes); @@ -170,30 +157,6 @@ return $s; } - /* - private function _str_replace($str){ - #$this->search,$this->replace, - $searchs = $this->search; - foreach($searchs as $search){ - $search = "|".preg_quote($search)."(\|[a-zA-Z0-9_]*)*|"; - $m = array(); - if (preg_match_all($search, $str,$m)){ - foreach ($m[0] as $match){ - $toks = explode("|",$match); - $val = $this->_get_var($toks[0]); - for($k=1; $k1){ - $str = str_replace( $match, $val, $str); - } - } - } - - } - return str_replace($this->search,$this->replace, $str); - }*/ private function var_replace($s){ $m = array(); @@ -209,12 +172,7 @@ public function replace($s, $r) { $this->r = $r; - /*$this->search = array(); - $this->replace = array();*/ - - //$this->_build_replace($r, ""); - #$s = str_replace(array("\n","\r"),array("§n§","§r§"),$s); $s = $this->_build_nodes($s); $s = preg_replace_callback('/\|\|([0-9]+)\|\|/', array($this, "_replcb_node"), $s); @@ -222,13 +180,12 @@ // remove comments block $s = preg_replace('/{#[^#]*#}/', "" , $s); + // replace strings recursively (limit to 10 loops) $os = ""; $count=0; while($os!=$s && $count<10){ $os=$s; $count++; - //$s = $this->_str_replace($s); $s = $this->var_replace($s); - //$s = str_replace($this->search, $this->replace, $s); } return template_unescape($s); } -- cgit v1.2.3 From aef737f37637270b4f79ea390ee23a61f7fcb4ba Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Fri, 2 Mar 2012 15:53:48 +0100 Subject: template proc: allow isolation of var name between [ and ] $var.name -> $[var.name] --- include/template_processor.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/template_processor.php b/include/template_processor.php index 9ac0a1313..111fc5849 100755 --- a/include/template_processor.php +++ b/include/template_processor.php @@ -160,13 +160,15 @@ private function var_replace($s){ $m = array(); - if (preg_match_all('/\$([a-zA-Z0-9-_]+\.*)+/', $s,$m)){ + if (preg_match_all('/\$\[{0,1}([a-zA-Z0-9-_]+\.*)+\]{0,1}/', $s,$m)){ foreach($m[0] as $var){ - $val = $this->_get_var($var, true); + $varn = str_replace(array("[","]"), array("",""), $var); + $val = $this->_get_var($varn, true); if ($val!=KEY_NOT_EXISTS) $s = str_replace($var, $val, $s); } } + return $s; } -- cgit v1.2.3 From 685686b3e81e53264b4946f54904e8f5323da2ea Mon Sep 17 00:00:00 2001 From: Fabio Comuni Date: Sat, 3 Mar 2012 00:00:38 +0100 Subject: template proc: fix variables regexp --- include/template_processor.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/template_processor.php b/include/template_processor.php index 111fc5849..8671587fc 100755 --- a/include/template_processor.php +++ b/include/template_processor.php @@ -160,7 +160,16 @@ private function var_replace($s){ $m = array(); - if (preg_match_all('/\$\[{0,1}([a-zA-Z0-9-_]+\.*)+\]{0,1}/', $s,$m)){ + /** regexp: + * \$ literal $ + * (\[)? optional open square bracket + * ([a-zA-Z0-9-_]+\.?)+ var name, followed by optional + * dot, repeated at least 1 time + * (?(1)\]) if there was opened square bracket + * (subgrup 1), match close bracket + */ + if (preg_match_all('/\$(\[)?([a-zA-Z0-9-_]+\.?)+(?(1)\])/', $s,$m)){ + foreach($m[0] as $var){ $varn = str_replace(array("[","]"), array("",""), $var); $val = $this->_get_var($varn, true); -- cgit v1.2.3 From 4134fd3dcee1b26b888c89c47f798fd3fd058064 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 4 Mar 2012 16:26:16 -0800 Subject: unused replacement variable displays %1 in all html2bbcode 'code' blocks --- include/html2bbcode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/html2bbcode.php b/include/html2bbcode.php index 51d629940..32a90d7d6 100755 --- a/include/html2bbcode.php +++ b/include/html2bbcode.php @@ -212,7 +212,7 @@ function html2bbcode($message) node2bbcode($doc, 'audio', array('src'=>'/(.+)/'), '[audio]$1', '[/audio]'); node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), '[iframe]$1', '[/iframe]'); - node2bbcode($doc, 'code', array(), '[code]$1', '[/code]'); + node2bbcode($doc, 'code', array(), '[code]', '[/code]'); $message = $doc->saveHTML(); -- cgit v1.2.3 From fba089012a3b4cd8c2969e111173bab0d58b6750 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 4 Mar 2012 18:50:32 -0800 Subject: correct owner info from misconfigured installs, duepuntozero title block misplaced in editplain mode --- include/items.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'include') diff --git a/include/items.php b/include/items.php index a1254e165..3c55fbb4f 100755 --- a/include/items.php +++ b/include/items.php @@ -1747,6 +1747,18 @@ function consume_feed($xml,$importer,&$contact, &$hub, $datedir = 0, $pass = 0) $datarray['parent-uri'] = $item_id; $datarray['uid'] = $importer['uid']; $datarray['contact-id'] = $contact['id']; + + if(x($datarray,'owner-link') && strlen($datarray['owner-link']) && (! link_compare($datarray['owner-link'],$contact['url']))) { + // The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery, + // but otherwise there's a possible data mixup on the sender's system. + // the tgroup delivery code called from item_store will correct it if it's a forum, + // but we're going to unconditionally correct it here so that the post will always be owned by our contact. + logger('local_delivery: Correcting item owner.', LOGGER_DEBUG); + $datarray['owner-name'] = $contact['name']; + $datarray['owner-link'] = $contact['url']; + $datarray['owner-avatar'] = $contact['thumb']; + } + $r = item_store($datarray); continue; @@ -2439,6 +2451,18 @@ function local_delivery($importer,$data) { $datarray['parent-uri'] = $item_id; $datarray['uid'] = $importer['importer_uid']; $datarray['contact-id'] = $importer['id']; + + if(x($datarray,'owner-link') && strlen($datarray['owner-link']) && (! link_compare($datarray['owner-link'],$importer['url']))) { + // The item owner info is not our contact. It's OK and is to be expected if this is a tgroup delivery, + // but otherwise there's a possible data mixup on the sender's system. + // the tgroup delivery code called from item_store will correct it if it's a forum, + // but we're going to unconditionally correct it here so that the post will always be owned by our contact. + logger('local_delivery: Correcting item owner.', LOGGER_DEBUG); + $datarray['owner-name'] = $importer['senderName']; + $datarray['owner-link'] = $importer['url']; + $datarray['owner-avatar'] = $importer['thumb']; + } + $r = item_store($datarray); continue; } -- cgit v1.2.3