+function twitter_prepare_body(&$a,&$b) {
+ if ($b["item"]["network"] != NETWORK_TWITTER)
+ return;
+
+ if ($b["preview"]) {
+ $max_char = 140;
+ require_once("include/plaintext.php");
+ $item = $b["item"];
+ $item["plink"] = $a->get_baseurl()."/display/".$a->user["nickname"]."/".$item["parent"];
+
+ $r = q("SELECT `author-link` FROM item WHERE item.uri = '%s' AND item.uid = %d LIMIT 1",
+ dbesc($item["thr-parent"]),
+ intval(local_user()));
+
+ if(count($r)) {
+ $orig_post = $r[0];
+
+ $nicknameplain = preg_replace("=https?://twitter.com/(.*)=ism", "$1", $orig_post["author-link"]);
+ $nickname = "@[url=".$orig_post["author-link"]."]".$nicknameplain."[/url]";
+ $nicknameplain = "@".$nicknameplain;
+
+ if ((strpos($item["body"], $nickname) === false) AND (strpos($item["body"], $nicknameplain) === false))
+ $item["body"] = $nickname." ".$item["body"];
+ }
+
+
+ $msgarr = plaintext($a, $item, $max_char, true, 8);
+ $msg = $msgarr["text"];
+
+ if (isset($msgarr["url"]) AND ($msgarr["type"] != "photo"))
+ $msg .= " ".$msgarr["url"];
+
+ if (isset($msgarr["image"]))
+ $msg .= " ".$msgarr["image"];
+
+ $b['html'] = nl2br(htmlspecialchars($msg));
+ }
+}
+
+/**
+ * @brief Build the item array for the mirrored post
+ *
+ * @param object $a Application class
+ * @param integer $uid User id
+ * @param object $post Twitter object with the post
+ *
+ * @return array item data to be posted
+ */
+function twitter_do_mirrorpost($a, $uid, $post) {
+ $datarray["type"] = "wall";
+ $datarray["api_source"] = true;
+ $datarray["profile_uid"] = $uid;
+ $datarray["extid"] = NETWORK_TWITTER;
+ $datarray['message_id'] = item_new_uri($a->get_hostname(), $uid, NETWORK_TWITTER.":".$post->id);
+ $datarray['object'] = json_encode($post);
+ $datarray["title"] = "";
+
+ if (is_object($post->retweeted_status)) {
+ // We don't support nested shares, so we mustn't show quotes as shares on retweets
+ $item = twitter_createpost($a, $uid, $post->retweeted_status, array('id' => 0), false, false, true);
+
+ $datarray['body'] = "\n".share_header($item['author-name'], $item['author-link'], $item['author-avatar'], "",
+ $item['created'], $item['plink']);
+
+ $datarray['body'] .= $item['body'].'[/share]';
+ } else {
+ $item = twitter_createpost($a, $uid, $post, array('id' => 0), false, false, false);
+
+ $datarray['body'] = $item['body'];
+ }
+
+ $datarray["source"] = $item['app'];
+ $datarray["verb"] = $item['verb'];
+
+ if (isset($item["location"])) {
+ $datarray["location"] = $item["location"];
+ }
+
+ if (isset($item["coord"])) {
+ $datarray["coord"] = $item["coord"];
+ }
+
+ return $datarray;
+}
+