Media from FTP - Version 9.82

Version Description

Fixed problem of add-ons.

Download this release

Release Info

Developer Katsushi Kawamori
Plugin Icon wp plugin Media from FTP
Version 9.82
Comparing to
See all releases

Version 9.82

css/jquery.datetimepicker.css ADDED
@@ -0,0 +1,306 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .xdsoft_datetimepicker{
2
+ box-shadow: 0px 5px 15px -5px rgba(0, 0, 0, 0.506);
3
+ background: #FFFFFF;
4
+ border-bottom: 1px solid #BBBBBB;
5
+ border-left: 1px solid #CCCCCC;
6
+ border-right: 1px solid #CCCCCC;
7
+ border-top: 1px solid #CCCCCC;
8
+ color: #333333;
9
+ font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
10
+ padding: 8px;
11
+ padding-left: 0px;
12
+ padding-top: 2px;
13
+ position: absolute;
14
+ z-index: 9999;
15
+ -moz-box-sizing: border-box;
16
+ box-sizing: border-box;
17
+ display:none;
18
+ }
19
+
20
+ .xdsoft_datetimepicker iframe {
21
+ position: absolute;
22
+ left: 0;
23
+ top: 0;
24
+ width: 75px;
25
+ height: 210px;
26
+ background: transparent;
27
+ border:none;
28
+ }
29
+ /*For IE8 or lower*/
30
+ .xdsoft_datetimepicker button {
31
+ border:none !important;
32
+ }
33
+
34
+ .xdsoft_noselect{
35
+ -webkit-touch-callout: none;
36
+ -webkit-user-select: none;
37
+ -khtml-user-select: none;
38
+ -moz-user-select: none;
39
+ -ms-user-select: none;
40
+ -o-user-select: none;
41
+ user-select: none;
42
+ }
43
+ .xdsoft_noselect::selection { background: transparent; }
44
+ .xdsoft_noselect::-moz-selection { background: transparent; }
45
+ .xdsoft_datetimepicker.xdsoft_inline{
46
+ display: inline-block;
47
+ position: static;
48
+ box-shadow: none;
49
+ }
50
+ .xdsoft_datetimepicker *{
51
+ -moz-box-sizing: border-box;
52
+ box-sizing: border-box;
53
+ padding:0px;
54
+ margin:0px;
55
+ }
56
+ .xdsoft_datetimepicker .xdsoft_datepicker, .xdsoft_datetimepicker .xdsoft_timepicker{
57
+ display:none;
58
+ }
59
+ .xdsoft_datetimepicker .xdsoft_datepicker.active, .xdsoft_datetimepicker .xdsoft_timepicker.active{
60
+ display:block;
61
+ }
62
+ .xdsoft_datetimepicker .xdsoft_datepicker{
63
+ width: 224px;
64
+ float:left;
65
+ margin-left:8px;
66
+ }
67
+ .xdsoft_datetimepicker.xdsoft_showweeks .xdsoft_datepicker{
68
+ width: 256px;
69
+ }
70
+ .xdsoft_datetimepicker .xdsoft_timepicker{
71
+ width: 58px;
72
+ float:left;
73
+ text-align:center;
74
+ margin-left:8px;
75
+ margin-top:0px;
76
+ }
77
+ .xdsoft_datetimepicker .xdsoft_datepicker.active+.xdsoft_timepicker{
78
+ margin-top:8px;
79
+ margin-bottom:3px
80
+ }
81
+ .xdsoft_datetimepicker .xdsoft_mounthpicker{
82
+ position: relative;
83
+ text-align: center;
84
+ }
85
+
86
+ .xdsoft_datetimepicker .xdsoft_prev, .xdsoft_datetimepicker .xdsoft_next,.xdsoft_datetimepicker .xdsoft_today_button{
87
+ background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFoAAAAeCAYAAACsYQl4AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDozQjRCQjRGREU4MkNFMzExQjRDQkIyRDJDOTdBRUI1MCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpCQjg0OUYyNTZDODAxMUUzQjMwM0IwMERBNUU0ODQ5NSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpCQjg0OUYyNDZDODAxMUUzQjMwM0IwMERBNUU0ODQ5NSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M2IChXaW5kb3dzKSI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkI5NzE3MjFBN0E2Q0UzMTFBQjJEQjgzMDk5RTNBNTdBIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjNCNEJCNEZERTgyQ0UzMTFCNENCQjJEMkM5N0FFQjUwIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+aQvATgAAAfVJREFUeNrsmr1OwzAQxzGtkPjYEAuvVGAvfQIGRKADE49gdLwDDwBiZ2RhQUKwICQkWLsgFiRQuIBTucFJ/XFp4+hO+quqnZ4uvzj2nV2RpukCW/22yAgYNINmc7du7DcghCjrkqgOKjF1znpt6rZ0AGWQj7TvCU8d9UM+QAGDrhdyc2Bnc1WVVPBev9V8lBnY+rDwncWZThG4xk4lmxtJy2AHgoY/FySgbSBPwPZ8mEXbQx3aDERb0EbYAYFC7pcAtAvkMWwC0D3NX58S9D/YnoGC7nPWr3Dg9JTbtuHhDShBT8D2CBSK/iIEvVXxpuxSgh7DdgwUTL4iA92zmJb6lKB/YTsECmV+IgK947AGDIqgQ/LojsO135Hn51l2cWlov0JdGNrPUceueXRwilSVgkUyom9Rd6gbLfYTDeO+1v6orn0InTogYDGUkYLO3/wc9BdqqTCKP1Tfi+oTIaCBIL2TES+GTyruT9S61p6BHam+99DFEAgLFklYsIBHwSI9QY80H5ta+1rB/6ovaKihBJeEJbgLbBlQgl+j3lDPqA2tfQV1j3pVn8s+oKHGTSVJ+FqDLeR5bCqJ2E/BCycsoLZETXaKGs7rhKVt+9HZScrZNMi88V8P7LlDbvOZYaJVpMMmBCT4n0o8dTBoNgbdWPsRYACs3r7XyNfbnAAAAABJRU5ErkJggg==');
88
+ }
89
+ .xdsoft_datetimepicker .xdsoft_prev{
90
+ float: left;
91
+ background-position:-20px 0px;
92
+ }
93
+ .xdsoft_datetimepicker .xdsoft_today_button{
94
+ float: left;
95
+ background-position:-70px 0px;
96
+ margin-left:5px;
97
+ }
98
+
99
+ .xdsoft_datetimepicker .xdsoft_next{
100
+ float: right;
101
+ background-position:0px 0px;
102
+ }
103
+ .xdsoft_datetimepicker .xdsoft_next:active,.xdsoft_datetimepicker .xdsoft_prev:active{
104
+ }
105
+ .xdsoft_datetimepicker .xdsoft_next,.xdsoft_datetimepicker .xdsoft_prev ,.xdsoft_datetimepicker .xdsoft_today_button{
106
+ background-color: transparent;
107
+ background-repeat: no-repeat;
108
+ border: 0px none currentColor;
109
+ cursor: pointer;
110
+ display: block;
111
+ height: 30px;
112
+ opacity: 0.5;
113
+ outline: medium none currentColor;
114
+ overflow: hidden;
115
+ padding: 0px;
116
+ position: relative;
117
+ text-indent: 100%;
118
+ white-space: nowrap;
119
+ width: 20px;
120
+ }
121
+ .xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_prev,
122
+ .xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_next{
123
+ float:none;
124
+ background-position:-40px -15px;
125
+ height: 15px;
126
+ width: 30px;
127
+ display: block;
128
+ margin-left:14px;
129
+ margin-top:7px;
130
+ }
131
+ .xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_prev{
132
+ background-position:-40px 0px;
133
+ margin-bottom:7px;
134
+ margin-top:0px;
135
+ }
136
+ .xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_time_box{
137
+ height:151px;
138
+ overflow:hidden;
139
+ border-bottom:1px solid #DDDDDD;
140
+ }
141
+ .xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_time_box >div >div{
142
+ background: #F5F5F5;
143
+ border-top:1px solid #DDDDDD;
144
+ color: #666666;
145
+ font-size: 12px;
146
+ text-align: center;
147
+ border-collapse:collapse;
148
+ cursor:pointer;
149
+ border-bottom-width:0px;
150
+ height:25px;
151
+ line-height:25px;
152
+ }
153
+
154
+ .xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_time_box >div > div:first-child{
155
+ border-top-width:0px;
156
+ }
157
+ .xdsoft_datetimepicker .xdsoft_today_button:hover,
158
+ .xdsoft_datetimepicker .xdsoft_next:hover,
159
+ .xdsoft_datetimepicker .xdsoft_prev:hover {
160
+ opacity: 1;
161
+ }
162
+ .xdsoft_datetimepicker .xdsoft_label{
163
+ display: inline;
164
+ position: relative;
165
+ z-index: 9999;
166
+ margin: 0;
167
+ padding: 5px 3px;
168
+ font-size: 14px;
169
+ line-height: 20px;
170
+ font-weight: bold;
171
+ background-color: #fff;
172
+ float:left;
173
+ width:182px;
174
+ text-align:center;
175
+ cursor:pointer;
176
+ }
177
+ .xdsoft_datetimepicker .xdsoft_label:hover{
178
+ text-decoration:underline;
179
+ }
180
+ .xdsoft_datetimepicker .xdsoft_label > .xdsoft_select{
181
+ border:1px solid #ccc;
182
+ position:absolute;
183
+ right:0px;
184
+ top:30px;
185
+ z-index:101;
186
+ display:none;
187
+ background:#fff;
188
+ max-height:160px;
189
+ overflow-y:hidden;
190
+ }
191
+ .xdsoft_datetimepicker .xdsoft_label > .xdsoft_select.xdsoft_monthselect{right:-7px;}
192
+ .xdsoft_datetimepicker .xdsoft_label > .xdsoft_select.xdsoft_yearselect{right:2px;}
193
+ .xdsoft_datetimepicker .xdsoft_label > .xdsoft_select > div > .xdsoft_option:hover{
194
+ color: #fff;
195
+ background: #ff8000;
196
+ }
197
+ .xdsoft_datetimepicker .xdsoft_label > .xdsoft_select > div > .xdsoft_option{
198
+ padding:2px 10px 2px 5px;
199
+ }
200
+ .xdsoft_datetimepicker .xdsoft_label > .xdsoft_select > div > .xdsoft_option.xdsoft_current{
201
+ background: #33AAFF;
202
+ box-shadow: #178FE5 0px 1px 3px 0px inset;
203
+ color:#fff;
204
+ font-weight: 700;
205
+ }
206
+ .xdsoft_datetimepicker .xdsoft_month{
207
+ width:90px;
208
+ text-align:right;
209
+ }
210
+ .xdsoft_datetimepicker .xdsoft_calendar{
211
+ clear:both;
212
+ }
213
+ .xdsoft_datetimepicker .xdsoft_year{
214
+ width:56px;
215
+ }
216
+ .xdsoft_datetimepicker .xdsoft_calendar table{
217
+ border-collapse:collapse;
218
+ width:100%;
219
+
220
+ }
221
+ .xdsoft_datetimepicker .xdsoft_calendar td > div{
222
+ padding-right:5px;
223
+ }
224
+ .xdsoft_datetimepicker .xdsoft_calendar th{
225
+ height: 25px;
226
+ }
227
+ .xdsoft_datetimepicker .xdsoft_calendar td,.xdsoft_datetimepicker .xdsoft_calendar th{
228
+ width:14.2857142%;
229
+ background: #F5F5F5;
230
+ border:1px solid #DDDDDD;
231
+ color: #666666;
232
+ font-size: 12px;
233
+ text-align: right;
234
+ padding:0px;
235
+ border-collapse:collapse;
236
+ cursor:pointer;
237
+ height: 25px;
238
+ }
239
+ .xdsoft_datetimepicker.xdsoft_showweeks .xdsoft_calendar td,.xdsoft_datetimepicker.xdsoft_showweeks .xdsoft_calendar th{
240
+ width:12.5%;
241
+ }
242
+ .xdsoft_datetimepicker .xdsoft_calendar th{
243
+ background: #F1F1F1;
244
+ }
245
+ .xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_today{
246
+ color:#33AAFF;
247
+ }
248
+ .xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_default,
249
+ .xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_current,
250
+ .xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_time_box >div >div.xdsoft_current{
251
+ background: #33AAFF;
252
+ box-shadow: #178FE5 0px 1px 3px 0px inset;
253
+ color:#fff;
254
+ font-weight: 700;
255
+ }
256
+ .xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_other_month,
257
+ .xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_disabled,
258
+ .xdsoft_datetimepicker .xdsoft_time_box >div >div.xdsoft_disabled{
259
+ opacity:0.5;
260
+ }
261
+ .xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_other_month.xdsoft_disabled{
262
+ opacity:0.2;
263
+ }
264
+ .xdsoft_datetimepicker .xdsoft_calendar td:hover,
265
+ .xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_time_box >div >div:hover{
266
+ color: #fff !important;
267
+ background: #ff8000 !important;
268
+ box-shadow: none !important;
269
+ }
270
+ .xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_disabled:hover,
271
+ .xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_time_box >div >div.xdsoft_disabled:hover{
272
+ color: inherit !important;
273
+ background: inherit !important;
274
+ box-shadow: inherit !important;
275
+ }
276
+ .xdsoft_datetimepicker .xdsoft_calendar th{
277
+ font-weight: 700;
278
+ text-align: center;
279
+ color: #999;
280
+ cursor:default;
281
+ }
282
+ .xdsoft_datetimepicker .xdsoft_copyright{ color:#ccc !important; font-size:10px;clear:both;float:none;margin-left:8px;}
283
+ .xdsoft_datetimepicker .xdsoft_copyright a{ color:#eee !important;}
284
+ .xdsoft_datetimepicker .xdsoft_copyright a:hover{ color:#aaa !important;}
285
+
286
+
287
+ .xdsoft_time_box{
288
+ position:relative;
289
+ border:1px solid #ccc;
290
+ }
291
+ .xdsoft_scrollbar >.xdsoft_scroller{
292
+ background:#ccc !important;
293
+ height:20px;
294
+ border-radius:3px;
295
+ }
296
+ .xdsoft_scrollbar{
297
+ position:absolute;
298
+ width:7px;
299
+ right:0px;
300
+ top:0px;
301
+ bottom:0px;
302
+ cursor:pointer;
303
+ }
304
+ .xdsoft_scroller_box{
305
+ position:relative;
306
+ }
css/loading.gif ADDED
Binary file
css/mediafromftp.css ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #mediafromftp-loading{
2
+ position: relative;
3
+ left: 40%;
4
+ top: 10%;
5
+ }
6
+
7
+ .item-mediafromftp-settings {
8
+ width: 100%;
9
+ height: 100%;
10
+ float: left;
11
+ margin: 5px;
12
+ padding: 5px;
13
+ border: #CCC 2px solid;
14
+ }
15
+
css/responsive-tabs.css ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .r-tabs .r-tabs-nav {
2
+ margin: 0;
3
+ padding: 0;
4
+ }
5
+
6
+ .r-tabs .r-tabs-tab {
7
+ display: inline-block;
8
+ margin: 0;
9
+ list-style: none;
10
+ }
11
+
12
+ .r-tabs .r-tabs-panel {
13
+ padding: 15px;
14
+ display: none;
15
+ }
16
+
17
+ .r-tabs .r-tabs-accordion-title {
18
+ display: none;
19
+ }
20
+
21
+ .r-tabs .r-tabs-panel.r-tabs-state-active {
22
+ display: block;
23
+ }
24
+
25
+ /* Accordion responsive breakpoint */
26
+ @media only screen and (max-width: 768px) {
27
+ .r-tabs .r-tabs-nav {
28
+ display: none;
29
+ }
30
+
31
+ .r-tabs .r-tabs-accordion-title {
32
+ display: block;
33
+ }
34
+ }
css/style.css ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ body {
2
+ font-family: Arial, Helvetica, Verdana, sans-serif;
3
+ font-size: 12px;
4
+ }
5
+
6
+ .r-tabs {
7
+ position: relative;
8
+ }
9
+
10
+ .r-tabs .r-tabs-nav {
11
+ border-bottom: 1px solid #ccc;
12
+ }
13
+
14
+ .r-tabs .r-tabs-nav .r-tabs-tab {
15
+ position: relative;
16
+ top: 1px;
17
+ }
18
+
19
+ .r-tabs .r-tabs-nav .r-tabs-anchor {
20
+ background: #000000;
21
+ margin-bottom: 3px;
22
+ padding: 10px 12px;
23
+ display: inline-block;
24
+ text-decoration: none;
25
+ color: #fff;
26
+ font-weight: bold;
27
+ }
28
+
29
+ .r-tabs .r-tabs-nav .r-tabs-state-active {
30
+ background-color: #fff;
31
+ margin-bottom: -1px;
32
+ border-top: 1px solid #ccc;
33
+ border-right: 1px solid #ccc;
34
+ border-left: 1px solid #ccc;
35
+ }
36
+
37
+ .r-tabs .r-tabs-nav .r-tabs-state-disabled {
38
+ opacity: 0.5;
39
+ }
40
+
41
+ .r-tabs .r-tabs-nav .r-tabs-state-active .r-tabs-anchor {
42
+ color: #000000;
43
+ background-color: #fff;
44
+ }
45
+
46
+ .r-tabs .r-tabs-panel {
47
+ border-right: 1px solid #ccc;
48
+ border-bottom: 1px solid #ccc;
49
+ border-left: 1px solid #ccc;
50
+ margin-bottom: 3px;
51
+ }
52
+
53
+ .r-tabs .r-tabs-accordion-title .r-tabs-anchor {
54
+ display: block;
55
+ padding: 10px;
56
+ background-color: #000000;
57
+ color: #fff;
58
+ font-weight: bold;
59
+ text-decoration: none;
60
+ margin-bottom: 3px;
61
+ }
62
+
63
+ .r-tabs .r-tabs-accordion-title.r-tabs-state-disabled {
64
+ opacity: 0.5;
65
+ }
66
+
67
+ .r-tabs .r-tabs-accordion-title.r-tabs-state-active .r-tabs-anchor {
68
+ background-color: #fff;
69
+ color: #000000;
70
+ border-top: 1px solid #ccc;
71
+ border-right: 1px solid #ccc;
72
+ border-left: 1px solid #ccc;
73
+ margin-bottom: 0;
74
+ }
inc/MediaFromFtp.php ADDED
@@ -0,0 +1,1401 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media from FTP
4
+ *
5
+ * @package Media from FTP
6
+ * @subpackage MediaFromFtp Main Functions
7
+ /* Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
8
+ This program is free software; you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation; version 2 of the License.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program; if not, write to the Free Software
19
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ */
21
+
22
+ class MediaFromFtp {
23
+
24
+ private $is_add_on_activate;
25
+
26
+ /* ==================================================
27
+ * Construct
28
+ * @since 9.81
29
+ */
30
+ function __construct() {
31
+
32
+ $exif_active = FALSE;
33
+ if( function_exists('media_from_ftp_add_on_exif_load_textdomain') ){
34
+ $exif_active = TRUE;
35
+ }
36
+
37
+ $cli_active = FALSE;
38
+ if( function_exists('media_from_ftp_add_on_cli_load_textdomain') ){
39
+ $cli_active = TRUE;
40
+ }
41
+
42
+ $this->is_add_on_activate = array(
43
+ 'exif' => $exif_active,
44
+ 'cli' => $cli_active
45
+ );
46
+
47
+ }
48
+
49
+ /* ==================================================
50
+ * @param string $dir
51
+ * @param string $extpattern
52
+ * @param array $mediafromftp_settings
53
+ * @return array $list
54
+ * @since 1.0
55
+ */
56
+ function scan_file($dir, $extpattern, $mediafromftp_settings) {
57
+
58
+ // for media-from-ftp-add-on-wpcron and mediafromftpcmd.php
59
+ $cmdoptions = array();
60
+ if ( $this->is_add_on_activate['cli'] ) {
61
+ $cmdoptions = getopt("s:d:a:e:t:x:p:f:c:i:b:r:y:hgm");
62
+ }
63
+
64
+ if ( isset($cmdoptions['f']) ) {
65
+ $search_limit_number = $cmdoptions['f'];
66
+ } else {
67
+ $search_limit_number = $mediafromftp_settings['search_limit_number'];
68
+ }
69
+
70
+ $thumb_deep_search = FALSE;
71
+ if ( isset($cmdoptions['m']) ) {
72
+ $thumb_deep_search = TRUE;
73
+ } else {
74
+ $thumb_deep_search = $mediafromftp_settings['thumb_deep_search'];
75
+ }
76
+ if ( $thumb_deep_search ) {
77
+ $excludefile = 'media-from-ftp-tmp'; // tmp dir file
78
+ } else {
79
+ $excludefile = '-[0-9]+x[0-9]+\.|media-from-ftp-tmp'; // thumbnail & tmp dir file
80
+ }
81
+ global $blog_id;
82
+ if ( is_multisite() && is_main_site($blog_id) ) {
83
+ $excludefile .= '|\/sites\/';
84
+ }
85
+ if ( isset($cmdoptions['e']) ) {
86
+ $excludefile .= '|'.$cmdoptions['e'];
87
+ } else {
88
+ if( !empty($mediafromftp_settings['exclude']) ){
89
+ $excludefile .= '|'.$mediafromftp_settings['exclude'];
90
+ }
91
+ }
92
+
93
+ $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
94
+ if ( isset($cmdoptions['t']) ) {
95
+ $ext2typefilter = $cmdoptions['t'];
96
+ } else {
97
+ if (!empty($_POST['ext2type'])){
98
+ $ext2typefilter = $_POST['ext2type'];
99
+ }
100
+ }
101
+
102
+ unset($cmdoptions);
103
+
104
+ $searchtext = '.*';
105
+ if (!empty($_POST['searchtext'])){
106
+ $searchtext = $this->mb_encode_multibyte($_POST['searchtext'], $mediafromftp_settings['character_code']);
107
+ }else if (!empty($_GET['searchtext'])){
108
+ $searchtext = $this->mb_encode_multibyte($_GET['searchtext'], $mediafromftp_settings['character_code']);
109
+ }
110
+
111
+ $files = scandir($dir);
112
+ $list = array();
113
+ $count = 0;
114
+ foreach ($files as $file) {
115
+ if($file == '.' || $file == '..'){
116
+ continue;
117
+ }
118
+ $fullpath = rtrim($dir, '/') . '/' . $file;
119
+ if (is_file($fullpath)) {
120
+ if (!preg_match("/".$excludefile."/", $fullpath)) {
121
+ $exts = explode('.', $file);
122
+ $ext = end($exts);
123
+ $searchflag = @preg_match("/".$searchtext."/", $fullpath);
124
+ if (!$searchflag) {
125
+ // for "preg_match error: Compilation failed: missing terminating ] for character class"
126
+ $searchflag = preg_match("/".preg_quote($searchtext,'/')."/", $fullpath);
127
+ }
128
+ if ($searchflag) {
129
+ if (preg_match("/".$extpattern."/", $ext)) {
130
+ if ( $ext2typefilter === wp_ext2type($ext) || $ext2typefilter === 'all' ) {
131
+ ++$count;
132
+ if ( $count > $search_limit_number ) {
133
+ break;
134
+ }
135
+ $list[] = $fullpath;
136
+ }
137
+ }
138
+ }
139
+ }
140
+ }
141
+ if (is_dir($fullpath)) {
142
+ $list = array_merge($list, $this->scan_file($fullpath, $extpattern, $mediafromftp_settings));
143
+ }
144
+ }
145
+
146
+ return $list;
147
+
148
+ }
149
+
150
+ /* ==================================================
151
+ * @param string $dir
152
+ * @return array $dirlist
153
+ * @since 2.1
154
+ */
155
+ function scan_dir($dir) {
156
+
157
+ $excludedir = 'media-from-ftp-tmp'; // tmp dir
158
+ global $blog_id;
159
+ if ( is_multisite() && is_main_site($blog_id) ) {
160
+ $excludedir .= '|\/sites\/';
161
+ }
162
+
163
+ $files = scandir($dir);
164
+ $list = array();
165
+ foreach ($files as $file) {
166
+ if($file == '.' || $file == '..'){
167
+ continue;
168
+ }
169
+ $fullpath = rtrim($dir, '/') . '/' . $file;
170
+ if (is_dir($fullpath)) {
171
+ if (!preg_match("/".$excludedir."/", $fullpath)) {
172
+ $list[] = $fullpath;
173
+ }
174
+ $list = array_merge($list, $this->scan_dir($fullpath));
175
+ }
176
+ }
177
+
178
+ arsort($list);
179
+ return $list;
180
+
181
+ }
182
+
183
+ /* ==================================================
184
+ * @param string $extfilter
185
+ * @return string $extpattern
186
+ * @since 2.2
187
+ */
188
+ function extpattern($extfilter){
189
+
190
+ $extpattern = NULL;
191
+
192
+ if ( $extfilter === 'all' ) {
193
+ global $user_ID;
194
+ $mimes = get_allowed_mime_types($user_ID);
195
+ foreach ($mimes as $ext => $mime) {
196
+ $extpattern .= $ext.'|'.strtoupper($ext).'|';
197
+ }
198
+ $extpattern = substr($extpattern, 0, -1);
199
+ } else {
200
+ $extpattern = $extfilter.'|'.strtoupper($extfilter);
201
+ }
202
+
203
+ return $extpattern;
204
+
205
+ }
206
+
207
+ /* ==================================================
208
+ * @param string $suffix
209
+ * @return string $mimetype
210
+ * @since 1.0
211
+ */
212
+ function mime_type($suffix){
213
+
214
+ $suffix = str_replace('.', '', $suffix);
215
+
216
+ global $user_ID;
217
+ $mimes = get_allowed_mime_types($user_ID);
218
+
219
+ foreach ($mimes as $ext => $mime) {
220
+ if ( preg_match("/".$ext."/i", $suffix) ) {
221
+ $mimetype = $mime;
222
+ }
223
+ }
224
+
225
+ return $mimetype;
226
+
227
+ }
228
+
229
+ /* ==================================================
230
+ * @param string $ext
231
+ * @param string $file
232
+ * @param string $new_url
233
+ * @return string $view_thumb_url
234
+ * @since 2.36
235
+ */
236
+ function create_cash($ext, $file, $new_url){
237
+
238
+ $cash_thumb_key = md5($new_url);
239
+ $cash_thumb_filename = MEDIAFROMFTP_PLUGIN_TMP_DIR.'/'.$cash_thumb_key.'.'.$ext;
240
+ $value_cash = get_transient( $cash_thumb_key );
241
+ if ( $value_cash <> FALSE ) {
242
+ if ( ! file_exists( $cash_thumb_filename )) {
243
+ delete_transient( $cash_thumb_key );
244
+ $value_cash = FALSE;
245
+ }
246
+ }
247
+ if ( $value_cash == FALSE ) {
248
+ if ( ! file_exists( $cash_thumb_filename )) {
249
+ $cash_thumb = wp_get_image_editor( $file );
250
+ if ( ! is_wp_error( $cash_thumb ) ) {
251
+ $cash_thumb->resize( 40 ,40, true );
252
+ $cash_thumb->save( $cash_thumb_filename );
253
+ $view_thumb_url = MEDIAFROMFTP_PLUGIN_TMP_URL.'/'.$cash_thumb_key.'.'.$ext;
254
+ } else {
255
+ $view_thumb_url = MEDIAFROMFTP_PLUGIN_SITE_URL. WPINC . '/images/media/default.png';
256
+ }
257
+ } else {
258
+ if ( file_exists( $cash_thumb_filename )) {
259
+ $view_thumb_url = MEDIAFROMFTP_PLUGIN_TMP_URL.'/'.$cash_thumb_key.'.'.$ext;
260
+ } else {
261
+ $view_thumb_url = MEDIAFROMFTP_PLUGIN_SITE_URL. WPINC . '/images/media/default.png';
262
+ }
263
+ }
264
+ set_transient( $cash_thumb_key, $view_thumb_url, DAY_IN_SECONDS);
265
+ } else {
266
+ $view_thumb_url = $value_cash;
267
+ set_transient( $cash_thumb_key, $value_cash, DAY_IN_SECONDS);
268
+ }
269
+
270
+ return $view_thumb_url;
271
+
272
+ }
273
+
274
+ /* ==================================================
275
+ * @param string $ext
276
+ * @param string $new_url_attach
277
+ * @return none
278
+ * @since 2.36
279
+ */
280
+ function delete_cash($ext, $new_url_attach){
281
+
282
+ if ( wp_ext2type($ext) === 'image' ){
283
+ $del_cash_thumb_key = md5($new_url_attach);
284
+ $del_cash_thumb_filename = MEDIAFROMFTP_PLUGIN_TMP_DIR.'/'.$del_cash_thumb_key.'.'.$ext;
285
+ $value_del_cash = get_transient( $del_cash_thumb_key );
286
+ if ( $value_del_cash <> FALSE ) {
287
+ delete_transient( $del_cash_thumb_key );
288
+ if ( file_exists( $del_cash_thumb_filename )) {
289
+ unlink( $del_cash_thumb_filename );
290
+ }
291
+ }
292
+ }
293
+
294
+ }
295
+
296
+ /* ==================================================
297
+ * @param none
298
+ * @return int $del_cash_count(int)
299
+ * @since 7.5
300
+ */
301
+ function delete_all_cash(){
302
+
303
+ global $wpdb;
304
+ $search_transients = MEDIAFROMFTP_PLUGIN_TMP_URL;
305
+ $del_transients = $wpdb->get_results("
306
+ SELECT option_value
307
+ FROM $wpdb->options
308
+ WHERE option_value LIKE '%%$search_transients%%'
309
+ ");
310
+
311
+ $del_cash_count = 0;
312
+ foreach ( $del_transients as $del_transient ) {
313
+ $delfile = pathinfo($del_transient->option_value);
314
+ $del_cash_thumb_key = $delfile['filename'];
315
+ $value_del_cash = get_transient( $del_cash_thumb_key );
316
+ if ( $value_del_cash <> FALSE ) {
317
+ delete_transient( $del_cash_thumb_key );
318
+ ++$del_cash_count;
319
+ }
320
+ }
321
+
322
+ $del_cash_thumb_filename = MEDIAFROMFTP_PLUGIN_TMP_DIR.'/*.*';
323
+ foreach ( glob($del_cash_thumb_filename) as $val ) {
324
+ unlink($val);
325
+ ++$del_cash_count;
326
+ }
327
+
328
+ return $del_cash_count;
329
+
330
+ }
331
+
332
+ /* ==================================================
333
+ * @param string $file
334
+ * @param string $dateset
335
+ * @return string $date
336
+ * @since 2.36
337
+ */
338
+ function get_date_check($file, $dateset){
339
+
340
+ $date = get_date_from_gmt(date("Y-m-d H:i:s", filemtime($file)));
341
+
342
+ if ( $dateset === 'exif' ) {
343
+ // for wp_read_image_metadata
344
+ include_once( ABSPATH . 'wp-admin/includes/image.php' );
345
+ $exifdata = wp_read_image_metadata( $file );
346
+
347
+ if ( $exifdata ) {
348
+ $exif_ux_time = $exifdata['created_timestamp'];
349
+ if ( !empty($exif_ux_time) ) {
350
+ $date = date_i18n( "Y-m-d H:i:s", $exif_ux_time, FALSE );
351
+ }
352
+ }
353
+ }
354
+
355
+ $date = substr( $date , 0 , strlen($date)-3 );
356
+
357
+ return $date;
358
+
359
+ }
360
+
361
+ /* ==================================================
362
+ * @param string $file
363
+ * @param array $attachments
364
+ * @param string $character_code
365
+ * @param bool $thumb_deep_search
366
+ * @return array $new_file(bool), $ext(string), $new_url(string)
367
+ * @since 2.36
368
+ */
369
+ function input_url($file, $attachments, $character_code, $thumb_deep_search){
370
+
371
+ $ext = NULL;
372
+ $new_url = NULL;
373
+
374
+ if ( is_dir($file) ) { // dirctory
375
+ $new_file = FALSE;
376
+ } else {
377
+ $exts = explode('.', wp_basename($file));
378
+ $ext = end($exts);
379
+ $suffix_file = '.'.$ext;
380
+ $file = wp_normalize_path($file);
381
+ $upload_path = wp_normalize_path(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR);
382
+ $new_url = MEDIAFROMFTP_PLUGIN_UPLOAD_URL.str_replace($upload_path, '', $file);
383
+ $new_titles = explode('/', $new_url);
384
+ $new_title = str_replace($suffix_file, '', end($new_titles));
385
+ $new_title_md5 = md5($new_title);
386
+ $new_url_md5 = str_replace($new_title.$suffix_file, '', $new_url).$new_title_md5.$suffix_file;
387
+ $new_file = TRUE;
388
+ $new_url = $this->mb_utf8($new_url, $character_code);
389
+ foreach ( $attachments as $attachment ){
390
+ $attach_url = MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/'.get_post_meta( $attachment->ID, '_wp_attached_file', true );
391
+ if ( $attach_url === $new_url || $attach_url === $new_url_md5 ) {
392
+ $new_file = FALSE;
393
+ } else {
394
+ if ($thumb_deep_search) {
395
+ $exts_attach_url = explode('.', wp_basename($attach_url));
396
+ $delete_ext = '.'.end($exts_attach_url);
397
+ $attach_url_base = rtrim($attach_url, $delete_ext);
398
+ if ( strstr($new_url, $attach_url_base) || strstr($new_url_md5, $attach_url_base) ) {
399
+ $thumb_pattern = '-[0-9]+x[0-9]+\.';
400
+ if ( preg_match("/".$thumb_pattern."/", $new_url) || preg_match("/".$thumb_pattern."/", $new_url_md5) ) {
401
+ $new_file = FALSE;
402
+ }
403
+ }
404
+ }
405
+ }
406
+ }
407
+ }
408
+
409
+ return array($new_file, $ext, $new_url);
410
+
411
+ }
412
+
413
+ /* ==================================================
414
+ * @param string $ext
415
+ * @param string $file
416
+ * @param string $new_url
417
+ * @param string $postcount
418
+ * @param array $mediafromftp_settings
419
+ * @return array $input_html(string), $date_time_html(string)
420
+ * @since 9.30
421
+ */
422
+ function input_html($ext, $file, $new_url, $postcount, $mediafromftp_settings){
423
+
424
+ $input_html = NULL;
425
+
426
+ if ($mediafromftp_settings['search_display_metadata']){
427
+ $file_size = size_format(filesize($file));
428
+ $mimetype = $ext.'('.$this->mime_type($ext).')';
429
+ if ( wp_ext2type($ext) === 'image' ){
430
+ $view_thumb_url = $this->create_cash($ext, $file, $new_url);
431
+ } else if ( wp_ext2type($ext) === 'audio' ) {
432
+ $view_thumb_url = MEDIAFROMFTP_PLUGIN_SITE_URL. WPINC . '/images/media/audio.png';
433
+ $metadata_audio = wp_read_audio_metadata( $file );
434
+ $file_size = size_format($metadata_audio['filesize']);
435
+ $mimetype = $metadata_audio['fileformat'].'('.$metadata_audio['mime_type'].')';
436
+ $length = $metadata_audio['length_formatted'];
437
+ } else if ( wp_ext2type($ext) === 'video' ) {
438
+ $view_thumb_url = MEDIAFROMFTP_PLUGIN_SITE_URL. WPINC . '/images/media/video.png';
439
+ $metadata_video = wp_read_video_metadata( $file );
440
+ $file_size = size_format($metadata_video['filesize']);
441
+ $mimetype = $metadata_video['fileformat'].'('.$metadata_video['mime_type'].')';
442
+ $length = $metadata_video['length_formatted'];
443
+ } else {
444
+ $filetype2 = wp_ext2type($ext);
445
+ if ( empty($filetype2) ) { $filetype2 = 'default'; }
446
+ $view_thumb_url = MEDIAFROMFTP_PLUGIN_SITE_URL. WPINC . '/images/media/'.$filetype2.'.png';
447
+ }
448
+ $input_html .= '<img width="40" height="40" src="'.$view_thumb_url.'" style="float: left; margin: 5px;">';
449
+ }
450
+
451
+ $input_html .= '<div style="overflow: hidden;">';
452
+ $input_html .= '<div><a href="'.$new_url.'" target="_blank" style="text-decoration: none; word-break: break-all;">'.$new_url.'</a></div>';
453
+
454
+ if ($mediafromftp_settings['search_display_metadata']){
455
+ $input_html .= '<div>'.__('File type:').' '.$mimetype.'</div>';
456
+ $input_html .= '<div>'.__('File size:').' '.$file_size.'</div>';
457
+ if ( wp_ext2type($ext) === 'audio' || wp_ext2type($ext) === 'video' ) {
458
+ $input_html .= '<div>'.__('Length:').' '.$length.'</div>';
459
+ }
460
+ }
461
+ $input_html .= '</div>';
462
+
463
+ $date_time_html = NULL;
464
+ $date = $this->get_date_check($file, $mediafromftp_settings['dateset']);
465
+ if ( $mediafromftp_settings['dateset'] === 'new' || $mediafromftp_settings['dateset'] === 'fixed' ) {
466
+ $input_html .= '<input type="hidden" name="new_url_attaches['.$postcount.'][datetime]" value="'.$date.'" form="mediafromftp_ajax_update" >';
467
+ } else {
468
+ $date_time_html .= '<input type="text" id="datetimepicker-mediafromftp'.$postcount.'" name="new_url_attaches['.$postcount.'][datetime]" value="'.$date.'" form="mediafromftp_ajax_update" style="width: 160px;">';
469
+ }
470
+
471
+ return array($input_html, $date_time_html);
472
+
473
+ }
474
+
475
+ /* ==================================================
476
+ * @param array $mediafromftp_settings
477
+ * @return string $form_html
478
+ * @since 9.50
479
+ */
480
+ function form_html($mediafromftp_settings) {
481
+
482
+ $scriptname = admin_url('admin.php?page=mediafromftp-search-register');
483
+
484
+ $searchtext = NULL;
485
+ if ( !empty($_POST['searchtext']) ) {
486
+ $searchtext = $_POST['searchtext'];
487
+ } else if ( !empty($_GET['searchtext']) ) {
488
+ $searchtext = $_GET['searchtext'];
489
+ }
490
+
491
+ $pagemax = $mediafromftp_settings['pagemax'];
492
+ $searchdir = $mediafromftp_settings['searchdir'];
493
+ $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
494
+ $extfilter = $mediafromftp_settings['extfilter'];
495
+
496
+ $dirs = $this->scan_dir(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR);
497
+ $linkselectbox = NULL;
498
+ $wordpress_path = wp_normalize_path(ABSPATH);
499
+ foreach ($dirs as $linkdir) {
500
+ if ( strstr($linkdir, $wordpress_path ) ) {
501
+ $linkdirenc = $this->mb_utf8(str_replace($wordpress_path, '', $linkdir), $mediafromftp_settings['character_code']);
502
+ } else {
503
+ $linkdirenc = MEDIAFROMFTP_PLUGIN_UPLOAD_PATH.$this->mb_utf8(str_replace(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR, "", $linkdir), $mediafromftp_settings['character_code']);
504
+ }
505
+ if( $searchdir === $linkdirenc ){
506
+ $linkdirs = '<option value="'.urlencode($linkdirenc).'" selected>'.$linkdirenc.'</option>';
507
+ }else{
508
+ $linkdirs = '<option value="'.urlencode($linkdirenc).'">'.$linkdirenc.'</option>';
509
+ }
510
+ $linkselectbox = $linkselectbox.$linkdirs;
511
+ }
512
+ if( $searchdir === MEDIAFROMFTP_PLUGIN_UPLOAD_PATH ){
513
+ $linkdirs = '<option value="'.urlencode(MEDIAFROMFTP_PLUGIN_UPLOAD_PATH).'" selected>'.MEDIAFROMFTP_PLUGIN_UPLOAD_PATH.'</option>';
514
+ }else{
515
+ $linkdirs = '<option value="'.urlencode(MEDIAFROMFTP_PLUGIN_UPLOAD_PATH).'">'.MEDIAFROMFTP_PLUGIN_UPLOAD_PATH.'</option>';
516
+ }
517
+ $linkselectbox = $linkselectbox.$linkdirs;
518
+ ?>
519
+ <div class="wp-filter" style="margin: 0px;"> <!-- wp-admin/css/list-tables.css -->
520
+ <form method="post" action="<?php echo $scriptname; ?>">
521
+ <?php wp_nonce_field('mff_search', 'media_from_ftp_search'); ?>
522
+ <div style="font-size: small; font-weight: bold;"><code><?php echo $wordpress_path; ?></code></div>
523
+ <select name="searchdir" style="width: 250px">
524
+ <?php echo $linkselectbox; ?>
525
+ </select>
526
+ <?php submit_button( __('Search'), 'large', '', FALSE ); ?>
527
+ <span style="margin-right: 1em;"></span>
528
+ <select name="ext2type" style="width: 110px;">
529
+ <option value="all" <?php if ($ext2typefilter === 'all') echo 'selected';?>><?php echo esc_attr( __('All types', 'media-from-ftp') ); ?></option>
530
+ <option value="image" <?php if ($ext2typefilter === 'image') echo 'selected';?>>image</option>
531
+ <option value="audio" <?php if ($ext2typefilter === 'audio') echo 'selected';?>>audio</option>
532
+ <option value="video" <?php if ($ext2typefilter === 'video') echo 'selected';?>>video</option>
533
+ <option value="document" <?php if ($ext2typefilter === 'document') echo 'selected';?>>document</option>
534
+ <option value="spreadsheet" <?php if ($ext2typefilter === 'spreadsheet') echo 'selected';?>>spreadsheet</option>
535
+ <option value="interactive" <?php if ($ext2typefilter === 'interactive') echo 'selected';?>>interactive</option>
536
+ <option value="text" <?php if ($ext2typefilter === 'text') echo 'selected';?>>text</option>
537
+ <option value="archive" <?php if ($ext2typefilter === 'archive') echo 'selected';?>>archive</option>
538
+ <option value="code" <?php if ($ext2typefilter === 'code') echo 'selected';?>>code</option>
539
+ </select>
540
+ <select name="extension" style="width: 120px;">
541
+ <option value="all" <?php if ($extfilter === 'all') echo 'selected';?>><?php echo esc_attr( __('All extensions', 'media-from-ftp') ); ?></option>
542
+ <?php
543
+ $extensions = $this->scan_extensions($ext2typefilter);
544
+ foreach ($extensions as $extselect) {
545
+ ?>
546
+ <option value="<?php echo $extselect; ?>" <?php if ($extfilter === $extselect) echo 'selected';?>><?php echo $extselect; ?></option>
547
+ <?php
548
+ }
549
+ ?>
550
+ </select>
551
+ <?php
552
+ if ( empty($searchtext) ) {
553
+ ?>
554
+ <input name="searchtext" type="text" value="" placeholder="<?php echo __('Search'); ?>">
555
+ <?php
556
+ } else {
557
+ ?>
558
+ <input name="searchtext" type="text" value="" placeholder="<?php echo $searchtext; ?>">
559
+ <?php
560
+ }
561
+ submit_button( __('Filter'), 'large', '', FALSE );
562
+ ?>
563
+ </form>
564
+ </div>
565
+ <?php
566
+
567
+ }
568
+
569
+ /* ==================================================
570
+ * @param string $ext
571
+ * @param string $new_url_attach
572
+ * @param string $new_url_datetime
573
+ * @param string $dateset
574
+ * @param string $datefixed
575
+ * @param bool $yearmonth_folders
576
+ * @param string $character_code
577
+ * @param string $cron_user
578
+ * @return array $attach_id(int), $new_attach_title(string), $new_url_attach(string), $metadata(array)
579
+ * @since 2.36
580
+ */
581
+ function regist($ext, $new_url_attach, $new_url_datetime, $dateset, $datefixed, $yearmonth_folders, $character_code, $cron_user){
582
+
583
+ // Rename and Move file
584
+ $suffix_attach_file = '.'.$ext;
585
+ $new_attach_titlenames = explode('/', $new_url_attach);
586
+ $new_attach_title = str_replace($suffix_attach_file, '', end($new_attach_titlenames));
587
+ // for utf8mb4 charcter
588
+ $new_attach_title = $this->utf8mb4_html_numeric_encode($new_attach_title, $character_code);
589
+
590
+ $path_parts = pathinfo($new_url_attach);
591
+ $urlpath_dir = wp_make_link_relative($path_parts['dirname']);
592
+
593
+ $relation_path_true = strstr(MEDIAFROMFTP_PLUGIN_UPLOAD_PATH, '../');
594
+ if ( !$relation_path_true ) {
595
+ $plus_path = ltrim(str_replace(MEDIAFROMFTP_PLUGIN_UPLOAD_PATH, '', strstr($urlpath_dir, MEDIAFROMFTP_PLUGIN_UPLOAD_PATH)), '/');
596
+ } else {
597
+ $plus_path_tmp = str_replace($urlpath_dir, '', str_replace('../', '', MEDIAFROMFTP_PLUGIN_UPLOAD_PATH).'/');
598
+ $plus_path = ltrim(str_replace($plus_path_tmp, '', $urlpath_dir), '/');
599
+ }
600
+ if ( !empty($plus_path) ) {
601
+ $plus_path = trailingslashit($plus_path);
602
+ }
603
+ $filename = $plus_path.wp_basename( $new_url_attach );
604
+
605
+ $err_copy = TRUE;
606
+ $copy_file_org1 = NULL;
607
+ $copy_file_org2 = NULL;
608
+ $copy_file_org3 = NULL;
609
+ $copy_file_new1 = NULL;
610
+ $copy_file_new2 = NULL;
611
+ $copy_file_new3 = NULL;
612
+ $postdategmt = date_i18n( "Y-m-d H:i:s", FALSE, TRUE );
613
+ if ( $dateset === 'server' || $dateset === 'exif' ) {
614
+ $postdategmt = get_gmt_from_date($new_url_datetime.':00');
615
+ }
616
+ if ( strpos( $filename ,'/' ) === FALSE ) {
617
+ $currentdir = '';
618
+ $currentfile = $filename;
619
+ } else {
620
+ $currentfiles = explode('/', $filename);
621
+ $currentfile = end($currentfiles);
622
+ $currentdir = str_replace($currentfile, '', $filename);
623
+ }
624
+ if ( strpos($currentfile, ' ' ) ) {
625
+ $oldfilename = $filename;
626
+ $currentfile = str_replace(' ', '-', $currentfile);
627
+ $filename = $currentdir.$currentfile;
628
+ $new_url_attach = MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/'.$filename;
629
+ $copy_file_org1 = $this->mb_encode_multibyte(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.'/'.$oldfilename, $character_code);
630
+ $copy_file_new1 = $this->mb_encode_multibyte(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.'/'.$filename, $character_code);
631
+ $err_copy = @copy( $copy_file_org1, $copy_file_new1 );
632
+ if ( !$err_copy ) {
633
+ return array(-1, $this->mb_utf8($copy_file_org1, $character_code), $this->mb_utf8(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.'/'.$plus_path, $character_code), NULL);
634
+ }
635
+ }
636
+ if ( function_exists('mb_check_encoding') ) {
637
+ if ( !mb_check_encoding($new_url_attach, 'ASCII') ) {
638
+ if ( strpos( $filename ,'/' ) === FALSE ) {
639
+ $currentdir = '';
640
+ $currentfile = str_replace($suffix_attach_file, '', $filename);
641
+ } else {
642
+ $currentfiles = explode('/', $filename);
643
+ $currentfile = end($currentfiles);
644
+ $currentdir = str_replace($currentfile, '', $filename);
645
+ $currentfile = str_replace($suffix_attach_file, '', $currentfile);
646
+ }
647
+
648
+ $oldfilename = $currentdir.$currentfile.$suffix_attach_file;
649
+ $filename = $currentdir.md5($currentfile).$suffix_attach_file;
650
+ $new_url_attach = MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/'.$filename;
651
+ $copy_file_org2 = $this->mb_encode_multibyte(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.'/'.$oldfilename, $character_code);
652
+ $copy_file_new2 = $this->mb_encode_multibyte(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.'/'.$filename, $character_code);
653
+ $err_copy = @copy( $copy_file_org2, $copy_file_new2 );
654
+ if ( !$err_copy ) {
655
+ if (!empty($copy_file_new1)) {
656
+ $copy_file_org2 = $copy_file_org1;
657
+ unlink( $copy_file_new1 );
658
+ }
659
+ return array(-1, $this->mb_utf8($copy_file_org2, $character_code), $this->mb_utf8(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.'/'.$plus_path, $character_code), NULL);
660
+ }
661
+ }
662
+ }
663
+
664
+ // Move YearMonth Folders
665
+ if ( $yearmonth_folders == 1 ) {
666
+ $y = substr( $postdategmt, 0, 4 );
667
+ $m = substr( $postdategmt, 5, 2 );
668
+ $subdir = "/$y/$m";
669
+ $filename_base = wp_basename($filename);
670
+ if ( MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.'/'.$filename <> MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.$subdir.'/'.$filename_base ) {
671
+ if ( !file_exists($this->mb_encode_multibyte(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.$subdir, $character_code)) ) {
672
+ wp_mkdir_p($this->mb_encode_multibyte(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.$subdir, $character_code));
673
+ }
674
+ if ( file_exists($this->mb_encode_multibyte(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.$subdir.'/'.$filename_base, $character_code)) ) {
675
+ $filename_base = wp_basename($filename, $suffix_attach_file).date_i18n( "dHis", FALSE, FALSE ).$suffix_attach_file;
676
+ }
677
+ $copy_file_org3 = $this->mb_encode_multibyte(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.'/'.$filename, $character_code);
678
+ $copy_file_new3 = $this->mb_encode_multibyte(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.$subdir.'/'.$filename_base, $character_code);
679
+ $err_copy = @copy( $copy_file_org3, $copy_file_new3 );
680
+ if ( !$err_copy ) {
681
+ if (!empty($copy_file_new1)) {
682
+ $copy_file_org3 = $copy_file_org1;
683
+ unlink( $copy_file_new1 );
684
+ } else if (!empty($copy_file_new2)) {
685
+ $copy_file_org3 = $copy_file_org2;
686
+ unlink( $copy_file_new2 );
687
+ }
688
+ return array(-1, $this->mb_utf8($copy_file_org3, $character_code), $this->mb_utf8(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.$subdir, $character_code), NULL);
689
+ }
690
+ $filename = ltrim($subdir, '/').'/'.$filename_base;
691
+ $new_url_attach = MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/'.$filename;
692
+ }
693
+ }
694
+
695
+ $filename = $this->mb_utf8($filename, $character_code);
696
+ $new_url_attach = $this->mb_utf8($new_url_attach, $character_code);
697
+
698
+ // File Regist
699
+ $newfile_post = array(
700
+ 'post_title' => $new_attach_title,
701
+ 'post_content' => '',
702
+ 'post_author' => $cron_user,
703
+ 'guid' => $new_url_attach,
704
+ 'post_status' => 'inherit',
705
+ 'post_type' => 'attachment',
706
+ 'post_mime_type' => $this->mime_type($suffix_attach_file)
707
+ );
708
+ $attach_id = wp_insert_attachment( $newfile_post, $filename );
709
+
710
+ if ( $attach_id == 0 ) { // error
711
+ if (!empty($copy_file_new1)) { unlink( $copy_file_new1 ); }
712
+ if (!empty($copy_file_new2)) { unlink( $copy_file_new2 ); }
713
+ if (!empty($copy_file_new3)) { unlink( $copy_file_new3 ); }
714
+ return array(-2, $new_attach_title, $new_url_attach, NULL);
715
+ } else {
716
+ if (!empty($copy_file_org1)) { unlink( $copy_file_org1 ); }
717
+ if (!empty($copy_file_org2)) { unlink( $copy_file_org2 ); }
718
+ if (!empty($copy_file_org3)) { unlink( $copy_file_org3 ); }
719
+ }
720
+
721
+ // Date Time Regist
722
+ if ( $dateset <> 'new' ) {
723
+ if ( $dateset === 'fixed' ) {
724
+ $postdategmt = get_gmt_from_date($datefixed.':00');
725
+ }
726
+ $postdate = get_date_from_gmt($postdategmt);
727
+ $up_post = array(
728
+ 'ID' => $attach_id,
729
+ 'post_date' => $postdate,
730
+ 'post_date_gmt' => $postdategmt,
731
+ 'post_modified' => $postdate,
732
+ 'post_modified_gmt' => $postdategmt
733
+ );
734
+ wp_update_post( $up_post );
735
+ }
736
+
737
+ // for wp_read_audio_metadata and wp_read_video_metadata
738
+ include_once( ABSPATH . 'wp-admin/includes/media.php' );
739
+ // for wp_generate_attachment_metadata
740
+ include_once( ABSPATH . 'wp-admin/includes/image.php' );
741
+
742
+ // Meta data Regist
743
+ $fullpath_filename = $this->mb_encode_multibyte(get_attached_file($attach_id), $character_code);
744
+ if ( wp_ext2type($ext) === 'image' ){
745
+ $metadata = wp_generate_attachment_metadata( $attach_id, $fullpath_filename );
746
+ }else if ( wp_ext2type($ext) === 'video' ){
747
+ $metadata = wp_read_video_metadata( $fullpath_filename );
748
+ }else if ( wp_ext2type($ext) === 'audio' ){
749
+ $metadata = wp_read_audio_metadata( $fullpath_filename );
750
+ } else {
751
+ $metadata = NULL;
752
+ }
753
+ if ( !empty($metadata) ) { // 'file' => UTF-8
754
+ if ( function_exists('array_replace') ) {
755
+ $metadata = array_replace($metadata, array('file' => $filename));
756
+ } else {
757
+ $metadata = $this->array_replace($metadata, array('file' => $filename));
758
+ }
759
+ }
760
+ wp_update_attachment_metadata( $attach_id, $metadata );
761
+
762
+ return array($attach_id, $new_attach_title, $new_url_attach, $metadata);
763
+
764
+ }
765
+
766
+ /* ==================================================
767
+ * @param string $ext
768
+ * @param int $attach_id
769
+ * @param array $metadata
770
+ * @param string $character_code
771
+ * @param string $exif_text_tag
772
+ * @return array $imagethumburls(string), $mimetype(string), $length(string), $stamptime(string), $file_size(string), $exif_text(string)
773
+ * @since 7.4
774
+ */
775
+ function output_metadata($ext, $attach_id, $metadata, $character_code, $exif_text_tag){
776
+
777
+ $imagethumburls = array();
778
+ $mimetype = NULL;
779
+ $length = NULL;
780
+ $exif_text = NULL;
781
+ $filetype = wp_check_filetype( $this->mb_encode_multibyte(get_attached_file($attach_id), $character_code) );
782
+ if ( wp_ext2type($ext) === 'image' ){
783
+ $imagethumburl_base = MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/'.rtrim($metadata['file'], wp_basename($metadata['file']));
784
+ foreach ( $metadata as $key1 => $key2 ){
785
+ if ( $key1 === 'sizes' ) {
786
+ foreach ( $metadata[$key1] as $key2 => $key3 ){
787
+ $imagethumburls[$key2] = $imagethumburl_base.$metadata['sizes'][$key2]['file'];
788
+ }
789
+ }
790
+ }
791
+ $mimetype = $filetype['ext'].'('.$filetype['type'].')';
792
+ }else if ( wp_ext2type($ext) === 'video'|| wp_ext2type($ext) === 'audio' ){
793
+ $mimetype = $metadata['fileformat'].'('.$metadata['mime_type'].')';
794
+ $length = $metadata['length_formatted'];
795
+ } else {
796
+ $metadata = NULL;
797
+ $mimetype = $filetype['ext'].'('.$filetype['type'].')';
798
+ }
799
+
800
+ $stamptime = get_the_time( 'Y-n-j ', $attach_id ).get_the_time( 'G:i', $attach_id );
801
+ if ( isset( $metadata['filesize'] ) ) {
802
+ $file_size = $metadata['filesize'];
803
+ } else {
804
+ $file_size = @filesize( $this->mb_encode_multibyte(get_attached_file($attach_id), $character_code) );
805
+ }
806
+
807
+ if ( $this->is_add_on_activate['exif'] ) {
808
+ if ( $filetype['type'] === 'image/jpeg' || $filetype['type'] === 'image/tiff' ) {
809
+ if ( !empty($exif_text_tag) ) {
810
+ include_once MEDIAFROMFTP_ADDON_EXIF_PLUGIN_BASE_DIR.'/inc/MediaFromFtpAddOnExif.php';
811
+ $mediafromftpaddonexif = new MediaFromFtpAddOnExif();
812
+ $exif_text = $mediafromftpaddonexif->exifcaption($attach_id, $metadata, $exif_text_tag);
813
+ unset($mediafromftpaddonexif);
814
+ }
815
+ }
816
+ }
817
+
818
+ return array($imagethumburls, $mimetype, $length, $stamptime, $file_size, $exif_text);
819
+
820
+ }
821
+
822
+ /* ==================================================
823
+ * @param string $ext
824
+ * @param string $file_size
825
+ * @param int $attach_id
826
+ * @param string $new_attach_title
827
+ * @param string $new_url_attach
828
+ * @param array $imagethumburls
829
+ * @param string $mimetype
830
+ * @param string $length
831
+ * @param string $stamptime
832
+ * @param string $file_size
833
+ * @param string $exif_text
834
+ * @param array $image_attr_thumbnail
835
+ * @param array $mediafromftp_settings
836
+ * @param string $cat_html
837
+ * @return string $output_html
838
+ * @since 9.30
839
+ */
840
+ function output_html_and_log($ext, $attach_id, $new_attach_title, $new_url_attach, $imagethumburls, $mimetype, $length, $stamptime, $file_size, $exif_text, $image_attr_thumbnail, $mediafromftp_settings, $cat_html, $mlccategory, $emlcategory, $mlacategory, $mlatag){
841
+
842
+ $thumbnails = array();
843
+
844
+ $output_html = '<div style="border-bottom: 1px solid; padding-top: 5px; padding-bottom: 5px;">';
845
+ $output_html .= '<img width="40" height="40" src="'.$image_attr_thumbnail[0].'" style="float: left; margin: 5px;">';
846
+ $output_html .= '<div style="overflow: hidden;">';
847
+ $output_html .= '<div>ID: '.$attach_id.'</div>';
848
+ $output_html .= '<div>'.__('Title').': '.$new_attach_title.'</div>';
849
+ $output_html .= '<div>'.__('Permalink:').' <a href="'.get_attachment_link($attach_id).'" target="_blank" style="text-decoration: none; word-break: break-all;">'.get_attachment_link($attach_id).'</a></div>';
850
+ $output_html .= '<div>URL: <a href="'.$new_url_attach.'" target="_blank" style="text-decoration: none; word-break: break-all;">'.$new_url_attach.'</a></div>';
851
+ $new_url_attachs = explode('/', $new_url_attach);
852
+ $output_html .= '<div>'.__('File name:').' '.end($new_url_attachs).'</div>';
853
+
854
+ $output_html .= '<div>'.__('Date/Time').': '.$stamptime.'</div>';
855
+ if ( !$file_size ) {
856
+ $file_size = '<font color="red">'.__('Could not retrieve.', 'media-from-ftp').'</font>';
857
+ } else {
858
+ $file_size = size_format($file_size);
859
+ }
860
+ $output_html .= '<div>'.__('File type:').' '.$mimetype.'</div>';
861
+ $output_html .= '<div>'.__('File size:').' '.$file_size.'</div>';
862
+ if ( wp_ext2type($ext) === 'image' ) {
863
+ $output_html .= '<div>'.__('Images').': ';
864
+ $thumb_count = 0;
865
+ foreach ( $imagethumburls as $thumbsize => $imagethumburl ) {
866
+ $output_html .= '[<a href="'.$imagethumburl.'" target="_blank" style="text-decoration: none; word-break: break-all;">'.$thumbsize.'</a>]';
867
+ ++$thumb_count;
868
+ $thumbnails[$thumb_count] = $imagethumburl;
869
+ }
870
+ $output_html .= '</div>';
871
+ if ( !empty($exif_text) ) {
872
+ $output_html .= '<div>'.__('Caption').'[Exif]: '.$exif_text.'</div>';
873
+ }
874
+ } else {
875
+ if ( wp_ext2type($ext) === 'video' || wp_ext2type($ext) === 'audio' ) {
876
+ $output_html .= '<div>'.__('Length:').' '.$length.'</div>';
877
+ }
878
+ }
879
+ if ( !empty($cat_html) ) {
880
+ $output_html .= $cat_html;
881
+ }
882
+ $output_html .= '</div></div>';
883
+
884
+ if ( $mediafromftp_settings['log'] ) {
885
+ global $wpdb;
886
+ $user = wp_get_current_user();
887
+ $thumbnail = json_encode($thumbnails);
888
+ $thumbnail = str_replace('\\', '', $thumbnail);
889
+ // Log
890
+ $log_arr = array(
891
+ 'id' => $attach_id,
892
+ 'user' => $user->display_name,
893
+ 'title' => $new_attach_title,
894
+ 'permalink' => get_attachment_link($attach_id),
895
+ 'url' => $new_url_attach,
896
+ 'filename' => end($new_url_attachs),
897
+ 'time' => $stamptime,
898
+ 'filetype' => $mimetype,
899
+ 'filesize' => $file_size,
900
+ 'exif' => $exif_text,
901
+ 'length' => $length,
902
+ 'thumbnail' => $thumbnail,
903
+ 'mlccategories' => $mlccategory,
904
+ 'emlcategories' => $emlcategory,
905
+ 'mlacategories' => $mlacategory,
906
+ 'mlatags' => $mlatag
907
+ );
908
+ $table_name = $wpdb->prefix.'mediafromftp_log';
909
+ $wpdb->insert( $table_name, $log_arr);
910
+ $wpdb->show_errors();
911
+ }
912
+
913
+ return $output_html;
914
+
915
+ }
916
+
917
+ /* ==================================================
918
+ * @param string $base
919
+ * @param string $relationalpath
920
+ * @return string realurl
921
+ * @since 7.7
922
+ */
923
+ function realurl( $base, $relationalpath ){
924
+ $parse = array(
925
+ "scheme" => null,
926
+ "user" => null,
927
+ "pass" => null,
928
+ "host" => null,
929
+ "port" => null,
930
+ "query" => null,
931
+ "fragment" => null
932
+ );
933
+ $parse = parse_url( $base );
934
+
935
+ if( strpos($parse["path"], "/", (strlen($parse["path"])-1)) !== false ){
936
+ $parse["path"] .= ".";
937
+ }
938
+
939
+ if( preg_match("#^https?://#", $relationalpath) ){
940
+ return $relationalpath;
941
+ }else if( preg_match("#^/.*$#", $relationalpath) ){
942
+ return $parse["scheme"] . "://" . $parse["host"] . $relationalpath;
943
+ }else{
944
+ $basePath = explode("/", dirname($parse["path"]));
945
+ $relPath = explode("/", $relationalpath);
946
+ foreach( $relPath as $relDirName ){
947
+ if( $relDirName == "." ){
948
+ array_shift( $basePath );
949
+ array_unshift( $basePath, "" );
950
+ }else if( $relDirName == ".." ){
951
+ array_pop( $basePath );
952
+ if( count($basePath) == 0 ){
953
+ $basePath = array("");
954
+ }
955
+ }else{
956
+ array_push($basePath, $relDirName);
957
+ }
958
+ }
959
+ $path = implode("/", $basePath);
960
+ return $parse["scheme"] . "://" . $parse["host"] . $path;
961
+ }
962
+
963
+ }
964
+
965
+ /* ==================================================
966
+ * @param none
967
+ * @return array $upload_dir, $upload_url, $upload_path
968
+ * @since 7.8
969
+ */
970
+ function upload_dir_url_path(){
971
+
972
+ $wp_uploads = wp_upload_dir();
973
+
974
+ $relation_path_true = strpos($wp_uploads['baseurl'], '../');
975
+ if ( $relation_path_true > 0 ) {
976
+ $relationalpath = substr($wp_uploads['baseurl'], $relation_path_true);
977
+ $basepath = substr($wp_uploads['baseurl'], 0, $relation_path_true);
978
+ $upload_url = $this->realurl($basepath, $relationalpath);
979
+ $upload_dir = wp_normalize_path(realpath($wp_uploads['basedir']));
980
+ } else {
981
+ $upload_url = $wp_uploads['baseurl'];
982
+ $upload_dir = wp_normalize_path($wp_uploads['basedir']);
983
+ }
984
+
985
+ if(is_ssl()){
986
+ $upload_url = str_replace('http:', 'https:', $upload_url);
987
+ }
988
+
989
+ if ( $relation_path_true > 0 ) {
990
+ $upload_path = $relationalpath;
991
+ } else {
992
+ $wordpress_path = wp_normalize_path(ABSPATH);
993
+ $upload_path = str_replace($wordpress_path, '', $upload_dir);
994
+ }
995
+
996
+ $upload_dir = untrailingslashit($upload_dir);
997
+ $upload_url = untrailingslashit($upload_url);
998
+ $upload_path = untrailingslashit($upload_path);
999
+
1000
+ return array($upload_dir, $upload_url, $upload_path);
1001
+
1002
+ }
1003
+
1004
+ /* ==================================================
1005
+ * @param none
1006
+ * @return $siteurl
1007
+ * @since 8.5
1008
+ */
1009
+ function siteurl(){
1010
+ if ( is_multisite() ) {
1011
+ global $blog_id;
1012
+ $siteurl = trailingslashit(get_blog_details($blog_id)->siteurl);
1013
+ } else {
1014
+ $siteurl = site_url('/');
1015
+ }
1016
+ return $siteurl;
1017
+ }
1018
+
1019
+ /* ==================================================
1020
+ * @param string $ext2typefilter
1021
+ * @return array $extensions
1022
+ * @since 8.2
1023
+ */
1024
+ function scan_extensions($ext2typefilter){
1025
+
1026
+ $extensions = array();
1027
+ global $user_ID;
1028
+ $mimes = get_allowed_mime_types($user_ID);
1029
+
1030
+ foreach ($mimes as $extselect => $mime) {
1031
+ if( strpos( $extselect, '|' ) ){
1032
+ $extselects = explode('|',$extselect);
1033
+ foreach ( $extselects as $extselect2 ) {
1034
+ if ( $ext2typefilter === 'all' || $ext2typefilter === wp_ext2type($extselect2) ) {
1035
+ $extensions[] = $extselect2;
1036
+ }
1037
+ }
1038
+ } else {
1039
+ if ( $ext2typefilter === 'all' || $ext2typefilter === wp_ext2type($extselect) ) {
1040
+ $extensions[] = $extselect;
1041
+ }
1042
+ }
1043
+ }
1044
+
1045
+ asort($extensions);
1046
+ return $extensions;
1047
+
1048
+ }
1049
+
1050
+ /* ==================================================
1051
+ * @param string $str
1052
+ * @param string $character_code
1053
+ * @return string $ret
1054
+ * @since 9.02
1055
+ */
1056
+ function utf8mb4_html_numeric_encode($str, $character_code) {
1057
+
1058
+ if ( function_exists('mb_language') && $character_code <> 'none' ) {
1059
+ $length = mb_strlen($str, 'UTF-8');
1060
+ $ret = '';
1061
+
1062
+ for ($i = 0; $i < $length; ++$i) {
1063
+ $buf = mb_substr($str, $i, 1, 'UTF-8');
1064
+
1065
+ if (mb_strlen($buf, '8bit') === 4) {
1066
+ $buf = mb_encode_numericentity($buf, array(0x10000, 0x10FFFF, 0, 0xFFFFFF), 'UTF-8');
1067
+ }
1068
+
1069
+ $ret .= $buf;
1070
+ }
1071
+ } else {
1072
+ $ret = $str;
1073
+ }
1074
+
1075
+ return $ret;
1076
+
1077
+ }
1078
+
1079
+ /* ==================================================
1080
+ * @param string $character_code
1081
+ * @return string none
1082
+ * @since 9.05
1083
+ */
1084
+ function mb_initialize($character_code) {
1085
+
1086
+ if ( function_exists('mb_language') && $character_code <> 'none' ) {
1087
+ if( get_locale() === 'ja' ) {
1088
+ mb_language('Japanese');
1089
+ } else if( get_locale() === 'en_US' ) {
1090
+ mb_language('English');
1091
+ } else {
1092
+ mb_language('uni');
1093
+ }
1094
+ }
1095
+
1096
+ }
1097
+
1098
+ /* ==================================================
1099
+ * @param string $str
1100
+ * @param string $character_code
1101
+ * @return string $str
1102
+ * @since 9.10
1103
+ */
1104
+ function mb_encode_multibyte($str, $character_code) {
1105
+
1106
+ if ( function_exists('mb_language') && $character_code <> 'none' ) {
1107
+ $str = mb_convert_encoding($str, $character_code, "auto");
1108
+ }
1109
+
1110
+ return $str;
1111
+
1112
+ }
1113
+
1114
+ /* ==================================================
1115
+ * @param string $str
1116
+ * @param string $character_code
1117
+ * @return string $str
1118
+ * @since 9.05
1119
+ */
1120
+ function mb_utf8($str, $character_code) {
1121
+
1122
+ if ( function_exists('mb_convert_encoding') && $character_code <> 'none' ) {
1123
+ $str = mb_convert_encoding($str, "UTF-8", "auto");
1124
+ }
1125
+
1126
+ return $str;
1127
+
1128
+ }
1129
+
1130
+ /* ==================================================
1131
+ * for php < 5.3.0
1132
+ * @param array $array
1133
+ * @return array $array
1134
+ * @since 9.11
1135
+ */
1136
+ function array_replace() {
1137
+
1138
+ $array = array();
1139
+ $n = func_num_args();
1140
+
1141
+ while ( $n-- >0 ) {
1142
+ $array+=func_get_arg($n);
1143
+ }
1144
+ return $array;
1145
+ }
1146
+
1147
+
1148
+ /* ==================================================
1149
+ * for Media Library Import
1150
+ * @param string $filename
1151
+ * @return array $authors
1152
+ * @since 9.43
1153
+ */
1154
+ function author_select($filename) {
1155
+
1156
+ $scriptname = admin_url('admin.php?page=mediafromftp-import');
1157
+
1158
+ $s = @file_get_contents($filename);
1159
+ $controlCode = array("\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x0b", "\x0c", "\x0e", "\x0f");
1160
+ $s = str_replace($controlCode, '', $s);
1161
+ $xml = simplexml_load_string($s);
1162
+
1163
+ $authors = array();
1164
+ $namespaces = $xml->getDocNamespaces();
1165
+ foreach ( $xml->xpath('/rss/channel/wp:author') as $author_arr ) {
1166
+ $a = $author_arr->children( $namespaces['wp'] );
1167
+ $authors[] = array(
1168
+ 'author_login' => (string) $a->author_login,
1169
+ 'author_display_name' => (string) $a->author_display_name,
1170
+ );
1171
+ }
1172
+
1173
+
1174
+ $form_select = NULL;
1175
+ $count = 0;
1176
+ if ( current_user_can( 'manage_options' ) ) {
1177
+ $blogusers = get_users();
1178
+ foreach ( $authors as $key => $value) {
1179
+ ++$count;
1180
+ $form_select .= '<div style="display: block; padding: 5px 10px">'.$count.'.'.__('Import author:', 'media-from-ftp').'<strong>'.$value['author_display_name'].'('.$value['author_login'].')'.'</strong></div>';
1181
+ $form_select .= '<div style="display: block; padding: 5px 30px">'.__('Assign posts to an existing user:', 'media-from-ftp').'<select name="'.$value['author_login'].'">';
1182
+ $form_select .= '<option value="-1" select>'.__('Select').'</option>';
1183
+ foreach ( $blogusers as $user ) {
1184
+ $form_select .= '<option value="'.$user->ID.'">'.$user->display_name.'('.$user->user_login.')</option>';
1185
+ }
1186
+ $form_select .= '</select></div>';
1187
+ }
1188
+ $current_user = wp_get_current_user();
1189
+ $current_user_html = '<strong>'.$current_user->display_name.'('.$current_user->user_login.')</strong>';
1190
+ $form_select .= '<div style="display: block; padding: 10px 0px">'.sprintf(__('If not selected, assign posts to %1$s.', 'media-from-ftp'), $current_user_html).'</div>';
1191
+ } else {
1192
+ $user = wp_get_current_user();
1193
+ foreach ( $authors as $key => $value) {
1194
+ ++$count;
1195
+ $form_select .= '<div style="display: block; padding: 5px 10px">'.$count.'.'.__('Import author:', 'media-from-ftp').'<strong>'.$value['author_display_name'].'('.$value['author_login'].')'.'</strong></div>';
1196
+ $current_user_html = '<strong>'.$user->display_name.'('.$user->user_login.')</strong>';
1197
+ $form_select .= '<div style="display: block; padding: 5px 30px">'.sprintf(__('Assign posts to %1$s', 'media-from-ftp'), $current_user_html).'</div>';
1198
+
1199
+ }
1200
+ }
1201
+ $button_value = get_submit_button( __('Apply'), 'large', 'select_author', FALSE );
1202
+ $nonce_field = wp_nonce_field('mff_select_author', 'media_from_ftp_select_author');
1203
+
1204
+ $author_form = <<<MEDIAFROMFTP_AUTHOR_SELECT
1205
+
1206
+ <!-- BEGIN: Media from FTP Media Library Import -->
1207
+ <form method="post" action="$scriptname">
1208
+ $nonce_field
1209
+ $form_select
1210
+ <div style="display: block; padding: 20px 0px">$button_value</div>
1211
+ <input type="hidden" name="mediafromftp_select_author" value="1" />
1212
+ <input type="hidden" name="mediafromftp_xml_file" value="$filename" />
1213
+ </form>
1214
+
1215
+ <!-- END: Media from FTP Media Library Import -->
1216
+
1217
+ MEDIAFROMFTP_AUTHOR_SELECT;
1218
+
1219
+ return $author_form;
1220
+
1221
+ }
1222
+
1223
+ /* ==================================================
1224
+ * for Media Library Import
1225
+ * @param string $filename
1226
+ * @param array $select_author
1227
+ * @return string $add_js
1228
+ * @since 9.40
1229
+ */
1230
+ function make_object($filename, $select_author) {
1231
+
1232
+ $s = @file_get_contents($filename);
1233
+ $controlCode = array("\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x0b", "\x0c", "\x0e", "\x0f");
1234
+ $s = str_replace($controlCode, '', $s);
1235
+ $xml = simplexml_load_string($s);
1236
+ $data = array();
1237
+ foreach ($xml->channel->item as $item) {
1238
+ $x = array();
1239
+ $x['title'] = (string)$item->title;
1240
+ $x['link'] = (string)$item->link;
1241
+ $x['pubDate'] = (string)$item->pubDate;
1242
+ $x['creator'] = (string)$item->children('dc',true)->creator;
1243
+ $x['guid'] = (string)$item->guid;
1244
+ $x['guid_atr'] = (string)$item->guid->attributes()->isPermaLink;
1245
+ $x['description'] = (string)$item->description;
1246
+ $x['content_encoded'] = (string)$item->children('content',true)->encoded;
1247
+ $x['excerpt_encoded'] = (string)$item->children('excerpt',true)->encoded;
1248
+ $x['post_id'] = (int)$item->children('wp',true)->post_id;
1249
+ $x['post_date'] = (string)$item->children('wp',true)->post_date;
1250
+ $x['post_date_gmt'] = (string)$item->children('wp',true)->post_date_gmt;
1251
+ $x['comment_status'] = (string)$item->children('wp',true)->comment_status;
1252
+ $x['ping_status'] = (string)$item->children('wp',true)->ping_status;
1253
+ $x['post_name'] = (string)$item->children('wp',true)->post_name;
1254
+ $x['status'] = (string)$item->children('wp',true)->status;
1255
+ $x['post_parent'] = (int)$item->children('wp',true)->post_parent;
1256
+ $x['menu_order'] = (int)$item->children('wp',true)->menu_order;
1257
+ $x['post_type'] = (string)$item->children('wp',true)->post_type;
1258
+ $x['post_password'] = (string)$item->children('wp',true)->post_password;
1259
+ $x['is_sticky'] = (int)$item->children('wp',true)->is_sticky;
1260
+ $x['attachment_url'] = (string)$item->children('wp',true)->attachment_url;
1261
+
1262
+ $postmeta_count = count($item->children('wp',true)->postmeta);
1263
+ for ($i = 0; $i < $postmeta_count; $i++){
1264
+ $wp_postmeta_node = $item->children('wp',true)->postmeta[$i];
1265
+ $post_meta_key = (string)$wp_postmeta_node->meta_key;
1266
+ $post_meta_value = (string)$wp_postmeta_node->meta_value;
1267
+ if ( $post_meta_key === '_wp_attached_file' ) {
1268
+ $x['postmeta_wp_attached_file'] = $post_meta_key;
1269
+ $x['postmeta_wp_attached_file_value'] = $post_meta_value;
1270
+ } else if ( $post_meta_key === '_thumbnail_id' ) {
1271
+ $x['postmeta_thumbnail_id'] = $post_meta_key;
1272
+ $x['postmeta_thumbnail_id_value'] = $post_meta_value;
1273
+ } else if ( $post_meta_key === '_cover_hash' ) {
1274
+ $x['postmeta_cover_hash'] = $post_meta_key;
1275
+ $x['postmeta_cover_hash_value'] = $post_meta_value;
1276
+ } else if ( $post_meta_key === '_wp_attachment_metadata' ) {
1277
+ $x['postmeta_wp_attachment_metadata'] = $post_meta_key;
1278
+ $x['postmeta_wp_attachment_metadata_value'] = $post_meta_value;
1279
+ } else if ( $post_meta_key === '_wp_attachment_image_alt' ) {
1280
+ $x['postmeta_wp_attachment_image_alt'] = $post_meta_key;
1281
+ $x['postmeta_wp_attachment_image_alt_value'] = $post_meta_value;
1282
+ }
1283
+ }
1284
+
1285
+ $data[] = $x;
1286
+ }
1287
+
1288
+ $count = 0;
1289
+ $file_array = array();
1290
+ $db_array = array();
1291
+ $db_wp_attachment_metadata_array = array();
1292
+ $db_thumbnail_id_array = array();
1293
+ $db_cover_hash_array = array();
1294
+ $db_wp_attachment_image_alt_array = array();
1295
+ foreach ($data as $key => $value) {
1296
+ if ($value['post_type'] === 'attachment') {
1297
+ $file = MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.'/'.$value['postmeta_wp_attached_file_value'];
1298
+ $filetype = wp_check_filetype( basename( $file ), null );
1299
+
1300
+ $user = wp_get_current_user();
1301
+ $loginuser = $user->ID;
1302
+ foreach ( $select_author as $authorkey => $authorvalue ) {
1303
+ if ( $value['creator'] === $authorkey) {
1304
+ $loginuser = $authorvalue;
1305
+ }
1306
+ }
1307
+
1308
+ $db_array[$count] = array(
1309
+ 'ID' => $value['post_id'],
1310
+ 'post_author' => $loginuser,
1311
+ 'post_date' => $value['post_date'],
1312
+ 'post_date_gmt' => $value['post_date_gmt'],
1313
+ 'post_content' => $value['content_encoded'],
1314
+ 'post_title' => $value['title'],
1315
+ 'post_excerpt' => $value['excerpt_encoded'],
1316
+ 'post_status' => $value['status'],
1317
+ 'comment_status' => $value['comment_status'],
1318
+ 'ping_status' => $value['ping_status'],
1319
+ 'post_password' => $value['post_password'],
1320
+ 'post_name' => $value['post_name'],
1321
+ 'post_parent' => $value['post_parent'],
1322
+ 'guid' => $value['guid'],
1323
+ 'menu_order' => $value['menu_order'],
1324
+ 'post_type' => $value['post_type'],
1325
+ 'post_mime_type' => $filetype['type']
1326
+ );
1327
+
1328
+ $file_array[$count] = $file;
1329
+
1330
+ if ( array_key_exists( "postmeta_wp_attachment_metadata_value", $value ) ) {
1331
+ $db_wp_attachment_metadata_array[$count] = json_encode($value['postmeta_wp_attachment_metadata_value']);
1332
+ if ( strrpos($value['postmeta_wp_attached_file_value'], '/') ) {
1333
+ $monthdir = '/'.substr($value['postmeta_wp_attached_file_value'], 0 , strrpos($value['postmeta_wp_attached_file_value'], '/'));
1334
+ $dir = MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.$monthdir;
1335
+ }
1336
+ $thumbnails = maybe_unserialize($value['postmeta_wp_attachment_metadata_value']);
1337
+ if ( is_array($thumbnails) ) {
1338
+ foreach ( $thumbnails as $key1 => $value1 ) {
1339
+ if ( is_array($value1) ) {
1340
+ foreach ( $value1 as $key2 => $value2 ) {
1341
+ if ( is_array($value2) ) {
1342
+ foreach ( $value2 as $key3 => $value3 ) {
1343
+ if ( $key3 === 'file' ) {
1344
+ $thumbnail = $dir.'/'.$value3;
1345
+ ++$count;
1346
+ $file_array[$count] = $thumbnail;
1347
+ }
1348
+ }
1349
+ }
1350
+ }
1351
+ }
1352
+ }
1353
+ }
1354
+ }
1355
+ if ( array_key_exists( "postmeta_thumbnail_id_value", $value ) ) {
1356
+ $db_thumbnail_id_array[$count] = $value['postmeta_thumbnail_id_value'];
1357
+ }
1358
+ if ( array_key_exists( "postmeta_cover_hash_value", $value ) ) {
1359
+ $db_cover_hash_array[$count] = $value['postmeta_cover_hash_value'];
1360
+ }
1361
+ if ( array_key_exists( "postmeta_wp_attachment_image_alt_value", $value ) ) {
1362
+ $db_wp_attachment_image_alt_array[$count] = $value['postmeta_wp_attachment_image_alt_value'];
1363
+ }
1364
+
1365
+ ++$count;
1366
+ }
1367
+ }
1368
+
1369
+ $file_obj = json_encode($file_array);
1370
+ $db_array_obj = json_encode($db_array);
1371
+ $db_wp_attachment_metadata_obj = json_encode($db_wp_attachment_metadata_array);
1372
+ $db_thumbnail_id_obj = json_encode($db_thumbnail_id_array);
1373
+ $db_cover_hash_obj = json_encode($db_cover_hash_array);
1374
+ $db_wp_attachment_image_alt_obj = json_encode($db_wp_attachment_image_alt_array);
1375
+
1376
+ // JS
1377
+ $add_js = <<<MEDIAFROMFTP
1378
+
1379
+ <!-- BEGIN: Media from FTP Media Library Import -->
1380
+ <script type="text/javascript">
1381
+ /* <![CDATA[ */
1382
+ var medialibraryimport_maxcount = $count;
1383
+ var medialibraryimport_file = $file_obj;
1384
+ var medialibraryimport_db_array = $db_array_obj;
1385
+ var medialibraryimport_db_wp_attachment_metadata = $db_wp_attachment_metadata_obj;
1386
+ var medialibraryimport_db_thumbnail_id = $db_thumbnail_id_obj;
1387
+ var medialibraryimport_db_cover_hash = $db_cover_hash_obj;
1388
+ var medialibraryimport_db_wp_attachment_image_alt = $db_wp_attachment_image_alt_obj;
1389
+ /* ]]> */
1390
+ </script>
1391
+ <!-- END: Media from FTP Media Library Import -->
1392
+
1393
+ MEDIAFROMFTP;
1394
+
1395
+ return $add_js;
1396
+
1397
+ }
1398
+
1399
+ }
1400
+
1401
+ ?>
js/jquery.datetimepicker.js ADDED
@@ -0,0 +1,1474 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @preserve jQuery DateTimePicker plugin v2.3.4
3
+ * @homepage http://xdsoft.net/jqplugins/datetimepicker/
4
+ * (c) 2014, Chupurnov Valeriy.
5
+ */
6
+ (function( $ ) {
7
+ 'use strict';
8
+ var default_options = {
9
+ i18n:{
10
+ bg:{ // Bulgarian
11
+ months:[
12
+ "Януари", "Февруари", "Март", "Април", "Май", "Юни", "Юли", "Август", "Септември", "Октомври", "Ноември", "Декември"
13
+ ],
14
+ dayOfWeek:[
15
+ "Нд", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"
16
+ ]
17
+ },
18
+ fa:{ // Persian/Farsi
19
+ months:[
20
+ 'فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند'
21
+ ],
22
+ dayOfWeek:[
23
+ 'یکشنبه', 'دوشنبه', 'سه شنبه', 'چهارشنبه', 'پنجشنبه', 'جمعه', 'شنبه'
24
+ ]
25
+ },
26
+ ru:{ // Russian
27
+ months:[
28
+ 'Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'
29
+ ],
30
+ dayOfWeek:[
31
+ "Вск", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб"
32
+ ]
33
+ },
34
+ uk:{ // Ukrainian
35
+ months:[
36
+ 'Січень','Лютий','Березень','Квітень','Травень','Червень','Липень','Серпень','Вересень','Жовтень','Листопад','Грудень'
37
+ ],
38
+ dayOfWeek:[
39
+ "Ндл", "Пнд", "Втр", "Срд", "Чтв", "Птн", "Сбт"
40
+ ]
41
+ },
42
+ en:{ // English
43
+ months: [
44
+ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
45
+ ],
46
+ dayOfWeek: [
47
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
48
+ ]
49
+ },
50
+ el:{ // Ελληνικά
51
+ months: [
52
+ "Ιανουάριος", "Φεβρουάριος", "Μάρτιος", "Απρίλιος", "Μάιος", "Ιούνιος", "Ιούλιος", "Αύγουστος", "Σεπτέμβριος", "Οκτώβριος", "Νοέμβριος", "Δεκέμβριος"
53
+ ],
54
+ dayOfWeek: [
55
+ "Κυρ", "Δευ", "Τρι", "Τετ", "Πεμ", "Παρ", "Σαβ"
56
+ ]
57
+ },
58
+ de:{ // German
59
+ months:[
60
+ 'Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'
61
+ ],
62
+ dayOfWeek:[
63
+ "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"
64
+ ]
65
+ },
66
+ nl:{ // Dutch
67
+ months:[
68
+ "januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"
69
+ ],
70
+ dayOfWeek:[
71
+ "zo", "ma", "di", "wo", "do", "vr", "za"
72
+ ]
73
+ },
74
+ tr:{ // Turkish
75
+ months:[
76
+ "Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"
77
+ ],
78
+ dayOfWeek:[
79
+ "Paz", "Pts", "Sal", "Çar", "Per", "Cum", "Cts"
80
+ ]
81
+ },
82
+ fr:{ //French
83
+ months:[
84
+ "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"
85
+ ],
86
+ dayOfWeek:[
87
+ "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam"
88
+ ]
89
+ },
90
+ es:{ // Spanish
91
+ months: [
92
+ "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"
93
+ ],
94
+ dayOfWeek: [
95
+ "Dom", "Lun", "Mar", "Mié", "Jue", "Vie", "Sáb"
96
+ ]
97
+ },
98
+ th:{ // Thai
99
+ months:[
100
+ 'มกราคม','กุมภาพันธ์','มีนาคม','เมษายน','พฤษภาคม','มิถุนายน','กรกฎาคม','สิงหาคม','กันยายน','ตุลาคม','พฤศจิกายน','ธันวาคม'
101
+ ],
102
+ dayOfWeek:[
103
+ 'อา.','จ.','อ.','พ.','พฤ.','ศ.','ส.'
104
+ ]
105
+ },
106
+ pl:{ // Polish
107
+ months: [
108
+ "styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec", "lipiec", "sierpień", "wrzesień", "październik", "listopad", "grudzień"
109
+ ],
110
+ dayOfWeek: [
111
+ "nd", "pn", "wt", "śr", "cz", "pt", "sb"
112
+ ]
113
+ },
114
+ pt:{ // Portuguese
115
+ months: [
116
+ "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"
117
+ ],
118
+ dayOfWeek: [
119
+ "Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sab"
120
+ ]
121
+ },
122
+ ch:{ // Simplified Chinese
123
+ months: [
124
+ "一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"
125
+ ],
126
+ dayOfWeek: [
127
+ "日", "一","二","三","四","五","六"
128
+ ]
129
+ },
130
+ se:{ // Swedish
131
+ months: [
132
+ "Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September","Oktober", "November", "December"
133
+ ],
134
+ dayOfWeek: [
135
+ "Sön", "Mån", "Tis", "Ons", "Tor", "Fre", "Lör"
136
+ ]
137
+ },
138
+ kr:{ // Korean
139
+ months: [
140
+ "1월", "2월", "3월", "4월", "5월", "6월", "7월", "8월", "9월", "10월", "11월", "12월"
141
+ ],
142
+ dayOfWeek: [
143
+ "일", "월", "화", "수", "목", "금", "토"
144
+ ]
145
+ },
146
+ it:{ // Italian
147
+ months: [
148
+ "Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"
149
+ ],
150
+ dayOfWeek: [
151
+ "Dom", "Lun", "Mar", "Mer", "Gio", "Ven", "Sab"
152
+ ]
153
+ },
154
+ da:{ // Dansk
155
+ months: [
156
+ "January", "Februar", "Marts", "April", "Maj", "Juni", "July", "August", "September", "Oktober", "November", "December"
157
+ ],
158
+ dayOfWeek: [
159
+ "Søn", "Man", "Tir", "Ons", "Tor", "Fre", "Lør"
160
+ ]
161
+ },
162
+ no:{ // Norwegian
163
+ months: [
164
+ "Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Desember"
165
+ ],
166
+ dayOfWeek: [
167
+ "Søn", "Man", "Tir", "Ons", "Tor", "Fre", "Lør"
168
+ ]
169
+ },
170
+ ja:{ // Japanese
171
+ months: [
172
+ "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"
173
+ ],
174
+ dayOfWeek: [
175
+ "日", "月", "火", "水", "木", "金", "土"
176
+ ]
177
+ },
178
+ vi:{ // Vietnamese
179
+ months: [
180
+ "Tháng 1", "Tháng 2", "Tháng 3", "Tháng 4", "Tháng 5", "Tháng 6", "Tháng 7", "Tháng 8", "Tháng 9", "Tháng 10", "Tháng 11", "Tháng 12"
181
+ ],
182
+ dayOfWeek: [
183
+ "CN", "T2", "T3", "T4", "T5", "T6", "T7"
184
+ ]
185
+ },
186
+ sl:{ // Slovenščina
187
+ months: [
188
+ "Januar", "Februar", "Marec", "April", "Maj", "Junij", "Julij", "Avgust", "September", "Oktober", "November", "December"
189
+ ],
190
+ dayOfWeek: [
191
+ "Ned", "Pon", "Tor", "Sre", "Čet", "Pet", "Sob"
192
+ ]
193
+ },
194
+ cs:{ // Čeština
195
+ months: [
196
+ "Leden", "Únor", "Březen", "Duben", "Květen", "Červen", "Červenec", "Srpen", "Září", "Říjen", "Listopad", "Prosinec"
197
+ ],
198
+ dayOfWeek: [
199
+ "Ne", "Po", "Út", "St", "Čt", "Pá", "So"
200
+ ]
201
+ },
202
+ hu:{ // Hungarian
203
+ months: [
204
+ "Január", "Február", "Március", "Április", "Május", "Június", "Július", "Augusztus", "Szeptember", "Október", "November", "December"
205
+ ],
206
+ dayOfWeek: [
207
+ "Va", "Hé", "Ke", "Sze", "Cs", "Pé", "Szo"
208
+ ]
209
+ }
210
+ },
211
+ value:'',
212
+ lang:'en',
213
+
214
+ format: 'Y/m/d H:i',
215
+ formatTime: 'H:i',
216
+ formatDate: 'Y/m/d',
217
+
218
+ startDate: false, // new Date(), '1986/12/08', '-1970/01/05','-1970/01/05',
219
+
220
+ step:60,
221
+ monthChangeSpinner:true,
222
+ closeOnDateSelect:false,
223
+ closeOnWithoutClick:true,
224
+ closeOnInputClick: true,
225
+
226
+ timepicker:true,
227
+ datepicker:true,
228
+ weeks:false,
229
+
230
+ defaultTime:false, // use formatTime format (ex. '10:00' for formatTime: 'H:i')
231
+ defaultDate:false, // use formatDate format (ex new Date() or '1986/12/08' or '-1970/01/05' or '-1970/01/05')
232
+
233
+ minDate:false,
234
+ maxDate:false,
235
+ minTime:false,
236
+ maxTime:false,
237
+
238
+ allowTimes:[],
239
+ opened:false,
240
+ initTime:true,
241
+ inline:false,
242
+
243
+ onSelectDate:function() {},
244
+ onSelectTime:function() {},
245
+ onChangeMonth:function() {},
246
+ onChangeDateTime:function() {},
247
+ onShow:function() {},
248
+ onClose:function() {},
249
+ onGenerate:function() {},
250
+
251
+ withoutCopyright:true,
252
+
253
+ inverseButton:false,
254
+ hours12:false,
255
+ next: 'xdsoft_next',
256
+ prev : 'xdsoft_prev',
257
+ dayOfWeekStart:0,
258
+
259
+ timeHeightInTimePicker:25,
260
+ timepickerScrollbar:true,
261
+
262
+ todayButton:true, // 2.1.0
263
+ defaultSelect:true, // 2.1.0
264
+
265
+ scrollMonth:true,
266
+ scrollTime:true,
267
+ scrollInput:true,
268
+
269
+ lazyInit:false,
270
+
271
+ mask:false,
272
+ validateOnBlur:true,
273
+ allowBlank:true,
274
+
275
+ yearStart:1950,
276
+ yearEnd:2050,
277
+
278
+ style:'',
279
+ id:'',
280
+
281
+ fixed: false,
282
+
283
+ roundTime:'round', // ceil, floor
284
+ className:'',
285
+
286
+ weekends : [],
287
+ yearOffset:0,
288
+ beforeShowDay: null
289
+ };
290
+
291
+ // fix for ie8
292
+ if ( !Array.prototype.indexOf ) {
293
+ Array.prototype.indexOf = function(obj, start) {
294
+ for (var i = (start || 0), j = this.length; i < j; i++) {
295
+ if (this[i] === obj) { return i; }
296
+ }
297
+ return -1;
298
+ }
299
+ }
300
+
301
+ Date.prototype.countDaysInMonth = function(){
302
+ return new Date(this.getFullYear(), this.getMonth()+1, 0).getDate();
303
+ };
304
+
305
+ $.fn.xdsoftScroller = function( _percent ) {
306
+ return this.each(function() {
307
+ var timeboxparent = $(this);
308
+ if( !$(this).hasClass('xdsoft_scroller_box') ) {
309
+ var pointerEventToXY = function( e ) {
310
+ var out = {x:0, y:0};
311
+ if( e.type == 'touchstart' || e.type == 'touchmove' || e.type == 'touchend' || e.type == 'touchcancel' ) {
312
+ var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
313
+ out.x = touch.pageX;
314
+ out.y = touch.pageY;
315
+ }else if (e.type == 'mousedown' || e.type == 'mouseup' || e.type == 'mousemove' || e.type == 'mouseover'|| e.type=='mouseout' || e.type=='mouseenter' || e.type=='mouseleave') {
316
+ out.x = e.pageX;
317
+ out.y = e.pageY;
318
+ }
319
+ return out;
320
+ },
321
+ move = 0,
322
+ timebox = timeboxparent.children().eq(0),
323
+ parentHeight = timeboxparent[0].clientHeight,
324
+ height = timebox[0].offsetHeight,
325
+ scrollbar = $('<div class="xdsoft_scrollbar"></div>'),
326
+ scroller = $('<div class="xdsoft_scroller"></div>'),
327
+ maximumOffset = 100,
328
+ start = false;
329
+
330
+ scrollbar.append(scroller);
331
+
332
+ timeboxparent.addClass('xdsoft_scroller_box').append(scrollbar);
333
+ scroller.on('mousedown.xdsoft_scroller',function ( event ) {
334
+ if( !parentHeight )
335
+ timeboxparent.trigger('resize_scroll.xdsoft_scroller',[_percent]);
336
+ var pageY = event.pageY,
337
+ top = parseInt(scroller.css('margin-top')),
338
+ h1 = scrollbar[0].offsetHeight;
339
+ $(document.body).addClass('xdsoft_noselect');
340
+ $([document.body,window]).on('mouseup.xdsoft_scroller',function arguments_callee() {
341
+ $([document.body,window]).off('mouseup.xdsoft_scroller',arguments_callee)
342
+ .off('mousemove.xdsoft_scroller',move)
343
+ .removeClass('xdsoft_noselect');
344
+ });
345
+ $(document.body).on('mousemove.xdsoft_scroller',move = function(event) {
346
+ var offset = event.pageY-pageY+top;
347
+ if( offset<0 )
348
+ offset = 0;
349
+ if( offset+scroller[0].offsetHeight>h1 )
350
+ offset = h1-scroller[0].offsetHeight;
351
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[maximumOffset?offset/maximumOffset:0]);
352
+ });
353
+ });
354
+
355
+ timeboxparent
356
+ .on('scroll_element.xdsoft_scroller',function( event,percent ) {
357
+ if( !parentHeight )
358
+ timeboxparent.trigger('resize_scroll.xdsoft_scroller',[percent,true]);
359
+ percent = percent>1?1:(percent<0||isNaN(percent))?0:percent;
360
+ scroller.css('margin-top',maximumOffset*percent);
361
+ timebox.css('marginTop',-parseInt((height-parentHeight)*percent))
362
+ })
363
+ .on('resize_scroll.xdsoft_scroller',function( event,_percent,noTriggerScroll ) {
364
+ parentHeight = timeboxparent[0].clientHeight;
365
+ height = timebox[0].offsetHeight;
366
+ var percent = parentHeight/height,
367
+ sh = percent*scrollbar[0].offsetHeight;
368
+ if( percent>1 )
369
+ scroller.hide();
370
+ else{
371
+ scroller.show();
372
+ scroller.css('height',parseInt(sh>10?sh:10));
373
+ maximumOffset = scrollbar[0].offsetHeight-scroller[0].offsetHeight;
374
+ if( noTriggerScroll!==true )
375
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[_percent?_percent:Math.abs(parseInt(timebox.css('marginTop')))/(height-parentHeight)]);
376
+ }
377
+ });
378
+ timeboxparent.mousewheel&&timeboxparent.mousewheel(function(event, delta, deltaX, deltaY) {
379
+ var top = Math.abs(parseInt(timebox.css('marginTop')));
380
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[(top-delta*20)/(height-parentHeight)]);
381
+ event.stopPropagation();
382
+ return false;
383
+ });
384
+ timeboxparent.on('touchstart',function( event ) {
385
+ start = pointerEventToXY(event);
386
+ });
387
+ timeboxparent.on('touchmove',function( event ) {
388
+ if( start ) {
389
+ var coord = pointerEventToXY(event), top = Math.abs(parseInt(timebox.css('marginTop')));
390
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[(top-(coord.y-start.y))/(height-parentHeight)]);
391
+ event.stopPropagation();
392
+ event.preventDefault();
393
+ start = pointerEventToXY(event);
394
+ }
395
+ });
396
+ timeboxparent.on('touchend touchcancel',function( event ) {
397
+ start = false;
398
+ });
399
+ }
400
+ timeboxparent.trigger('resize_scroll.xdsoft_scroller',[_percent]);
401
+ });
402
+ };
403
+ $.fn.datetimepicker = function( opt ) {
404
+ var KEY0 = 48,
405
+ KEY9 = 57,
406
+ _KEY0 = 96,
407
+ _KEY9 = 105,
408
+ CTRLKEY = 17,
409
+ DEL = 46,
410
+ ENTER = 13,
411
+ ESC = 27,
412
+ BACKSPACE = 8,
413
+ ARROWLEFT = 37,
414
+ ARROWUP = 38,
415
+ ARROWRIGHT = 39,
416
+ ARROWDOWN = 40,
417
+ TAB = 9,
418
+ F5 = 116,
419
+ AKEY = 65,
420
+ CKEY = 67,
421
+ VKEY = 86,
422
+ ZKEY = 90,
423
+ YKEY = 89,
424
+ ctrlDown = false,
425
+ options = ($.isPlainObject(opt)||!opt)?$.extend(true,{},default_options,opt):$.extend({},default_options),
426
+
427
+ lazyInitTimer = 0,
428
+
429
+ lazyInit = function( input ){
430
+ input
431
+ .on('open.xdsoft focusin.xdsoft mousedown.xdsoft',function initOnActionCallback(event) {
432
+ if( input.is(':disabled')||input.is(':hidden')||!input.is(':visible')||input.data( 'xdsoft_datetimepicker') )
433
+ return;
434
+
435
+ clearTimeout(lazyInitTimer);
436
+
437
+ lazyInitTimer = setTimeout(function() {
438
+
439
+ if( !input.data( 'xdsoft_datetimepicker') )
440
+ createDateTimePicker(input);
441
+
442
+ input
443
+ .off('open.xdsoft focusin.xdsoft mousedown.xdsoft',initOnActionCallback)
444
+ .trigger('open.xdsoft');
445
+ },100);
446
+
447
+ });
448
+ },
449
+
450
+ createDateTimePicker = function( input ) {
451
+
452
+ var datetimepicker = $('<div '+(options.id?'id="'+options.id+'"':'')+' '+(options.style?'style="'+options.style+'"':'')+' class="xdsoft_datetimepicker xdsoft_noselect '+(options.weeks?' xdsoft_showweeks':'')+options.className+'"></div>'),
453
+ xdsoft_copyright = $('<div class="xdsoft_copyright"><a target="_blank" href="http://xdsoft.net/jqplugins/datetimepicker/">xdsoft.net</a></div>'),
454
+ datepicker = $('<div class="xdsoft_datepicker active"></div>'),
455
+ mounth_picker = $('<div class="xdsoft_mounthpicker"><button type="button" class="xdsoft_prev"></button><button type="button" class="xdsoft_today_button"></button><div class="xdsoft_label xdsoft_month"><span></span></div><div class="xdsoft_label xdsoft_year"><span></span></div><button type="button" class="xdsoft_next"></button></div>'),
456
+ calendar = $('<div class="xdsoft_calendar"></div>'),
457
+ timepicker = $('<div class="xdsoft_timepicker active"><button type="button" class="xdsoft_prev"></button><div class="xdsoft_time_box"></div><button type="button" class="xdsoft_next"></button></div>'),
458
+ timeboxparent = timepicker.find('.xdsoft_time_box').eq(0),
459
+ timebox = $('<div class="xdsoft_time_variant"></div>'),
460
+ scrollbar = $('<div class="xdsoft_scrollbar"></div>'),
461
+ scroller = $('<div class="xdsoft_scroller"></div>'),
462
+ monthselect =$('<div class="xdsoft_select xdsoft_monthselect"><div></div></div>'),
463
+ yearselect =$('<div class="xdsoft_select xdsoft_yearselect"><div></div></div>');
464
+
465
+ //constructor lego
466
+ mounth_picker
467
+ .find('.xdsoft_month span')
468
+ .after(monthselect);
469
+ mounth_picker
470
+ .find('.xdsoft_year span')
471
+ .after(yearselect);
472
+
473
+ mounth_picker
474
+ .find('.xdsoft_month,.xdsoft_year')
475
+ .on('mousedown.xdsoft',function(event) {
476
+ mounth_picker
477
+ .find('.xdsoft_select')
478
+ .hide();
479
+
480
+ var select = $(this).find('.xdsoft_select').eq(0),
481
+ val = 0,
482
+ top = 0;
483
+
484
+ if( _xdsoft_datetime.currentTime )
485
+ val = _xdsoft_datetime.currentTime[$(this).hasClass('xdsoft_month')?'getMonth':'getFullYear']();
486
+
487
+ select.show();
488
+
489
+ for(var items = select.find('div.xdsoft_option'),i = 0;i<items.length;i++) {
490
+ if( items.eq(i).data('value')==val ) {
491
+ break;
492
+ }else top+=items[0].offsetHeight;
493
+ }
494
+
495
+ select.xdsoftScroller(top/(select.children()[0].offsetHeight-(select[0].clientHeight)));
496
+ event.stopPropagation();
497
+
498
+ return false;
499
+ });
500
+
501
+ mounth_picker
502
+ .find('.xdsoft_select')
503
+ .xdsoftScroller()
504
+ .on('mousedown.xdsoft',function( event ) {
505
+ event.stopPropagation();
506
+ event.preventDefault();
507
+ })
508
+ .on('mousedown.xdsoft','.xdsoft_option',function( event ) {
509
+ if( _xdsoft_datetime&&_xdsoft_datetime.currentTime )
510
+ _xdsoft_datetime.currentTime[$(this).parent().parent().hasClass('xdsoft_monthselect')?'setMonth':'setFullYear']($(this).data('value'));
511
+
512
+ $(this).parent().parent().hide();
513
+
514
+ datetimepicker.trigger('xchange.xdsoft');
515
+ options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
516
+ });
517
+
518
+
519
+ // set options
520
+ datetimepicker.setOptions = function( _options ) {
521
+ options = $.extend(true,{},options,_options);
522
+
523
+ if( _options.allowTimes && $.isArray(_options.allowTimes) && _options.allowTimes.length ){
524
+ options['allowTimes'] = $.extend(true,[],_options.allowTimes);
525
+ }
526
+
527
+ if( _options.weekends && $.isArray(_options.weekends) && _options.weekends.length ){
528
+ options['weekends'] = $.extend(true,[],_options.weekends);
529
+ }
530
+
531
+ if( (options.open||options.opened)&&(!options.inline) ) {
532
+ input.trigger('open.xdsoft');
533
+ }
534
+
535
+ if( options.inline ) {
536
+ triggerAfterOpen = true;
537
+ datetimepicker.addClass('xdsoft_inline');
538
+ input.after(datetimepicker).hide();
539
+ }
540
+
541
+ if( options.inverseButton ) {
542
+ options.next = 'xdsoft_prev';
543
+ options.prev = 'xdsoft_next';
544
+ }
545
+
546
+ if( options.datepicker )
547
+ datepicker.addClass('active');
548
+ else
549
+ datepicker.removeClass('active');
550
+
551
+ if( options.timepicker )
552
+ timepicker.addClass('active');
553
+ else
554
+ timepicker.removeClass('active');
555
+
556
+ if( options.value ){
557
+ input&&input.val&&input.val(options.value);
558
+ _xdsoft_datetime.setCurrentTime(options.value);
559
+ }
560
+
561
+ if( isNaN(options.dayOfWeekStart) )
562
+ options.dayOfWeekStart = 0;
563
+ else
564
+ options.dayOfWeekStart = parseInt(options.dayOfWeekStart)%7;
565
+
566
+ if( !options.timepickerScrollbar )
567
+ scrollbar.hide();
568
+
569
+ if( options.minDate && /^-(.*)$/.test(options.minDate) ){
570
+ options.minDate = _xdsoft_datetime.strToDateTime(options.minDate).dateFormat( options.formatDate );
571
+ }
572
+
573
+ if( options.maxDate && /^\+(.*)$/.test(options.maxDate) ) {
574
+ options.maxDate = _xdsoft_datetime.strToDateTime(options.maxDate).dateFormat( options.formatDate );
575
+ }
576
+
577
+ mounth_picker
578
+ .find('.xdsoft_today_button')
579
+ .css('visibility',!options.todayButton?'hidden':'visible');
580
+
581
+ if( options.mask ) {
582
+ var e,
583
+ getCaretPos = function ( input ) {
584
+ try{
585
+ if ( document.selection && document.selection.createRange ) {
586
+ var range = document.selection.createRange();
587
+ return range.getBookmark().charCodeAt(2) - 2;
588
+ }else
589
+ if ( input.setSelectionRange )
590
+ return input.selectionStart;
591
+ }catch(e) {
592
+ return 0;
593
+ }
594
+ },
595
+ setCaretPos = function ( node,pos ) {
596
+ node = (typeof node == "string" || node instanceof String) ? document.getElementById(node) : node;
597
+ if(!node) {
598
+ return false;
599
+ }else if(node.createTextRange) {
600
+ var textRange = node.createTextRange();
601
+ textRange.collapse(true);
602
+ textRange.moveEnd(pos);
603
+ textRange.moveStart(pos);
604
+ textRange.select();
605
+ return true;
606
+ }else if(node.setSelectionRange) {
607
+ node.setSelectionRange(pos,pos);
608
+ return true;
609
+ }
610
+ return false;
611
+ },
612
+ isValidValue = function ( mask,value ) {
613
+ var reg = mask
614
+ .replace(/([\[\]\/\{\}\(\)\-\.\+]{1})/g,'\\$1')
615
+ .replace(/_/g,'{digit+}')
616
+ .replace(/([0-9]{1})/g,'{digit$1}')
617
+ .replace(/\{digit([0-9]{1})\}/g,'[0-$1_]{1}')
618
+ .replace(/\{digit[\+]\}/g,'[0-9_]{1}');
619
+ return RegExp(reg).test(value);
620
+ };
621
+ input.off('keydown.xdsoft');
622
+ switch(true) {
623
+ case ( options.mask===true ):
624
+
625
+ options.mask = options.format
626
+ .replace(/Y/g,'9999')
627
+ .replace(/F/g,'9999')
628
+ .replace(/m/g,'19')
629
+ .replace(/d/g,'39')
630
+ .replace(/H/g,'29')
631
+ .replace(/i/g,'59')
632
+ .replace(/s/g,'59');
633
+
634
+ case ( $.type(options.mask) == 'string' ):
635
+
636
+ if( !isValidValue( options.mask,input.val() ) )
637
+ input.val(options.mask.replace(/[0-9]/g,'_'));
638
+
639
+ input.on('keydown.xdsoft',function( event ) {
640
+ var val = this.value,
641
+ key = event.which;
642
+
643
+ switch(true) {
644
+ case (( key>=KEY0&&key<=KEY9 )||( key>=_KEY0&&key<=_KEY9 ))||(key==BACKSPACE||key==DEL):
645
+ var pos = getCaretPos(this),
646
+ digit = ( key!=BACKSPACE&&key!=DEL )?String.fromCharCode((_KEY0 <= key && key <= _KEY9)? key-KEY0 : key):'_';
647
+
648
+ if( (key==BACKSPACE||key==DEL)&&pos ) {
649
+ pos--;
650
+ digit='_';
651
+ }
652
+
653
+ while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos<options.mask.length&&pos>0 )
654
+ pos+=( key==BACKSPACE||key==DEL )?-1:1;
655
+
656
+ val = val.substr(0,pos)+digit+val.substr(pos+1);
657
+ if( $.trim(val)=='' ){
658
+ val = options.mask.replace(/[0-9]/g,'_');
659
+ }else{
660
+ if( pos==options.mask.length )
661
+ break;
662
+ }
663
+
664
+ pos+=(key==BACKSPACE||key==DEL)?0:1;
665
+ while( /[^0-9_]/.test(options.mask.substr(pos,1))&&pos<options.mask.length&&pos>0 )
666
+ pos+=(key==BACKSPACE||key==DEL)?-1:1;
667
+
668
+ if( isValidValue( options.mask,val ) ) {
669
+ this.value = val;
670
+ setCaretPos(this,pos);
671
+ }else if( $.trim(val)=='' )
672
+ this.value = options.mask.replace(/[0-9]/g,'_');
673
+ else{
674
+ input.trigger('error_input.xdsoft');
675
+ }
676
+ break;
677
+ case ( !!~([AKEY,CKEY,VKEY,ZKEY,YKEY].indexOf(key))&&ctrlDown ):
678
+ case !!~([ESC,ARROWUP,ARROWDOWN,ARROWLEFT,ARROWRIGHT,F5,CTRLKEY,TAB,ENTER].indexOf(key)):
679
+ return true;
680
+ }
681
+ event.preventDefault();
682
+ return false;
683
+ });
684
+ break;
685
+ }
686
+ }
687
+ if( options.validateOnBlur ) {
688
+ input
689
+ .off('blur.xdsoft')
690
+ .on('blur.xdsoft', function() {
691
+ if( options.allowBlank && !$.trim($(this).val()).length ) {
692
+ $(this).val(null);
693
+ datetimepicker.data('xdsoft_datetime').empty();
694
+ }else if( !Date.parseDate( $(this).val(), options.format ) ) {
695
+ $(this).val((_xdsoft_datetime.now()).dateFormat( options.format ));
696
+ datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
697
+ }
698
+ else{
699
+ datetimepicker.data('xdsoft_datetime').setCurrentTime($(this).val());
700
+ }
701
+ datetimepicker.trigger('changedatetime.xdsoft');
702
+ });
703
+ }
704
+ options.dayOfWeekStartPrev = (options.dayOfWeekStart==0)?6:options.dayOfWeekStart-1;
705
+
706
+ datetimepicker
707
+ .trigger('xchange.xdsoft')
708
+ .trigger('afterOpen.xdsoft')
709
+ };
710
+
711
+ datetimepicker
712
+ .data('options',options)
713
+ .on('mousedown.xdsoft',function( event ) {
714
+ event.stopPropagation();
715
+ event.preventDefault();
716
+ yearselect.hide();
717
+ monthselect.hide();
718
+ return false;
719
+ });
720
+
721
+ var scroll_element = timepicker.find('.xdsoft_time_box');
722
+ scroll_element.append(timebox);
723
+ scroll_element.xdsoftScroller();
724
+
725
+ datetimepicker.on('afterOpen.xdsoft',function() {
726
+ scroll_element.xdsoftScroller();
727
+ });
728
+
729
+ datetimepicker
730
+ .append(datepicker)
731
+ .append(timepicker);
732
+
733
+ if( options.withoutCopyright!==true )
734
+ datetimepicker
735
+ .append(xdsoft_copyright);
736
+
737
+ datepicker
738
+ .append(mounth_picker)
739
+ .append(calendar);
740
+
741
+ $('body').append(datetimepicker);
742
+
743
+ var _xdsoft_datetime = new function() {
744
+ var _this = this;
745
+ _this.now = function( norecursion ) {
746
+ var d = new Date();
747
+
748
+ if( !norecursion && options.defaultDate ){
749
+ var date = _this.strToDate(options.defaultDate);
750
+ d.setFullYear( date.getFullYear() );
751
+ d.setMonth( date.getMonth() );
752
+ d.setDate( date.getDate() );
753
+ }
754
+
755
+ if( options.yearOffset ){
756
+ d.setFullYear(d.getFullYear()+options.yearOffset);
757
+ }
758
+
759
+ if( !norecursion && options.defaultTime ){
760
+ var time = _this.strtotime(options.defaultTime);
761
+ d.setHours( time.getHours() );
762
+ d.setMinutes( time.getMinutes() );
763
+ }
764
+
765
+ return d;
766
+ };
767
+
768
+
769
+ _this.isValidDate = function (d) {
770
+ if ( Object.prototype.toString.call(d) !== "[object Date]" )
771
+ return false;
772
+ return !isNaN(d.getTime());
773
+ };
774
+
775
+ _this.setCurrentTime = function( dTime ) {
776
+ _this.currentTime = (typeof dTime == 'string')? _this.strToDateTime(dTime) : _this.isValidDate(dTime) ? dTime: _this.now();
777
+ datetimepicker.trigger('xchange.xdsoft');
778
+ };
779
+
780
+ _this.empty = function() {
781
+ _this.currentTime = null;
782
+ };
783
+
784
+ _this.getCurrentTime = function( dTime) {
785
+ return _this.currentTime;
786
+ };
787
+
788
+ _this.nextMonth = function() {
789
+ var month = _this.currentTime.getMonth()+1;
790
+ if( month==12 ) {
791
+ _this.currentTime.setFullYear(_this.currentTime.getFullYear()+1);
792
+ month = 0;
793
+ }
794
+ _this.currentTime.setDate(
795
+ Math.min(
796
+ Date.daysInMonth[month],
797
+ _this.currentTime.getDate()
798
+ )
799
+ );
800
+ _this.currentTime.setMonth(month);
801
+ options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
802
+ datetimepicker.trigger('xchange.xdsoft');
803
+ return month;
804
+ };
805
+
806
+ _this.prevMonth = function() {
807
+ var month = _this.currentTime.getMonth()-1;
808
+ if( month==-1 ) {
809
+ _this.currentTime.setFullYear(_this.currentTime.getFullYear()-1);
810
+ month = 11;
811
+ }
812
+ _this.currentTime.setDate(
813
+ Math.min(
814
+ Date.daysInMonth[month],
815
+ _this.currentTime.getDate()
816
+ )
817
+ );
818
+ _this.currentTime.setMonth(month);
819
+ options.onChangeMonth&&options.onChangeMonth.call&&options.onChangeMonth.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
820
+ datetimepicker.trigger('xchange.xdsoft');
821
+ return month;
822
+ };
823
+
824
+ _this.strToDateTime = function( sDateTime ) {
825
+ if( sDateTime && sDateTime instanceof Date && _this.isValidDate(sDateTime) )
826
+ return sDateTime;
827
+
828
+ var tmpDate = [],timeOffset,currentTime;
829
+
830
+ if( ( tmpDate = /^(\+|\-)(.*)$/.exec(sDateTime) ) && ( tmpDate[2]=Date.parseDate(tmpDate[2], options.formatDate) ) ) {
831
+ timeOffset = tmpDate[2].getTime()-(tmpDate[2].getTimezoneOffset())*60000;
832
+ currentTime = new Date((_xdsoft_datetime.now()).getTime()+parseInt(tmpDate[1]+'1')*timeOffset);
833
+ }else
834
+ currentTime = sDateTime?Date.parseDate(sDateTime, options.format):_this.now();
835
+
836
+ if( !_this.isValidDate(currentTime) )
837
+ currentTime = _this.now();
838
+
839
+ return currentTime;
840
+ };
841
+
842
+ _this.strToDate = function( sDate ) {
843
+ if( sDate && sDate instanceof Date && _this.isValidDate(sDate) )
844
+ return sDate;
845
+
846
+ var currentTime = sDate?Date.parseDate(sDate, options.formatDate):_this.now(true);
847
+ if( !_this.isValidDate(currentTime) )
848
+ currentTime = _this.now(true);
849
+
850
+ return currentTime;
851
+ };
852
+
853
+ _this.strtotime = function( sTime ) {
854
+ if( sTime && sTime instanceof Date && _this.isValidDate(sTime) )
855
+ return sTime;
856
+
857
+ var currentTime = sTime?Date.parseDate(sTime, options.formatTime):_this.now();
858
+ if( !_this.isValidDate(currentTime) )
859
+ currentTime = _this.now(true);
860
+
861
+ return currentTime;
862
+ };
863
+
864
+ _this.str = function() {
865
+ return _this.currentTime.dateFormat(options.format);
866
+ };
867
+
868
+ _this.currentTime = this.now();
869
+ };
870
+ mounth_picker
871
+ .find('.xdsoft_today_button')
872
+ .on('mousedown.xdsoft',function() {
873
+ datetimepicker.data('changed',true);
874
+ _xdsoft_datetime.setCurrentTime(0);
875
+ datetimepicker.trigger('afterOpen.xdsoft');
876
+ }).on('dblclick.xdsoft',function(){
877
+ input.val( _xdsoft_datetime.str() );
878
+ datetimepicker.trigger('close.xdsoft');
879
+ });
880
+ mounth_picker
881
+ .find('.xdsoft_prev,.xdsoft_next')
882
+ .on('mousedown.xdsoft',function() {
883
+ var $this = $(this),
884
+ timer = 0,
885
+ stop = false;
886
+
887
+ (function arguments_callee1(v) {
888
+ var month = _xdsoft_datetime.currentTime.getMonth();
889
+ if( $this.hasClass( options.next ) ) {
890
+ _xdsoft_datetime.nextMonth();
891
+ }else if( $this.hasClass( options.prev ) ) {
892
+ _xdsoft_datetime.prevMonth();
893
+ }
894
+ if (options.monthChangeSpinner) {
895
+ !stop&&(timer = setTimeout(arguments_callee1,v?v:100));
896
+ }
897
+ })(500);
898
+
899
+ $([document.body,window]).on('mouseup.xdsoft',function arguments_callee2() {
900
+ clearTimeout(timer);
901
+ stop = true;
902
+ $([document.body,window]).off('mouseup.xdsoft',arguments_callee2);
903
+ });
904
+ });
905
+
906
+ timepicker
907
+ .find('.xdsoft_prev,.xdsoft_next')
908
+ .on('mousedown.xdsoft',function() {
909
+ var $this = $(this),
910
+ timer = 0,
911
+ stop = false,
912
+ period = 110;
913
+ (function arguments_callee4(v) {
914
+ var pheight = timeboxparent[0].clientHeight,
915
+ height = timebox[0].offsetHeight,
916
+ top = Math.abs(parseInt(timebox.css('marginTop')));
917
+ if( $this.hasClass(options.next) && (height-pheight)- options.timeHeightInTimePicker>=top ) {
918
+ timebox.css('marginTop','-'+(top+options.timeHeightInTimePicker)+'px')
919
+ }else if( $this.hasClass(options.prev) && top-options.timeHeightInTimePicker>=0 ) {
920
+ timebox.css('marginTop','-'+(top-options.timeHeightInTimePicker)+'px')
921
+ }
922
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[Math.abs(parseInt(timebox.css('marginTop'))/(height-pheight))]);
923
+ period= ( period>10 )?10:period-10;
924
+ !stop&&(timer = setTimeout(arguments_callee4,v?v:period));
925
+ })(500);
926
+ $([document.body,window]).on('mouseup.xdsoft',function arguments_callee5() {
927
+ clearTimeout(timer);
928
+ stop = true;
929
+ $([document.body,window])
930
+ .off('mouseup.xdsoft',arguments_callee5);
931
+ });
932
+ });
933
+
934
+ var xchangeTimer = 0;
935
+ // base handler - generating a calendar and timepicker
936
+ datetimepicker
937
+ .on('xchange.xdsoft',function( event ) {
938
+ clearTimeout(xchangeTimer);
939
+ xchangeTimer = setTimeout(function(){
940
+ var table = '',
941
+ start = new Date(_xdsoft_datetime.currentTime.getFullYear(),_xdsoft_datetime.currentTime.getMonth(),1, 12, 0, 0),
942
+ i = 0,
943
+ today = _xdsoft_datetime.now();
944
+
945
+ while( start.getDay()!=options.dayOfWeekStart )
946
+ start.setDate(start.getDate()-1);
947
+
948
+ //generate calendar
949
+ table+='<table><thead><tr>';
950
+
951
+ if(options.weeks) {
952
+ table+='<th></th>';
953
+ }
954
+
955
+ // days
956
+ for(var j = 0; j<7; j++) {
957
+ table+='<th>'+options.i18n[options.lang].dayOfWeek[(j+options.dayOfWeekStart)%7]+'</th>';
958
+ }
959
+
960
+ table+='</tr></thead>';
961
+ table+='<tbody>';
962
+ var maxDate = false, minDate = false;
963
+
964
+ if( options.maxDate!==false ) {
965
+ maxDate = _xdsoft_datetime.strToDate(options.maxDate);
966
+ maxDate = new Date(maxDate.getFullYear(),maxDate.getMonth(),maxDate.getDate(),23,59,59,999);
967
+ }
968
+
969
+ if( options.minDate!==false ) {
970
+ minDate = _xdsoft_datetime.strToDate(options.minDate);
971
+ minDate = new Date(minDate.getFullYear(),minDate.getMonth(),minDate.getDate());
972
+ }
973
+
974
+ var d,y,m,w,classes = [],customDateSettings,newRow=true;
975
+
976
+ while( i<_xdsoft_datetime.currentTime.countDaysInMonth()||start.getDay()!=options.dayOfWeekStart||_xdsoft_datetime.currentTime.getMonth()==start.getMonth() ) {
977
+ classes = [];
978
+ i++;
979
+
980
+ d = start.getDate(); y = start.getFullYear(); m = start.getMonth(); w = start.getWeekOfYear();
981
+
982
+ classes.push('xdsoft_date');
983
+
984
+ if ( options.beforeShowDay && options.beforeShowDay.call ) {
985
+ customDateSettings = options.beforeShowDay.call(datetimepicker, start);
986
+ } else {
987
+ customDateSettings = null;
988
+ }
989
+
990
+ if( ( maxDate!==false && start > maxDate )||( minDate!==false && start < minDate )||(customDateSettings && customDateSettings[0] === false) ){
991
+ classes.push('xdsoft_disabled');
992
+ }
993
+
994
+ if ( customDateSettings && customDateSettings[1] != "" ) {
995
+ classes.push(customDateSettings[1]);
996
+ }
997
+
998
+ if( _xdsoft_datetime.currentTime.getMonth()!=m ) classes.push('xdsoft_other_month');
999
+
1000
+ if( (options.defaultSelect||datetimepicker.data('changed')) && _xdsoft_datetime.currentTime.dateFormat( options.formatDate )==start.dateFormat( options.formatDate ) ) {
1001
+ classes.push('xdsoft_current');
1002
+ }
1003
+
1004
+ if( today.dateFormat( options.formatDate )==start.dateFormat( options.formatDate ) ) {
1005
+ classes.push('xdsoft_today');
1006
+ }
1007
+
1008
+ if( start.getDay()==0||start.getDay()==6||~options.weekends.indexOf(start.dateFormat( options.formatDate )) ) {
1009
+ classes.push('xdsoft_weekend');
1010
+ }
1011
+
1012
+ if(options.beforeShowDay && typeof options.beforeShowDay == 'function') {
1013
+ classes.push(options.beforeShowDay(start))
1014
+ }
1015
+
1016
+ if(newRow) {
1017
+ table+='<tr>';
1018
+ newRow = false;
1019
+
1020
+ if(options.weeks) {
1021
+ table+='<th>'+w+'</th>';
1022
+ }
1023
+ }
1024
+
1025
+ table+='<td data-date="'+d+'" data-month="'+m+'" data-year="'+y+'"'+' class="xdsoft_date xdsoft_day_of_week'+start.getDay()+' '+ classes.join(' ')+'">'+
1026
+ '<div>'+d+'</div>'+
1027
+ '</td>';
1028
+
1029
+ if( start.getDay()==options.dayOfWeekStartPrev ) {
1030
+ table+='</tr>';
1031
+ newRow = true;
1032
+ }
1033
+
1034
+ start.setDate(d+1);
1035
+ }
1036
+ table+='</tbody></table>';
1037
+
1038
+ calendar.html(table);
1039
+
1040
+ mounth_picker.find('.xdsoft_label span').eq(0).text(options.i18n[options.lang].months[_xdsoft_datetime.currentTime.getMonth()]);
1041
+ mounth_picker.find('.xdsoft_label span').eq(1).text(_xdsoft_datetime.currentTime.getFullYear());
1042
+
1043
+ // generate timebox
1044
+ var time = '',
1045
+ h = '',
1046
+ m ='',
1047
+ line_time = function line_time( h,m ) {
1048
+ var now = _xdsoft_datetime.now();
1049
+ now.setHours(h);
1050
+ h = parseInt(now.getHours());
1051
+ now.setMinutes(m);
1052
+ m = parseInt(now.getMinutes());
1053
+
1054
+ classes = [];
1055
+ if( (options.maxTime!==false&&_xdsoft_datetime.strtotime(options.maxTime).getTime()<now.getTime())||(options.minTime!==false&&_xdsoft_datetime.strtotime(options.minTime).getTime()>now.getTime()))
1056
+ classes.push('xdsoft_disabled');
1057
+ if( (options.initTime||options.defaultSelect||datetimepicker.data('changed')) && parseInt(_xdsoft_datetime.currentTime.getHours())==parseInt(h)&&(options.step>59||Math[options.roundTime](_xdsoft_datetime.currentTime.getMinutes()/options.step)*options.step==parseInt(m))) {
1058
+ if( options.defaultSelect||datetimepicker.data('changed')) {
1059
+ classes.push('xdsoft_current');
1060
+ } else if( options.initTime ) {
1061
+ classes.push('xdsoft_init_time');
1062
+ }
1063
+ }
1064
+ if( parseInt(today.getHours())==parseInt(h)&&parseInt(today.getMinutes())==parseInt(m))
1065
+ classes.push('xdsoft_today');
1066
+ time+= '<div class="xdsoft_time '+classes.join(' ')+'" data-hour="'+h+'" data-minute="'+m+'">'+now.dateFormat(options.formatTime)+'</div>';
1067
+ };
1068
+
1069
+ if( !options.allowTimes || !$.isArray(options.allowTimes) || !options.allowTimes.length ) {
1070
+ for( var i=0,j=0;i<(options.hours12?12:24);i++ ) {
1071
+ for( j=0;j<60;j+=options.step ) {
1072
+ h = (i<10?'0':'')+i;
1073
+ m = (j<10?'0':'')+j;
1074
+ line_time( h,m );
1075
+ }
1076
+ }
1077
+ }else{
1078
+ for( var i=0;i<options.allowTimes.length;i++ ) {
1079
+ h = _xdsoft_datetime.strtotime(options.allowTimes[i]).getHours();
1080
+ m = _xdsoft_datetime.strtotime(options.allowTimes[i]).getMinutes();
1081
+ line_time( h,m );
1082
+ }
1083
+ }
1084
+
1085
+ timebox.html(time);
1086
+
1087
+ var opt = '',
1088
+ i = 0;
1089
+
1090
+ for( i = parseInt(options.yearStart,10)+options.yearOffset;i<= parseInt(options.yearEnd,10)+options.yearOffset;i++ ) {
1091
+ opt+='<div class="xdsoft_option '+(_xdsoft_datetime.currentTime.getFullYear()==i?'xdsoft_current':'')+'" data-value="'+i+'">'+i+'</div>';
1092
+ }
1093
+ yearselect.children().eq(0)
1094
+ .html(opt);
1095
+
1096
+ for( i = 0,opt = '';i<= 11;i++ ) {
1097
+ opt+='<div class="xdsoft_option '+(_xdsoft_datetime.currentTime.getMonth()==i?'xdsoft_current':'')+'" data-value="'+i+'">'+options.i18n[options.lang].months[i]+'</div>';
1098
+ }
1099
+ monthselect.children().eq(0).html(opt);
1100
+ $(datetimepicker)
1101
+ .trigger('generate.xdsoft');
1102
+ },10);
1103
+ event.stopPropagation();
1104
+ })
1105
+ .on('afterOpen.xdsoft',function() {
1106
+ if( options.timepicker ) {
1107
+ var classType;
1108
+ if( timebox.find('.xdsoft_current').length ) {
1109
+ classType = '.xdsoft_current';
1110
+ } else if( timebox.find('.xdsoft_init_time').length ) {
1111
+ classType = '.xdsoft_init_time';
1112
+ }
1113
+
1114
+ if( classType ) {
1115
+ var pheight = timeboxparent[0].clientHeight,
1116
+ height = timebox[0].offsetHeight,
1117
+ top = timebox.find(classType).index()*options.timeHeightInTimePicker+1;
1118
+ if( (height-pheight)<top )
1119
+ top = height-pheight;
1120
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[parseInt(top)/(height-pheight)]);
1121
+ }else{
1122
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[0]);
1123
+ }
1124
+ }
1125
+ });
1126
+
1127
+ var timerclick = 0;
1128
+
1129
+ calendar
1130
+ .on('click.xdsoft', 'td', function (xdevent) {
1131
+ xdevent.stopPropagation(); // Prevents closing of Pop-ups, Modals and Flyouts in Bootstrap
1132
+ timerclick++;
1133
+ var $this = $(this),
1134
+ currentTime = _xdsoft_datetime.currentTime;
1135
+
1136
+ if( currentTime===undefined||currentTime===null ){
1137
+ _xdsoft_datetime.currentTime = _xdsoft_datetime.now();
1138
+ currentTime = _xdsoft_datetime.currentTime;
1139
+ }
1140
+
1141
+ if( $this.hasClass('xdsoft_disabled') )
1142
+ return false;
1143
+
1144
+ currentTime.setDate( 1 );
1145
+ currentTime.setFullYear( $this.data('year') );
1146
+ currentTime.setMonth( $this.data('month') );
1147
+ currentTime.setDate( $this.data('date') );
1148
+
1149
+ datetimepicker.trigger('select.xdsoft',[currentTime]);
1150
+
1151
+ input.val( _xdsoft_datetime.str() );
1152
+ if( (timerclick>1||(options.closeOnDateSelect===true||( options.closeOnDateSelect===0&&!options.timepicker )))&&!options.inline ) {
1153
+ datetimepicker.trigger('close.xdsoft');
1154
+ }
1155
+
1156
+ if( options.onSelectDate && options.onSelectDate.call ) {
1157
+ options.onSelectDate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
1158
+ }
1159
+
1160
+ datetimepicker.data('changed',true);
1161
+ datetimepicker.trigger('xchange.xdsoft');
1162
+ datetimepicker.trigger('changedatetime.xdsoft');
1163
+ setTimeout(function(){
1164
+ timerclick = 0;
1165
+ },200);
1166
+ });
1167
+
1168
+ timebox
1169
+ .on('click.xdsoft', 'div', function (xdevent) {
1170
+ xdevent.stopPropagation(); // NAJ: Prevents closing of Pop-ups, Modals and Flyouts
1171
+ var $this = $(this),
1172
+ currentTime = _xdsoft_datetime.currentTime;
1173
+
1174
+ if( currentTime===undefined||currentTime===null ){
1175
+ _xdsoft_datetime.currentTime = _xdsoft_datetime.now();
1176
+ currentTime = _xdsoft_datetime.currentTime;
1177
+ }
1178
+
1179
+ if( $this.hasClass('xdsoft_disabled') )
1180
+ return false;
1181
+ currentTime.setHours($this.data('hour'));
1182
+ currentTime.setMinutes($this.data('minute'));
1183
+ datetimepicker.trigger('select.xdsoft',[currentTime]);
1184
+
1185
+ datetimepicker.data('input').val( _xdsoft_datetime.str() );
1186
+
1187
+ !options.inline&&datetimepicker.trigger('close.xdsoft');
1188
+
1189
+ if( options.onSelectTime&&options.onSelectTime.call ) {
1190
+ options.onSelectTime.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
1191
+ }
1192
+ datetimepicker.data('changed',true);
1193
+ datetimepicker.trigger('xchange.xdsoft');
1194
+ datetimepicker.trigger('changedatetime.xdsoft');
1195
+ });
1196
+
1197
+ datetimepicker.mousewheel&&datepicker.mousewheel(function(event, delta, deltaX, deltaY) {
1198
+ if( !options.scrollMonth )
1199
+ return true;
1200
+ if( delta<0 )
1201
+ _xdsoft_datetime.nextMonth();
1202
+ else
1203
+ _xdsoft_datetime.prevMonth();
1204
+ return false;
1205
+ });
1206
+
1207
+ datetimepicker.mousewheel&&timeboxparent.unmousewheel().mousewheel(function(event, delta, deltaX, deltaY) {
1208
+ if( !options.scrollTime )
1209
+ return true;
1210
+ var pheight = timeboxparent[0].clientHeight,
1211
+ height = timebox[0].offsetHeight,
1212
+ top = Math.abs(parseInt(timebox.css('marginTop'))),
1213
+ fl = true;
1214
+ if( delta<0 && (height-pheight)-options.timeHeightInTimePicker>=top ) {
1215
+ timebox.css('marginTop','-'+(top+options.timeHeightInTimePicker)+'px');
1216
+ fl = false;
1217
+ }else if( delta>0&&top-options.timeHeightInTimePicker>=0 ) {
1218
+ timebox.css('marginTop','-'+(top-options.timeHeightInTimePicker)+'px');
1219
+ fl = false;
1220
+ }
1221
+ timeboxparent.trigger('scroll_element.xdsoft_scroller',[Math.abs(parseInt(timebox.css('marginTop'))/(height-pheight))]);
1222
+ event.stopPropagation();
1223
+ return fl;
1224
+ });
1225
+
1226
+ var triggerAfterOpen = false;
1227
+ datetimepicker
1228
+ .on('changedatetime.xdsoft',function() {
1229
+ if( options.onChangeDateTime&&options.onChangeDateTime.call ) {
1230
+ var $input = datetimepicker.data('input');
1231
+ options.onChangeDateTime.call(datetimepicker, _xdsoft_datetime.currentTime, $input);
1232
+ delete options.value;
1233
+ $input.trigger('change');
1234
+ }
1235
+ })
1236
+ .on('generate.xdsoft',function() {
1237
+ if( options.onGenerate&&options.onGenerate.call )
1238
+ options.onGenerate.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
1239
+ if( triggerAfterOpen ){
1240
+ datetimepicker.trigger('afterOpen.xdsoft');
1241
+ triggerAfterOpen = false;
1242
+ }
1243
+ })
1244
+ .on( 'click.xdsoft', function( xdevent )
1245
+ {
1246
+ xdevent.stopPropagation(); // Prevents closing of Pop-ups, Modals and Flyouts in Bootstrap
1247
+ });
1248
+
1249
+ var current_time_index = 0;
1250
+ input.mousewheel&&input.mousewheel(function( event, delta, deltaX, deltaY ) {
1251
+ if( !options.scrollInput )
1252
+ return true;
1253
+ if( !options.datepicker && options.timepicker ) {
1254
+ current_time_index = timebox.find('.xdsoft_current').length?timebox.find('.xdsoft_current').eq(0).index():0;
1255
+ if( current_time_index+delta>=0&&current_time_index+delta<timebox.children().length )
1256
+ current_time_index+=delta;
1257
+ timebox.children().eq(current_time_index).length&&timebox.children().eq(current_time_index).trigger('mousedown');
1258
+ return false;
1259
+ }else if( options.datepicker && !options.timepicker ) {
1260
+ datepicker.trigger( event, [delta, deltaX, deltaY]);
1261
+ input.val&&input.val( _xdsoft_datetime.str() );
1262
+ datetimepicker.trigger('changedatetime.xdsoft');
1263
+ return false;
1264
+ }
1265
+ });
1266
+ var setPos = function() {
1267
+ var offset = datetimepicker.data('input').offset(), top = offset.top+datetimepicker.data('input')[0].offsetHeight-1, left = offset.left, position = "absolute";
1268
+ if (options.fixed) {
1269
+ top -= $(window).scrollTop();
1270
+ left -= $(window).scrollLeft();
1271
+ position = "fixed";
1272
+ }else {
1273
+ if( top+datetimepicker[0].offsetHeight>$(window).height()+$(window).scrollTop() )
1274
+ top = offset.top-datetimepicker[0].offsetHeight+1;
1275
+ if (top < 0)
1276
+ top = 0;
1277
+ if( left+datetimepicker[0].offsetWidth>$(window).width() )
1278
+ left = offset.left-datetimepicker[0].offsetWidth+datetimepicker.data('input')[0].offsetWidth;
1279
+ }
1280
+ datetimepicker.css({
1281
+ left:left,
1282
+ top:top,
1283
+ position: position
1284
+ });
1285
+ };
1286
+ datetimepicker
1287
+ .on('open.xdsoft', function() {
1288
+ var onShow = true;
1289
+ if( options.onShow&&options.onShow.call) {
1290
+ onShow = options.onShow.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
1291
+ }
1292
+ if( onShow!==false ) {
1293
+ datetimepicker.show();
1294
+ setPos();
1295
+ $(window)
1296
+ .off('resize.xdsoft',setPos)
1297
+ .on('resize.xdsoft',setPos);
1298
+
1299
+ if( options.closeOnWithoutClick ) {
1300
+ $([document.body,window]).on('mousedown.xdsoft',function arguments_callee6() {
1301
+ datetimepicker.trigger('close.xdsoft');
1302
+ $([document.body,window]).off('mousedown.xdsoft',arguments_callee6);
1303
+ });
1304
+ }
1305
+ }
1306
+ })
1307
+ .on('close.xdsoft', function( event ) {
1308
+ var onClose = true;
1309
+ if( options.onClose&&options.onClose.call ) {
1310
+ onClose=options.onClose.call(datetimepicker,_xdsoft_datetime.currentTime,datetimepicker.data('input'));
1311
+ }
1312
+ if( onClose!==false&&!options.opened&&!options.inline ) {
1313
+ datetimepicker.hide();
1314
+ }
1315
+ event.stopPropagation();
1316
+ })
1317
+ .data('input',input);
1318
+
1319
+ var timer = 0,
1320
+ timer1 = 0;
1321
+
1322
+ datetimepicker.data('xdsoft_datetime',_xdsoft_datetime);
1323
+ datetimepicker.setOptions(options);
1324
+
1325
+ function getCurrentValue(){
1326
+
1327
+ var ct = false;
1328
+
1329
+ if ( options.startDate ) {
1330
+ ct = _xdsoft_datetime.strToDate(options.startDate);
1331
+ } else {
1332
+ ct = options.value?options.value:(input&&input.val&&input.val())?input.val():'';
1333
+ if( ct ) {
1334
+ ct = _xdsoft_datetime.strToDateTime(ct);
1335
+ } else if ( options.defaultDate ) {
1336
+ ct = _xdsoft_datetime.strToDate(options.defaultDate);
1337
+ }
1338
+ }
1339
+
1340
+ if ( ct && _xdsoft_datetime.isValidDate(ct) ) {
1341
+ datetimepicker.data('changed',true);
1342
+ } else {
1343
+ ct = '';
1344
+ }
1345
+
1346
+ return ct?ct:0;
1347
+ }
1348
+ //debugger
1349
+ _xdsoft_datetime.setCurrentTime( getCurrentValue() );
1350
+
1351
+ input
1352
+ .data( 'xdsoft_datetimepicker',datetimepicker )
1353
+ .on('open.xdsoft focusin.xdsoft mousedown.xdsoft',function(event) {
1354
+ if( input.is(':disabled')||input.is(':hidden')||!input.is(':visible')||(input.data('xdsoft_datetimepicker').is(':visible') && options.closeOnInputClick) )
1355
+ return;
1356
+ clearTimeout(timer);
1357
+ timer = setTimeout(function() {
1358
+ if( input.is(':disabled')||input.is(':hidden')||!input.is(':visible') )
1359
+ return;
1360
+
1361
+ triggerAfterOpen = true;
1362
+ _xdsoft_datetime.setCurrentTime(getCurrentValue());
1363
+
1364
+ datetimepicker.trigger('open.xdsoft');
1365
+ },100);
1366
+ })
1367
+ .on('keydown.xdsoft',function( event ) {
1368
+ var val = this.value,
1369
+ key = event.which;
1370
+ switch(true) {
1371
+ case !!~([ENTER].indexOf(key)):
1372
+ var elementSelector = $("input:visible,textarea:visible");
1373
+ datetimepicker.trigger('close.xdsoft');
1374
+ elementSelector.eq(elementSelector.index(this) + 1).focus();
1375
+ return false;
1376
+ case !!~[TAB].indexOf(key):
1377
+ datetimepicker.trigger('close.xdsoft');
1378
+ return true;
1379
+ }
1380
+ });
1381
+ },
1382
+ destroyDateTimePicker = function( input ) {
1383
+ var datetimepicker = input.data('xdsoft_datetimepicker');
1384
+ if( datetimepicker ) {
1385
+ datetimepicker.data('xdsoft_datetime',null);
1386
+ datetimepicker.remove();
1387
+ input
1388
+ .data( 'xdsoft_datetimepicker',null )
1389
+ .off( 'open.xdsoft focusin.xdsoft focusout.xdsoft mousedown.xdsoft blur.xdsoft keydown.xdsoft' );
1390
+ $(window).off('resize.xdsoft');
1391
+ $([window,document.body]).off('mousedown.xdsoft');
1392
+ input.unmousewheel&&input.unmousewheel();
1393
+ }
1394
+ };
1395
+ $(document)
1396
+ .off('keydown.xdsoftctrl keyup.xdsoftctrl')
1397
+ .on('keydown.xdsoftctrl',function(e) {
1398
+ if ( e.keyCode == CTRLKEY )
1399
+ ctrlDown = true;
1400
+ })
1401
+ .on('keyup.xdsoftctrl',function(e) {
1402
+ if ( e.keyCode == CTRLKEY )
1403
+ ctrlDown = false;
1404
+ });
1405
+ return this.each(function() {
1406
+ var datetimepicker;
1407
+ if( datetimepicker = $(this).data('xdsoft_datetimepicker') ) {
1408
+ if( $.type(opt) === 'string' ) {
1409
+ switch(opt) {
1410
+ case 'show':
1411
+ $(this).select().focus();
1412
+ datetimepicker.trigger( 'open.xdsoft' );
1413
+ break;
1414
+ case 'hide':
1415
+ datetimepicker.trigger('close.xdsoft');
1416
+ break;
1417
+ case 'destroy':
1418
+ destroyDateTimePicker($(this));
1419
+ break;
1420
+ case 'reset':
1421
+ this.value = this.defaultValue;
1422
+ if(!this.value || !datetimepicker.data('xdsoft_datetime').isValidDate(Date.parseDate(this.value, options.format)))
1423
+ datetimepicker.data('changed',false);
1424
+ datetimepicker.data('xdsoft_datetime').setCurrentTime(this.value);
1425
+ break;
1426
+ }
1427
+ }else{
1428
+ datetimepicker
1429
+ .setOptions(opt);
1430
+ }
1431
+ return 0;
1432
+ }else
1433
+ if( ($.type(opt) !== 'string') ){
1434
+ if( !options.lazyInit||options.open||options.inline ){
1435
+ createDateTimePicker($(this));
1436
+ }else
1437
+ lazyInit($(this));
1438
+ }
1439
+ });
1440
+ };
1441
+ $.fn.datetimepicker.defaults = default_options;
1442
+ })( jQuery );
1443
+
1444
+ /*
1445
+ * Copyright (c) 2013 Brandon Aaron (http://brandonaaron.net)
1446
+ *
1447
+ * Licensed under the MIT License (LICENSE.txt).
1448
+ *
1449
+ * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
1450
+ * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
1451
+ * Thanks to: Seamus Leahy for adding deltaX and deltaY
1452
+ *
1453
+ * Version: 3.1.3
1454
+ *
1455
+ * Requires: 1.2.2+
1456
+ */
1457
+ (function(factory) {if(typeof define==='function'&&define.amd) {define(['jquery'],factory)}else if(typeof exports==='object') {module.exports=factory}else{factory(jQuery)}}(function($) {var toFix=['wheel','mousewheel','DOMMouseScroll','MozMousePixelScroll'];var toBind='onwheel'in document||document.documentMode>=9?['wheel']:['mousewheel','DomMouseScroll','MozMousePixelScroll'];var lowestDelta,lowestDeltaXY;if($.event.fixHooks) {for(var i=toFix.length;i;) {$.event.fixHooks[toFix[--i]]=$.event.mouseHooks}}$.event.special.mousewheel={setup:function() {if(this.addEventListener) {for(var i=toBind.length;i;) {this.addEventListener(toBind[--i],handler,false)}}else{this.onmousewheel=handler}},teardown:function() {if(this.removeEventListener) {for(var i=toBind.length;i;) {this.removeEventListener(toBind[--i],handler,false)}}else{this.onmousewheel=null}}};$.fn.extend({mousewheel:function(fn) {return fn?this.bind("mousewheel",fn):this.trigger("mousewheel")},unmousewheel:function(fn) {return this.unbind("mousewheel",fn)}});function handler(event) {var orgEvent=event||window.event,args=[].slice.call(arguments,1),delta=0,deltaX=0,deltaY=0,absDelta=0,absDeltaXY=0,fn;event=$.event.fix(orgEvent);event.type="mousewheel";if(orgEvent.wheelDelta) {delta=orgEvent.wheelDelta}if(orgEvent.detail) {delta=orgEvent.detail*-1}if(orgEvent.deltaY) {deltaY=orgEvent.deltaY*-1;delta=deltaY}if(orgEvent.deltaX) {deltaX=orgEvent.deltaX;delta=deltaX*-1}if(orgEvent.wheelDeltaY!==undefined) {deltaY=orgEvent.wheelDeltaY}if(orgEvent.wheelDeltaX!==undefined) {deltaX=orgEvent.wheelDeltaX*-1}absDelta=Math.abs(delta);if(!lowestDelta||absDelta<lowestDelta) {lowestDelta=absDelta}absDeltaXY=Math.max(Math.abs(deltaY),Math.abs(deltaX));if(!lowestDeltaXY||absDeltaXY<lowestDeltaXY) {lowestDeltaXY=absDeltaXY}fn=delta>0?'floor':'ceil';delta=Math[fn](delta/lowestDelta);deltaX=Math[fn](deltaX/lowestDeltaXY);deltaY=Math[fn](deltaY/lowestDeltaXY);args.unshift(event,delta,deltaX,deltaY);return($.event.dispatch||$.event.handle).apply(this,args)}}));
1458
+
1459
+
1460
+ // Parse and Format Library
1461
+ //http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/
1462
+ /*
1463
+ * Copyright (C) 2004 Baron Schwartz <baron at sequent dot org>
1464
+ *
1465
+ * This program is free software; you can redistribute it and/or modify it
1466
+ * under the terms of the GNU Lesser General Public License as published by the
1467
+ * Free Software Foundation, version 2.1.
1468
+ *
1469
+ * This program is distributed in the hope that it will be useful, but WITHOUT
1470
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1471
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
1472
+ * details.
1473
+ */
1474
+ Date.parseFunctions={count:0};Date.parseRegexes=[];Date.formatFunctions={count:0};Date.prototype.dateFormat=function(b){if(b=="unixtime"){return parseInt(this.getTime()/1000);}if(Date.formatFunctions[b]==null){Date.createNewFormat(b);}var a=Date.formatFunctions[b];return this[a]();};Date.createNewFormat=function(format){var funcName="format"+Date.formatFunctions.count++;Date.formatFunctions[format]=funcName;var code="Date.prototype."+funcName+" = function() {return ";var special=false;var ch="";for(var i=0;i<format.length;++i){ch=format.charAt(i);if(!special&&ch=="\\"){special=true;}else{if(special){special=false;code+="'"+String.escape(ch)+"' + ";}else{code+=Date.getFormatCode(ch);}}}eval(code.substring(0,code.length-3)+";}");};Date.getFormatCode=function(a){switch(a){case"d":return"String.leftPad(this.getDate(), 2, '0') + ";case"D":return"Date.dayNames[this.getDay()].substring(0, 3) + ";case"j":return"this.getDate() + ";case"l":return"Date.dayNames[this.getDay()] + ";case"S":return"this.getSuffix() + ";case"w":return"this.getDay() + ";case"z":return"this.getDayOfYear() + ";case"W":return"this.getWeekOfYear() + ";case"F":return"Date.monthNames[this.getMonth()] + ";case"m":return"String.leftPad(this.getMonth() + 1, 2, '0') + ";case"M":return"Date.monthNames[this.getMonth()].substring(0, 3) + ";case"n":return"(this.getMonth() + 1) + ";case"t":return"this.getDaysInMonth() + ";case"L":return"(this.isLeapYear() ? 1 : 0) + ";case"Y":return"this.getFullYear() + ";case"y":return"('' + this.getFullYear()).substring(2, 4) + ";case"a":return"(this.getHours() < 12 ? 'am' : 'pm') + ";case"A":return"(this.getHours() < 12 ? 'AM' : 'PM') + ";case"g":return"((this.getHours() %12) ? this.getHours() % 12 : 12) + ";case"G":return"this.getHours() + ";case"h":return"String.leftPad((this.getHours() %12) ? this.getHours() % 12 : 12, 2, '0') + ";case"H":return"String.leftPad(this.getHours(), 2, '0') + ";case"i":return"String.leftPad(this.getMinutes(), 2, '0') + ";case"s":return"String.leftPad(this.getSeconds(), 2, '0') + ";case"O":return"this.getGMTOffset() + ";case"T":return"this.getTimezone() + ";case"Z":return"(this.getTimezoneOffset() * -60) + ";default:return"'"+String.escape(a)+"' + ";}};Date.parseDate=function(a,c){if(c=="unixtime"){return new Date(!isNaN(parseInt(a))?parseInt(a)*1000:0);}if(Date.parseFunctions[c]==null){Date.createParser(c);}var b=Date.parseFunctions[c];return Date[b](a);};Date.createParser=function(format){var funcName="parse"+Date.parseFunctions.count++;var regexNum=Date.parseRegexes.length;var currentGroup=1;Date.parseFunctions[format]=funcName;var code="Date."+funcName+" = function(input) {\nvar y = -1, m = -1, d = -1, h = -1, i = -1, s = -1, z = -1;\nvar d = new Date();\ny = d.getFullYear();\nm = d.getMonth();\nd = d.getDate();\nvar results = input.match(Date.parseRegexes["+regexNum+"]);\nif (results && results.length > 0) {";var regex="";var special=false;var ch="";for(var i=0;i<format.length;++i){ch=format.charAt(i);if(!special&&ch=="\\"){special=true;}else{if(special){special=false;regex+=String.escape(ch);}else{obj=Date.formatCodeToRegex(ch,currentGroup);currentGroup+=obj.g;regex+=obj.s;if(obj.g&&obj.c){code+=obj.c;}}}}code+="if (y > 0 && z > 0){\nvar doyDate = new Date(y,0);\ndoyDate.setDate(z);\nm = doyDate.getMonth();\nd = doyDate.getDate();\n}";code+="if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n{return new Date(y, m, d, h, i, s);}\nelse if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n{return new Date(y, m, d, h, i);}\nelse if (y > 0 && m >= 0 && d > 0 && h >= 0)\n{return new Date(y, m, d, h);}\nelse if (y > 0 && m >= 0 && d > 0)\n{return new Date(y, m, d);}\nelse if (y > 0 && m >= 0)\n{return new Date(y, m);}\nelse if (y > 0)\n{return new Date(y);}\n}return null;}";Date.parseRegexes[regexNum]=new RegExp("^"+regex+"$");eval(code);};Date.formatCodeToRegex=function(b,a){switch(b){case"D":return{g:0,c:null,s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};case"j":case"d":return{g:1,c:"d = parseInt(results["+a+"], 10);\n",s:"(\\d{1,2})"};case"l":return{g:0,c:null,s:"(?:"+Date.dayNames.join("|")+")"};case"S":return{g:0,c:null,s:"(?:st|nd|rd|th)"};case"w":return{g:0,c:null,s:"\\d"};case"z":return{g:1,c:"z = parseInt(results["+a+"], 10);\n",s:"(\\d{1,3})"};case"W":return{g:0,c:null,s:"(?:\\d{2})"};case"F":return{g:1,c:"m = parseInt(Date.monthNumbers[results["+a+"].substring(0, 3)], 10);\n",s:"("+Date.monthNames.join("|")+")"};case"M":return{g:1,c:"m = parseInt(Date.monthNumbers[results["+a+"]], 10);\n",s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};case"n":case"m":return{g:1,c:"m = parseInt(results["+a+"], 10) - 1;\n",s:"(\\d{1,2})"};case"t":return{g:0,c:null,s:"\\d{1,2}"};case"L":return{g:0,c:null,s:"(?:1|0)"};case"Y":return{g:1,c:"y = parseInt(results["+a+"], 10);\n",s:"(\\d{4})"};case"y":return{g:1,c:"var ty = parseInt(results["+a+"], 10);\ny = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",s:"(\\d{1,2})"};case"a":return{g:1,c:"if (results["+a+"] == 'am') {\nif (h == 12) { h = 0; }\n} else { if (h < 12) { h += 12; }}",s:"(am|pm)"};case"A":return{g:1,c:"if (results["+a+"] == 'AM') {\nif (h == 12) { h = 0; }\n} else { if (h < 12) { h += 12; }}",s:"(AM|PM)"};case"g":case"G":case"h":case"H":return{g:1,c:"h = parseInt(results["+a+"], 10);\n",s:"(\\d{1,2})"};case"i":return{g:1,c:"i = parseInt(results["+a+"], 10);\n",s:"(\\d{2})"};case"s":return{g:1,c:"s = parseInt(results["+a+"], 10);\n",s:"(\\d{2})"};case"O":return{g:0,c:null,s:"[+-]\\d{4}"};case"T":return{g:0,c:null,s:"[A-Z]{3}"};case"Z":return{g:0,c:null,s:"[+-]\\d{1,5}"};default:return{g:0,c:null,s:String.escape(b)};}};Date.prototype.getTimezone=function(){return this.toString().replace(/^.*? ([A-Z]{3}) [0-9]{4}.*$/,"$1").replace(/^.*?\(([A-Z])[a-z]+ ([A-Z])[a-z]+ ([A-Z])[a-z]+\)$/,"$1$2$3");};Date.prototype.getGMTOffset=function(){return(this.getTimezoneOffset()>0?"-":"+")+String.leftPad(Math.floor(Math.abs(this.getTimezoneOffset())/60),2,"0")+String.leftPad(Math.abs(this.getTimezoneOffset())%60,2,"0");};Date.prototype.getDayOfYear=function(){var a=0;Date.daysInMonth[1]=this.isLeapYear()?29:28;for(var b=0;b<this.getMonth();++b){a+=Date.daysInMonth[b];}return a+this.getDate();};Date.prototype.getWeekOfYear=function(){var b=this.getDayOfYear()+(4-this.getDay());var a=new Date(this.getFullYear(),0,1);var c=(7-a.getDay()+4);return String.leftPad(Math.ceil((b-c)/7)+1,2,"0");};Date.prototype.isLeapYear=function(){var a=this.getFullYear();return((a&3)==0&&(a%100||(a%400==0&&a)));};Date.prototype.getFirstDayOfMonth=function(){var a=(this.getDay()-(this.getDate()-1))%7;return(a<0)?(a+7):a;};Date.prototype.getLastDayOfMonth=function(){var a=(this.getDay()+(Date.daysInMonth[this.getMonth()]-this.getDate()))%7;return(a<0)?(a+7):a;};Date.prototype.getDaysInMonth=function(){Date.daysInMonth[1]=this.isLeapYear()?29:28;return Date.daysInMonth[this.getMonth()];};Date.prototype.getSuffix=function(){switch(this.getDate()){case 1:case 21:case 31:return"st";case 2:case 22:return"nd";case 3:case 23:return"rd";default:return"th";}};String.escape=function(a){return a.replace(/('|\\)/g,"\\$1");};String.leftPad=function(d,b,c){var a=new String(d);if(c==null){c=" ";}while(a.length<b){a=c+a;}return a;};Date.daysInMonth=[31,28,31,30,31,30,31,31,30,31,30,31];Date.monthNames=["January","February","March","April","May","June","July","August","September","October","November","December"];Date.dayNames=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];Date.y2kYear=50;Date.monthNumbers={Jan:0,Feb:1,Mar:2,Apr:3,May:4,Jun:5,Jul:6,Aug:7,Sep:8,Oct:9,Nov:10,Dec:11};Date.patterns={ISO8601LongPattern:"Y-m-d H:i:s",ISO8601ShortPattern:"Y-m-d",ShortDatePattern:"n/j/Y",LongDatePattern:"l, F d, Y",FullDateTimePattern:"l, F d, Y g:i:s A",MonthDayPattern:"F d",ShortTimePattern:"g:i A",LongTimePattern:"g:i:s A",SortableDateTimePattern:"Y-m-d\\TH:i:s",UniversalSortableDateTimePattern:"Y-m-d H:i:sO",YearMonthPattern:"F, Y"};
js/jquery.mediafromftp.datetimepicker.js ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Media from FTP
3
+ *
4
+ * @package Media from FTP
5
+ * @subpackage jquery.mediafromftp.datetimepicker.js
6
+ /* Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
7
+ This program is free software; you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation; version 2 of the License.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with this program; if not, write to the Free Software
18
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ */
20
+ jQuery(function(){
21
+ /* Date Time Picker */
22
+ jQuery(':input[id^=datetimepicker-mediafromftp]').datetimepicker({format:'Y-m-d H:i'});
23
+ });
js/jquery.mediafromftp.js ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Media from FTP
3
+ *
4
+ * @package Media from FTP
5
+ * @subpackage jquery.mediafromftp.js
6
+ /* Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
7
+ This program is free software; you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation; version 2 of the License.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU General Public License for more details.
15
+
16
+ You should have received a copy of the GNU General Public License
17
+ along with this program; if not, write to the Free Software
18
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ */
20
+ jQuery(function(){
21
+
22
+ /* Responsive Tabs */
23
+ jQuery('#mediafromftp-settings-tabs').responsiveTabs({
24
+ startCollapsed: 'accordion'
25
+ });
26
+
27
+ /* Spiner */
28
+ window.addEventListener( "load", function(){
29
+ jQuery("#mediafromftp-loading").delay(2000).fadeOut();
30
+ jQuery("#mediafromftp-loading-container").delay(2000).fadeIn();
31
+ }, false );
32
+
33
+ /* Control of the Enter key */
34
+ jQuery('input[type!="submit"][type!="button"]').keypress(function(e){
35
+ if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
36
+ return false;
37
+ }else{
38
+ return true;
39
+ }
40
+ });
41
+
42
+ /* Select bulk Date time */
43
+ jQuery('input[name="bulk_mediafromftp_datetime"]').change( function(){
44
+ var edit_date_time_val = jQuery('input[name="bulk_mediafromftp_datetime"]').val();
45
+ jQuery(':input[id^=datetimepicker-mediafromftp]').val(edit_date_time_val);
46
+ });
47
+
48
+ /* All check for Checkbox */
49
+ jQuery('.event-mediafromftp-checkAll').on('change', function() {
50
+ jQuery('.' + this.id).prop('checked', this.checked);
51
+ });
52
+
53
+ /* Ajax for register */
54
+ var mediafromftp_defer = jQuery.Deferred().resolve();
55
+ jQuery('#mediafromftp_ajax_update').submit(function(){
56
+
57
+ var new_url = new Array();
58
+ var new_datetime = new Array();
59
+ var new_mlccategory = new Array();
60
+ var new_emlcategory = new Array();
61
+ var new_mlacategory = new Array();
62
+ var new_mlatags = new Array();
63
+ var form_names = jQuery("#mediafromftp_ajax_update").serializeArray();
64
+ var mlccount = 0;
65
+ var emlcount = 0;
66
+ var mlacatcount = 0;
67
+ var mlatagcount = 0;
68
+ jQuery.each(form_names, function(i) {
69
+ if ( form_names[i].name.indexOf("[url]") != -1 ) {
70
+ new_url[i] = form_names[i].value;
71
+ }
72
+ if ( form_names[i].name.indexOf("[datetime]") != -1 ) {
73
+ new_datetime[i] = form_names[i].value;
74
+ }
75
+ if ( form_names[i].name.indexOf("[mlccount]") != -1 ) {
76
+ mlccount = form_names[i].value;
77
+ var form_checkbox = ".mlccheckbox" + mlccount + " input:checked";
78
+ var value="";
79
+ jQuery(form_checkbox).each(function() {
80
+ value = jQuery(this).val() + ',' + value;
81
+ });
82
+ new_mlccategory[i] = value.substr( 0, value.length-1 );
83
+ }
84
+ if ( form_names[i].name.indexOf("[emlcount]") != -1 ) {
85
+ emlcount = form_names[i].value;
86
+ var form_checkbox = ".emlcheckbox" + emlcount + " input:checked";
87
+ var value="";
88
+ jQuery(form_checkbox).each(function() {
89
+ value = jQuery(this).val() + ',' + value;
90
+ });
91
+ new_emlcategory[i] = value.substr( 0, value.length-1 );
92
+ }
93
+ if ( form_names[i].name.indexOf("[mlacatcount]") != -1 ) {
94
+ mlacatcount = form_names[i].value;
95
+ var form_checkbox = ".mlacatcheckbox" + mlacatcount + " input:checked";
96
+ var value="";
97
+ jQuery(form_checkbox).each(function() {
98
+ value = jQuery(this).val() + ',' + value;
99
+ });
100
+ new_mlacategory[i] = value.substr( 0, value.length-1 );
101
+ }
102
+ if ( form_names[i].name.indexOf("[mlatagcount]") != -1 ) {
103
+ mlatagcount = form_names[i].value;
104
+ var form_checkbox = ".mlatagcheckbox" + mlatagcount + " input:checked";
105
+ var value="";
106
+ jQuery(form_checkbox).each(function() {
107
+ value = jQuery(this).val() + ',' + value;
108
+ });
109
+ new_mlatags[i] = value.substr( 0, value.length-1 );
110
+ }
111
+ });
112
+ var new_url = jQuery.grep(new_url, function(e){return e;});
113
+ var new_datetime = jQuery.grep(new_datetime, function(e){return e;});
114
+ var new_mlccategory = jQuery.grep(new_mlccategory, function(e){return e;});
115
+ var new_emlcategory = jQuery.grep(new_emlcategory, function(e){return e;});
116
+ var new_mlacategory = jQuery.grep(new_mlacategory, function(e){return e;});
117
+ var new_mlatags = jQuery.grep(new_mlatags, function(e){return e;});
118
+
119
+ jQuery("#mediafromftp-loading-container").empty();
120
+ jQuery("#screen-options-wrap").remove();
121
+ jQuery(".updated").remove();
122
+ jQuery(".error").remove();
123
+
124
+ jQuery("#mediafromftp-loading-container").append("<div id=\"mediafromftp-update-progress\"><progress value=\"0\" max=\"100\"></progress> 0%</div><button type=\"button\" id=\"mediafromftp_ajax_stop\">Stop</button>");
125
+ jQuery("#mediafromftp-loading-container").append("<div id=\"mediafromftp-update-result\"></div>");
126
+
127
+ var update_continue = true;
128
+ // Stop button
129
+ jQuery("#mediafromftp_ajax_stop").click(function() {
130
+ update_continue = false;
131
+ jQuery("#mediafromftp_ajax_stop").text("Stopping now..");
132
+ });
133
+
134
+ var count = 0;
135
+ var success_count = 0;
136
+ var success_update = "";
137
+ var error_count = 0;
138
+ var error_update = "";
139
+ jQuery.each(new_url, function(i){
140
+ var j = i ;
141
+ mediafromftp_defer = mediafromftp_defer.then(function(){
142
+ if ( update_continue == true ) {
143
+ return jQuery.ajax({
144
+ type: 'POST',
145
+ url: MEDIAFROMFTPUPDATE.ajax_url,
146
+ data: {
147
+ 'action': MEDIAFROMFTPUPDATE.action,
148
+ 'nonce': MEDIAFROMFTPUPDATE.nonce,
149
+ 'maxcount': new_url.length,
150
+ 'new_url': new_url[j],
151
+ 'new_datetime': new_datetime[j],
152
+ 'new_mlccategory': new_mlccategory[j],
153
+ 'new_emlcategory': new_emlcategory[j],
154
+ 'new_mlacategory': new_mlacategory[j],
155
+ 'new_mlatags': new_mlatags[j]
156
+ }
157
+ }).then(
158
+ function(result){
159
+ count += 1;
160
+ success_count += 1;
161
+ jQuery("#mediafromftp-update-result").append(result);
162
+ jQuery("#mediafromftp-update-progress").empty();
163
+ var progressper = Math.round((count/new_url.length)*100);
164
+ jQuery("#mediafromftp-update-progress").append("<progress value=\"" + progressper + "\" max=\"100\"></progress> " + progressper + "%");
165
+ if ( count == new_url.length || update_continue == false ) {
166
+ jQuery.ajax({
167
+ type: 'POST',
168
+ url: MEDIAFROMFTPUPDATE.ajax_url,
169
+ data: {
170
+ 'action': 'mediafromftp_message',
171
+ 'error_count': error_count,
172
+ 'error_update': error_update,
173
+ 'success_count': success_count
174
+ }
175
+ }).done(function(result){
176
+ jQuery("#mediafromftp-update-progress").empty();
177
+ jQuery("#mediafromftp-update-progress").append(result);
178
+ jQuery("#mediafromftp_ajax_stop").hide();
179
+ });
180
+ }
181
+ },
182
+ function( jqXHR, textStatus, errorThrown){
183
+ error_count += 1;
184
+ error_update += "<div>" + new_url[j] + ": error -> status " + jqXHR.status + ' ' + textStatus.status + "</div>";
185
+ }
186
+ );
187
+ }
188
+ });
189
+ });
190
+ return false;
191
+ });
192
+
193
+ /* Ajax for import */
194
+ var medialibraryimport_defer = jQuery.Deferred().resolve();
195
+ jQuery('#medialibraryimport_ajax_update').submit(function(){
196
+
197
+ jQuery("#medialibraryimport-loading-container").empty();
198
+ jQuery(".updated").remove();
199
+ jQuery(".error").remove();
200
+
201
+ jQuery("#medialibraryimport-loading-container").append("<div id=\"medialibraryimport-update-progress\"><progress value=\"0\" max=\"100\"></progress> 0%</div><button type=\"button\" id=\"medialibraryimport_ajax_stop\">Stop</button>");
202
+ jQuery("#medialibraryimport-loading-container").append("<div id=\"medialibraryimport-update-result\"></div>");
203
+ var update_continue = true;
204
+ // Stop button
205
+ jQuery("#medialibraryimport_ajax_stop").click(function() {
206
+ update_continue = false;
207
+ jQuery("#medialibraryimport_ajax_stop").text("Stopping now..");
208
+ });
209
+
210
+ var count = 0;
211
+ var success_count = 0;
212
+ var db_success_count = 0;
213
+ var error_count = 0;
214
+ var error_update = "";
215
+
216
+ jQuery.each(medialibraryimport_file, function(i){
217
+ var j = i;
218
+ medialibraryimport_defer = medialibraryimport_defer.then(function(){
219
+ if ( update_continue == true ) {
220
+ return jQuery.ajax({
221
+ type: 'POST',
222
+ cache : false,
223
+ url: MEDIAFROMFTPIMPORT.ajax_url,
224
+ data: {
225
+ 'action': MEDIAFROMFTPIMPORT.action,
226
+ 'nonce': MEDIAFROMFTPIMPORT.nonce,
227
+ 'maxcount': medialibraryimport_maxcount,
228
+ 'file': medialibraryimport_file[j],
229
+ 'db_array': medialibraryimport_db_array[j],
230
+ 'db_wp_attachment_metadata': medialibraryimport_db_wp_attachment_metadata[j],
231
+ 'db_thumbnail_id': medialibraryimport_db_thumbnail_id[j],
232
+ 'db_cover_hash': medialibraryimport_db_cover_hash[j],
233
+ 'db_wp_attachment_image_alt': medialibraryimport_db_wp_attachment_image_alt[j]
234
+ }
235
+ }).then(
236
+ function(result){
237
+ count += 1;
238
+ var update_view = result.split(",");
239
+ if( update_view[0] == "success" ) {
240
+ success_count += 1;
241
+ } else if( update_view[0] == "success_db" ) {
242
+ success_count += 1;
243
+ db_success_count += 1;
244
+ } else {
245
+ error_count += 1;
246
+ error_update += update_view[0];
247
+ }
248
+ jQuery("#medialibraryimport-update-progress").empty();
249
+ var progressper = Math.round((count/medialibraryimport_maxcount)*100);
250
+ jQuery("#medialibraryimport-update-progress").append("<progress value=\"" + progressper + "\" max=\"100\"></progress> " + progressper + "%");
251
+ jQuery("#medialibraryimport-update-result").append(update_view[1]);
252
+ if ( count == medialibraryimport_maxcount || update_continue == false ) {
253
+ jQuery.ajax({
254
+ type: 'POST',
255
+ url: MEDIAFROMFTPIMPORT.ajax_url,
256
+ data: {
257
+ 'action': 'mediafromftp_medialibraryimport_message',
258
+ 'error_count': error_count,
259
+ 'error_update': error_update,
260
+ 'success_count': success_count,
261
+ 'db_success_count': db_success_count
262
+ }
263
+ }).done(function(result){
264
+ jQuery("#medialibraryimport-update-progress").empty();
265
+ jQuery("#medialibraryimport-update-progress").append(result);
266
+ jQuery("#medialibraryimport_ajax_stop").hide();
267
+ });
268
+ }
269
+ }
270
+ ).fail(
271
+ function( jqXHR, textStatus, errorThrown){
272
+ error_count += 1;
273
+ error_update += "<div>" + medialibraryimport_file[j] + ": error -> status " + jqXHR.status + ' ' + textStatus.status + "</div>";
274
+ }
275
+ );
276
+ }
277
+ });
278
+ });
279
+ return false;
280
+ });
281
+
282
+ });
283
+
js/jquery.responsiveTabs.min.js ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ /*
2
+ * Project: jquery.responsiveTabs.js
3
+ * Description: A plugin that creates responsive tabs, optimized for all devices
4
+ * Author: Jelle Kralt (jelle@jellekralt.nl)
5
+ * Version: 1.4.0
6
+ * License: MIT
7
+ */(function(e,t,n){function i(t,n){this.element=t;this.$element=e(t);this.tabs=[];this.state="";this.rotateInterval=0;this.$queue=e({});this.options=e.extend({},r,n);this.init()}var r={active:null,disabled:[],collapsible:"accordion",startCollapsed:!1,rotate:!1,setHash:!1,animation:"default",duration:500,activate:function(){},deactivate:function(){},load:function(){},activateState:function(){},classes:{stateDefault:"r-tabs-state-default",stateActive:"r-tabs-state-active",stateDisabled:"r-tabs-state-disabled",stateExcluded:"r-tabs-state-excluded",tab:"r-tabs-tab",anchor:"r-tabs-anchor",panel:"r-tabs-panel",accordionTitle:"r-tabs-accordion-title"}};i.prototype.init=function(){var n=this;this.tabs=this._loadElements();this._loadClasses();this._loadEvents();e(t).on("resize",function(e){n._setState(e)});e(t).on("hashchange",function(e){var r=n._getTabRefBySelector(t.location.hash),i=n._getTab(r);r>=0&&!i._ignoreHashChange&&!i.disabled&&n._openTab(e,n._getTab(r),!0)});this.options.rotate!==!1&&this.startRotation();this.$element.bind("tabs-activate",function(e,t){n.options.activate.call(this,e,t)});this.$element.bind("tabs-deactivate",function(e,t){n.options.deactivate.call(this,e,t)});this.$element.bind("tabs-activate-state",function(e,t){n.options.activateState.call(this,e,t)});this.$element.bind("tabs-load",function(e){var r=n._getTabRefBySelector(t.location.hash),i;n._setState(e);if(n.options.startCollapsed!==!0&&(n.options.startCollapsed!=="accordion"||n.state!=="accordion")){r>=0&&!n._getTab(r).disabled?i=n._getTab(r):n.options.active>0&&!n._getTab(n.options.active).disabled?i=n._getTab(n.options.active):i=n._getTab(0);n._openTab(e,i);n.options.load.call(this,e,i)}});this.$element.trigger("tabs-load")};i.prototype._loadElements=function(){var t=this,n=this.$element.children("ul"),r=[],i=0;this.$element.addClass("r-tabs");n.addClass("r-tabs-nav");e("li",n).each(function(){var n=e(this),s=n.hasClass(t.options.classes.stateExcluded),o,u,a,f,l;if(!s){o=e("a",n);l=o.attr("href");u=e(l);a=e("<div></div>").insertBefore(u);f=e("<a></a>").attr("href",l).html(o.html()).appendTo(a);var c={_ignoreHashChange:!1,id:i,disabled:e.inArray(i,t.options.disabled)!==-1,tab:e(this),anchor:e("a",n),panel:u,selector:l,accordionTab:a,accordionAnchor:f,active:!1};i++;r.push(c)}});return r};i.prototype._loadClasses=function(){for(var e=0;e<this.tabs.length;e++){this.tabs[e].tab.addClass(this.options.classes.stateDefault).addClass(this.options.classes.tab);this.tabs[e].anchor.addClass(this.options.classes.anchor);this.tabs[e].panel.addClass(this.options.classes.stateDefault).addClass(this.options.classes.panel);this.tabs[e].accordionTab.addClass(this.options.classes.accordionTitle);this.tabs[e].accordionAnchor.addClass(this.options.classes.anchor);if(this.tabs[e].disabled){this.tabs[e].tab.removeClass(this.options.classes.stateDefault).addClass(this.options.classes.stateDisabled);this.tabs[e].accordionTab.removeClass(this.options.classes.stateDefault).addClass(this.options.classes.stateDisabled)}}};i.prototype._loadEvents=function(){var e=this,n=function(n){var r=e._getCurrentTab(),i=n.data.tab;n.preventDefault();if(!i.disabled){e.options.setHash&&(t.location.hash=i.selector);n.data.tab._ignoreHashChange=!0;if(r!==i||e._isCollapisble()){e._closeTab(n,r);(r!==i||!e._isCollapisble())&&e._openTab(n,i,!1,!0)}}};for(var r=0;r<this.tabs.length;r++){this.tabs[r].anchor.on("click",{tab:e.tabs[r]},n);this.tabs[r].accordionAnchor.on("click",{tab:e.tabs[r]},n)}};i.prototype._setState=function(){var t=e("ul",this.$element),n=this.state;t.is(":visible")?this.state="tabs":this.state="accordion";this.state!==n&&this.$element.trigger("tabs-activate-state",{oldState:n,newState:this.state})};i.prototype._openTab=function(e,t,n,r){var i=this;n&&this._closeTab(e,this._getCurrentTab());r&&this.rotateInterval>0&&this.stopRotation();t.active=!0;t.tab.removeClass(i.options.classes.stateDefault).addClass(i.options.classes.stateActive);t.accordionTab.removeClass(i.options.classes.stateDefault).addClass(i.options.classes.stateActive);i._doTransition(t.panel,i.options.animation,"open",function(){t.panel.removeClass(i.options.classes.stateDefault).addClass(i.options.classes.stateActive)});this.$element.trigger("tabs-activate",t)};i.prototype._closeTab=function(e,t){var r=this;if(t!==n){t.active=!1;t.tab.removeClass(r.options.classes.stateActive).addClass(r.options.classes.stateDefault);r._doTransition(t.panel,r.options.animation,"close",function(){t.accordionTab.removeClass(r.options.classes.stateActive).addClass(r.options.classes.stateDefault);t.panel.removeClass(r.options.classes.stateActive).addClass(r.options.classes.stateDefault)},!0);this.$element.trigger("tabs-deactivate",t)}};i.prototype._doTransition=function(e,t,n,r,i){var s,o=this;switch(t){case"slide":s=n==="open"?"slideDown":"slideUp";break;case"fade":s=n==="open"?"fadeIn":"fadeOut";break;default:s=n==="open"?"show":"hide";o.options.duration=0}this.$queue.queue("responsive-tabs",function(i){e[s]({duration:o.options.duration,complete:function(){r.call(e,t,n);i()}})});(n==="open"||i)&&this.$queue.dequeue("responsive-tabs")};i.prototype._isCollapisble=function(){return typeof this.options.collapsible=="boolean"&&this.options.collapsible||typeof this.options.collapsible=="string"&&this.options.collapsible===this.getState()};i.prototype._getTab=function(e){return this.tabs[e]};i.prototype._getTabRefBySelector=function(e){for(var t=0;t<this.tabs.length;t++)if(this.tabs[t].selector===e)return t;return-1};i.prototype._getCurrentTab=function(){return this._getTab(this._getCurrentTabRef())};i.prototype._getNextTabRef=function(e){var t=e||this._getCurrentTabRef(),n=t===this.tabs.length-1?0:t+1;return this._getTab(n).disabled?this._getNextTabRef(n):n};i.prototype._getPreviousTabRef=function(){return this._getCurrentTabRef()===0?this.tabs.length-1:this._getCurrentTabRef()-1};i.prototype._getCurrentTabRef=function(){for(var e=0;e<this.tabs.length;e++)if(this.tabs[e].active)return e;return-1};i.prototype.activate=function(e,t){var n=jQuery.Event("tabs-activate"),r=this._getTab(e);r.disabled||this._openTab(n,r,!0,t||!0)};i.prototype.deactivate=function(e){var t=jQuery.Event("tabs-dectivate"),n=this._getTab(e);n.disabled||this._closeTab(t,n)};i.prototype.getState=function(){return this.state};i.prototype.startRotation=function(t){var n=this;if(!(this.tabs.length>this.options.disabled.length))throw new Error("Rotation is not possible if all tabs are disabled");this.rotateInterval=setInterval(function(){var e=jQuery.Event("rotate");n._openTab(e,n._getTab(n._getNextTabRef()),!0)},t||(e.isNumeric(n.options.rotate)?n.options.rotate:4e3))};i.prototype.stopRotation=function(){t.clearInterval(this.rotateInterval);this.rotateInterval=0};e.fn.responsiveTabs=function(t){var r=arguments;if(t===n||typeof t=="object")return this.each(function(){e.data(this,"responsivetabs")||e.data(this,"responsivetabs",new i(this,t))});if(typeof t=="string"&&t[0]!=="_"&&t!=="init")return this.each(function(){var n=e.data(this,"responsivetabs");n instanceof i&&typeof n[t]=="function"&&n[t].apply(n,Array.prototype.slice.call(r,1));t==="destroy"&&e.data(this,"responsivetabs",null)})}})(jQuery,window);
mediafromftp.php ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Media from FTP
4
+ Plugin URI: https://wordpress.org/plugins/media-from-ftp/
5
+ Version: 9.82
6
+ Description: Register to media library from files that have been uploaded by FTP.
7
+ Author: Katsushi Kawamori
8
+ Author URI: https://riverforest-wp.info/
9
+ Text Domain: media-from-ftp
10
+ Domain Path: /languages
11
+ */
12
+
13
+ /* Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; version 2 of the License.
17
+
18
+ This program is distributed in the hope that it will be useful,
19
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ GNU General Public License for more details.
22
+
23
+ You should have received a copy of the GNU General Public License
24
+ along with this program; if not, write to the Free Software
25
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
+ */
27
+
28
+ load_plugin_textdomain('media-from-ftp');
29
+ // load_plugin_textdomain('media-from-ftp', false, basename( dirname( __FILE__ ) ) . '/languages' );
30
+
31
+ define("MEDIAFROMFTP_PLUGIN_BASE_FILE", plugin_basename(__FILE__));
32
+ define("MEDIAFROMFTP_PLUGIN_BASE_DIR", dirname(__FILE__));
33
+ define("MEDIAFROMFTP_PLUGIN_URL", plugins_url($path='',$scheme=null).'/media-from-ftp');
34
+
35
+ if ( !defined('MEDIAFROMFTP_ADDON_CATEGORY_PLUGIN_BASE_DIR') ) {
36
+ define("MEDIAFROMFTP_ADDON_CATEGORY_PLUGIN_BASE_DIR", wp_normalize_path(WP_PLUGIN_DIR.'/media-from-ftp-add-on-category'));
37
+ }
38
+ if ( !defined('MEDIAFROMFTP_ADDON_CLI_PLUGIN_BASE_DIR') ) {
39
+ define("MEDIAFROMFTP_ADDON_CLI_PLUGIN_BASE_DIR", wp_normalize_path(WP_PLUGIN_DIR.'/media-from-ftp-add-on-cli'));
40
+ }
41
+ if ( !defined('MEDIAFROMFTP_ADDON_CLI_PLUGIN_URL') ) {
42
+ define("MEDIAFROMFTP_ADDON_CLI_PLUGIN_URL", plugins_url($path='',$scheme=null).'/media-from-ftp-add-on-cli');
43
+ }
44
+ if ( !defined('MEDIAFROMFTP_ADDON_EXIF_PLUGIN_BASE_DIR') ) {
45
+ define("MEDIAFROMFTP_ADDON_EXIF_PLUGIN_BASE_DIR", wp_normalize_path(WP_PLUGIN_DIR.'/media-from-ftp-add-on-exif'));
46
+ }
47
+ if ( !defined('MEDIAFROMFTP_ADDON_WPCRON_PLUGIN_BASE_DIR') ) {
48
+ define("MEDIAFROMFTP_ADDON_WPCRON_PLUGIN_BASE_DIR", wp_normalize_path(WP_PLUGIN_DIR.'/media-from-ftp-add-on-wpcron'));
49
+ }
50
+
51
+ include_once MEDIAFROMFTP_PLUGIN_BASE_DIR.'/inc/MediaFromFtp.php';
52
+ $mediafromftp = new MediaFromFtp();
53
+ define("MEDIAFROMFTP_PLUGIN_SITE_URL", $mediafromftp->siteurl());
54
+ list($upload_dir, $upload_url, $upload_path) = $mediafromftp->upload_dir_url_path();
55
+ define("MEDIAFROMFTP_PLUGIN_UPLOAD_DIR", $upload_dir);
56
+ define("MEDIAFROMFTP_PLUGIN_UPLOAD_URL", $upload_url);
57
+ define("MEDIAFROMFTP_PLUGIN_UPLOAD_PATH", $upload_path);
58
+ unset($mediafromftp, $upload_dir, $upload_url, $upload_path);
59
+
60
+ define("MEDIAFROMFTP_PLUGIN_TMP_URL", MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/media-from-ftp-tmp');
61
+ define("MEDIAFROMFTP_PLUGIN_TMP_DIR", MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.'/media-from-ftp-tmp');
62
+ define("MEDIAFROMFTP_PLUGIN_DISALLOW_TMP_DIR", '/'.MEDIAFROMFTP_PLUGIN_UPLOAD_PATH.'/media-from-ftp-tmp/');
63
+
64
+ // Make tmp dir
65
+ if ( !is_dir( MEDIAFROMFTP_PLUGIN_TMP_DIR ) ) {
66
+ wp_mkdir_p( MEDIAFROMFTP_PLUGIN_TMP_DIR );
67
+ }
68
+
69
+ require_once( MEDIAFROMFTP_PLUGIN_BASE_DIR.'/req/MediaFromFtpRegist.php' );
70
+ $mediafromftpregist = new MediaFromFtpRegist();
71
+ register_activation_hook( __FILE__, array($mediafromftpregist, 'log_settings') );
72
+ add_action( 'plugins_loaded', array($mediafromftpregist, 'log_settings') );
73
+ add_action( 'admin_init', array($mediafromftpregist, 'register_settings') );
74
+ unset($mediafromftpregist);
75
+
76
+ require_once( MEDIAFROMFTP_PLUGIN_BASE_DIR.'/req/MediaFromFtpAdmin.php' );
77
+ $mediafromftpadmin = new MediaFromFtpAdmin();
78
+ add_filter( 'plugin_action_links', array($mediafromftpadmin, 'settings_link'), 10, 2 );
79
+ add_action( 'admin_menu', array($mediafromftpadmin, 'add_pages') );
80
+ add_action( 'admin_enqueue_scripts', array($mediafromftpadmin, 'load_custom_wp_admin_style') );
81
+ add_action( 'admin_footer', array($mediafromftpadmin, 'load_custom_wp_admin_style2') );
82
+ add_action( 'admin_footer', array($mediafromftpadmin, 'custom_bulk_admin_footer') );
83
+ add_action( 'screen_settings', array($mediafromftpadmin, 'search_register_show_screen_options'), 10, 2 );
84
+ add_filter( 'set-screen-option', array($mediafromftpadmin, 'search_register_set_screen_options'), 11, 3 );
85
+ add_filter( 'contextual_help', array($mediafromftpadmin, 'search_register_help_tab'), 12, 3);
86
+ add_filter( 'robots_txt', array($mediafromftpadmin, 'custom_robots_txt') );
87
+ unset($mediafromftpadmin);
88
+
89
+ require_once( MEDIAFROMFTP_PLUGIN_BASE_DIR.'/req/MediaFromFtpAjax.php' );
90
+ $mediafromftpajax = new MediaFromFtpAjax();
91
+ $action1 = 'mediafromftp-update-ajax-action';
92
+ $action2 = 'mediafromftp-import-ajax-action';
93
+ add_action( 'wp_ajax_'.$action1, array($mediafromftpajax, 'mediafromftp_update_callback') );
94
+ add_action( 'wp_ajax_mediafromftp_message', array($mediafromftpajax, 'mediafromftp_message_callback') );
95
+ add_action( 'wp_ajax_'.$action2, array($mediafromftpajax, 'mediafromftp_medialibraryimport_update_callback') );
96
+ add_action( 'wp_ajax_mediafromftp_medialibraryimport_message', array($mediafromftpajax, 'mediafromftp_medialibraryimport_message_callback') );
97
+ unset($mediafromftpajax, $action1, $action2);
98
+
99
+ ?>
readme.txt ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Media from FTP ===
2
+ Contributors: Katsushi Kawamori
3
+ Donate link: https://pledgie.com/campaigns/28307
4
+ Tags: files, ftp, import, media, sync, uploads
5
+ Requires at least: 3.6.0
6
+ Requires PHP: 5.3.0
7
+ Tested up to: 4.8
8
+ Stable tag: 9.82
9
+ License: GPLv2 or later
10
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
+
12
+ Register to media library from files that have been uploaded by FTP.
13
+
14
+ == Description ==
15
+
16
+ = Register to media library from files that have been uploaded by FTP. =
17
+ * This create a thumbnail of the image file.
18
+ * This create a metadata(Images, Videos, Audios).
19
+ * Change the date/time.
20
+ * Work with [DateTimePicker](https://xdsoft.net/jqplugins/datetimepicker/). jQuery plugin select date/time.
21
+ * Export the log to a CSV file.
22
+ * To Import the files to Media Library from a WordPress export file.
23
+ * You can register a large number of files without timeout work with Ajax.
24
+
25
+ = Why I made this? =
26
+ * In the media uploader, you may not be able to upload by the environment of server. That's when the files are large. You do not mind the size of the file if FTP.
27
+
28
+ = Special Thanks! Created Banner & Icon =
29
+ * [Li-An](https://www.li-an.fr/blog/)
30
+
31
+ = Special Thanks! Translator =
32
+ * Deutsch [pixelverbieger](https://www.pixelverbieger.de/)
33
+ * Español [apasionados](https://apasionados.es/)
34
+ * Français [Li-An](https://www.echodesplugins.li-an.fr/)
35
+
36
+ == Installation ==
37
+
38
+ 1. Upload `media-from-ftp` directory to the `/wp-content/plugins/` directory
39
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
40
+
41
+ == Frequently Asked Questions ==
42
+
43
+ = A server error is displayed because there are too many files. "Search & Register" screen does not appear. =
44
+ * Media from FTP Settings -> Other -> Limit number of search files
45
+ * Please reduce this number.
46
+
47
+ = Certain file types can not be searched. =
48
+ * If you want to add the mime type that can be used in the media library to each file type, Please use the <a href="https://wordpress.org/plugins/mime-types-plus/">Mime Types Plus</a>.
49
+
50
+ = I will not find a file with name like this: a-b-0x0.jpg. =
51
+ * Media from FTP Search & Register -> Screen Options -> Search method for the exclusion of the thumbnail
52
+ * Check of "Unusual selection. if you want to search for filename that contains such -0x0. It is low speed."
53
+
54
+ = Where is it better to upload files? =
55
+ * Upload directory is any of the following locations.
56
+ * Single-site wp-content/uploads
57
+ * Multisite wp-content/uploads/sites/*
58
+
59
+ = I want to register file for any folder. =
60
+ * Media from FTP Settings -> Register -> Date.
61
+ * Uncheck of "Organize my uploads into month- and year-based folders".
62
+
63
+ = I want to register file to "month- and year-based folders" without relevant to the timestamp of the file. =
64
+ * Media from FTP Settings -> Register -> Date.
65
+ * Uncheck of "Organize my uploads into month- and year-based folders".
66
+
67
+ = File at the time of registration is moved to another directory. =
68
+ * If checked "Organize my uploads into month- and year-based folders", it will move the file at the time of registration to year month-based folders. If you want to register in the same directory, Please uncheck.
69
+
70
+ = The original file is deleted. =
71
+ * The case of the following of this plugin to delete the file.
72
+ 1. If it contains spaces in the file name. Convert to "-". And remove original file. image example.jpg -> image-example.jpg
73
+ 2. If the file name is a multi-byte. It makes the MD5 conversion. And remove original file. image例.jpg -> 2edd9ad56212ce13a39f25b429b09012.jpg
74
+ 3. If checked "Organize my uploads into month- and year-based folders", it copy the file to the "month- and year-based folder" and then delete the original file. wp-content/uploads/sites/2/image-example.jpg -> wp-content/uploads/sites/2/2015/09/image-example.jpg
75
+ * Thumbnail creation, database registration, do in file after copy.
76
+
77
+ = The original file is deleted, it will be the one that has been added to eight characters to the end of the file. =
78
+ * When find the same file name in the media library in order to avoid duplication of the file, adds the date and time, minute, and second at the time it was registered in the end.
79
+ * image-example.jpg -> image-example03193845.jpg
80
+ * Meaning 03193845 -> 3rd 19h38m45s
81
+
82
+ = 'Fatal error: Maximum execution time of ** seconds exceeded.' get an error message. =
83
+ * Media from FTP Settings -> Other -> Execution time
84
+ * Please increasing the number of seconds.
85
+
86
+ = I want to change the date at the time of registration. =
87
+ * Media from FTP Settings -> Register -> Date -> Get the date/time of the file, and updated based on it. Change it if necessary.
88
+ * Please checked.
89
+
90
+ = I want to register at the date of the Exif information. =
91
+ * Media from FTP Settings -> Register -> Date -> Get the date/time of the file, and updated based on it. Change it if necessary.Get by priority if there is date and time of the Exif information.
92
+ * Please checked.
93
+
94
+ = I would like to hide the files do not need to search & registration screen. =
95
+ * Media from FTP Search & Register -> Screen Options -> Exclude file
96
+ * Please enter the exclusion file. It can be a regular expression.
97
+
98
+ = I want to turn off the creation of additional images such as thumbnail. =
99
+ * It conforms to the WordPress settings.
100
+ * Settings-> Media
101
+ * Please change the six values to all zeros.
102
+ * Please comment out the 'set_post_thumbnail_size' or 'add_image_size' of theme's functions.php.
103
+
104
+ == Screenshots ==
105
+
106
+ 1. Search file display
107
+ 2. Settings Screen Options
108
+ 3. Settings Register
109
+ 4. Settings Other
110
+ 5. Registration file selection
111
+ 6. File registration result
112
+ 7. Log screen
113
+ 8. Import File Load
114
+ 9. Import result
115
+
116
+ == Changelog ==
117
+
118
+ = 9.82 =
119
+ Fixed problem of add-ons.
120
+
121
+ = 9.81 =
122
+ Fixed problem of add-ons.
123
+
124
+ = 9.80 =
125
+ Fixed [PHP Object Injection Vulnerability](https://www.pluginvulnerabilities.com/2017/09/13/authenticated-php-object-injection-vulnerability-in-media-from-ftp/). Please do not use the previous version.
126
+
127
+ == Upgrade Notice ==
128
+
129
+ = 9.80 =
130
+ Fixed [PHP Object Injection Vulnerability](https://www.pluginvulnerabilities.com/2017/09/13/authenticated-php-object-injection-vulnerability-in-media-from-ftp/). Please do not use the previous version.
131
+
req/MediaFromFtpAdmin.php ADDED
@@ -0,0 +1,1845 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media from FTP
4
+ *
5
+ * @package Media from FTP
6
+ * @subpackage MediafromFTPAdmin Main & Management screen
7
+ /* Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
8
+ This program is free software; you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation; version 2 of the License.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program; if not, write to the Free Software
19
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ */
21
+
22
+ class MediaFromFtpAdmin {
23
+
24
+ private $is_add_on_activate;
25
+
26
+ /* ==================================================
27
+ * Construct
28
+ * @since 9.81
29
+ */
30
+ function __construct() {
31
+
32
+ $category_active = FALSE;
33
+ if( function_exists('media_from_ftp_add_on_category_load_textdomain') ){
34
+ include_once MEDIAFROMFTP_ADDON_CATEGORY_PLUGIN_BASE_DIR.'/inc/MediaFromFtpAddOnCategory.php';
35
+ $category_active = TRUE;
36
+ }
37
+ $exif_active = FALSE;
38
+ if( function_exists('media_from_ftp_add_on_exif_load_textdomain') ){
39
+ include_once MEDIAFROMFTP_ADDON_EXIF_PLUGIN_BASE_DIR.'/inc/MediaFromFtpAddOnExif.php';
40
+ $exif_active = TRUE;
41
+ }
42
+ $cli_active = FALSE;
43
+ if( function_exists('media_from_ftp_add_on_cli_load_textdomain') ){
44
+ require_once( MEDIAFROMFTP_ADDON_CLI_PLUGIN_BASE_DIR.'/req/MediaFromFtpCli.php' );
45
+ $cli_active = TRUE;
46
+ }
47
+ $wpcron_active = FALSE;
48
+ if( function_exists('media_from_ftp_add_on_wpcron_load_textdomain') ){
49
+ include_once MEDIAFROMFTP_ADDON_WPCRON_PLUGIN_BASE_DIR.'/inc/MediaFromFtpAddOnWpcron.php';
50
+ $wpcron_active = TRUE;
51
+ }
52
+
53
+ $this->is_add_on_activate = array(
54
+ 'category' => $category_active,
55
+ 'exif' => $exif_active,
56
+ 'cli' => $cli_active,
57
+ 'wpcron' => $wpcron_active
58
+ );
59
+
60
+ if(!class_exists('MediaFromFtp')){
61
+ include_once MEDIAFROMFTP_PLUGIN_BASE_DIR.'/inc/MediaFromFtp.php';
62
+ }
63
+ if(!class_exists('TT_MediaFromFtp_List_Table')){
64
+ require_once( MEDIAFROMFTP_PLUGIN_BASE_DIR.'/req/MediaFromFtpListTable.php' );
65
+ }
66
+
67
+ }
68
+
69
+ /* ==================================================
70
+ * Add a "Settings" link to the plugins page
71
+ * @since 1.0
72
+ */
73
+ function settings_link( $links, $file ) {
74
+ static $this_plugin;
75
+ if ( empty($this_plugin) ) {
76
+ $this_plugin = MEDIAFROMFTP_PLUGIN_BASE_FILE;
77
+ }
78
+ if ( $file == $this_plugin ) {
79
+ $links[] = '<a href="'.admin_url('admin.php?page=mediafromftp').'">Media from FTP</a>';
80
+ $links[] = '<a href="'.admin_url('admin.php?page=mediafromftp-search-register').'">'.__('Search & Register', 'media-from-ftp').'</a>';
81
+ $links[] = '<a href="'.admin_url('admin.php?page=mediafromftp-settings').'">'.__( 'Settings').'</a>';
82
+ $mediafromftp = new MediaFromFtp();
83
+ if ( $this->is_add_on_activate['wpcron'] ) {
84
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
85
+ $links[] = $mediafromftpaddonwpcron->mediafromftp_settings_link_html();
86
+ unset($mediafromftpaddonwpcron);
87
+ }
88
+ $links[] = '<a href="'.admin_url('admin.php?page=mediafromftp-log').'">'.__('Log', 'media-from-ftp').'</a>';
89
+ $links[] = '<a href="'.admin_url('admin.php?page=mediafromftp-import').'">'.__('Import').'</a>';
90
+ $links[] = '<a href="'.admin_url('admin.php?page=mediafromftp-addons').'">'.__('Add-Ons', 'media-from-ftp').'</a>';
91
+ }
92
+ return $links;
93
+ }
94
+
95
+ /* ==================================================
96
+ * Add page
97
+ * @since 1.0
98
+ */
99
+ function add_pages() {
100
+ add_menu_page(
101
+ 'Media from FTP',
102
+ 'Media from FTP',
103
+ 'upload_files',
104
+ 'mediafromftp',
105
+ array($this, 'manage_page'),
106
+ 'dashicons-upload'
107
+ );
108
+ add_submenu_page(
109
+ 'mediafromftp',
110
+ __('Search & Register', 'media-from-ftp'),
111
+ __('Search & Register', 'media-from-ftp'),
112
+ 'upload_files',
113
+ 'mediafromftp-search-register',
114
+ array($this, 'search_register_page')
115
+ );
116
+ add_submenu_page(
117
+ 'mediafromftp',
118
+ __('Settings'),
119
+ __('Settings'),
120
+ 'upload_files',
121
+ 'mediafromftp-settings',
122
+ array($this, 'settings_page')
123
+ );
124
+ $mediafromftp = new MediaFromFtp();
125
+ if ( $this->is_add_on_activate['wpcron'] ) {
126
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
127
+ $mediafromftpaddonwpcron->mediafromftp_add_submenu();
128
+ unset($mediafromftpaddonwpcron);
129
+ }
130
+ add_submenu_page(
131
+ 'mediafromftp',
132
+ __('Log', 'media-from-ftp'),
133
+ __('Log', 'media-from-ftp'),
134
+ 'upload_files',
135
+ 'mediafromftp-log',
136
+ array($this, 'log_page')
137
+ );
138
+ add_submenu_page(
139
+ 'mediafromftp',
140
+ __('Import'),
141
+ __('Import'),
142
+ 'upload_files',
143
+ 'mediafromftp-import',
144
+ array($this, 'medialibrary_import_page')
145
+ );
146
+ add_submenu_page(
147
+ 'mediafromftp',
148
+ __('Add-Ons', 'media-from-ftp'),
149
+ __('Add-Ons', 'media-from-ftp'),
150
+ 'upload_files',
151
+ 'mediafromftp-addons',
152
+ array($this, 'addons_page')
153
+ );
154
+ }
155
+
156
+ /* ==================================================
157
+ * Show Screen Option Search & Register
158
+ * @since 9.52
159
+ */
160
+ function search_register_show_screen_options( $status, $args ) {
161
+
162
+ $mediafromftp_settings = get_option($this->wp_options_name());
163
+
164
+ $return = $status;
165
+ if ( $args->base == 'media-from-ftp_page_mediafromftp-search-register' ) {
166
+ $return .= '<div style="display: block; padding: 5px 15px">';
167
+ $return .= '<div class="item-mediafromftp-settings">';
168
+ $return .= '<legend>'.__('Pagination').'</legend>';
169
+ $return .= '<label>'.__('Number of items per page:').'</label>';
170
+ $return .= '<input type="number" step="1" min="1" max="999" class="screen-per-page" name="mediafromftp_pagemax" maxlength="3" value="'.$mediafromftp_settings['pagemax'].'">';
171
+ $return .= '</div>';
172
+
173
+ $return .= '<div class="item-mediafromftp-settings">';
174
+ $return .= '<legend>'.__('Date and time input assistance', 'media-from-ftp').'</legend>';
175
+ $return .= '<div style="display: block;padding:5px 5px">';
176
+ if ($mediafromftp_settings['datetimepicker'] == TRUE) {
177
+ $return .= '<input type="checkbox" name="mediafromftp_datetimepicker" value="1" checked />';
178
+ } else {
179
+ $return .= '<input type="checkbox" name="mediafromftp_datetimepicker" value="1" />';
180
+ }
181
+ $return .= '<a href="https://xdsoft.net/jqplugins/datetimepicker/" target="_blank" style="text-decoration: none;">Date Time Picker</a>(jQuery '.__('Plugin').')';
182
+ $return .= '</div>';
183
+ $return .= '</div>';
184
+
185
+ $return .= '<div class="item-mediafromftp-settings">';
186
+ $return .= '<legend>'.__('Display of search results', 'media-from-ftp').'</legend>';
187
+ $return .= '<div style="display: block;padding:5px 5px">';
188
+ if ($mediafromftp_settings['search_display_metadata'] == TRUE) {
189
+ $return .= '<input type="radio" name="search_display_metadata" value="1" checked>';
190
+ } else {
191
+ $return .= '<input type="radio" name="search_display_metadata" value="1">';
192
+ }
193
+ $return .= __('Usual selection. It is user-friendly. It displays a thumbnail and metadata. It is low speed.', 'media-from-ftp');
194
+ $return .= '</div>';
195
+ $return .= '<div style="display: block;padding:5px 5px">';
196
+ if ($mediafromftp_settings['search_display_metadata'] == FALSE) {
197
+ $return .= '<input type="radio" name="search_display_metadata" value="0" checked>';
198
+ } else {
199
+ $return .= '<input type="radio" name="search_display_metadata" value="0">';
200
+ }
201
+ $return .= __('Unusual selection. Only the file name and output. It is suitable for the search of large amounts of data. It is hi speed.', 'media-from-ftp');
202
+ $return .= '</div>';
203
+ $return .= '</div>';
204
+
205
+ $return .= '<div class="item-mediafromftp-settings">';
206
+ $return .= '<legend>'.__('Exclude file', 'media-from-ftp').'</legend>';
207
+ $return .= '<div style="display: block;padding:5px 5px">';
208
+ $return .= '<div>'.__('Regular expression is possible.', 'media-from-ftp').'</div>';
209
+ $return .= '<textarea id="mediafromftp_exclude" name="mediafromftp_exclude" rows="3" style="width: 100%;">'.$mediafromftp_settings['exclude'].'</textarea>';
210
+ $return .= '</div>';
211
+ $return .= '</div>';
212
+
213
+ $return .= '<div class="item-mediafromftp-settings">';
214
+ $return .= '<legend>'.__('Search method for the exclusion of the thumbnail', 'media-from-ftp').'</legend>';
215
+ $return .= '<div style="display: block;padding:5px 5px">';
216
+ if ($mediafromftp_settings['thumb_deep_search'] == FALSE) {
217
+ $return .= '<input type="radio" name="mediafromftp_thumb_deep_search" value="0" checked>';
218
+ } else {
219
+ $return .= '<input type="radio" name="mediafromftp_thumb_deep_search" value="0">';
220
+ }
221
+ $return .= __('Usual selection. It is hi speed.', 'media-from-ftp');
222
+ $return .= '</div>';
223
+ $return .= '<div style="display: block;padding:5px 5px">';
224
+ if ($mediafromftp_settings['thumb_deep_search'] == TRUE) {
225
+ $return .= '<input type="radio" name="mediafromftp_thumb_deep_search" value="1" checked>';
226
+ } else {
227
+ $return .= '<input type="radio" name="mediafromftp_thumb_deep_search" value="1">';
228
+ }
229
+ $return .= __('Unusual selection. if you want to search for filename that contains such -0x0. It is low speed.', 'media-from-ftp');
230
+ $return .= '</div>';
231
+ $return .= '</div>';
232
+ $return .= '<div style="display: block;padding:5px 5px">'.get_submit_button( __( 'Apply' ), 'primary', 'media-from-ftp-screen-options-apply', FALSE ).'</div>';
233
+ $return .= '</div>';
234
+
235
+ $return .= '<input type="hidden" name="wp_screen_options[option]" value="media_from_ftp_show_screen" />';
236
+ $return .= '<input type="hidden" name="wp_screen_options[value]" value="2" />';
237
+ }
238
+ return $return;
239
+ }
240
+
241
+ /* ==================================================
242
+ * Save Screen Option Search & Register
243
+ * @since 9.52
244
+ */
245
+ function search_register_set_screen_options($status, $option, $value) {
246
+ if ( 'media_from_ftp_show_screen' == $option ) {
247
+ $this->options_updated($value);
248
+ return $value;
249
+ }
250
+ return $status;
251
+ }
252
+
253
+ /* ==================================================
254
+ * Help Tab
255
+ * @since 9.53
256
+ */
257
+ function search_register_help_tab($help, $screen_id, $screen) {
258
+
259
+ if( $screen_id === 'media-from-ftp_page_mediafromftp-search-register' || $screen_id === 'media-from-ftp_page_mediafromftp-settings' || $screen_id === 'media-from-ftp_page_mediafromftp-event' || $screen_id === 'media-from-ftp_page_mediafromftp-log' || $screen_id === 'media-from-ftp_page_mediafromftp-import' || $screen_id === 'media-from-ftp_page_mediafromftp-addons' ) {
260
+ $sidebar = '<p><strong>'.__('For more information:').'</strong></p>';
261
+ $sidebar .= '<p><a href="'.__('https://wordpress.org/plugins/media-from-ftp/faq', 'media-from-ftp').'" target="_blank">'.__('FAQ').'</a></p>';
262
+ $sidebar .= '<p><a href="https://wordpress.org/support/plugin/media-from-ftp" target="_blank">'.__('Support Forums').'</a></p>';
263
+ $sidebar .= '<p><a href="https://wordpress.org/support/view/plugin-reviews/media-from-ftp" target="_blank">'.__('Reviews', 'media-from-ftp').'</a></p>';
264
+ $sidebar .= '<p><a href="https://translate.wordpress.org/projects/wp-plugins/media-from-ftp" target="_blank">'.sprintf(__('Translations for %s'), 'Media from FTP').'</a></p>';
265
+ $sidebar .= '<p><a style="text-decoration: none;" href="https://www.facebook.com/katsushikawamori/" target="_blank"><span class="dashicons dashicons-facebook"></span></a> <a style="text-decoration: none;" href="https://twitter.com/dodesyo312" target="_blank"><span class="dashicons dashicons-twitter"></span></a></p>';
266
+ $sidebar .= '<p><a href="https://pledgie.com/campaigns/28307" target="_blank">'.__('Donate to this plugin &#187;').'</a></p>';
267
+
268
+ $tabs = $this->get_help_message($screen_id);
269
+ foreach($tabs as $tab) {
270
+ $screen->add_help_tab($tab);
271
+ }
272
+ $screen->set_help_sidebar($sidebar);
273
+ }
274
+ }
275
+
276
+ /* ==================================================
277
+ * Help Tab for message
278
+ * @param string $screen_id
279
+ * @return array $tab
280
+ * @since 9.53
281
+ */
282
+ function get_help_message($screen_id) {
283
+
284
+ $upload_dir_html = '<span style="color: red;">'.MEDIAFROMFTP_PLUGIN_UPLOAD_PATH.'</span>';
285
+ $mediafromftp = new MediaFromFtp();
286
+
287
+ switch ($screen_id) {
288
+ case "media-from-ftp_page_mediafromftp-search-register":
289
+ $outline = '<p>'.sprintf(__('Search the upload directory(%1$s) and display files that do not exist in the media library.', 'media-from-ftp'), $upload_dir_html).'</p>';
290
+ $outline .= '<p>'.sprintf(__('Please check and press the "%1$s" button.', 'media-from-ftp'), __('Update Media')).'</p>';
291
+ $outline .= '<p>'.sprintf(__('Options for searching can be specified with "%1$s".', 'media-from-ftp'), __('Screen Options')).'</p>';
292
+ break;
293
+ case "media-from-ftp_page_mediafromftp-settings":
294
+ $outline = '<p>'.sprintf(__('"%1$s" sets options for %2$s registration.', 'media-from-ftp'), __('Register'), __('Media Library')).'</p>';
295
+ $outline .= '<p>'.sprintf(__('"%1$s" sets other options.', 'media-from-ftp'), __('Other', 'media-from-ftp')).'</p>';
296
+ if ( $this->is_add_on_activate['cli'] ) {
297
+ $mediafromftpcli = new MediaFromFtpCli();
298
+ $outline .= $mediafromftpcli->mediafromftp_settings_helptab_html();
299
+ }
300
+ break;
301
+ case "media-from-ftp_page_mediafromftp-event":
302
+ if ( $this->is_add_on_activate['wpcron'] ) {
303
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
304
+ $outline = $mediafromftpaddonwpcron->mediafromftp_event_helptab_html();
305
+ }
306
+ break;
307
+ case "media-from-ftp_page_mediafromftp-log":
308
+ $outline = '<p>'.__('Display history of registration.', 'media-from-ftp').'</p>';
309
+ $outline .= '<p>'.__('You can export to CSV format.', 'media-from-ftp').'</p>';
310
+ break;
311
+ case "media-from-ftp_page_mediafromftp-import":
312
+ $outline = '<p>'.__('To Import the files to Media Library from a WordPress export file.', 'media-from-ftp').'</p>';
313
+ $outline .= '<p>'.sprintf(__('In uploads directory(%1$s), that you need to copy the file to the same state as the import source by FTP.', 'media-from-ftp'), $upload_dir_html).'</p>';
314
+ break;
315
+ case "media-from-ftp_page_mediafromftp-addons":
316
+ $outline = '<p>'.__('This page shows paid add-ons and their summaries.', 'media-from-ftp').'</p>';
317
+ $outline .= '<p>'.__('You can check whether it is installed or activated.', 'media-from-ftp').'</p>';
318
+ break;
319
+ }
320
+
321
+ $tabs = array(
322
+ array(
323
+ 'title' => __('Overview'),
324
+ 'id' => 'outline',
325
+ 'content' => $outline
326
+ )
327
+ );
328
+
329
+ return $tabs;
330
+ }
331
+
332
+ /* ==================================================
333
+ * Add Css and Script
334
+ * @since 2.23
335
+ */
336
+ function load_custom_wp_admin_style() {
337
+ if ($this->is_my_plugin_screen()) {
338
+ $mediafromftp_settings = get_option($this->wp_options_name());
339
+ if ( $mediafromftp_settings['datetimepicker'] ) {
340
+ wp_enqueue_style( 'jquery-datetimepicker', MEDIAFROMFTP_PLUGIN_URL.'/css/jquery.datetimepicker.css' );
341
+ }
342
+ wp_enqueue_style( 'jquery-responsiveTabs', MEDIAFROMFTP_PLUGIN_URL.'/css/responsive-tabs.css' );
343
+ wp_enqueue_style( 'jquery-responsiveTabs-style', MEDIAFROMFTP_PLUGIN_URL.'/css/style.css' );
344
+ wp_enqueue_style( 'mediafromftp', MEDIAFROMFTP_PLUGIN_URL.'/css/mediafromftp.css' );
345
+ wp_enqueue_script( 'jquery' );
346
+ if ( $mediafromftp_settings['datetimepicker'] ) {
347
+ wp_enqueue_script( 'jquery-datetimepicker', MEDIAFROMFTP_PLUGIN_URL.'/js/jquery.datetimepicker.js', null, '2.3.4' );
348
+ wp_enqueue_script( 'jquery-mediafromftp-datetimepicker', MEDIAFROMFTP_PLUGIN_URL.'/js/jquery.mediafromftp.datetimepicker.js', array('jquery') );
349
+ }
350
+ wp_enqueue_script( 'jquery-responsiveTabs', MEDIAFROMFTP_PLUGIN_URL.'/js/jquery.responsiveTabs.min.js' );
351
+
352
+ $handle = 'mediafromftp-ajax-script';
353
+ $action1 = 'mediafromftp-update-ajax-action';
354
+ $action2 = 'mediafromftp-import-ajax-action';
355
+ wp_enqueue_script( $handle, MEDIAFROMFTP_PLUGIN_URL.'/js/jquery.mediafromftp.js', array('jquery') );
356
+ wp_localize_script( $handle, 'MEDIAFROMFTPUPDATE', array(
357
+ 'ajax_url' => admin_url('admin-ajax.php'),
358
+ 'action' => $action1,
359
+ 'nonce' => wp_create_nonce( $action1 )
360
+ ));
361
+ wp_localize_script( $handle, 'MEDIAFROMFTPIMPORT', array(
362
+ 'ajax_url' => admin_url('admin-ajax.php'),
363
+ 'action' => $action2,
364
+ 'nonce' => wp_create_nonce( $action2 )
365
+ ));
366
+ }
367
+ }
368
+
369
+ /* ==================================================
370
+ * Add Script on footer
371
+ * @since 1.0
372
+ */
373
+ function load_custom_wp_admin_style2() {
374
+ if ($this->is_my_plugin_screen2()) {
375
+ if ( isset($_POST['media_from_ftp_select_author']) && $_POST['media_from_ftp_select_author'] ) {
376
+ if ( check_admin_referer('mff_select_author', 'media_from_ftp_select_author') ) {
377
+ if ( !empty($_POST['mediafromftp_select_author']) && !empty($_POST['mediafromftp_xml_file']) ) {
378
+ if ( is_file($_POST['mediafromftp_xml_file']) ) {
379
+ $select_author = array();
380
+ foreach (array_keys($_POST) as $key) {
381
+ if ( $key === 'select_author' || $key === 'mediafromftp_select_author' || $key === 'mediafromftp_xml_file' ) { // skip
382
+ } else {
383
+ if ( $_POST[$key] <> -1 ) {
384
+ $select_author[$key] = $_POST[$key];
385
+ }
386
+ }
387
+ }
388
+ $filename = $_POST['mediafromftp_xml_file'];
389
+ $mediafromftp = new MediaFromFtp();
390
+ echo $mediafromftp->make_object($filename, $select_author);
391
+ unset($mediafromftp);
392
+ unlink($filename);
393
+ }
394
+ }
395
+ }
396
+ }
397
+ }
398
+ }
399
+
400
+ /* ==================================================
401
+ * For only admin style
402
+ * @since 8.82
403
+ */
404
+ function is_my_plugin_screen() {
405
+ $screen = get_current_screen();
406
+ if (is_object($screen) && $screen->id == 'toplevel_page_mediafromftp') {
407
+ return TRUE;
408
+ } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-settings') {
409
+ return TRUE;
410
+ } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-search-register') {
411
+ return TRUE;
412
+ } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-event') {
413
+ return TRUE;
414
+ } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-log') {
415
+ return TRUE;
416
+ } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-import') {
417
+ return TRUE;
418
+ } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-addons') {
419
+ return TRUE;
420
+ } else {
421
+ return FALSE;
422
+ }
423
+ }
424
+
425
+ /* ==================================================
426
+ * For only admin style
427
+ * @since 8.82
428
+ */
429
+ function is_my_plugin_screen2() {
430
+ $screen = get_current_screen();
431
+ if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-import') {
432
+ return TRUE;
433
+ } else {
434
+ return FALSE;
435
+ }
436
+ }
437
+
438
+ /* ==================================================
439
+ * For only admin style
440
+ * @since 9.63
441
+ */
442
+ function is_my_plugin_screen3() {
443
+ $screen = get_current_screen();
444
+ if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-search-register') {
445
+ return TRUE;
446
+ } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-settings') {
447
+ return TRUE;
448
+ } else {
449
+ return FALSE;
450
+ }
451
+ }
452
+
453
+ /* ==================================================
454
+ * Main
455
+ */
456
+ function manage_page() {
457
+
458
+ if ( !current_user_can( 'upload_files' ) ) {
459
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
460
+ }
461
+
462
+ $plugin_datas = get_file_data( MEDIAFROMFTP_PLUGIN_BASE_DIR.'/mediafromftp.php', array('version' => 'Version') );
463
+ $plugin_version = __('Version:').' '.$plugin_datas['version'];
464
+
465
+ ?>
466
+
467
+ <div class="wrap">
468
+
469
+ <h2>Media from FTP
470
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" class="page-title-action"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
471
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" class="page-title-action"><?php _e('Settings'); ?></a>
472
+ <?php
473
+ if ( $this->is_add_on_activate['wpcron'] ) {
474
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
475
+ $mediafromftpaddonwpcron->mediafromftp_event_link_html();
476
+ unset($mediafromftpaddonwpcron);
477
+ }
478
+ ?>
479
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" class="page-title-action"><?php _e('Log', 'media-from-ftp'); ?></a>
480
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-import'); ?>" class="page-title-action"><?php _e('Import'); ?></a>
481
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-addons'); ?>" class="page-title-action"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
482
+ </h2>
483
+ <div style="clear: both;"></div>
484
+
485
+ <h3><?php _e('Register to media library from files that have been uploaded by FTP.', 'media-from-ftp'); ?></h3>
486
+ <span style="font-weight: bold;">
487
+ <div>
488
+ <?php echo $plugin_version; ?> |
489
+ <a style="text-decoration: none;" href="<?php _e('https://wordpress.org/plugins/media-from-ftp/faq', 'media-from-ftp'); ?>" target="_blank"><?php _e('FAQ'); ?></a> | <a style="text-decoration: none;" href="https://wordpress.org/support/plugin/media-from-ftp" target="_blank"><?php _e('Support Forums'); ?></a>
490
+ </div>
491
+ <div>
492
+ <a style="text-decoration: none;" href="https://wordpress.org/support/view/plugin-reviews/media-from-ftp" target="_blank"><?php _e('Reviews', 'media-from-ftp'); ?></a> |
493
+ <a style="text-decoration: none;" href="https://translate.wordpress.org/projects/wp-plugins/media-from-ftp" target="_blank"><?php echo sprintf(__('Translations for %s'), 'Media from FTP'); ?></a> | <a style="text-decoration: none;" href="https://www.facebook.com/katsushikawamori/" target="_blank"><span class="dashicons dashicons-facebook"></span></a> | <a style="text-decoration: none;" href="https://twitter.com/dodesyo312" target="_blank"><span class="dashicons dashicons-twitter"></span></a>
494
+ </div>
495
+ </span>
496
+
497
+ <div style="width: 250px; height: 180px; margin: 5px; padding: 5px; border: #CCC 2px solid;">
498
+ <h3><?php _e('Please make a donation if you like my work or would like to further the development of this plugin.', 'media-from-ftp'); ?></h3>
499
+ <div style="text-align: right; margin: 5px; padding: 5px;"><span style="padding: 3px; color: #ffffff; background-color: #008000">Plugin Author</span> <span style="font-weight: bold;">Katsushi Kawamori</span></div>
500
+ <a style="margin: 5px; padding: 5px;" href='https://pledgie.com/campaigns/28307' target="_blank"><img alt='Click here to lend your support to: Various Plugins for WordPress and make a donation at pledgie.com !' src='https://pledgie.com/campaigns/28307.png?skin_name=chrome' border='0' ></a>
501
+ </div>
502
+
503
+ </div>
504
+ <?php
505
+
506
+ }
507
+
508
+ /* ==================================================
509
+ * Sub Menu
510
+ */
511
+ function settings_page() {
512
+
513
+ if ( !current_user_can( 'upload_files' ) ) {
514
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
515
+ }
516
+
517
+ if ( isset($_POST['media_from_ftp_settings']) && $_POST['media_from_ftp_settings'] ) {
518
+ if ( check_admin_referer('mff_settings', 'media_from_ftp_settings') ) {
519
+ $submenu = 1;
520
+ $this->options_updated($submenu);
521
+ }
522
+ }
523
+ if ( isset($_POST['media_from_ftp_clear_cash']) && $_POST['media_from_ftp_clear_cash'] ) {
524
+ if ( check_admin_referer('mff_clear_cash', 'media_from_ftp_clear_cash') ) {
525
+ $submenu = 3;
526
+ $this->options_updated($submenu);
527
+ }
528
+ }
529
+ if ( isset($_POST['media_from_ftp_run_cron']) && $_POST['media_from_ftp_run_cron'] ) {
530
+ if ( check_admin_referer('mff_run_cron', 'media_from_ftp_run_cron') ) {
531
+ $submenu = 4;
532
+ $this->options_updated($submenu);
533
+ }
534
+ }
535
+ if ( isset($_POST['media_from_ftp_add_schedule']) && $_POST['media_from_ftp_add_schedule'] ) {
536
+ if ( check_admin_referer('mff_add_schedule', 'media_from_ftp_add_schedule') ) {
537
+ $submenu = 5;
538
+ $this->options_updated($submenu);
539
+ }
540
+ }
541
+ if ( isset($_POST['media_from_ftp_add_schedule_delete']) && $_POST['media_from_ftp_add_schedule_delete'] ) {
542
+ if ( check_admin_referer('mff_add_schedule_delete', 'media_from_ftp_add_schedule_delete') ) {
543
+ $submenu = 6;
544
+ $this->options_updated($submenu);
545
+ }
546
+ }
547
+ if ( isset($_POST['media_from_ftp_settings_cron_event_create']) && $_POST['media_from_ftp_settings_cron_event_create'] ) {
548
+ if ( check_admin_referer('mff_settings_cron_event_create', 'media_from_ftp_settings_cron_event_create') ) {
549
+ $submenu = 7;
550
+ $this->options_updated($submenu);
551
+ }
552
+ }
553
+
554
+ $mediafromftp = new MediaFromFtp();
555
+
556
+ $mediafromftp_addon_wpcron = FALSE;
557
+ if ( $this->is_add_on_activate['wpcron'] ) {
558
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
559
+ $mediafromftp_addon_wpcron = TRUE;
560
+ }
561
+
562
+ $mediafromftp_addon_category = FALSE;
563
+ if ( $this->is_add_on_activate['category'] ) {
564
+ $mediafromftpaddoncategory = new MediaFromFtpAddOnCategory();
565
+ $mediafromftp_addon_category = TRUE;
566
+ }
567
+
568
+ $mediafromftp_addon_exif = FALSE;
569
+ if ( $this->is_add_on_activate['exif'] ) {
570
+ $mediafromftpaddonexif = new MediaFromFtpAddOnExif();
571
+ $mediafromftp_addon_exif = TRUE;
572
+ }
573
+
574
+ $mediafromftp_settings = get_option($this->wp_options_name());
575
+
576
+ $def_max_execution_time = ini_get('max_execution_time');
577
+ $scriptname = admin_url('admin.php?page=mediafromftp-settings');
578
+
579
+ ?>
580
+
581
+ <div class="wrap">
582
+
583
+ <h2>Media from FTP <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" style="text-decoration: none;"><?php _e('Settings'); ?></a>
584
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" class="page-title-action"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
585
+ <?php
586
+ if ($mediafromftp_addon_wpcron) {
587
+ $mediafromftpaddonwpcron->mediafromftp_event_link_html();
588
+ }
589
+ ?>
590
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" class="page-title-action"><?php _e('Log', 'media-from-ftp'); ?></a>
591
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-import'); ?>" class="page-title-action"><?php _e('Import'); ?></a>
592
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-addons'); ?>" class="page-title-action"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
593
+ </h2>
594
+ <div style="clear: both;"></div>
595
+
596
+ <div id="mediafromftp-settings-tabs">
597
+ <ul>
598
+ <li><a href="#mediafromftp-settings-tabs-1"><?php _e('Register'); ?></a></li>
599
+ <li><a href="#mediafromftp-settings-tabs-2"><?php _e('Other', 'media-from-ftp'); ?></a></li>
600
+ <?php
601
+ if ( $this->is_add_on_activate['cli'] ) {
602
+ $mediafromftpcli = new MediaFromFtpCli();
603
+ $mediafromftpcli->mediafromftp_settings_tab_menu_html();
604
+ }
605
+ ?>
606
+ </ul>
607
+
608
+ <div id="mediafromftp-settings-tabs-1">
609
+ <div style="display: block; padding: 5px 15px">
610
+ <div class="item-mediafromftp-settings">
611
+ <h3><?php _e('Date'); ?></h3>
612
+ <div style="display: block;padding:5px 5px">
613
+ <input type="radio" name="mediafromftp_dateset" form="mediafromftp_settings_form" value="new" <?php if ($mediafromftp_settings['dateset'] === 'new') echo 'checked'; ?>>
614
+ <?php _e('Update to use of the current date/time.', 'media-from-ftp'); ?>
615
+ </div>
616
+ <div style="display: block;padding:5px 5px">
617
+ <input type="radio" name="mediafromftp_dateset" form="mediafromftp_settings_form" value="server" <?php if ($mediafromftp_settings['dateset'] === 'server') echo 'checked'; ?>>
618
+ <?php _e('Get the date/time of the file, and updated based on it. Change it if necessary.', 'media-from-ftp'); ?>
619
+ </div>
620
+ <div style="display: block; padding:5px 5px">
621
+ <input type="radio" name="mediafromftp_dateset" form="mediafromftp_settings_form" value="exif" <?php if ($mediafromftp_settings['dateset'] === 'exif') echo 'checked'; ?>>
622
+ <?php
623
+ _e('Get the date/time of the file, and updated based on it. Change it if necessary.', 'media-from-ftp');
624
+ _e('Get by priority if there is date and time of the Exif information.', 'media-from-ftp');
625
+ ?>
626
+ </div>
627
+ <div style="display: block; padding:5px 5px">
628
+ <input type="radio" name="mediafromftp_dateset" form="mediafromftp_settings_form" value="fixed" <?php if ($mediafromftp_settings['dateset'] === 'fixed') echo 'checked'; ?>>
629
+ <?php _e('Update to use of fixed the date/time.', 'media-from-ftp'); ?>
630
+ </div>
631
+ <div style="display: block; padding:5px 40px">
632
+ <input type="text" id="datetimepicker-mediafromftp00" name="mediafromftp_datefixed" form="mediafromftp_settings_form" value="<?php echo $mediafromftp_settings['datefixed']; ?>">
633
+ </div>
634
+ <div style="display: block; padding:5px 5px">
635
+ <?php
636
+ if ( current_user_can('manage_options') ) {
637
+ ?>
638
+ <input type="checkbox" name="move_yearmonth_folders" form="mediafromftp_settings_form" value="1" <?php checked('1', get_option('uploads_use_yearmonth_folders')); ?> />
639
+ <?php
640
+ } else {
641
+ ?>
642
+ <input type="checkbox" form="mediafromftp_settings_form" disabled="disabled" value="1" <?php checked('1', get_option('uploads_use_yearmonth_folders')); ?> />
643
+ <input type="hidden" name="move_yearmonth_folders" form="mediafromftp_settings_form" value="<?php echo get_option('uploads_use_yearmonth_folders'); ?>">
644
+ <?php
645
+ }
646
+ _e('Organize my uploads into month- and year-based folders');
647
+ ?>
648
+ </div>
649
+ </div>
650
+
651
+ <div class="item-mediafromftp-settings">
652
+ <h3><?php _e('Log', 'media-from-ftp'); ?></h3>
653
+ <div style="display:block;padding:5px 0">
654
+ <?php _e('Record the registration result.', 'media-from-ftp'); ?>
655
+ </div>
656
+ <div style="display:block;padding:5px 0">
657
+ <input type="checkbox" name="mediafromftp_apply_log" form="mediafromftp_settings_form" value="1" <?php checked('1', $mediafromftp_settings['log']); ?> />
658
+ <?php _e('Create log', 'media-from-ftp'); ?>
659
+ </div>
660
+ </div>
661
+
662
+ <div class="item-mediafromftp-settings">
663
+ <h3><?php _e('Schedule', 'media-from-ftp'); ?>(<?php _e('Cron Event', 'media-from-ftp'); ?>)</h3>
664
+ <div style="display:block;padding:5px 0">
665
+ <?php _e('Set the schedule.', 'media-from-ftp'); ?>
666
+ </div>
667
+ <?php
668
+ if ($mediafromftp_addon_wpcron) {
669
+ $mediafromftpaddonwpcron->mediafromftp_schedule_form($scriptname, $mediafromftp_settings);
670
+ } else {
671
+ $add_on_url = '<a href="'.admin_url('admin.php?page=mediafromftp-addons').'" style="text-decoration: none; word-break: break-all;"><strong>'.__('Add-Ons', 'media-from-ftp').'(Media from FTP Add On Wp Cron)</strong></a>';
672
+ $use_add_on_html = sprintf(__('This function requires %1$s.', 'media-from-ftp'), $add_on_url);
673
+ ?>
674
+ <div style="display:block;padding:5px 0">
675
+ <?php echo $use_add_on_html; ?>
676
+ </div>
677
+ <?php
678
+ }
679
+ ?>
680
+ </div>
681
+
682
+ <div class="item-mediafromftp-settings">
683
+ <h3><?php _e('Categories'); ?></h3>
684
+ <div style="display:block;padding:5px 0">
685
+ <?php _e('Specify categories to register at the same time when registering.', 'media-from-ftp'); ?>
686
+ </div>
687
+ <?php
688
+ if ($mediafromftp_addon_category) {
689
+ $mlccs = explode(',', $mediafromftp_settings['mlcc']);
690
+ $emlcs = explode(',', $mediafromftp_settings['emlc']);
691
+ $mlacs = explode(',', $mediafromftp_settings['mlac']);
692
+ $mlats = explode(',', $mediafromftp_settings['mlat']);
693
+ echo $mediafromftpaddoncategory->mlc_category_admin_html($mlccs);
694
+ echo $mediafromftpaddoncategory->eml_category_admin_html($emlcs);
695
+ echo $mediafromftpaddoncategory->mla_category_admin_html($mlacs, $mlats);
696
+ } else {
697
+ $add_on_url = '<a href="'.admin_url('admin.php?page=mediafromftp-addons').'" style="text-decoration: none; word-break: break-all;"><strong>'.__('Add-Ons', 'media-from-ftp').'(Media from FTP Add On Category)</strong></a>';
698
+ $use_add_on_html = sprintf(__('This function requires %1$s.', 'media-from-ftp'), $add_on_url);
699
+ ?>
700
+ <div style="display:block;padding:5px 0">
701
+ <?php echo $use_add_on_html; ?>
702
+ </div>
703
+ <?php
704
+ }
705
+ ?>
706
+ </div>
707
+
708
+ <div class="item-mediafromftp-settings">
709
+ <h3>Exif <?php _e('Caption'); ?></h3>
710
+ <div style="display:block;padding:5px 0">
711
+ <?php _e('Register the Exif data to the caption.', 'media-from-ftp'); ?>
712
+ </div>
713
+ <?php
714
+ if ($mediafromftp_addon_exif) {
715
+ $mediafromftpaddonexif->mediafromftp_exif_form($mediafromftp_settings);
716
+ } else {
717
+ $add_on_url = '<a href="'.admin_url('admin.php?page=mediafromftp-addons').'" style="text-decoration: none; word-break: break-all;"><strong>'.__('Add-Ons', 'media-from-ftp').'(Media from FTP Add On Exif)</strong></a>';
718
+ $use_add_on_html = sprintf(__('This function requires %1$s.', 'media-from-ftp'), $add_on_url);
719
+ ?>
720
+ <div style="display:block;padding:5px 0">
721
+ <?php echo $use_add_on_html; ?>
722
+ </div>
723
+ <?php
724
+ }
725
+ ?>
726
+ </div>
727
+
728
+ <div style="clear: both;"></div>
729
+
730
+ <form method="post" id="mediafromftp_settings_form" action="<?php echo $scriptname; ?>">
731
+ <?php wp_nonce_field('mff_settings', 'media_from_ftp_settings'); ?>
732
+ <div style="display: block;padding:5px 5px">
733
+ <?php submit_button( __('Save Changes'), 'large', 'media-from-ftp-settings-options-apply', FALSE ); ?>
734
+ </div>
735
+ </form>
736
+
737
+ </div>
738
+ </div>
739
+
740
+ <div id="mediafromftp-settings-tabs-2">
741
+ <div style="display: block; padding: 5px 15px">
742
+
743
+ <div class="item-mediafromftp-settings">
744
+ <h3><?php _e('Limit number of search files', 'media-from-ftp'); ?></h3>
745
+ <p>
746
+ <?php _e('If you can not search because there are too many files, please reduce this number.', 'media-from-ftp'); ?>
747
+ </p>
748
+ <div style="display:block;padding:5px 0">
749
+ <input type="number" step="100" min="100" max="100000" name="mediafromftp_search_limit_number" value="<?php echo $mediafromftp_settings['search_limit_number']; ?>" form="mediafromftp_settings_form" >
750
+ </div>
751
+ <div style="clear: both;"></div>
752
+ </div>
753
+
754
+ <div class="item-mediafromftp-settings">
755
+ <h3><?php _e('Execution time', 'media-from-ftp'); ?></h3>
756
+ <div style="display:block; padding:5px 5px">
757
+ <?php
758
+ $max_execution_time = $mediafromftp_settings['max_execution_time'];
759
+ if ( !@set_time_limit($max_execution_time) ) {
760
+ $limit_seconds_html = '<font color="red">'.$def_max_execution_time.__('seconds', 'media-from-ftp').'</font>';
761
+ ?>
762
+ <?php echo sprintf(__('Execution time for this server is fixed at %1$s. If this limit is exceeded, the search times out&#40;%2$s, %3$s&#41;.', 'media-from-ftp'), $limit_seconds_html, __('Search'), __('Log', 'media-from-ftp')); ?>
763
+ <input type="hidden" name="mediafromftp_max_execution_time" form="mediafromftp_settings_form" value="<?php echo $def_max_execution_time; ?>" />
764
+ <?php
765
+ } else {
766
+ $max_execution_time_text = __('The number of seconds a script is allowed to run.', 'media-from-ftp').'('.__('The max_execution_time value defined in the php.ini.', 'media-from-ftp').'[<font color="red">'.$def_max_execution_time.'</font>]'.')';
767
+ _e('This is to suppress the timeout when retrieving a large amount of data when displaying the search screen and log screen.', 'media-from-ftp');
768
+ _e('It does not matter on the registration screen.', 'media-from-ftp');
769
+ ?>
770
+ <div style="float: left;"><?php echo $max_execution_time_text; ?>:<input type="number" step="1" min="1" max="999" class="screen-per-page" maxlength="3" name="mediafromftp_max_execution_time" form="mediafromftp_settings_form" value="<?php echo $max_execution_time; ?>" /></div>
771
+ <?php
772
+ }
773
+ ?>
774
+ </div>
775
+ <div style="clear: both;"></div>
776
+ </div>
777
+
778
+ <?php
779
+ if ( function_exists('mb_check_encoding') ) {
780
+ ?>
781
+ <div class="item-mediafromftp-settings">
782
+ <h3><?php _e('Character Encodings for Server', 'media-from-ftp'); ?></h3>
783
+ <p>
784
+ <?php _e('It may fail to register if you are using a multi-byte name in the file name or folder name. In that case, please change.', 'media-from-ftp');
785
+ $characterencodings_none_html = '<a href="'.__('https://en.wikipedia.org/wiki/Variable-width_encoding', 'media-from-ftp').'" target="_blank" style="text-decoration: none; word-break: break-all;">'.__('variable-width encoding', 'media-from-ftp').'</a>';
786
+ echo sprintf(__('If you do not use the filename or directory name of %1$s, please choose "%2$s".','media-from-ftp'), $characterencodings_none_html, '<font color="red">none</font>');
787
+ ?>
788
+ </p>
789
+ <select name="mediafromftp_character_code" form="mediafromftp_settings_form" style="width: 210px">
790
+ <?php
791
+ if ( 'none' === $mediafromftp_settings['character_code'] ) {
792
+ ?>
793
+ <option value="none" selected>none</option>
794
+ <?php
795
+ } else {
796
+ ?>
797
+ <option value="none">none</option>
798
+ <?php
799
+ }
800
+ foreach (mb_list_encodings() as $chrcode) {
801
+ if ( $chrcode <> 'pass' && $chrcode <> 'auto' ) {
802
+ if ( $chrcode === $mediafromftp_settings['character_code'] ) {
803
+ ?>
804
+ <option value="<?php echo $chrcode; ?>" selected><?php echo $chrcode; ?></option>
805
+ <?php
806
+ } else {
807
+ ?>
808
+ <option value="<?php echo $chrcode; ?>"><?php echo $chrcode; ?></option>
809
+ <?php
810
+ }
811
+ }
812
+ }
813
+ ?>
814
+ </select>
815
+ <div style="clear: both;"></div>
816
+ </div>
817
+ <?php
818
+ }
819
+ ?>
820
+
821
+ <div class="item-mediafromftp-settings">
822
+ <h3><?php _e('Remove Thumbnails Cache', 'media-from-ftp'); ?></h3>
823
+ <div style="display:block;padding:5px 0">
824
+ <?php _e('Remove the cache of thumbnail used in the search screen. Please try out if trouble occurs in the search screen. It might become normal.', 'media-from-ftp'); ?>
825
+ </div>
826
+ <form method="post" action="<?php echo $scriptname; ?>" />
827
+ <?php wp_nonce_field('mff_clear_cash', 'media_from_ftp_clear_cash'); ?>
828
+ <input type="hidden" name="mediafromftp_clear_cash" value="1" />
829
+ <div>
830
+ <?php submit_button( __('Remove Thumbnails Cache', 'media-from-ftp'), 'delete', '', FALSE); ?>
831
+ </div>
832
+ </form>
833
+ </div>
834
+
835
+ <div style="clear: both;"></div>
836
+
837
+ <div style="display: block;padding:5px 5px">
838
+ <?php submit_button( __('Save Changes'), 'large', 'media-from-ftp-settings-options-apply', FALSE, array( 'form' => 'mediafromftp_settings_form' ) ); ?>
839
+ </div>
840
+
841
+ </div>
842
+ </div>
843
+
844
+ <?php
845
+ if ( $this->is_add_on_activate['cli'] ) {
846
+ $mediafromftpcli->mediafromftp_command_line_html($this->wp_options_name());
847
+ unset($mediafromftpcli);
848
+ }
849
+ ?>
850
+
851
+ </div>
852
+ </div>
853
+ <?php
854
+ unset($mediafromftpaddonwpcron);
855
+ unset($mediafromftpaddoncategory);
856
+ }
857
+
858
+ /* ==================================================
859
+ * Sub Menu
860
+ */
861
+ function search_register_page(){
862
+
863
+ if ( !current_user_can( 'upload_files' ) ) {
864
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
865
+ }
866
+
867
+ if ( isset($_POST['media_from_ftp_search']) && $_POST['media_from_ftp_search'] ) {
868
+ if ( check_admin_referer('mff_search', 'media_from_ftp_search') ) {
869
+ $submenu = 2;
870
+ $this->options_updated($submenu);
871
+ }
872
+ }
873
+ $mediafromftp_settings = get_option($this->wp_options_name());
874
+
875
+ $def_max_execution_time = ini_get('max_execution_time');
876
+ $max_execution_time = $mediafromftp_settings['max_execution_time'];
877
+
878
+ $limit_seconds_html = '<font color="red">'.$def_max_execution_time.__('seconds', 'media-from-ftp').'</font>';
879
+
880
+ if ( !@set_time_limit($max_execution_time) ) {
881
+ echo '<div class="notice notice-info is-dismissible"><ul><li>'.sprintf(__('Execution time for this server is fixed at %1$s. If this limit is exceeded, times out&#40;%2$s&#41;. Please note the "Number of items per page" so as not to exceed this limit.', 'media-from-ftp'), $limit_seconds_html, __('Search')).'</li></ul></div>';
882
+ }
883
+
884
+ ?>
885
+ <div class="wrap">
886
+
887
+ <h2>Media from FTP <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" style="text-decoration: none;"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
888
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" class="page-title-action"><?php _e('Settings'); ?></a>
889
+ <?php
890
+ $mediafromftp = new MediaFromFtp();
891
+ if ( $this->is_add_on_activate['wpcron'] ) {
892
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
893
+ $mediafromftpaddonwpcron->mediafromftp_event_link_html();
894
+ unset($mediafromftpaddonwpcron);
895
+ }
896
+ ?>
897
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" class="page-title-action"><?php _e('Log', 'media-from-ftp'); ?></a>
898
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-import'); ?>" class="page-title-action"><?php _e('Import'); ?></a>
899
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-addons'); ?>" class="page-title-action"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
900
+ </h2>
901
+ <div style="clear: both;"></div>
902
+
903
+ <div id="mediafromftp-loading"><img src="<?php echo MEDIAFROMFTP_PLUGIN_URL.'/css/loading.gif'; ?>"></div>
904
+ <div id="mediafromftp-loading-container">
905
+ <?php
906
+ $formhtml = $mediafromftp->form_html($mediafromftp_settings);
907
+ unset($mediafromftp);
908
+ $MediaFromFtpListTable = new TT_MediaFromFtp_List_Table();
909
+ $MediaFromFtpListTable->prepare_items($mediafromftp_settings);
910
+ if ( $MediaFromFtpListTable->max_items > 0 ) {
911
+ $update_button = get_submit_button( __('Update Media'), 'primary', '', FALSE, array('form' => 'mediafromftp_ajax_update') );
912
+ $update_upper_button = '<div style="padding: 15px 15px 0px;">'.$update_button.'</div>';
913
+ $update_lower_button = '<div style="padding: 0px 15px;">'.$update_button.'</div>';
914
+ } else {
915
+ $update_upper_button = NULL;
916
+ $update_lower_button = NULL;
917
+ }
918
+ ?>
919
+ <div><?php echo $formhtml; ?></div>
920
+ <form method="post" id="mediafromftp_ajax_update">
921
+ <form id="media-from-ftp-filter" method="get">
922
+ <input type="hidden" name="page" value="<?php echo $_REQUEST['page']; ?>" />
923
+ <?php echo $update_upper_button; ?>
924
+ <?php $MediaFromFtpListTable->display(); ?>
925
+ <?php echo $update_lower_button; ?>
926
+ </form>
927
+ </form>
928
+ </div>
929
+ </div>
930
+ <?php
931
+ }
932
+
933
+ /* ==================================================
934
+ * Bulk Change Date Time
935
+ * @since 9.63
936
+ */
937
+ function custom_bulk_admin_footer() {
938
+ $mediafromftp_settings = get_option($this->wp_options_name());
939
+ if ( $mediafromftp_settings['dateset'] === 'server' || $mediafromftp_settings['dateset'] === 'exif' ) {
940
+ if ($this->is_my_plugin_screen3()) {
941
+ $now_date_time = date_i18n("Y-m-d H:i");
942
+ $html = '<div style="float: right;">'.__('Bulk Change', 'media-from-ftp').'<input type="text" id="datetimepicker-mediafromftp0" name="bulk_mediafromftp_datetime" value="'.$now_date_time.'" style="width: 160px; height: 1.7em;" /></div>';
943
+
944
+ ?>
945
+ <script type="text/javascript">
946
+ jQuery('<?php echo $html; ?>').prependTo("#datetime");
947
+ </script>
948
+ <?php
949
+ }
950
+ }
951
+ }
952
+
953
+ /* ==================================================
954
+ * Sub Menu
955
+ * for media-from-ftp-add-on-wpcron
956
+ */
957
+ function event_page() {
958
+
959
+ $mediafromftp_addon_wpcron = FALSE;
960
+ $mediafromftp = new MediaFromFtp();
961
+ if ( $this->is_add_on_activate['wpcron'] ) {
962
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
963
+ include_once MEDIAFROMFTP_ADDON_WPCRON_PLUGIN_BASE_DIR.'/req/MediaFromFtpCron.php';
964
+ $mediafromftpcron = new MediaFromFtpCron();
965
+ $mediafromftp_addon_wpcron = TRUE;
966
+ }
967
+
968
+ if ( !current_user_can( 'upload_files' ) || !$mediafromftp_addon_wpcron ) {
969
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
970
+ }
971
+
972
+ if ( isset($_POST['media_from_ftp_run_cron']) && $_POST['media_from_ftp_run_cron'] ) {
973
+ if ( check_admin_referer('mff_run_cron', 'media_from_ftp_run_cron') ) {
974
+ $submenu = 4;
975
+ $this->options_updated($submenu);
976
+ }
977
+ }
978
+
979
+ ?>
980
+ <div class="wrap">
981
+
982
+ <h2>Media from FTP <?php echo $mediafromftpaddonwpcron->mediafromftp_event_top_link_html(); ?>
983
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" class="page-title-action"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
984
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" class="page-title-action"><?php _e('Settings'); ?></a>
985
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" class="page-title-action"><?php _e('Log', 'media-from-ftp'); ?></a>
986
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-import'); ?>" class="page-title-action"><?php _e('Import'); ?></a>
987
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-addons'); ?>" class="page-title-action"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
988
+ </h2>
989
+ <div style="clear: both;"></div>
990
+ <p>
991
+ <?php
992
+
993
+ if ( isset($_POST['media_from_ftp_event']) && $_POST['media_from_ftp_event'] ) {
994
+ if ( check_admin_referer('mff_event', 'media_from_ftp_event') ) {
995
+ if ( isset($_POST['event-mediafromftp']) && $_POST['event-mediafromftp'] ) {
996
+ $events_mediafromftp = $_POST['event-mediafromftp'];
997
+ $events = get_option( $this->wp_add_on_wpcron_events_name() );
998
+ $event_names = NULL;
999
+ foreach ($events_mediafromftp as $key => $event_id ) {
1000
+ $option_name = $events[$event_id];
1001
+ $mediafromftpcron->CronStop($option_name);
1002
+ delete_option($option_name);
1003
+ $event_names .= ' '.$event_id.' ';
1004
+ unset($events[$event_id]);
1005
+ update_option($this->wp_add_on_wpcron_events_name(), $events);
1006
+ }
1007
+ unset($mediafromftpcron);
1008
+ echo $mediafromftpaddonwpcron->mediafromftp_event_notice_html($event_names);
1009
+ }
1010
+ }
1011
+ }
1012
+
1013
+ $scriptname = admin_url('admin.php?page=mediafromftp-event');
1014
+
1015
+ echo $mediafromftpaddonwpcron->mediafromftp_event_html( $scriptname, get_option($this->wp_add_on_wpcron_events_name()) );
1016
+
1017
+ ?>
1018
+ </div>
1019
+ <?php
1020
+
1021
+ }
1022
+
1023
+ /* ==================================================
1024
+ * Sub Menu
1025
+ */
1026
+ function log_page() {
1027
+
1028
+ if ( !current_user_can( 'upload_files' ) ) {
1029
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1030
+ }
1031
+
1032
+ $mediafromftp_settings = get_option($this->wp_options_name());
1033
+ if ( !$mediafromftp_settings['log'] ) {
1034
+ echo '<div class="notice notice-info is-dismissible"><ul><li>'.__('Current, log is not created. If you want to create a log, please put a check in the [Create log] in the settings.', 'media-from-ftp').'</li></ul></div>';
1035
+ }
1036
+ $def_max_execution_time = ini_get('max_execution_time');
1037
+ $max_execution_time = $mediafromftp_settings['max_execution_time'];
1038
+
1039
+ $limit_seconds_html = '<font color="red">'.$def_max_execution_time.__('seconds', 'media-from-ftp').'</font>';
1040
+ if ( !@set_time_limit($max_execution_time) ) {
1041
+ echo '<div class="notice notice-info is-dismissible"><ul><li>'.sprintf(__('Execution time for this server is fixed at %1$s. If this limit is exceeded, times out. Please run the frequently "Delete log" and "Export to CSV" so as not to exceed this limit.', 'media-from-ftp'), $limit_seconds_html).'</li></ul></div>';
1042
+ }
1043
+
1044
+ ?>
1045
+ <div class="wrap">
1046
+
1047
+ <h2>Media from FTP <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" style="text-decoration: none;"><?php _e('Log', 'media-from-ftp'); ?></a>
1048
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" class="page-title-action"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
1049
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" class="page-title-action"><?php _e('Settings'); ?></a>
1050
+ <?php
1051
+ $mediafromftp = new MediaFromFtp();
1052
+ if ( $this->is_add_on_activate['wpcron'] ) {
1053
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1054
+ $mediafromftpaddonwpcron->mediafromftp_event_link_html();
1055
+ unset($mediafromftpaddonwpcron);
1056
+ }
1057
+ ?>
1058
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-import'); ?>" class="page-title-action"><?php _e('Import'); ?></a>
1059
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-addons'); ?>" class="page-title-action"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
1060
+ </h2>
1061
+ <div style="clear: both;"></div>
1062
+
1063
+ <div id="mediafromftp-loading"><img src="<?php echo MEDIAFROMFTP_PLUGIN_URL.'/css/loading.gif'; ?>"></div>
1064
+ <div id="mediafromftp-loading-container">
1065
+ <?php
1066
+ global $wpdb;
1067
+
1068
+ $user = wp_get_current_user();
1069
+
1070
+ $table_name = $wpdb->prefix.'mediafromftp_log';
1071
+
1072
+ if ( isset($_POST['media_from_ftp_clear_log']) && $_POST['media_from_ftp_clear_log'] ) {
1073
+ if ( check_admin_referer('mff_clear_log', 'media_from_ftp_clear_log') ) {
1074
+ if ( !empty($_POST['mediafromftp_clear_log']) && $_POST['mediafromftp_clear_log'] == 1 ) {
1075
+ if ( current_user_can('administrator') ) {
1076
+ $wpdb->query("DELETE FROM $table_name");
1077
+ echo '<div class="notice notice-success is-dismissible"><ul><li>'.__('Removed all of the log.', 'media-from-ftp').'</li></ul></div>';
1078
+ } else {
1079
+ $delete_count = $wpdb->delete($table_name, array( 'user' => $user->display_name ));
1080
+ if ( $delete_count > 0 ) {
1081
+ echo '<div class="notice notice-success is-dismissible"><ul><li>'.sprintf(__('%1$s of the log has been deleted %2$d.', 'media-from-ftp'), $user->display_name, $delete_count ).'</li></ul></div>';
1082
+ } else {
1083
+ echo '<div class="notice notice-info is-dismissible"><ul><li>'.sprintf(__('%1$s do not have a possible deletion log.', 'media-from-ftp'), $user->display_name ).'</li></ul></div>';
1084
+ }
1085
+ }
1086
+ }
1087
+ }
1088
+ }
1089
+
1090
+ $records = $wpdb->get_results("SELECT * FROM $table_name");
1091
+
1092
+ $csv = NULL;
1093
+ $max_thumbnail_count = 0;
1094
+ $max_mlccategories_count = 0;
1095
+ $max_emlcategories_count = 0;
1096
+ $max_mlacategories_count = 0;
1097
+ $max_mlatags_count = 0;
1098
+ $html = '<table>';
1099
+
1100
+ foreach ( $records as $record ) {
1101
+ $csvs = '"'.$record->id.'","'.$record->user.'","'.$record->title.'","'.$record->permalink.'","'.$record->url.'","'.$record->filename.'","'.$record->time.'","'.$record->filetype.'","'.$record->filesize.'","'.$record->exif.'","'.$record->length.'"';
1102
+ $html_thumbnail = NULL;
1103
+ if ( $record->thumbnail ) {
1104
+ $thumbnails = json_decode($record->thumbnail, true);
1105
+ if ( $max_thumbnail_count < count($thumbnails) ) {
1106
+ $max_thumbnail_count = count($thumbnails);
1107
+ }
1108
+ $count = 0;
1109
+ foreach ( $thumbnails as $thumbnail ) {
1110
+ ++$count;
1111
+ $html_thumbnail .= '<tr><th align="right" style="white-space: nowrap;">'.__('Featured Image').$count.':</th><td>'.$thumbnail.'</td></tr>';
1112
+ $csvs .= ',"'.$thumbnail.'"';
1113
+ }
1114
+ }
1115
+ $html_mlccategory = NULL;
1116
+ if ( $record->mlccategories ) {
1117
+ $mlccategories = json_decode($record->mlccategories, true);
1118
+ if ( $max_mlccategories_count < count($mlccategories) ) {
1119
+ $max_mlccategories_count = count($mlccategories);
1120
+ }
1121
+ $count = 0;
1122
+ foreach ( $mlccategories as $mlccategory ) {
1123
+ ++$count;
1124
+ $html_mlccategory .= '<tr><th align="right" style="white-space: nowrap;">'.__('Categories').'[Media Library Categories]'.$count.':</th><td>'.$mlccategory.'</td></tr>';
1125
+ $csvs .= ',"'.$mlccategory.'"';
1126
+ }
1127
+ }
1128
+ $html_emlcategory = NULL;
1129
+ if ( $record->emlcategories ) {
1130
+ $emlcategories = json_decode($record->emlcategories, true);
1131
+ if ( $max_emlcategories_count < count($emlcategories) ) {
1132
+ $max_emlcategories_count = count($emlcategories);
1133
+ }
1134
+ $count = 0;
1135
+ foreach ( $emlcategories as $emlcategory ) {
1136
+ ++$count;
1137
+ $html_emlcategory .= '<tr><th align="right" style="white-space: nowrap;">'.__('Categories').'[Enhanced Media Library]'.$count.':</th><td>'.$emlcategory.'</td></tr>';
1138
+ $csvs .= ',"'.$emlcategory.'"';
1139
+ }
1140
+ }
1141
+ $html_mlacategory = NULL;
1142
+ if ( $record->mlacategories ) {
1143
+ $mlacategories = json_decode($record->mlacategories, true);
1144
+ if ( $max_mlacategories_count < count($mlacategories) ) {
1145
+ $max_mlacategories_count = count($mlacategories);
1146
+ }
1147
+ $count = 0;
1148
+ foreach ( $mlacategories as $mlacategory ) {
1149
+ ++$count;
1150
+ $html_mlacategory .= '<tr><th align="right" style="white-space: nowrap;">'.__('Categories').'[Media Library Assistant]'.$count.':</th><td>'.$mlacategory.'</td></tr>';
1151
+ $csvs .= ',"'.$mlacategory.'"';
1152
+ }
1153
+ }
1154
+ $html_mlatag = NULL;
1155
+ if ( $record->mlatags ) {
1156
+ $mlatags = json_decode($record->mlatags, true);
1157
+ if ( $max_mlatags_count < count($mlatags) ) {
1158
+ $max_mlatags_count = count($mlatags);
1159
+ }
1160
+ $count = 0;
1161
+ foreach ( $mlatags as $mlatag ) {
1162
+ ++$count;
1163
+ $html_mlatag .= '<tr><th align="right" style="white-space: nowrap;">'.__('Tags').'[Media Library Assistant]'.$count.':</th><td>'.$mlatag.'</td></tr>';
1164
+ $csvs .= ',"'.$mlatag.'"';
1165
+ }
1166
+ }
1167
+ $csvs .= "\n";
1168
+ $csv .= $csvs;
1169
+ $html .= '<tr><th>&nbsp;</th><td>&nbsp;</td></tr>';
1170
+ $html .= '<tr><th align="right" style="background-color: #cccccc;">ID:</th><td>'.$record->id.'</td></tr>';
1171
+ $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('Author').':</th><td>'.$record->user.'</td></tr>';
1172
+ $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('Title').':</th><td>'.$record->title.'</td></tr>';
1173
+ $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('Permalink:').'</th><td>'.$record->permalink.'</td></tr>';
1174
+ $html .= '<tr><th align="right" style="white-space: nowrap;">URL:</th><td>'.$record->url.'</td>';
1175
+ $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('File name:').'</th><td>'.$record->filename.'</td></tr>';
1176
+ $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('Date/Time').':</th><td>'.$record->time.'</td></tr>';
1177
+ $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('File type:').'</th><td>'.$record->filetype.'</td></tr>';
1178
+ $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('File size:').'</th><td>'.$record->filesize.'</td></tr>';
1179
+ if ( $record->exif ) {
1180
+ $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('Caption').'[Exif]:</th><td>'.$record->exif.'</td></tr>';
1181
+ }
1182
+ if ( $record->length ) {
1183
+ $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('Length:').'</th><td>'.$record->length.'</td></tr>';
1184
+ }
1185
+ $html .= $html_thumbnail.$html_mlccategory.$html_emlcategory.$html_mlacategory.$html_mlatag;
1186
+ }
1187
+ $html .= '</table>'."\n";
1188
+ $csv_head = '"ID","'.__('Author').'","'.__('Title').':","'.__('Permalink:').'","URL:","'.__('File name:').'","'.__('Date/Time').':","'.__('File type:').'","'.__('File size:').'","'.__('Caption').'[Exif]:","'.__('Length:').'"';
1189
+ for ($i = 1 ; $i <= $max_thumbnail_count; $i++) {
1190
+ $csv_head .= ',"'.__('Featured Image').$i.'"';
1191
+ }
1192
+ for ($i = 1 ; $i <= $max_mlccategories_count; $i++) {
1193
+ $csv_head .= ',"'.__('Categories').'[Media Library Categories]'.$i.'"';
1194
+ }
1195
+ for ($i = 1 ; $i <= $max_emlcategories_count; $i++) {
1196
+ $csv_head .= ',"'.__('Categories').'[Enhanced Media Library]'.$i.'"';
1197
+ }
1198
+ for ($i = 1 ; $i <= $max_mlacategories_count; $i++) {
1199
+ $csv_head .= ',"'.__('Categories').'[Media Library Assistant]'.$i.'"';
1200
+ }
1201
+ for ($i = 1 ; $i <= $max_mlatags_count; $i++) {
1202
+ $csv_head .= ',"'.__('Tags').'[Media Library Assistant]'.$i.'"';
1203
+ }
1204
+
1205
+ $csv = $csv_head."\n".$csv;
1206
+
1207
+ $csvFileName = MEDIAFROMFTP_PLUGIN_TMP_DIR.'/'.$table_name.'.csv';
1208
+ if ( isset($_POST['media_from_ftp_put_log']) && $_POST['media_from_ftp_put_log'] ) {
1209
+ if ( check_admin_referer('mff_put_log', 'media_from_ftp_put_log') ) {
1210
+ if ( !empty($_POST['mediafromftp_put_log']) && $_POST['mediafromftp_put_log'] == 1 ) {
1211
+ file_put_contents($csvFileName, pack('C*',0xEF,0xBB,0xBF)); //UTF-8 BOM
1212
+ file_put_contents($csvFileName, $csv, FILE_APPEND | LOCK_EX);
1213
+ }
1214
+ }
1215
+ } else {
1216
+ if ( file_exists($csvFileName) ) {
1217
+ unlink($csvFileName);
1218
+ }
1219
+ }
1220
+
1221
+ if ( !empty($records) ) {
1222
+ ?>
1223
+ <div style="display: block; padding: 10px 10px">
1224
+ <form style="float: left;" method="post" action="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" />
1225
+ <?php wp_nonce_field('mff_clear_log', 'media_from_ftp_clear_log'); ?>
1226
+ <input type="hidden" name="mediafromftp_clear_log" value="1" />
1227
+ <div>
1228
+ <?php submit_button( __('Delete log', 'media-from-ftp'), 'large', '', FALSE ); ?>
1229
+ </div>
1230
+ </form>
1231
+ <form style="float: left; margin-left: 0.5em; margin-right: 0.5em;" method="post" action="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" />
1232
+ <?php wp_nonce_field('mff_put_log', 'media_from_ftp_put_log'); ?>
1233
+ <input type="hidden" name="mediafromftp_put_log" value="1" />
1234
+ <div>
1235
+ <?php submit_button( __('Export to CSV', 'media-from-ftp'), 'large', '', FALSE ); ?>
1236
+ </div>
1237
+ </form>
1238
+ <?php
1239
+ if ( file_exists($csvFileName) ) {
1240
+ ?>
1241
+ <form method="post" action="<?php echo MEDIAFROMFTP_PLUGIN_TMP_URL.'/'.$table_name.'.csv'; ?>" />
1242
+ <?php wp_nonce_field('mff_download', 'media_from_ftp_download'); ?>
1243
+ <div>
1244
+ <input type="hidden" name="mediafromftp_download" value="1" />
1245
+ <?php submit_button( __('Download CSV', 'media-from-ftp'), 'large', '', FALSE ); ?>
1246
+ </div>
1247
+ </form>
1248
+ <?php
1249
+ }
1250
+ ?>
1251
+ </div>
1252
+ <div style="clear: both;"></div>
1253
+ <div style="display: block; padding: 10px 10px">
1254
+ <?php echo $html;
1255
+ ?>
1256
+ </div>
1257
+ <?php
1258
+ } else {
1259
+ if ( $mediafromftp_settings['log'] ) {
1260
+ echo '<div class="notice notice-info is-dismissible"><ul><li>'.__('There is no log.', 'media-from-ftp').'</li></ul></div>';
1261
+ }
1262
+ }
1263
+ ?>
1264
+ </div>
1265
+
1266
+ </div>
1267
+
1268
+ <?php
1269
+
1270
+ }
1271
+
1272
+ /* ==================================================
1273
+ * Sub Menu
1274
+ */
1275
+ function medialibrary_import_page() {
1276
+
1277
+ if ( !current_user_can( 'upload_files' ) ) {
1278
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1279
+ }
1280
+
1281
+ $scriptname = admin_url('admin.php?page=mediafromftp-import');
1282
+
1283
+ ?>
1284
+ <div class="wrap">
1285
+ <h2>Media from FTP <a href="<?php echo $scriptname; ?>" style="text-decoration: none;"><?php _e('Import'); ?></a>
1286
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" class="page-title-action"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
1287
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" class="page-title-action"><?php _e('Settings'); ?></a>
1288
+ <?php
1289
+ $mediafromftp = new MediaFromFtp();
1290
+ if ( $this->is_add_on_activate['wpcron'] ) {
1291
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1292
+ $mediafromftpaddonwpcron->mediafromftp_event_link_html();
1293
+ unset($mediafromftpaddonwpcron);
1294
+ }
1295
+ ?>
1296
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" class="page-title-action"><?php _e('Log', 'media-from-ftp'); ?></a>
1297
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-addons'); ?>" class="page-title-action"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
1298
+ </h2>
1299
+ <div style="clear: both;"></div>
1300
+
1301
+ <div id="mediafromftp-loading"><img src="<?php echo MEDIAFROMFTP_PLUGIN_URL.'/css/loading.gif'; ?>"></div>
1302
+ <div id="medialibraryimport-loading-container">
1303
+
1304
+ <?php
1305
+ if ( isset($_POST['media_from_ftp_file_load']) && $_POST['media_from_ftp_file_load'] ) {
1306
+ if ( check_admin_referer('mff_file_load', 'media_from_ftp_file_load') ) {
1307
+ if ( !empty($_FILES['filename']['name']) ) {
1308
+ $filename = $_FILES['filename']['tmp_name'];
1309
+ $name = basename($filename);
1310
+ move_uploaded_file($filename, MEDIAFROMFTP_PLUGIN_TMP_DIR.'/'.$name);
1311
+
1312
+ $mediafromftp = new MediaFromFtp();
1313
+ ?>
1314
+ <h4><?php _e('Assign Authors', 'media-from-ftp'); ?></h4>
1315
+ <?php
1316
+ echo $mediafromftp->author_select(MEDIAFROMFTP_PLUGIN_TMP_DIR.'/'.$name);
1317
+ }
1318
+ }
1319
+ } else if ( isset($_POST['media_from_ftp_select_author']) && $_POST['media_from_ftp_select_author'] ) {
1320
+ if ( check_admin_referer('mff_select_author', 'media_from_ftp_select_author') ) {
1321
+ if ( !empty($_POST['mediafromftp_select_author']) && !empty($_POST['mediafromftp_xml_file']) ) {
1322
+ ?>
1323
+ <h4><?php _e('Ready to import. Press the following button to start the import.', 'media-from-ftp'); ?></h4>
1324
+ <form method="post" id="medialibraryimport_ajax_update">
1325
+ <?php submit_button( __('Import'), 'primary', '', FALSE ); ?>
1326
+ </form>
1327
+ <?php
1328
+ }
1329
+ }
1330
+ } else {
1331
+ ?>
1332
+ <form method="post" action="<?php echo $scriptname; ?>" enctype="multipart/form-data">
1333
+ <?php wp_nonce_field('mff_file_load', 'media_from_ftp_file_load'); ?>
1334
+ <h4><?php _e('Select File'); ?>[WordPress eXtended RSS (WXR)(.xml)]</h4>
1335
+ <div><input name="filename" type="file" size="80" /></div>
1336
+ <div>
1337
+ <?php submit_button( __('File Load', 'media-from-ftp'), 'large', '', FALSE ); ?>
1338
+ </div>
1339
+ </form>
1340
+ <?php
1341
+ }
1342
+ ?>
1343
+
1344
+ </div>
1345
+ </div>
1346
+
1347
+ <?php
1348
+ }
1349
+
1350
+ /* ==================================================
1351
+ * Sub Menu
1352
+ */
1353
+ function addons_page() {
1354
+
1355
+ if ( !current_user_can( 'upload_files' ) ) {
1356
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1357
+ }
1358
+
1359
+ $scriptname = admin_url('admin.php?page=mediafromftp-addons');
1360
+
1361
+ ?>
1362
+ <div class="wrap">
1363
+
1364
+ <h2>Media from FTP <a href="<?php echo $scriptname; ?>" style="text-decoration: none;"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
1365
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" class="page-title-action"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
1366
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" class="page-title-action"><?php _e('Settings'); ?></a>
1367
+ <?php
1368
+ $mediafromftp = new MediaFromFtp();
1369
+ if ( $this->is_add_on_activate['wpcron'] ) {
1370
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1371
+ $mediafromftpaddonwpcron->mediafromftp_event_link_html();
1372
+ unset($mediafromftpaddonwpcron);
1373
+ }
1374
+ ?>
1375
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" class="page-title-action"><?php _e('Log', 'media-from-ftp'); ?></a>
1376
+ <a href="<?php echo admin_url('admin.php?page=mediafromftp-import'); ?>" class="page-title-action"><?php _e('Import'); ?></a>
1377
+ </h2>
1378
+ <div style="clear: both;"></div>
1379
+
1380
+ <div style="width: 300px; height: 100%; margin: 5px; padding: 5px; border: #CCC 2px solid; float: left;">
1381
+ <h4>Media from FTP Add On Commandline</h4>
1382
+ <div style="margin: 5px; padding: 5px;"><?php _e('This add-on can use "Media from FTP" on the command-line.', 'media-from-ftp'); ?></div>
1383
+ <div style="margin: 5px; padding: 5px;">
1384
+ <li><?php _e('The execution of the command line is supported.(lib/mediafromftpcmd.php)', 'media-from-ftp'); ?></li>
1385
+ </div>
1386
+ <p>
1387
+ <?php
1388
+ if ( is_dir(WP_PLUGIN_DIR.'/media-from-ftp-add-on-cli') ) {
1389
+ ?><div style="margin: 5px; padding: 5px;"><strong><?php
1390
+ _e('Installed', 'media-from-ftp');?> & <?php
1391
+ if ( $this->is_add_on_activate['cli'] ) {
1392
+ _e('Activated', 'media-from-ftp');
1393
+ } else {
1394
+ _e('Deactivated', 'media-from-ftp');
1395
+ }
1396
+ ?></strong></div><?php
1397
+ } else {
1398
+ ?>
1399
+ <div>
1400
+ <a href="<?php _e('https://riverforest-wp.info/media-from-ftp-add-on-cli/', 'media-from-ftp'); ?>" target="_blank" class="page-title-action"><?php _e('BUY', 'media-from-ftp'); ?> &yen;1,000</a>
1401
+ </div>
1402
+ <?php
1403
+ }
1404
+ ?>
1405
+ </div>
1406
+
1407
+ <div style="width: 300px; height: 100%; margin: 5px; padding: 5px; border: #CCC 2px solid; float: left;">
1408
+ <h4>Media from FTP Add On Wp Cron</h4>
1409
+ <div style="margin: 5px; padding: 5px;"><?php _e('This add-on can register and execute Cron Event with multiple settings by "Media from FTP".', 'media-from-ftp'); ?></div>
1410
+ <div style="margin: 5px; padding: 5px;">
1411
+ <li><?php _e('Can start multiple Cron Events with multiple settings.', 'media-from-ftp'); ?></li>
1412
+ <li><?php _e('Can add intervals of schedule.', 'media-from-ftp'); ?></li>
1413
+ </div>
1414
+ <p>
1415
+ <?php
1416
+ if ( is_dir(WP_PLUGIN_DIR.'/media-from-ftp-add-on-wpcron') ) {
1417
+ ?><div style="margin: 5px; padding: 5px;"><strong><?php
1418
+ _e('Installed', 'media-from-ftp');?> & <?php
1419
+ if ( $this->is_add_on_activate['wpcron'] ) {
1420
+ _e('Activated', 'media-from-ftp');
1421
+ } else {
1422
+ _e('Deactivated', 'media-from-ftp');
1423
+ }
1424
+ ?></strong></div><?php
1425
+ } else {
1426
+ ?>
1427
+ <div>
1428
+ <a href="<?php _e('https://riverforest-wp.info/media-from-ftp-add-on-wpcron/', 'media-from-ftp'); ?>" target="_blank" class="page-title-action"><?php _e('BUY', 'media-from-ftp'); ?> &yen;2,000</a>
1429
+ </div>
1430
+ <?php
1431
+ }
1432
+ ?>
1433
+ </div>
1434
+
1435
+ <div style="width: 300px; height: 100%; margin: 5px; padding: 5px; border: #CCC 2px solid; float: left;">
1436
+ <h4>Media from FTP Add On Category</h4>
1437
+ <div style="margin: 5px; padding: 5px;"><?php _e('This Add-on When registering by "Media from FTP", add Category to Media Library.', 'media-from-ftp'); ?></div>
1438
+ <div style="margin: 5px; padding: 5px;">
1439
+ <li><?php _e('Works with next plugin.', 'media-from-ftp'); ?> [<a style="text-decoration: none;" href="https://wordpress.org/plugins/wp-media-library-categories/" target="_blank">Media Library Categories</a>] [<a style="text-decoration: none;" href="https://wordpress.org/plugins/enhanced-media-library/" target="_blank">Enhanced Media Library</a>] [<a style="text-decoration: none;" href="https://wordpress.org/plugins/media-library-assistant/" target="_blank">Media Library Assistant</a>]</li>
1440
+ </div>
1441
+ <p>
1442
+ <?php
1443
+ if ( is_dir(WP_PLUGIN_DIR.'/media-from-ftp-add-on-category') ) {
1444
+ ?><div style="margin: 5px; padding: 5px;"><strong><?php
1445
+ _e('Installed', 'media-from-ftp');?> & <?php
1446
+ if ( $this->is_add_on_activate['category'] ) {
1447
+ _e('Activated', 'media-from-ftp');
1448
+ } else {
1449
+ _e('Deactivated', 'media-from-ftp');
1450
+ }
1451
+ ?></strong></div><?php
1452
+ } else {
1453
+ ?>
1454
+ <div>
1455
+ <a href="<?php _e('https://riverforest-wp.info/media-from-ftp-add-on-category/', 'media-from-ftp'); ?>" target="_blank" class="page-title-action"><?php _e('BUY', 'media-from-ftp'); ?> &yen;1,000</a>
1456
+ </div>
1457
+ <?php
1458
+ }
1459
+ ?>
1460
+ </div>
1461
+
1462
+ <div style="width: 300px; height: 100%; margin: 5px; padding: 5px; border: #CCC 2px solid; float: left;">
1463
+ <h4>Media from FTP Add On Exif</h4>
1464
+ <div style="margin: 5px; padding: 5px;"><?php _e('This Add-on When registering by "Media from FTP", add Exif to Media Library Caption.', 'media-from-ftp'); ?></div>
1465
+ <div style="margin: 5px; padding: 5px;">
1466
+ <li><?php _e('Sort each Exif data to an arbitrary position and insert it into the caption as text.', 'media-from-ftp'); ?></li>
1467
+ <li><a style="text-decoration: none;" href="https://codex.wordpress.org/Function_Reference/wp_read_image_metadata#Return%20Values" target="_blank">Exif</a></li>
1468
+ </div>
1469
+
1470
+ <p>
1471
+ <?php
1472
+ if ( is_dir(WP_PLUGIN_DIR.'/media-from-ftp-add-on-exif') ) {
1473
+ ?><div style="margin: 5px; padding: 5px;"><strong><?php
1474
+ _e('Installed', 'media-from-ftp');?> & <?php
1475
+ if ( $this->is_add_on_activate['exif'] ) {
1476
+ _e('Activated', 'media-from-ftp');
1477
+ } else {
1478
+ _e('Deactivated', 'media-from-ftp');
1479
+ }
1480
+ ?></strong></div><?php
1481
+ } else {
1482
+ ?>
1483
+ <div>
1484
+ <a href="<?php _e('https://riverforest-wp.info/media-from-ftp-add-on-exif/', 'media-from-ftp'); ?>" target="_blank" class="page-title-action"><?php _e('BUY', 'media-from-ftp'); ?> &yen;500</a>
1485
+ </div>
1486
+ <?php
1487
+ }
1488
+ ?>
1489
+ </div>
1490
+
1491
+ <?php
1492
+ }
1493
+
1494
+ /* ==================================================
1495
+ * Update wp_options table.
1496
+ * @param int $submenu
1497
+ * @since 2.36
1498
+ */
1499
+ function options_updated($submenu){
1500
+
1501
+ $mediafromftp = new MediaFromFtp();
1502
+
1503
+ $mediafromftp_settings = get_option($this->wp_options_name());
1504
+
1505
+ $addonwpcron = FALSE;
1506
+ if ( $this->is_add_on_activate['wpcron'] ) {
1507
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1508
+ $addonwpcron = TRUE;
1509
+ }
1510
+
1511
+ switch ($submenu) {
1512
+ case 1:
1513
+ if ( !empty($_POST['mediafromftp_datefixed']) ) {
1514
+ $datefixed = $_POST['mediafromftp_datefixed'];
1515
+ } else {
1516
+ $datefixed = $mediafromftp_settings['datefixed'];
1517
+ }
1518
+ if ( !empty($_POST['mediafromftp_cron_apply']) ) {
1519
+ $mediafromftp_cron_apply = $_POST['mediafromftp_cron_apply'];
1520
+ } else {
1521
+ $mediafromftp_cron_apply = FALSE;
1522
+ }
1523
+ if ( !empty($_POST['mediafromftp_cron_schedule']) ) {
1524
+ $mediafromftp_cron_schedule = $_POST['mediafromftp_cron_schedule'];
1525
+ } else {
1526
+ $mediafromftp_cron_schedule = $mediafromftp_settings['cron']['schedule'];
1527
+ }
1528
+ if ( !empty($_POST['mediafromftp_cron_limit_number']) ) {
1529
+ $mediafromftp_cron_limit_number = $_POST['mediafromftp_cron_limit_number'];
1530
+ } else {
1531
+ $mediafromftp_cron_limit_number = FALSE;
1532
+ }
1533
+ if ( !empty($_POST['mediafromftp_cron_mail_apply']) ) {
1534
+ $mediafromftp_cron_mail_apply = $_POST['mediafromftp_cron_mail_apply'];
1535
+ } else {
1536
+ $mediafromftp_cron_mail_apply = FALSE;
1537
+ }
1538
+ if ( !empty($_POST['mediafromftp_caption_apply']) ) {
1539
+ $mediafromftp_caption_apply = $_POST['mediafromftp_caption_apply'];
1540
+ } else {
1541
+ $mediafromftp_caption_apply = FALSE;
1542
+ }
1543
+ if ( !empty($_POST['mediafromftp_exif_text']) ) {
1544
+ $exif_text = $_POST['mediafromftp_exif_text'];
1545
+ } else {
1546
+ $exif_text = $mediafromftp_settings['caption']['exif_text'];
1547
+ }
1548
+ if ( !empty($_POST['mediafromftp_exif_default']) ) {
1549
+ $exif_text = '%title% %credit% %camera% %caption% %created_timestamp% %copyright% %aperture% %shutter_speed% %iso% %focal_length%';
1550
+ }
1551
+ if ( !empty($_POST['mediafromftp_apply_log']) ) {
1552
+ $mediafromftp_apply_log = $_POST['mediafromftp_apply_log'];
1553
+ } else {
1554
+ $mediafromftp_apply_log = FALSE;
1555
+ }
1556
+ if ( !empty($_POST['mediafromftp_search_limit_number']) ) {
1557
+ if ( ctype_digit($_POST['mediafromftp_search_limit_number']) ) {
1558
+ $search_limit_number = intval($_POST['mediafromftp_search_limit_number']);
1559
+ if ( $search_limit_number < 100 ) {
1560
+ $search_limit_number = 100;
1561
+ }
1562
+ } else {
1563
+ $search_limit_number = 100000;
1564
+ }
1565
+ } else {
1566
+ $search_limit_number = 100000;
1567
+ }
1568
+ if ( !empty($_POST['mlc_category']) ) {
1569
+ $mlcc = implode(',', $_POST['mlc_category']);
1570
+ } else {
1571
+ $mlcc = NULL;
1572
+ }
1573
+ if ( !empty($_POST['eml_category']) ) {
1574
+ $emlc = implode(',', $_POST['eml_category']);
1575
+ } else {
1576
+ $emlc = NULL;
1577
+ }
1578
+ if ( !empty($_POST['mla_category']) ) {
1579
+ $mlac = implode(',', $_POST['mla_category']);
1580
+ } else {
1581
+ $mlac = NULL;
1582
+ }
1583
+ if ( !empty($_POST['mla_tag']) ) {
1584
+ $mlat = implode(',', $_POST['mla_tag']);
1585
+ } else {
1586
+ $mlat = NULL;
1587
+ }
1588
+ $mediafromftp_tbl = array(
1589
+ 'pagemax' => $mediafromftp_settings['pagemax'],
1590
+ 'basedir' => $mediafromftp_settings['basedir'],
1591
+ 'searchdir' => $mediafromftp_settings['searchdir'],
1592
+ 'ext2typefilter' => $mediafromftp_settings['ext2typefilter'],
1593
+ 'extfilter' => $mediafromftp_settings['extfilter'],
1594
+ 'search_display_metadata' => $mediafromftp_settings['search_display_metadata'],
1595
+ 'dateset' => $_POST['mediafromftp_dateset'],
1596
+ 'datefixed' => $datefixed,
1597
+ 'datetimepicker' => $mediafromftp_settings['datetimepicker'],
1598
+ 'max_execution_time' => intval($_POST['mediafromftp_max_execution_time']),
1599
+ 'character_code' => $_POST['mediafromftp_character_code'],
1600
+ 'exclude' => $mediafromftp_settings['exclude'],
1601
+ 'thumb_deep_search' => $mediafromftp_settings['thumb_deep_search'],
1602
+ 'search_limit_number' => $search_limit_number,
1603
+ 'cron' => array(
1604
+ 'apply' => $mediafromftp_cron_apply,
1605
+ 'schedule' => $mediafromftp_cron_schedule,
1606
+ 'limit_number' => $mediafromftp_cron_limit_number,
1607
+ 'mail_apply' => $mediafromftp_cron_mail_apply,
1608
+ 'mail' => $mediafromftp_settings['cron']['mail'],
1609
+ 'user' => $mediafromftp_settings['cron']['user']
1610
+ ),
1611
+ 'caption' => array(
1612
+ 'apply' => $mediafromftp_caption_apply,
1613
+ 'exif_text' => $exif_text
1614
+ ),
1615
+ 'log' => $mediafromftp_apply_log,
1616
+ 'mlcc' => $mlcc,
1617
+ 'emlc' => $emlc,
1618
+ 'mlac' => $mlac,
1619
+ 'mlat' => $mlat
1620
+ );
1621
+ update_option( $this->wp_options_name(), $mediafromftp_tbl );
1622
+ if ( !empty($_POST['move_yearmonth_folders']) ) {
1623
+ update_option( 'uploads_use_yearmonth_folders', $_POST['move_yearmonth_folders'] );
1624
+ } else {
1625
+ update_option( 'uploads_use_yearmonth_folders', '0' );
1626
+ }
1627
+ echo '<div class="notice notice-success is-dismissible"><ul><li>'.__('Settings').' --> '.__('Changes saved.').'</li></ul></div>';
1628
+ break;
1629
+ case 2:
1630
+ if (!empty($_POST['mediafromftp_pagemax'])){
1631
+ $pagemax = intval($_POST['mediafromftp_pagemax']);
1632
+ } else {
1633
+ $pagemax = $mediafromftp_settings['pagemax'];
1634
+ }
1635
+ if ( !empty($_POST['mediafromftp_datetimepicker']) ) {
1636
+ $datetimepicker = intval($_POST['mediafromftp_datetimepicker']);
1637
+ } else {
1638
+ $datetimepicker = 0;
1639
+ }
1640
+ $basedir = $mediafromftp_settings['basedir'];
1641
+ if (!empty($_POST['searchdir'])){
1642
+ $searchdir = urldecode($_POST['searchdir']);
1643
+ } else {
1644
+ $searchdir = $mediafromftp_settings['searchdir'];
1645
+ if ( MEDIAFROMFTP_PLUGIN_UPLOAD_PATH <> $basedir ) {
1646
+ $searchdir = MEDIAFROMFTP_PLUGIN_UPLOAD_PATH;
1647
+ $basedir = MEDIAFROMFTP_PLUGIN_UPLOAD_PATH;
1648
+ }
1649
+ }
1650
+ if (!empty($_POST['ext2type'])){
1651
+ $ext2typefilter = $_POST['ext2type'];
1652
+ } else {
1653
+ $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
1654
+ }
1655
+ if (!empty($_POST['extension'])){
1656
+ if ( $_POST['extension'] === 'all') {
1657
+ $extfilter = 'all';
1658
+ } else {
1659
+ if ( $ext2typefilter === 'all' || $ext2typefilter === wp_ext2type($_POST['extension']) ) {
1660
+ $extfilter = $_POST['extension'];
1661
+ } else {
1662
+ $extfilter = 'all';
1663
+ }
1664
+ }
1665
+ } else {
1666
+ $extfilter = $mediafromftp_settings['extfilter'];
1667
+ }
1668
+ if (isset($_POST['search_display_metadata'])){
1669
+ $search_display_metadata = $_POST['search_display_metadata'];
1670
+ } else {
1671
+ $search_display_metadata = $mediafromftp_settings['search_display_metadata'];
1672
+ }
1673
+ if (!empty($_POST['mediafromftp_exclude'])){
1674
+ $mediafromftp_exclude = stripslashes($_POST['mediafromftp_exclude']);
1675
+ } else {
1676
+ $mediafromftp_exclude = $mediafromftp_settings['exclude'];
1677
+ }
1678
+ if (isset($_POST['mediafromftp_thumb_deep_search'])){
1679
+ $mediafromftp_thumb_deep_search = $_POST['mediafromftp_thumb_deep_search'];
1680
+ } else {
1681
+ $mediafromftp_thumb_deep_search = $mediafromftp_settings['thumb_deep_search'];
1682
+ }
1683
+ $mediafromftp_tbl = array(
1684
+ 'pagemax' => $pagemax,
1685
+ 'basedir' => $basedir,
1686
+ 'searchdir' => $searchdir,
1687
+ 'ext2typefilter' => $ext2typefilter,
1688
+ 'extfilter' => $extfilter,
1689
+ 'search_display_metadata' => $search_display_metadata,
1690
+ 'dateset' => $mediafromftp_settings['dateset'],
1691
+ 'datefixed' => $mediafromftp_settings['datefixed'],
1692
+ 'datetimepicker' => $datetimepicker,
1693
+ 'max_execution_time' => $mediafromftp_settings['max_execution_time'],
1694
+ 'character_code' => $mediafromftp_settings['character_code'],
1695
+ 'exclude' => $mediafromftp_exclude,
1696
+ 'thumb_deep_search' => $mediafromftp_thumb_deep_search,
1697
+ 'search_limit_number' => $mediafromftp_settings['search_limit_number'],
1698
+ 'cron' => array(
1699
+ 'apply' => $mediafromftp_settings['cron']['apply'],
1700
+ 'schedule' => $mediafromftp_settings['cron']['schedule'],
1701
+ 'limit_number' => $mediafromftp_settings['cron']['limit_number'],
1702
+ 'mail_apply' => $mediafromftp_settings['cron']['mail_apply'],
1703
+ 'mail' => $mediafromftp_settings['cron']['mail'],
1704
+ 'user' => $mediafromftp_settings['cron']['user']
1705
+ ),
1706
+ 'caption' => array(
1707
+ 'apply' => $mediafromftp_settings['caption']['apply'],
1708
+ 'exif_text' => $mediafromftp_settings['caption']['exif_text']
1709
+ ),
1710
+ 'log' => $mediafromftp_settings['log'],
1711
+ 'mlcc' => $mediafromftp_settings['mlcc'],
1712
+ 'emlc' => $mediafromftp_settings['emlc'],
1713
+ 'mlac' => $mediafromftp_settings['mlac'],
1714
+ 'mlat' => $mediafromftp_settings['mlat']
1715
+ );
1716
+ update_option( $this->wp_options_name(), $mediafromftp_tbl );
1717
+ break;
1718
+ case 3:
1719
+ if ( !empty($_POST['mediafromftp_clear_cash']) ) {
1720
+ $del_cash_count = $mediafromftp->delete_all_cash();
1721
+ if ( $del_cash_count > 0 ) {
1722
+ echo '<div class="notice notice-success is-dismissible"><ul><li>'.__('Thumbnails Cache', 'media-from-ftp').' --> '.__('Delete').'</li></ul></div>';
1723
+ } else {
1724
+ echo '<div class="notice notice-info is-dismissible"><ul><li>'.__('No Thumbnails Cache', 'media-from-ftp').'</li></ul></div>';
1725
+ }
1726
+ }
1727
+ break;
1728
+ case 4:
1729
+ // for media-from-ftp-add-on-wpcron
1730
+ if ( $addonwpcron ) {
1731
+ if ( !empty($_POST['mediafromftp_run_cron']) ) {
1732
+ $mediafromftp_cron_events = get_option( $this->wp_add_on_wpcron_events_name() );
1733
+ if ( !empty($_POST['cron-run']) ) {
1734
+ $option_name = $_POST['cron-run'];
1735
+ echo $mediafromftpaddonwpcron->CronRun($option_name);
1736
+ } elseif ( !empty($_POST['cron-start']) ) {
1737
+ $option_name = $_POST['cron-start'];
1738
+ echo $mediafromftpaddonwpcron->CronRunStart($option_name);
1739
+ } elseif ( !empty($_POST['cron-stop']) ) {
1740
+ $option_name = $_POST['cron-stop'];
1741
+ echo $mediafromftpaddonwpcron->CronRunStop($option_name);
1742
+ }
1743
+ }
1744
+ } else {
1745
+ $mediafromftp_settings['cron']['apply'] = FALSE;
1746
+ update_option( $this->wp_options_name(), $mediafromftp_settings );
1747
+ }
1748
+ break;
1749
+ case 5:
1750
+ // for media-from-ftp-add-on-wpcron
1751
+ if ( !empty($_POST['mediafromftp_add_schedule']) ) {
1752
+ if ( !empty($_POST['mediafromftp_cron_schedule_innername']) && !empty($_POST['mediafromftp_cron_schedule_secounds']) && !empty($_POST['mediafromftp_cron_schedule_viewname']) ) {
1753
+ $mediafromftp_cron_intervals_tbl = get_option( 'mediafromftp_event_intervals' );
1754
+ $innername = $_POST['mediafromftp_cron_schedule_innername'];
1755
+ $secounds = intval($_POST['mediafromftp_cron_schedule_secounds']);
1756
+ $viewname = $_POST['mediafromftp_cron_schedule_viewname'];
1757
+ $mediafromftp_cron_intervals_tbl[$innername] = array(
1758
+ 'interval' => $secounds,
1759
+ 'display' => $viewname
1760
+ );
1761
+ update_option( 'mediafromftp_event_intervals', $mediafromftp_cron_intervals_tbl );
1762
+ echo $mediafromftpaddonwpcron->mediafromftp_schedule_notice_html($submenu);
1763
+ }
1764
+ }
1765
+ break;
1766
+ case 6:
1767
+ // for media-from-ftp-add-on-wpcron
1768
+ if ( !empty($_POST['mediafromftp_add_schedule_delete']) ) {
1769
+ if ( !empty($_POST['mediafromftp_cron_schedule_delete']) ) {
1770
+ $delete_keys = $_POST['mediafromftp_cron_schedule_delete'];
1771
+ $mediafromftp_cron_intervals_tbl = get_option( 'mediafromftp_event_intervals' );
1772
+ foreach ( $delete_keys as $key ) {
1773
+ unset($mediafromftp_cron_intervals_tbl[$key]);
1774
+ }
1775
+ update_option( 'mediafromftp_event_intervals', $mediafromftp_cron_intervals_tbl );
1776
+ echo $mediafromftpaddonwpcron->mediafromftp_schedule_notice_html($submenu);
1777
+ }
1778
+ }
1779
+ break;
1780
+ case 7:
1781
+ // for media-from-ftp-add-on-wpcron
1782
+ if ( !empty($_POST['mediafromftp_cron_event_create']) ) {
1783
+ $event_id = date_i18n("Y-m-d-H-i-s");
1784
+ $event_option_name = 'mediafromftp_cronevent-'.$event_id;
1785
+ $mediafromftp_cron_events = get_option( $this->wp_add_on_wpcron_events_name(), array() );
1786
+ $mediafromftp_cron_events[$event_id] = $event_option_name;
1787
+ update_option( $this->wp_add_on_wpcron_events_name(), $mediafromftp_cron_events );
1788
+ update_option( $event_option_name, $mediafromftp_settings);
1789
+ echo $mediafromftpaddonwpcron->mediafromftp_cronevent_create_html();
1790
+ }
1791
+ break;
1792
+ }
1793
+
1794
+ }
1795
+
1796
+ /* ==================================================
1797
+ * @param none
1798
+ * @return string $wp_options_name
1799
+ * @since 9.18
1800
+ */
1801
+ function wp_options_name(){
1802
+
1803
+ $user = wp_get_current_user();
1804
+ $cron_user = $user->ID;
1805
+
1806
+ $wp_options_name = 'mediafromftp_settings'.'_'.$cron_user;
1807
+
1808
+ return $wp_options_name;
1809
+
1810
+ }
1811
+
1812
+ /* ==================================================
1813
+ * @param none
1814
+ * @return string $wp_cron_events_name
1815
+ * @since 9.71
1816
+ */
1817
+ function wp_add_on_wpcron_events_name(){
1818
+
1819
+ $user = wp_get_current_user();
1820
+ $cron_user = $user->ID;
1821
+
1822
+ $wp_cron_events_name = 'mediafromftp_add_on_wpcron_events'.'_'.$cron_user;
1823
+
1824
+ return $wp_cron_events_name;
1825
+
1826
+ }
1827
+
1828
+ /* ==================================================
1829
+ * @param string $output
1830
+ * @return string $output
1831
+ * @since 9.75
1832
+ */
1833
+ function custom_robots_txt($output) {
1834
+
1835
+ $public = get_option( 'blog_public' );
1836
+ if ( '0' != $public ) {
1837
+ $output .= 'Disallow: '.MEDIAFROMFTP_PLUGIN_DISALLOW_TMP_DIR."\n";
1838
+ }
1839
+
1840
+ return $output;
1841
+
1842
+ }
1843
+
1844
+ }
1845
+ ?>
req/MediaFromFtpAjax.php ADDED
@@ -0,0 +1,276 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media from FTP
4
+ *
5
+ * @package Media from FTP
6
+ * @subpackage MediafromFtpAjax
7
+ /* Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
8
+ This program is free software; you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation; version 2 of the License.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program; if not, write to the Free Software
19
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ */
21
+
22
+ class MediaFromFtpAjax {
23
+
24
+ private $is_add_on_activate;
25
+
26
+ /* ==================================================
27
+ * Construct
28
+ * @since 9.81
29
+ */
30
+ function __construct() {
31
+
32
+ $category_active = FALSE;
33
+ if( function_exists('media_from_ftp_add_on_category_load_textdomain') ){
34
+ include_once MEDIAFROMFTP_ADDON_CATEGORY_PLUGIN_BASE_DIR.'/inc/MediaFromFtpAddOnCategory.php';
35
+ $category_active = TRUE;
36
+ }
37
+
38
+ $this->is_add_on_activate = array(
39
+ 'category' => $category_active
40
+ );
41
+
42
+ if(!class_exists('MediaFromFtpAdmin')){
43
+ require_once( MEDIAFROMFTP_PLUGIN_BASE_DIR.'/req/MediaFromFtpAdmin.php' );
44
+ }
45
+ if(!class_exists('MediaFromFtp')){
46
+ include_once MEDIAFROMFTP_PLUGIN_BASE_DIR.'/inc/MediaFromFtp.php';
47
+ }
48
+
49
+ }
50
+
51
+ /* ==================================================
52
+ * Update Files Callback
53
+ *
54
+ * @since 9.30
55
+ */
56
+ function mediafromftp_update_callback(){
57
+
58
+ $action1 = 'mediafromftp-update-ajax-action';
59
+ if ( isset( $_REQUEST['nonce'] ) && wp_verify_nonce( $_REQUEST['nonce'], $action1 ) ) {
60
+ if ( current_user_can( 'upload_files' ) ) {
61
+ $maxcount = intval($_POST["maxcount"]);
62
+ $new_url_attach = $_POST["new_url"];
63
+ $new_url_datetime = $_POST["new_datetime"];
64
+ $new_url_mlccategory = NULL;
65
+ $new_url_emlcategory = NULL;
66
+ $new_url_mlacategory = NULL;
67
+ $new_url_mlatags = NULL;
68
+ if ( $this->is_add_on_activate['category'] ) {
69
+ $new_url_mlccategory = $_POST["new_mlccategory"];
70
+ $new_url_emlcategory = $_POST["new_emlcategory"];
71
+ $new_url_mlacategory = $_POST["new_mlacategory"];
72
+ $new_url_mlatags = $_POST["new_mlatags"];
73
+ }
74
+
75
+ $mediafromftpadmin = new MediaFromFtpAdmin();
76
+ $mediafromftp_settings = get_option($mediafromftpadmin->wp_options_name());
77
+ unset($mediafromftpadmin);
78
+
79
+ if (!empty($new_url_attach)) {
80
+
81
+ $mediafromftp = new MediaFromFtp();
82
+
83
+ $dateset = $mediafromftp_settings['dateset'];
84
+ $datefixed = $mediafromftp_settings['datefixed'];
85
+ $yearmonth_folders = get_option('uploads_use_yearmonth_folders');
86
+ $exif_text_tag = NULL;
87
+ if ( $mediafromftp_settings['caption']['apply'] ) {
88
+ $exif_text_tag = $mediafromftp_settings['caption']['exif_text'];
89
+ }
90
+
91
+ $exts = explode('.', wp_basename($new_url_attach));
92
+ $ext = end($exts);
93
+
94
+ // Delete Cash
95
+ $mediafromftp->delete_cash($ext, $new_url_attach);
96
+
97
+ // Regist
98
+ list($attach_id, $new_attach_title, $new_url_attach, $metadata) = $mediafromftp->regist($ext, $new_url_attach, $new_url_datetime, $dateset, $datefixed, $yearmonth_folders, $mediafromftp_settings['character_code'], $mediafromftp_settings['cron']['user']);
99
+
100
+ $cat_html = NULL;
101
+ $mlccategory = NULL;
102
+ $emlcategory = NULL;
103
+ $mlacategory = NULL;
104
+ $mlatag = NULL;
105
+ if ( $this->is_add_on_activate['category'] ) {
106
+ $mediafromftpaddoncategory = new MediaFromFtpAddOnCategory();
107
+ list($cat_html, $cat_text, $mlccategory, $emlcategory, $mlacategory, $mlatag) = $mediafromftpaddoncategory->regist_term($attach_id, $new_url_mlccategory, $new_url_emlcategory, $new_url_mlacategory, $new_url_mlatags);
108
+ unset($mediafromftpaddoncategory);
109
+ }
110
+
111
+ if ( $attach_id == -1 || $attach_id == -2 ) { // error
112
+ $error_title = $mediafromftp->mb_utf8($new_attach_title, $mediafromftp_settings['character_code']);
113
+ $error_url = $mediafromftp->mb_utf8($new_url_attach, $mediafromftp_settings['character_code']);
114
+ if ( $attach_id == -1 ) {
115
+ echo '<div class="notice notice-error is-dismissible"><ul><li>'.'<div>'.__('File name:').$error_title.'</div>'.'<div>'.__('Directory name:', 'media-from-ftp').$error_url.'</div>'.sprintf(__('<div>You need to make this directory writable before you can register this file. See <a href="%1$s" target="_blank">the Codex</a> for more information.</div><div>Or, filename or directoryname must be changed of illegal. Please change Character Encodings for Server of <a href="%2$s">Settings</a>.</div>', 'media-from-ftp'), 'https://codex.wordpress.org/Changing_File_Permissions', admin_url('admin.php?page=mediafromftp-settings')).'</li></div>';
116
+ } else if ( $attach_id == -2 ) {
117
+ echo '<div class="notice notice-error is-dismissible"><ul><li><div>'.__('Title').': '.$error_title.'</div>'.'<div>URL: '.$error_url.'</div><div>'.__('This file could not be registered in the database.', 'media-from-ftp').'</div></li></ul></div>';
118
+ }
119
+ } else {
120
+ // Outputdata
121
+ list($imagethumburls, $mimetype, $length, $stamptime, $file_size, $exif_text) = $mediafromftp->output_metadata($ext, $attach_id, $metadata, $mediafromftp_settings['character_code'], $exif_text_tag);
122
+
123
+ $image_attr_thumbnail = wp_get_attachment_image_src($attach_id, 'thumbnail', true);
124
+
125
+ $output_html = $mediafromftp->output_html_and_log($ext, $attach_id, $new_attach_title, $new_url_attach, $imagethumburls, $mimetype, $length, $stamptime, $file_size, $exif_text, $image_attr_thumbnail, $mediafromftp_settings, $cat_html, $mlccategory, $emlcategory, $mlacategory, $mlatag);
126
+
127
+ header('Content-type: text/html; charset=UTF-8');
128
+ echo $output_html;
129
+
130
+ }
131
+ unset($mediafromftp);
132
+
133
+ }
134
+ }
135
+ } else {
136
+ status_header( '403' );
137
+ echo 'Forbidden';
138
+ }
139
+
140
+ wp_die();
141
+
142
+ }
143
+
144
+ /* ==================================================
145
+ * Update Messages Callback
146
+ *
147
+ * @since 9.30
148
+ */
149
+ function mediafromftp_message_callback(){
150
+
151
+ $error_count = intval($_POST["error_count"]);
152
+ $error_update = $_POST["error_update"];
153
+ $success_count = intval($_POST["success_count"]);
154
+
155
+ $output_html = NULL;
156
+ if ( $error_count > 0 ) {
157
+ $error_message = sprintf(__('Errored to the registration of %1$d files.', 'media-from-ftp'), $error_count);
158
+ $output_html .= '<div class="notice notice-error is-dismissible"><ul><li><div>'.$error_message.'</div>'.$error_update.'</li></ul></div>';
159
+ }
160
+ $success_message = sprintf(__('Succeeded to the registration of %1$d files.', 'media-from-ftp'), $success_count);
161
+ $output_html .= '<div class="notice notice-success is-dismissible"><ul><li><div>'.$success_message.'</li></ul></div>';
162
+
163
+ header('Content-type: text/html; charset=UTF-8');
164
+ echo $output_html;
165
+
166
+ wp_die();
167
+
168
+ }
169
+
170
+ /* ==================================================
171
+ * Import Files Callback
172
+ *
173
+ * @since 9.40
174
+ */
175
+ function mediafromftp_medialibraryimport_update_callback(){
176
+
177
+ $action2 = 'mediafromftp-import-ajax-action';
178
+ if ( isset( $_REQUEST['nonce'] ) && wp_verify_nonce( $_REQUEST['nonce'], $action2 ) ) {
179
+ if ( current_user_can( 'upload_files' ) ) {
180
+ $file = $_POST["file"];
181
+ $filepath = str_replace(MEDIAFROMFTP_PLUGIN_UPLOAD_DIR.'/' , '', $file);
182
+ if ( is_file($file) ) {
183
+ if ( !empty($_POST["db_array"]) ) {
184
+ $db_array = $_POST["db_array"];
185
+ global $wpdb;
186
+ $table_name = $wpdb->prefix.'posts';
187
+ $wpdb->insert( $table_name, $db_array );
188
+ update_attached_file( $db_array['ID'], $filepath ) ;
189
+ if ( !empty($_POST["db_wp_attachment_metadata"]) ) {
190
+ $metadata_json = stripslashes($_POST["db_wp_attachment_metadata"]);
191
+ $metadata = json_decode($metadata_json);
192
+ $table_meta_name = $wpdb->prefix.'postmeta';
193
+ $db_meta_array = array(
194
+ "post_id" => $db_array['ID'],
195
+ "meta_key" => '_wp_attachment_metadata',
196
+ "meta_value" => $metadata
197
+ );
198
+ $wpdb->insert( $table_meta_name, $db_meta_array );
199
+ }
200
+ if ( !empty($_POST["db_thumbnail_id"]) ) {
201
+ update_post_meta( $db_array['ID'], '_thumbnail_id', $_POST["db_thumbnail_id"] );
202
+ }
203
+ if ( !empty($_POST["db_cover_hash"]) ) {
204
+ update_post_meta( $db_array['ID'], '_cover_hash', $_POST["db_cover_hash"] );
205
+ }
206
+ if ( !empty($_POST["db_wp_attachment_image_alt"]) ) {
207
+ update_post_meta( $db_array['ID'], '_wp_attachment_image_alt', $_POST["db_wp_attachment_image_alt"] );
208
+ }
209
+ $msg = 'success_db';
210
+ $output_html = $msg.','.'<div>'.__('Media').': <a href="'.get_permalink($db_array['ID']).'" target="_blank" style="text-decoration: none; color: green;">'.$this->esc_title($db_array['post_title']).'</a>: '.'<a href="'.MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/'.$filepath.'" target="_blank" style="text-decoration: none;">'.$filepath.'</a></div>';
211
+ } else {
212
+ $msg = 'success';
213
+ $output_html = $msg.','.'<div>'.__('Thumbnail').': '.'<a href="'.MEDIAFROMFTP_PLUGIN_UPLOAD_URL.'/'.$filepath.'" target="_blank" style="text-decoration: none;">'.$filepath.'</a></div>';
214
+ }
215
+ } else {
216
+ $error_string = __('No file!', 'media-from-ftp');
217
+ $msg = '<div>'.$filepath.': '.$error_string.'</div>';
218
+ $output_html = $msg.','.'<div>'.$filepath.'<span style="color: red;"> &#8811; '.$error_string.'</span></div>';
219
+ }
220
+
221
+ header('Content-type: text/html; charset=UTF-8');
222
+ echo $output_html;
223
+ }
224
+ } else {
225
+ status_header( '403' );
226
+ echo 'Forbidden';
227
+ }
228
+
229
+ wp_die();
230
+
231
+ }
232
+
233
+ /* ==================================================
234
+ * Import Messages Callback
235
+ *
236
+ * @since 9.40
237
+ */
238
+ function mediafromftp_medialibraryimport_message_callback(){
239
+
240
+ $error_count = intval($_POST["error_count"]);
241
+ $error_update = $_POST["error_update"];
242
+ $success_count = intval($_POST["success_count"]);
243
+ $db_success_count = intval($_POST["db_success_count"]);
244
+
245
+ $output_html = NULL;
246
+ if ( $error_count > 0 ) {
247
+ $error_message = sprintf(__('Errored to the registration of %1$d files.', 'media-from-ftp'), $error_count);
248
+ $output_html .= '<div class="notice notice-error is-dismissible"><ul><li><div>'.$error_message.'</div>'.$error_update.'</li></ul></div>';
249
+ }
250
+ $success_message = sprintf(__('Succeeded to the registration of %1$d files and %2$d items for MediaLibrary.', 'media-from-ftp'), $success_count, $db_success_count);
251
+ $output_html .= '<div class="notice notice-success is-dismissible"><ul><li><div>'.$success_message.'</li></ul></div>';
252
+
253
+ header('Content-type: text/html; charset=UTF-8');
254
+ echo $output_html;
255
+
256
+ wp_die();
257
+
258
+ }
259
+
260
+ /* ==================================================
261
+ * Escape Title
262
+ * @param string $str
263
+ * @return string $str
264
+ * @since 9.41
265
+ */
266
+ function esc_title($str){
267
+
268
+ $str = esc_html($str);
269
+ $str = str_replace(',', '&#44;', $str);
270
+
271
+ return $str;
272
+ }
273
+
274
+ }
275
+
276
+ ?>
req/MediaFromFtpListTable.php ADDED
@@ -0,0 +1,368 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media from FTP
4
+ *
5
+ * @package Media from FTP
6
+ * @subpackage MediaFromFtp List Table
7
+ * reference Custom List Table Example
8
+ * https://wordpress.org/plugins/custom-list-table-example/
9
+ /* Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
10
+ This program is free software; you can redistribute it and/or modify
11
+ it under the terms of the GNU General Public License as published by
12
+ the Free Software Foundation; version 2 of the License.
13
+
14
+ This program is distributed in the hope that it will be useful,
15
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ GNU General Public License for more details.
18
+
19
+ You should have received a copy of the GNU General Public License
20
+ along with this program; if not, write to the Free Software
21
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
+ */
23
+
24
+ if(!class_exists('WP_List_Table')){
25
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-screen.php' );
26
+ require_once( ABSPATH . 'wp-admin/includes/screen.php' );
27
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
28
+ require_once( ABSPATH . 'wp-admin/includes/template.php' );
29
+ }
30
+
31
+ class TT_MediaFromFtp_List_Table extends WP_List_Table {
32
+
33
+ public $max_items;
34
+ private $is_add_on_activate;
35
+
36
+ function __construct(){
37
+
38
+ $category_active = FALSE;
39
+ if( function_exists('media_from_ftp_add_on_category_load_textdomain') ){
40
+ include_once MEDIAFROMFTP_ADDON_CATEGORY_PLUGIN_BASE_DIR.'/inc/MediaFromFtpAddOnCategory.php';
41
+ $category_active = TRUE;
42
+ }
43
+ if( function_exists('media_from_ftp_add_on_exif_load_textdomain') ){
44
+ include_once MEDIAFROMFTP_ADDON_EXIF_PLUGIN_BASE_DIR.'/inc/MediaFromFtpAddOnExif.php';
45
+ }
46
+ if( function_exists('media_from_ftp_add_on_cli_load_textdomain') ){
47
+ require_once( MEDIAFROMFTP_ADDON_CLI_PLUGIN_BASE_DIR.'/req/MediaFromFtpCli.php' );
48
+ }
49
+ if( function_exists('media_from_ftp_add_on_wpcron_load_textdomain') ){
50
+ include_once MEDIAFROMFTP_ADDON_WPCRON_PLUGIN_BASE_DIR.'/inc/MediaFromFtpAddOnWpcron.php';
51
+ }
52
+
53
+ if(!class_exists('MediaFromFtp')){
54
+ include_once MEDIAFROMFTP_PLUGIN_BASE_DIR.'/inc/MediaFromFtp.php';
55
+ }
56
+
57
+ // Media Library Categories
58
+ $mlc_active = FALSE;
59
+ if ( function_exists( 'wpmediacategory_init' ) ) {
60
+ $mlc_active = TRUE;
61
+ }
62
+
63
+ // Enhanced Media Library
64
+ $eml_active = FALSE;
65
+ if ( function_exists( 'wpuxss_eml_on_plugins_loaded' ) ) {
66
+ $eml_active = TRUE;
67
+ }
68
+
69
+ // Media Library Assistant
70
+ $mla_active = FALSE;
71
+ if ( function_exists( 'mla_name_conflict_reporting_action' ) ) {
72
+ $mla_active = TRUE;
73
+ }
74
+
75
+ $this->is_add_on_activate = array(
76
+ 'category' => $category_active,
77
+ 'mlc' => $mlc_active,
78
+ 'eml' => $eml_active,
79
+ 'mla' => $mla_active
80
+ );
81
+
82
+ global $status, $page;
83
+ //Set parent defaults
84
+ parent::__construct( array(
85
+ 'singular' => 'new_url_attaches',
86
+ 'ajax' => false
87
+ ) );
88
+
89
+ }
90
+
91
+ /* ==================================================
92
+ * @return array $listtable_array
93
+ * @since 9.50
94
+ */
95
+ function read_data(){
96
+
97
+ $mediafromftp = new MediaFromFtp();
98
+ $mediafromftp_settings = get_option($this->wp_options_name());
99
+ $pagemax = $mediafromftp_settings['pagemax'];
100
+ $searchdir = $mediafromftp_settings['searchdir'];
101
+ $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
102
+ $extfilter = $mediafromftp_settings['extfilter'];
103
+ $max_execution_time = $mediafromftp_settings['max_execution_time'];
104
+
105
+ $mlccs = explode(',', $mediafromftp_settings['mlcc']);
106
+ $emlcs = explode(',', $mediafromftp_settings['emlc']);
107
+ $mlacs = explode(',', $mediafromftp_settings['mlac']);
108
+ $mlats = explode(',', $mediafromftp_settings['mlat']);
109
+
110
+ $document_root = ABSPATH.$searchdir;
111
+
112
+ $mediafromftp->mb_initialize($mediafromftp_settings['character_code']);
113
+ $document_root = $mediafromftp->mb_encode_multibyte($document_root, $mediafromftp_settings['character_code']);
114
+
115
+ if ( strstr($searchdir, '../') ) {
116
+ $document_root = realpath($document_root);
117
+ }
118
+
119
+ global $wpdb;
120
+ $attachments = $wpdb->get_results("
121
+ SELECT ID
122
+ FROM $wpdb->posts
123
+ WHERE post_type = 'attachment'
124
+ ");
125
+
126
+ $extpattern = $mediafromftp->extpattern($extfilter);
127
+ $files = $mediafromftp->scan_file($document_root, $extpattern, $mediafromftp_settings);
128
+
129
+ $count = 0;
130
+ $listtable_array = array();
131
+ foreach ( $files as $file ){
132
+ // Input URL
133
+ list($new_file, $ext, $new_url) = $mediafromftp->input_url($file, $attachments, $mediafromftp_settings['character_code'], $mediafromftp_settings['thumb_deep_search']);
134
+ if ( $new_file ) {
135
+ ++$count;
136
+ list($inputhtml, $datetimehtml) = $mediafromftp->input_html($ext, $file, $new_url, $count, $mediafromftp_settings);
137
+
138
+ $mlccategoryhtml = NULL;
139
+ $emlcategoryhtml = NULL;
140
+ $mlacategoryhtml = NULL;
141
+ if ( $this->is_add_on_activate['category'] ) {
142
+ include_once MEDIAFROMFTP_ADDON_CATEGORY_PLUGIN_BASE_DIR.'/inc/MediaFromFtpAddOnCategory.php';
143
+ $mediafromftpaddoncategory = new MediaFromFtpAddOnCategory();
144
+ $mlccategoryhtml = $mediafromftpaddoncategory->mlc_category_check_html($count, $mlccs);
145
+ $emlcategoryhtml = $mediafromftpaddoncategory->eml_category_check_html($count, $emlcs);
146
+ $mlacategoryhtml = $mediafromftpaddoncategory->mla_category_check_html($count, $mlacs, $mlats);
147
+ unset($mediafromftpaddoncategory);
148
+ }
149
+
150
+ $listtable_array[] = array(
151
+ 'ID' => $count,
152
+ 'title' => $inputhtml,
153
+ 'new_url' => $new_url,
154
+ 'datetime' => $datetimehtml,
155
+ 'mlccategories' => $mlccategoryhtml,
156
+ 'emlcategories' => $emlcategoryhtml,
157
+ 'mlacategories' => $mlacategoryhtml
158
+ );
159
+
160
+ }
161
+ }
162
+ unset($files, $mediafromftp, $attachments);
163
+
164
+ return $listtable_array;
165
+
166
+ }
167
+
168
+ /* ==================================================
169
+ * @param none
170
+ * @return string $wp_options_name
171
+ * @since 9.18
172
+ * There is the same function. (rec/MediaFromFtpAdmin.php)
173
+ */
174
+ function wp_options_name(){
175
+
176
+ $user = wp_get_current_user();
177
+ $cron_user = $user->ID;
178
+
179
+ $wp_options_name = 'mediafromftp_settings'.'_'.$cron_user;
180
+
181
+ return $wp_options_name;
182
+
183
+ }
184
+
185
+ function column_default($item, $column_name){
186
+ switch($column_name){
187
+ case 'datetime':
188
+ case 'mlccategories':
189
+ case 'emlcategories':
190
+ case 'mlacategories':
191
+ return $item[$column_name];
192
+ default:
193
+ return print_r($item,true); //Show the whole array for troubleshooting purposes
194
+ }
195
+ }
196
+
197
+ function column_title($item){
198
+ //Return the title contents
199
+ return sprintf('%1$s <span style="color:silver"></span>',
200
+ /*$1%s*/ $item['title']
201
+ );
202
+ }
203
+
204
+ function column_cb($item){
205
+ return sprintf(
206
+ '<input type="checkbox" name="%1$s[%2$s][url]" value="%3$s" form="mediafromftp_ajax_update" />',
207
+ /*$1%s*/ $this->_args['singular'],
208
+ /*$2%s*/ $item['ID'],
209
+ /*$3%s*/ $item['new_url']
210
+ );
211
+ }
212
+
213
+ function get_columns(){
214
+ $columns = array(
215
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
216
+ 'title' => 'URL',
217
+ 'datetime' => __('Edit date and time'),
218
+ 'mlccategories' => '<div>'.__('Categories').'<div></div>'.'Media Library Categories'.'</div>',
219
+ 'emlcategories' => '<div>'.__('Categories').'<div></div>'.'Enhanced Media Library'.'</div>',
220
+ 'mlacategories' => '<div>'.__('Categories').' & '.__('Tags').'<div></div>'.'Media Library Assistant'.'</div>'
221
+ );
222
+ $mediafromftp_settings = get_option($this->wp_options_name());
223
+ if ( $mediafromftp_settings['dateset'] === 'new' || $mediafromftp_settings['dateset'] === 'fixed' ) unset($columns['datetime']);
224
+
225
+ if ( $this->is_add_on_activate['category'] ) {
226
+ if ( !$this->is_add_on_activate['mlc'] ) unset($columns['mlccategories']);
227
+ if ( !$this->is_add_on_activate['eml'] ) unset($columns['emlcategories']);
228
+ if ( !$this->is_add_on_activate['mla'] ) unset($columns['mlacategories']);
229
+ } else {
230
+ unset($columns['mlccategories']);
231
+ unset($columns['emlcategories']);
232
+ unset($columns['mlacategories']);
233
+ }
234
+
235
+ return $columns;
236
+ }
237
+
238
+ function get_sortable_columns() {
239
+ $sortable_columns = array(
240
+ 'title' => array('title',false)
241
+ );
242
+ return $sortable_columns;
243
+ }
244
+
245
+ /** ************************************************************************
246
+ * REQUIRED! This is where you prepare your data for display. This method will
247
+ * usually be used to query the database, sort and filter the data, and generally
248
+ * get it ready to be displayed. At a minimum, we should set $this->items and
249
+ * $this->set_pagination_args(), although the following properties and methods
250
+ * are frequently interacted with here...
251
+ *
252
+ * @global WPDB $wpdb
253
+ * @uses $this->_column_headers
254
+ * @uses $this->items
255
+ * @uses $this->get_columns()
256
+ * @uses $this->get_sortable_columns()
257
+ * @uses $this->get_pagenum()
258
+ * @uses $this->set_pagination_args()
259
+ **************************************************************************/
260
+ function prepare_items() {
261
+
262
+ /**
263
+ * First, lets decide how many records per page to show
264
+ */
265
+ $mediafromftp_settings = get_option($this->wp_options_name());
266
+ $per_page = $mediafromftp_settings['pagemax'];
267
+
268
+ /**
269
+ * REQUIRED. Now we need to define our column headers. This includes a complete
270
+ * array of columns to be displayed (slugs & titles), a list of columns
271
+ * to keep hidden, and a list of columns that are sortable. Each of these
272
+ * can be defined in another method (as we've done here) before being
273
+ * used to build the value for our _column_headers property.
274
+ */
275
+ $columns = $this->get_columns();
276
+ $hidden = array();
277
+ $sortable = $this->get_sortable_columns();
278
+
279
+ /**
280
+ * REQUIRED. Finally, we build an array to be used by the class for column
281
+ * headers. The $this->_column_headers property takes an array which contains
282
+ * 3 other arrays. One for all columns, one for hidden columns, and one
283
+ * for sortable columns.
284
+ */
285
+ $this->_column_headers = array($columns, $hidden, $sortable);
286
+
287
+ /**
288
+ * Instead of querying a database, we're going to fetch the example data
289
+ * property we created for use in this plugin. This makes this example
290
+ * package slightly different than one you might build on your own. In
291
+ * this example, we'll be using array manipulation to sort and paginate
292
+ * our data. In a real-world implementation, you will probably want to
293
+ * use sort and pagination data to build a custom query instead, as you'll
294
+ * be able to use your precisely-queried data immediately.
295
+ */
296
+ $data = $this->read_data();
297
+
298
+ /**
299
+ * This checks for sorting input and sorts the data in our array accordingly.
300
+ *
301
+ * In a real-world situation involving a database, you would probably want
302
+ * to handle sorting by passing the 'orderby' and 'order' values directly
303
+ * to a custom query. The returned data will be pre-sorted, and this array
304
+ * sorting technique would be unnecessary.
305
+ */
306
+ function usort_reorder($a,$b){
307
+ $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'title'; //If no sort, default to title
308
+ $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc
309
+ $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
310
+ return ($order==='asc') ? $result : -$result; //Send final sort direction to usort
311
+ }
312
+ usort($data, 'usort_reorder');
313
+
314
+ /***********************************************************************
315
+ * ---------------------------------------------------------------------
316
+ * vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
317
+ *
318
+ * In a real-world situation, this is where you would place your query.
319
+ *
320
+ * For information on making queries in WordPress, see this Codex entry:
321
+ * http://codex.wordpress.org/Class_Reference/wpdb
322
+ *
323
+ * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
324
+ * ---------------------------------------------------------------------
325
+ **********************************************************************/
326
+
327
+ /**
328
+ * REQUIRED for pagination. Let's figure out what page the user is currently
329
+ * looking at. We'll need this later, so you should always include it in
330
+ * your own package classes.
331
+ */
332
+ $current_page = $this->get_pagenum();
333
+
334
+ /**
335
+ * REQUIRED for pagination. Let's check how many items are in our data array.
336
+ * In real-world use, this would be the total number of items in your database,
337
+ * without filtering. We'll need this later, so you should always include it
338
+ * in your own package classes.
339
+ */
340
+ $total_items = count($data);
341
+ $this->max_items = $total_items;
342
+
343
+ /**
344
+ * The WP_List_Table class does not handle pagination for us, so we need
345
+ * to ensure that the data is trimmed to only the current page. We can use
346
+ * array_slice() to
347
+ */
348
+ $data = array_slice($data,(($current_page-1)*$per_page),$per_page);
349
+
350
+ /**
351
+ * REQUIRED. Now we can add our *sorted* data to the items property, where
352
+ * it can be used by the rest of the class.
353
+ */
354
+ $this->items = $data;
355
+
356
+ /**
357
+ * REQUIRED. We also have to register our pagination options & calculations.
358
+ */
359
+ $this->set_pagination_args( array(
360
+ 'total_items' => $total_items, //WE have to calculate the total number of items
361
+ 'per_page' => $per_page, //WE have to determine how many items to show on a page
362
+ 'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages
363
+ ) );
364
+ }
365
+
366
+ }
367
+
368
+ ?>
req/MediaFromFtpRegist.php ADDED
@@ -0,0 +1,378 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media from FTP
4
+ *
5
+ * @package Media from FTP
6
+ * @subpackage MediaFromFtpRegist registered in the database
7
+ /* Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
8
+ This program is free software; you can redistribute it and/or modify
9
+ it under the terms of the GNU General Public License as published by
10
+ the Free Software Foundation; version 2 of the License.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program; if not, write to the Free Software
19
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ */
21
+
22
+ class MediaFromFtpRegist {
23
+
24
+ /* ==================================================
25
+ * Settings Log Settings
26
+ * @since 9.19
27
+ */
28
+ function log_settings(){
29
+
30
+ $mediafromftp_log_db_version = '3.0';
31
+ $installed_ver = get_option( 'mediafromftp_log_version' );
32
+
33
+ if( $installed_ver != $mediafromftp_log_db_version ) {
34
+ global $wpdb;
35
+ $log_name = $wpdb->prefix.'mediafromftp_log';
36
+ require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
37
+
38
+ $records = $wpdb->get_results("SELECT * FROM $log_name");
39
+ if ( $records ) { // db_version 1.0, 2.0
40
+ $wpdb->query("DELETE FROM $log_name");
41
+
42
+ $wpdb->query("ALTER TABLE $log_name DROP thumbnail1, DROP thumbnail2, DROP thumbnail3, DROP thumbnail4, DROP thumbnail5, DROP thumbnail6");
43
+ $wpdb->query("ALTER TABLE $log_name ADD thumbnail longtext");
44
+ $wpdb->query("ALTER TABLE $log_name ADD mlccategories longtext");
45
+ $wpdb->query("ALTER TABLE $log_name ADD emlcategories longtext");
46
+ $wpdb->query("ALTER TABLE $log_name ADD mlacategories longtext");
47
+ $wpdb->query("ALTER TABLE $log_name ADD mlatags longtext");
48
+
49
+ foreach ( $records as $record ) {
50
+ $thumbnail = NULL;
51
+ $thumbnails = array();
52
+ if ( !empty($record->thumbnail1) ) { $thumbnails[0] = $record->thumbnail1; }
53
+ if ( !empty($record->thumbnail2) ) { $thumbnails[1] = $record->thumbnail2; }
54
+ if ( !empty($record->thumbnail3) ) { $thumbnails[2] = $record->thumbnail3; }
55
+ if ( !empty($record->thumbnail4) ) { $thumbnails[3] = $record->thumbnail4; }
56
+ if ( !empty($record->thumbnail5) ) { $thumbnails[4] = $record->thumbnail5; }
57
+ if ( !empty($record->thumbnail6) ) { $thumbnails[5] = $record->thumbnail6; }
58
+ if ( !empty($thumbnails) ) {
59
+ $thumbnail = json_encode($thumbnails);
60
+ $thumbnail = str_replace('\\', '', $thumbnail);
61
+ } else {
62
+ $thumbnail = $record->thumbnail;
63
+ }
64
+
65
+ $log_arr = array(
66
+ 'id' => $record->id,
67
+ 'user' => $record->user,
68
+ 'title' => $record->title,
69
+ 'permalink' => $record->permalink,
70
+ 'url' => $record->url,
71
+ 'filename' => $record->filename,
72
+ 'time' => $record->time,
73
+ 'filetype' => $record->filetype,
74
+ 'filesize' => $record->filesize,
75
+ 'exif' => $record->exif,
76
+ 'length' => $record->length,
77
+ 'thumbnail' => $thumbnail,
78
+ 'mlccategories' => NULL,
79
+ 'emlcategories' => NULL,
80
+ 'mlacategories' => NULL,
81
+ 'mlatags' => NULL
82
+ );
83
+ $wpdb->insert( $log_name, $log_arr);
84
+ $wpdb->show_errors();
85
+ }
86
+ } else {
87
+ // from version 9.57
88
+ $sql = "CREATE TABLE " . $log_name . " (
89
+ meta_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
90
+ id bigint(20),
91
+ user text,
92
+ title text,
93
+ permalink text,
94
+ url text,
95
+ filename text,
96
+ time datetime,
97
+ filetype text,
98
+ filesize text,
99
+ exif text,
100
+ length text,
101
+ thumbnail longtext,
102
+ mlccategories longtext,
103
+ emlcategories longtext,
104
+ mlacategories longtext,
105
+ mlatags longtext,
106
+ UNIQUE KEY meta_id (meta_id)
107
+ )
108
+ CHARACTER SET 'utf8';";
109
+ dbDelta($sql);
110
+ }
111
+ update_option( 'mediafromftp_log_version', $mediafromftp_log_db_version );
112
+ }
113
+
114
+ }
115
+
116
+ /* ==================================================
117
+ * Settings register
118
+ * @since 2.3
119
+ */
120
+ function register_settings(){
121
+
122
+ $user = wp_get_current_user();
123
+ $cron_mail = $user->user_email;
124
+ $cron_user = $user->ID;
125
+
126
+ $wp_options_name = 'mediafromftp_settings'.'_'.$cron_user;
127
+ $wp_cron_events_name = 'mediafromftp_add_on_wpcron_events'.'_'.$cron_user;
128
+
129
+ $pagemax = 20;
130
+ $basedir = MEDIAFROMFTP_PLUGIN_UPLOAD_PATH;
131
+ $searchdir = MEDIAFROMFTP_PLUGIN_UPLOAD_PATH;
132
+ $ext2typefilter = 'all';
133
+ $extfilter = 'all';
134
+ $search_display_metadata = TRUE;
135
+ $dateset = 'new';
136
+ $datefixed = date_i18n("Y-m-d H:i");
137
+ $datetimepicker = 1;
138
+ $max_execution_time = 300;
139
+ if( strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && get_locale() === 'ja' ) { // Japanese Windows
140
+ $character_code = 'CP932';
141
+ } else {
142
+ $character_code = 'UTF-8';
143
+ }
144
+ $exclude = '(.ktai.)|(.backwpup_log.)|(.ps_auto_sitemap.)|\.php|\.js';
145
+ $thumb_deep_search = FALSE;
146
+ $search_limit_number = 100000;
147
+ $cron_apply = FALSE;
148
+ $cron_schedule = 'hourly';
149
+ $cron_limit_number = FALSE;
150
+ $cron_mail_apply = TRUE;
151
+
152
+ $caption_apply = FALSE;
153
+ $exif_text = '%title% %credit% %camera% %caption% %created_timestamp% %copyright% %aperture% %shutter_speed% %iso% %focal_length%';
154
+ $log = FALSE;
155
+
156
+ // for media-from-ftp-add-on-category
157
+ $mlcc = NULL;
158
+ $emlc = NULL;
159
+ $mlac = NULL;
160
+ $mlat = NULL;
161
+
162
+ // for media-from-ftp-add-on-wpcron
163
+ if ( !get_option( 'mediafromftp_event_intervals' ) ) {
164
+ update_option( 'mediafromftp_event_intervals', array() );
165
+ }
166
+ if ( !get_option( $wp_cron_events_name ) ) {
167
+ update_option( $wp_cron_events_name, array() );
168
+ }
169
+
170
+ // << version 2.35
171
+ if ( get_option('mediafromftp_exclude_file') ) {
172
+ $exclude = get_option('mediafromftp_exclude_file');
173
+ delete_option( 'mediafromftp_exclude_file' );
174
+ }
175
+
176
+ if ( !get_option($wp_options_name) ) {
177
+ if ( get_option('mediafromftp_settings') ) { // old settings
178
+ $mediafromftp_settings = get_option('mediafromftp_settings');
179
+ if ( array_key_exists( "pagemax", $mediafromftp_settings ) ) {
180
+ $pagemax = $mediafromftp_settings['pagemax'];
181
+ }
182
+ if ( array_key_exists( "basedir", $mediafromftp_settings ) ) {
183
+ $basedir = $mediafromftp_settings['basedir'];
184
+ }
185
+ if ( array_key_exists( "searchdir", $mediafromftp_settings ) ) {
186
+ $searchdir = $mediafromftp_settings['searchdir'];
187
+ }
188
+ if ( array_key_exists( "ext2typefilter", $mediafromftp_settings ) ) {
189
+ $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
190
+ }
191
+ if ( array_key_exists( "extfilter", $mediafromftp_settings ) ) {
192
+ $extfilter = $mediafromftp_settings['extfilter'];
193
+ }
194
+ if ( array_key_exists( "search_display_metadata", $mediafromftp_settings ) ) {
195
+ $search_display_metadata = $mediafromftp_settings['search_display_metadata'];
196
+ }
197
+ if ( array_key_exists( "dateset", $mediafromftp_settings ) ) {
198
+ $dateset = $mediafromftp_settings['dateset'];
199
+ }
200
+ if ( array_key_exists( "datefixed", $mediafromftp_settings ) ) {
201
+ $datefixed = $mediafromftp_settings['datefixed'];
202
+ }
203
+ if ( array_key_exists( "datetimepicker", $mediafromftp_settings ) ) {
204
+ $datetimepicker = $mediafromftp_settings['datetimepicker'];
205
+ }
206
+ if ( array_key_exists( "max_execution_time", $mediafromftp_settings ) ) {
207
+ $max_execution_time = $mediafromftp_settings['max_execution_time'];
208
+ }
209
+ if ( array_key_exists( "character_code", $mediafromftp_settings ) ) {
210
+ $character_code = $mediafromftp_settings['character_code'];
211
+ }
212
+ if ( array_key_exists( "exclude", $mediafromftp_settings ) ) {
213
+ $exclude = $mediafromftp_settings['exclude'];
214
+ }
215
+ if ( array_key_exists( "thumb_deep_search", $mediafromftp_settings ) ) {
216
+ $thumb_deep_search = $mediafromftp_settings['thumb_deep_search'];
217
+ }
218
+ if ( array_key_exists( "search_limit_number", $mediafromftp_settings ) ) {
219
+ $search_limit_number = $mediafromftp_settings['search_limit_number'];
220
+ }
221
+ if ( array_key_exists( "apply", $mediafromftp_settings["cron"] ) ) {
222
+ $cron_apply = $mediafromftp_settings['cron']['apply'];
223
+ }
224
+ if ( array_key_exists( "schedule", $mediafromftp_settings["cron"] ) ) {
225
+ $cron_schedule = $mediafromftp_settings['cron']['schedule'];
226
+ }
227
+ if ( array_key_exists( "limit_number", $mediafromftp_settings["cron"] ) ) {
228
+ $cron_limit_number = $mediafromftp_settings['cron']['limit_number'];
229
+ }
230
+ if ( array_key_exists( "mail_apply", $mediafromftp_settings["cron"] ) ) {
231
+ $cron_mail_apply = $mediafromftp_settings['cron']['mail_apply'];
232
+ }
233
+ if ( array_key_exists( "apply", $mediafromftp_settings["caption"] ) ) {
234
+ $caption_apply = $mediafromftp_settings['caption']['apply'];
235
+ }
236
+ if ( array_key_exists( "exif_text", $mediafromftp_settings["caption"] ) ) {
237
+ $exif_text = $mediafromftp_settings['caption']['exif_text'];
238
+ }
239
+ if ( array_key_exists( "log", $mediafromftp_settings ) ) {
240
+ $log = $mediafromftp_settings['log'];
241
+ }
242
+
243
+ // for media-from-ftp-add-on-category
244
+ if ( array_key_exists( "mlcc", $mediafromftp_settings ) ) {
245
+ $mlcc = $mediafromftp_settings['mlcc'];
246
+ }
247
+ if ( array_key_exists( "emlc", $mediafromftp_settings ) ) {
248
+ $emlc = $mediafromftp_settings['emlc'];
249
+ }
250
+ if ( array_key_exists( "mlac", $mediafromftp_settings ) ) {
251
+ $mlac = $mediafromftp_settings['mlac'];
252
+ }
253
+ if ( array_key_exists( "mlat", $mediafromftp_settings ) ) {
254
+ $mlat = $mediafromftp_settings['mlat'];
255
+ }
256
+
257
+ delete_option( 'mediafromftp_settings' );
258
+ }
259
+ } else {
260
+ $mediafromftp_settings = get_option($wp_options_name);
261
+ if ( array_key_exists( "pagemax", $mediafromftp_settings ) ) {
262
+ $pagemax = $mediafromftp_settings['pagemax'];
263
+ }
264
+ if ( array_key_exists( "basedir", $mediafromftp_settings ) ) {
265
+ $basedir = $mediafromftp_settings['basedir'];
266
+ }
267
+ if ( array_key_exists( "searchdir", $mediafromftp_settings ) ) {
268
+ $searchdir = $mediafromftp_settings['searchdir'];
269
+ }
270
+ if ( array_key_exists( "ext2typefilter", $mediafromftp_settings ) ) {
271
+ $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
272
+ }
273
+ if ( array_key_exists( "extfilter", $mediafromftp_settings ) ) {
274
+ $extfilter = $mediafromftp_settings['extfilter'];
275
+ }
276
+ if ( array_key_exists( "search_display_metadata", $mediafromftp_settings ) ) {
277
+ $search_display_metadata = $mediafromftp_settings['search_display_metadata'];
278
+ }
279
+ if ( array_key_exists( "dateset", $mediafromftp_settings ) ) {
280
+ $dateset = $mediafromftp_settings['dateset'];
281
+ }
282
+ if ( array_key_exists( "datefixed", $mediafromftp_settings ) ) {
283
+ $datefixed = $mediafromftp_settings['datefixed'];
284
+ }
285
+ if ( array_key_exists( "datetimepicker", $mediafromftp_settings ) ) {
286
+ $datetimepicker = $mediafromftp_settings['datetimepicker'];
287
+ }
288
+ if ( array_key_exists( "max_execution_time", $mediafromftp_settings ) ) {
289
+ $max_execution_time = $mediafromftp_settings['max_execution_time'];
290
+ }
291
+ if ( array_key_exists( "character_code", $mediafromftp_settings ) ) {
292
+ $character_code = $mediafromftp_settings['character_code'];
293
+ }
294
+ if ( array_key_exists( "exclude", $mediafromftp_settings ) ) {
295
+ $exclude = $mediafromftp_settings['exclude'];
296
+ }
297
+ if ( array_key_exists( "thumb_deep_search", $mediafromftp_settings ) ) {
298
+ $thumb_deep_search = $mediafromftp_settings['thumb_deep_search'];
299
+ }
300
+ if ( array_key_exists( "search_limit_number", $mediafromftp_settings ) ) {
301
+ $search_limit_number = $mediafromftp_settings['search_limit_number'];
302
+ }
303
+ if ( array_key_exists( "apply", $mediafromftp_settings["cron"] ) ) {
304
+ $cron_apply = $mediafromftp_settings['cron']['apply'];
305
+ }
306
+ if ( array_key_exists( "schedule", $mediafromftp_settings["cron"] ) ) {
307
+ $cron_schedule = $mediafromftp_settings['cron']['schedule'];
308
+ }
309
+ if ( array_key_exists( "limit_number", $mediafromftp_settings["cron"] ) ) {
310
+ $cron_limit_number = $mediafromftp_settings['cron']['limit_number'];
311
+ }
312
+ if ( array_key_exists( "mail_apply", $mediafromftp_settings["cron"] ) ) {
313
+ $cron_mail_apply = $mediafromftp_settings['cron']['mail_apply'];
314
+ }
315
+ if ( array_key_exists( "apply", $mediafromftp_settings["caption"] ) ) {
316
+ $caption_apply = $mediafromftp_settings['caption']['apply'];
317
+ }
318
+ if ( array_key_exists( "exif_text", $mediafromftp_settings["caption"] ) ) {
319
+ $exif_text = $mediafromftp_settings['caption']['exif_text'];
320
+ }
321
+ if ( array_key_exists( "log", $mediafromftp_settings ) ) {
322
+ $log = $mediafromftp_settings['log'];
323
+ }
324
+ // for media-from-ftp-add-on-category
325
+ if ( array_key_exists( "mlcc", $mediafromftp_settings ) ) {
326
+ $mlcc = $mediafromftp_settings['mlcc'];
327
+ }
328
+ if ( array_key_exists( "emlc", $mediafromftp_settings ) ) {
329
+ $emlc = $mediafromftp_settings['emlc'];
330
+ }
331
+ if ( array_key_exists( "mlac", $mediafromftp_settings ) ) {
332
+ $mlac = $mediafromftp_settings['mlac'];
333
+ }
334
+ if ( array_key_exists( "mlat", $mediafromftp_settings ) ) {
335
+ $mlat = $mediafromftp_settings['mlat'];
336
+ }
337
+ }
338
+
339
+ $mediafromftp_tbl = array(
340
+ 'pagemax' => $pagemax,
341
+ 'basedir' => $basedir,
342
+ 'searchdir' => $searchdir,
343
+ 'ext2typefilter' => $ext2typefilter,
344
+ 'extfilter' => $extfilter,
345
+ 'search_display_metadata' => $search_display_metadata,
346
+ 'dateset' => $dateset,
347
+ 'datefixed' => $datefixed,
348
+ 'datetimepicker' => $datetimepicker,
349
+ 'max_execution_time' => $max_execution_time,
350
+ 'character_code' => $character_code,
351
+ 'exclude' => $exclude,
352
+ 'thumb_deep_search' => $thumb_deep_search,
353
+ 'search_limit_number' => $search_limit_number,
354
+ 'cron' => array(
355
+ 'apply' => $cron_apply,
356
+ 'schedule' => $cron_schedule,
357
+ 'limit_number' => $cron_limit_number,
358
+ 'mail_apply' => $cron_mail_apply,
359
+ 'mail' => $cron_mail,
360
+ 'user' => $cron_user
361
+ ),
362
+ 'caption' => array(
363
+ 'apply' => $caption_apply,
364
+ 'exif_text' => $exif_text
365
+ ),
366
+ 'log' => $log,
367
+ 'mlcc' => $mlcc,
368
+ 'emlc' => $emlc,
369
+ 'mlac' => $mlac,
370
+ 'mlat' => $mlat
371
+ );
372
+ update_option( $wp_options_name, $mediafromftp_tbl );
373
+
374
+ }
375
+
376
+ }
377
+
378
+ ?>
uninstall.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ //if uninstall not called from WordPress exit
4
+ if ( !defined( 'WP_UNINSTALL_PLUGIN' ) )
5
+ exit();
6
+
7
+ global $wpdb;
8
+
9
+ // For Single site
10
+ if ( !is_multisite() )
11
+ {
12
+ foreach ( media_from_ftp_uninstall_option_names() as $option_name ) {
13
+ delete_option( $option_name );
14
+ // Delete log database
15
+ $log_name = $wpdb->prefix.'mediafromftp_log';
16
+ $wpdb->query("DROP TABLE IF EXISTS $log_name");
17
+ }
18
+
19
+ }
20
+ // For Multisite
21
+ else
22
+ {
23
+ // For regular options.
24
+ $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
25
+ $original_blog_id = get_current_blog_id();
26
+ foreach ( $blog_ids as $blog_id )
27
+ {
28
+ switch_to_blog( $blog_id );
29
+ foreach ( media_from_ftp_uninstall_option_names() as $option_name ) {
30
+ delete_option( $option_name );
31
+ // Delete log database
32
+ $log_name = $wpdb->prefix.'mediafromftp_log';
33
+ $wpdb->query("DROP TABLE IF EXISTS $log_name");
34
+ }
35
+ }
36
+ switch_to_blog( $original_blog_id );
37
+
38
+ // For site options.
39
+ foreach ( media_from_ftp_uninstall_option_names() as $option_name ) {
40
+ delete_site_option( $option_name );
41
+ }
42
+ }
43
+
44
+ // Delete all cache
45
+ $wp_uploads = wp_upload_dir();
46
+ $tmp_dir = $wp_uploads['basedir'].'/media-from-ftp-tmp';
47
+ if(is_ssl()){
48
+ $tmp_url = str_replace('http:', 'https:', $wp_uploads['baseurl']).'/media-from-ftp-tmp';
49
+ } else {
50
+ $tmp_url = $wp_uploads['baseurl'].'/media-from-ftp-tmp';
51
+ }
52
+ $del_transients = $wpdb->get_results("
53
+ SELECT option_value
54
+ FROM $wpdb->options
55
+ WHERE option_value LIKE '%%$tmp_url%%'
56
+ ");
57
+
58
+ foreach ( $del_transients as $del_transient ) {
59
+ $delfile = pathinfo($del_transient->option_value);
60
+ $del_cash_thumb_key = $delfile['filename'];
61
+ $value_del_cash = get_transient( $del_cash_thumb_key );
62
+ if ( $value_del_cash <> FALSE ) {
63
+ delete_transient( $del_cash_thumb_key );
64
+ }
65
+ }
66
+ $del_cash_thumb_filename = $tmp_dir.'/*.*';
67
+ foreach ( glob($del_cash_thumb_filename) as $val ) {
68
+ unlink($val);
69
+ }
70
+ if ( is_dir( $tmp_dir ) ) {
71
+ rmdir( $tmp_dir );
72
+ }
73
+
74
+ function media_from_ftp_uninstall_option_names() {
75
+
76
+ global $wpdb;
77
+ $option_names = array();
78
+ $wp_options = $wpdb->get_results("
79
+ SELECT option_name
80
+ FROM $wpdb->options
81
+ WHERE option_name LIKE '%%mediafromftp_%%'
82
+ ");
83
+ foreach ( $wp_options as $wp_option ) {
84
+ $option_names[] = $wp_option->option_name;
85
+ }
86
+
87
+ return $option_names;
88
+
89
+ }
90
+
91
+ ?>