',
'
',
'
',
'
7.95, 'adsense-now' => 6.95, 'google-adsense' => 9.45); static $border = ''; static $kills = array('page', 'sticky', 'home', 'front_page', 'category', 'tag', 'archive', 'search', 'single', 'attachment'); static $unSettable = array('Phone', 'Tablet', 'All', 'Mobile'); static $noAds = false; static function isActive() { if (!function_exists('is_plugin_active')) { include_once ABSPATH . 'wp-admin/includes/plugin.php'; } $plgSlug = self::getPlgMode(); $plgSlug = str_replace("-ultra", "", $plgSlug); $plugin = basename(dirname(__FILE__)) . "/$plgSlug.php"; return is_plugin_active($plugin); } static function isLoggedIn() { define('WP_USE_THEMES', false); define('WP_INSTALLING', true); global $wpdb; // used within $wpHeader later for multisite. Do not remove! $isLoggedIn = false; // check from admin and ajax foreach (array("../../../..", "../../../../..") as $dir) { $wpHeader = "$dir/wp-blog-header.php"; if (@file_exists($wpHeader)) { require_once $wpHeader; break; } } if (function_exists('current_user_can')) { if (current_user_can('manage_options')) { $isLoggedIn = true; } } return $isLoggedIn; } static function doPluginActions() { $plugin_slug = self::getSlug(); require_once plugin_dir_path(__FILE__) . $plugin_slug . '-frontend.php'; } static function urlExists($url) {//se passar a URL existe $c = curl_init(); curl_setopt($c, CURLOPT_URL, $url); curl_setopt($c, CURLOPT_HEADER, 1); //get the header curl_setopt($c, CURLOPT_NOBODY, 1); //and *only* get the header curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); //get the response as a string from curl_exec(), rather than echoing it curl_setopt($c, CURLOPT_FRESH_CONNECT, 1); //don't use a cached version of the url if (!curl_exec($c)) { return false; } else { return true; } //$httpcode=curl_getinfo($c,CURLINFO_HTTP_CODE); //return ($httpcode<400); } static function validate_url($url) { $format = "Use the format http[s]://[www].site.com[/file[?p=v]]"; if (!filter_var($url, FILTER_VALIDATE_URL)) { $text = "$format"; return $text; } $pattern = '#^(http(?:s)?\:\/\/[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$#'; if (!preg_match($pattern, $url)) { $text = "$format"; return $text; } if (!self::urlExists($url)) { $text = "URL not accessible"; return $text; } return true; } static function validate_email($s) { if (!filter_var($s, FILTER_VALIDATE_EMAIL)) { return "Bad email address"; } return true; } static function validate_notNull($s) { $s = trim($s); if (empty($s)) { return "Null value not allowed"; } return true; } static function validate_number($s) { if (!is_numeric($s)) { return "Need a number here"; } return true; } static function validate_alnum($s) { $aValid = array('_', '-'); $s = str_replace($aValid, '', $s); if (!ctype_alnum($s)) { return "Please use only letters, numbers, - and _"; } return true; } // AJAX CRUD implementation. Create. static function create() { // creates a new DB record self::update(); } // AJAX CRUD implementation. Delete. static function read() { // not implemented } // AJAX CRUD implementation. Update using wpdb->replace() static function update() { $posted_pk = $posted_name = $posted_value = $posted_validator = ""; if (!EzGA::isLoggedIn()) { http_response_code(400); die("Please login before changing options!"); } global $wpdb; if (empty($wpdb)) { http_response_code(400); die("Global variable wpdb not set!"); } $table = $wpdb->prefix . "ez_adsense_options"; $row = array(); extract($_POST, EXTR_PREFIX_ALL, 'posted'); if (empty($posted_pk)) { http_response_code(400); die("Empty primary key"); } if (empty($posted_name)) { http_response_code(400); die("Empty name ($posted_name) in data"); } if (!isset($posted_value)) { // Checkbox, unchecked $posted_value = 0; } if (is_array($posted_value)) { // Checkbox (from checklist), checked $posted_value = 1; } if (!empty($posted_validator)) { // a server-side validator is specified $fun = "validate_$posted_validator"; if (method_exists('EzGA', $fun)) { $valid = self::$fun($posted_value); } else { http_response_code(400); die("Unknown validator ($posted_validator) specified"); } if ($valid !== true) { http_response_code(400); die("$valid"); } } $row['name'] = $posted_pk; $row['value'] = $posted_value; foreach (array('plugin_slug', 'theme', 'provider', 'optionset') as $col) { $posted = "posted_$col"; if (!empty($$posted)) { $row[$col] = $$posted; } else { $row[$col] = "All"; } } $status = $wpdb->replace($table, $row); if ($status === false) { http_response_code(400); die("Database Replace/Insert Error"); } http_response_code(200); exit(); } // AJAX CRUD implementation. Delete. static function delete() { // not implemented } static function isAssoc($options) { $isAssoc = count(array_filter(array_keys($options), 'is_string')) > 0; return $isAssoc; } static function mkSelectSource($options) { $isAssoc = self::isAssoc($options); $source = "["; foreach ($options as $k => $o) { if ($isAssoc) { $source .= "{value: '$k', text: '$o'},"; } else { $source .= "{value: '$o', text: '$o'},"; } } $source .= "]"; return $source; } static function getThemes($killCurrent = true) { global $wpdb; $table = $wpdb->prefix . "ez_adsense_options"; $sql = "SELECT DISTINCT theme FROM $table "; $themsDB = $wpdb->get_results($sql); $themes = array(); foreach ($themsDB as $t) { if ($t->theme != 'All') { $themes[] = $t->theme; } } $theme = array(get_option('stylesheet')); if ($killCurrent) { $themes = array_diff($themes, $theme); } $themes = array_values($themes); return $themes; } static function getOptionSets($settableOnly = false) { global $wpdb; $table = $wpdb->prefix . "ez_adsense_options"; $plugin_slug = self::getSlug(); $sql = "SELECT DISTINCT optionset FROM $table WHERE plugin_slug = '$plugin_slug'"; $optionSetsDB = $wpdb->get_results($sql); $optionSets = array(); foreach ($optionSetsDB as $t) { if ($t->optionset != 'All') { $optionSets[] = $t->optionset; } } if ($settableOnly) { $unSettable = self::$unSettable; $unSettable[] = self::getGenOption('optionset'); $optionSets = array_diff($optionSets, $unSettable); } $optionSets = array_values($optionSets); return $optionSets; } static function setOptionset($name) { self::$options = self::getOptions($name); self::putGenOption('editing', $name); if (!in_array($name, self::$unSettable)) { self::putGenOption('optionset', $name); } } static function getAllOptions() { global $wpdb; $table = $wpdb->prefix . "ez_adsense_options"; $sql = "SELECT name, value FROM $table WHERE plugin_slug='All' AND theme='All' AND provider='All' AND optionset='All'"; $row = $wpdb->get_results($sql); $options = array(); if (!empty($row)) { foreach ($row as $r) { $options[$r->name] = $r->value; } } return $options; } static function getOptions($optionset = "", $provider = "AdSense") { $allOptions = self::getAllOptions(); global $wpdb; $table = $wpdb->prefix . "ez_adsense_options"; if (empty($optionset)) { if (is_admin()) { $optionset = self::getGenOption('editing'); } else { $optionset = self::getGenOption('optionset'); } } if (empty($optionset)) { $optionset = "Default"; self::setOptionset($optionset); } $plugin_slug = self::getSlug(); $lookup = array('google-adsense' => 'Google AdSense', 'easy-adsense' => 'Easy AdSense', 'adsense-now' => 'AdSense Now!'); $plugin = $lookup[$plugin_slug]; $theme = get_option('stylesheet'); self::putGenOption('theme', $theme); $sql = "SELECT name,value FROM $table WHERE plugin_slug='$plugin_slug' AND theme='$theme' AND provider='$provider' AND optionset='$optionset'"; $rows = $wpdb->get_results($sql); $defaultText = 'Please generate and paste your ad code here. If left empty, the ad location will be highlighted on your blog pages with a reminder to enter your code.'; $options = compact('plugin', 'theme', 'provider', 'optionset', 'plugin_slug', 'defaultText'); foreach ($rows as $row) { $options[$row->name] = $row->value; } self::$options = $options = array_merge($allOptions, $options); require "admin/$plugin_slug-options.php"; $defaults = EzGA::getDefaults($ezOptions); self::$options = $options = array_merge($defaults, $options); return $options; } static function info($hide = true) { if (!function_exists('get_plugin_data')) { require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); } $dir = plugin_dir_path(__FILE__); $slug = ''; foreach (self::$plgPrice as $plg => $price) { if (strpos($dir, $plg) !== false) { $slug = $plg; break; } } $plugin_data = get_plugin_data("$dir$slug.php"); $str = "{$plugin_data['Name']} V{$plugin_data['Version']}"; if ($hide) { $str = ""; } return $str; } static function getDefaults($ezOptions, $echo = false) { $defaults = array(); $msg = '
';
foreach ($ezOptions as $k => $v) {
if (isset($v['value'])) {
$defaults[$k] = $v['value'];
}
else {
$msg .= "No default for $k\n";
}
}
$msg .= "";
if ($echo) {
echo $msg;
}
return $defaults;
}
static function putDefaults($ezOptions, $optionset = '', $force = false, $provider = "AdSense") {
$row = array();
foreach (array('plugin_slug', 'theme', 'provider', 'optionset') as $col) {
$row[$col] = self::$options[$col];
}
if (!empty($optionset)) {
$row['optionset'] = $optionset;
}
global $wpdb;
$table = $wpdb->prefix . "ez_adsense_options";
$defaults = self::getDefaults($ezOptions);
foreach ($defaults as $name => $value) {
if ($force || !isset(self::$options[$name])) {
$row['name'] = $name;
$row['value'] = $value;
$wpdb->replace($table, $row);
}
}
}
static function renderOption($pk, $option) {
$optionsDB = EzGA::$options;
if (isset($optionsDB[$pk])) {
$value = $optionsDB[$pk];
$option['value'] = $value;
if (!empty($option['options']) && is_array($option['options']) && self::isAssoc($option['options'])) {
$option['value'] = $option['options'][$value];
}
}
return self::renderRow($pk, $option);
}
static function renderOptionCell($pk, $option) {
$optionsDB = EzGA::$options;
if (isset($optionsDB[$pk])) {
$value = $optionsDB[$pk];
$option['value'] = $value;
if (!empty($option['type']) && $option['type'] == 'select' &&
!empty($option['options']) && is_array($option['options']) &&
self::isAssoc($option['options'])
) {
$option['key'] = $value;
$option['value'] = $option['options'][$value];
}
}
$name = $option['name'];
if (!empty($option['type'])) {
$type = $option['type'];
}
else {
$type = 'text';
}
$helpAttr = self::renderHelpAttr($pk, $option);
switch ($type) {
case 'textarea':
$value = self::renderOptionValue($pk, $option);
$cell = "$msg"; } echo ''; } } static function flashError($msg, $noPre = false) { self::flashMsg($msg, 'Error', false, $noPre); } static function showError($msg, $noPre = false) { self::flashMsg($msg, 'Error', true, $noPre); } static function flashWarning($msg, $noPre = false) { self::flashMsg($msg, 'Warning', false, $noPre); } static function showWarning($msg, $noPre = false) { self::flashMsg($msg, 'Warning', true, $noPre); } static function flashSuccess($msg, $noPre = false) { self::flashMsg($msg, 'Success', false, $noPre); } static function showSuccess($msg, $noPre = false) { self::flashMsg($msg, 'Success', true, $noPre); } static function flashInfo($msg, $noPre = false) { self::flashMsg($msg, 'Info', false, $noPre); } static function showInfo($msg, $noPre = false) { self::flashMsg($msg, 'Info', true, $noPre); } static function toggleMenu($header) { if (!empty($_SERVER["HTTP_REFERER"])) { $referer = $_SERVER["HTTP_REFERER"]; } else { $referer = ''; } $standAlone = (strpos($referer, 'wp-admin/options-general.php') === false) && !isset($_REQUEST['inframe']); if (!$standAlone) { $search = array('