X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FTwitterBridge%2Ftwitterimport.php;h=0eacfcd62c57cf10dc05350dc0a52ff88347d726;hb=4e1ce4e5bbc43869dc7c85463f9a733da9f5fda4;hp=3a4c0c43c0f1170e0b42345c81f9a36d5c0f5d69;hpb=6455461c196fcb8e7c0047870d480e4a97986709;p=quix0rs-gnu-social.git
diff --git a/plugins/TwitterBridge/twitterimport.php b/plugins/TwitterBridge/twitterimport.php
index 3a4c0c43c0..0eacfcd62c 100644
--- a/plugins/TwitterBridge/twitterimport.php
+++ b/plugins/TwitterBridge/twitterimport.php
@@ -264,7 +264,7 @@ class TwitterImport
function ensureProfile($user)
{
// check to see if there's already a profile for this user
- $profileurl = 'http://twitter.com/#!/' . $user->screen_name;
+ $profileurl = 'http://twitter.com/' . $user->screen_name;
$profile = $this->getProfileByUrl($user->screen_name, $profileurl);
if (!empty($profile)) {
@@ -554,8 +554,8 @@ class TwitterImport
}
// Move all the entities into order so we can
- // replace them in reverse order and thus
- // not mess up their indices
+ // replace them and escape surrounding plaintext
+ // in order
$toReplace = array();
@@ -577,56 +577,85 @@ class TwitterImport
}
}
- // sort in reverse order by key
+ // sort in forward order by key
- krsort($toReplace);
+ 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);
+ $linkText = $this->makeUrlLink($object, $orig);
break;
case self::HASHTAG:
- $linkText = $this->makeHashtagLink($object);
+ $linkText = $this->makeHashtagLink($object, $orig);
break;
case self::MENTION:
- $linkText = $this->makeMentionLink($object);
+ $linkText = $this->makeMentionLink($object, $orig);
break;
default:
+ $linkText = $orig;
continue;
}
- $text = mb_substr($text, 0, $object->indices[0]) . $linkText . mb_substr($text, $object->indices[1]);
+ $result .= $linkText;
+ $cursor = $end;
}
- return $text;
+ $last = $this->twitEscape(mb_substr($text, $cursor));
+ $result .= $last;
+
+ return $result;
+ }
+
+ function twitEscape($str)
+ {
+ // Twitter seems to preemptive turn < and > into < and >
+ // but doesn't for &, so while you may have some magic protection
+ // against XSS by not bothing to escape manually, you still get
+ // invalid XHTML. Thanks!
+ //
+ // Looks like their web interface pretty much sends anything
+ // through intact, so.... to do equivalent, decode all entities
+ // and then re-encode the special ones.
+ return htmlspecialchars(html_entity_decode($str, ENT_COMPAT, 'UTF-8'));
}
- function makeUrlLink($object)
+ function makeUrlLink($object, $orig)
{
- return "{$object->url}";
+ return "{$orig}";
}
- function makeHashtagLink($object)
+ function makeHashtagLink($object, $orig)
{
- return "#" . self::tagLink($object->text);
+ return "#" . self::tagLink($object->text, substr($orig, 1));
}
- function makeMentionLink($object)
+ function makeMentionLink($object, $orig)
{
- return "@".self::atLink($object->screen_name, $object->name);
+ return "@".self::atLink($object->screen_name, $object->name, substr($orig, 1));
}
- static function tagLink($tag)
+ static function tagLink($tag, $orig)
{
- return "{$tag}";
+ return "{$orig}";
}
- static function atLink($screenName, $fullName=null)
+ static function atLink($screenName, $fullName, $orig)
{
if (!empty($fullName)) {
- return "{$screenName}";
+ return "{$orig}";
} else {
- return "{$screenName}";
+ return "{$orig}";
}
}
@@ -646,6 +675,7 @@ class TwitterImport
$reply = new Reply();
$reply->notice_id = $notice->id;
$reply->profile_id = $user->id;
+ $reply->modified = $notice->created;
common_log(LOG_INFO, __METHOD__ . ": saving reply: notice {$notice->id} to profile {$user->id}");
$id = $reply->insert();
}