function tt_twitter($atts, $content = null) { global $tt_theme; $defaults = shortcode_atts(array('title' => '', 'username' => '', 'count' => 4, 'el_class' => ''), $atts); $output = ''; $tweets = twitter_get_tweets($defaults['username']); if (is_null($tweets)) { return 'Twitter is not configured.'; } $number = min(20, $defaults['count']); $tweets = array_slice($tweets, 0, $number); $time = time(); $last = count($tweets) - 1; foreach ($tweets as $i => $tweet) { $date = $tweet->created_at; $date = date_parse($date); $date = mktime(0, 0, 0, $date['month'], $date['day'], $date['year']); $date = $time - $date; $seconds = (int) $date; $date = floor($date / 60); $minutes = (int) $date; if ($minutes) { $date = floor($date / 60); $hours = (int) $date; if ($hours) { $date = floor($date / 24); $days = (int) $date; if ($days) { $date = floor($date / 7); $weeks = (int) $date; if ($weeks) { $date = $weeks . ' week' . (1 === $weeks ? '' : 's') . ' ago'; } else { $date = $days . ' day' . (1 === $days ? '' : 's') . ' ago'; } } else { $date = $hours . ' hour' . (1 === $hours ? '' : 's') . ' ago'; } } else { $date = $minutes . ' minute' . (1 === $minutes ? '' : 's') . ' ago'; } } else { $date = 'less than a minute ago'; } $status_text = preg_replace('/(https?:\\/\\/\\S+)/', ' <a class="text-alpha" href="\\1">\\1</a> ', $tweet->text); // linkify twitter users $status_text = preg_replace('/(^|\\s)@(\\w+)/', '\\1 <a class="text-alpha" href="http://twitter.com/\\2">@\\2</a> ', $status_text); // linkify tags $status_text = preg_replace('/(^|\\s)#(\\w+)/', '\\1 <a class="text-alpha" href="http://twitter.com/search?q=%23\\2&src=hash">#\\2</a> ', $status_text); $output .= '<li' . ($i === $last ? ' class="last"' : '') . '><div class="twitter-item"><p>' . $status_text . '<span class="date">' . $date . '</span>' . '</p></div></li>'; } $defaults['tweets'] = $output; ob_start(); $tt_theme->tt_view('twitter', $defaults, 'shortcodes'); return ob_get_clean(); }
function twitter_generate_output($user, $number, $callback = '', $step_callback = '', $before = false, $after = false) { $tweets = twitter_get_tweets($user); if (is_null($tweets)) { return 'Twitter is not configured.'; } $number = min(20, $number); $tweets = array_slice($tweets, 0, $number); if (!empty($callback)) { return call_user_func($callback, $tweets); } $output = $before === false ? '<div class="tt_twitter"><ul class="twitter">' : $before; $time = time(); $last = count($tweets) - 1; if (!empty($tweets)) { foreach ($tweets as $i => $tweet) { $date = $tweet->created_at; $date = date_parse($date); $date = mktime(0, 0, 0, $date['month'], $date['day'], $date['year']); $date = $time - $date; $seconds = (int) $date; $date = floor($date / 60); $minutes = (int) $date; if ($minutes) { $date = floor($date / 60); $hours = (int) $date; if ($hours) { $date = floor($date / 24); $days = (int) $date; if ($days) { $date = floor($date / 7); $weeks = (int) $date; if ($weeks) { $date = $weeks . ' week' . (1 === $weeks ? '' : 's') . ' ago'; } else { $date = $days . ' day' . (1 === $days ? '' : 's') . ' ago'; } } else { $date = $hours . ' hour' . (1 === $hours ? '' : 's') . ' ago'; } } else { $date = $minutes . ' minute' . (1 === $minutes ? '' : 's') . ' ago'; } } else { $date = 'less than a minute ago'; } $output .= $step_callback === '' ? '<li' . ($i === $last ? ' class="last"' : '') . '>' . linkify($tweet->text) . '<span class="date">' . $date . '</span>' . '</li>' : call_user_func($step_callback, $i, linkify($tweet->text), $date); } } $output .= $after === false ? '</ul></div>' : $after; return $output; }
function post_share_shortcode2() { $memcache_obj = new Memcache(); $memcache_obj->connect('localhost', 11211) or die("Could not connect to Memcached server!"); $cacheTime = 60 * 60 * 12; // 12 hours $t1 = microtime(1); $pinterest_pins_count = $memcache_obj->get('pinterest_pins_count'); if (false === $pinterest_pins_count) { $pinterest_pins_count = pinterest_get_pins(get_permalink()); $memcache_obj->set('pinterest_pins_count', $pinterest_pins_count, 0, $cacheTime); } $twitter_tweets_count = $memcache_obj->get('$twitter_tweets_count'); if (false === $twitter_tweets_count) { $twitter_tweets_count = twitter_get_tweets(get_permalink()); $memcache_obj->set('$twitter_tweets_count', $twitter_tweets_count, 0, $cacheTime); } $google_plus_likes = $memcache_obj->get('google_plus_likes'); if (false === $google_plus_likes) { $google_plus_likes = google_get_plusones(get_permalink()); $memcache_obj->set('google_plus_likes', $google_plus_likes, 0, $cacheTime); } $t1 = microtime(1) - $t1; echo '<!-- optimization time: ' . $t1 . ' -->'; if (is_single()) { ?> <div class="social-sharer-bottom"> <!-- Article Views Counter --> <div class="share-views"><div class="share-text"><div class="dashicons dashicons-views"><img class="yuzo-views-icon" src="/wp-content/themes/news-pro/images/share-views.png" alt="views"></div><div class="longtext"> Views </div><?php echo do_shortcode('[yuzo_views]'); ?> </div></div> <!-- Facebook Like --> <div class="facebook-button"> <div class="fb-like" data-href="<?php the_permalink(); ?> " data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div></div> <!-- Twitter Share --> <a style='text-decoration:none;' type="icon_link" onClick="window.open('http://twitter.com/home?status=<?php print urlencode(the_title()); ?> +<?php print urlencode(get_permalink()); ?> ','sharer','toolbar=0,status=0,width=580,height=325');" href="javascript: void(0)"><div class="share-twitter"> <div class="share-text-twitter"><img class="tweet-icon" src="/wp-content/themes/news-pro/images/tweeter.png" alt="tweet"><div class="longtext"> Tweet</div> <?php echo $twitter_tweets_count; ?> </div></div></a> <!-- Google Plus Share --> <a style='text-decoration:none;' type="icon_link" onClick="window.open('https://plus.google.com/share?url=<?php print urlencode(get_permalink()); ?> ','sharer','toolbar=0,status=0,width=580,height=325');" href="javascript: void(0)"><div class="share-google"><div class="share-text-google"><img class="gplus-icon" src="/wp-content/themes/news-pro/images/gplus.png" alt="gplus"><div class="longtext-google"> Share </div><?php echo $google_plus_likes; ?> </div></div></a> <!-- Pinterest Share --> <a style='text-decoration:none;' type="icon_link" onClick="window.open('//www.pinterest.com/pin/create/button/?url=<?php print urlencode(get_permalink()); ?> &media=<?php $thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium'); $url = $thumb['0']; echo $url; ?> &description=<?php print urlencode(the_title()); ?> ','sharer','toolbar=0,status=0,width=580,height=325');" href="javascript: void(0)"><div class="share-pinterest"><div class="share-text"><div class="dashicons dashicons-pinterest"><div class="entry-socials"><img class="pin-icon" src="/wp-content/themes/news-pro/images/pinterest.png" alt="pinit"></div></div><div class="longtext"> Pin it</div> <?php echo $pinterest_pins_count; ?> </div></div></a> </div> <?php } }
function get_cache() { if (file_exists('twitter.txt')) { $file = file_get_contents('twitter.txt'); if ($file !== false && $file !== '') { $data = unserialize($file); $time = time(); if ($data['time'] + $data['expire'] > $time) { return $data['data']; } file_put_contents('twitter.txt', ''); } } } function set_cache($arr, $expire) { if (file_exists('twitter.txt')) { $file = file_get_contents('twitter.txt'); $data = unserialize($file); } else { $data = array(); } $data['time'] = time(); $data['expire'] = $expire; $data['data'] = $arr; $file = serialize($data); file_put_contents('twitter.txt', $file); } if (isset($_GET['user'])) { twitter_get_tweets($_GET['user']); }