$qm->enqueue($data, 'tweetin'); } $lastId = twitter_id($timeline[0]); Twitter_synch_status::setLastId($flink->foreign_id, $timelineUri, $lastId); common_debug("Set lastId value '{$lastId}' for foreign id '{$flink->foreign_id}' and timeline '" . $timelineUri . "'"); } // Okay, record the time we synced with Twitter for posterity $flink->last_noticesync = common_sql_now(); $flink->update(); } } $id = null; $debug = null; if (have_option('i')) { $id = get_option_value('i'); } else { if (have_option('--id')) { $id = get_option_value('--id'); } else { if (count($args) > 0) { $id = $args[0]; } else { $id = null; } } } if (have_option('d') || have_option('debug')) { $debug = true; } $fetcher = new TwitterStatusFetcher($id, POLL_INTERVAL, MAXCHILDREN, $debug); $fetcher->runOnce();
function linkify($status, $html = FALSE) { $text = $status->text; if (empty($status->entities)) { $statusId = twitter_id($status); common_log(LOG_WARNING, "No entities data for {$statusId}; trying to fake up links ourselves."); $text = common_replace_urls_callback($text, 'common_linkify'); $text = preg_replace_callback('/(^|\\"\\;|\'|\\(|\\[|\\{|\\s+)#([\\pL\\pN_\\-\\.]{1,64})/', function ($m) { return $m[1] . '#' . TwitterStatusFetcher::tagLink($m[2]); }, $text); $text = preg_replace_callback('/(^|\\s+)@([a-z0-9A-Z_]{1,64})/', function ($m) { return $m[1] . '@' . TwitterStatusFetcher::atLink($m[2]); }, $text); return $text; } // Move all the entities into order so we can // replace them and escape surrounding plaintext // in order $toReplace = array(); if (!empty($status->entities->urls)) { foreach ($status->entities->urls as $url) { $toReplace[$url->indices[0]] = array(self::URL, $url); } } if (!empty($status->entities->hashtags)) { foreach ($status->entities->hashtags as $hashtag) { $toReplace[$hashtag->indices[0]] = array(self::HASHTAG, $hashtag); } } if (!empty($status->entities->user_mentions)) { foreach ($status->entities->user_mentions as $mention) { $toReplace[$mention->indices[0]] = array(self::MENTION, $mention); } } // sort in forward order by key ksort($toReplace); $result = ''; $cursor = 0; foreach ($toReplace as $part) { list($type, $object) = $part; $start = $object->indices[0]; $end = $object->indices[1]; if ($cursor < $start) { // Copy in the preceding plaintext $result .= $this->twitEscape(mb_substr($text, $cursor, $start - $cursor)); $cursor = $start; } $orig = $this->twitEscape(mb_substr($text, $start, $end - $start)); switch ($type) { case self::URL: $linkText = $this->makeUrlLink($object, $orig, $html); break; case self::HASHTAG: if ($html) { $linkText = $this->makeHashtagLink($object, $orig); } else { $linkText = $orig; } break; case self::MENTION: if ($html) { $linkText = $this->makeMentionLink($object, $orig); } else { $linkText = $orig; } break; default: $linkText = $orig; continue; } $result .= $linkText; $cursor = $end; } $last = $this->twitEscape(mb_substr($text, $cursor)); $result .= $last; return $result; }