<?php //compares the tokens returned by token_get_all with the lexer if (!isset($_SERVER['argv'][1])) { die("Usage: {$_SERVER['argv'][0]} [FILE | --code CODE]\n"); } if ($_SERVER['argv'][1] == '--code') { echo "processing code:\n\n"; processString($_SERVER['argv'][2]); } else { unset($_SERVER['argv'][0]); foreach ($_SERVER['argv'] as $file) { echo "processing file {$file}:\n\n"; processString(file_get_contents($file)); } } function processString($c) { $tokens = array(); $start = microtime(true); $c = str_replace("\r", "", $c); foreach (token_get_all($c) as $i) { if (is_string($i)) { $name = $i; $chars = $i; } else { if (is_int($i[0])) { $name = token_name($i[0]); $chars = $i[1]; } else { $name = $i[0];
function widget($args, $instance) { extract($args); //Our variables from the widget settings. $title = apply_filters('widget_title', $instance['title']); $twitteruser = $instance['name']; $notweets = $instance['num']; $consumerkey = $instance['custommerkey']; $consumersecret = $instance['custommersecret']; $accesstoken = $instance['accesstoken']; $accesstokensecret = $instance['accesstokensecret']; $show_info = isset($instance['show_info']) ? $instance['show_info'] : false; //Test echo $before_widget; // Display the widget title if ($title) { echo $before_title . $title . $after_title; } //Display the name $connection = $this->getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret); $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $twitteruser . "&count=" . $notweets); $status = json_encode($tweets); $fp = fopen('results.json', 'w'); fwrite($fp, json_encode($tweets)); fclose($fp); $responseJson = file_get_contents(get_home_url() . '/results.json'); if ($responseJson) { $response = json_decode($responseJson); } ?> <div class=" tweets-widget"> <ul> <?php if (!function_exists('processString')) { function processString($s) { return preg_replace('/https?:\\/\\/[\\w\\-\\.!~?&+\\*\'"(),\\/]+/', '<a href="$0">$0</a>', $s); } } ?> <?php foreach ((array) $response as $tweet) { ?> <?php ?> <li> <p><?php echo processString($tweet->text); ?> </p> <span><?php echo $this->getAgo(strtotime($tweet->created_at)); ?> </span> </li> <?php } ?> </ul> </div> <?php echo $after_widget; }
<?php const OPEN_BRACE = '{'; const CLOSE_BRACE = '}'; $string = "{Пожалуйста|Просто} сделайте так, чтобы это {удивительное|крутое|простое} тестовое предложение {изменялось {{быстро|быстрее}|мгновенно} случайным образом|менялось каждый раз}."; for ($i = 0; $i < 100; ++$i) { echo processString($string) . PHP_EOL; } unset($i, $string); // functions function processString($string) { $inputArray = mbStringToArray($string); $nextIndex = 0; $result = ''; $length = count($inputArray); for ($index = 0; $index < $length; ++$index) { $char = $inputArray[$index]; switch ($char) { case OPEN_BRACE: $result .= processOpenBrace($index + 1, $inputArray, $nextIndex); $index = $nextIndex; break; default: $result .= $char; break; } } unset($index, $char); return $result; }
<?php $fd = $facebook_data['data']; $arrLen = count($fd); for ($i = 0; $i < $arrLen; $i++) { print PHP_EOL . ' <entry>' . PHP_EOL; print ' <id>tag:facebook.com,' . date("Y-m-d", strtotime($fd[$i]['created_time'])) . ':/' . $fd[$i]['from']['name'] . '/statuses/' . $fd[$i]['id'] . '</id>' . PHP_EOL; if (isset($fd[$i]['link']) && $fd[$i]['type'] == 'photo') { print ' <link href="' . $fd[$i]['link'] . '" rel="alternate" type="text/html"/>' . PHP_EOL; } else { print ' <link href="http://facebook.com/' . $fd[$i]['id'] . '" rel="alternate" type="text/html"/>' . PHP_EOL; } print ' <title>' . getFeedTitle($fd[$i]) . '</title>' . PHP_EOL; -(print ' <summary type="html"><![CDATA[' . $fd[$i]['message'] . ']]></summary>' . PHP_EOL); $text = ' <content type="html"><![CDATA[<p>' . processString(nl2br($fd[$i]['message'] . ' ' . $fd[$i]['link'])) . '</p>' . (isset($fd[$i]['picture']) ? '<img src="' . $fd[$i]['picture'] . '"/>' : '') . ']]></content>'; print $text . PHP_EOL; print ' <pubdate>' . date('c', strtotime($fd[$i]['created_time'])) . '</pubdate>' . PHP_EOL; print ' <updated>' . date('c', strtotime($fd[$i]['updated_time'])) . '</updated>' . PHP_EOL; print ' <author><name>' . $fd[$i]['from']['name'] . '</name></author>' . PHP_EOL; print ' </entry>' . PHP_EOL; } print '</feed>' . PHP_EOL; print '<!-- vim:ft=xml -->'; function getFeedTitle($feed) { $title = ""; if (isset($feed['message'])) { appendStringToTitle($feed['message'], $title); } if (isset($feed['link']) && isset($feed['name'])) { appendStringToTitle($feed['name'], $title);
<?php function processString($s) { return preg_replace('@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.]*(\\?\\S+)?)?)*)@', '<a target="_blank" href="$1">$1</a>', $s); } $unsafe = array(".", "!", "/", ";", "!", "?", "\$", "#", "*", "'", '"'); $clean_room = str_replace($unsafe, "", strip_tags(strlen($_GET['room']) > 200 ? substr($_GET['room'], 0, 200) : $_GET['room'])); $clean_data = processString(strip_tags(strlen($_GET['message']) > 500 ? substr($_GET['message'], 0, 500) : $_GET['message'])); $clean_user = strip_tags(strlen($_GET['user']) > 15 ? substr($_GET['user'], 0, 15) : $_GET['user']); if ($clean_data == "" || $clean_user == "") { exit; } $message = '<div itemscope itemtype="https://schema.org/CommunicateAction" class="message"><div itemprop="about" class="content">' . $clean_data . '</div><div class="meta"><span itemprop="participant" class="username">' . $clean_user . '</span> • <span itemprop="startTime" class="timestamp">' . time() . '</span></div></div>' . "\r\n"; $file_data = file_get_contents('rooms/' . $clean_room . '.txt') . $message; file_put_contents('rooms/' . $clean_room . '.txt', $file_data);
<?php if (isset($q)) { $td = $twitter_data['statuses']; } else { $td = $twitter_data; } $arrLen = count($td); for ($i = 0; $i < $arrLen; $i++) { print PHP_EOL . ' <entry>' . PHP_EOL; print ' <id>tag:twitter.com,' . date("Y-m-d", strtotime($td[$i]['created_at'])) . ':/' . $td[$i]['user']['screen_name'] . '/statuses/' . $td[$i]['id_str'] . '</id>' . PHP_EOL; print ' <link href="https://twitter.com/' . $td[$i]['user']['screen_name'] . '/statuses/' . $td[$i]['id_str'] . '" rel="alternate" type="text/html"/>' . PHP_EOL; print ' <title>' . $td[$i]['user']['screen_name'] . ': ' . htmlspecialchars($td[$i]['text']) . '</title>' . PHP_EOL; print ' <summary type="html"><![CDATA[' . $td[$i]['user']['screen_name'] . ': ' . $td[$i]['text'] . ']]></summary>' . PHP_EOL; $feedContent = ' <content type="html"><![CDATA[<p>' . nl2br($td[$i]['text']) . '</p>]]></content>'; $text = processString($feedContent); print $text . PHP_EOL; print ' <updated>' . date('c', strtotime($td[$i]['created_at'])) . '</updated>' . PHP_EOL; print ' <author><name>' . $td[$i]['user']['screen_name'] . '</name></author>' . PHP_EOL; $hashLen = count($td[$i]['entities']['hashtags']); if ($hashLen > 0) { for ($j = 0; $j < $hashLen; $j++) { print ' <category term="' . $td[$i]['entities']['hashtags'][$j]['text'] . '"/>' . PHP_EOL; } } print ' </entry>' . PHP_EOL; } print '</feed>' . PHP_EOL; print '<!-- vim:ft=xml -->';