From 08089fa05319b1fed03dd50c0a9d6c05a0fe72f8 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Tue, 17 Jan 2012 21:25:25 -0800 Subject: [PATCH 01/10] Rinat has a different WP.org username --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index a00fca7..a9b4129 100644 --- a/readme.txt +++ b/readme.txt @@ -1,5 +1,5 @@ === Ad Code Manager === -Contributors: danielbachhuber, rinatkhaziev, automattic +Contributors: danielbachhuber, johnbl4ck, automattic Tags: advertising, ad codes Requires at least: 3.1 Tested up to: 3.3.1 From e8948103c7ed7198dba9006d6c0aa5cf0a6956d9 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Tue, 17 Jan 2012 21:48:33 -0800 Subject: [PATCH 02/10] Better plugins_url for loading resources --- ad-code-manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ad-code-manager.php b/ad-code-manager.php index d47801b..9534cdb 100644 --- a/ad-code-manager.php +++ b/ad-code-manager.php @@ -27,7 +27,7 @@ define( 'AD_CODE_MANAGER_VERSION', '0.1' ); define( 'AD_CODE_MANAGER_ROOT' , dirname( __FILE__ ) ); define( 'AD_CODE_MANAGER_FILE_PATH' , AD_CODE_MANAGER_ROOT . '/' . basename( __FILE__ ) ); -define( 'AD_CODE_MANAGER_URL' , plugins_url( plugin_basename( dirname( __FILE__ ) ) . '/' ) ); +define( 'AD_CODE_MANAGER_URL' , plugins_url( '/', __FILE__ ) ); class Ad_Code_Manager { From e68e295672e893cec90ba8c3f6a8d7d4e26cd5d7 Mon Sep 17 00:00:00 2001 From: Rinat Khaziev Date: Wed, 18 Jan 2012 17:08:31 -0600 Subject: [PATCH 03/10] supply offset for get_posts in get_posts_ajax, otherwise pagination in jqGrid won't work --- ad-code-manager.php | 35 +++++++++++++++++++++++++---------- common/js/acm.js | 2 +- readme.txt | 36 ++++++++++++++++++++++++++++++++++-- 3 files changed, 60 insertions(+), 13 deletions(-) diff --git a/ad-code-manager.php b/ad-code-manager.php index 9534cdb..39e7458 100644 --- a/ad-code-manager.php +++ b/ad-code-manager.php @@ -207,7 +207,14 @@ function get_ad_codes_ajax() { */ $response; if ( isset( $_GET[ 'acm-action' ] ) && $_GET[ 'acm-action'] == 'datasource' ) { - $ad_codes = $this->get_ad_codes() ; + $response->page = isset( $_GET[ 'acm-grid-page' ] ) ? sanitize_key( $_GET[ 'acm-grid-page' ] ) : 1 ; + $query_args = array(); + + // We need to pass offset to get_ad_codes offset for jqGrid to work correctly + if ( 1 < $response->page ) + $query_args['offset'] = ( $response->page - 1 ) * intval( $_GET['rows'] ); + + $ad_codes = $this->get_ad_codes( $query_args ) ; // prepare data in jqGrid specific format $pass = array(); foreach ( $ad_codes as $ad_code ) { @@ -219,13 +226,10 @@ function get_ad_codes_ajax() { ); } $response->rows = $pass; - - $count = count( $response->rows ); - $total_pages = 1; // this should be $count / $_GET[ 'rows' ] // 'rows' is per page limit - - $response->page = isset( $_GET[ 'acm-grid-page' ] ) ? sanitize_key( $_GET[ 'acm-grid-page' ] ) : 1 ; - $response->total = $total_pages; - $response->records = $count; + $count_object = wp_count_posts( $this->post_type ); + $total_pages = ceil ( $count_object->publish / $_GET['rows'] ); + $response->total = $total_pages; + $response->records = $count_object->publish; $this->print_json( $response ); } return; @@ -237,12 +241,23 @@ function get_ad_codes_ajax() { * * @todo This is too DFP specific. Abstract it */ - function get_ad_codes() { + function get_ad_codes( $query_args = array() ) { $ad_codes_formatted = array(); + $allowed_query_params = apply_filters( 'acm_allowed_get_posts_args', array( 'offset' ) ); + $args = array( 'post_type' => $this->post_type, 'numberposts' => apply_filters( 'acm_ad_code_count', 50 ), ); + + foreach ( (array) $query_args as $query_key => $query_value ) { + if ( ! in_array( $query_key, $allowed_query_params ) ) { + unset( $query_args[$query_key] ); + } else { + $args[$query_key] = sanitize_text_field( $query_value ); + } + } + $ad_codes = get_posts( $args ); foreach ( $ad_codes as $ad_code_cpt ) { $ad_codes_formatted[] = array( @@ -266,7 +281,7 @@ function get_conditionals_ajax() { $count = count( $response->rows ); $total_pages = 1; // this should be $count / $_GET[ 'rows' ] // 'rows' is per page limit - $response->page = isset( $_GET['acm-grid-page'] ) ? sanitize_key( $_GET['acm-grid-page'] ) : 1 ; + $response->page = isset( $_GET['acm-grid-page'] ) ? sanitize_text( $_GET['acm-grid-page'] ) : 1 ; $response->total = $total_pages; $response->records = $count; $this->print_json( $response ); diff --git a/common/js/acm.js b/common/js/acm.js index a195f84..b24c04a 100644 --- a/common/js/acm.js +++ b/common/js/acm.js @@ -80,7 +80,7 @@ jQuery( document ).ready( function( $ ) { subgrid_lastsel=id; }}, rowNum:5, - rowList:[5,10,20], + rowList:[5,10,20,50,100], pager: '#acm-codes-conditionals-pager', sortname: 'item', jsonReader : { repeatitems: false }, // workaround for jqGrid issue diff --git a/readme.txt b/readme.txt index a9b4129..b1dc41d 100644 --- a/readme.txt +++ b/readme.txt @@ -1,8 +1,40 @@ === Ad Code Manager === -Contributors: danielbachhuber, johnbl4ck, automattic +Contributors: danielbachhuber, rinatkhaziev, automattic Tags: advertising, ad codes Requires at least: 3.1 Tested up to: 3.3.1 Stable tag: 0.1 -Easy ad code management. \ No newline at end of file +Easy ad code management. + +== Description == + +Easily manage your ads via nice and simple UI. Each ad code has unlimited amount of conditionals. Conditionals are core WordPress +methods like is_page(), is_category(), or your custom methods. + +Currently works with: + +* Doubleclick for publishers +This is the long description. No limit, and you can use Markdown (as well as in the following sections). +* More to come + + +== Installation == + +Since the plugin is only v0.1 there are some extra steps required to configure it + +1. Upload `ad-code-manager` to the `/wp-content/plugins/` directory +1. Activate the plugin through the 'Plugins' menu in WordPress +1. + +== Frequently Asked Questions == + += A question that someone might have = + +An answer to that question. + += What about foo bar? = + +Answer to foo bar dilemma. + +== Screenshots == \ No newline at end of file From 09a30d3f655aa60b8a99fd2938815813dc40c0d3 Mon Sep 17 00:00:00 2001 From: Rinat Khaziev Date: Wed, 18 Jan 2012 17:10:52 -0600 Subject: [PATCH 04/10] remove draft lines from readme --- readme.txt | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/readme.txt b/readme.txt index b1dc41d..735623d 100644 --- a/readme.txt +++ b/readme.txt @@ -25,16 +25,4 @@ Since the plugin is only v0.1 there are some extra steps required to configure i 1. Upload `ad-code-manager` to the `/wp-content/plugins/` directory 1. Activate the plugin through the 'Plugins' menu in WordPress -1. - -== Frequently Asked Questions == - -= A question that someone might have = - -An answer to that question. - -= What about foo bar? = - -Answer to foo bar dilemma. - -== Screenshots == \ No newline at end of file +1. \ No newline at end of file From 9990e2721639f190f237848e1b3522fdc4126dbc Mon Sep 17 00:00:00 2001 From: Rinat Khaziev Date: Wed, 18 Jan 2012 17:48:52 -0600 Subject: [PATCH 05/10] data from jqGrid was passed as string, but treated as array, added type check --- ad-code-manager.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ad-code-manager.php b/ad-code-manager.php index 39e7458..a32f8ce 100644 --- a/ad-code-manager.php +++ b/ad-code-manager.php @@ -165,10 +165,10 @@ function register_acm_post_type() { * * @since 0.1 */ - function ajax_handler() { + function ajax_handler() { if ( ! isset( $_REQUEST['nonce'] ) || ! wp_verify_nonce( $_REQUEST['nonce'], 'acm_nonce' ) ) return; - + if ( !current_user_can( $this->manage_ads_cap ) ) return; @@ -275,13 +275,17 @@ function get_ad_codes( $query_args = array() ) { function get_conditionals_ajax() { if ( 0 !== intval( $_GET[ 'id' ] ) ) { $conditionals = $this->get_conditionals( intval( $_GET[ 'id' ] ) ); - $response; - foreach ( $conditionals as $index => $item ) + $response; + foreach ( $conditionals as $index => $item ) { + if ( is_array( $item['arguments'] ) ) { + $item['arguments'] = implode(";", $item['arguments'] ); + } $response->rows[] = $item; + } $count = count( $response->rows ); $total_pages = 1; // this should be $count / $_GET[ 'rows' ] // 'rows' is per page limit - $response->page = isset( $_GET['acm-grid-page'] ) ? sanitize_text( $_GET['acm-grid-page'] ) : 1 ; + $response->page = isset( $_GET['acm-grid-page'] ) ? sanitize_text_field( $_GET['acm-grid-page'] ) : 1 ; $response->total = $total_pages; $response->records = $count; $this->print_json( $response ); @@ -326,7 +330,8 @@ function conditionals_edit_actions() { if ( ! empty( $_POST ) ) { $conditional_vals = array( 'function' => sanitize_key( $_POST['function'] ), - 'arguments' => array_map( 'sanitize_text_field', $_POST['arguments'] ), + //arguments from jqGrid are passed as string, need to check arguments type before choosing the way to sanitize the value + 'arguments' => is_array( $_POST['arguments'] ) ? array_map( 'sanitize_text_field', $_POST['arguments'] ) : sanitize_text_field( $_POST['arguments'] ), ); switch ( $_POST[ 'oper' ] ) { case 'add': @@ -407,7 +412,7 @@ function create_conditional( $ad_code_id, $conditional ) { } $existing_conditionals[] = array( 'function' => $conditional[ 'function' ], - 'arguments' => (array) $conditional[ 'arguments' ], // @todo explode + 'arguments' => explode(';', $conditional[ 'arguments' ] ), // @todo filterize explode character? ); update_post_meta( $ad_code_id, 'conditionals', $existing_conditionals ); } From f65977cd4e22e6524a396a9b4473608b2eb6609c Mon Sep 17 00:00:00 2001 From: Rinat Khaziev Date: Wed, 18 Jan 2012 18:20:11 -0600 Subject: [PATCH 06/10] do not add ad code with no conditionals in the array of codes to display if logical_operator is not equal AND --- ad-code-manager.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ad-code-manager.php b/ad-code-manager.php index a32f8ce..c96f9e0 100644 --- a/ad-code-manager.php +++ b/ad-code-manager.php @@ -616,10 +616,12 @@ function action_acm_tag( $tag_id ) { $display_codes = array(); foreach( (array)$this->ad_codes[$tag_id] as $ad_code ) { - // If the ad code doesn't have any conditionals, + // If the ad code doesn't have any conditionals and logical_operator set to "AND", // we should add it to the display list if ( empty( $ad_code['conditionals'] ) ) { - $display_codes[] = $ad_code; + if ( $this->logical_operator == 'AND' ) { + $display_codes[] = $ad_code; + } continue; } From c30c8f155937b3e788e969384e74cd86a01e39db Mon Sep 17 00:00:00 2001 From: Rinat Khaziev Date: Wed, 18 Jan 2012 18:20:11 -0600 Subject: [PATCH 07/10] do not add ad code with no conditionals in the array of codes to display if logical_operator is not equal AND --- ad-code-manager.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ad-code-manager.php b/ad-code-manager.php index c96f9e0..e897c4f 100644 --- a/ad-code-manager.php +++ b/ad-code-manager.php @@ -126,7 +126,7 @@ function action_init() { 'tag' => '300x250-btf', 'url_vars' => array( 'sz' => '300x250', - 'fold' => 'atf' + 'fold' => 'btf' ) ), array( @@ -135,7 +135,7 @@ function action_init() { 'sz' => '160x600', 'fold' => 'atf' ) - ) + ), ); $this->ad_tag_ids = apply_filters( 'acm_ad_tag_ids', $this->ad_tag_ids ); @@ -192,8 +192,7 @@ function ajax_handler() { /** * Returns json encoded ad code * This is the datasource for jqGRID - * - * @todo nonce? + * */ function get_ad_codes_ajax() { // These are params that should be managed via UI @@ -203,7 +202,7 @@ function get_ad_codes_ajax() { * $response->page = current page * $response->total = total pages * $response->record = count of rows - * $response->rows = nested array of assoc arrays @see $model + * $response->rows = nested array of assoc arrays */ $response; if ( isset( $_GET[ 'acm-action' ] ) && $_GET[ 'acm-action'] == 'datasource' ) { @@ -283,7 +282,7 @@ function get_conditionals_ajax() { $response->rows[] = $item; } $count = count( $response->rows ); - $total_pages = 1; // this should be $count / $_GET[ 'rows' ] // 'rows' is per page limit + $total_pages = ceil ( $count / $_GET['rows'] ); $response->page = isset( $_GET['acm-grid-page'] ) ? sanitize_text_field( $_GET['acm-grid-page'] ) : 1 ; $response->total = $total_pages; From 667792537feed3ae5028e876aad50125984f7066 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 19 Jan 2012 12:18:35 -0800 Subject: [PATCH 08/10] Remove draft text from the readme --- readme.txt | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/readme.txt b/readme.txt index 735623d..fcc79a5 100644 --- a/readme.txt +++ b/readme.txt @@ -9,20 +9,9 @@ Easy ad code management. == Description == -Easily manage your ads via nice and simple UI. Each ad code has unlimited amount of conditionals. Conditionals are core WordPress -methods like is_page(), is_category(), or your custom methods. +Easily manage your ads via nice and simple UI. Each ad code has unlimited amount of conditionals. Conditionals are core WordPress methods like is_page(), is_category(), or your custom methods. Currently works with: * Doubleclick for publishers -This is the long description. No limit, and you can use Markdown (as well as in the following sections). -* More to come - - -== Installation == - -Since the plugin is only v0.1 there are some extra steps required to configure it - -1. Upload `ad-code-manager` to the `/wp-content/plugins/` directory -1. Activate the plugin through the 'Plugins' menu in WordPress -1. \ No newline at end of file +* More to come \ No newline at end of file From b889a235b310aee3a7a9bf07ce1cee51ff89a549 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 19 Jan 2012 12:34:31 -0800 Subject: [PATCH 09/10] sanitize_text_field() isn't necessary here... we should be passing safe data to begin with --- ad-code-manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ad-code-manager.php b/ad-code-manager.php index e897c4f..4220342 100644 --- a/ad-code-manager.php +++ b/ad-code-manager.php @@ -253,7 +253,7 @@ function get_ad_codes( $query_args = array() ) { if ( ! in_array( $query_key, $allowed_query_params ) ) { unset( $query_args[$query_key] ); } else { - $args[$query_key] = sanitize_text_field( $query_value ); + $args[$query_key] = $query_value; } } From 0d0e65c4583db0ae835d7975fbd9f9059542bd54 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 19 Jan 2012 12:49:46 -0800 Subject: [PATCH 10/10] Tagging v0.1.1 --- ad-code-manager.php | 4 ++-- readme.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ad-code-manager.php b/ad-code-manager.php index 4220342..6d7d2d0 100644 --- a/ad-code-manager.php +++ b/ad-code-manager.php @@ -4,7 +4,7 @@ Plugin URI: http://automattic.com Description: Easy ad code management Author: Daniel Bachhuber, Rinat Khaziev, Automattic -Version: 0.1 +Version: 0.1.1 Author URI: http://automattic.com GNU General Public License, Free Software Foundation @@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -define( 'AD_CODE_MANAGER_VERSION', '0.1' ); +define( 'AD_CODE_MANAGER_VERSION', '0.1.1' ); define( 'AD_CODE_MANAGER_ROOT' , dirname( __FILE__ ) ); define( 'AD_CODE_MANAGER_FILE_PATH' , AD_CODE_MANAGER_ROOT . '/' . basename( __FILE__ ) ); define( 'AD_CODE_MANAGER_URL' , plugins_url( '/', __FILE__ ) ); diff --git a/readme.txt b/readme.txt index fcc79a5..297e673 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: danielbachhuber, rinatkhaziev, automattic Tags: advertising, ad codes Requires at least: 3.1 Tested up to: 3.3.1 -Stable tag: 0.1 +Stable tag: 0.1.1 Easy ad code management.