+function twitter_expire($a,$b) {
+
+ $days = get_config('twitter', 'expire');
+
+ if ($days == 0)
+ return;
+
+ $r = q("DELETE FROM `item` WHERE `deleted` AND `network` = '%s'", dbesc(NETWORK_TWITTER));
+
+ require_once("include/items.php");
+
+ logger('twitter_expire: expire_start');
+
+ $r = q("SELECT * FROM `pconfig` WHERE `cat` = 'twitter' AND `k` = 'import' AND `v` = '1' ORDER BY RAND()");
+ if(count($r)) {
+ foreach($r as $rr) {
+ logger('twitter_expire: user '.$rr['uid']);
+ item_expire($rr['uid'], $days, NETWORK_TWITTER, true);
+ }
+ }
+
+ logger('twitter_expire: expire_end');
+}
+
+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"]))
+ $msg .= " ".$msgarr["url"];
+
+ if (isset($msgarr["image"]))
+ $msg .= " ".$msgarr["image"];
+
+ $b['html'] = nl2br(htmlspecialchars($msg));
+ }
+}
+