Settings → AdSense Now!, or use the "Settings" link on the right.
Version: 1.21
Author: Manoj Thulasidas
Author URI: http://www.thulasidas.com
*/
/*
Copyright (C) 2008 www.thulasidas.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("adsNow")) {
class adsNow {
var $plugindir, $locale ;
function adsNow() { //constructor
}
function init() {
$this->getAdminOptions();
}
//Returns an array of admin options
function getAdminOptions($reset = false) {
$mThemeName = get_settings('stylesheet') ;
$mOptions = "adsNow" . $mThemeName ;
$this->plugindir = get_option('siteurl') . '/' . PLUGINDIR .
'/' . basename(dirname(__FILE__)) ;
$locale = get_locale();
$this->locale = $locale ;
if(!empty($this->locale) && $this->locale != 'en_US') {
$moFile = dirname(__FILE__) . '/lang/' . $this->locale . '/easy-adsenser.mo';
if(@file_exists($moFile) && is_readable($moFile))
load_textdomain('easy-adsenser', $moFile);
else {
// look for any other similar locale with the same first three characters
$foo = glob(dirname(__FILE__) . '/lang/' . substr($this->locale, 0, 2) .
'*/easy-adsenser.mo') ;
if (!empty($foo)>0) {
$moFile = $foo[0] ;
load_textdomain('easy-adsenser', $moFile);
$this->locale = basename(dirname($moFile)) ;
}
}
}
$adsNowAdminOptions = array(
'ad_text' =>
'
',
'show_leadin' => 'float:right',
'show_midtext' => 'float:left',
'show_leadout' => 'float:right',
'kill_pages' => 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);
return $adsNowAdminOptions;
}
//Prints out the admin page
function printAdminPage() {
$mThemeName = get_settings('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'];
}
$adNwOptions['kill_pages'] = $_POST['adNwKillPages'];
update_option($mOptions, $adNwOptions);
?>
getAdminOptions($reset);
?>
' . __("Error locating the admin page!\nEnsure admin.php exists, or reinstall the plugin.", 'easy-adsenser') . '' ;
?>
" .
__('Settings', 'easy-adsenser') . "";
array_unshift( $links, $settings_link );
}
return $links;
}
function contentMeta() {
$ezAdOptions = $this->getAdminOptions();
global $post;
$meta = get_post_custom($post->ID);
$adkeys = array('adsense', 'adsense-top', 'adsense-middle', 'adsense-bottom') ;
$ezkeys = array('adsense', 'show_leadin', 'show_midtext', 'show_leadout') ;
$metaOptions = array() ;
// initialize to ezAdOptions
foreach ($ezkeys as $key => $optKey) {
$metaOptions[$ezkeys[$key]] = $ezAdOptions[$optKey] ;
}
// overwrite with custom fields
if (!empty($meta)) {
foreach ($meta as $key => $val) {
$tkey = array_search(strtolower(trim($key)), $adkeys) ;
if ($tkey !== FALSE) {
$value = strtolower(trim($val[0])) ;
// ensure valid values for options
if ($value == 'left' || $value == 'right' || $value == 'center' || $value == 'no') {
if ($value == 'left' || $value == 'right') $value = 'float:' . $value ;
if ($value == 'center') $value = 'text-align:' . $value ;
$metaOptions[$ezkeys[$tkey]] = $value ;
}
}
}
}
return $metaOptions ;
}
// Serve a help file name
function gethelp($id) {
$dir = dirname(__FILE__) ;
if(!empty($this->locale)) {
$fname1 = '/lang/' . $this->locale . '/help' . $id . '.htm';
if(@file_exists($dir . $fname1) && is_readable($dir . $fname1)) $fname = $fname1 ;
else $fname = '/lang/help' . $id . '.htm' ;
}
if(!@file_exists($dir . $fname) || !is_readable($dir . $fname)) {
$fname = '/lang/help-not-found.htm' ;
}
return $this->plugindir . $fname ;
}
function adsNow_content($content) {
$adNwOptions = $this->getAdminOptions();
if ($adNwOptions['kill_pages'] && is_page()) return $content ;
global $nwCount ;
if ($nwCount >= $this->nwMax) return $content ;
if(strpos($content, "") !== false) return $content;
$metaOptions = $this->contentMeta() ;
if ($metaOptions['adsense'] == 'no') return $content;
$show_leadin = $metaOptions['show_leadin'] ;
$leadin = '' ;
if ($show_leadin != 'no')
{
if ($nwCount < $this->nwMax)
{
$nwCount++;
$leadin =
stripslashes('' .
$adNwOptions['ad_text'] . '
') ;
}
}
$show_midtext = $metaOptions['show_midtext'] ;
if ($show_midtext != 'no')
{
if ($nwCount < $this->nwMax)
{
$midtext =
stripslashes('' .
$adNwOptions['ad_text'] . '
') ;
$poses = array();
$lastpos = -1;
$repchar = " $half)
array_pop($poses);
$pickme = $poses[floor(sizeof($poses)/2)];
$nwCount++;
$content = substr_replace($content, $midtext.$repchar, $pickme, 2);
}
}
$show_leadout = $metaOptions['show_leadout'] ;
$leadout = '' ;
if ($show_leadout != 'no')
{
if ($nwCount < $this->nwMax)
{
$nwCount++;
$leadout =
stripslashes('
' .
$adNwOptions['ad_text'] . '
') ;
}
}
return $leadin . $content . $leadout ;
}
}
} //End Class adsNow
$nwCount = 0 ;
if (class_exists("adsNow")) {
$nw_ad = new adsNow();
if (isset($nw_ad)) {
//Initialize the admin panel
if (!function_exists("adsNow_ap")) {
function adsNow_ap() {
global $nw_ad ;
if (function_exists('add_options_page')) {
add_options_page('AdSense Now!', 'AdSense Now!', 9,
basename(__FILE__), array(&$nw_ad, 'printAdminPage'));
}
}
}
add_filter('the_content', array($nw_ad, 'adsNow_content'));
add_action('admin_menu', 'adsNow_ap');
add_action('activate_' . basename(dirname(__FILE__)) . '/' . basename(__FILE__),
array(&$nw_ad, 'init'));
add_filter('plugin_action_links', array($nw_ad, 'plugin_action'), -10, 2);
}
}
?>