From 03ae2f0de3c2a06c9542a0f8b7a38ca6a1079b8d Mon Sep 17 00:00:00 2001 From: Lew Ayotte Date: Wed, 13 Nov 2013 10:14:27 -0500 Subject: [PATCH] initial commit to new repo --- class.php | 356 +++++++++++++++++++++++ css/issuem-leaky-paywall-settings.css | 12 + functions.php | 94 ++++++ issuem-leaky-paywall-subscriber-meta.php | 62 ++++ js/issuem-leaky-paywall-settings.js | 20 ++ readme.txt | 46 +++ 6 files changed, 590 insertions(+) create mode 100644 class.php create mode 100644 css/issuem-leaky-paywall-settings.css create mode 100644 functions.php create mode 100644 issuem-leaky-paywall-subscriber-meta.php create mode 100644 js/issuem-leaky-paywall-settings.js create mode 100644 readme.txt diff --git a/class.php b/class.php new file mode 100644 index 0000000..dfbb1af --- /dev/null +++ b/class.php @@ -0,0 +1,356 @@ +get_settings(); + + add_action( 'admin_init', array( $this, 'upgrade' ) ); + + add_action( 'admin_enqueue_scripts', array( $this, 'admin_wp_enqueue_scripts' ) ); + add_action( 'admin_print_styles', array( $this, 'admin_wp_print_styles' ) ); + + add_action( 'issuem_leaky_paywall_settings_form', array( $this, 'settings_div' ) ); + add_action( 'issuem_leaky_paywall_update_settings', array( $this, 'update_settings_div' ) ); + + add_filter( 'leaky_paywall_subscribers_columns', array( $this, 'leaky_paywall_subscribers_columns' ) ); + //add_filter( 'leaky_paywall_subscribers_sortable_columns', array( $this, 'leaky_paywall_subscribers_sortable_columns' ) ); + add_filter( 'manage_leaky_paywall_susbcribers_custom_column', array( $this, 'manage_leaky_paywall_susbcribers_custom_column' ), 10, 3 ); + add_action( 'update_leaky_paywall_subscriber_form', array( $this, 'update_leaky_paywall_subscriber_form' ) ); + add_action( 'update_leaky_paywall_subscriber', array( $this, 'update_leaky_paywall_subscriber' ) ); + add_action( 'add_leaky_paywall_subscriber_form', array( $this, 'add_leaky_paywall_subscriber_form' ) ); + add_action( 'add_leaky_paywall_subscriber', array( $this, 'add_leaky_paywall_subscriber' ) ); + add_filter( 'issuem_leaky_paywall_subscriber_query_join', array( $this, 'issuem_leaky_paywall_subscriber_query_join' ) ); + add_filter( 'issuem_leaky_paywall_search_susbcriber_where_array', array( $this, 'issuem_leaky_paywall_search_susbcriber_where_array' ), 10, 3 ); + + } + + /** + * Prints backend IssueM styles + * + * @since 1.0.0 + */ + function admin_wp_print_styles() { + + global $hook_suffix; + + if ( 'leaky-paywall_page_leaky-paywall-subscribers' === $hook_suffix + || 'toplevel_page_issuem-leaky-paywall' === $hook_suffix ) + wp_enqueue_style( 'issuem_leaky_paywall_sm_settings_style', ISSUEM_LP_SM_URL . 'css/issuem-leaky-paywall-settings.css', '', ISSUEM_LP_SM_VERSION ); + + } + + /** + * Enqueues backend IssueM styles + * + * @since 1.0.0 + */ + function admin_wp_enqueue_scripts( $hook_suffix ) { + + if ( 'leaky-paywall_page_leaky-paywall-subscribers' === $hook_suffix + || 'toplevel_page_issuem-leaky-paywall' === $hook_suffix ) + wp_enqueue_script( 'issuem_leaky_paywall_sm_settings_js', ISSUEM_LP_SM_URL . 'js/issuem-leaky-paywall-settings.js', array( 'jquery' ), ISSUEM_LP_SM_VERSION ); + + + } + + /** + * Get IssueM's Leaky Paywall - Subscriber Meta options + * + * @since 1.0.0 + */ + function get_settings() { + + $defaults = array( + 'meta_keys' => array(), + ); + + $defaults = apply_filters( 'issuem_leaky_paywall_subscriber_meta_default_settings', $defaults ); + + $settings = get_option( 'issuem-leaky-paywall-subscriber-meta' ); + + return wp_parse_args( $settings, $defaults ); + + } + + /** + * Update IssueM's Leaky Paywall options + * + * @since 1.0.0 + */ + function update_settings( $settings ) { + + update_option( 'issuem-leaky-paywall-subscriber-meta', $settings ); + + } + + /** + * Create and Display IssueM settings page + * + * @since 1.0.0 + */ + function settings_div() { + + // Get the user options + $settings = $this->get_settings(); + + // Display HTML form for the options below + ?> +
+ +

+ +

+ +
+ + + + + + + + + + + + + + + + + +
/>x
+ + + +

