Example #1
0
/**
 * Sanitize and validate form input. Accepts an array, return a sanitized array.
 */
function kebo_twitter_options_validate($input)
{
    $options = kebo_get_twitter_options();
    $output = array();
    // Purge currently cached data
    // A tool to allow users to forcefully reset the cache.
    delete_transient('kebo_twitter_feed_' . get_current_blog_id());
    // Refresh Tweets when saving settings
    kebo_twitter_get_tweets();
    if (isset($input['kebo_twitter_cache_timer']) && !empty($input['kebo_twitter_cache_timer'])) {
        if (is_numeric($input['kebo_twitter_cache_timer'])) {
            if (1 <= $input['kebo_twitter_cache_timer'] && 30 >= $input['kebo_twitter_cache_timer']) {
                $output['kebo_twitter_cache_timer'] = intval($input['kebo_twitter_cache_timer']);
            } else {
                add_settings_error('kebo_twitter_messages', esc_attr('settings_updated'), __('Value supplied is outside of acceptable range 1-30.', 'kebo_twitter'), 'error');
            }
        } else {
            add_settings_error('kebo_twitter_messages', esc_attr('settings_updated'), __('Value supplied is not a valid number.', 'kebo_twitter'), 'error');
        }
    }
    if (isset($input['kebo_twitter_nofollow_links']) && 'nofollow' == $input['kebo_twitter_nofollow_links']) {
        $output['kebo_twitter_nofollow_links'] = $input['kebo_twitter_nofollow_links'];
    } else {
        $output['kebo_twitter_nofollow_links'] = false;
    }
    return apply_filters('kebo_twitter_options_validate', $output, $options);
}
						<div class="hidden">
							
						</div>
						<div class="resp-small-hide">
							<a id="more_posts" href="#" class="primary-button">Load More</a>							
						</div>
					</div>
				</div>
				<div class="col-4 side-content resp-small-hide">
					<div class="side-block">
						<h3>Twitter <span class="follow"><a href="https://twitter.com/intent/follow?screen_name=superdry" data-show-count="false">Follow us </a><i class="icon-circle-plus"></i></span></h3>
						
						<div class="tweets">
							<ul>
								<?php 
$tweets = kebo_twitter_get_tweets();
?>

								<?php 
$i = 0;
?>

								<?php 
