function widget($args, $instance) { global $cs_theme_option; extract($args, EXTR_SKIP); $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); $username = $instance['username']; $numoftweets = $instance['numoftweets']; if ($numoftweets == '') { $numoftweets = 2; } echo $before_widget; // WIDGET display CODE Start if (!empty($title) && $title != ' ') { echo $before_title . $title . $after_title; } if (strlen($username) > 1) { $text = ''; $return = ''; $cacheTime = 10000; $transName = 'latest-tweets'; require_once "twitteroauth/twitteroauth.php"; //Path to twitteroauth library $consumerkey = $cs_theme_option['consumer_key']; $consumersecret = $cs_theme_option['consumer_secret']; $accesstoken = $cs_theme_option['access_token']; $accesstokensecret = $cs_theme_option['access_token_secret']; $connection = new TwitterOAuth($consumerkey, $consumersecret, $accesstoken, $accesstokensecret); $tweets = $connection->get("https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" . $username . "&count=" . $numoftweets); if (!is_wp_error($tweets) and is_array($tweets)) { set_transient($transName, $tweets, 60 * $cacheTime); } else { $tweets = get_transient('latest-tweets'); } if (!is_wp_error($tweets) and is_array($tweets)) { cs_enqueue_swiper_script(); $rand_id = rand(5, 300); ?> <?php $return .= "<div class='swiper-container swiper-container" . $rand_id . "'><div class='swiper-wrapper'>\r\n\t\t\t\t\t\t\t"; foreach ($tweets as $tweet) { $text = $tweet->{'text'}; foreach ($tweet->{'user'} as $type => $userentity) { if ($type == 'profile_image_url') { $profile_image_url = $userentity; } else { if ($type == 'screen_name') { $screen_name = '<a href="https://twitter.com/' . $userentity . '" target="_blank" class="colrhover" title="' . $userentity . '">@' . $userentity . '</a>'; } } } foreach ($tweet->{'entities'} as $type => $entity) { if ($type == 'urls') { foreach ($entity as $j => $url) { $display_url = '<a href="' . $url->{'url'} . '" target="_blank" title="' . $url->{'expanded_url'} . '">' . $url->{'display_url'} . '</a>'; $update_with = 'Read more at ' . $display_url; $text = str_replace('Read more at ' . $url->{'url'}, '', $text); $text = str_replace($url->{'url'}, '', $text); } } else { if ($type == 'hashtags') { foreach ($entity as $j => $hashtag) { $update_with = '<a href="https://twitter.com/search?q=%23' . $hashtag->{'text'} . '&src=hash" target="_blank" title="' . $hashtag->{'text'} . '">#' . $hashtag->{'text'} . '</a>'; $text = str_replace('#' . $hashtag->{'text'}, $update_with, $text); } } else { if ($type == 'user_mentions') { foreach ($entity as $j => $user) { $update_with = '<a href="https://twitter.com/' . $user->{'screen_name'} . '" target="_blank" title="' . $user->{'name'} . '">@' . $user->{'screen_name'} . '</a>'; $text = str_replace('@' . $user->{'screen_name'}, $update_with, $text); } } } } } $large_ts = time(); $n = $large_ts - strtotime($tweet->{'created_at'}); if ($n < 60) { $posted = sprintf(__('%d seconds ago', 'WeStand'), $n); } elseif ($n < 60 * 60) { $minutes = round($n / 60); $posted = sprintf(_n('About a Minute Ago', '@%d Minutes Ago', $minutes, 'WeStand'), $minutes); } elseif ($n < 60 * 60 * 16) { $hours = round($n / (60 * 60)); $posted = sprintf(_n('About an Hour Ago', '@%d Hours Ago', $hours, 'WeStand'), $hours); } elseif ($n < 60 * 60 * 24) { $hours = round($n / (60 * 60)); $posted = sprintf(_n('About an Hour Ago', '@%d Hours Ago', $hours, 'WeStand'), $hours); } elseif ($n < 60 * 60 * 24 * 6.5) { $days = round($n / (60 * 60 * 24)); $posted = sprintf(_n('About a Day Ago', '@%d Days Ago', $days, 'WeStand'), $days); } elseif ($n < 60 * 60 * 24 * 7 * 3.5) { $weeks = round($n / (60 * 60 * 24 * 7)); $posted = sprintf(_n('About a Week Ago', '%d Weeks Ago', $weeks, 'WeStand'), $weeks); } elseif ($n < 60 * 60 * 24 * 7 * 4 * 11.5) { $months = round($n / (60 * 60 * 24 * 7 * 4)); $posted = sprintf(_n('About a Month Ago', '%d Months Ago', $months, 'WeStand'), $months); } elseif ($n >= 60 * 60 * 24 * 7 * 4 * 12) { $years = round($n / (60 * 60 * 24 * 7 * 52)); $posted = sprintf(_n('About a year Ago', '%d years Ago', $years, 'WeStand'), $years); } $return .= "<div class='swiper-slide'><div class='tweet'><h5><i class='fa fa-twitter'></i></h5>"; $return .= "<h4>" . $text . "</h4>"; $return .= "<p><a href='https://twitter.com/" . $username . "'>@" . $username . "</a></p>"; $return .= "<ul class='tweet-panel'>"; $return .= "<li>" . $posted . "</li>"; $return .= "</ul>"; $return .= "</div></div>"; } $return .= "</div></div>"; echo $return; ?> <script type="text/javascript"> jQuery(document).ready(function($) { twitter_swiper_carousal(<?php echo $rand_id; ?> ); }); </script> <?php } else { if (isset($tweets->errors[0]) && $tweets->errors[0] != "") { echo '<span class="bad_authentication">' . $tweets->errors[0]->message . ". Please enter valid Twitter API Keys </span>"; } else { echo '<span class="bad_authentication">'; fnc_no_result_found(false); echo '</span>'; } } } else { echo '<span class="bad_authentication">'; fnc_no_result_found(false); echo '</span>'; } echo $after_widget; // WIDGET display CODE End }
" tabindex="-1" role="dialog" aria-hidden="true"></div> <?php } ?> <?php wp_link_pages(array('before' => '<div class="page-links"><span class="page-links-title">' . __('Pages:', 'WeStand') . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>')); ?> <!-- Blog Post End --> <?php } ?> <!-- Blog End --> <?php } else { if ($cs_node->cs_blog_view == "blog-carousel-view") { cs_enqueue_swiper_script(); ?> <div class="device"> <div class="swiper-container"> <div class="swiper-wrapper"> <?php $width = 406; $height = 202; $count_carousal = 0; $no_image = 'featured-slide '; while ($custom_query->have_posts()) { $custom_query->the_post(); $post_xml = get_post_meta($post->ID, "post", true);