diff --git a/tweet_feed.module b/tweet_feed.module old mode 100644 new mode 100755 index 070391a..4303578 --- a/tweet_feed.module +++ b/tweet_feed.module @@ -765,33 +765,17 @@ function tweet_feed_save_tweet($tweet, $feed, $update_node_id = 0, $hash = NULL, $node->sticky = 0; $node->language = LANGUAGE_NONE; - // The tweet author goes into the title field - // Filter it cleanly since it is going into the title field. If we cannot use iconv, - // then use something more primitive, but effective - // @see https://www.drupal.org/node/1910376 - // @see http://webcollab.sourceforge.net/unicode.html - // Reject overly long 2 byte sequences, as well as characters above U+10000 - // and replace with --. - $title_tweet_text = preg_replace('/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]' . - '|[\x00-\x7F][\x80-\xBF]+' . - '|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*' . - '|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})' . - '|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/S', - '--', $tweet->text); - // Reject overly long 3 byte sequences and UTF-16 surrogates and replace - // with --. - $title_tweet_text = preg_replace('/\xE0[\x80-\x9F][\x80-\xBF]' . '|\xED[\xA0-\xBF][\x80-\xBF]/S', '--', $title_tweet_text); - - $node->title = check_plain(substr($tweet->user->screen_name . ': ' . $title_tweet_text, 0, 255)); + // Filter it cleanly since it is going into the title field and remove iconv. + $node->title = check_plain(substr(tweet_feed_filter_iconv_text($tweet->user->screen_name) . ': ' . tweet_feed_filter_iconv_text($tweet->text), 0, 255)); // The tweet itself goes into the tweet contents field $node->field_tweet_contents[$node->language][0] = array( - 'value' => utf8_encode(htmlspecialchars_decode($tweet_html)), + 'value' => htmlspecialchars_decode(utf8_encode($tweet_html)), 'format' => 'full_html', ); // Save the name of the user to the tweet. - $node->field_tweet_author_name[$node->language][0]['value'] = $tweet->user->name; + $node->field_tweet_author_name[$node->language][0]['value'] = tweet_feed_filter_iconv_text($tweet->user->name); // Set our verified field $node->field_tweet_author_verified[$node->language][0]['value'] = (int) $tweet->user->verified; @@ -852,8 +836,8 @@ function tweet_feed_save_tweet($tweet, $feed, $update_node_id = 0, $hash = NULL, // Handle the author name $node->field_tweet_author[$node->language][0] = array( - 'value' => $tweet->user->screen_name, - 'safe_value' => $tweet->user->screen_name, + 'value' => tweet_feed_filter_iconv_text($tweet->user->screen_name), + 'safe_value' => tweet_feed_filter_iconv_text($tweet->user->screen_name), ); // Handle the author id @@ -904,8 +888,8 @@ function tweet_feed_save_tweet($tweet, $feed, $update_node_id = 0, $hash = NULL, if (!empty($tweet->entities->user_mentions) && is_array($tweet->entities->user_mentions)) { foreach ($tweet->entities->user_mentions as $key => $mention) { $node->field_tweet_user_mentions[$node->language][$key] = array( - 'tweet_feed_mention_name' => $mention->name, - 'tweet_feed_mention_screen_name' => $mention->screen_name, + 'tweet_feed_mention_name' => tweet_feed_filter_iconv_text($mention->name), + 'tweet_feed_mention_screen_name' => tweet_feed_filter_iconv_text($mention->screen_name), 'tweet_feed_mention_id' => $mention->id, ); } @@ -1007,7 +991,7 @@ function tweet_feed_save_tweet($tweet, $feed, $update_node_id = 0, $hash = NULL, $node->field_twitter_user_id[$node->language][0]['value'] = $tweet->user->id_str; $node->title = $tweet->user->name; $node->body[$node->language][0]['value'] = $tweet->user->description; - $node->field_twitter_a_screen_name[$node->language][0]['value'] = $tweet->user->screen_name; + $node->field_twitter_a_screen_name[$node->language][0]['value'] = tweet_feed_filter_iconv_text($tweet->user->screen_name); $node->field_twitter_location[$node->language][0]['value'] = $tweet->user->location; $node->field_twitter_a_profile_url[$node->language][0]['value'] = $tweet->user->entities->url->urls[0]->url; $node->field_twitter_profile_url[$node->language][0]['value'] = $tweet->user->entities->url->urls[0]->display_url; @@ -1058,6 +1042,28 @@ function tweet_feed_save_tweet($tweet, $feed, $update_node_id = 0, $hash = NULL, } /** + * Filter iconv from text. + */ +function tweet_feed_filter_iconv_text($text, $replace = '--') { + // The tweet author goes into the title field + // Filter it cleanly since it is going into the title field. If we cannot use iconv, + // then use something more primitive, but effective + // @see https://www.drupal.org/node/1910376 + // @see http://webcollab.sourceforge.net/unicode.html + // Reject overly long 2 byte sequences, as well as characters above U+10000 + // and replace with --. + $altered = preg_replace('/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]' . + '|[\x00-\x7F][\x80-\xBF]+' . + '|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*' . + '|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})' . + '|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/S', + '--', $text); + // Reject overly long 3 byte sequences and UTF-16 surrogates and replace + // with --. + return preg_replace('/\xE0[\x80-\x9F][\x80-\xBF]' . '|\xED[\xA0-\xBF][\x80-\xBF]/S', $replace, $altered); +} + +/** * Implements hook_node_delete(). * * Remove hashes when tweets or profiles deleted