public function update() { $feed = new SimplePie(); $feed->set_feed_url('http://api.twitter.com/1/statuses/user_timeline.atom?screen_name=' . $this->user); $feed->enable_cache(false); $feed->set_stupidly_fast(true); $feed->init(); foreach ($feed->get_items() as $item) { $title = substr($item->get_title(), strlen($this->user) + 2); $title = sprintf('<blockquote>%s</blockquote>', $title); $data = array( 'id' => $item->get_id(), 'title' => Twitter_Autolink::create($title) ->setTarget(false) ->setExternal(false) ->addLinks(), 'content' => '', 'source' => 'twitter', 'timestamp' => $item->get_date('U') ); Murray_Entry::create($data); } }
public function getData() { $params = $this->params; $minute = (int) $params->get('cache_time', 90); if (!$params->get('use_cache') || !file_exists($this->cacheFile) || filemtime($this->cacheFile) <= time() - 60 * $minute) { $twitterConnection = new TwitterOAuth(trim($params->get('con_key', '')), trim($params->get('con_secret', '')), trim($params->get('access_token', '')), trim($params->get('access_token_secret', ''))); if ($params->get('widget_type') == 'timeline') { $twitterData = $twitterConnection->get('statuses/user_timeline', array('screen_name' => trim($params->get('username', 'leotheme')), 'count' => trim($params->get('tweet_number', 5)))); } else { $twitterData = $twitterConnection->get('search/tweets', array('q' => trim($params->get('search_query', '')), 'count' => trim($params->get('tweet_number', 5)))); if (!isset($twitterData->errors)) { $twitterData = $twitterData->statuses; } } // if there are no errors if (!isset($twitterData->errors)) { $tweets = array(); foreach ($twitterData as $tweet) { $tweetDetails = new stdClass(); $tweetDetails->text = Twitter_Autolink::create($tweet->text)->setNoFollow(false)->addLinks(); $tweetDetails->time = $this->getTime($tweet->created_at); $tweetDetails->id = $tweet->id_str; $tweetDetails->screenName = $tweet->user->screen_name; $tweetDetails->displayName = $tweet->user->name; $tweetDetails->profileImage = $tweet->user->profile_image_url_https; $tweets[] = $tweetDetails; } $data = new stdClass(); $data->tweets = $tweets; $this->data = $data; if ($params->get('use_cache')) { $this->setCache(); } return $data; } else { return ''; } } else { return $this->getCache(); } }
function twitter_parse_tags($input, $entities = false) { $out = $input; //Linebreaks. Some clients insert \n for formatting. $out = nl2br($out); // Use the Entities to replace hyperlink URLs // http://dev.twitter.com/pages/tweet_entities if ($entities) { if ($entities->urls) { foreach ($entities->urls as $urls) { if ($urls->expanded_url != "") { $display_url = $urls->expanded_url; } else { $display_url = $urls->url; } $url = $urls->url; $parsed_url = parse_url($url); if (empty($parsed_url['scheme'])) { $url = 'http://' . $url; } if (setting_fetch('gwt') == 'on') { $encoded = urlencode($url); $link = "http://google.com/gwt/n?u={$encoded}"; } else { $link = $url; } $link_html = '<a href="' . $link . '" target="' . get_target() . '">' . $display_url . '</a>'; $url = $urls->url; // Replace all URLs *UNLESS* they have already been linked (for example to an image) $pattern = '#((?<!href\\=(\'|\\"))' . preg_quote($url, '#') . ')#i'; $out = preg_replace($pattern, $link_html, $out); } } if ($entities->hashtags) { foreach ($entities->hashtags as $hashtag) { $text = $hashtag->text; $pattern = '/(^|\\s)([##]+)(' . $text . ')/iu'; $link_html = ' <a href="hash/' . $text . '">#' . $text . '</a> '; $out = preg_replace($pattern, $link_html, $out, 1); } } } else { // If Entities haven't been returned (usually because of search or a bio) use Autolink // Create an array containing all URLs $urls = Twitter_Extractor::create($input)->extractURLs(); // Hyperlink the URLs if (setting_fetch('gwt') == 'on') { foreach ($urls as $url) { $encoded = urlencode($url); $out = str_replace($url, "<a href='http://google.com/gwt/n?u={$encoded}' target='" . get_target() . "'>{$url}</a>", $out); } } else { $out = Twitter_Autolink::create($out)->addLinksToURLs(); } // Hyperlink the # $out = Twitter_Autolink::create($out)->setTarget('')->addLinksToHashtags(); } // Hyperlink the @ and lists $out = Twitter_Autolink::create($out)->setTarget('')->addLinksToUsernamesAndLists(); // Emails $tok = strtok($out, " \n\t\n\r"); // Tokenise the string by whitespace while ($tok !== false) { // Go through all the tokens $at = stripos($tok, "@"); // Does the string contain an "@"? if ($at && $at > 0) { // @ is in the string & isn't the first character $tok = trim($tok, "?.,!\"\\'"); // Remove any trailing punctuation if (filter_var($tok, FILTER_VALIDATE_EMAIL)) { // Use the internal PHP email validator $email = $tok; $out = str_replace($email, "<a href=\"mailto:{$email}\">{$email}</a>", $out); // Create the mailto: link } } $tok = strtok(" \n\t\n\r"); // Move to the next token } // Add Emoticons :-) if (setting_fetch('emoticons') != 'off') { $out = emoticons($out); } //Return the completed string return $out; }
function be_tweet_autolink($tweet) { require_once BE_PB_ROOT_PATH . 'functions/twitter/Autolink.php'; $autolinked_tweet = Twitter_Autolink::create($tweet, false)->setNoFollow(false)->setExternal(false)->setTarget('')->setUsernameClass('')->setHashtagClass('')->setURLClass('')->addLinks(); return $autolinked_tweet; }
public function formatTweets($tweets) { $t = array(); $i = 0; foreach ($tweets as $tweet) { if (isset($tweet->retweeted_status)) { $text = $this->removeSpamCharacters($tweet->retweeted_status->text); } else { $text = $this->removeSpamCharacters($tweet->text); } $urls = $tweet->entities->urls; $mentions = $tweet->entities->user_mentions; $hashtags = $tweet->entities->hashtags; if ($urls) { foreach ($urls as $url) { if (strpos($text, $url->url) !== false) { $text = str_replace($url->url, '<a href="' . $url->url . '">' . $url->url . '</a>', $text); } } } if ($mentions && $this->attags) { foreach ($mentions as $mention) { if (strpos($text, $mention->screen_name) !== false) { $text = str_replace("@" . $mention->screen_name . " ", '<a href="http://twitter.com/' . $mention->screen_name . '">@' . $mention->screen_name . '</a> ', $text); } } } if ($hashtags && $this->hashtags) { foreach ($hashtags as $hashtag) { if (strpos($text, $hashtag->text) !== false) { $text = str_replace('#' . $hashtag->text . " ", '<a href="http://twitter.com/search?q=%23' . $hashtag->text . '">#' . $hashtag->text . '</a> ', $text); } } } $t[$i]["tweet"] = Twitter_Autolink::create($text, false)->setNoFollow(false)->setExternal(false)->setTarget('')->setUsernameClass('')->setHashtagClass('')->setURLClass('')->addLinks(); //trim($this->changeLink($text)); $t[$i]["time"] = trim($this->getTimeAgo($tweet->created_at)); $i++; } $this->saveCachedTweets($t); return $t; }
/** * La tache cron pour un flux particulier (une TwitterEntity, donc une chaine avec ses dates) */ public function streamCron(TwitterEntity $twitterEntity) { $this->initTwitterOAuth(); if ($this->db == null) { $this->db = new Database(); } /** @var TwitterEntity $twitterEntity Pour l'autocompletion de l'IDE */ /** @var ArticleEntity $firstArticle */ /** @var ArticleEntity $lastArticle */ /** On recupere le premier et le dernier tweet en BD de ce flux */ $firstArticle = $this->getFirstArticle($twitterEntity); $lastArticle = $this->getLastArticle($twitterEntity); /** On recupere tous les tweets de maintenant a stream.firstUpdate. dans $articles, en enlevant ceux deja presents en BD*/ $tweetsToInsert = $this->loadTweets($twitterEntity->getChannel(), $twitterEntity->getFirstUpdate(), $firstArticle->getArticleDate(), $lastArticle->getArticleDate()); /** On ajoute en BD les articles a inserer */ /** de plus, on les parse pour que les liens s'affichent */ $autolink = Twitter_Autolink::create(); $req = 'INSERT INTO article (title, content, articleDate, streamType, stream_id, url) VALUES (?,?,?,?,?,?)'; foreach ($tweetsToInsert as $tweet) { $text1 = $autolink->autoLink($tweet->text); $imageLink = $this->getImageLink($tweet); $this->db->execute($req, array($twitterEntity->getChannel(), $text1 . '<br/>' . $imageLink, date(Database::DATE_FORMAT, strtotime($tweet->created_at)), ArticleModel::TWITTER, $twitterEntity->getId(), $autolink->autoLink('@' . $twitterEntity->getChannel()))); } /** On modifie en BD le lastUpdate du stream qu'on traite a now() */ $this->db->execute('UPDATE stream_twitter SET lastUpdate = now()'); }
public static function autolink($tweet) { $autolink = \Twitter_Autolink::create(); return $autolink->autolink($tweet); }
/** * Parses tweets and generates HTML anchor tags around URLs, usernames, * username/list pairs and hashtags. * * @link https://github.com/mzsanford/twitter-text-php * * @since 0.1.0 * @param string $content Tweet content * @return string Modified tweet content */ public static function twitter_linkify($content) { // Include the Twitter-Text-PHP library if (!class_exists('Twitter_Regex')) { require_once WDS_TWWI_PATH . 'lib/TwitterText/lib/Twitter/Autolink.php'; } return Twitter_Autolink::create($content, true)->setNoFollow(false)->setExternal(true)->setTarget('_blank')->setUsernameClass('tweet-url username')->setListClass('tweet-url list-slug')->setHashtagClass('tweet-url hashtag')->setURLClass('tweet-url tweek-link')->addLinks(); }
echo $browser ? '<p>' : " [1;35m"; echo 'Skipping Test...'; echo $browser ? '</p>' : "[0m" . PHP_EOL; echo PHP_EOL; continue; } $function = $functions[$group]; $pass_group = 0; $fail_group = 0; if ($browser) { echo '<ul>', PHP_EOL; } foreach ($tests as $test) { echo $browser ? '<li>' : ' - '; echo $test['description'], ' ... '; $linked = Twitter_Autolink::create($test['text'], false)->setNoFollow(false)->setExternal(false)->setTarget('')->setUsernameClass('tweet-url username')->setListClass('tweet-url list-slug')->setHashtagClass('tweet-url hashtag')->setURLClass('')->{$function}(); # XXX: Need to re-order for hashtag as it is written out differently... # We use the same wrapping function for adding links for all methods. if ($group == 'hashtags') { $linked = preg_replace(array('!<a class="([^"]*)" href="([^"]*)">([^<]*)</a>!', '!title="#([^"]+)"!'), array('<a href="$2" title="$3" class="$1">$3</a>', 'title="#$1"'), $linked); } if ($test['expected'] == $linked) { $pass_group++; echo $browser ? '<span class="pass">PASS</span>' : "[1;32mPASS[0m"; } else { $fail_group++; echo $browser ? '<span class="fail">FAIL</span>' : "[1;31mFAIL[0m"; if ($browser) { echo '<pre>'; echo 'Original: ' . htmlspecialchars($test['text'], ENT_QUOTES, 'UTF-8', false), PHP_EOL; echo 'Expected: ' . pretty_format($test['expected']), PHP_EOL;
?> </div> <div class="img-name-tweet"> <div class="two-names"> <span class="name-ures-tweet"><?php echo $user['name']; ?> </span> <span class="name-screen-tweet"><?php echo $screenNameLink; ?> </span> </div> <div class="text-post hide-phone"> <?php echo Twitter_Autolink::create()->setNoFollow(false)->autoLink($tweet['text']); ?> </div> </div> <div class="text-post show-phone"> <?php echo Twitter_Autolink::create()->setNoFollow(false)->autoLink($tweet['text']); ?> </div> </li> <?php } ?> </ul>
function twitter_parse_tags($input, $entities = false, $id = false) { // Filter if ($id && substr($_GET["q"], 0, 6) !== "status" && setting_fetch('filtero', 'no') == 'yes' && twitter_timeline_filter($input)) { return "<a href='status/{$id}' class='filter'><span class='texts'>[Tweet Filtered]</span></a>"; } $out = $input; //Linebreaks. Some clients insert \n for formatting. $out = nl2br($out); // Use the Entities to replace hyperlink URLs // http://dev.twitter.com/pages/tweet_entities if ($entities) { if ($entities->urls) { foreach ($entities->urls as $urls) { if ($urls->display_url != "") { $display_url = $urls->display_url; } else { $display_url = $urls->url; } $expanded_url = $urls->expanded_url ? $urls->expanded_url : $urls->url; $expanded_url = add_http($expanded_url); $lurl = setting_fetch('longurl') == 'yes' && LONG_URL == 'ON' ? long_url($expanded_url) : $expanded_url; if (setting_fetch('gwt') == 'on') { $encoded = urlencode($lurl); $link = "http://google.com/gwt/n?u={$encoded}"; } else { $link = $lurl; } $atext = link_trans($display_url); $link_html = '<a href="' . $link . '" rel="external nofollow noreferrer">' . $atext . '</a>'; $url = $urls->url; // Replace all URLs *UNLESS* they have already been linked (for example to an image) $pattern = '#((?<!href\\=(\'|\\"))' . preg_quote($url, '#') . ')#i'; $out = preg_replace($pattern, $link_html, $out); } } if ($entities->hashtags) { foreach ($entities->hashtags as $hashtag) { $text = $hashtag->text; $pattern = '/(^|\\s)([##]+)(' . $text . ')/iu'; $link_html = ' <a href="hash/' . $text . '" rel="external nofollow tag noreferrer" class="hashtag">#' . $text . '</a> '; $out = preg_replace($pattern, $link_html, $out, 1); } } } else { // If Entities haven't been returned (usually because of search or a bio) use Autolink // Create an array containing all URLs $urls = Twitter_Extractor::create($input)->extractURLs(); // Hyperlink the URLs if (setting_fetch('gwt') == 'on') { foreach ($urls as $url) { if (setting_fetch('longurl') == 'yes' && LONG_URL == 'ON') { $lurl = long_url($url); } else { $lurl = $url; } $encoded = urlencode($lurl); $atext = link_trans($lurl); $out = str_replace($url, "<a href='http://google.com/gwt/n?u={$encoded}' rel='external nofollow noreferrer'>{$atext}</a>", $out); } } else { $out = Twitter_Autolink::create($out)->setTarget('')->setTag('')->addLinksToURLs(); foreach ($urls as $url) { if (setting_fetch('longurl') == 'yes' && LONG_URL == 'ON') { $lurl = long_url($url); $out = str_replace('href="' . $url . '"', 'href="' . $lurl . '"', $out); } else { $lurl = $url; } $atext = link_trans($lurl); $out = str_replace(">{$url}</a>", ">{$atext}</a>", $out); } } // Hyperlink the # $out = Twitter_Autolink::create($out)->setTarget('')->addLinksToHashtags(); } // Hyperlink the @ and lists $out = Twitter_Autolink::create($out)->setTarget('')->setTag('')->addLinksToUsernamesAndLists(); // Emails $tok = strtok($out, " \n\t\n\r"); // Tokenise the string by whitespace while ($tok !== false) { // Go through all the tokens $at = stripos($tok, "@"); // Does the string contain an "@"? if ($at && $at > 0) { // @ is in the string & isn't the first character $tok = trim($tok, "?.,!\"\\'"); // Remove any trailing punctuation if (filter_var($tok, FILTER_VALIDATE_EMAIL)) { // Use the internal PHP email validator $email = $tok; $out = str_replace($email, "<a href=\"mailto:{$email}\">{$email}</a>", $out); // Create the mailto: link } } $tok = strtok(" \n\t\n\r"); // Move to the next token } //Return the completed string return $out; }
function be_tweet_autolink($tweet) { require_once get_template_directory() . '/functions/twitter/Autolink.php'; $autolinked_tweet = Twitter_Autolink::create($tweet, false)->setNoFollow(false)->setExternal(false)->setTarget('')->setUsernameClass('')->setHashtagClass('')->setURLClass('')->addLinks(); return $autolinked_tweet; }
<?php /* * Twitter api interface */ chdir(dirname(__FILE__)); date_default_timezone_set('America/Los_Angeles'); include 'twitter-async/EpiCurl.php'; include 'twitter-async/EpiOAuth.php'; include 'twitter-async/EpiTwitter.php'; include 'twitter-text-php/Autolink.php'; include 'twitter-text-php/Extractor.php'; include 'twitter-text-php/HitHighlighter.php'; $key = trim(file_get_contents('secrets/tw-key')); $sec = trim(file_get_contents('secrets/tw-sec')); $tok = trim(file_get_contents('secrets/tw-tok')); $toksec = trim(file_get_contents('secrets/tw-toksec')); $tw = new EpiTwitter($key, $sec, $tok, $toksec); $resp = $tw->get('/users/show/openphoto.json'); $status = Twitter_Autolink::create($resp->status->text)->setNoFollow(false)->addLinks(); if ($status) { file_put_contents('output/twitter.txt', $status . '<div class="footnote"><a href="https://twitter.com/OpenPhoto/status/' . $resp->status->id_str . '" target="_blank" rel="external">' . date('h:i \\o\\n l, M jS', strtotime($resp->status->created_at)) . '</a> from <a href="https://twitter.com/OpenPhoto" target="_blank" rel="external">Twitter</a></div>'); }
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type' => 'application/x-www-form-urlencoded')); curl_setopt($curl, CURLOPT_USERAGENT, 'PHP'); curl_setopt($curl, CURLOPT_URL, $request->to_url()); $result = curl_exec($curl); curl_close($curl); $tweets = json_decode($result); if (!$tweets || isset($tweets->errors)) { return; } // output result in json format & cache it $output = array(); foreach ($tweets as $tweet) { $tweet_text = htmlentities(htmlspecialchars_decode($tweet->text), ENT_COMPAT, 'UTF-8'); $output[] = array('time_ago' => time_elapsed_string(strtotime($tweet->created_at)), 'text' => Twitter_Autolink::create($tweet_text)->setNoFollow(false)->addLinks(), 'actions' => array('reply' => 'http://twitter.com/intent/retweet?tweet_id=' . $tweet->id_str, 'retweet' => 'http://twitter.com/intent/tweet?in_reply_to=' . $tweet->id_str, 'favorite' => 'http://twitter.com/intent/favorite?tweet_id=' . $tweet->id_str)); } //cache result if ($cache !== false && $cache && file_exists('./twitter.cache')) { $file = './twitter.cache'; $cached = file_get_contents($file); @($unserialized = unserialize($cached)); if (!$unserialized) { $unserialized = array(); } $contents = serialize(array_merge(array($username => array('time' => time(), 'data' => $output)), $unserialized)); file_put_contents($file, $contents); } } else { $output = $cached_output; }
\$html = Twitter_Autolink::create() ->setNoFollow(false) ->autoLink(\$tweet); echo \$html; EOPHP; if ($browser) { echo '<h3>Source</h3>', PHP_EOL; echo '<pre class="source">'; highlight_string($code); echo '</pre>', PHP_EOL; } else { echo 'Source:', PHP_EOL, PHP_EOL; echo $code; echo PHP_EOL, PHP_EOL; } $html = Twitter_Autolink::create()->setNoFollow(false)->autoLink($tweet); if ($browser) { echo '<h3>Markup</h3>', PHP_EOL; echo '<pre class="markup"><code>'; echo htmlspecialchars($html, ENT_QUOTES, 'UTF-8', false); echo '</code></pre>', PHP_EOL; } else { echo 'Markup:', PHP_EOL, PHP_EOL; echo wordwrap(htmlspecialchars($html, ENT_QUOTES, 'UTF-8', false)); echo PHP_EOL, PHP_EOL; } if ($browser) { echo '<h3>Output</h3>', PHP_EOL; echo '<div class="output">'; echo $html; echo '</div>', PHP_EOL;
/** * Helper function to convert usernames, hashtags and URLs * in a tweet to HTML links. */ public function autolink($tweet) { require_once dirname(__FILE__) . '/lib/twitter-text-php/lib/Twitter/Autolink.php'; $autolinked_tweet = Twitter_Autolink::create($tweet, false)->setNoFollow(false)->setExternal(false)->setTarget('')->setUsernameClass('')->setHashtagClass('')->setURLClass('')->addLinks(); return $autolinked_tweet; }
echo '</ul>'; } echo PHP_EOL; $pass_total += $pass_group; $fail_total += $fail_group; echo $browser ? '<p class="group">' : " [1;33m"; printf('Group Results: %d passes, %d failures', $pass_group, $fail_group); echo $browser ? '</p>' : "[0m" . PHP_EOL; echo PHP_EOL; } output_h2('Autolink Conformance'); # Load the test data. $data = Yaml::parse($DATA . '/autolink.yml'); # Define the functions to be tested. $functions = array('usernames' => 'autoLinkUsernamesAndLists', 'lists' => 'autoLinkUsernamesAndLists', 'hashtags' => 'autoLinkHashtags', 'cashtags' => 'autoLinkCashtags', 'urls' => 'autoLinkURLs', 'json' => 'autoLinkWithJson', 'all' => 'autoLink'); $linker = Twitter_Autolink::create(); # Perform testing. foreach ($data['tests'] as $group => $tests) { output_h3('Test Group - ' . ucfirst(str_replace('_', ' ', $group))); if (!array_key_exists($group, $functions)) { output_skip_test(); continue; } $function = $functions[$group]; $pass_group = 0; $fail_group = 0; if ($browser) { echo '<ul>', PHP_EOL; } foreach ($tests as $test) { echo $browser ? '<li>' : ' - ';
<h1><span class="name-screen-tweet"><?php echo Twitter_Autolink::create()->setNoFollow(false)->autoLink('@' . $screenName); ?> 's feed looks empty.</span></h1>
function twitter_parse_tags($input, $entities = false, $id = false, $source = NULL) { // Filter. if ($id && substr($_GET["q"], 0, 6) !== "status" && setting_fetch('filtero', 'no') == 'yes' && twitter_timeline_filter($input . ' ' . $source)) { return "<a href='" . BASE_URL . "status/{$id}' style='text-decoration:none;'><small>[" . __("Tweet Filtered") . "]</small></a>"; } // Linebreaks. Some clients insert \n for formatting. $out = nl2br($input); // Use the Entities to replace hyperlink URLs if ($entities && $entities->urls) { foreach ($entities->urls as $urls) { if ($urls->expanded_url != "") { $display_url = $urls->expanded_url; } else { $display_url = $urls->url; } $url_detect = parse_url($display_url); if (isset($url_detect["scheme"])) { $link_html = theme('external_link', $display_url); $url = $urls->url; // Replace all URLs *UNLESS* they have already been linked (for example to an image) $pattern = '#((?<!href\\=(\'|\\"))' . preg_quote($url, '#') . ')#i'; $out = preg_replace($pattern, $link_html, $out); } } } else { // If Entities haven't been returned, use Autolink // Create an array containing all URLs $urls = Twitter_Extractor::create($input)->extractURLs(); // Hyperlink the URLs $out = Twitter_Autolink::create($out)->addLinksToURLs(); // Hyperlink the # $out = Twitter_Autolink::create($out)->setTarget('')->addLinksToHashtags(); } // Hyperlink the @ and lists $out = Twitter_Autolink::create($out)->setTarget('')->addLinksToUsernamesAndLists(); // Hyperlink the # $out = Twitter_Autolink::create($out)->setTarget('')->addLinksToHashtags(); //Return the completed string return $out; }
\$html = Twitter_Autolink::create(\$tweet) ->setNoFollow(false) ->addLinks(); echo \$html; EOPHP; if ($browser) { echo '<h3>Source</h3>', PHP_EOL; echo '<pre class="source">'; highlight_string($code); echo '</pre>', PHP_EOL; } else { echo 'Source:', PHP_EOL, PHP_EOL; echo $code; echo PHP_EOL, PHP_EOL; } $html = Twitter_Autolink::create($tweet)->setNoFollow(false)->addLinks(); if ($browser) { echo '<h3>Markup</h3>', PHP_EOL; echo '<pre class="markup"><code>'; echo htmlspecialchars($html, ENT_QUOTES, 'UTF-8', false); echo '</code></pre>', PHP_EOL; } else { echo 'Markup:', PHP_EOL, PHP_EOL; echo wordwrap(htmlspecialchars($html, ENT_QUOTES, 'UTF-8', false)); echo PHP_EOL, PHP_EOL; } if ($browser) { echo '<h3>Output</h3>', PHP_EOL; echo '<div class="output">'; echo $html; echo '</div>', PHP_EOL;
/** * @dataProvider addLinksProvider */ public function testAddLinks($description, $text, $expected) { $linked = Twitter_Autolink::create($text, false)->setNoFollow(false)->setExternal(false)->setTarget('')->setUsernameClass('tweet-url username')->setListClass('tweet-url list-slug')->setHashtagClass('tweet-url hashtag')->setCashtagClass('tweet-url cashtag')->setURLClass('')->addLinks(); $this->assertSame($expected, $linked, $description); }
public function live() { $this->viewBuilder()->layout('frontend'); $twitter = $this->Twitter->Oauth(); $autolink = \Twitter_Autolink::create(); $query = '#DigitalThursday'; if ($this->request->query('last')) { $twitter = $twitter->get('search/tweets', ['q' => $query, 'since_id' => $this->request->query('last'), 'count' => 7]); if ($twitter->statuses && $twitter->statuses[0]->id == $this->request->query('last')) { $twitter = []; } else { if (empty($twitter->statuses)) { $twitter = []; } else { foreach ($twitter->statuses as $tweet) { $text = $autolink->autoLink($tweet->text); $tweet->text = $text; } $twitter = $twitter->statuses; } } } else { $twitter = $twitter->get('search/tweets', ['q' => $query, 'count' => 7]); $twitter = $twitter->statuses; } $this->set(compact('twitter', 'autolink')); $this->set('_serialize', ['twitter', 'autolink']); }