WP125 - Version 1.2.0

Version Description

Download this release

Release Info

Developer redwallhp
Plugin Icon wp plugin WP125
Version 1.2.0
Comparing to
See all releases

Code changes from version 1.1.5 to 1.2.0

Files changed (4) hide show
  1. adminmenus.php +14 -6
  2. installer.php +7 -3
  3. readme.txt +7 -2
  4. wp125.php +115 -81
adminmenus.php CHANGED
@@ -27,12 +27,12 @@ if ($_GET['wp125action'] == "activateconf") {
27
  $theid = $_GET['theid'];
28
  global $wpdb, $table_prefix;
29
  $adtable_name = $wpdb->prefix . "wp125_ads";
30
- $wpdb->query("UPDATE $adtable_name SET status = '1' WHERE id = '$theid'");
31
  echo '<div id="message" class="updated fade"><p>Ad activated.</p></div>';
32
  }
33
 
34
  echo '<ul class="subsubsub">'; ?>
35
- <li><a href="admin.php?page=wp125/wp125.php" <?php if ($_GET['showmanage'] != 'inactive') { echo 'class="current"'; } ?>>Active Ads</a> |</li><li><a href="admin.php?page=wp125/wp125.php&showmanage=inactive" <?php if ($_GET['showmanage'] == 'inactive') { echo 'class="current"'; } ?>>Inactive Ads</a></li>
36
  <?php echo '</ul>
37
  <table class="widefat">
38
  <thead><tr>
@@ -42,7 +42,7 @@ echo '<ul class="subsubsub">'; ?>
42
  <th scope="col">Start Date</th>
43
  <th scope="col">End Date</th>
44
  <th scope="col"></th>
45
- <th scope="col"></th>
46
  </tr></thead>
47
  <tbody>';
48
 
@@ -234,6 +234,7 @@ $post_salespage = $wpdb->escape($_POST['salespage']);
234
  $post_widgettitle = $wpdb->escape($_POST['widgettitle']);
235
  $post_defaultstyle = $wpdb->escape($_POST['defaultstyle']);
236
  $post_emailonexp = $wpdb->escape($_POST['emailonexp']);
 
237
  $post_defaultad = $wpdb->escape($_POST['defaultad']);
238
  if ($post_defaultstyle!='on') { $post_defaultstyle = 'yes'; } else { $post_defaultstyle = ''; }
239
  update_option("wp125_ad_orientation", $post_adorient);
@@ -243,6 +244,7 @@ update_option("wp125_buyad_url", $post_salespage);
243
  update_option("wp125_widget_title", $post_widgettitle);
244
  update_option("wp125_disable_default_style", $post_defaultstyle);
245
  update_option("wp125_emailonexp", $post_emailonexp);
 
246
  update_option("wp125_defaultad", $post_defaultad);
247
  echo '<div id="message" class="updated fade"><p>Settings updated.</p></div>';
248
  }
@@ -255,6 +257,7 @@ $setting_widget_title = get_option("wp125_widget_title");
255
  $setting_disable_default_style = get_option("wp125_disable_default_style");
256
  $setting_emailonexp = get_option("wp125_emailonexp");
257
  $setting_defaultad = get_option("wp125_defaultad");
 
258
  ?><div class="wrap">
259
  <h2>Settings</h2>
260
  <form method="post" action="admin.php?page=wp125_settings">
@@ -286,12 +289,12 @@ $setting_defaultad = get_option("wp125_defaultad");
286
 
287
  <tr valign="top">
288
  <th scope="row">Widget Title</th>
289
- <td><input name="widgettitle" type="text" id="widgettitle" value="<?php echo $setting_widget_title; ?>" size="50" /><br/>The title to be displayed in the widget. (Leave blank to disable)</td>
290
  </tr>
291
 
292
  <tr valign="top">
293
  <th scope="row">Ad Sales Page</th>
294
- <td><input name="salespage" type="text" id="salespage" value="<?php echo $setting_buyad_url; ?>" size="50" /><br/>Do you have a page with statistics and prices? (Default Ads will link here)</td>
295
  </tr>
296
 
297
  <tr valign="top">
@@ -301,7 +304,12 @@ $setting_defaultad = get_option("wp125_defaultad");
301
 
302
  <tr valign="top">
303
  <th scope="row">Expiration Email</th>
304
- <td><input name="emailonexp" type="text" id="emailonexp" value="<?php echo $setting_emailonexp; ?>" size="50" /><br/>Enter your email address if you would like to be emailed when an ad expires. (Leave blank to disable)</td>
 
 
 
 
 
305
  </tr>
306
 
307
  <tr valign="top">
27
  $theid = $_GET['theid'];
28
  global $wpdb, $table_prefix;
29
  $adtable_name = $wpdb->prefix . "wp125_ads";
30
+ $wpdb->query("UPDATE $adtable_name SET status = '1', SET pre_exp_email='0' WHERE id = '$theid'");
31
  echo '<div id="message" class="updated fade"><p>Ad activated.</p></div>';
