minimus / simple-ads-manager

Advertisement rotation system for Wordpress with a flexible logic of displaying advertisements.
16 stars 15 forks source link

If get_header isn't called then zones and places return nothing #24

Open mark-netalico opened 9 years ago

mark-netalico commented 9 years ago

I use the manager in a custom rotating ajax way so I call a page in the background with a really basic page that only consists of the ads html.

In one of the latest versions I've found if you call a page without get_header() then the zones and places never return content. How can I fix that without having to call the entire get_header()?

rmorse commented 8 years ago

I'm not sure what the issue is here but ran in to something similar.

I upgraded from quite an old version which was working fine (calling ads via ajax via dynamic_sidebar) which stopped working.

So I opted to use the ads place function directly:

if(function_exists('drawAdsPlace')){

    drawAdsPlace(array('id' => 5), true);
} 

Which was still not working.

After doing a bit of digging in the code (ad.class.php) I found that

if ( is_null( $this->clauses ) ) {

is always true in my ajax calls which means an ad is never returned.

I'm not sure if this is to do with inproper detection of admin areas or ajax but I found a little hack that worked for me.

In ad.class.php

Around line 301, replace:

if ( is_null( $this->clauses ) ) {
    return '';
}

with

if ( is_null( $this->clauses ) ) {

    if (( defined( 'DOING_AJAX' ) && DOING_AJAX ) || (is_admin()))
    {
        $this->clauses = array();

        $this->clauses['WC'] = '(IF(sa.ad_users = 0, TRUE, IF(sa.ad_users_reg = 1, IF(sa.x_ad_users = 1, NOT FIND_IN_SET("admin", sa.x_view_users), TRUE) AND IF(sa.ad_users_adv = 1, (sa.adv_nick <> "admin"), TRUE), FALSE))) AND ((sa.view_type = 1) OR (sa.view_type = 0 AND (sa.view_pages+0 & 1))) AND (sa.ad_cats = 0)  AND (sa.ad_authors = 0)       ';
        $this->clauses['WCT'] = ' AND IF(sa.ad_schedule, CURDATE() BETWEEN sa.ad_start_date AND sa.ad_end_date, TRUE) AND IF(sa.limit_hits, sa.hits_limit > (SELECT IFNULL(COUNT(*), 0) FROM fi_sam_stats ss WHERE ss.id = sa.id AND ss.event_type = 0), TRUE) AND IF(sa.limit_clicks, sa.clicks_limit > (SELECT IFNULL(COUNT(*), 0) FROM fi_sam_stats ss WHERE ss.id = sa.id AND ss.event_type = 1), TRUE)';
        $this->clauses['WCW'] = ' AND IF(sa.ad_weight > 0, (sa.ad_weight_hits*10/(sa.ad_weight*1000)) < 1, FALSE)';
        $this->clauses['WC2W'] = 'AND (sa.ad_weight > 0)';
    }
    else
    {
        return '';
    }

}

Basically I got htese values from doing a var_dump on my code (where ads were successfully being shown) and then adding in the clauses manually

It definitely a dirty workaround though, hope this gets fixed soon.

Thanks