Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)

wp125.php 1.4.9 fixed

By: samuelaguilera on Mar 14th, 2013  |  syntax: PHP  |  size: 11.30 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2. /*
  3. Plugin Name: WP125
  4. 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.4.9
  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. //Includes
  17. include "widget_class.php";
  18.  
  19.  
  20. //Ad Click Redirect
  21. add_action('init', 'wp125_adclick');
  22. function wp125_adclick() {
  23.         if (isset($_GET['adclick']) && $_GET['adclick'] != "" && ctype_digit($_GET['adclick'])) {
  24.         $theid = $_GET['adclick'];
  25.         global $wpdb;
  26.         $adtable_name = $wpdb->prefix . "wp125_ads";
  27.         $thead = $wpdb->get_row($wpdb->prepare(
  28.                 "SELECT target FROM {$adtable_name} WHERE id = %d",
  29.                 $theid
  30.         ));
  31.         $theid = $wpdb->escape($theid);
  32.         $update = "UPDATE ". $adtable_name ." SET clicks=clicks+1 WHERE id='$theid'";
  33.         $results = $wpdb->query( $update );
  34.         header("Location: $thead->target");
  35.         exit;
  36.         }
  37. }
  38.  
  39.  
  40. //Stylesheet
  41. function wp125_stylesheet() {
  42.         if (get_option("wp125_disable_default_style")=='') {
  43.                 wp_register_style('wp125style', wp125_get_plugin_dir('url').'/wp125.css');
  44.                 wp_enqueue_style('wp125style');
  45.         }
  46. }
  47. add_action('wp_enqueue_scripts', 'wp125_stylesheet');
  48.  
  49.  
  50. //Installer
  51. function wp125_install () {
  52.         require_once(dirname(__FILE__).'/installer.php');
  53. }
  54. register_activation_hook(__FILE__,'wp125_install');
  55.  
  56.  
  57. //Create Widget
  58. function wp125_create_ad_widget() {
  59.         register_widget('WP125_Widget');
  60. }
  61.  
  62.  
  63.  
  64.  
  65. //Add the Admin Menus
  66. if (is_admin()) {
  67.         function wp125_add_admin_menu() {
  68.                 global $wp125_edit; // make it global so we can read from wp125_admin_styles()
  69.  
  70.                 load_plugin_textdomain('wp125', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)).'/translations', dirname(plugin_basename(__FILE__)).'/translations');
  71.                 add_menu_page(__("125x125 Ads", 'wp125'), __("Ads", 'wp125'), MANAGEMENT_PERMISSION, __FILE__, "wp125_write_managemenu");
  72.                 add_submenu_page(__FILE__, __("Manage 125x125 Ads", 'wp125'), __("Manage", 'wp125'), MANAGEMENT_PERMISSION, __FILE__, "wp125_write_managemenu");
  73.                 $wp125_edit = add_submenu_page(__FILE__, __("Add/Edit 125x125 Ads", 'wp125'), __("Add/Edit", 'wp125'), MANAGEMENT_PERMISSION, 'wp125_addedit', "wp125_write_addeditmenu");
  74.                 add_submenu_page(__FILE__, __("125x125 Ad Settings", 'wp125'), __("Settings", 'wp125'), MANAGEMENT_PERMISSION, 'wp125_settings', "wp125_write_settingsmenu");
  75.         }
  76.         //Include menus
  77.         require_once(dirname(__FILE__).'/adminmenus.php');
  78. }
  79.  
  80.  
  81.  
  82. //Check Ad Date, and deactivate if the time is up
  83. function wp125_CheckAdDate($thedate, $theid, $pre_exp_email) {
  84.         global $wpdb;
  85.         $adtable_name = $wpdb->prefix . "wp125_ads";
  86.         if ($thedate!='00/00/0000') {
  87.                 $today = strtotime(date('m').'/'.date('d').'/'.date('Y'));
  88.                 $thedefdate = $thedate;
  89.                 $thedate = strtotime($thedate);
  90.                 if ($today > $thedate) {
  91.                         $updatedb = "UPDATE $adtable_name SET status='0' AND pre_exp_email='0' WHERE id='$theid'";
  92.                         $results = $wpdb->query($updatedb);
  93.                         sendExpirationEmail($theid);
  94.                 }
  95.                 $dayssetting = get_option("wp125_daysbeforeexp");
  96.                 if ( strtotime(date('m').'/'.date('d').'/'.date('Y')) > strtotime($thedefdate." - $dayssetting days") AND $dayssetting>0 AND $pre_exp_email!=1 ) {
  97.                         sendPreExpirationEmail($theid);
  98.                         $updatedb = "UPDATE $adtable_name SET pre_exp_email='1' WHERE id='$theid'";
  99.                         $results = $wpdb->query($updatedb);
  100.                 }
  101.                 return;
  102.         } else { return; }
  103. }
  104.  
  105.  
  106. function wp125_task_check_ad_expiry() {
  107.  
  108.         global $wpdb;
  109.         $adtable_name = $wpdb->prefix . "wp125_ads";
  110.         $ads = $wpdb->get_results("SELECT * FROM $adtable_name WHERE status = '1'");
  111.  
  112.         if ($ads) {
  113.                 foreach ($ads as $key => $ad) {
  114.                         wp125_CheckAdDate($ad->end_date, $ad->id, $ad->pre_exp_email);
  115.                 }
  116.         }
  117.  
  118. }
  119.  
  120.  
  121.  
  122. //Write the Ads
  123. function wp125_write_ads($exclude="0") {
  124. global $wpdb;
  125. if ($exclude != "0") { $exclude = implode(",", $exclude); }
  126. $setting_ad_orientation = get_option("wp125_ad_orientation");
  127. $setting_num_slots = get_option("wp125_num_slots");
  128. $setting_ad_order = get_option("wp125_ad_order");
  129. $setting_buyad_url = get_option("wp125_buyad_url");
  130. $setting_defaultad = get_option("wp125_defaultad");
  131. $adtable_name = $wpdb->prefix . "wp125_ads";
  132. if (!defined('ADLINK_EXTRA')) { define("ADLINK_EXTRA", ""); }
  133. if ($setting_ad_order == 'random') { $theorder = 'RAND() LIMIT '.$setting_num_slots; } else { $theorder = 'slot ASC'; }
  134. $exclude_sql = "AND slot NOT IN ($exclude)";
  135. $theads = $wpdb->get_results("SELECT * FROM $adtable_name WHERE status = '1' $exclude_sql ORDER BY $theorder", ARRAY_A);
  136. if ($setting_ad_orientation=='1c') {
  137. echo '<div id="wp125adwrap_1c">'."\n";
  138. $arraycount = 0;
  139. if (!empty($theads)) {
  140. foreach ($theads as $thead){
  141. $theslot = $thead['slot'];
  142. $adguidearray[$theslot] = $thead;
  143. $arraycount++;
  144. }
  145. if ($setting_ad_order == 'random') {
  146. srand((float)microtime() * 1000000);
  147. shuffle($adguidearray);
  148. $adguidearray_shufflefix = $adguidearray[0]; $adguidearray[0]=''; $adguidearray[]=$adguidearray_shufflefix;
  149. }
  150. }
  151. for ($curslot=1; $curslot <= $setting_num_slots; $curslot++) {
  152. $altclass = ( ' odd' != $altclass ) ? ' odd' : ' even';
  153. if (isset($adguidearray[$curslot])) {
  154. if ($adguidearray[$curslot]['clicks'] != -1) { $linkurl = get_option('blogurl').'index.php?adclick='.$adguidearray[$curslot]['id']; } else { $linkurl = $adguidearray[$curslot]['target']; }
  155. echo '<div class="wp125ad'.$altclass.'"><a href="'.$linkurl.'" title="'.$adguidearray[$curslot]['name'].'" rel="nofollow"'.ADLINK_EXTRA.'><img src="'.$adguidearray[$curslot]['image_url'].'" alt="'.$adguidearray[$curslot]['name'].'" /></a></div>'."\n";
  156. } else { echo '<div class="wp125ad'.$altclass.'"><a href="'.$setting_buyad_url.'" rel="nofollow"'.ADLINK_EXTRA.'><img src="'.$setting_defaultad.'" alt="" /></a></div>'."\n"; }
  157. }
  158. echo "</div>\n";
  159. }
  160. if ($setting_ad_orientation=='2c') {
  161. echo '<div id="wp125adwrap_2c" class="wp125clearfix">'."\n";
  162. $arraycount = 0;
  163. if (!empty($theads)) {
  164. foreach ($theads as $thead){
  165. $theslot = $thead['slot'];
  166. $adguidearray[$theslot] = $thead;
  167. $arraycount++;
  168. }
  169. if ($setting_ad_order == 'random') {
  170. srand((float)microtime() * 1000000);
  171. shuffle($adguidearray);
  172. $adguidearray_shufflefix = $adguidearray[0]; $adguidearray[0]=''; $adguidearray[]=$adguidearray_shufflefix;
  173. }
  174. }
  175. for ($curslot=1; $curslot <= $setting_num_slots; $curslot++) {
  176. $altclass = ( ' odd' != $altclass ) ? ' odd' : ' even';
  177. if (isset($adguidearray[$curslot])) {
  178. if ($adguidearray[$curslot]['clicks'] != -1) { $linkurl = get_option('blogurl').'index.php?adclick='.$adguidearray[$curslot]['id']; } else { $linkurl = $adguidearray[$curslot]['target']; }
  179. echo '<div class="wp125ad'.$altclass.'"><a href="'.$linkurl.'" title="'.$adguidearray[$curslot]['name'].'" rel="nofollow"'.ADLINK_EXTRA.'><img src="'.$adguidearray[$curslot]['image_url'].'" alt="'.$adguidearray[$curslot]['name'].'" /></a></div>'."\n";
  180. } else { echo '<div class="wp125ad'.$altclass.'"><a href="'.$setting_buyad_url.'" rel="nofollow"'.ADLINK_EXTRA.'><img src="'.$setting_defaultad.'" alt="" /></a></div>'."\n"; }
  181. }
  182. echo "</div>\n";
  183. }
  184. }
  185.  
  186.  
  187. function wp125_single_ad($theslot) {
  188.         global $wpdb;
  189.         if (!defined('ADLINK_EXTRA')) { define("ADLINK_EXTRA", ""); }
  190.         $adtable_name = $wpdb->prefix . "wp125_ads";
  191.         $thead = $wpdb->get_row("SELECT * FROM $adtable_name WHERE slot = '$theslot' AND status = '1' ORDER BY id DESC", OBJECT);
  192.         if ($thead) {
  193.                 if ($thead->clicks != -1) { $linkurl = get_option('blogurl').'index.php?adclick='.$thead->id; } else { $linkurl = $thead->target; }
  194.                 echo '<a href="'.$linkurl.'" title="'.$adguidearray[$curslot]['name'].'" rel="nofollow"'.ADLINK_EXTRA.'><img src="'.$thead->image_url.'" alt="'.$thead->name.'" /></a>';
  195.         } else { echo '<a href="'.get_option("wp125_buyad_url").'" rel="nofollow"><img src="'.get_option("wp125_defaultad").'" alt="Your Ad Here" /></a>'; }
  196. }
  197.  
  198.  
  199. //Return path to plugin directory (url/path)
  200. function wp125_get_plugin_dir($type) {
  201.         if ( !defined('WP_CONTENT_URL') )
  202.                 define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
  203.         if ( !defined('WP_CONTENT_DIR') )
  204.                 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
  205.         if ($type=='path') { return WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__)); }
  206.         else { return WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)); }
  207. }
  208.  
  209.  
  210. //Send email alert to admin when an ad expires
  211. function sendExpirationEmail($theid) {
  212.         global $wpdb;
  213.         $adtable_name = $wpdb->prefix . "wp125_ads";
  214.         $thead = $wpdb->get_row("SELECT * FROM $adtable_name WHERE id='$theid'", OBJECT);
  215.         if (get_option('wp125_emailonexp')!='') {
  216.                 $theblog = get_option('blogname');
  217.                 $from = get_option('admin_email');
  218.                 $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 ***";
  219.                 $headers = "From: $from\r\nReply-To: $from";
  220.                 $mail_sent = @mail(get_option('wp125_emailonexp'), "An ad on your blog has expired", $message, $headers);
  221.         }
  222.         return;
  223. }
  224.  
  225.  
  226. //Handle pre-expiration emails
  227. function sendPreExpirationEmail($theid) {
  228.         global $wpdb;
  229.         $adtable_name = $wpdb->prefix . "wp125_ads";
  230.         $thead = $wpdb->get_row("SELECT * FROM $adtable_name WHERE id='$theid'", OBJECT);
  231.         if (get_option('wp125_emailonexp')!='') {
  232.                 $theblog = get_option('blogname');
  233.                 $from = get_option('admin_email');
  234.                 $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 ***";
  235.                 $headers = "From: $from\r\nReply-To: $from";
  236.                 $mail_sent = @mail(get_option('wp125_emailonexp'), "An ad on your blog expires soon", $message, $headers);
  237.         }
  238.         return;
  239. }
  240.  
  241.  
  242. function wp125_add_menu_favorite($actions) {
  243.         $actions['admin.php?page=wp125/wp125.php'] = array('Manage Ads', 'manage_options');
  244.         return $actions;
  245. }
  246. add_filter('favorite_actions', 'wp125_add_menu_favorite'); //Favorites Menu
  247.  
  248.  
  249. //Hooks
  250. add_action("widgets_init", "wp125_create_ad_widget"); //Create the Widget
  251. if (is_admin()) { add_action('admin_menu', 'wp125_add_admin_menu'); } //Admin pages
  252.  
  253. if (!wp_next_scheduled('wp125classic_cron_ad_expiry')) {
  254.         wp_schedule_event(time(), 'twicedaily', 'wp125classic_cron_ad_expiry');
  255. }
  256. add_action('wp125classic_cron_ad_expiry', 'wp125_task_check_ad_expiry');
  257.  
  258.  
  259.  
  260. /*
  261. Copyright 2008 Matt Harzewski
  262.  
  263. This program is free software: you can redistribute it and/or modify
  264. it under the terms of the GNU General Public License as published by
  265. the Free Software Foundation, either version 3 of the License, or
  266. (at your option) any later version.
  267.  
  268. This program is distributed in the hope that it will be useful,
  269. but WITHOUT ANY WARRANTY; without even the implied warranty of
  270. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  271. GNU General Public License for more details.
  272.  
  273. You should have received a copy of the GNU General Public License
  274. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  275. */
  276.  
  277. ?>