32
  }
33
 
34
  echo '<ul class="subsubsub">'; ?>
35
+ <li><a href="admin.php?page=wp125/wp125.php" <?php if ($_GET['showmanage'] != 'inactive') { echo 'class="current"'; } ?>>Active Ads</a> | </li><li><a href="admin.php?page=wp125/wp125.php&showmanage=inactive" <?php if ($_GET['showmanage'] == 'inactive') { echo 'class="current"'; } ?>>Inactive Ads</a></li>
36
  <?php echo '</ul>
37
  <table class="widefat">
38
  <thead><tr>
42
  <th scope="col">Start Date</th>
43
  <th scope="col">End Date</th>
44
  <th scope="col"></th>
45
+ <th scope="col" style="text-align:right;"><a href="admin.php?page=wp125_addedit" class="button rbutton">Add New</a></th>
46
  </tr></thead>
47
  <tbody>';
48
 
234
  $post_widgettitle = $wpdb->escape($_POST['widgettitle']);
235
  $post_defaultstyle = $wpdb->escape($_POST['defaultstyle']);
236
  $post_emailonexp = $wpdb->escape($_POST['emailonexp']);
237
+ $post_daysbeforeexp = $wpdb->escape($_POST['daysbeforeexp']);
238
  $post_defaultad = $wpdb->escape($_POST['defaultad']);
239
  if ($post_defaultstyle!='on') { $post_defaultstyle = 'yes'; } else { $post_defaultstyle = ''; }
240
  update_option("wp125_ad_orientation", $post_adorient);
244
  update_option("wp125_widget_title", $post_widgettitle);
245
  update_option("wp125_disable_default_style", $post_defaultstyle);
246
  update_option("wp125_emailonexp", $post_emailonexp);
247
+ update_option("wp125_daysbeforeexp", $post_daysbeforeexp);
248
  update_option("wp125_defaultad", $post_defaultad);
249
  echo '<div id="message" class="updated fade"><p>Settings updated.</p></div>';
250
  }
257
  $setting_disable_default_style = get_option("wp125_disable_default_style");
258
  $setting_emailonexp = get_option("wp125_emailonexp");
259
  $setting_defaultad = get_option("wp125_defaultad");
260
+ $setting_daysbeforeexp = get_option("wp125_daysbeforeexp");
261
  ?><div class="wrap">
262
  <h2>Settings</h2>
263
  <form method="post" action="admin.php?page=wp125_settings">
289
 
290
  <tr valign="top">
291
  <th scope="row">Widget Title</th>
292
+ <td><input name="widgettitle" type="text" id="widgettitle" value="<?php echo $setting_widget_title; ?>" size="50" /><br/>The title to be displayed in the widget. <em>(Leave blank to disable.)</em></td>
293
  </tr>
294
 
295
  <tr valign="top">
296
  <th scope="row">Ad Sales Page</th>
297
+ <td><input name="salespage" type="text" id="salespage" value="<?php echo $setting_buyad_url; ?>" size="50" /><br/>Do you have a page with statistics and prices? <em>(Default Ads will link here.)</em></td>
298
  </tr>
299
 
300
  <tr valign="top">
304
 
305
  <tr valign="top">
306
  <th scope="row">Expiration Email</th>
307
+ <td><input name="emailonexp" type="text" id="emailonexp" value="<?php echo $setting_emailonexp; ?>" size="50" /><br/>Enter your email address if you would like to be emailed when an ad expires. <em>(Leave blank to disable.)</em></td>
308
+ </tr>
309
+
310
+ <tr valign="top">
311
+ <th scope="row">Pre-Expiration Email</th>
312
+ <td>Remind me <input name="daysbeforeexp" type="text" id="daysbeforeexp" value="<?php echo $setting_daysbeforeexp; ?>" size="2" /> days before an ad expires. <em>(Emails will be sent to the address specified above).</em></td>
313
  </tr>
314
 
315
  <tr valign="top">
installer.php CHANGED
@@ -4,7 +4,7 @@ require_once(ABSPATH . 'wp-admin/upgrade.php');
4
  //***Installer variables***
5
  global $wpdb;
6
  $table_name = $wpdb->prefix . "wp125_ads";
7
- $wp125_db_version = "1.33667";
8
  //***Installer***
9
  if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
10
  $sql = "CREATE TABLE " . $table_name . " (
@@ -17,6 +17,7 @@ $sql = "CREATE TABLE " . $table_name . " (
17
  status int(1) NOT NULL,
18
  target text NOT NULL,
19
  image_url text NOT NULL,
 
20
  PRIMARY KEY (id)
21
  );";
22
  dbDelta($sql);
@@ -28,7 +29,8 @@ add_option("wp125_buyad_url", "");
28
  add_option("wp125_disable_default_style", "");
29
  add_option("wp125_widget_title", "Ads");
