diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 60124c2..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "wp-common"] - path = wp-common - url = https://github.com/petermolnar/wp-common.git diff --git a/readme.txt b/readme.txt index b9be87c..97adbd3 100644 --- a/readme.txt +++ b/readme.txt @@ -3,8 +3,8 @@ Contributors: cadeyrn, ameir, haroldkyle, plescheff, dkcwd, IgorCode Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XU3DG7LLA76WC Tags: cache, page cache, full page cache, nginx, memcached, apc, speed Requires at least: 3.0 -Tested up to: 4.1 -Stable tag: 1.7.9 +Tested up to: 4.2.1 +Stable tag: 1.8.0 License: GPLv3 License URI: http://www.gnu.org/licenses/gpl-3.0.html @@ -125,6 +125,17 @@ Version numbering logic: * every .B version indicates new features. * every ..C indicates bugfixes for A.B version. += 1.8.0 = +*2015-04-29* + +What's new: + +* backend keys are now sha1 hashes instead of full url; this is to prevent too long key error with memcached + +Under the hood: +* wp-common is removed; no more git submodules +* logging method changed + = 1.7.9 = *2015-02-02* diff --git a/uninstall.php b/uninstall.php index bc66239..88657bc 100644 --- a/uninstall.php +++ b/uninstall.php @@ -13,5 +13,3 @@ include_once ( 'wp-ffpc.php' ); /* run uninstall function */ $wp_ffpc->plugin_uninstall(); - -?> diff --git a/wp-common b/wp-common deleted file mode 160000 index a355960..0000000 --- a/wp-common +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a355960827c466a01a00f3d4e04c6ee812594c37 diff --git a/wp-ffpc-abstract.php b/wp-ffpc-abstract.php new file mode 100644 index 0000000..4b12f86 --- /dev/null +++ b/wp-ffpc-abstract.php @@ -0,0 +1,610 @@ +plugin_constant = $plugin_constant; + $this->plugin_file = $this->plugin_constant . '/' . $this->plugin_constant . '.php'; + + $this->plugin_version = $plugin_version; + $this->plugin_name = $plugin_name; + $this->defaults = $defaults; + + $this->plugin_settings_page = $this->plugin_constant .'-settings'; + + $this->button_save = $this->plugin_constant . '-save'; + $this->button_delete = $this->plugin_constant . '-delete'; + + if ( !empty( $donation_business_name ) && !empty( $donation_item_name ) && !empty( $donation_business_id ) ) { + $this->donation_business_name = $donation_business_name; + $this->donation_item_name = $donation_item_name; + $this->donation_business_id = $donation_business_id; + $this->donation = true; + } + + //$this->utils = new PluginUtils(); + + /* we need network wide plugin check functions */ + if ( ! function_exists( 'is_plugin_active_for_network' ) ) + require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); + + /* check if plugin is network-activated */ + if ( @is_plugin_active_for_network ( $this->plugin_file ) ) { + $this->network = true; + $this->settings_slug = 'settings.php'; + } + else { + $this->settings_slug = 'options-general.php'; + } + + /* set the settings page link string */ + $this->settings_link = $this->settings_slug . '?page=' . $this->plugin_settings_page; + + /* initialize plugin, plugin specific init functions */ + $this->plugin_post_construct(); + + add_action( 'init', array(&$this,'plugin_init')); + add_action( 'admin_enqueue_scripts', array(&$this,'enqueue_admin_css_js')); + + } + + /** + * activation hook function, to be extended + */ + abstract function plugin_activate(); + + /** + * deactivation hook function, to be extended + */ + abstract function plugin_deactivate (); + + /** + * runs within the __construct, after all the initial settings + */ + abstract function plugin_post_construct(); + + /** + * first init hook function, to be extended, before options were read + */ + abstract function plugin_pre_init(); + + /** + * second init hook function, to be extended, after options were read + */ + abstract function plugin_post_init(); + + public function plugin_init() { + + /* initialize plugin, plugin specific init functions */ + $this->plugin_pre_init(); + + /* get the options */ + $this->plugin_options_read(); + + register_activation_hook( $this->plugin_file , array( &$this, 'plugin_activate' ) ); + register_deactivation_hook( $this->plugin_file , array( &$this, 'plugin_deactivate' ) ); + + /* register settings pages */ + if ( $this->network ) + add_filter( "network_admin_plugin_action_links_" . $this->plugin_file, array( &$this, 'plugin_settings_link' ) ); + else + add_filter( "plugin_action_links_" . $this->plugin_file, array( &$this, 'plugin_settings_link' ) ); + + /* register admin init, catches $_POST and adds submenu to admin menu */ + if ( $this->network ) + add_action('network_admin_menu', array( &$this , 'plugin_admin_init') ); + else + add_action('admin_menu', array( &$this , 'plugin_admin_init') ); + + add_filter('contextual_help', array( &$this, 'plugin_admin_help' ), 10, 2); + + /* setup plugin, plugin specific setup functions that need options */ + $this->plugin_post_init(); + } + + + /** + * admin panel, the HTML usually + */ + abstract function plugin_admin_panel(); + + /** + * admin help menu + */ + abstract function plugin_admin_help( $contextual_help, $screen_id ); + + /** + * admin init called by WordPress add_action, needs to be public + */ + public function plugin_admin_init() { + + /* save parameter updates, if there are any */ + if ( isset( $_POST[ $this->button_save ] ) && check_admin_referer( $this->plugin_constant ) ) { + + $this->plugin_options_save(); + $this->status = 1; + header( "Location: ". $this->settings_link . self::slug_save ); + } + + /* delete parameters if requested */ + if ( isset( $_POST[ $this->button_delete ] ) && check_admin_referer( $this->plugin_constant ) ) { + $this->plugin_options_delete(); + $this->status = 2; + header( "Location: ". $this->settings_link . self::slug_delete ); + } + + /* load additional moves */ + $this->plugin_extend_admin_init(); + + /* add submenu to settings pages */ + add_submenu_page( $this->settings_slug, $this->plugin_name . __translate__( ' options' , $this->plugin_constant ), $this->plugin_name, $this->capability, $this->plugin_settings_page, array ( &$this , 'plugin_admin_panel' ) ); + } + + /** + * to be extended + * + */ + abstract function plugin_extend_admin_init(); + + /** + * callback function to add settings link to plugins page + * + * @param array $links Current links to add ours to + * + */ + public function plugin_settings_link ( $links ) { + $settings_link = '' . __translate__( 'Settings', $this->plugin_constant ) . ''; + array_unshift( $links, $settings_link ); + return $links; + } + + /* add admin styling */ + public function enqueue_admin_css_js(){ + /* jquery ui tabs is provided by WordPress */ + wp_enqueue_script ( "jquery-ui-tabs" ); + wp_enqueue_script ( "jquery-ui-slider" ); + + /* additional admin styling */ + wp_register_style( $this->admin_css_handle, $this->admin_css_url, array('dashicons'), false, 'all' ); + wp_enqueue_style( $this->admin_css_handle ); + } + + /** + * deletes saved options from database + */ + protected function plugin_options_delete () { + static::_delete_option ( $this->plugin_constant, $this->network ); + + /* additional moves */ + $this->plugin_extend_options_delete(); + } + + /** + * hook to add functionality into plugin_options_read + */ + abstract function plugin_extend_options_delete (); + + /** + * reads options stored in database and reads merges them with default values + */ + protected function plugin_options_read () { + $options = static::_get_option ( $this->plugin_constant, $this->network ); + + /* this is the point to make any migrations from previous versions */ + $this->plugin_options_migrate( $options ); + + /* map missing values from default */ + foreach ( $this->defaults as $key => $default ) + if ( !@array_key_exists ( $key, $options ) ) + $options[$key] = $default; + + /* removed unused keys, rare, but possible */ + foreach ( @array_keys ( $options ) as $key ) + if ( !@array_key_exists( $key, $this->defaults ) ) + unset ( $options[$key] ); + + /* any additional read hook */ + $this->plugin_extend_options_read( $options ); + + $this->options = $options; + } + + /** + * hook for parameter migration, runs right after options read from DB + */ + abstract function plugin_options_migrate( &$options ); + + /** + * hook to add functionality into plugin_options_read, runs after defaults check + */ + abstract function plugin_extend_options_read ( &$options ); + + /** + * used on update and to save current options to database + * + * @param boolean $activating [optional] true on activation hook + * + */ + protected function plugin_options_save ( $activating = false ) { + + /* only try to update defaults if it's not activation hook, $_POST is not empty and the post + is ours */ + if ( !$activating && !empty ( $_POST ) && isset( $_POST[ $this->button_save ] ) ) { + /* we'll only update those that exist in the defaults array */ + $options = $this->defaults; + + foreach ( $options as $key => $default ) + { + /* $_POST element is available */ + if ( !empty( $_POST[$key] ) ) { + $update = $_POST[$key]; + + /* get rid of slashes in strings, just in case */ + if ( is_string ( $update ) ) + $update = stripslashes($update); + + $options[$key] = $update; + } + /* empty $_POST element: when HTML form posted, empty checkboxes a 0 input + values will not be part of the $_POST array, thus we need to check + if this is the situation by checking the types of the elements, + since a missing value means update from an integer to 0 + */ + elseif ( empty( $_POST[$key] ) && ( is_bool ( $default ) || is_int( $default ) ) ) { + $options[$key] = 0; + } + elseif ( empty( $_POST[$key] ) && is_array( $default) ) { + $options[$key] = array(); + } + } + + /* update the options array */ + $this->options = $options; + } + + /* set plugin version */ + $this->options['version'] = $this->plugin_version; + + /* call hook function for additional moves before saving the values */ + $this->plugin_extend_options_save( $activating ); + + /* save options to database */ + static::_update_option ( $this->plugin_constant , $this->options, $this->network ); + } + + /** + * hook to add functionality into plugin_options_save + */ + abstract function plugin_extend_options_save ( $activating ); + + /** + * function to easily print a variable + * + * @param mixed $var Variable to dump + * @param boolean $ret Return text instead of printing if true + * + */ + protected function print_var ( $var , $ret = false ) { + if ( @is_array ( $var ) || @is_object( $var ) || @is_bool( $var ) ) + $var = var_export ( $var, true ); + + if ( $ret ) + return $var; + else + echo $var; + } + + /** + * print value of an element from defaults array + * + * @param mixed $e Element index of $this->defaults array + * + */ + protected function print_default ( $e ) { + _e('Default : ', $this->plugin_constant); + $select = 'select_' . $e; + if ( @is_array ( $this->$select ) ) { + $x = $this->$select; + $this->print_var ( $x[ $this->defaults[ $e ] ] ); + } + else { + $this->print_var ( $this->defaults[ $e ] ); + } + } + + /** + * select options field processor + * + * @param elements + * array to build