/* * HTML output for the Horizontal Slider style of widget. */ ?> <?php // Prepare Classes $classes[] = 'kebo-tweets'; $classes[] = 'slider'; $classes[] = $widget_id; $classes[] = $instance['theme']; if (is_rtl()) { $classes[] = 'rtl'; } $options = kebo_get_twitter_options(); $allowed_html = array('a' => array('href' => true, 'title' => true, 'target' => true, 'rel' => 'nofollow' == $options['kebo_twitter_nofollow_links'] ? true : false)); ?> <ul class="<?php echo implode(' ', $classes); ?> " data-timeout="10000" data-speed="1000" data-animation="fade"> <?php $i = 0; ?> <?php $format = get_option('date_format'); $corruption = 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 }
/** * 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); }
function kebo_twitter_get_display_url($url) { $options = kebo_get_twitter_options(); $display_url = $url->display_url; return $display_url; }