";a("tr",e).append(q)}}})},GridToForm:function(f,b){return this.each(function(){var e=this;
-if(e.grid){var q=a(e).jqGrid("getRowData",f);if(q)for(var x in q)a("[name="+a.jgrid.jqID(x)+"]",b).is("input:radio")||a("[name="+a.jgrid.jqID(x)+"]",b).is("input:checkbox")?a("[name="+a.jgrid.jqID(x)+"]",b).each(function(){if(a(this).val()==q[x])a(this)[e.p.useProp?"prop":"attr"]("checked",true);else a(this)[e.p.useProp?"prop":"attr"]("checked",false)}):a("[name="+a.jgrid.jqID(x)+"]",b).val(q[x])}})},FormToGrid:function(f,b,e,q){return this.each(function(){if(this.grid){e||(e="set");q||(q="first");
-var x=a(b).serializeArray(),G={};a.each(x,function(B,w){G[w.name]=w.value});if(e=="add")a(this).jqGrid("addRowData",f,G,q);else e=="set"&&a(this).jqGrid("setRowData",f,G)}})}})})(jQuery);
-(function(c){c.fn.jqFilter=function(k){if(typeof k==="string"){var w=c.fn.jqFilter[k];if(!w)throw"jqFilter - No such method: "+k;var B=c.makeArray(arguments).slice(1);return w.apply(this,B)}var o=c.extend(true,{filter:null,columns:[],onChange:null,afterRedraw:null,checkValues:null,error:false,errmsg:"",errorcheck:true,showQuery:true,sopt:null,ops:[{name:"eq",description:"equal",operator:"="},{name:"ne",description:"not equal",operator:"<>"},{name:"lt",description:"less",operator:"<"},{name:"le",description:"less or equal",
-operator:"<="},{name:"gt",description:"greater",operator:">"},{name:"ge",description:"greater or equal",operator:">="},{name:"bw",description:"begins with",operator:"LIKE"},{name:"bn",description:"does not begin with",operator:"NOT LIKE"},{name:"in",description:"in",operator:"IN"},{name:"ni",description:"not in",operator:"NOT IN"},{name:"ew",description:"ends with",operator:"LIKE"},{name:"en",description:"does not end with",operator:"NOT LIKE"},{name:"cn",description:"contains",operator:"LIKE"},{name:"nc",
-description:"does not contain",operator:"NOT LIKE"},{name:"nu",description:"is null",operator:"IS NULL"},{name:"nn",description:"is not null",operator:"IS NOT NULL"}],numopts:["eq","ne","lt","le","gt","ge","nu","nn","in","ni"],stropts:["eq","ne","bw","bn","ew","en","cn","nc","nu","nn","in","ni"],_gridsopt:[],groupOps:[{op:"AND",text:"AND"},{op:"OR",text:"OR"}],groupButton:true,ruleButtons:true,direction:"ltr"},k||{});return this.each(function(){if(!this.filter){this.p=o;if(this.p.filter===null||this.p.filter===
-undefined)this.p.filter={groupOp:this.p.groupOps[0].op,rules:[],groups:[]};var q,x=this.p.columns.length,j,y=/msie/i.test(navigator.userAgent)&&!window.opera;if(this.p._gridsopt.length)for(q=0;q
From 6af113d164bd5e1592eee8d43f98e6083cad135c Mon Sep 17 00:00:00 2001
From: rinatkhaziev
Date: Wed, 11 Apr 2012 23:29:17 -0500
Subject: [PATCH 09/63] yo dawg, i herd you like documentation. so i put a
documentation in your documentation (per
https://github.com/Automattic/Ad-Code-Manager/issues/10#issuecomment-5053333)
---
readme.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/readme.txt b/readme.txt
index b9c48c4..78f2601 100644
--- a/readme.txt
+++ b/readme.txt
@@ -25,9 +25,9 @@ Since the plugin is in its early stages, there are a couple additional configura
1. Upload `ad-code-manager` to the `/wp-content/plugins/` directory
1. Activate the plugin through the 'Plugins' menu in WordPress
-1. Incorporate ad tags in your theme template
+1. Incorporate ad tags in your theme template with .
1. Implement filters to make the plugin work with your provider
-1. Configure your ad codes in the WordPress admin
+1. Configure your ad codes in the WordPress admin ( Tools -> Ad Code Manager )
== Configuration Filters ==
From 57ee7f77d2d36247ec90b4ab6892fbe0cba204b9 Mon Sep 17 00:00:00 2001
From: rinatkhaziev
Date: Wed, 11 Apr 2012 23:36:29 -0500
Subject: [PATCH 10/63] comment out caching, doesn't really work that well
---
ad-code-manager.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/ad-code-manager.php b/ad-code-manager.php
index 4c34412..8ce8a2d 100644
--- a/ad-code-manager.php
+++ b/ad-code-manager.php
@@ -342,7 +342,7 @@ function get_ad_codes( $query_args = array() ) {
}
}
$cache_key = 'ad_codes_' . implode('_', $query_args );
- if ( false === ($ad_codes_formatted = wp_cache_get( $cache_key , 'acm' ) ) ) {
+ //if ( false === ($ad_codes_formatted = wp_cache_get( $cache_key , 'acm' ) ) ) {
$ad_codes = get_posts( $args );
foreach ( $ad_codes as $ad_code_cpt ) {
@@ -359,9 +359,9 @@ function get_ad_codes( $query_args = array() ) {
);
}
// dev value
- wp_cache_add( $cache_key, $ad_codes_formatted, 'acm', 1 );
- $this->add_cache_key_to_index( $cache_key );
- }
+ //wp_cache_add( $cache_key, $ad_codes_formatted, 'acm', 1 );
+ //$this->add_cache_key_to_index( $cache_key );
+ //}
return $ad_codes_formatted;
}
From 499e57160f7f4cd47f37b0d4e8b005b4d3cbc885 Mon Sep 17 00:00:00 2001
From: Jeremy Felt
Date: Thu, 12 Apr 2012 00:12:06 -0700
Subject: [PATCH 11/63] Initial shot at an inline edit UI
Adds row actions in the ACM list table for View Conditionals, Edit, and Delete.
Connects each row's 'Edit' option to a hidden row containing a form with
all of the current Ad Code data.
Handles the basic Ad Code meta on a POST request, and updates accordingly,
but does not yet handle changes to the conditionals. Redirects back to the
referring site once saved.
Hopefully this approach isn't too far off, though I don't think it would
be too difficult to change course if it is.
View Conditionals and Delete are not yet hooked up to anything.
Side note - while preparing the conditionals, I noticed that multiple
arguments are possible for each. I tried saving an array() with multiple
arguments for a conditional, but it was still stored as a string. I didn't
investigate too much, but for now am displaying only argument 0 in the
inline display, as I didn't want to get distracted thinking out that
scenario.
---
ad-code-manager.php | 6 +-
common/css/acm.css | 49 +++++++++++-
common/js/acm.js | 26 ++++++-
common/lib/acm-wp-list-table.php | 124 ++++++++++++++++++++++---------
4 files changed, 166 insertions(+), 39 deletions(-)
diff --git a/ad-code-manager.php b/ad-code-manager.php
index 8ce8a2d..4e984cc 100644
--- a/ad-code-manager.php
+++ b/ad-code-manager.php
@@ -533,8 +533,10 @@ function edit_ad_code( $ad_code_id, $ad_code = array() ) {
update_post_meta( $ad_code_id, $slug, $ad_code[$slug] );
}
update_post_meta( $ad_code_id, 'priority', $ad_code['priority'] );
- }
- return;
+ }
+ $this->flush_cache();
+ wp_redirect( wp_get_referer() );
+ exit();
}
/**
diff --git a/common/css/acm.css b/common/css/acm.css
index 9da948f..22c436b 100755
--- a/common/css/acm.css
+++ b/common/css/acm.css
@@ -14,7 +14,7 @@
width: 600px;
}
-#the-list:hover .row-actions {
+tr:hover .row-actions {
visibility: visible;
}
@@ -34,4 +34,51 @@
clear:left;
width: 90%;
text-align: right;
+}
+
+.acm-edit-field {
+ position: relative;
+ max-width: 200px;
+ float: left;
+ margin: 15px 0 0 15px;
+}
+
+.acm-edit-field label {
+ position: relative;
+ float: left;
+ font-weight: 700;
+ color: #333;
+}
+
+.acm-edit-cond,
+.acm-cancel-button,
+.acm-edit-field input,
+.acm-conditional-label {
+ position: relative;
+ float: left;
+ clear: left;
+}
+
+.acm-edit-cond {
+ margin: 5px 0 0 15px;
+}
+
+.acm-edit-cond input {
+ margin-left: 15px;
+}
+
+.acm-conditional-label {
+ width: 100%;
+ font-weight: 700;
+ color: #333;
+ margin: 10px 0 0 15px;
+}
+
+.acm-cancel-button {
+ margin: 10px 0 30px 15px;
+}
+
+.acm-edit-button {
+ float: left;
+ margin: 10px 0 30px 15px;
}
\ No newline at end of file
diff --git a/common/js/acm.js b/common/js/acm.js
index 90787e7..b5b5560 100644
--- a/common/js/acm.js
+++ b/common/js/acm.js
@@ -13,4 +13,28 @@ jQuery( document ).ready( function( $ ) {
el.toggleClass('hidden');
});
-} );
\ No newline at end of file
+ jQuery('.ad-code-edit').click( function( $ ) {
+ var url_request = ajaxurl + jQuery(this).val();
+ var data = {
+ action: 'acm_edit_ad_code',
+ data: post_id,
+ nonce: $( '#acm_edit_ad_code_nonce' ).val()
+ };
+ $.post( ajaxurl, data, function( response ) {
+ $('.edit_acm_view').replaceWith( response );
+ } );
+ });
+ jQuery('.acm-ajax-edit').click( function($) {
+ var post_id = parseInt( jQuery(this).attr('id').split('-')[1] );
+ jQuery('.acm-edit-display').hide();
+ jQuery('.acm-record-display').show();
+ jQuery('#record_' + post_id ).hide();
+ jQuery('#acm-conditional-0 option').clone().appendTo('.cond_' + post_id );
+ jQuery('#record_display_' + post_id ).show();
+ jQuery('#acm-cancel-edit-' + post_id ).click( function($) {
+ jQuery('.acm-edit-display').hide();
+ jQuery('.acm-record-display').show();
+ });
+
+ });
+});
\ No newline at end of file
diff --git a/common/lib/acm-wp-list-table.php b/common/lib/acm-wp-list-table.php
index e08f28d..64bff0f 100644
--- a/common/lib/acm-wp-list-table.php
+++ b/common/lib/acm-wp-list-table.php
@@ -84,55 +84,109 @@ function prepare_items() {
* @return string, echo the markup of the rows
*/
function display_rows() {
+ // Alternate the table row classes for color swapping
+ $alternate = '';
- //Get the records registered in the prepare_items method
- $records = $this->items;
+ //Get the records registered in the prepare_items method
+ $records = $this->items;
- //Get the columns registered in the get_columns and get_sortable_columns methods
- list( $columns, $hidden ) = $this->get_column_info();
-
-
- //Loop for each record
- if( ! empty( $records ) ) { foreach( $records as $rec ) {
-
- //Open the line
- echo '
';
- $i = 0;
- foreach ( $columns as $column_name => $column_display_name ) {
+ //Get the columns registered in the get_columns and get_sortable_columns methods
+ list( $columns, $hidden ) = $this->get_column_info();
- //Style attributes for each col
- $class = "class='$column_name column-$column_name'";
- $style = "";
- if ( in_array( $column_name, $hidden ) ) $style = ' style="display:none;"';
- $attributes = $class . $style;
+ //Loop for each record
+ if( ! empty( $records ) ) { foreach( $records as $rec ) {
//edit link
$edit_link = add_query_arg( array(
'acm-request' => true,
'acm-action' => 'edit',
'acm_id' => (int) $rec['post_id']
- ), home_url() );
-
+ ), home_url( '/' ) );
+
+ $alternate = 'alternate' == $alternate ? '' : 'alternate';
+
+ // Gather a new set of inputs for the inline editor on each loop
+ $inline_edit_inputs = '';
+ //Open the line
+ echo '
';
+
+ if ( in_array( $column_name, $hidden ) )
+ continue;
+
+ // If this is *not* a hidden field, we also want to include it in the inline editor
+ $inline_edit_inputs .= '
When the main blog page is being displayed. This is the page which shows the time based blog content of your site, so if you've set a static Page for the Front Page (see below), then this will only be true on the Page which you set as the "Posts page" in Administration > Settings > Reading.
@@ -689,12 +703,27 @@ function admin_view_controller() {
has_tag( array( 'sharp', 'mild', 'extreme' ) )
When the current post has any of the tags in the array.
When the main blog page is being displayed. This is the page which shows the time based blog content of your site, so if you've set a static Page for the Front Page (see below), then this will only be true on the Page which you set as the "Posts page" in Administration > Settings > Reading.
@@ -622,11 +588,12 @@ function contextual_help() {
Ad Code Manager gives non-developers an interface in the WordPress admin for configuring your complex set of ad codes.
When the main blog page is being displayed. This is the page which shows the time based blog content of your site, so if you've set a static Page for the Front Page (see below), then this will only be true on the Page which you set as the "Posts page" in Administration > Settings > Reading.
When the front of the site is displayed, whether it is posts or a Page. Returns true when the main blog page is being displayed and the 'Settings > Reading ->Front page displays' is set to "Your latest posts", or when 'Settings > Reading ->Front page displays' is set to "A static page" and the "Front Page" value is the current Page being displayed.
+
When the front of the site is displayed, whether it is posts or a Page. Returns true when the main blog page is being displayed and the 'Settings > Reading ->Front page displays' is set to "Your latest posts", or when 'Settings > Reading ->Front page displays' is set to "A static page" and the "Front Page" value is the current Page being displayed.
',
- )
+ )
);
get_current_screen()->add_help_tab(
array(
'id' => 'acm-conditionals',
'title' => 'Conditionals',
'content' => $contextual_help,
- )
+ )
);
-
-
+
+
+ }
+
+ /**
+ * Register a custom widget to display ad zones
+ *
+ */
+ function register_widget() {
+ register_widget( 'ACM_ad_zones' );
}
/**
@@ -655,7 +665,7 @@ function register_ad_code( $tag, $url, $conditionals = array(), $url_vars = arra
// @todo Sanitize all of the other input
// Make sure our priority is an integer
- if ( !is_int( $priority ) )
+ if ( !is_int( $priority ) )
$priority = 10;
// Save the ad code to our set of ad codes
@@ -878,7 +888,7 @@ function validate_script_url( $url ) {
}
return $valid;
}
-
+
}
diff --git a/common/lib/acm-widget.php b/common/lib/acm-widget.php
new file mode 100644
index 0000000..a87f835
--- /dev/null
+++ b/common/lib/acm-widget.php
@@ -0,0 +1,64 @@
+ 'acm_ad_zones',
+ 'description' => 'Display Ad Code Manger ad zones in widget areas'
+ );
+ $this->WP_Widget( 'ACM_ad_zones', 'Ad Code Manager Ad Zones', $widget_ops );
+ }
+
+ //build the widget settings form
+ function form($instance) {
+ $defaults = array( 'title' => '' );
+ $instance = wp_parse_args( (array) $instance, $defaults );
+ $title = $instance['title'];
+ $zone = $instance['ad_zone'];
+ global $ad_code_manager;
+ ?>
+
+
+
+
+
+
Date: Thu, 19 Apr 2012 15:27:33 -0500
Subject: [PATCH 20/63] coding standards for widget
---
common/lib/acm-widget.php | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/common/lib/acm-widget.php b/common/lib/acm-widget.php
index a87f835..96afab1 100644
--- a/common/lib/acm-widget.php
+++ b/common/lib/acm-widget.php
@@ -2,12 +2,12 @@
/**
* ACM custom widget to choose ad tags to display in widget areas.
*
- * @since v0.1.3
+ * @since v0.2
*/
-class ACM_ad_zones extends WP_Widget {
+class ACM_Ad_Zones extends WP_Widget {
- //process the new widget
+ // Process the new widget
function ACM_ad_zones() {
$widget_ops = array(
'classname' => 'acm_ad_zones',
@@ -16,8 +16,8 @@ function ACM_ad_zones() {
$this->WP_Widget( 'ACM_ad_zones', 'Ad Code Manager Ad Zones', $widget_ops );
}
- //build the widget settings form
- function form($instance) {
+ // Build the widget settings form
+ function form( $instance ) {
$defaults = array( 'title' => '' );
$instance = wp_parse_args( (array) $instance, $defaults );
$title = $instance['title'];
@@ -26,10 +26,10 @@ function form($instance) {
?>
-
-
';
+ ob_start();
+?>
+
Ad Code Manager gives non-developers an interface in the WordPress admin for configuring your complex set of ad codes.
+
We tried to streamline the process and make everyday AdOps a little bit easier
+
Depending on ad network you use, you will see a set of required fields to fill in (generally, "Ad Code" is a set of parameters you need to pass to ad server, so it could serve proper ad). Then you set conditionals. You can create ad code with conditionals in one easy step
+
Priorities work pretty much the same way they work in WordPress. Lower numbers correspond with higher priority.
+
Once you've done creating ad codes, you can easily implement them in your theme using:
+
+add_help_tab(
array(
'id' => 'acm-overview',
diff --git a/common/js/acm.js b/common/js/acm.js
index b5b5560..425ba6d 100644
--- a/common/js/acm.js
+++ b/common/js/acm.js
@@ -37,4 +37,16 @@ jQuery( document ).ready( function( $ ) {
});
});
+ jQuery('.acm-ajax-delete').click( function($) {
+ var $this = jQuery(this);
+ var post_id = parseInt( $this.attr('id').split('-')[1] );
+ var url = '/?acm-request=true&acm-action=delete&acm-id=' + post_id;
+ var data = { 'acm-nonce': acm_ajax_nonce }
+ jQuery.post( url , data , function( response ) {
+ if (1 == response) {
+ $this.parents('tr').hide('fast');
+ }
+ } );
+
+ });
});
\ No newline at end of file
From 69d3671519bbc4f1c174a1745aeac991f7d226cb Mon Sep 17 00:00:00 2001
From: Rinat Khaziev
Date: Thu, 19 Apr 2012 20:11:38 -0500
Subject: [PATCH 26/63] fix readme urls
---
readme.txt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/readme.txt b/readme.txt
index f9587e1..47e1c4a 100644
--- a/readme.txt
+++ b/readme.txt
@@ -15,9 +15,9 @@ To set things up, you'll need to add small template tags to your theme where you
Once this code-level configuration is in place, the Ad Code Manager admin interface will allow you to add new ad codes, modify the parameters for your script URL, and define conditionals to determine when the ad code appears. Conditionals are core WordPress functions like is_page(), is_category(), or your own custom functions.
-Ad Code Manager currently works with Doubleclick for Publishers and [we'd like to abstract it to other providers](https://github.com/danielbachhuber/Ad-Code-Manager/issues/4)
+Ad Code Manager currently works with Doubleclick for Publishers and [we'd like to abstract it to other providers](https://github.com/Automattic/Ad-Code-Manager/issues/4)
-[Fork the plugin on Github](https://github.com/danielbachhuber/Ad-Code-Manager) and [follow our development blog](http://adcodemanager.wordpress.com/).
+[Fork the plugin on Github](https://github.com/Automattic/Ad-Code-Manager) and [follow our development blog](http://adcodemanager.wordpress.com/).
== Installation ==
From 75f9354e9e02b94c2657e935f6cbd496820a6188 Mon Sep 17 00:00:00 2001
From: Jeremy Felt
Date: Thu, 19 Apr 2012 21:01:28 -0700
Subject: [PATCH 27/63] Fix PHP warning when no items have been added
PHP was throwing a warning "array_slice() expects parameter 1 to be
array, boolean given", when $this->items was empty.
Add a check for an empty array and return early if it matches. Allows the
no records found message to display.
---
common/lib/acm-wp-list-table.php | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/common/lib/acm-wp-list-table.php b/common/lib/acm-wp-list-table.php
index 15d69c2..6e45426 100644
--- a/common/lib/acm-wp-list-table.php
+++ b/common/lib/acm-wp-list-table.php
@@ -37,7 +37,10 @@ function get_columns() {
function prepare_items() {
//global $wpdb, $_wp_column_headers;
$screen = get_current_screen();
-
+
+ if ( empty( $this->items ) )
+ return;
+
/* -- Pagination parameters -- */
//Number of elements in your table?
$totalitems = count( $this->items ); //return the total number of affected rows
From 76450e6679a737380802a5d05a0041011728b81b Mon Sep 17 00:00:00 2001
From: Jeremy Felt
Date: Thu, 19 Apr 2012 22:04:30 -0700
Subject: [PATCH 28/63] Add Ability to delete conditionals via inline editor
Connect the hooks to delete conditionals through the inline editor. Allows
removal of all but one of the conditionals as the current requirement for
saving conditionals is that the incoming array not be empty. Whenever only
one conditional is present, the 'x' to delete does not show.
Changes some of the edit_conditionals code to not care about the existing
indexing as things are unpredictable otherwise. We could probably maintain
the index before form submission, but I don't think any problem arises
from just ignoring it.
---
ad-code-manager.php | 6 +++---
common/css/acm.css | 13 +++++++++++++
common/js/acm.js | 15 +++++++++++++--
common/lib/acm-wp-list-table.php | 7 ++++---
4 files changed, 33 insertions(+), 8 deletions(-)
diff --git a/ad-code-manager.php b/ad-code-manager.php
index 29cea27..2d0dfb7 100644
--- a/ad-code-manager.php
+++ b/ad-code-manager.php
@@ -457,13 +457,13 @@ function create_conditional( $ad_code_id, $conditional ) {
*/
function edit_conditionals( $ad_code_id, $conditionals = array() ) {
if ( 0 !== $ad_code_id && !empty( $conditionals ) ) {
- foreach( $conditionals as $index => $conditional ) {
- $conditionals[$index] = array(
+ foreach( $conditionals as $conditional ) {
+ $new_conditionals[] = array(
'function' => $conditional['function'],
'arguments' => (array) $conditional['arguments'],
);
}
- return update_post_meta( $ad_code_id, 'conditionals', $conditionals );
+ return update_post_meta( $ad_code_id, 'conditionals', $new_conditionals );
}
}
diff --git a/common/css/acm.css b/common/css/acm.css
index 22c436b..1b8b923 100755
--- a/common/css/acm.css
+++ b/common/css/acm.css
@@ -81,4 +81,17 @@ tr:hover .row-actions {
.acm-edit-button {
float: left;
margin: 10px 0 30px 15px;
+}
+
+.acm-x-cond {
+ font-size: 14px;
+ padding-left: 5px;
+ color: #888;
+ cursor: pointer;
+ font-family: sans-serif
+}
+
+.acm-x-cond:hover {
+ color: #333;
+ text-decoration: underline;
}
\ No newline at end of file
diff --git a/common/js/acm.js b/common/js/acm.js
index 425ba6d..c5224b7 100644
--- a/common/js/acm.js
+++ b/common/js/acm.js
@@ -35,7 +35,17 @@ jQuery( document ).ready( function( $ ) {
jQuery('.acm-edit-display').hide();
jQuery('.acm-record-display').show();
});
-
+ if ( 1 == jQuery('.acm-edit-cond', '#record_display_' + post_id ).length ) {
+ jQuery('.acm-x-cond', '#record_display_' + post_id ).remove();
+ } else {
+ jQuery('.acm-x-cond').click( function($) {
+ var record_id = parseInt( jQuery(this).attr('id').split('-')[1] );
+ jQuery('#acm-edit-cond-' + record_id ).remove();
+ if ( 1 == jQuery('.acm-edit-cond', '#record_display_' + post_id ).length ) {
+ jQuery('.acm-x-cond', '#record_display_' + post_id ).remove();
+ }
+ });
+ }
});
jQuery('.acm-ajax-delete').click( function($) {
var $this = jQuery(this);
@@ -48,5 +58,6 @@ jQuery( document ).ready( function( $ ) {
}
} );
- });
+ });
+
});
\ No newline at end of file
diff --git a/common/lib/acm-wp-list-table.php b/common/lib/acm-wp-list-table.php
index 6e45426..01dda17 100644
--- a/common/lib/acm-wp-list-table.php
+++ b/common/lib/acm-wp-list-table.php
@@ -161,15 +161,16 @@ function display_rows() {
$inline_edit_conditionals = '';
if ( ! empty( $conditionals ) ) {
for( $j=0, $total = sizeof( $conditionals ); $j < $total; $j++ ) {
- $inline_edit_conditionals .= '
';
- if ( in_array( $column_name, $hidden ) )
+ if ( in_array( $column_name, $hidden ) || $key == 'conditionals' )
continue;
// If this is *not* a hidden field, we also want to include it in the inline editor
@@ -156,8 +163,6 @@ function display_rows() {
//Close the line
echo'
';
- // Gather the conditional functions/arguments
- $conditionals = get_post_meta( $rec[ 'post_id' ], 'conditionals', true );
$inline_edit_conditionals = '';
if ( ! empty( $conditionals ) ) {
for( $j=0, $total = sizeof( $conditionals ); $j < $total; $j++ ) {
diff --git a/providers/doubleclick-for-publishers.php b/providers/doubleclick-for-publishers.php
index c909851..79f56c6 100644
--- a/providers/doubleclick-for-publishers.php
+++ b/providers/doubleclick-for-publishers.php
@@ -81,10 +81,11 @@ function __construct() {
*/
function get_columns() {
return $columns = array(
- 'col_acm_post_id'=>__( 'ID' ),
- 'col_acm_site_name'=>__( 'Site Name' ),
- 'col_acm_zone1'=>__( 'Zone1' ),
- 'col_acm_priority'=>__( 'Priority' ),
+ 'col_acm_post_id' =>__( 'ID' ),
+ 'col_acm_site_name' =>__( 'Site Name' ),
+ 'col_acm_zone1' =>__( 'Zone1' ),
+ 'col_acm_priority' =>__( 'Priority' ),
+ 'col_acm_conditionals' => __( 'Conditionals', 'ad-code-manager' ),
);
}
}
From 27ae825967d137c1fab68bbfcad05f9150b17bcf Mon Sep 17 00:00:00 2001
From: Daniel Bachhuber
Date: Mon, 23 Apr 2012 17:14:01 -0700
Subject: [PATCH 37/63] First pass at refactoring the WP_List_Table
implementation.
Higher-level notes:
* Abstracted much of display_rows() into individual, class-level methods that can be plugged and played
* Removed unnecessary prefixes from the columns
* Allow columns to be filtered if the user chooses to extend that way
Inline editing still needs to be plugged back in.
See #23
---
common/lib/acm-wp-list-table.php | 215 ++++++++++-------------
providers/doubleclick-for-publishers.php | 42 ++++-
2 files changed, 124 insertions(+), 133 deletions(-)
diff --git a/common/lib/acm-wp-list-table.php b/common/lib/acm-wp-list-table.php
index 97ed809..2e63196 100644
--- a/common/lib/acm-wp-list-table.php
+++ b/common/lib/acm-wp-list-table.php
@@ -24,12 +24,13 @@ function __construct( $params = array() ) {
* @return array $columns, the array of columns to use with the table
*/
function get_columns() {
- return $columns = array(
- 'col_acm_id' => __( 'ID', 'ad-code-manager' ),
- 'col_acm_name' => __( 'Name', 'ad-code-manager' ),
- 'col_acm_priority' => __( 'Priority', 'ad-code-manager' ),
- 'col_acm_conditionals' => __( 'Conditionals', 'ad-code-manager' ),
+ $columns = array(
+ 'id' => __( 'ID', 'ad-code-manager' ),
+ 'name' => __( 'Name', 'ad-code-manager' ),
+ 'priority' => __( 'Priority', 'ad-code-manager' ),
+ 'conditionals' => __( 'Conditionals', 'ad-code-manager' ),
);
+ return apply_filters( 'acm_list_table_columns', $columns );
}
/**
@@ -50,7 +51,7 @@ function prepare_items() {
$perpage = 25;
//Which page is this?
- $paged = !empty($_GET["paged"]) ? mysql_real_escape_string($_GET["paged"]) : '';
+ $paged = !empty( $_GET["paged"] ) ? intval( $_GET["paged"] ) : '';
//Page Number
if(empty($paged) || !is_numeric($paged) || $paged<=0 ){ $paged=1; }
@@ -74,7 +75,10 @@ function prepare_items() {
/* -- Register the Columns -- */
$columns = $this->get_columns();
- $this->_column_headers = array($columns, array( 'col_acm_post_id' ), $this->get_sortable_columns() ) ;
+ $hidden = array(
+ 'id',
+ );
+ $this->_column_headers = array( $columns, $hidden, $this->get_sortable_columns() ) ;
/**
* Items are set in Ad_Code_Manager class
@@ -84,124 +88,85 @@ function prepare_items() {
}
/**
- * Display the rows of records in the table
- * @return string, echo the markup of the rows
+ * Message to be displayed if there are no ad codes found
+ *
+ * @since 0.2
*/
- function display_rows() {
- // Alternate the table row classes for color swapping
- $alternate = '';
-
- //Get the records registered in the prepare_items method
- $records = $this->items;
-
- //Get the columns registered in the get_columns and get_sortable_columns methods
- list( $columns, $hidden ) = $this->get_column_info();
-
- //Loop for each record
- if( ! empty( $records ) ) { foreach( $records as $rec ) {
-
- // Gather the conditional functions/arguments
- $conditionals = get_post_meta( $rec[ 'post_id' ], 'conditionals', true );
-
- //edit link
- $edit_link = add_query_arg( array(
- 'acm-request' => true,
- 'acm-action' => 'edit',
- 'acm-id' => (int) $rec['post_id']
- ), home_url( '/' ) );
-
- $alternate = 'alternate' == $alternate ? '' : 'alternate';
-
- // Gather a new set of inputs for the inline editor on each loop
- $inline_edit_inputs = '';
-
- //Open the line
- echo '
';
-
- if ( in_array( $column_name, $hidden ) || $key == 'conditionals' )
- continue;
-
- // If this is *not* a hidden field, we also want to include it in the inline editor
- $inline_edit_inputs .= '