30
  add_option("wp125_dofollow", "");
31
- add_option("wp125_emailonexp", "");
 
32
  add_option("wp125_defaultad", wp125_get_plugin_dir('url')."/youradhere.jpg");
33
 
34
  add_option("wp125_db_version", $wp125_db_version);
@@ -48,6 +50,7 @@ $sql = "CREATE TABLE " . $table_name . " (
48
  status int(1) NOT NULL,
49
  target text NOT NULL,
50
  image_url text NOT NULL,
 
51
  PRIMARY KEY (id)
52
  );";
53
  dbDelta($sql);
@@ -58,7 +61,8 @@ add_option("wp125_buyad_url", "");
58
  add_option("wp125_disable_default_style", "");
59
  add_option("wp125_widget_title", "Ads");
60
  add_option("wp125_dofollow", "");
61
- add_option("wp125_emailonexp", "");
 
62
  add_option("wp125_defaultad", wp125_get_plugin_dir('url')."/youradhere.jpg");
63
  update_option( "wp125_db_version", $wp125_db_version );
64
  }
4
  //***Installer variables***
5
  global $wpdb;
6
  $table_name = $wpdb->prefix . "wp125_ads";
7
+ $wp125_db_version = "1.33671";
8
  //***Installer***
9
  if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
10
  $sql = "CREATE TABLE " . $table_name . " (
17
  status int(1) NOT NULL,
18
  target text NOT NULL,
19
  image_url text NOT NULL,
20
+ pre_exp_email int(1) NOT NULL,
21
  PRIMARY KEY (id)
22
  );";
23
  dbDelta($sql);
29
  add_option("wp125_disable_default_style", "");
30
  add_option("wp125_widget_title", "Ads");
31
  add_option("wp125_dofollow", "");
32
+ add_option("wp125_emailonexp", get_option('admin_email'));
33
+ add_option("wp125_daysbeforeexp", "3");
34
  add_option("wp125_defaultad", wp125_get_plugin_dir('url')."/youradhere.jpg");
35
 
36
  add_option("wp125_db_version", $wp125_db_version);
50
  status int(1) NOT NULL,
51
  target text NOT NULL,
52
  image_url text NOT NULL,
53
+ pre_exp_email int(1) NOT NULL,
54
  PRIMARY KEY (id)
55
  );";
56
  dbDelta($sql);
61
  add_option("wp125_disable_default_style", "");
62
  add_option("wp125_widget_title", "Ads");
63
  add_option("wp125_dofollow", "");
64
+ add_option("wp125_emailonexp", get_option('admin_email'));
65
+ add_option("wp125_daysbeforeexp", "3");
66
  add_option("wp125_defaultad", wp125_get_plugin_dir('url')."/youradhere.jpg");
67
  update_option( "wp125_db_version", $wp125_db_version );
68
  }
readme.txt CHANGED
@@ -2,11 +2,11 @@
2
  Contributors: redwall_hp
3
  Plugin URI: http://www.webmaster-source.com/wp125-ad-plugin-wordpress/
4
  Author URI: http://www.webmaster-source.com
5
- Donate link: http://www.webmaster-source.com/donate/
6
  Tags: ads, 125x125, management, advertisement
7
  Requires at least: 2.3
8
  Tested up to: 2.7
9
- Stable tag: 1.1.5
10
 
11
 
12
  Easy management of 125x125 ads on your blog. Ads can be run for a specified number of days, and will automatically be taken down. Track clicks too.
@@ -26,6 +26,8 @@ Features include:
26
  * Keep track of how many times an ad is clicked
27
  * When creating a new ad, you don't have to calculate the end date yourself. Just input how many days you wish the ad to run for, and the correct date will be applied. The ad will be automatically taken down when the time comes.
28
  * When an ad run is over, the record is archived on the Inactive ads screen, so you can check on the final click count, or revive the ad for another run.
 
 
29
 
30
 
31
 
@@ -70,6 +72,9 @@ First, uncheck the Default Style box on the Settings page. This will remove the
70
  #wp125adwrap_2c { width:100%; }
71
  #wp125adwrap_2c .wp125ad { width:125px; float:left; padding:10px; }`
72
 
 
 
 
73
 
74
 
75
  == Screenshots ==
2
  Contributors: redwall_hp
3
  Plugin URI: http://www.webmaster-source.com/wp125-ad-plugin-wordpress/
4
  Author URI: http://www.webmaster-source.com
5
+ Donate link: http://www.webmaster-source.com/donate/?plugin=wp125
6
  Tags: ads, 125x125, management, advertisement
7
  Requires at least: 2.3
8
  Tested up to: 2.7
9
+ Stable tag: 1.2.0
10
 
11
 
12
  Easy management of 125x125 ads on your blog. Ads can be run for a specified number of days, and will automatically be taken down. Track clicks too.
26
  * Keep track of how many times an ad is clicked
