WordPress File Upload - Version 4.13.1

Version Description

  • file checking of uploaded files hardened to better handle xss attacks coming through uploaded image files.
Download this release

Release Info

Developer nickboss
Plugin Icon 128x128 WordPress File Upload
Version 4.13.1
Comparing to
See all releases

Code changes from version 4.13.0 to 4.13.1

js/wordpress_file_upload_adminfunctions.js CHANGED
@@ -1,472 +1,472 @@
1
- var DraggedItem=null;var ShortcodeNextSave=0;var ShortcodeTimeOut=null;var ShortcodeString="";var Autosave=false;var PageObsolete=false;var PageUpdating=false;var CheckObsolescenceTimeOut=5E3;var wfu_transfers_observer_interval=100;var wfu_allops_freeze_events=false;var wfu_PD_bank={};
2
- jQuery(document).ready(function($){$(".wfu_color_field").wpColorPicker({change:function(event,ui){event.target.value=ui.color.toString();if(event.target.name=="wfu_text_elements")wfu_update_text_value(event);else if(event.target.name=="wfu_triplecolor_elements")wfu_update_triplecolor_value(event)}})});
3
- function wfu_admin_activate_tab(key){var tabs=document.getElementById("wfu_tab_container");var tab,tabkey;for(var i=0;i<tabs.childNodes.length;i++){tab=tabs.childNodes[i];if(tab.nodeType===1){tabkey=tab.id.substr(8);if(tab.className.indexOf("nav-tab-active")>-1){tab.className="nav-tab";document.getElementById("wfu_container_"+tabkey).style.display="none"}}}document.getElementById("wfu_tab_"+key).className="nav-tab nav-tab-active";document.getElementById("wfu_container_"+key).style.display="block"}
4
- function wfu_admin_onoff_clicked(key){var onoff=document.getElementById("wfu_attribute_"+key);var shadows=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_"+key);var shadows_inv=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_"+key+"_inv");var status=onoff.className.substr(onoff.className.length-2)=="on";status=!status;if(status){document.getElementById("wfu_attribute_value_"+key).value="true";onoff.className="wfu_onoff_container_on";for(var i=0;i<shadows.length;i++)shadows[i].style.display=
5
- "none";for(var i=0;i<shadows_inv.length;i++)shadows_inv[i].style.display="block"}else{document.getElementById("wfu_attribute_value_"+key).value="false";onoff.className="wfu_onoff_container_off";for(var i=0;i<shadows.length;i++)shadows[i].style.display="block";for(var i=0;i<shadows_inv.length;i++)shadows_inv[i].style.display="none"}wfu_generate_shortcode();if(key=="userdata"||key=="formdata")wfu_update_formfield_variables()}
6
- function wfu_admin_radio_clicked(key){var radios=document.getElementsByName("wfu_radioattribute_"+key);var shadows=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_"+key);var shadows_inv=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_"+key+"_inv");var val="";for(i=0;i<radios.length;i++)if(radios[i].checked)val=radios[i].value;var status=val.substr(0,1)=="*";if(status){val=val.substr(1);for(var i=0;i<shadows.length;i++)shadows[i].style.display="none";for(var i=0;i<shadows_inv.length;i++)shadows_inv[i].style.display=
7
- "block"}else{for(var i=0;i<shadows.length;i++)shadows[i].style.display="block";for(var i=0;i<shadows_inv.length;i++)shadows_inv[i].style.display="none"}document.getElementById("wfu_attribute_value_"+key).value=val;wfu_generate_shortcode()}function wfu_set_checkbox_status(check,status){if(status==0){check.checked=false;check.indeterminate=true;check.classList.add("indeterminate")}else{check.indeterminate=false;check.classList.remove("indeterminate");check.checked=status==1}}
8
- function wfu_addEventHandler(obj,evt,handler){if(obj.addEventListener)obj.addEventListener(evt,handler,false);else if(obj.attachEvent)obj.attachEvent("on"+evt,handler);else obj["on"+evt]=handler}
9
- function wfu_attach_separator_dragdrop_events(){var container=document.getElementById("wfu_placements_container");var item;for(var i=0;i<container.childNodes.length;i++){item=container.childNodes[i];if(item.className=="wfu_component_separator_hor"||item.className=="wfu_component_separator_ver"){wfu_addEventHandler(item,"dragenter",wfu_separator_dragenter);wfu_addEventHandler(item,"dragover",wfu_default_dragover);wfu_addEventHandler(item,"dragleave",wfu_separator_dragleave);wfu_addEventHandler(item,
10
- "drop",wfu_separator_drop)}}}
11
- function wfu_Attach_Admin_DragDrop_Events(){if(window.FileReader){var container=document.getElementById("wfu_placements_container");if(container){var available_container=document.getElementById("wfu_componentlist_container");var item;for(var i=0;i<container.childNodes.length;i++){item=container.childNodes[i];if(item.className=="wfu_component_box"){wfu_addEventHandler(item,"dragstart",wfu_component_dragstart);wfu_addEventHandler(item,"dragend",wfu_component_dragend)}}for(var i=0;i<available_container.childNodes.length;i++){item=
12
- available_container.childNodes[i];if(item.className=="wfu_component_box_container")for(var ii=0;ii<item.childNodes.length;ii++)if(item.childNodes[ii].className=="wfu_component_box wfu_inbase"){wfu_addEventHandler(item.childNodes[ii],"dragstart",wfu_component_dragstart);wfu_addEventHandler(item.childNodes[ii],"dragend",wfu_component_dragend)}}item=document.getElementById("wfu_componentlist_dragdrop");wfu_addEventHandler(item,"dragenter",wfu_componentlist_dragenter);wfu_addEventHandler(item,"dragover",
13
- wfu_default_dragover);wfu_addEventHandler(item,"dragleave",wfu_componentlist_dragleave);wfu_addEventHandler(item,"drop",wfu_componentlist_drop);wfu_attach_separator_dragdrop_events()}}}
14
- function wfu_componentlist_dragenter(e){e=e||window.event;if(e.preventDefault)e.preventDefault();if(!DraggedItem)return false;var item=document.getElementById("wfu_componentlist_dragdrop");if(item.className.indexOf("wfu_componentlist_dragdrop_dragover")==-1)item.className+=" wfu_componentlist_dragdrop_dragover";return false}
15
- function wfu_componentlist_dragleave(e){e=e||window.event;if(e.preventDefault)e.preventDefault();if(!DraggedItem)return false;var item=document.getElementById("wfu_componentlist_dragdrop");item.className=item.className.replace(" wfu_componentlist_dragdrop_dragover","");return false}
16
- function wfu_componentlist_drop(e){e=e||window.event;if(e.preventDefault)e.preventDefault();var component_raw=e.dataTransfer.getData("Component");if(!component_raw)return false;var parts=component_raw.split("_");var component=parts[0];var multi_index=parseInt(parts[1]);var item=document.getElementById("wfu_component_box_"+component+"_"+multi_index);if(multi_index==0){item.className="wfu_component_box wfu_inbase";item.style.display="block";document.getElementById("wfu_component_box_container_"+component).appendChild(item)}else item.parentNode.removeChild(item);
17
- var placements=wfu_admin_recreate_placements_text(null,"");wfu_admin_recreate_placements_panel(placements);document.getElementById("wfu_attribute_value_placements").value=placements;wfu_update_multiplacement_attributes();wfu_generate_shortcode();return false}
18
- function wfu_separator_dragenter(e){e=e||window.event;if(e.preventDefault)e.preventDefault();if(!DraggedItem)return false;if(e.target.className=="wfu_component_separator_hor"){var bar=document.getElementById("wfu_component_bar_hor");bar.style.top=e.target.offsetTop+"px";bar.style.display="block"}else if(e.target.className=="wfu_component_separator_ver"){var bar=document.getElementById("wfu_component_bar_ver");bar.style.top=e.target.offsetTop+"px";bar.style.left=e.target.offsetLeft+"px";bar.style.display=
19
- "block"}return false}function wfu_default_dragover(e){e=e||window.event;if(e.preventDefault)e.preventDefault();return false}
20
- function wfu_separator_dragleave(e){e=e||window.event;if(e.preventDefault)e.preventDefault();if(!DraggedItem)return false;if(e.target.className=="wfu_component_separator_hor"){var bar=document.getElementById("wfu_component_bar_hor");bar.style.display="none"}else if(e.target.className=="wfu_component_separator_ver"){var bar=document.getElementById("wfu_component_bar_ver");bar.style.display="none"}return false}
21
- function wfu_separator_drop(e){e=e||window.event;if(e.preventDefault)e.preventDefault();var component_raw=e.dataTransfer.getData("Component");if(!component_raw)return false;var parts=component_raw.split("_");var component=parts[0];var multi_index=parseInt(parts[1]);var item=document.getElementById("wfu_component_box_"+component+"_"+multi_index);item.style.display="none";item.className="wfu_component_box wfu_inbase";document.getElementById("wfu_component_box_container_"+component).appendChild(item);
22
- var placements=wfu_admin_recreate_placements_text(e.target,component);wfu_admin_recreate_placements_panel(placements);document.getElementById("wfu_attribute_value_placements").value=placements;wfu_update_multiplacement_attributes();wfu_generate_shortcode();return false}
23
- function wfu_component_dragstart(e){e=e||window.event;e.dataTransfer.setData("Component",e.target.id.replace("wfu_component_box_",""));if(e.target.className.indexOf("wfu_component_box_dragged")==-1){e.target.className+=" wfu_component_box_dragged";DraggedItem=e.target}e.target.style.zIndex=3;var item=document.getElementById("wfu_componentlist_dragdrop");item.className="wfu_componentlist_dragdrop wfu_componentlist_dragdrop_dragover";item.style.display="block";return false}
24
- function wfu_component_dragend(e){e=e||window.event;DraggedItem=null;e.target.style.zIndex=1;var item=document.getElementById("wfu_componentlist_dragdrop");item.style.display="none";item.className="wfu_componentlist_dragdrop";e.target.className=e.target.className.replace(" wfu_component_box_dragged","");document.getElementById("wfu_component_bar_ver").style.display="none";document.getElementById("wfu_component_bar_hor").style.display="none";return false}
25
- function wfu_admin_recreate_placements_text(place,new_component){function add_item(component){if(placements!="")placements+=delim;placements+=component;delim=""}var container=document.getElementById("wfu_placements_container");var delim="";var placements="";var component="";for(var i=0;i<container.childNodes.length;i++){item=container.childNodes[i];if(item.className=="wfu_component_separator_ver"){if(delim=="")delim="+";if(item==place){add_item(new_component);delim="+"}}else if(item.className=="wfu_component_separator_hor"){delim=
26
- "/";if(item==place){add_item(new_component);delim="/"}}else if(item.className=="wfu_component_box")add_item(item.id.replace("wfu_component_box_","").replace(/_.*$/,""))}return placements}
27
- function wfu_admin_recreate_placements_panel(placements_text){var container=document.getElementById("wfu_placements_container");var item,placements,sections,itemname_raw,parts,multi_index,index_item;var itemname="";for(var i=0;i<container.childNodes.length;i++){item=container.childNodes[i];if(item.className=="wfu_component_box"){itemname_raw=item.id.replace("wfu_component_box_","");parts=itemname_raw.split("_");itemname=parts[0];multi_index=parseInt(parts[1]);if(multi_index==0){item.style.display=
28
- "inline-block";item.className="wfu_component_box wfu_inbase";document.getElementById("wfu_component_box_container_"+itemname).appendChild(item)}else item.parentNode.removeChild(item)}}var box_containers=document.querySelectorAll("div.wfu_component_box_container");var component_used={};for(var i=0;i<box_containers.length;i++){itemname=box_containers[i].id.replace("wfu_component_box_container_","");component_used[itemname]=0;index_item=document.querySelector("div#"+box_containers[i].id+" div.wfu_component_box_index");
29
- if(index_item)index_item.innerHTML="1"}container.innerHTML="";placements=placements_text.split("/");for(var i=0;i<placements.length;i++){item=document.createElement("DIV");item.className="wfu_component_separator_hor";item.setAttribute("draggable",true);container.appendChild(item);item=document.createElement("DIV");item.className="wfu_component_separator_ver";item.setAttribute("draggable",true);container.appendChild(item);sections=placements[i].split("+");for(var ii=0;ii<sections.length;ii++){item=
30
- document.querySelector("div#wfu_component_box_container_"+sections[ii]+" div.wfu_component_box.wfu_inbase");if(item){itemname_raw=item.id.replace("wfu_component_box_","");parts=itemname_raw.split("_");itemname=parts[0];multi_index=parseInt(parts[1]);if(multi_index==0)container.appendChild(item);else{component_used[itemname]++;item.id="wfu_component_box_"+itemname+"_"+(component_used[itemname]+1).toString();item.style.display="block";index_item=document.querySelector("div#"+item.id+" div.wfu_component_box_index");
31
- index_item.innerHTML=(component_used[itemname]+1).toString();item=item.cloneNode(true);container.appendChild(item);item.id="wfu_component_box_"+itemname+"_"+component_used[itemname].toString();index_item=document.querySelector("div#"+item.id+" div.wfu_component_box_index");index_item.innerHTML=component_used[itemname].toString();wfu_addEventHandler(item,"dragstart",wfu_component_dragstart);wfu_addEventHandler(item,"dragend",wfu_component_dragend)}item.className="wfu_component_box";item.style.display=
32
- "inline-block";item=document.createElement("DIV");item.className="wfu_component_separator_ver";item.setAttribute("draggable",true);container.appendChild(item)}}}item=document.createElement("DIV");item.className="wfu_component_separator_hor";item.setAttribute("draggable",true);container.appendChild(item);item=document.createElement("DIV");item.id="wfu_component_bar_hor";item.className="wfu_component_bar_hor";container.appendChild(item);item=document.createElement("DIV");item.id="wfu_component_bar_ver";
33
- item.className="wfu_component_bar_ver";container.appendChild(item);wfu_attach_separator_dragdrop_events()}
34
- function wfu_update_multiplacement_attributes(){var box_containers=document.querySelectorAll("div.wfu_component_box_container");for(var i=0;i<box_containers.length;i++){itemname=box_containers[i].id.replace("wfu_component_box_container_","");var index_item=document.querySelector("div#"+box_containers[i].id+" div.wfu_component_box_index");if(index_item){var occurrences=Math.max(1,parseInt(index_item.innerHTML)-1);var dependencies=document.getElementsByName("wfu_attribute_governor_"+itemname);for(var j=
35
- 0;j<dependencies.length;j++)wfu_update_multiplacement_attribute(dependencies[j].value,occurrences)}}}
36
- function wfu_update_multiplacement_attribute(attribute,occurrencies){if(attribute=="userdatalabel"){var attributes=document.querySelectorAll("div.wfu_formdata_container");var current=attributes.length;if(current<1)return;var base=attributes[0],tr0,tr;var i=2;while(i<=Math.max(current,occurrencies)){if(i>current){var new_attribute=attribute+i.toString();tr0=base.parentNode;while(tr0!=null&&tr0.tagName!="TR")tr0=tr0.parentNode;if(tr0==null||tr0.tagName!="TR")return;tr=tr0.cloneNode(true);tr.id="tr_"+
37
- wfu_randomString(4);tr0.parentNode.appendChild(tr);var elem=document.querySelector("tr#"+tr.id+' label[for="wfu_attribute_'+attribute+'"]');elem.setAttribute("for","wfu_attribute_"+new_attribute);elem.innerHTML+=" ("+i.toString()+")";elem=document.querySelector("tr#"+tr.id+" input.wfu_attribute_governor");elem.setAttribute("name","wfu_attribute_governor_independent");elem.value=new_attribute;elem=document.querySelector("tr#"+tr.id+" div.wfu_formdata_container");elem.id+=i.toString();var def=document.getElementById("wfu_attribute_default_"+
38
- new_attribute);if(!def){def=document.createElement("INPUT");def.id="wfu_attribute_default_"+new_attribute;def.type="hidden";def.value=document.getElementById("wfu_attribute_default_"+attribute).value;document.getElementById("wfu_attribute_defaults").appendChild(def)}var shortcode_value=document.getElementById("wfu_attribute_value_"+new_attribute);if(!shortcode_value){shortcode_value=document.createElement("INPUT");shortcode_value.id="wfu_attribute_value_"+new_attribute;shortcode_value.type="hidden";
39
- shortcode_value.value=def.value;document.getElementById("wfu_attribute_values").appendChild(shortcode_value)}window["wfu_attribute_"+new_attribute+"_formtemplate"]=window["wfu_attribute_"+attribute+"_formtemplate"];window["wfu_attribute_"+new_attribute+"_typeprops"]=window["wfu_attribute_"+attribute+"_typeprops"];wfu_apply_value(new_attribute,"formfields",shortcode_value.value)}else if(i>occurrencies){tr=attributes[i-1].parentNode;while(tr!=null&&tr.tagName!="TR")tr=tr.parentNode;if(tr==null||tr.tagName!=
40
- "TR")return;tr.parentNode.removeChild(tr);wfu_update_formfield_variables()}i++}attributes=document.querySelectorAll("div.wfu_formdata_container");var names=[];for(var i=0;i<attributes.length;i++)names.push(attributes[i].id.replace(/^wfu_attribute_/,""));var all_attributes=document.querySelectorAll(".wfu_formdata_all_attributes");for(var i=0;i<all_attributes.length;i++)all_attributes[i].value=names.join(",");wfu_formdata_update_all_updown_buttons(attribute)}}
41
- function wfu_subfolders_input_changed(e){e=e||window.event;var item=e.target;var key=item.id.replace("wfu_subfolders_path_","");key=key.replace("wfu_subfolders_label_","");var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+key);var tools_ok=document.getElementById("wfu_subfolders_ok_"+key);var old_path_value,old_label_value;var isnewitem=
42
- document.getElementById("wfu_subfolders_isnewitem_"+key).value=="1";if(isnewitem){old_path_value="";old_label_value=""}else{var items=list.data;item=items[list.selectedIndex];old_path_value=item.path;old_label_value=item.label}if(tools_path.value==old_path_value&&tools_label.value==old_label_value){tools_ok.disabled=true;if(!isnewitem)wfu_subfolders_update_nav(key)}else{tools_ok.disabled=false;var navs=document.getElementsByName("wfu_subfolder_nav_"+key);for(var i=0;i<navs.length;i++)navs[i].disabled=
43
- true}}
44
- function wfu_subfolders_auto_changed(key){var list=document.getElementById("wfu_attribute_"+key);var auto=document.getElementById("wfu_subfolders_auto_"+key);var editable=document.getElementById("wfu_subfolders_editable_"+key);var manualtext=document.getElementById("wfu_subfolders_manualtext_"+key);if(auto.checked){var manualvalue=document.getElementById("wfu_attribute_value_"+key).value;if(manualvalue.substr(0,4)!="auto")manualtext.value=manualvalue;editable.parentNode.style.display="inline";wfu_apply_value(key,
45
- "folderlist","auto"+(editable.checked?"+":""));list.disabled=true}else{list.disabled=false;editable.parentNode.style.display="none";wfu_apply_value(key,"folderlist",manualtext.value)}}
46
- function wfu_subfolders_up_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];var prevind=item.index-1;if(prevind<0)return;var prevpos=-1;var curind=list.selectedIndex-1;while(curind>=0)if(items[curind].level==item.level&&items[curind].index==prevind){prevpos=curind;break}else curind--;if(prevpos==-1)return;var children_count=0;curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level>
47
- item.level){children_count++;curind++}else break;items[prevpos].index=item.index;item.index=prevind;list.data=items.slice(0,prevpos).concat(items.slice(list.selectedIndex,list.selectedIndex+1+children_count)).concat(items.slice(prevpos,list.selectedIndex)).concat(items.slice(list.selectedIndex+1+children_count));var val=wfu_update_subfolder_list(key);list.selectedIndex=prevpos;wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
48
- key).value=val;wfu_generate_shortcode()}}
49
- function wfu_subfolders_down_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];var nextind=item.index+1;var nextpos=-1;curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level==item.level){nextpos=curind;break}else if(items[curind].level<item.level)break;else curind++;if(nextpos==-1)return;var next_children_count=0;curind=nextpos+1;while(curind<items.length)if(items[curind].level>
50
- item.level){next_children_count++;curind++}else break;items[nextpos].index=item.index;item.index=nextind;list.data=items.slice(0,list.selectedIndex).concat(items.slice(nextpos,nextpos+1+next_children_count)).concat(items.slice(list.selectedIndex,nextpos)).concat(items.slice(nextpos+1+next_children_count));var val=wfu_update_subfolder_list(key);list.selectedIndex=list.selectedIndex+next_children_count+1;wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
51
- key).value=val;wfu_generate_shortcode()}}
52
- function wfu_subfolders_left_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level>item.level){items[curind].level--;curind++}else break;item.level--;var val=wfu_update_subfolder_list(key);list.data=wfu_decode_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
53
- key).value=val;wfu_generate_shortcode()}}
54
- function wfu_subfolders_right_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level>item.level){items[curind].level++;curind++}else break;item.level++;var val=wfu_update_subfolder_list(key);list.data=wfu_decode_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
55
- key).value=val;wfu_generate_shortcode()}}
56
- function wfu_subfolders_def_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];if(item["default"])item["default"]=false;else{for(var i=0;i<items.length;i++)items[i]["default"]=false;item["default"]=true}var val=wfu_update_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+key).value=val;wfu_generate_shortcode()}}
57
- function wfu_subfolders_ok_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+key);if(tools_path.value==""||tools_label.value==""){alert("Path or label cannot be empty!");return}var items=list.data;var isnewitem=document.getElementById("wfu_subfolders_isnewitem_"+key).value=="1";if(isnewitem){var newlevel=parseInt(document.getElementById("wfu_subfolders_newitemlevel_"+
58
- key).value);var newitem={label:tools_label.value,path:tools_path.value,level:newlevel,"default":false};var newpos=parseInt(document.getElementById("wfu_subfolders_newitemindex_"+key).value);if(newpos>=items.length)items.push(newitem);else items.splice(newpos,0,newitem)}else{item=items[list.selectedIndex];item.path=tools_path.value;item.label=tools_label.value}var val=wfu_update_subfolder_list(key);list.data=wfu_decode_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=
59
- val;document.getElementById("wfu_attribute_value_"+key).value=val;wfu_generate_shortcode()}}
60
- function wfu_subfolders_del_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];var children_count=0;curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level>item.level){children_count++;curind++}else break;if(children_count>0)if(!confirm("Children items will be deleted as well. Proceed?"))return;items.splice(list.selectedIndex,1+children_count);var val=wfu_update_subfolder_list(key);
61
- list.data=wfu_decode_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+key).value=val;wfu_generate_shortcode()}}
62
- function wfu_subfolders_add_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;var curpos=list.selectedIndex;item=items[curpos];var opts=list.options;var opt=document.createElement("option");opt.value="";opt.innerHTML="";opts.add(opt,curpos);list.selectedIndex=curpos;var tools_container=document.getElementById("wfu_subfolder_tools_"+key);var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+
63
- key);var tools_ok=document.getElementById("wfu_subfolders_ok_"+key);var tools_browse=document.getElementById("wfu_subfolders_browse_"+key);tools_container.className="wfu_subfolder_tools_container";tools_label.disabled=false;tools_ok.disabled=true;document.getElementById("wfu_subfolders_isnewitem_"+key).value="1";document.getElementById("wfu_subfolders_newitemindex_"+key).value=curpos;document.getElementById("wfu_subfolders_newitemlevel_"+key).value=item.level;document.getElementById("wfu_subfolders_newitemlevel2_"+
64
- key).value="";tools_path.disabled=item.level==0;tools_browse.disabled=item.level==0;if(item.level==0){tools_path.value="{root}";tools_label.value="{upload folder}"}else{tools_path.value="";tools_label.value=""}var navs=document.getElementsByName("wfu_subfolder_nav_"+key);for(var i=0;i<navs.length;i++)navs[i].disabled=true}
65
- function wfu_subfolders_browse_clicked(key){var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var fd=null;try{var fd=new FormData}catch(e){}if(fd==null)return;var container=document.getElementById("wfu_global_dialog_container");var dialog=document.getElementById("wfu_subfolders_browser_"+key);var btn=document.getElementById("wfu_subfolders_browse_"+key);var shadow=document.getElementById("wfu_subfolders_inner_shadow_"+key);var msgcont=document.getElementById("wfu_subfolders_browser_msgcont_"+
66
- key);var msg=document.getElementById("wfu_subfolders_browser_msg_"+key);var img=document.getElementById("wfu_subfolders_browser_img_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);var list=document.getElementById("wfu_subfolders_browser_list_"+key);while(list.options.length>0)list.options.remove(0);ok.disabled=true;ok.onclick=function(){wfu_folder_browser_cancel_clicked(key)};msg.innerHTML="loading folder contents...";img.style.display="inline";msgcont.style.display="block";
67
- container.style.display="block";dialog.style.display="block";dialog.style.left=btn.offsetLeft+btn.offsetWidth-dialog.offsetWidth+"px";dialog.style.top=btn.offsetTop+btn.offsetHeight-dialog.offsetHeight+"px";shadow.style.display="block";container.onclick=function(){wfu_folder_browser_cancel_clicked(key)};var path=document.getElementById("wfu_attribute_uploadpath").value;if(path.substr(path.length-1)=="/")path=path.substr(0,path.length-1);var paths=wfu_get_relative_path(key).split(",");var path1=path+
68
- paths[0];if(path1.substr(0)!="/")path1="/"+path1;var path2="";if(paths.length==2)path2=paths[1];fd.append("action","wfu_ajax_action_read_subfolders");fd.append("folder1",wfu_plugin_encode_string(path1));fd.append("folder2",wfu_plugin_encode_string(path2));xhr.key=key;xhr.addEventListener("load",wfu_readfolderComplete,false);xhr.addEventListener("error",wfu_readfolderFailed,false);xhr.addEventListener("abort",wfu_readfolderCanceled,false);xhr.open("POST",AdminParams.wfu_ajax_url);xhr.send(fd)}
69
- function wfu_readfolderComplete(evt){var key=evt.target.key;var msgcont=document.getElementById("wfu_subfolders_browser_msgcont_"+key);var msg=document.getElementById("wfu_subfolders_browser_msg_"+key);var img=document.getElementById("wfu_subfolders_browser_img_"+key);var list=document.getElementById("wfu_subfolders_browser_list_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+
70
- key);var txt=evt.target.responseText;if(txt!=-1){var start_text="wfu_read_subfolders:";var pos=evt.target.responseText.indexOf(start_text);if(pos==-1)pos=evt.target.responseText.length;var messages=evt.target.responseText.substr(0,pos);var response=evt.target.responseText.substr(pos+start_text.length,evt.target.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header=="success"){var filelist=
71
- wfu_plugin_decode_string(txt_value);var flist=filelist.split(",");var fcount=0;var opt;for(var i=0;i<flist.length;i++)if(flist[i]!=""){opt=document.createElement("option");opt.value=flist[i];opt.innerHTML=flist[i].replace("*","&nbsp;&nbsp;&nbsp;");list.add(opt);fcount++}if(fcount==0){opt=document.createElement("option");opt.value="";opt.innerHTML="{empty}";opt.disabled=true;list.add(opt)}list.selectedIndex=-1;ok.onclick=function(){var val=list.options[list.selectedIndex].value;var level=parseInt(document.getElementById("wfu_subfolders_newitemlevel_"+
72
- key).value);if(val.substr(0,1)=="*"||level==0){document.getElementById("wfu_subfolders_newitemlevel_"+key).value=level+1;if(level>0)val=val.substr(1)}tools_path.value=val;tools_label.value=val;wfu_folder_browser_cancel_clicked(key);wfu_subfolders_ok_clicked(key)};msgcont.style.display="none"}else if(txt_header=="error"){msg.innerHTML=txt_value;img.style.display="none";ok.disabled=false}else{msg.innerHTML="Unknown error";img.style.display="none";ok.disabled=false}}}
73
- function wfu_readfolderFailed(evt){var key=evt.target.key;var msg=document.getElementById("wfu_subfolders_browser_msg_"+key);var img=document.getElementById("wfu_subfolders_browser_img_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);msg.innerHTML="Unknown error";img.style.display="none";ok.disabled=false}
74
- function wfu_readfolderCanceled(evt){var key=evt.target.key;var msg=document.getElementById("wfu_subfolders_browser_msg_"+key);var img=document.getElementById("wfu_subfolders_browser_img_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);msg.innerHTML="Unknown error";img.style.display="none";ok.disabled=false}
75
- function wfu_subfolders_browser_list_changed(key){var list=document.getElementById("wfu_subfolders_browser_list_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);ok.disabled=list.selectedIndex<0}
76
- function wfu_folder_browser_cancel_clicked(key){var container=document.getElementById("wfu_global_dialog_container");var dialog=document.getElementById("wfu_subfolders_browser_"+key);var btn=document.getElementById("wfu_subfolders_browse_"+key);var shadow=document.getElementById("wfu_subfolders_inner_shadow_"+key);container.onclick=null;shadow.style.display="none";dialog.style.display="none";container.style.display="none"}
77
- function wfu_get_relative_path(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;var isnewitem=document.getElementById("wfu_subfolders_isnewitem_"+key).value=="1";var level;if(isnewitem)level=parseInt(document.getElementById("wfu_subfolders_newitemlevel_"+key).value);else level=items[list.selectedIndex].level;var relpath="/";var curpos=list.selectedIndex-1;var curlevel=level;while(curpos>=0&&curlevel>1){if(items[curpos].level<curlevel){relpath=
78
- "/"+items[curpos].path+relpath;curlevel=items[curpos].level}curpos--}if(isnewitem&&document.getElementById("wfu_subfolders_newitemlevel2_"+key).value=="1"&&level>0&&list.selectedIndex>0)relpath+=","+items[list.selectedIndex-1].path;return relpath}function wfu_subfolders_changed(key){wfu_update_subfolder_list(key);wfu_subfolders_update_toolnav(key)}
79
- function wfu_subfolders_update_toolnav(key){var list=document.getElementById("wfu_attribute_"+key);var items,item,ind,nextind,prevlevel;var tools_container=document.getElementById("wfu_subfolder_tools_"+key);var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+key);var tools_ok=document.getElementById("wfu_subfolders_ok_"+key);var tools_browse=document.getElementById("wfu_subfolders_browse_"+key);var auto=document.getElementById("wfu_subfolders_auto_"+
80
- key);document.getElementById("wfu_subfolders_isnewitem_"+key).value="";document.getElementById("wfu_subfolders_newitemindex_"+key).value="";document.getElementById("wfu_subfolders_newitemlevel_"+key).value="";document.getElementById("wfu_subfolders_newitemlevel2_"+key).value="";if(list.data==null){items=wfu_decode_subfolder_list(key);list.data=items}else items=list.data;if(list.data.length===0){list.className="wfu_select_folders wfu_select_folders_empty";list.options[0].innerHTML=auto.checked?"":
81
- "press here"}else list.className="wfu_select_folders";if(list.selectedIndex<0){tools_container.className="wfu_subfolder_tools_container wfu_subfolder_tools_disabled";tools_path.disabled=true;tools_label.disabled=true;tools_ok.disabled=true;tools_browse.disabled=true;tools_label.value="";tools_path.value=""}else if(list.selectedIndex>=list.options.length-1){tools_container.className="wfu_subfolder_tools_container";tools_label.disabled=false;tools_ok.disabled=true;document.getElementById("wfu_subfolders_isnewitem_"+
82
- key).value="1";document.getElementById("wfu_subfolders_newitemindex_"+key).value=items.length;var level;if(items.length==0)level=0;else if(items[items.length-1].level==0)level=1;else level=items[items.length-1].level;document.getElementById("wfu_subfolders_newitemlevel_"+key).value=level;document.getElementById("wfu_subfolders_newitemlevel2_"+key).value="1";tools_path.disabled=level==0;tools_browse.disabled=false;if(level==0){tools_path.value="{root}";tools_label.value="{upload folder}"}else{tools_path.value=
83
- "";tools_label.value=""}}else{tools_container.className="wfu_subfolder_tools_container";tools_label.disabled=false;tools_ok.disabled=true;item=items[list.selectedIndex];tools_path.disabled=item.level==0;tools_browse.disabled=item.level==0;tools_label.value=item.label;tools_path.value=item.path}var navs=document.getElementsByName("wfu_subfolder_nav_"+key);if(list.selectedIndex<0||list.selectedIndex>=list.options.length-1)for(var i=0;i<navs.length;i++)navs[i].disabled=true;else wfu_subfolders_update_nav(key)}
84
- function wfu_subfolders_update_nav(key){var list=document.getElementById("wfu_attribute_"+key);var navs_up=document.getElementById("wfu_subfolders_up_"+key);var navs_down=document.getElementById("wfu_subfolders_down_"+key);var navs_left=document.getElementById("wfu_subfolders_left_"+key);var navs_right=document.getElementById("wfu_subfolders_right_"+key);var navs_add=document.getElementById("wfu_subfolders_add_"+key);var navs_def=document.getElementById("wfu_subfolders_def_"+key);var navs_del=document.getElementById("wfu_subfolders_del_"+
85
- key);var items=list.data;var item=items[list.selectedIndex];navs_up.disabled=item.index<=0;ind=list.selectedIndex+1;nextind=0;while(ind<items.length)if(items[ind].level==item.level){nextind=items[ind].index;break}else if(items[ind].level<item.level)break;else ind++;navs_down.disabled=item.level==0||nextind==0;navs_left.disabled=list.selectedIndex==0&&item.level<1||list.selectedIndex>0&&item.level<=1;if(list.selectedIndex>=1)prevlevel=items[list.selectedIndex-1].level;else prevlevel=0;navs_right.disabled=
86
- item.level-prevlevel>0;navs_add.disabled=item.level==0;navs_def.disabled=false;navs_def.className="button"+(item["default"]?" wfu_subfolder_nav_pressed":"");navs_del.disabled=false}
87
- function wfu_decode_subfolder(data){var ret={label:"",path:"",level:0,"default":false};data=data.trim();var star_count=0;var is_default=false;while(star_count<data.length)if(data.substr(star_count,1)=="*")star_count++;else break;data=data.substr(star_count,data.length-star_count);if(data.substr(0,1)=="&"){data=data.substr(1);is_default=true}ret.level=star_count;ret["default"]=is_default;var data_raw=data.split("/");if(data_raw.length==1){ret.path=data_raw[0];ret.label=data_raw[0]}else if(data_raw.length>
88
- 1){ret.path=data_raw[0];ret.label=data_raw[1]}if(star_count==0){ret.path="{root}";if(ret.label=="")ret.label="{upload folder}"}return ret}
89
- function wfu_decode_subfolder_list(key){var opts=document.getElementById("wfu_attribute_"+key).options;var list=Array();var dir_levels=["root"];var last_index=[0];var subfolder_path;var prev_level=-1;for(var i=0;i<opts.length-1;i++){list.push(wfu_decode_subfolder(wfu_plugin_decode_string(opts[i].value)));if(dir_levels.length>list[i].level)dir_levels[list[i].level]=list[i].path;else dir_levels.push(list[i].path);subfolder_path="";for(j=1;j<=list[i].level;j++)subfolder_path+=dir_levels[j]+"/";list[i].fullpath=
90
- subfolder_path;if(last_index.length<=list[i].level)last_index.push(0);if(list[i].level>prev_level)list[i].index=0;else list[i].index=last_index[list[i].level]+1;last_index[list[i].level]=list[i].index;prev_level=list[i].level}return list}
91
- function wfu_update_subfolder_list(key){var opts=document.getElementById("wfu_attribute_"+key).options;var list=document.getElementById("wfu_attribute_"+key);var items=list.data;if(items==null)return;var value_raw,text_raw;var global_raw="";opts.length=items.length+1;for(var i=0;i<items.length;i++){value_raw="";text_raw="";for(j=0;j<items[i].level;j++){value_raw+="*";text_raw+="&nbsp;&nbsp;&nbsp;"}if(items[i]["default"]){value_raw+="&";opts[i].className="wfu_select_folders_option_default"}else opts[i].className=
92
- "";value_raw+=items[i].path+"/"+items[i].label;text_raw+=items[i].label;opts[i].value=wfu_plugin_encode_string(value_raw);opts[i].innerHTML=text_raw;if(global_raw!="")global_raw+=",";global_raw+=value_raw}opts[items.length].value="";opts[items.length].innerHTML="";return global_raw}
93
- function wfu_userdata_edit_field(line,label,required){var item;for(var i=0;i<line.childNodes.length;i++){item=line.childNodes[i];if(item.tagName=="INPUT")if(item.type=="text"){item.value=label;wfu_attach_element_handlers(item,wfu_update_userfield_value)}else{if(item.type=="checkbox")item.checked=required}else if(item.tagName=="DIV")item.className="wfu_userdata_action"}}function wfu_formdata_edit_field(line,label,required){}
94
- function wfu_formdata_get_field_props(key){var key_parts=key.split("_");var attribute=key_parts[0];var a="wfu_formfield_"+key;var fielddef=window["wfu_attribute_"+attribute+"_typeprops"][document.getElementById(a+"_type").value];var field={type:document.getElementById(a+"_type").value,label:fielddef.label==""?document.getElementById(a+"_label").value:fielddef.label,labelposition:fielddef.labelposition.substr(0,4)=="show"&&document.getElementById(a+"_labelposition")?document.getElementById(a+"_labelposition").value:
95
- fielddef.labelposition.substr(5),required:fielddef.required.substr(0,4)=="show"&&document.getElementById(a+"_required")?document.getElementById(a+"_required").checked:fielddef.required.substr(5)=="true",donotautocomplete:fielddef.donotautocomplete.substr(0,4)=="show"&&document.getElementById(a+"_donotautocomplete")?document.getElementById(a+"_donotautocomplete").checked:fielddef.donotautocomplete.substr(5)=="true",validate:fielddef.validate.substr(0,4)=="show"&&document.getElementById(a+"_validate")?
96
- document.getElementById(a+"_validate").checked:fielddef.validate.substr(5)=="true",typehook:fielddef.typehook.substr(0,4)=="show"&&document.getElementById(a+"_typehook")?document.getElementById(a+"_typehook").checked:fielddef.typehook.substr(5)=="true",hintposition:fielddef.hintposition.substr(0,4)=="show"&&document.getElementById(a+"_hintposition")?document.getElementById(a+"_hintposition").value:fielddef.hintposition.substr(5),"default":fielddef["default"].substr(0,4)=="show"&&document.getElementById(a+
97
- "_default")?document.getElementById(a+"_default").value:fielddef["default"].substr(5),data:fielddef.data.substr(0,4)=="show"&&document.getElementById(a+"_data")?document.getElementById(a+"_data").value:fielddef.data.substr(5),group:fielddef.group.substr(0,4)=="show"&&document.getElementById(a+"_group")?document.getElementById(a+"_group").value:fielddef.group.substr(5),format:fielddef.format.substr(0,4)=="show"&&document.getElementById(a+"_format")?document.getElementById(a+"_format").value:fielddef.format.substr(5)};
98
- return field}
99
- function wfu_formdata_type_changed(key){var key_parts=key.split("_");var attribute=key_parts[0];var a="wfu_formfield_"+key;var line_container=document.getElementById(a+"_container");var field=wfu_formdata_get_field_props(key);var template=wfu_formdata_prepare_template(attribute,field,key);line_container.innerHTML=template;var formfield_elements=document.querySelectorAll("div#"+a+'_container input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],wfu_update_formfield_value);
100
- wfu_formdata_update_buttons(key);wfu_update_formfield_value({target:line_container})}function wfu_userdata_add_field(obj){var line=obj.parentNode;var newline=line.cloneNode(true);wfu_userdata_edit_field(newline,"",false);line.parentNode.insertBefore(newline,line.nextSibling)}
101
- function wfu_formdata_add_field(key){var key_parts=key.split("_");var attribute=key_parts[0];var ind=key_parts[1];var container=document.getElementById("wfu_attribute_"+attribute);var prev=document.getElementById("wfu_formfield_"+key+"_container");var new_line_container=document.createElement("DIV");var new_key=attribute+"_"+wfu_randomString(4);new_line_container.id="wfu_formfield_"+new_key+"_container";new_line_container.className="wfu_formdata_line_container";container.insertBefore(new_line_container,
102
- prev.nextSibling);var field={type:"text",label:"",labelposition:"left",required:false,donotautocomplete:false,validate:false,"default":"",data:"",group:"",format:"",hintposition:"right",typehook:false};var template=wfu_formdata_prepare_template(attribute,field,new_key);new_line_container.innerHTML=template;var formfield_elements=document.querySelectorAll("div#wfu_formfield_"+new_key+'_container input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],
103
- wfu_update_formfield_value);wfu_formdata_update_buttons(key);wfu_formdata_update_buttons(new_key);wfu_update_formfield_value({target:new_line_container})}
104
- function wfu_formdata_prepare_template(attribute,field,key){var template=wfu_plugin_decode_string(window["wfu_attribute_"+attribute+"_formtemplate"]);var fielddef=window["wfu_attribute_"+attribute+"_typeprops"][field.type];var fielddef_array=window["wfu_attribute_"+attribute+"_typeprops"][0].split(",");var fieldprops_basic=["label","required","donotautocomplete","validate","typehook","labelposition","hintposition","default","data","group","format"];var labelpositions=["none","top","right","bottom",
105
- "left","placeholder"];var hintpositions=["none","inline","top","right","bottom","left"];template=template.replace(/\[\[key\]\]/g,key).replace(/\[\[t\]\]/g,field.type).replace(/\[\[label\]\]/g,field.label).replace(/\[\[s\]\]/g,field.labelposition).replace(/\[\[d\]\]/g,field["default"]).replace(/\[\[l\]\]/g,field.data).replace(/\[\[label_label\]\]/g,fielddef.label_label).replace(/\[\[data_label\]\]/g,fielddef.data_label).replace(/\[\[g\]\]/g,field.group).replace(/\[\[f\]\]/g,field.format).replace(/\[\[p\]\]/g,
106
- field.hintposition);for(var i=0;i<fieldprops_basic.length;i++)template=template.replace(new RegExp("\\[\\["+fieldprops_basic[i]+"_hint\\]\\]","g"),fielddef[fieldprops_basic[i]+"_hint"]);for(var i=0;i<fielddef_array.length;i++)template=template.replace("[[type_"+fielddef_array[i]+"_selected]]",fielddef_array[i]==field.type?' selected="selected"':"");for(var i=0;i<labelpositions.length;i++)template=template.replace("[[labelposition_"+labelpositions[i]+"_selected]]",labelpositions[i]==field.labelposition?
107
- ' selected="selected"':"");for(var i=0;i<hintpositions.length;i++)template=template.replace("[[hintposition_"+hintpositions[i]+"_selected]]",hintpositions[i]==field.hintposition?' selected="selected"':"");template=template.replace("[[remove_disabled]]","");template=template.replace("[[up_disabled]]","");template=template.replace("[[down_disabled]]","");template=field.required?template.replace(/\[\[r\->\]\]|\[\[<\-r\]\]/g,""):template.replace(/\[\[r\->\]\].*\[\[<\-r\]\]/g,"");template=field.donotautocomplete?
108
- template.replace(/\[\[a\->\]\]|\[\[<\-a\]\]/g,""):template.replace(/\[\[a\->\]\].*\[\[<\-a\]\]/g,"");template=field.validate?template.replace(/\[\[v\->\]\]|\[\[<\-v\]\]/g,""):template.replace(/\[\[v\->\]\].*\[\[<\-v\]\]/g,"");template=field.typehook?template.replace(/\[\[h\->\]\]|\[\[<\-h\]\]/g,""):template.replace(/\[\[h\->\]\].*\[\[<\-h\]\]/g,"");template=fielddef.labelposition.substr(0,4)=="show"?template.replace(/\[\[S\->\]\]|\[\[<\-S\]\]/g,""):template.replace(/\[\[S\->\]\][^]*\[\[<\-S\]\]/g,
109
- "");template=fielddef.required.substr(0,4)=="show"?template.replace(/\[\[R\->\]\]|\[\[<\-R\]\]/g,""):template.replace(/\[\[R\->\]\][^]*\[\[<\-R\]\]/g,"");template=fielddef.donotautocomplete.substr(0,4)=="show"?template.replace(/\[\[A\->\]\]|\[\[<\-A\]\]/g,""):template.replace(/\[\[A\->\]\][^]*\[\[<\-A\]\]/g,"");template=fielddef.validate.substr(0,4)=="show"?template.replace(/\[\[V\->\]\]|\[\[<\-V\]\]/g,""):template.replace(/\[\[V\->\]\][^]*\[\[<\-V\]\]/g,"");template=fielddef.hintposition.substr(0,
110
- 4)=="show"?template.replace(/\[\[P\->\]\]|\[\[<\-P\]\]/g,""):template.replace(/\[\[P\->\]\][^]*\[\[<\-P\]\]/g,"");template=fielddef.typehook.substr(0,4)=="show"?template.replace(/\[\[H\->\]\]|\[\[<\-H\]\]/g,""):template.replace(/\[\[H\->\]\][^]*\[\[<\-H\]\]/g,"");template=fielddef["default"].substr(0,4)=="show"?template.replace(/\[\[D\->\]\]|\[\[<\-D\]\]/g,""):template.replace(/\[\[D\->\]\][^]*\[\[<\-D\]\]/g,"");template=fielddef.data.substr(0,4)=="show"?template.replace(/\[\[L\->\]\]|\[\[<\-L\]\]/g,
111
- ""):template.replace(/\[\[L\->\]\][^]*\[\[<\-L\]\]/g,"");template=fielddef.group.substr(0,4)=="show"?template.replace(/\[\[G\->\]\]|\[\[<\-G\]\]/g,""):template.replace(/\[\[G\->\]\][^]*\[\[<\-G\]\]/g,"");template=fielddef.format.substr(0,4)=="show"?template.replace(/\[\[F\->\]\]|\[\[<\-F\]\]/g,""):template.replace(/\[\[F\->\]\][^]*\[\[<\-F\]\]/g,"");return template}
112
- function wfu_userdata_remove_field(obj){var line=obj.parentNode;var container=line.parentNode;var first=null;for(var i=0;i<container.childNodes.length;i++)if(container.childNodes[i].nodeType===1){first=container.childNodes[i];break}if(line!=first){line.parentNode.removeChild(line);for(var i=0;i<first.childNodes.length;i++)if(first.childNodes[i].nodeType===1){wfu_update_userfield_value({target:first.childNodes[i]});break}}}
113
- function wfu_formdata_remove_field(key){var key_parts=key.split("_");var attribute=key_parts[0];var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");if(containers.length<2)return;var container=document.getElementById("wfu_attribute_"+attribute);var line_container=document.getElementById("wfu_formfield_"+key+"_container");var line_container_index=0;for(var i=0;i<containers.length;i++)if(containers[i]==line_container){line_container_index=i+1;break}container.removeChild(line_container);
114
- containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");if(line_container_index>containers.length)line_container_index=containers.length;line_container=containers[line_container_index-1];var prev_key=line_container.id.replace(/^wfu_formfield_/,"").replace(/_container$/,"");wfu_formdata_update_buttons(prev_key);wfu_update_formfield_value({target:line_container})}
115
- function wfu_formdata_move_field(key,direction){var key_parts=key.split("_");var attribute=key_parts[0];var all_attributes=document.querySelector("div#wfu_attribute_"+attribute+" .wfu_formdata_all_attributes").value.split(",");var attr_occur_index=all_attributes.indexOf(attribute)+1;var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");var container=document.getElementById("wfu_attribute_"+attribute);var line_container=document.getElementById("wfu_formfield_"+
116
- key+"_container");var line_container_index=0;for(var i=0;i<containers.length;i++)if(containers[i]==line_container){line_container_index=i+1;break}if(direction=="up"&&attr_occur_index==1&&line_container_index==1||direction=="down"&&attr_occur_index==all_attributes.length&&line_container_index==containers.length)return;var field=wfu_formdata_get_field_props(key);var other_attribute=attribute;var other_line_container=line_container;if(direction=="up")if(line_container_index>1)other_line_container=containers[line_container_index-
117
- 2];else{other_attribute=all_attributes[attr_occur_index-2];var other_containers=document.querySelectorAll("div#wfu_attribute_"+other_attribute+" .wfu_formdata_line_container");other_line_container=other_containers[other_containers.length-1]}else if(line_container_index<containers.length)other_line_container=containers[line_container_index];else{other_attribute=all_attributes[attr_occur_index];var other_containers=document.querySelectorAll("div#wfu_attribute_"+other_attribute+" .wfu_formdata_line_container");
118
- other_line_container=other_containers[0]}var other_key=other_line_container.id.replace(/^wfu_formfield_/,"").replace(/_container$/,"");if(other_attribute==attribute)if(direction=="up")container.insertBefore(line_container,other_line_container);else container.insertBefore(other_line_container,line_container);else{var other_field=wfu_formdata_get_field_props(other_key);var template=wfu_formdata_prepare_template(other_attribute,field,other_key);other_line_container.innerHTML=template;var formfield_elements=
119
- document.querySelectorAll("div#wfu_formfield_"+other_key+'_container input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],wfu_update_formfield_value);template=wfu_formdata_prepare_template(attribute,other_field,key);line_container.innerHTML=template;formfield_elements=document.querySelectorAll("div#wfu_formfield_"+key+'_container input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],
120
- wfu_update_formfield_value)}wfu_formdata_update_buttons(key);wfu_formdata_update_buttons(other_key);wfu_update_formfield_value({target:line_container});if(other_attribute!=attribute)wfu_update_formfield_value({target:other_line_container})}
121
- function wfu_formdata_update_buttons(key){var key_parts=key.split("_");var attribute=key_parts[0];var all_attributes=document.querySelector("div#wfu_attribute_"+attribute+" .wfu_formdata_all_attributes").value.split(",");var attr_occur_index=all_attributes.indexOf(attribute)+1;var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");var line_container=document.getElementById("wfu_formfield_"+key+"_container");var line_container_index=0;for(var i=0;i<
122
- containers.length;i++)if(containers[i]==line_container){line_container_index=i+1;break}var up_element=document.querySelector("div#wfu_formfield_"+key+"_container .wfu_formdata_action.wfu_formdata_action_up");var down_element=document.querySelector("div#wfu_formfield_"+key+"_container .wfu_formdata_action.wfu_formdata_action_down");var remove_elements=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_action_remove");up_element.className="wfu_formdata_action wfu_formdata_action_up"+
123
- (attr_occur_index==1&&line_container_index==1?" wfu_formdata_action_disabled":"");down_element.className="wfu_formdata_action wfu_formdata_action_down"+(attr_occur_index==all_attributes.length&&line_container_index==containers.length?" wfu_formdata_action_disabled":"");for(var i=0;i<remove_elements.length;i++)remove_elements[i].className="wfu_formdata_action wfu_formdata_action_remove"+(remove_elements.length>1?"":" wfu_formdata_action_disabled")}
124
- function wfu_formdata_update_all_updown_buttons(attribute){var all_attributes=document.querySelector("div#wfu_attribute_"+attribute+" .wfu_formdata_all_attributes").value.split(",");for(var i=0;i<all_attributes.length;i++){var ii=i+1;var containers=document.querySelectorAll("div#wfu_attribute_"+all_attributes[i]+" .wfu_formdata_line_container");for(var j=0;j<containers.length;j++){var jj=j+1;var key=containers[j].id.replace(/^wfu_formfield_/,"").replace(/_container$/,"");var up_element=document.querySelector("div#wfu_formfield_"+
125
- key+"_container .wfu_formdata_action.wfu_formdata_action_up");var down_element=document.querySelector("div#wfu_formfield_"+key+"_container .wfu_formdata_action.wfu_formdata_action_down");up_element.className="wfu_formdata_action wfu_formdata_action_up"+(ii==1&&jj==1?" wfu_formdata_action_disabled":"");down_element.className="wfu_formdata_action wfu_formdata_action_down"+(ii==all_attributes.length&&jj==containers.length?" wfu_formdata_action_disabled":"")}}}
126
- function wfu_generate_shortcode(){var shortcode_tag=document.getElementById("wfu_shortcode_tag").value;var defaults=document.getElementById("wfu_attribute_defaults");var values=document.getElementById("wfu_attribute_values");var item;var attribute="";var value="";var shortcode_full="["+shortcode_tag;var shortcode="";for(var i=0;i<defaults.childNodes.length;i++){item=defaults.childNodes[i];if(item.nodeType===1){attribute=item.id.replace("wfu_attribute_default_","");value=document.getElementById("wfu_attribute_value_"+
127
- attribute).value;if(item.value!=value)shortcode+=" "+attribute+'="'+value+'"'}}shortcode_full+=shortcode+"]";document.getElementById("wfu_shortcode").value=shortcode_full;ShortcodeString=shortcode.substr(1);if(document.getElementById("wfu_update_shortcode"))document.getElementById("wfu_update_shortcode").disabled=wfu_plugin_encode_string(shortcode_full)==document.getElementById("wfu_shortcode_original_enc").value;if(Autosave)wfu_schedule_save_shortcode()}
128
- function wfu_update_text_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");var val=item.value;val=val.replace(/(\r\n|\n|\r)/gm,"%n%");val=val.replace(/"/gm,"%dq%");val=val.replace(/\[/gm,"%brl%");val=val.replace(/\]/gm,"%brr%");if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode()}}
129
- function wfu_update_date_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");var val=item.value;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode()}}
130
- function wfu_update_stringmatch_textvalue(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");attribute=attribute.replace("_matchfield","").replace("_matchvalue","");wfu_update_stringmatch_value(attribute)}
131
- function wfu_update_triplecolor_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");attribute=attribute.replace("_color","");attribute=attribute.replace("_bgcolor","");attribute=attribute.replace("_borcolor","");item=document.getElementById("wfu_attribute_"+attribute+"_color");var val=item.value+","+document.getElementById("wfu_attribute_"+attribute+"_bgcolor").value+","+document.getElementById("wfu_attribute_"+attribute+"_borcolor").value;if(val!==item.oldVal){item.oldVal=
132
- val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode()}}
133
- function wfu_update_dimension_value(e){e=e||window.event;var item=e.target;var attribute=item.name.replace("wfu_dimension_elements_","");var group=document.getElementsByName(item.name);item=group[0];var val="";var dimname="";for(var i=0;i<group.length;i++){dimname=group[i].id.replace("wfu_attribute_"+attribute+"_","");if(val!=""&&group[i].value!="")val+=", ";if(group[i].value!="")val+=dimname+":"+group[i].value}if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=
134
- val;wfu_generate_shortcode()}}function wfu_update_ptext_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");attribute=attribute.substr(2);var singular=document.getElementById("wfu_attribute_s_"+attribute).value;var plural=document.getElementById("wfu_attribute_p_"+attribute).value;var val=singular+"/"+plural;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=val}wfu_generate_shortcode()}
135
- function wfu_update_mchecklist_value(attribute){var value="";var mchecklist=document.getElementById("wfu_attribute_"+attribute);var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");if(checkall.checked){jQuery("#wfu_attribute_"+attribute+" input").prop("disabled",true);jQuery("#wfu_attribute_"+attribute+" input").prop("checked",true);value="all"}else{jQuery("#wfu_attribute_"+attribute+" input").prop("disabled",false);jQuery("#wfu_attribute_"+attribute+" input").each(function(){if(jQuery(this).prop("checked"))value+=
136
- ","+jQuery(this).next().html()});value=value.substr(1)}document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}
137
- function wfu_update_rolelist_value(attribute){var value="";var rolelist=document.getElementById("wfu_attribute_"+attribute);var guests=document.getElementById("wfu_attribute_"+attribute+"_guests");var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");if(checkall.checked){rolelist.disabled=true;value="all"}else{rolelist.disabled=false;var options=rolelist.options;for(var i=0;i<options.length;i++)if(options[i].selected){if(value!="")value+=",";value+=options[i].value}}if(guests.checked){if(value!=
138
- "")value+=",";value+="guests"}document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}
139
- function wfu_update_userlist_value(attribute){var value="";var userlist=document.getElementById("wfu_attribute_"+attribute);var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");var guests=document.getElementById("wfu_attribute_"+attribute+"_guests");var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");if(only_current&&only_current.checked){userlist.disabled=true;checkall.disabled=true;guests.disabled=true;value="current"}else{checkall.disabled=false;guests.disabled=
140
- false;if(checkall.checked){userlist.disabled=true;value="all"}else{userlist.disabled=false;var options=userlist.options;for(var i=0;i<options.length;i++)if(options[i].selected){if(value!="")value+=",";value+=options[i].value}}if(guests.checked){if(value!="")value+=",";value+="guests"}}document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}
141
- function wfu_update_postlist_value(attribute){var value="";var userlist=Array();var checkall=Array();var postlist=document.getElementById("wfu_attribute_"+attribute+"_postlist").value.split(",");for(var i=0;i<postlist.length;i++){userlist.push(document.getElementById("wfu_attribute_"+attribute+"_"+postlist[i]));checkall.push(document.getElementById("wfu_attribute_"+attribute+"_all_"+postlist[i]))}var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");if(only_current&&only_current.checked){for(var i=
142
- 0;i<postlist.length;i++){userlist[i].disabled=true;checkall[i].disabled=true}value="current"}else{var allchecked=true;value="";for(var i=0;i<postlist.length;i++){checkall[i].disabled=false;if(checkall[i].checked){userlist[i].disabled=true;if(value!="")value+=",";value+="all"+postlist[i]}else{userlist[i].disabled=false;allchecked=false;var options=userlist[i].options;for(var j=0;j<options.length;j++)if(options[j].selected){if(value!="")value+=",";value+=options[j].value}}}if(allchecked)value="all"}document.getElementById("wfu_attribute_value_"+
143
- attribute).value=value;wfu_generate_shortcode()}
144
- function wfu_update_bloglist_value(attribute){var value="";var bloglist=document.getElementById("wfu_attribute_"+attribute);var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");if(only_current&&only_current.checked){bloglist.disabled=true;checkall.disabled=true;value="current"}else{checkall.disabled=false;if(checkall.checked){bloglist.disabled=true;value="all"}else{bloglist.disabled=false;var options=
145
- bloglist.options;for(var i=0;i<options.length;i++)if(options[i].selected){if(value!="")value+=",";value+=options[i].value}}}document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}
146
- function wfu_update_stringmatch_value(attribute){var matchfield=document.getElementById("wfu_attribute_"+attribute+"_matchfield").value;var matchcriterion=document.getElementById("wfu_attribute_"+attribute+"_matchcriterion").value;var matchvalue=document.getElementById("wfu_attribute_"+attribute+"_matchvalue").value;matchfield=matchfield.replace(";","");if(matchfield.trim()=="")document.getElementById("wfu_attribute_value_"+attribute).value="";else document.getElementById("wfu_attribute_value_"+attribute).value=
147
- "field:"+matchfield+";criterion:"+matchcriterion+";value:"+matchvalue;wfu_generate_shortcode()}
148
- function wfu_update_userfield_value(e){e=e||window.event;var item=e.target;var line=item.parentNode;var container=line.parentNode;var fieldval="";var fieldreq=false;var val="";for(var i=0;i<container.childNodes.length;i++){line=container.childNodes[i];if(line.tagName==="DIV"){for(var j=0;j<line.childNodes.length;j++)if(line.childNodes[j].tagName=="INPUT")if(line.childNodes[j].type=="text"){fieldval=line.childNodes[j].value;if(i==0)item=line.childNodes[j]}else if(line.childNodes[j].type=="checkbox")fieldreq=
149
- line.childNodes[j].checked;if(val!=""&&fieldval!="")val+="/";if(fieldval!=""&&fieldreq)val+="*";if(fieldval!="")val+=fieldval}}if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_userdatalabel").value=val;wfu_generate_shortcode();wfu_update_formfield_variables()}}
150
- function wfu_update_ftpinfobase_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");var val=item.value;item.freezetool=true;var ftpinfo=wfu_decode_ftpinfo(val);var ftpinfo_username=document.getElementById("ftpinfo_username");var ftpinfo_password=document.getElementById("ftpinfo_password");var ftpinfo_domain=document.getElementById("ftpinfo_domain");var ftpinfo_port=document.getElementById("ftpinfo_port");var ftpinfo_sftp=document.getElementById("ftpinfo_sftp");
151
- if(ftpinfo.error){item.classList.add("ftpinfo_error");ftpinfo_username.classList.add("ftpinfo_error");ftpinfo_password.classList.add("ftpinfo_error");ftpinfo_domain.classList.add("ftpinfo_error");ftpinfo_port.classList.add("ftpinfo_error");ftpinfo_sftp.classList.add("ftpinfo_error")}else{item.classList.remove("ftpinfo_error");ftpinfo_username.classList.remove("ftpinfo_error");ftpinfo_password.classList.remove("ftpinfo_error");ftpinfo_domain.classList.remove("ftpinfo_error");ftpinfo_port.classList.remove("ftpinfo_error");
152
- ftpinfo_sftp.classList.remove("ftpinfo_error")}ftpinfo_username.value=ftpinfo.data.username;ftpinfo_password.value=ftpinfo.data.password;ftpinfo_domain.value=ftpinfo.data.ftpdomain;ftpinfo_port.value=ftpinfo.data.port;ftpinfo_sftp.checked=ftpinfo.data.sftp;item.freezetool=false;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode()}}
153
- function wfu_update_ftpinfotool_value(e){var item=document.querySelector(".ftpinfo_btn").previousElementSibling;if(!item.freezetool){var attribute=item.id.replace("wfu_attribute_","");var ftpinfo_username=document.getElementById("ftpinfo_username").value;var ftpinfo_password=document.getElementById("ftpinfo_password").value;var ftpinfo_domain=document.getElementById("ftpinfo_domain").value;var ftpinfo_port=document.getElementById("ftpinfo_port").value;var ftpinfo_sftp=document.getElementById("ftpinfo_sftp").checked;
154
- if(ftpinfo_sftp)ftpinfo_port="s"+ftpinfo_port;var ftpdata=ftpinfo_username.replace(/:/g,"\\\\:").replace(/@/g,"\\\\@");if(ftpinfo_password!="")ftpdata+=":"+ftpinfo_password.replace(/:/g,"\\\\:").replace(/@/g,"\\\\@");ftpdata+="@"+ftpinfo_domain;if(ftpinfo_port!="")ftpdata+=":"+ftpinfo_port;item.value=ftpdata;wfu_update_ftpinfobase_value({target:item})}}
155
- function wfu_update_formfield_value(e){e=e||window.event;var item=e.target;var attribute=item.id.match(/^wfu_formfield_(.*?)_/)[1];var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");var val="";for(var i=0;i<containers.length;i++){var part="";var ind=containers[i].id.match(/^wfu_formfield_.*?_(.*?)_/)[1];var key=attribute+"_"+ind;var label=document.getElementById("wfu_formfield_"+key+"_label").value;if(label.trim()!=""){part=label.trim();var type=
156
- document.getElementById("wfu_formfield_"+key+"_type").value;var typeprops=window["wfu_attribute_"+attribute+"_typeprops"];part+="|t:"+type;if(typeprops[type].labelposition.substr(0,4)=="show")part+="|s:"+document.getElementById("wfu_formfield_"+key+"_labelposition").value;if(typeprops[type].required.substr(0,4)=="show")part+="|r:"+(document.getElementById("wfu_formfield_"+key+"_required").checked?"1":"0");if(typeprops[type].donotautocomplete.substr(0,4)=="show")part+="|a:"+(document.getElementById("wfu_formfield_"+
157
- key+"_donotautocomplete").checked?"1":"0");if(typeprops[type].validate.substr(0,4)=="show")part+="|v:"+(document.getElementById("wfu_formfield_"+key+"_validate").checked?"1":"0");if(typeprops[type].typehook.substr(0,4)=="show")part+="|h:"+(document.getElementById("wfu_formfield_"+key+"_typehook").checked?"1":"0");if(typeprops[type].hintposition.substr(0,4)=="show")part+="|p:"+document.getElementById("wfu_formfield_"+key+"_hintposition").value;if(typeprops[type]["default"].substr(0,4)=="show")part+=
158
- "|d:"+document.getElementById("wfu_formfield_"+key+"_default").value;if(typeprops[type].data.substr(0,4)=="show")part+="|l:"+document.getElementById("wfu_formfield_"+key+"_data").value;if(typeprops[type].group.substr(0,4)=="show")part+="|g:"+document.getElementById("wfu_formfield_"+key+"_group").value;if(typeprops[type].format.substr(0,4)=="show")part+="|f:"+document.getElementById("wfu_formfield_"+key+"_format").value}if(part!=""){if(val!="")val+="/";val+=part}}if(val!==item.oldVal){item.oldVal=
159
- val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode();wfu_update_formfield_variables()}}
160
- function wfu_update_formfield_variables(){var userdata=document.getElementById("wfu_attribute_value_userdatalabel");if(!userdata)return;var shadows=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_userdata");var selects=document.getElementsByName("wfu_formfield_select");for(var i=0;i<selects.length;i++)selects[i].style.display="none";if(shadows.length==0)return;if(shadows[0].style.display=="block")return;var options_str='<option style="display:none;">%userdataXXX%</option>';var userfields=userdata.value.replace(/\//g,
161
- "[/]").replace(/\(.*\)/,function(m){return m.replace(/\[\/\]/g,"/")}).split("[/]");var ind=2;while(document.getElementById("wfu_attribute_userdatalabel"+ind)){var userfields2=document.getElementById("wfu_attribute_value_userdatalabel"+ind).value.replace(/\//g,"[/]").replace(/\(.*\)/,function(m){return m.replace(/\[\/\]/g,"/")}).split("[/]");userfields=userfields.concat(userfields2);ind++}var field="";var pos=0;ind=1;for(var i=0;i<userfields.length;i++){field=userfields[i];if(field[0]=="*")field=field.substr(1);
162
- pos=field.indexOf("|");if(pos>-1)field=field.substr(0,pos);if(field.trim()!=""){options_str+='<option value="%userdata'+ind+'%">'+ind+": "+field.trim()+"</option>";ind++}}for(var i=0;i<selects.length;i++){selects[i].innerHTML=options_str;selects[i].style.display="inline-block"}}
163
- function wfu_attach_element_handlers(item,handler){var elem_events=["DOMAttrModified","textInput","input","change","keypress","paste","focus","propertychange"];for(var i=0;i<elem_events.length;i++)wfu_addEventHandler(item,elem_events[i],handler)}
164
- function wfu_Attach_Admin_Events(autosave_shortcode){Autosave=autosave_shortcode;wfu_generate_shortcode();wfu_update_formfield_variables();wfu_Attach_Admin_DragDrop_Events();var text_elements=document.getElementsByName("wfu_text_elements");for(var i=0;i<text_elements.length;i++)wfu_attach_element_handlers(text_elements[i],wfu_update_text_value);var ptext_elements=document.getElementsByName("wfu_ptext_elements");for(var i=0;i<ptext_elements.length;i++)wfu_attach_element_handlers(ptext_elements[i],
165
- wfu_update_ptext_value);var stringmatch_elements=document.getElementsByName("wfu_stringmatch_elements");for(var i=0;i<stringmatch_elements.length;i++)wfu_attach_element_handlers(stringmatch_elements[i],wfu_update_stringmatch_textvalue);var triplecolor_elements=document.getElementsByName("wfu_triplecolor_elements");for(var i=0;i<triplecolor_elements.length;i++)wfu_attach_element_handlers(triplecolor_elements[i],wfu_update_triplecolor_value);var dimension_elements=document.getElementsByName("wfu_dimension_elements_widths");
166
- for(var i=0;i<dimension_elements.length;i++)wfu_attach_element_handlers(dimension_elements[i],wfu_update_dimension_value);dimension_elements=document.getElementsByName("wfu_dimension_elements_heights");for(var i=0;i<dimension_elements.length;i++)wfu_attach_element_handlers(dimension_elements[i],wfu_update_dimension_value);var userfield_elements=document.getElementsByName("wfu_userfield_elements");for(var i=0;i<userfield_elements.length;i++)wfu_attach_element_handlers(userfield_elements[i],wfu_update_userfield_value);
167
- var formfield_elements=document.getElementsByName("wfu_formfield_elements");for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],wfu_update_formfield_value);var ftpinfobase_elements=document.getElementsByName("wfu_ftpinfobase_elements");for(var i=0;i<ftpinfobase_elements.length;i++)wfu_attach_element_handlers(ftpinfobase_elements[i],wfu_update_ftpinfobase_value);var ftpinfotool_elements=document.getElementsByName("wfu_ftpinfotool_elements");for(var i=0;i<ftpinfotool_elements.length;i++)wfu_attach_element_handlers(ftpinfotool_elements[i],
168
- wfu_update_ftpinfotool_value);var subfolder_input_elements=document.getElementsByName("wfu_subfolder_tools_input");for(var i=0;i<subfolder_input_elements.length;i++)wfu_attach_element_handlers(subfolder_input_elements[i],wfu_subfolders_input_changed);var wfu_columnprops_elements=document.getElementsByName("wfu_columnprops_elements");for(var i=0;i<wfu_columnprops_elements.length;i++)wfu_attach_element_handlers(wfu_columnprops_elements[i],wfu_columnprops_element_changed);if(document.getElementById("wfu_shortcode_postid").value!=
169
- "")setTimeout(function(){wfu_check_page_obsolescence()},CheckObsolescenceTimeOut);wfu_install_unload_hook()}function wfu_install_unload_hook(){window.onbeforeunload=wfu_unload_hook}function wfu_unload_hook(){if(!wfu_changes_saved())return 1}function wfu_changes_saved(){return wfu_plugin_encode_string(document.getElementById("wfu_shortcode").value)==document.getElementById("wfu_shortcode_original_enc").value}
170
- function wfu_force_save_changes(){document.getElementById("wfu_shortcode").value=wfu_plugin_decode_string(document.getElementById("wfu_shortcode_original_enc").value)}function wfu_insert_variable(obj){var attr=obj.className.replace("wfu_variable wfu_variable_","");var inp=document.getElementById("wfu_attribute_"+attr);var pos=inp.selectionStart;var prevval=inp.value;inp.value=prevval.substr(0,pos)+obj.innerHTML+prevval.substr(pos);wfu_update_text_value({target:inp})}
171
- function wfu_insert_userfield_variable(obj){var attr=obj.className.replace("wfu_variable wfu_variable_","");var inp=document.getElementById("wfu_attribute_"+attr);var pos=inp.selectionStart;var prevval=inp.value;inp.value=prevval.substr(0,pos)+obj.value+prevval.substr(pos);obj.value="%userdataXXX%";wfu_update_text_value({target:inp})}
172
- function wfu_columns_itemclicked(obj,attribute){var select=obj.parentNode;if(select.tagName!="SELECT")return;for(var i=0;i<select.options.length;i++)select.options[i].selected=select.options[i]==obj;wfu_update_column_props(attribute)}
173
- function wfu_columns_buttonaction(attribute,action){var source=document.getElementById("wfu_attribute_"+attribute+"_sourcelist");var target=document.getElementById("wfu_attribute_"+attribute);if(action=="add")for(var i=0;i<source.options.length;i++){if(source.options[i].selected||source.options[i].className=="wfu_columns_item_required"){var found=false;var sou=source.options[i].value.replace(/:.*/,"");for(var j=0;j<target.options.length;j++){var tar=target.options[j].value.replace(/:.*/,"");if(tar==
174
- sou){found=true;break}}if(!found){var parts=source.options[i].value.match(/(.*?):(.*?)\/(.*)/);var item_name=parts[1];var sorttype=item_name=="custom"?"+-"+(parts[2]==""?"s":parts[2]):parts[2]!=""?"-+"+parts[2]:"";var title=parts[3];if(item_name=="custom")item_name="custom1";var opt=document.createElement("OPTION");opt.value=item_name+":"+sorttype+"/"+source.options[i].innerHTML+"/"+title;opt.innerHTML=source.options[i].innerHTML+(title!=""&&title!=source.options[i].innerHTML?" ("+title+")":"");opt.className=
175
- source.options[i].className;opt.onclick=source.options[i].onclick;target.appendChild(opt);target.selectedIndex=target.options.length-1}}}else if(action=="del"){var i=0;while(i<target.options.length)if(target.options[i].selected&&target.options[i].className!="wfu_columns_item_required")target.options.remove(i);else i++}else if(action=="up"||action=="down"){var ind=-1;for(var i=0;i<target.options.length;i++)if(target.options[i].selected&&ind==-1)ind=i;else if(target.options[i].selected&&ind>-1)target.options[i].selected=
176
- false;if(action=="up"&&ind>0)target.insertBefore(target.options[ind],target.options[ind-1]);else if(action=="down"&&ind<target.options.length-1)target.insertBefore(target.options[ind+1],target.options[ind])}wfu_update_column_props(attribute);wfu_update_columns(attribute)}
177
- function wfu_update_column_props(attribute){var target=document.getElementById("wfu_attribute_"+attribute);var props_table=document.getElementById("wfu_attribute_"+attribute+"_columnprops_container");var props_title=document.getElementById("wfu_attribute_"+attribute+"_columnprops_title");var props_title_label=document.getElementById("wfu_attribute_"+attribute+"_columnprops_title_label");var props_id=document.getElementById("wfu_attribute_"+attribute+"_columnprops_id");var props_id_label=document.getElementById("wfu_attribute_"+
178
- attribute+"_columnprops_id_label");var props_sort=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sort");var props_sort_label=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sort_label");var props_sorttype=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sorttype");var props_sorttype_label=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sorttype_label");var index=target.selectedIndex;if(props_sorttype.options[0].value=="")props_sorttype.options.remove(0);
179
- if(index==-1){props_table.className="wfu_columnprops_container wfu_columnprops_container_disabled";props_title.value="";props_title.disabled=true;props_id.value="";props_id.disabled=true;props_sort.checked=false;props_sort.disabled=true;props_sorttype.selectedIndex=-1;props_sorttype.disabled=true}else{var parts=target.options[index].value.match(/(.*?):(.*?)\/(.*?)\/(.*)/);var item_name=parts[1];var fieldid_enabled=item_name.substr(0,6)=="custom";var fieldid_value=fieldid_enabled?item_name.substr(6):
180
- "";var sortable_enabled=parts[2]!="";var sortable=sortable_enabled&&parts[2].substr(1,1)=="+";var sorttype_enabled=sortable&&parts[2].substr(0,1)=="+";var sorttype=sortable?parts[2].substr(2):"";var title=parts[4];props_table.className="wfu_columnprops_container";props_title.value=title;props_title.disabled=false;props_id_label.className=fieldid_enabled?"":"wfu_columnprops_label_disabled";props_id.value=fieldid_value;props_id.disabled=!fieldid_enabled;props_sort_label.className=sortable_enabled?"":
181
- "wfu_columnprops_label_disabled";props_sort.checked=sortable;props_sort.disabled=!sortable_enabled;props_sorttype_label.className=sorttype_enabled?"":"wfu_columnprops_label_disabled";props_sorttype.value=sorttype;props_sorttype.disabled=!sorttype_enabled}}
182
- function wfu_columnprops_element_changed(e){e=e||window.event;var item=e.target;var attribute=item.id.match(/^wfu_attribute_(.*?)_columnprops_/)[1];var target=document.getElementById("wfu_attribute_"+attribute);var props_title=document.getElementById("wfu_attribute_"+attribute+"_columnprops_title");var props_id=document.getElementById("wfu_attribute_"+attribute+"_columnprops_id");var props_sort=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sort");var props_sorttype=document.getElementById("wfu_attribute_"+
183
- attribute+"_columnprops_sorttype");var index=target.selectedIndex;if(index==-1)return;var parts=target.options[index].value.match(/(.*?):(.*?)\/(.*?)\/(.*)/);var item_name=parts[1];var flat_name=item_name.substr(0,6)=="custom"?"custom":item_name;var fieldid_enabled=flat_name=="custom";var fieldid_value=fieldid_enabled?parseInt(props_id.value)>=1?props_id.value:"1":"";var sort=parts[2]!=""?parts[2].substr(0,1)+(props_sort.checked?"+":"-")+(props_sorttype.value!=""?props_sorttype.value:parts[2].substr(2)!=
184
- ""?parts[2].substr(2):"s"):"";var label=parts[3];var title=props_title.value!=""?props_title.value:label;target.options[index].value=flat_name+fieldid_value+":"+sort+"/"+label+"/"+title;target.options[index].innerHTML=label+(title!=label?" ("+title+")":"");wfu_update_column_props(attribute);wfu_update_columns(attribute)}
185
- function wfu_update_columns(attribute){var target=document.getElementById("wfu_attribute_"+attribute);var columns="";for(var i=0;i<target.options.length;i++){var parts=target.options[i].value.match(/(.*?):(.*?)\/(.*?)\/(.*)/);var col=parts[1]+":"+(parts[2].substr(1,1)=="+"?parts[2].substr(2):"")+"/"+parts[4];if(columns!="")columns+=",";columns+=col}document.getElementById("wfu_attribute_value_"+attribute).value=columns;wfu_generate_shortcode()}
186
- function wfu_GetHttpRequestObject(){var xhr=null;try{xhr=new XMLHttpRequest}catch(e$0){try{xhr=new ActiveXObject("Msxml2.XMLHTTP")}catch(e2){try{xhr=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}}}if(xhr==null&&window.createRequest)try{xmlhttp=window.createRequest()}catch(e$1){}return xhr}
187
- function wfu_plugin_encode_string(str){var i=0;var newstr="";var num;var hex="";for(i=0;i<str.length;i++){num=str.charCodeAt(i);if(num>=2048)num=((num&16773120|917504)<<4)+((num&4032|8192)<<2)+(num&63|128);else if(num>=128)num=((num&65472|12288)<<2)+(num&63|128);hex=num.toString(16);if(hex.length==1||hex.length==3||hex.length==5)hex="0"+hex;newstr+=hex}return newstr}
188
- function wfu_plugin_decode_string(str){var i=0;var newstr="";var num,val;while(i<str.length){num=parseInt(str.substr(i,2),16);if(num<128)val=num;else if(num<224)val=((num&31)<<6)+(parseInt(str.substr(i+=2,2),16)&63);else val=((num&15)<<12)+((parseInt(str.substr(i+=2,2),16)&63)<<6)+(parseInt(str.substr(i+=2,2),16)&63);newstr+=String.fromCharCode(val);i+=2}return newstr}
189
- function wfu_decode_array_from_string(str){var arr_str=wfu_plugin_decode_string(str);var arr=null;try{arr=JSON.parse(arr_str)}catch(e){}return arr}function wfu_randomString(len){var chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";var string_length=len;var randomstring="";for(var i=0;i<string_length;i++){var rnum=Math.floor(Math.random()*chars.length);randomstring+=chars.substring(rnum,rnum+1)}return randomstring}
190
- function wfu_schedule_save_shortcode(){var d=new Date;var dt=ShortcodeNextSave-d.getTime();if(ShortcodeTimeOut!=null){clearTimeout(ShortcodeTimeOut);ShortcodeTimeOut=null}if(dt<=0)wfu_save_shortcode();else ShortcodeTimeOut=setTimeout(function(){wfu_save_shortcode()},dt)}function wfu_check_page_obsolescence(){if(PageObsolete||PageUpdating||document.getElementById("wfu_shortcode_postid").value=="")return}
191
- function wfu_save_shortcode(){if(typeof window.fromGutenberg!="undefined"){document.getElementById("wfu_shortcode").value=wfu_plugin_decode_string(document.getElementById("wfu_shortcode_original_enc").value);window.plugin_window.wfu_save_from_editor(window.blockId);return}if(PageObsolete)return;var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;PageUpdating=true;document.getElementById("wfu_update_failed_message").style.display="none";var url=AdminParams.wfu_ajax_url;params=new Array(8);params[0]=
192
- new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_save_shortcode";params[1]=new Array(2);params[1][0]="shortcode";params[1][1]=wfu_plugin_encode_string(ShortcodeString);params[2]=new Array(2);params[2][0]="shortcode_original";params[2][1]=document.getElementById("wfu_shortcode_original_enc").value;params[3]=new Array(2);params[3][0]="post_id";params[3][1]=document.getElementById("wfu_shortcode_postid").value;params[4]=new Array(2);params[4][0]="post_hash";params[4][1]=document.getElementById("wfu_shortcode_posthash").value;
193
- params[5]=new Array(2);params[5][0]="shortcode_position";params[5][1]=document.getElementById("wfu_shortcode_position").value;params[6]=new Array(2);params[6][0]="shortcode_tag";params[6][1]=document.getElementById("wfu_shortcode_tag").value;params[7]=new Array(2);params[7][0]="widget_id";params[7][1]=document.getElementById("wfu_shortcode_widgetid").value;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);var d=new Date;if(Autosave)ShortcodeNextSave=
194
- d.getTime()+5E3;else if(document.getElementById("wfu_update_shortcode"))document.getElementById("wfu_update_shortcode_wait").style.display="inline";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){PageUpdating=false;var start_text="wfu_save_shortcode:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,
195
- pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header=="success"){if(Autosave){document.getElementById("wfu_save_label").innerHTML="saved";document.getElementById("wfu_save_label").className="wfu_save_label";document.getElementById("wfu_save_label").style.opacity=1;wfu_fadeout_element(300);ShortcodeNextSave=d.getTime()+
196
- 1E3;if(ShortcodeTimeOut!=null)wfu_schedule_save_shortcode()}else if(document.getElementById("wfu_update_shortcode")){document.getElementById("wfu_update_shortcode_wait").style.display="none";document.getElementById("wfu_update_shortcode").disabled=true;if(window.plugin_window)window.plugin_window.location.reload(true)}if(document.getElementById("wfu_shortcode_postid").value!=""){var shortcode_tag=document.getElementById("wfu_shortcode_tag").value;document.getElementById("wfu_shortcode_original_enc").value=
197
- wfu_plugin_encode_string("["+shortcode_tag+" "+ShortcodeString+"]");document.getElementById("wfu_shortcode_posthash").value=txt_value;setTimeout(function(){wfu_check_page_obsolescence()},CheckObsolescenceTimeOut)}}else{if(Autosave){document.getElementById("wfu_save_label").innerHTML="not saved";document.getElementById("wfu_save_label").className="wfu_save_label_fail";document.getElementById("wfu_save_label").style.opacity=1;wfu_fadeout_element(300)}if(txt_header=="fail")if(txt_value=="post_modified"){PageObsolete=
198
- true;if(document.getElementById("wfu_update_shortcode"))document.getElementById("wfu_update_shortcode").disabled=true;document.getElementById("wfu_update_rejected_message").style.display="block"}else document.getElementById("wfu_update_failed_message").style.display="block"}}};xhr.send(parameters)}function wfu_adjust_opacity(opacity){document.getElementById("wfu_save_label").style.opacity=opacity}
199
- function wfu_fadeout_element(interval){var reps=20;var op=0;for(var i=0;i<reps;i++){op=1-i/reps;setTimeout('wfu_adjust_opacity("'+op.toString()+'")',i*interval/reps)}setTimeout('wfu_adjust_opacity("0.0")',i*interval/reps)}
200
- function wfu_apply_value(attribute,type,value){if(type=="onoff"){document.getElementById("wfu_attribute_"+attribute).className="wfu_onoff_container_"+(value!="true"?"on":"off");wfu_admin_onoff_clicked(attribute)}else if(type=="text"||type=="ltext"||type=="integer"||type=="float"||type=="mtext"||type=="color"){var item=document.getElementById("wfu_attribute_"+attribute);value=value.replace(/%n%/gm,"\n");value=value.replace(/%dq%/gm,'"');value=value.replace(/%brl%/gm,"[");value=value.replace(/%brr%/gm,
201
- "]");if(type=="color"){var rgb=colourNameToHex(value);if(!rgb)rgb=value;jQuery("#wfu_attribute_"+attribute).wpColorPicker("color",rgb)}item.value=value;wfu_update_text_value({target:item})}else if(type=="date"){var item=document.getElementById("wfu_attribute_"+attribute);item.value=value;wfu_update_date_value({target:item})}else if(type=="placements"){wfu_admin_recreate_placements_panel(value);document.getElementById("wfu_attribute_value_placements").value=value;wfu_generate_shortcode()}else if(type==
202
- "radio"){var radios=document.getElementsByName("wfu_radioattribute_"+attribute);for(var i=0;i<radios.length;i++)radios[i].checked=radios[i].value==value||"*"+radios[i].value==value;wfu_admin_radio_clicked(attribute)}else if(type=="ptext"){value=value.replace(/%n%/gm,"\n");value=value.replace(/%dq%/gm,'"');value=value.replace(/%brl%/gm,"[");value=value.replace(/%brr%/gm,"]");var parts=value.split("/");var singular=parts.length<1?"":parts[0];var plural=parts.length<2?singular:parts[1];var item1=document.getElementById("wfu_attribute_s_"+
203
- attribute);item1.value=singular;var item2=document.getElementById("wfu_attribute_p_"+attribute);item2.value=plural;wfu_update_ptext_value({target:item1});wfu_update_ptext_value({target:item2})}else if(type=="mchecklist"){value=value.toLowerCase();if(value=="all")document.getElementById("wfu_attribute_"+attribute+"_all").checked=true;else{document.getElementById("wfu_attribute_"+attribute+"_all").checked=false;var items=value.split(",");for(var i=0;i<items.length;i++)items[i]=items[i].trim();jQuery("#wfu_attribute_"+
204
- attribute+" input").each(function(){jQuery(this).prop("checked",items.indexOf(jQuery(this).next().html())>-1)})}wfu_update_mchecklist_value(attribute)}else if(type=="rolelist"){var item=document.getElementById("wfu_attribute_"+attribute);var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");var default_administrator=checkall.className.indexOf("wfu_default_administrator")>-1;var roles=value.split(",");if(roles.indexOf("all")>-1){checkall.checked=true;for(var i=0;i<item.options.length;i++)item.options[i].selected=
205
- default_administrator&&item.options[i].value=="administrator"}else{checkall.checked=false;for(var i=0;i<roles.length;i++)roles[i]=roles[i].trim();for(var i=0;i<item.options.length;i++)item.options[i].selected=roles.indexOf(item.options[i].value)>-1}document.getElementById("wfu_attribute_"+attribute+"_guests").checked=roles.indexOf("guests")>-1;wfu_update_rolelist_value(attribute)}else if(type=="userlist"){var item=document.getElementById("wfu_attribute_"+attribute);var checkall=document.getElementById("wfu_attribute_"+
206
- attribute+"_all");var default_0=checkall.className.indexOf("wfu_default_0")>-1;var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");if(only_current&&value=="current"){only_current.checked=true;checkall.checked=false;document.getElementById("wfu_attribute_"+attribute+"_guests").checked=false;for(var i=0;i<item.options.length;i++)item.options[i].selected=default_0&&i<1}else{if(only_current)only_current.checked=false;var users=value.split(",");if(users.indexOf("all")>-1){checkall.checked=
207
- true;for(var i=0;i<item.options.length;i++)item.options[i].selected=default_0&&i<1}else{checkall.checked=false;for(var i=0;i<users.length;i++)users[i]=users[i].trim();for(var i=0;i<item.options.length;i++)item.options[i].selected=users.indexOf(item.options[i].value)>-1}document.getElementById("wfu_attribute_"+attribute+"_guests").checked=users.indexOf("guests")>-1}wfu_update_userlist_value(attribute)}else if(type=="postlist"){var userlist=Array();var checkall=Array();var postlist=document.getElementById("wfu_attribute_"+
208
- attribute+"_postlist").value.split(",");for(var i=0;i<postlist.length;i++){userlist.push(document.getElementById("wfu_attribute_"+attribute+"_"+postlist[i]));checkall.push(document.getElementById("wfu_attribute_"+attribute+"_all_"+postlist[i]))}var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");if(only_current&&value=="current"){only_current.checked=true;for(var i=0;i<postlist.length;i++){checkall[i].checked=false;for(var j=0;j<userlist[i].options.length;j++)userlist[i].options[j].selected=
209
- false}}else{if(only_current)only_current.checked=false;var ids=value.split(",");for(var i=0;i<postlist.length;i++){if(value=="all"||ids.indexOf("all"+postlist[i])>-1)checkall[i].checked=true;for(var j=0;j<userlist[i].options.length;j++)userlist[i].options[j].selected=ids.indexOf(userlist[i].options[j].value)>-1}}wfu_update_postlist_value(attribute)}else if(type=="bloglist"){var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");if(only_current&&value=="current"){only_current.checked=
210
- true;document.getElementById("wfu_attribute_"+attribute+"_all").checked=false;var item=document.getElementById("wfu_attribute_"+attribute);for(var i=0;i<item.options.length;i++)item.options[i].selected=false}else{if(only_current)only_current.checked=false;var blogs=value.split(",");if(value=="all")document.getElementById("wfu_attribute_"+attribute+"_all").checked=true;else{document.getElementById("wfu_attribute_"+attribute+"_all").checked=false;for(var i=0;i<blogs.length;i++)blogs[i]=blogs[i].trim();
211
- var item=document.getElementById("wfu_attribute_"+attribute);for(var i=0;i<item.options.length;i++)item.options[i].selected=blogs.indexOf(item.options[i].value)>-1}}wfu_update_bloglist_value(attribute)}else if(type=="stringmatch"){var matchfield="";var matchcriterion="equal to";var matchvalue="";var matches=value.match(/^field:(.*?);\s*criterion:(.*?)\s*;\s*value:(.*)$/);if(matches&&matches.length==4){matchfield=matches[1];matchcriterion=matches[2];matchvalue=matches[3]}document.getElementById("wfu_attribute_"+
212
- attribute+"_matchfield").value=matchfield;document.getElementById("wfu_attribute_"+attribute+"_matchcriterion").value=matchcriterion;document.getElementById("wfu_attribute_"+attribute+"_matchvalue").value=matchvalue;wfu_update_stringmatch_value(attribute)}else if(type=="columns"){var source=document.getElementById("wfu_attribute_"+attribute+"_sourcelist");var target=document.getElementById("wfu_attribute_"+attribute);target.innerHTML="";var columns_flat=value.replace(/(:|\/).*?(,|$)/g,"$2").split(",");
213
- for(var i=0;i<source.options.length;i++){var parts=source.options[i].value.match(/(.*?):(.*?)\/(.*)/);var item_name=parts[1];if(source.options[i].className=="wfu_columns_item_required"&&columns_flat.indexOf(item_name)==-1){var sorttype=item_name=="custom"?"+-"+(parts[2]==""?"s":parts[2]):parts[2]!=""?"-+"+parts[2]:"";var title=parts[3];if(item_name=="custom")item_name="custom1";var opt=document.createElement("OPTION");opt.value=item_name+":"+sorttype+"/"+source.options[i].innerHTML+"/"+title;opt.innerHTML=
214
- source.options[i].innerHTML+(title!=""&&title!=source.options[i].innerHTML?" ("+title+")":"");opt.className=source.options[i].className;opt.onclick=source.options[i].onclick;target.appendChild(opt)}}var columns=value.split(",");for(var i=0;i<columns.length;i++){var item_parts=columns[i].split("/",2);var item_name=item_parts[0];var item_title="";if(item_parts.length>1)item_title=item_parts[1];item_parts=item_name.split(":",2);item_name=item_parts[0];var flat_name=item_name.replace(/custom[0-9]+$/,
215
- "custom");var ind=-1;for(var j=0;j<source.options.length;j++){var sou=source.options[j].value.replace(/:.*/,"");if(sou==flat_name){ind=j;break}}var already_exists=false;for(var j=0;j<target.options.length;j++){var tar=target.options[j].value.replace(/:.*/,"");if(tar==item_name){already_exists=true;break}}if(item_name!="custom"&&ind>-1&&!already_exists){var parts=source.options[ind].value.match(/(.*?):(.*?)\/(.*)/);var sortable=flat_name=="custom"||parts[2]!="";var sorttype=parts[2];var label=source.options[ind].innerHTML;
216
- var title=parts[3];var item_sort="";if(item_parts.length==1)item_sort=flat_name=="custom"?"+-s":sortable?"-+"+sorttype:"";else if(flat_name=="custom")item_sort="+"+(item_parts[1]==""?"-s":"+"+item_parts[1]);else item_sort=sortable?"-"+(item_parts[1]==""?"-":"+")+sorttype:"";if(item_title=="")item_title=title;var opt=document.createElement("OPTION");opt.value=item_name+":"+item_sort+"/"+label+"/"+item_title;opt.innerHTML=label+(title!=label?" ("+title+")":"");opt.className=source.options[ind].className;
217
- opt.onclick=source.options[i].onclick;target.appendChild(opt)}}wfu_update_column_props(attribute);wfu_update_columns(attribute)}else if(type=="dimensions"){var dims=value.split(",");var details,nam,val,item;var group=document.getElementsByName("wfu_dimension_elements_"+attribute);for(var i=0;i<group.length;i++)group[i].value="";for(var i=0;i<dims.length;i++){details=dims[i].split(":",2);nam=details.length<1?"":details[0];val=details.length<2?nam:details[1];item=document.getElementById("wfu_attribute_"+
218
- attribute+"_"+nam.trim());if(item)item.value=val.trim()}item=group[0];wfu_update_dimension_value({target:item})}else if(type=="userfields"){var fields_arr=value.replace(/\//g,"[/]").replace(/\(.*\)/,function(m){return m.replace(/\[\/\]/g,"/")}).split("[/]");var is_req;var fields=Array();for(var i=0;i<fields_arr.length;i++){is_req=fields_arr[i].substr(0,1)=="*";if(is_req)fields_arr[i]=fields_arr[i].substr(1);if(fields_arr[i]!="")fields.push({name:fields_arr[i],required:is_req})}var container=document.getElementById("wfu_attribute_"+
219
- attribute);var first=null;var remove_array=Array();for(var i=0;i<container.childNodes.length;i++)if(container.childNodes[i].nodeType===1)if(first==null)first=container.childNodes[i];else remove_array.push(container.childNodes[i]);for(var i=0;i<remove_array.length;i++)container.removeChild(remove_array[i]);wfu_userdata_edit_field(first,"",false);var newline;var prevline=first;for(var i=0;i<fields.length;i++)if(i==0)wfu_userdata_edit_field(first,fields[i].name,fields[i].required);else{newline=prevline.cloneNode(true);
220
- wfu_userdata_edit_field(newline,fields[i].name,fields[i].required);container.insertBefore(newline,prevline.nextSibling);prevline=newline}var item;for(var i=0;i<first.childNodes.length;i++){item=first.childNodes[i];if(item.tagName=="INPUT")break}wfu_update_userfield_value({target:item})}else if(type=="formfields"){var fields=Array();var fielddefs=window["wfu_attribute_"+attribute+"_typeprops"];var fielddef_array=fielddefs[0].split(",");var defaults={};for(var i=0;i<fielddef_array.length;i++){var fielddef=
221
- fielddefs[fielddef_array[i]];var def={};def.type=fielddef_array[i];def.label=fielddef.label;def.labelposition=fielddef.labelposition.substr(5);def.required=fielddef.required.substr(5)=="true";def.donotautocomplete=fielddef.donotautocomplete.substr(5)=="true";def.validate=fielddef.validate.substr(5)=="true";def.typehook=fielddef.typehook.substr(5)=="true";def.hintposition=fielddef.hintposition.substr(5);def["default"]=fielddef["default"].substr(5);def.data=fielddef.data.substr(5);def.group=fielddef.group.substr(5);
222
- def.format=fielddef.format.substr(5);defaults[fielddef_array[i]]=def}var fields_arr=value.replace(/\//g,"[/]").replace(/\(.*\)/,function(m){return m.replace(/\[\/\]/g,"/")}).split("[/]");for(var i=0;i<fields_arr.length;i++){var field_raw=fields_arr[i].trim();var fieldprops={};for(prop in defaults["text"])fieldprops[prop]=defaults["text"][prop];if(field_raw.substr(0,1)=="*"){fieldprops.required=true;field_raw=field_raw.substr(1)}var field_parts=field_raw.split("|");if(field_parts[0].trim()!=""){var type_key=
223
- -1;var new_type="";for(var j=0;j<field_parts.length;j++){var part=field_parts[j].replace(/^\s+/gm,"");var flag=part.substr(0,2);var val=part.substr(2);if(flag=="t:"&&j>0&&fielddef_array.indexOf(val)>-1){new_type=val;type_key=j;break}}if(new_type!=""){for(prop in defaults[new_type])fieldprops[prop]=defaults[new_type][prop];field_parts.splice(type_key,1)}fieldprops.label=field_parts[0].trim();field_parts.splice(0,1);for(var j=0;j<field_parts.length;j++){var part=field_parts[j].replace(/^\s+/gm,"");
224
- var flag=part.substr(0,2);var val=part.substr(2);if(flag=="s:")fieldprops.labelposition=val;else if(flag=="r:")fieldprops.required=val=="1";else if(flag=="a:")fieldprops.donotautocomplete=val=="1";else if(flag=="v:")fieldprops.validate=val=="1";else if(flag=="d:")fieldprops["default"]=val;else if(flag=="l:")fieldprops.data=val;else if(flag=="g:")fieldprops.group=val;else if(flag=="f:")fieldprops.format=val;else if(flag=="p:")fieldprops.hintposition=val;else if(flag=="h:")fieldprops.typehook=val==
225
- "1"}fields.push(fieldprops)}}if(fields.length==0)fields.push(fieldprops_default);var container=document.getElementById("wfu_attribute_"+attribute);var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");for(var i=1;i<containers.length;i++)container.removeChild(containers[i]);var new_line_container=containers[0];for(var i=0;i<fields.length;i++){var new_key=attribute+"_"+wfu_randomString(4);var template=wfu_formdata_prepare_template(attribute,fields[i],
226
- new_key);if(i>0)new_line_container=document.createElement("DIV");new_line_container.id="wfu_formfield_"+new_key+"_container";new_line_container.className="wfu_formdata_line_container";if(i>0)container.insertBefore(new_line_container,null);new_line_container.innerHTML=template;wfu_formdata_update_buttons(new_key)}var formfield_elements=document.querySelectorAll("div#wfu_attribute_"+attribute+' input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],
227
- wfu_update_formfield_value);wfu_update_formfield_value({target:containers[0]})}else if(type=="color-triplet"){var colors=value.split(",");for(var i=0;i<colors.length;i++)colors[i]=colors[i].trim();if(colors.length==2)colors=[colors[0],colors[1],"#000000"];else if(colors.length==1)colors=[colors[0],"#FFFFFF","#000000"];else if(colors.length<3)colors=["#000000","#FFFFFF","#000000"];var rgb=colourNameToHex(colors[0]);if(!rgb)rgb=colors[0];jQuery("#wfu_attribute_"+attribute+"_color").wpColorPicker("color",
228
- rgb);var item=document.getElementById("wfu_attribute_"+attribute+"_color");item.value=colors[0];rgb=colourNameToHex(colors[1]);if(!rgb)rgb=colors[1];jQuery("#wfu_attribute_"+attribute+"_bgcolor").wpColorPicker("color",rgb);document.getElementById("wfu_attribute_"+attribute+"_bgcolor").value=colors[1];rgb=colourNameToHex(colors[2]);if(!rgb)rgb=colors[2];jQuery("#wfu_attribute_"+attribute+"_borcolor").wpColorPicker("color",rgb);document.getElementById("wfu_attribute_"+attribute+"_borcolor").value=colors[2];
229
- wfu_update_triplecolor_value({target:item})}else if(type=="ftpinfo"){var item=document.getElementById("wfu_attribute_"+attribute);item.value=value;wfu_update_text_value({target:item})}else if(type=="folderlist"){var items=wfu_parse_folderlist_js(value);var opts=document.getElementById("wfu_attribute_"+attribute).options;while(opts.length>0)opts.remove(0);var opt,subfolder,subfolder_raw,text,stars,subvalue;for(var i=0;i<items.path.length;i++){subfolder=items.path[i];if(subfolder.substr(subfolder.length,
230
- 1)=="/")subfolder=subfolder.substr(0,subfolder.length-1);subfolder_raw=subfolder.split("/");subfolder=subfolder_raw[subfolder_raw.length-1];stars=parseInt(items.level[i]);text="";subvalue="";for(var j=0;j<stars;j++){text+="&nbsp;&nbsp;&nbsp;";subvalue+="*"}text+=items.label[i];if(items["default"][i])subvalue+="&";if(subfolder=="")subvalue+="{root}/"+items.label[i];else subvalue+=subfolder+items.label[i];opt=document.createElement("option");if(items["default"][i])opt.className="wfu_select_folders_option_default";
231
- else opt.className="";opt.value=wfu_plugin_encode_string(subvalue);opt.innerHTML=text;opts.add(opt)}opt=document.createElement("option");opt.value="";opt.innerHTML="";opts.add(opt);var list=document.getElementById("wfu_attribute_"+attribute);list.data=wfu_decode_subfolder_list(attribute);wfu_subfolders_update_toolnav(attribute);item=list;if(value!==item.oldVal){item.oldVal=value;document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}}}
232
- function wfu_decode_ftpinfo(ftpdata){var ret={error:true,data:{username:"",password:"",ftpdomain:"",port:"",sftp:false}};var ftpdata_flat=ftpdata.replace(/\\\\:/g,"\\\\_").replace(/\\\\@/g,"\\\\_");var pos1=ftpdata_flat.indexOf(":");var pos2=ftpdata_flat.indexOf("@");if(pos1>-1&&pos2>-1&&pos2>pos1){ret.error=false;ret.data.username=ftpdata.substr(0,pos1).replace(/\\\\:/g,":").replace(/\\\\@/g,"@");ret.data.password=ftpdata.substr(pos1+1,pos2-pos1-1).replace(/\\\\:/g,":").replace(/\\\\@/g,"@");var ftp_host=
233
- ftpdata.substr(pos2+1);ret.data.ftpdomain=ftp_host.replace(/:.*/,"");if(ret.data.ftpdomain.trim()=="")ret.error=true;var ftp_port=ftp_host.replace(/^[^:]*:?/,"");if(ftp_port.substr(0,1)=="s"){ret.data.sftp=true;ftp_port=ftp_port.substr(1)}ret.data.port=ftp_port}else if(pos2>-1){ret.error=false;ret.data.username=ftpdata.substr(0,pos2).replace(/\\\\:/g,":").replace(/\\\\@/g,"@");var ftp_host=ftpdata.substr(pos2+1);ret.data.ftpdomain=ftp_host.replace(/:.*/,"");if(ret.data.ftpdomain.trim()=="")ret.error=
234
- true;var ftp_port=ftp_host.replace(/^[^:]*:?/,"");if(ftp_port.substr(0,1)=="s"){ret.data.sftp=true;ftp_port=ftp_port.substr(1)}ret.data.port=ftp_port}else if(pos1>-1){ret.error=true;ret.data.username=ftpdata.substr(0,pos1).replace(/\\\\:/g,":").replace(/\\\\@/g,"@");ret.data.password=ftpdata.substr(pos1+1).replace(/\\\\:/g,":").replace(/\\\\@/g,"@")}else{ret.error=true;ret.data.username=ftpdata.replace(/\\\\:/g,":").replace(/\\\\@/g,"@")}return ret}
235
- function wfu_ftpinfotool_toggle(){var ftpinfobtn=document.querySelector(".ftpinfo_btn");var ftpinfotool=document.querySelector(".ftpinfo_tool");if(ftpinfotool.classList.contains("hidden")){ftpinfobtn.innerHTML="Close";ftpinfotool.classList.remove("hidden")}else{ftpinfobtn.innerHTML="Edit";ftpinfotool.classList.add("hidden")}}
236
- function wfu_parse_folderlist_js(list){var ret=Object();ret.path=Array();ret.label=Array();ret.level=Array();ret["default"]=Array();if(list.substr(0,4)=="auto")return ret;var subfolders=list.split(",");if(subfolders.length==0)return ret;if(subfolders.length==1&&subfolders[0].trim()=="")return ret;var dir_levels=["root"];var prev_level=0;var level0_count=0;var _default=-1;var subfolder,star_count,start_spaces,is_default,subfolder_dir,subfolder_label,subfolder_path;for(var i=0;i<subfolders.length;i++){subfolder=
237
- subfolders[i].trim();star_count=0;start_spaces="";is_default=false;while(star_count<subfolder.length)if(subfolder.substr(star_count,1)=="*"){star_count++;start_spaces+="&nbsp;&nbsp;&nbsp;"}else break;if(star_count-prev_level<=1&&(star_count>0||level0_count==0)){subfolder=subfolder.substr(star_count,subfolder.length-star_count);if(subfolder.substr(0,1)=="&"){subfolder=subfolder.substr(1);is_default=true}subfolder_items=subfolder.split("/");if(subfolder_items.length<2)subfolder_items.push("");if(subfolder_items[1]!=
238
- ""){subfolder_dir=subfolder_items[0];subfolder_label=subfolder_items[1]}else{subfolder_dir=subfolder;subfolder_label=subfolder}if(subfolder_dir!=""){if(is_default&&_default==-1)_default=ret.path.length;else is_default=false;if(star_count==0)level0_count=1;if(dir_levels.length>star_count)dir_levels[star_count]=subfolder_dir;else dir_levels.push(subfolder_dir);subfolder_path="";for(var i_count=1;i_count<=star_count;i_count++)subfolder_path+=dir_levels[i_count]+"/";ret.path.push(subfolder_path);ret.label.push(subfolder_label);
239
- ret.level.push(star_count);ret["default"].push(is_default);prev_level=star_count}}}return ret}
240
- function colourNameToHex(colour){var colours={"aliceblue":"#f0f8ff","antiquewhite":"#faebd7","aqua":"#00ffff","aquamarine":"#7fffd4","azure":"#f0ffff","beige":"#f5f5dc","bisque":"#ffe4c4","black":"#000000","blanchedalmond":"#ffebcd","blue":"#0000ff","blueviolet":"#8a2be2","brown":"#a52a2a","burlywood":"#deb887","cadetblue":"#5f9ea0","chartreuse":"#7fff00","chocolate":"#d2691e","coral":"#ff7f50","cornflowerblue":"#6495ed","cornsilk":"#fff8dc","crimson":"#dc143c","cyan":"#00ffff","darkblue":"#00008b",
241
- "darkcyan":"#008b8b","darkgoldenrod":"#b8860b","darkgray":"#a9a9a9","darkgreen":"#006400","darkkhaki":"#bdb76b","darkmagenta":"#8b008b","darkolivegreen":"#556b2f","darkorange":"#ff8c00","darkorchid":"#9932cc","darkred":"#8b0000","darksalmon":"#e9967a","darkseagreen":"#8fbc8f","darkslateblue":"#483d8b","darkslategray":"#2f4f4f","darkturquoise":"#00ced1","darkviolet":"#9400d3","deeppink":"#ff1493","deepskyblue":"#00bfff","dimgray":"#696969","dodgerblue":"#1e90ff","firebrick":"#b22222","floralwhite":"#fffaf0",
242
- "forestgreen":"#228b22","fuchsia":"#ff00ff","gainsboro":"#dcdcdc","ghostwhite":"#f8f8ff","gold":"#ffd700","goldenrod":"#daa520","gray":"#808080","green":"#008000","greenyellow":"#adff2f","honeydew":"#f0fff0","hotpink":"#ff69b4","indianred ":"#cd5c5c","indigo ":"#4b0082","ivory":"#fffff0","khaki":"#f0e68c","lavender":"#e6e6fa","lavenderblush":"#fff0f5","lawngreen":"#7cfc00","lemonchiffon":"#fffacd","lightblue":"#add8e6","lightcoral":"#f08080","lightcyan":"#e0ffff","lightgoldenrodyellow":"#fafad2",
243
- "lightgrey":"#d3d3d3","lightgreen":"#90ee90","lightpink":"#ffb6c1","lightsalmon":"#ffa07a","lightseagreen":"#20b2aa","lightskyblue":"#87cefa","lightslategray":"#778899","lightsteelblue":"#b0c4de","lightyellow":"#ffffe0","lime":"#00ff00","limegreen":"#32cd32","linen":"#faf0e6","magenta":"#ff00ff","maroon":"#800000","mediumaquamarine":"#66cdaa","mediumblue":"#0000cd","mediumorchid":"#ba55d3","mediumpurple":"#9370d8","mediumseagreen":"#3cb371","mediumslateblue":"#7b68ee","mediumspringgreen":"#00fa9a",
244
- "mediumturquoise":"#48d1cc","mediumvioletred":"#c71585","midnightblue":"#191970","mintcream":"#f5fffa","mistyrose":"#ffe4e1","moccasin":"#ffe4b5","navajowhite":"#ffdead","navy":"#000080","oldlace":"#fdf5e6","olive":"#808000","olivedrab":"#6b8e23","orange":"#ffa500","orangered":"#ff4500","orchid":"#da70d6","palegoldenrod":"#eee8aa","palegreen":"#98fb98","paleturquoise":"#afeeee","palevioletred":"#d87093","papayawhip":"#ffefd5","peachpuff":"#ffdab9","peru":"#cd853f","pink":"#ffc0cb","plum":"#dda0dd",
245
- "powderblue":"#b0e0e6","purple":"#800080","red":"#ff0000","rosybrown":"#bc8f8f","royalblue":"#4169e1","saddlebrown":"#8b4513","salmon":"#fa8072","sandybrown":"#f4a460","seagreen":"#2e8b57","seashell":"#fff5ee","sienna":"#a0522d","silver":"#c0c0c0","skyblue":"#87ceeb","slateblue":"#6a5acd","slategray":"#708090","snow":"#fffafa","springgreen":"#00ff7f","steelblue":"#4682b4","tan":"#d2b48c","teal":"#008080","thistle":"#d8bfd8","tomato":"#ff6347","turquoise":"#40e0d0","violet":"#ee82ee","wheat":"#f5deb3",
246
- "white":"#ffffff","whitesmoke":"#f5f5f5","yellow":"#ffff00","yellowgreen":"#9acd32"};if(typeof colours[colour.toLowerCase()]!="undefined")return colours[colour.toLowerCase()];return false}function wfu_add_cookies(cookies){for(var i=0;i<cookies.length;i++){var date=new Date;date.setTime(date.getTime()+cookies[i].expires*1E3);document.cookie=cookies[i].name+"="+cookies[i].value+"; expires="+date.toUTCString()+"; path=/"}}
247
- function wfu_download_file(filepath_enc,ii){var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var nonce="";var nonce_elem=document.getElementById("wfu_download_file_nonce");if(nonce_elem)nonce=nonce_elem.value;if(nonce=="")return;var url=AdminParams.wfu_ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_download_file_invoker";params[1]=new Array(2);params[1][0]="file";params[1][1]=filepath_enc;params[2]=new Array(2);params[2][0]="nonce";params[2][1]=
248
- nonce;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var start_text="wfu_ajax_action_download_file_invoker:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+
249
- start_text.length,xhr.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header.substr(0,16)=="wfu_download_id;"){var download_id=txt_header.substr(16);var container=document.getElementById("wfu_file_download_container_"+ii);var props=wfu_decode_array_from_string(txt_value);if(props){container.innerHTML=props.html;if(props.js!=""){var script=document.createElement("SCRIPT");script.type=
250
- "text/javascript";script.text=props.js;container.appendChild(script)}setTimeout("wfu_download_file_monitor('"+filepath_enc+"', "+ii+", '"+download_id+"')",100)}}}};xhr.send(parameters)}
251
- function wfu_download_file_monitor(filepath_enc,ii,id){var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_download_file_monitor";params[1]=new Array(2);params[1][0]="file";params[1][1]=filepath_enc;params[2]=new Array(2);params[2][0]="id";params[2][1]=id;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);
252
- xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var start_text="wfu_ajax_action_download_file_monitor:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=
253
- response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header!="repeat"){var container=document.getElementById("wfu_file_download_container_"+ii);container.innerHTML=""}else if(txt_header=="repeat")setTimeout("wfu_download_file_monitor('"+filepath_enc+"', "+ii+", '"+txt_value+"')",100)}};xhr.send(parameters)}
254
- function wfu_filedetails_changed(e){var userdata_elements=document.getElementsByName("wfu_filedetails_userdata");var def,subm;var changed=false,changed2=false;for(var i=0;i<userdata_elements.length;i++){def=document.getElementById(userdata_elements[i].id.replace("wfu_filedetails_userdata_value_","wfu_filedetails_userdata_default_"));subm=document.getElementById(userdata_elements[i].id.replace("wfu_filedetails_userdata_value_","wfu_filedetails_userdata_"));subm.value=userdata_elements[i].value;if(userdata_elements[i].value!=
255
- def.value){changed=true;break}}if(document.getElementById("wfu_filedetails_userid"))changed2=document.getElementById("wfu_filedetails_userid").value!=document.getElementById("wfu_filedetails_userid_default").value;document.getElementById("dp_filedetails_submit_fields").disabled=!changed&&!changed2}
256
- function wfu_Attach_FileDetails_Admin_Events(){var userdata_elements=document.getElementsByName("wfu_filedetails_userdata");for(var i=0;i<userdata_elements.length;i++)wfu_attach_element_handlers(userdata_elements[i],wfu_filedetails_changed)}
257
- function wfu_update_browserpermission_option(type,id,immediate){var users=document.getElementById("wfu_fbperm_users");var roles=document.getElementById("wfu_fbperm_roles");var view=document.getElementById("wfu_fbperm_"+type+"_"+id+"_view");var dl=document.getElementById("wfu_fbperm_"+type+"_"+id+"_dl");var edit=document.getElementById("wfu_fbperm_"+type+"_"+id+"_edit");var del=document.getElementById("wfu_fbperm_"+type+"_"+id+"_del");if(type=="role"){if(id=="0"){dl.checked=view.checked&&dl.checked;
258
- edit.checked=view.checked&&edit.checked;del.checked=view.checked&&del.checked;dl.disabled=!view.checked;edit.disabled=!view.checked;del.disabled=!view.checked;var roles_tr=document.querySelectorAll("tr.wfu_fbperm_role_tr");for(var i=0;i<roles_tr.length;i++){var rolename=roles_tr[i].id.substr(16,roles_tr[i].id.length-20);wfu_update_browserpermission_option("role",rolename,false)}if(immediate){var props=(view.checked?"v":"")+(dl.checked?"d":"")+(edit.checked?"e":"")+(del.checked?"l":"");roles.value=
259
- roles.value.replace(/^0\[\w*\]/,"0["+props+"]")}}else if(id!="administrator"){var row=document.getElementById("wfu_fbperm_role_"+id+"_row");var def=document.getElementById("wfu_fbperm_role_"+id+"_def");var view_def=document.getElementById("wfu_fbperm_role_0_view");var dl_def=document.getElementById("wfu_fbperm_role_0_dl");var edit_def=document.getElementById("wfu_fbperm_role_0_edit");var del_def=document.getElementById("wfu_fbperm_role_0_del");view.checked=def.checked?view_def.checked:view.checked;
260
- row.style.fontWeight=def.checked?"":"bold";dl.checked=def.checked?dl_def.checked:view.checked&&dl.checked;edit.checked=def.checked?edit_def.checked:view.checked&&edit.checked;del.checked=def.checked?del_def.checked:view.checked&&del.checked;view.disabled=def.checked;dl.disabled=def.checked||!view.checked;edit.disabled=def.checked||!view.checked;del.disabled=def.checked||!view.checked;if(immediate){var props=def.checked?"":"D"+(view.checked?"v":"")+(dl.checked?"d":"")+(edit.checked?"e":"")+(del.checked?
261
- "l":"");roles.value=roles.value.replace(new RegExp(","+id+"\\[\\w*\\]"),","+id+"["+props+"]")}}var users_tr=document.querySelectorAll("tr.wfu_fbperm_user_tr");for(var i=0;i<users_tr.length;i++){var username=users_tr[i].id.substr(16,users_tr[i].id.length-20);wfu_update_browserpermission_option("user",username,false)}}else if(type=="user"){var role=document.getElementById("wfu_fbperm_user_"+id+"_role");if(id=="0"){view.checked=role.checked?false:view.checked;dl.checked=role.checked?false:view.checked&&
262
- dl.checked;edit.checked=role.checked?false:view.checked&&edit.checked;del.checked=role.checked?false:view.checked&&del.checked;view.disabled=role.checked;dl.disabled=role.checked||!view.checked;edit.disabled=role.checked||!view.checked;del.disabled=role.checked||!view.checked;view.indeterminate=role.checked;dl.indeterminate=role.checked;edit.indeterminate=role.checked;del.indeterminate=role.checked;var users_tr=document.querySelectorAll("tr.wfu_fbperm_user_tr");for(var i=0;i<users_tr.length;i++){var username=
263
- users_tr[i].id.substr(16,users_tr[i].id.length-20);wfu_update_browserpermission_option("user",username,false)}if(immediate){var props=role.checked?"":"R"+(view.checked?"v":"")+(dl.checked?"d":"")+(edit.checked?"e":"")+(del.checked?"l":"");users.value=users.value.replace(/^0\[\w*\],?/,"");users.value="0["+props+"]"+(users.value==""?"":","+users.value)}}else{var user_roles=document.getElementById("wfu_fbperm_user_"+id+"_roles").value.split(",");if(user_roles.length==1&&user_roles[0]=="")user_roles=
264
- Array();if(user_roles.indexOf("administrator")<0){var row=document.getElementById("wfu_fbperm_user_"+id+"_row");var def=document.getElementById("wfu_fbperm_user_"+id+"_def");var role_def=document.getElementById("wfu_fbperm_user_0_role");var view_def=document.getElementById("wfu_fbperm_user_0_view");var dl_def=document.getElementById("wfu_fbperm_user_0_dl");var edit_def=document.getElementById("wfu_fbperm_user_0_edit");var del_def=document.getElementById("wfu_fbperm_user_0_del");if(user_roles.length>
265
- 0){var $view_from_roles=false;var $dl_from_roles=false;var $edit_from_roles=false;var $del_from_roles=false;for(var i=0;i<user_roles.length;i++){$view_from_roles=$view_from_roles||document.getElementById("wfu_fbperm_role_"+user_roles[i]+"_view").checked;$dl_from_roles=$view_from_roles&&($dl_from_roles||document.getElementById("wfu_fbperm_role_"+user_roles[i]+"_dl").checked);$edit_from_roles=$view_from_roles&&($edit_from_roles||document.getElementById("wfu_fbperm_role_"+user_roles[i]+"_edit").checked);
266
- $del_from_roles=$view_from_roles&&($del_from_roles||document.getElementById("wfu_fbperm_role_"+user_roles[i]+"_del").checked)}}else{var $view_from_roles=document.getElementById("wfu_fbperm_role_0_view");var $dl_from_roles=document.getElementById("wfu_fbperm_role_0_dl");var $edit_from_roles=document.getElementById("wfu_fbperm_role_0_edit");var $del_from_roles=document.getElementById("wfu_fbperm_role_0_del")}row.style.fontWeight=def.checked?"":"bold";role.checked=def.checked?role_def.checked:role.checked;
267
- view.checked=def.checked?role_def.checked?$view_from_roles:view_def.checked:role.checked?$view_from_roles:view.checked;dl.checked=def.checked?role_def.checked?$dl_from_roles:dl_def.checked:role.checked?$dl_from_roles:view.checked&&dl.checked;edit.checked=def.checked?role_def.checked?$edit_from_roles:edit_def.checked:role.checked?$edit_from_roles:view.checked&&edit.checked;del.checked=def.checked?role_def.checked?$del_from_roles:del_def.checked:role.checked?$del_from_roles:view.checked&&del.checked;
268
- role.disabled=def.checked;view.disabled=def.checked||role.checked;dl.disabled=def.checked||role.checked||!view.checked;edit.disabled=def.checked||role.checked||!view.checked;del.disabled=def.checked||role.checked||!view.checked;if(immediate){var props=def.checked?"":"D"+(role.checked?"":"R"+(view.checked?"v":"")+(dl.checked?"d":"")+(edit.checked?"e":"")+(del.checked?"l":""));users.value=users.value.replace(new RegExp(","+id+"\\[\\w*\\]|"+id+"\\[\\w*\\],|"+id+"\\[\\w*\\]"),"");users.value+=(users.value==
269
- ""?"":",")+id+"["+props+"]"}}}}}
270
- function wfu_goto_historylog_page(token,go_to){var sel=document.getElementById("wfu_historylog_pages");var page=sel.selectedIndex+1;var newpage=page;if(go_to=="next")newpage=Math.min(page+1,sel.options.length);else if(go_to=="prev")newpage=Math.max(page-1,1);else if(go_to=="last")newpage=sel.options.length;else if(go_to=="first")newpage=1;else if(go_to=="sel")page=-1;if(newpage==page)return;var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);
271
- params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_get_historylog_page";params[1]=new Array(2);params[1][0]="token";params[1][1]=token;params[2]=new Array(2);params[2][0]="page";params[2][1]=newpage;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);document.getElementById("wfu_historylog_overlay").style.display="block";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
272
- xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){document.getElementById("wfu_historylog_overlay").style.display="none";var start_text="wfu_historylog_page_success:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);if(response!=""){var t=document.getElementById("wfu_historylog_table");t.tBodies[0].innerHTML=
273
- wfu_plugin_decode_string(response);sel.selectedIndex=newpage-1;document.getElementById("wfu_historylog_first_disabled").style.display=newpage==1?"inline":"none";document.getElementById("wfu_historylog_prev_disabled").style.display=newpage==1?"inline":"none";document.getElementById("wfu_historylog_first").style.display=newpage==1?"none":"inline";document.getElementById("wfu_historylog_prev").style.display=newpage==1?"none":"inline";document.getElementById("wfu_historylog_last_disabled").style.display=
274
- newpage==sel.options.length?"inline":"none";document.getElementById("wfu_historylog_next_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_historylog_last").style.display=newpage==sel.options.length?"none":"inline";document.getElementById("wfu_historylog_next").style.display=newpage==sel.options.length?"none":"inline"}}};xhr.send(parameters)}
275
- function wfu_attach_uploadedfiles_events(){function _wfu_hightlight_property(obj){var id=obj.id.replace(/^p_([0-9]+)_[0-9]+$/,"$1");document.querySelector("tr.wfu_row-"+id+" .wfu-remarks-container").innerHTML=wfu_plugin_decode_string(obj.firstChild.value)}function _wfu_unhightlight_property(obj){var id=obj.id.replace(/^p_([0-9]+)_[0-9]+$/,"$1");obj.classList.remove("wfu-clicked");document.querySelector("tr.wfu_row-"+id+" .wfu-remarks-container").innerHTML=""}window.wfu_last_shown_remark=null;var props=
276
- document.querySelectorAll(".wfu-properties:not(.wfu-dashicons-hidden)");for(var i=0;i<props.length;i++)if(typeof props[i].hashover=="undefined"||props[i].hashover!=true){jQuery(props[i]).hover(function(){if(window.wfu_last_shown_remark)_wfu_unhightlight_property(window.wfu_last_shown_remark);_wfu_hightlight_property(this);window.wfu_last_shown_remark=this},function(){if(window.wfu_last_shown_remark)_wfu_unhightlight_property(window.wfu_last_shown_remark);_wfu_unhightlight_property(this);window.wfu_last_shown_remark=
277
- null});jQuery(props[i]).click(function(){if(window.wfu_last_shown_remark)_wfu_unhightlight_property(window.wfu_last_shown_remark);_wfu_hightlight_property(this);this.classList.add("wfu-clicked");window.wfu_last_shown_remark=this});this.hashover=true}}
278
- function wfu_update_uploadedfiles_bubble(count){var bubble_container=document.querySelector("#toplevel_page_wfu_uploaded_files .update-plugins");var bubble_text=document.querySelector("#toplevel_page_wfu_uploaded_files .plugin-count");if(bubble_container&&bubble_text){bubble_container.className="update-plugins count-"+count;var text=count;if(count>99)text="99+";bubble_text.innerHTML=text}}
279
- function wfu_goto_uploadedfiles_page(token,go_to){var sel=document.getElementById("wfu_uploadedfiles_pages");var page=sel.selectedIndex+1;var newpage=page;if(go_to=="next")newpage=Math.min(page+1,sel.options.length);else if(go_to=="prev")newpage=Math.max(page-1,1);else if(go_to=="last")newpage=sel.options.length;else if(go_to=="first")newpage=1;else if(go_to=="sel")page=-1;if(newpage==page)return;var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);
280
- params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_get_uploadedfiles_page";params[1]=new Array(2);params[1][0]="token";params[1][1]=token;params[2]=new Array(2);params[2][0]="page";params[2][1]=newpage;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);document.getElementById("wfu_uploadedfiles_overlay").style.display="block";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
281
- xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){document.getElementById("wfu_uploadedfiles_overlay").style.display="none";var start_text="wfu_uploadedfiles_page_success:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);if(response!=""){var t=document.getElementById("wfu_uploadedfiles_table");
282
- var html=wfu_plugin_decode_string(response);var unread_files_count=0;var unread_files_count_raw=html.match(/wfu_uploadedfiles_unread\[(.*?)\]/);if(unread_files_count_raw&&unread_files_count_raw[1])unread_files_count=parseInt(unread_files_count_raw[1]);if(isNaN(unread_files_count))unread_files_count=0;t.tBodies[0].innerHTML=html;sel.selectedIndex=newpage-1;document.getElementById("wfu_uploadedfiles_first_disabled").style.display=newpage==1?"inline":"none";document.getElementById("wfu_uploadedfiles_prev_disabled").style.display=
283
- newpage==1?"inline":"none";document.getElementById("wfu_uploadedfiles_first").style.display=newpage==1?"none":"inline";document.getElementById("wfu_uploadedfiles_prev").style.display=newpage==1?"none":"inline";document.getElementById("wfu_uploadedfiles_last_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_uploadedfiles_next_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_uploadedfiles_last").style.display=
284
- newpage==sel.options.length?"none":"inline";document.getElementById("wfu_uploadedfiles_next").style.display=newpage==sel.options.length?"none":"inline";wfu_attach_uploadedfiles_events();wfu_update_uploadedfiles_bubble(unread_files_count)}}};xhr.send(parameters)}
285
- function wfu_include_file(filepath_enc,ii){var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var nonce="";var nonce_elem=document.getElementById("wfu_include_file_nonce");if(nonce_elem)nonce=nonce_elem.value;if(nonce=="")return;var url=AdminParams.wfu_ajax_url;params=new Array(2);params[0]=new Array(3);params[0][0]="action";params[0][1]="wfu_ajax_action_include_file";params[1]=new Array(2);params[1][0]="file";params[1][1]=filepath_enc;params[2]=new Array(2);params[2][0]="nonce";params[2][1]=
286
- nonce;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);document.getElementById("wfu_include_file_"+ii+"_a").href="javascript: void(0)";document.getElementById("wfu_include_file_"+ii+"_img").style.display="inline";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4){document.getElementById("wfu_include_file_"+ii+"_img").style.display=
287
- "none";if(xhr.status==200){var start_text="wfu_include_file:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header=="success"){document.getElementById("wfu_file_flat_"+ii).style.display="none";
288
- document.getElementById("wfu_file_link_"+ii).style.display="inline";document.getElementById("wfu_file_can_be_included_actions_"+ii).style.display="none";document.getElementById("wfu_file_is_included_actions_"+ii).style.display="block"}else document.getElementById("wfu_include_file_"+ii+"_a").innerHTML=document.getElementById("wfu_include_file_"+ii+"_inpfail").value}}};xhr.send(parameters)}
289
- function wfu_adminbrowser_select_all_visible_changed(){var status=document.getElementById("wfu_select_all_visible").checked;var selectors=document.querySelectorAll(".wfu_selectors");for(var i=0;i<selectors.length;i++)selectors[i].checked=status}
290
- function wfu_adminbrowser_selector_changed(obj){var selectors_count=document.querySelectorAll(".wfu_selectors").length;var selected_count=document.querySelectorAll(".wfu_selectors:checked").length;var all_visible=document.getElementById("wfu_select_all_visible");all_visible.style.webkitAppearance="";all_visible.style.webkitAppearance="checkbox";all_visible.checked=selected_count>0;all_visible.indeterminate=selected_count>0&&selected_count<selectors_count}
291
- function wfu_apply_bulkaction_select(code){if(typeof window["wfu_apply_"+code+"_bulkselect"]!="undefined")window["wfu_apply_"+code+"_bulkselect"]()}
292
- function wfu_apply_adminbrowser_bulkaction(){var actionselector=document.getElementById("wfu_adminbrowser_bulkactions");if(actionselector.selectedIndex<1)return;var action=actionselector.options[actionselector.selectedIndex].value;var selected=document.querySelectorAll(".wfu_selectors:checked");if(selected.length==0)return;var codes=[];var codes_included=0,codes_not_included=0;for(var i=0;i<selected.length;i++){var file_code=selected[i].className.replace(/.*?wfu_selcode_/,"");if(file_code!=""){var included=
293
- selected[i].className.indexOf("wfu_included")>-1;if(included)codes_included++;else codes_not_included++;if(action=="delete"&&!included||action=="include"&&included)selected[i].checked=false;else codes.push(file_code)}}if(action=="move"&&codes_not_included>0)alert("Notice! Files that were not uploaded using the plugin cannot be moved and have been deselected.");else if(action=="delete"&&codes_not_included>0)alert("Notice! Files that were not uploaded using the plugin cannot be deleted and have been deselected.");
294
- else if(action=="include"&&codes_included>0)alert("Notice! Files already included in the plugin have been deselected.");if(codes.length==0)return;var url=document.getElementById("wfu_adminbrowser_action_url").value;var referer=document.getElementById("wfu_adminbrowser_referer").value;if(action=="move"||action=="delete"||action=="include"){var form=document.createElement("FORM");form.method="POST";form.action=url;form.style.display="none";var field1=document.createElement("INPUT");field1.type="hidden";
295
- field1.name="action";field1.value=action+"_file";form.appendChild(field1);var field2=document.createElement("INPUT");field2.type="hidden";field2.name="file";field2.value="list:"+codes.join();form.appendChild(field2);var field3=document.createElement("INPUT");field3.type="hidden";field3.name="referer";field3.value=referer;form.appendChild(field3);document.body.appendChild(form);form.submit()}}
296
- function wfu_goto_adminbrowser_page(token,go_to){var sel=document.getElementById("wfu_adminbrowser_pages");var page=sel.selectedIndex+1;var newpage=page;if(go_to=="next")newpage=Math.min(page+1,sel.options.length);else if(go_to=="prev")newpage=Math.max(page-1,1);else if(go_to=="last")newpage=sel.options.length;else if(go_to=="first")newpage=1;else if(go_to=="sel")page=-1;if(newpage==page)return;var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(4);
297
- params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_get_adminbrowser_page";params[1]=new Array(2);params[1][0]="code";params[1][1]=document.getElementById("wfu_adminbrowser_code").value;params[2]=new Array(2);params[2][0]="token";params[2][1]=token;params[3]=new Array(2);params[3][0]="page";params[3][1]=newpage;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);document.getElementById("wfu_adminbrowser_overlay").style.display=
298
- "block";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){document.getElementById("wfu_adminbrowser_overlay").style.display="none";var start_text="wfu_adminbrowser_page_success:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-
299
- pos-start_text.length);if(response!=""){response=wfu_plugin_decode_string(response);var t=document.getElementById("wfu_adminbrowser_table");t.tBodies[0].innerHTML=response;document.getElementById("wfu_select_all_visible").checked=false;wfu_adminbrowser_select_all_visible_changed();sel.selectedIndex=newpage-1;document.getElementById("wfu_adminbrowser_first_disabled").style.display=newpage==1?"inline":"none";document.getElementById("wfu_adminbrowser_prev_disabled").style.display=newpage==1?"inline":
300
- "none";document.getElementById("wfu_adminbrowser_first").style.display=newpage==1?"none":"inline";document.getElementById("wfu_adminbrowser_prev").style.display=newpage==1?"none":"inline";document.getElementById("wfu_adminbrowser_last_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_adminbrowser_next_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_adminbrowser_last").style.display=newpage==sel.options.length?
301
- "none":"inline";document.getElementById("wfu_adminbrowser_next").style.display=newpage==sel.options.length?"none":"inline"}}};xhr.send(parameters)}
302
- function wfu_focus_table_on_highlighted_file(tableID){var tr=document.querySelector("#"+tableID+" tr.wfu-highlighted");if(tr){var adminbar=document.getElementById("wpadminbar");if(adminbar)adminbar=jQuery(adminbar).is(":visible")?adminbar:null;jQuery("html, body").animate({scrollTop:jQuery(tr).offset().top-(adminbar?jQuery(adminbar).height():0)+"px"},"fast")}}
303
- function wfu_cleanlog_initialize_elements(){jQuery("#wfu_cleanlog_dateold").datepicker({dateFormat:"yy-mm-dd",beforeShow:function(){wfu_cleanlog_element_handler()},onSelect:function(){wfu_cleanlog_element_handler()},onClose:function(){wfu_cleanlog_element_handler()}});jQuery("#wfu_cleanlog_datefrom").datepicker({dateFormat:"yy-mm-dd",beforeShow:function(){wfu_cleanlog_element_handler()},onSelect:function(){wfu_cleanlog_element_handler()},onClose:function(){wfu_cleanlog_element_handler()}});jQuery("#wfu_cleanlog_dateto").datepicker({dateFormat:"yy-mm-dd",
304
- beforeShow:function(){wfu_cleanlog_element_handler()},onSelect:function(){wfu_cleanlog_element_handler()},onClose:function(){wfu_cleanlog_element_handler()}});wfu_attach_element_handlers(document.getElementById("wfu_cleanlog_periodold"),wfu_cleanlog_element_handler);wfu_attach_element_handlers(document.getElementById("wfu_cleanlog_periodtype"),wfu_cleanlog_element_handler)}function wfu_cleanlog_element_handler(e){document.querySelector(".wfu_cleanlog_error").classList.add("hidden")}
305
- function wfu_cleanlog_period_changed(){var sel=document.getElementById("wfu_cleanlog_period");if(sel.selectedIndex==0){document.querySelector(".wfu_selectdate_container").style.display="block";document.querySelector(".wfu_selectperiod_container").style.display="none";document.querySelector(".wfu_selectdates_container").style.display="none";document.getElementById("wfu_cleanlog_dateold").value="";document.querySelector(".wfu_cleanlog_proceed").classList.remove("disabled")}else if(sel.selectedIndex==
306
- 1){document.querySelector(".wfu_selectdate_container").style.display="none";document.querySelector(".wfu_selectperiod_container").style.display="block";document.querySelector(".wfu_selectdates_container").style.display="none";document.getElementById("wfu_cleanlog_periodold").value="1";document.getElementById("wfu_cleanlog_periodtype").selectedIndex=1;document.querySelector(".wfu_cleanlog_proceed").classList.remove("disabled")}else if(sel.selectedIndex==2){document.querySelector(".wfu_selectdate_container").style.display=
307
- "none";document.querySelector(".wfu_selectperiod_container").style.display="none";document.querySelector(".wfu_selectdates_container").style.display="block";document.getElementById("wfu_cleanlog_datefrom").value="";document.getElementById("wfu_cleanlog_dateto").value="";document.querySelector(".wfu_cleanlog_proceed").classList.remove("disabled")}else if(sel.selectedIndex==3){document.querySelector(".wfu_selectdate_container").style.display="none";document.querySelector(".wfu_selectperiod_container").style.display=
308
- "none";document.querySelector(".wfu_selectdates_container").style.display="none";document.querySelector(".wfu_cleanlog_proceed").classList.remove("disabled")}else{document.querySelector(".wfu_selectdate_container").style.display="none";document.querySelector(".wfu_selectperiod_container").style.display="none";document.querySelector(".wfu_selectdates_container").style.display="none";document.querySelector(".wfu_cleanlog_proceed").classList.add("disabled")}document.querySelector(".wfu_cleanlog_error").classList.add("hidden")}
309
- function wfu_cleanlog_selector_toggle(show){if(show){document.getElementById("wfu_includefiles").checked=false;document.getElementById("wfu_cleanlog_period").selectedIndex=-1;wfu_cleanlog_period_changed();document.querySelector(".wfu_cleanlog_tr").style.display="table-row"}else document.querySelector(".wfu_cleanlog_tr").style.display="none"}
310
- function wfu_cleanlog_selector_validate(){var ret={error:"",param:""};var flag=document.getElementById("wfu_includefiles").checked?"1":"0";var sel=document.getElementById("wfu_cleanlog_period");if(sel.selectedIndex==-1)ret.error="Invalid clean-up period selected";else if(sel.selectedIndex==0){var date=jQuery("#wfu_cleanlog_dateold").datepicker("getDate");if(date==null)ret.error="Invalid or empty date";else{var today=new Date;if(date>today)ret.error="Date must be older than today";else{var timelimit=
311
- jQuery.datepicker.formatDate("yymmdd",date);ret.param="0"+flag+":"+timelimit.toString()}}}else if(sel.selectedIndex==1){var inp=document.getElementById("wfu_cleanlog_periodold");var sel2=document.getElementById("wfu_cleanlog_periodtype");if(parseInt(inp.value)<=0)ret.error="Invalid period";else if(sel2.selectedIndex<0||sel2.selectedIndex>2)ret.error="Invalid period interval";else ret.param="1"+flag+":"+inp.value.toString()+":"+sel2.value.substr(0,1)}else if(sel.selectedIndex==2){var datefrom=jQuery("#wfu_cleanlog_datefrom").datepicker("getDate");
312
- var dateto=jQuery("#wfu_cleanlog_dateto").datepicker("getDate");if(datefrom==null)ret.error="Invalid or empty starting date";else if(dateto==null)ret.error="Invalid or empty ending date";else{var today=new Date;if(datefrom>today)ret.error="Starting date must be older than today";else if(dateto>datefrom)ret.error="Ending date must be older or equal to starting date";else{var fromlimit=jQuery.datepicker.formatDate("yymmdd",datefrom);var tolimit=jQuery.datepicker.formatDate("yymmdd",dateto);ret.param=
313
- "2"+flag+":"+fromlimit.toString()+":"+tolimit.toString()}}}else if(sel.selectedIndex==3)ret.param="3"+flag;return ret}
314
- function wfu_cleanlog_selector_checkproceed(){var ret=wfu_cleanlog_selector_validate();if(ret.error!=""){document.querySelector(".wfu_cleanlog_error").innerHTML=ret.error;document.querySelector(".wfu_cleanlog_error").classList.remove("hidden");return false}document.querySelector(".wfu_cleanlog_error").classList.add("hidden");document.querySelector(".wfu_cleanlog_proceed").href=document.getElementById("wfu_cleanlog_href").value+"&data="+ret.param;return true}
315
- function wfu_initialize_consent_policy(params){wfu_PD_bank.params=params;wfu_adjust_pdops_levels();wfu_adjust_permissions_levels();wfu_adjust_logactions_levels();wfu_attach_pdheaders_events();wfu_attach_pdops_events();wfu_attach_conops_events();wfu_pdops_update(true);wfu_allops_freeze_events=true;wfu_conops_update();wfu_consent_question_optable_recreate();wfu_update_consent_questions();wfu_consent_question_operations_reassign();wfu_update_consent_question_itemprops(0,-1);wfu_permissions_update(true);
316
- wfu_logactions_update(true);wfu_pdusers_update();wfu_allops_freeze_events=false}function wfu_get_consent_policy(){var policy_str=wfu_plugin_decode_string(document.getElementById("wfu_consent_policy").value);var policy=null;try{policy=JSON.parse(policy_str)}catch(e){}return policy}function wfu_get_permissions_policy(){var policy_str=wfu_plugin_decode_string(document.getElementById("wfu_permissions_policy").value);var policy=null;try{policy=JSON.parse(policy_str)}catch(e){}return policy}
317
- function wfu_get_logactions_policy(){var policy_str=wfu_plugin_decode_string(document.getElementById("wfu_logactions_policy").value);var policy=null;try{policy=JSON.parse(policy_str)}catch(e){}return policy}function wfu_get_pd_users(){var pd_users_str=wfu_plugin_decode_string(document.getElementById("wfu_assigned_users").value);var pd_users=null;try{pd_users=JSON.parse(pd_users_str)}catch(e){}return pd_users}
318
- function wfu_set_consent_policy(new_policy){var policy_str=JSON.stringify(new_policy);document.getElementById("wfu_consent_policy").value=wfu_plugin_encode_string(policy_str)}function wfu_set_logactions_policy(new_policy){var policy_str=JSON.stringify(new_policy);document.getElementById("wfu_logactions_policy").value=wfu_plugin_encode_string(policy_str)}
319
- function wfu_set_permissions_policy(new_policy){var policy_str=JSON.stringify(new_policy);document.getElementById("wfu_permissions_policy").value=wfu_plugin_encode_string(policy_str)}
320
- function wfu_adjust_pdops_levels(){function _wfu_force_pdop_update_nested(item){var id=item.ID;if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_force_pdop_update_nested(item.children[j]);else policy.operations[id].Allowed=true}function _wfu_nested_adjust_pdops_levels(item,level){if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_nested_adjust_pdops_levels(item.children[j],level+1);var id=item.ID;if(wfu_PD_bank.allowedstatus[id]==0&&level==wfu_PD_bank.params.oplevels){_wfu_force_pdop_update_nested(item);
321
- wfu_PD_bank.allowedstatus[id]=1;policy_needs_update=true}}wfu_pdops_update(false);var policy=wfu_get_consent_policy();if(policy){console.log(policy);var policy_needs_update=false;for(var i=0;i<policy.structure.length;i++)_wfu_nested_adjust_pdops_levels(policy.structure[i],1);if(policy_needs_update)wfu_set_consent_policy(policy)}}
322
- function wfu_attach_pdheaders_events(){var acc=document.querySelectorAll(".wfu_pdheader_button");var i;for(i=0;i<acc.length;i++)acc[i].addEventListener("click",function(){this.classList.toggle("expanded");var panel=null;if(this.classList.contains("wfu_pdop_header_button"))panel=document.querySelector(".wfu_plugin_operations");else if(this.classList.contains("wfu_conop_header_button"))panel=document.querySelector(".wfu_consent_operations");else if(this.classList.contains("wfu_conquestion_header_button"))panel=
323
- document.querySelector(".wfu_consent_questions");else if(this.classList.contains("wfu_permissions_header_button"))panel=document.querySelector(".wfu_consent_permissions");else if(this.classList.contains("wfu_logactions_header_button"))panel=document.querySelector(".wfu_consent_logactions");else if(this.classList.contains("wfu_pdusers_header_button"))panel=document.querySelector(".wfu_consent_users");if(panel)if(this.classList.contains("expanded"))panel.style.display="block";else panel.style.display=
324
- "none"})}function wfu_attach_pdops_events(){var acc=document.querySelectorAll(".wfu_pdop_button");var i;for(i=0;i<acc.length;i++)acc[i].addEventListener("click",function(){this.classList.toggle("expanded");var panel=this.parentElement.nextElementSibling;if(this.classList.contains("expanded"))panel.style.display="block";else panel.style.display="none"})}
325
- function wfu_attach_conops_events(){var acc=document.querySelectorAll(".wfu_conop_button");var i;for(i=0;i<acc.length;i++)acc[i].addEventListener("click",function(){this.classList.toggle("expanded");var panel=this.parentElement.nextElementSibling;if(this.classList.contains("expanded"))panel.style.display="block";else panel.style.display="none"})}
326
- function wfu_pdop_toggle(obj){if(wfu_allops_freeze_events)return;if(obj.id.indexOf("wfu_pdop_")==-1)return;var id=obj.id.replace("wfu_pdop_","");var policy=wfu_get_consent_policy();if(policy){if(typeof policy.operations[id]=="undefined")return;var prev_status=obj.classList.contains("indeterminate")?0:obj.checked?-1:1;var new_status=obj.classList.contains("indeterminate")?true:obj.checked;if(!obj.indeterminate)obj.classList.remove("indeterminate");if(policy.children_index[id].length>0){var level=1;
327
- var parid=id;while((parid=policy.operations[parid].Parent)>0)level++;if((wfu_PD_bank.params.oplevels<1||level<wfu_PD_bank.params.oplevels)&&!confirm("This will set all children operations to "+(new_status?"allowed":"not allowed")+". Continue?")){wfu_allops_freeze_events=true;wfu_set_checkbox_status(obj,prev_status);wfu_allops_freeze_events=false;return}for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];if(policy.children_index[id2].length==0)policy.operations[id2].Allowed=
328
- new_status}}else policy.operations[id].Allowed=new_status;wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;wfu_pdops_update(true);wfu_conops_update();wfu_update_consent_question_itemprops(0,-1);wfu_consent_question_optable_recreate();wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(0,0);wfu_allops_freeze_events=false}}
329
- function wfu_conop_toggle(obj){if(wfu_allops_freeze_events)return;if(obj.id.indexOf("wfu_conop_")==-1)return;var id=obj.id.replace("wfu_conop_","");var policy=wfu_get_consent_policy();if(policy){if(typeof policy.operations[id]=="undefined")return;var prev_status=obj.classList.contains("indeterminate")?0:obj.checked?-1:1;var new_status=obj.classList.contains("indeterminate")?true:obj.checked;if(!obj.indeterminate)check.classList.remove("indeterminate");if(policy.children_index[id].length>0){var level=
330
- 1;var parid=id;while((parid=policy.operations[parid].Parent)>0)level++;if((wfu_PD_bank.params.oplevels<1||level<wfu_PD_bank.params.oplevels)&&!confirm("This will make all children operations "+(new_status?"require":"not require")+" consent. Continue?")){wfu_allops_freeze_events=true;wfu_set_checkbox_status(obj,prev_status);wfu_allops_freeze_events=false;return}for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];if(policy.children_index[id2].length==0)policy.operations[id2].NeedsConsent=
331
- new_status}}else policy.operations[id].NeedsConsent=new_status;wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;wfu_conops_update();wfu_update_consent_question_itemprops(0,-1);wfu_consent_question_optable_recreate();wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(0,0);wfu_allops_freeze_events=false}}
332
- function wfu_pdops_update(updatehtml){function _wfu_atomic_pdop_update(id){var allowed=policy.operations[id].Allowed;policy.operations[id].allowedstatus={};for(var k=0;k<policy.operations[id].Datatypes.length;k++){var type=policy.operations[id].Datatypes[k];policy.operations[id].allowedstatus[type]=allowed?1:-1}var condition=policy.operations[id].Condition;if(condition=="")policy.operations[id].pdvisible=true;else{var negative=false;if(condition.substr(0,1)=="!"){negative=true;condition=condition.replace("!",
333
- "")}var allowedstatus2=policy.operations[parseInt(condition)].allowedstatus;var enabled=false;for(var type in allowedstatus2)if(allowedstatus2.hasOwnProperty(type))if(allowedstatus2[type]>-1){enabled=true;break}policy.operations[id].pdvisible=negative?!enabled:enabled}}function _wfu_nested_pdops_update(item,level){var id=item.ID;if(item.children.length>0){policy.operations[id].allowedstatus={};policy.operations[id].pdvisible=false;for(var j=0;j<item.children.length;j++){_wfu_nested_pdops_update(item.children[j],
334
- level+1);var id2=item.children[j].ID;if(policy.operations[id2].pdvisible){var allowed=policy.operations[id2].Allowed;for(var type in policy.operations[id2].allowedstatus)if(policy.operations[id2].allowedstatus.hasOwnProperty(type)){var allowedstatus2=policy.operations[id2].allowedstatus[type];if(typeof policy.operations[id].allowedstatus[type]=="undefined")policy.operations[id].allowedstatus[type]=allowedstatus2;else if(policy.operations[id].allowedstatus[type]*allowedstatus2<1)policy.operations[id].allowedstatus[type]=
335
- 0}if(!policy.operations[id].pdvisible)policy.operations[id].pdvisible=policy.operations[id2].pdvisible}}}else _wfu_atomic_pdop_update(id);var allowedstatus=-2;for(var type in policy.operations[id].allowedstatus)if(policy.operations[id].allowedstatus.hasOwnProperty(type)){var allowedstatus2=policy.operations[id].allowedstatus[type];if(allowedstatus==-2)allowedstatus=allowedstatus2;else if(allowedstatus*allowedstatus2<1){allowedstatus=0;break}}if(typeof wfu_PD_bank.allowedstatus=="undefined")wfu_PD_bank.allowedstatus=
336
- {};wfu_PD_bank.allowedstatus[id]=allowedstatus;if(typeof wfu_PD_bank.level=="undefined")wfu_PD_bank.level={};wfu_PD_bank.level[id]=level;if(updatehtml){var check=document.getElementById("wfu_pdop_"+id);wfu_set_checkbox_status(check,allowedstatus);var container=document.getElementById("wfu_pdop_container_"+id);if(container)container.style.display=policy.operations[id].pdvisible&&(wfu_PD_bank.params.oplevels<1||level<=wfu_PD_bank.params.oplevels)?"block":"none"}}var policy=wfu_get_consent_policy();
337
- if(policy){wfu_allops_freeze_events=true;for(var i=0;i<policy.structure.length;i++)_wfu_nested_pdops_update(policy.structure[i],1);wfu_allops_freeze_events=false}}
338
- function wfu_conops_update(){function _wfu_atomic_conop_update(id){policy.operations[id].needsconsentstatus=policy.operations[id].Allowed&&policy.operations[id].NeedsConsent?1:-1;var condition=policy.operations[id].Condition;if(condition=="")policy.operations[id].convisible=true;else{var negative=false;if(condition.substr(0,1)=="!"){negative=true;condition=condition.replace("!","")}var enabled=wfu_PD_bank.allowedstatus[parseInt(condition)]>-1;policy.operations[id].convisible=negative?!enabled:enabled}policy.operations[id].convisible=
339
- policy.operations[id].convisible&&policy.operations[id].Allowed}function _wfu_nested_conops_update(item,level){var id=item.ID;if(item.children.length>0){policy.operations[id].needsconsentstatus=-2;policy.operations[id].convisible=false;for(var j=0;j<item.children.length;j++){_wfu_nested_conops_update(item.children[j],level+1);var id2=item.children[j].ID;if(policy.operations[id2].convisible){var needsconsentstatus2=policy.operations[id2].needsconsentstatus;if(policy.operations[id].needsconsentstatus==
340
- -2)policy.operations[id].needsconsentstatus=needsconsentstatus2;else if(policy.operations[id].needsconsentstatus*needsconsentstatus2<1)policy.operations[id].needsconsentstatus=0;if(!policy.operations[id].convisible)policy.operations[id].convisible=policy.operations[id2].convisible}}}else _wfu_atomic_conop_update(id);if(typeof wfu_PD_bank.visible=="undefined")wfu_PD_bank.visible={};wfu_PD_bank.visible[id]=policy.operations[id].convisible;if(typeof wfu_PD_bank.needsconsentstatus=="undefined")wfu_PD_bank.needsconsentstatus=
341
- {};wfu_PD_bank.needsconsentstatus[id]=policy.operations[id].needsconsentstatus;var check=document.getElementById("wfu_conop_"+id);wfu_set_checkbox_status(check,policy.operations[id].needsconsentstatus);var container=document.getElementById("wfu_conop_container_"+id);if(container)container.style.display=policy.operations[id].convisible&&(wfu_PD_bank.params.oplevels<1||level<=wfu_PD_bank.params.oplevels)?"block":"none"}var policy=wfu_get_consent_policy();if(policy){wfu_allops_freeze_events=true;for(var i=
342
- 0;i<policy.structure.length;i++)_wfu_nested_conops_update(policy.structure[i],1);wfu_allops_freeze_events=false}}
343
- function wfu_update_consent_questions(){var policy=wfu_get_consent_policy();if(policy){var maincontainer=document.getElementById("wfu_conquestions_container");wfu_allops_freeze_events=true;for(var i=0;i<policy.questions.length;i++){var container=wfu_render_consent_question(i);if(container){maincontainer.appendChild(container);wfu_update_consent_question(i,true)}}wfu_update_conquestion_header();wfu_allops_freeze_events=false}}
344
- function wfu_render_consent_question(index){var policy=wfu_get_consent_policy();if(!policy)return null;var question=policy.questions[index];var i=index+1;var container=document.createElement("DIV");container.className="wfu_conquestion_container";container.id="wfu_conquestion_container_"+i;var header=document.createElement("DIV");header.className="wfu_conquestion_header";var headerlabel=document.createElement("LABEL");headerlabel.className="wfu_conquestion_headerlabel";headerlabel.innerHTML="Question "+
345
- i;header.appendChild(headerlabel);var tools=document.createElement("DIV");tools.className="wfu_conquestion_tools";var add_btn=document.getElementById("wfu_conquestion_add").cloneNode(true);add_btn.removeAttribute("id");wfu_addEventHandler(add_btn,"click",wfu_conquestion_tools_handler);var remove_btn=document.getElementById("wfu_conquestion_remove").cloneNode(true);remove_btn.removeAttribute("id");wfu_addEventHandler(remove_btn,"click",wfu_conquestion_tools_handler);var up_btn=document.getElementById("wfu_conquestion_up").cloneNode(true);
346
- up_btn.removeAttribute("id");wfu_addEventHandler(up_btn,"click",wfu_conquestion_tools_handler);var down_btn=document.getElementById("wfu_conquestion_down").cloneNode(true);down_btn.removeAttribute("id");wfu_addEventHandler(down_btn,"click",wfu_conquestion_tools_handler);tools.appendChild(add_btn);tools.appendChild(remove_btn);tools.appendChild(up_btn);tools.appendChild(down_btn);header.appendChild(tools);var subcontainer=document.createElement("DIV");subcontainer.className="wfu_conquestion_subcontainer";
347
- var mainprops=document.createElement("DIV");mainprops.className="wfu_conquestion_mainprops";var mainpropstitle=document.createElement("LABEL");mainpropstitle.className="wfu_conquestion_mainpropstitle";mainpropstitle.innerHTML="Main Properties";var titlelabel=document.createElement("LABEL");titlelabel.className="wfu_conquestion_titlelabel";titlelabel.innerHTML="Title";var titletext=document.createElement("INPUT");titletext.className="wfu_conquestion_titletext";titletext.value=question.title;wfu_attach_element_handlers(titletext,
348
- wfu_conquestion_mainprops_handler);var titlelocationlabel=document.createElement("LABEL");titlelocationlabel.className="wfu_conquestion_titlelocationlabel";titlelocationlabel.innerHTML="Title Location";var titlelocationlist=document.createElement("SELECT");titlelocationlist.className="wfu_conquestion_titlelocationlist";var opt=document.createElement("OPTION");opt.value="top";opt.innerHTML="Top";opt.selected=question.location=="top";titlelocationlist.add(opt);var opt=document.createElement("OPTION");
349
- opt.value="bottom";opt.innerHTML="Bottom";opt.selected=question.location=="bottom";titlelocationlist.add(opt);wfu_addEventHandler(titlelocationlist,"change",wfu_conquestion_mainprops_handler);var matrixlabel=document.createElement("LABEL");matrixlabel.className="wfu_conquestion_matrixlabel";matrixlabel.innerHTML="Number of Items";var matrix_x=document.createElement("INPUT");matrix_x.className="wfu_conquestion_matrix_x";matrix_x.type="number";matrix_x.min=1;var qx=parseInt(question.x);if(qx<=0)qx=
350
- 1;question.x=qx;matrix_x.value=qx;wfu_attach_element_handlers(matrix_x,wfu_conquestion_mainprops_handler);var matrixsep=document.createElement("LABEL");matrixsep.className="wfu_conquestion_matrixsep";matrixsep.innerHTML="x";var matrix_y=document.createElement("INPUT");matrix_y.className="wfu_conquestion_matrix_y";matrix_y.type="number";matrix_y.min=1;var qy=parseInt(question.y);if(qy<=0)qy=1;question.y=qy;matrix_y.value=qy;wfu_attach_element_handlers(matrix_y,wfu_conquestion_mainprops_handler);var groupedlabel=
351
- document.createElement("LABEL");groupedlabel.className="wfu_conquestion_groupedlabel";groupedlabel.innerHTML="Grouped";var groupedbox=document.createElement("INPUT");groupedbox.className="wfu_conquestion_groupedbox";groupedbox.type="checkbox";groupedbox.checked=question.grouped==1;wfu_addEventHandler(groupedbox,"change",wfu_conquestion_mainprops_handler);var typelabel=document.createElement("LABEL");typelabel.className="wfu_conquestion_typelabel";typelabel.innerHTML="Type";var typelist=document.createElement("SELECT");
352
- typelist.className="wfu_conquestion_typelist";var opt=document.createElement("OPTION");opt.value="checkbox";opt.innerHTML="Checkbox";opt.selected=question.type=="checkbox";typelist.add(opt);var opt=document.createElement("OPTION");opt.value="radio";opt.innerHTML="Radio";opt.selected=question.type=="radio";typelist.add(opt);var opt=document.createElement("OPTION");opt.value="prompt";opt.innerHTML="Prompt";opt.selected=question.type=="prompt";typelist.add(opt);wfu_addEventHandler(typelist,"change",
353
- wfu_conquestion_mainprops_handler);mainprops.appendChild(mainpropstitle);mainprops.appendChild(matrixlabel);mainprops.appendChild(matrix_x);mainprops.appendChild(matrixsep);mainprops.appendChild(matrix_y);mainprops.appendChild(titlelabel);mainprops.appendChild(titletext);mainprops.appendChild(titlelocationlabel);mainprops.appendChild(titlelocationlist);mainprops.appendChild(groupedlabel);mainprops.appendChild(groupedbox);mainprops.appendChild(typelabel);mainprops.appendChild(typelist);var itemspreview=
354
- document.createElement("DIV");itemspreview.className="wfu_conquestion_itemspreview";var itemspreviewtitle=document.createElement("LABEL");itemspreviewtitle.className="wfu_conquestion_itemspreviewtitle";itemspreviewtitle.innerHTML="Items";var displayedtitle=document.createElement("LABEL");displayedtitle.className="wfu_conquestion_displayedtitle";displayedtitle.innerHTML=question.title;var itemtable=document.createElement("TABLE");itemtable.className="wfu_conquestion_itemtable";itemspreview.appendChild(itemspreviewtitle);
355
- if(question.location!="bottom")itemspreview.appendChild(displayedtitle);itemspreview.appendChild(itemtable);if(question.location=="bottom")itemspreview.appendChild(displayedtitle);wfu_addEventHandler(itemspreview,"click",wfu_conquestion_itempreviewer_handler);var itemprops=document.createElement("DIV");itemprops.className="wfu_conquestion_itemprops";var itempropstitle=document.createElement("LABEL");itempropstitle.className="wfu_conquestion_itempropstitle";itempropstitle.innerHTML="Item Properties";
356
- var labellabel=document.createElement("LABEL");labellabel.className="wfu_conquestion_labellabel";labellabel.innerHTML="Label";var labeltext=document.createElement("INPUT");labeltext.className="wfu_conquestion_labeltext";labeltext.value="";wfu_attach_element_handlers(labeltext,wfu_conquestion_mainprops_handler);var labellocationlabel=document.createElement("LABEL");labellocationlabel.className="wfu_conquestion_labellocationlabel";labellocationlabel.innerHTML="Label Location";var labellocationlist=
357
- document.createElement("SELECT");labellocationlist.className="wfu_conquestion_labellocationlist";var opt=document.createElement("OPTION");opt.value="top";opt.innerHTML="Top";opt.selected=false;labellocationlist.add(opt);var opt=document.createElement("OPTION");opt.value="left";opt.innerHTML="Left";opt.selected=false;labellocationlist.add(opt);var opt=document.createElement("OPTION");opt.value="right";opt.innerHTML="Right";opt.selected=true;labellocationlist.add(opt);var opt=document.createElement("OPTION");
358
- opt.value="bottom";opt.innerHTML="Bottom";opt.selected=false;labellocationlist.add(opt);wfu_addEventHandler(labellocationlist,"change",wfu_conquestion_mainprops_handler);var preselectedlabel=document.createElement("LABEL");preselectedlabel.className="wfu_conquestion_preselectedlabel";preselectedlabel.innerHTML="Preselected";var preselectedbox=document.createElement("INPUT");preselectedbox.className="wfu_conquestion_preselectedbox";preselectedbox.type="checkbox";preselectedbox.checked=false;wfu_addEventHandler(preselectedbox,
359
- "change",wfu_conquestion_mainprops_handler);var visiblelabel=document.createElement("LABEL");visiblelabel.className="wfu_conquestion_visiblelabel";visiblelabel.innerHTML="Visible";var visiblebox=document.createElement("INPUT");visiblebox.className="wfu_conquestion_visiblebox";visiblebox.type="checkbox";visiblebox.checked=true;wfu_addEventHandler(visiblebox,"change",wfu_conquestion_mainprops_handler);itemprops.appendChild(itempropstitle);itemprops.appendChild(labellabel);itemprops.appendChild(labeltext);
360
- itemprops.appendChild(labellocationlabel);itemprops.appendChild(labellocationlist);itemprops.appendChild(preselectedlabel);itemprops.appendChild(preselectedbox);itemprops.appendChild(visiblelabel);itemprops.appendChild(visiblebox);subcontainer.appendChild(mainprops);subcontainer.appendChild(itemspreview);subcontainer.appendChild(itemprops);container.appendChild(header);container.appendChild(subcontainer);return container}
361
- function wfu_consent_question_action(action,index){var policy=wfu_get_consent_policy();if(!policy)return;var maincontainer=document.getElementById("wfu_conquestions_container");var qcount=document.querySelectorAll(".wfu_conquestion_container").length;if(action=="add"){var question={title:"",location:"top",x:1,y:1,grouped:0,type:"checkbox",items:[{index:1,label:"I agree to allow the plugin to use my personal data",location:"right",preselect:0,visible:true,operations:{}}]};policy.questions.splice(index+
362
- 1,0,question);wfu_set_consent_policy(policy);var container=wfu_render_consent_question(index+1);if(container){for(var j=index+2;j<=qcount;j++)document.getElementById("wfu_conquestion_container_"+j).id="wfu_conquestion_container_"+(j+1);maincontainer.insertBefore(container,document.getElementById("wfu_conquestion_container_"+(index+3)));wfu_update_consent_question(index+1,true);wfu_update_consent_question_itemprops(index+1,-1)}}else if(action=="remove"){if(qcount<=1)return;policy.questions.splice(index,
363
- 1);wfu_set_consent_policy(policy);maincontainer.removeChild(document.getElementById("wfu_conquestion_container_"+(index+1)));for(var j=index+2;j<=qcount;j++)document.getElementById("wfu_conquestion_container_"+j).id="wfu_conquestion_container_"+(j-1)}else if(action=="up"){if(index<=0)return;var tempq=policy.questions[index];policy.questions[index]=policy.questions[index-1];policy.questions[index-1]=tempq;wfu_set_consent_policy(policy);var container1=document.getElementById("wfu_conquestion_container_"+
364
- (index+1));var container2=document.getElementById("wfu_conquestion_container_"+index);container1.id="wfu_conquestion_container_"+index+"_temp";container2.id="wfu_conquestion_container_"+(index+1);container1.id="wfu_conquestion_container_"+index;maincontainer.insertBefore(container1,container2)}else if(action=="down"){if(index>=qcount-1)return;var tempq=policy.questions[index];policy.questions[index]=policy.questions[index+1];policy.questions[index+1]=tempq;wfu_set_consent_policy(policy);var container1=
365
- document.getElementById("wfu_conquestion_container_"+(index+2));var container2=document.getElementById("wfu_conquestion_container_"+(index+1));container1.id="wfu_conquestion_container_"+(index+1)+"_temp";container2.id="wfu_conquestion_container_"+(index+2);container1.id="wfu_conquestion_container_"+(index+1);maincontainer.insertBefore(container1,container2)}}
366
- function wfu_update_consent_question(index,recreate){var policy=wfu_get_consent_policy();if(!policy)return;var question=policy.questions[index];var i=index+1;var itemspreview=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_itemspreview");var itemtable=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_itemtable");var displayedtitle=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_displayedtitle");if(!itemspreview)return;if(recreate){var matrix_x=
367
- document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_matrix_x");var matrix_y=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_matrix_y");var titletext=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_titletext");var titlelocationlist=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_titlelocationlist");var groupedbox=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_groupedbox");
368
- matrix_x.value=question.x;matrix_y.value=question.y;titletext.value=question.title;titlelocationlist.value=question.location;groupedbox.checked=question.grouped==1;matrix_x.disabled=question.type=="prompt";matrix_y.disabled=question.type=="prompt";titletext.disabled=question.type=="prompt";titlelocationlist.disabled=question.type=="prompt";groupedbox.disabled=question.type=="prompt";displayedtitle.style.display=question.type=="prompt"?"none":"block";while(itemtable.rows.length>0)itemtable.deleteRow(0)}var qnum=
369
- question.x*question.y;var qitems=[];for(var j=0;j<qnum;j++)qitems.push({label:"",location:"right",preselect:false,visible:true,operations:{}});for(var j=0;j<question.items.length;j++)if(typeof question.items[j].visible=="undefined")question.items[j].visible=1;for(var j=0;j<question.items.length;j++){var ind=question.items[j].index-1;if(ind>=0&&ind<qnum){qitems[ind].label=question.items[j].label;qitems[ind].location=question.items[j].location;qitems[ind].preselect=question.items[j].preselect==1;qitems[ind].visible=
370
- typeof question.items[j].visible=="undefined"||question.items[j].visible==1;qitems[ind].operations=question.items[j].operations}}var j=0;for(var k=0;k<question.x;k++){var row;if(recreate)row=itemtable.insertRow(k);else row=itemtable.rows[k];for(var l=0;l<question.y;l++){var cell;if(recreate){cell=row.insertCell(l);cell.classList.add("wfu_conquestion_itemcontainer")}else cell=row.cells[l];while(cell.childNodes.length>0)cell.removeChild(cell.childNodes[0]);if(qitems[j].visible)cell.classList.add("wfu_item_visible");
371
- else cell.classList.remove("wfu_item_visible");var itemlabel=document.createElement("LABEL");itemlabel.className="wfu_conquestion_itemlabel";if(qitems[j].label==""){itemlabel.classList.add("wfu_empty_label");itemlabel.innerHTML="{no label}"}else{itemlabel.classList.remove("wfu_empty_label");itemlabel.innerHTML=qitems[j].label}if(question.type=="prompt")cell.appendChild(itemlabel);else{var itembox=document.createElement("INPUT");itembox.className="wfu_conquestion_itembox wfu_frozen";itembox.type=question.type;
372
- itembox.checked=qitems[j].preselect;if(qitems[j].location=="top"){cell.appendChild(itemlabel);cell.appendChild(document.createElement("BR"));cell.appendChild(itembox)}else if(qitems[j].location=="left"){cell.appendChild(itemlabel);cell.appendChild(itembox)}else if(qitems[j].location=="bottom"){cell.appendChild(itembox);cell.appendChild(document.createElement("BR"));cell.appendChild(itemlabel)}else{cell.appendChild(itembox);cell.appendChild(itemlabel)}}j++}}if(question.title==""){displayedtitle.classList.add("wfu_empty_label");
373
- displayedtitle.innerHTML="{no title}"}else{displayedtitle.classList.remove("wfu_empty_label");displayedtitle.innerHTML=question.title}if(question.location!="bottom")itemspreview.insertBefore(displayedtitle,itemtable);else itemspreview.insertBefore(displayedtitle,null)}
374
- function wfu_conquestion_mainprops_handler(e){if(wfu_allops_freeze_events)return;var policy=wfu_get_consent_policy();if(!policy)return;e=e||window.event;var item=par=e.target;while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));var i=parseInt(par.id.replace("wfu_conquestion_container_",""));var index=i-1;var question=policy.questions[index];var recreate=true;var is_mainprop=true;var update_optable=false;if(item.classList.contains("wfu_conquestion_titletext"))question.title=
375
- item.value;else if(item.classList.contains("wfu_conquestion_matrix_x"))question.x=item.value;else if(item.classList.contains("wfu_conquestion_matrix_y"))question.y=item.value;else if(item.classList.contains("wfu_conquestion_titlelocationlist"))question.location=item.value;else if(item.classList.contains("wfu_conquestion_groupedbox")){question.grouped=item.checked?1:0;if(question.grouped==1){var qpreselect_count=0;for(var j=0;j<question.items.length;j++)if(qpreselect_count==1)question.items[j].preselect=
376
- 0;else if(question.items[j].preselect==1)qpreselect_count++}}else if(item.classList.contains("wfu_conquestion_typelist")){question.type=item.value;if(question.type=="prompt"){question.x=1;question.y=1;question.title="";question.location="top";question.grouped=0}}else{var itemcontainers=document.querySelectorAll("#wfu_conquestion_container_"+i+" .wfu_conquestion_itemcontainer.wfu_item_selected");if(itemcontainers.length==0)return;var itemindex=itemcontainers[0].parentNode.rowIndex*itemcontainers[0].parentNode.cells.length+
377
- itemcontainers[0].cellIndex+1;var qitem=null;var qindex=question.items.length;for(var j=0;j<question.items.length;j++)if(question.items[j].index==itemindex){qitem=question.items[j];break}else if(question.items[j].index>itemindex){qindex=j;break}if(!qitem){qitem={index:itemindex,label:"",location:"right",preselect:false,visible:1,operations:{}};question.items.splice(qindex,0,qitem)}if(item.classList.contains("wfu_conquestion_labeltext"))qitem.label=item.value;else if(item.classList.contains("wfu_conquestion_labellocationlist"))qitem.location=
378
- item.value;else if(item.classList.contains("wfu_conquestion_preselectedbox")){if(item.checked&&question.grouped==1)for(var j=0;j<question.items.length;j++)question.items[j].preselect=0;qitem.preselect=item.checked?1:0}else if(item.classList.contains("wfu_conquestion_visiblebox")){qitem.visible=item.checked?1:0;update_optable=true}recreate=false;is_mainprop=false}wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;wfu_update_consent_question(index,recreate);if(is_mainprop){wfu_update_consent_question_itemprops(index,
379
- -1);wfu_consent_question_operations_reassign()}if(update_optable){wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(i,itemindex)}wfu_allops_freeze_events=false}
380
- function wfu_conquestion_itempreviewer_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=par=e.target;var qcount=document.querySelectorAll(".wfu_conquestion_container").length;while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));var i=parseInt(par.id.replace("wfu_conquestion_container_",""));var index=i-1;if(!item.classList.contains("wfu_conquestion_itemcontainer"))item=item.parentNode;var itemindex=-1;if(item.classList.contains("wfu_conquestion_itemcontainer"))itemindex=
381
- item.parentNode.rowIndex*item.parentNode.cells.length+item.cellIndex+1;wfu_allops_freeze_events=true;for(var j=0;j<qcount;j++)wfu_update_consent_question_itemprops(j,-1);wfu_update_consent_question_itemprops(index,itemindex);wfu_allops_freeze_events=false}
382
- function wfu_update_consent_question_itemprops(index,itemindex){var policy=wfu_get_consent_policy();if(!policy)return;var question=policy.questions[index];var i=index+1;var itemcontainers=document.querySelectorAll("#wfu_conquestions_container .wfu_conquestion_itemcontainer");var itemcontainer=null;var contindex=0;var contitemindex=1;for(var j=0;j<itemcontainers.length;j++){itemcontainers[j].classList.remove("wfu_item_selected");var par=itemcontainers[j];while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));
383
- if(parseInt(par.id.replace("wfu_conquestion_container_",""))>contindex){contindex++;contitemindex=1}if(contindex==i&&contitemindex==itemindex)itemcontainer=itemcontainers[j];contitemindex++}if(itemcontainer)itemcontainer.classList.add("wfu_item_selected");var labeltext=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_labeltext");var labellocationlist=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_labellocationlist");var preselectedbox=document.querySelector("#wfu_conquestion_container_"+
384
- i+" .wfu_conquestion_preselectedbox");var visiblebox=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_visiblebox");var qindex=-1;for(var j=0;j<question.items.length;j++)if(question.items[j].index==itemindex){qindex=j;break}if(qindex<0){labeltext.value="";labeltext.disabled=itemindex<1;labellocationlist.value="right";labellocationlist.disabled=itemindex<1;preselectedbox.checked=false;preselectedbox.disabled=itemindex<1;visiblebox.checked=true;visiblebox.disabled=itemindex<
385
- 1}else{labeltext.disabled=false;labeltext.value=question.items[qindex].label;labellocationlist.disabled=question.type=="prompt";labellocationlist.value=question.type=="prompt"?"":question.items[qindex].location;preselectedbox.disabled=question.type=="prompt";preselectedbox.checked=question.type=="prompt"?false:question.items[qindex].preselect==1;visiblebox.disabled=question.type=="prompt"?true:index==0&&itemindex==1;visiblebox.checked=question.type=="prompt"?true:typeof question.items[qindex].visible==
386
- "undefined"||question.items[qindex].visible==1}wfu_consent_question_optable_update(i,itemindex)}
387
- function wfu_consent_question_optable_recreate(){var oplist=[];var policy=wfu_get_consent_policy();if(policy){if(typeof wfu_PD_bank.conops!="undefined")for(var id in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(id))wfu_PD_bank.conops[id].active=false;var optable=document.getElementById("wfu_conquestions_optable");var body=optable.tBodies[0];while(body.rows.length>0)optable.rows[0].remove();var i=0;for(var id in wfu_PD_bank.allowedstatus)if(wfu_PD_bank.allowedstatus.hasOwnProperty(id)){var included=
388
- true;included=included&&(policy.children_index[id].length==0&&(wfu_PD_bank.params.oplevels<1||wfu_PD_bank.level[id]<=wfu_PD_bank.params.oplevels)||policy.children_index[id].length>0&&wfu_PD_bank.level[id]==wfu_PD_bank.params.oplevels);included=included&&wfu_PD_bank.needsconsentstatus[id]==1;included=included&&wfu_PD_bank.visible[id];if(included){if(typeof wfu_PD_bank.conops=="undefined")wfu_PD_bank.conops={};wfu_PD_bank.conops[id]={active:true,qindex:[1],itemindex:[1],inverse:[false],unassigned:true,
389
- nonevisible:false};var row=body.insertRow(i);row.id="wfu_conquestions_oprow_"+id;var cell=row.insertCell(0);var name=policy.operations[id].Name;var parid=id;while((parid=policy.operations[parid].Parent)>0)name=policy.operations[parid].Name+"/"+name;cell.innerHTML=name;var cell=row.insertCell(1);var selbox=document.createElement("INPUT");selbox.type="radio";selbox.className="wfu_conquestions_opsel wfu_frozen";wfu_addEventHandler(selbox,"click",wfu_conquestion_optable_handler);cell.appendChild(selbox);
390
- var cell=row.insertCell(2);var invbox=document.createElement("INPUT");invbox.type="checkbox";invbox.className="wfu_conquestions_opinv wfu_frozen";invbox.disabled=true;wfu_addEventHandler(invbox,"change",wfu_conquestion_optable_handler);cell.appendChild(invbox);i++}}}}
391
- function wfu_consent_question_operations_reassign(){var policy=wfu_get_consent_policy();if(policy){for(var opid in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(opid)){wfu_PD_bank.conops[opid].qindex=[];wfu_PD_bank.conops[opid].itemindex=[];wfu_PD_bank.conops[opid].inverse=[];wfu_PD_bank.conops[opid].unassigned=true;wfu_PD_bank.conops[opid].nonevisible=true}for(var i=0;i<policy.questions.length;i++){var question=policy.questions[i];for(var j=0;j<question.items.length;j++){var qitem=question.items[j];
392
- for(var opid in qitem.operations)if(qitem.operations.hasOwnProperty(opid))if(typeof wfu_PD_bank.conops[opid]!="undefined")if(wfu_PD_bank.params.multi_op_assignments||wfu_PD_bank.conops[opid].qindex.length==0){wfu_PD_bank.conops[opid].qindex.push(i+1);wfu_PD_bank.conops[opid].itemindex.push(j+1);wfu_PD_bank.conops[opid].inverse.push(qitem.operations[opid]==-1);wfu_PD_bank.conops[opid].unassigned=false}else delete qitem.operations[opid]}}for(var opid in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(opid)){var j=
393
- 0;while(j<wfu_PD_bank.conops[opid].qindex.length){var qindex=wfu_PD_bank.conops[opid].qindex[j];var itemindex=wfu_PD_bank.conops[opid].itemindex[j];var remove=false;if(qindex<1||qindex>policy.questions.length)remove=true;else{var question=policy.questions[qindex-1];var qnum=question.x*question.y;if(itemindex<1||itemindex>qnum)remove=true}if(remove){wfu_PD_bank.conops[opid].qindex.splice(j,1);wfu_PD_bank.conops[opid].itemindex.splice(j,1);wfu_PD_bank.conops[opid].inverse.splice(j,1)}else{var qitem=
394
- policy.questions[qindex-1].items[itemindex-1];if(typeof qitem.visible=="undefined"||qitem.visible)wfu_PD_bank.conops[opid].nonevisible=false;j++}}if(wfu_PD_bank.conops[opid].nonevisible){wfu_PD_bank.conops[opid].unassigned=wfu_PD_bank.conops[opid].qindex.length==0;wfu_PD_bank.conops[opid].qindex.splice(0,0,1);wfu_PD_bank.conops[opid].itemindex.splice(0,0,1);wfu_PD_bank.conops[opid].inverse.splice(0,0,false)}}wfu_set_consent_policy(policy);wfu_update_consent_question_item_assignments()}}
395
- function wfu_update_consent_question_item_assignments(){var containers=document.querySelectorAll("#wfu_conquestions_container .wfu_conquestion_itemcontainer");for(var i=0;i<containers.length;i++)containers[i].classList.remove("wfu_item_assigned");for(var opid in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(opid)&&wfu_PD_bank.conops[opid].active)for(var j=0;j<wfu_PD_bank.conops[opid].qindex.length;j++){var qindex=wfu_PD_bank.conops[opid].qindex[j];var itemindex=wfu_PD_bank.conops[opid].itemindex[j];
396
- var itemtable=document.querySelector("#wfu_conquestion_container_"+qindex+" .wfu_conquestion_itemtable");var x=itemtable.rows[0].cells.length;var rowindex=Math.floor((itemindex-1)/x);var cellindex=(itemindex-1)%x;itemtable.rows[rowindex].cells[cellindex].classList.add("wfu_item_assigned")}}
397
- function wfu_conquestion_conop_bankpos(opid,index,itemindex){var pos=-1;for(var i=0;i<wfu_PD_bank.conops[opid].qindex.length;i++)if(wfu_PD_bank.conops[opid].qindex[i]==index&&wfu_PD_bank.conops[opid].itemindex[i]==itemindex){pos=i;break}return pos}
398
- function wfu_consent_question_optable_update(index,itemindex){var freeze=index<1||itemindex<1;for(var opid in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(opid)&&wfu_PD_bank.conops[opid].active){var oprow=document.getElementById("wfu_conquestions_oprow_"+opid);var selbox=document.querySelector("#wfu_conquestions_oprow_"+opid+" .wfu_conquestions_opsel");var invbox=document.querySelector("#wfu_conquestions_oprow_"+opid+" .wfu_conquestions_opinv");if(wfu_PD_bank.conops[opid].unassigned||wfu_PD_bank.conops[opid].nonevisible)oprow.classList.add("wfu_op_unassigned");
399
- else oprow.classList.remove("wfu_op_unassigned");var pos=wfu_conquestion_conop_bankpos(opid,index,itemindex);selbox.checked=!freeze&&pos>-1;if(!freeze&&pos>-1&&(wfu_PD_bank.conops[opid].unassigned||wfu_PD_bank.conops[opid].nonevisible)&&index==1&&itemindex==1)selbox.classList.add("wfu_forced_selection");else selbox.classList.remove("wfu_forced_selection");invbox.checked=!freeze&&pos>-1&&wfu_PD_bank.conops[opid].inverse[pos];invbox.disabled=!(!freeze&&pos>-1);if(freeze){selbox.classList.add("wfu_frozen");
400
- invbox.classList.add("wfu_frozen")}else{selbox.classList.remove("wfu_frozen");invbox.classList.remove("wfu_frozen")}}}
401
- function wfu_conquestion_optable_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;var itemcontainer=document.querySelector("#wfu_conquestions_container .wfu_conquestion_itemcontainer.wfu_item_selected");if(!itemcontainer)return;var par=itemcontainer;while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));var index=parseInt(par.id.replace("wfu_conquestion_container_",""));var itemcontainers=document.querySelectorAll("#wfu_conquestion_container_"+
402
- index+" .wfu_conquestion_itemcontainer");var itemindex=-1;for(var j=0;j<itemcontainers.length;j++)if(itemcontainers[j]==itemcontainer){itemindex=j+1;break}var policy=wfu_get_consent_policy();if(!policy)return;if(!item.classList.contains("wfu_conquestions_opsel")&&!item.classList.contains("wfu_conquestions_opinv"))return;var opid=parseInt(item.parentNode.parentNode.id.replace("wfu_conquestions_oprow_",""));var opas=wfu_PD_bank.conops[opid];var pos=wfu_conquestion_conop_bankpos(opid,index,itemindex);
403
- if(pos<0||opas.unassigned){if(!wfu_PD_bank.params.multi_op_assignments||opas.unassigned){var question=policy.questions[opas.qindex[0]-1];for(var j=0;j<question.items.length;j++)if(question.items[j].index==opas.itemindex[0]){if(typeof question.items[j].operations[opid]!="undefined")delete question.items[j].operations[opid];break}opas.qindex.splice(0,1);opas.itemindex.splice(0,1);opas.inverse.splice(0,1)}opas.qindex.push(index);opas.itemindex.push(itemindex);opas.inverse.push(document.querySelector("#wfu_conquestions_oprow_"+
404
- opid+" .wfu_conquestions_opinv").checked);opas.unassigned=false;pos=opas.qindex.length-1;var question=policy.questions[opas.qindex[pos]-1];var qitem=null;var qindex=question.items.length;for(var j=0;j<question.items.length;j++)if(question.items[j].index==opas.itemindex[pos]){qitem=question.items[j];qitem.operations[opid]=opas.inverse[pos]?-1:1;break}else if(question.items[j].index>itemindex){qindex=j;break}if(!qitem){qitem={index:opas.itemindex[pos],label:"",location:"right",preselect:false,operations:{}};
405
- qitem.operations[opid]=opas.inverse[pos]?-1:1;question.items.splice(qindex,0,qitem)}wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(index,itemindex);wfu_update_consent_question_item_assignments();wfu_allops_freeze_events=false}else if(item.classList.contains("wfu_conquestions_opsel")&&pos>=0){var question=policy.questions[opas.qindex[pos]-1];for(var j=0;j<question.items.length;j++)if(question.items[j].index==
406
- opas.itemindex[pos]){if(typeof question.items[j].operations[opid]!="undefined")delete question.items[j].operations[opid];break}opas.qindex.splice(pos,1);opas.itemindex.splice(pos,1);opas.inverse.splice(pos,1);wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;item.checked=false;wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(index,itemindex);wfu_update_consent_question_item_assignments();wfu_allops_freeze_events=false}else if(item.classList.contains("wfu_conquestions_opinv")){opas.inverse[pos]=
407
- item.checked;var question=policy.questions[opas.qindex[pos]-1];for(var j=0;j<question.items.length;j++)if(question.items[j].index==opas.itemindex[pos]){question.items[j].operations[opid]=opas.inverse[pos]?-1:1;break}wfu_set_consent_policy(policy)}}
408
- function wfu_conquestion_tools_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;var qcount=document.querySelectorAll(".wfu_conquestion_container").length;var par=item;while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));var index=parseInt(par.id.replace("wfu_conquestion_container_",""))-1;wfu_allops_freeze_events=true;var action="";if(item.classList.contains("wfu_conquestion_add"))action="add";else if(item.classList.contains("wfu_conquestion_remove")&&
409
- qcount>1)action="remove";else if(item.classList.contains("wfu_conquestion_up")&&index>0)action="up";else if(item.classList.contains("wfu_conquestion_down")&&index<qcount-1)action="down";if(action!=""){wfu_update_consent_question_itemprops(0,-1);wfu_consent_question_action(action,index);wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(0,0);wfu_update_conquestion_header()}wfu_allops_freeze_events=false}
410
- function wfu_update_conquestion_header(){var labels=document.querySelectorAll(".wfu_conquestion_headerlabel");var add_btns=document.querySelectorAll(".wfu_conquestion_tools .wfu_conquestion_btn.wfu_conquestion_add");var remove_btns=document.querySelectorAll(".wfu_conquestion_tools .wfu_conquestion_btn.wfu_conquestion_remove");var up_btns=document.querySelectorAll(".wfu_conquestion_tools .wfu_conquestion_btn.wfu_conquestion_up");var down_btns=document.querySelectorAll(".wfu_conquestion_tools .wfu_conquestion_btn.wfu_conquestion_down");
411
- for(var i=0;i<labels.length;i++){labels[i].innerHTML="Question "+(i+1);if(labels.length>1)remove_btns[i].classList.remove("wfu_tool_disabled");else remove_btns[i].classList.add("wfu_tool_disabled");if(i>0)up_btns[i].classList.remove("wfu_tool_disabled");else up_btns[i].classList.add("wfu_tool_disabled");if(i<labels.length-1)down_btns[i].classList.remove("wfu_tool_disabled");else down_btns[i].classList.add("wfu_tool_disabled")}}
412
- function wfu_permissions_update(updatehtml){function _wfu_nested_perms_update(item,level){var id=item.ID;if(item.children.length>0){policy.permissions[id].allowedstatus={};for(var j=0;j<item.children.length;j++){_wfu_nested_perms_update(item.children[j],level+1);var id2=item.children[j].ID;for(var locid in policy.permissions[id2].allowedstatus)if(policy.permissions[id2].allowedstatus.hasOwnProperty(locid)){var allowedstatus2=policy.permissions[id2].allowedstatus[locid];if(typeof policy.permissions[id].allowedstatus[locid]==
413
- "undefined")policy.permissions[id].allowedstatus[locid]=allowedstatus2;else if(policy.permissions[id].allowedstatus[locid]*allowedstatus2<1)policy.permissions[id].allowedstatus[locid]=0}}}else{var allowed=policy.permissions[id].Allowed;policy.permissions[id].allowedstatus={};for(var k=0;k<policy.permissions[id].Locations.length;k++){var locid=policy.permissions[id].Locations[k];policy.permissions[id].allowedstatus[locid]=allowed.indexOf(locid)>-1?1:-1}}if(typeof wfu_PD_bank.perallowedstatus=="undefined")wfu_PD_bank.perallowedstatus=
414
- {};wfu_PD_bank.perallowedstatus[id]=policy.permissions[id].allowedstatus;if(updatehtml){var row=document.getElementById("wfu_perm_row_"+id);for(var locid in policy.permissions[id].allowedstatus)if(policy.permissions[id].allowedstatus.hasOwnProperty(locid)){var check=document.querySelector("#wfu_perm_row_"+id+" .wfu_location_cell:nth-child("+(parseInt(locid)+1)+") input");wfu_set_checkbox_status(check,policy.permissions[id].allowedstatus[locid])}}}var policy=wfu_get_permissions_policy();if(policy){console.log(policy);
415
- wfu_allops_freeze_events=true;for(var i=0;i<policy.structure.length;i++)_wfu_nested_perms_update(policy.structure[i],1);wfu_allops_freeze_events=false}}
416
- function wfu_adjust_permissions_levels(){function _wfu_force_permission_update_nested(item,locid){var id=item.ID;if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_force_permission_update_nested(item.children[j],locid);else if(policy.permissions[id].Allowed.indexOf(locid)==-1&&policy.permissions[id].Locations.indexOf(locid)>-1)policy.permissions[id].Allowed.push(locid)}function _wfu_nested_adjust_permissions_levels(item,level){if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_nested_adjust_permissions_levels(item.children[j],
417
- level+1);var id=item.ID;for(var locid in wfu_PD_bank.perallowedstatus[id])if(wfu_PD_bank.perallowedstatus[id].hasOwnProperty(locid))if(wfu_PD_bank.perallowedstatus[id][locid]==0&&level==wfu_PD_bank.params.perlevels){_wfu_force_permission_update_nested(item,parseInt(locid));wfu_PD_bank.perallowedstatus[id][locid]=1;policy_needs_update=true}}wfu_permissions_update(false);var policy=wfu_get_permissions_policy();if(policy){var policy_needs_update=false;for(var i=0;i<policy.structure.length;i++)_wfu_nested_adjust_permissions_levels(policy.structure[i],
418
- 1);if(policy_needs_update)wfu_set_permissions_policy(policy)}}
419
- function wfu_perm_toggle(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_location_selector"))return;var id=obj.parentNode.parentNode.id.replace("wfu_perm_row_","");var locid=obj.parentNode.cellIndex;var policy=wfu_get_permissions_policy();if(policy){if(typeof policy.permissions[id]=="undefined")return;var prev_status=obj.classList.contains("indeterminate")?0:obj.checked?-1:1;var new_status=obj.classList.contains("indeterminate")?true:obj.checked;if(!obj.indeterminate)obj.classList.remove("indeterminate");
420
- if(policy.children_index[id].length>0){var level=1;var parid=id;while((parid=policy.permissions[parid].Parent)>0)level++;if((wfu_PD_bank.params.perlevels<1||level<wfu_PD_bank.params.perlevels)&&!confirm("This will make all children permissions "+(new_status?"allowed":"not allowed")+". Continue?")){wfu_allops_freeze_events=true;wfu_set_checkbox_status(obj,prev_status);wfu_allops_freeze_events=false;return}for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];if(policy.children_index[id2].length==
421
- 0){var locindex2=policy.permissions[id2].Allowed.indexOf(locid);if(new_status&&locindex2==-1&&policy.permissions[id2].Locations.indexOf(locid)>-1)policy.permissions[id2].Allowed.push(locid);else if(!new_status&&locindex2>-1)policy.permissions[id2].Allowed.splice(locindex2,1)}}}else{var locindex=policy.permissions[id].Allowed.indexOf(locid);if(new_status&&locindex==-1&&policy.permissions[id].Locations.indexOf(locid)>-1)policy.permissions[id].Allowed.push(locid);else if(!new_status&&locindex>-1)policy.permissions[id].Allowed.splice(locindex,
422
- 1)}wfu_set_permissions_policy(policy);wfu_allops_freeze_events=true;wfu_permissions_update(true);wfu_allops_freeze_events=false}}
423
- function wfu_perm_button_action(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_perm_button"))return;var policy=wfu_get_permissions_policy();if(policy){var par=obj;while((par=par.parentElement)&&!par.classList.contains("wfu_perm_row"));var id=parseInt(par.id.replace("wfu_perm_row_",""));obj.classList.toggle("expanded");for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];var parid=id2;var visible=true;while((parid=policy.permissions[parid].Parent)>
424
- 0)visible=visible&&document.querySelector("#wfu_perm_row_"+parid+" .wfu_perm_button")&&document.querySelector("#wfu_perm_row_"+parid+" .wfu_perm_button").classList.contains("expanded");document.getElementById("wfu_perm_row_"+id2).style.display=visible?"table-row":"none"}}}
425
- function wfu_logactions_update(updatehtml){function _wfu_nested_logactions_update(item,level){var id=item.ID;if(item.children.length>0){policy.logactions[id].allowedstatus={};for(var j=0;j<item.children.length;j++){_wfu_nested_logactions_update(item.children[j],level+1);var id2=item.children[j].ID;for(var entid in policy.logactions[id2].allowedstatus)if(policy.logactions[id2].allowedstatus.hasOwnProperty(entid)){var allowedstatus2=policy.logactions[id2].allowedstatus[entid];if(typeof policy.logactions[id].allowedstatus[entid]==
426
- "undefined")policy.logactions[id].allowedstatus[entid]=allowedstatus2;else if(policy.logactions[id].allowedstatus[entid]*allowedstatus2<1)policy.logactions[id].allowedstatus[entid]=0}}}else{var allowed=policy.logactions[id].Allowed;policy.logactions[id].allowedstatus={};for(var k=0;k<policy.logactions[id].Entities.length;k++){var entid=policy.logactions[id].Entities[k];policy.logactions[id].allowedstatus[entid]=allowed.indexOf(entid)>-1?1:-1}}if(typeof wfu_PD_bank.logallowedstatus=="undefined")wfu_PD_bank.logallowedstatus=
427
- {};wfu_PD_bank.logallowedstatus[id]=policy.logactions[id].allowedstatus;if(updatehtml){var row=document.getElementById("wfu_log_row_"+id);for(var entid in policy.logactions[id].allowedstatus)if(policy.logactions[id].allowedstatus.hasOwnProperty(entid)){var check=document.querySelector("#wfu_log_row_"+id+" .wfu_entity_cell:nth-child("+(parseInt(entid)+1)+") input");wfu_set_checkbox_status(check,policy.logactions[id].allowedstatus[entid])}}}var policy=wfu_get_logactions_policy();if(policy){console.log(policy);
428
- wfu_allops_freeze_events=true;for(var i=0;i<policy.structure.length;i++)_wfu_nested_logactions_update(policy.structure[i],1);wfu_allops_freeze_events=false}}
429
- function wfu_adjust_logactions_levels(){function _wfu_force_logaction_update_nested(item,entid){var id=item.ID;if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_force_logaction_update_nested(item.children[j],entid);else if(policy.logactions[id].Allowed.indexOf(entid)==-1&&policy.logactions[id].Entities.indexOf(entid)>-1)policy.logactions[id].Allowed.push(entid)}function _wfu_nested_adjust_logactions_levels(item,level){if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_nested_adjust_logactions_levels(item.children[j],
430
- level+1);var id=item.ID;for(var entid in wfu_PD_bank.logallowedstatus[id])if(wfu_PD_bank.logallowedstatus[id].hasOwnProperty(entid))if(wfu_PD_bank.logallowedstatus[id][entid]==0&&level==wfu_PD_bank.params.loglevels){_wfu_force_logaction_update_nested(item,parseInt(entid));wfu_PD_bank.logallowedstatus[id][entid]=1;policy_needs_update=true}}wfu_logactions_update(false);var policy=wfu_get_logactions_policy();if(policy){var policy_needs_update=false;for(var i=0;i<policy.structure.length;i++)_wfu_nested_adjust_logactions_levels(policy.structure[i],
431
- 1);if(policy_needs_update)wfu_set_logactions_policy(policy)}}
432
- function wfu_log_toggle(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_entity_selector"))return;var id=obj.parentNode.parentNode.id.replace("wfu_log_row_","");var entid=obj.parentNode.cellIndex;var policy=wfu_get_logactions_policy();if(policy){if(typeof policy.logactions[id]=="undefined")return;var prev_status=obj.classList.contains("indeterminate")?0:obj.checked?-1:1;var new_status=obj.classList.contains("indeterminate")?true:obj.checked;if(!obj.indeterminate)obj.classList.remove("indeterminate");
433
- if(policy.children_index[id].length>0){var level=1;var parid=id;while((parid=policy.logactions[parid].Parent)>0)level++;if((wfu_PD_bank.params.loglevels<1||level<wfu_PD_bank.params.loglevels)&&!confirm("This will make all children log actions "+(new_status?"allowed":"not allowed")+". Continue?")){wfu_allops_freeze_events=true;wfu_set_checkbox_status(obj,prev_status);wfu_allops_freeze_events=false;return}for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];if(policy.children_index[id2].length==
434
- 0){var entindex2=policy.logactions[id2].Allowed.indexOf(entid);if(new_status&&entindex2==-1&&policy.logactions[id2].Entities.indexOf(entid)>-1)policy.logactions[id2].Allowed.push(entid);else if(!new_status&&entindex2>-1)policy.logactions[id2].Allowed.splice(entindex2,1)}}}else{var entindex=policy.logactions[id].Allowed.indexOf(entid);if(new_status&&entindex==-1&&policy.logactions[id].Entities.indexOf(entid)>-1)policy.logactions[id].Allowed.push(entid);else if(!new_status&&entindex>-1)policy.logactions[id].Allowed.splice(entindex,
435
- 1)}wfu_set_logactions_policy(policy);wfu_allops_freeze_events=true;wfu_logactions_update(true);wfu_allops_freeze_events=false}}
436
- function wfu_log_button_action(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_log_button"))return;var policy=wfu_get_logactions_policy();if(policy){var par=obj;while((par=par.parentElement)&&!par.classList.contains("wfu_log_row"));var id=parseInt(par.id.replace("wfu_log_row_",""));obj.classList.toggle("expanded");for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];var parid=id2;var visible=true;while((parid=policy.logactions[parid].Parent)>
437
- 0)visible=visible&&document.querySelector("#wfu_log_row_"+parid+" .wfu_log_button")&&document.querySelector("#wfu_log_row_"+parid+" .wfu_log_button").classList.contains("expanded");document.getElementById("wfu_log_row_"+id2).style.display=visible?"table-row":"none"}}}
438
- function wfu_pdusers_addrole_handler(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_pdusers_roles_add"))return;var par=obj;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_roles_container"));var type=par.id.replace(/^wfu_pdusers_roles_(in|out)_container$/,"$1");var roles=document.querySelector("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_list");var names=[];for(var i=0;i<roles.options.length;i++)if(roles.options[i].selected)names.push(roles.options[i].value);
439
- wfu_allops_freeze_events=true;wfu_pdusers_add_roles(type,names);wfu_allops_freeze_events=false}
440
- function wfu_pdusers_add_roles(type,names){var show=document.querySelector("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_show");var roles=document.querySelector("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_list");var selected=document.querySelectorAll("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_rightpanel .wfu_pdusers_roles_role");var source=document.querySelector('#wfu_pdusers_roles_in_container input[type="radio"]').checked?"in":"out";var btype=type=="in"?
441
- "included":"excluded";var count=selected.length;for(var i=0;i<names.length;i++){var title="";if(names[i]=="all")title="All";else for(var j=0;j<roles.options.length;j++)if(roles.options[j].value==names[i]){title=roles.options[j].innerHTML;break}if(title!=""){var already_in=false;for(var j=0;j<selected.length;j++)if(selected[j].roleName==names[i]){already_in=true;break}if(!already_in){var pos=wfu_PD_bank.pdusers.rolestates[source][btype].indexOf(names[i]);if(pos==-1)wfu_PD_bank.pdusers.rolestates[source][btype].push(names[i]);
442
- if(count>0)show.appendChild(document.createElement("BR"));var role=document.createElement("DIV");role.classList.add("wfu_pdusers_roles_role");role.roleName=names[i];role.innerHTML=title;if(names[i]=="all")role.classList.add("wfu_pdusers_roles_all");else{var delbtn=document.createElement("SPAN");wfu_addEventHandler(delbtn,"click",wfu_pdusers_removerole_handler);role.appendChild(delbtn)}show.appendChild(role);count++}}}}
443
- function wfu_pdusers_clear_roles(type){var show=document.querySelector("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_show");var selected=document.querySelectorAll("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_rightpanel .wfu_pdusers_roles_role");var brs=document.querySelectorAll("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_rightpanel br");for(var i=0;i<selected.length;i++)show.removeChild(selected[i]);for(var i=0;i<brs.length;i++)show.removeChild(brs[i])}
444
- function wfu_pdusers_removerole_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;if(!item.parentNode.classList.contains("wfu_pdusers_roles_role"))return;var role=item.parentNode.roleName;var par=item;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_roles_container"));var type=par.id.replace(/^wfu_pdusers_roles_(in|out)_container$/,"$1");var source=document.querySelector('#wfu_pdusers_roles_in_container input[type="radio"]').checked?"in":"out";var btype=
445
- type=="in"?"included":"excluded";var pos=wfu_PD_bank.pdusers.rolestates[source][btype].indexOf(role);if(pos>-1)wfu_PD_bank.pdusers.rolestates[source][btype].splice(pos,1);var br1=item.parentNode.previousSibling;var br2=item.parentNode.nextSibling;var show=document.querySelector("#"+par.id+" .wfu_pdusers_roles_show");wfu_allops_freeze_events=true;show.removeChild(item.parentNode);if(br1&&br1.tagName&&br1.tagName=="BR")show.removeChild(br1);else if(br2&&br2.tagName&&br2.tagName=="BR")show.removeChild(br2);
446
- wfu_allops_freeze_events=false}
447
- function wfu_pdusers_update(){var pd_users=wfu_get_pd_users();if(pd_users){console.log(pd_users);wfu_PD_bank.pdusers={rolestates:{"in":{included:[],excluded:[]},out:{included:["all"],excluded:[]}}};var userin_input=document.querySelector('#wfu_pdusers_users_in_container .wfu_pdusers_users_leftpanel input[type="text"]');wfu_attach_element_handlers(userin_input,wfu_pdusers_get_users);var userout_input=document.querySelector('#wfu_pdusers_users_out_container .wfu_pdusers_users_leftpanel input[type="text"]');wfu_attach_element_handlers(userout_input,
448
- wfu_pdusers_get_users);wfu_PD_bank.pdusers.userinput={"in":{prev_value:""},out:{prev_value:""},xhr:null};var radioin=document.querySelector('#wfu_pdusers_roles_in_container input[type="radio"]');var rolein_list=document.querySelector("#wfu_pdusers_roles_in_container .wfu_pdusers_roles_list");var rolein_back=document.querySelector("#wfu_pdusers_roles_in_container .wfu_pdusers_roles_back");var radioout=document.querySelector('#wfu_pdusers_roles_out_container input[type="radio"]');var roleout_list=document.querySelector("#wfu_pdusers_roles_out_container .wfu_pdusers_roles_list");
449
- var roleout_back=document.querySelector("#wfu_pdusers_roles_out_container .wfu_pdusers_roles_back");if(pd_users.roles_included.length>0&&pd_users.roles_included[0]!="all"||pd_users.roles_excluded.length==1&&pd_users.roles_excluded[0]=="all"||pd_users.roles_included.length==0&&pd_users.roles_excluded.length==0){wfu_PD_bank.pdusers.rolestates["in"].included=pd_users.roles_included;rolein_list.disabled=false;rolein_back.classList.add("active");roleout_list.disabled=true;roleout_back.classList.remove("active");
450
- radioin.checked=true;wfu_pdusers_add_roles("in",pd_users.roles_included);wfu_pdusers_add_roles("out",[])}else{wfu_PD_bank.pdusers.rolestates.out.excluded=pd_users.roles_excluded;rolein_list.disabled=true;rolein_back.classList.remove("active");roleout_list.disabled=false;roleout_back.classList.add("active");radioout.checked=true;wfu_pdusers_add_roles("in",["all"]);wfu_pdusers_add_roles("out",pd_users.roles_excluded)}}}
451
- function wfu_pdusers_roletype_handler(obj){if(wfu_allops_freeze_events)return;if(obj.name!="wfu_pdusers_roletypes")return;var radioin=document.querySelector('#wfu_pdusers_roles_in_container input[type="radio"]');var rolein_list=document.querySelector("#wfu_pdusers_roles_in_container .wfu_pdusers_roles_list");var rolein_back=document.querySelector("#wfu_pdusers_roles_in_container .wfu_pdusers_roles_back");var radioout=document.querySelector('#wfu_pdusers_roles_out_container input[type="radio"]');var roleout_list=
452
- document.querySelector("#wfu_pdusers_roles_out_container .wfu_pdusers_roles_list");var roleout_back=document.querySelector("#wfu_pdusers_roles_out_container .wfu_pdusers_roles_back");wfu_allops_freeze_events=true;wfu_pdusers_clear_roles("in");wfu_pdusers_clear_roles("out");if(obj.value=="include"){rolein_list.disabled=false;rolein_back.classList.add("active");roleout_list.disabled=true;roleout_back.classList.remove("active");radioin.checked=true;wfu_pdusers_add_roles("in",wfu_PD_bank.pdusers.rolestates["in"].included);
453
- wfu_pdusers_add_roles("out",wfu_PD_bank.pdusers.rolestates["in"].excluded)}else{rolein_list.disabled=true;rolein_back.classList.remove("active");roleout_list.disabled=false;roleout_back.classList.add("active");radioout.checked=true;wfu_pdusers_add_roles("in",wfu_PD_bank.pdusers.rolestates.out.included);wfu_pdusers_add_roles("out",wfu_PD_bank.pdusers.rolestates.out.excluded)}wfu_allops_freeze_events=false}
454
- function wfu_pdusers_adduser_handler(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_pdusers_users_add"))return;var par=obj;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_users_container"));var type=par.id.replace(/^wfu_pdusers_users_(in|out)_container$/,"$1");var users=document.querySelector("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_list");var names=[];for(var i=0;i<users.options.length;i++)if(users.options[i].selected)names.push(users.options[i].value);
455
- wfu_allops_freeze_events=true;wfu_pdusers_add_users(type,names);wfu_allops_freeze_events=false}
456
- function wfu_pdusers_add_users(type,names){var show=document.querySelector("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_show");var users=document.querySelector("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_list");var selected=document.querySelectorAll("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_rightpanel .wfu_pdusers_users_user");var otherselected=document.querySelectorAll("#wfu_pdusers_users_"+(type=="in"?"out":"in")+"_container .wfu_pdusers_users_rightpanel .wfu_pdusers_users_user");
457
- var count=selected.length;for(var i=0;i<names.length;i++){var title="";for(var j=0;j<users.options.length;j++)if(users.options[j].value==names[i]){title=users.options[j].innerHTML;break}if(title!=""){var already_in=false;for(var j=0;j<selected.length;j++)if(selected[j].userName==names[i]){already_in=true;break}if(!already_in){if(count>0)show.appendChild(document.createElement("BR"));for(var j=0;j<otherselected.length;j++)if(otherselected[j].userName==names[i]){var prev_wfu_allops_freeze_events=wfu_allops_freeze_events;
458
- wfu_allops_freeze_events=false;wfu_pdusers_removeuser_handler({target:otherselected[j].children[0]});wfu_allops_freeze_events=prev_wfu_allops_freeze_events;break}var user=document.createElement("DIV");user.classList.add("wfu_pdusers_users_user");user.userName=names[i];user.innerHTML=title;var delbtn=document.createElement("SPAN");wfu_addEventHandler(delbtn,"click",wfu_pdusers_removeuser_handler);user.appendChild(delbtn);show.appendChild(user);count++}}}}
459
- function wfu_pdusers_removeuser_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;if(!item.parentNode.classList.contains("wfu_pdusers_users_user"))return;var user=item.parentNode.userName;var par=item;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_users_container"));var type=par.id.replace(/^wfu_pdusers_users_(in|out)_container$/,"$1");var br1=item.parentNode.previousSibling;var br2=item.parentNode.nextSibling;var show=document.querySelector("#"+
460
- par.id+" .wfu_pdusers_users_show");wfu_allops_freeze_events=true;show.removeChild(item.parentNode);if(br1&&br1.tagName&&br1.tagName=="BR")show.removeChild(br1);else if(br2&&br2.tagName&&br2.tagName=="BR")show.removeChild(br2);wfu_allops_freeze_events=false}
461
- function wfu_pdusers_get_users(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;if(!item.parentNode.classList.contains("wfu_pdusers_users_leftpanel"))return;var par=item;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_users_container"));var type=par.id.replace(/^wfu_pdusers_users_(in|out)_container$/,"$1");if(item.value==wfu_PD_bank.pdusers.userinput[type].prev_value)return;wfu_PD_bank.pdusers.userinput[type].prev_value=item.value;if(wfu_PD_bank.pdusers.xhr!=
462
- null){wfu_PD_bank.pdusers.xhr.abort();wfu_PD_bank.pdusers.xhr=null}var userlist=document.querySelector("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_list");if(item.value==""){var length=userlist.options.length;for(i=0;i<length;i++)userlist.options[0]=null;return}var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_pdusers_get_users";params[1]=new Array(2);params[1][0]=
463
- "nonce";params[1][1]=document.getElementById("_wpnonce").value;params[2]=new Array(2);params[2][0]="query";params[2][1]=item.value;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var start_text="pdusers_get_users:";var pos=xhr.responseText.indexOf(start_text);
464
- if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);var users_str=wfu_plugin_decode_string(response);var users=null;try{users=JSON.parse(users_str)}catch(e$2){}var length=userlist.options.length;for(i=0;i<length;i++)userlist.options[i]=null;for(i=0;i<users.length;i++){var opt=document.createElement("OPTION");opt.value=users[i].user_login;opt.innerHTML=users[i].display_name+
465
- " ("+users[i].user_login+")";userlist.options.add(opt)}}};wfu_PD_bank.pdusers.xhr=xhr;xhr.send(parameters)}function wfu_initialize_consent_policy_basic(){wfu_PD_bank.userinput={prev_value:"",xhr:null,prev_select:-1};wfu_attach_element_handlers(document.getElementById("wfu_pd_user_box0"),wfu_pd_get_users_basic)}
466
- function wfu_pd_get_users_basic(e){e=e||window.event;var item=e.target;if(!item.classList.contains("wfu_pd_user_box0"))return;if(item.value==wfu_PD_bank.userinput)return;var userlist=document.getElementById("wfu_pd_user_select0");wfu_PD_bank.userinput=item.value;if(wfu_PD_bank.userinput.xhr!=null){wfu_PD_bank.userinput.xhr.abort();wfu_PD_bank.userinput.xhr=null}if(item.value==""){var length=userlist.options.length;for(i=0;i<length;i++)userlist.options[0]=null;return}var xhr=wfu_GetHttpRequestObject();
467
- if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_pdusers_get_users";params[1]=new Array(2);params[1][0]="nonce";params[1][1]=document.getElementById("_wpnonce").value;params[2]=new Array(2);params[2][0]="query";params[2][1]=item.value;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type",
468
- "application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var start_text="pdusers_get_users:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);var users_str=wfu_plugin_decode_string(response);var users=null;try{users=JSON.parse(users_str)}catch(e$3){}var length=
469
- userlist.options.length;for(i=0;i<length;i++)userlist.options[0]=null;for(i=0;i<users.length;i++){var opt=document.createElement("OPTION");opt.value=users[i].user_login;opt.innerHTML=users[i].display_name+" ("+users[i].user_login+")";userlist.options.add(opt)}}};wfu_PD_bank.userinput.xhr=xhr;xhr.send(parameters)}
470
- function wfu_export_user_data(){var userlist=document.getElementById("wfu_pd_user_select0");if(userlist.selectedIndex<0){alert("No user has been selected!");return}var params={username:userlist.options[userlist.selectedIndex].value};var params_str=JSON.stringify(params);wfu_download_file("exportdata:"+params_str,1)}
471
- function wfu_erase_user_data_check(){var userlist=document.getElementById("wfu_pd_user_select0");var anchor=document.getElementById("wfu_erase_userdata0");if(userlist.selectedIndex<0){alert("No user has been selected!");return false}else{anchor.href=anchor.href.replace(/action=erase_userdata_ask.*$/,"action=erase_userdata_ask&username="+userlist.options[userlist.selectedIndex].value);return true}}
472
- function wfu_pd_pre_save_actions(){var wfu_PD_bank_str=JSON.stringify(wfu_PD_bank);document.getElementById("wfu_PD_bank").value=wfu_plugin_encode_string(wfu_PD_bank_str)};
1
+ var DraggedItem=null;var ShortcodeNextSave=0;var ShortcodeTimeOut=null;var ShortcodeString="";var Autosave=false;var PageObsolete=false;var PageUpdating=false;var CheckObsolescenceTimeOut=5E3;var wfu_transfers_observer_interval=100;var wfu_allops_freeze_events=false;var wfu_PD_bank={};
2
+ jQuery(document).ready(function($){$(".wfu_color_field").wpColorPicker({change:function(event,ui){event.target.value=ui.color.toString();if(event.target.name=="wfu_text_elements")wfu_update_text_value(event);else if(event.target.name=="wfu_triplecolor_elements")wfu_update_triplecolor_value(event)}})});
3
+ function wfu_admin_activate_tab(key){var tabs=document.getElementById("wfu_tab_container");var tab,tabkey;for(var i=0;i<tabs.childNodes.length;i++){tab=tabs.childNodes[i];if(tab.nodeType===1){tabkey=tab.id.substr(8);if(tab.className.indexOf("nav-tab-active")>-1){tab.className="nav-tab";document.getElementById("wfu_container_"+tabkey).style.display="none"}}}document.getElementById("wfu_tab_"+key).className="nav-tab nav-tab-active";document.getElementById("wfu_container_"+key).style.display="block"}
4
+ function wfu_admin_onoff_clicked(key){var onoff=document.getElementById("wfu_attribute_"+key);var shadows=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_"+key);var shadows_inv=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_"+key+"_inv");var status=onoff.className.substr(onoff.className.length-2)=="on";status=!status;if(status){document.getElementById("wfu_attribute_value_"+key).value="true";onoff.className="wfu_onoff_container_on";for(var i=0;i<shadows.length;i++)shadows[i].style.display=
5
+ "none";for(var i=0;i<shadows_inv.length;i++)shadows_inv[i].style.display="block"}else{document.getElementById("wfu_attribute_value_"+key).value="false";onoff.className="wfu_onoff_container_off";for(var i=0;i<shadows.length;i++)shadows[i].style.display="block";for(var i=0;i<shadows_inv.length;i++)shadows_inv[i].style.display="none"}wfu_generate_shortcode();if(key=="userdata"||key=="formdata")wfu_update_formfield_variables()}
6
+ function wfu_admin_radio_clicked(key){var radios=document.getElementsByName("wfu_radioattribute_"+key);var shadows=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_"+key);var shadows_inv=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_"+key+"_inv");var val="";for(i=0;i<radios.length;i++)if(radios[i].checked)val=radios[i].value;var status=val.substr(0,1)=="*";if(status){val=val.substr(1);for(var i=0;i<shadows.length;i++)shadows[i].style.display="none";for(var i=0;i<shadows_inv.length;i++)shadows_inv[i].style.display=
7
+ "block"}else{for(var i=0;i<shadows.length;i++)shadows[i].style.display="block";for(var i=0;i<shadows_inv.length;i++)shadows_inv[i].style.display="none"}document.getElementById("wfu_attribute_value_"+key).value=val;wfu_generate_shortcode()}function wfu_set_checkbox_status(check,status){if(status==0){check.checked=false;check.indeterminate=true;check.classList.add("indeterminate")}else{check.indeterminate=false;check.classList.remove("indeterminate");check.checked=status==1}}
8
+ function wfu_addEventHandler(obj,evt,handler){if(obj.addEventListener)obj.addEventListener(evt,handler,false);else if(obj.attachEvent)obj.attachEvent("on"+evt,handler);else obj["on"+evt]=handler}
9
+ function wfu_attach_separator_dragdrop_events(){var container=document.getElementById("wfu_placements_container");var item;for(var i=0;i<container.childNodes.length;i++){item=container.childNodes[i];if(item.className=="wfu_component_separator_hor"||item.className=="wfu_component_separator_ver"){wfu_addEventHandler(item,"dragenter",wfu_separator_dragenter);wfu_addEventHandler(item,"dragover",wfu_default_dragover);wfu_addEventHandler(item,"dragleave",wfu_separator_dragleave);wfu_addEventHandler(item,
10
+ "drop",wfu_separator_drop)}}}
11
+ function wfu_Attach_Admin_DragDrop_Events(){if(window.FileReader){var container=document.getElementById("wfu_placements_container");if(container){var available_container=document.getElementById("wfu_componentlist_container");var item;for(var i=0;i<container.childNodes.length;i++){item=container.childNodes[i];if(item.className=="wfu_component_box"){wfu_addEventHandler(item,"dragstart",wfu_component_dragstart);wfu_addEventHandler(item,"dragend",wfu_component_dragend)}}for(var i=0;i<available_container.childNodes.length;i++){item=
12
+ available_container.childNodes[i];if(item.className=="wfu_component_box_container")for(var ii=0;ii<item.childNodes.length;ii++)if(item.childNodes[ii].className=="wfu_component_box wfu_inbase"){wfu_addEventHandler(item.childNodes[ii],"dragstart",wfu_component_dragstart);wfu_addEventHandler(item.childNodes[ii],"dragend",wfu_component_dragend)}}item=document.getElementById("wfu_componentlist_dragdrop");wfu_addEventHandler(item,"dragenter",wfu_componentlist_dragenter);wfu_addEventHandler(item,"dragover",
13
+ wfu_default_dragover);wfu_addEventHandler(item,"dragleave",wfu_componentlist_dragleave);wfu_addEventHandler(item,"drop",wfu_componentlist_drop);wfu_attach_separator_dragdrop_events()}}}
14
+ function wfu_componentlist_dragenter(e){e=e||window.event;if(e.preventDefault)e.preventDefault();if(!DraggedItem)return false;var item=document.getElementById("wfu_componentlist_dragdrop");if(item.className.indexOf("wfu_componentlist_dragdrop_dragover")==-1)item.className+=" wfu_componentlist_dragdrop_dragover";return false}
15
+ function wfu_componentlist_dragleave(e){e=e||window.event;if(e.preventDefault)e.preventDefault();if(!DraggedItem)return false;var item=document.getElementById("wfu_componentlist_dragdrop");item.className=item.className.replace(" wfu_componentlist_dragdrop_dragover","");return false}
16
+ function wfu_componentlist_drop(e){e=e||window.event;if(e.preventDefault)e.preventDefault();var component_raw=e.dataTransfer.getData("Component");if(!component_raw)return false;var parts=component_raw.split("_");var component=parts[0];var multi_index=parseInt(parts[1]);var item=document.getElementById("wfu_component_box_"+component+"_"+multi_index);if(multi_index==0){item.className="wfu_component_box wfu_inbase";item.style.display="block";document.getElementById("wfu_component_box_container_"+component).appendChild(item)}else item.parentNode.removeChild(item);
17
+ var placements=wfu_admin_recreate_placements_text(null,"");wfu_admin_recreate_placements_panel(placements);document.getElementById("wfu_attribute_value_placements").value=placements;wfu_update_multiplacement_attributes();wfu_generate_shortcode();return false}
18
+ function wfu_separator_dragenter(e){e=e||window.event;if(e.preventDefault)e.preventDefault();if(!DraggedItem)return false;if(e.target.className=="wfu_component_separator_hor"){var bar=document.getElementById("wfu_component_bar_hor");bar.style.top=e.target.offsetTop+"px";bar.style.display="block"}else if(e.target.className=="wfu_component_separator_ver"){var bar=document.getElementById("wfu_component_bar_ver");bar.style.top=e.target.offsetTop+"px";bar.style.left=e.target.offsetLeft+"px";bar.style.display=
19
+ "block"}return false}function wfu_default_dragover(e){e=e||window.event;if(e.preventDefault)e.preventDefault();return false}
20
+ function wfu_separator_dragleave(e){e=e||window.event;if(e.preventDefault)e.preventDefault();if(!DraggedItem)return false;if(e.target.className=="wfu_component_separator_hor"){var bar=document.getElementById("wfu_component_bar_hor");bar.style.display="none"}else if(e.target.className=="wfu_component_separator_ver"){var bar=document.getElementById("wfu_component_bar_ver");bar.style.display="none"}return false}
21
+ function wfu_separator_drop(e){e=e||window.event;if(e.preventDefault)e.preventDefault();var component_raw=e.dataTransfer.getData("Component");if(!component_raw)return false;var parts=component_raw.split("_");var component=parts[0];var multi_index=parseInt(parts[1]);var item=document.getElementById("wfu_component_box_"+component+"_"+multi_index);item.style.display="none";item.className="wfu_component_box wfu_inbase";document.getElementById("wfu_component_box_container_"+component).appendChild(item);
22
+ var placements=wfu_admin_recreate_placements_text(e.target,component);wfu_admin_recreate_placements_panel(placements);document.getElementById("wfu_attribute_value_placements").value=placements;wfu_update_multiplacement_attributes();wfu_generate_shortcode();return false}
23
+ function wfu_component_dragstart(e){e=e||window.event;e.dataTransfer.setData("Component",e.target.id.replace("wfu_component_box_",""));if(e.target.className.indexOf("wfu_component_box_dragged")==-1){e.target.className+=" wfu_component_box_dragged";DraggedItem=e.target}e.target.style.zIndex=3;var item=document.getElementById("wfu_componentlist_dragdrop");item.className="wfu_componentlist_dragdrop wfu_componentlist_dragdrop_dragover";item.style.display="block";return false}
24
+ function wfu_component_dragend(e){e=e||window.event;DraggedItem=null;e.target.style.zIndex=1;var item=document.getElementById("wfu_componentlist_dragdrop");item.style.display="none";item.className="wfu_componentlist_dragdrop";e.target.className=e.target.className.replace(" wfu_component_box_dragged","");document.getElementById("wfu_component_bar_ver").style.display="none";document.getElementById("wfu_component_bar_hor").style.display="none";return false}
25
+ function wfu_admin_recreate_placements_text(place,new_component){function add_item(component){if(placements!="")placements+=delim;placements+=component;delim=""}var container=document.getElementById("wfu_placements_container");var delim="";var placements="";var component="";for(var i=0;i<container.childNodes.length;i++){item=container.childNodes[i];if(item.className=="wfu_component_separator_ver"){if(delim=="")delim="+";if(item==place){add_item(new_component);delim="+"}}else if(item.className=="wfu_component_separator_hor"){delim=
26
+ "/";if(item==place){add_item(new_component);delim="/"}}else if(item.className=="wfu_component_box")add_item(item.id.replace("wfu_component_box_","").replace(/_.*$/,""))}return placements}
27
+ function wfu_admin_recreate_placements_panel(placements_text){var container=document.getElementById("wfu_placements_container");var item,placements,sections,itemname_raw,parts,multi_index,index_item;var itemname="";for(var i=0;i<container.childNodes.length;i++){item=container.childNodes[i];if(item.className=="wfu_component_box"){itemname_raw=item.id.replace("wfu_component_box_","");parts=itemname_raw.split("_");itemname=parts[0];multi_index=parseInt(parts[1]);if(multi_index==0){item.style.display=
28
+ "inline-block";item.className="wfu_component_box wfu_inbase";document.getElementById("wfu_component_box_container_"+itemname).appendChild(item)}else item.parentNode.removeChild(item)}}var box_containers=document.querySelectorAll("div.wfu_component_box_container");var component_used={};for(var i=0;i<box_containers.length;i++){itemname=box_containers[i].id.replace("wfu_component_box_container_","");component_used[itemname]=0;index_item=document.querySelector("div#"+box_containers[i].id+" div.wfu_component_box_index");
29
+ if(index_item)index_item.innerHTML="1"}container.innerHTML="";placements=placements_text.split("/");for(var i=0;i<placements.length;i++){item=document.createElement("DIV");item.className="wfu_component_separator_hor";item.setAttribute("draggable",true);container.appendChild(item);item=document.createElement("DIV");item.className="wfu_component_separator_ver";item.setAttribute("draggable",true);container.appendChild(item);sections=placements[i].split("+");for(var ii=0;ii<sections.length;ii++){item=
30
+ document.querySelector("div#wfu_component_box_container_"+sections[ii]+" div.wfu_component_box.wfu_inbase");if(item){itemname_raw=item.id.replace("wfu_component_box_","");parts=itemname_raw.split("_");itemname=parts[0];multi_index=parseInt(parts[1]);if(multi_index==0)container.appendChild(item);else{component_used[itemname]++;item.id="wfu_component_box_"+itemname+"_"+(component_used[itemname]+1).toString();item.style.display="block";index_item=document.querySelector("div#"+item.id+" div.wfu_component_box_index");
31
+ index_item.innerHTML=(component_used[itemname]+1).toString();item=item.cloneNode(true);container.appendChild(item);item.id="wfu_component_box_"+itemname+"_"+component_used[itemname].toString();index_item=document.querySelector("div#"+item.id+" div.wfu_component_box_index");index_item.innerHTML=component_used[itemname].toString();wfu_addEventHandler(item,"dragstart",wfu_component_dragstart);wfu_addEventHandler(item,"dragend",wfu_component_dragend)}item.className="wfu_component_box";item.style.display=
32
+ "inline-block";item=document.createElement("DIV");item.className="wfu_component_separator_ver";item.setAttribute("draggable",true);container.appendChild(item)}}}item=document.createElement("DIV");item.className="wfu_component_separator_hor";item.setAttribute("draggable",true);container.appendChild(item);item=document.createElement("DIV");item.id="wfu_component_bar_hor";item.className="wfu_component_bar_hor";container.appendChild(item);item=document.createElement("DIV");item.id="wfu_component_bar_ver";
33
+ item.className="wfu_component_bar_ver";container.appendChild(item);wfu_attach_separator_dragdrop_events()}
34
+ function wfu_update_multiplacement_attributes(){var box_containers=document.querySelectorAll("div.wfu_component_box_container");for(var i=0;i<box_containers.length;i++){itemname=box_containers[i].id.replace("wfu_component_box_container_","");var index_item=document.querySelector("div#"+box_containers[i].id+" div.wfu_component_box_index");if(index_item){var occurrences=Math.max(1,parseInt(index_item.innerHTML)-1);var dependencies=document.getElementsByName("wfu_attribute_governor_"+itemname);for(var j=
35
+ 0;j<dependencies.length;j++)wfu_update_multiplacement_attribute(dependencies[j].value,occurrences)}}}
36
+ function wfu_update_multiplacement_attribute(attribute,occurrencies){if(attribute=="userdatalabel"){var attributes=document.querySelectorAll("div.wfu_formdata_container");var current=attributes.length;if(current<1)return;var base=attributes[0],tr0,tr;var i=2;while(i<=Math.max(current,occurrencies)){if(i>current){var new_attribute=attribute+i.toString();tr0=base.parentNode;while(tr0!=null&&tr0.tagName!="TR")tr0=tr0.parentNode;if(tr0==null||tr0.tagName!="TR")return;tr=tr0.cloneNode(true);tr.id="tr_"+
37
+ wfu_randomString(4);tr0.parentNode.appendChild(tr);var elem=document.querySelector("tr#"+tr.id+' label[for="wfu_attribute_'+attribute+'"]');elem.setAttribute("for","wfu_attribute_"+new_attribute);elem.innerHTML+=" ("+i.toString()+")";elem=document.querySelector("tr#"+tr.id+" input.wfu_attribute_governor");elem.setAttribute("name","wfu_attribute_governor_independent");elem.value=new_attribute;elem=document.querySelector("tr#"+tr.id+" div.wfu_formdata_container");elem.id+=i.toString();var def=document.getElementById("wfu_attribute_default_"+
38
+ new_attribute);if(!def){def=document.createElement("INPUT");def.id="wfu_attribute_default_"+new_attribute;def.type="hidden";def.value=document.getElementById("wfu_attribute_default_"+attribute).value;document.getElementById("wfu_attribute_defaults").appendChild(def)}var shortcode_value=document.getElementById("wfu_attribute_value_"+new_attribute);if(!shortcode_value){shortcode_value=document.createElement("INPUT");shortcode_value.id="wfu_attribute_value_"+new_attribute;shortcode_value.type="hidden";
39
+ shortcode_value.value=def.value;document.getElementById("wfu_attribute_values").appendChild(shortcode_value)}window["wfu_attribute_"+new_attribute+"_formtemplate"]=window["wfu_attribute_"+attribute+"_formtemplate"];window["wfu_attribute_"+new_attribute+"_typeprops"]=window["wfu_attribute_"+attribute+"_typeprops"];wfu_apply_value(new_attribute,"formfields",shortcode_value.value)}else if(i>occurrencies){tr=attributes[i-1].parentNode;while(tr!=null&&tr.tagName!="TR")tr=tr.parentNode;if(tr==null||tr.tagName!=
40
+ "TR")return;tr.parentNode.removeChild(tr);wfu_update_formfield_variables()}i++}attributes=document.querySelectorAll("div.wfu_formdata_container");var names=[];for(var i=0;i<attributes.length;i++)names.push(attributes[i].id.replace(/^wfu_attribute_/,""));var all_attributes=document.querySelectorAll(".wfu_formdata_all_attributes");for(var i=0;i<all_attributes.length;i++)all_attributes[i].value=names.join(",");wfu_formdata_update_all_updown_buttons(attribute)}}
41
+ function wfu_subfolders_input_changed(e){e=e||window.event;var item=e.target;var key=item.id.replace("wfu_subfolders_path_","");key=key.replace("wfu_subfolders_label_","");var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+key);var tools_ok=document.getElementById("wfu_subfolders_ok_"+key);var old_path_value,old_label_value;var isnewitem=
42
+ document.getElementById("wfu_subfolders_isnewitem_"+key).value=="1";if(isnewitem){old_path_value="";old_label_value=""}else{var items=list.data;item=items[list.selectedIndex];old_path_value=item.path;old_label_value=item.label}if(tools_path.value==old_path_value&&tools_label.value==old_label_value){tools_ok.disabled=true;if(!isnewitem)wfu_subfolders_update_nav(key)}else{tools_ok.disabled=false;var navs=document.getElementsByName("wfu_subfolder_nav_"+key);for(var i=0;i<navs.length;i++)navs[i].disabled=
43
+ true}}
44
+ function wfu_subfolders_auto_changed(key){var list=document.getElementById("wfu_attribute_"+key);var auto=document.getElementById("wfu_subfolders_auto_"+key);var editable=document.getElementById("wfu_subfolders_editable_"+key);var manualtext=document.getElementById("wfu_subfolders_manualtext_"+key);if(auto.checked){var manualvalue=document.getElementById("wfu_attribute_value_"+key).value;if(manualvalue.substr(0,4)!="auto")manualtext.value=manualvalue;editable.parentNode.style.display="inline";wfu_apply_value(key,
45
+ "folderlist","auto"+(editable.checked?"+":""));list.disabled=true}else{list.disabled=false;editable.parentNode.style.display="none";wfu_apply_value(key,"folderlist",manualtext.value)}}
46
+ function wfu_subfolders_up_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];var prevind=item.index-1;if(prevind<0)return;var prevpos=-1;var curind=list.selectedIndex-1;while(curind>=0)if(items[curind].level==item.level&&items[curind].index==prevind){prevpos=curind;break}else curind--;if(prevpos==-1)return;var children_count=0;curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level>
47
+ item.level){children_count++;curind++}else break;items[prevpos].index=item.index;item.index=prevind;list.data=items.slice(0,prevpos).concat(items.slice(list.selectedIndex,list.selectedIndex+1+children_count)).concat(items.slice(prevpos,list.selectedIndex)).concat(items.slice(list.selectedIndex+1+children_count));var val=wfu_update_subfolder_list(key);list.selectedIndex=prevpos;wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
48
+ key).value=val;wfu_generate_shortcode()}}
49
+ function wfu_subfolders_down_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];var nextind=item.index+1;var nextpos=-1;curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level==item.level){nextpos=curind;break}else if(items[curind].level<item.level)break;else curind++;if(nextpos==-1)return;var next_children_count=0;curind=nextpos+1;while(curind<items.length)if(items[curind].level>
50
+ item.level){next_children_count++;curind++}else break;items[nextpos].index=item.index;item.index=nextind;list.data=items.slice(0,list.selectedIndex).concat(items.slice(nextpos,nextpos+1+next_children_count)).concat(items.slice(list.selectedIndex,nextpos)).concat(items.slice(nextpos+1+next_children_count));var val=wfu_update_subfolder_list(key);list.selectedIndex=list.selectedIndex+next_children_count+1;wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
51
+ key).value=val;wfu_generate_shortcode()}}
52
+ function wfu_subfolders_left_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level>item.level){items[curind].level--;curind++}else break;item.level--;var val=wfu_update_subfolder_list(key);list.data=wfu_decode_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
53
+ key).value=val;wfu_generate_shortcode()}}
54
+ function wfu_subfolders_right_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level>item.level){items[curind].level++;curind++}else break;item.level++;var val=wfu_update_subfolder_list(key);list.data=wfu_decode_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+
55
+ key).value=val;wfu_generate_shortcode()}}
56
+ function wfu_subfolders_def_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];if(item["default"])item["default"]=false;else{for(var i=0;i<items.length;i++)items[i]["default"]=false;item["default"]=true}var val=wfu_update_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+key).value=val;wfu_generate_shortcode()}}
57
+ function wfu_subfolders_ok_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+key);if(tools_path.value==""||tools_label.value==""){alert("Path or label cannot be empty!");return}var items=list.data;var isnewitem=document.getElementById("wfu_subfolders_isnewitem_"+key).value=="1";if(isnewitem){var newlevel=parseInt(document.getElementById("wfu_subfolders_newitemlevel_"+
58
+ key).value);var newitem={label:tools_label.value,path:tools_path.value,level:newlevel,"default":false};var newpos=parseInt(document.getElementById("wfu_subfolders_newitemindex_"+key).value);if(newpos>=items.length)items.push(newitem);else items.splice(newpos,0,newitem)}else{item=items[list.selectedIndex];item.path=tools_path.value;item.label=tools_label.value}var val=wfu_update_subfolder_list(key);list.data=wfu_decode_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=
59
+ val;document.getElementById("wfu_attribute_value_"+key).value=val;wfu_generate_shortcode()}}
60
+ function wfu_subfolders_del_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;item=items[list.selectedIndex];var children_count=0;curind=list.selectedIndex+1;while(curind<items.length)if(items[curind].level>item.level){children_count++;curind++}else break;if(children_count>0)if(!confirm("Children items will be deleted as well. Proceed?"))return;items.splice(list.selectedIndex,1+children_count);var val=wfu_update_subfolder_list(key);
61
+ list.data=wfu_decode_subfolder_list(key);wfu_subfolders_update_toolnav(key);item=list;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+key).value=val;wfu_generate_shortcode()}}
62
+ function wfu_subfolders_add_clicked(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;var curpos=list.selectedIndex;item=items[curpos];var opts=list.options;var opt=document.createElement("option");opt.value="";opt.innerHTML="";opts.add(opt,curpos);list.selectedIndex=curpos;var tools_container=document.getElementById("wfu_subfolder_tools_"+key);var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+
63
+ key);var tools_ok=document.getElementById("wfu_subfolders_ok_"+key);var tools_browse=document.getElementById("wfu_subfolders_browse_"+key);tools_container.className="wfu_subfolder_tools_container";tools_label.disabled=false;tools_ok.disabled=true;document.getElementById("wfu_subfolders_isnewitem_"+key).value="1";document.getElementById("wfu_subfolders_newitemindex_"+key).value=curpos;document.getElementById("wfu_subfolders_newitemlevel_"+key).value=item.level;document.getElementById("wfu_subfolders_newitemlevel2_"+
64
+ key).value="";tools_path.disabled=item.level==0;tools_browse.disabled=item.level==0;if(item.level==0){tools_path.value="{root}";tools_label.value="{upload folder}"}else{tools_path.value="";tools_label.value=""}var navs=document.getElementsByName("wfu_subfolder_nav_"+key);for(var i=0;i<navs.length;i++)navs[i].disabled=true}
65
+ function wfu_subfolders_browse_clicked(key){var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var fd=null;try{var fd=new FormData}catch(e){}if(fd==null)return;var container=document.getElementById("wfu_global_dialog_container");var dialog=document.getElementById("wfu_subfolders_browser_"+key);var btn=document.getElementById("wfu_subfolders_browse_"+key);var shadow=document.getElementById("wfu_subfolders_inner_shadow_"+key);var msgcont=document.getElementById("wfu_subfolders_browser_msgcont_"+
66
+ key);var msg=document.getElementById("wfu_subfolders_browser_msg_"+key);var img=document.getElementById("wfu_subfolders_browser_img_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);var list=document.getElementById("wfu_subfolders_browser_list_"+key);while(list.options.length>0)list.options.remove(0);ok.disabled=true;ok.onclick=function(){wfu_folder_browser_cancel_clicked(key)};msg.innerHTML="loading folder contents...";img.style.display="inline";msgcont.style.display="block";
67
+ container.style.display="block";dialog.style.display="block";dialog.style.left=btn.offsetLeft+btn.offsetWidth-dialog.offsetWidth+"px";dialog.style.top=btn.offsetTop+btn.offsetHeight-dialog.offsetHeight+"px";shadow.style.display="block";container.onclick=function(){wfu_folder_browser_cancel_clicked(key)};var path=document.getElementById("wfu_attribute_uploadpath").value;if(path.substr(path.length-1)=="/")path=path.substr(0,path.length-1);var paths=wfu_get_relative_path(key).split(",");var path1=path+
68
+ paths[0];if(path1.substr(0)!="/")path1="/"+path1;var path2="";if(paths.length==2)path2=paths[1];fd.append("action","wfu_ajax_action_read_subfolders");fd.append("folder1",wfu_plugin_encode_string(path1));fd.append("folder2",wfu_plugin_encode_string(path2));xhr.key=key;xhr.addEventListener("load",wfu_readfolderComplete,false);xhr.addEventListener("error",wfu_readfolderFailed,false);xhr.addEventListener("abort",wfu_readfolderCanceled,false);xhr.open("POST",AdminParams.wfu_ajax_url);xhr.send(fd)}
69
+ function wfu_readfolderComplete(evt){var key=evt.target.key;var msgcont=document.getElementById("wfu_subfolders_browser_msgcont_"+key);var msg=document.getElementById("wfu_subfolders_browser_msg_"+key);var img=document.getElementById("wfu_subfolders_browser_img_"+key);var list=document.getElementById("wfu_subfolders_browser_list_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+
70
+ key);var txt=evt.target.responseText;if(txt!=-1){var start_text="wfu_read_subfolders:";var pos=evt.target.responseText.indexOf(start_text);if(pos==-1)pos=evt.target.responseText.length;var messages=evt.target.responseText.substr(0,pos);var response=evt.target.responseText.substr(pos+start_text.length,evt.target.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header=="success"){var filelist=
71
+ wfu_plugin_decode_string(txt_value);var flist=filelist.split(",");var fcount=0;var opt;for(var i=0;i<flist.length;i++)if(flist[i]!=""){opt=document.createElement("option");opt.value=flist[i];opt.innerHTML=flist[i].replace("*","&nbsp;&nbsp;&nbsp;");list.add(opt);fcount++}if(fcount==0){opt=document.createElement("option");opt.value="";opt.innerHTML="{empty}";opt.disabled=true;list.add(opt)}list.selectedIndex=-1;ok.onclick=function(){var val=list.options[list.selectedIndex].value;var level=parseInt(document.getElementById("wfu_subfolders_newitemlevel_"+
72
+ key).value);if(val.substr(0,1)=="*"||level==0){document.getElementById("wfu_subfolders_newitemlevel_"+key).value=level+1;if(level>0)val=val.substr(1)}tools_path.value=val;tools_label.value=val;wfu_folder_browser_cancel_clicked(key);wfu_subfolders_ok_clicked(key)};msgcont.style.display="none"}else if(txt_header=="error"){msg.innerHTML=txt_value;img.style.display="none";ok.disabled=false}else{msg.innerHTML="Unknown error";img.style.display="none";ok.disabled=false}}}
73
+ function wfu_readfolderFailed(evt){var key=evt.target.key;var msg=document.getElementById("wfu_subfolders_browser_msg_"+key);var img=document.getElementById("wfu_subfolders_browser_img_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);msg.innerHTML="Unknown error";img.style.display="none";ok.disabled=false}
74
+ function wfu_readfolderCanceled(evt){var key=evt.target.key;var msg=document.getElementById("wfu_subfolders_browser_msg_"+key);var img=document.getElementById("wfu_subfolders_browser_img_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);msg.innerHTML="Unknown error";img.style.display="none";ok.disabled=false}
75
+ function wfu_subfolders_browser_list_changed(key){var list=document.getElementById("wfu_subfolders_browser_list_"+key);var ok=document.getElementById("wfu_subfolders_browser_ok_"+key);ok.disabled=list.selectedIndex<0}
76
+ function wfu_folder_browser_cancel_clicked(key){var container=document.getElementById("wfu_global_dialog_container");var dialog=document.getElementById("wfu_subfolders_browser_"+key);var btn=document.getElementById("wfu_subfolders_browse_"+key);var shadow=document.getElementById("wfu_subfolders_inner_shadow_"+key);container.onclick=null;shadow.style.display="none";dialog.style.display="none";container.style.display="none"}
77
+ function wfu_get_relative_path(key){var list=document.getElementById("wfu_attribute_"+key);if(list.selectedIndex<0)return;var items=list.data;var isnewitem=document.getElementById("wfu_subfolders_isnewitem_"+key).value=="1";var level;if(isnewitem)level=parseInt(document.getElementById("wfu_subfolders_newitemlevel_"+key).value);else level=items[list.selectedIndex].level;var relpath="/";var curpos=list.selectedIndex-1;var curlevel=level;while(curpos>=0&&curlevel>1){if(items[curpos].level<curlevel){relpath=
78
+ "/"+items[curpos].path+relpath;curlevel=items[curpos].level}curpos--}if(isnewitem&&document.getElementById("wfu_subfolders_newitemlevel2_"+key).value=="1"&&level>0&&list.selectedIndex>0)relpath+=","+items[list.selectedIndex-1].path;return relpath}function wfu_subfolders_changed(key){wfu_update_subfolder_list(key);wfu_subfolders_update_toolnav(key)}
79
+ function wfu_subfolders_update_toolnav(key){var list=document.getElementById("wfu_attribute_"+key);var items,item,ind,nextind,prevlevel;var tools_container=document.getElementById("wfu_subfolder_tools_"+key);var tools_path=document.getElementById("wfu_subfolders_path_"+key);var tools_label=document.getElementById("wfu_subfolders_label_"+key);var tools_ok=document.getElementById("wfu_subfolders_ok_"+key);var tools_browse=document.getElementById("wfu_subfolders_browse_"+key);var auto=document.getElementById("wfu_subfolders_auto_"+
80
+ key);document.getElementById("wfu_subfolders_isnewitem_"+key).value="";document.getElementById("wfu_subfolders_newitemindex_"+key).value="";document.getElementById("wfu_subfolders_newitemlevel_"+key).value="";document.getElementById("wfu_subfolders_newitemlevel2_"+key).value="";if(list.data==null){items=wfu_decode_subfolder_list(key);list.data=items}else items=list.data;if(list.data.length===0){list.className="wfu_select_folders wfu_select_folders_empty";list.options[0].innerHTML=auto.checked?"":
81
+ "press here"}else list.className="wfu_select_folders";if(list.selectedIndex<0){tools_container.className="wfu_subfolder_tools_container wfu_subfolder_tools_disabled";tools_path.disabled=true;tools_label.disabled=true;tools_ok.disabled=true;tools_browse.disabled=true;tools_label.value="";tools_path.value=""}else if(list.selectedIndex>=list.options.length-1){tools_container.className="wfu_subfolder_tools_container";tools_label.disabled=false;tools_ok.disabled=true;document.getElementById("wfu_subfolders_isnewitem_"+
82
+ key).value="1";document.getElementById("wfu_subfolders_newitemindex_"+key).value=items.length;var level;if(items.length==0)level=0;else if(items[items.length-1].level==0)level=1;else level=items[items.length-1].level;document.getElementById("wfu_subfolders_newitemlevel_"+key).value=level;document.getElementById("wfu_subfolders_newitemlevel2_"+key).value="1";tools_path.disabled=level==0;tools_browse.disabled=false;if(level==0){tools_path.value="{root}";tools_label.value="{upload folder}"}else{tools_path.value=
83
+ "";tools_label.value=""}}else{tools_container.className="wfu_subfolder_tools_container";tools_label.disabled=false;tools_ok.disabled=true;item=items[list.selectedIndex];tools_path.disabled=item.level==0;tools_browse.disabled=item.level==0;tools_label.value=item.label;tools_path.value=item.path}var navs=document.getElementsByName("wfu_subfolder_nav_"+key);if(list.selectedIndex<0||list.selectedIndex>=list.options.length-1)for(var i=0;i<navs.length;i++)navs[i].disabled=true;else wfu_subfolders_update_nav(key)}
84
+ function wfu_subfolders_update_nav(key){var list=document.getElementById("wfu_attribute_"+key);var navs_up=document.getElementById("wfu_subfolders_up_"+key);var navs_down=document.getElementById("wfu_subfolders_down_"+key);var navs_left=document.getElementById("wfu_subfolders_left_"+key);var navs_right=document.getElementById("wfu_subfolders_right_"+key);var navs_add=document.getElementById("wfu_subfolders_add_"+key);var navs_def=document.getElementById("wfu_subfolders_def_"+key);var navs_del=document.getElementById("wfu_subfolders_del_"+
85
+ key);var items=list.data;var item=items[list.selectedIndex];navs_up.disabled=item.index<=0;ind=list.selectedIndex+1;nextind=0;while(ind<items.length)if(items[ind].level==item.level){nextind=items[ind].index;break}else if(items[ind].level<item.level)break;else ind++;navs_down.disabled=item.level==0||nextind==0;navs_left.disabled=list.selectedIndex==0&&item.level<1||list.selectedIndex>0&&item.level<=1;if(list.selectedIndex>=1)prevlevel=items[list.selectedIndex-1].level;else prevlevel=0;navs_right.disabled=
86
+ item.level-prevlevel>0;navs_add.disabled=item.level==0;navs_def.disabled=false;navs_def.className="button"+(item["default"]?" wfu_subfolder_nav_pressed":"");navs_del.disabled=false}
87
+ function wfu_decode_subfolder(data){var ret={label:"",path:"",level:0,"default":false};data=data.trim();var star_count=0;var is_default=false;while(star_count<data.length)if(data.substr(star_count,1)=="*")star_count++;else break;data=data.substr(star_count,data.length-star_count);if(data.substr(0,1)=="&"){data=data.substr(1);is_default=true}ret.level=star_count;ret["default"]=is_default;var data_raw=data.split("/");if(data_raw.length==1){ret.path=data_raw[0];ret.label=data_raw[0]}else if(data_raw.length>
88
+ 1){ret.path=data_raw[0];ret.label=data_raw[1]}if(star_count==0){ret.path="{root}";if(ret.label=="")ret.label="{upload folder}"}return ret}
89
+ function wfu_decode_subfolder_list(key){var opts=document.getElementById("wfu_attribute_"+key).options;var list=Array();var dir_levels=["root"];var last_index=[0];var subfolder_path;var prev_level=-1;for(var i=0;i<opts.length-1;i++){list.push(wfu_decode_subfolder(wfu_plugin_decode_string(opts[i].value)));if(dir_levels.length>list[i].level)dir_levels[list[i].level]=list[i].path;else dir_levels.push(list[i].path);subfolder_path="";for(j=1;j<=list[i].level;j++)subfolder_path+=dir_levels[j]+"/";list[i].fullpath=
90
+ subfolder_path;if(last_index.length<=list[i].level)last_index.push(0);if(list[i].level>prev_level)list[i].index=0;else list[i].index=last_index[list[i].level]+1;last_index[list[i].level]=list[i].index;prev_level=list[i].level}return list}
91
+ function wfu_update_subfolder_list(key){var opts=document.getElementById("wfu_attribute_"+key).options;var list=document.getElementById("wfu_attribute_"+key);var items=list.data;if(items==null)return;var value_raw,text_raw;var global_raw="";opts.length=items.length+1;for(var i=0;i<items.length;i++){value_raw="";text_raw="";for(j=0;j<items[i].level;j++){value_raw+="*";text_raw+="&nbsp;&nbsp;&nbsp;"}if(items[i]["default"]){value_raw+="&";opts[i].className="wfu_select_folders_option_default"}else opts[i].className=
92
+ "";value_raw+=items[i].path+"/"+items[i].label;text_raw+=items[i].label;opts[i].value=wfu_plugin_encode_string(value_raw);opts[i].innerHTML=text_raw;if(global_raw!="")global_raw+=",";global_raw+=value_raw}opts[items.length].value="";opts[items.length].innerHTML="";return global_raw}
93
+ function wfu_userdata_edit_field(line,label,required){var item;for(var i=0;i<line.childNodes.length;i++){item=line.childNodes[i];if(item.tagName=="INPUT")if(item.type=="text"){item.value=label;wfu_attach_element_handlers(item,wfu_update_userfield_value)}else{if(item.type=="checkbox")item.checked=required}else if(item.tagName=="DIV")item.className="wfu_userdata_action"}}function wfu_formdata_edit_field(line,label,required){}
94
+ function wfu_formdata_get_field_props(key){var key_parts=key.split("_");var attribute=key_parts[0];var a="wfu_formfield_"+key;var fielddef=window["wfu_attribute_"+attribute+"_typeprops"][document.getElementById(a+"_type").value];var field={type:document.getElementById(a+"_type").value,label:fielddef.label==""?document.getElementById(a+"_label").value:fielddef.label,labelposition:fielddef.labelposition.substr(0,4)=="show"&&document.getElementById(a+"_labelposition")?document.getElementById(a+"_labelposition").value:
95
+ fielddef.labelposition.substr(5),required:fielddef.required.substr(0,4)=="show"&&document.getElementById(a+"_required")?document.getElementById(a+"_required").checked:fielddef.required.substr(5)=="true",donotautocomplete:fielddef.donotautocomplete.substr(0,4)=="show"&&document.getElementById(a+"_donotautocomplete")?document.getElementById(a+"_donotautocomplete").checked:fielddef.donotautocomplete.substr(5)=="true",validate:fielddef.validate.substr(0,4)=="show"&&document.getElementById(a+"_validate")?
96
+ document.getElementById(a+"_validate").checked:fielddef.validate.substr(5)=="true",typehook:fielddef.typehook.substr(0,4)=="show"&&document.getElementById(a+"_typehook")?document.getElementById(a+"_typehook").checked:fielddef.typehook.substr(5)=="true",hintposition:fielddef.hintposition.substr(0,4)=="show"&&document.getElementById(a+"_hintposition")?document.getElementById(a+"_hintposition").value:fielddef.hintposition.substr(5),"default":fielddef["default"].substr(0,4)=="show"&&document.getElementById(a+
97
+ "_default")?document.getElementById(a+"_default").value:fielddef["default"].substr(5),data:fielddef.data.substr(0,4)=="show"&&document.getElementById(a+"_data")?document.getElementById(a+"_data").value:fielddef.data.substr(5),group:fielddef.group.substr(0,4)=="show"&&document.getElementById(a+"_group")?document.getElementById(a+"_group").value:fielddef.group.substr(5),format:fielddef.format.substr(0,4)=="show"&&document.getElementById(a+"_format")?document.getElementById(a+"_format").value:fielddef.format.substr(5)};
98
+ return field}
99
+ function wfu_formdata_type_changed(key){var key_parts=key.split("_");var attribute=key_parts[0];var a="wfu_formfield_"+key;var line_container=document.getElementById(a+"_container");var field=wfu_formdata_get_field_props(key);var template=wfu_formdata_prepare_template(attribute,field,key);line_container.innerHTML=template;var formfield_elements=document.querySelectorAll("div#"+a+'_container input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],wfu_update_formfield_value);
100
+ wfu_formdata_update_buttons(key);wfu_update_formfield_value({target:line_container})}function wfu_userdata_add_field(obj){var line=obj.parentNode;var newline=line.cloneNode(true);wfu_userdata_edit_field(newline,"",false);line.parentNode.insertBefore(newline,line.nextSibling)}
101
+ function wfu_formdata_add_field(key){var key_parts=key.split("_");var attribute=key_parts[0];var ind=key_parts[1];var container=document.getElementById("wfu_attribute_"+attribute);var prev=document.getElementById("wfu_formfield_"+key+"_container");var new_line_container=document.createElement("DIV");var new_key=attribute+"_"+wfu_randomString(4);new_line_container.id="wfu_formfield_"+new_key+"_container";new_line_container.className="wfu_formdata_line_container";container.insertBefore(new_line_container,
102
+ prev.nextSibling);var field={type:"text",label:"",labelposition:"left",required:false,donotautocomplete:false,validate:false,"default":"",data:"",group:"",format:"",hintposition:"right",typehook:false};var template=wfu_formdata_prepare_template(attribute,field,new_key);new_line_container.innerHTML=template;var formfield_elements=document.querySelectorAll("div#wfu_formfield_"+new_key+'_container input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],
103
+ wfu_update_formfield_value);wfu_formdata_update_buttons(key);wfu_formdata_update_buttons(new_key);wfu_update_formfield_value({target:new_line_container})}
104
+ function wfu_formdata_prepare_template(attribute,field,key){var template=wfu_plugin_decode_string(window["wfu_attribute_"+attribute+"_formtemplate"]);var fielddef=window["wfu_attribute_"+attribute+"_typeprops"][field.type];var fielddef_array=window["wfu_attribute_"+attribute+"_typeprops"][0].split(",");var fieldprops_basic=["label","required","donotautocomplete","validate","typehook","labelposition","hintposition","default","data","group","format"];var labelpositions=["none","top","right","bottom",
105
+ "left","placeholder"];var hintpositions=["none","inline","top","right","bottom","left"];template=template.replace(/\[\[key\]\]/g,key).replace(/\[\[t\]\]/g,field.type).replace(/\[\[label\]\]/g,field.label).replace(/\[\[s\]\]/g,field.labelposition).replace(/\[\[d\]\]/g,field["default"]).replace(/\[\[l\]\]/g,field.data).replace(/\[\[label_label\]\]/g,fielddef.label_label).replace(/\[\[data_label\]\]/g,fielddef.data_label).replace(/\[\[g\]\]/g,field.group).replace(/\[\[f\]\]/g,field.format).replace(/\[\[p\]\]/g,
106
+ field.hintposition);for(var i=0;i<fieldprops_basic.length;i++)template=template.replace(new RegExp("\\[\\["+fieldprops_basic[i]+"_hint\\]\\]","g"),fielddef[fieldprops_basic[i]+"_hint"]);for(var i=0;i<fielddef_array.length;i++)template=template.replace("[[type_"+fielddef_array[i]+"_selected]]",fielddef_array[i]==field.type?' selected="selected"':"");for(var i=0;i<labelpositions.length;i++)template=template.replace("[[labelposition_"+labelpositions[i]+"_selected]]",labelpositions[i]==field.labelposition?
107
+ ' selected="selected"':"");for(var i=0;i<hintpositions.length;i++)template=template.replace("[[hintposition_"+hintpositions[i]+"_selected]]",hintpositions[i]==field.hintposition?' selected="selected"':"");template=template.replace("[[remove_disabled]]","");template=template.replace("[[up_disabled]]","");template=template.replace("[[down_disabled]]","");template=field.required?template.replace(/\[\[r\->\]\]|\[\[<\-r\]\]/g,""):template.replace(/\[\[r\->\]\].*\[\[<\-r\]\]/g,"");template=field.donotautocomplete?
108
+ template.replace(/\[\[a\->\]\]|\[\[<\-a\]\]/g,""):template.replace(/\[\[a\->\]\].*\[\[<\-a\]\]/g,"");template=field.validate?template.replace(/\[\[v\->\]\]|\[\[<\-v\]\]/g,""):template.replace(/\[\[v\->\]\].*\[\[<\-v\]\]/g,"");template=field.typehook?template.replace(/\[\[h\->\]\]|\[\[<\-h\]\]/g,""):template.replace(/\[\[h\->\]\].*\[\[<\-h\]\]/g,"");template=fielddef.labelposition.substr(0,4)=="show"?template.replace(/\[\[S\->\]\]|\[\[<\-S\]\]/g,""):template.replace(/\[\[S\->\]\][^]*\[\[<\-S\]\]/g,
109
+ "");template=fielddef.required.substr(0,4)=="show"?template.replace(/\[\[R\->\]\]|\[\[<\-R\]\]/g,""):template.replace(/\[\[R\->\]\][^]*\[\[<\-R\]\]/g,"");template=fielddef.donotautocomplete.substr(0,4)=="show"?template.replace(/\[\[A\->\]\]|\[\[<\-A\]\]/g,""):template.replace(/\[\[A\->\]\][^]*\[\[<\-A\]\]/g,"");template=fielddef.validate.substr(0,4)=="show"?template.replace(/\[\[V\->\]\]|\[\[<\-V\]\]/g,""):template.replace(/\[\[V\->\]\][^]*\[\[<\-V\]\]/g,"");template=fielddef.hintposition.substr(0,
110
+ 4)=="show"?template.replace(/\[\[P\->\]\]|\[\[<\-P\]\]/g,""):template.replace(/\[\[P\->\]\][^]*\[\[<\-P\]\]/g,"");template=fielddef.typehook.substr(0,4)=="show"?template.replace(/\[\[H\->\]\]|\[\[<\-H\]\]/g,""):template.replace(/\[\[H\->\]\][^]*\[\[<\-H\]\]/g,"");template=fielddef["default"].substr(0,4)=="show"?template.replace(/\[\[D\->\]\]|\[\[<\-D\]\]/g,""):template.replace(/\[\[D\->\]\][^]*\[\[<\-D\]\]/g,"");template=fielddef.data.substr(0,4)=="show"?template.replace(/\[\[L\->\]\]|\[\[<\-L\]\]/g,
111
+ ""):template.replace(/\[\[L\->\]\][^]*\[\[<\-L\]\]/g,"");template=fielddef.group.substr(0,4)=="show"?template.replace(/\[\[G\->\]\]|\[\[<\-G\]\]/g,""):template.replace(/\[\[G\->\]\][^]*\[\[<\-G\]\]/g,"");template=fielddef.format.substr(0,4)=="show"?template.replace(/\[\[F\->\]\]|\[\[<\-F\]\]/g,""):template.replace(/\[\[F\->\]\][^]*\[\[<\-F\]\]/g,"");return template}
112
+ function wfu_userdata_remove_field(obj){var line=obj.parentNode;var container=line.parentNode;var first=null;for(var i=0;i<container.childNodes.length;i++)if(container.childNodes[i].nodeType===1){first=container.childNodes[i];break}if(line!=first){line.parentNode.removeChild(line);for(var i=0;i<first.childNodes.length;i++)if(first.childNodes[i].nodeType===1){wfu_update_userfield_value({target:first.childNodes[i]});break}}}
113
+ function wfu_formdata_remove_field(key){var key_parts=key.split("_");var attribute=key_parts[0];var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");if(containers.length<2)return;var container=document.getElementById("wfu_attribute_"+attribute);var line_container=document.getElementById("wfu_formfield_"+key+"_container");var line_container_index=0;for(var i=0;i<containers.length;i++)if(containers[i]==line_container){line_container_index=i+1;break}container.removeChild(line_container);
114
+ containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");if(line_container_index>containers.length)line_container_index=containers.length;line_container=containers[line_container_index-1];var prev_key=line_container.id.replace(/^wfu_formfield_/,"").replace(/_container$/,"");wfu_formdata_update_buttons(prev_key);wfu_update_formfield_value({target:line_container})}
115
+ function wfu_formdata_move_field(key,direction){var key_parts=key.split("_");var attribute=key_parts[0];var all_attributes=document.querySelector("div#wfu_attribute_"+attribute+" .wfu_formdata_all_attributes").value.split(",");var attr_occur_index=all_attributes.indexOf(attribute)+1;var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");var container=document.getElementById("wfu_attribute_"+attribute);var line_container=document.getElementById("wfu_formfield_"+
116
+ key+"_container");var line_container_index=0;for(var i=0;i<containers.length;i++)if(containers[i]==line_container){line_container_index=i+1;break}if(direction=="up"&&attr_occur_index==1&&line_container_index==1||direction=="down"&&attr_occur_index==all_attributes.length&&line_container_index==containers.length)return;var field=wfu_formdata_get_field_props(key);var other_attribute=attribute;var other_line_container=line_container;if(direction=="up")if(line_container_index>1)other_line_container=containers[line_container_index-
117
+ 2];else{other_attribute=all_attributes[attr_occur_index-2];var other_containers=document.querySelectorAll("div#wfu_attribute_"+other_attribute+" .wfu_formdata_line_container");other_line_container=other_containers[other_containers.length-1]}else if(line_container_index<containers.length)other_line_container=containers[line_container_index];else{other_attribute=all_attributes[attr_occur_index];var other_containers=document.querySelectorAll("div#wfu_attribute_"+other_attribute+" .wfu_formdata_line_container");
118
+ other_line_container=other_containers[0]}var other_key=other_line_container.id.replace(/^wfu_formfield_/,"").replace(/_container$/,"");if(other_attribute==attribute)if(direction=="up")container.insertBefore(line_container,other_line_container);else container.insertBefore(other_line_container,line_container);else{var other_field=wfu_formdata_get_field_props(other_key);var template=wfu_formdata_prepare_template(other_attribute,field,other_key);other_line_container.innerHTML=template;var formfield_elements=
119
+ document.querySelectorAll("div#wfu_formfield_"+other_key+'_container input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],wfu_update_formfield_value);template=wfu_formdata_prepare_template(attribute,other_field,key);line_container.innerHTML=template;formfield_elements=document.querySelectorAll("div#wfu_formfield_"+key+'_container input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],
120
+ wfu_update_formfield_value)}wfu_formdata_update_buttons(key);wfu_formdata_update_buttons(other_key);wfu_update_formfield_value({target:line_container});if(other_attribute!=attribute)wfu_update_formfield_value({target:other_line_container})}
121
+ function wfu_formdata_update_buttons(key){var key_parts=key.split("_");var attribute=key_parts[0];var all_attributes=document.querySelector("div#wfu_attribute_"+attribute+" .wfu_formdata_all_attributes").value.split(",");var attr_occur_index=all_attributes.indexOf(attribute)+1;var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");var line_container=document.getElementById("wfu_formfield_"+key+"_container");var line_container_index=0;for(var i=0;i<
122
+ containers.length;i++)if(containers[i]==line_container){line_container_index=i+1;break}var up_element=document.querySelector("div#wfu_formfield_"+key+"_container .wfu_formdata_action.wfu_formdata_action_up");var down_element=document.querySelector("div#wfu_formfield_"+key+"_container .wfu_formdata_action.wfu_formdata_action_down");var remove_elements=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_action_remove");up_element.className="wfu_formdata_action wfu_formdata_action_up"+
123
+ (attr_occur_index==1&&line_container_index==1?" wfu_formdata_action_disabled":"");down_element.className="wfu_formdata_action wfu_formdata_action_down"+(attr_occur_index==all_attributes.length&&line_container_index==containers.length?" wfu_formdata_action_disabled":"");for(var i=0;i<remove_elements.length;i++)remove_elements[i].className="wfu_formdata_action wfu_formdata_action_remove"+(remove_elements.length>1?"":" wfu_formdata_action_disabled")}
124
+ function wfu_formdata_update_all_updown_buttons(attribute){var all_attributes=document.querySelector("div#wfu_attribute_"+attribute+" .wfu_formdata_all_attributes").value.split(",");for(var i=0;i<all_attributes.length;i++){var ii=i+1;var containers=document.querySelectorAll("div#wfu_attribute_"+all_attributes[i]+" .wfu_formdata_line_container");for(var j=0;j<containers.length;j++){var jj=j+1;var key=containers[j].id.replace(/^wfu_formfield_/,"").replace(/_container$/,"");var up_element=document.querySelector("div#wfu_formfield_"+
125
+ key+"_container .wfu_formdata_action.wfu_formdata_action_up");var down_element=document.querySelector("div#wfu_formfield_"+key+"_container .wfu_formdata_action.wfu_formdata_action_down");up_element.className="wfu_formdata_action wfu_formdata_action_up"+(ii==1&&jj==1?" wfu_formdata_action_disabled":"");down_element.className="wfu_formdata_action wfu_formdata_action_down"+(ii==all_attributes.length&&jj==containers.length?" wfu_formdata_action_disabled":"")}}}
126
+ function wfu_generate_shortcode(){var shortcode_tag=document.getElementById("wfu_shortcode_tag").value;var defaults=document.getElementById("wfu_attribute_defaults");var values=document.getElementById("wfu_attribute_values");var item;var attribute="";var value="";var shortcode_full="["+shortcode_tag;var shortcode="";for(var i=0;i<defaults.childNodes.length;i++){item=defaults.childNodes[i];if(item.nodeType===1){attribute=item.id.replace("wfu_attribute_default_","");value=document.getElementById("wfu_attribute_value_"+
127
+ attribute).value;if(item.value!=value)shortcode+=" "+attribute+'="'+value+'"'}}shortcode_full+=shortcode+"]";document.getElementById("wfu_shortcode").value=shortcode_full;ShortcodeString=shortcode.substr(1);if(document.getElementById("wfu_update_shortcode"))document.getElementById("wfu_update_shortcode").disabled=wfu_plugin_encode_string(shortcode_full)==document.getElementById("wfu_shortcode_original_enc").value;if(Autosave)wfu_schedule_save_shortcode()}
128
+ function wfu_update_text_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");var val=item.value;val=val.replace(/(\r\n|\n|\r)/gm,"%n%");val=val.replace(/"/gm,"%dq%");val=val.replace(/\[/gm,"%brl%");val=val.replace(/\]/gm,"%brr%");if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode()}}
129
+ function wfu_update_date_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");var val=item.value;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode()}}
130
+ function wfu_update_stringmatch_textvalue(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");attribute=attribute.replace("_matchfield","").replace("_matchvalue","");wfu_update_stringmatch_value(attribute)}
131
+ function wfu_update_triplecolor_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");attribute=attribute.replace("_color","");attribute=attribute.replace("_bgcolor","");attribute=attribute.replace("_borcolor","");item=document.getElementById("wfu_attribute_"+attribute+"_color");var val=item.value+","+document.getElementById("wfu_attribute_"+attribute+"_bgcolor").value+","+document.getElementById("wfu_attribute_"+attribute+"_borcolor").value;if(val!==item.oldVal){item.oldVal=
132
+ val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode()}}
133
+ function wfu_update_dimension_value(e){e=e||window.event;var item=e.target;var attribute=item.name.replace("wfu_dimension_elements_","");var group=document.getElementsByName(item.name);item=group[0];var val="";var dimname="";for(var i=0;i<group.length;i++){dimname=group[i].id.replace("wfu_attribute_"+attribute+"_","");if(val!=""&&group[i].value!="")val+=", ";if(group[i].value!="")val+=dimname+":"+group[i].value}if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=
134
+ val;wfu_generate_shortcode()}}function wfu_update_ptext_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");attribute=attribute.substr(2);var singular=document.getElementById("wfu_attribute_s_"+attribute).value;var plural=document.getElementById("wfu_attribute_p_"+attribute).value;var val=singular+"/"+plural;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=val}wfu_generate_shortcode()}
135
+ function wfu_update_mchecklist_value(attribute){var value="";var mchecklist=document.getElementById("wfu_attribute_"+attribute);var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");if(checkall.checked){jQuery("#wfu_attribute_"+attribute+" input").prop("disabled",true);jQuery("#wfu_attribute_"+attribute+" input").prop("checked",true);value="all"}else{jQuery("#wfu_attribute_"+attribute+" input").prop("disabled",false);jQuery("#wfu_attribute_"+attribute+" input").each(function(){if(jQuery(this).prop("checked"))value+=
136
+ ","+jQuery(this).next().html()});value=value.substr(1)}document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}
137
+ function wfu_update_rolelist_value(attribute){var value="";var rolelist=document.getElementById("wfu_attribute_"+attribute);var guests=document.getElementById("wfu_attribute_"+attribute+"_guests");var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");if(checkall.checked){rolelist.disabled=true;value="all"}else{rolelist.disabled=false;var options=rolelist.options;for(var i=0;i<options.length;i++)if(options[i].selected){if(value!="")value+=",";value+=options[i].value}}if(guests.checked){if(value!=
138
+ "")value+=",";value+="guests"}document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}
139
+ function wfu_update_userlist_value(attribute){var value="";var userlist=document.getElementById("wfu_attribute_"+attribute);var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");var guests=document.getElementById("wfu_attribute_"+attribute+"_guests");var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");if(only_current&&only_current.checked){userlist.disabled=true;checkall.disabled=true;guests.disabled=true;value="current"}else{checkall.disabled=false;guests.disabled=
140
+ false;if(checkall.checked){userlist.disabled=true;value="all"}else{userlist.disabled=false;var options=userlist.options;for(var i=0;i<options.length;i++)if(options[i].selected){if(value!="")value+=",";value+=options[i].value}}if(guests.checked){if(value!="")value+=",";value+="guests"}}document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}
141
+ function wfu_update_postlist_value(attribute){var value="";var userlist=Array();var checkall=Array();var postlist=document.getElementById("wfu_attribute_"+attribute+"_postlist").value.split(",");for(var i=0;i<postlist.length;i++){userlist.push(document.getElementById("wfu_attribute_"+attribute+"_"+postlist[i]));checkall.push(document.getElementById("wfu_attribute_"+attribute+"_all_"+postlist[i]))}var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");if(only_current&&only_current.checked){for(var i=
142
+ 0;i<postlist.length;i++){userlist[i].disabled=true;checkall[i].disabled=true}value="current"}else{var allchecked=true;value="";for(var i=0;i<postlist.length;i++){checkall[i].disabled=false;if(checkall[i].checked){userlist[i].disabled=true;if(value!="")value+=",";value+="all"+postlist[i]}else{userlist[i].disabled=false;allchecked=false;var options=userlist[i].options;for(var j=0;j<options.length;j++)if(options[j].selected){if(value!="")value+=",";value+=options[j].value}}}if(allchecked)value="all"}document.getElementById("wfu_attribute_value_"+
143
+ attribute).value=value;wfu_generate_shortcode()}
144
+ function wfu_update_bloglist_value(attribute){var value="";var bloglist=document.getElementById("wfu_attribute_"+attribute);var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");if(only_current&&only_current.checked){bloglist.disabled=true;checkall.disabled=true;value="current"}else{checkall.disabled=false;if(checkall.checked){bloglist.disabled=true;value="all"}else{bloglist.disabled=false;var options=
145
+ bloglist.options;for(var i=0;i<options.length;i++)if(options[i].selected){if(value!="")value+=",";value+=options[i].value}}}document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}
146
+ function wfu_update_stringmatch_value(attribute){var matchfield=document.getElementById("wfu_attribute_"+attribute+"_matchfield").value;var matchcriterion=document.getElementById("wfu_attribute_"+attribute+"_matchcriterion").value;var matchvalue=document.getElementById("wfu_attribute_"+attribute+"_matchvalue").value;matchfield=matchfield.replace(";","");if(matchfield.trim()=="")document.getElementById("wfu_attribute_value_"+attribute).value="";else document.getElementById("wfu_attribute_value_"+attribute).value=
147
+ "field:"+matchfield+";criterion:"+matchcriterion+";value:"+matchvalue;wfu_generate_shortcode()}
148
+ function wfu_update_userfield_value(e){e=e||window.event;var item=e.target;var line=item.parentNode;var container=line.parentNode;var fieldval="";var fieldreq=false;var val="";for(var i=0;i<container.childNodes.length;i++){line=container.childNodes[i];if(line.tagName==="DIV"){for(var j=0;j<line.childNodes.length;j++)if(line.childNodes[j].tagName=="INPUT")if(line.childNodes[j].type=="text"){fieldval=line.childNodes[j].value;if(i==0)item=line.childNodes[j]}else if(line.childNodes[j].type=="checkbox")fieldreq=
149
+ line.childNodes[j].checked;if(val!=""&&fieldval!="")val+="/";if(fieldval!=""&&fieldreq)val+="*";if(fieldval!="")val+=fieldval}}if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_userdatalabel").value=val;wfu_generate_shortcode();wfu_update_formfield_variables()}}
150
+ function wfu_update_ftpinfobase_value(e){e=e||window.event;var item=e.target;var attribute=item.id.replace("wfu_attribute_","");var val=item.value;item.freezetool=true;var ftpinfo=wfu_decode_ftpinfo(val);var ftpinfo_username=document.getElementById("ftpinfo_username");var ftpinfo_password=document.getElementById("ftpinfo_password");var ftpinfo_domain=document.getElementById("ftpinfo_domain");var ftpinfo_port=document.getElementById("ftpinfo_port");var ftpinfo_sftp=document.getElementById("ftpinfo_sftp");
151
+ if(ftpinfo.error){item.classList.add("ftpinfo_error");ftpinfo_username.classList.add("ftpinfo_error");ftpinfo_password.classList.add("ftpinfo_error");ftpinfo_domain.classList.add("ftpinfo_error");ftpinfo_port.classList.add("ftpinfo_error");ftpinfo_sftp.classList.add("ftpinfo_error")}else{item.classList.remove("ftpinfo_error");ftpinfo_username.classList.remove("ftpinfo_error");ftpinfo_password.classList.remove("ftpinfo_error");ftpinfo_domain.classList.remove("ftpinfo_error");ftpinfo_port.classList.remove("ftpinfo_error");
152
+ ftpinfo_sftp.classList.remove("ftpinfo_error")}ftpinfo_username.value=ftpinfo.data.username;ftpinfo_password.value=ftpinfo.data.password;ftpinfo_domain.value=ftpinfo.data.ftpdomain;ftpinfo_port.value=ftpinfo.data.port;ftpinfo_sftp.checked=ftpinfo.data.sftp;item.freezetool=false;if(val!==item.oldVal){item.oldVal=val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode()}}
153
+ function wfu_update_ftpinfotool_value(e){var item=document.querySelector(".ftpinfo_btn").previousElementSibling;if(!item.freezetool){var attribute=item.id.replace("wfu_attribute_","");var ftpinfo_username=document.getElementById("ftpinfo_username").value;var ftpinfo_password=document.getElementById("ftpinfo_password").value;var ftpinfo_domain=document.getElementById("ftpinfo_domain").value;var ftpinfo_port=document.getElementById("ftpinfo_port").value;var ftpinfo_sftp=document.getElementById("ftpinfo_sftp").checked;
154
+ if(ftpinfo_sftp)ftpinfo_port="s"+ftpinfo_port;var ftpdata=ftpinfo_username.replace(/:/g,"\\\\:").replace(/@/g,"\\\\@");if(ftpinfo_password!="")ftpdata+=":"+ftpinfo_password.replace(/:/g,"\\\\:").replace(/@/g,"\\\\@");ftpdata+="@"+ftpinfo_domain;if(ftpinfo_port!="")ftpdata+=":"+ftpinfo_port;item.value=ftpdata;wfu_update_ftpinfobase_value({target:item})}}
155
+ function wfu_update_formfield_value(e){e=e||window.event;var item=e.target;var attribute=item.id.match(/^wfu_formfield_(.*?)_/)[1];var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");var val="";for(var i=0;i<containers.length;i++){var part="";var ind=containers[i].id.match(/^wfu_formfield_.*?_(.*?)_/)[1];var key=attribute+"_"+ind;var label=document.getElementById("wfu_formfield_"+key+"_label").value;if(label.trim()!=""){part=label.trim();var type=
156
+ document.getElementById("wfu_formfield_"+key+"_type").value;var typeprops=window["wfu_attribute_"+attribute+"_typeprops"];part+="|t:"+type;if(typeprops[type].labelposition.substr(0,4)=="show")part+="|s:"+document.getElementById("wfu_formfield_"+key+"_labelposition").value;if(typeprops[type].required.substr(0,4)=="show")part+="|r:"+(document.getElementById("wfu_formfield_"+key+"_required").checked?"1":"0");if(typeprops[type].donotautocomplete.substr(0,4)=="show")part+="|a:"+(document.getElementById("wfu_formfield_"+
157
+ key+"_donotautocomplete").checked?"1":"0");if(typeprops[type].validate.substr(0,4)=="show")part+="|v:"+(document.getElementById("wfu_formfield_"+key+"_validate").checked?"1":"0");if(typeprops[type].typehook.substr(0,4)=="show")part+="|h:"+(document.getElementById("wfu_formfield_"+key+"_typehook").checked?"1":"0");if(typeprops[type].hintposition.substr(0,4)=="show")part+="|p:"+document.getElementById("wfu_formfield_"+key+"_hintposition").value;if(typeprops[type]["default"].substr(0,4)=="show")part+=
158
+ "|d:"+document.getElementById("wfu_formfield_"+key+"_default").value;if(typeprops[type].data.substr(0,4)=="show")part+="|l:"+document.getElementById("wfu_formfield_"+key+"_data").value;if(typeprops[type].group.substr(0,4)=="show")part+="|g:"+document.getElementById("wfu_formfield_"+key+"_group").value;if(typeprops[type].format.substr(0,4)=="show")part+="|f:"+document.getElementById("wfu_formfield_"+key+"_format").value}if(part!=""){if(val!="")val+="/";val+=part}}if(val!==item.oldVal){item.oldVal=
159
+ val;document.getElementById("wfu_attribute_value_"+attribute).value=val;wfu_generate_shortcode();wfu_update_formfield_variables()}}
160
+ function wfu_update_formfield_variables(){var userdata=document.getElementById("wfu_attribute_value_userdatalabel");if(!userdata)return;var shadows=document.querySelectorAll("#wfu_wrapper div.wfu_shadow_userdata");var selects=document.getElementsByName("wfu_formfield_select");for(var i=0;i<selects.length;i++)selects[i].style.display="none";if(shadows.length==0)return;if(shadows[0].style.display=="block")return;var options_str='<option style="display:none;">%userdataXXX%</option>';var userfields=userdata.value.replace(/\//g,
161
+ "[/]").replace(/\(.*\)/,function(m){return m.replace(/\[\/\]/g,"/")}).split("[/]");var ind=2;while(document.getElementById("wfu_attribute_userdatalabel"+ind)){var userfields2=document.getElementById("wfu_attribute_value_userdatalabel"+ind).value.replace(/\//g,"[/]").replace(/\(.*\)/,function(m){return m.replace(/\[\/\]/g,"/")}).split("[/]");userfields=userfields.concat(userfields2);ind++}var field="";var pos=0;ind=1;for(var i=0;i<userfields.length;i++){field=userfields[i];if(field[0]=="*")field=field.substr(1);
162
+ pos=field.indexOf("|");if(pos>-1)field=field.substr(0,pos);if(field.trim()!=""){options_str+='<option value="%userdata'+ind+'%">'+ind+": "+field.trim()+"</option>";ind++}}for(var i=0;i<selects.length;i++){selects[i].innerHTML=options_str;selects[i].style.display="inline-block"}}
163
+ function wfu_attach_element_handlers(item,handler){var elem_events=["DOMAttrModified","textInput","input","change","keypress","paste","focus","propertychange"];for(var i=0;i<elem_events.length;i++)wfu_addEventHandler(item,elem_events[i],handler)}
164
+ function wfu_Attach_Admin_Events(autosave_shortcode){Autosave=autosave_shortcode;wfu_generate_shortcode();wfu_update_formfield_variables();wfu_Attach_Admin_DragDrop_Events();var text_elements=document.getElementsByName("wfu_text_elements");for(var i=0;i<text_elements.length;i++)wfu_attach_element_handlers(text_elements[i],wfu_update_text_value);var ptext_elements=document.getElementsByName("wfu_ptext_elements");for(var i=0;i<ptext_elements.length;i++)wfu_attach_element_handlers(ptext_elements[i],
165
+ wfu_update_ptext_value);var stringmatch_elements=document.getElementsByName("wfu_stringmatch_elements");for(var i=0;i<stringmatch_elements.length;i++)wfu_attach_element_handlers(stringmatch_elements[i],wfu_update_stringmatch_textvalue);var triplecolor_elements=document.getElementsByName("wfu_triplecolor_elements");for(var i=0;i<triplecolor_elements.length;i++)wfu_attach_element_handlers(triplecolor_elements[i],wfu_update_triplecolor_value);var dimension_elements=document.getElementsByName("wfu_dimension_elements_widths");
166
+ for(var i=0;i<dimension_elements.length;i++)wfu_attach_element_handlers(dimension_elements[i],wfu_update_dimension_value);dimension_elements=document.getElementsByName("wfu_dimension_elements_heights");for(var i=0;i<dimension_elements.length;i++)wfu_attach_element_handlers(dimension_elements[i],wfu_update_dimension_value);var userfield_elements=document.getElementsByName("wfu_userfield_elements");for(var i=0;i<userfield_elements.length;i++)wfu_attach_element_handlers(userfield_elements[i],wfu_update_userfield_value);
167
+ var formfield_elements=document.getElementsByName("wfu_formfield_elements");for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],wfu_update_formfield_value);var ftpinfobase_elements=document.getElementsByName("wfu_ftpinfobase_elements");for(var i=0;i<ftpinfobase_elements.length;i++)wfu_attach_element_handlers(ftpinfobase_elements[i],wfu_update_ftpinfobase_value);var ftpinfotool_elements=document.getElementsByName("wfu_ftpinfotool_elements");for(var i=0;i<ftpinfotool_elements.length;i++)wfu_attach_element_handlers(ftpinfotool_elements[i],
168
+ wfu_update_ftpinfotool_value);var subfolder_input_elements=document.getElementsByName("wfu_subfolder_tools_input");for(var i=0;i<subfolder_input_elements.length;i++)wfu_attach_element_handlers(subfolder_input_elements[i],wfu_subfolders_input_changed);var wfu_columnprops_elements=document.getElementsByName("wfu_columnprops_elements");for(var i=0;i<wfu_columnprops_elements.length;i++)wfu_attach_element_handlers(wfu_columnprops_elements[i],wfu_columnprops_element_changed);if(document.getElementById("wfu_shortcode_postid").value!=
169
+ "")setTimeout(function(){wfu_check_page_obsolescence()},CheckObsolescenceTimeOut);wfu_install_unload_hook()}function wfu_install_unload_hook(){window.onbeforeunload=wfu_unload_hook}function wfu_unload_hook(){if(!wfu_changes_saved())return 1}function wfu_changes_saved(){return wfu_plugin_encode_string(document.getElementById("wfu_shortcode").value)==document.getElementById("wfu_shortcode_original_enc").value}
170
+ function wfu_force_save_changes(){document.getElementById("wfu_shortcode").value=wfu_plugin_decode_string(document.getElementById("wfu_shortcode_original_enc").value)}function wfu_insert_variable(obj){var attr=obj.className.replace("wfu_variable wfu_variable_","");var inp=document.getElementById("wfu_attribute_"+attr);var pos=inp.selectionStart;var prevval=inp.value;inp.value=prevval.substr(0,pos)+obj.innerHTML+prevval.substr(pos);wfu_update_text_value({target:inp})}
171
+ function wfu_insert_userfield_variable(obj){var attr=obj.className.replace("wfu_variable wfu_variable_","");var inp=document.getElementById("wfu_attribute_"+attr);var pos=inp.selectionStart;var prevval=inp.value;inp.value=prevval.substr(0,pos)+obj.value+prevval.substr(pos);obj.value="%userdataXXX%";wfu_update_text_value({target:inp})}
172
+ function wfu_columns_itemclicked(obj,attribute){var select=obj.parentNode;if(select.tagName!="SELECT")return;for(var i=0;i<select.options.length;i++)select.options[i].selected=select.options[i]==obj;wfu_update_column_props(attribute)}
173
+ function wfu_columns_buttonaction(attribute,action){var source=document.getElementById("wfu_attribute_"+attribute+"_sourcelist");var target=document.getElementById("wfu_attribute_"+attribute);if(action=="add")for(var i=0;i<source.options.length;i++){if(source.options[i].selected||source.options[i].className=="wfu_columns_item_required"){var found=false;var sou=source.options[i].value.replace(/:.*/,"");for(var j=0;j<target.options.length;j++){var tar=target.options[j].value.replace(/:.*/,"");if(tar==
174
+ sou){found=true;break}}if(!found){var parts=source.options[i].value.match(/(.*?):(.*?)\/(.*)/);var item_name=parts[1];var sorttype=item_name=="custom"?"+-"+(parts[2]==""?"s":parts[2]):parts[2]!=""?"-+"+parts[2]:"";var title=parts[3];if(item_name=="custom")item_name="custom1";var opt=document.createElement("OPTION");opt.value=item_name+":"+sorttype+"/"+source.options[i].innerHTML+"/"+title;opt.innerHTML=source.options[i].innerHTML+(title!=""&&title!=source.options[i].innerHTML?" ("+title+")":"");opt.className=
175
+ source.options[i].className;opt.onclick=source.options[i].onclick;target.appendChild(opt);target.selectedIndex=target.options.length-1}}}else if(action=="del"){var i=0;while(i<target.options.length)if(target.options[i].selected&&target.options[i].className!="wfu_columns_item_required")target.options.remove(i);else i++}else if(action=="up"||action=="down"){var ind=-1;for(var i=0;i<target.options.length;i++)if(target.options[i].selected&&ind==-1)ind=i;else if(target.options[i].selected&&ind>-1)target.options[i].selected=
176
+ false;if(action=="up"&&ind>0)target.insertBefore(target.options[ind],target.options[ind-1]);else if(action=="down"&&ind<target.options.length-1)target.insertBefore(target.options[ind+1],target.options[ind])}wfu_update_column_props(attribute);wfu_update_columns(attribute)}
177
+ function wfu_update_column_props(attribute){var target=document.getElementById("wfu_attribute_"+attribute);var props_table=document.getElementById("wfu_attribute_"+attribute+"_columnprops_container");var props_title=document.getElementById("wfu_attribute_"+attribute+"_columnprops_title");var props_title_label=document.getElementById("wfu_attribute_"+attribute+"_columnprops_title_label");var props_id=document.getElementById("wfu_attribute_"+attribute+"_columnprops_id");var props_id_label=document.getElementById("wfu_attribute_"+
178
+ attribute+"_columnprops_id_label");var props_sort=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sort");var props_sort_label=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sort_label");var props_sorttype=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sorttype");var props_sorttype_label=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sorttype_label");var index=target.selectedIndex;if(props_sorttype.options[0].value=="")props_sorttype.options.remove(0);
179
+ if(index==-1){props_table.className="wfu_columnprops_container wfu_columnprops_container_disabled";props_title.value="";props_title.disabled=true;props_id.value="";props_id.disabled=true;props_sort.checked=false;props_sort.disabled=true;props_sorttype.selectedIndex=-1;props_sorttype.disabled=true}else{var parts=target.options[index].value.match(/(.*?):(.*?)\/(.*?)\/(.*)/);var item_name=parts[1];var fieldid_enabled=item_name.substr(0,6)=="custom";var fieldid_value=fieldid_enabled?item_name.substr(6):
180
+ "";var sortable_enabled=parts[2]!="";var sortable=sortable_enabled&&parts[2].substr(1,1)=="+";var sorttype_enabled=sortable&&parts[2].substr(0,1)=="+";var sorttype=sortable?parts[2].substr(2):"";var title=parts[4];props_table.className="wfu_columnprops_container";props_title.value=title;props_title.disabled=false;props_id_label.className=fieldid_enabled?"":"wfu_columnprops_label_disabled";props_id.value=fieldid_value;props_id.disabled=!fieldid_enabled;props_sort_label.className=sortable_enabled?"":
181
+ "wfu_columnprops_label_disabled";props_sort.checked=sortable;props_sort.disabled=!sortable_enabled;props_sorttype_label.className=sorttype_enabled?"":"wfu_columnprops_label_disabled";props_sorttype.value=sorttype;props_sorttype.disabled=!sorttype_enabled}}
182
+ function wfu_columnprops_element_changed(e){e=e||window.event;var item=e.target;var attribute=item.id.match(/^wfu_attribute_(.*?)_columnprops_/)[1];var target=document.getElementById("wfu_attribute_"+attribute);var props_title=document.getElementById("wfu_attribute_"+attribute+"_columnprops_title");var props_id=document.getElementById("wfu_attribute_"+attribute+"_columnprops_id");var props_sort=document.getElementById("wfu_attribute_"+attribute+"_columnprops_sort");var props_sorttype=document.getElementById("wfu_attribute_"+
183
+ attribute+"_columnprops_sorttype");var index=target.selectedIndex;if(index==-1)return;var parts=target.options[index].value.match(/(.*?):(.*?)\/(.*?)\/(.*)/);var item_name=parts[1];var flat_name=item_name.substr(0,6)=="custom"?"custom":item_name;var fieldid_enabled=flat_name=="custom";var fieldid_value=fieldid_enabled?parseInt(props_id.value)>=1?props_id.value:"1":"";var sort=parts[2]!=""?parts[2].substr(0,1)+(props_sort.checked?"+":"-")+(props_sorttype.value!=""?props_sorttype.value:parts[2].substr(2)!=
184
+ ""?parts[2].substr(2):"s"):"";var label=parts[3];var title=props_title.value!=""?props_title.value:label;target.options[index].value=flat_name+fieldid_value+":"+sort+"/"+label+"/"+title;target.options[index].innerHTML=label+(title!=label?" ("+title+")":"");wfu_update_column_props(attribute);wfu_update_columns(attribute)}
185
+ function wfu_update_columns(attribute){var target=document.getElementById("wfu_attribute_"+attribute);var columns="";for(var i=0;i<target.options.length;i++){var parts=target.options[i].value.match(/(.*?):(.*?)\/(.*?)\/(.*)/);var col=parts[1]+":"+(parts[2].substr(1,1)=="+"?parts[2].substr(2):"")+"/"+parts[4];if(columns!="")columns+=",";columns+=col}document.getElementById("wfu_attribute_value_"+attribute).value=columns;wfu_generate_shortcode()}
186
+ function wfu_GetHttpRequestObject(){var xhr=null;try{xhr=new XMLHttpRequest}catch(e$0){try{xhr=new ActiveXObject("Msxml2.XMLHTTP")}catch(e2){try{xhr=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}}}if(xhr==null&&window.createRequest)try{xmlhttp=window.createRequest()}catch(e$1){}return xhr}
187
+ function wfu_plugin_encode_string(str){var i=0;var newstr="";var num;var hex="";for(i=0;i<str.length;i++){num=str.charCodeAt(i);if(num>=2048)num=((num&16773120|917504)<<4)+((num&4032|8192)<<2)+(num&63|128);else if(num>=128)num=((num&65472|12288)<<2)+(num&63|128);hex=num.toString(16);if(hex.length==1||hex.length==3||hex.length==5)hex="0"+hex;newstr+=hex}return newstr}
188
+ function wfu_plugin_decode_string(str){var i=0;var newstr="";var num,val;while(i<str.length){num=parseInt(str.substr(i,2),16);if(num<128)val=num;else if(num<224)val=((num&31)<<6)+(parseInt(str.substr(i+=2,2),16)&63);else val=((num&15)<<12)+((parseInt(str.substr(i+=2,2),16)&63)<<6)+(parseInt(str.substr(i+=2,2),16)&63);newstr+=String.fromCharCode(val);i+=2}return newstr}
189
+ function wfu_decode_array_from_string(str){var arr_str=wfu_plugin_decode_string(str);var arr=null;try{arr=JSON.parse(arr_str)}catch(e){}return arr}function wfu_randomString(len){var chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";var string_length=len;var randomstring="";for(var i=0;i<string_length;i++){var rnum=Math.floor(Math.random()*chars.length);randomstring+=chars.substring(rnum,rnum+1)}return randomstring}
190
+ function wfu_schedule_save_shortcode(){var d=new Date;var dt=ShortcodeNextSave-d.getTime();if(ShortcodeTimeOut!=null){clearTimeout(ShortcodeTimeOut);ShortcodeTimeOut=null}if(dt<=0)wfu_save_shortcode();else ShortcodeTimeOut=setTimeout(function(){wfu_save_shortcode()},dt)}function wfu_check_page_obsolescence(){if(PageObsolete||PageUpdating||document.getElementById("wfu_shortcode_postid").value=="")return}
191
+ function wfu_save_shortcode(){if(typeof window.fromGutenberg!="undefined"){document.getElementById("wfu_shortcode").value=wfu_plugin_decode_string(document.getElementById("wfu_shortcode_original_enc").value);window.plugin_window.wfu_save_from_editor(window.blockId);return}if(PageObsolete)return;var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;PageUpdating=true;document.getElementById("wfu_update_failed_message").style.display="none";var url=AdminParams.wfu_ajax_url;params=new Array(8);params[0]=
192
+ new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_save_shortcode";params[1]=new Array(2);params[1][0]="shortcode";params[1][1]=wfu_plugin_encode_string(ShortcodeString);params[2]=new Array(2);params[2][0]="shortcode_original";params[2][1]=document.getElementById("wfu_shortcode_original_enc").value;params[3]=new Array(2);params[3][0]="post_id";params[3][1]=document.getElementById("wfu_shortcode_postid").value;params[4]=new Array(2);params[4][0]="post_hash";params[4][1]=document.getElementById("wfu_shortcode_posthash").value;
193
+ params[5]=new Array(2);params[5][0]="shortcode_position";params[5][1]=document.getElementById("wfu_shortcode_position").value;params[6]=new Array(2);params[6][0]="shortcode_tag";params[6][1]=document.getElementById("wfu_shortcode_tag").value;params[7]=new Array(2);params[7][0]="widget_id";params[7][1]=document.getElementById("wfu_shortcode_widgetid").value;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);var d=new Date;if(Autosave)ShortcodeNextSave=
194
+ d.getTime()+5E3;else if(document.getElementById("wfu_update_shortcode"))document.getElementById("wfu_update_shortcode_wait").style.display="inline";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){PageUpdating=false;var start_text="wfu_save_shortcode:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,
195
+ pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header=="success"){if(Autosave){document.getElementById("wfu_save_label").innerHTML="saved";document.getElementById("wfu_save_label").className="wfu_save_label";document.getElementById("wfu_save_label").style.opacity=1;wfu_fadeout_element(300);ShortcodeNextSave=d.getTime()+
196
+ 1E3;if(ShortcodeTimeOut!=null)wfu_schedule_save_shortcode()}else if(document.getElementById("wfu_update_shortcode")){document.getElementById("wfu_update_shortcode_wait").style.display="none";document.getElementById("wfu_update_shortcode").disabled=true;if(window.plugin_window)window.plugin_window.location.reload(true)}if(document.getElementById("wfu_shortcode_postid").value!=""){var shortcode_tag=document.getElementById("wfu_shortcode_tag").value;document.getElementById("wfu_shortcode_original_enc").value=
197
+ wfu_plugin_encode_string("["+shortcode_tag+" "+ShortcodeString+"]");document.getElementById("wfu_shortcode_posthash").value=txt_value;setTimeout(function(){wfu_check_page_obsolescence()},CheckObsolescenceTimeOut)}}else{if(Autosave){document.getElementById("wfu_save_label").innerHTML="not saved";document.getElementById("wfu_save_label").className="wfu_save_label_fail";document.getElementById("wfu_save_label").style.opacity=1;wfu_fadeout_element(300)}if(txt_header=="fail")if(txt_value=="post_modified"){PageObsolete=
198
+ true;if(document.getElementById("wfu_update_shortcode"))document.getElementById("wfu_update_shortcode").disabled=true;document.getElementById("wfu_update_rejected_message").style.display="block"}else document.getElementById("wfu_update_failed_message").style.display="block"}}};xhr.send(parameters)}function wfu_adjust_opacity(opacity){document.getElementById("wfu_save_label").style.opacity=opacity}
199
+ function wfu_fadeout_element(interval){var reps=20;var op=0;for(var i=0;i<reps;i++){op=1-i/reps;setTimeout('wfu_adjust_opacity("'+op.toString()+'")',i*interval/reps)}setTimeout('wfu_adjust_opacity("0.0")',i*interval/reps)}
200
+ function wfu_apply_value(attribute,type,value){if(type=="onoff"){document.getElementById("wfu_attribute_"+attribute).className="wfu_onoff_container_"+(value!="true"?"on":"off");wfu_admin_onoff_clicked(attribute)}else if(type=="text"||type=="ltext"||type=="integer"||type=="float"||type=="mtext"||type=="color"){var item=document.getElementById("wfu_attribute_"+attribute);value=value.replace(/%n%/gm,"\n");value=value.replace(/%dq%/gm,'"');value=value.replace(/%brl%/gm,"[");value=value.replace(/%brr%/gm,
201
+ "]");if(type=="color"){var rgb=colourNameToHex(value);if(!rgb)rgb=value;jQuery("#wfu_attribute_"+attribute).wpColorPicker("color",rgb)}item.value=value;wfu_update_text_value({target:item})}else if(type=="date"){var item=document.getElementById("wfu_attribute_"+attribute);item.value=value;wfu_update_date_value({target:item})}else if(type=="placements"){wfu_admin_recreate_placements_panel(value);document.getElementById("wfu_attribute_value_placements").value=value;wfu_generate_shortcode()}else if(type==
202
+ "radio"){var radios=document.getElementsByName("wfu_radioattribute_"+attribute);for(var i=0;i<radios.length;i++)radios[i].checked=radios[i].value==value||"*"+radios[i].value==value;wfu_admin_radio_clicked(attribute)}else if(type=="ptext"){value=value.replace(/%n%/gm,"\n");value=value.replace(/%dq%/gm,'"');value=value.replace(/%brl%/gm,"[");value=value.replace(/%brr%/gm,"]");var parts=value.split("/");var singular=parts.length<1?"":parts[0];var plural=parts.length<2?singular:parts[1];var item1=document.getElementById("wfu_attribute_s_"+
203
+ attribute);item1.value=singular;var item2=document.getElementById("wfu_attribute_p_"+attribute);item2.value=plural;wfu_update_ptext_value({target:item1});wfu_update_ptext_value({target:item2})}else if(type=="mchecklist"){value=value.toLowerCase();if(value=="all")document.getElementById("wfu_attribute_"+attribute+"_all").checked=true;else{document.getElementById("wfu_attribute_"+attribute+"_all").checked=false;var items=value.split(",");for(var i=0;i<items.length;i++)items[i]=items[i].trim();jQuery("#wfu_attribute_"+
204
+ attribute+" input").each(function(){jQuery(this).prop("checked",items.indexOf(jQuery(this).next().html())>-1)})}wfu_update_mchecklist_value(attribute)}else if(type=="rolelist"){var item=document.getElementById("wfu_attribute_"+attribute);var checkall=document.getElementById("wfu_attribute_"+attribute+"_all");var default_administrator=checkall.className.indexOf("wfu_default_administrator")>-1;var roles=value.split(",");if(roles.indexOf("all")>-1){checkall.checked=true;for(var i=0;i<item.options.length;i++)item.options[i].selected=
205
+ default_administrator&&item.options[i].value=="administrator"}else{checkall.checked=false;for(var i=0;i<roles.length;i++)roles[i]=roles[i].trim();for(var i=0;i<item.options.length;i++)item.options[i].selected=roles.indexOf(item.options[i].value)>-1}document.getElementById("wfu_attribute_"+attribute+"_guests").checked=roles.indexOf("guests")>-1;wfu_update_rolelist_value(attribute)}else if(type=="userlist"){var item=document.getElementById("wfu_attribute_"+attribute);var checkall=document.getElementById("wfu_attribute_"+
206
+ attribute+"_all");var default_0=checkall.className.indexOf("wfu_default_0")>-1;var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");if(only_current&&value=="current"){only_current.checked=true;checkall.checked=false;document.getElementById("wfu_attribute_"+attribute+"_guests").checked=false;for(var i=0;i<item.options.length;i++)item.options[i].selected=default_0&&i<1}else{if(only_current)only_current.checked=false;var users=value.split(",");if(users.indexOf("all")>-1){checkall.checked=
207
+ true;for(var i=0;i<item.options.length;i++)item.options[i].selected=default_0&&i<1}else{checkall.checked=false;for(var i=0;i<users.length;i++)users[i]=users[i].trim();for(var i=0;i<item.options.length;i++)item.options[i].selected=users.indexOf(item.options[i].value)>-1}document.getElementById("wfu_attribute_"+attribute+"_guests").checked=users.indexOf("guests")>-1}wfu_update_userlist_value(attribute)}else if(type=="postlist"){var userlist=Array();var checkall=Array();var postlist=document.getElementById("wfu_attribute_"+
208
+ attribute+"_postlist").value.split(",");for(var i=0;i<postlist.length;i++){userlist.push(document.getElementById("wfu_attribute_"+attribute+"_"+postlist[i]));checkall.push(document.getElementById("wfu_attribute_"+attribute+"_all_"+postlist[i]))}var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");if(only_current&&value=="current"){only_current.checked=true;for(var i=0;i<postlist.length;i++){checkall[i].checked=false;for(var j=0;j<userlist[i].options.length;j++)userlist[i].options[j].selected=
209
+ false}}else{if(only_current)only_current.checked=false;var ids=value.split(",");for(var i=0;i<postlist.length;i++){if(value=="all"||ids.indexOf("all"+postlist[i])>-1)checkall[i].checked=true;for(var j=0;j<userlist[i].options.length;j++)userlist[i].options[j].selected=ids.indexOf(userlist[i].options[j].value)>-1}}wfu_update_postlist_value(attribute)}else if(type=="bloglist"){var only_current=document.getElementById("wfu_attribute_"+attribute+"_current");if(only_current&&value=="current"){only_current.checked=
210
+ true;document.getElementById("wfu_attribute_"+attribute+"_all").checked=false;var item=document.getElementById("wfu_attribute_"+attribute);for(var i=0;i<item.options.length;i++)item.options[i].selected=false}else{if(only_current)only_current.checked=false;var blogs=value.split(",");if(value=="all")document.getElementById("wfu_attribute_"+attribute+"_all").checked=true;else{document.getElementById("wfu_attribute_"+attribute+"_all").checked=false;for(var i=0;i<blogs.length;i++)blogs[i]=blogs[i].trim();
211
+ var item=document.getElementById("wfu_attribute_"+attribute);for(var i=0;i<item.options.length;i++)item.options[i].selected=blogs.indexOf(item.options[i].value)>-1}}wfu_update_bloglist_value(attribute)}else if(type=="stringmatch"){var matchfield="";var matchcriterion="equal to";var matchvalue="";var matches=value.match(/^field:(.*?);\s*criterion:(.*?)\s*;\s*value:(.*)$/);if(matches&&matches.length==4){matchfield=matches[1];matchcriterion=matches[2];matchvalue=matches[3]}document.getElementById("wfu_attribute_"+
212
+ attribute+"_matchfield").value=matchfield;document.getElementById("wfu_attribute_"+attribute+"_matchcriterion").value=matchcriterion;document.getElementById("wfu_attribute_"+attribute+"_matchvalue").value=matchvalue;wfu_update_stringmatch_value(attribute)}else if(type=="columns"){var source=document.getElementById("wfu_attribute_"+attribute+"_sourcelist");var target=document.getElementById("wfu_attribute_"+attribute);target.innerHTML="";var columns_flat=value.replace(/(:|\/).*?(,|$)/g,"$2").split(",");
213
+ for(var i=0;i<source.options.length;i++){var parts=source.options[i].value.match(/(.*?):(.*?)\/(.*)/);var item_name=parts[1];if(source.options[i].className=="wfu_columns_item_required"&&columns_flat.indexOf(item_name)==-1){var sorttype=item_name=="custom"?"+-"+(parts[2]==""?"s":parts[2]):parts[2]!=""?"-+"+parts[2]:"";var title=parts[3];if(item_name=="custom")item_name="custom1";var opt=document.createElement("OPTION");opt.value=item_name+":"+sorttype+"/"+source.options[i].innerHTML+"/"+title;opt.innerHTML=
214
+ source.options[i].innerHTML+(title!=""&&title!=source.options[i].innerHTML?" ("+title+")":"");opt.className=source.options[i].className;opt.onclick=source.options[i].onclick;target.appendChild(opt)}}var columns=value.split(",");for(var i=0;i<columns.length;i++){var item_parts=columns[i].split("/",2);var item_name=item_parts[0];var item_title="";if(item_parts.length>1)item_title=item_parts[1];item_parts=item_name.split(":",2);item_name=item_parts[0];var flat_name=item_name.replace(/custom[0-9]+$/,
215
+ "custom");var ind=-1;for(var j=0;j<source.options.length;j++){var sou=source.options[j].value.replace(/:.*/,"");if(sou==flat_name){ind=j;break}}var already_exists=false;for(var j=0;j<target.options.length;j++){var tar=target.options[j].value.replace(/:.*/,"");if(tar==item_name){already_exists=true;break}}if(item_name!="custom"&&ind>-1&&!already_exists){var parts=source.options[ind].value.match(/(.*?):(.*?)\/(.*)/);var sortable=flat_name=="custom"||parts[2]!="";var sorttype=parts[2];var label=source.options[ind].innerHTML;
216
+ var title=parts[3];var item_sort="";if(item_parts.length==1)item_sort=flat_name=="custom"?"+-s":sortable?"-+"+sorttype:"";else if(flat_name=="custom")item_sort="+"+(item_parts[1]==""?"-s":"+"+item_parts[1]);else item_sort=sortable?"-"+(item_parts[1]==""?"-":"+")+sorttype:"";if(item_title=="")item_title=title;var opt=document.createElement("OPTION");opt.value=item_name+":"+item_sort+"/"+label+"/"+item_title;opt.innerHTML=label+(title!=label?" ("+title+")":"");opt.className=source.options[ind].className;
217
+ opt.onclick=source.options[i].onclick;target.appendChild(opt)}}wfu_update_column_props(attribute);wfu_update_columns(attribute)}else if(type=="dimensions"){var dims=value.split(",");var details,nam,val,item;var group=document.getElementsByName("wfu_dimension_elements_"+attribute);for(var i=0;i<group.length;i++)group[i].value="";for(var i=0;i<dims.length;i++){details=dims[i].split(":",2);nam=details.length<1?"":details[0];val=details.length<2?nam:details[1];item=document.getElementById("wfu_attribute_"+
218
+ attribute+"_"+nam.trim());if(item)item.value=val.trim()}item=group[0];wfu_update_dimension_value({target:item})}else if(type=="userfields"){var fields_arr=value.replace(/\//g,"[/]").replace(/\(.*\)/,function(m){return m.replace(/\[\/\]/g,"/")}).split("[/]");var is_req;var fields=Array();for(var i=0;i<fields_arr.length;i++){is_req=fields_arr[i].substr(0,1)=="*";if(is_req)fields_arr[i]=fields_arr[i].substr(1);if(fields_arr[i]!="")fields.push({name:fields_arr[i],required:is_req})}var container=document.getElementById("wfu_attribute_"+
219
+ attribute);var first=null;var remove_array=Array();for(var i=0;i<container.childNodes.length;i++)if(container.childNodes[i].nodeType===1)if(first==null)first=container.childNodes[i];else remove_array.push(container.childNodes[i]);for(var i=0;i<remove_array.length;i++)container.removeChild(remove_array[i]);wfu_userdata_edit_field(first,"",false);var newline;var prevline=first;for(var i=0;i<fields.length;i++)if(i==0)wfu_userdata_edit_field(first,fields[i].name,fields[i].required);else{newline=prevline.cloneNode(true);
220
+ wfu_userdata_edit_field(newline,fields[i].name,fields[i].required);container.insertBefore(newline,prevline.nextSibling);prevline=newline}var item;for(var i=0;i<first.childNodes.length;i++){item=first.childNodes[i];if(item.tagName=="INPUT")break}wfu_update_userfield_value({target:item})}else if(type=="formfields"){var fields=Array();var fielddefs=window["wfu_attribute_"+attribute+"_typeprops"];var fielddef_array=fielddefs[0].split(",");var defaults={};for(var i=0;i<fielddef_array.length;i++){var fielddef=
221
+ fielddefs[fielddef_array[i]];var def={};def.type=fielddef_array[i];def.label=fielddef.label;def.labelposition=fielddef.labelposition.substr(5);def.required=fielddef.required.substr(5)=="true";def.donotautocomplete=fielddef.donotautocomplete.substr(5)=="true";def.validate=fielddef.validate.substr(5)=="true";def.typehook=fielddef.typehook.substr(5)=="true";def.hintposition=fielddef.hintposition.substr(5);def["default"]=fielddef["default"].substr(5);def.data=fielddef.data.substr(5);def.group=fielddef.group.substr(5);
222
+ def.format=fielddef.format.substr(5);defaults[fielddef_array[i]]=def}var fields_arr=value.replace(/\//g,"[/]").replace(/\(.*\)/,function(m){return m.replace(/\[\/\]/g,"/")}).split("[/]");for(var i=0;i<fields_arr.length;i++){var field_raw=fields_arr[i].trim();var fieldprops={};for(prop in defaults["text"])fieldprops[prop]=defaults["text"][prop];if(field_raw.substr(0,1)=="*"){fieldprops.required=true;field_raw=field_raw.substr(1)}var field_parts=field_raw.split("|");if(field_parts[0].trim()!=""){var type_key=
223
+ -1;var new_type="";for(var j=0;j<field_parts.length;j++){var part=field_parts[j].replace(/^\s+/gm,"");var flag=part.substr(0,2);var val=part.substr(2);if(flag=="t:"&&j>0&&fielddef_array.indexOf(val)>-1){new_type=val;type_key=j;break}}if(new_type!=""){for(prop in defaults[new_type])fieldprops[prop]=defaults[new_type][prop];field_parts.splice(type_key,1)}fieldprops.label=field_parts[0].trim();field_parts.splice(0,1);for(var j=0;j<field_parts.length;j++){var part=field_parts[j].replace(/^\s+/gm,"");
224
+ var flag=part.substr(0,2);var val=part.substr(2);if(flag=="s:")fieldprops.labelposition=val;else if(flag=="r:")fieldprops.required=val=="1";else if(flag=="a:")fieldprops.donotautocomplete=val=="1";else if(flag=="v:")fieldprops.validate=val=="1";else if(flag=="d:")fieldprops["default"]=val;else if(flag=="l:")fieldprops.data=val;else if(flag=="g:")fieldprops.group=val;else if(flag=="f:")fieldprops.format=val;else if(flag=="p:")fieldprops.hintposition=val;else if(flag=="h:")fieldprops.typehook=val==
225
+ "1"}fields.push(fieldprops)}}if(fields.length==0)fields.push(fieldprops_default);var container=document.getElementById("wfu_attribute_"+attribute);var containers=document.querySelectorAll("div#wfu_attribute_"+attribute+" .wfu_formdata_line_container");for(var i=1;i<containers.length;i++)container.removeChild(containers[i]);var new_line_container=containers[0];for(var i=0;i<fields.length;i++){var new_key=attribute+"_"+wfu_randomString(4);var template=wfu_formdata_prepare_template(attribute,fields[i],
226
+ new_key);if(i>0)new_line_container=document.createElement("DIV");new_line_container.id="wfu_formfield_"+new_key+"_container";new_line_container.className="wfu_formdata_line_container";if(i>0)container.insertBefore(new_line_container,null);new_line_container.innerHTML=template;wfu_formdata_update_buttons(new_key)}var formfield_elements=document.querySelectorAll("div#wfu_attribute_"+attribute+' input[name="wfu_formfield_elements"]');for(var i=0;i<formfield_elements.length;i++)wfu_attach_element_handlers(formfield_elements[i],
227
+ wfu_update_formfield_value);wfu_update_formfield_value({target:containers[0]})}else if(type=="color-triplet"){var colors=value.split(",");for(var i=0;i<colors.length;i++)colors[i]=colors[i].trim();if(colors.length==2)colors=[colors[0],colors[1],"#000000"];else if(colors.length==1)colors=[colors[0],"#FFFFFF","#000000"];else if(colors.length<3)colors=["#000000","#FFFFFF","#000000"];var rgb=colourNameToHex(colors[0]);if(!rgb)rgb=colors[0];jQuery("#wfu_attribute_"+attribute+"_color").wpColorPicker("color",
228
+ rgb);var item=document.getElementById("wfu_attribute_"+attribute+"_color");item.value=colors[0];rgb=colourNameToHex(colors[1]);if(!rgb)rgb=colors[1];jQuery("#wfu_attribute_"+attribute+"_bgcolor").wpColorPicker("color",rgb);document.getElementById("wfu_attribute_"+attribute+"_bgcolor").value=colors[1];rgb=colourNameToHex(colors[2]);if(!rgb)rgb=colors[2];jQuery("#wfu_attribute_"+attribute+"_borcolor").wpColorPicker("color",rgb);document.getElementById("wfu_attribute_"+attribute+"_borcolor").value=colors[2];
229
+ wfu_update_triplecolor_value({target:item})}else if(type=="ftpinfo"){var item=document.getElementById("wfu_attribute_"+attribute);item.value=value;wfu_update_text_value({target:item})}else if(type=="folderlist"){var items=wfu_parse_folderlist_js(value);var opts=document.getElementById("wfu_attribute_"+attribute).options;while(opts.length>0)opts.remove(0);var opt,subfolder,subfolder_raw,text,stars,subvalue;for(var i=0;i<items.path.length;i++){subfolder=items.path[i];if(subfolder.substr(subfolder.length,
230
+ 1)=="/")subfolder=subfolder.substr(0,subfolder.length-1);subfolder_raw=subfolder.split("/");subfolder=subfolder_raw[subfolder_raw.length-1];stars=parseInt(items.level[i]);text="";subvalue="";for(var j=0;j<stars;j++){text+="&nbsp;&nbsp;&nbsp;";subvalue+="*"}text+=items.label[i];if(items["default"][i])subvalue+="&";if(subfolder=="")subvalue+="{root}/"+items.label[i];else subvalue+=subfolder+items.label[i];opt=document.createElement("option");if(items["default"][i])opt.className="wfu_select_folders_option_default";
231
+ else opt.className="";opt.value=wfu_plugin_encode_string(subvalue);opt.innerHTML=text;opts.add(opt)}opt=document.createElement("option");opt.value="";opt.innerHTML="";opts.add(opt);var list=document.getElementById("wfu_attribute_"+attribute);list.data=wfu_decode_subfolder_list(attribute);wfu_subfolders_update_toolnav(attribute);item=list;if(value!==item.oldVal){item.oldVal=value;document.getElementById("wfu_attribute_value_"+attribute).value=value;wfu_generate_shortcode()}}}
232
+ function wfu_decode_ftpinfo(ftpdata){var ret={error:true,data:{username:"",password:"",ftpdomain:"",port:"",sftp:false}};var ftpdata_flat=ftpdata.replace(/\\\\:/g,"\\\\_").replace(/\\\\@/g,"\\\\_");var pos1=ftpdata_flat.indexOf(":");var pos2=ftpdata_flat.indexOf("@");if(pos1>-1&&pos2>-1&&pos2>pos1){ret.error=false;ret.data.username=ftpdata.substr(0,pos1).replace(/\\\\:/g,":").replace(/\\\\@/g,"@");ret.data.password=ftpdata.substr(pos1+1,pos2-pos1-1).replace(/\\\\:/g,":").replace(/\\\\@/g,"@");var ftp_host=
233
+ ftpdata.substr(pos2+1);ret.data.ftpdomain=ftp_host.replace(/:.*/,"");if(ret.data.ftpdomain.trim()=="")ret.error=true;var ftp_port=ftp_host.replace(/^[^:]*:?/,"");if(ftp_port.substr(0,1)=="s"){ret.data.sftp=true;ftp_port=ftp_port.substr(1)}ret.data.port=ftp_port}else if(pos2>-1){ret.error=false;ret.data.username=ftpdata.substr(0,pos2).replace(/\\\\:/g,":").replace(/\\\\@/g,"@");var ftp_host=ftpdata.substr(pos2+1);ret.data.ftpdomain=ftp_host.replace(/:.*/,"");if(ret.data.ftpdomain.trim()=="")ret.error=
234
+ true;var ftp_port=ftp_host.replace(/^[^:]*:?/,"");if(ftp_port.substr(0,1)=="s"){ret.data.sftp=true;ftp_port=ftp_port.substr(1)}ret.data.port=ftp_port}else if(pos1>-1){ret.error=true;ret.data.username=ftpdata.substr(0,pos1).replace(/\\\\:/g,":").replace(/\\\\@/g,"@");ret.data.password=ftpdata.substr(pos1+1).replace(/\\\\:/g,":").replace(/\\\\@/g,"@")}else{ret.error=true;ret.data.username=ftpdata.replace(/\\\\:/g,":").replace(/\\\\@/g,"@")}return ret}
235
+ function wfu_ftpinfotool_toggle(){var ftpinfobtn=document.querySelector(".ftpinfo_btn");var ftpinfotool=document.querySelector(".ftpinfo_tool");if(ftpinfotool.classList.contains("hidden")){ftpinfobtn.innerHTML="Close";ftpinfotool.classList.remove("hidden")}else{ftpinfobtn.innerHTML="Edit";ftpinfotool.classList.add("hidden")}}
236
+ function wfu_parse_folderlist_js(list){var ret=Object();ret.path=Array();ret.label=Array();ret.level=Array();ret["default"]=Array();if(list.substr(0,4)=="auto")return ret;var subfolders=list.split(",");if(subfolders.length==0)return ret;if(subfolders.length==1&&subfolders[0].trim()=="")return ret;var dir_levels=["root"];var prev_level=0;var level0_count=0;var _default=-1;var subfolder,star_count,start_spaces,is_default,subfolder_dir,subfolder_label,subfolder_path;for(var i=0;i<subfolders.length;i++){subfolder=
237
+ subfolders[i].trim();star_count=0;start_spaces="";is_default=false;while(star_count<subfolder.length)if(subfolder.substr(star_count,1)=="*"){star_count++;start_spaces+="&nbsp;&nbsp;&nbsp;"}else break;if(star_count-prev_level<=1&&(star_count>0||level0_count==0)){subfolder=subfolder.substr(star_count,subfolder.length-star_count);if(subfolder.substr(0,1)=="&"){subfolder=subfolder.substr(1);is_default=true}subfolder_items=subfolder.split("/");if(subfolder_items.length<2)subfolder_items.push("");if(subfolder_items[1]!=
238
+ ""){subfolder_dir=subfolder_items[0];subfolder_label=subfolder_items[1]}else{subfolder_dir=subfolder;subfolder_label=subfolder}if(subfolder_dir!=""){if(is_default&&_default==-1)_default=ret.path.length;else is_default=false;if(star_count==0)level0_count=1;if(dir_levels.length>star_count)dir_levels[star_count]=subfolder_dir;else dir_levels.push(subfolder_dir);subfolder_path="";for(var i_count=1;i_count<=star_count;i_count++)subfolder_path+=dir_levels[i_count]+"/";ret.path.push(subfolder_path);ret.label.push(subfolder_label);
239
+ ret.level.push(star_count);ret["default"].push(is_default);prev_level=star_count}}}return ret}
240
+ function colourNameToHex(colour){var colours={"aliceblue":"#f0f8ff","antiquewhite":"#faebd7","aqua":"#00ffff","aquamarine":"#7fffd4","azure":"#f0ffff","beige":"#f5f5dc","bisque":"#ffe4c4","black":"#000000","blanchedalmond":"#ffebcd","blue":"#0000ff","blueviolet":"#8a2be2","brown":"#a52a2a","burlywood":"#deb887","cadetblue":"#5f9ea0","chartreuse":"#7fff00","chocolate":"#d2691e","coral":"#ff7f50","cornflowerblue":"#6495ed","cornsilk":"#fff8dc","crimson":"#dc143c","cyan":"#00ffff","darkblue":"#00008b",
241
+ "darkcyan":"#008b8b","darkgoldenrod":"#b8860b","darkgray":"#a9a9a9","darkgreen":"#006400","darkkhaki":"#bdb76b","darkmagenta":"#8b008b","darkolivegreen":"#556b2f","darkorange":"#ff8c00","darkorchid":"#9932cc","darkred":"#8b0000","darksalmon":"#e9967a","darkseagreen":"#8fbc8f","darkslateblue":"#483d8b","darkslategray":"#2f4f4f","darkturquoise":"#00ced1","darkviolet":"#9400d3","deeppink":"#ff1493","deepskyblue":"#00bfff","dimgray":"#696969","dodgerblue":"#1e90ff","firebrick":"#b22222","floralwhite":"#fffaf0",
242
+ "forestgreen":"#228b22","fuchsia":"#ff00ff","gainsboro":"#dcdcdc","ghostwhite":"#f8f8ff","gold":"#ffd700","goldenrod":"#daa520","gray":"#808080","green":"#008000","greenyellow":"#adff2f","honeydew":"#f0fff0","hotpink":"#ff69b4","indianred ":"#cd5c5c","indigo ":"#4b0082","ivory":"#fffff0","khaki":"#f0e68c","lavender":"#e6e6fa","lavenderblush":"#fff0f5","lawngreen":"#7cfc00","lemonchiffon":"#fffacd","lightblue":"#add8e6","lightcoral":"#f08080","lightcyan":"#e0ffff","lightgoldenrodyellow":"#fafad2",
243
+ "lightgrey":"#d3d3d3","lightgreen":"#90ee90","lightpink":"#ffb6c1","lightsalmon":"#ffa07a","lightseagreen":"#20b2aa","lightskyblue":"#87cefa","lightslategray":"#778899","lightsteelblue":"#b0c4de","lightyellow":"#ffffe0","lime":"#00ff00","limegreen":"#32cd32","linen":"#faf0e6","magenta":"#ff00ff","maroon":"#800000","mediumaquamarine":"#66cdaa","mediumblue":"#0000cd","mediumorchid":"#ba55d3","mediumpurple":"#9370d8","mediumseagreen":"#3cb371","mediumslateblue":"#7b68ee","mediumspringgreen":"#00fa9a",
244
+ "mediumturquoise":"#48d1cc","mediumvioletred":"#c71585","midnightblue":"#191970","mintcream":"#f5fffa","mistyrose":"#ffe4e1","moccasin":"#ffe4b5","navajowhite":"#ffdead","navy":"#000080","oldlace":"#fdf5e6","olive":"#808000","olivedrab":"#6b8e23","orange":"#ffa500","orangered":"#ff4500","orchid":"#da70d6","palegoldenrod":"#eee8aa","palegreen":"#98fb98","paleturquoise":"#afeeee","palevioletred":"#d87093","papayawhip":"#ffefd5","peachpuff":"#ffdab9","peru":"#cd853f","pink":"#ffc0cb","plum":"#dda0dd",
245
+ "powderblue":"#b0e0e6","purple":"#800080","red":"#ff0000","rosybrown":"#bc8f8f","royalblue":"#4169e1","saddlebrown":"#8b4513","salmon":"#fa8072","sandybrown":"#f4a460","seagreen":"#2e8b57","seashell":"#fff5ee","sienna":"#a0522d","silver":"#c0c0c0","skyblue":"#87ceeb","slateblue":"#6a5acd","slategray":"#708090","snow":"#fffafa","springgreen":"#00ff7f","steelblue":"#4682b4","tan":"#d2b48c","teal":"#008080","thistle":"#d8bfd8","tomato":"#ff6347","turquoise":"#40e0d0","violet":"#ee82ee","wheat":"#f5deb3",
246
+ "white":"#ffffff","whitesmoke":"#f5f5f5","yellow":"#ffff00","yellowgreen":"#9acd32"};if(typeof colours[colour.toLowerCase()]!="undefined")return colours[colour.toLowerCase()];return false}function wfu_add_cookies(cookies){for(var i=0;i<cookies.length;i++){var date=new Date;date.setTime(date.getTime()+cookies[i].expires*1E3);document.cookie=cookies[i].name+"="+cookies[i].value+"; expires="+date.toUTCString()+"; path=/"}}
247
+ function wfu_download_file(filepath_enc,ii){var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var nonce="";var nonce_elem=document.getElementById("wfu_download_file_nonce");if(nonce_elem)nonce=nonce_elem.value;if(nonce=="")return;var url=AdminParams.wfu_ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_download_file_invoker";params[1]=new Array(2);params[1][0]="file";params[1][1]=filepath_enc;params[2]=new Array(2);params[2][0]="nonce";params[2][1]=
248
+ nonce;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var start_text="wfu_ajax_action_download_file_invoker:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+
249
+ start_text.length,xhr.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header.substr(0,16)=="wfu_download_id;"){var download_id=txt_header.substr(16);var container=document.getElementById("wfu_file_download_container_"+ii);var props=wfu_decode_array_from_string(txt_value);if(props){container.innerHTML=props.html;if(props.js!=""){var script=document.createElement("SCRIPT");script.type=
250
+ "text/javascript";script.text=props.js;container.appendChild(script)}setTimeout("wfu_download_file_monitor('"+filepath_enc+"', "+ii+", '"+download_id+"')",100)}}}};xhr.send(parameters)}
251
+ function wfu_download_file_monitor(filepath_enc,ii,id){var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_download_file_monitor";params[1]=new Array(2);params[1][0]="file";params[1][1]=filepath_enc;params[2]=new Array(2);params[2][0]="id";params[2][1]=id;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);
252
+ xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var start_text="wfu_ajax_action_download_file_monitor:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=
253
+ response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header!="repeat"){var container=document.getElementById("wfu_file_download_container_"+ii);container.innerHTML=""}else if(txt_header=="repeat")setTimeout("wfu_download_file_monitor('"+filepath_enc+"', "+ii+", '"+txt_value+"')",100)}};xhr.send(parameters)}
254
+ function wfu_filedetails_changed(e){var userdata_elements=document.getElementsByName("wfu_filedetails_userdata");var def,subm;var changed=false,changed2=false;for(var i=0;i<userdata_elements.length;i++){def=document.getElementById(userdata_elements[i].id.replace("wfu_filedetails_userdata_value_","wfu_filedetails_userdata_default_"));subm=document.getElementById(userdata_elements[i].id.replace("wfu_filedetails_userdata_value_","wfu_filedetails_userdata_"));subm.value=userdata_elements[i].value;if(userdata_elements[i].value!=
255
+ def.value){changed=true;break}}if(document.getElementById("wfu_filedetails_userid"))changed2=document.getElementById("wfu_filedetails_userid").value!=document.getElementById("wfu_filedetails_userid_default").value;document.getElementById("dp_filedetails_submit_fields").disabled=!changed&&!changed2}
256
+ function wfu_Attach_FileDetails_Admin_Events(){var userdata_elements=document.getElementsByName("wfu_filedetails_userdata");for(var i=0;i<userdata_elements.length;i++)wfu_attach_element_handlers(userdata_elements[i],wfu_filedetails_changed)}
257
+ function wfu_update_browserpermission_option(type,id,immediate){var users=document.getElementById("wfu_fbperm_users");var roles=document.getElementById("wfu_fbperm_roles");var view=document.getElementById("wfu_fbperm_"+type+"_"+id+"_view");var dl=document.getElementById("wfu_fbperm_"+type+"_"+id+"_dl");var edit=document.getElementById("wfu_fbperm_"+type+"_"+id+"_edit");var del=document.getElementById("wfu_fbperm_"+type+"_"+id+"_del");if(type=="role"){if(id=="0"){dl.checked=view.checked&&dl.checked;
258
+ edit.checked=view.checked&&edit.checked;del.checked=view.checked&&del.checked;dl.disabled=!view.checked;edit.disabled=!view.checked;del.disabled=!view.checked;var roles_tr=document.querySelectorAll("tr.wfu_fbperm_role_tr");for(var i=0;i<roles_tr.length;i++){var rolename=roles_tr[i].id.substr(16,roles_tr[i].id.length-20);wfu_update_browserpermission_option("role",rolename,false)}if(immediate){var props=(view.checked?"v":"")+(dl.checked?"d":"")+(edit.checked?"e":"")+(del.checked?"l":"");roles.value=
259
+ roles.value.replace(/^0\[\w*\]/,"0["+props+"]")}}else if(id!="administrator"){var row=document.getElementById("wfu_fbperm_role_"+id+"_row");var def=document.getElementById("wfu_fbperm_role_"+id+"_def");var view_def=document.getElementById("wfu_fbperm_role_0_view");var dl_def=document.getElementById("wfu_fbperm_role_0_dl");var edit_def=document.getElementById("wfu_fbperm_role_0_edit");var del_def=document.getElementById("wfu_fbperm_role_0_del");view.checked=def.checked?view_def.checked:view.checked;
260
+ row.style.fontWeight=def.checked?"":"bold";dl.checked=def.checked?dl_def.checked:view.checked&&dl.checked;edit.checked=def.checked?edit_def.checked:view.checked&&edit.checked;del.checked=def.checked?del_def.checked:view.checked&&del.checked;view.disabled=def.checked;dl.disabled=def.checked||!view.checked;edit.disabled=def.checked||!view.checked;del.disabled=def.checked||!view.checked;if(immediate){var props=def.checked?"":"D"+(view.checked?"v":"")+(dl.checked?"d":"")+(edit.checked?"e":"")+(del.checked?
261
+ "l":"");roles.value=roles.value.replace(new RegExp(","+id+"\\[\\w*\\]"),","+id+"["+props+"]")}}var users_tr=document.querySelectorAll("tr.wfu_fbperm_user_tr");for(var i=0;i<users_tr.length;i++){var username=users_tr[i].id.substr(16,users_tr[i].id.length-20);wfu_update_browserpermission_option("user",username,false)}}else if(type=="user"){var role=document.getElementById("wfu_fbperm_user_"+id+"_role");if(id=="0"){view.checked=role.checked?false:view.checked;dl.checked=role.checked?false:view.checked&&
262
+ dl.checked;edit.checked=role.checked?false:view.checked&&edit.checked;del.checked=role.checked?false:view.checked&&del.checked;view.disabled=role.checked;dl.disabled=role.checked||!view.checked;edit.disabled=role.checked||!view.checked;del.disabled=role.checked||!view.checked;view.indeterminate=role.checked;dl.indeterminate=role.checked;edit.indeterminate=role.checked;del.indeterminate=role.checked;var users_tr=document.querySelectorAll("tr.wfu_fbperm_user_tr");for(var i=0;i<users_tr.length;i++){var username=
263
+ users_tr[i].id.substr(16,users_tr[i].id.length-20);wfu_update_browserpermission_option("user",username,false)}if(immediate){var props=role.checked?"":"R"+(view.checked?"v":"")+(dl.checked?"d":"")+(edit.checked?"e":"")+(del.checked?"l":"");users.value=users.value.replace(/^0\[\w*\],?/,"");users.value="0["+props+"]"+(users.value==""?"":","+users.value)}}else{var user_roles=document.getElementById("wfu_fbperm_user_"+id+"_roles").value.split(",");if(user_roles.length==1&&user_roles[0]=="")user_roles=
264
+ Array();if(user_roles.indexOf("administrator")<0){var row=document.getElementById("wfu_fbperm_user_"+id+"_row");var def=document.getElementById("wfu_fbperm_user_"+id+"_def");var role_def=document.getElementById("wfu_fbperm_user_0_role");var view_def=document.getElementById("wfu_fbperm_user_0_view");var dl_def=document.getElementById("wfu_fbperm_user_0_dl");var edit_def=document.getElementById("wfu_fbperm_user_0_edit");var del_def=document.getElementById("wfu_fbperm_user_0_del");if(user_roles.length>
265
+ 0){var $view_from_roles=false;var $dl_from_roles=false;var $edit_from_roles=false;var $del_from_roles=false;for(var i=0;i<user_roles.length;i++){$view_from_roles=$view_from_roles||document.getElementById("wfu_fbperm_role_"+user_roles[i]+"_view").checked;$dl_from_roles=$view_from_roles&&($dl_from_roles||document.getElementById("wfu_fbperm_role_"+user_roles[i]+"_dl").checked);$edit_from_roles=$view_from_roles&&($edit_from_roles||document.getElementById("wfu_fbperm_role_"+user_roles[i]+"_edit").checked);
266
+ $del_from_roles=$view_from_roles&&($del_from_roles||document.getElementById("wfu_fbperm_role_"+user_roles[i]+"_del").checked)}}else{var $view_from_roles=document.getElementById("wfu_fbperm_role_0_view");var $dl_from_roles=document.getElementById("wfu_fbperm_role_0_dl");var $edit_from_roles=document.getElementById("wfu_fbperm_role_0_edit");var $del_from_roles=document.getElementById("wfu_fbperm_role_0_del")}row.style.fontWeight=def.checked?"":"bold";role.checked=def.checked?role_def.checked:role.checked;
267
+ view.checked=def.checked?role_def.checked?$view_from_roles:view_def.checked:role.checked?$view_from_roles:view.checked;dl.checked=def.checked?role_def.checked?$dl_from_roles:dl_def.checked:role.checked?$dl_from_roles:view.checked&&dl.checked;edit.checked=def.checked?role_def.checked?$edit_from_roles:edit_def.checked:role.checked?$edit_from_roles:view.checked&&edit.checked;del.checked=def.checked?role_def.checked?$del_from_roles:del_def.checked:role.checked?$del_from_roles:view.checked&&del.checked;
268
+ role.disabled=def.checked;view.disabled=def.checked||role.checked;dl.disabled=def.checked||role.checked||!view.checked;edit.disabled=def.checked||role.checked||!view.checked;del.disabled=def.checked||role.checked||!view.checked;if(immediate){var props=def.checked?"":"D"+(role.checked?"":"R"+(view.checked?"v":"")+(dl.checked?"d":"")+(edit.checked?"e":"")+(del.checked?"l":""));users.value=users.value.replace(new RegExp(","+id+"\\[\\w*\\]|"+id+"\\[\\w*\\],|"+id+"\\[\\w*\\]"),"");users.value+=(users.value==
269
+ ""?"":",")+id+"["+props+"]"}}}}}
270
+ function wfu_goto_historylog_page(token,go_to){var sel=document.getElementById("wfu_historylog_pages");var page=sel.selectedIndex+1;var newpage=page;if(go_to=="next")newpage=Math.min(page+1,sel.options.length);else if(go_to=="prev")newpage=Math.max(page-1,1);else if(go_to=="last")newpage=sel.options.length;else if(go_to=="first")newpage=1;else if(go_to=="sel")page=-1;if(newpage==page)return;var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);
271
+ params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_get_historylog_page";params[1]=new Array(2);params[1][0]="token";params[1][1]=token;params[2]=new Array(2);params[2][0]="page";params[2][1]=newpage;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);document.getElementById("wfu_historylog_overlay").style.display="block";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
272
+ xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){document.getElementById("wfu_historylog_overlay").style.display="none";var start_text="wfu_historylog_page_success:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);if(response!=""){var t=document.getElementById("wfu_historylog_table");t.tBodies[0].innerHTML=
273
+ wfu_plugin_decode_string(response);sel.selectedIndex=newpage-1;document.getElementById("wfu_historylog_first_disabled").style.display=newpage==1?"inline":"none";document.getElementById("wfu_historylog_prev_disabled").style.display=newpage==1?"inline":"none";document.getElementById("wfu_historylog_first").style.display=newpage==1?"none":"inline";document.getElementById("wfu_historylog_prev").style.display=newpage==1?"none":"inline";document.getElementById("wfu_historylog_last_disabled").style.display=
274
+ newpage==sel.options.length?"inline":"none";document.getElementById("wfu_historylog_next_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_historylog_last").style.display=newpage==sel.options.length?"none":"inline";document.getElementById("wfu_historylog_next").style.display=newpage==sel.options.length?"none":"inline"}}};xhr.send(parameters)}
275
+ function wfu_attach_uploadedfiles_events(){function _wfu_hightlight_property(obj){var id=obj.id.replace(/^p_([0-9]+)_[0-9]+$/,"$1");document.querySelector("tr.wfu_row-"+id+" .wfu-remarks-container").innerHTML=wfu_plugin_decode_string(obj.firstChild.value)}function _wfu_unhightlight_property(obj){var id=obj.id.replace(/^p_([0-9]+)_[0-9]+$/,"$1");obj.classList.remove("wfu-clicked");document.querySelector("tr.wfu_row-"+id+" .wfu-remarks-container").innerHTML=""}window.wfu_last_shown_remark=null;var props=
276
+ document.querySelectorAll(".wfu-properties:not(.wfu-dashicons-hidden)");for(var i=0;i<props.length;i++)if(typeof props[i].hashover=="undefined"||props[i].hashover!=true){jQuery(props[i]).hover(function(){if(window.wfu_last_shown_remark)_wfu_unhightlight_property(window.wfu_last_shown_remark);_wfu_hightlight_property(this);window.wfu_last_shown_remark=this},function(){if(window.wfu_last_shown_remark)_wfu_unhightlight_property(window.wfu_last_shown_remark);_wfu_unhightlight_property(this);window.wfu_last_shown_remark=
277
+ null});jQuery(props[i]).click(function(){if(window.wfu_last_shown_remark)_wfu_unhightlight_property(window.wfu_last_shown_remark);_wfu_hightlight_property(this);this.classList.add("wfu-clicked");window.wfu_last_shown_remark=this});this.hashover=true}}
278
+ function wfu_update_uploadedfiles_bubble(count){var bubble_container=document.querySelector("#toplevel_page_wfu_uploaded_files .update-plugins");var bubble_text=document.querySelector("#toplevel_page_wfu_uploaded_files .plugin-count");if(bubble_container&&bubble_text){bubble_container.className="update-plugins count-"+count;var text=count;if(count>99)text="99+";bubble_text.innerHTML=text}}
279
+ function wfu_goto_uploadedfiles_page(token,go_to){var sel=document.getElementById("wfu_uploadedfiles_pages");var page=sel.selectedIndex+1;var newpage=page;if(go_to=="next")newpage=Math.min(page+1,sel.options.length);else if(go_to=="prev")newpage=Math.max(page-1,1);else if(go_to=="last")newpage=sel.options.length;else if(go_to=="first")newpage=1;else if(go_to=="sel")page=-1;if(newpage==page)return;var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);
280
+ params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_get_uploadedfiles_page";params[1]=new Array(2);params[1][0]="token";params[1][1]=token;params[2]=new Array(2);params[2][0]="page";params[2][1]=newpage;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);document.getElementById("wfu_uploadedfiles_overlay").style.display="block";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
281
+ xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){document.getElementById("wfu_uploadedfiles_overlay").style.display="none";var start_text="wfu_uploadedfiles_page_success:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);if(response!=""){var t=document.getElementById("wfu_uploadedfiles_table");
282
+ var html=wfu_plugin_decode_string(response);var unread_files_count=0;var unread_files_count_raw=html.match(/wfu_uploadedfiles_unread\[(.*?)\]/);if(unread_files_count_raw&&unread_files_count_raw[1])unread_files_count=parseInt(unread_files_count_raw[1]);if(isNaN(unread_files_count))unread_files_count=0;t.tBodies[0].innerHTML=html;sel.selectedIndex=newpage-1;document.getElementById("wfu_uploadedfiles_first_disabled").style.display=newpage==1?"inline":"none";document.getElementById("wfu_uploadedfiles_prev_disabled").style.display=
283
+ newpage==1?"inline":"none";document.getElementById("wfu_uploadedfiles_first").style.display=newpage==1?"none":"inline";document.getElementById("wfu_uploadedfiles_prev").style.display=newpage==1?"none":"inline";document.getElementById("wfu_uploadedfiles_last_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_uploadedfiles_next_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_uploadedfiles_last").style.display=
284
+ newpage==sel.options.length?"none":"inline";document.getElementById("wfu_uploadedfiles_next").style.display=newpage==sel.options.length?"none":"inline";wfu_attach_uploadedfiles_events();wfu_update_uploadedfiles_bubble(unread_files_count)}}};xhr.send(parameters)}
285
+ function wfu_include_file(filepath_enc,ii){var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var nonce="";var nonce_elem=document.getElementById("wfu_include_file_nonce");if(nonce_elem)nonce=nonce_elem.value;if(nonce=="")return;var url=AdminParams.wfu_ajax_url;params=new Array(2);params[0]=new Array(3);params[0][0]="action";params[0][1]="wfu_ajax_action_include_file";params[1]=new Array(2);params[1][0]="file";params[1][1]=filepath_enc;params[2]=new Array(2);params[2][0]="nonce";params[2][1]=
286
+ nonce;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);document.getElementById("wfu_include_file_"+ii+"_a").href="javascript: void(0)";document.getElementById("wfu_include_file_"+ii+"_img").style.display="inline";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4){document.getElementById("wfu_include_file_"+ii+"_img").style.display=
287
+ "none";if(xhr.status==200){var start_text="wfu_include_file:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header=="success"){document.getElementById("wfu_file_flat_"+ii).style.display="none";
288
+ document.getElementById("wfu_file_link_"+ii).style.display="inline";document.getElementById("wfu_file_can_be_included_actions_"+ii).style.display="none";document.getElementById("wfu_file_is_included_actions_"+ii).style.display="block"}else document.getElementById("wfu_include_file_"+ii+"_a").innerHTML=document.getElementById("wfu_include_file_"+ii+"_inpfail").value}}};xhr.send(parameters)}
289
+ function wfu_adminbrowser_select_all_visible_changed(){var status=document.getElementById("wfu_select_all_visible").checked;var selectors=document.querySelectorAll(".wfu_selectors");for(var i=0;i<selectors.length;i++)selectors[i].checked=status}
290
+ function wfu_adminbrowser_selector_changed(obj){var selectors_count=document.querySelectorAll(".wfu_selectors").length;var selected_count=document.querySelectorAll(".wfu_selectors:checked").length;var all_visible=document.getElementById("wfu_select_all_visible");all_visible.style.webkitAppearance="";all_visible.style.webkitAppearance="checkbox";all_visible.checked=selected_count>0;all_visible.indeterminate=selected_count>0&&selected_count<selectors_count}
291
+ function wfu_apply_bulkaction_select(code){if(typeof window["wfu_apply_"+code+"_bulkselect"]!="undefined")window["wfu_apply_"+code+"_bulkselect"]()}
292
+ function wfu_apply_adminbrowser_bulkaction(){var actionselector=document.getElementById("wfu_adminbrowser_bulkactions");if(actionselector.selectedIndex<1)return;var action=actionselector.options[actionselector.selectedIndex].value;var selected=document.querySelectorAll(".wfu_selectors:checked");if(selected.length==0)return;var codes=[];var codes_included=0,codes_not_included=0;for(var i=0;i<selected.length;i++){var file_code=selected[i].className.replace(/.*?wfu_selcode_/,"");if(file_code!=""){var included=
293
+ selected[i].className.indexOf("wfu_included")>-1;if(included)codes_included++;else codes_not_included++;if(action=="delete"&&!included||action=="include"&&included)selected[i].checked=false;else codes.push(file_code)}}if(action=="move"&&codes_not_included>0)alert("Notice! Files that were not uploaded using the plugin cannot be moved and have been deselected.");else if(action=="delete"&&codes_not_included>0)alert("Notice! Files that were not uploaded using the plugin cannot be deleted and have been deselected.");
294
+ else if(action=="include"&&codes_included>0)alert("Notice! Files already included in the plugin have been deselected.");if(codes.length==0)return;var url=document.getElementById("wfu_adminbrowser_action_url").value;var referer=document.getElementById("wfu_adminbrowser_referer").value;if(action=="move"||action=="delete"||action=="include"){var form=document.createElement("FORM");form.method="POST";form.action=url;form.style.display="none";var field1=document.createElement("INPUT");field1.type="hidden";
295
+ field1.name="action";field1.value=action+"_file";form.appendChild(field1);var field2=document.createElement("INPUT");field2.type="hidden";field2.name="file";field2.value="list:"+codes.join();form.appendChild(field2);var field3=document.createElement("INPUT");field3.type="hidden";field3.name="referer";field3.value=referer;form.appendChild(field3);document.body.appendChild(form);form.submit()}}
296
+ function wfu_goto_adminbrowser_page(token,go_to){var sel=document.getElementById("wfu_adminbrowser_pages");var page=sel.selectedIndex+1;var newpage=page;if(go_to=="next")newpage=Math.min(page+1,sel.options.length);else if(go_to=="prev")newpage=Math.max(page-1,1);else if(go_to=="last")newpage=sel.options.length;else if(go_to=="first")newpage=1;else if(go_to=="sel")page=-1;if(newpage==page)return;var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(4);
297
+ params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_get_adminbrowser_page";params[1]=new Array(2);params[1][0]="code";params[1][1]=document.getElementById("wfu_adminbrowser_code").value;params[2]=new Array(2);params[2][0]="token";params[2][1]=token;params[3]=new Array(2);params[3][0]="page";params[3][1]=newpage;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);document.getElementById("wfu_adminbrowser_overlay").style.display=
298
+ "block";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){document.getElementById("wfu_adminbrowser_overlay").style.display="none";var start_text="wfu_adminbrowser_page_success:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-
299
+ pos-start_text.length);if(response!=""){response=wfu_plugin_decode_string(response);var t=document.getElementById("wfu_adminbrowser_table");t.tBodies[0].innerHTML=response;document.getElementById("wfu_select_all_visible").checked=false;wfu_adminbrowser_select_all_visible_changed();sel.selectedIndex=newpage-1;document.getElementById("wfu_adminbrowser_first_disabled").style.display=newpage==1?"inline":"none";document.getElementById("wfu_adminbrowser_prev_disabled").style.display=newpage==1?"inline":
300
+ "none";document.getElementById("wfu_adminbrowser_first").style.display=newpage==1?"none":"inline";document.getElementById("wfu_adminbrowser_prev").style.display=newpage==1?"none":"inline";document.getElementById("wfu_adminbrowser_last_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_adminbrowser_next_disabled").style.display=newpage==sel.options.length?"inline":"none";document.getElementById("wfu_adminbrowser_last").style.display=newpage==sel.options.length?
301
+ "none":"inline";document.getElementById("wfu_adminbrowser_next").style.display=newpage==sel.options.length?"none":"inline"}}};xhr.send(parameters)}
302
+ function wfu_focus_table_on_highlighted_file(tableID){var tr=document.querySelector("#"+tableID+" tr.wfu-highlighted");if(tr){var adminbar=document.getElementById("wpadminbar");if(adminbar)adminbar=jQuery(adminbar).is(":visible")?adminbar:null;jQuery("html, body").animate({scrollTop:jQuery(tr).offset().top-(adminbar?jQuery(adminbar).height():0)+"px"},"fast")}}
303
+ function wfu_cleanlog_initialize_elements(){jQuery("#wfu_cleanlog_dateold").datepicker({dateFormat:"yy-mm-dd",beforeShow:function(){wfu_cleanlog_element_handler()},onSelect:function(){wfu_cleanlog_element_handler()},onClose:function(){wfu_cleanlog_element_handler()}});jQuery("#wfu_cleanlog_datefrom").datepicker({dateFormat:"yy-mm-dd",beforeShow:function(){wfu_cleanlog_element_handler()},onSelect:function(){wfu_cleanlog_element_handler()},onClose:function(){wfu_cleanlog_element_handler()}});jQuery("#wfu_cleanlog_dateto").datepicker({dateFormat:"yy-mm-dd",
304
+ beforeShow:function(){wfu_cleanlog_element_handler()},onSelect:function(){wfu_cleanlog_element_handler()},onClose:function(){wfu_cleanlog_element_handler()}});wfu_attach_element_handlers(document.getElementById("wfu_cleanlog_periodold"),wfu_cleanlog_element_handler);wfu_attach_element_handlers(document.getElementById("wfu_cleanlog_periodtype"),wfu_cleanlog_element_handler)}function wfu_cleanlog_element_handler(e){document.querySelector(".wfu_cleanlog_error").classList.add("hidden")}
305
+ function wfu_cleanlog_period_changed(){var sel=document.getElementById("wfu_cleanlog_period");if(sel.selectedIndex==0){document.querySelector(".wfu_selectdate_container").style.display="block";document.querySelector(".wfu_selectperiod_container").style.display="none";document.querySelector(".wfu_selectdates_container").style.display="none";document.getElementById("wfu_cleanlog_dateold").value="";document.querySelector(".wfu_cleanlog_proceed").classList.remove("disabled")}else if(sel.selectedIndex==
306
+ 1){document.querySelector(".wfu_selectdate_container").style.display="none";document.querySelector(".wfu_selectperiod_container").style.display="block";document.querySelector(".wfu_selectdates_container").style.display="none";document.getElementById("wfu_cleanlog_periodold").value="1";document.getElementById("wfu_cleanlog_periodtype").selectedIndex=1;document.querySelector(".wfu_cleanlog_proceed").classList.remove("disabled")}else if(sel.selectedIndex==2){document.querySelector(".wfu_selectdate_container").style.display=
307
+ "none";document.querySelector(".wfu_selectperiod_container").style.display="none";document.querySelector(".wfu_selectdates_container").style.display="block";document.getElementById("wfu_cleanlog_datefrom").value="";document.getElementById("wfu_cleanlog_dateto").value="";document.querySelector(".wfu_cleanlog_proceed").classList.remove("disabled")}else if(sel.selectedIndex==3){document.querySelector(".wfu_selectdate_container").style.display="none";document.querySelector(".wfu_selectperiod_container").style.display=
308
+ "none";document.querySelector(".wfu_selectdates_container").style.display="none";document.querySelector(".wfu_cleanlog_proceed").classList.remove("disabled")}else{document.querySelector(".wfu_selectdate_container").style.display="none";document.querySelector(".wfu_selectperiod_container").style.display="none";document.querySelector(".wfu_selectdates_container").style.display="none";document.querySelector(".wfu_cleanlog_proceed").classList.add("disabled")}document.querySelector(".wfu_cleanlog_error").classList.add("hidden")}
309
+ function wfu_cleanlog_selector_toggle(show){if(show){document.getElementById("wfu_includefiles").checked=false;document.getElementById("wfu_cleanlog_period").selectedIndex=-1;wfu_cleanlog_period_changed();document.querySelector(".wfu_cleanlog_tr").style.display="table-row"}else document.querySelector(".wfu_cleanlog_tr").style.display="none"}
310
+ function wfu_cleanlog_selector_validate(){var ret={error:"",param:""};var flag=document.getElementById("wfu_includefiles").checked?"1":"0";var sel=document.getElementById("wfu_cleanlog_period");if(sel.selectedIndex==-1)ret.error="Invalid clean-up period selected";else if(sel.selectedIndex==0){var date=jQuery("#wfu_cleanlog_dateold").datepicker("getDate");if(date==null)ret.error="Invalid or empty date";else{var today=new Date;if(date>today)ret.error="Date must be older than today";else{var timelimit=
311
+ jQuery.datepicker.formatDate("yymmdd",date);ret.param="0"+flag+":"+timelimit.toString()}}}else if(sel.selectedIndex==1){var inp=document.getElementById("wfu_cleanlog_periodold");var sel2=document.getElementById("wfu_cleanlog_periodtype");if(parseInt(inp.value)<=0)ret.error="Invalid period";else if(sel2.selectedIndex<0||sel2.selectedIndex>2)ret.error="Invalid period interval";else ret.param="1"+flag+":"+inp.value.toString()+":"+sel2.value.substr(0,1)}else if(sel.selectedIndex==2){var datefrom=jQuery("#wfu_cleanlog_datefrom").datepicker("getDate");
312
+ var dateto=jQuery("#wfu_cleanlog_dateto").datepicker("getDate");if(datefrom==null)ret.error="Invalid or empty starting date";else if(dateto==null)ret.error="Invalid or empty ending date";else{var today=new Date;if(datefrom>today)ret.error="Starting date must be older than today";else if(dateto>datefrom)ret.error="Ending date must be older or equal to starting date";else{var fromlimit=jQuery.datepicker.formatDate("yymmdd",datefrom);var tolimit=jQuery.datepicker.formatDate("yymmdd",dateto);ret.param=
313
+ "2"+flag+":"+fromlimit.toString()+":"+tolimit.toString()}}}else if(sel.selectedIndex==3)ret.param="3"+flag;return ret}
314
+ function wfu_cleanlog_selector_checkproceed(){var ret=wfu_cleanlog_selector_validate();if(ret.error!=""){document.querySelector(".wfu_cleanlog_error").innerHTML=ret.error;document.querySelector(".wfu_cleanlog_error").classList.remove("hidden");return false}document.querySelector(".wfu_cleanlog_error").classList.add("hidden");document.querySelector(".wfu_cleanlog_proceed").href=document.getElementById("wfu_cleanlog_href").value+"&data="+ret.param;return true}
315
+ function wfu_initialize_consent_policy(params){wfu_PD_bank.params=params;wfu_adjust_pdops_levels();wfu_adjust_permissions_levels();wfu_adjust_logactions_levels();wfu_attach_pdheaders_events();wfu_attach_pdops_events();wfu_attach_conops_events();wfu_pdops_update(true);wfu_allops_freeze_events=true;wfu_conops_update();wfu_consent_question_optable_recreate();wfu_update_consent_questions();wfu_consent_question_operations_reassign();wfu_update_consent_question_itemprops(0,-1);wfu_permissions_update(true);
316
+ wfu_logactions_update(true);wfu_pdusers_update();wfu_allops_freeze_events=false}function wfu_get_consent_policy(){var policy_str=wfu_plugin_decode_string(document.getElementById("wfu_consent_policy").value);var policy=null;try{policy=JSON.parse(policy_str)}catch(e){}return policy}function wfu_get_permissions_policy(){var policy_str=wfu_plugin_decode_string(document.getElementById("wfu_permissions_policy").value);var policy=null;try{policy=JSON.parse(policy_str)}catch(e){}return policy}
317
+ function wfu_get_logactions_policy(){var policy_str=wfu_plugin_decode_string(document.getElementById("wfu_logactions_policy").value);var policy=null;try{policy=JSON.parse(policy_str)}catch(e){}return policy}function wfu_get_pd_users(){var pd_users_str=wfu_plugin_decode_string(document.getElementById("wfu_assigned_users").value);var pd_users=null;try{pd_users=JSON.parse(pd_users_str)}catch(e){}return pd_users}
318
+ function wfu_set_consent_policy(new_policy){var policy_str=JSON.stringify(new_policy);document.getElementById("wfu_consent_policy").value=wfu_plugin_encode_string(policy_str)}function wfu_set_logactions_policy(new_policy){var policy_str=JSON.stringify(new_policy);document.getElementById("wfu_logactions_policy").value=wfu_plugin_encode_string(policy_str)}
319
+ function wfu_set_permissions_policy(new_policy){var policy_str=JSON.stringify(new_policy);document.getElementById("wfu_permissions_policy").value=wfu_plugin_encode_string(policy_str)}
320
+ function wfu_adjust_pdops_levels(){function _wfu_force_pdop_update_nested(item){var id=item.ID;if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_force_pdop_update_nested(item.children[j]);else policy.operations[id].Allowed=true}function _wfu_nested_adjust_pdops_levels(item,level){if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_nested_adjust_pdops_levels(item.children[j],level+1);var id=item.ID;if(wfu_PD_bank.allowedstatus[id]==0&&level==wfu_PD_bank.params.oplevels){_wfu_force_pdop_update_nested(item);
321
+ wfu_PD_bank.allowedstatus[id]=1;policy_needs_update=true}}wfu_pdops_update(false);var policy=wfu_get_consent_policy();if(policy){console.log(policy);var policy_needs_update=false;for(var i=0;i<policy.structure.length;i++)_wfu_nested_adjust_pdops_levels(policy.structure[i],1);if(policy_needs_update)wfu_set_consent_policy(policy)}}
322
+ function wfu_attach_pdheaders_events(){var acc=document.querySelectorAll(".wfu_pdheader_button");var i;for(i=0;i<acc.length;i++)acc[i].addEventListener("click",function(){this.classList.toggle("expanded");var panel=null;if(this.classList.contains("wfu_pdop_header_button"))panel=document.querySelector(".wfu_plugin_operations");else if(this.classList.contains("wfu_conop_header_button"))panel=document.querySelector(".wfu_consent_operations");else if(this.classList.contains("wfu_conquestion_header_button"))panel=
323
+ document.querySelector(".wfu_consent_questions");else if(this.classList.contains("wfu_permissions_header_button"))panel=document.querySelector(".wfu_consent_permissions");else if(this.classList.contains("wfu_logactions_header_button"))panel=document.querySelector(".wfu_consent_logactions");else if(this.classList.contains("wfu_pdusers_header_button"))panel=document.querySelector(".wfu_consent_users");if(panel)if(this.classList.contains("expanded"))panel.style.display="block";else panel.style.display=
324
+ "none"})}function wfu_attach_pdops_events(){var acc=document.querySelectorAll(".wfu_pdop_button");var i;for(i=0;i<acc.length;i++)acc[i].addEventListener("click",function(){this.classList.toggle("expanded");var panel=this.parentElement.nextElementSibling;if(this.classList.contains("expanded"))panel.style.display="block";else panel.style.display="none"})}
325
+ function wfu_attach_conops_events(){var acc=document.querySelectorAll(".wfu_conop_button");var i;for(i=0;i<acc.length;i++)acc[i].addEventListener("click",function(){this.classList.toggle("expanded");var panel=this.parentElement.nextElementSibling;if(this.classList.contains("expanded"))panel.style.display="block";else panel.style.display="none"})}
326
+ function wfu_pdop_toggle(obj){if(wfu_allops_freeze_events)return;if(obj.id.indexOf("wfu_pdop_")==-1)return;var id=obj.id.replace("wfu_pdop_","");var policy=wfu_get_consent_policy();if(policy){if(typeof policy.operations[id]=="undefined")return;var prev_status=obj.classList.contains("indeterminate")?0:obj.checked?-1:1;var new_status=obj.classList.contains("indeterminate")?true:obj.checked;if(!obj.indeterminate)obj.classList.remove("indeterminate");if(policy.children_index[id].length>0){var level=1;
327
+ var parid=id;while((parid=policy.operations[parid].Parent)>0)level++;if((wfu_PD_bank.params.oplevels<1||level<wfu_PD_bank.params.oplevels)&&!confirm("This will set all children operations to "+(new_status?"allowed":"not allowed")+". Continue?")){wfu_allops_freeze_events=true;wfu_set_checkbox_status(obj,prev_status);wfu_allops_freeze_events=false;return}for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];if(policy.children_index[id2].length==0)policy.operations[id2].Allowed=
328
+ new_status}}else policy.operations[id].Allowed=new_status;wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;wfu_pdops_update(true);wfu_conops_update();wfu_update_consent_question_itemprops(0,-1);wfu_consent_question_optable_recreate();wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(0,0);wfu_allops_freeze_events=false}}
329
+ function wfu_conop_toggle(obj){if(wfu_allops_freeze_events)return;if(obj.id.indexOf("wfu_conop_")==-1)return;var id=obj.id.replace("wfu_conop_","");var policy=wfu_get_consent_policy();if(policy){if(typeof policy.operations[id]=="undefined")return;var prev_status=obj.classList.contains("indeterminate")?0:obj.checked?-1:1;var new_status=obj.classList.contains("indeterminate")?true:obj.checked;if(!obj.indeterminate)check.classList.remove("indeterminate");if(policy.children_index[id].length>0){var level=
330
+ 1;var parid=id;while((parid=policy.operations[parid].Parent)>0)level++;if((wfu_PD_bank.params.oplevels<1||level<wfu_PD_bank.params.oplevels)&&!confirm("This will make all children operations "+(new_status?"require":"not require")+" consent. Continue?")){wfu_allops_freeze_events=true;wfu_set_checkbox_status(obj,prev_status);wfu_allops_freeze_events=false;return}for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];if(policy.children_index[id2].length==0)policy.operations[id2].NeedsConsent=
331
+ new_status}}else policy.operations[id].NeedsConsent=new_status;wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;wfu_conops_update();wfu_update_consent_question_itemprops(0,-1);wfu_consent_question_optable_recreate();wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(0,0);wfu_allops_freeze_events=false}}
332
+ function wfu_pdops_update(updatehtml){function _wfu_atomic_pdop_update(id){var allowed=policy.operations[id].Allowed;policy.operations[id].allowedstatus={};for(var k=0;k<policy.operations[id].Datatypes.length;k++){var type=policy.operations[id].Datatypes[k];policy.operations[id].allowedstatus[type]=allowed?1:-1}var condition=policy.operations[id].Condition;if(condition=="")policy.operations[id].pdvisible=true;else{var negative=false;if(condition.substr(0,1)=="!"){negative=true;condition=condition.replace("!",
333
+ "")}var allowedstatus2=policy.operations[parseInt(condition)].allowedstatus;var enabled=false;for(var type in allowedstatus2)if(allowedstatus2.hasOwnProperty(type))if(allowedstatus2[type]>-1){enabled=true;break}policy.operations[id].pdvisible=negative?!enabled:enabled}}function _wfu_nested_pdops_update(item,level){var id=item.ID;if(item.children.length>0){policy.operations[id].allowedstatus={};policy.operations[id].pdvisible=false;for(var j=0;j<item.children.length;j++){_wfu_nested_pdops_update(item.children[j],
334
+ level+1);var id2=item.children[j].ID;if(policy.operations[id2].pdvisible){var allowed=policy.operations[id2].Allowed;for(var type in policy.operations[id2].allowedstatus)if(policy.operations[id2].allowedstatus.hasOwnProperty(type)){var allowedstatus2=policy.operations[id2].allowedstatus[type];if(typeof policy.operations[id].allowedstatus[type]=="undefined")policy.operations[id].allowedstatus[type]=allowedstatus2;else if(policy.operations[id].allowedstatus[type]*allowedstatus2<1)policy.operations[id].allowedstatus[type]=
335
+ 0}if(!policy.operations[id].pdvisible)policy.operations[id].pdvisible=policy.operations[id2].pdvisible}}}else _wfu_atomic_pdop_update(id);var allowedstatus=-2;for(var type in policy.operations[id].allowedstatus)if(policy.operations[id].allowedstatus.hasOwnProperty(type)){var allowedstatus2=policy.operations[id].allowedstatus[type];if(allowedstatus==-2)allowedstatus=allowedstatus2;else if(allowedstatus*allowedstatus2<1){allowedstatus=0;break}}if(typeof wfu_PD_bank.allowedstatus=="undefined")wfu_PD_bank.allowedstatus=
336
+ {};wfu_PD_bank.allowedstatus[id]=allowedstatus;if(typeof wfu_PD_bank.level=="undefined")wfu_PD_bank.level={};wfu_PD_bank.level[id]=level;if(updatehtml){var check=document.getElementById("wfu_pdop_"+id);wfu_set_checkbox_status(check,allowedstatus);var container=document.getElementById("wfu_pdop_container_"+id);if(container)container.style.display=policy.operations[id].pdvisible&&(wfu_PD_bank.params.oplevels<1||level<=wfu_PD_bank.params.oplevels)?"block":"none"}}var policy=wfu_get_consent_policy();
337
+ if(policy){wfu_allops_freeze_events=true;for(var i=0;i<policy.structure.length;i++)_wfu_nested_pdops_update(policy.structure[i],1);wfu_allops_freeze_events=false}}
338
+ function wfu_conops_update(){function _wfu_atomic_conop_update(id){policy.operations[id].needsconsentstatus=policy.operations[id].Allowed&&policy.operations[id].NeedsConsent?1:-1;var condition=policy.operations[id].Condition;if(condition=="")policy.operations[id].convisible=true;else{var negative=false;if(condition.substr(0,1)=="!"){negative=true;condition=condition.replace("!","")}var enabled=wfu_PD_bank.allowedstatus[parseInt(condition)]>-1;policy.operations[id].convisible=negative?!enabled:enabled}policy.operations[id].convisible=
339
+ policy.operations[id].convisible&&policy.operations[id].Allowed}function _wfu_nested_conops_update(item,level){var id=item.ID;if(item.children.length>0){policy.operations[id].needsconsentstatus=-2;policy.operations[id].convisible=false;for(var j=0;j<item.children.length;j++){_wfu_nested_conops_update(item.children[j],level+1);var id2=item.children[j].ID;if(policy.operations[id2].convisible){var needsconsentstatus2=policy.operations[id2].needsconsentstatus;if(policy.operations[id].needsconsentstatus==
340
+ -2)policy.operations[id].needsconsentstatus=needsconsentstatus2;else if(policy.operations[id].needsconsentstatus*needsconsentstatus2<1)policy.operations[id].needsconsentstatus=0;if(!policy.operations[id].convisible)policy.operations[id].convisible=policy.operations[id2].convisible}}}else _wfu_atomic_conop_update(id);if(typeof wfu_PD_bank.visible=="undefined")wfu_PD_bank.visible={};wfu_PD_bank.visible[id]=policy.operations[id].convisible;if(typeof wfu_PD_bank.needsconsentstatus=="undefined")wfu_PD_bank.needsconsentstatus=
341
+ {};wfu_PD_bank.needsconsentstatus[id]=policy.operations[id].needsconsentstatus;var check=document.getElementById("wfu_conop_"+id);wfu_set_checkbox_status(check,policy.operations[id].needsconsentstatus);var container=document.getElementById("wfu_conop_container_"+id);if(container)container.style.display=policy.operations[id].convisible&&(wfu_PD_bank.params.oplevels<1||level<=wfu_PD_bank.params.oplevels)?"block":"none"}var policy=wfu_get_consent_policy();if(policy){wfu_allops_freeze_events=true;for(var i=
342
+ 0;i<policy.structure.length;i++)_wfu_nested_conops_update(policy.structure[i],1);wfu_allops_freeze_events=false}}
343
+ function wfu_update_consent_questions(){var policy=wfu_get_consent_policy();if(policy){var maincontainer=document.getElementById("wfu_conquestions_container");wfu_allops_freeze_events=true;for(var i=0;i<policy.questions.length;i++){var container=wfu_render_consent_question(i);if(container){maincontainer.appendChild(container);wfu_update_consent_question(i,true)}}wfu_update_conquestion_header();wfu_allops_freeze_events=false}}
344
+ function wfu_render_consent_question(index){var policy=wfu_get_consent_policy();if(!policy)return null;var question=policy.questions[index];var i=index+1;var container=document.createElement("DIV");container.className="wfu_conquestion_container";container.id="wfu_conquestion_container_"+i;var header=document.createElement("DIV");header.className="wfu_conquestion_header";var headerlabel=document.createElement("LABEL");headerlabel.className="wfu_conquestion_headerlabel";headerlabel.innerHTML="Question "+
345
+ i;header.appendChild(headerlabel);var tools=document.createElement("DIV");tools.className="wfu_conquestion_tools";var add_btn=document.getElementById("wfu_conquestion_add").cloneNode(true);add_btn.removeAttribute("id");wfu_addEventHandler(add_btn,"click",wfu_conquestion_tools_handler);var remove_btn=document.getElementById("wfu_conquestion_remove").cloneNode(true);remove_btn.removeAttribute("id");wfu_addEventHandler(remove_btn,"click",wfu_conquestion_tools_handler);var up_btn=document.getElementById("wfu_conquestion_up").cloneNode(true);
346
+ up_btn.removeAttribute("id");wfu_addEventHandler(up_btn,"click",wfu_conquestion_tools_handler);var down_btn=document.getElementById("wfu_conquestion_down").cloneNode(true);down_btn.removeAttribute("id");wfu_addEventHandler(down_btn,"click",wfu_conquestion_tools_handler);tools.appendChild(add_btn);tools.appendChild(remove_btn);tools.appendChild(up_btn);tools.appendChild(down_btn);header.appendChild(tools);var subcontainer=document.createElement("DIV");subcontainer.className="wfu_conquestion_subcontainer";
347
+ var mainprops=document.createElement("DIV");mainprops.className="wfu_conquestion_mainprops";var mainpropstitle=document.createElement("LABEL");mainpropstitle.className="wfu_conquestion_mainpropstitle";mainpropstitle.innerHTML="Main Properties";var titlelabel=document.createElement("LABEL");titlelabel.className="wfu_conquestion_titlelabel";titlelabel.innerHTML="Title";var titletext=document.createElement("INPUT");titletext.className="wfu_conquestion_titletext";titletext.value=question.title;wfu_attach_element_handlers(titletext,
348
+ wfu_conquestion_mainprops_handler);var titlelocationlabel=document.createElement("LABEL");titlelocationlabel.className="wfu_conquestion_titlelocationlabel";titlelocationlabel.innerHTML="Title Location";var titlelocationlist=document.createElement("SELECT");titlelocationlist.className="wfu_conquestion_titlelocationlist";var opt=document.createElement("OPTION");opt.value="top";opt.innerHTML="Top";opt.selected=question.location=="top";titlelocationlist.add(opt);var opt=document.createElement("OPTION");
349
+ opt.value="bottom";opt.innerHTML="Bottom";opt.selected=question.location=="bottom";titlelocationlist.add(opt);wfu_addEventHandler(titlelocationlist,"change",wfu_conquestion_mainprops_handler);var matrixlabel=document.createElement("LABEL");matrixlabel.className="wfu_conquestion_matrixlabel";matrixlabel.innerHTML="Number of Items";var matrix_x=document.createElement("INPUT");matrix_x.className="wfu_conquestion_matrix_x";matrix_x.type="number";matrix_x.min=1;var qx=parseInt(question.x);if(qx<=0)qx=
350
+ 1;question.x=qx;matrix_x.value=qx;wfu_attach_element_handlers(matrix_x,wfu_conquestion_mainprops_handler);var matrixsep=document.createElement("LABEL");matrixsep.className="wfu_conquestion_matrixsep";matrixsep.innerHTML="x";var matrix_y=document.createElement("INPUT");matrix_y.className="wfu_conquestion_matrix_y";matrix_y.type="number";matrix_y.min=1;var qy=parseInt(question.y);if(qy<=0)qy=1;question.y=qy;matrix_y.value=qy;wfu_attach_element_handlers(matrix_y,wfu_conquestion_mainprops_handler);var groupedlabel=
351
+ document.createElement("LABEL");groupedlabel.className="wfu_conquestion_groupedlabel";groupedlabel.innerHTML="Grouped";var groupedbox=document.createElement("INPUT");groupedbox.className="wfu_conquestion_groupedbox";groupedbox.type="checkbox";groupedbox.checked=question.grouped==1;wfu_addEventHandler(groupedbox,"change",wfu_conquestion_mainprops_handler);var typelabel=document.createElement("LABEL");typelabel.className="wfu_conquestion_typelabel";typelabel.innerHTML="Type";var typelist=document.createElement("SELECT");
352
+ typelist.className="wfu_conquestion_typelist";var opt=document.createElement("OPTION");opt.value="checkbox";opt.innerHTML="Checkbox";opt.selected=question.type=="checkbox";typelist.add(opt);var opt=document.createElement("OPTION");opt.value="radio";opt.innerHTML="Radio";opt.selected=question.type=="radio";typelist.add(opt);var opt=document.createElement("OPTION");opt.value="prompt";opt.innerHTML="Prompt";opt.selected=question.type=="prompt";typelist.add(opt);wfu_addEventHandler(typelist,"change",
353
+ wfu_conquestion_mainprops_handler);mainprops.appendChild(mainpropstitle);mainprops.appendChild(matrixlabel);mainprops.appendChild(matrix_x);mainprops.appendChild(matrixsep);mainprops.appendChild(matrix_y);mainprops.appendChild(titlelabel);mainprops.appendChild(titletext);mainprops.appendChild(titlelocationlabel);mainprops.appendChild(titlelocationlist);mainprops.appendChild(groupedlabel);mainprops.appendChild(groupedbox);mainprops.appendChild(typelabel);mainprops.appendChild(typelist);var itemspreview=
354
+ document.createElement("DIV");itemspreview.className="wfu_conquestion_itemspreview";var itemspreviewtitle=document.createElement("LABEL");itemspreviewtitle.className="wfu_conquestion_itemspreviewtitle";itemspreviewtitle.innerHTML="Items";var displayedtitle=document.createElement("LABEL");displayedtitle.className="wfu_conquestion_displayedtitle";displayedtitle.innerHTML=question.title;var itemtable=document.createElement("TABLE");itemtable.className="wfu_conquestion_itemtable";itemspreview.appendChild(itemspreviewtitle);
355
+ if(question.location!="bottom")itemspreview.appendChild(displayedtitle);itemspreview.appendChild(itemtable);if(question.location=="bottom")itemspreview.appendChild(displayedtitle);wfu_addEventHandler(itemspreview,"click",wfu_conquestion_itempreviewer_handler);var itemprops=document.createElement("DIV");itemprops.className="wfu_conquestion_itemprops";var itempropstitle=document.createElement("LABEL");itempropstitle.className="wfu_conquestion_itempropstitle";itempropstitle.innerHTML="Item Properties";
356
+ var labellabel=document.createElement("LABEL");labellabel.className="wfu_conquestion_labellabel";labellabel.innerHTML="Label";var labeltext=document.createElement("INPUT");labeltext.className="wfu_conquestion_labeltext";labeltext.value="";wfu_attach_element_handlers(labeltext,wfu_conquestion_mainprops_handler);var labellocationlabel=document.createElement("LABEL");labellocationlabel.className="wfu_conquestion_labellocationlabel";labellocationlabel.innerHTML="Label Location";var labellocationlist=
357
+ document.createElement("SELECT");labellocationlist.className="wfu_conquestion_labellocationlist";var opt=document.createElement("OPTION");opt.value="top";opt.innerHTML="Top";opt.selected=false;labellocationlist.add(opt);var opt=document.createElement("OPTION");opt.value="left";opt.innerHTML="Left";opt.selected=false;labellocationlist.add(opt);var opt=document.createElement("OPTION");opt.value="right";opt.innerHTML="Right";opt.selected=true;labellocationlist.add(opt);var opt=document.createElement("OPTION");
358
+ opt.value="bottom";opt.innerHTML="Bottom";opt.selected=false;labellocationlist.add(opt);wfu_addEventHandler(labellocationlist,"change",wfu_conquestion_mainprops_handler);var preselectedlabel=document.createElement("LABEL");preselectedlabel.className="wfu_conquestion_preselectedlabel";preselectedlabel.innerHTML="Preselected";var preselectedbox=document.createElement("INPUT");preselectedbox.className="wfu_conquestion_preselectedbox";preselectedbox.type="checkbox";preselectedbox.checked=false;wfu_addEventHandler(preselectedbox,
359
+ "change",wfu_conquestion_mainprops_handler);var visiblelabel=document.createElement("LABEL");visiblelabel.className="wfu_conquestion_visiblelabel";visiblelabel.innerHTML="Visible";var visiblebox=document.createElement("INPUT");visiblebox.className="wfu_conquestion_visiblebox";visiblebox.type="checkbox";visiblebox.checked=true;wfu_addEventHandler(visiblebox,"change",wfu_conquestion_mainprops_handler);itemprops.appendChild(itempropstitle);itemprops.appendChild(labellabel);itemprops.appendChild(labeltext);
360
+ itemprops.appendChild(labellocationlabel);itemprops.appendChild(labellocationlist);itemprops.appendChild(preselectedlabel);itemprops.appendChild(preselectedbox);itemprops.appendChild(visiblelabel);itemprops.appendChild(visiblebox);subcontainer.appendChild(mainprops);subcontainer.appendChild(itemspreview);subcontainer.appendChild(itemprops);container.appendChild(header);container.appendChild(subcontainer);return container}
361
+ function wfu_consent_question_action(action,index){var policy=wfu_get_consent_policy();if(!policy)return;var maincontainer=document.getElementById("wfu_conquestions_container");var qcount=document.querySelectorAll(".wfu_conquestion_container").length;if(action=="add"){var question={title:"",location:"top",x:1,y:1,grouped:0,type:"checkbox",items:[{index:1,label:"I agree to allow the plugin to use my personal data",location:"right",preselect:0,visible:true,operations:{}}]};policy.questions.splice(index+
362
+ 1,0,question);wfu_set_consent_policy(policy);var container=wfu_render_consent_question(index+1);if(container){for(var j=index+2;j<=qcount;j++)document.getElementById("wfu_conquestion_container_"+j).id="wfu_conquestion_container_"+(j+1);maincontainer.insertBefore(container,document.getElementById("wfu_conquestion_container_"+(index+3)));wfu_update_consent_question(index+1,true);wfu_update_consent_question_itemprops(index+1,-1)}}else if(action=="remove"){if(qcount<=1)return;policy.questions.splice(index,
363
+ 1);wfu_set_consent_policy(policy);maincontainer.removeChild(document.getElementById("wfu_conquestion_container_"+(index+1)));for(var j=index+2;j<=qcount;j++)document.getElementById("wfu_conquestion_container_"+j).id="wfu_conquestion_container_"+(j-1)}else if(action=="up"){if(index<=0)return;var tempq=policy.questions[index];policy.questions[index]=policy.questions[index-1];policy.questions[index-1]=tempq;wfu_set_consent_policy(policy);var container1=document.getElementById("wfu_conquestion_container_"+
364
+ (index+1));var container2=document.getElementById("wfu_conquestion_container_"+index);container1.id="wfu_conquestion_container_"+index+"_temp";container2.id="wfu_conquestion_container_"+(index+1);container1.id="wfu_conquestion_container_"+index;maincontainer.insertBefore(container1,container2)}else if(action=="down"){if(index>=qcount-1)return;var tempq=policy.questions[index];policy.questions[index]=policy.questions[index+1];policy.questions[index+1]=tempq;wfu_set_consent_policy(policy);var container1=
365
+ document.getElementById("wfu_conquestion_container_"+(index+2));var container2=document.getElementById("wfu_conquestion_container_"+(index+1));container1.id="wfu_conquestion_container_"+(index+1)+"_temp";container2.id="wfu_conquestion_container_"+(index+2);container1.id="wfu_conquestion_container_"+(index+1);maincontainer.insertBefore(container1,container2)}}
366
+ function wfu_update_consent_question(index,recreate){var policy=wfu_get_consent_policy();if(!policy)return;var question=policy.questions[index];var i=index+1;var itemspreview=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_itemspreview");var itemtable=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_itemtable");var displayedtitle=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_displayedtitle");if(!itemspreview)return;if(recreate){var matrix_x=
367
+ document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_matrix_x");var matrix_y=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_matrix_y");var titletext=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_titletext");var titlelocationlist=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_titlelocationlist");var groupedbox=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_groupedbox");
368
+ matrix_x.value=question.x;matrix_y.value=question.y;titletext.value=question.title;titlelocationlist.value=question.location;groupedbox.checked=question.grouped==1;matrix_x.disabled=question.type=="prompt";matrix_y.disabled=question.type=="prompt";titletext.disabled=question.type=="prompt";titlelocationlist.disabled=question.type=="prompt";groupedbox.disabled=question.type=="prompt";displayedtitle.style.display=question.type=="prompt"?"none":"block";while(itemtable.rows.length>0)itemtable.deleteRow(0)}var qnum=
369
+ question.x*question.y;var qitems=[];for(var j=0;j<qnum;j++)qitems.push({label:"",location:"right",preselect:false,visible:true,operations:{}});for(var j=0;j<question.items.length;j++)if(typeof question.items[j].visible=="undefined")question.items[j].visible=1;for(var j=0;j<question.items.length;j++){var ind=question.items[j].index-1;if(ind>=0&&ind<qnum){qitems[ind].label=question.items[j].label;qitems[ind].location=question.items[j].location;qitems[ind].preselect=question.items[j].preselect==1;qitems[ind].visible=
370
+ typeof question.items[j].visible=="undefined"||question.items[j].visible==1;qitems[ind].operations=question.items[j].operations}}var j=0;for(var k=0;k<question.x;k++){var row;if(recreate)row=itemtable.insertRow(k);else row=itemtable.rows[k];for(var l=0;l<question.y;l++){var cell;if(recreate){cell=row.insertCell(l);cell.classList.add("wfu_conquestion_itemcontainer")}else cell=row.cells[l];while(cell.childNodes.length>0)cell.removeChild(cell.childNodes[0]);if(qitems[j].visible)cell.classList.add("wfu_item_visible");
371
+ else cell.classList.remove("wfu_item_visible");var itemlabel=document.createElement("LABEL");itemlabel.className="wfu_conquestion_itemlabel";if(qitems[j].label==""){itemlabel.classList.add("wfu_empty_label");itemlabel.innerHTML="{no label}"}else{itemlabel.classList.remove("wfu_empty_label");itemlabel.innerHTML=qitems[j].label}if(question.type=="prompt")cell.appendChild(itemlabel);else{var itembox=document.createElement("INPUT");itembox.className="wfu_conquestion_itembox wfu_frozen";itembox.type=question.type;
372
+ itembox.checked=qitems[j].preselect;if(qitems[j].location=="top"){cell.appendChild(itemlabel);cell.appendChild(document.createElement("BR"));cell.appendChild(itembox)}else if(qitems[j].location=="left"){cell.appendChild(itemlabel);cell.appendChild(itembox)}else if(qitems[j].location=="bottom"){cell.appendChild(itembox);cell.appendChild(document.createElement("BR"));cell.appendChild(itemlabel)}else{cell.appendChild(itembox);cell.appendChild(itemlabel)}}j++}}if(question.title==""){displayedtitle.classList.add("wfu_empty_label");
373
+ displayedtitle.innerHTML="{no title}"}else{displayedtitle.classList.remove("wfu_empty_label");displayedtitle.innerHTML=question.title}if(question.location!="bottom")itemspreview.insertBefore(displayedtitle,itemtable);else itemspreview.insertBefore(displayedtitle,null)}
374
+ function wfu_conquestion_mainprops_handler(e){if(wfu_allops_freeze_events)return;var policy=wfu_get_consent_policy();if(!policy)return;e=e||window.event;var item=par=e.target;while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));var i=parseInt(par.id.replace("wfu_conquestion_container_",""));var index=i-1;var question=policy.questions[index];var recreate=true;var is_mainprop=true;var update_optable=false;if(item.classList.contains("wfu_conquestion_titletext"))question.title=
375
+ item.value;else if(item.classList.contains("wfu_conquestion_matrix_x"))question.x=item.value;else if(item.classList.contains("wfu_conquestion_matrix_y"))question.y=item.value;else if(item.classList.contains("wfu_conquestion_titlelocationlist"))question.location=item.value;else if(item.classList.contains("wfu_conquestion_groupedbox")){question.grouped=item.checked?1:0;if(question.grouped==1){var qpreselect_count=0;for(var j=0;j<question.items.length;j++)if(qpreselect_count==1)question.items[j].preselect=
376
+ 0;else if(question.items[j].preselect==1)qpreselect_count++}}else if(item.classList.contains("wfu_conquestion_typelist")){question.type=item.value;if(question.type=="prompt"){question.x=1;question.y=1;question.title="";question.location="top";question.grouped=0}}else{var itemcontainers=document.querySelectorAll("#wfu_conquestion_container_"+i+" .wfu_conquestion_itemcontainer.wfu_item_selected");if(itemcontainers.length==0)return;var itemindex=itemcontainers[0].parentNode.rowIndex*itemcontainers[0].parentNode.cells.length+
377
+ itemcontainers[0].cellIndex+1;var qitem=null;var qindex=question.items.length;for(var j=0;j<question.items.length;j++)if(question.items[j].index==itemindex){qitem=question.items[j];break}else if(question.items[j].index>itemindex){qindex=j;break}if(!qitem){qitem={index:itemindex,label:"",location:"right",preselect:false,visible:1,operations:{}};question.items.splice(qindex,0,qitem)}if(item.classList.contains("wfu_conquestion_labeltext"))qitem.label=item.value;else if(item.classList.contains("wfu_conquestion_labellocationlist"))qitem.location=
378
+ item.value;else if(item.classList.contains("wfu_conquestion_preselectedbox")){if(item.checked&&question.grouped==1)for(var j=0;j<question.items.length;j++)question.items[j].preselect=0;qitem.preselect=item.checked?1:0}else if(item.classList.contains("wfu_conquestion_visiblebox")){qitem.visible=item.checked?1:0;update_optable=true}recreate=false;is_mainprop=false}wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;wfu_update_consent_question(index,recreate);if(is_mainprop){wfu_update_consent_question_itemprops(index,
379
+ -1);wfu_consent_question_operations_reassign()}if(update_optable){wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(i,itemindex)}wfu_allops_freeze_events=false}
380
+ function wfu_conquestion_itempreviewer_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=par=e.target;var qcount=document.querySelectorAll(".wfu_conquestion_container").length;while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));var i=parseInt(par.id.replace("wfu_conquestion_container_",""));var index=i-1;if(!item.classList.contains("wfu_conquestion_itemcontainer"))item=item.parentNode;var itemindex=-1;if(item.classList.contains("wfu_conquestion_itemcontainer"))itemindex=
381
+ item.parentNode.rowIndex*item.parentNode.cells.length+item.cellIndex+1;wfu_allops_freeze_events=true;for(var j=0;j<qcount;j++)wfu_update_consent_question_itemprops(j,-1);wfu_update_consent_question_itemprops(index,itemindex);wfu_allops_freeze_events=false}
382
+ function wfu_update_consent_question_itemprops(index,itemindex){var policy=wfu_get_consent_policy();if(!policy)return;var question=policy.questions[index];var i=index+1;var itemcontainers=document.querySelectorAll("#wfu_conquestions_container .wfu_conquestion_itemcontainer");var itemcontainer=null;var contindex=0;var contitemindex=1;for(var j=0;j<itemcontainers.length;j++){itemcontainers[j].classList.remove("wfu_item_selected");var par=itemcontainers[j];while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));
383
+ if(parseInt(par.id.replace("wfu_conquestion_container_",""))>contindex){contindex++;contitemindex=1}if(contindex==i&&contitemindex==itemindex)itemcontainer=itemcontainers[j];contitemindex++}if(itemcontainer)itemcontainer.classList.add("wfu_item_selected");var labeltext=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_labeltext");var labellocationlist=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_labellocationlist");var preselectedbox=document.querySelector("#wfu_conquestion_container_"+
384
+ i+" .wfu_conquestion_preselectedbox");var visiblebox=document.querySelector("#wfu_conquestion_container_"+i+" .wfu_conquestion_visiblebox");var qindex=-1;for(var j=0;j<question.items.length;j++)if(question.items[j].index==itemindex){qindex=j;break}if(qindex<0){labeltext.value="";labeltext.disabled=itemindex<1;labellocationlist.value="right";labellocationlist.disabled=itemindex<1;preselectedbox.checked=false;preselectedbox.disabled=itemindex<1;visiblebox.checked=true;visiblebox.disabled=itemindex<
385
+ 1}else{labeltext.disabled=false;labeltext.value=question.items[qindex].label;labellocationlist.disabled=question.type=="prompt";labellocationlist.value=question.type=="prompt"?"":question.items[qindex].location;preselectedbox.disabled=question.type=="prompt";preselectedbox.checked=question.type=="prompt"?false:question.items[qindex].preselect==1;visiblebox.disabled=question.type=="prompt"?true:index==0&&itemindex==1;visiblebox.checked=question.type=="prompt"?true:typeof question.items[qindex].visible==
386
+ "undefined"||question.items[qindex].visible==1}wfu_consent_question_optable_update(i,itemindex)}
387
+ function wfu_consent_question_optable_recreate(){var oplist=[];var policy=wfu_get_consent_policy();if(policy){if(typeof wfu_PD_bank.conops!="undefined")for(var id in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(id))wfu_PD_bank.conops[id].active=false;var optable=document.getElementById("wfu_conquestions_optable");var body=optable.tBodies[0];while(body.rows.length>0)optable.rows[0].remove();var i=0;for(var id in wfu_PD_bank.allowedstatus)if(wfu_PD_bank.allowedstatus.hasOwnProperty(id)){var included=
388
+ true;included=included&&(policy.children_index[id].length==0&&(wfu_PD_bank.params.oplevels<1||wfu_PD_bank.level[id]<=wfu_PD_bank.params.oplevels)||policy.children_index[id].length>0&&wfu_PD_bank.level[id]==wfu_PD_bank.params.oplevels);included=included&&wfu_PD_bank.needsconsentstatus[id]==1;included=included&&wfu_PD_bank.visible[id];if(included){if(typeof wfu_PD_bank.conops=="undefined")wfu_PD_bank.conops={};wfu_PD_bank.conops[id]={active:true,qindex:[1],itemindex:[1],inverse:[false],unassigned:true,
389
+ nonevisible:false};var row=body.insertRow(i);row.id="wfu_conquestions_oprow_"+id;var cell=row.insertCell(0);var name=policy.operations[id].Name;var parid=id;while((parid=policy.operations[parid].Parent)>0)name=policy.operations[parid].Name+"/"+name;cell.innerHTML=name;var cell=row.insertCell(1);var selbox=document.createElement("INPUT");selbox.type="radio";selbox.className="wfu_conquestions_opsel wfu_frozen";wfu_addEventHandler(selbox,"click",wfu_conquestion_optable_handler);cell.appendChild(selbox);
390
+ var cell=row.insertCell(2);var invbox=document.createElement("INPUT");invbox.type="checkbox";invbox.className="wfu_conquestions_opinv wfu_frozen";invbox.disabled=true;wfu_addEventHandler(invbox,"change",wfu_conquestion_optable_handler);cell.appendChild(invbox);i++}}}}
391
+ function wfu_consent_question_operations_reassign(){var policy=wfu_get_consent_policy();if(policy){for(var opid in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(opid)){wfu_PD_bank.conops[opid].qindex=[];wfu_PD_bank.conops[opid].itemindex=[];wfu_PD_bank.conops[opid].inverse=[];wfu_PD_bank.conops[opid].unassigned=true;wfu_PD_bank.conops[opid].nonevisible=true}for(var i=0;i<policy.questions.length;i++){var question=policy.questions[i];for(var j=0;j<question.items.length;j++){var qitem=question.items[j];
392
+ for(var opid in qitem.operations)if(qitem.operations.hasOwnProperty(opid))if(typeof wfu_PD_bank.conops[opid]!="undefined")if(wfu_PD_bank.params.multi_op_assignments||wfu_PD_bank.conops[opid].qindex.length==0){wfu_PD_bank.conops[opid].qindex.push(i+1);wfu_PD_bank.conops[opid].itemindex.push(j+1);wfu_PD_bank.conops[opid].inverse.push(qitem.operations[opid]==-1);wfu_PD_bank.conops[opid].unassigned=false}else delete qitem.operations[opid]}}for(var opid in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(opid)){var j=
393
+ 0;while(j<wfu_PD_bank.conops[opid].qindex.length){var qindex=wfu_PD_bank.conops[opid].qindex[j];var itemindex=wfu_PD_bank.conops[opid].itemindex[j];var remove=false;if(qindex<1||qindex>policy.questions.length)remove=true;else{var question=policy.questions[qindex-1];var qnum=question.x*question.y;if(itemindex<1||itemindex>qnum)remove=true}if(remove){wfu_PD_bank.conops[opid].qindex.splice(j,1);wfu_PD_bank.conops[opid].itemindex.splice(j,1);wfu_PD_bank.conops[opid].inverse.splice(j,1)}else{var qitem=
394
+ policy.questions[qindex-1].items[itemindex-1];if(typeof qitem.visible=="undefined"||qitem.visible)wfu_PD_bank.conops[opid].nonevisible=false;j++}}if(wfu_PD_bank.conops[opid].nonevisible){wfu_PD_bank.conops[opid].unassigned=wfu_PD_bank.conops[opid].qindex.length==0;wfu_PD_bank.conops[opid].qindex.splice(0,0,1);wfu_PD_bank.conops[opid].itemindex.splice(0,0,1);wfu_PD_bank.conops[opid].inverse.splice(0,0,false)}}wfu_set_consent_policy(policy);wfu_update_consent_question_item_assignments()}}
395
+ function wfu_update_consent_question_item_assignments(){var containers=document.querySelectorAll("#wfu_conquestions_container .wfu_conquestion_itemcontainer");for(var i=0;i<containers.length;i++)containers[i].classList.remove("wfu_item_assigned");for(var opid in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(opid)&&wfu_PD_bank.conops[opid].active)for(var j=0;j<wfu_PD_bank.conops[opid].qindex.length;j++){var qindex=wfu_PD_bank.conops[opid].qindex[j];var itemindex=wfu_PD_bank.conops[opid].itemindex[j];
396
+ var itemtable=document.querySelector("#wfu_conquestion_container_"+qindex+" .wfu_conquestion_itemtable");var x=itemtable.rows[0].cells.length;var rowindex=Math.floor((itemindex-1)/x);var cellindex=(itemindex-1)%x;itemtable.rows[rowindex].cells[cellindex].classList.add("wfu_item_assigned")}}
397
+ function wfu_conquestion_conop_bankpos(opid,index,itemindex){var pos=-1;for(var i=0;i<wfu_PD_bank.conops[opid].qindex.length;i++)if(wfu_PD_bank.conops[opid].qindex[i]==index&&wfu_PD_bank.conops[opid].itemindex[i]==itemindex){pos=i;break}return pos}
398
+ function wfu_consent_question_optable_update(index,itemindex){var freeze=index<1||itemindex<1;for(var opid in wfu_PD_bank.conops)if(wfu_PD_bank.conops.hasOwnProperty(opid)&&wfu_PD_bank.conops[opid].active){var oprow=document.getElementById("wfu_conquestions_oprow_"+opid);var selbox=document.querySelector("#wfu_conquestions_oprow_"+opid+" .wfu_conquestions_opsel");var invbox=document.querySelector("#wfu_conquestions_oprow_"+opid+" .wfu_conquestions_opinv");if(wfu_PD_bank.conops[opid].unassigned||wfu_PD_bank.conops[opid].nonevisible)oprow.classList.add("wfu_op_unassigned");
399
+ else oprow.classList.remove("wfu_op_unassigned");var pos=wfu_conquestion_conop_bankpos(opid,index,itemindex);selbox.checked=!freeze&&pos>-1;if(!freeze&&pos>-1&&(wfu_PD_bank.conops[opid].unassigned||wfu_PD_bank.conops[opid].nonevisible)&&index==1&&itemindex==1)selbox.classList.add("wfu_forced_selection");else selbox.classList.remove("wfu_forced_selection");invbox.checked=!freeze&&pos>-1&&wfu_PD_bank.conops[opid].inverse[pos];invbox.disabled=!(!freeze&&pos>-1);if(freeze){selbox.classList.add("wfu_frozen");
400
+ invbox.classList.add("wfu_frozen")}else{selbox.classList.remove("wfu_frozen");invbox.classList.remove("wfu_frozen")}}}
401
+ function wfu_conquestion_optable_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;var itemcontainer=document.querySelector("#wfu_conquestions_container .wfu_conquestion_itemcontainer.wfu_item_selected");if(!itemcontainer)return;var par=itemcontainer;while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));var index=parseInt(par.id.replace("wfu_conquestion_container_",""));var itemcontainers=document.querySelectorAll("#wfu_conquestion_container_"+
402
+ index+" .wfu_conquestion_itemcontainer");var itemindex=-1;for(var j=0;j<itemcontainers.length;j++)if(itemcontainers[j]==itemcontainer){itemindex=j+1;break}var policy=wfu_get_consent_policy();if(!policy)return;if(!item.classList.contains("wfu_conquestions_opsel")&&!item.classList.contains("wfu_conquestions_opinv"))return;var opid=parseInt(item.parentNode.parentNode.id.replace("wfu_conquestions_oprow_",""));var opas=wfu_PD_bank.conops[opid];var pos=wfu_conquestion_conop_bankpos(opid,index,itemindex);
403
+ if(pos<0||opas.unassigned){if(!wfu_PD_bank.params.multi_op_assignments||opas.unassigned){var question=policy.questions[opas.qindex[0]-1];for(var j=0;j<question.items.length;j++)if(question.items[j].index==opas.itemindex[0]){if(typeof question.items[j].operations[opid]!="undefined")delete question.items[j].operations[opid];break}opas.qindex.splice(0,1);opas.itemindex.splice(0,1);opas.inverse.splice(0,1)}opas.qindex.push(index);opas.itemindex.push(itemindex);opas.inverse.push(document.querySelector("#wfu_conquestions_oprow_"+
404
+ opid+" .wfu_conquestions_opinv").checked);opas.unassigned=false;pos=opas.qindex.length-1;var question=policy.questions[opas.qindex[pos]-1];var qitem=null;var qindex=question.items.length;for(var j=0;j<question.items.length;j++)if(question.items[j].index==opas.itemindex[pos]){qitem=question.items[j];qitem.operations[opid]=opas.inverse[pos]?-1:1;break}else if(question.items[j].index>itemindex){qindex=j;break}if(!qitem){qitem={index:opas.itemindex[pos],label:"",location:"right",preselect:false,operations:{}};
405
+ qitem.operations[opid]=opas.inverse[pos]?-1:1;question.items.splice(qindex,0,qitem)}wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(index,itemindex);wfu_update_consent_question_item_assignments();wfu_allops_freeze_events=false}else if(item.classList.contains("wfu_conquestions_opsel")&&pos>=0){var question=policy.questions[opas.qindex[pos]-1];for(var j=0;j<question.items.length;j++)if(question.items[j].index==
406
+ opas.itemindex[pos]){if(typeof question.items[j].operations[opid]!="undefined")delete question.items[j].operations[opid];break}opas.qindex.splice(pos,1);opas.itemindex.splice(pos,1);opas.inverse.splice(pos,1);wfu_set_consent_policy(policy);wfu_allops_freeze_events=true;item.checked=false;wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(index,itemindex);wfu_update_consent_question_item_assignments();wfu_allops_freeze_events=false}else if(item.classList.contains("wfu_conquestions_opinv")){opas.inverse[pos]=
407
+ item.checked;var question=policy.questions[opas.qindex[pos]-1];for(var j=0;j<question.items.length;j++)if(question.items[j].index==opas.itemindex[pos]){question.items[j].operations[opid]=opas.inverse[pos]?-1:1;break}wfu_set_consent_policy(policy)}}
408
+ function wfu_conquestion_tools_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;var qcount=document.querySelectorAll(".wfu_conquestion_container").length;var par=item;while((par=par.parentElement)&&!par.classList.contains("wfu_conquestion_container"));var index=parseInt(par.id.replace("wfu_conquestion_container_",""))-1;wfu_allops_freeze_events=true;var action="";if(item.classList.contains("wfu_conquestion_add"))action="add";else if(item.classList.contains("wfu_conquestion_remove")&&
409
+ qcount>1)action="remove";else if(item.classList.contains("wfu_conquestion_up")&&index>0)action="up";else if(item.classList.contains("wfu_conquestion_down")&&index<qcount-1)action="down";if(action!=""){wfu_update_consent_question_itemprops(0,-1);wfu_consent_question_action(action,index);wfu_consent_question_operations_reassign();wfu_consent_question_optable_update(0,0);wfu_update_conquestion_header()}wfu_allops_freeze_events=false}
410
+ function wfu_update_conquestion_header(){var labels=document.querySelectorAll(".wfu_conquestion_headerlabel");var add_btns=document.querySelectorAll(".wfu_conquestion_tools .wfu_conquestion_btn.wfu_conquestion_add");var remove_btns=document.querySelectorAll(".wfu_conquestion_tools .wfu_conquestion_btn.wfu_conquestion_remove");var up_btns=document.querySelectorAll(".wfu_conquestion_tools .wfu_conquestion_btn.wfu_conquestion_up");var down_btns=document.querySelectorAll(".wfu_conquestion_tools .wfu_conquestion_btn.wfu_conquestion_down");
411
+ for(var i=0;i<labels.length;i++){labels[i].innerHTML="Question "+(i+1);if(labels.length>1)remove_btns[i].classList.remove("wfu_tool_disabled");else remove_btns[i].classList.add("wfu_tool_disabled");if(i>0)up_btns[i].classList.remove("wfu_tool_disabled");else up_btns[i].classList.add("wfu_tool_disabled");if(i<labels.length-1)down_btns[i].classList.remove("wfu_tool_disabled");else down_btns[i].classList.add("wfu_tool_disabled")}}
412
+ function wfu_permissions_update(updatehtml){function _wfu_nested_perms_update(item,level){var id=item.ID;if(item.children.length>0){policy.permissions[id].allowedstatus={};for(var j=0;j<item.children.length;j++){_wfu_nested_perms_update(item.children[j],level+1);var id2=item.children[j].ID;for(var locid in policy.permissions[id2].allowedstatus)if(policy.permissions[id2].allowedstatus.hasOwnProperty(locid)){var allowedstatus2=policy.permissions[id2].allowedstatus[locid];if(typeof policy.permissions[id].allowedstatus[locid]==
413
+ "undefined")policy.permissions[id].allowedstatus[locid]=allowedstatus2;else if(policy.permissions[id].allowedstatus[locid]*allowedstatus2<1)policy.permissions[id].allowedstatus[locid]=0}}}else{var allowed=policy.permissions[id].Allowed;policy.permissions[id].allowedstatus={};for(var k=0;k<policy.permissions[id].Locations.length;k++){var locid=policy.permissions[id].Locations[k];policy.permissions[id].allowedstatus[locid]=allowed.indexOf(locid)>-1?1:-1}}if(typeof wfu_PD_bank.perallowedstatus=="undefined")wfu_PD_bank.perallowedstatus=
414
+ {};wfu_PD_bank.perallowedstatus[id]=policy.permissions[id].allowedstatus;if(updatehtml){var row=document.getElementById("wfu_perm_row_"+id);for(var locid in policy.permissions[id].allowedstatus)if(policy.permissions[id].allowedstatus.hasOwnProperty(locid)){var check=document.querySelector("#wfu_perm_row_"+id+" .wfu_location_cell:nth-child("+(parseInt(locid)+1)+") input");wfu_set_checkbox_status(check,policy.permissions[id].allowedstatus[locid])}}}var policy=wfu_get_permissions_policy();if(policy){console.log(policy);
415
+ wfu_allops_freeze_events=true;for(var i=0;i<policy.structure.length;i++)_wfu_nested_perms_update(policy.structure[i],1);wfu_allops_freeze_events=false}}
416
+ function wfu_adjust_permissions_levels(){function _wfu_force_permission_update_nested(item,locid){var id=item.ID;if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_force_permission_update_nested(item.children[j],locid);else if(policy.permissions[id].Allowed.indexOf(locid)==-1&&policy.permissions[id].Locations.indexOf(locid)>-1)policy.permissions[id].Allowed.push(locid)}function _wfu_nested_adjust_permissions_levels(item,level){if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_nested_adjust_permissions_levels(item.children[j],
417
+ level+1);var id=item.ID;for(var locid in wfu_PD_bank.perallowedstatus[id])if(wfu_PD_bank.perallowedstatus[id].hasOwnProperty(locid))if(wfu_PD_bank.perallowedstatus[id][locid]==0&&level==wfu_PD_bank.params.perlevels){_wfu_force_permission_update_nested(item,parseInt(locid));wfu_PD_bank.perallowedstatus[id][locid]=1;policy_needs_update=true}}wfu_permissions_update(false);var policy=wfu_get_permissions_policy();if(policy){var policy_needs_update=false;for(var i=0;i<policy.structure.length;i++)_wfu_nested_adjust_permissions_levels(policy.structure[i],
418
+ 1);if(policy_needs_update)wfu_set_permissions_policy(policy)}}
419
+ function wfu_perm_toggle(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_location_selector"))return;var id=obj.parentNode.parentNode.id.replace("wfu_perm_row_","");var locid=obj.parentNode.cellIndex;var policy=wfu_get_permissions_policy();if(policy){if(typeof policy.permissions[id]=="undefined")return;var prev_status=obj.classList.contains("indeterminate")?0:obj.checked?-1:1;var new_status=obj.classList.contains("indeterminate")?true:obj.checked;if(!obj.indeterminate)obj.classList.remove("indeterminate");
420
+ if(policy.children_index[id].length>0){var level=1;var parid=id;while((parid=policy.permissions[parid].Parent)>0)level++;if((wfu_PD_bank.params.perlevels<1||level<wfu_PD_bank.params.perlevels)&&!confirm("This will make all children permissions "+(new_status?"allowed":"not allowed")+". Continue?")){wfu_allops_freeze_events=true;wfu_set_checkbox_status(obj,prev_status);wfu_allops_freeze_events=false;return}for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];if(policy.children_index[id2].length==
421
+ 0){var locindex2=policy.permissions[id2].Allowed.indexOf(locid);if(new_status&&locindex2==-1&&policy.permissions[id2].Locations.indexOf(locid)>-1)policy.permissions[id2].Allowed.push(locid);else if(!new_status&&locindex2>-1)policy.permissions[id2].Allowed.splice(locindex2,1)}}}else{var locindex=policy.permissions[id].Allowed.indexOf(locid);if(new_status&&locindex==-1&&policy.permissions[id].Locations.indexOf(locid)>-1)policy.permissions[id].Allowed.push(locid);else if(!new_status&&locindex>-1)policy.permissions[id].Allowed.splice(locindex,
422
+ 1)}wfu_set_permissions_policy(policy);wfu_allops_freeze_events=true;wfu_permissions_update(true);wfu_allops_freeze_events=false}}
423
+ function wfu_perm_button_action(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_perm_button"))return;var policy=wfu_get_permissions_policy();if(policy){var par=obj;while((par=par.parentElement)&&!par.classList.contains("wfu_perm_row"));var id=parseInt(par.id.replace("wfu_perm_row_",""));obj.classList.toggle("expanded");for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];var parid=id2;var visible=true;while((parid=policy.permissions[parid].Parent)>
424
+ 0)visible=visible&&document.querySelector("#wfu_perm_row_"+parid+" .wfu_perm_button")&&document.querySelector("#wfu_perm_row_"+parid+" .wfu_perm_button").classList.contains("expanded");document.getElementById("wfu_perm_row_"+id2).style.display=visible?"table-row":"none"}}}
425
+ function wfu_logactions_update(updatehtml){function _wfu_nested_logactions_update(item,level){var id=item.ID;if(item.children.length>0){policy.logactions[id].allowedstatus={};for(var j=0;j<item.children.length;j++){_wfu_nested_logactions_update(item.children[j],level+1);var id2=item.children[j].ID;for(var entid in policy.logactions[id2].allowedstatus)if(policy.logactions[id2].allowedstatus.hasOwnProperty(entid)){var allowedstatus2=policy.logactions[id2].allowedstatus[entid];if(typeof policy.logactions[id].allowedstatus[entid]==
426
+ "undefined")policy.logactions[id].allowedstatus[entid]=allowedstatus2;else if(policy.logactions[id].allowedstatus[entid]*allowedstatus2<1)policy.logactions[id].allowedstatus[entid]=0}}}else{var allowed=policy.logactions[id].Allowed;policy.logactions[id].allowedstatus={};for(var k=0;k<policy.logactions[id].Entities.length;k++){var entid=policy.logactions[id].Entities[k];policy.logactions[id].allowedstatus[entid]=allowed.indexOf(entid)>-1?1:-1}}if(typeof wfu_PD_bank.logallowedstatus=="undefined")wfu_PD_bank.logallowedstatus=
427
+ {};wfu_PD_bank.logallowedstatus[id]=policy.logactions[id].allowedstatus;if(updatehtml){var row=document.getElementById("wfu_log_row_"+id);for(var entid in policy.logactions[id].allowedstatus)if(policy.logactions[id].allowedstatus.hasOwnProperty(entid)){var check=document.querySelector("#wfu_log_row_"+id+" .wfu_entity_cell:nth-child("+(parseInt(entid)+1)+") input");wfu_set_checkbox_status(check,policy.logactions[id].allowedstatus[entid])}}}var policy=wfu_get_logactions_policy();if(policy){console.log(policy);
428
+ wfu_allops_freeze_events=true;for(var i=0;i<policy.structure.length;i++)_wfu_nested_logactions_update(policy.structure[i],1);wfu_allops_freeze_events=false}}
429
+ function wfu_adjust_logactions_levels(){function _wfu_force_logaction_update_nested(item,entid){var id=item.ID;if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_force_logaction_update_nested(item.children[j],entid);else if(policy.logactions[id].Allowed.indexOf(entid)==-1&&policy.logactions[id].Entities.indexOf(entid)>-1)policy.logactions[id].Allowed.push(entid)}function _wfu_nested_adjust_logactions_levels(item,level){if(item.children.length>0)for(var j=0;j<item.children.length;j++)_wfu_nested_adjust_logactions_levels(item.children[j],
430
+ level+1);var id=item.ID;for(var entid in wfu_PD_bank.logallowedstatus[id])if(wfu_PD_bank.logallowedstatus[id].hasOwnProperty(entid))if(wfu_PD_bank.logallowedstatus[id][entid]==0&&level==wfu_PD_bank.params.loglevels){_wfu_force_logaction_update_nested(item,parseInt(entid));wfu_PD_bank.logallowedstatus[id][entid]=1;policy_needs_update=true}}wfu_logactions_update(false);var policy=wfu_get_logactions_policy();if(policy){var policy_needs_update=false;for(var i=0;i<policy.structure.length;i++)_wfu_nested_adjust_logactions_levels(policy.structure[i],
431
+ 1);if(policy_needs_update)wfu_set_logactions_policy(policy)}}
432
+ function wfu_log_toggle(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_entity_selector"))return;var id=obj.parentNode.parentNode.id.replace("wfu_log_row_","");var entid=obj.parentNode.cellIndex;var policy=wfu_get_logactions_policy();if(policy){if(typeof policy.logactions[id]=="undefined")return;var prev_status=obj.classList.contains("indeterminate")?0:obj.checked?-1:1;var new_status=obj.classList.contains("indeterminate")?true:obj.checked;if(!obj.indeterminate)obj.classList.remove("indeterminate");
433
+ if(policy.children_index[id].length>0){var level=1;var parid=id;while((parid=policy.logactions[parid].Parent)>0)level++;if((wfu_PD_bank.params.loglevels<1||level<wfu_PD_bank.params.loglevels)&&!confirm("This will make all children log actions "+(new_status?"allowed":"not allowed")+". Continue?")){wfu_allops_freeze_events=true;wfu_set_checkbox_status(obj,prev_status);wfu_allops_freeze_events=false;return}for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];if(policy.children_index[id2].length==
434
+ 0){var entindex2=policy.logactions[id2].Allowed.indexOf(entid);if(new_status&&entindex2==-1&&policy.logactions[id2].Entities.indexOf(entid)>-1)policy.logactions[id2].Allowed.push(entid);else if(!new_status&&entindex2>-1)policy.logactions[id2].Allowed.splice(entindex2,1)}}}else{var entindex=policy.logactions[id].Allowed.indexOf(entid);if(new_status&&entindex==-1&&policy.logactions[id].Entities.indexOf(entid)>-1)policy.logactions[id].Allowed.push(entid);else if(!new_status&&entindex>-1)policy.logactions[id].Allowed.splice(entindex,
435
+ 1)}wfu_set_logactions_policy(policy);wfu_allops_freeze_events=true;wfu_logactions_update(true);wfu_allops_freeze_events=false}}
436
+ function wfu_log_button_action(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_log_button"))return;var policy=wfu_get_logactions_policy();if(policy){var par=obj;while((par=par.parentElement)&&!par.classList.contains("wfu_log_row"));var id=parseInt(par.id.replace("wfu_log_row_",""));obj.classList.toggle("expanded");for(var i=0;i<policy.children_index[id].length;i++){var id2=policy.children_index[id][i];var parid=id2;var visible=true;while((parid=policy.logactions[parid].Parent)>
437
+ 0)visible=visible&&document.querySelector("#wfu_log_row_"+parid+" .wfu_log_button")&&document.querySelector("#wfu_log_row_"+parid+" .wfu_log_button").classList.contains("expanded");document.getElementById("wfu_log_row_"+id2).style.display=visible?"table-row":"none"}}}
438
+ function wfu_pdusers_addrole_handler(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_pdusers_roles_add"))return;var par=obj;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_roles_container"));var type=par.id.replace(/^wfu_pdusers_roles_(in|out)_container$/,"$1");var roles=document.querySelector("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_list");var names=[];for(var i=0;i<roles.options.length;i++)if(roles.options[i].selected)names.push(roles.options[i].value);
439
+ wfu_allops_freeze_events=true;wfu_pdusers_add_roles(type,names);wfu_allops_freeze_events=false}
440
+ function wfu_pdusers_add_roles(type,names){var show=document.querySelector("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_show");var roles=document.querySelector("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_list");var selected=document.querySelectorAll("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_rightpanel .wfu_pdusers_roles_role");var source=document.querySelector('#wfu_pdusers_roles_in_container input[type="radio"]').checked?"in":"out";var btype=type=="in"?
441
+ "included":"excluded";var count=selected.length;for(var i=0;i<names.length;i++){var title="";if(names[i]=="all")title="All";else for(var j=0;j<roles.options.length;j++)if(roles.options[j].value==names[i]){title=roles.options[j].innerHTML;break}if(title!=""){var already_in=false;for(var j=0;j<selected.length;j++)if(selected[j].roleName==names[i]){already_in=true;break}if(!already_in){var pos=wfu_PD_bank.pdusers.rolestates[source][btype].indexOf(names[i]);if(pos==-1)wfu_PD_bank.pdusers.rolestates[source][btype].push(names[i]);
442
+ if(count>0)show.appendChild(document.createElement("BR"));var role=document.createElement("DIV");role.classList.add("wfu_pdusers_roles_role");role.roleName=names[i];role.innerHTML=title;if(names[i]=="all")role.classList.add("wfu_pdusers_roles_all");else{var delbtn=document.createElement("SPAN");wfu_addEventHandler(delbtn,"click",wfu_pdusers_removerole_handler);role.appendChild(delbtn)}show.appendChild(role);count++}}}}
443
+ function wfu_pdusers_clear_roles(type){var show=document.querySelector("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_show");var selected=document.querySelectorAll("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_rightpanel .wfu_pdusers_roles_role");var brs=document.querySelectorAll("#wfu_pdusers_roles_"+type+"_container .wfu_pdusers_roles_rightpanel br");for(var i=0;i<selected.length;i++)show.removeChild(selected[i]);for(var i=0;i<brs.length;i++)show.removeChild(brs[i])}
444
+ function wfu_pdusers_removerole_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;if(!item.parentNode.classList.contains("wfu_pdusers_roles_role"))return;var role=item.parentNode.roleName;var par=item;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_roles_container"));var type=par.id.replace(/^wfu_pdusers_roles_(in|out)_container$/,"$1");var source=document.querySelector('#wfu_pdusers_roles_in_container input[type="radio"]').checked?"in":"out";var btype=
445
+ type=="in"?"included":"excluded";var pos=wfu_PD_bank.pdusers.rolestates[source][btype].indexOf(role);if(pos>-1)wfu_PD_bank.pdusers.rolestates[source][btype].splice(pos,1);var br1=item.parentNode.previousSibling;var br2=item.parentNode.nextSibling;var show=document.querySelector("#"+par.id+" .wfu_pdusers_roles_show");wfu_allops_freeze_events=true;show.removeChild(item.parentNode);if(br1&&br1.tagName&&br1.tagName=="BR")show.removeChild(br1);else if(br2&&br2.tagName&&br2.tagName=="BR")show.removeChild(br2);
446
+ wfu_allops_freeze_events=false}
447
+ function wfu_pdusers_update(){var pd_users=wfu_get_pd_users();if(pd_users){console.log(pd_users);wfu_PD_bank.pdusers={rolestates:{"in":{included:[],excluded:[]},out:{included:["all"],excluded:[]}}};var userin_input=document.querySelector('#wfu_pdusers_users_in_container .wfu_pdusers_users_leftpanel input[type="text"]');wfu_attach_element_handlers(userin_input,wfu_pdusers_get_users);var userout_input=document.querySelector('#wfu_pdusers_users_out_container .wfu_pdusers_users_leftpanel input[type="text"]');wfu_attach_element_handlers(userout_input,
448
+ wfu_pdusers_get_users);wfu_PD_bank.pdusers.userinput={"in":{prev_value:""},out:{prev_value:""},xhr:null};var radioin=document.querySelector('#wfu_pdusers_roles_in_container input[type="radio"]');var rolein_list=document.querySelector("#wfu_pdusers_roles_in_container .wfu_pdusers_roles_list");var rolein_back=document.querySelector("#wfu_pdusers_roles_in_container .wfu_pdusers_roles_back");var radioout=document.querySelector('#wfu_pdusers_roles_out_container input[type="radio"]');var roleout_list=document.querySelector("#wfu_pdusers_roles_out_container .wfu_pdusers_roles_list");
449
+ var roleout_back=document.querySelector("#wfu_pdusers_roles_out_container .wfu_pdusers_roles_back");if(pd_users.roles_included.length>0&&pd_users.roles_included[0]!="all"||pd_users.roles_excluded.length==1&&pd_users.roles_excluded[0]=="all"||pd_users.roles_included.length==0&&pd_users.roles_excluded.length==0){wfu_PD_bank.pdusers.rolestates["in"].included=pd_users.roles_included;rolein_list.disabled=false;rolein_back.classList.add("active");roleout_list.disabled=true;roleout_back.classList.remove("active");
450
+ radioin.checked=true;wfu_pdusers_add_roles("in",pd_users.roles_included);wfu_pdusers_add_roles("out",[])}else{wfu_PD_bank.pdusers.rolestates.out.excluded=pd_users.roles_excluded;rolein_list.disabled=true;rolein_back.classList.remove("active");roleout_list.disabled=false;roleout_back.classList.add("active");radioout.checked=true;wfu_pdusers_add_roles("in",["all"]);wfu_pdusers_add_roles("out",pd_users.roles_excluded)}}}
451
+ function wfu_pdusers_roletype_handler(obj){if(wfu_allops_freeze_events)return;if(obj.name!="wfu_pdusers_roletypes")return;var radioin=document.querySelector('#wfu_pdusers_roles_in_container input[type="radio"]');var rolein_list=document.querySelector("#wfu_pdusers_roles_in_container .wfu_pdusers_roles_list");var rolein_back=document.querySelector("#wfu_pdusers_roles_in_container .wfu_pdusers_roles_back");var radioout=document.querySelector('#wfu_pdusers_roles_out_container input[type="radio"]');var roleout_list=
452
+ document.querySelector("#wfu_pdusers_roles_out_container .wfu_pdusers_roles_list");var roleout_back=document.querySelector("#wfu_pdusers_roles_out_container .wfu_pdusers_roles_back");wfu_allops_freeze_events=true;wfu_pdusers_clear_roles("in");wfu_pdusers_clear_roles("out");if(obj.value=="include"){rolein_list.disabled=false;rolein_back.classList.add("active");roleout_list.disabled=true;roleout_back.classList.remove("active");radioin.checked=true;wfu_pdusers_add_roles("in",wfu_PD_bank.pdusers.rolestates["in"].included);
453
+ wfu_pdusers_add_roles("out",wfu_PD_bank.pdusers.rolestates["in"].excluded)}else{rolein_list.disabled=true;rolein_back.classList.remove("active");roleout_list.disabled=false;roleout_back.classList.add("active");radioout.checked=true;wfu_pdusers_add_roles("in",wfu_PD_bank.pdusers.rolestates.out.included);wfu_pdusers_add_roles("out",wfu_PD_bank.pdusers.rolestates.out.excluded)}wfu_allops_freeze_events=false}
454
+ function wfu_pdusers_adduser_handler(obj){if(wfu_allops_freeze_events)return;if(!obj.classList.contains("wfu_pdusers_users_add"))return;var par=obj;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_users_container"));var type=par.id.replace(/^wfu_pdusers_users_(in|out)_container$/,"$1");var users=document.querySelector("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_list");var names=[];for(var i=0;i<users.options.length;i++)if(users.options[i].selected)names.push(users.options[i].value);
455
+ wfu_allops_freeze_events=true;wfu_pdusers_add_users(type,names);wfu_allops_freeze_events=false}
456
+ function wfu_pdusers_add_users(type,names){var show=document.querySelector("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_show");var users=document.querySelector("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_list");var selected=document.querySelectorAll("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_rightpanel .wfu_pdusers_users_user");var otherselected=document.querySelectorAll("#wfu_pdusers_users_"+(type=="in"?"out":"in")+"_container .wfu_pdusers_users_rightpanel .wfu_pdusers_users_user");
457
+ var count=selected.length;for(var i=0;i<names.length;i++){var title="";for(var j=0;j<users.options.length;j++)if(users.options[j].value==names[i]){title=users.options[j].innerHTML;break}if(title!=""){var already_in=false;for(var j=0;j<selected.length;j++)if(selected[j].userName==names[i]){already_in=true;break}if(!already_in){if(count>0)show.appendChild(document.createElement("BR"));for(var j=0;j<otherselected.length;j++)if(otherselected[j].userName==names[i]){var prev_wfu_allops_freeze_events=wfu_allops_freeze_events;
458
+ wfu_allops_freeze_events=false;wfu_pdusers_removeuser_handler({target:otherselected[j].children[0]});wfu_allops_freeze_events=prev_wfu_allops_freeze_events;break}var user=document.createElement("DIV");user.classList.add("wfu_pdusers_users_user");user.userName=names[i];user.innerHTML=title;var delbtn=document.createElement("SPAN");wfu_addEventHandler(delbtn,"click",wfu_pdusers_removeuser_handler);user.appendChild(delbtn);show.appendChild(user);count++}}}}
459
+ function wfu_pdusers_removeuser_handler(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;if(!item.parentNode.classList.contains("wfu_pdusers_users_user"))return;var user=item.parentNode.userName;var par=item;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_users_container"));var type=par.id.replace(/^wfu_pdusers_users_(in|out)_container$/,"$1");var br1=item.parentNode.previousSibling;var br2=item.parentNode.nextSibling;var show=document.querySelector("#"+
460
+ par.id+" .wfu_pdusers_users_show");wfu_allops_freeze_events=true;show.removeChild(item.parentNode);if(br1&&br1.tagName&&br1.tagName=="BR")show.removeChild(br1);else if(br2&&br2.tagName&&br2.tagName=="BR")show.removeChild(br2);wfu_allops_freeze_events=false}
461
+ function wfu_pdusers_get_users(e){if(wfu_allops_freeze_events)return;e=e||window.event;var item=e.target;if(!item.parentNode.classList.contains("wfu_pdusers_users_leftpanel"))return;var par=item;while((par=par.parentElement)&&!par.classList.contains("wfu_pdusers_users_container"));var type=par.id.replace(/^wfu_pdusers_users_(in|out)_container$/,"$1");if(item.value==wfu_PD_bank.pdusers.userinput[type].prev_value)return;wfu_PD_bank.pdusers.userinput[type].prev_value=item.value;if(wfu_PD_bank.pdusers.xhr!=
462
+ null){wfu_PD_bank.pdusers.xhr.abort();wfu_PD_bank.pdusers.xhr=null}var userlist=document.querySelector("#wfu_pdusers_users_"+type+"_container .wfu_pdusers_users_list");if(item.value==""){var length=userlist.options.length;for(i=0;i<length;i++)userlist.options[0]=null;return}var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_pdusers_get_users";params[1]=new Array(2);params[1][0]=
463
+ "nonce";params[1][1]=document.getElementById("_wpnonce").value;params[2]=new Array(2);params[2][0]="query";params[2][1]=item.value;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var start_text="pdusers_get_users:";var pos=xhr.responseText.indexOf(start_text);
464
+ if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);var users_str=wfu_plugin_decode_string(response);var users=null;try{users=JSON.parse(users_str)}catch(e$2){}var length=userlist.options.length;for(i=0;i<length;i++)userlist.options[i]=null;for(i=0;i<users.length;i++){var opt=document.createElement("OPTION");opt.value=users[i].user_login;opt.innerHTML=users[i].display_name+
465
+ " ("+users[i].user_login+")";userlist.options.add(opt)}}};wfu_PD_bank.pdusers.xhr=xhr;xhr.send(parameters)}function wfu_initialize_consent_policy_basic(){wfu_PD_bank.userinput={prev_value:"",xhr:null,prev_select:-1};wfu_attach_element_handlers(document.getElementById("wfu_pd_user_box0"),wfu_pd_get_users_basic)}
466
+ function wfu_pd_get_users_basic(e){e=e||window.event;var item=e.target;if(!item.classList.contains("wfu_pd_user_box0"))return;if(item.value==wfu_PD_bank.userinput)return;var userlist=document.getElementById("wfu_pd_user_select0");wfu_PD_bank.userinput=item.value;if(wfu_PD_bank.userinput.xhr!=null){wfu_PD_bank.userinput.xhr.abort();wfu_PD_bank.userinput.xhr=null}if(item.value==""){var length=userlist.options.length;for(i=0;i<length;i++)userlist.options[0]=null;return}var xhr=wfu_GetHttpRequestObject();
467
+ if(xhr==null)return;var url=AdminParams.wfu_ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_pdusers_get_users";params[1]=new Array(2);params[1][0]="nonce";params[1][1]=document.getElementById("_wpnonce").value;params[2]=new Array(2);params[2][0]="query";params[2][1]=item.value;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type",
468
+ "application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var start_text="pdusers_get_users:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);var users_str=wfu_plugin_decode_string(response);var users=null;try{users=JSON.parse(users_str)}catch(e$3){}var length=
469
+ userlist.options.length;for(i=0;i<length;i++)userlist.options[0]=null;for(i=0;i<users.length;i++){var opt=document.createElement("OPTION");opt.value=users[i].user_login;opt.innerHTML=users[i].display_name+" ("+users[i].user_login+")";userlist.options.add(opt)}}};wfu_PD_bank.userinput.xhr=xhr;xhr.send(parameters)}
470
+ function wfu_export_user_data(){var userlist=document.getElementById("wfu_pd_user_select0");if(userlist.selectedIndex<0){alert("No user has been selected!");return}var params={username:userlist.options[userlist.selectedIndex].value};var params_str=JSON.stringify(params);wfu_download_file("exportdata:"+params_str,1)}
471
+ function wfu_erase_user_data_check(){var userlist=document.getElementById("wfu_pd_user_select0");var anchor=document.getElementById("wfu_erase_userdata0");if(userlist.selectedIndex<0){alert("No user has been selected!");return false}else{anchor.href=anchor.href.replace(/action=erase_userdata_ask.*$/,"action=erase_userdata_ask&username="+userlist.options[userlist.selectedIndex].value);return true}}
472
+ function wfu_pd_pre_save_actions(){var wfu_PD_bank_str=JSON.stringify(wfu_PD_bank);document.getElementById("wfu_PD_bank").value=wfu_plugin_encode_string(wfu_PD_bank_str)};
js/wordpress_file_upload_functions.js CHANGED
@@ -1,156 +1,156 @@
1
- GlobalData={};Code_Initializators=[];GlobalData.WFU={n:[]};GlobalData.WFUB={n:[]};GlobalData.filestatematch={};GlobalData.filestatematch.success=[0,1,2,2];GlobalData.filestatematch.warning=[1,1,2,2];GlobalData.filestatematch.error1=[3,3,2,3];GlobalData.filestatematch.error2=[2,2,2,3];GlobalData.UploadInProgressString="";GlobalData.FreeChangeHandler=false;wfu_Check_Browser_Capabilities();
2
- if(typeof wfu_js_decode_obj=="undefined")wfu_js_decode_obj=function(obj_str){var obj=null;if(obj_str=="window")obj=window;else{var dbs=String.fromCharCode(92);var match=obj_str.match(new RegExp("GlobalData("+dbs+".(WFU|WFUB)"+dbs+"[(.*?)"+dbs+"]("+dbs+".(.*))?)?$"));if(match){obj=GlobalData;if(match[3])obj=obj[match[2]][match[3]];if(match[5])obj=obj[match[5]]}}return obj};
3
- function wfu_run_js_from_bank(){if(typeof WFU_JS_BANK!="undefined")while(WFU_JS_BANK.length>0){var obj=wfu_js_decode_obj(WFU_JS_BANK[0].obj_str);if(obj)obj[WFU_JS_BANK[0].func].call(obj);WFU_JS_BANK.splice(0,1)}}
4
- function wfu_Initialize_Consts(consts){if(typeof GlobalData.consts!="undefined")return;GlobalData.consts=new Object;var consts_arr=consts.split(";");var const_arr;for(var i=0;i<consts_arr.length;i++){const_txt=consts_arr[i].split(":");GlobalData.consts[wfu_plugin_decode_string(const_txt[0])]=wfu_plugin_decode_string(const_txt[1])}}
5
- function wfu_Load_Code_Connectors(sid){if(typeof wfu_Code_Objects=="undefined")wfu_Code_Objects={};wfu_Code_Objects[sid]=new wfu_Code_Object(sid);for(var i=0;i<Code_Initializators.length;i++)wfu_Code_Objects[sid].additem(Code_Initializators[i](sid))}
6
- function wfu_Code_Object(sid){this.sid=sid;this.items=[];this._calc_prioritized_list=function(section){var item,list=[],idlist=[],nolist=[],priority;for(var i=0;i<this.items.length;i++){item=this.items[i];if(item[section]){priority=-1;if(item.priority)priority=item.priority;if(item[section].priority)priority=item[section].priority;if(priority>=0){list.push(priority);idlist.push(i)}else nolist.push(i)}}for(var i=1;i<list.length;i++)for(var j=i;j<list.length;j++)if(list[j]<list[i-1]){var temp=list[j];
7
- list[j]=list[i-1];list[i-1]=temp;var temp=idlist[j];idlist[j]=idlist[i-1];idlist[i-1]=temp}return idlist.concat(nolist)};this.additem=function(item){this.items.push(item)};this.apply_filters=function(section,val){if(typeof val=="undefined")return null;var idlist=this._calc_prioritized_list(section);if(idlist.length==0)return val;for(var i=0;i<idlist.length;i++){var item=this.items[idlist[i]];var func=null;if(typeof item[section]=="function")func=item[section];else if(typeof item[section].func=="function")func=
8
- item[section].func;if(func!=null){val=func.apply(this,Array.prototype.slice.call(arguments,1));arguments[1]=val}}return val};this.do_action=function(section){var idlist=this._calc_prioritized_list(section);if(idlist.length==0)return;for(var i=0;i<idlist.length;i++){var item=this.items[idlist[i]];var func=null;if(typeof item[section]=="function")func=item[section];else if(typeof item[section].func=="function")func=item[section].func;if(func!=null)func.apply(this,Array.prototype.slice.call(arguments,
9
- 1))}}}
10
- function wfu_plugin_load_action(sid){var WFU=GlobalData.WFU[sid];wfu_install_unload_hook();if(!!WFU.visualeditorbutton_exist){WFU.visualeditorbutton.init();var invoke_function=function(){wfu_invoke_shortcode_editor(WFU)};WFU.visualeditorbutton.attachInvokeHandler(invoke_function)}if(WFU.is_formupload)WFU.uploadaction=function(){wfu_redirect_to_classic(sid,0,0)};else WFU.uploadaction=function(){wfu_HTML5UploadFile(sid)};var clickaction=function(){wfu_selectbutton_clicked(sid)};var changeaction=function(fileselected){var WFU=
11
- GlobalData.WFU[sid];var usefilearray=0;wfu_selectbutton_changed(sid,usefilearray);wfu_update_uploadbutton_status(sid);if(WFU.singlebutton&&fileselected)WFU.uploadaction()};if(!!WFU.uploadform_exist)WFU.uploadform.attachActions(clickaction,changeaction);var completeaction=function(status){document.getElementById("consentresult_"+sid).value=status};if(!!WFU.consent_exist){WFU.consent.attachActions(completeaction);WFU.consent.update("init")}if(!!WFU.submit_exist){if(WFU.testmode)clickaction=function(){alert(GlobalData.consts.notify_testmode)};
12
- else clickaction=function(){WFU.uploadaction()};WFU.submit.attachClickAction(clickaction)}}function wfu_install_unload_hook(){window.onbeforeunload=wfu_unload_hook}function wfu_unload_hook(){if(GlobalData.UploadInProgressString!="")if(GlobalData.UploadInProgressString.trim()!="")return GlobalData.consts.wfu_pageexit_prompt}
13
- function wfu_Check_Browser_Capabilities(){if(typeof wfu_BrowserCaps!="undefined")return;wfu_BrowserCaps=new Object;var xmlhttp=wfu_GetHttpRequestObject();wfu_BrowserCaps.supportsAJAX=xmlhttp!=null;wfu_BrowserCaps.supportsUploadProgress=!!(xmlhttp&&"upload"in xmlhttp&&"onprogress"in xmlhttp.upload);var fd=null;try{var fd=new FormData}catch(e$0){}wfu_BrowserCaps.supportsHTML5=fd!=null;var e=document.createElement("iframe");wfu_BrowserCaps.supportsIFRAME=e!=null;wfu_BrowserCaps.supportsDRAGDROP=window.FileReader?
14
- true:false;wfu_BrowserCaps.supportsAnimation=wfu_check_animation();wfu_BrowserCaps.isSafari=Object.prototype.toString.call(window.HTMLElement).indexOf("Constructor")>0}
15
- function wfu_check_animation(){var animation=false,animationstring="animation",keyframeprefix="",domPrefixes="Webkit Moz O ms Khtml".split(" "),pfx="";var elm=document.createElement("DIV");if(elm.style.animationName)animation=true;if(animation===false)for(var i=0;i<domPrefixes.length;i++)if(elm.style[domPrefixes[i]+"AnimationName"]!==undefined){pfx=domPrefixes[i];animationstring=pfx+"Animation";keyframeprefix="-"+pfx.toLowerCase()+"-";animation=true;break}return animation}
16
- function wfu_join_strings(delimeter){var args=[].slice.call(arguments);var str="";var delim="";for(var i=1;i<args.length;i++){if(str==""||args[i]=="")delim="";else delim=delimeter;str+=delim+args[i]}return str}
17
- function wfu_plugin_decode_string(str){var i=0;var newstr="";var num,val;while(i<str.length){num=parseInt(str.substr(i,2),16);if(num<128)val=num;else if(num<224)val=((num&31)<<6)+(parseInt(str.substr(i+=2,2),16)&63);else val=((num&15)<<12)+((parseInt(str.substr(i+=2,2),16)&63)<<6)+(parseInt(str.substr(i+=2,2),16)&63);newstr+=String.fromCharCode(val);i+=2}return newstr}
18
- function wfu_plugin_encode_string(str){var i=0;var newstr="";var hex="";for(i=0;i<str.length;i++){num=str.charCodeAt(i);if(num>=2048)num=((num&16773120|917504)<<4)+((num&4032|8192)<<2)+(num&63|128);else if(num>=128)num=((num&65472|12288)<<2)+(num&63|128);hex=num.toString(16);if(hex.length==1||hex.length==3||hex.length==5)hex="0"+hex;newstr+=hex}return newstr}
19
- function wfu_decode_array_from_string(str){var arr_str=wfu_plugin_decode_string(str);var arr=null;try{arr=JSON.parse(arr_str)}catch(e){}return arr}function wfu_randomString(len){var chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";var string_length=len;var randomstring="";for(var i=0;i<string_length;i++){var rnum=Math.floor(Math.random()*chars.length);randomstring+=chars.substring(rnum,rnum+1)}return randomstring}
20
- function wfu_addEventHandler(obj,evt,handler){if(obj.addEventListener)obj.addEventListener(evt,handler,false);else if(obj.attachEvent)obj.attachEvent("on"+evt,handler);else obj["on"+evt]=handler}function wfu_attach_element_handlers(item,handler){var elem_events=["DOMAttrModified","textInput","input","change","keypress","paste","focus","propertychange"];for(var i=0;i<elem_events.length;i++)wfu_addEventHandler(item,elem_events[i],handler)}
21
- function wfu_GetHttpRequestObject(){var xhr=null;try{xhr=new XMLHttpRequest}catch(e$1){try{xhr=new ActiveXObject("Msxml2.XMLHTTP")}catch(e2){try{xhr=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}}}if(xhr==null&&window.createRequest)try{xmlhttp=window.createRequest()}catch(e$2){}return xhr}
22
- function wfu_get_filelist(sid,include_filearray){var WFU=GlobalData.WFU[sid];include_filearray=typeof include_filearray!=="undefined"?include_filearray:true;var farr=[];if(!!WFU.uploadform_exist)farr=WFU.uploadform.files();if(include_filearray&&typeof WFU.filearray!=="undefined")farr=WFU.filearray;return farr}
23
- function wfu_add_files(sid,files){var WFU=GlobalData.WFU[sid];if(typeof WFU.filearray=="undefined"){WFU.filearray=Array();WFU.filearrayprops=Array()}if(!!WFU.uploadform_exist)WFU.uploadform.reset();WFU.filearray.length=WFU.filearrayprops.length=0;for(var i=0;i<files.length;i++){WFU.filearray.push(files[i].file);WFU.filearrayprops.push(files[i].props)}}
24
- function wfu_attach_cancel_event(sid,unique_upload_id){function wfu_cancel_classic_upload_final(){var Params=wfu_Initialize_Params();Params.general.shortcode_id=sid;Params.general.unique_id="";Params.general.files_count=0;Params.general.state=16;wfu_ProcessUploadComplete(sid,0,Params,"no-ajax","",[false,null,false]);if(!!WFU.uploadform_exist){WFU.uploadform.reset();WFU.uploadform.submit();WFU.uploadform.lock()}}function wfu_cancel_classic_upload(){var url=GlobalData.consts.ajax_url+"?action=wfu_ajax_action_cancel_upload&wfu_uploader_nonce="+
25
- document.getElementById("wfu_uploader_nonce_"+sid).value+"&sid="+sid+"&unique_id="+unique_upload_id+"&session_token="+GlobalData.WFU[sid].session;var xmlhttp=wfu_GetHttpRequestObject();if(xmlhttp==null){var i=document.createElement("iframe");if(i){i.style.display="none";i.src=url;document.body.appendChild(i);i.onload=function(){wfu_cancel_classic_upload_final()};return}}xmlhttp.open("GET",url,true);xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4&&xmlhttp.status==200)wfu_cancel_classic_upload_final()};
26
- xmlhttp.send(null)}var WFU=GlobalData.WFU[sid];if(!!WFU.textbox_exist){var textbox_cancel_function=function(){var answer=false;if(WFU.is_formupload){answer=confirm(GlobalData.consts.cancel_upload_prompt);if(answer==true)wfu_cancel_classic_upload()}else{if(!GlobalData[sid]||GlobalData[sid].xhrs.length==0)return false;var answer=confirm(GlobalData.consts.cancel_upload_prompt);if(answer==true){var farr=wfu_get_filelist(sid);var firstxhr=[];var filename=[];for(var i=0;i<farr.length;i++){firstxhr.push(null);
27
- filename.push(farr[i].name)}for(var i=0;i<GlobalData[sid].xhrs.length;i++){var file_ind=GlobalData[sid].xhrs[i].file_id-1;if(file_ind>=0&&firstxhr[file_ind]==null)firstxhr[file_ind]=GlobalData[sid].xhrs[i]}if(WFU.debugmode)console.log("upload cancelled!");for(var i=0;i<firstxhr.length;i++){if(firstxhr[i]==null){firstxhr[i]=wfu_GetHttpRequestObject();if(firstxhr[i]!=null)wfu_initialize_fileupload_xhr(firstxhr[i],sid,unique_upload_id,i,filename[i])}if(firstxhr[i]!=-1){var evt={target:{responseText:"force_cancel_code",
28
- shortcode_id:sid}};wfu_uploadComplete.call(firstxhr[i],evt)}}}}return answer};WFU.textbox.attachCancelHandler(textbox_cancel_function)}}function wfu_dettach_cancel_event(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.textbox_exist)WFU.textbox.dettachCancelHandler()}
29
- function wfu_selectbutton_changed(sid,usefilearray){if(!wfu_BrowserCaps.supportsAJAX||!wfu_BrowserCaps.supportsHTML5)usefilearray=0;var farr=wfu_get_filelist(sid,false);if(usefilearray==1){if(typeof GlobalData.WFU[sid].filearray=="undefined")GlobalData.WFU[sid].filearray=Array();for(var i=0;i<farr.length;i++)GlobalData.WFU[sid].filearray.push(farr[i])}else if(typeof GlobalData.WFU[sid].filearray!="undefined")delete GlobalData.WFU[sid].filearray;wfu_update_filename_text(sid)}
30
- function wfu_selectbutton_clicked(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.message_exist)WFU.message.reset();var resetform=true;if(resetform)if(!!WFU.uploadform_exist)WFU.uploadform.reset()}function wfu_update_uploadbutton_status(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.submit_exist){var submit=WFU.submit;var farr=wfu_get_filelist(sid);var status=farr.length>0||WFU.allownofile;status=wfu_Code_Objects[sid].apply_filters("uploadbutton_status",status);submit.toggle(status)}}
31
- function wfu_update_filename_text(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.textbox_exist){var farr=wfu_get_filelist(sid);var filenames=[];for(var i=0;i<farr.length;i++)filenames.push(farr[i].name);WFU.textbox.update("set",filenames)}}
32
- function wfu_init_userdata_handlers(sid,key){var WFU=GlobalData.WFU[sid];var props=WFU.userdata.props[key];var JS=WFU.userdata.codes[key];var obj=WFU.userdata;JS.init=function(){};JS.value=function(){return""};JS.lock=function(){};JS.unlock=function(){};JS.reset=function(){};JS.empty=function(){return""};JS.validate=null;JS.typehook=null;if(props.type=="text"){JS.init=function(){obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};
33
- JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""}}else if(props.type=="multitext"){JS.init=function(){obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===
34
- ""?obj.error_empty:""}}else if(props.type=="number"){JS.init=function(){obj.attachHandlers(props,function(e){if(props.typehook)JS.typehook(e);else props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""};JS.validate=function(){var re=/^(\+|\-)?[0-9]*$/i;if(props.format==
35
- "f")re=/^(\+|\-)?[0-9]*?\.?[0-9]*$/i;return re.test(obj.getValue(props))?"":obj.error_invalid_number};JS.typehook=function(e){var re=/^(\+|\-)?[0-9]*$/i;if(props.format=="f")re=/^(\+|\-)?[0-9]*?\.?[0-9]*$/i;if(re.test(e.target.value))props.store();else e.target.value=props.getstored()}}else if(props.type=="email"){JS.init=function(){obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};
36
- JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""};JS.validate=function(){if(obj.getValue(props)=="")return"";var re=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return re.test(obj.getValue(props))?"":obj.error_invalid_email}}else if(props.type=="confirmemail"){JS.init=function(){obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};
37
- JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""};JS.validate=function(){var baseprops=null;for(var i=0;i<WFU.userdata.props.length;i++)if(WFU.userdata.props[i]&&WFU.userdata.props[i].type=="email"&&WFU.userdata.props[i].group==props.group){baseprops=WFU.userdata.props[i];break}return baseprops!=null?obj.getValue(props)==obj.getValue(baseprops)?
38
- "":obj.error_confirm_email_nomatch:obj.error_confirm_email_nobase}}else if(props.type=="password"){JS.init=function(){obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""}}else if(props.type=="confirmpassword"){JS.init=function(){obj.attachHandlers(props,
39
- function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""};JS.validate=function(){var baseprops=null;for(var i=0;i<WFU.userdata.props.length;i++)if(WFU.userdata.props[i]&&WFU.userdata.props[i].type=="password"&&WFU.userdata.props[i].group==props.group){baseprops=
40
- WFU.userdata.props[i];break}return baseprops!=null?obj.getValue(props)==obj.getValue(baseprops)?"":obj.error_confirm_password_nomatch:obj.error_confirm_password_nobase}}else if(props.type=="checkbox"){JS.init=function(){obj.initField(props);obj.setValue(props,props["default"]=="true");obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)?"true":"false"};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,
41
- props["default"]=="true");props.store()};JS.empty=function(){return!obj.getValue(props)?obj.error_checkbox_notchecked:""}}else if(props.type=="radiobutton"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?
42
- obj.error_radio_notselected:""}}else if(props.type=="date"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){def=props["default"].trim();if(def.substr(0,1)=="("&&def.substr(def.length-1,1)==")")def=def.substr(1,def.length-2);else def="";obj.setValue(props,def);props.store()};JS.empty=function(){return obj.getValue(props)===
43
- ""?obj.error_empty:""}}else if(props.type=="time"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){def=props["default"].trim();if(def.substr(0,1)=="("&&def.substr(def.length-1,1)==")")def=def.substr(1,def.length-2);else def="";obj.setValue(props,def);props.store()};JS.empty=function(){return obj.getValue(props)===
44
- ""?obj.error_empty:""}}else if(props.type=="datetime"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){def=props["default"].trim();if(def.substr(0,1)=="("&&def.substr(def.length-1,1)==")")def=def.substr(1,def.length-2);else def="";obj.setValue(props,def);props.store()};JS.empty=function(){return obj.getValue(props)===
45
- ""?obj.error_empty:""}}else if(props.type=="list"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""}}else if(props.type=="dropdown"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,
46
- function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""}}else if(props.type=="honeypot"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};
47
- JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""}}JS.init()}function wfu_Redirect(link){window.location=link}function wfu_loadStart(evt){}
48
- function wfu_update_upload_metrics(sid){var totalsize=0;var totalloaded=0;var totaldelta=0;var metrics=Array();var farr=wfu_get_filelist(sid);for(var i=0;i<farr.length;i++)metrics[i]={size:farr[i].size,aborted:false,loaded:0,delta:0};for(var i=0;i<GlobalData[sid].xhrs.length;i++){var file_id=GlobalData[sid].xhrs[i].file_id;if(file_id>0&&GlobalData[sid].xhrs[i].aborted)metrics[file_id-1].aborted=true}for(var i=0;i<GlobalData[sid].xhrs.length;i++){var file_id=GlobalData[sid].xhrs[i].file_id;if(file_id>
49
- 0&&!metrics[file_id-1].aborted){metrics[file_id-1].size=Math.max(GlobalData[sid].xhrs[i].totalsize,metrics[file_id-1].size);metrics[file_id-1].loaded+=GlobalData[sid].xhrs[i].sizeloaded;metrics[file_id-1].delta+=Math.max(GlobalData[sid].xhrs[i].deltaloaded,0)}}for(var i=0;i<farr.length;i++){var Gm=GlobalData[sid].metrics[i];if(!metrics[i].aborted&&metrics[i].size>0){Gm.size=metrics[i].size;if(GlobalData.consts.wfu_uploadprogress_mode=="incremental")Gm.progress_pos=Math.min(Gm.progress_pos+(1-Gm.progress_pos)*
50
- metrics[i].delta/(Gm.size-Gm.loaded),1);else Gm.progress_pos=metrics[i].loaded/metrics[i].size;Gm.loaded=metrics[i].loaded;totalsize+=Gm.size;totalloaded+=Gm.loaded;totaldelta+=metrics[i].delta}else{Gm.size=0;Gm.progress_pos=0;Gm.loaded=0}}var Gm=GlobalData[sid].metricstotal;Gm.size=totalsize;if(GlobalData.consts.wfu_uploadprogress_mode=="incremental")Gm.progress_pos=Math.min(Gm.progress_pos+(1-Gm.progress_pos)*totaldelta/(Gm.size-Gm.loaded),1);else Gm.progress_pos=totalloaded/totalsize;Gm.loaded=
51
- totalloaded}
52
- function wfu_uploadProgress(evt,sid,xhrid,debugmode){var WFU=GlobalData.WFU[sid];if(debugmode&&typeof this.xhr=="undefined"){console.log("total="+evt.total+", loaded="+evt.loaded);console.log(evt)}var this_xhr=GlobalData[sid].xhrs[xhrid];if(this_xhr.file_id==0)return;var percentComplete=0;var delta=0;var simplebar_exists=!!WFU.progressbar_exist;if(evt.lengthComputable){this_xhr.deltaloaded=evt.loaded-this_xhr.sizeloaded;this_xhr.sizeloaded=evt.loaded;if(this_xhr.size<evt.total&&evt.total>0){delta=
53
- evt.total-this_xhr.size;this_xhr.deltasize+=delta;this_xhr.size+=delta;for(var i=0;i<GlobalData[sid].xhrs.length;i++)if(GlobalData[sid].xhrs[i].file_id==this_xhr.file_id)GlobalData[sid].xhrs[i].totalsize+=delta}wfu_update_upload_metrics(sid);this_xhr.deltaloaded=0;if(simplebar_exists){percentComplete=Math.round(GlobalData[sid].metricstotal.progress_pos*100);WFU.progressbar.update(percentComplete)}}else if(simplebar_exists)WFU.progressbar.update(0)}
54
- function wfu_notify_WPFilebase(params_index,session_token){var xhr=wfu_GetHttpRequestObject();if(xhr==null){var i=document.createElement("iframe");i.style.display="none";i.src=GlobalData.consts.ajax_url+"?action=wfu_ajax_action_notify_wpfilebase&params_index="+params_index+"&session_token="+session_token;document.body.appendChild(i);return}var url=GlobalData.consts.ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_notify_wpfilebase";params[1]=
55
- new Array(2);params[1][0]="params_index";params[1][1]=params_index;params[2]=new Array(2);params[2][0]="session_token";params[2][1]=session_token;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){};xhr.send(parameters)}
56
- function wfu_send_email_notification(sid,unique_id){var WFU=GlobalData.WFU[sid];var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=GlobalData.consts.ajax_url;params=new Array(4);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_send_email_notification";params[1]=new Array(2);params[1][0]="params_index";params[1][1]=WFU.params_index;params[2]=new Array(2);params[2][0]="session_token";params[2][1]=WFU.session;params[3]=new Array(2);params[3][0]="uniqueuploadid_"+
57
- sid;params[3][1]=unique_id;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);wfu_initialize_fileupload_xhr(xhr,sid,unique_id,-1,"");xhr.success_message_header="";xhr.error_message_header="";xhr.error_adminmessage_unknown="";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.addEventListener("load",wfu_uploadComplete,false);xhr.addEventListener("error",wfu_uploadFailed,false);xhr.addEventListener("abort",
58
- wfu_uploadCanceled,false);xhr.send(parameters)}
59
- function wfu_uploadComplete(evt){var d=new Date;var sid=this.shortcode_id;var WFU=GlobalData.WFU[sid];var i=this.file_id;var last=false;var js_script_enc="";var upload_params="";var safe_params="";var file_status="unknown";var uploaded_file_props="";var debug_data=null;var success_txt="wfu_fileupload_success:";this.loading=false;this.end_time=d.getTime();var txt=evt.target.responseText;var result_data=txt;var error_code="error";if(txt!=-1){if(txt.indexOf("force_errorabort_code")>-1){error_code="errorabort";
60
- txt=txt.replace("force_errorabort_code","")}if(txt.indexOf("force_cancel_code")>-1){error_code="errorcancel";txt=txt.replace("force_cancel_code","")}if(txt.indexOf("force_abortsuccess_code")>-1){error_code="errorabortsuccess";txt=txt.replace("force_abortsuccess_code","")}}if(txt!=-1){var pos=txt.indexOf(success_txt);var debug_data_str="";if(pos>-1){if(WFU.debugmode)debug_data_str=txt.substr(0,pos);result_data=txt.substr(pos+success_txt.length);pos=result_data.indexOf(":");js_script_enc=result_data.substr(0,
61
- pos);result_data=result_data.substr(pos+1);pos=result_data.indexOf(":");safe_params=result_data.substr(0,pos);upload_params=result_data.substr(pos+1)}if(debug_data_str!=""){var title="";if(this.requesttype=="fileupload")title="Debug Data - File: "+this.file_id;else if(this.requesttype=="email")title="Debug Data - Email Notification";debug_data={title:title,data:debug_data_str}}if(safe_params!=""){var safe_parts=safe_params.split(";");if(parseInt(safe_parts[2])==1){var filedata=safe_parts[3].split(",");
62
- file_status=wfu_plugin_decode_string(filedata[0]);uploaded_file_props=filedata[4]}}}if(upload_params==""||safe_params==""){var Params=wfu_Initialize_Params();Params.general.shortcode_id=sid;Params.general.unique_id=this.unique_id;Params.general.state=7;Params.general.files_count=this.requesttype=="fileupload"?1:0;Params.general.upload_finish_time=this.finish_time;var file_colors=WFU.fail_colors.split(",");var file_header=this.error_message_header;var file_message_type=error_code;if(error_code=="errorabortsuccess"){Params.general.fail_message=
63
- "";Params.general.fail_admin_message="";file_colors=WFU.success_colors.split(",");file_header=this.success_message_header;file_message_type="success"}else if(error_code!="errorcancel"){Params.general.fail_message=GlobalData.consts.message_unknown;Params.general.fail_admin_message=wfu_join_strings("<br />",this.error_adminmessage_unknown,this.requesttype+":"+result_data)}else{Params.general.fail_message=GlobalData.consts.file_cancelled;Params.general.fail_admin_message=""}if(Params.general.files_count>
64
- 0){Params[0]={};Params[0]["color"]=file_colors[0];Params[0]["bgcolor"]=file_colors[1];Params[0]["borcolor"]=file_colors[2];Params[0]["message_type"]=file_message_type;file_status=error_code;Params[0]["header"]=file_header;Params[0]["message"]=GlobalData.consts.message_timelimit;Params[0]["admin_messages"]=WFU.is_admin?GlobalData.consts.message_admin_timelimit:""}else Params.general.admin_messages.other=WFU.is_admin?GlobalData.consts.message_admin_timelimit:"";if(Params.general.upload_finish_time>
65
- 0)if(d.getTime()<Params.general.upload_finish_time)if(Params.general.files_count>0){Params[0]["message"]=Params.general.fail_message;Params[0]["admin_messages"]=WFU.is_admin?Params.general.fail_admin_message:""}else Params.general.admin_messages.other=WFU.is_admin?Params.general.fail_admin_message:""}if(upload_params==""||safe_params==""){if(WFU.debugmode)console.log("wfu_ProcessUploadComplete: ",sid,this.file_id,"Params obj",this.unique_id,"",[WFU.debugmode,debug_data,WFU.is_admin],this.requesttype,
66
- "");last=wfu_ProcessUploadComplete(sid,this.file_id,Params,this.unique_id,"",[WFU.debugmode,debug_data,WFU.is_admin],this.requesttype,"")}else{if(WFU.debugmode)console.log("wfu_ProcessUploadComplete: ",sid,this.file_id,"Params str",this.unique_id,safe_params,[WFU.debugmode,debug_data,WFU.is_admin],this.requesttype,js_script_enc);last=wfu_ProcessUploadComplete(sid,this.file_id,upload_params,this.unique_id,safe_params,[WFU.debugmode,debug_data,WFU.is_admin],this.requesttype,js_script_enc)}if(last){wfu_dettach_cancel_event(sid);
67
- wfu_unlock_upload(sid);if(!!WFU.progressbar_exist)WFU.progressbar.hide();wfu_clear(sid)}if(evt.target.return_status)return file_status}
68
- function wfu_ProcessUploadComplete(sid,file_id,upload_params,unique_id,safe_output,debug_data,request_type,js_script_enc){var WFU=GlobalData.WFU[sid];if(!sid||sid<0)return;if(upload_params==null||upload_params=="")return;if(unique_id=="")return;if(unique_id!="no-ajax"&&!GlobalData[sid])return;var do_redirect=false;if(typeof upload_params==="string"){upload_params=wfu_plugin_decode_string(upload_params.replace(/^\s+|\s+$/g,""));var Params=null;try{Params=JSON.parse(upload_params)}catch(e){}if(Params==
69
- null){var safe_parts=safe_output.split(";");Params=wfu_Initialize_Params();Params.general.shortcode_id=sid;Params.general.unique_id=unique_id;Params.general.state=safe_parts[0];if(Params.general.state==4)Params.general.state++;var default_colors=safe_parts[1].split(",");var filedata="";var error_jsonparse_filemessage=GlobalData.consts.jsonparse_filemessage;var error_jsonparse_message=GlobalData.consts.jsonparse_message;var error_jsonparse_adminmessage=GlobalData.consts.jsonparse_adminmessage;Params.general.files_count=
70
- parseInt(safe_parts[2]);for(var i=0;i<Params.general.files_count;i++){Params[i]={};Params[i]["color"]=default_colors[0];Params[i]["bgcolor"]=default_colors[1];Params[i]["borcolor"]=default_colors[2];filedata=safe_parts[i+3].split(",");Params[i]["message_type"]=wfu_plugin_decode_string(filedata[0]);Params[i]["header"]=wfu_plugin_decode_string(filedata[1]);if(Params[i]["message_type"]=="success"){Params[i]["header"]+=error_jsonparse_filemessage;Params[i]["message_type"]="warning"}Params[i]["message"]=
71
- wfu_join_strings("<br />",error_jsonparse_message,wfu_plugin_decode_string(filedata[2]));Params[i]["admin_messages"]=wfu_join_strings("<br />",error_jsonparse_adminmessage,wfu_plugin_decode_string(filedata[3]))}}}else if(typeof upload_params==="object")var Params=upload_params;else return;if(WFU.debugmode)console.log("wfu_ProcessUploadComplete debug: ",debug_data);if(WFU.debugmode)console.log("wfu_ProcessUploadComplete Params: ",Params);var message_types=[];i=0;while(Params[i]){if(Params[i].message_type){message_types.push(Params[i].message_type);
72
- if(Params[i].message_type.substr(0,5)=="error")Params[i].message_type=Params[i].message_type.substr(0,5)}i++}if(!GlobalData[sid])GlobalData[sid]=Object();var G=GlobalData[sid];if(unique_id=="no-ajax"){G.last=false;G.unique_id="";G.files_count=Params.general.files_count;if(Params.general.state==0)Params.general.files_count=0;G.files_processed=Params.general.files_count;G.upload_state=Params.general.state;G.nofileupload=Params.general.state>12&&Params.general.state<16;if(!("message"in G))G.message=
73
- [];if(Params.general.message!="")G.message.push(Params.general.message);else G.message=[];G.update_wpfilebase=Params.general.update_wpfilebase;G.redirect_link=Params.general.redirect_link;G.notify_by_email=0;G.admin_messages={};G.admin_messages.wpfilebase=Params.general.admin_messages.wpfilebase;G.admin_messages.notify=Params.general.admin_messages.notify;G.admin_messages.redirect=Params.general.admin_messages.redirect;if(!("debug"in G.admin_messages))G.admin_messages.debug=[];if(debug_data[1]!==
74
- null)G.admin_messages.debug.push(debug_data[1]);if(!("other"in G.admin_messages))G.admin_messages.other=[];if(Params.general.admin_messages.other!="")G.admin_messages.other.push(Params.general.admin_messages.other);G.errors={};G.errors.wpfilebase=Params.general.errors.wpfilebase;G.errors.notify=Params.general.errors.notify;G.errors.redirect=Params.general.errors.redirect;G.current_size=0;G.total_size=0}else{if(G.unique_id==""||G.unique_id!=unique_id||G.unique_id!=Params.general.unique_id)return;if(G.last)return;
75
- if(Params.general.files_count==0&&Params[0])if(Params[0].message_type=="error")Params.general.files_count=1;var file_status="";for(var i=0;i<Params.general.files_count;i++){if(Params[i].message_type=="error"&&G.files_processed==0)file_status="error1";else if(Params[i].message_type=="error"&&G.files_processed>0)file_status="error2";else file_status=Params[i].message_type;G.upload_state=GlobalData.filestatematch[file_status][G.upload_state]}G.files_processed+=Params.general.files_count;if(Params.general.message!=
76
- "")G.message.push(Params.general.message);if(G.update_wpfilebase=="")G.update_wpfilebase=Params.general.update_wpfilebase;if(!request_type||request_type&&request_type!="email")G.redirect_link=Params.general.redirect_link;G.notify_by_email+=parseInt("0"+Params.general.notify_by_email);if(debug_data[1]!==null)G.admin_messages.debug.push(debug_data[1]);if(Params.general.admin_messages.other!="")G.admin_messages.other.push(Params.general.admin_messages.other);if(G.admin_messages.wpfilebase=="")G.admin_messages.wpfilebase=
77
- Params.general.admin_messages.wpfilebase;if(G.admin_messages.notify=="")G.admin_messages.notify=Params.general.admin_messages.notify;if(G.admin_messages.redirect=="")G.admin_messages.redirect=Params.general.admin_messages.redirect;if(G.errors.wpfilebase=="")G.errors.wpfilebase=Params.general.errors.wpfilebase;if(G.errors.notify=="")G.errors.notify=Params.general.errors.notify;if(G.errors.redirect=="")G.errors.redirect=Params.general.errors.redirect}if(G.files_processed==G.files_count){G.last=true;
78
- if(G.update_wpfilebase!=""){G.admin_messages.wpfilebase="";wfu_notify_WPFilebase(WFU.params_index,WFU.session)}if(G.notify_by_email>0){G.admin_messages.notify="";wfu_send_email_notification(sid,unique_id);G.last=false;G.notify_by_email=0}if(G.last){if(unique_id!="no-ajax"&&!G.nofileupload)wfu_notify_server_upload_ended(sid,unique_id);GlobalData.UploadInProgressString=GlobalData.UploadInProgressString.replace(new RegExp("\\["+unique_id+"\\]","g"),"")}if(G.errors.redirect!="")G.redirect_link="";if(G.redirect_link!=
79
- ""&&G.last&&GlobalData.UploadInProgressString.trim()==""){G.upload_state=11;do_redirect=true}}var nonadmin_message=G.message;var admin_message=[].concat(G.admin_messages.other,G.admin_messages.wpfilebase!=""?[G.admin_messages.wpfilebase]:[],G.admin_messages.notify!=""?[G.admin_messages.notify]:[],G.admin_messages.redirect!=""?[G.admin_messages.redirect]:[]);if(G.last)if(G.nofileupload){if(unique_id!="no-ajax")if(G.upload_state==0)G.upload_state=14;else if(G.upload_state<4)G.upload_state=15;if(G.upload_state==
80
- 15&&Params[0]){nonadmin_message.push(Params[0].message);admin_message.push(Params[0].admin_messages)}}else{if(G.files_count>0&&G.store_nothing&&G.upload_state<3)G.upload_state=19;if(G.files_count==0&&G.upload_state!=12&&G.upload_state<16)G.upload_state=8;else if(G.upload_state<4)G.upload_state+=4;if(G.upload_state==4&&admin_message.length>0)G.upload_state++;else if(G.upload_state==5&&admin_message.length==0&&nonadmin_message.length==0)G.upload_state--}if(!!WFU.message_exist){var suffix="";if(G.files_count==
81
- 1&&(G.upload_state==5||G.upload_state==7))suffix="_singlefile";var final_upload_state=G.upload_state==0&&G.nofileupload?13:G.upload_state;var data={files_count:!G.nofileupload?G.files_count:0,files_processed:!G.nofileupload?G.files_processed:0,state:final_upload_state,single:G.files_count==1&&nonadmin_message.length==0&&admin_message.length==0&&G.last&&!do_redirect&&!G.nofileupload,color:GlobalData.States["State"+final_upload_state+suffix].color,bgcolor:GlobalData.States["State"+final_upload_state+
82
- suffix].bgcolor,borcolor:GlobalData.States["State"+final_upload_state+suffix].borcolor,message1:GlobalData.States["State"+final_upload_state+suffix].message,message2:nonadmin_message,message3:admin_message,debug_data:G.admin_messages.debug,files:[]};for(var i=0;i<Params.general.files_count;i++)data.files[i]={index:i+file_id,result:Params[i].message_type,message1:Params[i].header,message2:Params[i].message,message3:Params[i].admin_messages};WFU.message.update(data)}if(js_script_enc)eval(wfu_plugin_decode_string(js_script_enc));
83
- if(do_redirect)wfu_Redirect(G.redirect_link);return G.last}function wfu_uploadFailed(evt,debugmode){if(debugmode){console.log("failure report following");console.log(evt)}var xhr=evt.target;var new_evt={target:{responseText:"",shortcode_id:xhr.shortcode_id}};wfu_uploadComplete.call(xhr,new_evt)}function wfu_uploadCanceled(evt){}
84
- function wfu_notify_server_upload_ended(sid,unique_id){var WFU=GlobalData.WFU[sid];var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=GlobalData.consts.ajax_url;params=new Array(6);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action";params[1]=new Array(2);params[1][0]="wfu_uploader_nonce";params[1][1]=document.getElementById("wfu_uploader_nonce_"+sid).value;params[2]=new Array(2);params[2][0]="uniqueuploadid_"+sid;params[2][1]=unique_id;params[3]=new Array(2);params[3][0]=
85
- "params_index";params[3][1]=WFU.params_index;params[4]=new Array(2);params[4][0]="session_token";params[4][1]=WFU.session;params[5]=new Array(2);params[5][0]="upload_finished";params[5][1]=1;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200)wfu_Code_Objects[sid].do_action("after_upload",
86
- xhr.responseText)};xhr.send(parameters)}
87
- function wfu_Initialize_Params(){var params={};params.version="full";params.general={};params.general.shortcode_id=0;params.general.unique_id="";params.general.state=0;params.general.files_count=0;params.general.update_wpfilebase="";params.general.redirect_link="";params.general.upload_finish_time=0;params.general.message="";params.general.message_type="";params.general.admin_messages={};params.general.admin_messages.wpfilebase="";params.general.admin_messages.notify="";params.general.admin_messages.redirect=
88
- "";params.general.admin_messages.other="";params.general.errors={};params.general.errors.wpfilebase="";params.general.errors.notify="";params.general.errors.redirect="";params.general.color="";params.general.bgcolor="";params.general.borcolor="";params.general.notify_by_email=0;params.general.fail_message="";params.general.fail_admin_message="";return params}
89
- function wfu_redirect_to_classic(sid,flag,adminerrorcode){var WFU=GlobalData.WFU[sid];WFU.is_formupload=true;var numfiles=wfu_filesselected(sid);if(numfiles==0&&!WFU.allownofile)return;if(!!WFU.subfolders_exist&&numfiles>0&&!WFU.subfolders.check())return;if(!wfu_check_required_userdata(sid,true))return;if(!wfu_Code_Objects[sid].apply_filters("pre_start_check",true))return;wfu_redirect_to_classic_cont(sid,flag,adminerrorcode)}
90
- function wfu_redirect_to_classic_cont(sid,flag,adminerrorcode){var process_function=function(responseText){var WFU=GlobalData.WFU[sid];var txt_value="";var session_token=WFU.session;var success_txt="wfu_askserver_success:";var error_txt="wfu_askserver_error:";var pos_success=responseText.indexOf(success_txt);var pos_error=responseText.indexOf(error_txt);if(pos_success>-1){txt_value=responseText.substr(pos_success+success_txt.length);var numfiles=wfu_filesselected(sid);var nofileupload=numfiles==0&&
91
- WFU.allownofile;wfu_Code_Objects[sid].do_action("askserver_success",txt_value,"no-ajax");if(!!WFU.progressbar_exist&&!nofileupload)WFU.progressbar.show("shuffle");wfu_attach_cancel_event(sid,unique_id);var Params=wfu_Initialize_Params();Params.general.shortcode_id=sid;Params.general.unique_id="";Params.general.files_count=numfiles;if(nofileupload)Params.general.state=13;wfu_ProcessUploadComplete(sid,0,Params,"no-ajax","",[false,null,false]);document.getElementById("uniqueuploadid_"+sid).value=unique_id;
92
- document.getElementById("nofileupload_"+sid).value=nofileupload?"1":"0";var suffix="";var redirected_txt="";if(flag==1)redirected_txt="_redirected";if(!!WFU.uploadform_exist){WFU.uploadform.changeFileName("uploadedfile_"+sid+redirected_txt+suffix);document.getElementById("uploadedfile_"+sid+"_name").name="uploadedfile_"+sid+redirected_txt+"_name";document.getElementById("uploadedfile_"+sid+"_size").name="uploadedfile_"+sid+redirected_txt+"_size"}if(adminerrorcode>0)document.getElementById("adminerrorcodes_"+
93
- sid).value=adminerrorcode;else document.getElementById("adminerrorcodes_"+sid).value="";if(!!WFU.uploadform_exist){WFU.uploadform.submit();WFU.uploadform.lock()}}else if(pos_error>-1){txt_value=responseText.substr(pos_error+error_txt.length);wfu_unlock_upload(sid);wfu_Code_Objects[sid].do_action("askserver_error",txt_value)}};var unique_id=wfu_randomString(10);wfu_lock_upload(sid);wfu_Code_Objects[sid].do_action("pre_start");var pass_params="";var params_obj=wfu_Code_Objects[sid].apply_filters("askserver_pass_params",
94
- {});for(var prop in params_obj)if(params_obj.hasOwnProperty(prop))pass_params+="&"+prop+"="+params_obj[prop];var d=new Date;var url=GlobalData.consts.ajax_url+"?action=wfu_ajax_action_ask_server&wfu_uploader_nonce="+document.getElementById("wfu_uploader_nonce_"+sid).value+"&sid="+sid+"&unique_id="+unique_id+"&start_time="+d.getTime()+"&session_token="+GlobalData.WFU[sid].session+pass_params;var xmlhttp=wfu_GetHttpRequestObject();if(xmlhttp==null){var i=document.createElement("iframe");if(i){i.style.display=
95
- "none";i.src=url;document.body.appendChild(i);i.onload=function(){process_function(i.contentDocument.body.innerHTML)};return}else{wfu_Code_Objects[sid].do_action("not_supported");return}}xmlhttp.open("GET",url,true);xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4)if(xmlhttp.status==200)process_function(xmlhttp.responseText);else{alert(GlobalData.consts.remoteserver_noresult);wfu_Code_Objects[sid].do_action("askserver_noresult")}};xmlhttp.send(null)}
96
- Code_Initializators[Code_Initializators.length]=function(sid){var CBUV_Code_Objects={};CBUV_Code_Objects.pre_start_check=function(attr){if(!attr)return attr;var sid=this.sid;var result=true;if(!!GlobalData.WFU[sid].consent_exist){if(GlobalData.WFU[sid].consent.consent_format!="prompt"&&document.getElementById("consentresult_"+sid).value==""){alert(GlobalData.consts.wfu_consent_notcompleted);result=false}else if(GlobalData.WFU[sid].consent.consent_format=="prompt"){document.getElementById("consentresult_"+
97
- sid).value=confirm(GlobalData.WFU[sid].consent.consent_question)?"yes":"no";result=true}if(GlobalData.WFU[sid].consent.no_rejects_upload&&document.getElementById("consentresult_"+sid).value=="no"){alert(GlobalData.WFU[sid].consent_rejection_message);result=false}}return result};CBUV_Code_Objects.pre_start_ask_server=function(attr,has_filters){if(attr)return attr;var sid=this.sid;var consent_ask_server=GlobalData.WFU[sid].consent_maybe_ask_server&&!GlobalData.WFU[sid].consent_exist;return has_filters==
98
- "true"||consent_ask_server};CBUV_Code_Objects.askserver_pass_params=function(params){var sid=this.sid;var farr=wfu_get_filelist(sid);var filenames="";var filesizes="";for(var i=0;i<farr.length;i++){if(i>0){filenames+=";";filesizes+=";"}filenames+=wfu_plugin_encode_string(farr[i].name);filesizes+=farr[i].size}params.filenames=filenames;params.filesizes=filesizes;if(GlobalData.WFU[sid].consent_maybe_ask_server&&!GlobalData.WFU[sid].consent_exist){params.consent_check="1";params.consent_rejection_message=
99
- GlobalData.WFU[sid].consent_rejection_message}return params};CBUV_Code_Objects.askserver_success=function(response,mode){var sid=this.sid;var upload_status="success";var txt_match=response.match(/CBUVJS\[(.*?)\]/);var txt_header=txt_match?typeof txt_match[1]!="undefined"?txt_match[1]:"":"";if(txt_header!="")eval(wfu_plugin_decode_string(txt_header))};CBUV_Code_Objects.askserver_error=function(response,mode){var sid=this.sid;var upload_status="error";var txt_match=response.match(/CBUVJS\[(.*?)\]/);
100
- var txt_header=txt_match?typeof txt_match[1]!="undefined"?txt_match[1]:"":"";if(txt_header!="")eval(wfu_plugin_decode_string(txt_header));txt_match=response.match(/CBUV\[(.*?)\]/);txt_header=txt_match?typeof txt_match[1]!="undefined"?txt_match[1]:"":"";if(txt_header!=""){var Params=wfu_Initialize_Params();GlobalData[sid]={};Params.general.shortcode_id=sid;Params.general.message=txt_header;Params.general.state=12;wfu_ProcessUploadComplete(sid,0,Params,"no-ajax","",[false,null,false]);wfu_clear(sid)}};
101
- CBUV_Code_Objects.lock_upload=function(){var sid=this.sid;if(!!GlobalData.WFU[sid].consent_exist)GlobalData.WFU[sid].consent.update("lock")};CBUV_Code_Objects.unlock_upload=function(){var sid=this.sid;if(!!GlobalData.WFU[sid].consent_exist)GlobalData.WFU[sid].consent.update("unlock")};CBUV_Code_Objects.clear_upload=function(){var sid=this.sid;var WFU=GlobalData.WFU[sid];if(!!WFU.consent_exist)if(WFU.consent.remember_consent){WFU.consent.update("clear");WFU.consent_exist=false}else WFU.consent.update("init")};
102
- CBUV_Code_Objects.upload_pass_params=function(params,mode){var sid=this.sid;if(!!GlobalData.WFU[sid].consent_exist)params.consent_result=document.getElementById("consentresult_"+sid).value;return params};CBUV_Code_Objects.after_upload=function(response){var sid=this.sid;var txt_match=response.match(/CBUVJS\[(.*?)\]/);var txt_header=txt_match?typeof txt_match[1]!="undefined"?txt_match[1]:"":"";if(txt_header!="")eval(wfu_plugin_decode_string(txt_header))};return CBUV_Code_Objects};
103
- function wfu_filesselected(sid){var WFU=GlobalData.WFU[sid];var farr=wfu_get_filelist(sid);if(farr.length==0&&!WFU.allownofile&&!!WFU.textbox_exist)WFU.textbox.update("nofile");return farr.length}
104
- function wfu_check_required_userdata(sid,prompt){var WFU=GlobalData.WFU[sid];var userdata_count=wfu_get_userdata_count(sid);var req_empty=false;for(var i=0;i<userdata_count;i++){WFU.userdata.props[i].store();var error_message="";if(WFU.userdata.props[i].required)error_message=WFU.userdata.codes[i].empty();if(error_message===""&&WFU.userdata.codes[i].validate!=null&&WFU.userdata.props[i].validate)error_message=WFU.userdata.codes[i].validate();if(error_message!==""){if(prompt)WFU.userdata.prompt(WFU.userdata.props[i],
105
- error_message);req_empty=true}}return!req_empty}
106
- function wfu_HTML5UploadFile(sid){var WFU=GlobalData.WFU[sid];if(!wfu_BrowserCaps.supportsAJAX){wfu_redirect_to_classic(sid,1,1);return}if(!wfu_BrowserCaps.supportsHTML5){wfu_redirect_to_classic(sid,1,2);return}var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var numfiles=wfu_filesselected(sid);if(numfiles==0&&!WFU.allownofile)return;if(numfiles==0)wfu_selectbutton_clicked(sid);if(!!WFU.subfolders_exist&&numfiles>0&&!WFU.subfolders.check()){if(WFU.singlebutton)wfu_clear_files(sid);return}var numpasses=
107
- numfiles;numpasses+=numpasses;if(!wfu_check_required_userdata(sid,true)){if(WFU.singlebutton)wfu_clear_files(sid);return}if(!wfu_Code_Objects[sid].apply_filters("pre_start_check",true))return;var unique_upload_id=wfu_randomString(10);wfu_lock_upload(sid);wfu_Code_Objects[sid].do_action("pre_start");if(!wfu_Code_Objects[sid].apply_filters("pre_start_ask_server",false,WFU.has_filters?"true":"false"))wfu_HTML5UploadFile_cont(sid,unique_upload_id);else{var url=GlobalData.consts.ajax_url;params=new Array(5);
108
- params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_ask_server";params[1]=new Array(2);params[1][0]="session_token";params[1][1]=WFU.session;params[2]=new Array(2);params[2][0]="sid";params[2][1]=sid;params[3]=new Array(2);params[3][0]="unique_id";params[3][1]=unique_upload_id;params[4]=new Array(2);params[4][0]="wfu_uploader_nonce";params[4][1]=document.getElementById("wfu_uploader_nonce_"+sid).value;var params_obj=wfu_Code_Objects[sid].apply_filters("askserver_pass_params",
109
- {});for(var prop in params_obj)if(params_obj.hasOwnProperty(prop))params.push([prop,params_obj[prop]]);var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var txt=xhr.responseText;var txt_value="";var success_txt="wfu_askserver_success:";var error_txt="wfu_askserver_error:";
110
- var pos_success=txt.indexOf(success_txt);var pos_error=txt.indexOf(error_txt);var pos=-1;if(pos_success>-1){txt_value=txt.substr(pos_success+success_txt.length);wfu_Code_Objects[sid].do_action("askserver_success",txt_value,"ajax");wfu_HTML5UploadFile_cont(sid,unique_upload_id)}else if(pos_error>-1){txt_value=txt.substr(pos_error+error_txt.length);wfu_unlock_upload(sid);wfu_Code_Objects[sid].do_action("askserver_error",txt_value)}}else{alert(GlobalData.consts.remoteserver_noresult);wfu_unlock_upload(sid);
111
- wfu_Code_Objects[sid].do_action("askserver_noresult")}};xhr.send(parameters)}}
112
- function wfu_HTML5UploadFile_cont(sid,unique_upload_id){function sendfile(ind,file,only_check,force_close_connection){ret_status=true;var xhr=wfu_GetHttpRequestObject();var xhr_close_connection=wfu_GetHttpRequestObject();if(xhr==null||xhr_close_connection==null)return;var fd=null;var fd_close_connection=null;try{var fd=new FormData;var fd_close_connection=new FormData}catch(e){}if(fd==null||fd_close_connection==null)return;fd.append("action","wfu_ajax_action");fd.append("wfu_uploader_nonce",document.getElementById("wfu_uploader_nonce_"+
113
- sid).value);if(!only_check)fd.append("uploadedfile_"+sid+suffice,file);fd.append("uploadedfile_"+sid+"_index",ind);fd.append("uploadedfile_"+sid+"_name",wfu_plugin_encode_string(farr[ind].name));fd.append("uploadedfile_"+sid+"_size",farr[ind].size);fd.append("uniqueuploadid_"+sid,unique_upload_id);fd.append("params_index",WFU.params_index);fd.append("subdir_sel_index",subdir_sel_index);fd.append("nofileupload_"+sid,nofileupload?"1":"0");if(only_check)fd.append("only_check","1");else fd.append("only_check",
114
- "0");fd.append("session_token",WFU.session);var other_params=wfu_Code_Objects[sid].apply_filters("upload_pass_params",{},"ajax");for(var prop in other_params)if(other_params.hasOwnProperty(prop))fd.append(prop,other_params[prop]);var userdata_count=wfu_get_userdata_count(sid);for(var ii=0;ii<userdata_count;ii++)fd.append("hiddeninput_"+sid+"_userdata_"+ii,document.getElementById("hiddeninput_"+sid+"_userdata_"+ii).value);wfu_initialize_fileupload_xhr(xhr,sid,unique_upload_id,ind,farr[ind].name);xhr.loading=
115
- true;if(!only_check){xhr.size=file.size;xhr.totalsize=farr[ind].size}if(force_close_connection){fd_close_connection.append("action","wfu_ajax_action");fd_close_connection.append("wfu_uploader_nonce",document.getElementById("wfu_uploader_nonce_"+sid).value);fd_close_connection.append("params_index",WFU.params_index);fd_close_connection.append("session_token",WFU.session);fd_close_connection.append("force_connection_close","1");xhr_close_connection.open("POST",GlobalData.consts.ajax_url,false);try{xhr_close_connection.send(fd_close_connection)}catch(err){}ret_status=
116
- xhr_close_connection.responseText.indexOf("success")>-1}if(ret_status)if(!only_check){xhr.upload.xhr=xhr;xhr.upload.dummy=1;xhr.upload.addEventListener("loadstart",wfu_loadStart,false);xhr.upload.addEventListener("progress",new Function("evt","wfu_uploadProgress(evt, "+sid+", "+xhr.xhrid+", "+(WFU.debugmode?"true":"false")+");"),false);xhr.addEventListener("load",wfu_uploadComplete,false);xhr.addEventListener("error",new Function("evt","wfu_uploadFailed(evt, "+(WFU.debugmode?"true":"false")+");"),
117
- false);xhr.addEventListener("abort",wfu_uploadCanceled,false);xhr.open("POST",GlobalData.consts.ajax_url,true);xhr.send(fd)}else{xhr.addEventListener("load",function(evt){evt={target:{responseText:evt.target.responseText,shortcode_id:sid,return_status:true}};var file_status=wfu_uploadComplete.call(xhr,evt);xhr.file_id=0;ret_status=file_status=="success"||file_status=="warning";if(ret_status&&!nofileupload)sendfile(ind,file,false,false);else if(ret_status&&nofileupload);},false);xhr.addEventListener("error",
118
- function(evt){return},false);xhr.open("POST",GlobalData.consts.ajax_url,true);xhr.send(fd)}else{var evt={target:{responseText:"",shortcode_id:sid}};wfu_uploadComplete.call(xhr,evt)}inc++;return ret_status}var WFU=GlobalData.WFU[sid];var subdir_sel_index=-1;if(!!WFU.subfolders_exist)subdir_sel_index=WFU.subfolders.index();var farr=wfu_get_filelist(sid);var nofileupload=false;if(farr.length==0&&WFU.allownofile){nofileupload=true;farr=[{name:"dummy.txt",size:0}]}var suffice="";GlobalData.UploadInProgressString+=
119
- "["+unique_upload_id+"]";GlobalData[sid]={};GlobalData[sid].unique_id=unique_upload_id;GlobalData[sid].last=false;GlobalData[sid].files_count=1;GlobalData[sid].files_processed=0;GlobalData[sid].upload_state=0;GlobalData[sid].nofileupload=nofileupload;GlobalData[sid].store_nothing=!!WFU.consent_exist&&document.getElementById("consentresult_"+sid).value=="no"&&WFU.not_store_files;GlobalData[sid].message=[];GlobalData[sid].update_wpfilebase="";GlobalData[sid].redirect_link="";GlobalData[sid].notify_by_email=
120
- 0;GlobalData[sid].admin_messages={};GlobalData[sid].admin_messages.wpfilebase="";GlobalData[sid].admin_messages.notify="";GlobalData[sid].admin_messages.redirect="";GlobalData[sid].admin_messages.debug=[];GlobalData[sid].admin_messages.other=[];GlobalData[sid].errors={};GlobalData[sid].errors.wpfilebase="";GlobalData[sid].errors.notify="";GlobalData[sid].errors.redirect="";GlobalData[sid].xhrs=Array();GlobalData[sid].metricstotal={size:farr[0].size,loaded:0,progress_pos:0};GlobalData[sid].metrics=
121
- [{size:farr[0].size,loaded:0,progress_pos:0}];if(!!WFU.progressbar_exist&&!nofileupload)WFU.progressbar.show("progressive");wfu_attach_cancel_event(sid,unique_upload_id);var Params=wfu_Initialize_Params();Params.general.shortcode_id=sid;Params.general.unique_id=unique_upload_id;wfu_ProcessUploadComplete(sid,0,Params,unique_upload_id,"",[false,null,false]);var inc=0;var ret_status=true;var i=0;var fprops=[];sendfile(i,farr[i],true,false)}
122
- function wfu_initialize_fileupload_xhr(xhr,sid,unique_upload_id,file_ind,filename){var WFU=GlobalData.WFU[sid];var xhrid=file_ind>=0?GlobalData[sid].xhrs.push(xhr)-1:-1;var d=new Date;xhr.xhrid=xhrid;xhr.shortcode_id=sid;xhr.requesttype=file_ind>=0?"fileupload":"email";xhr.file_id=file_ind+1;xhr.size=0;xhr.totalsize=0;xhr.loading=false;xhr.deltasize=0;xhr.deltaloaded=0;xhr.sizeloaded=0;xhr.aborted=false;xhr.unique_id=unique_upload_id;xhr.start_time=d.getTime();xhr.end_time=xhr.start_time;xhr.finish_time=
123
- xhr.start_time+parseInt(GlobalData.consts.max_time_limit)*1E3;xhr.success_message_header=WFU.success_header.replace(/%username%/g,"no data");xhr.success_message_header=xhr.success_message_header.replace(/%useremail%/g,"no data");xhr.success_message_header=xhr.success_message_header.replace(/%filename%/g,filename);xhr.success_message_header=xhr.success_message_header.replace(/%filepath%/g,filename);xhr.error_message_header=WFU.error_header.replace(/%username%/g,"no data");xhr.error_message_header=
124
- xhr.error_message_header.replace(/%useremail%/g,"no data");xhr.error_message_header=xhr.error_message_header.replace(/%filename%/g,filename);xhr.error_message_header=xhr.error_message_header.replace(/%filepath%/g,filename);xhr.error_message_failed=GlobalData.consts.message_failed;xhr.error_message_cancelled=GlobalData.consts.message_cancelled;xhr.error_adminmessage_unknown=GlobalData.consts.adminmessage_unknown.replace(/%username%/g,"no data");xhr.error_adminmessage_unknown=xhr.error_adminmessage_unknown.replace(/%useremail%/g,
125
- "no data");xhr.error_adminmessage_unknown=xhr.error_adminmessage_unknown.replace(/%filename%/g,filename);xhr.error_adminmessage_unknown=xhr.error_adminmessage_unknown.replace(/%filepath%/g,filename)}function wfu_get_userdata_count(sid){var WFU=GlobalData.WFU[sid];var fields_count=0;if(!!WFU.userdata_exist)fields_count=WFU.userdata.props.length;return fields_count}
126
- function wfu_lock_upload(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.textbox_exist)WFU.textbox.update("lock");if(!!WFU.uploadform_exist)WFU.uploadform.lock();if(!!WFU.subfolders_exist)WFU.subfolders.toggle(false);if(!!WFU.submit_exist)WFU.submit.toggle(false);var userdata_count=wfu_get_userdata_count(sid);for(var i=0;i<userdata_count;i++)WFU.userdata.codes[i].lock();wfu_Code_Objects[sid].do_action("lock_upload")}
127
- function wfu_unlock_upload(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.textbox_exist)WFU.textbox.update("unlock");if(!!WFU.uploadform_exist)WFU.uploadform.unlock();if(!!WFU.subfolders_exist)WFU.subfolders.toggle(true);if(!!WFU.submit_exist)WFU.submit.toggle(true);var userdata_count=wfu_get_userdata_count(sid);for(var i=0;i<userdata_count;i++)WFU.userdata.codes[i].unlock();wfu_Code_Objects[sid].do_action("unlock_upload")}
128
- function wfu_clear_files(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.uploadform_exist)WFU.uploadform.reset();if(typeof WFU.filearray!="undefined"){WFU.filearray.length=0;WFU.filearrayprops.length=0}if(!!WFU.textbox_exist)WFU.textbox.update("clear")}
129
- function wfu_check_reset(sid){var WFU=GlobalData.WFU[sid];var G=GlobalData[sid];if(WFU.resetmode=="always")return true;else if(WFU.resetmode=="never")return false;else if(WFU.resetmode=="onsuccess")return[4,5,6,14].indexOf(G.upload_state)>-1;else if(WFU.resetmode=="onfullsuccess")return[4,5,14].indexOf(G.upload_state)>-1;else return true}
130
- function wfu_clear(sid){var WFU=GlobalData.WFU[sid];var do_reset=wfu_check_reset(sid);wfu_clear_files(sid);if(do_reset){if(!!WFU.subfolders_exist)WFU.subfolders.reset();var userdata_count=wfu_get_userdata_count(sid);for(var i=0;i<userdata_count;i++)WFU.userdata.codes[i].reset();if(!!WFU.uploadform_exist)WFU.uploadform.resetDummy()}wfu_Code_Objects[sid].do_action("clear_upload")}
131
- function wfu_invoke_shortcode_editor(WFU){var sid=WFU.shortcode_id;var same=0;var n=GlobalData.WFU.n;if(WFU.shortcode_tag=="wordpress_file_upload_browser")n=GlobalData.WFUB.n;for(var i=0;i<n.length;i++)if(n[i]==sid)same++;if(same==0)return;if(same>1){alert(GlobalData.consts.same_pluginid);return}var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;WFU.visualeditorbutton.update("on_invoke");var url=GlobalData.consts.ajax_url;params=new Array(6);params[0]=new Array(2);params[0][0]="action";params[0][1]=
132
- "wfu_ajax_action_edit_shortcode";params[1]=new Array(2);params[1][0]="upload_id";params[1][1]=sid;params[2]=new Array(2);params[2][0]="post_id";params[2][1]=WFU.post_id;params[3]=new Array(2);params[3][0]="post_hash";params[3][1]=WFU.post_hash;params[4]=new Array(2);params[4][0]="shortcode_tag";params[4][1]=WFU.shortcode_tag;params[5]=new Array(2);params[5][0]="widget_id";params[5][1]=WFU.widgetid?WFU.widgetid:"";var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+
133
- "="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){WFU.visualeditorbutton.update("on_open");var start_text="wfu_edit_shortcode:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);
134
- pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header=="success"){var editor_window=window.open(wfu_plugin_decode_string(txt_value),"_blank");if(editor_window)editor_window.plugin_window=window;else alert(GlobalData.consts.enable_popups)}else if(txt_header=="check_page_obsolete")alert(txt_value)}};xhr.send(parameters)}
135
- wfu_initialize_webcam=function(sid,mode,audiocapture,videowidth,videoheight,videoaspectratio,videoframerate,camerafacing,maxrecordtime){if(typeof wfu_parse_video_width=="undefined")wfu_parse_video_width=function(videowidth){var vw=parseInt(videowidth);if(vw>0){this.empty=false;this.video.width=vw}};if(typeof wfu_parse_video_height=="undefined")wfu_parse_video_height=function(videoheight){var vh=parseInt(videoheight);if(vh>0){this.empty=false;this.video.height=vh}};if(typeof wfu_parse_video_aspectratio==
136
- "undefined")wfu_parse_video_aspectratio=function(videoaspectratio){var ar=parseFloat(videoaspectratio);if(ar>0){this.empty=false;this.video.aspectRatio=ar}};if(typeof wfu_parse_video_framerate=="undefined")wfu_parse_video_framerate=function(videoframerate){var fr=parseFloat(videoframerate);if(fr>0){this.empty=false;this.video.frameRate=fr}};if(typeof wfu_parse_video_facingmode=="undefined")wfu_parse_video_facingmode=function(camerafacing){var cf=camerafacing=="front"?"user":camerafacing=="back"?"environment":
137
- "";if(cf!=""){this.empty=false;this.video.facingMode=cf}};var video_settings={empty:true,video:{}};wfu_parse_video_width.call(video_settings,videowidth);wfu_parse_video_height.call(video_settings,videoheight);wfu_parse_video_aspectratio.call(video_settings,videoaspectratio);wfu_parse_video_framerate.call(video_settings,videoframerate);wfu_parse_video_facingmode.call(video_settings,camerafacing);var WebcamProps={mode:mode,audio:audiocapture=="true",video:video_settings.empty?true:video_settings.video,
138
- maxrecordtime:maxrecordtime};GlobalData.WFU[sid].webcamProps=WebcamProps;wfu_reinitialize_webcam(sid)};
139
- wfu_reinitialize_webcam=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;webcam_props.active=true;webcam_props.width=0;webcam_props.width=0;webcam_props.timeStart=0;webcam_props.duration=0;webcam_props.counting=false;webcam_props.stream=null;webcam_props.media=null;webcam_props.blobs=null;webcam_props.playing=false;var WebcamProps=webcam_props;webcam_obj.updateStatus("idle");var constraints={audio:WebcamProps.audio,video:WebcamProps.video};if(typeof Promise==
140
- "undefined"){Promise=function(mainCallback){this.mainCallback=mainCallback;this.then=function(successCallback){this.successCallback=successCallback;return this};this["catch"]=function(errorCallback){mainCallback(this.successCallback,errorCallback)}};PromiseRejected=function(error){this.then=function(successCallback){return this};this["catch"]=function(errorCallback){errorCallback(error)}};Promise.reject=function(error){return new PromiseRejected(error)}}var promisifiedOldGUM=function(constraints,
141
- successCallback,errorCallback){var getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;if(!getUserMedia||typeof MediaRecorder=="undefined")return Promise.reject(new Error("getUserMedia is not implemented in this browser"));return new Promise(function(successCallback,errorCallback){getUserMedia.call(navigator,constraints,successCallback,errorCallback)})};if(navigator.mediaDevices===undefined)navigator.mediaDevices={};if(navigator.mediaDevices.getUserMedia===
142
- undefined)navigator.mediaDevices.getUserMedia=promisifiedOldGUM;navigator.mediaDevices.getUserMedia(constraints).then(function(stream){webcam_props.stream=stream;webcam_obj.setVideoProperties({autoplay:true,ontimeupdate:null,onerror:null,onloadeddata:function(e){wfu_webcam_init_callback(sid)},srcObject:stream});webcam_obj.initButtons(WebcamProps.mode)})["catch"](function(e){console.log("Video not supported!",e);webcam_obj.updateStatus("video_notsupported")})};
143
- wfu_webcam_init_callback=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;var video_size=webcam_obj.videoSize();webcam_props.width=video_size.width;webcam_props.height=video_size.height;webcam_obj.initCallback()};
144
- wfu_webcam_counter_status=function(sid,action){var webcam_props=GlobalData.WFU[sid].webcamProps;if(action=="start"){var d=new Date;webcam_props.duration=0;webcam_props.timeStart=d.getTime()/1E3;webcam_props.counting=true;wfu_webcam_update_counter(sid)}else{var d=new Date;webcam_props.duration=d.getTime()/1E3-webcam_props.timeStart;webcam_props.counting=false}};
145
- wfu_webcam_update_counter=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.counting){var d=new Date;var dif=d.getTime()/1E3-webcam_props.timeStart;webcam_obj.updateTimer(dif);setTimeout(function(){wfu_webcam_update_counter(sid)},100)}};
146
- wfu_webcam_onoff=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.active){webcam_obj.updateStatus("off");webcam_obj.updateButtonStatus("hidden");if(webcam_props.stream&&webcam_props.stream.stop)webcam_props.stream.stop();webcam_props.stream=null;webcam_props.media=null;webcam_props.blobs=null;webcam_props.active=false}else wfu_reinitialize_webcam(sid);wfu_selectbutton_clicked(sid)};
147
- wfu_webcam_golive=function(sid){var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.playing)return;wfu_reinitialize_webcam(sid);wfu_add_files(sid,[],false);wfu_selectbutton_clicked(sid);wfu_update_uploadbutton_status(sid)};
148
- wfu_webcam_start_rec=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.media&&webcam_props.media.state&&webcam_props.media.state=="recording")return;try{webcam_props.media=new MediaRecorder(webcam_props.stream)}catch(err){alert(GlobalData.consts.webcam_video_notsupported);return}webcam_props.blobs=[];webcam_props.media.ondataavailable=function(e){var d=new Date;var dif=d.getTime()/1E3-webcam_props.timeStart;if(webcam_props.maxrecordtime==
149
- -1||webcam_props.maxrecordtime>0&&dif<=webcam_props.maxrecordtime){if(e.data&&e.data.size>0)webcam_props.blobs.push(e.data)}else wfu_webcam_stop_rec(sid)};webcam_obj.updateButtonStatus("recording");wfu_webcam_counter_status(sid,"start");webcam_props.media.onstop=function(e){wfu_webcam_counter_status(sid,"stop");webcam_obj.updateButtonStatus("after_recording");wfu_webcam_onstop(e,sid)};webcam_props.media.start(10)};
150
- wfu_webcam_stop_rec=function(sid){var webcam_props=GlobalData.WFU[sid].webcamProps;webcam_props.media.stop()};
151
- wfu_webcam_onstop=function(e,sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.blobs.length==0){alert(GlobalData.consts.webcam_video_nothingrecorded);wfu_webcam_golive(sid)}else{if(webcam_props.stream)webcam_obj.screenshot();var superBuffer=new Blob(webcam_props.blobs,{type:"video/mp4"});webcam_obj.setVideoProperties({autoplay:false,ontimeupdate:function(e){wfu_webcam_update_pos(sid)},onended:function(e){wfu_webcam_ended(sid)},onloadeddata:function(e){if(webcam_obj.readyState()>=
152
- 2)webcam_obj.updateButtonStatus("ready_playback")},onerror:function(e){webcam_obj.setVideoProperties({onloadeddata:null,srcObject:webcam_props.stream})},srcObject:superBuffer});superBuffer.name="video.mp4";wfu_add_files(sid,[{file:superBuffer,props:{}}],false);wfu_update_uploadbutton_status(sid)}};
153
- wfu_webcam_play=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.playing)return;webcam_obj.updateButtonStatus("playing");webcam_props.playing=true;webcam_obj.play()};wfu_webcam_ended=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;webcam_obj.ended();webcam_obj.updateButtonStatus("ready_playback");webcam_props.playing=false};
154
- wfu_webcam_pause=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;webcam_obj.pause();webcam_obj.updateButtonStatus("ready_playback");webcam_props.playing=false};wfu_webcam_back=function(sid){GlobalData.WFU[sid].webcam.back()};wfu_webcam_fwd=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;webcam_obj.fwd(webcam_props.duration)};
155
- wfu_webcam_take_picture=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.stream){webcam_obj.screenshot(function(image_file){image_file.name="image.png";wfu_add_files(sid,[{file:image_file,props:{}}],false);wfu_update_uploadbutton_status(sid)},"image/png");webcam_obj.updateButtonStatus("after_screenshot")}};
156
- wfu_webcam_update_pos=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;webcam_obj.updatePlayProgress(webcam_props.duration);webcam_obj.updateTimer(video.currentTime)};wfu_run_js_from_bank();
1
+ GlobalData={};Code_Initializators=[];GlobalData.WFU={n:[]};GlobalData.WFUB={n:[]};GlobalData.filestatematch={};GlobalData.filestatematch.success=[0,1,2,2];GlobalData.filestatematch.warning=[1,1,2,2];GlobalData.filestatematch.error1=[3,3,2,3];GlobalData.filestatematch.error2=[2,2,2,3];GlobalData.UploadInProgressString="";GlobalData.FreeChangeHandler=false;wfu_Check_Browser_Capabilities();
2
+ if(typeof wfu_js_decode_obj=="undefined")wfu_js_decode_obj=function(obj_str){var obj=null;if(obj_str=="window")obj=window;else{var dbs=String.fromCharCode(92);var match=obj_str.match(new RegExp("GlobalData("+dbs+".(WFU|WFUB)"+dbs+"[(.*?)"+dbs+"]("+dbs+".(.*))?)?$"));if(match){obj=GlobalData;if(match[3])obj=obj[match[2]][match[3]];if(match[5])obj=obj[match[5]]}}return obj};
3
+ function wfu_run_js_from_bank(){if(typeof WFU_JS_BANK!="undefined")while(WFU_JS_BANK.length>0){var obj=wfu_js_decode_obj(WFU_JS_BANK[0].obj_str);if(obj)obj[WFU_JS_BANK[0].func].call(obj);WFU_JS_BANK.splice(0,1)}}
4
+ function wfu_Initialize_Consts(consts){if(typeof GlobalData.consts!="undefined")return;GlobalData.consts=new Object;var consts_arr=consts.split(";");var const_arr;for(var i=0;i<consts_arr.length;i++){const_txt=consts_arr[i].split(":");GlobalData.consts[wfu_plugin_decode_string(const_txt[0])]=wfu_plugin_decode_string(const_txt[1])}}
5
+ function wfu_Load_Code_Connectors(sid){if(typeof wfu_Code_Objects=="undefined")wfu_Code_Objects={};wfu_Code_Objects[sid]=new wfu_Code_Object(sid);for(var i=0;i<Code_Initializators.length;i++)wfu_Code_Objects[sid].additem(Code_Initializators[i](sid))}
6
+ function wfu_Code_Object(sid){this.sid=sid;this.items=[];this._calc_prioritized_list=function(section){var item,list=[],idlist=[],nolist=[],priority;for(var i=0;i<this.items.length;i++){item=this.items[i];if(item[section]){priority=-1;if(item.priority)priority=item.priority;if(item[section].priority)priority=item[section].priority;if(priority>=0){list.push(priority);idlist.push(i)}else nolist.push(i)}}for(var i=1;i<list.length;i++)for(var j=i;j<list.length;j++)if(list[j]<list[i-1]){var temp=list[j];
7
+ list[j]=list[i-1];list[i-1]=temp;var temp=idlist[j];idlist[j]=idlist[i-1];idlist[i-1]=temp}return idlist.concat(nolist)};this.additem=function(item){this.items.push(item)};this.apply_filters=function(section,val){if(typeof val=="undefined")return null;var idlist=this._calc_prioritized_list(section);if(idlist.length==0)return val;for(var i=0;i<idlist.length;i++){var item=this.items[idlist[i]];var func=null;if(typeof item[section]=="function")func=item[section];else if(typeof item[section].func=="function")func=
8
+ item[section].func;if(func!=null){val=func.apply(this,Array.prototype.slice.call(arguments,1));arguments[1]=val}}return val};this.do_action=function(section){var idlist=this._calc_prioritized_list(section);if(idlist.length==0)return;for(var i=0;i<idlist.length;i++){var item=this.items[idlist[i]];var func=null;if(typeof item[section]=="function")func=item[section];else if(typeof item[section].func=="function")func=item[section].func;if(func!=null)func.apply(this,Array.prototype.slice.call(arguments,
9
+ 1))}}}
10
+ function wfu_plugin_load_action(sid){var WFU=GlobalData.WFU[sid];wfu_install_unload_hook();if(!!WFU.visualeditorbutton_exist){WFU.visualeditorbutton.init();var invoke_function=function(){wfu_invoke_shortcode_editor(WFU)};WFU.visualeditorbutton.attachInvokeHandler(invoke_function)}if(WFU.is_formupload)WFU.uploadaction=function(){wfu_redirect_to_classic(sid,0,0)};else WFU.uploadaction=function(){wfu_HTML5UploadFile(sid)};var clickaction=function(){wfu_selectbutton_clicked(sid)};var changeaction=function(fileselected){var WFU=
11
+ GlobalData.WFU[sid];var usefilearray=0;wfu_selectbutton_changed(sid,usefilearray);wfu_update_uploadbutton_status(sid);if(WFU.singlebutton&&fileselected)WFU.uploadaction()};if(!!WFU.uploadform_exist)WFU.uploadform.attachActions(clickaction,changeaction);var completeaction=function(status){document.getElementById("consentresult_"+sid).value=status};if(!!WFU.consent_exist){WFU.consent.attachActions(completeaction);WFU.consent.update("init")}if(!!WFU.submit_exist){if(WFU.testmode)clickaction=function(){alert(GlobalData.consts.notify_testmode)};
12
+ else clickaction=function(){WFU.uploadaction()};WFU.submit.attachClickAction(clickaction)}}function wfu_install_unload_hook(){window.onbeforeunload=wfu_unload_hook}function wfu_unload_hook(){if(GlobalData.UploadInProgressString!="")if(GlobalData.UploadInProgressString.trim()!="")return GlobalData.consts.wfu_pageexit_prompt}
13
+ function wfu_Check_Browser_Capabilities(){if(typeof wfu_BrowserCaps!="undefined")return;wfu_BrowserCaps=new Object;var xmlhttp=wfu_GetHttpRequestObject();wfu_BrowserCaps.supportsAJAX=xmlhttp!=null;wfu_BrowserCaps.supportsUploadProgress=!!(xmlhttp&&"upload"in xmlhttp&&"onprogress"in xmlhttp.upload);var fd=null;try{var fd=new FormData}catch(e$0){}wfu_BrowserCaps.supportsHTML5=fd!=null;var e=document.createElement("iframe");wfu_BrowserCaps.supportsIFRAME=e!=null;wfu_BrowserCaps.supportsDRAGDROP=window.FileReader?
14
+ true:false;wfu_BrowserCaps.supportsAnimation=wfu_check_animation();wfu_BrowserCaps.isSafari=Object.prototype.toString.call(window.HTMLElement).indexOf("Constructor")>0}
15
+ function wfu_check_animation(){var animation=false,animationstring="animation",keyframeprefix="",domPrefixes="Webkit Moz O ms Khtml".split(" "),pfx="";var elm=document.createElement("DIV");if(elm.style.animationName)animation=true;if(animation===false)for(var i=0;i<domPrefixes.length;i++)if(elm.style[domPrefixes[i]+"AnimationName"]!==undefined){pfx=domPrefixes[i];animationstring=pfx+"Animation";keyframeprefix="-"+pfx.toLowerCase()+"-";animation=true;break}return animation}
16
+ function wfu_join_strings(delimeter){var args=[].slice.call(arguments);var str="";var delim="";for(var i=1;i<args.length;i++){if(str==""||args[i]=="")delim="";else delim=delimeter;str+=delim+args[i]}return str}
17
+ function wfu_plugin_decode_string(str){var i=0;var newstr="";var num,val;while(i<str.length){num=parseInt(str.substr(i,2),16);if(num<128)val=num;else if(num<224)val=((num&31)<<6)+(parseInt(str.substr(i+=2,2),16)&63);else val=((num&15)<<12)+((parseInt(str.substr(i+=2,2),16)&63)<<6)+(parseInt(str.substr(i+=2,2),16)&63);newstr+=String.fromCharCode(val);i+=2}return newstr}
18
+ function wfu_plugin_encode_string(str){var i=0;var newstr="";var hex="";for(i=0;i<str.length;i++){num=str.charCodeAt(i);if(num>=2048)num=((num&16773120|917504)<<4)+((num&4032|8192)<<2)+(num&63|128);else if(num>=128)num=((num&65472|12288)<<2)+(num&63|128);hex=num.toString(16);if(hex.length==1||hex.length==3||hex.length==5)hex="0"+hex;newstr+=hex}return newstr}
19
+ function wfu_decode_array_from_string(str){var arr_str=wfu_plugin_decode_string(str);var arr=null;try{arr=JSON.parse(arr_str)}catch(e){}return arr}function wfu_randomString(len){var chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";var string_length=len;var randomstring="";for(var i=0;i<string_length;i++){var rnum=Math.floor(Math.random()*chars.length);randomstring+=chars.substring(rnum,rnum+1)}return randomstring}
20
+ function wfu_addEventHandler(obj,evt,handler){if(obj.addEventListener)obj.addEventListener(evt,handler,false);else if(obj.attachEvent)obj.attachEvent("on"+evt,handler);else obj["on"+evt]=handler}function wfu_attach_element_handlers(item,handler){var elem_events=["DOMAttrModified","textInput","input","change","keypress","paste","focus","propertychange"];for(var i=0;i<elem_events.length;i++)wfu_addEventHandler(item,elem_events[i],handler)}
21
+ function wfu_GetHttpRequestObject(){var xhr=null;try{xhr=new XMLHttpRequest}catch(e$1){try{xhr=new ActiveXObject("Msxml2.XMLHTTP")}catch(e2){try{xhr=new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}}}if(xhr==null&&window.createRequest)try{xmlhttp=window.createRequest()}catch(e$2){}return xhr}
22
+ function wfu_get_filelist(sid,include_filearray){var WFU=GlobalData.WFU[sid];include_filearray=typeof include_filearray!=="undefined"?include_filearray:true;var farr=[];if(!!WFU.uploadform_exist)farr=WFU.uploadform.files();if(include_filearray&&typeof WFU.filearray!=="undefined")farr=WFU.filearray;return farr}
23
+ function wfu_add_files(sid,files){var WFU=GlobalData.WFU[sid];if(typeof WFU.filearray=="undefined"){WFU.filearray=Array();WFU.filearrayprops=Array()}if(!!WFU.uploadform_exist)WFU.uploadform.reset();WFU.filearray.length=WFU.filearrayprops.length=0;for(var i=0;i<files.length;i++){WFU.filearray.push(files[i].file);WFU.filearrayprops.push(files[i].props)}}
24
+ function wfu_attach_cancel_event(sid,unique_upload_id){function wfu_cancel_classic_upload_final(){var Params=wfu_Initialize_Params();Params.general.shortcode_id=sid;Params.general.unique_id="";Params.general.files_count=0;Params.general.state=16;wfu_ProcessUploadComplete(sid,0,Params,"no-ajax","",[false,null,false]);if(!!WFU.uploadform_exist){WFU.uploadform.reset();WFU.uploadform.submit();WFU.uploadform.lock()}}function wfu_cancel_classic_upload(){var url=GlobalData.consts.ajax_url+"?action=wfu_ajax_action_cancel_upload&wfu_uploader_nonce="+
25
+ document.getElementById("wfu_uploader_nonce_"+sid).value+"&sid="+sid+"&unique_id="+unique_upload_id+"&session_token="+GlobalData.WFU[sid].session;var xmlhttp=wfu_GetHttpRequestObject();if(xmlhttp==null){var i=document.createElement("iframe");if(i){i.style.display="none";i.src=url;document.body.appendChild(i);i.onload=function(){wfu_cancel_classic_upload_final()};return}}xmlhttp.open("GET",url,true);xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4&&xmlhttp.status==200)wfu_cancel_classic_upload_final()};
26
+ xmlhttp.send(null)}var WFU=GlobalData.WFU[sid];if(!!WFU.textbox_exist){var textbox_cancel_function=function(){var answer=false;if(WFU.is_formupload){answer=confirm(GlobalData.consts.cancel_upload_prompt);if(answer==true)wfu_cancel_classic_upload()}else{if(!GlobalData[sid]||GlobalData[sid].xhrs.length==0)return false;var answer=confirm(GlobalData.consts.cancel_upload_prompt);if(answer==true){var farr=wfu_get_filelist(sid);var firstxhr=[];var filename=[];for(var i=0;i<farr.length;i++){firstxhr.push(null);
27
+ filename.push(farr[i].name)}for(var i=0;i<GlobalData[sid].xhrs.length;i++){var file_ind=GlobalData[sid].xhrs[i].file_id-1;if(file_ind>=0&&firstxhr[file_ind]==null)firstxhr[file_ind]=GlobalData[sid].xhrs[i]}if(WFU.debugmode)console.log("upload cancelled!");for(var i=0;i<firstxhr.length;i++){if(firstxhr[i]==null){firstxhr[i]=wfu_GetHttpRequestObject();if(firstxhr[i]!=null)wfu_initialize_fileupload_xhr(firstxhr[i],sid,unique_upload_id,i,filename[i])}if(firstxhr[i]!=-1){var evt={target:{responseText:"force_cancel_code",
28
+ shortcode_id:sid}};wfu_uploadComplete.call(firstxhr[i],evt)}}}}return answer};WFU.textbox.attachCancelHandler(textbox_cancel_function)}}function wfu_dettach_cancel_event(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.textbox_exist)WFU.textbox.dettachCancelHandler()}
29
+ function wfu_selectbutton_changed(sid,usefilearray){if(!wfu_BrowserCaps.supportsAJAX||!wfu_BrowserCaps.supportsHTML5)usefilearray=0;var farr=wfu_get_filelist(sid,false);if(usefilearray==1){if(typeof GlobalData.WFU[sid].filearray=="undefined")GlobalData.WFU[sid].filearray=Array();for(var i=0;i<farr.length;i++)GlobalData.WFU[sid].filearray.push(farr[i])}else if(typeof GlobalData.WFU[sid].filearray!="undefined")delete GlobalData.WFU[sid].filearray;wfu_update_filename_text(sid)}
30
+ function wfu_selectbutton_clicked(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.message_exist)WFU.message.reset();var resetform=true;if(resetform)if(!!WFU.uploadform_exist)WFU.uploadform.reset()}function wfu_update_uploadbutton_status(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.submit_exist){var submit=WFU.submit;var farr=wfu_get_filelist(sid);var status=farr.length>0||WFU.allownofile;status=wfu_Code_Objects[sid].apply_filters("uploadbutton_status",status);submit.toggle(status)}}
31
+ function wfu_update_filename_text(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.textbox_exist){var farr=wfu_get_filelist(sid);var filenames=[];for(var i=0;i<farr.length;i++)filenames.push(farr[i].name);WFU.textbox.update("set",filenames)}}
32
+ function wfu_init_userdata_handlers(sid,key){var WFU=GlobalData.WFU[sid];var props=WFU.userdata.props[key];var JS=WFU.userdata.codes[key];var obj=WFU.userdata;JS.init=function(){};JS.value=function(){return""};JS.lock=function(){};JS.unlock=function(){};JS.reset=function(){};JS.empty=function(){return""};JS.validate=null;JS.typehook=null;if(props.type=="text"){JS.init=function(){obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};
33
+ JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""}}else if(props.type=="multitext"){JS.init=function(){obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===
34
+ ""?obj.error_empty:""}}else if(props.type=="number"){JS.init=function(){obj.attachHandlers(props,function(e){if(props.typehook)JS.typehook(e);else props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""};JS.validate=function(){var re=/^(\+|\-)?[0-9]*$/i;if(props.format==
35
+ "f")re=/^(\+|\-)?[0-9]*?\.?[0-9]*$/i;return re.test(obj.getValue(props))?"":obj.error_invalid_number};JS.typehook=function(e){var re=/^(\+|\-)?[0-9]*$/i;if(props.format=="f")re=/^(\+|\-)?[0-9]*?\.?[0-9]*$/i;if(re.test(e.target.value))props.store();else e.target.value=props.getstored()}}else if(props.type=="email"){JS.init=function(){obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};
36
+ JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""};JS.validate=function(){if(obj.getValue(props)=="")return"";var re=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;return re.test(obj.getValue(props))?"":obj.error_invalid_email}}else if(props.type=="confirmemail"){JS.init=function(){obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};
37
+ JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""};JS.validate=function(){var baseprops=null;for(var i=0;i<WFU.userdata.props.length;i++)if(WFU.userdata.props[i]&&WFU.userdata.props[i].type=="email"&&WFU.userdata.props[i].group==props.group){baseprops=WFU.userdata.props[i];break}return baseprops!=null?obj.getValue(props)==obj.getValue(baseprops)?
38
+ "":obj.error_confirm_email_nomatch:obj.error_confirm_email_nobase}}else if(props.type=="password"){JS.init=function(){obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""}}else if(props.type=="confirmpassword"){JS.init=function(){obj.attachHandlers(props,
39
+ function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""};JS.validate=function(){var baseprops=null;for(var i=0;i<WFU.userdata.props.length;i++)if(WFU.userdata.props[i]&&WFU.userdata.props[i].type=="password"&&WFU.userdata.props[i].group==props.group){baseprops=
40
+ WFU.userdata.props[i];break}return baseprops!=null?obj.getValue(props)==obj.getValue(baseprops)?"":obj.error_confirm_password_nomatch:obj.error_confirm_password_nobase}}else if(props.type=="checkbox"){JS.init=function(){obj.initField(props);obj.setValue(props,props["default"]=="true");obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)?"true":"false"};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,
41
+ props["default"]=="true");props.store()};JS.empty=function(){return!obj.getValue(props)?obj.error_checkbox_notchecked:""}}else if(props.type=="radiobutton"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?
42
+ obj.error_radio_notselected:""}}else if(props.type=="date"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){def=props["default"].trim();if(def.substr(0,1)=="("&&def.substr(def.length-1,1)==")")def=def.substr(1,def.length-2);else def="";obj.setValue(props,def);props.store()};JS.empty=function(){return obj.getValue(props)===
43
+ ""?obj.error_empty:""}}else if(props.type=="time"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){def=props["default"].trim();if(def.substr(0,1)=="("&&def.substr(def.length-1,1)==")")def=def.substr(1,def.length-2);else def="";obj.setValue(props,def);props.store()};JS.empty=function(){return obj.getValue(props)===
44
+ ""?obj.error_empty:""}}else if(props.type=="datetime"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){def=props["default"].trim();if(def.substr(0,1)=="("&&def.substr(def.length-1,1)==")")def=def.substr(1,def.length-2);else def="";obj.setValue(props,def);props.store()};JS.empty=function(){return obj.getValue(props)===
45
+ ""?obj.error_empty:""}}else if(props.type=="list"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""}}else if(props.type=="dropdown"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,
46
+ function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""}}else if(props.type=="honeypot"){JS.init=function(){obj.initField(props);obj.attachHandlers(props,function(e){props.store()})};JS.value=function(){return obj.getValue(props)};JS.lock=function(){obj.disable(props)};
47
+ JS.unlock=function(){obj.enable(props)};JS.reset=function(){obj.setValue(props,props["default"]);props.store()};JS.empty=function(){return obj.getValue(props)===""?obj.error_empty:""}}JS.init()}function wfu_Redirect(link){window.location=link}function wfu_loadStart(evt){}
48
+ function wfu_update_upload_metrics(sid){var totalsize=0;var totalloaded=0;var totaldelta=0;var metrics=Array();var farr=wfu_get_filelist(sid);for(var i=0;i<farr.length;i++)metrics[i]={size:farr[i].size,aborted:false,loaded:0,delta:0};for(var i=0;i<GlobalData[sid].xhrs.length;i++){var file_id=GlobalData[sid].xhrs[i].file_id;if(file_id>0&&GlobalData[sid].xhrs[i].aborted)metrics[file_id-1].aborted=true}for(var i=0;i<GlobalData[sid].xhrs.length;i++){var file_id=GlobalData[sid].xhrs[i].file_id;if(file_id>
49
+ 0&&!metrics[file_id-1].aborted){metrics[file_id-1].size=Math.max(GlobalData[sid].xhrs[i].totalsize,metrics[file_id-1].size);metrics[file_id-1].loaded+=GlobalData[sid].xhrs[i].sizeloaded;metrics[file_id-1].delta+=Math.max(GlobalData[sid].xhrs[i].deltaloaded,0)}}for(var i=0;i<farr.length;i++){var Gm=GlobalData[sid].metrics[i];if(!metrics[i].aborted&&metrics[i].size>0){Gm.size=metrics[i].size;if(GlobalData.consts.wfu_uploadprogress_mode=="incremental")Gm.progress_pos=Math.min(Gm.progress_pos+(1-Gm.progress_pos)*
50
+ metrics[i].delta/(Gm.size-Gm.loaded),1);else Gm.progress_pos=metrics[i].loaded/metrics[i].size;Gm.loaded=metrics[i].loaded;totalsize+=Gm.size;totalloaded+=Gm.loaded;totaldelta+=metrics[i].delta}else{Gm.size=0;Gm.progress_pos=0;Gm.loaded=0}}var Gm=GlobalData[sid].metricstotal;Gm.size=totalsize;if(GlobalData.consts.wfu_uploadprogress_mode=="incremental")Gm.progress_pos=Math.min(Gm.progress_pos+(1-Gm.progress_pos)*totaldelta/(Gm.size-Gm.loaded),1);else Gm.progress_pos=totalloaded/totalsize;Gm.loaded=
51
+ totalloaded}
52
+ function wfu_uploadProgress(evt,sid,xhrid,debugmode){var WFU=GlobalData.WFU[sid];if(debugmode&&typeof this.xhr=="undefined"){console.log("total="+evt.total+", loaded="+evt.loaded);console.log(evt)}var this_xhr=GlobalData[sid].xhrs[xhrid];if(this_xhr.file_id==0)return;var percentComplete=0;var delta=0;var simplebar_exists=!!WFU.progressbar_exist;if(evt.lengthComputable){this_xhr.deltaloaded=evt.loaded-this_xhr.sizeloaded;this_xhr.sizeloaded=evt.loaded;if(this_xhr.size<evt.total&&evt.total>0){delta=
53
+ evt.total-this_xhr.size;this_xhr.deltasize+=delta;this_xhr.size+=delta;for(var i=0;i<GlobalData[sid].xhrs.length;i++)if(GlobalData[sid].xhrs[i].file_id==this_xhr.file_id)GlobalData[sid].xhrs[i].totalsize+=delta}wfu_update_upload_metrics(sid);this_xhr.deltaloaded=0;if(simplebar_exists){percentComplete=Math.round(GlobalData[sid].metricstotal.progress_pos*100);WFU.progressbar.update(percentComplete)}}else if(simplebar_exists)WFU.progressbar.update(0)}
54
+ function wfu_notify_WPFilebase(params_index,session_token){var xhr=wfu_GetHttpRequestObject();if(xhr==null){var i=document.createElement("iframe");i.style.display="none";i.src=GlobalData.consts.ajax_url+"?action=wfu_ajax_action_notify_wpfilebase&params_index="+params_index+"&session_token="+session_token;document.body.appendChild(i);return}var url=GlobalData.consts.ajax_url;params=new Array(3);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_notify_wpfilebase";params[1]=
55
+ new Array(2);params[1][0]="params_index";params[1][1]=params_index;params[2]=new Array(2);params[2][0]="session_token";params[2][1]=session_token;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){};xhr.send(parameters)}
56
+ function wfu_send_email_notification(sid,unique_id){var WFU=GlobalData.WFU[sid];var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=GlobalData.consts.ajax_url;params=new Array(4);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_send_email_notification";params[1]=new Array(2);params[1][0]="params_index";params[1][1]=WFU.params_index;params[2]=new Array(2);params[2][0]="session_token";params[2][1]=WFU.session;params[3]=new Array(2);params[3][0]="uniqueuploadid_"+
57
+ sid;params[3][1]=unique_id;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);wfu_initialize_fileupload_xhr(xhr,sid,unique_id,-1,"");xhr.success_message_header="";xhr.error_message_header="";xhr.error_adminmessage_unknown="";xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.addEventListener("load",wfu_uploadComplete,false);xhr.addEventListener("error",wfu_uploadFailed,false);xhr.addEventListener("abort",
58
+ wfu_uploadCanceled,false);xhr.send(parameters)}
59
+ function wfu_uploadComplete(evt){var d=new Date;var sid=this.shortcode_id;var WFU=GlobalData.WFU[sid];var i=this.file_id;var last=false;var js_script_enc="";var upload_params="";var safe_params="";var file_status="unknown";var uploaded_file_props="";var debug_data=null;var success_txt="wfu_fileupload_success:";this.loading=false;this.end_time=d.getTime();var txt=evt.target.responseText;var result_data=txt;var error_code="error";if(txt!=-1){if(txt.indexOf("force_errorabort_code")>-1){error_code="errorabort";
60
+ txt=txt.replace("force_errorabort_code","")}if(txt.indexOf("force_cancel_code")>-1){error_code="errorcancel";txt=txt.replace("force_cancel_code","")}if(txt.indexOf("force_abortsuccess_code")>-1){error_code="errorabortsuccess";txt=txt.replace("force_abortsuccess_code","")}}if(txt!=-1){var pos=txt.indexOf(success_txt);var debug_data_str="";if(pos>-1){if(WFU.debugmode)debug_data_str=txt.substr(0,pos);result_data=txt.substr(pos+success_txt.length);pos=result_data.indexOf(":");js_script_enc=result_data.substr(0,
61
+ pos);result_data=result_data.substr(pos+1);pos=result_data.indexOf(":");safe_params=result_data.substr(0,pos);upload_params=result_data.substr(pos+1)}if(debug_data_str!=""){var title="";if(this.requesttype=="fileupload")title="Debug Data - File: "+this.file_id;else if(this.requesttype=="email")title="Debug Data - Email Notification";debug_data={title:title,data:debug_data_str}}if(safe_params!=""){var safe_parts=safe_params.split(";");if(parseInt(safe_parts[2])==1){var filedata=safe_parts[3].split(",");
62
+ file_status=wfu_plugin_decode_string(filedata[0]);uploaded_file_props=filedata[4]}}}if(upload_params==""||safe_params==""){var Params=wfu_Initialize_Params();Params.general.shortcode_id=sid;Params.general.unique_id=this.unique_id;Params.general.state=7;Params.general.files_count=this.requesttype=="fileupload"?1:0;Params.general.upload_finish_time=this.finish_time;var file_colors=WFU.fail_colors.split(",");var file_header=this.error_message_header;var file_message_type=error_code;if(error_code=="errorabortsuccess"){Params.general.fail_message=
63
+ "";Params.general.fail_admin_message="";file_colors=WFU.success_colors.split(",");file_header=this.success_message_header;file_message_type="success"}else if(error_code!="errorcancel"){Params.general.fail_message=GlobalData.consts.message_unknown;Params.general.fail_admin_message=wfu_join_strings("<br />",this.error_adminmessage_unknown,this.requesttype+":"+result_data)}else{Params.general.fail_message=GlobalData.consts.file_cancelled;Params.general.fail_admin_message=""}if(Params.general.files_count>
64
+ 0){Params[0]={};Params[0]["color"]=file_colors[0];Params[0]["bgcolor"]=file_colors[1];Params[0]["borcolor"]=file_colors[2];Params[0]["message_type"]=file_message_type;file_status=error_code;Params[0]["header"]=file_header;Params[0]["message"]=GlobalData.consts.message_timelimit;Params[0]["admin_messages"]=WFU.is_admin?GlobalData.consts.message_admin_timelimit:""}else Params.general.admin_messages.other=WFU.is_admin?GlobalData.consts.message_admin_timelimit:"";if(Params.general.upload_finish_time>
65
+ 0)if(d.getTime()<Params.general.upload_finish_time)if(Params.general.files_count>0){Params[0]["message"]=Params.general.fail_message;Params[0]["admin_messages"]=WFU.is_admin?Params.general.fail_admin_message:""}else Params.general.admin_messages.other=WFU.is_admin?Params.general.fail_admin_message:""}if(upload_params==""||safe_params==""){if(WFU.debugmode)console.log("wfu_ProcessUploadComplete: ",sid,this.file_id,"Params obj",this.unique_id,"",[WFU.debugmode,debug_data,WFU.is_admin],this.requesttype,
66
+ "");last=wfu_ProcessUploadComplete(sid,this.file_id,Params,this.unique_id,"",[WFU.debugmode,debug_data,WFU.is_admin],this.requesttype,"")}else{if(WFU.debugmode)console.log("wfu_ProcessUploadComplete: ",sid,this.file_id,"Params str",this.unique_id,safe_params,[WFU.debugmode,debug_data,WFU.is_admin],this.requesttype,js_script_enc);last=wfu_ProcessUploadComplete(sid,this.file_id,upload_params,this.unique_id,safe_params,[WFU.debugmode,debug_data,WFU.is_admin],this.requesttype,js_script_enc)}if(last){wfu_dettach_cancel_event(sid);
67
+ wfu_unlock_upload(sid);if(!!WFU.progressbar_exist)WFU.progressbar.hide();wfu_clear(sid)}if(evt.target.return_status)return file_status}
68
+ function wfu_ProcessUploadComplete(sid,file_id,upload_params,unique_id,safe_output,debug_data,request_type,js_script_enc){var WFU=GlobalData.WFU[sid];if(!sid||sid<0)return;if(upload_params==null||upload_params=="")return;if(unique_id=="")return;if(unique_id!="no-ajax"&&!GlobalData[sid])return;var do_redirect=false;if(typeof upload_params==="string"){upload_params=wfu_plugin_decode_string(upload_params.replace(/^\s+|\s+$/g,""));var Params=null;try{Params=JSON.parse(upload_params)}catch(e){}if(Params==
69
+ null){var safe_parts=safe_output.split(";");Params=wfu_Initialize_Params();Params.general.shortcode_id=sid;Params.general.unique_id=unique_id;Params.general.state=safe_parts[0];if(Params.general.state==4)Params.general.state++;var default_colors=safe_parts[1].split(",");var filedata="";var error_jsonparse_filemessage=GlobalData.consts.jsonparse_filemessage;var error_jsonparse_message=GlobalData.consts.jsonparse_message;var error_jsonparse_adminmessage=GlobalData.consts.jsonparse_adminmessage;Params.general.files_count=
70
+ parseInt(safe_parts[2]);for(var i=0;i<Params.general.files_count;i++){Params[i]={};Params[i]["color"]=default_colors[0];Params[i]["bgcolor"]=default_colors[1];Params[i]["borcolor"]=default_colors[2];filedata=safe_parts[i+3].split(",");Params[i]["message_type"]=wfu_plugin_decode_string(filedata[0]);Params[i]["header"]=wfu_plugin_decode_string(filedata[1]);if(Params[i]["message_type"]=="success"){Params[i]["header"]+=error_jsonparse_filemessage;Params[i]["message_type"]="warning"}Params[i]["message"]=
71
+ wfu_join_strings("<br />",error_jsonparse_message,wfu_plugin_decode_string(filedata[2]));Params[i]["admin_messages"]=wfu_join_strings("<br />",error_jsonparse_adminmessage,wfu_plugin_decode_string(filedata[3]))}}}else if(typeof upload_params==="object")var Params=upload_params;else return;if(WFU.debugmode)console.log("wfu_ProcessUploadComplete debug: ",debug_data);if(WFU.debugmode)console.log("wfu_ProcessUploadComplete Params: ",Params);var message_types=[];i=0;while(Params[i]){if(Params[i].message_type){message_types.push(Params[i].message_type);
72
+ if(Params[i].message_type.substr(0,5)=="error")Params[i].message_type=Params[i].message_type.substr(0,5)}i++}if(!GlobalData[sid])GlobalData[sid]=Object();var G=GlobalData[sid];if(unique_id=="no-ajax"){G.last=false;G.unique_id="";G.files_count=Params.general.files_count;if(Params.general.state==0)Params.general.files_count=0;G.files_processed=Params.general.files_count;G.upload_state=Params.general.state;G.nofileupload=Params.general.state>12&&Params.general.state<16;if(!("message"in G))G.message=
73
+ [];if(Params.general.message!="")G.message.push(Params.general.message);else G.message=[];G.update_wpfilebase=Params.general.update_wpfilebase;G.redirect_link=Params.general.redirect_link;G.notify_by_email=0;G.admin_messages={};G.admin_messages.wpfilebase=Params.general.admin_messages.wpfilebase;G.admin_messages.notify=Params.general.admin_messages.notify;G.admin_messages.redirect=Params.general.admin_messages.redirect;if(!("debug"in G.admin_messages))G.admin_messages.debug=[];if(debug_data[1]!==
74
+ null)G.admin_messages.debug.push(debug_data[1]);if(!("other"in G.admin_messages))G.admin_messages.other=[];if(Params.general.admin_messages.other!="")G.admin_messages.other.push(Params.general.admin_messages.other);G.errors={};G.errors.wpfilebase=Params.general.errors.wpfilebase;G.errors.notify=Params.general.errors.notify;G.errors.redirect=Params.general.errors.redirect;G.current_size=0;G.total_size=0}else{if(G.unique_id==""||G.unique_id!=unique_id||G.unique_id!=Params.general.unique_id)return;if(G.last)return;
75
+ if(Params.general.files_count==0&&Params[0])if(Params[0].message_type=="error")Params.general.files_count=1;var file_status="";for(var i=0;i<Params.general.files_count;i++){if(Params[i].message_type=="error"&&G.files_processed==0)file_status="error1";else if(Params[i].message_type=="error"&&G.files_processed>0)file_status="error2";else file_status=Params[i].message_type;G.upload_state=GlobalData.filestatematch[file_status][G.upload_state]}G.files_processed+=Params.general.files_count;if(Params.general.message!=
76
+ "")G.message.push(Params.general.message);if(G.update_wpfilebase=="")G.update_wpfilebase=Params.general.update_wpfilebase;if(!request_type||request_type&&request_type!="email")G.redirect_link=Params.general.redirect_link;G.notify_by_email+=parseInt("0"+Params.general.notify_by_email);if(debug_data[1]!==null)G.admin_messages.debug.push(debug_data[1]);if(Params.general.admin_messages.other!="")G.admin_messages.other.push(Params.general.admin_messages.other);if(G.admin_messages.wpfilebase=="")G.admin_messages.wpfilebase=
77
+ Params.general.admin_messages.wpfilebase;if(G.admin_messages.notify=="")G.admin_messages.notify=Params.general.admin_messages.notify;if(G.admin_messages.redirect=="")G.admin_messages.redirect=Params.general.admin_messages.redirect;if(G.errors.wpfilebase=="")G.errors.wpfilebase=Params.general.errors.wpfilebase;if(G.errors.notify=="")G.errors.notify=Params.general.errors.notify;if(G.errors.redirect=="")G.errors.redirect=Params.general.errors.redirect}if(G.files_processed==G.files_count){G.last=true;
78
+ if(G.update_wpfilebase!=""){G.admin_messages.wpfilebase="";wfu_notify_WPFilebase(WFU.params_index,WFU.session)}if(G.notify_by_email>0){G.admin_messages.notify="";wfu_send_email_notification(sid,unique_id);G.last=false;G.notify_by_email=0}if(G.last){if(unique_id!="no-ajax"&&!G.nofileupload)wfu_notify_server_upload_ended(sid,unique_id);GlobalData.UploadInProgressString=GlobalData.UploadInProgressString.replace(new RegExp("\\["+unique_id+"\\]","g"),"")}if(G.errors.redirect!="")G.redirect_link="";if(G.redirect_link!=
79
+ ""&&G.last&&GlobalData.UploadInProgressString.trim()==""){G.upload_state=11;do_redirect=true}}var nonadmin_message=G.message;var admin_message=[].concat(G.admin_messages.other,G.admin_messages.wpfilebase!=""?[G.admin_messages.wpfilebase]:[],G.admin_messages.notify!=""?[G.admin_messages.notify]:[],G.admin_messages.redirect!=""?[G.admin_messages.redirect]:[]);if(G.last)if(G.nofileupload){if(unique_id!="no-ajax")if(G.upload_state==0)G.upload_state=14;else if(G.upload_state<4)G.upload_state=15;if(G.upload_state==
80
+ 15&&Params[0]){nonadmin_message.push(Params[0].message);admin_message.push(Params[0].admin_messages)}}else{if(G.files_count>0&&G.store_nothing&&G.upload_state<3)G.upload_state=19;if(G.files_count==0&&G.upload_state!=12&&G.upload_state<16)G.upload_state=8;else if(G.upload_state<4)G.upload_state+=4;if(G.upload_state==4&&admin_message.length>0)G.upload_state++;else if(G.upload_state==5&&admin_message.length==0&&nonadmin_message.length==0)G.upload_state--}if(!!WFU.message_exist){var suffix="";if(G.files_count==
81
+ 1&&(G.upload_state==5||G.upload_state==7))suffix="_singlefile";var final_upload_state=G.upload_state==0&&G.nofileupload?13:G.upload_state;var data={files_count:!G.nofileupload?G.files_count:0,files_processed:!G.nofileupload?G.files_processed:0,state:final_upload_state,single:G.files_count==1&&nonadmin_message.length==0&&admin_message.length==0&&G.last&&!do_redirect&&!G.nofileupload,color:GlobalData.States["State"+final_upload_state+suffix].color,bgcolor:GlobalData.States["State"+final_upload_state+
82
+ suffix].bgcolor,borcolor:GlobalData.States["State"+final_upload_state+suffix].borcolor,message1:GlobalData.States["State"+final_upload_state+suffix].message,message2:nonadmin_message,message3:admin_message,debug_data:G.admin_messages.debug,files:[]};for(var i=0;i<Params.general.files_count;i++)data.files[i]={index:i+file_id,result:Params[i].message_type,message1:Params[i].header,message2:Params[i].message,message3:Params[i].admin_messages};WFU.message.update(data)}if(js_script_enc)eval(wfu_plugin_decode_string(js_script_enc));
83
+ if(do_redirect)wfu_Redirect(G.redirect_link);return G.last}function wfu_uploadFailed(evt,debugmode){if(debugmode){console.log("failure report following");console.log(evt)}var xhr=evt.target;var new_evt={target:{responseText:"",shortcode_id:xhr.shortcode_id}};wfu_uploadComplete.call(xhr,new_evt)}function wfu_uploadCanceled(evt){}
84
+ function wfu_notify_server_upload_ended(sid,unique_id){var WFU=GlobalData.WFU[sid];var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var url=GlobalData.consts.ajax_url;params=new Array(6);params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action";params[1]=new Array(2);params[1][0]="wfu_uploader_nonce";params[1][1]=document.getElementById("wfu_uploader_nonce_"+sid).value;params[2]=new Array(2);params[2][0]="uniqueuploadid_"+sid;params[2][1]=unique_id;params[3]=new Array(2);params[3][0]=
85
+ "params_index";params[3][1]=WFU.params_index;params[4]=new Array(2);params[4][0]="session_token";params[4][1]=WFU.session;params[5]=new Array(2);params[5][0]="upload_finished";params[5][1]=1;var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200)wfu_Code_Objects[sid].do_action("after_upload",
86
+ xhr.responseText)};xhr.send(parameters)}
87
+ function wfu_Initialize_Params(){var params={};params.version="full";params.general={};params.general.shortcode_id=0;params.general.unique_id="";params.general.state=0;params.general.files_count=0;params.general.update_wpfilebase="";params.general.redirect_link="";params.general.upload_finish_time=0;params.general.message="";params.general.message_type="";params.general.admin_messages={};params.general.admin_messages.wpfilebase="";params.general.admin_messages.notify="";params.general.admin_messages.redirect=
88
+ "";params.general.admin_messages.other="";params.general.errors={};params.general.errors.wpfilebase="";params.general.errors.notify="";params.general.errors.redirect="";params.general.color="";params.general.bgcolor="";params.general.borcolor="";params.general.notify_by_email=0;params.general.fail_message="";params.general.fail_admin_message="";return params}
89
+ function wfu_redirect_to_classic(sid,flag,adminerrorcode){var WFU=GlobalData.WFU[sid];WFU.is_formupload=true;var numfiles=wfu_filesselected(sid);if(numfiles==0&&!WFU.allownofile)return;if(!!WFU.subfolders_exist&&numfiles>0&&!WFU.subfolders.check())return;if(!wfu_check_required_userdata(sid,true))return;if(!wfu_Code_Objects[sid].apply_filters("pre_start_check",true))return;wfu_redirect_to_classic_cont(sid,flag,adminerrorcode)}
90
+ function wfu_redirect_to_classic_cont(sid,flag,adminerrorcode){var process_function=function(responseText){var WFU=GlobalData.WFU[sid];var txt_value="";var session_token=WFU.session;var success_txt="wfu_askserver_success:";var error_txt="wfu_askserver_error:";var pos_success=responseText.indexOf(success_txt);var pos_error=responseText.indexOf(error_txt);if(pos_success>-1){txt_value=responseText.substr(pos_success+success_txt.length);var numfiles=wfu_filesselected(sid);var nofileupload=numfiles==0&&
91
+ WFU.allownofile;wfu_Code_Objects[sid].do_action("askserver_success",txt_value,"no-ajax");if(!!WFU.progressbar_exist&&!nofileupload)WFU.progressbar.show("shuffle");wfu_attach_cancel_event(sid,unique_id);var Params=wfu_Initialize_Params();Params.general.shortcode_id=sid;Params.general.unique_id="";Params.general.files_count=numfiles;if(nofileupload)Params.general.state=13;wfu_ProcessUploadComplete(sid,0,Params,"no-ajax","",[false,null,false]);document.getElementById("uniqueuploadid_"+sid).value=unique_id;
92
+ document.getElementById("nofileupload_"+sid).value=nofileupload?"1":"0";var suffix="";var redirected_txt="";if(flag==1)redirected_txt="_redirected";if(!!WFU.uploadform_exist){WFU.uploadform.changeFileName("uploadedfile_"+sid+redirected_txt+suffix);document.getElementById("uploadedfile_"+sid+"_name").name="uploadedfile_"+sid+redirected_txt+"_name";document.getElementById("uploadedfile_"+sid+"_size").name="uploadedfile_"+sid+redirected_txt+"_size"}if(adminerrorcode>0)document.getElementById("adminerrorcodes_"+
93
+ sid).value=adminerrorcode;else document.getElementById("adminerrorcodes_"+sid).value="";if(!!WFU.uploadform_exist){WFU.uploadform.submit();WFU.uploadform.lock()}}else if(pos_error>-1){txt_value=responseText.substr(pos_error+error_txt.length);wfu_unlock_upload(sid);wfu_Code_Objects[sid].do_action("askserver_error",txt_value)}};var unique_id=wfu_randomString(10);wfu_lock_upload(sid);wfu_Code_Objects[sid].do_action("pre_start");var pass_params="";var params_obj=wfu_Code_Objects[sid].apply_filters("askserver_pass_params",
94
+ {});for(var prop in params_obj)if(params_obj.hasOwnProperty(prop))pass_params+="&"+prop+"="+params_obj[prop];var d=new Date;var url=GlobalData.consts.ajax_url+"?action=wfu_ajax_action_ask_server&wfu_uploader_nonce="+document.getElementById("wfu_uploader_nonce_"+sid).value+"&sid="+sid+"&unique_id="+unique_id+"&start_time="+d.getTime()+"&session_token="+GlobalData.WFU[sid].session+pass_params;var xmlhttp=wfu_GetHttpRequestObject();if(xmlhttp==null){var i=document.createElement("iframe");if(i){i.style.display=
95
+ "none";i.src=url;document.body.appendChild(i);i.onload=function(){process_function(i.contentDocument.body.innerHTML)};return}else{wfu_Code_Objects[sid].do_action("not_supported");return}}xmlhttp.open("GET",url,true);xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4)if(xmlhttp.status==200)process_function(xmlhttp.responseText);else{alert(GlobalData.consts.remoteserver_noresult);wfu_Code_Objects[sid].do_action("askserver_noresult")}};xmlhttp.send(null)}
96
+ Code_Initializators[Code_Initializators.length]=function(sid){var CBUV_Code_Objects={};CBUV_Code_Objects.pre_start_check=function(attr){if(!attr)return attr;var sid=this.sid;var result=true;if(!!GlobalData.WFU[sid].consent_exist){if(GlobalData.WFU[sid].consent.consent_format!="prompt"&&document.getElementById("consentresult_"+sid).value==""){alert(GlobalData.consts.wfu_consent_notcompleted);result=false}else if(GlobalData.WFU[sid].consent.consent_format=="prompt"){document.getElementById("consentresult_"+
97
+ sid).value=confirm(GlobalData.WFU[sid].consent.consent_question)?"yes":"no";result=true}if(GlobalData.WFU[sid].consent.no_rejects_upload&&document.getElementById("consentresult_"+sid).value=="no"){alert(GlobalData.WFU[sid].consent_rejection_message);result=false}}return result};CBUV_Code_Objects.pre_start_ask_server=function(attr,has_filters){if(attr)return attr;var sid=this.sid;var consent_ask_server=GlobalData.WFU[sid].consent_maybe_ask_server&&!GlobalData.WFU[sid].consent_exist;return has_filters==
98
+ "true"||consent_ask_server};CBUV_Code_Objects.askserver_pass_params=function(params){var sid=this.sid;var farr=wfu_get_filelist(sid);var filenames="";var filesizes="";for(var i=0;i<farr.length;i++){if(i>0){filenames+=";";filesizes+=";"}filenames+=wfu_plugin_encode_string(farr[i].name);filesizes+=farr[i].size}params.filenames=filenames;params.filesizes=filesizes;if(GlobalData.WFU[sid].consent_maybe_ask_server&&!GlobalData.WFU[sid].consent_exist){params.consent_check="1";params.consent_rejection_message=
99
+ GlobalData.WFU[sid].consent_rejection_message}return params};CBUV_Code_Objects.askserver_success=function(response,mode){var sid=this.sid;var upload_status="success";var txt_match=response.match(/CBUVJS\[(.*?)\]/);var txt_header=txt_match?typeof txt_match[1]!="undefined"?txt_match[1]:"":"";if(txt_header!="")eval(wfu_plugin_decode_string(txt_header))};CBUV_Code_Objects.askserver_error=function(response,mode){var sid=this.sid;var upload_status="error";var txt_match=response.match(/CBUVJS\[(.*?)\]/);
100
+ var txt_header=txt_match?typeof txt_match[1]!="undefined"?txt_match[1]:"":"";if(txt_header!="")eval(wfu_plugin_decode_string(txt_header));txt_match=response.match(/CBUV\[(.*?)\]/);txt_header=txt_match?typeof txt_match[1]!="undefined"?txt_match[1]:"":"";if(txt_header!=""){var Params=wfu_Initialize_Params();GlobalData[sid]={};Params.general.shortcode_id=sid;Params.general.message=txt_header;Params.general.state=12;wfu_ProcessUploadComplete(sid,0,Params,"no-ajax","",[false,null,false]);wfu_clear(sid)}};
101
+ CBUV_Code_Objects.lock_upload=function(){var sid=this.sid;if(!!GlobalData.WFU[sid].consent_exist)GlobalData.WFU[sid].consent.update("lock")};CBUV_Code_Objects.unlock_upload=function(){var sid=this.sid;if(!!GlobalData.WFU[sid].consent_exist)GlobalData.WFU[sid].consent.update("unlock")};CBUV_Code_Objects.clear_upload=function(){var sid=this.sid;var WFU=GlobalData.WFU[sid];if(!!WFU.consent_exist)if(WFU.consent.remember_consent){WFU.consent.update("clear");WFU.consent_exist=false}else WFU.consent.update("init")};
102
+ CBUV_Code_Objects.upload_pass_params=function(params,mode){var sid=this.sid;if(!!GlobalData.WFU[sid].consent_exist)params.consent_result=document.getElementById("consentresult_"+sid).value;return params};CBUV_Code_Objects.after_upload=function(response){var sid=this.sid;var txt_match=response.match(/CBUVJS\[(.*?)\]/);var txt_header=txt_match?typeof txt_match[1]!="undefined"?txt_match[1]:"":"";if(txt_header!="")eval(wfu_plugin_decode_string(txt_header))};return CBUV_Code_Objects};
103
+ function wfu_filesselected(sid){var WFU=GlobalData.WFU[sid];var farr=wfu_get_filelist(sid);if(farr.length==0&&!WFU.allownofile&&!!WFU.textbox_exist)WFU.textbox.update("nofile");return farr.length}
104
+ function wfu_check_required_userdata(sid,prompt){var WFU=GlobalData.WFU[sid];var userdata_count=wfu_get_userdata_count(sid);var req_empty=false;for(var i=0;i<userdata_count;i++){WFU.userdata.props[i].store();var error_message="";if(WFU.userdata.props[i].required)error_message=WFU.userdata.codes[i].empty();if(error_message===""&&WFU.userdata.codes[i].validate!=null&&WFU.userdata.props[i].validate)error_message=WFU.userdata.codes[i].validate();if(error_message!==""){if(prompt)WFU.userdata.prompt(WFU.userdata.props[i],
105
+ error_message);req_empty=true}}return!req_empty}
106
+ function wfu_HTML5UploadFile(sid){var WFU=GlobalData.WFU[sid];if(!wfu_BrowserCaps.supportsAJAX){wfu_redirect_to_classic(sid,1,1);return}if(!wfu_BrowserCaps.supportsHTML5){wfu_redirect_to_classic(sid,1,2);return}var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;var numfiles=wfu_filesselected(sid);if(numfiles==0&&!WFU.allownofile)return;if(numfiles==0)wfu_selectbutton_clicked(sid);if(!!WFU.subfolders_exist&&numfiles>0&&!WFU.subfolders.check()){if(WFU.singlebutton)wfu_clear_files(sid);return}var numpasses=
107
+ numfiles;numpasses+=numpasses;if(!wfu_check_required_userdata(sid,true)){if(WFU.singlebutton)wfu_clear_files(sid);return}if(!wfu_Code_Objects[sid].apply_filters("pre_start_check",true))return;var unique_upload_id=wfu_randomString(10);wfu_lock_upload(sid);wfu_Code_Objects[sid].do_action("pre_start");if(!wfu_Code_Objects[sid].apply_filters("pre_start_ask_server",false,WFU.has_filters?"true":"false"))wfu_HTML5UploadFile_cont(sid,unique_upload_id);else{var url=GlobalData.consts.ajax_url;params=new Array(5);
108
+ params[0]=new Array(2);params[0][0]="action";params[0][1]="wfu_ajax_action_ask_server";params[1]=new Array(2);params[1][0]="session_token";params[1][1]=WFU.session;params[2]=new Array(2);params[2][0]="sid";params[2][1]=sid;params[3]=new Array(2);params[3][0]="unique_id";params[3][1]=unique_upload_id;params[4]=new Array(2);params[4][0]="wfu_uploader_nonce";params[4][1]=document.getElementById("wfu_uploader_nonce_"+sid).value;var params_obj=wfu_Code_Objects[sid].apply_filters("askserver_pass_params",
109
+ {});for(var prop in params_obj)if(params_obj.hasOwnProperty(prop))params.push([prop,params_obj[prop]]);var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+"="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){var txt=xhr.responseText;var txt_value="";var success_txt="wfu_askserver_success:";var error_txt="wfu_askserver_error:";
110
+ var pos_success=txt.indexOf(success_txt);var pos_error=txt.indexOf(error_txt);var pos=-1;if(pos_success>-1){txt_value=txt.substr(pos_success+success_txt.length);wfu_Code_Objects[sid].do_action("askserver_success",txt_value,"ajax");wfu_HTML5UploadFile_cont(sid,unique_upload_id)}else if(pos_error>-1){txt_value=txt.substr(pos_error+error_txt.length);wfu_unlock_upload(sid);wfu_Code_Objects[sid].do_action("askserver_error",txt_value)}}else{alert(GlobalData.consts.remoteserver_noresult);wfu_unlock_upload(sid);
111
+ wfu_Code_Objects[sid].do_action("askserver_noresult")}};xhr.send(parameters)}}
112
+ function wfu_HTML5UploadFile_cont(sid,unique_upload_id){function sendfile(ind,file,only_check,force_close_connection){ret_status=true;var xhr=wfu_GetHttpRequestObject();var xhr_close_connection=wfu_GetHttpRequestObject();if(xhr==null||xhr_close_connection==null)return;var fd=null;var fd_close_connection=null;try{var fd=new FormData;var fd_close_connection=new FormData}catch(e){}if(fd==null||fd_close_connection==null)return;fd.append("action","wfu_ajax_action");fd.append("wfu_uploader_nonce",document.getElementById("wfu_uploader_nonce_"+
113
+ sid).value);if(!only_check)fd.append("uploadedfile_"+sid+suffice,file);fd.append("uploadedfile_"+sid+"_index",ind);fd.append("uploadedfile_"+sid+"_name",wfu_plugin_encode_string(farr[ind].name));fd.append("uploadedfile_"+sid+"_size",farr[ind].size);fd.append("uniqueuploadid_"+sid,unique_upload_id);fd.append("params_index",WFU.params_index);fd.append("subdir_sel_index",subdir_sel_index);fd.append("nofileupload_"+sid,nofileupload?"1":"0");if(only_check)fd.append("only_check","1");else fd.append("only_check",
114
+ "0");fd.append("session_token",WFU.session);var other_params=wfu_Code_Objects[sid].apply_filters("upload_pass_params",{},"ajax");for(var prop in other_params)if(other_params.hasOwnProperty(prop))fd.append(prop,other_params[prop]);var userdata_count=wfu_get_userdata_count(sid);for(var ii=0;ii<userdata_count;ii++)fd.append("hiddeninput_"+sid+"_userdata_"+ii,document.getElementById("hiddeninput_"+sid+"_userdata_"+ii).value);wfu_initialize_fileupload_xhr(xhr,sid,unique_upload_id,ind,farr[ind].name);xhr.loading=
115
+ true;if(!only_check){xhr.size=file.size;xhr.totalsize=farr[ind].size}if(force_close_connection){fd_close_connection.append("action","wfu_ajax_action");fd_close_connection.append("wfu_uploader_nonce",document.getElementById("wfu_uploader_nonce_"+sid).value);fd_close_connection.append("params_index",WFU.params_index);fd_close_connection.append("session_token",WFU.session);fd_close_connection.append("force_connection_close","1");xhr_close_connection.open("POST",GlobalData.consts.ajax_url,false);try{xhr_close_connection.send(fd_close_connection)}catch(err){}ret_status=
116
+ xhr_close_connection.responseText.indexOf("success")>-1}if(ret_status)if(!only_check){xhr.upload.xhr=xhr;xhr.upload.dummy=1;xhr.upload.addEventListener("loadstart",wfu_loadStart,false);xhr.upload.addEventListener("progress",new Function("evt","wfu_uploadProgress(evt, "+sid+", "+xhr.xhrid+", "+(WFU.debugmode?"true":"false")+");"),false);xhr.addEventListener("load",wfu_uploadComplete,false);xhr.addEventListener("error",new Function("evt","wfu_uploadFailed(evt, "+(WFU.debugmode?"true":"false")+");"),
117
+ false);xhr.addEventListener("abort",wfu_uploadCanceled,false);xhr.open("POST",GlobalData.consts.ajax_url,true);xhr.send(fd)}else{xhr.addEventListener("load",function(evt){evt={target:{responseText:evt.target.responseText,shortcode_id:sid,return_status:true}};var file_status=wfu_uploadComplete.call(xhr,evt);xhr.file_id=0;ret_status=file_status=="success"||file_status=="warning";if(ret_status&&!nofileupload)sendfile(ind,file,false,false);else if(ret_status&&nofileupload);},false);xhr.addEventListener("error",
118
+ function(evt){return},false);xhr.open("POST",GlobalData.consts.ajax_url,true);xhr.send(fd)}else{var evt={target:{responseText:"",shortcode_id:sid}};wfu_uploadComplete.call(xhr,evt)}inc++;return ret_status}var WFU=GlobalData.WFU[sid];var subdir_sel_index=-1;if(!!WFU.subfolders_exist)subdir_sel_index=WFU.subfolders.index();var farr=wfu_get_filelist(sid);var nofileupload=false;if(farr.length==0&&WFU.allownofile){nofileupload=true;farr=[{name:"dummy.txt",size:0}]}var suffice="";GlobalData.UploadInProgressString+=
119
+ "["+unique_upload_id+"]";GlobalData[sid]={};GlobalData[sid].unique_id=unique_upload_id;GlobalData[sid].last=false;GlobalData[sid].files_count=1;GlobalData[sid].files_processed=0;GlobalData[sid].upload_state=0;GlobalData[sid].nofileupload=nofileupload;GlobalData[sid].store_nothing=!!WFU.consent_exist&&document.getElementById("consentresult_"+sid).value=="no"&&WFU.not_store_files;GlobalData[sid].message=[];GlobalData[sid].update_wpfilebase="";GlobalData[sid].redirect_link="";GlobalData[sid].notify_by_email=
120
+ 0;GlobalData[sid].admin_messages={};GlobalData[sid].admin_messages.wpfilebase="";GlobalData[sid].admin_messages.notify="";GlobalData[sid].admin_messages.redirect="";GlobalData[sid].admin_messages.debug=[];GlobalData[sid].admin_messages.other=[];GlobalData[sid].errors={};GlobalData[sid].errors.wpfilebase="";GlobalData[sid].errors.notify="";GlobalData[sid].errors.redirect="";GlobalData[sid].xhrs=Array();GlobalData[sid].metricstotal={size:farr[0].size,loaded:0,progress_pos:0};GlobalData[sid].metrics=
121
+ [{size:farr[0].size,loaded:0,progress_pos:0}];if(!!WFU.progressbar_exist&&!nofileupload)WFU.progressbar.show("progressive");wfu_attach_cancel_event(sid,unique_upload_id);var Params=wfu_Initialize_Params();Params.general.shortcode_id=sid;Params.general.unique_id=unique_upload_id;wfu_ProcessUploadComplete(sid,0,Params,unique_upload_id,"",[false,null,false]);var inc=0;var ret_status=true;var i=0;var fprops=[];sendfile(i,farr[i],true,false)}
122
+ function wfu_initialize_fileupload_xhr(xhr,sid,unique_upload_id,file_ind,filename){var WFU=GlobalData.WFU[sid];var xhrid=file_ind>=0?GlobalData[sid].xhrs.push(xhr)-1:-1;var d=new Date;xhr.xhrid=xhrid;xhr.shortcode_id=sid;xhr.requesttype=file_ind>=0?"fileupload":"email";xhr.file_id=file_ind+1;xhr.size=0;xhr.totalsize=0;xhr.loading=false;xhr.deltasize=0;xhr.deltaloaded=0;xhr.sizeloaded=0;xhr.aborted=false;xhr.unique_id=unique_upload_id;xhr.start_time=d.getTime();xhr.end_time=xhr.start_time;xhr.finish_time=
123
+ xhr.start_time+parseInt(GlobalData.consts.max_time_limit)*1E3;xhr.success_message_header=WFU.success_header.replace(/%username%/g,"no data");xhr.success_message_header=xhr.success_message_header.replace(/%useremail%/g,"no data");xhr.success_message_header=xhr.success_message_header.replace(/%filename%/g,filename);xhr.success_message_header=xhr.success_message_header.replace(/%filepath%/g,filename);xhr.error_message_header=WFU.error_header.replace(/%username%/g,"no data");xhr.error_message_header=
124
+ xhr.error_message_header.replace(/%useremail%/g,"no data");xhr.error_message_header=xhr.error_message_header.replace(/%filename%/g,filename);xhr.error_message_header=xhr.error_message_header.replace(/%filepath%/g,filename);xhr.error_message_failed=GlobalData.consts.message_failed;xhr.error_message_cancelled=GlobalData.consts.message_cancelled;xhr.error_adminmessage_unknown=GlobalData.consts.adminmessage_unknown.replace(/%username%/g,"no data");xhr.error_adminmessage_unknown=xhr.error_adminmessage_unknown.replace(/%useremail%/g,
125
+ "no data");xhr.error_adminmessage_unknown=xhr.error_adminmessage_unknown.replace(/%filename%/g,filename);xhr.error_adminmessage_unknown=xhr.error_adminmessage_unknown.replace(/%filepath%/g,filename)}function wfu_get_userdata_count(sid){var WFU=GlobalData.WFU[sid];var fields_count=0;if(!!WFU.userdata_exist)fields_count=WFU.userdata.props.length;return fields_count}
126
+ function wfu_lock_upload(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.textbox_exist)WFU.textbox.update("lock");if(!!WFU.uploadform_exist)WFU.uploadform.lock();if(!!WFU.subfolders_exist)WFU.subfolders.toggle(false);if(!!WFU.submit_exist)WFU.submit.toggle(false);var userdata_count=wfu_get_userdata_count(sid);for(var i=0;i<userdata_count;i++)WFU.userdata.codes[i].lock();wfu_Code_Objects[sid].do_action("lock_upload")}
127
+ function wfu_unlock_upload(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.textbox_exist)WFU.textbox.update("unlock");if(!!WFU.uploadform_exist)WFU.uploadform.unlock();if(!!WFU.subfolders_exist)WFU.subfolders.toggle(true);if(!!WFU.submit_exist)WFU.submit.toggle(true);var userdata_count=wfu_get_userdata_count(sid);for(var i=0;i<userdata_count;i++)WFU.userdata.codes[i].unlock();wfu_Code_Objects[sid].do_action("unlock_upload")}
128
+ function wfu_clear_files(sid){var WFU=GlobalData.WFU[sid];if(!!WFU.uploadform_exist)WFU.uploadform.reset();if(typeof WFU.filearray!="undefined"){WFU.filearray.length=0;WFU.filearrayprops.length=0}if(!!WFU.textbox_exist)WFU.textbox.update("clear")}
129
+ function wfu_check_reset(sid){var WFU=GlobalData.WFU[sid];var G=GlobalData[sid];if(WFU.resetmode=="always")return true;else if(WFU.resetmode=="never")return false;else if(WFU.resetmode=="onsuccess")return[4,5,6,14].indexOf(G.upload_state)>-1;else if(WFU.resetmode=="onfullsuccess")return[4,5,14].indexOf(G.upload_state)>-1;else return true}
130
+ function wfu_clear(sid){var WFU=GlobalData.WFU[sid];var do_reset=wfu_check_reset(sid);wfu_clear_files(sid);if(do_reset){if(!!WFU.subfolders_exist)WFU.subfolders.reset();var userdata_count=wfu_get_userdata_count(sid);for(var i=0;i<userdata_count;i++)WFU.userdata.codes[i].reset();if(!!WFU.uploadform_exist)WFU.uploadform.resetDummy()}wfu_Code_Objects[sid].do_action("clear_upload")}
131
+ function wfu_invoke_shortcode_editor(WFU){var sid=WFU.shortcode_id;var same=0;var n=GlobalData.WFU.n;if(WFU.shortcode_tag=="wordpress_file_upload_browser")n=GlobalData.WFUB.n;for(var i=0;i<n.length;i++)if(n[i]==sid)same++;if(same==0)return;if(same>1){alert(GlobalData.consts.same_pluginid);return}var xhr=wfu_GetHttpRequestObject();if(xhr==null)return;WFU.visualeditorbutton.update("on_invoke");var url=GlobalData.consts.ajax_url;params=new Array(6);params[0]=new Array(2);params[0][0]="action";params[0][1]=
132
+ "wfu_ajax_action_edit_shortcode";params[1]=new Array(2);params[1][0]="upload_id";params[1][1]=sid;params[2]=new Array(2);params[2][0]="post_id";params[2][1]=WFU.post_id;params[3]=new Array(2);params[3][0]="post_hash";params[3][1]=WFU.post_hash;params[4]=new Array(2);params[4][0]="shortcode_tag";params[4][1]=WFU.shortcode_tag;params[5]=new Array(2);params[5][0]="widget_id";params[5][1]=WFU.widgetid?WFU.widgetid:"";var parameters="";for(var i=0;i<params.length;i++)parameters+=(i>0?"&":"")+params[i][0]+
133
+ "="+encodeURI(params[i][1]);xhr.open("POST",url,true);xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");xhr.onreadystatechange=function(){if(xhr.readyState==4)if(xhr.status==200){WFU.visualeditorbutton.update("on_open");var start_text="wfu_edit_shortcode:";var pos=xhr.responseText.indexOf(start_text);if(pos==-1)pos=xhr.responseText.length;var messages=xhr.responseText.substr(0,pos);var response=xhr.responseText.substr(pos+start_text.length,xhr.responseText.length-pos-start_text.length);
134
+ pos=response.indexOf(":");var txt_header=response.substr(0,pos);txt_value=response.substr(pos+1,response.length-pos-1);if(txt_header=="success"){var editor_window=window.open(wfu_plugin_decode_string(txt_value),"_blank");if(editor_window)editor_window.plugin_window=window;else alert(GlobalData.consts.enable_popups)}else if(txt_header=="check_page_obsolete")alert(txt_value)}};xhr.send(parameters)}
135
+ wfu_initialize_webcam=function(sid,mode,audiocapture,videowidth,videoheight,videoaspectratio,videoframerate,camerafacing,maxrecordtime){if(typeof wfu_parse_video_width=="undefined")wfu_parse_video_width=function(videowidth){var vw=parseInt(videowidth);if(vw>0){this.empty=false;this.video.width=vw}};if(typeof wfu_parse_video_height=="undefined")wfu_parse_video_height=function(videoheight){var vh=parseInt(videoheight);if(vh>0){this.empty=false;this.video.height=vh}};if(typeof wfu_parse_video_aspectratio==
136
+ "undefined")wfu_parse_video_aspectratio=function(videoaspectratio){var ar=parseFloat(videoaspectratio);if(ar>0){this.empty=false;this.video.aspectRatio=ar}};if(typeof wfu_parse_video_framerate=="undefined")wfu_parse_video_framerate=function(videoframerate){var fr=parseFloat(videoframerate);if(fr>0){this.empty=false;this.video.frameRate=fr}};if(typeof wfu_parse_video_facingmode=="undefined")wfu_parse_video_facingmode=function(camerafacing){var cf=camerafacing=="front"?"user":camerafacing=="back"?"environment":
137
+ "";if(cf!=""){this.empty=false;this.video.facingMode=cf}};var video_settings={empty:true,video:{}};wfu_parse_video_width.call(video_settings,videowidth);wfu_parse_video_height.call(video_settings,videoheight);wfu_parse_video_aspectratio.call(video_settings,videoaspectratio);wfu_parse_video_framerate.call(video_settings,videoframerate);wfu_parse_video_facingmode.call(video_settings,camerafacing);var WebcamProps={mode:mode,audio:audiocapture=="true",video:video_settings.empty?true:video_settings.video,
138
+ maxrecordtime:maxrecordtime};GlobalData.WFU[sid].webcamProps=WebcamProps;wfu_reinitialize_webcam(sid)};
139
+ wfu_reinitialize_webcam=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;webcam_props.active=true;webcam_props.width=0;webcam_props.width=0;webcam_props.timeStart=0;webcam_props.duration=0;webcam_props.counting=false;webcam_props.stream=null;webcam_props.media=null;webcam_props.blobs=null;webcam_props.playing=false;var WebcamProps=webcam_props;webcam_obj.updateStatus("idle");var constraints={audio:WebcamProps.audio,video:WebcamProps.video};if(typeof Promise==
140
+ "undefined"){Promise=function(mainCallback){this.mainCallback=mainCallback;this.then=function(successCallback){this.successCallback=successCallback;return this};this["catch"]=function(errorCallback){mainCallback(this.successCallback,errorCallback)}};PromiseRejected=function(error){this.then=function(successCallback){return this};this["catch"]=function(errorCallback){errorCallback(error)}};Promise.reject=function(error){return new PromiseRejected(error)}}var promisifiedOldGUM=function(constraints,
141
+ successCallback,errorCallback){var getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;if(!getUserMedia||typeof MediaRecorder=="undefined")return Promise.reject(new Error("getUserMedia is not implemented in this browser"));return new Promise(function(successCallback,errorCallback){getUserMedia.call(navigator,constraints,successCallback,errorCallback)})};if(navigator.mediaDevices===undefined)navigator.mediaDevices={};if(navigator.mediaDevices.getUserMedia===
142
+ undefined)navigator.mediaDevices.getUserMedia=promisifiedOldGUM;navigator.mediaDevices.getUserMedia(constraints).then(function(stream){webcam_props.stream=stream;webcam_obj.setVideoProperties({autoplay:true,ontimeupdate:null,onerror:null,onloadeddata:function(e){wfu_webcam_init_callback(sid)},srcObject:stream});webcam_obj.initButtons(WebcamProps.mode)})["catch"](function(e){console.log("Video not supported!",e);webcam_obj.updateStatus("video_notsupported")})};
143
+ wfu_webcam_init_callback=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;var video_size=webcam_obj.videoSize();webcam_props.width=video_size.width;webcam_props.height=video_size.height;webcam_obj.initCallback()};
144
+ wfu_webcam_counter_status=function(sid,action){var webcam_props=GlobalData.WFU[sid].webcamProps;if(action=="start"){var d=new Date;webcam_props.duration=0;webcam_props.timeStart=d.getTime()/1E3;webcam_props.counting=true;wfu_webcam_update_counter(sid)}else{var d=new Date;webcam_props.duration=d.getTime()/1E3-webcam_props.timeStart;webcam_props.counting=false}};
145
+ wfu_webcam_update_counter=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.counting){var d=new Date;var dif=d.getTime()/1E3-webcam_props.timeStart;webcam_obj.updateTimer(dif);setTimeout(function(){wfu_webcam_update_counter(sid)},100)}};
146
+ wfu_webcam_onoff=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.active){webcam_obj.updateStatus("off");webcam_obj.updateButtonStatus("hidden");if(webcam_props.stream&&webcam_props.stream.stop)webcam_props.stream.stop();webcam_props.stream=null;webcam_props.media=null;webcam_props.blobs=null;webcam_props.active=false}else wfu_reinitialize_webcam(sid);wfu_selectbutton_clicked(sid)};
147
+ wfu_webcam_golive=function(sid){var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.playing)return;wfu_reinitialize_webcam(sid);wfu_add_files(sid,[],false);wfu_selectbutton_clicked(sid);wfu_update_uploadbutton_status(sid)};
148
+ wfu_webcam_start_rec=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.media&&webcam_props.media.state&&webcam_props.media.state=="recording")return;try{webcam_props.media=new MediaRecorder(webcam_props.stream)}catch(err){alert(GlobalData.consts.webcam_video_notsupported);return}webcam_props.blobs=[];webcam_props.media.ondataavailable=function(e){var d=new Date;var dif=d.getTime()/1E3-webcam_props.timeStart;if(webcam_props.maxrecordtime==
149
+ -1||webcam_props.maxrecordtime>0&&dif<=webcam_props.maxrecordtime){if(e.data&&e.data.size>0)webcam_props.blobs.push(e.data)}else wfu_webcam_stop_rec(sid)};webcam_obj.updateButtonStatus("recording");wfu_webcam_counter_status(sid,"start");webcam_props.media.onstop=function(e){wfu_webcam_counter_status(sid,"stop");webcam_obj.updateButtonStatus("after_recording");wfu_webcam_onstop(e,sid)};webcam_props.media.start(10)};
150
+ wfu_webcam_stop_rec=function(sid){var webcam_props=GlobalData.WFU[sid].webcamProps;webcam_props.media.stop()};
151
+ wfu_webcam_onstop=function(e,sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.blobs.length==0){alert(GlobalData.consts.webcam_video_nothingrecorded);wfu_webcam_golive(sid)}else{if(webcam_props.stream)webcam_obj.screenshot();var superBuffer=new Blob(webcam_props.blobs,{type:"video/mp4"});webcam_obj.setVideoProperties({autoplay:false,ontimeupdate:function(e){wfu_webcam_update_pos(sid)},onended:function(e){wfu_webcam_ended(sid)},onloadeddata:function(e){if(webcam_obj.readyState()>=
152
+ 2)webcam_obj.updateButtonStatus("ready_playback")},onerror:function(e){webcam_obj.setVideoProperties({onloadeddata:null,srcObject:webcam_props.stream})},srcObject:superBuffer});superBuffer.name="video.mp4";wfu_add_files(sid,[{file:superBuffer,props:{}}],false);wfu_update_uploadbutton_status(sid)}};
153
+ wfu_webcam_play=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.playing)return;webcam_obj.updateButtonStatus("playing");webcam_props.playing=true;webcam_obj.play()};wfu_webcam_ended=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;webcam_obj.ended();webcam_obj.updateButtonStatus("ready_playback");webcam_props.playing=false};
154
+ wfu_webcam_pause=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;webcam_obj.pause();webcam_obj.updateButtonStatus("ready_playback");webcam_props.playing=false};wfu_webcam_back=function(sid){GlobalData.WFU[sid].webcam.back()};wfu_webcam_fwd=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;webcam_obj.fwd(webcam_props.duration)};
155
+ wfu_webcam_take_picture=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;if(webcam_props.stream){webcam_obj.screenshot(function(image_file){image_file.name="image.png";wfu_add_files(sid,[{file:image_file,props:{}}],false);wfu_update_uploadbutton_status(sid)},"image/png");webcam_obj.updateButtonStatus("after_screenshot")}};
156
+ wfu_webcam_update_pos=function(sid){var webcam_obj=GlobalData.WFU[sid].webcam;var webcam_props=GlobalData.WFU[sid].webcamProps;webcam_obj.updatePlayProgress(webcam_props.duration);webcam_obj.updateTimer(video.currentTime)};wfu_run_js_from_bank();
lib/wfu_admin.php CHANGED
@@ -1,1385 +1,1385 @@
1
- <?php
2
-
3
- /**
4
- * Initialize Dashboard Area of Plugin
5
- *
6
- * This file initializes the Dashboard area of the plugin; it registers the
7
- * Dashboard menu pages and processes Dashboard requests.
8
- *
9
- * @link /lib/wfu_admin.php
10
- *
11
- * @package WordPress File Upload Plugin
12
- * @subpackage Core Components
13
- * @since 2.1.2
14
- */
15
-
16
- /**
17
- * Register Dashboard Styles and Scripts.
18
- *
19
- * This function registers styles and scripts for Dashboard area.
20
- *
21
- * @since 2.4.6
22
- */
23
- function wordpress_file_upload_admin_init() {
24
- $uri = $_SERVER['REQUEST_URI'];
25
- $is_admin = current_user_can( 'manage_options' );
26
- $can_edit_posts = ( current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) );
27
- $can_open_composer = ( WFU_VAR("WFU_SHORTCODECOMPOSER_NOADMIN") == "true" && $can_edit_posts );
28
- if ( is_admin() && ( ( $is_admin && strpos($uri, "options-general.php") !== false ) ) ||
29
- //conditional that will register scripts for non-admin users who can
30
- //edit posts or pages so that they can open the shortcode composer
31
- ( is_admin() && !$is_admin && $can_open_composer && strpos($uri, "admin.php") !== false ) ) {
32
- //apply wfu_before_admin_scripts to get additional settings
33
- $changable_data = array();
34
- /**
35
- * Execute Custom Actions Before Loading Admin Scripts.
36
- *
37
- * This filter allows to execute custom actions before scripts and
38
- * styles of the plugin's main Dashboard area are loaded. Loading of
39
- * plugin's scripts and styles can be completely customised.
40
- *
41
- * @since 4.1.0
42
- *
43
- * @param array $changable_data {
44
- * Controls loading of frontpage scripts.
45
- *
46
- * @type mixed $return_value Optional. If it is set then no
47
- * frontpage scripts will be loaded.
48
- * @type string $correct_NextGenGallery_incompatibility Optional. If
49
- * it is set to "true" then JQuery UI styles will not be
50
- * loaded in order to avoid incompatibility with NextGEN
51
- * Gallery plugin.
52
- * @type string $correct_JQueryUI_incompatibility Optional. If it is
53
- * set to "true" then JQuery UI styles will not be loaded
54
- * (same as previous parameter).
55
- * @type string $exclude_datepicker Optional. If it is set to "true"
56
- * then jQuery datepicker styles and scripts will not be
57
- * loaded.
58
- * }
59
- */
60
- $ret_data = apply_filters('wfu_before_admin_scripts', $changable_data);
61
- //if $ret_data contains 'return_value' key then no scripts will be
62
- //registered
63
- if ( isset($ret_data['return_value']) ) return $ret_data['return_value'];
64
- //continue with script and style registering
65
- wp_register_style('wordpress-file-upload-admin-style', WPFILEUPLOAD_DIR.'css/wordpress_file_upload_adminstyle.css',false,'1.0','all');
66
- wp_register_style('wordpress-file-upload-adminbar-style', WPFILEUPLOAD_DIR.'css/wordpress_file_upload_adminbarstyle.css',false,'1.0','all');
67
- //do not register JQuery UI css if $ret_data denotes incompatibility
68
- //issues
69
- if ( ( !isset($ret_data["correct_NextGenGallery_incompatibility"]) || $ret_data["correct_NextGenGallery_incompatibility"] != "true" ) &&
70
- ( !isset($ret_data["correct_JQueryUI_incompatibility"]) || $ret_data["correct_JQueryUI_incompatibility"] != "true" ) )
71
- wp_register_style('jquery-ui-css', WPFILEUPLOAD_DIR.'vendor/jquery/jquery-ui.min.css');
72
- //don't load datepicker js if $ret_data exclude_datepicker flag is true
73
- if ( !isset($ret_data["exclude_datepicker"]) || $ret_data["exclude_datepicker"] != "true" )
74
- wp_register_script('jquery-ui-datepicker', false, array('jquery'));
75
- wp_register_script('wordpress_file_upload_admin_script', WPFILEUPLOAD_DIR.'js/wordpress_file_upload_adminfunctions.js', array( 'wp-color-picker' ), false, true);
76
- if ( !$is_admin ) {
77
- add_action('admin_post_edit_shortcode', 'wordpress_file_upload_manage_dashboard');
78
- add_action('admin_print_scripts', 'wfu_enqueue_admin_scripts');
79
- }
80
- }
81
- //register scripts for Uploaded Files
82
- elseif ( is_admin() && $is_admin && strpos($uri, "admin.php") !== false ) {
83
- //apply wfu_before_admin_scripts to get additional settings
84
- $changable_data = array();
85
- /**
86
- * Execute Custom Actions Before Loading Uploaded Files Scripts.
87
- *
88
- * This filter allows to execute custom actions before scripts and
89
- * styles of the plugin's Uploaded Files Dashboard page are loaded.
90
- * Loading of plugin's scripts and styles can be completely customised.
91
- *
92
- * @since 4.7.0
93
- *
94
- * @param array $changable_data {
95
- * Controls loading of frontpage scripts.
96
- *
97
- * @type mixed $return_value Optional. If it is set then no
98
- * frontpage scripts will be loaded.
99
- * @type string $correct_NextGenGallery_incompatibility Optional. If
100
- * it is set to "true" then JQuery UI styles will not be
101
- * loaded in order to avoid incompatibility with NextGEN
102
- * Gallery plugin.
103
- * @type string $correct_JQueryUI_incompatibility Optional. If it is
104
- * set to "true" then JQuery UI styles will not be loaded
105
- * (same as previous parameter).
106
- * }
107
- */
108
- $ret_data = apply_filters('wfu_before_uploadedfiles_admin_scripts', $changable_data);
109
- //if $ret_data contains 'return_value' key then no scripts will be
110
- //registered
111
- if ( isset($ret_data['return_value']) ) return $ret_data['return_value'];
112
- //continue with script and style registering
113
- wp_register_style('wordpress-file-upload-admin-style', WPFILEUPLOAD_DIR.'css/wordpress_file_upload_adminstyle.css',false,'1.0','all');
114
- wp_register_style('wordpress-file-upload-adminbar-style', WPFILEUPLOAD_DIR.'css/wordpress_file_upload_adminbarstyle.css',false,'1.0','all');
115
- //do not register JQuery UI css if $ret_data denotes incompatibility
116
- //issues
117
- if ( ( !isset($ret_data["correct_NextGenGallery_incompatibility"]) || $ret_data["correct_NextGenGallery_incompatibility"] != "true" ) &&
118
- ( !isset($ret_data["correct_JQueryUI_incompatibility"]) || $ret_data["correct_JQueryUI_incompatibility"] != "true" ) )
119
- wp_register_style('jquery-ui-css', WPFILEUPLOAD_DIR.'vendor/jquery/jquery-ui.min.css');
120
- wp_register_script('wordpress_file_upload_admin_script', WPFILEUPLOAD_DIR.'js/wordpress_file_upload_adminfunctions.js', array( 'wp-color-picker' ), false, true);
121
- }
122
- //register scripts for admin bar menu item
123
- elseif ( is_admin() && $is_admin ) {
124
- //script and style registering
125
- wp_register_style('wordpress-file-upload-adminbar-style', WPFILEUPLOAD_DIR.'css/wordpress_file_upload_adminbarstyle.css',false,'1.0','all');
126
- }
127
- }
128
-
129
- /**
130
- * Register Dashboard Menu Pages.
131
- *
132
- * This function registers the Dashboard pages of the plugin.
133
- *
134
- * @since 2.1.2
135
- */
136
- function wordpress_file_upload_add_admin_pages() {
137
- global $wpdb;
138
- global $wfu_uploadedfiles_hook_suffix;
139
- $table_name1 = $wpdb->prefix . "wfu_log";
140
-
141
- $page_hook_suffix = false;
142
- if ( current_user_can( 'manage_options' ) ) $page_hook_suffix = add_options_page('Wordpress File Upload', 'Wordpress File Upload', 'manage_options', 'wordpress_file_upload', 'wordpress_file_upload_manage_dashboard');
143
- if ( $page_hook_suffix !== false ) add_action('admin_print_scripts-'.$page_hook_suffix, 'wfu_enqueue_admin_scripts');
144
- //conditional that will create Wordpress File Upload Dashboard menu, if it
145
- //has not already been created, for non-admin users who can edit posts or
146
- //pages, so that their requests for opening the shortcode composer can be
147
- //handled
148
- elseif ( WFU_VAR("WFU_SHORTCODECOMPOSER_NOADMIN") == "true" && ( current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) ) ) {
149
- $page_hook_suffix = add_menu_page('Wordpress File Upload', 'Wordpress File Upload', 'read', 'wordpress_file_upload', 'wordpress_file_upload_manage_dashboard_editor');
150
- if ( $page_hook_suffix !== false ) add_action('admin_print_scripts-'.$page_hook_suffix, 'wfu_enqueue_admin_scripts');
151
- }
152
- //add Uploaded Files menu if it is allowed
153
- $wfu_uploadedfiles_hook_suffix = false;
154
- if ( current_user_can( 'manage_options' ) && WFU_VAR("WFU_UPLOADEDFILES_MENU") == "true" ) {
155
- //get the number of new (unread) uploaded files
156
- $unread_files_count = wfu_get_unread_files_count();
157
- $text = $unread_files_count;
158
- if ( $unread_files_count > 99 ) $text = "99+";
159
- $title = 'Uploaded Files <span class="update-plugins count-'.$unread_files_count.'"><span class="plugin-count">'.$text.'</span></span>';
160
- $wfu_uploadedfiles_hook_suffix = add_menu_page(
161
- 'Uploaded Files',
162
- $title,
163
- 'manage_options',
164
- 'wfu_uploaded_files',
165
- 'wfu_uploadedfiles_menu',
166
- 'dashicons-upload',
167
- 6
168
- );
169
- }
170
- if ( $wfu_uploadedfiles_hook_suffix !== false ) {
171
- add_action('admin_print_scripts-'.$wfu_uploadedfiles_hook_suffix, 'wfu_enqueue_uploadedfiles_admin_scripts');
172
- }
173
- //enqueue scripts for admin bar menu item
174
- if ( current_user_can( 'manage_options' ) )
175
- add_action('admin_print_scripts', 'wfu_enqueue_uploadedfiles_adminbar_scripts');
176
- }
177
-
178
- /**
179
- * Enqueue Main Dashboard Page Styles and Scripts.
180
- *
181
- * This function registers the styles and scripts of the plugin's main
182
- * Dashboard page.
183
- *
184
- * @since 2.4.6
185
- */
186
- function wfu_enqueue_admin_scripts() {
187
- $uri = $_SERVER['REQUEST_URI'];
188
- $is_admin = current_user_can( 'manage_options' );
189
- $can_open_composer = ( WFU_VAR("WFU_SHORTCODECOMPOSER_NOADMIN") == "true" && ( current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) ) );
190
- if ( is_admin() && ( ( $is_admin && strpos($uri, "options-general.php") !== false ) ) ||
191
- //conditional that will enqueue scripts for non-admin users who can
192
- //edit posts or pages so that they can open the shortcode composer
193
- ( is_admin() && $can_open_composer && strpos($uri, "admin.php") !== false ) ) {
194
- //apply wfu_before_admin_scripts to get additional settings
195
- $changable_data = array();
196
- /** This filter is documented above */
197
- $ret_data = apply_filters('wfu_before_admin_scripts', $changable_data);
198
- //if $ret_data contains 'return_value' key then no scripts will be
199
- //enqueued
200
- if ( isset($ret_data['return_value']) ) return $ret_data['return_value'];
201
- //continue with script and style enqueuing
202
- wp_enqueue_style('wordpress-file-upload-admin-style');
203
- wp_enqueue_style('wordpress-file-upload-adminbar-style');
204
- //do not enqueue JQuery UI css if $ret_data denotes incompatibility
205
- //issues
206
- if ( ( !isset($ret_data["correct_NextGenGallery_incompatibility"]) || $ret_data["correct_NextGenGallery_incompatibility"] != "true" ) &&
207
- ( !isset($ret_data["correct_JQueryUI_incompatibility"]) || $ret_data["correct_JQueryUI_incompatibility"] != "true" ) )
208
- wp_enqueue_style('jquery-ui-css');
209
- wp_enqueue_style( 'wp-color-picker' );
210
- //don't load datepicker js if $ret_data exclude_datepicker flag is true
211
- if ( !isset($ret_data["exclude_datepicker"]) || $ret_data["exclude_datepicker"] != "true" )
212
- wp_enqueue_script('jquery-ui-datepicker');
213
- wp_enqueue_script('wordpress_file_upload_admin_script');
214
- $AdminParams = array("wfu_ajax_url" => site_url()."/wp-admin/admin-ajax.php");
215
- wp_localize_script( 'wordpress_file_upload_admin_script', 'AdminParams', $AdminParams );
216
- }
217
- }
218
-
219
- /**
220
- * Enqueue Uploaded Files Dashboard Page Styles and Scripts.
221
- *
222
- * This function registers the styles and scripts of the plugin's Uploaded Files
223
- * Dashboard page.
224
- *
225
- * @since 4.7.0
226
- */
227
- function wfu_enqueue_uploadedfiles_admin_scripts() {
228
- $uri = $_SERVER['REQUEST_URI'];
229
- $is_admin = current_user_can( 'manage_options' );
230
- if ( is_admin() && $is_admin && strpos($uri, "admin.php") !== false ) {
231
- //apply wfu_before_admin_scripts to get additional settings
232
- $changable_data = array();
233
- /** This filter is documented above */
234
- $ret_data = apply_filters('wfu_before_uploadedfiles_admin_scripts', $changable_data);
235
- //if $ret_data contains 'return_value' key then no scripts will be
236
- //enqueued
237
- if ( isset($ret_data['return_value']) ) return $ret_data['return_value'];
238
- //continue with script and style enqueuing
239
- wp_enqueue_style('wordpress-file-upload-admin-style');
240
- wp_enqueue_style('wordpress-file-upload-adminbar-style');
241
- //do not enqueue JQuery UI css if $ret_data denotes incompatibility
242
- //issues
243
- if ( ( !isset($ret_data["correct_NextGenGallery_incompatibility"]) || $ret_data["correct_NextGenGallery_incompatibility"] != "true" ) &&
244
- ( !isset($ret_data["correct_JQueryUI_incompatibility"]) || $ret_data["correct_JQueryUI_incompatibility"] != "true" ) )
245
- wp_enqueue_style('jquery-ui-css');
246
- wp_enqueue_script('wordpress_file_upload_admin_script');
247
- $AdminParams = array("wfu_ajax_url" => site_url()."/wp-admin/admin-ajax.php");
248
- wp_localize_script( 'wordpress_file_upload_admin_script', 'AdminParams', $AdminParams );
249
- }
250
- }
251
-
252
- /**
253
- * Enqueue Admin Bar Styles and Scripts.
254
- *
255
- * This function registers the styles and scripts of the plugin for the Admin
256
- * Bar.
257
- *
258
- * @since 4.8.0
259
- */
260
- function wfu_enqueue_uploadedfiles_adminbar_scripts() {
261
- $is_admin = current_user_can( 'manage_options' );
262
- if ( is_admin() && $is_admin ) {
263
- //script and style enqueuing
264
- wp_enqueue_style('wordpress-file-upload-adminbar-style');
265
- }
266
- }
267
-
268
-
269
- /**
270
- * Initialize Tables.
271
- *
272
- * This function initializes the plugin's database tables and other actions.
273
- *
274
- * @since 2.4.1
275
- */
276
- function wordpress_file_upload_install() {
277
- global $wpdb;
278
- global $wfu_tb_log_version;
279
- global $wfu_tb_userdata_version;
280
- global $wfu_tb_dbxqueue_version;
281
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
282
-
283
- //define database tables
284
- $table_name1 = $wpdb->prefix . "wfu_log";
285
- $installed_ver = get_option( "wordpress_file_upload_table_log_version" );
286
- if( $installed_ver != $wfu_tb_log_version ) {
287
- $sql = "CREATE TABLE " . $table_name1 . " (
288
- idlog mediumint(9) NOT NULL AUTO_INCREMENT,
289
- userid int NOT NULL,
290
- uploaduserid int NOT NULL,
291
- uploadtime bigint,
292
- sessionid VARCHAR(40),
293
- filepath TEXT NOT NULL,
294
- filehash VARCHAR(100) NOT NULL,
295
- filesize bigint NOT NULL,
296
- uploadid VARCHAR(20) NOT NULL,
297
- pageid mediumint(9),
298
- blogid mediumint(9),
299
- sid VARCHAR(10),
300
- date_from DATETIME,
301
- date_to DATETIME,
302
- action VARCHAR(20) NOT NULL,
303
- linkedto mediumint(9),
304
- filedata TEXT,
305
- PRIMARY KEY (idlog),
306
- KEY uploadid (uploadid))
307
- DEFAULT CHARACTER SET = utf8
308
- DEFAULT COLLATE = utf8_general_ci;";
309
- dbDelta($sql);
310
- update_option("wordpress_file_upload_table_log_version", $wfu_tb_log_version);
311
- }
312
-
313
- $table_name2 = $wpdb->prefix . "wfu_userdata";
314
- $installed_ver = get_option( "wordpress_file_upload_table_userdata_version" );
315
- if( $installed_ver != $wfu_tb_userdata_version ) {
316
- $sql = "CREATE TABLE " . $table_name2 . " (
317
- iduserdata mediumint(9) NOT NULL AUTO_INCREMENT,
318
- uploadid VARCHAR(20) NOT NULL,
319
- property VARCHAR(100) NOT NULL,
320
- propkey mediumint(9) NOT NULL,
321
- propvalue TEXT,
322
- date_from DATETIME,
323
- date_to DATETIME,
324
- PRIMARY KEY (iduserdata),
325
- KEY uploadid (uploadid))
326
- DEFAULT CHARACTER SET = utf8
327
- DEFAULT COLLATE = utf8_general_ci;";
328
- dbDelta($sql);
329
- update_option("wordpress_file_upload_table_userdata_version", $wfu_tb_userdata_version);
330
- }
331
-
332
- $table_name3 = $wpdb->prefix . "wfu_dbxqueue";
333
- $installed_ver = get_option( "wordpress_file_upload_table_dbxqueue_version" );
334
- if( $installed_ver != $wfu_tb_dbxqueue_version ) {
335
- $sql = "CREATE TABLE " . $table_name3 . " (
336
- iddbxqueue mediumint(9) NOT NULL AUTO_INCREMENT,
337
- fileid mediumint(9) NOT NULL,
338
- priority mediumint(9) NOT NULL,
339
- status mediumint(9) NOT NULL,
340
- jobid VARCHAR(10) NOT NULL,
341
- start_time bigint,
342
- PRIMARY KEY (iddbxqueue))
343
- DEFAULT CHARACTER SET = utf8
344
- DEFAULT COLLATE = utf8_general_ci;";
345
- dbDelta($sql);
346
- update_option("wordpress_file_upload_table_dbxqueue_version", $wfu_tb_dbxqueue_version);
347
- }
348
- //adjust user state handler to 'dboption' except if there are active hooks
349
- //that use session; adjustment will be done only once
350
- if ( WFU_VAR("WFU_US_HANDLER_CHANGED") == "false" ) {
351
- $envars = get_option("wfu_environment_variables", array());
352
- {
353
- $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
354
- if ( $plugin_options["userstatehandler"] != "dboption" ) wfu_update_setting("userstatehandler", "dboption");
355
- if ( WFU_VAR("WFU_US_DBOPTION_BASE") != "cookies" ) {
356
- $GLOBALS["WFU_GLOBALS"]["WFU_US_DBOPTION_BASE"][3] = "cookies";
357
- $envars["WFU_US_DBOPTION_BASE"] = "cookies";
358
- }
359
- }
360
- $GLOBALS["WFU_GLOBALS"]["WFU_US_HANDLER_CHANGED"][3] = "true";
361
- $envars["WFU_US_HANDLER_CHANGED"] = "true";
362
- update_option("wfu_environment_variables", $envars);
363
- }
364
- }
365
-
366
- /**
367
- * Actions Before Uninstalling Plugin.
368
- *
369
- * This function performs actions before uninstalling the plugin.
370
- *
371
- * @since 4.4.0
372
- */
373
- function wordpress_file_upload_uninstall() {
374
- }
375
-
376
- /**
377
- * Actions After Plugins are Loaded.
378
- *
379
- * This function performs actions after plugin are loaded. It updates the
380
- * database tables in necessary.
381
- *
382
- * @since 2.4.1
383
- */
384
- function wordpress_file_upload_update_db_check() {
385
- global $wfu_tb_log_version;
386
- global $wfu_tb_userdata_version;
387
- global $wfu_tb_dbxqueue_version;
388
- // update_option("wordpress_file_upload_table_log_version", "0");
389
- // update_option("wordpress_file_upload_table_userdata_version", "0");
390
- // update_option("wordpress_file_upload_table_dbxqueue_version", "0");
391
- if ( get_option('wordpress_file_upload_table_log_version') != $wfu_tb_log_version || get_option('wordpress_file_upload_table_userdata_version') != $wfu_tb_userdata_version || get_option('wordpress_file_upload_table_dbxqueue_version') != $wfu_tb_dbxqueue_version ) {
392
- wordpress_file_upload_install();
393
- }
394
- }
395
-
396
- /**
397
- * Process Dashboard Requests.
398
- *
399
- * This function processes Dashboard requests and shows main Dashboard pages of
400
- * the plugin in Settings.
401
- *
402
- * @since 2.1.2
403
- */
404
- function wordpress_file_upload_manage_dashboard() {
405
- $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
406
- $_POST = stripslashes_deep($_POST);
407
- $_GET = stripslashes_deep($_GET);
408
- $action = (!empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''));
409
- $dir = (!empty($_POST['dir']) ? $_POST['dir'] : (!empty($_GET['dir']) ? $_GET['dir'] : ''));
410
- $file = (!empty($_POST['file']) ? $_POST['file'] : (!empty($_GET['file']) ? $_GET['file'] : ''));
411
- $referer = (!empty($_POST['referer']) ? $_POST['referer'] : (!empty($_GET['referer']) ? $_GET['referer'] : ''));
412
- $data_enc = (!empty($_POST['data']) ? $_POST['data'] : (!empty($_GET['data']) ? $_GET['data'] : ''));
413
- $postid = (!empty($_POST['postid']) ? $_POST['postid'] : (!empty($_GET['postid']) ? $_GET['postid'] : ''));
414
- $nonce = (!empty($_POST['nonce']) ? $_POST['nonce'] : (!empty($_GET['nonce']) ? $_GET['nonce'] : ''));
415
- $tag = (!empty($_POST['tag']) ? $_POST['tag'] : (!empty($_GET['tag']) ? $_GET['tag'] : ''));
416
- $username = (!empty($_POST['username']) ? $_POST['username'] : (!empty($_GET['username']) ? $_GET['username'] : ''));
417
- $invoker = (!empty($_POST['invoker']) ? $_POST['invoker'] : (!empty($_GET['invoker']) ? $_GET['invoker'] : ''));
418
- $echo_str = "";
419
-
420
- if ( $action == 'edit_settings' ) {
421
- wfu_update_settings();
422
- $echo_str = wfu_manage_settings();
423
- }
424
- elseif ( $action == 'shortcode_composer' ) {
425
- $echo_str = wfu_shortcode_composer();
426
- }
427
- elseif ( $action == 'file_browser' ) {
428
- $echo_str = wfu_browse_files($dir);
429
- }
430
- elseif ( $action == 'view_log' ) {
431
- $page = $tag;
432
- if ( $page == '' ) $page = 1;
433
- $page = (int)wfu_sanitize_int($page);
434
- $located_rec = $invoker;
435
- if ( $located_rec == '' ) $located_rec = -1;
436
- $located_rec = (int)wfu_sanitize_int($located_rec);
437
- $echo_str = wfu_view_log($page, false, $located_rec);
438
- }
439
- elseif ( $action == 'rename_file' && $file != "" ) {
440
- $echo_str = wfu_rename_file_prompt($file, 'file', false);
441
- }
442
- elseif ( $action == 'rename_dir' && $file != "" ) {
443
- $echo_str = wfu_rename_file_prompt($file, 'dir', false);
444
- }
445
- elseif ( $action == 'move_file' && $file != "" ) {
446
- if ( substr($file, 0, 5) == "list:" ) $file = explode(",", substr($file, 5));
447
- $echo_str = wfu_move_file_prompt($file, false);
448
- }
449
- elseif ( $action == 'renamefile' && $file != "" ) {
450
- if ( wfu_rename_file($file, 'file') ) $echo_str = wfu_browse_files($dir);
451
- else $echo_str = wfu_rename_file_prompt($file, 'file', true);
452
- }
453
- elseif ( $action == 'renamedir' && $file != "" ) {
454
- if ( wfu_rename_file($file, 'dir') ) $echo_str = wfu_browse_files($dir);
455
- else $echo_str = wfu_rename_file_prompt($file, 'dir', true);
456
- }
457
- elseif ( $action == 'movefile' && $file != "" ) {
458
- if ( substr($file, 0, 5) == "list:" ) $file = explode(",", substr($file, 5));
459
- if ( wfu_move_file($file) ) $echo_str = wfu_browse_files($dir);
460
- else $echo_str = wfu_move_file_prompt($file, true);
461
- }
462
- elseif ( $action == 'delete_file' && $file != "" && $referer != "" ) {
463
- if ( substr($file, 0, 5) == "list:" ) $file = explode(",", substr($file, 5));
464
- $echo_str = wfu_delete_file_prompt($file, 'file', $referer);
465
- }
466
- elseif ( $action == 'delete_dir' && $file != "" && $referer != "" ) {
467
- $echo_str = wfu_delete_file_prompt($file, 'dir', $referer);
468
- }
469
- elseif ( $action == 'deletefile' && $file != "" ) {
470
- if ( substr($file, 0, 5) == "list:" ) $file = explode(",", substr($file, 5));
471
- wfu_delete_file($file, 'file');
472
- $referer_url = wfu_flatten_path(wfu_get_filepath_from_safe(wfu_sanitize_code($referer)));
473
- if ( $referer_url === false ) $referer_url = "";
474
- $match = array();
475
- preg_match("/\&dir=(.*)/", $referer_url, $match);
476
- $dir = ( isset($match[1]) ? $match[1] : "" );
477
- $echo_str = wfu_browse_files($dir);
478
- }
479
- elseif ( $action == 'deletedir' && $file != "" ) {
480
- wfu_delete_file($file, 'dir');
481
- $referer_url = wfu_flatten_path(wfu_get_filepath_from_safe(wfu_sanitize_code($referer)));
482
- if ( $referer_url === false ) $referer_url = "";
483
- $match = array();
484
- preg_match("/\&dir=(.*)/", $referer_url, $match);
485
- $dir = ( isset($match[1]) ? $match[1] : "" );
486
- $echo_str = wfu_browse_files($dir);
487
- }
488
- elseif ( $action == 'create_dir' ) {
489
- $echo_str = wfu_create_dir_prompt($dir, false);
490
- }
491
- elseif ( $action == 'createdir' ) {
492
- if ( wfu_create_dir($dir) ) $echo_str = wfu_browse_files($dir);
493
- else $echo_str = wfu_create_dir_prompt($dir, true);
494
- }
495
- elseif ( $action == 'include_file' && $file != "" && $referer != "" ) {
496
- if ( substr($file, 0, 5) == "list:" ) $file = explode(",", substr($file, 5));
497
- $echo_str = wfu_include_file_prompt($file, $referer);
498
- }
499
- elseif ( $action == 'includefile' && $file != "" ) {
500
- if ( substr($file, 0, 5) == "list:" ) $file = explode(",", substr($file, 5));
501
- wfu_include_file($file);
502
- $referer_url = wfu_flatten_path(wfu_get_filepath_from_safe(wfu_sanitize_code($referer)));
503
- if ( $referer_url === false ) $referer_url = "";
504
- $match = array();
505
- preg_match("/\&dir=(.*)/", $referer_url, $match);
506
- $dir = ( isset($match[1]) ? $match[1] : "" );
507
- $echo_str = wfu_browse_files($dir);
508
- }
509
- elseif ( $action == 'file_details' && $file != "" ) {
510
- $echo_str = wfu_file_details($file, false, $invoker);
511
- }
512
- elseif ( $action == 'edit_filedetails' && $file != "" ) {
513
- wfu_edit_filedetails($file);
514
- $echo_str = wfu_file_details($file, false, $invoker);
515
- }
516
- elseif ( $action == 'personal_data' && $plugin_options["personaldata"] == "1" ) {
517
- $echo_str = wfu_manage_personaldata_policies();
518
- }
519
- elseif ( $action == 'erase_userdata_ask' && $plugin_options["personaldata"] == "1" && $username != "" ) {
520
- $echo_str = wfu_erase_userdata_ask_prompt($username);
521
- }
522
- elseif ( $action == 'erase_userdata' && $plugin_options["personaldata"] == "1" && $username != "" ) {
523
- $ret = wfu_erase_userdata($username);
524
- if ( $ret <= -1 ) $echo_str = wfu_manage_personaldata_policies();
525
- else $echo_str = wfu_manage_personaldata_policies('Database cleaned. '.$ret.' items where affected.');
526
- }
527
- elseif ( $action == 'maintenance_actions' ) {
528
- $echo_str = wfu_maintenance_actions();
529
- }
530
- elseif ( $action == 'sync_db' && $nonce != "" ) {
531
- $affected_items = wfu_sync_database_controller($nonce);
532
- if ( $affected_items > -1 ) $echo_str = wfu_maintenance_actions('Database updated. '.$affected_items.' items where affected.');
533
- else $echo_str = wfu_maintenance_actions();
534
- }
535
- elseif ( $action == 'clean_log_ask' && $nonce != "" && $data_enc != "" ) {
536
- $echo_str = wfu_clean_log_prompt($nonce, $data_enc);
537
- }
538
- elseif ( $action == 'clean_log' ) {
539
- $ret = wfu_clean_log();
540
- if ( $ret["recs_count"] <= -1 && $ret["files_count"] ) $echo_str = wfu_maintenance_actions();
541
- else $echo_str = wfu_maintenance_actions('Database cleaned. '.$ret["recs_count"].' records and '.$ret["files_count"].' files where deleted.');
542
- }
543
- elseif ( $action == 'purge_data_ask' && $nonce != "" ) {
544
- $echo_str = wfu_purge_data_prompt($nonce);
545
- }
546
- elseif ( $action == 'purge_data' ) {
547
- $ret = wfu_purge_data();
548
- if ( !$ret ) $echo_str = wfu_maintenance_actions();
549
- else $echo_str = '<script type="text/javascript">window.location.replace("'.admin_url('plugins.php').'");</script>';
550
- }
551
- elseif ( $action == 'reset_all_transfers' && $nonce != "" ) {
552
- if ( wfu_reset_all_transfers_controller($nonce) === true )
553
- $echo_str = wfu_maintenance_actions('All file transfers were successfully reset.');
554
- else $echo_str = wfu_maintenance_actions();
555
- }
556
- elseif ( $action == 'clear_all_transfers' && $nonce != "" ) {
557
- if ( wfu_clear_all_transfers_controller($nonce) === true )
558
- $echo_str = wfu_maintenance_actions('All file transfers were successfully cleared.');
559
- else $echo_str = wfu_maintenance_actions();
560
- }
561
- elseif ( $action == 'plugin_settings' ) {
562
- $echo_str = wfu_manage_settings();
563
- }
564
- elseif ( $action == 'add_shortcode' && $postid != "" && $nonce != "" && $tag != "" ) {
565
- if ( WFU_USVAR('wfu_add_shortcode_ticket_for_'.$tag) != $nonce ) $echo_str = wfu_manage_mainmenu();
566
- elseif ( wfu_add_shortcode($postid, $tag) ) $echo_str = wfu_manage_mainmenu();
567
- else $echo_str = wfu_manage_mainmenu(WFU_DASHBOARD_ADD_SHORTCODE_REJECTED);
568
- WFU_USVAR_store('wfu_add_shortcode_ticket', 'noticket');
569
- }
570
- elseif ( $action == 'edit_shortcode' && $data_enc != "" && $tag != "" ) {
571
- $data = wfu_decode_array_from_string(wfu_get_shortcode_data_from_safe($data_enc));
572
- if ( $data['post_id'] == "" || $referer == 'guteditor' || wfu_check_edit_shortcode($data) ) wfu_shortcode_composer($data, $tag, $referer);
573
- else $echo_str = wfu_manage_mainmenu(WFU_DASHBOARD_EDIT_SHORTCODE_REJECTED);
574
- }
575
- elseif ( $action == 'delete_shortcode' && $data_enc != "" ) {
576
- $data = wfu_decode_array_from_string(wfu_get_shortcode_data_from_safe($data_enc));
577
- if ( wfu_check_edit_shortcode($data) ) $echo_str = wfu_delete_shortcode_prompt($data_enc);
578
- else $echo_str = wfu_manage_mainmenu(WFU_DASHBOARD_DELETE_SHORTCODE_REJECTED);
579
- }
580
- elseif ( $action == 'deleteshortcode' && $data_enc != "" ) {
581
- $data = wfu_decode_array_from_string(wfu_get_shortcode_data_from_safe($data_enc));
582
- if ( wfu_check_edit_shortcode($data) ) {
583
- if ( wfu_delete_shortcode($data) ) wfu_clear_shortcode_data_from_safe($data_enc);
584
- $echo_str = wfu_manage_mainmenu();
585
- }
586
- else $echo_str = wfu_manage_mainmenu(WFU_DASHBOARD_DELETE_SHORTCODE_REJECTED);
587
- }
588
- elseif ( $action == 'add_policy' ) {
589
- $echo_str = wfu_edit_pd_policy();
590
- }
591
- else {
592
- $echo_str = wfu_manage_mainmenu();
593
- }
594
-
595
- echo $echo_str;
596
- }
597
-
598
- /**
599
- * Process Dashboard Requests for Non-Admin Users.
600
- *
601
- * This function processes Dashboard requests and shows the shortcode composer
602
- * to users that are not admins but who can edit posts or pages. It also lets
603
- * extensions implement their own actions when receiving Dashboard requests by
604
- * non-admin users.
605
- *
606
- * @since 4.11.0
607
- */
608
- function wordpress_file_upload_manage_dashboard_editor() {
609
- $_POST = stripslashes_deep($_POST);
610
- $_GET = stripslashes_deep($_GET);
611
- $action = (!empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''));
612
- $referer = (!empty($_POST['referer']) ? $_POST['referer'] : (!empty($_GET['referer']) ? $_GET['referer'] : ''));
613
- $data_enc = (!empty($_POST['data']) ? $_POST['data'] : (!empty($_GET['data']) ? $_GET['data'] : ''));
614
- $tag = (!empty($_POST['tag']) ? $_POST['tag'] : (!empty($_GET['tag']) ? $_GET['tag'] : ''));
615
- $echo_str = "";
616
-
617
- if ( $action == 'edit_shortcode' && $data_enc != "" && $tag != "" ) {
618
- $data = wfu_decode_array_from_string(wfu_get_shortcode_data_from_safe($data_enc));
619
- if ( $data['post_id'] == "" || $referer == 'guteditor' || wfu_check_edit_shortcode($data) ) wfu_shortcode_composer($data, $tag, $referer);
620
- else $echo_str = wfu_manage_mainmenu(WFU_DASHBOARD_EDIT_SHORTCODE_REJECTED);
621
- }
622
- else {
623
- $echo_str = wfu_manage_mainmenu_editor();
624
- }
625
-
626
- echo $echo_str;
627
- }
628
-
629
- /**
630
- * Display the Main Dashboard Page.
631
- *
632
- * This function displays the Main Dashboard page of the plugin.
633
- *
634
- * @since 2.5.2
635
- *
636
- * @param string $message Optional. A message to display on top when showing
637
- * Main page of the plugin in Dashboard.
638
- *
639
- * @return string The HTML output of the plugin's Main Dashboard page.
640
- */
641
- function wfu_manage_mainmenu($message = '') {
642
- if ( !current_user_can( 'manage_options' ) ) return;
643
-
644
- //get php version
645
- $php_version = preg_replace("/-.*/", "", phpversion());
646
-
647
- $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
648
-
649
- $echo_str = '<div class="wrap wfumain">';
650
- $echo_str .= "\n\t".'<h2>Wordpress File Upload Control Panel</h2>';
651
- if ( $message != '' ) {
652
- $echo_str .= "\n\t".'<div class="updated">';
653
- $echo_str .= "\n\t\t".'<p>'.$message.'</p>';
654
- $echo_str .= "\n\t".'</div>';
655
- }
656
- $echo_str .= "\n\t".'<div style="margin-top:20px;">';
657
- $echo_str .= wfu_generate_dashboard_menu("\n\t\t", "Main");
658
- $echo_str .= "\n\t\t".'<h3 style="margin-bottom: 10px;">Status';
659
- if ( $plugin_options["altserver"] == "1" && substr(trim(WFU_VAR("WFU_ALT_IPTANUS_SERVER")), 0, 5) == "http:" ) {
660
- $echo_str .= '<div style="display: inline-block; margin-left:20px;" title="'.WFU_WARNING_ALT_IPTANUS_SERVER_ACTIVATED.'"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 200 800" version="1.1" style="background:darkorange; border-radius:13px; padding:2px; vertical-align:middle; border: 1px solid silver;"><path d="M 110,567 L 90,567 L 42,132 C 40,114 40,100 40,90 C 40,70 45,49 56,35 C 70,22 83,15 100,15 C 117,15 130,22 144,35 C 155,49 160,70 160,90 C 160,100 160,114 158,132 z M 100,640 A 60,60 0 1,1 100,760 A 60,60 0 1,1 100,640 z"/></svg></div>';
661
- }
662
- $echo_str .= '</h3>';
663
- $echo_str .= "\n\t\t".'<table class="form-table">';
664
- $echo_str .= "\n\t\t\t".'<tbody>';
665
- //plugin edition
666
- $echo_str .= "\n\t\t\t\t".'<tr>';
667
- $echo_str .= "\n\t\t\t\t\t".'<th scope="row">';
668
- $echo_str .= "\n\t\t\t\t\t\t".'<label style="cursor:default;">Edition</label>';
669
- $echo_str .= "\n\t\t\t\t\t".'</th>';
670
- $echo_str .= "\n\t\t\t\t\t".'<td style="width:100px; vertical-align:top;">';
671
- $echo_str .= "\n\t\t\t\t\t\t".'<label style="font-weight:bold; cursor:default;">Free</label>';
672
- $echo_str .= "\n\t\t\t\t\t".'</td>';
673
- $echo_str .= "\n\t\t\t\t\t".'<td>';
674
- $echo_str .= "\n\t\t\t\t\t\t".'<div style="display:inline-block; background-color:bisque; padding:0 0 0 4px; border-left:3px solid lightcoral;">';
675
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label style="cursor:default;">Consider </label><a href="'.WFU_PRO_VERSION_URL.'">Upgrading</a><label style="cursor:default;"> to the Professional Version. </label>';
676
- $echo_str .= "\n\t\t\t\t\t\t\t".'<button onclick="if (this.innerText == \'See why >>\') {this.innerText = \'<< Close\'; document.getElementById(\'wfu_version_comparison\').style.display = \'inline-block\';} else {this.innerText = \'See why >>\'; document.getElementById(\'wfu_version_comparison\').style.display = \'none\';}">See why >></button>';
677
- $echo_str .= "\n\t\t\t\t\t\t".'</div>';
678
- $echo_str .= "\n\t\t\t\t\t\t".'<br /><div id="wfu_version_comparison" style="display:none; background-color:lightyellow; border:1px solid yellow; margin:10px 0; padding:10px;">';
679
- $echo_str .= "\n\t\t\t\t\t\t\t".'<img src="'.WFU_IMAGE_VERSION_COMPARISON.'" style="display:block; margin-bottom:6px;" />';
680
- $echo_str .= "\n\t\t\t\t\t\t\t".'<a class="button-primary" href="'.WFU_PRO_VERSION_URL.'">Go for the PRO version</a>';
681
- $echo_str .= "\n\t\t\t\t\t\t".'</div>';
682
- $echo_str .= "\n\t\t\t\t\t".'</td>';
683
- $echo_str .= "\n\t\t\t\t".'</tr>';
684
- //plugin version
685
- $echo_str .= "\n\t\t\t\t".'<tr>';
686
- $echo_str .= "\n\t\t\t\t\t".'<th scope="row">';
687
- $echo_str .= "\n\t\t\t\t\t\t".'<label style="cursor:default;">Version</label>';
688
- $echo_str .= "\n\t\t\t\t\t".'</th>';
689
- $echo_str .= "\n\t\t\t\t\t".'<td style="width:100px;">';
690
- $cur_version = wfu_get_plugin_version();
691
- $echo_str .= "\n\t\t\t\t\t\t".'<label style="font-weight:bold; cursor:default;">'.$cur_version.'</label>';
692
- $echo_str .= "\n\t\t\t\t\t".'</td>';
693
- $echo_str .= "\n\t\t\t\t\t".'<td>';
694
- $lat_version = wfu_get_latest_version();
695
- $ret = wfu_compare_versions($cur_version, $lat_version);
696
- if ( $lat_version == "" && WFU_VAR("WFU_DISABLE_VERSION_CHECK") != "true" ) {
697
- $echo_str .= "\n\t\t\t\t\t\t".'<div style="display:inline-block; background-color:transparent; padding:0 0 0 4px; color:red;">';
698
- $echo_str .= "\n\t\t\t\t\t\t\t".'<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 200 800" version="1.1" style="background:transparent; border-radius:13px; padding:2px; vertical-align:middle; border: 2px solid red; fill:red;"><path d="M 110,567 L 90,567 L 42,132 C 40,114 40,100 40,90 C 40,70 45,49 56,35 C 70,22 83,15 100,15 C 117,15 130,22 144,35 C 155,49 160,70 160,90 C 160,100 160,114 158,132 z M 100,640 A 60,60 0 1,1 100,760 A 60,60 0 1,1 100,640 z"/></svg>';
699
- $warning_text = preg_replace("/:(\w+):/", '<a target="_blank" href="'.WFU_IPTANUS_SERVER_UNREACHABLE_ARTICLE.'" title="Iptanus Services Server Unreachable Error of WFU Plugin">$1</a>', WFU_WARNING_IPTANUS_SERVER_UNREACHABLE);
700
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label style="cursor:default;">'.$warning_text.'</label>';
701
- $echo_str .= "\n\t\t\t\t\t\t".'</div>';
702
- }
703
- elseif ( $ret['status'] && $ret['result'] == 'lower' ) {
704
- $echo_str .= "\n\t\t\t\t\t\t".'<div style="display:inline-block; background-color:bisque; padding:0 0 0 4px; border-left:3px solid lightcoral;">';
705
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label style="cursor:default;">Version <strong>'.$lat_version.'</strong> of the plugin is available. Go to Plugins page of your Dashboard to update to the latest version.</label>';
706
- if ( $ret['custom'] ) $echo_str .= '<label style="cursor:default; color: purple;"> <em>Please note that you are using a custom version of the plugin. If you upgrade to the newest version, custom changes will be lost.</em></label>';
707
- $echo_str .= "\n\t\t\t\t\t\t".'</div>';
708
- }
709
- elseif ( $ret['status'] && $ret['result'] == 'equal' ) {
710
- $echo_str .= "\n\t\t\t\t\t\t".'<div style="display:inline-block; background-color:rgb(220,255,220); padding:0 0 0 4px; border-left:3px solid limegreen;">';
711
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label style="cursor:default;">You have the latest version.</label>';
712
- if ( $ret['custom'] ) $echo_str .= '<label style="cursor:default; color: purple;"> <em>(Please note that your version is custom)</em></label>';
713
- $echo_str .= "\n\t\t\t\t\t\t".'</div>';
714
- }
715
- $echo_str .= "\n\t\t\t\t\t".'</td>';
716
- $echo_str .= "\n\t\t\t\t".'</tr>';
717
- //server environment
718
- $php_env = wfu_get_server_environment();
719
- $echo_str .= "\n\t\t\t\t".'<tr>';
720
- $echo_str .= "\n\t\t\t\t\t".'<th scope="row">';
721
- $echo_str .= "\n\t\t\t\t\t\t".'<label style="cursor:default;">Server Environment</label>';
722
- $echo_str .= "\n\t\t\t\t\t".'</th>';
723
- $echo_str .= "\n\t\t\t\t\t".'<td style="width:100px;">';
724
- if ( $php_env == '64bit' ) $echo_str .= "\n\t\t\t\t\t\t".'<label style="font-weight:bold; cursor:default;">64bit</label></td><td><label style="font-weight:normal; font-style:italic; cursor:default;">(Your server supports files up to 1 Exabyte, practically unlimited)</label>';
725
- if ( $php_env == '32bit' ) $echo_str .= "\n\t\t\t\t\t\t".'<label style="font-weight:bold; cursor:default;">32bit</label></td><td><label style="font-weight:normal; font-style:italic; cursor:default;">(Your server does not support files larger than 2GB)</label>';
726
- if ( $php_env == '' ) $echo_str .= "\n\t\t\t\t\t\t".'<label style="font-weight:bold; cursor:default;">Unknown</label></td><td><label style="font-weight:normal; font-style:italic; cursor:default;">(The maximum file size supported by the server cannot be determined)</label>';
727
- $echo_str .= "\n\t\t\t\t\t".'</td>';
728
- $echo_str .= "\n\t\t\t\t".'</tr>';
729
- $echo_str .= "\n\t\t\t\t".'<tr>';
730
- $echo_str .= "\n\t\t\t\t\t".'<th scope="row">';
731
- $echo_str .= "\n\t\t\t\t\t\t".'<label style="cursor:default;">PHP Version</label>';
732
- $echo_str .= "\n\t\t\t\t\t".'</th>';
733
- $echo_str .= "\n\t\t\t\t\t".'<td style="width:100px;">';
734
- $cur_version = wfu_get_plugin_version();
735
- $echo_str .= "\n\t\t\t\t\t\t".'<label style="font-weight:bold; cursor:default;">'.$php_version.'</label>';
736
- $echo_str .= "\n\t\t\t\t\t".'</td>';
737
- $echo_str .= "\n\t\t\t\t\t".'<td>';
738
- $echo_str .= "\n\t\t\t\t\t".'</td>';
739
- $echo_str .= "\n\t\t\t\t".'</tr>';
740
- $echo_str .= "\n\t\t\t\t".'<tr>';
741
- $echo_str .= "\n\t\t\t\t\t".'<th scope="row">';
742
- $echo_str .= "\n\t\t\t\t\t\t".'<label style="cursor:default;">Release Notes</label>';
743
- $echo_str .= "\n\t\t\t\t\t".'</th>';
744
- $echo_str .= "\n\t\t\t\t\t".'<td colspan="2" style="width:100px;">';
745
- $rel_path = ABSWPFILEUPLOAD_DIR.'release_notes.txt';
746
- $rel_notes = '';
747
- if ( file_exists($rel_path) ) $rel_notes = file_get_contents($rel_path);
748
- $echo_str .= "\n\t\t\t\t\t\t".'<div style="text-align:justify;">'.$rel_notes.'</div>';
749
- $echo_str .= "\n\t\t\t\t\t".'</td>';
750
- $echo_str .= "\n\t\t\t\t".'</tr>';
751
- $echo_str .= "\n\t\t\t".'</tbody>';
752
- $echo_str .= "\n\t\t".'</table>';
753
-
754
- $echo_str .= wfu_manage_instances();
755
-
756
- $echo_str .= "\n\t".'</div>';
757
- $echo_str .= "\n".'</div>';
758
-
759
- return $echo_str;
760
- }
761
-
762
- /**
763
- * Default Dashboard Page for Non-Admin Users.
764
- *
765
- * This function displays the plugin's default Dashboard page for non-admin
766
- * users who can edit pages or posts.
767
- *
768
- * @since 4.11.0
769
- *
770
- * @param string $message Optional. A message to display on top when showing
771
- * the default Dashboard page of the plugin for non-admin users.
772
- *
773
- * @return string The HTML output of the plugin's default Dashboard page.
774
- */
775
- function wfu_manage_mainmenu_editor($message = '') {
776
- if ( !current_user_can( 'edit_pages' ) && !current_user_can( 'edit_posts' ) ) return;
777
-
778
- $echo_str = '<div class="wrap wfumain">';
779
- $echo_str .= "\n\t".'<h2>Wordpress File Upload Control Panel</h2>';
780
- if ( $message != '' ) {
781
- $echo_str .= "\n\t".'<div class="updated">';
782
- $echo_str .= "\n\t\t".'<p>'.$message.'</p>';
783
- $echo_str .= "\n\t".'</div>';
784
- }
785
- $echo_str .= "\n\t".'<div style="margin-top:20px;">';
786
- $echo_str .= "\n\t\t".'<h3 style="margin-bottom: 10px;">This menu item exists to show the plugin\'s shortcode composer when editing pages or posts.</h3>';
787
- $echo_str .= "\n\t".'</div>';
788
- $echo_str .= "\n".'</div>';
789
-
790
- return $echo_str;
791
- }
792
-
793
- /**
794
- * Main Dashboard Page Tabs.
795
- *
796
- * This function generates the tabs of the plugin's main area in Dashboard.
797
- *
798
- * @since 3.6.0
799
- *
800
- * @redeclarable
801
- *
802
- * @param string $dlp Identation string before the beginning of each HTML line.
803
- * @param string $active The name of the tab that it is active.
804
- *
805
- * @return string The HTML output of the tabs.
806
- */
807
- function wfu_generate_dashboard_menu($dlp, $active) {
808
- $a = func_get_args(); $a = WFU_FUNCTION_HOOK(__FUNCTION__, $a, $out); if (isset($out['vars'])) foreach($out['vars'] as $p => $v) $$p = $v; switch($a) { case 'R': return $out['output']; break; case 'D': die($out['output']); }
809
- $siteurl = site_url();
810
- $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
811
-
812
- $echo_str = $dlp.'<h2 class="nav-tab-wrapper" style="margin-bottom:40px;">';
813
- $echo_str .= $dlp."\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="nav-tab'.( $active == "Main" ? ' nav-tab-active' : '' ).'" title="Main">Main</a>';
814
- $echo_str .= $dlp."\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=plugin_settings" class="nav-tab'.( $active == "Settings" ? ' nav-tab-active' : '' ).'" title="Settings">Settings</a>';
815
- $echo_str .= $dlp."\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=file_browser" class="nav-tab'.( $active == "File Browser" ? ' nav-tab-active' : '' ).'" title="File browser">File Browser</a>';
816
- $echo_str .= $dlp."\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=view_log" class="nav-tab'.( $active == "View Log" ? ' nav-tab-active' : '' ).'" title="View log">View Log</a>';
817
- if ( $plugin_options["personaldata"] == "1" )
818
- $echo_str .= $dlp."\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=personal_data" class="nav-tab'.( $active == "Personal Data" ? ' nav-tab-active' : '' ).'" title="Personal Data">Personal Data</a>';
819
- $echo_str .= $dlp."\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=maintenance_actions" class="nav-tab'.( $active == "Maintenance Actions" ? ' nav-tab-active' : '' ).'" title="Maintenance Actions">Maintenance Actions</a>';
820
- $echo_str .= $dlp.'</h2>';
821
-
822
- return $echo_str;
823
- }
824
-
825
- /**
826
- * Generate List of Posts in Tree Order.
827
- *
828
- * This function converts a flat array of posts into a tree structure, where an
829
- * individual item of the returned array may contain a nested array of children.
830
- * Items of the same parent and level are sorted by post status (publish,
831
- * private, draft) and then by title.
832
- *
833
- * @since 2.7.6
834
- *
835
- * @param array $posts The initial flat array of posts.
836
- *
837
- * @return array The returned list of posts in tree order.
838
- */
839
- function wfu_construct_post_list($posts) {
840
- $ids = array();
841
- $list = array();
842
- $id_keys = array();
843
- //construct item indices
844
- foreach ( $posts as $key => $post ) {
845
- if ( !array_key_exists($post->post_type, $ids) ) {
846
- $ids[$post->post_type] = array();
847
- $list[$post->post_type] = array();
848
- }
849
- array_push($ids[$post->post_type], $post->ID);
850
- $id_keys[$post->ID] = $key;
851
- }
852
- //create post list in tree order; items are sorted by post status (publish,
853
- //private, draft) and then by title
854
- $i = 0;
855
- while ( $i < count($posts) ) {
856
- $post = $posts[$i];
857
- //find topmost element in family tree
858
- $tree = array( $post->ID );
859
- $topmost = $post;
860
- $par_id = $topmost->post_parent;
861
- while ( in_array($par_id, $ids[$post->post_type]) ) {
862
- $topmost = $posts[$id_keys[$par_id]];
863
- array_splice($tree, 0, 0, $par_id);
864
- $par_id = $topmost->post_parent;
865
- }
866
- //find which needs to be processed
867
- $level = 0;
868
- $host = &$list[$post->post_type];
869
- foreach ( $tree as $process_id ) {
870
- $found_key = -1;
871
- foreach ( $host as $key => $item )
872
- if ( $item['id'] == $process_id ) {
873
- $found_key = $key;
874
- break;
875
- }
876
- if ( $found_key == -1 ) break;
877
- $level++;
878
- $host = &$host[$found_key]['children'];
879
- }
880
- if ( $found_key == -1 ) {
881
- $processed = $posts[$id_keys[$process_id]];
882
- //add the processed item in the right position in children's list
883
- $pos = 0;
884
- $status = ( $processed->post_status == 'publish' ? 0 : ( $processed->post_status == 'private' ? 1 : 2 ) );
885
- foreach ($host as $item) {
886
- if ( $status < $item['status'] ) break;
887
- if ( $status == $item['status'] && strcmp($processed->post_title, $item['title']) < 0 ) break;
888
- $pos++;
889
- }
890
- $new_item = array(
891
- 'id' => $process_id,
892
- 'title' => $processed->post_title,
893
- 'status' => $status,
894
- 'level' => $level,
895
- 'children' => array()
896
- );
897
- array_splice($host, $pos, 0, array($new_item));
898
- }
899
- //advance index if we have finished processing all the tree
900
- if ( $process_id == $post->ID ) $i++;
901
- }
902
- return $list;
903
- }
904
-
905
- /**
906
- * Flatten Tree List of Posts.
907
- *
908
- * This function converts a list that contains posts in tree order into a flat
909
- * list (array) of posts.
910
- *
911
- * @since 2.7.6
912
- *
913
- * @param array $list The initial tree list of posts.
914
- *
915
- * @return array The returned flat list of posts.
916
- */
917
- function wfu_flatten_post_list($list) {
918
- $flat = array();
919
- if ( !is_array($list) ) return $flat;
920
- foreach( $list as $item ) {
921
- $flat_item = array(
922
- 'id' => $item['id'],
923
- 'title' => $item['title'],
924
- 'status' => $item['status'],
925
- 'level' => $item['level']
926
- );
927
- array_push($flat, $flat_item);
928
- $flat = array_merge($flat, wfu_flatten_post_list($item['children']));
929
- }
930
- return $flat;
931
- }
932
-
933
- /**
934
- * Generate List of Instances of All Plugin' Shortcodes.
935
- *
936
- * This function generates a tabular list of all instances of all plugin's
937
- * shortcodes.
938
- *
939
- * @since 2.5.2
940
- *
941
- * @return string The HTML code of the list of instances of all the shortcodes.
942
- */
943
- function wfu_manage_instances() {
944
- $echo_str = wfu_manage_instances_of_shortcode('wordpress_file_upload', 'Uploader Instances', 'uploader', 1);
945
-
946
- return $echo_str;
947
- }
948
-
949
- /**
950
- * Generate List of Instances of A Plugin' Shortcode.
951
- *
952
- * This function generates a tabular list of all instances of a plugin's
953
- * shortcode.
954
- *
955
- * @since 3.1.0
956
- *
957
- * @param string $tag The shortcode tag.
958
- * @param string $title The title of the list
959
- * @param string $slug A slug of the shortcode.
960
- * @param integer $inc The increment number of this list of instances.
961
- *
962
- * @return string The HTML code of the list of instances of the shortcode.
963
- */
964
- function wfu_manage_instances_of_shortcode($tag, $title, $slug, $inc) {
965
- global $wp_registered_widgets, $wp_registered_sidebars;
966
-
967
- $siteurl = site_url();
968
- $args = array( 'post_type' => array( "post", "page" ), 'post_status' => "publish,private,draft", 'posts_per_page' => -1 );
969
- /**
970
- * Filter Arguments for Getting List of Posts.
971
- *
972
- * This filter allows to customize the arguments passed to get_posts()
973
- * function to get a list of posts. By default the plugin will get a list of
974
- * all posts and pages. If the website contains too many posts this
975
- * operation may take time and delay loading of the page. So this filter can
976
- * be used to optimize this operation.
977
- *
978
- * @since 4.0.0
979
- *
980
- * @param array $args Arguments to retrieve posts.
981
- * @param string $operation A parameter designating in which operation this
982
- * filter is used.
983
- */
984
- $args = apply_filters("_wfu_get_posts", $args, "manage_instances");
985
- $posts = get_posts($args);
986
- $wfu_shortcodes = array();
987
- //get shortcode instances from page/posts
988
- foreach ( $posts as $post ) {
989
- $ret = wfu_get_content_shortcodes($post, $tag);
990
- if ( $ret !== false ) $wfu_shortcodes = array_merge($wfu_shortcodes, $ret);
991
- }
992
- //get shortcode instances from sidebars
993
- $data = array();
994
- $widget_base = $tag.'_widget';
995
- if ( is_array($wp_registered_widgets) ) {
996
- foreach ( $wp_registered_widgets as $id => $widget ) {
997
- if ( substr($id, 0, strlen($widget_base)) == $widget_base ) {
998
- $widget_obj = ( isset($widget['callback']) ? ( isset($widget['callback'][0]) ? ( $widget['callback'][0] instanceof WP_Widget ? $widget['callback'][0] : false ) : false ) : false );
999
- $widget_sidebar = is_active_widget(false, $id, $widget_base);
1000
- if ( $widget_obj !== false && $widget_sidebar !== false ) {
1001
- if ( isset($wp_registered_sidebars[$widget_sidebar]) && isset($wp_registered_sidebars[$widget_sidebar]['name']) ) $widget_sidebar = $wp_registered_sidebars[$widget_sidebar]['name'];
1002
- $data['post_id'] = "";
1003
- $data['post_hash'] = "";
1004
- $data['shortcode'] = $widget_obj->shortcode();
1005
- $data['position'] = 0;
1006
- $data['widgetid'] = $id;
1007
- $data['sidebar'] = $widget_sidebar;
1008
- array_push($wfu_shortcodes, $data);
1009
- }
1010
- }
1011
- }
1012
- }
1013
-
1014
- $list = wfu_construct_post_list($posts);
1015
- $pagelist = wfu_flatten_post_list($list["page"]);
1016
- $postlist = wfu_flatten_post_list($list["post"]);
1017
-
1018
- $echo_str = "\n\t\t".'<h3 style="margin-bottom: 10px; margin-top: 40px;">'.$title.'</h3>';
1019
- $onchange_js = 'document.getElementById(\'wfu_add_plugin_ok_'.$inc.'\').disabled = !((document.getElementById(\'wfu_page_type_'.$inc.'\').value == \'page\' && document.getElementById(\'wfu_page_list_'.$inc.'\').value != \'\') || (document.getElementById(\'wfu_page_type_'.$inc.'\').value == \'post\' && document.getElementById(\'wfu_post_list_'.$inc.'\').value != \'\'));';
1020
- $no_shortcodes = ( count($wfu_shortcodes) == 0 );
1021
- $echo_str .= "\n\t\t".'<div id="wfu_add_plugin_button_'.$inc.'" style="'. ( !$no_shortcodes ? '' : 'color:blue; font-weight:bold; font-size:larger;' ).'margin-bottom: 20px; margin-top: 10px;">';
1022
- $addbutton_pre = ( !$no_shortcodes ? '' : '<label>Press </label>');
1023
- $addbutton_post = ( !$no_shortcodes ? '' : '<label> to get started and add the '.$slug.' in a page</label>');
1024
- $echo_str .= "\n\t\t\t".$addbutton_pre.'<button onclick="document.getElementById(\'wfu_add_plugin_button_'.$inc.'\').style.display = \'none\'; document.getElementById(\'wfu_add_plugin_'.$inc.'\').style.display = \'inline-block\'; '.$onchange_js.'">'.( !$no_shortcodes ? 'Add Plugin Instance' : 'here' ).'</button>'.$addbutton_post;
1025
- $echo_str .= "\n\t\t".'</div>';
1026
- $echo_str .= "\n\t\t".'<div id="wfu_add_plugin_'.$inc.'" style="margin-bottom: 20px; margin-top: 10px; position:relative; display:none;">';
1027
- $echo_str .= "\n\t\t\t".'<div id="wfu_add_plugin_'.$inc.'_overlay" style="position:absolute; top:0; left:0; width:100%; height:100%; background-color:rgba(255,255,255,0.8); border:none; display:none;">';
1028
- $echo_str .= "\n\t\t\t\t".'<table style="background:none; border:none; margin:0; padding:0; line-height:1; border-spacing:0; width:100%; height:100%; table-layout:fixed;"><tbody><tr><td style="text-align:center; vertical-align:middle;"><div style="display:inline-block;"><span class="spinner" style="opacity:1; float:left; margin:0; display:inline;"></span><label style="margin-left:4px;">please wait...</label></div></td></tr></tbody></table>';
1029
- $echo_str .= "\n\t\t\t".'</div>';
1030
- $echo_str .= "\n\t\t\t".'<label>Add '.$slug.' to </label><select id="wfu_page_type_'.$inc.'" onchange="document.getElementById(\'wfu_page_list_'.$inc.'\').style.display = (this.value == \'page\' ? \'inline-block\' : \'none\'); document.getElementById(\'wfu_post_list_'.$inc.'\').style.display = (this.value == \'post\' ? \'inline-block\' : \'none\'); '.$onchange_js.'"><option value="page" selected="selected">Page</option><option value="post">Post</option></select>';
1031
- $echo_str .= "\n\t\t\t".'<select id="wfu_page_list_'.$inc.'" style="margin-bottom:6px;" onchange="'.$onchange_js.'">';
1032
- $echo_str .= "\n\t\t\t\t".'<option value=""></option>';
1033
- foreach ( $pagelist as $item )
1034
- $echo_str .= "\n\t\t\t\t".'<option value="'.$item['id'].'">'.str_repeat('&nbsp;', 4 * $item['level']).( $item['status'] == 1 ? '[Private]' : ( $item['status'] == 2 ? '[Draft]' : '' ) ).$item['title'].'</option>';
1035
- $echo_str .= "\n\t\t\t".'</select>';
1036
- $echo_str .= "\n\t\t\t".'<select id="wfu_post_list_'.$inc.'" style="display:none; margin-bottom:6px;" onchange="'.$onchange_js.'">';
1037
- $echo_str .= "\n\t\t\t\t".'<option value=""></option>';
1038
- foreach ( $postlist as $item )
1039
- $echo_str .= "\n\t\t\t\t".'<option value="'.$item['id'].'">'.str_repeat('&nbsp;', 4 * $item['level']).( $item['status'] == 1 ? '[Private]' : ( $item['status'] == 2 ? '[Draft]' : '' ) ).$item['title'].'</option>';
1040
- $echo_str .= "\n\t\t\t".'</select><br />';
1041
- $add_shortcode_ticket = wfu_create_random_string(16);
1042
- WFU_USVAR_store('wfu_add_shortcode_ticket_for_'.$tag, $add_shortcode_ticket);
1043
- $echo_str .= "\n\t\t".'<button id="wfu_add_plugin_ok_'.$inc.'" style="float:right; margin: 0 2px 0 4px;" disabled="disabled" onclick="document.getElementById(\'wfu_add_plugin_'.$inc.'_overlay\').style.display = \'block\'; window.location = \''.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=add_shortcode&amp;tag='.$tag.'&amp;postid=\' + (document.getElementById(\'wfu_page_type_'.$inc.'\').value == \'page\' ? document.getElementById(\'wfu_page_list_'.$inc.'\').value : document.getElementById(\'wfu_post_list_'.$inc.'\').value) + \'&amp;nonce='.$add_shortcode_ticket.'\';">Ok</button>';
1044
- $echo_str .= "\n\t\t".'<button style="float:right;" onclick="document.getElementById(\'wfu_page_type_'.$inc.'\').value = \'page\'; document.getElementById(\'wfu_page_list_'.$inc.'\').value = \'\'; document.getElementById(\'wfu_post_list_'.$inc.'\').value = \'\'; document.getElementById(\'wfu_add_plugin_'.$inc.'\').style.display = \'none\'; document.getElementById(\'wfu_add_plugin_button_'.$inc.'\').style.display = \'inline-block\';">Cancel</button>';
1045
- $echo_str .= "\n\t\t".'</div>';
1046
- $echo_str .= "\n\t\t".'<table class="wp-list-table widefat fixed striped">';
1047
- $echo_str .= "\n\t\t\t".'<thead>';
1048
- $echo_str .= "\n\t\t\t\t".'<tr>';
1049
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="5%" class="manage-column column-primary">';
1050
- $echo_str .= "\n\t\t\t\t\t\t".'<label>ID</label>';
1051
- $echo_str .= "\n\t\t\t\t\t".'</th>';
1052
- // $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" style="text-align:center;">';
1053
- // $echo_str .= "\n\t\t\t\t\t\t".'<label>ID</label>';
1054
- // $echo_str .= "\n\t\t\t\t\t".'</th>';
1055
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column">';
1056
- $echo_str .= "\n\t\t\t\t\t\t".'<label>Contained In</label>';
1057
- $echo_str .= "\n\t\t\t\t\t".'</th>';
1058
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="30%" class="manage-column">';
1059
- $echo_str .= "\n\t\t\t\t\t\t".'<label>Page/Post Title</label>';
1060
- $echo_str .= "\n\t\t\t\t\t".'</th>';
1061
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="45%" class="manage-column">';
1062
- $echo_str .= "\n\t\t\t\t\t\t".'<label>Shortcode</label>';
1063
- $echo_str .= "\n\t\t\t\t\t".'</th>';
1064
- $echo_str .= "\n\t\t\t\t".'</tr>';
1065
- $echo_str .= "\n\t\t\t".'</thead>';
1066
- $echo_str .= "\n\t\t\t".'<tbody>';
1067
- $i = 1;
1068
- foreach ( $wfu_shortcodes as $key => $data ) {
1069
- $widget_id = ( isset($data['widgetid']) ? $data['widgetid'] : '' );
1070
- if ( $widget_id == "" ) {
1071
- $id = $data['post_id'];
1072
- $posttype_obj = get_post_type_object(get_post_type($id));
1073
- $type = ( $posttype_obj ? $posttype_obj->labels->singular_name : "" );
1074
- $title = get_the_title($id);
1075
- if ( trim($title) == "" ) $title = 'ID: '.$id;
1076
- }
1077
- else {
1078
- $type = 'Sidebar';
1079
- $title = $data['sidebar'];
1080
- }
1081
- $data_enc = wfu_safe_store_shortcode_data(wfu_encode_array_to_string($data));
1082
- $echo_str .= "\n\t\t\t\t".'<tr onmouseover="var actions=document.getElementsByName(\'wfu_shortcode_actions_'.$inc.'\'); for (var i=0; i<actions.length; i++) {actions[i].style.visibility=\'hidden\';} document.getElementById(\'wfu_shortcode_actions_'.$inc.'_'.$i.'\').style.visibility=\'visible\'" onmouseout="var actions=document.getElementsByName(\'wfu_shortcode_actions_'.$inc.'\'); for (var i=0; i<actions.length; i++) {actions[i].style.visibility=\'hidden\';}">';
1083
- $echo_str .= "\n\t\t\t\t\t".'<td class="column-primary" data-colname="ID">';
1084
- $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=edit_shortcode&tag='.$tag.'&data='.$data_enc.'&referer=dashboard" title="Instance #'.$i.'">Instance '.$i.'</a>';
1085
- $echo_str .= "\n\t\t\t\t\t\t".'<div id="wfu_shortcode_actions_'.$inc.'_'.$i.'" name="wfu_shortcode_actions_'.$inc.'" style="visibility:hidden;">';
1086
- $echo_str .= "\n\t\t\t\t\t\t\t".'<span>';
1087
- $echo_str .= "\n\t\t\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=edit_shortcode&tag='.$tag.'&data='.$data_enc.'&referer=dashboard" title="Edit this shortcode">Edit</a>';
1088
- $echo_str .= "\n\t\t\t\t\t\t\t\t".' | ';
1089
- $echo_str .= "\n\t\t\t\t\t\t\t".'</span>';
1090
- $echo_str .= "\n\t\t\t\t\t\t\t".'<span>';
1091
- $echo_str .= "\n\t\t\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=delete_shortcode&data='.$data_enc.'" title="Delete this shortcode">Delete</a>';
1092
- $echo_str .= "\n\t\t\t\t\t\t\t".'</span>';
1093
- $echo_str .= "\n\t\t\t\t\t\t".'</div>';
1094
- $echo_str .= "\n\t\t\t\t\t\t".'<button type="button" class="toggle-row"><span class="screen-reader-text">Show more details</span></button>';
1095
- $echo_str .= "\n\t\t\t\t\t".'</td>';
1096
- // $echo_str .= "\n\t\t\t\t\t".'<td style="padding: 5px 5px 5px 10px; text-align:center;">'.$id.'</td>';
1097
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Contained In">'.$type.'</td>';
1098
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Page/Post Title">'.$title.'</td>';
1099
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Shortcode">';
1100
- $echo_str .= "\n\t\t\t\t\t\t".'<textarea rows="3" disabled="disabled" style="width:100%;">'.trim($data['shortcode']).'</textarea>';
1101
- $echo_str .= "\n\t\t\t\t\t".'</td>';
1102
- $echo_str .= "\n\t\t\t\t".'</tr>';
1103
- $i++;
1104
- }
1105
- $echo_str .= "\n\t\t\t".'</tbody>';
1106
- $echo_str .= "\n\t\t".'</table>';
1107
-
1108
- return $echo_str;
1109
- }
1110
-
1111
- /**
1112
- * Get Shortcodes Contained In A Post.
1113
- *
1114
- * This function returns an array of shortcodes contained inside a post.
1115
- *
1116
- * @since 2.5.4
1117
- *
1118
- * @param object $post The post to check for shortcodes.
1119
- * @param string $tag The shortcode tag to look for.
1120
- *
1121
- * @return array An array of shortcodes contained inside the post.
1122
- */
1123
- function wfu_get_content_shortcodes($post, $tag) {
1124
- global $shortcode_tags;
1125
- $found_shortcodes = array();
1126
- $content = $post->post_content;
1127
- if ( false !== strpos( $content, '[' ) ) {
1128
- $hash = hash('md5', $content);
1129
- if ( array_key_exists( $tag, $shortcode_tags ) ) wfu_match_shortcode_nested($tag, $post, $hash, $content, 0, $found_shortcodes);
1130
- }
1131
- /**
1132
- * Let Custom Scripts Modify the Found Shortcodes.
1133
- *
1134
- * This filter allows to execute custom scripts in order to modify the
1135
- * found shortcodes. It allows to make the plugin compatible with page
1136
- * builders, like Elementor, that do not handle posts / pages the way
1137
- * Wordpress does.
1138
- *
1139
- * @since 4.12.2
1140
- *
1141
- * @param array $found_shortcodes The list of found shortcodes.
1142
- * @param object $post The post to check for shortcodes.
1143
- * @param string $tag The shortcode tag to look for.
1144
- */
1145
- $found_shortcodes = apply_filters("_wfu_get_content_shortcodes", $found_shortcodes, $post, $tag);
1146
-
1147
- if ( count($found_shortcodes) == 0 ) $found_shortcodes = false;
1148
-
1149
- return $found_shortcodes;
1150
- }
1151
-
1152
- /**
1153
- * Match Shortcodes.
1154
- *
1155
- * This function matches all shortcodes inside post contents. It performs
1156
- * matching recursively in order to identify shortcodes contained in other
1157
- * shortcodes.
1158
- *
1159
- * @since 2.7.6
1160
- *
1161
- * @param string $tag The shortcode tag to look for.
1162
- * @param object $post The post to check for shortcodes.
1163
- * @param string $hash A unique hash representing the current contents of the
1164
- * post.
1165
- * @param string $content The content where to look for shortcodes.
1166
- * @param integer $position The starting position of content.
1167
- * @param array $found_shortcodes An array of already found shortcodes that must
1168
- * be filled by additional shortcodes found from this function.
1169
- */
1170
- function wfu_match_shortcode_nested($tag, $post, $hash, $content, $position, &$found_shortcodes) {
1171
- if ( false === strpos( $content, '[' ) ) return false;
1172
- preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE );
1173
- if ( empty( $matches ) ) return false;
1174
- foreach ( $matches as $shortcode ) {
1175
- if ( $tag === $shortcode[2][0] ) {
1176
- $data['post_id'] = $post->ID;
1177
- $data['post_hash'] = $hash;
1178
- $data['shortcode'] = $shortcode[0][0];
1179
- $data['position'] = (int)$shortcode[0][1] + (int)$position;
1180
- array_push($found_shortcodes, $data);
1181
- }
1182
- wfu_match_shortcode_nested($tag, $post, $hash, $shortcode[5][0], $shortcode[5][1] + (int)$position, $found_shortcodes);
1183
- }
1184
- return false;
1185
- }
1186
-
1187
- /**
1188
- * Check Whether Shortcode Can Be Edited.
1189
- *
1190
- * This function checks whether the shortcode submitted for editing can actually
1191
- * be edited. It checks whether the hash of the post, where the shortcode is
1192
- * contained, is the same with the one stored in the shortcode data. If it is
1193
- * not, then this means that the page contents have changed, so the shortcode
1194
- * cannot be edited and the user will have to reload the page before editing the
1195
- * shortcode.
1196
- *
1197
- * @since 2.6.0
1198
- *
1199
- * @param array $data The shortcode data to check.
1200
- *
1201
- * @return bool True if the shortcode can be edited, false otherwise.
1202
- */
1203
- function wfu_check_edit_shortcode($data) {
1204
- $post = get_post($data['post_id']);
1205
- /** This filter is described in wfu_loader.php */
1206
- $content = apply_filters("_wfu_get_post_content", $post->post_content, $post);
1207
- $hash = hash('md5', $content);
1208
-
1209
- return ( $hash == $data['post_hash'] );
1210
- }
1211
-
1212
- /**
1213
- * Add Shortcode Inside Post.
1214
- *
1215
- * This function adds a shortcode at the beginning of post's contents.
1216
- *
1217
- * @since 2.7.6
1218
- *
1219
- * @param integer $postid The post ID where to add the shortcode.
1220
- * $param string $tag The shortcode tag to add in post.
1221
- *
1222
- * @return bool True if the shortcode was added successfully inside the post,
1223
- * false otherwise.
1224
- */
1225
- function wfu_add_shortcode($postid, $tag) {
1226
- /**
1227
- * Let Custom Scripts Add a Shortcode to Post.
1228
- *
1229
- * This filter allows to customize the way that a shortcode is added in a
1230
- * post / page. It allows to make the plugin compatible with page builders,
1231
- * like Elementor, that do not handle posts / pages the way Wordpress does.
1232
- *
1233
- * @since 4.12.2
1234
- *
1235
- * @param integer $postid The post ID where to add the shortcode.
1236
- * @param string $tag The shortcode tag to add in post.
1237
- */
1238
- $result = apply_filters("_wfu_add_shortcode", null, $postid, $tag);
1239
- if ( $result == null ) {
1240
- $post = get_post($postid);
1241
- $new_content = '['.$tag.']'.$post->post_content;
1242
- $new_post = array( 'ID' => $postid, 'post_content' => $new_content );
1243
- $result = ( wp_update_post( wfu_slash($new_post) ) === 0 ? false : true );
1244
- }
1245
- return $result;
1246
- }
1247
-
1248
- /**
1249
- * Replace Shortcode Inside Post.
1250
- *
1251
- * This function replaces a shortcode inside post's contents.
1252
- *
1253
- * @since 2.6.0
1254
- *
1255
- * @param array $data {
1256
- * Contains information about the shortcode.
1257
- *
1258
- * $type integer $post_id The ID of the post that contains the shortcode.
1259
- * $type string $post_hash A hash that represents the current post contents.
1260
- * $type string $shortcode The shortcode string to be replaced.
1261
- * $type integer $position The position of the shortcode inside post's
1262
- * contents.
1263
- * }
1264
- * $param string $new_shortcode The new shortcode.
1265
- *
1266
- * @return bool True if the shortcode was replaced successfully, false
1267
- * otherwise.
1268
- */
1269
- function wfu_replace_shortcode($data, $new_shortcode) {
1270
- /**
1271
- * Let Custom Scripts Modify Shortcode Replacement.
1272
- *
1273
- * This filter allows to customize the way that a shortcode is replaced. It
1274
- * allows to make the plugin compatible with page builders, like Elementor,
1275
- * that do not handle posts / pages the way Wordpress does.
1276
- *
1277
- * @since 4.12.2
1278
- *
1279
- * @param bool|null $result The result of shortcode replacement. It must be
1280
- * true if the replacement succeeded, false if it failed or null if
1281
- * no replacement operation occurred.
1282
- * @param array $data Contains information about the shortcode.
1283
- * $param string $new_shortcode The new shortcode.
1284
- */
1285
- $result = apply_filters("_wfu_replace_shortcode", null, $data, $new_shortcode);
1286
- if ( $result == null ) {
1287
- $post = get_post($data['post_id']);
1288
- $new_content = substr($post->post_content, 0, $data['position']).$new_shortcode.substr($post->post_content, (int)$data['position'] + strlen($data['shortcode']));
1289
- $new_post = array( 'ID' => $data['post_id'], 'post_content' => $new_content );
1290
- $result = ( wp_update_post( wfu_slash($new_post) ) === 0 ? false : true );
1291
- }
1292
- return $result;
1293
- }
1294
-
1295
- /**
1296
- * Generate Page for Confirmation of Deletion of Shortcode.
1297
- *
1298
- * This function generates the HTML code of the page to ask from the user to
1299
- * confirm deletion of the selected shortcode.
1300
- *
1301
- * @since 2.7.0
1302
- *
1303
- * $param string $data_enc Code that represents the shortcode data stored in
1304
- * safe.
1305
- *
1306
- * @return string The HTML code of the deletion confirmation page.
1307
- */
1308
- function wfu_delete_shortcode_prompt($data_enc) {
1309
- $siteurl = site_url();
1310
- $data = wfu_decode_array_from_string(wfu_get_shortcode_data_from_safe($data_enc));
1311
- $postid = $data['post_id'];
1312
- $echo_str = "\n".'<div class="wrap">';
1313
- $echo_str .= "\n\t".'<h2>Wordpress File Upload Control Panel</h2>';
1314
- $echo_str .= "\n\t".'<div style="margin-top:20px;">';
1315
- $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>';
1316
- $echo_str .= "\n\t".'</div>';
1317
- $echo_str .= "\n\t".'<h2 style="margin-bottom: 10px; margin-top: 20px;">Delete Shortcode</h2>';
1318
- $echo_str .= "\n\t".'<form enctype="multipart/form-data" name="deletefile" id="deleteshortcode" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="validate">';
1319
- $echo_str .= "\n\t\t".'<input type="hidden" name="action" value="deleteshortcode">';
1320
- $echo_str .= "\n\t\t".'<input type="hidden" name="data" value="'.$data_enc.'">';
1321
- $echo_str .= "\n\t\t".'<label>Are you sure that you want to delete shortcode for <strong>'.get_post_type($postid).' "'.get_the_title($postid).'" ('.$postid.') Position '.$data['position'].'</strong> ?</label><br/>';
1322
- $echo_str .= "\n\t\t".'<p class="submit">';
1323
- $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Delete">';
1324
- $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Cancel">';
1325
- $echo_str .= "\n\t\t".'</p>';
1326
- $echo_str .= "\n\t".'</form>';
1327
- $echo_str .= "\n".'</div>';
1328
- return $echo_str;
1329
- }
1330
-
1331
- /**
1332
- * Deletion Shortcode.
1333
- *
1334
- * This function deletes a shortcode from page contents.
1335
- *
1336
- * @since 2.7.0
1337
- *
1338
- * $param array $data Code that represents the shortcode data stored in
1339
- * safe. See {@see wfu_replace_shortcode()} for a list of supported
1340
- * arguments.
1341
- *
1342
- * @return bool True if deletion succeeded, false otherwise.
1343
- */
1344
- function wfu_delete_shortcode($data) {
1345
- //check if user is allowed to perform this action
1346
- if ( !current_user_can( 'manage_options' ) ) return false;
1347
-
1348
- $res = true;
1349
- if ( isset($_POST['submit']) ) {
1350
- if ( $_POST['submit'] == "Delete" ) {
1351
- $res = wfu_replace_shortcode($data, '');
1352
- }
1353
- }
1354
- return $res;
1355
- }
1356
-
1357
- /**
1358
- * Add Custom Properties to Media Editor.
1359
- *
1360
- * When "Show Custom Fields in Media Library" option in plugin's Settings is
1361
- * true then Media Library attachments created by uploaded files will contain
1362
- * custom fields corresponding to the uploaded files' userdata (if any). This
1363
- * function shows these custom fields when editing the Media Library attachment.
1364
- *
1365
- * @since 3.7.2
1366
- *
1367
- * @redeclarable
1368
- */
1369
- function wfu_media_editor_properties() {
1370
- $a = func_get_args(); $a = WFU_FUNCTION_HOOK(__FUNCTION__, $a, $out); if (isset($out['vars'])) foreach($out['vars'] as $p => $v) $$p = $v; switch($a) { case 'R': return $out['output']; break; case 'D': die($out['output']); }
1371
- $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
1372
- if ( $plugin_options["mediacustom"] != "1" ) return;
1373
-
1374
- $post = get_post();
1375
- $meta = wp_get_attachment_metadata( $post->ID );
1376
-
1377
- $echo_str = "";
1378
- if ( isset($meta["WFU User Data"]) && is_array($meta["WFU User Data"]) ) {
1379
- foreach ( $meta["WFU User Data"] as $label => $value )
1380
- $echo_str .= '<div class="misc-pub-section misc-pub-userdata">'.$label.': <strong>'.$value.'</strong></div>';
1381
- }
1382
- echo $echo_str;
1383
- }
1384
-
1385
  ?>
1
+ <?php
2
+
3
+ /**
4
+ * Initialize Dashboard Area of Plugin
5
+ *
6
+ * This file initializes the Dashboard area of the plugin; it registers the
7
+ * Dashboard menu pages and processes Dashboard requests.
8
+ *
9
+ * @link /lib/wfu_admin.php
10
+ *
11
+ * @package WordPress File Upload Plugin
12
+ * @subpackage Core Components
13
+ * @since 2.1.2
14
+ */
15
+
16
+ /**
17
+ * Register Dashboard Styles and Scripts.
18
+ *
19
+ * This function registers styles and scripts for Dashboard area.
20
+ *
21
+ * @since 2.4.6
22
+ */
23
+ function wordpress_file_upload_admin_init() {
24
+ $uri = $_SERVER['REQUEST_URI'];
25
+ $is_admin = current_user_can( 'manage_options' );
26
+ $can_edit_posts = ( current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) );
27
+ $can_open_composer = ( WFU_VAR("WFU_SHORTCODECOMPOSER_NOADMIN") == "true" && $can_edit_posts );
28
+ if ( is_admin() && ( ( $is_admin && strpos($uri, "options-general.php") !== false ) ) ||
29
+ //conditional that will register scripts for non-admin users who can
30
+ //edit posts or pages so that they can open the shortcode composer
31
+ ( is_admin() && !$is_admin && $can_open_composer && strpos($uri, "admin.php") !== false ) ) {
32
+ //apply wfu_before_admin_scripts to get additional settings
33
+ $changable_data = array();
34
+ /**
35
+ * Execute Custom Actions Before Loading Admin Scripts.
36
+ *
37
+ * This filter allows to execute custom actions before scripts and
38
+ * styles of the plugin's main Dashboard area are loaded. Loading of
39
+ * plugin's scripts and styles can be completely customised.
40
+ *
41
+ * @since 4.1.0
42
+ *
43
+ * @param array $changable_data {
44
+ * Controls loading of frontpage scripts.
45
+ *
46
+ * @type mixed $return_value Optional. If it is set then no
47
+ * frontpage scripts will be loaded.
48
+ * @type string $correct_NextGenGallery_incompatibility Optional. If
49
+ * it is set to "true" then JQuery UI styles will not be
50
+ * loaded in order to avoid incompatibility with NextGEN
51
+ * Gallery plugin.
52
+ * @type string $correct_JQueryUI_incompatibility Optional. If it is
53
+ * set to "true" then JQuery UI styles will not be loaded
54
+ * (same as previous parameter).
55
+ * @type string $exclude_datepicker Optional. If it is set to "true"
56
+ * then jQuery datepicker styles and scripts will not be
57
+ * loaded.
58
+ * }
59
+ */
60
+ $ret_data = apply_filters('wfu_before_admin_scripts', $changable_data);
61
+ //if $ret_data contains 'return_value' key then no scripts will be
62
+ //registered
63
+ if ( isset($ret_data['return_value']) ) return $ret_data['return_value'];
64
+ //continue with script and style registering
65
+ wp_register_style('wordpress-file-upload-admin-style', WPFILEUPLOAD_DIR.'css/wordpress_file_upload_adminstyle.css',false,'1.0','all');
66
+ wp_register_style('wordpress-file-upload-adminbar-style', WPFILEUPLOAD_DIR.'css/wordpress_file_upload_adminbarstyle.css',false,'1.0','all');
67
+ //do not register JQuery UI css if $ret_data denotes incompatibility
68
+ //issues
69
+ if ( ( !isset($ret_data["correct_NextGenGallery_incompatibility"]) || $ret_data["correct_NextGenGallery_incompatibility"] != "true" ) &&
70
+ ( !isset($ret_data["correct_JQueryUI_incompatibility"]) || $ret_data["correct_JQueryUI_incompatibility"] != "true" ) )
71
+ wp_register_style('jquery-ui-css', WPFILEUPLOAD_DIR.'vendor/jquery/jquery-ui.min.css');
72
+ //don't load datepicker js if $ret_data exclude_datepicker flag is true
73
+ if ( !isset($ret_data["exclude_datepicker"]) || $ret_data["exclude_datepicker"] != "true" )
74
+ wp_register_script('jquery-ui-datepicker', false, array('jquery'));
75
+ wp_register_script('wordpress_file_upload_admin_script', WPFILEUPLOAD_DIR.'js/wordpress_file_upload_adminfunctions.js', array( 'wp-color-picker' ), false, true);
76
+ if ( !$is_admin ) {
77
+ add_action('admin_post_edit_shortcode', 'wordpress_file_upload_manage_dashboard');
78
+ add_action('admin_print_scripts', 'wfu_enqueue_admin_scripts');
79
+ }
80
+ }
81
+ //register scripts for Uploaded Files
82
+ elseif ( is_admin() && $is_admin && strpos($uri, "admin.php") !== false ) {
83
+ //apply wfu_before_admin_scripts to get additional settings
84
+ $changable_data = array();
85
+ /**
86
+ * Execute Custom Actions Before Loading Uploaded Files Scripts.
87
+ *
88
+ * This filter allows to execute custom actions before scripts and
89
+ * styles of the plugin's Uploaded Files Dashboard page are loaded.
90
+ * Loading of plugin's scripts and styles can be completely customised.
91
+ *
92
+ * @since 4.7.0
93
+ *
94
+ * @param array $changable_data {
95
+ * Controls loading of frontpage scripts.
96
+ *
97
+ * @type mixed $return_value Optional. If it is set then no
98
+ * frontpage scripts will be loaded.
99
+ * @type string $correct_NextGenGallery_incompatibility Optional. If
100
+ * it is set to "true" then JQuery UI styles will not be
101
+ * loaded in order to avoid incompatibility with NextGEN
102
+ * Gallery plugin.
103
+ * @type string $correct_JQueryUI_incompatibility Optional. If it is
104
+ * set to "true" then JQuery UI styles will not be loaded
105
+ * (same as previous parameter).
106
+ * }
107
+ */
108
+ $ret_data = apply_filters('wfu_before_uploadedfiles_admin_scripts', $changable_data);
109
+ //if $ret_data contains 'return_value' key then no scripts will be
110
+ //registered
111
+ if ( isset($ret_data['return_value']) ) return $ret_data['return_value'];
112
+ //continue with script and style registering
113
+ wp_register_style('wordpress-file-upload-admin-style', WPFILEUPLOAD_DIR.'css/wordpress_file_upload_adminstyle.css',false,'1.0','all');
114
+ wp_register_style('wordpress-file-upload-adminbar-style', WPFILEUPLOAD_DIR.'css/wordpress_file_upload_adminbarstyle.css',false,'1.0','all');
115
+ //do not register JQuery UI css if $ret_data denotes incompatibility
116
+ //issues
117
+ if ( ( !isset($ret_data["correct_NextGenGallery_incompatibility"]) || $ret_data["correct_NextGenGallery_incompatibility"] != "true" ) &&
118
+ ( !isset($ret_data["correct_JQueryUI_incompatibility"]) || $ret_data["correct_JQueryUI_incompatibility"] != "true" ) )
119
+ wp_register_style('jquery-ui-css', WPFILEUPLOAD_DIR.'vendor/jquery/jquery-ui.min.css');
120
+ wp_register_script('wordpress_file_upload_admin_script', WPFILEUPLOAD_DIR.'js/wordpress_file_upload_adminfunctions.js', array( 'wp-color-picker' ), false, true);
121
+ }
122
+ //register scripts for admin bar menu item
123
+ elseif ( is_admin() && $is_admin ) {
124
+ //script and style registering
125
+ wp_register_style('wordpress-file-upload-adminbar-style', WPFILEUPLOAD_DIR.'css/wordpress_file_upload_adminbarstyle.css',false,'1.0','all');
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Register Dashboard Menu Pages.
131
+ *
132
+ * This function registers the Dashboard pages of the plugin.
133
+ *
134
+ * @since 2.1.2
135
+ */
136
+ function wordpress_file_upload_add_admin_pages() {
137
+ global $wpdb;
138
+ global $wfu_uploadedfiles_hook_suffix;
139
+ $table_name1 = $wpdb->prefix . "wfu_log";
140
+
141
+ $page_hook_suffix = false;
142
+ if ( current_user_can( 'manage_options' ) ) $page_hook_suffix = add_options_page('Wordpress File Upload', 'Wordpress File Upload', 'manage_options', 'wordpress_file_upload', 'wordpress_file_upload_manage_dashboard');
143
+ if ( $page_hook_suffix !== false ) add_action('admin_print_scripts-'.$page_hook_suffix, 'wfu_enqueue_admin_scripts');
144
+ //conditional that will create Wordpress File Upload Dashboard menu, if it
145
+ //has not already been created, for non-admin users who can edit posts or
146
+ //pages, so that their requests for opening the shortcode composer can be
147
+ //handled
148
+ elseif ( WFU_VAR("WFU_SHORTCODECOMPOSER_NOADMIN") == "true" && ( current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) ) ) {
149
+ $page_hook_suffix = add_menu_page('Wordpress File Upload', 'Wordpress File Upload', 'read', 'wordpress_file_upload', 'wordpress_file_upload_manage_dashboard_editor');
150
+ if ( $page_hook_suffix !== false ) add_action('admin_print_scripts-'.$page_hook_suffix, 'wfu_enqueue_admin_scripts');
151
+ }
152
+ //add Uploaded Files menu if it is allowed
153
+ $wfu_uploadedfiles_hook_suffix = false;
154
+ if ( current_user_can( 'manage_options' ) && WFU_VAR("WFU_UPLOADEDFILES_MENU") == "true" ) {
155
+ //get the number of new (unread) uploaded files
156
+ $unread_files_count = wfu_get_unread_files_count();
157
+ $text = $unread_files_count;
158
+ if ( $unread_files_count > 99 ) $text = "99+";
159
+ $title = 'Uploaded Files <span class="update-plugins count-'.$unread_files_count.'"><span class="plugin-count">'.$text.'</span></span>';
160
+ $wfu_uploadedfiles_hook_suffix = add_menu_page(
161
+ 'Uploaded Files',
162
+ $title,
163
+ 'manage_options',
164
+ 'wfu_uploaded_files',
165
+ 'wfu_uploadedfiles_menu',
166
+ 'dashicons-upload',
167
+ 6
168
+ );
169
+ }
170
+ if ( $wfu_uploadedfiles_hook_suffix !== false ) {
171
+ add_action('admin_print_scripts-'.$wfu_uploadedfiles_hook_suffix, 'wfu_enqueue_uploadedfiles_admin_scripts');
172
+ }
173
+ //enqueue scripts for admin bar menu item
174
+ if ( current_user_can( 'manage_options' ) )
175
+ add_action('admin_print_scripts', 'wfu_enqueue_uploadedfiles_adminbar_scripts');
176
+ }
177
+
178
+ /**
179
+ * Enqueue Main Dashboard Page Styles and Scripts.
180
+ *
181
+ * This function registers the styles and scripts of the plugin's main
182
+ * Dashboard page.
183
+ *
184
+ * @since 2.4.6
185
+ */
186
+ function wfu_enqueue_admin_scripts() {
187
+ $uri = $_SERVER['REQUEST_URI'];
188
+ $is_admin = current_user_can( 'manage_options' );
189
+ $can_open_composer = ( WFU_VAR("WFU_SHORTCODECOMPOSER_NOADMIN") == "true" && ( current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) ) );
190
+ if ( is_admin() && ( ( $is_admin && strpos($uri, "options-general.php") !== false ) ) ||
191
+ //conditional that will enqueue scripts for non-admin users who can
192
+ //edit posts or pages so that they can open the shortcode composer
193
+ ( is_admin() && $can_open_composer && strpos($uri, "admin.php") !== false ) ) {
194
+ //apply wfu_before_admin_scripts to get additional settings
195
+ $changable_data = array();
196
+ /** This filter is documented above */
197
+ $ret_data = apply_filters('wfu_before_admin_scripts', $changable_data);
198
+ //if $ret_data contains 'return_value' key then no scripts will be
199
+ //enqueued
200
+ if ( isset($ret_data['return_value']) ) return $ret_data['return_value'];
201
+ //continue with script and style enqueuing
202
+ wp_enqueue_style('wordpress-file-upload-admin-style');
203
+ wp_enqueue_style('wordpress-file-upload-adminbar-style');
204
+ //do not enqueue JQuery UI css if $ret_data denotes incompatibility
205
+ //issues
206
+ if ( ( !isset($ret_data["correct_NextGenGallery_incompatibility"]) || $ret_data["correct_NextGenGallery_incompatibility"] != "true" ) &&
207
+ ( !isset($ret_data["correct_JQueryUI_incompatibility"]) || $ret_data["correct_JQueryUI_incompatibility"] != "true" ) )
208
+ wp_enqueue_style('jquery-ui-css');
209
+ wp_enqueue_style( 'wp-color-picker' );
210
+ //don't load datepicker js if $ret_data exclude_datepicker flag is true
211
+ if ( !isset($ret_data["exclude_datepicker"]) || $ret_data["exclude_datepicker"] != "true" )
212
+ wp_enqueue_script('jquery-ui-datepicker');
213
+ wp_enqueue_script('wordpress_file_upload_admin_script');
214
+ $AdminParams = array("wfu_ajax_url" => site_url()."/wp-admin/admin-ajax.php");
215
+ wp_localize_script( 'wordpress_file_upload_admin_script', 'AdminParams', $AdminParams );
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Enqueue Uploaded Files Dashboard Page Styles and Scripts.
221
+ *
222
+ * This function registers the styles and scripts of the plugin's Uploaded Files
223
+ * Dashboard page.
224
+ *
225
+ * @since 4.7.0
226
+ */
227
+ function wfu_enqueue_uploadedfiles_admin_scripts() {
228
+ $uri = $_SERVER['REQUEST_URI'];
229
+ $is_admin = current_user_can( 'manage_options' );
230
+ if ( is_admin() && $is_admin && strpos($uri, "admin.php") !== false ) {
231
+ //apply wfu_before_admin_scripts to get additional settings
232
+ $changable_data = array();
233
+ /** This filter is documented above */
234
+ $ret_data = apply_filters('wfu_before_uploadedfiles_admin_scripts', $changable_data);
235
+ //if $ret_data contains 'return_value' key then no scripts will be
236
+ //enqueued
237
+ if ( isset($ret_data['return_value']) ) return $ret_data['return_value'];
238
+ //continue with script and style enqueuing
239
+ wp_enqueue_style('wordpress-file-upload-admin-style');
240
+ wp_enqueue_style('wordpress-file-upload-adminbar-style');
241
+ //do not enqueue JQuery UI css if $ret_data denotes incompatibility
242
+ //issues
243
+ if ( ( !isset($ret_data["correct_NextGenGallery_incompatibility"]) || $ret_data["correct_NextGenGallery_incompatibility"] != "true" ) &&
244
+ ( !isset($ret_data["correct_JQueryUI_incompatibility"]) || $ret_data["correct_JQueryUI_incompatibility"] != "true" ) )
245
+ wp_enqueue_style('jquery-ui-css');
246
+ wp_enqueue_script('wordpress_file_upload_admin_script');
247
+ $AdminParams = array("wfu_ajax_url" => site_url()."/wp-admin/admin-ajax.php");
248
+ wp_localize_script( 'wordpress_file_upload_admin_script', 'AdminParams', $AdminParams );
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Enqueue Admin Bar Styles and Scripts.
254
+ *
255
+ * This function registers the styles and scripts of the plugin for the Admin
256
+ * Bar.
257
+ *
258
+ * @since 4.8.0
259
+ */
260
+ function wfu_enqueue_uploadedfiles_adminbar_scripts() {
261
+ $is_admin = current_user_can( 'manage_options' );
262
+ if ( is_admin() && $is_admin ) {
263
+ //script and style enqueuing
264
+ wp_enqueue_style('wordpress-file-upload-adminbar-style');
265
+ }
266
+ }
267
+
268
+
269
+ /**
270
+ * Initialize Tables.
271
+ *
272
+ * This function initializes the plugin's database tables and other actions.
273
+ *
274
+ * @since 2.4.1
275
+ */
276
+ function wordpress_file_upload_install() {
277
+ global $wpdb;
278
+ global $wfu_tb_log_version;
279
+ global $wfu_tb_userdata_version;
280
+ global $wfu_tb_dbxqueue_version;
281
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
282
+
283
+ //define database tables
284
+ $table_name1 = $wpdb->prefix . "wfu_log";
285
+ $installed_ver = get_option( "wordpress_file_upload_table_log_version" );
286
+ if( $installed_ver != $wfu_tb_log_version ) {
287
+ $sql = "CREATE TABLE " . $table_name1 . " (
288
+ idlog mediumint(9) NOT NULL AUTO_INCREMENT,
289
+ userid int NOT NULL,
290
+ uploaduserid int NOT NULL,
291
+ uploadtime bigint,
292
+ sessionid VARCHAR(40),
293
+ filepath TEXT NOT NULL,
294
+ filehash VARCHAR(100) NOT NULL,
295
+ filesize bigint NOT NULL,
296
+ uploadid VARCHAR(20) NOT NULL,
297
+ pageid mediumint(9),
298
+ blogid mediumint(9),
299
+ sid VARCHAR(10),
300
+ date_from DATETIME,
301
+ date_to DATETIME,
302
+ action VARCHAR(20) NOT NULL,
303
+ linkedto mediumint(9),
304
+ filedata TEXT,
305
+ PRIMARY KEY (idlog),
306
+ KEY uploadid (uploadid))
307
+ DEFAULT CHARACTER SET = utf8
308
+ DEFAULT COLLATE = utf8_general_ci;";
309
+ dbDelta($sql);
310
+ update_option("wordpress_file_upload_table_log_version", $wfu_tb_log_version);
311
+ }
312
+
313
+ $table_name2 = $wpdb->prefix . "wfu_userdata";
314
+ $installed_ver = get_option( "wordpress_file_upload_table_userdata_version" );
315
+ if( $installed_ver != $wfu_tb_userdata_version ) {
316
+ $sql = "CREATE TABLE " . $table_name2 . " (
317
+ iduserdata mediumint(9) NOT NULL AUTO_INCREMENT,
318
+ uploadid VARCHAR(20) NOT NULL,
319
+ property VARCHAR(100) NOT NULL,
320
+ propkey mediumint(9) NOT NULL,
321
+ propvalue TEXT,
322
+ date_from DATETIME,
323
+ date_to DATETIME,
324
+ PRIMARY KEY (iduserdata),
325
+ KEY uploadid (uploadid))
326
+ DEFAULT CHARACTER SET = utf8
327
+ DEFAULT COLLATE = utf8_general_ci;";
328
+ dbDelta($sql);
329
+ update_option("wordpress_file_upload_table_userdata_version", $wfu_tb_userdata_version);
330
+ }
331
+
332
+ $table_name3 = $wpdb->prefix . "wfu_dbxqueue";
333
+ $installed_ver = get_option( "wordpress_file_upload_table_dbxqueue_version" );
334
+ if( $installed_ver != $wfu_tb_dbxqueue_version ) {
335
+ $sql = "CREATE TABLE " . $table_name3 . " (
336
+ iddbxqueue mediumint(9) NOT NULL AUTO_INCREMENT,
337
+ fileid mediumint(9) NOT NULL,
338
+ priority mediumint(9) NOT NULL,
339
+ status mediumint(9) NOT NULL,
340
+ jobid VARCHAR(10) NOT NULL,
341
+ start_time bigint,
342
+ PRIMARY KEY (iddbxqueue))
343
+ DEFAULT CHARACTER SET = utf8
344
+ DEFAULT COLLATE = utf8_general_ci;";
345
+ dbDelta($sql);
346
+ update_option("wordpress_file_upload_table_dbxqueue_version", $wfu_tb_dbxqueue_version);
347
+ }
348
+ //adjust user state handler to 'dboption' except if there are active hooks
349
+ //that use session; adjustment will be done only once
350
+ if ( WFU_VAR("WFU_US_HANDLER_CHANGED") == "false" ) {
351
+ $envars = get_option("wfu_environment_variables", array());
352
+ {
353
+ $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
354
+ if ( $plugin_options["userstatehandler"] != "dboption" ) wfu_update_setting("userstatehandler", "dboption");
355
+ if ( WFU_VAR("WFU_US_DBOPTION_BASE") != "cookies" ) {
356
+ $GLOBALS["WFU_GLOBALS"]["WFU_US_DBOPTION_BASE"][3] = "cookies";
357
+ $envars["WFU_US_DBOPTION_BASE"] = "cookies";
358
+ }
359
+ }
360
+ $GLOBALS["WFU_GLOBALS"]["WFU_US_HANDLER_CHANGED"][3] = "true";
361
+ $envars["WFU_US_HANDLER_CHANGED"] = "true";
362
+ update_option("wfu_environment_variables", $envars);
363
+ }
364
+ }
365
+
366
+ /**
367
+ * Actions Before Uninstalling Plugin.
368
+ *
369
+ * This function performs actions before uninstalling the plugin.
370
+ *
371
+ * @since 4.4.0
372
+ */
373
+ function wordpress_file_upload_uninstall() {
374
+ }
375
+
376
+ /**
377
+ * Actions After Plugins are Loaded.
378
+ *
379
+ * This function performs actions after plugin are loaded. It updates the
380
+ * database tables in necessary.
381
+ *
382
+ * @since 2.4.1
383
+ */
384
+ function wordpress_file_upload_update_db_check() {
385
+ global $wfu_tb_log_version;
386
+ global $wfu_tb_userdata_version;
387
+ global $wfu_tb_dbxqueue_version;
388
+ // update_option("wordpress_file_upload_table_log_version", "0");
389
+ // update_option("wordpress_file_upload_table_userdata_version", "0");
390
+ // update_option("wordpress_file_upload_table_dbxqueue_version", "0");
391
+ if ( get_option('wordpress_file_upload_table_log_version') != $wfu_tb_log_version || get_option('wordpress_file_upload_table_userdata_version') != $wfu_tb_userdata_version || get_option('wordpress_file_upload_table_dbxqueue_version') != $wfu_tb_dbxqueue_version ) {
392
+ wordpress_file_upload_install();
393
+ }
394
+ }
395
+
396
+ /**
397
+ * Process Dashboard Requests.
398
+ *
399
+ * This function processes Dashboard requests and shows main Dashboard pages of
400
+ * the plugin in Settings.
401
+ *
402
+ * @since 2.1.2
403
+ */
404
+ function wordpress_file_upload_manage_dashboard() {
405
+ $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
406
+ $_POST = stripslashes_deep($_POST);
407
+ $_GET = stripslashes_deep($_GET);
408
+ $action = (!empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''));
409
+ $dir = (!empty($_POST['dir']) ? $_POST['dir'] : (!empty($_GET['dir']) ? $_GET['dir'] : ''));
410
+ $file = (!empty($_POST['file']) ? $_POST['file'] : (!empty($_GET['file']) ? $_GET['file'] : ''));
411
+ $referer = (!empty($_POST['referer']) ? $_POST['referer'] : (!empty($_GET['referer']) ? $_GET['referer'] : ''));
412
+ $data_enc = (!empty($_POST['data']) ? $_POST['data'] : (!empty($_GET['data']) ? $_GET['data'] : ''));
413
+ $postid = (!empty($_POST['postid']) ? $_POST['postid'] : (!empty($_GET['postid']) ? $_GET['postid'] : ''));
414
+ $nonce = (!empty($_POST['nonce']) ? $_POST['nonce'] : (!empty($_GET['nonce']) ? $_GET['nonce'] : ''));
415
+ $tag = (!empty($_POST['tag']) ? $_POST['tag'] : (!empty($_GET['tag']) ? $_GET['tag'] : ''));
416
+ $username = (!empty($_POST['username']) ? $_POST['username'] : (!empty($_GET['username']) ? $_GET['username'] : ''));
417
+ $invoker = (!empty($_POST['invoker']) ? $_POST['invoker'] : (!empty($_GET['invoker']) ? $_GET['invoker'] : ''));
418
+ $echo_str = "";
419
+
420
+ if ( $action == 'edit_settings' ) {
421
+ wfu_update_settings();
422
+ $echo_str = wfu_manage_settings();
423
+ }
424
+ elseif ( $action == 'shortcode_composer' ) {
425
+ $echo_str = wfu_shortcode_composer();
426
+ }
427
+ elseif ( $action == 'file_browser' ) {
428
+ $echo_str = wfu_browse_files($dir);
429
+ }
430
+ elseif ( $action == 'view_log' ) {
431
+ $page = $tag;
432
+ if ( $page == '' ) $page = 1;
433
+ $page = (int)wfu_sanitize_int($page);
434
+ $located_rec = $invoker;
435
+ if ( $located_rec == '' ) $located_rec = -1;
436
+ $located_rec = (int)wfu_sanitize_int($located_rec);
437
+ $echo_str = wfu_view_log($page, false, $located_rec);
438
+ }
439
+ elseif ( $action == 'rename_file' && $file != "" ) {
440
+ $echo_str = wfu_rename_file_prompt($file, 'file', false);
441
+ }
442
+ elseif ( $action == 'rename_dir' && $file != "" ) {
443
+ $echo_str = wfu_rename_file_prompt($file, 'dir', false);
444
+ }
445
+ elseif ( $action == 'move_file' && $file != "" ) {
446
+ if ( substr($file, 0, 5) == "list:" ) $file = explode(",", substr($file, 5));
447
+ $echo_str = wfu_move_file_prompt($file, false);
448
+ }
449
+ elseif ( $action == 'renamefile' && $file != "" ) {
450
+ if ( wfu_rename_file($file, 'file') ) $echo_str = wfu_browse_files($dir);
451
+ else $echo_str = wfu_rename_file_prompt($file, 'file', true);
452
+ }
453
+ elseif ( $action == 'renamedir' && $file != "" ) {
454
+ if ( wfu_rename_file($file, 'dir') ) $echo_str = wfu_browse_files($dir);
455
+ else $echo_str = wfu_rename_file_prompt($file, 'dir', true);
456
+ }
457
+ elseif ( $action == 'movefile' && $file != "" ) {
458
+ if ( substr($file, 0, 5) == "list:" ) $file = explode(",", substr($file, 5));
459
+ if ( wfu_move_file($file) ) $echo_str = wfu_browse_files($dir);
460
+ else $echo_str = wfu_move_file_prompt($file, true);
461
+ }
462
+ elseif ( $action == 'delete_file' && $file != "" && $referer != "" ) {
463
+ if ( substr($file, 0, 5) == "list:" ) $file = explode(",", substr($file, 5));
464
+ $echo_str = wfu_delete_file_prompt($file, 'file', $referer);
465
+ }
466
+ elseif ( $action == 'delete_dir' && $file != "" && $referer != "" ) {
467
+ $echo_str = wfu_delete_file_prompt($file, 'dir', $referer);
468
+ }
469
+ elseif ( $action == 'deletefile' && $file != "" ) {
470
+ if ( substr($file, 0, 5) == "list:" ) $file = explode(",", substr($file, 5));
471
+ wfu_delete_file($file, 'file');
472
+ $referer_url = wfu_flatten_path(wfu_get_filepath_from_safe(wfu_sanitize_code($referer)));
473
+ if ( $referer_url === false ) $referer_url = "";
474
+ $match = array();
475
+ preg_match("/\&dir=(.*)/", $referer_url, $match);
476
+ $dir = ( isset($match[1]) ? $match[1] : "" );
477
+ $echo_str = wfu_browse_files($dir);
478
+ }
479
+ elseif ( $action == 'deletedir' && $file != "" ) {
480
+ wfu_delete_file($file, 'dir');
481
+ $referer_url = wfu_flatten_path(wfu_get_filepath_from_safe(wfu_sanitize_code($referer)));
482
+ if ( $referer_url === false ) $referer_url = "";
483
+ $match = array();
484
+ preg_match("/\&dir=(.*)/", $referer_url, $match);
485
+ $dir = ( isset($match[1]) ? $match[1] : "" );
486
+ $echo_str = wfu_browse_files($dir);
487
+ }
488
+ elseif ( $action == 'create_dir' ) {
489
+ $echo_str = wfu_create_dir_prompt($dir, false);
490
+ }
491
+ elseif ( $action == 'createdir' ) {
492
+ if ( wfu_create_dir($dir) ) $echo_str = wfu_browse_files($dir);
493
+ else $echo_str = wfu_create_dir_prompt($dir, true);
494
+ }
495
+ elseif ( $action == 'include_file' && $file != "" && $referer != "" ) {
496
+ if ( substr($file, 0, 5) == "list:" ) $file = explode(",", substr($file, 5));
497
+ $echo_str = wfu_include_file_prompt($file, $referer);
498
+ }
499
+ elseif ( $action == 'includefile' && $file != "" ) {
500
+ if ( substr($file, 0, 5) == "list:" ) $file = explode(",", substr($file, 5));
501
+ wfu_include_file($file);
502
+ $referer_url = wfu_flatten_path(wfu_get_filepath_from_safe(wfu_sanitize_code($referer)));
503
+ if ( $referer_url === false ) $referer_url = "";
504
+ $match = array();
505
+ preg_match("/\&dir=(.*)/", $referer_url, $match);
506
+ $dir = ( isset($match[1]) ? $match[1] : "" );
507
+ $echo_str = wfu_browse_files($dir);
508
+ }
509
+ elseif ( $action == 'file_details' && $file != "" ) {
510
+ $echo_str = wfu_file_details($file, false, $invoker);
511
+ }
512
+ elseif ( $action == 'edit_filedetails' && $file != "" ) {
513
+ wfu_edit_filedetails($file);
514
+ $echo_str = wfu_file_details($file, false, $invoker);
515
+ }
516
+ elseif ( $action == 'personal_data' && $plugin_options["personaldata"] == "1" ) {
517
+ $echo_str = wfu_manage_personaldata_policies();
518
+ }
519
+ elseif ( $action == 'erase_userdata_ask' && $plugin_options["personaldata"] == "1" && $username != "" ) {
520
+ $echo_str = wfu_erase_userdata_ask_prompt($username);
521
+ }
522
+ elseif ( $action == 'erase_userdata' && $plugin_options["personaldata"] == "1" && $username != "" ) {
523
+ $ret = wfu_erase_userdata($username);
524
+ if ( $ret <= -1 ) $echo_str = wfu_manage_personaldata_policies();
525
+ else $echo_str = wfu_manage_personaldata_policies('Database cleaned. '.$ret.' items where affected.');
526
+ }
527
+ elseif ( $action == 'maintenance_actions' ) {
528
+ $echo_str = wfu_maintenance_actions();
529
+ }
530
+ elseif ( $action == 'sync_db' && $nonce != "" ) {
531
+ $affected_items = wfu_sync_database_controller($nonce);
532
+ if ( $affected_items > -1 ) $echo_str = wfu_maintenance_actions('Database updated. '.$affected_items.' items where affected.');
533
+ else $echo_str = wfu_maintenance_actions();
534
+ }
535
+ elseif ( $action == 'clean_log_ask' && $nonce != "" && $data_enc != "" ) {
536
+ $echo_str = wfu_clean_log_prompt($nonce, $data_enc);
537
+ }
538
+ elseif ( $action == 'clean_log' ) {
539
+ $ret = wfu_clean_log();
540
+ if ( $ret["recs_count"] <= -1 && $ret["files_count"] ) $echo_str = wfu_maintenance_actions();
541
+ else $echo_str = wfu_maintenance_actions('Database cleaned. '.$ret["recs_count"].' records and '.$ret["files_count"].' files where deleted.');
542
+ }
543
+ elseif ( $action == 'purge_data_ask' && $nonce != "" ) {
544
+ $echo_str = wfu_purge_data_prompt($nonce);
545
+ }
546
+ elseif ( $action == 'purge_data' ) {
547
+ $ret = wfu_purge_data();
548
+ if ( !$ret ) $echo_str = wfu_maintenance_actions();
549
+ else $echo_str = '<script type="text/javascript">window.location.replace("'.admin_url('plugins.php').'");</script>';
550
+ }
551
+ elseif ( $action == 'reset_all_transfers' && $nonce != "" ) {
552
+ if ( wfu_reset_all_transfers_controller($nonce) === true )
553
+ $echo_str = wfu_maintenance_actions('All file transfers were successfully reset.');
554
+ else $echo_str = wfu_maintenance_actions();
555
+ }
556
+ elseif ( $action == 'clear_all_transfers' && $nonce != "" ) {
557
+ if ( wfu_clear_all_transfers_controller($nonce) === true )
558
+ $echo_str = wfu_maintenance_actions('All file transfers were successfully cleared.');
559
+ else $echo_str = wfu_maintenance_actions();
560
+ }
561
+ elseif ( $action == 'plugin_settings' ) {
562
+ $echo_str = wfu_manage_settings();
563
+ }
564
+ elseif ( $action == 'add_shortcode' && $postid != "" && $nonce != "" && $tag != "" ) {
565
+ if ( WFU_USVAR('wfu_add_shortcode_ticket_for_'.$tag) != $nonce ) $echo_str = wfu_manage_mainmenu();
566
+ elseif ( wfu_add_shortcode($postid, $tag) ) $echo_str = wfu_manage_mainmenu();
567
+ else $echo_str = wfu_manage_mainmenu(WFU_DASHBOARD_ADD_SHORTCODE_REJECTED);
568
+ WFU_USVAR_store('wfu_add_shortcode_ticket', 'noticket');
569
+ }
570
+ elseif ( $action == 'edit_shortcode' && $data_enc != "" && $tag != "" ) {
571
+ $data = wfu_decode_array_from_string(wfu_get_shortcode_data_from_safe($data_enc));
572
+ if ( $data['post_id'] == "" || $referer == 'guteditor' || wfu_check_edit_shortcode($data) ) wfu_shortcode_composer($data, $tag, $referer);
573
+ else $echo_str = wfu_manage_mainmenu(WFU_DASHBOARD_EDIT_SHORTCODE_REJECTED);
574
+ }
575
+ elseif ( $action == 'delete_shortcode' && $data_enc != "" ) {
576
+ $data = wfu_decode_array_from_string(wfu_get_shortcode_data_from_safe($data_enc));
577
+ if ( wfu_check_edit_shortcode($data) ) $echo_str = wfu_delete_shortcode_prompt($data_enc);
578
+ else $echo_str = wfu_manage_mainmenu(WFU_DASHBOARD_DELETE_SHORTCODE_REJECTED);
579
+ }
580
+ elseif ( $action == 'deleteshortcode' && $data_enc != "" ) {
581
+ $data = wfu_decode_array_from_string(wfu_get_shortcode_data_from_safe($data_enc));
582
+ if ( wfu_check_edit_shortcode($data) ) {
583
+ if ( wfu_delete_shortcode($data) ) wfu_clear_shortcode_data_from_safe($data_enc);
584
+ $echo_str = wfu_manage_mainmenu();
585
+ }
586
+ else $echo_str = wfu_manage_mainmenu(WFU_DASHBOARD_DELETE_SHORTCODE_REJECTED);
587
+ }
588
+ elseif ( $action == 'add_policy' ) {
589
+ $echo_str = wfu_edit_pd_policy();
590
+ }
591
+ else {
592
+ $echo_str = wfu_manage_mainmenu();
593
+ }
594
+
595
+ echo $echo_str;
596
+ }
597
+
598
+ /**
599
+ * Process Dashboard Requests for Non-Admin Users.
600
+ *
601
+ * This function processes Dashboard requests and shows the shortcode composer
602
+ * to users that are not admins but who can edit posts or pages. It also lets
603
+ * extensions implement their own actions when receiving Dashboard requests by
604
+ * non-admin users.
605
+ *
606
+ * @since 4.11.0
607
+ */
608
+ function wordpress_file_upload_manage_dashboard_editor() {
609
+ $_POST = stripslashes_deep($_POST);
610
+ $_GET = stripslashes_deep($_GET);
611
+ $action = (!empty($_POST['action']) ? $_POST['action'] : (!empty($_GET['action']) ? $_GET['action'] : ''));
612
+ $referer = (!empty($_POST['referer']) ? $_POST['referer'] : (!empty($_GET['referer']) ? $_GET['referer'] : ''));
613
+ $data_enc = (!empty($_POST['data']) ? $_POST['data'] : (!empty($_GET['data']) ? $_GET['data'] : ''));
614
+ $tag = (!empty($_POST['tag']) ? $_POST['tag'] : (!empty($_GET['tag']) ? $_GET['tag'] : ''));
615
+ $echo_str = "";
616
+
617
+ if ( $action == 'edit_shortcode' && $data_enc != "" && $tag != "" ) {
618
+ $data = wfu_decode_array_from_string(wfu_get_shortcode_data_from_safe($data_enc));
619
+ if ( $data['post_id'] == "" || $referer == 'guteditor' || wfu_check_edit_shortcode($data) ) wfu_shortcode_composer($data, $tag, $referer);
620
+ else $echo_str = wfu_manage_mainmenu(WFU_DASHBOARD_EDIT_SHORTCODE_REJECTED);
621
+ }
622
+ else {
623
+ $echo_str = wfu_manage_mainmenu_editor();
624
+ }
625
+
626
+ echo $echo_str;
627
+ }
628
+
629
+ /**
630
+ * Display the Main Dashboard Page.
631
+ *
632
+ * This function displays the Main Dashboard page of the plugin.
633
+ *
634
+ * @since 2.5.2
635
+ *
636
+ * @param string $message Optional. A message to display on top when showing
637
+ * Main page of the plugin in Dashboard.
638
+ *
639
+ * @return string The HTML output of the plugin's Main Dashboard page.
640
+ */
641
+ function wfu_manage_mainmenu($message = '') {
642
+ if ( !current_user_can( 'manage_options' ) ) return;
643
+
644
+ //get php version
645
+ $php_version = preg_replace("/-.*/", "", phpversion());
646
+
647
+ $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
648
+
649
+ $echo_str = '<div class="wrap wfumain">';
650
+ $echo_str .= "\n\t".'<h2>Wordpress File Upload Control Panel</h2>';
651
+ if ( $message != '' ) {
652
+ $echo_str .= "\n\t".'<div class="updated">';
653
+ $echo_str .= "\n\t\t".'<p>'.$message.'</p>';
654
+ $echo_str .= "\n\t".'</div>';
655
+ }
656
+ $echo_str .= "\n\t".'<div style="margin-top:20px;">';
657
+ $echo_str .= wfu_generate_dashboard_menu("\n\t\t", "Main");
658
+ $echo_str .= "\n\t\t".'<h3 style="margin-bottom: 10px;">Status';
659
+ if ( $plugin_options["altserver"] == "1" && substr(trim(WFU_VAR("WFU_ALT_IPTANUS_SERVER")), 0, 5) == "http:" ) {
660
+ $echo_str .= '<div style="display: inline-block; margin-left:20px;" title="'.WFU_WARNING_ALT_IPTANUS_SERVER_ACTIVATED.'"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 200 800" version="1.1" style="background:darkorange; border-radius:13px; padding:2px; vertical-align:middle; border: 1px solid silver;"><path d="M 110,567 L 90,567 L 42,132 C 40,114 40,100 40,90 C 40,70 45,49 56,35 C 70,22 83,15 100,15 C 117,15 130,22 144,35 C 155,49 160,70 160,90 C 160,100 160,114 158,132 z M 100,640 A 60,60 0 1,1 100,760 A 60,60 0 1,1 100,640 z"/></svg></div>';
661
+ }
662
+ $echo_str .= '</h3>';
663
+ $echo_str .= "\n\t\t".'<table class="form-table">';
664
+ $echo_str .= "\n\t\t\t".'<tbody>';
665
+ //plugin edition
666
+ $echo_str .= "\n\t\t\t\t".'<tr>';
667
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="row">';
668
+ $echo_str .= "\n\t\t\t\t\t\t".'<label style="cursor:default;">Edition</label>';
669
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
670
+ $echo_str .= "\n\t\t\t\t\t".'<td style="width:100px; vertical-align:top;">';
671
+ $echo_str .= "\n\t\t\t\t\t\t".'<label style="font-weight:bold; cursor:default;">Free</label>';
672
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
673
+ $echo_str .= "\n\t\t\t\t\t".'<td>';
674
+ $echo_str .= "\n\t\t\t\t\t\t".'<div style="display:inline-block; background-color:bisque; padding:0 0 0 4px; border-left:3px solid lightcoral;">';
675
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label style="cursor:default;">Consider </label><a href="'.WFU_PRO_VERSION_URL.'">Upgrading</a><label style="cursor:default;"> to the Professional Version. </label>';
676
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<button onclick="if (this.innerText == \'See why >>\') {this.innerText = \'<< Close\'; document.getElementById(\'wfu_version_comparison\').style.display = \'inline-block\';} else {this.innerText = \'See why >>\'; document.getElementById(\'wfu_version_comparison\').style.display = \'none\';}">See why >></button>';
677
+ $echo_str .= "\n\t\t\t\t\t\t".'</div>';
678
+ $echo_str .= "\n\t\t\t\t\t\t".'<br /><div id="wfu_version_comparison" style="display:none; background-color:lightyellow; border:1px solid yellow; margin:10px 0; padding:10px;">';
679
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<img src="'.WFU_IMAGE_VERSION_COMPARISON.'" style="display:block; margin-bottom:6px;" />';
680
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<a class="button-primary" href="'.WFU_PRO_VERSION_URL.'">Go for the PRO version</a>';
681
+ $echo_str .= "\n\t\t\t\t\t\t".'</div>';
682
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
683
+ $echo_str .= "\n\t\t\t\t".'</tr>';
684
+ //plugin version
685
+ $echo_str .= "\n\t\t\t\t".'<tr>';
686
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="row">';
687
+ $echo_str .= "\n\t\t\t\t\t\t".'<label style="cursor:default;">Version</label>';
688
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
689
+ $echo_str .= "\n\t\t\t\t\t".'<td style="width:100px;">';
690
+ $cur_version = wfu_get_plugin_version();
691
+ $echo_str .= "\n\t\t\t\t\t\t".'<label style="font-weight:bold; cursor:default;">'.$cur_version.'</label>';
692
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
693
+ $echo_str .= "\n\t\t\t\t\t".'<td>';
694
+ $lat_version = wfu_get_latest_version();
695
+ $ret = wfu_compare_versions($cur_version, $lat_version);
696
+ if ( $lat_version == "" && WFU_VAR("WFU_DISABLE_VERSION_CHECK") != "true" ) {
697
+ $echo_str .= "\n\t\t\t\t\t\t".'<div style="display:inline-block; background-color:transparent; padding:0 0 0 4px; color:red;">';
698
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 200 800" version="1.1" style="background:transparent; border-radius:13px; padding:2px; vertical-align:middle; border: 2px solid red; fill:red;"><path d="M 110,567 L 90,567 L 42,132 C 40,114 40,100 40,90 C 40,70 45,49 56,35 C 70,22 83,15 100,15 C 117,15 130,22 144,35 C 155,49 160,70 160,90 C 160,100 160,114 158,132 z M 100,640 A 60,60 0 1,1 100,760 A 60,60 0 1,1 100,640 z"/></svg>';
699
+ $warning_text = preg_replace("/:(\w+):/", '<a target="_blank" href="'.WFU_IPTANUS_SERVER_UNREACHABLE_ARTICLE.'" title="Iptanus Services Server Unreachable Error of WFU Plugin">$1</a>', WFU_WARNING_IPTANUS_SERVER_UNREACHABLE);
700
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label style="cursor:default;">'.$warning_text.'</label>';
701
+ $echo_str .= "\n\t\t\t\t\t\t".'</div>';
702
+ }
703
+ elseif ( $ret['status'] && $ret['result'] == 'lower' ) {
704
+ $echo_str .= "\n\t\t\t\t\t\t".'<div style="display:inline-block; background-color:bisque; padding:0 0 0 4px; border-left:3px solid lightcoral;">';
705
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label style="cursor:default;">Version <strong>'.$lat_version.'</strong> of the plugin is available. Go to Plugins page of your Dashboard to update to the latest version.</label>';
706
+ if ( $ret['custom'] ) $echo_str .= '<label style="cursor:default; color: purple;"> <em>Please note that you are using a custom version of the plugin. If you upgrade to the newest version, custom changes will be lost.</em></label>';
707
+ $echo_str .= "\n\t\t\t\t\t\t".'</div>';
708
+ }
709
+ elseif ( $ret['status'] && $ret['result'] == 'equal' ) {
710
+ $echo_str .= "\n\t\t\t\t\t\t".'<div style="display:inline-block; background-color:rgb(220,255,220); padding:0 0 0 4px; border-left:3px solid limegreen;">';
711
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label style="cursor:default;">You have the latest version.</label>';
712
+ if ( $ret['custom'] ) $echo_str .= '<label style="cursor:default; color: purple;"> <em>(Please note that your version is custom)</em></label>';
713
+ $echo_str .= "\n\t\t\t\t\t\t".'</div>';
714
+ }
715
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
716
+ $echo_str .= "\n\t\t\t\t".'</tr>';
717
+ //server environment
718
+ $php_env = wfu_get_server_environment();
719
+ $echo_str .= "\n\t\t\t\t".'<tr>';
720
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="row">';
721
+ $echo_str .= "\n\t\t\t\t\t\t".'<label style="cursor:default;">Server Environment</label>';
722
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
723
+ $echo_str .= "\n\t\t\t\t\t".'<td style="width:100px;">';
724
+ if ( $php_env == '64bit' ) $echo_str .= "\n\t\t\t\t\t\t".'<label style="font-weight:bold; cursor:default;">64bit</label></td><td><label style="font-weight:normal; font-style:italic; cursor:default;">(Your server supports files up to 1 Exabyte, practically unlimited)</label>';
725
+ if ( $php_env == '32bit' ) $echo_str .= "\n\t\t\t\t\t\t".'<label style="font-weight:bold; cursor:default;">32bit</label></td><td><label style="font-weight:normal; font-style:italic; cursor:default;">(Your server does not support files larger than 2GB)</label>';
726
+ if ( $php_env == '' ) $echo_str .= "\n\t\t\t\t\t\t".'<label style="font-weight:bold; cursor:default;">Unknown</label></td><td><label style="font-weight:normal; font-style:italic; cursor:default;">(The maximum file size supported by the server cannot be determined)</label>';
727
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
728
+ $echo_str .= "\n\t\t\t\t".'</tr>';
729
+ $echo_str .= "\n\t\t\t\t".'<tr>';
730
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="row">';
731
+ $echo_str .= "\n\t\t\t\t\t\t".'<label style="cursor:default;">PHP Version</label>';
732
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
733
+ $echo_str .= "\n\t\t\t\t\t".'<td style="width:100px;">';
734
+ $cur_version = wfu_get_plugin_version();
735
+ $echo_str .= "\n\t\t\t\t\t\t".'<label style="font-weight:bold; cursor:default;">'.$php_version.'</label>';
736
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
737
+ $echo_str .= "\n\t\t\t\t\t".'<td>';
738
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
739
+ $echo_str .= "\n\t\t\t\t".'</tr>';
740
+ $echo_str .= "\n\t\t\t\t".'<tr>';
741
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="row">';
742
+ $echo_str .= "\n\t\t\t\t\t\t".'<label style="cursor:default;">Release Notes</label>';
743
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
744
+ $echo_str .= "\n\t\t\t\t\t".'<td colspan="2" style="width:100px;">';
745
+ $rel_path = ABSWPFILEUPLOAD_DIR.'release_notes.txt';
746
+ $rel_notes = '';
747
+ if ( file_exists($rel_path) ) $rel_notes = file_get_contents($rel_path);
748
+ $echo_str .= "\n\t\t\t\t\t\t".'<div style="text-align:justify;">'.$rel_notes.'</div>';
749
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
750
+ $echo_str .= "\n\t\t\t\t".'</tr>';
751
+ $echo_str .= "\n\t\t\t".'</tbody>';
752
+ $echo_str .= "\n\t\t".'</table>';
753
+
754
+ $echo_str .= wfu_manage_instances();
755
+
756
+ $echo_str .= "\n\t".'</div>';
757
+ $echo_str .= "\n".'</div>';
758
+
759
+ return $echo_str;
760
+ }
761
+
762
+ /**
763
+ * Default Dashboard Page for Non-Admin Users.
764
+ *
765
+ * This function displays the plugin's default Dashboard page for non-admin
766
+ * users who can edit pages or posts.
767
+ *
768
+ * @since 4.11.0
769
+ *
770
+ * @param string $message Optional. A message to display on top when showing
771
+ * the default Dashboard page of the plugin for non-admin users.
772
+ *
773
+ * @return string The HTML output of the plugin's default Dashboard page.
774
+ */
775
+ function wfu_manage_mainmenu_editor($message = '') {
776
+ if ( !current_user_can( 'edit_pages' ) && !current_user_can( 'edit_posts' ) ) return;
777
+
778
+ $echo_str = '<div class="wrap wfumain">';
779
+ $echo_str .= "\n\t".'<h2>Wordpress File Upload Control Panel</h2>';
780
+ if ( $message != '' ) {
781
+ $echo_str .= "\n\t".'<div class="updated">';
782
+ $echo_str .= "\n\t\t".'<p>'.$message.'</p>';
783
+ $echo_str .= "\n\t".'</div>';
784
+ }
785
+ $echo_str .= "\n\t".'<div style="margin-top:20px;">';
786
+ $echo_str .= "\n\t\t".'<h3 style="margin-bottom: 10px;">This menu item exists to show the plugin\'s shortcode composer when editing pages or posts.</h3>';
787
+ $echo_str .= "\n\t".'</div>';
788
+ $echo_str .= "\n".'</div>';
789
+
790
+ return $echo_str;
791
+ }
792
+
793
+ /**
794
+ * Main Dashboard Page Tabs.
795
+ *
796
+ * This function generates the tabs of the plugin's main area in Dashboard.
797
+ *
798
+ * @since 3.6.0
799
+ *
800
+ * @redeclarable
801
+ *
802
+ * @param string $dlp Identation string before the beginning of each HTML line.
803
+ * @param string $active The name of the tab that it is active.
804
+ *
805
+ * @return string The HTML output of the tabs.
806
+ */
807
+ function wfu_generate_dashboard_menu($dlp, $active) {
808
+ $a = func_get_args(); $a = WFU_FUNCTION_HOOK(__FUNCTION__, $a, $out); if (isset($out['vars'])) foreach($out['vars'] as $p => $v) $$p = $v; switch($a) { case 'R': return $out['output']; break; case 'D': die($out['output']); }
809
+ $siteurl = site_url();
810
+ $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
811
+
812
+ $echo_str = $dlp.'<h2 class="nav-tab-wrapper" style="margin-bottom:40px;">';
813
+ $echo_str .= $dlp."\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="nav-tab'.( $active == "Main" ? ' nav-tab-active' : '' ).'" title="Main">Main</a>';
814
+ $echo_str .= $dlp."\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=plugin_settings" class="nav-tab'.( $active == "Settings" ? ' nav-tab-active' : '' ).'" title="Settings">Settings</a>';
815
+ $echo_str .= $dlp."\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=file_browser" class="nav-tab'.( $active == "File Browser" ? ' nav-tab-active' : '' ).'" title="File browser">File Browser</a>';
816
+ $echo_str .= $dlp."\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=view_log" class="nav-tab'.( $active == "View Log" ? ' nav-tab-active' : '' ).'" title="View log">View Log</a>';
817
+ if ( $plugin_options["personaldata"] == "1" )
818
+ $echo_str .= $dlp."\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=personal_data" class="nav-tab'.( $active == "Personal Data" ? ' nav-tab-active' : '' ).'" title="Personal Data">Personal Data</a>';
819
+ $echo_str .= $dlp."\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=maintenance_actions" class="nav-tab'.( $active == "Maintenance Actions" ? ' nav-tab-active' : '' ).'" title="Maintenance Actions">Maintenance Actions</a>';
820
+ $echo_str .= $dlp.'</h2>';
821
+
822
+ return $echo_str;
823
+ }
824
+
825
+ /**
826
+ * Generate List of Posts in Tree Order.
827
+ *
828
+ * This function converts a flat array of posts into a tree structure, where an
829
+ * individual item of the returned array may contain a nested array of children.
830
+ * Items of the same parent and level are sorted by post status (publish,
831
+ * private, draft) and then by title.
832
+ *
833
+ * @since 2.7.6
834
+ *
835
+ * @param array $posts The initial flat array of posts.
836
+ *
837
+ * @return array The returned list of posts in tree order.
838
+ */
839
+ function wfu_construct_post_list($posts) {
840
+ $ids = array();
841
+ $list = array();
842
+ $id_keys = array();
843
+ //construct item indices
844
+ foreach ( $posts as $key => $post ) {
845
+ if ( !array_key_exists($post->post_type, $ids) ) {
846
+ $ids[$post->post_type] = array();
847
+ $list[$post->post_type] = array();
848
+ }
849
+ array_push($ids[$post->post_type], $post->ID);
850
+ $id_keys[$post->ID] = $key;
851
+ }
852
+ //create post list in tree order; items are sorted by post status (publish,
853
+ //private, draft) and then by title
854
+ $i = 0;
855
+ while ( $i < count($posts) ) {
856
+ $post = $posts[$i];
857
+ //find topmost element in family tree
858
+ $tree = array( $post->ID );
859
+ $topmost = $post;
860
+ $par_id = $topmost->post_parent;
861
+ while ( in_array($par_id, $ids[$post->post_type]) ) {
862
+ $topmost = $posts[$id_keys[$par_id]];
863
+ array_splice($tree, 0, 0, $par_id);
864
+ $par_id = $topmost->post_parent;
865
+ }
866
+ //find which needs to be processed
867
+ $level = 0;
868
+ $host = &$list[$post->post_type];
869
+ foreach ( $tree as $process_id ) {
870
+ $found_key = -1;
871
+ foreach ( $host as $key => $item )
872
+ if ( $item['id'] == $process_id ) {
873
+ $found_key = $key;
874
+ break;
875
+ }
876
+ if ( $found_key == -1 ) break;
877
+ $level++;
878
+ $host = &$host[$found_key]['children'];
879
+ }
880
+ if ( $found_key == -1 ) {
881
+ $processed = $posts[$id_keys[$process_id]];
882
+ //add the processed item in the right position in children's list
883
+ $pos = 0;
884
+ $status = ( $processed->post_status == 'publish' ? 0 : ( $processed->post_status == 'private' ? 1 : 2 ) );
885
+ foreach ($host as $item) {
886
+ if ( $status < $item['status'] ) break;
887
+ if ( $status == $item['status'] && strcmp($processed->post_title, $item['title']) < 0 ) break;
888
+ $pos++;
889
+ }
890
+ $new_item = array(
891
+ 'id' => $process_id,
892
+ 'title' => $processed->post_title,
893
+ 'status' => $status,
894
+ 'level' => $level,
895
+ 'children' => array()
896
+ );
897
+ array_splice($host, $pos, 0, array($new_item));
898
+ }
899
+ //advance index if we have finished processing all the tree
900
+ if ( $process_id == $post->ID ) $i++;
901
+ }
902
+ return $list;
903
+ }
904
+
905
+ /**
906
+ * Flatten Tree List of Posts.
907
+ *
908
+ * This function converts a list that contains posts in tree order into a flat
909
+ * list (array) of posts.
910
+ *
911
+ * @since 2.7.6
912
+ *
913
+ * @param array $list The initial tree list of posts.
914
+ *
915
+ * @return array The returned flat list of posts.
916
+ */
917
+ function wfu_flatten_post_list($list) {
918
+ $flat = array();
919
+ if ( !is_array($list) ) return $flat;
920
+ foreach( $list as $item ) {
921
+ $flat_item = array(
922
+ 'id' => $item['id'],
923
+ 'title' => $item['title'],
924
+ 'status' => $item['status'],
925
+ 'level' => $item['level']
926
+ );
927
+ array_push($flat, $flat_item);
928
+ $flat = array_merge($flat, wfu_flatten_post_list($item['children']));
929
+ }
930
+ return $flat;
931
+ }
932
+
933
+ /**
934
+ * Generate List of Instances of All Plugin' Shortcodes.
935
+ *
936
+ * This function generates a tabular list of all instances of all plugin's
937
+ * shortcodes.
938
+ *
939
+ * @since 2.5.2
940
+ *
941
+ * @return string The HTML code of the list of instances of all the shortcodes.
942
+ */
943
+ function wfu_manage_instances() {
944
+ $echo_str = wfu_manage_instances_of_shortcode('wordpress_file_upload', 'Uploader Instances', 'uploader', 1);
945
+
946
+ return $echo_str;
947
+ }
948
+
949
+ /**
950
+ * Generate List of Instances of A Plugin' Shortcode.
951
+ *
952
+ * This function generates a tabular list of all instances of a plugin's
953
+ * shortcode.
954
+ *
955
+ * @since 3.1.0
956
+ *
957
+ * @param string $tag The shortcode tag.
958
+ * @param string $title The title of the list
959
+ * @param string $slug A slug of the shortcode.
960
+ * @param integer $inc The increment number of this list of instances.
961
+ *
962
+ * @return string The HTML code of the list of instances of the shortcode.
963
+ */
964
+ function wfu_manage_instances_of_shortcode($tag, $title, $slug, $inc) {
965
+ global $wp_registered_widgets, $wp_registered_sidebars;
966
+
967
+ $siteurl = site_url();
968
+ $args = array( 'post_type' => array( "post", "page" ), 'post_status' => "publish,private,draft", 'posts_per_page' => -1 );
969
+ /**
970
+ * Filter Arguments for Getting List of Posts.
971
+ *
972
+ * This filter allows to customize the arguments passed to get_posts()
973
+ * function to get a list of posts. By default the plugin will get a list of
974
+ * all posts and pages. If the website contains too many posts this
975
+ * operation may take time and delay loading of the page. So this filter can
976
+ * be used to optimize this operation.
977
+ *
978
+ * @since 4.0.0
979
+ *
980
+ * @param array $args Arguments to retrieve posts.
981
+ * @param string $operation A parameter designating in which operation this
982
+ * filter is used.
983
+ */
984
+ $args = apply_filters("_wfu_get_posts", $args, "manage_instances");
985
+ $posts = get_posts($args);
986
+ $wfu_shortcodes = array();
987
+ //get shortcode instances from page/posts
988
+ foreach ( $posts as $post ) {
989
+ $ret = wfu_get_content_shortcodes($post, $tag);
990
+ if ( $ret !== false ) $wfu_shortcodes = array_merge($wfu_shortcodes, $ret);
991
+ }
992
+ //get shortcode instances from sidebars
993
+ $data = array();
994
+ $widget_base = $tag.'_widget';
995
+ if ( is_array($wp_registered_widgets) ) {
996
+ foreach ( $wp_registered_widgets as $id => $widget ) {
997
+ if ( substr($id, 0, strlen($widget_base)) == $widget_base ) {
998
+ $widget_obj = ( isset($widget['callback']) ? ( isset($widget['callback'][0]) ? ( $widget['callback'][0] instanceof WP_Widget ? $widget['callback'][0] : false ) : false ) : false );
999
+ $widget_sidebar = is_active_widget(false, $id, $widget_base);
1000
+ if ( $widget_obj !== false && $widget_sidebar !== false ) {
1001
+ if ( isset($wp_registered_sidebars[$widget_sidebar]) && isset($wp_registered_sidebars[$widget_sidebar]['name']) ) $widget_sidebar = $wp_registered_sidebars[$widget_sidebar]['name'];
1002
+ $data['post_id'] = "";
1003
+ $data['post_hash'] = "";
1004
+ $data['shortcode'] = $widget_obj->shortcode();
1005
+ $data['position'] = 0;
1006
+ $data['widgetid'] = $id;
1007
+ $data['sidebar'] = $widget_sidebar;
1008
+ array_push($wfu_shortcodes, $data);
1009
+ }
1010
+ }
1011
+ }
1012
+ }
1013
+
1014
+ $list = wfu_construct_post_list($posts);
1015
+ $pagelist = wfu_flatten_post_list($list["page"]);
1016
+ $postlist = wfu_flatten_post_list($list["post"]);
1017
+
1018
+ $echo_str = "\n\t\t".'<h3 style="margin-bottom: 10px; margin-top: 40px;">'.$title.'</h3>';
1019
+ $onchange_js = 'document.getElementById(\'wfu_add_plugin_ok_'.$inc.'\').disabled = !((document.getElementById(\'wfu_page_type_'.$inc.'\').value == \'page\' && document.getElementById(\'wfu_page_list_'.$inc.'\').value != \'\') || (document.getElementById(\'wfu_page_type_'.$inc.'\').value == \'post\' && document.getElementById(\'wfu_post_list_'.$inc.'\').value != \'\'));';
1020
+ $no_shortcodes = ( count($wfu_shortcodes) == 0 );
1021
+ $echo_str .= "\n\t\t".'<div id="wfu_add_plugin_button_'.$inc.'" style="'. ( !$no_shortcodes ? '' : 'color:blue; font-weight:bold; font-size:larger;' ).'margin-bottom: 20px; margin-top: 10px;">';
1022
+ $addbutton_pre = ( !$no_shortcodes ? '' : '<label>Press </label>');
1023
+ $addbutton_post = ( !$no_shortcodes ? '' : '<label> to get started and add the '.$slug.' in a page</label>');
1024
+ $echo_str .= "\n\t\t\t".$addbutton_pre.'<button onclick="document.getElementById(\'wfu_add_plugin_button_'.$inc.'\').style.display = \'none\'; document.getElementById(\'wfu_add_plugin_'.$inc.'\').style.display = \'inline-block\'; '.$onchange_js.'">'.( !$no_shortcodes ? 'Add Plugin Instance' : 'here' ).'</button>'.$addbutton_post;
1025
+ $echo_str .= "\n\t\t".'</div>';
1026
+ $echo_str .= "\n\t\t".'<div id="wfu_add_plugin_'.$inc.'" style="margin-bottom: 20px; margin-top: 10px; position:relative; display:none;">';
1027
+ $echo_str .= "\n\t\t\t".'<div id="wfu_add_plugin_'.$inc.'_overlay" style="position:absolute; top:0; left:0; width:100%; height:100%; background-color:rgba(255,255,255,0.8); border:none; display:none;">';
1028
+ $echo_str .= "\n\t\t\t\t".'<table style="background:none; border:none; margin:0; padding:0; line-height:1; border-spacing:0; width:100%; height:100%; table-layout:fixed;"><tbody><tr><td style="text-align:center; vertical-align:middle;"><div style="display:inline-block;"><span class="spinner" style="opacity:1; float:left; margin:0; display:inline;"></span><label style="margin-left:4px;">please wait...</label></div></td></tr></tbody></table>';
1029
+ $echo_str .= "\n\t\t\t".'</div>';
1030
+ $echo_str .= "\n\t\t\t".'<label>Add '.$slug.' to </label><select id="wfu_page_type_'.$inc.'" onchange="document.getElementById(\'wfu_page_list_'.$inc.'\').style.display = (this.value == \'page\' ? \'inline-block\' : \'none\'); document.getElementById(\'wfu_post_list_'.$inc.'\').style.display = (this.value == \'post\' ? \'inline-block\' : \'none\'); '.$onchange_js.'"><option value="page" selected="selected">Page</option><option value="post">Post</option></select>';
1031
+ $echo_str .= "\n\t\t\t".'<select id="wfu_page_list_'.$inc.'" style="margin-bottom:6px;" onchange="'.$onchange_js.'">';
1032
+ $echo_str .= "\n\t\t\t\t".'<option value=""></option>';
1033
+ foreach ( $pagelist as $item )
1034
+ $echo_str .= "\n\t\t\t\t".'<option value="'.$item['id'].'">'.str_repeat('&nbsp;', 4 * $item['level']).( $item['status'] == 1 ? '[Private]' : ( $item['status'] == 2 ? '[Draft]' : '' ) ).$item['title'].'</option>';
1035
+ $echo_str .= "\n\t\t\t".'</select>';
1036
+ $echo_str .= "\n\t\t\t".'<select id="wfu_post_list_'.$inc.'" style="display:none; margin-bottom:6px;" onchange="'.$onchange_js.'">';
1037
+ $echo_str .= "\n\t\t\t\t".'<option value=""></option>';
1038
+ foreach ( $postlist as $item )
1039
+ $echo_str .= "\n\t\t\t\t".'<option value="'.$item['id'].'">'.str_repeat('&nbsp;', 4 * $item['level']).( $item['status'] == 1 ? '[Private]' : ( $item['status'] == 2 ? '[Draft]' : '' ) ).$item['title'].'</option>';
1040
+ $echo_str .= "\n\t\t\t".'</select><br />';
1041
+ $add_shortcode_ticket = wfu_create_random_string(16);
1042
+ WFU_USVAR_store('wfu_add_shortcode_ticket_for_'.$tag, $add_shortcode_ticket);
1043
+ $echo_str .= "\n\t\t".'<button id="wfu_add_plugin_ok_'.$inc.'" style="float:right; margin: 0 2px 0 4px;" disabled="disabled" onclick="document.getElementById(\'wfu_add_plugin_'.$inc.'_overlay\').style.display = \'block\'; window.location = \''.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=add_shortcode&amp;tag='.$tag.'&amp;postid=\' + (document.getElementById(\'wfu_page_type_'.$inc.'\').value == \'page\' ? document.getElementById(\'wfu_page_list_'.$inc.'\').value : document.getElementById(\'wfu_post_list_'.$inc.'\').value) + \'&amp;nonce='.$add_shortcode_ticket.'\';">Ok</button>';
1044
+ $echo_str .= "\n\t\t".'<button style="float:right;" onclick="document.getElementById(\'wfu_page_type_'.$inc.'\').value = \'page\'; document.getElementById(\'wfu_page_list_'.$inc.'\').value = \'\'; document.getElementById(\'wfu_post_list_'.$inc.'\').value = \'\'; document.getElementById(\'wfu_add_plugin_'.$inc.'\').style.display = \'none\'; document.getElementById(\'wfu_add_plugin_button_'.$inc.'\').style.display = \'inline-block\';">Cancel</button>';
1045
+ $echo_str .= "\n\t\t".'</div>';
1046
+ $echo_str .= "\n\t\t".'<table class="wp-list-table widefat fixed striped">';
1047
+ $echo_str .= "\n\t\t\t".'<thead>';
1048
+ $echo_str .= "\n\t\t\t\t".'<tr>';
1049
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="5%" class="manage-column column-primary">';
1050
+ $echo_str .= "\n\t\t\t\t\t\t".'<label>ID</label>';
1051
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
1052
+ // $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" style="text-align:center;">';
1053
+ // $echo_str .= "\n\t\t\t\t\t\t".'<label>ID</label>';
1054
+ // $echo_str .= "\n\t\t\t\t\t".'</th>';
1055
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column">';
1056
+ $echo_str .= "\n\t\t\t\t\t\t".'<label>Contained In</label>';
1057
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
1058
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="30%" class="manage-column">';
1059
+ $echo_str .= "\n\t\t\t\t\t\t".'<label>Page/Post Title</label>';
1060
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
1061
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="45%" class="manage-column">';
1062
+ $echo_str .= "\n\t\t\t\t\t\t".'<label>Shortcode</label>';
1063
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
1064
+ $echo_str .= "\n\t\t\t\t".'</tr>';
1065
+ $echo_str .= "\n\t\t\t".'</thead>';
1066
+ $echo_str .= "\n\t\t\t".'<tbody>';
1067
+ $i = 1;
1068
+ foreach ( $wfu_shortcodes as $key => $data ) {
1069
+ $widget_id = ( isset($data['widgetid']) ? $data['widgetid'] : '' );
1070
+ if ( $widget_id == "" ) {
1071
+ $id = $data['post_id'];
1072
+ $posttype_obj = get_post_type_object(get_post_type($id));
1073
+ $type = ( $posttype_obj ? $posttype_obj->labels->singular_name : "" );
1074
+ $title = get_the_title($id);
1075
+ if ( trim($title) == "" ) $title = 'ID: '.$id;
1076
+ }
1077
+ else {
1078
+ $type = 'Sidebar';
1079
+ $title = $data['sidebar'];
1080
+ }
1081
+ $data_enc = wfu_safe_store_shortcode_data(wfu_encode_array_to_string($data));
1082
+ $echo_str .= "\n\t\t\t\t".'<tr onmouseover="var actions=document.getElementsByName(\'wfu_shortcode_actions_'.$inc.'\'); for (var i=0; i<actions.length; i++) {actions[i].style.visibility=\'hidden\';} document.getElementById(\'wfu_shortcode_actions_'.$inc.'_'.$i.'\').style.visibility=\'visible\'" onmouseout="var actions=document.getElementsByName(\'wfu_shortcode_actions_'.$inc.'\'); for (var i=0; i<actions.length; i++) {actions[i].style.visibility=\'hidden\';}">';
1083
+ $echo_str .= "\n\t\t\t\t\t".'<td class="column-primary" data-colname="ID">';
1084
+ $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=edit_shortcode&tag='.$tag.'&data='.$data_enc.'&referer=dashboard" title="Instance #'.$i.'">Instance '.$i.'</a>';
1085
+ $echo_str .= "\n\t\t\t\t\t\t".'<div id="wfu_shortcode_actions_'.$inc.'_'.$i.'" name="wfu_shortcode_actions_'.$inc.'" style="visibility:hidden;">';
1086
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<span>';
1087
+ $echo_str .= "\n\t\t\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=edit_shortcode&tag='.$tag.'&data='.$data_enc.'&referer=dashboard" title="Edit this shortcode">Edit</a>';
1088
+ $echo_str .= "\n\t\t\t\t\t\t\t\t".' | ';
1089
+ $echo_str .= "\n\t\t\t\t\t\t\t".'</span>';
1090
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<span>';
1091
+ $echo_str .= "\n\t\t\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=delete_shortcode&data='.$data_enc.'" title="Delete this shortcode">Delete</a>';
1092
+ $echo_str .= "\n\t\t\t\t\t\t\t".'</span>';
1093
+ $echo_str .= "\n\t\t\t\t\t\t".'</div>';
1094
+ $echo_str .= "\n\t\t\t\t\t\t".'<button type="button" class="toggle-row"><span class="screen-reader-text">Show more details</span></button>';
1095
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
1096
+ // $echo_str .= "\n\t\t\t\t\t".'<td style="padding: 5px 5px 5px 10px; text-align:center;">'.$id.'</td>';
1097
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Contained In">'.$type.'</td>';
1098
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Page/Post Title">'.$title.'</td>';
1099
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Shortcode">';
1100
+ $echo_str .= "\n\t\t\t\t\t\t".'<textarea rows="3" disabled="disabled" style="width:100%;">'.trim($data['shortcode']).'</textarea>';
1101
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
1102
+ $echo_str .= "\n\t\t\t\t".'</tr>';
1103
+ $i++;
1104
+ }
1105
+ $echo_str .= "\n\t\t\t".'</tbody>';
1106
+ $echo_str .= "\n\t\t".'</table>';
1107
+
1108
+ return $echo_str;
1109
+ }
1110
+
1111
+ /**
1112
+ * Get Shortcodes Contained In A Post.
1113
+ *
1114
+ * This function returns an array of shortcodes contained inside a post.
1115
+ *
1116
+ * @since 2.5.4
1117
+ *
1118
+ * @param object $post The post to check for shortcodes.
1119
+ * @param string $tag The shortcode tag to look for.
1120
+ *
1121
+ * @return array An array of shortcodes contained inside the post.
1122
+ */
1123
+ function wfu_get_content_shortcodes($post, $tag) {
1124
+ global $shortcode_tags;
1125
+ $found_shortcodes = array();
1126
+ $content = $post->post_content;
1127
+ if ( false !== strpos( $content, '[' ) ) {
1128
+ $hash = hash('md5', $content);
1129
+ if ( array_key_exists( $tag, $shortcode_tags ) ) wfu_match_shortcode_nested($tag, $post, $hash, $content, 0, $found_shortcodes);
1130
+ }
1131
+ /**
1132
+ * Let Custom Scripts Modify the Found Shortcodes.
1133
+ *
1134
+ * This filter allows to execute custom scripts in order to modify the
1135
+ * found shortcodes. It allows to make the plugin compatible with page
1136
+ * builders, like Elementor, that do not handle posts / pages the way
1137
+ * Wordpress does.
1138
+ *
1139
+ * @since 4.12.2
1140
+ *
1141
+ * @param array $found_shortcodes The list of found shortcodes.
1142
+ * @param object $post The post to check for shortcodes.
1143
+ * @param string $tag The shortcode tag to look for.
1144
+ */
1145
+ $found_shortcodes = apply_filters("_wfu_get_content_shortcodes", $found_shortcodes, $post, $tag);
1146
+
1147
+ if ( count($found_shortcodes) == 0 ) $found_shortcodes = false;
1148
+
1149
+ return $found_shortcodes;
1150
+ }
1151
+
1152
+ /**
1153
+ * Match Shortcodes.
1154
+ *
1155
+ * This function matches all shortcodes inside post contents. It performs
1156
+ * matching recursively in order to identify shortcodes contained in other
1157
+ * shortcodes.
1158
+ *
1159
+ * @since 2.7.6
1160
+ *
1161
+ * @param string $tag The shortcode tag to look for.
1162
+ * @param object $post The post to check for shortcodes.
1163
+ * @param string $hash A unique hash representing the current contents of the
1164
+ * post.
1165
+ * @param string $content The content where to look for shortcodes.
1166
+ * @param integer $position The starting position of content.
1167
+ * @param array $found_shortcodes An array of already found shortcodes that must
1168
+ * be filled by additional shortcodes found from this function.
1169
+ */
1170
+ function wfu_match_shortcode_nested($tag, $post, $hash, $content, $position, &$found_shortcodes) {
1171
+ if ( false === strpos( $content, '[' ) ) return false;
1172
+ preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE );
1173
+ if ( empty( $matches ) ) return false;
1174
+ foreach ( $matches as $shortcode ) {
1175
+ if ( $tag === $shortcode[2][0] ) {
1176
+ $data['post_id'] = $post->ID;
1177
+ $data['post_hash'] = $hash;
1178
+ $data['shortcode'] = $shortcode[0][0];
1179
+ $data['position'] = (int)$shortcode[0][1] + (int)$position;
1180
+ array_push($found_shortcodes, $data);
1181
+ }
1182
+ wfu_match_shortcode_nested($tag, $post, $hash, $shortcode[5][0], $shortcode[5][1] + (int)$position, $found_shortcodes);
1183
+ }
1184
+ return false;
1185
+ }
1186
+
1187
+ /**
1188
+ * Check Whether Shortcode Can Be Edited.
1189
+ *
1190
+ * This function checks whether the shortcode submitted for editing can actually
1191
+ * be edited. It checks whether the hash of the post, where the shortcode is
1192
+ * contained, is the same with the one stored in the shortcode data. If it is
1193
+ * not, then this means that the page contents have changed, so the shortcode
1194
+ * cannot be edited and the user will have to reload the page before editing the
1195
+ * shortcode.
1196
+ *
1197
+ * @since 2.6.0
1198
+ *
1199
+ * @param array $data The shortcode data to check.
1200
+ *
1201
+ * @return bool True if the shortcode can be edited, false otherwise.
1202
+ */
1203
+ function wfu_check_edit_shortcode($data) {
1204
+ $post = get_post($data['post_id']);
1205
+ /** This filter is described in wfu_loader.php */
1206
+ $content = apply_filters("_wfu_get_post_content", $post->post_content, $post);
1207
+ $hash = hash('md5', $content);
1208
+
1209
+ return ( $hash == $data['post_hash'] );
1210
+ }
1211
+
1212
+ /**
1213
+ * Add Shortcode Inside Post.
1214
+ *
1215
+ * This function adds a shortcode at the beginning of post's contents.
1216
+ *
1217
+ * @since 2.7.6
1218
+ *
1219
+ * @param integer $postid The post ID where to add the shortcode.
1220
+ * $param string $tag The shortcode tag to add in post.
1221
+ *
1222
+ * @return bool True if the shortcode was added successfully inside the post,
1223
+ * false otherwise.
1224
+ */
1225
+ function wfu_add_shortcode($postid, $tag) {
1226
+ /**
1227
+ * Let Custom Scripts Add a Shortcode to Post.
1228
+ *
1229
+ * This filter allows to customize the way that a shortcode is added in a
1230
+ * post / page. It allows to make the plugin compatible with page builders,
1231
+ * like Elementor, that do not handle posts / pages the way Wordpress does.
1232
+ *
1233
+ * @since 4.12.2
1234
+ *
1235
+ * @param integer $postid The post ID where to add the shortcode.
1236
+ * @param string $tag The shortcode tag to add in post.
1237
+ */
1238
+ $result = apply_filters("_wfu_add_shortcode", null, $postid, $tag);
1239
+ if ( $result == null ) {
1240
+ $post = get_post($postid);
1241
+ $new_content = '['.$tag.']'.$post->post_content;
1242
+ $new_post = array( 'ID' => $postid, 'post_content' => $new_content );
1243
+ $result = ( wp_update_post( wfu_slash($new_post) ) === 0 ? false : true );
1244
+ }
1245
+ return $result;
1246
+ }
1247
+
1248
+ /**
1249
+ * Replace Shortcode Inside Post.
1250
+ *
1251
+ * This function replaces a shortcode inside post's contents.
1252
+ *
1253
+ * @since 2.6.0
1254
+ *
1255
+ * @param array $data {
1256
+ * Contains information about the shortcode.
1257
+ *
1258
+ * $type integer $post_id The ID of the post that contains the shortcode.
1259
+ * $type string $post_hash A hash that represents the current post contents.
1260
+ * $type string $shortcode The shortcode string to be replaced.
1261
+ * $type integer $position The position of the shortcode inside post's
1262
+ * contents.
1263
+ * }
1264
+ * $param string $new_shortcode The new shortcode.
1265
+ *
1266
+ * @return bool True if the shortcode was replaced successfully, false
1267
+ * otherwise.
1268
+ */
1269
+ function wfu_replace_shortcode($data, $new_shortcode) {
1270
+ /**
1271
+ * Let Custom Scripts Modify Shortcode Replacement.
1272
+ *
1273
+ * This filter allows to customize the way that a shortcode is replaced. It
1274
+ * allows to make the plugin compatible with page builders, like Elementor,
1275
+ * that do not handle posts / pages the way Wordpress does.
1276
+ *
1277
+ * @since 4.12.2
1278
+ *
1279
+ * @param bool|null $result The result of shortcode replacement. It must be
1280
+ * true if the replacement succeeded, false if it failed or null if
1281
+ * no replacement operation occurred.
1282
+ * @param array $data Contains information about the shortcode.
1283
+ * $param string $new_shortcode The new shortcode.
1284
+ */
1285
+ $result = apply_filters("_wfu_replace_shortcode", null, $data, $new_shortcode);
1286
+ if ( $result == null ) {
1287
+ $post = get_post($data['post_id']);
1288
+ $new_content = substr($post->post_content, 0, $data['position']).$new_shortcode.substr($post->post_content, (int)$data['position'] + strlen($data['shortcode']));
1289
+ $new_post = array( 'ID' => $data['post_id'], 'post_content' => $new_content );
1290
+ $result = ( wp_update_post( wfu_slash($new_post) ) === 0 ? false : true );
1291
+ }
1292
+ return $result;
1293
+ }
1294
+
1295
+ /**
1296
+ * Generate Page for Confirmation of Deletion of Shortcode.
1297
+ *
1298
+ * This function generates the HTML code of the page to ask from the user to
1299
+ * confirm deletion of the selected shortcode.
1300
+ *
1301
+ * @since 2.7.0
1302
+ *
1303
+ * $param string $data_enc Code that represents the shortcode data stored in
1304
+ * safe.
1305
+ *
1306
+ * @return string The HTML code of the deletion confirmation page.
1307
+ */
1308
+ function wfu_delete_shortcode_prompt($data_enc) {
1309
+ $siteurl = site_url();
1310
+ $data = wfu_decode_array_from_string(wfu_get_shortcode_data_from_safe($data_enc));
1311
+ $postid = $data['post_id'];
1312
+ $echo_str = "\n".'<div class="wrap">';
1313
+ $echo_str .= "\n\t".'<h2>Wordpress File Upload Control Panel</h2>';
1314
+ $echo_str .= "\n\t".'<div style="margin-top:20px;">';
1315
+ $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>';
1316
+ $echo_str .= "\n\t".'</div>';
1317
+ $echo_str .= "\n\t".'<h2 style="margin-bottom: 10px; margin-top: 20px;">Delete Shortcode</h2>';
1318
+ $echo_str .= "\n\t".'<form enctype="multipart/form-data" name="deletefile" id="deleteshortcode" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="validate">';
1319
+ $echo_str .= "\n\t\t".'<input type="hidden" name="action" value="deleteshortcode">';
1320
+ $echo_str .= "\n\t\t".'<input type="hidden" name="data" value="'.$data_enc.'">';
1321
+ $echo_str .= "\n\t\t".'<label>Are you sure that you want to delete shortcode for <strong>'.get_post_type($postid).' "'.get_the_title($postid).'" ('.$postid.') Position '.$data['position'].'</strong> ?</label><br/>';
1322
+ $echo_str .= "\n\t\t".'<p class="submit">';
1323
+ $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Delete">';
1324
+ $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Cancel">';
1325
+ $echo_str .= "\n\t\t".'</p>';
1326
+ $echo_str .= "\n\t".'</form>';
1327
+ $echo_str .= "\n".'</div>';
1328
+ return $echo_str;
1329
+ }
1330
+
1331
+ /**
1332
+ * Deletion Shortcode.
1333
+ *
1334
+ * This function deletes a shortcode from page contents.
1335
+ *
1336
+ * @since 2.7.0
1337
+ *
1338
+ * $param array $data Code that represents the shortcode data stored in
1339
+ * safe. See {@see wfu_replace_shortcode()} for a list of supported
1340
+ * arguments.
1341
+ *
1342
+ * @return bool True if deletion succeeded, false otherwise.
1343
+ */
1344
+ function wfu_delete_shortcode($data) {
1345
+ //check if user is allowed to perform this action
1346
+ if ( !current_user_can( 'manage_options' ) ) return false;
1347
+
1348
+ $res = true;
1349
+ if ( isset($_POST['submit']) ) {
1350
+ if ( $_POST['submit'] == "Delete" ) {
1351
+ $res = wfu_replace_shortcode($data, '');
1352
+ }
1353
+ }
1354
+ return $res;
1355
+ }
1356
+
1357
+ /**
1358
+ * Add Custom Properties to Media Editor.
1359
+ *
1360
+ * When "Show Custom Fields in Media Library" option in plugin's Settings is
1361
+ * true then Media Library attachments created by uploaded files will contain
1362
+ * custom fields corresponding to the uploaded files' userdata (if any). This
1363
+ * function shows these custom fields when editing the Media Library attachment.
1364
+ *
1365
+ * @since 3.7.2
1366
+ *
1367
+ * @redeclarable
1368
+ */
1369
+ function wfu_media_editor_properties() {
1370
+ $a = func_get_args(); $a = WFU_FUNCTION_HOOK(__FUNCTION__, $a, $out); if (isset($out['vars'])) foreach($out['vars'] as $p => $v) $$p = $v; switch($a) { case 'R': return $out['output']; break; case 'D': die($out['output']); }
1371
+ $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
1372
+ if ( $plugin_options["mediacustom"] != "1" ) return;
1373
+
1374
+ $post = get_post();
1375
+ $meta = wp_get_attachment_metadata( $post->ID );
1376
+
1377
+ $echo_str = "";
1378
+ if ( isset($meta["WFU User Data"]) && is_array($meta["WFU User Data"]) ) {
1379
+ foreach ( $meta["WFU User Data"] as $label => $value )
1380
+ $echo_str .= '<div class="misc-pub-section misc-pub-userdata">'.$label.': <strong>'.$value.'</strong></div>';
1381
+ }
1382
+ echo $echo_str;
1383
+ }
1384
+
1385
  ?>
lib/wfu_admin_browser.php CHANGED
@@ -1,1659 +1,1659 @@
1
- <?php
2
-
3
- /**
4
- * File Browser Page in Dashboard Area of Plugin
5
- *
6
- * This file contains functions related to File Browser page of plugin's
7
- * Dashboard area.
8
- *
9
- * @link /lib/wfu_admin_browser.php
10
- *
11
- * @package WordPress File Upload Plugin
12
- * @subpackage Core Components
13
- * @since 3.7.1
14
- */
15
-
16
- /**
17
- * Display the File Browser Page.
18
- *
19
- * This function displays the File Browser page of the plugin's Dashboard area.
20
- *
21
- * @since 2.2.1
22
- *
23
- * @param string $basedir_code A code string corresponding to the folder to be
24
- * displayed.
25
- * @param integer $page Optional. The page to display in case folder contents
26
- * are paginated.
27
- * @param bool $only_table_rows Optional. Return only the HTML code of the table
28
- * rows.
29
- *
30
- * @return string The HTML output of the plugin's File Browser Dashboard page.
31
- */
32
- function wfu_browse_files($basedir_code, $page = -1, $only_table_rows = false) {
33
- $siteurl = site_url();
34
- $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
35
- $user = wp_get_current_user();
36
- //store session variables for use from the downloader
37
-
38
- if ( !current_user_can( 'manage_options' ) ) return;
39
-
40
- //first decode basedir_code
41
- $basedir = wfu_get_filepath_from_safe($basedir_code);
42
- //clean session array holding dir and file paths if it is too big
43
- if ( WFU_USVAR_exists('wfu_filepath_safe_storage') && count(WFU_USVAR('wfu_filepath_safe_storage')) > WFU_VAR("WFU_PHP_ARRAY_MAXLEN") ) WFU_USVAR_store('wfu_filepath_safe_storage', array());
44
-
45
- //basedir may also contain information about the sorting of the displayed
46
- //elements, as well as a filename that needs to be located and get focus on
47
- //the browser;
48
- //sorting information is enclosed in double brackets: [[sort_info]]
49
- //filename information is enclosed in double braces: {{filename}}
50
- $sort = "";
51
- $located_file = "";
52
- $located_file_found = false;
53
- $filter = "";
54
- if ( $basedir !== false ) {
55
- $ret = wfu_extract_sortdata_from_path($basedir);
56
- $basedir = $ret['path'];
57
- $sort = $ret['sort'];
58
- $located_file = $ret['file'];
59
- $filter = $ret['filter'];
60
- }
61
- if ( $sort == "" ) $sort = 'name';
62
- if ( substr($sort, 0, 1) == '-' ) $order = SORT_DESC;
63
- else $order = SORT_ASC;
64
- //if page is not -1, then do not locate a file
65
- if ( $located_file != "" && $page > -1 ) $located_file = "";
66
- //adjust page to be larger than zero
67
- if ( $page < 1 ) $page = 1;
68
-
69
- //adjust basedir to have a standard format
70
- if ( $basedir !== false ) {
71
- if ( substr($basedir, -1) != '/' ) $basedir .= '/';
72
- if ( substr($basedir, 0, 1) == '/' ) $basedir = substr($basedir, 1);
73
- //calculate the absolute path of basedir knowing that basedir is relative to website root
74
- $basedir = wfu_path_rel2abs($basedir);
75
- if ( !file_exists($basedir) ) $basedir = false;
76
- }
77
- //set basedit to default value if empty
78
- if ( $basedir === false ) {
79
- $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
80
- $basedir = ( isset($plugin_options['basedir']) ? $plugin_options['basedir'] : "" );
81
- $temp_params = array( 'uploadpath' => $basedir, 'accessmethod' => 'normal', 'ftpinfo' => '', 'useftpdomain' => 'false' );
82
- $basedir = wfu_upload_plugin_full_path($temp_params);
83
- }
84
- //find relative dir
85
- $reldir = str_replace(wfu_abspath(), "root/", $basedir);
86
- //save dir route to an array
87
- $parts = explode('/', $reldir);
88
- $route = array();
89
- $prev = "";
90
- foreach ( $parts as $part ) {
91
- $part = trim($part);
92
- if ( $part != "" ) {
93
- // if ( $part == 'root' && $prev == "" ) $prev = wfu_abspath();
94
- if ( $part == 'root' && $prev == "" ) $prev = "";
95
- else $prev .= $part.'/';
96
- array_push($route, array( 'item' => $part, 'path' => $prev ));
97
- }
98
- }
99
- //calculate upper directory
100
- $updir = substr($basedir, 0, -1);
101
- $delim_pos = strrpos($updir, '/');
102
- if ( $delim_pos !== false ) $updir = substr($updir, 0, $delim_pos + 1);
103
-
104
- //define referer (with sort data) to point to this url for use by the elements
105
- $referer = $siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$basedir_code;
106
- $referer_code = wfu_safe_store_filepath($referer.'[['.$sort.']]');
107
- //define header parameters that can be later used when defining file actions
108
- $header_params = array();
109
-
110
- //find contents of current folder taking into account pagination, if it is
111
- //activated; contents are found following an optimized procedure as follows:
112
- // 1. all dirs and files are found and stored in separate arrays
113
- // 2. if pagination is activated then it is checked if there are any dirs
114
- // in the current page
115
- // 3. if dir sorting is name then dirs are sorted
116
- // 4. if dir sorting is date then stat is called for all dirs and then they
117
- // are sorted
118
- // 5. if pagination is activated then dirs array is sliced to keep only the
119
- // ones belonging to the current page and then stat is called if it has
120
- // not already been called
121
- // 6. if there is room in the page for showing files, then files are also
122
- // processed
123
- // 7. if file sorting is name then files are sorted
124
- // 8. if file sorting is date or size then stat is called for all files and
125
- // then they are sorted
126
- // 9. if file sorting is user then db record is retrieved for all files and
127
- // then they are sorted
128
- // 10. if pagination is activated then files array is sliced to keep only
129
- // the ones fitting in the page; then stat is called and/or db record is
130
- // retrieved
131
- //first calculate dirs and files arrays
132
- $dirlist = array();
133
- $dirlist_include = true;
134
- $dirlist_perpage = array();
135
- $dirstat_ok = false;
136
- $filelist = array();
137
- $filestat_ok = false;
138
- $filerec_ok = false;
139
- if ( $handle = opendir($basedir) ) {
140
- $blacklist = array('.', '..');
141
- while ( false !== ($file = readdir($handle)) )
142
- if ( !in_array($file, $blacklist) ) {
143
- $filepath = $basedir.$file;
144
- if ( is_dir($filepath) ) array_push($dirlist, array( 'name' => $file, 'fullpath' => $filepath ));
145
- else array_push($filelist, array( 'name' => $file, 'fullpath' => $filepath ));
146
- }
147
- closedir($handle);
148
- }
149
- $dirlist_count = count($dirlist);
150
- $filelist_count = count($filelist);
151
- //get pagination details and determine if any dirs will be shown
152
- $maxrows = (int)WFU_VAR("WFU_ADMINBROWSER_TABLE_MAXROWS");
153
- $files_total = $dirlist_count + $filelist_count;
154
- if ( $maxrows > 0 ) {
155
- $pages = max(ceil($files_total / $maxrows), 1);
156
- if ( $page > $pages ) $page = $pages;
157
- //if first item index passes number of dirs then do not include dirs
158
- if ( ($page - 1) * $maxrows >= $dirlist_count ) $dirlist_include = false;
159
- //if a filename has been defined to get focus, then $dirlist_include
160
- //needs to be true in order to calculate the dirs of every page
161
- if ( $located_file != "" ) $dirlist_include = true;
162
- }
163
- //process dirs if they are included in page
164
- if ( $dirlist_include ) {
165
- //adjust sort details
166
- $dirsort = ( substr($sort, -4) == 'date' ? 'mdate' : substr($sort, -4) );
167
- $dirorder = $order;
168
- if ( $dirsort == 'size' ) { $dirsort = 'name'; $dirorder = SORT_ASC; }
169
- if ( $dirsort == 'user' ) { $dirsort = 'name'; $dirorder = SORT_ASC; }
170
- switch ( $dirsort ) {
171
- case "name": $dirsort .= ":s"; break;
172
- case "mdate": $dirsort .= ":n"; break;
173
- }
174
- //if dir sort is mdate or if a file needs to be located then first
175
- //calculate stat
176
- if ( substr($dirsort, 0, 5) == 'mdate' || $located_file != "" ) {
177
- foreach ( $dirlist as &$dir ) {
178
- $stat = stat($dir['fullpath']);
179
- $dir['mdate'] = $stat['mtime'];
180
- }
181
- unset($dir);
182
- $dirstat_ok = true;
183
- }
184
- //sort dirs
185
- $dirlist = wfu_array_sort($dirlist, $dirsort, $dirorder);
186
- //if pagination is activated then slice dirs array to keep only the
187
- //items belonging in the current page
188
- if ( $maxrows > 0 ) {
189
- //before slicing we store the items in $dirlist_perpage array
190
- $i = $maxrows;
191
- $ipage = 0;
192
- foreach ( $dirlist as $dir ) {
193
- if ( $i >= $maxrows ) {
194
- $i = 0;
195
- $ipage ++;
196
- $dirlist_perpage[$ipage] = array();
197
- }
198
- array_push($dirlist_perpage[$ipage], $dir);
199
- $i ++;
200
- }
201
- //now we slice $dirlist
202
- $dirlist = array_slice($dirlist, ($page - 1) * $maxrows, $maxrows);
203
- }
204
- //calculate stat for the remaining dirs array, if it has not already
205
- //been done
206
- if ( !$dirstat_ok ) {
207
- foreach ( $dirlist as &$dir ) {
208
- $stat = stat($dir['fullpath']);
209
- $dir['mdate'] = $stat['mtime'];
210
- }
211
- unset($dir);
212
- }
213
- }
214
- else $dirlist = array();
215
- //determine if any files will be included in page; in case pagination is
216
- //activated then the remaining places need to be more than zero
217
- $files_included = ( $maxrows > 0 ? ( $maxrows - count($dirlist) > 0 ) : true );
218
- //if a filename has been defined to get focus, then $files_included
219
- //needs to be true in order to re-calculate the page
220
- if ( $located_file != "" ) $files_included = true;
221
- if ( $files_included ) {
222
- //adjust sort details
223
- $filesort = ( substr($sort, -4) == 'date' ? 'mdate' : substr($sort, -4) );
224
- switch ( $filesort ) {
225
- case "name": $filesort .= ":s"; break;
226
- case "size": $filesort .= ":n"; break;
227
- case "mdate": $filesort .= ":n"; break;
228
- case "user": $filesort .= ":s"; break;
229
- }
230
- //if file sort is size or mdate then first calculate stat
231
- if ( substr($filesort, 0, 4) == 'size' || substr($filesort, 0, 5) == 'mdate' ) {
232
- foreach ( $filelist as &$file ) {
233
- $stat = stat($file['fullpath']);
234
- $file['size'] = $stat['size'];
235
- $file['mdate'] = $stat['mtime'];
236
- }
237
- unset($file);
238
- $filestat_ok = true;
239
- }
240
- //if file sort is user then first calculate db records
241
- elseif ( substr($filesort, 0, 4) == 'user' ) {
242
- foreach ( $filelist as &$file ) {
243
- //find relative file record in database together with user data;
244
- //if the file is php, then file record is null meaning that the file
245
- //can only be viewed; if file record is not found then the file can
246
- //again only be viewed
247
- if ( preg_match("/\.php$/", $file['fullpath']) ) $filerec = null;
248
- else $filerec = wfu_get_file_rec($file['fullpath'], true);
249
- //find user who uploaded the file
250
- $username = ( $filerec != null ? wfu_get_username_by_id($filerec->uploaduserid) : '' );
251
- $file['user'] = $username;
252
- $file['filedata'] = $filerec;
253
- }
254
- unset($file);
255
- $filerec_ok = true;
256
- }
257
- //sort files
258
- $filelist = wfu_array_sort($filelist, $filesort, $order);
259
- //if pagination is activated and a file needs to receive focus, then we
260
- //need to calculate the page where the file is shown
261
- if ( $maxrows > 0 && $located_file != "" ) {
262
- $i = $dirlist_count;
263
- foreach ( $filelist as $key => $file ) {
264
- if ( $file['name'] == $located_file ) {
265
- $located_file_found = true;
266
- $filelist[$key]['highlighted'] = 1;
267
- break;
268
- }
269
- $i ++;
270
- }
271
- if ( $located_file_found ) {
272
- $page = floor( $i / $maxrows ) + 1;
273
- if ( isset($dirlist_perpage[$page]) ) $dirlist = $dirlist_perpage[$page];
274
- else $dirlist = array();
275
- }
276
- }
277
- //if pagination is activated then slice files array to keep only the items
278
- //belonging in the current page
279
- if ( $maxrows > 0 )
280
- $filelist = array_slice($filelist, max(($page - 1) * $maxrows - $dirlist_count, 0), $maxrows - count($dirlist));
281
- if ( !$filestat_ok || !$filerec_ok ) {
282
- foreach ( $filelist as &$file ) {
283
- if ( !$filestat_ok ) {
284
- $stat = stat($file['fullpath']);
285
- $file['size'] = $stat['size'];
286
- $file['mdate'] = $stat['mtime'];
287
- }
288
- if ( !$filerec_ok ) {
289
- if ( preg_match("/\.php$/", $file['fullpath']) ) $filerec = null;
290
- else $filerec = wfu_get_file_rec($file['fullpath'], true);
291
- $username = ( $filerec != null ? wfu_get_username_by_id($filerec->uploaduserid) : '' );
292
- $file['user'] = $username;
293
- $file['filedata'] = $filerec;
294
- }
295
- }
296
- unset($file);
297
- }
298
- }
299
- else $filelist = array();
300
-
301
- //start html output
302
- $echo_str = "";
303
- if ( !$only_table_rows ) {
304
- $echo_str .= "\n".'<div class="wrap">';
305
- $echo_str .= "\n\t".'<h2>Wordpress File Upload Control Panel</h2>';
306
- $echo_str .= "\n\t".'<div style="margin-top:20px;">';
307
- $echo_str .= wfu_generate_dashboard_menu("\n\t\t", "File Browser");
308
- $echo_str .= "\n\t".'<div>';
309
- $echo_str .= "\n\t\t".'<span><strong>Location:</strong> </span>';
310
- foreach ( $route as $item ) {
311
- // store dir path that we need to pass to other functions in session, instead of exposing it in the url
312
- $dir_code = wfu_safe_store_filepath($item['path']);
313
- $echo_str .= '<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code.'">'.$item['item'].'</a>';
314
- $echo_str .= '<span>/</span>';
315
- }
316
- //file browser header
317
- $echo_str .= "\n\t".'</div>';
318
- // $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.$sort.']]');
319
- // $echo_str .= "\n\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=create_dir&dir='.$dir_code.'" class="button" title="create folder" style="margin-top:6px">Create folder</a>';
320
- $echo_str .= "\n\t".'<div style="margin-top:10px; position:relative;">';
321
- $echo_str .= wfu_add_loading_overlay("\n\t\t", "adminbrowser");
322
- $adminbrowser_nonce = wp_create_nonce( 'wfu-adminbrowser-page' );
323
- $echo_str .= "\n\t\t".'<div class="wfu_adminbrowser_header" style="width: 100%;">';
324
- $bulkactions = array(
325
- array( "name" => "move", "title" => "Move" ),
326
- array( "name" => "delete", "title" => "Delete" ),
327
- array( "name" => "include", "title" => "Include" )
328
- );
329
- $echo_str .= wfu_add_bulkactions_header("\n\t\t\t", "adminbrowser", $bulkactions);
330
- if ( $maxrows > 0 ) {
331
- $echo_str .= wfu_add_pagination_header("\n\t\t\t", "adminbrowser", $page, $pages, $adminbrowser_nonce);
332
- }
333
- $echo_str .= "\n\t\t\t".'<input id="wfu_adminbrowser_action_url" type="hidden" value="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" />';
334
- $echo_str .= "\n\t\t\t".'<input id="wfu_adminbrowser_code" type="hidden" value="'.$basedir_code.'" />';
335
- $echo_str .= "\n\t\t\t".'<input id="wfu_adminbrowser_referer" type="hidden" value="'.$referer_code.'" />';
336
- $echo_str .= "\n\t\t\t".'<input id="wfu_download_file_nonce" type="hidden" value="'.wp_create_nonce('wfu_download_file_invoker').'" />';
337
- $echo_str .= "\n\t\t\t".'<input id="wfu_include_file_nonce" type="hidden" value="'.wp_create_nonce('wfu_include_file').'" />';
338
- $echo_str .= "\n\t\t".'</div>';
339
- $echo_str .= "\n\t\t".'<table id="wfu_adminbrowser_table" class="wfu-adminbrowser wp-list-table widefat fixed striped">';
340
- $echo_str .= "\n\t\t\t".'<thead>';
341
- $echo_str .= "\n\t\t\t\t".'<tr>';
342
- $echo_str .= "\n\t\t\t\t\t".'<td scope="col" width="5%" class="manage-column check-column">';
343
- $echo_str .= "\n\t\t\t\t\t\t".'<input id="wfu_select_all_visible" type="checkbox" onchange="wfu_adminbrowser_select_all_visible_changed();" style="-webkit-appearance:checkbox;" />';
344
- $echo_str .= "\n\t\t\t\t\t".'</td>';
345
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="25%" class="manage-column column-primary">';
346
- $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.( substr($sort, -4) == 'name' ? ( $order == SORT_ASC ? '-name' : 'name' ) : 'name' ).']]');
347
- $echo_str .= "\n\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code.'">Name'.( substr($sort, -4) == 'name' ? ( $order == SORT_ASC ? ' &uarr;' : ' &darr;' ) : '' ).'</a>';
348
- $echo_str .= "\n\t\t\t\t\t".'</th>';
349
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column">';
350
- $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.( substr($sort, -4) == 'size' ? ( $order == SORT_ASC ? '-size' : 'size' ) : 'size' ).']]');
351
- $echo_str .= "\n\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code.'">Size'.( substr($sort, -4) == 'size' ? ( $order == SORT_ASC ? ' &uarr;' : ' &darr;' ) : '' ).'</a>';
352
- $echo_str .= "\n\t\t\t\t\t".'</th>';
353
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="20%" class="manage-column">';
354
- $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.( substr($sort, -4) == 'date' ? ( $order == SORT_ASC ? '-date' : 'date' ) : 'date' ).']]');
355
- $echo_str .= "\n\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code.'">Date'.( substr($sort, -4) == 'date' ? ( $order == SORT_ASC ? ' &uarr;' : ' &darr;' ) : '' ).'</a>';
356
- $echo_str .= "\n\t\t\t\t\t".'</th>';
357
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column">';
358
- $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.( substr($sort, -4) == 'user' ? ( $order == SORT_ASC ? '-user' : 'user' ) : 'user' ).']]');
359
- $echo_str .= "\n\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code.'">Uploaded By'.( substr($sort, -4) == 'user' ? ( $order == SORT_ASC ? ' &uarr;' : ' &darr;' ) : '' ).'</a>';
360
- $echo_str .= "\n\t\t\t\t\t".'</th>';
361
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="30%" class="manage-column">';
362
- $echo_str .= "\n\t\t\t\t\t\t".'<label>User Data</label>';
363
- $echo_str .= "\n\t\t\t\t\t".'</th>';
364
- $echo_str .= "\n\t\t\t\t".'</tr>';
365
- $echo_str .= "\n\t\t\t".'</thead>';
366
- $echo_str .= "\n\t\t\t".'<tbody>';
367
- }
368
-
369
- //show subfolders first
370
- if ( $reldir != "root/" ) {
371
- $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($updir));
372
- $echo_str .= "\n\t\t\t\t".'<tr>';
373
- $echo_str .= "\n\t\t\t\t\t".'<th class="check-column"><input type="checkbox" disabled="disabled" /></th>';
374
- $echo_str .= "\n\t\t\t\t\t".'<td class="column-primary" data-colname="Name">';
375
- $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_browser&dir='.$dir_code.'" title="go up">..</a>';
376
- $echo_str .= "\n\t\t\t\t\t".'</td>';
377
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Size"> </td>';
378
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Date"> </td>';
379
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Uploaded By"> </td>';
380
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="User Data"> </td>';
381
- $echo_str .= "\n\t\t\t\t".'</tr>';
382
- }
383
- $ii = 1;
384
- foreach ( $dirlist as $dir ) {
385
- $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($dir['fullpath']).'[['.$sort.']]');
386
- $echo_str .= "\n\t\t\t\t".'<tr onmouseover="var actions=document.getElementsByName(\'wfu_dir_actions\'); for (var i=0; i<actions.length; i++) {actions[i].style.visibility=\'hidden\';} document.getElementById(\'wfu_dir_actions_'.$ii.'\').style.visibility=\'visible\'" onmouseout="var actions=document.getElementsByName(\'wfu_dir_actions\'); for (var i=0; i<actions.length; i++) {actions[i].style.visibility=\'hidden\';}">';
387
- $echo_str .= "\n\t\t\t\t\t".'<th class="check-column"><input type="checkbox" disabled="disabled" /></th>';
388
- $echo_str .= "\n\t\t\t\t\t".'<td class="column-primary" data-colname="Name">';
389
- $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_browser&dir='.$dir_code.'" title="'.$dir['name'].'">'.$dir['name'].'</a>';
390
- $echo_str .= "\n\t\t\t\t\t\t".'<div id="wfu_dir_actions_'.$ii.'" name="wfu_dir_actions" style="visibility:hidden;">';
391
- $echo_str .= "\n\t\t\t\t\t\t\t".'<span style="visibility:hidden;">';
392
- $echo_str .= "\n\t\t\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir=">Noaction</a>';
393
- $echo_str .= "\n\t\t\t\t\t\t\t\t".' | ';
394
- $echo_str .= "\n\t\t\t\t\t\t\t".'</span>';
395
- // $echo_str .= "\n\t\t\t\t\t\t\t".'<span>';
396
- // $echo_str .= "\n\t\t\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=rename_dir&file='.$dir_code.'" title="Rename this folder">Rename</a>';
397
- // $echo_str .= "\n\t\t\t\t\t\t\t\t".' | ';
398
- // $echo_str .= "\n\t\t\t\t\t\t\t".'</span>';
399
- // $echo_str .= "\n\t\t\t\t\t\t\t".'<span>';
400
- // $echo_str .= "\n\t\t\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=delete_dir&file='.$dir_code.'" title="Delete this folder">Delete</a>';
401
- // $echo_str .= "\n\t\t\t\t\t\t\t".'</span>';
402
- $echo_str .= "\n\t\t\t\t\t\t".'</div>';
403
- $echo_str .= "\n\t\t\t\t\t\t".'<button type="button" class="toggle-row"><span class="screen-reader-text">Show more details</span></button>';
404
- $echo_str .= "\n\t\t\t\t\t".'</td>';
405
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Size"> </td>';
406
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Date">'.get_date_from_gmt(date("Y-m-d H:i:s", $dir['mdate']), "d/m/Y H:i:s").'</td>';
407
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Uploaded By"> </td>';
408
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="User Data"> </td>';
409
- $echo_str .= "\n\t\t\t\t".'</tr>';
410
- $ii ++;
411
- }
412
- //show contained files
413
- foreach ( $filelist as $file ) {
414
- $is_included = ( $file['filedata'] != null );
415
- $can_be_included = ( $plugin_options['includeotherfiles'] == "1" ) && !wfu_file_extension_blacklisted($file['name']);
416
- $highlighted = ( isset($file['highlighted']) && $file['highlighted'] == 1 );
417
- $file_code = '';
418
- if ( $is_included || $can_be_included ) $file_code = wfu_safe_store_filepath(wfu_path_abs2rel($file['fullpath']).'[['.$sort.']]');
419
- $echo_str .= "\n\t\t\t\t".'<tr '.( $highlighted ? 'class="wfu-highlighted" ' : '' ).'onmouseover="var actions=document.getElementsByName(\'wfu_file_actions\'); for (var i=0; i<actions.length; i++) {actions[i].style.visibility=\'hidden\';} document.getElementById(\'wfu_file_actions_'.$ii.'\').style.visibility=\'visible\'" onmouseout="var actions=document.getElementsByName(\'wfu_file_actions\'); for (var i=0; i<actions.length; i++) {actions[i].style.visibility=\'hidden\';}">';
420
- $echo_str .= "\n\t\t\t\t\t".'<th class="check-column">';
421
- if ( $is_included || $can_be_included ) $echo_str .= "\n\t\t\t\t\t\t".'<input class="wfu_selectors'.( $is_included ? ' wfu_included' : '' ).' wfu_selcode_'.$file_code.'" type="checkbox" onchange="wfu_adminbrowser_selector_changed(this);" />';
422
- else $echo_str .= "\n\t\t\t\t\t\t".'<input type="checkbox" disabled="disabled" />';
423
- $echo_str .= "\n\t\t\t\t\t".'</th>';
424
- $echo_str .= "\n\t\t\t\t\t".'<td class="column-primary" data-colname="Name">';
425
- if ( $is_included || $can_be_included )
426
- $echo_str .= "\n\t\t\t\t\t\t".'<a id="wfu_file_link_'.$ii.'" class="row-title" href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_details&file='.$file_code.'" title="View and edit file details" style="font-weight:normal;'.( $is_included ? '' : ' display:none;' ).'">'.$file['name'].'</a>';
427
- if ( !$is_included )
428
- $echo_str .= "\n\t\t\t\t\t\t".'<span id="wfu_file_flat_'.$ii.'">'.$file['name'].'</span>';
429
- //set additional $file properties for generating file actions
430
- $file["index"] = $ii;
431
- $file["code"] = $file_code;
432
- $file["referer_code"] = $referer_code;
433
- $file_actions = wfu_adminbrowser_file_actions($file, $header_params);
434
- $echo_str .= "\n\t\t\t\t\t\t".'<div id="wfu_file_actions_'.$ii.'" name="wfu_file_actions" style="visibility:hidden;">';
435
- if ( $is_included || $can_be_included ) {
436
- $echo_str .= "\n\t\t\t\t\t\t\t".'<div id="wfu_file_is_included_actions_'.$ii.'" style="display:'.( $is_included ? 'block' : 'none' ).';">';
437
- //add file actions for files already included
438
- $array_keys = array_keys($file_actions["is_included"]);
439
- $lastkey = array_pop($array_keys);
440
- foreach ( $file_actions["is_included"] as $key => $action ) {
441
- $echo_str .= "\n\t\t\t\t\t\t\t\t".'<span>';
442
- foreach ( $action as $line )
443
- $echo_str .= "\n\t\t\t\t\t\t\t\t\t".$line;
444
- if ( $key != $lastkey ) $echo_str .= "\n\t\t\t\t\t\t\t\t\t".' | ';
445
- $echo_str .= "\n\t\t\t\t\t\t\t\t".'</span>';
446
- }
447
- $echo_str .= "\n\t\t\t\t\t\t\t".'</div>';
448
- $echo_str .= "\n\t\t\t\t\t\t\t".'<div id="wfu_file_can_be_included_actions_'.$ii.'" style="display:'.( $is_included ? 'none' : 'block' ).';">';
449
- //add file actions for files that can be included
450
- $array_keys = array_keys($file_actions["can_be_included"]);
451
- $lastkey = array_pop($array_keys);
452
- foreach ( $file_actions["can_be_included"] as $key => $action ) {
453
- $echo_str .= "\n\t\t\t\t\t\t\t\t".'<span>';
454
- foreach ( $action as $line )
455
- $echo_str .= "\n\t\t\t\t\t\t\t\t\t".$line;
456
- if ( $key != $lastkey ) $echo_str .= "\n\t\t\t\t\t\t\t\t\t".' | ';
457
- $echo_str .= "\n\t\t\t\t\t\t\t\t".'</span>';
458
- }
459
- $echo_str .= "\n\t\t\t\t\t\t\t".'</div>';
460
- }
461
- else {
462
- $echo_str .= "\n\t\t\t\t\t\t\t".'<span style="visibility:hidden;">';
463
- $echo_str .= "\n\t\t\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir=">Noaction</a>';
464
- $echo_str .= "\n\t\t\t\t\t\t\t\t".' | ';
465
- $echo_str .= "\n\t\t\t\t\t\t\t".'</span>';
466
- }
467
- $echo_str .= "\n\t\t\t\t\t\t".'</div>';
468
- $echo_str .= "\n\t\t\t\t\t\t".'<div id="wfu_file_download_container_'.$ii.'" style="display: none;"></div>';
469
- $echo_str .= "\n\t\t\t\t\t\t".'<button type="button" class="toggle-row"><span class="screen-reader-text">Show more details</span></button>';
470
- $echo_str .= "\n\t\t\t\t\t".'</td>';
471
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Size">'.$file['size'].'</td>';
472
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Date">'.get_date_from_gmt(date("Y-m-d H:i:s", $file['mdate']), "d/m/Y H:i:s").'</td>';
473
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Uploaded By">'.$file['user'].'</td>';
474
- $echo_str .= "\n\t\t\t\t\t".'<td data-colname="User Data">';
475
- if ( $is_included ) {
476
- if ( is_array($file['filedata']->userdata) && count($file['filedata']->userdata) > 0 ) {
477
- $echo_str .= "\n\t\t\t\t\t\t".'<select multiple="multiple" style="width:100%; height:40px; background:none; font-size:small;">';
478
- foreach ( $file['filedata']->userdata as $userdata )
479
- $echo_str .= "\n\t\t\t\t\t\t\t".'<option>'.$userdata->property.': '.$userdata->propvalue.'</option>';
480
- $echo_str .= "\n\t\t\t\t\t\t".'</select>';
481
- }
482
- }
483
- $echo_str .= "\n\t\t\t\t\t".'</td>';
484
- $echo_str .= "\n\t\t\t\t".'</tr>';
485
- $ii ++;
486
- }
487
-
488
- if ( !$only_table_rows ) {
489
- $echo_str .= "\n\t\t\t".'</tbody>';
490
- $echo_str .= "\n\t\t".'</table>';
491
- $echo_str .= "\n\t\t".'<iframe id="wfu_download_frame" style="display: none;"></iframe>';
492
- $echo_str .= "\n\t".'</div>';
493
- $echo_str .= "\n\t".'</div>';
494
- $echo_str .= "\n".'</div>';
495
- }
496
- if ( $located_file_found ) {
497
- $handler = 'function() { wfu_focus_table_on_highlighted_file("wfu_adminbrowser_table"); }';
498
- $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>';
499
- }
500
-
501
- return $echo_str;
502
- }
503
-
504
- /**
505
- * Add Actions to Displayed Files.
506
- *
507
- * This function sets the actions that can be applied on the displayed files.
508
- * Filters can customize these actions.
509
- *
510
- * @since 4.1.0
511
- *
512
- * @param array $file An array containing properties of the file.
513
- * @param array $params An array of custom parameters to pass to file actions
514
- * filter.
515
- *
516
- * @return array An array of actions that can be executed on the file.
517
- */
518
- function wfu_adminbrowser_file_actions($file, $params) {
519
- $siteurl = site_url();
520
- $actions = array(
521
- "is_included" => array(),
522
- "can_be_included" => array()
523
- );
524
- //add file actions if file is already included
525
- $actions["is_included"] += array(
526
- array( '<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_details&file='.$file["code"].'" title="View and edit file details">Details</a>' ),
527
- array( '<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=rename_file&file='.$file["code"].'" title="Rename this file">Rename</a>' ),
528
- array( '<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=move_file&file='.$file["code"].'" title="Move this file">Move</a>' ),
529
- array( '<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=delete_file&file='.$file["code"].'&referer='.$file["referer_code"].'" title="Delete this file">Delete</a>' ),
530
- array( '<a href="javascript:wfu_download_file(\''.$file["code"].'\', '.$file["index"].');" title="Download this file">Download</a>' )
531
- );
532
- //add file actions if file can be included
533
- $actions["can_be_included"] += array(
534
- array(
535
- '<a id="wfu_include_file_'.$file["index"].'_a" href="javascript:wfu_include_file(\''.$file["code"].'\', '.$file["index"].');" title="Include file in plugin\'s database">Include File</a>',
536
- '<img id="wfu_include_file_'.$file["index"].'_img" src="'.WFU_IMAGE_ADMIN_SUBFOLDER_LOADING.'" style="width:12px; display:none;" />',
537
- '<input id="wfu_include_file_'.$file["index"].'_inpfail" type="hidden" value="File could not be included!" />'
538
- )
539
- );
540
-
541
- return $actions;
542
- }
543
-
544
- /**
545
- * Check if User Owns a File.
546
- *
547
- * This function checks if a user is the owner of a specific file. It will
548
- * return true if the user in an administrator.
549
- *
550
- * @since 3.8.5
551
- *
552
- * @param integer $userid The ID of the user to check.
553
- * @param object $filerec The database record of the file.
554
- *
555
- * @return bool True if the user owns the file, false otherwise.
556
- */
557
- function wfu_user_owns_file($userid, $filerec) {
558
- if ( 0 == $userid )
559
- return false;
560
- if ( current_user_can('manage_options') ) return true;
561
- return false;
562
- }
563
-
564
- /**
565
- * Check if Current User Owns a File.
566
- *
567
- * This function checks if the current user is the owner of a specific file. It
568
- * will first check if the file extension is valid.
569
- *
570
- * @since 3.0.0
571
- *
572
- * @param string $filepath The full path of the file to check.
573
- * @param object $filerec Optional. The db record of the file, if available.
574
- *
575
- * @return bool True if the user owns the file, false otherwise.
576
- */
577
- function wfu_current_user_owes_file($filepath, $filerec = null) {
578
- //first check if file has a restricted extension; for security reasons some
579
- //file extensions cannot be owned
580
- if ( wfu_file_extension_blacklisted($filepath) ) return false;
581
- //then get file data from database, if exist
582
- if ( $filerec == null ) $filerec = wfu_get_file_rec($filepath, false);
583
- if ( $filerec == null ) return false;
584
-
585
- $user = wp_get_current_user();
586
- return wfu_user_owns_file($user->ID, $filerec);
587
- }
588
-
589
- /**
590
- * Check if Current User is Allowed to Execute an Action on a File.
591
- *
592
- * This function checks if the current user is allowed to execute a specific
593
- * action on a file.
594
- *
595
- * @since 2.4.1
596
- *
597
- * @param string $action A file action to check.
598
- * @param string $filepath The full path of the file to check.
599
- *
600
- * @return object|null Returns the current WP_User object if current user is
601
- * allowed to execute the action on the file or null otherwise.
602
- */
603
- function wfu_current_user_allowed_action($action, $filepath) {
604
- //first get file data from database, if exist
605
- $filerec = wfu_get_file_rec($filepath, false);
606
-
607
- $user = wp_get_current_user();
608
- if ( 0 == $user->ID ) return null;
609
- else $is_admin = current_user_can('manage_options');
610
- if ( !$is_admin ) {
611
- return null;
612
- }
613
- return $user;
614
- }
615
-
616
- /**
617
- * Check if User is Allowed to Execute an Action on a File.
618
- *
619
- * This function checks if a user is allowed to execute a specific action on a
620
- * file.
621
- *
622
- * @since 2.6.0
623
- *
624
- * @param string $action A file action to check.
625
- * @param string $filepath The full path of the file to check.
626
- * @param integer $userid The ID of the user to check.
627
- *
628
- * @return bool|null Returns true if current user is allowed to execute the
629
- * action on the file or null otherwise.
630
- */
631
- function wfu_current_user_allowed_action_remote($action, $filepath, $userid) {
632
- //first get file data from database, if exist
633
- $filerec = wfu_get_file_rec($filepath, false);
634
-
635
- if ( 0 == $userid ) return null;
636
- else $is_admin = user_can($userid, 'manage_options');
637
- if ( !$is_admin ) {
638
- return null;
639
- }
640
- return true;
641
- }
642
-
643
- /**
644
- * Confirm Renaming of File.
645
- *
646
- * This function shows a page to confirm renaming of a file.
647
- *
648
- * @since 2.2.1
649
- *
650
- * @param string $file_code A code corresponding to the file/dir to be renamed.
651
- * @param string $type Rename dir or file. Can take the values 'dir' or 'file'.
652
- * @param string $error An error message to show on top of the page in case an
653
- * error occured during renaming.
654
- *
655
- * @return string The HTML code of the confirmation page.
656
- */
657
- function wfu_rename_file_prompt($file_code, $type, $error) {
658
- if ( $type == 'dir' ) return;
659
-
660
- $siteurl = site_url();
661
-
662
- $is_admin = current_user_can( 'manage_options' );
663
- //check if user is allowed to view file details
664
- if ( !$is_admin ) {
665
- return;
666
- }
667
- $file_code = wfu_sanitize_code($file_code);
668
- $dec_file = wfu_get_filepath_from_safe($file_code);
669
- if ( $dec_file === false ) return;
670
-
671
- //first extract sort info from dec_file
672
- $ret = wfu_extract_sortdata_from_path($dec_file);
673
- $dec_file = wfu_path_rel2abs($ret['path']);
674
- if ( $type == 'dir' && substr($dec_file, -1) == '/' ) $dec_file = substr($dec_file, 0, -1);
675
-
676
- //check if user is allowed to perform this action
677
- if ( !wfu_current_user_owes_file($dec_file) ) return;
678
-
679
- $parts = pathinfo($dec_file);
680
- $newname = $parts['basename'];
681
- $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($parts['dirname']).'[['.$ret['sort'].']]');
682
-
683
- $echo_str = "\n".'<div class="wrap">';
684
- if ( $error ) {
685
- $rename_file = WFU_USVAR('wfu_rename_file');
686
- $newname = $rename_file['newname'];
687
- $echo_str .= "\n\t".'<div class="error">';
688
- $echo_str .= "\n\t\t".'<p>'.WFU_USVAR('wfu_rename_file_error').'</p>';
689
- $echo_str .= "\n\t".'</div>';
690
- }
691
- $echo_str .= "\n\t".'<div style="margin-top:20px;">';
692
- if ( $is_admin ) $echo_str .= "\n\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=file_browser&dir='.$dir_code.'" class="button" title="go back">Go back</a>';
693
- $echo_str .= "\n\t".'</div>';
694
- $echo_str .= "\n\t".'<h2 style="margin-bottom: 10px;">Rename '.( $type == 'dir' ? 'Folder' : 'File' ).'</h2>';
695
- if ( $is_admin ) $echo_str .= "\n\t".'<form enctype="multipart/form-data" name="renamefile" id="renamefile" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="validate">';
696
- $echo_str .= "\n\t\t".'<input type="hidden" name="action" value="rename'.( $type == 'dir' ? 'dir' : 'file' ).'">';
697
- $echo_str .= "\n\t\t".'<input type="hidden" name="dir" value="'.$dir_code.'">';
698
- $echo_str .= "\n\t\t".'<input type="hidden" name="file" value="'.$file_code.'">';
699
- if ( $type == 'dir' ) $echo_str .= "\n\t\t".'<label>Enter new name for folder <strong>'.$dec_file.'</strong></label><br/>';
700
- elseif ( $is_admin ) $echo_str .= "\n\t\t".'<label>Enter new filename for file <strong>'.$dec_file.'</strong></label><br/>';
701
- $echo_str .= "\n\t\t".'<input name="wfu_newname" id="wfu_newname" type="text" value="'.$newname.'" style="width:50%;" />';
702
- $echo_str .= "\n\t\t".'<p class="submit">';
703
- $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Rename">';
704
- $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Cancel">';
705
- $echo_str .= "\n\t\t".'</p>';
706
- $echo_str .= "\n\t".'</form>';
707
- $echo_str .= "\n".'</div>';
708
- return $echo_str;
709
- }
710
-
711
- /**
712
- * Confirm Moving of File.
713
- *
714
- * This function shows a page to confirm moving of a file to a new location.
715
- *
716
- * @since 4.10.3
717
- *
718
- * @param string $file_code A code corresponding to the file to be moved.
719
- * @param string $error An error message to show on top of the page in case an
720
- * error occured during move.
721
- *
722
- * @return string The HTML code of the confirmation page.
723
- */
724
- function wfu_move_file_prompt($file_code, $error) {
725
- $siteurl = site_url();
726
-
727
- $is_admin = current_user_can( 'manage_options' );
728
- //check if user is allowed to view file details
729
- if ( !$is_admin ) return;
730
-
731
- if ( !is_array($file_code) ) $file_code = array( $file_code );
732
- $names = array();
733
- foreach ( $file_code as $index => $code ) {
734
- $file_code[$index] = wfu_sanitize_code($code);
735
- $dec_file = wfu_get_filepath_from_safe($file_code[$index]);
736
- if ( $dec_file === false ) unset($file_code[$index]);
737
- else {
738
- //first extract sort info from dec_file
739
- $ret = wfu_extract_sortdata_from_path($dec_file);
740
- $dec_file = $ret['path'];
741
- $parts = pathinfo($dec_file);
742
- array_push($names, $parts['basename']);
743
- }
744
- }
745
- if ( count($file_code) == 0 ) return;
746
- $file_code_list = "list:".implode(",", $file_code);
747
-
748
- $newpath = $parts['dirname'];
749
- $replacefiles = "";
750
- $dir_code = wfu_safe_store_filepath($parts['dirname'].'[['.$ret['sort'].']]');
751
-
752
- $echo_str = "\n".'<div class="wrap">';
753
- if ( $error ) {
754
- $move_file = WFU_USVAR('wfu_move_file');
755
- $newpath = $move_file['newpath'];
756
- $replacefiles = $move_file['replacefiles'];
757
- $echo_str .= "\n\t".'<div class="error">';
758
- $echo_str .= "\n\t\t".'<p>'.WFU_USVAR('wfu_move_file_error').'</p>';
759
- $echo_str .= "\n\t".'</div>';
760
- }
761
- $echo_str .= "\n\t".'<div style="margin-top:20px;">';
762
- $echo_str .= "\n\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=file_browser&dir='.$dir_code.'" class="button" title="go back">Go back</a>';
763
- $echo_str .= "\n\t".'</div>';
764
- $echo_str .= "\n\t".'<h2 style="margin-bottom: 10px;">Move File</h2>';
765
- $echo_str .= "\n\t".'<form enctype="multipart/form-data" name="movefile" id="movefile" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="validate">';
766
- $echo_str .= "\n\t\t".'<input type="hidden" name="action" value="movefile">';
767
- $echo_str .= "\n\t\t".'<input type="hidden" name="dir" value="'.$dir_code.'">';
768
- $echo_str .= "\n\t\t".'<input type="hidden" name="file" value="'.$file_code_list.'">';
769
- if ( count($names) == 1 )
770
- $echo_str .= "\n\t\t".'<label style="display:inline-block; margin-bottom:1em;">Enter destination folder for file <strong>'.$dec_file.'</strong></label><br/>';
771
- else {
772
- $echo_str .= "\n\t\t".'<label>Enter destination folder for files:</label><br/>';
773
- $echo_str .= "\n\t\t".'<ul style="padding-left: 20px; list-style: initial;">';
774
- foreach ( $names as $name )
775
- $echo_str .= "\n\t\t\t".'<li><strong>'.$name.'</strong></li>';
776
- $echo_str .= "\n\t\t".'</ul>';
777
- }
778
- $echo_str .= "\n\t\t".'<input name="wfu_newpath" id="wfu_newpath" type="text" value="'.$newpath.'" style="width:50%;" />';
779
- $echo_str .= "\n\t\t".'<p>';
780
- $echo_str .= "\n\t\t\t".'<label>Replace files with the same filename at destination:</label><br />';
781
- $echo_str .= "\n\t\t\t".'<input name="wfu_replace" id="wfu_replace_yes" type="radio" value="yes"'.( $replacefiles == "yes" ? ' checked="checked"' : '' ).' /><label for="wfu_replace_yes">Yes</label>';
782
- $echo_str .= "\n\t\t\t".'<input name="wfu_replace" id="wfu_replace_no" type="radio" value="no"'.( $replacefiles == "no" ? ' checked="checked"' : '' ).' style="margin-left:1em;" /><label for="wfu_replace_no">No</label>';
783
- $echo_str .= "\n\t\t".'</p>';
784
- $echo_str .= "\n\t\t".'<p class="submit">';
785
- $echo_str .= "\n\t\t\t".'<input type="button" class="button-primary" name="submitBtn" value="Move" onclick="if (!document.getElementById(\'wfu_replace_yes\').checked && !document.getElementById(\'wfu_replace_no\').checked) alert(\'Please select if files in destination with the same filename will be replaced or not!\'); else this.form.submit();" />';
786
- $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submitBtn" value="Cancel" />';
787
- $echo_str .= "\n\t\t".'</p>';
788
- $echo_str .= "\n\t".'</form>';
789
- $echo_str .= "\n".'</div>';
790
- return $echo_str;
791
- }
792
-
793
- /**
794
- * Execute Renaming of File.
795
- *
796
- * This function renames a file.
797
- *
798
- * @since 2.2.1
799
- *
800
- * @param string $file_code A code corresponding to the file/dir to be renamed.
801
- * @param string $type Rename dir or file. Can take the values 'dir' or 'file'.
802
- *
803
- * @return bool True if renaming of file succeeded, false otherwise.
804
- */
805
- function wfu_rename_file($file_code, $type) {
806
- if ( $type == 'dir' ) return;
807
-
808
- $user = wp_get_current_user();
809
- $is_admin = current_user_can( 'manage_options' );
810
- //check if user is allowed to view file details
811
- if ( !$is_admin ) {
812
- return;
813
- }
814
- $file_code = wfu_sanitize_code($file_code);
815
- $dec_file = wfu_get_filepath_from_safe($file_code);
816
- if ( $dec_file === false ) return;
817
-
818
- $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
819
- if ( $type == 'dir' && substr($dec_file, -1) == '/' ) $dec_file = substr($dec_file, 0, -1);
820
- if ( !file_exists($dec_file) ) return;
821
-
822
- //check if user is allowed to perform this action
823
- if ( !wfu_current_user_owes_file($dec_file) ) return;
824
-
825
- $parts = pathinfo($dec_file);
826
- $error = "";
827
- if ( isset($_POST['wfu_newname']) && isset($_POST['submit']) ) {
828
- if ( $_POST['submit'] == "Rename" && $_POST['wfu_newname'] != $parts['basename'] ) {
829
- $new_file = $parts['dirname'].'/'.$_POST['wfu_newname'];
830
- if ( $_POST['wfu_newname'] == "" ) $error = 'Error: New '.( $type == 'dir' ? 'folder ' : 'file' ).'name cannot be empty!';
831
- elseif ( preg_match("/[^A-Za-z0-9_.#\-$]/", $_POST['wfu_newname']) ) $error = 'Error: name contained invalid characters that were stripped off! Please try again.';
832
- elseif ( substr($_POST['wfu_newname'], -1 - strlen($parts['extension'])) != '.'.$parts['extension'] ) $error = 'Error: new and old file name extensions must be identical! Please correct.';
833
- elseif ( wfu_file_extension_blacklisted($_POST['wfu_newname']) ) $error = 'Error: the new file name has an extension that is forbidden for security reasons. Please correct.';
834
- elseif ( file_exists($new_file) ) $error = 'Error: The '.( $type == 'dir' ? 'folder' : 'file' ).' <strong>'.$_POST['wfu_newname'].'</strong> already exists! Please choose another one.';
835
- else {
836
- //pre-log rename action
837
- if ( $type == 'file' ) $retid = wfu_log_action('rename:'.$new_file, $dec_file, $user->ID, '', 0, 0, '', null);
838
- //perform rename action
839
- if ( rename($dec_file, $new_file) == false ) $error = 'Error: Rename of '.( $type == 'dir' ? 'folder' : 'file' ).' <strong>'.$parts['basename'].'</strong> failed!';
840
- //revert log action if file was not renamed
841
- if ( $type == 'file' && !file_exists($new_file) ) wfu_revert_log_action($retid);
842
- }
843
- }
844
- }
845
- if ( $error != "" ) {
846
- WFU_USVAR_store('wfu_rename_file_error', $error);
847
- $rename_file = WFU_USVAR('wfu_rename_file');
848
- $rename_file['newname'] = preg_replace("/[^A-Za-z0-9_.#\-$]/", "", $_POST['wfu_newname']);
849
- WFU_USVAR_store('wfu_rename_file', $rename_file);
850
- }
851
- return ( $error == "" );
852
- }
853
-
854
- /**
855
- * Execute Moving of File.
856
- *
857
- * This function moves a file to another location.
858
- *
859
- * @since 4.10.3
860
- *
861
- * @param string $file_code A code corresponding to the file to be moved.
862
- *
863
- * @return bool True if move of file succeeded, false otherwise.
864
- */
865
- function wfu_move_file($file_code) {
866
- $user = wp_get_current_user();
867
- $is_admin = current_user_can( 'manage_options' );
868
- //check if user is allowed to view file details
869
- if ( !$is_admin ) return;
870
-
871
- if ( !is_array($file_code) ) $file_code = array( $file_code );
872
- $dec_files = array();
873
- foreach ( $file_code as $index => $code ) {
874
- $file_code[$index] = wfu_sanitize_code($code);
875
- $dec_file = wfu_get_filepath_from_safe($file_code[$index]);
876
- if ( $dec_file !== false ) {
877
- $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
878
- array_push($dec_files, $dec_file);
879
- }
880
- }
881
- if ( count($dec_files) == 0 ) return;
882
-
883
- $parts = pathinfo($dec_files[0]);
884
- $error = "";
885
- $regex = "/([^A-Za-z0-9\-._~!$&'()*+,;=:@#\/\\\\%]|%[^A-Fa-f0-9][^A-Fa-f0-9]|%[A-Fa-f0-9][^A-Fa-f0-9]|%[^A-Fa-f0-9][A-Fa-f0-9]|%.?$)/";
886
- if ( isset($_POST['wfu_newpath']) && isset($_POST['wfu_replace']) ) {
887
- $oldpath = $parts['dirname'];
888
- if ( substr($oldpath, -1) != '/' ) $oldpath = $oldpath.'/';
889
- $newpath = preg_replace($regex, "", $_POST['wfu_newpath']);
890
- if ( substr($newpath, 0, 1) != '/' ) $newpath = '/'.$newpath;
891
- $newpath = realpath(wfu_path_rel2abs($newpath));
892
- if ( substr($newpath, -1) != '/' ) $newpath = $newpath.'/';
893
- $replacefiles = ( $_POST['wfu_replace'] == 'yes' ? 'yes' : ( $_POST['wfu_replace'] == 'no' ? 'no' : '' ) );
894
- if ( trim($_POST['wfu_newpath']) == "" ) $error = 'Error: Destination path cannot be empty!';
895
- elseif ( $newpath == $oldpath ) $error = 'Error: Destination path is the same as source path!';
896
- elseif ( preg_match($regex, $_POST['wfu_newpath']) ) $error = 'Error: path contained invalid characters that were stripped off! Please try again.';
897
- elseif ( !file_exists($newpath) ) $error = 'Error: Destination folder <strong>'.$_POST['wfu_newpath'].'</strong> does not exist!';
898
- elseif ( $replacefiles == "" ) $error = 'Error: Invalid selection about replacing files with same filename at destination!';
899
- else {
900
- foreach ( $dec_files as $dec_file ) {
901
- if ( file_exists($dec_file) ) {
902
- $new_file = $newpath.wfu_basename($dec_file);
903
- if ( !file_exists($new_file) || $replacefiles == "yes" ) {
904
- //pre-log move action
905
- $retid = wfu_log_action('move:'.$new_file, $dec_file, $user->ID, '', 0, 0, '', null);
906
- //perform move action
907
- if ( @rename($dec_file, $new_file) === false || !file_exists($new_file) ) {
908
- wfu_revert_log_action($retid);
909
- }
910
- }
911
- }
912
- }
913
- }
914
- }
915
- if ( $error != "" ) {
916
- WFU_USVAR_store('wfu_move_file_error', $error);
917
- $move_file = WFU_USVAR('wfu_move_file');
918
- $move_file['newpath'] = preg_replace($regex, "", $_POST['wfu_newpath']);
919
- $move_file['replacefiles'] = $replacefiles;
920
- WFU_USVAR_store('wfu_move_file', $move_file);
921
- }
922
- return ( $error == "" );
923
- }
924
-
925
- /**
926
- * Confirm Deletion of File.
927
- *
928
- * This function shows a page to confirm deletion of a file.
929
- *
930
- * @since 2.2.1
931
- *
932
- * @param string $file_code A code corresponding to the file/dir to be deleted.
933
- * @param string $type Delete dir or file. Can take the values 'dir' or 'file'.
934
- * @param string $referer The page that initiated the deletion of the file.
935
- *
936
- * @return string The HTML code of the confirmation page.
937
- */
938
- function wfu_delete_file_prompt($file_code, $type, $referer) {
939
- if ( $type == 'dir' ) return;
940
-
941
- $siteurl = site_url();
942
-
943
- $is_admin = current_user_can( 'manage_options' );
944
- //check if user is allowed to view file details
945
- if ( !$is_admin ) {
946
- return;
947
- }
948
- if ( !is_array($file_code) ) $file_code = array( $file_code );
949
- $names = array();
950
- foreach ( $file_code as $index => $code ) {
951
- $file_code[$index] = wfu_sanitize_code($code);
952
- $dec_file = wfu_get_filepath_from_safe($file_code[$index]);
953
- if ( $dec_file === false ) unset($file_code[$index]);
954
- else {
955
- //first extract sort info from dec_file
956
- $ret = wfu_extract_sortdata_from_path($dec_file);
957
- $dec_file = wfu_path_rel2abs($ret['path']);
958
- if ( $type == 'dir' && substr($dec_file, -1) == '/' ) $dec_file = substr($dec_file, 0, -1);
959
- //check if user is allowed to perform this action
960
- if ( !wfu_current_user_owes_file($dec_file) ) unset($file_code[$index]);
961
- else {
962
- $parts = pathinfo($dec_file);
963
- array_push($names, $parts['basename']);
964
- }
965
- }
966
- }
967
- if ( count($file_code) == 0 ) return;
968
- $file_code_list = "list:".implode(",", $file_code);
969
-
970
- $referer_url = wfu_get_filepath_from_safe(wfu_sanitize_code($referer));
971
- $ret = wfu_extract_sortdata_from_path($referer_url);
972
- $referer_url = $ret['path'];
973
-
974
- $echo_str = "\n".'<div class="wrap">';
975
- $echo_str .= "\n\t".'<div style="margin-top:20px;">';
976
- if ( $is_admin ) $echo_str .= "\n\t\t".'<a href="'.$referer_url.'" class="button" title="go back">Go back</a>';
977
- $echo_str .= "\n\t".'</div>';
978
- $echo_str .= "\n\t".'<h2 style="margin-bottom: 10px;">Delete '.( $type == 'dir' ? 'Folder' : 'File'.( count($names) == 1 ? '' : 's' ) ).'</h2>';
979
- if ( $is_admin ) $echo_str .= "\n\t".'<form enctype="multipart/form-data" name="deletefile" id="deletefile" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="validate">';
980
- $echo_str .= "\n\t\t".'<input type="hidden" name="action" value="delete'.( $type == 'dir' ? 'dir' : 'file' ).'">';
981
- $echo_str .= "\n\t\t".'<input type="hidden" name="referer" value="'.$referer.'">';
982
- $echo_str .= "\n\t\t".'<input type="hidden" name="file" value="'.$file_code_list.'">';
983
- if ( count($names) == 1 )
984
- $echo_str .= "\n\t\t".'<label>Are you sure that you want to delete '.( $type == 'dir' ? 'folder' : 'file' ).' <strong>'.$names[0].'</strong>?</label><br/>';
985
- else {
986
- $echo_str .= "\n\t\t".'<label>Are you sure that you want to delete '.( $type == 'dir' ? 'folder' : 'files' ).':';
987
- $echo_str .= "\n\t\t".'<ul style="padding-left: 20px; list-style: initial;">';
988
- foreach ( $names as $name )
989
- $echo_str .= "\n\t\t\t".'<li><strong>'.$name.'</strong></li>';
990
- $echo_str .= "\n\t\t".'</ul>';
991
- }
992
- $echo_str .= "\n\t\t".'<p class="submit">';
993
- $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Delete">';
994
- $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Cancel">';
995
- $echo_str .= "\n\t\t".'</p>';
996
- $echo_str .= "\n\t".'</form>';
997
- $echo_str .= "\n".'</div>';
998
- return $echo_str;
999
- }
1000
-
1001
- /**
1002
- * Execute Deletion of File.
1003
- *
1004
- * This function deletes a file.
1005
- *
1006
- * @since 2.2.1
1007
- *
1008
- * @param string $file_code A code corresponding to the file/dir to be deleted.
1009
- * @param string $type Delete dir or file. Can take the values 'dir' or 'file'.
1010
- *
1011
- * @return bool True if deletion of file succeeded, false otherwise.
1012
- */
1013
- function wfu_delete_file($file_code, $type) {
1014
- if ( $type == 'dir' ) return;
1015
-
1016
- $user = wp_get_current_user();
1017
- $is_admin = current_user_can( 'manage_options' );
1018
- //check if user is allowed to view file details
1019
- if ( !$is_admin ) {
1020
- return;
1021
- }
1022
- if ( !is_array($file_code) ) $file_code = array( $file_code );
1023
- $dec_files = array();
1024
- foreach ( $file_code as $index => $code ) {
1025
- $file_code[$index] = wfu_sanitize_code($code);
1026
- $dec_file = wfu_get_filepath_from_safe($file_code[$index]);
1027
- if ( $dec_file !== false ) {
1028
- $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
1029
- if ( $type == 'dir' && substr($dec_file, -1) == '/' ) $dec_file = substr($dec_file, 0, -1);
1030
- //check if user is allowed to perform this action
1031
- if ( wfu_current_user_owes_file($dec_file) ) array_push($dec_files, $dec_file);
1032
- }
1033
- }
1034
- if ( count($dec_files) == 0 ) return;
1035
-
1036
- if ( isset($_POST['submit']) ) {
1037
- if ( $_POST['submit'] == "Delete" ) {
1038
- foreach ( $dec_files as $dec_file ) {
1039
- //pre-log delete action
1040
- if ( $type == 'file' ) wfu_delete_file_execute($dec_file, $user->ID);
1041
- elseif ( $type == 'dir' && $dec_file != "" ) wfu_delTree($dec_file);
1042
- }
1043
- }
1044
- }
1045
- return true;
1046
- }
1047
-
1048
- /**
1049
- * Confirm Creation of a Directory.
1050
- *
1051
- * This function shows a page to confirm creation of a directory.
1052
- *
1053
- * @since 2.2.1
1054
- *
1055
- * @param string $dir_code A code corresponding to the dir to be created.
1056
- * @param string $error An error message to show on top of the page in case an
1057
- * error occured during creation.
1058
- *
1059
- * @return string The HTML code of the confirmation page.
1060
- */
1061
- function wfu_create_dir_prompt($dir_code, $error) {
1062
- return;
1063
-
1064
- $siteurl = site_url();
1065
-
1066
- if ( !current_user_can( 'manage_options' ) ) return;
1067
-
1068
- $dir_code = wfu_sanitize_code($dir_code);
1069
- $dec_dir = wfu_get_filepath_from_safe($dir_code);
1070
- if ( $dec_dir === false ) return;
1071
-
1072
- //first extract sort info from dec_dir
1073
- $ret = wfu_extract_sortdata_from_path($dec_dir);
1074
- $dec_dir = wfu_path_rel2abs($ret['path']);
1075
- if ( substr($dec_dir, -1) != '/' ) $dec_dir .= '/';
1076
- $newname = '';
1077
-
1078
- $echo_str = "\n".'<div class="wrap">';
1079
- if ( $error ) {
1080
- $create_dir = WFU_USVAR('wfu_create_dir');
1081
- $newname = $create_dir['newname'];
1082
- $echo_str .= "\n\t".'<div class="error">';
1083
- $echo_str .= "\n\t\t".'<p>'.WFU_USVAR('wfu_create_dir_error').'</p>';
1084
- $echo_str .= "\n\t".'</div>';
1085
- }
1086
- $echo_str .= "\n\t".'<div style="margin-top:20px;">';
1087
- $echo_str .= "\n\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=file_browser&dir='.$dir_code.'" class="button" title="go back">Go back</a>';
1088
- $echo_str .= "\n\t".'</div>';
1089
- $echo_str .= "\n\t".'<h2 style="margin-bottom: 10px;">Create Folder</h2>';
1090
- $echo_str .= "\n\t".'<form enctype="multipart/form-data" name="createdir" id="createdir" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="validate">';
1091
- $echo_str .= "\n\t\t".'<input type="hidden" name="action" value="createdir">';
1092
- $echo_str .= "\n\t\t".'<input type="hidden" name="dir" value="'.$dir_code.'">';
1093
- $echo_str .= "\n\t\t".'<label>Enter the name of the new folder inside <strong>'.$dec_dir.'</strong></label><br/>';
1094
- $echo_str .= "\n\t\t".'<input name="wfu_newname" id="wfu_newname" type="text" value="'.$newname.'" style="width:50%;" />';
1095
- $echo_str .= "\n\t\t".'<p class="submit">';
1096
- $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Create">';
1097
- $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Cancel">';
1098
- $echo_str .= "\n\t\t".'</p>';
1099
- $echo_str .= "\n\t".'</form>';
1100
- $echo_str .= "\n".'</div>';
1101
- return $echo_str;
1102
- }
1103
-
1104
- /**
1105
- * Execute Creation of Directory.
1106
- *
1107
- * This function creates a new directory.
1108
- *
1109
- * @since 2.2.1
1110
- *
1111
- * @param string $dir_code A code corresponding to the dir to be created.
1112
- *
1113
- * @return bool True if creation of dir succeeded, false otherwise.
1114
- */
1115
- function wfu_create_dir($dir_code) {
1116
- return;
1117
-
1118
- if ( !current_user_can( 'manage_options' ) ) return;
1119
-
1120
- $dir_code = wfu_sanitize_code($dir_code);
1121
- $dec_dir = wfu_get_filepath_from_safe($dir_code);
1122
- if ( $dec_dir === false ) return;
1123
-
1124
- $dec_dir = wfu_path_rel2abs(wfu_flatten_path($dec_dir));
1125
- if ( substr($dec_dir, -1) != '/' ) $dec_dir .= '/';
1126
- if ( !file_exists($dec_dir) ) return;
1127
- $error = "";
1128
- if ( isset($_POST['wfu_newname']) && isset($_POST['submit']) ) {
1129
- if ( $_POST['submit'] == "Create" ) {
1130
- $new_dir = $dec_dir.$_POST['wfu_newname'];
1131
- if ( $_POST['wfu_newname'] == "" ) $error = 'Error: New folder name cannot be empty!';
1132
- elseif ( preg_match("/[^A-Za-z0-9_.#\-$]/", $_POST['wfu_newname']) ) $error = 'Error: name contained invalid characters that were stripped off! Please try again.';
1133
- elseif ( file_exists($new_dir) ) $error = 'Error: The folder <strong>'.$_POST['wfu_newname'].'</strong> already exists! Please choose another one.';
1134
- elseif ( mkdir($new_dir) == false ) $error = 'Error: Creation of folder <strong>'.$_POST['wfu_newname'].'</strong> failed!';
1135
- }
1136
- }
1137
- if ( $error != "" ) {
1138
- WFU_USVAR_store('wfu_create_dir_error', $error);
1139
- $create_dir = WFU_USVAR('wfu_create_dir');
1140
- $create_dir['newname'] = preg_replace("/[^A-Za-z0-9_.#\-$]/", "", $_POST['wfu_newname']);
1141
- WFU_USVAR_store('wfu_create_dir', $create_dir);
1142
- }
1143
- return ( $error == "" );
1144
- }
1145
-
1146
- /**
1147
- * Confirm Inclusion of File in Plugin's Database.
1148
- *
1149
- * This function shows a page to confirm inclusion of a file in plugin's
1150
- * database.
1151
- *
1152
- * @since 3.8.5
1153
- *
1154
- * @param string $file_code A code corresponding to the file to be included.
1155
- * @param string $type Rename dir or file. Can take the values 'dir' or 'file'.
1156
- * @param string $referer The page that initiated the inclusion of the file.
1157
- *
1158
- * @return string The HTML code of the confirmation page.
1159
- */
1160
- function wfu_include_file_prompt($file_code, $referer) {
1161
- if ( !current_user_can( 'manage_options' ) ) return;
1162
- $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
1163
- if ( $plugin_options['includeotherfiles'] != "1" ) return;
1164
-
1165
- $siteurl = site_url();
1166
- if ( !is_array($file_code) ) $file_code = array( $file_code );
1167
- $names = array();
1168
- foreach ( $file_code as $index => $code ) {
1169
- $file_code[$index] = wfu_sanitize_code($code);
1170
- $dec_file = wfu_get_filepath_from_safe($file_code[$index]);
1171
- if ( $dec_file === false ) unset($file_code[$index]);
1172
- else {
1173
- $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
1174
- //do not include file if it has a forbidden extention or it is already included
1175
- if ( wfu_file_extension_blacklisted(wfu_basename($dec_file)) || wfu_get_file_rec($dec_file, false) != null )
1176
- unset($file_code[$index]);
1177
- else array_push($names, wfu_basename($dec_file));
1178
- }
1179
- }
1180
- if ( count($file_code) == 0 ) return;
1181
- $file_code_list = "list:".implode(",", $file_code);
1182
-
1183
- $referer_url = wfu_get_filepath_from_safe(wfu_sanitize_code($referer));
1184
- $ret = wfu_extract_sortdata_from_path($referer_url);
1185
- $referer_url = $ret['path'];
1186
-
1187
- $echo_str = "\n".'<div class="wrap">';
1188
- $echo_str .= "\n\t".'<div style="margin-top:20px;">';
1189
- $echo_str .= "\n\t\t".'<a href="'.$referer_url.'" class="button" title="go back">Go back</a>';
1190
- $echo_str .= "\n\t".'</div>';
1191
- $echo_str .= "\n\t".'<h2 style="margin-bottom: 10px;">Include File'.( count($names) == 1 ? '' : 's' ).'</h2>';
1192
- $echo_str .= "\n\t".'<form enctype="multipart/form-data" name="includefile" id="includefile" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="validate">';
1193
- $echo_str .= "\n\t\t".'<input type="hidden" name="action" value="includefile">';
1194
- $echo_str .= "\n\t\t".'<input type="hidden" name="referer" value="'.$referer.'">';
1195
- $echo_str .= "\n\t\t".'<input type="hidden" name="file" value="'.$file_code_list.'">';
1196
- if ( count($names) == 1 )
1197
- $echo_str .= "\n\t\t".'<label>Are you sure that you want to include file <strong>'.$names[0].'</strong>?</label><br/>';
1198
- else {
1199
- $echo_str .= "\n\t\t".'<label>Are you sure that you want to include files:';
1200
- $echo_str .= "\n\t\t".'<ul style="padding-left: 20px; list-style: initial;">';
1201
- foreach ( $names as $name )
1202
- $echo_str .= "\n\t\t\t".'<li><strong>'.$name.'</strong></li>';
1203
- $echo_str .= "\n\t\t".'</ul>';
1204
- }
1205
- $echo_str .= "\n\t\t".'<p class="submit">';
1206
- $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Include">';
1207
- $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Cancel">';
1208
- $echo_str .= "\n\t\t".'</p>';
1209
- $echo_str .= "\n\t".'</form>';
1210
- $echo_str .= "\n".'</div>';
1211
- return $echo_str;
1212
- }
1213
-
1214
- /**
1215
- * Execute Inclusion of File in Plugin's Database.
1216
- *
1217
- * This function includes a file in plugin's database.
1218
- *
1219
- * @since 3.8.5
1220
- *
1221
- * @param string $file_code A code corresponding to the file to be included.
1222
- *
1223
- * @return bool True if inclusion of file succeeded, false otherwise.
1224
- */
1225
- function wfu_include_file($file_code) {
1226
- if ( !current_user_can( 'manage_options' ) ) return;
1227
- $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
1228
- if ( $plugin_options['includeotherfiles'] != "1" ) return;
1229
-
1230
- if ( !is_array($file_code) ) $file_code = array( $file_code );
1231
- $dec_files = array();
1232
- foreach ( $file_code as $index => $code ) {
1233
- $file_code[$index] = wfu_sanitize_code($code);
1234
- $dec_file = wfu_get_filepath_from_safe($file_code[$index]);
1235
- if ( $dec_file !== false ) {
1236
- $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
1237
- //include file if it does not have a forbidden extention and it not already included
1238
- if ( !wfu_file_extension_blacklisted(wfu_basename($dec_file)) && wfu_get_file_rec($dec_file, false) == null )
1239
- array_push($dec_files, $dec_file);
1240
- }
1241
- }
1242
- if ( count($dec_files) == 0 ) return;
1243
-
1244
- $user = wp_get_current_user();
1245
- if ( isset($_POST['submit']) ) {
1246
- if ( $_POST['submit'] == "Include" ) {
1247
- foreach ( $dec_files as $dec_file )
1248
- $fileid = wfu_log_action('include', $dec_file, $user->ID, '', '', get_current_blog_id(), '', null);
1249
- }
1250
- }
1251
- return true;
1252
- }
1253
-
1254
- /**
1255
- * Show File Details Page.
1256
- *
1257
- * This function shows a page displaying details of the uploaded file.
1258
- *
1259
- * @since 2.4.1
1260
- *
1261
- * @param string $file_code A code corresponding to the file to be included.
1262
- * @param string $errorstatus Error status. If it has the value 'error' then an
1263
- * error will be shown on top of the page.
1264
- * @param string $invoker Optional. The page URL that initiated file details
1265
- * page.
1266
- *
1267
- * @return string The HTML code of File Details page.
1268
- */
1269
- function wfu_file_details($file_code, $errorstatus, $invoker = '') {
1270
- $siteurl = site_url();
1271
- $allow_obsolete = false;
1272
- $file_exists = true;
1273
- $file_belongs = true;
1274
- $admin_can_edit = true;
1275
-
1276
- //if $file_code starts with 'byID:', then it contains a db record ID and not
1277
- //a file path; in this case we show the properties of the specific record
1278
- //and all linked ones, even if it is obsolete; this is only allowed for
1279
- //admins
1280
- if ( substr($file_code, 0, 5) == "byID:" ) {
1281
- $allow_obsolete = true;
1282
- $file_code = substr($file_code, 5);
1283
- }
1284
-
1285
- $user = wp_get_current_user();
1286
- $is_admin = current_user_can( 'manage_options' );
1287
- //check if user is allowed to view file details
1288
- if ( !$is_admin ) {
1289
- if ( $allow_obsolete ) return;
1290
- return;
1291
- }
1292
- if ( $allow_obsolete ) {
1293
- $file_code = wfu_sanitize_int($file_code);
1294
- $initialrec = wfu_get_file_rec_from_id($file_code, true);
1295
- if ( $initialrec == null ) return;
1296
-
1297
- //get all associated file records
1298
- $filerecs = wfu_get_rec_new_history($initialrec->idlog);
1299
- //get the latest record of this upload
1300
- $filerec = $filerecs[count($filerecs) - 1];
1301
- $filerec->userdata = $initialrec->userdata;
1302
-
1303
- $filepath = wfu_path_rel2abs($filerec->filepath);
1304
- //in the case of $allow_obsolete we need to check if the file exists and
1305
- //if it belongs to the current record
1306
- $latestrec = wfu_get_file_rec($filepath, true);
1307
- $file_exists = ( $latestrec != null );
1308
- $file_belongs = ( $file_exists && $latestrec->idlog == $filerec->idlog );
1309
- $admin_can_edit = $file_exists;
1310
-
1311
- //extract file parts and file properties
1312
- $parts = pathinfo($filepath);
1313
- if ( $file_exists ) $stat = stat($filepath);
1314
- else $stat['mtime'] = '';
1315
- }
1316
- else {
1317
- $file_code = wfu_sanitize_code($file_code);
1318
- $dec_file = wfu_get_filepath_from_safe($file_code);
1319
- if ( $dec_file === false ) return;
1320
-
1321
- //extract file browser data from $file variable
1322
- $ret = wfu_extract_sortdata_from_path($dec_file);
1323
- $filepath = wfu_path_rel2abs($ret['path']);
1324
-
1325
- //check if user is allowed to perform this action
1326
- if ( !wfu_current_user_owes_file($filepath) ) return;
1327
-
1328
- //get file data from database with user data
1329
- $filerec = wfu_get_file_rec($filepath, true);
1330
- if ( $filerec == null ) return;
1331
-
1332
- //extract sort info and construct contained dir
1333
- $parts = pathinfo($filepath);
1334
- $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($parts['dirname']).'[['.$ret['sort'].']]');
1335
-
1336
- $stat = stat($filepath);
1337
- }
1338
-
1339
- $echo_str = '<div class="regev_wrap">';
1340
- if ( $errorstatus == 'error' ) {
1341
- $echo_str .= "\n\t".'<div class="error">';
1342
- $echo_str .= "\n\t\t".'<p>'.WFU_USVAR('wfu_filedetails_error').'</p>';
1343
- $echo_str .= "\n\t".'</div>';
1344
- }
1345
- //show file detais
1346
- $echo_str .= "\n\t".'<h2>Detais of File: '.$parts['basename'].'</h2>';
1347
- if ( !$file_exists ) {
1348
- $echo_str .= "\n\t\t".'<div class="notice notice-warning">';
1349
- $echo_str .= "\n\t\t\t".'<p>File does not exist on the server anymore!</p>';
1350
- $echo_str .= "\n\t\t".'</div>';
1351
- }
1352
- elseif ( !$file_belongs ) {
1353
- $echo_str .= "\n\t\t".'<div class="notice notice-warning">';
1354
- $echo_str .= "\n\t\t\t".'<p>This record is old. The file is associated with another record.</p>';
1355
- $echo_str .= "\n\t\t".'</div>';
1356
- }
1357
- $echo_str .= "\n\t".'<div style="margin-top:10px;">';
1358
- if ( $is_admin ) {
1359
- $invoker_action = ( $invoker == '' ? false : wfu_get_browser_params_from_safe($invoker) );
1360
- $goback_action = ( $invoker_action === false ? 'file_browser&dir='.$dir_code : $invoker_action );
1361
- if ( substr($goback_action, 0, 18) == "wfu_uploaded_files" )
1362
- $echo_str .= "\n\t\t".'<a href="'.$siteurl.'/wp-admin/admin.php?page='.$goback_action.'" class="button" title="go back">Go back</a>';
1363
- elseif ( $goback_action != "no_referer" )
1364
- $echo_str .= "\n\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action='.$goback_action.'" class="button" title="go back">Go back</a>';
1365
- $echo_str .= "\n\t\t".'<form enctype="multipart/form-data" name="editfiledetails" id="editfiledetails" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=edit_filedetails" class="validate">';
1366
- }
1367
- $echo_str .= "\n\t\t\t".'<h3 style="margin-bottom: 10px; margin-top: 40px;">Upload Details</h3>';
1368
- $echo_str .= "\n\t\t\t".'<input type="hidden" name="action" value="edit_filedetails" />';
1369
- //$echo_str .= "\n\t\t\t".'<input type="hidden" name="dir" value="'.$dir_code.'">';
1370
- $echo_str .= "\n\t\t\t".'<input type="hidden" name="invoker" value="'.$invoker.'">';
1371
- $echo_str .= "\n\t\t\t".'<input type="hidden" name="file" value="'.( $allow_obsolete ? 'byID:'.$file_code : $file_code ).'">';
1372
- $echo_str .= "\n\t\t\t".'<table class="form-table">';
1373
- $echo_str .= "\n\t\t\t\t".'<tbody>';
1374
- if ( $is_admin ) {
1375
- $echo_str .= "\n\t\t\t\t\t".'<tr>';
1376
- $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1377
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label>Full Path</label>';
1378
- $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1379
- $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1380
- $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="text" value="'.$filepath.'" readonly="readonly" style="width:50%;" />';
1381
- $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1382
- $echo_str .= "\n\t\t\t\t\t".'</tr>';
1383
- $echo_str .= "\n\t\t\t\t\t".'<tr>';
1384
- $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1385
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label>Uploaded By User</label>';
1386
- $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1387
- $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1388
- $echo_str .= "\n\t\t\t\t\t\t\t".'<select id="wfu_filedetails_users" disabled="disabled">';
1389
- //get all users
1390
- $args = array();
1391
- /**
1392
- * Filter Arguments for Getting List of Users.
1393
- *
1394
- * This filter allows to customize the arguments passed to get_users()
1395
- * function to get a list of users. By default the plugin will get a
1396
- * list of all users. If the website contains too many users this
1397
- * operation may take time and delay loading of the page. So this filter
1398
- * can be used to optimize this operation.
1399
- *
1400
- * @since 4.11.0
1401
- *
1402
- * @param array $args Arguments to retrieve users.
1403
- * @param string $operation A parameter designating in which operation
1404
- * the filter is used.
1405
- */
1406
- $args = apply_filters("_wfu_get_users", $args, "edit_file_details");
1407
- $users = get_users($args);
1408
- foreach ( $users as $userid => $user )
1409
- $echo_str .= "\n\t\t\t\t\t\t\t\t".'<option value="'.$user->ID.'"'.( $filerec->uploaduserid == $user->ID ? ' selected="selected"' : '' ).'>'.$user->display_name.' ('.$user->user_login.')</option>';
1410
- $echo_str .= "\n\t\t\t\t\t\t\t".'</select>';
1411
- if ( $admin_can_edit ) {
1412
- $echo_str .= "\n\t\t\t\t\t\t\t".'<a class="button" id="btn_change" href="" onclick="document.getElementById(\'wfu_filedetails_users\').disabled = false; this.style.display = \'none\'; document.getElementById(\'btn_ok\').style.display = \'inline-block\'; document.getElementById(\'btn_cancel\').style.display = \'inline-block\'; return false;"'.( $is_admin ? '' : ' style="display:none;"' ).'>Change User</a>';
1413
- $echo_str .= "\n\t\t\t\t\t\t\t".'<a class="button" id="btn_ok" href="" onclick="document.getElementById(\'wfu_filedetails_users\').disabled = true; document.getElementById(\'btn_change\').style.display = \'inline-block\'; this.style.display=\'none\'; document.getElementById(\'btn_cancel\').style.display = \'none\'; document.getElementById(\'wfu_filedetails_userid\').value = document.getElementById(\'wfu_filedetails_users\').value; wfu_filedetails_changed(); return false;" style="display:none;">Ok</a>';
1414
- $echo_str .= "\n\t\t\t\t\t\t\t".'<a class="button" id="btn_cancel" href="" onclick="document.getElementById(\'wfu_filedetails_users\').disabled = true; document.getElementById(\'btn_change\').style.display = \'inline-block\'; this.style.display=\'none\'; document.getElementById(\'btn_ok\').style.display = \'none\'; document.getElementById(\'wfu_filedetails_users\').value = document.getElementById(\'wfu_filedetails_userid\').value; return false;" style="display:none;">Cancel</a>';
1415
- $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="hidden" id="wfu_filedetails_userid" name="wfu_filedetails_userid" value="'.$filerec->uploaduserid.'" />';
1416
- $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="hidden" id="wfu_filedetails_userid_default" value="'.$filerec->uploaduserid.'" />';
1417
- }
1418
- $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1419
- $echo_str .= "\n\t\t\t\t\t".'</tr>';
1420
- }
1421
- $echo_str .= "\n\t\t\t\t\t".'<tr>';
1422
- $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1423
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label>File Size</label>';
1424
- $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1425
- $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1426
- $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="text" value="'.$filerec->filesize.'" readonly="readonly" style="width:auto;" />';
1427
- $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1428
- $echo_str .= "\n\t\t\t\t\t".'</tr>';
1429
- $echo_str .= "\n\t\t\t\t\t".'<tr>';
1430
- $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1431
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label>File Date</label>';
1432
- $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1433
- $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1434
- $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="text" value="'.( $file_exists ? get_date_from_gmt(date("Y-m-d H:i:s", $stat['mtime']), "d/m/Y H:i:s") : '' ).'" readonly="readonly" style="width:auto;" />';
1435
- $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1436
- $echo_str .= "\n\t\t\t\t\t".'</tr>';
1437
- $echo_str .= "\n\t\t\t\t\t".'<tr>';
1438
- $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1439
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label>Uploaded From Page</label>';
1440
- $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1441
- $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1442
- $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="text" value="'.get_the_title($filerec->pageid).' ('.$filerec->pageid.')'.'" readonly="readonly" style="width:50%;" />';
1443
- $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1444
- $echo_str .= "\n\t\t\t\t\t".'</tr>';
1445
- if ( $is_admin ) {
1446
- $echo_str .= "\n\t\t\t\t\t".'<tr>';
1447
- $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1448
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label>Upload Plugin ID</label>';
1449
- $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1450
- $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1451
- $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="text" value="'.$filerec->sid.'" readonly="readonly" style="width:auto;" />';
1452
- $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1453
- $echo_str .= "\n\t\t\t\t\t".'</tr>';
1454
- }
1455
- $echo_str .= "\n\t\t\t\t".'</tbody>';
1456
- $echo_str .= "\n\t\t\t".'</table>';
1457
- if ( $is_admin ) {
1458
- //show history details
1459
- $echo_str .= "\n\t\t\t".'<h3 style="margin-bottom: 10px; margin-top: 40px;">File History</h3>';
1460
- $echo_str .= "\n\t\t\t".'<table class="form-table">';
1461
- $echo_str .= "\n\t\t\t\t".'<tbody>';
1462
- $echo_str .= "\n\t\t\t\t\t".'<tr>';
1463
- $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1464
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label></label>';
1465
- $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1466
- $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1467
- //read all linked older records
1468
- $filerecs = wfu_get_rec_old_history($filerec->idlog);
1469
- //construct report from db records
1470
- $rep = '';
1471
- foreach ( $filerecs as $rec ) {
1472
- $username = wfu_get_username_by_id($rec->userid);
1473
- $fileparts = pathinfo($rec->filepath);
1474
- if ( $rep != '' ) $rep .= "<br />";
1475
- $rep .= '<strong>['.get_date_from_gmt($rec->date_from).']</strong> ';
1476
- if ( $rec->action == 'upload' )
1477
- $rep .= 'File uploaded at <strong>'.$fileparts['dirname'].'</strong> with name <strong>'.$fileparts['basename'].'</strong> by user <strong>'.$username.'</strong>';
1478
- elseif ( $rec->action == 'include' )
1479
- $rep .= 'File included in database at <strong>'.$fileparts['dirname'].'</strong> with name <strong>'.$fileparts['basename'].'</strong> by user <strong>'.$username.'</strong>';
1480
- elseif ( $rec->action == 'download' )
1481
- $rep .= 'File downloaded by user <strong>'.$username.'</strong>';
1482
- elseif ( $rec->action == 'rename' )
1483
- $rep .= 'File renamed to <strong>'.$fileparts['basename'].'</strong> by user <strong>'.$username.'</strong>';
1484
- elseif ( $rec->action == 'move' )
1485
- $rep .= 'File moved to <strong>'.$fileparts['dirname'].'</strong> by user <strong>'.$username.'</strong>';
1486
- elseif ( $rec->action == 'delete' )
1487
- $rep .= 'File deleted by user <strong>'.$username.'</strong>';
1488
- elseif ( $rec->action == 'modify' )
1489
- $rep .= 'File userdata modified by user <strong>'.$username.'</strong>';
1490
- elseif ( $rec->action == 'changeuser' )
1491
- $rep .= 'File upload user modified by user <strong>'.$username.'</strong>';
1492
- }
1493
- $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;">';
1494
- $echo_str .= "\n\t\t\t\t\t\t\t".'<span style="white-space:nowrap;">'.$rep.'</span>';
1495
- $echo_str .= "\n\t\t\t\t\t\t\t".'</div>';
1496
- $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1497
- $echo_str .= "\n\t\t\t\t\t".'</tr>';
1498
- $echo_str .= "\n\t\t\t\t".'</tbody>';
1499
- $echo_str .= "\n\t\t\t".'</table>';
1500
- }
1501
-
1502
- $echo_str .= "\n\t\t\t".'<h3 style="margin-bottom: 10px; margin-top: 40px;">User Data Details</h3>';
1503
- $echo_str .= "\n\t\t\t".'<table class="form-table">';
1504
- $echo_str .= "\n\t\t\t\t".'<tbody>';
1505
- if ( is_array($filerec->userdata) && count($filerec->userdata) > 0 ) {
1506
- foreach ( $filerec->userdata as $userdata ) {
1507
- $echo_str .= "\n\t\t\t\t\t".'<tr>';
1508
- $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1509
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label>'.$userdata->property.'</label>';
1510
- $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1511
- $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1512
- // $echo_str .= "\n\t\t\t\t\t\t\t".'<input id="wfu_filedetails_userdata_value_'.$userdata->propkey.'" name="wfu_filedetails_userdata" type="text"'.( $is_admin ? '' : ' readonly="readonly"' ).' value="'.$userdata->propvalue.'" />';
1513
- $echo_str .= "\n\t\t\t\t\t\t\t".'<textarea id="wfu_filedetails_userdata_value_'.$userdata->propkey.'" name="wfu_filedetails_userdata" '.( ($is_admin && $admin_can_edit) ? '' : ' readonly="readonly"' ).' value="'.$userdata->propvalue.'">'.$userdata->propvalue.'</textarea>';
1514
- $echo_str .= "\n\t\t\t\t\t\t\t".'<input id="wfu_filedetails_userdata_default_'.$userdata->propkey.'" type="hidden" value="'.$userdata->propvalue.'" />';
1515
- $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.'" />';
1516
- $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1517
- $echo_str .= "\n\t\t\t\t\t".'</tr>';
1518
- }
1519
- }
1520
- else {
1521
- $echo_str .= "\n\t\t\t\t\t".'<tr>';
1522
- $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1523
- $echo_str .= "\n\t\t\t\t\t\t\t".'<label>No user data</label>';
1524
- $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1525
- $echo_str .= "\n\t\t\t\t\t\t".'<td></td>';
1526
- $echo_str .= "\n\t\t\t\t\t".'</tr>';
1527
- }
1528
- $echo_str .= "\n\t\t\t\t".'</tbody>';
1529
- $echo_str .= "\n\t\t\t".'</table>';
1530
- if ( ($is_admin && $admin_can_edit) ) {
1531
- $echo_str .= "\n\t\t\t".'<p class="submit">';
1532
- $echo_str .= "\n\t\t\t\t".'<input id="dp_filedetails_submit_fields" type="submit" class="button-primary" name="submit" value="Update" disabled="disabled" />';
1533
- $echo_str .= "\n\t\t\t".'</p>';
1534
- }
1535
- $echo_str .= "\n\t\t".'</form>';
1536
- $echo_str .= "\n\t".'</div>';
1537
- $handler = 'function() { wfu_Attach_FileDetails_Admin_Events(); }';
1538
- $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>';
1539
- $echo_str .= '</div>';
1540
-
1541
- return $echo_str;
1542
- }
1543
-
1544
- /**
1545
- * Change File Details.
1546
- *
1547
- * This function modifies the database record of an uploaded file, as well as
1548
- * any associated user data field records.
1549
- *
1550
- * @since 2.4.1
1551
- *
1552
- * @param string $file_code A code corresponding to the file to be modified.
1553
- *
1554
- * @return bool True if modification of file succeeded, false otherwise.
1555
- */
1556
- function wfu_edit_filedetails($file_code) {
1557
- global $wpdb;
1558
- $table_name2 = $wpdb->prefix . "wfu_userdata";
1559
- $allow_obsolete = false;
1560
-
1561
- if ( substr($file_code, 0, 5) == "byID:" ) {
1562
- $allow_obsolete = true;
1563
- $file_code = substr($file_code, 5);
1564
- }
1565
-
1566
- $user = wp_get_current_user();
1567
- $is_admin = current_user_can( 'manage_options' );
1568
- //check if user is allowed to view file details
1569
- if ( !$is_admin ) {
1570
- if ( $allow_obsolete ) return;
1571
- return;
1572
- }
1573
- if ( $allow_obsolete ) {
1574
- $file_code = wfu_sanitize_int($file_code);
1575
- $initialrec = wfu_get_file_rec_from_id($file_code, true);
1576
- if ( $initialrec == null ) return;
1577
-
1578
- //get all associated file records
1579
- $filerecs = wfu_get_rec_new_history($initialrec->idlog);
1580
- //get the latest record of this upload
1581
- $filerec = $filerecs[count($filerecs) - 1];
1582
- $filerec->userdata = $initialrec->userdata;
1583
-
1584
- $filepath = wfu_path_rel2abs($filerec->filepath);
1585
- $latestrec = wfu_get_file_rec($filepath, true);
1586
- //if $latestrec is null then this means that file does not exist
1587
- if ( $latestrec == null ) return;
1588
- //if the record is obsolete then do not proceed
1589
- if ( $latestrec->idlog != $filerec->idlog ) return;
1590
- }
1591
- else {
1592
- $file_code = wfu_sanitize_code($file_code);
1593
- $dec_file = wfu_get_filepath_from_safe($file_code);
1594
- if ( $dec_file === false ) return;
1595
-
1596
- $filepath = wfu_path_rel2abs(wfu_flatten_path($dec_file));
1597
-
1598
- //check if user is allowed to perform this action
1599
- if ( !wfu_current_user_owes_file($filepath) ) return;
1600
-
1601
- //get file data from database with user data
1602
- $filerec = wfu_get_file_rec($filepath, true);
1603
- if ( $filerec == null ) return;
1604
- }
1605
-
1606
- if ( isset($_POST['submit']) ) {
1607
- if ( $_POST['submit'] == "Update" ) {
1608
- if ( !is_array($filerec->userdata) ) $filerec->userdata = array();
1609
- //check for errors
1610
- $is_error = false;
1611
- foreach ( $filerec->userdata as $userdata ) {
1612
- if ( !isset($_POST['wfu_filedetails_userdata_'.$userdata->propkey]) ) {
1613
- $is_error = true;
1614
- break;
1615
- }
1616
- }
1617
- if ( !$is_error ) {
1618
- $now_date = date('Y-m-d H:i:s');
1619
- $userdata_count = 0;
1620
- foreach ( $filerec->userdata as $userdata ) {
1621
- $userdata_count ++;
1622
- //make existing userdata record obsolete
1623
- $wpdb->update($table_name2,
1624
- array( 'date_to' => $now_date ),
1625
- array( 'uploadid' => $userdata->uploadid, 'propkey' => $userdata->propkey ),
1626
- array( '%s' ),
1627
- array( '%s', '%s' )
1628
- );
1629
- //insert new userdata record
1630
- $wpdb->insert($table_name2,
1631
- array(
1632
- 'uploadid' => $userdata->uploadid,
1633
- 'property' => $userdata->property,
1634
- 'propkey' => $userdata->propkey,
1635
- 'propvalue' => $_POST['wfu_filedetails_userdata_'.$userdata->propkey],
1636
- 'date_from' => $now_date,
1637
- 'date_to' => 0
1638
- ),
1639
- array(
1640
- '%s',
1641
- '%s',
1642
- '%d',
1643
- '%s',
1644
- '%s',
1645
- '%s'
1646
- )
1647
- );
1648
- }
1649
- if ( $userdata_count > 0 ) wfu_log_action('modify:'.$now_date, $filepath, $user->ID, '', 0, 0, '', null);
1650
- }
1651
- if ( isset($_POST['wfu_filedetails_userid']) && $_POST['wfu_filedetails_userid'] != $filerec->uploaduserid ) {
1652
- wfu_log_action('changeuser:'.$_POST['wfu_filedetails_userid'], $filepath, $user->ID, '', 0, 0, '', null);
1653
- }
1654
- }
1655
- }
1656
- return true;
1657
- }
1658
-
1659
- ?>
1
+ <?php
2
+
3
+ /**
4
+ * File Browser Page in Dashboard Area of Plugin
5
+ *
6
+ * This file contains functions related to File Browser page of plugin's
7
+ * Dashboard area.
8
+ *
9
+ * @link /lib/wfu_admin_browser.php
10
+ *
11
+ * @package WordPress File Upload Plugin
12
+ * @subpackage Core Components
13
+ * @since 3.7.1
14
+ */
15
+
16
+ /**
17
+ * Display the File Browser Page.
18
+ *
19
+ * This function displays the File Browser page of the plugin's Dashboard area.
20
+ *
21
+ * @since 2.2.1
22
+ *
23
+ * @param string $basedir_code A code string corresponding to the folder to be
24
+ * displayed.
25
+ * @param integer $page Optional. The page to display in case folder contents
26
+ * are paginated.
27
+ * @param bool $only_table_rows Optional. Return only the HTML code of the table
28
+ * rows.
29
+ *
30
+ * @return string The HTML output of the plugin's File Browser Dashboard page.
31
+ */
32
+ function wfu_browse_files($basedir_code, $page = -1, $only_table_rows = false) {
33
+ $siteurl = site_url();
34
+ $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
35
+ $user = wp_get_current_user();
36
+ //store session variables for use from the downloader
37
+
38
+ if ( !current_user_can( 'manage_options' ) ) return;
39
+
40
+ //first decode basedir_code
41
+ $basedir = wfu_get_filepath_from_safe($basedir_code);
42
+ //clean session array holding dir and file paths if it is too big
43
+ if ( WFU_USVAR_exists('wfu_filepath_safe_storage') && count(WFU_USVAR('wfu_filepath_safe_storage')) > WFU_VAR("WFU_PHP_ARRAY_MAXLEN") ) WFU_USVAR_store('wfu_filepath_safe_storage', array());
44
+
45
+ //basedir may also contain information about the sorting of the displayed
46
+ //elements, as well as a filename that needs to be located and get focus on
47
+ //the browser;
48
+ //sorting information is enclosed in double brackets: [[sort_info]]
49
+ //filename information is enclosed in double braces: {{filename}}
50
+ $sort = "";
51
+ $located_file = "";
52
+ $located_file_found = false;
53
+ $filter = "";
54
+ if ( $basedir !== false ) {
55
+ $ret = wfu_extract_sortdata_from_path($basedir);
56
+ $basedir = $ret['path'];
57
+ $sort = $ret['sort'];
58
+ $located_file = $ret['file'];
59
+ $filter = $ret['filter'];
60
+ }
61
+ if ( $sort == "" ) $sort = 'name';
62
+ if ( substr($sort, 0, 1) == '-' ) $order = SORT_DESC;
63
+ else $order = SORT_ASC;
64
+ //if page is not -1, then do not locate a file
65
+ if ( $located_file != "" && $page > -1 ) $located_file = "";
66
+ //adjust page to be larger than zero
67
+ if ( $page < 1 ) $page = 1;
68
+
69
+ //adjust basedir to have a standard format
70
+ if ( $basedir !== false ) {
71
+ if ( substr($basedir, -1) != '/' ) $basedir .= '/';
72
+ if ( substr($basedir, 0, 1) == '/' ) $basedir = substr($basedir, 1);
73
+ //calculate the absolute path of basedir knowing that basedir is relative to website root
74
+ $basedir = wfu_path_rel2abs($basedir);
75
+ if ( !file_exists($basedir) ) $basedir = false;
76
+ }
77
+ //set basedit to default value if empty
78
+ if ( $basedir === false ) {
79
+ $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
80
+ $basedir = ( isset($plugin_options['basedir']) ? $plugin_options['basedir'] : "" );
81
+ $temp_params = array( 'uploadpath' => $basedir, 'accessmethod' => 'normal', 'ftpinfo' => '', 'useftpdomain' => 'false' );
82
+ $basedir = wfu_upload_plugin_full_path($temp_params);
83
+ }
84
+ //find relative dir
85
+ $reldir = str_replace(wfu_abspath(), "root/", $basedir);
86
+ //save dir route to an array
87
+ $parts = explode('/', $reldir);
88
+ $route = array();
89
+ $prev = "";
90
+ foreach ( $parts as $part ) {
91
+ $part = trim($part);
92
+ if ( $part != "" ) {
93
+ // if ( $part == 'root' && $prev == "" ) $prev = wfu_abspath();
94
+ if ( $part == 'root' && $prev == "" ) $prev = "";
95
+ else $prev .= $part.'/';
96
+ array_push($route, array( 'item' => $part, 'path' => $prev ));
97
+ }
98
+ }
99
+ //calculate upper directory
100
+ $updir = substr($basedir, 0, -1);
101
+ $delim_pos = strrpos($updir, '/');
102
+ if ( $delim_pos !== false ) $updir = substr($updir, 0, $delim_pos + 1);
103
+
104
+ //define referer (with sort data) to point to this url for use by the elements
105
+ $referer = $siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$basedir_code;
106
+ $referer_code = wfu_safe_store_filepath($referer.'[['.$sort.']]');
107
+ //define header parameters that can be later used when defining file actions
108
+ $header_params = array();
109
+
110
+ //find contents of current folder taking into account pagination, if it is
111
+ //activated; contents are found following an optimized procedure as follows:
112
+ // 1. all dirs and files are found and stored in separate arrays
113
+ // 2. if pagination is activated then it is checked if there are any dirs
114
+ // in the current page
115
+ // 3. if dir sorting is name then dirs are sorted
116
+ // 4. if dir sorting is date then stat is called for all dirs and then they
117
+ // are sorted
118
+ // 5. if pagination is activated then dirs array is sliced to keep only the
119
+ // ones belonging to the current page and then stat is called if it has
120
+ // not already been called
121
+ // 6. if there is room in the page for showing files, then files are also
122
+ // processed
123
+ // 7. if file sorting is name then files are sorted
124
+ // 8. if file sorting is date or size then stat is called for all files and
125
+ // then they are sorted
126
+ // 9. if file sorting is user then db record is retrieved for all files and
127
+ // then they are sorted
128
+ // 10. if pagination is activated then files array is sliced to keep only
129
+ // the ones fitting in the page; then stat is called and/or db record is
130
+ // retrieved
131
+ //first calculate dirs and files arrays
132
+ $dirlist = array();
133
+ $dirlist_include = true;
134
+ $dirlist_perpage = array();
135
+ $dirstat_ok = false;
136
+ $filelist = array();
137
+ $filestat_ok = false;
138
+ $filerec_ok = false;
139
+ if ( $handle = opendir($basedir) ) {
140
+ $blacklist = array('.', '..');
141
+ while ( false !== ($file = readdir($handle)) )
142
+ if ( !in_array($file, $blacklist) ) {
143
+ $filepath = $basedir.$file;
144
+ if ( is_dir($filepath) ) array_push($dirlist, array( 'name' => $file, 'fullpath' => $filepath ));
145
+ else array_push($filelist, array( 'name' => $file, 'fullpath' => $filepath ));
146
+ }
147
+ closedir($handle);
148
+ }
149
+ $dirlist_count = count($dirlist);
150
+ $filelist_count = count($filelist);
151
+ //get pagination details and determine if any dirs will be shown
152
+ $maxrows = (int)WFU_VAR("WFU_ADMINBROWSER_TABLE_MAXROWS");
153
+ $files_total = $dirlist_count + $filelist_count;
154
+ if ( $maxrows > 0 ) {
155
+ $pages = max(ceil($files_total / $maxrows), 1);
156
+ if ( $page > $pages ) $page = $pages;
157
+ //if first item index passes number of dirs then do not include dirs
158
+ if ( ($page - 1) * $maxrows >= $dirlist_count ) $dirlist_include = false;
159
+ //if a filename has been defined to get focus, then $dirlist_include
160
+ //needs to be true in order to calculate the dirs of every page
161
+ if ( $located_file != "" ) $dirlist_include = true;
162
+ }
163
+ //process dirs if they are included in page
164
+ if ( $dirlist_include ) {
165
+ //adjust sort details
166
+ $dirsort = ( substr($sort, -4) == 'date' ? 'mdate' : substr($sort, -4) );
167
+ $dirorder = $order;
168
+ if ( $dirsort == 'size' ) { $dirsort = 'name'; $dirorder = SORT_ASC; }
169
+ if ( $dirsort == 'user' ) { $dirsort = 'name'; $dirorder = SORT_ASC; }
170
+ switch ( $dirsort ) {
171
+ case "name": $dirsort .= ":s"; break;
172
+ case "mdate": $dirsort .= ":n"; break;
173
+ }
174
+ //if dir sort is mdate or if a file needs to be located then first
175
+ //calculate stat
176
+ if ( substr($dirsort, 0, 5) == 'mdate' || $located_file != "" ) {
177
+ foreach ( $dirlist as &$dir ) {
178
+ $stat = stat($dir['fullpath']);
179
+ $dir['mdate'] = $stat['mtime'];
180
+ }
181
+ unset($dir);
182
+ $dirstat_ok = true;
183
+ }
184
+ //sort dirs
185
+ $dirlist = wfu_array_sort($dirlist, $dirsort, $dirorder);
186
+ //if pagination is activated then slice dirs array to keep only the
187
+ //items belonging in the current page
188
+ if ( $maxrows > 0 ) {
189
+ //before slicing we store the items in $dirlist_perpage array
190
+ $i = $maxrows;
191
+ $ipage = 0;
192
+ foreach ( $dirlist as $dir ) {
193
+ if ( $i >= $maxrows ) {
194
+ $i = 0;
195
+ $ipage ++;
196
+ $dirlist_perpage[$ipage] = array();
197
+ }
198
+ array_push($dirlist_perpage[$ipage], $dir);
199
+ $i ++;
200
+ }
201
+ //now we slice $dirlist
202
+ $dirlist = array_slice($dirlist, ($page - 1) * $maxrows, $maxrows);
203
+ }
204
+ //calculate stat for the remaining dirs array, if it has not already
205
+ //been done
206
+ if ( !$dirstat_ok ) {
207
+ foreach ( $dirlist as &$dir ) {
208
+ $stat = stat($dir['fullpath']);
209
+ $dir['mdate'] = $stat['mtime'];
210
+ }
211
+ unset($dir);
212
+ }
213
+ }
214
+ else $dirlist = array();
215
+ //determine if any files will be included in page; in case pagination is
216
+ //activated then the remaining places need to be more than zero
217
+ $files_included = ( $maxrows > 0 ? ( $maxrows - count($dirlist) > 0 ) : true );
218
+ //if a filename has been defined to get focus, then $files_included
219
+ //needs to be true in order to re-calculate the page
220
+ if ( $located_file != "" ) $files_included = true;
221
+ if ( $files_included ) {
222
+ //adjust sort details
223
+ $filesort = ( substr($sort, -4) == 'date' ? 'mdate' : substr($sort, -4) );
224
+ switch ( $filesort ) {
225
+ case "name": $filesort .= ":s"; break;
226
+ case "size": $filesort .= ":n"; break;
227
+ case "mdate": $filesort .= ":n"; break;
228
+ case "user": $filesort .= ":s"; break;
229
+ }
230
+ //if file sort is size or mdate then first calculate stat
231
+ if ( substr($filesort, 0, 4) == 'size' || substr($filesort, 0, 5) == 'mdate' ) {
232
+ foreach ( $filelist as &$file ) {
233
+ $stat = stat($file['fullpath']);
234
+ $file['size'] = $stat['size'];
235
+ $file['mdate'] = $stat['mtime'];
236
+ }
237
+ unset($file);
238
+ $filestat_ok = true;
239
+ }
240
+ //if file sort is user then first calculate db records
241
+ elseif ( substr($filesort, 0, 4) == 'user' ) {
242
+ foreach ( $filelist as &$file ) {
243
+ //find relative file record in database together with user data;
244
+ //if the file is php, then file record is null meaning that the file
245
+ //can only be viewed; if file record is not found then the file can
246
+ //again only be viewed
247
+ if ( preg_match("/\.php$/", $file['fullpath']) ) $filerec = null;
248
+ else $filerec = wfu_get_file_rec($file['fullpath'], true);
249
+ //find user who uploaded the file
250
+ $username = ( $filerec != null ? wfu_get_username_by_id($filerec->uploaduserid) : '' );
251
+ $file['user'] = $username;
252
+ $file['filedata'] = $filerec;
253
+ }
254
+ unset($file);
255
+ $filerec_ok = true;
256
+ }
257
+ //sort files
258
+ $filelist = wfu_array_sort($filelist, $filesort, $order);
259
+ //if pagination is activated and a file needs to receive focus, then we
260
+ //need to calculate the page where the file is shown
261
+ if ( $maxrows > 0 && $located_file != "" ) {
262
+ $i = $dirlist_count;
263
+ foreach ( $filelist as $key => $file ) {
264
+ if ( $file['name'] == $located_file ) {
265
+ $located_file_found = true;
266
+ $filelist[$key]['highlighted'] = 1;
267
+ break;
268
+ }
269
+ $i ++;
270
+ }
271
+ if ( $located_file_found ) {
272
+ $page = floor( $i / $maxrows ) + 1;
273
+ if ( isset($dirlist_perpage[$page]) ) $dirlist = $dirlist_perpage[$page];
274
+ else $dirlist = array();
275
+ }
276
+ }
277
+ //if pagination is activated then slice files array to keep only the items
278
+ //belonging in the current page
279
+ if ( $maxrows > 0 )
280
+ $filelist = array_slice($filelist, max(($page - 1) * $maxrows - $dirlist_count, 0), $maxrows - count($dirlist));
281
+ if ( !$filestat_ok || !$filerec_ok ) {
282
+ foreach ( $filelist as &$file ) {
283
+ if ( !$filestat_ok ) {
284
+ $stat = stat($file['fullpath']);
285
+ $file['size'] = $stat['size'];
286
+ $file['mdate'] = $stat['mtime'];
287
+ }
288
+ if ( !$filerec_ok ) {
289
+ if ( preg_match("/\.php$/", $file['fullpath']) ) $filerec = null;
290
+ else $filerec = wfu_get_file_rec($file['fullpath'], true);
291
+ $username = ( $filerec != null ? wfu_get_username_by_id($filerec->uploaduserid) : '' );
292
+ $file['user'] = $username;
293
+ $file['filedata'] = $filerec;
294
+ }
295
+ }
296
+ unset($file);
297
+ }
298
+ }
299
+ else $filelist = array();
300
+
301
+ //start html output
302
+ $echo_str = "";
303
+ if ( !$only_table_rows ) {
304
+ $echo_str .= "\n".'<div class="wrap">';
305
+ $echo_str .= "\n\t".'<h2>Wordpress File Upload Control Panel</h2>';
306
+ $echo_str .= "\n\t".'<div style="margin-top:20px;">';
307
+ $echo_str .= wfu_generate_dashboard_menu("\n\t\t", "File Browser");
308
+ $echo_str .= "\n\t".'<div>';
309
+ $echo_str .= "\n\t\t".'<span><strong>Location:</strong> </span>';
310
+ foreach ( $route as $item ) {
311
+ // store dir path that we need to pass to other functions in session, instead of exposing it in the url
312
+ $dir_code = wfu_safe_store_filepath($item['path']);
313
+ $echo_str .= '<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code.'">'.$item['item'].'</a>';
314
+ $echo_str .= '<span>/</span>';
315
+ }
316
+ //file browser header
317
+ $echo_str .= "\n\t".'</div>';
318
+ // $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.$sort.']]');
319
+ // $echo_str .= "\n\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=create_dir&dir='.$dir_code.'" class="button" title="create folder" style="margin-top:6px">Create folder</a>';
320
+ $echo_str .= "\n\t".'<div style="margin-top:10px; position:relative;">';
321
+ $echo_str .= wfu_add_loading_overlay("\n\t\t", "adminbrowser");
322
+ $adminbrowser_nonce = wp_create_nonce( 'wfu-adminbrowser-page' );
323
+ $echo_str .= "\n\t\t".'<div class="wfu_adminbrowser_header" style="width: 100%;">';
324
+ $bulkactions = array(
325
+ array( "name" => "move", "title" => "Move" ),
326
+ array( "name" => "delete", "title" => "Delete" ),
327
+ array( "name" => "include", "title" => "Include" )
328
+ );
329
+ $echo_str .= wfu_add_bulkactions_header("\n\t\t\t", "adminbrowser", $bulkactions);
330
+ if ( $maxrows > 0 ) {
331
+ $echo_str .= wfu_add_pagination_header("\n\t\t\t", "adminbrowser", $page, $pages, $adminbrowser_nonce);
332
+ }
333
+ $echo_str .= "\n\t\t\t".'<input id="wfu_adminbrowser_action_url" type="hidden" value="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" />';
334
+ $echo_str .= "\n\t\t\t".'<input id="wfu_adminbrowser_code" type="hidden" value="'.$basedir_code.'" />';
335
+ $echo_str .= "\n\t\t\t".'<input id="wfu_adminbrowser_referer" type="hidden" value="'.$referer_code.'" />';
336
+ $echo_str .= "\n\t\t\t".'<input id="wfu_download_file_nonce" type="hidden" value="'.wp_create_nonce('wfu_download_file_invoker').'" />';
337
+ $echo_str .= "\n\t\t\t".'<input id="wfu_include_file_nonce" type="hidden" value="'.wp_create_nonce('wfu_include_file').'" />';
338
+ $echo_str .= "\n\t\t".'</div>';
339
+ $echo_str .= "\n\t\t".'<table id="wfu_adminbrowser_table" class="wfu-adminbrowser wp-list-table widefat fixed striped">';
340
+ $echo_str .= "\n\t\t\t".'<thead>';
341
+ $echo_str .= "\n\t\t\t\t".'<tr>';
342
+ $echo_str .= "\n\t\t\t\t\t".'<td scope="col" width="5%" class="manage-column check-column">';
343
+ $echo_str .= "\n\t\t\t\t\t\t".'<input id="wfu_select_all_visible" type="checkbox" onchange="wfu_adminbrowser_select_all_visible_changed();" style="-webkit-appearance:checkbox;" />';
344
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
345
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="25%" class="manage-column column-primary">';
346
+ $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.( substr($sort, -4) == 'name' ? ( $order == SORT_ASC ? '-name' : 'name' ) : 'name' ).']]');
347
+ $echo_str .= "\n\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code.'">Name'.( substr($sort, -4) == 'name' ? ( $order == SORT_ASC ? ' &uarr;' : ' &darr;' ) : '' ).'</a>';
348
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
349
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column">';
350
+ $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.( substr($sort, -4) == 'size' ? ( $order == SORT_ASC ? '-size' : 'size' ) : 'size' ).']]');
351
+ $echo_str .= "\n\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code.'">Size'.( substr($sort, -4) == 'size' ? ( $order == SORT_ASC ? ' &uarr;' : ' &darr;' ) : '' ).'</a>';
352
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
353
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="20%" class="manage-column">';
354
+ $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.( substr($sort, -4) == 'date' ? ( $order == SORT_ASC ? '-date' : 'date' ) : 'date' ).']]');
355
+ $echo_str .= "\n\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code.'">Date'.( substr($sort, -4) == 'date' ? ( $order == SORT_ASC ? ' &uarr;' : ' &darr;' ) : '' ).'</a>';
356
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
357
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column">';
358
+ $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($basedir).'[['.( substr($sort, -4) == 'user' ? ( $order == SORT_ASC ? '-user' : 'user' ) : 'user' ).']]');
359
+ $echo_str .= "\n\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code.'">Uploaded By'.( substr($sort, -4) == 'user' ? ( $order == SORT_ASC ? ' &uarr;' : ' &darr;' ) : '' ).'</a>';
360
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
361
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="30%" class="manage-column">';
362
+ $echo_str .= "\n\t\t\t\t\t\t".'<label>User Data</label>';
363
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
364
+ $echo_str .= "\n\t\t\t\t".'</tr>';
365
+ $echo_str .= "\n\t\t\t".'</thead>';
366
+ $echo_str .= "\n\t\t\t".'<tbody>';
367
+ }
368
+
369
+ //show subfolders first
370
+ if ( $reldir != "root/" ) {
371
+ $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($updir));
372
+ $echo_str .= "\n\t\t\t\t".'<tr>';
373
+ $echo_str .= "\n\t\t\t\t\t".'<th class="check-column"><input type="checkbox" disabled="disabled" /></th>';
374
+ $echo_str .= "\n\t\t\t\t\t".'<td class="column-primary" data-colname="Name">';
375
+ $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_browser&dir='.$dir_code.'" title="go up">..</a>';
376
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
377
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Size"> </td>';
378
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Date"> </td>';
379
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Uploaded By"> </td>';
380
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="User Data"> </td>';
381
+ $echo_str .= "\n\t\t\t\t".'</tr>';
382
+ }
383
+ $ii = 1;
384
+ foreach ( $dirlist as $dir ) {
385
+ $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($dir['fullpath']).'[['.$sort.']]');
386
+ $echo_str .= "\n\t\t\t\t".'<tr onmouseover="var actions=document.getElementsByName(\'wfu_dir_actions\'); for (var i=0; i<actions.length; i++) {actions[i].style.visibility=\'hidden\';} document.getElementById(\'wfu_dir_actions_'.$ii.'\').style.visibility=\'visible\'" onmouseout="var actions=document.getElementsByName(\'wfu_dir_actions\'); for (var i=0; i<actions.length; i++) {actions[i].style.visibility=\'hidden\';}">';
387
+ $echo_str .= "\n\t\t\t\t\t".'<th class="check-column"><input type="checkbox" disabled="disabled" /></th>';
388
+ $echo_str .= "\n\t\t\t\t\t".'<td class="column-primary" data-colname="Name">';
389
+ $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_browser&dir='.$dir_code.'" title="'.$dir['name'].'">'.$dir['name'].'</a>';
390
+ $echo_str .= "\n\t\t\t\t\t\t".'<div id="wfu_dir_actions_'.$ii.'" name="wfu_dir_actions" style="visibility:hidden;">';
391
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<span style="visibility:hidden;">';
392
+ $echo_str .= "\n\t\t\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir=">Noaction</a>';
393
+ $echo_str .= "\n\t\t\t\t\t\t\t\t".' | ';
394
+ $echo_str .= "\n\t\t\t\t\t\t\t".'</span>';
395
+ // $echo_str .= "\n\t\t\t\t\t\t\t".'<span>';
396
+ // $echo_str .= "\n\t\t\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=rename_dir&file='.$dir_code.'" title="Rename this folder">Rename</a>';
397
+ // $echo_str .= "\n\t\t\t\t\t\t\t\t".' | ';
398
+ // $echo_str .= "\n\t\t\t\t\t\t\t".'</span>';
399
+ // $echo_str .= "\n\t\t\t\t\t\t\t".'<span>';
400
+ // $echo_str .= "\n\t\t\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=delete_dir&file='.$dir_code.'" title="Delete this folder">Delete</a>';
401
+ // $echo_str .= "\n\t\t\t\t\t\t\t".'</span>';
402
+ $echo_str .= "\n\t\t\t\t\t\t".'</div>';
403
+ $echo_str .= "\n\t\t\t\t\t\t".'<button type="button" class="toggle-row"><span class="screen-reader-text">Show more details</span></button>';
404
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
405
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Size"> </td>';
406
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Date">'.get_date_from_gmt(date("Y-m-d H:i:s", $dir['mdate']), "d/m/Y H:i:s").'</td>';
407
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Uploaded By"> </td>';
408
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="User Data"> </td>';
409
+ $echo_str .= "\n\t\t\t\t".'</tr>';
410
+ $ii ++;
411
+ }
412
+ //show contained files
413
+ foreach ( $filelist as $file ) {
414
+ $is_included = ( $file['filedata'] != null );
415
+ $can_be_included = ( $plugin_options['includeotherfiles'] == "1" ) && !wfu_file_extension_blacklisted($file['name']);
416
+ $highlighted = ( isset($file['highlighted']) && $file['highlighted'] == 1 );
417
+ $file_code = '';
418
+ if ( $is_included || $can_be_included ) $file_code = wfu_safe_store_filepath(wfu_path_abs2rel($file['fullpath']).'[['.$sort.']]');
419
+ $echo_str .= "\n\t\t\t\t".'<tr '.( $highlighted ? 'class="wfu-highlighted" ' : '' ).'onmouseover="var actions=document.getElementsByName(\'wfu_file_actions\'); for (var i=0; i<actions.length; i++) {actions[i].style.visibility=\'hidden\';} document.getElementById(\'wfu_file_actions_'.$ii.'\').style.visibility=\'visible\'" onmouseout="var actions=document.getElementsByName(\'wfu_file_actions\'); for (var i=0; i<actions.length; i++) {actions[i].style.visibility=\'hidden\';}">';
420
+ $echo_str .= "\n\t\t\t\t\t".'<th class="check-column">';
421
+ if ( $is_included || $can_be_included ) $echo_str .= "\n\t\t\t\t\t\t".'<input class="wfu_selectors'.( $is_included ? ' wfu_included' : '' ).' wfu_selcode_'.$file_code.'" type="checkbox" onchange="wfu_adminbrowser_selector_changed(this);" />';
422
+ else $echo_str .= "\n\t\t\t\t\t\t".'<input type="checkbox" disabled="disabled" />';
423
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
424
+ $echo_str .= "\n\t\t\t\t\t".'<td class="column-primary" data-colname="Name">';
425
+ if ( $is_included || $can_be_included )
426
+ $echo_str .= "\n\t\t\t\t\t\t".'<a id="wfu_file_link_'.$ii.'" class="row-title" href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_details&file='.$file_code.'" title="View and edit file details" style="font-weight:normal;'.( $is_included ? '' : ' display:none;' ).'">'.$file['name'].'</a>';
427
+ if ( !$is_included )
428
+ $echo_str .= "\n\t\t\t\t\t\t".'<span id="wfu_file_flat_'.$ii.'">'.$file['name'].'</span>';
429
+ //set additional $file properties for generating file actions
430
+ $file["index"] = $ii;
431
+ $file["code"] = $file_code;
432
+ $file["referer_code"] = $referer_code;
433
+ $file_actions = wfu_adminbrowser_file_actions($file, $header_params);
434
+ $echo_str .= "\n\t\t\t\t\t\t".'<div id="wfu_file_actions_'.$ii.'" name="wfu_file_actions" style="visibility:hidden;">';
435
+ if ( $is_included || $can_be_included ) {
436
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<div id="wfu_file_is_included_actions_'.$ii.'" style="display:'.( $is_included ? 'block' : 'none' ).';">';
437
+ //add file actions for files already included
438
+ $array_keys = array_keys($file_actions["is_included"]);
439
+ $lastkey = array_pop($array_keys);
440
+ foreach ( $file_actions["is_included"] as $key => $action ) {
441
+ $echo_str .= "\n\t\t\t\t\t\t\t\t".'<span>';
442
+ foreach ( $action as $line )
443
+ $echo_str .= "\n\t\t\t\t\t\t\t\t\t".$line;
444
+ if ( $key != $lastkey ) $echo_str .= "\n\t\t\t\t\t\t\t\t\t".' | ';
445
+ $echo_str .= "\n\t\t\t\t\t\t\t\t".'</span>';
446
+ }
447
+ $echo_str .= "\n\t\t\t\t\t\t\t".'</div>';
448
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<div id="wfu_file_can_be_included_actions_'.$ii.'" style="display:'.( $is_included ? 'none' : 'block' ).';">';
449
+ //add file actions for files that can be included
450
+ $array_keys = array_keys($file_actions["can_be_included"]);
451
+ $lastkey = array_pop($array_keys);
452
+ foreach ( $file_actions["can_be_included"] as $key => $action ) {
453
+ $echo_str .= "\n\t\t\t\t\t\t\t\t".'<span>';
454
+ foreach ( $action as $line )
455
+ $echo_str .= "\n\t\t\t\t\t\t\t\t\t".$line;
456
+ if ( $key != $lastkey ) $echo_str .= "\n\t\t\t\t\t\t\t\t\t".' | ';
457
+ $echo_str .= "\n\t\t\t\t\t\t\t\t".'</span>';
458
+ }
459
+ $echo_str .= "\n\t\t\t\t\t\t\t".'</div>';
460
+ }
461
+ else {
462
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<span style="visibility:hidden;">';
463
+ $echo_str .= "\n\t\t\t\t\t\t\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir=">Noaction</a>';
464
+ $echo_str .= "\n\t\t\t\t\t\t\t\t".' | ';
465
+ $echo_str .= "\n\t\t\t\t\t\t\t".'</span>';
466
+ }
467
+ $echo_str .= "\n\t\t\t\t\t\t".'</div>';
468
+ $echo_str .= "\n\t\t\t\t\t\t".'<div id="wfu_file_download_container_'.$ii.'" style="display: none;"></div>';
469
+ $echo_str .= "\n\t\t\t\t\t\t".'<button type="button" class="toggle-row"><span class="screen-reader-text">Show more details</span></button>';
470
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
471
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Size">'.$file['size'].'</td>';
472
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Date">'.get_date_from_gmt(date("Y-m-d H:i:s", $file['mdate']), "d/m/Y H:i:s").'</td>';
473
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Uploaded By">'.$file['user'].'</td>';
474
+ $echo_str .= "\n\t\t\t\t\t".'<td data-colname="User Data">';
475
+ if ( $is_included ) {
476
+ if ( is_array($file['filedata']->userdata) && count($file['filedata']->userdata) > 0 ) {
477
+ $echo_str .= "\n\t\t\t\t\t\t".'<select multiple="multiple" style="width:100%; height:40px; background:none; font-size:small;">';
478
+ foreach ( $file['filedata']->userdata as $userdata )
479
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<option>'.$userdata->property.': '.$userdata->propvalue.'</option>';
480
+ $echo_str .= "\n\t\t\t\t\t\t".'</select>';
481
+ }
482
+ }
483
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
484
+ $echo_str .= "\n\t\t\t\t".'</tr>';
485
+ $ii ++;
486
+ }
487
+
488
+ if ( !$only_table_rows ) {
489
+ $echo_str .= "\n\t\t\t".'</tbody>';
490
+ $echo_str .= "\n\t\t".'</table>';
491
+ $echo_str .= "\n\t\t".'<iframe id="wfu_download_frame" style="display: none;"></iframe>';
492
+ $echo_str .= "\n\t".'</div>';
493
+ $echo_str .= "\n\t".'</div>';
494
+ $echo_str .= "\n".'</div>';
495
+ }
496
+ if ( $located_file_found ) {
497
+ $handler = 'function() { wfu_focus_table_on_highlighted_file("wfu_adminbrowser_table"); }';
498
+ $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>';
499
+ }
500
+
501
+ return $echo_str;
502
+ }
503
+
504
+ /**
505
+ * Add Actions to Displayed Files.
506
+ *
507
+ * This function sets the actions that can be applied on the displayed files.
508
+ * Filters can customize these actions.
509
+ *
510
+ * @since 4.1.0
511
+ *
512
+ * @param array $file An array containing properties of the file.
513
+ * @param array $params An array of custom parameters to pass to file actions
514
+ * filter.
515
+ *
516
+ * @return array An array of actions that can be executed on the file.
517
+ */
518
+ function wfu_adminbrowser_file_actions($file, $params) {
519
+ $siteurl = site_url();
520
+ $actions = array(
521
+ "is_included" => array(),
522
+ "can_be_included" => array()
523
+ );
524
+ //add file actions if file is already included
525
+ $actions["is_included"] += array(
526
+ array( '<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_details&file='.$file["code"].'" title="View and edit file details">Details</a>' ),
527
+ array( '<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=rename_file&file='.$file["code"].'" title="Rename this file">Rename</a>' ),
528
+ array( '<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=move_file&file='.$file["code"].'" title="Move this file">Move</a>' ),
529
+ array( '<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=delete_file&file='.$file["code"].'&referer='.$file["referer_code"].'" title="Delete this file">Delete</a>' ),
530
+ array( '<a href="javascript:wfu_download_file(\''.$file["code"].'\', '.$file["index"].');" title="Download this file">Download</a>' )
531
+ );
532
+ //add file actions if file can be included
533
+ $actions["can_be_included"] += array(
534
+ array(
535
+ '<a id="wfu_include_file_'.$file["index"].'_a" href="javascript:wfu_include_file(\''.$file["code"].'\', '.$file["index"].');" title="Include file in plugin\'s database">Include File</a>',
536
+ '<img id="wfu_include_file_'.$file["index"].'_img" src="'.WFU_IMAGE_ADMIN_SUBFOLDER_LOADING.'" style="width:12px; display:none;" />',
537
+ '<input id="wfu_include_file_'.$file["index"].'_inpfail" type="hidden" value="File could not be included!" />'
538
+ )
539
+ );
540
+
541
+ return $actions;
542
+ }
543
+
544
+ /**
545
+ * Check if User Owns a File.
546
+ *
547
+ * This function checks if a user is the owner of a specific file. It will
548
+ * return true if the user in an administrator.
549
+ *
550
+ * @since 3.8.5
551
+ *
552
+ * @param integer $userid The ID of the user to check.
553
+ * @param object $filerec The database record of the file.
554
+ *
555
+ * @return bool True if the user owns the file, false otherwise.
556
+ */
557
+ function wfu_user_owns_file($userid, $filerec) {
558
+ if ( 0 == $userid )
559
+ return false;
560
+ if ( current_user_can('manage_options') ) return true;
561
+ return false;
562
+ }
563
+
564
+ /**
565
+ * Check if Current User Owns a File.
566
+ *
567
+ * This function checks if the current user is the owner of a specific file. It
568
+ * will first check if the file extension is valid.
569
+ *
570
+ * @since 3.0.0
571
+ *
572
+ * @param string $filepath The full path of the file to check.
573
+ * @param object $filerec Optional. The db record of the file, if available.
574
+ *
575
+ * @return bool True if the user owns the file, false otherwise.
576
+ */
577
+ function wfu_current_user_owes_file($filepath, $filerec = null) {
578
+ //first check if file has a restricted extension; for security reasons some
579
+ //file extensions cannot be owned
580
+ if ( wfu_file_extension_blacklisted($filepath) ) return false;
581
+ //then get file data from database, if exist
582
+ if ( $filerec == null ) $filerec = wfu_get_file_rec($filepath, false);
583
+ if ( $filerec == null ) return false;
584
+
585
+ $user = wp_get_current_user();
586
+ return wfu_user_owns_file($user->ID, $filerec);
587
+ }
588
+
589
+ /**
590
+ * Check if Current User is Allowed to Execute an Action on a File.
591
+ *
592
+ * This function checks if the current user is allowed to execute a specific
593
+ * action on a file.
594
+ *
595
+ * @since 2.4.1
596
+ *
597
+ * @param string $action A file action to check.
598
+ * @param string $filepath The full path of the file to check.
599
+ *
600
+ * @return object|null Returns the current WP_User object if current user is
601
+ * allowed to execute the action on the file or null otherwise.
602
+ */
603
+ function wfu_current_user_allowed_action($action, $filepath) {
604
+ //first get file data from database, if exist
605
+ $filerec = wfu_get_file_rec($filepath, false);
606
+
607
+ $user = wp_get_current_user();
608
+ if ( 0 == $user->ID ) return null;
609
+ else $is_admin = current_user_can('manage_options');
610
+ if ( !$is_admin ) {
611
+ return null;
612
+ }
613
+ return $user;
614
+ }
615
+
616
+ /**
617
+ * Check if User is Allowed to Execute an Action on a File.
618
+ *
619
+ * This function checks if a user is allowed to execute a specific action on a
620
+ * file.
621
+ *
622
+ * @since 2.6.0
623
+ *
624
+ * @param string $action A file action to check.
625
+ * @param string $filepath The full path of the file to check.
626
+ * @param integer $userid The ID of the user to check.
627
+ *
628
+ * @return bool|null Returns true if current user is allowed to execute the
629
+ * action on the file or null otherwise.
630
+ */
631
+ function wfu_current_user_allowed_action_remote($action, $filepath, $userid) {
632
+ //first get file data from database, if exist
633
+ $filerec = wfu_get_file_rec($filepath, false);
634
+
635
+ if ( 0 == $userid ) return null;
636
+ else $is_admin = user_can($userid, 'manage_options');
637
+ if ( !$is_admin ) {
638
+ return null;
639
+ }
640
+ return true;
641
+ }
642
+
643
+ /**
644
+ * Confirm Renaming of File.
645
+ *
646
+ * This function shows a page to confirm renaming of a file.
647
+ *
648
+ * @since 2.2.1
649
+ *
650
+ * @param string $file_code A code corresponding to the file/dir to be renamed.
651
+ * @param string $type Rename dir or file. Can take the values 'dir' or 'file'.
652
+ * @param string $error An error message to show on top of the page in case an
653
+ * error occured during renaming.
654
+ *
655
+ * @return string The HTML code of the confirmation page.
656
+ */
657
+ function wfu_rename_file_prompt($file_code, $type, $error) {
658
+ if ( $type == 'dir' ) return;
659
+
660
+ $siteurl = site_url();
661
+
662
+ $is_admin = current_user_can( 'manage_options' );
663
+ //check if user is allowed to view file details
664
+ if ( !$is_admin ) {
665
+ return;
666
+ }
667
+ $file_code = wfu_sanitize_code($file_code);
668
+ $dec_file = wfu_get_filepath_from_safe($file_code);
669
+ if ( $dec_file === false ) return;
670
+
671
+ //first extract sort info from dec_file
672
+ $ret = wfu_extract_sortdata_from_path($dec_file);
673
+ $dec_file = wfu_path_rel2abs($ret['path']);
674
+ if ( $type == 'dir' && substr($dec_file, -1) == '/' ) $dec_file = substr($dec_file, 0, -1);
675
+
676
+ //check if user is allowed to perform this action
677
+ if ( !wfu_current_user_owes_file($dec_file) ) return;
678
+
679
+ $parts = pathinfo($dec_file);
680
+ $newname = $parts['basename'];
681
+ $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($parts['dirname']).'[['.$ret['sort'].']]');
682
+
683
+ $echo_str = "\n".'<div class="wrap">';
684
+ if ( $error ) {
685
+ $rename_file = WFU_USVAR('wfu_rename_file');
686
+ $newname = $rename_file['newname'];
687
+ $echo_str .= "\n\t".'<div class="error">';
688
+ $echo_str .= "\n\t\t".'<p>'.WFU_USVAR('wfu_rename_file_error').'</p>';
689
+ $echo_str .= "\n\t".'</div>';
690
+ }
691
+ $echo_str .= "\n\t".'<div style="margin-top:20px;">';
692
+ if ( $is_admin ) $echo_str .= "\n\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=file_browser&dir='.$dir_code.'" class="button" title="go back">Go back</a>';
693
+ $echo_str .= "\n\t".'</div>';
694
+ $echo_str .= "\n\t".'<h2 style="margin-bottom: 10px;">Rename '.( $type == 'dir' ? 'Folder' : 'File' ).'</h2>';
695
+ if ( $is_admin ) $echo_str .= "\n\t".'<form enctype="multipart/form-data" name="renamefile" id="renamefile" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="validate">';
696
+ $echo_str .= "\n\t\t".'<input type="hidden" name="action" value="rename'.( $type == 'dir' ? 'dir' : 'file' ).'">';
697
+ $echo_str .= "\n\t\t".'<input type="hidden" name="dir" value="'.$dir_code.'">';
698
+ $echo_str .= "\n\t\t".'<input type="hidden" name="file" value="'.$file_code.'">';
699
+ if ( $type == 'dir' ) $echo_str .= "\n\t\t".'<label>Enter new name for folder <strong>'.$dec_file.'</strong></label><br/>';
700
+ elseif ( $is_admin ) $echo_str .= "\n\t\t".'<label>Enter new filename for file <strong>'.$dec_file.'</strong></label><br/>';
701
+ $echo_str .= "\n\t\t".'<input name="wfu_newname" id="wfu_newname" type="text" value="'.$newname.'" style="width:50%;" />';
702
+ $echo_str .= "\n\t\t".'<p class="submit">';
703
+ $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Rename">';
704
+ $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Cancel">';
705
+ $echo_str .= "\n\t\t".'</p>';
706
+ $echo_str .= "\n\t".'</form>';
707
+ $echo_str .= "\n".'</div>';
708
+ return $echo_str;
709
+ }
710
+
711
+ /**
712
+ * Confirm Moving of File.
713
+ *
714
+ * This function shows a page to confirm moving of a file to a new location.
715
+ *
716
+ * @since 4.10.3
717
+ *
718
+ * @param string $file_code A code corresponding to the file to be moved.
719
+ * @param string $error An error message to show on top of the page in case an
720
+ * error occured during move.
721
+ *
722
+ * @return string The HTML code of the confirmation page.
723
+ */
724
+ function wfu_move_file_prompt($file_code, $error) {
725
+ $siteurl = site_url();
726
+
727
+ $is_admin = current_user_can( 'manage_options' );
728
+ //check if user is allowed to view file details
729
+ if ( !$is_admin ) return;
730
+
731
+ if ( !is_array($file_code) ) $file_code = array( $file_code );
732
+ $names = array();
733
+ foreach ( $file_code as $index => $code ) {
734
+ $file_code[$index] = wfu_sanitize_code($code);
735
+ $dec_file = wfu_get_filepath_from_safe($file_code[$index]);
736
+ if ( $dec_file === false ) unset($file_code[$index]);
737
+ else {
738
+ //first extract sort info from dec_file
739
+ $ret = wfu_extract_sortdata_from_path($dec_file);
740
+ $dec_file = $ret['path'];
741
+ $parts = pathinfo($dec_file);
742
+ array_push($names, $parts['basename']);
743
+ }
744
+ }
745
+ if ( count($file_code) == 0 ) return;
746
+ $file_code_list = "list:".implode(",", $file_code);
747
+
748
+ $newpath = $parts['dirname'];
749
+ $replacefiles = "";
750
+ $dir_code = wfu_safe_store_filepath($parts['dirname'].'[['.$ret['sort'].']]');
751
+
752
+ $echo_str = "\n".'<div class="wrap">';
753
+ if ( $error ) {
754
+ $move_file = WFU_USVAR('wfu_move_file');
755
+ $newpath = $move_file['newpath'];
756
+ $replacefiles = $move_file['replacefiles'];
757
+ $echo_str .= "\n\t".'<div class="error">';
758
+ $echo_str .= "\n\t\t".'<p>'.WFU_USVAR('wfu_move_file_error').'</p>';
759
+ $echo_str .= "\n\t".'</div>';
760
+ }
761
+ $echo_str .= "\n\t".'<div style="margin-top:20px;">';
762
+ $echo_str .= "\n\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=file_browser&dir='.$dir_code.'" class="button" title="go back">Go back</a>';
763
+ $echo_str .= "\n\t".'</div>';
764
+ $echo_str .= "\n\t".'<h2 style="margin-bottom: 10px;">Move File</h2>';
765
+ $echo_str .= "\n\t".'<form enctype="multipart/form-data" name="movefile" id="movefile" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="validate">';
766
+ $echo_str .= "\n\t\t".'<input type="hidden" name="action" value="movefile">';
767
+ $echo_str .= "\n\t\t".'<input type="hidden" name="dir" value="'.$dir_code.'">';
768
+ $echo_str .= "\n\t\t".'<input type="hidden" name="file" value="'.$file_code_list.'">';
769
+ if ( count($names) == 1 )
770
+ $echo_str .= "\n\t\t".'<label style="display:inline-block; margin-bottom:1em;">Enter destination folder for file <strong>'.$dec_file.'</strong></label><br/>';
771
+ else {
772
+ $echo_str .= "\n\t\t".'<label>Enter destination folder for files:</label><br/>';
773
+ $echo_str .= "\n\t\t".'<ul style="padding-left: 20px; list-style: initial;">';
774
+ foreach ( $names as $name )
775
+ $echo_str .= "\n\t\t\t".'<li><strong>'.$name.'</strong></li>';
776
+ $echo_str .= "\n\t\t".'</ul>';
777
+ }
778
+ $echo_str .= "\n\t\t".'<input name="wfu_newpath" id="wfu_newpath" type="text" value="'.$newpath.'" style="width:50%;" />';
779
+ $echo_str .= "\n\t\t".'<p>';
780
+ $echo_str .= "\n\t\t\t".'<label>Replace files with the same filename at destination:</label><br />';
781
+ $echo_str .= "\n\t\t\t".'<input name="wfu_replace" id="wfu_replace_yes" type="radio" value="yes"'.( $replacefiles == "yes" ? ' checked="checked"' : '' ).' /><label for="wfu_replace_yes">Yes</label>';
782
+ $echo_str .= "\n\t\t\t".'<input name="wfu_replace" id="wfu_replace_no" type="radio" value="no"'.( $replacefiles == "no" ? ' checked="checked"' : '' ).' style="margin-left:1em;" /><label for="wfu_replace_no">No</label>';
783
+ $echo_str .= "\n\t\t".'</p>';
784
+ $echo_str .= "\n\t\t".'<p class="submit">';
785
+ $echo_str .= "\n\t\t\t".'<input type="button" class="button-primary" name="submitBtn" value="Move" onclick="if (!document.getElementById(\'wfu_replace_yes\').checked && !document.getElementById(\'wfu_replace_no\').checked) alert(\'Please select if files in destination with the same filename will be replaced or not!\'); else this.form.submit();" />';
786
+ $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submitBtn" value="Cancel" />';
787
+ $echo_str .= "\n\t\t".'</p>';
788
+ $echo_str .= "\n\t".'</form>';
789
+ $echo_str .= "\n".'</div>';
790
+ return $echo_str;
791
+ }
792
+
793
+ /**
794
+ * Execute Renaming of File.
795
+ *
796
+ * This function renames a file.
797
+ *
798
+ * @since 2.2.1
799
+ *
800
+ * @param string $file_code A code corresponding to the file/dir to be renamed.
801
+ * @param string $type Rename dir or file. Can take the values 'dir' or 'file'.
802
+ *
803
+ * @return bool True if renaming of file succeeded, false otherwise.
804
+ */
805
+ function wfu_rename_file($file_code, $type) {
806
+ if ( $type == 'dir' ) return;
807
+
808
+ $user = wp_get_current_user();
809
+ $is_admin = current_user_can( 'manage_options' );
810
+ //check if user is allowed to view file details
811
+ if ( !$is_admin ) {
812
+ return;
813
+ }
814
+ $file_code = wfu_sanitize_code($file_code);
815
+ $dec_file = wfu_get_filepath_from_safe($file_code);
816
+ if ( $dec_file === false ) return;
817
+
818
+ $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
819
+ if ( $type == 'dir' && substr($dec_file, -1) == '/' ) $dec_file = substr($dec_file, 0, -1);
820
+ if ( !file_exists($dec_file) ) return;
821
+
822
+ //check if user is allowed to perform this action
823
+ if ( !wfu_current_user_owes_file($dec_file) ) return;
824
+
825
+ $parts = pathinfo($dec_file);
826
+ $error = "";
827
+ if ( isset($_POST['wfu_newname']) && isset($_POST['submit']) ) {
828
+ if ( $_POST['submit'] == "Rename" && $_POST['wfu_newname'] != $parts['basename'] ) {
829
+ $new_file = $parts['dirname'].'/'.$_POST['wfu_newname'];
830
+ if ( $_POST['wfu_newname'] == "" ) $error = 'Error: New '.( $type == 'dir' ? 'folder ' : 'file' ).'name cannot be empty!';
831
+ elseif ( preg_match("/[^A-Za-z0-9_.#\-$]/", $_POST['wfu_newname']) ) $error = 'Error: name contained invalid characters that were stripped off! Please try again.';
832
+ elseif ( substr($_POST['wfu_newname'], -1 - strlen($parts['extension'])) != '.'.$parts['extension'] ) $error = 'Error: new and old file name extensions must be identical! Please correct.';
833
+ elseif ( wfu_file_extension_blacklisted($_POST['wfu_newname']) ) $error = 'Error: the new file name has an extension that is forbidden for security reasons. Please correct.';
834
+ elseif ( file_exists($new_file) ) $error = 'Error: The '.( $type == 'dir' ? 'folder' : 'file' ).' <strong>'.$_POST['wfu_newname'].'</strong> already exists! Please choose another one.';
835
+ else {
836
+ //pre-log rename action
837
+ if ( $type == 'file' ) $retid = wfu_log_action('rename:'.$new_file, $dec_file, $user->ID, '', 0, 0, '', null);
838
+ //perform rename action
839
+ if ( rename($dec_file, $new_file) == false ) $error = 'Error: Rename of '.( $type == 'dir' ? 'folder' : 'file' ).' <strong>'.$parts['basename'].'</strong> failed!';
840
+ //revert log action if file was not renamed
841
+ if ( $type == 'file' && !file_exists($new_file) ) wfu_revert_log_action($retid);
842
+ }
843
+ }
844
+ }
845
+ if ( $error != "" ) {
846
+ WFU_USVAR_store('wfu_rename_file_error', $error);
847
+ $rename_file = WFU_USVAR('wfu_rename_file');
848
+ $rename_file['newname'] = preg_replace("/[^A-Za-z0-9_.#\-$]/", "", $_POST['wfu_newname']);
849
+ WFU_USVAR_store('wfu_rename_file', $rename_file);
850
+ }
851
+ return ( $error == "" );
852
+ }
853
+
854
+ /**
855
+ * Execute Moving of File.
856
+ *
857
+ * This function moves a file to another location.
858
+ *
859
+ * @since 4.10.3
860
+ *
861
+ * @param string $file_code A code corresponding to the file to be moved.
862
+ *
863
+ * @return bool True if move of file succeeded, false otherwise.
864
+ */
865
+ function wfu_move_file($file_code) {
866
+ $user = wp_get_current_user();
867
+ $is_admin = current_user_can( 'manage_options' );
868
+ //check if user is allowed to view file details
869
+ if ( !$is_admin ) return;
870
+
871
+ if ( !is_array($file_code) ) $file_code = array( $file_code );
872
+ $dec_files = array();
873
+ foreach ( $file_code as $index => $code ) {
874
+ $file_code[$index] = wfu_sanitize_code($code);
875
+ $dec_file = wfu_get_filepath_from_safe($file_code[$index]);
876
+ if ( $dec_file !== false ) {
877
+ $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
878
+ array_push($dec_files, $dec_file);
879
+ }
880
+ }
881
+ if ( count($dec_files) == 0 ) return;
882
+
883
+ $parts = pathinfo($dec_files[0]);
884
+ $error = "";
885
+ $regex = "/([^A-Za-z0-9\-._~!$&'()*+,;=:@#\/\\\\%]|%[^A-Fa-f0-9][^A-Fa-f0-9]|%[A-Fa-f0-9][^A-Fa-f0-9]|%[^A-Fa-f0-9][A-Fa-f0-9]|%.?$)/";
886
+ if ( isset($_POST['wfu_newpath']) && isset($_POST['wfu_replace']) ) {
887
+ $oldpath = $parts['dirname'];
888
+ if ( substr($oldpath, -1) != '/' ) $oldpath = $oldpath.'/';
889
+ $newpath = preg_replace($regex, "", $_POST['wfu_newpath']);
890
+ if ( substr($newpath, 0, 1) != '/' ) $newpath = '/'.$newpath;
891
+ $newpath = realpath(wfu_path_rel2abs($newpath));
892
+ if ( substr($newpath, -1) != '/' ) $newpath = $newpath.'/';
893
+ $replacefiles = ( $_POST['wfu_replace'] == 'yes' ? 'yes' : ( $_POST['wfu_replace'] == 'no' ? 'no' : '' ) );
894
+ if ( trim($_POST['wfu_newpath']) == "" ) $error = 'Error: Destination path cannot be empty!';
895
+ elseif ( $newpath == $oldpath ) $error = 'Error: Destination path is the same as source path!';
896
+ elseif ( preg_match($regex, $_POST['wfu_newpath']) ) $error = 'Error: path contained invalid characters that were stripped off! Please try again.';
897
+ elseif ( !file_exists($newpath) ) $error = 'Error: Destination folder <strong>'.$_POST['wfu_newpath'].'</strong> does not exist!';
898
+ elseif ( $replacefiles == "" ) $error = 'Error: Invalid selection about replacing files with same filename at destination!';
899
+ else {
900
+ foreach ( $dec_files as $dec_file ) {
901
+ if ( file_exists($dec_file) ) {
902
+ $new_file = $newpath.wfu_basename($dec_file);
903
+ if ( !file_exists($new_file) || $replacefiles == "yes" ) {
904
+ //pre-log move action
905
+ $retid = wfu_log_action('move:'.$new_file, $dec_file, $user->ID, '', 0, 0, '', null);
906
+ //perform move action
907
+ if ( @rename($dec_file, $new_file) === false || !file_exists($new_file) ) {
908
+ wfu_revert_log_action($retid);
909
+ }
910
+ }
911
+ }
912
+ }
913
+ }
914
+ }
915
+ if ( $error != "" ) {
916
+ WFU_USVAR_store('wfu_move_file_error', $error);
917
+ $move_file = WFU_USVAR('wfu_move_file');
918
+ $move_file['newpath'] = preg_replace($regex, "", $_POST['wfu_newpath']);
919
+ $move_file['replacefiles'] = $replacefiles;
920
+ WFU_USVAR_store('wfu_move_file', $move_file);
921
+ }
922
+ return ( $error == "" );
923
+ }
924
+
925
+ /**
926
+ * Confirm Deletion of File.
927
+ *
928
+ * This function shows a page to confirm deletion of a file.
929
+ *
930
+ * @since 2.2.1
931
+ *
932
+ * @param string $file_code A code corresponding to the file/dir to be deleted.
933
+ * @param string $type Delete dir or file. Can take the values 'dir' or 'file'.
934
+ * @param string $referer The page that initiated the deletion of the file.
935
+ *
936
+ * @return string The HTML code of the confirmation page.
937
+ */
938
+ function wfu_delete_file_prompt($file_code, $type, $referer) {
939
+ if ( $type == 'dir' ) return;
940
+
941
+ $siteurl = site_url();
942
+
943
+ $is_admin = current_user_can( 'manage_options' );
944
+ //check if user is allowed to view file details
945
+ if ( !$is_admin ) {
946
+ return;
947
+ }
948
+ if ( !is_array($file_code) ) $file_code = array( $file_code );
949
+ $names = array();
950
+ foreach ( $file_code as $index => $code ) {
951
+ $file_code[$index] = wfu_sanitize_code($code);
952
+ $dec_file = wfu_get_filepath_from_safe($file_code[$index]);
953
+ if ( $dec_file === false ) unset($file_code[$index]);
954
+ else {
955
+ //first extract sort info from dec_file
956
+ $ret = wfu_extract_sortdata_from_path($dec_file);
957
+ $dec_file = wfu_path_rel2abs($ret['path']);
958
+ if ( $type == 'dir' && substr($dec_file, -1) == '/' ) $dec_file = substr($dec_file, 0, -1);
959
+ //check if user is allowed to perform this action
960
+ if ( !wfu_current_user_owes_file($dec_file) ) unset($file_code[$index]);
961
+ else {
962
+ $parts = pathinfo($dec_file);
963
+ array_push($names, $parts['basename']);
964
+ }
965
+ }
966
+ }
967
+ if ( count($file_code) == 0 ) return;
968
+ $file_code_list = "list:".implode(",", $file_code);
969
+
970
+ $referer_url = wfu_get_filepath_from_safe(wfu_sanitize_code($referer));
971
+ $ret = wfu_extract_sortdata_from_path($referer_url);
972
+ $referer_url = $ret['path'];
973
+
974
+ $echo_str = "\n".'<div class="wrap">';
975
+ $echo_str .= "\n\t".'<div style="margin-top:20px;">';
976
+ if ( $is_admin ) $echo_str .= "\n\t\t".'<a href="'.$referer_url.'" class="button" title="go back">Go back</a>';
977
+ $echo_str .= "\n\t".'</div>';
978
+ $echo_str .= "\n\t".'<h2 style="margin-bottom: 10px;">Delete '.( $type == 'dir' ? 'Folder' : 'File'.( count($names) == 1 ? '' : 's' ) ).'</h2>';
979
+ if ( $is_admin ) $echo_str .= "\n\t".'<form enctype="multipart/form-data" name="deletefile" id="deletefile" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="validate">';
980
+ $echo_str .= "\n\t\t".'<input type="hidden" name="action" value="delete'.( $type == 'dir' ? 'dir' : 'file' ).'">';
981
+ $echo_str .= "\n\t\t".'<input type="hidden" name="referer" value="'.$referer.'">';
982
+ $echo_str .= "\n\t\t".'<input type="hidden" name="file" value="'.$file_code_list.'">';
983
+ if ( count($names) == 1 )
984
+ $echo_str .= "\n\t\t".'<label>Are you sure that you want to delete '.( $type == 'dir' ? 'folder' : 'file' ).' <strong>'.$names[0].'</strong>?</label><br/>';
985
+ else {
986
+ $echo_str .= "\n\t\t".'<label>Are you sure that you want to delete '.( $type == 'dir' ? 'folder' : 'files' ).':';
987
+ $echo_str .= "\n\t\t".'<ul style="padding-left: 20px; list-style: initial;">';
988
+ foreach ( $names as $name )
989
+ $echo_str .= "\n\t\t\t".'<li><strong>'.$name.'</strong></li>';
990
+ $echo_str .= "\n\t\t".'</ul>';
991
+ }
992
+ $echo_str .= "\n\t\t".'<p class="submit">';
993
+ $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Delete">';
994
+ $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Cancel">';
995
+ $echo_str .= "\n\t\t".'</p>';
996
+ $echo_str .= "\n\t".'</form>';
997
+ $echo_str .= "\n".'</div>';
998
+ return $echo_str;
999
+ }
1000
+
1001
+ /**
1002
+ * Execute Deletion of File.
1003
+ *
1004
+ * This function deletes a file.
1005
+ *
1006
+ * @since 2.2.1
1007
+ *
1008
+ * @param string $file_code A code corresponding to the file/dir to be deleted.
1009
+ * @param string $type Delete dir or file. Can take the values 'dir' or 'file'.
1010
+ *
1011
+ * @return bool True if deletion of file succeeded, false otherwise.
1012
+ */
1013
+ function wfu_delete_file($file_code, $type) {
1014
+ if ( $type == 'dir' ) return;
1015
+
1016
+ $user = wp_get_current_user();
1017
+ $is_admin = current_user_can( 'manage_options' );
1018
+ //check if user is allowed to view file details
1019
+ if ( !$is_admin ) {
1020
+ return;
1021
+ }
1022
+ if ( !is_array($file_code) ) $file_code = array( $file_code );
1023
+ $dec_files = array();
1024
+ foreach ( $file_code as $index => $code ) {
1025
+ $file_code[$index] = wfu_sanitize_code($code);
1026
+ $dec_file = wfu_get_filepath_from_safe($file_code[$index]);
1027
+ if ( $dec_file !== false ) {
1028
+ $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
1029
+ if ( $type == 'dir' && substr($dec_file, -1) == '/' ) $dec_file = substr($dec_file, 0, -1);
1030
+ //check if user is allowed to perform this action
1031
+ if ( wfu_current_user_owes_file($dec_file) ) array_push($dec_files, $dec_file);
1032
+ }
1033
+ }
1034
+ if ( count($dec_files) == 0 ) return;
1035
+
1036
+ if ( isset($_POST['submit']) ) {
1037
+ if ( $_POST['submit'] == "Delete" ) {
1038
+ foreach ( $dec_files as $dec_file ) {
1039
+ //pre-log delete action
1040
+ if ( $type == 'file' ) wfu_delete_file_execute($dec_file, $user->ID);
1041
+ elseif ( $type == 'dir' && $dec_file != "" ) wfu_delTree($dec_file);
1042
+ }
1043
+ }
1044
+ }
1045
+ return true;
1046
+ }
1047
+
1048
+ /**
1049
+ * Confirm Creation of a Directory.
1050
+ *
1051
+ * This function shows a page to confirm creation of a directory.
1052
+ *
1053
+ * @since 2.2.1
1054
+ *
1055
+ * @param string $dir_code A code corresponding to the dir to be created.
1056
+ * @param string $error An error message to show on top of the page in case an
1057
+ * error occured during creation.
1058
+ *
1059
+ * @return string The HTML code of the confirmation page.
1060
+ */
1061
+ function wfu_create_dir_prompt($dir_code, $error) {
1062
+ return;
1063
+
1064
+ $siteurl = site_url();
1065
+
1066
+ if ( !current_user_can( 'manage_options' ) ) return;
1067
+
1068
+ $dir_code = wfu_sanitize_code($dir_code);
1069
+ $dec_dir = wfu_get_filepath_from_safe($dir_code);
1070
+ if ( $dec_dir === false ) return;
1071
+
1072
+ //first extract sort info from dec_dir
1073
+ $ret = wfu_extract_sortdata_from_path($dec_dir);
1074
+ $dec_dir = wfu_path_rel2abs($ret['path']);
1075
+ if ( substr($dec_dir, -1) != '/' ) $dec_dir .= '/';
1076
+ $newname = '';
1077
+
1078
+ $echo_str = "\n".'<div class="wrap">';
1079
+ if ( $error ) {
1080
+ $create_dir = WFU_USVAR('wfu_create_dir');
1081
+ $newname = $create_dir['newname'];
1082
+ $echo_str .= "\n\t".'<div class="error">';
1083
+ $echo_str .= "\n\t\t".'<p>'.WFU_USVAR('wfu_create_dir_error').'</p>';
1084
+ $echo_str .= "\n\t".'</div>';
1085
+ }
1086
+ $echo_str .= "\n\t".'<div style="margin-top:20px;">';
1087
+ $echo_str .= "\n\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=file_browser&dir='.$dir_code.'" class="button" title="go back">Go back</a>';
1088
+ $echo_str .= "\n\t".'</div>';
1089
+ $echo_str .= "\n\t".'<h2 style="margin-bottom: 10px;">Create Folder</h2>';
1090
+ $echo_str .= "\n\t".'<form enctype="multipart/form-data" name="createdir" id="createdir" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="validate">';
1091
+ $echo_str .= "\n\t\t".'<input type="hidden" name="action" value="createdir">';
1092
+ $echo_str .= "\n\t\t".'<input type="hidden" name="dir" value="'.$dir_code.'">';
1093
+ $echo_str .= "\n\t\t".'<label>Enter the name of the new folder inside <strong>'.$dec_dir.'</strong></label><br/>';
1094
+ $echo_str .= "\n\t\t".'<input name="wfu_newname" id="wfu_newname" type="text" value="'.$newname.'" style="width:50%;" />';
1095
+ $echo_str .= "\n\t\t".'<p class="submit">';
1096
+ $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Create">';
1097
+ $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Cancel">';
1098
+ $echo_str .= "\n\t\t".'</p>';
1099
+ $echo_str .= "\n\t".'</form>';
1100
+ $echo_str .= "\n".'</div>';
1101
+ return $echo_str;
1102
+ }
1103
+
1104
+ /**
1105
+ * Execute Creation of Directory.
1106
+ *
1107
+ * This function creates a new directory.
1108
+ *
1109
+ * @since 2.2.1
1110
+ *
1111
+ * @param string $dir_code A code corresponding to the dir to be created.
1112
+ *
1113
+ * @return bool True if creation of dir succeeded, false otherwise.
1114
+ */
1115
+ function wfu_create_dir($dir_code) {
1116
+ return;
1117
+
1118
+ if ( !current_user_can( 'manage_options' ) ) return;
1119
+
1120
+ $dir_code = wfu_sanitize_code($dir_code);
1121
+ $dec_dir = wfu_get_filepath_from_safe($dir_code);
1122
+ if ( $dec_dir === false ) return;
1123
+
1124
+ $dec_dir = wfu_path_rel2abs(wfu_flatten_path($dec_dir));
1125
+ if ( substr($dec_dir, -1) != '/' ) $dec_dir .= '/';
1126
+ if ( !file_exists($dec_dir) ) return;
1127
+ $error = "";
1128
+ if ( isset($_POST['wfu_newname']) && isset($_POST['submit']) ) {
1129
+ if ( $_POST['submit'] == "Create" ) {
1130
+ $new_dir = $dec_dir.$_POST['wfu_newname'];
1131
+ if ( $_POST['wfu_newname'] == "" ) $error = 'Error: New folder name cannot be empty!';
1132
+ elseif ( preg_match("/[^A-Za-z0-9_.#\-$]/", $_POST['wfu_newname']) ) $error = 'Error: name contained invalid characters that were stripped off! Please try again.';
1133
+ elseif ( file_exists($new_dir) ) $error = 'Error: The folder <strong>'.$_POST['wfu_newname'].'</strong> already exists! Please choose another one.';
1134
+ elseif ( mkdir($new_dir) == false ) $error = 'Error: Creation of folder <strong>'.$_POST['wfu_newname'].'</strong> failed!';
1135
+ }
1136
+ }
1137
+ if ( $error != "" ) {
1138
+ WFU_USVAR_store('wfu_create_dir_error', $error);
1139
+ $create_dir = WFU_USVAR('wfu_create_dir');
1140
+ $create_dir['newname'] = preg_replace("/[^A-Za-z0-9_.#\-$]/", "", $_POST['wfu_newname']);
1141
+ WFU_USVAR_store('wfu_create_dir', $create_dir);
1142
+ }
1143
+ return ( $error == "" );
1144
+ }
1145
+
1146
+ /**
1147
+ * Confirm Inclusion of File in Plugin's Database.
1148
+ *
1149
+ * This function shows a page to confirm inclusion of a file in plugin's
1150
+ * database.
1151
+ *
1152
+ * @since 3.8.5
1153
+ *
1154
+ * @param string $file_code A code corresponding to the file to be included.
1155
+ * @param string $type Rename dir or file. Can take the values 'dir' or 'file'.
1156
+ * @param string $referer The page that initiated the inclusion of the file.
1157
+ *
1158
+ * @return string The HTML code of the confirmation page.
1159
+ */
1160
+ function wfu_include_file_prompt($file_code, $referer) {
1161
+ if ( !current_user_can( 'manage_options' ) ) return;
1162
+ $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
1163
+ if ( $plugin_options['includeotherfiles'] != "1" ) return;
1164
+
1165
+ $siteurl = site_url();
1166
+ if ( !is_array($file_code) ) $file_code = array( $file_code );
1167
+ $names = array();
1168
+ foreach ( $file_code as $index => $code ) {
1169
+ $file_code[$index] = wfu_sanitize_code($code);
1170
+ $dec_file = wfu_get_filepath_from_safe($file_code[$index]);
1171
+ if ( $dec_file === false ) unset($file_code[$index]);
1172
+ else {
1173
+ $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
1174
+ //do not include file if it has a forbidden extention or it is already included
1175
+ if ( wfu_file_extension_blacklisted(wfu_basename($dec_file)) || wfu_get_file_rec($dec_file, false) != null )
1176
+ unset($file_code[$index]);
1177
+ else array_push($names, wfu_basename($dec_file));
1178
+ }
1179
+ }
1180
+ if ( count($file_code) == 0 ) return;
1181
+ $file_code_list = "list:".implode(",", $file_code);
1182
+
1183
+ $referer_url = wfu_get_filepath_from_safe(wfu_sanitize_code($referer));
1184
+ $ret = wfu_extract_sortdata_from_path($referer_url);
1185
+ $referer_url = $ret['path'];
1186
+
1187
+ $echo_str = "\n".'<div class="wrap">';
1188
+ $echo_str .= "\n\t".'<div style="margin-top:20px;">';
1189
+ $echo_str .= "\n\t\t".'<a href="'.$referer_url.'" class="button" title="go back">Go back</a>';
1190
+ $echo_str .= "\n\t".'</div>';
1191
+ $echo_str .= "\n\t".'<h2 style="margin-bottom: 10px;">Include File'.( count($names) == 1 ? '' : 's' ).'</h2>';
1192
+ $echo_str .= "\n\t".'<form enctype="multipart/form-data" name="includefile" id="includefile" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload" class="validate">';
1193
+ $echo_str .= "\n\t\t".'<input type="hidden" name="action" value="includefile">';
1194
+ $echo_str .= "\n\t\t".'<input type="hidden" name="referer" value="'.$referer.'">';
1195
+ $echo_str .= "\n\t\t".'<input type="hidden" name="file" value="'.$file_code_list.'">';
1196
+ if ( count($names) == 1 )
1197
+ $echo_str .= "\n\t\t".'<label>Are you sure that you want to include file <strong>'.$names[0].'</strong>?</label><br/>';
1198
+ else {
1199
+ $echo_str .= "\n\t\t".'<label>Are you sure that you want to include files:';
1200
+ $echo_str .= "\n\t\t".'<ul style="padding-left: 20px; list-style: initial;">';
1201
+ foreach ( $names as $name )
1202
+ $echo_str .= "\n\t\t\t".'<li><strong>'.$name.'</strong></li>';
1203
+ $echo_str .= "\n\t\t".'</ul>';
1204
+ }
1205
+ $echo_str .= "\n\t\t".'<p class="submit">';
1206
+ $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Include">';
1207
+ $echo_str .= "\n\t\t\t".'<input type="submit" class="button-primary" name="submit" value="Cancel">';
1208
+ $echo_str .= "\n\t\t".'</p>';
1209
+ $echo_str .= "\n\t".'</form>';
1210
+ $echo_str .= "\n".'</div>';
1211
+ return $echo_str;
1212
+ }
1213
+
1214
+ /**
1215
+ * Execute Inclusion of File in Plugin's Database.
1216
+ *
1217
+ * This function includes a file in plugin's database.
1218
+ *
1219
+ * @since 3.8.5
1220
+ *
1221
+ * @param string $file_code A code corresponding to the file to be included.
1222
+ *
1223
+ * @return bool True if inclusion of file succeeded, false otherwise.
1224
+ */
1225
+ function wfu_include_file($file_code) {
1226
+ if ( !current_user_can( 'manage_options' ) ) return;
1227
+ $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
1228
+ if ( $plugin_options['includeotherfiles'] != "1" ) return;
1229
+
1230
+ if ( !is_array($file_code) ) $file_code = array( $file_code );
1231
+ $dec_files = array();
1232
+ foreach ( $file_code as $index => $code ) {
1233
+ $file_code[$index] = wfu_sanitize_code($code);
1234
+ $dec_file = wfu_get_filepath_from_safe($file_code[$index]);
1235
+ if ( $dec_file !== false ) {
1236
+ $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
1237
+ //include file if it does not have a forbidden extention and it not already included
1238
+ if ( !wfu_file_extension_blacklisted(wfu_basename($dec_file)) && wfu_get_file_rec($dec_file, false) == null )
1239
+ array_push($dec_files, $dec_file);
1240
+ }
1241
+ }
1242
+ if ( count($dec_files) == 0 ) return;
1243
+
1244
+ $user = wp_get_current_user();
1245
+ if ( isset($_POST['submit']) ) {
1246
+ if ( $_POST['submit'] == "Include" ) {
1247
+ foreach ( $dec_files as $dec_file )
1248
+ $fileid = wfu_log_action('include', $dec_file, $user->ID, '', '', get_current_blog_id(), '', null);
1249
+ }
1250
+ }
1251
+ return true;
1252
+ }
1253
+
1254
+ /**
1255
+ * Show File Details Page.
1256
+ *
1257
+ * This function shows a page displaying details of the uploaded file.
1258
+ *
1259
+ * @since 2.4.1
1260
+ *
1261
+ * @param string $file_code A code corresponding to the file to be included.
1262
+ * @param string $errorstatus Error status. If it has the value 'error' then an
1263
+ * error will be shown on top of the page.
1264
+ * @param string $invoker Optional. The page URL that initiated file details
1265
+ * page.
1266
+ *
1267
+ * @return string The HTML code of File Details page.
1268
+ */
1269
+ function wfu_file_details($file_code, $errorstatus, $invoker = '') {
1270
+ $siteurl = site_url();
1271
+ $allow_obsolete = false;
1272
+ $file_exists = true;
1273
+ $file_belongs = true;
1274
+ $admin_can_edit = true;
1275
+
1276
+ //if $file_code starts with 'byID:', then it contains a db record ID and not
1277
+ //a file path; in this case we show the properties of the specific record
1278
+ //and all linked ones, even if it is obsolete; this is only allowed for
1279
+ //admins
1280
+ if ( substr($file_code, 0, 5) == "byID:" ) {
1281
+ $allow_obsolete = true;
1282
+ $file_code = substr($file_code, 5);
1283
+ }
1284
+
1285
+ $user = wp_get_current_user();
1286
+ $is_admin = current_user_can( 'manage_options' );
1287
+ //check if user is allowed to view file details
1288
+ if ( !$is_admin ) {
1289
+ if ( $allow_obsolete ) return;
1290
+ return;
1291
+ }
1292
+ if ( $allow_obsolete ) {
1293
+ $file_code = wfu_sanitize_int($file_code);
1294
+ $initialrec = wfu_get_file_rec_from_id($file_code, true);
1295
+ if ( $initialrec == null ) return;
1296
+
1297
+ //get all associated file records
1298
+ $filerecs = wfu_get_rec_new_history($initialrec->idlog);
1299
+ //get the latest record of this upload
1300
+ $filerec = $filerecs[count($filerecs) - 1];
1301
+ $filerec->userdata = $initialrec->userdata;
1302
+
1303
+ $filepath = wfu_path_rel2abs($filerec->filepath);
1304
+ //in the case of $allow_obsolete we need to check if the file exists and
1305
+ //if it belongs to the current record
1306
+ $latestrec = wfu_get_file_rec($filepath, true);
1307
+ $file_exists = ( $latestrec != null );
1308
+ $file_belongs = ( $file_exists && $latestrec->idlog == $filerec->idlog );
1309
+ $admin_can_edit = $file_exists;
1310
+
1311
+ //extract file parts and file properties
1312
+ $parts = pathinfo($filepath);
1313
+ if ( $file_exists ) $stat = stat($filepath);
1314
+ else $stat['mtime'] = '';
1315
+ }
1316
+ else {
1317
+ $file_code = wfu_sanitize_code($file_code);
1318
+ $dec_file = wfu_get_filepath_from_safe($file_code);
1319
+ if ( $dec_file === false ) return;
1320
+
1321
+ //extract file browser data from $file variable
1322
+ $ret = wfu_extract_sortdata_from_path($dec_file);
1323
+ $filepath = wfu_path_rel2abs($ret['path']);
1324
+
1325
+ //check if user is allowed to perform this action
1326
+ if ( !wfu_current_user_owes_file($filepath) ) return;
1327
+
1328
+ //get file data from database with user data
1329
+ $filerec = wfu_get_file_rec($filepath, true);
1330
+ if ( $filerec == null ) return;
1331
+
1332
+ //extract sort info and construct contained dir
1333
+ $parts = pathinfo($filepath);
1334
+ $dir_code = wfu_safe_store_filepath(wfu_path_abs2rel($parts['dirname']).'[['.$ret['sort'].']]');
1335
+
1336
+ $stat = stat($filepath);
1337
+ }
1338
+
1339
+ $echo_str = '<div class="regev_wrap">';
1340
+ if ( $errorstatus == 'error' ) {
1341
+ $echo_str .= "\n\t".'<div class="error">';
1342
+ $echo_str .= "\n\t\t".'<p>'.WFU_USVAR('wfu_filedetails_error').'</p>';
1343
+ $echo_str .= "\n\t".'</div>';
1344
+ }
1345
+ //show file detais
1346
+ $echo_str .= "\n\t".'<h2>Detais of File: '.$parts['basename'].'</h2>';
1347
+ if ( !$file_exists ) {
1348
+ $echo_str .= "\n\t\t".'<div class="notice notice-warning">';
1349
+ $echo_str .= "\n\t\t\t".'<p>File does not exist on the server anymore!</p>';
1350
+ $echo_str .= "\n\t\t".'</div>';
1351
+ }
1352
+ elseif ( !$file_belongs ) {
1353
+ $echo_str .= "\n\t\t".'<div class="notice notice-warning">';
1354
+ $echo_str .= "\n\t\t\t".'<p>This record is old. The file is associated with another record.</p>';
1355
+ $echo_str .= "\n\t\t".'</div>';
1356
+ }
1357
+ $echo_str .= "\n\t".'<div style="margin-top:10px;">';
1358
+ if ( $is_admin ) {
1359
+ $invoker_action = ( $invoker == '' ? false : wfu_get_browser_params_from_safe($invoker) );
1360
+ $goback_action = ( $invoker_action === false ? 'file_browser&dir='.$dir_code : $invoker_action );
1361
+ if ( substr($goback_action, 0, 18) == "wfu_uploaded_files" )
1362
+ $echo_str .= "\n\t\t".'<a href="'.$siteurl.'/wp-admin/admin.php?page='.$goback_action.'" class="button" title="go back">Go back</a>';
1363
+ elseif ( $goback_action != "no_referer" )
1364
+ $echo_str .= "\n\t\t".'<a href="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action='.$goback_action.'" class="button" title="go back">Go back</a>';
1365
+ $echo_str .= "\n\t\t".'<form enctype="multipart/form-data" name="editfiledetails" id="editfiledetails" method="post" action="'.$siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&amp;action=edit_filedetails" class="validate">';
1366
+ }
1367
+ $echo_str .= "\n\t\t\t".'<h3 style="margin-bottom: 10px; margin-top: 40px;">Upload Details</h3>';
1368
+ $echo_str .= "\n\t\t\t".'<input type="hidden" name="action" value="edit_filedetails" />';
1369
+ //$echo_str .= "\n\t\t\t".'<input type="hidden" name="dir" value="'.$dir_code.'">';
1370
+ $echo_str .= "\n\t\t\t".'<input type="hidden" name="invoker" value="'.$invoker.'">';
1371
+ $echo_str .= "\n\t\t\t".'<input type="hidden" name="file" value="'.( $allow_obsolete ? 'byID:'.$file_code : $file_code ).'">';
1372
+ $echo_str .= "\n\t\t\t".'<table class="form-table">';
1373
+ $echo_str .= "\n\t\t\t\t".'<tbody>';
1374
+ if ( $is_admin ) {
1375
+ $echo_str .= "\n\t\t\t\t\t".'<tr>';
1376
+ $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1377
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label>Full Path</label>';
1378
+ $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1379
+ $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1380
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="text" value="'.$filepath.'" readonly="readonly" style="width:50%;" />';
1381
+ $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1382
+ $echo_str .= "\n\t\t\t\t\t".'</tr>';
1383
+ $echo_str .= "\n\t\t\t\t\t".'<tr>';
1384
+ $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1385
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label>Uploaded By User</label>';
1386
+ $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1387
+ $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1388
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<select id="wfu_filedetails_users" disabled="disabled">';
1389
+ //get all users
1390
+ $args = array();
1391
+ /**
1392
+ * Filter Arguments for Getting List of Users.
1393
+ *
1394
+ * This filter allows to customize the arguments passed to get_users()
1395
+ * function to get a list of users. By default the plugin will get a
1396
+ * list of all users. If the website contains too many users this
1397
+ * operation may take time and delay loading of the page. So this filter
1398
+ * can be used to optimize this operation.
1399
+ *
1400
+ * @since 4.11.0
1401
+ *
1402
+ * @param array $args Arguments to retrieve users.
1403
+ * @param string $operation A parameter designating in which operation
1404
+ * the filter is used.
1405
+ */
1406
+ $args = apply_filters("_wfu_get_users", $args, "edit_file_details");
1407
+ $users = get_users($args);
1408
+ foreach ( $users as $userid => $user )
1409
+ $echo_str .= "\n\t\t\t\t\t\t\t\t".'<option value="'.$user->ID.'"'.( $filerec->uploaduserid == $user->ID ? ' selected="selected"' : '' ).'>'.$user->display_name.' ('.$user->user_login.')</option>';
1410
+ $echo_str .= "\n\t\t\t\t\t\t\t".'</select>';
1411
+ if ( $admin_can_edit ) {
1412
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<a class="button" id="btn_change" href="" onclick="document.getElementById(\'wfu_filedetails_users\').disabled = false; this.style.display = \'none\'; document.getElementById(\'btn_ok\').style.display = \'inline-block\'; document.getElementById(\'btn_cancel\').style.display = \'inline-block\'; return false;"'.( $is_admin ? '' : ' style="display:none;"' ).'>Change User</a>';
1413
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<a class="button" id="btn_ok" href="" onclick="document.getElementById(\'wfu_filedetails_users\').disabled = true; document.getElementById(\'btn_change\').style.display = \'inline-block\'; this.style.display=\'none\'; document.getElementById(\'btn_cancel\').style.display = \'none\'; document.getElementById(\'wfu_filedetails_userid\').value = document.getElementById(\'wfu_filedetails_users\').value; wfu_filedetails_changed(); return false;" style="display:none;">Ok</a>';
1414
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<a class="button" id="btn_cancel" href="" onclick="document.getElementById(\'wfu_filedetails_users\').disabled = true; document.getElementById(\'btn_change\').style.display = \'inline-block\'; this.style.display=\'none\'; document.getElementById(\'btn_ok\').style.display = \'none\'; document.getElementById(\'wfu_filedetails_users\').value = document.getElementById(\'wfu_filedetails_userid\').value; return false;" style="display:none;">Cancel</a>';
1415
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="hidden" id="wfu_filedetails_userid" name="wfu_filedetails_userid" value="'.$filerec->uploaduserid.'" />';
1416
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="hidden" id="wfu_filedetails_userid_default" value="'.$filerec->uploaduserid.'" />';
1417
+ }
1418
+ $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1419
+ $echo_str .= "\n\t\t\t\t\t".'</tr>';
1420
+ }
1421
+ $echo_str .= "\n\t\t\t\t\t".'<tr>';
1422
+ $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1423
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label>File Size</label>';
1424
+ $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1425
+ $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1426
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="text" value="'.$filerec->filesize.'" readonly="readonly" style="width:auto;" />';
1427
+ $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1428
+ $echo_str .= "\n\t\t\t\t\t".'</tr>';
1429
+ $echo_str .= "\n\t\t\t\t\t".'<tr>';
1430
+ $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1431
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label>File Date</label>';
1432
+ $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1433
+ $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1434
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="text" value="'.( $file_exists ? get_date_from_gmt(date("Y-m-d H:i:s", $stat['mtime']), "d/m/Y H:i:s") : '' ).'" readonly="readonly" style="width:auto;" />';
1435
+ $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1436
+ $echo_str .= "\n\t\t\t\t\t".'</tr>';
1437
+ $echo_str .= "\n\t\t\t\t\t".'<tr>';
1438
+ $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1439
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label>Uploaded From Page</label>';
1440
+ $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1441
+ $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1442
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="text" value="'.get_the_title($filerec->pageid).' ('.$filerec->pageid.')'.'" readonly="readonly" style="width:50%;" />';
1443
+ $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1444
+ $echo_str .= "\n\t\t\t\t\t".'</tr>';
1445
+ if ( $is_admin ) {
1446
+ $echo_str .= "\n\t\t\t\t\t".'<tr>';
1447
+ $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1448
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label>Upload Plugin ID</label>';
1449
+ $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1450
+ $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1451
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<input type="text" value="'.$filerec->sid.'" readonly="readonly" style="width:auto;" />';
1452
+ $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1453
+ $echo_str .= "\n\t\t\t\t\t".'</tr>';
1454
+ }
1455
+ $echo_str .= "\n\t\t\t\t".'</tbody>';
1456
+ $echo_str .= "\n\t\t\t".'</table>';
1457
+ if ( $is_admin ) {
1458
+ //show history details
1459
+ $echo_str .= "\n\t\t\t".'<h3 style="margin-bottom: 10px; margin-top: 40px;">File History</h3>';
1460
+ $echo_str .= "\n\t\t\t".'<table class="form-table">';
1461
+ $echo_str .= "\n\t\t\t\t".'<tbody>';
1462
+ $echo_str .= "\n\t\t\t\t\t".'<tr>';
1463
+ $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1464
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label></label>';
1465
+ $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1466
+ $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1467
+ //read all linked older records
1468
+ $filerecs = wfu_get_rec_old_history($filerec->idlog);
1469
+ //construct report from db records
1470
+ $rep = '';
1471
+ foreach ( $filerecs as $rec ) {
1472
+ $username = wfu_get_username_by_id($rec->userid);
1473
+ $fileparts = pathinfo($rec->filepath);
1474
+ if ( $rep != '' ) $rep .= "<br />";
1475
+ $rep .= '<strong>['.get_date_from_gmt($rec->date_from).']</strong> ';
1476
+ if ( $rec->action == 'upload' )
1477
+ $rep .= 'File uploaded at <strong>'.$fileparts['dirname'].'</strong> with name <strong>'.$fileparts['basename'].'</strong> by user <strong>'.$username.'</strong>';
1478
+ elseif ( $rec->action == 'include' )
1479
+ $rep .= 'File included in database at <strong>'.$fileparts['dirname'].'</strong> with name <strong>'.$fileparts['basename'].'</strong> by user <strong>'.$username.'</strong>';
1480
+ elseif ( $rec->action == 'download' )
1481
+ $rep .= 'File downloaded by user <strong>'.$username.'</strong>';
1482
+ elseif ( $rec->action == 'rename' )
1483
+ $rep .= 'File renamed to <strong>'.$fileparts['basename'].'</strong> by user <strong>'.$username.'</strong>';
1484
+ elseif ( $rec->action == 'move' )
1485
+ $rep .= 'File moved to <strong>'.$fileparts['dirname'].'</strong> by user <strong>'.$username.'</strong>';
1486
+ elseif ( $rec->action == 'delete' )
1487
+ $rep .= 'File deleted by user <strong>'.$username.'</strong>';
1488
+ elseif ( $rec->action == 'modify' )
1489
+ $rep .= 'File userdata modified by user <strong>'.$username.'</strong>';
1490
+ elseif ( $rec->action == 'changeuser' )
1491
+ $rep .= 'File upload user modified by user <strong>'.$username.'</strong>';
1492
+ }
1493
+ $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;">';
1494
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<span style="white-space:nowrap;">'.$rep.'</span>';
1495
+ $echo_str .= "\n\t\t\t\t\t\t\t".'</div>';
1496
+ $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1497
+ $echo_str .= "\n\t\t\t\t\t".'</tr>';
1498
+ $echo_str .= "\n\t\t\t\t".'</tbody>';
1499
+ $echo_str .= "\n\t\t\t".'</table>';
1500
+ }
1501
+
1502
+ $echo_str .= "\n\t\t\t".'<h3 style="margin-bottom: 10px; margin-top: 40px;">User Data Details</h3>';
1503
+ $echo_str .= "\n\t\t\t".'<table class="form-table">';
1504
+ $echo_str .= "\n\t\t\t\t".'<tbody>';
1505
+ if ( is_array($filerec->userdata) && count($filerec->userdata) > 0 ) {
1506
+ foreach ( $filerec->userdata as $userdata ) {
1507
+ $echo_str .= "\n\t\t\t\t\t".'<tr>';
1508
+ $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1509
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label>'.$userdata->property.'</label>';
1510
+ $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1511
+ $echo_str .= "\n\t\t\t\t\t\t".'<td>';
1512
+ // $echo_str .= "\n\t\t\t\t\t\t\t".'<input id="wfu_filedetails_userdata_value_'.$userdata->propkey.'" name="wfu_filedetails_userdata" type="text"'.( $is_admin ? '' : ' readonly="readonly"' ).' value="'.$userdata->propvalue.'" />';
1513
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<textarea id="wfu_filedetails_userdata_value_'.$userdata->propkey.'" name="wfu_filedetails_userdata" '.( ($is_admin && $admin_can_edit) ? '' : ' readonly="readonly"' ).' value="'.$userdata->propvalue.'">'.$userdata->propvalue.'</textarea>';
1514
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<input id="wfu_filedetails_userdata_default_'.$userdata->propkey.'" type="hidden" value="'.$userdata->propvalue.'" />';
1515
+ $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.'" />';
1516
+ $echo_str .= "\n\t\t\t\t\t\t".'</td>';
1517
+ $echo_str .= "\n\t\t\t\t\t".'</tr>';
1518
+ }
1519
+ }
1520
+ else {
1521
+ $echo_str .= "\n\t\t\t\t\t".'<tr>';
1522
+ $echo_str .= "\n\t\t\t\t\t\t".'<th scope="row">';
1523
+ $echo_str .= "\n\t\t\t\t\t\t\t".'<label>No user data</label>';
1524
+ $echo_str .= "\n\t\t\t\t\t\t".'</th>';
1525
+ $echo_str .= "\n\t\t\t\t\t\t".'<td></td>';
1526
+ $echo_str .= "\n\t\t\t\t\t".'</tr>';
1527
+ }
1528
+ $echo_str .= "\n\t\t\t\t".'</tbody>';
1529
+ $echo_str .= "\n\t\t\t".'</table>';
1530
+ if ( ($is_admin && $admin_can_edit) ) {
1531
+ $echo_str .= "\n\t\t\t".'<p class="submit">';
1532
+ $echo_str .= "\n\t\t\t\t".'<input id="dp_filedetails_submit_fields" type="submit" class="button-primary" name="submit" value="Update" disabled="disabled" />';
1533
+ $echo_str .= "\n\t\t\t".'</p>';
1534
+ }
1535
+ $echo_str .= "\n\t\t".'</form>';
1536
+ $echo_str .= "\n\t".'</div>';
1537
+ $handler = 'function() { wfu_Attach_FileDetails_Admin_Events(); }';
1538
+ $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>';
1539
+ $echo_str .= '</div>';
1540
+
1541
+ return $echo_str;
1542
+ }
1543
+
1544
+ /**
1545
+ * Change File Details.
1546
+ *
1547
+ * This function modifies the database record of an uploaded file, as well as
1548
+ * any associated user data field records.
1549
+ *
1550
+ * @since 2.4.1
1551
+ *
1552
+ * @param string $file_code A code corresponding to the file to be modified.
1553
+ *
1554
+ * @return bool True if modification of file succeeded, false otherwise.
1555
+ */
1556
+ function wfu_edit_filedetails($file_code) {
1557
+ global $wpdb;
1558
+ $table_name2 = $wpdb->prefix . "wfu_userdata";
1559
+ $allow_obsolete = false;
1560
+
1561
+ if ( substr($file_code, 0, 5) == "byID:" ) {
1562
+ $allow_obsolete = true;
1563
+ $file_code = substr($file_code, 5);
1564
+ }
1565
+
1566
+ $user = wp_get_current_user();
1567
+ $is_admin = current_user_can( 'manage_options' );
1568
+ //check if user is allowed to view file details
1569
+ if ( !$is_admin ) {
1570
+ if ( $allow_obsolete ) return;
1571
+ return;
1572
+ }
1573
+ if ( $allow_obsolete ) {
1574
+ $file_code = wfu_sanitize_int($file_code);
1575
+ $initialrec = wfu_get_file_rec_from_id($file_code, true);
1576
+ if ( $initialrec == null ) return;
1577
+
1578
+ //get all associated file records
1579
+ $filerecs = wfu_get_rec_new_history($initialrec->idlog);
1580
+ //get the latest record of this upload
1581
+ $filerec = $filerecs[count($filerecs) - 1];
1582
+ $filerec->userdata = $initialrec->userdata;
1583
+
1584
+ $filepath = wfu_path_rel2abs($filerec->filepath);
1585
+ $latestrec = wfu_get_file_rec($filepath, true);
1586
+ //if $latestrec is null then this means that file does not exist
1587
+ if ( $latestrec == null ) return;
1588
+ //if the record is obsolete then do not proceed
1589
+ if ( $latestrec->idlog != $filerec->idlog ) return;
1590
+ }
1591
+ else {
1592
+ $file_code = wfu_sanitize_code($file_code);
1593
+ $dec_file = wfu_get_filepath_from_safe($file_code);
1594
+ if ( $dec_file === false ) return;
1595
+
1596
+ $filepath = wfu_path_rel2abs(wfu_flatten_path($dec_file));
1597
+
1598
+ //check if user is allowed to perform this action
1599
+ if ( !wfu_current_user_owes_file($filepath) ) return;
1600
+
1601
+ //get file data from database with user data
1602
+ $filerec = wfu_get_file_rec($filepath, true);
1603
+ if ( $filerec == null ) return;
1604
+ }
1605
+
1606
+ if ( isset($_POST['submit']) ) {
1607
+ if ( $_POST['submit'] == "Update" ) {
1608
+ if ( !is_array($filerec->userdata) ) $filerec->userdata = array();
1609
+ //check for errors
1610
+ $is_error = false;
1611
+ foreach ( $filerec->userdata as $userdata ) {
1612
+ if ( !isset($_POST['wfu_filedetails_userdata_'.$userdata->propkey]) ) {
1613
+ $is_error = true;
1614
+ break;
1615
+ }
1616
+ }
1617
+ if ( !$is_error ) {
1618
+ $now_date = date('Y-m-d H:i:s');
1619
+ $userdata_count = 0;
1620
+ foreach ( $filerec->userdata as $userdata ) {
1621
+ $userdata_count ++;
1622
+ //make existing userdata record obsolete
1623
+ $wpdb->update($table_name2,
1624
+ array( 'date_to' => $now_date ),
1625
+ array( 'uploadid' => $userdata->uploadid, 'propkey' => $userdata->propkey ),
1626
+ array( '%s' ),
1627
+ array( '%s', '%s' )
1628
+ );
1629
+ //insert new userdata record
1630
+ $wpdb->insert($table_name2,
1631
+ array(
1632
+ 'uploadid' => $userdata->uploadid,
1633
+ 'property' => $userdata->property,
1634
+ 'propkey' => $userdata->propkey,
1635
+ 'propvalue' => $_POST['wfu_filedetails_userdata_'.$userdata->propkey],
1636
+ 'date_from' => $now_date,
1637
+ 'date_to' => 0
1638
+ ),
1639
+ array(
1640
+ '%s',
1641
+ '%s',
1642
+ '%d',
1643
+ '%s',
1644
+ '%s',
1645
+ '%s'
1646
+ )
1647
+ );
1648
+ }
1649
+ if ( $userdata_count > 0 ) wfu_log_action('modify:'.$now_date, $filepath, $user->ID, '', 0, 0, '', null);
1650
+ }
1651
+ if ( isset($_POST['wfu_filedetails_userid']) && $_POST['wfu_filedetails_userid'] != $filerec->uploaduserid ) {
1652
+ wfu_log_action('changeuser:'.$_POST['wfu_filedetails_userid'], $filepath, $user->ID, '', 0, 0, '', null);
1653
+ }
1654
+ }
1655
+ }
1656
+ return true;
1657
+ }
1658
+
1659
+ ?>
lib/wfu_admin_uploadedfiles.php CHANGED
@@ -1,675 +1,675 @@
1
- <?php
2
-
3
- /**
4
- * Uploaded Files Page in Dashboard Area of Plugin
5
- *
6
- * This file contains functions related to Uploaded Files page of plugin's
7
- * Dashboard area.
8
- *
9
- * @link /lib/wfu_admin_uploadedfiles.php
10
- *
11
- * @package WordPress File Upload Plugin
12
- * @subpackage Core Components
13
- * @since 4.7.0
14
- */
15
-
16
- /**
17
- * Process Dashboard Requests for Uploaded Files Page
18
- *
19
- * This function processes Dashboard requests and shows main Uploaded Files page
20
- * of the plugin.
21
- *
22
- * @since 4.7.0
23
- */
24
- function wfu_uploadedfiles_menu() {
25
- $_GET = stripslashes_deep($_GET);
26
- $tag = (!empty($_GET['tag']) ? $_GET['tag'] : '1');
27
- $page = max((int)$tag, 1);
28
- echo wfu_uploadedfiles_manager($page);
29
- }
30
-
31
- /**
32
- * Display the Uploaded Files Page.
33
- *
34
- * This function displays the Uploaded Files page of the plugin.
35
- *
36
- * @since 4.7.0
37
- *
38
- * @param integer $page Optional. The page to display in case contents are
39
- * paginated.
40
- * @param bool $only_table_rows Optional. Return only the HTML code of the table
41
- * rows.
42
- *
43
- * @return string The HTML output of the plugin's Uploaded Files Dashboard page.
44
- */
45
- function wfu_uploadedfiles_manager($page = 1, $only_table_rows = false) {
46
- global $wpdb;
47
- $table_name1 = $wpdb->prefix . "wfu_log";
48
- $table_name3 = $wpdb->prefix . "wfu_dbxqueue";
49
- $def_other_cols = array( 'upload_date', 'user', 'properties', 'remarks', 'actions' );
50
-
51
- if ( !current_user_can( 'manage_options' ) ) return;
52
-
53
- $siteurl = site_url();
54
- $maxrows = (int)WFU_VAR("WFU_UPLOADEDFILES_TABLE_MAXROWS");
55
-
56
- //get log data from database
57
- //$files_total = $wpdb->get_var('SELECT COUNT(idlog) FROM '.$table_name1.' WHERE action = \'upload\'');
58
- //$filerecs = $wpdb->get_results('SELECT * FROM '.$table_name1.' WHERE action = \'upload\' ORDER BY date_from DESC'.( $maxrows > 0 ? ' LIMIT '.$maxrows.' OFFSET '.(($page - 1) * $maxrows) : '' ));
59
- $files_total = 0;
60
- $filerecs = array();
61
- $has_history = false;
62
- extract(wfu_uploadedfiles_get_filerecs($page));
63
-
64
- //get last record already read
65
- $last_idlog = get_option( "wordpress_file_upload_last_idlog", array( "pre" => 0, "post" => 0, "time" => 0 ) );
66
-
67
- //get visible columns and their order
68
- $cols = array();
69
- $cols_raw = explode(',', WFU_VAR("WFU_UPLOADEDFILES_COLUMNS"));
70
- //normalize column list
71
- foreach ( $cols_raw as $ind => $col ) $cols_raw[$ind] = strtolower(trim($col));
72
- //check if '#' column is visible
73
- $id_visible = in_array('#', $cols_raw);
74
- //'file' column is always visible and follows '#' column
75
- //create an associative array $cols where keys are the columns and values
76
- //are either true for visible columns or false for hidden ones
77
- $visible_cols_count = 0;
78
- foreach ( $cols_raw as $col )
79
- if ( ($key = array_search($col, $def_other_cols)) !== false ) {
80
- unset($def_other_cols[$key]);
81
- $cols[$col] = true;
82
- $visible_cols_count ++;
83
- }
84
- foreach ( $def_other_cols as $col ) $cols[$col] = false;
85
-
86
- //prepare html
87
- $echo_str = "";
88
- if ( !$only_table_rows ) {
89
- //Update last_idlog option so that next time Uploaded Files menu item is
90
- //pressed files have been read.
91
- //Option last_idlog requires a minimum interval of some seconds, defined
92
- //by advanced variable WFU_UPLOADEDFILES_RESET_TIME, before it can be
93
- //updated. This way, if the admin presses Uploaded Files menu item two
94
- //times immediately, the same number of unread files will not change.
95
- //It is noted that last_idlog option uses two values, 'pre' and 'post'.
96
- //The way they are updated makes sure that the number of unread files
97
- //gets reset only when Uploaded Files menu item is pressed and not
98
- //when the admin browses through the pages of the list (when pagination
99
- //is activated).
100
- $limit = (int)WFU_VAR("WFU_UPLOADEDFILES_RESET_TIME");
101
- if ( $limit == -1 || time() > $last_idlog["time"] + $limit ) {
102
- $last_idlog["pre"] = $last_idlog["post"];
103
- $last_idlog["post"] = $wpdb->get_var('SELECT MAX(idlog) FROM '.$table_name1);
104
- $last_idlog["time"] = time();
105
- update_option( "wordpress_file_upload_last_idlog", $last_idlog );
106
- }
107
-
108
- $echo_str .= "\n".'<div class="wrap">';
109
- $echo_str .= "\n\t".'<h2>List of Uploaded Files</h2>';
110
- $echo_str .= "\n\t".'<div style="position:relative;">';
111
- $echo_str .= wfu_add_loading_overlay("\n\t\t", "uploadedfiles");
112
- $echo_str .= "\n\t\t".'<div class="wfu_uploadedfiles_header" style="width: 100%;">';
113
- if ( $maxrows > 0 ) {
114
- $pages = ceil($files_total / $maxrows);
115
- $echo_str .= wfu_add_pagination_header("\n\t\t\t", "uploadedfiles", $page, $pages);
116
- }
117
- $echo_str .= "\n\t\t\t".'<input id="wfu_download_file_nonce" type="hidden" value="'.wp_create_nonce('wfu_download_file_invoker').'" />';
118
- $echo_str .= "\n\t\t".'</div>';
119
- $echo_str .= "\n\t\t".'<table id="wfu_uploadedfiles_table" class="wfu-uploadedfiles wp-list-table widefat fixed striped">';
120
- $echo_str .= "\n\t\t\t".'<thead>';
121
- $echo_str .= "\n\t\t\t\t".'<tr>';
122
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="5%" class="manage-column'.( $id_visible ? '' : ' hidden' ).'">';
123
- $echo_str .= "\n\t\t\t\t\t\t".'<label>#</label>';
124
- $echo_str .= "\n\t\t\t\t\t".'</th>';
125
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="30%" class="manage-column column-primary">';
126
- $echo_str .= "\n\t\t\t\t\t\t".'<label>File</label>';
127
- $echo_str .= "\n\t\t\t\t\t".'</th>';
128
- foreach ( $cols as $col => $is_visible ) {
129
- if ( $col == 'upload_date' ) {
130
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column'.( $is_visible ? '' : ' hidden' ).'">';
131
- $echo_str .= "\n\t\t\t\t\t\t".'<label>Upload Date</label>';
132
- $echo_str .= "\n\t\t\t\t\t".'</th>';
133
- }
134
- elseif ( $col == 'user' ) {
135
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column'.( $is_visible ? '' : ' hidden' ).'">';
136
- $echo_str .= "\n\t\t\t\t\t\t".'<label>User</label>';
137
- $echo_str .= "\n\t\t\t\t\t".'</th>';
138
- }
139
- elseif ( $col == 'properties' ) {
140
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column'.( $is_visible ? '' : ' hidden' ).'">';
141
- $echo_str .= "\n\t\t\t\t\t\t".'<label>Properties</label>';
142
- $echo_str .= "\n\t\t\t\t\t".'</th>';
143
- }
144
- elseif ( $col == 'remarks' ) {
145
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="25%" class="manage-column'.( $is_visible ? '' : ' hidden' ).'">';
146
- $echo_str .= "\n\t\t\t\t\t\t".'<label>Remarks</label>';
147
- $echo_str .= "\n\t\t\t\t\t".'</th>';
148
- }
149
- elseif ( $col == 'actions' ) {
150
- $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column'.( $is_visible ? '' : ' hidden' ).'">';
151
- $echo_str .= "\n\t\t\t\t\t\t".'<label>Actions</label>';
152
- $echo_str .= "\n\t\t\t\t\t".'</th>';
153
- }
154
- }
155
- $echo_str .= "\n\t\t\t\t".'</tr>';
156
- $echo_str .= "\n\t\t\t".'</thead>';
157
- $echo_str .= "\n\t\t\t".'<tbody>';
158
- }
159
- //echo the number of unread uploaded files in order to update the
160
- //notification bubble of the toplevel menu item
161
- $unread_files_count = wfu_get_new_files_count($last_idlog["pre"]);
162
- $echo_str .= "\n\t\t\t".'<!-- wfu_uploadedfiles_unread['.$unread_files_count.'] -->';
163
-
164
- $i = ($page - 1) * $maxrows;
165
- $abspath_notrailing_slash = substr(wfu_abspath(), 0, -1);
166
- $pagecode = wfu_safe_store_browser_params('wfu_uploaded_files&tag='.$page);
167
- $nopagecode = wfu_safe_store_browser_params('no_referer');
168
- foreach ( $filerecs as $filerec ) {
169
- $i ++;
170
- $initialrec = $filerec;
171
- //get all newer associated file records
172
- $historyrecs = array();
173
- if ( $has_history ) $historyrecs = $filerec->history;
174
- else $historyrecs = wfu_get_rec_new_history($initialrec->idlog);
175
- //get the latest record of this upload
176
- $filerec = $historyrecs[count($historyrecs) - 1];
177
- $filedata = wfu_get_filedata_from_rec($filerec, false, true, false);
178
- if ( $filedata == null ) $filedata = array();
179
-
180
- $echo_str .= "\n\t\t\t\t".'<tr class="wfu_row-'.$i.( $initialrec->idlog > $last_idlog["pre"] ? ' wfu_unread' : '' ).'">';
181
- $file_abspath = wfu_path_rel2abs($filerec->filepath);
182
- $file_relpath = ( substr($filerec->filepath, 0, 4) == 'abs:' ? substr($filerec->filepath, 4) : $filerec->filepath );
183
- $displayed_data = array(
184
- "file" => $file_relpath,
185
- "date" => get_date_from_gmt($initialrec->date_from),
186
- "user" => wfu_get_username_by_id($filerec->uploaduserid),
187
- "properties" => '',
188
- "remarks" => '<div class="wfu-remarks-container"></div>',
189
- "actions" => ''
190
- );
191
- $properties = wfu_init_uploadedfiles_properties();
192
- $actions = wfu_init_uploadedfiles_actions();
193
- $remarks = '';
194
- //check if file is stored in FTP location
195
- $file_in_ftp = ( substr($file_abspath, 0, 6) == 'ftp://' || substr($file_abspath, 0, 7) == 'ftps://' || substr($file_abspath, 0, 7) == 'sftp://' );
196
- //check if file resides inside WP root
197
- $file_in_root = ( !$file_in_ftp && substr($file_abspath, 0, strlen($abspath_notrailing_slash)) == $abspath_notrailing_slash );
198
- //check if file exists for non-ftp uploads
199
- $file_exists = ( $file_in_ftp ? true : file_exists($file_abspath) );
200
- //check if record is obsolete
201
- $obsolete = ( $filerec->date_to != "0000-00-00 00:00:00" );
202
- //check if file is associated with Media item
203
- $has_media = ( $file_in_root && $file_exists && !$obsolete && isset($filedata["media"]) );
204
-
205
- //update properties
206
- $properties['status']['icon'] = ( $file_exists ? ( $obsolete ? "obsolete" : "ok" ) : "notexists" );
207
- $properties['userdata']['visible'] = ( count(wfu_get_userdata_from_rec($filerec)) > 0 );
208
- if ( $has_media ) {
209
- $properties['media']['visible'] = true;
210
- $properties['media']['remarks'] = 'File is associated with Media item ID <strong>'.$filedata["media"]["attach_id"].'</strong>';
211
- }
212
- $properties['ftp']['visible'] = $file_in_ftp;
213
- /**
214
- * Customize Uploaded File Properties.
215
- *
216
- * This filter allows scripts to customize the list of properties of an
217
- * uploaded file.
218
- *
219
- * @since 4.8.0
220
- *
221
- * @param array $properties The list of properties of the file.
222
- * @param object $filerec The database record of the uploaded file.
223
- * @param integer $i The file's index in the list of uploaded files.
224
- */
225
- $properties = apply_filters("_wfu_uploadefiles_file_properties", $properties, $filerec, $i);
226
-
227
- //update actions
228
- $details_href_net = $siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_details&file=byID:'.$filerec->idlog;
229
- if ( $actions['details']['allowed'] ) {
230
- $actions['details']['visible'] = true;
231
- $actions['details']['href'] = $details_href_net.'&invoker='.$nopagecode;
232
- }
233
- $media_href = null;
234
- if ( $has_media && $actions['media']['allowed'] ) {
235
- $actions['media']['visible'] = true;
236
- $media_href = get_attachment_link( $filedata["media"]["attach_id"] );
237
- $actions['media']['href'] = $media_href;
238
- }
239
- $adminbrowser_href = false;
240
- if ( $file_in_root && $file_exists && !$obsolete && $actions['adminbrowser']['allowed'] ) {
241
- $only_path = wfu_basedir($file_relpath);
242
- $dir_code = wfu_safe_store_filepath($only_path.'{{'.wfu_basename($file_relpath).'}}');
243
- $adminbrowser_href = $siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code;
244
- $actions['adminbrowser']['visible'] = true;
245
- $actions['adminbrowser']['href'] = $adminbrowser_href;
246
- }
247
- $historylog_href = $siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=view_log&invoker='.$initialrec->idlog;
248
- if ( $actions['historylog']['allowed'] ) {
249
- $actions['historylog']['visible'] = true;
250
- $actions['historylog']['href'] = $historylog_href;
251
- }
252
- $link_href = ( $file_in_root ? site_url().( substr($file_relpath, 0, 1) == '/' ? '' : '/' ) : '' ).$file_relpath;
253
- if ( ( $file_in_ftp || $file_in_root ) && $file_exists && !$obsolete && $actions['link']['allowed'] ) {
254
- $actions['link']['visible'] = true;
255
- $actions['link']['href'] = $link_href;
256
- }
257
- $download_href = false;
258
- if ( !$file_in_ftp && $file_exists && !$obsolete && $actions['download']['allowed'] ) {
259
- $file_code = wfu_safe_store_filepath(wfu_path_abs2rel($file_abspath));
260
- $download_href = 'javascript:wfu_download_file(\''.$file_code.'\', '.$i.');';
261
- $actions['download']['visible'] = true;
262
- $actions['download']['href'] = $download_href;
263
- $actions['download']['newtab'] = false;
264
- }
265
- /**
266
- * Customize Uploaded File Actions.
267
- *
268
- * This filter allows scripts to customize the list of actions of an
269
- * uploaded file.
270
- *
271
- * @since 4.8.0
272
- *
273
- * @param array $actions The list of actions of the file.
274
- * @param object $filerec The database record of the uploaded file.
275
- * @param integer $i The file's index in the list of uploaded files.
276
- */
277
- $actions = apply_filters("_wfu_uploadefiles_file_actions", $actions, $filerec, $i);
278
-
279
- //update default file link action
280
- $default_link = $displayed_data["file"];
281
- if ( WFU_VAR("WFU_UPLOADEDFILES_DEFACTION") == "details" )
282
- $default_link = '<a href="'.$details_href_net.'&invoker='.$pagecode.'" title="Go to file details">'.$file_relpath.'</a>';
283
- elseif ( $file_in_root && $file_exists && !$obsolete && WFU_VAR("WFU_UPLOADEDFILES_DEFACTION") == "adminbrowser" ) {
284
- if ( $adminbrowser_href === false ) {
285
- $only_path = wfu_basedir($file_relpath);
286
- $dir_code = wfu_safe_store_filepath($only_path.'{{'.wfu_basename($file_relpath).'}}');
287
- $adminbrowser_href = $siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code;
288
- }
289
- $default_link = '<a href="'.$adminbrowser_href.'" title="Open file in File Browser">'.$file_relpath.'</a>';
290
- }
291
- elseif ( WFU_VAR("WFU_UPLOADEDFILES_DEFACTION") == "historylog" )
292
- $default_link = '<a href="'.$historylog_href.'" title="Go to View Log record of file">'.$file_relpath.'</a>';
293
- elseif ( ( $file_in_ftp || $file_in_root ) && $file_exists && !$obsolete && WFU_VAR("WFU_UPLOADEDFILES_DEFACTION") == "link" )
294
- $default_link = '<a href="'.$link_href.'" title="Open file link">'.$file_relpath.'</a>';
295
- elseif ( !$file_in_ftp && $file_exists && !$obsolete && WFU_VAR("WFU_UPLOADEDFILES_DEFACTION") == "download" ) {
296
- if ( $download_href === false ) {
297
- $file_code = wfu_safe_store_filepath(wfu_path_abs2rel($file_abspath));
298
- $download_href = 'javascript:wfu_download_file(\''.$file_code.'\', '.$i.');';
299
- }
300
- $default_link = '<a href="'.$download_href.'" title="Download file">'.$file_relpath.'</a>';
301
- }
302
- /**
303
- * Customize Default File Link.
304
- *
305
- * This filter allows scripts to customize the default file link action
306
- * of an uploaded file.
307
- *
308
- * @since 4.8.0
309
- *
310
- * @param string $default_link The default file link action.
311
- * @param object $filerec The database record of the uploaded file.
312
- * @param integer $i The file's index in the list of uploaded files.
313
- */
314
- $default_link = apply_filters("_wfu_uploadefiles_file_link", $default_link, $filerec, $i);
315
-
316
- $displayed_data["file"] = $default_link;
317
- $displayed_data["properties"] = wfu_render_uploadedfiles_properties($properties, $i);
318
- $displayed_data["actions"] = wfu_render_uploadedfiles_actions($actions);
319
- $echo_str .= "\n\t\t\t\t\t".'<th style="word-wrap: break-word;"'.( $id_visible ? '' : ' class="hidden"' ).'>'.$i.'</th>';
320
- $echo_str .= "\n\t\t\t\t\t".'<td class="column-primary" data-colname="File">'.$displayed_data["file"];
321
- $echo_str .= "\n\t\t\t\t\t\t".'<div id="wfu_file_download_container_'.$i.'" style="display: none;"></div>';
322
- if ( $visible_cols_count > 0 ) $echo_str .= "\n\t\t\t\t\t\t".'<button type="button" class="toggle-row"><span class="screen-reader-text">Show more details</span></button>';
323
- $echo_str .= "\n\t\t\t\t\t".'</td>';
324
- foreach ( $cols as $col => $is_visible )
325
- if ( $col == 'upload_date' ) $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Upload Date"'.( $is_visible ? '' : ' class="hidden"' ).'>'.$displayed_data["date"].'</td>';
326
- elseif ( $col == 'user' ) $echo_str .= "\n\t\t\t\t\t".'<td data-colname="User"'.( $is_visible ? '' : ' class="hidden"' ).'>'.$displayed_data["user"].'</td>';
327
- elseif ( $col == 'properties' ) $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Properties"'.( $is_visible ? '' : ' class="hidden"' ).'>'.$displayed_data["properties"].'</td>';
328
- elseif ( $col == 'remarks' ) $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Remarks"'.( $is_visible ? '' : ' class="hidden"' ).'>'.$displayed_data["remarks"].'</td>';
329
- elseif ( $col == 'actions' ) $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Actions"'.( $is_visible ? '' : ' class="hidden"' ).'>'.$displayed_data["actions"].'</td>';
330
- $echo_str .= "\n\t\t\t\t".'</tr>';
331
- }
332
- if ( !$only_table_rows ) {
333
- $echo_str .= "\n\t\t\t".'</tbody>';
334
- $echo_str .= "\n\t\t".'</table>';
335
- $echo_str .= "\n\t".'</div>';
336
- $handler = 'function() { wfu_attach_uploadedfiles_events(); }';
337
- $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>';
338
- $echo_str .= "\n".'</div>';
339
- }
340
-
341
- /**
342
- * Customize Uploaded Files Page Output.
343
- *
344
- * This filter allows scripts to customize the HTML code of Uploaded Files
345
- * Dashboard page.
346
- *
347
- * @since 4.8.0
348
- *
349
- * @param string $echo_str The HTML code of Uploaded Files page.
350
- * @param integer $page The current shown page of uploaded files list.
351
- * @param bool $only_table_rows Return only HTML code of table rows.
352
- */
353
- $echo_str = apply_filters("_wfu_uploadedfiles_output", $echo_str, $page, $only_table_rows);
354
- return $echo_str;
355
- }
356
-
357
- /**
358
- * Get List of Uploaded Files.
359
- *
360
- * This function returns the list of uploaded files to be displayed in Uploaded
361
- * Files Dashboard page.
362
- *
363
- * @since 4.9.1
364
- *
365
- * @redeclarable
366
- *
367
- * @param integer $page The page number where the uploaded files belong.
368
- *
369
- * @return array An array holding the list of uploaded files.
370
- */
371
- function wfu_uploadedfiles_get_filerecs($page) {
372
- $a = func_get_args(); $a = WFU_FUNCTION_HOOK(__FUNCTION__, $a, $out); if (isset($out['vars'])) foreach($out['vars'] as $p => $v) $$p = $v; switch($a) { case 'R': return $out['output']; break; case 'D': die($out['output']); }
373
- global $wpdb;
374
- $table_name1 = $wpdb->prefix . "wfu_log";
375
- $maxrows = (int)WFU_VAR("WFU_UPLOADEDFILES_TABLE_MAXROWS");
376
- $ret = array(
377
- "files_total" => 0,
378
- "filerecs" => array(),
379
- "has_history" => false
380
- );
381
-
382
- if ( WFU_VAR("WFU_UPLOADEDFILES_HIDEINVALID") != "true" ) {
383
- $ret["files_total"] = $wpdb->get_var('SELECT COUNT(idlog) FROM '.$table_name1.' WHERE action = \'upload\'');
384
- $ret["filerecs"] = $wpdb->get_results('SELECT * FROM '.$table_name1.' WHERE action = \'upload\' ORDER BY date_from DESC'.( $maxrows > 0 ? ' LIMIT '.$maxrows.' OFFSET '.(($page - 1) * $maxrows) : '' ));
385
- }
386
- else {
387
- $filerecs = $wpdb->get_results('SELECT * FROM '.$table_name1.' WHERE action = \'upload\' ORDER BY date_from DESC');
388
- foreach ( $filerecs as $ind => $filerec ) {
389
- $initialrec = $filerec;
390
- //get all newer associated file records
391
- $historyrecs = wfu_get_rec_new_history($initialrec->idlog);
392
- //get the latest record of this upload
393
- $filerec = $historyrecs[count($historyrecs) - 1];
394
- $file_abspath = wfu_path_rel2abs($filerec->filepath);
395
- //check if file is stored in FTP location
396
- $file_in_ftp = ( substr($file_abspath, 0, 6) == 'ftp://' || substr($file_abspath, 0, 7) == 'ftps://' || substr($file_abspath, 0, 7) == 'sftp://' );
397
- //check if file exists for non-ftp uploads
398
- $file_exists = ( $file_in_ftp ? true : file_exists($file_abspath) );
399
- //check if record is obsolete
400
- $obsolete = ( $filerec->date_to != "0000-00-00 00:00:00" );
401
- if ( !$file_exists || $obsolete ) unset($filerecs[$ind]);
402
- else $filerecs[$ind]->history = $historyrecs;
403
- }
404
- $ret["files_total"] = count($filerecs);
405
- if ( $maxrows > 0 ) $filerecs = array_slice($filerecs, ($page - 1) * $maxrows, $maxrows);
406
- $ret["filerecs"] = $filerecs;
407
- $ret["has_history"] = true;
408
- }
409
-
410
- return $ret;
411
- }
412
-
413
- /**
414
- * Generate Default List of Properties of an Uploaded File.
415
- *
416
- * This function generates the list of default properties of an uploaded file.
417
- * Each property has an icon, a title (when the mouse hovers over the icon) and
418
- * remarks (shown in Remarks column when the mouse hovers over the icon).
419
- *
420
- * @since 4.7.0
421
- *
422
- * @return array An array of properties of an uploaded file.
423
- */
424
- function wfu_init_uploadedfiles_properties() {
425
- $props["status"] = array(
426
- "icon" => "obsolete",
427
- "icon-list" => array(
428
- "ok" => "dashicons-yes",
429
- "notexists" => "dashicons-trash",
430
- "obsolete" => "dashicons-warning"
431
- ),
432
- "title" => "",
433
- "title-list" => array(
434
- "ok" => "File is Ok",
435
- "notexists" => "File does not exist",
436
- "obsolete" => "Record is invalid"
437
- ),
438
- "visible" => true,
439
- "remarks" => '',
440
- "remarks-list" => array(
441
- "ok" => "File uploaded successfully to the website",
442
- "notexists" => "File does not exist anymore in the website",
443
- "obsolete" => "Record is not valid anymore"
444
- ),
445
- "code" => wfu_create_random_string(6)
446
- );
447
- $props["userdata"] = array(
448
- "icon" => "dashicons-id-alt",
449
- "title" => "File has user data",
450
- "visible" => false,
451
- "remarks" => 'File has user data, accessible in File Details',
452
- "code" => wfu_create_random_string(6)
453
- );
454
- $props["media"] = array(
455
- "icon" => "dashicons-admin-media",
456
- "title" => "File is associated with Media item",
457
- "visible" => false,
458
- "remarks" => 'File is associated with Media item',
459
- "code" => wfu_create_random_string(6)
460
- );
461
- $props["ftp"] = array(
462
- "icon" => "wfu-dashicons-ftp",
463
- "title" => "File saved in FTP",
464
- "visible" => false,
465
- "remarks" => 'File has been saved in FTP location',
466
- "code" => wfu_create_random_string(6)
467
- );
468
-
469
- return $props;
470
- }
471
-
472
- /**
473
- * Generate Default List of Actions of an Uploaded File.
474
- *
475
- * This function generates the list of default actions of an uploaded file. Each
476
- * action has an icon, a title (when the mouse hovers over the icon) and a link
477
- * URL (the action itself).
478
- *
479
- * @since 4.7.0
480
- *
481
- * @return array An array of properties of an uploaded file.
482
- */
483
- function wfu_init_uploadedfiles_actions() {
484
- $def_actions["details"] = array(
485
- "icon" => "dashicons-info",
486
- "title" => "View file details",
487
- "allowed" => false,
488
- "visible" => false,
489
- "href" => "",
490
- "newtab" => true,
491
- "color" => "default"
492
- );
493
- $def_actions["media"] = array(
494
- "icon" => "wfu-dashicons-media-external",
495
- "title" => "Open associated Media item",
496
- "allowed" => false,
497
- "visible" => false,
498
- "href" => "",
499
- "newtab" => true,
500
- "color" => "default"
501
- );
502
- $def_actions["adminbrowser"] = array(
503
- "icon" => "dashicons-portfolio",
504
- "title" => "Locate file in File Browser",
505
- "allowed" => false,
506
- "visible" => false,
507
- "href" => "",
508
- "newtab" => true,
509
- "color" => "default"
510
- );
511
- $def_actions["historylog"] = array(
512
- "icon" => "dashicons-backup",
513
- "title" => "Locate file record in View Log",
514
- "allowed" => false,
515
- "visible" => false,
516
- "href" => "",
517
- "newtab" => true,
518
- "color" => "default"
519
- );
520
- $def_actions["link"] = array(
521
- "icon" => "dashicons-external",
522
- "title" => "Open file link",
523
- "allowed" => false,
524
- "visible" => false,
525
- "href" => "",
526
- "newtab" => true,
527
- "color" => "default"
528
- );
529
- $def_actions["download"] = array(
530
- "icon" => "dashicons-download",
531
- "title" => "Download file",
532
- "allowed" => false,
533
- "visible" => false,
534
- "href" => "",
535
- "newtab" => true,
536
- "color" => "default"
537
- );
538
-
539
- //get visible actions and their order
540
- $actions = array();
541
- $actions_raw = explode(',', WFU_VAR("WFU_UPLOADEDFILES_ACTIONS"));
542
- //normalize action list
543
- foreach ( $actions_raw as $ind => $action ) $actions_raw[$ind] = strtolower(trim($action));
544
- //generate associative array of actions adjusting order and 'allowed'
545
- //property
546
- foreach ( $actions_raw as $ind => $action )
547
- if ( isset($def_actions[$action]) ) {
548
- $actions[$action] = $def_actions[$action];
549
- $actions[$action]['allowed'] = true;
550
- unset($def_actions[$action]);
551
- }
552
- foreach ( $def_actions as $action => $props ) $actions[$action] = $props;
553
-
554
- return $actions;
555
- }
556
-
557
- /**
558
- * Display Properties of an Uploaded File.
559
- *
560
- * This function generates the HTML code of the properties of an uploaded file
561
- * that will be shown in Properties column.
562
- *
563
- * @since 4.7.0
564
- *
565
- * @redeclarable
566
- *
567
- * @param array $props The properties of the uploaded file.
568
- * @param integer $index The index of the uploaded file.
569
- *
570
- * @return string The HTML code of the properties of an uploaded file.
571
- */
572
- function wfu_render_uploadedfiles_properties($props, $index) {
573
- $a = func_get_args(); switch(WFU_FUNCTION_HOOK(__FUNCTION__, $a, $out)) { case 'X': break; case 'R': return $out; break; case 'D': die($out); break; }
574
- $i = 0;
575
- $echo_str = "";
576
- foreach ( $props as $key => $prop ) {
577
- $ii = $i + 1;
578
- $iconclass = $prop['icon'];
579
- if ( isset($prop['icon-list']) ) $iconclass = $prop['icon-list'][$prop['icon']];
580
- $title = $prop['title'];
581
- if ( isset($prop['title-list']) ) $title = $prop['title-list'][$prop['icon']];
582
- $remarks = $prop['remarks'];
583
- if ( isset($prop['remarks-list']) ) $remarks = $prop['remarks-list'][$prop['icon']];
584
- $echo_str .= '<div id="p_'.$index.'_'.$ii.'" class="wfu-properties dashicons '.$iconclass.( $i == 0 ? '' : ' wfu-dashicons-after' ).( $prop['visible'] ? '' : ' wfu-dashicons-hidden' ).'" title="'.$title.'"><input type="hidden" class="wfu-remarks" value="'.wfu_plugin_encode_string($remarks).'" /></div>';
585
- $i ++;
586
- }
587
-
588
- return $echo_str;
589
- }
590
-
591
- /**
592
- * Display Actions of an Uploaded File.
593
- *
594
- * This function generates the HTML code of the actions of an uploaded file that
595
- * will be shown in Actions column.
596
- *
597
- * @since 4.7.0
598
- *
599
- * @redeclarable
600
- *
601
- * @param array $actions The actions of the uploaded file.
602
- *
603
- * @return string The HTML code of the actions of an uploaded file.
604
- */
605
- function wfu_render_uploadedfiles_actions($actions) {
606
- $a = func_get_args(); switch(WFU_FUNCTION_HOOK(__FUNCTION__, $a, $out)) { case 'X': break; case 'R': return $out; break; case 'D': die($out); break; }
607
- $i = 0;
608
- $echo_str = "";
609
- foreach ( $actions as $key => $action ) {
610
- $iconclass = $action['icon'];
611
- if ( isset($action['icon-list']) ) $iconclass = $action['icon-list'][$action['icon']];
612
- $title = $action['title'];
613
- if ( isset($action['title-list']) ) $title = $action['title-list'][$action['icon']];
614
- $echo_str .= '<a class="dashicons '.$iconclass.( $i == 0 ? '' : ' wfu-dashicons-after' ).( $action['visible'] ? '' : ' wfu-dashicons-hidden' ).'" href="'.$action['href'].'" target="'.( !isset($action['newtab']) || $action['newtab'] ? '_blank' : '_self' ).'" title="'.$title.'"'.( isset($action['color']) && $action['color'] != 'default' ? ' style="color:'.$action['color'].';"' : '' ).'></a>';
615
- $i ++;
616
- }
617
-
618
- return $echo_str;
619
- }
620
-
621
- /**
622
- * Display Unread Uploaded File in Admin Bar.
623
- *
624
- * This function displays the number of unread uploaded files in Admin Bar.
625
- *
626
- * @since 4.8.0
627
- */
628
- function wfu_admin_toolbar_new_uploads() {
629
- global $wp_admin_bar;
630
-
631
- if ( WFU_VAR("WFU_UPLOADEDFILES_BARMENU") == "true" ) {
632
- //get the number of new (unread) uploaded files
633
- $unread_files_count = wfu_get_unread_files_count();
634
- $text = $unread_files_count;
635
- if ( $unread_files_count > 99 ) $text = "99+";
636
- $title = ( $unread_files_count == 0 ? 'No new files uploaded' : ( $unread_files_count == 1 ? '1 new file uploaded' : $unread_files_count.' files uploaded' ) );
637
-
638
- $args = array(
639
- 'id' => 'wfu_uploads',
640
- 'title' => '<span class="ab-icon"></span><span class="ab-label">'.$unread_files_count.'</span><span class="screen-reader-text">'.$title.'</span>',
641
- 'href' => admin_url( 'admin.php?page=wfu_uploaded_files' ),
642
- 'group' => false,
643
- 'meta' => array(
644
- 'title' => $title,
645
- 'class' => ( $unread_files_count == 0 && WFU_VAR("WFU_UPLOADEDFILES_BARAUTOHIDE") == "true" ? 'hidden' : '' )
646
- ),
647
- );
648
- $wp_admin_bar->add_menu( $args );
649
- }
650
- }
651
-
652
- /**
653
- * Display Files Per Page in Uploaded Files Screen Options.
654
- *
655
- * This function displays the number of uploaded files per page to display in
656
- * the screen options section of Uploaded Files Dashboard page.
657
- *
658
- * @since 4.8.0
659
- */
660
- function wfu_uploadedfiles_screen_options() {
661
- global $wfu_uploadedfiles_hook_suffix;
662
-
663
- $screen = get_current_screen();
664
- // get out of here if we are not on uploadedfiles page
665
- if( !is_object($screen) || $screen->id != $wfu_uploadedfiles_hook_suffix ) return;
666
-
667
- $args = array(
668
- 'label' => 'Files per page',
669
- 'default' => WFU_VAR("WFU_UPLOADEDFILES_TABLE_MAXROWS"),
670
- 'option' => 'wfu_uploadedfiles_per_page'
671
- );
672
- add_screen_option( 'per_page', $args );
673
- }
674
-
675
- ?>
1
+ <?php
2
+
3
+ /**
4
+ * Uploaded Files Page in Dashboard Area of Plugin
5
+ *
6
+ * This file contains functions related to Uploaded Files page of plugin's
7
+ * Dashboard area.
8
+ *
9
+ * @link /lib/wfu_admin_uploadedfiles.php
10
+ *
11
+ * @package WordPress File Upload Plugin
12
+ * @subpackage Core Components
13
+ * @since 4.7.0
14
+ */
15
+
16
+ /**
17
+ * Process Dashboard Requests for Uploaded Files Page
18
+ *
19
+ * This function processes Dashboard requests and shows main Uploaded Files page
20
+ * of the plugin.
21
+ *
22
+ * @since 4.7.0
23
+ */
24
+ function wfu_uploadedfiles_menu() {
25
+ $_GET = stripslashes_deep($_GET);
26
+ $tag = (!empty($_GET['tag']) ? $_GET['tag'] : '1');
27
+ $page = max((int)$tag, 1);
28
+ echo wfu_uploadedfiles_manager($page);
29
+ }
30
+
31
+ /**
32
+ * Display the Uploaded Files Page.
33
+ *
34
+ * This function displays the Uploaded Files page of the plugin.
35
+ *
36
+ * @since 4.7.0
37
+ *
38
+ * @param integer $page Optional. The page to display in case contents are
39
+ * paginated.
40
+ * @param bool $only_table_rows Optional. Return only the HTML code of the table
41
+ * rows.
42
+ *
43
+ * @return string The HTML output of the plugin's Uploaded Files Dashboard page.
44
+ */
45
+ function wfu_uploadedfiles_manager($page = 1, $only_table_rows = false) {
46
+ global $wpdb;
47
+ $table_name1 = $wpdb->prefix . "wfu_log";
48
+ $table_name3 = $wpdb->prefix . "wfu_dbxqueue";
49
+ $def_other_cols = array( 'upload_date', 'user', 'properties', 'remarks', 'actions' );
50
+
51
+ if ( !current_user_can( 'manage_options' ) ) return;
52
+
53
+ $siteurl = site_url();
54
+ $maxrows = (int)WFU_VAR("WFU_UPLOADEDFILES_TABLE_MAXROWS");
55
+
56
+ //get log data from database
57
+ //$files_total = $wpdb->get_var('SELECT COUNT(idlog) FROM '.$table_name1.' WHERE action = \'upload\'');
58
+ //$filerecs = $wpdb->get_results('SELECT * FROM '.$table_name1.' WHERE action = \'upload\' ORDER BY date_from DESC'.( $maxrows > 0 ? ' LIMIT '.$maxrows.' OFFSET '.(($page - 1) * $maxrows) : '' ));
59
+ $files_total = 0;
60
+ $filerecs = array();
61
+ $has_history = false;
62
+ extract(wfu_uploadedfiles_get_filerecs($page));
63
+
64
+ //get last record already read
65
+ $last_idlog = get_option( "wordpress_file_upload_last_idlog", array( "pre" => 0, "post" => 0, "time" => 0 ) );
66
+
67
+ //get visible columns and their order
68
+ $cols = array();
69
+ $cols_raw = explode(',', WFU_VAR("WFU_UPLOADEDFILES_COLUMNS"));
70
+ //normalize column list
71
+ foreach ( $cols_raw as $ind => $col ) $cols_raw[$ind] = strtolower(trim($col));
72
+ //check if '#' column is visible
73
+ $id_visible = in_array('#', $cols_raw);
74
+ //'file' column is always visible and follows '#' column
75
+ //create an associative array $cols where keys are the columns and values
76
+ //are either true for visible columns or false for hidden ones
77
+ $visible_cols_count = 0;
78
+ foreach ( $cols_raw as $col )
79
+ if ( ($key = array_search($col, $def_other_cols)) !== false ) {
80
+ unset($def_other_cols[$key]);
81
+ $cols[$col] = true;
82
+ $visible_cols_count ++;
83
+ }
84
+ foreach ( $def_other_cols as $col ) $cols[$col] = false;
85
+
86
+ //prepare html
87
+ $echo_str = "";
88
+ if ( !$only_table_rows ) {
89
+ //Update last_idlog option so that next time Uploaded Files menu item is
90
+ //pressed files have been read.
91
+ //Option last_idlog requires a minimum interval of some seconds, defined
92
+ //by advanced variable WFU_UPLOADEDFILES_RESET_TIME, before it can be
93
+ //updated. This way, if the admin presses Uploaded Files menu item two
94
+ //times immediately, the same number of unread files will not change.
95
+ //It is noted that last_idlog option uses two values, 'pre' and 'post'.
96
+ //The way they are updated makes sure that the number of unread files
97
+ //gets reset only when Uploaded Files menu item is pressed and not
98
+ //when the admin browses through the pages of the list (when pagination
99
+ //is activated).
100
+ $limit = (int)WFU_VAR("WFU_UPLOADEDFILES_RESET_TIME");
101
+ if ( $limit == -1 || time() > $last_idlog["time"] + $limit ) {
102
+ $last_idlog["pre"] = $last_idlog["post"];
103
+ $last_idlog["post"] = $wpdb->get_var('SELECT MAX(idlog) FROM '.$table_name1);
104
+ $last_idlog["time"] = time();
105
+ update_option( "wordpress_file_upload_last_idlog", $last_idlog );
106
+ }
107
+
108
+ $echo_str .= "\n".'<div class="wrap">';
109
+ $echo_str .= "\n\t".'<h2>List of Uploaded Files</h2>';
110
+ $echo_str .= "\n\t".'<div style="position:relative;">';
111
+ $echo_str .= wfu_add_loading_overlay("\n\t\t", "uploadedfiles");
112
+ $echo_str .= "\n\t\t".'<div class="wfu_uploadedfiles_header" style="width: 100%;">';
113
+ if ( $maxrows > 0 ) {
114
+ $pages = ceil($files_total / $maxrows);
115
+ $echo_str .= wfu_add_pagination_header("\n\t\t\t", "uploadedfiles", $page, $pages);
116
+ }
117
+ $echo_str .= "\n\t\t\t".'<input id="wfu_download_file_nonce" type="hidden" value="'.wp_create_nonce('wfu_download_file_invoker').'" />';
118
+ $echo_str .= "\n\t\t".'</div>';
119
+ $echo_str .= "\n\t\t".'<table id="wfu_uploadedfiles_table" class="wfu-uploadedfiles wp-list-table widefat fixed striped">';
120
+ $echo_str .= "\n\t\t\t".'<thead>';
121
+ $echo_str .= "\n\t\t\t\t".'<tr>';
122
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="5%" class="manage-column'.( $id_visible ? '' : ' hidden' ).'">';
123
+ $echo_str .= "\n\t\t\t\t\t\t".'<label>#</label>';
124
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
125
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="30%" class="manage-column column-primary">';
126
+ $echo_str .= "\n\t\t\t\t\t\t".'<label>File</label>';
127
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
128
+ foreach ( $cols as $col => $is_visible ) {
129
+ if ( $col == 'upload_date' ) {
130
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column'.( $is_visible ? '' : ' hidden' ).'">';
131
+ $echo_str .= "\n\t\t\t\t\t\t".'<label>Upload Date</label>';
132
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
133
+ }
134
+ elseif ( $col == 'user' ) {
135
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column'.( $is_visible ? '' : ' hidden' ).'">';
136
+ $echo_str .= "\n\t\t\t\t\t\t".'<label>User</label>';
137
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
138
+ }
139
+ elseif ( $col == 'properties' ) {
140
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column'.( $is_visible ? '' : ' hidden' ).'">';
141
+ $echo_str .= "\n\t\t\t\t\t\t".'<label>Properties</label>';
142
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
143
+ }
144
+ elseif ( $col == 'remarks' ) {
145
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="25%" class="manage-column'.( $is_visible ? '' : ' hidden' ).'">';
146
+ $echo_str .= "\n\t\t\t\t\t\t".'<label>Remarks</label>';
147
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
148
+ }
149
+ elseif ( $col == 'actions' ) {
150
+ $echo_str .= "\n\t\t\t\t\t".'<th scope="col" width="10%" class="manage-column'.( $is_visible ? '' : ' hidden' ).'">';
151
+ $echo_str .= "\n\t\t\t\t\t\t".'<label>Actions</label>';
152
+ $echo_str .= "\n\t\t\t\t\t".'</th>';
153
+ }
154
+ }
155
+ $echo_str .= "\n\t\t\t\t".'</tr>';
156
+ $echo_str .= "\n\t\t\t".'</thead>';
157
+ $echo_str .= "\n\t\t\t".'<tbody>';
158
+ }
159
+ //echo the number of unread uploaded files in order to update the
160
+ //notification bubble of the toplevel menu item
161
+ $unread_files_count = wfu_get_new_files_count($last_idlog["pre"]);
162
+ $echo_str .= "\n\t\t\t".'<!-- wfu_uploadedfiles_unread['.$unread_files_count.'] -->';
163
+
164
+ $i = ($page - 1) * $maxrows;
165
+ $abspath_notrailing_slash = substr(wfu_abspath(), 0, -1);
166
+ $pagecode = wfu_safe_store_browser_params('wfu_uploaded_files&tag='.$page);
167
+ $nopagecode = wfu_safe_store_browser_params('no_referer');
168
+ foreach ( $filerecs as $filerec ) {
169
+ $i ++;
170
+ $initialrec = $filerec;
171
+ //get all newer associated file records
172
+ $historyrecs = array();
173
+ if ( $has_history ) $historyrecs = $filerec->history;
174
+ else $historyrecs = wfu_get_rec_new_history($initialrec->idlog);
175
+ //get the latest record of this upload
176
+ $filerec = $historyrecs[count($historyrecs) - 1];
177
+ $filedata = wfu_get_filedata_from_rec($filerec, false, true, false);
178
+ if ( $filedata == null ) $filedata = array();
179
+
180
+ $echo_str .= "\n\t\t\t\t".'<tr class="wfu_row-'.$i.( $initialrec->idlog > $last_idlog["pre"] ? ' wfu_unread' : '' ).'">';
181
+ $file_abspath = wfu_path_rel2abs($filerec->filepath);
182
+ $file_relpath = ( substr($filerec->filepath, 0, 4) == 'abs:' ? substr($filerec->filepath, 4) : $filerec->filepath );
183
+ $displayed_data = array(
184
+ "file" => $file_relpath,
185
+ "date" => get_date_from_gmt($initialrec->date_from),
186
+ "user" => wfu_get_username_by_id($filerec->uploaduserid),
187
+ "properties" => '',
188
+ "remarks" => '<div class="wfu-remarks-container"></div>',
189
+ "actions" => ''
190
+ );
191
+ $properties = wfu_init_uploadedfiles_properties();
192
+ $actions = wfu_init_uploadedfiles_actions();
193
+ $remarks = '';
194
+ //check if file is stored in FTP location
195
+ $file_in_ftp = ( substr($file_abspath, 0, 6) == 'ftp://' || substr($file_abspath, 0, 7) == 'ftps://' || substr($file_abspath, 0, 7) == 'sftp://' );
196
+ //check if file resides inside WP root
197
+ $file_in_root = ( !$file_in_ftp && substr($file_abspath, 0, strlen($abspath_notrailing_slash)) == $abspath_notrailing_slash );
198
+ //check if file exists for non-ftp uploads
199
+ $file_exists = ( $file_in_ftp ? true : file_exists($file_abspath) );
200
+ //check if record is obsolete
201
+ $obsolete = ( $filerec->date_to != "0000-00-00 00:00:00" );
202
+ //check if file is associated with Media item
203
+ $has_media = ( $file_in_root && $file_exists && !$obsolete && isset($filedata["media"]) );
204
+
205
+ //update properties
206
+ $properties['status']['icon'] = ( $file_exists ? ( $obsolete ? "obsolete" : "ok" ) : "notexists" );
207
+ $properties['userdata']['visible'] = ( count(wfu_get_userdata_from_rec($filerec)) > 0 );
208
+ if ( $has_media ) {
209
+ $properties['media']['visible'] = true;
210
+ $properties['media']['remarks'] = 'File is associated with Media item ID <strong>'.$filedata["media"]["attach_id"].'</strong>';
211
+ }
212
+ $properties['ftp']['visible'] = $file_in_ftp;
213
+ /**
214
+ * Customize Uploaded File Properties.
215
+ *
216
+ * This filter allows scripts to customize the list of properties of an
217
+ * uploaded file.
218
+ *
219
+ * @since 4.8.0
220
+ *
221
+ * @param array $properties The list of properties of the file.
222
+ * @param object $filerec The database record of the uploaded file.
223
+ * @param integer $i The file's index in the list of uploaded files.
224
+ */
225
+ $properties = apply_filters("_wfu_uploadefiles_file_properties", $properties, $filerec, $i);
226
+
227
+ //update actions
228
+ $details_href_net = $siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_details&file=byID:'.$filerec->idlog;
229
+ if ( $actions['details']['allowed'] ) {
230
+ $actions['details']['visible'] = true;
231
+ $actions['details']['href'] = $details_href_net.'&invoker='.$nopagecode;
232
+ }
233
+ $media_href = null;
234
+ if ( $has_media && $actions['media']['allowed'] ) {
235
+ $actions['media']['visible'] = true;
236
+ $media_href = get_attachment_link( $filedata["media"]["attach_id"] );
237
+ $actions['media']['href'] = $media_href;
238
+ }
239
+ $adminbrowser_href = false;
240
+ if ( $file_in_root && $file_exists && !$obsolete && $actions['adminbrowser']['allowed'] ) {
241
+ $only_path = wfu_basedir($file_relpath);
242
+ $dir_code = wfu_safe_store_filepath($only_path.'{{'.wfu_basename($file_relpath).'}}');
243
+ $adminbrowser_href = $siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code;
244
+ $actions['adminbrowser']['visible'] = true;
245
+ $actions['adminbrowser']['href'] = $adminbrowser_href;
246
+ }
247
+ $historylog_href = $siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=view_log&invoker='.$initialrec->idlog;
248
+ if ( $actions['historylog']['allowed'] ) {
249
+ $actions['historylog']['visible'] = true;
250
+ $actions['historylog']['href'] = $historylog_href;
251
+ }
252
+ $link_href = ( $file_in_root ? site_url().( substr($file_relpath, 0, 1) == '/' ? '' : '/' ) : '' ).$file_relpath;
253
+ if ( ( $file_in_ftp || $file_in_root ) && $file_exists && !$obsolete && $actions['link']['allowed'] ) {
254
+ $actions['link']['visible'] = true;
255
+ $actions['link']['href'] = $link_href;
256
+ }
257
+ $download_href = false;
258
+ if ( !$file_in_ftp && $file_exists && !$obsolete && $actions['download']['allowed'] ) {
259
+ $file_code = wfu_safe_store_filepath(wfu_path_abs2rel($file_abspath));
260
+ $download_href = 'javascript:wfu_download_file(\''.$file_code.'\', '.$i.');';
261
+ $actions['download']['visible'] = true;
262
+ $actions['download']['href'] = $download_href;
263
+ $actions['download']['newtab'] = false;
264
+ }
265
+ /**
266
+ * Customize Uploaded File Actions.
267
+ *
268
+ * This filter allows scripts to customize the list of actions of an
269
+ * uploaded file.
270
+ *
271
+ * @since 4.8.0
272
+ *
273
+ * @param array $actions The list of actions of the file.
274
+ * @param object $filerec The database record of the uploaded file.
275
+ * @param integer $i The file's index in the list of uploaded files.
276
+ */
277
+ $actions = apply_filters("_wfu_uploadefiles_file_actions", $actions, $filerec, $i);
278
+
279
+ //update default file link action
280
+ $default_link = $displayed_data["file"];
281
+ if ( WFU_VAR("WFU_UPLOADEDFILES_DEFACTION") == "details" )
282
+ $default_link = '<a href="'.$details_href_net.'&invoker='.$pagecode.'" title="Go to file details">'.$file_relpath.'</a>';
283
+ elseif ( $file_in_root && $file_exists && !$obsolete && WFU_VAR("WFU_UPLOADEDFILES_DEFACTION") == "adminbrowser" ) {
284
+ if ( $adminbrowser_href === false ) {
285
+ $only_path = wfu_basedir($file_relpath);
286
+ $dir_code = wfu_safe_store_filepath($only_path.'{{'.wfu_basename($file_relpath).'}}');
287
+ $adminbrowser_href = $siteurl.'/wp-admin/options-general.php?page=wordpress_file_upload&action=file_browser&dir='.$dir_code;
288
+ }
289
+ $default_link = '<a href="'.$adminbrowser_href.'" title="Open file in File Browser">'.$file_relpath.'</a>';
290
+ }
291
+ elseif ( WFU_VAR("WFU_UPLOADEDFILES_DEFACTION") == "historylog" )
292
+ $default_link = '<a href="'.$historylog_href.'" title="Go to View Log record of file">'.$file_relpath.'</a>';
293
+ elseif ( ( $file_in_ftp || $file_in_root ) && $file_exists && !$obsolete && WFU_VAR("WFU_UPLOADEDFILES_DEFACTION") == "link" )
294
+ $default_link = '<a href="'.$link_href.'" title="Open file link">'.$file_relpath.'</a>';
295
+ elseif ( !$file_in_ftp && $file_exists && !$obsolete && WFU_VAR("WFU_UPLOADEDFILES_DEFACTION") == "download" ) {
296
+ if ( $download_href === false ) {
297
+ $file_code = wfu_safe_store_filepath(wfu_path_abs2rel($file_abspath));
298
+ $download_href = 'javascript:wfu_download_file(\''.$file_code.'\', '.$i.');';
299
+ }
300
+ $default_link = '<a href="'.$download_href.'" title="Download file">'.$file_relpath.'</a>';
301
+ }
302
+ /**
303
+ * Customize Default File Link.
304
+ *
305
+ * This filter allows scripts to customize the default file link action
306
+ * of an uploaded file.
307
+ *
308
+ * @since 4.8.0
309
+ *
310
+ * @param string $default_link The default file link action.
311
+ * @param object $filerec The database record of the uploaded file.
312
+ * @param integer $i The file's index in the list of uploaded files.
313
+ */
314
+ $default_link = apply_filters("_wfu_uploadefiles_file_link", $default_link, $filerec, $i);
315
+
316
+ $displayed_data["file"] = $default_link;
317
+ $displayed_data["properties"] = wfu_render_uploadedfiles_properties($properties, $i);
318
+ $displayed_data["actions"] = wfu_render_uploadedfiles_actions($actions);
319
+ $echo_str .= "\n\t\t\t\t\t".'<th style="word-wrap: break-word;"'.( $id_visible ? '' : ' class="hidden"' ).'>'.$i.'</th>';
320
+ $echo_str .= "\n\t\t\t\t\t".'<td class="column-primary" data-colname="File">'.$displayed_data["file"];
321
+ $echo_str .= "\n\t\t\t\t\t\t".'<div id="wfu_file_download_container_'.$i.'" style="display: none;"></div>';
322
+ if ( $visible_cols_count > 0 ) $echo_str .= "\n\t\t\t\t\t\t".'<button type="button" class="toggle-row"><span class="screen-reader-text">Show more details</span></button>';
323
+ $echo_str .= "\n\t\t\t\t\t".'</td>';
324
+ foreach ( $cols as $col => $is_visible )
325
+ if ( $col == 'upload_date' ) $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Upload Date"'.( $is_visible ? '' : ' class="hidden"' ).'>'.$displayed_data["date"].'</td>';
326
+ elseif ( $col == 'user' ) $echo_str .= "\n\t\t\t\t\t".'<td data-colname="User"'.( $is_visible ? '' : ' class="hidden"' ).'>'.$displayed_data["user"].'</td>';
327
+ elseif ( $col == 'properties' ) $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Properties"'.( $is_visible ? '' : ' class="hidden"' ).'>'.$displayed_data["properties"].'</td>';
328
+ elseif ( $col == 'remarks' ) $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Remarks"'.( $is_visible ? '' : ' class="hidden"' ).'>'.$displayed_data["remarks"].'</td>';
329
+ elseif ( $col == 'actions' ) $echo_str .= "\n\t\t\t\t\t".'<td data-colname="Actions"'.( $is_visible ? '' : ' class="hidden"' ).'>'.$displayed_data["actions"].'</td>';
330
+ $echo_str .= "\n\t\t\t\t".'</tr>';
331
+ }
332
+ if ( !$only_table_rows ) {
333
+ $echo_str .= "\n\t\t\t".'</tbody>';
334
+ $echo_str .= "\n\t\t".'</table>';
335
+ $echo_str .= "\n\t".'</div>';
336
+ $handler = 'function() { wfu_attach_uploadedfiles_events(); }';
337
+ $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>';
338
+ $echo_str .= "\n".'</div>';
339
+ }
340
+
341
+ /**
342
+ * Customize Uploaded Files Page Output.
343
+ *
344
+ * This filter allows scripts to customize the HTML code of Uploaded Files
345
+ * Dashboard page.
346
+ *
347
+ * @since 4.8.0
348
+ *
349
+ * @param string $echo_str The HTML code of Uploaded Files page.
350
+ * @param integer $page The current shown page of uploaded files list.
351
+ * @param bool $only_table_rows Return only HTML code of table rows.
352
+ */
353
+ $echo_str = apply_filters("_wfu_uploadedfiles_output", $echo_str, $page, $only_table_rows);
354
+ return $echo_str;
355
+ }
356
+
357
+ /**
358
+ * Get List of Uploaded Files.
359
+ *
360
+ * This function returns the list of uploaded files to be displayed in Uploaded
361
+ * Files Dashboard page.
362
+ *
363
+ * @since 4.9.1
364
+ *
365
+ * @redeclarable
366
+ *
367
+ * @param integer $page The page number where the uploaded files belong.
368
+ *
369
+ * @return array An array holding the list of uploaded files.
370
+ */
371
+ function wfu_uploadedfiles_get_filerecs($page) {
372
+ $a = func_get_args(); $a = WFU_FUNCTION_HOOK(__FUNCTION__, $a, $out); if (isset($out['vars'])) foreach($out['vars'] as $p => $v) $$p = $v; switch($a) { case 'R': return $out['output']; break; case 'D': die($out['output']); }
373
+ global $wpdb;
374
+ $table_name1 = $wpdb->prefix . "wfu_log";
375
+ $maxrows = (int)WFU_VAR("WFU_UPLOADEDFILES_TABLE_MAXROWS");
376
+ $ret = array(
377
+ "files_total" => 0,
378
+ "filerecs" => array(),
379
+ "has_history" => false
380
+ );
381
+
382
+ if ( WFU_VAR("WFU_UPLOADEDFILES_HIDEINVALID") != "true" ) {
383
+ $ret["files_total"] = $wpdb->get_var('SELECT COUNT(idlog) FROM '.$table_name1.' WHERE action = \'upload\'');
384
+ $ret["filerecs"] = $wpdb->get_results('SELECT * FROM '.$table_name1.' WHERE action = \'upload\' ORDER BY date_from DESC'.( $maxrows > 0 ? ' LIMIT '.$maxrows.' OFFSET '.(($page - 1) * $maxrows) : '' ));
385
+ }
386
+ else {
387
+ $filerecs = $wpdb->get_results('SELECT * FROM '.$table_name1.' WHERE action = \'upload\' ORDER BY date_from DESC');
388
+ foreach ( $filerecs as $ind => $filerec ) {
389
+ $initialrec = $filerec;
390
+ //get all newer associated file records
391
+ $historyrecs = wfu_get_rec_new_history($initialrec->idlog);
392
+ //get the latest record of this upload
393
+ $filerec = $historyrecs[count($historyrecs) - 1];
394
+ $file_abspath = wfu_path_rel2abs($filerec->filepath);
395
+ //check if file is stored in FTP location
396
+ $file_in_ftp = ( substr($file_abspath, 0, 6) == 'ftp://' || substr($file_abspath, 0, 7) == 'ftps://' || substr($file_abspath, 0, 7) == 'sftp://' );
397
+ //check if file exists for non-ftp uploads
398
+ $file_exists = ( $file_in_ftp ? true : file_exists($file_abspath) );
399
+ //check if record is obsolete
400
+ $obsolete = ( $filerec->date_to != "0000-00-00 00:00:00" );
401
+ if ( !$file_exists || $obsolete ) unset($filerecs[$ind]);
402
+ else $filerecs[$ind]->history = $historyrecs;
403
+ }
404
+ $ret["files_total"] = count($filerecs);
405
+ if ( $maxrows > 0 ) $filerecs = array_slice($filerecs, ($page - 1) * $maxrows, $maxrows);
406
+ $ret["filerecs"] = $filerecs;
407
+ $ret["has_history"] = true;
408
+ }
409
+
410
+ return $ret;
411
+ }
412
+
413
+ /**
414
+ * Generate Default List of Properties of an Uploaded File.
415
+ *
416
+ * This function generates the list of default properties of an uploaded file.
417
+ * Each property has an icon, a title (when the mouse hovers over the icon) and
418
+ * remarks (shown in Remarks column when the mouse hovers over the icon).
419
+ *
420
+ * @since 4.7.0
421
+ *
422
+ * @return array An array of properties of an uploaded file.
423
+ */
424
+ function wfu_init_uploadedfiles_properties() {
425
+ $props["status"] = array(
426
+ "icon" => "obsolete",
427
+ "icon-list" => array(
428
+ "ok" => "dashicons-yes",
429
+ "notexists" => "dashicons-trash",
430
+ "obsolete" => "dashicons-warning"
431
+ ),
432
+ "title" => "",
433
+ "title-list" => array(
434
+ "ok" => "File is Ok",
435
+ "notexists" => "File does not exist",
436
+ "obsolete" => "Record is invalid"
437
+ ),
438
+ "visible" => true,
439
+ "remarks" => '',
440
+ "remarks-list" => array(
441
+ "ok" => "File uploaded successfully to the website",
442
+ "notexists" => "File does not exist anymore in the website",
443
+ "obsolete" => "Record is not valid anymore"
444
+ ),
445
+ "code" => wfu_create_random_string(6)
446
+ );
447
+ $props["userdata"] = array(
448
+ "icon" => "dashicons-id-alt",
449
+ "title" => "File has user data",
450
+ "visible" => false,
451
+ "remarks" => 'File has user data, accessible in File Details',
452
+ "code" => wfu_create_random_string(6)
453
+ );
454
+ $props["media"] = array(
455
+ "icon" => "dashicons-admin-media",
456
+ "title" => "File is associated with Media item",
457
+ "visible" => false,
458
+ "remarks" => 'File is associated with Media item',
459
+ "code" => wfu_create_random_string(6)
460
+ );
461
+ $props["ftp"] = array(
462
+ "icon" => "wfu-dashicons-ftp",
463
+ "title" => "File saved in FTP",
464
+ "visible" => false,
465
+ "remarks" => 'File has been saved in FTP location',
466
+ "code" => wfu_create_random_string(6)
467
+ );
468
+
469
+ return $props;
470
+ }
471
+
472
+ /**
473
+ * Generate Default List of Actions of an Uploaded File.
474
+ *
475
+ * This function generates the list of default actions of an uploaded file. Each
476
+ * action has an icon, a title (when the mouse hovers over the icon) and a link
477
+ * URL (the action itself).
478
+ *
479
+ * @since 4.7.0
480
+ *
481
+ * @return array An array of properties of an uploaded file.
482
+ */
483
+ function wfu_init_uploadedfiles_actions() {
484
+ $def_actions["details"] = array(
485
+ "icon" => "dashicons-info",
486
+ "title" => "View file details",
487
+ "allowed" => false,
488
+ "visible" => false,
489
+ "href" => "",
490
+ "newtab" => true,
491
+ "color" => "default"
492
+ );
493
+ $def_actions["media"] = array(
494
+ "icon" => "wfu-dashicons-media-external",
495
+ "title" => "Open associated Media item",
496
+ "allowed" => false,
497
+ "visible" => false,
498
+ "href" => "",
499
+ "newtab" => true,
500
+ "color" => "default"
501
+ );
502
+ $def_actions["adminbrowser"] = array(
503
+ "icon" => "dashicons-portfolio",
504
+ "title" => "Locate file in File Browser",
505
+ "allowed" => false,
506
+ "visible" => false,
507
+ "href" => "",
508
+ "newtab" => true,
509
+ "color" => "default"
510
+ );
511
+ $def_actions["historylog"] = array(
512
+ "icon" => "dashicons-backup",
513
+ "title" => "Locate file record in View Log",
514
+ "allowed" => false,
515
+ "visible" => false,
516
+ "href" => "",
517
+ "newtab" => true,
518
+ "color" => "default"
519
+ );
520
+ $def_actions["link"] = array(
521
+ "icon" => "dashicons-external",
522
+ "title" => "Open file link",
523
+ "allowed" => false,
524
+ "visible" => false,
525
+ "href" => "",
526
+ "newtab" => true,
527
+ "color" => "default"
528
+ );
529
+ $def_actions["download"] = array(
530
+ "icon" => "dashicons-download",
531
+ "title" => "Download file",
532
+ "allowed" => false,
533
+ "visible" => false,
534
+ "href" => "",
535
+ "newtab" => true,
536
+ "color" => "default"
537
+ );
538
+
539
+ //get visible actions and their order
540
+ $actions = array();
541
+ $actions_raw = explode(',', WFU_VAR("WFU_UPLOADEDFILES_ACTIONS"));
542
+ //normalize action list
543
+ foreach ( $actions_raw as $ind => $action ) $actions_raw[$ind] = strtolower(trim($action));
544
+ //generate associative array of actions adjusting order and 'allowed'
545
+ //property
546
+ foreach ( $actions_raw as $ind => $action )
547
+ if ( isset($def_actions[$action]) ) {
548
+ $actions[$action] = $def_actions[$action];
549
+ $actions[$action]['allowed'] = true;
550
+ unset($def_actions[$action]);
551
+ }
552
+ foreach ( $def_actions as $action => $props ) $actions[$action] = $props;
553
+
554
+ return $actions;
555
+ }
556
+
557
+ /**
558
+ * Display Properties of an Uploaded File.
559
+ *
560
+ * This function generates the HTML code of the properties of an uploaded file
561
+ * that will be shown in Properties column.
562
+ *
563
+ * @since 4.7.0
564
+ *
565
+ * @redeclarable
566
+ *
567
+ * @param array $props The properties of the uploaded file.
568
+ * @param integer $index The index of the uploaded file.
569
+ *
570
+ * @return string The HTML code of the properties of an uploaded file.
571
+ */
572
+ function wfu_render_uploadedfiles_properties($props, $index) {
573
+ $a = func_get_args(); switch(WFU_FUNCTION_HOOK(__FUNCTION__, $a, $out)) { case 'X': break; case 'R': return $out; break; case 'D': die($out); break; }
574
+ $i = 0;
575
+ $echo_str = "";
576
+ foreach ( $props as $key => $prop ) {
577
+ $ii = $i + 1;
578
+ $iconclass = $prop['icon'];
579
+ if ( isset($prop['icon-list']) ) $iconclass = $prop['icon-list'][$prop['icon']];
580
+ $title = $prop['title'];
581
+ if ( isset($prop['title-list']) ) $title = $prop['title-list'][$prop['icon']];
582
+ $remarks = $prop['remarks'];
583
+ if ( isset($prop['remarks-list']) ) $remarks = $prop['remarks-list'][$prop['icon']];
584
+ $echo_str .= '<div id="p_'.$index.'_'.$ii.'" class="wfu-properties dashicons '.$iconclass.( $i == 0 ? '' : ' wfu-dashicons-after' ).( $prop['visible'] ? '' : ' wfu-dashicons-hidden' ).'" title="'.$title.'"><input type="hidden" class="wfu-remarks" value="'.wfu_plugin_encode_string($remarks).'" /></div>';
585
+ $i ++;
586
+ }
587
+
588
+ return $echo_str;
589
+ }
590
+
591
+ /**
592
+ * Display Actions of an Uploaded File.
593
+ *
594
+ * This function generates the HTML code of the actions of an uploaded file that
595
+ * will be shown in Actions column.
596
+ *
597
+ * @since 4.7.0
598
+ *
599
+ * @redeclarable
600
+ *
601
+ * @param array $actions The actions of the uploaded file.
602
+ *
603
+ * @return string The HTML code of the actions of an uploaded file.
604
+ */
605
+ function wfu_render_uploadedfiles_actions($actions) {
606
+ $a = func_get_args(); switch(WFU_FUNCTION_HOOK(__FUNCTION__, $a, $out)) { case 'X': break; case 'R': return $out; break; case 'D': die($out); break; }
607
+ $i = 0;
608
+ $echo_str = "";
609
+ foreach ( $actions as $key => $action ) {
610
+ $iconclass = $action['icon'];
611
+ if ( isset($action['icon-list']) ) $iconclass = $action['icon-list'][$action['icon']];
612
+ $title = $action['title'];
613
+ if ( isset($action['title-list']) ) $title = $action['title-list'][$action['icon']];
614
+ $echo_str .= '<a class="dashicons '.$iconclass.( $i == 0 ? '' : ' wfu-dashicons-after' ).( $action['visible'] ? '' : ' wfu-dashicons-hidden' ).'" href="'.$action['href'].'" target="'.( !isset($action['newtab']) || $action['newtab'] ? '_blank' : '_self' ).'" title="'.$title.'"'.( isset($action['color']) && $action['color'] != 'default' ? ' style="color:'.$action['color'].';"' : '' ).'></a>';
615
+ $i ++;
616
+ }
617
+
618
+ return $echo_str;
619
+ }
620
+
621
+ /**
622
+ * Display Unread Uploaded File in Admin Bar.
623
+ *
624
+ * This function displays the number of unread uploaded files in Admin Bar.
625
+ *
626
+ * @since 4.8.0
627
+ */
628
+ function wfu_admin_toolbar_new_uploads() {
629
+ global $wp_admin_bar;
630
+
631
+ if ( WFU_VAR("WFU_UPLOADEDFILES_BARMENU") == "true" ) {
632
+ //get the number of new (unread) uploaded files
633
+ $unread_files_count = wfu_get_unread_files_count();
634
+ $text = $unread_files_count;
635
+ if ( $unread_files_count > 99 ) $text = "99+";
636
+ $title = ( $unread_files_count == 0 ? 'No new files uploaded' : ( $unread_files_count == 1 ? '1 new file uploaded' : $unread_files_count.' files uploaded' ) );
637
+
638
+ $args = array(
639
+ 'id' => 'wfu_uploads',
640
+ 'title' => '<span class="ab-icon"></span><span class="ab-label">'.$unread_files_count.'</span><span class="screen-reader-text">'.$title.'</span>',
641
+ 'href' => admin_url( 'admin.php?page=wfu_uploaded_files' ),
642
+ 'group' => false,
643
+ 'meta' => array(
644
+ 'title' => $title,
645
+ 'class' => ( $unread_files_count == 0 && WFU_VAR("WFU_UPLOADEDFILES_BARAUTOHIDE") == "true" ? 'hidden' : '' )
646
+ ),
647
+ );
648
+ $wp_admin_bar->add_menu( $args );
649
+ }
650
+ }
651
+
652
+ /**
653
+ * Display Files Per Page in Uploaded Files Screen Options.
654
+ *
655
+ * This function displays the number of uploaded files per page to display in
656
+ * the screen options section of Uploaded Files Dashboard page.
657
+ *
658
+ * @since 4.8.0
659
+ */
660
+ function wfu_uploadedfiles_screen_options() {
661
+ global $wfu_uploadedfiles_hook_suffix;
662
+
663
+ $screen = get_current_screen();
664
+ // get out of here if we are not on uploadedfiles page
665
+ if( !is_object($screen) || $screen->id != $wfu_uploadedfiles_hook_suffix ) return;
666
+
667
+ $args = array(
668
+ 'label' => 'Files per page',
669
+ 'default' => WFU_VAR("WFU_UPLOADEDFILES_TABLE_MAXROWS"),
670
+ 'option' => 'wfu_uploadedfiles_per_page'
671
+ );
672
+ add_screen_option( 'per_page', $args );
673
+ }
674
+
675
+ ?>
lib/wfu_ajaxactions.php CHANGED
@@ -1,1324 +1,1324 @@
1
- <?php
2
-
3
- /**
4
- * AJAX Handlers of the Plugin
5
- *
6
- * This file contains AJAX handlers of the plugin.
7
- *
8
- * @link /lib/wfu_ajaxactions.php
9
- *
10
- * @package WordPress File Upload Plugin
11
- * @subpackage Core Components
12
- * @since 2.1.2
13
- */
14
-
15
- /**
16
- * Execute Email Notification Dispatching
17
- *
18
- * This function sends an email notification after files have been uploaded.
19
- *
20
- * @since 2.1.2
21
- */
22
- function wfu_ajax_action_send_email_notification() {
23
- $_POST = stripslashes_deep($_POST);
24
-
25
- $user = wp_get_current_user();
26
- if ( 0 == $user->ID ) $is_admin = false;
27
- else $is_admin = current_user_can('manage_options');
28
-
29
- $params_index = sanitize_text_field($_POST['params_index']);
30
- $session_token = sanitize_text_field($_POST['session_token']);
31
-
32
- $arr = wfu_get_params_fields_from_index($params_index, $session_token);
33
- //check referer using server sessions to avoid CSRF attacks
34
- $sid = $arr['shortcode_id'];
35
- if ( WFU_USVAR("wfu_token_".$sid) != $session_token ) die();
36
- if ( $user->user_login != $arr['user_login'] ) {
37
- $arr = wfu_get_params_fields_from_index($params_index.'[|][|]'.$arr['page_id'].'[|][|]'.$sid.'[|][|]'.$arr['user_login'], $session_token);
38
- if ( $user->user_login != $arr['user_login'] ) die();
39
- }
40
-
41
- $params_str = get_option('wfu_params_'.$arr['unique_id']);
42
- $params = wfu_decode_array_from_string($params_str);
43
-
44
- //check whether email notifications are activated
45
- if ( $params["notify"] != "true" ) die();
46
-
47
- $uniqueid = ( isset($_POST['uniqueuploadid_'.$sid]) ? sanitize_text_field($_POST['uniqueuploadid_'.$sid]) : "" );
48
- //uniqueid cannot be empty and cannot be "no-ajax"
49
- if ( $uniqueid == "" || $uniqueid == "no-ajax" ) die();
50
-
51
- //retrieve the list of uploaded files from session
52
- $target_path_list = array();
53
- $all_files_count = 0;
54
- if ( WFU_USVAR_exists("filedata_".$uniqueid) && is_array(WFU_USVAR("filedata_".$uniqueid)) ) {
55
- $all_files_count = count(WFU_USVAR("filedata_".$uniqueid));
56
- foreach ( WFU_USVAR("filedata_".$uniqueid) as $file ) {
57
- if ( $file["upload_result"] == "success" || $file["upload_result"] == "warning" )
58
- array_push($target_path_list, $file["filepath"]);
59
- }
60
- }
61
- $uploaded_files_count = count($target_path_list);
62
- $nofileupload = ( $params["allownofile"] == "true" && $all_files_count == 0 );
63
- $force_notifications = ( WFU_VAR("WFU_FORCE_NOTIFICATIONS") == "true" );
64
-
65
- //in case no files have been uploaded and this is not a nofileupload
66
- //situation and Force Email Notifications option is not active then abort
67
- if ( $uploaded_files_count == 0 && !$nofileupload && !$force_notifications ) die();
68
-
69
- /* initialize return array */
70
- $params_output_array["version"] = "full";
71
- $params_output_array["general"]['shortcode_id'] = $params["uploadid"];
72
- $params_output_array["general"]['unique_id'] = $uniqueid;
73
- $params_output_array["general"]['state'] = 0;
74
- $params_output_array["general"]['files_count'] = 0;
75
- $params_output_array["general"]['update_wpfilebase'] = "";
76
- $params_output_array["general"]['redirect_link'] = "";
77
- $params_output_array["general"]['upload_finish_time'] = "";
78
- $params_output_array["general"]['message'] = "";
79
- $params_output_array["general"]['message_type'] = "";
80
- $params_output_array["general"]['admin_messages']['wpfilebase'] = "";
81
- $params_output_array["general"]['admin_messages']['notify'] = "";
82
- $params_output_array["general"]['admin_messages']['redirect'] = "";
83
- $params_output_array["general"]['admin_messages']['other'] = "";
84
- $params_output_array["general"]['errors']['wpfilebase'] = "";
85
- $params_output_array["general"]['errors']['notify'] = "";
86
- $params_output_array["general"]['errors']['redirect'] = "";
87
- $params_output_array["general"]['color'] = "black";
88
- $params_output_array["general"]['bgcolor'] = "#F5F5F5";
89
- $params_output_array["general"]['borcolor'] = "#D3D3D3";
90
- $params_output_array["general"]['notify_by_email'] = 0;
91
- $params_output_array["general"]['fail_message'] = WFU_ERROR_UNKNOWN;
92
-
93
- //retrieve userdata, first get default userdata from $params
94
- $userdata_fields = $params["userdata_fields"];
95
- //remove any honeypot fields and initialize default values
96
- foreach ( $userdata_fields as $userdata_key => $userdata_field )
97
- if ( $userdata_field["type"] == "honeypot" ) unset($userdata_fields[$userdata_key]);
98
- else $userdata_fields[$userdata_key]["value"] = "";
99
- //then retrieve userdata from session if files exist
100
- if ( $all_files_count > 0 && WFU_USVAR_exists("filedata_".$uniqueid) && is_array(WFU_USVAR("filedata_".$uniqueid)) ) {
101
- foreach ( WFU_USVAR("filedata_".$uniqueid) as $file ) {
102
- if ( isset($file["user_data"]) ) {
103
- $userdata_fields = array();
104
- foreach ( $file["user_data"] as $userdata_key => $userdata_field )
105
- $userdata_fields[$userdata_key] = array( "label" => $userdata_field["label"], "value" => $userdata_field["value"] );
106
- break;
107
- }
108
- }
109
- }
110
- //in case there are no files in session (because allownofile attribute is
111
- //active and the user did not select any files for upload) then retrieve
112
- //userdata from the database based on uploadid
113
- else {
114
- $userdata_saved = wfu_get_userdata_from_uploadid($uniqueid);
115
- if ( $userdata_saved != null && is_array($userdata_saved) ) {
116
- $userdata_fields = array();
117
- foreach ( $userdata_saved as $userdata_saved_rec )
118
- $userdata_fields[$userdata_saved_rec->propkey] = array( "label" => $userdata_saved_rec->property, "value" => $userdata_saved_rec->propvalue );
119
- }
120
- }
121
-
122
- $send_error = wfu_send_notification_email($user, $target_path_list, $userdata_fields, $params);
123
-
124
- /* suppress any errors if user is not admin */
125
- if ( !$is_admin ) $send_error = "";
126
-
127
- if ( $send_error != "" ) {
128
- $params_output_array["general"]['admin_messages']['notify'] = $send_error;
129
- $params_output_array["general"]['errors']['notify'] = "error";
130
- }
131
-
132
- /* construct safe output */
133
- $sout = "0;".WFU_VAR("WFU_DEFAULTMESSAGECOLORS").";0";
134
-
135
- $echo_str = "wfu_fileupload_success::".$sout.":".wfu_encode_array_to_string($params_output_array);
136
- /**
137
- * Customise Email Notification Result.
138
- *
139
- * This filter allows scripts to customise the result of email notification
140
- * operation.
141
- *
142
- * @since 4.0.0
143
- *
144
- * @param string $echo_str The result of email notification operation.
145
- */
146
- $echo_str = apply_filters('_wfu_ajax_action_send_email_notification', $echo_str);
147
-
148
- die($echo_str);
149
- }
150
-
151
- /**
152
- * Execute Pre-Upload Actions
153
- *
154
- * This function executes server-side actions before the upload starts, in order
155
- * to determine whether the upload will continue, or any other custom actions.
156
- *
157
- * @since 3.7.0
158
- */
159
- function wfu_ajax_action_ask_server() {
160
- if ( !isset($_REQUEST['session_token']) || !isset($_REQUEST['sid']) || !isset($_REQUEST['unique_id']) ) die();
161
-
162
- $_REQUEST = stripslashes_deep($_REQUEST);
163
-
164
- $session_token = sanitize_text_field( $_REQUEST["session_token"] );
165
- $sid = sanitize_text_field( $_REQUEST["sid"] );
166
- $unique_id = wfu_sanitize_code($_REQUEST['unique_id']);
167
- if ( $session_token == "" ) die();
168
- //check referrer using Wordpress nonces and server sessions to avoid CSRF attacks
169
- check_ajax_referer( 'wfu-uploader-nonce', 'wfu_uploader_nonce' );
170
- if ( WFU_USVAR("wfu_token_".$sid) != $session_token ) die();
171
-
172
- //prepare parameters for before-upload filters
173
- $ret = array( "status" => "", "echo" => "" );
174
- //retrieve file names and sizes from request parameters
175
- $filenames_raw = ( isset($_REQUEST['filenames']) ? $_REQUEST['filenames'] : "" );
176
- $filenames = array();
177
- if ( trim($filenames_raw) != "" ) $filenames = explode(";", $filenames_raw);
178
- //use wfu_basename() function in order to avoid directory traversal attacks
179
- foreach ( $filenames as $ind => $filename ) $filenames[$ind] = wfu_basename(esc_attr(wfu_plugin_decode_string(trim($filename))));
180
- $filesizes_raw = ( isset($_REQUEST['filesizes']) ? $_REQUEST['filesizes'] : "" );
181
- $filesizes = array();
182
- if ( trim($filesizes_raw) != "" ) $filesizes = explode(";", $filesizes_raw);
183
- foreach ( $filesizes as $ind => $filesize ) $filesizes[$ind] = wfu_sanitize_int($filesize);
184
- $files = array();
185
- foreach ( $filenames as $ind => $filename ) {
186
- $filesize = "";
187
- if ( isset($filesizes[$ind]) ) $filesize = $filesizes[$ind];
188
- array_push($files, array( "filename" => $filename, "filesize" => $filesize ));
189
- }
190
- $attr = array( "sid" => $sid, "unique_id" => $unique_id, "files" => $files );
191
- //execute before upload filters
192
- $echo_str = "";
193
- //first execute any custom filters created by admin
194
- if ( has_filter("wfu_before_upload") ) {
195
- $changable_data = array( "error_message" => "", "js_script" => "" );
196
- /**
197
- * Execute Custom Actions Before Upload Starts.
198
- *
199
- * This filter allows to execute custom actions before upload starts. It
200
- * can cancel the upload returning an error message.
201
- *
202
- * @since 3.7.0
203
- *
204
- * @param array $changable_data {
205
- * Controls the upload.
206
- *
207
- * @type string $error_message An error message to display if the
208
- * upload must be cancelled.
209
- * @type string $js_script Javascript code to execute on user's
210
- * browser after this filter finishes.
211
- * }
212
- * @param array $attr {
213
- * Various attributes of the upload.
214
- *
215
- * @type string $sid The ID of the shortcode.
216
- * @type string $unique_id The unique ID of the upload.
217
- * @type array $files {
218
- * Contains an array of the uploaded files.
219
- *
220
- * @type array $file {
221
- * Contains information for each uploaded file.
222
- *
223
- * @type string $filename The filename of the file.
224
- * @type int $filesize The size of the file.
225
- * }
226
- * }
227
- * }
228
- */
229
- $changable_data = apply_filters("wfu_before_upload", $changable_data, $attr);
230
- if ( $changable_data["error_message"] == "" ) $ret["status"] = "success";
231
- else {
232
- $ret["status"] = "error";
233
- $echo_str .= "CBUV[".$changable_data["error_message"]."]";
234
- }
235
- if ( $changable_data["js_script"] != "" ) $echo_str .= "CBUVJS[".wfu_plugin_encode_string($changable_data["js_script"])."]";
236
- }
237
- /**
238
- * Execute Custom Internal Actions Before Upload Starts.
239
- *
240
- * This filter allows to execute custom internal actions by extensions
241
- * before upload starts. It can cancel the upload.
242
- *
243
- * @since 3.7.0
244
- *
245
- * @param array $ret {
246
- * Controls the upload and output of this function.
247
- *
248
- * @type string $status The status of the upload. It must be 'success'
249
- * or 'error'.
250
- * @type string $echo Additional content to the echoed by the function.
251
- * }
252
- * @param array $attr {
253
- * Various attributes of the upload.
254
- *
255
- * @type string $sid The ID of the shortcode.
256
- * @type string $unique_id The unique ID of the upload.
257
- * @type array $files {
258
- * Contains an array of the uploaded files.
259
- *
260
- * @type array $file {
261
- * Contains information for each uploaded file.
262
- *
263
- * @type string $filename The filename of the file.
264
- * @type int $filesize The size of the file.
265
- * }
266
- * }
267
- * }
268
- */
269
- $ret = apply_filters("_wfu_before_upload", $ret, $attr);
270
- $echo_str .= $ret["echo"];
271
- //in case that no filters were executed, because $ret["status"] is
272
- //empty, then this call to wfu_ajax_action_ask_server was erroneous
273
- if ( $ret["status"] == "" ) $ret["status"] = "die";
274
- //create an internal flag stored in session regarding the status of this
275
- //upload, that will be used to verify or not the upload
276
- if ( $ret["status"] == "success" ) WFU_USVAR_store("wfu_uploadstatus_".$attr["unique_id"], 1);
277
- else WFU_USVAR_store("wfu_uploadstatus_".$attr["unique_id"], 0);
278
-
279
- if ( $ret["status"] == "success" || $ret["status"] == "error" )
280
- echo "wfu_askserver_".$ret["status"].":".$echo_str;
281
-
282
- die();
283
- }
284
-
285
- /**
286
- * Execute Cancellation of Classic Upload
287
- *
288
- * This function sets the necessary User State variables to denote cancellation
289
- * of the upload that was requested by the user. This function applies only to
290
- * classic (non-AJAX) uploads.
291
- *
292
- * @since 4.0.0
293
- */
294
- function wfu_ajax_action_cancel_upload() {
295
- if ( !isset($_REQUEST['session_token']) || !isset($_REQUEST['sid']) || !isset($_REQUEST['unique_id']) ) die();
296
-
297
- $_REQUEST = stripslashes_deep($_REQUEST);
298
-
299
- $session_token = sanitize_text_field( $_REQUEST["session_token"] );
300
- $sid = sanitize_text_field( $_REQUEST["sid"] );
301
- $unique_id = wfu_sanitize_code($_REQUEST['unique_id']);
302
- if ( $session_token == "" ) die();
303
- //check referrer using Wordpress nonces and server sessions to avoid CSRF attacks
304
- check_ajax_referer( 'wfu-uploader-nonce', 'wfu_uploader_nonce' );
305
- if ( WFU_USVAR("wfu_token_".$sid) != $session_token ) die();
306
-
307
- //setting status to 0 denotes cancelling of the upload
308
- WFU_USVAR_store("wfu_uploadstatus_".$unique_id, 0);
309
-
310
- die("success");
311
- }
312
-
313
- /**
314
- * Execute AJAX Upload
315
- *
316
- * This function is the main callback of an AJAX upload of a whole file or a
317
- * chunk. It performs security checks to verify the user, then it performs pre-
318
- * upload actions, then it executes wfu_process_files() function that processes
319
- * and saves the files and then performs post-upload actions and filters.
320
- *
321
- * @since 2.1.2
322
- *
323
- * @global string $wfu_user_state_handler The defined User State handler.
324
- */
325
- function wfu_ajax_action_callback() {
326
- global $wfu_user_state_handler;
327
- if ( !isset($_REQUEST['session_token']) ) die();
328
-
329
- $_REQUEST = stripslashes_deep($_REQUEST);
330
- $_POST = stripslashes_deep($_POST);
331
-
332
- $session_token = sanitize_text_field( $_REQUEST["session_token"] );
333
- if ( $session_token == "" ) die();
334
- check_ajax_referer( 'wfu-uploader-nonce', 'wfu_uploader_nonce' );
335
-
336
- if ( !isset($_REQUEST['params_index']) ) die();
337
-
338
- $params_index = sanitize_text_field( $_REQUEST["params_index"] );
339
-
340
- if ( $params_index == "" ) die();
341
-
342
- $user = wp_get_current_user();
343
- $arr = wfu_get_params_fields_from_index($params_index, $session_token);
344
- $sid = $arr['shortcode_id'];
345
- //check referrer using server sessions to avoid CSRF attacks
346
- if ( WFU_USVAR("wfu_token_".$sid) != $session_token ) {
347
- $echo_str = "Session failed!<br/><br/>Session Data:<br/>";
348
- $echo_str .= print_r(wfu_sanitize(WFU_USALL()), true);
349
- $echo_str .= "<br/><br/>Post Data:<br/>";
350
- $echo_str .= print_r(wfu_sanitize($_REQUEST), true);
351
- $echo_str .= 'force_errorabort_code';
352
- /**
353
- * Customise Output on Session Error.
354
- *
355
- * This filter allows scripts to customise output of the function in
356
- * case of session error.
357
- *
358
- * @since 3.11.0
359
- *
360
- * @param string $echo_str The output in case of session error.
361
- */
362
- $echo_str = apply_filters('_wfu_upload_session_failed', $echo_str);
363
- die($echo_str);
364
- }
365
-
366
- if ( $user->user_login != $arr['user_login'] ) {
367
- $arr = wfu_get_params_fields_from_index($params_index.'[|][|]'.$arr['page_id'].'[|][|]'.$sid.'[|][|]'.$arr['user_login'], $session_token);
368
- if ( $user->user_login != $arr['user_login'] ) {
369
- $echo_str = "User failed!<br/><br/>User Data:<br/>";
370
- $echo_str .= print_r(wfu_sanitize($user), true);
371
- $echo_str .= "<br/><br/>Post Data:<br/>";
372
- $echo_str .= print_r(wfu_sanitize($_REQUEST), true);
373
- $echo_str .= "<br/><br/>Params Data:<br/>";
374
- $echo_str .= print_r(wfu_sanitize($arr), true);
375
- $echo_str .= 'force_errorabort_code';
376
- /**
377
- * Customise Output on User Error.
378
- *
379
- * This filter allows scripts to customise output of the function in
380
- * case of user error.
381
- *
382
- * @since 3.11.0
383
- *
384
- * @param string $echo_str The output in case of user error.
385
- */
386
- $echo_str = apply_filters('_wfu_upload_user_failed', $echo_str);
387
- die($echo_str);
388
- }
389
- }
390
-
391
- //if force_connection_close is set, then the first pass to this callback
392
- //script is for closing the previous connection
393
- if ( isset($_POST["force_connection_close"]) && $_POST["force_connection_close"] === "1" ) {
394
- header("Connection: Close");
395
- /**
396
- * Customise Output on Forced Connection Close.
397
- *
398
- * This filter allows scripts to customise return of the function in
399
- * case of forced connection close.
400
- *
401
- * @since 3.11.0
402
- *
403
- * @param string $echo_str The return in case of forced connection
404
- * close.
405
- */
406
- die(apply_filters('_wfu_upload_force_connection_close', 'success'));
407
- }
408
-
409
- //get the unique id of the upload
410
- $unique_id = ( isset($_POST['uniqueuploadid_'.$sid]) ? sanitize_text_field($_POST['uniqueuploadid_'.$sid]) : "" );
411
- if ( strlen($unique_id) != 10 ) {
412
- /**
413
- * Customise Output on Unique ID Fail.
414
- *
415
- * This filter allows scripts to customise return of the function in
416
- * case that the retrieved unique ID is invalid.
417
- *
418
- * @since 3.11.0
419
- *
420
- * @param string $echo_str The return in case of unique ID fail.
421
- */
422
- die(apply_filters('_wfu_upload_uniqueid_failed', 'force_errorabort_code'));
423
- }
424
-
425
- //if before upload actions have been executed and they have rejected the
426
- //upload, but for some reason (hack attempt) the upload continued, then
427
- //terminate it
428
- if ( WFU_USVAR_exists("wfu_uploadstatus_".$unique_id) && WFU_USVAR("wfu_uploadstatus_".$unique_id) == 0 ) die('force_errorabort_code');
429
-
430
- //get stored shortcode parameters
431
- $params_str = get_option('wfu_params_'.$arr['unique_id']);
432
- $params = wfu_decode_array_from_string($params_str);
433
-
434
- //if upload has finished then perform post upload actions
435
- if ( isset($_POST["upload_finished"]) && $_POST["upload_finished"] === "1" ) {
436
- //remove any queues that were generated during the upload process
437
- wfu_remove_queue($unique_id);
438
- $echo_str = "";
439
- //execute after upload filters
440
- $ret = wfu_execute_after_upload_filters($sid, $unique_id, $params);
441
- if ( $ret["js_script"] != "" ) $echo_str = "CBUVJS[".wfu_plugin_encode_string($ret["js_script"])."]";
442
- die($echo_str);
443
- }
444
-
445
- //check if honeypot userdata fields have been added to the form and if they
446
- //contain any data; if wfu_check_remove_honeypot_fields returns true this
447
- //means that at least one honeypot field has beed filled with a value and
448
- //the upload must be aborted because it was not done by a human
449
- if ( $params["userdata"] == "true" && wfu_check_remove_honeypot_fields($params["userdata_fields"], 'hiddeninput_'.$sid.'_userdata_') ) die("force_abortsuccess_code");
450
-
451
- //apply filters to determine if the upload will continue or stop
452
- $ret = array( "status" => "", "echo" => "" );
453
- $attr = array( "sid" => $sid, "unique_id" => $unique_id, "params" => $params );
454
- /**
455
- * Execute Pre-Upload Checks.
456
- *
457
- * This is an internal filter which allows to execute custom actions right
458
- * before an upload starts. It can cancel the upload.
459
- *
460
- * @since 3.7.0
461
- *
462
- * @param array $ret {
463
- * Controls the Upload.
464
- *
465
- * @type string $status Status of the upload. If it is 'die' then the
466
- * upload will be cancelled.
467
- * @type string $echo A message to return in case of upload
468
- * cancellation.
469
- * }
470
- * @param array $attr {
471
- * Various attributes of the upload.
472
- *
473
- * @type string $sid The ID of the shortcode.
474
- * @type string $unique_id The unique ID of the upload.
475
- * @type array $params The shortcode parameters of the upload form.
476
- */
477
- $ret = apply_filters("_wfu_pre_upload_check", $ret, $attr);
478
- if ( $ret["status"] == "die" ) die($ret["echo"]);
479
-
480
- //if this is the first pass of an upload attempt then perform pre-upload actions
481
- if ( !WFU_USVAR_exists('wfu_upload_first_pass_'.$unique_id) || WFU_USVAR('wfu_upload_first_pass_'.$unique_id) != 'true' ) {
482
- WFU_USVAR_store('wfu_upload_first_pass_'.$unique_id, 'true');
483
- }
484
-
485
- if ( !isset($_POST["subdir_sel_index"]) ) die();
486
- $subdir_sel_index = sanitize_text_field( $_POST["subdir_sel_index"] );
487
- $params['subdir_selection_index'] = $subdir_sel_index;
488
- WFU_USVAR_store('wfu_check_refresh_'.$params["uploadid"], 'do not process');
489
-
490
- //update consent status of user
491
- $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
492
- $params["consent_result"] = wfu_check_user_consent($user);
493
- $require_consent = ( $plugin_options["personaldata"] == "1" && ( $params["notrememberconsent"] == "true" || $params["consent_result"] == "" ) && $params["askconsent"] == "true" );
494
- if ( $require_consent ) {
495
- if ( !isset($_POST['consent_result']) ) die();
496
- $consent_result = ( $_POST['consent_result'] == "yes" ? "yes" : ( $_POST['consent_result'] == "no" ? "no" : "" ) );
497
- $params["consent_result"] = ( $_POST['consent_result'] == "yes" ? "1" : ( $_POST['consent_result'] == "no" ? "0" : "" ) );
498
- wfu_update_user_consent($user, $consent_result);
499
- }
500
-
501
- if ( $wfu_user_state_handler == "dboption" )
502
- $proc_ret = wfu_run_process_in_queue($unique_id, "wfu_process_files", array( $params, 'ajax' ));
503
- else {
504
- $proc_ret["result"] = true;
505
- $proc_ret["output"] = wfu_process_files($params, 'ajax');
506
- }
507
- $echo_str = "";
508
- if ( $proc_ret["result"] ) {
509
- $wfu_process_file_array = $proc_ret["output"];
510
- //extract safe_output from wfu_process_file_array and pass it as
511
- //separate part of the response text
512
- $safe_output = $wfu_process_file_array["general"]['safe_output'];
513
- unset($wfu_process_file_array["general"]['safe_output']);
514
- //get javascript code that has been defined in wfu_after_file_upload
515
- //action
516
- $js_script = wfu_plugin_encode_string($wfu_process_file_array["general"]['js_script']);
517
- unset($wfu_process_file_array["general"]['js_script']);
518
-
519
- $echo_str = "wfu_fileupload_success:".$js_script.":".$safe_output.":".wfu_encode_array_to_string($wfu_process_file_array);
520
- }
521
- elseif ( $proc_ret["error"] == "abort_thread" ) wfu_advance_queue($unique_id);
522
- /**
523
- * Customise Output of Successful AJAX Upload.
524
- *
525
- * This filter allows scripts to customise return of the function in case
526
- * that the AJAX upload was successful.
527
- *
528
- * @since 3.11.0
529
- *
530
- * @param string $echo_str The return in case of successful AJAX upload.
531
- */
532
- $echo_str = apply_filters('_wfu_upload_callback_success', $echo_str);
533
- die($echo_str);
534
- }
535
-
536
- /**
537
- * Execute Saving of Shortcode
538
- *
539
- * This function executes saving of a shortcode after it has been edited through
540
- * the shortcode composer.
541
- *
542
- * @since 2.1.3
543
- */
544
- function wfu_ajax_action_save_shortcode() {
545
- $is_admin = current_user_can( 'manage_options' );
546
- $can_open_composer = ( WFU_VAR("WFU_SHORTCODECOMPOSER_NOADMIN") == "true" && ( current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) ) );
547
- if ( !$is_admin && !$can_open_composer ) die();
548
- if ( !isset($_POST['shortcode']) || !isset($_POST['shortcode_original']) || !isset($_POST['post_id']) || !isset($_POST['post_hash']) || !isset($_POST['shortcode_position']) || !isset($_POST['shortcode_tag']) || !isset($_POST['widget_id']) ) die();
549
-
550
- $_POST = stripslashes_deep($_POST);
551
-
552
- //sanitize parameters
553
- $shortcode = wfu_sanitize_code($_POST['shortcode']);
554
- $shortcode_original = wfu_sanitize_code($_POST['shortcode_original']);
555
- $post_id = wfu_sanitize_int($_POST['post_id']);
556
- $post_hash = wfu_sanitize_code($_POST['post_hash']);
557
- $shortcode_position = wfu_sanitize_int($_POST['shortcode_position']);
558
- $shortcode_tag = wfu_sanitize_tag($_POST['shortcode_tag']);
559
- $widget_id = sanitize_text_field($_POST['widget_id']);
560
-
561
- $shortcode = wfu_sanitize_shortcode(wfu_plugin_decode_string($shortcode), $shortcode_tag);
562
-
563
- if ( $post_id == "" && $widget_id == "" ) {
564
- die();
565
- }
566
- else {
567
- $data['post_id'] = $post_id;
568
- $data['post_hash'] = $post_hash;
569
- $data['shortcode'] = wfu_plugin_decode_string($shortcode_original);
570
- $data['position'] = $shortcode_position;
571
- if ( $post_id != "" && !wfu_check_edit_shortcode($data) ) $echo_str = "wfu_save_shortcode:fail:post_modified";
572
- else {
573
- if ( $widget_id == "" ) {
574
- $new_shortcode = "[".$shortcode_tag." ".$shortcode."]";
575
- if ( wfu_replace_shortcode($data, $new_shortcode) ) {
576
- $post = get_post($post_id);
577
- /** This filter is described in wfu_loader.php */
578
- $content = apply_filters("_wfu_get_post_content", $post->post_content, $post);
579
- $hash = hash('md5', $content);
580
- $echo_str = "wfu_save_shortcode:success:".$hash;
581
- }
582
- else $echo_str = "wfu_save_shortcode:fail:post_update_failed";
583
- }
584
- else {
585
- $widget_obj = wfu_get_widget_obj_from_id($widget_id);
586
- if ( $widget_obj === false ) $echo_str = "wfu_save_shortcode:fail:post_update_failed";
587
- else {
588
- $widget_sidebar = is_active_widget(false, $widget_id, "wordpress_file_upload_widget");
589
- if ( !$widget_sidebar ) $echo_str = "wfu_save_shortcode:fail:post_update_failed";
590
- else {
591
- $widget_obj->update_external($shortcode);
592
- $hash = $data['post_hash'];
593
- $echo_str = "wfu_save_shortcode:success:".$hash;
594
- }
595
- }
596
- }
597
- }
598
- }
599
-
600
- /**
601
- * Customise Output on Shortcode Saving.
602
- *
603
- * This filter allows scripts to customise return of the function after
604
- * finish of it.
605
- *
606
- * @since 3.11.0
607
- *
608
- * @param string $echo_str The return of the function.
609
- */
610
- $echo_str = apply_filters('_wfu_ajax_action_save_shortcode', $echo_str);
611
- die($echo_str);
612
- }
613
-
614
- /**
615
- * Execute Checking of Post Contents
616
- *
617
- * This function executes checking of post contents to determine whether they
618
- * are current or obsolete (they have changed).
619
- *
620
- * @since 2.6.0
621
- */
622
- function wfu_ajax_action_check_page_contents() {
623
- if ( !current_user_can( 'manage_options' ) ) die();
624
- if ( !isset($_POST['post_id']) || !isset($_POST['post_hash']) ) die();
625
- if ( $_POST['post_id'] == "" ) die();
626
-
627
- $_POST = stripslashes_deep($_POST);
628
-
629
- $data['post_id'] = wfu_sanitize_int($_POST['post_id']);
630
- $data['post_hash'] = wfu_sanitize_code($_POST['post_hash']);
631
- if ( wfu_check_edit_shortcode($data) ) $echo_str = "wfu_check_page_contents:current:";
632
- else $echo_str = "wfu_check_page_contents:obsolete:";
633
-
634
- /**
635
- * Customise Output of Post Contents Checking Function.
636
- *
637
- * This filter allows scripts to customise return of this function after
638
- * finish of it.
639
- *
640
- * @since 3.11.0
641
- *
642
- * @param string $echo_str The return of the function.
643
- */
644
- $echo_str = apply_filters('_wfu_ajax_action_check_page_contents', $echo_str);
645
- die($echo_str);
646
- }
647
-
648
- /**
649
- * Initiate Editing of Shortcode
650
- *
651
- * This function invokes the shortcode composer in order to edit a shortcode. It
652
- * applies when editing a shortcode from Main page of the plugin in Dashboard or
653
- * from a front-end post or page or from a sidebar.
654
- *
655
- * @since 2.6.0
656
- */
657
- function wfu_ajax_action_edit_shortcode() {
658
- global $wp_registered_widgets;
659
- global $wp_registered_sidebars;
660
-
661
- $is_admin = current_user_can( 'manage_options' );
662
- $can_open_composer = ( WFU_VAR("WFU_SHORTCODECOMPOSER_NOADMIN") == "true" && ( current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) ) );
663
- if ( !$is_admin && !$can_open_composer ) die();
664
- if ( !isset($_POST['upload_id']) || !isset($_POST['post_id']) || !isset($_POST['post_hash']) || !isset($_POST['shortcode_tag']) || !isset($_POST['widget_id']) ) die();
665
-
666
- $_POST = stripslashes_deep($_POST);
667
-
668
- //sanitize parameters
669
- $upload_id = sanitize_text_field($_POST['upload_id']);
670
- $widget_id = sanitize_text_field($_POST['widget_id']);
671
- $post_id = wfu_sanitize_int($_POST['post_id']);
672
- $post_hash = wfu_sanitize_code($_POST['post_hash']);
673
- $shortcode_tag = wfu_sanitize_tag($_POST['shortcode_tag']);
674
-
675
- $keyname = "uploadid";
676
- if ( $shortcode_tag == "wordpress_file_upload_browser" ) $keyname = "browserid";
677
-
678
- $data['post_id'] = $post_id;
679
- $data['post_hash'] = $post_hash;
680
- if ( wfu_check_edit_shortcode($data) ) {
681
- if ( $widget_id == "" ) {
682
- $post = get_post($data['post_id']);
683
- //get default value for uploadid
684
- if ( $shortcode_tag == "wordpress_file_upload_browser" ) $defs = wfu_browser_attribute_definitions();
685
- else $defs = wfu_attribute_definitions();
686
- $default = "";
687
- foreach ( $defs as $key => $def ) {
688
- if ( $def['attribute'] == $keyname ) {
689
- $default = $def['value'];
690
- break;
691
- }
692
- }
693
- //get page shortcodes
694
- $wfu_shortcodes = wfu_get_content_shortcodes($post, $shortcode_tag);
695
- //find the shortcodes' uploadid and the correct one
696
- $validkey = -1;
697
- foreach ( $wfu_shortcodes as $key => $data ) {
698
- $shortcode = trim(substr($data['shortcode'], strlen('['.$shortcode_tag), -1));
699
- $shortcode_attrs = wfu_shortcode_string_to_array($shortcode);
700
- if ( array_key_exists($keyname, $shortcode_attrs) ) $uploadid = $shortcode_attrs[$keyname];
701
- else $uploadid = $default;
702
- if ( $uploadid == $upload_id ) {
703
- $validkey = $key;
704
- break;
705
- }
706
- }
707
- if ( $validkey == -1 ) die();
708
- $data_enc = wfu_safe_store_shortcode_data(wfu_encode_array_to_string($wfu_shortcodes[$validkey]));
709
- }
710
- else {
711
- $widget_obj = wfu_get_widget_obj_from_id($widget_id);
712
- if ( $widget_obj === false ) die();
713
- $widget_sidebar = is_active_widget(false, $widget_id, "wordpress_file_upload_widget");
714
- if ( !$widget_sidebar ) die();
715
- if ( isset($wp_registered_sidebars[$widget_sidebar]) && isset($wp_registered_sidebars[$widget_sidebar]['name']) ) $widget_sidebar = $wp_registered_sidebars[$widget_sidebar]['name'];
716
- $data['shortcode'] = $widget_obj->shortcode();
717
- $data['position'] = 0;
718
- $data['widgetid'] = $widget_id;
719
- $data['sidebar'] = $widget_sidebar;
720
- $data_enc = wfu_safe_store_shortcode_data(wfu_encode_array_to_string($data));
721
- }
722
- if( $is_admin ) $url = site_url().'/wp-admin/options-general.php?page=wordpress_file_upload&tag='.$shortcode_tag.'&action=edit_shortcode&data='.$data_enc;
723
- //conditional that will open the shortcode composer for non-admin users
724
- //who can edit posts or pages
725
- else $url = site_url().'/wp-admin/admin.php?page=wordpress_file_upload&tag='.$shortcode_tag.'&action=edit_shortcode&data='.$data_enc;
726
- $echo_str = "wfu_edit_shortcode:success:".wfu_plugin_encode_string($url);
727
- }
728
- else $echo_str = "wfu_edit_shortcode:check_page_obsolete:".WFU_ERROR_PAGE_OBSOLETE;
729
-
730
- /**
731
- * Customise Output of Shortcode Editing Initiation Function.
732
- *
733
- * This filter allows scripts to customise return of this function after
734
- * finish of it.
735
- *
736
- * @since 3.11.0
737
- *
738
- * @param string $echo_str The return of the function.
739
- */
740
- $echo_str = apply_filters('_wfu_ajax_action_edit_shortcode', $echo_str);
741
- die($echo_str);
742
- }
743
-
744
- /**
745
- * Initiate Editing of Shortcode in Gutenberg Editor
746
- *
747
- * This function invokes the shortcode composer in order to edit a shortcode. It
748
- * applies when editing a shortcode from the new Gutenberg page editor of
749
- * Wordpress.
750
- *
751
- * @since 4.11.0
752
- */
753
- function wfu_ajax_action_gutedit_shortcode() {
754
- $is_admin = current_user_can( 'manage_options' );
755
- $can_open_composer = ( WFU_VAR("WFU_SHORTCODECOMPOSER_NOADMIN") == "true" && ( current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) ) );
756
- if ( !$is_admin && !$can_open_composer ) die();
757
- if ( !isset($_POST['shortcode']) || !isset($_POST['post_id']) || !isset($_POST['shortcode_tag']) ) die();
758
-
759
- $_POST = stripslashes_deep($_POST);
760
-
761
- //sanitize parameters
762
- $shortcode = wfu_sanitize_code($_POST['shortcode']);
763
- $post_id = wfu_sanitize_int($_POST['post_id']);
764
- $shortcode_tag = wfu_sanitize_tag($_POST['shortcode_tag']);
765
-
766
- $shortcode = wfu_sanitize_shortcode(wfu_plugin_decode_string($shortcode), $shortcode_tag);
767
-
768
- if ( $post_id == "" ) die();
769
-
770
- $data['shortcode'] = '['.$shortcode_tag.' '.$shortcode.']';
771
- $data['post_id'] = $post_id;
772
- $data['post_hash'] = '';
773
- $data['position'] = 0;
774
- $data_enc = wfu_safe_store_shortcode_data(wfu_encode_array_to_string($data));
775
- if ( $is_admin ) $url = site_url().'/wp-admin/options-general.php?page=wordpress_file_upload&tag='.$shortcode_tag.'&action=edit_shortcode&data='.$data_enc.'&referer=guteditor';
776
- //conditional that will open the shortcode composer for non-admin users who
777
- //can edit posts or pages
778
- else $url = site_url().'/wp-admin/admin.php?page=wordpress_file_upload&tag='.$shortcode_tag.'&action=edit_shortcode&data='.$data_enc.'&referer=guteditor';
779
-
780
- $echo_str = "wfu_gutedit_shortcode:success:".wfu_plugin_encode_string($url);
781
- /**
782
- * Customise Output of Gutenberg Shortcode Editing Initiation Function.
783
- *
784
- * This filter allows scripts to customise return of this function after
785
- * finish of it.
786
- *
787
- * @since 4.11.0
788
- *
789
- * @param string $echo_str The return of the function.
790
- */
791
- $echo_str = apply_filters('_wfu_ajax_action_gutedit_shortcode', $echo_str);
792
- die($echo_str);
793
- }
794
-
795
- /**
796
- * Retrieve Subfolder Structure of a Folder
797
- *
798
- * This function is used to retrieve the subfolder structure of a folder,
799
- * together with the subfolder structure of one of the subfolders. It is used
800
- * when defining the subfolders of the subfolders element of the upload form
801
- * using the shortcoe composer.
802
- *
803
- * @since 2.4.1
804
- */
805
- function wfu_ajax_action_read_subfolders() {
806
- if ( !isset($_POST['folder1']) || !isset($_POST['folder2']) ) die();
807
-
808
- $_POST = stripslashes_deep($_POST);
809
-
810
- $folder1 = wfu_sanitize_code($_POST['folder1']);
811
- $folder1 = wfu_sanitize_url(wfu_plugin_decode_string($folder1));
812
- $folder2 = wfu_sanitize_code($_POST['folder2']);
813
- $folder2 = wfu_sanitize_url(wfu_plugin_decode_string($folder2));
814
- if ( wfu_plugin_encode_string($folder1) != $_POST['folder1'] || wfu_plugin_encode_string($folder2) != $_POST['folder2'] ) die();
815
-
816
- $temp_params = array( 'uploadpath' => $folder1, 'accessmethod' => 'normal', 'ftpinfo' => '', 'useftpdomain' => 'false' );
817
- $path = wfu_upload_plugin_full_path($temp_params);
818
-
819
- if ( !is_dir($path) ) {
820
- /**
821
- * Customise Output of Shortcode Subfolder Structure Retrieval.
822
- *
823
- * This filter allows scripts to customise return of this function after
824
- * finish of it.
825
- *
826
- * @since 3.11.0
827
- *
828
- * @param string $echo_str The return of the function.
829
- */
830
- die(apply_filters('_wfu_ajax_action_read_subfolders', 'wfu_read_subfolders:error:Parent folder is not valid! Cannot retrieve subfolder list.'));
831
- }
832
-
833
- $path2 = $folder2;
834
- $dirlist = "";
835
- if ( $handle = opendir($path) ) {
836
- $blacklist = array('.', '..');
837
- while ( false !== ($file = readdir($handle)) )
838
- if ( !in_array($file, $blacklist) ) {
839
- $filepath = $path.$file;
840
- if ( is_dir($filepath) ) {
841
- if ( $file == $path2 ) $file = '[['.$file.']]';
842
- $dirlist .= ( $dirlist == "" ? "" : "," ).$file;
843
- }
844
- }
845
- closedir($handle);
846
- }
847
- if ( $path2 != "" ) {
848
- $dirlist2 = $path2;
849
- $path .= $path2."/";
850
- if ( is_dir($path) ) {
851
- if ( $handle = opendir($path) ) {
852
- $blacklist = array('.', '..');
853
- while ( false !== ($file = readdir($handle)) )
854
- if ( !in_array($file, $blacklist) ) {
855
- $filepath = $path.$file;
856
- if ( is_dir($filepath) )
857
- $dirlist2 .= ",*".$file;
858
- }
859
- closedir($handle);
860
- }
861
- }
862
- $dirlist = str_replace('[['.$path2.']]', $dirlist2, $dirlist);
863
- }
864
-
865
- /** This filter is documnted above. */
866
- die(apply_filters('_wfu_ajax_action_read_subfolders', "wfu_read_subfolders:success:".wfu_plugin_encode_string($dirlist)));
867
- }
868
-
869
- /**
870
- * Initiate a File Download
871
- *
872
- * This function initiates a file download. It will first check whether the user
873
- * has the right to download the file. Then it will return an iframe element
874
- * that will start the download. Short life tokens are used in order to avoid
875
- * CSRF attacks. Download is executed outside Wordpress enviroment because some
876
- * times Wordpress environment outputs warnings that are downloaded with the
877
- * file, resulting in a broken download.
878
- *
879
- * @since 2.6.0
880
- */
881
- function wfu_ajax_action_download_file_invoker() {
882
- global $wfu_user_state_handler;
883
-
884
- $_POST = stripslashes_deep($_POST);
885
- $_GET = stripslashes_deep($_GET);
886
-
887
- $file_code = (isset($_POST['file']) ? $_POST['file'] : (isset($_GET['file']) ? $_GET['file'] : ''));
888
- $nonce = (isset($_POST['nonce']) ? $_POST['nonce'] : (isset($_GET['nonce']) ? $_GET['nonce'] : ''));
889
- if ( $file_code == '' || $nonce == '' ) die();
890
-
891
- //security check to avoid CSRF attacks
892
- if ( !wp_verify_nonce($nonce, 'wfu_download_file_invoker') ) die();
893
-
894
- //check if user is allowed to download files
895
- if ( !current_user_can( 'manage_options' ) ) {
896
- die();
897
- }
898
-
899
- $cookies = array();
900
- $use_cookies = ( $wfu_user_state_handler == "dboption" && WFU_VAR("WFU_US_DBOPTION_BASE") == "cookies" );
901
- $file_code = sanitize_text_field($file_code);
902
- //if file_code is exportdata, then export of data has been requested and
903
- //we need to create a file with export data and recreate file_code
904
- if ( substr($file_code, 0, 10) == "exportdata" && current_user_can( 'manage_options' ) ) {
905
- $params = null;
906
- $params_str = substr($file_code, 11);
907
- if ( trim($params_str) != "" ) $params = json_decode($params_str, true);
908
- $filepath = wfu_export_uploaded_files($params);
909
- if ( $filepath === false ) die();
910
- $file_code = "exportdata".wfu_safe_store_filepath($filepath);
911
- //store filepath in user state otherwise it can not be retrieved by
912
- //downloader script
913
- if ( !$use_cookies ) WFU_USVAR_store_session('wfu_storage_'.substr($file_code, 10), $filepath);
914
- else array_push($cookies, '{name: "wfu_storage_'.substr($file_code, 10).'", value: "'.$filepath.'", expires: 30}');
915
- }
916
- //else get the file path from the safe
917
- else {
918
- $filepath = wfu_get_filepath_from_safe($file_code);
919
- if ( $filepath === false ) die();
920
- $filepath = wfu_path_rel2abs(wfu_flatten_path($filepath));
921
- //reject download of blacklisted file types for security reasons
922
- if ( wfu_file_extension_blacklisted($filepath) ) {
923
- /**
924
- * Customise Output of Download Initiation Operation.
925
- *
926
- * This filter allows scripts to customise return of this function
927
- * after finish of it.
928
- *
929
- * @since 3.11.0
930
- *
931
- * @param string $echo_str The return of the function.
932
- */
933
- die(apply_filters('_wfu_ajax_action_download_file_invoker', 'wfu_ajax_action_download_file_invoker:not_allowed:'.( isset($_POST['browser']) ? WFU_BROWSER_DOWNLOADFILE_NOTALLOWED : 'You are not allowed to download this file!' )));
934
- }
935
- //for front-end browser apply wfu_browser_check_file_action filter to
936
- //allow or restrict the download
937
- if ( isset($_POST['browser']) ) {
938
- $changable_data["error_message"] = "";
939
- $filerec = wfu_get_file_rec($filepath, true);
940
- $userdata = array();
941
- foreach ( $filerec->userdata as $data )
942
- array_push($userdata, array( "label" => $data->property, "value" => $data->propvalue ));
943
- $additional_data = array(
944
- "file_action" => "download",
945
- "filepath" => $filepath,
946
- "uploaduser" => $filerec->uploaduserid,
947
- "userdata" => $userdata
948
- );
949
- /**
950
- * Check if Action is Allowed in Front-End File Browser.
951
- *
952
- * This filter allows scripts to check whether the action on a file
953
- * from the front-end file browser is allowed.
954
- *
955
- * @since 3.7.2
956
- *
957
- * @param array $changable_data {
958
- * Controls allowance or rejection of the action.
959
- *
960
- * @type string $error_message An error message to return in
961
- * case the action must be rejected.
962
- * }
963
- * @param array $additional_data {
964
- * Additional data of the file action operation.
965
- *
966
- * @type string $file_action The performed action.
967
- * @type string $filepath The full path of the file.
968
- * @type string $uploaduser The ID of the user who uploaded
969
- * the file.
970
- * @type array $userdata Each item of the array contains the
971
- * label and value of any additional userdata exist
972
- * together with the file.
973
- * }
974
- */
975
- $changable_data = apply_filters("wfu_browser_check_file_action", $changable_data, $additional_data);
976
- if ( $changable_data["error_message"] != "" )
977
- /** This filter is documented above. */
978
- die(apply_filters('_wfu_ajax_action_download_file_invoker', 'wfu_ajax_action_download_file_invoker:not_allowed:'.$changable_data["error_message"]));
979
- }
980
- //for back-end browser check if user is allowed to perform this action
981
- //on this file
982
- if ( !wfu_current_user_owes_file($filepath) ) die();
983
- //store filepath in user state otherwise it can not be retrieved by
984
- //downloader script
985
- if ( !$use_cookies ) WFU_USVAR_store_session('wfu_storage_'.$file_code, wfu_get_filepath_from_safe($file_code));
986
- else array_push($cookies, '{name: "wfu_storage_'.$file_code.'", value: "'.wfu_get_filepath_from_safe($file_code).'", expires: 30}');
987
- }
988
-
989
- //generate download unique id to monitor this download
990
- $download_id = wfu_create_random_string(16);
991
- //store download status of this download in user state, so that it can be
992
- //changed by downloader script; it is noted that the downloader script
993
- //does not load WP environment, so in case of dboption it cannot access the
994
- //download status (which is stored in the database); however the downloader
995
- //script does not need to read it; it only needs to change it after the
996
- //download; so after the download, the downloader script loads WP
997
- //environment, so that it can change download status
998
- WFU_USVAR_store('wfu_download_status_'.$download_id, 'starting');
999
- //generate download ticket which expires in 30sec and store it in user
1000
- //state; it will be used as security measure for the downloader script,
1001
- //which runs outside Wordpress environment; it is noted that the downloader
1002
- //script needs to read download ticket before the download; however in the
1003
- //case of dboption the only way to achieve this is to store it in a cookie
1004
- if ( !$use_cookies ) WFU_USVAR_store_session('wfu_download_ticket_'.$download_id, time() + 30);
1005
- else array_push($cookies, '{name: "wfu_download_ticket_'.$download_id.'", value: '.(time() + 30).', expires: 30}');
1006
- //generate download monitor ticket which expires in 30sec and store it in
1007
- //user state; it will be used as security measure for the monitor script
1008
- //that will check download status; it is noted that there is no reason to
1009
- //store download monitor ticket in a cookie in case of dboption, because it
1010
- //is not needed to be read by the downloader script
1011
- WFU_USVAR_store('wfu_download_monitor_ticket_'.$download_id, time() + 30);
1012
-
1013
- //store ABSPATH in user state so that it can be used by download script;
1014
- //again, in case of dboption, the only way the downloader script can read it
1015
- //is to store it in a cookie
1016
- if ( !$use_cookies ) WFU_USVAR_store_session('wfu_ABSPATH', wfu_abspath());
1017
- else array_push($cookies, '{name: "wfu_ABSPATH", value: "'.urlencode(wfu_abspath()).'", expires: 30}');
1018
- //store translatable strings to user state so that they can be used by a
1019
- //script that runs outside Wordpress environment
1020
- if ( !$use_cookies ) WFU_USVAR_store_session('wfu_browser_downloadfile_notexist', ( isset($_POST['browser']) ? WFU_BROWSER_DOWNLOADFILE_NOTEXIST : 'File does not exist!' ));
1021
- else array_push($cookies, '{name: "wfu_browser_downloadfile_notexist", value: "'.( isset($_POST['browser']) ? WFU_BROWSER_DOWNLOADFILE_NOTEXIST : 'File does not exist!' ).'", expires: 30}');
1022
- if ( !$use_cookies ) WFU_USVAR_store_session('wfu_browser_downloadfile_failed', ( isset($_POST['browser']) ? WFU_BROWSER_DOWNLOADFILE_FAILED : 'Could not download file!' ));
1023
- else array_push($cookies, '{name: "wfu_browser_downloadfile_failed", value: "'.( isset($_POST['browser']) ? WFU_BROWSER_DOWNLOADFILE_FAILED : 'Could not download file!' ).'", expires: 30}');
1024
-
1025
- //this routine returns a dynamically created iframe element, that will call
1026
- //the actual download script; the actual download script runs outside
1027
- //Wordpress environment in order to ensure that no php warnings or echo from
1028
- //other plugins is generated, that could scramble the downloaded file; a
1029
- //ticket, similar to nonces, is passed to the download script to check that
1030
- //it is not a CSRF attack; moreover,the ticket is destroyed by the time it
1031
- //is consumed by the download script, so it cannot be used again
1032
- $urlparams = 'file='.$file_code.'&ticket='.$download_id.'&handler='.$wfu_user_state_handler.'&session_legacy='.( WFU_VAR("WFU_US_SESSION_LEGACY") == "true" ? '1' : '0' ).'&dboption_base='.WFU_VAR("WFU_US_DBOPTION_BASE").'&wfu_cookie='.WPFILEUPLOAD_COOKIE;
1033
- $response["html"] = '<iframe src="'.WFU_DOWNLOADER_URL.'?'.$urlparams.'" style="display: none;"></iframe>';
1034
- //if user state handler is set to dboption (cookies), then tickets and other
1035
- //variables must pass to the download script as cookies; the cookies are
1036
- //passed in the response of this function, so that the client browser can
1037
- //add them in cookies by executing wfu_add_cookies() function
1038
- $response["js"] = ( count($cookies) > 0 ? 'wfu_add_cookies(['.implode(", ", $cookies).']);' : '' );
1039
- $response = wfu_encode_array_to_string($response);
1040
-
1041
- /** This filter is documented above. */
1042
- die(apply_filters('_wfu_ajax_action_download_file_invoker', 'wfu_ajax_action_download_file_invoker:wfu_download_id;'.$download_id.':'.$response));
1043
- }
1044
-
1045
- /**
1046
- * Monitor a File Download
1047
- *
1048
- * This function monitors a file download and performs post-download actions in
1049
- * case the download has ended.
1050
- *
1051
- * @since 2.6.0
1052
- */
1053
- function wfu_ajax_action_download_file_monitor() {
1054
- $_POST = stripslashes_deep($_POST);
1055
- $_GET = stripslashes_deep($_GET);
1056
-
1057
- $file_code = (isset($_POST['file']) ? $_POST['file'] : (isset($_GET['file']) ? $_GET['file'] : ''));
1058
- $id = (isset($_POST['id']) ? $_POST['id'] : (isset($_GET['id']) ? $_GET['id'] : ''));
1059
- if ( $file_code == '' || $id == '' ) die();
1060
- $id = wfu_sanitize_code($id);
1061
-
1062
- //ensure that this is not a CSRF attack by checking validity of a security
1063
- //ticket
1064
- if ( !WFU_USVAR_exists('wfu_download_monitor_ticket_'.$id) || time() > WFU_USVAR('wfu_download_monitor_ticket_'.$id) ) {
1065
- WFU_USVAR_unset('wfu_download_monitor_ticket_'.$id);
1066
- WFU_USVAR_unset('wfu_download_status_'.$id);
1067
- die();
1068
- }
1069
- //destroy monitor ticket so it cannot be used again
1070
- WFU_USVAR_unset('wfu_download_monitor_ticket_'.$id);
1071
-
1072
- //initiate loop of 30secs to check the download status of the file;
1073
- //the download status is controlled by the actual download script;
1074
- //if the file finishes within the 30secs of the loop, then this routine logs
1075
- //the action and notifies the client side about the download status of the
1076
- //file, otherwise an instruction to the client side to repeat this routine
1077
- //and wait for another 30secs is dispatched
1078
- $end_time = time() + 30;
1079
- $upload_ended = false;
1080
- while ( time() < $end_time ) {
1081
- $upload_ended = ( WFU_USVAR_exists('wfu_download_status_'.$id) ? ( WFU_USVAR('wfu_download_status_'.$id) == 'downloaded' || WFU_USVAR('wfu_download_status_'.$id) == 'failed' ? true : false ) : false );
1082
- if ( $upload_ended ) break;
1083
- usleep(100);
1084
- }
1085
-
1086
- if ( $upload_ended ) {
1087
- $upload_result = WFU_USVAR('wfu_download_status_'.$id);
1088
- WFU_USVAR_unset('wfu_download_status_'.$id);
1089
- $user = wp_get_current_user();
1090
- // $filepath = wfu_plugin_decode_string($file_code);
1091
- $filepath = wfu_get_filepath_from_safe($file_code);
1092
- if ( $filepath === false ) die();
1093
- $filepath = wfu_path_rel2abs(wfu_flatten_path($filepath));
1094
- wfu_log_action('download', $filepath, $user->ID, '', 0, 0, '', null);
1095
- /**
1096
- * Customise Output of Download Monitoring Operation.
1097
- *
1098
- * This filter allows scripts to customise return of this function after
1099
- * finish of it.
1100
- *
1101
- * @since 3.11.0
1102
- *
1103
- * @param string $echo_str The return of the function.
1104
- */
1105
- die(apply_filters('_wfu_ajax_action_download_file_monitor', 'wfu_ajax_action_download_file_monitor:'.$upload_result.':'));
1106
- }
1107
- else {
1108
- //regenerate monitor ticket
1109
- WFU_USVAR_store('wfu_download_monitor_ticket_'.$id, time() + 30);
1110
- /** This filter is documented above. */
1111
- die(apply_filters('_wfu_ajax_action_download_file_monitor', 'wfu_ajax_action_download_file_monitor:repeat:'.$id));
1112
- }
1113
- }
1114
-
1115
- /**
1116
- * Get View Log Page
1117
- *
1118
- * This function returns the HTML code of a specific page of View Log feature of
1119
- * the plugin in Dashboard.
1120
- *
1121
- * @since 3.5.0
1122
- */
1123
- function wfu_ajax_action_get_historylog_page() {
1124
- if ( !isset($_POST['token']) || !isset($_POST['page']) ) die();
1125
- check_ajax_referer( 'wfu-historylog-page', 'token' );
1126
- if ( !current_user_can( 'manage_options' ) ) die();
1127
- if ( WFU_VAR("WFU_HISTORYLOG_TABLE_MAXROWS") <= 0 ) die();
1128
-
1129
- $_POST = stripslashes_deep($_POST);
1130
-
1131
- $page = wfu_sanitize_int($_POST['page']);
1132
- $rows = wfu_view_log($page, true);
1133
-
1134
- /**
1135
- * Customise Output of View Log Page Retrieval.
1136
- *
1137
- * This filter allows scripts to customise return of this function after
1138
- * finish of it.
1139
- *
1140
- * @since 3.11.0
1141
- *
1142
- * @param string $echo_str The return of the function.
1143
- */
1144
- die(apply_filters('_wfu_ajax_action_get_historylog_page', 'wfu_historylog_page_success:'.wfu_plugin_encode_string($rows)));
1145
- }
1146
-
1147
- /**
1148
- * Get Uploaded Files Page
1149
- *
1150
- * This function returns the HTML code of a specific page of Uploaded Files area
1151
- * of the plugin in Dashboard.
1152
- *
1153
- * @since 4.7.0
1154
- */
1155
- function wfu_ajax_action_get_uploadedfiles_page() {
1156
- if ( !isset($_POST['token']) || !isset($_POST['page']) ) die();
1157
- check_ajax_referer( 'wfu-uploadedfiles-page', 'token' );
1158
- if ( !current_user_can( 'manage_options' ) ) die();
1159
- if ( WFU_VAR("WFU_UPLOADEDFILES_TABLE_MAXROWS") <= 0 ) die();
1160
-
1161
- $_POST = stripslashes_deep($_POST);
1162
-
1163
- $page = wfu_sanitize_int($_POST['page']);
1164
- $rows = wfu_uploadedfiles_manager($page, true);
1165
-
1166
- /**
1167
- * Customise Output of Uploaded Files Page Retrieval.
1168
- *
1169
- * This filter allows scripts to customise return of this function after
1170
- * finish of it.
1171
- *
1172
- * @since 4.7.0
1173
- *
1174
- * @param string $echo_str The return of the function.
1175
- */
1176
- die(apply_filters('_wfu_ajax_action_get_uploadedfiles_page', 'wfu_uploadedfiles_page_success:'.wfu_plugin_encode_string($rows)));
1177
- }
1178
-
1179
- /**
1180
- * Get File Browser Page
1181
- *
1182
- * This function returns the HTML code of a specific page of File Browser
1183
- * feature of the plugin in Dashboard.
1184
- *
1185
- * @since 4.6.1
1186
- */
1187
- function wfu_ajax_action_get_adminbrowser_page() {
1188
- if ( !isset($_POST['code']) || !isset($_POST['token']) || !isset($_POST['page']) ) die();
1189
-
1190
- $_POST = stripslashes_deep($_POST);
1191
-
1192
- check_ajax_referer( 'wfu-adminbrowser-page', 'token' );
1193
- if ( !current_user_can( 'manage_options' ) ) die();
1194
- if ( WFU_VAR("WFU_ADMINBROWSER_TABLE_MAXROWS") <= 0 ) die();
1195
-
1196
- $code = wfu_sanitize_code($_POST['code']);
1197
- $page = wfu_sanitize_int($_POST['page']);
1198
- //get list of files
1199
- $rows = wfu_browse_files($code, $page, true);
1200
-
1201
- /**
1202
- * Customise Output of File Browser Page Retrieval.
1203
- *
1204
- * This filter allows scripts to customise return of this function after
1205
- * finish of it.
1206
- *
1207
- * @since 4.6.1
1208
- *
1209
- * @param string $echo_str The return of the function.
1210
- */
1211
- die(apply_filters('_wfu_ajax_action_get_adminbrowser_page', 'wfu_adminbrowser_page_success:'.wfu_plugin_encode_string($rows)));
1212
- }
1213
-
1214
- /**
1215
- * Include a File in Plugin Database
1216
- *
1217
- * This function includes a file in the plugin database.
1218
- *
1219
- * @since 3.8.2
1220
- */
1221
- function wfu_ajax_action_include_file() {
1222
- $_POST = stripslashes_deep($_POST);
1223
- $_GET = stripslashes_deep($_GET);
1224
-
1225
- $file_code = (isset($_POST['file']) ? $_POST['file'] : (isset($_GET['file']) ? $_GET['file'] : ''));
1226
- $nonce = (isset($_POST['nonce']) ? $_POST['nonce'] : (isset($_GET['nonce']) ? $_GET['nonce'] : ''));
1227
- if ( $file_code == '' || $nonce == '' ) die();
1228
-
1229
- if ( !current_user_can( 'manage_options' ) ) die();
1230
- //security check to avoid CSRF attacks
1231
- if ( !wp_verify_nonce($nonce, 'wfu_include_file') ) die();
1232
-
1233
- $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
1234
- if ( $plugin_options['includeotherfiles'] != "1" ) die();
1235
-
1236
- $dec_file = wfu_get_filepath_from_safe($file_code);
1237
- if ( $dec_file === false ) die();
1238
-
1239
- $user = wp_get_current_user();
1240
- $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
1241
- $fileid = wfu_log_action('include', $dec_file, $user->ID, '', '', get_current_blog_id(), '', null);
1242
-
1243
- if ( $fileid !== false ) {
1244
- /**
1245
- * Customise Output of File Inclusion Operation.
1246
- *
1247
- * This filter allows scripts to customise return of this function after
1248
- * finish of it.
1249
- *
1250
- * @since 3.11.0
1251
- *
1252
- * @param string $echo_str The return of the function.
1253
- */
1254
- die(apply_filters('_wfu_ajax_action_include_file', "wfu_include_file:success:".$fileid));
1255
- }
1256
- /** This filter is documented above. */
1257
- else die(apply_filters('_wfu_ajax_action_include_file', 'wfu_include_file:fail:'));
1258
- }
1259
-
1260
- /**
1261
- * Update WPFilebase Manager Plugin
1262
- *
1263
- * This function instructs WPFilebase Manager plugin to synchronize its list of
1264
- * files, after a file upload.
1265
- *
1266
- * @since 2.4.1
1267
- */
1268
- function wfu_ajax_action_notify_wpfilebase() {
1269
- $_POST = stripslashes_deep($_POST);
1270
- $_GET = stripslashes_deep($_GET);
1271
-
1272
- $params_index = (isset($_POST['params_index']) ? $_POST['params_index'] : (isset($_GET['params_index']) ? $_GET['params_index'] : ''));
1273
- $session_token = (isset($_POST['session_token']) ? $_POST['session_token'] : (isset($_GET['session_token']) ? $_GET['session_token'] : ''));
1274
- if ( $params_index == '' || $session_token == '' ) die();
1275
-
1276
- $params_index = sanitize_text_field($params_index);
1277
- $session_token = sanitize_text_field($session_token);
1278
-
1279
- $arr = wfu_get_params_fields_from_index($params_index, $session_token);
1280
- //check referer using server sessions to avoid CSRF attacks
1281
- if ( WFU_USVAR("wfu_token_".$arr['shortcode_id']) != $session_token ) die();
1282
-
1283
- //execute WPFilebase plugin sunchronization by calling 'wpfilebase_sync'
1284
- //action
1285
- do_action('wpfilebase_sync');
1286
-
1287
- die();
1288
- }
1289
-
1290
- /**
1291
- * Get List of Users
1292
- *
1293
- * This function returns a list of users meeting specific criteria. Only the
1294
- * first 100 users will be returned, for avoiding performance issues.
1295
- *
1296
- * @since 4.5.0
1297
- */
1298
- function wfu_ajax_action_pdusers_get_users() {
1299
- $_POST = stripslashes_deep($_POST);
1300
- $_GET = stripslashes_deep($_GET);
1301
-
1302
- $nonce = (isset($_POST['nonce']) ? $_POST['nonce'] : (isset($_GET['nonce']) ? $_GET['nonce'] : ''));
1303
- $query = (isset($_POST['query']) ? $_POST['query'] : (isset($_GET['query']) ? $_GET['query'] : ''));
1304
- if ( $nonce == '' || $query == '' ) die();
1305
-
1306
- if ( !current_user_can( 'manage_options' ) ) die();
1307
- //security check to avoid CSRF attacks
1308
- if ( !wp_verify_nonce($nonce, 'wfu_edit_policy') ) die();
1309
-
1310
- $query = sanitize_text_field($query);
1311
- $args = array(
1312
- 'search' => $query,
1313
- 'search_columns' => array( 'user_login', 'display_name' ),
1314
- 'fields' => array( 'user_login', 'display_name' ),
1315
- 'number' => 100
1316
- );
1317
- /** This filter is documented in lib/wfu_admin_browser.php */
1318
- $args = apply_filters("_wfu_get_users", $args, "manage_pdusers");
1319
- $users = get_users($args);
1320
-
1321
- die("pdusers_get_users:".wfu_encode_array_to_string($users));
1322
- }
1323
-
1324
- ?>
1
+ <?php
2
+
3
+ /**
4
+ * AJAX Handlers of the Plugin
5
+ *
6
+ * This file contains AJAX handlers of the plugin.
7
+ *
8
+ * @link /lib/wfu_ajaxactions.php
9
+ *
10
+ * @package WordPress File Upload Plugin
11
+ * @subpackage Core Components
12
+ * @since 2.1.2
13
+ */
14
+
15
+ /**
16
+ * Execute Email Notification Dispatching
17
+ *
18
+ * This function sends an email notification after files have been uploaded.
19
+ *
20
+ * @since 2.1.2
21
+ */
22
+ function wfu_ajax_action_send_email_notification() {
23
+ $_POST = stripslashes_deep($_POST);
24
+
25
+ $user = wp_get_current_user();
26
+ if ( 0 == $user->ID ) $is_admin = false;
27
+ else $is_admin = current_user_can('manage_options');
28
+
29
+ $params_index = sanitize_text_field($_POST['params_index']);
30
+ $session_token = sanitize_text_field($_POST['session_token']);
31
+
32
+ $arr = wfu_get_params_fields_from_index($params_index, $session_token);
33
+ //check referer using server sessions to avoid CSRF attacks
34
+ $sid = $arr['shortcode_id'];
35
+ if ( WFU_USVAR("wfu_token_".$sid) != $session_token ) die();
36
+ if ( $user->user_login != $arr['user_login'] ) {
37
+ $arr = wfu_get_params_fields_from_index($params_index.'[|][|]'.$arr['page_id'].'[|][|]'.$sid.'[|][|]'.$arr['user_login'], $session_token);
38
+ if ( $user->user_login != $arr['user_login'] ) die();
39
+ }
40
+
41
+ $params_str = get_option('wfu_params_'.$arr['unique_id']);
42
+ $params = wfu_decode_array_from_string($params_str);
43
+
44
+ //check whether email notifications are activated
45
+ if ( $params["notify"] != "true" ) die();
46
+
47
+ $uniqueid = ( isset($_POST['uniqueuploadid_'.$sid]) ? sanitize_text_field($_POST['uniqueuploadid_'.$sid]) : "" );
48
+ //uniqueid cannot be empty and cannot be "no-ajax"
49
+ if ( $uniqueid == "" || $uniqueid == "no-ajax" ) die();
50
+
51
+ //retrieve the list of uploaded files from session
52
+ $target_path_list = array();
53
+ $all_files_count = 0;
54
+ if ( WFU_USVAR_exists("filedata_".$uniqueid) && is_array(WFU_USVAR("filedata_".$uniqueid)) ) {
55
+ $all_files_count = count(WFU_USVAR("filedata_".$uniqueid));
56
+ foreach ( WFU_USVAR("filedata_".$uniqueid) as $file ) {
57
+ if ( $file["upload_result"] == "success" || $file["upload_result"] == "warning" )
58
+ array_push($target_path_list, $file["filepath"]);
59
+ }
60
+ }
61
+ $uploaded_files_count = count($target_path_list);
62
+ $nofileupload = ( $params["allownofile"] == "true" && $all_files_count == 0 );
63
+ $force_notifications = ( WFU_VAR("WFU_FORCE_NOTIFICATIONS") == "true" );
64
+
65
+ //in case no files have been uploaded and this is not a nofileupload
66
+ //situation and Force Email Notifications option is not active then abort
67
+ if ( $uploaded_files_count == 0 && !$nofileupload && !$force_notifications ) die();
68
+
69
+ /* initialize return array */
70
+ $params_output_array["version"] = "full";
71
+ $params_output_array["general"]['shortcode_id'] = $params["uploadid"];
72
+ $params_output_array["general"]['unique_id'] = $uniqueid;
73
+ $params_output_array["general"]['state'] = 0;
74
+ $params_output_array["general"]['files_count'] = 0;
75
+ $params_output_array["general"]['update_wpfilebase'] = "";
76
+ $params_output_array["general"]['redirect_link'] = "";
77
+ $params_output_array["general"]['upload_finish_time'] = "";
78
+ $params_output_array["general"]['message'] = "";
79
+ $params_output_array["general"]['message_type'] = "";
80
+ $params_output_array["general"]['admin_messages']['wpfilebase'] = "";
81
+ $params_output_array["general"]['admin_messages']['notify'] = "";
82
+ $params_output_array["general"]['admin_messages']['redirect'] = "";
83
+ $params_output_array["general"]['admin_messages']['other'] = "";
84
+ $params_output_array["general"]['errors']['wpfilebase'] = "";
85
+ $params_output_array["general"]['errors']['notify'] = "";
86
+ $params_output_array["general"]['errors']['redirect'] = "";
87
+ $params_output_array["general"]['color'] = "black";
88
+ $params_output_array["general"]['bgcolor'] = "#F5F5F5";
89
+ $params_output_array["general"]['borcolor'] = "#D3D3D3";
90
+ $params_output_array["general"]['notify_by_email'] = 0;
91
+ $params_output_array["general"]['fail_message'] = WFU_ERROR_UNKNOWN;
92
+
93
+ //retrieve userdata, first get default userdata from $params
94
+ $userdata_fields = $params["userdata_fields"];
95
+ //remove any honeypot fields and initialize default values
96
+ foreach ( $userdata_fields as $userdata_key => $userdata_field )
97
+ if ( $userdata_field["type"] == "honeypot" ) unset($userdata_fields[$userdata_key]);
98
+ else $userdata_fields[$userdata_key]["value"] = "";
99
+ //then retrieve userdata from session if files exist
100
+ if ( $all_files_count > 0 && WFU_USVAR_exists("filedata_".$uniqueid) && is_array(WFU_USVAR("filedata_".$uniqueid)) ) {
101
+ foreach ( WFU_USVAR("filedata_".$uniqueid) as $file ) {
102
+ if ( isset($file["user_data"]) ) {
103
+ $userdata_fields = array();
104
+ foreach ( $file["user_data"] as $userdata_key => $userdata_field )
105
+ $userdata_fields[$userdata_key] = array( "label" => $userdata_field["label"], "value" => $userdata_field["value"] );
106
+ break;
107
+ }
108
+ }
109
+ }
110
+ //in case there are no files in session (because allownofile attribute is
111
+ //active and the user did not select any files for upload) then retrieve
112
+ //userdata from the database based on uploadid
113
+ else {
114
+ $userdata_saved = wfu_get_userdata_from_uploadid($uniqueid);
115
+ if ( $userdata_saved != null && is_array($userdata_saved) ) {
116
+ $userdata_fields = array();
117
+ foreach ( $userdata_saved as $userdata_saved_rec )
118
+ $userdata_fields[$userdata_saved_rec->propkey] = array( "label" => $userdata_saved_rec->property, "value" => $userdata_saved_rec->propvalue );
119
+ }
120
+ }
121
+
122
+ $send_error = wfu_send_notification_email($user, $target_path_list, $userdata_fields, $params);
123
+
124
+ /* suppress any errors if user is not admin */
125
+ if ( !$is_admin ) $send_error = "";
126
+
127
+ if ( $send_error != "" ) {
128
+ $params_output_array["general"]['admin_messages']['notify'] = $send_error;
129
+ $params_output_array["general"]['errors']['notify'] = "error";
130
+ }
131
+
132
+ /* construct safe output */
133
+ $sout = "0;".WFU_VAR("WFU_DEFAULTMESSAGECOLORS").";0";
134
+
135
+ $echo_str = "wfu_fileupload_success::".$sout.":".wfu_encode_array_to_string($params_output_array);
136
+ /**
137
+ * Customise Email Notification Result.
138
+ *
139
+ * This filter allows scripts to customise the result of email notification
140
+ * operation.
141
+ *
142
+ * @since 4.0.0
143
+ *
144
+ * @param string $echo_str The result of email notification operation.
145
+ */
146
+ $echo_str = apply_filters('_wfu_ajax_action_send_email_notification', $echo_str);
147
+
148
+ die($echo_str);
149
+ }
150
+
151
+ /**
152
+ * Execute Pre-Upload Actions
153
+ *
154
+ * This function executes server-side actions before the upload starts, in order
155
+ * to determine whether the upload will continue, or any other custom actions.
156
+ *
157
+ * @since 3.7.0
158
+ */
159
+ function wfu_ajax_action_ask_server() {
160
+ if ( !isset($_REQUEST['session_token']) || !isset($_REQUEST['sid']) || !isset($_REQUEST['unique_id']) ) die();
161
+
162
+ $_REQUEST = stripslashes_deep($_REQUEST);
163
+
164
+ $session_token = sanitize_text_field( $_REQUEST["session_token"] );
165
+ $sid = sanitize_text_field( $_REQUEST["sid"] );
166
+ $unique_id = wfu_sanitize_code($_REQUEST['unique_id']);
167
+ if ( $session_token == "" ) die();
168
+ //check referrer using Wordpress nonces and server sessions to avoid CSRF attacks
169
+ check_ajax_referer( 'wfu-uploader-nonce', 'wfu_uploader_nonce' );
170
+ if ( WFU_USVAR("wfu_token_".$sid) != $session_token ) die();
171
+
172
+ //prepare parameters for before-upload filters
173
+ $ret = array( "status" => "", "echo" => "" );
174
+ //retrieve file names and sizes from request parameters
175
+ $filenames_raw = ( isset($_REQUEST['filenames']) ? $_REQUEST['filenames'] : "" );
176
+ $filenames = array();
177
+ if ( trim($filenames_raw) != "" ) $filenames = explode(";", $filenames_raw);
178
+ //use wfu_basename() function in order to avoid directory traversal attacks
179
+ foreach ( $filenames as $ind => $filename ) $filenames[$ind] = wfu_basename(esc_attr(wfu_plugin_decode_string(trim($filename))));
180
+ $filesizes_raw = ( isset($_REQUEST['filesizes']) ? $_REQUEST['filesizes'] : "" );
181
+ $filesizes = array();
182
+ if ( trim($filesizes_raw) != "" ) $filesizes = explode(";", $filesizes_raw);
183
+ foreach ( $filesizes as $ind => $filesize ) $filesizes[$ind] = wfu_sanitize_int($filesize);
184
+ $files = array();
185
+ foreach ( $filenames as $ind => $filename ) {
186
+ $filesize = "";
187
+ if ( isset($filesizes[$ind]) ) $filesize = $filesizes[$ind];
188
+ array_push($files, array( "filename" => $filename, "filesize" => $filesize ));
189
+ }
190
+ $attr = array( "sid" => $sid, "unique_id" => $unique_id, "files" => $files );
191
+ //execute before upload filters
192
+ $echo_str = "";
193
+ //first execute any custom filters created by admin
194
+ if ( has_filter("wfu_before_upload") ) {
195
+ $changable_data = array( "error_message" => "", "js_script" => "" );
196
+ /**
197
+ * Execute Custom Actions Before Upload Starts.
198
+ *
199
+ * This filter allows to execute custom actions before upload starts. It
200
+ * can cancel the upload returning an error message.
201
+ *
202
+ * @since 3.7.0
203
+ *
204
+ * @param array $changable_data {
205
+ * Controls the upload.
206
+ *
207
+ * @type string $error_message An error message to display if the
208
+ * upload must be cancelled.
209
+ * @type string $js_script Javascript code to execute on user's
210
+ * browser after this filter finishes.
211
+ * }
212
+ * @param array $attr {
213
+ * Various attributes of the upload.
214
+ *
215
+ * @type string $sid The ID of the shortcode.
216
+ * @type string $unique_id The unique ID of the upload.
217
+ * @type array $files {
218
+ * Contains an array of the uploaded files.
219
+ *
220
+ * @type array $file {
221
+ * Contains information for each uploaded file.
222
+ *
223
+ * @type string $filename The filename of the file.
224
+ * @type int $filesize The size of the file.
225
+ * }
226
+ * }
227
+ * }
228
+ */
229
+ $changable_data = apply_filters("wfu_before_upload", $changable_data, $attr);
230
+ if ( $changable_data["error_message"] == "" ) $ret["status"] = "success";
231
+ else {
232
+ $ret["status"] = "error";
233
+ $echo_str .= "CBUV[".$changable_data["error_message"]."]";
234
+ }
235
+ if ( $changable_data["js_script"] != "" ) $echo_str .= "CBUVJS[".wfu_plugin_encode_string($changable_data["js_script"])."]";
236
+ }
237
+ /**
238
+ * Execute Custom Internal Actions Before Upload Starts.
239
+ *
240
+ * This filter allows to execute custom internal actions by extensions
241
+ * before upload starts. It can cancel the upload.
242
+ *
243
+ * @since 3.7.0
244
+ *
245
+ * @param array $ret {
246
+ * Controls the upload and output of this function.
247
+ *
248
+ * @type string $status The status of the upload. It must be 'success'
249
+ * or 'error'.
250
+ * @type string $echo Additional content to the echoed by the function.
251
+ * }
252
+ * @param array $attr {
253
+ * Various attributes of the upload.
254
+ *
255
+ * @type string $sid The ID of the shortcode.
256
+ * @type string $unique_id The unique ID of the upload.
257
+ * @type array $files {
258
+ * Contains an array of the uploaded files.
259
+ *
260
+ * @type array $file {
261
+ * Contains information for each uploaded file.
262
+ *
263
+ * @type string $filename The filename of the file.
264
+ * @type int $filesize The size of the file.
265
+ * }
266
+ * }
267
+ * }
268
+ */
269
+ $ret = apply_filters("_wfu_before_upload", $ret, $attr);
270
+ $echo_str .= $ret["echo"];
271
+ //in case that no filters were executed, because $ret["status"] is
272
+ //empty, then this call to wfu_ajax_action_ask_server was erroneous
273
+ if ( $ret["status"] == "" ) $ret["status"] = "die";
274
+ //create an internal flag stored in session regarding the status of this
275
+ //upload, that will be used to verify or not the upload
276
+ if ( $ret["status"] == "success" ) WFU_USVAR_store("wfu_uploadstatus_".$attr["unique_id"], 1);
277
+ else WFU_USVAR_store("wfu_uploadstatus_".$attr["unique_id"], 0);
278
+
279
+ if ( $ret["status"] == "success" || $ret["status"] == "error" )
280
+ echo "wfu_askserver_".$ret["status"].":".$echo_str;
281
+
282
+ die();
283
+ }
284
+
285
+ /**
286
+ * Execute Cancellation of Classic Upload
287
+ *
288
+ * This function sets the necessary User State variables to denote cancellation
289
+ * of the upload that was requested by the user. This function applies only to
290
+ * classic (non-AJAX) uploads.
291
+ *
292
+ * @since 4.0.0
293
+ */
294
+ function wfu_ajax_action_cancel_upload() {
295
+ if ( !isset($_REQUEST['session_token']) || !isset($_REQUEST['sid']) || !isset($_REQUEST['unique_id']) ) die();
296
+
297
+ $_REQUEST = stripslashes_deep($_REQUEST);
298
+
299
+ $session_token = sanitize_text_field( $_REQUEST["session_token"] );
300
+ $sid = sanitize_text_field( $_REQUEST["sid"] );
301
+ $unique_id = wfu_sanitize_code($_REQUEST['unique_id']);
302
+ if ( $session_token == "" ) die();
303
+ //check referrer using Wordpress nonces and server sessions to avoid CSRF attacks
304
+ check_ajax_referer( 'wfu-uploader-nonce', 'wfu_uploader_nonce' );
305
+ if ( WFU_USVAR("wfu_token_".$sid) != $session_token ) die();
306
+
307
+ //setting status to 0 denotes cancelling of the upload
308
+ WFU_USVAR_store("wfu_uploadstatus_".$unique_id, 0);
309
+
310
+ die("success");
311
+ }
312
+
313
+ /**
314
+ * Execute AJAX Upload
315
+ *
316
+ * This function is the main callback of an AJAX upload of a whole file or a
317
+ * chunk. It performs security checks to verify the user, then it performs pre-
318
+ * upload actions, then it executes wfu_process_files() function that processes
319
+ * and saves the files and then performs post-upload actions and filters.
320
+ *
321
+ * @since 2.1.2
322
+ *
323
+ * @global string $wfu_user_state_handler The defined User State handler.
324
+ */
325
+ function wfu_ajax_action_callback() {
326
+ global $wfu_user_state_handler;
327
+ if ( !isset($_REQUEST['session_token']) ) die();
328
+
329
+ $_REQUEST = stripslashes_deep($_REQUEST);
330
+ $_POST = stripslashes_deep($_POST);
331
+
332
+ $session_token = sanitize_text_field( $_REQUEST["session_token"] );
333
+ if ( $session_token == "" ) die();
334
+ check_ajax_referer( 'wfu-uploader-nonce', 'wfu_uploader_nonce' );
335
+
336
+ if ( !isset($_REQUEST['params_index']) ) die();
337
+
338
+ $params_index = sanitize_text_field( $_REQUEST["params_index"] );
339
+
340
+ if ( $params_index == "" ) die();
341
+
342
+ $user = wp_get_current_user();
343
+ $arr = wfu_get_params_fields_from_index($params_index, $session_token);
344
+ $sid = $arr['shortcode_id'];
345
+ //check referrer using server sessions to avoid CSRF attacks
346
+ if ( WFU_USVAR("wfu_token_".$sid) != $session_token ) {
347
+ $echo_str = "Session failed!<br/><br/>Session Data:<br/>";
348
+ $echo_str .= print_r(wfu_sanitize(WFU_USALL()), true);
349
+ $echo_str .= "<br/><br/>Post Data:<br/>";
350
+ $echo_str .= print_r(wfu_sanitize($_REQUEST), true);
351
+ $echo_str .= 'force_errorabort_code';
352
+ /**
353
+ * Customise Output on Session Error.
354
+ *
355
+ * This filter allows scripts to customise output of the function in
356
+ * case of session error.
357
+ *
358
+ * @since 3.11.0
359
+ *
360
+ * @param string $echo_str The output in case of session error.
361
+ */
362
+ $echo_str = apply_filters('_wfu_upload_session_failed', $echo_str);
363
+ die($echo_str);
364
+ }
365
+
366
+ if ( $user->user_login != $arr['user_login'] ) {
367
+ $arr = wfu_get_params_fields_from_index($params_index.'[|][|]'.$arr['page_id'].'[|][|]'.$sid.'[|][|]'.$arr['user_login'], $session_token);
368
+ if ( $user->user_login != $arr['user_login'] ) {
369
+ $echo_str = "User failed!<br/><br/>User Data:<br/>";
370
+ $echo_str .= print_r(wfu_sanitize($user), true);
371
+ $echo_str .= "<br/><br/>Post Data:<br/>";
372
+ $echo_str .= print_r(wfu_sanitize($_REQUEST), true);
373
+ $echo_str .= "<br/><br/>Params Data:<br/>";
374
+ $echo_str .= print_r(wfu_sanitize($arr), true);
375
+ $echo_str .= 'force_errorabort_code';
376
+ /**
377
+ * Customise Output on User Error.
378
+ *
379
+ * This filter allows scripts to customise output of the function in
380
+ * case of user error.
381
+ *
382
+ * @since 3.11.0
383
+ *
384
+ * @param string $echo_str The output in case of user error.
385
+ */
386
+ $echo_str = apply_filters('_wfu_upload_user_failed', $echo_str);
387
+ die($echo_str);
388
+ }
389
+ }
390
+
391
+ //if force_connection_close is set, then the first pass to this callback
392
+ //script is for closing the previous connection
393
+ if ( isset($_POST["force_connection_close"]) && $_POST["force_connection_close"] === "1" ) {
394
+ header("Connection: Close");
395
+ /**
396
+ * Customise Output on Forced Connection Close.
397
+ *
398
+ * This filter allows scripts to customise return of the function in
399
+ * case of forced connection close.
400
+ *
401
+ * @since 3.11.0
402
+ *
403
+ * @param string $echo_str The return in case of forced connection
404
+ * close.
405
+ */
406
+ die(apply_filters('_wfu_upload_force_connection_close', 'success'));
407
+ }
408
+
409
+ //get the unique id of the upload
410
+ $unique_id = ( isset($_POST['uniqueuploadid_'.$sid]) ? sanitize_text_field($_POST['uniqueuploadid_'.$sid]) : "" );
411
+ if ( strlen($unique_id) != 10 ) {
412
+ /**
413
+ * Customise Output on Unique ID Fail.
414
+ *
415
+ * This filter allows scripts to customise return of the function in
416
+ * case that the retrieved unique ID is invalid.
417
+ *
418
+ * @since 3.11.0
419
+ *
420
+ * @param string $echo_str The return in case of unique ID fail.
421
+ */
422
+ die(apply_filters('_wfu_upload_uniqueid_failed', 'force_errorabort_code'));
423
+ }
424
+
425
+ //if before upload actions have been executed and they have rejected the
426
+ //upload, but for some reason (hack attempt) the upload continued, then
427
+ //terminate it
428
+ if ( WFU_USVAR_exists("wfu_uploadstatus_".$unique_id) && WFU_USVAR("wfu_uploadstatus_".$unique_id) == 0 ) die('force_errorabort_code');
429
+
430
+ //get stored shortcode parameters
431
+ $params_str = get_option('wfu_params_'.$arr['unique_id']);
432
+ $params = wfu_decode_array_from_string($params_str);
433
+
434
+ //if upload has finished then perform post upload actions
435
+ if ( isset($_POST["upload_finished"]) && $_POST["upload_finished"] === "1" ) {
436
+ //remove any queues that were generated during the upload process
437
+ wfu_remove_queue($unique_id);
438
+ $echo_str = "";
439
+ //execute after upload filters
440
+ $ret = wfu_execute_after_upload_filters($sid, $unique_id, $params);
441
+ if ( $ret["js_script"] != "" ) $echo_str = "CBUVJS[".wfu_plugin_encode_string($ret["js_script"])."]";
442
+ die($echo_str);
443
+ }
444
+
445
+ //check if honeypot userdata fields have been added to the form and if they
446
+ //contain any data; if wfu_check_remove_honeypot_fields returns true this
447
+ //means that at least one honeypot field has beed filled with a value and
448
+ //the upload must be aborted because it was not done by a human
449
+ if ( $params["userdata"] == "true" && wfu_check_remove_honeypot_fields($params["userdata_fields"], 'hiddeninput_'.$sid.'_userdata_') ) die("force_abortsuccess_code");
450
+
451
+ //apply filters to determine if the upload will continue or stop
452
+ $ret = array( "status" => "", "echo" => "" );
453
+ $attr = array( "sid" => $sid, "unique_id" => $unique_id, "params" => $params );
454
+ /**
455
+ * Execute Pre-Upload Checks.
456
+ *
457
+ * This is an internal filter which allows to execute custom actions right
458
+ * before an upload starts. It can cancel the upload.
459
+ *
460
+ * @since 3.7.0
461
+ *
462
+ * @param array $ret {
463
+ * Controls the Upload.
464
+ *
465
+ * @type string $status Status of the upload. If it is 'die' then the
466
+ * upload will be cancelled.
467
+ * @type string $echo A message to return in case of upload
468
+ * cancellation.
469
+ * }
470
+ * @param array $attr {
471
+ * Various attributes of the upload.
472
+ *
473
+ * @type string $sid The ID of the shortcode.
474
+ * @type string $unique_id The unique ID of the upload.
475
+ * @type array $params The shortcode parameters of the upload form.
476
+ */
477
+ $ret = apply_filters("_wfu_pre_upload_check", $ret, $attr);
478
+ if ( $ret["status"] == "die" ) die($ret["echo"]);
479
+
480
+ //if this is the first pass of an upload attempt then perform pre-upload actions
481
+ if ( !WFU_USVAR_exists('wfu_upload_first_pass_'.$unique_id) || WFU_USVAR('wfu_upload_first_pass_'.$unique_id) != 'true' ) {
482
+ WFU_USVAR_store('wfu_upload_first_pass_'.$unique_id, 'true');
483
+ }
484
+
485
+ if ( !isset($_POST["subdir_sel_index"]) ) die();
486
+ $subdir_sel_index = sanitize_text_field( $_POST["subdir_sel_index"] );
487
+ $params['subdir_selection_index'] = $subdir_sel_index;
488
+ WFU_USVAR_store('wfu_check_refresh_'.$params["uploadid"], 'do not process');
489
+
490
+ //update consent status of user
491
+ $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
492
+ $params["consent_result"] = wfu_check_user_consent($user);
493
+ $require_consent = ( $plugin_options["personaldata"] == "1" && ( $params["notrememberconsent"] == "true" || $params["consent_result"] == "" ) && $params["askconsent"] == "true" );
494
+ if ( $require_consent ) {
495
+ if ( !isset($_POST['consent_result']) ) die();
496
+ $consent_result = ( $_POST['consent_result'] == "yes" ? "yes" : ( $_POST['consent_result'] == "no" ? "no" : "" ) );
497
+ $params["consent_result"] = ( $_POST['consent_result'] == "yes" ? "1" : ( $_POST['consent_result'] == "no" ? "0" : "" ) );
498
+ wfu_update_user_consent($user, $consent_result);
499
+ }
500
+
501
+ if ( $wfu_user_state_handler == "dboption" )
502
+ $proc_ret = wfu_run_process_in_queue($unique_id, "wfu_process_files", array( $params, 'ajax' ));
503
+ else {
504
+ $proc_ret["result"] = true;
505
+ $proc_ret["output"] = wfu_process_files($params, 'ajax');
506
+ }
507
+ $echo_str = "";
508
+ if ( $proc_ret["result"] ) {
509
+ $wfu_process_file_array = $proc_ret["output"];
510
+ //extract safe_output from wfu_process_file_array and pass it as
511
+ //separate part of the response text
512
+ $safe_output = $wfu_process_file_array["general"]['safe_output'];
513
+ unset($wfu_process_file_array["general"]['safe_output']);
514
+ //get javascript code that has been defined in wfu_after_file_upload
515
+ //action
516
+ $js_script = wfu_plugin_encode_string($wfu_process_file_array["general"]['js_script']);
517
+ unset($wfu_process_file_array["general"]['js_script']);
518
+
519
+ $echo_str = "wfu_fileupload_success:".$js_script.":".$safe_output.":".wfu_encode_array_to_string($wfu_process_file_array);
520
+ }
521
+ elseif ( $proc_ret["error"] == "abort_thread" ) wfu_advance_queue($unique_id);
522
+ /**
523
+ * Customise Output of Successful AJAX Upload.
524
+ *
525
+ * This filter allows scripts to customise return of the function in case
526
+ * that the AJAX upload was successful.
527
+ *
528
+ * @since 3.11.0
529
+ *
530
+ * @param string $echo_str The return in case of successful AJAX upload.
531
+ */
532
+ $echo_str = apply_filters('_wfu_upload_callback_success', $echo_str);
533
+ die($echo_str);
534
+ }
535
+
536
+ /**
537
+ * Execute Saving of Shortcode
538
+ *
539
+ * This function executes saving of a shortcode after it has been edited through
540
+ * the shortcode composer.
541
+ *
542
+ * @since 2.1.3
543
+ */
544
+ function wfu_ajax_action_save_shortcode() {
545
+ $is_admin = current_user_can( 'manage_options' );
546
+ $can_open_composer = ( WFU_VAR("WFU_SHORTCODECOMPOSER_NOADMIN") == "true" && ( current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) ) );
547
+ if ( !$is_admin && !$can_open_composer ) die();
548
+ if ( !isset($_POST['shortcode']) || !isset($_POST['shortcode_original']) || !isset($_POST['post_id']) || !isset($_POST['post_hash']) || !isset($_POST['shortcode_position']) || !isset($_POST['shortcode_tag']) || !isset($_POST['widget_id']) ) die();
549
+
550
+ $_POST = stripslashes_deep($_POST);
551
+
552
+ //sanitize parameters
553
+ $shortcode = wfu_sanitize_code($_POST['shortcode']);
554
+ $shortcode_original = wfu_sanitize_code($_POST['shortcode_original']);
555
+ $post_id = wfu_sanitize_int($_POST['post_id']);
556
+ $post_hash = wfu_sanitize_code($_POST['post_hash']);
557
+ $shortcode_position = wfu_sanitize_int($_POST['shortcode_position']);
558
+ $shortcode_tag = wfu_sanitize_tag($_POST['shortcode_tag']);
559
+ $widget_id = sanitize_text_field($_POST['widget_id']);
560
+
561
+ $shortcode = wfu_sanitize_shortcode(wfu_plugin_decode_string($shortcode), $shortcode_tag);
562
+
563
+ if ( $post_id == "" && $widget_id == "" ) {
564
+ die();
565
+ }
566
+ else {
567
+ $data['post_id'] = $post_id;
568
+ $data['post_hash'] = $post_hash;
569
+ $data['shortcode'] = wfu_plugin_decode_string($shortcode_original);
570
+ $data['position'] = $shortcode_position;
571
+ if ( $post_id != "" && !wfu_check_edit_shortcode($data) ) $echo_str = "wfu_save_shortcode:fail:post_modified";
572
+ else {
573
+ if ( $widget_id == "" ) {
574
+ $new_shortcode = "[".$shortcode_tag." ".$shortcode."]";
575
+ if ( wfu_replace_shortcode($data, $new_shortcode) ) {
576
+ $post = get_post($post_id);
577
+ /** This filter is described in wfu_loader.php */
578
+ $content = apply_filters("_wfu_get_post_content", $post->post_content, $post);
579
+ $hash = hash('md5', $content);
580
+ $echo_str = "wfu_save_shortcode:success:".$hash;
581
+ }
582
+ else $echo_str = "wfu_save_shortcode:fail:post_update_failed";
583
+ }
584
+ else {
585
+ $widget_obj = wfu_get_widget_obj_from_id($widget_id);
586
+ if ( $widget_obj === false ) $echo_str = "wfu_save_shortcode:fail:post_update_failed";
587
+ else {
588
+ $widget_sidebar = is_active_widget(false, $widget_id, "wordpress_file_upload_widget");
589
+ if ( !$widget_sidebar ) $echo_str = "wfu_save_shortcode:fail:post_update_failed";
590
+ else {
591
+ $widget_obj->update_external($shortcode);
592
+ $hash = $data['post_hash'];
593
+ $echo_str = "wfu_save_shortcode:success:".$hash;
594
+ }
595
+ }
596
+ }
597
+ }
598
+ }
599
+
600
+ /**
601
+ * Customise Output on Shortcode Saving.
602
+ *
603
+ * This filter allows scripts to customise return of the function after
604
+ * finish of it.
605
+ *
606
+ * @since 3.11.0
607
+ *
608
+ * @param string $echo_str The return of the function.
609
+ */
610
+ $echo_str = apply_filters('_wfu_ajax_action_save_shortcode', $echo_str);
611
+ die($echo_str);
612
+ }
613
+
614
+ /**
615
+ * Execute Checking of Post Contents
616
+ *
617
+ * This function executes checking of post contents to determine whether they
618
+ * are current or obsolete (they have changed).
619
+ *
620
+ * @since 2.6.0
621
+ */
622
+ function wfu_ajax_action_check_page_contents() {
623
+ if ( !current_user_can( 'manage_options' ) ) die();
624
+ if ( !isset($_POST['post_id']) || !isset($_POST['post_hash']) ) die();
625
+ if ( $_POST['post_id'] == "" ) die();
626
+
627
+ $_POST = stripslashes_deep($_POST);
628
+
629
+ $data['post_id'] = wfu_sanitize_int($_POST['post_id']);
630
+ $data['post_hash'] = wfu_sanitize_code($_POST['post_hash']);
631
+ if ( wfu_check_edit_shortcode($data) ) $echo_str = "wfu_check_page_contents:current:";
632
+ else $echo_str = "wfu_check_page_contents:obsolete:";
633
+
634
+ /**
635
+ * Customise Output of Post Contents Checking Function.
636
+ *
637
+ * This filter allows scripts to customise return of this function after
638
+ * finish of it.
639
+ *
640
+ * @since 3.11.0
641
+ *
642
+ * @param string $echo_str The return of the function.
643
+ */
644
+ $echo_str = apply_filters('_wfu_ajax_action_check_page_contents', $echo_str);
645
+ die($echo_str);
646
+ }
647
+
648
+ /**
649
+ * Initiate Editing of Shortcode
650
+ *
651
+ * This function invokes the shortcode composer in order to edit a shortcode. It
652
+ * applies when editing a shortcode from Main page of the plugin in Dashboard or
653
+ * from a front-end post or page or from a sidebar.
654
+ *
655
+ * @since 2.6.0
656
+ */
657
+ function wfu_ajax_action_edit_shortcode() {
658
+ global $wp_registered_widgets;
659
+ global $wp_registered_sidebars;
660
+
661
+ $is_admin = current_user_can( 'manage_options' );
662
+ $can_open_composer = ( WFU_VAR("WFU_SHORTCODECOMPOSER_NOADMIN") == "true" && ( current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) ) );
663
+ if ( !$is_admin && !$can_open_composer ) die();
664
+ if ( !isset($_POST['upload_id']) || !isset($_POST['post_id']) || !isset($_POST['post_hash']) || !isset($_POST['shortcode_tag']) || !isset($_POST['widget_id']) ) die();
665
+
666
+ $_POST = stripslashes_deep($_POST);
667
+
668
+ //sanitize parameters
669
+ $upload_id = sanitize_text_field($_POST['upload_id']);
670
+ $widget_id = sanitize_text_field($_POST['widget_id']);
671
+ $post_id = wfu_sanitize_int($_POST['post_id']);
672
+ $post_hash = wfu_sanitize_code($_POST['post_hash']);
673
+ $shortcode_tag = wfu_sanitize_tag($_POST['shortcode_tag']);
674
+
675
+ $keyname = "uploadid";
676
+ if ( $shortcode_tag == "wordpress_file_upload_browser" ) $keyname = "browserid";
677
+
678
+ $data['post_id'] = $post_id;
679
+ $data['post_hash'] = $post_hash;
680
+ if ( wfu_check_edit_shortcode($data) ) {
681
+ if ( $widget_id == "" ) {
682
+ $post = get_post($data['post_id']);
683
+ //get default value for uploadid
684
+ if ( $shortcode_tag == "wordpress_file_upload_browser" ) $defs = wfu_browser_attribute_definitions();
685
+ else $defs = wfu_attribute_definitions();
686
+ $default = "";
687
+ foreach ( $defs as $key => $def ) {
688
+ if ( $def['attribute'] == $keyname ) {
689
+ $default = $def['value'];
690
+ break;
691
+ }
692
+ }
693
+ //get page shortcodes
694
+ $wfu_shortcodes = wfu_get_content_shortcodes($post, $shortcode_tag);
695
+ //find the shortcodes' uploadid and the correct one
696
+ $validkey = -1;
697
+ foreach ( $wfu_shortcodes as $key => $data ) {
698
+ $shortcode = trim(substr($data['shortcode'], strlen('['.$shortcode_tag), -1));
699
+ $shortcode_attrs = wfu_shortcode_string_to_array($shortcode);
700
+ if ( array_key_exists($keyname, $shortcode_attrs) ) $uploadid = $shortcode_attrs[$keyname];
701
+ else $uploadid = $default;
702
+ if ( $uploadid == $upload_id ) {
703
+ $validkey = $key;
704
+ break;
705
+ }
706
+ }
707
+ if ( $validkey == -1 ) die();
708
+ $data_enc = wfu_safe_store_shortcode_data(wfu_encode_array_to_string($wfu_shortcodes[$validkey]));
709
+ }
710
+ else {
711
+ $widget_obj = wfu_get_widget_obj_from_id($widget_id);
712
+ if ( $widget_obj === false ) die();
713
+ $widget_sidebar = is_active_widget(false, $widget_id, "wordpress_file_upload_widget");
714
+ if ( !$widget_sidebar ) die();
715
+ if ( isset($wp_registered_sidebars[$widget_sidebar]) && isset($wp_registered_sidebars[$widget_sidebar]['name']) ) $widget_sidebar = $wp_registered_sidebars[$widget_sidebar]['name'];
716
+ $data['shortcode'] = $widget_obj->shortcode();
717
+ $data['position'] = 0;
718
+ $data['widgetid'] = $widget_id;
719
+ $data['sidebar'] = $widget_sidebar;
720
+ $data_enc = wfu_safe_store_shortcode_data(wfu_encode_array_to_string($data));
721
+ }
722
+ if( $is_admin ) $url = site_url().'/wp-admin/options-general.php?page=wordpress_file_upload&tag='.$shortcode_tag.'&action=edit_shortcode&data='.$data_enc;
723
+ //conditional that will open the shortcode composer for non-admin users
724
+ //who can edit posts or pages
725
+ else $url = site_url().'/wp-admin/admin.php?page=wordpress_file_upload&tag='.$shortcode_tag.'&action=edit_shortcode&data='.$data_enc;
726
+ $echo_str = "wfu_edit_shortcode:success:".wfu_plugin_encode_string($url);
727
+ }
728
+ else $echo_str = "wfu_edit_shortcode:check_page_obsolete:".WFU_ERROR_PAGE_OBSOLETE;
729
+
730
+ /**
731
+ * Customise Output of Shortcode Editing Initiation Function.
732
+ *
733
+ * This filter allows scripts to customise return of this function after
734
+ * finish of it.
735
+ *
736
+ * @since 3.11.0
737
+ *
738
+ * @param string $echo_str The return of the function.
739
+ */
740
+ $echo_str = apply_filters('_wfu_ajax_action_edit_shortcode', $echo_str);
741
+ die($echo_str);
742
+ }
743
+
744
+ /**
745
+ * Initiate Editing of Shortcode in Gutenberg Editor
746
+ *
747
+ * This function invokes the shortcode composer in order to edit a shortcode. It
748
+ * applies when editing a shortcode from the new Gutenberg page editor of
749
+ * Wordpress.
750
+ *
751
+ * @since 4.11.0
752
+ */
753
+ function wfu_ajax_action_gutedit_shortcode() {
754
+ $is_admin = current_user_can( 'manage_options' );
755
+ $can_open_composer = ( WFU_VAR("WFU_SHORTCODECOMPOSER_NOADMIN") == "true" && ( current_user_can( 'edit_pages' ) || current_user_can( 'edit_posts' ) ) );
756
+ if ( !$is_admin && !$can_open_composer ) die();
757
+ if ( !isset($_POST['shortcode']) || !isset($_POST['post_id']) || !isset($_POST['shortcode_tag']) ) die();
758
+
759
+ $_POST = stripslashes_deep($_POST);
760
+
761
+ //sanitize parameters
762
+ $shortcode = wfu_sanitize_code($_POST['shortcode']);
763
+ $post_id = wfu_sanitize_int($_POST['post_id']);
764
+ $shortcode_tag = wfu_sanitize_tag($_POST['shortcode_tag']);
765
+
766
+ $shortcode = wfu_sanitize_shortcode(wfu_plugin_decode_string($shortcode), $shortcode_tag);
767
+
768
+ if ( $post_id == "" ) die();
769
+
770
+ $data['shortcode'] = '['.$shortcode_tag.' '.$shortcode.']';
771
+ $data['post_id'] = $post_id;
772
+ $data['post_hash'] = '';
773
+ $data['position'] = 0;
774
+ $data_enc = wfu_safe_store_shortcode_data(wfu_encode_array_to_string($data));
775
+ if ( $is_admin ) $url = site_url().'/wp-admin/options-general.php?page=wordpress_file_upload&tag='.$shortcode_tag.'&action=edit_shortcode&data='.$data_enc.'&referer=guteditor';
776
+ //conditional that will open the shortcode composer for non-admin users who
777
+ //can edit posts or pages
778
+ else $url = site_url().'/wp-admin/admin.php?page=wordpress_file_upload&tag='.$shortcode_tag.'&action=edit_shortcode&data='.$data_enc.'&referer=guteditor';
779
+
780
+ $echo_str = "wfu_gutedit_shortcode:success:".wfu_plugin_encode_string($url);
781
+ /**
782
+ * Customise Output of Gutenberg Shortcode Editing Initiation Function.
783
+ *
784
+ * This filter allows scripts to customise return of this function after
785
+ * finish of it.
786
+ *
787
+ * @since 4.11.0
788
+ *
789
+ * @param string $echo_str The return of the function.
790
+ */
791
+ $echo_str = apply_filters('_wfu_ajax_action_gutedit_shortcode', $echo_str);
792
+ die($echo_str);
793
+ }
794
+
795
+ /**
796
+ * Retrieve Subfolder Structure of a Folder
797
+ *
798
+ * This function is used to retrieve the subfolder structure of a folder,
799
+ * together with the subfolder structure of one of the subfolders. It is used
800
+ * when defining the subfolders of the subfolders element of the upload form
801
+ * using the shortcoe composer.
802
+ *
803
+ * @since 2.4.1
804
+ */
805
+ function wfu_ajax_action_read_subfolders() {
806
+ if ( !isset($_POST['folder1']) || !isset($_POST['folder2']) ) die();
807
+
808
+ $_POST = stripslashes_deep($_POST);
809
+
810
+ $folder1 = wfu_sanitize_code($_POST['folder1']);
811
+ $folder1 = wfu_sanitize_url(wfu_plugin_decode_string($folder1));
812
+ $folder2 = wfu_sanitize_code($_POST['folder2']);
813
+ $folder2 = wfu_sanitize_url(wfu_plugin_decode_string($folder2));
814
+ if ( wfu_plugin_encode_string($folder1) != $_POST['folder1'] || wfu_plugin_encode_string($folder2) != $_POST['folder2'] ) die();
815
+
816
+ $temp_params = array( 'uploadpath' => $folder1, 'accessmethod' => 'normal', 'ftpinfo' => '', 'useftpdomain' => 'false' );
817
+ $path = wfu_upload_plugin_full_path($temp_params);
818
+
819
+ if ( !is_dir($path) ) {
820
+ /**
821
+ * Customise Output of Shortcode Subfolder Structure Retrieval.
822
+ *
823
+ * This filter allows scripts to customise return of this function after
824
+ * finish of it.
825
+ *
826
+ * @since 3.11.0
827
+ *
828
+ * @param string $echo_str The return of the function.
829
+ */
830
+ die(apply_filters('_wfu_ajax_action_read_subfolders', 'wfu_read_subfolders:error:Parent folder is not valid! Cannot retrieve subfolder list.'));
831
+ }
832
+
833
+ $path2 = $folder2;
834
+ $dirlist = "";
835
+ if ( $handle = opendir($path) ) {
836
+ $blacklist = array('.', '..');
837
+ while ( false !== ($file = readdir($handle)) )
838
+ if ( !in_array($file, $blacklist) ) {
839
+ $filepath = $path.$file;
840
+ if ( is_dir($filepath) ) {
841
+ if ( $file == $path2 ) $file = '[['.$file.']]';
842
+ $dirlist .= ( $dirlist == "" ? "" : "," ).$file;
843
+ }
844
+ }
845
+ closedir($handle);
846
+ }
847
+ if ( $path2 != "" ) {
848
+ $dirlist2 = $path2;
849
+ $path .= $path2."/";
850
+ if ( is_dir($path) ) {
851
+ if ( $handle = opendir($path) ) {
852
+ $blacklist = array('.', '..');
853
+ while ( false !== ($file = readdir($handle)) )
854
+ if ( !in_array($file, $blacklist) ) {
855
+ $filepath = $path.$file;
856
+ if ( is_dir($filepath) )
857
+ $dirlist2 .= ",*".$file;
858
+ }
859
+ closedir($handle);
860
+ }
861
+ }
862
+ $dirlist = str_replace('[['.$path2.']]', $dirlist2, $dirlist);
863
+ }
864
+
865
+ /** This filter is documnted above. */
866
+ die(apply_filters('_wfu_ajax_action_read_subfolders', "wfu_read_subfolders:success:".wfu_plugin_encode_string($dirlist)));
867
+ }
868
+
869
+ /**
870
+ * Initiate a File Download
871
+ *
872
+ * This function initiates a file download. It will first check whether the user
873
+ * has the right to download the file. Then it will return an iframe element
874
+ * that will start the download. Short life tokens are used in order to avoid
875
+ * CSRF attacks. Download is executed outside Wordpress enviroment because some
876
+ * times Wordpress environment outputs warnings that are downloaded with the
877
+ * file, resulting in a broken download.
878
+ *
879
+ * @since 2.6.0
880
+ */
881
+ function wfu_ajax_action_download_file_invoker() {
882
+ global $wfu_user_state_handler;
883
+
884
+ $_POST = stripslashes_deep($_POST);
885
+ $_GET = stripslashes_deep($_GET);
886
+
887
+ $file_code = (isset($_POST['file']) ? $_POST['file'] : (isset($_GET['file']) ? $_GET['file'] : ''));
888
+ $nonce = (isset($_POST['nonce']) ? $_POST['nonce'] : (isset($_GET['nonce']) ? $_GET['nonce'] : ''));
889
+ if ( $file_code == '' || $nonce == '' ) die();
890
+
891
+ //security check to avoid CSRF attacks
892
+ if ( !wp_verify_nonce($nonce, 'wfu_download_file_invoker') ) die();
893
+
894
+ //check if user is allowed to download files
895
+ if ( !current_user_can( 'manage_options' ) ) {
896
+ die();
897
+ }
898
+
899
+ $cookies = array();
900
+ $use_cookies = ( $wfu_user_state_handler == "dboption" && WFU_VAR("WFU_US_DBOPTION_BASE") == "cookies" );
901
+ $file_code = sanitize_text_field($file_code);
902
+ //if file_code is exportdata, then export of data has been requested and
903
+ //we need to create a file with export data and recreate file_code
904
+ if ( substr($file_code, 0, 10) == "exportdata" && current_user_can( 'manage_options' ) ) {
905
+ $params = null;
906
+ $params_str = substr($file_code, 11);
907
+ if ( trim($params_str) != "" ) $params = json_decode($params_str, true);
908
+ $filepath = wfu_export_uploaded_files($params);
909
+ if ( $filepath === false ) die();
910
+ $file_code = "exportdata".wfu_safe_store_filepath($filepath);
911
+ //store filepath in user state otherwise it can not be retrieved by
912
+ //downloader script
913
+ if ( !$use_cookies ) WFU_USVAR_store_session('wfu_storage_'.substr($file_code, 10), $filepath);
914
+ else array_push($cookies, '{name: "wfu_storage_'.substr($file_code, 10).'", value: "'.$filepath.'", expires: 30}');
915
+ }
916
+ //else get the file path from the safe
917
+ else {
918
+ $filepath = wfu_get_filepath_from_safe($file_code);
919
+ if ( $filepath === false ) die();
920
+ $filepath = wfu_path_rel2abs(wfu_flatten_path($filepath));
921
+ //reject download of blacklisted file types for security reasons
922
+ if ( wfu_file_extension_blacklisted($filepath) ) {
923
+ /**
924
+ * Customise Output of Download Initiation Operation.
925
+ *
926
+ * This filter allows scripts to customise return of this function
927
+ * after finish of it.
928
+ *
929
+ * @since 3.11.0
930
+ *
931
+ * @param string $echo_str The return of the function.
932
+ */
933
+ die(apply_filters('_wfu_ajax_action_download_file_invoker', 'wfu_ajax_action_download_file_invoker:not_allowed:'.( isset($_POST['browser']) ? WFU_BROWSER_DOWNLOADFILE_NOTALLOWED : 'You are not allowed to download this file!' )));
934
+ }
935
+ //for front-end browser apply wfu_browser_check_file_action filter to
936
+ //allow or restrict the download
937
+ if ( isset($_POST['browser']) ) {
938
+ $changable_data["error_message"] = "";
939
+ $filerec = wfu_get_file_rec($filepath, true);
940
+ $userdata = array();
941
+ foreach ( $filerec->userdata as $data )
942
+ array_push($userdata, array( "label" => $data->property, "value" => $data->propvalue ));
943
+ $additional_data = array(
944
+ "file_action" => "download",
945
+ "filepath" => $filepath,
946
+ "uploaduser" => $filerec->uploaduserid,
947
+ "userdata" => $userdata
948
+ );
949
+ /**
950
+ * Check if Action is Allowed in Front-End File Browser.
951
+ *
952
+ * This filter allows scripts to check whether the action on a file
953
+ * from the front-end file browser is allowed.
954
+ *
955
+ * @since 3.7.2
956
+ *
957
+ * @param array $changable_data {
958
+ * Controls allowance or rejection of the action.
959
+ *
960
+ * @type string $error_message An error message to return in
961
+ * case the action must be rejected.
962
+ * }
963
+ * @param array $additional_data {
964
+ * Additional data of the file action operation.
965
+ *
966
+ * @type string $file_action The performed action.
967
+ * @type string $filepath The full path of the file.
968
+ * @type string $uploaduser The ID of the user who uploaded
969
+ * the file.
970
+ * @type array $userdata Each item of the array contains the
971
+ * label and value of any additional userdata exist
972
+ * together with the file.
973
+ * }
974
+ */
975
+ $changable_data = apply_filters("wfu_browser_check_file_action", $changable_data, $additional_data);
976
+ if ( $changable_data["error_message"] != "" )
977
+ /** This filter is documented above. */
978
+ die(apply_filters('_wfu_ajax_action_download_file_invoker', 'wfu_ajax_action_download_file_invoker:not_allowed:'.$changable_data["error_message"]));
979
+ }
980
+ //for back-end browser check if user is allowed to perform this action
981
+ //on this file
982
+ if ( !wfu_current_user_owes_file($filepath) ) die();
983
+ //store filepath in user state otherwise it can not be retrieved by
984
+ //downloader script
985
+ if ( !$use_cookies ) WFU_USVAR_store_session('wfu_storage_'.$file_code, wfu_get_filepath_from_safe($file_code));
986
+ else array_push($cookies, '{name: "wfu_storage_'.$file_code.'", value: "'.wfu_get_filepath_from_safe($file_code).'", expires: 30}');
987
+ }
988
+
989
+ //generate download unique id to monitor this download
990
+ $download_id = wfu_create_random_string(16);
991
+ //store download status of this download in user state, so that it can be
992
+ //changed by downloader script; it is noted that the downloader script
993
+ //does not load WP environment, so in case of dboption it cannot access the
994
+ //download status (which is stored in the database); however the downloader
995
+ //script does not need to read it; it only needs to change it after the
996
+ //download; so after the download, the downloader script loads WP
997
+ //environment, so that it can change download status
998
+ WFU_USVAR_store('wfu_download_status_'.$download_id, 'starting');
999
+ //generate download ticket which expires in 30sec and store it in user
1000
+ //state; it will be used as security measure for the downloader script,
1001
+ //which runs outside Wordpress environment; it is noted that the downloader
1002
+ //script needs to read download ticket before the download; however in the
1003
+ //case of dboption the only way to achieve this is to store it in a cookie
1004
+ if ( !$use_cookies ) WFU_USVAR_store_session('wfu_download_ticket_'.$download_id, time() + 30);
1005
+ else array_push($cookies, '{name: "wfu_download_ticket_'.$download_id.'", value: '.(time() + 30).', expires: 30}');
1006
+ //generate download monitor ticket which expires in 30sec and store it in
1007
+ //user state; it will be used as security measure for the monitor script
1008
+ //that will check download status; it is noted that there is no reason to
1009
+ //store download monitor ticket in a cookie in case of dboption, because it
1010
+ //is not needed to be read by the downloader script
1011
+ WFU_USVAR_store('wfu_download_monitor_ticket_'.$download_id, time() + 30);
1012
+
1013
+ //store ABSPATH in user state so that it can be used by download script;
1014
+ //again, in case of dboption, the only way the downloader script can read it
1015
+ //is to store it in a cookie
1016
+ if ( !$use_cookies ) WFU_USVAR_store_session('wfu_ABSPATH', wfu_abspath());
1017
+ else array_push($cookies, '{name: "wfu_ABSPATH", value: "'.urlencode(wfu_abspath()).'", expires: 30}');
1018
+ //store translatable strings to user state so that they can be used by a
1019
+ //script that runs outside Wordpress environment
1020
+ if ( !$use_cookies ) WFU_USVAR_store_session('wfu_browser_downloadfile_notexist', ( isset($_POST['browser']) ? WFU_BROWSER_DOWNLOADFILE_NOTEXIST : 'File does not exist!' ));
1021
+ else array_push($cookies, '{name: "wfu_browser_downloadfile_notexist", value: "'.( isset($_POST['browser']) ? WFU_BROWSER_DOWNLOADFILE_NOTEXIST : 'File does not exist!' ).'", expires: 30}');
1022
+ if ( !$use_cookies ) WFU_USVAR_store_session('wfu_browser_downloadfile_failed', ( isset($_POST['browser']) ? WFU_BROWSER_DOWNLOADFILE_FAILED : 'Could not download file!' ));
1023
+ else array_push($cookies, '{name: "wfu_browser_downloadfile_failed", value: "'.( isset($_POST['browser']) ? WFU_BROWSER_DOWNLOADFILE_FAILED : 'Could not download file!' ).'", expires: 30}');
1024
+
1025
+ //this routine returns a dynamically created iframe element, that will call
1026
+ //the actual download script; the actual download script runs outside
1027
+ //Wordpress environment in order to ensure that no php warnings or echo from
1028
+ //other plugins is generated, that could scramble the downloaded file; a
1029
+ //ticket, similar to nonces, is passed to the download script to check that
1030
+ //it is not a CSRF attack; moreover,the ticket is destroyed by the time it
1031
+ //is consumed by the download script, so it cannot be used again
1032
+ $urlparams = 'file='.$file_code.'&ticket='.$download_id.'&handler='.$wfu_user_state_handler.'&session_legacy='.( WFU_VAR("WFU_US_SESSION_LEGACY") == "true" ? '1' : '0' ).'&dboption_base='.WFU_VAR("WFU_US_DBOPTION_BASE").'&wfu_cookie='.WPFILEUPLOAD_COOKIE;
1033
+ $response["html"] = '<iframe src="'.WFU_DOWNLOADER_URL.'?'.$urlparams.'" style="display: none;"></iframe>';
1034
+ //if user state handler is set to dboption (cookies), then tickets and other
1035
+ //variables must pass to the download script as cookies; the cookies are
1036
+ //passed in the response of this function, so that the client browser can
1037
+ //add them in cookies by executing wfu_add_cookies() function
1038
+ $response["js"] = ( count($cookies) > 0 ? 'wfu_add_cookies(['.implode(", ", $cookies).']);' : '' );
1039
+ $response = wfu_encode_array_to_string($response);
1040
+
1041
+ /** This filter is documented above. */
1042
+ die(apply_filters('_wfu_ajax_action_download_file_invoker', 'wfu_ajax_action_download_file_invoker:wfu_download_id;'.$download_id.':'.$response));
1043
+ }
1044
+
1045
+ /**
1046
+ * Monitor a File Download
1047
+ *
1048
+ * This function monitors a file download and performs post-download actions in
1049
+ * case the download has ended.
1050
+ *
1051
+ * @since 2.6.0
1052
+ */
1053
+ function wfu_ajax_action_download_file_monitor() {
1054
+ $_POST = stripslashes_deep($_POST);
1055
+ $_GET = stripslashes_deep($_GET);
1056
+
1057
+ $file_code = (isset($_POST['file']) ? $_POST['file'] : (isset($_GET['file']) ? $_GET['file'] : ''));
1058
+ $id = (isset($_POST['id']) ? $_POST['id'] : (isset($_GET['id']) ? $_GET['id'] : ''));
1059
+ if ( $file_code == '' || $id == '' ) die();
1060
+ $id = wfu_sanitize_code($id);
1061
+
1062
+ //ensure that this is not a CSRF attack by checking validity of a security
1063
+ //ticket
1064
+ if ( !WFU_USVAR_exists('wfu_download_monitor_ticket_'.$id) || time() > WFU_USVAR('wfu_download_monitor_ticket_'.$id) ) {
1065
+ WFU_USVAR_unset('wfu_download_monitor_ticket_'.$id);
1066
+ WFU_USVAR_unset('wfu_download_status_'.$id);
1067
+ die();
1068
+ }
1069
+ //destroy monitor ticket so it cannot be used again
1070
+ WFU_USVAR_unset('wfu_download_monitor_ticket_'.$id);
1071
+
1072
+ //initiate loop of 30secs to check the download status of the file;
1073
+ //the download status is controlled by the actual download script;
1074
+ //if the file finishes within the 30secs of the loop, then this routine logs
1075
+ //the action and notifies the client side about the download status of the
1076
+ //file, otherwise an instruction to the client side to repeat this routine
1077
+ //and wait for another 30secs is dispatched
1078
+ $end_time = time() + 30;
1079
+ $upload_ended = false;
1080
+ while ( time() < $end_time ) {
1081
+ $upload_ended = ( WFU_USVAR_exists('wfu_download_status_'.$id) ? ( WFU_USVAR('wfu_download_status_'.$id) == 'downloaded' || WFU_USVAR('wfu_download_status_'.$id) == 'failed' ? true : false ) : false );
1082
+ if ( $upload_ended ) break;
1083
+ usleep(100);
1084
+ }
1085
+
1086
+ if ( $upload_ended ) {
1087
+ $upload_result = WFU_USVAR('wfu_download_status_'.$id);
1088
+ WFU_USVAR_unset('wfu_download_status_'.$id);
1089
+ $user = wp_get_current_user();
1090
+ // $filepath = wfu_plugin_decode_string($file_code);
1091
+ $filepath = wfu_get_filepath_from_safe($file_code);
1092
+ if ( $filepath === false ) die();
1093
+ $filepath = wfu_path_rel2abs(wfu_flatten_path($filepath));
1094
+ wfu_log_action('download', $filepath, $user->ID, '', 0, 0, '', null);
1095
+ /**
1096
+ * Customise Output of Download Monitoring Operation.
1097
+ *
1098
+ * This filter allows scripts to customise return of this function after
1099
+ * finish of it.
1100
+ *
1101
+ * @since 3.11.0
1102
+ *
1103
+ * @param string $echo_str The return of the function.
1104
+ */
1105
+ die(apply_filters('_wfu_ajax_action_download_file_monitor', 'wfu_ajax_action_download_file_monitor:'.$upload_result.':'));
1106
+ }
1107
+ else {
1108
+ //regenerate monitor ticket
1109
+ WFU_USVAR_store('wfu_download_monitor_ticket_'.$id, time() + 30);
1110
+ /** This filter is documented above. */
1111
+ die(apply_filters('_wfu_ajax_action_download_file_monitor', 'wfu_ajax_action_download_file_monitor:repeat:'.$id));
1112
+ }
1113
+ }
1114
+
1115
+ /**
1116
+ * Get View Log Page
1117
+ *
1118
+ * This function returns the HTML code of a specific page of View Log feature of
1119
+ * the plugin in Dashboard.
1120
+ *
1121
+ * @since 3.5.0
1122
+ */
1123
+ function wfu_ajax_action_get_historylog_page() {
1124
+ if ( !isset($_POST['token']) || !isset($_POST['page']) ) die();
1125
+ check_ajax_referer( 'wfu-historylog-page', 'token' );
1126
+ if ( !current_user_can( 'manage_options' ) ) die();
1127
+ if ( WFU_VAR("WFU_HISTORYLOG_TABLE_MAXROWS") <= 0 ) die();
1128
+
1129
+ $_POST = stripslashes_deep($_POST);
1130
+
1131
+ $page = wfu_sanitize_int($_POST['page']);
1132
+ $rows = wfu_view_log($page, true);
1133
+
1134
+ /**
1135
+ * Customise Output of View Log Page Retrieval.
1136
+ *
1137
+ * This filter allows scripts to customise return of this function after
1138
+ * finish of it.
1139
+ *
1140
+ * @since 3.11.0
1141
+ *
1142
+ * @param string $echo_str The return of the function.
1143
+ */
1144
+ die(apply_filters('_wfu_ajax_action_get_historylog_page', 'wfu_historylog_page_success:'.wfu_plugin_encode_string($rows)));
1145
+ }
1146
+
1147
+ /**
1148
+ * Get Uploaded Files Page
1149
+ *
1150
+ * This function returns the HTML code of a specific page of Uploaded Files area
1151
+ * of the plugin in Dashboard.
1152
+ *
1153
+ * @since 4.7.0
1154
+ */
1155
+ function wfu_ajax_action_get_uploadedfiles_page() {
1156
+ if ( !isset($_POST['token']) || !isset($_POST['page']) ) die();
1157
+ check_ajax_referer( 'wfu-uploadedfiles-page', 'token' );
1158
+ if ( !current_user_can( 'manage_options' ) ) die();
1159
+ if ( WFU_VAR("WFU_UPLOADEDFILES_TABLE_MAXROWS") <= 0 ) die();
1160
+
1161
+ $_POST = stripslashes_deep($_POST);
1162
+
1163
+ $page = wfu_sanitize_int($_POST['page']);
1164
+ $rows = wfu_uploadedfiles_manager($page, true);
1165
+
1166
+ /**
1167
+ * Customise Output of Uploaded Files Page Retrieval.
1168
+ *
1169
+ * This filter allows scripts to customise return of this function after
1170
+ * finish of it.
1171
+ *
1172
+ * @since 4.7.0
1173
+ *
1174
+ * @param string $echo_str The return of the function.
1175
+ */
1176
+ die(apply_filters('_wfu_ajax_action_get_uploadedfiles_page', 'wfu_uploadedfiles_page_success:'.wfu_plugin_encode_string($rows)));
1177
+ }
1178
+
1179
+ /**
1180
+ * Get File Browser Page
1181
+ *
1182
+ * This function returns the HTML code of a specific page of File Browser
1183
+ * feature of the plugin in Dashboard.
1184
+ *
1185
+ * @since 4.6.1
1186
+ */
1187
+ function wfu_ajax_action_get_adminbrowser_page() {
1188
+ if ( !isset($_POST['code']) || !isset($_POST['token']) || !isset($_POST['page']) ) die();
1189
+
1190
+ $_POST = stripslashes_deep($_POST);
1191
+
1192
+ check_ajax_referer( 'wfu-adminbrowser-page', 'token' );
1193
+ if ( !current_user_can( 'manage_options' ) ) die();
1194
+ if ( WFU_VAR("WFU_ADMINBROWSER_TABLE_MAXROWS") <= 0 ) die();
1195
+
1196
+ $code = wfu_sanitize_code($_POST['code']);
1197
+ $page = wfu_sanitize_int($_POST['page']);
1198
+ //get list of files
1199
+ $rows = wfu_browse_files($code, $page, true);
1200
+
1201
+ /**
1202
+ * Customise Output of File Browser Page Retrieval.
1203
+ *
1204
+ * This filter allows scripts to customise return of this function after
1205
+ * finish of it.
1206
+ *
1207
+ * @since 4.6.1
1208
+ *
1209
+ * @param string $echo_str The return of the function.
1210
+ */
1211
+ die(apply_filters('_wfu_ajax_action_get_adminbrowser_page', 'wfu_adminbrowser_page_success:'.wfu_plugin_encode_string($rows)));
1212
+ }
1213
+
1214
+ /**
1215
+ * Include a File in Plugin Database
1216
+ *
1217
+ * This function includes a file in the plugin database.
1218
+ *
1219
+ * @since 3.8.2
1220
+ */
1221
+ function wfu_ajax_action_include_file() {
1222
+ $_POST = stripslashes_deep($_POST);
1223
+ $_GET = stripslashes_deep($_GET);
1224
+
1225
+ $file_code = (isset($_POST['file']) ? $_POST['file'] : (isset($_GET['file']) ? $_GET['file'] : ''));
1226
+ $nonce = (isset($_POST['nonce']) ? $_POST['nonce'] : (isset($_GET['nonce']) ? $_GET['nonce'] : ''));
1227
+ if ( $file_code == '' || $nonce == '' ) die();
1228
+
1229
+ if ( !current_user_can( 'manage_options' ) ) die();
1230
+ //security check to avoid CSRF attacks
1231
+ if ( !wp_verify_nonce($nonce, 'wfu_include_file') ) die();
1232
+
1233
+ $plugin_options = wfu_decode_plugin_options(get_option( "wordpress_file_upload_options" ));
1234
+ if ( $plugin_options['includeotherfiles'] != "1" ) die();
1235
+
1236
+ $dec_file = wfu_get_filepath_from_safe($file_code);
1237
+ if ( $dec_file === false ) die();
1238
+
1239
+ $user = wp_get_current_user();
1240
+ $dec_file = wfu_path_rel2abs(wfu_flatten_path($dec_file));
1241
+ $fileid = wfu_log_action('include', $dec_file, $user->ID, '', '', get_current_blog_id(), '', null);
1242
+
1243
+ if ( $fileid !== false ) {
1244
+ /**
1245
+ * Customise Output of File Inclusion Operation.
1246
+ *
1247
+ * This filter allows scripts to customise return of this function after
1248
+ * finish of it.
1249
+ *
1250
+ * @since 3.11.0
1251
+ *
1252
+ * @param string $echo_str The return of the function.
1253
+ */
1254
+ die(apply_filters('_wfu_ajax_action_include_file', "wfu_include_file:success:".$fileid));
1255
+ }
1256
+ /** This filter is documented above. */
1257
+ else die(apply_filters('_wfu_ajax_action_include_file', 'wfu_include_file:fail:'));
1258
+ }
1259
+
1260
+ /**
1261
+ * Update WPFilebase Manager Plugin
1262
+ *
1263
+ * This function instructs WPFilebase Manager plugin to synchronize its list of
1264
+ * files, after a file upload.
1265
+ *
1266
+ * @since 2.4.1
1267
+ */
1268
+ function wfu_ajax_action_notify_wpfilebase() {
1269
+ $_POST = stripslashes_deep($_POST);
1270
+ $_GET = stripslashes_deep($_GET);
1271
+
1272
+ $params_index = (isset($_POST['params_index']) ? $_POST['params_index'] : (isset($_GET['params_index']) ? $_GET['params_index'] : ''));
1273
+ $session_token = (isset($_POST['session_token']) ? $_POST['session_token'] : (isset($_GET['session_token']) ? $_GET['session_token'] : ''));
1274
+ if ( $params_index == '' || $session_token == '' ) die();
1275
+
1276
+ $params_index = sanitize_text_field($params_index);
1277
+ $session_token = sanitize_text_field($session_token);
1278
+
1279
+ $arr = wfu_get_params_fields_from_index($params_index, $session_token);
1280
+ //check referer using server sessions to avoid CSRF attacks
1281
+ if ( WFU_USVAR("wfu_token_".$arr['shortcode_id']) != $session_token ) die();
1282
+
1283
+ //execute WPFilebase plugin sunchronization by calling 'wpfilebase_sync'
1284
+ //action
1285
+ do_action('wpfilebase_sync');
1286
+
1287
+ die();
1288
+ }
1289
+
1290
+ /**
1291
+ * Get List of Users
1292
+ *
1293
+ * This function returns a list of users meeting specific criteria. Only the
1294
+ * first 100 users will be returned, for avoiding performance issues.
1295
+ *
1296
+ * @since 4.5.0
1297
+ */
1298
+ function wfu_ajax_action_pdusers_get_users() {
1299
+ $_POST = stripslashes_deep($_POST);
1300
+ $_GET = stripslashes_deep($_GET);
1301
+
1302
+ $nonce = (isset($_POST['nonce']) ? $_POST['nonce'] : (isset($_GET['nonce']) ? $_GET['nonce'] : ''));
1303
+ $query = (isset($_POST['query']) ? $_POST['query'] : (isset($_GET['query']) ? $_GET['query'] : ''));
1304
+ if ( $nonce == '' || $query == '' ) die();
1305
+
1306
+ if ( !current_user_can( 'manage_options' ) ) die();
1307
+ //security check to avoid CSRF attacks
1308
+ if ( !wp_verify_nonce($nonce, 'wfu_edit_policy') ) die();
1309
+
1310
+ $query = sanitize_text_field($query);
1311
+ $args = array(
1312
+ 'search' => $query,
1313
+ 'search_columns' => array( 'user_login', 'display_name' ),
1314
+ 'fields' => array( 'user_login', 'display_name' ),
1315
+ 'number' => 100
1316
+ );
1317
+ /** This filter is documented in lib/wfu_admin_browser.php */
1318
+ $args = apply_filters("_wfu_get_users", $args, "manage_pdusers");
1319
+ $users = get_users($args);
1320
+
1321
+ die("pdusers_get_users:".wfu_encode_array_to_string($users));
1322
+ }
1323
+
1324
+ ?>
lib/wfu_attributes.php CHANGED
@@ -1,1855 +1,1855 @@
1
- <?php
2
-
3
- /**
4
- * Definition of Various Attributes of the Plugin
5
- *
6
- * This file contains definition of shortcode and formfield attributes of the
7
- * plugin.
8
- *
9
- * @link /lib/wfu_attributes.php
10
- *
11
- * @package WordPress File Upload Plugin
12
- * @subpackage Core Components
13
- * @since 2.1.2
14
- */
15
-
16
- /**
17
- * Definition of Uploader Form Elements
18
- *
19
- * This function defines the elements of the plugin upload form.
20
- *
21
- * @since 2.1.2
22
- *
23
- * @return array The list of uploader form elements (components).
24
- */
25
- function wfu_component_definitions() {
26
- $components = array(
27
- array(
28
- "id" => "title",
29
- "name" => "Title",
30
- "mode" => "free",
31
- "dimensions" => array("plugin/Plugin", "title/Title"),
32
- "multiplacements" => false,
33
- "help" => "A title text for the plugin"
34
- ),
35
- array(
36
- "id" => "filename",
37
- "name" => "Filename",
38
- "mode" => "free",
39
- "dimensions" => null,
40
- "multiplacements" => false,
41
- "help" => "It shows the name of the selected file (useful only for single file uploads)."
42
- ),
43
- array(
44
- "id" => "selectbutton",
45
- "name" => "Select Button",
46
- "mode" => "free",
47
- "dimensions" => null,
48
- "multiplacements" => false,
49
- "help" => "Represents the button to select the files for upload."
50
- ),
51
- array(
52
- "id" => "uploadbutton",
53
- "name" => "Upload Button",
54
- "mode" => "free",
55
- "dimensions" => null,
56
- "multiplacements" => false,
57
- "help" => "Represents the button to execute the upload after some files have been selected."
58
- ),
59
- array(
60
- "id" => "subfolders",
61
- "name" => "Subfolders",
62
- "mode" => "free",
63
- "dimensions" => array("uploadfolder_label/Upload Folder Label", "subfolders/Subfolders", "subfolders_label/Subfolders Label", "subfolders_select/Subfolders List"),
64
- "multiplacements" => false,
65
- "help" => "Allows the user to select the upload folder from a dropdown list."
66
- ),
67
- array(
68
- "id" => "webcam",
69
- "name" => "Webcam",
70
- "mode" => "commercial",
71
- "dimensions" => array("webcam/Webcam Box"),
72
- "multiplacements" => false,
73
- "help" => "Displays video from the device's webcam. The user can capture and upload screenshots or video streams."
74
- ),
75
- array(
76
- "id" => "progressbar",
77
- "name" => "Progressbar",
78
- "mode" => "free",
79
- "dimensions" => null,
80
- "multiplacements" => false,
81
- "help" => "Displays a simple progress bar, showing total progress of upload."
82
- ),
83
- array(
84
- "id" => "userdata",
85
- "name" => "User Fields",
86
- "mode" => "free",
87
- "dimensions" => array("userdata/User Fields", "userdata_label/User Fields Label", "userdata_value/User Fields Value"),
88
- "multiplacements" => true,
89
- "help" => "Displays additional fields that the user must fill-in together with the uploaded files."
90
- ),
91
- array(
92
- "id" => "consent",
93
- "name" => "Consent",
94
- "mode" => "free",
95
- "dimensions" => array("consent/Consent Block"),
96
- "multiplacements" => false,
97
- "help" => "Displays a checkbox asking user's consent for storing personal data."
98
- ),
99
- array(
100
- "id" => "message",
101
- "name" => "Message",
102
- "mode" => "free",
103
- "dimensions" => null,
104
- "multiplacements" => false,
105
- "help" => "Displays a message block with information about the upload, together with any warnings or errors."
106
- )
107
- );
108
-
109
- wfu_array_remove_nulls($components);
110
-
111
- return $components;
112
- }
113
-
114
- /**
115
- * Definition of Uploader Form Attribute Categories
116
- *
117
- * This function defines the categories of the plugin uploader shortcode
118
- * attributes. These categories show up as different tabs of the shortcode
119
- * composer.
120
- *
121
- * @since 2.1.2
122
- *
123
- * @return array The list of uploader form attribute categories.
124
- */
125
- function wfu_category_definitions() {
126
- $cats = array(
127
- "general" => "General",
128
- "placements" => "Placements",
129
- "labels" => "Labels",
130
- "notifications" => "Notifications",
131
- "personaldata" => "Personal Data",
132
- "colors" => "Colors",
133
- "dimensions" => "Dimensions",
134
- "userdata" => "Additional Fields",
135
- "interoperability" => "Interoperability",
136
- "webcam" => "Webcam"
137
- );
138
-
139
- return $cats;
140
- }
141
-
142
- /**
143
- * Definition of Uploader Form Custom Fields
144
- *
145
- * This function defines the plugin upload form custom fields and their
146
- * attributes.
147
- *
148
- * @since 3.3.0
149
- *
150
- * @return array The list of upload form custom fields.
151
- */
152
- function wfu_formfield_definitions() {
153
- //field properties have 2 parts separated by "/"; the first part determines if the property will be shown to the user (show or hide); the second part determines default value)
154
- //when making changes in the structure of formfield definitions, the following are affected:
155
- // - wfu_admin_composer.php function wfu_shortcode_composer
156
- // variable $fieldprops_basic
157
- // variable $fieldprops_default
158
- // variable $template
159
- // variable wfu_attribute_..._typeprops
160
- // variable $from_template
161
- // - wfu_functions.php function wfu_parse_userdata_attribute
162
- // variable $default
163
- // variable $fieldprops
164
- // - wfu_blocks.php function wfu_userdata_apply_template
165
- // return variable
166
- // - wordpress_file_upload_adminfuctions.js function wfu_formdata_type_changed
167
- // variable field
168
- // - wordpress_file_upload_adminfuctions.js function wfu_formdata_add_field
169
- // variable field
170
- // - wordpress_file_upload_adminfuctions.js function wfu_formdata_prepare_template
171
- // variable fieldprops_basic
172
- // variable template
173
- // - wordpress_file_upload_adminfuctions.js function wfu_update_formfield_value
174
- // variable part
175
- // - wordpress_file_upload_adminfuctions.js function wfu_apply_value
176
- // variable def
177
- // variable fieldprops
178
- $formfields = array(
179
- array(
180
- "type" => "text",
181
- "type_description" => "Simple Text",
182
- //label properties
183
- "label" => "",
184
- "label_label" => "Label",
185
- "label_hint" => "enter the label that will be shown next to the field",
186
- //checkbox properties
187
- "required" => "show/false",
188
- "required_hint" => "if checked, then this field must have a non-empty value for the file to be uploaded",
189
- "donotautocomplete" => "show/false",
190
- "donotautocomplete_hint" => "if checked, then the field will notify the browsers not to fill it with autocomplete data when the plugin is reloaded",
191
- "validate" => "hide/false",
192
- "validate_hint" => "if checked, then the field value entered by the user will be validated before file upload",
193
- "typehook" => "hide/false",
194
- "typehook_hint" => "if checked, then text suggestions will be shown below the field as the user types more text inside",
195
- //dropdown properties
196
- "labelposition" => "show/left",
197
- "labelposition_hint" => "select the position of the field&#39;s label; the position is relative to the field",
198
- "hintposition" => "show/right",
199
- "hintposition_hint" => "select the position of the hint that will be shown to notify the user that something is wrong\\r\\nthe position is relative to the field",
200
- //text properties
201
- "default" => "show/",
202
- "default_hint" => "enter a default value for the field or leave it empty if you do not want a default value",
203
- "data" => "hide/",
204
- "data_label" => "Data",
205
- "data_hint" => "complete a list of values to be shown to the user",
206
- "group" => "hide/",
207
- "group_hint" => "if a value is set, then all fields having the same value will belong to the same group",
208
- "format" => "hide/",
209
- "format_hint" => "enter a format to format user selection"
210
- ),
211
- array(
212
- "type" => "multitext",
213
- "type_description" => "Multiple Lines Text",
214
- //label properties
215
- "label" => "",
216
- "label_label" => "Label",
217
- "label_hint" => "enter the label that will be shown next to the field",
218
- //checkbox properties
219
- "required" => "show/false",
220
- "required_hint" => "if checked, then this field must have a non-empty value for the file to be uploaded",
221
- "donotautocomplete" => "hide/true",
222
- "donotautocomplete_hint" => "if checked, then the field will notify the browsers not to fill it with autocomplete data when the plugin is reloaded",
223
- "validate" => "hide/false",
224
- "validate_hint" => "if checked, then the field value entered by the user will be validated before file upload",
225
- "typehook" => "hide/false",
226
- "typehook_hint" => "if checked, then text suggestions will be shown below the field as the user types more text inside",
227
- //dropdown properties
228
- "labelposition" => "show/left",
229
- "labelposition_hint" => "select the position of the field&#39;s label; the position is relative to the field",
230
- "hintposition" => "show/right",
231
- "hintposition_hint" => "select the position of the hint that will be shown to notify the user that something is wrong\\r\\nthe position is relative to the field",
232
- //text properties
233
- "default" => "hide/",
234
- "default_hint" => "enter a default value for the field or leave it empty if you do not want a default value",
235
- "data" => "hide/",
236
- "data_label" => "Data",
237
- "data_hint" => "complete a list of values to be shown to the user",
238
- "group" => "hide/",
239
- "group_hint" => "if a value is set, then all fields having the same value will belong to the same group",
240
- "format" => "hide/",
241
- "format_hint" => "enter a format to format user selection"
242
- ),
243
- array(
244
- "type" => "number",
245
- "type_description" => "Number",
246
- //label properties
247
- "label" => "",
248
- "label_label" => "Label",
249
- "label_hint" => "enter the label that will be shown next to the field",
250
- //checkbox properties
251
- "required" => "show/false",
252
- "required_hint" => "if checked, then this field must have a non-empty value for the file to be uploaded",
253
- "donotautocomplete" => "show/true",
254
- "donotautocomplete_hint" => "if checked, then the field will notify the browsers not to fill it with autocomplete data when the plugin is reloaded",
255
- "validate" => "show/true",
256
- "validate_hint" => "if checked, then the number entered by the user will be checked if it is a valid number, based on the format defined, before file upload",
257
- "typehook" => "show/false",
258
- "typehook_hint" => "if checked, then only valid characters will be allowed during typing",
259
- //dropdown properties
260
- "labelposition" => "show/left",
261
- "labelposition_hint" => "select the position of the field&#39;s label; the position is relative to the field",
262
- "hintposition" => "show/right",
263
- "hintposition_hint" => "select the position of the hint that will be shown to notify the user that something is wrong\\r\\nthe position is relative to the field",
264
- //text properties
265
- "default" => "show/",
266
- "default_hint" => "enter a default value for the field or leave it empty if you do not want a default value",
267
- "data" => "hide/",
268
- "data_label" => "Data",
269
- "data_hint" => "complete a list of values to be shown to the user",
270
- "group" => "hide/",
271
- "group_hint" => "if a non-empty group value is set, then another email confirmation field belonging to the same group must have the same email value",
272
- "format" => "show/d",
273
- "format_hint" => "enter a format for the number:\\r\\n d for integers\\r\\n f for floating point numbers\\r\\nthe dot (.) symbol is used as a decimal separator"
274
- ),
275
- array(
276
- "type" => "email",
277
- "type_description" => "Email",
278
- //label properties
279
- "label" => "",
280
- "label_label" => "Label",
281
- "label_hint" => "enter the label that will be shown next to the field",
282
- //checkbox properties
283
- "required" => "show/false",
284
- "required_hint" => "if checked, then this field must have a non-empty value for the file to be uploaded",
285
- "donotautocomplete" => "show/true",
286
- "donotautocomplete_hint" => "if checked, then the field will notify the browsers not to fill it with autocomplete data when the plugin is reloaded",
287
- "validate" => "show/true",
288
- "validate_hint" => "if checked, then the email entered by the user will be checked if it is valid before file upload",
289
- "typehook" => "hide/false",
290
- "typehook_hint" => "if checked, then text suggestions will be shown below the field as the user types more text inside",
291
- //dropdown properties
292
- "labelposition" => "show/left",
293
- "labelposition_hint" => "select the position of the field&#39;s label; the position is relative to the field",
294
- "hintposition" => "show/right",
295
- "hintposition_hint" => "select the position of the hint that will be shown to notify the user that something is wrong\\r\\nthe position is relative to the field",
296
- //text properties
297
- "default" => "show/",
298
- "default_hint" => "enter a default value for the field or leave it empty if you do not want a default value",
299
- "data" => "hide/",
300
- "data_label" => "Data",
301
- "data_hint" => "complete a list of values to be shown to the user",
302
- "group" => "show/0",
303
- "group_hint" => "if a non-empty group value is set, then another email confirmation field belonging to the same group must have the same email value",
304
- "format" => "hide/",
305
- "format_hint" => "enter a format to format user selection"
306
- ),
307
- array(
308
- "type" => "confirmemail",
309
- "type_description" => "Confirmation Email",
310
- //label properties
311
- "label" => "",
312
- "label_label" => "Label",
313
- "label_hint" => "enter the label that will be shown next to the field",
314
- //checkbox properties
315
- "required" => "show/true",
316
- "required_hint" => "if checked, then this field must have a non-empty value for the file to be uploaded",
317
- "donotautocomplete" => "show/true",
318
- "donotautocomplete_hint" => "if checked, then the field will notify the browsers not to fill it with autocomplete data when the plugin is reloaded",
319
- "validate" => "hide/true",
320
- "validate_hint" => "if checked, then the confirmation email entered by the user will be checked if it is the same with the email belonging to the same group",
321
- "typehook" => "hide/false",
322
- "typehook_hint" => "if checked, then text suggestions will be shown below the field as the user types more text inside",
323
- //dropdown properties
324
- "labelposition" => "show/left",
325
- "labelposition_hint" => "select the position of the field&#39;s label; the position is relative to the field",
326
- "hintposition" => "show/right",
327
- "hintposition_hint" => "select the position of the hint that will be shown to notify the user that something is wrong\\r\\nthe position is relative to the field",
328
- //text properties
329
- "default" => "hide/",
330
- "default_hint" => "enter a default value for the field or leave it empty if you do not want a default value",
331
- "data" => "hide/",
332
- "data_label" => "Data",
333
- "data_hint" => "complete a list of values to be shown to the user",
334
- "group" => "show/0",
335
- "group_hint" => "enter a non-empty value to match this email confirmation field with another email field",
336
- "format" => "hide/",
337
- "format_hint" => "enter a format to format user selection"
338
- ),
339
- array(
340
- "type" => "password",
341
- "type_description" => "Password",
342
- //label properties
343
- "label" => "",
344
- "label_label" => "Label",
345
- "label_hint" => "enter the label that will be shown next to the field",
346
- //checkbox properties
347
- "required" => "show/true",
348
- "required_hint" => "if checked, then this field must have a non-empty value for the file to be uploaded",
349
- "donotautocomplete" => "false/true",
350
- "donotautocomplete_hint" => "if checked, then the field will notify the browsers not to fill it with autocomplete data when the plugin is reloaded",
351
- "validate" => "hide/false",
352
- "validate_hint" => "if checked, then the value entered by the user will be validated",
353
- "typehook" => "hide/false",
354
- "typehook_hint" => "if checked, then text suggestions will be shown below the field as the user types more text inside",
355
- //dropdown properties
356
- "labelposition" => "show/left",
357
- "labelposition_hint" => "select the position of the field&#39;s label; the position is relative to the field",
358
- "hintposition" => "show/right",
359
- "hintposition_hint" => "select the position of the hint that will be shown to notify the user that something is wrong\\r\\nthe position is relative to the field",
360
- //text properties
361
- "default" => "hide/",
362
- "default_hint" => "enter a default value for the field or leave it empty if you do not want a default value",
363
- "data" => "hide/",
364
- "data_label" => "Data",
365
- "data_hint" => "complete a list of values to be shown to the user",
366
- "group" => "show/0",
367
- "group_hint" => "if a non-empty group value is set, then another password confirmation field belonging to the same group must have the same password",
368
- "format" => "hide/",
369
- "format_hint" => "enter a format to format user selection"
370
- ),
371
- array(
372
- "type" => "confirmpassword",
373
- "type_description" => "Confirmation Password",
374
- //label properties
375
- "label" => "",
376
- "label_label" => "Label",
377
- "label_hint" => "enter the label that will be shown next to the field",
378
- //checkbox properties
379
- "required" => "show/true",
380
- "required_hint" => "if checked, then this field must have a non-empty value for the file to be uploaded",
381
- "donotautocomplete" => "false/true",
382
- "donotautocomplete_hint" => "if checked, then the field will notify the browsers not to fill it with autocomplete data when the plugin is reloaded",
383
- "validate" => "hide/true",
384
- "validate_hint" => "if checked, then the value entered by the user will be validated",
385
- "typehook" => "hide/false",
386
- "typehook_hint" => "if checked, then text suggestions will be shown below the field as the user types more text inside",
387
- //dropdown properties
388
- "labelposition" => "show/left",
389
- "labelposition_hint" => "select the position of the field&#39;s label; the position is relative to the field",
390
- "hintposition" => "show/right",
391
- "hintposition_hint" => "select the position of the hint that will be shown to notify the user that something is wrong\\r\\nthe position is relative to the field",
392
- //text properties
393
- "default" => "hide/",
394
- "default_hint" => "enter a default value for the field or leave it empty if you do not want a default value",
395
- "data" => "hide/",
396
- "data_label" => "Data",
397
- "data_hint" => "complete a list of values to be shown to the user",
398
- "group" => "show/0",
399
- "group_hint" => "if a non-empty group value is set, then another password confirmation field belonging to the same group must have the same password",
400
- "format" => "hide/",
401
- "format_hint" => "enter a format to format user selection"
402
- ),
403
- array(
404
- "type" => "checkbox",
405
- "type_description" => "Checkbox",
406
- //label properties
407
- "label" => "",
408
- "label_label" => "Label",
409
- "label_hint" => "enter the label that will be shown next to the field",
410
- //checkbox properties
411
- "required" => "show/false",
412
- "required_hint" => "if checked, then this checkbox field must be checked before file upload",
413
- "donotautocomplete" => "show/true",
414
- "donotautocomplete_hint" => "if checked, then the field will not be autocompleted by browsers",
415
- "validate" => "hide/false",
416
- "validate_hint" => "if checked, then the field value entered by the user will be validated before file upload",
417
- "typehook" => "hide/false",
418
- "typehook_hint" => "if checked, then text suggestions will be shown below the field as the user types more text inside",
419
- //dropdown properties
420
- "labelposition" => "show/none",
421
- "labelposition_hint" => "select the position of the field&#39;s label; the position is relative to the field",
422
- "hintposition" => "show/right",
423
- "hintposition_hint" => "select the position of the hint that will be shown to notify the user that something is wrong\\r\\nthe position is relative to the field",
424
- //text properties
425
- "default" => "show/false",
426
- "default_hint" => "enter a default value (true or false) for the field or leave it empty if you do not want a default value",
427
- "data" => "show/",
428
- "data_label" => "Description",
429
- "data_hint" => "enter a description for the checkbox",
430
- "group" => "hide/",
431
- "group_hint" => "if a value is set, then all fields having the same value will belong to the same group",
432
- "format" => "show/right",
433
- "format_hint" => "define the location of the description in relation to the check box\\r\\npossible values are: top, right, bottom, left"
434
- ),
435
- array(
436
- "type" => "radiobutton",
437
- "type_description" => "Radio button",
438
- //label properties
439
- "label" => "",
440
- "label_label" => "Label",
441
- "label_hint" => "enter the label that will be shown next to the field",
442
- //checkbox properties
443
- "required" => "show/false",
444
- "required_hint" => "if checked, then a radio button must be selected before file upload",
445
- "donotautocomplete" => "show/true",
446
- "donotautocomplete_hint" => "if checked, then the field will not be autocompleted by browsers",
447
- "validate" => "hide/false",
448
- "validate_hint" => "if checked, then the field value entered by the user will be validated before file upload",
449
- "typehook" => "hide/false",
450
- "typehook_hint" => "if checked, then text suggestions will be shown below the field as the user types more text inside",
451
- //dropdown properties
452
- "labelposition" => "show/left",
453
- "labelposition_hint" => "select the position of the field&#39;s label; the position is relative to the field",
454
- "hintposition" => "show/right",
455
- "hintposition_hint" => "select the position of the hint that will be shown to notify the user that something is wrong\\r\\nthe position is relative to the field",
456
- //text properties
457
- "default" => "show/",
458
- "default_hint" => "enter a default value for the field or leave it empty if you do not want a default value",
459
- "data" => "show/",
460
- "data_label" => "Items",
461
- "data_hint" => "enter a comma delimited list of radio button items",
462
- "group" => "show/0",
463
- "group_hint" => "all radio buttons having the same group id belong to the same group",
464
- "format" => "show/",
465
- "format_hint" => "define the location of the radio labels in relation to their radio buttons (top, right, bottom, left)\\r\\nand the placement of the radio buttons (horizontal, vertical)"
466
- ),
467
- array(
468
- "type" => "date",
469
- "type_description" => "Date",
470
- //label properties
471
- "label" => "",
472
- "label_label" => "Label",
473
- "label_hint" => "enter the label that will be shown next to the field",
474
- //checkbox properties
475
- "required" => "show/false",
476
- "required_hint" => "if checked, then a date must be entered before file upload",
477
- "donotautocomplete" => "show/true",
478
- "donotautocomplete_hint" => "if checked, then the field will not be autocompleted by browsers",
479
- "validate" => "hide/false",
480
- "validate_hint" => "if checked, then the field value entered by the user will be validated before file upload",
481
- "typehook" => "hide/false",
482
- "typehook_hint" => "if checked, then text suggestions will be shown below the field as the user types more text inside",
483
- //dropdown properties
484
- "labelposition" => "show/left",
485
- "labelposition_hint" => "select the position of the field&#39;s label; the position is relative to the field",
486
- "hintpos