Lite Version: Get started with AdSense now, and make money from your blog. Configure it at Settings → AdSense Now!. Version: 4.00 Author: Manoj Thulasidas Author URI: http://www.thulasidas.com */ /* Copyright (C) 2008 www.ads-ez.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ if (class_exists("AdsNowPro")) { $msg = sprintf(__("%s Pro seems to be active.
Please use the Pro version, or deactivate it before activating %s.", "adsense-now"), "AdSense Now!", "AdSense Now!"); die($msg); } if (!class_exists("AdsNow")) { require_once('EzOptions.php'); class AdsNow extends EzBasePlugin { var $locale, $defaults, $adminOptions, $options, $adminOptionName; function AdsNow() { //constructor parent::__construct("adsense-now", "AdSense Now!", __FILE__); $this->defaults = array ('defaultText' => 'Please generate and paste your ad code here. If left empty, the ad location will be highlighted on your blog pages with a reminder to enter your code.'); } function init() { $this->getAdminOptions(); } //Returns an array of admin options function getAdminOptions($reset = false) { if (!$reset && count($this->adminOptions) > 0) { return $this->adminOptions; } $mThemeName = get_option('stylesheet'); $mOptions = "adsNow" . $mThemeName; $adsNowAdminOptions = array('info' => "\n", 'ad_text' => $this->defaults['defaultText'], 'show_leadin' => 'float:right', 'show_midtext' => 'float:left', 'show_leadout' => 'float:right', 'kill_invites' => false, 'kill_rating' => false, 'kill_pages' => false, 'kill_home' => false, 'kill_attach' => false, 'kill_front' => false, 'kill_cat' => false, 'kill_tag' => false, 'kill_archive' => false); $adNwOptions = get_option($mOptions); if (empty($adNwOptions)) { // try loading the default from the pre 1.3 version, so as not to annoy // the dudes who have already been using adNwsenser $adminOptionsName = "adsNowAdminOptions"; $adNwOptions = get_option($adminOptionsName); } if (!empty($adNwOptions) && !$reset) { foreach ($adNwOptions as $key => $option) { $adsNowAdminOptions[$key] = $option; } } update_option($mOptions, $adsNowAdminOptions); $this->adminOptions = $adsNowAdminOptions; $this->adminOptionName = $mOptions; return $adsNowAdminOptions; } function handleDefaultText($text, $key = '300x250') { $ret = $text; if ($ret == $this->defaults['defaultText'] || strlen(trim($ret)) == 0) { $x = strpos($key, 'x'); $w = substr($key, 0, $x); $h = substr($key, $x + 1); $p = (int) (min($w, $h) / 6); $ret = '

Your ads will be inserted here by

AdSense Now!.

Please go to the plugin admin page to paste your ad code.

'; } return $ret; } //Prints out the admin page function printAdminPage() { $ez = parent::printAdminPage(); if (empty($ez)) { return; } if (empty($this->defaults)) { return; } $mThemeName = get_option('stylesheet'); $mOptions = "adsNow" . $mThemeName; $adNwOptions = $this->getAdminOptions(); if (isset($_POST['update_adsNowSettings'])) { if (isset($_POST['adsNowText'])) { $adNwOptions['ad_text'] = $_POST['adsNowText']; } if (isset($_POST['adsNowShowLeadin'])) { $adNwOptions['show_leadin'] = $_POST['adsNowShowLeadin']; } if (isset($_POST['adsNowShowMidtext'])) { $adNwOptions['show_midtext'] = $_POST['adsNowShowMidtext']; } if (isset($_POST['adsNowShowLeadout'])) { $adNwOptions['show_leadout'] = $_POST['adsNowShowLeadout']; } if (isset($_POST['kill_invites'])) { $adNwOptions['kill_invites'] = $_POST['kill_invites']; } if (isset($_POST['kill_rating'])) { $adNwOptions['kill_rating'] = $_POST['kill_rating']; } $adNwOptions['kill_pages'] = isset($_POST['adNwKillPages']); $adNwOptions['kill_home'] = isset($_POST['adNwKillHome']); $adNwOptions['kill_attach'] = isset($_POST['adNwKillAttach']); $adNwOptions['kill_front'] = isset($_POST['adNwKillFront']); $adNwOptions['kill_cat'] = isset($_POST['adNwKillCat']); $adNwOptions['kill_tag'] = isset($_POST['adNwKillTag']); $adNwOptions['kill_archive'] = isset($_POST['adNwKillArchive']); $adNwOptions['info'] = $this->info(); update_option($mOptions, $adNwOptions); echo '

'; _e("Settings Updated.", "adsense-now"); echo '

'; } else if (isset($_POST['reset_adsNowSettings'])) { $reset = true; $adNwOptions = $this->getAdminOptions($reset); echo '

'; _e("Ok, all your settings have been discarded!", "adsense-now"); echo '

'; } else if (isset($_POST['clean_db']) || isset($_POST['kill_me'])) { $reset = true; $adNwOptions = $this->getAdminOptions($reset); $this->cleanDB('adsNow'); echo '

'; _e("Database has been cleaned. All your options for this plugin (for all themes) have been removed.", "adsense-now"); echo '

'; if (isset($_POST['kill_me'])) { remove_action('admin_menu', 'adsNow_ap'); deactivate_plugins('adsense-now-lite/adsense-now-lite.php', true); echo '

