Settings → AdSense Now!, or use the "Settings" link on the right.
Version: 1.01
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 ;
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__)) ;
$adsNowAdminOptions = array(
'ad_text' =>
'
',
'show_leadin' => 'float:right',
'show_midtext' => 'float:left',
'show_leadout' => 'float:right'
);
$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'];
}
update_option($mOptions, $adNwOptions);
?>
getAdminOptions($reset);
?>
" .
__('Settings', 'adsense-now') . "";
array_unshift( $links, $settings_link );
}
return $links;
}
function adsNow_content($content) {
$adNwOptions = $this->getAdminOptions();
global $nwCount ;
if ($nwCount >= $this->nwMax) return $content ;
if(strpos($content, "") !== false) return $content;
global $post;
$admeta = get_post_meta($post->ID, "adsense", true);
if (strtolower(trim($admeta)) == 'no') return $content;
$show_leadin = $adNwOptions['show_leadin'] ;
$leadin = '' ;
if ($show_leadin != 'no')
{
if ($nwCount < $this->nwMax)
{
$nwCount++;
$leadin =
stripslashes('' .
$adNwOptions['ad_text'] .
'
') ;
}
}
$show_midtext = $adNwOptions['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 = $adNwOptions['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);
}
}
?>