'on', 'checkname' => '', 'checkdate' => '', 'checkaction' => ADSHO_ACTIVE_NONE, 'tplpath' => ADSHO_TEMPLATE_DIR1, ); } break; default: return null; } return $options; } //================================= function adsho_stripPath($FilePath) { if (strlen($FilePath) > 0) { if (substr_compare($FilePath, ABSPATH, 1, strlen(ABSPATH)) ) $FilePath = "../".substr($FilePath, strlen(ABSPATH)); } return $FilePath; } //================================= function adsho_Deactivation(){ } //================================= function adsho_Uninstall(){ global $wpdb; adsho_DbUninstall(); delete_option( ADSHO_OPTIONS_GENERAL ); } //================================= function adsho_Init() { $locale = apply_filters( 'plugin_locale', get_locale(), ADSHO_TEXT_DOMAIN ); //var_dump($locale); load_plugin_textdomain( ADSHO_TEXT_DOMAIN, FALSE, dirname( plugin_basename( __FILE__ ) ) . ADSHO_LANG_DIR ); } //================================= function adsho_Loaded() { global $wpdb; adsho_DbInstall(); } //================================= //setup, install, deinstall //================================= function adsho_DbUpdate() { global $wpdb; //Check Version $table_name = $wpdb->prefix.ADSHO_TBLVERSION; $Table = $wpdb->get_var("show tables like '$table_name'"); $ve = false; if($Table == $table_name ) { $sql = "SELECT * from $table_name;"; $ve = $wpdb->get_row($sql); } if (!$ve) { adsho_DbUnInstall(); return true; } $Update = $ve->Version != ADSHO_DB_VERSION ? $ve->Version : ''; switch ($Update) { case ADSHO_DB_VERSION0100: $table_name = $wpdb->prefix.ADSHO_TBLEFFECTS; $arChars = "*,\\u2606,\\u2744"; $sql = "ALTER TABLE $table_name ADD TextChars VARCHAR(80) DEFAULT '$arChars';"; if ($wpdb->query($sql) == 1) { $Wf = array("%s"); $Wh = array("Name" => "%"); $Fo = array("%s"); $Da = array( 'TextChars' => $arChars ); $wpdb->Update($table_name, $Da, $Wh, $Fo, $Wf); } break; default: break; } if ($Update != '') { $table_name = $wpdb->prefix.ADSHO_TBLVERSION; $Wf = array("%s"); $Wh = array("Name" => "%"); $Fo = array("%s"); $Da = array( 'Version' => ADSHO_DB_VERSION ); $wpdb->Update($table_name, $Da, $Wh, $Fo, $Wf); } return( $Update != '' ); } //================================= function adsho_DbInstall () { global $wpdb; if (adsho_DbUpdate() ) { $table_name = $wpdb->prefix.ADSHO_TBLVERSION; $Table = $wpdb->get_var("show tables like '$table_name'"); if($Table != $table_name ) { // No table create $sql = "CREATE TABLE $table_name ( Version VARCHAR(10) NOT NULL DEFAULT '', PRIMARY KEY ( Version) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); $Fo = array("%s"); $Da = array('Version' => ADSHO_DB_VERSION0100); $wpdb->Insert($table_name, $Da, $Fo); } $table_name = $wpdb->prefix . ADSHO_TBLHOLIDAYS; $Table = $wpdb->get_var("show tables like '$table_name'"); if($Table != $table_name) { // No table create $sql = "CREATE TABLE $table_name ( ID BIGINT(20) NOT NULL AUTO_INCREMENT, Name VARCHAR(20) DEFAULT '', DaFrom VARCHAR(10) DEFAULT 'ccyy-00-00', DaTo VARCHAR(10) DEFAULT 'ccyy-00-00', Template VARCHAR(50) DEFAULT '', Lang VARCHAR(2) DEFAULT '', Effect VARCHAR(20) DEFAULT 0, Type INT(5) DEFAULT 0, Active TINYINT (1) NOT NULL DEFAULT ".ADSHO_ACTIVE_AUTOMATIC.", PRIMARY KEY ( ID ) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); $Fo = array("%s","%s","%s","%s","%s","%s","%d","%d"); $Da = array('Name' => 'test', 'DaFrom' => '', 'DaTo' => '', 'Template' => 'testing', 'Lang' => '', 'Effect' => 'confetti', 'Type' => ADSHO_TYPE_NONE, 'Active' => ADSHO_ACTIVE_ON); $wpdb->Insert($table_name, $Da, $Fo); $Da = array('Name' => 'easter', 'DaFrom' => '', 'DaTo' => '', 'Template' => 'easter', 'Lang' => '', 'Effect' => '', 'Type' => ADSHO_TYPE_EASTER, 'Active' => ADSHO_ACTIVE_NONE); $wpdb->Insert($table_name, $Da, $Fo); $Da = array('Name' => 'snow', 'DaFrom' => 'ccyy-12-01', 'DaTo' => 'ccyy-01-31', 'Template' => '', 'Lang' => '', 'Effect' => 'snow', 'Type' => ADSHO_TYPE_NONE, 'Active' => ADSHO_ACTIVE_AUTOMATIC); $wpdb->Insert($table_name, $Da, $Fo); $Da = array('Name' => 'advent', 'DaFrom' => 'ccyy-12-01', 'DaTo' => 'ccyy-12-26', 'Template' => 'advent', 'Lang' => '', 'Effect' => '', 'Type' => 2, 'Active' => ADSHO_ACTIVE_NONE); $wpdb->Insert($table_name, $Da, $Fo); $Da = array('Name' => 'newyear', 'DaFrom' => 'ccyy-12-27', 'DaTo' => 'ccyy-01-10', 'Template' => 'newyear', 'Lang' => '', 'Effect' => '', 'Type' => 3, 'Active' => ADSHO_ACTIVE_NONE); $wpdb->Insert($table_name, $Da, $Fo); $Da = array('Name' => 'halloween', 'DaFrom' => 'ccyy-10-31', 'DaTo' => 'ccyy-10-31', 'Template' => 'halloween', 'Lang' => '', 'Effect' => '', 'Type' => 4, 'Active' => ADSHO_ACTIVE_NONE); $wpdb->Insert($table_name, $Da, $Fo); } } $table_name = $wpdb->prefix . ADSHO_TBLEFFECTS; $Table = $wpdb->get_var("show tables like '$table_name'"); $arChars = "*,\\u2606,\\u2744"; if($Table != $table_name) { // No table create $sql = "CREATE TABLE $table_name ( ID BIGINT(20) NOT NULL AUTO_INCREMENT, Name VARCHAR(20) DEFAULT '', Count INT(2) DEFAULT 0, TimeSec INT(2) DEFAULT 0, Size VARCHAR(5) DEFAULT '', ImgName VARCHAR(50) DEFAULT '', CalcType VARCHAR(20) DEFAULT 'falling', TextChars VARCHAR(80) DEFAULT '".$arChars."', PRIMARY KEY ( ID ) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); $Fo = array("%s","%d","%d","%s","%s","%s","%s"); $Da = array('Name' => 'confetti', 'Count' => 20, 'TimeSec' => 20, 'Size' => '10-30', 'ImgName' => 'confetti*.gif', 'CalcType' => ADSHO_FUNCTION_FALLING, 'TextChars' => $arChars); $wpdb->Insert($table_name, $Da, $Fo); $Da = array('Name' => 'snow', 'Count' => 10, 'TimeSec' => 30, 'Size' => "10-30", 'ImgName' => 'snow*.png', 'CalcType' => ADSHO_FUNCTION_FALLING, 'TextChars' => $arChars); $wpdb->Insert($table_name, $Da, $Fo); $Da = array('Name' => 'onlytext', 'Count' => 10, 'TimeSec' => 20, 'Size' => "2-8", 'ImgName' => 'textmode', 'CalcType' => ADSHO_FUNCTION_FALLING, 'TextChars' => $arChars); $wpdb->Insert($table_name, $Da, $Fo); } } //================================= function adsho_DbUninstall() { global $wpdb; $table_name = $wpdb->prefix . ADSHO_TBLVERSION; $wpdb->query("DROP TABLE IF EXISTS $table_name"); $table_name = $wpdb->prefix . ADSHO_TBLHOLIDAYS; $wpdb->query("DROP TABLE IF EXISTS $table_name"); $table_name = $wpdb->prefix . ADSHO_TBLEFFECTS; $wpdb->query("DROP TABLE IF EXISTS $table_name"); } //================================= function adsho_ExportDB(){ global $wpdb; $Path = ADSHO_XML_EXPORT; if (file_exists($Path) ) unlink($Path); echo "Export\n"; $x = new XMLWriter(); $x->openUri($Path); $x->setIndentString("\t"); $x->setIndent(true); $x->startDocument('1.0','UTF-8'); $x->startElement("database"); echo "exported '".ADSHO_TBLVERSION ."'\n"; $table_name = $wpdb->prefix . ADSHO_TBLVERSION; $DAT = $wpdb->get_row("SELECT * from $table_name;"); if ($DAT) { $x->writeAttribute('Version', $DAT->Version); $x->writeAttribute('ExportTime', Date("Y-m-d\TH:i:s", current_time( 'timestamp' ))); } echo "exported '".ADSHO_TBLEFFECTS ."'\n"; $table_name = $wpdb->prefix . ADSHO_TBLEFFECTS; $DAT = $wpdb->get_results("SELECT * from $table_name;"); adsho_DoExport($x, $DAT, $table_name); echo "exported '".ADSHO_TBLHOLIDAYS ."'\n"; $table_name = $wpdb->prefix . ADSHO_TBLHOLIDAYS; $DAT = $wpdb->get_results("SELECT * from $table_name;"); adsho_DoExport($x, $DAT, $table_name); $x->endElement(); // Version $x->endDocument(); $x->flush(); unset($x); } //================================= function adsho_DoExport($x, $DAT, $table_name) { if ($DAT && count($DAT)){ $x->startElement($table_name); foreach ($DAT as $dat) { $x->startElement("record"); foreach($dat as $key => $value) { $x->startElement($key); $x->text($value); $x->endElement(); // Version } $x->endElement(); // Version } // foreach $songs $x->endElement(); // table } } //================================= function adsho_ImportDB(){ global $wpdb; $Path = ADSHO_XML_EXPORT; if (!file_exists($Path) ) return false; $fp = fopen($Path, "r"); if ($fp) { $get = fread($fp, filesize($Path)); fclose($fp); $xml = simplexml_load_string($get); echo "Version=".$xml->attributes()->Version."\n"; $DAT = (array)$xml; $table_name = $wpdb->prefix . ADSHO_TBLEFFECTS; echo "Import: ".$table_name."\n"; foreach($DAT[$table_name] as $t) { $Wf = array("%s"); $Wh = array("Name" => $t->Name); $Fo = array("%s","%d","%d","%s","%s","%s","%s"); $Da = array( 'Name' => $t->Name, 'Count' => $t->Count, 'TimeSec' => $t->TimeSec, 'Size' => $t->Size, 'ImgName' => $t->ImgName, 'CalcType' => $t->CalcType, 'TextChars' => $t->TextChars); $ret = $wpdb->get_row("SELECT * FROM $table_name WHERE LOWER(Name) LIKE '".strtolower($t->Name)."';"); if ($ret) { $ret = $wpdb->Update($table_name, $Da, $Wh, $Fo, $Wf); echo "Update '".$t->Name."'\n"; } else { $ret = $wpdb->Insert($table_name, $Da, $Fo); echo "Insert '".$t->Name."'\n"; } } $table_name = $wpdb->prefix . ADSHO_TBLHOLIDAYS; echo "\nImport: ".$table_name."\n"; foreach($DAT[$table_name] as $t) { $Wf = array("%s"); $Wh = array("Name" => $t->Name); $Fo = array("%s","%s","%s","%s","%s","%s","%d","%d"); $Da = array( 'Name' => $t->Name, 'DaFrom' => $t->DaFrom, 'DaTo' => $t->DaTo, 'Template' => $t->Template, 'Lang' => $t->Lang, 'Effect' => $t->Effect, 'Type' => $t->Type, 'Active' => $t->Active); $ret = $wpdb->get_row("SELECT * FROM $table_name WHERE LOWER(Name) LIKE '".strtolower($t->Name)."';"); if ($ret) { $ret = $wpdb->Update($table_name, $Da, $Wh, $Fo, $Wf); echo "Update '".$t->Name."'\n"; } else { $ret = $wpdb->Insert($table_name, $Da, $Fo); echo "Insert '".$t->Name."'\n"; } } } wp_die(); } //================================== //redirects //================================== function adsho_redirect() { if (preg_match("/\\/".ADSHO_FILE_EXPORT."/i", $_SERVER['REQUEST_URI']) == 1) { ob_start(); adsho_ExportDB(); $out = ob_get_contents(); ob_end_clean(); $Path = ADSHO_XML_EXPORT; if (file_exists($Path) && adsho_isAdmin() ) { $Fname = basename($Path); $Size = filesize($Path); // no errors if( function_exists('ini_set') ) @ini_set( 'display_errors', 0 ); @session_write_close(); if ( function_exists( 'apache_setenv' ) ) @apache_setenv( 'no-gzip', 1 ); if( function_exists('ini_set') ) @ini_set('zlib.output_compression', 'Off'); ignore_user_abort(true); @set_time_limit(3600); //One Houre // no cache @session_cache_limiter('none'); nocache_headers(); @ob_clean(); //send header header("X-Robots-Tag: noindex, nofollow", true ); header("Robots: none"); header("Cache-Control:"); header("Cache-Control: public"); header("Cache-Control: post-check=0, pre-check=0"); header("Cache-Control: no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); //header("Content-Type: application/xml; charset=utf-8"); header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=\"".$Fname."\""); header("Content-Transfer-Encoding: binary"); header("Content-Description: ".$Fname." - Download"); header("Content-Length: ".$Size); $fp = @fopen($Path, "rb"); if ( $fp ) { print( @fread($fp, $Size) ); @flush(); @fclose($fp); } die(); } header("HTTP/1.1 Error 404 - File or Directory not found"); header("Location: ".get_bloginfo('url')); } } //================================== //script enqueue //================================== function adsho_Scripts() { wp_enqueue_script( 'adsho_scripts', ADSHO_JAVA_URL.'falling.js', array('jquery'), '1.0', true ); //wp_enqueue_script( 'adsho_scripts', ADSHO_JAVA_URL.'adsho_scripts.js', array('jquery'), '1.0', true ); wp_localize_script( 'adsho_scripts', 'adsho_dopost', array( 'ajax_url' => admin_url( 'admin-ajax.php' ))); } //================================== //style enqueue //================================= function adsho_AddStylesheet() { wp_register_style('adshoCSS', ADSHO_STYLE_URL.'styles.css'); wp_enqueue_style( 'adshoCSS'); } //================================= function adsho_db_callback() { $typ = isset($_POST['dbtyp']) ? sanitize_text_field($_POST['dbtyp']) : 'x'; if ($typ == 'reset') { adsho_DbUninstall(); adsho_DbInstall(); echo "ereased !"; } else if ($typ == 'export') { adsho_ExportDB(); } else if ($typ == 'import') { adsho_ImportDB(); } wp_die(); } /* Register a custom menu page. */ //================================= add_action('init', 'adsho_Init'); add_action('plugins_loaded', 'adsho_Loaded'); add_action('wp_print_styles', 'adsho_AddStylesheet'); add_action('admin_print_styles', 'adsho_AddStylesheet'); add_action('wp_enqueue_scripts', 'adsho_Scripts' ); add_action('login_enqueue_scripts', 'adsho_Scripts' ); add_action('admin_enqueue_scripts', 'adsho_Scripts' ); add_action( 'wp_ajax_adsho_dbcb', 'adsho_db_callback' ); //add_action('template_redirect','adsho_redirect'); add_action('init','adsho_redirect'); add_filter('widget_text','do_shortcode'); register_deactivation_hook( __FILE__, 'adsho_Deactivation' ); register_uninstall_hook( __FILE__, 'adsho_Uninstall' ); //================================== //is admin checker //================================== function adsho_isAdmin() { $a = in_array('administrator', wp_get_current_user()->roles); return $a; } ?>