From 9bc9f14335266370370c3c82f6fda9f48419b4b5 Mon Sep 17 00:00:00 2001 From: James Pederson Date: Mon, 20 May 2019 16:46:02 -0500 Subject: [PATCH] Separate the wordpress functionality into its own file, and included it via the 'files' autoload. --- composer.json | 5 +- twitterAggregator.php | 108 ---------------------------------------- wordpress.php | 111 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 111 deletions(-) create mode 100644 wordpress.php diff --git a/composer.json b/composer.json index 147281e..e5b0f91 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,7 @@ "j7mbo/twitter-api-php":"*" }, "autoload": { - "classmap": [ - "twitterAggregator.php" - ] + "classmap": ["twitterAggregator.php"], + "files": ["wordpress.php"] } } diff --git a/twitterAggregator.php b/twitterAggregator.php index 6363e3f..eee2fd5 100644 --- a/twitterAggregator.php +++ b/twitterAggregator.php @@ -328,111 +328,3 @@ public function error( $message ) { } } - -/************************************ - wordpress functionality - ***********************************/ - -// check if we're inside wordpress -if ( function_exists( 'add_shortcode' ) ) { - - // twitter aggregator options for the wordpress settings page and the shortcode - $ta_options = array( - 'ta_consumer_key', - 'ta_consumer_secret', - 'ta_oauth_access_token', - 'ta_oauth_access_token_secret', - 'ta_usenames' - ); - - - /************************************ - shortcode [twitter-aggregator] - ***********************************/ - function twitter_aggregator_shortcode( $atts ) { - - // default parameters - $a = shortcode_atts( array( - 'consumer_key' => get_option( "ta_consumer_key", "" ), - 'consumer_secret' => get_option( "ta_consumer_secret", "" ), - 'oauth_access_token' => get_option( "ta_oauth_access_token", "" ), - 'oauth_access_token_secret' => get_option( "ta_oauth_access_token_secret", "" ), - 'usernames' => get_option( "ta_usenames", "reuters,ap,propublica" ), - 'update_interval' => 10, - 'styles' => true, - 'count' => 10, - 'exclude_replies' => true, - 'include_rts' => true - ), $atts ); - - - // generate an aggregator object - $ta = new twitterAggregator( $a ); - - if ( $a['styles'] ) { - // display the widget - return $ta->widget(); - } else { - // display the widget - return $ta->widget_unstyled(); - } - } - - // register our function as a shortcode - add_shortcode( 'twitter-aggregator', 'twitter_aggregator_shortcode' ); - - - - /************************************ - settings interface - ***********************************/ - - // register the settings for the first time. - function ta_register_settings() { - global $ta_options; - - // loop through the options and add them. - foreach ( $ta_options as $opt ) { - add_option( $opt, ''); - register_setting( 'ta_options_group', $opt ); - } - } - add_action( 'admin_init', 'ta_register_settings' ); - - - // register the options page in the admin menu - function ta_register_options_page() { - add_options_page('Twitter Aggregator Settings', 'Twitter Aggregator', 'manage_options', 'ta', 'ta_options_page'); - } - add_action('admin_menu', 'ta_register_options_page'); - - - // the actual page output function - function ta_options_page() { - global $ta_options; - - ?> -

Twitter Aggregator Settings

-
- -


-

- -
- get_option( "ta_consumer_key", "" ), + 'consumer_secret' => get_option( "ta_consumer_secret", "" ), + 'oauth_access_token' => get_option( "ta_oauth_access_token", "" ), + 'oauth_access_token_secret' => get_option( "ta_oauth_access_token_secret", "" ), + 'usernames' => get_option( "ta_usenames", "reuters,ap,propublica" ), + 'update_interval' => 10, + 'styles' => true, + 'count' => 10, + 'exclude_replies' => true, + 'include_rts' => true + ), $atts ); + + + // generate an aggregator object + $ta = new twitterAggregator( $a ); + + if ( $a['styles'] ) { + // display the widget + return $ta->widget(); + } else { + // display the widget + return $ta->widget_unstyled(); + } + } + + // register our function as a shortcode + add_shortcode( 'twitter-aggregator', 'twitter_aggregator_shortcode' ); + + + + /************************************ + settings interface + ***********************************/ + + // register the settings for the first time. + function ta_register_settings() { + global $ta_options; + + // loop through the options and add them. + foreach ( $ta_options as $opt ) { + add_option( $opt, ''); + register_setting( 'ta_options_group', $opt ); + } + } + add_action( 'admin_init', 'ta_register_settings' ); + + + // register the options page in the admin menu + function ta_register_options_page() { + add_options_page('Twitter Aggregator Settings', 'Twitter Aggregator', 'manage_options', 'ta', 'ta_options_page'); + } + add_action('admin_menu', 'ta_register_options_page'); + + + // the actual page output function + function ta_options_page() { + global $ta_options; + + ?> +

Twitter Aggregator Settings

+
+ +


+

+ +
+