public function render($factory) { $twitterApi = QodeStockholmTwitterApi::getInstance(); $message = ''; if (!empty($_GET['oauth_token']) && !empty($_GET['oauth_verifier'])) { if (!empty($_GET['oauth_token'])) { update_option($twitterApi::AUTHORIZE_TOKEN_FIELD, $_GET['oauth_token']); } if (!empty($_GET['oauth_verifier'])) { update_option($twitterApi::AUTHORIZE_VERIFIER_FIELD, $_GET['oauth_verifier']); } $responseObj = $twitterApi->obtainAccessToken(); if ($responseObj->status) { $message = esc_html__('You have successfully connected with your Twitter account. If you have any issues fetching data from Twitter try reconnecting.', 'qode'); } else { $message = $responseObj->message; } } $buttonText = $twitterApi->hasUserConnected() ? esc_html__('Re-connect with Twitter', 'qode') : esc_html__('Connect with Twitter', 'qode'); ?> <?php if ($message !== '') { ?> <div class="alert alert-success" style="margin-top: 20px;"> <span><?php echo esc_html($message); ?> </span> </div> <?php } ?> <div class="qodef-page-form-section" id="qodef_enable_social_share"> <div class="qodef-field-desc"> <h4><?php esc_html_e('Connect with Twitter', 'qode'); ?> </h4> <p><?php esc_html_e('Connecting with Twitter will enable you to show your latest tweets on your site', 'qode'); ?> </p> </div> <!-- close div.qodef-field-desc --> <div class="qodef-section-content"> <div class="container-fluid"> <div class="row"> <div class="col-lg-12"> <a id="qodef-tw-request-token-btn" class="btn btn-primary" href="#"><?php echo esc_html($buttonText); ?> </a> <input type="hidden" data-name="current-page-url" value="<?php echo esc_url($twitterApi->buildCurrentPageURI()); ?> "/> </div> </div> </div> </div> <!-- close div.qodef-section-content --> </div> <?php }
public function widget($args, $instance) { extract($instance); print $args['before_widget']; if (!empty($title)) { print $args['before_title'] . $title . $args['after_title']; } $user_id = !empty($user_id) ? $user_id : ''; $count = !empty($count) ? $count : ''; $transient_time = !empty($transient_time) ? $transient_time : 0; $twitter_api = QodeStockholmTwitterApi::getInstance(); if ($twitter_api->hasUserConnected()) { $response = $twitter_api->fetchTweets($user_id, $count, array('transient_time' => $transient_time, 'transient_id' => 'qode_twitter_' . $args['widget_id'])); if ($response->status) { if (is_array($response->data) && count($response->data)) { ?> <ul class="qode_twitter_widget"> <?php foreach ($response->data as $tweet) { ?> <li> <div class="tweet_icon_holder"> <span class="social_twitter"></span> </div> <div class="tweet_content_holder"> <div class="qode_tweet_text"> <?php echo wp_kses_post($twitter_api->getHelper()->getTweetText($tweet)); ?> </div> <?php if ($show_tweet_time == 'yes') { ?> <div class="qode_tweet_time"> <a target="_blank" href="<?php echo esc_url($twitter_api->getHelper()->getTweetURL($tweet)); ?> "> <?php echo wp_kses_post($twitter_api->getHelper()->getTweetTime($tweet)); ?> </a> </div> <?php } ?> </div> </li> <?php } ?> </ul> <?php } } else { echo esc_html($response->message); } } else { esc_html_e('It seams that you haven\'t connected with your Twitter account', 'select-twitter-feed'); } print $args['after_widget']; }
/** * Wrapper function for obtaining twitter request token. * Hooks to wp_ajax_qode_twitter_obtain_request_token ajax action * * @see QodeStockholmTwitterApi::obtainRequestToken() */ function qode_hook_twitter_request_ajax() { QodeStockholmTwitterApi::getInstance()->obtainRequestToken(); }
/** * Renders shortcodes HTML * * @param $atts array of shortcode params * @param $content string shortcode content * @return string */ public function render($atts, $content = null) { $args = array("user_id" => "", "count" => "", "show_tweet_time" => "no", "transient_time" => "", "feed_id" => "", "show_navigation" => "", "show_arrows" => "", "auto_rotate_slides" => "", "animation_type" => "", "animation_speed" => ""); extract(shortcode_atts($args, $atts)); $shortcode_id = $html = ""; $user_id = !empty($user_id) ? $user_id : ''; $count = !empty($count) ? $count : ''; $transient_time = !empty($transient_time) ? $transient_time : 0; $feed_id = !empty($feed_id) ? $feed_id : rand(); $twitter_api = QodeStockholmTwitterApi::getInstance(); if ($twitter_api->hasUserConnected()) { $response = $twitter_api->fetchTweets($user_id, $count, array('transient_time' => $transient_time, 'transient_id' => 'qode_twitter_' . $feed_id)); if ($response->status) { if (is_array($response->data) && count($response->data)) { ?> <div class="qode_twitter_shortcode twitter_carousel" data-show-navigation="<?php echo esc_attr($show_navigation); ?> " data-show-arrows="<?php echo esc_attr($show_arrows); ?> " data-animation-type="<?php echo esc_attr($animation_type); ?> " data-animation-speed="<?php echo esc_attr($animation_speed); ?> " data-auto-rotate-slides="<?php echo esc_attr($auto_rotate_slides); ?> "> <ul class="slides"> <?php foreach ($response->data as $tweet) { ?> <li> <div class="grid_section"><div class="section_inner"> <div class="qode_twitter_holder"> <div class="tweet_icon_holder"> <span class="social_twitter"></span> </div> <div class="tweet_content_holder"> <div class="qode_tweet_text_holder"> <div class="qode_tweet_text"> <?php echo wp_kses_post($twitter_api->getHelper()->getTweetText($tweet)); ?> </div> <?php if ($show_tweet_time == 'yes') { ?> <div class="qode_tweet_time"> <a target="_blank" href="<?php echo esc_url($twitter_api->getHelper()->getTweetURL($tweet)); ?> "> <?php echo wp_kses_post($twitter_api->getHelper()->getTweetTime($tweet)); ?> </a> </div> <?php } ?> </div> <div class="qode_tweet_author"> –<?php echo esc_html($twitter_api->getHelper()->getTweetUserName($tweet)); ?> (<a target="_blank" href="<?php echo esc_url('https://twitter.com/' . $twitter_api->getHelper()->getTweetUserScreenName($tweet)); ?> ">@<?php echo esc_html($twitter_api->getHelper()->getTweetUserScreenName($tweet)); ?> </a>) </div> </div> </div> </div></div> </li> <?php } ?> </ul> </div> <?php } } else { echo esc_html($response->message); } } else { esc_html_e('It seams that you haven\'t connected with your Twitter account', 'select-twitter-feed'); } return $html; }