http://tools.arielbrailovsky.com/viralad/ * Author: Ariel Brailovsky * Desarrollo: Ariel Brailovsky, J.Laso, M.Santos * Author URI: http://tools.arielbrailovsy.com * */ define ('ABRKY_PREFIX_FUNC', "aBrky_"); define ('ABRKY_PREFIX_TEXT', "ABrky "); //error_reporting (E_ALL); class ArielBrailovskyClass { /** variables de la clase **/ var $opciones = array(); // opciones del plugin var $ajustes = array(); // ajustes del plugin var $mi_request = array(); // contiene los parametros GET/POST var $defAjustes = array( 'font_family' => 'Arial', 'font_size' => 11, 'font_color' => '#0f0f0f', 'bg_color' => '#f0f0f0', 'border_color'=> '#555555', 'text_align' => 'left', 'font_italic' => 0, 'font_bold' => 0, 'font_underline'=>0 ); var $urlSitio = ''; // la url del sitio WP var $pathWpContent = ''; // el path de wp-content dentro del sistema var $selectedId = 0; // ID del link que mostraremos var $activado = 0; // Si ya hemos mostrado la barra var $preactivado = 0; var $html_content = ''; public function getPathWpContent() { return $this->pathWpContent; } function getUrlSitio() { return $this->urlSitio; } function getOpciones() { return $this->opciones; } function getAjustes() { return $this->ajustes; } /* =================================================== * determina la ubicación de las rutas * =================================================== */ function ArielBrailovskyClass(){ // se queda con la parte de la ruta que pende de wp-content/plugins $mi_path = preg_replace("/^.*[\\\\\/]wp-content[\\\\\/]plugins[\\\\\/]/", "", dirname(__FILE__)); $mi_path = str_replace('\\','/',$mi_path); $this->pathWpContent = $mi_path; $mi_path = get_bloginfo('wpurl'); $this->urlSitio = (strpos( $mi_path,'http://')) ? $mi_path : get_bloginfo('siteurl') ; //Comprobamos si el plugin está habilitado $this->activado = get_option('abva_activated'); } /* =================================================== * Función de instalación * =================================================== */ function abva_install() { global $wpdb; ob_start(); $abva_version = "1.0.7"; $table_name_options = $wpdb->prefix . 'abva_options'; $table_name_data = $wpdb->prefix . 'abva_data'; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); if (! $st = dbDelta("DROP TABLE IF EXISTS " . $table_name_options)) add_option("abva_error1","status: ".$st); if (! $st = dbDelta("DROP TABLE IF EXISTS " . $table_name_data)) add_option("abva_error2","status: ".$st); $sql = "CREATE TABLE " . $table_name_options . " ( id mediumint(9) NOT NULL AUTO_INCREMENT, id_ad mediumint(9) NOT NULL, param VARCHAR(55) DEFAULT '' NOT NULL, value VARCHAR(55) DEFAULT '' NOT NULL, UNIQUE KEY id (id) );"; if (!$st = dbDelta($sql)) add_option('avba_error3',"status ".$st); $sql = "CREATE TABLE " . $table_name_data . " ( id mediumint(9) NOT NULL AUTO_INCREMENT, `text` VARCHAR(255) DEFAULT '' NOT NULL, url VARCHAR(255) DEFAULT '' NOT NULL, active TINYINT(1) DEFAULT 0, priority MEDIUMINT(3) DEFAULT 0, total_clicks INT(9) DEFAULT 0, last_clicks INT(9) DEFAULT 0, impressions INT(9) DEFAULT 0, UNIQUE KEY id (id) );"; if (!$st = dbDelta($sql)) add_option('avba_error4',"status ".$st); // ahora se inserta un anuncio de ejemplo if (!$st = $wpdb->query("INSERT INTO ".$table_name_data." (id, text, url, active, priority) VALUES (1, 'Consigue Gratis Tu Propio ViralAd
Click Aquí', 'http://tools.arielbrailovsky.com/viralad', 1, 50)") ) add_option('avba_error5',"Excepción capturada: ".$st); if (!$st = $wpdb->query("INSERT INTO ".$table_name_options." (id_ad, param, value) VALUES (1, 'font_family', 'Arial'), (1, 'font_size', 16), (1, 'font_color', '#0f0f0f'), (1, 'bg_color', '#ffffff'), (1, 'border_color', '#ffffff'), (1, 'text_align', 'center'), (1, 'font_italic', 0), (1, 'font_underline', 0), (1, 'font_bold', 0)") ) add_option('avba_error6',"Excepción capturada: ".$st); add_option("abva_version", $abva_version); add_option("abva_verified", 0); add_option("abva_idcb", ""); update_option("abva_chart","SI"); // utilizar las gráficas de google en lugar de las propias ob_clean(); } /* =================================================== * Función de desinstalación * =================================================== */ function abva_uninstall() { global $wpdb; $table_name_options = $wpdb->prefix . 'abva_options'; $table_name_data = $wpdb->prefix . 'abva_data'; $wpdb->query("DROP TABLE IF EXISTS " . $table_name_options); $wpdb->query("DROP TABLE IF EXISTS " . $table_name_data); delete_option("abva_version"); delete_option("abva_verified"); delete_option("abva_idcb"); delete_option("abva_error1"); delete_option("abva_error2"); delete_option("abva_error3"); delete_option("abva_error4"); delete_option("abva_error5"); delete_option("abva_error6"); } public function getParam($id=0, $param='font_family') { global $wpdb; if(strlen($param)) { $table_name_data = $wpdb->prefix . 'abva_options'; $sql = "SELECT value FROM ".$table_name_data." WHERE param = '".$param."' AND id_ad = '".$id."'"; //echo $sql; $data = $wpdb->get_var($wpdb->prepare($sql)); return $data; } else return ''; } /* =================================================== * Determina un elemento a mostrar * =================================================== */ private function selectLink() { global $wpdb; $table_name_data = $wpdb->prefix . 'abva_data'; $id = 0; //Calculamos el total de impresiones $sql = "SELECT SUM(impressions) total FROM ".$table_name_data." WHERE active = 1"; $total = $wpdb->get_var($wpdb->prepare($sql)); //Calculamos la prioridad total $sql = "SELECT SUM(priority) total FROM ".$table_name_data." WHERE active = 1"; $totalPriority = $wpdb->get_var($wpdb->prepare($sql)); //Consultamos cuáles no han cubierto aún su cupo para determinar uno al azar $sql = "SELECT id, priority, impressions FROM ".$table_name_data." WHERE active = 1 "; if($total>0) $sql .= "AND priority > (impressions/".$total.")*".$totalPriority; $sql .=" ORDER BY priority DESC"; $data = $wpdb->get_results($sql); $i = array_rand($data); $row = $data[$i]; $id = $row->id; //echo $id; //Si todos cubrieron el cupo, determinamos uno al azar if(!$id) { $sql = "SELECT id FROM ".$table_name_data." WHERE active = 1"; $data = $wpdb->get_results($sql); $i = array_rand($data); $row = $data[$i]; $id = $row->id; } $this->selectedId = $id; } /* =================================================== * Preconstruye un link dado e incrementa una impresión * =================================================== */ private function prepareLink() { global $wpdb; $table_name_data = $wpdb->prefix . 'abva_data'; $sql = "SELECT * FROM ".$table_name_data." WHERE id = '".$this->selectedId."'"; $row = $wpdb->get_row($sql); $texto = html_entity_decode($row->text,ENT_COMPAT,"UTF-8"); $url = $row->url; $show = ''.$texto.''; if(!is_admin()) { $wpdb->query("UPDATE ".$table_name_data." SET impressions = impressions + 1 WHERE id = ".$this->selectedId); } return $show; } /* =================================================== * Construcción del div * =================================================== */ function displayDiv() { //if(!preg_match("/.*\/wp-admin\/.*/",$_SERVER['PHP_SELF'])) { $url = plugins_url(); $tdeco = ($this->getParam($this->selectedId,'font_underline'))?'underline':'none'; $tcursiva = ($this->getParam($this->selectedId,'font_italic'))?'italic':'normal'; $tnegrita = ($this->getParam($this->selectedId,'font_bold'))?'bold':'normal'; //$align = ($this->getParam($this->selectedId,'text_align')=='right')?'left':'right'; $idcb = get_option('abva_idcb'); $img = file_get_contents('http://tools.arielbrailovsky.com/viralad/getimage.php'); $html = "
');\" onmouseout=\"return nd();\"> \"Powered ".$this->prepareLink()."
"; //} return $html; } /* =================================================== * Muestra el resultado del plugin * =================================================== */ function printViralAd() { if (!is_admin()) { if(0 === $this->activado) { $this->activado = 1; $this->selectLink(); $miDiv = '$1'.$this->displayDiv(); if ( 1 == $this->preactivado) { $html = ob_get_contents(); ob_end_clean(); echo preg_replace( '/(\)/i', $miDiv, $html ); $this->preactivado = 0; } } } } function prePrintViralAd() { if (!is_admin() && !$this->preactivado && !$this->activado) { $this->preactivado = 1; ob_start(); } } } ?>