Plugin Directory

Changeset 324319


Ignore:
Timestamp:
12/19/2010 02:10:06 PM (15 years ago)
Author:
rjune
Message:

Tagging 0.6

Location:
ad-engine
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • ad-engine/trunk/ad-engine.php

    r321647 r324319  
    44Plugin URI: http://www.oriontechnologysolutions.com/web-design/ad-engine
    55Description: Ad Engine Let's you insert image or text ads using shortcode or widgets.
    6 Version: 0.5
     6Version: 0.6
    77Author: Orion Technology Solutions
    88Author URI: http://www.oriontechnologysolutions.com/
     
    149149
    150150    $tmp['ad_shown']++;
     151    ad_update_count($ad_id, 1);
    151152    update_option('ad_engine_' . $tmp['ad_id'] , $tmp);
    152153
     
    250251
    251252function ad_engine_form() {
    252   global $_POST;
    253   $jads = ad_engine_get_counts();
    254   $ad_deck = ad_engine_get_ad_deck();
    255 
    256 
    257   $output = "<div class='wrap'><h2>";
    258   $output .= __("Advertisements","Advertisements");
    259   $output .= "<a class=\"button add-new-h2\" href=\"" . admin_url("admin.php?page=ad-engine-new") ."\">Add New</a>";
    260   $output .= "</h2><p>";
    261   $output .= "\n<table class='widefat post fixed'>\n<thead><tr><th>Name</th><th>Ad Group</th><th>Client</th><th>Impressions</th><th>Clicks</th><th>Actions</th></tr></thead><tbody>\n";
    262 
    263   for($iter = 0; $iter < count($ad_deck); $iter++) {
    264     $cl = get_option('ad_engine_client_' . $ad_deck[$iter]['ad_client']);
    265     $ct = get_option('ad_engine_cat_' . $ad_deck[$iter]['ad_cat']);
    266     $ad_deck[$iter]['cat_name'] = $ct['name'];
    267     $ad_deck[$iter]['co_name']  = $cl['name'];
    268   }
    269   uasort($ad_deck, ad_engine_ad_cmp);
    270 
    271   while($ad = array_shift($ad_deck)) {
    272     $output .= sprintf("\n<tr><td><a href='%s'>%s</a></td><td>%s</td><td>%s</td><td>%s / %s</td><td>%d (%0.2f%%)</td><td><a class='submitdelete' href='%s'>Delete</a></td></tr>"
    273                        , admin_url("admin.php?page=ad-engine-edit&id=" . $ad['ad_id'])
    274                        , $ad['ad_name']
    275                        , $ad['cat_name']
    276                        , $ad['co_name']
    277                        , $ad['ad_shown']
    278                        , $ad['ad_imp']
    279                        , $ad['ad_clicks']
    280                        , ($ad['ad_shown']) ? ($ad['ad_clicks'] / $ad['ad_shown'] * 100) : 0
    281                        , admin_url("admin.php?page=ad-engine-menu&action=ad_delete&id=" . $ad['ad_id'])
    282                       );
    283   }
    284   $output .= '</tbody></table></div>';
    285   echo $output;
     253    global $_POST, $wpdb;
     254    $jads = ad_engine_get_counts();
     255    $ad_deck = ad_engine_get_ad_deck();
     256    $dstamp = date("Y-m-d");
     257
     258    $output = "<div class='wrap'><h2>";
     259    $output .= __("Advertisements","Advertisements");
     260    $output .= "<a class=\"button add-new-h2\" href=\"" . admin_url("admin.php?page=ad-engine-new") ."\">Add New</a>";
     261    $output .= "</h2><p><script type='text/javascript'>
     262function confirm_delete(ad) {
     263    rval = confirm(\"Really delete the ad \\n\" + ad.ad_name);
     264    if(rval == true) {
     265        document.location = '" . admin_url("admin.php?page=ad-engine-menu&action=ad_delete&id=") . "' + ad.ad_id;
     266    }
     267}
     268</script>";
     269    $output .= "\n<table class='widefat post fixed'>\n<thead><tr><th>Name</th><th>Ad Group</th><th>Client</th><th>Impressions<br/>Today</th><th>Impressions<br/>Total</th><th>Clicks<br />Today</th><th>Clicks<br />Total</th><th>Actions</th></tr></thead><tbody>\n";
     270
     271    for($iter = 0; $iter < count($ad_deck); $iter++) {
     272      $cl = get_option('ad_engine_client_' . $ad_deck[$iter]['ad_client']);
     273      $ct = get_option('ad_engine_cat_' . $ad_deck[$iter]['ad_cat']);
     274      $ad_deck[$iter]['cat_name'] = $ct['name'];
     275      $ad_deck[$iter]['co_name']  = $cl['name'];
     276    }
     277    uasort($ad_deck, ad_engine_ad_cmp);
     278
     279    while($ad = array_shift($ad_deck)) {
     280        $dimps = $wpdb->get_var('SELECT count from ad_engine where type=1 AND dstamp="' . $dstamp . '" AND id = ' . $ad['ad_id']);
     281        if(!isset($dimps))
     282            $dimps = 0;
     283        $timps = $wpdb->get_var('SELECT sum(count) from ad_engine where type=1 AND id = ' . $ad['ad_id']);
     284        if(!isset($timps))
     285            $timps = 0;
     286        $dclicks = $wpdb->get_var('SELECT count from ad_engine where type=2 AND dstamp="' . $dstamp . '" AND id = ' . $ad['ad_id']);
     287        if(!isset($dclicks))
     288            $dclicks = 0;
     289        $tclicks = $wpdb->get_var('SELECT sum(count) from ad_engine where type=2 AND id = ' . $ad['ad_id']);
     290        if(!isset($tclicks))
     291            $tclicks = 0;
     292
     293        $output .= sprintf("\n<tr><td><a href='%s'>%s</a></td><td>%s</td><td>%s</td><td>%s</td><td>%s / %s</td><td>%d (%0.2f%%)</td><td>%d (%0.2f%%)</td><td><a href='%s'>CSV</a> <a class='submitdelete' onclick='confirm_delete(%s)' href='javascript:'>Delete</a></td></tr>"
     294                         , admin_url("admin.php?page=ad-engine-edit&id=" . $ad['ad_id'])
     295                         , $ad['ad_name']
     296                         , $ad['cat_name']
     297                         , $ad['co_name']
     298                         , $dimps
     299                         , $timps
     300                         , $ad['ad_imp']
     301                         , $dclicks
     302                         , ($dimps) ? ($dclicks / $dimps * 100) : 0
     303                         , $tclicks
     304                         , ($ad['ad_shown']) ? ($ad['ad_clicks'] / $ad['ad_shown'] * 100) : 0
     305                         , site_url("?ae_get_csv=" . $ad['ad_id'])
     306                         , json_encode($ad)
     307                         /*, admin_url("admin.php?page=ad-engine-menu&action=ad_delete&id=" . $ad['ad_id'])*/
     308                        );
     309    }
     310    $output .= '</tbody></table></div>';
     311    echo $output;
    286312}
    287313
     
    439465}
    440466
     467function ad_update_count($id, $type) {
     468    global $wpdb;
     469    $dstamp = date("Y-m-d");
     470    $sql = 'select count from ad_engine where dstamp="' . $dstamp . '" AND type='. $type . ' AND id=' . intval($id);
     471    $count = $wpdb->get_var($wpdb->prepare($sql));
     472    if(isset($count))
     473        $sql = 'update ad_engine set count = ' . ($count + 1) . ' where dstamp="' . $dstamp . '" AND type=' . $type . ' AND id=' . intval($id);
     474    else
     475        $sql = 'INSERT INTO ad_engine set count = 1, dstamp="' . $dstamp . '", type=' . $type . ', id=' . intval($id);
     476    $wpdb->query($wpdb->prepare($sql));
     477}
    441478
    442479function ad_engine_init() {
     480    global $wpdb;
    443481    $jads = ad_engine_get_counts();
     482
     483    $table = $wpdb->get_var('SHOW TABLES LIKE "ad_engine"');
     484    if($table == '') {
     485        $wpdb->query('CREATE TABLE ad_engine ( id INT, dstamp DATE, count INT, type INT)');
     486    }
    444487
    445488    if(isset($_GET['cancel']) || isset($_POST['cancel'])) {
    446489        return;
     490    }
     491    else if(isset($_GET['ae_get_csv'])) {
     492        header('Content-type: text/plain');
     493        printf('"Date","Impressions","Clicks"');
     494        $ad_metrics = $wpdb->get_results($wpdb->prepare('SELECT * from ad_engine where id=' . $_GET['ae_get_csv'] . ' order by dstamp,type limit 1000;'));
     495        $dstamp = 0;
     496        foreach($ad_metrics as $daily) {
     497            if($dstamp != $daily->dstamp) {
     498                if($type == 2)
     499                    echo ',0';
     500                $type = 1;
     501                $dstamp = $daily->dstamp;
     502                echo "\n\"" . $dstamp . '"';
     503               
     504            }
     505            if($daily->type == $type) {
     506                $type++;
     507                echo ",\"" . $daily->count . '"';
     508            }
     509            else
     510                echo "\"0\",\"" . $daily->count . '"';
     511        }
     512        if($type == 2)
     513            echo ',"0"';
     514        die();
     515    }
     516    else if(isset($_GET['ae_ad_clicked'])) {
     517        ad_update_count($_GET['ae_ad_clicked'], 2);
    447518    }
    448519    else if(isset($_GET['ae_get_data'])) {
     
    641712        $fname = $ad_data['img'];
    642713        $text = $ad_data['text'];
    643 
     714        if(isset($fname) && $fname != '') {
     715            $img = "<img src='" . $fname . "' />";
     716        }
     717        if(isset($text) && $text != '') {
     718            $caption = "<span class='ad_caption'>" . $text . "</span>";
     719        }
     720
     721                /* reference <a id='ad_engine_ad_%d' target='_blank' href='%s?ae_redirect=%d'>%s%s</a> */
    644722        $output .= sprintf("%s<ul class='ad'>
    645723                <li class='image'>
    646                   <a id='ad_engine_ad_%d' target='_blank' href='%s?ae_redirect=%d'><img src='%s'><span class='ad_caption'>%s</span></a>
     724                  <a id='ad_engine_ad_%d' target='_blank' href='%s' onclick='jQuery.get(\"%s?ae_ad_clicked=%s\")'>%s%s</a>
    647725                </li>
    648726              </ul>"
    649727             , $javascript
    650728             , $ad_slot
     729             , $r_ad['ad_link']
    651730             , site_url()
    652731             , $r_ad['ad_id']
    653              , $fname
    654              , $text
     732             , $img
     733             , $caption
    655734            );
    656735        $ad_slot++;
  • ad-engine/trunk/readme.txt

    r321656 r324319  
    3535== Changelog ==
    3636
     37= 0.6 =
     38* Delete ad now asks for confirmation
     39* Impressions and clicks are tracked per day
     40* CSV download capable
     41* Text links now refer to the target site.
     42
    3743= 0.5 =
    3844* Added align=[left|right] to shortcode support
Note: See TracChangeset for help on using the changeset viewer.