";
echo '';
echo '';
}
add_action('admin_head', 'custom_admin_header');
/*----------------------------------------------------------------------------*
* Dashboard and Administrative Functionality
*----------------------------------------------------------------------------*/
/*
* @TODO:
*
* - replace `class-adsoptimal-admin.php` with the name of the plugin's admin file
* - replace Plugin_Name_Admin with the name of the class defined in
* `class-adsoptimal-admin.php`
*
* If you want to include Ajax within the dashboard, change the following
* conditional to:
*
* if ( is_admin() ) {
* ...
* }
*
* The code below is intended to to give the lightest footprint possible.
*/
if ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
require_once( plugin_dir_path( __FILE__ ) . 'admin/class-adsoptimal-admin.php' );
add_action( 'plugins_loaded', array( 'AdsOptimal_Admin', 'get_instance' ) );
}
function adsoptimal_script_head() {
if (get_option('adsoptimal_settings', '') != '') {
$object = json_decode(rawurldecode(get_option('adsoptimal_settings', '{"jscode": ""}')), true);
if ($object && array_key_exists('jscode', $object)) {
echo $object['jscode'];
}
}
if (get_option('adsoptimal_enable_desktop_ad', 'false') == 'true') {
?>
';
}
}
function adsoptimal_loop_end(&$wp_query) {
if (get_option('adsoptimal_enable_desktop_ad', 'false') == 'false') return;
if (get_option('adsoptimal_footer_ad_type', '') == '') return;
if (is_single() && get_option('adsoptimal_enable_post_ad', 'true') == 'false') return;
if (!is_single() && get_option('adsoptimal_enable_page_ad', 'true') == 'false') return;
global $wp_the_query;
if (($wp_query === $wp_the_query) && !is_admin() && !is_feed() && !is_robots() && !is_trackback()) {
$size = split('x', get_option('adsoptimal_footer_ad_type', ''));
echo '
';
}
}
class SharedParams {
public $countWord = 0;
public $foundDot = false;
public $insertCount = 0;
public $targetAt = 100;
function __construct() {
$this->targetAt = intval(get_option('adsoptimal_content_ad_every', '100'));
}
}
function addContentAd(DOMNode $domNode, $sharedParams) {
foreach ($domNode->childNodes as $node)
{
if ($sharedParams->insertCount >= 2) return;
if ($node->nodeType == XML_TEXT_NODE) {
$splitedText = split(' ', $node->nodeValue);
for ($i=0; $icountWord += 1;
if ($sharedParams->countWord >= $sharedParams->targetAt) {
if ($sharedParams->foundDot) {
$splitedText[$i] = '[ADSOPTIMAL_AD_TAG]'.$splitedText[$i];
$sharedParams->insertCount += 1;
$sharedParams->countWord = 0;
$sharedParams->foundDot = false;
}
elseif (strpos($splitedText[$i], '.') !== false) {
$sharedParams->foundDot = true;
}
}
}
$node->nodeValue = join(' ', $splitedText);
}
if($node->hasChildNodes()) {
addContentAd($node, $sharedParams);
}
}
}
function adsoptimal_content($content = '') {
if (get_option('adsoptimal_enable_desktop_ad', 'false') == 'false') return $content;
if (get_option('adsoptimal_content_ad_type', '') == '') return $content;
if (is_single() && get_option('adsoptimal_enable_post_ad', 'true') == 'false') return $content;
if (!is_single() && get_option('adsoptimal_enable_page_ad', 'true') == 'false') return $content;
if (!is_single()) return $content;
if (!is_admin() && !is_feed() && !is_robots() && !is_trackback()) {
$size = split('x', get_option('adsoptimal_content_ad_type', ''));
$adHtml = '
';
$sharedParams = new SharedParams();
$dom = new DOMDocument();
$libxml_previous_state = libxml_use_internal_errors(true);
$dom->loadHTML('