'; _e("This plugin has been deactivated.", "adsense-now"); echo ''; _e("Refresh", "adsense-now"); echo '

'; return; } } if (file_exists($this->plgDir . '/admin.php')) { include ($this->plgDir . '/admin.php'); } else { echo '' . __("Error locating the admin page!\nEnsure admin.php exists, or reinstall the plugin.", 'adsense-now') . ''; } } //End function printAdminPage() function info() { $me = basename($this->plgDir) . '/' . basename(__FILE__); $plugins = get_plugins(); $str = "\n"; return $str; } var $nwMax = 3; function cleanDB($prefix) { global $wpdb; $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE '$prefix%'"); } function plugin_action($links, $file) { if ($file == plugin_basename($this->plgDir . '/adsense-now-lite.php')) { $settings_link = "" . __('Settings', 'adsense-now') . ""; array_unshift($links, $settings_link); } return $links; } function getMetaOptions() { $adNwOptions = $this->getAdminOptions(); global $post; $lookup = array('adsense' => 'adsense', 'adsense-top' => 'show_leadin', 'adsense-middle' => 'show_midtext', 'adsense-bottom' => 'show_leadout'); $metaOptions = array(); foreach ($lookup as $metaKey => $optKey) { if (!empty($adNwOptions[$optKey])) { $metaOptions[$optKey] = $adNwOptions[$optKey]; } else { $metaOptions[$optKey] = ''; } $customStyle = get_post_custom_values($metaKey, $post->ID, true); if (is_array($customStyle)) { $metaStyle = strtolower($customStyle[0]); } else { $metaStyle = strtolower($customStyle); } $style = ''; if ($metaStyle == 'left') { $style = 'float:left;display:block;'; } else if ($metaStyle == 'right') { $style = 'float:right;display:block;'; } else if ($metaStyle == 'center') { $style = 'text-align:center;display:block;'; } else { $style = $metaStyle; } if (!empty($style)) { $metaOptions[$optKey] = $style; } } return $metaOptions; } function adsNow_content($content) { if (!in_the_loop()) { return $content; } $adNwOptions = $this->getAdminOptions(); if ($adNwOptions['kill_pages'] && is_page()) { return $content; } if ($adNwOptions['kill_home'] && is_home()) { return $content; } if ($adNwOptions['kill_attach'] && is_attachment()) { return $content; } if ($adNwOptions['kill_front'] && is_front_page()) { return $content; } if ($adNwOptions['kill_cat'] && is_category()) { return $content; } if ($adNwOptions['kill_tag'] && is_tag()) { return $content; } if ($adNwOptions['kill_archive'] && is_archive()) { return $content; } global $nwCount; if ($nwCount >= $this->nwMax) { return $content; } if (strpos($content, "") !== false) { return $content; } $metaOptions = $this->getMetaOptions(); if ($metaOptions['adsense'] == 'no') { return $content; } $show_leadin = $metaOptions['show_leadin']; $leadin = ''; if ($show_leadin != 'no') { if ($nwCount < $this->nwMax) { $nwCount++; $adText = $this->handleDefaultText($adNwOptions['ad_text']); $leadin = stripslashes($adNwOptions['info'] . "\n" . '
' . $adText . '
'); } } $show_midtext = $metaOptions['show_midtext']; if ($show_midtext != 'no') { if ($nwCount < $this->nwMax) { $poses = array(); $lastpos = -1; $repchar = " $half) { array_pop($poses); } $pickme = $poses[floor(sizeof($poses) / 2)]; $nwCount++; $adText = $this->handleDefaultText($adNwOptions['ad_text']); $midtext = stripslashes($adNwOptions['info'] . "\n" . '
' . $adText . '
'); $content = substr_replace($content, $midtext . $repchar, $pickme, 2); } } $show_leadout = $metaOptions['show_leadout']; $leadout = ''; if ($show_leadout != 'no') { if ($nwCount < $this->nwMax) { $nwCount++; $adText = $this->handleDefaultText($adNwOptions['ad_text']); $leadout = stripslashes($adNwOptions['info'] . "\n" . '
' . $adText . '
'); } } return $leadin . $content . $leadout; } } } //End Class adsNow $nwCount = 0; // provide a replacement for htmlspecialchars_decode() (for PHP4 compatibility) if (!function_exists("htmlspecialchars_decode")) { function htmlspecialchars_decode($string, $style = ENT_COMPAT) { $translation = array_flip(get_html_translation_table(HTML_SPECIALCHARS, $style)); if ($style === ENT_QUOTES) { $translation['''] = '\''; } return strtr($string, $translation); } } if (class_exists("AdsNow")) { $adsNow = new AdsNow(); if (isset($adsNow) && !empty($adsNow->defaults)) { //Initialize the admin panel if (!function_exists("adsNow_ap")) { function adsNow_ap() { global $adsNow; if (function_exists('add_options_page')) { $mName = 'AdSense Now!'; add_options_page($mName, $mName, 'activate_plugins', basename(__FILE__), array($adsNow, 'printAdminPage')); } } } add_filter('the_content', array($adsNow, 'adsNow_content')); add_action('admin_menu', 'adsNow_ap'); add_action('activate_' . basename($adsNow->plgDir) . '/' . basename(__FILE__), array($adsNow, 'init')); add_filter('plugin_action_links', array($adsNow, 'plugin_action'), -10, 2); } }