Changeset 324319
- Timestamp:
- 12/19/2010 02:10:06 PM (15 years ago)
- Location:
- ad-engine
- Files:
-
- 3 added
- 2 edited
-
tags/0.6 (added)
-
tags/0.6/ad-engine.php (added)
-
tags/0.6/readme.txt (added)
-
trunk/ad-engine.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ad-engine/trunk/ad-engine.php
r321647 r324319 4 4 Plugin URI: http://www.oriontechnologysolutions.com/web-design/ad-engine 5 5 Description: Ad Engine Let's you insert image or text ads using shortcode or widgets. 6 Version: 0. 56 Version: 0.6 7 7 Author: Orion Technology Solutions 8 8 Author URI: http://www.oriontechnologysolutions.com/ … … 149 149 150 150 $tmp['ad_shown']++; 151 ad_update_count($ad_id, 1); 151 152 update_option('ad_engine_' . $tmp['ad_id'] , $tmp); 152 153 … … 250 251 251 252 function 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'> 262 function 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; 286 312 } 287 313 … … 439 465 } 440 466 467 function 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 } 441 478 442 479 function ad_engine_init() { 480 global $wpdb; 443 481 $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 } 444 487 445 488 if(isset($_GET['cancel']) || isset($_POST['cancel'])) { 446 489 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); 447 518 } 448 519 else if(isset($_GET['ae_get_data'])) { … … 641 712 $fname = $ad_data['img']; 642 713 $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> */ 644 722 $output .= sprintf("%s<ul class='ad'> 645 723 <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> 647 725 </li> 648 726 </ul>" 649 727 , $javascript 650 728 , $ad_slot 729 , $r_ad['ad_link'] 651 730 , site_url() 652 731 , $r_ad['ad_id'] 653 , $ fname654 , $ text732 , $img 733 , $caption 655 734 ); 656 735 $ad_slot++; -
ad-engine/trunk/readme.txt
r321656 r324319 35 35 == Changelog == 36 36 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 37 43 = 0.5 = 38 44 * Added align=[left|right] to shortcode support
Note: See TracChangeset
for help on using the changeset viewer.