function cimy_manage_upload($input_name, $user_login, $rules, $old_file = false, $delete_file = false, $type = "", $new_filename = "")
{
    global $cuef_upload_path, $cuef_upload_webpath, $cuef_plugin_dir, $cimy_uef_plugins_dir;
    $type_path = "";
    if ($type == "file" || $type == "avatar") {
        $type_path .= $type . "/";
    }
    $blog_path = $cuef_upload_path;
    if ($cimy_uef_plugins_dir == "plugins" && is_multisite()) {
        global $blog_id;
        $blog_path .= $blog_id . "/";
        // create blog subdir
        if (!is_dir($blog_path)) {
            if (defined("FS_CHMOD_DIR")) {
                mkdir($blog_path, FS_CHMOD_DIR);
                chmod($blog_path, FS_CHMOD_DIR);
            } else {
                mkdir($blog_path, 0777);
                chmod($blog_path, 0777);
            }
        }
    }
    if (!empty($user_login)) {
        $user_path = $blog_path . $user_login . "/";
        $file_path = $blog_path . $user_login . "/" . $type_path;
    } else {
        $user_path = $blog_path;
        $file_path = $blog_path . $type_path;
    }
    if (!empty($new_filename)) {
        $file_name = $new_filename;
    } else {
        $file_name = $_FILES[$input_name]['name'];
    }
    // protect from site traversing
    $file_name = str_replace('../', '', $file_name);
    $file_name = str_replace('/', '', $file_name);
    // delete old file if requested
    if ($delete_file) {
        if (is_file($file_path . $old_file)) {
            unlink($file_path . $old_file);
        }
        $old_thumb_file = cimy_get_thumb_path($old_file);
        if (is_file($file_path . $old_thumb_file)) {
            unlink($file_path . $old_thumb_file);
        }
    }
    // if $user_login is not present
    //	or there is no file to upload
    //	or dest dir is not writable
    // then everything else is useless
    if ($user_login == "" && $type != "registration-logo" || !isset($_FILES[$input_name]['name']) || !is_writable($cuef_upload_path)) {
        return "";
    }
    // create user subdir
    if (!is_dir($user_path)) {
        if (defined("FS_CHMOD_DIR")) {
            mkdir($user_path, FS_CHMOD_DIR);
            chmod($user_path, FS_CHMOD_DIR);
        } else {
            mkdir($user_path, 0777);
            chmod($user_path, 0777);
        }
    }
    // create avatar subdir if needed
    if ($type != "registration-logo" && $type != "picture" && !is_dir($file_path)) {
        if (defined("FS_CHMOD_DIR")) {
            mkdir($file_path, FS_CHMOD_DIR);
            chmod($file_path, FS_CHMOD_DIR);
        } else {
            mkdir($file_path, 0777);
            chmod($file_path, 0777);
        }
    }
    // picture filesystem path
    $file_full_path = $file_path . $file_name;
    // picture url to write in the DB
    $data = $cuef_upload_webpath;
    if ($cimy_uef_plugins_dir == "plugins" && is_multisite()) {
        $data .= $blog_id . "/";
    }
    if (empty($user_login)) {
        $data .= $type_path . $file_name;
    } else {
        $data .= $user_login . "/" . $type_path . $file_name;
    }
    // filesize in Byte transformed in KiloByte
    $file_size = $_FILES[$input_name]['size'] / 1024;
    $file_type = $_FILES[$input_name]['type'];
    $file_tmp_name = $_FILES[$input_name]['tmp_name'];
    $file_error = $_FILES[$input_name]['error'];
    // CHECK IF IT IS A REAL PICTURE
    if ($type != "file" && stristr($file_type, "image/") === false) {
        $file_error = 1;
    }
    // MIN LENGTH
    if (isset($rules['min_length'])) {
        if ($file_size < intval($rules['min_length'])) {
            $file_error = 1;
        }
    }
    // EXACT LENGTH
    if (isset($rules['exact_length'])) {
        if ($file_size != intval($rules['exact_length'])) {
            $file_error = 1;
        }
    }
    // MAX LENGTH
    if (isset($rules['max_length'])) {
        if ($file_size > intval($rules['max_length'])) {
            $file_error = 1;
        }
    }
    // if there are no errors and filename is NOT empty
    if ($file_error == 0 && !empty($file_name)) {
        if (move_uploaded_file($file_tmp_name, $file_full_path)) {
            // change file permissions for broken servers
            if (defined("FS_CHMOD_FILE")) {
                @chmod($file_full_path, FS_CHMOD_FILE);
            } else {
                @chmod($file_full_path, 0644);
            }
            // if there is an old file to delete
            if ($old_file) {
                // delete old file if the name is different, if equal NOPE because new file is already uploaded
                if ($file_name != $old_file) {
                    if (is_file($file_path . $old_file)) {
                        unlink($file_path . $old_file);
                    }
                }
                $old_thumb_file = cimy_get_thumb_path($old_file);
                if (is_file($file_path . $old_thumb_file)) {
                    unlink($file_path . $old_thumb_file);
                }
            }
            // should be stay AFTER DELETIONS
            if (isset($rules['equal_to']) && $type != "file") {
                if ($maxside = intval($rules['equal_to'])) {
                    if (!function_exists("image_resize")) {
                        require_once ABSPATH . 'wp-includes/media.php';
                    }
                    if (!function_exists("wp_load_image")) {
                        require_once $cuef_plugin_dir . '/cimy_uef_missing_functions.php';
                    }
                    image_resize($file_full_path, $maxside, $maxside, false, "thumbnail");
                }
            }
        } else {
            $data = "";
        }
    } else {
        $data = "";
    }
    return $data;
}
Exemple #2
0
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');
    } else {
        $force_update = true;
    }
    $charset_collate = "";
    // try to get proper charset and collate
    if ($wpdb->supports_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);
            }
        }
        $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/upgrade-functions.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/upgrade-functions.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/upgrade-functions.php';
        dbDelta($sql);
    }
}
Exemple #3
0
function cimy_extract_ExtraFields()
{
    global $wpdb, $user_ID, $wpdb_data_table, $start_cimy_uef_comment, $end_cimy_uef_comment, $rule_profile_value, $cimy_uef_options, $rule_maxlen_needed, $fields_name_prefix, $cuef_upload_path, $cimy_uef_domain, $cuef_plugin_dir, $cimy_uef_file_types, $cimy_uef_textarea_types, $user_level;
    // if editing a different user (only admin)
    if (isset($_GET['user_id'])) {
        $get_user_id = $_GET['user_id'];
        if (!current_user_can('edit_user', $get_user_id)) {
            return;
        }
    } else {
        if (isset($_POST['user_id'])) {
            $get_user_id = $_POST['user_id'];
            if (!current_user_can('edit_user', $get_user_id)) {
                return;
            }
        } else {
            if (!isset($user_ID)) {
                return;
            }
            $get_user_id = $user_ID;
        }
    }
    $get_user_id = intval($get_user_id);
    $options = cimy_get_options();
    $extra_fields = get_cimyFields(false, true);
    if (cimy_uef_is_multisite_per_blog_installation()) {
        echo "<input type=\"hidden\" name=\"from_blog_id\" value=\"" . strval(get_current_blog_id()) . "\" />\n";
    }
    if (!empty($extra_fields)) {
        $upload_image_function = false;
        echo $start_cimy_uef_comment;
        if ($options['extra_fields_title'] != "") {
            echo "<br clear=\"all\" />\n";
            echo "<h2>" . esc_html(cimy_wpml_translate_string("a_opt_extra_fields_title", $options['extra_fields_title'])) . "</h2>\n";
        }
        foreach ($extra_fields as $thisField) {
            $field_id = $thisField['ID'];
            cimy_insert_ExtraFields_if_not_exist($get_user_id, $field_id);
        }
        // 		$ef_db = $wpdb->get_results("SELECT FIELD_ID, VALUE FROM ".$wpdb_data_table." WHERE USER_ID = ".$get_user_id, ARRAY_A);
        $radio_checked = array();
        $current_fieldset = -1;
        $tiny_mce_objects = "";
        if (!empty($options['fieldset_title'])) {
            $fieldset_titles = explode(',', $options['fieldset_title']);
        } else {
            $fieldset_titles = array();
        }
        $close_table = false;
        echo '<table class="form-table">';
        echo "\n";
        foreach ($extra_fields as $thisField) {
            $value = "";
            $old_value = "";
            $field_id = $thisField['ID'];
            $name = $thisField['NAME'];
            $rules = $thisField['RULES'];
            $type = $thisField['TYPE'];
            $label = cimy_wpml_translate_string($name . "_label", $thisField["LABEL"]);
            $description = cimy_uef_sanitize_content(cimy_wpml_translate_string($name . "_desc", $thisField["DESCRIPTION"]));
            $fieldset = $thisField['FIELDSET'];
            $unique_id = $fields_name_prefix . $field_id;
            $input_name = $fields_name_prefix . esc_attr($name);
            $field_id_data = $input_name . "_" . $field_id . "_data";
            $advanced_options = cimy_uef_parse_advanced_options($rules["advanced_options"]);
            // if the current user LOGGED IN has not enough permissions to see the field, skip it
            // apply only for EXTRA FIELDS
            if ($rules['show_level'] == 'view_cimy_extra_fields') {
                if (!current_user_can($rules['show_level'])) {
                    continue;
                }
            } else {
                if ($user_level < $rules['show_level']) {
                    continue;
                }
            }
            // if show_level == anonymous then do NOT ovverride other show_xyz rules
            if ($rules['show_level'] == -1) {
                // if flag to show the field in the profile is NOT activated, skip it
                if (!$rules['show_in_profile']) {
                    continue;
                }
            }
            // 			foreach ($ef_db as $d_field) {
            // 				if ($d_field['FIELD_ID'] == $field_id)
            // 					$value = $d_field['VALUE'];
            // 			}
            $value = $wpdb->get_var($wpdb->prepare("SELECT VALUE FROM " . $wpdb_data_table . " WHERE USER_ID=%d AND FIELD_ID=%d", $get_user_id, $field_id));
            $old_value = $value;
            if ($type == "radio" && empty($radio_checked[$name])) {
                $radio_checked[$name] = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM " . $wpdb_data_table . " WHERE USER_ID=%d AND FIELD_ID=%d AND VALUE=\"selected\"", $get_user_id, $field_id));
            }
            // if nothing is inserted and field admin default value then assign it
            if (in_array($type, $rule_profile_value)) {
                if (empty($value)) {
                    $value = $thisField['VALUE'];
                }
            }
            if ($fieldset > $current_fieldset && isset($fieldset_titles[$fieldset])) {
                $current_fieldset = $fieldset;
                // do not close the table if it is the first iteration
                if ($close_table) {
                    echo "</table>\n";
                } else {
                    $close_table = true;
                }
                if (isset($fieldset_titles[$current_fieldset])) {
                    echo "\n\t<h3>" . esc_html(cimy_wpml_translate_string("a_opt_fieldset_title_" . $current_fieldset, $fieldset_titles[$current_fieldset])) . "</h3>\n";
                }
                echo '<table class="form-table">';
                echo "\n";
            }
            echo "\t";
            echo "<tr>";
            echo "\n\t";
            // if you use it you need to escape it!
            $non_escaped_value = $value;
            $value = esc_attr($value);
            $old_value = esc_attr($old_value);
            $obj_class = '';
            if ($rules['can_be_empty']) {
                $required = '';
            } else {
                $required = ' <span class="description">' . __("(required)") . '</span>';
            }
            switch ($type) {
                case "picture-url":
                case "password":
                case "text":
                    $obj_label = '<label for="' . $unique_id . '">' . cimy_uef_sanitize_content($label) . $required . '</label>';
                    $obj_name = ' name="' . $input_name . '"';
                    if ($type == "picture-url") {
                        $obj_type = ' type="text"';
                    } else {
                        $obj_type = ' type="' . $type . '"';
                    }
                    $obj_value = ' value="' . $value . '"';
                    $obj_value2 = "";
                    $obj_checked = "";
                    $obj_tag = "input";
                    $obj_closing_tag = false;
                    $obj_style = ' class="regular-text"';
                    if (cimy_uef_is_field_disabled($type, $rules['edit'], $old_value)) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    break;
                case "textarea":
                    $obj_label = '<label for="' . $unique_id . '">' . cimy_uef_sanitize_content($label) . $required . '</label>';
                    $obj_name = ' name="' . $input_name . '"';
                    $obj_type = "";
                    $obj_value = "";
                    $obj_value2 = $value;
                    $obj_checked = "";
                    $obj_tag = "textarea";
                    $obj_closing_tag = true;
                    $obj_style = "";
                    $obj_class = ' class="cimy_uef_textarea"';
                    if (cimy_uef_is_field_disabled($type, $rules['edit'], $old_value)) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    break;
                case "textarea-rich":
                    if ($tiny_mce_objects == "") {
                        $tiny_mce_objects = $unique_id;
                    } else {
                        $tiny_mce_objects .= "," . $unique_id;
                    }
                    $obj_label = '<label for="' . $unique_id . '">' . cimy_uef_sanitize_content($label) . $required . '</label>';
                    $obj_name = ' name="' . $input_name . '"';
                    $obj_type = "";
                    $obj_value = "";
                    $obj_value2 = $value;
                    $obj_checked = "";
                    $obj_tag = "textarea";
                    $obj_closing_tag = true;
                    $obj_style = "";
                    $obj_class = ' class="cimy_uef_textarea"';
                    if (cimy_uef_is_field_disabled($type, $rules['edit'], $old_value)) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    break;
                case "dropdown-multi":
                case "dropdown":
                    // cimy_dropDownOptions uses cimy_uef_sanitize_content and esc_attr by itself
                    $ret = cimy_dropDownOptions($label, $non_escaped_value);
                    $label = $ret['label'];
                    $html = $ret['html'];
                    $obj_label = '<label for="' . $unique_id . '">' . $label . $required . '</label>';
                    if ($type == "dropdown-multi") {
                        $obj_name = ' name="' . $input_name . '[]" multiple="multiple" size="5"';
                        $obj_style = ' style="height: 11em;"';
                    } else {
                        $obj_name = ' name="' . $input_name . '"';
                        $obj_style = '';
                    }
                    $obj_type = '';
                    $obj_value = '';
                    $obj_value2 = $html;
                    $obj_checked = "";
                    $obj_tag = "select";
                    $obj_closing_tag = true;
                    if (cimy_uef_is_field_disabled($type, $rules['edit'], $old_value)) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    break;
                case "checkbox":
                    $obj_label = '<label for="' . $unique_id . '">' . cimy_uef_sanitize_content($label) . '</label>';
                    $obj_name = ' name="' . $input_name . '"';
                    $obj_type = ' type="' . $type . '"';
                    $obj_value = ' value="1"';
                    $obj_value2 = "";
                    $value == "YES" ? $obj_checked = ' checked="checked"' : ($obj_checked = '');
                    $obj_tag = "input";
                    $obj_closing_tag = false;
                    $obj_style = ' style="width:auto; border:0; background:white;"';
                    if (cimy_uef_is_field_disabled($type, $rules['edit'], $old_value)) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    break;
                case "radio":
                    $obj_label = '<label for="' . $unique_id . '"> ' . cimy_uef_sanitize_content($label) . '</label>';
                    $obj_name = ' name="' . $input_name . '"';
                    $obj_type = ' type="' . $type . '"';
                    $obj_value = ' value="' . $field_id . '"';
                    $obj_value2 = "";
                    $obj_tag = "input";
                    $obj_closing_tag = false;
                    $obj_style = ' style="width:auto; border:0; background:white;"';
                    if (cimy_uef_is_field_disabled($type, $rules['edit'], $old_value)) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    if ($value == "selected" || $value == "YES" && $radio_checked[$name] == 0) {
                        $radio_checked[$name] = 1;
                        $obj_checked = ' checked="checked"';
                    } else {
                        $obj_checked = '';
                    }
                    break;
                case "avatar":
                case "picture":
                case "file":
                    $allowed_exts = '';
                    if (isset($rules['equal_to'])) {
                        if (!empty($rules['equal_to'])) {
                            $allowed_exts = "'" . implode("', '", explode(",", $rules['equal_to'])) . "'";
                        }
                    }
                    $obj_label = '<label for="' . $unique_id . '">' . cimy_uef_sanitize_content($label) . $required . '</label>';
                    $obj_class = '';
                    $obj_name = ' name="' . $input_name . '"';
                    $obj_type = ' type="file"';
                    $obj_value = ' value=""';
                    $obj_value2 = '';
                    $obj_checked = "";
                    $obj_tag = "input";
                    $obj_closing_tag = false;
                    if ($type == "file") {
                        // if we do not escape then some translations can break
                        $warning_msg = $wpdb->escape(__("Please upload a file with one of the following extensions", $cimy_uef_domain));
                        $obj_style = ' onchange="uploadFile(\'your-profile\', \'' . $unique_id . '\', \'' . $warning_msg . '\', Array(' . $allowed_exts . '));"';
                    } else {
                        // if we do not escape then some translations can break
                        $warning_msg = $wpdb->escape(__("Please upload an image with one of the following extensions", $cimy_uef_domain));
                        $allowed_exts = "'" . implode("','", cimy_uef_get_allowed_image_extensions()) . "'";
                        $obj_style = ' onchange="uploadFile(\'your-profile\', \'' . $unique_id . '\', \'' . $warning_msg . '\', Array(' . $allowed_exts . '));"';
                    }
                    if (cimy_uef_is_field_disabled($type, $rules['edit'], $old_value)) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    break;
                case "registration-date":
                    $value = cimy_get_registration_date($get_user_id, $value);
                    if (isset($rules['equal_to'])) {
                        $obj_value = cimy_get_formatted_date($value, $rules['equal_to']);
                    } else {
                        $obj_value = cimy_get_formatted_date($value);
                    }
                    $obj_label = '<label>' . cimy_uef_sanitize_content($label) . '</label>';
                    break;
            }
            $obj_id = ' id="' . $unique_id . '"';
            $obj_maxlen = "";
            if (in_array($type, $rule_maxlen_needed) && !in_array($type, $cimy_uef_file_types)) {
                if (isset($rules['max_length'])) {
                    $obj_maxlen = ' maxlength="' . $rules['max_length'] . '"';
                } else {
                    if (isset($rules['exact_length'])) {
                        $obj_maxlen = ' maxlength="' . $rules['exact_length'] . '"';
                    }
                }
            }
            if (in_array($type, $cimy_uef_textarea_types)) {
                $obj_rowscols = ' rows="3" cols="25"';
            } else {
                $obj_rowscols = '';
            }
            echo "\t";
            $form_object = '<' . $obj_tag . $obj_id . $obj_class . $obj_name . $obj_type . $obj_value . $obj_checked . $obj_maxlen . $obj_rowscols . $obj_style . $obj_disabled;
            if ($obj_closing_tag) {
                $form_object .= ">" . $obj_value2 . "</" . $obj_tag . ">";
            } else {
                $form_object .= " />";
            }
            echo "<th>";
            echo $obj_label;
            echo "</th>\n";
            echo "\t\t<td>";
            if (!empty($description) && ($type == "picture" || $type == "picture-url")) {
                echo "<span class='description'>" . $description . "</span><br />";
            }
            if (in_array($type, $cimy_uef_file_types)) {
                $profileuser = get_user_to_edit($get_user_id);
            }
            if ($type == "avatar") {
                $user_email = $profileuser->user_email;
                $img_avatar = get_avatar($user_email, $size = '128');
                $img_avatar = str_replace("<img", "<img id='{$field_id_data}'", $img_avatar);
                echo '<div id="profpic">' . $img_avatar . "</div>\n\t\t";
            }
            if (in_array($type, $cimy_uef_file_types) && !empty($value)) {
                $old_value = basename($old_value);
                $user_login = $profileuser->user_login;
                if ($type == "picture") {
                    $value_thumb = cimy_get_thumb_path($value);
                    $file_on_server = cimy_uef_get_dir_or_filename($user_login, $value, false);
                    $file_thumb = cimy_uef_get_dir_or_filename($user_login, $value, true);
                    if (!empty($advanced_options["no-thumb"]) && is_file($file_thumb)) {
                        rename($file_thumb, $file_on_server);
                    }
                    echo "\n\t\t";
                    if (is_file($file_thumb)) {
                        echo '<a target="_blank" href="' . $value . '"><img id="' . $field_id_data . '" src="' . $value_thumb . '" alt="picture" /></a><br />';
                        echo "\n\t\t";
                    } else {
                        if (is_file($file_on_server)) {
                            echo '<img id="' . $field_id_data . '" src="' . $value . '" alt="picture" /><br />';
                            echo "\n\t\t";
                        }
                    }
                }
                if ($type == "file") {
                    echo '<a target="_blank" href="' . $value . '">';
                    echo basename($value);
                    echo '</a><br />';
                    echo "\n\t\t";
                }
                // if there is no image or there is the default one then disable delete button
                if (empty($old_value)) {
                    $dis_delete_img = ' disabled="disabled"';
                } else {
                    // take the "can be modified" rule just set before
                    $dis_delete_img = $obj_disabled;
                    // 					echo '<input type="hidden" name="'.$input_name.'_oldfile" value="'.basename($value).'" />';
                    // 					echo "\n\t\t";
                }
                if (($type == "picture" || $type == "avatar") && (empty($rules["equal_to"]) || !empty($advanced_options["no-thumb"]))) {
                    echo "<input type=\"hidden\" name=\"" . $field_id_data . "_x1\" id=\"" . $field_id_data . "_x1\" value=\"\" />";
                    echo "<input type=\"hidden\" name=\"" . $field_id_data . "_y1\" id=\"" . $field_id_data . "_y1\" value=\"\" />";
                    echo "<input type=\"hidden\" name=\"" . $field_id_data . "_x2\" id=\"" . $field_id_data . "_x2\" value=\"\" />";
                    echo "<input type=\"hidden\" name=\"" . $field_id_data . "_y2\" id=\"" . $field_id_data . "_y2\" value=\"\" />";
                    echo "<input type=\"hidden\" name=\"" . $field_id_data . "_w\" id=\"" . $field_id_data . "_w\" value=\"\" />";
                    echo "<input type=\"hidden\" name=\"" . $field_id_data . "_h\" id=\"" . $field_id_data . "_h\" value=\"\" />";
                    // 					echo "<p class=\"submit\"><input type=\"submit\" name=\"".$field_id_data."_button\" class=\"button-primary\" value=\"".__("Edit Image")."\"  /></p>";
                    echo "<input type=\"hidden\" name=\"" . $field_id_data . "_button\" id=\"" . $field_id_data . "_button\" value=\"1\" />";
                    $imgarea_options = "handles: true, fadeSpeed: 200, onSelectChange: preview";
                    if (isset($advanced_options["crop_x1"]) && isset($advanced_options["crop_y1"]) && isset($advanced_options["crop_x2"]) && isset($advanced_options["crop_y2"])) {
                        $imgarea_options .= ", x1: " . intval($advanced_options["crop_x1"]);
                        $imgarea_options .= ", y1: " . intval($advanced_options["crop_y1"]);
                        $imgarea_options .= ", x2: " . intval($advanced_options["crop_x2"]);
                        $imgarea_options .= ", y2: " . intval($advanced_options["crop_y2"]);
                    }
                    if (!empty($advanced_options["crop_ratio"])) {
                        $imgarea_options .= ", aspectRatio: '" . esc_js($advanced_options["crop_ratio"]) . "'";
                    } else {
                        if ($type == "avatar") {
                            $imgarea_options .= ", aspectRatio: '1:1'";
                        }
                    }
                    echo "<script type='text/javascript'>jQuery(document).ready(function () { jQuery('#" . esc_js($field_id_data) . "').imgAreaSelect({ " . $imgarea_options . " }); });</script>";
                }
                echo '<input type="checkbox" name="' . $input_name . '_del" value="1" style="width:auto; border:0; background:white;"' . $dis_delete_img . ' />';
                if ($type == "file") {
                    echo " " . __("Delete the file", $cimy_uef_domain) . "<br /><br />";
                    echo "\n\t\t" . __("Update the file", $cimy_uef_domain) . "<br />";
                } else {
                    echo " " . __("Delete the picture", $cimy_uef_domain) . "<br /><br />";
                    echo "\n\t\t" . __("Update the picture", $cimy_uef_domain) . "<br />";
                }
                echo "\n\t\t";
            }
            if ($type == "picture-url") {
                if (!empty($value)) {
                    if (intval($rules['equal_to'])) {
                        echo '<a target="_blank" href="' . $value . '">';
                        echo '<img src="' . $value . '" alt="picture"' . $size . ' width="' . intval($rules['equal_to']) . '" height="*" />';
                        echo "</a>";
                    } else {
                        echo '<img src="' . $value . '" alt="picture" />';
                    }
                    echo "<br />";
                    echo "\n\t\t";
                }
                echo "<br />" . __("Picture URL:", $cimy_uef_domain) . "<br />\n\t\t";
            }
            // write previous value
            echo "<input type=\"hidden\" name=\"" . $input_name . "_" . $field_id . "_prev_value\" value=\"" . $old_value . "\" />\n\t\t";
            // TinceMCE needed and we have WordPress >= 3.3 yummy!
            if ($type == "textarea-rich" && function_exists("wp_editor")) {
                $quicktags_settings = array('buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close');
                $editor_settings = array('textarea_name' => $input_name, 'teeny' => false, 'textarea_rows' => '10', 'dfw' => false, 'media_buttons' => true, 'tinymce' => true, 'quicktags' => $quicktags_settings);
                wp_editor($non_escaped_value, $unique_id, $editor_settings);
            } else {
                if ($type != "registration-date") {
                    echo $form_object;
                } else {
                    echo $obj_value;
                }
            }
            if (!empty($description) && $type != "picture" && $type != "picture-url") {
                if ($type == "textarea" || $type == "textarea-rich") {
                    echo "<br />";
                } else {
                    echo " ";
                }
                echo "<span class='description'>" . $description . "</span>";
            }
            echo "</td>";
            echo "\n\t</tr>\n";
        }
        echo "</table>";
        // WP 3.2 or lower (N)
        if (!empty($tiny_mce_objects) && !function_exists("wp_editor")) {
            require_once $cuef_plugin_dir . '/cimy_uef_init_mce.php';
        }
        echo $end_cimy_uef_comment;
    }
}
function cimy_uef_get_dir_or_filename($user_login, $url = "", $is_thumbnail = false)
{
    global $cimy_uef_plugins_dir, $cuef_upload_path;
    $blog_path = $cuef_upload_path;
    if ($cimy_uef_plugins_dir == "plugins" && is_multisite()) {
        global $blog_id;
        $blog_path .= $blog_id . "/";
    }
    if (empty($url)) {
        return $blog_path . $user_login;
    } else {
        if ($is_thumbnail) {
            return $blog_path . $user_login . "/" . cimy_get_thumb_path(basename($url));
        } else {
            return $blog_path . $user_login . "/" . basename($url);
        }
    }
}
Exemple #5
0
function cimy_manage_upload($input_name, $user_login, $rules, $old_file = false, $delete_file = false, $type = "", $new_filename = "")
{
    global $cuef_upload_path, $cuef_upload_webpath, $cuef_plugin_dir, $cimy_uef_plugins_dir;
    $type_path = "";
    if ($type == "file" || $type == "avatar") {
        $type_path .= $type . "/";
    }
    $blog_path = $cuef_upload_path;
    if ($cimy_uef_plugins_dir == "plugins" && is_multisite()) {
        global $blog_id;
        $blog_path .= $blog_id . "/";
        // create blog subdir
        if (!is_dir($blog_path)) {
            if (defined("FS_CHMOD_DIR")) {
                mkdir($blog_path, FS_CHMOD_DIR);
                chmod($blog_path, FS_CHMOD_DIR);
            } else {
                wp_mkdir_p($blog_path);
            }
        }
    }
    if (!empty($user_login)) {
        $user_path = $blog_path . $user_login . "/";
        $file_path = $blog_path . $user_login . "/" . $type_path;
    } else {
        $user_path = $blog_path;
        $file_path = $blog_path . $type_path;
    }
    // delete old file if requested
    if ($delete_file) {
        if (is_file($file_path . $old_file)) {
            unlink($file_path . $old_file);
        }
        $old_thumb_file = cimy_get_thumb_path($old_file);
        if (is_file($file_path . $old_thumb_file)) {
            unlink($file_path . $old_thumb_file);
        }
    }
    // if $user_login is not present
    //	or there is no file to upload
    //	or dest dir is not writable
    // then everything else is useless
    if ($user_login == "" && $type != "registration-logo" || empty($_FILES[$input_name]['name']) || !is_writable($cuef_upload_path)) {
        return "";
    }
    // create user subdir
    if (!is_dir($user_path)) {
        if (defined("FS_CHMOD_DIR")) {
            mkdir($user_path, FS_CHMOD_DIR);
            chmod($user_path, FS_CHMOD_DIR);
        } else {
            wp_mkdir_p($user_path);
        }
    }
    // create avatar subdir if needed
    if ($type != "registration-logo" && $type != "picture" && !is_dir($file_path)) {
        if (defined("FS_CHMOD_DIR")) {
            mkdir($file_path, FS_CHMOD_DIR);
            chmod($file_path, FS_CHMOD_DIR);
        } else {
            wp_mkdir_p($file_path);
        }
    }
    if (!empty($new_filename)) {
        $file_name = $new_filename;
    } else {
        $file_name = $_FILES[$input_name]['name'];
    }
    // filesize in Byte transformed in KiloByte
    $file_size = $_FILES[$input_name]['size'] / 1024;
    $file_type = $_FILES[$input_name]['type'];
    $file_tmp_name = $_FILES[$input_name]['tmp_name'];
    $file_error = $_FILES[$input_name]['error'];
    $allowed_mime_types = get_allowed_mime_types();
    // let's see if the image extension is correct, bad boy
    $validate = wp_check_filetype_and_ext($file_tmp_name, $file_name, $allowed_mime_types);
    if ($validate['proper_filename'] !== false) {
        $file_name = $validate['proper_filename'];
    }
    // sanitize the file name
    $file_name = wp_unique_filename($file_path, $file_name);
    // file path
    $file_full_path = $file_path . $file_name;
    // picture url to write in the DB
    $data = $cuef_upload_webpath;
    if ($cimy_uef_plugins_dir == "plugins" && is_multisite()) {
        $data .= $blog_id . "/";
    }
    if (empty($user_login)) {
        $data .= $type_path . $file_name;
    } else {
        $data .= $user_login . "/" . $type_path . $file_name;
    }
    // CHECK IF IT IS A REAL PICTURE
    if ($type != "file" && stristr($file_type, "image/") === false) {
        $file_error = 1;
    }
    // MIN LENGTH
    if (isset($rules['min_length'])) {
        if ($file_size < intval($rules['min_length'])) {
            $file_error = 1;
        }
    }
    // EXACT LENGTH
    if (isset($rules['exact_length'])) {
        if ($file_size != intval($rules['exact_length'])) {
            $file_error = 1;
        }
    }
    // MAX LENGTH
    if (isset($rules['max_length'])) {
        if ($file_size > intval($rules['max_length'])) {
            $file_error = 1;
        }
    }
    // if there are no errors and filename is NOT empty
    if ($file_error == 0 && !empty($file_name)) {
        if (move_uploaded_file($file_tmp_name, $file_full_path)) {
            // change file permissions for broken servers
            if (defined("FS_CHMOD_FILE")) {
                @chmod($file_full_path, FS_CHMOD_FILE);
            } else {
                @chmod($file_full_path, 0644);
            }
            // if there is an old file to delete
            if ($old_file) {
                // delete old file if the name is different, if equal NOPE because new file is already uploaded
                if ($file_name != $old_file) {
                    if (is_file($file_path . $old_file)) {
                        unlink($file_path . $old_file);
                    }
                }
                $old_thumb_file = cimy_get_thumb_path($old_file);
                if (is_file($file_path . $old_thumb_file)) {
                    unlink($file_path . $old_thumb_file);
                }
            }
            // should be stay AFTER DELETIONS
            if (isset($rules['equal_to']) && $type != "file") {
                if ($maxside = intval($rules['equal_to'])) {
                    if (cimy_is_at_least_wordpress35()) {
                        if (!defined("WPINC")) {
                            define('WPINC', 'wp-includes');
                        }
                        if (!function_exists("image_make_intermediate_size")) {
                            require_once ABSPATH . WPINC . '/media.php';
                            require_once ABSPATH . WPINC . '/functions.php';
                        }
                        $resized_file = image_make_intermediate_size($file_full_path, $maxside, $maxside, false);
                        if (isset($resized_file["file"])) {
                            @rename($file_path . $resized_file["file"], $file_path . str_replace(sprintf("%sx%s", $resized_file["width"], $resized_file["height"]), "thumbnail", $resized_file["file"]));
                        }
                    } else {
                        if (!function_exists("image_resize")) {
                            require_once ABSPATH . 'wp-includes/media.php';
                        }
                        if (!function_exists("wp_load_image")) {
                            require_once $cuef_plugin_dir . '/cimy_uef_missing_functions.php';
                        }
                        image_resize($file_full_path, $maxside, $maxside, false, "thumbnail");
                    }
                }
            }
        } else {
            $data = "";
        }
    } else {
        $data = "";
    }
    return $data;
}
             echo '<img src="' . $field . '" alt="picture" />';
         }
         echo "<br />";
         echo "\n\t\t";
     }
 } else {
     if ($type == "picture") {
         if ($field == "") {
             $field = $value;
         }
         if ($field != "") {
             //$profileuser = get_user_to_edit($user_object->ID);
             //$user_login = $profileuser->user_login;
             $user_login = $user_object->user_login;
             $value_thumb = cimy_get_thumb_path($field);
             $file_thumb = $cuef_upload_path . $user_login . "/" . cimy_get_thumb_path(basename($field));
             $file_on_server = $cuef_upload_path . $user_login . "/" . basename($field);
             echo "\n\t\t";
             if (is_file($file_thumb)) {
                 echo '<a target="_blank" href="' . $field . '"><img src="' . $value_thumb . '" alt="picture" /></a><br />';
                 echo "\n\t\t";
             } else {
                 if (is_file($file_on_server)) {
                     echo '<img src="' . $field . '" alt="picture" /><br />';
                     echo "\n\t\t";
                 }
             }
         }
     } else {
         if ($type == "file") {
             echo '<a target="_blank" href="' . $field . '">';
function cimy_extract_ExtraFields()
{
    global $wpdb, $user_ID, $wpdb_data_table, $start_cimy_uef_comment, $end_cimy_uef_comment, $rule_profile_value, $cimy_uef_options, $rule_maxlen_needed, $fields_name_prefix, $cuef_upload_path, $cimy_uef_domain, $cuef_plugin_dir, $cimy_uef_file_types, $cimy_uef_textarea_types, $user_level;
    // if editing a different user (only admin)
    if (isset($_GET['user_id'])) {
        $get_user_id = $_GET['user_id'];
        if (!current_user_can('edit_user', $get_user_id)) {
            return;
        }
    } else {
        if (isset($_POST['user_id'])) {
            $get_user_id = $_POST['user_id'];
            if (!current_user_can('edit_user', $get_user_id)) {
                return;
            }
        } else {
            if (!isset($user_ID)) {
                return;
            }
            $get_user_id = $user_ID;
        }
    }
    $get_user_id = intval($get_user_id);
    $options = cimy_get_options();
    $extra_fields = get_cimyFields(false, true);
    if (!empty($extra_fields)) {
        $upload_image_function = false;
        echo $start_cimy_uef_comment;
        if ($options['extra_fields_title'] != "") {
            echo "<br clear=\"all\" />\n";
            echo "<h2>" . $options['extra_fields_title'] . "</h2>\n";
        }
        foreach ($extra_fields as $thisField) {
            $field_id = $thisField['ID'];
            cimy_insert_ExtraFields_if_not_exist($get_user_id, $field_id);
        }
        // 		$ef_db = $wpdb->get_results("SELECT FIELD_ID, VALUE FROM ".$wpdb_data_table." WHERE USER_ID = ".$get_user_id, ARRAY_A);
        $radio_checked = array();
        $current_fieldset = -1;
        $tiny_mce_objects = "";
        if ($options['fieldset_title'] != "") {
            $fieldset_titles = explode(',', $options['fieldset_title']);
        } else {
            $fieldset_titles = array();
        }
        $close_table = false;
        echo '<table class="form-table">';
        echo "\n";
        foreach ($extra_fields as $thisField) {
            $value = "";
            $old_value = "";
            $field_id = $thisField['ID'];
            $name = $thisField['NAME'];
            $rules = $thisField['RULES'];
            $type = $thisField['TYPE'];
            $label = $thisField['LABEL'];
            $description = $thisField['DESCRIPTION'];
            $fieldset = $thisField['FIELDSET'];
            $input_name = $fields_name_prefix . esc_attr($name);
            // if the current user LOGGED IN has not enough permissions to see the field, skip it
            // apply only for EXTRA FIELDS
            if ($user_level < $rules['show_level']) {
                continue;
            }
            // if show_level == anonymous then do NOT ovverride other show_xyz rules
            if ($rules['show_level'] == -1) {
                // if flag to show the field in the profile is NOT activated, skip it
                if (!$rules['show_in_profile']) {
                    continue;
                }
            }
            // 			foreach ($ef_db as $d_field) {
            // 				if ($d_field['FIELD_ID'] == $field_id)
            // 					$value = $d_field['VALUE'];
            // 			}
            $value = $wpdb->get_var($wpdb->prepare("SELECT VALUE FROM " . $wpdb_data_table . " WHERE USER_ID=" . $get_user_id . " AND FIELD_ID=" . $field_id));
            $old_value = $value;
            // if nothing is inserted and field admin default value then assign it
            if (in_array($type, $rule_profile_value)) {
                if ($value == "") {
                    $value = $thisField['VALUE'];
                }
            }
            if ($fieldset > $current_fieldset && isset($fieldset_titles[$fieldset])) {
                $current_fieldset = $fieldset;
                // do not close the table if it is the first iteration
                if ($close_table) {
                    echo "</table>\n";
                } else {
                    $close_table = true;
                }
                if (isset($fieldset_titles[$current_fieldset])) {
                    echo "\n\t<h3>" . $fieldset_titles[$current_fieldset] . "</h3>\n";
                }
                echo '<table class="form-table">';
                echo "\n";
            }
            echo "\t";
            echo "<tr>";
            echo "\n\t";
            $value = esc_attr($value);
            switch ($type) {
                case "picture-url":
                case "password":
                case "text":
                    $obj_label = '<label for="' . $fields_name_prefix . $field_id . '">' . $label . '</label>';
                    $obj_name = ' name="' . $input_name . '"';
                    if ($type == "picture-url") {
                        $obj_type = ' type="text"';
                    } else {
                        $obj_type = ' type="' . $type . '"';
                    }
                    $obj_value = ' value="' . $value . '"';
                    $obj_value2 = "";
                    $obj_checked = "";
                    $obj_tag = "input";
                    $obj_closing_tag = false;
                    $obj_style = ' class="regular-text"';
                    if ($old_value != "" && $rules['edit'] == 'edit_only_if_empty' || $old_value != "" && !current_user_can('edit_users') && $rules['edit'] == 'edit_only_by_admin_or_if_empty' || $rules['edit'] == 'no_edit' || $rules['edit'] == 'edit_only_by_admin' && !current_user_can('edit_users')) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    break;
                case "textarea":
                    $obj_label = '<label for="' . $fields_name_prefix . $field_id . '">' . $label . '</label>';
                    $obj_name = ' name="' . $input_name . '"';
                    $obj_type = "";
                    $obj_value = "";
                    $obj_value2 = $value;
                    $obj_checked = "";
                    $obj_tag = "textarea";
                    $obj_closing_tag = true;
                    $obj_style = "";
                    if ($old_value != "" && $rules['edit'] == 'edit_only_if_empty' || $old_value != "" && !current_user_can('edit_users') && $rules['edit'] == 'edit_only_by_admin_or_if_empty' || $rules['edit'] == 'no_edit' || $rules['edit'] == 'edit_only_by_admin' && !current_user_can('edit_users')) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    break;
                case "textarea-rich":
                    if ($tiny_mce_objects == "") {
                        $tiny_mce_objects = $fields_name_prefix . $field_id;
                    } else {
                        $tiny_mce_objects .= "," . $fields_name_prefix . $field_id;
                    }
                    $obj_label = '<label for="' . $fields_name_prefix . $field_id . '">' . $label . '</label>';
                    $obj_name = ' name="' . $input_name . '"';
                    $obj_type = "";
                    $obj_value = "";
                    $obj_value2 = $value;
                    $obj_checked = "";
                    $obj_tag = "textarea";
                    $obj_closing_tag = true;
                    $obj_style = "";
                    if ($old_value != "" && $rules['edit'] == 'edit_only_if_empty' || $old_value != "" && !current_user_can('edit_users') && $rules['edit'] == 'edit_only_by_admin_or_if_empty' || $rules['edit'] == 'no_edit' || $rules['edit'] == 'edit_only_by_admin' && !current_user_can('edit_users')) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    break;
                case "dropdown-multi":
                case "dropdown":
                    $ret = cimy_dropDownOptions($label, $value);
                    $label = $ret['label'];
                    $html = $ret['html'];
                    $obj_label = '<label for="' . $fields_name_prefix . $field_id . '">' . $label . '</label>';
                    if ($type == "dropdown-multi") {
                        $obj_name = ' name="' . $input_name . '[]" multiple="multiple" size="5"';
                        $obj_style = ' style="height: 11em;"';
                    } else {
                        $obj_name = ' name="' . $input_name . '"';
                        $obj_style = '';
                    }
                    $obj_type = '';
                    $obj_value = '';
                    $obj_value2 = $html;
                    $obj_checked = "";
                    $obj_tag = "select";
                    $obj_closing_tag = true;
                    if ($old_value != "" && $rules['edit'] == 'edit_only_if_empty' || $old_value != "" && !current_user_can('edit_users') && $rules['edit'] == 'edit_only_by_admin_or_if_empty' || $rules['edit'] == 'no_edit' || $rules['edit'] == 'edit_only_by_admin' && !current_user_can('edit_users')) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    break;
                case "checkbox":
                    $obj_label = '<label for="' . $fields_name_prefix . $field_id . '">' . $label . '</label>';
                    $obj_name = ' name="' . $input_name . '"';
                    $obj_type = ' type="' . $type . '"';
                    $obj_value = ' value="1"';
                    $obj_value2 = "";
                    $value == "YES" ? $obj_checked = ' checked="checked"' : ($obj_checked = '');
                    $obj_tag = "input";
                    $obj_closing_tag = false;
                    $obj_style = ' style="width:auto; border:0; background:white;"';
                    if ($rules['edit'] == 'no_edit' || ($rules['edit'] == 'edit_only_by_admin' || $rules['edit'] == 'edit_only_by_admin_or_if_empty') && !current_user_can('edit_users')) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    break;
                case "radio":
                    $obj_label = '<label for="' . $fields_name_prefix . $field_id . '"> ' . $label . '</label>';
                    $obj_name = ' name="' . $input_name . '"';
                    $obj_type = ' type="' . $type . '"';
                    $obj_value = ' value="' . $field_id . '"';
                    $obj_value2 = "";
                    $obj_tag = "input";
                    $obj_closing_tag = false;
                    $obj_style = ' style="width:auto; border:0; background:white;"';
                    if ($rules['edit'] == 'no_edit' || ($rules['edit'] == 'edit_only_by_admin' || $rules['edit'] == 'edit_only_by_admin_or_if_empty') && !current_user_can('edit_users')) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    if ($value == "") {
                        $obj_checked = '';
                    } else {
                        $obj_checked .= ' checked="checked"';
                    }
                    break;
                case "avatar":
                case "picture":
                case "file":
                    $allowed_exts = '';
                    if (isset($rules['equal_to'])) {
                        if ($rules['equal_to'] != "") {
                            $allowed_exts = "'" . implode("', '", explode(",", $rules['equal_to'])) . "'";
                        }
                    }
                    // javascript will be added later
                    $upload_file_function = true;
                    $obj_label = '<label for="' . $fields_name_prefix . $field_id . '">' . $label . '</label>';
                    $obj_class = '';
                    $obj_name = ' name="' . $input_name . '"';
                    $obj_type = ' type="file"';
                    $obj_value = ' value=""';
                    $obj_value2 = '';
                    $obj_checked = "";
                    $obj_tag = "input";
                    $obj_closing_tag = false;
                    if ($type == "file") {
                        // if we do not escape then some translations can break
                        $warning_msg = $wpdb->escape(__("Please upload a file with one of the following extensions", $cimy_uef_domain));
                        $obj_style = ' onchange="uploadFile(\'your-profile\', \'' . $fields_name_prefix . $field_id . '\', \'' . $warning_msg . '\', Array(' . $allowed_exts . '));"';
                    } else {
                        // if we do not escape then some translations can break
                        $warning_msg = $wpdb->escape(__("Please upload an image with one of the following extensions", $cimy_uef_domain));
                        $obj_style = ' onchange="uploadFile(\'your-profile\', \'' . $fields_name_prefix . $field_id . '\', \'' . $warning_msg . '\', Array(\'gif\', \'png\', \'jpg\', \'jpeg\', \'tiff\'));"';
                    }
                    if ($old_value != "" && $rules['edit'] == 'edit_only_if_empty' || $old_value != "" && !current_user_can('edit_users') && $rules['edit'] == 'edit_only_by_admin_or_if_empty' || $rules['edit'] == 'no_edit' || $rules['edit'] == 'edit_only_by_admin' && !current_user_can('edit_users')) {
                        $obj_disabled = ' disabled="disabled"';
                    } else {
                        $obj_disabled = "";
                    }
                    break;
                case "registration-date":
                    if (isset($rules['equal_to'])) {
                        $obj_value = cimy_get_formatted_date($value, $rules['equal_to']);
                    } else {
                        $obj_value = cimy_get_formatted_date($value);
                    }
                    $obj_label = '<label>' . $label . '</label>';
                    break;
            }
            $obj_id = ' id="' . $fields_name_prefix . $field_id . '"';
            $obj_class = '';
            $obj_maxlen = "";
            if (in_array($type, $rule_maxlen_needed) && !in_array($type, $cimy_uef_file_types)) {
                if (isset($rules['max_length'])) {
                    $obj_maxlen = ' maxlength="' . $rules['max_length'] . '"';
                } else {
                    if (isset($rules['exact_length'])) {
                        $obj_maxlen = ' maxlength="' . $rules['exact_length'] . '"';
                    }
                }
            }
            if (in_array($type, $cimy_uef_textarea_types)) {
                $obj_rowscols = ' rows="3" cols="25"';
            } else {
                $obj_rowscols = '';
            }
            echo "\t";
            $form_object = '<' . $obj_tag . $obj_id . $obj_class . $obj_name . $obj_type . $obj_value . $obj_checked . $obj_maxlen . $obj_rowscols . $obj_style . $obj_disabled;
            if ($obj_closing_tag) {
                $form_object .= ">" . $obj_value2 . "</" . $obj_tag . ">";
            } else {
                $form_object .= " />";
            }
            echo "<th>";
            echo $obj_label;
            echo "</th>\n";
            echo "\t\t<td>";
            if ($description != "" && ($type == "picture" || $type == "picture-url")) {
                echo $description . "<br />";
            }
            if (in_array($type, $cimy_uef_file_types)) {
                $profileuser = get_user_to_edit($get_user_id);
            }
            if ($type == "avatar") {
                $user_email = $profileuser->user_email;
                echo '<div id="profpic">' . get_avatar($user_email, $size = '128') . "</div>\n\t\t";
            }
            if (in_array($type, $cimy_uef_file_types) && $value != "") {
                global $cimy_uef_plugins_dir;
                $blog_path = $cuef_upload_path;
                if ($cimy_uef_plugins_dir == "plugins" && is_multisite()) {
                    global $blog_id;
                    $blog_path .= $blog_id . "/";
                }
                $user_login = $profileuser->user_login;
                if ($type == "picture") {
                    $value_thumb = cimy_get_thumb_path($value);
                    $file_thumb = $blog_path . $user_login . "/" . cimy_get_thumb_path(basename($value));
                    $file_on_server = $blog_path . $user_login . "/" . basename($value);
                    echo "\n\t\t";
                    if (is_file($file_thumb)) {
                        echo '<a target="_blank" href="' . $value . '"><img src="' . $value_thumb . '" alt="picture" /></a><br />';
                        echo "\n\t\t";
                    } else {
                        if (is_file($file_on_server)) {
                            echo '<img src="' . $value . '" alt="picture" /><br />';
                            echo "\n\t\t";
                        }
                    }
                }
                if ($type == "file") {
                    echo '<a target="_blank" href="' . $value . '">';
                    echo basename($value);
                    echo '</a><br />';
                    echo "\n\t\t";
                }
                // if there is no image or there is the default one then disable delete button
                if ($old_value == "") {
                    $dis_delete_img = ' disabled="disabled"';
                } else {
                    // take the "can be modified" rule just set before
                    $dis_delete_img = $obj_disabled;
                    echo '<input type="hidden" name="' . $input_name . '_oldfile" value="' . basename($value) . '" />';
                    echo "\n\t\t";
                }
                echo '<input type="checkbox" name="' . $input_name . '_del" value="1" style="width:auto; border:0; background:white;"' . $dis_delete_img . ' />';
                if ($type == "file") {
                    echo " " . __("Delete the file", $cimy_uef_domain) . "<br /><br />";
                    echo "\n\t\t" . __("Update the file", $cimy_uef_domain) . "<br />";
                } else {
                    echo " " . __("Delete the picture", $cimy_uef_domain) . "<br /><br />";
                    echo "\n\t\t" . __("Update the picture", $cimy_uef_domain) . "<br />";
                }
                echo "\n\t\t";
            }
            if ($type == "picture-url") {
                if ($value != "") {
                    if (intval($rules['equal_to'])) {
                        echo '<a target="_blank" href="' . $value . '">';
                        echo '<img src="' . $value . '" alt="picture"' . $size . ' width="' . intval($rules['equal_to']) . '" height="*" />';
                        echo "</a>";
                    } else {
                        echo '<img src="' . $value . '" alt="picture" />';
                    }
                    echo "<br />";
                    echo "\n\t\t";
                }
                echo "<br />" . __("Picture URL:", $cimy_uef_domain) . "<br />\n\t\t";
            }
            // write to the html the form object built
            if ($type != "registration-date") {
                echo $form_object;
            } else {
                echo $obj_value;
            }
            if ($description != "" && $type != "picture" && $type != "picture-url") {
                if ($type == "textarea" || $type == "textarea-rich") {
                    echo "<br />";
                } else {
                    echo " ";
                }
                echo $description;
            }
            echo "</td>";
            echo "\n\t</tr>\n";
        }
        echo "</table>";
        if ($tiny_mce_objects != "") {
            $mce_skin = 'skin : "wp_theme",';
            require_once $cuef_plugin_dir . '/cimy_uef_init_mce.php';
        }
        if ($upload_file_function) {
            wp_print_scripts("cimy_uef_upload_file");
        }
        echo $end_cimy_uef_comment;
    }
}