27
  * When creating a new ad, you don't have to calculate the end date yourself. Just input how many days you wish the ad to run for, and the correct date will be applied. The ad will be automatically taken down when the time comes.
28
  * When an ad run is over, the record is archived on the Inactive ads screen, so you can check on the final click count, or revive the ad for another run.
29
+ * When an ad slot is empty, a placeholder ad of your choice will be displayed. This could be a �Your Ad Here� image linking to a page with statistics and pricing, or an affiliate link.
30
+ * Optionally recieve email notifications when an ad expires. Useful if you send follow-up messages to advertisers, or if you just want to stay in the know.
31
 
32
 
33
 
72
  #wp125adwrap_2c { width:100%; }
73
  #wp125adwrap_2c .wp125ad { width:125px; float:left; padding:10px; }`
74
 
75
+ = How do I make the ads open in a new window? =
76
+ If you absolutely *must* have your ads open in a new window when clicked, open the wp125.php file and find the `define(...` line near the top and remove the first `//` from the beginning.
77
+
78
 
79
 
80
  == Screenshots ==
wp125.php CHANGED
@@ -5,57 +5,58 @@ Plugin URI: http://www.webmaster-source.com/wp125-ad-plugin-wordpress/
5
  Description: Easily manage 125x125 ads within your WordPress Dashboard.
6
  Author: Matt Harzewski (redwall_hp)
7
  Author URI: http://www.webmaster-source.com
8
- Version: 1.1.5
9
  */
10
 
11
 
 
12
  define("MANAGEMENT_PERMISSION", "edit_themes"); //The minimum privilege required to manage ads. http://tinyurl.com/wpprivs
13
 
14
 
15
  //Ad Click Redirect
16
  add_action('init', 'wp125_adclick');
17
  function wp125_adclick() {
18
- if ($_GET['adclick'] != "" && ctype_digit($_GET['adclick'])) {
19
- $theid = $_GET['adclick'];
20
- global $wpdb;
21
- $adtable_name = $wpdb->prefix . "wp125_ads";
22
- $thead = $wpdb->get_row("SELECT target FROM $adtable_name WHERE id = '$theid'", OBJECT);
23
- $update = "UPDATE ". $adtable_name ." SET clicks=clicks+1 WHERE id='$theid'";
24
- $results = $wpdb->query( $update );
25
- header("Location: $thead->target");
26
- exit;
27
- }
28
  }
29
 
30
 
31
  //Stylesheet
32
  function wp125_stylesheet() {
33
- if (get_option("wp125_disable_default_style")=='') {
34
- echo '<link rel="stylesheet" href="'.wp125_get_plugin_dir('url').'/wp125.css" type="text/css" media="screen" />'."\n";
35
- } else { return; }
36
  }
37
- add_action('wp_print_scripts', 'wp125_stylesheet');
38
 
39
 
40
  //Installer
41
  function wp125_install () {
42
- require_once(dirname(__FILE__).'/installer.php');
43
  }
44
  register_activation_hook(__FILE__,'wp125_install');
45
 
46
 
47
  //Create Widget
48
  function wp125_create_ad_widget() {
49
- register_sidebar_widget(__('WP125'), 'wp125_write_ads_widget');
50
  }
51
  function wp125_write_ads_widget($args) {
52
- extract($args);
53
- echo $before_widget;
54
- if (get_option("wp125_widget_title")!='') {
55
- echo $before_title; echo get_option("wp125_widget_title"); echo $after_title;
56
- }
57
- wp125_write_ads();
58
- echo $after_widget;
59
  }
60
 
61
 
@@ -63,32 +64,39 @@ echo $after_widget;
63
 
64
  //Add the Admin Menus
65
  if (is_admin()) {
66
- function wp125_add_admin_menu() {
67
- add_menu_page("125x125 Ads", "Ads", MANAGEMENT_PERMISSION, __FILE__, "wp125_write_managemenu");
68
- add_submenu_page(__FILE__, "Manage 125x125 Ads", "Manage", MANAGEMENT_PERMISSION, __FILE__, "wp125_write_managemenu");
69
- add_submenu_page(__FILE__, "Add/Edit 125x125 Ads", "Add/Edit", MANAGEMENT_PERMISSION, 'wp125_addedit', "wp125_write_addeditmenu");
70
- add_submenu_page(__FILE__, "125x125 Ad Settings", "Settings", MANAGEMENT_PERMISSION, 'wp125_settings', "wp125_write_settingsmenu");
71
- }
72
-
73
- //Include menus
74
- require_once(dirname(__FILE__).'/adminmenus.php');
75
  }
76
 
77
 
78
 
79
  //Check Ad Date, and deactivate if the time is up
