function cimy_save_options() { global $wpdb, $cimy_uef_version, $wpdb_wp_fields_table, $max_length_fieldset_value, $cimy_uef_domain, $wp_hidden_fields, $max_length_extra_fields_title; if (!cimy_check_admin('manage_options')) { return; } if (isset($_POST['force_activation'])) { cimy_plugin_install(); return; } if (!check_admin_referer('cimy_uef_options', 'cimy_uef_optionsnonce')) { return; } $results = array(); $do_not_save_options = false; $options = cimy_get_options(); $old_wp_hidden_fields = $options['wp_hidden_fields']; $options['aue_hidden_fields'] = array(); $options['wp_hidden_fields'] = array(); $options['welcome_email'] = stripslashes($_POST['welcome_email']); cimy_wpml_register_string("a_opt_welcome_email", $options['welcome_email']); $options['extra_fields_title'] = stripslashes($_POST['extra_fields_title']); $options['extra_fields_title'] = substr($options['extra_fields_title'], 0, $max_length_extra_fields_title); cimy_wpml_register_string("a_opt_extra_fields_title", $options['extra_fields_title']); $options['fieldset_title'] = stripslashes($_POST['fieldset_title']); $options['fieldset_title'] = substr($options['fieldset_title'], 0, $max_length_fieldset_value); $fieldset_titles = explode(",", $options['fieldset_title']); if (!empty($fieldset_titles)) { foreach ($fieldset_titles as $fset_key => $fieldset) { cimy_wpml_register_string("a_opt_fieldset_title_" . $fset_key, $fieldset); } } $old_reg_log = $options['registration-logo']; $registration_logo = cimy_manage_upload("registration_logo", "", array(), empty($old_reg_log) ? false : basename($old_reg_log), isset($_POST['registration_logo_del']), "registration-logo"); if (!empty($registration_logo) || isset($_POST['registration_logo_del'])) { $options['registration-logo'] = $registration_logo; } if (isset($_POST['db_wp_fields_check'])) { switch ($_POST['db_wp_fields']) { case 'empty': cimy_manage_db('empty_wp_fields'); $results['empty_wp_fields'] = __("WordPress Fields table emptied", $cimy_uef_domain); break; case 'delete': cimy_manage_db('drop_wp_fields'); $results['empty_wp_fields'] = __("WordPress Fields table deleted", $cimy_uef_domain); break; } } if (isset($_POST['db_extra_fields_check'])) { switch ($_POST['db_extra_fields']) { case 'empty': cimy_manage_db('empty_extra_fields'); $results['empty_extra_fields'] = __("Extra Fields table emptied", $cimy_uef_domain); break; case 'delete': cimy_manage_db('drop_extra_fields'); $results['empty_extra_fields'] = __("Extra Fields table deleted", $cimy_uef_domain); break; } } if (isset($_POST['db_data_check'])) { switch ($_POST['db_data']) { case 'empty': cimy_manage_db('empty_data'); $results['empty_data'] = __("Users Data table emptied", $cimy_uef_domain); break; case 'delete': cimy_manage_db('drop_data'); $results['empty_data'] = __("Users Data table deleted", $cimy_uef_domain); break; } } if (isset($_POST['db_options_check'])) { switch ($_POST['db_options']) { case 'default': cimy_manage_db('default_options'); $do_not_save_options = true; $results['results'] = __("Options set to default values", $cimy_uef_domain); break; case 'delete': cimy_manage_db('drop_options'); $do_not_save_options = true; $results['results'] = __("Options deleted", $cimy_uef_domain); break; } } if (isset($_POST['do_not_save_options'])) { $do_not_save_options = true; } if (isset($_POST['hide_username'])) { array_push($options['aue_hidden_fields'], 'username'); } if (isset($_POST['hide_name'])) { array_push($options['aue_hidden_fields'], 'name'); } if (isset($_POST['hide_posts'])) { array_push($options['aue_hidden_fields'], 'posts'); } if (isset($_POST['hide_email'])) { array_push($options['aue_hidden_fields'], 'email'); } if (isset($_POST['hide_website'])) { array_push($options['aue_hidden_fields'], 'website'); } if (isset($_POST['hide_role'])) { array_push($options['aue_hidden_fields'], 'role'); } $tot_wp_hidden_fields = count($old_wp_hidden_fields); $action = "add"; isset($_POST['confirm_email']) ? $options['confirm_email'] = true : ($options['confirm_email'] = false); isset($_POST['confirm_form']) ? $options['confirm_form'] = true : ($options['confirm_form'] = false); if ($options['confirm_email']) { cimy_force_signup_table_creation(); } isset($_POST['redirect_to']) ? $options['redirect_to'] = $_POST['redirect_to'] : ($options['redirect_to'] = ""); isset($_POST['mail_include_fields']) ? $options['mail_include_fields'] = true : ($options['mail_include_fields'] = false); if (isset($_POST['captcha'])) { $options['captcha'] = $_POST['captcha']; } if (isset($_POST['recaptcha_public_key'])) { $options['recaptcha_public_key'] = trim($_POST['recaptcha_public_key']); } if (isset($_POST['recaptcha_private_key'])) { $options['recaptcha_private_key'] = trim($_POST['recaptcha_private_key']); } if (!isset($results['empty_wp_fields'])) { if (isset($_POST['show_wp_password'])) { array_push($options['wp_hidden_fields'], 'password'); if (!in_array("password", $old_wp_hidden_fields)) { $data = $wp_hidden_fields['password']; $data['num_fields'] = $tot_wp_hidden_fields; $tot_wp_hidden_fields++; cimy_save_field($action, $wpdb_wp_fields_table, $data); } if (isset($_POST['show_wp_password2'])) { array_push($options['wp_hidden_fields'], 'password2'); if (!in_array("password2", $old_wp_hidden_fields)) { $data = $wp_hidden_fields['password2']; $data['num_fields'] = $tot_wp_hidden_fields; $tot_wp_hidden_fields++; cimy_save_field($action, $wpdb_wp_fields_table, $data); } } isset($_POST['show_wp_password_meter']) ? $options['password_meter'] = true : ($options['password_meter'] = false); } else { $options['password_meter'] = false; } $db_wp_fields_independent = array("username", "firstname", "lastname", "nickname", "website", "aim", "yahoo", "jgt", "bio-info"); foreach ($db_wp_fields_independent as $wp_field_independent) { if (isset($_POST['show_wp_' . $wp_field_independent])) { array_push($options['wp_hidden_fields'], $wp_field_independent); if (!in_array($wp_field_independent, $old_wp_hidden_fields)) { $data = $wp_hidden_fields[$wp_field_independent]; $data['num_fields'] = $tot_wp_hidden_fields; $tot_wp_hidden_fields++; cimy_save_field($action, $wpdb_wp_fields_table, $data); } } } } $all_wp_fields = get_cimyFields(true); $sql = "DELETE FROM " . $wpdb_wp_fields_table . " WHERE "; $k = -1; $j = -1; $msg = ""; $not_del_old = ""; $not_del_sql = ""; foreach ($all_wp_fields as $wp_field) { $f_name = strtolower($wp_field['NAME']); $f_order = intval($wp_field['F_ORDER']); if (!in_array($f_name, $options['wp_hidden_fields'])) { if (in_array($f_name, $old_wp_hidden_fields)) { if ($k > -1) { $sql .= " OR "; $msg .= ", "; } else { $k = $f_order; $j = $f_order; } $sql .= "F_ORDER=" . $f_order; $msg .= $f_order; } } else { if ($j > -1) { if ($not_del_old != "") { $not_del_old .= ", "; } $not_del_sql .= " WHEN " . $f_order . " THEN " . $j . " "; $not_del_old .= $f_order; $j++; } } } // if at least one field was selected if ($k > -1) { // $sql WILL BE: DELETE FROM <table> WHERE F_ORDER=<value1> [OR F_ORDER=<value2> ...] $wpdb->query($sql); if ($not_del_sql != "") { $not_del_sql = "UPDATE " . $wpdb_wp_fields_table . " SET F_ORDER=CASE F_ORDER" . $not_del_sql . "ELSE F_ORDER END WHERE F_ORDER IN(" . $not_del_old . ")"; // $not_del_sql WILL BE: UPDATE <table> SET F_ORDER=CASE F_ORDER WHEN <oldvalue1> THEN <newvalue1> [WHEN ... THEN ...] ELSE F_ORDER END WHERE F_ORDER IN(<oldvalue1> [, <oldvalue2>...]) $wpdb->query($not_del_sql); } } if (!$do_not_save_options) { cimy_set_options($options); $results['results'] = __("Options changed", $cimy_uef_domain); } return $results; }
function cimy_plugin_install() { // for WP >= 2.5 when adding a global here need to be added also to main global global $wpdb, $old_wpdb_data_table, $wpdb_data_table, $old_wpdb_fields_table, $wpdb_fields_table, $wpdb_wp_fields_table, $cimy_uef_options, $cimy_uef_version, $cuef_upload_path, $cimy_uef_domain; if (!cimy_check_admin('activate_plugins')) { return; } $force_update = false; if (!($options = cimy_get_options())) { cimy_manage_db('new_options'); $options = cimy_get_options(); } else { $force_update = true; } $charset_collate = ""; // try to get proper charset and collate if ($wpdb->has_cap('collation')) { if (!empty($wpdb->charset)) { $charset_collate = " DEFAULT CHARACTER SET {$wpdb->charset}"; } if (!empty($wpdb->collate)) { $charset_collate .= " COLLATE {$wpdb->collate}"; } } if ($force_update) { if (version_compare($options['version'], "0.9.1", "<=") === true) { unset($options['show_buggy_ie_warning']); } if (version_compare($options['version'], "1.0.0-beta1", "<=") === true) { $sql = "RENAME TABLE " . $old_wpdb_fields_table . " TO " . $wpdb_fields_table; $wpdb->query($sql); $sql = "RENAME TABLE " . $old_wpdb_data_table . " TO " . $wpdb_data_table; $wpdb->query($sql); $options['wp_hidden_fields'] = array(); // convert all html entity to normal chars $sql = "SELECT * FROM " . $wpdb_fields_table; $fields = $wpdb->get_results($sql, ARRAY_A); foreach ($fields as $field) { $id = $field['ID']; $name = $wpdb->escape(html_entity_decode($field['NAME'], ENT_QUOTES, "UTF-8")); $label = $wpdb->escape(html_entity_decode($field['LABEL'], ENT_QUOTES, "UTF-8")); $desc = $wpdb->escape(html_entity_decode($field['DESCRIPTION'], ENT_QUOTES, "UTF-8")); $value = $wpdb->escape(html_entity_decode($field['VALUE'], ENT_QUOTES, "UTF-8")); $rules = unserialize($field['RULES']); $rules['equal_to'] = html_entity_decode($rules['equal_to'], ENT_QUOTES, "UTF-8"); $rules = $wpdb->escape(serialize($rules)); $sql = "UPDATE " . $wpdb_fields_table . " SET name='" . $name . "', value='" . $value . "', description='" . $desc . "', label='" . $label . "', rules='" . $rules . "' WHERE ID=" . $id; $wpdb->query($sql); } } if (version_compare($options['version'], "1.1.0-rc1", "<=") === true) { $sql = "SELECT ID FROM " . $wpdb_fields_table . " WHERE TYPE='picture'"; $f_pictures = $wpdb->get_results($sql, ARRAY_A); if (isset($f_pictures)) { if ($f_pictures != NULL) { foreach ($f_pictures as $f_picture) { $sql = "SELECT VALUE FROM " . $wpdb_data_table . " WHERE FIELD_ID=" . $f_picture['ID']; $p_filenames = $wpdb->get_results($sql, ARRAY_A); if (isset($p_filenames)) { if ($p_filenames != NULL) { foreach ($p_filenames as $p_filename) { $path_pieces = explode("/", $p_filename['VALUE']); $p_filename = basename($p_filename['VALUE']); $user_login = array_slice($path_pieces, -2, 1); $p_oldfilename_t = $cuef_upload_path . $user_login[0] . "/" . cimy_get_thumb_path($p_filename, true); $p_newfilename_t = $cuef_upload_path . $user_login[0] . "/" . cimy_get_thumb_path($p_filename, false); if (is_file($p_oldfilename_t)) { rename($p_oldfilename_t, $p_newfilename_t); } } } } } } } } if (version_compare($options['version'], "1.1.0", "<=") === true) { if ($charset_collate != "") { $sql = "ALTER TABLE " . $wpdb_fields_table . $charset_collate; $wpdb->query($sql); $sql = "ALTER TABLE " . $wpdb_wp_fields_table . $charset_collate; $wpdb->query($sql); $sql = "ALTER TABLE " . $wpdb_data_table . $charset_collate; $wpdb->query($sql); } } if (version_compare($options['version'], "1.3.0-beta1", "<=") === true) { $options["users_per_page"] = 50; } if (version_compare($options['version'], "1.3.0-beta2", "<=") === true) { unset($options["disable_cimy_fieldvalue"]); } if (version_compare($options['version'], "1.3.1", "<=") === true) { $options["extra_fields_title"] = __("Extra Fields", $cimy_uef_domain); // Added again since after cleanup DB migration code in v1.3.0-beta2 was buggy! if (isset($options["disable_cimy_fieldvalue"])) { unset($options["disable_cimy_fieldvalue"]); } if (!isset($options["users_per_page"])) { $options["users_per_page"] = 50; } } if (version_compare($options['version'], "1.4.0-beta2", "<=") === true) { unset($options['items_per_fieldset']); $sql = "ALTER TABLE " . $wpdb_fields_table . " ADD COLUMN FIELDSET bigint(20) NOT NULL DEFAULT 0 AFTER F_ORDER"; $wpdb->query($sql); } if (version_compare($options['version'], "1.4.0", "<=") === true) { $sql = "ALTER TABLE " . $wpdb_data_table . " MODIFY COLUMN VALUE LONGTEXT"; $wpdb->query($sql); } // add $rules[show_in_blog]=true and $rules[show_level]=-1 if (version_compare($options['version'], "1.5.0-beta1", "<=") === true) { for ($i = 0; $i <= 1; $i++) { if ($i == 0) { $the_table = $wpdb_wp_fields_table; } else { $the_table = $wpdb_fields_table; } $sql = "SELECT ID, RULES FROM " . $the_table; $all_rules = $wpdb->get_results($sql, ARRAY_A); if (isset($all_rules)) { foreach ($all_rules as $rule) { $rule_to_be_updated = unserialize($rule["RULES"]); $rule_id = $rule["ID"]; // do not add show_level to $wpdb_wp_fields_table if (!isset($rule_to_be_updated["show_level"]) && $i == 1) { $rule_to_be_updated["show_level"] = -1; } if (!isset($rule_to_be_updated["show_in_blog"])) { $rule_to_be_updated["show_in_blog"] = true; } if (!isset($rule_to_be_updated["show_in_search"])) { $rule_to_be_updated["show_in_search"] = true; } $sql = "UPDATE " . $the_table . " SET RULES='" . $wpdb->escape(serialize($rule_to_be_updated)) . "' WHERE ID=" . $rule_id; $wpdb->query($sql); } } } } if (version_compare($options['version'], "2.0.0-beta1", "<=") === true) { if ($options["recaptcha"]) { $options["captcha"] = "recaptcha"; } else { $options["captcha"] = "none"; } unset($options["recaptcha"]); for ($i = 0; $i <= 1; $i++) { if ($i == 0) { $the_table = $wpdb_wp_fields_table; } else { $the_table = $wpdb_fields_table; } $sql = "SELECT ID, RULES FROM " . $the_table; $all_rules = $wpdb->get_results($sql, ARRAY_A); if (isset($all_rules)) { foreach ($all_rules as $rule) { $rule_to_be_updated = unserialize($rule["RULES"]); $rule_id = $rule["ID"]; // stupid bug introduced in v2.0.0-beta1 if (empty($rule_to_be_updated["edit"])) { $rule_to_be_updated["edit"] = "ok_edit"; } $sql = "UPDATE " . $the_table . " SET RULES='" . $wpdb->escape(serialize($rule_to_be_updated)) . "' WHERE ID=" . $rule_id; $wpdb->query($sql); } } } } if (version_compare($options['version'], "2.0.0-beta2", "<=") === true) { $sql = "SELECT DESCRIPTION FROM {$wpdb_wp_fields_table} WHERE NAME='PASSWORD'"; $desc = $wpdb->get_var($sql); if ($desc == __('<strong>Note:</strong> this website let you personalize your password; after the registration you will receive an e-mail with another password, do not care about that!', $cimy_uef_domain)) { $sql = "UPDATE {$wpdb_wp_fields_table} SET DESCRIPTION='' WHERE NAME='PASSWORD'"; $wpdb->query($sql); } } if (version_compare($options['version'], "2.1.0-beta1", "<=") === true) { $welcome_email = sprintf(__('Username: %s'), "USERNAME") . "\r\n"; $welcome_email .= sprintf(__('Password: %s'), "PASSWORD") . "\r\n"; $welcome_email .= "LOGINLINK" . "\r\n"; $options["welcome_email"] = $welcome_email; } if (version_compare($options['version'], "2.2.0", "<=") === true) { $javascripts_dep = array('file_fields' => array('show_in_reg' => 0, 'show_in_profile' => 0, 'show_in_aeu' => 0, 'show_in_blog' => 0, 'show_in_search' => 0), 'image_fields' => array('show_in_reg' => 0, 'show_in_profile' => 0, 'show_in_aeu' => 0, 'show_in_blog' => 0, 'show_in_search' => 0), 'tinymce_fields' => array('show_in_reg' => 0, 'show_in_profile' => 0, 'show_in_aeu' => 0, 'show_in_blog' => 0, 'show_in_search' => 0)); $sql = "SELECT TYPE, RULES FROM " . $wpdb_fields_table; $all_rules = $wpdb->get_results($sql, ARRAY_A); if (isset($all_rules)) { foreach ($all_rules as $rule) { $rules = unserialize($rule["RULES"]); $type = $rule["TYPE"]; $javascripts_dep = cimy_uef_set_javascript_dependencies($javascripts_dep, $type, "show_in_reg", $rules["show_in_reg"]); $javascripts_dep = cimy_uef_set_javascript_dependencies($javascripts_dep, $type, "show_in_profile", $rules["show_in_profile"]); $javascripts_dep = cimy_uef_set_javascript_dependencies($javascripts_dep, $type, "show_in_aeu", $rules["show_in_aeu"]); $javascripts_dep = cimy_uef_set_javascript_dependencies($javascripts_dep, $type, "show_in_blog", $rules["show_in_blog"]); $javascripts_dep = cimy_uef_set_javascript_dependencies($javascripts_dep, $type, "show_in_search", $rules["show_in_search"]); } } $options['file_fields'] = $javascripts_dep['file_fields']; $options['image_fields'] = $javascripts_dep['image_fields']; $options['tinymce_fields'] = $javascripts_dep['tinymce_fields']; } if (version_compare($options['version'], "2.3.11", "<=") === true) { for ($i = 0; $i <= 1; $i++) { if ($i == 0) { $the_table = $wpdb_wp_fields_table; } else { $the_table = $wpdb_fields_table; } $sql = "SELECT ID, RULES FROM " . $the_table; $all_fields = $wpdb->get_results($sql, ARRAY_A); if (!empty($all_fields)) { foreach ($all_fields as $field) { cimy_wpml_register_string($field['NAME'] . "_label", $field['LABEL']); cimy_wpml_register_string($field['NAME'] . "_desc", $field['DESCRIPTION']); } } } } if (version_compare($options['version'], "2.4.0", "<=") === true) { cimy_wpml_register_string("a_opt_welcome_email", $options['welcome_email']); cimy_wpml_register_string("a_opt_extra_fields_title", $options['extra_fields_title']); $fieldset_titles = explode(",", $options['fieldset_title']); if (!empty($fieldset_titles)) { foreach ($fieldset_titles as $fset_key => $fieldset) { cimy_wpml_register_string("a_opt_fieldset_title_" . $fset_key, $fieldset); } } } if (version_compare($options['version'], "2.4.2", "<=") === true) { $options["wp_hidden_fields"][] = "username"; } $options['version'] = $cimy_uef_version; cimy_set_options($options); } if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb_wp_fields_table}'") != $wpdb_wp_fields_table) { $sql = "CREATE TABLE " . $wpdb_wp_fields_table . " (ID bigint(20) NOT NULL AUTO_INCREMENT, F_ORDER bigint(20) NOT NULL, NAME varchar(20), LABEL TEXT, DESCRIPTION TEXT, TYPE varchar(20), RULES TEXT, VALUE TEXT, PRIMARY KEY (ID), INDEX F_ORDER (F_ORDER), INDEX NAME (NAME))" . $charset_collate . ";"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); } if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb_data_table}'") != $wpdb_data_table) { $sql = "CREATE TABLE " . $wpdb_data_table . " (ID bigint(20) NOT NULL AUTO_INCREMENT, USER_ID bigint(20) NOT NULL, FIELD_ID bigint(20) NOT NULL, VALUE TEXT NOT NULL, PRIMARY KEY (ID), INDEX USER_ID (USER_ID), INDEX FIELD_ID (FIELD_ID))" . $charset_collate . ";"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); } if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb_fields_table}'") != $wpdb_fields_table) { $sql = "CREATE TABLE " . $wpdb_fields_table . " (ID bigint(20) NOT NULL AUTO_INCREMENT, F_ORDER bigint(20) NOT NULL, FIELDSET bigint(20) NOT NULL DEFAULT 0, NAME varchar(20), LABEL TEXT, DESCRIPTION TEXT, TYPE varchar(20), RULES TEXT, VALUE TEXT, PRIMARY KEY (ID), INDEX F_ORDER (F_ORDER), INDEX NAME (NAME))" . $charset_collate . ";"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); } return $options; }