From 81d003cad1842a8375c88ad02dbd0a5a6bc8a0c5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 19 Dec 2016 23:30:50 -0500 Subject: [PATCH 1/9] Diaspora: Complete /people/* links from fcontact or author domain --- include/diaspora.php | 72 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index f2d4848678..453f3cb9c4 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -700,6 +700,33 @@ class diaspora { return strtolower($handle); } + /** + * @brief get a url (scheme://domain.tld/u/user) from a given Diaspora + * fcontact id or guid + * + * @param mixed $contact_id Either the numeric id or the string guid + * + * @return string the url + */ + public static function url_from_fcontact($contact_id) { + $handle = False; + + logger("fcontact id is ".$contact_id, LOGGER_DEBUG); + + if (is_numeric($contact_id)) { + $r = q("SELECT `url` FROM `fcontact` WHERE `id` = %d AND `network` = 'dspr' `url` != ''", + intval($contact_id)); + }else { + $r = q("SELECT `url` FROM `fcontact` WHERE `guid` = '%s' AND `network` = 'dspr' AND `url` != ''", + $contact_id); + } + if ($r) { + return $r[0]['url']; + } + + return null; + } + /** * @brief Get a contact id for a given handle * @@ -826,6 +853,37 @@ class diaspora { },$item["body"]); } + /** + * @brief Checks for relative /people/* links to match local contacts or + * prepends the remote host taken from the author link + * + * @param string $body The item body to replace links from + * @param string $author_link The author link for missing local contact fallback + */ + public function replace_people_guid($body, $author_link) { + $return = preg_replace_callback("&\[url=/people/([^\[\]]*)\](.*)\[\/url\]&Usi", + function ($match) use ($author_link){ + // $match + // 0 => '[url=/people/0123456789abcdef]Foo Bar[/url]' + // 1 => '0123456789abcdef' + // 2 => 'Foo Bar' + $handle = self::url_from_fcontact($match[1]); + + if ($handle) { + $return = '@[url='.$handle.']'.$match[2].'[/url]'; + }else { + // No local match, restoring absolute remote URL from author scheme and host + $author_url = parse_url($author_link); + $return = '[url='.$author_url['scheme'].'://'.$author_url['host'].'/people/'.$match[1].']'.$match[2].'[/url]'; + } + + return $return; + + }, $body); + + return $return; + } + /** * @brief sub function of "fetch_guid" which checks for links in messages * @@ -1170,6 +1228,8 @@ class diaspora { $datarray["body"] = diaspora2bb($text); + $datarray["body"] = self::replace_people_gui($datarray); + self::fetch_guid($datarray); $message_id = item_store($datarray); @@ -1564,7 +1624,8 @@ class diaspora { $reply = 0; - $body = diaspora2bb($text); + $body = self::replace_people_guid(diaspora2bb($text), $person["url"]); + $message_uri = $author.":".$guid; $person = self::person_by_handle($author); @@ -2031,7 +2092,7 @@ class diaspora { if (self::is_reshare($r[0]["body"], true)) $r = array(); elseif (self::is_reshare($r[0]["body"], false)) { - $r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"])); + $r[0]["body"] = self::replace_people_guid(diaspora2bb(bb2diaspora($r[0]["body"])), $r[0]["author-link"]); // Add OEmbed and other information to the body $r[0]["body"] = add_page_info_to_body($r[0]["body"], false, true); @@ -2060,8 +2121,9 @@ class diaspora { if ($r) { // If it is a reshared post from another network then reformat to avoid display problems with two share elements - if (self::is_reshare($r[0]["body"], false)) - $r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"])); + if (self::is_reshare($r[0]["body"], false)) { + $r[0]["body"] = self::replace_people_guid(diaspora2bb(bb2diaspora($r[0]["body"])), $r[0]["author-link"]); + } return $r[0]; } @@ -2319,7 +2381,7 @@ class diaspora { $datarray["object"] = $xml; - $datarray["body"] = $body; + $datarray["body"] = self::replace_people_guid($body, $datarray["author-link"]); if ($provider_display_name != "") $datarray["app"] = $provider_display_name; From 4a7c3b9eefd381bb5c77a96a4311ceb558a1c1a5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 20 Dec 2016 12:44:15 -0500 Subject: [PATCH 2/9] Diaspora: Fix class name case + add self --- include/Contact.php | 2 +- include/api.php | 2 +- include/contact_selectors.php | 2 +- include/delivery.php | 10 +++++----- include/diaspora.php | 8 ++++---- include/follow.php | 2 +- include/like.php | 2 +- include/notifier.php | 2 +- include/profile_update.php | 2 +- include/queue.php | 2 +- mod/dfrn_confirm.php | 2 +- mod/fetch.php | 6 +++--- mod/item.php | 2 +- mod/p.php | 4 ++-- mod/receive.php | 6 +++--- object/Item.php | 2 +- 16 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 8a33e3fe91..83be830469 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -115,7 +115,7 @@ function terminate_friendship($user,$self,$contact) { } elseif($contact['network'] === NETWORK_DIASPORA) { require_once('include/diaspora.php'); - diaspora::send_unshare($user,$contact); + Diaspora::send_unshare($user,$contact); } elseif($contact['network'] === NETWORK_DFRN) { require_once('include/dfrn.php'); diff --git a/include/api.php b/include/api.php index 1f3c762989..6253a2280a 100644 --- a/include/api.php +++ b/include/api.php @@ -3218,7 +3218,7 @@ function api_share_as_retweet(&$item) { $body = trim($item["body"]); - if (diaspora::is_reshare($body, false)===false) { + if (Diaspora::is_reshare($body, false)===false) { return false; } diff --git a/include/contact_selectors.php b/include/contact_selectors.php index 35c9d983d7..5e9c06aed7 100644 --- a/include/contact_selectors.php +++ b/include/contact_selectors.php @@ -99,7 +99,7 @@ function network_to_name($s, $profile = "") { $networkname = str_replace($search,$replace,$s); - if (($s == NETWORK_DIASPORA) AND ($profile != "") AND diaspora::is_redmatrix($profile)) { + if (($s == NETWORK_DIASPORA) AND ($profile != "") AND Diaspora::is_redmatrix($profile)) { $networkname = t("Hubzilla/Redmatrix"); $r = q("SELECT `gserver`.`platform` FROM `gcontact` diff --git a/include/delivery.php b/include/delivery.php index 8fce987742..81152a2df2 100644 --- a/include/delivery.php +++ b/include/delivery.php @@ -508,7 +508,7 @@ function delivery_run(&$argv, &$argc){ break; if ($mail) { - diaspora::send_mail($item,$owner,$contact); + Diaspora::send_mail($item,$owner,$contact); break; } @@ -530,22 +530,22 @@ function delivery_run(&$argv, &$argc){ if (($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) { // top-level retraction logger('diaspora retract: '.$loc); - diaspora::send_retraction($target_item,$owner,$contact,$public_message); + Diaspora::send_retraction($target_item,$owner,$contact,$public_message); break; } elseif ($followup) { // send comments and likes to owner to relay logger('diaspora followup: '.$loc); - diaspora::send_followup($target_item,$owner,$contact,$public_message); + Diaspora::send_followup($target_item,$owner,$contact,$public_message); break; } elseif ($target_item['uri'] !== $target_item['parent-uri']) { // we are the relay - send comments, likes and relayable_retractions to our conversants logger('diaspora relay: '.$loc); - diaspora::send_relay($target_item,$owner,$contact,$public_message); + Diaspora::send_relay($target_item,$owner,$contact,$public_message); break; } elseif ($top_level && !$walltowall) { // currently no workable solution for sending walltowall logger('diaspora status: '.$loc); - diaspora::send_status($target_item,$owner,$contact,$public_message); + Diaspora::send_status($target_item,$owner,$contact,$public_message); break; } diff --git a/include/diaspora.php b/include/diaspora.php index 453f3cb9c4..dd8c00a6fb 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -23,7 +23,7 @@ require_once("include/queue_fn.php"); * @brief This class contain functions to create and send Diaspora XML files * */ -class diaspora { +class Diaspora { /** * @brief Return a list of relay servers @@ -344,7 +344,7 @@ class diaspora { // This will often be different with relayed messages (for example "like" and "comment") $sender = $msg["author"]; - if (!diaspora::valid_posting($msg, $fields)) { + if (!self::valid_posting($msg, $fields)) { logger("Invalid posting"); return false; } @@ -2444,7 +2444,7 @@ class diaspora { $b64url_data = base64url_encode($msg); $data = str_replace(array("\n", "\r", " ", "\t"), array("", "", "", ""), $b64url_data); - $key_id = base64url_encode(diaspora::my_handle($user)); + $key_id = base64url_encode(self::my_handle($user)); $type = "application/xml"; $encoding = "base64url"; $alg = "RSA-SHA256"; @@ -2970,7 +2970,7 @@ class diaspora { */ public static function send_status($item, $owner, $contact, $public_batch = false) { - $status = diaspora::build_status($item, $owner); + $status = self::build_status($item, $owner); return self::build_and_transmit($owner, $contact, $status["type"], $status["message"], $public_batch, $item["guid"]); } diff --git a/include/follow.php b/include/follow.php index 1c33edf80e..2cb72a6068 100644 --- a/include/follow.php +++ b/include/follow.php @@ -302,7 +302,7 @@ function new_contact($uid,$url,$interactive = false) { } if($contact['network'] == NETWORK_DIASPORA) { require_once('include/diaspora.php'); - $ret = diaspora::send_share($a->user,$contact); + $ret = Diaspora::send_share($a->user,$contact); logger('share returns: '.$ret); } } diff --git a/include/like.php b/include/like.php index 118ec81ca1..c2fa3bd199 100644 --- a/include/like.php +++ b/include/like.php @@ -239,7 +239,7 @@ EOT; // Save the author information for the like in case we need to relay to Diaspora - diaspora::store_like_signature($contact, $post_id); + Diaspora::store_like_signature($contact, $post_id); $arr['id'] = $post_id; diff --git a/include/notifier.php b/include/notifier.php index 812752a55c..37512ebd6a 100644 --- a/include/notifier.php +++ b/include/notifier.php @@ -570,7 +570,7 @@ function notifier_run(&$argv, &$argc){ if($public_message) { if (!$followup) - $r0 = diaspora::relay_list(); + $r0 = Diaspora::relay_list(); else $r0 = array(); diff --git a/include/profile_update.php b/include/profile_update.php index 399150f21c..7aa34d45d7 100644 --- a/include/profile_update.php +++ b/include/profile_update.php @@ -2,5 +2,5 @@ require_once('include/diaspora.php'); function profile_change() { - diaspora::send_profile(local_user()); + Diaspora::send_profile(local_user()); } diff --git a/include/queue.php b/include/queue.php index ad7079e959..852315878d 100644 --- a/include/queue.php +++ b/include/queue.php @@ -195,7 +195,7 @@ function queue_run(&$argv, &$argc){ case NETWORK_DIASPORA: if($contact['notify']) { logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>'); - $deliver_status = diaspora::transmit($owner,$contact,$data,$public,true); + $deliver_status = Diaspora::transmit($owner,$contact,$data,$public,true); if($deliver_status == (-1)) { update_queue_time($q_item['id']); diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 5aea4eede9..45243900c2 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -433,7 +433,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) { if(($contact) && ($contact['network'] === NETWORK_DIASPORA)) { require_once('include/diaspora.php'); - $ret = diaspora::send_share($user[0],$r[0]); + $ret = Diaspora::send_share($user[0],$r[0]); logger('share returns: ' . $ret); } diff --git a/mod/fetch.php b/mod/fetch.php index 1c73ad3718..753e286be7 100644 --- a/mod/fetch.php +++ b/mod/fetch.php @@ -50,12 +50,12 @@ function fetch_init($a){ } $user = $r[0]; - $status = diaspora::build_status($item[0], $user); - $xml = diaspora::build_post_xml($status["type"], $status["message"]); + $status = Diaspora::build_status($item[0], $user); + $xml = Diaspora::build_post_xml($status["type"], $status["message"]); // Send the envelope header("Content-Type: application/magic-envelope+xml; charset=utf-8"); - echo diaspora::build_magic_envelope($xml, $user); + echo Diaspora::build_magic_envelope($xml, $user); killme(); } diff --git a/mod/item.php b/mod/item.php index 170bed12a5..c8575a961e 100644 --- a/mod/item.php +++ b/mod/item.php @@ -952,7 +952,7 @@ function item_post(&$a) { // Store the comment signature information in case we need to relay to Diaspora - diaspora::store_comment_signature($datarray, $author, ($self ? $user['prvkey'] : false), $post_id); + Diaspora::store_comment_signature($datarray, $author, ($self ? $user['prvkey'] : false), $post_id); } else { $parent = $post_id; diff --git a/mod/p.php b/mod/p.php index 8da044e932..8d535145dc 100644 --- a/mod/p.php +++ b/mod/p.php @@ -54,8 +54,8 @@ function p_init($a){ } $user = $r[0]; - $status = diaspora::build_status($item[0], $user); - $xml = diaspora::build_post_xml($status["type"], $status["message"]); + $status = Diaspora::build_status($item[0], $user); + $xml = Diaspora::build_post_xml($status["type"], $status["message"]); header("Content-Type: application/xml; charset=utf-8"); echo $xml; diff --git a/mod/receive.php b/mod/receive.php index 4991ac47e8..571bac6def 100644 --- a/mod/receive.php +++ b/mod/receive.php @@ -53,7 +53,7 @@ function receive_post(&$a) { logger('mod-diaspora: message is okay', LOGGER_DEBUG); - $msg = diaspora::decode($importer,$xml); + $msg = Diaspora::decode($importer,$xml); logger('mod-diaspora: decoded', LOGGER_DEBUG); @@ -66,9 +66,9 @@ function receive_post(&$a) { $ret = 0; if($public) { - diaspora::dispatch_public($msg); + Diaspora::dispatch_public($msg); } else { - $ret = diaspora::dispatch($importer,$msg); + $ret = Diaspora::dispatch($importer,$msg); } http_status_exit(($ret) ? $ret : 200); diff --git a/object/Item.php b/object/Item.php index 9f01ac59b0..e6a777d8d6 100644 --- a/object/Item.php +++ b/object/Item.php @@ -334,7 +334,7 @@ class Item extends BaseObject { // Diaspora isn't able to do likes on comments - but red does if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND - !diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) + !Diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) unset($buttons["like"]); // Diaspora doesn't has multithreaded comments From 155e777d19e596b57101689aebc04298ccc356f5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 20 Dec 2016 12:49:32 -0500 Subject: [PATCH 3/9] replace_people_guid: Break down nested calls - Fix typo in function name - Fix arguments - Simplify url_from_fcontact_guid --- include/diaspora.php | 54 ++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index dd8c00a6fb..2166f8bf72 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -701,26 +701,20 @@ class Diaspora { } /** - * @brief get a url (scheme://domain.tld/u/user) from a given Diaspora - * fcontact id or guid + * @brief get a url (scheme://domain.tld/u/user) from a given Diaspora* + * fcontact guid * - * @param mixed $contact_id Either the numeric id or the string guid + * @param mixed $fcontact_guid Hexadecimal string guid * - * @return string the url + * @return string the contact url or null */ - public static function url_from_fcontact($contact_id) { - $handle = False; + public static function url_from_fcontact_guid($fcontact_guid) { + logger("fcontact guid is ".$fcontact_guid, LOGGER_DEBUG); - logger("fcontact id is ".$contact_id, LOGGER_DEBUG); + $r = q("SELECT `url` FROM `fcontact` WHERE `guid` = '%s' AND `network` = 'dspr' AND `url` != ''", + $fcontact_guid); - if (is_numeric($contact_id)) { - $r = q("SELECT `url` FROM `fcontact` WHERE `id` = %d AND `network` = 'dspr' `url` != ''", - intval($contact_id)); - }else { - $r = q("SELECT `url` FROM `fcontact` WHERE `guid` = '%s' AND `network` = 'dspr' AND `url` != ''", - $contact_id); - } - if ($r) { + if (dbm::is_result($r)) { return $r[0]['url']; } @@ -854,20 +848,22 @@ class Diaspora { } /** - * @brief Checks for relative /people/* links to match local contacts or - * prepends the remote host taken from the author link + * @brief Checks for relative /people/* links in an item body to match local + * contacts or prepends the remote host taken from the author link. * * @param string $body The item body to replace links from * @param string $author_link The author link for missing local contact fallback + * + * @return the replaced string */ public function replace_people_guid($body, $author_link) { $return = preg_replace_callback("&\[url=/people/([^\[\]]*)\](.*)\[\/url\]&Usi", - function ($match) use ($author_link){ + function ($match) use ($author_link) { // $match // 0 => '[url=/people/0123456789abcdef]Foo Bar[/url]' // 1 => '0123456789abcdef' // 2 => 'Foo Bar' - $handle = self::url_from_fcontact($match[1]); + $handle = self::url_from_fcontact_guid($match[1]); if ($handle) { $return = '@[url='.$handle.']'.$match[2].'[/url]'; @@ -878,7 +874,6 @@ class Diaspora { } return $return; - }, $body); return $return; @@ -1226,9 +1221,9 @@ class Diaspora { $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at; - $datarray["body"] = diaspora2bb($text); + $body = diaspora2bb($text); - $datarray["body"] = self::replace_people_gui($datarray); + $datarray["body"] = self::replace_people_guid($body, $person["url"]); self::fetch_guid($datarray); @@ -1624,8 +1619,6 @@ class Diaspora { $reply = 0; - $body = self::replace_people_guid(diaspora2bb($text), $person["url"]); - $message_uri = $author.":".$guid; $person = self::person_by_handle($author); @@ -1643,6 +1636,10 @@ class Diaspora { return false; } + $body = diaspora2bb($text); + + $body = self::replace_people_guid($body, $person["url"]); + q("INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`) VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')", intval($importer["uid"]), @@ -2092,7 +2089,9 @@ class Diaspora { if (self::is_reshare($r[0]["body"], true)) $r = array(); elseif (self::is_reshare($r[0]["body"], false)) { - $r[0]["body"] = self::replace_people_guid(diaspora2bb(bb2diaspora($r[0]["body"])), $r[0]["author-link"]); + $r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"])); + + $r[0]["body"] = self::replace_people_guid($r[0]["body"], $r[0]["author-link"]); // Add OEmbed and other information to the body $r[0]["body"] = add_page_info_to_body($r[0]["body"], false, true); @@ -2122,7 +2121,8 @@ class Diaspora { if ($r) { // If it is a reshared post from another network then reformat to avoid display problems with two share elements if (self::is_reshare($r[0]["body"], false)) { - $r[0]["body"] = self::replace_people_guid(diaspora2bb(bb2diaspora($r[0]["body"])), $r[0]["author-link"]); + $r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"])); + $r[0]["body"] = self::replace_people_guid($r[0]["body"], $r[0]["author-link"]); } return $r[0]; @@ -2381,7 +2381,7 @@ class Diaspora { $datarray["object"] = $xml; - $datarray["body"] = self::replace_people_guid($body, $datarray["author-link"]); + $datarray["body"] = self::replace_people_guid($body, $contact["url"]); if ($provider_display_name != "") $datarray["app"] = $provider_display_name; From 177f93f9a5ddae8cfb8124748a4e1a2392c4c526 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 20 Dec 2016 12:49:50 -0500 Subject: [PATCH 4/9] diaspora.php: Standards, standards everywhere --- include/diaspora.php | 105 +++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 44 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 2166f8bf72..fcc9309395 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -669,27 +669,30 @@ class Diaspora { * @return string the handle */ public static function handle_from_contact($contact_id, $gcontact_id = 0) { - $handle = False; + $handle = false; logger("contact id is ".$contact_id." - gcontact id is ".$gcontact_id, LOGGER_DEBUG); if ($gcontact_id != 0) { $r = q("SELECT `addr` FROM `gcontact` WHERE `id` = %d AND `addr` != ''", intval($gcontact_id)); - if ($r) + + if (dbm::is_result($r)) { return strtolower($r[0]["addr"]); + } } $r = q("SELECT `network`, `addr`, `self`, `url`, `nick` FROM `contact` WHERE `id` = %d", intval($contact_id)); - if ($r) { + + if (dbm::is_result($r)) { $contact = $r[0]; logger("contact 'self' = ".$contact['self']." 'url' = ".$contact['url'], LOGGER_DEBUG); - if($contact['addr'] != "") + if ($contact['addr'] != "") { $handle = $contact['addr']; - else { + } else { $baseurl_start = strpos($contact['url'],'://') + 3; $baseurl_length = strpos($contact['url'],'/profile') - $baseurl_start; // allows installations in a subdirectory--not sure how Diaspora will handle $baseurl = substr($contact['url'], $baseurl_start, $baseurl_length); @@ -1168,22 +1171,26 @@ class Diaspora { $text = unxmlify($data->text); $author = notags(unxmlify($data->author)); - if (isset($data->created_at)) + if (isset($data->created_at)) { $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at))); - else + } else { $created_at = datetime_convert(); + } $contact = self::allowed_contact_by_handle($importer, $sender, true); - if (!$contact) + if (!$contact) { return false; + } $message_id = self::message_exists($importer["uid"], $guid); - if ($message_id) + if ($message_id) { return $message_id; + } $parent_item = self::parent_item($importer["uid"], $parent_guid, $author, $contact); - if (!$parent_item) + if (!$parent_item) { return false; + } $person = self::person_by_handle($author); if (!is_array($person)) { @@ -1229,8 +1236,9 @@ class Diaspora { $message_id = item_store($datarray); - if ($message_id) + if ($message_id) { logger("Stored comment ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG); + } // If we are the origin of the parent we store the original data and notify our followers if($message_id AND $parent_item["origin"]) { @@ -1266,8 +1274,6 @@ class Diaspora { $subject = notags(unxmlify($data->subject)); $author = notags(unxmlify($data->author)); - $reply = 0; - $msg_guid = notags(unxmlify($mesg->guid)); $msg_parent_guid = notags(unxmlify($mesg->parent_guid)); $msg_parent_author_signature = notags(unxmlify($mesg->parent_author_signature)); @@ -1277,16 +1283,17 @@ class Diaspora { // "diaspora_handle" is the element name from the old version // "author" is the element name from the new version - if ($mesg->author) + if ($mesg->author) { $msg_author = notags(unxmlify($mesg->author)); - elseif ($mesg->diaspora_handle) + } elseif ($mesg->diaspora_handle) { $msg_author = notags(unxmlify($mesg->diaspora_handle)); - else + } else { return false; + } $msg_conversation_guid = notags(unxmlify($mesg->conversation_guid)); - if($msg_conversation_guid != $guid) { + if ($msg_conversation_guid != $guid) { logger("message conversation guid does not belong to the current conversation."); return false; } @@ -1298,15 +1305,15 @@ class Diaspora { $author_signature = base64_decode($msg_author_signature); - if(strcasecmp($msg_author,$msg["author"]) == 0) { + if (strcasecmp($msg_author,$msg["author"]) == 0) { $person = $contact; $key = $msg["key"]; } else { $person = self::person_by_handle($msg_author); - if (is_array($person) && x($person, "pubkey")) + if (is_array($person) && x($person, "pubkey")) { $key = $person["pubkey"]; - else { + } else { logger("unable to find author details"); return false; } @@ -1317,7 +1324,7 @@ class Diaspora { return false; } - if($msg_parent_author_signature) { + if ($msg_parent_author_signature) { $owner_signed_data = $msg_guid.";".$msg_parent_guid.";".$msg_text.";".unxmlify($mesg->created_at).";".$msg_author.";".$msg_conversation_guid; $parent_author_signature = base64_decode($msg_parent_author_signature); @@ -1333,7 +1340,7 @@ class Diaspora { $r = q("SELECT `id` FROM `mail` WHERE `uri` = '%s' LIMIT 1", dbesc($message_uri) ); - if($r) { + if (dbm::is_result($r)) { logger("duplicate message already delivered.", LOGGER_DEBUG); return false; } @@ -1601,8 +1608,9 @@ class Diaspora { $conversation_guid = notags(unxmlify($data->conversation_guid)); $contact = self::allowed_contact_by_handle($importer, $author, true); - if (!$contact) + if (!$contact) { return false; + } $conversation = null; @@ -1610,15 +1618,13 @@ class Diaspora { intval($importer["uid"]), dbesc($conversation_guid) ); - if($c) + if ($c) { $conversation = $c[0]; - else { + } else { logger("conversation not available."); return false; } - $reply = 0; - $message_uri = $author.":".$guid; $person = self::person_by_handle($author); @@ -1631,7 +1637,7 @@ class Diaspora { dbesc($message_uri), intval($importer["uid"]) ); - if($r) { + if (dbm::is_result($r)) { logger("duplicate message already delivered.", LOGGER_DEBUG); return false; } @@ -2080,15 +2086,15 @@ class Diaspora { FROM `item` WHERE `guid` = '%s' AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1", dbesc($guid)); - if($r) { + if (dbm::is_result($r)) { logger("reshared message ".$guid." already exists on system."); // Maybe it is already a reshared item? // Then refetch the content, if it is a reshare from a reshare. // If it is a reshared post from another network then reformat to avoid display problems with two share elements - if (self::is_reshare($r[0]["body"], true)) + if (self::is_reshare($r[0]["body"], true)) { $r = array(); - elseif (self::is_reshare($r[0]["body"], false)) { + } elseif (self::is_reshare($r[0]["body"], false)) { $r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"])); $r[0]["body"] = self::replace_people_guid($r[0]["body"], $r[0]["author-link"]); @@ -2097,11 +2103,12 @@ class Diaspora { $r[0]["body"] = add_page_info_to_body($r[0]["body"], false, true); return $r[0]; - } else + } else { return $r[0]; + } } - if (!$r) { + if (!dbm::is_result($r)) { $server = "https://".substr($orig_author, strpos($orig_author, "@") + 1); logger("1st try: reshared message ".$guid." will be fetched via SSL from the server ".$server); $item_id = self::store_by_guid($guid, $server); @@ -2118,7 +2125,7 @@ class Diaspora { FROM `item` WHERE `id` = %d AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1", intval($item_id)); - if ($r) { + if (dbm::is_result($r)) { // If it is a reshared post from another network then reformat to avoid display problems with two share elements if (self::is_reshare($r[0]["body"], false)) { $r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"])); @@ -2330,17 +2337,21 @@ class Diaspora { // die("poll!\n"); //} $contact = self::allowed_contact_by_handle($importer, $author, false); - if (!$contact) + if (!$contact) { return false; + } $message_id = self::message_exists($importer["uid"], $guid); - if ($message_id) + if ($message_id) { return $message_id; + } $address = array(); - if ($data->location) - foreach ($data->location->children() AS $fieldname => $data) + if ($data->location) { + foreach ($data->location->children() AS $fieldname => $data) { $address[$fieldname] = notags(unxmlify($data)); + } + } $body = diaspora2bb($raw_message); @@ -2348,17 +2359,19 @@ class Diaspora { // Attach embedded pictures to the body if ($data->photo) { - foreach ($data->photo AS $photo) + foreach ($data->photo AS $photo) { $body = "[img]".unxmlify($photo->remote_photo_path). unxmlify($photo->remote_photo_name)."[/img]\n".$body; + } $datarray["object-type"] = ACTIVITY_OBJ_PHOTO; } else { $datarray["object-type"] = ACTIVITY_OBJ_NOTE; // Add OEmbed and other information to the body - if (!self::is_redmatrix($contact["url"])) + if (!self::is_redmatrix($contact["url"])) { $body = add_page_info_to_body($body, false, true); + } } $datarray["uid"] = $importer["uid"]; @@ -2383,24 +2396,28 @@ class Diaspora { $datarray["body"] = self::replace_people_guid($body, $contact["url"]); - if ($provider_display_name != "") + if ($provider_display_name != "") { $datarray["app"] = $provider_display_name; + } $datarray["plink"] = self::plink($author, $guid); $datarray["private"] = (($public == "false") ? 1 : 0); $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at; - if (isset($address["address"])) + if (isset($address["address"])) { $datarray["location"] = $address["address"]; + } - if (isset($address["lat"]) AND isset($address["lng"])) + if (isset($address["lat"]) AND isset($address["lng"])) { $datarray["coord"] = $address["lat"]." ".$address["lng"]; + } self::fetch_guid($datarray); $message_id = item_store($datarray); - if ($message_id) + if ($message_id) { logger("Stored item ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG); + } return $message_id; } From a99532707bee766205347aac77bed992b55a0cb9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 20 Dec 2016 12:52:24 -0500 Subject: [PATCH 5/9] Resolve conflict --- include/follow.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/include/follow.php b/include/follow.php index 779ecf082d..f74655a9d2 100644 --- a/include/follow.php +++ b/include/follow.php @@ -289,14 +289,9 @@ function new_contact($uid,$url,$interactive = false) { $slap = ostatus::salmon($item, $r[0]); slapper($r[0], $contact['notify'], $slap); } -<<<<<<< HEAD - if($contact['network'] == NETWORK_DIASPORA) { - require_once('include/diaspora.php'); - $ret = Diaspora::send_share($a->user,$contact); -======= + if ($contact['network'] == NETWORK_DIASPORA) { - $ret = diaspora::send_share($a->user,$contact); ->>>>>>> friendica/develop + $ret = Diaspora::send_share($a->user,$contact); logger('share returns: '.$ret); } } From b631442760b134b14071eaeab9a2a8756feeca98 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 20 Dec 2016 14:33:33 -0500 Subject: [PATCH 6/9] Misc changes to url_from_contact_guid - Rename url_from_fcontact_guid to url_from_fcontact_guid - Use network name constant - Standards --- include/diaspora.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 4af1b6daa1..db49441a03 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -711,10 +711,10 @@ class Diaspora { * * @return string the contact url or null */ - public static function url_from_fcontact_guid($fcontact_guid) { + public static function url_from_contact_guid($fcontact_guid) { logger("fcontact guid is ".$fcontact_guid, LOGGER_DEBUG); - $r = q("SELECT `url` FROM `fcontact` WHERE `guid` = '%s' AND `network` = 'dspr' AND `url` != ''", + $r = q("SELECT `url` FROM `fcontact` WHERE `guid` = '%s' AND `network` = '" . NETWORK_DIASPORA . "' AND `url` != ''", $fcontact_guid); if (dbm::is_result($r)) { @@ -866,11 +866,11 @@ class Diaspora { // 0 => '[url=/people/0123456789abcdef]Foo Bar[/url]' // 1 => '0123456789abcdef' // 2 => 'Foo Bar' - $handle = self::url_from_fcontact_guid($match[1]); + $handle = self::url_from_contact_guid($match[1]); if ($handle) { $return = '@[url='.$handle.']'.$match[2].'[/url]'; - }else { + } else { // No local match, restoring absolute remote URL from author scheme and host $author_url = parse_url($author_link); $return = '[url='.$author_url['scheme'].'://'.$author_url['host'].'/people/'.$match[1].']'.$match[2].'[/url]'; From 769b8496655fb8c9e64694cd4bb65a364460b992 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 20 Dec 2016 20:52:42 -0500 Subject: [PATCH 7/9] url_from_contact_guid: move network constant to arg list --- include/diaspora.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index db49441a03..2547de5149 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -714,8 +714,10 @@ class Diaspora { public static function url_from_contact_guid($fcontact_guid) { logger("fcontact guid is ".$fcontact_guid, LOGGER_DEBUG); - $r = q("SELECT `url` FROM `fcontact` WHERE `guid` = '%s' AND `network` = '" . NETWORK_DIASPORA . "' AND `url` != ''", - $fcontact_guid); + $r = q("SELECT `url` FROM `fcontact` WHERE `url` != '' AND `network` = '%s' AND `guid` = '%s'", + dbesc(NETWORK_DIASPORA), + dbesc($fcontact_guid) + ); if (dbm::is_result($r)) { return $r[0]['url']; From d242e72c656e6185e634ba6978783c2596f0918a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 22 Dec 2016 09:09:27 +0100 Subject: [PATCH 8/9] applied coding convention rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- include/like.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/like.php b/include/like.php index 94ff33a699..4df15b4b63 100644 --- a/include/like.php +++ b/include/like.php @@ -48,10 +48,8 @@ function do_like($item_id, $verb) { break; } - logger('like: verb ' . $verb . ' item ' . $item_id); - $r = q("SELECT * FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1", dbesc($item_id), dbesc($item_id) @@ -109,8 +107,7 @@ function do_like($item_id, $verb) { if ((local_user()) && (local_user() == $owner_uid)) { $contact = $owner; - } - else { + } else { $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($_SESSION['visitor_id']), intval($owner_uid) From 41da37ae670e1f3238d58916a4837b1907a116df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20H=C3=A4der?= Date: Thu, 22 Dec 2016 11:21:50 +0100 Subject: [PATCH 9/9] Beatification/coding convention: - added a lot spaces to make it look nicer - added curly braces (coding convention) - added needed spaces (coding convention)get_id - removed obsolete $a = get_app() call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- object/Item.php | 383 ++++++++++++++++++++++++------------------------ 1 file changed, 193 insertions(+), 190 deletions(-) diff --git a/object/Item.php b/object/Item.php index d14b5418cc..e60344f7d3 100644 --- a/object/Item.php +++ b/object/Item.php @@ -52,21 +52,22 @@ class Item extends BaseObject { $ssl_state = ((local_user()) ? true : false); $this->redirect_url = 'redir/' . $this->get_data_value('cid') ; - if(get_config('system','thread_allow') && $a->theme_thread_allow && !$this->is_toplevel()) + if (get_config('system','thread_allow') && $a->theme_thread_allow && !$this->is_toplevel()) { $this->threaded = true; + } // Prepare the children - if(count($data['children'])) { - foreach($data['children'] as $item) { + if (count($data['children'])) { + foreach ($data['children'] as $item) { /* * Only add will be displayed */ - if($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { - continue; - } - if(! visible_activity($item)) { + if ($item['network'] === NETWORK_MAIL && local_user() != $item['uid']) { + continue; + } elseif (! visible_activity($item)) { continue; } + $item['pagedrop'] = $data['pagedrop']; $child = new Item($item); $this->add_child($child); @@ -91,11 +92,11 @@ class Item extends BaseObject { $item = $this->get_data(); $edited = false; if (strcmp($item['created'], $item['edited'])<>0) { - $edited = array( - 'label' => t('This entry was edited'), - 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'), - 'relative' => relative_date($item['edited']) - ); + $edited = array( + 'label' => t('This entry was edited'), + 'date' => datetime_convert('UTC', date_default_timezone_get(), $item['edited'], 'r'), + 'relative' => relative_date($item['edited']) + ); } $commentww = ''; $sparkle = ''; @@ -111,7 +112,6 @@ class Item extends BaseObject { $conv = $this->get_conversation(); - $lock = ((($item['private'] == 1) || (($item['uid'] == local_user()) && (strlen($item['allow_cid']) || strlen($item['allow_gid']) || strlen($item['deny_cid']) || strlen($item['deny_gid'])))) ? t('Private Message') @@ -134,22 +134,24 @@ class Item extends BaseObject { $drop = array( 'dropping' => $dropping, 'pagedrop' => ((feature_enabled($conv->get_profile_owner(),'multi_delete')) ? $item['pagedrop'] : ''), - 'select' => t('Select'), - 'delete' => t('Delete'), + 'select' => t('Select'), + 'delete' => t('Delete'), ); $filer = (($conv->get_profile_owner() == local_user()) ? t("save to folder") : false); $diff_author = ((link_compare($item['url'],$item['author-link'])) ? false : true); $profile_name = htmlentities(((strlen($item['author-name'])) && $diff_author) ? $item['author-name'] : $item['name']); - if($item['author-link'] && (! $item['author-name'])) + if ($item['author-link'] && (! $item['author-name'])) { $profile_name = $item['author-link']; + } $sp = false; $profile_link = best_link_url($item,$sp); if ($profile_link === 'mailbox') { $profile_link = ''; } + if ($sp) { $sparkle = ' sparkle'; } else { @@ -198,13 +200,14 @@ class Item extends BaseObject { // process action responses - e.g. like/dislike/attend/agree/whatever $response_verbs = array('like'); - if(feature_enabled($conv->get_profile_owner(),'dislike')) + if (feature_enabled($conv->get_profile_owner(),'dislike')) { $response_verbs[] = 'dislike'; - if($item['object-type'] === ACTIVITY_OBJ_EVENT) { + } + if ($item['object-type'] === ACTIVITY_OBJ_EVENT) { $response_verbs[] = 'attendyes'; $response_verbs[] = 'attendno'; $response_verbs[] = 'attendmaybe'; - if($conv->is_writable()) { + if ($conv->is_writable()) { $isevent = true; $attend = array( t('I will attend'), t('I will not attend'), t('I might attend')); } @@ -213,8 +216,7 @@ class Item extends BaseObject { $responses = get_responses($conv_responses,$response_verbs,$this,$item); foreach ($response_verbs as $value=>$verbs) { - $responses[$verbs][output] = ((x($conv_responses[$verbs],$item['uri'])) ? format_like($conv_responses[$verbs][$item['uri']],$conv_responses[$verbs][$item['uri'] . '-l'],$verbs,$item['uri']) : ''); - + $responses[$verbs]['output'] = ((x($conv_responses[$verbs],$item['uri'])) ? format_like($conv_responses[$verbs][$item['uri']],$conv_responses[$verbs][$item['uri'] . '-l'],$verbs,$item['uri']) : ''); } /* @@ -224,20 +226,21 @@ class Item extends BaseObject { */ $this->check_wall_to_wall(); - if($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url())) + if ($this->is_wall_to_wall() && ($this->get_owner_url() == $this->get_redirect_url())) { $osparkle = ' sparkle'; + } - if($this->is_toplevel()) { - if($conv->get_profile_owner() == local_user()) { + if ($this->is_toplevel()) { + if ($conv->get_profile_owner() == local_user()) { $isstarred = (($item['starred']) ? "starred" : "unstarred"); $star = array( - 'do' => t("add star"), - 'undo' => t("remove star"), - 'toggle' => t("toggle star status"), - 'classdo' => (($item['starred']) ? "hidden" : ""), + 'do' => t("add star"), + 'undo' => t("remove star"), + 'toggle' => t("toggle star status"), + 'classdo' => (($item['starred']) ? "hidden" : ""), 'classundo' => (($item['starred']) ? "" : "hidden"), - 'starred' => t('starred'), + 'starred' => t('starred'), ); $r = q("SELECT `ignored` FROM `thread` WHERE `uid` = %d AND `iid` = %d LIMIT 1", intval($item['uid']), @@ -245,19 +248,19 @@ class Item extends BaseObject { ); if (dbm::is_result($r)) { $ignore = array( - 'do' => t("ignore thread"), - 'undo' => t("unignore thread"), - 'toggle' => t("toggle ignore status"), - 'classdo' => (($r[0]['ignored']) ? "hidden" : ""), + 'do' => t("ignore thread"), + 'undo' => t("unignore thread"), + 'toggle' => t("toggle ignore status"), + 'classdo' => (($r[0]['ignored']) ? "hidden" : ""), 'classundo' => (($r[0]['ignored']) ? "" : "hidden"), - 'ignored' => t('ignored'), + 'ignored' => t('ignored'), ); } $tagger = ''; if(feature_enabled($conv->get_profile_owner(),'commtag')) { $tagger = array( - 'add' => t("add tag"), + 'add' => t("add tag"), 'class' => "", ); } @@ -266,17 +269,19 @@ class Item extends BaseObject { $indent = 'comment'; } - if($conv->is_writable()) { + if ($conv->is_writable()) { $buttons = array( 'like' => array( t("I like this \x28toggle\x29"), t("like")), 'dislike' => ((feature_enabled($conv->get_profile_owner(),'dislike')) ? array( t("I don't like this \x28toggle\x29"), t("dislike")) : ''), ); - if ($shareable) $buttons['share'] = array( t('Share this'), t('share')); + if ($shareable) { + $buttons['share'] = array( t('Share this'), t('share')); + } } $comment = $this->get_comment_box($indent); - if(strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0){ + if (strcmp(datetime_convert('UTC','UTC',$item['created']),datetime_convert('UTC','UTC','now - 12 hours')) > 0){ $shiny = 'shiny'; } @@ -298,8 +303,9 @@ class Item extends BaseObject { foreach ($languages as $language) { $langdata = explode(";", $language); - if ($langstr != "") + if ($langstr != "") { $langstr .= ", "; + } //$langstr .= $langdata[0]." (".round($langdata[1]*100, 1)."%)"; $langstr .= round($langdata[1]*100, 1)."% ".$langdata[0]; @@ -311,20 +317,19 @@ class Item extends BaseObject { list($categories, $folders) = get_cats_and_terms($item); - if($a->theme['template_engine'] === 'internal') { - $body_e = template_escape($body); - $text_e = strip_tags(template_escape($body)); - $name_e = template_escape($profile_name); - $title_e = template_escape($item['title']); - $location_e = template_escape($location); + if ($a->theme['template_engine'] === 'internal') { + $body_e = template_escape($body); + $text_e = strip_tags(template_escape($body)); + $name_e = template_escape($profile_name); + $title_e = template_escape($item['title']); + $location_e = template_escape($location); $owner_name_e = template_escape($this->get_owner_name()); - } - else { - $body_e = $body; - $text_e = strip_tags($body); - $name_e = $profile_name; - $title_e = $item['title']; - $location_e = $location; + } else { + $body_e = $body; + $text_e = strip_tags($body); + $name_e = $profile_name; + $title_e = $item['title']; + $location_e = $location; $owner_name_e = $this->get_owner_name(); } @@ -334,89 +339,93 @@ class Item extends BaseObject { $tagger = ''; } - if (($item["item_network"] == NETWORK_FEED) AND isset($buttons["like"])) + if (($item["item_network"] == NETWORK_FEED) AND isset($buttons["like"])) { unset($buttons["like"]); + } - if (($item["item_network"] == NETWORK_MAIL) AND isset($buttons["like"])) + if (($item["item_network"] == NETWORK_MAIL) AND isset($buttons["like"])) { unset($buttons["like"]); + } // Diaspora isn't able to do likes on comments - but red does if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND - !diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) + !diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) { unset($buttons["like"]); + } // Diaspora doesn't has multithreaded comments - if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment')) + if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment')) { unset($comment); + } // Facebook can like comments - but it isn't programmed in the connector yet. - if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"])) + if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"])) { unset($buttons["like"]); + } $tmp_item = array( - 'template' => $this->get_template(), - - 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), - 'tags' => $item['tags'], - 'hashtags' => $item['hashtags'], - 'mentions' => $item['mentions'], - 'txt_cats' => t('Categories:'), - 'txt_folders' => t('Filed under:'), - 'has_cats' => ((count($categories)) ? 'true' : ''), - 'has_folders' => ((count($folders)) ? 'true' : ''), - 'categories' => $categories, - 'folders' => $folders, - 'body' => $body_e, - 'text' => $text_e, - 'id' => $this->get_id(), - 'guid' => urlencode($item['guid']), - 'isevent' => $isevent, - 'attend' => $attend, - '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'), htmlentities($this->get_owner_name()), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), - 'to' => t('to'), - 'via' => t('via'), - 'wall' => t('Wall-to-Wall'), - 'vwall' => t('via Wall-To-Wall:'), - 'profile_url' => $profile_link, + 'template' => $this->get_template(), + 'type' => implode("",array_slice(explode("/",$item['verb']),-1)), + 'tags' => $item['tags'], + 'hashtags' => $item['hashtags'], + 'mentions' => $item['mentions'], + 'txt_cats' => t('Categories:'), + 'txt_folders' => t('Filed under:'), + 'has_cats' => ((count($categories)) ? 'true' : ''), + 'has_folders' => ((count($folders)) ? 'true' : ''), + 'categories' => $categories, + 'folders' => $folders, + 'body' => $body_e, + 'text' => $text_e, + 'id' => $this->get_id(), + 'guid' => urlencode($item['guid']), + 'isevent' => $isevent, + 'attend' => $attend, + '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'), htmlentities($this->get_owner_name()), ((strlen($item['owner-link'])) ? $item['owner-link'] : $item['url'])), + 'to' => t('to'), + 'via' => t('via'), + 'wall' => t('Wall-to-Wall'), + 'vwall' => t('via Wall-To-Wall:'), + 'profile_url' => $profile_link, 'item_photo_menu' => item_photo_menu($item), - 'name' => $name_e, - 'thumb' => $a->remove_baseurl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)), - 'osparkle' => $osparkle, - 'sparkle' => $sparkle, - 'title' => $title_e, - 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), - 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), - 'app' => $item['app'], - 'created' => relative_date($item['created']), - 'lock' => $lock, - 'location' => $location_e, - 'indent' => $indent, - 'shiny' => $shiny, - 'owner_url' => $this->get_owner_url(), - 'owner_photo' => $a->remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)), - 'owner_name' => htmlentities($owner_name_e), - 'plink' => get_plink($item), - 'edpost' => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''), - 'isstarred' => $isstarred, - 'star' => ((feature_enabled($conv->get_profile_owner(),'star_posts')) ? $star : ''), - 'ignore' => ((feature_enabled($conv->get_profile_owner(),'ignore_posts')) ? $ignore : ''), - 'tagger' => $tagger, - 'filer' => ((feature_enabled($conv->get_profile_owner(),'filing')) ? $filer : ''), - 'drop' => $drop, - 'vote' => $buttons, - 'like' => $responses['like']['output'], - 'dislike' => $responses['dislike']['output'], - 'responses' => $responses, - 'switchcomment' => t('Comment'), - 'comment' => $comment, - 'previewing' => ($conv->is_preview() ? ' preview ' : ''), - 'wait' => t('Please wait'), - 'thread_level' => $thread_level, - 'postopts' => $langstr, - 'edited' => $edited, - 'network' => $item["item_network"], - 'network_name' => network_to_name($item['item_network'], $profile_link), + 'name' => $name_e, + 'thumb' => $a->remove_baseurl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)), + 'osparkle' => $osparkle, + 'sparkle' => $sparkle, + 'title' => $title_e, + 'localtime' => datetime_convert('UTC', date_default_timezone_get(), $item['created'], 'r'), + 'ago' => (($item['app']) ? sprintf( t('%s from %s'),relative_date($item['created']),$item['app']) : relative_date($item['created'])), + 'app' => $item['app'], + 'created' => relative_date($item['created']), + 'lock' => $lock, + 'location' => $location_e, + 'indent' => $indent, + 'shiny' => $shiny, + 'owner_url' => $this->get_owner_url(), + 'owner_photo' => $a->remove_baseurl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)), + 'owner_name' => htmlentities($owner_name_e), + 'plink' => get_plink($item), + 'edpost' => ((feature_enabled($conv->get_profile_owner(),'edit_posts')) ? $edpost : ''), + 'isstarred' => $isstarred, + 'star' => ((feature_enabled($conv->get_profile_owner(),'star_posts')) ? $star : ''), + 'ignore' => ((feature_enabled($conv->get_profile_owner(),'ignore_posts')) ? $ignore : ''), + 'tagger' => $tagger, + 'filer' => ((feature_enabled($conv->get_profile_owner(),'filing')) ? $filer : ''), + 'drop' => $drop, + 'vote' => $buttons, + 'like' => $responses['like']['output'], + 'dislike' => $responses['dislike']['output'], + 'responses' => $responses, + 'switchcomment' => t('Comment'), + 'comment' => $comment, + 'previewing' => ($conv->is_preview() ? ' preview ' : ''), + 'wait' => t('Please wait'), + 'thread_level' => $thread_level, + 'postopts' => $langstr, + 'edited' => $edited, + 'network' => $item["item_network"], + 'network_name' => network_to_name($item['item_network'], $profile_link), ); $arr = array('item' => $item, 'output' => $tmp_item); @@ -427,39 +436,37 @@ class Item extends BaseObject { $result['children'] = array(); $children = $this->get_children(); $nb_children = count($children); - if($nb_children > 0) { - foreach($children as $child) { + if ($nb_children > 0) { + foreach ($children as $child) { $result['children'][] = $child->get_template_data($conv_responses, $thread_level + 1); } // Collapse - if(($nb_children > 2) || ($thread_level > 1)) { + if (($nb_children > 2) || ($thread_level > 1)) { $result['children'][0]['comment_firstcollapsed'] = true; $result['children'][0]['num_comments'] = sprintf( tt('%d comment','%d comments',$total_children),$total_children ); $result['children'][0]['hidden_comments_num'] = $total_children; $result['children'][0]['hidden_comments_text'] = tt('comment', 'comments', $total_children); $result['children'][0]['hide_text'] = t('show more'); - if($thread_level > 1) { + if ($thread_level > 1) { $result['children'][$nb_children - 1]['comment_lastcollapsed'] = true; - } - else { + } else { $result['children'][$nb_children - 3]['comment_lastcollapsed'] = true; } } } if ($this->is_toplevel()) { - $result['total_comments_num'] = "$total_children"; - $result['total_comments_text'] = tt('comment', 'comments', $total_children); + $result['total_comments_num'] = "$total_children"; + $result['total_comments_text'] = tt('comment', 'comments', $total_children); } $result['private'] = $item['private']; $result['toplevel'] = ($this->is_toplevel() ? 'toplevel_item' : ''); - if($this->is_threaded()) { + if ($this->is_threaded()) { $result['flatten'] = false; $result['threaded'] = true; - } - else { + } else { $result['flatten'] = true; $result['threaded'] = false; } @@ -478,23 +485,21 @@ class Item extends BaseObject { /** * Add a child item */ - public function add_child($item) { + public function add_child(Item $item) { $item_id = $item->get_id(); - if(!$item_id) { + if (!$item_id) { logger('[ERROR] Item::add_child : Item has no ID!!', LOGGER_DEBUG); return false; - } - if($this->get_child($item->get_id())) { + } elseif ($this->get_child($item->get_id())) { logger('[WARN] Item::add_child : Item already exists ('. $item->get_id() .').', LOGGER_DEBUG); return false; } /* * Only add what will be displayed */ - if($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) { + if ($item->get_data_value('network') === NETWORK_MAIL && local_user() != $item->get_data_value('uid')) { return false; - } - if(activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) { + } elseif (activity_match($item->get_data_value('verb'),ACTIVITY_LIKE) || activity_match($item->get_data_value('verb'),ACTIVITY_DISLIKE)) { return false; } @@ -507,9 +512,10 @@ class Item extends BaseObject { * Get a child by its ID */ public function get_child($id) { - foreach($this->get_children() as $child) { - if($child->get_id() == $id) + foreach ($this->get_children() as $child) { + if ($child->get_id() == $id) { return $child; + } } return null; } @@ -546,8 +552,8 @@ class Item extends BaseObject { */ public function remove_child($item) { $id = $item->get_id(); - foreach($this->get_children() as $key => $child) { - if($child->get_id() == $id) { + foreach ($this->get_children() as $key => $child) { + if ($child->get_id() == $id) { $child->remove_parent(); unset($this->children[$key]); // Reindex the array, in order to make sure there won't be any trouble on loops using count() @@ -575,8 +581,9 @@ class Item extends BaseObject { $this->conversation = $conv; // Set it on our children too - foreach($this->get_children() as $child) + foreach ($this->get_children() as $child) { $child->set_conversation($conv); + } } /** @@ -603,7 +610,7 @@ class Item extends BaseObject { * _ false on failure */ public function get_data_value($name) { - if(!isset($this->data[$name])) { + if (!isset($this->data[$name])) { // logger('[ERROR] Item::get_data_value : Item has no value name "'. $name .'".', LOGGER_DEBUG); return false; } @@ -615,9 +622,7 @@ class Item extends BaseObject { * Set template */ private function set_template($name) { - $a = get_app(); - - if(!x($this->available_templates, $name)) { + if (!x($this->available_templates, $name)) { logger('[ERROR] Item::set_template : Template not available ("'. $name .'").', LOGGER_DEBUG); return false; } @@ -645,13 +650,14 @@ class Item extends BaseObject { private function is_writable() { $conv = $this->get_conversation(); - if($conv) { + if ($conv) { // This will allow us to comment on wall-to-wall items owned by our friends // and community forums even if somebody else wrote the post. // bug #517 - this fixes for conversation owner - if($conv->get_mode() == 'profile' && $conv->get_profile_owner() == local_user()) - return true; + if ($conv->get_mode() == 'profile' && $conv->get_profile_owner() == local_user()) { + return true; + } // this fixes for visitors return ($this->writable || ($this->is_visiting() && $conv->get_mode() == 'profile')); @@ -665,8 +671,8 @@ class Item extends BaseObject { private function count_descendants() { $children = $this->get_children(); $total = count($children); - if($total > 0) { - foreach($children as $child) { + if ($total > 0) { + foreach ($children as $child) { $total += $child->count_descendants(); } } @@ -689,7 +695,7 @@ class Item extends BaseObject { */ private function get_comment_box($indent) { $a = $this->get_app(); - if(!$this->is_toplevel() && !(get_config('system','thread_allow') && $a->theme_thread_allow)) { + if (!$this->is_toplevel() && !(get_config('system','thread_allow') && $a->theme_thread_allow)) { return ''; } @@ -697,48 +703,48 @@ class Item extends BaseObject { $conv = $this->get_conversation(); $template = get_markup_template($this->get_comment_box_template()); $ww = ''; - if( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() ) + if ( ($conv->get_mode() === 'network') && $this->is_wall_to_wall() ) $ww = 'ww'; - if($conv->is_writable() && $this->is_writable()) { + if ($conv->is_writable() && $this->is_writable()) { $qc = $qcomment = null; /* * Hmmm, code depending on the presence of a particular plugin? * This should be better if done by a hook */ - if(in_array('qcomment',$a->plugins)) { + if (in_array('qcomment',$a->plugins)) { $qc = ((local_user()) ? get_pconfig(local_user(),'qcomment','words') : null); $qcomment = (($qc) ? explode("\n",$qc) : null); } $comment_box = replace_macros($template,array( '$return_path' => $a->query_string, - '$threaded' => $this->is_threaded(), -// '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''), - '$jsreload' => '', - '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'), - '$id' => $this->get_id(), - '$parent' => $this->get_id(), - '$qcomment' => $qcomment, + '$threaded' => $this->is_threaded(), +// '$jsreload' => (($conv->get_mode() === 'display') ? $_SESSION['return_url'] : ''), + '$jsreload' => '', + '$type' => (($conv->get_mode() === 'profile') ? 'wall-comment' : 'net-comment'), + '$id' => $this->get_id(), + '$parent' => $this->get_id(), + '$qcomment' => $qcomment, '$profile_uid' => $conv->get_profile_owner(), - '$mylink' => $a->remove_baseurl($a->contact['url']), - '$mytitle' => t('This is you'), - '$myphoto' => $a->remove_baseurl($a->contact['thumb']), - '$comment' => t('Comment'), - '$submit' => t('Submit'), - '$edbold' => t('Bold'), - '$editalic' => t('Italic'), - '$eduline' => t('Underline'), - '$edquote' => t('Quote'), - '$edcode' => t('Code'), - '$edimg' => t('Image'), - '$edurl' => t('Link'), - '$edvideo' => t('Video'), - '$preview' => ((feature_enabled($conv->get_profile_owner(),'preview')) ? t('Preview') : ''), - '$indent' => $indent, - '$sourceapp' => t($a->sourcename), - '$ww' => (($conv->get_mode() === 'network') ? $ww : ''), - '$rand_num' => random_digits(12) + '$mylink' => $a->remove_baseurl($a->contact['url']), + '$mytitle' => t('This is you'), + '$myphoto' => $a->remove_baseurl($a->contact['thumb']), + '$comment' => t('Comment'), + '$submit' => t('Submit'), + '$edbold' => t('Bold'), + '$editalic' => t('Italic'), + '$eduline' => t('Underline'), + '$edquote' => t('Quote'), + '$edcode' => t('Code'), + '$edimg' => t('Image'), + '$edurl' => t('Link'), + '$edvideo' => t('Video'), + '$preview' => ((feature_enabled($conv->get_profile_owner(),'preview')) ? t('Preview') : ''), + '$indent' => $indent, + '$sourceapp' => t($a->sourcename), + '$ww' => (($conv->get_mode() === 'network') ? $ww : ''), + '$rand_num' => random_digits(12) )); } @@ -768,14 +774,13 @@ class Item extends BaseObject { $this->owner_photo = $a->page_contact['thumb']; $this->owner_name = $a->page_contact['name']; $this->wall_to_wall = true; - } - else if($this->get_data_value('owner-link')) { + } elseif($this->get_data_value('owner-link')) { $owner_linkmatch = (($this->get_data_value('owner-link')) && link_compare($this->get_data_value('owner-link'),$this->get_data_value('author-link'))); $alias_linkmatch = (($this->get_data_value('alias')) && link_compare($this->get_data_value('alias'),$this->get_data_value('author-link'))); $owner_namematch = (($this->get_data_value('owner-name')) && $this->get_data_value('owner-name') == $this->get_data_value('author-name')); - if((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) { + if ((! $owner_linkmatch) && (! $alias_linkmatch) && (! $owner_namematch)) { // The author url doesn't match the owner (typically the contact) // and also doesn't match the contact alias. @@ -791,18 +796,18 @@ class Item extends BaseObject { $this->owner_name = $this->get_data_value('owner-name'); $this->wall_to_wall = true; // If it is our contact, use a friendly redirect link - if((link_compare($this->get_data_value('owner-link'),$this->get_data_value('url'))) + if ((link_compare($this->get_data_value('owner-link'),$this->get_data_value('url'))) && ($this->get_data_value('network') === NETWORK_DFRN)) { $this->owner_url = $this->get_redirect_url(); - } - else + } else { $this->owner_url = zrl($this->get_data_value('owner-link')); + } } } } } - if(!$this->wall_to_wall) { + if (!$this->wall_to_wall) { $this->set_template('wall'); $this->owner_url = ''; $this->owner_photo = ''; @@ -830,8 +835,6 @@ class Item extends BaseObject { return $this->visiting; } - - - } +/// @TODO These are discouraged and should be removed: ?>