80
- function wp125_CheckAdDate($thedate, $theid) {
81
- global $wpdb;
82
- $adtable_name = $wpdb->prefix . "wp125_ads";
83
- if ($thedate!='00/00/0000') {
84
- $today = strtotime(date('m').'/'.date('d').'/'.date('Y'));
85
- $thedate = strtotime($thedate);
86
- if ($today > $thedate) {
87
- $updatedb = "UPDATE $adtable_name SET status='0' WHERE id='$theid'";
88
- $results = $wpdb->query($updatedb);
89
- sendExpirationEmail($theid);
90
- } else { return; }
91
- } else { return; }
 
 
 
 
 
 
 
 
92
  }
93
 
94
 
@@ -102,14 +110,15 @@ $setting_ad_order = get_option("wp125_ad_order");
102
  $setting_buyad_url = get_option("wp125_buyad_url");
103
  $setting_defaultad = get_option("wp125_defaultad");
104
  $adtable_name = $wpdb->prefix . "wp125_ads";
 
105
  if ($setting_ad_order == 'random') { $theorder = 'RAND() LIMIT '.$setting_num_slots; } else { $theorder = 'slot ASC'; }
106
  $theads = $wpdb->get_results("SELECT * FROM $adtable_name WHERE status = '1' ORDER BY $theorder", ARRAY_A);
107
  if ($theads) {
108
  if ($setting_ad_orientation=='1c') {
109
- echo '<div id="wp125adwrap_1c">';
110
  $arraycount = 0;
111
  foreach ($theads as $thead){
112
- wp125_CheckAdDate($thead['end_date'], $thead['id']);
113
  $theslot = $thead['slot'];
114
  $adguidearray[$theslot] = $thead;
115
  $arraycount++;
@@ -120,18 +129,19 @@ shuffle($adguidearray);
120
  $adguidearray_shufflefix = $adguidearray[0]; $adguidearray[0]=''; $adguidearray[]=$adguidearray_shufflefix;
121
  }
122
  for ($curslot=1; $curslot <= $setting_num_slots; $curslot++) {
 
123
  if (isset($adguidearray[$curslot])) {
124
  if ($adguidearray[$curslot]['clicks'] != -1) { $linkurl = get_option('blogurl').'index.php?adclick='.$adguidearray[$curslot]['id']; } else { $linkurl = $adguidearray[$curslot]['target']; }
125
- echo '<div class="wp125ad"><a href="'.$linkurl.'" rel="nofollow"><img src="'.$adguidearray[$curslot]['image_url'].'" alt="'.$adguidearray[$curslot]['name'].'" /></a></div>';
126
- } else { echo '<div class="wp125ad"><a href="'.$setting_buyad_url.'" rel="nofollow"><img src="'.$setting_defaultad.'" alt="" /></a></div>'; }
127
  }
128
- echo '</div>';
129
  }
130
  if ($setting_ad_orientation=='2c') {
131
- echo '<div id="wp125adwrap_2c">';
132
  $arraycount = 0;
133
  foreach ($theads as $thead){
134
- wp125_CheckAdDate($thead['end_date'], $thead['id']);
135
  $theslot = $thead['slot'];
136
  $adguidearray[$theslot] = $thead;
137
  $arraycount++;
@@ -142,54 +152,78 @@ shuffle($adguidearray);
142
  $adguidearray_shufflefix = $adguidearray[0]; $adguidearray[0]=''; $adguidearray[]=$adguidearray_shufflefix;
143
  }
144
  for ($curslot=1; $curslot <= $setting_num_slots; $curslot++) {
 
145
  if (isset($adguidearray[$curslot])) {
146
  if ($adguidearray[$curslot]['clicks'] != -1) { $linkurl = get_option('blogurl').'index.php?adclick='.$adguidearray[$curslot]['id']; } else { $linkurl = $adguidearray[$curslot]['target']; }
147
- echo '<div class="wp125ad"><a href="'.$linkurl.'" rel="nofollow"><img src="'.$adguidearray[$curslot]['image_url'].'" alt="'.$adguidearray[$curslot]['name'].'" /></a></div>';
148
- } else { echo '<div class="wp125ad"><a href="'.$setting_buyad_url.'" rel="nofollow"><img src="'.$setting_defaultad.'" alt="" /></a></div>'; }
149
  }
150
- echo '</div>';
151
  }
152
  }
153
  }
154
 
155
 
156
  function wp125_single_ad($theslot) {
157
- global $wpdb;
158
- $adtable_name = $wpdb->prefix . "wp125_ads";
159
- $thead = $wpdb->get_row("SELECT * FROM $adtable_name WHERE slot = '$theslot' AND status = '1' ORDER BY id DESC", OBJECT);
160
- if ($thead) {
161
- wp125_CheckAdDate($thead->end_date, $thead->id);
162
- if ($thead->clicks != -1) { $linkurl = get_option('blogurl').'index.php?adclick='.$thead->id; } else { $linkurl = $thead->target; }
163
- echo '<a href="'.$linkurl.'" rel="nofollow"><img src="'.$thead->image_url.'" alt="'.$thead->name.'" /></a>';
164
- } else { echo '<a href="'.get_option("wp125_buyad_url").'" rel="nofollow"><img src="'.get_option("wp125_defaultad").'" alt="Your Ad Here" /></a>'; }
165
  }
