Download Monitor - Version 4.7.52

Version Description

  • 23.11.2022 = Fix: Security fix
Download this release

Release Info

Developer raldea89
Plugin Icon 128x128 Download Monitor
Version 4.7.52
Comparing to
See all releases

Code changes from version 4.7.51 to 4.7.52

assets/js/reports/reports.js CHANGED
@@ -111,10 +111,7 @@ class DLM_Reports {
111
  dlmReportsInstance.setSpinner(jQuery('#users_download_log'));
112
  dlmReportsInstance.setSpinner(jQuery('#total_downloads_table_wrapper2'));
113
  // Let's see if these are pretty permalinks or plain
114
- let fetchingLink = dlmDownloadReportsAPI + '?offset=' + offset + '&limit=' + limit;
115
- if (dlmDownloadReportsAPI.indexOf('index.php?') > 0) {
116
- fetchingLink = dlmDownloadReportsAPI + '&offset=' + offset + '&limit=' + limit;
117
- }
118
  // Fetch our data
119
  const fetchedDownloadsData = await fetch(fetchingLink);
120
 
@@ -182,10 +179,7 @@ class DLM_Reports {
182
  const wrapper = jQuery('div[data-id="user_reports"]');
183
 
184
  // Let's see if these are pretty permalinks or plain
185
- let fetchingLink = dlmUserReportsAPI + '?offset=' + offset + '&limit=' + limit;
186
- if (dlmUserReportsAPI.indexOf('index.php?') > 0) {
187
- fetchingLink = dlmUserReportsAPI + '&offset=' + offset + '&limit=' + limit;
188
- }
189
 
190
  const fetchedUserData = await fetch(fetchingLink);
191
 
@@ -1774,7 +1768,7 @@ class DLM_Reports {
1774
  valid_user : ('0' !== dataResponse[i].user_id),
1775
  edit_link : ( '0' !== dataResponse[i].user_id) ? 'user-edit.php?user_id=' + dataResponse[i].user_id : '#',
1776
  edit_download_link: ('undefined' !== typeof download && null !== download) ? dlmAdminUrl + 'post.php?post=' + download.id + '&action=edit' : '#',
1777
- status : dataResponse[i].download_status,
1778
  download_date : dataResponse[i].display_date,
1779
  }
1780
 
111
  dlmReportsInstance.setSpinner(jQuery('#users_download_log'));
112
  dlmReportsInstance.setSpinner(jQuery('#total_downloads_table_wrapper2'));
113
  // Let's see if these are pretty permalinks or plain
114
+ let fetchingLink = dlmDownloadReportsAPI + '&offset=' + offset + '&limit=' + limit;
 
 
 
115
  // Fetch our data
116
  const fetchedDownloadsData = await fetch(fetchingLink);
117
 
179
  const wrapper = jQuery('div[data-id="user_reports"]');
180
 
181
  // Let's see if these are pretty permalinks or plain
182
+ let fetchingLink = dlmUserReportsAPI + '&offset=' + offset + '&limit=' + limit;
 
 
 
183
 
184
  const fetchedUserData = await fetch(fetchingLink);
185
 
1768
  valid_user : ('0' !== dataResponse[i].user_id),
1769
  edit_link : ( '0' !== dataResponse[i].user_id) ? 'user-edit.php?user_id=' + dataResponse[i].user_id : '#',
1770
  edit_download_link: ('undefined' !== typeof download && null !== download) ? dlmAdminUrl + 'post.php?post=' + download.id + '&action=edit' : '#',
1771
+ status : ( 'redirect' === dataResponse[i].download_status ) ? 'redirected' : dataResponse[i].download_status,
1772
  download_date : dataResponse[i].display_date,
1773
  }
1774
 
assets/js/reports/reports.min.js CHANGED
@@ -1 +1 @@
1
- jQuery(function(e){new DLM_Reports;dlmReportsInstance.fetchDownloadsCPT()});class DLM_Reports{dlmReportsStats=[];dlmUsersStats={logs:[],users:[]};currentFilters=[];tempDownloads=null;templates={};totalDownloads=0;perPage=dlmReportsPerPage;downloads=[];constructor(){(dlmReportsInstance=this).chartContainer=document.getElementById("total_downloads_chart");const e=dlmReportsInstance.chartContainer.getContext("2d");dlmReportsInstance.chartColors={purple:{default:"rgba(149, 76, 233, 1)",threesome:"rgba(149, 76, 233, 0.75)",half:"rgba(149, 76, 233, 0.5)",quarter:"rgba(149, 76, 233, 0.5)",zero:"rgba(149, 76, 233, 0.05)"},blue:{default:"rgba(67, 56, 202, 1)",threesome:"rgba(67, 56, 202, 0.75)",half:"rgba(67, 56, 202, 0.5)",quarter:"rgba(67, 56, 202, 0.25)",zero:"rgba(67, 56, 202, 0.05)"},green:{default:"rgba(00, 255, 00, 1)",threesome:"rgba(00, 255, 00, 0.75)",half:"rgba(00, 255, 00, 0.5)",quarter:"rgba(00, 255, 00, 0.25)",zero:"rgba(67, 56, 202, 0.05)"},royalBlue:{default:"rgba(65, 105, 225, 1)",threesome:"rgba(65, 105, 225, 0.75)",half:"rgba(65, 105, 225, 0.5)",quarter:"rgba(65, 105, 225, 0.25)",zero:"rgba(65, 105, 225, 0.05)"},persianBlue:{default:"rgba(28, 57, 187, 1)",threesome:"rgba(28, 57, 187, 0.75)",half:"rgba(28, 57, 187, 0.5)",quarter:"rgba(28, 57, 187, 0.25)",zero:"rgba(28, 57, 187, 0.05)"},darkCyan:{default:"rgba(0,129,167, 1)",threesome:"rgba(0,129,167, 0.75)",half:"rgba(0,129,167, 0.5)",quarter:"rgba(0,129,167, 0.25)",zero:"rgba(0,129,167, 0.05)"},strongCyan:{default:"rgba(0, 175, 185, 1)",threesome:"rgba(0, 175, 185, 0.75)",half:"rgba(0, 175, 185, 0.5)",quarter:"rgba(0, 175, 185, 0.25)",zero:"rgba(0, 175, 185, 0.05)"}},dlmReportsInstance.chartGradient=e.createLinearGradient(0,25,0,300),dlmReportsInstance.chartGradient.addColorStop(0,dlmReportsInstance.chartColors.darkCyan.half),dlmReportsInstance.chartGradient.addColorStop(.45,dlmReportsInstance.chartColors.darkCyan.quarter),dlmReportsInstance.chartGradient.addColorStop(1,dlmReportsInstance.chartColors.darkCyan.zero),dlmReportsInstance.datePickerContainer=document.getElementById("dlm-date-range-picker"),dlmReportsInstance.dataSets=[];let t=new Date;dlmReportsInstance.dates={downloads:{start_date:new Date(t.setMonth(t.getMonth()-1)),end_date:new Date}},dlmReportsInstance.chartDataObject={}}async fetchReportsData(e=0,t=1e3){const a=jQuery('div[data-id="general_info"]');dlmReportsInstance.setSpinner(jQuery(".total_downloads_chart-wrapper")),dlmReportsInstance.setSpinner(jQuery("#users_download_log")),dlmReportsInstance.setSpinner(jQuery("#total_downloads_table_wrapper2"));let n=dlmDownloadReportsAPI+"?offset="+e+"&limit="+t;0<dlmDownloadReportsAPI.indexOf("index.php?")&&(n=dlmDownloadReportsAPI+"&offset="+e+"&limit="+t);const o=await fetch(n);if(!o.ok){const s=document.createElement("div"),r=(s.className="dlm-loading-data",document.createTextNode("Seems like we bumped into an error! ")),d=document.createTextNode("Data fetching returned a status text of : "+fetchedData.statusText),l=document.createElement("h1"),m=document.createElement("h3");throw l.appendChild(r),m.appendChild(d),s.appendChild(l),s.appendChild(m),a.find(".dlm-loading-data").remove(),a.append(s),new Error("Something went wrong! Reports response did not come OK - "+fetchedData.statusText)}dlmReportsInstance.mostDownloaded=!1,dlmReportsInstance.stats=!1,dlmReportsInstance.chartType="day";e=await o.json();dlmReportsInstance.dlmReportsStats=dlmReportsInstance.dlmReportsStats.concat(e.stats),!0===e.done?(0<window.location.href.indexOf("dlm_time")&&(dlmReportsInstance.dates.downloads.start_date=0<Object.keys(dlmReportsInstance.dlmReportsStats).length?new Date(dlmReportsInstance.dlmReportsStats[0].date):new Date,dlmReportsInstance.dates.downloads.end_date=new Date,jQuery("#dlm-date-range-picker .date-range-info").html(dlmReportsInstance.dates.downloads.start_date.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"2-digit"})+" - "+dlmReportsInstance.dates.downloads.end_date.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"2-digit"}))),dlmReportsInstance.createDataOnDate(dlmReportsInstance.dates.downloads.start_date,dlmReportsInstance.dates.downloads.end_date),dlmReportsInstance.datePicker={opened:!1},jQuery(document).trigger("dlm_downloads_report_fetched",[dlmReportsInstance,dlmReportsInstance.dlmReportsStats]),dlmReportsInstance.stopSpinner(jQuery(".total_downloads_chart-wrapper")),dlmReportsInstance.init()):dlmReportsInstance.fetchReportsData(e.offset)}async fetchUsersReportsData(e=0,t=dlmPHPinfo.retrieved_rows){const a=jQuery('div[data-id="user_reports"]');let n=dlmUserReportsAPI+"?offset="+e+"&limit="+t;0<dlmUserReportsAPI.indexOf("index.php?")&&(n=dlmUserReportsAPI+"&offset="+e+"&limit="+t);const o=await fetch(n);if(!o.ok)throw new Error("Something went wrong! Reports response did not come OK - "+o.statusText);e=await o.json();dlmReportsInstance.dlmUsersStats.logs=dlmReportsInstance.dlmUsersStats.logs.concat(e.logs),!0===e.done?(dlmReportsInstance.userDownloads=void 0!==dlmReportsInstance.dlmUsersStats.logs?JSON.parse(JSON.stringify(dlmReportsInstance.dlmUsersStats.logs)):{},a.find(".dlm-loading-data").remove(),dlmReportsInstance.userReportsTab(),dlmReportsInstance.setTopDownloads(),dlmReportsInstance.stopSpinner(jQuery("#total_downloads_table_wrapper2"))):dlmReportsInstance.fetchUsersReportsData(e.offset)}async fetchUserData(){const e=await fetch(dlmUserDataAPI);if(!e.ok)throw new Error("Something went wrong! Reports response did not come OK - "+e.statusText);var t=await e.json();dlmReportsInstance.dlmUsersStats.users=dlmReportsInstance.dlmUsersStats.users.concat(t),dlmReportsInstance.fetchReportsData()}init(){dlmReportsInstance.tabNagivation(),dlmReportsInstance.overViewTab(),dlmReportsInstance.togglePageSettings(),dlmReportsInstance.setSpinner(jQuery("#users_download_log")),dlmReportsInstance.setSpinner(jQuery("#total_downloads_table_wrapper2")),dlmReportsInstance.fetchUsersReportsData(),jQuery(document).trigger("dlm_reports_init",[dlmReportsInstance]),dlmReportsInstance.eventsFunctions()}overViewTab(){dlmReportsInstance.dlmCreateChart(dlmReportsInstance.stats.chartStats,dlmReportsInstance.chartContainer),dlmReportsInstance.dlmDownloadsSummary(),dlmReportsInstance.datePickerContainer.addEventListener("click",dlmReportsInstance.toggleDatepicker.bind(this)),dlmReportsInstance.setTodayDownloads(),dlmReportsInstance.handleTopDownloads(),jQuery(document).on("click","body",function(e){e.stopPropagation(),0<jQuery(dlmReportsInstance.datePickerContainer).find("#dlm_date_range_picker").length&&dlmReportsInstance.hideDatepicker(jQuery(dlmReportsInstance.datePickerContainer),{target:"dlm-date-range-picker"})})}userReportsTab(){0!==Object.values(dlmReportsInstance.dlmUsersStats).length&&(dlmReportsInstance.logsDataByDate(dlmReportsInstance.dates.downloads.start_date,dlmReportsInstance.dates.downloads.end_date),dlmReportsInstance.handleUserDownloads(),dlmReportsInstance.filterDownloads())}getDates(e,t){const a={};let n=e;for(;n.getTime()<t.getTime();)a[this.createDateElement(n)]=0,n=this.getNextDay(n);return a[this.createDateElement(n)]=0,n=this.getNextDay(n),a}getMonths(e){const t={};return Object.keys(e).map(e=>{e=e.substring(0,7);void 0===t[e]&&(t[e]=0)}),t}getDoubleMonths(e){const t={},a=Object.keys(e)[0],n=Object.keys(e)[Object.keys(e).length-1];let o=0,s=a.substring(0,7),r=n.substring(0,7);return Object.keys(e).map(e=>{e=e.substring(0,7);s!==e&&r!==e&&(s=e,o++),void 0===t[e]&&0==o%2&&(t[e]=0)}),t}getWeeks(e){let a={};return Object.keys(e).forEach(e=>{let t;t=15<moment(e).date()?e.substring(0,7)+"-15":e.substring(0,7)+"-01",void 0===a[t]&&(a[t]=0)}),a}getWeek(e){let t={},a=Object.keys(e)[Object.keys(e).length-1],n=0;return Object.keys(e).map(e=>{void 0===t[e]&&0==n%7&&(t[e]=0),n++}),void 0===t[a]&&(t[a]=0),t}getDoubleDays(e){let t={},a=Object.keys(e)[0],n=Object.keys(e)[Object.keys(e).length-1],o=0;return Object.keys(e).map(e=>{a!==e&&n!==e&&(a=e,o++),void 0===t[e]&&0==o%2&&(t[e]=0)}),t}getNextDay(e){const t=new Date(e);return t.setDate(e.getDate()+1),t}createDateElement(e){var t=(e.getMonth()+1<10?"0":"")+(e.getMonth()+1);return e.getFullYear()+"-"+t+"-"+("0"+e.getDate()).slice(-2)}getSetDates(e,t){let a,n;if(void 0!==e&&e)a=dlmReportsInstance.createDateElement(new Date(e));else{const o=new Date;o.setDate(o.getDate()-30),a=dlmReportsInstance.createDateElement(o)}if(void 0!==t&&t){e=new Date(t);n=dlmReportsInstance.createDateElement(e)}else{const s=new Date;s.setDate(s.getDate()+1),n=dlmReportsInstance.createDateElement(s)}return{startDate:a,endDate:n}}createDataOnDate(e,t){let{startDate:a,endDate:n}={...dlmReportsInstance.getSetDates(e,t)},o,s,r,d,l,m=(dlmReportsInstance.reportsData=void 0!==dlmReportsInstance.dlmReportsStats?JSON.parse(JSON.stringify(dlmReportsInstance.dlmReportsStats)):{},s=moment(n,"YYYY-MM-DD").month()-moment(a,"YYYY-MM-DD").month(),r=moment(n,"YYYY-MM-DD").year()-moment(a,"YYYY-MM-DD").year(),o=moment(n).date()-moment(a).date(),dlmReportsInstance.chartType="day",0==r&&-6<s&&s<6?1<s||s<-1?dlmReportsInstance.chartType=2==s?"week":"weeks":1==s&&(8<o||-14<o||0==o)&&(dlmReportsInstance.chartType="days"):s<=0?dlmReportsInstance.chartType="month":dlmReportsInstance.chartType="months",dlmReportsInstance.getDates(new Date(a),new Date(n))),c,p,i,g;switch(dlmReportsInstance.chartType){case"months":p=dlmReportsInstance.getDoubleMonths(m),l=p;break;case"month":var u=dlmReportsInstance.getMonths(m);l=u;break;case"weeks":i=dlmReportsInstance.getWeeks(m),l=i;break;case"week":g=dlmReportsInstance.getWeek(m),l=g;break;case"days":c=dlmReportsInstance.getDoubleDays(m),l=c;break;case"day":l=m}Object.values(dlmReportsInstance.reportsData).forEach((o,e)=>{var s=JSON.parse(o.download_ids);if(void 0!==m[o.date])switch(dlmReportsInstance.chartType){case"months":d=o.date.substring(0,7);let e=parseInt(o.date.substring(5,7)),t=o.date.substring(0,5),a=6<(e-1).length?t+(e-1):t+"0"+(e-1);Object.values(s).forEach((e,t)=>{void 0===p[d]?void 0!==p[a]&&(p[a]=p[a]+e.downloads):p[d]=p[d]+e.downloads}),l=p;break;case"month":d=o.date.substring(0,7),Object.values(s).forEach((e,t)=>{monthDownloads[d]=void 0!==monthDownloads[d]?monthDownloads[d]+e.downloads:e.downloads}),l=monthDownloads;break;case"weeks":d=15<moment(o.date).date()?o.date.substring(0,7)+"-15":o.date.substring(0,7)+"-01",Object.values(s).forEach((e,t)=>{i[d]=void 0!==i[d]?i[d]+e.downloads:e.downloads}),l=i;break;case"week":d=o.date,Object.values(s).forEach((t,e)=>{if(void 0===g[d])for(let e=1;e<8;e++){var a=moment(o.date).date(moment(o.date).date()-e).format("YYYY-MM-DD");void 0!==g[a]&&(g[a]=g[a]+t.downloads)}else g[d]=g[d]+t.downloads}),l=g;break;case"days":d=o.date;let n=moment(o.date).date(moment(o.date).date()-1).format("YYYY-MM-DD");Object.values(s).forEach((e,t)=>{void 0===c[d]?void 0!==c[n]&&(c[n]=c[n]+e.downloads):c[d]=c[d]+e.downloads}),l=c;break;case"day":Object.values(s).forEach((e,t)=>{m[o.date]=m[o.date]+e.downloads}),l=m}else delete dlmReportsInstance.reportsData[e]});const I=Object.keys(m);e=I.length,t=I.findIndex(e=>a===e);let R=I.findIndex(e=>n===e);-1===t&&-1===R?dlmReportsInstance.stats={chartStats:Object.assign({},l),summaryStats:!1,daysLength:e}:(-1===R&&(R=e),dlmReportsInstance.stats={chartStats:Object.assign({},l),summaryStats:dlmReportsInstance.reportsData,daysLength:e})}dlmCreateChart(t,a,n=!1){if(t&&a){let e=Chart.getChart("total_downloads_chart");dlmReportsInstance.chartDataObject={dataSetLabel:"Downloads",dataSetColor:"#27ae60",dataSetbg:dlmReportsInstance.chartGradient,dataSetPointbg:dlmReportsInstance.chartColors.darkCyan.default,dataSetBorder:dlmReportsInstance.chartColors.darkCyan.default,dataSetElementColor:"#2ecc71",lineType:"original",xAxis:"x",chartData:t},void 0!==e&&e.destroy(),jQuery(document).trigger("dlm_reports_before_data_sets",[dlmReportsInstance.chartDataObject,t,n]),0<dlmReportsInstance.dataSets.length&&(dlmReportsInstance.dataSets=dlmReportsInstance.dataSets.filter(e=>dlmReportsInstance.chartDataObject.lineType!==e.origin)),dlmReportsInstance.dataSets.push({origin:dlmReportsInstance.chartDataObject.lineType,label:dlmReportsInstance.chartDataObject.dataSetLabel,color:dlmReportsInstance.chartDataObject.dataSetColor,data:dlmReportsInstance.chartDataObject.chartData,type:"line",fill:!0,backgroundColor:dlmReportsInstance.chartDataObject.dataSetbg,pointBackgroundColor:dlmReportsInstance.chartDataObject.dataSetPointbg,pointHoverBackgroundColor:"#fff",borderColor:dlmReportsInstance.chartDataObject.dataSetBorder,pointBorderWidth:1,lineTension:.3,borderWidth:1,pointRadius:3,elements:{line:{borderColor:dlmReportsInstance.chartDataObject.dataSetElementColor,borderWidth:1},point:{radius:4,hoverRadius:4,pointStyle:"circle"}}});t=Object.values(dlmReportsInstance.dataSets).filter(e=>"original"===e.origin);let s=Object.keys(t[0].data);dlmReportsInstance.dataSets.sort(function(e,t){return"original"===e.origin?-1:1}),dlmReportsInstance.chart=new Chart(a,{title:"",data:{datasets:dlmReportsInstance.dataSets},height:450,is_series:1,options:{aspectRatio:5,animation:!1,interaction:{mode:"index",intersect:!1},stacked:!1,scales:{x:{grid:{display:!1},ticks:{callback:e=>{let t="";var a=s[e],n=s[s.length-1],o=moment(n).month(moment(n).month()-1).format("YYYY-MM");return t="undefined"!==dlmReportsInstance.chartType&&"months"===dlmReportsInstance.chartType?(e=moment(s[e]).month())<11?a===o?moment(a).format("MMM, YYYY"):moment(a).format("MMM")+" - "+moment(a).month(e+1).format("MMM")+moment(a).format(", YYYY"):a===o||a===n?moment(a).format("MMM, YYYY"):moment(a).format("MMM")+moment(a).format(" YYYY")+" - "+moment(a).month(e+1).format("MMM")+moment(a).month(e+1).format(", YYYY"):"undefined"!==dlmReportsInstance.chartType&&"months"===dlmReportsInstance.chartType?moment(a).format("MMMM, YYYY"):moment(a).format("D MMM")}}},y:{grid:{drawBorder:!1},min:0,max:0!==dlmReportsInstance.getMaxDownload()?1===Math.ceil(dlmReportsInstance.getMaxDownload()/10)?dlmReportsInstance.getMaxDownload()+1:10*Math.ceil(dlmReportsInstance.getMaxDownload()/10):100,ticks:{stepSize:0!==dlmReportsInstance.getMaxDownload()?Math.ceil(dlmReportsInstance.getMaxDownload()/4):25,callback:e=>dlmReportsInstance.shortNumber(e)}}},normalized:!0,parsing:{xAxisKey:"x",yAxisKey:"y"},plugins:{tooltip:{enabled:!1,external:dlmReportsInstance.externalTooltipHandler.bind(dlmReportsInstance,this)},legend:{display:!0}}}})}}dlmDownloadsSummary(){let a={};if(!1===dlmReportsInstance.stats||!1===dlmReportsInstance.stats.summaryStats||Object.keys(dlmReportsInstance.stats.summaryStats).length<=0)return this.setTotalDownloads(0),this.setDailyAverage(0),void this.setMostDownloaded("--");dlmReportsInstance.totalDownloads=0,dlmReportsInstance.stats.summaryStats.forEach(e=>{e=JSON.parse(e.download_ids),Object.entries(e).forEach(([e,t])=>{dlmReportsInstance.totalDownloads+=t.downloads,a[e]=void 0===a[e]?{downloads:t.downloads,id:e,title:t.title}:{downloads:a[e].downloads+t.downloads,id:e,title:t.title}})}),dlmReportsInstance.mostDownloaded=dlmReportsInstance.orderItems(Object.values(a),"desc","downloads"),dlmReportsInstance.setTotalDownloads(dlmReportsInstance.totalDownloads),dlmReportsInstance.setDailyAverage((dlmReportsInstance.totalDownloads/parseInt(dlmReportsInstance.stats.daysLength)).toFixed(0));var e=dlmReportsInstance.getDownloadCPT(dlmReportsInstance.mostDownloaded[0].id);void 0!==e?dlmReportsInstance.setMostDownloaded(e.title.rendered):dlmReportsInstance.setMostDownloaded(dlmReportsInstance.mostDownloaded[0].title)}createDatepicker(e,t,a){const n=new Date;let o=n.getDate()-1,s=n.getMonth()+1,r=s-1;var d=n.getFullYear(),l=(o<10&&(o="0"+o),s<10&&(s="0"+s),r<10&&(r="0"+r),d+"-"+s+"-"+o),d=d+"-"+r+"-"+o,m=jQuery("<div>").addClass("dlm_rdrs_overlay"),a=jQuery("<div>").attr("id",a.replace("#",""));return"dlm-date-range-picker"===t.target?(dlmReportsInstance.startDateInput=jQuery("<input>").attr("type","hidden").attr("id","dlm_start_date").attr("value",d),dlmReportsInstance.endDateInput=jQuery("<input>").attr("type","hidden").attr("id","dlm_end_date").attr("value",l),m.append(a).append(dlmReportsInstance.startDateInput).append(dlmReportsInstance.endDateInput)):jQuery(document).trigger("dlm_create_date_picker_"+t.target,[dlmReportsInstance,m,a,d,l]),m}displayDatepicker(e,s){var t;if(jQuery(e)){if(t="#"+jQuery(e).attr("id").replace(/-/gi,"_"),"dlm-date-range-picker"===s.target){if(dlmReportsInstance.datePicker.opened)return;dlmReportsInstance.datePicker.opened=!0}else jQuery(document).trigger("dlm_display_datepicker_"+s.target,[dlmReportsInstance,s,e]);let o=dlmReportsInstance.createDatepicker(e,s,t);e.append(o);var a=0<Object.keys(dlmReportsInstance.dlmReportsStats).length?new Date(dlmReportsInstance.dlmReportsStats[0].date):new Date,n=(new Date,[]),e=(jQuery(document).trigger("dlm_datepicker_shortcuts_"+s.target,[dlmReportsInstance,s,e,n]),{separator:" to ",autoClose:!0,getValue:function(){},setValue:function(e,t,a){o.find('input[type="hidden"]').first().val(t),o.find('input[type="hidden"]').last().val(a)},inline:!0,alwaysOpen:!0,container:t,endDate:new Date,startDate:a,showShortcuts:!0,shortcuts:null,customShortcuts:n});o.dateRangePicker(e).on("datepicker-change",(e,t)=>{var a,n;t.date1&&t.date2&&(a=t.date1.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"2-digit"}),n=t.date2.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"2-digit"}),o.parent().find("span.date-range-info").text(a+" - "+n)),"dlm-date-range-picker"===s.target?(dlmReportsInstance.dates.downloads={start_date:t.date1,end_date:t.date2},dlmReportsInstance.createDataOnDate(dlmReportsInstance.dates.downloads.start_date,dlmReportsInstance.dates.downloads.end_date),dlmReportsInstance.dlmCreateChart(dlmReportsInstance.stats.chartStats,dlmReportsInstance.chartContainer,!1),dlmReportsInstance.dlmDownloadsSummary(),0<Object.values(dlmReportsInstance.dlmUsersStats.logs).length&&dlmReportsInstance.logsDataByDate(dlmReportsInstance.dates.downloads.start_date,dlmReportsInstance.dates.downloads.end_date)):jQuery(document).trigger("dlm_daterangepicker_init_"+s.target,[dlmReportsInstance,t.date1,t.date2]),dlmReportsInstance.setTopDownloads(),o.data("dateRangePicker").close()}),"dlm-date-range-picker"===s.target?o.data("dateRangePicker").setDateRange(dlmReportsInstance.dates.downloads.start_date,dlmReportsInstance.dates.downloads.end_date):jQuery(document).trigger("dlm_daterangepicker_after_init_"+s.target,[o,dlmReportsInstance])}}hideDatepicker(e,t){"dlm-date-range-picker"===t.target?dlmReportsInstance.datePicker.opened=!1:jQuery(document).trigger("dlm_hide_datepicker_"+t.target,[dlmReportsInstance,e,t]),e.find(".dlm_rdrs_overlay").remove()}toggleDatepicker(e){e.stopPropagation();const t=jQuery(e.target).parents(".dlm-reports-header-date-selector");e={target:t.attr("id"),object:dlmReportsInstance.datePicker};dlmReportsInstance.closeDatePickers(t),"dlm-date-range-picker"===e.target?dlmReportsInstance.datePicker.opened?dlmReportsInstance.hideDatepicker(t,e):dlmReportsInstance.displayDatepicker(t,e):jQuery(document).trigger("dlm_toggle_datepicker_"+e.target,[dlmReportsInstance,t,e])}setTotalDownloads(e){jQuery(".dlm-reports-block-summary li#total span").html(e.toLocaleString())}setDailyAverage(e){jQuery(".dlm-reports-block-summary li#average span").html(e.toLocaleString())}setMostDownloaded(e){jQuery(".dlm-reports-block-summary li#most_popular span").html(e)}setTodayDownloads(){let e=0;Object.keys(dlmReportsInstance.dlmReportsStats).length<=0?jQuery(".dlm-reports-block-summary li#today span").html(e.toLocaleString()):(dlmReportsInstance.dlmReportsStats[dlmReportsInstance.dlmReportsStats.length-1].date===dlmReportsInstance.createDateElement(new Date)&&(e=Object.values(JSON.parse(dlmReportsInstance.dlmReportsStats[dlmReportsInstance.dlmReportsStats.length-1].download_ids)).reduce((e,t)=>e+t.downloads,0)),jQuery(".dlm-reports-block-summary li#today span").html(e))}setTopDownloads(e=0,t=!1){const a=jQuery("#total_downloads_table_wrapper2"),n=jQuery("#total_downloads_table_wrapper2 .total_downloads_table__list");if(n.empty(),n.parent().addClass("empty"),dlmReportsInstance.mostDownloaded&&!0!==t){var o=JSON.parse(JSON.stringify(dlmReportsInstance.mostDownloaded)).slice(dlmReportsInstance.perPage*parseInt(e),dlmReportsInstance.perPage*parseInt(e+1));for(let t=0;t<o.length;t++){const r=dlmReportsInstance.getDownloadByID(o[t].id);var s=dlmReportsInstance.getDownloadCPT(o[t].id);let e="--";if(e=void 0===s?o[t].title:s.title.rendered,void 0===r)return;s={id:o[t].id,title:dlmReportsInstance.htmlEntities(e),edit_link:dlmAdminUrl+"post.php?post="+o[t].id+"&action=edit",total_downloads:r.total.toLocaleString()};jQuery(document).trigger("dlm_reports_top_downloads_item_before_render",[s,dlmReportsInstance,o[t],r]),new dlmBackBone.modelTopDownloads(s)}n.parent().removeClass("empty"),a.find(".dlm-reports-total-pages").html(Math.ceil(dlmReportsInstance.mostDownloaded.length/dlmReportsInstance.perPage)),parseInt(dlmReportsInstance.perPage)!==parseInt(o.length)?a.find('.downloads-block-navigation button[data-action="load-more"]').attr("disabled","disabled"):a.find('.downloads-block-navigation button[data-action="load-more"]').removeAttr("disabled"),dlmReportsInstance.mostDownloaded.length>dlmReportsInstance.perPage?a.find(".downloads-block-navigation button").removeClass("hidden"):a.find(".downloads-block-navigation button").addClass("hidden"),dlmReportsInstance.stopSpinner(jQuery("#total_downloads_table_wrapper2"))}}handleTopDownloads(){jQuery("html body").on("click","#total_downloads_table_wrapper2 .downloads-block-navigation button",function(){let e=jQuery(this).parents("#total_downloads_table_wrapper2"),t=e,a=e.attr("data-page"),n=jQuery(this),o=parseInt(a)+1,s=0!==a?parseInt(a)-1:0,r=e.find(".downloads-block-navigation").find("button").first(),d=e.find(".downloads-block-navigation").find("button").last();n.attr("disabled","disabled");var l={data:dlmReportsInstance.mostDownloaded,main_parent:e,offsetHolder:t,offset:a,link:n,nextPage:o,prevPage:s,prevButton:r,nextButton:d,doAction:dlmReportsInstance.setTopDownloads};dlmReportsInstance.handleSliderNavigation(l)}),jQuery("#total_downloads_table_wrapper2").find("input.dlm-reports-current-page").on("change",function(){dlmReportsInstance.paginationChange(jQuery(this),dlmReportsInstance.mostDownloaded,jQuery("#total_downloads_table_wrapper2"),jQuery(this).parents("#total_downloads_table_wrapper2"),dlmReportsInstance.setTopDownloads)})}handleSliderNavigation(e){const{data:t,main_parent:a,offsetHolder:n,offset:o,link:s,nextPage:r,prevPage:d,prevButton:l,nextButton:m,doAction:c}={...e};let p=1;"load-more"===s.data("action")?(n.attr("data-page",r),c(r),Math.ceil(t.length/dlmReportsInstance.perPage)>r+1&&m.removeAttr("disabled"),l.removeAttr("disabled"),p=parseInt(r)+1):0!==parseInt(o)&&(n.attr("data-page",d),c(d),1!==parseInt(o)&&l.removeAttr("disabled"),m.removeAttr("disabled"),p=parseInt(d)+1),a.find(".dlm-reports-current-page").val(p)}tabNagivation(){jQuery(document).on("click",".dlm-reports .dlm-insights-tab-navigation > li",function(){const e=jQuery(this),t=jQuery(".dlm-reports .dlm-insights-tab-navigation > li").not(e),a=jQuery('div.dlm-insights-tab-navigation__content[data-id="'+e.attr("id")+'"]'),n=jQuery("div.dlm-insights-tab-navigation__content").not(a);e.hasClass("active")||(e.addClass("active"),t.removeClass("active"),a.addClass("active"),n.removeClass("active"))})}getOrCreateTooltip(e){let t=e.canvas.parentNode.querySelector("div.dlm-canvas-tooltip"),a=e.canvas.parentNode.querySelector("div.dlm-reports-tooltip__line");if(t||((a=document.createElement("div")).className="dlm-reports-tooltip__line"),!t){(t=document.createElement("div")).className="dlm-canvas-tooltip";const n=document.createElement("div");n.className="dlm-reports-tooltip",t.appendChild(n),e.canvas.parentNode.appendChild(t),e.canvas.parentNode.appendChild(a)}return{tooltipEl:t,tooltipLine:a}}externalTooltipHandler(d,e){const{chart:t,tooltip:l}=e,{tooltipEl:a,tooltipLine:n}={...d.getOrCreateTooltip(t)};e=jQuery(a).parent().width();if(0===l.opacity)return a.style.opacity=0,void(n.style.opacity=0);if(l.body){const m=l.title||[],c=document.createElement("div"),p=(c.className="dlm-reports-tooltip__header",m.forEach(e=>{const t=document.createElement("div"),a=(t.className="dlm-reports-tooltip__row",document.createElement("p")),n=(a.className="dlm-reports-tooltip__info",a.appendChild(document.createTextNode("Downloads")),t.appendChild(a),jQuery(document).trigger("dlm_chart_tooltip_before",[dlmReportsInstance,l,t,d]),document.createElement("p"));n.className="dlm-reports-tooltip__date";var o=dlmReportsInstance.setChartTooltipDate(l.dataPoints[0].label,d,d.stats.chartStats);n.appendChild(document.createTextNode(o)),t.appendChild(n);const s=document.createElement("p"),r=(s.className="dlm-reports-tooltip__downloads",document.createElement("span"));r.className="dlm-reports-tooltip__downloads_pointer",r.style.backgroundColor=dlmReportsInstance.chartColors.darkCyan.default,s.appendChild(r),s.appendChild(document.createTextNode(dlmReportsInstance.shortNumber(l.dataPoints[0].formattedValue))),t.appendChild(s),jQuery(document).trigger("dlm_chart_tooltip_after",[dlmReportsInstance,l,t,d]),c.appendChild(t)}),a.querySelector("div.dlm-reports-tooltip"));for(;p.firstChild;)p.firstChild.remove();p.appendChild(c)}var{offsetLeft:o,offsetTop:s}=t.canvas;a.style.opacity=1;let r={isMargin:!(n.style.opacity=1),left:!1};l.caretX-l.width<0&&(r.isMargin=!0,r.left=!0),o+l.caretX+l.width>e&&(r.isMargin=!0,r.left=!1),r.isMargin?r.left?a.style.left=o+l.width+"px":a.style.left=e-l.width+"px":a.style.left=o+l.caretX+"px",n.style.left=o+l.caretX+"px",a.style.top=s+l.caretY-a.offsetHeight-10+"px"}createUserRelatedData(){dlmReportsInstance.userRelatedData=[],Object.values(dlmReportsInstance.userDownloads).forEach((e,t)=>{var a;"0"!==e.user_id&&(a=[e.user_id,e.download_id,e.download_date,e.download_status],e="user_"+e.user_id,void 0!==dlmReportsInstance.userRelatedData[e]?dlmReportsInstance.userRelatedData[e].push(a):dlmReportsInstance.userRelatedData[e]=[a])})}logsDataByDate(e,t){var{startDate:e,endDate:t}={...dlmReportsInstance.getSetDates(e,t)};dlmReportsInstance.userDownloads=JSON.parse(JSON.stringify(dlmReportsInstance.dlmUsersStats.logs));let a=new Date(e),n=(a.setDate(a.getDate()-1),a=a.getTime(),new Date(t));n.setDate(n.getDate()+1),n=n.getTime(),dlmReportsInstance.userDownloads=dlmReportsInstance.userDownloads.filter((e,t)=>{e=dlmReportsInstance.createDateElement(new Date(e.download_date));return(e=new Date(e).getTime())>a&&e<n}),dlmReportsInstance.createUserRelatedData(),dlmReportsInstance.filterDownloads(),dlmReportsInstance.setMostActiveUser(),dlmReportsInstance.setLoggedOutDownloads(),dlmReportsInstance.setLoggedInDownloads(),jQuery(document).trigger("dlm_set_logs_data_by_date",[dlmReportsInstance])}setMostActiveUser(){var e=dlmReportsInstance.getUserByID(dlmReportsInstance.getMostActiveID()[0]);jQuery(".dlm-reports-block-summary li#most_active_user span").html(dlmReportsInstance.userToolTipMarkup(e))}getMostActiveID(){return Object.values(dlmReportsInstance.userRelatedData).length?Object.values(dlmReportsInstance.userRelatedData).reduce((e,t,a)=>parseInt(e.length)>parseInt(t.length)&&0<e.length&&null!==dlmReportsInstance.getUserByID(e[0][0])?e:null!==dlmReportsInstance.getUserByID(t[0][0])?t:[],[]):0}getUserByID(t){if(!t)return null;if("0"===t)return{role:"Guest",display_name:"Guest"};var e=Object.values(dlmReportsInstance.dlmUsersStats.users).filter(e=>parseInt(t)===parseInt(e.id));return Array.isArray(e)?0===e.length?null:e[0]:e}getLoggedInDownloads(){return Object.values(dlmReportsInstance.userRelatedData).length?1<Object.values(dlmReportsInstance.userRelatedData).length?Object.values(dlmReportsInstance.userRelatedData).reduce((e,t)=>parseInt(e)+parseInt(t.length),0):Object.values(dlmReportsInstance.userRelatedData)[0].length:0}setLoggedInDownloads(){const e=dlmReportsInstance.getLoggedInDownloads();jQuery(".dlm-reports-block-summary li#logged_in span,#total_downloads_summary_wrapper .dlm-reports-logged-in").html(e.toLocaleString())}getLoggedOutDownloads(){return dlmReportsInstance.userDownloads.length-dlmReportsInstance.getLoggedInDownloads()}setLoggedOutDownloads(){const e=dlmReportsInstance.getLoggedOutDownloads();jQuery(".dlm-reports-block-summary li#logged_out span,#total_downloads_summary_wrapper .dlm-reports-logged-out").html(e.toLocaleString())}userToolTipMarkup(e){let t='<div class="dlm-user-reports">';return t=(t=t+'<div class="wpchill-tooltip"><i>[?]</i>'+'<div class="wpchill-tooltip-content">')+("<span>User ID: "+(null!==e?e.id:"--")+"</span>"),"object"!=typeof e&&e.url.length&&(t+="<span>User URL: "+(null!==e?e.url:"--")+"</span>"),t+="<span>User registration date: "+(null!==e?e.registered:"--")+"</span>",null!==e&&void 0!==e.role&&e.role.length&&(t+="<span>User role: "+e.role+"</span>"),t=(t+="</div></div>")+(null!==e?e.display_name:"--")+"</div>"}setUserDownloads(e=0,t=!1){const a=jQuery("#users_download_log"),n=jQuery("#users_download_log .user-logs__list");if(n.empty(),!0!==t){let n=[];n=(null!==dlmReportsInstance.tempDownloads?JSON.parse(JSON.stringify(dlmReportsInstance.tempDownloads)):JSON.parse(JSON.stringify(dlmReportsInstance.userDownloads))).slice(dlmReportsInstance.perPage*parseInt(e),dlmReportsInstance.perPage*parseInt(e+1));for(let a=0;a<n.length;a++){var o=dlmReportsInstance.getUserByID(n[a].user_id.toString());let e=dlmReportsInstance.getDownloadCPT(parseInt(n[a].download_id)),t="--";void 0===e?void 0!==(e=dlmReportsInstance.altGetDownloadCPT(n[a].download_id.toString()))&&(t=e.title):t=e.title.rendered;var s={key:a,user:null!=o?o.display_name:"--",ip:n[a].user_ip,role:null!==o&&null!==o.role?o.role:"--",download:void 0!==e&&null!==e?dlmReportsInstance.htmlEntities(t):"--",valid_user:"0"!==n[a].user_id,edit_link:"0"!==n[a].user_id?"user-edit.php?user_id="+n[a].user_id:"#",edit_download_link:void 0!==e&&null!==e?dlmAdminUrl+"post.php?post="+e.id+"&action=edit":"#",status:n[a].download_status,download_date:n[a].display_date};jQuery(document).trigger("dlm_reports_user_logs_item_before_render",[s,dlmReportsInstance,n[a],o,e]),new dlmBackBone.modelUserLogs(s)}dlmReportsInstance.stopSpinner(jQuery("#users_download_log")),a.find(".dlm-reports-total-pages").html(Math.ceil(dlmReportsInstance.tempDownloads.length/dlmReportsInstance.perPage)),parseInt(dlmReportsInstance.perPage)!==parseInt(n.length)?a.find('.user-downloads-block-navigation button[data-action="load-more"]').attr("disabled","disabled"):a.find('.user-downloads-block-navigation button[data-action="load-more"]').removeAttr("disabled"),dlmReportsInstance.userDownloads.length>dlmReportsInstance.perPage?a.find(".user-downloads-block-navigation button").removeClass("hidden"):a.find(".user-downloads-block-navigation button").addClass("hidden")}}filterDownloads(){dlmReportsInstance.tempDownloads=JSON.parse(JSON.stringify(dlmReportsInstance.userDownloads)),dlmReportsInstance.currentFilters.length&&dlmReportsInstance.currentFilters.forEach(t=>{dlmReportsInstance.tempDownloads=dlmReportsInstance.tempDownloads.filter(e=>t.on===e[t.type])}),dlmReportsInstance.setUserDownloads()}handleUserDownloads(){jQuery(".user-downloads-block-navigation").on("click","button",function(e){e.stopPropagation();let t=jQuery(this).parents("#users_downloads_table_wrapper"),a=t.find("#users_download_log"),n=a.attr("data-page"),o=jQuery(this),s=parseInt(n)+1,r=0!==n?parseInt(n)-1:0,d=t.find(".downloads-block-navigation button").first(),l=t.find(".downloads-block-navigation button").last();o.attr("disabled","disabled");e={data:dlmReportsInstance.tempDownloads,main_parent:t,offsetHolder:a,offset:n,link:o,nextPage:s,prevPage:r,prevButton:d,nextButton:l,doAction:dlmReportsInstance.setUserDownloads};dlmReportsInstance.handleSliderNavigation(e)}),jQuery("#users_downloads_table_wrapper").find("input.dlm-reports-current-page").on("change",function(){dlmReportsInstance.paginationChange(jQuery(this),dlmReportsInstance.tempDownloads,jQuery("#users_downloads_table_wrapper"),jQuery("#users_downloads_table_wrapper").find("#users_download_log"),dlmReportsInstance.setUserDownloads)})}togglePageSettings(){jQuery("#dlm-toggle-settings").on("click",function(e){e.stopPropagation(),jQuery(this).find(".dlm-toggle-settings__settings").toggleClass("display")}),jQuery(".dlm-toggle-settings__settings").on("click",function(e){e.stopPropagation()}),jQuery("html,body").on("click",function(){jQuery(this).find(".dlm-toggle-settings__settings").removeClass("display")}),jQuery(document).on("change",".wpchill-toggle__input",function(e){const t=jQuery(this),a=t.attr("name"),n={action:"dlm_update_report_setting",name:a,checked:t.is(":checked"),_ajax_nonce:dlmReportsNonce};jQuery.post(ajaxurl,n,function(e){a,jQuery(document).trigger("dlm_settings_ajax_response",[dlmReportsInstance,t,e])})})}getMaxDownload(){let t=0;return dlmReportsInstance.dataSets.forEach(e=>{e=Object.values(e.data).reduce((e,t)=>t<e?e:t,0);t<e&&(t=e)}),parseInt(t)}setChartTooltipDate(e,t,a){let n="";var o,s,r;return n="undefined"!==t.chartType&&"months"===t.chartType?(moment(e).year(),r=moment(e).month(),a=Object.keys(a)[Object.keys(a).length-1],o=moment(a).month(moment(a).month()-1).format("YYYY-MM"),s=moment(e).format("YYYY-MM"),r<11?s===o?moment(s).format("MMMM, YYYY"):moment(e).format("MMM")+" - "+moment(e).month(r+1).format("MMM")+moment(e).format(", YYYY"):s===o||s===a?moment(s).format("MMMM, YYYY"):moment(e).format("MMM")+moment(e).format(" YYYY")+" - "+moment(e).month(r+1).format("MMM")+moment(e).month(r+1).format(", YYYY")):"undefined"!==t.chartType&&"days"===t.chartType?(moment(e).year(),o=moment(e).day(),a=moment(e).format("MMMM"),s=moment(e).day(o+1).format("MMMM"),r=dlmReportsInstance.dates.downloads.end_date,t=moment(r).day(moment(r).day()-1).format("MMMM Do"),moment(e).format("MMMM Do")===moment(r).format("MMMM Do")||moment(e).format("MMMM Do")===t?moment(e).format("MMMM Do, YYYY"):a===s?moment(e).format("MMMM Do")+" - "+moment(e).day(o+1).format("Do")+moment(e).format(", YYYY"):moment(e).format("MMM Do")+" - "+moment(e).day(o+1).format("MMM Do")+moment(e).format(", YYYY")):moment(e).format("MMMM Do, YY")}closeDatePickers(e){jQuery(".dlm-reports-header-date-selector").not(e).each(function(){var e={target:jQuery(this).attr("id")};dlmReportsInstance.hideDatepicker(jQuery(this),e)})}shortNumber(e){return e=4<=(e="string"==typeof e?e.replace(/,/gi,""):parseInt(e).toString()).length?parseInt(e.substring(0,e.length-3)).toLocaleString()+"k":e}getDownloadByID(t){let a={total:0},n;return dlmReportsInstance.tempDownloads.forEach(function(e){t===e.download_id&&(n=e,a.total=a.total+1,jQuery(document).trigger("dlm_download_by_id",[dlmReportsInstance,a,n]))}),a}getDownloadCPT(t){let e=null;return Array.isArray(dlmReportsInstance.downloads)&&(e=dlmReportsInstance.downloads.filter(e=>parseInt(e.id)===parseInt(t),0)[0]),jQuery(document).trigger("dlm_download_cpt",[dlmReportsInstance,e]),e}setSpinner(e){e.append('<div class="dlm-reports-spinner"><span></span></div>')}stopSpinner(e){e.find(".dlm-reports-spinner").remove()}eventsFunctions(){jQuery("body").on("click",".total_downloads_table_filters_total_downloads > a",function(e){e.preventDefault(),jQuery(this).parent().find("span.dashicons").toggleClass("dashicons-arrow-down dashicons-arrow-up"),dlmReportsInstance.orderOverviewItemsByTotal()}),jQuery("body").on("click",".total_downloads_table_filters_download_date > a",function(e){e.preventDefault(),jQuery(this).parent().find("span.dashicons").toggleClass("dashicons-arrow-down dashicons-arrow-up"),dlmReportsInstance.orderUserReportsItemsByDate()}),jQuery("body").on("change","select.dlm-reports-per-page",function(e){dlmReportsInstance.perPage=jQuery(this).val(),dlmReportsInstance.setTopDownloads(),dlmReportsInstance.setUserDownloads(),jQuery.post(ajaxurl,{action:"dlm_update_report_setting",name:"dlm-reports-per-page",value:dlmReportsInstance.perPage,_ajax_nonce:dlmReportsNonce},function(e){})})}orderItems(e,a,n,t=0){return e.sort((e,t)=>"asc"!==a?t[n]-e[n]:e[n]-t[n]),e}orderOverviewItemsByTotal(){dlmReportsInstance.mostDownloaded=dlmReportsInstance.mostDownloaded.reverse(),dlmReportsInstance.setTopDownloads()}orderUserReportsItemsByDate(){dlmReportsInstance.tempDownloads=dlmReportsInstance.tempDownloads.reverse(),dlmReportsInstance.setUserDownloads()}paginationChange(e,t,a,n,o){let s=parseInt(e.val()),r=(0===s&&(s=1),t.length<s*dlmReportsInstance.perPage&&(s=Math.ceil(t.length/dlmReportsInstance.perPage)),jQuery(this).next('button[data-action="load-more"]')),d=s+1,l=s-1,m=a.find(".downloads-block-navigation button").first(),c=a.find(".downloads-block-navigation button").last();r.attr("disabled","disabled");e={data:t,main_parent:a,offsetHolder:n,offset:s,link:r,nextPage:d,prevPage:l,prevButton:m,nextButton:c,doAction:o};dlmReportsInstance.handleSliderNavigation(e)}htmlEntities(e){var t=document.getElementById("dlm_reports_decode_area");return t.innerHTML=e,t.value}async fetchDownloadsCPT(){const e=await fetch(dlmDownloadsCptApiapi);if(!e.ok)throw new Error("Something went wrong! Reports response did not come OK - "+e.statusText);dlmReportsInstance.downloads=await e.json(),dlmReportsInstance.fetchUserData()}altGetDownloadCPT(t){let e=null;return Array.isArray(dlmReportsInstance.mostDownloaded)&&(e=dlmReportsInstance.mostDownloaded.filter(e=>e.id===t,0)[0]),jQuery(document).trigger("dlm_download_cpt",[dlmReportsInstance,e]),e}}
1
+ jQuery(function(e){new DLM_Reports;dlmReportsInstance.fetchDownloadsCPT()});class DLM_Reports{dlmReportsStats=[];dlmUsersStats={logs:[],users:[]};currentFilters=[];tempDownloads=null;templates={};totalDownloads=0;perPage=dlmReportsPerPage;downloads=[];constructor(){(dlmReportsInstance=this).chartContainer=document.getElementById("total_downloads_chart");const e=dlmReportsInstance.chartContainer.getContext("2d");dlmReportsInstance.chartColors={purple:{default:"rgba(149, 76, 233, 1)",threesome:"rgba(149, 76, 233, 0.75)",half:"rgba(149, 76, 233, 0.5)",quarter:"rgba(149, 76, 233, 0.5)",zero:"rgba(149, 76, 233, 0.05)"},blue:{default:"rgba(67, 56, 202, 1)",threesome:"rgba(67, 56, 202, 0.75)",half:"rgba(67, 56, 202, 0.5)",quarter:"rgba(67, 56, 202, 0.25)",zero:"rgba(67, 56, 202, 0.05)"},green:{default:"rgba(00, 255, 00, 1)",threesome:"rgba(00, 255, 00, 0.75)",half:"rgba(00, 255, 00, 0.5)",quarter:"rgba(00, 255, 00, 0.25)",zero:"rgba(67, 56, 202, 0.05)"},royalBlue:{default:"rgba(65, 105, 225, 1)",threesome:"rgba(65, 105, 225, 0.75)",half:"rgba(65, 105, 225, 0.5)",quarter:"rgba(65, 105, 225, 0.25)",zero:"rgba(65, 105, 225, 0.05)"},persianBlue:{default:"rgba(28, 57, 187, 1)",threesome:"rgba(28, 57, 187, 0.75)",half:"rgba(28, 57, 187, 0.5)",quarter:"rgba(28, 57, 187, 0.25)",zero:"rgba(28, 57, 187, 0.05)"},darkCyan:{default:"rgba(0,129,167, 1)",threesome:"rgba(0,129,167, 0.75)",half:"rgba(0,129,167, 0.5)",quarter:"rgba(0,129,167, 0.25)",zero:"rgba(0,129,167, 0.05)"},strongCyan:{default:"rgba(0, 175, 185, 1)",threesome:"rgba(0, 175, 185, 0.75)",half:"rgba(0, 175, 185, 0.5)",quarter:"rgba(0, 175, 185, 0.25)",zero:"rgba(0, 175, 185, 0.05)"}},dlmReportsInstance.chartGradient=e.createLinearGradient(0,25,0,300),dlmReportsInstance.chartGradient.addColorStop(0,dlmReportsInstance.chartColors.darkCyan.half),dlmReportsInstance.chartGradient.addColorStop(.45,dlmReportsInstance.chartColors.darkCyan.quarter),dlmReportsInstance.chartGradient.addColorStop(1,dlmReportsInstance.chartColors.darkCyan.zero),dlmReportsInstance.datePickerContainer=document.getElementById("dlm-date-range-picker"),dlmReportsInstance.dataSets=[];let t=new Date;dlmReportsInstance.dates={downloads:{start_date:new Date(t.setMonth(t.getMonth()-1)),end_date:new Date}},dlmReportsInstance.chartDataObject={}}async fetchReportsData(e=0,t=1e3){const a=jQuery('div[data-id="general_info"]');dlmReportsInstance.setSpinner(jQuery(".total_downloads_chart-wrapper")),dlmReportsInstance.setSpinner(jQuery("#users_download_log")),dlmReportsInstance.setSpinner(jQuery("#total_downloads_table_wrapper2"));e=dlmDownloadReportsAPI+"&offset="+e+"&limit="+t;const n=await fetch(e);if(!n.ok){const o=document.createElement("div"),s=(o.className="dlm-loading-data",document.createTextNode("Seems like we bumped into an error! ")),r=document.createTextNode("Data fetching returned a status text of : "+fetchedData.statusText),d=document.createElement("h1"),l=document.createElement("h3");throw d.appendChild(s),l.appendChild(r),o.appendChild(d),o.appendChild(l),a.find(".dlm-loading-data").remove(),a.append(o),new Error("Something went wrong! Reports response did not come OK - "+fetchedData.statusText)}dlmReportsInstance.mostDownloaded=!1,dlmReportsInstance.stats=!1,dlmReportsInstance.chartType="day";t=await n.json();dlmReportsInstance.dlmReportsStats=dlmReportsInstance.dlmReportsStats.concat(t.stats),!0===t.done?(0<window.location.href.indexOf("dlm_time")&&(dlmReportsInstance.dates.downloads.start_date=0<Object.keys(dlmReportsInstance.dlmReportsStats).length?new Date(dlmReportsInstance.dlmReportsStats[0].date):new Date,dlmReportsInstance.dates.downloads.end_date=new Date,jQuery("#dlm-date-range-picker .date-range-info").html(dlmReportsInstance.dates.downloads.start_date.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"2-digit"})+" - "+dlmReportsInstance.dates.downloads.end_date.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"2-digit"}))),dlmReportsInstance.createDataOnDate(dlmReportsInstance.dates.downloads.start_date,dlmReportsInstance.dates.downloads.end_date),dlmReportsInstance.datePicker={opened:!1},jQuery(document).trigger("dlm_downloads_report_fetched",[dlmReportsInstance,dlmReportsInstance.dlmReportsStats]),dlmReportsInstance.stopSpinner(jQuery(".total_downloads_chart-wrapper")),dlmReportsInstance.init()):dlmReportsInstance.fetchReportsData(t.offset)}async fetchUsersReportsData(e=0,t=dlmPHPinfo.retrieved_rows){const a=jQuery('div[data-id="user_reports"]');e=dlmUserReportsAPI+"&offset="+e+"&limit="+t;const n=await fetch(e);if(!n.ok)throw new Error("Something went wrong! Reports response did not come OK - "+n.statusText);t=await n.json();dlmReportsInstance.dlmUsersStats.logs=dlmReportsInstance.dlmUsersStats.logs.concat(t.logs),!0===t.done?(dlmReportsInstance.userDownloads=void 0!==dlmReportsInstance.dlmUsersStats.logs?JSON.parse(JSON.stringify(dlmReportsInstance.dlmUsersStats.logs)):{},a.find(".dlm-loading-data").remove(),dlmReportsInstance.userReportsTab(),dlmReportsInstance.setTopDownloads(),dlmReportsInstance.stopSpinner(jQuery("#total_downloads_table_wrapper2"))):dlmReportsInstance.fetchUsersReportsData(t.offset)}async fetchUserData(){const e=await fetch(dlmUserDataAPI);if(!e.ok)throw new Error("Something went wrong! Reports response did not come OK - "+e.statusText);var t=await e.json();dlmReportsInstance.dlmUsersStats.users=dlmReportsInstance.dlmUsersStats.users.concat(t),dlmReportsInstance.fetchReportsData()}init(){dlmReportsInstance.tabNagivation(),dlmReportsInstance.overViewTab(),dlmReportsInstance.togglePageSettings(),dlmReportsInstance.setSpinner(jQuery("#users_download_log")),dlmReportsInstance.setSpinner(jQuery("#total_downloads_table_wrapper2")),dlmReportsInstance.fetchUsersReportsData(),jQuery(document).trigger("dlm_reports_init",[dlmReportsInstance]),dlmReportsInstance.eventsFunctions()}overViewTab(){dlmReportsInstance.dlmCreateChart(dlmReportsInstance.stats.chartStats,dlmReportsInstance.chartContainer),dlmReportsInstance.dlmDownloadsSummary(),dlmReportsInstance.datePickerContainer.addEventListener("click",dlmReportsInstance.toggleDatepicker.bind(this)),dlmReportsInstance.setTodayDownloads(),dlmReportsInstance.handleTopDownloads(),jQuery(document).on("click","body",function(e){e.stopPropagation(),0<jQuery(dlmReportsInstance.datePickerContainer).find("#dlm_date_range_picker").length&&dlmReportsInstance.hideDatepicker(jQuery(dlmReportsInstance.datePickerContainer),{target:"dlm-date-range-picker"})})}userReportsTab(){0!==Object.values(dlmReportsInstance.dlmUsersStats).length&&(dlmReportsInstance.logsDataByDate(dlmReportsInstance.dates.downloads.start_date,dlmReportsInstance.dates.downloads.end_date),dlmReportsInstance.handleUserDownloads(),dlmReportsInstance.filterDownloads())}getDates(e,t){const a={};let n=e;for(;n.getTime()<t.getTime();)a[this.createDateElement(n)]=0,n=this.getNextDay(n);return a[this.createDateElement(n)]=0,n=this.getNextDay(n),a}getMonths(e){const t={};return Object.keys(e).map(e=>{e=e.substring(0,7);void 0===t[e]&&(t[e]=0)}),t}getDoubleMonths(e){const t={},a=Object.keys(e)[0],n=Object.keys(e)[Object.keys(e).length-1];let o=0,s=a.substring(0,7),r=n.substring(0,7);return Object.keys(e).map(e=>{e=e.substring(0,7);s!==e&&r!==e&&(s=e,o++),void 0===t[e]&&0==o%2&&(t[e]=0)}),t}getWeeks(e){let a={};return Object.keys(e).forEach(e=>{let t;t=15<moment(e).date()?e.substring(0,7)+"-15":e.substring(0,7)+"-01",void 0===a[t]&&(a[t]=0)}),a}getWeek(e){let t={},a=Object.keys(e)[Object.keys(e).length-1],n=0;return Object.keys(e).map(e=>{void 0===t[e]&&0==n%7&&(t[e]=0),n++}),void 0===t[a]&&(t[a]=0),t}getDoubleDays(e){let t={},a=Object.keys(e)[0],n=Object.keys(e)[Object.keys(e).length-1],o=0;return Object.keys(e).map(e=>{a!==e&&n!==e&&(a=e,o++),void 0===t[e]&&0==o%2&&(t[e]=0)}),t}getNextDay(e){const t=new Date(e);return t.setDate(e.getDate()+1),t}createDateElement(e){var t=(e.getMonth()+1<10?"0":"")+(e.getMonth()+1);return e.getFullYear()+"-"+t+"-"+("0"+e.getDate()).slice(-2)}getSetDates(e,t){let a,n;if(void 0!==e&&e)a=dlmReportsInstance.createDateElement(new Date(e));else{const o=new Date;o.setDate(o.getDate()-30),a=dlmReportsInstance.createDateElement(o)}if(void 0!==t&&t){e=new Date(t);n=dlmReportsInstance.createDateElement(e)}else{const s=new Date;s.setDate(s.getDate()+1),n=dlmReportsInstance.createDateElement(s)}return{startDate:a,endDate:n}}createDataOnDate(e,t){let{startDate:a,endDate:n}={...dlmReportsInstance.getSetDates(e,t)},o,s,r,d,l,m=(dlmReportsInstance.reportsData=void 0!==dlmReportsInstance.dlmReportsStats?JSON.parse(JSON.stringify(dlmReportsInstance.dlmReportsStats)):{},s=moment(n,"YYYY-MM-DD").month()-moment(a,"YYYY-MM-DD").month(),r=moment(n,"YYYY-MM-DD").year()-moment(a,"YYYY-MM-DD").year(),o=moment(n).date()-moment(a).date(),dlmReportsInstance.chartType="day",0==r&&-6<s&&s<6?1<s||s<-1?dlmReportsInstance.chartType=2==s?"week":"weeks":1==s&&(8<o||-14<o||0==o)&&(dlmReportsInstance.chartType="days"):s<=0?dlmReportsInstance.chartType="month":dlmReportsInstance.chartType="months",dlmReportsInstance.getDates(new Date(a),new Date(n))),c,p,i,g;switch(dlmReportsInstance.chartType){case"months":p=dlmReportsInstance.getDoubleMonths(m),l=p;break;case"month":var u=dlmReportsInstance.getMonths(m);l=u;break;case"weeks":i=dlmReportsInstance.getWeeks(m),l=i;break;case"week":g=dlmReportsInstance.getWeek(m),l=g;break;case"days":c=dlmReportsInstance.getDoubleDays(m),l=c;break;case"day":l=m}Object.values(dlmReportsInstance.reportsData).forEach((o,e)=>{var s=JSON.parse(o.download_ids);if(void 0!==m[o.date])switch(dlmReportsInstance.chartType){case"months":d=o.date.substring(0,7);let e=parseInt(o.date.substring(5,7)),t=o.date.substring(0,5),a=6<(e-1).length?t+(e-1):t+"0"+(e-1);Object.values(s).forEach((e,t)=>{void 0===p[d]?void 0!==p[a]&&(p[a]=p[a]+e.downloads):p[d]=p[d]+e.downloads}),l=p;break;case"month":d=o.date.substring(0,7),Object.values(s).forEach((e,t)=>{monthDownloads[d]=void 0!==monthDownloads[d]?monthDownloads[d]+e.downloads:e.downloads}),l=monthDownloads;break;case"weeks":d=15<moment(o.date).date()?o.date.substring(0,7)+"-15":o.date.substring(0,7)+"-01",Object.values(s).forEach((e,t)=>{i[d]=void 0!==i[d]?i[d]+e.downloads:e.downloads}),l=i;break;case"week":d=o.date,Object.values(s).forEach((t,e)=>{if(void 0===g[d])for(let e=1;e<8;e++){var a=moment(o.date).date(moment(o.date).date()-e).format("YYYY-MM-DD");void 0!==g[a]&&(g[a]=g[a]+t.downloads)}else g[d]=g[d]+t.downloads}),l=g;break;case"days":d=o.date;let n=moment(o.date).date(moment(o.date).date()-1).format("YYYY-MM-DD");Object.values(s).forEach((e,t)=>{void 0===c[d]?void 0!==c[n]&&(c[n]=c[n]+e.downloads):c[d]=c[d]+e.downloads}),l=c;break;case"day":Object.values(s).forEach((e,t)=>{m[o.date]=m[o.date]+e.downloads}),l=m}else delete dlmReportsInstance.reportsData[e]});const I=Object.keys(m);e=I.length,t=I.findIndex(e=>a===e);let R=I.findIndex(e=>n===e);-1===t&&-1===R?dlmReportsInstance.stats={chartStats:Object.assign({},l),summaryStats:!1,daysLength:e}:(-1===R&&(R=e),dlmReportsInstance.stats={chartStats:Object.assign({},l),summaryStats:dlmReportsInstance.reportsData,daysLength:e})}dlmCreateChart(t,a,n=!1){if(t&&a){let e=Chart.getChart("total_downloads_chart");dlmReportsInstance.chartDataObject={dataSetLabel:"Downloads",dataSetColor:"#27ae60",dataSetbg:dlmReportsInstance.chartGradient,dataSetPointbg:dlmReportsInstance.chartColors.darkCyan.default,dataSetBorder:dlmReportsInstance.chartColors.darkCyan.default,dataSetElementColor:"#2ecc71",lineType:"original",xAxis:"x",chartData:t},void 0!==e&&e.destroy(),jQuery(document).trigger("dlm_reports_before_data_sets",[dlmReportsInstance.chartDataObject,t,n]),0<dlmReportsInstance.dataSets.length&&(dlmReportsInstance.dataSets=dlmReportsInstance.dataSets.filter(e=>dlmReportsInstance.chartDataObject.lineType!==e.origin)),dlmReportsInstance.dataSets.push({origin:dlmReportsInstance.chartDataObject.lineType,label:dlmReportsInstance.chartDataObject.dataSetLabel,color:dlmReportsInstance.chartDataObject.dataSetColor,data:dlmReportsInstance.chartDataObject.chartData,type:"line",fill:!0,backgroundColor:dlmReportsInstance.chartDataObject.dataSetbg,pointBackgroundColor:dlmReportsInstance.chartDataObject.dataSetPointbg,pointHoverBackgroundColor:"#fff",borderColor:dlmReportsInstance.chartDataObject.dataSetBorder,pointBorderWidth:1,lineTension:.3,borderWidth:1,pointRadius:3,elements:{line:{borderColor:dlmReportsInstance.chartDataObject.dataSetElementColor,borderWidth:1},point:{radius:4,hoverRadius:4,pointStyle:"circle"}}});t=Object.values(dlmReportsInstance.dataSets).filter(e=>"original"===e.origin);let s=Object.keys(t[0].data);dlmReportsInstance.dataSets.sort(function(e,t){return"original"===e.origin?-1:1}),dlmReportsInstance.chart=new Chart(a,{title:"",data:{datasets:dlmReportsInstance.dataSets},height:450,is_series:1,options:{aspectRatio:5,animation:!1,interaction:{mode:"index",intersect:!1},stacked:!1,scales:{x:{grid:{display:!1},ticks:{callback:e=>{let t="";var a=s[e],n=s[s.length-1],o=moment(n).month(moment(n).month()-1).format("YYYY-MM");return t="undefined"!==dlmReportsInstance.chartType&&"months"===dlmReportsInstance.chartType?(e=moment(s[e]).month())<11?a===o?moment(a).format("MMM, YYYY"):moment(a).format("MMM")+" - "+moment(a).month(e+1).format("MMM")+moment(a).format(", YYYY"):a===o||a===n?moment(a).format("MMM, YYYY"):moment(a).format("MMM")+moment(a).format(" YYYY")+" - "+moment(a).month(e+1).format("MMM")+moment(a).month(e+1).format(", YYYY"):"undefined"!==dlmReportsInstance.chartType&&"months"===dlmReportsInstance.chartType?moment(a).format("MMMM, YYYY"):moment(a).format("D MMM")}}},y:{grid:{drawBorder:!1},min:0,max:0!==dlmReportsInstance.getMaxDownload()?1===Math.ceil(dlmReportsInstance.getMaxDownload()/10)?dlmReportsInstance.getMaxDownload()+1:10*Math.ceil(dlmReportsInstance.getMaxDownload()/10):100,ticks:{stepSize:0!==dlmReportsInstance.getMaxDownload()?Math.ceil(dlmReportsInstance.getMaxDownload()/4):25,callback:e=>dlmReportsInstance.shortNumber(e)}}},normalized:!0,parsing:{xAxisKey:"x",yAxisKey:"y"},plugins:{tooltip:{enabled:!1,external:dlmReportsInstance.externalTooltipHandler.bind(dlmReportsInstance,this)},legend:{display:!0}}}})}}dlmDownloadsSummary(){let a={};if(!1===dlmReportsInstance.stats||!1===dlmReportsInstance.stats.summaryStats||Object.keys(dlmReportsInstance.stats.summaryStats).length<=0)return this.setTotalDownloads(0),this.setDailyAverage(0),void this.setMostDownloaded("--");dlmReportsInstance.totalDownloads=0,dlmReportsInstance.stats.summaryStats.forEach(e=>{e=JSON.parse(e.download_ids),Object.entries(e).forEach(([e,t])=>{dlmReportsInstance.totalDownloads+=t.downloads,a[e]=void 0===a[e]?{downloads:t.downloads,id:e,title:t.title}:{downloads:a[e].downloads+t.downloads,id:e,title:t.title}})}),dlmReportsInstance.mostDownloaded=dlmReportsInstance.orderItems(Object.values(a),"desc","downloads"),dlmReportsInstance.setTotalDownloads(dlmReportsInstance.totalDownloads),dlmReportsInstance.setDailyAverage((dlmReportsInstance.totalDownloads/parseInt(dlmReportsInstance.stats.daysLength)).toFixed(0));var e=dlmReportsInstance.getDownloadCPT(dlmReportsInstance.mostDownloaded[0].id);void 0!==e?dlmReportsInstance.setMostDownloaded(e.title.rendered):dlmReportsInstance.setMostDownloaded(dlmReportsInstance.mostDownloaded[0].title)}createDatepicker(e,t,a){const n=new Date;let o=n.getDate()-1,s=n.getMonth()+1,r=s-1;var d=n.getFullYear(),l=(o<10&&(o="0"+o),s<10&&(s="0"+s),r<10&&(r="0"+r),d+"-"+s+"-"+o),d=d+"-"+r+"-"+o,m=jQuery("<div>").addClass("dlm_rdrs_overlay"),a=jQuery("<div>").attr("id",a.replace("#",""));return"dlm-date-range-picker"===t.target?(dlmReportsInstance.startDateInput=jQuery("<input>").attr("type","hidden").attr("id","dlm_start_date").attr("value",d),dlmReportsInstance.endDateInput=jQuery("<input>").attr("type","hidden").attr("id","dlm_end_date").attr("value",l),m.append(a).append(dlmReportsInstance.startDateInput).append(dlmReportsInstance.endDateInput)):jQuery(document).trigger("dlm_create_date_picker_"+t.target,[dlmReportsInstance,m,a,d,l]),m}displayDatepicker(e,s){var t;if(jQuery(e)){if(t="#"+jQuery(e).attr("id").replace(/-/gi,"_"),"dlm-date-range-picker"===s.target){if(dlmReportsInstance.datePicker.opened)return;dlmReportsInstance.datePicker.opened=!0}else jQuery(document).trigger("dlm_display_datepicker_"+s.target,[dlmReportsInstance,s,e]);let o=dlmReportsInstance.createDatepicker(e,s,t);e.append(o);var a=0<Object.keys(dlmReportsInstance.dlmReportsStats).length?new Date(dlmReportsInstance.dlmReportsStats[0].date):new Date,n=(new Date,[]),e=(jQuery(document).trigger("dlm_datepicker_shortcuts_"+s.target,[dlmReportsInstance,s,e,n]),{separator:" to ",autoClose:!0,getValue:function(){},setValue:function(e,t,a){o.find('input[type="hidden"]').first().val(t),o.find('input[type="hidden"]').last().val(a)},inline:!0,alwaysOpen:!0,container:t,endDate:new Date,startDate:a,showShortcuts:!0,shortcuts:null,customShortcuts:n});o.dateRangePicker(e).on("datepicker-change",(e,t)=>{var a,n;t.date1&&t.date2&&(a=t.date1.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"2-digit"}),n=t.date2.toLocaleDateString(void 0,{year:"numeric",month:"short",day:"2-digit"}),o.parent().find("span.date-range-info").text(a+" - "+n)),"dlm-date-range-picker"===s.target?(dlmReportsInstance.dates.downloads={start_date:t.date1,end_date:t.date2},dlmReportsInstance.createDataOnDate(dlmReportsInstance.dates.downloads.start_date,dlmReportsInstance.dates.downloads.end_date),dlmReportsInstance.dlmCreateChart(dlmReportsInstance.stats.chartStats,dlmReportsInstance.chartContainer,!1),dlmReportsInstance.dlmDownloadsSummary(),0<Object.values(dlmReportsInstance.dlmUsersStats.logs).length&&dlmReportsInstance.logsDataByDate(dlmReportsInstance.dates.downloads.start_date,dlmReportsInstance.dates.downloads.end_date)):jQuery(document).trigger("dlm_daterangepicker_init_"+s.target,[dlmReportsInstance,t.date1,t.date2]),dlmReportsInstance.setTopDownloads(),o.data("dateRangePicker").close()}),"dlm-date-range-picker"===s.target?o.data("dateRangePicker").setDateRange(dlmReportsInstance.dates.downloads.start_date,dlmReportsInstance.dates.downloads.end_date):jQuery(document).trigger("dlm_daterangepicker_after_init_"+s.target,[o,dlmReportsInstance])}}hideDatepicker(e,t){"dlm-date-range-picker"===t.target?dlmReportsInstance.datePicker.opened=!1:jQuery(document).trigger("dlm_hide_datepicker_"+t.target,[dlmReportsInstance,e,t]),e.find(".dlm_rdrs_overlay").remove()}toggleDatepicker(e){e.stopPropagation();const t=jQuery(e.target).parents(".dlm-reports-header-date-selector");e={target:t.attr("id"),object:dlmReportsInstance.datePicker};dlmReportsInstance.closeDatePickers(t),"dlm-date-range-picker"===e.target?dlmReportsInstance.datePicker.opened?dlmReportsInstance.hideDatepicker(t,e):dlmReportsInstance.displayDatepicker(t,e):jQuery(document).trigger("dlm_toggle_datepicker_"+e.target,[dlmReportsInstance,t,e])}setTotalDownloads(e){jQuery(".dlm-reports-block-summary li#total span").html(e.toLocaleString())}setDailyAverage(e){jQuery(".dlm-reports-block-summary li#average span").html(e.toLocaleString())}setMostDownloaded(e){jQuery(".dlm-reports-block-summary li#most_popular span").html(e)}setTodayDownloads(){let e=0;Object.keys(dlmReportsInstance.dlmReportsStats).length<=0?jQuery(".dlm-reports-block-summary li#today span").html(e.toLocaleString()):(dlmReportsInstance.dlmReportsStats[dlmReportsInstance.dlmReportsStats.length-1].date===dlmReportsInstance.createDateElement(new Date)&&(e=Object.values(JSON.parse(dlmReportsInstance.dlmReportsStats[dlmReportsInstance.dlmReportsStats.length-1].download_ids)).reduce((e,t)=>e+t.downloads,0)),jQuery(".dlm-reports-block-summary li#today span").html(e))}setTopDownloads(e=0,t=!1){const a=jQuery("#total_downloads_table_wrapper2"),n=jQuery("#total_downloads_table_wrapper2 .total_downloads_table__list");if(n.empty(),n.parent().addClass("empty"),dlmReportsInstance.mostDownloaded&&!0!==t){var o=JSON.parse(JSON.stringify(dlmReportsInstance.mostDownloaded)).slice(dlmReportsInstance.perPage*parseInt(e),dlmReportsInstance.perPage*parseInt(e+1));for(let t=0;t<o.length;t++){const r=dlmReportsInstance.getDownloadByID(o[t].id);var s=dlmReportsInstance.getDownloadCPT(o[t].id);let e="--";if(e=void 0===s?o[t].title:s.title.rendered,void 0===r)return;s={id:o[t].id,title:dlmReportsInstance.htmlEntities(e),edit_link:dlmAdminUrl+"post.php?post="+o[t].id+"&action=edit",total_downloads:r.total.toLocaleString()};jQuery(document).trigger("dlm_reports_top_downloads_item_before_render",[s,dlmReportsInstance,o[t],r]),new dlmBackBone.modelTopDownloads(s)}n.parent().removeClass("empty"),a.find(".dlm-reports-total-pages").html(Math.ceil(dlmReportsInstance.mostDownloaded.length/dlmReportsInstance.perPage)),parseInt(dlmReportsInstance.perPage)!==parseInt(o.length)?a.find('.downloads-block-navigation button[data-action="load-more"]').attr("disabled","disabled"):a.find('.downloads-block-navigation button[data-action="load-more"]').removeAttr("disabled"),dlmReportsInstance.mostDownloaded.length>dlmReportsInstance.perPage?a.find(".downloads-block-navigation button").removeClass("hidden"):a.find(".downloads-block-navigation button").addClass("hidden"),dlmReportsInstance.stopSpinner(jQuery("#total_downloads_table_wrapper2"))}}handleTopDownloads(){jQuery("html body").on("click","#total_downloads_table_wrapper2 .downloads-block-navigation button",function(){let e=jQuery(this).parents("#total_downloads_table_wrapper2"),t=e,a=e.attr("data-page"),n=jQuery(this),o=parseInt(a)+1,s=0!==a?parseInt(a)-1:0,r=e.find(".downloads-block-navigation").find("button").first(),d=e.find(".downloads-block-navigation").find("button").last();n.attr("disabled","disabled");var l={data:dlmReportsInstance.mostDownloaded,main_parent:e,offsetHolder:t,offset:a,link:n,nextPage:o,prevPage:s,prevButton:r,nextButton:d,doAction:dlmReportsInstance.setTopDownloads};dlmReportsInstance.handleSliderNavigation(l)}),jQuery("#total_downloads_table_wrapper2").find("input.dlm-reports-current-page").on("change",function(){dlmReportsInstance.paginationChange(jQuery(this),dlmReportsInstance.mostDownloaded,jQuery("#total_downloads_table_wrapper2"),jQuery(this).parents("#total_downloads_table_wrapper2"),dlmReportsInstance.setTopDownloads)})}handleSliderNavigation(e){const{data:t,main_parent:a,offsetHolder:n,offset:o,link:s,nextPage:r,prevPage:d,prevButton:l,nextButton:m,doAction:c}={...e};let p=1;"load-more"===s.data("action")?(n.attr("data-page",r),c(r),Math.ceil(t.length/dlmReportsInstance.perPage)>r+1&&m.removeAttr("disabled"),l.removeAttr("disabled"),p=parseInt(r)+1):0!==parseInt(o)&&(n.attr("data-page",d),c(d),1!==parseInt(o)&&l.removeAttr("disabled"),m.removeAttr("disabled"),p=parseInt(d)+1),a.find(".dlm-reports-current-page").val(p)}tabNagivation(){jQuery(document).on("click",".dlm-reports .dlm-insights-tab-navigation > li",function(){const e=jQuery(this),t=jQuery(".dlm-reports .dlm-insights-tab-navigation > li").not(e),a=jQuery('div.dlm-insights-tab-navigation__content[data-id="'+e.attr("id")+'"]'),n=jQuery("div.dlm-insights-tab-navigation__content").not(a);e.hasClass("active")||(e.addClass("active"),t.removeClass("active"),a.addClass("active"),n.removeClass("active"))})}getOrCreateTooltip(e){let t=e.canvas.parentNode.querySelector("div.dlm-canvas-tooltip"),a=e.canvas.parentNode.querySelector("div.dlm-reports-tooltip__line");if(t||((a=document.createElement("div")).className="dlm-reports-tooltip__line"),!t){(t=document.createElement("div")).className="dlm-canvas-tooltip";const n=document.createElement("div");n.className="dlm-reports-tooltip",t.appendChild(n),e.canvas.parentNode.appendChild(t),e.canvas.parentNode.appendChild(a)}return{tooltipEl:t,tooltipLine:a}}externalTooltipHandler(d,e){const{chart:t,tooltip:l}=e,{tooltipEl:a,tooltipLine:n}={...d.getOrCreateTooltip(t)};e=jQuery(a).parent().width();if(0===l.opacity)return a.style.opacity=0,void(n.style.opacity=0);if(l.body){const m=l.title||[],c=document.createElement("div"),p=(c.className="dlm-reports-tooltip__header",m.forEach(e=>{const t=document.createElement("div"),a=(t.className="dlm-reports-tooltip__row",document.createElement("p")),n=(a.className="dlm-reports-tooltip__info",a.appendChild(document.createTextNode("Downloads")),t.appendChild(a),jQuery(document).trigger("dlm_chart_tooltip_before",[dlmReportsInstance,l,t,d]),document.createElement("p"));n.className="dlm-reports-tooltip__date";var o=dlmReportsInstance.setChartTooltipDate(l.dataPoints[0].label,d,d.stats.chartStats);n.appendChild(document.createTextNode(o)),t.appendChild(n);const s=document.createElement("p"),r=(s.className="dlm-reports-tooltip__downloads",document.createElement("span"));r.className="dlm-reports-tooltip__downloads_pointer",r.style.backgroundColor=dlmReportsInstance.chartColors.darkCyan.default,s.appendChild(r),s.appendChild(document.createTextNode(dlmReportsInstance.shortNumber(l.dataPoints[0].formattedValue))),t.appendChild(s),jQuery(document).trigger("dlm_chart_tooltip_after",[dlmReportsInstance,l,t,d]),c.appendChild(t)}),a.querySelector("div.dlm-reports-tooltip"));for(;p.firstChild;)p.firstChild.remove();p.appendChild(c)}var{offsetLeft:o,offsetTop:s}=t.canvas;a.style.opacity=1;let r={isMargin:!(n.style.opacity=1),left:!1};l.caretX-l.width<0&&(r.isMargin=!0,r.left=!0),o+l.caretX+l.width>e&&(r.isMargin=!0,r.left=!1),r.isMargin?r.left?a.style.left=o+l.width+"px":a.style.left=e-l.width+"px":a.style.left=o+l.caretX+"px",n.style.left=o+l.caretX+"px",a.style.top=s+l.caretY-a.offsetHeight-10+"px"}createUserRelatedData(){dlmReportsInstance.userRelatedData=[],Object.values(dlmReportsInstance.userDownloads).forEach((e,t)=>{var a;"0"!==e.user_id&&(a=[e.user_id,e.download_id,e.download_date,e.download_status],e="user_"+e.user_id,void 0!==dlmReportsInstance.userRelatedData[e]?dlmReportsInstance.userRelatedData[e].push(a):dlmReportsInstance.userRelatedData[e]=[a])})}logsDataByDate(e,t){var{startDate:e,endDate:t}={...dlmReportsInstance.getSetDates(e,t)};dlmReportsInstance.userDownloads=JSON.parse(JSON.stringify(dlmReportsInstance.dlmUsersStats.logs));let a=new Date(e),n=(a.setDate(a.getDate()-1),a=a.getTime(),new Date(t));n.setDate(n.getDate()+1),n=n.getTime(),dlmReportsInstance.userDownloads=dlmReportsInstance.userDownloads.filter((e,t)=>{e=dlmReportsInstance.createDateElement(new Date(e.download_date));return(e=new Date(e).getTime())>a&&e<n}),dlmReportsInstance.createUserRelatedData(),dlmReportsInstance.filterDownloads(),dlmReportsInstance.setMostActiveUser(),dlmReportsInstance.setLoggedOutDownloads(),dlmReportsInstance.setLoggedInDownloads(),jQuery(document).trigger("dlm_set_logs_data_by_date",[dlmReportsInstance])}setMostActiveUser(){var e=dlmReportsInstance.getUserByID(dlmReportsInstance.getMostActiveID()[0]);jQuery(".dlm-reports-block-summary li#most_active_user span").html(dlmReportsInstance.userToolTipMarkup(e))}getMostActiveID(){return Object.values(dlmReportsInstance.userRelatedData).length?Object.values(dlmReportsInstance.userRelatedData).reduce((e,t,a)=>parseInt(e.length)>parseInt(t.length)&&0<e.length&&null!==dlmReportsInstance.getUserByID(e[0][0])?e:null!==dlmReportsInstance.getUserByID(t[0][0])?t:[],[]):0}getUserByID(t){if(!t)return null;if("0"===t)return{role:"Guest",display_name:"Guest"};var e=Object.values(dlmReportsInstance.dlmUsersStats.users).filter(e=>parseInt(t)===parseInt(e.id));return Array.isArray(e)?0===e.length?null:e[0]:e}getLoggedInDownloads(){return Object.values(dlmReportsInstance.userRelatedData).length?1<Object.values(dlmReportsInstance.userRelatedData).length?Object.values(dlmReportsInstance.userRelatedData).reduce((e,t)=>parseInt(e)+parseInt(t.length),0):Object.values(dlmReportsInstance.userRelatedData)[0].length:0}setLoggedInDownloads(){const e=dlmReportsInstance.getLoggedInDownloads();jQuery(".dlm-reports-block-summary li#logged_in span,#total_downloads_summary_wrapper .dlm-reports-logged-in").html(e.toLocaleString())}getLoggedOutDownloads(){return dlmReportsInstance.userDownloads.length-dlmReportsInstance.getLoggedInDownloads()}setLoggedOutDownloads(){const e=dlmReportsInstance.getLoggedOutDownloads();jQuery(".dlm-reports-block-summary li#logged_out span,#total_downloads_summary_wrapper .dlm-reports-logged-out").html(e.toLocaleString())}userToolTipMarkup(e){let t='<div class="dlm-user-reports">';return t=(t=t+'<div class="wpchill-tooltip"><i>[?]</i>'+'<div class="wpchill-tooltip-content">')+("<span>User ID: "+(null!==e?e.id:"--")+"</span>"),"object"!=typeof e&&e.url.length&&(t+="<span>User URL: "+(null!==e?e.url:"--")+"</span>"),t+="<span>User registration date: "+(null!==e?e.registered:"--")+"</span>",null!==e&&void 0!==e.role&&e.role.length&&(t+="<span>User role: "+e.role+"</span>"),t=(t+="</div></div>")+(null!==e?e.display_name:"--")+"</div>"}setUserDownloads(e=0,t=!1){const a=jQuery("#users_download_log"),n=jQuery("#users_download_log .user-logs__list");if(n.empty(),!0!==t){let n=[];n=(null!==dlmReportsInstance.tempDownloads?JSON.parse(JSON.stringify(dlmReportsInstance.tempDownloads)):JSON.parse(JSON.stringify(dlmReportsInstance.userDownloads))).slice(dlmReportsInstance.perPage*parseInt(e),dlmReportsInstance.perPage*parseInt(e+1));for(let a=0;a<n.length;a++){var o=dlmReportsInstance.getUserByID(n[a].user_id.toString());let e=dlmReportsInstance.getDownloadCPT(parseInt(n[a].download_id)),t="--";void 0===e?void 0!==(e=dlmReportsInstance.altGetDownloadCPT(n[a].download_id.toString()))&&(t=e.title):t=e.title.rendered;var s={key:a,user:null!=o?o.display_name:"--",ip:n[a].user_ip,role:null!==o&&null!==o.role?o.role:"--",download:void 0!==e&&null!==e?dlmReportsInstance.htmlEntities(t):"--",valid_user:"0"!==n[a].user_id,edit_link:"0"!==n[a].user_id?"user-edit.php?user_id="+n[a].user_id:"#",edit_download_link:void 0!==e&&null!==e?dlmAdminUrl+"post.php?post="+e.id+"&action=edit":"#",status:"redirect"===n[a].download_status?"redirected":n[a].download_status,download_date:n[a].display_date};jQuery(document).trigger("dlm_reports_user_logs_item_before_render",[s,dlmReportsInstance,n[a],o,e]),new dlmBackBone.modelUserLogs(s)}dlmReportsInstance.stopSpinner(jQuery("#users_download_log")),a.find(".dlm-reports-total-pages").html(Math.ceil(dlmReportsInstance.tempDownloads.length/dlmReportsInstance.perPage)),parseInt(dlmReportsInstance.perPage)!==parseInt(n.length)?a.find('.user-downloads-block-navigation button[data-action="load-more"]').attr("disabled","disabled"):a.find('.user-downloads-block-navigation button[data-action="load-more"]').removeAttr("disabled"),dlmReportsInstance.userDownloads.length>dlmReportsInstance.perPage?a.find(".user-downloads-block-navigation button").removeClass("hidden"):a.find(".user-downloads-block-navigation button").addClass("hidden")}}filterDownloads(){dlmReportsInstance.tempDownloads=JSON.parse(JSON.stringify(dlmReportsInstance.userDownloads)),dlmReportsInstance.currentFilters.length&&dlmReportsInstance.currentFilters.forEach(t=>{dlmReportsInstance.tempDownloads=dlmReportsInstance.tempDownloads.filter(e=>t.on===e[t.type])}),dlmReportsInstance.setUserDownloads()}handleUserDownloads(){jQuery(".user-downloads-block-navigation").on("click","button",function(e){e.stopPropagation();let t=jQuery(this).parents("#users_downloads_table_wrapper"),a=t.find("#users_download_log"),n=a.attr("data-page"),o=jQuery(this),s=parseInt(n)+1,r=0!==n?parseInt(n)-1:0,d=t.find(".downloads-block-navigation button").first(),l=t.find(".downloads-block-navigation button").last();o.attr("disabled","disabled");e={data:dlmReportsInstance.tempDownloads,main_parent:t,offsetHolder:a,offset:n,link:o,nextPage:s,prevPage:r,prevButton:d,nextButton:l,doAction:dlmReportsInstance.setUserDownloads};dlmReportsInstance.handleSliderNavigation(e)}),jQuery("#users_downloads_table_wrapper").find("input.dlm-reports-current-page").on("change",function(){dlmReportsInstance.paginationChange(jQuery(this),dlmReportsInstance.tempDownloads,jQuery("#users_downloads_table_wrapper"),jQuery("#users_downloads_table_wrapper").find("#users_download_log"),dlmReportsInstance.setUserDownloads)})}togglePageSettings(){jQuery("#dlm-toggle-settings").on("click",function(e){e.stopPropagation(),jQuery(this).find(".dlm-toggle-settings__settings").toggleClass("display")}),jQuery(".dlm-toggle-settings__settings").on("click",function(e){e.stopPropagation()}),jQuery("html,body").on("click",function(){jQuery(this).find(".dlm-toggle-settings__settings").removeClass("display")}),jQuery(document).on("change",".wpchill-toggle__input",function(e){const t=jQuery(this),a=t.attr("name"),n={action:"dlm_update_report_setting",name:a,checked:t.is(":checked"),_ajax_nonce:dlmReportsNonce};jQuery.post(ajaxurl,n,function(e){a,jQuery(document).trigger("dlm_settings_ajax_response",[dlmReportsInstance,t,e])})})}getMaxDownload(){let t=0;return dlmReportsInstance.dataSets.forEach(e=>{e=Object.values(e.data).reduce((e,t)=>t<e?e:t,0);t<e&&(t=e)}),parseInt(t)}setChartTooltipDate(e,t,a){let n="";var o,s,r;return n="undefined"!==t.chartType&&"months"===t.chartType?(moment(e).year(),r=moment(e).month(),a=Object.keys(a)[Object.keys(a).length-1],o=moment(a).month(moment(a).month()-1).format("YYYY-MM"),s=moment(e).format("YYYY-MM"),r<11?s===o?moment(s).format("MMMM, YYYY"):moment(e).format("MMM")+" - "+moment(e).month(r+1).format("MMM")+moment(e).format(", YYYY"):s===o||s===a?moment(s).format("MMMM, YYYY"):moment(e).format("MMM")+moment(e).format(" YYYY")+" - "+moment(e).month(r+1).format("MMM")+moment(e).month(r+1).format(", YYYY")):"undefined"!==t.chartType&&"days"===t.chartType?(moment(e).year(),o=moment(e).day(),a=moment(e).format("MMMM"),s=moment(e).day(o+1).format("MMMM"),r=dlmReportsInstance.dates.downloads.end_date,t=moment(r).day(moment(r).day()-1).format("MMMM Do"),moment(e).format("MMMM Do")===moment(r).format("MMMM Do")||moment(e).format("MMMM Do")===t?moment(e).format("MMMM Do, YYYY"):a===s?moment(e).format("MMMM Do")+" - "+moment(e).day(o+1).format("Do")+moment(e).format(", YYYY"):moment(e).format("MMM Do")+" - "+moment(e).day(o+1).format("MMM Do")+moment(e).format(", YYYY")):moment(e).format("MMMM Do, YY")}closeDatePickers(e){jQuery(".dlm-reports-header-date-selector").not(e).each(function(){var e={target:jQuery(this).attr("id")};dlmReportsInstance.hideDatepicker(jQuery(this),e)})}shortNumber(e){return e=4<=(e="string"==typeof e?e.replace(/,/gi,""):parseInt(e).toString()).length?parseInt(e.substring(0,e.length-3)).toLocaleString()+"k":e}getDownloadByID(t){let a={total:0},n;return dlmReportsInstance.tempDownloads.forEach(function(e){t===e.download_id&&(n=e,a.total=a.total+1,jQuery(document).trigger("dlm_download_by_id",[dlmReportsInstance,a,n]))}),a}getDownloadCPT(t){let e=null;return Array.isArray(dlmReportsInstance.downloads)&&(e=dlmReportsInstance.downloads.filter(e=>parseInt(e.id)===parseInt(t),0)[0]),jQuery(document).trigger("dlm_download_cpt",[dlmReportsInstance,e]),e}setSpinner(e){e.append('<div class="dlm-reports-spinner"><span></span></div>')}stopSpinner(e){e.find(".dlm-reports-spinner").remove()}eventsFunctions(){jQuery("body").on("click",".total_downloads_table_filters_total_downloads > a",function(e){e.preventDefault(),jQuery(this).parent().find("span.dashicons").toggleClass("dashicons-arrow-down dashicons-arrow-up"),dlmReportsInstance.orderOverviewItemsByTotal()}),jQuery("body").on("click",".total_downloads_table_filters_download_date > a",function(e){e.preventDefault(),jQuery(this).parent().find("span.dashicons").toggleClass("dashicons-arrow-down dashicons-arrow-up"),dlmReportsInstance.orderUserReportsItemsByDate()}),jQuery("body").on("change","select.dlm-reports-per-page",function(e){dlmReportsInstance.perPage=jQuery(this).val(),dlmReportsInstance.setTopDownloads(),dlmReportsInstance.setUserDownloads(),jQuery.post(ajaxurl,{action:"dlm_update_report_setting",name:"dlm-reports-per-page",value:dlmReportsInstance.perPage,_ajax_nonce:dlmReportsNonce},function(e){})})}orderItems(e,a,n,t=0){return e.sort((e,t)=>"asc"!==a?t[n]-e[n]:e[n]-t[n]),e}orderOverviewItemsByTotal(){dlmReportsInstance.mostDownloaded=dlmReportsInstance.mostDownloaded.reverse(),dlmReportsInstance.setTopDownloads()}orderUserReportsItemsByDate(){dlmReportsInstance.tempDownloads=dlmReportsInstance.tempDownloads.reverse(),dlmReportsInstance.setUserDownloads()}paginationChange(e,t,a,n,o){let s=parseInt(e.val()),r=(0===s&&(s=1),t.length<s*dlmReportsInstance.perPage&&(s=Math.ceil(t.length/dlmReportsInstance.perPage)),jQuery(this).next('button[data-action="load-more"]')),d=s+1,l=s-1,m=a.find(".downloads-block-navigation button").first(),c=a.find(".downloads-block-navigation button").last();r.attr("disabled","disabled");e={data:t,main_parent:a,offsetHolder:n,offset:s,link:r,nextPage:d,prevPage:l,prevButton:m,nextButton:c,doAction:o};dlmReportsInstance.handleSliderNavigation(e)}htmlEntities(e){var t=document.getElementById("dlm_reports_decode_area");return t.innerHTML=e,t.value}async fetchDownloadsCPT(){const e=await fetch(dlmDownloadsCptApiapi);if(!e.ok)throw new Error("Something went wrong! Reports response did not come OK - "+e.statusText);dlmReportsInstance.downloads=await e.json(),dlmReportsInstance.fetchUserData()}altGetDownloadCPT(t){let e=null;return Array.isArray(dlmReportsInstance.mostDownloaded)&&(e=dlmReportsInstance.mostDownloaded.filter(e=>e.id===t,0)[0]),jQuery(document).trigger("dlm_download_cpt",[dlmReportsInstance,e]),e}}
changelog.txt CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  = 4.7.51 - 22.11.2022 =
2
  Fix: Bug on reports when Download deleted ( [#1136](https://github.com/WPChill/download-monitor/issues/1136) )
3
 
1
+ = 4.7.52 - 23.11.2022 =
2
+ Fix: Security fix
3
+
4
  = 4.7.51 - 22.11.2022 =
5
  Fix: Bug on reports when Download deleted ( [#1136](https://github.com/WPChill/download-monitor/issues/1136) )
6
 
download-monitor.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Download Monitor
4
  Plugin URI: https://www.download-monitor.com
5
  Description: A full solution for managing and selling downloadable files, monitoring downloads and outputting download links and file information on your WordPress powered site.
6
- Version: 4.7.51
7
  Author: WPChill
8
  Author URI: https://wpchill.com
9
  Requires at least: 5.4
@@ -34,7 +34,7 @@ if ( ! defined( 'ABSPATH' ) ) {
34
 
35
  // Define DLM Version
36
 
37
- define( 'DLM_VERSION', '4.7.51' );
38
  define( 'DLM_UPGRADER_VERSION', '4.6.0' );
39
 
40
  // Define DLM FILE
3
  Plugin Name: Download Monitor
4
  Plugin URI: https://www.download-monitor.com
5
  Description: A full solution for managing and selling downloadable files, monitoring downloads and outputting download links and file information on your WordPress powered site.
6
+ Version: 4.7.52
7
  Author: WPChill
8
  Author URI: https://wpchill.com
9
  Requires at least: 5.4
34
 
35
  // Define DLM Version
36
 
37
+ define( 'DLM_VERSION', '4.7.52' );
38
  define( 'DLM_UPGRADER_VERSION', '4.6.0' );
39
 
40
  // Define DLM FILE
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: wpchill, silkalns, barrykooij, mikejolley
3
  Tags: download manager, document management, file manager, digital store, ecommerce, document management plugin, download monitor, download counter, password protection, download protection, password, protect downloads, tracker, sell, shop, ecommerce, paypal
4
  Requires at least: 5.4
5
  Tested up to: 6.1
6
- Stable tag: 4.7.51
7
  License: GPLv3
8
  Text Domain: -
9
  Requires PHP: 5.6
@@ -121,6 +121,9 @@ More documentation can be found in our [Knowledge Base](https://www.download-mon
121
 
122
  == Changelog ==
123
 
 
 
 
124
  = 4.7.51 - 22.11.2022 =
125
  Fix: Bug on reports when Download deleted ( [#1136](https://github.com/WPChill/download-monitor/issues/1136) )
126
 
3
  Tags: download manager, document management, file manager, digital store, ecommerce, document management plugin, download monitor, download counter, password protection, download protection, password, protect downloads, tracker, sell, shop, ecommerce, paypal
4
  Requires at least: 5.4
5
  Tested up to: 6.1
6
+ Stable tag: 4.7.52
7
  License: GPLv3
8
  Text Domain: -
9
  Requires PHP: 5.6
121
 
122
  == Changelog ==
123
 
124
+ = 4.7.52 - 23.11.2022 =
125
+ Fix: Security fix
126
+
127
  = 4.7.51 - 22.11.2022 =
128
  Fix: Bug on reports when Download deleted ( [#1136](https://github.com/WPChill/download-monitor/issues/1136) )
129
 
src/Admin/Reports/class-dlm-reports.php CHANGED
@@ -138,11 +138,13 @@ if ( ! class_exists( 'DLM_Reports' ) ) {
138
  * @since 4.6.0
139
  */
140
  public function create_global_variable() {
 
 
 
 
 
 
141
 
142
- $rest_route_download_reports = rest_url() . 'download-monitor/v1/download_reports';
143
- $rest_route_user_reports = rest_url() . 'download-monitor/v1/user_reports';
144
- $rest_route_user_data = rest_url() . 'download-monitor/v1/user_data';
145
- $rest_route_templates = rest_url() . 'download-monitor/v1/templates';
146
  $cpt_fields = apply_filters( 'dlm_reports_downloads_cpt', array(
147
  'author',
148
  'id',
@@ -262,8 +264,22 @@ if ( ! class_exists( 'DLM_Reports' ) ) {
262
 
263
  global $wpdb;
264
 
 
 
 
 
 
 
 
 
 
 
265
  if ( ! DLM_Logging::is_logging_enabled() || ! DLM_Utils::table_checker( $wpdb->dlm_reports ) ) {
266
- return array();
 
 
 
 
267
  }
268
 
269
  $offset = isset( $_REQUEST['offset'] ) ? absint( sanitize_text_field( wp_unslash( $_REQUEST['offset'] ) ) ) : 0;
@@ -288,6 +304,16 @@ if ( ! class_exists( 'DLM_Reports' ) ) {
288
 
289
  global $wpdb;
290
 
 
 
 
 
 
 
 
 
 
 
291
  if ( ! DLM_Logging::is_logging_enabled() || ! DLM_Utils::table_checker( $wpdb->dlm_reports ) ) {
292
  return array(
293
  'logs' => array(),
@@ -348,6 +374,12 @@ if ( ! class_exists( 'DLM_Reports' ) ) {
348
 
349
  global $wpdb;
350
 
 
 
 
 
 
 
351
  if ( ! DLM_Logging::is_logging_enabled() || ! DLM_Utils::table_checker( $wpdb->dlm_reports ) ) {
352
  return array();
353
  }
138
  * @since 4.6.0
139
  */
140
  public function create_global_variable() {
141
+ $current_user_can = '&user_can_view_reports=' . apply_filters( 'dlm_user_can_view_reports', current_user_can( 'manage_options' ) );
142
+
143
+ $rest_route_download_reports = rest_url() . 'download-monitor/v1/download_reports?_wpnonce=' . wp_create_nonce( 'wp_rest' ) . $current_user_can;
144
+ $rest_route_user_reports = rest_url() . 'download-monitor/v1/user_reports?_wpnonce=' . wp_create_nonce( 'wp_rest' ) . $current_user_can;
145
+ $rest_route_user_data = rest_url() . 'download-monitor/v1/user_data?_wpnonce=' . wp_create_nonce( 'wp_rest' ) . $current_user_can;
146
+ $rest_route_templates = rest_url() . 'download-monitor/v1/templates?_wpnonce=' . wp_create_nonce( 'wp_rest' ) . $current_user_can;
147
 
 
 
 
 
148
  $cpt_fields = apply_filters( 'dlm_reports_downloads_cpt', array(
149
  'author',
150
  'id',
264
 
265
  global $wpdb;
266
 
267
+ check_ajax_referer( 'wp_rest' );
268
+
269
+ if ( ! isset( $_REQUEST['user_can_view_reports'] ) || ! (bool) $_REQUEST['user_can_view_reports'] || ! is_user_logged_in() ) {
270
+ return array(
271
+ 'stats' => array(),
272
+ 'offset' => 0,
273
+ 'done' => true,
274
+ );
275
+ }
276
+
277
  if ( ! DLM_Logging::is_logging_enabled() || ! DLM_Utils::table_checker( $wpdb->dlm_reports ) ) {
278
+ return array(
279
+ 'stats' => array(),
280
+ 'offset' => 0,
281
+ 'done' => true,
282
+ );
283
  }
284
 
285
  $offset = isset( $_REQUEST['offset'] ) ? absint( sanitize_text_field( wp_unslash( $_REQUEST['offset'] ) ) ) : 0;
304
 
305
  global $wpdb;
306
 
307
+ check_ajax_referer( 'wp_rest' );
308
+
309
+ if ( ! isset( $_REQUEST['user_can_view_reports'] ) || ! (bool) $_REQUEST['user_can_view_reports'] || ! is_user_logged_in() ) {
310
+ return array(
311
+ 'logs' => array(),
312
+ 'offset' => 1,
313
+ 'done' => true,
314
+ );
315
+ }
316
+
317
  if ( ! DLM_Logging::is_logging_enabled() || ! DLM_Utils::table_checker( $wpdb->dlm_reports ) ) {
318
  return array(
319
  'logs' => array(),
374
 
375
  global $wpdb;
376
 
377
+ check_ajax_referer( 'wp_rest' );
378
+
379
+ if ( ! isset( $_REQUEST['user_can_view_reports'] ) || ! (bool) $_REQUEST['user_can_view_reports'] || ! is_user_logged_in() ) {
380
+ return array();
381
+ }
382
+
383
  if ( ! DLM_Logging::is_logging_enabled() || ! DLM_Utils::table_checker( $wpdb->dlm_reports ) ) {
384
  return array();
385
  }
src/DownloadHandler.php CHANGED
@@ -536,7 +536,7 @@ class DLM_Download_Handler {
536
  // Redirect to the file...
537
  if ( $download->is_redirect_only() || apply_filters( 'dlm_do_not_force', false, $download, $version ) ) {
538
  if ( ! $this->check_for_xhr() ) {
539
- $this->dlm_logging->log( $download, $version, 'redirect', false, $referrer );
540
  }
541
 
542
  // If it's not a remote file we need to create the correct URL.
536
  // Redirect to the file...
537
  if ( $download->is_redirect_only() || apply_filters( 'dlm_do_not_force', false, $download, $version ) ) {
538
  if ( ! $this->check_for_xhr() ) {
539
+ $this->dlm_logging->log( $download, $version, 'redirected', false, $referrer );
540
  }
541
 
542
  // If it's not a remote file we need to create the correct URL.