PluginProbe ʕ •ᴥ•ʔ
Auto Post Cleaner / trunk
Auto Post Cleaner vtrunk
3.12.0 3.13.1 3.2.4 3.2.5 3.3.0 3.3.10 3.3.11 3.3.8 3.4.2 3.5.3 3.6.0 3.7.0 3.7.1 3.7.2 3.7.3 3.7.5 3.7.6 3.8.0 3.9.0 3.9.4 3.9.6 3.9.7 trunk 3.0.0 3.1.0 3.10.1 3.10.2 3.11.4
delete-old-posts-programmatically / assets / js / deloldp_alpine.js
delete-old-posts-programmatically / assets / js Last commit date
alpine.min.js 5 years ago deloldp_alpine.js 7 months ago delp_multi_select.js 7 months ago delp_script.js 1 month ago
deloldp_alpine.js
194 lines
1 function deloldp_Start() {
2 return {
3 deloldpDays: '',
4 checkDays(days) {
5 if( days <= 7 ) {
6 var answer = confirm("Are you shure you want to delete Posts older than " + days + " days?")
7 if ( !answer ) document.getElementById("deloldpDays").value = ''
8 }
9 },
10 confirmSkipTrash() {
11 if(document.getElementById("skiptrash").checked) {
12 var answer = confirm("Are you sure you want to permanently delete the posts? This will result in the complete deletion of the posts without the possibility to recover them.")
13 if ( !answer ) document.getElementById("skiptrash").checked = false
14 }
15 },
16 confirmForceDelete() {
17 if(document.getElementById("forcedeleteattachedimg").checked) {
18 var answer = confirm("Are you sure you want to force-delete the media attached to posts? This will result in the deletion of the media attached to posts, even if it is used by another post.")
19 if ( !answer ) document.getElementById("forcedeleteattachedimg").checked = false
20 }
21 },
22 calculateDaysInMonths(daysInMonth){
23 var daysToMonth = daysInMonth * 30
24 document.getElementById("daysInXMonths").innerHTML = daysToMonth
25 var calcDays = document.getElementById("deloldp-post-months").value;
26 if( calcDays > 0 ) document.getElementById("deloldpDays").value = calcDays * 30;
27 },
28 copyDays() {
29 var calcDays = document.getElementById("deloldp-post-months").value;
30 if( calcDays > 0 ) document.getElementById("deloldpDays").value = calcDays * 30;
31 },
32 dismiss() {
33 // Store the info dismiss status
34 localStorage.setItem("infostatus", "dismissed")
35 document.getElementById("pluginInfo").className = 'hide'
36 },
37 onstart(){
38 // get the status for info message
39 var infoStatus = localStorage.getItem("infostatus")
40 if( infoStatus == 'dismissed' ) document.getElementById("pluginInfo").classList.add("hide")
41 }
42 }
43
44 }
45
46 /**
47 * datepicker
48 */
49 const MONTH_NAMES = [
50 "January",
51 "February",
52 "March",
53 "April",
54 "May",
55 "June",
56 "July",
57 "August",
58 "September",
59 "October",
60 "November",
61 "December",
62 ];
63 const MONTH_SHORT_NAMES = [
64 "Jan",
65 "Feb",
66 "Mar",
67 "Apr",
68 "May",
69 "Jun",
70 "Jul",
71 "Aug",
72 "Sep",
73 "Oct",
74 "Nov",
75 "Dec",
76 ];
77 const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
78
79 function app() {
80 return {
81 showDatepicker: false,
82 datepickerValue: "",
83 selectedDate: calculateDatefromDays(),
84 dateFormat: "DD-MM-YYYY",
85 month: "",
86 year: "",
87 no_of_days: [],
88 blankdays: [],
89 initDate() {
90 let today;
91 if (this.selectedDate) {
92 today = new Date(Date.parse(this.selectedDate));
93 } else {
94 today = new Date();
95 }
96 this.month = today.getMonth();
97 this.year = today.getFullYear();
98 this.datepickerValue = this.formatDateForDisplay(
99 today
100 );
101 },
102 formatDateForDisplay(date) {
103 let formattedDay = DAYS[date.getDay()];
104 let formattedDate = ("0" + date.getDate()).slice(
105 -2
106 ); // appends 0 (zero) in single digit date
107 let formattedMonth = MONTH_NAMES[date.getMonth()];
108 let formattedMonthShortName =
109 MONTH_SHORT_NAMES[date.getMonth()];
110 let formattedMonthInNumber = (
111 "0" +
112 (parseInt(date.getMonth()) + 1)
113 ).slice(-2);
114 let formattedYear = date.getFullYear();
115 if (this.dateFormat === "DD-MM-YYYY") {
116 return `${formattedDate}-${formattedMonthInNumber}-${formattedYear}`; // 02-04-2021
117 }
118 if (this.dateFormat === "YYYY-MM-DD") {
119 return `${formattedYear}-${formattedMonthInNumber}-${formattedDate}`; // 2021-04-02
120 }
121 if (this.dateFormat === "D d M, Y") {
122 return `${formattedDay} ${formattedDate} ${formattedMonthShortName} ${formattedYear}`; // Tue 02 Mar 2021
123 }
124 return `${formattedDay} ${formattedDate} ${formattedMonth} ${formattedYear}`;
125 },
126 isSelectedDate(date) {
127 const d = new Date(this.year, this.month, date);
128 return this.datepickerValue ===
129 this.formatDateForDisplay(d) ?
130 true :
131 false;
132 },
133 isToday(date) {
134 const today = new Date();
135 const d = new Date(this.year, this.month, date);
136 return today.toDateString() === d.toDateString() ?
137 true :
138 false;
139 },
140 getDateValue(date) {
141 let selectedDate = new Date(
142 this.year,
143 this.month,
144 date
145 );
146 this.datepickerValue = this.formatDateForDisplay(
147 selectedDate
148 );
149 calculateDateinDays(selectedDate);
150 // this.$refs.date.value = selectedDate.getFullYear() + "-" + ('0' + formattedMonthInNumber).slice(-2) + "-" + ('0' + selectedDate.getDate()).slice(-2);
151 this.isSelectedDate(date);
152 this.showDatepicker = false;
153 },
154 getNoOfDays() {
155 let daysInMonth = new Date(
156 this.year,
157 this.month + 1,
158 0
159 ).getDate();
160 // find where to start calendar day of week
161 let dayOfWeek = new Date(
162 this.year,
163 this.month
164 ).getDay();
165 let blankdaysArray = [];
166 for (var i = 1; i <= dayOfWeek; i++) {
167 blankdaysArray.push(i);
168 }
169 let daysArray = [];
170 for (var i = 1; i <= daysInMonth; i++) {
171 daysArray.push(i);
172 }
173 this.blankdays = blankdaysArray;
174 this.no_of_days = daysArray;
175 }
176 };
177 }
178
179 function calculateDateinDays(selectedDate){
180 const today = new Date();
181 const diffTime = Math.abs(today - selectedDate);
182 const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
183 document.getElementById("deloldpDays").value = (diffDays - 1);
184 }
185
186 function calculateDatefromDays(){
187 selectedDays = document.getElementById("deloldpDays").value;
188 var d = new Date();
189 d.setDate(d.getDate() - selectedDays);
190 setDate = d.toISOString().slice(0, 10);
191 if(selectedDays != ''){
192 return setDate;
193 } else return "";
194 }