Пример #1
0
function wfu_ajax_action_read_subfolders()
{
    if (!isset($_POST['folder1']) || !isset($_POST['folder2'])) {
        die;
    }
    $temp_params = array('uploadpath' => wfu_plugin_decode_string($_POST['folder1']), 'accessmethod' => 'normal', 'ftpinfo' => '', 'useftpdomain' => 'false');
    $path = wfu_upload_plugin_full_path($temp_params);
    if (!is_dir($path)) {
        die("wfu_read_subfolders:error:Parent folder is not valid! Cannot retrieve subfolder list.");
    }
    $path2 = wfu_plugin_decode_string($_POST['folder2']);
    $dirlist = "";
    if ($handle = opendir($path)) {
        $blacklist = array('.', '..');
        while (false !== ($file = readdir($handle))) {
            if (!in_array($file, $blacklist)) {
                $filepath = $path . $file;
                if (is_dir($filepath)) {
                    if ($file == $path2) {
                        $file = '[[' . $file . ']]';
                    }
                    $dirlist .= ($dirlist == "" ? "" : ",") . $file;
                }
            }
        }
        closedir($handle);
    }
    if ($path2 != "") {
        $dirlist2 = $path2;
        $path .= $path2 . "/";
        if (is_dir($path)) {
            if ($handle = opendir($path)) {
                $blacklist = array('.', '..');
                while (false !== ($file = readdir($handle))) {
                    if (!in_array($file, $blacklist)) {
                        $filepath = $path . $file;
                        if (is_dir($filepath)) {
                            $dirlist2 .= ",*" . $file;
                        }
                    }
                }
                closedir($handle);
            }
        }
        $dirlist = str_replace('[[' . $path2 . ']]', $dirlist2, $dirlist);
    }
    die("wfu_read_subfolders:success:" . wfu_plugin_encode_string($dirlist));
}
Пример #2
0
function wfu_encode_plugin_options($plugin_options)
{
    $encoded_options = 'version=' . $plugin_options['version'] . ';';
    $encoded_options .= 'shortcode=' . wfu_plugin_encode_string($plugin_options['shortcode']) . ';';
    $encoded_options .= 'hashfiles=' . $plugin_options['hashfiles'] . ';';
    $encoded_options .= 'basedir=' . wfu_plugin_encode_string($plugin_options['basedir']) . ';';
    $encoded_options .= 'postmethod=' . $plugin_options['postmethod'] . ';';
    $encoded_options .= 'relaxcss=' . $plugin_options['relaxcss'] . ';';
    $encoded_options .= 'captcha_sitekey=' . wfu_plugin_encode_string($plugin_options['captcha_sitekey']) . ';';
    $encoded_options .= 'captcha_secretkey=' . wfu_plugin_encode_string($plugin_options['captcha_secretkey']) . ';';
    $encoded_options .= 'browser_permissions=' . wfu_encode_array_to_string($plugin_options['browser_permissions']);
    return $encoded_options;
}
Пример #3
0
function wfu_set_javascript_constants()
{
    $consts = array("nofilemessage" => WFU_ERROR_UPLOAD_NOFILESELECTED, "enable_popups" => WFU_ERROR_ENABLE_POPUPS, "remoteserver_noresult" => WFU_ERROR_REMOTESERVER_NORESULT, "message_header" => WFU_ERRORMESSAGE, "message_failed" => WFU_ERROR_UPLOAD_FAILED_WHILE, "message_cancelled" => WFU_ERROR_UPLOAD_CANCELLED, "message_unknown" => WFU_ERROR_UNKNOWN, "adminmessage_unknown" => WFU_FAILMESSAGE_DETAILS, "message_timelimit" => WFU_ERROR_FILE_PHP_TIME, "message_admin_timelimit" => WFU_ERROR_ADMIN_FILE_PHP_TIME, "cancel_upload_prompt" => WFU_CANCEL_UPLOAD_PROMPT, "file_cancelled" => WFU_ERROR_FILE_CANCELLED, "jsonparse_filemessage" => WFU_ERROR_JSONPARSE_FILEMESSAGE, "jsonparse_message" => WFU_ERROR_JSONPARSE_MESSAGE, "jsonparse_adminmessage" => WFU_ERROR_JSONPARSE_ADMINMESSAGE, "jsonparse_headermessage" => WFU_ERROR_JSONPARSE_HEADERMESSAGE, "jsonparse_headeradminmessage" => WFU_ERROR_JSONPARSE_HEADERADMINMESSAGE, "same_pluginid" => WFU_ERROR_SAME_PLUGINID, "default_colors" => WFU_VAR("WFU_DEFAULTMESSAGECOLORS"), "fail_colors" => WFU_VAR("WFU_FAILMESSAGECOLORS"), "max_time_limit" => WFU_MAX_TIME_LIMIT, "response_url" => WFU_RESPONSE_URL, "ajax_url" => wfu_ajaxurl(), "wfu_pageexit_prompt" => WFU_PAGEEXIT_PROMPT, "wfu_subdir_typedir" => WFU_SUBDIR_TYPEDIR);
    $consts_txt = "";
    foreach ($consts as $key => $val) {
        $consts_txt .= ($consts_txt == "" ? "" : ";") . wfu_plugin_encode_string($key) . ":" . wfu_plugin_encode_string($val);
    }
    return $consts_txt;
}
function wfu_encode_plugin_options($plugin_options)
{
    $encoded_options = 'version=' . (isset($plugin_options['version']) ? $plugin_options['version'] : "1.0") . ';';
    $encoded_options .= 'shortcode=' . (isset($plugin_options['shortcode']) ? wfu_plugin_encode_string($plugin_options['shortcode']) : "") . ';';
    $encoded_options .= 'hashfiles=' . (isset($plugin_options['hashfiles']) ? $plugin_options['hashfiles'] : "") . ';';
    $encoded_options .= 'basedir=' . (isset($plugin_options['basedir']) ? wfu_plugin_encode_string($plugin_options['basedir']) : "") . ';';
    $encoded_options .= 'postmethod=' . (isset($plugin_options['postmethod']) ? $plugin_options['postmethod'] : "") . ';';
    $encoded_options .= 'modsecurity=' . (isset($plugin_options['modsecurity']) ? $plugin_options['modsecurity'] : "") . ';';
    $encoded_options .= 'relaxcss=' . (isset($plugin_options['relaxcss']) ? $plugin_options['relaxcss'] : "") . ';';
    $encoded_options .= 'admindomain=' . (isset($plugin_options['admindomain']) ? $plugin_options['admindomain'] : "") . ';';
    $encoded_options .= 'mediacustom=' . (isset($plugin_options['mediacustom']) ? $plugin_options['mediacustom'] : "") . ';';
    $encoded_options .= 'captcha_sitekey=' . (isset($plugin_options['captcha_sitekey']) ? wfu_plugin_encode_string($plugin_options['captcha_sitekey']) : "") . ';';
    $encoded_options .= 'captcha_secretkey=' . (isset($plugin_options['captcha_secretkey']) ? wfu_plugin_encode_string($plugin_options['captcha_secretkey']) : "") . ';';
    $encoded_options .= 'dropbox_accesstoken=' . (isset($plugin_options['dropbox_accesstoken']) ? wfu_plugin_encode_string($plugin_options['dropbox_accesstoken']) : "") . ';';
    $encoded_options .= 'dropbox_defaultpath=' . (isset($plugin_options['dropbox_defaultpath']) ? wfu_plugin_encode_string($plugin_options['dropbox_defaultpath']) : "") . ';';
    $encoded_options .= 'browser_permissions=' . (isset($plugin_options['browser_permissions']) ? wfu_encode_array_to_string($plugin_options['browser_permissions']) : "");
    return $encoded_options;
}
Пример #5
0
function wfu_view_log($page = 1, $only_table_rows = false)
{
    global $wpdb;
    $siteurl = site_url();
    $table_name1 = $wpdb->prefix . "wfu_log";
    $table_name2 = $wpdb->prefix . "wfu_userdata";
    $plugin_options = wfu_decode_plugin_options(get_option("wordpress_file_upload_options"));
    if (!current_user_can('manage_options')) {
        return;
    }
    //get log data from database
    $files_total = $wpdb->get_var('SELECT COUNT(idlog) FROM ' . $table_name1);
    $filerecs = $wpdb->get_results('SELECT * FROM ' . $table_name1 . ' ORDER BY date_from DESC' . (WFU_VAR("WFU_HISTORYLOG_TABLE_MAXROWS") > 0 ? ' LIMIT ' . WFU_VAR("WFU_HISTORYLOG_TABLE_MAXROWS") . ' OFFSET ' . ($page - 1) * (int) WFU_VAR("WFU_HISTORYLOG_TABLE_MAXROWS") : ''));
    $echo_str = "";
    if (!$only_table_rows) {
        $echo_str .= "\n" . '<div class="wrap">';
        $echo_str .= "\n\t" . '<h2>Wordpress File Upload Control Panel</h2>';
        $echo_str .= "\n\t" . '<div style="margin-top:20px;">';
        $echo_str .= wfu_generate_dashboard_menu("\n\t\t", "View Log");
        $echo_str .= "\n\t" . '<div style="position:relative;">';
        $echo_str .= wfu_add_loading_overlay("\n\t\t", "historylog");
        $echo_str .= "\n\t\t" . '<div class="wfu_historylog_header" style="width: 100%;">';
        if (WFU_VAR("WFU_HISTORYLOG_TABLE_MAXROWS") > 0) {
            $pages = ceil($files_total / WFU_VAR("WFU_HISTORYLOG_TABLE_MAXROWS"));
            $echo_str .= wfu_add_pagination_header("\n\t\t\t", "historylog", 1, $pages);
        }
        $echo_str .= "\n\t\t" . '</div>';
        $echo_str .= "\n\t\t" . '<table id="wfu_historylog_table" class="wp-list-table widefat fixed striped">';
        $echo_str .= "\n\t\t\t" . '<thead>';
        $echo_str .= "\n\t\t\t\t" . '<tr>';
        $echo_str .= "\n\t\t\t\t\t" . '<th scope="col" width="5%" style="text-align:center;">';
        $echo_str .= "\n\t\t\t\t\t\t" . '<label>#</label>';
        $echo_str .= "\n\t\t\t\t\t" . '</th>';
        $echo_str .= "\n\t\t\t\t\t" . '<th scope="col" width="15%" style="text-align:left;">';
        $echo_str .= "\n\t\t\t\t\t\t" . '<label>Date</label>';
        $echo_str .= "\n\t\t\t\t\t" . '</th>';
        $echo_str .= "\n\t\t\t\t\t" . '<th scope="col" width="10%" style="text-align:center;">';
        $echo_str .= "\n\t\t\t\t\t\t" . '<label>Action</label>';
        $echo_str .= "\n\t\t\t\t\t" . '</th>';
        $echo_str .= "\n\t\t\t\t\t" . '<th scope="col" width="30%" style="text-align:left;">';
        $echo_str .= "\n\t\t\t\t\t\t" . '<label>File</label>';
        $echo_str .= "\n\t\t\t\t\t" . '</th>';
        $echo_str .= "\n\t\t\t\t\t" . '<th scope="col" width="15%" style="text-align:center;">';
        $echo_str .= "\n\t\t\t\t\t\t" . '<label>User</label>';
        $echo_str .= "\n\t\t\t\t\t" . '</th>';
        $echo_str .= "\n\t\t\t\t\t" . '<th scope="col" width="25%" style="text-align:left;">';
        $echo_str .= "\n\t\t\t\t\t\t" . '<label>Remarks</label>';
        $echo_str .= "\n\t\t\t\t\t" . '</th>';
        $echo_str .= "\n\t\t\t\t" . '</tr>';
        $echo_str .= "\n\t\t\t" . '</thead>';
        $echo_str .= "\n\t\t\t" . '<tbody>';
    }
    $userdatarecs = $wpdb->get_results('SELECT * FROM ' . $table_name2);
    $deletedfiles = array();
    $filecodes = array();
    $time0 = strtotime("0000-00-00 00:00:00");
    $i = ($page - 1) * (int) WFU_VAR("WFU_HISTORYLOG_TABLE_MAXROWS");
    foreach ($filerecs as $filerec) {
        $remarks = '';
        $filepath = ABSPATH;
        if (substr($filepath, -1) == '/') {
            $filepath = substr($filepath, 0, -1);
        }
        $filepath .= $filerec->filepath;
        $enc_file = wfu_plugin_encode_string($filepath . '[[name]]');
        if ($filerec->action == 'delete') {
            array_push($deletedfiles, $filerec->linkedto);
        } elseif ($filerec->action == 'rename') {
            $prevfilepath = '';
            foreach ($filerecs as $key => $prevfilerec) {
                if ($prevfilerec->idlog == $filerec->linkedto) {
                    $prevfilepath = $prevfilerec->filepath;
                    break;
                }
            }
            if ($prevfilepath != '') {
                $remarks = "\n\t\t\t\t\t\t" . '<label>Previous filepath: ' . $prevfilepath . '</label>';
            }
        } elseif ($filerec->action == 'upload' || $filerec->action == 'modify') {
            foreach ($userdatarecs as $userdata) {
                if ($userdata->uploadid == $filerec->uploadid) {
                    $userdata_datefrom = strtotime($userdata->date_from);
                    $userdata_dateto = strtotime($userdata->date_to);
                    $filerec_datefrom = strtotime($filerec->date_from);
                    if ($filerec_datefrom >= $userdata_datefrom && ($userdata_dateto == $time0 || $filerec_datefrom < $userdata_dateto)) {
                        $remarks .= "\n\t\t\t\t\t\t\t" . '<option>' . $userdata->property . ': ' . $userdata->propvalue . '</option>';
                    }
                }
            }
            if ($remarks != '') {
                $remarks = "\n\t\t\t\t\t\t" . '<select multiple="multiple" style="width:100%; height:40px; background:none; font-size:small;">' . $remarks;
                $remarks .= "\n\t\t\t\t\t\t" . '</select>';
            }
        } elseif ($filerec->action == 'other') {
            $info = $filerec->filepath;
            $filerec->filepath = '';
            $remarks = "\n\t\t\t\t\t\t" . '<textarea style="width:100%; resize:vertical; background:none;" readonly="readonly">' . $info . '</textarea>';
        }
        $i++;
        $otheraction = $filerec->action == 'other';
        $echo_str .= "\n\t\t\t\t" . '<tr>';
        $echo_str .= "\n\t\t\t\t\t" . '<td style="padding: 5px 5px 5px 10px; text-align:center;">' . $i . '</td>';
        $echo_str .= "\n\t\t\t\t\t" . '<td style="padding: 5px 5px 5px 10px; text-align:left;">' . $filerec->date_from . '</td>';
        $echo_str .= "\n\t\t\t\t\t" . '<td style="padding: 5px 5px 5px 10px; text-align:center;">' . $filerec->action . '</td>';
        if (!$otheraction) {
            $echo_str .= "\n\t\t\t\t\t" . '<td style="padding: 5px 5px 5px 10px; text-align:left;">';
            if (in_array($filerec->linkedto, $deletedfiles) || in_array($filerec->idlog, $deletedfiles)) {
                $echo_str .= "\n\t\t\t\t\t\t" . '<span>' . $filerec->filepath . '</span>';
            } else {
                $lid = 0;
                if ($filerec->action == 'upload' || $filerec->action == 'include') {
                    $lid = $filerec->idlog;
                } elseif ($filerec->linkedto > 0) {
                    $lid = $filerec->linkedto;
                }
                if ($lid > 0) {
                    if (!isset($filecodes[$lid])) {
                        $filecodes[$lid] = wfu_safe_store_filepath($filerec->filepath);
                    }
                    $echo_str .= "\n\t\t\t\t\t\t" . '<a class="row-title" href="' . $siteurl . '/wp-admin/options-general.php?page=wordpress_file_upload&action=file_details&file=' . $filecodes[$lid] . '" title="View and edit file details" style="font-weight:normal;">' . $filerec->filepath . '</a>';
                } else {
                    $echo_str .= "\n\t\t\t\t\t\t" . '<span>' . $filerec->filepath . '</span>';
                }
            }
            $echo_str .= "\n\t\t\t\t\t" . '</td>';
            $echo_str .= "\n\t\t\t\t\t" . '<td style="padding: 5px 5px 5px 10px; text-align:center;">' . wfu_get_username_by_id($filerec->userid) . '</td>';
        }
        $echo_str .= "\n\t\t\t\t\t" . '<td style="padding: 5px 5px 5px 10px; text-align:left;"' . ($otheraction ? ' colspan="3"' : '') . '>';
        $echo_str .= $remarks;
        $echo_str .= "\n\t\t\t\t\t" . '</td>';
        $echo_str .= "\n\t\t\t\t" . '</tr>';
    }
    if (!$only_table_rows) {
        $echo_str .= "\n\t\t\t" . '</tbody>';
        $echo_str .= "\n\t\t" . '</table>';
        $echo_str .= "\n\t" . '</div>';
        $echo_str .= "\n" . '</div>';
    }
    return $echo_str;
}
Пример #6
0
function wfu_prepare_message_block_skeleton($sid, $styles, $test)
{
    /* Prepare header styles for all upload states */
    $header_styles["State0"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE0"));
    $header_styles["State0"]['message'] = WFU_UPLOAD_STATE0;
    $header_styles["State1"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE1"));
    $header_styles["State1"]['message'] = WFU_UPLOAD_STATE1;
    $header_styles["State2"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE2"));
    $header_styles["State2"]['message'] = WFU_UPLOAD_STATE2;
    $header_styles["State3"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE3"));
    $header_styles["State3"]['message'] = WFU_UPLOAD_STATE3;
    $header_styles["State4"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE4"));
    $header_styles["State4"]['message'] = WFU_UPLOAD_STATE4;
    $header_styles["State5"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE5"));
    $header_styles["State5"]['message'] = WFU_UPLOAD_STATE5;
    $header_styles["State5_singlefile"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE5"));
    $header_styles["State5_singlefile"]['message'] = WFU_UPLOAD_STATE5_SINGLEFILE;
    $header_styles["State6"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE6"));
    $header_styles["State6"]['message'] = WFU_UPLOAD_STATE6;
    $header_styles["State7"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE7"));
    $header_styles["State7"]['message'] = WFU_UPLOAD_STATE7;
    $header_styles["State7_singlefile"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE7"));
    $header_styles["State7_singlefile"]['message'] = WFU_UPLOAD_STATE7_SINGLEFILE;
    $header_styles["State8"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE8"));
    $header_styles["State8"]['message'] = WFU_UPLOAD_STATE8;
    $header_styles["State9"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE9"));
    $header_styles["State9"]['message'] = WFU_UPLOAD_STATE9;
    $header_styles["State10"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE10"));
    $header_styles["State10"]['message'] = WFU_UPLOAD_STATE10;
    $header_styles["State11"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE11"));
    $header_styles["State11"]['message'] = WFU_UPLOAD_STATE11;
    $header_styles["State12"] = wfu_prepare_message_colors(WFU_VAR("WFU_HEADERMESSAGECOLORS_STATE12"));
    $header_styles["State12"]['message'] = WFU_UPLOAD_STATE12;
    $ExposedStateIndex = array("0", "1", "2", "3", "4", "5", "5_singlefile", "6", "7", "7_singlefile", "8", "11", "12");
    /* set general variables */
    $messageblock_main = 'wfu_messageblock_' . $sid;
    $messageblock_header = 'wfu_messageblock_header_' . $sid;
    $messageblock_arrow = 'wfu_messageblock_arrow_' . $sid;
    $messageblock_subheader = 'wfu_messageblock_subheader_' . $sid;
    $dlp = "\n\t\t\t\t\t\t\t";
    /* Prepare header HTML template
    	   Variables:
    		[header_safe]: suffix having the value "_safe" in case of State10 upload state, or empty otherwise,
    		[header_color]: text color of header,
    		[header_bgcolor]: background color of header,
    		[header_borcolor]: border color of header,
    		[header_message]: text shown in header */
    $i = 1;
    $messageblock_headers[$i++] = "\t\t\t" . '<div id="' . $messageblock_header . '[header_safe]" class="file_messageblock_header" style="color:[header_color]; background-color:[header_bgcolor]; border:1px solid [header_borcolor];">';
    $messageblock_headers[$i++] = "\t\t\t\t" . '<label id="' . $messageblock_header . '_label[header_safe]" class="file_messageblock_header_label">[header_message]</label>';
    $messageblock_headers[$i++] = "\t\t\t" . '</div>';
    /* Prepare the file block HTML template
    	   Variables:
    		[file_id]: replaced by the id of the file (1, 2, ...),
    		[filenumber_display]: display:none if single file upload, otherwise empty,
    		[fileheader_color], [fileheader_bgcolor], [fileheader_borcolor], [fileheader_message]: replaced by the returned values,
    		[filesubheadermessage_display]: display:none if there is no message, otherwise empty,
    		[filesubheader_message]: replaced by the returned value,
    		[filesubheaderadminmessage_display]: display:none if there is no admin message, otherwise empty,
    		[filesubheader_adminmessage]: replaced by the returned value */
    /* Prepare the files header block HTML template */
    $i = 1;
    $file_count = $test ? 2 : 1;
    for ($ii = 1; $ii <= $file_count; $ii++) {
        if ($test) {
            $file_props = wfu_prepare_message_colors(WFU_VAR("WFU_TESTMESSAGECOLORS"));
            $file_id = $ii;
            $filenumber_display = "";
            $fileheader_color = $file_props['color'];
            $fileheader_bgcolor = $file_props['bgcolor'];
            $fileheader_borcolor = $file_props['borcolor'];
            $fileheader_message = constant('WFU_TESTMESSAGE_FILE' . $ii . '_HEADER');
            $filesubheadermessage_display = "";
            $filesubheader_message = constant('WFU_TESTMESSAGE_FILE' . $ii . '_MESSAGE');
            $filesubheaderadminmessage_display = "";
            $filesubheader_adminmessage = constant('WFU_TESTMESSAGE_FILE' . $ii . '_ADMINMESSAGE');
        } else {
            $file_id = '[file_id]';
            $filenumber_display = '[filenumber_display]';
            $fileheader_color = '[fileheader_color]';
            $fileheader_bgcolor = '[fileheader_bgcolor]';
            $fileheader_borcolor = '[fileheader_borcolor]';
            $fileheader_message = '[fileheader_message]';
            $filesubheadermessage_display = '[filesubheadermessage_display]';
            $filesubheader_message = '[filesubheader_message]';
            $filesubheaderadminmessage_display = '[filesubheaderadminmessage_display]';
            $filesubheader_adminmessage = '[filesubheader_adminmessage]';
        }
        $messageblock_file[$i++] = "\t" . '<tr id="' . $messageblock_main . '_' . $file_id . '" class="file_messageblock_fileheader_tr" style="display:none;">';
        $messageblock_file[$i++] = "\t\t" . '<td id="' . $messageblock_main . '_filenumber_' . $file_id . '" class="file_messageblock_filenumber_td"' . $filenumber_display . '>' . $file_id . '</td>';
        $messageblock_file[$i++] = "\t\t" . '<td id="' . $messageblock_header . '_container_' . $file_id . '" class="file_messageblock_fileheader_td">';
        $messageblock_file[$i++] = "\t\t\t" . '<div id="' . $messageblock_header . '_' . $file_id . '" class="file_messageblock_fileheader" style="color:' . $fileheader_color . '; background-color:' . $fileheader_bgcolor . '; border:1px solid ' . $fileheader_borcolor . ';">';
        $messageblock_file[$i++] = "\t\t\t\t" . '<label id="' . $messageblock_header . '_label_' . $file_id . '" class="file_messageblock_fileheader_label">' . $fileheader_message . '</label>';
        /* The following hidden input holds state of arrow (open or close) */
        $messageblock_file[$i++] = "\t\t\t\t" . '<input id="' . $messageblock_header . '_state_' . $file_id . '" type="hidden" value="none" />';
        $messageblock_file[$i++] = "\t\t\t" . '</div>';
        $messageblock_file[$i++] = "\t\t" . '</td>';
        /* Add a drop down arrow to the file header (file has always details to be shown) */
        $messageblock_file[$i++] = "\t\t" . '<td id="' . $messageblock_arrow . '_' . $file_id . '" class="file_messageblock_filearrow_td" onclick="wfu_filedetails_toggle(' . $sid . ', ' . $file_id . ');">';
        $messageblock_file[$i++] = "\t\t\t" . '<div id="' . $messageblock_arrow . '_up_' . $file_id . '" class="file_messageblock_file_arrow_up" style="display:none;"></div>';
        $messageblock_file[$i++] = "\t\t\t" . '<div id="' . $messageblock_arrow . '_down_' . $file_id . '" class="file_messageblock_file_arrow_down"></div>';
        $messageblock_file[$i++] = "\t\t" . '</td>';
        $messageblock_file[$i++] = "\t" . '</tr>';
        /* Prepare the files subheader block HTML template */
        $messageblock_file[$i++] = "\t" . '<tr id="' . $messageblock_subheader . '_' . $file_id . '" class="file_messageblock_filesubheader_tr" style="display:none;">';
        $messageblock_file[$i++] = "\t\t" . '<td id="' . $messageblock_subheader . '_fileempty_' . $file_id . '" class="file_messageblock_filesubheaderempty_td"' . $filenumber_display . '></td>';
        $messageblock_file[$i++] = "\t\t" . '<td colspan="2" id="' . $messageblock_subheader . '_container_' . $file_id . '" class="file_messageblock_filesubheader_td">';
        $messageblock_file[$i++] = "\t\t\t" . '<div id="' . $messageblock_subheader . '_message_' . $file_id . '" class="file_messageblock_filesubheader_message"' . $filesubheadermessage_display . '>';
        $messageblock_file[$i++] = "\t\t\t\t" . '<label id="' . $messageblock_subheader . '_messagelabel_' . $file_id . '" class="file_messageblock_filesubheader_messagelabel">' . $filesubheader_message . '</label>';
        $messageblock_file[$i++] = "\t\t\t" . '</div>';
        $messageblock_file[$i++] = "\t\t\t" . '<div id="' . $messageblock_subheader . '_adminmessage_' . $file_id . '" class="file_messageblock_filesubheader_adminmessage"' . $filesubheaderadminmessage_display . '>';
        $messageblock_file[$i++] = "\t\t\t\t" . '<label id="' . $messageblock_subheader . '_adminmessagelabel_' . $file_id . '" class="file_messageblock_filesubheader_adminmessagelabel">' . $filesubheader_adminmessage . '</label>';
        $messageblock_file[$i++] = "\t\t\t" . '</div>';
        $messageblock_file[$i++] = "\t\t" . '</td>';
        $messageblock_file[$i++] = "\t" . '</tr>';
    }
    /* Construct the main header block HTML text
    	/* Construct the header block HTML text */
    $i = 1;
    $messageblock["msgblock"]["line" . $i++] = '<table id="' . $messageblock_main . '" class="file_messageblock_table"' . $styles . '><tbody>';
    $messageblock["msgblock"]["line" . $i++] = "\t" . '<tr id="' . $messageblock_header . '" class="file_messageblock_header_tr"' . ($test ? '' : ' style="display:none;"') . '>';
    $messageblock["msgblock"]["line" . $i++] = "\t\t" . '<td colspan="2" id="' . $messageblock_header . '_container" class="file_messageblock_header_td">';
    /* Inside this td element the appropriate upload state HTML block is going to be inserted using Javascript 
       If the plugin is in test mode, then State9 HTML block is inserted now */
    if ($test) {
        foreach ($messageblock_headers as $messageblock_header_part) {
            $messageblock["msgblock"]["line" . $i++] = strtr($messageblock_header_part, array("[header_safe]" => "", "[header_color]" => $header_styles["State9"]["color"], "[header_bgcolor]" => $header_styles["State9"]["bgcolor"], "[header_borcolor]" => $header_styles["State9"]["borcolor"], "[header_message]" => $header_styles["State9"]["message"]));
        }
    }
    $messageblock["msgblock"]["line" . $i++] = "\t\t" . '</td>';
    /* Add a drop down arrow to the header */
    $messageblock["msgblock"]["line" . $i++] = "\t\t" . '<td id="' . $messageblock_arrow . '" class="file_messageblock_arrow_td"' . ($test ? '' : ' style="display:none;"') . ' onclick="wfu_headerdetails_toggle(' . $sid . ');">';
    $messageblock["msgblock"]["line" . $i++] = "\t\t\t" . '<input id="' . $messageblock_header . '_state" type="hidden" value="none" />';
    $messageblock["msgblock"]["line" . $i++] = "\t\t\t" . '<div id="' . $messageblock_arrow . '_up" class="file_messageblock_header_arrow_up" style="display:none;"></div>';
    $messageblock["msgblock"]["line" . $i++] = "\t\t\t" . '<div id="' . $messageblock_arrow . '_down" class="file_messageblock_header_arrow_down"></div>';
    $messageblock["msgblock"]["line" . $i++] = "\t\t" . '</td>';
    $messageblock["msgblock"]["line" . $i++] = "\t" . '</tr>';
    /* Construct the subheader block HTML text if exists */
    $messageblock["msgblock"]["line" . $i++] = "\t" . '<tr id="' . $messageblock_subheader . '" class="file_messageblock_subheader_tr" style="display:none;">';
    $messageblock["msgblock"]["line" . $i++] = "\t\t" . '<td colspan="3" id="' . $messageblock_subheader . '_td" class="file_messageblock_subheader_td">';
    $messageblock["msgblock"]["line" . $i++] = "\t\t\t" . '<div id="' . $messageblock_subheader . '_message" class="file_messageblock_subheader_message"' . ($test ? '' : ' style="display:none;"') . '>';
    $messageblock["msgblock"]["line" . $i++] = "\t\t\t\t" . '<label id="' . $messageblock_subheader . '_messagelabel" class="file_messageblock_subheader_messagelabel">' . ($test ? WFU_TESTMESSAGE_MESSAGE : '') . '</label>';
    $messageblock["msgblock"]["line" . $i++] = "\t\t\t" . '</div>';
    $messageblock["msgblock"]["line" . $i++] = "\t\t\t" . '<div id="' . $messageblock_subheader . '_adminmessage" class="file_messageblock_subheader_adminmessage"' . ($test ? '' : ' style="display:none;"') . '>';
    $messageblock["msgblock"]["line" . $i++] = "\t\t\t\t" . '<label id="' . $messageblock_subheader . '_adminmessagelabel" class="file_messageblock_subheader_adminmessagelabel">' . ($test ? WFU_TESTMESSAGE_ADMINMESSAGE : '') . '</label>';
    $messageblock["msgblock"]["line" . $i++] = "\t\t\t" . '</div>';
    $messageblock["msgblock"]["line" . $i++] = "\t\t" . '</td>';
    $messageblock["msgblock"]["line" . $i++] = "\t" . '</tr>';
    /* After the above tr the file blocks are appended by Javascript dynamically as additional tr elements
       If the plugin is in test mode, then two test file blocks are appended now */
    if ($test) {
        foreach ($messageblock_file as $messageblock_file_part) {
            $messageblock["msgblock"]["line" . $i++] = $messageblock_file_part;
        }
    }
    $messageblock["msgblock"]["line" . $i++] = '</tbody></table>';
    /* Construct a div element that will hold the State10 header and use it in case JSON parse fails and upload results cannot be decoded */
    $messageblock["msgblock"]["line" . $i++] = '<div id="' . $messageblock_header . '_safecontainer" style="display:none;">';
    foreach ($messageblock_headers as $messageblock_header_part) {
        $messageblock["msgblock"]["line" . $i++] = strtr($messageblock_header_part, array("[header_safe]" => "_safe", "[header_color]" => $header_styles["State10"]["color"], "[header_bgcolor]" => $header_styles["State10"]["bgcolor"], "[header_borcolor]" => $header_styles["State10"]["borcolor"], "[header_message]" => $header_styles["State10"]["message"]));
    }
    $messageblock["msgblock"]["line" . $i++] = '</div>';
    /* Construct header HTML text for all upload states and save it to hidden input, to be used later on by Javascript to adjust the upload state dynamically */
    $messageblock_header_template = "";
    foreach ($messageblock_headers as $messageblock_header_part) {
        $messageblock_header_template .= $dlp . $messageblock_header_part;
    }
    foreach ($ExposedStateIndex as $ii) {
        $messageblock["header"]["State" . $ii] = strtr($messageblock_header_template, array("[header_safe]" => "", "[header_color]" => $header_styles["State" . $ii]["color"], "[header_bgcolor]" => $header_styles["State" . $ii]["bgcolor"], "[header_borcolor]" => $header_styles["State" . $ii]["borcolor"], "[header_message]" => $header_styles["State" . $ii]["message"]));
    }
    $messageblock_header_str = wfu_encode_array_to_string($messageblock["header"]);
    $messageblock["msgblock"]["line" . $i++] = '<input id="' . $messageblock_header . '_states" type="hidden" value="' . $messageblock_header_str . '" />';
    /* Construct file HTML block template and save it to hidden div to be used later on by Javascript to add file results to the upload message dynamically */
    $messageblock_file_str = "";
    foreach ($messageblock_file as $messageblock_file_part) {
        $messageblock_file_str .= $dlp . $messageblock_file_part;
    }
    $messageblock_file_str = wfu_plugin_encode_string($messageblock_file_str);
    $messageblock["msgblock"]["line" . $i++] = '<input id="' . $messageblock_main . '_filetemplate" type="hidden" value="' . $messageblock_file_str . '" />';
    $messageblock["msgblock"]["line" . $i++] = '<div id="' . $messageblock_main . '_door" style="display:none;"></div>';
    return $messageblock;
}
Пример #7
0
function wfu_view_log()
{
    global $wpdb;
    $siteurl = site_url();
    $table_name1 = $wpdb->prefix . "wfu_log";
    $table_name2 = $wpdb->prefix . "wfu_userdata";
    $plugin_options = wfu_decode_plugin_options(get_option("wordpress_file_upload_options"));
    if (!current_user_can('manage_options')) {
        return;
    }
    $echo_str = "\n" . '<div class="wrap">';
    $echo_str .= "\n\t" . '<h2>Wordpress File Upload Control Panel</h2>';
    $echo_str .= "\n\t" . '<div style="margin-top:20px;">';
    $echo_str .= "\n\t\t" . '<a href="' . $siteurl . '/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=manage_mainmenu" class="button" title="go back">Go to Main Menu</a>';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<h2 style="margin-bottom: 10px; margin-top: 20px;">History Log</h2>';
    $echo_str .= "\n\t" . '<div>';
    $echo_str .= "\n\t\t" . '<table class="widefat">';
    $echo_str .= "\n\t\t\t" . '<thead>';
    $echo_str .= "\n\t\t\t\t" . '<tr>';
    $echo_str .= "\n\t\t\t\t\t" . '<th scope="col" width="5%" style="text-align:center;">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<label>#</label>';
    $echo_str .= "\n\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t\t" . '<th scope="col" width="15%" style="text-align:left;">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<label>Date</label>';
    $echo_str .= "\n\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t\t" . '<th scope="col" width="10%" style="text-align:center;">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<label>Action</label>';
    $echo_str .= "\n\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t\t" . '<th scope="col" width="30%" style="text-align:left;">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<label>File</label>';
    $echo_str .= "\n\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t\t" . '<th scope="col" width="15%" style="text-align:center;">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<label>User</label>';
    $echo_str .= "\n\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t\t" . '<th scope="col" width="25%" style="text-align:left;">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<label>Remarks</label>';
    $echo_str .= "\n\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t" . '</tr>';
    $echo_str .= "\n\t\t\t" . '</thead>';
    $echo_str .= "\n\t\t\t" . '<tbody>';
    $filerecs = $wpdb->get_results('SELECT * FROM ' . $table_name1 . ' ORDER BY date_from DESC');
    $userdatarecs = $wpdb->get_results('SELECT * FROM ' . $table_name2);
    $i = 0;
    foreach ($filerecs as $filerec) {
        $remarks = '';
        $filepath = ABSPATH;
        if (substr($filepath, -1) == '/') {
            $filepath = substr($filepath, 0, -1);
        }
        $filepath .= $filerec->filepath;
        $enc_file = wfu_plugin_encode_string($filepath . '[[name]]');
        if ($filerec->action == 'rename') {
            $prevfilepath = '';
            foreach ($filerecs as $key => $prevfilerec) {
                if ($prevfilerec->idlog == $filerec->linkedto) {
                    $prevfilepath = $prevfilerec->filepath;
                    break;
                }
            }
            if ($prevfilepath != '') {
                $remarks = "\n\t\t\t\t\t\t" . '<label>Previous filepath: ' . $prevfilepath . '</label>';
            }
        } elseif ($filerec->action == 'upload' || $filerec->action == 'modify') {
            foreach ($userdatarecs as $userdata) {
                if ($userdata->uploadid == $filerec->uploadid && $userdata->date_from == $filerec->date_from) {
                    $remarks .= "\n\t\t\t\t\t\t\t" . '<option>' . $userdata->property . ': ' . $userdata->propvalue . '</option>';
                }
            }
            if ($remarks != '') {
                $remarks = "\n\t\t\t\t\t\t" . '<select multiple="multiple" style="width:100%; height:40px; background:none; font-size:small;">' . $remarks;
                $remarks .= "\n\t\t\t\t\t\t" . '</select>';
            }
        } elseif ($filerec->action == 'other') {
            $info = $filerec->filepath;
            $filerec->filepath = '';
            $remarks = "\n\t\t\t\t\t\t" . '<textarea style="width:100%; resize:vertical; background:none;" readonly="readonly">' . $info . '</textarea>';
        }
        $i++;
        $otheraction = $filerec->action == 'other';
        $echo_str .= "\n\t\t\t\t" . '<tr>';
        $echo_str .= "\n\t\t\t\t\t" . '<td style="padding: 5px 5px 5px 10px; text-align:center;">' . $i . '</td>';
        $echo_str .= "\n\t\t\t\t\t" . '<td style="padding: 5px 5px 5px 10px; text-align:left;">' . $filerec->date_from . '</td>';
        $echo_str .= "\n\t\t\t\t\t" . '<td style="padding: 5px 5px 5px 10px; text-align:center;">' . $filerec->action . '</td>';
        if (!$otheraction) {
            $echo_str .= "\n\t\t\t\t\t" . '<td style="padding: 5px 5px 5px 10px; text-align:left;">';
            $echo_str .= "\n\t\t\t\t\t\t" . '<a class="row-title" href="' . $siteurl . '/wp-admin/options-general.php?page=wordpress_file_upload&action=file_details&file=' . $enc_file . '" title="View and edit file details" style="font-weight:normal;">' . $filerec->filepath . '</a>';
            $echo_str .= "\n\t\t\t\t\t" . '</td>';
            $echo_str .= "\n\t\t\t\t\t" . '<td style="padding: 5px 5px 5px 10px; text-align:center;">' . wfu_get_username_by_id($filerec->userid) . '</td>';
        }
        $echo_str .= "\n\t\t\t\t\t" . '<td style="padding: 5px 5px 5px 10px; text-align:left;"' . ($otheraction ? ' colspan="3"' : '') . '>';
        $echo_str .= $remarks;
        $echo_str .= "\n\t\t\t\t\t" . '</td>';
        $echo_str .= "\n\t\t\t\t" . '</tr>';
    }
    $echo_str .= "\n\t\t\t" . '</tbody>';
    $echo_str .= "\n\t\t" . '</table>';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n" . '</div>';
    return $echo_str;
}
Пример #8
0
function wfu_ajax_action_get_historylog_page()
{
    if (!isset($_POST['token']) || !isset($_POST['page'])) {
        die;
    }
    check_ajax_referer('wfu-historylog-page', 'token');
    if (!current_user_can('manage_options')) {
        die;
    }
    if (WFU_HISTORYLOG_TABLE_MAXROWS <= 0) {
        die;
    }
    $page = wfu_sanitize_int($_POST['page']);
    $rows = wfu_view_log($page, true);
    die('wfu_historylog_page_success:' . wfu_plugin_encode_string($rows));
}
Пример #9
0
function wfu_shortcode_composer($data = '', $shortcode_tag = 'wordpress_file_upload')
{
    global $wpdb;
    global $wp_roles;
    $siteurl = site_url();
    $components = wfu_component_definitions();
    if ($shortcode_tag == 'wordpress_file_upload') {
        $plugin_title = "Uploader";
        $cats = wfu_category_definitions();
        $defs = wfu_attribute_definitions();
    } else {
        $plugin_title = "Browser";
        $cats = wfu_browser_category_definitions();
        $defs = wfu_browser_attribute_definitions();
    }
    $plugin_options = wfu_decode_plugin_options(get_option("wordpress_file_upload_options"));
    if ($data == "") {
        $shortcode = $plugin_options['shortcode'];
        $shortcode_full = '[' . $shortcode_tag . ' ' . $shortcode . ']';
        $postid = "";
        $postname = "";
        $posttype = "";
        $posthash = "";
        $shortcode_position = -1;
        $widgetid = "";
        $sidebar = "";
        $autosave = true;
    } else {
        $shortcode = trim(substr($data['shortcode'], strlen('[' . $shortcode_tag), -1));
        $shortcode_full = $data['shortcode'];
        $postid = $data['post_id'];
        $postname = get_the_title($postid);
        $posttype_obj = get_post_type_object(get_post_type($postid));
        $posttype = $posttype_obj ? $posttype_obj->labels->singular_name : "";
        $posthash = $data['post_hash'];
        $shortcode_position = $data['position'];
        $widgetid = isset($data['widgetid']) ? $data['widgetid'] : "";
        $sidebar = isset($data['sidebar']) ? $data['sidebar'] : "";
        $autosave = false;
    }
    // index $components
    $components_indexed = array();
    foreach ($components as $component) {
        $components_indexed[$component['id']] = $component;
    }
    // complete defs array and index dependencies
    $governors = array();
    $shortcode_attrs = wfu_shortcode_string_to_array($shortcode);
    $shortcode_id = '';
    foreach ($defs as $key => $def) {
        $attr = $def['attribute'];
        $defs[$key]['default'] = $def['value'];
        if (array_key_exists($attr, $shortcode_attrs)) {
            $defs[$key]['value'] = $shortcode_attrs[$attr];
        }
        $subblock_active = false;
        //detect if the dependencies of this attribute will be disabled or not
        if ($def['type'] == "onoff" && $defs[$key]['value'] == "true" || $def['type'] == "radio" && in_array("*" . $defs[$key]['value'], $def['listitems'])) {
            $subblock_active = true;
        }
        // assign dependencies if exist
        if ($def['dependencies'] != null) {
            foreach ($def['dependencies'] as $dependency) {
                if (substr($dependency, 0, 1) == "!") {
                    //invert state for this dependency if an exclamation mark is defined
                    $governors[substr($dependency, 1)] = array('attribute' => $attr, 'active' => !$subblock_active, 'inv' => '_inv');
                } else {
                    $governors[$dependency] = array('attribute' => $attr, 'active' => $subblock_active, 'inv' => '');
                }
            }
        }
        if ($attr == 'uploadid' || $attr == 'browserid') {
            $shortcode_id = $defs[$key]['value'];
        }
    }
    //check if attributes need to be generated more than once because their governor is a component field that appears more than once in placements attribute
    $key = 0;
    while ($key < count($defs)) {
        $defs[$key]['additional_values'] = array();
        $def = $defs[$key];
        $attr = $def['attribute'];
        //check if this attribute needs to be generated more than once
        if (array_key_exists($attr, $governors)) {
            $governor = $governors[$attr]['attribute'];
        } else {
            $governor = "";
        }
        if ($governor != "" && isset($components_indexed[$governor]) && $components_indexed[$governor]['multiplacements'] && isset($shortcode_attrs['placements'])) {
            //count how many occurrences of the governor attribute appear inside placements attribute
            $occurrences = 0;
            $sections = explode("/", $shortcode_attrs['placements']);
            foreach ($sections as $section) {
                $items_in_section = explode("+", trim($section));
                foreach ($items_in_section as $item) {
                    if (trim($item) == $governor) {
                        $occurrences++;
                    }
                }
            }
            //add indexed attributes if there is more than one occurrence
            for ($ii = 2; $ii <= $occurrences; $ii++) {
                $def2 = $def;
                $def2['attribute'] .= $ii;
                $def2['name'] .= ' (' . $ii . ')';
                if (array_key_exists($def2['attribute'], $shortcode_attrs)) {
                    $def2['value'] = $shortcode_attrs[$def2['attribute']];
                } else {
                    $def2['value'] = $def2['default'];
                }
                array_splice($defs, $key + 1, 0, array($def2));
                $key++;
            }
            //check if the shortcode contains additional indexed definitions and store them in 'additional_values'
            $ii = max(1, $occurrences) + 1;
            while (array_key_exists($attr . $ii, $shortcode_attrs)) {
                $defs[$key]['additional_values'][$ii] = $shortcode_attrs[$attr . $ii];
                $ii++;
            }
        }
        $key++;
    }
    $echo_str = '<div id="wfu_wrapper" class="wrap">';
    $echo_str .= "\n\t" . '<h2>Wordpress File Upload Control Panel</h2>';
    $echo_str .= "\n\t" . '<div id="wfu_page_obsolete_message" class="error" style="display:none;">';
    $echo_str .= "\n\t\t" . '<p>' . WFU_DASHBOARD_PAGE_OBSOLETE . '</p>';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<div id="wfu_update_rejected_message" class="error" style="display:none;">';
    $echo_str .= "\n\t\t" . '<p>' . WFU_DASHBOARD_UPDATE_SHORTCODE_REJECTED . '</p>';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<div id="wfu_update_failed_message" class="error" style="display:none;">';
    $echo_str .= "\n\t\t" . '<p>' . WFU_DASHBOARD_UPDATE_SHORTCODE_FAILED . '</p>';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<div style="margin-top:20px;">';
    if (current_user_can('manage_options')) {
        $echo_str .= "\n\t" . '<a href="' . $siteurl . '/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=manage_mainmenu" class="button" title="go back">Go to Main Menu</a>';
    }
    $echo_str .= "\n\t" . '</div>';
    if ($widgetid == "") {
        $echo_str .= "\n\t" . '<h2 style="margin-bottom: 10px; margin-top: 20px;">' . ($data == "" ? 'Test' : $posttype . ' <strong>' . $postname . '</strong>') . ': Shortcode Composer for ' . $plugin_title . ' <strong>ID ' . $shortcode_id . '</strong></h2>';
    } else {
        $echo_str .= "\n\t" . '<h2 style="margin-bottom: 10px; margin-top: 20px;">Sidebar <strong>' . $sidebar . '</strong>: Shortcode Composer for Uploader <strong>ID ' . $shortcode_id . '</strong></h2>';
    }
    $echo_str .= "\n\t" . '<div style="margin-top:10px; display:inline-block;">';
    if ($data != "") {
        $echo_str .= "\n\t\t" . '<input id="wfu_update_shortcode" type="button" value="Update" class="button-primary" disabled="disabled" onclick="wfu_save_shortcode()" /><span id="wfu_update_shortcode_wait" class="spinner" style="float:right; display:none;"></span>';
    }
    $echo_str .= "\n\t\t" . '<input id="wfu_shortcode_original_enc" type="hidden" value="' . wfu_plugin_encode_string($shortcode_full) . '" />';
    $echo_str .= "\n\t\t" . '<input id="wfu_shortcode_tag" type="hidden" value="' . $shortcode_tag . '" />';
    $echo_str .= "\n\t\t" . '<input id="wfu_shortcode_postid" type="hidden" value="' . $postid . '" />';
    $echo_str .= "\n\t\t" . '<input id="wfu_shortcode_posthash" type="hidden" value="' . $posthash . '" />';
    $echo_str .= "\n\t\t" . '<input id="wfu_shortcode_position" type="hidden" value="' . $shortcode_position . '" />';
    $echo_str .= "\n\t\t" . '<input id="wfu_shortcode_widgetid" type="hidden" value="' . $widgetid . '" />';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<div style="margin-top:20px;">';
    $echo_str .= "\n\t\t" . '<div class="wfu_shortcode_container">';
    $echo_str .= "\n\t\t\t" . '<span><strong>Generated Shortcode</strong></span>';
    $echo_str .= "\n\t\t\t" . '<span id="wfu_save_label" class="wfu_save_label">saved</span>';
    $echo_str .= "\n\t\t\t" . '<textarea id="wfu_shortcode" class="wfu_shortcode" rows="5">[' . $shortcode_tag . ']</textarea>';
    $echo_str .= "\n\t\t\t" . '<div id="wfu_attribute_defaults" style="display:none;">';
    // remove hidden attributes from defs array
    foreach ($defs as $key => $def) {
        if ($def['type'] == "hidden") {
            unset($defs[$key]);
        }
    }
    foreach ($defs as $def) {
        $echo_str .= "\n\t\t\t\t" . '<input id="wfu_attribute_default_' . $def['attribute'] . '" type="hidden" value="' . $def['default'] . '" />';
    }
    $echo_str .= "\n\t\t\t" . '</div>';
    $echo_str .= "\n\t\t\t" . '<div id="wfu_attribute_values" style="display:none;">';
    foreach ($defs as $def) {
        $echo_str .= "\n\t\t\t\t" . '<input id="wfu_attribute_value_' . $def['attribute'] . '" type="hidden" value="' . $def['value'] . '" />';
        //add additional values, if exist
        foreach ($def['additional_values'] as $key => $val) {
            $echo_str .= "\n\t\t\t\t" . '<input id="wfu_attribute_value_' . $def['attribute'] . $key . '" type="hidden" value="' . $val . '" />';
        }
    }
    $echo_str .= "\n\t\t\t" . '</div>';
    $echo_str .= "\n\t\t" . '</div>';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<h3 id="wfu_tab_container" class="nav-tab-wrapper">';
    $is_first = true;
    foreach ($cats as $key => $cat) {
        $echo_str .= "\n\t\t" . '<a id="wfu_tab_' . $key . '" class="nav-tab' . ($is_first ? ' nav-tab-active' : '') . '" href="javascript: wfu_admin_activate_tab(\'' . $key . '\');">' . $cat . '</a>';
        $is_first = false;
    }
    $echo_str .= "\n\t" . '</h3>';
    $prevcat = "";
    $prevsubcat = "";
    $is_first = true;
    $block_open = false;
    $subblock_open = false;
    foreach ($defs as $def) {
        $attr = $def['attribute'];
        //check if this attribute depends on other
        if (!array_key_exists($attr, $governors)) {
            $governors[$attr] = "";
        }
        if ($governors[$attr] != "") {
            $governor = $governors[$attr];
        } else {
            $governor = array('attribute' => "independent", 'active' => true, 'inv' => '');
        }
        //close previous blocks
        if ($def['parent'] == "") {
            if ($subblock_open) {
                $echo_str .= "\n\t\t\t\t\t\t\t" . '</tbody>';
                $echo_str .= "\n\t\t\t\t\t\t" . '</table>';
                $subblock_open = false;
            }
            if ($block_open) {
                $echo_str .= "\n\t\t\t\t\t" . '</div></td>';
                $echo_str .= "\n\t\t\t\t" . '</tr>';
                $block_open = false;
            }
        }
        //check if new category must be generated
        if ($def['category'] != $prevcat) {
            if ($prevcat != "") {
                $echo_str .= "\n\t\t\t" . '</tbody>';
                $echo_str .= "\n\t\t" . '</table>';
                $echo_str .= "\n\t" . '</div>';
            }
            $prevcat = $def['category'];
            $prevsubcat = "";
            $echo_str .= "\n\t" . '<div id="wfu_container_' . $prevcat . '" class="wfu_container"' . ($is_first ? '' : ' style="display:none;"') . '">';
            $echo_str .= "\n\t\t" . '<table class="form-table wfu_main_table">';
            $echo_str .= "\n\t\t\t" . '<thead><tr><th></th><td></td><td></td></tr></thead>';
            $echo_str .= "\n\t\t\t" . '<tbody>';
            $is_first = false;
        }
        //check if new sub-category must be generated
        if ($def['subcategory'] != $prevsubcat) {
            $prevsubcat = $def['subcategory'];
            $echo_str .= "\n\t\t\t\t" . '<tr class="wfu_subcategory">';
            $echo_str .= "\n\t\t\t\t\t" . '<th scope="row" colspan="3">';
            $echo_str .= "\n\t\t\t\t\t\t" . '<h3 style="margin-bottom: 10px; margin-top: 10px;">' . $prevsubcat . '</h3>';
            $echo_str .= "\n\t\t\t\t\t" . '</th>';
            $echo_str .= "\n\t\t\t\t" . '</tr>';
        }
        //draw attribute element
        if ($def['parent'] == "") {
            $dlp = "\n\t\t\t\t";
        } else {
            if (!$subblock_open) {
                $echo_str .= "\n\t\t\t\t\t\t" . '<div class="wfu_shadow wfu_shadow_' . $def['parent'] . $governor['inv'] . '" style="display:' . ($governor['active'] ? 'none' : 'block') . ';"></div>';
                $echo_str .= "\n\t\t\t\t\t\t" . '<table class="form-table wfu_inner_table" style="margin:0;">';
                $echo_str .= "\n\t\t\t\t\t\t\t" . '<tbody>';
            }
            $dlp = "\n\t\t\t\t\t\t\t\t";
        }
        $echo_str .= $dlp . '<tr>';
        $echo_str .= $dlp . "\t" . '<th scope="row"><div class="wfu_td_div">';
        if ($def['parent'] == "") {
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_shadow wfu_shadow_' . $governor['attribute'] . $governor['inv'] . '" style="display:' . ($governor['active'] ? 'none' : 'block') . ';"></div>';
        }
        $echo_str .= $dlp . "\t\t" . '<div class="wfu_restore_container" title="Double-click to restore defaults setting"><img src="' . WFU_IMAGE_ADMIN_RESTOREDEFAULT . '" ondblclick="wfu_apply_value(\'' . $attr . '\', \'' . $def['type'] . '\', \'' . $def['default'] . '\');" /></div>';
        $echo_str .= $dlp . "\t\t" . '<label for="wfu_attribute_' . $attr . '">' . $def['name'] . '</label>';
        $echo_str .= $dlp . "\t\t" . '<input type="hidden" name="wfu_attribute_governor_' . $governor['attribute'] . '" class="wfu_attribute_governor" value="' . $attr . '" />';
        $echo_str .= $dlp . "\t\t" . '<div class="wfu_help_container" title="' . $def['help'] . '"><img src="' . WFU_IMAGE_ADMIN_HELP . '" /></div>';
        $echo_str .= $dlp . "\t" . '</div></th>';
        $echo_str .= $dlp . "\t" . '<td style="vertical-align:top;"><div class="wfu_td_div">';
        if ($def['parent'] == "") {
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_shadow wfu_shadow_' . $governor['attribute'] . $governor['inv'] . '" style="display:' . ($governor['active'] ? 'none' : 'block') . ';"></div>';
        }
        if ($def['type'] == "onoff") {
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_attribute_' . $attr . '" class="wfu_onoff_container_' . ($def['value'] == "true" ? "on" : "off") . '" onclick="wfu_admin_onoff_clicked(\'' . $attr . '\');">';
            $echo_str .= $dlp . "\t\t\t" . '<div class="wfu_onoff_slider"></div>';
            $echo_str .= $dlp . "\t\t\t" . '<span class="wfu_onoff_text">ON</span>';
            $echo_str .= $dlp . "\t\t\t" . '<span class="wfu_onoff_text">OFF</span>';
            $echo_str .= $dlp . "\t\t" . '</div>';
        } elseif ($def['type'] == "text") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="text" name="wfu_text_elements" value="' . $val . '" />';
            if ($def['variables'] != null) {
                $echo_str .= $dlp . wfu_insert_variables($def['variables'], 'wfu_variable wfu_variable_' . $attr);
            }
        } elseif ($def['type'] == "placements") {
            $components_used = array();
            foreach ($components as $component) {
                $components_used[$component['id']] = 0;
            }
            $centered_content = '<div class="wfu_component_box_inner"><div class="wfu_component_box_label">XXX</div></div>';
            $centered_content_multi = '<div class="wfu_component_box_inner"><div class="wfu_component_box_label">XXX</div><div class="wfu_component_box_index">YYY</div></div>';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_placements_wrapper">';
            $echo_str .= $dlp . "\t\t\t" . '<div id="wfu_placements_container" class="wfu_placements_container">';
            $itemplaces = explode("/", $def['value']);
            foreach ($itemplaces as $section) {
                $echo_str .= $dlp . "\t\t\t\t" . '<div class="wfu_component_separator_hor"></div>';
                $echo_str .= $dlp . "\t\t\t\t" . '<div class="wfu_component_separator_ver"></div>';
                $items_in_section = explode("+", trim($section));
                $section_array = array();
                foreach ($items_in_section as $item_in_section) {
                    if (key_exists($item_in_section, $components_indexed)) {
                        if ($components_indexed[$item_in_section]['multiplacements'] || $components_used[$item_in_section] == 0) {
                            $components_used[$item_in_section]++;
                            if ($components_indexed[$item_in_section]['multiplacements']) {
                                $multi_index = $components_used[$item_in_section];
                                $echo_str .= $dlp . "\t\t\t\t" . '<div id="wfu_component_box_' . $item_in_section . '_' . $multi_index . '" class="wfu_component_box" draggable="true" title="' . $components_indexed[$item_in_section]['help'] . '">' . str_replace(array("XXX", "YYY"), array($components_indexed[$item_in_section]['name'], $multi_index), $centered_content_multi) . '</div>';
                            } else {
                                $echo_str .= $dlp . "\t\t\t\t" . '<div id="wfu_component_box_' . $item_in_section . '_0" class="wfu_component_box" draggable="true" title="' . $components_indexed[$item_in_section]['help'] . '">' . str_replace("XXX", $components_indexed[$item_in_section]['name'], $centered_content) . '</div>';
                            }
                            $echo_str .= $dlp . "\t\t\t\t" . '<div class="wfu_component_separator_ver"></div>';
                        }
                    }
                }
            }
            $echo_str .= $dlp . "\t\t\t\t" . '<div class="wfu_component_separator_hor"></div>';
            $echo_str .= $dlp . "\t\t\t\t" . '<div id="wfu_component_bar_hor" class="wfu_component_bar_hor"></div>';
            $echo_str .= $dlp . "\t\t\t\t" . '<div id="wfu_component_bar_ver" class="wfu_component_bar_ver"></div>';
            $echo_str .= $dlp . "\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t\t" . '<div id="wfu_componentlist_container" class="wfu_componentlist_container">';
            $echo_str .= $dlp . "\t\t\t\t" . '<div id="wfu_componentlist_dragdrop" class="wfu_componentlist_dragdrop" style="display:none;"></div>';
            $ii = 1;
            foreach ($components as $component) {
                $echo_str .= $dlp . "\t\t\t\t" . '<div id="wfu_component_box_container_' . $component['id'] . '" class="wfu_component_box_container">';
                $echo_str .= $dlp . "\t\t\t\t\t" . '<div class="wfu_component_box_base">' . str_replace("XXX", $component['name'], $centered_content) . '</div>';
                if ($component['multiplacements']) {
                    $multi_index = $components_used[$component['id']] + 1;
                    $echo_str .= $dlp . "\t\t\t\t\t" . '<div id="wfu_component_box_' . $component['id'] . '_' . $multi_index . '" class="wfu_component_box wfu_inbase" draggable="true" title="' . $component['help'] . '">' . str_replace(array("XXX", "YYY"), array($component['name'], $multi_index), $centered_content_multi) . '</div>';
                } elseif ($components_used[$component['id']] == 0) {
                    $echo_str .= $dlp . "\t\t\t\t\t" . '<div id="wfu_component_box_' . $component['id'] . '_0" class="wfu_component_box wfu_inbase" draggable="true" title="' . $component['help'] . '">' . str_replace("XXX", $component['name'], $centered_content) . '</div>';
                }
                $echo_str .= $dlp . "\t\t\t\t" . '</div>' . ($ii++ % 3 == 0 ? '<br />' : '');
            }
            $echo_str .= $dlp . "\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t" . '</div>';
        } elseif ($def['type'] == "ltext") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="text" name="wfu_text_elements" class="wfu_long_text" value="' . $val . '" />';
            if ($def['variables'] != null) {
                $echo_str .= $dlp . wfu_insert_variables($def['variables'], 'wfu_variable wfu_variable_' . $attr);
            }
        } elseif ($def['type'] == "integer") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="number" name="wfu_text_elements" class="wfu_short_text" min="1" value="' . $val . '" />';
            if (isset($def['listitems']['unit'])) {
                $echo_str .= $dlp . "\t\t" . '<label> ' . $def['listitems']['unit'] . '</label>';
            }
        } elseif ($def['type'] == "float") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="number" name="wfu_text_elements" class="wfu_short_text" step="any" min="0" value="' . $val . '" />';
            if (isset($def['listitems']['unit'])) {
                $echo_str .= $dlp . "\t\t" . '<label> ' . $def['listitems']['unit'] . '</label>';
            }
        } elseif ($def['type'] == "date") {
            $val = $def['value'];
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_date_container"><input id="wfu_attribute_' . $attr . '" type="text" value="' . $val . '" readonly style="padding-right:16px; background-color:white;" /><img class="wfu_datereset_button" src="' . WFU_IMAGE_ADMIN_SUBFOLDER_CANCEL . '" onclick="var f = document.getElementById(\'wfu_attribute_' . $attr . '\'); f.value = \'\'; wfu_update_date_value({target:f});" /></div><label style="font-size:smaller; margin-left:4px;">format: YYYY-MM-DD</label>';
            $echo_str .= wfu_inject_js_code('jQuery(function() {jQuery("#wfu_attribute_' . $attr . '").datepicker({dateFormat: "yy-mm-dd", onClose: function(date, picker) {wfu_update_date_value({target:this});}});});');
        } elseif ($def['type'] == "radio") {
            $echo_str .= $dlp . "\t\t";
            $ii = 0;
            foreach ($def['listitems'] as $item) {
                $echo_str .= '<input name="wfu_radioattribute_' . $attr . '" type="radio" value="' . $item . '" ' . ($item == $def['value'] || $item == "*" . $def['value'] ? 'checked="checked" ' : '') . 'style="width:auto; margin:0px 2px 0px ' . ($ii++ == 0 ? '0px' : '8px') . ';" onchange="wfu_admin_radio_clicked(\'' . $attr . '\');" />' . ($item[0] == "*" ? substr($item, 1) : $item);
            }
            //			$echo_str .= '<input type="button" class="button" value="empty" style="width:auto; margin:-2px 0px 0px 8px;" />';
        } elseif ($def['type'] == "ptext") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $parts = explode("/", $val);
            $singular = $parts[0];
            if (count($parts) < 2) {
                $plural = $singular;
            } else {
                $plural = $parts[1];
            }
            $echo_str .= $dlp . "\t\t" . '<span class="wfu_ptext_span">Singular</span><input id="wfu_attribute_s_' . $attr . '" type="text" name="wfu_ptext_elements" value="' . $singular . '" />';
            if ($def['variables'] != null) {
                if (count($def['variables']) > 0) {
                    $echo_str .= $dlp . "\t\t" . '<br /><span class="wfu_ptext_span">&nbsp;</span>';
                }
            }
            if ($def['variables'] != null) {
                $echo_str .= $dlp . wfu_insert_variables($def['variables'], 'wfu_variable wfu_variable_s_' . $attr);
            }
            $echo_str .= $dlp . "\t\t" . '<br /><span class="wfu_ptext_span">Plural</span><input id="wfu_attribute_p_' . $attr . '" type="text" name="wfu_ptext_elements" value="' . $plural . '" />';
            if ($def['variables'] != null) {
                if (count($def['variables']) > 0) {
                    $echo_str .= $dlp . "\t\t" . '<br /><span class="wfu_ptext_span">&nbsp;</span>';
                }
            }
            if ($def['variables'] != null) {
                $echo_str .= $dlp . wfu_insert_variables($def['variables'], 'wfu_variable wfu_variable_p_' . $attr, $dlp);
            }
        } elseif ($def['type'] == "mtext") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $echo_str .= $dlp . "\t\t" . '<textarea id="wfu_attribute_' . $attr . '" name="wfu_text_elements" rows="5">' . $val . '</textarea>';
            if ($def['variables'] != null) {
                $echo_str .= $dlp . wfu_insert_variables($def['variables'], 'wfu_variable wfu_variable_' . $attr);
            }
        } elseif ($def['type'] == "folderlist") {
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_subfolders_inner_shadow_' . $attr . '" class="wfu_subfolders_inner_shadow" style="display:none;"></div>';
            $subfolders = wfu_parse_folderlist($def['value']);
            $poptitle = "Populate list automatically with the first-level subfolders of the path defined in uploadpath";
            $edittitle = "Allow the user to type the subfolder and filter the list during typing";
            $echo_str .= $dlp . "\t\t" . '<input type="checkbox" id="wfu_subfolders_auto_' . $attr . '"' . (substr($def['value'], 0, 4) == "auto" ? ' checked="checked"' : '') . ' onchange="wfu_subfolders_auto_changed(\'' . $attr . '\');" title="' . $poptitle . '" /><label for="wfu_subfolders_auto_' . $attr . '" title="' . $poptitle . '"> Auto-populate list</label>';
            $echo_str .= $dlp . "\t\t" . '<div style="display:' . (substr($def['value'], 0, 4) == "auto" ? 'inline' : 'none') . '; padding:0; margin:0 0 0 30px; background:none; border:none;"><input type="checkbox" id="wfu_subfolders_editable_' . $attr . '"' . (substr($def['value'], 0, 5) == "auto+" ? ' checked="checked"' : '') . ' onchange="wfu_subfolders_auto_changed(\'' . $attr . '\');" title="' . $edittitle . '" /><label for="wfu_subfolders_editable_' . $attr . '" title="' . $edittitle . '"> List is editable</label></div><br />';
            $echo_str .= $dlp . "\t\t" . '<input type="hidden" id="wfu_subfolders_manualtext_' . $attr . '" value="' . (substr($def['value'], 0, 4) == "auto" ? "" : $def['value']) . '" />';
            $echo_str .= $dlp . "\t\t" . '<select id="wfu_attribute_' . $attr . '" class="wfu_select_folders' . (count($subfolders['path']) == 0 ? ' wfu_select_folders_empty' : '') . '" size="7"' . (substr($def['value'], 0, 4) == "auto" ? ' disabled="disabled"' : '') . ' onchange="wfu_subfolders_changed(\'' . $attr . '\');">';
            foreach ($subfolders['path'] as $ind => $subfolder) {
                if (substr($subfolder, -1) == '/') {
                    $subfolder = substr($subfolder, 0, -1);
                }
                $subfolder_raw = explode('/', $subfolder);
                $subfolder = $subfolder_raw[count($subfolder_raw) - 1];
                $text = str_repeat("&nbsp;&nbsp;&nbsp;", intval($subfolders['level'][$ind])) . $subfolders['label'][$ind];
                $subvalue = str_repeat("*", intval($subfolders['level'][$ind])) . ($subfolders['default'][$ind] ? '&' : '') . ($subfolder == "" ? '{root}' : $subfolder) . '/' . $subfolders['label'][$ind];
                $echo_str .= $dlp . "\t\t\t" . '<option class="' . ($subfolders['default'][$ind] ? 'wfu_select_folders_option_default' : '') . '" value="' . wfu_plugin_encode_string($subvalue) . '">' . $text . '</option>';
            }
            $echo_str .= $dlp . "\t\t\t" . '<option value="">' . (substr($def['value'], 0, 4) != "auto" && count($subfolders['path']) == 0 ? 'press here' : '') . '</option>';
            $echo_str .= $dlp . "\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_subfolder_nav_' . $attr . '" class="wfu_subfolder_nav_container">';
            $echo_str .= $dlp . "\t\t\t" . '<table class="wfu_subfolder_nav"><tbody>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td><button id="wfu_subfolders_up_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" disabled="disabled" title="move item up" onclick="wfu_subfolders_up_clicked(\'' . $attr . '\');">&uarr;</button></tr></td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td><button id="wfu_subfolders_left_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" title="make it parent" disabled="disabled" style="height:14px;" onclick="wfu_subfolders_left_clicked(\'' . $attr . '\');">&larr;</button>';
            $echo_str .= $dlp . "\t\t\t\t" . '<button id="wfu_subfolders_right_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" title="make it child" disabled="disabled" style="height:14px;" onclick="wfu_subfolders_right_clicked(\'' . $attr . '\');">&rarr;</button></tr></td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td><button id="wfu_subfolders_down_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" title="move item down" disabled="disabled" onclick="wfu_subfolders_down_clicked(\'' . $attr . '\');">&darr;</button></tr></td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td style="line-height:0;"><button  class="button" style="visibility:hidden; height:10px;"></button></tr></td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td><button id="wfu_subfolders_add_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" title="add new item" disabled="disabled" style="height:14px;" onclick="wfu_subfolders_add_clicked(\'' . $attr . '\');">+</button></tr></td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td><button id="wfu_subfolders_def_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" title="make it default" disabled="disabled" style="height:14px;" onclick="wfu_subfolders_def_clicked(\'' . $attr . '\');">&diams;</button></tr></td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td><button id="wfu_subfolders_del_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" title="delete item" disabled="disabled" style="height:14px;" onclick="wfu_subfolders_del_clicked(\'' . $attr . '\');">-</button></tr></td>';
            $echo_str .= $dlp . "\t\t\t" . '</tbody></table>';
            $echo_str .= $dlp . "\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_subfolder_tools_' . $attr . '" class="wfu_subfolder_tools_container wfu_subfolder_tools_disabled">';
            $echo_str .= $dlp . "\t\t\t" . '<table class="wfu_subfolder_tools"><tbody><tr>';
            $echo_str .= $dlp . "\t\t\t\t" . '<td style="width:40%;">';
            $echo_str .= $dlp . "\t\t\t\t\t" . '<label>Label</label>';
            $echo_str .= $dlp . "\t\t\t\t\t" . '<input id="wfu_subfolders_label_' . $attr . '" name="wfu_subfolder_tools_input" type="text" disabled="disabled" />';
            $echo_str .= $dlp . "\t\t\t\t" . '</td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<td style="width:60%;"><div style="padding-right:36px;">';
            $echo_str .= $dlp . "\t\t\t\t\t" . '<label>Path</label>';
            $echo_str .= $dlp . "\t\t\t\t\t" . '<input id="wfu_subfolders_path_' . $attr . '" name="wfu_subfolder_tools_input" type="text" disabled="disabled" />';
            $echo_str .= $dlp . "\t\t\t\t\t" . '<button id="wfu_subfolders_browse_' . $attr . '" class="button" title="browse folders" style="right:18px;" disabled="disabled" onclick="wfu_subfolders_browse_clicked(\'' . $attr . '\');"><img src="' . WFU_IMAGE_ADMIN_SUBFOLDER_BROWSE . '" ></button>';
            $echo_str .= $dlp . "\t\t\t\t\t" . '<button id="wfu_subfolders_ok_' . $attr . '" class="button" title="save changes" style="right:0px;" disabled="disabled" onclick="wfu_subfolders_ok_clicked(\'' . $attr . '\');"><img src="' . WFU_IMAGE_ADMIN_SUBFOLDER_OK . '" ></button>';
            // file browser dialog
            $echo_str .= $dlp . "\t\t\t\t\t" . '<div id="wfu_subfolders_browser_' . $attr . '" class="wfu_subfolders_browser_container" style="display:none;">';
            $echo_str .= $dlp . "\t\t\t\t\t\t" . '<table><tbody>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t" . '<tr><td style="height:15px;">';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t" . '<div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '<label>Folder Browser</label>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '<button class="button wfu_folder_browser_cancel" onclick="wfu_folder_browser_cancel_clicked(\'' . $attr . '\');"><img src="' . WFU_IMAGE_ADMIN_SUBFOLDER_CANCEL . '" ></button>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t" . '</td></tr>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t" . '<tr><td style="height:106px;">';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t" . '<div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '<select id="wfu_subfolders_browser_list_' . $attr . '" size="2" onchange="wfu_subfolders_browser_list_changed(\'' . $attr . '\');">';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t\t" . '<option>Value</option>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t\t" . '<option>Value2</option>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t\t" . '<option>Value3</option>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '<div id="wfu_subfolders_browser_msgcont_' . $attr . '" class="wfu_folder_browser_loading_container" style="padding-top:40px;">';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t\t" . '<label id="wfu_subfolders_browser_msg_' . $attr . '" style="margin-bottom:4px;">loading folder contents...</label>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t\t" . '<img id="wfu_subfolders_browser_img_' . $attr . '" src="' . WFU_IMAGE_ADMIN_SUBFOLDER_LOADING . '" ></button>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t" . '</td></tr>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t" . '<tr><td align="right" style="height:15px;">';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t" . '<div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '<button class="button" onclick="wfu_folder_browser_cancel_clicked(\'' . $attr . '\');">Cancel</button>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '<button id="wfu_subfolders_browser_ok_' . $attr . '" class="button">Ok</button>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t" . '</td></tr>';
            $echo_str .= $dlp . "\t\t\t\t\t\t" . '</tbody></table>';
            $echo_str .= $dlp . "\t\t\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t\t\t" . '</div></td>';
            $echo_str .= $dlp . "\t\t\t" . '</tr></tbody></table>';
            $echo_str .= $dlp . "\t\t\t" . '<input id="wfu_subfolders_isnewitem_' . $attr . '" type="hidden" value="" />';
            $echo_str .= $dlp . "\t\t\t" . '<input id="wfu_subfolders_newitemindex_' . $attr . '" type="hidden" value="" />';
            $echo_str .= $dlp . "\t\t\t" . '<input id="wfu_subfolders_newitemlevel_' . $attr . '" type="hidden" value="" />';
            $echo_str .= $dlp . "\t\t\t" . '<input id="wfu_subfolders_newitemlevel2_' . $attr . '" type="hidden" value="" />';
            $echo_str .= $dlp . "\t\t" . '</div>';
        } elseif ($def['type'] == "mchecklist") {
            $help_count = 0;
            foreach ($def['listitems'] as $key => $item) {
                $parts = explode("/", $item);
                if (count($parts) == 1) {
                    $items[$key]['id'] = $item;
                    $items[$key]['help'] = '';
                } else {
                    $items[$key]['id'] = $parts[0];
                    $items[$key]['help'] = $parts[1];
                    $help_count++;
                }
            }
            $def['value'] = strtolower($def['value']);
            if ($def['value'] == "all") {
                $selected = array();
            } else {
                $selected = explode(",", $def['value']);
            }
            foreach ($selected as $key => $item) {
                $selected[$key] = trim($item);
            }
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_attribute_' . $attr . '" class="wfu_mchecklist_container">';
            $is_first = true;
            foreach ($items as $key => $item) {
                if (!$is_first) {
                    $echo_str .= "<br />";
                }
                $is_first = false;
                $echo_str .= $dlp . "\t\t\t" . '<div class="wfu_mchecklist_item"><input id="wfu_attribute_' . $attr . '_' . $key . '" type="checkbox"' . ($def['value'] == "all" || in_array($item['id'], $selected) ? ' checked="checked"' : '') . ($def['value'] == "all" ? ' disabled="disabled"' : '') . ' onchange="wfu_update_mchecklist_value(\'' . $attr . '\');" /><label for="wfu_attribute_' . $attr . '_' . $key . '">' . $item['id'] . '</label>';
                if ($item['help'] != '') {
                    $echo_str .= '<div class="wfu_help_container" title="' . $item['help'] . '"><img src="' . WFU_IMAGE_ADMIN_HELP . '" /></div>';
                }
                $echo_str .= '</div>';
            }
            $echo_str .= $dlp . "\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_attribute_' . $attr . '_optionhelp" class="wfu_help_container" title="" style="display:none; position:absolute;"><img src="' . WFU_IMAGE_ADMIN_HELP . '" style="visibility:visible;" /></div>';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_mchecklist_checkall"><input id="wfu_attribute_' . $attr . '_all" type="checkbox" onchange="wfu_update_mchecklist_value(\'' . $attr . '\');"' . ($def['value'] == "all" ? ' checked="checked"' : '') . ' /> Select all</div>';
        } elseif ($def['type'] == "rolelist") {
            $roles = $wp_roles->get_names();
            $selected = explode(",", $def['value']);
            $default_administrator = is_array($def['listitems']) && in_array('default_administrator', $def['listitems']);
            if (in_array('all', $selected)) {
                $rolesselected = $default_administrator ? array("administrator") : array();
            } else {
                $rolesselected = $selected;
            }
            foreach ($selected as $key => $item) {
                $selected[$key] = trim($item);
            }
            $echo_str .= $dlp . "\t\t" . '<table class="wfu_rolelist_container"><tbody><tr><td>';
            $echo_str .= $dlp . "\t\t" . '<select id="wfu_attribute_' . $attr . '" multiple="multiple" size="' . count($roles) . '" onchange="wfu_update_rolelist_value(\'' . $attr . '\');"' . (in_array('all', $selected) ? ' disabled="disabled"' : '') . '>';
            foreach ($roles as $roleid => $rolename) {
                $echo_str .= $dlp . "\t\t\t" . '<option value="' . $roleid . '"' . (in_array($roleid, $rolesselected) ? ' selected="selected"' : '') . '>' . $rolename . '</option>';
            }
            $echo_str .= $dlp . "\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t" . '</td><td>';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_rolelist_checkbtn"><input class="' . ($default_administrator ? 'wfu_default_administrator' : '') . '" id="wfu_attribute_' . $attr . '_all" type="checkbox" onchange="wfu_update_rolelist_value(\'' . $attr . '\');"' . (in_array('all', $selected) ? ' checked="checked"' : '') . ' /><label for="wfu_attribute_' . $attr . '_all"> Select all</label></div><br />';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_rolelist_checkbtn"><input id="wfu_attribute_' . $attr . '_guests" type="checkbox" onchange="wfu_update_rolelist_value(\'' . $attr . '\');"' . (in_array("guests", $selected) ? ' checked="checked"' : '') . ' /><label for="wfu_attribute_' . $attr . '_guests"> Include guests</label></div>';
            $echo_str .= $dlp . "\t\t" . '</td></tr></tbody></table>';
        } elseif ($def['type'] == "userlist") {
            $users = get_users();
            $selected = explode(",", $def['value']);
            $default_0 = is_array($def['listitems']) && in_array('default_0', $def['listitems']);
            if (in_array('all', $selected)) {
                $usersselected = $default_0 ? array($users[0]->user_login) : array();
            } else {
                $usersselected = $selected;
            }
            $only_current = false;
            $echo_str .= $dlp . "\t\t" . '<table class="wfu_userlist_container"><tbody><tr>';
            if (is_array($def['listitems']) && in_array('include_current', $def['listitems'])) {
                $only_current = $def['value'] == 'current';
                if ($only_current) {
                    $usersselected = $default_0 ? array($users[0]->user_login) : array();
                }
                $echo_str .= $dlp . "\t\t" . '<td colspan="2"><div class="wfu_userlist_checkbtn"><input id="wfu_attribute_' . $attr . '_current" type="checkbox" onchange="wfu_update_userlist_value(\'' . $attr . '\');"' . ($only_current ? ' checked="checked"' : '') . ' /><label for="wfu_attribute_' . $attr . '_current"> Only From Current User</label></div>';
                $echo_str .= $dlp . "\t\t" . '</td></tr><tr>';
            }
            $echo_str .= $dlp . "\t\t" . '<td><select id="wfu_attribute_' . $attr . '" multiple="multiple" size="' . min(count($users), 10) . '" onchange="wfu_update_userlist_value(\'' . $attr . '\');"' . ($only_current || in_array('all', $selected) ? ' disabled="disabled"' : '') . '>';
            foreach ($users as $userid => $user) {
                $echo_str .= $dlp . "\t\t\t" . '<option value="' . $user->user_login . '"' . (in_array($user->user_login, $usersselected) ? ' selected="selected"' : '') . '>' . $user->display_name . ' (' . $user->user_login . ')</option>';
            }
            $echo_str .= $dlp . "\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t" . '</td><td>';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_userlist_checkbtn"><input class="' . ($default_0 ? 'wfu_default_0' : '') . '" id="wfu_attribute_' . $attr . '_all" type="checkbox" onchange="wfu_update_userlist_value(\'' . $attr . '\');"' . (in_array('all', $selected) ? ' checked="checked"' : '') . ($only_current ? ' disabled="disabled"' : '') . ' /><label for="wfu_attribute_' . $attr . '_all"> Select all</label></div><br />';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_userlist_checkbtn"><input id="wfu_attribute_' . $attr . '_guests" type="checkbox" onchange="wfu_update_userlist_value(\'' . $attr . '\');"' . (in_array("guests", $selected) ? ' checked="checked"' : '') . ($only_current ? ' disabled="disabled"' : '') . ' /><label for="wfu_attribute_' . $attr . '_guests"> Include guests</label></div>';
            $echo_str .= $dlp . "\t\t" . '</td></tr></tbody></table>';
        } elseif ($def['type'] == "postlist") {
            $processed = false;
            if (is_array($def['listitems'])) {
                $has_current = in_array('include_current', $def['listitems']);
                if ($has_current) {
                    unset($def['listitems'][array_search('include_current', $def['listitems'])]);
                }
                foreach ($def['listitems'] as $post_type) {
                    // if a post type cannot be found then we reset the list so that it is not processed at all
                    if (get_post_type_object($post_type) == null) {
                        $def['listitems'] = array();
                        break;
                    }
                }
                if (count($def['listitems']) > 0) {
                    $selected = explode(",", $def['value']);
                    $only_current = false;
                    $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '_postlist" type="hidden" value="' . implode(",", $def['listitems']) . '" />';
                    $echo_str .= $dlp . "\t\t" . '<table class="wfu_postlist_container"><tbody><tr>';
                    if ($has_current) {
                        $only_current = $def['value'] == 'current';
                        if ($only_current) {
                            $sselected = array();
                        }
                        $echo_str .= $dlp . "\t\t" . '<td colspan="' . count($def['listitems']) . '"><div class="wfu_postlist_checkbtn"><input id="wfu_attribute_' . $attr . '_current" type="checkbox" onchange="wfu_update_postlist_value(\'' . $attr . '\');"' . ($only_current ? ' checked="checked"' : '') . ' /><label for="wfu_attribute_' . $attr . '_current"> Only From Current Post/Page</label></div>';
                        $echo_str .= $dlp . "\t\t" . '</td></tr><tr>';
                    }
                    $postargs = array('post_type' => $def['listitems'], 'post_status' => "publish,private,draft", 'posts_per_page' => -1);
                    $posts = get_posts($postargs);
                    $list = wfu_construct_post_list($posts);
                    foreach ($def['listitems'] as $post_type) {
                        $flatlist = wfu_flatten_post_list($list[$post_type]);
                        $postobj = get_post_type_object($post_type);
                        $echo_str .= $dlp . "\t\t" . '<td><div class="wfu_postlist_header"><label>' . $postobj->label . '</label><div class="wfu_postlist_selectall"><input id="wfu_attribute_' . $attr . '_all_' . $post_type . '" type="checkbox" onchange="wfu_update_postlist_value(\'' . $attr . '\');"' . (in_array('all', $selected) || in_array('all' . $post_type, $selected) ? ' checked="checked"' : '') . ($only_current ? ' disabled="disabled"' : '') . ' /><label for="wfu_attribute_' . $attr . '_all_' . $post_type . '"> Select all</label></div></div>';
                        $echo_str .= $dlp . "\t\t" . '<select id="wfu_attribute_' . $attr . '_' . $post_type . '" multiple="multiple" size="' . min(count($flatlist), 10) . '" onchange="wfu_update_postlist_value(\'' . $attr . '\');"' . ($only_current || in_array('all', $selected) || in_array('all' . $post_type, $selected) ? ' disabled="disabled"' : '') . '>';
                        foreach ($flatlist as $item) {
                            $echo_str .= $dlp . "\t\t\t" . '<option value="' . $item['id'] . '"' . (in_array($item['id'], $selected) ? ' selected="selected"' : '') . '>' . str_repeat('&nbsp;', 4 * $item['level']) . ($item['status'] == 1 ? '[Private]' : ($item['status'] == 2 ? '[Draft]' : '')) . $item['title'] . '</option>';
                        }
                        $echo_str .= $dlp . "\t\t" . '</select></td>';
                    }
                    $echo_str .= $dlp . "\t\t" . '</tr></tbody></table>';
                    $processed = true;
                }
            }
            if (!$processed) {
                $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
                $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="text" name="wfu_text_elements" value="' . $val . '" />';
            }
        } elseif ($def['type'] == "bloglist") {
            if (function_exists('wp_get_sites')) {
                $blogs = wp_get_sites();
                $selected = explode(",", $def['value']);
                if (in_array('all', $selected)) {
                    $blogsselected = array();
                } else {
                    $blogsselected = $selected;
                }
                $only_current = false;
                $echo_str .= $dlp . "\t\t" . '<table class="wfu_bloglist_container"><tbody><tr>';
                if (is_array($def['listitems']) && in_array('include_current', $def['listitems'])) {
                    $only_current = $def['value'] == 'current';
                    if ($only_current) {
                        $blogsselected = array();
                    }
                    $echo_str .= $dlp . "\t\t" . '<td colspan="2"><div class="wfu_bloglist_checkbtn"><input id="wfu_attribute_' . $attr . '_current" type="checkbox" onchange="wfu_update_bloglist_value(\'' . $attr . '\');"' . ($only_current ? ' checked="checked"' : '') . ' /><label for="wfu_attribute_' . $attr . '_current"> Only From Current Site</label></div>';
                    $echo_str .= $dlp . "\t\t" . '</td></tr><tr>';
                }
                $echo_str .= $dlp . "\t\t" . '<td><select id="wfu_attribute_' . $attr . '" multiple="multiple" size="' . min(count($blogs), 10) . '" onchange="wfu_update_bloglist_value(\'' . $attr . '\');"' . ($only_current || in_array('all', $selected) ? ' disabled="disabled"' : '') . '>';
                foreach ($blogs as $blog) {
                    $echo_str .= $dlp . "\t\t\t" . '<option value="' . $blog->blog_id . '"' . (in_array($blog->blog_id, $blogsselected) ? ' selected="selected"' : '') . '>' . $blog->path . '</option>';
                }
                $echo_str .= $dlp . "\t\t" . '</select>';
                $echo_str .= $dlp . "\t\t" . '</td><td>';
                $echo_str .= $dlp . "\t\t" . '<div class="wfu_bloglist_checkbtn"><input id="wfu_attribute_' . $attr . '_all" type="checkbox" onchange="wfu_update_bloglist_value(\'' . $attr . '\');"' . (in_array('all', $selected) ? ' checked="checked"' : '') . ($only_current ? ' disabled="disabled"' : '') . ' /><label for="wfu_attribute_' . $attr . '_all"> Select all</label></div>';
                $echo_str .= $dlp . "\t\t" . '</td></tr></tbody></table>';
            } else {
                $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
                $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="text" name="wfu_text_elements" value="' . $val . '" />';
            }
        } elseif ($def['type'] == "stringmatch") {
            $matchfield = "";
            $matchcriterion = "equal to";
            $matchvalue = "";
            preg_match('/^field:(.*?);\\s*criterion:(.*?)\\s*;\\s*value:(.*)$/', $def['value'], $matches);
            if (count($matches) == 4) {
                $matchfield = $matches[1];
                $matchcriterion = $matches[2];
                $matchvalue = $matches[3];
            }
            $echo_str .= $dlp . "\t\t" . '<div style="white-space:nowrap;">';
            $echo_str .= $dlp . "\t\t" . '<label>Field </label><input id="wfu_attribute_' . $attr . '_matchfield" type="text" name="wfu_stringmatch_elements" value="' . $matchfield . '" />';
            $echo_str .= $dlp . "\t\t" . '<select id="wfu_attribute_' . $attr . '_matchcriterion" value="' . $matchcriterion . '" onchange="wfu_update_stringmatch_value(\'' . $attr . '\');">';
            $echo_str .= $dlp . "\t\t\t" . '<option value="equal to"' . ($matchcriterion == "equal to" ? 'selected="selected"' : '') . '>equal to</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="starts with"' . ($matchcriterion == "starts with" ? 'selected="selected"' : '') . '>starts with</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="ends with"' . ($matchcriterion == "ends with" ? 'selected="selected"' : '') . '>ends with</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="contains"' . ($matchcriterion == "contains" ? 'selected="selected"' : '') . '>contains</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="not equal to"' . ($matchcriterion == "not equal to" ? 'selected="selected"' : '') . '>not equal to</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="does not start with"' . ($matchcriterion == "does not start with" ? 'selected="selected"' : '') . '>does not start with</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="does not end with"' . ($matchcriterion == "does not end with" ? 'selected="selected"' : '') . '>does not end with</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="does not contain"' . ($matchcriterion == "does not contain" ? 'selected="selected"' : '') . '>does not contain</option>';
            $echo_str .= $dlp . "\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '_matchvalue" type="text" name="wfu_stringmatch_elements" value="' . $matchvalue . '" />';
            $echo_str .= $dlp . "\t\t" . '</div>';
        } elseif ($def['type'] == "columns") {
            $selected = explode(",", $def['value']);
            if (count($selected) == 1 && $selected[0] == "") {
                $selected = array();
            }
            $echo_str .= $dlp . "\t" . '<table class="wfu_columns_container"><tbody><tr>';
            $echo_str .= $dlp . "\t\t" . '<td>';
            $echo_str .= $dlp . "\t\t\t" . '<label class="wfu_columns_listtitle">Available Columns</label><br />';
            $echo_str .= $dlp . "\t\t\t" . '<select id="wfu_attribute_' . $attr . '_sourcelist" multiple="multiple" size="' . min(count($def['listitems']), 10) . '">';
            foreach ($def['listitems'] as $item) {
                $item_required = substr($item, 0, 1) == "*";
                if ($item_required) {
                    $item = substr($item, 1);
                }
                $item_parts = explode("/", $item, 2);
                if (count($item_parts) == 1) {
                    $item_name = $item;
                    $item_label = $item . ($item_required ? ' (required)' : '');
                } else {
                    $item_name = $item_parts[0];
                    $item_label = $item_parts[1];
                }
                $itemprops[$item_name] = array('label' => $item_label, 'required' => $item_required);
                $echo_str .= $dlp . "\t\t\t\t" . '<option value="' . $item_name . '"' . ($item_required ? ' class="wfu_columns_item_required"' : '') . ' onclick="wfu_columns_itemclicked(this);">' . $item_label . '</option>';
            }
            $echo_str .= $dlp . "\t\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t" . '</td>';
            foreach ($itemprops as $item_name => $prop) {
                if ($prop['required'] && !in_array($item_name, $selected)) {
                    array_splice($selected, 0, 0, array($item_name));
                }
            }
            $echo_str .= $dlp . "\t\t" . '<td align="center">';
            $echo_str .= $dlp . "\t\t\t" . '<label class="wfu_columns_listtitle"></label><br />';
            $echo_str .= $dlp . "\t\t\t" . '<button class="wfu_columns_addbutton" onclick="wfu_columns_buttonaction(\'' . $attr . '\', \'add\');">Add &gt;&gt;</button><br />';
            $echo_str .= $dlp . "\t\t\t" . '<button class="wfu_columns_addbutton" onclick="wfu_columns_buttonaction(\'' . $attr . '\', \'del\');">&lt;&lt; Remove</button>';
            $echo_str .= $dlp . "\t\t" . '</td>';
            $echo_str .= $dlp . "\t\t" . '<td>';
            $echo_str .= $dlp . "\t\t\t" . '<label class="wfu_columns_listtitle">Displayed Columns</label><br />';
            $echo_str .= $dlp . "\t\t\t" . '<select id="wfu_attribute_' . $attr . '" multiple="multiple" size="' . min(count($def['listitems']), 10) . '" onchange="wfu_update_columns(\'' . $attr . '\');">';
            foreach ($selected as $item_name) {
                $echo_str .= $dlp . "\t\t\t\t" . '<option value="' . $item_name . '"' . ($itemprops[$item_name]['required'] ? ' class="wfu_columns_item_required"' : '') . ' onclick="wfu_columns_itemclicked(this);">' . $itemprops[$item_name]['label'] . '</option>';
            }
            $echo_str .= $dlp . "\t\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t" . '</td>';
            $echo_str .= $dlp . "\t\t" . '<td align="center">';
            $echo_str .= $dlp . "\t\t\t" . '<label class="wfu_columns_listtitle"></label><br />';
            $echo_str .= $dlp . "\t\t\t" . '<button class="wfu_columns_addbutton" onclick="wfu_columns_buttonaction(\'' . $attr . '\', \'up\');">&#8593;</button><br />';
            $echo_str .= $dlp . "\t\t\t" . '<button class="wfu_columns_addbutton" onclick="wfu_columns_buttonaction(\'' . $attr . '\', \'down\');">&#8595;</button>';
            $echo_str .= $dlp . "\t\t" . '</td>';
            $echo_str .= $dlp . "\t" . '</tr></tbody></table>';
        } elseif ($def['type'] == "dimensions") {
            $vals_arr = explode(",", $def['value']);
            $vals = array();
            foreach ($vals_arr as $val_raw) {
                if (trim($val_raw) != "") {
                    list($val_id, $val) = explode(":", $val_raw);
                    $vals[trim($val_id)] = trim($val);
                }
            }
            $dims = array();
            foreach ($components as $comp) {
                if ($comp['dimensions'] == null) {
                    $dims[$comp['id']] = $comp['name'];
                } else {
                    foreach ($comp['dimensions'] as $dimraw) {
                        list($dim_id, $dim_name) = explode("/", $dimraw);
                        $dims[$dim_id] = $dim_name;
                    }
                }
            }
            foreach ($dims as $dim_id => $dim_name) {
                if (!array_key_exists($dim_id, $vals)) {
                    $vals[$dim_id] = "";
                }
                $echo_str .= $dlp . "\t\t" . '<span style="display:inline-block; width:130px;">' . $dim_name . '</span><input id="wfu_attribute_' . $attr . '_' . $dim_id . '" type="text" name="wfu_dimension_elements_' . $attr . '" class="wfu_short_text" value="' . $vals[$dim_id] . '" /><br />';
            }
        } elseif ($def['type'] == "userfields") {
            $fields_arr = explode("/", $def['value']);
            $fields = array();
            foreach ($fields_arr as $field_raw) {
                $is_req = substr($field_raw, 0, 1) == "*";
                if ($is_req) {
                    $field_raw = substr($field_raw, 1);
                }
                if ($field_raw != "") {
                    array_push($fields, array("name" => $field_raw, "required" => $is_req));
                }
            }
            if (count($fields) == 0) {
                array_push($fields, array("name" => "", "required" => false));
            }
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_attribute_' . $attr . '" class="wfu_userdata_container">';
            foreach ($fields as $field) {
                $echo_str .= $dlp . "\t\t\t" . '<div class="wfu_userdata_line">';
                $echo_str .= $dlp . "\t\t\t\t" . '<input type="text" name="wfu_userfield_elements" value="' . $field['name'] . '" />';
                $echo_str .= $dlp . "\t\t\t\t" . '<div class="wfu_userdata_action" onclick="wfu_userdata_add_field(this);"><img src="' . WFU_IMAGE_ADMIN_USERDATA_ADD . '" ></div>';
                $echo_str .= $dlp . "\t\t\t\t" . '<div class="wfu_userdata_action wfu_userdata_action_disabled" onclick="wfu_userdata_remove_field(this);"><img src="' . WFU_IMAGE_ADMIN_USERDATA_REMOVE . '" ></div>';
                $echo_str .= $dlp . "\t\t\t\t" . '<input type="checkbox"' . ($field['required'] ? 'checked="checked"' : '') . ' onchange="wfu_update_userfield_value({target:this});" />';
                $echo_str .= $dlp . "\t\t\t\t" . '<span>Required</span>';
                $echo_str .= $dlp . "\t\t\t" . '</div>';
            }
            $echo_str .= $dlp . "\t\t" . '</div>';
        } elseif ($def['type'] == "formfields") {
            //get field type definitions
            $fielddefs_array = $def['listitems'];
            foreach ($fielddefs_array as $fielddef) {
                $fielddefs[$fielddef['type']] = $fielddef;
            }
            //initialize editable field properties
            $fieldprops_basic = array('required', 'donotautocomplete', 'validate', 'typehook', 'labelposition', 'hintposition', 'default', 'data', 'group', 'format');
            $fieldprops_default = array("type" => "text", "label" => "", "labelposition" => "left", "required" => false, "donotautocomplete" => false, "validate" => false, "default" => "", "data" => "", "group" => "", "format" => "", "hintposition" => "right", "typehook" => false);
            //parse shortcode attribute to $fields
            $fields = wfu_parse_userdata_attribute($def['value']);
            $labelpositions = array("none", "top", "right", "bottom", "left");
            $hintpositions = array("none", "inline", "top", "right", "bottom", "left");
            if (count($fields) == 0) {
                array_push($fields, $fieldprops_default);
            }
            //set html template variable
            $template = $dlp . "\t\t\t\t" . '<table class="wfu_formdata_props_table"><tbody>';
            $template .= $dlp . "\t\t\t\t" . '<tr><td colspan="2"><label class="wfu_formdata_label">Type</label><select id="wfu_formfield_[[key]]_type" value="[[t]]" onchange="wfu_formdata_type_changed(\'[[key]]\');">';
            foreach ($fielddefs as $item) {
                $template .= $dlp . "\t\t\t\t\t" . '<option value="' . $item['type'] . '"[[type_' . $item['type'] . '_selected]]>' . $item['type_description'] . '</option>';
            }
            $template .= $dlp . "\t\t\t\t" . '</select></td><td>';
            $template .= $dlp . "\t\t\t\t" . '<div class="wfu_formdata_action wfu_formdata_action_add" onclick="wfu_formdata_add_field(\'[[key]]\');"><img src="' . WFU_IMAGE_ADMIN_USERDATA_ADD . '" ></div>';
            $template .= $dlp . "\t\t\t\t" . '<div class="wfu_formdata_action wfu_formdata_action_remove[[remove_disabled]]" onclick="wfu_formdata_remove_field(\'[[key]]\');"><img src="' . WFU_IMAGE_ADMIN_USERDATA_REMOVE . '" ></div></td></tr>';
            $template .= $dlp . "\t\t\t\t" . '<tr><td class="wfu_formdata_props"><label class="wfu_formdata_label">Label</label></td><td><input type="text" id="wfu_formfield_[[key]]_label" name="wfu_formfield_elements" value="[[label]]" /></td><td></td></tr>';
            $labelpos_options = "";
            foreach ($labelpositions as $pos) {
                $labelpos_options .= '<option value="' . $pos . '"[[labelposition_' . $pos . '_selected]]>' . $pos . '</option>';
            }
            $template .= $dlp . "\t\t\t\t" . '<tr><td class="wfu_formdata_props"><label class="wfu_formdata_labelposition" title="[[labelposition_hint]]">Label Position</label></td><td><select id="wfu_formfield_[[key]]_labelposition" value="[[s]]" title="[[labelposition_hint]]" onchange="wfu_update_formfield_value({target:this});">' . $labelpos_options . '</select></td><td></td></tr>';
            $template .= '[[R->]]' . $dlp . "\t\t\t\t" . '<tr><td colspan="2" class="wfu_formdata_props"><input id="wfu_formfield_[[key]]_required" type="checkbox"[[r->]] checked="checked"[[<-r]] title="[[required_hint]]" onchange="wfu_update_formfield_value({target:this});" /><label for="wfu_formfield_[[key]]_required" title="[[required_hint]]"> Required</label></td><td></td></tr>[[<-R]]';
            $template .= '[[A->]]' . $dlp . "\t\t\t\t" . '<tr><td colspan="2" class="wfu_formdata_props"><input id="wfu_formfield_[[key]]_donotautocomplete" type="checkbox"[[a->]] checked="checked"[[<-a]] title="[[donotautocomplete_hint]]" onchange="wfu_update_formfield_value({target:this});" /><label for="wfu_formfield_[[key]]_donotautocomplete" title="[[donotautocomplete_hint]]"> Do not autocomplete</label></td><td></td></tr>[[<-A]]';
            $template .= '[[V->]]' . $dlp . "\t\t\t\t" . '<tr><td colspan="2" class="wfu_formdata_props"><input id="wfu_formfield_[[key]]_validate" type="checkbox"[[v->]] checked="checked"[[<-v]] title="[[validate_hint]]" onchange="wfu_update_formfield_value({target:this});" /><label for="wfu_formfield_[[key]]_validate" title="[[validate_hint]]"> Validate</label></td><td></td></tr>[[<-V]]';
            $hint_options = "";
            foreach ($hintpositions as $pos) {
                $hint_options .= '<option value="' . $pos . '"[[hintposition_' . $pos . '_selected]]>' . $pos . '</option>';
            }
            $template .= '[[P->]]' . $dlp . "\t\t\t\t" . '<tr><td class="wfu_formdata_props"><label class="wfu_formdata_label" title="[[hintposition_hint]]">Hint Position</label></td><td><select id="wfu_formfield_[[key]]_hintposition" value="[[p]]" title="[[hintposition_hint]]" onchange="wfu_update_formfield_value({target:this});">' . $hint_options . '</select></td><td></td></tr>[[<-P]]';
            $template .= '[[H->]]' . $dlp . "\t\t\t\t" . '<tr><td colspan="2" class="wfu_formdata_props"><input id="wfu_formfield_[[key]]_typehook" type="checkbox"[[h->]] checked="checked"[[<-h]] title="[[typehook_hint]]" onchange="wfu_update_formfield_value({target:this});" /><label for="wfu_formfield_[[key]]_typehook" title="[[typehook_hint]]"> Type hook</label></td><td></td></tr>[[<-H]]';
            $template .= '[[D->]]' . $dlp . "\t\t\t\t" . '<tr><td class="wfu_formdata_props"><label class="wfu_formdata_label" title="[[default_hint]]">Default</label></td><td><input id="wfu_formfield_[[key]]_default" type="text" name="wfu_formfield_elements" value="[[d]]" title="[[default_hint]]" /></td><td></td></tr>[[<-D]]';
            $template .= '[[L->]]' . $dlp . "\t\t\t\t" . '<tr><td class="wfu_formdata_props"><label class="wfu_formdata_label" title="[[data_hint]]">[[data_label]]</label></td><td><input id="wfu_formfield_[[key]]_data" type="text" name="wfu_formfield_elements" value="[[l]]" title="[[data_hint]]" /></td><td></td></tr>[[<-L]]';
            $template .= '[[G->]]' . $dlp . "\t\t\t\t" . '<tr><td class="wfu_formdata_props"><label class="wfu_formdata_label" title="[[group_hint]]">Group ID</label></td><td><input id="wfu_formfield_[[key]]_group" type="text" name="wfu_formfield_elements" value="[[g]]" title="[[group_hint]]" /></td><td></td></tr>[[<-G]]';
            $template .= '[[F->]]' . $dlp . "\t\t\t\t" . '<tr><td class="wfu_formdata_props"><label class="wfu_formdata_label" title="[[format_hint]]">Format</label></td><td><input id="wfu_formfield_[[key]]_format" type="text" name="wfu_formfield_elements" value="[[f]]" title="[[format_hint]]" /></td><td></td></tr>[[<-F]]';
            $template .= $dlp . "\t\t\t\t" . '</tbody></table>';
            //draw html elements
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_attribute_' . $attr . '" class="wfu_formdata_container">';
            $echo_str .= $dlp . "\t\t\t" . '<div id="wfu_attribute_' . $attr . '_codeadd" style="display:none;">';
            //pass template and type props to client javascript variable and then erase the code
            $echo_str .= $dlp . "\t\t\t\t" . '<script type="text/javascript">';
            $echo_str .= $dlp . "\t\t\t\t\t" . 'var wfu_attribute_' . $attr . '_formtemplate = "' . wfu_plugin_encode_string($template) . '";';
            $echo_str .= $dlp . "\t\t\t\t\t" . 'var wfu_attribute_' . $attr . '_typeprops = {};';
            $fielddef_array = array();
            foreach ($fielddefs as $item) {
                array_push($fielddef_array, $item['type']);
            }
            //prepare storage of field definitions to browser context
            $echo_str .= $dlp . "\t\t\t\t\t" . 'wfu_attribute_' . $attr . '_typeprops[0] = \'' . implode(",", $fielddef_array) . '\'';
            foreach ($fielddefs as $item) {
                $typeprops = array();
                foreach ($fieldprops_basic as $prop) {
                    array_push($typeprops, $prop . ': \'' . $item[$prop] . '\'');
                    array_push($typeprops, $prop . '_hint: \'' . $item[$prop . '_hint'] . '\'');
                }
                array_push($typeprops, 'data_label: \'' . $item['data_label'] . '\'');
                $echo_str .= $dlp . "\t\t\t\t\t" . 'wfu_attribute_' . $attr . '_typeprops["' . $item['type'] . '"] = {' . implode(", ", $typeprops) . '};';
            }
            $echo_str .= $dlp . "\t\t\t\t\t" . 'var self = document.getElementById("wfu_attribute_' . $attr . '_codeadd"); self.parentNode.removeChild(self);';
            $echo_str .= $dlp . "\t\t\t\t" . '</script>';
            $echo_str .= $dlp . "\t\t\t" . '</div>';
            foreach ($fields as $field) {
                $ind = wfu_create_random_string(4);
                $key = $attr . "_" . $ind;
                $fielddef = $fielddefs[$field["type"]];
                $echo_str .= $dlp . "\t\t\t" . '<div id="wfu_formfield_' . $key . '_container" class="wfu_formdata_line_container">';
                //generate html elements from template, replacing variables where applicable
                $from_template = str_replace(array('[[key]]', '[[t]]', '[[label]]', '[[s]]', '[[d]]', '[[l]]', '[[data_label]]', '[[g]]', '[[f]]', '[[p]]'), array($key, $field['type'], $field['label'], $field['labelposition'], $field['default'], $field['data'], $fielddef['data_label'], $field['group'], $field['format'], $field['hintposition']), $template);
                foreach ($fieldprops_basic as $prop) {
                    $from_template = str_replace('[[' . $prop . '_hint]]', str_replace('\\r\\n', "\r\n", $fielddef[$prop . '_hint']), $from_template);
                }
                foreach ($fielddefs as $item) {
                    $from_template = str_replace('[[type_' . $item['type'] . '_selected]]', $item['type'] == $field['type'] ? ' selected = "selected"' : '', $from_template);
                }
                foreach ($labelpositions as $pos) {
                    $from_template = str_replace('[[labelposition_' . $pos . '_selected]]', $pos == $field['labelposition'] ? ' selected = "selected"' : '', $from_template);
                }
                foreach ($hintpositions as $pos) {
                    $from_template = str_replace('[[hintposition_' . $pos . '_selected]]', $pos == $field['hintposition'] ? ' selected = "selected"' : '', $from_template);
                }
                $from_template = str_replace('[[remove_disabled]]', count($fields) <= 1 ? ' wfu_formdata_action_disabled' : '', $from_template);
                //adjust checkbox field values
                $from_template = preg_replace('/\\[\\[r\\-\\>\\]\\]' . ($field['required'] ? '|' : '.*') . '\\[\\[\\<\\-r\\]\\]/', '', $from_template);
                $from_template = preg_replace('/\\[\\[a\\-\\>\\]\\]' . ($field['donotautocomplete'] ? '|' : '.*') . '\\[\\[\\<\\-a\\]\\]/', '', $from_template);
                $from_template = preg_replace('/\\[\\[v\\-\\>\\]\\]' . ($field['validate'] ? '|' : '.*') . '\\[\\[\\<\\-v\\]\\]/', '', $from_template);
                $from_template = preg_replace('/\\[\\[h\\-\\>\\]\\]' . ($field['typehook'] ? '|' : '.*') . '\\[\\[\\<\\-h\\]\\]/', '', $from_template);
                //adjust visibility of properties
                $from_template = preg_replace('/\\[\\[R\\-\\>\\]\\]' . (substr($fielddef["required"], 0, 4) == "show" ? '|' : '.*') . '\\[\\[\\<\\-R\\]\\]/s', '', $from_template);
                $from_template = preg_replace('/\\[\\[A\\-\\>\\]\\]' . (substr($fielddef["donotautocomplete"], 0, 4) == "show" ? '|' : '.*') . '\\[\\[\\<\\-A\\]\\]/s', '', $from_template);
                $from_template = preg_replace('/\\[\\[V\\-\\>\\]\\]' . (substr($fielddef["validate"], 0, 4) == "show" ? '|' : '.*') . '\\[\\[\\<\\-V\\]\\]/s', '', $from_template);
                $from_template = preg_replace('/\\[\\[P\\-\\>\\]\\]' . (substr($fielddef["hintposition"], 0, 4) == "show" ? '|' : '.*') . '\\[\\[\\<\\-P\\]\\]/s', '', $from_template);
                $from_template = preg_replace('/\\[\\[H\\-\\>\\]\\]' . (substr($fielddef["typehook"], 0, 4) == "show" ? '|' : '.*') . '\\[\\[\\<\\-H\\]\\]/s', '', $from_template);
                $from_template = preg_replace('/\\[\\[D\\-\\>\\]\\]' . (substr($fielddef["default"], 0, 4) == "show" ? '|' : '.*') . '\\[\\[\\<\\-D\\]\\]/s', '', $from_template);
                $from_template = preg_replace('/\\[\\[L\\-\\>\\]\\]' . (substr($fielddef["data"], 0, 4) == "show" ? '|' : '.*') . '\\[\\[\\<\\-L\\]\\]/s', '', $from_template);
                $from_template = preg_replace('/\\[\\[G\\-\\>\\]\\]' . (substr($fielddef["group"], 0, 4) == "show" ? '|' : '.*') . '\\[\\[\\<\\-G\\]\\]/s', '', $from_template);
                $from_template = preg_replace('/\\[\\[F\\-\\>\\]\\]' . (substr($fielddef["format"], 0, 4) == "show" ? '|' : '.*') . '\\[\\[\\<\\-F\\]\\]/s', '', $from_template);
                $echo_str .= $from_template;
                $echo_str .= $dlp . "\t\t\t" . '</div>';
            }
            $echo_str .= $dlp . "\t\t" . '</div>';
        } elseif ($def['type'] == "color") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="text" name="wfu_text_elements" class="wfu_color_field" value="' . $val . '" />';
        } elseif ($def['type'] == "color-triplet") {
            $triplet = explode(",", $def['value']);
            foreach ($triplet as $key => $item) {
                $triplet[$key] = trim($item);
            }
            if (count($triplet) == 2) {
                $triplet = array($triplet[0], $triplet[1], "#000000");
            } elseif (count($triplet) == 1) {
                $triplet = array($triplet[0], "#FFFFFF", "#000000");
            } elseif (count($triplet) < 3) {
                $triplet = array("#000000", "#FFFFFF", "#000000");
            }
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_color_container"><label style="display:inline-block; width:120px; margin-top:-16px;">Text Color</label><input id="wfu_attribute_' . $attr . '_color" type="text" class="wfu_color_field" name="wfu_triplecolor_elements" value="' . $triplet[0] . '" /></div>';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_color_container"><label style="display:inline-block; width:120px; margin-top:-16px;">Background Color</label><input id="wfu_attribute_' . $attr . '_bgcolor" type="text" class="wfu_color_field" name="wfu_triplecolor_elements" value="' . $triplet[1] . '" /></div>';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_color_container"><label style="display:inline-block; width:120px; margin-top:-16px;">Border Color</label><input id="wfu_attribute_' . $attr . '_borcolor" type="text" class="wfu_color_field" name="wfu_triplecolor_elements" value="' . $triplet[2] . '" /></div>';
        } else {
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="text" name="wfu_text_elements" value="' . $def['value'] . '" />';
            if ($def['variables'] != null) {
                $echo_str .= $dlp . wfu_insert_variables($def['variables'], 'wfu_variable wfu_variable_' . $attr);
            }
        }
        $echo_str .= $dlp . "\t" . '</div></td>';
        if ($def['parent'] == "") {
            $echo_str .= $dlp . "\t" . '<td style="position:relative; vertical-align:top; padding:0;"><div class="wfu_td_div">';
            $block_open = false;
        } else {
            $echo_str .= $dlp . '</tr>';
            $subblock_open = true;
        }
    }
    if ($subblock_open) {
        $echo_str .= "\n\t\t\t\t\t\t" . '</div>';
    }
    if ($block_open) {
        $echo_str .= "\n\t\t\t\t\t" . '</div></td>';
        $echo_str .= "\n\t\t\t\t" . '</tr>';
    }
    $echo_str .= "\n\t\t\t" . '</tbody>';
    $echo_str .= "\n\t\t" . '</table>';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<div id="wfu_global_dialog_container" class="wfu_global_dialog_container">';
    $echo_str .= "\n\t" . '</div>';
    $handler = 'function() { wfu_Attach_Admin_Events(' . ($data == "" ? 'true' : 'false') . '); }';
    $echo_str .= "\n\t" . '<script type="text/javascript">if(window.addEventListener) { window.addEventListener("load", ' . $handler . ', false); } else if(window.attachEvent) { window.attachEvent("onload", ' . $handler . '); } else { window["onload"] = ' . $handler . '; }</script>';
    $echo_str .= "\n" . '</div>';
    //	$echo_str .= "\n\t".'<div style="margin-top:10px;">';
    //	$echo_str .= "\n\t\t".'<label>Final shortcode text</label>';
    //	$echo_str .= "\n\t".'</div>';
    echo $echo_str;
}
Пример #10
0
function wfu_process_files($params, $method)
{
    $sid = $params["uploadid"];
    $sesid = session_id();
    $user = wp_get_current_user();
    if (0 == $user->ID) {
        $user_id = 0;
        $user_login = "******";
        $user_email = "";
        $is_admin = false;
    } else {
        $user_id = $user->ID;
        $user_login = $user->user_login;
        $user_email = $user->user_email;
        $is_admin = current_user_can('manage_options');
    }
    $plugin_options = wfu_decode_plugin_options(get_option("wordpress_file_upload_options"));
    $unique_id = sanitize_text_field($_POST['uniqueuploadid_' . $sid]);
    // determine if this routine is only for checking the file
    $only_check = isset($_POST['only_check']) ? $_POST['only_check'] == "1" : false;
    $suppress_admin_messages = $params["adminmessages"] != "true" || !$is_admin;
    $success_count = 0;
    $warning_count = 0;
    $error_count = 0;
    $default_colors = wfu_prepare_message_colors(WFU_VAR("WFU_DEFAULTMESSAGECOLORS"));
    $notify_only_filename_list = "";
    $notify_target_path_list = "";
    $notify_attachment_list = "";
    $uploadedfile = 'uploadedfile_' . $sid;
    $hiddeninput = 'hiddeninput_' . $sid;
    $allowed_patterns = explode(",", $params["uploadpatterns"]);
    foreach ($allowed_patterns as $key => $allowed_pattern) {
        $allowed_patterns[$key] = trim($allowed_pattern);
    }
    $userdata_fields = $params["userdata_fields"];
    foreach ($userdata_fields as $userdata_key => $userdata_field) {
        $userdata_fields[$userdata_key]["value"] = isset($_POST[$hiddeninput . '_userdata_' . $userdata_key]) ? strip_tags($_POST[$hiddeninput . '_userdata_' . $userdata_key]) : "";
    }
    $params_output_array["version"] = "full";
    $params_output_array["general"]['shortcode_id'] = $sid;
    $params_output_array["general"]['unique_id'] = $unique_id;
    $params_output_array["general"]['state'] = 0;
    $params_output_array["general"]['files_count'] = 0;
    $params_output_array["general"]['update_wpfilebase'] = "";
    $params_output_array["general"]['redirect_link'] = $params["redirect"] == "true" ? $params["redirectlink"] : "";
    $params_output_array["general"]['upload_finish_time'] = 0;
    $params_output_array["general"]['message'] = "";
    $params_output_array["general"]['message_type'] = "";
    $params_output_array["general"]['admin_messages']['wpfilebase'] = "";
    $params_output_array["general"]['admin_messages']['notify'] = "";
    $params_output_array["general"]['admin_messages']['redirect'] = "";
    $params_output_array["general"]['admin_messages']['other'] = "";
    $params_output_array["general"]['errors']['wpfilebase'] = "";
    $params_output_array["general"]['errors']['notify'] = "";
    $params_output_array["general"]['errors']['redirect'] = "";
    $params_output_array["general"]['color'] = $default_colors['color'];
    $params_output_array["general"]['bgcolor'] = $default_colors['bgcolor'];
    $params_output_array["general"]['borcolor'] = $default_colors['borcolor'];
    $params_output_array["general"]['notify_only_filename_list'] = "";
    $params_output_array["general"]['notify_target_path_list'] = "";
    $params_output_array["general"]['notify_attachment_list'] = "";
    $params_output_array["general"]['fail_message'] = "";
    $params_output_array["general"]['fail_admin_message'] = "";
    /* safe_output is a minimized version of params_output_array, that is passed as text, in case JSON parse fails
    	   its data are separated by semicolon (;) and are the following:
    		upload state: the upload state number
    		default colors: the default color, bgcolor and borcolor values, separated by comma(,)
    		file_count: the number of files processed
    		filedata: message type, header, message and admin message of each file, encoded and separated by comma (,) */
    $params_output_array["general"]['safe_output'] = "";
    /* js_script is javascript code that is executed after each file upload and is defined in wfu_after_file_upload action */
    $params_output_array["general"]['js_script'] = "";
    /* adjust $uploadedfile variable (holding file data) if this is a redirection caused because the browser of the user could not handle AJAX upload */
    if (isset($_FILES[$uploadedfile . '_redirected'])) {
        $uploadedfile .= '_redirected';
    }
    /* notify admin if this is a redirection caused because the browser of the user could not handle AJAX upload */
    $params_output_array["general"]['admin_messages']['other'] = $params['adminerrors'];
    if (isset($_FILES[$uploadedfile]['error']) || $only_check) {
        $files_count = 1;
        // in case of checking of file, then the $_FILES variable has not been set because no file has been uploaded,
        // so we set it manually in order to allow the routine to continue
        if ($only_check) {
            $_FILES[$uploadedfile]['name'] = wfu_plugin_decode_string($_POST[$uploadedfile . '_name']);
            $_FILES[$uploadedfile]['type'] = 'any';
            $_FILES[$uploadedfile]['tmp_name'] = 'any';
            $_FILES[$uploadedfile]['error'] = '';
            $_FILES[$uploadedfile]['size'] = $_POST[$uploadedfile . '_size'];
        }
    } else {
        $files_count = 0;
    }
    $params_output_array["general"]['files_count'] = $files_count;
    // index of uploaded file in case of ajax uploads (in ajax uploads only one file is uploaded in every ajax call)
    // the index is used to store any file data in session variables, in case the file is uploaded in two or more passes
    // (like the case were in the first pass it is only checked)
    $single_file_index = isset($_POST[$uploadedfile . '_index']) ? $_POST[$uploadedfile . '_index'] : -1;
    /* append userdata fields to upload path */
    $search = array();
    $replace = array();
    foreach ($userdata_fields as $userdata_key => $userdata_field) {
        $ind = 1 + $userdata_key;
        array_push($search, '/%userdata' . $ind . '%/');
        array_push($replace, $userdata_field["value"]);
    }
    $params["uploadpath"] = preg_replace($search, $replace, $params["uploadpath"]);
    /* append subfolder name to upload path */
    if ($params["askforsubfolders"] == "true") {
        if ($params["subfoldertree"] == "auto+" && $params['subdir_selection_index'] != '') {
            if (substr($params["uploadpath"], -1, 1) == "/") {
                $params["uploadpath"] .= $params['subdir_selection_index'];
            } else {
                $params["uploadpath"] .= '/' . $params['subdir_selection_index'];
            }
        } elseif ($params["subfoldertree"] != "auto+" && $params['subdir_selection_index'] >= 1) {
            if (substr($params["uploadpath"], -1, 1) == "/") {
                $params["uploadpath"] .= $params['subfoldersarray'][$params['subdir_selection_index']];
            } else {
                $params["uploadpath"] .= '/' . $params['subfoldersarray'][$params['subdir_selection_index']];
            }
        }
    }
    if ($files_count == 1) {
        foreach ($_FILES[$uploadedfile] as $key => $prop) {
            $fileprops[$key] = $prop;
        }
        $upload_path_ok = false;
        $allowed_file_ok = false;
        $size_file_ok = false;
        $size_file_phpenv_ok = true;
        $ignore_server_actions = false;
        $file_output['color'] = $default_colors['color'];
        $file_output['bgcolor'] = $default_colors['bgcolor'];
        $file_output['borcolor'] = $default_colors['borcolor'];
        $file_output['header'] = "";
        $file_output['message'] = "";
        $file_output['message_type'] = "";
        $file_output['admin_messages'] = "";
        $file_output['uploaded_file_props'] = "";
        $fileid = -1;
        // determine if file data have been saved to session variables, due to a previous pass of this file
        $file_map = "filedata_" . $unique_id . "_" . $single_file_index;
        // retrieve unique id of the file, used in filter actions for identifying each separate file
        $file_unique_id = isset($_SESSION[$file_map]) ? $_SESSION[$file_map]['file_unique_id'] : '';
        $filedata_previously_defined = $file_unique_id != '';
        /* generate unique id for each file for use in filter actions if it has not been previously defined */
        if (!$filedata_previously_defined) {
            $file_unique_id = wfu_create_random_string(20);
        }
        /* Get uploaded file size in Mbytes */
        // correct file size in case of checking of file otherwise $upload_file_size will be zero and the routine will fail
        if ($only_check) {
            $upload_file_size = $fileprops['size'];
            if ($upload_file_size == 0) {
                $upload_file_size++;
            }
        } else {
            $upload_file_size = filesize($fileprops['tmp_name']);
            if ($upload_file_size == 0 && file_exists($fileprops['tmp_name']) && $fileprops['error'] == 0) {
                $upload_file_size++;
            }
        }
        $upload_file_size_MB = $upload_file_size / 1024 / 1024;
        $only_filename = $fileprops['name'];
        $target_path = wfu_upload_plugin_full_path($params) . $only_filename;
        if ($upload_file_size > 0) {
            /* Section to perform filter action wfu_before_file_check before file is checked in order to perform
               any filename or userdata modifications or reject the upload of the file by setting error_message item
               of $ret_data array to a non-empty value */
            $filter_error_message = '';
            $filter_admin_message = '';
            if ($file_unique_id != '' && !$filedata_previously_defined) {
                /* store file data and upload result to filemap session array 
                   for use by after_upload filters */
                if (!isset($_SESSION["filedata_" . $unique_id])) {
                    $_SESSION["filedata_" . $unique_id] = array();
                }
                $real_file_index = $single_file_index;
                if ($single_file_index == -1) {
                    $real_file_index = $i;
                }
                // get correct file size
                if ($only_check) {
                    $filesize = $fileprops['size'];
                } else {
                    $filesize = filesize($fileprops['tmp_name']);
                }
                $_SESSION["filedata_" . $unique_id][$real_file_index] = array("file_unique_id" => $file_unique_id, "original_filename" => $only_filename, "filesize" => $filesize);
                // prepare parameters for wfu_before_file_check filter
                $changable_data['file_path'] = $target_path;
                $changable_data['user_data'] = $userdata_fields;
                $changable_data['error_message'] = $filter_error_message;
                $changable_data['admin_message'] = $filter_admin_message;
                $additional_data['shortcode_id'] = $sid;
                $additional_data['file_unique_id'] = $file_unique_id;
                $additional_data['file_size'] = $filesize;
                $additional_data['user_id'] = $user->ID;
                $additional_data['page_id'] = $params["pageid"];
                $ret_data = apply_filters('wfu_before_file_check', $changable_data, $additional_data);
                $target_path = $ret_data['file_path'];
                $only_filename = wfu_basename($target_path);
                $userdata_fields = $ret_data['user_data'];
                $filter_error_message = $ret_data['error_message'];
                $filter_admin_message = $ret_data['admin_message'];
                // if this is a file check, which means that a second pass of the file will follow, then we do not want to
                // apply the filters again, so we store the changable data to session variables for this specific file
                if ($only_check) {
                    $_SESSION[$file_map]['file_unique_id'] = $file_unique_id;
                    $_SESSION[$file_map]['filepath'] = $target_path;
                    $_SESSION[$file_map]['userdata'] = $userdata_fields;
                }
            }
            // if this is a second pass of the file, because a first pass with file checking was done before, then retrieve
            // file data that may have previously changed because of application of filters
            if ($filedata_previously_defined) {
                $target_path = $_SESSION[$file_map]['filepath'];
                $only_filename = wfu_basename($target_path);
                $userdata_fields = $_SESSION[$file_map]['userdata'];
            }
            if ($filter_error_message != '') {
                //errorabort flag designates that file will be aborted and no resuming will be attempted
                $file_output['message_type'] = "errorabort";
                $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], $filter_error_message);
                if ($filter_admin_message != '') {
                    $file_output['admin_messages'] = wfu_join_strings("<br />", $file_output['admin_messages'], $filter_admin_message);
                }
            } else {
                /* generate safe filename by removing invalid characters if forcefilename is deactivated */
                if ($params['forcefilename'] != "true") {
                    $only_filename = wfu_upload_plugin_clean($only_filename);
                    //reconstruct target_path
                    $target_path = wfu_basedir($target_path) . $only_filename;
                }
                /* if medialink or postlink is activated then the target path becomes the current wordpress upload folder */
                if ($params["medialink"] == "true" || $params["postlink"] == "true") {
                    $mediapath = wp_upload_dir();
                    $target_path = $mediapath['path'] . '/' . $only_filename;
                }
                /* Check if upload path exist */
                if (is_dir(wfu_basedir($target_path))) {
                    $upload_path_ok = true;
                } else {
                    if ($params["createpath"] == "true") {
                        $wfu_create_directory_ret = wfu_create_directory(wfu_basedir($target_path), $params["accessmethod"], $params["ftpinfo"]);
                        if ($wfu_create_directory_ret != "") {
                            $file_output['admin_messages'] = wfu_join_strings("<br />", $file_output['admin_messages'], $wfu_create_directory_ret);
                        }
                        if (is_dir(wfu_basedir($target_path))) {
                            $upload_path_ok = true;
                        }
                    }
                }
                /* File name control, reject files with .php, .js (and other) extensions for security reasons.
                   This is the first pass of extension control, which only checks the filename.
                   A second pass is performed after the file has completely uploaded, using WP inherent file
                   extension control, which provides better security. */
                if (!wfu_file_extension_restricted(strtolower($only_filename))) {
                    foreach ($allowed_patterns as $allowed_pattern) {
                        if (wfu_upload_plugin_wildcard_match($allowed_pattern, $only_filename)) {
                            $allowed_file_ok = true;
                            break;
                        }
                    }
                }
                /* File size control */
                if ($upload_file_size_MB <= $params["maxsize"]) {
                    if ($params['php_env'] == '32bit' && $upload_file_size > 2147483647) {
                        $size_file_phpenv_ok = false;
                    } else {
                        $size_file_ok = true;
                    }
                }
                if (!$upload_path_ok or !$allowed_file_ok or !$size_file_ok) {
                    //abort the file, no resuming will be attempted
                    $file_output['message_type'] = "errorabort";
                    $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_UPLOAD_FAILED);
                    if (!$upload_path_ok) {
                        $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_DIR_EXIST);
                    }
                    if (!$allowed_file_ok) {
                        $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_FILE_ALLOW);
                    }
                    if (!$size_file_ok) {
                        if ($size_file_phpenv_ok) {
                            $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_FILE_PLUGIN_SIZE);
                        } else {
                            $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_FILE_PLUGIN_2GBSIZE);
                        }
                    }
                }
            }
        } else {
            // This block is executed when there is an error
            $upload_error = $fileprops['error'];
            if ($upload_error == 1) {
                $message_text = WFU_ERROR_FILE_PHP_SIZE;
                $file_output['admin_messages'] = wfu_join_strings("<br />", $file_output['admin_messages'], WFU_ERROR_ADMIN_FILE_PHP_SIZE);
            } elseif ($upload_error == 2) {
                $message_text = WFU_ERROR_FILE_HTML_SIZE;
            } elseif ($upload_error == 3) {
                $message_text = WFU_ERROR_FILE_PARTIAL;
            } elseif ($upload_error == 4) {
                $message_text = WFU_ERROR_FILE_NOTHING;
            } elseif ($upload_error == 6) {
                $message_text = WFU_ERROR_DIR_NOTEMP;
            } elseif ($upload_error == 7) {
                $message_text = WFU_ERROR_FILE_WRITE;
            } elseif ($upload_error == 8) {
                $message_text = WFU_ERROR_UPLOAD_STOPPED;
            } else {
                $upload_time_limit = ini_get("max_input_time");
                $params_output_array["general"]['upload_finish_time'] = $params["upload_start_time"] + $upload_time_limit * 1000;
                $message_text = WFU_ERROR_FILE_PHP_TIME;
                $file_output['admin_messages'] = wfu_join_strings("<br />", $file_output['admin_messages'], WFU_ERROR_ADMIN_FILE_PHP_TIME);
            }
            //error (and not errorabort) flag designates that a resuming of the file may be attempted
            $file_output['message_type'] = "error";
            $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], $message_text);
        }
        $message_processed = false;
        //		if ( $upload_path_ok and $allowed_file_ok and $size_file_ok ) {
        if (substr($file_output['message_type'], 0, 5) != "error") {
            if (is_uploaded_file($fileprops['tmp_name']) || $only_check) {
                $source_path = $fileprops['tmp_name'];
                if ($only_check || $ignore_server_actions) {
                    $file_copied = true;
                } else {
                    $file_copied = false;
                    if ($source_path) {
                        $file_exists = file_exists($target_path);
                        if (!$file_exists || $params["dublicatespolicy"] == "" || $params["dublicatespolicy"] == "overwrite") {
                            //redirect echo in internal buffer to receive and process any unwanted warning messages from wfu_upload_file
                            ob_start();
                            ob_clean();
                            /* Apply wfu_before_file_upload filter right before the upload, in order to allow the user to change the file name.
                               If additional data are required, such as user_id or userdata values, they can be retrieved by implementing the
                               previous filter wfu_before_file_check, corresponding them to the unique file id */
                            if ($file_unique_id != '') {
                                $target_path = apply_filters('wfu_before_file_upload', $target_path, $file_unique_id);
                            }
                            //recalculate $only_filename in case it changed with wfu_before_file_upload filter
                            $only_filename = wfu_basename($target_path);
                            //move the uploaded file to its final destination
                            $wfu_upload_file_ret = wfu_upload_file($source_path, $target_path, $params["accessmethod"], $params["ftpinfo"], $params["ftppassivemode"], $params["ftpfilepermissions"]);
                            $file_copied = $wfu_upload_file_ret["uploaded"];
                            //process warning messages from wfu_upload_file
                            $echo_message = ob_get_contents();
                            //finish redirecting of echo to internal buffer
                            ob_end_clean();
                            if ($echo_message != "" && !$file_copied) {
                                //error (and not errorabort) flag designates that file may be resumed
                                $file_output['message_type'] = "error";
                                if (stristr($echo_message, "warning") && stristr($echo_message, "permission denied") && stristr($echo_message, "unable to move")) {
                                    $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_DIR_PERMISSION);
                                    $file_output['admin_messages'] = wfu_join_strings("<br />", $file_output['admin_messages'], WFU_ERROR_ADMIN_DIR_PERMISSION);
                                } else {
                                    $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_FILE_MOVE);
                                    $file_output['admin_messages'] = wfu_join_strings("<br />", $file_output['admin_messages'], strip_tags($echo_message));
                                }
                                $message_processed = true;
                            }
                            if ($wfu_upload_file_ret["admin_message"] != "") {
                                $file_output['admin_messages'] = wfu_join_strings("<br />", $file_output['admin_messages'], $wfu_upload_file_ret["admin_message"]);
                            }
                        } else {
                            if ($file_exists && $params["dublicatespolicy"] == "maintain both") {
                                $full_path = wfu_basedir($target_path);
                                $name_part = $only_filename;
                                $ext_part = "";
                                $dot_pos = strrpos($name_part, ".");
                                if ($dot_pos) {
                                    $ext_part = substr($name_part, $dot_pos);
                                    $name_part = substr($name_part, 0, $dot_pos);
                                }
                                if ($params["uniquepattern"] != "datetimestamp") {
                                    $unique_ind = 1;
                                    do {
                                        $unique_ind += 1;
                                        $only_filename = $name_part . "(" . $unique_ind . ")" . $ext_part;
                                        $target_path = $full_path . $only_filename;
                                    } while (file_exists($target_path));
                                } else {
                                    $current_datetime = gmdate("U") - 1;
                                    do {
                                        $current_datetime += 1;
                                        $only_filename = $name_part . "-" . gmdate("YmdHis", $current_datetime) . $ext_part;
                                        $target_path = $full_path . $only_filename;
                                    } while (file_exists($target_path));
                                }
                                //redirect echo in internal buffer to receive and process any unwanted warning messages from move_uploaded_file
                                ob_start();
                                ob_clean();
                                /* Apply wfu_before_file_upload filter right before the upload, in order to allow the user to change the file name.
                                   If additional data are required, such as user_id or userdata values, they can be retrieved by implementing the
                                   previous filter wfu_before_file_check, corresponding them to the unique file id */
                                if ($file_unique_id != '') {
                                    $target_path = apply_filters('wfu_before_file_upload', $target_path, $file_unique_id);
                                }
                                //recalculate $only_filename in case it changed with wfu_before_file_upload filter
                                $only_filename = wfu_basename($target_path);
                                //move the uploaded file to its final destination
                                $wfu_upload_file_ret = wfu_upload_file($source_path, $target_path, $params["accessmethod"], $params["ftpinfo"], $params["ftppassivemode"], $params["ftpfilepermissions"]);
                                $file_copied = $wfu_upload_file_ret["uploaded"];
                                //process warning messages from move_uploaded_file
                                $echo_message = ob_get_contents();
                                //finish redirecting of echo to internal buffer
                                ob_end_clean();
                                if ($echo_message != "" && !$file_copied) {
                                    //error (and not errorabort) flag designates that file may be resumed
                                    $file_output['message_type'] = "error";
                                    if (stristr($echo_message, "warning") && stristr($echo_message, "permission denied") && stristr($echo_message, "unable to move")) {
                                        $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_DIR_PERMISSION);
                                        $file_output['admin_messages'] = wfu_join_strings("<br />", $file_output['admin_messages'], WFU_ERROR_ADMIN_DIR_PERMISSION);
                                    } else {
                                        $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_FILE_MOVE);
                                        $file_output['admin_messages'] = wfu_join_strings("<br />n", $file_output['admin_messages'], strip_tags($echo_message));
                                    }
                                    $message_processed = true;
                                }
                                if ($wfu_upload_file_ret["admin_message"] != "") {
                                    $file_output['admin_messages'] = wfu_join_strings("<br />", $file_output['admin_messages'], $wfu_upload_file_ret["admin_message"]);
                                }
                            } else {
                                //abort the file and do not allow resuming
                                $file_output['message_type'] = "errorabort";
                                $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_WARNING_FILE_EXISTS);
                                $message_processed = true;
                                $file_copied = false;
                            }
                        }
                    }
                }
                if ($file_copied) {
                    /* prepare email notification parameters if email notification is enabled */
                    if ($params["notify"] == "true" && !$only_check) {
                        $notify_only_filename_list .= ($notify_only_filename_list == "" ? "" : ", ") . $only_filename;
                        $notify_target_path_list .= ($notify_target_path_list == "" ? "" : ", ") . $target_path;
                        if ($params["attachfile"] == "true") {
                            $notify_attachment_list .= ($notify_attachment_list == "" ? "" : ",") . $target_path;
                        }
                    }
                    /* prepare redirect link if redirection is enabled */
                    if ($params["redirect"] == "true") {
                        /* Define dynamic redirect link from variables */
                        $search = array('/%filename%/', '/%username%/');
                        $replace = array($only_filename, $user_login);
                        $params_output_array["general"]['redirect_link'] = trim(preg_replace($search, $replace, $params["redirectlink"]));
                    }
                    if (!$message_processed) {
                        $file_output['message_type'] = "success";
                    }
                } else {
                    if (!$message_processed) {
                        //abort the file and do not allow resuming
                        $file_output['message_type'] = "errorabort";
                        $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_UNKNOWN);
                    }
                }
                /* Delete temporary file (in tmp directory) */
                //				unlink($source_path);
            } else {
                //abort the file and do not allow resuming
                $file_output['message_type'] = "errorabort";
                $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_UNKNOWN);
            }
        }
        /* last check of output file status */
        if ($file_output['message_type'] == "") {
            if ($file_copied) {
                $file_output['message_type'] = "success";
            } else {
                //abort the file and do not allow resuming
                $file_output['message_type'] = "errorabort";
                $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_UNKNOWN);
            }
        }
        /* suppress any admin messages if user is not administrator or adminmessages is not activated */
        if ($suppress_admin_messages) {
            $file_output['admin_messages'] = "";
        }
        /* set file status to "warning" if the file has been uploaded but there are messages */
        if ($file_output['message_type'] == "success") {
            if ($file_output['message'] != "" || $file_output['admin_messages'] != "") {
                $file_output['message_type'] = "warning";
            }
        }
        /* set success status of the file, to be used for medialink and post actions */
        $file_finished_successfully = !$only_check && ($file_output['message_type'] == "success" || $file_output['message_type'] == "warning");
        /* set non-success status of the file, to be used for medialink and post actions */
        $file_finished_unsuccessfully = substr($file_output['message_type'], 0, 5) == "error";
        /* perform custom actions after file is completely uploaded in order to determine if file is valid ir not */
        if ($file_finished_successfully && !$ignore_server_actions) {
            /* Here the second pass of file extension control is performed after the file has completely
               uploaded, using WP inherent functions that determine the real extension from analyzing the
               data and not from the filename extension. If this check reveals an extension which is not
               permitted then the file will be rejected and erased. If the real extension is different
               than the original one but it is permitted, then the file will remain as it is but a warning
               message will notify the user that the extension of the file does not match its contents. */
            $check = wp_check_filetype_and_ext($target_path, $only_filename, false);
            if ($check['proper_filename'] !== false) {
                $proper_filename = $check['proper_filename'];
                if (wfu_file_extension_restricted(strtolower($only_filename))) {
                    $file_finished_successfully = false;
                    $file_finished_unsuccessfully = true;
                    unlink($target_path);
                    $file_output['message_type'] = "errorabort";
                    $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_ERROR_FILE_REJECT);
                    $file_output['admin_messages'] = wfu_join_strings("<br />", $file_output['admin_messages'], WFU_ERROR_ADMIN_FILE_WRONGEXT . $check['proper_filename']);
                } else {
                    $file_output['message_type'] = "warning";
                    $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], WFU_WARNING_FILE_SUSPICIOUS);
                    $file_output['admin_messages'] = wfu_join_strings("<br />", $file_output['admin_messages'], WFU_WARNING_ADMIN_FILE_SUSPICIOUS . $check['proper_filename']);
                }
            }
            // run any wfu_after_file_loaded filters to make any last file checks and accept or reject it
            if ($file_finished_successfully) {
                $filter_error_message = '';
                $filter_admin_message = '';
                $changable_data['error_message'] = $filter_error_message;
                $changable_data['admin_message'] = $filter_admin_message;
                $additional_data['file_unique_id'] = $file_unique_id;
                $additional_data['file_path'] = $target_path;
                $additional_data['shortcode_id'] = $sid;
                $ret_data = apply_filters('wfu_after_file_loaded', $changable_data, $additional_data);
                //this is a call to wfu_after_file_complete filters, which is
                //the old name of wfu_after_file_loaded filters, for maintaining
                //backward compatibility
                $ret_data = apply_filters('wfu_after_file_complete', $changable_data, $additional_data);
                $filter_error_message = $ret_data['error_message'];
                $filter_admin_message = $ret_data['admin_message'];
                if ($filter_error_message != '') {
                    $file_finished_successfully = false;
                    $file_finished_unsuccessfully = true;
                    unlink($target_path);
                    $file_output['message_type'] = "errorabort";
                    $file_output['message'] = wfu_join_strings("<br />", $file_output['message'], $filter_error_message);
                    if ($filter_admin_message != '') {
                        $file_output['admin_messages'] = wfu_join_strings("<br />", $file_output['admin_messages'], $filter_admin_message);
                    }
                }
            }
        }
        /* adjust message details and colors according to file result */
        /* FileResult: A */
        $search = array('/%username%/', '/%useremail%/', '/%filename%/', '/%filepath%/');
        $replace = array($user_login, $user_email == "" ? "no email" : $user_email, $only_filename, $target_path);
        if ($file_output['message_type'] == "success") {
            $success_count++;
            $color_array = explode(",", $params['successmessagecolors']);
            $file_output['color'] = $color_array[0];
            $file_output['bgcolor'] = $color_array[1];
            $file_output['borcolor'] = $color_array[2];
            $file_output['header'] = preg_replace($search, $replace, $params['successmessage']);
            /* prepare details of successful file upload, visible only to administrator */
            $file_output['admin_messages'] = wfu_join_strings("<br />", preg_replace($search, $replace, WFU_SUCCESSMESSAGE_DETAILS), $file_output['admin_messages']);
        } elseif ($file_output['message_type'] == "warning") {
            $warning_count++;
            $color_array = explode(",", $params['warningmessagecolors']);
            $file_output['color'] = $color_array[0];
            $file_output['bgcolor'] = $color_array[1];
            $file_output['borcolor'] = $color_array[2];
            $file_output['header'] = preg_replace($search, $replace, $params['warningmessage']);
            /* prepare and prepend details of successful file upload, visible only to administrator */
            $file_output['admin_messages'] = wfu_join_strings("<br />", preg_replace($search, $replace, WFU_SUCCESSMESSAGE_DETAILS), $file_output['admin_messages']);
        } elseif (substr($file_output['message_type'], 0, 5) == "error") {
            $error_count++;
            $color_array = explode(",", $params['failmessagecolors']);
            $file_output['color'] = $color_array[0];
            $file_output['bgcolor'] = $color_array[1];
            $file_output['borcolor'] = $color_array[2];
            $replace = array($user_login, $user_email == "" ? "no email" : $user_email, $only_filename, $target_path);
            $file_output['header'] = preg_replace($search, $replace, $params['errormessage']);
            /* prepare and prepend details of failed file upload, visible only to administrator */
            $file_output['admin_messages'] = wfu_join_strings("<br />", preg_replace($search, $replace, WFU_FAILMESSAGE_DETAILS), $file_output['admin_messages']);
        }
        /* suppress again any admin messages if user is not administrator or adminmessages is not activated */
        if ($suppress_admin_messages) {
            $file_output['admin_messages'] = "";
        }
        $params_output_array[0] = $file_output;
        if ($file_unique_id != '' && $file_finished_unsuccessfully && !$ignore_server_actions) {
            /* Apply wfu_after_file_upload filter after failed upload, in order to allow the user to perform any post-upload actions.
               If additional data are required, such as user_id or userdata values or filepath, they can be retrieved by implementing
               the previous filters wfu_before_file_check and wfu_before_file_upload, corresponding them to the unique file id.
               This actions allows to define custom javascript code to run after each file finishes (either succeeded or failed).
               For backward compatibility, the wfu_after_file_upload action that was implemented in previous version of the plugin
               still remains. */
            $changable_data['ret_value'] = null;
            $changable_data['js_script'] = '';
            $additional_data['shortcode_id'] = $sid;
            $additional_data['file_unique_id'] = $file_unique_id;
            $additional_data['upload_result'] = $file_output['message_type'];
            $additional_data['error_message'] = $file_output['message'];
            $additional_data['admin_messages'] = $file_output['admin_messages'];
            $ret_data = apply_filters('wfu_after_file_upload', $changable_data, $additional_data);
            $params_output_array["general"]['js_script'] = $ret_data['js_script'];
            //			do_action('wfu_after_file_upload', $file_unique_id, $file_output['message_type'], $file_output['message'], $file_output['admin_messages']);
        }
        if ($file_finished_successfully && !$ignore_server_actions) {
            /* log file upload action if file has finished uploading successfully */
            $fileid = wfu_log_action('upload', $target_path, $user->ID, $unique_id, $params['pageid'], $params['blogid'], $sid, $userdata_fields);
            /* Apply wfu_after_file_upload filter after failed upload, in order to allow the user to perform any post-upload actions.
               If additional data are required, such as user_id or userdata values or filepath, they can be retrieved by implementing
               the previous filters wfu_before_file_check and wfu_before_file_upload, corresponding them to the unique file id.
               This actions allows to define custom javascript code to run after each file finishes (either suceeded or failed).
               For backward compatibility, the wfu_after_file_upload action that was implemented in previous version of the plugin
               still remains. */
            $changable_data['ret_value'] = null;
            $changable_data['js_script'] = '';
            $additional_data['shortcode_id'] = $sid;
            $additional_data['file_unique_id'] = $file_unique_id;
            $additional_data['upload_result'] = $file_output['message_type'];
            $additional_data['error_message'] = $file_output['message'];
            $additional_data['admin_messages'] = $file_output['admin_messages'];
            $ret_data = apply_filters('wfu_after_file_upload', $changable_data, $additional_data);
            $params_output_array["general"]['js_script'] = $ret_data['js_script'];
            //			do_action('wfu_after_file_upload', $file_unique_id, $file_output['message_type'], $file_output['message'], $file_output['admin_messages']);
        }
        /* add file to Media or attach file to current post if any of these options is activated and the file has finished uploading successfully */
        if (($params["medialink"] == "true" || $params["postlink"] == "true") && $file_finished_successfully && !$ignore_server_actions) {
            $pageid = $params["postlink"] == "true" ? $params['pageid'] : 0;
            wfu_process_media_insert($target_path, $pageid);
        }
        /* store final file data and upload result to filemap session array for
           use by after_upload filters */
        $real_file_index = $single_file_index;
        if ($single_file_index == -1) {
            $real_file_index = $i;
        }
        if (($file_finished_successfully || $file_finished_unsuccessfully) && isset($_SESSION["filedata_" . $unique_id][$real_file_index]) && !$ignore_server_actions) {
            $_SESSION["filedata_" . $unique_id][$real_file_index]["filepath"] = $target_path;
            $_SESSION["filedata_" . $unique_id][$real_file_index]["user_data"] = $userdata_fields;
            $_SESSION["filedata_" . $unique_id][$real_file_index]["upload_result"] = $file_output['message_type'];
            $_SESSION["filedata_" . $unique_id][$real_file_index]["message"] = $file_output['message'];
            $_SESSION["filedata_" . $unique_id][$real_file_index]["admin_messages"] = $file_output['admin_messages'];
        }
    }
    // in case of file check set files_count to 0 in order to denote that the file was not really uploaded
    if ($only_check) {
        $params_output_array["general"]['files_count'] = 0;
    }
    $somefiles_Ok = $warning_count + $success_count > 0;
    $allfiles_Ok = $somefiles_Ok && $error_count == 0;
    /* Prepare WPFileBase Plugin update url, if this option has been selected and only if at least one file has been successfully uploaded.
       Execution will happen only if accumulated $params_output_array["general"]['update_wpfilebase'] is not empty */
    if ($params["filebaselink"] == "true") {
        if ($somefiles_Ok) {
            $filebaseurl = site_url();
            if (substr($filebaseurl, -1, 1) == "/") {
                $filebaseurl = substr($filebaseurl, 0, strlen($filebaseurl) - 1);
            }
            /* if the following variable is not empty, then WPFileBase Plugin update must be executed
               and any admin messages must be suppressed */
            $params_output_array["general"]['update_wpfilebase'] = $filebaseurl;
        } else {
            $params_output_array["general"]['admin_messages']['wpfilebase'] = WFU_WARNING_WPFILEBASE_NOTUPDATED_NOFILES;
            $params_output_array["general"]['errors']['wpfilebase'] = "error";
        }
    }
    /* Prepare email notification parameters if email notification is enabled and only if at least one file has been successfully uploaded
       	if $method = "no-ajax" then send the email to the recipients 
       	if $method = "ajax" then return the notification parameters to the handler for further processing
       In case of ajax, execution will happen only if accumulated notify_only_filename_list is not empty */
    if ($params["notify"] == "true") {
        /* verify that there are recipients */
        $notifyrecipients = trim(preg_replace('/%useremail%/', $user_email, $params["notifyrecipients"]));
        if ($notifyrecipients != "") {
            if ($somefiles_Ok) {
                if ($method == 'no_ajax' && !$ignore_server_actions) {
                    $send_error = wfu_send_notification_email($user, $notify_only_filename_list, $notify_target_path_list, $notify_attachment_list, $userdata_fields, $params);
                    if ($send_error != "") {
                        $params_output_array["general"]['admin_messages']['notify'] = $send_error;
                        $params_output_array["general"]['errors']['notify'] = "error";
                    }
                } else {
                    /* if the following variable is not empty, then email notification must be sent
                       and any admin messages must be suppressed */
                    $params_output_array["general"]['notify_only_filename_list'] = $notify_only_filename_list;
                    $params_output_array["general"]['notify_target_path_list'] = $notify_target_path_list;
                    $params_output_array["general"]['notify_attachment_list'] = $notify_attachment_list;
                }
            } else {
                $params_output_array["general"]['admin_messages']['notify'] = WFU_WARNING_NOTIFY_NOTSENT_NOFILES;
                $params_output_array["general"]['errors']['notify'] = "error";
            }
        } else {
            $params_output_array["general"]['admin_messages']['notify'] = WFU_WARNING_NOTIFY_NOTSENT_NORECIPIENTS;
            $params_output_array["general"]['errors']['notify'] = "error";
        }
    }
    /* Prepare redirect link if redirection is enabled and only if all files have been successfully uploaded
       Execution will happen only if accumulated redirect_link is not empty and accumulated redirect errors are empty */
    if ($params["redirect"] == "true") {
        if ($params_output_array["general"]['redirect_link'] == "") {
            $params_output_array["general"]['admin_messages']['redirect'] = WFU_WARNING_REDIRECT_NOTEXECUTED_EMPTY;
            $params_output_array["general"]['errors']['redirect'] = "error";
        } elseif (!$allfiles_Ok) {
            $params_output_array["general"]['admin_messages']['redirect'] = WFU_WARNING_REDIRECT_NOTEXECUTED_FILESFAILED;
            $params_output_array["general"]['errors']['redirect'] = "error";
        }
    }
    /* suppress any admin messages if user is not administrator or adminmessages is not activated */
    if ($suppress_admin_messages) {
        $params_output_array["general"]['admin_messages']['wpfilebase'] = "";
        $params_output_array["general"]['admin_messages']['notify'] = "";
        $params_output_array["general"]['admin_messages']['redirect'] = "";
        $params_output_array["general"]['admin_messages']['other'] = "";
    }
    /* Calculate upload state from file results */
    if ($allfiles_Ok && $warning_count == 0) {
        $params_output_array["general"]['state'] = 4;
    } else {
        if ($allfiles_Ok) {
            $params_output_array["general"]['state'] = 5;
        } else {
            if ($somefiles_Ok) {
                $params_output_array["general"]['state'] = 6;
            } else {
                if (!$somefiles_Ok && $error_count > 0) {
                    $params_output_array["general"]['state'] = 7;
                } else {
                    $params_output_array["general"]['state'] = 8;
                }
            }
        }
    }
    /* construct safe output */
    $sout = $params_output_array["general"]['state'] . ";" . WFU_VAR("WFU_DEFAULTMESSAGECOLORS") . ";" . $files_count;
    for ($i = 0; $i < $files_count; $i++) {
        $sout .= ";" . wfu_plugin_encode_string($file_output['message_type']);
        $sout .= "," . wfu_plugin_encode_string($file_output['header']);
        $sout .= "," . wfu_plugin_encode_string($file_output['message']);
        $sout .= "," . wfu_plugin_encode_string($file_output['admin_messages']);
        $sout .= "," . $file_output['uploaded_file_props'];
    }
    $params_output_array["general"]['safe_output'] = $sout;
    return $params_output_array;
}
Пример #11
0
function wfu_shortcode_composer($data = '', $shortcode_tag = 'wordpress_file_upload')
{
    global $wpdb;
    global $wp_roles;
    $siteurl = site_url();
    $components = wfu_component_definitions();
    if ($shortcode_tag == 'wordpress_file_upload') {
        $cats = wfu_category_definitions();
        $defs = wfu_attribute_definitions();
    } else {
        $cats = wfu_browser_category_definitions();
        $defs = wfu_browser_attribute_definitions();
    }
    $plugin_options = wfu_decode_plugin_options(get_option("wordpress_file_upload_options"));
    if ($data == "") {
        $shortcode = $plugin_options['shortcode'];
        $shortcode_full = '[' . $shortcode_tag . ' ' . $shortcode . ']';
        $postid = "";
        $postname = "";
        $posttype = "";
        $posthash = "";
        $shortcode_position = -1;
        $autosave = true;
    } else {
        $shortcode = trim(substr($data['shortcode'], strlen('[' . $shortcode_tag), -1));
        $shortcode_full = $data['shortcode'];
        $postid = $data['post_id'];
        $postname = get_the_title($postid);
        $posttype = get_post_type($postid);
        $posthash = $data['post_hash'];
        $shortcode_position = $data['position'];
        $autosave = false;
    }
    $shortcode_attrs = wfu_shortcode_string_to_array($shortcode);
    $shortcode_id = '';
    foreach ($defs as $key => $def) {
        $defs[$key]['default'] = $def['value'];
        if (array_key_exists($def['attribute'], $shortcode_attrs)) {
            $defs[$key]['value'] = $shortcode_attrs[$def['attribute']];
        }
        if ($def['attribute'] == 'uploadid' || $def['attribute'] == 'browserid') {
            $shortcode_id = $defs[$key]['value'];
        }
    }
    // index $components
    $components_indexed = array();
    foreach ($components as $component) {
        $components_indexed[$component['id']] = $component;
    }
    // index dependiencies
    $governors = array();
    $echo_str = '<div id="wfu_wrapper" class="wrap">';
    $echo_str .= "\n\t" . '<h2>Wordpress File Upload Control Panel</h2>';
    $echo_str .= "\n\t" . '<div id="wfu_page_obsolete_message" class="error" style="display:none;">';
    $echo_str .= "\n\t\t" . '<p>' . WFU_DASHBOARD_PAGE_OBSOLETE . '</p>';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<div id="wfu_update_rejected_message" class="error" style="display:none;">';
    $echo_str .= "\n\t\t" . '<p>' . WFU_DASHBOARD_UPDATE_SHORTCODE_REJECTED . '</p>';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<div id="wfu_update_failed_message" class="error" style="display:none;">';
    $echo_str .= "\n\t\t" . '<p>' . WFU_DASHBOARD_UPDATE_SHORTCODE_FAILED . '</p>';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<div style="margin-top:20px;">';
    if (current_user_can('manage_options')) {
        $echo_str .= "\n\t" . '<a href="' . $siteurl . '/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=manage_mainmenu" class="button" title="go back">Go to Main Menu</a>';
    }
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<h2 style="margin-bottom: 10px; margin-top: 20px;">Shortcode Composer for ' . ($data == "" ? 'Test' : $posttype . ' "' . $postname . '" (' . $postid . ') Position ' . $data['position']) . ' with ID ' . $shortcode_id . '</h2>';
    $echo_str .= "\n\t" . '<div style="margin-top:10px; display:inline-block;">';
    if ($data != "") {
        $echo_str .= "\n\t\t" . '<input id="wfu_update_shortcode" type="button" value="Update" class="button-primary" disabled="disabled" onclick="wfu_save_shortcode()" /><span id="wfu_update_shortcode_wait" class="spinner" style="float:right; display:none;"></span>';
    }
    $echo_str .= "\n\t\t" . '<input id="wfu_shortcode_original_enc" type="hidden" value="' . wfu_plugin_encode_string($shortcode_full) . '" />';
    $echo_str .= "\n\t\t" . '<input id="wfu_shortcode_tag" type="hidden" value="' . $shortcode_tag . '" />';
    $echo_str .= "\n\t\t" . '<input id="wfu_shortcode_postid" type="hidden" value="' . $postid . '" />';
    $echo_str .= "\n\t\t" . '<input id="wfu_shortcode_posthash" type="hidden" value="' . $posthash . '" />';
    $echo_str .= "\n\t\t" . '<input id="wfu_shortcode_position" type="hidden" value="' . $shortcode_position . '" />';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<div style="margin-top:20px;">';
    $echo_str .= "\n\t\t" . '<div class="wfu_shortcode_container">';
    $echo_str .= "\n\t\t\t" . '<span><strong>Generated Shortcode</strong></span>';
    $echo_str .= "\n\t\t\t" . '<span id="wfu_save_label" class="wfu_save_label">saved</span>';
    $echo_str .= "\n\t\t\t" . '<textarea id="wfu_shortcode" class="wfu_shortcode" rows="5">[' . $shortcode_tag . ']</textarea>';
    $echo_str .= "\n\t\t\t" . '<div id="wfu_attribute_defaults" style="display:none;">';
    foreach ($defs as $def) {
        $echo_str .= "\n\t\t\t\t" . '<input id="wfu_attribute_default_' . $def['attribute'] . '" type="hidden" value="' . $def['default'] . '" />';
    }
    $echo_str .= "\n\t\t\t" . '</div>';
    $echo_str .= "\n\t\t\t" . '<div id="wfu_attribute_values" style="display:none;">';
    foreach ($defs as $def) {
        $echo_str .= "\n\t\t\t\t" . '<input id="wfu_attribute_value_' . $def['attribute'] . '" type="hidden" value="' . $def['value'] . '" />';
    }
    $echo_str .= "\n\t\t\t" . '</div>';
    $echo_str .= "\n\t\t" . '</div>';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<h3 id="wfu_tab_container" class="nav-tab-wrapper">';
    $is_first = true;
    foreach ($cats as $key => $cat) {
        $echo_str .= "\n\t\t" . '<a id="wfu_tab_' . $key . '" class="nav-tab' . ($is_first ? ' nav-tab-active' : '') . '" href="javascript: wfu_admin_activate_tab(\'' . $key . '\');">' . $cat . '</a>';
        $is_first = false;
    }
    $echo_str .= "\n\t" . '</h3>';
    $prevcat = "";
    $prevsubcat = "";
    $is_first = true;
    $block_open = false;
    $subblock_open = false;
    foreach ($defs as $def) {
        $attr = $def['attribute'];
        $subblock_active = false;
        //detect if the dependencies of this attribute will be disabled or not
        if ($def['type'] == "onoff" && $def['value'] == "true" || $def['type'] == "radio" && in_array("*" . $def['value'], $def['listitems'])) {
            $subblock_active = true;
        }
        // assign dependencies if exist
        if ($def['dependencies'] != null) {
            foreach ($def['dependencies'] as $dependency) {
                if (substr($dependency, 0, 1) == "!") {
                    //invert state for this dependency if an exclamation mark is defined
                    $governors[substr($dependency, 1)] = array('attribute' => $attr, 'active' => !$subblock_active, 'inv' => '_inv');
                } else {
                    $governors[$dependency] = array('attribute' => $attr, 'active' => $subblock_active, 'inv' => '');
                }
            }
        }
        //check if this attribute depends on other
        if (!array_key_exists($attr, $governors)) {
            $governors[$attr] = "";
        }
        if ($governors[$attr] != "") {
            $governor = $governors[$attr];
        } else {
            $governor = array('attribute' => "independent", 'active' => true, 'inv' => '');
        }
        //close previous blocks
        if ($def['parent'] == "") {
            if ($subblock_open) {
                $echo_str .= "\n\t\t\t\t\t\t\t" . '</tbody>';
                $echo_str .= "\n\t\t\t\t\t\t" . '</table>';
                $subblock_open = false;
            }
            if ($block_open) {
                $echo_str .= "\n\t\t\t\t\t" . '</div></td>';
                $echo_str .= "\n\t\t\t\t" . '</tr>';
                $block_open = false;
            }
        }
        //check if new category must be generated
        if ($def['category'] != $prevcat) {
            if ($prevcat != "") {
                $echo_str .= "\n\t\t\t" . '</tbody>';
                $echo_str .= "\n\t\t" . '</table>';
                $echo_str .= "\n\t" . '</div>';
            }
            $prevcat = $def['category'];
            $prevsubcat = "";
            $echo_str .= "\n\t" . '<div id="wfu_container_' . $prevcat . '" class="wfu_container"' . ($is_first ? '' : ' style="display:none;"') . '">';
            $echo_str .= "\n\t\t" . '<table class="form-table wfu_main_table">';
            $echo_str .= "\n\t\t\t" . '<thead><tr><th></th><td></td><td></td></tr></thead>';
            $echo_str .= "\n\t\t\t" . '<tbody>';
            $is_first = false;
        }
        //check if new sub-category must be generated
        if ($def['subcategory'] != $prevsubcat) {
            $prevsubcat = $def['subcategory'];
            $echo_str .= "\n\t\t\t\t" . '<tr class="wfu_subcategory">';
            $echo_str .= "\n\t\t\t\t\t" . '<th scope="row" colspan="3">';
            $echo_str .= "\n\t\t\t\t\t\t" . '<h3 style="margin-bottom: 10px; margin-top: 10px;">' . $prevsubcat . '</h3>';
            $echo_str .= "\n\t\t\t\t\t" . '</th>';
            $echo_str .= "\n\t\t\t\t" . '</tr>';
        }
        //draw attribute element
        if ($def['parent'] == "") {
            $dlp = "\n\t\t\t\t";
        } else {
            if (!$subblock_open) {
                $echo_str .= "\n\t\t\t\t\t\t" . '<div class="wfu_shadow wfu_shadow_' . $def['parent'] . $governor['inv'] . '" style="display:' . ($governor['active'] ? 'none' : 'block') . ';"></div>';
                $echo_str .= "\n\t\t\t\t\t\t" . '<table class="form-table wfu_inner_table" style="margin:0;">';
                $echo_str .= "\n\t\t\t\t\t\t\t" . '<tbody>';
            }
            $dlp = "\n\t\t\t\t\t\t\t\t";
        }
        $echo_str .= $dlp . '<tr>';
        $echo_str .= $dlp . "\t" . '<th scope="row"><div class="wfu_td_div">';
        if ($def['parent'] == "") {
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_shadow wfu_shadow_' . $governor['attribute'] . $governor['inv'] . '" style="display:' . ($governor['active'] ? 'none' : 'block') . ';"></div>';
        }
        $echo_str .= $dlp . "\t\t" . '<div class="wfu_restore_container" title="Double-click to restore defaults setting"><img src="' . WFU_IMAGE_ADMIN_RESTOREDEFAULT . '" ondblclick="wfu_apply_value(\'' . $attr . '\', \'' . $def['type'] . '\', \'' . $def['default'] . '\');" /></div>';
        $echo_str .= $dlp . "\t\t" . '<label for="wfu_attribute_' . $attr . '">' . $def['name'] . '</label>';
        $echo_str .= $dlp . "\t\t" . '<div class="wfu_help_container" title="' . $def['help'] . '"><img src="' . WFU_IMAGE_ADMIN_HELP . '" /></div>';
        $echo_str .= $dlp . "\t" . '</div></th>';
        $echo_str .= $dlp . "\t" . '<td style="vertical-align:top;"><div class="wfu_td_div">';
        if ($def['parent'] == "") {
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_shadow wfu_shadow_' . $governor['attribute'] . $governor['inv'] . '" style="display:' . ($governor['active'] ? 'none' : 'block') . ';"></div>';
        }
        if ($def['type'] == "onoff") {
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_attribute_' . $attr . '" class="wfu_onoff_container_' . ($def['value'] == "true" ? "on" : "off") . '" onclick="wfu_admin_onoff_clicked(\'' . $attr . '\');">';
            $echo_str .= $dlp . "\t\t\t" . '<div class="wfu_onoff_slider"></div>';
            $echo_str .= $dlp . "\t\t\t" . '<span class="wfu_onoff_text">ON</span>';
            $echo_str .= $dlp . "\t\t\t" . '<span class="wfu_onoff_text">OFF</span>';
            $echo_str .= $dlp . "\t\t" . '</div>';
        } elseif ($def['type'] == "text") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="text" name="wfu_text_elements" value="' . $val . '" />';
            if ($def['variables'] != null) {
                $echo_str .= $dlp . wfu_insert_variables($def['variables'], 'wfu_variable wfu_variable_' . $attr);
            }
        } elseif ($def['type'] == "placements") {
            $components_used = array();
            foreach ($components as $component) {
                $components_used[$component['id']] = false;
            }
            $centered_content = '<div style="display:table; width:100%; height:100%;"><div style="display:table-cell; text-align:center; vertical-align:middle;">XXX</div></div>';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_placements_wrapper">';
            $echo_str .= $dlp . "\t\t\t" . '<div id="wfu_placements_container" class="wfu_placements_container">';
            $itemplaces = explode("/", $def['value']);
            foreach ($itemplaces as $section) {
                $echo_str .= $dlp . "\t\t\t\t" . '<div class="wfu_component_separator_hor"></div>';
                $echo_str .= $dlp . "\t\t\t\t" . '<div class="wfu_component_separator_ver"></div>';
                $items_in_section = explode("+", trim($section));
                $section_array = array();
                foreach ($items_in_section as $item_in_section) {
                    if (key_exists($item_in_section, $components_indexed)) {
                        $components_used[$item_in_section] = true;
                        $echo_str .= $dlp . "\t\t\t\t" . '<div id="wfu_component_box_' . $item_in_section . '" class="wfu_component_box" draggable="true" title="' . $components_indexed[$item_in_section]['help'] . '">' . str_replace("XXX", $components_indexed[$item_in_section]['name'], $centered_content) . '</div>';
                        $echo_str .= $dlp . "\t\t\t\t" . '<div class="wfu_component_separator_ver"></div>';
                    }
                }
            }
            $echo_str .= $dlp . "\t\t\t\t" . '<div class="wfu_component_separator_hor"></div>';
            $echo_str .= $dlp . "\t\t\t\t" . '<div id="wfu_component_bar_hor" class="wfu_component_bar_hor"></div>';
            $echo_str .= $dlp . "\t\t\t\t" . '<div id="wfu_component_bar_ver" class="wfu_component_bar_ver"></div>';
            $echo_str .= $dlp . "\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t\t" . '<div id="wfu_componentlist_container" class="wfu_componentlist_container">';
            $echo_str .= $dlp . "\t\t\t\t" . '<div id="wfu_componentlist_dragdrop" class="wfu_componentlist_dragdrop" style="display:none;"></div>';
            $ii = 1;
            foreach ($components as $component) {
                $echo_str .= $dlp . "\t\t\t\t" . '<div id="wfu_component_box_container_' . $component['id'] . '" class="wfu_component_box_container">';
                $echo_str .= $dlp . "\t\t\t\t\t" . '<div class="wfu_component_box_base">' . str_replace("XXX", $component['name'], $centered_content) . '</div>';
                if (!$components_used[$component['id']]) {
                    $echo_str .= $dlp . "\t\t\t\t\t" . '<div id="wfu_component_box_' . $component['id'] . '" class="wfu_component_box wfu_inbase" draggable="true" title="' . $component['help'] . '">' . str_replace("XXX", $component['name'], $centered_content) . '</div>';
                }
                $echo_str .= $dlp . "\t\t\t\t" . '</div>' . ($ii++ % 3 == 0 ? '<br />' : '');
            }
            $echo_str .= $dlp . "\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t" . '</div>';
        } elseif ($def['type'] == "ltext") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="text" name="wfu_text_elements" class="wfu_long_text" value="' . $val . '" />';
            if ($def['variables'] != null) {
                $echo_str .= $dlp . wfu_insert_variables($def['variables'], 'wfu_variable wfu_variable_' . $attr);
            }
        } elseif ($def['type'] == "integer") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="number" name="wfu_text_elements" class="wfu_short_text" min="1" value="' . $val . '" />';
            if (isset($def['listitems']['unit'])) {
                $echo_str .= $dlp . "\t\t" . '<label> ' . $def['listitems']['unit'] . '</label>';
            }
        } elseif ($def['type'] == "float") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="number" name="wfu_text_elements" class="wfu_short_text" step="any" min="0" value="' . $val . '" />';
            if (isset($def['listitems']['unit'])) {
                $echo_str .= $dlp . "\t\t" . '<label> ' . $def['listitems']['unit'] . '</label>';
            }
        } elseif ($def['type'] == "date") {
            $val = $def['value'];
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="date" name="wfu_date_elements" value="' . $val . '" />';
        } elseif ($def['type'] == "radio") {
            $echo_str .= $dlp . "\t\t";
            $ii = 0;
            foreach ($def['listitems'] as $item) {
                $echo_str .= '<input name="wfu_radioattribute_' . $attr . '" type="radio" value="' . $item . '" ' . ($item == $def['value'] || $item == "*" . $def['value'] ? 'checked="checked" ' : '') . 'style="width:auto; margin:0px 2px 0px ' . ($ii++ == 0 ? '0px' : '8px') . ';" onchange="wfu_admin_radio_clicked(\'' . $attr . '\');" />' . ($item[0] == "*" ? substr($item, 1) : $item);
            }
            //			$echo_str .= '<input type="button" class="button" value="empty" style="width:auto; margin:-2px 0px 0px 8px;" />';
        } elseif ($def['type'] == "ptext") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $parts = explode("/", $val);
            $singular = $parts[0];
            if (count($parts) < 2) {
                $plural = $singular;
            } else {
                $plural = $parts[1];
            }
            $echo_str .= $dlp . "\t\t" . '<span class="wfu_ptext_span">Singular</span><input id="wfu_attribute_s_' . $attr . '" type="text" name="wfu_ptext_elements" value="' . $singular . '" />';
            if ($def['variables'] != null) {
                if (count($def['variables']) > 0) {
                    $echo_str .= $dlp . "\t\t" . '<br /><span class="wfu_ptext_span">&nbsp;</span>';
                }
            }
            if ($def['variables'] != null) {
                $echo_str .= $dlp . wfu_insert_variables($def['variables'], 'wfu_variable wfu_variable_s_' . $attr);
            }
            $echo_str .= $dlp . "\t\t" . '<br /><span class="wfu_ptext_span">Plural</span><input id="wfu_attribute_p_' . $attr . '" type="text" name="wfu_ptext_elements" value="' . $plural . '" />';
            if ($def['variables'] != null) {
                if (count($def['variables']) > 0) {
                    $echo_str .= $dlp . "\t\t" . '<br /><span class="wfu_ptext_span">&nbsp;</span>';
                }
            }
            if ($def['variables'] != null) {
                $echo_str .= $dlp . wfu_insert_variables($def['variables'], 'wfu_variable wfu_variable_p_' . $attr, $dlp);
            }
        } elseif ($def['type'] == "mtext") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $echo_str .= $dlp . "\t\t" . '<textarea id="wfu_attribute_' . $attr . '" name="wfu_text_elements" rows="5">' . $val . '</textarea>';
            if ($def['variables'] != null) {
                $echo_str .= $dlp . wfu_insert_variables($def['variables'], 'wfu_variable wfu_variable_' . $attr);
            }
        } elseif ($def['type'] == "folderlist") {
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_subfolders_inner_shadow_' . $attr . '" class="wfu_subfolders_inner_shadow" style="display:none;"></div>';
            $subfolders = wfu_parse_folderlist($def['value']);
            $poptitle = "Populate list automatically with the first-level subfolders of the path defined in uploadpath";
            $edittitle = "Allow the user to type the subfolder and filter the list during typing";
            $echo_str .= $dlp . "\t\t" . '<input type="checkbox" id="wfu_subfolders_auto_' . $attr . '"' . (substr($def['value'], 0, 4) == "auto" ? ' checked="checked"' : '') . ' onchange="wfu_subfolders_auto_changed(\'' . $attr . '\');" title="' . $poptitle . '" /><label for="wfu_subfolders_auto_' . $attr . '" title="' . $poptitle . '"> Auto-populate list</label>';
            $echo_str .= $dlp . "\t\t" . '<div style="display:' . (substr($def['value'], 0, 4) == "auto" ? 'inline' : 'none') . '; padding:0; margin:0 0 0 30px; background:none; border:none;"><input type="checkbox" id="wfu_subfolders_editable_' . $attr . '"' . (substr($def['value'], 0, 5) == "auto+" ? ' checked="checked"' : '') . ' onchange="wfu_subfolders_auto_changed(\'' . $attr . '\');" title="' . $edittitle . '" /><label for="wfu_subfolders_editable_' . $attr . '" title="' . $edittitle . '"> List is editable</label></div><br />';
            $echo_str .= $dlp . "\t\t" . '<input type="hidden" id="wfu_subfolders_manualtext_' . $attr . '" value="' . (substr($def['value'], 0, 4) == "auto" ? "" : $def['value']) . '" />';
            $echo_str .= $dlp . "\t\t" . '<select id="wfu_attribute_' . $attr . '" class="wfu_select_folders' . (count($subfolders['path']) == 0 ? ' wfu_select_folders_empty' : '') . '" size="7"' . (substr($def['value'], 0, 4) == "auto" ? ' disabled="disabled"' : '') . ' onchange="wfu_subfolders_changed(\'' . $attr . '\');">';
            foreach ($subfolders['path'] as $ind => $subfolder) {
                if (substr($subfolder, -1) == '/') {
                    $subfolder = substr($subfolder, 0, -1);
                }
                $subfolder_raw = explode('/', $subfolder);
                $subfolder = $subfolder_raw[count($subfolder_raw) - 1];
                $text = str_repeat("&nbsp;&nbsp;&nbsp;", intval($subfolders['level'][$ind])) . $subfolders['label'][$ind];
                $subvalue = str_repeat("*", intval($subfolders['level'][$ind])) . ($subfolders['default'][$ind] ? '&' : '') . ($subfolder == "" ? '{root}' : $subfolder) . '/' . $subfolders['label'][$ind];
                $echo_str .= $dlp . "\t\t\t" . '<option class="' . ($subfolders['default'][$ind] ? 'wfu_select_folders_option_default' : '') . '" value="' . wfu_plugin_encode_string($subvalue) . '">' . $text . '</option>';
            }
            $echo_str .= $dlp . "\t\t\t" . '<option value="">' . (substr($def['value'], 0, 4) != "auto" && count($subfolders['path']) == 0 ? 'press here' : '') . '</option>';
            $echo_str .= $dlp . "\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_subfolder_nav_' . $attr . '" class="wfu_subfolder_nav_container">';
            $echo_str .= $dlp . "\t\t\t" . '<table class="wfu_subfolder_nav"><tbody>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td><button id="wfu_subfolders_up_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" disabled="disabled" title="move item up" onclick="wfu_subfolders_up_clicked(\'' . $attr . '\');">&uarr;</button></tr></td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td><button id="wfu_subfolders_left_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" title="make it parent" disabled="disabled" style="height:14px;" onclick="wfu_subfolders_left_clicked(\'' . $attr . '\');">&larr;</button>';
            $echo_str .= $dlp . "\t\t\t\t" . '<button id="wfu_subfolders_right_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" title="make it child" disabled="disabled" style="height:14px;" onclick="wfu_subfolders_right_clicked(\'' . $attr . '\');">&rarr;</button></tr></td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td><button id="wfu_subfolders_down_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" title="move item down" disabled="disabled" onclick="wfu_subfolders_down_clicked(\'' . $attr . '\');">&darr;</button></tr></td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td style="line-height:0;"><button  class="button" style="visibility:hidden; height:10px;"></button></tr></td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td><button id="wfu_subfolders_add_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" title="add new item" disabled="disabled" style="height:14px;" onclick="wfu_subfolders_add_clicked(\'' . $attr . '\');">+</button></tr></td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td><button id="wfu_subfolders_def_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" title="make it default" disabled="disabled" style="height:14px;" onclick="wfu_subfolders_def_clicked(\'' . $attr . '\');">&diams;</button></tr></td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<tr><td><button id="wfu_subfolders_del_' . $attr . '" name="wfu_subfolder_nav_' . $attr . '" class="button" title="delete item" disabled="disabled" style="height:14px;" onclick="wfu_subfolders_del_clicked(\'' . $attr . '\');">-</button></tr></td>';
            $echo_str .= $dlp . "\t\t\t" . '</tbody></table>';
            $echo_str .= $dlp . "\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_subfolder_tools_' . $attr . '" class="wfu_subfolder_tools_container wfu_subfolder_tools_disabled">';
            $echo_str .= $dlp . "\t\t\t" . '<table class="wfu_subfolder_tools"><tbody><tr>';
            $echo_str .= $dlp . "\t\t\t\t" . '<td style="width:40%;">';
            $echo_str .= $dlp . "\t\t\t\t\t" . '<label>Label</label>';
            $echo_str .= $dlp . "\t\t\t\t\t" . '<input id="wfu_subfolders_label_' . $attr . '" name="wfu_subfolder_tools_input" type="text" disabled="disabled" />';
            $echo_str .= $dlp . "\t\t\t\t" . '</td>';
            $echo_str .= $dlp . "\t\t\t\t" . '<td style="width:60%;"><div style="padding-right:36px;">';
            $echo_str .= $dlp . "\t\t\t\t\t" . '<label>Path</label>';
            $echo_str .= $dlp . "\t\t\t\t\t" . '<input id="wfu_subfolders_path_' . $attr . '" name="wfu_subfolder_tools_input" type="text" disabled="disabled" />';
            $echo_str .= $dlp . "\t\t\t\t\t" . '<button id="wfu_subfolders_browse_' . $attr . '" class="button" title="browse folders" style="right:18px;" disabled="disabled" onclick="wfu_subfolders_browse_clicked(\'' . $attr . '\');"><img src="' . WFU_IMAGE_ADMIN_SUBFOLDER_BROWSE . '" ></button>';
            $echo_str .= $dlp . "\t\t\t\t\t" . '<button id="wfu_subfolders_ok_' . $attr . '" class="button" title="save changes" style="right:0px;" disabled="disabled" onclick="wfu_subfolders_ok_clicked(\'' . $attr . '\');"><img src="' . WFU_IMAGE_ADMIN_SUBFOLDER_OK . '" ></button>';
            // file browser dialog
            $echo_str .= $dlp . "\t\t\t\t\t" . '<div id="wfu_subfolders_browser_' . $attr . '" class="wfu_subfolders_browser_container" style="display:none;">';
            $echo_str .= $dlp . "\t\t\t\t\t\t" . '<table><tbody>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t" . '<tr><td style="height:15px;">';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t" . '<div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '<label>Folder Browser</label>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '<button class="button wfu_folder_browser_cancel" onclick="wfu_folder_browser_cancel_clicked(\'' . $attr . '\');"><img src="' . WFU_IMAGE_ADMIN_SUBFOLDER_CANCEL . '" ></button>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t" . '</td></tr>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t" . '<tr><td style="height:106px;">';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t" . '<div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '<select id="wfu_subfolders_browser_list_' . $attr . '" size="2" onchange="wfu_subfolders_browser_list_changed(\'' . $attr . '\');">';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t\t" . '<option>Value</option>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t\t" . '<option>Value2</option>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t\t" . '<option>Value3</option>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '<div id="wfu_subfolders_browser_msgcont_' . $attr . '" class="wfu_folder_browser_loading_container" style="padding-top:40px;">';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t\t" . '<label id="wfu_subfolders_browser_msg_' . $attr . '" style="margin-bottom:4px;">loading folder contents...</label>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t\t" . '<img id="wfu_subfolders_browser_img_' . $attr . '" src="' . WFU_IMAGE_ADMIN_SUBFOLDER_LOADING . '" ></button>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t" . '</td></tr>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t" . '<tr><td align="right" style="height:15px;">';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t" . '<div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '<button class="button" onclick="wfu_folder_browser_cancel_clicked(\'' . $attr . '\');">Cancel</button>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t\t" . '<button id="wfu_subfolders_browser_ok_' . $attr . '" class="button">Ok</button>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t\t\t\t\t\t" . '</td></tr>';
            $echo_str .= $dlp . "\t\t\t\t\t\t" . '</tbody></table>';
            $echo_str .= $dlp . "\t\t\t\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t\t\t" . '</div></td>';
            $echo_str .= $dlp . "\t\t\t" . '</tr></tbody></table>';
            $echo_str .= $dlp . "\t\t\t" . '<input id="wfu_subfolders_isnewitem_' . $attr . '" type="hidden" value="" />';
            $echo_str .= $dlp . "\t\t\t" . '<input id="wfu_subfolders_newitemindex_' . $attr . '" type="hidden" value="" />';
            $echo_str .= $dlp . "\t\t\t" . '<input id="wfu_subfolders_newitemlevel_' . $attr . '" type="hidden" value="" />';
            $echo_str .= $dlp . "\t\t\t" . '<input id="wfu_subfolders_newitemlevel2_' . $attr . '" type="hidden" value="" />';
            $echo_str .= $dlp . "\t\t" . '</div>';
        } elseif ($def['type'] == "mchecklist") {
            $help_count = 0;
            foreach ($def['listitems'] as $key => $item) {
                $parts = explode("/", $item);
                if (count($parts) == 1) {
                    $items[$key]['id'] = $item;
                    $items[$key]['help'] = '';
                } else {
                    $items[$key]['id'] = $parts[0];
                    $items[$key]['help'] = $parts[1];
                    $help_count++;
                }
            }
            $def['value'] = strtolower($def['value']);
            if ($def['value'] == "all") {
                $selected = array();
            } else {
                $selected = explode(",", $def['value']);
            }
            foreach ($selected as $key => $item) {
                $selected[$key] = trim($item);
            }
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_attribute_' . $attr . '" class="wfu_mchecklist_container">';
            $is_first = true;
            foreach ($items as $key => $item) {
                if (!$is_first) {
                    $echo_str .= "<br />";
                }
                $is_first = false;
                $echo_str .= $dlp . "\t\t\t" . '<div class="wfu_mchecklist_item"><input id="wfu_attribute_' . $attr . '_' . $key . '" type="checkbox"' . ($def['value'] == "all" || in_array($item['id'], $selected) ? ' checked="checked"' : '') . ($def['value'] == "all" ? ' disabled="disabled"' : '') . ' onchange="wfu_update_mchecklist_value(\'' . $attr . '\');" /><label for="wfu_attribute_' . $attr . '_' . $key . '">' . $item['id'] . '</label>';
                if ($item['help'] != '') {
                    $echo_str .= '<div class="wfu_help_container" title="' . $item['help'] . '"><img src="' . WFU_IMAGE_ADMIN_HELP . '" /></div>';
                }
                $echo_str .= '</div>';
            }
            $echo_str .= $dlp . "\t\t" . '</div>';
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_attribute_' . $attr . '_optionhelp" class="wfu_help_container" title="" style="display:none; position:absolute;"><img src="' . WFU_IMAGE_ADMIN_HELP . '" style="visibility:visible;" /></div>';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_mchecklist_checkall"><input id="wfu_attribute_' . $attr . '_all" type="checkbox" onchange="wfu_update_mchecklist_value(\'' . $attr . '\');"' . ($def['value'] == "all" ? ' checked="checked"' : '') . ' /> Select all</div>';
        } elseif ($def['type'] == "rolelist") {
            $roles = $wp_roles->get_names();
            $selected = explode(",", $def['value']);
            $default_administrator = is_array($def['listitems']) && in_array('default_administrator', $def['listitems']);
            if (in_array('all', $selected)) {
                $rolesselected = $default_administrator ? array("administrator") : array();
            } else {
                $rolesselected = $selected;
            }
            foreach ($selected as $key => $item) {
                $selected[$key] = trim($item);
            }
            $echo_str .= $dlp . "\t\t" . '<table class="wfu_rolelist_container"><tbody><tr><td>';
            $echo_str .= $dlp . "\t\t" . '<select id="wfu_attribute_' . $attr . '" multiple="multiple" size="' . count($roles) . '" onchange="wfu_update_rolelist_value(\'' . $attr . '\');"' . (in_array('all', $selected) ? ' disabled="disabled"' : '') . '>';
            foreach ($roles as $roleid => $rolename) {
                $echo_str .= $dlp . "\t\t\t" . '<option value="' . $roleid . '"' . (in_array($roleid, $rolesselected) ? ' selected="selected"' : '') . '>' . $rolename . '</option>';
            }
            $echo_str .= $dlp . "\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t" . '</td><td>';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_rolelist_checkbtn"><input class="' . ($default_administrator ? 'wfu_default_administrator' : '') . '" id="wfu_attribute_' . $attr . '_all" type="checkbox" onchange="wfu_update_rolelist_value(\'' . $attr . '\');"' . (in_array('all', $selected) ? ' checked="checked"' : '') . ' /><label for="wfu_attribute_' . $attr . '_all"> Select all</label></div><br />';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_rolelist_checkbtn"><input id="wfu_attribute_' . $attr . '_guests" type="checkbox" onchange="wfu_update_rolelist_value(\'' . $attr . '\');"' . (in_array("guests", $selected) ? ' checked="checked"' : '') . ' /><label for="wfu_attribute_' . $attr . '_guests"> Include guests</label></div>';
            $echo_str .= $dlp . "\t\t" . '</td></tr></tbody></table>';
        } elseif ($def['type'] == "userlist") {
            $users = get_users();
            $selected = explode(",", $def['value']);
            $default_0 = is_array($def['listitems']) && in_array('default_0', $def['listitems']);
            if (in_array('all', $selected)) {
                $usersselected = $default_0 ? array($users[0]->user_login) : array();
            } else {
                $usersselected = $selected;
            }
            $only_current = false;
            $echo_str .= $dlp . "\t\t" . '<table class="wfu_userlist_container"><tbody><tr>';
            if (is_array($def['listitems']) && in_array('include_current', $def['listitems'])) {
                $only_current = $def['value'] == 'current';
                if ($only_current) {
                    $usersselected = $default_0 ? array($users[0]->user_login) : array();
                }
                $echo_str .= $dlp . "\t\t" . '<td colspan="2"><div class="wfu_userlist_checkbtn"><input id="wfu_attribute_' . $attr . '_current" type="checkbox" onchange="wfu_update_userlist_value(\'' . $attr . '\');"' . ($only_current ? ' checked="checked"' : '') . ' /><label for="wfu_attribute_' . $attr . '_current"> Only From Current User</label></div>';
                $echo_str .= $dlp . "\t\t" . '</td></tr><tr>';
            }
            $echo_str .= $dlp . "\t\t" . '<td><select id="wfu_attribute_' . $attr . '" multiple="multiple" size="' . min(count($users), 10) . '" onchange="wfu_update_userlist_value(\'' . $attr . '\');"' . ($only_current || in_array('all', $selected) ? ' disabled="disabled"' : '') . '>';
            foreach ($users as $userid => $user) {
                $echo_str .= $dlp . "\t\t\t" . '<option value="' . $user->user_login . '"' . (in_array($user->user_login, $usersselected) ? ' selected="selected"' : '') . '>' . $user->display_name . ' (' . $user->user_login . ')</option>';
            }
            $echo_str .= $dlp . "\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t" . '</td><td>';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_userlist_checkbtn"><input class="' . ($default_0 ? 'wfu_default_0' : '') . '" id="wfu_attribute_' . $attr . '_all" type="checkbox" onchange="wfu_update_userlist_value(\'' . $attr . '\');"' . (in_array('all', $selected) ? ' checked="checked"' : '') . ($only_current ? ' disabled="disabled"' : '') . ' /><label for="wfu_attribute_' . $attr . '_all"> Select all</label></div><br />';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_userlist_checkbtn"><input id="wfu_attribute_' . $attr . '_guests" type="checkbox" onchange="wfu_update_userlist_value(\'' . $attr . '\');"' . (in_array("guests", $selected) ? ' checked="checked"' : '') . ($only_current ? ' disabled="disabled"' : '') . ' /><label for="wfu_attribute_' . $attr . '_guests"> Include guests</label></div>';
            $echo_str .= $dlp . "\t\t" . '</td></tr></tbody></table>';
        } elseif ($def['type'] == "postlist") {
            $processed = false;
            if (is_array($def['listitems'])) {
                $has_current = in_array('include_current', $def['listitems']);
                if ($has_current) {
                    unset($def['listitems'][array_search('include_current', $def['listitems'])]);
                }
                foreach ($def['listitems'] as $post_type) {
                    // if a post type cannot be found then we reset the list so that it is not processed at all
                    if (get_post_type_object($post_type) == null) {
                        $def['listitems'] = array();
                        break;
                    }
                }
                if (count($def['listitems']) > 0) {
                    $selected = explode(",", $def['value']);
                    $only_current = false;
                    $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '_postlist" type="hidden" value="' . implode(",", $def['listitems']) . '" />';
                    $echo_str .= $dlp . "\t\t" . '<table class="wfu_postlist_container"><tbody><tr>';
                    if ($has_current) {
                        $only_current = $def['value'] == 'current';
                        if ($only_current) {
                            $sselected = array();
                        }
                        $echo_str .= $dlp . "\t\t" . '<td colspan="' . count($def['listitems']) . '"><div class="wfu_postlist_checkbtn"><input id="wfu_attribute_' . $attr . '_current" type="checkbox" onchange="wfu_update_postlist_value(\'' . $attr . '\');"' . ($only_current ? ' checked="checked"' : '') . ' /><label for="wfu_attribute_' . $attr . '_current"> Only From Current Post/Page</label></div>';
                        $echo_str .= $dlp . "\t\t" . '</td></tr><tr>';
                    }
                    $postargs = array('post_type' => $def['listitems'], 'post_status' => "publish,private,draft", 'posts_per_page' => -1);
                    $posts = get_posts($postargs);
                    $list = wfu_construct_post_list($posts);
                    foreach ($def['listitems'] as $post_type) {
                        $flatlist = wfu_flatten_post_list($list[$post_type]);
                        $postobj = get_post_type_object($post_type);
                        $echo_str .= $dlp . "\t\t" . '<td><div class="wfu_postlist_header"><label>' . $postobj->label . '</label><div class="wfu_postlist_selectall"><input id="wfu_attribute_' . $attr . '_all_' . $post_type . '" type="checkbox" onchange="wfu_update_postlist_value(\'' . $attr . '\');"' . (in_array('all', $selected) || in_array('all' . $post_type, $selected) ? ' checked="checked"' : '') . ($only_current ? ' disabled="disabled"' : '') . ' /><label for="wfu_attribute_' . $attr . '_all_' . $post_type . '"> Select all</label></div></div>';
                        $echo_str .= $dlp . "\t\t" . '<select id="wfu_attribute_' . $attr . '_' . $post_type . '" multiple="multiple" size="' . min(count($flatlist), 10) . '" onchange="wfu_update_postlist_value(\'' . $attr . '\');"' . ($only_current || in_array('all', $selected) || in_array('all' . $post_type, $selected) ? ' disabled="disabled"' : '') . '>';
                        foreach ($flatlist as $item) {
                            $echo_str .= $dlp . "\t\t\t" . '<option value="' . $item['id'] . '"' . (in_array($item['id'], $selected) ? ' selected="selected"' : '') . '>' . str_repeat('&nbsp;', 4 * $item['level']) . ($item['status'] == 1 ? '[Private]' : ($item['status'] == 2 ? '[Draft]' : '')) . $item['title'] . '</option>';
                        }
                        $echo_str .= $dlp . "\t\t" . '</select></td>';
                    }
                    $echo_str .= $dlp . "\t\t" . '</tr></tbody></table>';
                    $processed = true;
                }
            }
            if (!processed) {
                $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
                $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="text" name="wfu_text_elements" value="' . $val . '" />';
            }
        } elseif ($def['type'] == "bloglist") {
            if (function_exists('wp_get_sites')) {
                $blogs = wp_get_sites();
                $selected = explode(",", $def['value']);
                if (in_array('all', $selected)) {
                    $blogsselected = array();
                } else {
                    $blogsselected = $selected;
                }
                $only_current = false;
                $echo_str .= $dlp . "\t\t" . '<table class="wfu_bloglist_container"><tbody><tr>';
                if (is_array($def['listitems']) && in_array('include_current', $def['listitems'])) {
                    $only_current = $def['value'] == 'current';
                    if ($only_current) {
                        $blogsselected = array();
                    }
                    $echo_str .= $dlp . "\t\t" . '<td colspan="2"><div class="wfu_bloglist_checkbtn"><input id="wfu_attribute_' . $attr . '_current" type="checkbox" onchange="wfu_update_bloglist_value(\'' . $attr . '\');"' . ($only_current ? ' checked="checked"' : '') . ' /><label for="wfu_attribute_' . $attr . '_current"> Only From Current Site</label></div>';
                    $echo_str .= $dlp . "\t\t" . '</td></tr><tr>';
                }
                $echo_str .= $dlp . "\t\t" . '<td><select id="wfu_attribute_' . $attr . '" multiple="multiple" size="' . min(count($blogs), 10) . '" onchange="wfu_update_bloglist_value(\'' . $attr . '\');"' . ($only_current || in_array('all', $selected) ? ' disabled="disabled"' : '') . '>';
                foreach ($blogs as $blog) {
                    $echo_str .= $dlp . "\t\t\t" . '<option value="' . $blog->blog_id . '"' . (in_array($blog->blog_id, $blogsselected) ? ' selected="selected"' : '') . '>' . $blog->path . '</option>';
                }
                $echo_str .= $dlp . "\t\t" . '</select>';
                $echo_str .= $dlp . "\t\t" . '</td><td>';
                $echo_str .= $dlp . "\t\t" . '<div class="wfu_bloglist_checkbtn"><input id="wfu_attribute_' . $attr . '_all" type="checkbox" onchange="wfu_update_bloglist_value(\'' . $attr . '\');"' . (in_array('all', $selected) ? ' checked="checked"' : '') . ($only_current ? ' disabled="disabled"' : '') . ' /><label for="wfu_attribute_' . $attr . '_all"> Select all</label></div>';
                $echo_str .= $dlp . "\t\t" . '</td></tr></tbody></table>';
            } else {
                $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
                $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="text" name="wfu_text_elements" value="' . $val . '" />';
            }
        } elseif ($def['type'] == "stringmatch") {
            $matchfield = "";
            $matchcriterion = "equal to";
            $matchvalue = "";
            preg_match('/^field:(.*?);\\s*criterion:(.*?)\\s*;\\s*value:(.*)$/', $def['value'], $matches);
            if (count($matches) == 4) {
                $matchfield = $matches[1];
                $matchcriterion = $matches[2];
                $matchvalue = $matches[3];
            }
            $echo_str .= $dlp . "\t\t" . '<div style="white-space:nowrap;">';
            $echo_str .= $dlp . "\t\t" . '<label>Field </label><input id="wfu_attribute_' . $attr . '_matchfield" type="text" name="wfu_stringmatch_elements" value="' . $matchfield . '" />';
            $echo_str .= $dlp . "\t\t" . '<select id="wfu_attribute_' . $attr . '_matchcriterion" value="' . $matchcriterion . '" onchange="wfu_update_stringmatch_value(\'' . $attr . '\');">';
            $echo_str .= $dlp . "\t\t\t" . '<option value="equal to"' . ($matchcriterion == "equal to" ? 'selected="selected"' : '') . '>equal to</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="starts with"' . ($matchcriterion == "starts with" ? 'selected="selected"' : '') . '>starts with</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="ends with"' . ($matchcriterion == "ends with" ? 'selected="selected"' : '') . '>ends with</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="contains"' . ($matchcriterion == "contains" ? 'selected="selected"' : '') . '>contains</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="not equal to"' . ($matchcriterion == "not equal to" ? 'selected="selected"' : '') . '>not equal to</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="does not start with"' . ($matchcriterion == "does not start with" ? 'selected="selected"' : '') . '>does not start with</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="does not end with"' . ($matchcriterion == "does not end with" ? 'selected="selected"' : '') . '>does not end with</option>';
            $echo_str .= $dlp . "\t\t\t" . '<option value="does not contain"' . ($matchcriterion == "does not contain" ? 'selected="selected"' : '') . '>does not contain</option>';
            $echo_str .= $dlp . "\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '_matchvalue" type="text" name="wfu_stringmatch_elements" value="' . $matchvalue . '" />';
            $echo_str .= $dlp . "\t\t" . '</div>';
        } elseif ($def['type'] == "columns") {
            $selected = explode(",", $def['value']);
            if (count($selected) == 1 && $selected[0] == "") {
                $selected = array();
            }
            $echo_str .= $dlp . "\t" . '<table class="wfu_columns_container"><tbody><tr>';
            $echo_str .= $dlp . "\t\t" . '<td>';
            $echo_str .= $dlp . "\t\t\t" . '<label class="wfu_columns_listtitle">Available Columns</label><br />';
            $echo_str .= $dlp . "\t\t\t" . '<select id="wfu_attribute_' . $attr . '_sourcelist" multiple="multiple" size="' . min(count($def['listitems']), 10) . '">';
            foreach ($def['listitems'] as $item) {
                $item_required = substr($item, 0, 1) == "*";
                if ($item_required) {
                    $item = substr($item, 1);
                }
                $item_parts = explode("/", $item, 2);
                if (count($item_parts) == 1) {
                    $item_name = $item;
                    $item_label = $item . ($item_required ? ' (required)' : '');
                } else {
                    $item_name = $item_parts[0];
                    $item_label = $item_parts[1];
                }
                $itemprops[$item_name] = array('label' => $item_label, 'required' => $item_required);
                $echo_str .= $dlp . "\t\t\t\t" . '<option value="' . $item_name . '"' . ($item_required ? ' class="wfu_columns_item_required"' : '') . ' onclick="wfu_columns_itemclicked(this);">' . $item_label . '</option>';
            }
            $echo_str .= $dlp . "\t\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t" . '</td>';
            foreach ($itemprops as $item_name => $prop) {
                if ($prop['required'] && !in_array($item_name, $selected)) {
                    array_splice($selected, 0, 0, array($item_name));
                }
            }
            $echo_str .= $dlp . "\t\t" . '<td align="center">';
            $echo_str .= $dlp . "\t\t\t" . '<label class="wfu_columns_listtitle"></label><br />';
            $echo_str .= $dlp . "\t\t\t" . '<button class="wfu_columns_addbutton" onclick="wfu_columns_buttonaction(\'' . $attr . '\', \'add\');">Add &gt;&gt;</button><br />';
            $echo_str .= $dlp . "\t\t\t" . '<button class="wfu_columns_addbutton" onclick="wfu_columns_buttonaction(\'' . $attr . '\', \'del\');">&lt;&lt; Remove</button>';
            $echo_str .= $dlp . "\t\t" . '</td>';
            $echo_str .= $dlp . "\t\t" . '<td>';
            $echo_str .= $dlp . "\t\t\t" . '<label class="wfu_columns_listtitle">Displayed Columns</label><br />';
            $echo_str .= $dlp . "\t\t\t" . '<select id="wfu_attribute_' . $attr . '" multiple="multiple" size="' . min(count($def['listitems']), 10) . '" onchange="wfu_update_columns(\'' . $attr . '\');">';
            foreach ($selected as $item_name) {
                $echo_str .= $dlp . "\t\t\t\t" . '<option value="' . $item_name . '"' . ($itemprops[$item_name]['required'] ? ' class="wfu_columns_item_required"' : '') . ' onclick="wfu_columns_itemclicked(this);">' . $itemprops[$item_name]['label'] . '</option>';
            }
            $echo_str .= $dlp . "\t\t\t" . '</select>';
            $echo_str .= $dlp . "\t\t" . '</td>';
            $echo_str .= $dlp . "\t\t" . '<td align="center">';
            $echo_str .= $dlp . "\t\t\t" . '<label class="wfu_columns_listtitle"></label><br />';
            $echo_str .= $dlp . "\t\t\t" . '<button class="wfu_columns_addbutton" onclick="wfu_columns_buttonaction(\'' . $attr . '\', \'up\');">&#8593;</button><br />';
            $echo_str .= $dlp . "\t\t\t" . '<button class="wfu_columns_addbutton" onclick="wfu_columns_buttonaction(\'' . $attr . '\', \'down\');">&#8595;</button>';
            $echo_str .= $dlp . "\t\t" . '</td>';
            $echo_str .= $dlp . "\t" . '</tr></tbody></table>';
        } elseif ($def['type'] == "dimensions") {
            $vals_arr = explode(",", $def['value']);
            $vals = array();
            foreach ($vals_arr as $val_raw) {
                if (trim($val_raw) != "") {
                    list($val_id, $val) = explode(":", $val_raw);
                    $vals[trim($val_id)] = trim($val);
                }
            }
            $dims = array();
            foreach ($components as $comp) {
                if ($comp['dimensions'] == null) {
                    $dims[$comp['id']] = $comp['name'];
                } else {
                    foreach ($comp['dimensions'] as $dimraw) {
                        list($dim_id, $dim_name) = explode("/", $dimraw);
                        $dims[$dim_id] = $dim_name;
                    }
                }
            }
            foreach ($dims as $dim_id => $dim_name) {
                if (!array_key_exists($dim_id, $vals)) {
                    $vals[$dim_id] = "";
                }
                $echo_str .= $dlp . "\t\t" . '<span style="display:inline-block; width:130px;">' . $dim_name . '</span><input id="wfu_attribute_' . $attr . '_' . $dim_id . '" type="text" name="wfu_dimension_elements_' . $attr . '" class="wfu_short_text" value="' . $vals[$dim_id] . '" /><br />';
            }
        } elseif ($def['type'] == "userfields") {
            $fields_arr = explode("/", $def['value']);
            $fields = array();
            foreach ($fields_arr as $field_raw) {
                $is_req = substr($field_raw, 0, 1) == "*";
                if ($is_req) {
                    $field_raw = substr($field_raw, 1);
                }
                if ($field_raw != "") {
                    array_push($fields, array("name" => $field_raw, "required" => $is_req));
                }
            }
            if (count($fields) == 0) {
                array_push($fields, array("name" => "", "required" => false));
            }
            $echo_str .= $dlp . "\t\t" . '<div id="wfu_attribute_' . $attr . '" class="wfu_userdata_container">';
            foreach ($fields as $field) {
                $echo_str .= $dlp . "\t\t\t" . '<div class="wfu_userdata_line">';
                $echo_str .= $dlp . "\t\t\t\t" . '<input type="text" name="wfu_userfield_elements" value="' . $field['name'] . '" />';
                $echo_str .= $dlp . "\t\t\t\t" . '<div class="wfu_userdata_action" onclick="wfu_userdata_add_field(this);"><img src="' . WFU_IMAGE_ADMIN_USERDATA_ADD . '" ></div>';
                $echo_str .= $dlp . "\t\t\t\t" . '<div class="wfu_userdata_action wfu_userdata_action_disabled" onclick="wfu_userdata_remove_field(this);"><img src="' . WFU_IMAGE_ADMIN_USERDATA_REMOVE . '" ></div>';
                $echo_str .= $dlp . "\t\t\t\t" . '<input type="checkbox"' . ($field['required'] ? 'checked="checked"' : '') . ' onchange="wfu_update_userfield_value({target:this});" />';
                $echo_str .= $dlp . "\t\t\t\t" . '<span>Required</span>';
                $echo_str .= $dlp . "\t\t\t" . '</div>';
            }
            $echo_str .= $dlp . "\t\t" . '</div>';
        } elseif ($def['type'] == "color") {
            $val = str_replace(array("%n%", "%dq%", "%brl%", "%brr%"), array("\n", "&quot;", "[", "]"), $def['value']);
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="text" name="wfu_text_elements" class="wfu_color_field" value="' . $val . '" />';
        } elseif ($def['type'] == "color-triplet") {
            $triplet = explode(",", $def['value']);
            foreach ($triplet as $key => $item) {
                $triplet[$key] = trim($item);
            }
            if (count($triplet) == 2) {
                $triplet = array($triplet[0], $triplet[1], "#000000");
            } elseif (count($triplet) == 1) {
                $triplet = array($triplet[0], "#FFFFFF", "#000000");
            } elseif (count($triplet) < 3) {
                $triplet = array("#000000", "#FFFFFF", "#000000");
            }
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_color_container"><label style="display:inline-block; width:120px; margin-top:-16px;">Text Color</label><input id="wfu_attribute_' . $attr . '_color" type="text" class="wfu_color_field" name="wfu_triplecolor_elements" value="' . $triplet[0] . '" /></div>';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_color_container"><label style="display:inline-block; width:120px; margin-top:-16px;">Background Color</label><input id="wfu_attribute_' . $attr . '_bgcolor" type="text" class="wfu_color_field" name="wfu_triplecolor_elements" value="' . $triplet[1] . '" /></div>';
            $echo_str .= $dlp . "\t\t" . '<div class="wfu_color_container"><label style="display:inline-block; width:120px; margin-top:-16px;">Border Color</label><input id="wfu_attribute_' . $attr . '_borcolor" type="text" class="wfu_color_field" name="wfu_triplecolor_elements" value="' . $triplet[2] . '" /></div>';
        } else {
            $echo_str .= $dlp . "\t\t" . '<input id="wfu_attribute_' . $attr . '" type="text" name="wfu_text_elements" value="' . $def['value'] . '" />';
            if ($def['variables'] != null) {
                $echo_str .= $dlp . wfu_insert_variables($def['variables'], 'wfu_variable wfu_variable_' . $attr);
            }
        }
        $echo_str .= $dlp . "\t" . '</div></td>';
        if ($def['parent'] == "") {
            $echo_str .= $dlp . "\t" . '<td style="position:relative; vertical-align:top; padding:0;"><div class="wfu_td_div">';
            $block_open = false;
        } else {
            $echo_str .= $dlp . '</tr>';
            $subblock_open = true;
        }
    }
    if ($subblock_open) {
        $echo_str .= "\n\t\t\t\t\t\t" . '</div>';
    }
    if ($block_open) {
        $echo_str .= "\n\t\t\t\t\t" . '</div></td>';
        $echo_str .= "\n\t\t\t\t" . '</tr>';
    }
    $echo_str .= "\n\t\t\t" . '</tbody>';
    $echo_str .= "\n\t\t" . '</table>';
    $echo_str .= "\n\t" . '</div>';
    $echo_str .= "\n\t" . '<div id="wfu_global_dialog_container" class="wfu_global_dialog_container">';
    $echo_str .= "\n\t" . '</div>';
    $handler = 'function() { wfu_Attach_Admin_Events(' . ($data == "" ? 'true' : 'false') . '); }';
    $echo_str .= "\n\t" . '<script type="text/javascript">if(window.addEventListener) { window.addEventListener("load", ' . $handler . ', false); } else if(window.attachEvent) { window.attachEvent("onload", ' . $handler . '); } else { window["onload"] = ' . $handler . '; }</script>';
    $echo_str .= "\n" . '</div>';
    //	$echo_str .= "\n\t".'<div style="margin-top:10px;">';
    //	$echo_str .= "\n\t\t".'<label>Final shortcode text</label>';
    //	$echo_str .= "\n\t".'</div>';
    echo $echo_str;
}
function wordpress_file_upload_function($incomingfromhandler)
{
    global $post;
    global $blog_id;
    $shortcode_tag = 'wordpress_file_upload';
    $params = wfu_plugin_parse_array($incomingfromhandler);
    $sid = $params["uploadid"];
    $widgetid = $params["widgetid"];
    // store current page and blog id in params array
    $params["pageid"] = $post->ID;
    $params["blogid"] = $blog_id;
    if (!isset($_SESSION['wfu_token_' . $sid]) || $_SESSION['wfu_token_' . $sid] == "") {
        $_SESSION['wfu_token_' . $sid] = uniqid(mt_rand(), TRUE);
    }
    //store the server environment (32 or 64bit) for use when checking file size limits
    $params["php_env"] = wfu_get_server_environment();
    $user = wp_get_current_user();
    $widths = wfu_decode_dimensions($params["widths"]);
    $heights = wfu_decode_dimensions($params["heights"]);
    //additional parameters to pass to visualization routines
    $additional_params = array();
    $additional_params['widths'] = $widths;
    $additional_params['heights'] = $heights;
    $uploadedfile = 'uploadedfile_' . $sid;
    $hiddeninput = 'hiddeninput_' . $sid;
    $adminerrorcodes = 'adminerrorcodes_' . $sid;
    $upload_clickaction = 'wfu_redirect_to_classic(' . $sid . ', \'' . $_SESSION['wfu_token_' . $sid] . '\' , 0, 0);';
    //check if user is allowed to view plugin, otherwise do not generate it
    $uploadroles = explode(",", $params["uploadrole"]);
    foreach ($uploadroles as &$uploadrole) {
        $uploadrole = trim($uploadrole);
    }
    $plugin_upload_user_role = wfu_get_user_role($user, $uploadroles);
    if ($plugin_upload_user_role == 'nomatch') {
        return;
    }
    //activate debug mode only for admins
    if ($plugin_upload_user_role != 'administrator') {
        $params["debugmode"] = "false";
    }
    $params["adminmessages"] = $params["adminmessages"] == "true" && $plugin_upload_user_role == 'administrator';
    // define variable to hold any additional admin errors coming before processing of files (e.g. due to redirection)
    $params["adminerrors"] = "";
    /* Define dynamic upload path from variables */
    $search = array('/%userid%/', '/%username%/', '/%blogid%/', '/%pageid%/', '/%pagetitle%/');
    if (is_user_logged_in()) {
        $username = $user->user_login;
    } else {
        $username = "******";
    }
    $replace = array($user->ID, $username, $blog_id, $post->ID, get_the_title($post->ID));
    $params["uploadpath"] = preg_replace($search, $replace, $params["uploadpath"]);
    /* Determine if userdata fields have been defined */
    $userdata_fields = array();
    $userdata_occurrencies = substr_count($params["placements"], "userdata");
    if ($userdata_occurrencies == 0) {
        $userdata_occurrencies = 1;
    }
    if ($params["userdata"] == "true") {
        for ($i = 1; $i <= $userdata_occurrencies; $i++) {
            $userdata_fields2 = wfu_parse_userdata_attribute($params["userdatalabel" . ($i > 1 ? $i : "")]);
            foreach ($userdata_fields2 as $key => $item) {
                $userdata_fields2[$key]["occurrence"] = $i;
            }
            $userdata_fields = array_merge($userdata_fields, $userdata_fields2);
        }
    }
    $params["userdata_fields"] = $userdata_fields;
    /* If medialink or postlink is activated, then subfolders are deactivated */
    if ($params["medialink"] == "true" || $params["postlink"] == "true") {
        $params["askforsubfolders"] = "false";
    }
    /* Generate the array of subfolder paths */
    $params['subfoldersarray'] = wfu_get_subfolders_paths($params);
    /* in case that webcam is activated, then some elements related to file
       selection need to be removed */
    if (strpos($params["placements"], "webcam") !== false && $params["webcam"] == "true") {
        $params["placements"] = wfu_placements_remove_item($params["placements"], "filename");
        $params["placements"] = wfu_placements_remove_item($params["placements"], "selectbutton");
        $params["singlebutton"] = "false";
        $params["uploadbutton"] = $params["uploadmediabutton"];
    }
    //____________________________________________________________________________________________________________________________________________________________________________________
    if ($params['forceclassic'] != "true") {
        //**************section to put additional options inside params array**************
        $params['subdir_selection_index'] = "-1";
        //**************end of section of additional options inside params array**************
        //	below this line no other changes to params array are allowed
        //**************section to save params as Wordpress options**************
        //		every params array is indexed (uniquely identified) by three fields:
        //			- the page that contains the shortcode
        //			- the id of the shortcode instance (because there may be more than one instances of the shortcode inside a page)
        //			- the user that views the plugin (because some items of the params array are affected by the user name)
        //		the wordpress option "wfu_params_index" holds an array of combinations of these three fields, together with a randomly generated string that corresponds to these fields.
        //		the wordpress option "wfu_params_xxx", where xxx is the randomly generated string, holds the params array (encoded to string) that corresponds to this string.
        //		the structure of the "wfu_params_index" option is as follows: "a1||b1||c1||d1&&a2||b2||c2||d2&&...", where
        //			- a is the randomly generated string (16 characters)
        //			- b is the page id
        //			- c is the shortcode id
        //			- d is the user name
        $params_index = wfu_generate_current_params_index($sid, $user->user_login);
        $params_str = wfu_encode_array_to_string($params);
        update_option('wfu_params_' . $params_index, $params_str);
        $ajax_params['shortcode_id'] = $sid;
        $ajax_params['params_index'] = $params_index;
        $ajax_params['debugmode'] = $params["debugmode"];
        $ajax_params['is_admin'] = $plugin_upload_user_role == 'administrator' ? "true" : "false";
        $ajax_params["has_filters"] = has_filter("wfu_before_upload") ? "true" : "false";
        $ajax_params["error_header"] = $params["errormessage"];
        $ajax_params["fail_colors"] = $params["failmessagecolors"];
        $ajax_params_str = wfu_encode_array_to_string($ajax_params);
        $upload_clickaction = 'wfu_HTML5UploadFile(' . $sid . ', \'' . $ajax_params_str . '\', \'' . $_SESSION['wfu_token_' . $sid] . '\')';
    }
    $upload_onclick = ' onclick="' . $upload_clickaction . '"';
    $additional_params['clickaction'] = $upload_clickaction;
    /* Compose the html code for the plugin */
    $wordpress_file_upload_output = "";
    $plugin_style = "";
    if ($widths["plugin"] != "") {
        $plugin_style .= 'width: ' . $widths["plugin"] . '; ';
    }
    if ($heights["plugin"] != "") {
        $plugin_style .= 'height: ' . $heights["plugin"] . '; ';
    }
    if ($plugin_style != "") {
        $plugin_style = ' style="' . $plugin_style . '"';
    }
    $wordpress_file_upload_output .= '<div id="' . $shortcode_tag . '_block_' . $sid . '" class="file_div_clean' . ($params["fitmode"] == "responsive" ? '_responsive_container' : '') . ' wfu_container"' . $plugin_style . '>';
    $wordpress_file_upload_output .= "\n\t" . '<input type="hidden" id="' . $shortcode_tag . '_' . $sid . '_widgetid" value="' . $widgetid . '" />';
    //add visual editor overlay if the current user is administrator
    if (current_user_can('manage_options')) {
        $wordpress_file_upload_output .= wfu_add_visual_editor_button($shortcode_tag, $sid);
    }
    //read indexed component definitions
    $components = wfu_component_definitions();
    $components_indexed = array();
    foreach ($components as $component) {
        $components_indexed[$component['id']] = $component;
        $components_indexed[$component['id']]['occurrencies'] = 0;
    }
    $itemplaces = explode("/", $params["placements"]);
    foreach ($itemplaces as $section) {
        $items_in_section = explode("+", trim($section));
        $section_array = array($params["fitmode"]);
        foreach ($items_in_section as $item_in_section) {
            $item_in_section = strtolower(trim($item_in_section));
            if (isset($components_indexed[$item_in_section]) && ($components_indexed[$item_in_section]['multiplacements'] || $components_indexed[$item_in_section]['occurrencies'] == 0)) {
                $components_indexed[$item_in_section]['occurrencies']++;
                $occurrence_index = $components_indexed[$item_in_section]['multiplacements'] ? $components_indexed[$item_in_section]['occurrencies'] : 0;
                if ($item_in_section == "title") {
                    array_push($section_array, wfu_prepare_title_block($params, $additional_params, $occurrence_index));
                } elseif ($item_in_section == "filename") {
                    array_push($section_array, wfu_prepare_textbox_block($params, $additional_params, $occurrence_index));
                } elseif ($item_in_section == "selectbutton") {
                    array_push($section_array, wfu_prepare_uploadform_block($params, $additional_params, $occurrence_index));
                } elseif ($item_in_section == "uploadbutton" && $params["singlebutton"] != "true") {
                    array_push($section_array, wfu_prepare_submit_block($params, $additional_params, $occurrence_index));
                } elseif ($item_in_section == "subfolders") {
                    array_push($section_array, wfu_prepare_subfolders_block($params, $additional_params, $occurrence_index));
                } elseif ($item_in_section == "progressbar") {
                    array_push($section_array, wfu_prepare_progressbar_block($params, $additional_params, $occurrence_index));
                } elseif ($item_in_section == "message") {
                    array_push($section_array, wfu_prepare_message_block($params, $additional_params, $occurrence_index));
                } elseif ($item_in_section == "userdata" && $params["userdata"] == "true") {
                    array_push($section_array, wfu_prepare_userdata_block($params, $additional_params, $occurrence_index));
                } elseif ($item_in_section == "webcam" && $params["webcam"] == "true") {
                    array_push($section_array, wfu_prepare_webcam_block($params, $additional_params, $occurrence_index));
                }
            }
        }
        $wordpress_file_upload_output .= call_user_func_array("wfu_add_div", $section_array);
    }
    /* Append mandatory blocks, if have not been included in placements attribute */
    if ($params["userdata"] == "true" && strpos($params["placements"], "userdata") === false) {
        $section_array = array($params["fitmode"]);
        array_push($section_array, wfu_prepare_userdata_block($params, $additional_params, 0));
        $wordpress_file_upload_output .= call_user_func_array("wfu_add_div", $section_array);
    }
    if (strpos($params["placements"], "selectbutton") === false) {
        $section_array = array($params["fitmode"]);
        array_push($section_array, wfu_prepare_uploadform_block($params, $additional_params, 0));
        $wordpress_file_upload_output .= call_user_func_array("wfu_add_div", $section_array);
    }
    /* Pass constants to javascript and run plugin post-load actions */
    $consts = wfu_set_javascript_constants();
    $handler = 'function() { wfu_Initialize_Consts("' . $consts . '"); wfu_Load_Code_Connectors(' . $sid . '); wfu_plugin_load_action(' . $sid . '); }';
    $wordpress_file_upload_output .= "\n\t" . '<script type="text/javascript">if(window.addEventListener) { window.addEventListener("load", ' . $handler . ', false); } else if(window.attachEvent) { window.attachEvent("onload", ' . $handler . '); } else { window["onload"] = ' . $handler . '; }</script>';
    $wordpress_file_upload_output .= '</div>';
    //	$wordpress_file_upload_output .= '<div>';
    //	$wordpress_file_upload_output .= wfu_test_admin();
    //	$wordpress_file_upload_output .= '</div>';
    //	The plugin uses sessions in order to detect if the page was loaded due to file upload or
    //	because the user pressed the Refresh button (or F5) of the page.
    //	In the second case we do not want to perform any file upload, so we abort the rest of the script.
    if (!isset($_SESSION['wfu_check_refresh_' . $sid]) || $_SESSION['wfu_check_refresh_' . $sid] != "form button pressed") {
        $_SESSION['wfu_check_refresh_' . $sid] = 'do not process';
        $wordpress_file_upload_output .= wfu_post_plugin_actions($params);
        return $wordpress_file_upload_output . "\n";
    }
    $_SESSION['wfu_check_refresh_' . $sid] = 'do not process';
    $params["upload_start_time"] = $_SESSION['wfu_start_time_' . $sid];
    //	The plugin uses two ways to upload the file:
    //		- The first one uses classic functionality of an HTML form (highest compatibility with browsers but few capabilities).
    //		- The second uses ajax (HTML5) functionality (medium compatibility with browsers but many capabilities, like no page refresh and progress bar).
    //	The plugin loads using ajax functionality by default, however if it detects that ajax functionality is not supported, it will automatically switch to classic functionality.
    //	The next line checks to see if the form was submitted using ajax or classic functionality.
    //	If the uploaded file variable stored in $_FILES ends with "_redirected", then it means that ajax functionality is not supported and the plugin must switch to classic functionality.
    if (isset($_FILES[$uploadedfile . '_redirected'])) {
        $params['forceclassic'] = "true";
    }
    if ($params['forceclassic'] != "true") {
        $wordpress_file_upload_output .= wfu_post_plugin_actions($params);
        return $wordpress_file_upload_output . "\n";
    }
    //  The following code is executed in case of non-ajax uploads to process the files.
    //  Consecutive checks are performed in order to verify and approve the upload of files
    $wfu_checkpass = true;
    //  First we test that WP nonce passes the check
    $wfu_checkpass = $wfu_checkpass && isset($_REQUEST["wfu_uploader_nonce"]) && wp_verify_nonce($_REQUEST["wfu_uploader_nonce"], "wfu-uploader-nonce") !== false;
    $unique_id = isset($_POST['uniqueuploadid_' . $sid]) ? sanitize_text_field($_POST['uniqueuploadid_' . $sid]) : "";
    //  Check that upload_id is valid
    $wfu_checkpass = $wfu_checkpass && strlen($unique_id) == 10;
    if ($wfu_checkpass) {
        //process any error messages due to redirection to non-ajax upload
        if (isset($_POST[$adminerrorcodes])) {
            $code = $_POST[$adminerrorcodes];
            if ($code == "") {
                $params['adminerrors'] = "";
            } elseif ($code == "1" || $code == "2" || $code == "3") {
                $params['adminerrors'] = constant('WFU_ERROR_REDIRECTION_ERRORCODE' . $code);
            } else {
                $params['adminerrors'] = WFU_ERROR_REDIRECTION_ERRORCODE0;
            }
        }
        $params['subdir_selection_index'] = -1;
        if (isset($_POST[$hiddeninput])) {
            $params['subdir_selection_index'] = sanitize_text_field($_POST[$hiddeninput]);
        }
        $wfu_process_file_array = wfu_process_files($params, 'no_ajax');
        $safe_output = $wfu_process_file_array["general"]['safe_output'];
        unset($wfu_process_file_array["general"]['safe_output']);
        //javascript code generated from individual wfu_after_upload_filters is not executed in non-ajax uploads
        unset($wfu_process_file_array["general"]['js_script']);
        $js_script_enc = "";
        //execute after upload filters
        $ret = wfu_execute_after_upload_filters($sid, $unique_id);
        if ($ret["js_script"] != "") {
            $js_script_enc = wfu_plugin_encode_string($ret["js_script"]);
        }
        $wfu_process_file_array_str = wfu_encode_array_to_string($wfu_process_file_array);
        $ProcessUploadComplete_functiondef = 'function(){wfu_ProcessUploadComplete(' . $sid . ', 1, "' . $wfu_process_file_array_str . '", "no-ajax", "", "", "' . $safe_output . '", ["false", "", "false"], "fileupload", "' . $js_script_enc . '");}';
        $wordpress_file_upload_output .= '<script type="text/javascript">window.onload=' . $ProcessUploadComplete_functiondef . '</script>';
    }
    $wordpress_file_upload_output .= wfu_post_plugin_actions($params);
    return $wordpress_file_upload_output . "\n";
}
Пример #13
0
function wfu_encode_plugin_options($plugin_options)
{
    $encoded_options = 'version=' . $plugin_options['version'] . ';';
    $encoded_options .= 'shortcode=' . wfu_plugin_encode_string($plugin_options['shortcode']) . ';';
    $encoded_options .= 'hashfiles=' . $plugin_options['hashfiles'] . ';';
    $encoded_options .= 'basedir=' . wfu_plugin_encode_string($plugin_options['basedir']) . ';';
    $encoded_options .= 'captcha_sitekey=' . wfu_plugin_encode_string($plugin_options['captcha_sitekey']) . ';';
    $encoded_options .= 'captcha_secretkey=' . wfu_plugin_encode_string($plugin_options['captcha_secretkey']);
    return $encoded_options;
}
Пример #14
0
function wfu_file_details($file, $errorstatus)
{
    global $wpdb;
    $table_name1 = $wpdb->prefix . "wfu_log";
    $siteurl = site_url();
    //extract file browser data from $file variable
    $dec_file = wfu_plugin_decode_string($file);
    $ret = wfu_extract_sortdata_from_path($dec_file);
    $filepath = $ret['path'];
    //get file data from database with user data
    $filedata = wfu_get_file_rec($filepath, true);
    if ($filedata == null) {
        return;
    }
    //check if user is allowed to perform this action
    $user = wfu_current_user_allowed_action('details', $filepath);
    if ($user == null) {
        return;
    }
    //get the username of the uploader
    $uploadername = wfu_get_username_by_id($filedata->uploaduserid);
    //extract sort info and construct contained dir
    $parts = pathinfo($filepath);
    $enc_dir = wfu_plugin_encode_string($parts['dirname'] . '[[' . $ret['sort'] . ']]');
    $stat = stat($filepath);
    $echo_str = '<div class="regev_wrap">';
    if ($errorstatus == 'error') {
        $echo_str .= "\n\t" . '<div class="error">';
        $echo_str .= "\n\t\t" . '<p>' . $_SESSION['wfu_filedetails_error'] . '</p>';
        $echo_str .= "\n\t" . '</div>';
    }
    //show file detais
    $echo_str .= "\n\t" . '<h2>Detais of File: ' . $parts['basename'] . '</h2>';
    $echo_str .= "\n\t" . '<div style="margin-top:10px;">';
    $echo_str .= "\n\t\t" . '<a href="' . $siteurl . '/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=file_browser&dir=' . $enc_dir . '" class="button" title="go back">Go back</a>';
    $echo_str .= "\n\t\t" . '<form enctype="multipart/form-data" name="editfiledetails" id="editfiledetails" method="post" action="/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=edit_filedetails" class="validate">';
    $echo_str .= "\n\t\t\t" . '<h3 style="margin-bottom: 10px; margin-top: 40px;">Upload Details</h3>';
    $echo_str .= "\n\t\t\t" . '<input type="hidden" name="action" value="edit_filedetails" />';
    $echo_str .= "\n\t\t\t" . '<input type="hidden" name="dir" value="' . $enc_dir . '">';
    $echo_str .= "\n\t\t\t" . '<input type="hidden" name="file" value="' . $file . '">';
    $echo_str .= "\n\t\t\t" . '<table class="form-table">';
    $echo_str .= "\n\t\t\t\t" . '<tbody>';
    $echo_str .= "\n\t\t\t\t\t" . '<tr class="form-field">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>Full Path</label>';
    $echo_str .= "\n\t\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t\t\t" . '<td>';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<input type="text" value="' . $filepath . '" readonly="readonly" />';
    $echo_str .= "\n\t\t\t\t\t\t" . '</td>';
    $echo_str .= "\n\t\t\t\t\t" . '</tr>';
    $echo_str .= "\n\t\t\t\t\t" . '<tr class="form-field">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>Uploaded From User</label>';
    $echo_str .= "\n\t\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t\t\t" . '<td>';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<input type="text" value="' . $uploadername . '" readonly="readonly" style="width:auto;" />';
    $echo_str .= "\n\t\t\t\t\t\t" . '</td>';
    $echo_str .= "\n\t\t\t\t\t" . '</tr>';
    $echo_str .= "\n\t\t\t\t\t" . '<tr class="form-field">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>File Size</label>';
    $echo_str .= "\n\t\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t\t\t" . '<td>';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<input type="text" value="' . $filedata->filesize . '" readonly="readonly" style="width:auto;" />';
    $echo_str .= "\n\t\t\t\t\t\t" . '</td>';
    $echo_str .= "\n\t\t\t\t\t" . '</tr>';
    $echo_str .= "\n\t\t\t\t\t" . '<tr class="form-field">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>File Date</label>';
    $echo_str .= "\n\t\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t\t\t" . '<td>';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<input type="text" value="' . date("d/m/Y H:i:s", $stat['mtime']) . '" readonly="readonly" style="width:auto;" />';
    $echo_str .= "\n\t\t\t\t\t\t" . '</td>';
    $echo_str .= "\n\t\t\t\t\t" . '</tr>';
    $echo_str .= "\n\t\t\t\t\t" . '<tr class="form-field">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>Uploaded From Page</label>';
    $echo_str .= "\n\t\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t\t\t" . '<td>';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<input type="text" value="' . get_the_title($filedata->pageid) . ' (' . $filedata->pageid . ')' . '" readonly="readonly" style="width:50%;" />';
    $echo_str .= "\n\t\t\t\t\t\t" . '</td>';
    $echo_str .= "\n\t\t\t\t\t" . '</tr>';
    $echo_str .= "\n\t\t\t\t\t" . '<tr class="form-field">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>Upload Plugin ID</label>';
    $echo_str .= "\n\t\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t\t\t" . '<td>';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<input type="text" value="' . $filedata->sid . '" readonly="readonly" style="width:auto;" />';
    $echo_str .= "\n\t\t\t\t\t\t" . '</td>';
    $echo_str .= "\n\t\t\t\t\t" . '</tr>';
    $echo_str .= "\n\t\t\t\t" . '</tbody>';
    $echo_str .= "\n\t\t\t" . '</table>';
    //show history details
    $echo_str .= "\n\t\t\t" . '<h3 style="margin-bottom: 10px; margin-top: 40px;">File History</h3>';
    $echo_str .= "\n\t\t\t" . '<table class="form-table">';
    $echo_str .= "\n\t\t\t\t" . '<tbody>';
    $echo_str .= "\n\t\t\t\t\t" . '<tr class="form-field">';
    $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<label></label>';
    $echo_str .= "\n\t\t\t\t\t\t" . '</th>';
    $echo_str .= "\n\t\t\t\t\t\t" . '<td>';
    //read all linked records
    $filerecs = array();
    array_push($filerecs, $filedata);
    $currec = $filedata;
    while ($currec->linkedto > 0) {
        $currec = $wpdb->get_row('SELECT * FROM ' . $table_name1 . ' WHERE idlog = ' . $currec->linkedto);
        if ($currec != null) {
            array_push($filerecs, $currec);
        } else {
            break;
        }
    }
    //construct report from db records
    $rep = '';
    foreach ($filerecs as $filerec) {
        $username = wfu_get_username_by_id($filerec->userid);
        $fileparts = pathinfo($filerec->filepath);
        if ($rep != '') {
            $rep .= "<br />";
        }
        $rep .= '<strong>[' . $filerec->date_from . ']</strong> ';
        if ($filerec->action == 'upload') {
            $rep .= 'File uploaded with name <strong>' . $fileparts['basename'] . '</strong> by user <strong>' . $username . '</strong>';
        } elseif ($filerec->action == 'download') {
            $rep .= 'File downloaded by user <strong>' . $username . '</strong>';
        } elseif ($filerec->action == 'rename') {
            $rep .= 'File renamed to <strong>' . $fileparts['basename'] . '</strong> by user <strong>' . $username . '</strong>';
        } elseif ($filerec->action == 'delete') {
            $rep .= 'File deleted by user <strong>' . $username . '</strong>';
        } elseif ($filerec->action == 'modify') {
            $rep .= 'File userdata modified by user <strong>' . $username . '</strong>';
        }
    }
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<div style="border:1px solid #dfdfdf; border-radius:3px; width:50%; overflow:scroll; padding:6px; height:100px; background-color:#eee;">';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '<span style="white-space:nowrap;">' . $rep . '</span>';
    $echo_str .= "\n\t\t\t\t\t\t\t" . '</div>';
    $echo_str .= "\n\t\t\t\t\t\t" . '</td>';
    $echo_str .= "\n\t\t\t\t\t" . '</tr>';
    $echo_str .= "\n\t\t\t\t" . '</tbody>';
    $echo_str .= "\n\t\t\t" . '</table>';
    $echo_str .= "\n\t\t\t" . '<h3 style="margin-bottom: 10px; margin-top: 40px;">User Data Details</h3>';
    $echo_str .= "\n\t\t\t" . '<table class="form-table">';
    $echo_str .= "\n\t\t\t\t" . '<tbody>';
    if (count($filedata->userdata) > 0) {
        foreach ($filedata->userdata as $userdata) {
            $echo_str .= "\n\t\t\t\t\t" . '<tr class="form-field">';
            $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">';
            $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>' . $userdata->property . '</label>';
            $echo_str .= "\n\t\t\t\t\t\t" . '</th>';
            $echo_str .= "\n\t\t\t\t\t\t" . '<td>';
            $echo_str .= "\n\t\t\t\t\t\t\t" . '<input id="wfu_filedetails_userdata_value_' . $userdata->propkey . '" name="wfu_filedetails_userdata" type="text" value="' . $userdata->propvalue . '" />';
            $echo_str .= "\n\t\t\t\t\t\t\t" . '<input id="wfu_filedetails_userdata_default_' . $userdata->propkey . '" type="hidden" value="' . $userdata->propvalue . '" />';
            $echo_str .= "\n\t\t\t\t\t\t\t" . '<input id="wfu_filedetails_userdata_' . $userdata->propkey . '" name="wfu_filedetails_userdata_' . $userdata->propkey . '" type="hidden" value="' . $userdata->propvalue . '" />';
            $echo_str .= "\n\t\t\t\t\t\t" . '</td>';
            $echo_str .= "\n\t\t\t\t\t" . '</tr>';
        }
    } else {
        $echo_str .= "\n\t\t\t\t\t" . '<tr class="form-field">';
        $echo_str .= "\n\t\t\t\t\t\t" . '<th scope="row">';
        $echo_str .= "\n\t\t\t\t\t\t\t" . '<label>No user data</label>';
        $echo_str .= "\n\t\t\t\t\t\t" . '</th>';
        $echo_str .= "\n\t\t\t\t\t\t" . '<td></td>';
        $echo_str .= "\n\t\t\t\t\t" . '</tr>';
    }
    $echo_str .= "\n\t\t\t\t" . '</tbody>';
    $echo_str .= "\n\t\t\t" . '</table>';
    $echo_str .= "\n\t\t\t" . '<p class="submit">';
    $echo_str .= "\n\t\t\t\t" . '<input id="dp_filedetails_submit_fields" type="submit" class="button-primary" name="submit" value="Update" disabled="disabled" />';
    $echo_str .= "\n\t\t\t" . '</p>';
    $echo_str .= "\n\t\t" . '</form>';
    $echo_str .= "\n\t" . '</div>';
    $handler = 'function() { wfu_Attach_FileDetails_Admin_Events(); }';
    $echo_str .= "\n\t" . '<script type="text/javascript">if(window.addEventListener) { window.addEventListener("load", ' . $handler . ', false); } else if(window.attachEvent) { window.attachEvent("onload", ' . $handler . '); } else { window["onload"] = ' . $handler . '; }</script>';
    $echo_str .= '</div>';
    return $echo_str;
}