if (isset($tweets->{0}->created_at)) {
    ?>

								    <?php 
    foreach ($tweets as $tweet) {
        ?>
								    
								        <li>
Example #3
0
 function widget($args, $instance)
 {
     extract($args, EXTR_SKIP);
     // Enqueue Style Sheet
     wp_enqueue_style('kebo-twitter-plugin');
     wp_enqueue_script('jquery');
     if (!true == self::$printed_intent_js) {
         self::$printed_intent_js = true;
         add_action('wp_footer', 'kebo_twitter_intent_script', 90);
     }
     if (2 == $instance['style']) {
         self::$slider_ids[] = $widget_id;
         wp_enqueue_script('responsive-slides');
         add_action('wp_footer', 'kebo_twitter_slider_script', 90);
     }
     /*
      * Get tweets from transient and refresh if its expired.
      */
     if (false === ($tweets = kebo_twitter_get_tweets())) {
         return;
     }
     // Ensure not undefined for updates
     if (!isset($instance['conversations'])) {
         $instance['conversations'] = false;
     }
     // Ensure not undefined for updates
     if (!isset($instance['media'])) {
         $instance['media'] = false;
     }
     // Ensure not undefined for updates
     if (!isset($instance['media_visible'])) {
         $instance['media_visible'] = false;
     }
     // Ensure not undefined for updates
     if (!isset($instance['intent'])) {
         $instance['intent'] = true;
     }
     // Ensure not undefined for updates
     if (!isset($instance['display'])) {
         $instance['display'] = 'tweets';
     }
     // Output opening Widget HTML
     echo $before_widget;
     // If Title is set, output it with Widget title opening and closing HTML
     if (isset($instance['title']) && !empty($instance['title'])) {
         echo $before_title;
         echo esc_html($instance['title']);
         echo $after_title;
     }
     /*
      * Check which Style (Slider/List) has been chosen and use correct view file, default List.
      */
     if (2 == $instance['style']) {
         if ('' != locate_template('views/kebo-twitter-slider.php')) {
             // yep, load the page template
             get_template_part('views/kebo-twitter-slider');
         } else {
             require KEBO_TWITTER_PLUGIN_PATH . 'views/slider.php';
         }
     } else {
         if ('' != locate_template('views/kebo-twitter-list.php')) {
             // yep, load the page template
             get_template_part('views/kebo-twitter-list');
         } else {
             require KEBO_TWITTER_PLUGIN_PATH . 'views/list.php';
         }
     }
     // Output closing Widget HTML
     echo $after_widget;
 }
Example #4
0
/**
 * Renders the Twitter Feed Options page.
 */
function kebo_twitter_menu_render()
{
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    // Collect returned OAuth2 credentials on callback and save in a transient.
    if (isset($_GET['service']) && isset($_GET['token'])) {
        $data = array('service' => $_GET['service'], 'token' => $_GET['token'], 'secret' => $_GET['secret'], 'account' => $_GET['account'], 'userid' => $_GET['userid'], 'account_link' => $_GET['account_link']);
        // Store Website OAuth Credentials in transient, use extra long expiry as Twitter does not currently set an expiry time.
        update_option('kebo_twitter_connection', $data);
        // On Successful Connection, Fetch Tweets.
        kebo_twitter_get_tweets();
        // Let user know we successfully received and stored their credentials.
        // TODO: Add error checking.
        add_settings_error('kebo-twitter', esc_attr('settings_updated'), sprintf(__('Connection established with Twitter. You can now display your Twitter Feed on your website using a <a href="%s">Widget</a>.', 'kebo_twitter'), admin_url('widgets.php')), 'updated');
    }
    // Check for reset request, if set delete transient which will break the connection to Twitter, so the credentials will be lost.
    if (isset($_GET['reset']) && 'true' == $_GET['reset']) {
        if ('true' == $_GET['reset']) {
            update_option('kebo_twitter_connection', false);
            add_settings_error('kebo-twitter', esc_attr('settings_updated'), __('Connection reset to Twitter.', 'kebo_twitter'), 'updated');
        }
    }
    // Enqueue Thickbox
    add_thickbox();
    ?>
    <div class="wrap">
        
        <?php 
    screen_icon('options-general');
    ?>
        <h2><?php 
    _e('Kebo Twitter Feed', 'kebo_twitter');
    ?>
</h2>
            <?php 
    settings_errors('kebo-twitter');
    ?>

        <form method="post" action="options.php">
            <?php 
    settings_fields('kebo_twitter_options');
    do_settings_sections('kebo-twitter');
    submit_button();
    ?>
        </form>
        
        <?php 
    $errors = get_option('kebo_twitter_errors');
    ?>
        <?php 
    if (!empty($errors)) {
        ?>
        
        <div class="box">
            
            <h3><?php 
        _e('Twitter API - Error Log', 'kebo_twitter');
        ?>
</h3>
            
            <p><?php 
        _e('Any errors received while connecting to Twitter will be displayed below.', 'kebo_twitter');
        ?>
</p>

            <ul class="error-log">

                <li class="header"><span class="date"><?php 
        _e('Date', 'kebo_twitter');
        ?>
</span> <span class="ref"><?php 
        _e('Code', 'kebo_twitter');
        ?>
</span> <span class="message"><?php 
        _e('Message', 'kebo_twitter');
        ?>
</span></li>

                <?php 
        foreach ($errors as $error) {
            ?>
                    <li><span class="date"><?php 
            echo date('H:i:s', $error['date']);
            ?>
 - <?php 
            echo date_i18n(get_option('date_format'), $error['date']);
            ?>
</span> <span class="ref"><?php 
            echo $error['code'];
            ?>
</span> <span class="message"><?php 
            echo $error['message'];
            ?>
</span></li>
                <?php 
        }
        ?>

            </ul>
        
        </div>
        
        <div class="box">
            
            <h3><?php 
        _e('Twitter API - Error Key', 'kebo_twitter');
        ?>
</h3>
            
            <p><?php 
        _e('Below is a key of the most common types of error returned by Twitter and a short description.', 'kebo_twitter');
        ?>
</p>

            <?php 
        $options = kebo_get_twitter_options();
        ?>
            <?php 
        $requests = 60 / $options['kebo_twitter_cache_timer'];
        ?>

            <p><strong>Error 32: Could not authenticate you</strong> - <?php 
        _e('There is a problem with your connection to Twitter, please disconnect and re-connect to the service.', 'kebo_twitter');
        ?>
</p>
            <p><strong>Error 64: Your account is suspended and is not permitted to access this feature</strong> - <?php 
        _e('Twitter has blocked our access to your account.', 'kebo_twitter');
        ?>
</p>
            <p><strong>Error 88: Rate limit exceeded</strong> - <?php 
        printf(__("Your account has hit Twitter's limit of 180 requests per hour, we are making %d of those requests. You can edit the 'Feed Refresh Rate' in the options above to change this.", 'kebo_twitter'), $requests);
        ?>
</p>
            <p><strong>Error 89: Invalid or expired token</strong> - <?php 
        _e('There is a problem with your connection to Twitter, please disconnect and re-connect to the service.', 'kebo_twitter');
        ?>
</p>
            <p><strong>Error 130: Over capacity</strong> - <?php 
        _e('Twitter is currently too busy to reply.', 'kebo_twitter');
        ?>
</p>
        
        </div>
        
        <?php 
    }
    ?>
        
        <a href="#TB_inline?width=600&height=550&inlineId=kebo-debug-modal" class="thickbox kdebug-button"><?php 
    _e('Debug Tweet Data', 'kebo_twitter');
    ?>
</a>

        <div id="kebo-debug-modal" style="display:none;">
            
            <h2><?php 
    _e('Debug - Cached Tweet Data', 'kebo_twitter');
    ?>
 <a class="kselect" href="#"><?php 
    _e('Select All', 'kebo_twitter');
    ?>
</a> </h2>
            
            <img class="kloading" src="<?php 
    echo admin_url('images/wpspin_light.gif');
    ?>
">
            
            <textarea class="kdebug-content" readonly="readonly">
                
            </textarea>
            
        </div>
        
        <script type="text/javascript">
            
            jQuery( document ).ready( function() {
                
                jQuery( '.kdebug-button' ).one( 'click', function() {
                    
                    var data = {
                        action: 'kebo_twitter_fetch_tweet_data',
                        nonce: '<?php 
    echo wp_create_nonce('kebo_twitter_fetch_tweet_data');
    ?>
'
                    };

                    // do AJAX request
                    jQuery.post( ajaxurl, data, function( response ) {

                        response = jQuery.parseJSON( response );

                        if ( true === response.success ) {

                            jQuery('#TB_ajaxContent .kloading').hide();
                            jQuery('.kdebug-content').text( response.data );

                        } else {

                            jQuery('#TB_ajaxContent .kloading').hide();
                            jQuery('.kdebug-content').text( 'Sorry, no Tweet data was found.' );

                        }

                    });
                    
                });
                
                jQuery( '.kselect' ).on( 'click', function(e) {
                    e.preventDefault();
                    jQuery('.kdebug-content').select();
                });
                
            });
        
        </script>
        
        <div class="kapi-status">
            
            <h4><?php 
    _e('API Status', 'kebo_twitter');
    ?>
</h4>
            
            <div>
                <span title="auth.kebopowered.com">23.239.13.127</span>
                <img class="kloading" src="<?php 
    echo admin_url('images/wpspin_light.gif');
    ?>
" title="Testing API Connection">
                <span class="ksuccess" title="<?php 
    _e('Your site can successfully connect to the Kebo API.', 'kebo_twitter');
    ?>
"><?php 
    _e('Success', 'kebo_twitter');
    ?>
</span>
                <span class="kerror" title="<?php 
    _e('Your site failed to connect to the Kebo API.', 'kebo_twitter');
    ?>
"><?php 
    _e('Error', 'kebo_twitter');
    ?>
</span>
                <?php 
    $url = 'http://wordpress.org/support/plugin/kebo-twitter-feed';
    ?>
                <p class="kmessage"><?php 
    printf(__('Your site cannot connect to the Kebo API, this will prevent the plugin from functioning as expected. You are welcome to ask for help on the <a href="%s" target="_blank">support forum</a>.', 'kebo_twitter'), esc_url($url));
    ?>
</p>
            </div>
            
        </div>
        
        <script type="text/javascript">
            
            jQuery( document ).ready(function() {
                
                var data = {
                    action: 'kebo_twitter_api_status',
                    nonce: '<?php 
    echo wp_create_nonce('kebo_twitter_api_status');
    ?>
'
                };

                // do AJAX request
                jQuery.post( ajaxurl, data, function( response ) {

                    response = jQuery.parseJSON( response );

                    if ( true === response.success ) {
                        
                        jQuery('.kapi-status').addClass( 'ksuccess' );
                        jQuery('.kapi-status .kloading').hide();
                        jQuery('.kapi-status .ksuccess').show();
                        jQuery('.kapi-status .kerror').hide();
                        
                    } else {
                        
                        jQuery('.kapi-status').addClass( 'kerror' );
                        jQuery('.kapi-status .kloading').hide();
                        jQuery('.kapi-status .kerror').show();
                        jQuery('.kapi-status .ksuccess').hide();
                        jQuery('.kapi-status .kmessage').show();
                        
                    }

                });
                
            });
            
        </script>
        
    </div><!-- .wrap -->

    <?php 
}
Example #5
0
 function get_tweets()
 {
     $tweets = kebo_twitter_get_tweets();
     return $tweets;
 }
Example #6
0
 static function handle_shortcode($atts)
 {
     // Sort Options
     extract(shortcode_atts(array('title' => null, 'display' => 'tweets', 'style' => 'list', 'theme' => 'light', 'count' => 5, 'avatar' => 'off', 'offset' => false, 'conversations' => false, 'media' => false, 'media_visible' => false, 'intent' => true), $atts));
     // Check if a connection to Twitter exists.
     $twitter_data = get_option('kebo_twitter_connection');
     if (empty($twitter_data)) {
         return false;
     }
     // Enqueue Style Sheet
     wp_enqueue_style('kebo-twitter-plugin');
     wp_enqueue_script('jquery');
     $widget_id = 'kebo_twitter_feed_shortcode-' . self::$shortcode_id;
     self::$shortcode_id++;
     if (!true == Kebo_Twitter_Feed_Widget::$printed_intent_js) {
         Kebo_Twitter_Feed_Widget::$printed_intent_js = true;
         add_action('wp_footer', 'kebo_twitter_intent_script', 90);
     }
     if ('slider' == $style) {
         Kebo_Twitter_Feed_Widget::$slider_ids[] = $widget_id;
         wp_enqueue_script('responsive-slides');
         add_action('wp_footer', 'kebo_twitter_slider_script', 90);
     }
     // Add defaults.
     $instance['title'] = $title;
     $instance['count'] = $count;
     $instance['theme'] = $theme;
     $instance['conversations'] = $conversations;
     $instance['media'] = $media;
     $instance['media_visible'] = $media_visible;
     $instance['display'] = $display;
     $instance['intent'] = $intent;
     if ('on' == $avatar) {
         $instance['avatar'] = 'avatar';
     } else {
         $instance['avatar'] = 'off';
     }
     if ('slider' == $style) {
         $instance['style'] = 2;
     } else {
         $instance['style'] = 1;
     }
     // Begin Output Buffering
     ob_start();
     // Shortcode Container
     echo '<div id="' . $widget_id . '" class="kcontainer">';
     if (isset($instance['title'])) {
         echo '<h2 class="ktweets-title">' . esc_html($instance['title']) . '</h2>';
     }
     /*
      * Get tweets from transient and refresh if its expired.
      */
     if (false === ($tweets = kebo_twitter_get_tweets())) {
         return false;
     }
     // If an offset is set, slice early items off the array
     if (!false == $offset && is_numeric($offset)) {
         $tweets = array_slice($tweets, $offset);
     }
     /*
      * Check which Style (Slider/List) has been chosen and use correct view file, default List.
      */
     if (2 == $instance['style']) {
         if ('' != locate_template('views/kebo-twitter-slider.php')) {
             // yep, load the page template
             get_template_part('views/kebo-twitter-slider');
         } else {
             require KEBO_TWITTER_PLUGIN_PATH . 'views/slider.php';
         }
     } else {
         if ('' != locate_template('views/kebo-twitter-list.php')) {
             // yep, load the page template
             get_template_part('views/kebo-twitter-list');
         } else {
             require KEBO_TWITTER_PLUGIN_PATH . 'views/list.php';
         }
     }
     // End of Shortcode Container
     echo '</div><!-- .kcontainer -->';
     // End Output Buffering and Clear Buffer
     $output = ob_get_contents();
     ob_end_clean();
     return $output;
 }