166
 
167
 
168
  //Return path to plugin directory (url/path)
169
  function wp125_get_plugin_dir($type) {
170
- if ( !defined('WP_CONTENT_URL') )
171
- define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
172
- if ( !defined('WP_CONTENT_DIR') )
173
- define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
174
- if ($type=='path') { return WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__)); }
175
- else { return WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)); }
176
  }
177
 
178
 
179
  //Send email alert to admin when an ad expires
180
  function sendExpirationEmail($theid) {
181
- global $wpdb;
182
- $adtable_name = $wpdb->prefix . "wp125_ads";
183
- $thead = $wpdb->get_row("SELECT * FROM $adtable_name WHERE id='$theid'", OBJECT);
184
- if (get_option('wp125_emailonexp')!='') {
185
- $theblog = get_option('blogname');
186
- $from = get_option('admin_email');
187
- $message = "One of the advertisements on $theblog has expired.\n\nAD NAME: ".$thead->name."\nAD URL: ".$thead->target."\nSTART DATE: ".$thead->start_date."\nEND DATE: ".$thead->end_date."\n\nFor more information, and to manage your ads, please log in to your WordPress administration.\n\n\n*** Powered by WordPress and WP125 ***";
188
- $headers = "From: $from\r\nReply-To: $from";
189
- $mail_sent = @mail(get_option('wp125_emailonexp'), "An ad on your blog has expired", $message, $headers);
190
- }
191
- return;
192
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
 
194
 
195
  //Hooks
5
  Description: Easily manage 125x125 ads within your WordPress Dashboard.
6
  Author: Matt Harzewski (redwall_hp)
7
  Author URI: http://www.webmaster-source.com
8
+ Version: 1.2.0
9
  */
10
 
11
 
12
+ //define("ADLINK_EXTRA", ' target="_blank"'); //If you absolutely *must* open your ads in new windows, uncomment this line
13
  define("MANAGEMENT_PERMISSION", "edit_themes"); //The minimum privilege required to manage ads. http://tinyurl.com/wpprivs
14
 
15
 
16
  //Ad Click Redirect
17
  add_action('init', 'wp125_adclick');
18
  function wp125_adclick() {
19
+ if (isset($_GET['adclick']) && $_GET['adclick'] != "" && ctype_digit($_GET['adclick'])) {
20
+ $theid = $_GET['adclick'];
21
+ global $wpdb;
22
+ $adtable_name = $wpdb->prefix . "wp125_ads";
23
+ $thead = $wpdb->get_row("SELECT target FROM $adtable_name WHERE id = '$theid'", OBJECT);
24
+ $update = "UPDATE ". $adtable_name ." SET clicks=clicks+1 WHERE id='$theid'";
25
+ $results = $wpdb->query( $update );
26
+ header("Location: $thead->target");
27
+ exit;
28
+ }
29
  }
30
 
31
 
32
  //Stylesheet
33
  function wp125_stylesheet() {
34
+ if (get_option("wp125_disable_default_style")=='') {
35
+ echo '<link rel="stylesheet" href="'.wp125_get_plugin_dir('url').'/wp125.css" type="text/css" media="screen" />'."\n";
36
+ } else { return; }
37
  }
38
+ add_action('wp_print_styles', 'wp125_stylesheet');
39
 
40
 
41
  //Installer
42
  function wp125_install () {
43
+ require_once(dirname(__FILE__).'/installer.php');
44
  }
45
  register_activation_hook(__FILE__,'wp125_install');
46
 
47
 
48
  //Create Widget
49
  function wp125_create_ad_widget() {
50
+ register_sidebar_widget(__('WP125'), 'wp125_write_ads_widget');
51
  }
52
  function wp125_write_ads_widget($args) {
53
+ extract($args);
54
+ echo $before_widget;
55
+ if (get_option("wp125_widget_title")!='') {
56
+ echo "\n".$before_title; echo get_option("wp125_widget_title"); echo $after_title;
57
+ }
58
+ wp125_write_ads();
59
+ echo $after_widget;
60
  }
61
 
62
 
64
 
65
  //Add the Admin Menus
66
  if (is_admin()) {
67
+ function wp125_add_admin_menu() {
68
+ add_menu_page("125x125 Ads", "Ads", MANAGEMENT_PERMISSION, __FILE__, "wp125_write_managemenu");
69
+ add_submenu_page(__FILE__, "Manage 125x125 Ads", "Manage", MANAGEMENT_PERMISSION, __FILE__, "wp125_write_managemenu");
70
+ add_submenu_page(__FILE__, "Add/Edit 125x125 Ads", "Add/Edit", MANAGEMENT_PERMISSION, 'wp125_addedit', "wp125_write_addeditmenu");
71
+ add_submenu_page(__FILE__, "125x125 Ad Settings", "Settings", MANAGEMENT_PERMISSION, 'wp125_settings', "wp125_write_settingsmenu");
72
+ }
73
+ //Include menus
74
+ require_once(dirname(__FILE__).'/adminmenus.php');
 
75
  }
76
 
77
 
78
 
79
  //Check Ad Date, and deactivate if the time is up
80
+ function wp125_CheckAdDate($thedate, $theid, $pre_exp_email) {
81
+ global $wpdb;
82
+ $adtable_name = $wpdb->prefix . "wp125_ads";
83
+ if ($thedate!='00/00/0000') {
84
+ $today = strtotime(date('m').'/'.date('d').'/'.date('Y'));
85
+ $thedefdate = $thedate;
86
+ $thedate = strtotime($thedate);
87
+ if ($today > $thedate) {
88
+ $updatedb = "UPDATE $adtable_name SET status='0', SET pre_exp_email='0' WHERE id='$theid'";
89
+ $results = $wpdb->query($updatedb);
90
+ sendExpirationEmail($theid);
91
+ }
92
+ $dayssetting = get_option("wp125_daysbeforeexp");
93
+ if ( strtotime(date('m').'/'.date('d').'/'.date('Y')) > strtotime($thedefdate." - $dayssetting days") AND $dayssetting>0 AND $pre_exp_email!=1 ) {
94
+ sendPreExpirationEmail($theid);
95
+ $updatedb = "UPDATE $adtable_name SET pre_exp_email='1' WHERE id='$theid'";
96
+ $results = $wpdb->query($updatedb);
97
+ }
98
+ return;
99
+ } else { return; }
100
  }
101
 
102
 
110
  $setting_buyad_url = get_option("wp125_buyad_url");
111
  $setting_defaultad = get_option("wp125_defaultad");
112
  $adtable_name = $wpdb->prefix . "wp125_ads";
113
+ if (!defined('ADLINK_EXTRA')) { define("ADLINK_EXTRA", ""); }
114
  if ($setting_ad_order == 'random') { $theorder = 'RAND() LIMIT '.$setting_num_slots; } else { $theorder = 'slot ASC'; }
115
  $theads = $wpdb->get_results("SELECT * FROM $adtable_name WHERE status = '1' ORDER BY $theorder", ARRAY_A);
116
  if ($theads) {
117
  if ($setting_ad_orientation=='1c') {
118
+ echo '<div id="wp125adwrap_1c">'."\n";
119
  $arraycount = 0;
120
  foreach ($theads as $thead){
121
+ wp125_CheckAdDate($thead['end_date'], $thead['id'], $thead['pre_exp_email']);
122
  $theslot = $thead['slot'];
123
  $adguidearray[$theslot] = $thead;
124
  $arraycount++;
129
  $adguidearray_shufflefix = $adguidearray[0]; $adguidearray[0]=''; $adguidearray[]=$adguidearray_shufflefix;
130
  }
131
  for ($curslot=1; $curslot <= $setting_num_slots; $curslot++) {
132
+ $altclass = ( ' odd' != $altclass ) ? ' odd' : ' even';
133
  if (isset($adguidearray[$curslot])) {
134
  if ($adguidearray[$curslot]['clicks'] != -1) { $linkurl = get_option('blogurl').'index.php?adclick='.$adguidearray[$curslot]['id']; } else { $linkurl = $adguidearray[$curslot]['target']; }
135
+ echo '<div class="wp125ad'.$altclass.'"><a href="'.$linkurl.'" rel="nofollow"'.ADLINK_EXTRA.'><img src="'.$adguidearray[$curslot]['image_url'].'" alt="'.$adguidearray[$curslot]['name'].'" /></a></div>'."\n";
136
+ } else { echo '<div class="wp125ad'.$altclass.'"><a href="'.$setting_buyad_url.'" rel="nofollow"'.ADLINK_EXTRA.'><img src="'.$setting_defaultad.'" alt="" /></a></div>'."\n"; }
137
  }
138
+ echo "</div>\n";
139
  }
140
  if ($setting_ad_orientation=='2c') {
141
+ echo '<div id="wp125adwrap_2c">'."\n";
142
  $arraycount = 0;
143
  foreach ($theads as $thead){
144
+ wp125_CheckAdDate($thead['end_date'], $thead['id'], $thead['pre_exp_email']);
145
  $theslot = $thead['slot'];
146
  $adguidearray[$theslot] = $thead;
147
  $arraycount++;
152
  $adguidearray_shufflefix = $adguidearray[0]; $adguidearray[0]=''; $adguidearray[]=$adguidearray_shufflefix;
153
  }
154
  for ($curslot=1; $curslot <= $setting_num_slots; $curslot++) {
155
+ $altclass = ( ' odd' != $altclass ) ? ' odd' : ' even';
156
  if (isset($adguidearray[$curslot])) {
157
  if ($adguidearray[$curslot]['clicks'] != -1) { $linkurl = get_option('blogurl').'index.php?adclick='.$adguidearray[$curslot]['id']; } else { $linkurl = $adguidearray[$curslot]['target']; }
158
+ echo '<div class="wp125ad'.$altclass.'"><a href="'.$linkurl.'" rel="nofollow"'.ADLINK_EXTRA.'><img src="'.$adguidearray[$curslot]['image_url'].'" alt="'.$adguidearray[$curslot]['name'].'" /></a></div>'."\n";
159
+ } else { echo '<div class="wp125ad'.$altclass.'"><a href="'.$setting_buyad_url.'" rel="nofollow"'.ADLINK_EXTRA.'><img src="'.$setting_defaultad.'" alt="" /></a></div>'."\n"; }
160
  }
161
+ echo "</div>\n";
162
  }
163
  }
164
  }