+ +

+ +

+ +

+ +
+ +
+ get_settings(); + + if ( !empty( $_REQUEST['meta_keys'] ) ) + $settings['meta_keys'] = $_REQUEST['meta_keys']; + else + $settings['meta_keys'] = ''; + + $this->update_settings( $settings ); + + } + + function leaky_paywall_subscribers_columns( $columns ) { + + $settings = $this->get_settings(); + + if ( !empty( $settings['meta_keys'] ) ) { + foreach ( $settings['meta_keys'] as $meta_key ) { + if ( !empty( $meta_key['checked'] ) && 'on' === $meta_key['checked'] ) { + $label = $meta_key['name']; + $meta_key = sanitize_title_with_dashes( $meta_key['name'] ); + $columns[$meta_key] = $label; + } + } + } + + return $columns; + } + + function leaky_paywall_subscribers_sortable_columns( $columns ) { + + $settings = $this->get_settings(); + + if ( !empty( $settings['meta_keys'] ) ) { + foreach ( $settings['meta_keys'] as $meta_key ) { + if ( !empty( $meta_key['checked'] ) && 'on' === $meta_key['checked'] ) { + $meta_key = sanitize_title_with_dashes( $meta_key['name'] ); + $columns[$meta_key] = array( 'lpsm.meta_key', false ); + } + } + } + + return $columns; + } + + function manage_leaky_paywall_susbcribers_custom_column( $output, $column, $hash ) { + + return issuem_leaky_paywall_get_user_meta( $hash, $column ); + + } + + function update_leaky_paywall_subscriber_form( $subscriber ) { + $settings = $this->get_settings(); + + if ( !empty( $settings['meta_keys'] ) ) { + foreach ( $settings['meta_keys'] as $meta_key ) { + if ( !empty( $meta_key['checked'] ) && 'on' === $meta_key['checked'] ) { + $label = $meta_key['name']; + $meta_key = sanitize_title_with_dashes( $meta_key['name'] ); + ?> +

+ + +

+ get_settings(); + + if ( !empty( $settings['meta_keys'] ) ) { + foreach ( $settings['meta_keys'] as $meta_key ) { + if ( !empty( $meta_key['name'] ) ) { + $meta_key = sanitize_title_with_dashes( $meta_key['name'] ); + if ( !empty( $_REQUEST['leaky-paywall-subscriber-' . $meta_key . '-meta-key'] ) ) { + issuem_leaky_paywall_update_user_meta( $subscriber->hash, $meta_key, $_REQUEST['leaky-paywall-subscriber-' . $meta_key . '-meta-key'] ); + } + } + } + } + } + + function add_leaky_paywall_subscriber_form() { + $settings = $this->get_settings(); + + if ( !empty( $settings['meta_keys'] ) ) { + foreach ( $settings['meta_keys'] as $meta_key ) { + if ( !empty( $meta_key['checked'] ) && 'on' === $meta_key['checked'] ) { + $label = $meta_key['name']; + $meta_key = sanitize_title_with_dashes( $meta_key['name'] ); + ?> +

+ + +

+ get_settings(); + + if ( !empty( $settings['meta_keys'] ) ) { + foreach ( $settings['meta_keys'] as $meta_key ) { + if ( !empty( $meta_key['name'] ) ) { + $meta_key = sanitize_title_with_dashes( $meta_key['name'] ); + if ( !empty( $_REQUEST['leaky-paywall-subscriber-' . $meta_key . '-meta-key'] ) ) { + issuem_leaky_paywall_update_user_meta( $subscriber->hash, $meta_key, $_REQUEST['leaky-paywall-subscriber-' . $meta_key . '-meta-key'] ); + } + } + } + } + } + + function issuem_leaky_paywall_subscriber_query_join( $join ) { + global $wpdb; + return $join . ' LEFT JOIN ' . $wpdb->prefix . 'issuem_leaky_paywall_subscriber_meta AS lpsm ON lpsm.hash = lps.hash '; + } + + function issuem_leaky_paywall_search_susbcriber_where_array( $where_array, $search_type, $search ) { + $where_array[] .= sprintf( "lpsm.`meta_value` %s '%s'", $search_type, $search ); + return $where_array; + } + + /** + * Upgrade function, tests for upgrade version changes and performs necessary actions + * + * @since 1.0.0 + */ + function upgrade() { + + $settings = $this->get_settings(); + + if ( isset( $settings['version'] ) ) + $old_version = $settings['version']; + else + $old_version = 0; + + /* Table Version Changes */ + //if ( isset( $settings['db_version'] ) ) + // $old_db_version = $settings['db_version']; + // else + $old_db_version = 0; + + if ( version_compare( $old_db_version, '1.0.0', '<' ) ) + $this->init_db_table(); + + $settings['version'] = ISSUEM_LP_SM_VERSION; + $settings['db_version'] = ISSUEM_LP_SM_DB_VERSION; + + $this->update_settings( $settings ); + + } + + function init_db_table() { + + global $wpdb; + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); + + $table_name = $wpdb->prefix . 'issuem_leaky_paywall_subscriber_meta'; + + $sql = "CREATE TABLE $table_name ( + hash VARCHAR(64) NOT NULL, + meta_key VARCHAR(254) NOT NULL, + meta_value VARCHAR(254) NOT NULL + );"; + + dbDelta( $sql ); + + } + + } + +} \ No newline at end of file diff --git a/css/issuem-leaky-paywall-settings.css b/css/issuem-leaky-paywall-settings.css new file mode 100644 index 0000000..51efcd8 --- /dev/null +++ b/css/issuem-leaky-paywall-settings.css @@ -0,0 +1,12 @@ +#issuem_leaky_paywall_subscriber_meta_wrapper { + display: table; + width: 100%; +} + +#issuem_leaky_paywall_subscriber_meta_wrapper .row { + display: table-row; +} + +#issuem_leaky_paywall_subscriber_meta_wrapper .cell { + display: cell; +} \ No newline at end of file diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..32b4be0 --- /dev/null +++ b/functions.php @@ -0,0 +1,94 @@ +get_var( $wpdb->prepare( + " + SELECT meta_value + FROM " . $wpdb->prefix . "issuem_leaky_paywall_subscriber_meta + WHERE hash = '%s' + AND meta_key = '%s' + ", + $hash, + $key + ) + ); + + } + +} + +if ( !function_exists( 'issuem_leaky_paywall_update_user_meta' ) ) { + + function issuem_leaky_paywall_update_user_meta( $hash, $key, $value ) { + + global $wpdb; + + $current_value = issuem_leaky_paywall_get_user_meta( $hash, $key ); + + if ( !empty( $current_value ) ) { + return $wpdb->update( + $wpdb->prefix . "issuem_leaky_paywall_subscriber_meta", + array( + 'meta_value' => $value // string + ), + array( + 'hash' => $hash, + 'meta_key' => $key, // string + ), + array( + '%s', // meta_key + '%s' // meta_value + ), + array( '%s' ) + ); + } else if ( $current_value !== $value ) { + return $wpdb->insert( + $wpdb->prefix . "issuem_leaky_paywall_subscriber_meta", + array( + 'hash' => $hash, // string + 'meta_key' => $key, // string + 'meta_value' => $value // string + ), + array( + '%s', // hash + '%s', // meta_key + '%s' // meta_value + ) + ); + } + + return false; + } +} + +if ( !function_exists( 'wp_print_r' ) ) { + + /** + * Helper function used for printing out debug information + * + * HT: Glenn Ansley @ iThemes.com + * + * @since 1.0.0 + * + * @param int $args Arguments to pass to print_r + * @param bool $die TRUE to die else FALSE (default TRUE) + */ + function wp_print_r( $args, $die = true ) { + + $echo = '
' . print_r( $args, true ) . '
'; + + if ( $die ) die( $echo ); + else echo $echo; + + } + +} \ No newline at end of file diff --git a/issuem-leaky-paywall-subscriber-meta.php b/issuem-leaky-paywall-subscriber-meta.php new file mode 100644 index 0000000..164423d --- /dev/null +++ b/issuem-leaky-paywall-subscriber-meta.php @@ -0,0 +1,62 @@ +'; + new_row += ''; + new_row += ''; + new_row += 'x'; + new_row += ''; + subscriber_meta_key_count++; + $( 'table#issuem_leaky_paywall_subscriber_meta_wrapper' ).append( new_row ); + + }); + $( '.delete_lp_meta_key' ).live( 'click', function( e ) { + e.preventDefault(); + $( this ).closest( 'tr' ).remove(); + }); + +}); \ No newline at end of file diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..4e381b5 --- /dev/null +++ b/readme.txt @@ -0,0 +1,46 @@ +=== IssueM - Leaky Paywall - IP Exceptions === +Contributors: layotte +Tags: magazine, issue, manager, paywall, leaky +Requires at least: 3.0 +Tested up to: 3.7 +Stable tag: 1.0.0 + +Allow IP addresses to access content through IssueM's Leaky Paywall. More info at http://issuem.com + +== Description == + +Allow IP addresses to access content through IssueM's Leaky Paywall. More info at http://issuem.com + +== Installation == + +1. Upload the entire `issuem-leaky-paywall` folder to your `/wp-content/plugins/` folder. +1. Go to the 'Plugins' page in the menu and activate the plugin. + +== Frequently Asked Questions == + += What are the minimum requirements for IssueM's Leaky Paywall - IP Exceptions? = + +You must have: + +* WordPress 3.3 or later +* PHP 5 +* IssueM's Leaky Paywall version 1.1.0 or later + += How is IssueM's Leaky Paywall Licensed? = + +* Like IssueM, Leaky Paywall is GPL + +== Changelog == += 1.0.0 = +* Initial Release + +== License == + +IssueM - Leaky Paywall - IP Exceptions +Copyright (C) 2011 The Complete Website, LLC. + +This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with this program. If not, see .