function update($new_instance, $old_instance) { $instance = $old_instance; /* Strip tags (if needed) and update the widget settings. */ $instance['title'] = strip_tags($new_instance['title']); $instance['advert'] = $new_instance['advert']; $options = adinj_options(); write_ad_to_file($instance['advert'], $this->get_ad_file_path2()); return $instance; }
function widget($args, $instance) { if (adinj_ads_completely_disabled_from_page('widget')) { return; } if (is_front_page() && adinj_ticked('widget_exclude_front') || is_home() && adinj_ticked('widget_exclude_home') || is_page() && adinj_ticked('widget_exclude_page') || is_single() && adinj_ticked('widget_exclude_single') || is_archive() && adinj_ticked('widget_exclude_archive') || is_search() && adinj_ticked('widget_exclude_search') || is_404() && adinj_ticked('widget_exclude_404')) { return; } if (is_front_page() && adinj_ticked('exclude_front', $instance) || is_home() && adinj_ticked('exclude_home', $instance) || is_page() && adinj_ticked('exclude_page', $instance) || is_single() && adinj_ticked('exclude_single', $instance) || is_archive() && adinj_ticked('exclude_archive', $instance) || is_search() && adinj_ticked('exclude_search', $instance) || is_404() && adinj_ticked('exclude_404', $instance)) { return; } if (!adinj_allowed_in_category('widget', $instance)) { return; } if (!adinj_allowed_in_tag('widget', $instance)) { return; } if (!adinj_allowed_in_author('widget', $instance)) { return; } if (!adinj_allowed_in_id('widget', $instance)) { return; } extract($args); $ops = adinj_options(); $include = ""; if (adinj_mfunc_mode()) { $include = adinj_ad_code_include(); } $title = apply_filters('widget_title', $instance['title']); // The old 'non upgraded' db will be passed here if the widget hasn't // been resaved. We can't upgrade as doing so would mean we'd have to // re-save the widget files - which we can't do as we can't re-write // the settings back to the db (at least not without a bit more work) $adcode = adinj_get_ad_code('widget_' . $this->get_id(), $instance); echo $before_widget; if ($title) { echo $before_title . $title . $after_title; } if (!empty($adcode)) { echo $include; echo $adcode; } echo $after_widget; }
function adinj_add_row_with_text_box($name_stem, $num, $title, $total) { $ops = adinj_options(); $name = $name_stem . $num; $namesplit = $name . '_split'; $percent = adinj_percentage_split($name_stem, $num, $ops, $total); echo <<<EOT \t<tr><td> \t<a name="{$name}"></a> \t<span style="font-size:10px;"><b>{$title} {$num}</b></span><br /> \t<textarea name="{$name}" rows="8" cols=" EOT; adinj_table_width('rotation'); echo '">' . adinj_process_text($ops[$name]); echo <<<EOT </textarea> \t</td><td> \t<input name="{$namesplit}" size="7" value="{$ops[$namesplit]}" /> \t<br /> \t{$percent} \t</td></tr> EOT; }
function adinj_config_block_hours() { // if blocked by referrer $ops = adinj_options(); return $ops['block_ads_for_hours']; }
function adinj_init_hook() { $ops = adinj_options(); if ($ops['ads_enabled'] != 'on') { add_action('admin_notices', 'adinj_init_warning'); } }
function adinj_side_status_box() { $ops = adinj_options(); ?> <div class="postbox-container" style="width:258px;"> <div class="metabox-holder"> <div class="meta-box-sortables" style="min-height:50px;"> <div class="postbox"> <h3 class="hndle"><span><?php echo adinj_get_logo(); ?> Status</span></h3> <div class="inside" style="margin:5px;"> <style type="text/css"> .adinjstatustable td { vertical-align: top; } .adinjstatustable td { padding: 2px; } </style> <table border="0" cellpadding="2" class="adinjstatustable"> <tr><td style="text-align:right"> <b><a href="#global">Ads enabled</a></b> </td><td> <?php $info = adinj_get_status('global'); echo adinj_dot($info[0]) . ' ' . $info[1]; if ($info[0] != 'red') { ?> </td></tr> <tr><td style="text-align:right"> <b><a href='#global'>Ads on posts</a></b> </td><td> <?php $info = adinj_get_status('older_than_normal'); echo adinj_dot($info[0]) . ' ' . $info[1]; ?> </td></tr> <tr><td style="text-align:right"> <b><a href='#global'>Widgets on posts</a></b> </td><td> <?php $info = adinj_get_status('older_than_widgets'); echo adinj_dot($info[0]) . ' ' . $info[1]; ?> </td></tr> <tr><td style="text-align:right"> <b><a href="#restrictions">Mode</a></b> </td><td> <?php $info = adinj_get_status('mode'); echo adinj_dot($info[0]) . ' ' . $info[1]; ?> </td></tr> <tr><td style="text-align:right"> <b><a href="#restrictions">Restrictions</a></b> </td><td> <?php $info = adinj_get_status('restrictions'); echo adinj_dot($info[0]) . ' ' . $info[1]; ?> </td></tr> <tr><td style="text-align:right"> <b><a href='?page=ad-injection&tab=debug#debugging'>Debug mode</a></b> </td><td> <?php $info = adinj_get_status('debugging'); echo adinj_dot($info[0]) . ' ' . $info[1]; ?> </td></tr> <tr><td colspan="2"> <p></p> <b>Ads on/off summary</b><br /> <table class="adinjstatustable"> <tr> <td></td> <td><b>Ads</b></td> <td><b>Alt</b></td> <td><b>S</b></td> <td><b>P</b></td> <td><b>H</b></td> <td><b>F</b></td> <td><b>A</b></td> </tr> <tr> <td style="text-align:right"><b><a href="#topadplacement">Top</a></b></td> <td><?php echo adinj_count_live_ads('top', $ops); ?> </td> <td><?php echo adinj_count_live_ads('top_alt', $ops); ?> </td> <td><?php adinj_print_ad_dot('top', 'single'); ?> </td> <td><?php adinj_print_ad_dot('top', 'page'); ?> </td> <td><?php adinj_print_ad_dot('top', 'home'); ?> </td> <td><?php adinj_print_ad_dot('top', 'front'); ?> </td> <td><?php adinj_print_ad_dot('top', 'archive'); ?> </td> </tr> <tr> <td style="text-align:right"><b><a href="#randomadplacement">Random</a></b></td> <td><?php echo adinj_count_live_ads('random', $ops); ?> </td> <td><?php echo adinj_count_live_ads('random_alt', $ops); ?> </td> <td><?php adinj_print_ad_dot('random', 'single'); ?> </td> <td><?php adinj_print_ad_dot('random', 'page'); ?> </td> <td><?php adinj_print_ad_dot('random', 'home'); ?> </td> <td><?php adinj_print_ad_dot('random', 'front'); ?> </td> <td><?php adinj_print_ad_dot('random', 'archive'); ?> </td> </tr> <tr> <td style="text-align:right"><b><a href="#bottomadplacement">Bottom</a></b></td> <td><?php echo adinj_count_live_ads('bottom', $ops); ?> </td> <td><?php echo adinj_count_live_ads('bottom_alt', $ops); ?> </td> <td><?php adinj_print_ad_dot('bottom', 'single'); ?> </td> <td><?php adinj_print_ad_dot('bottom', 'page'); ?> </td> <td><?php adinj_print_ad_dot('bottom', 'home'); ?> </td> <td><?php adinj_print_ad_dot('bottom', 'front'); ?> </td> <td><?php adinj_print_ad_dot('bottom', 'archive'); ?> </td> </tr> <tr> <td style="text-align:right"><b><a href="#footeradplacement">Footer</a></b></td> <td><?php echo adinj_count_live_ads('footer', $ops); ?> </td> <td><?php echo adinj_count_live_ads('footer_alt', $ops); ?> </td> <td><?php adinj_print_ad_dot('footer', 'single'); ?> </td> <td><?php adinj_print_ad_dot('footer', 'page'); ?> </td> <td><?php adinj_print_ad_dot('footer', 'home'); ?> </td> <td><?php adinj_print_ad_dot('footer', 'front'); ?> </td> <td><?php adinj_print_ad_dot('footer', 'archive'); ?> </td> </tr> <tr> <td style="text-align:right"><b>Widget</b></td> <td></td> <td></td> <td><?php adinj_print_ad_dot('widget', 'single'); ?> </td> <td><?php adinj_print_ad_dot('widget', 'page'); ?> </td> <td><?php adinj_print_ad_dot('widget', 'home'); ?> </td> <td><?php adinj_print_ad_dot('widget', 'front'); ?> </td> <td><?php adinj_print_ad_dot('widget', 'archive'); ?> </td> </tr> <tr> <td style="text-align:right"><b>Template</b></td> <td></td> <td></td> <td><?php adinj_print_ad_dot('template', 'single'); ?> </td> <td><?php adinj_print_ad_dot('template', 'page'); ?> </td> <td><?php adinj_print_ad_dot('template', 'home'); ?> </td> <td><?php adinj_print_ad_dot('template', 'front'); ?> </td> <td><?php adinj_print_ad_dot('template', 'archive'); ?> </td> </tr> </table> <p>S=single post | P=single page | H=home | F=front | A=archive <!--E=excerpt--></p> </td></tr> <tr><td> </td><td> </td></tr> <tr><td> </td><td> <?php } ?> </td></tr> </table> </div> </div> </div> </div> </div> <br /> <?php }
function adinj_ticked($option) { $ops = adinj_options(); if (!empty($ops[$option])) { return 'checked="checked"'; } return false; }
function adinj_upgrade_db_if_necessary() { $cached_options = adinj_options(); if (empty($cached_options)) { // 1st Install. require_once ADINJ_PATH . '/ad-injection-admin.php'; adinj_install_db(); return; } $cached_dbversion = adinj_db_version($cached_options); if (ADINJ_DB_VERSION != $cached_dbversion) { require_once ADINJ_PATH . '/ad-injection-admin.php'; adinj_upgrade_db(); } }
function adinj_debug_information() { $stored_options = adinj_options(); $default_options = adinj_default_options(); ?> <h4>Settings dump from database (all in 'adinj_options' option)</h4> <table border="1" style="width:610px; table-layout:fixed; word-wrap:break-word;"> <tr><td><b>Name</b></td><td><b>Stored</b></td><td><b>Default</b></td></tr> <?php $main_length = 0; if ($stored_options !== false) { $count = 0; foreach ($stored_options as $key => $value) { if ($count % 2 == 0) { echo '<tr style="background-color:#cccccc"><td>'; } else { echo '<tr><td>'; } echo "{$key}"; $main_length += sizeof($key); $value = htmlspecialchars($value); $main_length += sizeof($value); $default = $default_options[$key]; echo "</td><td>"; if ($value != $default) { echo '<font color="blue">'; } echo $value; if ($value != $default) { echo '</font>'; } echo "</td><td>"; echo $default; echo "</td></tr>"; $count++; } } else { echo "<br />No options in database!"; } echo '</table>'; ?> <h4>Widget settings dump from database (all in 'widget_adinj' option)</h4> <table border="1" style="width:610px; word-wrap:break-word;"> <tr><td><b>Widget</b></td><td><b>Setting:Value</b></td></tr> <?php $widgetops = get_option('widget_adinj'); $widgets_length = 0; $count = 0; if (is_array($widgetops)) { foreach ($widgetops as $key => $val) { if ($count % 2 == 0) { echo '<tr style="background-color:#cccccc"><td style="vertical-align:top">'; } else { echo '<tr><td style="vertical-align:top">'; } echo $key; $widgets_length += strlen($key); echo "</td>"; echo '<td style="vertical-align:top">'; if (is_array($val)) { foreach ($val as $subkey => $subval) { echo $subkey . ':' . htmlspecialchars($subval) . '<br />'; $widgets_length += strlen($subkey) + strlen($subval); } } else { echo htmlspecialchars($val); $widgets_length += strlen($val); } echo '</td></tr>'; ++$count; } } else { echo '<tr><td></td><td><b>No widget settings found</b></td></tr>'; } echo '</table>'; echo '<h4>Other settings</h4><blockquote>'; echo 'ADINJ_PATH=' . ADINJ_PATH . '<br />'; echo 'ADINJ_CONFIG_FILE=' . ADINJ_CONFIG_FILE . '<br />'; echo 'ADINJ_AD_PATH=' . ADINJ_AD_PATH . '<br />'; echo 'Plugin version=' . adinj_get_version() . '<br />'; echo 'Main settings length=' . $main_length . ' chars<br />'; echo 'All widgets length=' . $widgets_length . ' chars<br />'; echo '</blockquote>'; global $adinj_warning_msg_filewrite; if (!empty($adinj_warning_msg_filewrite)) { echo "<h4>Errors on 'Save all settings'</h4><blockquote>{$adinj_warning_msg_filewrite}</blockquote"; } global $adinj_warning_msg_chmod; if (!empty($adinj_warning_msg_chmod)) { echo "<h4>Warnings on 'Save all settings'</h4><blockquote>{$adinj_warning_msg_chmod}</blockquote"; } }