Skip to content

Commit

Permalink
merge fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinat Khaziev committed Jan 17, 2012
1 parent ed5abd2 commit 01c371e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions ad-code-manager.php
Expand Up @@ -253,10 +253,10 @@ function get_ad_codes_ajax() {
function get_ad_codes() {
$ad_codes_formatted = array();
$ad_codes = get_posts( array( 'post_type' => $this->post_type ) );

foreach ( $ad_codes as $ad_code_cpt ) {
$ad_codes_formatted[] = array(
'conditionals' => $this->get_conditionals( $ad_code_cpt->ID ),
'conditionals' => $this->get_conditionals( intval( $ad_code_cpt->ID ) ),
'url_vars' => array(
'site_name' => get_post_meta( $ad_code_cpt->ID, 'site_name', true ),
'zone1' => get_post_meta( $ad_code_cpt->ID, 'zone1', true ),
Expand Down Expand Up @@ -379,14 +379,13 @@ function delete_ad_code( $ad_code_id ) {
function create_conditional( $ad_code_id, $conditional ) {
if ( 0 !== intval( $ad_code_id ) && !empty( $conditional ) ) {
$ad_code_id = intval( $ad_code_id );
$existing_conditionals = (array) get_post_meta( $ad_code_id, 'conditionals', true );
$existing_conditionals = get_post_meta( $ad_code_id, 'conditionals', true ); // this can't be casted to array, if string is empty, breaks jqGrid
if ( ! is_array( $existing_conditionals ) ) {
$existing_conditionals = array();
}
$existing_conditionals[] = array(
'function' => $conditional[ 'function' ],
'arguments' => (array) $conditional[ 'arguments' ], // @todo explode
'result' => true // kill me
);
update_post_meta( $ad_code_id, 'conditionals', $existing_conditionals );
}
Expand Down Expand Up @@ -555,10 +554,13 @@ function register_ad_codes( $ad_codes = array() ) {
'url_vars' => array(),
);
$ad_code = array_merge( $default, $ad_code );

foreach ( (array)$this->ad_tag_ids as $default_tag ) {
$ad_code = array_merge( $ad_code, $default_tag );

// May be we should add plugin setting for default url. For now just apply the filter which should return default url if $ad_code['url'] is empty
$this->register_ad_code( $ad_code['tag'], apply_filters( 'acm_empty_url', $ad_code['url'] ), $ad_code['conditionals'], $ad_code['url_vars'] );
// messy
$this->register_ad_code( $default_tag['tag'], apply_filters( 'acm_empty_url', $ad_code['url'] ), $ad_code['conditionals'], $ad_code['url_vars'] );
}
}
}
Expand Down Expand Up @@ -590,7 +592,6 @@ function action_acm_tag( $tag_id ) {
$display_codes[] = $ad_code;
continue;
}

$include = true;
foreach( $ad_code['conditionals'] as $conditional ) {
// If the conditional was passed as an array, then we have a complex rule
Expand Down Expand Up @@ -627,11 +628,10 @@ function action_acm_tag( $tag_id ) {
$result = call_user_func_array( $cond_func, (array)$cond_args );
else
$result = call_user_func( $cond_func );

// If our results don't match what we need, don't include this ad code
if ( $cond_result !== $result )
$include = false;

//
// If we have matching conditional and $this->logical_operator equals OR just break from the loop and do not try to evaluate others
if ( $include && $this->logical_operator == 'OR' )
Expand Down Expand Up @@ -666,6 +666,7 @@ function action_acm_tag( $tag_id ) {
foreach( (array)$output_tokens as $token => $val ) {
$output_html = str_replace( $token, $val, $output_html );
}

// Print the ad code
echo $output_html;
}
Expand Down

0 comments on commit 01c371e

Please sign in to comment.