function check_charset()
{
    global $maxbuttons_installed_version;
    global $wpdb;
    $check = "SHOW FULL COLUMNS FROM " . maxButtonsUtils::get_buttons_table_name();
    $charset = $wpdb->query($check);
    return $charset;
}
Exemple #2
0
 function getButtonCount($args = array())
 {
     $defaults = array("status" => "publish");
     $args = wp_parse_args($args, $defaults);
     $sql = "SELECT count(id) FROM " . maxButtonsUtils::get_buttons_table_name() . " WHERE status = '%s'";
     $sql = $this->wpdb->prepare($sql, $args["status"]);
     $result = $this->wpdb->get_var($sql);
     return $result;
 }
 public function check_database($blocks)
 {
     maxButtonsUtils::addTime("Check database");
     $sql = "SELECT id,name,status,cache";
     foreach ($blocks as $block => $class) {
         $sql .= ", {$block}";
     }
     $sql .= " from " . maxButtonsUtils::get_buttons_table_name() . " limit 1";
     global $wpdb;
     $wpdb->hide_errors();
     $result = $wpdb->get_results($sql);
     // check this query for errors. If there is an error, one or more database fields are missing. Fix that.
     if (isset($wpdb->last_error) && $wpdb->last_error != '') {
         //echo $wpdb->last_error;  echo "ERREUR!";
         $install = $this->getClass("install");
         $install::create_database_table();
         $install::migrate();
     }
     maxButtonsUtils::addTime("End check database");
 }
<?php

/*if(is_admin()) {
    wp_enqueue_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css', '', '4.0.1', false);
} */
if (isset($_POST['alter_charset'])) {
    global $maxbuttons_installed_version;
    global $wpdb;
    $table_name = maxButtonsUtils::get_buttons_table_name();
    $sql = "ALTER TABLE " . $table_name . " CONVERT TO CHARACTER SET utf8";
    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    $wpdb->query($sql);
    $response = 'CHARSET now utf_8 COLLATE utf8_general_ci';
} else {
    $response = '';
}
if (isset($_POST["reset_cache"])) {
    $button = new maxButton();
    $button->reset_cache();
}
if (isset($_POST["remigrate"])) {
    $install = MB()->getClass("install");
    $install::create_database_table();
    $install::migrate();
}
?>

<div id="maxbuttons">
	<div class="wrap">
 
		
Exemple #5
0
 static function create_database_table()
 {
     //global $maxbuttons_installed_version;
     $table_name = maxButtonsUtils::get_buttons_table_name();
     $button = new maxButton();
     $blocks = $button->getDefinedBlocks();
     // IMPORTANT: There MUST be two spaces between the PRIMARY KEY keywords
     // and the column name, and the column name MUST be in parenthesis.
     $sql = "CREATE TABLE " . $table_name . " ( \n\t\t\t\t\tid int NOT NULL AUTO_INCREMENT, \n\t\t\t\t\t name varchar(100) NULL, \n\t\t\t\t\t status varchar(10) default 'publish' NOT NULL, \n\t\t\t\t\t cache text, \n\t\t\t\t";
     foreach ($blocks as $block) {
         $sql .= "" . $block . " TEXT NULL, \n ";
     }
     $sql .= " PRIMARY KEY  (id) )";
     if (!static::maxbuttons_database_table_exists($table_name)) {
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         dbDelta($sql);
     }
     if (static::maxbuttons_database_table_exists($table_name) && (get_option(MAXBUTTONS_VERSION_KEY) != MAXBUTTONS_VERSION_NUM || get_option(MAXBUTTONS_VERSION_KEY) == '')) {
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         dbDelta($sql);
     }
     // Reset the cache if there were any left from before
     $button->reset_cache();
     // Collection table
     $collection_table_name = maxButtonsUtils::get_collection_table_name();
     $sql = "CREATE TABLE " . $collection_table_name . " ( \n\t\t\t\t\tmeta_id int NOT NULL AUTO_INCREMENT, \n\t\t\t\t\tcollection_id int NOT NULL, \n\t\t\t\t\tcollection_key varchar(255), \n\t\t\t\t\tcollection_value text, \n\t\t\t\t\tPRIMARY KEY(meta_id) ) \n\t\t\t\t\t\n\t\t\t\t";
     dbDelta($sql);
     //else exit( __("Something went wrong when creating database table", "maxbuttons") );
 }
Exemple #6
0
 public function reset_cache()
 {
     $fields = array("cache" => null);
     $where = array(1 => 1);
     //$where_format = array('%d');
     $sql = "UPDATE " . maxButtonsUtils::get_buttons_table_name() . " SET cache = NULL ";
     $this->wpdb->query($sql);
 }
