settings = new WordPressSettingsFramework(ARS_PATH_INCLUDES . '/settings/ars.php');
}
/**
* AdSense display filter
*/
public function ars_display($content)
{
if (!is_single())
return $content;
$options = get_option('ars_settings');
if (!$options)
return $content;
$admin_pub = $options['ars_general_publisher_id'];
if (empty($admin_pub) || !preg_match('/pub-\d{16}/', $admin_pub))
return $content;
$author_pub = get_the_author_meta('ars-publisher');
$author_percent = get_the_author_meta('ars-percent');
if ($author_percent)
$percent = $author_percent;
if (empty($author_pub) || !preg_match('/pub-\d{16}/', $author_pub))
$author_pub = $admin_pub;
$percent = $options['ars_general_percent'];
$display_pub = (mt_rand(1, 100) <= $percent) ? $author_pub : $admin_pub;
list($width, $height) = explode('x', $options['ars_general_size']);
$ad_code = '
';
$position = $options['ars_general_position'];
switch ($position) {
case 'header':
$new_content = $ad_code . '
' . $content;
break;
case 'footer':
$new_content = $content . '
' . $ad_code;
break;
default:
$new_content = $content;
}
return $new_content;
}
public function ars_shortcode_button()
{
if (!current_user_can('edit_posts') && !current_user_can('edit_pages')) {
return;
}
if (get_user_option('rich_editing') == 'true') {
add_filter('mce_external_plugins', array($this, 'add_plugin'));
add_filter('mce_buttons', array($this,'register_button'));
}
}
public function register_button($buttons)
{
array_push($buttons, "|", "ars");
return $buttons;
}
public function add_plugin($plugin_array)
{
$plugin_array['ars'] = plugins_url('js/ars.js', __FILE__);
return $plugin_array;
}
public function ars_shortcode($atts)
{
global $post;
extract( shortcode_atts(
array(
'size' => '250x250',
), $atts )
);
$general_options = get_option('ars_settings');
$admin_pub = $general_options['ars_general_publisher_id'];
$percent = $general_options['ars_general_percent'];
if (is_single())
$post_id = $GLOBALS['post']->ID;
if ($post->ID) {
$author_id = get_post($post->ID)->post_author;
$author_pub = get_the_author_meta('ars-publisher', $author_id);
$author_percent = get_the_author_meta('ars-percent', $author_id);
}
if ($author_percent)
$percent = $author_percent;
if (empty($author_pub) || !preg_match('/pub-\d{16}/', $author_pub))
$author_pub = $admin_pub;
list($width, $height) = explode('x', $atts['size']);
$display_pub = (mt_rand(1, 100) <= $percent) ? $author_pub : $admin_pub;
if (empty($display_pub) || !preg_match('/pub-\d{16}/', $display_pub))
$content = '';
else
$content = '
';
return $content;
}
/**
* Adding JavaScript scripts
*
* Loading existing scripts from wp-includes or adding custom ones
*/
public function ars_add_js()
{
}
/**
* Adding JavaScript scripts for the admin pages only
*
* Loading existing scripts from wp-includes or adding custom ones
*/
public function ars_add_admin_js()
{
}
/**
* Add CSS styles
*/
public function ars_add_css()
{
}
/**
* Add admin CSS styles - available only on admin
*/
public function ars_add_admin_css()
{
}
/**
* Callback for registering pages
*/
public function ars_admin_pages_callback()
{
add_options_page(__("Adsense Revenue Share", 'base'), __("Adsense Rev Share", 'base'), 'manage_options', 'ars-plugin-base', array($this, 'ars_settings'));
}
/**
* The content of the settings page
*/
public function ars_settings()
{
$this->settings->settings();
}
/**
* Add user extra meta fields
*/
public function ars_profile_fields($user)
{
?>
AdSense Information
Settings';
array_push($links, $settings_link);
return $links;
}
}
/**
* Register activation hook
*/
function ars_on_activate_callback()
{
}
/**
* Register deactivation hook
*/
function ars_on_deactivate_callback()
{
}
// Initialize plugin
$ars_plugin_base = new ARS_Plugin_Base();