diff --git a/src/classes/class-wpt-latest-tweets-widget.php b/src/classes/class-wpt-latest-tweets-widget.php deleted file mode 100644 index 0f6fe93..0000000 --- a/src/classes/class-wpt-latest-tweets-widget.php +++ /dev/null @@ -1,186 +0,0 @@ -defaults = array( - 'title' => '', - 'twitter_id' => '', - 'twitter_num' => '', - 'twitter_duration' => '', - 'twitter_hide_replies' => 0, - 'twitter_include_rts' => 0, - 'link_links' => '', - 'link_mentions' => '', - 'link_hashtags' => '', - 'intents' => '', - 'source' => '', - 'show_images' => '', - 'hide_header' => 0, - ); - - $widget_ops = array( - 'classname' => 'wpt-latest-tweets', - 'description' => __( 'Display a list of your latest tweets.', 'wp-to-twitter' ), - 'customize_selective_refresh' => true, - ); - - $control_ops = array( - 'id_base' => 'wpt-latest-tweets', - 'width' => 200, - 'height' => 250, - ); - parent::__construct( 'wpt-latest-tweets', __( 'XPoster - Latest Tweets', 'wp-to-twitter' ), $widget_ops, $control_ops ); - } - - /** - * Echo the widget content. - * - * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. - * @param array $instance The settings for the particular instance of the widget. - */ - function widget( $args, $instance ) { - $before_widget = $args['before_widget']; - $after_widget = $args['after_widget']; - $before_title = $args['before_title']; - $after_title = $args['after_title']; - - wp_enqueue_script( 'twitter-platform', 'https://platform.twitter.com/widgets.js' ); - /** Merge with defaults */ - $instance = wp_parse_args( (array) $instance, $this->defaults ); - - echo $before_widget; - if ( $instance['title'] ) { - echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title; - } - echo wpt_twitter_feed( $instance ); - echo $after_widget; - } - - /** - * Update a particular instance. - * - * This function should check that $new_instance is set correctly. - * The newly calculated value of $instance should be returned. - * If "false" is returned, the instance won't be saved/updated. - * - * @since 0.1 - * - * @param array $new_instance New settings for this instance as input by the user via form(). - * @param array $old_instance Old settings for this instance. - * - * @return array Settings to save or bool false to cancel saving - */ - function update( $new_instance, $old_instance ) { - // Force the cache to refresh. - update_option( 'wpt_delete_cache', 'true' ); - $new_instance['title'] = strip_tags( $new_instance['title'] ); - - return $new_instance; - } - - /** - * Echo the settings update form. - * - * @param array $instance Current settings. - */ - function form( $instance ) { - - // Merge with defaults. - $instance = wp_parse_args( (array) $instance, $this->defaults ); - ?> -

- - -

- -

- - -

- -

- /> - -

- -

- - -

- -

- /> - -

- -

- /> - -

- -

- /> - -

- -

- /> - -

- -

- /> - -

- -

- /> - -

- -

- /> - -

- -

- /> - -

-

- - -

- defaults = array( - 'title' => '', - 'twitter_num' => '', - 'search' => '', - 'result_type' => 'recent', // mixed, recent, popular. - 'geocode' => '', // 37.777,-127.98,2km. - 'link_links' => '', - 'link_mentions' => '', - 'show_images' => '', - 'link_hashtags' => '', - 'intents' => '', - 'source' => '', - ); - - $widget_ops = array( - 'classname' => 'wpt-search-tweets', - 'description' => __( 'Display a list of tweets returned by a search.', 'wp-to-twitter' ), - 'customize_selective_refresh' => true, - ); - - $control_ops = array( - 'id_base' => 'wpt-search-tweets', - 'width' => 200, - 'height' => 250, - ); - parent::__construct( 'wpt-search-tweets', __( 'XPoster - Searched Tweets', 'wp-to-twitter' ), $widget_ops, $control_ops ); - } - - /** - * Echo the widget content. - * - * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. - * @param array $instance The settings for the particular instance of the widget. - */ - function widget( $args, $instance ) { - $before_widget = $args['before_widget']; - $after_widget = $args['after_widget']; - $before_title = $args['before_title']; - $after_title = $args['after_title']; - - wp_enqueue_script( 'twitter-platform', 'https://platform.twitter.com/widgets.js' ); - // Merge with defaults. - $instance = wp_parse_args( (array) $instance, $this->defaults ); - echo $before_widget; - if ( $instance['title'] ) { - echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title; - } - echo wpt_twitter_feed( $instance ); - echo $after_widget; - } - - /** - * Update a particular instance. - * - * This function should check that $new_instance is set correctly. - * The newly calculated value of $instance should be returned. - * If "false" is returned, the instance won't be saved/updated. - * - * @since 0.1 - * - * @param array $new_instance New settings for this instance as input by the user via form(). - * @param array $old_instance Old settings for this instance. - * - * @return array Settings to save or bool false to cancel saving - */ - function update( $new_instance, $old_instance ) { - // Force the cache to refresh. - update_option( 'wpt_delete_cache', 'true' ); - $new_instance['title'] = strip_tags( $new_instance['title'] ); - - return $new_instance; - } - - /** - * Echo the settings update form. - * - * @param array $instance Current settings. - */ - function form( $instance ) { - // Merge with defaults. - $instance = wp_parse_args( (array) $instance, $this->defaults ); - ?> -

- - -

- -

- - -

- -

- - -

- -

- - -

- -

- - -

- -

- /> - -

- -

- /> - -

- -

- /> - -

- -

- /> - -

- -

- /> - -

- -

- /> - -

- '', - 'key' => '', - 'secret' => '', - 'token' => '', - 'token_secret' => '', - 'screenname' => false, - 'cache_expire' => 1800, - ); - - /** - * Last error, if any. - * - * @var $st_last_error - */ - public $st_last_error = false; - - /** - * Constructor. - * - * @param array $args Arguments; merged with defaults. - */ - function __construct( $args = array() ) { - $this->defaults = array_merge( $this->defaults, $args ); - } - - /** - * Convert arguments into a string. - * - * @return print_r of arguments. - */ - function __toString() { - return print_r( $this->defaults, true ); - } - - /** - * Get Tweets for a given screen name. - * - * @param int $count Number of Tweets to fetch. - * @param string $screenname X.com account feed to fetch. - * @param array $options Options to apply for display of feed. - * - * @return Tweets or error message. - */ - function get_tweets( $count = 20, $screenname = false, $options = false ) { - if ( $count > 20 ) { - /** - * Filters the max feed count. Default is 20, but you can change it. - * - * @param integer 20 - Default value - * @param integer $count - Widget variable - * @return integer - */ - $count = apply_filters( 'wpt_feed_max_count', 20, $count ); - } - if ( $count < 1 ) { - $count = 1; - } - - $default_options = array( - 'trim_user' => true, - 'exclude_replies' => true, - 'include_rts' => false, - ); - - if ( false === $options || ! is_array( $options ) ) { - $options = $default_options; - } else { - $options = array_merge( $default_options, $options ); - } - - if ( false === $screenname ) { - $screenname = get_option( 'wtt_twitter_username' ); - } - - $result = $this->check_valid_cache( $screenname, $options ); - if ( false !== $result ) { - return $this->crop_tweets( $result, $count ); - } - - // If we're here, we need to load. - $result = $this->oauth_get_tweets( $screenname, $options ); - - if ( is_object( $result ) && isset( $result->error ) ) { - $last_error = $result->error; - - return array( 'error' => 'X.com said: ' . $last_error ); - } else { - return $this->crop_tweets( $result, $count ); - } - - } - - /** - * Crop list of Tweets to display correct number of items. - * - * @param array $result Full query result. - * @param int $count Tweets to show. - * - * @return array - */ - private function crop_tweets( $result, $count ) { - if ( is_array( $result ) ) { - return array_slice( $result, 0, $count ); - } else { - return array(); - } - } - - /** - * Locate cache. - */ - private function get_cache_location() { - return $this->defaults['directory'] . '.tweetcache'; - } - - /** - * Hash options so cache is unique. - * - * @param array $options Display options. - * - * @return md5 hash. - */ - private function get_options_hash( $options ) { - $hash = md5( serialize( $options ) ); - - return $hash; - } - - /** - * Save cache to file. - * - * @param string $file Cache file location. - * @param string $cache Data to save. - */ - private function save_cache( $file, $cache ) { - $is_writable = wpt_is_writable( $file ); - if ( $is_writable ) { - file_put_contents( $file, $cache ); - } else { - set_transient( 'wpt_cache', $cache, $this->defaults['cache_expire'] ); - } - } - - /** - * Delete cache. - * - * @param string $file File name. - */ - private function delete_cache( $file ) { - $is_writable = wpt_is_writable( $file ); - if ( $is_writable ) { - unlink( $file ); - } else { - delete_transient( 'wpt_cache' ); - } - } - - /** - * Fetch and verify cache. - * - * @param string $screenname Name to get cache for. - * @param array $options Options for cache being fetched. - * - * @return boolean or cache contents. - */ - private function check_valid_cache( $screenname, $options ) { - $delete_cache = get_option( 'wpt_delete_cache' ); - $file = $this->get_cache_location(); - - if ( 'true' === $delete_cache ) { - update_option( 'wpt_delete_cache', 'false' ); - $this->delete_cache( $file ); - } - - if ( is_file( $file ) ) { - $cache = file_get_contents( $file ); - $cache = json_decode( $cache, true ); - if ( ! isset( $cache ) ) { - unlink( $file ); - - return false; - } - } else { - $cache = get_transient( 'wpt_cache' ); - $cache = json_decode( $cache, true ); - if ( ! isset( $cache ) ) { - return false; - } - } - $cachename = $screenname . '-' . $this->get_options_hash( $options ); - - // Check if we have a cache for the user. - if ( ! isset( $cache[ $cachename ] ) ) { - return false; - } - - if ( ! isset( $cache[ $cachename ]['time'] ) || ! isset( $cache[ $cachename ]['tweets'] ) ) { - unset( $cache[ $cachename ] ); - $this->save_cache( $file, json_encode( $cache ) ); - - return false; - } - - if ( $cache[ $cachename ]['time'] < ( time() - $this->defaults['cache_expire'] ) ) { - $result = $this->oauth_get_tweets( $screenname, $options ); - if ( ! isset( $result->error ) ) { - return $result; - } - } - - return $cache[ $cachename ]['tweets']; - } - - /** - * Fetch Tweets from X.com. - * - * @param string $screenname Username. - * @param array $options Array of display options. - * - * @return Tweets. - */ - private function oauth_get_tweets( $screenname, $options ) { - $key = $this->defaults['key']; - $secret = $this->defaults['secret']; - $token = $this->defaults['token']; - $token_secret = $this->defaults['token_secret']; - $cachename = $screenname . '-' . $this->get_options_hash( $options ); - $options = array_merge( - $options, - array( - 'screen_name' => $screenname, - 'count' => 20, - ) - ); - - if ( empty( $key ) ) { - return array( 'error' => __( 'Missing Consumer Key - Check settings', 'wp-to-twitter' ) ); - } - if ( empty( $secret ) ) { - return array( 'error' => __( 'Missing Consumer Secret - Check settings', 'wp-to-twitter' ) ); - } - if ( empty( $token ) ) { - return array( 'error' => __( 'Missing Access Token - Check settings', 'wp-to-twitter' ) ); - } - if ( empty( $token_secret ) ) { - return array( 'error' => __( 'Missing Access Token Secret - Check settings', 'wp-to-twitter' ) ); - } - if ( empty( $screenname ) ) { - return array( 'error' => __( 'Missing X.com Feed Screen Name - Check settings', 'wp-to-twitter' ) ); - } - - $connection = new wpt_TwitterOAuth( $key, $secret, $token, $token_secret ); - - if ( isset( $options['search'] ) ) { - $args = array( - 'q' => urlencode( $options['search'] ), - 'result_type' => urlencode( $options['result_type'] ), - ); - if ( '' !== $options['geocode'] ) { - $args['geocode'] = urlencode( $options['geocode'] ); - } - $url = add_query_arg( $args, 'https://api.twitter.com/1.1/search/tweets.json' ); - $result = $connection->get( $url, $options ); - } else { - $result = $connection->get( 'https://api.twitter.com/1.1/statuses/user_timeline.json', $options ); - } - $result = json_decode( $result ); - if ( isset( $options['search'] ) ) { - if ( ! method_exists( $result, 'errors' ) ) { - $result = ( is_object( $result ) ) ? $result->statuses : ''; - } else { - $errors = $result->errors; - $return = ''; - foreach ( $errors as $error ) { - $return .= "
  • $error->message
  • "; - } - echo ''; - return; - } - } - if ( is_file( $this->get_cache_location() ) ) { - $cache = json_decode( file_get_contents( $this->get_cache_location() ), true ); - } - - if ( ! isset( $result->error ) ) { - $cache[ $cachename ]['time'] = time(); - $cache[ $cachename ]['tweets'] = $result; - $file = $this->get_cache_location(); - $this->save_cache( $file, json_encode( $cache ) ); - } else { - if ( is_array( $result ) && isset( $result['errors'][0] ) && isset( $result['errors'][0]['message'] ) ) { - // Translators: Error message. - $last_error = '[' . gmdate( 'r' ) . '] ' . sprintf( __( 'X.com error: %s', 'wp-to-twitter' ), $result['errors'][0]['message'] ); - $this->st_last_error = $last_error; - } else { - $last_error = '[' . gmdate( 'r' ) . ']' . __( 'X.com returned an invalid response. It is probably down.', 'wp-to-twitter' ); - $this->st_last_error = $last_error; - } - } - /** - * Run an action on the results output from the X.com widget query. - * - * @hook wpt_process_tweets - * - * @param {array} $result Array of data received from X.com's API. - * @param {string} $screenname X.com user's screen name. - * @param {array} $options Array of options passed to this widget. - */ - do_action( 'wpt_process_tweets', $result, $screenname, $options ); - - return $result; - } -} diff --git a/src/css/twitter-feed.css b/src/css/twitter-feed.css deleted file mode 100644 index 94438af..0000000 --- a/src/css/twitter-feed.css +++ /dev/null @@ -1,98 +0,0 @@ -.wpt-header iframe { - float: right; -} - -.wpt-left { - float: left; - margin-right: 10px; -} - -.wpt-right { - float: right; - margin-left: 10px; -} - -.wpt-twitter-name { - font-size: 120%; - line-height: 1; -} - -.wpt-twitter-id { - display: inline-block; - margin-top: .5em; -} - -.wpt-tweet-time { - font-size: 90%; -} - -.wpt-latest-tweets li, .wpt-search-tweets li { - margin-bottom: .75em; - list-style-type: none; -} - -.wpt-intents-border { - border-top: 1px solid; - opacity: .3; - margin: 5px 0; -} - -.wpt-intents { - padding: 0 0 5px; - text-align: center; - font-size: 12px; -} - -.wpt-twitter-image { - width: 100%; - height: auto; -} - -.wpt-intents a span { - width: 16px; - height: 16px; - display: inline-block; - margin-right: 3px; - position: relative; - top: 2px; -} - -.wpt-intents .wpt-reply span { - background: url(../images/spritev2.png) 0px; -} - -.wpt-intents .wpt-retweet span { - background: url(../images/spritev2.png) -80px; -} - -.wpt-intents .wpt-favorite span { - background: url(../images/spritev2.png) -32px; -} - -.wpt-intents .wpt-reply:hover span, .wpt-intents .wpt-reply:focus span { - background-position: -16px; -} - -.wpt-intents .wpt-retweet:hover span, .wpt-intents .wpt-retweet:focus span { - background-position: -96px; -} - -.wpt-intents .wpt-favorite:hover span, .wpt-intents .wpt-favorite:focus span { - background-position: -48px; -} - -.retweeted .wpt-intents .wpt-retweet span { - background-position: -112px; -} - -.favorited .wpt-intents .wpt-favorite span { - background-position: -64px; -} - -.wpt-intents a span.intent-text { - width: auto; - height: auto; - margin: 0; - top: 0; - background: none; -} \ No newline at end of file diff --git a/src/images/spritev2.png b/src/images/spritev2.png deleted file mode 100644 index a8aa825..0000000 Binary files a/src/images/spritev2.png and /dev/null differ diff --git a/src/uninstall.php b/src/uninstall.php index 3da5670..01faeea 100644 --- a/src/uninstall.php +++ b/src/uninstall.php @@ -72,6 +72,7 @@ delete_option( 'jd_strip_nonan' ); delete_option( 'wpt_auto_tweet_allowed' ); delete_option( 'wpt_tweet_length' ); + delete_option( 'wpt_permit_feed_styles' ); delete_option( 'jd_individual_twitter_users' ); delete_option( 'use_tags_as_hashtags' ); diff --git a/src/wp-to-twitter-manager.php b/src/wp-to-twitter-manager.php index 2743aec..fee83ae 100644 --- a/src/wp-to-twitter-manager.php +++ b/src/wp-to-twitter-manager.php @@ -144,7 +144,6 @@ function wpt_updated_settings() { } } - update_option( 'wpt_permit_feed_styles', ( isset( $_POST['wpt_permit_feed_styles'] ) ) ? 1 : 0 ); update_option( 'wp_debug_oauth', ( isset( $_POST['wp_debug_oauth'] ) ) ? 1 : 0 ); update_option( 'wpt_debug_tweets', ( isset( $_POST['wpt_debug_tweets'] ) ) ? 1 : 0 ); $wpt_truncation_order = map_deep( $_POST['wpt_truncation_order'], 'sanitize_text_field' ); @@ -711,10 +710,6 @@ function wpt_update_settings() {