Exemple #7
0
 public function update($data)
 {
     $return = false;
     $fields = array();
     foreach ($this->blocks as $block) {
         $blockData = $data[$block];
         $fields[$block] = serialize($blockData);
     }
     if (isset($data["name"])) {
         // other fields.
         $fields["name"] = $data["name"];
     }
     if (isset($data["status"])) {
         $fields["status"] = $data["status"];
     }
     $where = array('id' => $this->id);
     if ($this->id > 0) {
         $where = array('id' => $this->id);
         $where_format = array('%d');
         $this->wpdb->update(maxButtonsUtils::get_buttons_table_name(), $fields, $where, null, $where_format);
         $return = true;
     } else {
         $this->wpdb->insert(maxButtonsUtils::get_buttons_table_name(), $fields);
         $id = $this->wpdb->insert_id;
         $return = $id;
     }
     return $return;
 }
Exemple #8
0
 static function create_database_table()
 {
     //global $maxbuttons_installed_version;
     $table_name = maxButtonsUtils::get_buttons_table_name();
     $button = new maxButton();
     $blocks = $button->getDefinedBlocks();
     // IMPORTANT: There MUST be two spaces between the PRIMARY KEY keywords
     // and the column name, and the column name MUST be in parenthesis.
     $sql = "CREATE TABLE " . $table_name . " ( \n\t\t\t\t\tid int NOT NULL AUTO_INCREMENT, \n\t\t\t\t\t name varchar(100) NULL, \n\t\t\t\t\t status varchar(10) default 'publish' NOT NULL, \n\t\t\t\t";
     /*	name VARCHAR(100) NULL,
     					description VARCHAR(500) NULL,
     					url VARCHAR(250) NULL,
     					text VARCHAR(100) NULL,
     					text_font_family VARCHAR(50) NULL,
     					text_font_size VARCHAR(10) NULL,
     					text_font_style VARCHAR(10) NULL,
     					text_font_weight VARCHAR(10) NULL,
     					text_color VARCHAR(10) NULL,
     					text_color_hover VARCHAR(10) NULL,
     					text_shadow_offset_left VARCHAR(10) NULL,
     					text_shadow_offset_top VARCHAR(10) NULL,
     					text_shadow_width VARCHAR(10) NULL,
     					text_shadow_color VARCHAR(10) NULL,
     					text_shadow_color_hover VARCHAR(10) NULL,
     					text_padding_top VARCHAR(10) NULL,
     					text_padding_bottom VARCHAR(10) NULL,
     					text_padding_left VARCHAR(10) NULL,
     					text_padding_right VARCHAR(10) NULL,
     					border_radius_top_left VARCHAR(10) NULL,
     					border_radius_top_right VARCHAR(10) NULL,
     					border_radius_bottom_left VARCHAR(10) NULL,
     					border_radius_bottom_right VARCHAR(10) NULL,
     					border_style VARCHAR(10) NULL,
     					border_width VARCHAR(10) NULL,
     					border_color VARCHAR(10) NULL,
     					border_color_hover VARCHAR(10) NULL,
     					box_shadow_offset_left VARCHAR(10) NULL,
     					box_shadow_offset_top VARCHAR(10) NULL,
     					box_shadow_width VARCHAR(10) NULL,
     					box_shadow_color VARCHAR(10) NULL,
     					box_shadow_color_hover VARCHAR(10) NULL,
     					gradient_start_color VARCHAR(10) NULL,
     					gradient_start_color_hover VARCHAR(10) NULL,
     					gradient_end_color VARCHAR(10) NULL,
     					gradient_end_color_hover VARCHAR(10) NULL,
     					gradient_stop VARCHAR(2) NULL,
     					gradient_start_opacity VARCHAR(3) NULL,
     					gradient_end_opacity VARCHAR(3) NULL,
     					gradient_start_opacity_hover VARCHAR(3),
     					gradient_end_opacity_hover VARCHAR(3),
     					new_window VARCHAR(10) NULL,
     					container_enabled VARCHAR(5) NULL,
     					container_width VARCHAR(7) NULL,
     					container_margin_top VARCHAR(7) NULL,
     					container_margin_right VARCHAR(7) NULL,
     					container_margin_bottom VARCHAR(7) NULL,
     					container_margin_left VARCHAR(7) NULL,
     					container_alignment VARCHAR(25) NULL,
     					container_center_div_wrap_enabled VARCHAR(5) NULL,
     					nofollow VARCHAR(5) NULL,
     					status VARCHAR(10) DEFAULT 'publish' NOT NULL,
     					external_css VARCHAR(5) NULL,
     					important_css VARCHAR(5) NULL, 
     			);"; */
     foreach ($blocks as $block) {
         $sql .= "" . $block . " TEXT NULL, \n ";
     }
     $sql .= " PRIMARY KEY  (id) )";
     if (!static::maxbuttons_database_table_exists($table_name)) {
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         dbDelta($sql);
     }
     if (static::maxbuttons_database_table_exists($table_name) && (get_option(MAXBUTTONS_VERSION_KEY) != MAXBUTTONS_VERSION_NUM || get_option(MAXBUTTONS_VERSION_KEY) == '')) {
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         dbDelta($sql);
     }
     //else exit( __("Something went wrong when creating database table", "maxbuttons") );
 }