165
 
166
 
167
  function wp125_single_ad($theslot) {
168
+ global $wpdb;
169
+ $adtable_name = $wpdb->prefix . "wp125_ads";
170
+ $thead = $wpdb->get_row("SELECT * FROM $adtable_name WHERE slot = '$theslot' AND status = '1' ORDER BY id DESC", OBJECT);
171
+ if ($thead) {
172
+ wp125_CheckAdDate($thead->end_date, $thead->id, $thead->pre_exp_email);
173
+ if ($thead->clicks != -1) { $linkurl = get_option('blogurl').'index.php?adclick='.$thead->id; } else { $linkurl = $thead->target; }
174
+ echo '<a href="'.$linkurl.'" rel="nofollow"'.ADLINK_EXTRA.'><img src="'.$thead->image_url.'" alt="'.$thead->name.'" /></a>';
175
+ } else { echo '<a href="'.get_option("wp125_buyad_url").'" rel="nofollow"><img src="'.get_option("wp125_defaultad").'" alt="Your Ad Here" /></a>'; }
176
  }
177
 
178
 
179
  //Return path to plugin directory (url/path)
180
  function wp125_get_plugin_dir($type) {
181
+ if ( !defined('WP_CONTENT_URL') )
182
+ define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
183
+ if ( !defined('WP_CONTENT_DIR') )
184
+ define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
185
+ if ($type=='path') { return WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__)); }
186
+ else { return WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)); }
187
  }
