$statusUri = $this->makeStatusURI($status->user->screen_name, $statusId);
// check to see if we've already imported the status
- $n2s = Notice_to_status::staticGet('status_id', $statusId);
+ $n2s = Notice_to_status::getKV('status_id', $statusId);
if (!empty($n2s)) {
common_log(
$this->name() .
" - Ignoring duplicate import: {$statusId}"
);
- return Notice::staticGet('id', $n2s->notice_id);
+ return Notice::getKV('id', $n2s->notice_id);
}
// If it's a retweet, save it as a repeat!
$replyTo = twitter_id($status, 'in_reply_to_status_id');
if (!empty($replyTo)) {
common_log(LOG_INFO, "Status {$statusId} is a reply to status {$replyTo}");
- $n2s = Notice_to_status::staticGet('status_id', $replyTo);
+ $n2s = Notice_to_status::getKV('status_id', $replyTo);
if (empty($n2s)) {
common_log(LOG_INFO, "Couldn't find local notice for status {$replyTo}");
} else {
- $reply = Notice::staticGet('id', $n2s->notice_id);
+ $reply = Notice::getKV('id', $n2s->notice_id);
if (empty($reply)) {
common_log(LOG_INFO, "Couldn't find local notice for status {$replyTo}");
} else {
$notice->is_local = Notice::GATEWAY;
- $notice->content = html_entity_decode($status->text, ENT_QUOTES, 'UTF-8');
- $notice->rendered = $this->linkify($status);
+ $notice->content = html_entity_decode($this->linkify($status, FALSE), ENT_QUOTES, 'UTF-8');
+ $notice->rendered = $this->linkify($status, TRUE);
if (Event::handle('StartNoticeSave', array(&$notice))) {
/**
- * Look up a Profile by profileurl field. Profile::staticGet() was
+ * Look up a Profile by profileurl field. Profile::getKV() was
* not working consistently.
*
* @param string $nickname local nickname of the Twitter user
// check for remote profile
- $remote_pro = Remote_profile::staticGet('uri', $profileurl);
+ $remote_pro = Remote_profile::getKV('uri', $profileurl);
if (empty($remote_pro)) {
$remote_pro = new Remote_profile();
{
global $config;
- $path_parts = pathinfo($twitter_user->profile_image_url);
-
- $newname = 'Twitter_' . $twitter_user->id . '_' .
- $path_parts['basename'];
+ $newname = 'Twitter_' . $twitter_user->id . '_' . basename($twitter_user->profile_image_url);
$oldname = $profile->getAvatar(48)->filename;
$path_parts = pathinfo($twitter_user->profile_image_url);
- $img_root = substr($path_parts['basename'], 0, -11);
- $ext = $path_parts['extension'];
- $mediatype = $this->getMediatype($ext);
+ $ext = (isset($path_parts['extension']) ? '.'.$path_parts['extension'] : ''); // some lack extension
+ $img_root = basename($path_parts['basename'], '_normal'.$ext); // cut off extension
+ $mediatype = $this->getMediatype(substr($ext, 1));
foreach (array('mini', 'normal', 'bigger') as $size) {
$url = $path_parts['dirname'] . '/' .
- $img_root . '_' . $size . ".$ext";
+ $img_root . '_' . $size . $ext;
$filename = 'Twitter_' . $twitter_user->id . '_' .
- $img_root . "_$size.$ext";
+ $img_root . '_' . $size . $ext;
$this->updateAvatar($profile->id, $size, $mediatype, $filename);
$this->fetchAvatar($url, $filename);
$mediatype = null;
switch (strtolower($ext)) {
+ case 'jpeg':
case 'jpg':
- $mediatype = 'image/jpg';
+ $mediatype = 'image/jpeg';
break;
case 'gif':
$mediatype = 'image/gif';
global $config;
$path_parts = pathinfo($user->profile_image_url);
- $ext = $path_parts['extension'];
- $end = strlen('_normal' . $ext);
- $img_root = substr($path_parts['basename'], 0, -($end+1));
- $mediatype = $this->getMediatype($ext);
+ $ext = (isset($path_parts['extension']) ? '.'.$path_parts['extension'] : '');
+ $img_root = basename($path_parts['basename'], '_normal'.$ext);
+ $mediatype = $this->getMediatype(substr($ext, 1));
foreach (array('mini', 'normal', 'bigger') as $size) {
$url = $path_parts['dirname'] . '/' .
- $img_root . '_' . $size . ".$ext";
+ $img_root . '_' . $size . $ext;
$filename = 'Twitter_' . $user->id . '_' .
- $img_root . "_$size.$ext";
+ $img_root . '_' . $size . $ext;
if ($this->fetchAvatar($url, $filename)) {
$this->newAvatar($id, $size, $mediatype, $filename);
common_debug($this->name() . " - Updating avatar: $size");
- $profile = Profile::staticGet($profile_id);
+ $profile = Profile::getKV($profile_id);
if (empty($profile)) {
common_debug($this->name() . " - Couldn't get profile: $profile_id!");
const HASHTAG = 2;
const MENTION = 3;
- function linkify($status)
+ function linkify($status, $html = FALSE)
{
$text = $status->text;
$orig = $this->twitEscape(mb_substr($text, $start, $end - $start));
switch($type) {
case self::URL:
- $linkText = $this->makeUrlLink($object, $orig);
+ $linkText = $this->makeUrlLink($object, $orig, $html);
break;
case self::HASHTAG:
- $linkText = $this->makeHashtagLink($object, $orig);
+ if ($html) {
+ $linkText = $this->makeHashtagLink($object, $orig);
+ }else{
+ $linkText = $orig;
+ }
break;
case self::MENTION:
- $linkText = $this->makeMentionLink($object, $orig);
+ if ($html) {
+ $linkText = $this->makeMentionLink($object, $orig);
+ }else{
+ $linkText = $orig;
+ }
break;
default:
$linkText = $orig;
return htmlspecialchars(html_entity_decode($str, ENT_COMPAT, 'UTF-8'));
}
- function makeUrlLink($object, $orig)
+ function makeUrlLink($object, $orig, $html)
{
- return "<a href='{$object->url}' class='extlink'>{$orig}</a>";
+ if ($html) {
+ return '<a href="'.htmlspecialchars($object->expanded_url).'" class="extlink">'.htmlspecialchars($object->display_url).'</a>';
+ }else{
+ return htmlspecialchars($object->expanded_url);
+ }
}
function makeHashtagLink($object, $orig)
foreach ($status->entities->user_mentions as $mention) {
$flink = Foreign_link::getByForeignID($mention->id, TWITTER_SERVICE);
if (!empty($flink)) {
- $user = User::staticGet('id', $flink->user_id);
+ $user = User::getKV('id', $flink->user_id);
if (!empty($user)) {
$reply = new Reply();
$reply->notice_id = $notice->id;