188
 
189
 
190
  //Send email alert to admin when an ad expires
191
  function sendExpirationEmail($theid) {
192
+ global $wpdb;
193
+ $adtable_name = $wpdb->prefix . "wp125_ads";
194
+ $thead = $wpdb->get_row("SELECT * FROM $adtable_name WHERE id='$theid'", OBJECT);
195
+ if (get_option('wp125_emailonexp')!='') {
196
+ $theblog = get_option('blogname');
197
+ $from = get_option('admin_email');
198
+ $message = "One of the advertisements on $theblog has expired.\n\nAD NAME: ".$thead->name."\nAD URL: ".$thead->target."\nSTART DATE: ".$thead->start_date."\nEND DATE: ".$thead->end_date."\n\nFor more information, and to manage your ads, please log in to your WordPress administration.\n\n\n*** Powered by WordPress and WP125 ***";
199
+ $headers = "From: $from\r\nReply-To: $from";
200
+ $mail_sent = @mail(get_option('wp125_emailonexp'), "An ad on your blog has expired", $message, $headers);
201
+ }
202
+ return;
203
+ }
204
+
205
+
206
+ //Handle pre-expiration emails
207
+ function sendPreExpirationEmail($theid) {
208
+ global $wpdb;
209
+ $adtable_name = $wpdb->prefix . "wp125_ads";
210
+ $thead = $wpdb->get_row("SELECT * FROM $adtable_name WHERE id='$theid'", OBJECT);
211
+ if (get_option('wp125_emailonexp')!='') {
212
+ $theblog = get_option('blogname');
213
+ $from = get_option('admin_email');
214
+ $message = "One of the advertisements on $theblog will be expiring soon.\n\nAD NAME: ".$thead->name."\nAD URL: ".$thead->target."\nSTART DATE: ".$thead->start_date."\nEND DATE: ".$thead->end_date."\n\nFor more information, and to manage your ads, please log in to your WordPress administration.\n\n\n*** Powered by WordPress and WP125 ***";
215
+ $headers = "From: $from\r\nReply-To: $from";
216
+ $mail_sent = @mail(get_option('wp125_emailonexp'), "An ad on your blog expires soon", $message, $headers);
217
+ }
218
+ return;
219
+ }
220
+
221
+
222
+ function wp125_add_menu_favorite($actions) {
223
+ $actions['admin.php?page=wp125/wp125.php'] = array('Manage Ads', 'manage_options');
224
+ return $actions;
225
+ }
226
+ add_filter('favorite_actions', 'wp125_add_menu_favorite'); //Favorites Menu
227
 
228
 
229
  //Hooks