Media from FTP - Version 11.00

Version Description

Conformed to the WordPress coding standard. The code at the time of registration was reviewed and the speed has improved.

Download this release

Release Info

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

Code changes from version 10.10 to 11.00

Files changed (83) hide show
  1. inc/MediaFromFtp.php +0 -1607
  2. inc/class-mediafromftp.php +1701 -0
  3. js/jquery.mediafromftp.datetimepicker.js +27 -23
  4. js/jquery.mediafromftp.js +431 -340
  5. mediafromftp.php +54 -38
  6. plugin-update-checker/.editorconfig +0 -15
  7. plugin-update-checker/Puc/v4/Factory.php +0 -6
  8. plugin-update-checker/Puc/v4p4/Autoloader.php +0 -49
  9. plugin-update-checker/Puc/v4p4/DebugBar/Extension.php +0 -177
  10. plugin-update-checker/Puc/v4p4/DebugBar/Panel.php +0 -165
  11. plugin-update-checker/Puc/v4p4/DebugBar/PluginExtension.php +0 -33
  12. plugin-update-checker/Puc/v4p4/DebugBar/PluginPanel.php +0 -38
  13. plugin-update-checker/Puc/v4p4/DebugBar/ThemePanel.php +0 -21
  14. plugin-update-checker/Puc/v4p4/Factory.php +0 -292
  15. plugin-update-checker/Puc/v4p4/Metadata.php +0 -132
  16. plugin-update-checker/Puc/v4p4/OAuthSignature.php +0 -88
  17. plugin-update-checker/Puc/v4p4/Plugin/Info.php +0 -130
  18. plugin-update-checker/Puc/v4p4/Plugin/Update.php +0 -110
  19. plugin-update-checker/Puc/v4p4/Plugin/UpdateChecker.php +0 -740
  20. plugin-update-checker/Puc/v4p4/Scheduler.php +0 -177
  21. plugin-update-checker/Puc/v4p4/StateStore.php +0 -207
  22. plugin-update-checker/Puc/v4p4/Theme/Update.php +0 -84
  23. plugin-update-checker/Puc/v4p4/Theme/UpdateChecker.php +0 -177
  24. plugin-update-checker/Puc/v4p4/Update.php +0 -34
  25. plugin-update-checker/Puc/v4p4/UpdateChecker.php +0 -906
  26. plugin-update-checker/Puc/v4p4/UpgraderStatus.php +0 -199
  27. plugin-update-checker/Puc/v4p4/Utils.php +0 -69
  28. plugin-update-checker/Puc/v4p4/Vcs/Api.php +0 -302
  29. plugin-update-checker/Puc/v4p4/Vcs/BaseChecker.php +0 -27
  30. plugin-update-checker/Puc/v4p4/Vcs/BitBucketApi.php +0 -256
  31. plugin-update-checker/Puc/v4p4/Vcs/GitHubApi.php +0 -413
  32. plugin-update-checker/Puc/v4p4/Vcs/GitLabApi.php +0 -278
  33. plugin-update-checker/Puc/v4p4/Vcs/PluginUpdateChecker.php +0 -217
  34. plugin-update-checker/Puc/v4p4/Vcs/Reference.php +0 -49
  35. plugin-update-checker/Puc/v4p4/Vcs/ThemeUpdateChecker.php +0 -118
  36. plugin-update-checker/README.md +0 -274
  37. plugin-update-checker/composer.json +0 -22
  38. plugin-update-checker/css/puc-debug-bar.css +0 -70
  39. plugin-update-checker/examples/plugin.json +0 -52
  40. plugin-update-checker/examples/theme.json +0 -5
  41. plugin-update-checker/js/debug-bar.js +0 -52
  42. plugin-update-checker/languages/plugin-update-checker-cs_CZ.mo +0 -0
  43. plugin-update-checker/languages/plugin-update-checker-cs_CZ.po +0 -45
  44. plugin-update-checker/languages/plugin-update-checker-da_DK.mo +0 -0
  45. plugin-update-checker/languages/plugin-update-checker-da_DK.po +0 -42
  46. plugin-update-checker/languages/plugin-update-checker-de_DE.mo +0 -0
  47. plugin-update-checker/languages/plugin-update-checker-de_DE.po +0 -38
  48. plugin-update-checker/languages/plugin-update-checker-fa_IR.mo +0 -0
  49. plugin-update-checker/languages/plugin-update-checker-fa_IR.po +0 -38
  50. plugin-update-checker/languages/plugin-update-checker-fr_CA.mo +0 -0
  51. plugin-update-checker/languages/plugin-update-checker-fr_CA.po +0 -48
  52. plugin-update-checker/languages/plugin-update-checker-fr_FR.mo +0 -0
  53. plugin-update-checker/languages/plugin-update-checker-fr_FR.po +0 -42
  54. plugin-update-checker/languages/plugin-update-checker-hu_HU.mo +0 -0
  55. plugin-update-checker/languages/plugin-update-checker-hu_HU.po +0 -41
  56. plugin-update-checker/languages/plugin-update-checker-it_IT.mo +0 -0
  57. plugin-update-checker/languages/plugin-update-checker-it_IT.po +0 -38
  58. plugin-update-checker/languages/plugin-update-checker-ja.mo +0 -0
  59. plugin-update-checker/languages/plugin-update-checker-ja.po +0 -42
  60. plugin-update-checker/languages/plugin-update-checker-nl_BE.mo +0 -0
  61. plugin-update-checker/languages/plugin-update-checker-nl_BE.po +0 -48
  62. plugin-update-checker/languages/plugin-update-checker-nl_NL.mo +0 -0
  63. plugin-update-checker/languages/plugin-update-checker-nl_NL.po +0 -48
  64. plugin-update-checker/languages/plugin-update-checker-pt_BR.mo +0 -0
  65. plugin-update-checker/languages/plugin-update-checker-pt_BR.po +0 -48
  66. plugin-update-checker/languages/plugin-update-checker-sv_SE.mo +0 -0
  67. plugin-update-checker/languages/plugin-update-checker-sv_SE.po +0 -42
  68. plugin-update-checker/languages/plugin-update-checker.pot +0 -49
  69. plugin-update-checker/license.txt +0 -7
  70. plugin-update-checker/plugin-update-checker.php +0 -24
  71. plugin-update-checker/vendor/Parsedown.php +0 -1538
  72. plugin-update-checker/vendor/ParsedownLegacy.php +0 -1535
  73. plugin-update-checker/vendor/readme-parser.php +0 -337
  74. readme.txt +170 -166
  75. req/MediaFromFtpAdmin.php +0 -1890
  76. req/MediaFromFtpAjax.php +0 -301
  77. req/MediaFromFtpListTable.php +0 -367
  78. req/MediaFromFtpRegist.php +0 -438
  79. req/class-mediafromftpadmin.php +2279 -0
  80. req/class-mediafromftpajax.php +443 -0
  81. req/class-mediafromftpregist.php +456 -0
  82. req/class-tt-mediafromftp-list-table.php +447 -0
  83. uninstall.php +55 -46
inc/MediaFromFtp.php DELETED
@@ -1,1607 +0,0 @@
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 $plugin_dir;
25
- private $upload_dir;
26
- private $upload_url;
27
- private $upload_path;
28
- private $plugin_tmp_url;
29
- private $plugin_tmp_dir;
30
- private $is_add_on_activate;
31
-
32
- /* ==================================================
33
- * Construct
34
- * @since 9.81
35
- */
36
- public function __construct() {
37
-
38
- $plugin_base_dir = untrailingslashit(plugin_dir_path( __DIR__ ));
39
- $slugs = explode('/', $plugin_base_dir);
40
- $slug = end($slugs);
41
- $this->plugin_dir = untrailingslashit(rtrim($plugin_base_dir, $slug));
42
-
43
- list($this->upload_dir, $this->upload_url, $this->upload_path) = $this->upload_dir_url_path();
44
- $this->plugin_tmp_url = $this->upload_url.'/media-from-ftp-tmp';
45
- $this->plugin_tmp_dir = $this->upload_dir.'/media-from-ftp-tmp';
46
-
47
- $exif_active = FALSE;
48
- if( function_exists('media_from_ftp_add_on_exif_load_textdomain') ){
49
- $exif_active = TRUE;
50
- }
51
-
52
- $cli_active = FALSE;
53
- if( function_exists('media_from_ftp_add_on_cli_load_textdomain') ){
54
- $cli_active = TRUE;
55
- }
56
-
57
- $this->is_add_on_activate = array(
58
- 'exif' => $exif_active,
59
- 'cli' => $cli_active
60
- );
61
-
62
- }
63
-
64
- /* ==================================================
65
- * @param string $dir
66
- * @param string $extpattern
67
- * @param array $mediafromftp_settings
68
- * @return array $list
69
- * @since 1.0
70
- */
71
- public function scan_file($dir, $extpattern, $mediafromftp_settings) {
72
-
73
- // for media-from-ftp-add-on-wpcron and mediafromftpcmd.php
74
- $cmdoptions = array();
75
- if ( $this->is_add_on_activate['cli'] ) {
76
- $cmdoptions = getopt("s:d:a:e:t:x:p:f:c:i:b:r:y:hgmo");
77
- }
78
-
79
- if ( isset($cmdoptions['f']) ) {
80
- $search_limit_number = $cmdoptions['f'];
81
- } else {
82
- $search_limit_number = $mediafromftp_settings['search_limit_number'];
83
- }
84
-
85
- $thumb_deep_search = FALSE;
86
- if ( isset($cmdoptions['m']) ) {
87
- $thumb_deep_search = TRUE;
88
- } else {
89
- $thumb_deep_search = $mediafromftp_settings['thumb_deep_search'];
90
- }
91
- if ( $thumb_deep_search ) {
92
- $excludefile = 'media-from-ftp-tmp'; // tmp dir file
93
- } else {
94
- $excludefile = '-[0-9]+x[0-9]+\.|media-from-ftp-tmp'; // thumbnail & tmp dir file
95
- }
96
-
97
- $recursive_search = TRUE;
98
- if ( isset($cmdoptions['o']) ) {
99
- $recursive_search = FALSE;
100
- } else {
101
- $recursive_search = $mediafromftp_settings['recursive_search'];
102
- }
103
-
104
- global $blog_id;
105
- if ( is_multisite() && is_main_site($blog_id) ) {
106
- $excludefile .= '|\/sites\/';
107
- }
108
- if ( isset($cmdoptions['e']) ) {
109
- $excludefile .= '|'.$cmdoptions['e'];
110
- } else {
111
- if( !empty($mediafromftp_settings['exclude']) ){
112
- $excludefile .= '|'.$mediafromftp_settings['exclude'];
113
- }
114
- }
115
-
116
- $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
117
- if ( isset($cmdoptions['t']) ) {
118
- $ext2typefilter = $cmdoptions['t'];
119
- } else {
120
- if (!empty($_POST['ext2type'])){
121
- $ext2typefilter = sanitize_text_field($_POST['ext2type']);
122
- }
123
- }
124
-
125
- unset($cmdoptions);
126
-
127
- $searchtext = '.*';
128
- if (!empty($_POST['searchtext'])){
129
- $searchtext = $this->mb_encode_multibyte(sanitize_text_field($_POST['searchtext']), $mediafromftp_settings['character_code']);
130
- }else if (!empty($_GET['searchtext'])){
131
- $searchtext = $this->mb_encode_multibyte(sanitize_text_field($_GET['searchtext']), $mediafromftp_settings['character_code']);
132
- }
133
-
134
- $files = scandir($dir);
135
- $list = array();
136
- $count = 0;
137
- foreach ($files as $file) {
138
- if($file == '.' || $file == '..'){
139
- continue;
140
- }
141
- $fullpath = rtrim($dir, '/') . '/' . $file;
142
- if (is_file($fullpath)) {
143
- if (!preg_match("/".$excludefile."/", $fullpath)) {
144
- $exts = explode('.', $file);
145
- $ext = end($exts);
146
- $searchflag = @preg_match("/".$searchtext."/", $fullpath);
147
- if (!$searchflag) {
148
- // for "preg_match error: Compilation failed: missing terminating ] for character class"
149
- $searchflag = preg_match("/".preg_quote($searchtext,'/')."/", $fullpath);
150
- }
151
- if ($searchflag) {
152
- if (preg_match("/".$extpattern."/", $ext)) {
153
- if ( $ext2typefilter === wp_ext2type($ext) || $ext2typefilter === 'all' ) {
154
- ++$count;
155
- if ( $count > $search_limit_number ) {
156
- break;
157
- }
158
- $list[] = $fullpath;
159
- }
160
- }
161
- }
162
- }
163
- }
164
- if (is_dir($fullpath) && $recursive_search) {
165
- $list = array_merge($list, $this->scan_file($fullpath, $extpattern, $mediafromftp_settings));
166
- }
167
- }
168
-
169
- return $list;
170
-
171
- }
172
-
173
- /* ==================================================
174
- * @param string $dir
175
- * @return array $dirlist
176
- * @since 2.1
177
- */
178
- private function scan_dir($dir) {
179
-
180
- $excludedir = 'media-from-ftp-tmp'; // tmp dir
181
- global $blog_id;
182
- if ( is_multisite() && is_main_site($blog_id) ) {
183
- $excludedir .= '|\/sites\/';
184
- }
185
-
186
- $files = scandir($dir);
187
- $list = array();
188
- foreach ($files as $file) {
189
- if($file == '.' || $file == '..'){
190
- continue;
191
- }
192
- $fullpath = rtrim($dir, '/') . '/' . $file;
193
- if (is_dir($fullpath)) {
194
- if (!preg_match("/".$excludedir."/", $fullpath)) {
195
- $list[] = $fullpath;
196
- }
197
- $list = array_merge($list, $this->scan_dir($fullpath));
198
- }
199
- }
200
-
201
- arsort($list);
202
- return $list;
203
-
204
- }
205
-
206
- /* ==================================================
207
- * @param string $extfilter
208
- * @return string $extpattern
209
- * @since 2.2
210
- */
211
- public function extpattern($extfilter){
212
-
213
- $extpattern = NULL;
214
-
215
- if ( $extfilter === 'all' ) {
216
- global $user_ID;
217
- $mimes = get_allowed_mime_types($user_ID);
218
- foreach ($mimes as $ext => $mime) {
219
- $extpattern .= $ext.'|'.strtoupper($ext).'|';
220
- }
221
- $extpattern = substr($extpattern, 0, -1);
222
- } else {
223
- $extpattern = $extfilter.'|'.strtoupper($extfilter);
224
- }
225
-
226
- return $extpattern;
227
-
228
- }
229
-
230
- /* ==================================================
231
- * @param string $suffix
232
- * @return string $mimetype
233
- * @since 1.0
234
- */
235
- private function mime_type($suffix){
236
-
237
- $suffix = str_replace('.', '', $suffix);
238
-
239
- global $user_ID;
240
- $mimes = get_allowed_mime_types($user_ID);
241
-
242
- foreach ($mimes as $ext => $mime) {
243
- if ( preg_match("/".$ext."/i", $suffix) ) {
244
- $mimetype = $mime;
245
- }
246
- }
247
-
248
- return $mimetype;
249
-
250
- }
251
-
252
- /* ==================================================
253
- * @param string $ext
254
- * @param string $file
255
- * @param string $new_url
256
- * @return string $view_thumb_url
257
- * @since 2.36
258
- */
259
- private function create_cash($ext, $file, $new_url){
260
-
261
- $cash_thumb_key = md5($new_url);
262
-
263
- $ext = strtolower($ext);
264
-
265
- if ( $ext === 'pdf' ) {
266
- $cash_thumb_filename = $this->plugin_tmp_dir.'/'.$cash_thumb_key.'-pdf.jpg';
267
- } else {
268
- $cash_thumb_filename = $this->plugin_tmp_dir.'/'.$cash_thumb_key.'.'.$ext;
269
- }
270
-
271
- $value_cash = get_transient( $cash_thumb_key );
272
- if ( $value_cash <> FALSE ) {
273
- if ( ! file_exists( $cash_thumb_filename )) {
274
- delete_transient( $cash_thumb_key );
275
- $value_cash = FALSE;
276
- }
277
- }
278
- if ( ! $value_cash ) {
279
- $filetype2 = wp_ext2type($ext);
280
- if ( empty($filetype2) ) $filetype2 = 'default';
281
- if ( ! file_exists( $cash_thumb_filename )) {
282
- $cash_thumb = wp_get_image_editor( $file );
283
- if ( ! is_wp_error( $cash_thumb ) ) {
284
- if ( $ext === 'pdf' ) {
285
- $cash_thumb->generate_filename( 'image', null, 'jpg' );
286
- $cash_thumb->save( $cash_thumb_filename );
287
- $cash_thumb2 = wp_get_image_editor( $cash_thumb_filename );
288
- if ( ! is_wp_error( $cash_thumb2 ) ) {
289
- $cash_thumb2->resize( 40 ,40, true );
290
- $cash_thumb2->save( $cash_thumb_filename );
291
- $view_thumb_url = $this->plugin_tmp_url.'/'.$cash_thumb_key.'-pdf.jpg';
292
- } else {
293
- $view_thumb_url = $this->siteurl().'/'.WPINC . '/images/media/'.$filetype2.'.png';
294
- }
295
- } else {
296
- $cash_thumb->resize( 40 ,40, true );
297
- $cash_thumb->save( $cash_thumb_filename );
298
- $view_thumb_url = $this->plugin_tmp_url.'/'.$cash_thumb_key.'.'.$ext;
299
- }
300
- } else {
301
- $view_thumb_url = $this->siteurl().'/'.WPINC . '/images/media/'.$filetype2.'.png';
302
- }
303
- } else {
304
- if ( file_exists( $cash_thumb_filename )) {
305
- $view_thumb_url = $this->plugin_tmp_url.'/'.$cash_thumb_key.'.'.$ext;
306
- } else {
307
- $view_thumb_url = $this->siteurl().'/'.WPINC . '/images/media/'.$filetype2.'.png';
308
- }
309
- }
310
- set_transient( $cash_thumb_key, $view_thumb_url, DAY_IN_SECONDS);
311
- } else {
312
- $view_thumb_url = $value_cash;
313
- set_transient( $cash_thumb_key, $value_cash, DAY_IN_SECONDS);
314
- }
315
-
316
- return $view_thumb_url;
317
-
318
- }
319
-
320
- /* ==================================================
321
- * @param string $ext
322
- * @param string $new_url_attach
323
- * @return none
324
- * @since 2.36
325
- */
326
- public function delete_cash($ext, $new_url_attach){
327
-
328
- $ext = strtolower($ext);
329
-
330
- if ( wp_ext2type($ext) === 'image' || $ext === 'pdf' ){
331
- $del_cash_thumb_key = md5($new_url_attach);
332
- if ( strtolower($ext) === 'pdf' ) {
333
- $del_cash_thumb_filename = $this->plugin_tmp_dir.'/'.$del_cash_thumb_key.'-pdf.jpg';
334
- } else {
335
- $del_cash_thumb_filename = $this->plugin_tmp_dir.'/'.$del_cash_thumb_key.'.'.$ext;
336
- }
337
- $value_del_cash = get_transient( $del_cash_thumb_key );
338
- if ( $value_del_cash <> FALSE ) {
339
- delete_transient( $del_cash_thumb_key );
340
- if ( file_exists( $del_cash_thumb_filename )) {
341
- unlink( $del_cash_thumb_filename );
342
- }
343
- }
344
- }
345
-
346
- }
347
-
348
- /* ==================================================
349
- * @param none
350
- * @return int $del_cash_count(int)
351
- * @since 7.5
352
- */
353
- public function delete_all_cash(){
354
-
355
- global $wpdb;
356
- $search_transients = $this->plugin_tmp_url;
357
- $del_transients = $wpdb->get_results("
358
- SELECT option_value
359
- FROM $wpdb->options
360
- WHERE option_value LIKE '%%$search_transients%%'
361
- ");
362
-
363
- $del_cash_count = 0;
364
- foreach ( $del_transients as $del_transient ) {
365
- $delfile = pathinfo($del_transient->option_value);
366
- $del_cash_thumb_key = $delfile['filename'];
367
- $value_del_cash = get_transient( $del_cash_thumb_key );
368
- if ( $value_del_cash <> FALSE ) {
369
- delete_transient( $del_cash_thumb_key );
370
- ++$del_cash_count;
371
- }
372
- }
373
-
374
- $del_cash_thumb_filename = $this->plugin_tmp_dir.'/*.*';
375
- foreach ( glob($del_cash_thumb_filename) as $val ) {
376
- unlink($val);
377
- ++$del_cash_count;
378
- }
379
-
380
- return $del_cash_count;
381
-
382
- }
383
-
384
- /* ==================================================
385
- * @param string $file
386
- * @param string $dateset
387
- * @return string $date
388
- * @since 2.36
389
- */
390
- public function get_date_check($file, $dateset){
391
-
392
- $date = get_date_from_gmt(date("Y-m-d H:i:s", filemtime($file)));
393
-
394
- if ( $dateset === 'exif' ) {
395
- $exifdata = @exif_read_data( $file, FILE, TRUE );
396
- if ( isset($exifdata["EXIF"]['DateTimeOriginal']) && !empty($exifdata["EXIF"]['DateTimeOriginal']) ) {
397
- $shooting_date_time = $exifdata["EXIF"]['DateTimeOriginal'];
398
- $shooting_date = str_replace( ':', '-', substr( $shooting_date_time , 0 , 10 ) );
399
- $shooting_time = substr( $shooting_date_time , 10);
400
- $date = $shooting_date.$shooting_time;
401
- }
402
- }
403
-
404
- $date = substr( $date , 0 , strlen($date)-3 );
405
-
406
- return $date;
407
-
408
- }
409
-
410
- /* ==================================================
411
- * @param string $file
412
- * @param array $attachments
413
- * @param string $character_code
414
- * @param bool $thumb_deep_search
415
- * @return array $new_file(bool), $ext(string), $new_url(string)
416
- * @since 2.36
417
- */
418
- public function input_url($file, $attachments, $character_code, $thumb_deep_search){
419
-
420
- $ext = NULL;
421
- $new_url = NULL;
422
-
423
- if ( is_dir($file) ) { // dirctory
424
- $new_file = FALSE;
425
- } else {
426
- $exts = explode('.', wp_basename($file));
427
- $ext = end($exts);
428
- $suffix_file = '.'.$ext;
429
- $file = wp_normalize_path($file);
430
- $upload_path = wp_normalize_path($this->upload_dir);
431
- $new_url = $this->upload_url.str_replace($upload_path, '', $file);
432
- $new_titles = explode('/', $new_url);
433
- $new_title = str_replace($suffix_file, '', end($new_titles));
434
- $new_title_md5 = md5($new_title);
435
- $new_url_md5 = str_replace($new_title.$suffix_file, '', $new_url).$new_title_md5.$suffix_file;
436
- $new_file = TRUE;
437
- $new_url = $this->mb_utf8($new_url, $character_code);
438
- foreach ( $attachments as $attachment ){
439
- $attach_url = $this->upload_url.'/'.get_post_meta( $attachment->ID, '_wp_attached_file', true );
440
- $pdf_thumb_url = rtrim($attach_url, '.pdf').'-pdf.jpg'; // for pdf thumbnail by imagick
441
- if ( $attach_url === $new_url || $attach_url === $new_url_md5 || $pdf_thumb_url === $new_url || $pdf_thumb_url === $new_url_md5 ) {
442
- $new_file = FALSE;
443
- } else {
444
- if ($thumb_deep_search) {
445
- $exts_attach_url = explode('.', wp_basename($attach_url));
446
- $delete_ext = '.'.end($exts_attach_url);
447
- $attach_url_base = rtrim($attach_url, $delete_ext);
448
- if ( strstr($new_url, $attach_url_base) || strstr($new_url_md5, $attach_url_base) ) {
449
- $thumb_pattern = '-[0-9]+x[0-9]+\.';
450
- if ( preg_match("/".$thumb_pattern."/", $new_url) || preg_match("/".$thumb_pattern."/", $new_url_md5) ) {
451
- $new_file = FALSE;
452
- }
453
- }
454
- }
455
- }
456
- }
457
- }
458
-
459
- return array($new_file, $ext, $new_url);
460
-
461
- }
462
-
463
- /* ==================================================
464
- * @param string $ext
465
- * @param string $file
466
- * @param string $new_url
467
- * @param string $postcount
468
- * @param array $mediafromftp_settings
469
- * @return array $input_html(string), $date_time_html(string)
470
- * @since 9.30
471
- */
472
- public function input_html($ext, $file, $new_url, $postcount, $mediafromftp_settings){
473
-
474
- $input_html = NULL;
475
-
476
- if ($mediafromftp_settings['search_display_metadata']){
477
- $file_size = size_format(filesize($file));
478
- $mimetype = $ext.'('.$this->mime_type($ext).')';
479
- if ( wp_ext2type($ext) === 'image' || strtolower($ext) === 'pdf' ){
480
- $view_thumb_url = $this->create_cash($ext, $file, $new_url);
481
- } else if ( wp_ext2type($ext) === 'audio' ) {
482
- $view_thumb_url = $this->siteurl().'/'.WPINC . '/images/media/audio.png';
483
- $metadata_audio = wp_read_audio_metadata( $file );
484
- $file_size = size_format($metadata_audio['filesize']);
485
- $mimetype = $metadata_audio['fileformat'].'('.$metadata_audio['mime_type'].')';
486
- $length = $metadata_audio['length_formatted'];
487
- } else if ( wp_ext2type($ext) === 'video' ) {
488
- $view_thumb_url = $this->siteurl().'/'.WPINC . '/images/media/video.png';
489
- $metadata_video = wp_read_video_metadata( $file );
490
- $file_size = size_format($metadata_video['filesize']);
491
- $mimetype = $metadata_video['fileformat'].'('.$metadata_video['mime_type'].')';
492
- $length = $metadata_video['length_formatted'];
493
- } else {
494
- $filetype2 = wp_ext2type($ext);
495
- if ( empty($filetype2) ) { $filetype2 = 'default'; }
496
- $view_thumb_url = $this->siteurl().'/'.WPINC . '/images/media/'.$filetype2.'.png';
497
- }
498
- $input_html .= '<img width="40" height="40" src="'.$view_thumb_url.'" style="float: left; margin: 5px;">';
499
- }
500
-
501
- $input_html .= '<div style="overflow: hidden;">';
502
- $input_html .= '<div><a href="'.$new_url.'" target="_blank" style="text-decoration: none; word-break: break-all;">'.$new_url.'</a></div>';
503
-
504
- if ($mediafromftp_settings['search_display_metadata']){
505
- $input_html .= '<div>'.__('File type:').' '.$mimetype.'</div>';
506
- $input_html .= '<div>'.__('File size:').' '.$file_size.'</div>';
507
- if ( wp_ext2type($ext) === 'audio' || wp_ext2type($ext) === 'video' ) {
508
- $input_html .= '<div>'.__('Length:').' '.$length.'</div>';
509
- }
510
- }
511
- $input_html .= '</div>';
512
-
513
- $date_time_html = NULL;
514
- $date = $this->get_date_check($file, $mediafromftp_settings['dateset']);
515
- if ( $mediafromftp_settings['dateset'] === 'new' || $mediafromftp_settings['dateset'] === 'fixed' ) {
516
- $input_html .= '<input type="hidden" name="new_url_attaches['.$postcount.'][datetime]" value="'.$date.'" form="mediafromftp_ajax_update" >';
517
- } else {
518
- $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;">';
519
- }
520
-
521
- return array($input_html, $date_time_html);
522
-
523
- }
524
-
525
- /* ==================================================
526
- * Search Option html
527
- * @param array $mediafromftp_settings
528
- * @return string $html
529
- * @since 9.98
530
- */
531
- public function search_option_html($mediafromftp_settings){
532
-
533
- $html = '<div class="item-mediafromftp-settings">';
534
- $html .= '<h3>'.__('Pagination').'</h3>';
535
- $html .= '<label>'.__('Number of items per page:').'</label>';
536
- $html .= '<input type="number" step="1" min="1" max="999" class="screen-per-page" name="mediafromftp_pagemax" maxlength="3" value="'.$mediafromftp_settings['pagemax'].'">';
537
- $html .= '</div>';
538
-
539
- $html .= '<div class="item-mediafromftp-settings">';
540
- $html .= '<h3>'.__('Display of search results', 'media-from-ftp').'</h3>';
541
- $html .= '<div style="display: block;padding:5px 5px">';
542
- if ($mediafromftp_settings['search_display_metadata'] == TRUE) {
543
- $html .= '<input type="radio" name="search_display_metadata" value="1" checked>';
544
- } else {
545
- $html .= '<input type="radio" name="search_display_metadata" value="1">';
546
- }
547
- $html .= __('Usual selection. It is user-friendly. It displays a thumbnail and metadata. It is low speed.', 'media-from-ftp');
548
- $html .= '</div>';
549
- $html .= '<div style="display: block;padding:5px 5px">';
550
- if ($mediafromftp_settings['search_display_metadata'] == FALSE) {
551
- $html .= '<input type="radio" name="search_display_metadata" value="0" checked>';
552
- } else {
553
- $html .= '<input type="radio" name="search_display_metadata" value="0">';
554
- }
555
- $html .= __('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');
556
- $html .= '</div>';
557
- $html .= '</div>';
558
-
559
- $html .= '<div class="item-mediafromftp-settings">';
560
- $html .= '<h3>'.__('Exclude file', 'media-from-ftp').'</h3>';
561
- $html .= '<div style="display: block;padding:5px 5px">';
562
- $html .= '<div>'.__('Regular expression is possible.', 'media-from-ftp').'</div>';
563
- $html .= '<textarea id="mediafromftp_exclude" name="mediafromftp_exclude" rows="3" style="width: 100%;">'.$mediafromftp_settings['exclude'].'</textarea>';
564
- $html .= '</div>';
565
- $html .= '</div>';
566
-
567
- $html .= '<div class="item-mediafromftp-settings">';
568
- $html .= '<h3>'.__('Search method of files', 'media-from-ftp').'</h3>';
569
- $html .= '<div style="display: block;padding:5px 5px">';
570
- if ($mediafromftp_settings['recursive_search'] == TRUE) {
571
- $html .= '<input type="radio" name="mediafromftp_recursive_search" value="1" checked>';
572
- } else {
573
- $html .= '<input type="radio" name="mediafromftp_recursive_search" value="1">';
574
- }
575
- $html .= __('Recursively search files below specified directory.', 'media-from-ftp');
576
- $html .= '</div>';
577
- $html .= '<div style="display: block;padding:5px 5px">';
578
- if ($mediafromftp_settings['recursive_search'] == FALSE) {
579
- $html .= '<input type="radio" name="mediafromftp_recursive_search" value="0" checked>';
580
- } else {
581
- $html .= '<input type="radio" name="mediafromftp_recursive_search" value="0">';
582
- }
583
- $html .= __('Search files only for specified directories.', 'media-from-ftp');
584
- $html .= '</div>';
585
- $html .= '</div>';
586
-
587
- $html .= '<div class="item-mediafromftp-settings">';
588
- $html .= '<h3>'.__('Search method for the exclusion of the thumbnail', 'media-from-ftp').'</h3>';
589
- $html .= '<div style="display: block;padding:5px 5px">';
590
- if ($mediafromftp_settings['thumb_deep_search'] == FALSE) {
591
- $html .= '<input type="radio" name="mediafromftp_thumb_deep_search" value="0" checked>';
592
- } else {
593
- $html .= '<input type="radio" name="mediafromftp_thumb_deep_search" value="0">';
594
- }
595
- $html .= __('Usual selection. It is hi speed.', 'media-from-ftp');
596
- $html .= '</div>';
597
- $html .= '<div style="display: block;padding:5px 5px">';
598
- if ($mediafromftp_settings['thumb_deep_search'] == TRUE) {
599
- $html .= '<input type="radio" name="mediafromftp_thumb_deep_search" value="1" checked>';
600
- } else {
601
- $html .= '<input type="radio" name="mediafromftp_thumb_deep_search" value="1">';
602
- }
603
- $html .= __('Unusual selection. if you want to search for filename that contains such -0x0. It is low speed.', 'media-from-ftp');
604
- $html .= '</div>';
605
- $html .= '</div>';
606
-
607
- return $html;
608
-
609
- }
610
-
611
- /* ==================================================
612
- * @param string $searchdir
613
- * @param string $character_code
614
- * @param string $wordpress_path
615
- * @return string $linkselectbox
616
- * @since 9.98
617
- */
618
- public function dir_select_box($searchdir, $character_code, $wordpress_path) {
619
-
620
- $linkselectbox = NULL;
621
- $linkselectbox .= '<div style="font-size: small; font-weight: bold;"><code>'.$wordpress_path.'</code></div>';
622
- $linkselectbox .= '<select name="searchdir" style="width: 250px">';
623
-
624
- $dirs = $this->scan_dir($this->upload_dir);
625
- foreach ($dirs as $linkdir) {
626
- if ( strstr($linkdir, $wordpress_path ) ) {
627
- $linkdirenc = $this->mb_utf8(str_replace($wordpress_path, '', $linkdir), $character_code);
628
- } else {
629
- $linkdirenc = $this->upload_path.$this->mb_utf8(str_replace($this->upload_dir, "", $linkdir), $character_code);
630
- }
631
- if( $searchdir === $linkdirenc ){
632
- $linkdirs = '<option value="'.urlencode($linkdirenc).'" selected>'.$linkdirenc.'</option>';
633
- }else{
634
- $linkdirs = '<option value="'.urlencode($linkdirenc).'">'.$linkdirenc.'</option>';
635
- }
636
- $linkselectbox = $linkselectbox.$linkdirs;
637
- }
638
- if( $searchdir === $this->upload_path ){
639
- $linkdirs = '<option value="'.urlencode($this->upload_path).'" selected>'.$this->upload_path.'</option>';
640
- }else{
641
- $linkdirs = '<option value="'.urlencode($this->upload_path).'">'.$this->upload_path.'</option>';
642
- }
643
- $linkselectbox = $linkselectbox.$linkdirs.'</select>';
644
-
645
- return $linkselectbox;
646
-
647
- }
648
-
649
- /* ==================================================
650
- * @param string $ext2typefilter
651
- * @param string $extfilter
652
- * @return string $typeextselectbox
653
- * @since 10.01
654
- */
655
- public function type_ext_select_box($ext2typefilter, $extfilter) {
656
-
657
- $typeextselectbox = NULL;
658
- $typeextselectbox .= '<select name="ext2type" style="width: 110px;">';
659
- $typeextselectbox .= '<option value="all"';
660
- if ($ext2typefilter === 'all') $typeextselectbox .= ' selected';
661
- $typeextselectbox .= '>'.esc_attr( __('All types', 'media-from-ftp') ).'</option>';
662
- $typeextselectbox .= '<option value="image"';
663
- if ($ext2typefilter === 'image') $typeextselectbox .= ' selected';
664
- $typeextselectbox .= '>image</option>';
665
- $typeextselectbox .= '<option value="audio"';
666
- if ($ext2typefilter === 'audio') $typeextselectbox .= ' selected';
667
- $typeextselectbox .= '>audio</option>';
668
- $typeextselectbox .= '<option value="video"';
669
- if ($ext2typefilter === 'video') $typeextselectbox .= ' selected';
670
- $typeextselectbox .= '>video</option>';
671
- $typeextselectbox .= '<option value="document"';
672
- if ($ext2typefilter === 'document') $typeextselectbox .= ' selected';
673
- $typeextselectbox .= '>document</option>';
674
- $typeextselectbox .= '<option value="spreadsheet"';
675
- if ($ext2typefilter === 'spreadsheet') $typeextselectbox .= ' selected';
676
- $typeextselectbox .= '>spreadsheet</option>';
677
- $typeextselectbox .= '<option value="interactive"';
678
- if ($ext2typefilter === 'interactive') $typeextselectbox .= ' selected';
679
- $typeextselectbox .= '>interactive</option>';
680
- $typeextselectbox .= '<option value="text"';
681
- if ($ext2typefilter === 'text') $typeextselectbox .= ' selected';
682
- $typeextselectbox .= '>text</option>';
683
- $typeextselectbox .= '<option value="archive"';
684
- if ($ext2typefilter === 'archive') $typeextselectbox .= ' selected';
685
- $typeextselectbox .= '>archive</option>';
686
- $typeextselectbox .= '<option value="code"';
687
- if ($ext2typefilter === 'code') $typeextselectbox .= ' selected';
688
- $typeextselectbox .= '>code</option>';
689
- $typeextselectbox .= '</select>';
690
- $typeextselectbox .= '<select name="extension" style="width: 120px;">';
691
- $typeextselectbox .= '<option value="all"';
692
- if ($extfilter === 'all') $typeextselectbox .= ' selected';
693
- $typeextselectbox .= '>'.esc_attr( __('All extensions', 'media-from-ftp') ).'</option>';
694
-
695
- $extensions = $this->scan_extensions($ext2typefilter);
696
- foreach ($extensions as $extselect) {
697
- $typeextselectbox .= '<option value="'.$extselect.'"';
698
- if ($extfilter === $extselect) $typeextselectbox .= ' selected';
699
- $typeextselectbox .= '>'.$extselect.'</option>';
700
- }
701
- $typeextselectbox .= '</select>';
702
-
703
- return $typeextselectbox;
704
-
705
- }
706
-
707
- /* ==================================================
708
- * @param array $mediafromftp_settings
709
- * @return string $form_html
710
- * @since 9.50
711
- */
712
- public function form_html($mediafromftp_settings) {
713
-
714
- $scriptname = admin_url('admin.php?page=mediafromftp-search-register');
715
-
716
- $searchtext = NULL;
717
- if ( !empty($_POST['searchtext']) ) {
718
- $searchtext = sanitize_text_field($_POST['searchtext']);
719
- } else if ( !empty($_GET['searchtext']) ) {
720
- $searchtext = sanitize_text_field($_GET['searchtext']);
721
- }
722
-
723
- $pagemax = $mediafromftp_settings['pagemax'];
724
- $searchdir = $mediafromftp_settings['searchdir'];
725
- $character_code = $mediafromftp_settings['character_code'];
726
- $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
727
- $extfilter = $mediafromftp_settings['extfilter'];
728
- $wordpress_path = wp_normalize_path(ABSPATH);
729
-
730
- $linkselectbox = $this->dir_select_box($searchdir, $character_code, $wordpress_path);
731
- $linkselectbox2 = $this->type_ext_select_box($ext2typefilter, $extfilter);
732
-
733
- ?>
734
- <div class="wp-filter" style="margin: 0px;"> <!-- wp-admin/css/list-tables.css -->
735
- <form method="post" action="<?php echo $scriptname; ?>">
736
- <?php wp_nonce_field('mff_search', 'media_from_ftp_search'); ?>
737
- <?php echo $linkselectbox; ?>
738
- <?php submit_button( __('Search'), 'large', '', FALSE ); ?>
739
- <span style="margin-right: 1em;"></span>
740
- <?php echo $linkselectbox2; ?>
741
- <?php
742
- if ( empty($searchtext) ) {
743
- ?>
744
- <input name="searchtext" type="text" value="" placeholder="<?php echo __('Search'); ?>">
745
- <?php
746
- } else {
747
- ?>
748
- <input name="searchtext" type="text" value="" placeholder="<?php echo $searchtext; ?>">
749
- <?php
750
- }
751
- submit_button( __('Filter'), 'large', '', FALSE );
752
- ?>
753
- </form>
754
- </div>
755
- <?php
756
-
757
- }
758
-
759
- /* ==================================================
760
- * @param string $ext
761
- * @param string $new_url_attach
762
- * @param string $new_url_datetime
763
- * @param string $dateset
764
- * @param string $datefixed
765
- * @param bool $yearmonth_folders
766
- * @param string $character_code
767
- * @param string $cron_user
768
- * @return array $attach_id(int), $new_attach_title(string), $new_url_attach(string), $metadata(array)
769
- * @since 2.36
770
- */
771
- public function regist($ext, $new_url_attach, $new_url_datetime, $dateset, $datefixed, $yearmonth_folders, $character_code, $cron_user){
772
-
773
- // Rename and Move file
774
- $suffix_attach_file = '.'.$ext;
775
- $new_attach_titlenames = explode('/', $new_url_attach);
776
- $new_attach_title = str_replace($suffix_attach_file, '', end($new_attach_titlenames));
777
- // for utf8mb4 charcter
778
- $new_attach_title = $this->utf8mb4_html_numeric_encode($new_attach_title, $character_code);
779
-
780
- $path_parts = pathinfo($new_url_attach);
781
- $urlpath_dir = wp_make_link_relative($path_parts['dirname']);
782
-
783
- $relation_path_true = strstr($this->upload_path, '../');
784
- if ( !$relation_path_true ) {
785
- $plus_path = ltrim(str_replace($this->upload_path, '', strstr($urlpath_dir, $this->upload_path)), '/');
786
- } else {
787
- $plus_path_tmp = str_replace($urlpath_dir, '', str_replace('../', '', $this->upload_path).'/');
788
- $plus_path = ltrim(str_replace($plus_path_tmp, '', $urlpath_dir), '/');
789
- }
790
- if ( !empty($plus_path) ) {
791
- $plus_path = trailingslashit($plus_path);
792
- }
793
- $filename = $plus_path.wp_basename( $new_url_attach );
794
-
795
- $err_copy = TRUE;
796
- $copy_file_org1 = NULL;
797
- $copy_file_org2 = NULL;
798
- $copy_file_org3 = NULL;
799
- $copy_file_new1 = NULL;
800
- $copy_file_new2 = NULL;
801
- $copy_file_new3 = NULL;
802
- $postdategmt = date_i18n( "Y-m-d H:i:s", FALSE, TRUE );
803
- if ( $dateset === 'server' || $dateset === 'exif' ) {
804
- $postdategmt = get_gmt_from_date($new_url_datetime.':00');
805
- }
806
- if ( strpos( $filename ,'/' ) === FALSE ) {
807
- $currentdir = '';
808
- $currentfile = $filename;
809
- } else {
810
- $currentfiles = explode('/', $filename);
811
- $currentfile = end($currentfiles);
812
- $currentdir = str_replace($currentfile, '', $filename);
813
- }
814
- if ( strpos($currentfile, ' ' ) ) {
815
- $oldfilename = $filename;
816
- $currentfile = str_replace(' ', '-', $currentfile);
817
- $filename = $currentdir.$currentfile;
818
- $new_url_attach = $this->upload_url.'/'.$filename;
819
- $copy_file_org1 = $this->mb_encode_multibyte($this->upload_dir.'/'.$oldfilename, $character_code);
820
- $copy_file_new1 = $this->mb_encode_multibyte($this->upload_dir.'/'.$filename, $character_code);
821
- $err_copy = @copy( $copy_file_org1, $copy_file_new1 );
822
- if ( !$err_copy ) {
823
- return array(-1, $this->mb_utf8($copy_file_org1, $character_code), $this->mb_utf8($this->upload_dir.'/'.$plus_path, $character_code), NULL);
824
- }
825
- }
826
- if ( function_exists('mb_check_encoding') ) {
827
- if ( !mb_check_encoding($new_url_attach, 'ASCII') ) {
828
- if ( strpos( $filename ,'/' ) === FALSE ) {
829
- $currentdir = '';
830
- $currentfile = str_replace($suffix_attach_file, '', $filename);
831
- } else {
832
- $currentfiles = explode('/', $filename);
833
- $currentfile = end($currentfiles);
834
- $currentdir = str_replace($currentfile, '', $filename);
835
- $currentfile = str_replace($suffix_attach_file, '', $currentfile);
836
- }
837
-
838
- $oldfilename = $currentdir.$currentfile.$suffix_attach_file;
839
- $filename = $currentdir.md5($currentfile).$suffix_attach_file;
840
- $new_url_attach = $this->upload_url.'/'.$filename;
841
- $copy_file_org2 = $this->mb_encode_multibyte($this->upload_dir.'/'.$oldfilename, $character_code);
842
- $copy_file_new2 = $this->mb_encode_multibyte($this->upload_dir.'/'.$filename, $character_code);
843
- $err_copy = @copy( $copy_file_org2, $copy_file_new2 );
844
- if ( !$err_copy ) {
845
- if (!empty($copy_file_new1)) {
846
- $copy_file_org2 = $copy_file_org1;
847
- unlink( $copy_file_new1 );
848
- }
849
- return array(-1, $this->mb_utf8($copy_file_org2, $character_code), $this->mb_utf8($this->upload_dir.'/'.$plus_path, $character_code), NULL);
850
- }
851
- }
852
- }
853
-
854
- // Move YearMonth Folders
855
- if ( $yearmonth_folders == 1 ) {
856
- $y = substr( $postdategmt, 0, 4 );
857
- $m = substr( $postdategmt, 5, 2 );
858
- $subdir = "/$y/$m";
859
- $filename_base = wp_basename($filename);
860
- if ( $this->upload_dir.'/'.$filename <> $this->upload_dir.$subdir.'/'.$filename_base ) {
861
- if ( !file_exists($this->mb_encode_multibyte($this->upload_dir.$subdir, $character_code)) ) {
862
- wp_mkdir_p($this->mb_encode_multibyte($this->upload_dir.$subdir, $character_code));
863
- }
864
- if ( file_exists($this->mb_encode_multibyte($this->upload_dir.$subdir.'/'.$filename_base, $character_code)) ) {
865
- $filename_base = wp_basename($filename, $suffix_attach_file).date_i18n( "dHis", FALSE, FALSE ).$suffix_attach_file;
866
- }
867
- $copy_file_org3 = $this->mb_encode_multibyte($this->upload_dir.'/'.$filename, $character_code);
868
- $copy_file_new3 = $this->mb_encode_multibyte($this->upload_dir.$subdir.'/'.$filename_base, $character_code);
869
- $err_copy = @copy( $copy_file_org3, $copy_file_new3 );
870
- if ( !$err_copy ) {
871
- if (!empty($copy_file_new1)) {
872
- $copy_file_org3 = $copy_file_org1;
873
- unlink( $copy_file_new1 );
874
- } else if (!empty($copy_file_new2)) {
875
- $copy_file_org3 = $copy_file_org2;
876
- unlink( $copy_file_new2 );
877
- }
878
- return array(-1, $this->mb_utf8($copy_file_org3, $character_code), $this->mb_utf8($this->upload_dir.$subdir, $character_code), NULL);
879
- }
880
- $filename = ltrim($subdir, '/').'/'.$filename_base;
881
- $new_url_attach = $this->upload_url.'/'.$filename;
882
- }
883
- }
884
-
885
- $filename = $this->mb_utf8($filename, $character_code);
886
- $new_url_attach = $this->mb_utf8($new_url_attach, $character_code);
887
-
888
- // File Regist
889
- $newfile_post = array(
890
- 'post_title' => $new_attach_title,
891
- 'post_content' => '',
892
- 'post_author' => $cron_user,
893
- 'guid' => $new_url_attach,
894
- 'post_status' => 'inherit',
895
- 'post_type' => 'attachment',
896
- 'post_mime_type' => $this->mime_type($suffix_attach_file)
897
- );
898
- $attach_id = wp_insert_attachment( $newfile_post, $filename );
899
-
900
- if ( $attach_id == 0 ) { // error
901
- if (!empty($copy_file_new1)) { unlink( $copy_file_new1 ); }
902
- if (!empty($copy_file_new2)) { unlink( $copy_file_new2 ); }
903
- if (!empty($copy_file_new3)) { unlink( $copy_file_new3 ); }
904
- return array(-2, $new_attach_title, $new_url_attach, NULL);
905
- } else {
906
- if (!empty($copy_file_org1)) { unlink( $copy_file_org1 ); }
907
- if (!empty($copy_file_org2)) { unlink( $copy_file_org2 ); }
908
- if (!empty($copy_file_org3)) { unlink( $copy_file_org3 ); }
909
- }
910
-
911
- // Date Time Regist
912
- if ( $dateset <> 'new' ) {
913
- if ( $dateset === 'fixed' ) {
914
- $postdategmt = get_gmt_from_date($datefixed.':00');
915
- }
916
- $postdate = get_date_from_gmt($postdategmt);
917
- $up_post = array(
918
- 'ID' => $attach_id,
919
- 'post_date' => $postdate,
920
- 'post_date_gmt' => $postdategmt,
921
- 'post_modified' => $postdate,
922
- 'post_modified_gmt' => $postdategmt
923
- );
924
- wp_update_post( $up_post );
925
- }
926
-
927
- // for wp_read_audio_metadata and wp_read_video_metadata
928
- include_once( ABSPATH . 'wp-admin/includes/media.php' );
929
- // for wp_generate_attachment_metadata
930
- include_once( ABSPATH . 'wp-admin/includes/image.php' );
931
-
932
- // Meta data Regist
933
- $metadata = NULL;
934
- $fullpath_filename = $this->mb_encode_multibyte(get_attached_file($attach_id), $character_code);
935
- if ( wp_ext2type($ext) === 'image' || strtolower($ext) === 'pdf' ){
936
- $metadata = wp_generate_attachment_metadata( $attach_id, $fullpath_filename );
937
- } else if ( wp_ext2type($ext) === 'video' ){
938
- $metadata = wp_read_video_metadata( $fullpath_filename );
939
- } else if ( wp_ext2type($ext) === 'audio' ){
940
- $metadata = wp_read_audio_metadata( $fullpath_filename );
941
- }
942
- wp_update_attachment_metadata( $attach_id, $metadata );
943
-
944
- return array($attach_id, $new_attach_title, $new_url_attach, $metadata);
945
-
946
- }
947
-
948
- /* ==================================================
949
- * @param string $ext
950
- * @param int $attach_id
951
- * @param array $metadata
952
- * @param string $character_code
953
- * @param string $exif_text_tag
954
- * @return array $imagethumburls(string), $mimetype(string), $length(string), $stamptime(string), $file_size(string), $exif_text(string)
955
- * @since 7.4
956
- */
957
- public function output_metadata($ext, $attach_id, $metadata, $character_code, $exif_text_tag){
958
-
959
- $imagethumburls = array();
960
- $mimetype = NULL;
961
- $length = NULL;
962
- $exif_text = NULL;
963
- $filetype = wp_check_filetype( $this->mb_encode_multibyte(get_attached_file($attach_id), $character_code) );
964
- if ( wp_ext2type($ext) === 'image' || strtolower($ext) === 'pdf' ){
965
- $wp_attached_file = get_post_meta( $attach_id, '_wp_attached_file', true );
966
- $imagethumburl_base = $this->upload_url.'/'.rtrim($wp_attached_file, wp_basename($wp_attached_file));
967
- if ( !empty($metadata) ) {
968
- foreach ( $metadata as $key1 => $key2 ){
969
- if ( $key1 === 'sizes' ) {
970
- foreach ( $metadata[$key1] as $key2 => $key3 ){
971
- $imagethumburls[$key2] = $imagethumburl_base.$metadata['sizes'][$key2]['file'];
972
- }
973
- }
974
- }
975
- }
976
- $mimetype = $filetype['ext'].'('.$filetype['type'].')';
977
- }else if ( wp_ext2type($ext) === 'video'|| wp_ext2type($ext) === 'audio' ){
978
- $mimetype = $metadata['fileformat'].'('.$metadata['mime_type'].')';
979
- $length = $metadata['length_formatted'];
980
- } else {
981
- $metadata = NULL;
982
- $mimetype = $filetype['ext'].'('.$filetype['type'].')';
983
- }
984
-
985
- $stamptime = get_the_time( 'Y-n-j ', $attach_id ).get_the_time( 'G:i', $attach_id );
986
- if ( isset( $metadata['filesize'] ) ) {
987
- $file_size = $metadata['filesize'];
988
- } else {
989
- $file_size = @filesize( $this->mb_encode_multibyte(get_attached_file($attach_id), $character_code) );
990
- }
991
-
992
- if ( $this->is_add_on_activate['exif'] ) {
993
- if ( $filetype['type'] === 'image/jpeg' || $filetype['type'] === 'image/tiff' ) {
994
- if ( !empty($exif_text_tag) ) {
995
- include_once $this->plugin_dir.'/media-from-ftp-add-on-exif/inc/MediaFromFtpAddOnExif.php';
996
- $mediafromftpaddonexif = new MediaFromFtpAddOnExif();
997
- $exif_text = $mediafromftpaddonexif->exifcaption($attach_id, $metadata, $exif_text_tag);
998
- unset($mediafromftpaddonexif);
999
- }
1000
- }
1001
- }
1002
-
1003
- return array($imagethumburls, $mimetype, $length, $stamptime, $file_size, $exif_text);
1004
-
1005
- }
1006
-
1007
- /* ==================================================
1008
- * @param string $ext
1009
- * @param string $file_size
1010
- * @param int $attach_id
1011
- * @param string $new_attach_title
1012
- * @param string $new_url_attach
1013
- * @param array $imagethumburls
1014
- * @param string $mimetype
1015
- * @param string $length
1016
- * @param string $stamptime
1017
- * @param string $file_size
1018
- * @param string $exif_text
1019
- * @param array $image_attr_thumbnail
1020
- * @param array $mediafromftp_settings
1021
- * @param string $cat_html
1022
- * @return string $output_html
1023
- * @since 9.30
1024
- */
1025
- public 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){
1026
-
1027
- $thumbnails = array();
1028
-
1029
- $output_html = '<div style="border-bottom: 1px solid; padding-top: 5px; padding-bottom: 5px;">';
1030
- $output_html .= '<img width="40" height="40" src="'.$image_attr_thumbnail[0].'" style="float: left; margin: 5px;">';
1031
- $output_html .= '<div style="overflow: hidden;">';
1032
- $output_html .= '<div>ID: '.$attach_id.'</div>';
1033
- $output_html .= '<div>'.__('Title').': '.$new_attach_title.'</div>';
1034
- $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>';
1035
- $output_html .= '<div>URL: <a href="'.$new_url_attach.'" target="_blank" style="text-decoration: none; word-break: break-all;">'.$new_url_attach.'</a></div>';
1036
- $new_url_attachs = explode('/', $new_url_attach);
1037
- $output_html .= '<div>'.__('File name:').' '.end($new_url_attachs).'</div>';
1038
-
1039
- $output_html .= '<div>'.__('Date/Time').': '.$stamptime.'</div>';
1040
- if ( !$file_size ) {
1041
- $file_size = '<font color="red">'.__('Could not retrieve.', 'media-from-ftp').'</font>';
1042
- } else {
1043
- $file_size = size_format($file_size);
1044
- }
1045
- $output_html .= '<div>'.__('File type:').' '.$mimetype.'</div>';
1046
- $output_html .= '<div>'.__('File size:').' '.$file_size.'</div>';
1047
- if ( wp_ext2type($ext) === 'image' || (strtolower($ext) === 'pdf' && !empty($imagethumburls)) ) {
1048
- $output_html .= '<div>'.__('Images').': ';
1049
- $thumb_count = 0;
1050
- foreach ( $imagethumburls as $thumbsize => $imagethumburl ) {
1051
- $output_html .= '[<a href="'.$imagethumburl.'" target="_blank" style="text-decoration: none; word-break: break-all;">'.$thumbsize.'</a>]';
1052
- ++$thumb_count;
1053
- $thumbnails[$thumb_count] = $imagethumburl;
1054
- }
1055
- $output_html .= '</div>';
1056
- if ( !empty($exif_text) ) {
1057
- $output_html .= '<div>'.__('Caption').'[Exif]: '.$exif_text.'</div>';
1058
- }
1059
- } else {
1060
- if ( wp_ext2type($ext) === 'video' || wp_ext2type($ext) === 'audio' ) {
1061
- $output_html .= '<div>'.__('Length:').' '.$length.'</div>';
1062
- }
1063
- }
1064
- if ( !empty($cat_html) ) {
1065
- $output_html .= $cat_html;
1066
- }
1067
- $output_html .= '</div></div>';
1068
-
1069
- if ( $mediafromftp_settings['log'] ) {
1070
- global $wpdb;
1071
- $user = wp_get_current_user();
1072
- $thumbnail = json_encode($thumbnails);
1073
- $thumbnail = str_replace('\\', '', $thumbnail);
1074
- // Log
1075
- $log_arr = array(
1076
- 'id' => $attach_id,
1077
- 'user' => $user->display_name,
1078
- 'title' => $new_attach_title,
1079
- 'permalink' => get_attachment_link($attach_id),
1080
- 'url' => $new_url_attach,
1081
- 'filename' => end($new_url_attachs),
1082
- 'time' => $stamptime,
1083
- 'filetype' => $mimetype,
1084
- 'filesize' => $file_size,
1085
- 'exif' => $exif_text,
1086
- 'length' => $length,
1087
- 'thumbnail' => $thumbnail,
1088
- 'mlccategories' => $mlccategory,
1089
- 'emlcategories' => $emlcategory,
1090
- 'mlacategories' => $mlacategory,
1091
- 'mlatags' => $mlatag
1092
- );
1093
- $table_name = $wpdb->prefix.'mediafromftp_log';
1094
- $wpdb->insert( $table_name, $log_arr);
1095
- $wpdb->show_errors();
1096
- }
1097
-
1098
- return $output_html;
1099
-
1100
- }
1101
-
1102
- /* ==================================================
1103
- * @param string $base
1104
- * @param string $relationalpath
1105
- * @return string realurl
1106
- * @since 7.7
1107
- */
1108
- private function realurl( $base, $relationalpath ){
1109
- $parse = array(
1110
- "scheme" => null,
1111
- "user" => null,
1112
- "pass" => null,
1113
- "host" => null,
1114
- "port" => null,
1115
- "query" => null,
1116
- "fragment" => null
1117
- );
1118
- $parse = parse_url( $base );
1119
-
1120
- if( strpos($parse["path"], "/", (strlen($parse["path"])-1)) !== false ){
1121
- $parse["path"] .= ".";
1122
- }
1123
-
1124
- if( preg_match("#^https?://#", $relationalpath) ){
1125
- return $relationalpath;
1126
- }else if( preg_match("#^/.*$#", $relationalpath) ){
1127
- return $parse["scheme"] . "://" . $parse["host"] . $relationalpath;
1128
- }else{
1129
- $basePath = explode("/", dirname($parse["path"]));
1130
- $relPath = explode("/", $relationalpath);
1131
- foreach( $relPath as $relDirName ){
1132
- if( $relDirName == "." ){
1133
- array_shift( $basePath );
1134
- array_unshift( $basePath, "" );
1135
- }else if( $relDirName == ".." ){
1136
- array_pop( $basePath );
1137
- if( count($basePath) == 0 ){
1138
- $basePath = array("");
1139
- }
1140
- }else{
1141
- array_push($basePath, $relDirName);
1142
- }
1143
- }
1144
- $path = implode("/", $basePath);
1145
- return $parse["scheme"] . "://" . $parse["host"] . $path;
1146
- }
1147
-
1148
- }
1149
-
1150
- /* ==================================================
1151
- * @param none
1152
- * @return array $upload_dir, $upload_url, $upload_path
1153
- * @since 7.8
1154
- */
1155
- public function upload_dir_url_path(){
1156
-
1157
- $wp_uploads = wp_upload_dir();
1158
-
1159
- $relation_path_true = strpos($wp_uploads['baseurl'], '../');
1160
- if ( $relation_path_true > 0 ) {
1161
- $relationalpath = substr($wp_uploads['baseurl'], $relation_path_true);
1162
- $basepath = substr($wp_uploads['baseurl'], 0, $relation_path_true);
1163
- $upload_url = $this->realurl($basepath, $relationalpath);
1164
- $upload_dir = wp_normalize_path(realpath($wp_uploads['basedir']));
1165
- } else {
1166
- $upload_url = $wp_uploads['baseurl'];
1167
- $upload_dir = wp_normalize_path($wp_uploads['basedir']);
1168
- }
1169
-
1170
- if(is_ssl()){
1171
- $upload_url = str_replace('http:', 'https:', $upload_url);
1172
- }
1173
-
1174
- if ( $relation_path_true > 0 ) {
1175
- $upload_path = $relationalpath;
1176
- } else {
1177
- $wordpress_path = wp_normalize_path(ABSPATH);
1178
- $upload_path = str_replace($wordpress_path, '', $upload_dir);
1179
- }
1180
-
1181
- $upload_dir = untrailingslashit($upload_dir);
1182
- $upload_url = untrailingslashit($upload_url);
1183
- $upload_path = untrailingslashit($upload_path);
1184
-
1185
- return array($upload_dir, $upload_url, $upload_path);
1186
-
1187
- }
1188
-
1189
- /* ==================================================
1190
- * @param none
1191
- * @return $siteurl
1192
- * @since 8.5
1193
- */
1194
- public function siteurl(){
1195
- if ( is_multisite() ) {
1196
- global $blog_id;
1197
- $siteurl = get_blog_details($blog_id)->siteurl;
1198
- } else {
1199
- $siteurl = site_url();
1200
- }
1201
- return $siteurl;
1202
- }
1203
-
1204
- /* ==================================================
1205
- * @param string $ext2typefilter
1206
- * @return array $extensions
1207
- * @since 8.2
1208
- */
1209
- private function scan_extensions($ext2typefilter){
1210
-
1211
- $extensions = array();
1212
- global $user_ID;
1213
- $mimes = get_allowed_mime_types($user_ID);
1214
-
1215
- foreach ($mimes as $extselect => $mime) {
1216
- if( strpos( $extselect, '|' ) ){
1217
- $extselects = explode('|',$extselect);
1218
- foreach ( $extselects as $extselect2 ) {
1219
- if ( $ext2typefilter === 'all' || $ext2typefilter === wp_ext2type($extselect2) ) {
1220
- $extensions[] = $extselect2;
1221
- }
1222
- }
1223
- } else {
1224
- if ( $ext2typefilter === 'all' || $ext2typefilter === wp_ext2type($extselect) ) {
1225
- $extensions[] = $extselect;
1226
- }
1227
- }
1228
- }
1229
-
1230
- asort($extensions);
1231
- return $extensions;
1232
-
1233
- }
1234
-
1235
- /* ==================================================
1236
- * @param string $str
1237
- * @param string $character_code
1238
- * @return string $ret
1239
- * @since 9.02
1240
- */
1241
- private function utf8mb4_html_numeric_encode($str, $character_code) {
1242
-
1243
- if ( function_exists('mb_language') && $character_code <> 'none' ) {
1244
- $length = mb_strlen($str, 'UTF-8');
1245
- $ret = '';
1246
-
1247
- for ($i = 0; $i < $length; ++$i) {
1248
- $buf = mb_substr($str, $i, 1, 'UTF-8');
1249
-
1250
- if (mb_strlen($buf, '8bit') === 4) {
1251
- $buf = mb_encode_numericentity($buf, array(0x10000, 0x10FFFF, 0, 0xFFFFFF), 'UTF-8');
1252
- }
1253
-
1254
- $ret .= $buf;
1255
- }
1256
- } else {
1257
- $ret = $str;
1258
- }
1259
-
1260
- return $ret;
1261
-
1262
- }
1263
-
1264
- /* ==================================================
1265
- * @param string $character_code
1266
- * @return string none
1267
- * @since 9.05
1268
- */
1269
- public function mb_initialize($character_code) {
1270
-
1271
- if ( function_exists('mb_language') && $character_code <> 'none' ) {
1272
- if( get_locale() === 'ja' ) {
1273
- mb_language('Japanese');
1274
- } else if( get_locale() === 'en_US' ) {
1275
- mb_language('English');
1276
- } else {
1277
- mb_language('uni');
1278
- }
1279
- }
1280
-
1281
- }
1282
-
1283
- /* ==================================================
1284
- * @param string $str
1285
- * @param string $character_code
1286
- * @return string $str
1287
- * @since 9.10
1288
- */
1289
- public function mb_encode_multibyte($str, $character_code) {
1290
-
1291
- if ( function_exists('mb_language') && $character_code <> 'none' ) {
1292
- $str = mb_convert_encoding($str, $character_code, "auto");
1293
- }
1294
-
1295
- return $str;
1296
-
1297
- }
1298
-
1299
- /* ==================================================
1300
- * @param string $str
1301
- * @param string $character_code
1302
- * @return string $str
1303
- * @since 9.05
1304
- */
1305
- public function mb_utf8($str, $character_code) {
1306
-
1307
- if ( function_exists('mb_convert_encoding') && $character_code <> 'none' ) {
1308
- $str = mb_convert_encoding($str, "UTF-8", "auto");
1309
- }
1310
-
1311
- return $str;
1312
-
1313
- }
1314
-
1315
- /* ==================================================
1316
- * for php < 5.3.0
1317
- * @param array $array
1318
- * @return array $array
1319
- * @since 9.11
1320
- */
1321
- private function array_replace() {
1322
-
1323
- $array = array();
1324
- $n = func_num_args();
1325
-
1326
- while ( $n-- >0 ) {
1327
- $array+=func_get_arg($n);
1328
- }
1329
- return $array;
1330
- }
1331
-
1332
-
1333
- /* ==================================================
1334
- * for Media Library Import
1335
- * @param string $filename
1336
- * @return array $authors
1337
- * @since 9.43
1338
- */
1339
- public function author_select($filename) {
1340
-
1341
- $scriptname = admin_url('admin.php?page=mediafromftp-import');
1342
-
1343
- $s = @file_get_contents($filename);
1344
- $controlCode = array("\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x0b", "\x0c", "\x0e", "\x0f");
1345
- $s = str_replace($controlCode, '', $s);
1346
- $xml = simplexml_load_string($s);
1347
-
1348
- $authors = array();
1349
- $namespaces = $xml->getDocNamespaces();
1350
- foreach ( $xml->xpath('/rss/channel/wp:author') as $author_arr ) {
1351
- $a = $author_arr->children( $namespaces['wp'] );
1352
- $authors[] = array(
1353
- 'author_login' => (string) $a->author_login,
1354
- 'author_display_name' => (string) $a->author_display_name,
1355
- );
1356
- }
1357
-
1358
-
1359
- $form_select = NULL;
1360
- $count = 0;
1361
- if ( current_user_can( 'manage_options' ) ) {
1362
- $blogusers = get_users();
1363
- foreach ( $authors as $key => $value) {
1364
- ++$count;
1365
- $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>';
1366
- $form_select .= '<div style="display: block; padding: 5px 30px">'.__('Assign posts to an existing user:', 'media-from-ftp').'<select name="'.$value['author_login'].'">';
1367
- $form_select .= '<option value="-1" select>'.__('Select').'</option>';
1368
- foreach ( $blogusers as $user ) {
1369
- $form_select .= '<option value="'.$user->ID.'">'.$user->display_name.'('.$user->user_login.')</option>';
1370
- }
1371
- $form_select .= '</select></div>';
1372
- }
1373
- $current_user = wp_get_current_user();
1374
- $current_user_html = '<strong>'.$current_user->display_name.'('.$current_user->user_login.')</strong>';
1375
- $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>';
1376
- } else {
1377
- $user = wp_get_current_user();
1378
- foreach ( $authors as $key => $value) {
1379
- ++$count;
1380
- $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>';
1381
- $current_user_html = '<strong>'.$user->display_name.'('.$user->user_login.')</strong>';
1382
- $form_select .= '<div style="display: block; padding: 5px 30px">'.sprintf(__('Assign posts to %1$s', 'media-from-ftp'), $current_user_html).'</div>';
1383
-
1384
- }
1385
- }
1386
- $button_value = get_submit_button( __('Apply'), 'large', 'select_author', FALSE );
1387
- $nonce_field = wp_nonce_field('mff_select_author', 'media_from_ftp_select_author');
1388
-
1389
- $author_form = <<<MEDIAFROMFTP_AUTHOR_SELECT
1390
-
1391
- <!-- BEGIN: Media from FTP Media Library Import -->
1392
- <form method="post" action="$scriptname">
1393
- $nonce_field
1394
- $form_select
1395
- <div style="display: block; padding: 20px 0px">$button_value</div>
1396
- <input type="hidden" name="mediafromftp_select_author" value="1" />
1397
- <input type="hidden" name="mediafromftp_xml_file" value="$filename" />
1398
- </form>
1399
-
1400
- <!-- END: Media from FTP Media Library Import -->
1401
-
1402
- MEDIAFROMFTP_AUTHOR_SELECT;
1403
-
1404
- return $author_form;
1405
-
1406
- }
1407
-
1408
- /* ==================================================
1409
- * for Media Library Import
1410
- * @param string $filename
1411
- * @param array $select_author
1412
- * @return string $add_js
1413
- * @since 9.40
1414
- */
1415
- public function make_object($filename, $select_author) {
1416
-
1417
- $s = @file_get_contents($filename);
1418
- $controlCode = array("\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x0b", "\x0c", "\x0e", "\x0f");
1419
- $s = str_replace($controlCode, '', $s);
1420
- $xml = simplexml_load_string($s);
1421
- $data = array();
1422
- foreach ($xml->channel->item as $item) {
1423
- $x = array();
1424
- $x['title'] = (string)$item->title;
1425
- $x['link'] = (string)$item->link;
1426
- $x['pubDate'] = (string)$item->pubDate;
1427
- $x['creator'] = (string)$item->children('dc',true)->creator;
1428
- $x['guid'] = (string)$item->guid;
1429
- $x['guid_atr'] = (string)$item->guid->attributes()->isPermaLink;
1430
- $x['description'] = (string)$item->description;
1431
- $x['content_encoded'] = (string)$item->children('content',true)->encoded;
1432
- $x['excerpt_encoded'] = (string)$item->children('excerpt',true)->encoded;
1433
- $x['post_id'] = (int)$item->children('wp',true)->post_id;
1434
- $x['post_date'] = (string)$item->children('wp',true)->post_date;
1435
- $x['post_date_gmt'] = (string)$item->children('wp',true)->post_date_gmt;
1436
- $x['comment_status'] = (string)$item->children('wp',true)->comment_status;
1437
- $x['ping_status'] = (string)$item->children('wp',true)->ping_status;
1438
- $x['post_name'] = (string)$item->children('wp',true)->post_name;
1439
- $x['status'] = (string)$item->children('wp',true)->status;
1440
- $x['post_parent'] = (int)$item->children('wp',true)->post_parent;
1441
- $x['menu_order'] = (int)$item->children('wp',true)->menu_order;
1442
- $x['post_type'] = (string)$item->children('wp',true)->post_type;
1443
- $x['post_password'] = (string)$item->children('wp',true)->post_password;
1444
- $x['is_sticky'] = (int)$item->children('wp',true)->is_sticky;
1445
- $x['attachment_url'] = (string)$item->children('wp',true)->attachment_url;
1446
-
1447
- $postmeta_count = count($item->children('wp',true)->postmeta);
1448
- for ($i = 0; $i < $postmeta_count; $i++){
1449
- $wp_postmeta_node = $item->children('wp',true)->postmeta[$i];
1450
- $post_meta_key = (string)$wp_postmeta_node->meta_key;
1451
- $post_meta_value = (string)$wp_postmeta_node->meta_value;
1452
- if ( $post_meta_key === '_wp_attached_file' ) {
1453
- $x['postmeta_wp_attached_file'] = $post_meta_key;
1454
- $x['postmeta_wp_attached_file_value'] = $post_meta_value;
1455
- } else if ( $post_meta_key === '_thumbnail_id' ) {
1456
- $x['postmeta_thumbnail_id'] = $post_meta_key;
1457
- $x['postmeta_thumbnail_id_value'] = $post_meta_value;
1458
- } else if ( $post_meta_key === '_cover_hash' ) {
1459
- $x['postmeta_cover_hash'] = $post_meta_key;
1460
- $x['postmeta_cover_hash_value'] = $post_meta_value;
1461
- } else if ( $post_meta_key === '_wp_attachment_metadata' ) {
1462
- $x['postmeta_wp_attachment_metadata'] = $post_meta_key;
1463
- $x['postmeta_wp_attachment_metadata_value'] = $post_meta_value;
1464
- } else if ( $post_meta_key === '_wp_attachment_image_alt' ) {
1465
- $x['postmeta_wp_attachment_image_alt'] = $post_meta_key;
1466
- $x['postmeta_wp_attachment_image_alt_value'] = $post_meta_value;
1467
- }
1468
- }
1469
-
1470
- $data[] = $x;
1471
- }
1472
-
1473
- $count = 0;
1474
- $file_array = array();
1475
- $db_array = array();
1476
- $db_wp_attachment_metadata_array = array();
1477
- $db_thumbnail_id_array = array();
1478
- $db_cover_hash_array = array();
1479
- $db_wp_attachment_image_alt_array = array();
1480
- foreach ($data as $key => $value) {
1481
- if ($value['post_type'] === 'attachment') {
1482
- $file = $this->upload_dir.'/'.$value['postmeta_wp_attached_file_value'];
1483
- $filetype = wp_check_filetype( basename( $file ), null );
1484
-
1485
- $user = wp_get_current_user();
1486
- $loginuser = $user->ID;
1487
- foreach ( $select_author as $authorkey => $authorvalue ) {
1488
- if ( $value['creator'] === $authorkey) {
1489
- $loginuser = $authorvalue;
1490
- }
1491
- }
1492
-
1493
- $db_array[$count] = array(
1494
- 'ID' => $value['post_id'],
1495
- 'post_author' => $loginuser,
1496
- 'post_date' => $value['post_date'],
1497
- 'post_date_gmt' => $value['post_date_gmt'],
1498
- 'post_content' => $value['content_encoded'],
1499
- 'post_title' => $value['title'],
1500
- 'post_excerpt' => $value['excerpt_encoded'],
1501
- 'post_status' => $value['status'],
1502
- 'comment_status' => $value['comment_status'],
1503
- 'ping_status' => $value['ping_status'],
1504
- 'post_password' => $value['post_password'],
1505
- 'post_name' => $value['post_name'],
1506
- 'post_parent' => $value['post_parent'],
1507
- 'guid' => $value['guid'],
1508
- 'menu_order' => $value['menu_order'],
1509
- 'post_type' => $value['post_type'],
1510
- 'post_mime_type' => $filetype['type']
1511
- );
1512
-
1513
- $file_array[$count] = $file;
1514
-
1515
- if ( array_key_exists( "postmeta_wp_attachment_metadata_value", $value ) ) {
1516
- $db_wp_attachment_metadata_array[$count] = json_encode($value['postmeta_wp_attachment_metadata_value']);
1517
- if ( strrpos($value['postmeta_wp_attached_file_value'], '/') ) {
1518
- $monthdir = '/'.substr($value['postmeta_wp_attached_file_value'], 0 , strrpos($value['postmeta_wp_attached_file_value'], '/'));
1519
- $dir = $this->upload_dir.$monthdir;
1520
- }
1521
- $thumbnails = maybe_unserialize($value['postmeta_wp_attachment_metadata_value']);
1522
- if ( is_array($thumbnails) ) {
1523
- foreach ( $thumbnails as $key1 => $value1 ) {
1524
- if ( is_array($value1) ) {
1525
- foreach ( $value1 as $key2 => $value2 ) {
1526
- if ( is_array($value2) ) {
1527
- foreach ( $value2 as $key3 => $value3 ) {
1528
- if ( $key3 === 'file' ) {
1529
- $thumbnail = $dir.'/'.$value3;
1530
- ++$count;
1531
- $file_array[$count] = $thumbnail;
1532
- }
1533
- }
1534
- }
1535
- }
1536
- }
1537
- }
1538
- }
1539
- }
1540
- if ( array_key_exists( "postmeta_thumbnail_id_value", $value ) ) {
1541
- $db_thumbnail_id_array[$count] = $value['postmeta_thumbnail_id_value'];
1542
- }
1543
- if ( array_key_exists( "postmeta_cover_hash_value", $value ) ) {
1544
- $db_cover_hash_array[$count] = $value['postmeta_cover_hash_value'];
1545
- }
1546
- if ( array_key_exists( "postmeta_wp_attachment_image_alt_value", $value ) ) {
1547
- $db_wp_attachment_image_alt_array[$count] = $value['postmeta_wp_attachment_image_alt_value'];
1548
- }
1549
-
1550
- ++$count;
1551
- }
1552
- }
1553
-
1554
- $file_obj = json_encode($file_array);
1555
- $db_array_obj = json_encode($db_array);
1556
- $db_wp_attachment_metadata_obj = json_encode($db_wp_attachment_metadata_array);
1557
- $db_thumbnail_id_obj = json_encode($db_thumbnail_id_array);
1558
- $db_cover_hash_obj = json_encode($db_cover_hash_array);
1559
- $db_wp_attachment_image_alt_obj = json_encode($db_wp_attachment_image_alt_array);
1560
-
1561
- // JS
1562
- $add_js = <<<MEDIAFROMFTP
1563
-
1564
- <!-- BEGIN: Media from FTP Media Library Import -->
1565
- <script type="text/javascript">
1566
- /* <![CDATA[ */
1567
- var medialibraryimport_maxcount = $count;
1568
- var medialibraryimport_file = $file_obj;
1569
- var medialibraryimport_db_array = $db_array_obj;
1570
- var medialibraryimport_db_wp_attachment_metadata = $db_wp_attachment_metadata_obj;
1571
- var medialibraryimport_db_thumbnail_id = $db_thumbnail_id_obj;
1572
- var medialibraryimport_db_cover_hash = $db_cover_hash_obj;
1573
- var medialibraryimport_db_wp_attachment_image_alt = $db_wp_attachment_image_alt_obj;
1574
- /* ]]> */
1575
- </script>
1576
- <!-- END: Media from FTP Media Library Import -->
1577
-
1578
- MEDIAFROMFTP;
1579
-
1580
- return $add_js;
1581
-
1582
- }
1583
-
1584
- /* ==================================================
1585
- * Sanitize Array
1586
- * @param array $a
1587
- * @return string $_a
1588
- * @since 9.88
1589
- */
1590
- public function sanitize_array($a) {
1591
-
1592
- $_a = array();
1593
- foreach($a as $key=>$value) {
1594
- if ( is_array($value) ) {
1595
- $_a[$key] = $this->sanitize_array($value);
1596
- } else {
1597
- $_a[$key] = htmlspecialchars($value);
1598
- }
1599
- }
1600
-
1601
- return $_a;
1602
-
1603
- }
1604
-
1605
- }
1606
-
1607
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/class-mediafromftp.php ADDED
@@ -0,0 +1,1701 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media from FTP
4
+ *
5
+ * @package Media from FTP
6
+ * @subpackage MediaFromFtp Main Functions
7
+ /*
8
+ Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
9
+ This program is free software; you can redistribute it and/or modify
10
+ it under the terms of the GNU General Public License as published by
11
+ the Free Software Foundation; version 2 of the License.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program; if not, write to the Free Software
20
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ /** ==================================================
24
+ * Main Functions
25
+ */
26
+ class MediaFromFtp {
27
+
28
+ /** ==================================================
29
+ * Path
30
+ *
31
+ * @var $plugin_dir plugin_dir.
32
+ */
33
+ private $plugin_dir;
34
+
35
+ /** ==================================================
36
+ * Path
37
+ *
38
+ * @var $upload_dir upload_dir.
39
+ */
40
+ private $upload_dir;
41
+
42
+ /** ==================================================
43
+ * Path
44
+ *
45
+ * @var $upload_url upload_url.
46
+ */
47
+ private $upload_url;
48
+
49
+ /** ==================================================
50
+ * Path
51
+ *
52
+ * @var $upload_path upload_path.
53
+ */
54
+ private $upload_path;
55
+
56
+ /** ==================================================
57
+ * Path
58
+ *
59
+ * @var $plugin_tmp_url plugin_tmp_url.
60
+ */
61
+ private $plugin_tmp_url;
62
+
63
+ /** ==================================================
64
+ * Path
65
+ *
66
+ * @var $plugin_tmp_dir plugin_tmp_dir.
67
+ */
68
+ private $plugin_tmp_dir;
69
+
70
+ /** ==================================================
71
+ * Add on bool
72
+ *
73
+ * @var $is_add_on_activate is_add_on_activate.
74
+ */
75
+ private $is_add_on_activate;
76
+
77
+ /** ==================================================
78
+ * Construct
79
+ *
80
+ * @since 9.81
81
+ */
82
+ public function __construct() {
83
+
84
+ $plugin_base_dir = untrailingslashit( plugin_dir_path( __DIR__ ) );
85
+ $slugs = explode( '/', $plugin_base_dir );
86
+ $slug = end( $slugs );
87
+ $this->plugin_dir = untrailingslashit( rtrim( $plugin_base_dir, $slug ) );
88
+
89
+ list($this->upload_dir, $this->upload_url, $this->upload_path) = $this->upload_dir_url_path();
90
+ $this->plugin_tmp_url = $this->upload_url . '/media-from-ftp-tmp';
91
+ $this->plugin_tmp_dir = $this->upload_dir . '/media-from-ftp-tmp';
92
+
93
+ $exif_active = false;
94
+ if ( function_exists( 'media_from_ftp_add_on_exif_load_textdomain' ) ) {
95
+ $exif_active = true;
96
+ }
97
+
98
+ $cli_active = false;
99
+ if ( function_exists( 'media_from_ftp_add_on_cli_load_textdomain' ) ) {
100
+ $cli_active = true;
101
+ }
102
+
103
+ $this->is_add_on_activate = array(
104
+ 'exif' => $exif_active,
105
+ 'cli' => $cli_active,
106
+ );
107
+
108
+ }
109
+
110
+ /** ==================================================
111
+ * Scan file
112
+ *
113
+ * @param string $dir dir.
114
+ * @param string $extpattern extpattern.
115
+ * @param array $mediafromftp_settings mediafromftp_settings.
116
+ * @return array $list
117
+ * @since 1.0
118
+ */
119
+ public function scan_file( $dir, $extpattern, $mediafromftp_settings ) {
120
+
121
+ /* for media-from-ftp-add-on-wpcron and mediafromftpcmd.php */
122
+ $cmdoptions = array();
123
+ if ( $this->is_add_on_activate['cli'] ) {
124
+ $cmdoptions = getopt( 's:d:a:e:t:x:p:f:c:i:b:r:y:hgmo' );
125
+ }
126
+
127
+ if ( isset( $cmdoptions['f'] ) ) {
128
+ $search_limit_number = $cmdoptions['f'];
129
+ } else {
130
+ $search_limit_number = $mediafromftp_settings['search_limit_number'];
131
+ }
132
+
133
+ $thumb_deep_search = false;
134
+ if ( isset( $cmdoptions['m'] ) ) {
135
+ $thumb_deep_search = true;
136
+ } else {
137
+ $thumb_deep_search = $mediafromftp_settings['thumb_deep_search'];
138
+ }
139
+ if ( $thumb_deep_search ) {
140
+ $excludefile = 'media-from-ftp-tmp'; /* tmp dir file */
141
+ } else {
142
+ $excludefile = '-[0-9]+x[0-9]+\.|media-from-ftp-tmp'; /* thumbnail & tmp dir file */
143
+ }
144
+
145
+ $recursive_search = true;
146
+ if ( isset( $cmdoptions['o'] ) ) {
147
+ $recursive_search = false;
148
+ } else {
149
+ $recursive_search = $mediafromftp_settings['recursive_search'];
150
+ }
151
+
152
+ global $blog_id;
153
+ if ( is_multisite() && is_main_site( $blog_id ) ) {
154
+ $excludefile .= '|\/sites\/';
155
+ }
156
+ if ( isset( $cmdoptions['e'] ) ) {
157
+ $excludefile .= '|' . $cmdoptions['e'];
158
+ } else {
159
+ if ( ! empty( $mediafromftp_settings['exclude'] ) ) {
160
+ $excludefile .= '|' . $mediafromftp_settings['exclude'];
161
+ }
162
+ }
163
+
164
+ $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
165
+ if ( isset( $cmdoptions['t'] ) ) {
166
+ $ext2typefilter = $cmdoptions['t'];
167
+ } else {
168
+ if ( isset( $_POST['ext2type'] ) && ! empty( $_POST['ext2type'] ) ) {
169
+ if ( check_admin_referer( 'mff_search', 'media_from_ftp_search' ) ) {
170
+ $ext2typefilter = sanitize_text_field( wp_unslash( $_POST['ext2type'] ) );
171
+ }
172
+ }
173
+ }
174
+
175
+ unset( $cmdoptions );
176
+
177
+ $searchtext = '.*';
178
+ if ( isset( $_POST['searchtext'] ) && ! empty( $_POST['searchtext'] ) ) {
179
+ if ( check_admin_referer( 'mff_search', 'media_from_ftp_search' ) ) {
180
+ $searchtext = $this->mb_encode_multibyte( sanitize_text_field( wp_unslash( $_POST['searchtext'] ) ), $mediafromftp_settings['character_code'] );
181
+ }
182
+ } elseif ( isset( $_GET['searchtext'] ) && ! empty( $_GET['searchtext'] ) ) {
183
+ if ( check_admin_referer( 'mff_search', 'media_from_ftp_search' ) ) {
184
+ $searchtext = $this->mb_encode_multibyte( sanitize_text_field( wp_unslash( $_GET['searchtext'] ) ), $mediafromftp_settings['character_code'] );
185
+ }
186
+ }
187
+
188
+ $files = scandir( $dir );
189
+ $list = array();
190
+ $count = 0;
191
+ foreach ( $files as $file ) {
192
+ if ( '.' == $file || '..' == $file ) {
193
+ continue;
194
+ }
195
+ $fullpath = rtrim( $dir, '/' ) . '/' . $file;
196
+ if ( is_file( $fullpath ) ) {
197
+ if ( ! preg_match( '/' . $excludefile . '/', $fullpath ) ) {
198
+ $exts = explode( '.', $file );
199
+ $ext = end( $exts );
200
+ $searchflag = @preg_match( '/' . $searchtext . '/', $fullpath );
201
+ if ( ! $searchflag ) {
202
+ /* for "preg_match error: Compilation failed: missing terminating ] for character class" */
203
+ $searchflag = preg_match( '/' . preg_quote( $searchtext, '/' ) . '/', $fullpath );
204
+ }
205
+ if ( $searchflag ) {
206
+ if ( preg_match( '/' . $extpattern . '/', $ext ) ) {
207
+ if ( wp_ext2type( $ext ) === $ext2typefilter || 'all' === $ext2typefilter ) {
208
+ ++$count;
209
+ if ( $count > $search_limit_number ) {
210
+ break;
211
+ }
212
+ $list[] = $fullpath;
213
+ }
214
+ }
215
+ }
216
+ }
217
+ }
218
+ if ( is_dir( $fullpath ) && $recursive_search ) {
219
+ $list = array_merge( $list, $this->scan_file( $fullpath, $extpattern, $mediafromftp_settings ) );
220
+ }
221
+ }
222
+
223
+ return $list;
224
+
225
+ }
226
+
227
+ /** ==================================================
228
+ * Scan directory
229
+ *
230
+ * @param string $dir dir.
231
+ * @return array $dirlist
232
+ * @since 2.1
233
+ */
234
+ private function scan_dir( $dir ) {
235
+
236
+ $excludedir = 'media-from-ftp-tmp'; /* tmp dir */
237
+ global $blog_id;
238
+ if ( is_multisite() && is_main_site( $blog_id ) ) {
239
+ $excludedir .= '|\/sites\/';
240
+ }
241
+
242
+ $files = scandir( $dir );
243
+ $list = array();
244
+ foreach ( $files as $file ) {
245
+ if ( '.' == $file || '..' == $file ) {
246
+ continue;
247
+ }
248
+ $fullpath = rtrim( $dir, '/' ) . '/' . $file;
249
+ if ( is_dir( $fullpath ) ) {
250
+ if ( ! preg_match( '/' . $excludedir . '/', $fullpath ) ) {
251
+ $list[] = $fullpath;
252
+ }
253
+ $list = array_merge( $list, $this->scan_dir( $fullpath ) );
254
+ }
255
+ }
256
+
257
+ arsort( $list );
258
+ return $list;
259
+
260
+ }
261
+
262
+ /** ==================================================
263
+ * Extention filter
264
+ *
265
+ * @param string $extfilter extfilter.
266
+ * @return string $extpattern
267
+ * @since 2.2
268
+ */
269
+ public function extpattern( $extfilter ) {
270
+
271
+ $extpattern = null;
272
+
273
+ if ( 'all' === $extfilter ) {
274
+ global $user_ID;
275
+ $mimes = get_allowed_mime_types( $user_ID );
276
+ foreach ( $mimes as $ext => $mime ) {
277
+ $extpattern .= $ext . '|' . strtoupper( $ext ) . '|';
278
+ }
279
+ $extpattern = substr( $extpattern, 0, -1 );
280
+ } else {
281
+ $extpattern = $extfilter . '|' . strtoupper( $extfilter );
282
+ }
283
+
284
+ return $extpattern;
285
+
286
+ }
287
+
288
+ /** ==================================================
289
+ * Mime type
290
+ *
291
+ * @param string $suffix suffix.
292
+ * @return string $mimetype
293
+ * @since 1.0
294
+ */
295
+ private function mime_type( $suffix ) {
296
+
297
+ $suffix = str_replace( '.', '', $suffix );
298
+
299
+ global $user_ID;
300
+ $mimes = get_allowed_mime_types( $user_ID );
301
+
302
+ foreach ( $mimes as $ext => $mime ) {
303
+ if ( preg_match( '/' . $ext . '/i', $suffix ) ) {
304
+ $mimetype = $mime;
305
+ }
306
+ }
307
+
308
+ return $mimetype;
309
+
310
+ }
311
+
312
+ /** ==================================================
313
+ * Create cache
314
+ *
315
+ * @param string $ext ext.
316
+ * @param string $file file.
317
+ * @param string $new_url new_url.
318
+ * @return string $view_thumb_url
319
+ * @since 2.36
320
+ */
321
+ private function create_cash( $ext, $file, $new_url ) {
322
+
323
+ $cash_thumb_key = md5( $new_url );
324
+
325
+ $ext = strtolower( $ext );
326
+
327
+ if ( 'pdf' === $ext ) {
328
+ $cash_thumb_filename = $this->plugin_tmp_dir . '/' . $cash_thumb_key . '-pdf.jpg';
329
+ } else {
330
+ $cash_thumb_filename = $this->plugin_tmp_dir . '/' . $cash_thumb_key . '.' . $ext;
331
+ }
332
+
333
+ $value_cash = get_transient( $cash_thumb_key );
334
+ if ( false <> $value_cash ) {
335
+ if ( ! file_exists( $cash_thumb_filename ) ) {
336
+ delete_transient( $cash_thumb_key );
337
+ $value_cash = false;
338
+ }
339
+ }
340
+ if ( ! $value_cash ) {
341
+ $filetype2 = wp_ext2type( $ext );
342
+ if ( empty( $filetype2 ) ) {
343
+ $filetype2 = 'default';
344
+ }
345
+ if ( ! file_exists( $cash_thumb_filename ) ) {
346
+ $cash_thumb = wp_get_image_editor( $file );
347
+ if ( ! is_wp_error( $cash_thumb ) ) {
348
+ if ( 'pdf' === $ext ) {
349
+ $cash_thumb->generate_filename( 'image', null, 'jpg' );
350
+ $cash_thumb->save( $cash_thumb_filename );
351
+ $cash_thumb2 = wp_get_image_editor( $cash_thumb_filename );
352
+ if ( ! is_wp_error( $cash_thumb2 ) ) {
353
+ $cash_thumb2->resize( 40, 40, true );
354
+ $cash_thumb2->save( $cash_thumb_filename );
355
+ $view_thumb_url = $this->plugin_tmp_url . '/' . $cash_thumb_key . '-pdf.jpg';
356
+ } else {
357
+ $view_thumb_url = $this->siteurl() . '/' . WPINC . '/images/media/' . $filetype2 . '.png';
358
+ }
359
+ } else {
360
+ $cash_thumb->resize( 40, 40, true );
361
+ $cash_thumb->save( $cash_thumb_filename );
362
+ $view_thumb_url = $this->plugin_tmp_url . '/' . $cash_thumb_key . '.' . $ext;
363
+ }
364
+ } else {
365
+ $view_thumb_url = $this->siteurl() . '/' . WPINC . '/images/media/' . $filetype2 . '.png';
366
+ }
367
+ } else {
368
+ if ( file_exists( $cash_thumb_filename ) ) {
369
+ $view_thumb_url = $this->plugin_tmp_url . '/' . $cash_thumb_key . '.' . $ext;
370
+ } else {
371
+ $view_thumb_url = $this->siteurl() . '/' . WPINC . '/images/media/' . $filetype2 . '.png';
372
+ }
373
+ }
374
+ set_transient( $cash_thumb_key, $view_thumb_url, DAY_IN_SECONDS );
375
+ } else {
376
+ $view_thumb_url = $value_cash;
377
+ set_transient( $cash_thumb_key, $value_cash, DAY_IN_SECONDS );
378
+ }
379
+
380
+ return $view_thumb_url;
381
+
382
+ }
383
+
384
+ /** ==================================================
385
+ * Delete cache
386
+ *
387
+ * @param string $ext ext.
388
+ * @param string $new_url_attach new_url_attach.
389
+ * @since 2.36
390
+ */
391
+ public function delete_cash( $ext, $new_url_attach ) {
392
+
393
+ $ext = strtolower( $ext );
394
+
395
+ if ( 'image' === wp_ext2type( $ext ) || 'pdf' === $ext ) {
396
+ $del_cash_thumb_key = md5( $new_url_attach );
397
+ if ( 'pdf' === strtolower( $ext ) ) {
398
+ $del_cash_thumb_filename = $this->plugin_tmp_dir . '/' . $del_cash_thumb_key . '-pdf.jpg';
399
+ } else {
400
+ $del_cash_thumb_filename = $this->plugin_tmp_dir . '/' . $del_cash_thumb_key . '.' . $ext;
401
+ }
402
+ $value_del_cash = get_transient( $del_cash_thumb_key );
403
+ if ( false <> $value_del_cash ) {
404
+ delete_transient( $del_cash_thumb_key );
405
+ if ( file_exists( $del_cash_thumb_filename ) ) {
406
+ unlink( $del_cash_thumb_filename );
407
+ }
408
+ }
409
+ }
410
+
411
+ }
412
+
413
+ /** ==================================================
414
+ * Delete all cache
415
+ *
416
+ * @return int $del_cash_count(int)
417
+ * @since 7.5
418
+ */
419
+ public function delete_all_cash() {
420
+
421
+ global $wpdb;
422
+ $del_transients = $wpdb->get_results(
423
+ $wpdb->prepare(
424
+ "
425
+ SELECT option_value
426
+ FROM $wpdb->options
427
+ WHERE option_value LIKE %s
428
+ ",
429
+ '%' . $wpdb->esc_like( $this->plugin_tmp_url ) . '%'
430
+ )
431
+ );
432
+
433
+ $del_cash_count = 0;
434
+ foreach ( $del_transients as $del_transient ) {
435
+ $delfile = pathinfo( $del_transient->option_value );
436
+ $del_cash_thumb_key = $delfile['filename'];
437
+ $value_del_cash = get_transient( $del_cash_thumb_key );
438
+ if ( false <> $value_del_cash ) {
439
+ delete_transient( $del_cash_thumb_key );
440
+ ++$del_cash_count;
441
+ }
442
+ }
443
+
444
+ $del_cash_thumb_filename = $this->plugin_tmp_dir . '/*.*';
445
+ foreach ( glob( $del_cash_thumb_filename ) as $val ) {
446
+ unlink( $val );
447
+ ++$del_cash_count;
448
+ }
449
+
450
+ return $del_cash_count;
451
+
452
+ }
453
+
454
+ /** ==================================================
455
+ * Date check for exif
456
+ *
457
+ * @param string $file file.
458
+ * @param string $dateset dateset.
459
+ * @return string $date
460
+ * @since 2.36
461
+ */
462
+ public function get_date_check( $file, $dateset ) {
463
+
464
+ $date = get_date_from_gmt( date( 'Y-m-d H:i:s', filemtime( $file ) ) );
465
+
466
+ if ( 'exif' === $dateset ) {
467
+ $exifdata = @exif_read_data( $file, FILE, true );
468
+ if ( isset( $exifdata['EXIF']['DateTimeOriginal'] ) && ! empty( $exifdata['EXIF']['DateTimeOriginal'] ) ) {
469
+ $shooting_date_time = $exifdata['EXIF']['DateTimeOriginal'];
470
+ $shooting_date = str_replace( ':', '-', substr( $shooting_date_time, 0, 10 ) );
471
+ $shooting_time = substr( $shooting_date_time, 10 );
472
+ $date = $shooting_date . $shooting_time;
473
+ }
474
+ }
475
+
476
+ $date = substr( $date, 0, strlen( $date ) - 3 );
477
+
478
+ return $date;
479
+
480
+ }
481
+
482
+ /** ==================================================
483
+ * Input url
484
+ *
485
+ * @param string $file file.
486
+ * @param array $attachments attachments.
487
+ * @param string $character_code character_code.
488
+ * @param bool $thumb_deep_search thumb_deep_search.
489
+ * @return array $new_file(bool), $ext(string), $new_url(string)
490
+ * @since 2.36
491
+ */
492
+ public function input_url( $file, $attachments, $character_code, $thumb_deep_search ) {
493
+
494
+ $ext = null;
495
+ $new_url = null;
496
+
497
+ if ( is_dir( $file ) ) { /* dirctory */
498
+ $new_file = false;
499
+ } else {
500
+ $exts = explode( '.', wp_basename( $file ) );
501
+ $ext = end( $exts );
502
+ $suffix_file = '.' . $ext;
503
+ $file = wp_normalize_path( $file );
504
+ $upload_path = wp_normalize_path( $this->upload_dir );
505
+ $new_url = $this->upload_url . str_replace( $upload_path, '', $file );
506
+ $new_titles = explode( '/', $new_url );
507
+ $new_title = str_replace( $suffix_file, '', end( $new_titles ) );
508
+ $new_title_md5 = md5( $new_title );
509
+ $new_url_md5 = str_replace( $new_title . $suffix_file, '', $new_url ) . $new_title_md5 . $suffix_file;
510
+ $new_file = true;
511
+ $new_url = $this->mb_utf8( $new_url, $character_code );
512
+ foreach ( $attachments as $attachment ) {
513
+ $attach_url = $this->upload_url . '/' . get_post_meta( $attachment->ID, '_wp_attached_file', true );
514
+ $pdf_thumb_url = rtrim( $attach_url, '.pdf' ) . '-pdf.jpg'; /* for pdf thumbnail by imagick */
515
+ if ( $attach_url === $new_url || $attach_url === $new_url_md5 || $pdf_thumb_url === $new_url || $pdf_thumb_url === $new_url_md5 ) {
516
+ $new_file = false;
517
+ } else {
518
+ if ( $thumb_deep_search ) {
519
+ $exts_attach_url = explode( '.', wp_basename( $attach_url ) );
520
+ $delete_ext = '.' . end( $exts_attach_url );
521
+ $attach_url_base = rtrim( $attach_url, $delete_ext );
522
+ if ( strstr( $new_url, $attach_url_base ) || strstr( $new_url_md5, $attach_url_base ) ) {
523
+ $thumb_pattern = '-[0-9]+x[0-9]+\.';
524
+ if ( preg_match( '/' . $thumb_pattern . '/', $new_url ) || preg_match( '/' . $thumb_pattern . '/', $new_url_md5 ) ) {
525
+ $new_file = false;
526
+ }
527
+ }
528
+ }
529
+ }
530
+ }
531
+ }
532
+
533
+ return array( $new_file, $ext, $new_url );
534
+
535
+ }
536
+
537
+ /** ==================================================
538
+ * Input html
539
+ *
540
+ * @param string $ext ext.
541
+ * @param string $file file.
542
+ * @param string $new_url new_url.
543
+ * @param string $postcount postcount.
544
+ * @param array $mediafromftp_settings mediafromftp_settings.
545
+ * @return array $input_html(string), $date_time_html(string)
546
+ * @since 9.30
547
+ */
548
+ public function input_html( $ext, $file, $new_url, $postcount, $mediafromftp_settings ) {
549
+
550
+ $input_html = null;
551
+
552
+ if ( $mediafromftp_settings['search_display_metadata'] ) {
553
+ $file_size = size_format( filesize( $file ) );
554
+ $mimetype = $ext . '(' . $this->mime_type( $ext ) . ')';
555
+ if ( 'image' === wp_ext2type( $ext ) || 'pdf' === strtolower( $ext ) ) {
556
+ $view_thumb_url = $this->create_cash( $ext, $file, $new_url );
557
+ } else if ( 'audio' === wp_ext2type( $ext ) ) {
558
+ $view_thumb_url = $this->siteurl() . '/' . WPINC . '/images/media/audio.png';
559
+ $metadata_audio = wp_read_audio_metadata( $file );
560
+ $file_size = size_format( $metadata_audio['filesize'] );
561
+ $mimetype = $metadata_audio['fileformat'] . '(' . $metadata_audio['mime_type'] . ')';
562
+ $length = $metadata_audio['length_formatted'];
563
+ } else if ( 'video' === wp_ext2type( $ext ) ) {
564
+ $view_thumb_url = $this->siteurl() . '/' . WPINC . '/images/media/video.png';
565
+ $metadata_video = wp_read_video_metadata( $file );
566
+ $file_size = size_format( $metadata_video['filesize'] );
567
+ $mimetype = $metadata_video['fileformat'] . '(' . $metadata_video['mime_type'] . ')';
568
+ $length = $metadata_video['length_formatted'];
569
+ } else {
570
+ $filetype2 = wp_ext2type( $ext );
571
+ if ( empty( $filetype2 ) ) {
572
+ $filetype2 = 'default'; }
573
+ $view_thumb_url = $this->siteurl() . '/' . WPINC . '/images/media/' . $filetype2 . '.png';
574
+ }
575
+ $input_html .= '<img width="40" height="40" src="' . $view_thumb_url . '" style="float: left; margin: 5px;">';
576
+ }
577
+
578
+ $input_html .= '<div style="overflow: hidden;">';
579
+ $input_html .= '<div><a href="' . $new_url . '" target="_blank" style="text-decoration: none; word-break: break-all;">' . $new_url . '</a></div>';
580
+
581
+ if ( $mediafromftp_settings['search_display_metadata'] ) {
582
+ $input_html .= '<div>' . __( 'File type:' ) . ' ' . $mimetype . '</div>';
583
+ $input_html .= '<div>' . __( 'File size:' ) . ' ' . $file_size . '</div>';
584
+ if ( 'audio' === wp_ext2type( $ext ) || 'video' === wp_ext2type( $ext ) ) {
585
+ $input_html .= '<div>' . __( 'Length:' ) . ' ' . $length . '</div>';
586
+ }
587
+ }
588
+ $input_html .= '</div>';
589
+
590
+ $date_time_html = null;
591
+ $date = $this->get_date_check( $file, $mediafromftp_settings['dateset'] );
592
+ if ( 'new' === $mediafromftp_settings['dateset'] || 'fixed' === $mediafromftp_settings['dateset'] ) {
593
+ $input_html .= '<input type="hidden" name="new_url_attaches[' . $postcount . '][datetime]" value="' . $date . '" form="mediafromftp_ajax_update" >';
594
+ } else {
595
+ $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;">';
596
+ }
597
+
598
+ return array( $input_html, $date_time_html );
599
+
600
+ }
601
+
602
+ /** ==================================================
603
+ * Search Option html
604
+ *
605
+ * @param array $mediafromftp_settings mediafromftp_settings.
606
+ * @return string $html
607
+ * @since 9.98
608
+ */
609
+ public function search_option_html( $mediafromftp_settings ) {
610
+
611
+ $html = '<div class="item-mediafromftp-settings">';
612
+ $html .= '<h3>' . __( 'Pagination' ) . '</h3>';
613
+ $html .= '<label>' . __( 'Number of items per page:' ) . '</label>';
614
+ $html .= '<input type="number" step="1" min="1" max="999" class="screen-per-page" name="mediafromftp_pagemax" maxlength="3" value="' . $mediafromftp_settings['pagemax'] . '">';
615
+ $html .= '</div>';
616
+
617
+ $html .= '<div class="item-mediafromftp-settings">';
618
+ $html .= '<h3>' . __( 'Display of search results', 'media-from-ftp' ) . '</h3>';
619
+ $html .= '<div style="display: block;padding:5px 5px">';
620
+ if ( true == $mediafromftp_settings['search_display_metadata'] ) {
621
+ $html .= '<input type="radio" name="search_display_metadata" value="1" checked>';
622
+ } else {
623
+ $html .= '<input type="radio" name="search_display_metadata" value="1">';
624
+ }
625
+ $html .= __( 'Usual selection. It is user-friendly. It displays a thumbnail and metadata. It is low speed.', 'media-from-ftp' );
626
+ $html .= '</div>';
627
+ $html .= '<div style="display: block;padding:5px 5px">';
628
+ if ( false == $mediafromftp_settings['search_display_metadata'] ) {
629
+ $html .= '<input type="radio" name="search_display_metadata" value="0" checked>';
630
+ } else {
631
+ $html .= '<input type="radio" name="search_display_metadata" value="0">';
632
+ }
633
+ $html .= __( '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' );
634
+ $html .= '</div>';
635
+ $html .= '</div>';
636
+
637
+ $html .= '<div class="item-mediafromftp-settings">';
638
+ $html .= '<h3>' . __( 'Exclude file', 'media-from-ftp' ) . '</h3>';
639
+ $html .= '<div style="display: block;padding:5px 5px">';
640
+ $html .= '<div>' . __( 'Regular expression is possible.', 'media-from-ftp' ) . '</div>';
641
+ $html .= '<textarea id="mediafromftp_exclude" name="mediafromftp_exclude" rows="3" style="width: 100%;">' . $mediafromftp_settings['exclude'] . '</textarea>';
642
+ $html .= '</div>';
643
+ $html .= '</div>';
644
+
645
+ $html .= '<div class="item-mediafromftp-settings">';
646
+ $html .= '<h3>' . __( 'Search method of files', 'media-from-ftp' ) . '</h3>';
647
+ $html .= '<div style="display: block;padding:5px 5px">';
648
+ if ( true == $mediafromftp_settings['recursive_search'] ) {
649
+ $html .= '<input type="radio" name="mediafromftp_recursive_search" value="1" checked>';
650
+ } else {
651
+ $html .= '<input type="radio" name="mediafromftp_recursive_search" value="1">';
652
+ }
653
+ $html .= __( 'Recursively search files below specified directory.', 'media-from-ftp' );
654
+ $html .= '</div>';
655
+ $html .= '<div style="display: block;padding:5px 5px">';
656
+ if ( false == $mediafromftp_settings['recursive_search'] ) {
657
+ $html .= '<input type="radio" name="mediafromftp_recursive_search" value="0" checked>';
658
+ } else {
659
+ $html .= '<input type="radio" name="mediafromftp_recursive_search" value="0">';
660
+ }
661
+ $html .= __( 'Search files only for specified directories.', 'media-from-ftp' );
662
+ $html .= '</div>';
663
+ $html .= '</div>';
664
+
665
+ $html .= '<div class="item-mediafromftp-settings">';
666
+ $html .= '<h3>' . __( 'Search method for the exclusion of the thumbnail', 'media-from-ftp' ) . '</h3>';
667
+ $html .= '<div style="display: block;padding:5px 5px">';
668
+ if ( false == $mediafromftp_settings['thumb_deep_search'] ) {
669
+ $html .= '<input type="radio" name="mediafromftp_thumb_deep_search" value="0" checked>';
670
+ } else {
671
+ $html .= '<input type="radio" name="mediafromftp_thumb_deep_search" value="0">';
672
+ }
673
+ $html .= __( 'Usual selection. It is hi speed.', 'media-from-ftp' );
674
+ $html .= '</div>';
675
+ $html .= '<div style="display: block;padding:5px 5px">';
676
+ if ( true == $mediafromftp_settings['thumb_deep_search'] ) {
677
+ $html .= '<input type="radio" name="mediafromftp_thumb_deep_search" value="1" checked>';
678
+ } else {
679
+ $html .= '<input type="radio" name="mediafromftp_thumb_deep_search" value="1">';
680
+ }
681
+ $html .= __( 'Unusual selection. if you want to search for filename that contains such -0x0. It is low speed.', 'media-from-ftp' );
682
+ $html .= '</div>';
683
+ $html .= '</div>';
684
+
685
+ return $html;
686
+
687
+ }
688
+
689
+ /** ==================================================
690
+ * Directory select box
691
+ *
692
+ * @param string $searchdir searchdir.
693
+ * @param string $character_code character_code.
694
+ * @param string $wordpress_path wordpress_path.
695
+ * @return string $linkselectbox
696
+ * @since 9.98
697
+ */
698
+ public function dir_select_box( $searchdir, $character_code, $wordpress_path ) {
699
+
700
+ $linkselectbox = null;
701
+ $linkselectbox .= '<div style="font-size: small; font-weight: bold;"><code>' . $wordpress_path . '</code></div>';
702
+ $linkselectbox .= '<select name="searchdir" style="width: 250px">';
703
+
704
+ $dirs = $this->scan_dir( $this->upload_dir );
705
+ foreach ( $dirs as $linkdir ) {
706
+ if ( strstr( $linkdir, $wordpress_path ) ) {
707
+ $linkdirenc = $this->mb_utf8( str_replace( $wordpress_path, '', $linkdir ), $character_code );
708
+ } else {
709
+ $linkdirenc = $this->upload_path . $this->mb_utf8( str_replace( $this->upload_dir, '', $linkdir ), $character_code );
710
+ }
711
+ if ( $searchdir === $linkdirenc ) {
712
+ $linkdirs = '<option value="' . urlencode( $linkdirenc ) . '" selected>' . $linkdirenc . '</option>';
713
+ } else {
714
+ $linkdirs = '<option value="' . urlencode( $linkdirenc ) . '">' . $linkdirenc . '</option>';
715
+ }
716
+ $linkselectbox = $linkselectbox . $linkdirs;
717
+ }
718
+ if ( $searchdir === $this->upload_path ) {
719
+ $linkdirs = '<option value="' . urlencode( $this->upload_path ) . '" selected>' . $this->upload_path . '</option>';
720
+ } else {
721
+ $linkdirs = '<option value="' . urlencode( $this->upload_path ) . '">' . $this->upload_path . '</option>';
722
+ }
723
+ $linkselectbox = $linkselectbox . $linkdirs . '</select>';
724
+
725
+ return $linkselectbox;
726
+
727
+ }
728
+
729
+ /** ==================================================
730
+ * Type select box
731
+ *
732
+ * @param string $ext2typefilter ext2typefilter.
733
+ * @param string $extfilter extfilter.
734
+ * @return string $typeextselectbox
735
+ * @since 10.01
736
+ */
737
+ public function type_ext_select_box( $ext2typefilter, $extfilter ) {
738
+
739
+ $typeextselectbox = null;
740
+ $typeextselectbox .= '<select name="ext2type" style="width: 110px;">';
741
+ $typeextselectbox .= '<option value="all"';
742
+ if ( 'all' === $ext2typefilter ) {
743
+ $typeextselectbox .= ' selected';
744
+ }
745
+ $typeextselectbox .= '>' . esc_attr( __( 'All types', 'media-from-ftp' ) ) . '</option>';
746
+ $typeextselectbox .= '<option value="image"';
747
+ if ( 'image' === $ext2typefilter ) {
748
+ $typeextselectbox .= ' selected';
749
+ }
750
+ $typeextselectbox .= '>image</option>';
751
+ $typeextselectbox .= '<option value="audio"';
752
+ if ( 'audio' === $ext2typefilter ) {
753
+ $typeextselectbox .= ' selected';
754
+ }
755
+ $typeextselectbox .= '>audio</option>';
756
+ $typeextselectbox .= '<option value="video"';
757
+ if ( 'video' === $ext2typefilter ) {
758
+ $typeextselectbox .= ' selected';
759
+ }
760
+ $typeextselectbox .= '>video</option>';
761
+ $typeextselectbox .= '<option value="document"';
762
+ if ( 'document' === $ext2typefilter ) {
763
+ $typeextselectbox .= ' selected';
764
+ }
765
+ $typeextselectbox .= '>document</option>';
766
+ $typeextselectbox .= '<option value="spreadsheet"';
767
+ if ( 'spreadsheet' === $ext2typefilter ) {
768
+ $typeextselectbox .= ' selected';
769
+ }
770
+ $typeextselectbox .= '>spreadsheet</option>';
771
+ $typeextselectbox .= '<option value="interactive"';
772
+ if ( 'interactive' === $ext2typefilter ) {
773
+ $typeextselectbox .= ' selected';
774
+ }
775
+ $typeextselectbox .= '>interactive</option>';
776
+ $typeextselectbox .= '<option value="text"';
777
+ if ( 'text' === $ext2typefilter ) {
778
+ $typeextselectbox .= ' selected';
779
+ }
780
+ $typeextselectbox .= '>text</option>';
781
+ $typeextselectbox .= '<option value="archive"';
782
+ if ( 'archive' === $ext2typefilter ) {
783
+ $typeextselectbox .= ' selected';
784
+ }
785
+ $typeextselectbox .= '>archive</option>';
786
+ $typeextselectbox .= '<option value="code"';
787
+ if ( 'code' === $ext2typefilter ) {
788
+ $typeextselectbox .= ' selected';
789
+ }
790
+ $typeextselectbox .= '>code</option>';
791
+ $typeextselectbox .= '</select>';
792
+ $typeextselectbox .= '<select name="extension" style="width: 120px;">';
793
+ $typeextselectbox .= '<option value="all"';
794
+ if ( 'all' === $extfilter ) {
795
+ $typeextselectbox .= ' selected';
796
+ }
797
+ $typeextselectbox .= '>' . esc_attr( __( 'All extensions', 'media-from-ftp' ) ) . '</option>';
798
+
799
+ $extensions = $this->scan_extensions( $ext2typefilter );
800
+ foreach ( $extensions as $extselect ) {
801
+ $typeextselectbox .= '<option value="' . $extselect . '"';
802
+ if ( $extfilter === $extselect ) {
803
+ $typeextselectbox .= ' selected';
804
+ }
805
+ $typeextselectbox .= '>' . $extselect . '</option>';
806
+ }
807
+ $typeextselectbox .= '</select>';
808
+
809
+ return $typeextselectbox;
810
+
811
+ }
812
+
813
+ /** ==================================================
814
+ * Form html
815
+ *
816
+ * @param array $mediafromftp_settings mediafromftp_settings.
817
+ * @since 9.50
818
+ */
819
+ public function form_html( $mediafromftp_settings ) {
820
+
821
+ $scriptname = admin_url( 'admin.php?page=mediafromftp-search-register' );
822
+
823
+ $searchtext = null;
824
+ if ( isset( $_POST['searchtext'] ) && ! empty( $_POST['searchtext'] ) ) {
825
+ if ( check_admin_referer( 'mff_search', 'media_from_ftp_search' ) ) {
826
+ $searchtext = sanitize_text_field( wp_unslash( $_POST['searchtext'] ) );
827
+ }
828
+ } elseif ( isset( $_GET['searchtext'] ) && ! empty( $_GET['searchtext'] ) ) {
829
+ if ( check_admin_referer( 'mff_search', 'media_from_ftp_search' ) ) {
830
+ $searchtext = sanitize_text_field( wp_unslash( $_GET['searchtext'] ) );
831
+ }
832
+ }
833
+
834
+ $pagemax = $mediafromftp_settings['pagemax'];
835
+ $searchdir = $mediafromftp_settings['searchdir'];
836
+ $character_code = $mediafromftp_settings['character_code'];
837
+ $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
838
+ $extfilter = $mediafromftp_settings['extfilter'];
839
+ $wordpress_path = wp_normalize_path( ABSPATH );
840
+
841
+ $linkselectbox = $this->dir_select_box( $searchdir, $character_code, $wordpress_path );
842
+ $linkselectbox2 = $this->type_ext_select_box( $ext2typefilter, $extfilter );
843
+
844
+ $allowed_select_html = array(
845
+ 'div' => array(
846
+ 'style' => array(),
847
+ ),
848
+ 'code' => array(),
849
+ 'select' => array(
850
+ 'name' => array(),
851
+ 'style' => array(),
852
+ ),
853
+ 'option' => array(
854
+ 'value' => array(),
855
+ 'selected' => array(),
856
+ ),
857
+ );
858
+ ?>
859
+ <div class="wp-filter" style="margin: 0px;"> <!-- wp-admin/css/list-tables.css -->
860
+ <form method="post" action="<?php echo esc_url( $scriptname ); ?>">
861
+ <?php wp_nonce_field( 'mff_search', 'media_from_ftp_search' ); ?>
862
+ <?php echo wp_kses( $linkselectbox, $allowed_select_html ); ?>
863
+ <?php submit_button( __( 'Search' ), 'large', '', false ); ?>
864
+ <span style="margin-right: 1em;"></span>
865
+ <?php echo wp_kses( $linkselectbox2, $allowed_select_html ); ?>
866
+ <?php
867
+ if ( empty( $searchtext ) ) {
868
+ ?>
869
+ <input name="searchtext" type="text" value="" placeholder="<?php echo esc_attr__( 'Search' ); ?>">
870
+ <?php
871
+ } else {
872
+ ?>
873
+ <input name="searchtext" type="text" value="" placeholder="<?php echo esc_attr( $searchtext ); ?>">
874
+ <?php
875
+ }
876
+ submit_button( __( 'Filter' ), 'large', '', false );
877
+ ?>
878
+ </form>
879
+ </div>
880
+ <?php
881
+
882
+ }
883
+
884
+ /** ==================================================
885
+ * Regist
886
+ *
887
+ * @param string $filename filename.
888
+ * @param string $ext ext.
889
+ * @param string $new_url_attach .
890
+ * @param string $new_url_datetime .
891
+ * @param string $dateset dateset.
892
+ * @param string $datefixed datefixed.
893
+ * @param bool $yearmonth_folders yearmonth_folders.
894
+ * @param string $character_code character_code.
895
+ * @param string $cron_user cron_user.
896
+ * @return array $attach_id(int), $new_attach_title(string), $new_url_attach(string), $metadata(array)
897
+ * @since 2.36
898
+ */
899
+ public function regist( $filename, $ext, $new_url_attach, $new_url_datetime, $dateset, $datefixed, $yearmonth_folders, $character_code, $cron_user ) {
900
+
901
+ /* Rename and Move file */
902
+ $suffix_attach_file = '.' . $ext;
903
+ $new_attach_titlenames = explode( '/', $new_url_attach );
904
+ $new_attach_title = str_replace( $suffix_attach_file, '', end( $new_attach_titlenames ) );
905
+ /* for utf8mb4 charcter */
906
+ $new_attach_title = $this->utf8mb4_html_numeric_encode( $new_attach_title, $character_code );
907
+
908
+ $upload_path = wp_normalize_path( $this->upload_dir );
909
+
910
+ $err_copy = true;
911
+ $copy_file_org1 = null;
912
+ $copy_file_org2 = null;
913
+ $copy_file_org3 = null;
914
+ $copy_file_new1 = null;
915
+ $copy_file_new2 = null;
916
+ $copy_file_new3 = null;
917
+ $postdategmt = date_i18n( 'Y-m-d H:i:s', false, true );
918
+ if ( 'server' === $dateset || 'exif' === $dateset ) {
919
+ $postdategmt = get_gmt_from_date( $new_url_datetime . ':00' );
920
+ }
921
+
922
+ $path_parts = pathinfo( $filename );
923
+ $currentdir = $path_parts['dirname'];
924
+
925
+ /* sanitize */
926
+ $orgfilename = $filename;
927
+ $filename = $currentdir . '/' . sanitize_file_name( wp_basename( $filename ) );
928
+ rename( $orgfilename, $filename );
929
+
930
+ if ( function_exists( 'mb_check_encoding' ) ) {
931
+ if ( ! mb_check_encoding( $filename, 'ASCII' ) ) {
932
+ $currentfile = wp_basename( $filename, $suffix_attach_file );
933
+ $oldfilename = $currentdir . '/' . $currentfile . $suffix_attach_file;
934
+ $filename = $currentdir . '/' . md5( $currentfile ) . $suffix_attach_file;
935
+ $copy_file_org2 = $this->mb_encode_multibyte( $oldfilename, $character_code );
936
+ $copy_file_new2 = $this->mb_encode_multibyte( $filename, $character_code );
937
+ $err_copy = @copy( $copy_file_org2, $copy_file_new2 );
938
+ if ( ! $err_copy ) {
939
+ if ( ! empty( $copy_file_new1 ) ) {
940
+ $copy_file_org2 = $copy_file_org1;
941
+ unlink( $copy_file_new1 );
942
+ }
943
+ return array( -1, $this->mb_utf8( $copy_file_org2, $character_code ), $this->mb_utf8( $currentdir, $character_code ), null );
944
+ }
945
+ }
946
+ }
947
+
948
+ /* Move YearMonth Folders */
949
+ if ( 1 == $yearmonth_folders ) {
950
+ $y = substr( $postdategmt, 0, 4 );
951
+ $m = substr( $postdategmt, 5, 2 );
952
+ $subdir = "/$y/$m";
953
+ $filename_base = wp_basename( $filename );
954
+ if ( $filename <> $this->upload_dir . $subdir . '/' . $filename_base ) {
955
+ if ( ! file_exists( $this->mb_encode_multibyte( $this->upload_dir . $subdir, $character_code ) ) ) {
956
+ wp_mkdir_p( $this->mb_encode_multibyte( $this->upload_dir . $subdir, $character_code ) );
957
+ }
958
+ if ( file_exists( $this->mb_encode_multibyte( $this->upload_dir . $subdir . '/' . $filename_base, $character_code ) ) ) {
959
+ $filename_base = wp_basename( $filename, $suffix_attach_file ) . date_i18n( 'dHis', false, false ) . $suffix_attach_file;
960
+ }
961
+ $copy_file_org3 = $this->mb_encode_multibyte( $filename, $character_code );
962
+ $copy_file_new3 = $this->mb_encode_multibyte( $this->upload_dir . $subdir . '/' . $filename_base, $character_code );
963
+ $err_copy = @copy( $copy_file_org3, $copy_file_new3 );
964
+ if ( ! $err_copy ) {
965
+ if ( ! empty( $copy_file_new1 ) ) {
966
+ $copy_file_org3 = $copy_file_org1;
967
+ unlink( $copy_file_new1 );
968
+ } else if ( ! empty( $copy_file_new2 ) ) {
969
+ $copy_file_org3 = $copy_file_org2;
970
+ unlink( $copy_file_new2 );
971
+ }
972
+ return array( -1, $this->mb_utf8( $copy_file_org3, $character_code ), $this->mb_utf8( $this->upload_dir . $subdir, $character_code ), null );
973
+ }
974
+ $filename = $this->upload_dir . $subdir . '/' . $filename_base;
975
+ }
976
+ }
977
+
978
+ $new_url_attach = $this->mb_utf8( $this->upload_url . str_replace( $upload_path, '', $filename ), $character_code );
979
+ $filename = $this->mb_utf8( $filename, $character_code );
980
+
981
+ /* File Regist */
982
+ $newfile_post = array(
983
+ 'post_title' => $new_attach_title,
984
+ 'post_content' => '',
985
+ 'post_author' => $cron_user,
986
+ 'guid' => $new_url_attach,
987
+ 'post_status' => 'inherit',
988
+ 'post_type' => 'attachment',
989
+ 'post_mime_type' => $this->mime_type( $suffix_attach_file ),
990
+ );
991
+ $attach_id = wp_insert_attachment( $newfile_post, $filename );
992
+
993
+ if ( 0 == $attach_id ) { /* error */
994
+ if ( ! empty( $copy_file_new1 ) ) {
995
+ unlink( $copy_file_new1 ); }
996
+ if ( ! empty( $copy_file_new2 ) ) {
997
+ unlink( $copy_file_new2 ); }
998
+ if ( ! empty( $copy_file_new3 ) ) {
999
+ unlink( $copy_file_new3 ); }
1000
+ return array( -2, $new_attach_title, $new_url_attach, null );
1001
+ } else {
1002
+ if ( ! empty( $copy_file_org1 ) ) {
1003
+ unlink( $copy_file_org1 ); }
1004
+ if ( ! empty( $copy_file_org2 ) ) {
1005
+ unlink( $copy_file_org2 ); }
1006
+ if ( ! empty( $copy_file_org3 ) ) {
1007
+ unlink( $copy_file_org3 ); }
1008
+ }
1009
+
1010
+ /* Date Time Regist */
1011
+ if ( 'new' <> $dateset ) {
1012
+ if ( 'fixed' === $dateset ) {
1013
+ $postdategmt = get_gmt_from_date( $datefixed . ':00' );
1014
+ }
1015
+ $postdate = get_date_from_gmt( $postdategmt );
1016
+ $up_post = array(
1017
+ 'ID' => $attach_id,
1018
+ 'post_date' => $postdate,
1019
+ 'post_date_gmt' => $postdategmt,
1020
+ 'post_modified' => $postdate,
1021
+ 'post_modified_gmt' => $postdategmt,
1022
+ );
1023
+ wp_update_post( $up_post );
1024
+ }
1025
+
1026
+ /* for wp_read_audio_metadata and wp_read_video_metadata */
1027
+ include_once( ABSPATH . 'wp-admin/includes/media.php' );
1028
+ /* for wp_generate_attachment_metadata */
1029
+ include_once( ABSPATH . 'wp-admin/includes/image.php' );
1030
+
1031
+ /* Meta data Regist */
1032
+ $metadata = null;
1033
+ $fullpath_filename = $this->mb_encode_multibyte( get_attached_file( $attach_id ), $character_code );
1034
+ if ( 'image' === wp_ext2type( $ext ) || 'pdf' === strtolower( $ext ) ) {
1035
+ $metadata = wp_generate_attachment_metadata( $attach_id, $fullpath_filename );
1036
+ } else if ( 'video' === wp_ext2type( $ext ) ) {
1037
+ $metadata = wp_read_video_metadata( $fullpath_filename );
1038
+ } else if ( 'audio' === wp_ext2type( $ext ) ) {
1039
+ $metadata = wp_read_audio_metadata( $fullpath_filename );
1040
+ }
1041
+ wp_update_attachment_metadata( $attach_id, $metadata );
1042
+
1043
+ return array( $attach_id, $new_attach_title, $new_url_attach, $metadata );
1044
+
1045
+ }
1046
+
1047
+ /** ==================================================
1048
+ * Output metadata
1049
+ *
1050
+ * @param string $ext ext.
1051
+ * @param int $attach_id attach_id.
1052
+ * @param array $metadata metadata.
1053
+ * @param string $character_code character_code.
1054
+ * @param string $exif_text_tag exif_text_tag.
1055
+ * @return array $imagethumburls(string), $mimetype(string), $length(string), $stamptime(string), $file_size(string), $exif_text(string)
1056
+ * @since 7.4
1057
+ */
1058
+ public function output_metadata( $ext, $attach_id, $metadata, $character_code, $exif_text_tag ) {
1059
+
1060
+ $imagethumburls = array();
1061
+ $mimetype = null;
1062
+ $length = null;
1063
+ $exif_text = null;
1064
+ $filetype = wp_check_filetype( $this->mb_encode_multibyte( get_attached_file( $attach_id ), $character_code ) );
1065
+ if ( 'image' === wp_ext2type( $ext ) || 'pdf' === strtolower( $ext ) ) {
1066
+ $wp_attached_file = get_post_meta( $attach_id, '_wp_attached_file', true );
1067
+ $imagethumburl_base = $this->upload_url . '/' . rtrim( $wp_attached_file, wp_basename( $wp_attached_file ) );
1068
+ if ( ! empty( $metadata ) ) {
1069
+ foreach ( $metadata as $key1 => $key2 ) {
1070
+ if ( 'sizes' === $key1 ) {
1071
+ foreach ( $metadata[ $key1 ] as $key2 => $key3 ) {
1072
+ $imagethumburls[ $key2 ] = $imagethumburl_base . $metadata['sizes'][ $key2 ]['file'];
1073
+ }
1074
+ }
1075
+ }
1076
+ }
1077
+ $mimetype = $filetype['ext'] . '(' . $filetype['type'] . ')';
1078
+ } else if ( 'video' === wp_ext2type( $ext ) || 'audio' === wp_ext2type( $ext ) ) {
1079
+ $mimetype = $metadata['fileformat'] . '(' . $metadata['mime_type'] . ')';
1080
+ $length = $metadata['length_formatted'];
1081
+ } else {
1082
+ $metadata = null;
1083
+ $mimetype = $filetype['ext'] . '(' . $filetype['type'] . ')';
1084
+ }
1085
+
1086
+ $stamptime = get_the_time( 'Y-n-j ', $attach_id ) . get_the_time( 'G:i', $attach_id );
1087
+ if ( isset( $metadata['filesize'] ) ) {
1088
+ $file_size = $metadata['filesize'];
1089
+ } else {
1090
+ $file_size = @filesize( $this->mb_encode_multibyte( get_attached_file( $attach_id ), $character_code ) );
1091
+ }
1092
+
1093
+ if ( $this->is_add_on_activate['exif'] ) {
1094
+ if ( 'image/jpeg' === $filetype['type'] || 'image/tiff' === $filetype['type'] ) {
1095
+ if ( ! empty( $exif_text_tag ) ) {
1096
+ include_once $this->plugin_dir . '/media-from-ftp-add-on-exif/inc/MediaFromFtpAddOnExif.php';
1097
+ $mediafromftpaddonexif = new MediaFromFtpAddOnExif();
1098
+ $exif_text = $mediafromftpaddonexif->exifcaption( $attach_id, $metadata, $exif_text_tag );
1099
+ unset( $mediafromftpaddonexif );
1100
+ }
1101
+ }
1102
+ }
1103
+
1104
+ return array( $imagethumburls, $mimetype, $length, $stamptime, $file_size, $exif_text );
1105
+
1106
+ }
1107
+
1108
+ /** ==================================================
1109
+ * Output html and log
1110
+ *
1111
+ * @param string $ext ext.
1112
+ * @param int $attach_id attach_id.
1113
+ * @param string $new_attach_title new_attach_title.
1114
+ * @param string $new_url_attach new_url_attach.
1115
+ * @param array $imagethumburls imagethumburls.
1116
+ * @param string $mimetype mimetype.
1117
+ * @param string $length length.
1118
+ * @param string $stamptime stamptime.
1119
+ * @param string $file_size file_size.
1120
+ * @param string $exif_text exif_text.
1121
+ * @param array $image_attr_thumbnail image_attr_thumbnail.
1122
+ * @param array $mediafromftp_settings mediafromftp_settings.
1123
+ * @param string $cat_html cat_html.
1124
+ * @param string $mlccategory mlccategory.
1125
+ * @param string $emlcategory emlcategory.
1126
+ * @param string $mlacategory mlacategory.
1127
+ * @param string $mlatag mlatag.
1128
+ * @return string $output_html
1129
+ * @since 9.30
1130
+ */
1131
+ public 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 ) {
1132
+
1133
+ $thumbnails = array();
1134
+
1135
+ $output_html = '<div style="border-bottom: 1px solid; padding-top: 5px; padding-bottom: 5px;">';
1136
+ $output_html .= '<img width="40" height="40" src="' . $image_attr_thumbnail[0] . '" style="float: left; margin: 5px;">';
1137
+ $output_html .= '<div style="overflow: hidden;">';
1138
+ $output_html .= '<div>ID: ' . $attach_id . '</div>';
1139
+ $output_html .= '<div>' . __( 'Title' ) . ': ' . $new_attach_title . '</div>';
1140
+ $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>';
1141
+ $output_html .= '<div>URL: <a href="' . $new_url_attach . '" target="_blank" style="text-decoration: none; word-break: break-all;">' . $new_url_attach . '</a></div>';
1142
+ $new_url_attachs = explode( '/', $new_url_attach );
1143
+ $output_html .= '<div>' . __( 'File name:' ) . ' ' . end( $new_url_attachs ) . '</div>';
1144
+
1145
+ $output_html .= '<div>' . __( 'Date/Time' ) . ': ' . $stamptime . '</div>';
1146
+ if ( ! $file_size ) {
1147
+ $file_size = '<font color="red">' . __( 'Could not retrieve.', 'media-from-ftp' ) . '</font>';
1148
+ } else {
1149
+ $file_size = size_format( $file_size );
1150
+ }
1151
+ $output_html .= '<div>' . __( 'File type:' ) . ' ' . $mimetype . '</div>';
1152
+ $output_html .= '<div>' . __( 'File size:' ) . ' ' . $file_size . '</div>';
1153
+ if ( 'image' === wp_ext2type( $ext ) || ( 'pdf' === strtolower( $ext ) && ! empty( $imagethumburls ) ) ) {
1154
+ $output_html .= '<div>' . __( 'Images' ) . ': ';
1155
+ $thumb_count = 0;
1156
+ foreach ( $imagethumburls as $thumbsize => $imagethumburl ) {
1157
+ $output_html .= '[<a href="' . $imagethumburl . '" target="_blank" style="text-decoration: none; word-break: break-all;">' . $thumbsize . '</a>]';
1158
+ ++$thumb_count;
1159
+ $thumbnails[ $thumb_count ] = $imagethumburl;
1160
+ }
1161
+ $output_html .= '</div>';
1162
+ if ( ! empty( $exif_text ) ) {
1163
+ $output_html .= '<div>' . __( 'Caption' ) . '[Exif]: ' . $exif_text . '</div>';
1164
+ }
1165
+ } else {
1166
+ if ( 'video' === wp_ext2type( $ext ) || 'audio' === wp_ext2type( $ext ) ) {
1167
+ $output_html .= '<div>' . __( 'Length:' ) . ' ' . $length . '</div>';
1168
+ }
1169
+ }
1170
+ if ( ! empty( $cat_html ) ) {
1171
+ $output_html .= $cat_html;
1172
+ }
1173
+ $output_html .= '</div></div>';
1174
+
1175
+ if ( $mediafromftp_settings['log'] ) {
1176
+ global $wpdb;
1177
+ $user = wp_get_current_user();
1178
+ $thumbnail = json_encode( $thumbnails );
1179
+ $thumbnail = str_replace( '\\', '', $thumbnail );
1180
+ /* Log */
1181
+ $log_arr = array(
1182
+ 'id' => $attach_id,
1183
+ 'user' => $user->display_name,
1184
+ 'title' => $new_attach_title,
1185
+ 'permalink' => get_attachment_link( $attach_id ),
1186
+ 'url' => $new_url_attach,
1187
+ 'filename' => end( $new_url_attachs ),
1188
+ 'time' => $stamptime,
1189
+ 'filetype' => $mimetype,
1190
+ 'filesize' => $file_size,
1191
+ 'exif' => $exif_text,
1192
+ 'length' => $length,
1193
+ 'thumbnail' => $thumbnail,
1194
+ 'mlccategories' => $mlccategory,
1195
+ 'emlcategories' => $emlcategory,
1196
+ 'mlacategories' => $mlacategory,
1197
+ 'mlatags' => $mlatag,
1198
+ );
1199
+ $table_name = $wpdb->prefix . 'mediafromftp_log';
1200
+ $wpdb->insert( $table_name, $log_arr );
1201
+ $wpdb->show_errors();
1202
+ }
1203
+
1204
+ return $output_html;
1205
+
1206
+ }
1207
+
1208
+ /** ==================================================
1209
+ * Real Url
1210
+ *
1211
+ * @param string $base base.
1212
+ * @param string $relationalpath relationalpath.
1213
+ * @return string $realurl realurl.
1214
+ * @since 7.7
1215
+ */
1216
+ private function realurl( $base, $relationalpath ) {
1217
+
1218
+ $parse = array(
1219
+ 'scheme' => null,
1220
+ 'user' => null,
1221
+ 'pass' => null,
1222
+ 'host' => null,
1223
+ 'port' => null,
1224
+ 'query' => null,
1225
+ 'fragment' => null,
1226
+ );
1227
+ $parse = wp_parse_url( $base );
1228
+
1229
+ if ( strpos( $parse['path'], '/', ( strlen( $parse['path'] ) - 1 ) ) !== false ) {
1230
+ $parse['path'] .= '.';
1231
+ }
1232
+
1233
+ if ( preg_match( '#^https?://#', $relationalpath ) ) {
1234
+ return $relationalpath;
1235
+ } elseif ( preg_match( '#^/.*$#', $relationalpath ) ) {
1236
+ return $parse['scheme'] . '://' . $parse['host'] . $relationalpath;
1237
+ } else {
1238
+ $base_path = explode( '/', dirname( $parse['path'] ) );
1239
+ $rel_path = explode( '/', $relationalpath );
1240
+ foreach ( $rel_path as $rel_dir_name ) {
1241
+ if ( '.' === $rel_dir_name ) {
1242
+ array_shift( $base_path );
1243
+ array_unshift( $base_path, '' );
1244
+ } elseif ( '..' === $rel_dir_name ) {
1245
+ array_pop( $base_path );
1246
+ if ( count( $base_path ) === 0 ) {
1247
+ $base_path = array( '' );
1248
+ }
1249
+ } else {
1250
+ array_push( $base_path, $rel_dir_name );
1251
+ }
1252
+ }
1253
+ $path = implode( '/', $base_path );
1254
+ return $parse['scheme'] . '://' . $parse['host'] . $path;
1255
+ }
1256
+
1257
+ }
1258
+
1259
+ /** ==================================================
1260
+ * Upload Path
1261
+ *
1262
+ * @return array $upload_dir,$upload_url,$upload_path uploadpath.
1263
+ * @since 7.8
1264
+ */
1265
+ public function upload_dir_url_path() {
1266
+
1267
+ $wp_uploads = wp_upload_dir();
1268
+
1269
+ $relation_path_true = strpos( $wp_uploads['baseurl'], '../' );
1270
+ if ( $relation_path_true > 0 ) {
1271
+ $relationalpath = substr( $wp_uploads['baseurl'], $relation_path_true );
1272
+ $basepath = substr( $wp_uploads['baseurl'], 0, $relation_path_true );
1273
+ $upload_url = $this->realurl( $basepath, $relationalpath );
1274
+ $upload_dir = wp_normalize_path( realpath( $wp_uploads['basedir'] ) );
1275
+ } else {
1276
+ $upload_url = $wp_uploads['baseurl'];
1277
+ $upload_dir = wp_normalize_path( $wp_uploads['basedir'] );
1278
+ }
1279
+
1280
+ if ( is_ssl() ) {
1281
+ $upload_url = str_replace( 'http:', 'https:', $upload_url );
1282
+ }
1283
+
1284
+ if ( $relation_path_true > 0 ) {
1285
+ $upload_path = $relationalpath;
1286
+ } else {
1287
+ $upload_path = str_replace( site_url( '/' ), '', $upload_url );
1288
+ }
1289
+
1290
+ $upload_dir = untrailingslashit( $upload_dir );
1291
+ $upload_url = untrailingslashit( $upload_url );
1292
+ $upload_path = untrailingslashit( $upload_path );
1293
+
1294
+ return array( $upload_dir, $upload_url, $upload_path );
1295
+
1296
+ }
1297
+
1298
+ /** ==================================================
1299
+ * Site url
1300
+ *
1301
+ * @return $siteurl
1302
+ * @since 8.5
1303
+ */
1304
+ public function siteurl() {
1305
+ if ( is_multisite() ) {
1306
+ global $blog_id;
1307
+ $siteurl = get_blog_details( $blog_id )->siteurl;
1308
+ } else {
1309
+ $siteurl = site_url();
1310
+ }
1311
+ return $siteurl;
1312
+ }
1313
+
1314
+ /** ==================================================
1315
+ * Scan extensions
1316
+ *
1317
+ * @param string $ext2typefilter ext2typefilter.
1318
+ * @return array $extensions
1319
+ * @since 8.2
1320
+ */
1321
+ private function scan_extensions( $ext2typefilter ) {
1322
+
1323
+ $extensions = array();
1324
+ global $user_ID;
1325
+ $mimes = get_allowed_mime_types( $user_ID );
1326
+
1327
+ foreach ( $mimes as $extselect => $mime ) {
1328
+ if ( strpos( $extselect, '|' ) ) {
1329
+ $extselects = explode( '|', $extselect );
1330
+ foreach ( $extselects as $extselect2 ) {
1331
+ if ( 'all' === $ext2typefilter || wp_ext2type( $extselect2 ) === $ext2typefilter ) {
1332
+ $extensions[] = $extselect2;
1333
+ }
1334
+ }
1335
+ } else {
1336
+ if ( 'all' === $ext2typefilter || wp_ext2type( $extselect ) === $ext2typefilter ) {
1337
+ $extensions[] = $extselect;
1338
+ }
1339
+ }
1340
+ }
1341
+
1342
+ asort( $extensions );
1343
+ return $extensions;
1344
+
1345
+ }
1346
+
1347
+ /** ==================================================
1348
+ * UTF8 mb4
1349
+ *
1350
+ * @param string $str str.
1351
+ * @param string $character_code character_code.
1352
+ * @return string $ret
1353
+ * @since 9.02
1354
+ */
1355
+ private function utf8mb4_html_numeric_encode( $str, $character_code ) {
1356
+
1357
+ if ( function_exists( 'mb_language' ) && 'none' <> $character_code ) {
1358
+ $length = mb_strlen( $str, 'UTF-8' );
1359
+ $ret = '';
1360
+
1361
+ for ( $i = 0; $i < $length; ++$i ) {
1362
+ $buf = mb_substr( $str, $i, 1, 'UTF-8' );
1363
+
1364
+ if ( 4 === mb_strlen( $buf, '8bit' ) ) {
1365
+ $buf = mb_encode_numericentity( $buf, array( 0x10000, 0x10FFFF, 0, 0xFFFFFF ), 'UTF-8' );
1366
+ }
1367
+
1368
+ $ret .= $buf;
1369
+ }
1370
+ } else {
1371
+ $ret = $str;
1372
+ }
1373
+
1374
+ return $ret;
1375
+
1376
+ }
1377
+
1378
+ /** ==================================================
1379
+ * Multibyte init
1380
+ *
1381
+ * @param string $character_code character_code.
1382
+ * @since 9.05
1383
+ */
1384
+ public function mb_initialize( $character_code ) {
1385
+
1386
+ if ( function_exists( 'mb_language' ) && 'none' <> $character_code ) {
1387
+ if ( 'ja' === get_locale() ) {
1388
+ mb_language( 'Japanese' );
1389
+ } else if ( 'en_US' === get_locale() ) {
1390
+ mb_language( 'English' );
1391
+ } else {
1392
+ mb_language( 'uni' );
1393
+ }
1394
+ }
1395
+
1396
+ }
1397
+
1398
+ /** ==================================================
1399
+ * Multibyte encode
1400
+ *
1401
+ * @param string $str str.
1402
+ * @param string $character_code character_code.
1403
+ * @return string $str
1404
+ * @since 9.10
1405
+ */
1406
+ public function mb_encode_multibyte( $str, $character_code ) {
1407
+
1408
+ if ( function_exists( 'mb_language' ) && 'none' <> $character_code ) {
1409
+ $str = mb_convert_encoding( $str, $character_code, 'auto' );
1410
+ }
1411
+
1412
+ return $str;
1413
+
1414
+ }
1415
+
1416
+ /** ==================================================
1417
+ * Multibyte UTF-8
1418
+ *
1419
+ * @param string $str str.
1420
+ * @param string $character_code character_code.
1421
+ * @return string $str
1422
+ * @since 9.05
1423
+ */
1424
+ public function mb_utf8( $str, $character_code ) {
1425
+
1426
+ if ( function_exists( 'mb_convert_encoding' ) && 'none' <> $character_code ) {
1427
+ $str = mb_convert_encoding( $str, 'UTF-8', 'auto' );
1428
+ }
1429
+
1430
+ return $str;
1431
+
1432
+ }
1433
+
1434
+ /** ==================================================
1435
+ * Array replace for php < 5.3.0
1436
+ *
1437
+ * @return array $array
1438
+ * @since 9.11
1439
+ */
1440
+ private function array_replace() {
1441
+
1442
+ $array = array();
1443
+ $n = func_num_args();
1444
+
1445
+ while ( $n-- > 0 ) {
1446
+ $array += func_get_arg( $n );
1447
+ }
1448
+ return $array;
1449
+ }
1450
+
1451
+
1452
+ /** ==================================================
1453
+ * Author select for Media Library Import
1454
+ *
1455
+ * @param string $filename filename.
1456
+ * @return array $authors
1457
+ * @since 9.43
1458
+ */
1459
+ public function author_select( $filename ) {
1460
+
1461
+ $scriptname = admin_url( 'admin.php?page=mediafromftp-import' );
1462
+
1463
+ $s = @file_get_contents( $filename );
1464
+ $control_code = array( "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x0b", "\x0c", "\x0e", "\x0f" );
1465
+ $s = str_replace( $control_code, '', $s );
1466
+ $xml = simplexml_load_string( $s );
1467
+
1468
+ $authors = array();
1469
+ $namespaces = $xml->getDocNamespaces();
1470
+ foreach ( $xml->xpath( '/rss/channel/wp:author' ) as $author_arr ) {
1471
+ $a = $author_arr->children( $namespaces['wp'] );
1472
+ $authors[] = array(
1473
+ 'author_login' => (string) $a->author_login,
1474
+ 'author_display_name' => (string) $a->author_display_name,
1475
+ );
1476
+ }
1477
+
1478
+ $form_select = null;
1479
+ $count = 0;
1480
+ if ( current_user_can( 'manage_options' ) ) {
1481
+ $blogusers = get_users();
1482
+ foreach ( $authors as $key => $value ) {
1483
+ ++$count;
1484
+ $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>';
1485
+ $form_select .= '<div style="display: block; padding: 5px 30px">' . __( 'Assign posts to an existing user:', 'media-from-ftp' ) . '<select name="' . $value['author_login'] . '">';
1486
+ $form_select .= '<option value="-1" select>' . __( 'Select' ) . '</option>';
1487
+ foreach ( $blogusers as $user ) {
1488
+ $form_select .= '<option value="' . $user->ID . '">' . $user->display_name . '(' . $user->user_login . ')</option>';
1489
+ }
1490
+ $form_select .= '</select></div>';
1491
+ }
1492
+ $current_user = wp_get_current_user();
1493
+ $current_user_html = '<strong>' . $current_user->display_name . '(' . $current_user->user_login . ')</strong>';
1494
+ /* translators: Current user */
1495
+ $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>';
1496
+ } else {
1497
+ $user = wp_get_current_user();
1498
+ foreach ( $authors as $key => $value ) {
1499
+ ++$count;
1500
+ $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>';
1501
+ $current_user_html = '<strong>' . $user->display_name . '(' . $user->user_login . ')</strong>';
1502
+ /* translators: Current user */
1503
+ $form_select .= '<div style="display: block; padding: 5px 30px">' . sprintf( __( 'Assign posts to %1$s', 'media-from-ftp' ), $current_user_html ) . '</div>';
1504
+
1505
+ }
1506
+ }
1507
+ $button_value = get_submit_button( __( 'Apply' ), 'large', 'select_author', false );
1508
+ $nonce_field = wp_nonce_field( 'mff_select_author', 'media_from_ftp_select_author' );
1509
+
1510
+ $author_form = <<<MEDIAFROMFTP_AUTHOR_SELECT
1511
+
1512
+ <!-- BEGIN: Media from FTP Media Library Import -->
1513
+ <form method="post" action="$scriptname">
1514
+ $nonce_field
1515
+ $form_select
1516
+ <div style="display: block; padding: 20px 0px">$button_value</div>
1517
+ <input type="hidden" name="mediafromftp_select_author" value="1" />
1518
+ <input type="hidden" name="mediafromftp_xml_file" value="$filename" />
1519
+ </form>
1520
+
1521
+ <!-- END: Media from FTP Media Library Import -->
1522
+
1523
+ MEDIAFROMFTP_AUTHOR_SELECT;
1524
+
1525
+ return $author_form;
1526
+
1527
+ }
1528
+
1529
+ /** ==================================================
1530
+ * Make object for Media Library Import
1531
+ *
1532
+ * @param string $filename filename.
1533
+ * @param array $select_author select_author.
1534
+ * @return string $add_js
1535
+ * @since 9.40
1536
+ */
1537
+ public function make_object( $filename, $select_author ) {
1538
+
1539
+ $s = @file_get_contents( $filename );
1540
+ $control_code = array( "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x0b", "\x0c", "\x0e", "\x0f" );
1541
+ $s = str_replace( $control_code, '', $s );
1542
+ $xml = simplexml_load_string( $s );
1543
+ $data = array();
1544
+ foreach ( $xml->channel->item as $item ) {
1545
+ $x = array();
1546
+ $x['title'] = (string) $item->title;
1547
+ $x['link'] = (string) $item->link;
1548
+ $x['pubDate'] = (string) $item->pubDate;
1549
+ $x['creator'] = (string) $item->children( 'dc', true )->creator;
1550
+ $x['guid'] = (string) $item->guid;
1551
+ $x['guid_atr'] = (string) $item->guid->attributes()->isPermaLink;
1552
+ $x['description'] = (string) $item->description;
1553
+ $x['content_encoded'] = (string) $item->children( 'content', true )->encoded;
1554
+ $x['excerpt_encoded'] = (string) $item->children( 'excerpt', true )->encoded;
1555
+ $x['post_id'] = (int) $item->children( 'wp', true )->post_id;
1556
+ $x['post_date'] = (string) $item->children( 'wp', true )->post_date;
1557
+ $x['post_date_gmt'] = (string) $item->children( 'wp', true )->post_date_gmt;
1558
+ $x['comment_status'] = (string) $item->children( 'wp', true )->comment_status;
1559
+ $x['ping_status'] = (string) $item->children( 'wp', true )->ping_status;
1560
+ $x['post_name'] = (string) $item->children( 'wp', true )->post_name;
1561
+ $x['status'] = (string) $item->children( 'wp', true )->status;
1562
+ $x['post_parent'] = (int) $item->children( 'wp', true )->post_parent;
1563
+ $x['menu_order'] = (int) $item->children( 'wp', true )->menu_order;
1564
+ $x['post_type'] = (string) $item->children( 'wp', true )->post_type;
1565
+ $x['post_password'] = (string) $item->children( 'wp', true )->post_password;
1566
+ $x['is_sticky'] = (int) $item->children( 'wp', true )->is_sticky;
1567
+ $x['attachment_url'] = (string) $item->children( 'wp', true )->attachment_url;
1568
+
1569
+ $postmeta_count = count( $item->children( 'wp', true )->postmeta );
1570
+ for ( $i = 0; $i < $postmeta_count; $i++ ) {
1571
+ $wp_postmeta_node = $item->children( 'wp', true )->postmeta[ $i ];
1572
+ $post_meta_key = (string) $wp_postmeta_node->meta_key;
1573
+ $post_meta_value = (string) $wp_postmeta_node->meta_value;
1574
+ if ( '_wp_attached_file' === $post_meta_key ) {
1575
+ $x['postmeta_wp_attached_file'] = $post_meta_key;
1576
+ $x['postmeta_wp_attached_file_value'] = $post_meta_value;
1577
+ } else if ( '_thumbnail_id' === $post_meta_key ) {
1578
+ $x['postmeta_thumbnail_id'] = $post_meta_key;
1579
+ $x['postmeta_thumbnail_id_value'] = $post_meta_value;
1580
+ } else if ( '_cover_hash' === $post_meta_key ) {
1581
+ $x['postmeta_cover_hash'] = $post_meta_key;
1582
+ $x['postmeta_cover_hash_value'] = $post_meta_value;
1583
+ } else if ( '_wp_attachment_metadata' === $post_meta_key ) {
1584
+ $x['postmeta_wp_attachment_metadata'] = $post_meta_key;
1585
+ $x['postmeta_wp_attachment_metadata_value'] = $post_meta_value;
1586
+ } else if ( '_wp_attachment_image_alt' === $post_meta_key ) {
1587
+ $x['postmeta_wp_attachment_image_alt'] = $post_meta_key;
1588
+ $x['postmeta_wp_attachment_image_alt_value'] = $post_meta_value;
1589
+ }
1590
+ }
1591
+
1592
+ $data[] = $x;
1593
+ }
1594
+
1595
+ $count = 0;
1596
+ $file_array = array();
1597
+ $db_array = array();
1598
+ $db_wp_attachment_metadata_array = array();
1599
+ $db_thumbnail_id_array = array();
1600
+ $db_cover_hash_array = array();
1601
+ $db_wp_attachment_image_alt_array = array();
1602
+ foreach ( $data as $key => $value ) {
1603
+ if ( 'attachment' === $value['post_type'] ) {
1604
+ $file = $this->upload_dir . '/' . $value['postmeta_wp_attached_file_value'];
1605
+ $filetype = wp_check_filetype( basename( $file ), null );
1606
+
1607
+ $user = wp_get_current_user();
1608
+ $loginuser = $user->ID;
1609
+ foreach ( $select_author as $authorkey => $authorvalue ) {
1610
+ if ( $value['creator'] === $authorkey ) {
1611
+ $loginuser = $authorvalue;
1612
+ }
1613
+ }
1614
+
1615
+ $guid = $this->upload_url . '/' . $value['postmeta_wp_attached_file_value'];
1616
+ $db_array[ $count ] = array(
1617
+ 'ID' => $value['post_id'],
1618
+ 'post_author' => $loginuser,
1619
+ 'post_date' => $value['post_date'],
1620
+ 'post_date_gmt' => $value['post_date_gmt'],
1621
+ 'post_content' => $value['content_encoded'],
1622
+ 'post_title' => $value['title'],
1623
+ 'post_excerpt' => $value['excerpt_encoded'],
1624
+ 'post_status' => $value['status'],
1625
+ 'comment_status' => $value['comment_status'],
1626
+ 'ping_status' => $value['ping_status'],
1627
+ 'post_password' => $value['post_password'],
1628
+ 'post_name' => $value['post_name'],
1629
+ 'post_parent' => $value['post_parent'],
1630
+ 'guid' => $guid,
1631
+ 'menu_order' => $value['menu_order'],
1632
+ 'post_type' => $value['post_type'],
1633
+ 'post_mime_type' => $filetype['type'],
1634
+ );
1635
+
1636
+ $file_array[ $count ] = $file;
1637
+
1638
+ if ( array_key_exists( 'postmeta_wp_attachment_metadata_value', $value ) ) {
1639
+ $db_wp_attachment_metadata_array[ $count ] = json_encode( $value['postmeta_wp_attachment_metadata_value'] );
1640
+ if ( strrpos( $value['postmeta_wp_attached_file_value'], '/' ) ) {
1641
+ $monthdir = '/' . substr( $value['postmeta_wp_attached_file_value'], 0, strrpos( $value['postmeta_wp_attached_file_value'], '/' ) );
1642
+ $dir = $this->upload_dir . $monthdir;
1643
+ }
1644
+ $thumbnails = maybe_unserialize( $value['postmeta_wp_attachment_metadata_value'] );
1645
+ if ( is_array( $thumbnails ) ) {
1646
+ foreach ( $thumbnails as $key1 => $value1 ) {
1647
+ if ( is_array( $value1 ) ) {
1648
+ foreach ( $value1 as $key2 => $value2 ) {
1649
+ if ( is_array( $value2 ) ) {
1650
+ foreach ( $value2 as $key3 => $value3 ) {
1651
+ if ( 'file' === $key3 ) {
1652
+ $thumbnail = $dir . '/' . $value3;
1653
+ ++$count;
1654
+ $file_array[ $count ] = $thumbnail;
1655
+ }
1656
+ }
1657
+ }
1658
+ }
1659
+ }
1660
+ }
1661
+ }
1662
+ }
1663
+ if ( array_key_exists( 'postmeta_thumbnail_id_value', $value ) ) {
1664
+ $db_thumbnail_id_array[ $count ] = $value['postmeta_thumbnail_id_value'];
1665
+ }
1666
+ if ( array_key_exists( 'postmeta_cover_hash_value', $value ) ) {
1667
+ $db_cover_hash_array[ $count ] = $value['postmeta_cover_hash_value'];
1668
+ }
1669
+ if ( array_key_exists( 'postmeta_wp_attachment_image_alt_value', $value ) ) {
1670
+ $db_wp_attachment_image_alt_array[ $count ] = $value['postmeta_wp_attachment_image_alt_value'];
1671
+ }
1672
+
1673
+ ++$count;
1674
+ }
1675
+ }
1676
+
1677
+ $file_obj = json_encode( $file_array );
1678
+ $db_array_obj = json_encode( $db_array );
1679
+ $db_wp_attachment_metadata_obj = json_encode( $db_wp_attachment_metadata_array );
1680
+ $db_thumbnail_id_obj = json_encode( $db_thumbnail_id_array );
1681
+ $db_cover_hash_obj = json_encode( $db_cover_hash_array );
1682
+ $db_wp_attachment_image_alt_obj = json_encode( $db_wp_attachment_image_alt_array );
1683
+
1684
+ /* JS */
1685
+ $add_js = '
1686
+ medialibraryimport_maxcount = ' . $count . ';
1687
+ medialibraryimport_file = ' . $file_obj . ';
1688
+ medialibraryimport_db_array = ' . $db_array_obj . ';
1689
+ medialibraryimport_db_wp_attachment_metadata = ' . $db_wp_attachment_metadata_obj . ';
1690
+ medialibraryimport_db_thumbnail_id = ' . $db_thumbnail_id_obj . ';
1691
+ medialibraryimport_db_cover_hash = ' . $db_cover_hash_obj . ';
1692
+ medialibraryimport_db_wp_attachment_image_alt = ' . $db_wp_attachment_image_alt_obj . ';
1693
+ ';
1694
+
1695
+ return $add_js;
1696
+
1697
+ }
1698
+
1699
+ }
1700
+
1701
+
js/jquery.mediafromftp.datetimepicker.js CHANGED
@@ -1,23 +1,27 @@
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
- });
 
 
 
 
1
+ /**
2
+ * Media from FTP
3
+ *
4
+ * @package Media from FTP
5
+ * @subpackage jquery.mediafromftp.datetimepicker.js
6
+ /*
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
+ jQuery(
23
+ function(){
24
+ /* Date Time Picker */
25
+ jQuery( ':input[id^=datetimepicker-mediafromftp]' ).datetimepicker( {format:'Y-m-d H:i'} );
26
+ }
27
+ );
js/jquery.mediafromftp.js CHANGED
@@ -1,340 +1,431 @@
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 check_id = new Array();
59
- var new_datetime = new Array();
60
- var new_mlccategory = new Array();
61
- var new_emlcategory = new Array();
62
- var new_mlacategory = new Array();
63
- var new_mlatags = new Array();
64
- var form_names = jQuery("#mediafromftp_ajax_update").serializeArray();
65
- var mlccount = 0;
66
- var emlcount = 0;
67
- var mlacatcount = 0;
68
- var mlatagcount = 0;
69
- var j = 0;
70
- jQuery.each(form_names, function(i) {
71
- check_id[i] = "";
72
- if ( form_names[i].name.indexOf("[url]") != -1 ) {
73
- new_url[j] = form_names[i].value;
74
- var id = form_names[i].name;
75
- id = id.replace(/new_url_attaches\[/g, '');
76
- id = id.replace(/\]\[url\]/g, '');
77
- check_id[i] = id;
78
- j = j + 1;
79
- }
80
- });
81
- var j = 0;
82
- jQuery.each(form_names, function(i) {
83
- if ( form_names[i].name.indexOf("[datetime]") != -1 ) {
84
- var id = form_names[i].name;
85
- id = id.replace(/new_url_attaches\[/g, '');
86
- id = id.replace(/\]\[datetime\]/g, '');
87
- jQuery.each(check_id, function(k) {
88
- if ( id == check_id[k] ) {
89
- new_datetime[j] = form_names[i].value;
90
- j = j + 1;
91
- }
92
- });
93
- }
94
- });
95
- var j = 0;
96
- jQuery.each(form_names, function(i) {
97
- if ( form_names[i].name.indexOf("[mlccount]") != -1 ) {
98
- var id = form_names[i].name;
99
- id = id.replace(/new_url_attaches\[/g, '');
100
- id = id.replace(/\]\[mlccount\]/g, '');
101
- jQuery.each(check_id, function(k) {
102
- if ( id == check_id[k] ) {
103
- mlccount = form_names[i].value;
104
- var form_checkbox = ".mlccheckbox" + mlccount + " input:checked";
105
- var value="";
106
- jQuery(form_checkbox).each(function() {
107
- value = jQuery(this).val() + ',' + value;
108
- });
109
- new_mlccategory[j] = value.substr( 0, value.length-1 );
110
- j = j + 1;
111
- }
112
- });
113
- }
114
- });
115
- var j = 0;
116
- jQuery.each(form_names, function(i) {
117
- if ( form_names[i].name.indexOf("[emlcount]") != -1 ) {
118
- var id = form_names[i].name;
119
- id = id.replace(/new_url_attaches\[/g, '');
120
- id = id.replace(/\]\[emlcount\]/g, '');
121
- jQuery.each(check_id, function(k) {
122
- if ( id == check_id[k] ) {
123
- emlcount = form_names[i].value;
124
- var form_checkbox = ".emlcheckbox" + emlcount + " input:checked";
125
- var value="";
126
- jQuery(form_checkbox).each(function() {
127
- value = jQuery(this).val() + ',' + value;
128
- });
129
- new_emlcategory[j] = value.substr( 0, value.length-1 );
130
- j = j + 1;
131
- }
132
- });
133
- }
134
- });
135
- var j = 0;
136
- jQuery.each(form_names, function(i) {
137
- if ( form_names[i].name.indexOf("[mlacatcount]") != -1 ) {
138
- var id = form_names[i].name;
139
- id = id.replace(/new_url_attaches\[/g, '');
140
- id = id.replace(/\]\[mlacatcount\]/g, '');
141
- jQuery.each(check_id, function(k) {
142
- if ( id == check_id[k] ) {
143
- mlacatcount = form_names[i].value;
144
- var form_checkbox = ".mlacatcheckbox" + mlacatcount + " input:checked";
145
- var value="";
146
- jQuery(form_checkbox).each(function() {
147
- value = jQuery(this).val() + ',' + value;
148
- });
149
- new_mlacategory[j] = value.substr( 0, value.length-1 );
150
- j = j + 1;
151
- }
152
- });
153
- }
154
- });
155
- var j = 0;
156
- jQuery.each(form_names, function(i) {
157
- if ( form_names[i].name.indexOf("[mlatagcount]") != -1 ) {
158
- var id = form_names[i].name;
159
- id = id.replace(/new_url_attaches\[/g, '');
160
- id = id.replace(/\]\[mlatagcount\]/g, '');
161
- jQuery.each(check_id, function(k) {
162
- if ( id == check_id[k] ) {
163
- mlatagcount = form_names[i].value;
164
- var form_checkbox = ".mlatagcheckbox" + mlatagcount + " input:checked";
165
- var value="";
166
- jQuery(form_checkbox).each(function() {
167
- value = jQuery(this).val() + ',' + value;
168
- });
169
- new_mlatags[j] = value.substr( 0, value.length-1 );
170
- j = j + 1;
171
- }
172
- });
173
- }
174
- });
175
-
176
- jQuery("#mediafromftp-loading-container").empty();
177
- jQuery("#screen-options-wrap").remove();
178
- jQuery(".updated").remove();
179
- jQuery(".error").remove();
180
-
181
- 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>");
182
- jQuery("#mediafromftp-loading-container").append("<div id=\"mediafromftp-update-result\"></div>");
183
-
184
- var update_continue = true;
185
- // Stop button
186
- jQuery("#mediafromftp_ajax_stop").click(function() {
187
- update_continue = false;
188
- jQuery("#mediafromftp_ajax_stop").text("Stopping now..");
189
- });
190
-
191
- var count = 0;
192
- var success_count = 0;
193
- var success_update = "";
194
- var error_count = 0;
195
- var error_update = "";
196
- jQuery.each(new_url, function(i){
197
- var j = i ;
198
- mediafromftp_defer = mediafromftp_defer.then(function(){
199
- if ( update_continue == true ) {
200
- return jQuery.ajax({
201
- type: 'POST',
202
- url: MEDIAFROMFTPUPDATE.ajax_url,
203
- data: {
204
- 'action': MEDIAFROMFTPUPDATE.action,
205
- 'nonce': MEDIAFROMFTPUPDATE.nonce,
206
- 'maxcount': new_url.length,
207
- 'new_url': new_url[j],
208
- 'new_datetime': new_datetime[j],
209
- 'new_mlccategory': new_mlccategory[j],
210
- 'new_emlcategory': new_emlcategory[j],
211
- 'new_mlacategory': new_mlacategory[j],
212
- 'new_mlatags': new_mlatags[j]
213
- }
214
- }).then(
215
- function(result){
216
- count += 1;
217
- success_count += 1;
218
- jQuery("#mediafromftp-update-result").append(result);
219
- jQuery("#mediafromftp-update-progress").empty();
220
- var progressper = Math.round((count/new_url.length)*100);
221
- jQuery("#mediafromftp-update-progress").append("<progress value=\"" + progressper + "\" max=\"100\"></progress> " + progressper + "%");
222
- if ( count == new_url.length || update_continue == false ) {
223
- jQuery.ajax({
224
- type: 'POST',
225
- url: MEDIAFROMFTPUPDATE.ajax_url,
226
- data: {
227
- 'action': 'mediafromftp_message',
228
- 'error_count': error_count,
229
- 'error_update': error_update,
230
- 'success_count': success_count
231
- }
232
- }).done(function(result){
233
- jQuery("#mediafromftp-update-progress").empty();
234
- jQuery("#mediafromftp-update-progress").append(result);
235
- jQuery("#mediafromftp_ajax_stop").hide();
236
- });
237
- }
238
- },
239
- function( jqXHR, textStatus, errorThrown){
240
- error_count += 1;
241
- error_update += "<div>" + new_url[j] + ": error -> status " + jqXHR.status + ' ' + textStatus.status + "</div>";
242
- }
243
- );
244
- }
245
- });
246
- });
247
- return false;
248
- });
249
-
250
- /* Ajax for import */
251
- var medialibraryimport_defer = jQuery.Deferred().resolve();
252
- jQuery('#medialibraryimport_ajax_update').submit(function(){
253
-
254
- jQuery("#medialibraryimport-loading-container").empty();
255
- jQuery(".updated").remove();
256
- jQuery(".error").remove();
257
-
258
- 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>");
259
- jQuery("#medialibraryimport-loading-container").append("<div id=\"medialibraryimport-update-result\"></div>");
260
- var update_continue = true;
261
- // Stop button
262
- jQuery("#medialibraryimport_ajax_stop").click(function() {
263
- update_continue = false;
264
- jQuery("#medialibraryimport_ajax_stop").text("Stopping now..");
265
- });
266
-
267
- var count = 0;
268
- var success_count = 0;
269
- var db_success_count = 0;
270
- var error_count = 0;
271
- var error_update = "";
272
-
273
- jQuery.each(medialibraryimport_file, function(i){
274
- var j = i;
275
- medialibraryimport_defer = medialibraryimport_defer.then(function(){
276
- if ( update_continue == true ) {
277
- return jQuery.ajax({
278
- type: 'POST',
279
- cache : false,
280
- url: MEDIAFROMFTPIMPORT.ajax_url,
281
- data: {
282
- 'action': MEDIAFROMFTPIMPORT.action,
283
- 'nonce': MEDIAFROMFTPIMPORT.nonce,
284
- 'maxcount': medialibraryimport_maxcount,
285
- 'file': medialibraryimport_file[j],
286
- 'db_array': medialibraryimport_db_array[j],
287
- 'db_wp_attachment_metadata': medialibraryimport_db_wp_attachment_metadata[j],
288
- 'db_thumbnail_id': medialibraryimport_db_thumbnail_id[j],
289
- 'db_cover_hash': medialibraryimport_db_cover_hash[j],
290
- 'db_wp_attachment_image_alt': medialibraryimport_db_wp_attachment_image_alt[j]
291
- }
292
- }).then(
293
- function(result){
294
- count += 1;
295
- var update_view = result.split(",");
296
- if( update_view[0] == "success" ) {
297
- success_count += 1;
298
- } else if( update_view[0] == "success_db" ) {
299
- success_count += 1;
300
- db_success_count += 1;
301
- } else {
302
- error_count += 1;
303
- error_update += update_view[0];
304
- }
305
- jQuery("#medialibraryimport-update-progress").empty();
306
- var progressper = Math.round((count/medialibraryimport_maxcount)*100);
307
- jQuery("#medialibraryimport-update-progress").append("<progress value=\"" + progressper + "\" max=\"100\"></progress> " + progressper + "%");
308
- jQuery("#medialibraryimport-update-result").append(update_view[1]);
309
- if ( count == medialibraryimport_maxcount || update_continue == false ) {
310
- jQuery.ajax({
311
- type: 'POST',
312
- url: MEDIAFROMFTPIMPORT.ajax_url,
313
- data: {
314
- 'action': 'mediafromftp_medialibraryimport_message',
315
- 'error_count': error_count,
316
- 'error_update': error_update,
317
- 'success_count': success_count,
318
- 'db_success_count': db_success_count
319
- }
320
- }).done(function(result){
321
- jQuery("#medialibraryimport-update-progress").empty();
322
- jQuery("#medialibraryimport-update-progress").append(result);
323
- jQuery("#medialibraryimport_ajax_stop").hide();
324
- });
325
- }
326
- }
327
- ).fail(
328
- function( jqXHR, textStatus, errorThrown){
329
- error_count += 1;
330
- error_update += "<div>" + medialibraryimport_file[j] + ": error -> status " + jqXHR.status + ' ' + textStatus.status + "</div>";
331
- }
332
- );
333
- }
334
- });
335
- });
336
- return false;
337
- });
338
-
339
- });
340
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Media from FTP
3
+ *
4
+ * @package Media from FTP
5
+ * @subpackage jquery.mediafromftp.js
6
+ /*
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
+ jQuery(
23
+ function(){
24
+
25
+ /* Responsive Tabs */
26
+ jQuery( '#mediafromftp-settings-tabs' ).responsiveTabs(
27
+ {
28
+ startCollapsed: 'accordion'
29
+ }
30
+ );
31
+
32
+ /* Spiner */
33
+ window.addEventListener(
34
+ "load",
35
+ function(){
36
+ jQuery( "#mediafromftp-loading" ).delay( 2000 ).fadeOut();
37
+ jQuery( "#mediafromftp-loading-container" ).delay( 2000 ).fadeIn();
38
+ },
39
+ false
40
+ );
41
+
42
+ /* Control of the Enter key */
43
+ jQuery( 'input[type!="submit"][type!="button"]' ).keypress(
44
+ function(e){
45
+ if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
46
+ return false;
47
+ } else {
48
+ return true;
49
+ }
50
+ }
51
+ );
52
+
53
+ /* Select bulk Date time */
54
+ jQuery( 'input[name="bulk_mediafromftp_datetime"]' ).change(
55
+ function(){
56
+ var edit_date_time_val = jQuery( 'input[name="bulk_mediafromftp_datetime"]' ).val();
57
+ jQuery( ':input[id^=datetimepicker-mediafromftp]' ).val( edit_date_time_val );
58
+ }
59
+ );
60
+
61
+ /* All check for Checkbox */
62
+ jQuery( '.event-mediafromftp-checkAll' ).on(
63
+ 'change',
64
+ function() {
65
+ jQuery( '.' + this.id ).prop( 'checked', this.checked );
66
+ }
67
+ );
68
+
69
+ /* Ajax for register */
70
+ var mediafromftp_defer = jQuery.Deferred().resolve();
71
+ jQuery( '#mediafromftp_ajax_update' ).submit(
72
+ function(){
73
+
74
+ var new_url = new Array();
75
+ var check_id = new Array();
76
+ var new_datetime = new Array();
77
+ var new_mlccategory = new Array();
78
+ var new_emlcategory = new Array();
79
+ var new_mlacategory = new Array();
80
+ var new_mlatags = new Array();
81
+ var form_names = jQuery( "#mediafromftp_ajax_update" ).serializeArray();
82
+ var mlccount = 0;
83
+ var emlcount = 0;
84
+ var mlacatcount = 0;
85
+ var mlatagcount = 0;
86
+ var j = 0;
87
+ jQuery.each(
88
+ form_names,
89
+ function(i) {
90
+ check_id[i] = "";
91
+ if ( form_names[i].name.indexOf( "[url]" ) != -1 ) {
92
+ new_url[j] = form_names[i].value;
93
+ var id = form_names[i].name;
94
+ id = id.replace( /new_url_attaches\[/g, '' );
95
+ id = id.replace( /\]\[url\]/g, '' );
96
+ check_id[i] = id;
97
+ j = j + 1;
98
+ }
99
+ }
100
+ );
101
+ var j = 0;
102
+ jQuery.each(
103
+ form_names,
104
+ function(i) {
105
+ if ( form_names[i].name.indexOf( "[datetime]" ) != -1 ) {
106
+ var id = form_names[i].name;
107
+ id = id.replace( /new_url_attaches\[/g, '' );
108
+ id = id.replace( /\]\[datetime\]/g, '' );
109
+ jQuery.each(
110
+ check_id,
111
+ function(k) {
112
+ if ( id == check_id[k] ) {
113
+ new_datetime[j] = form_names[i].value;
114
+ j = j + 1;
115
+ }
116
+ }
117
+ );
118
+ }
119
+ }
120
+ );
121
+ var j = 0;
122
+ jQuery.each(
123
+ form_names,
124
+ function(i) {
125
+ if ( form_names[i].name.indexOf( "[mlccount]" ) != -1 ) {
126
+ var id = form_names[i].name;
127
+ id = id.replace( /new_url_attaches\[/g, '' );
128
+ id = id.replace( /\]\[mlccount\]/g, '' );
129
+ jQuery.each(
130
+ check_id,
131
+ function(k) {
132
+ if ( id == check_id[k] ) {
133
+ mlccount = form_names[i].value;
134
+ var form_checkbox = ".mlccheckbox" + mlccount + " input:checked";
135
+ var value = "";
136
+ jQuery( form_checkbox ).each(
137
+ function() {
138
+ value = jQuery( this ).val() + ',' + value;
139
+ }
140
+ );
141
+ new_mlccategory[j] = value.substr( 0, value.length - 1 );
142
+ j = j + 1;
143
+ }
144
+ }
145
+ );
146
+ }
147
+ }
148
+ );
149
+ var j = 0;
150
+ jQuery.each(
151
+ form_names,
152
+ function(i) {
153
+ if ( form_names[i].name.indexOf( "[emlcount]" ) != -1 ) {
154
+ var id = form_names[i].name;
155
+ id = id.replace( /new_url_attaches\[/g, '' );
156
+ id = id.replace( /\]\[emlcount\]/g, '' );
157
+ jQuery.each(
158
+ check_id,
159
+ function(k) {
160
+ if ( id == check_id[k] ) {
161
+ emlcount = form_names[i].value;
162
+ var form_checkbox = ".emlcheckbox" + emlcount + " input:checked";
163
+ var value = "";
164
+ jQuery( form_checkbox ).each(
165
+ function() {
166
+ value = jQuery( this ).val() + ',' + value;
167
+ }
168
+ );
169
+ new_emlcategory[j] = value.substr( 0, value.length - 1 );
170
+ j = j + 1;
171
+ }
172
+ }
173
+ );
174
+ }
175
+ }
176
+ );
177
+ var j = 0;
178
+ jQuery.each(
179
+ form_names,
180
+ function(i) {
181
+ if ( form_names[i].name.indexOf( "[mlacatcount]" ) != -1 ) {
182
+ var id = form_names[i].name;
183
+ id = id.replace( /new_url_attaches\[/g, '' );
184
+ id = id.replace( /\]\[mlacatcount\]/g, '' );
185
+ jQuery.each(
186
+ check_id,
187
+ function(k) {
188
+ if ( id == check_id[k] ) {
189
+ mlacatcount = form_names[i].value;
190
+ var form_checkbox = ".mlacatcheckbox" + mlacatcount + " input:checked";
191
+ var value = "";
192
+ jQuery( form_checkbox ).each(
193
+ function() {
194
+ value = jQuery( this ).val() + ',' + value;
195
+ }
196
+ );
197
+ new_mlacategory[j] = value.substr( 0, value.length - 1 );
198
+ j = j + 1;
199
+ }
200
+ }
201
+ );
202
+ }
203
+ }
204
+ );
205
+ var j = 0;
206
+ jQuery.each(
207
+ form_names,
208
+ function(i) {
209
+ if ( form_names[i].name.indexOf( "[mlatagcount]" ) != -1 ) {
210
+ var id = form_names[i].name;
211
+ id = id.replace( /new_url_attaches\[/g, '' );
212
+ id = id.replace( /\]\[mlatagcount\]/g, '' );
213
+ jQuery.each(
214
+ check_id,
215
+ function(k) {
216
+ if ( id == check_id[k] ) {
217
+ mlatagcount = form_names[i].value;
218
+ var form_checkbox = ".mlatagcheckbox" + mlatagcount + " input:checked";
219
+ var value = "";
220
+ jQuery( form_checkbox ).each(
221
+ function() {
222
+ value = jQuery( this ).val() + ',' + value;
223
+ }
224
+ );
225
+ new_mlatags[j] = value.substr( 0, value.length - 1 );
226
+ j = j + 1;
227
+ }
228
+ }
229
+ );
230
+ }
231
+ }
232
+ );
233
+
234
+ jQuery( "#mediafromftp-loading-container" ).empty();
235
+ jQuery( "#screen-options-wrap" ).remove();
236
+ jQuery( ".updated" ).remove();
237
+ jQuery( ".error" ).remove();
238
+
239
+ 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>" );
240
+ jQuery( "#mediafromftp-loading-container" ).append( "<div id=\"mediafromftp-update-result\"></div>" );
241
+
242
+ var update_continue = true;
243
+ /* Stop button */
244
+ jQuery( "#mediafromftp_ajax_stop" ).click(
245
+ function() {
246
+ update_continue = false;
247
+ jQuery( "#mediafromftp_ajax_stop" ).text( "Stopping now.." );
248
+ }
249
+ );
250
+
251
+ var count = 0;
252
+ var success_count = 0;
253
+ var success_update = "";
254
+ var error_count = 0;
255
+ var error_update = "";
256
+ jQuery.each(
257
+ new_url,
258
+ function(i){
259
+ var j = i;
260
+ mediafromftp_defer = mediafromftp_defer.then(
261
+ function(){
262
+ if ( update_continue == true ) {
263
+ return jQuery.ajax(
264
+ {
265
+ type: 'POST',
266
+ url: MEDIAFROMFTPUPDATE.ajax_url,
267
+ data: {
268
+ 'action': MEDIAFROMFTPUPDATE.action,
269
+ 'nonce': MEDIAFROMFTPUPDATE.nonce,
270
+ 'maxcount': new_url.length,
271
+ 'new_url': new_url[j],
272
+ 'new_datetime': new_datetime[j],
273
+ 'new_mlccategory': new_mlccategory[j],
274
+ 'new_emlcategory': new_emlcategory[j],
275
+ 'new_mlacategory': new_mlacategory[j],
276
+ 'new_mlatags': new_mlatags[j]
277
+ }
278
+ }
279
+ ).then(
280
+ function(result){
281
+ count += 1;
282
+ success_count += 1;
283
+ jQuery( "#mediafromftp-update-result" ).append( result );
284
+ jQuery( "#mediafromftp-update-progress" ).empty();
285
+ var progressper = Math.round( (count / new_url.length) * 100 );
286
+ jQuery( "#mediafromftp-update-progress" ).append( "<progress value=\"" + progressper + "\" max=\"100\"></progress> " + progressper + "%" );
287
+ if ( count == new_url.length || update_continue == false ) {
288
+ jQuery.ajax(
289
+ {
290
+ type: 'POST',
291
+ url: MEDIAFROMFTPMESSAGE.ajax_url,
292
+ data: {
293
+ 'action': MEDIAFROMFTPMESSAGE.action,
294
+ 'nonce': MEDIAFROMFTPMESSAGE.nonce,
295
+ 'error_count': error_count,
296
+ 'error_update': error_update,
297
+ 'success_count': success_count
298
+ }
299
+ }
300
+ ).done(
301
+ function(result){
302
+ jQuery( "#mediafromftp-update-progress" ).empty();
303
+ jQuery( "#mediafromftp-update-progress" ).append( result );
304
+ jQuery( "#mediafromftp_ajax_stop" ).hide();
305
+ }
306
+ );
307
+ }
308
+ },
309
+ function( jqXHR, textStatus, errorThrown){
310
+ error_count += 1;
311
+ error_update += "<div>" + new_url[j] + ": error -> status " + jqXHR.status + ' ' + textStatus.status + "</div>";
312
+ }
313
+ );
314
+ }
315
+ }
316
+ );
317
+ }
318
+ );
319
+ return false;
320
+ }
321
+ );
322
+
323
+ /* Ajax for import */
324
+ var medialibraryimport_defer = jQuery.Deferred().resolve();
325
+ jQuery( '#medialibraryimport_ajax_update' ).submit(
326
+ function(){
327
+
328
+ jQuery( "#medialibraryimport-loading-container" ).empty();
329
+ jQuery( ".updated" ).remove();
330
+ jQuery( ".error" ).remove();
331
+
332
+ 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>" );
333
+ jQuery( "#medialibraryimport-loading-container" ).append( "<div id=\"medialibraryimport-update-result\"></div>" );
334
+ var update_continue = true;
335
+ /* Stop button */
336
+ jQuery( "#medialibraryimport_ajax_stop" ).click(
337
+ function() {
338
+ update_continue = false;
339
+ jQuery( "#medialibraryimport_ajax_stop" ).text( "Stopping now.." );
340
+ }
341
+ );
342
+
343
+ var count = 0;
344
+ var success_count = 0;
345
+ var db_success_count = 0;
346
+ var error_count = 0;
347
+ var error_update = "";
348
+
349
+ jQuery.each(
350
+ medialibraryimport_file,
351
+ function(i){
352
+ var j = i;
353
+ medialibraryimport_defer = medialibraryimport_defer.then(
354
+ function(){
355
+ if ( update_continue == true ) {
356
+ return jQuery.ajax(
357
+ {
358
+ type: 'POST',
359
+ cache : false,
360
+ url: MEDIAFROMFTPIMPORT.ajax_url,
361
+ data: {
362
+ 'action': MEDIAFROMFTPIMPORT.action,
363
+ 'nonce': MEDIAFROMFTPIMPORT.nonce,
364
+ 'maxcount': medialibraryimport_maxcount,
365
+ 'file': medialibraryimport_file[j],
366
+ 'db_array': medialibraryimport_db_array[j],
367
+ 'db_wp_attachment_metadata': medialibraryimport_db_wp_attachment_metadata[j],
368
+ 'db_thumbnail_id': medialibraryimport_db_thumbnail_id[j],
369
+ 'db_cover_hash': medialibraryimport_db_cover_hash[j],
370
+ 'db_wp_attachment_image_alt': medialibraryimport_db_wp_attachment_image_alt[j]
371
+ }
372
+ }
373
+ ).then(
374
+ function(result){
375
+ count += 1;
376
+ var update_view = result.split( "," );
377
+ if ( update_view[0] == "success" ) {
378
+ success_count += 1;
379
+ } else if ( update_view[0] == "success_db" ) {
380
+ success_count += 1;
381
+ db_success_count += 1;
382
+ } else {
383
+ /* error_count += 1; */
384
+ /* error_update += update_view[0]; */
385
+ success_count += 1;
386
+ db_success_count += 1;
387
+ }
388
+ jQuery( "#medialibraryimport-update-progress" ).empty();
389
+ var progressper = Math.round( (count / medialibraryimport_maxcount) * 100 );
390
+ jQuery( "#medialibraryimport-update-progress" ).append( "<progress value=\"" + progressper + "\" max=\"100\"></progress> " + progressper + "%" );
391
+ jQuery( "#medialibraryimport-update-result" ).append( update_view[1] );
392
+ if ( count == medialibraryimport_maxcount || update_continue == false ) {
393
+ jQuery.ajax(
394
+ {
395
+ type: 'POST',
396
+ url: MEDIAFROMFTPIMPORTMESSAGE.ajax_url,
397
+ data: {
398
+ 'action': MEDIAFROMFTPIMPORTMESSAGE.action,
399
+ 'nonce': MEDIAFROMFTPIMPORTMESSAGE.nonce,
400
+ 'error_count': error_count,
401
+ 'error_update': error_update,
402
+ 'success_count': success_count,
403
+ 'db_success_count': db_success_count
404
+ }
405
+ }
406
+ ).done(
407
+ function(result){
408
+ jQuery( "#medialibraryimport-update-progress" ).empty();
409
+ jQuery( "#medialibraryimport-update-progress" ).append( result );
410
+ jQuery( "#medialibraryimport_ajax_stop" ).hide();
411
+ }
412
+ );
413
+ }
414
+ }
415
+ ).fail(
416
+ function( jqXHR, textStatus, errorThrown){
417
+ error_count += 1;
418
+ error_update += "<div>" + medialibraryimport_file[j] + ": error -> status " + jqXHR.status + ' ' + textStatus.status + "</div>";
419
+ }
420
+ );
421
+ }
422
+ }
423
+ );
424
+ }
425
+ );
426
+ return false;
427
+ }
428
+ );
429
+
430
+ }
431
+ );
mediafromftp.php CHANGED
@@ -1,38 +1,54 @@
1
- <?php
2
- /*
3
- Plugin Name: Media from FTP
4
- Plugin URI: https://wordpress.org/plugins/media-from-ftp/
5
- Version: 10.10
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
- add_action( 'plugins_loaded', 'media_from_ftp_load_textdomain' );
29
- function media_from_ftp_load_textdomain() {
30
- load_plugin_textdomain('media-from-ftp');
31
- }
32
-
33
- if(!class_exists('MediaFromFtpRegist')) require_once( dirname( __FILE__ ).'/req/MediaFromFtpRegist.php' );
34
- if(!class_exists('MediaFromFtpAdmin')) require_once( dirname( __FILE__ ).'/req/MediaFromFtpAdmin.php' );
35
- if(!class_exists('MediaFromFtpAjax')) require_once( dirname( __FILE__ ).'/req/MediaFromFtpAjax.php' );
36
-
37
-
38
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Plugin Name: Media from FTP
4
+ * Plugin URI: https://wordpress.org/plugins/media-from-ftp/
5
+ * Description: Register to media library from files that have been uploaded by FTP.
6
+ * Version: 11.00
7
+ * Author: Katsushi Kawamori
8
+ * Author URI: https://riverforest-wp.info/
9
+ * License: GPL2
10
+ * License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
+ * Text Domain: media-from-ftp
12
+ * Domain Path: /languages
13
+ *
14
+ * @package Media from FTP
15
+ */
16
+
17
+ /*
18
+ Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
19
+ This program is free software; you can redistribute it and/or modify
20
+ it under the terms of the GNU General Public License as published by
21
+ the Free Software Foundation; version 2 of the License.
22
+
23
+ This program is distributed in the hope that it will be useful,
24
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+ GNU General Public License for more details.
27
+
28
+ You should have received a copy of the GNU General Public License
29
+ along with this program; if not, write to the Free Software
30
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31
+ */
32
+
33
+ add_action( 'plugins_loaded', 'media_from_ftp_load_textdomain' );
34
+ /** ==================================================
35
+ * i18n
36
+ *
37
+ * @since 1.00
38
+ */
39
+ function media_from_ftp_load_textdomain() {
40
+ load_plugin_textdomain( 'media-from-ftp' );
41
+ }
42
+
43
+ if ( ! class_exists( 'MediaFromFtpRegist' ) ) {
44
+ require_once( dirname( __FILE__ ) . '/req/class-mediafromftpregist.php' );
45
+ }
46
+ if ( ! class_exists( 'MediaFromFtpAdmin' ) ) {
47
+ require_once( dirname( __FILE__ ) . '/req/class-mediafromftpadmin.php' );
48
+ }
49
+ if ( ! class_exists( 'MediaFromFtpAjax' ) ) {
50
+ require_once( dirname( __FILE__ ) . '/req/class-mediafromftpajax.php' );
51
+ }
52
+
53
+
54
+
plugin-update-checker/.editorconfig DELETED
@@ -1,15 +0,0 @@
1
- [*]
2
- charset=utf-8
3
- end_of_line=lf
4
- insert_final_newline=false
5
- indent_style=tab
6
- tab_width=4
7
-
8
- [{phpunit.xml.dist,*.jhm,*.xslt,*.xul,*.rng,*.xsl,*.xsd,*.ant,*.tld,*.fxml,*.jrxml,*.xml,*.jnlp,*.wsdl}]
9
- indent_style=space
10
- indent_size=4
11
-
12
- [*.svg]
13
- indent_style=space
14
- indent_size=4
15
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4/Factory.php DELETED
@@ -1,6 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4_Factory', false) ):
3
-
4
- class Puc_v4_Factory extends Puc_v4p4_Factory { }
5
-
6
- endif;
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Autoloader.php DELETED
@@ -1,49 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_Autoloader', false) ):
4
-
5
- class Puc_v4p4_Autoloader {
6
- private $prefix = '';
7
- private $rootDir = '';
8
- private $libraryDir = '';
9
-
10
- private $staticMap;
11
-
12
- public function __construct() {
13
- $this->rootDir = dirname(__FILE__) . '/';
14
- $nameParts = explode('_', __CLASS__, 3);
15
- $this->prefix = $nameParts[0] . '_' . $nameParts[1] . '_';
16
-
17
- $this->libraryDir = realpath($this->rootDir . '../..') . '/';
18
- $this->staticMap = array(
19
- 'PucReadmeParser' => 'vendor/readme-parser.php',
20
- 'Parsedown' => 'vendor/ParsedownLegacy.php',
21
- );
22
- if ( version_compare(PHP_VERSION, '5.3.0', '>=') ) {
23
- $this->staticMap['Parsedown'] = 'vendor/Parsedown.php';
24
- }
25
-
26
- spl_autoload_register(array($this, 'autoload'));
27
- }
28
-
29
- public function autoload($className) {
30
- if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
31
- /** @noinspection PhpIncludeInspection */
32
- include ($this->libraryDir . $this->staticMap[$className]);
33
- return;
34
- }
35
-
36
- if (strpos($className, $this->prefix) === 0) {
37
- $path = substr($className, strlen($this->prefix));
38
- $path = str_replace('_', '/', $path);
39
- $path = $this->rootDir . $path . '.php';
40
-
41
- if (file_exists($path)) {
42
- /** @noinspection PhpIncludeInspection */
43
- include $path;
44
- }
45
- }
46
- }
47
- }
48
-
49
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/DebugBar/Extension.php DELETED
@@ -1,177 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_DebugBar_Extension', false) ):
3
-
4
- class Puc_v4p4_DebugBar_Extension {
5
- const RESPONSE_BODY_LENGTH_LIMIT = 4000;
6
-
7
- /** @var Puc_v4p4_UpdateChecker */
8
- protected $updateChecker;
9
- protected $panelClass = 'Puc_v4p4_DebugBar_Panel';
10
-
11
- public function __construct($updateChecker, $panelClass = null) {
12
- $this->updateChecker = $updateChecker;
13
- if ( isset($panelClass) ) {
14
- $this->panelClass = $panelClass;
15
- }
16
-
17
- add_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
18
- add_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
19
-
20
- add_action('wp_ajax_puc_v4_debug_check_now', array($this, 'ajaxCheckNow'));
21
- }
22
-
23
- /**
24
- * Register the PUC Debug Bar panel.
25
- *
26
- * @param array $panels
27
- * @return array
28
- */
29
- public function addDebugBarPanel($panels) {
30
- if ( $this->updateChecker->userCanInstallUpdates() ) {
31
- $panels[] = new $this->panelClass($this->updateChecker);
32
- }
33
- return $panels;
34
- }
35
-
36
- /**
37
- * Enqueue our Debug Bar scripts and styles.
38
- */
39
- public function enqueuePanelDependencies() {
40
- wp_enqueue_style(
41
- 'puc-debug-bar-style-v4',
42
- $this->getLibraryUrl("/css/puc-debug-bar.css"),
43
- array('debug-bar'),
44
- '20171124'
45
- );
46
-
47
- wp_enqueue_script(
48
- 'puc-debug-bar-js-v4',
49
- $this->getLibraryUrl("/js/debug-bar.js"),
50
- array('jquery'),
51
- '20170516'
52
- );
53
- }
54
-
55
- /**
56
- * Run an update check and output the result. Useful for making sure that
57
- * the update checking process works as expected.
58
- */
59
- public function ajaxCheckNow() {
60
- if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
61
- return;
62
- }
63
- $this->preAjaxRequest();
64
- $update = $this->updateChecker->checkForUpdates();
65
- if ( $update !== null ) {
66
- echo "An update is available:";
67
- echo '<pre>', htmlentities(print_r($update, true)), '</pre>';
68
- } else {
69
- echo 'No updates found.';
70
- }
71
-
72
- $errors = $this->updateChecker->getLastRequestApiErrors();
73
- if ( !empty($errors) ) {
74
- printf('<p>The update checker encountered %d API error%s.</p>', count($errors), (count($errors) > 1) ? 's' : '');
75
-
76
- foreach (array_values($errors) as $num => $item) {
77
- $wpError = $item['error'];
78
- /** @var WP_Error $wpError */
79
- printf('<h4>%d) %s</h4>', $num + 1, esc_html($wpError->get_error_message()));
80
-
81
- echo '<dl>';
82
- printf('<dt>Error code:</dt><dd><code>%s</code></dd>', esc_html($wpError->get_error_code()));
83
-
84
- if ( isset($item['url']) ) {
85
- printf('<dt>Requested URL:</dt><dd><code>%s</code></dd>', esc_html($item['url']));
86
- }
87
-
88
- if ( isset($item['httpResponse']) ) {
89
- if ( is_wp_error($item['httpResponse']) ) {
90
- $httpError = $item['httpResponse'];
91
- /** @var WP_Error $httpError */
92
- printf(
93
- '<dt>WordPress HTTP API error:</dt><dd>%s (<code>%s</code>)</dd>',
94
- esc_html($httpError->get_error_message()),
95
- esc_html($httpError->get_error_code())
96
- );
97
- } else {
98
- //Status code.
99
- printf(
100
- '<dt>HTTP status:</dt><dd><code>%d %s</code></dd>',
101
- wp_remote_retrieve_response_code($item['httpResponse']),
102
- wp_remote_retrieve_response_message($item['httpResponse'])
103
- );
104
-
105
- //Headers.
106
- echo '<dt>Response headers:</dt><dd><pre>';
107
- foreach (wp_remote_retrieve_headers($item['httpResponse']) as $name => $value) {
108
- printf("%s: %s\n", esc_html($name), esc_html($value));
109
- }
110
- echo '</pre></dd>';
111
-
112
- //Body.
113
- $body = wp_remote_retrieve_body($item['httpResponse']);
114
- if ( $body === '' ) {
115
- $body = '(Empty response.)';
116
- } else if ( strlen($body) > self::RESPONSE_BODY_LENGTH_LIMIT ) {
117
- $length = strlen($body);
118
- $body = substr($body, 0, self::RESPONSE_BODY_LENGTH_LIMIT)
119
- . sprintf("\n(Long string truncated. Total length: %d bytes.)", $length);
120
- }
121
-
122
- printf('<dt>Response body:</dt><dd><pre>%s</pre></dd>', esc_html($body));
123
- }
124
- }
125
- echo '<dl>';
126
- }
127
- }
128
-
129
- exit;
130
- }
131
-
132
- /**
133
- * Check access permissions and enable error display (for debugging).
134
- */
135
- protected function preAjaxRequest() {
136
- if ( !$this->updateChecker->userCanInstallUpdates() ) {
137
- die('Access denied');
138
- }
139
- check_ajax_referer('puc-ajax');
140
-
141
- error_reporting(E_ALL);
142
- @ini_set('display_errors', 'On');
143
- }
144
-
145
- /**
146
- * @param string $filePath
147
- * @return string
148
- */
149
- private function getLibraryUrl($filePath) {
150
- $absolutePath = realpath(dirname(__FILE__) . '/../../../' . ltrim($filePath, '/'));
151
-
152
- //Where is the library located inside the WordPress directory structure?
153
- $absolutePath = Puc_v4p4_Factory::normalizePath($absolutePath);
154
-
155
- $pluginDir = Puc_v4p4_Factory::normalizePath(WP_PLUGIN_DIR);
156
- $muPluginDir = Puc_v4p4_Factory::normalizePath(WPMU_PLUGIN_DIR);
157
- $themeDir = Puc_v4p4_Factory::normalizePath(get_theme_root());
158
-
159
- if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
160
- //It's part of a plugin.
161
- return plugins_url(basename($absolutePath), $absolutePath);
162
- } else if ( strpos($absolutePath, $themeDir) === 0 ) {
163
- //It's part of a theme.
164
- $relativePath = substr($absolutePath, strlen($themeDir) + 1);
165
- $template = substr($relativePath, 0, strpos($relativePath, '/'));
166
- $baseUrl = get_theme_root_uri($template);
167
-
168
- if ( !empty($baseUrl) && $relativePath ) {
169
- return $baseUrl . '/' . $relativePath;
170
- }
171
- }
172
-
173
- return '';
174
- }
175
- }
176
-
177
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/DebugBar/Panel.php DELETED
@@ -1,165 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_DebugBar_Panel', false) && class_exists('Debug_Bar_Panel', false) ):
4
-
5
- class Puc_v4p4_DebugBar_Panel extends Debug_Bar_Panel {
6
- /** @var Puc_v4p4_UpdateChecker */
7
- protected $updateChecker;
8
-
9
- private $responseBox = '<div class="puc-ajax-response" style="display: none;"></div>';
10
-
11
- public function __construct($updateChecker) {
12
- $this->updateChecker = $updateChecker;
13
- $title = sprintf(
14
- '<span class="puc-debug-menu-link-%s">PUC (%s)</span>',
15
- esc_attr($this->updateChecker->getUniqueName('uid')),
16
- $this->updateChecker->slug
17
- );
18
- parent::__construct($title);
19
- }
20
-
21
- public function render() {
22
- printf(
23
- '<div class="puc-debug-bar-panel-v4" id="%1$s" data-slug="%2$s" data-uid="%3$s" data-nonce="%4$s">',
24
- esc_attr($this->updateChecker->getUniqueName('debug-bar-panel')),
25
- esc_attr($this->updateChecker->slug),
26
- esc_attr($this->updateChecker->getUniqueName('uid')),
27
- esc_attr(wp_create_nonce('puc-ajax'))
28
- );
29
-
30
- $this->displayConfiguration();
31
- $this->displayStatus();
32
- $this->displayCurrentUpdate();
33
-
34
- echo '</div>';
35
- }
36
-
37
- private function displayConfiguration() {
38
- echo '<h3>Configuration</h3>';
39
- echo '<table class="puc-debug-data">';
40
- $this->displayConfigHeader();
41
- $this->row('Slug', htmlentities($this->updateChecker->slug));
42
- $this->row('DB option', htmlentities($this->updateChecker->optionName));
43
-
44
- $requestInfoButton = $this->getMetadataButton();
45
- $this->row('Metadata URL', htmlentities($this->updateChecker->metadataUrl) . ' ' . $requestInfoButton . $this->responseBox);
46
-
47
- $scheduler = $this->updateChecker->scheduler;
48
- if ( $scheduler->checkPeriod > 0 ) {
49
- $this->row('Automatic checks', 'Every ' . $scheduler->checkPeriod . ' hours');
50
- } else {
51
- $this->row('Automatic checks', 'Disabled');
52
- }
53
-
54
- if ( isset($scheduler->throttleRedundantChecks) ) {
55
- if ( $scheduler->throttleRedundantChecks && ($scheduler->checkPeriod > 0) ) {
56
- $this->row(
57
- 'Throttling',
58
- sprintf(
59
- 'Enabled. If an update is already available, check for updates every %1$d hours instead of every %2$d hours.',
60
- $scheduler->throttledCheckPeriod,
61
- $scheduler->checkPeriod
62
- )
63
- );
64
- } else {
65
- $this->row('Throttling', 'Disabled');
66
- }
67
- }
68
-
69
- $this->updateChecker->onDisplayConfiguration($this);
70
-
71
- echo '</table>';
72
- }
73
-
74
- protected function displayConfigHeader() {
75
- //Do nothing. This should be implemented in subclasses.
76
- }
77
-
78
- protected function getMetadataButton() {
79
- return '';
80
- }
81
-
82
- private function displayStatus() {
83
- echo '<h3>Status</h3>';
84
- echo '<table class="puc-debug-data">';
85
- $state = $this->updateChecker->getUpdateState();
86
- $checkNowButton = '';
87
- if ( function_exists('get_submit_button') ) {
88
- $checkNowButton = get_submit_button(
89
- 'Check Now',
90
- 'secondary',
91
- 'puc-check-now-button',
92
- false,
93
- array('id' => $this->updateChecker->getUniqueName('check-now-button'))
94
- );
95
- }
96
-
97
- if ( $state->getLastCheck() > 0 ) {
98
- $this->row('Last check', $this->formatTimeWithDelta($state->getLastCheck()) . ' ' . $checkNowButton . $this->responseBox);
99
- } else {
100
- $this->row('Last check', 'Never');
101
- }
102
-
103
- $nextCheck = wp_next_scheduled($this->updateChecker->scheduler->getCronHookName());
104
- $this->row('Next automatic check', $this->formatTimeWithDelta($nextCheck));
105
-
106
- if ( $state->getCheckedVersion() !== '' ) {
107
- $this->row('Checked version', htmlentities($state->getCheckedVersion()));
108
- $this->row('Cached update', $state->getUpdate());
109
- }
110
- $this->row('Update checker class', htmlentities(get_class($this->updateChecker)));
111
- echo '</table>';
112
- }
113
-
114
- private function displayCurrentUpdate() {
115
- $update = $this->updateChecker->getUpdate();
116
- if ( $update !== null ) {
117
- echo '<h3>An Update Is Available</h3>';
118
- echo '<table class="puc-debug-data">';
119
- $fields = $this->getUpdateFields();
120
- foreach($fields as $field) {
121
- if ( property_exists($update, $field) ) {
122
- $this->row(ucwords(str_replace('_', ' ', $field)), htmlentities($update->$field));
123
- }
124
- }
125
- echo '</table>';
126
- } else {
127
- echo '<h3>No updates currently available</h3>';
128
- }
129
- }
130
-
131
- protected function getUpdateFields() {
132
- return array('version', 'download_url', 'slug',);
133
- }
134
-
135
- private function formatTimeWithDelta($unixTime) {
136
- if ( empty($unixTime) ) {
137
- return 'Never';
138
- }
139
-
140
- $delta = time() - $unixTime;
141
- $result = human_time_diff(time(), $unixTime);
142
- if ( $delta < 0 ) {
143
- $result = 'after ' . $result;
144
- } else {
145
- $result = $result . ' ago';
146
- }
147
- $result .= ' (' . $this->formatTimestamp($unixTime) . ')';
148
- return $result;
149
- }
150
-
151
- private function formatTimestamp($unixTime) {
152
- return gmdate('Y-m-d H:i:s', $unixTime + (get_option('gmt_offset') * 3600));
153
- }
154
-
155
- public function row($name, $value) {
156
- if ( is_object($value) || is_array($value) ) {
157
- $value = '<pre>' . htmlentities(print_r($value, true)) . '</pre>';
158
- } else if ($value === null) {
159
- $value = '<code>null</code>';
160
- }
161
- printf('<tr><th scope="row">%1$s</th> <td>%2$s</td></tr>', $name, $value);
162
- }
163
- }
164
-
165
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/DebugBar/PluginExtension.php DELETED
@@ -1,33 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_DebugBar_PluginExtension', false) ):
3
-
4
- class Puc_v4p4_DebugBar_PluginExtension extends Puc_v4p4_DebugBar_Extension {
5
- /** @var Puc_v4p4_Plugin_UpdateChecker */
6
- protected $updateChecker;
7
-
8
- public function __construct($updateChecker) {
9
- parent::__construct($updateChecker, 'Puc_v4p4_DebugBar_PluginPanel');
10
-
11
- add_action('wp_ajax_puc_v4_debug_request_info', array($this, 'ajaxRequestInfo'));
12
- }
13
-
14
- /**
15
- * Request plugin info and output it.
16
- */
17
- public function ajaxRequestInfo() {
18
- if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
19
- return;
20
- }
21
- $this->preAjaxRequest();
22
- $info = $this->updateChecker->requestInfo();
23
- if ( $info !== null ) {
24
- echo 'Successfully retrieved plugin info from the metadata URL:';
25
- echo '<pre>', htmlentities(print_r($info, true)), '</pre>';
26
- } else {
27
- echo 'Failed to retrieve plugin info from the metadata URL.';
28
- }
29
- exit;
30
- }
31
- }
32
-
33
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/DebugBar/PluginPanel.php DELETED
@@ -1,38 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_DebugBar_PluginPanel', false) ):
4
-
5
- class Puc_v4p4_DebugBar_PluginPanel extends Puc_v4p4_DebugBar_Panel {
6
- /**
7
- * @var Puc_v4p4_Plugin_UpdateChecker
8
- */
9
- protected $updateChecker;
10
-
11
- protected function displayConfigHeader() {
12
- $this->row('Plugin file', htmlentities($this->updateChecker->pluginFile));
13
- parent::displayConfigHeader();
14
- }
15
-
16
- protected function getMetadataButton() {
17
- $requestInfoButton = '';
18
- if ( function_exists('get_submit_button') ) {
19
- $requestInfoButton = get_submit_button(
20
- 'Request Info',
21
- 'secondary',
22
- 'puc-request-info-button',
23
- false,
24
- array('id' => $this->updateChecker->getUniqueName('request-info-button'))
25
- );
26
- }
27
- return $requestInfoButton;
28
- }
29
-
30
- protected function getUpdateFields() {
31
- return array_merge(
32
- parent::getUpdateFields(),
33
- array('homepage', 'upgrade_notice', 'tested',)
34
- );
35
- }
36
- }
37
-
38
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/DebugBar/ThemePanel.php DELETED
@@ -1,21 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_DebugBar_ThemePanel', false) ):
4
-
5
- class Puc_v4p4_DebugBar_ThemePanel extends Puc_v4p4_DebugBar_Panel {
6
- /**
7
- * @var Puc_v4p4_Theme_UpdateChecker
8
- */
9
- protected $updateChecker;
10
-
11
- protected function displayConfigHeader() {
12
- $this->row('Theme directory', htmlentities($this->updateChecker->directoryName));
13
- parent::displayConfigHeader();
14
- }
15
-
16
- protected function getUpdateFields() {
17
- return array_merge(parent::getUpdateFields(), array('details_url'));
18
- }
19
- }
20
-
21
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Factory.php DELETED
@@ -1,292 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_Factory', false) ):
3
-
4
- /**
5
- * A factory that builds update checker instances.
6
- *
7
- * When multiple versions of the same class have been loaded (e.g. PluginUpdateChecker 4.0
8
- * and 4.1), this factory will always use the latest available minor version. Register class
9
- * versions by calling {@link PucFactory::addVersion()}.
10
- *
11
- * At the moment it can only build instances of the UpdateChecker class. Other classes are
12
- * intended mainly for internal use and refer directly to specific implementations.
13
- */
14
- class Puc_v4p4_Factory {
15
- protected static $classVersions = array();
16
- protected static $sorted = false;
17
-
18
- protected static $myMajorVersion = '';
19
- protected static $latestCompatibleVersion = '';
20
-
21
- /**
22
- * Create a new instance of the update checker.
23
- *
24
- * This method automatically detects if you're using it for a plugin or a theme and chooses
25
- * the appropriate implementation for your update source (JSON file, GitHub, BitBucket, etc).
26
- *
27
- * @see Puc_v4p4_UpdateChecker::__construct
28
- *
29
- * @param string $metadataUrl The URL of the metadata file, a GitHub repository, or another supported update source.
30
- * @param string $fullPath Full path to the main plugin file or to the theme directory.
31
- * @param string $slug Custom slug. Defaults to the name of the main plugin file or the theme directory.
32
- * @param int $checkPeriod How often to check for updates (in hours).
33
- * @param string $optionName Where to store book-keeping info about update checks.
34
- * @param string $muPluginFile The plugin filename relative to the mu-plugins directory.
35
- * @return Puc_v4p4_Plugin_UpdateChecker|Puc_v4p4_Theme_UpdateChecker|Puc_v4p4_Vcs_BaseChecker
36
- */
37
- public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
38
- $fullPath = self::normalizePath($fullPath);
39
- $id = null;
40
-
41
- //Plugin or theme?
42
- $themeDirectory = self::getThemeDirectoryName($fullPath);
43
- if ( self::isPluginFile($fullPath) ) {
44
- $type = 'Plugin';
45
- $id = $fullPath;
46
- } else if ( $themeDirectory !== null ) {
47
- $type = 'Theme';
48
- $id = $themeDirectory;
49
- } else {
50
- throw new RuntimeException(sprintf(
51
- 'The update checker cannot determine if "%s" is a plugin or a theme. ' .
52
- 'This is a bug. Please contact the PUC developer.',
53
- htmlentities($fullPath)
54
- ));
55
- }
56
-
57
- //Which hosting service does the URL point to?
58
- $service = self::getVcsService($metadataUrl);
59
-
60
- $apiClass = null;
61
- if ( empty($service) ) {
62
- //The default is to get update information from a remote JSON file.
63
- $checkerClass = $type . '_UpdateChecker';
64
- } else {
65
- //You can also use a VCS repository like GitHub.
66
- $checkerClass = 'Vcs_' . $type . 'UpdateChecker';
67
- $apiClass = $service . 'Api';
68
- }
69
-
70
- $checkerClass = self::getCompatibleClassVersion($checkerClass);
71
- if ( $checkerClass === null ) {
72
- trigger_error(
73
- sprintf(
74
- 'PUC %s does not support updates for %ss %s',
75
- htmlentities(self::$latestCompatibleVersion),
76
- strtolower($type),
77
- $service ? ('hosted on ' . htmlentities($service)) : 'using JSON metadata'
78
- ),
79
- E_USER_ERROR
80
- );
81
- return null;
82
- }
83
-
84
- if ( !isset($apiClass) ) {
85
- //Plain old update checker.
86
- return new $checkerClass($metadataUrl, $id, $slug, $checkPeriod, $optionName, $muPluginFile);
87
- } else {
88
- //VCS checker + an API client.
89
- $apiClass = self::getCompatibleClassVersion($apiClass);
90
- if ( $apiClass === null ) {
91
- trigger_error(sprintf(
92
- 'PUC %s does not support %s',
93
- htmlentities(self::$latestCompatibleVersion),
94
- htmlentities($service)
95
- ), E_USER_ERROR);
96
- return null;
97
- }
98
-
99
- return new $checkerClass(
100
- new $apiClass($metadataUrl),
101
- $id,
102
- $slug,
103
- $checkPeriod,
104
- $optionName,
105
- $muPluginFile
106
- );
107
- }
108
- }
109
-
110
- /**
111
- *
112
- * Normalize a filesystem path. Introduced in WP 3.9.
113
- * Copying here allows use of the class on earlier versions.
114
- * This version adapted from WP 4.8.2 (unchanged since 4.5.0)
115
- *
116
- * @param string $path Path to normalize.
117
- * @return string Normalized path.
118
- */
119
- public static function normalizePath($path) {
120
- if ( function_exists('wp_normalize_path') ) {
121
- return wp_normalize_path($path);
122
- }
123
- $path = str_replace('\\', '/', $path);
124
- $path = preg_replace('|(?<=.)/+|', '/', $path);
125
- if ( substr($path, 1, 1) === ':' ) {
126
- $path = ucfirst($path);
127
- }
128
- return $path;
129
- }
130
-
131
- /**
132
- * Check if the path points to a plugin file.
133
- *
134
- * @param string $absolutePath Normalized path.
135
- * @return bool
136
- */
137
- protected static function isPluginFile($absolutePath) {
138
- //Is the file inside the "plugins" or "mu-plugins" directory?
139
- $pluginDir = self::normalizePath(WP_PLUGIN_DIR);
140
- $muPluginDir = self::normalizePath(WPMU_PLUGIN_DIR);
141
- if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
142
- return true;
143
- }
144
-
145
- //Is it a file at all? Caution: is_file() can fail if the parent dir. doesn't have the +x permission set.
146
- if ( !is_file($absolutePath) ) {
147
- return false;
148
- }
149
-
150
- //Does it have a valid plugin header?
151
- //This is a last-ditch check for plugins symlinked from outside the WP root.
152
- if ( function_exists('get_file_data') ) {
153
- $headers = get_file_data($absolutePath, array('Name' => 'Plugin Name'), 'plugin');
154
- return !empty($headers['Name']);
155
- }
156
-
157
- return false;
158
- }
159
-
160
- /**
161
- * Get the name of the theme's directory from a full path to a file inside that directory.
162
- * E.g. "/abc/public_html/wp-content/themes/foo/whatever.php" => "foo".
163
- *
164
- * Note that subdirectories are currently not supported. For example,
165
- * "/xyz/wp-content/themes/my-theme/includes/whatever.php" => NULL.
166
- *
167
- * @param string $absolutePath Normalized path.
168
- * @return string|null Directory name, or NULL if the path doesn't point to a theme.
169
- */
170
- protected static function getThemeDirectoryName($absolutePath) {
171
- if ( is_file($absolutePath) ) {
172
- $absolutePath = dirname($absolutePath);
173
- }
174
-
175
- if ( file_exists($absolutePath . '/style.css') ) {
176
- return basename($absolutePath);
177
- }
178
- return null;
179
- }
180
-
181
- /**
182
- * Get the name of the hosting service that the URL points to.
183
- *
184
- * @param string $metadataUrl
185
- * @return string|null
186
- */
187
- private static function getVcsService($metadataUrl) {
188
- $service = null;
189
-
190
- //Which hosting service does the URL point to?
191
- $host = @parse_url($metadataUrl, PHP_URL_HOST);
192
- $path = @parse_url($metadataUrl, PHP_URL_PATH);
193
- //Check if the path looks like "/user-name/repository".
194
- $usernameRepoRegex = '@^/?([^/]+?)/([^/#?&]+?)/?$@';
195
- if ( preg_match($usernameRepoRegex, $path) ) {
196
- $knownServices = array(
197
- 'github.com' => 'GitHub',
198
- 'bitbucket.org' => 'BitBucket',
199
- 'gitlab.com' => 'GitLab',
200
- );
201
- if ( isset($knownServices[$host]) ) {
202
- $service = $knownServices[$host];
203
- }
204
- }
205
-
206
- return $service;
207
- }
208
-
209
- /**
210
- * Get the latest version of the specified class that has the same major version number
211
- * as this factory class.
212
- *
213
- * @param string $class Partial class name.
214
- * @return string|null Full class name.
215
- */
216
- protected static function getCompatibleClassVersion($class) {
217
- if ( isset(self::$classVersions[$class][self::$latestCompatibleVersion]) ) {
218
- return self::$classVersions[$class][self::$latestCompatibleVersion];
219
- }
220
- return null;
221
- }
222
-
223
- /**
224
- * Get the specific class name for the latest available version of a class.
225
- *
226
- * @param string $class
227
- * @return null|string
228
- */
229
- public static function getLatestClassVersion($class) {
230
- if ( !self::$sorted ) {
231
- self::sortVersions();
232
- }
233
-
234
- if ( isset(self::$classVersions[$class]) ) {
235
- return reset(self::$classVersions[$class]);
236
- } else {
237
- return null;
238
- }
239
- }
240
-
241
- /**
242
- * Sort available class versions in descending order (i.e. newest first).
243
- */
244
- protected static function sortVersions() {
245
- foreach ( self::$classVersions as $class => $versions ) {
246
- uksort($versions, array(__CLASS__, 'compareVersions'));
247
- self::$classVersions[$class] = $versions;
248
- }
249
- self::$sorted = true;
250
- }
251
-
252
- protected static function compareVersions($a, $b) {
253
- return -version_compare($a, $b);
254
- }
255
-
256
- /**
257
- * Register a version of a class.
258
- *
259
- * @access private This method is only for internal use by the library.
260
- *
261
- * @param string $generalClass Class name without version numbers, e.g. 'PluginUpdateChecker'.
262
- * @param string $versionedClass Actual class name, e.g. 'PluginUpdateChecker_1_2'.
263
- * @param string $version Version number, e.g. '1.2'.
264
- */
265
- public static function addVersion($generalClass, $versionedClass, $version) {
266
- if ( empty(self::$myMajorVersion) ) {
267
- $nameParts = explode('_', __CLASS__, 3);
268
- self::$myMajorVersion = substr(ltrim($nameParts[1], 'v'), 0, 1);
269
- }
270
-
271
- //Store the greatest version number that matches our major version.
272
- $components = explode('.', $version);
273
- if ( $components[0] === self::$myMajorVersion ) {
274
-
275
- if (
276
- empty(self::$latestCompatibleVersion)
277
- || version_compare($version, self::$latestCompatibleVersion, '>')
278
- ) {
279
- self::$latestCompatibleVersion = $version;
280
- }
281
-
282
- }
283
-
284
- if ( !isset(self::$classVersions[$generalClass]) ) {
285
- self::$classVersions[$generalClass] = array();
286
- }
287
- self::$classVersions[$generalClass][$version] = $versionedClass;
288
- self::$sorted = false;
289
- }
290
- }
291
-
292
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Metadata.php DELETED
@@ -1,132 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_Metadata', false) ):
3
-
4
- /**
5
- * A base container for holding information about updates and plugin metadata.
6
- *
7
- * @author Janis Elsts
8
- * @copyright 2016
9
- * @access public
10
- */
11
- abstract class Puc_v4p4_Metadata {
12
-
13
- /**
14
- * Create an instance of this class from a JSON document.
15
- *
16
- * @abstract
17
- * @param string $json
18
- * @return self
19
- */
20
- public static function fromJson(/** @noinspection PhpUnusedParameterInspection */ $json) {
21
- throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
22
- }
23
-
24
- /**
25
- * @param string $json
26
- * @param self $target
27
- * @return bool
28
- */
29
- protected static function createFromJson($json, $target) {
30
- /** @var StdClass $apiResponse */
31
- $apiResponse = json_decode($json);
32
- if ( empty($apiResponse) || !is_object($apiResponse) ){
33
- $errorMessage = "Failed to parse update metadata. Try validating your .json file with http://jsonlint.com/";
34
- do_action('puc_api_error', new WP_Error('puc-invalid-json', $errorMessage));
35
- trigger_error($errorMessage, E_USER_NOTICE);
36
- return false;
37
- }
38
-
39
- $valid = $target->validateMetadata($apiResponse);
40
- if ( is_wp_error($valid) ){
41
- do_action('puc_api_error', $valid);
42
- trigger_error($valid->get_error_message(), E_USER_NOTICE);
43
- return false;
44
- }
45
-
46
- foreach(get_object_vars($apiResponse) as $key => $value){
47
- $target->$key = $value;
48
- }
49
-
50
- return true;
51
- }
52
-
53
- /**
54
- * No validation by default! Subclasses should check that the required fields are present.
55
- *
56
- * @param StdClass $apiResponse
57
- * @return bool|WP_Error
58
- */
59
- protected function validateMetadata(/** @noinspection PhpUnusedParameterInspection */ $apiResponse) {
60
- return true;
61
- }
62
-
63
- /**
64
- * Create a new instance by copying the necessary fields from another object.
65
- *
66
- * @abstract
67
- * @param StdClass|self $object The source object.
68
- * @return self The new copy.
69
- */
70
- public static function fromObject(/** @noinspection PhpUnusedParameterInspection */ $object) {
71
- throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
72
- }
73
-
74
- /**
75
- * Create an instance of StdClass that can later be converted back to an
76
- * update or info container. Useful for serialization and caching, as it
77
- * avoids the "incomplete object" problem if the cached value is loaded
78
- * before this class.
79
- *
80
- * @return StdClass
81
- */
82
- public function toStdClass() {
83
- $object = new stdClass();
84
- $this->copyFields($this, $object);
85
- return $object;
86
- }
87
-
88
- /**
89
- * Transform the metadata into the format used by WordPress core.
90
- *
91
- * @return object
92
- */
93
- abstract public function toWpFormat();
94
-
95
- /**
96
- * Copy known fields from one object to another.
97
- *
98
- * @param StdClass|self $from
99
- * @param StdClass|self $to
100
- */
101
- protected function copyFields($from, $to) {
102
- $fields = $this->getFieldNames();
103
-
104
- if ( property_exists($from, 'slug') && !empty($from->slug) ) {
105
- //Let plugins add extra fields without having to create subclasses.
106
- $fields = apply_filters($this->getPrefixedFilter('retain_fields') . '-' . $from->slug, $fields);
107
- }
108
-
109
- foreach ($fields as $field) {
110
- if ( property_exists($from, $field) ) {
111
- $to->$field = $from->$field;
112
- }
113
- }
114
- }
115
-
116
- /**
117
- * @return string[]
118
- */
119
- protected function getFieldNames() {
120
- return array();
121
- }
122
-
123
- /**
124
- * @param string $tag
125
- * @return string
126
- */
127
- protected function getPrefixedFilter($tag) {
128
- return 'puc_' . $tag;
129
- }
130
- }
131
-
132
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/OAuthSignature.php DELETED
@@ -1,88 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_OAuthSignature', false) ):
4
-
5
- /**
6
- * A basic signature generator for zero-legged OAuth 1.0.
7
- */
8
- class Puc_v4p4_OAuthSignature {
9
- private $consumerKey = '';
10
- private $consumerSecret = '';
11
-
12
- public function __construct($consumerKey, $consumerSecret) {
13
- $this->consumerKey = $consumerKey;
14
- $this->consumerSecret = $consumerSecret;
15
- }
16
-
17
- /**
18
- * Sign a URL using OAuth 1.0.
19
- *
20
- * @param string $url The URL to be signed. It may contain query parameters.
21
- * @param string $method HTTP method such as "GET", "POST" and so on.
22
- * @return string The signed URL.
23
- */
24
- public function sign($url, $method = 'GET') {
25
- $parameters = array();
26
-
27
- //Parse query parameters.
28
- $query = @parse_url($url, PHP_URL_QUERY);
29
- if ( !empty($query) ) {
30
- parse_str($query, $parsedParams);
31
- if ( is_array($parameters) ) {
32
- $parameters = $parsedParams;
33
- }
34
- //Remove the query string from the URL. We'll replace it later.
35
- $url = substr($url, 0, strpos($url, '?'));
36
- }
37
-
38
- $parameters = array_merge(
39
- $parameters,
40
- array(
41
- 'oauth_consumer_key' => $this->consumerKey,
42
- 'oauth_nonce' => $this->nonce(),
43
- 'oauth_signature_method' => 'HMAC-SHA1',
44
- 'oauth_timestamp' => time(),
45
- 'oauth_version' => '1.0',
46
- )
47
- );
48
- unset($parameters['oauth_signature']);
49
-
50
- //Parameters must be sorted alphabetically before signing.
51
- ksort($parameters);
52
-
53
- //The most complicated part of the request - generating the signature.
54
- //The string to sign contains the HTTP method, the URL path, and all of
55
- //our query parameters. Everything is URL encoded. Then we concatenate
56
- //them with ampersands into a single string to hash.
57
- $encodedVerb = urlencode($method);
58
- $encodedUrl = urlencode($url);
59
- $encodedParams = urlencode(http_build_query($parameters, '', '&'));
60
-
61
- $stringToSign = $encodedVerb . '&' . $encodedUrl . '&' . $encodedParams;
62
-
63
- //Since we only have one OAuth token (the consumer secret) we only have
64
- //to use it as our HMAC key. However, we still have to append an & to it
65
- //as if we were using it with additional tokens.
66
- $secret = urlencode($this->consumerSecret) . '&';
67
-
68
- //The signature is a hash of the consumer key and the base string. Note
69
- //that we have to get the raw output from hash_hmac and base64 encode
70
- //the binary data result.
71
- $parameters['oauth_signature'] = base64_encode(hash_hmac('sha1', $stringToSign, $secret, true));
72
-
73
- return ($url . '?' . http_build_query($parameters));
74
- }
75
-
76
- /**
77
- * Generate a random nonce.
78
- *
79
- * @return string
80
- */
81
- private function nonce() {
82
- $mt = microtime();
83
- $rand = mt_rand();
84
- return md5($mt . '_' . $rand);
85
- }
86
- }
87
-
88
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Plugin/Info.php DELETED
@@ -1,130 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_Plugin_Info', false) ):
3
-
4
- /**
5
- * A container class for holding and transforming various plugin metadata.
6
- *
7
- * @author Janis Elsts
8
- * @copyright 2016
9
- * @access public
10
- */
11
- class Puc_v4p4_Plugin_Info extends Puc_v4p4_Metadata {
12
- //Most fields map directly to the contents of the plugin's info.json file.
13
- //See the relevant docs for a description of their meaning.
14
- public $name;
15
- public $slug;
16
- public $version;
17
- public $homepage;
18
- public $sections = array();
19
- public $download_url;
20
-
21
- public $banners;
22
- public $icons = array();
23
- public $translations = array();
24
-
25
- public $author;
26
- public $author_homepage;
27
-
28
- public $requires;
29
- public $tested;
30
- public $upgrade_notice;
31
-
32
- public $rating;
33
- public $num_ratings;
34
- public $downloaded;
35
- public $active_installs;
36
- public $last_updated;
37
-
38
- public $id = 0; //The native WP.org API returns numeric plugin IDs, but they're not used for anything.
39
-
40
- public $filename; //Plugin filename relative to the plugins directory.
41
-
42
- /**
43
- * Create a new instance of Plugin Info from JSON-encoded plugin info
44
- * returned by an external update API.
45
- *
46
- * @param string $json Valid JSON string representing plugin info.
47
- * @return self|null New instance of Plugin Info, or NULL on error.
48
- */
49
- public static function fromJson($json){
50
- $instance = new self();
51
-
52
- if ( !parent::createFromJson($json, $instance) ) {
53
- return null;
54
- }
55
-
56
- //json_decode decodes assoc. arrays as objects. We want them as arrays.
57
- $instance->sections = (array)$instance->sections;
58
- $instance->icons = (array)$instance->icons;
59
-
60
- return $instance;
61
- }
62
-
63
- /**
64
- * Very, very basic validation.
65
- *
66
- * @param StdClass $apiResponse
67
- * @return bool|WP_Error
68
- */
69
- protected function validateMetadata($apiResponse) {
70
- if (
71
- !isset($apiResponse->name, $apiResponse->version)
72
- || empty($apiResponse->name)
73
- || empty($apiResponse->version)
74
- ) {
75
- return new WP_Error(
76
- 'puc-invalid-metadata',
77
- "The plugin metadata file does not contain the required 'name' and/or 'version' keys."
78
- );
79
- }
80
- return true;
81
- }
82
-
83
-
84
- /**
85
- * Transform plugin info into the format used by the native WordPress.org API
86
- *
87
- * @return object
88
- */
89
- public function toWpFormat(){
90
- $info = new stdClass;
91
-
92
- //The custom update API is built so that many fields have the same name and format
93
- //as those returned by the native WordPress.org API. These can be assigned directly.
94
- $sameFormat = array(
95
- 'name', 'slug', 'version', 'requires', 'tested', 'rating', 'upgrade_notice',
96
- 'num_ratings', 'downloaded', 'active_installs', 'homepage', 'last_updated',
97
- );
98
- foreach($sameFormat as $field){
99
- if ( isset($this->$field) ) {
100
- $info->$field = $this->$field;
101
- } else {
102
- $info->$field = null;
103
- }
104
- }
105
-
106
- //Other fields need to be renamed and/or transformed.
107
- $info->download_link = $this->download_url;
108
- $info->author = $this->getFormattedAuthor();
109
- $info->sections = array_merge(array('description' => ''), $this->sections);
110
-
111
- if ( !empty($this->banners) ) {
112
- //WP expects an array with two keys: "high" and "low". Both are optional.
113
- //Docs: https://wordpress.org/plugins/about/faq/#banners
114
- $info->banners = is_object($this->banners) ? get_object_vars($this->banners) : $this->banners;
115
- $info->banners = array_intersect_key($info->banners, array('high' => true, 'low' => true));
116
- }
117
-
118
- return $info;
119
- }
120
-
121
- protected function getFormattedAuthor() {
122
- if ( !empty($this->author_homepage) ){
123
- /** @noinspection HtmlUnknownTarget */
124
- return sprintf('<a href="%s">%s</a>', $this->author_homepage, $this->author);
125
- }
126
- return $this->author;
127
- }
128
- }
129
-
130
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Plugin/Update.php DELETED
@@ -1,110 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_Plugin_Update', false) ):
3
-
4
- /**
5
- * A simple container class for holding information about an available update.
6
- *
7
- * @author Janis Elsts
8
- * @copyright 2016
9
- * @access public
10
- */
11
- class Puc_v4p4_Plugin_Update extends Puc_v4p4_Update {
12
- public $id = 0;
13
- public $homepage;
14
- public $upgrade_notice;
15
- public $tested;
16
- public $icons = array();
17
- public $filename; //Plugin filename relative to the plugins directory.
18
-
19
- protected static $extraFields = array(
20
- 'id', 'homepage', 'tested', 'upgrade_notice', 'icons', 'filename',
21
- );
22
-
23
- /**
24
- * Create a new instance of PluginUpdate from its JSON-encoded representation.
25
- *
26
- * @param string $json
27
- * @return Puc_v4p4_Plugin_Update|null
28
- */
29
- public static function fromJson($json){
30
- //Since update-related information is simply a subset of the full plugin info,
31
- //we can parse the update JSON as if it was a plugin info string, then copy over
32
- //the parts that we care about.
33
- $pluginInfo = Puc_v4p4_Plugin_Info::fromJson($json);
34
- if ( $pluginInfo !== null ) {
35
- return self::fromPluginInfo($pluginInfo);
36
- } else {
37
- return null;
38
- }
39
- }
40
-
41
- /**
42
- * Create a new instance of PluginUpdate based on an instance of PluginInfo.
43
- * Basically, this just copies a subset of fields from one object to another.
44
- *
45
- * @param Puc_v4p4_Plugin_Info $info
46
- * @return Puc_v4p4_Plugin_Update
47
- */
48
- public static function fromPluginInfo($info){
49
- return self::fromObject($info);
50
- }
51
-
52
- /**
53
- * Create a new instance by copying the necessary fields from another object.
54
- *
55
- * @param StdClass|Puc_v4p4_Plugin_Info|Puc_v4p4_Plugin_Update $object The source object.
56
- * @return Puc_v4p4_Plugin_Update The new copy.
57
- */
58
- public static function fromObject($object) {
59
- $update = new self();
60
- $update->copyFields($object, $update);
61
- return $update;
62
- }
63
-
64
- /**
65
- * @return string[]
66
- */
67
- protected function getFieldNames() {
68
- return array_merge(parent::getFieldNames(), self::$extraFields);
69
- }
70
-
71
- /**
72
- * Transform the update into the format used by WordPress native plugin API.
73
- *
74
- * @return object
75
- */
76
- public function toWpFormat() {
77
- $update = parent::toWpFormat();
78
-
79
- $update->id = $this->id;
80
- $update->url = $this->homepage;
81
- $update->tested = $this->tested;
82
- $update->plugin = $this->filename;
83
-
84
- if ( !empty($this->upgrade_notice) ) {
85
- $update->upgrade_notice = $this->upgrade_notice;
86
- }
87
-
88
- if ( !empty($this->icons) && is_array($this->icons) ) {
89
- //This should be an array with up to 4 keys: 'svg', '1x', '2x' and 'default'.
90
- //Docs: https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-icons
91
- $icons = array_intersect_key(
92
- $this->icons,
93
- array('svg' => true, '1x' => true, '2x' => true, 'default' => true)
94
- );
95
- if ( !empty($icons) ) {
96
- $update->icons = $icons;
97
-
98
- //It appears that the 'default' icon isn't used anywhere in WordPress 4.9,
99
- //but lets set it just in case a future release needs it.
100
- if ( !isset($update->icons['default']) ) {
101
- $update->icons['default'] = current($update->icons);
102
- }
103
- }
104
- }
105
-
106
- return $update;
107
- }
108
- }
109
-
110
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Plugin/UpdateChecker.php DELETED
@@ -1,740 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_Plugin_UpdateChecker', false) ):
3
-
4
- /**
5
- * A custom plugin update checker.
6
- *
7
- * @author Janis Elsts
8
- * @copyright 2016
9
- * @access public
10
- */
11
- class Puc_v4p4_Plugin_UpdateChecker extends Puc_v4p4_UpdateChecker {
12
- protected $updateTransient = 'update_plugins';
13
- protected $translationType = 'plugin';
14
-
15
- public $pluginAbsolutePath = ''; //Full path of the main plugin file.
16
- public $pluginFile = ''; //Plugin filename relative to the plugins directory. Many WP APIs use this to identify plugins.
17
- public $muPluginFile = ''; //For MU plugins, the plugin filename relative to the mu-plugins directory.
18
-
19
- private $cachedInstalledVersion = null;
20
- private $manualCheckErrorTransient = '';
21
-
22
- /**
23
- * Class constructor.
24
- *
25
- * @param string $metadataUrl The URL of the plugin's metadata file.
26
- * @param string $pluginFile Fully qualified path to the main plugin file.
27
- * @param string $slug The plugin's 'slug'. If not specified, the filename part of $pluginFile sans '.php' will be used as the slug.
28
- * @param integer $checkPeriod How often to check for updates (in hours). Defaults to checking every 12 hours. Set to 0 to disable automatic update checks.
29
- * @param string $optionName Where to store book-keeping info about update checks. Defaults to 'external_updates-$slug'.
30
- * @param string $muPluginFile Optional. The plugin filename relative to the mu-plugins directory.
31
- */
32
- public function __construct($metadataUrl, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = ''){
33
- $this->pluginAbsolutePath = $pluginFile;
34
- $this->pluginFile = plugin_basename($this->pluginAbsolutePath);
35
- $this->muPluginFile = $muPluginFile;
36
-
37
- //If no slug is specified, use the name of the main plugin file as the slug.
38
- //For example, 'my-cool-plugin/cool-plugin.php' becomes 'cool-plugin'.
39
- if ( empty($slug) ){
40
- $slug = basename($this->pluginFile, '.php');
41
- }
42
-
43
- //Plugin slugs must be unique.
44
- $slugCheckFilter = 'puc_is_slug_in_use-' . $slug;
45
- $slugUsedBy = apply_filters($slugCheckFilter, false);
46
- if ( $slugUsedBy ) {
47
- $this->triggerError(sprintf(
48
- 'Plugin slug "%s" is already in use by %s. Slugs must be unique.',
49
- htmlentities($slug),
50
- htmlentities($slugUsedBy)
51
- ), E_USER_ERROR);
52
- }
53
- add_filter($slugCheckFilter, array($this, 'getAbsolutePath'));
54
-
55
- //Backwards compatibility: If the plugin is a mu-plugin but no $muPluginFile is specified, assume
56
- //it's the same as $pluginFile given that it's not in a subdirectory (WP only looks in the base dir).
57
- if ( (strpbrk($this->pluginFile, '/\\') === false) && $this->isUnknownMuPlugin() ) {
58
- $this->muPluginFile = $this->pluginFile;
59
- }
60
-
61
- //To prevent a crash during plugin uninstallation, remove updater hooks when the user removes the plugin.
62
- //Details: https://github.com/YahnisElsts/plugin-update-checker/issues/138#issuecomment-335590964
63
- add_action('uninstall_' . $this->pluginFile, array($this, 'removeHooks'));
64
-
65
- $this->manualCheckErrorTransient = $this->getUniqueName('manual_check_errors');
66
-
67
- parent::__construct($metadataUrl, dirname($this->pluginFile), $slug, $checkPeriod, $optionName);
68
- }
69
-
70
- /**
71
- * Create an instance of the scheduler.
72
- *
73
- * @param int $checkPeriod
74
- * @return Puc_v4p4_Scheduler
75
- */
76
- protected function createScheduler($checkPeriod) {
77
- $scheduler = new Puc_v4p4_Scheduler($this, $checkPeriod, array('load-plugins.php'));
78
- register_deactivation_hook($this->pluginFile, array($scheduler, 'removeUpdaterCron'));
79
- return $scheduler;
80
- }
81
-
82
- /**
83
- * Install the hooks required to run periodic update checks and inject update info
84
- * into WP data structures.
85
- *
86
- * @return void
87
- */
88
- protected function installHooks(){
89
- //Override requests for plugin information
90
- add_filter('plugins_api', array($this, 'injectInfo'), 20, 3);
91
-
92
- add_filter('plugin_row_meta', array($this, 'addViewDetailsLink'), 10, 3);
93
- add_filter('plugin_row_meta', array($this, 'addCheckForUpdatesLink'), 10, 2);
94
- add_action('admin_init', array($this, 'handleManualCheck'));
95
- add_action('all_admin_notices', array($this, 'displayManualCheckResult'));
96
-
97
- //Clear the version number cache when something - anything - is upgraded or WP clears the update cache.
98
- add_filter('upgrader_post_install', array($this, 'clearCachedVersion'));
99
- add_action('delete_site_transient_update_plugins', array($this, 'clearCachedVersion'));
100
-
101
- parent::installHooks();
102
- }
103
-
104
- /**
105
- * Remove update checker hooks.
106
- *
107
- * The intent is to prevent a fatal error that can happen if the plugin has an uninstall
108
- * hook. During uninstallation, WP includes the main plugin file (which creates a PUC instance),
109
- * the uninstall hook runs, WP deletes the plugin files and then updates some transients.
110
- * If PUC hooks are still around at this time, they could throw an error while trying to
111
- * autoload classes from files that no longer exist.
112
- *
113
- * The "site_transient_{$transient}" filter is the main problem here, but let's also remove
114
- * most other PUC hooks to be safe.
115
- *
116
- * @internal
117
- */
118
- public function removeHooks() {
119
- parent::removeHooks();
120
-
121
- remove_filter('plugins_api', array($this, 'injectInfo'), 20);
122
-
123
- remove_filter('plugin_row_meta', array($this, 'addViewDetailsLink'), 10);
124
- remove_filter('plugin_row_meta', array($this, 'addCheckForUpdatesLink'), 10);
125
- remove_action('admin_init', array($this, 'handleManualCheck'));
126
- remove_action('all_admin_notices', array($this, 'displayManualCheckResult'));
127
-
128
- remove_filter('upgrader_post_install', array($this, 'clearCachedVersion'));
129
- remove_action('delete_site_transient_update_plugins', array($this, 'clearCachedVersion'));
130
- }
131
-
132
- /**
133
- * Retrieve plugin info from the configured API endpoint.
134
- *
135
- * @uses wp_remote_get()
136
- *
137
- * @param array $queryArgs Additional query arguments to append to the request. Optional.
138
- * @return Puc_v4p4_Plugin_Info
139
- */
140
- public function requestInfo($queryArgs = array()) {
141
- list($pluginInfo, $result) = $this->requestMetadata('Puc_v4p4_Plugin_Info', 'request_info', $queryArgs);
142
-
143
- if ( $pluginInfo !== null ) {
144
- /** @var Puc_v4p4_Plugin_Info $pluginInfo */
145
- $pluginInfo->filename = $this->pluginFile;
146
- $pluginInfo->slug = $this->slug;
147
- }
148
-
149
- $pluginInfo = apply_filters($this->getUniqueName('request_info_result'), $pluginInfo, $result);
150
- return $pluginInfo;
151
- }
152
-
153
- /**
154
- * Retrieve the latest update (if any) from the configured API endpoint.
155
- *
156
- * @uses PluginUpdateChecker::requestInfo()
157
- *
158
- * @return Puc_v4p4_Update|null An instance of Plugin_Update, or NULL when no updates are available.
159
- */
160
- public function requestUpdate() {
161
- //For the sake of simplicity, this function just calls requestInfo()
162
- //and transforms the result accordingly.
163
- $pluginInfo = $this->requestInfo(array('checking_for_updates' => '1'));
164
- if ( $pluginInfo === null ){
165
- return null;
166
- }
167
- $update = Puc_v4p4_Plugin_Update::fromPluginInfo($pluginInfo);
168
-
169
- $update = $this->filterUpdateResult($update);
170
-
171
- return $update;
172
- }
173
-
174
- /**
175
- * Get the currently installed version of the plugin.
176
- *
177
- * @return string Version number.
178
- */
179
- public function getInstalledVersion(){
180
- if ( isset($this->cachedInstalledVersion) ) {
181
- return $this->cachedInstalledVersion;
182
- }
183
-
184
- $pluginHeader = $this->getPluginHeader();
185
- if ( isset($pluginHeader['Version']) ) {
186
- $this->cachedInstalledVersion = $pluginHeader['Version'];
187
- return $pluginHeader['Version'];
188
- } else {
189
- //This can happen if the filename points to something that is not a plugin.
190
- $this->triggerError(
191
- sprintf(
192
- "Can't to read the Version header for '%s'. The filename is incorrect or is not a plugin.",
193
- $this->pluginFile
194
- ),
195
- E_USER_WARNING
196
- );
197
- return null;
198
- }
199
- }
200
-
201
- /**
202
- * Get plugin's metadata from its file header.
203
- *
204
- * @return array
205
- */
206
- protected function getPluginHeader() {
207
- if ( !is_file($this->pluginAbsolutePath) ) {
208
- //This can happen if the plugin filename is wrong.
209
- $this->triggerError(
210
- sprintf(
211
- "Can't to read the plugin header for '%s'. The file does not exist.",
212
- $this->pluginFile
213
- ),
214
- E_USER_WARNING
215
- );
216
- return array();
217
- }
218
-
219
- if ( !function_exists('get_plugin_data') ){
220
- /** @noinspection PhpIncludeInspection */
221
- require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
222
- }
223
- return get_plugin_data($this->pluginAbsolutePath, false, false);
224
- }
225
-
226
- /**
227
- * @return array
228
- */
229
- protected function getHeaderNames() {
230
- return array(
231
- 'Name' => 'Plugin Name',
232
- 'PluginURI' => 'Plugin URI',
233
- 'Version' => 'Version',
234
- 'Description' => 'Description',
235
- 'Author' => 'Author',
236
- 'AuthorURI' => 'Author URI',
237
- 'TextDomain' => 'Text Domain',
238
- 'DomainPath' => 'Domain Path',
239
- 'Network' => 'Network',
240
-
241
- //The newest WordPress version that this plugin requires or has been tested with.
242
- //We support several different formats for compatibility with other libraries.
243
- 'Tested WP' => 'Tested WP',
244
- 'Requires WP' => 'Requires WP',
245
- 'Tested up to' => 'Tested up to',
246
- 'Requires at least' => 'Requires at least',
247
- );
248
- }
249
-
250
-
251
- /**
252
- * Intercept plugins_api() calls that request information about our plugin and
253
- * use the configured API endpoint to satisfy them.
254
- *
255
- * @see plugins_api()
256
- *
257
- * @param mixed $result
258
- * @param string $action
259
- * @param array|object $args
260
- * @return mixed
261
- */
262
- public function injectInfo($result, $action = null, $args = null){
263
- $relevant = ($action == 'plugin_information') && isset($args->slug) && (
264
- ($args->slug == $this->slug) || ($args->slug == dirname($this->pluginFile))
265
- );
266
- if ( !$relevant ) {
267
- return $result;
268
- }
269
-
270
- $pluginInfo = $this->requestInfo();
271
- $pluginInfo = apply_filters($this->getUniqueName('pre_inject_info'), $pluginInfo);
272
- if ( $pluginInfo ) {
273
- return $pluginInfo->toWpFormat();
274
- }
275
-
276
- return $result;
277
- }
278
-
279
- protected function shouldShowUpdates() {
280
- //No update notifications for mu-plugins unless explicitly enabled. The MU plugin file
281
- //is usually different from the main plugin file so the update wouldn't show up properly anyway.
282
- return !$this->isUnknownMuPlugin();
283
- }
284
-
285
- /**
286
- * @param stdClass|null $updates
287
- * @param stdClass $updateToAdd
288
- * @return stdClass
289
- */
290
- protected function addUpdateToList($updates, $updateToAdd) {
291
- if ( $this->isMuPlugin() ) {
292
- //WP does not support automatic update installation for mu-plugins, but we can
293
- //still display a notice.
294
- $updateToAdd->package = null;
295
- }
296
- return parent::addUpdateToList($updates, $updateToAdd);
297
- }
298
-
299
- /**
300
- * @param stdClass|null $updates
301
- * @return stdClass|null
302
- */
303
- protected function removeUpdateFromList($updates) {
304
- $updates = parent::removeUpdateFromList($updates);
305
- if ( !empty($this->muPluginFile) && isset($updates, $updates->response) ) {
306
- unset($updates->response[$this->muPluginFile]);
307
- }
308
- return $updates;
309
- }
310
-
311
- /**
312
- * For plugins, the update array is indexed by the plugin filename relative to the "plugins"
313
- * directory. Example: "plugin-name/plugin.php".
314
- *
315
- * @return string
316
- */
317
- protected function getUpdateListKey() {
318
- if ( $this->isMuPlugin() ) {
319
- return $this->muPluginFile;
320
- }
321
- return $this->pluginFile;
322
- }
323
-
324
- /**
325
- * Alias for isBeingUpgraded().
326
- *
327
- * @deprecated
328
- * @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
329
- * @return bool
330
- */
331
- public function isPluginBeingUpgraded($upgrader = null) {
332
- return $this->isBeingUpgraded($upgrader);
333
- }
334
-
335
- /**
336
- * Is there an update being installed for this plugin, right now?
337
- *
338
- * @param WP_Upgrader|null $upgrader
339
- * @return bool
340
- */
341
- public function isBeingUpgraded($upgrader = null) {
342
- return $this->upgraderStatus->isPluginBeingUpgraded($this->pluginFile, $upgrader);
343
- }
344
-
345
- /**
346
- * Get the details of the currently available update, if any.
347
- *
348
- * If no updates are available, or if the last known update version is below or equal
349
- * to the currently installed version, this method will return NULL.
350
- *
351
- * Uses cached update data. To retrieve update information straight from
352
- * the metadata URL, call requestUpdate() instead.
353
- *
354
- * @return Puc_v4p4_Plugin_Update|null
355
- */
356
- public function getUpdate() {
357
- $update = parent::getUpdate();
358
- if ( isset($update) ) {
359
- /** @var Puc_v4p4_Plugin_Update $update */
360
- $update->filename = $this->pluginFile;
361
- }
362
- return $update;
363
- }
364
-
365
- /**
366
- * Add a "Check for updates" link to the plugin row in the "Plugins" page. By default,
367
- * the new link will appear after the "Visit plugin site" link if present, otherwise
368
- * after the "View plugin details" link.
369
- *
370
- * You can change the link text by using the "puc_manual_check_link-$slug" filter.
371
- * Returning an empty string from the filter will disable the link.
372
- *
373
- * @param array $pluginMeta Array of meta links.
374
- * @param string $pluginFile
375
- * @return array
376
- */
377
- public function addCheckForUpdatesLink($pluginMeta, $pluginFile) {
378
- $isRelevant = ($pluginFile == $this->pluginFile)
379
- || (!empty($this->muPluginFile) && $pluginFile == $this->muPluginFile);
380
-
381
- if ( $isRelevant && $this->userCanInstallUpdates() ) {
382
- $linkUrl = wp_nonce_url(
383
- add_query_arg(
384
- array(
385
- 'puc_check_for_updates' => 1,
386
- 'puc_slug' => $this->slug,
387
- ),
388
- self_admin_url('plugins.php')
389
- ),
390
- 'puc_check_for_updates'
391
- );
392
-
393
- $linkText = apply_filters(
394
- $this->getUniqueName('manual_check_link'),
395
- __('Check for updates', 'plugin-update-checker')
396
- );
397
- if ( !empty($linkText) ) {
398
- /** @noinspection HtmlUnknownTarget */
399
- $pluginMeta[] = sprintf('<a href="%s">%s</a>', esc_attr($linkUrl), $linkText);
400
- }
401
- }
402
- return $pluginMeta;
403
- }
404
-
405
- /**
406
- * Add a "View Details" link to the plugin row in the "Plugins" page. By default,
407
- * the new link will appear before the "Visit plugin site" link (if present).
408
- *
409
- * You can change the link text by using the "puc_view_details_link-$slug" filter.
410
- * Returning an empty string from the filter will disable the link.
411
- *
412
- * You can change the position of the link using the
413
- * "puc_view_details_link_position-$slug" filter.
414
- * Returning 'before' or 'after' will place the link immediately before/after the
415
- * "Visit plugin site" link
416
- * Returning 'append' places the link after any existing links at the time of the hook.
417
- * Returning 'replace' replaces the "Visit plugin site" link
418
- * Returning anything else disables the link when there is a "Visit plugin site" link.
419
- *
420
- * If there is no "Visit plugin site" link 'append' is always used!
421
- *
422
- * @param array $pluginMeta Array of meta links.
423
- * @param string $pluginFile
424
- * @param array $pluginData Array of plugin header data.
425
- * @return array
426
- */
427
- public function addViewDetailsLink($pluginMeta, $pluginFile, $pluginData = array()) {
428
- $isRelevant = ($pluginFile == $this->pluginFile)
429
- || (!empty($this->muPluginFile) && $pluginFile == $this->muPluginFile);
430
-
431
- if ( $isRelevant && $this->userCanInstallUpdates() && !isset($pluginData['slug']) ) {
432
- $linkText = apply_filters($this->getUniqueName('view_details_link'), __('View details'));
433
- if ( !empty($linkText) ) {
434
- $viewDetailsLinkPosition = 'append';
435
-
436
- //Find the "Visit plugin site" link (if present).
437
- $visitPluginSiteLinkIndex = count($pluginMeta) - 1;
438
- if ( $pluginData['PluginURI'] ) {
439
- $escapedPluginUri = esc_url($pluginData['PluginURI']);
440
- foreach ($pluginMeta as $linkIndex => $existingLink) {
441
- if ( strpos($existingLink, $escapedPluginUri) !== false ) {
442
- $visitPluginSiteLinkIndex = $linkIndex;
443
- $viewDetailsLinkPosition = apply_filters(
444
- $this->getUniqueName('view_details_link_position'),
445
- 'before'
446
- );
447
- break;
448
- }
449
- }
450
- }
451
-
452
- $viewDetailsLink = sprintf('<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
453
- esc_url(network_admin_url('plugin-install.php?tab=plugin-information&plugin=' . urlencode($this->slug) .
454
- '&TB_iframe=true&width=600&height=550')),
455
- esc_attr(sprintf(__('More information about %s'), $pluginData['Name'])),
456
- esc_attr($pluginData['Name']),
457
- $linkText
458
- );
459
- switch ($viewDetailsLinkPosition) {
460
- case 'before':
461
- array_splice($pluginMeta, $visitPluginSiteLinkIndex, 0, $viewDetailsLink);
462
- break;
463
- case 'after':
464
- array_splice($pluginMeta, $visitPluginSiteLinkIndex + 1, 0, $viewDetailsLink);
465
- break;
466
- case 'replace':
467
- $pluginMeta[$visitPluginSiteLinkIndex] = $viewDetailsLink;
468
- break;
469
- case 'append':
470
- default:
471
- $pluginMeta[] = $viewDetailsLink;
472
- break;
473
- }
474
- }
475
- }
476
- return $pluginMeta;
477
- }
478
-
479
-
480
- /**
481
- * Check for updates when the user clicks the "Check for updates" link.
482
- * @see self::addCheckForUpdatesLink()
483
- *
484
- * @return void
485
- */
486
- public function handleManualCheck() {
487
- $shouldCheck =
488
- isset($_GET['puc_check_for_updates'], $_GET['puc_slug'])
489
- && $_GET['puc_slug'] == $this->slug
490
- && $this->userCanInstallUpdates()
491
- && check_admin_referer('puc_check_for_updates');
492
-
493
- if ( $shouldCheck ) {
494
- $update = $this->checkForUpdates();
495
- $status = ($update === null) ? 'no_update' : 'update_available';
496
-
497
- if ( ($update === null) && !empty($this->lastRequestApiErrors) ) {
498
- //Some errors are not critical. For example, if PUC tries to retrieve the readme.txt
499
- //file from GitHub and gets a 404, that's an API error, but it doesn't prevent updates
500
- //from working. Maybe the plugin simply doesn't have a readme.
501
- //Let's only show important errors.
502
- $foundCriticalErrors = false;
503
- $questionableErrorCodes = array(
504
- 'puc-github-http-error',
505
- 'puc-gitlab-http-error',
506
- 'puc-bitbucket-http-error',
507
- );
508
-
509
- foreach ($this->lastRequestApiErrors as $item) {
510
- $wpError = $item['error'];
511
- /** @var WP_Error $wpError */
512
- if ( !in_array($wpError->get_error_code(), $questionableErrorCodes) ) {
513
- $foundCriticalErrors = true;
514
- break;
515
- }
516
- }
517
-
518
- if ( $foundCriticalErrors ) {
519
- $status = 'error';
520
- set_site_transient($this->manualCheckErrorTransient, $this->lastRequestApiErrors, 60);
521
- }
522
- }
523
-
524
- wp_redirect(add_query_arg(
525
- array(
526
- 'puc_update_check_result' => $status,
527
- 'puc_slug' => $this->slug,
528
- ),
529
- self_admin_url('plugins.php')
530
- ));
531
- }
532
- }
533
-
534
- /**
535
- * Display the results of a manual update check.
536
- * @see self::handleManualCheck()
537
- *
538
- * You can change the result message by using the "puc_manual_check_message-$slug" filter.
539
- */
540
- public function displayManualCheckResult() {
541
- if ( isset($_GET['puc_update_check_result'], $_GET['puc_slug']) && ($_GET['puc_slug'] == $this->slug) ) {
542
- $status = strval($_GET['puc_update_check_result']);
543
- $title = $this->getPluginTitle();
544
- $noticeClass = 'updated notice-success';
545
- $details = '';
546
-
547
- if ( $status == 'no_update' ) {
548
- $message = sprintf(_x('The %s plugin is up to date.', 'the plugin title', 'plugin-update-checker'), $title);
549
- } else if ( $status == 'update_available' ) {
550
- $message = sprintf(_x('A new version of the %s plugin is available.', 'the plugin title', 'plugin-update-checker'), $title);
551
- } else if ( $status === 'error' ) {
552
- $message = sprintf(_x('Could not determine if updates are available for %s.', 'the plugin title', 'plugin-update-checker'), $title);
553
- $noticeClass = 'error notice-error';
554
-
555
- $details = $this->formatManualCheckErrors(get_site_transient($this->manualCheckErrorTransient));
556
- delete_site_transient($this->manualCheckErrorTransient);
557
- } else {
558
- $message = sprintf(__('Unknown update checker status "%s"', 'plugin-update-checker'), htmlentities($status));
559
- $noticeClass = 'error notice-error';
560
- }
561
- printf(
562
- '<div class="notice %s is-dismissible"><p>%s</p>%s</div>',
563
- $noticeClass,
564
- apply_filters($this->getUniqueName('manual_check_message'), $message, $status),
565
- $details
566
- );
567
- }
568
- }
569
-
570
- /**
571
- * Format the list of errors that were thrown during an update check.
572
- *
573
- * @param array $errors
574
- * @return string
575
- */
576
- protected function formatManualCheckErrors($errors) {
577
- if ( empty($errors) ) {
578
- return '';
579
- }
580
- $output = '';
581
-
582
- $showAsList = count($errors) > 1;
583
- if ( $showAsList ) {
584
- $output .= '<ol>';
585
- $formatString = '<li>%1$s <code>%2$s</code></li>';
586
- } else {
587
- $formatString = '<p>%1$s <code>%2$s</code></p>';
588
- }
589
- foreach ($errors as $item) {
590
- $wpError = $item['error'];
591
- /** @var WP_Error $wpError */
592
- $output .= sprintf(
593
- $formatString,
594
- $wpError->get_error_message(),
595
- $wpError->get_error_code()
596
- );
597
- }
598
- if ( $showAsList ) {
599
- $output .= '</ol>';
600
- }
601
-
602
- return $output;
603
- }
604
-
605
- /**
606
- * Get the translated plugin title.
607
- *
608
- * @return string
609
- */
610
- protected function getPluginTitle() {
611
- $title = '';
612
- $header = $this->getPluginHeader();
613
- if ( $header && !empty($header['Name']) && isset($header['TextDomain']) ) {
614
- $title = translate($header['Name'], $header['TextDomain']);
615
- }
616
- return $title;
617
- }
618
-
619
- /**
620
- * Check if the current user has the required permissions to install updates.
621
- *
622
- * @return bool
623
- */
624
- public function userCanInstallUpdates() {
625
- return current_user_can('update_plugins');
626
- }
627
-
628
- /**
629
- * Check if the plugin file is inside the mu-plugins directory.
630
- *
631
- * @return bool
632
- */
633
- protected function isMuPlugin() {
634
- static $cachedResult = null;
635
-
636
- if ( $cachedResult === null ) {
637
- //Convert both paths to the canonical form before comparison.
638
- $muPluginDir = realpath(WPMU_PLUGIN_DIR);
639
- $pluginPath = realpath($this->pluginAbsolutePath);
640
-
641
- $cachedResult = (strpos($pluginPath, $muPluginDir) === 0);
642
- }
643
-
644
- return $cachedResult;
645
- }
646
-
647
- /**
648
- * MU plugins are partially supported, but only when we know which file in mu-plugins
649
- * corresponds to this plugin.
650
- *
651
- * @return bool
652
- */
653
- protected function isUnknownMuPlugin() {
654
- return empty($this->muPluginFile) && $this->isMuPlugin();
655
- }
656
-
657
- /**
658
- * Clear the cached plugin version. This method can be set up as a filter (hook) and will
659
- * return the filter argument unmodified.
660
- *
661
- * @param mixed $filterArgument
662
- * @return mixed
663
- */
664
- public function clearCachedVersion($filterArgument = null) {
665
- $this->cachedInstalledVersion = null;
666
- return $filterArgument;
667
- }
668
-
669
- /**
670
- * Get absolute path to the main plugin file.
671
- *
672
- * @return string
673
- */
674
- public function getAbsolutePath() {
675
- return $this->pluginAbsolutePath;
676
- }
677
-
678
- /**
679
- * @return string
680
- */
681
- public function getAbsoluteDirectoryPath() {
682
- return dirname($this->pluginAbsolutePath);
683
- }
684
-
685
- /**
686
- * Register a callback for filtering query arguments.
687
- *
688
- * The callback function should take one argument - an associative array of query arguments.
689
- * It should return a modified array of query arguments.
690
- *
691
- * @uses add_filter() This method is a convenience wrapper for add_filter().
692
- *
693
- * @param callable $callback
694
- * @return void
695
- */
696
- public function addQueryArgFilter($callback){
697
- $this->addFilter('request_info_query_args', $callback);
698
- }
699
-
700
- /**
701
- * Register a callback for filtering arguments passed to wp_remote_get().
702
- *
703
- * The callback function should take one argument - an associative array of arguments -
704
- * and return a modified array or arguments. See the WP documentation on wp_remote_get()
705
- * for details on what arguments are available and how they work.
706
- *
707
- * @uses add_filter() This method is a convenience wrapper for add_filter().
708
- *
709
- * @param callable $callback
710
- * @return void
711
- */
712
- public function addHttpRequestArgFilter($callback) {
713
- $this->addFilter('request_info_options', $callback);
714
- }
715
-
716
- /**
717
- * Register a callback for filtering the plugin info retrieved from the external API.
718
- *
719
- * The callback function should take two arguments. If the plugin info was retrieved
720
- * successfully, the first argument passed will be an instance of PluginInfo. Otherwise,
721
- * it will be NULL. The second argument will be the corresponding return value of
722
- * wp_remote_get (see WP docs for details).
723
- *
724
- * The callback function should return a new or modified instance of PluginInfo or NULL.
725
- *
726
- * @uses add_filter() This method is a convenience wrapper for add_filter().
727
- *
728
- * @param callable $callback
729
- * @return void
730
- */
731
- public function addResultFilter($callback) {
732
- $this->addFilter('request_info_result', $callback, 10, 2);
733
- }
734
-
735
- protected function createDebugBarExtension() {
736
- return new Puc_v4p4_DebugBar_PluginExtension($this);
737
- }
738
- }
739
-
740
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Scheduler.php DELETED
@@ -1,177 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_Scheduler', false) ):
3
-
4
- /**
5
- * The scheduler decides when and how often to check for updates.
6
- * It calls @see Puc_v4p4_UpdateChecker::checkForUpdates() to perform the actual checks.
7
- */
8
- class Puc_v4p4_Scheduler {
9
- public $checkPeriod = 12; //How often to check for updates (in hours).
10
- public $throttleRedundantChecks = false; //Check less often if we already know that an update is available.
11
- public $throttledCheckPeriod = 72;
12
-
13
- protected $hourlyCheckHooks = array('load-update.php');
14
-
15
- /**
16
- * @var Puc_v4p4_UpdateChecker
17
- */
18
- protected $updateChecker;
19
-
20
- private $cronHook = null;
21
-
22
- /**
23
- * Scheduler constructor.
24
- *
25
- * @param Puc_v4p4_UpdateChecker $updateChecker
26
- * @param int $checkPeriod How often to check for updates (in hours).
27
- * @param array $hourlyHooks
28
- */
29
- public function __construct($updateChecker, $checkPeriod, $hourlyHooks = array('load-plugins.php')) {
30
- $this->updateChecker = $updateChecker;
31
- $this->checkPeriod = $checkPeriod;
32
-
33
- //Set up the periodic update checks
34
- $this->cronHook = $this->updateChecker->getUniqueName('cron_check_updates');
35
- if ( $this->checkPeriod > 0 ){
36
-
37
- //Trigger the check via Cron.
38
- //Try to use one of the default schedules if possible as it's less likely to conflict
39
- //with other plugins and their custom schedules.
40
- $defaultSchedules = array(
41
- 1 => 'hourly',
42
- 12 => 'twicedaily',
43
- 24 => 'daily',
44
- );
45
- if ( array_key_exists($this->checkPeriod, $defaultSchedules) ) {
46
- $scheduleName = $defaultSchedules[$this->checkPeriod];
47
- } else {
48
- //Use a custom cron schedule.
49
- $scheduleName = 'every' . $this->checkPeriod . 'hours';
50
- add_filter('cron_schedules', array($this, '_addCustomSchedule'));
51
- }
52
-
53
- if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) {
54
- wp_schedule_event(time(), $scheduleName, $this->cronHook);
55
- }
56
- add_action($this->cronHook, array($this, 'maybeCheckForUpdates'));
57
-
58
- //In case Cron is disabled or unreliable, we also manually trigger
59
- //the periodic checks while the user is browsing the Dashboard.
60
- add_action( 'admin_init', array($this, 'maybeCheckForUpdates') );
61
-
62
- //Like WordPress itself, we check more often on certain pages.
63
- /** @see wp_update_plugins */
64
- add_action('load-update-core.php', array($this, 'maybeCheckForUpdates'));
65
- //"load-update.php" and "load-plugins.php" or "load-themes.php".
66
- $this->hourlyCheckHooks = array_merge($this->hourlyCheckHooks, $hourlyHooks);
67
- foreach($this->hourlyCheckHooks as $hook) {
68
- add_action($hook, array($this, 'maybeCheckForUpdates'));
69
- }
70
- //This hook fires after a bulk update is complete.
71
- add_action('upgrader_process_complete', array($this, 'maybeCheckForUpdates'), 11, 0);
72
-
73
- } else {
74
- //Periodic checks are disabled.
75
- wp_clear_scheduled_hook($this->cronHook);
76
- }
77
- }
78
-
79
- /**
80
- * Check for updates if the configured check interval has already elapsed.
81
- * Will use a shorter check interval on certain admin pages like "Dashboard -> Updates" or when doing cron.
82
- *
83
- * You can override the default behaviour by using the "puc_check_now-$slug" filter.
84
- * The filter callback will be passed three parameters:
85
- * - Current decision. TRUE = check updates now, FALSE = don't check now.
86
- * - Last check time as a Unix timestamp.
87
- * - Configured check period in hours.
88
- * Return TRUE to check for updates immediately, or FALSE to cancel.
89
- *
90
- * This method is declared public because it's a hook callback. Calling it directly is not recommended.
91
- */
92
- public function maybeCheckForUpdates(){
93
- if ( empty($this->checkPeriod) ){
94
- return;
95
- }
96
-
97
- $state = $this->updateChecker->getUpdateState();
98
- $shouldCheck = ($state->timeSinceLastCheck() >= $this->getEffectiveCheckPeriod());
99
-
100
- //Let plugin authors substitute their own algorithm.
101
- $shouldCheck = apply_filters(
102
- $this->updateChecker->getUniqueName('check_now'),
103
- $shouldCheck,
104
- $state->getLastCheck(),
105
- $this->checkPeriod
106
- );
107
-
108
- if ( $shouldCheck ) {
109
- $this->updateChecker->checkForUpdates();
110
- }
111
- }
112
-
113
- /**
114
- * Calculate the actual check period based on the current status and environment.
115
- *
116
- * @return int Check period in seconds.
117
- */
118
- protected function getEffectiveCheckPeriod() {
119
- $currentFilter = current_filter();
120
- if ( in_array($currentFilter, array('load-update-core.php', 'upgrader_process_complete')) ) {
121
- //Check more often when the user visits "Dashboard -> Updates" or does a bulk update.
122
- $period = 60;
123
- } else if ( in_array($currentFilter, $this->hourlyCheckHooks) ) {
124
- //Also check more often on /wp-admin/update.php and the "Plugins" or "Themes" page.
125
- $period = 3600;
126
- } else if ( $this->throttleRedundantChecks && ($this->updateChecker->getUpdate() !== null) ) {
127
- //Check less frequently if it's already known that an update is available.
128
- $period = $this->throttledCheckPeriod * 3600;
129
- } else if ( defined('DOING_CRON') && constant('DOING_CRON') ) {
130
- //WordPress cron schedules are not exact, so lets do an update check even
131
- //if slightly less than $checkPeriod hours have elapsed since the last check.
132
- $cronFuzziness = 20 * 60;
133
- $period = $this->checkPeriod * 3600 - $cronFuzziness;
134
- } else {
135
- $period = $this->checkPeriod * 3600;
136
- }
137
-
138
- return $period;
139
- }
140
-
141
- /**
142
- * Add our custom schedule to the array of Cron schedules used by WP.
143
- *
144
- * @param array $schedules
145
- * @return array
146
- */
147
- public function _addCustomSchedule($schedules){
148
- if ( $this->checkPeriod && ($this->checkPeriod > 0) ){
149
- $scheduleName = 'every' . $this->checkPeriod . 'hours';
150
- $schedules[$scheduleName] = array(
151
- 'interval' => $this->checkPeriod * 3600,
152
- 'display' => sprintf('Every %d hours', $this->checkPeriod),
153
- );
154
- }
155
- return $schedules;
156
- }
157
-
158
- /**
159
- * Remove the scheduled cron event that the library uses to check for updates.
160
- *
161
- * @return void
162
- */
163
- public function removeUpdaterCron(){
164
- wp_clear_scheduled_hook($this->cronHook);
165
- }
166
-
167
- /**
168
- * Get the name of the update checker's WP-cron hook. Mostly useful for debugging.
169
- *
170
- * @return string
171
- */
172
- public function getCronHookName() {
173
- return $this->cronHook;
174
- }
175
- }
176
-
177
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/StateStore.php DELETED
@@ -1,207 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_StateStore', false) ):
4
-
5
- class Puc_v4p4_StateStore {
6
- /**
7
- * @var int Last update check timestamp.
8
- */
9
- protected $lastCheck = 0;
10
-
11
- /**
12
- * @var string Version number.
13
- */
14
- protected $checkedVersion = '';
15
-
16
- /**
17
- * @var Puc_v4p4_Update|null Cached update.
18
- */
19
- protected $update = null;
20
-
21
- /**
22
- * @var string Site option name.
23
- */
24
- private $optionName = '';
25
-
26
- /**
27
- * @var bool Whether we've already tried to load the state from the database.
28
- */
29
- private $isLoaded = false;
30
-
31
- public function __construct($optionName) {
32
- $this->optionName = $optionName;
33
- }
34
-
35
- /**
36
- * Get time elapsed since the last update check.
37
- *
38
- * If there are no recorded update checks, this method returns a large arbitrary number
39
- * (i.e. time since the Unix epoch).
40
- *
41
- * @return int Elapsed time in seconds.
42
- */
43
- public function timeSinceLastCheck() {
44
- $this->lazyLoad();
45
- return time() - $this->lastCheck;
46
- }
47
-
48
- /**
49
- * @return int
50
- */
51
- public function getLastCheck() {
52
- $this->lazyLoad();
53
- return $this->lastCheck;
54
- }
55
-
56
- /**
57
- * Set the time of the last update check to the current timestamp.
58
- *
59
- * @return $this
60
- */
61
- public function setLastCheckToNow() {
62
- $this->lazyLoad();
63
- $this->lastCheck = time();
64
- return $this;
65
- }
66
-
67
- /**
68
- * @return null|Puc_v4p4_Update
69
- */
70
- public function getUpdate() {
71
- $this->lazyLoad();
72
- return $this->update;
73
- }
74
-
75
- /**
76
- * @param Puc_v4p4_Update|null $update
77
- * @return $this
78
- */
79
- public function setUpdate(Puc_v4p4_Update $update = null) {
80
- $this->lazyLoad();
81
- $this->update = $update;
82
- return $this;
83
- }
84
-
85
- /**
86
- * @return string
87
- */
88
- public function getCheckedVersion() {
89
- $this->lazyLoad();
90
- return $this->checkedVersion;
91
- }
92
-
93
- /**
94
- * @param string $version
95
- * @return $this
96
- */
97
- public function setCheckedVersion($version) {
98
- $this->lazyLoad();
99
- $this->checkedVersion = strval($version);
100
- return $this;
101
- }
102
-
103
- /**
104
- * Get translation updates.
105
- *
106
- * @return array
107
- */
108
- public function getTranslations() {
109
- $this->lazyLoad();
110
- if ( isset($this->update, $this->update->translations) ) {
111
- return $this->update->translations;
112
- }
113
- return array();
114
- }
115
-
116
- /**
117
- * Set translation updates.
118
- *
119
- * @param array $translationUpdates
120
- */
121
- public function setTranslations($translationUpdates) {
122
- $this->lazyLoad();
123
- if ( isset($this->update) ) {
124
- $this->update->translations = $translationUpdates;
125
- $this->save();
126
- }
127
- }
128
-
129
- public function save() {
130
- $state = new stdClass();
131
-
132
- $state->lastCheck = $this->lastCheck;
133
- $state->checkedVersion = $this->checkedVersion;
134
-
135
- if ( isset($this->update)) {
136
- $state->update = $this->update->toStdClass();
137
-
138
- $updateClass = get_class($this->update);
139
- $state->updateClass = $updateClass;
140
- $prefix = $this->getLibPrefix();
141
- if ( Puc_v4p4_Utils::startsWith($updateClass, $prefix) ) {
142
- $state->updateBaseClass = substr($updateClass, strlen($prefix));
143
- }
144
- }
145
-
146
- update_site_option($this->optionName, $state);
147
- $this->isLoaded = true;
148
- }
149
-
150
- /**
151
- * @return $this
152
- */
153
- public function lazyLoad() {
154
- if ( !$this->isLoaded ) {
155
- $this->load();
156
- }
157
- return $this;
158
- }
159
-
160
- protected function load() {
161
- $this->isLoaded = true;
162
-
163
- $state = get_site_option($this->optionName, null);
164
-
165
- if ( !is_object($state) ) {
166
- $this->lastCheck = 0;
167
- $this->checkedVersion = '';
168
- $this->update = null;
169
- return;
170
- }
171
-
172
- $this->lastCheck = intval(Puc_v4p4_Utils::get($state, 'lastCheck', 0));
173
- $this->checkedVersion = Puc_v4p4_Utils::get($state, 'checkedVersion', '');
174
- $this->update = null;
175
-
176
- if ( isset($state->update) ) {
177
- //This mess is due to the fact that the want the update class from this version
178
- //of the library, not the version that saved the update.
179
-
180
- $updateClass = null;
181
- if ( isset($state->updateBaseClass) ) {
182
- $updateClass = $this->getLibPrefix() . $state->updateBaseClass;
183
- } else if ( isset($state->updateClass) && class_exists($state->updateClass) ) {
184
- $updateClass = $state->updateClass;
185
- }
186
-
187
- if ( $updateClass !== null ) {
188
- $this->update = call_user_func(array($updateClass, 'fromObject'), $state->update);
189
- }
190
- }
191
- }
192
-
193
- public function delete() {
194
- delete_site_option($this->optionName);
195
-
196
- $this->lastCheck = 0;
197
- $this->checkedVersion = '';
198
- $this->update = null;
199
- }
200
-
201
- private function getLibPrefix() {
202
- $parts = explode('_', __CLASS__, 3);
203
- return $parts[0] . '_' . $parts[1] . '_';
204
- }
205
- }
206
-
207
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Theme/Update.php DELETED
@@ -1,84 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_Theme_Update', false) ):
4
-
5
- class Puc_v4p4_Theme_Update extends Puc_v4p4_Update {
6
- public $details_url = '';
7
-
8
- protected static $extraFields = array('details_url');
9
-
10
- /**
11
- * Transform the metadata into the format used by WordPress core.
12
- * Note the inconsistency: WP stores plugin updates as objects and theme updates as arrays.
13
- *
14
- * @return array
15
- */
16
- public function toWpFormat() {
17
- $update = array(
18
- 'theme' => $this->slug,
19
- 'new_version' => $this->version,
20
- 'url' => $this->details_url,
21
- );
22
-
23
- if ( !empty($this->download_url) ) {
24
- $update['package'] = $this->download_url;
25
- }
26
-
27
- return $update;
28
- }
29
-
30
- /**
31
- * Create a new instance of Theme_Update from its JSON-encoded representation.
32
- *
33
- * @param string $json Valid JSON string representing a theme information object.
34
- * @return self New instance of ThemeUpdate, or NULL on error.
35
- */
36
- public static function fromJson($json) {
37
- $instance = new self();
38
- if ( !parent::createFromJson($json, $instance) ) {
39
- return null;
40
- }
41
- return $instance;
42
- }
43
-
44
- /**
45
- * Create a new instance by copying the necessary fields from another object.
46
- *
47
- * @param StdClass|Puc_v4p4_Theme_Update $object The source object.
48
- * @return Puc_v4p4_Theme_Update The new copy.
49
- */
50
- public static function fromObject($object) {
51
- $update = new self();
52
- $update->copyFields($object, $update);
53
- return $update;
54
- }
55
-
56
- /**
57
- * Basic validation.
58
- *
59
- * @param StdClass $apiResponse
60
- * @return bool|WP_Error
61
- */
62
- protected function validateMetadata($apiResponse) {
63
- $required = array('version', 'details_url');
64
- foreach($required as $key) {
65
- if ( !isset($apiResponse->$key) || empty($apiResponse->$key) ) {
66
- return new WP_Error(
67
- 'tuc-invalid-metadata',
68
- sprintf('The theme metadata is missing the required "%s" key.', $key)
69
- );
70
- }
71
- }
72
- return true;
73
- }
74
-
75
- protected function getFieldNames() {
76
- return array_merge(parent::getFieldNames(), self::$extraFields);
77
- }
78
-
79
- protected function getPrefixedFilter($tag) {
80
- return parent::getPrefixedFilter($tag) . '_theme';
81
- }
82
- }
83
-
84
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Theme/UpdateChecker.php DELETED
@@ -1,177 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_Theme_UpdateChecker', false) ):
4
-
5
- class Puc_v4p4_Theme_UpdateChecker extends Puc_v4p4_UpdateChecker {
6
- protected $filterSuffix = 'theme';
7
- protected $updateTransient = 'update_themes';
8
- protected $translationType = 'theme';
9
-
10
- /**
11
- * @var string Theme directory name.
12
- */
13
- protected $stylesheet;
14
-
15
- /**
16
- * @var WP_Theme Theme object.
17
- */
18
- protected $theme;
19
-
20
- public function __construct($metadataUrl, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') {
21
- if ( $stylesheet === null ) {
22
- $stylesheet = get_stylesheet();
23
- }
24
- $this->stylesheet = $stylesheet;
25
- $this->theme = wp_get_theme($this->stylesheet);
26
-
27
- parent::__construct(
28
- $metadataUrl,
29
- $stylesheet,
30
- $customSlug ? $customSlug : $stylesheet,
31
- $checkPeriod,
32
- $optionName
33
- );
34
- }
35
-
36
- /**
37
- * For themes, the update array is indexed by theme directory name.
38
- *
39
- * @return string
40
- */
41
- protected function getUpdateListKey() {
42
- return $this->directoryName;
43
- }
44
-
45
- /**
46
- * Retrieve the latest update (if any) from the configured API endpoint.
47
- *
48
- * @return Puc_v4p4_Update|null An instance of Update, or NULL when no updates are available.
49
- */
50
- public function requestUpdate() {
51
- list($themeUpdate, $result) = $this->requestMetadata('Puc_v4p4_Theme_Update', 'request_update');
52
-
53
- if ( $themeUpdate !== null ) {
54
- /** @var Puc_v4p4_Theme_Update $themeUpdate */
55
- $themeUpdate->slug = $this->slug;
56
- }
57
-
58
- $themeUpdate = $this->filterUpdateResult($themeUpdate, $result);
59
- return $themeUpdate;
60
- }
61
-
62
- public function userCanInstallUpdates() {
63
- return current_user_can('update_themes');
64
- }
65
-
66
- /**
67
- * Get the currently installed version of the plugin or theme.
68
- *
69
- * @return string Version number.
70
- */
71
- public function getInstalledVersion() {
72
- return $this->theme->get('Version');
73
- }
74
-
75
- /**
76
- * @return string
77
- */
78
- public function getAbsoluteDirectoryPath() {
79
- if ( method_exists($this->theme, 'get_stylesheet_directory') ) {
80
- return $this->theme->get_stylesheet_directory(); //Available since WP 3.4.
81
- }
82
- return get_theme_root($this->stylesheet) . '/' . $this->stylesheet;
83
- }
84
-
85
- /**
86
- * Create an instance of the scheduler.
87
- *
88
- * @param int $checkPeriod
89
- * @return Puc_v4p4_Scheduler
90
- */
91
- protected function createScheduler($checkPeriod) {
92
- return new Puc_v4p4_Scheduler($this, $checkPeriod, array('load-themes.php'));
93
- }
94
-
95
- /**
96
- * Is there an update being installed right now for this theme?
97
- *
98
- * @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
99
- * @return bool
100
- */
101
- public function isBeingUpgraded($upgrader = null) {
102
- return $this->upgraderStatus->isThemeBeingUpgraded($this->stylesheet, $upgrader);
103
- }
104
-
105
- protected function createDebugBarExtension() {
106
- return new Puc_v4p4_DebugBar_Extension($this, 'Puc_v4p4_DebugBar_ThemePanel');
107
- }
108
-
109
- /**
110
- * Register a callback for filtering query arguments.
111
- *
112
- * The callback function should take one argument - an associative array of query arguments.
113
- * It should return a modified array of query arguments.
114
- *
115
- * @param callable $callback
116
- * @return void
117
- */
118
- public function addQueryArgFilter($callback){
119
- $this->addFilter('request_update_query_args', $callback);
120
- }
121
-
122
- /**
123
- * Register a callback for filtering arguments passed to wp_remote_get().
124
- *
125
- * The callback function should take one argument - an associative array of arguments -
126
- * and return a modified array or arguments. See the WP documentation on wp_remote_get()
127
- * for details on what arguments are available and how they work.
128
- *
129
- * @uses add_filter() This method is a convenience wrapper for add_filter().
130
- *
131
- * @param callable $callback
132
- * @return void
133
- */
134
- public function addHttpRequestArgFilter($callback) {
135
- $this->addFilter('request_update_options', $callback);
136
- }
137
-
138
- /**
139
- * Register a callback for filtering theme updates retrieved from the external API.
140
- *
141
- * The callback function should take two arguments. If the theme update was retrieved
142
- * successfully, the first argument passed will be an instance of Theme_Update. Otherwise,
143
- * it will be NULL. The second argument will be the corresponding return value of
144
- * wp_remote_get (see WP docs for details).
145
- *
146
- * The callback function should return a new or modified instance of Theme_Update or NULL.
147
- *
148
- * @uses add_filter() This method is a convenience wrapper for add_filter().
149
- *
150
- * @param callable $callback
151
- * @return void
152
- */
153
- public function addResultFilter($callback) {
154
- $this->addFilter('request_update_result', $callback, 10, 2);
155
- }
156
-
157
- /**
158
- * @return array
159
- */
160
- protected function getHeaderNames() {
161
- return array(
162
- 'Name' => 'Theme Name',
163
- 'ThemeURI' => 'Theme URI',
164
- 'Description' => 'Description',
165
- 'Author' => 'Author',
166
- 'AuthorURI' => 'Author URI',
167
- 'Version' => 'Version',
168
- 'Template' => 'Template',
169
- 'Status' => 'Status',
170
- 'Tags' => 'Tags',
171
- 'TextDomain' => 'Text Domain',
172
- 'DomainPath' => 'Domain Path',
173
- );
174
- }
175
- }
176
-
177
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Update.php DELETED
@@ -1,34 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_Update', false) ):
3
-
4
- /**
5
- * A simple container class for holding information about an available update.
6
- *
7
- * @author Janis Elsts
8
- * @access public
9
- */
10
- abstract class Puc_v4p4_Update extends Puc_v4p4_Metadata {
11
- public $slug;
12
- public $version;
13
- public $download_url;
14
- public $translations = array();
15
-
16
- /**
17
- * @return string[]
18
- */
19
- protected function getFieldNames() {
20
- return array('slug', 'version', 'download_url', 'translations');
21
- }
22
-
23
- public function toWpFormat() {
24
- $update = new stdClass();
25
-
26
- $update->slug = $this->slug;
27
- $update->new_version = $this->version;
28
- $update->package = $this->download_url;
29
-
30
- return $update;
31
- }
32
- }
33
-
34
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/UpdateChecker.php DELETED
@@ -1,906 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
4
-
5
- abstract class Puc_v4p4_UpdateChecker {
6
- protected $filterSuffix = '';
7
- protected $updateTransient = '';
8
- protected $translationType = ''; //"plugin" or "theme".
9
-
10
- /**
11
- * Set to TRUE to enable error reporting. Errors are raised using trigger_error()
12
- * and should be logged to the standard PHP error log.
13
- * @var bool
14
- */
15
- public $debugMode = null;
16
-
17
- /**
18
- * @var string Where to store the update info.
19
- */
20
- public $optionName = '';
21
-
22
- /**
23
- * @var string The URL of the metadata file.
24
- */
25
- public $metadataUrl = '';
26
-
27
- /**
28
- * @var string Plugin or theme directory name.
29
- */
30
- public $directoryName = '';
31
-
32
- /**
33
- * @var string The slug that will be used in update checker hooks and remote API requests.
34
- * Usually matches the directory name unless the plugin/theme directory has been renamed.
35
- */
36
- public $slug = '';
37
-
38
- /**
39
- * @var Puc_v4p4_Scheduler
40
- */
41
- public $scheduler;
42
-
43
- /**
44
- * @var Puc_v4p4_UpgraderStatus
45
- */
46
- protected $upgraderStatus;
47
-
48
- /**
49
- * @var Puc_v4p4_StateStore
50
- */
51
- protected $updateState;
52
-
53
- /**
54
- * @var array List of API errors triggered during the last checkForUpdates() call.
55
- */
56
- protected $lastRequestApiErrors = array();
57
-
58
- public function __construct($metadataUrl, $directoryName, $slug = null, $checkPeriod = 12, $optionName = '') {
59
- $this->debugMode = (bool)(constant('WP_DEBUG'));
60
- $this->metadataUrl = $metadataUrl;
61
- $this->directoryName = $directoryName;
62
- $this->slug = !empty($slug) ? $slug : $this->directoryName;
63
-
64
- $this->optionName = $optionName;
65
- if ( empty($this->optionName) ) {
66
- //BC: Initially the library only supported plugin updates and didn't use type prefixes
67
- //in the option name. Lets use the same prefix-less name when possible.
68
- if ( $this->filterSuffix === '' ) {
69
- $this->optionName = 'external_updates-' . $this->slug;
70
- } else {
71
- $this->optionName = $this->getUniqueName('external_updates');
72
- }
73
- }
74
-
75
- $this->scheduler = $this->createScheduler($checkPeriod);
76
- $this->upgraderStatus = new Puc_v4p4_UpgraderStatus();
77
- $this->updateState = new Puc_v4p4_StateStore($this->optionName);
78
-
79
- if ( did_action('init') ) {
80
- $this->loadTextDomain();
81
- } else {
82
- add_action('init', array($this, 'loadTextDomain'));
83
- }
84
-
85
- $this->installHooks();
86
- }
87
-
88
- /**
89
- * @internal
90
- */
91
- public function loadTextDomain() {
92
- //We're not using load_plugin_textdomain() or its siblings because figuring out where
93
- //the library is located (plugin, mu-plugin, theme, custom wp-content paths) is messy.
94
- $domain = 'plugin-update-checker';
95
- $locale = apply_filters(
96
- 'plugin_locale',
97
- (is_admin() && function_exists('get_user_locale')) ? get_user_locale() : get_locale(),
98
- $domain
99
- );
100
-
101
- $moFile = $domain . '-' . $locale . '.mo';
102
- $path = realpath(dirname(__FILE__) . '/../../languages');
103
-
104
- if ($path && file_exists($path)) {
105
- load_textdomain($domain, $path . '/' . $moFile);
106
- }
107
- }
108
-
109
- protected function installHooks() {
110
- //Insert our update info into the update array maintained by WP.
111
- add_filter('site_transient_' . $this->updateTransient, array($this,'injectUpdate'));
112
-
113
- //Insert translation updates into the update list.
114
- add_filter('site_transient_' . $this->updateTransient, array($this, 'injectTranslationUpdates'));
115
-
116
- //Clear translation updates when WP clears the update cache.
117
- //This needs to be done directly because the library doesn't actually remove obsolete plugin updates,
118
- //it just hides them (see getUpdate()). We can't do that with translations - too much disk I/O.
119
- add_action(
120
- 'delete_site_transient_' . $this->updateTransient,
121
- array($this, 'clearCachedTranslationUpdates')
122
- );
123
-
124
- //Rename the update directory to be the same as the existing directory.
125
- if ( $this->directoryName !== '.' ) {
126
- add_filter('upgrader_source_selection', array($this, 'fixDirectoryName'), 10, 3);
127
- }
128
-
129
- //Allow HTTP requests to the metadata URL even if it's on a local host.
130
- add_filter('http_request_host_is_external', array($this, 'allowMetadataHost'), 10, 2);
131
-
132
- //DebugBar integration.
133
- if ( did_action('plugins_loaded') ) {
134
- $this->maybeInitDebugBar();
135
- } else {
136
- add_action('plugins_loaded', array($this, 'maybeInitDebugBar'));
137
- }
138
- }
139
-
140
- /**
141
- * Remove hooks that were added by this update checker instance.
142
- */
143
- protected function removeHooks() {
144
- remove_filter('site_transient_' . $this->updateTransient, array($this,'injectUpdate'));
145
- remove_filter('site_transient_' . $this->updateTransient, array($this, 'injectTranslationUpdates'));
146
- remove_action(
147
- 'delete_site_transient_' . $this->updateTransient,
148
- array($this, 'clearCachedTranslationUpdates')
149
- );
150
-
151
- remove_filter('upgrader_source_selection', array($this, 'fixDirectoryName'), 10);
152
- remove_filter('http_request_host_is_external', array($this, 'allowMetadataHost'), 10);
153
- remove_action('plugins_loaded', array($this, 'maybeInitDebugBar'));
154
-
155
- remove_action('init', array($this, 'loadTextDomain'));
156
- }
157
-
158
- /**
159
- * Check if the current user has the required permissions to install updates.
160
- *
161
- * @return bool
162
- */
163
- abstract public function userCanInstallUpdates();
164
-
165
- /**
166
- * Explicitly allow HTTP requests to the metadata URL.
167
- *
168
- * WordPress has a security feature where the HTTP API will reject all requests that are sent to
169
- * another site hosted on the same server as the current site (IP match), a local host, or a local
170
- * IP, unless the host exactly matches the current site.
171
- *
172
- * This feature is opt-in (at least in WP 4.4). Apparently some people enable it.
173
- *
174
- * That can be a problem when you're developing your plugin and you decide to host the update information
175
- * on the same server as your test site. Update requests will mysteriously fail.
176
- *
177
- * We fix that by adding an exception for the metadata host.
178
- *
179
- * @param bool $allow
180
- * @param string $host
181
- * @return bool
182
- */
183
- public function allowMetadataHost($allow, $host) {
184
- static $metadataHost = 0; //Using 0 instead of NULL because parse_url can return NULL.
185
- if ( $metadataHost === 0 ) {
186
- $metadataHost = @parse_url($this->metadataUrl, PHP_URL_HOST);
187
- }
188
-
189
- if ( is_string($metadataHost) && (strtolower($host) === strtolower($metadataHost)) ) {
190
- return true;
191
- }
192
- return $allow;
193
- }
194
-
195
- /**
196
- * Create an instance of the scheduler.
197
- *
198
- * This is implemented as a method to make it possible for plugins to subclass the update checker
199
- * and substitute their own scheduler.
200
- *
201
- * @param int $checkPeriod
202
- * @return Puc_v4p4_Scheduler
203
- */
204
- abstract protected function createScheduler($checkPeriod);
205
-
206
- /**
207
- * Check for updates. The results are stored in the DB option specified in $optionName.
208
- *
209
- * @return Puc_v4p4_Update|null
210
- */
211
- public function checkForUpdates() {
212
- $installedVersion = $this->getInstalledVersion();
213
- //Fail silently if we can't find the plugin/theme or read its header.
214
- if ( $installedVersion === null ) {
215
- $this->triggerError(
216
- sprintf('Skipping update check for %s - installed version unknown.', $this->slug),
217
- E_USER_WARNING
218
- );
219
- return null;
220
- }
221
-
222
- //Start collecting API errors.
223
- $this->lastRequestApiErrors = array();
224
- add_action('puc_api_error', array($this, 'collectApiErrors'), 10, 4);
225
-
226
- $state = $this->updateState;
227
- $state->setLastCheckToNow()
228
- ->setCheckedVersion($installedVersion)
229
- ->save(); //Save before checking in case something goes wrong
230
-
231
- $state->setUpdate($this->requestUpdate());
232
- $state->save();
233
-
234
- //Stop collecting API errors.
235
- remove_action('puc_api_error', array($this, 'collectApiErrors'), 10);
236
-
237
- return $this->getUpdate();
238
- }
239
-
240
- /**
241
- * Load the update checker state from the DB.
242
- *
243
- * @return Puc_v4p4_StateStore
244
- */
245
- public function getUpdateState() {
246
- return $this->updateState->lazyLoad();
247
- }
248
-
249
- /**
250
- * Reset update checker state - i.e. last check time, cached update data and so on.
251
- *
252
- * Call this when your plugin is being uninstalled, or if you want to
253
- * clear the update cache.
254
- */
255
- public function resetUpdateState() {
256
- $this->updateState->delete();
257
- }
258
-
259
- /**
260
- * Get the details of the currently available update, if any.
261
- *
262
- * If no updates are available, or if the last known update version is below or equal
263
- * to the currently installed version, this method will return NULL.
264
- *
265
- * Uses cached update data. To retrieve update information straight from
266
- * the metadata URL, call requestUpdate() instead.
267
- *
268
- * @return Puc_v4p4_Update|null
269
- */
270
- public function getUpdate() {
271
- $update = $this->updateState->getUpdate();
272
-
273
- //Is there an update available?
274
- if ( isset($update) ) {
275
- //Check if the update is actually newer than the currently installed version.
276
- $installedVersion = $this->getInstalledVersion();
277
- if ( ($installedVersion !== null) && version_compare($update->version, $installedVersion, '>') ){
278
- return $update;
279
- }
280
- }
281
- return null;
282
- }
283
-
284
- /**
285
- * Retrieve the latest update (if any) from the configured API endpoint.
286
- *
287
- * Subclasses should run the update through filterUpdateResult before returning it.
288
- *
289
- * @return Puc_v4p4_Update An instance of Update, or NULL when no updates are available.
290
- */
291
- abstract public function requestUpdate();
292
-
293
- /**
294
- * Filter the result of a requestUpdate() call.
295
- *
296
- * @param Puc_v4p4_Update|null $update
297
- * @param array|WP_Error|null $httpResult The value returned by wp_remote_get(), if any.
298
- * @return Puc_v4p4_Update
299
- */
300
- protected function filterUpdateResult($update, $httpResult = null) {
301
- //Let plugins/themes modify the update.
302
- $update = apply_filters($this->getUniqueName('request_update_result'), $update, $httpResult);
303
-
304
- if ( isset($update, $update->translations) ) {
305
- //Keep only those translation updates that apply to this site.
306
- $update->translations = $this->filterApplicableTranslations($update->translations);
307
- }
308
-
309
- return $update;
310
- }
311
-
312
- /**
313
- * Get the currently installed version of the plugin or theme.
314
- *
315
- * @return string|null Version number.
316
- */
317
- abstract public function getInstalledVersion();
318
-
319
- /**
320
- * Get the full path of the plugin or theme directory.
321
- *
322
- * @return string
323
- */
324
- abstract public function getAbsoluteDirectoryPath();
325
-
326
- /**
327
- * Trigger a PHP error, but only when $debugMode is enabled.
328
- *
329
- * @param string $message
330
- * @param int $errorType
331
- */
332
- protected function triggerError($message, $errorType) {
333
- if ($this->isDebugModeEnabled()) {
334
- trigger_error($message, $errorType);
335
- }
336
- }
337
-
338
- /**
339
- * @return bool
340
- */
341
- protected function isDebugModeEnabled() {
342
- if ($this->debugMode === null) {
343
- $this->debugMode = (bool)(constant('WP_DEBUG'));
344
- }
345
- return $this->debugMode;
346
- }
347
-
348
- /**
349
- * Get the full name of an update checker filter, action or DB entry.
350
- *
351
- * This method adds the "puc_" prefix and the "-$slug" suffix to the filter name.
352
- * For example, "pre_inject_update" becomes "puc_pre_inject_update-plugin-slug".
353
- *
354
- * @param string $baseTag
355
- * @return string
356
- */
357
- public function getUniqueName($baseTag) {
358
- $name = 'puc_' . $baseTag;
359
- if ($this->filterSuffix !== '') {
360
- $name .= '_' . $this->filterSuffix;
361
- }
362
- return $name . '-' . $this->slug;
363
- }
364
-
365
- /**
366
- * Store API errors that are generated when checking for updates.
367
- *
368
- * @internal
369
- * @param WP_Error $error
370
- * @param array|null $httpResponse
371
- * @param string|null $url
372
- * @param string|null $slug
373
- */
374
- public function collectApiErrors($error, $httpResponse = null, $url = null, $slug = null) {
375
- if ( isset($slug) && ($slug !== $this->slug) ) {
376
- return;
377
- }
378
-
379
- $this->lastRequestApiErrors[] = array(
380
- 'error' => $error,
381
- 'httpResponse' => $httpResponse,
382
- 'url' => $url,
383
- );
384
- }
385
-
386
- /**
387
- * @return array
388
- */
389
- public function getLastRequestApiErrors() {
390
- return $this->lastRequestApiErrors;
391
- }
392
-
393
- /* -------------------------------------------------------------------
394
- * PUC filters and filter utilities
395
- * -------------------------------------------------------------------
396
- */
397
-
398
- /**
399
- * Register a callback for one of the update checker filters.
400
- *
401
- * Identical to add_filter(), except it automatically adds the "puc_" prefix
402
- * and the "-$slug" suffix to the filter name. For example, "request_info_result"
403
- * becomes "puc_request_info_result-your_plugin_slug".
404
- *
405
- * @param string $tag
406
- * @param callable $callback
407
- * @param int $priority
408
- * @param int $acceptedArgs
409
- */
410
- public function addFilter($tag, $callback, $priority = 10, $acceptedArgs = 1) {
411
- add_filter($this->getUniqueName($tag), $callback, $priority, $acceptedArgs);
412
- }
413
-
414
- /* -------------------------------------------------------------------
415
- * Inject updates
416
- * -------------------------------------------------------------------
417
- */
418
-
419
- /**
420
- * Insert the latest update (if any) into the update list maintained by WP.
421
- *
422
- * @param stdClass $updates Update list.
423
- * @return stdClass Modified update list.
424
- */
425
- public function injectUpdate($updates) {
426
- //Is there an update to insert?
427
- $update = $this->getUpdate();
428
-
429
- if ( !$this->shouldShowUpdates() ) {
430
- $update = null;
431
- }
432
-
433
- if ( !empty($update) ) {
434
- //Let plugins filter the update info before it's passed on to WordPress.
435
- $update = apply_filters($this->getUniqueName('pre_inject_update'), $update);
436
- $updates = $this->addUpdateToList($updates, $update->toWpFormat());
437
- } else {
438
- //Clean up any stale update info.
439
- $updates = $this->removeUpdateFromList($updates);
440
- }
441
-
442
- return $updates;
443
- }
444
-
445
- /**
446
- * @param stdClass|null $updates
447
- * @param stdClass|array $updateToAdd
448
- * @return stdClass
449
- */
450
- protected function addUpdateToList($updates, $updateToAdd) {
451
- if ( !is_object($updates) ) {
452
- $updates = new stdClass();
453
- $updates->response = array();
454
- }
455
-
456
- $updates->response[$this->getUpdateListKey()] = $updateToAdd;
457
- return $updates;
458
- }
459
-
460
- /**
461
- * @param stdClass|null $updates
462
- * @return stdClass|null
463
- */
464
- protected function removeUpdateFromList($updates) {
465
- if ( isset($updates, $updates->response) ) {
466
- unset($updates->response[$this->getUpdateListKey()]);
467
- }
468
- return $updates;
469
- }
470
-
471
- /**
472
- * Get the key that will be used when adding updates to the update list that's maintained
473
- * by the WordPress core. The list is always an associative array, but the key is different
474
- * for plugins and themes.
475
- *
476
- * @return string
477
- */
478
- abstract protected function getUpdateListKey();
479
-
480
- /**
481
- * Should we show available updates?
482
- *
483
- * Usually the answer is "yes", but there are exceptions. For example, WordPress doesn't
484
- * support automatic updates installation for mu-plugins, so PUC usually won't show update
485
- * notifications in that case. See the plugin-specific subclass for details.
486
- *
487
- * Note: This method only applies to updates that are displayed (or not) in the WordPress
488
- * admin. It doesn't affect APIs like requestUpdate and getUpdate.
489
- *
490
- * @return bool
491
- */
492
- protected function shouldShowUpdates() {
493
- return true;
494
- }
495
-
496
- /* -------------------------------------------------------------------
497
- * JSON-based update API
498
- * -------------------------------------------------------------------
499
- */
500
-
501
- /**
502
- * Retrieve plugin or theme metadata from the JSON document at $this->metadataUrl.
503
- *
504
- * @param string $metaClass Parse the JSON as an instance of this class. It must have a static fromJson method.
505
- * @param string $filterRoot
506
- * @param array $queryArgs Additional query arguments.
507
- * @return array [Puc_v4p4_Metadata|null, array|WP_Error] A metadata instance and the value returned by wp_remote_get().
508
- */
509
- protected function requestMetadata($metaClass, $filterRoot, $queryArgs = array()) {
510
- //Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()).
511
- $queryArgs = array_merge(
512
- array(
513
- 'installed_version' => strval($this->getInstalledVersion()),
514
- 'php' => phpversion(),
515
- 'locale' => get_locale(),
516
- ),
517
- $queryArgs
518
- );
519
- $queryArgs = apply_filters($this->getUniqueName($filterRoot . '_query_args'), $queryArgs);
520
-
521
- //Various options for the wp_remote_get() call. Plugins can filter these, too.
522
- $options = array(
523
- 'timeout' => 10, //seconds
524
- 'headers' => array(
525
- 'Accept' => 'application/json',
526
- ),
527
- );
528
- $options = apply_filters($this->getUniqueName($filterRoot . '_options'), $options);
529
-
530
- //The metadata file should be at 'http://your-api.com/url/here/$slug/info.json'
531
- $url = $this->metadataUrl;
532
- if ( !empty($queryArgs) ){
533
- $url = add_query_arg($queryArgs, $url);
534
- }
535
-
536
- $result = wp_remote_get($url, $options);
537
-
538
- $result = apply_filters($this->getUniqueName('request_metadata_http_result'), $result, $url, $options);
539
-
540
- //Try to parse the response
541
- $status = $this->validateApiResponse($result);
542
- $metadata = null;
543
- if ( !is_wp_error($status) ){
544
- $metadata = call_user_func(array($metaClass, 'fromJson'), $result['body']);
545
- } else {
546
- do_action('puc_api_error', $status, $result, $url, $this->slug);
547
- $this->triggerError(
548
- sprintf('The URL %s does not point to a valid metadata file. ', $url)
549
- . $status->get_error_message(),
550
- E_USER_WARNING
551
- );
552
- }
553
-
554
- return array($metadata, $result);
555
- }
556
-
557
- /**
558
- * Check if $result is a successful update API response.
559
- *
560
- * @param array|WP_Error $result
561
- * @return true|WP_Error
562
- */
563
- protected function validateApiResponse($result) {
564
- if ( is_wp_error($result) ) { /** @var WP_Error $result */
565
- return new WP_Error($result->get_error_code(), 'WP HTTP Error: ' . $result->get_error_message());
566
- }
567
-
568
- if ( !isset($result['response']['code']) ) {
569
- return new WP_Error(
570
- 'puc_no_response_code',
571
- 'wp_remote_get() returned an unexpected result.'
572
- );
573
- }
574
-
575
- if ( $result['response']['code'] !== 200 ) {
576
- return new WP_Error(
577
- 'puc_unexpected_response_code',
578
- 'HTTP response code is ' . $result['response']['code'] . ' (expected: 200)'
579
- );
580
- }
581
-
582
- if ( empty($result['body']) ) {
583
- return new WP_Error('puc_empty_response', 'The metadata file appears to be empty.');
584
- }
585
-
586
- return true;
587
- }
588
-
589
- /* -------------------------------------------------------------------
590
- * Language packs / Translation updates
591
- * -------------------------------------------------------------------
592
- */
593
-
594
- /**
595
- * Filter a list of translation updates and return a new list that contains only updates
596
- * that apply to the current site.
597
- *
598
- * @param array $translations
599
- * @return array
600
- */
601
- protected function filterApplicableTranslations($translations) {
602
- $languages = array_flip(array_values(get_available_languages()));
603
- $installedTranslations = $this->getInstalledTranslations();
604
-
605
- $applicableTranslations = array();
606
- foreach($translations as $translation) {
607
- //Does it match one of the available core languages?
608
- $isApplicable = array_key_exists($translation->language, $languages);
609
- //Is it more recent than an already-installed translation?
610
- if ( isset($installedTranslations[$translation->language]) ) {
611
- $updateTimestamp = strtotime($translation->updated);
612
- $installedTimestamp = strtotime($installedTranslations[$translation->language]['PO-Revision-Date']);
613
- $isApplicable = $updateTimestamp > $installedTimestamp;
614
- }
615
-
616
- if ( $isApplicable ) {
617
- $applicableTranslations[] = $translation;
618
- }
619
- }
620
-
621
- return $applicableTranslations;
622
- }
623
-
624
- /**
625
- * Get a list of installed translations for this plugin or theme.
626
- *
627
- * @return array
628
- */
629
- protected function getInstalledTranslations() {
630
- if ( !function_exists('wp_get_installed_translations') ) {
631
- return array();
632
- }
633
- $installedTranslations = wp_get_installed_translations($this->translationType . 's');
634
- if ( isset($installedTranslations[$this->directoryName]) ) {
635
- $installedTranslations = $installedTranslations[$this->directoryName];
636
- } else {
637
- $installedTranslations = array();
638
- }
639
- return $installedTranslations;
640
- }
641
-
642
- /**
643
- * Insert translation updates into the list maintained by WordPress.
644
- *
645
- * @param stdClass $updates
646
- * @return stdClass
647
- */
648
- public function injectTranslationUpdates($updates) {
649
- $translationUpdates = $this->getTranslationUpdates();
650
- if ( empty($translationUpdates) ) {
651
- return $updates;
652
- }
653
-
654
- //Being defensive.
655
- if ( !is_object($updates) ) {
656
- $updates = new stdClass();
657
- }
658
- if ( !isset($updates->translations) ) {
659
- $updates->translations = array();
660
- }
661
-
662
- //In case there's a name collision with a plugin or theme hosted on wordpress.org,
663
- //remove any preexisting updates that match our thing.
664
- $updates->translations = array_values(array_filter(
665
- $updates->translations,
666
- array($this, 'isNotMyTranslation')
667
- ));
668
-
669
- //Add our updates to the list.
670
- foreach($translationUpdates as $update) {
671
- $convertedUpdate = array_merge(
672
- array(
673
- 'type' => $this->translationType,
674
- 'slug' => $this->directoryName,
675
- 'autoupdate' => 0,
676
- //AFAICT, WordPress doesn't actually use the "version" field for anything.
677
- //But lets make sure it's there, just in case.
678
- 'version' => isset($update->version) ? $update->version : ('1.' . strtotime($update->updated)),
679
- ),
680
- (array)$update
681
- );
682
-
683
- $updates->translations[] = $convertedUpdate;
684
- }
685
-
686
- return $updates;
687
- }
688
-
689
- /**
690
- * Get a list of available translation updates.
691
- *
692
- * This method will return an empty array if there are no updates.
693
- * Uses cached update data.
694
- *
695
- * @return array
696
- */
697
- public function getTranslationUpdates() {
698
- return $this->updateState->getTranslations();
699
- }
700
-
701
- /**
702
- * Remove all cached translation updates.
703
- *
704
- * @see wp_clean_update_cache
705
- */
706
- public function clearCachedTranslationUpdates() {
707
- $this->updateState->setTranslations(array());
708
- }
709
-
710
- /**
711
- * Filter callback. Keeps only translations that *don't* match this plugin or theme.
712
- *
713
- * @param array $translation
714
- * @return bool
715
- */
716
- protected function isNotMyTranslation($translation) {
717
- $isMatch = isset($translation['type'], $translation['slug'])
718
- && ($translation['type'] === $this->translationType)
719
- && ($translation['slug'] === $this->directoryName);
720
-
721
- return !$isMatch;
722
- }
723
-
724
- /* -------------------------------------------------------------------
725
- * Fix directory name when installing updates
726
- * -------------------------------------------------------------------
727
- */
728
-
729
- /**
730
- * Rename the update directory to match the existing plugin/theme directory.
731
- *
732
- * When WordPress installs a plugin or theme update, it assumes that the ZIP file will contain
733
- * exactly one directory, and that the directory name will be the same as the directory where
734
- * the plugin or theme is currently installed.
735
- *
736
- * GitHub and other repositories provide ZIP downloads, but they often use directory names like
737
- * "project-branch" or "project-tag-hash". We need to change the name to the actual plugin folder.
738
- *
739
- * This is a hook callback. Don't call it from a plugin.
740
- *
741
- * @access protected
742
- *
743
- * @param string $source The directory to copy to /wp-content/plugins or /wp-content/themes. Usually a subdirectory of $remoteSource.
744
- * @param string $remoteSource WordPress has extracted the update to this directory.
745
- * @param WP_Upgrader $upgrader
746
- * @return string|WP_Error
747
- */
748
- public function fixDirectoryName($source, $remoteSource, $upgrader) {
749
- global $wp_filesystem;
750
- /** @var WP_Filesystem_Base $wp_filesystem */
751
-
752
- //Basic sanity checks.
753
- if ( !isset($source, $remoteSource, $upgrader, $upgrader->skin, $wp_filesystem) ) {
754
- return $source;
755
- }
756
-
757
- //If WordPress is upgrading anything other than our plugin/theme, leave the directory name unchanged.
758
- if ( !$this->isBeingUpgraded($upgrader) ) {
759
- return $source;
760
- }
761
-
762
- //Rename the source to match the existing directory.
763
- $correctedSource = trailingslashit($remoteSource) . $this->directoryName . '/';
764
- if ( $source !== $correctedSource ) {
765
- //The update archive should contain a single directory that contains the rest of plugin/theme files.
766
- //Otherwise, WordPress will try to copy the entire working directory ($source == $remoteSource).
767
- //We can't rename $remoteSource because that would break WordPress code that cleans up temporary files
768
- //after update.
769
- if ( $this->isBadDirectoryStructure($remoteSource) ) {
770
- return new WP_Error(
771
- 'puc-incorrect-directory-structure',
772
- sprintf(
773
- 'The directory structure of the update is incorrect. All files should be inside ' .
774
- 'a directory named <span class="code">%s</span>, not at the root of the ZIP archive.',
775
- htmlentities($this->slug)
776
- )
777
- );
778
- }
779
-
780
- /** @var WP_Upgrader_Skin $upgrader ->skin */
781
- $upgrader->skin->feedback(sprintf(
782
- 'Renaming %s to %s&#8230;',
783
- '<span class="code">' . basename($source) . '</span>',
784
- '<span class="code">' . $this->directoryName . '</span>'
785
- ));
786
-
787
- if ( $wp_filesystem->move($source, $correctedSource, true) ) {
788
- $upgrader->skin->feedback('Directory successfully renamed.');
789
- return $correctedSource;
790
- } else {
791
- return new WP_Error(
792
- 'puc-rename-failed',
793
- 'Unable to rename the update to match the existing directory.'
794
- );
795
- }
796
- }
797
-
798
- return $source;
799
- }
800
-
801
- /**
802
- * Is there an update being installed right now, for this plugin or theme?
803
- *
804
- * @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
805
- * @return bool
806
- */
807
- abstract public function isBeingUpgraded($upgrader = null);
808
-
809
- /**
810
- * Check for incorrect update directory structure. An update must contain a single directory,
811
- * all other files should be inside that directory.
812
- *
813
- * @param string $remoteSource Directory path.
814
- * @return bool
815
- */
816
- protected function isBadDirectoryStructure($remoteSource) {
817
- global $wp_filesystem;
818
- /** @var WP_Filesystem_Base $wp_filesystem */
819
-
820
- $sourceFiles = $wp_filesystem->dirlist($remoteSource);
821
- if ( is_array($sourceFiles) ) {
822
- $sourceFiles = array_keys($sourceFiles);
823
- $firstFilePath = trailingslashit($remoteSource) . $sourceFiles[0];
824
- return (count($sourceFiles) > 1) || (!$wp_filesystem->is_dir($firstFilePath));
825
- }
826
-
827
- //Assume it's fine.
828
- return false;
829
- }
830
-
831
- /* -------------------------------------------------------------------
832
- * File header parsing
833
- * -------------------------------------------------------------------
834
- */
835
-
836
- /**
837
- * Parse plugin or theme metadata from the header comment.
838
- *
839
- * This is basically a simplified version of the get_file_data() function from /wp-includes/functions.php.
840
- * It's intended as a utility for subclasses that detect updates by parsing files in a VCS.
841
- *
842
- * @param string|null $content File contents.
843
- * @return string[]
844
- */
845
- public function getFileHeader($content) {
846
- $content = (string) $content;
847
-
848
- //WordPress only looks at the first 8 KiB of the file, so we do the same.
849
- $content = substr($content, 0, 8192);
850
- //Normalize line endings.
851
- $content = str_replace("\r", "\n", $content);
852
-
853
- $headers = $this->getHeaderNames();
854
- $results = array();
855
- foreach ($headers as $field => $name) {
856
- $success = preg_match('/^[ \t\/*#@]*' . preg_quote($name, '/') . ':(.*)$/mi', $content, $matches);
857
-
858
- if ( ($success === 1) && $matches[1] ) {
859
- $value = $matches[1];
860
- if ( function_exists('_cleanup_header_comment') ) {
861
- $value = _cleanup_header_comment($value);
862
- }
863
- $results[$field] = $value;
864
- } else {
865
- $results[$field] = '';
866
- }
867
- }
868
-
869
- return $results;
870
- }
871
-
872
- /**
873
- * @return array Format: ['HeaderKey' => 'Header Name']
874
- */
875
- abstract protected function getHeaderNames();
876
-
877
- /* -------------------------------------------------------------------
878
- * DebugBar integration
879
- * -------------------------------------------------------------------
880
- */
881
-
882
- /**
883
- * Initialize the update checker Debug Bar plugin/add-on thingy.
884
- */
885
- public function maybeInitDebugBar() {
886
- if ( class_exists('Debug_Bar', false) && file_exists(dirname(__FILE__ . '/DebugBar')) ) {
887
- $this->createDebugBarExtension();
888
- }
889
- }
890
-
891
- protected function createDebugBarExtension() {
892
- return new Puc_v4p4_DebugBar_Extension($this);
893
- }
894
-
895
- /**
896
- * Display additional configuration details in the Debug Bar panel.
897
- *
898
- * @param Puc_v4p4_DebugBar_Panel $panel
899
- */
900
- public function onDisplayConfiguration($panel) {
901
- //Do nothing. Subclasses can use this to add additional info to the panel.
902
- }
903
-
904
- }
905
-
906
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/UpgraderStatus.php DELETED
@@ -1,199 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_UpgraderStatus', false) ):
3
-
4
- /**
5
- * A utility class that helps figure out which plugin or theme WordPress is upgrading.
6
- *
7
- * It may seem strange to have a separate class just for that, but the task is surprisingly complicated.
8
- * Core classes like Plugin_Upgrader don't expose the plugin file name during an in-progress update (AFAICT).
9
- * This class uses a few workarounds and heuristics to get the file name.
10
- */
11
- class Puc_v4p4_UpgraderStatus {
12
- private $currentType = null; //"plugin" or "theme".
13
- private $currentId = null; //Plugin basename or theme directory name.
14
-
15
- public function __construct() {
16
- //Keep track of which plugin/theme WordPress is currently upgrading.
17
- add_filter('upgrader_pre_install', array($this, 'setUpgradedThing'), 10, 2);
18
- add_filter('upgrader_package_options', array($this, 'setUpgradedPluginFromOptions'), 10, 1);
19
- add_filter('upgrader_post_install', array($this, 'clearUpgradedThing'), 10, 1);
20
- add_action('upgrader_process_complete', array($this, 'clearUpgradedThing'), 10, 1);
21
- }
22
-
23
- /**
24
- * Is there and update being installed RIGHT NOW, for a specific plugin?
25
- *
26
- * Caution: This method is unreliable. WordPress doesn't make it easy to figure out what it is upgrading,
27
- * and upgrader implementations are liable to change without notice.
28
- *
29
- * @param string $pluginFile The plugin to check.
30
- * @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
31
- * @return bool True if the plugin identified by $pluginFile is being upgraded.
32
- */
33
- public function isPluginBeingUpgraded($pluginFile, $upgrader = null) {
34
- return $this->isBeingUpgraded('plugin', $pluginFile, $upgrader);
35
- }
36
-
37
- /**
38
- * Is there an update being installed for a specific theme?
39
- *
40
- * @param string $stylesheet Theme directory name.
41
- * @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
42
- * @return bool
43
- */
44
- public function isThemeBeingUpgraded($stylesheet, $upgrader = null) {
45
- return $this->isBeingUpgraded('theme', $stylesheet, $upgrader);
46
- }
47
-
48
- /**
49
- * Check if a specific theme or plugin is being upgraded.
50
- *
51
- * @param string $type
52
- * @param string $id
53
- * @param Plugin_Upgrader|WP_Upgrader|null $upgrader
54
- * @return bool
55
- */
56
- protected function isBeingUpgraded($type, $id, $upgrader = null) {
57
- if ( isset($upgrader) ) {
58
- list($currentType, $currentId) = $this->getThingBeingUpgradedBy($upgrader);
59
- if ( $currentType !== null ) {
60
- $this->currentType = $currentType;
61
- $this->currentId = $currentId;
62
- }
63
- }
64
- return ($this->currentType === $type) && ($this->currentId === $id);
65
- }
66
-
67
- /**
68
- * Figure out which theme or plugin is being upgraded by a WP_Upgrader instance.
69
- *
70
- * Returns an array with two items. The first item is the type of the thing that's being
71
- * upgraded: "plugin" or "theme". The second item is either the plugin basename or
72
- * the theme directory name. If we can't determine what the upgrader is doing, both items
73
- * will be NULL.
74
- *
75
- * Examples:
76
- * ['plugin', 'plugin-dir-name/plugin.php']
77
- * ['theme', 'theme-dir-name']
78
- *
79
- * @param Plugin_Upgrader|WP_Upgrader $upgrader
80
- * @return array
81
- */
82
- private function getThingBeingUpgradedBy($upgrader) {
83
- if ( !isset($upgrader, $upgrader->skin) ) {
84
- return array(null, null);
85
- }
86
-
87
- //Figure out which plugin or theme is being upgraded.
88
- $pluginFile = null;
89
- $themeDirectoryName = null;
90
-
91
- $skin = $upgrader->skin;
92
- if ( isset($skin->theme_info) && ($skin->theme_info instanceof WP_Theme) ) {
93
- $themeDirectoryName = $skin->theme_info->get_stylesheet();
94
- } elseif ( $skin instanceof Plugin_Upgrader_Skin ) {
95
- if ( isset($skin->plugin) && is_string($skin->plugin) && ($skin->plugin !== '') ) {
96
- $pluginFile = $skin->plugin;
97
- }
98
- } elseif ( $skin instanceof Theme_Upgrader_Skin ) {
99
- if ( isset($skin->theme) && is_string($skin->theme) && ($skin->theme !== '') ) {
100
- $themeDirectoryName = $skin->theme;
101
- }
102
- } elseif ( isset($skin->plugin_info) && is_array($skin->plugin_info) ) {
103
- //This case is tricky because Bulk_Plugin_Upgrader_Skin (etc) doesn't actually store the plugin
104
- //filename anywhere. Instead, it has the plugin headers in $plugin_info. So the best we can
105
- //do is compare those headers to the headers of installed plugins.
106
- $pluginFile = $this->identifyPluginByHeaders($skin->plugin_info);
107
- }
108
-
109
- if ( $pluginFile !== null ) {
110
- return array('plugin', $pluginFile);
111
- } elseif ( $themeDirectoryName !== null ) {
112
- return array('theme', $themeDirectoryName);
113
- }
114
- return array(null, null);
115
- }
116
-
117
- /**
118
- * Identify an installed plugin based on its headers.
119
- *
120
- * @param array $searchHeaders The plugin file header to look for.
121
- * @return string|null Plugin basename ("foo/bar.php"), or NULL if we can't identify the plugin.
122
- */
123
- private function identifyPluginByHeaders($searchHeaders) {
124
- if ( !function_exists('get_plugins') ){
125
- /** @noinspection PhpIncludeInspection */
126
- require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
127
- }
128
-
129
- $installedPlugins = get_plugins();
130
- $matches = array();
131
- foreach($installedPlugins as $pluginBasename => $headers) {
132
- $diff1 = array_diff_assoc($headers, $searchHeaders);
133
- $diff2 = array_diff_assoc($searchHeaders, $headers);
134
- if ( empty($diff1) && empty($diff2) ) {
135
- $matches[] = $pluginBasename;
136
- }
137
- }
138
-
139
- //It's possible (though very unlikely) that there could be two plugins with identical
140
- //headers. In that case, we can't unambiguously identify the plugin that's being upgraded.
141
- if ( count($matches) !== 1 ) {
142
- return null;
143
- }
144
-
145
- return reset($matches);
146
- }
147
-
148
- /**
149
- * @access private
150
- *
151
- * @param mixed $input
152
- * @param array $hookExtra
153
- * @return mixed Returns $input unaltered.
154
- */
155
- public function setUpgradedThing($input, $hookExtra) {
156
- if ( !empty($hookExtra['plugin']) && is_string($hookExtra['plugin']) ) {
157
- $this->currentId = $hookExtra['plugin'];
158
- $this->currentType = 'plugin';
159
- } elseif ( !empty($hookExtra['theme']) && is_string($hookExtra['theme']) ) {
160
- $this->currentId = $hookExtra['theme'];
161
- $this->currentType = 'theme';
162
- } else {
163
- $this->currentType = null;
164
- $this->currentId = null;
165
- }
166
- return $input;
167
- }
168
-
169
- /**
170
- * @access private
171
- *
172
- * @param array $options
173
- * @return array
174
- */
175
- public function setUpgradedPluginFromOptions($options) {
176
- if ( isset($options['hook_extra']['plugin']) && is_string($options['hook_extra']['plugin']) ) {
177
- $this->currentType = 'plugin';
178
- $this->currentId = $options['hook_extra']['plugin'];
179
- } else {
180
- $this->currentType = null;
181
- $this->currentId = null;
182
- }
183
- return $options;
184
- }
185
-
186
- /**
187
- * @access private
188
- *
189
- * @param mixed $input
190
- * @return mixed Returns $input unaltered.
191
- */
192
- public function clearUpgradedThing($input = null) {
193
- $this->currentId = null;
194
- $this->currentType = null;
195
- return $input;
196
- }
197
- }
198
-
199
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Utils.php DELETED
@@ -1,69 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_Utils', false) ):
4
-
5
- class Puc_v4p4_Utils {
6
- /**
7
- * Get a value from a nested array or object based on a path.
8
- *
9
- * @param array|object|null $collection Get an entry from this array.
10
- * @param array|string $path A list of array keys in hierarchy order, or a string path like "foo.bar.baz".
11
- * @param mixed $default The value to return if the specified path is not found.
12
- * @param string $separator Path element separator. Only applies to string paths.
13
- * @return mixed
14
- */
15
- public static function get($collection, $path, $default = null, $separator = '.') {
16
- if ( is_string($path) ) {
17
- $path = explode($separator, $path);
18
- }
19
-
20
- //Follow the $path into $input as far as possible.
21
- $currentValue = $collection;
22
- foreach ($path as $node) {
23
- if ( is_array($currentValue) && isset($currentValue[$node]) ) {
24
- $currentValue = $currentValue[$node];
25
- } else if ( is_object($currentValue) && isset($currentValue->$node) ) {
26
- $currentValue = $currentValue->$node;
27
- } else {
28
- return $default;
29
- }
30
- }
31
-
32
- return $currentValue;
33
- }
34
-
35
- /**
36
- * Get the first array element that is not empty.
37
- *
38
- * @param array $values
39
- * @param mixed|null $default Returns this value if there are no non-empty elements.
40
- * @return mixed|null
41
- */
42
- public static function findNotEmpty($values, $default = null) {
43
- if ( empty($values) ) {
44
- return $default;
45
- }
46
-
47
- foreach ($values as $value) {
48
- if ( !empty($value) ) {
49
- return $value;
50
- }
51
- }
52
-
53
- return $default;
54
- }
55
-
56
- /**
57
- * Check if the input string starts with the specified prefix.
58
- *
59
- * @param string $input
60
- * @param string $prefix
61
- * @return bool
62
- */
63
- public static function startsWith($input, $prefix) {
64
- $length = strlen($prefix);
65
- return (substr($input, 0, $length) === $prefix);
66
- }
67
- }
68
-
69
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Vcs/Api.php DELETED
@@ -1,302 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_Vcs_Api') ):
3
-
4
- abstract class Puc_v4p4_Vcs_Api {
5
- protected $tagNameProperty = 'name';
6
- protected $slug = '';
7
-
8
- /**
9
- * @var string
10
- */
11
- protected $repositoryUrl = '';
12
-
13
- /**
14
- * @var mixed Authentication details for private repositories. Format depends on service.
15
- */
16
- protected $credentials = null;
17
-
18
- /**
19
- * @var string The filter tag that's used to filter options passed to wp_remote_get.
20
- * For example, "puc_request_info_options-slug" or "puc_request_update_options_theme-slug".
21
- */
22
- protected $httpFilterName = '';
23
-
24
- /**
25
- * @var string|null
26
- */
27
- protected $localDirectory = null;
28
-
29
- /**
30
- * Puc_v4p4_Vcs_Api constructor.
31
- *
32
- * @param string $repositoryUrl
33
- * @param array|string|null $credentials
34
- */
35
- public function __construct($repositoryUrl, $credentials = null) {
36
- $this->repositoryUrl = $repositoryUrl;
37
- $this->setAuthentication($credentials);
38
- }
39
-
40
- /**
41
- * @return string
42
- */
43
- public function getRepositoryUrl() {
44
- return $this->repositoryUrl;
45
- }
46
-
47
- /**
48
- * Figure out which reference (i.e tag or branch) contains the latest version.
49
- *
50
- * @param string $configBranch Start looking in this branch.
51
- * @return null|Puc_v4p4_Vcs_Reference
52
- */
53
- abstract public function chooseReference($configBranch);
54
-
55
- /**
56
- * Get the readme.txt file from the remote repository and parse it
57
- * according to the plugin readme standard.
58
- *
59
- * @param string $ref Tag or branch name.
60
- * @return array Parsed readme.
61
- */
62
- public function getRemoteReadme($ref = 'master') {
63
- $fileContents = $this->getRemoteFile($this->getLocalReadmeName(), $ref);
64
- if ( empty($fileContents) ) {
65
- return array();
66
- }
67
-
68
- $parser = new PucReadmeParser();
69
- return $parser->parse_readme_contents($fileContents);
70
- }
71
-
72
- /**
73
- * Get the case-sensitive name of the local readme.txt file.
74
- *
75
- * In most cases it should just be called "readme.txt", but some plugins call it "README.txt",
76
- * "README.TXT", or even "Readme.txt". Most VCS are case-sensitive so we need to know the correct
77
- * capitalization.
78
- *
79
- * Defaults to "readme.txt" (all lowercase).
80
- *
81
- * @return string
82
- */
83
- public function getLocalReadmeName() {
84
- static $fileName = null;
85
- if ( $fileName !== null ) {
86
- return $fileName;
87
- }
88
-
89
- $fileName = 'readme.txt';
90
- if ( isset($this->localDirectory) ) {
91
- $files = scandir($this->localDirectory);
92
- if ( !empty($files) ) {
93
- foreach ($files as $possibleFileName) {
94
- if ( strcasecmp($possibleFileName, 'readme.txt') === 0 ) {
95
- $fileName = $possibleFileName;
96
- break;
97
- }
98
- }
99
- }
100
- }
101
- return $fileName;
102
- }
103
-
104
- /**
105
- * Get a branch.
106
- *
107
- * @param string $branchName
108
- * @return Puc_v4p4_Vcs_Reference|null
109
- */
110
- abstract public function getBranch($branchName);
111
-
112
- /**
113
- * Get a specific tag.
114
- *
115
- * @param string $tagName
116
- * @return Puc_v4p4_Vcs_Reference|null
117
- */
118
- abstract public function getTag($tagName);
119
-
120
- /**
121
- * Get the tag that looks like the highest version number.
122
- * (Implementations should skip pre-release versions if possible.)
123
- *
124
- * @return Puc_v4p4_Vcs_Reference|null
125
- */
126
- abstract public function getLatestTag();
127
-
128
- /**
129
- * Check if a tag name string looks like a version number.
130
- *
131
- * @param string $name
132
- * @return bool
133
- */
134
- protected function looksLikeVersion($name) {
135
- //Tag names may be prefixed with "v", e.g. "v1.2.3".
136
- $name = ltrim($name, 'v');
137
-
138
- //The version string must start with a number.
139
- if ( !is_numeric(substr($name, 0, 1)) ) {
140
- return false;
141
- }
142
-
143
- //The goal is to accept any SemVer-compatible or "PHP-standardized" version number.
144
- return (preg_match('@^(\d{1,5}?)(\.\d{1,10}?){0,4}?($|[abrdp+_\-]|\s)@i', $name) === 1);
145
- }
146
-
147
- /**
148
- * Check if a tag appears to be named like a version number.
149
- *
150
- * @param stdClass $tag
151
- * @return bool
152
- */
153
- protected function isVersionTag($tag) {
154
- $property = $this->tagNameProperty;
155
- return isset($tag->$property) && $this->looksLikeVersion($tag->$property);
156
- }
157
-
158
- /**
159
- * Sort a list of tags as if they were version numbers.
160
- * Tags that don't look like version number will be removed.
161
- *
162
- * @param stdClass[] $tags Array of tag objects.
163
- * @return stdClass[] Filtered array of tags sorted in descending order.
164
- */
165
- protected function sortTagsByVersion($tags) {
166
- //Keep only those tags that look like version numbers.
167
- $versionTags = array_filter($tags, array($this, 'isVersionTag'));
168
- //Sort them in descending order.
169
- usort($versionTags, array($this, 'compareTagNames'));
170
-
171
- return $versionTags;
172
- }
173
-
174
- /**
175
- * Compare two tags as if they were version number.
176
- *
177
- * @param stdClass $tag1 Tag object.
178
- * @param stdClass $tag2 Another tag object.
179
- * @return int
180
- */
181
- protected function compareTagNames($tag1, $tag2) {
182
- $property = $this->tagNameProperty;
183
- if ( !isset($tag1->$property) ) {
184
- return 1;
185
- }
186
- if ( !isset($tag2->$property) ) {
187
- return -1;
188
- }
189
- return -version_compare(ltrim($tag1->$property, 'v'), ltrim($tag2->$property, 'v'));
190
- }
191
-
192
- /**
193
- * Get the contents of a file from a specific branch or tag.
194
- *
195
- * @param string $path File name.
196
- * @param string $ref
197
- * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
198
- */
199
- abstract public function getRemoteFile($path, $ref = 'master');
200
-
201
- /**
202
- * Get the timestamp of the latest commit that changed the specified branch or tag.
203
- *
204
- * @param string $ref Reference name (e.g. branch or tag).
205
- * @return string|null
206
- */
207
- abstract public function getLatestCommitTime($ref);
208
-
209
- /**
210
- * Get the contents of the changelog file from the repository.
211
- *
212
- * @param string $ref
213
- * @param string $localDirectory Full path to the local plugin or theme directory.
214
- * @return null|string The HTML contents of the changelog.
215
- */
216
- public function getRemoteChangelog($ref, $localDirectory) {
217
- $filename = $this->findChangelogName($localDirectory);
218
- if ( empty($filename) ) {
219
- return null;
220
- }
221
-
222
- $changelog = $this->getRemoteFile($filename, $ref);
223
- if ( $changelog === null ) {
224
- return null;
225
- }
226
-
227
- /** @noinspection PhpUndefinedClassInspection */
228
- return Parsedown::instance()->text($changelog);
229
- }
230
-
231
- /**
232
- * Guess the name of the changelog file.
233
- *
234
- * @param string $directory
235
- * @return string|null
236
- */
237
- protected function findChangelogName($directory = null) {
238
- if ( !isset($directory) ) {
239
- $directory = $this->localDirectory;
240
- }
241
- if ( empty($directory) || !is_dir($directory) || ($directory === '.') ) {
242
- return null;
243
- }
244
-
245
- $possibleNames = array('CHANGES.md', 'CHANGELOG.md', 'changes.md', 'changelog.md');
246
- $files = scandir($directory);
247
- $foundNames = array_intersect($possibleNames, $files);
248
-
249
- if ( !empty($foundNames) ) {
250
- return reset($foundNames);
251
- }
252
- return null;
253
- }
254
-
255
- /**
256
- * Set authentication credentials.
257
- *
258
- * @param $credentials
259
- */
260
- public function setAuthentication($credentials) {
261
- $this->credentials = $credentials;
262
- }
263
-
264
- public function isAuthenticationEnabled() {
265
- return !empty($this->credentials);
266
- }
267
-
268
- /**
269
- * @param string $url
270
- * @return string
271
- */
272
- public function signDownloadUrl($url) {
273
- return $url;
274
- }
275
-
276
- /**
277
- * @param string $filterName
278
- */
279
- public function setHttpFilterName($filterName) {
280
- $this->httpFilterName = $filterName;
281
- }
282
-
283
- /**
284
- * @param string $directory
285
- */
286
- public function setLocalDirectory($directory) {
287
- if ( empty($directory) || !is_dir($directory) || ($directory === '.') ) {
288
- $this->localDirectory = null;
289
- } else {
290
- $this->localDirectory = $directory;
291
- }
292
- }
293
-
294
- /**
295
- * @param string $slug
296
- */
297
- public function setSlug($slug) {
298
- $this->slug = $slug;
299
- }
300
- }
301
-
302
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Vcs/BaseChecker.php DELETED
@@ -1,27 +0,0 @@
1
- <?php
2
- if ( !interface_exists('Puc_v4p4_Vcs_BaseChecker', false) ):
3
-
4
- interface Puc_v4p4_Vcs_BaseChecker {
5
- /**
6
- * Set the repository branch to use for updates. Defaults to 'master'.
7
- *
8
- * @param string $branch
9
- * @return $this
10
- */
11
- public function setBranch($branch);
12
-
13
- /**
14
- * Set authentication credentials.
15
- *
16
- * @param array|string $credentials
17
- * @return $this
18
- */
19
- public function setAuthentication($credentials);
20
-
21
- /**
22
- * @return Puc_v4p4_Vcs_Api
23
- */
24
- public function getVcsApi();
25
- }
26
-
27
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Vcs/BitBucketApi.php DELETED
@@ -1,256 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
3
-
4
- class Puc_v4p4_Vcs_BitBucketApi extends Puc_v4p4_Vcs_Api {
5
- /**
6
- * @var Puc_v4p4_OAuthSignature
7
- */
8
- private $oauth = null;
9
-
10
- /**
11
- * @var string
12
- */
13
- private $username;
14
-
15
- /**
16
- * @var string
17
- */
18
- private $repository;
19
-
20
- public function __construct($repositoryUrl, $credentials = array()) {
21
- $path = @parse_url($repositoryUrl, PHP_URL_PATH);
22
- if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
23
- $this->username = $matches['username'];
24
- $this->repository = $matches['repository'];
25
- } else {
26
- throw new InvalidArgumentException('Invalid BitBucket repository URL: "' . $repositoryUrl . '"');
27
- }
28
-
29
- parent::__construct($repositoryUrl, $credentials);
30
- }
31
-
32
- /**
33
- * Figure out which reference (i.e tag or branch) contains the latest version.
34
- *
35
- * @param string $configBranch Start looking in this branch.
36
- * @return null|Puc_v4p4_Vcs_Reference
37
- */
38
- public function chooseReference($configBranch) {
39
- $updateSource = null;
40
-
41
- //Check if there's a "Stable tag: 1.2.3" header that points to a valid tag.
42
- $updateSource = $this->getStableTag($configBranch);
43
-
44
- //Look for version-like tags.
45
- if ( !$updateSource && ($configBranch === 'master') ) {
46
- $updateSource = $this->getLatestTag();
47
- }
48
- //If all else fails, use the specified branch itself.
49
- if ( !$updateSource ) {
50
- $updateSource = $this->getBranch($configBranch);
51
- }
52
-
53
- return $updateSource;
54
- }
55
-
56
- public function getBranch($branchName) {
57
- $branch = $this->api('/refs/branches/' . $branchName);
58
- if ( is_wp_error($branch) || empty($branch) ) {
59
- return null;
60
- }
61
-
62
- return new Puc_v4p4_Vcs_Reference(array(
63
- 'name' => $branch->name,
64
- 'updated' => $branch->target->date,
65
- 'downloadUrl' => $this->getDownloadUrl($branch->name),
66
- ));
67
- }
68
-
69
- /**
70
- * Get a specific tag.
71
- *
72
- * @param string $tagName
73
- * @return Puc_v4p4_Vcs_Reference|null
74
- */
75
- public function getTag($tagName) {
76
- $tag = $this->api('/refs/tags/' . $tagName);
77
- if ( is_wp_error($tag) || empty($tag) ) {
78
- return null;
79
- }
80
-
81
- return new Puc_v4p4_Vcs_Reference(array(
82
- 'name' => $tag->name,
83
- 'version' => ltrim($tag->name, 'v'),
84
- 'updated' => $tag->target->date,
85
- 'downloadUrl' => $this->getDownloadUrl($tag->name),
86
- ));
87
- }
88
-
89
- /**
90
- * Get the tag that looks like the highest version number.
91
- *
92
- * @return Puc_v4p4_Vcs_Reference|null
93
- */
94
- public function getLatestTag() {
95
- $tags = $this->api('/refs/tags?sort=-target.date');
96
- if ( !isset($tags, $tags->values) || !is_array($tags->values) ) {
97
- return null;
98
- }
99
-
100
- //Filter and sort the list of tags.
101
- $versionTags = $this->sortTagsByVersion($tags->values);
102
-
103
- //Return the first result.
104
- if ( !empty($versionTags) ) {
105
- $tag = $versionTags[0];
106
- return new Puc_v4p4_Vcs_Reference(array(
107
- 'name' => $tag->name,
108
- 'version' => ltrim($tag->name, 'v'),
109
- 'updated' => $tag->target->date,
110
- 'downloadUrl' => $this->getDownloadUrl($tag->name),
111
- ));
112
- }
113
- return null;
114
- }
115
-
116
- /**
117
- * Get the tag/ref specified by the "Stable tag" header in the readme.txt of a given branch.
118
- *
119
- * @param string $branch
120
- * @return null|Puc_v4p4_Vcs_Reference
121
- */
122
- protected function getStableTag($branch) {
123
- $remoteReadme = $this->getRemoteReadme($branch);
124
- if ( !empty($remoteReadme['stable_tag']) ) {
125
- $tag = $remoteReadme['stable_tag'];
126
-
127
- //You can explicitly opt out of using tags by setting "Stable tag" to
128
- //"trunk" or the name of the current branch.
129
- if ( ($tag === $branch) || ($tag === 'trunk') ) {
130
- return $this->getBranch($branch);
131
- }
132
-
133
- return $this->getTag($tag);
134
- }
135
-
136
- return null;
137
- }
138
-
139
- /**
140
- * @param string $ref
141
- * @return string
142
- */
143
- protected function getDownloadUrl($ref) {
144
- return sprintf(
145
- 'https://bitbucket.org/%s/%s/get/%s.zip',
146
- $this->username,
147
- $this->repository,
148
- $ref
149
- );
150
- }
151
-
152
- /**
153
- * Get the contents of a file from a specific branch or tag.
154
- *
155
- * @param string $path File name.
156
- * @param string $ref
157
- * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
158
- */
159
- public function getRemoteFile($path, $ref = 'master') {
160
- $response = $this->api('src/' . $ref . '/' . ltrim($path), '1.0');
161
- if ( is_wp_error($response) || !isset($response, $response->data) ) {
162
- return null;
163
- }
164
- return $response->data;
165
- }
166
-
167
- /**
168
- * Get the timestamp of the latest commit that changed the specified branch or tag.
169
- *
170
- * @param string $ref Reference name (e.g. branch or tag).
171
- * @return string|null
172
- */
173
- public function getLatestCommitTime($ref) {
174
- $response = $this->api('commits/' . $ref);
175
- if ( isset($response->values, $response->values[0], $response->values[0]->date) ) {
176
- return $response->values[0]->date;
177
- }
178
- return null;
179
- }
180
-
181
- /**
182
- * Perform a BitBucket API 2.0 request.
183
- *
184
- * @param string $url
185
- * @param string $version
186
- * @return mixed|WP_Error
187
- */
188
- public function api($url, $version = '2.0') {
189
- $url = implode('/', array(
190
- 'https://api.bitbucket.org',
191
- $version,
192
- 'repositories',
193
- $this->username,
194
- $this->repository,
195
- ltrim($url, '/')
196
- ));
197
- $baseUrl = $url;
198
-
199
- if ( $this->oauth ) {
200
- $url = $this->oauth->sign($url,'GET');
201
- }
202
-
203
- $options = array('timeout' => 10);
204
- if ( !empty($this->httpFilterName) ) {
205
- $options = apply_filters($this->httpFilterName, $options);
206
- }
207
- $response = wp_remote_get($url, $options);
208
- if ( is_wp_error($response) ) {
209
- do_action('puc_api_error', $response, null, $url, $this->slug);
210
- return $response;
211
- }
212
-
213
- $code = wp_remote_retrieve_response_code($response);
214
- $body = wp_remote_retrieve_body($response);
215
- if ( $code === 200 ) {
216
- $document = json_decode($body);
217
- return $document;
218
- }
219
-
220
- $error = new WP_Error(
221
- 'puc-bitbucket-http-error',
222
- sprintf('BitBucket API error. Base URL: "%s", HTTP status code: %d.', $baseUrl, $code)
223
- );
224
- do_action('puc_api_error', $error, $response, $url, $this->slug);
225
-
226
- return $error;
227
- }
228
-
229
- /**
230
- * @param array $credentials
231
- */
232
- public function setAuthentication($credentials) {
233
- parent::setAuthentication($credentials);
234
-
235
- if ( !empty($credentials) && !empty($credentials['consumer_key']) ) {
236
- $this->oauth = new Puc_v4p4_OAuthSignature(
237
- $credentials['consumer_key'],
238
- $credentials['consumer_secret']
239
- );
240
- } else {
241
- $this->oauth = null;
242
- }
243
- }
244
-
245
- public function signDownloadUrl($url) {
246
- //Add authentication data to download URLs. Since OAuth signatures incorporate
247
- //timestamps, we have to do this immediately before inserting the update. Otherwise
248
- //authentication could fail due to a stale timestamp.
249
- if ( $this->oauth ) {
250
- $url = $this->oauth->sign($url);
251
- }
252
- return $url;
253
- }
254
- }
255
-
256
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Vcs/GitHubApi.php DELETED
@@ -1,413 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_Vcs_GitHubApi', false) ):
4
-
5
- class Puc_v4p4_Vcs_GitHubApi extends Puc_v4p4_Vcs_Api {
6
- /**
7
- * @var string GitHub username.
8
- */
9
- protected $userName;
10
- /**
11
- * @var string GitHub repository name.
12
- */
13
- protected $repositoryName;
14
-
15
- /**
16
- * @var string Either a fully qualified repository URL, or just "user/repo-name".
17
- */
18
- protected $repositoryUrl;
19
-
20
- /**
21
- * @var string GitHub authentication token. Optional.
22
- */
23
- protected $accessToken;
24
-
25
- /**
26
- * @var bool Whether to download release assets instead of the auto-generated source code archives.
27
- */
28
- protected $releaseAssetsEnabled = false;
29
-
30
- /**
31
- * @var string|null Regular expression that's used to filter release assets by name. Optional.
32
- */
33
- protected $assetFilterRegex = null;
34
-
35
- /**
36
- * @var string|null The unchanging part of a release asset URL. Used to identify download attempts.
37
- */
38
- protected $assetApiBaseUrl = null;
39
-
40
- public function __construct($repositoryUrl, $accessToken = null) {
41
- $path = @parse_url($repositoryUrl, PHP_URL_PATH);
42
- if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
43
- $this->userName = $matches['username'];
44
- $this->repositoryName = $matches['repository'];
45
- } else {
46
- throw new InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"');
47
- }
48
-
49
- parent::__construct($repositoryUrl, $accessToken);
50
- }
51
-
52
- /**
53
- * Get the latest release from GitHub.
54
- *
55
- * @return Puc_v4p4_Vcs_Reference|null
56
- */
57
- public function getLatestRelease() {
58
- $release = $this->api('/repos/:user/:repo/releases/latest');
59
- if ( is_wp_error($release) || !is_object($release) || !isset($release->tag_name) ) {
60
- return null;
61
- }
62
-
63
- $reference = new Puc_v4p4_Vcs_Reference(array(
64
- 'name' => $release->tag_name,
65
- 'version' => ltrim($release->tag_name, 'v'), //Remove the "v" prefix from "v1.2.3".
66
- 'downloadUrl' => $this->signDownloadUrl($release->zipball_url),
67
- 'updated' => $release->created_at,
68
- 'apiResponse' => $release,
69
- ));
70
-
71
- if ( isset($release->assets[0]) ) {
72
- $reference->downloadCount = $release->assets[0]->download_count;
73
- }
74
-
75
- if ( $this->releaseAssetsEnabled && isset($release->assets, $release->assets[0]) ) {
76
- //Use the first release asset that matches the specified regular expression.
77
- $matchingAssets = array_filter($release->assets, array($this, 'matchesAssetFilter'));
78
- if ( !empty($matchingAssets) ) {
79
- if ( $this->isAuthenticationEnabled() ) {
80
- /**
81
- * Keep in mind that we'll need to add an "Accept" header to download this asset.
82
- * @see setReleaseDownloadHeader()
83
- */
84
- $reference->downloadUrl = $this->signDownloadUrl($matchingAssets[0]->url);
85
- } else {
86
- //It seems that browser_download_url only works for public repositories.
87
- //Using an access_token doesn't help. Maybe OAuth would work?
88
- $reference->downloadUrl = $matchingAssets[0]->browser_download_url;
89
- }
90
-
91
- $reference->downloadCount = $matchingAssets[0]->download_count;
92
- }
93
- }
94
-
95
- if ( !empty($release->body) ) {
96
- /** @noinspection PhpUndefinedClassInspection */
97
- $reference->changelog = Parsedown::instance()->text($release->body);
98
- }
99
-
100
- return $reference;
101
- }
102
-
103
- /**
104
- * Get the tag that looks like the highest version number.
105
- *
106
- * @return Puc_v4p4_Vcs_Reference|null
107
- */
108
- public function getLatestTag() {
109
- $tags = $this->api('/repos/:user/:repo/tags');
110
-
111
- if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) {
112
- return null;
113
- }
114
-
115
- $versionTags = $this->sortTagsByVersion($tags);
116
- if ( empty($versionTags) ) {
117
- return null;
118
- }
119
-
120
- $tag = $versionTags[0];
121
- return new Puc_v4p4_Vcs_Reference(array(
122
- 'name' => $tag->name,
123
- 'version' => ltrim($tag->name, 'v'),
124
- 'downloadUrl' => $this->signDownloadUrl($tag->zipball_url),
125
- 'apiResponse' => $tag,
126
- ));
127
- }
128
-
129
- /**
130
- * Get a branch by name.
131
- *
132
- * @param string $branchName
133
- * @return null|Puc_v4p4_Vcs_Reference
134
- */
135
- public function getBranch($branchName) {
136
- $branch = $this->api('/repos/:user/:repo/branches/' . $branchName);
137
- if ( is_wp_error($branch) || empty($branch) ) {
138
- return null;
139
- }
140
-
141
- $reference = new Puc_v4p4_Vcs_Reference(array(
142
- 'name' => $branch->name,
143
- 'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
144
- 'apiResponse' => $branch,
145
- ));
146
-
147
- if ( isset($branch->commit, $branch->commit->commit, $branch->commit->commit->author->date) ) {
148
- $reference->updated = $branch->commit->commit->author->date;
149
- }
150
-
151
- return $reference;
152
- }
153
-
154
- /**
155
- * Get the latest commit that changed the specified file.
156
- *
157
- * @param string $filename
158
- * @param string $ref Reference name (e.g. branch or tag).
159
- * @return StdClass|null
160
- */
161
- public function getLatestCommit($filename, $ref = 'master') {
162
- $commits = $this->api(
163
- '/repos/:user/:repo/commits',
164
- array(
165
- 'path' => $filename,
166
- 'sha' => $ref,
167
- )
168
- );
169
- if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
170
- return $commits[0];
171
- }
172
- return null;
173
- }
174
-
175
- /**
176
- * Get the timestamp of the latest commit that changed the specified branch or tag.
177
- *
178
- * @param string $ref Reference name (e.g. branch or tag).
179
- * @return string|null
180
- */
181
- public function getLatestCommitTime($ref) {
182
- $commits = $this->api('/repos/:user/:repo/commits', array('sha' => $ref));
183
- if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
184
- return $commits[0]->commit->author->date;
185
- }
186
- return null;
187
- }
188
-
189
- /**
190
- * Perform a GitHub API request.
191
- *
192
- * @param string $url
193
- * @param array $queryParams
194
- * @return mixed|WP_Error
195
- */
196
- protected function api($url, $queryParams = array()) {
197
- $baseUrl = $url;
198
- $url = $this->buildApiUrl($url, $queryParams);
199
-
200
- $options = array('timeout' => 10);
201
- if ( !empty($this->httpFilterName) ) {
202
- $options = apply_filters($this->httpFilterName, $options);
203
- }
204
- $response = wp_remote_get($url, $options);
205
- if ( is_wp_error($response) ) {
206
- do_action('puc_api_error', $response, null, $url, $this->slug);
207
- return $response;
208
- }
209
-
210
- $code = wp_remote_retrieve_response_code($response);
211
- $body = wp_remote_retrieve_body($response);
212
- if ( $code === 200 ) {
213
- $document = json_decode($body);
214
- return $document;
215
- }
216
-
217
- $error = new WP_Error(
218
- 'puc-github-http-error',
219
- sprintf('GitHub API error. Base URL: "%s", HTTP status code: %d.', $baseUrl, $code)
220
- );
221
- do_action('puc_api_error', $error, $response, $url, $this->slug);
222
-
223
- return $error;
224
- }
225
-
226
- /**
227
- * Build a fully qualified URL for an API request.
228
- *
229
- * @param string $url
230
- * @param array $queryParams
231
- * @return string
232
- */
233
- protected function buildApiUrl($url, $queryParams) {
234
- $variables = array(
235
- 'user' => $this->userName,
236
- 'repo' => $this->repositoryName,
237
- );
238
- foreach ($variables as $name => $value) {
239
- $url = str_replace('/:' . $name, '/' . urlencode($value), $url);
240
- }
241
- $url = 'https://api.github.com' . $url;
242
-
243
- if ( !empty($this->accessToken) ) {
244
- $queryParams['access_token'] = $this->accessToken;
245
- }
246
- if ( !empty($queryParams) ) {
247
- $url = add_query_arg($queryParams, $url);
248
- }
249
-
250
- return $url;
251
- }
252
-
253
- /**
254
- * Get the contents of a file from a specific branch or tag.
255
- *
256
- * @param string $path File name.
257
- * @param string $ref
258
- * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
259
- */
260
- public function getRemoteFile($path, $ref = 'master') {
261
- $apiUrl = '/repos/:user/:repo/contents/' . $path;
262
- $response = $this->api($apiUrl, array('ref' => $ref));
263
-
264
- if ( is_wp_error($response) || !isset($response->content) || ($response->encoding !== 'base64') ) {
265
- return null;
266
- }
267
- return base64_decode($response->content);
268
- }
269
-
270
- /**
271
- * Generate a URL to download a ZIP archive of the specified branch/tag/etc.
272
- *
273
- * @param string $ref
274
- * @return string
275
- */
276
- public function buildArchiveDownloadUrl($ref = 'master') {
277
- $url = sprintf(
278
- 'https://api.github.com/repos/%1$s/%2$s/zipball/%3$s',
279
- urlencode($this->userName),
280
- urlencode($this->repositoryName),
281
- urlencode($ref)
282
- );
283
- if ( !empty($this->accessToken) ) {
284
- $url = $this->signDownloadUrl($url);
285
- }
286
- return $url;
287
- }
288
-
289
- /**
290
- * Get a specific tag.
291
- *
292
- * @param string $tagName
293
- * @return Puc_v4p4_Vcs_Reference|null
294
- */
295
- public function getTag($tagName) {
296
- //The current GitHub update checker doesn't use getTag, so I didn't bother to implement it.
297
- throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
298
- }
299
-
300
- public function setAuthentication($credentials) {
301
- parent::setAuthentication($credentials);
302
- $this->accessToken = is_string($credentials) ? $credentials : null;
303
- }
304
-
305
- /**
306
- * Figure out which reference (i.e tag or branch) contains the latest version.
307
- *
308
- * @param string $configBranch Start looking in this branch.
309
- * @return null|Puc_v4p4_Vcs_Reference
310
- */
311
- public function chooseReference($configBranch) {
312
- $updateSource = null;
313
-
314
- if ( $configBranch === 'master' ) {
315
- //Use the latest release.
316
- $updateSource = $this->getLatestRelease();
317
- if ( $updateSource === null ) {
318
- //Failing that, use the tag with the highest version number.
319
- $updateSource = $this->getLatestTag();
320
- }
321
- }
322
- //Alternatively, just use the branch itself.
323
- if ( empty($updateSource) ) {
324
- $updateSource = $this->getBranch($configBranch);
325
- }
326
-
327
- return $updateSource;
328
- }
329
-
330
- /**
331
- * @param string $url
332
- * @return string
333
- */
334
- public function signDownloadUrl($url) {
335
- if ( empty($this->credentials) ) {
336
- return $url;
337
- }
338
- return add_query_arg('access_token', $this->credentials, $url);
339
- }
340
-
341
- /**
342
- * Enable updating via release assets.
343
- *
344
- * If the latest release contains no usable assets, the update checker
345
- * will fall back to using the automatically generated ZIP archive.
346
- *
347
- * Private repositories will only work with WordPress 3.7 or later.
348
- *
349
- * @param string|null $fileNameRegex Optional. Use only those assets where the file name matches this regex.
350
- */
351
- public function enableReleaseAssets($fileNameRegex = null) {
352
- $this->releaseAssetsEnabled = true;
353
- $this->assetFilterRegex = $fileNameRegex;
354
- $this->assetApiBaseUrl = sprintf(
355
- '//api.github.com/repos/%1$s/%2$s/releases/assets/',
356
- $this->userName,
357
- $this->repositoryName
358
- );
359
-
360
- //Optimization: Instead of filtering all HTTP requests, let's do it only when
361
- //WordPress is about to download an update.
362
- add_filter('upgrader_pre_download', array($this, 'addHttpRequestFilter'), 10, 1); //WP 3.7+
363
- }
364
-
365
- /**
366
- * Does this asset match the file name regex?
367
- *
368
- * @param stdClass $releaseAsset
369
- * @return bool
370
- */
371
- protected function matchesAssetFilter($releaseAsset) {
372
- if ( $this->assetFilterRegex === null ) {
373
- //The default is to accept all assets.
374
- return true;
375
- }
376
- return isset($releaseAsset->name) && preg_match($this->assetFilterRegex, $releaseAsset->name);
377
- }
378
-
379
- /**
380
- * @internal
381
- * @param bool $result
382
- * @return bool
383
- */
384
- public function addHttpRequestFilter($result) {
385
- static $filterAdded = false;
386
- if ( $this->releaseAssetsEnabled && !$filterAdded && $this->isAuthenticationEnabled() ) {
387
- add_filter('http_request_args', array($this, 'setReleaseDownloadHeader'), 10, 2);
388
- $filterAdded = true;
389
- }
390
- return $result;
391
- }
392
-
393
- /**
394
- * Set the HTTP header that's necessary to download private release assets.
395
- *
396
- * See GitHub docs:
397
- * @link https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
398
- *
399
- * @internal
400
- * @param array $requestArgs
401
- * @param string $url
402
- * @return array
403
- */
404
- public function setReleaseDownloadHeader($requestArgs, $url = '') {
405
- //Is WordPress trying to download one of our assets?
406
- if ( strpos($url, $this->assetApiBaseUrl) !== false ) {
407
- $requestArgs['headers']['accept'] = 'application/octet-stream';
408
- }
409
- return $requestArgs;
410
- }
411
- }
412
-
413
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Vcs/GitLabApi.php DELETED
@@ -1,278 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_Vcs_GitLabApi', false) ):
4
-
5
- class Puc_v4p4_Vcs_GitLabApi extends Puc_v4p4_Vcs_Api {
6
- /**
7
- * @var string GitLab username.
8
- */
9
- protected $userName;
10
-
11
- /**
12
- * @var string GitLab server host.
13
- */
14
- private $repositoryHost;
15
-
16
- /**
17
- * @var string GitLab repository name.
18
- */
19
- protected $repositoryName;
20
-
21
- /**
22
- * @var string GitLab authentication token. Optional.
23
- */
24
- protected $accessToken;
25
-
26
- public function __construct($repositoryUrl, $accessToken = null) {
27
- //Parse the repository host to support custom hosts.
28
- $port = @parse_url($repositoryUrl, PHP_URL_PORT);
29
- if ( !empty($port) ){
30
- $port = ':' . $port;
31
- }
32
- $this->repositoryHost = @parse_url($repositoryUrl, PHP_URL_HOST) . $port;
33
-
34
- //Find the repository information
35
- $path = @parse_url($repositoryUrl, PHP_URL_PATH);
36
- if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
37
- $this->userName = $matches['username'];
38
- $this->repositoryName = $matches['repository'];
39
- } else {
40
- //This is not a traditional url, it could be gitlab is in a deeper subdirectory.
41
- //Get the path segments.
42
- $segments = explode('/', untrailingslashit(ltrim($path, '/')));
43
-
44
- //We need at least /user-name/repository-name/
45
- if ( count($segments) < 2 ) {
46
- throw new InvalidArgumentException('Invalid GitLab repository URL: "' . $repositoryUrl . '"');
47
- }
48
-
49
- //Get the username and repository name.
50
- $usernameRepo = array_splice($segments, -2, 2);
51
- $this->userName = $usernameRepo[0];
52
- $this->repositoryName = $usernameRepo[1];
53
-
54
- //Append the remaining segments to the host.
55
- $this->repositoryHost = trailingslashit($this->repositoryHost) . implode('/', $segments);
56
- }
57
-
58
- parent::__construct($repositoryUrl, $accessToken);
59
- }
60
-
61
- /**
62
- * Get the latest release from GitLab.
63
- *
64
- * @return Puc_v4p4_Vcs_Reference|null
65
- */
66
- public function getLatestRelease() {
67
- return $this->getLatestTag();
68
- }
69
-
70
- /**
71
- * Get the tag that looks like the highest version number.
72
- *
73
- * @return Puc_v4p4_Vcs_Reference|null
74
- */
75
- public function getLatestTag() {
76
- $tags = $this->api('/:user/:repo/repository/tags');
77
- if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) {
78
- return null;
79
- }
80
-
81
- $versionTags = $this->sortTagsByVersion($tags);
82
- if ( empty($versionTags) ) {
83
- return null;
84
- }
85
-
86
- $tag = $versionTags[0];
87
- return new Puc_v4p4_Vcs_Reference(array(
88
- 'name' => $tag->name,
89
- 'version' => ltrim($tag->name, 'v'),
90
- 'downloadUrl' => $this->buildArchiveDownloadUrl($tag->name),
91
- 'apiResponse' => $tag
92
- ));
93
- }
94
-
95
- /**
96
- * Get a branch by name.
97
- *
98
- * @param string $branchName
99
- * @return null|Puc_v4p4_Vcs_Reference
100
- */
101
- public function getBranch($branchName) {
102
- $branch = $this->api('/:user/:repo/repository/branches/' . $branchName);
103
- if ( is_wp_error($branch) || empty($branch) ) {
104
- return null;
105
- }
106
-
107
- $reference = new Puc_v4p4_Vcs_Reference(array(
108
- 'name' => $branch->name,
109
- 'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
110
- 'apiResponse' => $branch,
111
- ));
112
-
113
- if ( isset($branch->commit, $branch->commit->committed_date) ) {
114
- $reference->updated = $branch->commit->committed_date;
115
- }
116
-
117
- return $reference;
118
- }
119
-
120
- /**
121
- * Get the timestamp of the latest commit that changed the specified branch or tag.
122
- *
123
- * @param string $ref Reference name (e.g. branch or tag).
124
- * @return string|null
125
- */
126
- public function getLatestCommitTime($ref) {
127
- $commits = $this->api('/:user/:repo/repository/commits/', array('ref_name' => $ref));
128
- if ( is_wp_error($commits) || !is_array($commits) || !isset($commits[0]) ) {
129
- return null;
130
- }
131
-
132
- return $commits[0]->committed_date;
133
- }
134
-
135
- /**
136
- * Perform a GitLab API request.
137
- *
138
- * @param string $url
139
- * @param array $queryParams
140
- * @return mixed|WP_Error
141
- */
142
- protected function api($url, $queryParams = array()) {
143
- $baseUrl = $url;
144
- $url = $this->buildApiUrl($url, $queryParams);
145
-
146
- $options = array('timeout' => 10);
147
- if ( !empty($this->httpFilterName) ) {
148
- $options = apply_filters($this->httpFilterName, $options);
149
- }
150
-
151
- $response = wp_remote_get($url, $options);
152
- if ( is_wp_error($response) ) {
153
- do_action('puc_api_error', $response, null, $url, $this->slug);
154
- return $response;
155
- }
156
-
157
- $code = wp_remote_retrieve_response_code($response);
158
- $body = wp_remote_retrieve_body($response);
159
- if ( $code === 200 ) {
160
- return json_decode($body);
161
- }
162
-
163
- $error = new WP_Error(
164
- 'puc-gitlab-http-error',
165
- sprintf('GitLab API error. URL: "%s", HTTP status code: %d.', $baseUrl, $code)
166
- );
167
- do_action('puc_api_error', $error, $response, $url, $this->slug);
168
-
169
- return $error;
170
- }
171
-
172
- /**
173
- * Build a fully qualified URL for an API request.
174
- *
175
- * @param string $url
176
- * @param array $queryParams
177
- * @return string
178
- */
179
- protected function buildApiUrl($url, $queryParams) {
180
- $variables = array(
181
- 'user' => $this->userName,
182
- 'repo' => $this->repositoryName
183
- );
184
-
185
- foreach ($variables as $name => $value) {
186
- $url = str_replace("/:{$name}", urlencode('/' . $value), $url);
187
- }
188
-
189
- $url = substr($url, 3);
190
- $url = sprintf('https://%1$s/api/v4/projects/%2$s', $this->repositoryHost, $url);
191
-
192
- if ( !empty($this->accessToken) ) {
193
- $queryParams['private_token'] = $this->accessToken;
194
- }
195
-
196
- if ( !empty($queryParams) ) {
197
- $url = add_query_arg($queryParams, $url);
198
- }
199
-
200
- return $url;
201
- }
202
-
203
- /**
204
- * Get the contents of a file from a specific branch or tag.
205
- *
206
- * @param string $path File name.
207
- * @param string $ref
208
- * @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
209
- */
210
- public function getRemoteFile($path, $ref = 'master') {
211
- $response = $this->api('/:user/:repo/repository/files/' . $path, array('ref' => $ref));
212
- if ( is_wp_error($response) || !isset($response->content) || $response->encoding !== 'base64' ) {
213
- return null;
214
- }
215
-
216
- return base64_decode($response->content);
217
- }
218
-
219
- /**
220
- * Generate a URL to download a ZIP archive of the specified branch/tag/etc.
221
- *
222
- * @param string $ref
223
- * @return string
224
- */
225
- public function buildArchiveDownloadUrl($ref = 'master') {
226
- $url = sprintf(
227
- 'https://%1$s/%2$s/%3$s/repository/%4$s/archive.zip',
228
- $this->repositoryHost,
229
- urlencode($this->userName),
230
- urlencode($this->repositoryName),
231
- urlencode($ref)
232
- );
233
-
234
- if ( !empty($this->accessToken) ) {
235
- $url = add_query_arg('private_token', $this->accessToken, $url);
236
- }
237
-
238
- return $url;
239
- }
240
-
241
- /**
242
- * Get a specific tag.
243
- *
244
- * @param string $tagName
245
- * @return Puc_v4p4_Vcs_Reference|null
246
- */
247
- public function getTag($tagName) {
248
- throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
249
- }
250
-
251
- /**
252
- * Figure out which reference (i.e tag or branch) contains the latest version.
253
- *
254
- * @param string $configBranch Start looking in this branch.
255
- * @return null|Puc_v4p4_Vcs_Reference
256
- */
257
- public function chooseReference($configBranch) {
258
- $updateSource = null;
259
-
260
- // GitLab doesn't handle releases the same as GitHub so just use the latest tag
261
- if ( $configBranch === 'master' ) {
262
- $updateSource = $this->getLatestTag();
263
- }
264
-
265
- if ( empty($updateSource) ) {
266
- $updateSource = $this->getBranch($configBranch);
267
- }
268
-
269
- return $updateSource;
270
- }
271
-
272
- public function setAuthentication($credentials) {
273
- parent::setAuthentication($credentials);
274
- $this->accessToken = is_string($credentials) ? $credentials : null;
275
- }
276
- }
277
-
278
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Vcs/PluginUpdateChecker.php DELETED
@@ -1,217 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
3
-
4
- class Puc_v4p4_Vcs_PluginUpdateChecker extends Puc_v4p4_Plugin_UpdateChecker implements Puc_v4p4_Vcs_BaseChecker {
5
- /**
6
- * @var string The branch where to look for updates. Defaults to "master".
7
- */
8
- protected $branch = 'master';
9
-
10
- /**
11
- * @var Puc_v4p4_Vcs_Api Repository API client.
12
- */
13
- protected $api = null;
14
-
15
- /**
16
- * Puc_v4p4_Vcs_PluginUpdateChecker constructor.
17
- *
18
- * @param Puc_v4p4_Vcs_Api $api
19
- * @param string $pluginFile
20
- * @param string $slug
21
- * @param int $checkPeriod
22
- * @param string $optionName
23
- * @param string $muPluginFile
24
- */
25
- public function __construct($api, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
26
- $this->api = $api;
27
- $this->api->setHttpFilterName($this->getUniqueName('request_info_options'));
28
-
29
- parent::__construct($api->getRepositoryUrl(), $pluginFile, $slug, $checkPeriod, $optionName, $muPluginFile);
30
-
31
- $this->api->setSlug($this->slug);
32
- }
33
-
34
- public function requestInfo($unusedParameter = null) {
35
- //We have to make several remote API requests to gather all the necessary info
36
- //which can take a while on slow networks.
37
- if ( function_exists('set_time_limit') ) {
38
- @set_time_limit(60);
39
- }
40
-
41
- $api = $this->api;
42
- $api->setLocalDirectory($this->getAbsoluteDirectoryPath());
43
-
44
- $info = new Puc_v4p4_Plugin_Info();
45
- $info->filename = $this->pluginFile;
46
- $info->slug = $this->slug;
47
-
48
- $this->setInfoFromHeader($this->getPluginHeader(), $info);
49
-
50
- //Pick a branch or tag.
51
- $updateSource = $api->chooseReference($this->branch);
52
- if ( $updateSource ) {
53
- $ref = $updateSource->name;
54
- $info->version = $updateSource->version;
55
- $info->last_updated = $updateSource->updated;
56
- $info->download_url = $updateSource->downloadUrl;
57
-
58
- if ( !empty($updateSource->changelog) ) {
59
- $info->sections['changelog'] = $updateSource->changelog;
60
- }
61
- if ( isset($updateSource->downloadCount) ) {
62
- $info->downloaded = $updateSource->downloadCount;
63
- }
64
- } else {
65
- //There's probably a network problem or an authentication error.
66
- do_action(
67
- 'puc_api_error',
68
- new WP_Error(
69
- 'puc-no-update-source',
70
- 'Could not retrieve version information from the repository. '
71
- . 'This usually means that the update checker either can\'t connect '
72
- . 'to the repository or it\'s configured incorrectly.'
73
- ),
74
- null, null, $this->slug
75
- );
76
- return null;
77
- }
78
-
79
- //Get headers from the main plugin file in this branch/tag. Its "Version" header and other metadata
80
- //are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags.
81
- $mainPluginFile = basename($this->pluginFile);
82
- $remotePlugin = $api->getRemoteFile($mainPluginFile, $ref);
83
- if ( !empty($remotePlugin) ) {
84
- $remoteHeader = $this->getFileHeader($remotePlugin);
85
- $this->setInfoFromHeader($remoteHeader, $info);
86
- }
87
-
88
- //Try parsing readme.txt. If it's formatted according to WordPress.org standards, it will contain
89
- //a lot of useful information like the required/tested WP version, changelog, and so on.
90
- if ( $this->readmeTxtExistsLocally() ) {
91
- $this->setInfoFromRemoteReadme($ref, $info);
92
- }
93
-
94
- //The changelog might be in a separate file.
95
- if ( empty($info->sections['changelog']) ) {
96
- $info->sections['changelog'] = $api->getRemoteChangelog($ref, dirname($this->getAbsolutePath()));
97
- if ( empty($info->sections['changelog']) ) {
98
- $info->sections['changelog'] = __('There is no changelog available.', 'plugin-update-checker');
99
- }
100
- }
101
-
102
- if ( empty($info->last_updated) ) {
103
- //Fetch the latest commit that changed the tag or branch and use it as the "last_updated" date.
104
- $latestCommitTime = $api->getLatestCommitTime($ref);
105
- if ( $latestCommitTime !== null ) {
106
- $info->last_updated = $latestCommitTime;
107
- }
108
- }
109
-
110
- $info = apply_filters($this->getUniqueName('request_info_result'), $info, null);
111
- return $info;
112
- }
113
-
114
- /**
115
- * Check if the currently installed version has a readme.txt file.
116
- *
117
- * @return bool
118
- */
119
- protected function readmeTxtExistsLocally() {
120
- $pluginDirectory = $this->getAbsoluteDirectoryPath();
121
- if ( empty($pluginDirectory) || !is_dir($pluginDirectory) || ($pluginDirectory === '.') ) {
122
- return false;
123
- }
124
- return is_file($pluginDirectory . '/' . $this->api->getLocalReadmeName());
125
- }
126
-
127
- /**
128
- * Copy plugin metadata from a file header to a Plugin Info object.
129
- *
130
- * @param array $fileHeader
131
- * @param Puc_v4p4_Plugin_Info $pluginInfo
132
- */
133
- protected function setInfoFromHeader($fileHeader, $pluginInfo) {
134
- $headerToPropertyMap = array(
135
- 'Version' => 'version',
136
- 'Name' => 'name',
137
- 'PluginURI' => 'homepage',
138
- 'Author' => 'author',
139
- 'AuthorName' => 'author',
140
- 'AuthorURI' => 'author_homepage',
141
-
142
- 'Requires WP' => 'requires',
143
- 'Tested WP' => 'tested',
144
- 'Requires at least' => 'requires',
145
- 'Tested up to' => 'tested',
146
- );
147
- foreach ($headerToPropertyMap as $headerName => $property) {
148
- if ( isset($fileHeader[$headerName]) && !empty($fileHeader[$headerName]) ) {
149
- $pluginInfo->$property = $fileHeader[$headerName];
150
- }
151
- }
152
-
153
- if ( !empty($fileHeader['Description']) ) {
154
- $pluginInfo->sections['description'] = $fileHeader['Description'];
155
- }
156
- }
157
-
158
- /**
159
- * Copy plugin metadata from the remote readme.txt file.
160
- *
161
- * @param string $ref GitHub tag or branch where to look for the readme.
162
- * @param Puc_v4p4_Plugin_Info $pluginInfo
163
- */
164
- protected function setInfoFromRemoteReadme($ref, $pluginInfo) {
165
- $readme = $this->api->getRemoteReadme($ref);
166
- if ( empty($readme) ) {
167
- return;
168
- }
169
-
170
- if ( isset($readme['sections']) ) {
171
- $pluginInfo->sections = array_merge($pluginInfo->sections, $readme['sections']);
172
- }
173
- if ( !empty($readme['tested_up_to']) ) {
174
- $pluginInfo->tested = $readme['tested_up_to'];
175
- }
176
- if ( !empty($readme['requires_at_least']) ) {
177
- $pluginInfo->requires = $readme['requires_at_least'];
178
- }
179
-
180
- if ( isset($readme['upgrade_notice'], $readme['upgrade_notice'][$pluginInfo->version]) ) {
181
- $pluginInfo->upgrade_notice = $readme['upgrade_notice'][$pluginInfo->version];
182
- }
183
- }
184
-
185
- public function setBranch($branch) {
186
- $this->branch = $branch;
187
- return $this;
188
- }
189
-
190
- public function setAuthentication($credentials) {
191
- $this->api->setAuthentication($credentials);
192
- return $this;
193
- }
194
-
195
- public function getVcsApi() {
196
- return $this->api;
197
- }
198
-
199
- public function getUpdate() {
200
- $update = parent::getUpdate();
201
-
202
- if ( isset($update) && !empty($update->download_url) ) {
203
- $update->download_url = $this->api->signDownloadUrl($update->download_url);
204
- }
205
-
206
- return $update;
207
- }
208
-
209
- public function onDisplayConfiguration($panel) {
210
- parent::onDisplayConfiguration($panel);
211
- $panel->row('Branch', $this->branch);
212
- $panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
213
- $panel->row('API client', get_class($this->api));
214
- }
215
- }
216
-
217
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Vcs/Reference.php DELETED
@@ -1,49 +0,0 @@
1
- <?php
2
- if ( !class_exists('Puc_v4p4_Vcs_Reference', false) ):
3
-
4
- /**
5
- * This class represents a VCS branch or tag. It's intended as a read only, short-lived container
6
- * that only exists to provide a limited degree of type checking.
7
- *
8
- * @property string $name
9
- * @property string|null version
10
- * @property string $downloadUrl
11
- * @property string $updated
12
- *
13
- * @property string|null $changelog
14
- * @property int|null $downloadCount
15
- */
16
- class Puc_v4p4_Vcs_Reference {
17
- private $properties = array();
18
-
19
- public function __construct($properties = array()) {
20
- $this->properties = $properties;
21
- }
22
-
23
- /**
24
- * @param string $name
25
- * @return mixed|null
26
- */
27
- public function __get($name) {
28
- return array_key_exists($name, $this->properties) ? $this->properties[$name] : null;
29
- }
30
-
31
- /**
32
- * @param string $name
33
- * @param mixed $value
34
- */
35
- public function __set($name, $value) {
36
- $this->properties[$name] = $value;
37
- }
38
-
39
- /**
40
- * @param string $name
41
- * @return bool
42
- */
43
- public function __isset($name) {
44
- return isset($this->properties[$name]);
45
- }
46
-
47
- }
48
-
49
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/Puc/v4p4/Vcs/ThemeUpdateChecker.php DELETED
@@ -1,118 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('Puc_v4p4_Vcs_ThemeUpdateChecker', false) ):
4
-
5
- class Puc_v4p4_Vcs_ThemeUpdateChecker extends Puc_v4p4_Theme_UpdateChecker implements Puc_v4p4_Vcs_BaseChecker {
6
- /**
7
- * @var string The branch where to look for updates. Defaults to "master".
8
- */
9
- protected $branch = 'master';
10
-
11
- /**
12
- * @var Puc_v4p4_Vcs_Api Repository API client.
13
- */
14
- protected $api = null;
15
-
16
- /**
17
- * Puc_v4p4_Vcs_ThemeUpdateChecker constructor.
18
- *
19
- * @param Puc_v4p4_Vcs_Api $api
20
- * @param null $stylesheet
21
- * @param null $customSlug
22
- * @param int $checkPeriod
23
- * @param string $optionName
24
- */
25
- public function __construct($api, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') {
26
- $this->api = $api;
27
- $this->api->setHttpFilterName($this->getUniqueName('request_update_options'));
28
-
29
- parent::__construct($api->getRepositoryUrl(), $stylesheet, $customSlug, $checkPeriod, $optionName);
30
-
31
- $this->api->setSlug($this->slug);
32
- }
33
-
34
- public function requestUpdate() {
35
- $api = $this->api;
36
- $api->setLocalDirectory($this->getAbsoluteDirectoryPath());
37
-
38
- $update = new Puc_v4p4_Theme_Update();
39
- $update->slug = $this->slug;
40
-
41
- //Figure out which reference (tag or branch) we'll use to get the latest version of the theme.
42
- $updateSource = $api->chooseReference($this->branch);
43
- if ( $updateSource ) {
44
- $ref = $updateSource->name;
45
- $update->download_url = $updateSource->downloadUrl;
46
- } else {
47
- do_action(
48
- 'puc_api_error',
49
- new WP_Error(
50
- 'puc-no-update-source',
51
- 'Could not retrieve version information from the repository. '
52
- . 'This usually means that the update checker either can\'t connect '
53
- . 'to the repository or it\'s configured incorrectly.'
54
- ),
55
- null, null, $this->slug
56
- );
57
- $ref = $this->branch;
58
- }
59
-
60
- //Get headers from the main stylesheet in this branch/tag. Its "Version" header and other metadata
61
- //are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags.
62
- $remoteHeader = $this->getFileHeader($api->getRemoteFile('style.css', $ref));
63
- $update->version = Puc_v4p4_Utils::findNotEmpty(array(
64
- $remoteHeader['Version'],
65
- Puc_v4p4_Utils::get($updateSource, 'version'),
66
- ));
67
-
68
- //The details URL defaults to the Theme URI header or the repository URL.
69
- $update->details_url = Puc_v4p4_Utils::findNotEmpty(array(
70
- $remoteHeader['ThemeURI'],
71
- $this->theme->get('ThemeURI'),
72
- $this->metadataUrl,
73
- ));
74
-
75
- if ( empty($update->version) ) {
76
- //It looks like we didn't find a valid update after all.
77
- $update = null;
78
- }
79
-
80
- $update = $this->filterUpdateResult($update);
81
- return $update;
82
- }
83
-
84
- //FIXME: This is duplicated code. Both theme and plugin subclasses that use VCS share these methods.
85
-
86
- public function setBranch($branch) {
87
- $this->branch = $branch;
88
- return $this;
89
- }
90
-
91
- public function setAuthentication($credentials) {
92
- $this->api->setAuthentication($credentials);
93
- return $this;
94
- }
95
-
96
- public function getVcsApi() {
97
- return $this->api;
98
- }
99
-
100
- public function getUpdate() {
101
- $update = parent::getUpdate();
102
-
103
- if ( isset($update) && !empty($update->download_url) ) {
104
- $update->download_url = $this->api->signDownloadUrl($update->download_url);
105
- }
106
-
107
- return $update;
108
- }
109
-
110
- public function onDisplayConfiguration($panel) {
111
- parent::onDisplayConfiguration($panel);
112
- $panel->row('Branch', $this->branch);
113
- $panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
114
- $panel->row('API client', get_class($this->api));
115
- }
116
- }
117
-
118
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/README.md DELETED
@@ -1,274 +0,0 @@
1
- Plugin Update Checker
2
- =====================
3
-
4
- This is a custom update checker library for WordPress plugins and themes. It lets you add automatic update notifications and one-click upgrades to your commercial plugins, private themes, and so on. All you need to do is put your plugin/theme details in a JSON file, place the file on your server, and pass the URL to the library. The library periodically checks the URL to see if there's a new version available and displays an update notification to the user if necessary.
5
-
6
- From the users' perspective, it works just like with plugins and themes hosted on WordPress.org. The update checker uses the default upgrade UI that is familiar to most WordPress users.
7
-
8
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
9
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
10
- **Table of Contents**
11
-
12
- - [Getting Started](#getting-started)
13
- - [Self-hosted Plugins and Themes](#self-hosted-plugins-and-themes)
14
- - [How to Release an Update](#how-to-release-an-update)
15
- - [Notes](#notes)
16
- - [GitHub Integration](#github-integration)
17
- - [How to Release an Update](#how-to-release-an-update-1)
18
- - [Notes](#notes-1)
19
- - [BitBucket Integration](#bitbucket-integration)
20
- - [How to Release an Update](#how-to-release-an-update-2)
21
- - [GitLab Integration](#gitlab-integration)
22
- - [How to Release an Update](#how-to-release-an-update-3)
23
- - [Resources](#resources)
24
-
25
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
26
-
27
- Getting Started
28
- ---------------
29
-
30
- ### Self-hosted Plugins and Themes
31
-
32
- 1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
33
- 2. Go to the `examples` subdirectory and open the .json file that fits your project type. Replace the placeholder data with your plugin/theme details.
34
- - Plugin example:
35
-
36
- ```json
37
- {
38
- "name" : "Plugin Name",
39
- "version" : "2.0",
40
- "download_url" : "http://example.com/plugin-name-2.0.zip",
41
- "sections" : {
42
- "description" : "Plugin description here. You can use HTML."
43
- }
44
- }
45
- ```
46
-
47
- This is a minimal example that leaves out optional fields. See [this table](https://docs.google.com/spreadsheets/d/1eOBbW7Go2qEQXReOOCdidMTf_tDYRq4JfegcO1CBPIs/edit?usp=sharing&authkey=CK7h9toK&output=html) for a full list of supported fields and their descriptions.
48
- - Theme example:
49
-
50
- ```json
51
- {
52
- "version": "2.0",
53
- "details_url": "http://example.com/version-2.0-details.html",
54
- "download_url": "http://example.com/example-theme-2.0.zip"
55
- }
56
- ```
57
-
58
- This is actually a complete example that shows all theme-related fields. `version` and `download_url` should be self-explanatory. The `details_url` key specifies the page that the user will see if they click the "View version 1.2.3 details" link in an update notification.
59
- 3. Upload the JSON file to a publicly accessible location.
60
- 4. Add the following code to the main plugin file or to the `functions.php` file:
61
-
62
- ```php
63
- require 'path/to/plugin-update-checker/plugin-update-checker.php';
64
- $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
65
- 'http://example.com/path/to/details.json',
66
- __FILE__, //Full path to the main plugin file or functions.php.
67
- 'unique-plugin-or-theme-slug'
68
- );
69
- ```
70
- Note: If you're using the Composer autoloader, you don't need to explicitly `require` the library.
71
-
72
- #### How to Release an Update
73
-
74
- Change the `version` number in the JSON file and make sure that `download_url` points to the latest version. Update the other fields if necessary. Tip: You can use [wp-update-server](https://github.com/YahnisElsts/wp-update-server) to automate this process.
75
-
76
- By default, the library will check the specified URL for changes every 12 hours. You can force it to check immediately by clicking the "Check for updates" link on the "Plugins" page (it's next to the "Visit plugin site" link). Themes don't have that link, but you can also trigger an update check like this:
77
-
78
- 1. Install [Debug Bar](https://srd.wordpress.org/plugins/debug-bar/).
79
- 2. Click the "Debug" menu in the Admin Bar (a.k.a Toolbar).
80
- 3. Open the "PUC (your-slug)" panel.
81
- 4. Click the "Check Now" button.
82
-
83
- #### Notes
84
- - The second argument passed to `buildUpdateChecker` must be the absolute path to the main plugin file or any file in the theme directory. If you followed the "getting started" instructions, you can just use the `__FILE__` constant.
85
- - The third argument - i.e. the slug - is optional but recommended. In most cases, the slug should be the same as the name of your plugin directory. For example, if your plugin lives in `/wp-content/plugins/my-plugin`, set the slug to `my-plugin`. If the slug is omitted, the update checker will use the name of the main plugin file as the slug (e.g. `my-cool-plugin.php` &rarr; `my-cool-plugin`). This can lead to conflicts if your plugin has a generic file name like `plugin.php`.
86
-
87
- This doesn't affect themes because PUC uses the theme directory name as the default slug. Still, if you're planning to use the slug in your own code - e.g. to filter updates or override update checker behaviour - it can be a good idea to set it explicitly.
88
-
89
- ### GitHub Integration
90
-
91
- 1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
92
- 2. Add the following code to the main plugin file or `functions.php`:
93
-
94
- ```php
95
- require 'plugin-update-checker/plugin-update-checker.php';
96
- $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
97
- 'https://github.com/user-name/repo-name/',
98
- __FILE__,
99
- 'unique-plugin-or-theme-slug'
100
- );
101
-
102
- //Optional: If you're using a private repository, specify the access token like this:
103
- $myUpdateChecker->setAuthentication('your-token-here');
104
-
105
- //Optional: Set the branch that contains the stable release.
106
- $myUpdateChecker->setBranch('stable-branch-name');
107
- ```
108
- 3. Plugins only: Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/about/readme.txt) to your repository. The contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.
109
-
110
- #### How to Release an Update
111
-
112
- This library supports a couple of different ways to release updates on GitHub. Pick the one that best fits your workflow.
113
-
114
- - **GitHub releases**
115
-
116
- Create a new release using the "Releases" feature on GitHub. The tag name and release title don't matter. The description is optional, but if you do provide one, it will be displayed when the user clicks the "View version x.y.z details" link on the "Plugins" page. Note that PUC ignores releases marked as "This is a pre-release".
117
-
118
- - **Tags**
119
-
120
- To release version 1.2.3, create a new Git tag named `v1.2.3` or `1.2.3`. That's it.
121
-
122
- PUC doesn't require strict adherence to [SemVer](http://semver.org/). These are all valid tag names: `v1.2.3`, `v1.2-foo`, `1.2.3_rc1-ABC`, `1.2.3.4.5`. However, be warned that it's not smart enough to filter out alpha/beta/RC versions. If that's a problem, you might want to use GitHub releases or branches instead.
123
-
124
- - **Stable branch**
125
-
126
- Point the update checker at a stable, production-ready branch:
127
- ```php
128
- $updateChecker->setBranch('branch-name');
129
- ```
130
- PUC will periodically check the `Version` header in the main plugin file or `style.css` and display a notification if it's greater than the installed version.
131
-
132
- Caveat: If you set the branch to `master` (the default), the update checker will look for recent releases and tags first. It'll only use the `master` branch if it doesn't find anything else suitable.
133
-
134
- #### Notes
135
-
136
- The library will pull update details from the following parts of a release/tag/branch:
137
-
138
- - Version number
139
- - The "Version" plugin header.
140
- - The latest GitHub release or tag name.
141
- - Changelog
142
- - The "Changelog" section of `readme.txt`.
143
- - One of the following files:
144
- CHANGES.md, CHANGELOG.md, changes.md, changelog.md
145
- - GitHub release notes.
146
- - Required and tested WordPress versions
147
- - The "Requires at least" and "Tested up to" fields in `readme.txt`.
148
- - The following plugin headers:
149
- `Required WP`, `Tested WP`, `Requires at least`, `Tested up to`
150
- - "Last updated" timestamp
151
- - The creation timestamp of the latest GitHub release.
152
- - The latest commit in the selected tag or branch.
153
- - Number of downloads
154
- - The `download_count` statistic of the latest release.
155
- - If you're not using GitHub releases, there will be no download stats.
156
- - Other plugin details - author, homepage URL, description
157
- - The "Description" section of `readme.txt`.
158
- - Remote plugin headers (i.e. the latest version on GitHub).
159
- - Local plugin headers (i.e. the currently installed version).
160
- - Ratings, banners, screenshots
161
- - Not supported.
162
-
163
- ### BitBucket Integration
164
-
165
- 1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
166
- 2. Add the following code to the main plugin file or `functions.php`:
167
-
168
- ```php
169
- require 'plugin-update-checker/plugin-update-checker.php';
170
- $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
171
- 'https://bitbucket.org/user-name/repo-name',
172
- __FILE__,
173
- 'unique-plugin-or-theme-slug'
174
- );
175
-
176
- //Optional: If you're using a private repository, create an OAuth consumer
177
- //and set the authentication credentials like this:
178
- //Note: For now you need to check "This is a private consumer" when
179
- //creating the consumer to work around #134:
180
- // https://github.com/YahnisElsts/plugin-update-checker/issues/134
181
- $myUpdateChecker->setAuthentication(array(
182
- 'consumer_key' => '...',
183
- 'consumer_secret' => '...',
184
- ));
185
-
186
- //Optional: Set the branch that contains the stable release.
187
- $myUpdateChecker->setBranch('stable-branch-name');
188
- ```
189
- 3. Optional: Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/about/readme.txt) to your repository. For plugins, the contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.
190
-
191
- #### How to Release an Update
192
-
193
- BitBucket doesn't have an equivalent to GitHub's releases, so the process is slightly different. You can use any of the following approaches:
194
-
195
- - **`Stable tag` header**
196
-
197
- This is the recommended approach if you're using tags to mark each version. Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/about/readme.txt) to your repository. Set the "stable tag" header to the tag that represents the latest release. Example:
198
- ```text
199
- Stable tag: v1.2.3
200
- ```
201
- The tag doesn't have to start with a "v" or follow any particular format. You can use any name you like as long as it's a valid Git tag.
202
-
203
- Tip: If you explicitly set a stable branch, the update checker will look for a `readme.txt` in that branch. Otherwise it will only look at the `master` branch.
204
-
205
- - **Tags**
206
-
207
- You can skip the "stable tag" bit and just create a new Git tag named `v1.2.3` or `1.2.3`. The update checker will look at the most recent tags and pick the one that looks like the highest version number.
208
-
209
- PUC doesn't require strict adherence to [SemVer](http://semver.org/). These are all valid tag names: `v1.2.3`, `v1.2-foo`, `1.2.3_rc1-ABC`, `1.2.3.4.5`. However, be warned that it's not smart enough to filter out alpha/beta/RC versions.
210
-
211
- - **Stable branch**
212
-
213
- Point the update checker at a stable, production-ready branch:
214
- ```php
215
- $updateChecker->setBranch('branch-name');
216
- ```
217
- PUC will periodically check the `Version` header in the main plugin file or `style.css` and display a notification if it's greater than the installed version. Caveat: If you set the branch to `master`, the update checker will still look for tags first.
218
-
219
- ### GitLab Integration
220
-
221
- 1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
222
- 2. Add the following code to the main plugin file or `functions.php`:
223
-
224
- ```php
225
- require 'plugin-update-checker/plugin-update-checker.php';
226
- $myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
227
- 'https://gitlab.com/user-name/repo-name/',
228
- __FILE__,
229
- 'unique-plugin-or-theme-slug'
230
- );
231
-
232
- //Note: Self-hosted instances of GitLab must be initialized like this:
233
- $myUpdateChecker = new Puc_v4p4_Vcs_PluginUpdateChecker(
234
- new Puc_v4p4_Vcs_GitLabApi('https://myserver.com/user-name/repo-name/'),
235
- __FILE__,
236
- 'unique-plugin-or-theme-slug'
237
- );
238
-
239
- //Optional: If you're using a private repository, specify the access token like this:
240
- $myUpdateChecker->setAuthentication('your-token-here');
241
-
242
- //Optional: Set the branch that contains the stable release.
243
- $myUpdateChecker->setBranch('stable-branch-name');
244
- ```
245
- 3. Plugins only: Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/about/readme.txt) to your repository. The contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.
246
-
247
- #### How to Release an Update
248
-
249
- GitLab doesn't have an equivalent to GitHub's releases, so the process is slightly different. You can use any of the following approaches:
250
-
251
- - **Tags**
252
-
253
- To release version 1.2.3, create a new Git tag named `v1.2.3` or `1.2.3`. That's it.
254
-
255
- PUC doesn't require strict adherence to [SemVer](http://semver.org/). These are all valid tag names: `v1.2.3`, `v1.2-foo`, `1.2.3_rc1-ABC`, `1.2.3.4.5`. However, be warned that it's not smart enough to filter out alpha/beta/RC versions. If that's a problem, you might want to use GitLab branches instead.
256
-
257
- - **Stable branch**
258
-
259
- Point the update checker at a stable, production-ready branch:
260
- ```php
261
- $updateChecker->setBranch('branch-name');
262
- ```
263
- PUC will periodically check the `Version` header in the main plugin file or `style.css` and display a notification if it's greater than the installed version.
264
-
265
- Caveat: If you set the branch to `master` (the default), the update checker will look for recent releases and tags first. It'll only use the `master` branch if it doesn't find anything else suitable.
266
-
267
- Resources
268
- ---------
269
-
270
- - [This blog post](http://w-shadow.com/blog/2010/09/02/automatic-updates-for-any-plugin/) has more information about the update checker API. *Slightly out of date.*
271
- - [Debug Bar](https://wordpress.org/plugins/debug-bar/) - useful for testing and debugging the update checker.
272
- - [Securing download links](http://w-shadow.com/blog/2013/03/19/plugin-updates-securing-download-links/) - a general overview.
273
- - [A GUI for entering download credentials](http://open-tools.net/documentation/tutorial-automatic-updates.html#wordpress)
274
- - [Theme Update Checker](http://w-shadow.com/blog/2011/06/02/automatic-updates-for-commercial-themes/) - an older, theme-only variant of this update checker.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/composer.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "name": "yahnis-elsts/plugin-update-checker",
3
- "type": "library",
4
- "description": "A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.",
5
- "keywords": ["wordpress", "plugin updates", "automatic updates", "theme updates"],
6
- "homepage": "https://github.com/YahnisElsts/plugin-update-checker/",
7
- "license": "MIT",
8
- "authors": [
9
- {
10
- "name": "Yahnis Elsts",
11
- "email": "whiteshadow@w-shadow.com",
12
- "homepage": "http://w-shadow.com/",
13
- "role": "Developer"
14
- }
15
- ],
16
- "require": {
17
- "php": ">=5.2.0"
18
- },
19
- "autoload": {
20
- "files": ["plugin-update-checker.php"]
21
- }
22
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/css/puc-debug-bar.css DELETED
@@ -1,70 +0,0 @@
1
- .puc-debug-bar-panel-v4 pre {
2
- margin-top: 0;
3
- }
4
-
5
- /* Style the debug data table to match "widefat" table style used by WordPress. */
6
- table.puc-debug-data {
7
- width: 100%;
8
- clear: both;
9
- margin: 0;
10
-
11
- border-spacing: 0;
12
- background-color: #f9f9f9;
13
-
14
- border-radius: 3px;
15
- border: 1px solid #dfdfdf;
16
- border-collapse: separate;
17
- }
18
-
19
- table.puc-debug-data * {
20
- word-wrap: break-word;
21
- }
22
-
23
- table.puc-debug-data th {
24
- width: 11em;
25
- padding: 7px 7px 8px;
26
- text-align: left;
27
-
28
- font-family: "Georgia", "Times New Roman", "Bitstream Charter", "Times", serif;
29
- font-weight: 400;
30
- font-size: 14px;
31
- line-height: 1.3em;
32
- text-shadow: rgba(255, 255, 255, 0.804) 0 1px 0;
33
- }
34
-
35
- table.puc-debug-data td, table.puc-debug-data th {
36
- border-width: 1px 0;
37
- border-style: solid;
38
-
39
- border-top-color: #fff;
40
- border-bottom-color: #dfdfdf;
41
-
42
- text-transform: none;
43
- }
44
-
45
- table.puc-debug-data td {
46
- color: #555;
47
- font-size: 12px;
48
- padding: 4px 7px 2px;
49
- vertical-align: top;
50
- }
51
-
52
- .puc-ajax-response {
53
- border: 1px solid #dfdfdf;
54
- border-radius: 3px;
55
- padding: 0.5em;
56
- margin: 5px 0;
57
- background-color: white;
58
- }
59
-
60
- .puc-ajax-nonce {
61
- display: none;
62
- }
63
-
64
- .puc-ajax-response dt {
65
- margin: 0;
66
- }
67
-
68
- .puc-ajax-response dd {
69
- margin: 0 0 1em;
70
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/examples/plugin.json DELETED
@@ -1,52 +0,0 @@
1
- {
2
- "name": "My Example Plugin",
3
- "version": "2.0",
4
- "download_url": "http://example.com/updates/example-plugin.zip",
5
-
6
- "homepage": "http://example.com/",
7
- "requires": "4.5",
8
- "tested": "4.8",
9
- "last_updated": "2017-01-01 16:17:00",
10
- "upgrade_notice": "Here's why you should upgrade...",
11
-
12
- "author": "Janis Elsts",
13
- "author_homepage": "http://example.com/",
14
-
15
- "sections": {
16
- "description": "(Required) Plugin description. Basic HTML can be used in all sections.",
17
- "installation": "(Recommended) Installation instructions.",
18
- "changelog": "(Recommended) Changelog. <p>This section will be displayed by default when the user clicks 'View version x.y.z details'.</p>",
19
- "custom_section": "This is a custom section labeled 'Custom Section'."
20
- },
21
-
22
- "icons" : {
23
- "1x" : "http://w-shadow.com/files/external-update-example/assets/icon-128x128.png",
24
- "2x" : "http://w-shadow.com/files/external-update-example/assets/icon-256x256.png"
25
- },
26
-
27
- "banners": {
28
- "low": "http://w-shadow.com/files/external-update-example/assets/banner-772x250.png",
29
- "high": "http://w-shadow.com/files/external-update-example/assets/banner-1544x500.png"
30
- },
31
-
32
- "translations": [
33
- {
34
- "language": "fr_FR",
35
- "version": "4.0",
36
- "updated": "2016-04-22 23:22:42",
37
- "package": "http://example.com/updates/translations/french-language-pack.zip"
38
- },
39
- {
40
- "language": "de_DE",
41
- "version": "5.0",
42
- "updated": "2016-04-22 23:22:42",
43
- "package": "http://example.com/updates/translations/german-language-pack.zip"
44
- }
45
- ],
46
-
47
- "rating": 90,
48
- "num_ratings": 123,
49
-
50
- "downloaded": 1234,
51
- "active_installs": 12345
52
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/examples/theme.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "version": "2.0",
3
- "details_url": "http://example.com/version-2.0-details.html",
4
- "download_url": "http://example.com/example-theme-2.0.zip"
5
- }
 
 
 
 
 
plugin-update-checker/js/debug-bar.js DELETED
@@ -1,52 +0,0 @@
1
- jQuery(function($) {
2
-
3
- function runAjaxAction(button, action) {
4
- button = $(button);
5
- var panel = button.closest('.puc-debug-bar-panel-v4');
6
- var responseBox = button.closest('td').find('.puc-ajax-response');
7
-
8
- responseBox.text('Processing...').show();
9
- $.post(
10
- ajaxurl,
11
- {
12
- action : action,
13
- uid : panel.data('uid'),
14
- _wpnonce: panel.data('nonce')
15
- },
16
- function(data) {
17
- responseBox.html(data);
18
- },
19
- 'html'
20
- );
21
- }
22
-
23
- $('.puc-debug-bar-panel-v4 input[name="puc-check-now-button"]').click(function() {
24
- runAjaxAction(this, 'puc_v4_debug_check_now');
25
- return false;
26
- });
27
-
28
- $('.puc-debug-bar-panel-v4 input[name="puc-request-info-button"]').click(function() {
29
- runAjaxAction(this, 'puc_v4_debug_request_info');
30
- return false;
31
- });
32
-
33
-
34
- // Debug Bar uses the panel class name as part of its link and container IDs. This means we can
35
- // end up with multiple identical IDs if more than one plugin uses the update checker library.
36
- // Fix it by replacing the class name with the plugin slug.
37
- var panels = $('#debug-menu-targets').find('.puc-debug-bar-panel-v4');
38
- panels.each(function() {
39
- var panel = $(this);
40
- var uid = panel.data('uid');
41
- var target = panel.closest('.debug-menu-target');
42
-
43
- //Change the panel wrapper ID.
44
- target.attr('id', 'debug-menu-target-puc-' + uid);
45
-
46
- //Change the menu link ID as well and point it at the new target ID.
47
- $('#debug-bar-menu').find('.puc-debug-menu-link-' + uid)
48
- .closest('.debug-menu-link')
49
- .attr('id', 'debug-menu-link-puc-' + uid)
50
- .attr('href', '#' + target.attr('id'));
51
- });
52
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-cs_CZ.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-cs_CZ.po DELETED
@@ -1,45 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2017-05-20 10:53+0300\n"
6
- "PO-Revision-Date: 2017-07-05 15:39+0000\n"
7
- "Last-Translator: Vojtěch Sajdl <vojtech@sajdl.com>\n"
8
- "Language-Team: Czech (Czech Republic)\n"
9
- "Language: cs-CZ\n"
10
- "Plural-Forms: nplurals=2; plural=(n != 1)\n"
11
- "MIME-Version: 1.0\n"
12
- "Content-Type: text/plain; charset=UTF-8\n"
13
- "Content-Transfer-Encoding: 8bit\n"
14
- "X-Loco-Source-Locale: cs_CZ\n"
15
- "X-Generator: Loco - https://localise.biz/\n"
16
- "X-Poedit-Basepath: ..\n"
17
- "X-Poedit-SourceCharset: UTF-8\n"
18
- "X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
19
- "X-Poedit-SearchPath-0: .\n"
20
- "X-Loco-Parser: loco_parse_po"
21
-
22
- #: Puc/v4p1/Plugin/UpdateChecker.php:358
23
- msgid "Check for updates"
24
- msgstr "Zkontrolovat aktualizace"
25
-
26
- #: Puc/v4p1/Plugin/UpdateChecker.php:405
27
- #, php-format
28
- msgctxt "the plugin title"
29
- msgid "The %s plugin is up to date."
30
- msgstr "Plugin %s je aktuální."
31
-
32
- #: Puc/v4p1/Plugin/UpdateChecker.php:407
33
- #, php-format
34
- msgctxt "the plugin title"
35
- msgid "A new version of the %s plugin is available."
36
- msgstr "Nová verze pluginu %s je dostupná."
37
-
38
- #: Puc/v4p1/Plugin/UpdateChecker.php:409
39
- #, php-format
40
- msgid "Unknown update checker status \"%s\""
41
- msgstr "Neznámý status kontroly aktualizací \"%s\""
42
-
43
- #: Puc/v4p1/Vcs/PluginUpdateChecker.php:83
44
- msgid "There is no changelog available."
45
- msgstr "Changelog není dostupný."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-da_DK.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-da_DK.po DELETED
@@ -1,42 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "POT-Creation-Date: 2017-05-20 10:53+0300\n"
5
- "PO-Revision-Date: 2017-10-17 11:07+0200\n"
6
- "Last-Translator: Mikk3lRo\n"
7
- "Language-Team: Mikk3lRo\n"
8
- "MIME-Version: 1.0\n"
9
- "Content-Type: text/plain; charset=UTF-8\n"
10
- "Content-Transfer-Encoding: 8bit\n"
11
- "X-Generator: Poedit 2.0.4\n"
12
- "X-Poedit-Basepath: ..\n"
13
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
14
- "X-Poedit-SourceCharset: UTF-8\n"
15
- "X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
16
- "Language: da_DK\n"
17
- "X-Poedit-SearchPath-0: .\n"
18
-
19
- #: Puc/v4p1/Plugin/UpdateChecker.php:358
20
- msgid "Check for updates"
21
- msgstr "Undersøg for opdateringer"
22
-
23
- #: Puc/v4p1/Plugin/UpdateChecker.php:405
24
- #, php-format
25
- msgctxt "the plugin title"
26
- msgid "The %s plugin is up to date."
27
- msgstr "Plugin'et %s er allerede opdateret."
28
-
29
- #: Puc/v4p1/Plugin/UpdateChecker.php:407
30
- #, php-format
31
- msgctxt "the plugin title"
32
- msgid "A new version of the %s plugin is available."
33
- msgstr "En ny version af plugin'et %s er tilgængelig."
34
-
35
- #: Puc/v4p1/Plugin/UpdateChecker.php:409
36
- #, php-format
37
- msgid "Unknown update checker status \"%s\""
38
- msgstr "Ukendt opdateringsstatus: \"%s\""
39
-
40
- #: Puc/v4p1/Vcs/PluginUpdateChecker.php:83
41
- msgid "There is no changelog available."
42
- msgstr "Der er ingen ændringslog tilgængelig."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-de_DE.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-de_DE.po DELETED
@@ -1,38 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "POT-Creation-Date: 2016-06-29 20:21+0100\n"
5
- "PO-Revision-Date: 2016-06-29 20:23+0100\n"
6
- "Last-Translator: Igor Lückel <info@igorlueckel.de>\n"
7
- "Language-Team: \n"
8
- "MIME-Version: 1.0\n"
9
- "Content-Type: text/plain; charset=UTF-8\n"
10
- "Content-Transfer-Encoding: 8bit\n"
11
- "X-Generator: Poedit 1.8.1\n"
12
- "X-Poedit-Basepath: ..\n"
13
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
14
- "X-Poedit-SourceCharset: UTF-8\n"
15
- "X-Poedit-KeywordsList: __;_e\n"
16
- "Language: de_DE\n"
17
- "X-Poedit-SearchPath-0: .\n"
18
-
19
- #: github-checker.php:137
20
- msgid "There is no changelog available."
21
- msgstr "Es ist keine Liste von Programmänderungen verfügbar."
22
-
23
- #: plugin-update-checker.php:852
24
- msgid "Check for updates"
25
- msgstr "Nach Update suchen"
26
-
27
- #: plugin-update-checker.php:896
28
- msgid "This plugin is up to date."
29
- msgstr "Das Plugin ist aktuell."
30
-
31
- #: plugin-update-checker.php:898
32
- msgid "A new version of this plugin is available."
33
- msgstr "Es ist eine neue Version für das Plugin verfügbar."
34
-
35
- #: plugin-update-checker.php:900
36
- #, php-format
37
- msgid "Unknown update checker status \"%s\""
38
- msgstr "Unbekannter Update Status \"%s\""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-fa_IR.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-fa_IR.po DELETED
@@ -1,38 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "POT-Creation-Date: 2016-02-17 14:21+0100\n"
5
- "PO-Revision-Date: 2016-10-28 14:30+0330\n"
6
- "Last-Translator: studio RVOLA <hello@rvola.com>\n"
7
- "Language-Team: Pro Style <info@prostyle.ir>\n"
8
- "Language: fa_IR\n"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=UTF-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "X-Generator: Poedit 1.8.8\n"
13
- "X-Poedit-Basepath: ..\n"
14
- "Plural-Forms: nplurals=2; plural=(n > 1);\n"
15
- "X-Poedit-SourceCharset: UTF-8\n"
16
- "X-Poedit-KeywordsList: __;_e\n"
17
- "X-Poedit-SearchPath-0: .\n"
18
-
19
- #: github-checker.php:120
20
- msgid "There is no changelog available."
21
- msgstr "شرحی برای تغییرات یافت نشد"
22
-
23
- #: plugin-update-checker.php:637
24
- msgid "Check for updates"
25
- msgstr "بررسی برای بروزرسانی "
26
-
27
- #: plugin-update-checker.php:681
28
- msgid "This plugin is up to date."
29
- msgstr "شما از آخرین نسخه استفاده میکنید . به‌روز باشید"
30
-
31
- #: plugin-update-checker.php:683
32
- msgid "A new version of this plugin is available."
33
- msgstr "نسخه جدیدی برای افزونه ارائه شده است ."
34
-
35
- #: plugin-update-checker.php:685
36
- #, php-format
37
- msgid "Unknown update checker status \"%s\""
38
- msgstr "وضعیت ناشناخته برای بروزرسانی \"%s\""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-fr_CA.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-fr_CA.po DELETED
@@ -1,48 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "POT-Creation-Date: 2017-11-24 17:02+0200\n"
5
- "PO-Revision-Date: 2018-02-12 10:32-0500\n"
6
- "Language-Team: \n"
7
- "MIME-Version: 1.0\n"
8
- "Content-Type: text/plain; charset=UTF-8\n"
9
- "Content-Transfer-Encoding: 8bit\n"
10
- "X-Generator: Poedit 2.0.4\n"
11
- "X-Poedit-Basepath: ..\n"
12
- "Plural-Forms: nplurals=2; plural=(n > 1);\n"
13
- "X-Poedit-SourceCharset: UTF-8\n"
14
- "X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
15
- "Last-Translator: Eric Gagnon <eric.gagnon@banq.qc.ca>\n"
16
- "Language: fr_CA\n"
17
- "X-Poedit-SearchPath-0: .\n"
18
-
19
- #: Puc/v4p3/Plugin/UpdateChecker.php:395
20
- msgid "Check for updates"
21
- msgstr "Vérifier les mises à jour"
22
-
23
- #: Puc/v4p3/Plugin/UpdateChecker.php:548
24
- #, php-format
25
- msgctxt "the plugin title"
26
- msgid "The %s plugin is up to date."
27
- msgstr "L’extension %s est à jour."
28
-
29
- #: Puc/v4p3/Plugin/UpdateChecker.php:550
30
- #, php-format
31
- msgctxt "the plugin title"
32
- msgid "A new version of the %s plugin is available."
33
- msgstr "Une nouvelle version de l’extension %s est disponible."
34
-
35
- #: Puc/v4p3/Plugin/UpdateChecker.php:552
36
- #, php-format
37
- msgctxt "the plugin title"
38
- msgid "Could not determine if updates are available for %s."
39
- msgstr "Impossible de déterminer si une mise à jour est disponible pour \"%s\""
40
-
41
- #: Puc/v4p3/Plugin/UpdateChecker.php:558
42
- #, php-format
43
- msgid "Unknown update checker status \"%s\""
44
- msgstr "Un problème inconnu est survenu \"%s\""
45
-
46
- #: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
47
- msgid "There is no changelog available."
48
- msgstr "Il n’y a aucun journal de mise à jour disponible."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-fr_FR.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-fr_FR.po DELETED
@@ -1,42 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "POT-Creation-Date: 2017-07-07 14:53+0200\n"
5
- "PO-Revision-Date: 2017-07-07 14:54+0200\n"
6
- "Language-Team: studio RVOLA <http://www.rvola.com>\n"
7
- "Language: fr_FR\n"
8
- "MIME-Version: 1.0\n"
9
- "Content-Type: text/plain; charset=UTF-8\n"
10
- "Content-Transfer-Encoding: 8bit\n"
11
- "X-Generator: Poedit 2.0.2\n"
12
- "X-Poedit-Basepath: ..\n"
13
- "Plural-Forms: nplurals=2; plural=(n > 1);\n"
14
- "X-Poedit-SourceCharset: UTF-8\n"
15
- "X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
16
- "Last-Translator: Nicolas GEHIN\n"
17
- "X-Poedit-SearchPath-0: .\n"
18
-
19
- #: Puc/v4p1/Plugin/UpdateChecker.php:358
20
- msgid "Check for updates"
21
- msgstr "Vérifier les mises à jour"
22
-
23
- #: Puc/v4p1/Plugin/UpdateChecker.php:405
24
- #, php-format
25
- msgctxt "the plugin title"
26
- msgid "The %s plugin is up to date."
27
- msgstr "L’extension %s est à jour."
28
-
29
- #: Puc/v4p1/Plugin/UpdateChecker.php:407
30
- #, php-format
31
- msgctxt "the plugin title"
32
- msgid "A new version of the %s plugin is available."
33
- msgstr "Une nouvelle version de l’extension %s est disponible."
34
-
35
- #: Puc/v4p1/Plugin/UpdateChecker.php:409
36
- #, php-format
37
- msgid "Unknown update checker status \"%s\""
38
- msgstr "Un problème inconnu est survenu \"%s\""
39
-
40
- #: Puc/v4p1/Vcs/PluginUpdateChecker.php:85
41
- msgid "There is no changelog available."
42
- msgstr "Il n’y a aucun journal de mise à jour disponible."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-hu_HU.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-hu_HU.po DELETED
@@ -1,41 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "POT-Creation-Date: 2016-01-11 21:23+0100\n"
5
- "PO-Revision-Date: 2016-01-11 21:25+0100\n"
6
- "Last-Translator: Tamás András Horváth <htomy92@gmail.com>\n"
7
- "Language-Team: \n"
8
- "Language: hu_HU\n"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=UTF-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "X-Generator: Poedit 1.8.6\n"
13
- "X-Poedit-Basepath: ..\n"
14
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
- "X-Poedit-SourceCharset: UTF-8\n"
16
- "X-Poedit-KeywordsList: __;_e\n"
17
- "X-Poedit-SearchPath-0: .\n"
18
-
19
- #: github-checker.php:137
20
- msgid "There is no changelog available."
21
- msgstr "Nem érhető el a changelog."
22
-
23
- #: plugin-update-checker.php:852
24
- msgid "Check for updates"
25
- msgstr "Frissítés ellenőrzése"
26
-
27
- #: plugin-update-checker.php:896
28
- msgid "This plugin is up to date."
29
- msgstr "Ez a plugin naprakész."
30
-
31
- #: plugin-update-checker.php:898
32
- msgid "A new version of this plugin is available."
33
- msgstr "Új verzió érhető el a kiegészítőhöz"
34
-
35
- #: plugin-update-checker.php:900
36
- #, php-format
37
- msgid "Unknown update checker status \"%s\""
38
- msgstr "Ismeretlen a frissítés ellenőrző státusza \"%s\""
39
-
40
- #~ msgid "Every %d hours"
41
- #~ msgstr "Minden %d órában"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-it_IT.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-it_IT.po DELETED
@@ -1,38 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "POT-Creation-Date: 2016-06-29 20:21+0100\n"
5
- "PO-Revision-Date: 2017-01-15 12:24+0100\n"
6
- "Last-Translator: Igor Lückel <info@igorlueckel.de>\n"
7
- "Language-Team: \n"
8
- "MIME-Version: 1.0\n"
9
- "Content-Type: text/plain; charset=UTF-8\n"
10
- "Content-Transfer-Encoding: 8bit\n"
11
- "X-Generator: Poedit 1.5.5\n"
12
- "X-Poedit-Basepath: ..\n"
13
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
14
- "X-Poedit-SourceCharset: UTF-8\n"
15
- "X-Poedit-KeywordsList: __;_e\n"
16
- "Language: de_DE\n"
17
- "X-Poedit-SearchPath-0: .\n"
18
-
19
- #: github-checker.php:137
20
- msgid "There is no changelog available."
21
- msgstr "Non c'è alcuna sezione di aggiornamento disponibile"
22
-
23
- #: plugin-update-checker.php:852
24
- msgid "Check for updates"
25
- msgstr "Verifica aggiornamenti"
26
-
27
- #: plugin-update-checker.php:896
28
- msgid "This plugin is up to date."
29
- msgstr "Il plugin è aggiornato"
30
-
31
- #: plugin-update-checker.php:898
32
- msgid "A new version of this plugin is available."
33
- msgstr "Una nuova versione del plugin è disponibile"
34
-
35
- #: plugin-update-checker.php:900
36
- #, php-format
37
- msgid "Unknown update checker status \"%s\""
38
- msgstr "Si è verificato un problema sconosciuto \"%s\""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-ja.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-ja.po DELETED
@@ -1,42 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "POT-Creation-Date: 2017-06-02 18:31+0900\n"
5
- "PO-Revision-Date: 2017-06-02 18:32+0900\n"
6
- "Last-Translator: tak <tak7725@gmail.com>\n"
7
- "Language-Team: \n"
8
- "Language: ja_JP\n"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=UTF-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "X-Generator: Poedit 2.0.2\n"
13
- "X-Poedit-Basepath: ..\n"
14
- "Plural-Forms: nplurals=1; plural=0;\n"
15
- "X-Poedit-SourceCharset: UTF-8\n"
16
- "X-Poedit-KeywordsList: __;_e;_x;_x:1,2c\n"
17
- "X-Poedit-SearchPath-0: .\n"
18
-
19
- #: Puc/v4p1/Plugin/UpdateChecker.php:362
20
- msgid "Check for updates"
21
- msgstr "アップデートを確認"
22
-
23
- #: Puc/v4p1/Plugin/UpdateChecker.php:409
24
- #, php-format
25
- msgctxt "the plugin title"
26
- msgid "The %s plugin is up to date."
27
- msgstr "%s プラグインは、最新バージョンです。"
28
-
29
- #: Puc/v4p1/Plugin/UpdateChecker.php:411
30
- #, php-format
31
- msgctxt "the plugin title"
32
- msgid "A new version of the %s plugin is available."
33
- msgstr "%s プラグインの最新バージョンがあります。"
34
-
35
- #: Puc/v4p1/Plugin/UpdateChecker.php:413
36
- #, php-format
37
- msgid "Unknown update checker status \"%s\""
38
- msgstr "バージョンアップの確認で想定外の状態になりました。ステータス:\"%s\""
39
-
40
- #: Puc/v4p1/Vcs/PluginUpdateChecker.php:83
41
- msgid "There is no changelog available."
42
- msgstr "更新履歴はありません。"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-nl_BE.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-nl_BE.po DELETED
@@ -1,48 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "POT-Creation-Date: 2018-03-25 18:15+0200\n"
5
- "PO-Revision-Date: 2018-03-25 18:32+0200\n"
6
- "Language-Team: \n"
7
- "MIME-Version: 1.0\n"
8
- "Content-Type: text/plain; charset=UTF-8\n"
9
- "Content-Transfer-Encoding: 8bit\n"
10
- "X-Generator: Poedit 1.8.7.1\n"
11
- "X-Poedit-Basepath: ..\n"
12
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
13
- "X-Poedit-SourceCharset: UTF-8\n"
14
- "X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
15
- "Last-Translator: Frank Goossens <frank@optimizingmatters.com>\n"
16
- "Language: nl_BE\n"
17
- "X-Poedit-SearchPath-0: .\n"
18
-
19
- #: Puc/v4p3/Plugin/UpdateChecker.php:395
20
- msgid "Check for updates"
21
- msgstr "Controleer op nieuwe versies"
22
-
23
- #: Puc/v4p3/Plugin/UpdateChecker.php:548
24
- #, php-format
25
- msgctxt "the plugin title"
26
- msgid "The %s plugin is up to date."
27
- msgstr "De meest recente %s versie is geïnstalleerd."
28
-
29
- #: Puc/v4p3/Plugin/UpdateChecker.php:550
30
- #, php-format
31
- msgctxt "the plugin title"
32
- msgid "A new version of the %s plugin is available."
33
- msgstr "Er is een nieuwe versie van %s beschikbaar."
34
-
35
- #: Puc/v4p3/Plugin/UpdateChecker.php:552
36
- #, php-format
37
- msgctxt "the plugin title"
38
- msgid "Could not determine if updates are available for %s."
39
- msgstr "Kon niet bepalen of er nieuwe versie van %s beschikbaar is."
40
-
41
- #: Puc/v4p3/Plugin/UpdateChecker.php:558
42
- #, php-format
43
- msgid "Unknown update checker status \"%s\""
44
- msgstr "Ongekende status bij controle op nieuwe versie: \"%s\""
45
-
46
- #: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
47
- msgid "There is no changelog available."
48
- msgstr "Er is geen changelog beschikbaar."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-nl_NL.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-nl_NL.po DELETED
@@ -1,48 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "POT-Creation-Date: 2018-03-25 18:15+0200\n"
5
- "PO-Revision-Date: 2018-03-25 18:32+0200\n"
6
- "Language-Team: \n"
7
- "MIME-Version: 1.0\n"
8
- "Content-Type: text/plain; charset=UTF-8\n"
9
- "Content-Transfer-Encoding: 8bit\n"
10
- "X-Generator: Poedit 1.8.7.1\n"
11
- "X-Poedit-Basepath: ..\n"
12
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
13
- "X-Poedit-SourceCharset: UTF-8\n"
14
- "X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
15
- "Last-Translator: Frank Goossens <frank@optimizingmatters.com>\n"
16
- "Language: nl_NL\n"
17
- "X-Poedit-SearchPath-0: .\n"
18
-
19
- #: Puc/v4p3/Plugin/UpdateChecker.php:395
20
- msgid "Check for updates"
21
- msgstr "Controleer op nieuwe versies"
22
-
23
- #: Puc/v4p3/Plugin/UpdateChecker.php:548
24
- #, php-format
25
- msgctxt "the plugin title"
26
- msgid "The %s plugin is up to date."
27
- msgstr "De meest recente %s versie is geïnstalleerd."
28
-
29
- #: Puc/v4p3/Plugin/UpdateChecker.php:550
30
- #, php-format
31
- msgctxt "the plugin title"
32
- msgid "A new version of the %s plugin is available."
33
- msgstr "Er is een nieuwe versie van %s beschikbaar."
34
-
35
- #: Puc/v4p3/Plugin/UpdateChecker.php:552
36
- #, php-format
37
- msgctxt "the plugin title"
38
- msgid "Could not determine if updates are available for %s."
39
- msgstr "Kon niet bepalen of er nieuwe versie van %s beschikbaar is."
40
-
41
- #: Puc/v4p3/Plugin/UpdateChecker.php:558
42
- #, php-format
43
- msgid "Unknown update checker status \"%s\""
44
- msgstr "Ongekende status bij controle op nieuwe versie: \"%s\""
45
-
46
- #: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
47
- msgid "There is no changelog available."
48
- msgstr "Er is geen changelog beschikbaar."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-pt_BR.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-pt_BR.po DELETED
@@ -1,48 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "POT-Creation-Date: 2017-05-19 15:41-0300\n"
5
- "PO-Revision-Date: 2017-05-19 15:42-0300\n"
6
- "Last-Translator: \n"
7
- "Language-Team: \n"
8
- "Language: pt_BR\n"
9
- "MIME-Version: 1.0\n"
10
- "Content-Type: text/plain; charset=UTF-8\n"
11
- "Content-Transfer-Encoding: 8bit\n"
12
- "X-Generator: Poedit 1.8.8\n"
13
- "X-Poedit-Basepath: ..\n"
14
- "Plural-Forms: nplurals=2; plural=(n > 1);\n"
15
- "X-Poedit-SourceCharset: UTF-8\n"
16
- "X-Poedit-KeywordsList: __;_e;_x;_x:1,2c\n"
17
- "X-Poedit-SearchPath-0: .\n"
18
-
19
- #: Puc/v4p1/Plugin/UpdateChecker.php:358
20
- msgid "Check for updates"
21
- msgstr "Verificar Atualizações"
22
-
23
- #: Puc/v4p1/Plugin/UpdateChecker.php:401 Puc/v4p1/Plugin/UpdateChecker.php:406
24
- #, php-format
25
- msgctxt "the plugin title"
26
- msgid "The %s plugin is up to date."
27
- msgstr "O plugin %s já está na sua versão mais recente."
28
-
29
- #: Puc/v4p1/Plugin/UpdateChecker.php:408
30
- #, php-format
31
- msgctxt "the plugin title"
32
- msgid "A new version of the %s plugin is available."
33
- msgstr "Há uma nova versão para o plugin %s disponível para download."
34
-
35
- #: Puc/v4p1/Plugin/UpdateChecker.php:410
36
- #, php-format
37
- msgid "Unknown update checker status \"%s\""
38
- msgstr "Status \"%s\" desconhecido."
39
-
40
- #: Puc/v4p1/Vcs/PluginUpdateChecker.php:83
41
- msgid "There is no changelog available."
42
- msgstr "Não há um changelog disponível."
43
-
44
- #~ msgid "The %s plugin is up to date."
45
- #~ msgstr "O plugin %s já está na sua versão mais recente."
46
-
47
- #~ msgid "A new version of the %s plugin is available."
48
- #~ msgstr "Há uma nova versão para o plugin %s disponível para download."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker-sv_SE.mo DELETED
Binary file
plugin-update-checker/languages/plugin-update-checker-sv_SE.po DELETED
@@ -1,42 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Project-Id-Version: plugin-update-checker\n"
4
- "POT-Creation-Date: 2017-05-20 10:53+0300\n"
5
- "PO-Revision-Date: 2017-10-16 15:02+0200\n"
6
- "Language-Team: \n"
7
- "MIME-Version: 1.0\n"
8
- "Content-Type: text/plain; charset=UTF-8\n"
9
- "Content-Transfer-Encoding: 8bit\n"
10
- "X-Generator: Poedit 2.0.4\n"
11
- "X-Poedit-Basepath: ..\n"
12
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
13
- "X-Poedit-SourceCharset: UTF-8\n"
14
- "X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
15
- "Last-Translator: \n"
16
- "Language: sv_SE\n"
17
- "X-Poedit-SearchPath-0: .\n"
18
-
19
- #: Puc/v4p1/Plugin/UpdateChecker.php:358
20
- msgid "Check for updates"
21
- msgstr "Sök efter uppdateringar"
22
-
23
- #: Puc/v4p1/Plugin/UpdateChecker.php:405
24
- #, php-format
25
- msgctxt "the plugin title"
26
- msgid "The %s plugin is up to date."
27
- msgstr "Tillägget %s är uppdaterat."
28
-
29
- #: Puc/v4p1/Plugin/UpdateChecker.php:407
30
- #, php-format
31
- msgctxt "the plugin title"
32
- msgid "A new version of the %s plugin is available."
33
- msgstr "Det finns en ny version av tillägget %s."
34
-
35
- #: Puc/v4p1/Plugin/UpdateChecker.php:409
36
- #, php-format
37
- msgid "Unknown update checker status \"%s\""
38
- msgstr "Okänd status för kontroll av uppdatering “%s”"
39
-
40
- #: Puc/v4p1/Vcs/PluginUpdateChecker.php:83
41
- msgid "There is no changelog available."
42
- msgstr "Det finns ingen ändringslogg tillgänglig."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/languages/plugin-update-checker.pot DELETED
@@ -1,49 +0,0 @@
1
- #, fuzzy
2
- msgid ""
3
- msgstr ""
4
- "Project-Id-Version: plugin-update-checker\n"
5
- "POT-Creation-Date: 2017-11-24 17:02+0200\n"
6
- "PO-Revision-Date: 2016-01-10 20:59+0100\n"
7
- "Last-Translator: Tamás András Horváth <htomy92@gmail.com>\n"
8
- "Language-Team: \n"
9
- "Language: en_US\n"
10
- "MIME-Version: 1.0\n"
11
- "Content-Type: text/plain; charset=UTF-8\n"
12
- "Content-Transfer-Encoding: 8bit\n"
13
- "X-Generator: Poedit 2.0.4\n"
14
- "X-Poedit-Basepath: ..\n"
15
- "Plural-Forms: nplurals=2; plural=(n != 1);\n"
16
- "X-Poedit-SourceCharset: UTF-8\n"
17
- "X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
18
- "X-Poedit-SearchPath-0: .\n"
19
-
20
- #: Puc/v4p3/Plugin/UpdateChecker.php:395
21
- msgid "Check for updates"
22
- msgstr ""
23
-
24
- #: Puc/v4p3/Plugin/UpdateChecker.php:548
25
- #, php-format
26
- msgctxt "the plugin title"
27
- msgid "The %s plugin is up to date."
28
- msgstr ""
29
-
30
- #: Puc/v4p3/Plugin/UpdateChecker.php:550
31
- #, php-format
32
- msgctxt "the plugin title"
33
- msgid "A new version of the %s plugin is available."
34
- msgstr ""
35
-
36
- #: Puc/v4p3/Plugin/UpdateChecker.php:552
37
- #, php-format
38
- msgctxt "the plugin title"
39
- msgid "Could not determine if updates are available for %s."
40
- msgstr ""
41
-
42
- #: Puc/v4p3/Plugin/UpdateChecker.php:558
43
- #, php-format
44
- msgid "Unknown update checker status \"%s\""
45
- msgstr ""
46
-
47
- #: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
48
- msgid "There is no changelog available."
49
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/license.txt DELETED
@@ -1,7 +0,0 @@
1
- Copyright (c) 2017 Jānis Elsts
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 
 
 
 
 
 
plugin-update-checker/plugin-update-checker.php DELETED
@@ -1,24 +0,0 @@
1
- <?php
2
- /**
3
- * Plugin Update Checker Library 4.4
4
- * http://w-shadow.com/
5
- *
6
- * Copyright 2017 Janis Elsts
7
- * Released under the MIT license. See license.txt for details.
8
- */
9
-
10
- require dirname(__FILE__) . '/Puc/v4p4/Factory.php';
11
- require dirname(__FILE__) . '/Puc/v4/Factory.php';
12
- require dirname(__FILE__) . '/Puc/v4p4/Autoloader.php';
13
- new Puc_v4p4_Autoloader();
14
-
15
- //Register classes defined in this file with the factory.
16
- Puc_v4_Factory::addVersion('Plugin_UpdateChecker', 'Puc_v4p4_Plugin_UpdateChecker', '4.4');
17
- Puc_v4_Factory::addVersion('Theme_UpdateChecker', 'Puc_v4p4_Theme_UpdateChecker', '4.4');
18
-
19
- Puc_v4_Factory::addVersion('Vcs_PluginUpdateChecker', 'Puc_v4p4_Vcs_PluginUpdateChecker', '4.4');
20
- Puc_v4_Factory::addVersion('Vcs_ThemeUpdateChecker', 'Puc_v4p4_Vcs_ThemeUpdateChecker', '4.4');
21
-
22
- Puc_v4_Factory::addVersion('GitHubApi', 'Puc_v4p4_Vcs_GitHubApi', '4.4');
23
- Puc_v4_Factory::addVersion('BitBucketApi', 'Puc_v4p4_Vcs_BitBucketApi', '4.4');
24
- Puc_v4_Factory::addVersion('GitLabApi', 'Puc_v4p4_Vcs_GitLabApi', '4.4');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/vendor/Parsedown.php DELETED
@@ -1,1538 +0,0 @@
1
- <?php
2
-
3
- #
4
- #
5
- # Parsedown
6
- # http://parsedown.org
7
- #
8
- # (c) Emanuil Rusev
9
- # http://erusev.com
10
- #
11
- # For the full license information, view the LICENSE file that was distributed
12
- # with this source code.
13
- #
14
- #
15
-
16
- class Parsedown
17
- {
18
- # ~
19
-
20
- const version = '1.6.0';
21
-
22
- # ~
23
-
24
- function text($text)
25
- {
26
- # make sure no definitions are set
27
- $this->DefinitionData = array();
28
-
29
- # standardize line breaks
30
- $text = str_replace(array("\r\n", "\r"), "\n", $text);
31
-
32
- # remove surrounding line breaks
33
- $text = trim($text, "\n");
34
-
35
- # split text into lines
36
- $lines = explode("\n", $text);
37
-
38
- # iterate through lines to identify blocks
39
- $markup = $this->lines($lines);
40
-
41
- # trim line breaks
42
- $markup = trim($markup, "\n");
43
-
44
- return $markup;
45
- }
46
-
47
- #
48
- # Setters
49
- #
50
-
51
- function setBreaksEnabled($breaksEnabled)
52
- {
53
- $this->breaksEnabled = $breaksEnabled;
54
-
55
- return $this;
56
- }
57
-
58
- protected $breaksEnabled;
59
-
60
- function setMarkupEscaped($markupEscaped)
61
- {
62
- $this->markupEscaped = $markupEscaped;
63
-
64
- return $this;
65
- }
66
-
67
- protected $markupEscaped;
68
-
69
- function setUrlsLinked($urlsLinked)
70
- {
71
- $this->urlsLinked = $urlsLinked;
72
-
73
- return $this;
74
- }
75
-
76
- protected $urlsLinked = true;
77
-
78
- #
79
- # Lines
80
- #
81
-
82
- protected $BlockTypes = array(
83
- '#' => array('Header'),
84
- '*' => array('Rule', 'List'),
85
- '+' => array('List'),
86
- '-' => array('SetextHeader', 'Table', 'Rule', 'List'),
87
- '0' => array('List'),
88
- '1' => array('List'),
89
- '2' => array('List'),
90
- '3' => array('List'),
91
- '4' => array('List'),
92
- '5' => array('List'),
93
- '6' => array('List'),
94
- '7' => array('List'),
95
- '8' => array('List'),
96
- '9' => array('List'),
97
- ':' => array('Table'),
98
- '<' => array('Comment', 'Markup'),
99
- '=' => array('SetextHeader'),
100
- '>' => array('Quote'),
101
- '[' => array('Reference'),
102
- '_' => array('Rule'),
103
- '`' => array('FencedCode'),
104
- '|' => array('Table'),
105
- '~' => array('FencedCode'),
106
- );
107
-
108
- # ~
109
-
110
- protected $unmarkedBlockTypes = array(
111
- 'Code',
112
- );
113
-
114
- #
115
- # Blocks
116
- #
117
-
118
- protected function lines(array $lines)
119
- {
120
- $CurrentBlock = null;
121
-
122
- foreach ($lines as $line)
123
- {
124
- if (chop($line) === '')
125
- {
126
- if (isset($CurrentBlock))
127
- {
128
- $CurrentBlock['interrupted'] = true;
129
- }
130
-
131
- continue;
132
- }
133
-
134
- if (strpos($line, "\t") !== false)
135
- {
136
- $parts = explode("\t", $line);
137
-
138
- $line = $parts[0];
139
-
140
- unset($parts[0]);
141
-
142
- foreach ($parts as $part)
143
- {
144
- $shortage = 4 - mb_strlen($line, 'utf-8') % 4;
145
-
146
- $line .= str_repeat(' ', $shortage);
147
- $line .= $part;
148
- }
149
- }
150
-
151
- $indent = 0;
152
-
153
- while (isset($line[$indent]) and $line[$indent] === ' ')
154
- {
155
- $indent ++;
156
- }
157
-
158
- $text = $indent > 0 ? substr($line, $indent) : $line;
159
-
160
- # ~
161
-
162
- $Line = array('body' => $line, 'indent' => $indent, 'text' => $text);
163
-
164
- # ~
165
-
166
- if (isset($CurrentBlock['continuable']))
167
- {
168
- $Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock);
169
-
170
- if (isset($Block))
171
- {
172
- $CurrentBlock = $Block;
173
-
174
- continue;
175
- }
176
- else
177
- {
178
- if ($this->isBlockCompletable($CurrentBlock['type']))
179
- {
180
- $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
181
- }
182
- }
183
- }
184
-
185
- # ~
186
-
187
- $marker = $text[0];
188
-
189
- # ~
190
-
191
- $blockTypes = $this->unmarkedBlockTypes;
192
-
193
- if (isset($this->BlockTypes[$marker]))
194
- {
195
- foreach ($this->BlockTypes[$marker] as $blockType)
196
- {
197
- $blockTypes []= $blockType;
198
- }
199
- }
200
-
201
- #
202
- # ~
203
-
204
- foreach ($blockTypes as $blockType)
205
- {
206
- $Block = $this->{'block'.$blockType}($Line, $CurrentBlock);
207
-
208
- if (isset($Block))
209
- {
210
- $Block['type'] = $blockType;
211
-
212
- if ( ! isset($Block['identified']))
213
- {
214
- $Blocks []= $CurrentBlock;
215
-
216
- $Block['identified'] = true;
217
- }
218
-
219
- if ($this->isBlockContinuable($blockType))
220
- {
221
- $Block['continuable'] = true;
222
- }
223
-
224
- $CurrentBlock = $Block;
225
-
226
- continue 2;
227
- }
228
- }
229
-
230
- # ~
231
-
232
- if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted']))
233
- {
234
- $CurrentBlock['element']['text'] .= "\n".$text;
235
- }
236
- else
237
- {
238
- $Blocks []= $CurrentBlock;
239
-
240
- $CurrentBlock = $this->paragraph($Line);
241
-
242
- $CurrentBlock['identified'] = true;
243
- }
244
- }
245
-
246
- # ~
247
-
248
- if (isset($CurrentBlock['continuable']) and $this->isBlockCompletable($CurrentBlock['type']))
249
- {
250
- $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
251
- }
252
-
253
- # ~
254
-
255
- $Blocks []= $CurrentBlock;
256
-
257
- unset($Blocks[0]);
258
-
259
- # ~
260
-
261
- $markup = '';
262
-
263
- foreach ($Blocks as $Block)
264
- {
265
- if (isset($Block['hidden']))
266
- {
267
- continue;
268
- }
269
-
270
- $markup .= "\n";
271
- $markup .= isset($Block['markup']) ? $Block['markup'] : $this->element($Block['element']);
272
- }
273
-
274
- $markup .= "\n";
275
-
276
- # ~
277
-
278
- return $markup;
279
- }
280
-
281
- protected function isBlockContinuable($Type)
282
- {
283
- return method_exists($this, 'block'.$Type.'Continue');
284
- }
285
-
286
- protected function isBlockCompletable($Type)
287
- {
288
- return method_exists($this, 'block'.$Type.'Complete');
289
- }
290
-
291
- #
292
- # Code
293
-
294
- protected function blockCode($Line, $Block = null)
295
- {
296
- if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted']))
297
- {
298
- return;
299
- }
300
-
301
- if ($Line['indent'] >= 4)
302
- {
303
- $text = substr($Line['body'], 4);
304
-
305
- $Block = array(
306
- 'element' => array(
307
- 'name' => 'pre',
308
- 'handler' => 'element',
309
- 'text' => array(
310
- 'name' => 'code',
311
- 'text' => $text,
312
- ),
313
- ),
314
- );
315
-
316
- return $Block;
317
- }
318
- }
319
-
320
- protected function blockCodeContinue($Line, $Block)
321
- {
322
- if ($Line['indent'] >= 4)
323
- {
324
- if (isset($Block['interrupted']))
325
- {
326
- $Block['element']['text']['text'] .= "\n";
327
-
328
- unset($Block['interrupted']);
329
- }
330
-
331
- $Block['element']['text']['text'] .= "\n";
332
-
333
- $text = substr($Line['body'], 4);
334
-
335
- $Block['element']['text']['text'] .= $text;
336
-
337
- return $Block;
338
- }
339
- }
340
-
341
- protected function blockCodeComplete($Block)
342
- {
343
- $text = $Block['element']['text']['text'];
344
-
345
- $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
346
-
347
- $Block['element']['text']['text'] = $text;
348
-
349
- return $Block;
350
- }
351
-
352
- #
353
- # Comment
354
-
355
- protected function blockComment($Line)
356
- {
357
- if ($this->markupEscaped)
358
- {
359
- return;
360
- }
361
-
362
- if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!')
363
- {
364
- $Block = array(
365
- 'markup' => $Line['body'],
366
- );
367
-
368
- if (preg_match('/-->$/', $Line['text']))
369
- {
370
- $Block['closed'] = true;
371
- }
372
-
373
- return $Block;
374
- }
375
- }
376
-
377
- protected function blockCommentContinue($Line, array $Block)
378
- {
379
- if (isset($Block['closed']))
380
- {
381
- return;
382
- }
383
-
384
- $Block['markup'] .= "\n" . $Line['body'];
385
-
386
- if (preg_match('/-->$/', $Line['text']))
387
- {
388
- $Block['closed'] = true;
389
- }
390
-
391
- return $Block;
392
- }
393
-
394
- #
395
- # Fenced Code
396
-
397
- protected function blockFencedCode($Line)
398
- {
399
- if (preg_match('/^['.$Line['text'][0].']{3,}[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches))
400
- {
401
- $Element = array(
402
- 'name' => 'code',
403
- 'text' => '',
404
- );
405
-
406
- if (isset($matches[1]))
407
- {
408
- $class = 'language-'.$matches[1];
409
-
410
- $Element['attributes'] = array(
411
- 'class' => $class,
412
- );
413
- }
414
-
415
- $Block = array(
416
- 'char' => $Line['text'][0],
417
- 'element' => array(
418
- 'name' => 'pre',
419
- 'handler' => 'element',
420
- 'text' => $Element,
421
- ),
422
- );
423
-
424
- return $Block;
425
- }
426
- }
427
-
428
- protected function blockFencedCodeContinue($Line, $Block)
429
- {
430
- if (isset($Block['complete']))
431
- {
432
- return;
433
- }
434
-
435
- if (isset($Block['interrupted']))
436
- {
437
- $Block['element']['text']['text'] .= "\n";
438
-
439
- unset($Block['interrupted']);
440
- }
441
-
442
- if (preg_match('/^'.$Block['char'].'{3,}[ ]*$/', $Line['text']))
443
- {
444
- $Block['element']['text']['text'] = substr($Block['element']['text']['text'], 1);
445
-
446
- $Block['complete'] = true;
447
-
448
- return $Block;
449
- }
450
-
451
- $Block['element']['text']['text'] .= "\n".$Line['body'];;
452
-
453
- return $Block;
454
- }
455
-
456
- protected function blockFencedCodeComplete($Block)
457
- {
458
- $text = $Block['element']['text']['text'];
459
-
460
- $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
461
-
462
- $Block['element']['text']['text'] = $text;
463
-
464
- return $Block;
465
- }
466
-
467
- #
468
- # Header
469
-
470
- protected function blockHeader($Line)
471
- {
472
- if (isset($Line['text'][1]))
473
- {
474
- $level = 1;
475
-
476
- while (isset($Line['text'][$level]) and $Line['text'][$level] === '#')
477
- {
478
- $level ++;
479
- }
480
-
481
- if ($level > 6)
482
- {
483
- return;
484
- }
485
-
486
- $text = trim($Line['text'], '# ');
487
-
488
- $Block = array(
489
- 'element' => array(
490
- 'name' => 'h' . min(6, $level),
491
- 'text' => $text,
492
- 'handler' => 'line',
493
- ),
494
- );
495
-
496
- return $Block;
497
- }
498
- }
499
-
500
- #
501
- # List
502
-
503
- protected function blockList($Line)
504
- {
505
- list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]');
506
-
507
- if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches))
508
- {
509
- $Block = array(
510
- 'indent' => $Line['indent'],
511
- 'pattern' => $pattern,
512
- 'element' => array(
513
- 'name' => $name,
514
- 'handler' => 'elements',
515
- ),
516
- );
517
-
518
- $Block['li'] = array(
519
- 'name' => 'li',
520
- 'handler' => 'li',
521
- 'text' => array(
522
- $matches[2],
523
- ),
524
- );
525
-
526
- $Block['element']['text'] []= & $Block['li'];
527
-
528
- return $Block;
529
- }
530
- }
531
-
532
- protected function blockListContinue($Line, array $Block)
533
- {
534
- if ($Block['indent'] === $Line['indent'] and preg_match('/^'.$Block['pattern'].'(?:[ ]+(.*)|$)/', $Line['text'], $matches))
535
- {
536
- if (isset($Block['interrupted']))
537
- {
538
- $Block['li']['text'] []= '';
539
-
540
- unset($Block['interrupted']);
541
- }
542
-
543
- unset($Block['li']);
544
-
545
- $text = isset($matches[1]) ? $matches[1] : '';
546
-
547
- $Block['li'] = array(
548
- 'name' => 'li',
549
- 'handler' => 'li',
550
- 'text' => array(
551
- $text,
552
- ),
553
- );
554
-
555
- $Block['element']['text'] []= & $Block['li'];
556
-
557
- return $Block;
558
- }
559
-
560
- if ($Line['text'][0] === '[' and $this->blockReference($Line))
561
- {
562
- return $Block;
563
- }
564
-
565
- if ( ! isset($Block['interrupted']))
566
- {
567
- $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']);
568
-
569
- $Block['li']['text'] []= $text;
570
-
571
- return $Block;
572
- }
573
-
574
- if ($Line['indent'] > 0)
575
- {
576
- $Block['li']['text'] []= '';
577
-
578
- $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']);
579
-
580
- $Block['li']['text'] []= $text;
581
-
582
- unset($Block['interrupted']);
583
-
584
- return $Block;
585
- }
586
- }
587
-
588
- #
589
- # Quote
590
-
591
- protected function blockQuote($Line)
592
- {
593
- if (preg_match('/^>[ ]?(.*)/', $Line['text'], $matches))
594
- {
595
- $Block = array(
596
- 'element' => array(
597
- 'name' => 'blockquote',
598
- 'handler' => 'lines',
599
- 'text' => (array) $matches[1],
600
- ),
601
- );
602
-
603
- return $Block;
604
- }
605
- }
606
-
607
- protected function blockQuoteContinue($Line, array $Block)
608
- {
609
- if ($Line['text'][0] === '>' and preg_match('/^>[ ]?(.*)/', $Line['text'], $matches))
610
- {
611
- if (isset($Block['interrupted']))
612
- {
613
- $Block['element']['text'] []= '';
614
-
615
- unset($Block['interrupted']);
616
- }
617
-
618
- $Block['element']['text'] []= $matches[1];
619
-
620
- return $Block;
621
- }
622
-
623
- if ( ! isset($Block['interrupted']))
624
- {
625
- $Block['element']['text'] []= $Line['text'];
626
-
627
- return $Block;
628
- }
629
- }
630
-
631
- #
632
- # Rule
633
-
634
- protected function blockRule($Line)
635
- {
636
- if (preg_match('/^(['.$Line['text'][0].'])([ ]*\1){2,}[ ]*$/', $Line['text']))
637
- {
638
- $Block = array(
639
- 'element' => array(
640
- 'name' => 'hr'
641
- ),
642
- );
643
-
644
- return $Block;
645
- }
646
- }
647
-
648
- #
649
- # Setext
650
-
651
- protected function blockSetextHeader($Line, array $Block = null)
652
- {
653
- if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
654
- {
655
- return;
656
- }
657
-
658
- if (chop($Line['text'], $Line['text'][0]) === '')
659
- {
660
- $Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2';
661
-
662
- return $Block;
663
- }
664
- }
665
-
666
- #
667
- # Markup
668
-
669
- protected function blockMarkup($Line)
670
- {
671
- if ($this->markupEscaped)
672
- {
673
- return;
674
- }
675
-
676
- if (preg_match('/^<(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
677
- {
678
- $element = strtolower($matches[1]);
679
-
680
- if (in_array($element, $this->textLevelElements))
681
- {
682
- return;
683
- }
684
-
685
- $Block = array(
686
- 'name' => $matches[1],
687
- 'depth' => 0,
688
- 'markup' => $Line['text'],
689
- );
690
-
691
- $length = strlen($matches[0]);
692
-
693
- $remainder = substr($Line['text'], $length);
694
-
695
- if (trim($remainder) === '')
696
- {
697
- if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
698
- {
699
- $Block['closed'] = true;
700
-
701
- $Block['void'] = true;
702
- }
703
- }
704
- else
705
- {
706
- if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
707
- {
708
- return;
709
- }
710
-
711
- if (preg_match('/<\/'.$matches[1].'>[ ]*$/i', $remainder))
712
- {
713
- $Block['closed'] = true;
714
- }
715
- }
716
-
717
- return $Block;
718
- }
719
- }
720
-
721
- protected function blockMarkupContinue($Line, array $Block)
722
- {
723
- if (isset($Block['closed']))
724
- {
725
- return;
726
- }
727
-
728
- if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open
729
- {
730
- $Block['depth'] ++;
731
- }
732
-
733
- if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close
734
- {
735
- if ($Block['depth'] > 0)
736
- {
737
- $Block['depth'] --;
738
- }
739
- else
740
- {
741
- $Block['closed'] = true;
742
- }
743
- }
744
-
745
- if (isset($Block['interrupted']))
746
- {
747
- $Block['markup'] .= "\n";
748
-
749
- unset($Block['interrupted']);
750
- }
751
-
752
- $Block['markup'] .= "\n".$Line['body'];
753
-
754
- return $Block;
755
- }
756
-
757
- #
758
- # Reference
759
-
760
- protected function blockReference($Line)
761
- {
762
- if (preg_match('/^\[(.+?)\]:[ ]*<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches))
763
- {
764
- $id = strtolower($matches[1]);
765
-
766
- $Data = array(
767
- 'url' => $matches[2],
768
- 'title' => null,
769
- );
770
-
771
- if (isset($matches[3]))
772
- {
773
- $Data['title'] = $matches[3];
774
- }
775
-
776
- $this->DefinitionData['Reference'][$id] = $Data;
777
-
778
- $Block = array(
779
- 'hidden' => true,
780
- );
781
-
782
- return $Block;
783
- }
784
- }
785
-
786
- #
787
- # Table
788
-
789
- protected function blockTable($Line, array $Block = null)
790
- {
791
- if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
792
- {
793
- return;
794
- }
795
-
796
- if (strpos($Block['element']['text'], '|') !== false and chop($Line['text'], ' -:|') === '')
797
- {
798
- $alignments = array();
799
-
800
- $divider = $Line['text'];
801
-
802
- $divider = trim($divider);
803
- $divider = trim($divider, '|');
804
-
805
- $dividerCells = explode('|', $divider);
806
-
807
- foreach ($dividerCells as $dividerCell)
808
- {
809
- $dividerCell = trim($dividerCell);
810
-
811
- if ($dividerCell === '')
812
- {
813
- continue;
814
- }
815
-
816
- $alignment = null;
817
-
818
- if ($dividerCell[0] === ':')
819
- {
820
- $alignment = 'left';
821
- }
822
-
823
- if (substr($dividerCell, - 1) === ':')
824
- {
825
- $alignment = $alignment === 'left' ? 'center' : 'right';
826
- }
827
-
828
- $alignments []= $alignment;
829
- }
830
-
831
- # ~
832
-
833
- $HeaderElements = array();
834
-
835
- $header = $Block['element']['text'];
836
-
837
- $header = trim($header);
838
- $header = trim($header, '|');
839
-
840
- $headerCells = explode('|', $header);
841
-
842
- foreach ($headerCells as $index => $headerCell)
843
- {
844
- $headerCell = trim($headerCell);
845
-
846
- $HeaderElement = array(
847
- 'name' => 'th',
848
- 'text' => $headerCell,
849
- 'handler' => 'line',
850
- );
851
-
852
- if (isset($alignments[$index]))
853
- {
854
- $alignment = $alignments[$index];
855
-
856
- $HeaderElement['attributes'] = array(
857
- 'style' => 'text-align: '.$alignment.';',
858
- );
859
- }
860
-
861
- $HeaderElements []= $HeaderElement;
862
- }
863
-
864
- # ~
865
-
866
- $Block = array(
867
- 'alignments' => $alignments,
868
- 'identified' => true,
869
- 'element' => array(
870
- 'name' => 'table',
871
- 'handler' => 'elements',
872
- ),
873
- );
874
-
875
- $Block['element']['text'] []= array(
876
- 'name' => 'thead',
877
- 'handler' => 'elements',
878
- );
879
-
880
- $Block['element']['text'] []= array(
881
- 'name' => 'tbody',
882
- 'handler' => 'elements',
883
- 'text' => array(),
884
- );
885
-
886
- $Block['element']['text'][0]['text'] []= array(
887
- 'name' => 'tr',
888
- 'handler' => 'elements',
889
- 'text' => $HeaderElements,
890
- );
891
-
892
- return $Block;
893
- }
894
- }
895
-
896
- protected function blockTableContinue($Line, array $Block)
897
- {
898
- if (isset($Block['interrupted']))
899
- {
900
- return;
901
- }
902
-
903
- if ($Line['text'][0] === '|' or strpos($Line['text'], '|'))
904
- {
905
- $Elements = array();
906
-
907
- $row = $Line['text'];
908
-
909
- $row = trim($row);
910
- $row = trim($row, '|');
911
-
912
- preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches);
913
-
914
- foreach ($matches[0] as $index => $cell)
915
- {
916
- $cell = trim($cell);
917
-
918
- $Element = array(
919
- 'name' => 'td',
920
- 'handler' => 'line',
921
- 'text' => $cell,
922
- );
923
-
924
- if (isset($Block['alignments'][$index]))
925
- {
926
- $Element['attributes'] = array(
927
- 'style' => 'text-align: '.$Block['alignments'][$index].';',
928
- );
929
- }
930
-
931
- $Elements []= $Element;
932
- }
933
-
934
- $Element = array(
935
- 'name' => 'tr',
936
- 'handler' => 'elements',
937
- 'text' => $Elements,
938
- );
939
-
940
- $Block['element']['text'][1]['text'] []= $Element;
941
-
942
- return $Block;
943
- }
944
- }
945
-
946
- #
947
- # ~
948
- #
949
-
950
- protected function paragraph($Line)
951
- {
952
- $Block = array(
953
- 'element' => array(
954
- 'name' => 'p',
955
- 'text' => $Line['text'],
956
- 'handler' => 'line',
957
- ),
958
- );
959
-
960
- return $Block;
961
- }
962
-
963
- #
964
- # Inline Elements
965
- #
966
-
967
- protected $InlineTypes = array(
968
- '"' => array('SpecialCharacter'),
969
- '!' => array('Image'),
970
- '&' => array('SpecialCharacter'),
971
- '*' => array('Emphasis'),
972
- ':' => array('Url'),
973
- '<' => array('UrlTag', 'EmailTag', 'Markup', 'SpecialCharacter'),
974
- '>' => array('SpecialCharacter'),
975
- '[' => array('Link'),
976
- '_' => array('Emphasis'),
977
- '`' => array('Code'),
978
- '~' => array('Strikethrough'),
979
- '\\' => array('EscapeSequence'),
980
- );
981
-
982
- # ~
983
-
984
- protected $inlineMarkerList = '!"*_&[:<>`~\\';
985
-
986
- #
987
- # ~
988
- #
989
-
990
- public function line($text)
991
- {
992
- $markup = '';
993
-
994
- # $excerpt is based on the first occurrence of a marker
995
-
996
- while ($excerpt = strpbrk($text, $this->inlineMarkerList))
997
- {
998
- $marker = $excerpt[0];
999
-
1000
- $markerPosition = strpos($text, $marker);
1001
-
1002
- $Excerpt = array('text' => $excerpt, 'context' => $text);
1003
-
1004
- foreach ($this->InlineTypes[$marker] as $inlineType)
1005
- {
1006
- $Inline = $this->{'inline'.$inlineType}($Excerpt);
1007
-
1008
- if ( ! isset($Inline))
1009
- {
1010
- continue;
1011
- }
1012
-
1013
- # makes sure that the inline belongs to "our" marker
1014
-
1015
- if (isset($Inline['position']) and $Inline['position'] > $markerPosition)
1016
- {
1017
- continue;
1018
- }
1019
-
1020
- # sets a default inline position
1021
-
1022
- if ( ! isset($Inline['position']))
1023
- {
1024
- $Inline['position'] = $markerPosition;
1025
- }
1026
-
1027
- # the text that comes before the inline
1028
- $unmarkedText = substr($text, 0, $Inline['position']);
1029
-
1030
- # compile the unmarked text
1031
- $markup .= $this->unmarkedText($unmarkedText);
1032
-
1033
- # compile the inline
1034
- $markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']);
1035
-
1036
- # remove the examined text
1037
- $text = substr($text, $Inline['position'] + $Inline['extent']);
1038
-
1039
- continue 2;
1040
- }
1041
-
1042
- # the marker does not belong to an inline
1043
-
1044
- $unmarkedText = substr($text, 0, $markerPosition + 1);
1045
-
1046
- $markup .= $this->unmarkedText($unmarkedText);
1047
-
1048
- $text = substr($text, $markerPosition + 1);
1049
- }
1050
-
1051
- $markup .= $this->unmarkedText($text);
1052
-
1053
- return $markup;
1054
- }
1055
-
1056
- #
1057
- # ~
1058
- #
1059
-
1060
- protected function inlineCode($Excerpt)
1061
- {
1062
- $marker = $Excerpt['text'][0];
1063
-
1064
- if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(?<!'.$marker.')\1(?!'.$marker.')/s', $Excerpt['text'], $matches))
1065
- {
1066
- $text = $matches[2];
1067
- $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
1068
- $text = preg_replace("/[ ]*\n/", ' ', $text);
1069
-
1070
- return array(
1071
- 'extent' => strlen($matches[0]),
1072
- 'element' => array(
1073
- 'name' => 'code',
1074
- 'text' => $text,
1075
- ),
1076
- );
1077
- }
1078
- }
1079
-
1080
- protected function inlineEmailTag($Excerpt)
1081
- {
1082
- if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $Excerpt['text'], $matches))
1083
- {
1084
- $url = $matches[1];
1085
-
1086
- if ( ! isset($matches[2]))
1087
- {
1088
- $url = 'mailto:' . $url;
1089
- }
1090
-
1091
- return array(
1092
- 'extent' => strlen($matches[0]),
1093
- 'element' => array(
1094
- 'name' => 'a',
1095
- 'text' => $matches[1],
1096
- 'attributes' => array(
1097
- 'href' => $url,
1098
- ),
1099
- ),
1100
- );
1101
- }
1102
- }
1103
-
1104
- protected function inlineEmphasis($Excerpt)
1105
- {
1106
- if ( ! isset($Excerpt['text'][1]))
1107
- {
1108
- return;
1109
- }
1110
-
1111
- $marker = $Excerpt['text'][0];
1112
-
1113
- if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches))
1114
- {
1115
- $emphasis = 'strong';
1116
- }
1117
- elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches))
1118
- {
1119
- $emphasis = 'em';
1120
- }
1121
- else
1122
- {
1123
- return;
1124
- }
1125
-
1126
- return array(
1127
- 'extent' => strlen($matches[0]),
1128
- 'element' => array(
1129
- 'name' => $emphasis,
1130
- 'handler' => 'line',
1131
- 'text' => $matches[1],
1132
- ),
1133
- );
1134
- }
1135
-
1136
- protected function inlineEscapeSequence($Excerpt)
1137
- {
1138
- if (isset($Excerpt['text'][1]) and in_array($Excerpt['text'][1], $this->specialCharacters))
1139
- {
1140
- return array(
1141
- 'markup' => $Excerpt['text'][1],
1142
- 'extent' => 2,
1143
- );
1144
- }
1145
- }
1146
-
1147
- protected function inlineImage($Excerpt)
1148
- {
1149
- if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[')
1150
- {
1151
- return;
1152
- }
1153
-
1154
- $Excerpt['text']= substr($Excerpt['text'], 1);
1155
-
1156
- $Link = $this->inlineLink($Excerpt);
1157
-
1158
- if ($Link === null)
1159
- {
1160
- return;
1161
- }
1162
-
1163
- $Inline = array(
1164
- 'extent' => $Link['extent'] + 1,
1165
- 'element' => array(
1166
- 'name' => 'img',
1167
- 'attributes' => array(
1168
- 'src' => $Link['element']['attributes']['href'],
1169
- 'alt' => $Link['element']['text'],
1170
- ),
1171
- ),
1172
- );
1173
-
1174
- $Inline['element']['attributes'] += $Link['element']['attributes'];
1175
-
1176
- unset($Inline['element']['attributes']['href']);
1177
-
1178
- return $Inline;
1179
- }
1180
-
1181
- protected function inlineLink($Excerpt)
1182
- {
1183
- $Element = array(
1184
- 'name' => 'a',
1185
- 'handler' => 'line',
1186
- 'text' => null,
1187
- 'attributes' => array(
1188
- 'href' => null,
1189
- 'title' => null,
1190
- ),
1191
- );
1192
-
1193
- $extent = 0;
1194
-
1195
- $remainder = $Excerpt['text'];
1196
-
1197
- if (preg_match('/\[((?:[^][]|(?R))*)\]/', $remainder, $matches))
1198
- {
1199
- $Element['text'] = $matches[1];
1200
-
1201
- $extent += strlen($matches[0]);
1202
-
1203
- $remainder = substr($remainder, $extent);
1204
- }
1205
- else
1206
- {
1207
- return;
1208
- }
1209
-
1210
- if (preg_match('/^[(]((?:[^ ()]|[(][^ )]+[)])+)(?:[ ]+("[^"]*"|\'[^\']*\'))?[)]/', $remainder, $matches))
1211
- {
1212
- $Element['attributes']['href'] = $matches[1];
1213
-
1214
- if (isset($matches[2]))
1215
- {
1216
- $Element['attributes']['title'] = substr($matches[2], 1, - 1);
1217
- }
1218
-
1219
- $extent += strlen($matches[0]);
1220
- }
1221
- else
1222
- {
1223
- if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches))
1224
- {
1225
- $definition = strlen($matches[1]) ? $matches[1] : $Element['text'];
1226
- $definition = strtolower($definition);
1227
-
1228
- $extent += strlen($matches[0]);
1229
- }
1230
- else
1231
- {
1232
- $definition = strtolower($Element['text']);
1233
- }
1234
-
1235
- if ( ! isset($this->DefinitionData['Reference'][$definition]))
1236
- {
1237
- return;
1238
- }
1239
-
1240
- $Definition = $this->DefinitionData['Reference'][$definition];
1241
-
1242
- $Element['attributes']['href'] = $Definition['url'];
1243
- $Element['attributes']['title'] = $Definition['title'];
1244
- }
1245
-
1246
- $Element['attributes']['href'] = str_replace(array('&', '<'), array('&amp;', '&lt;'), $Element['attributes']['href']);
1247
-
1248
- return array(
1249
- 'extent' => $extent,
1250
- 'element' => $Element,
1251
- );
1252
- }
1253
-
1254
- protected function inlineMarkup($Excerpt)
1255
- {
1256
- if ($this->markupEscaped or strpos($Excerpt['text'], '>') === false)
1257
- {
1258
- return;
1259
- }
1260
-
1261
- if ($Excerpt['text'][1] === '/' and preg_match('/^<\/\w*[ ]*>/s', $Excerpt['text'], $matches))
1262
- {
1263
- return array(
1264
- 'markup' => $matches[0],
1265
- 'extent' => strlen($matches[0]),
1266
- );
1267
- }
1268
-
1269
- if ($Excerpt['text'][1] === '!' and preg_match('/^<!---?[^>-](?:-?[^-])*-->/s', $Excerpt['text'], $matches))
1270
- {
1271
- return array(
1272
- 'markup' => $matches[0],
1273
- 'extent' => strlen($matches[0]),
1274
- );
1275
- }
1276
-
1277
- if ($Excerpt['text'][1] !== ' ' and preg_match('/^<\w*(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*\/?>/s', $Excerpt['text'], $matches))
1278
- {
1279
- return array(
1280
- 'markup' => $matches[0],
1281
- 'extent' => strlen($matches[0]),
1282
- );
1283
- }
1284
- }
1285
-
1286
- protected function inlineSpecialCharacter($Excerpt)
1287
- {
1288
- if ($Excerpt['text'][0] === '&' and ! preg_match('/^&#?\w+;/', $Excerpt['text']))
1289
- {
1290
- return array(
1291
- 'markup' => '&amp;',
1292
- 'extent' => 1,
1293
- );
1294
- }
1295
-
1296
- $SpecialCharacter = array('>' => 'gt', '<' => 'lt', '"' => 'quot');
1297
-
1298
- if (isset($SpecialCharacter[$Excerpt['text'][0]]))
1299
- {
1300
- return array(
1301
- 'markup' => '&'.$SpecialCharacter[$Excerpt['text'][0]].';',
1302
- 'extent' => 1,
1303
- );
1304
- }
1305
- }
1306
-
1307
- protected function inlineStrikethrough($Excerpt)
1308
- {
1309
- if ( ! isset($Excerpt['text'][1]))
1310
- {
1311
- return;
1312
- }
1313
-
1314
- if ($Excerpt['text'][1] === '~' and preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches))
1315
- {
1316
- return array(
1317
- 'extent' => strlen($matches[0]),
1318
- 'element' => array(
1319
- 'name' => 'del',
1320
- 'text' => $matches[1],
1321
- 'handler' => 'line',
1322
- ),
1323
- );
1324
- }
1325
- }
1326
-
1327
- protected function inlineUrl($Excerpt)
1328
- {
1329
- if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/')
1330
- {
1331
- return;
1332
- }
1333
-
1334
- if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE))
1335
- {
1336
- $Inline = array(
1337
- 'extent' => strlen($matches[0][0]),
1338
- 'position' => $matches[0][1],
1339
- 'element' => array(
1340
- 'name' => 'a',
1341
- 'text' => $matches[0][0],
1342
- 'attributes' => array(
1343
- 'href' => $matches[0][0],
1344
- ),
1345
- ),
1346
- );
1347
-
1348
- return $Inline;
1349
- }
1350
- }
1351
-
1352
- protected function inlineUrlTag($Excerpt)
1353
- {
1354
- if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches))
1355
- {
1356
- $url = str_replace(array('&', '<'), array('&amp;', '&lt;'), $matches[1]);
1357
-
1358
- return array(
1359
- 'extent' => strlen($matches[0]),
1360
- 'element' => array(
1361
- 'name' => 'a',
1362
- 'text' => $url,
1363
- 'attributes' => array(
1364
- 'href' => $url,
1365
- ),
1366
- ),
1367
- );
1368
- }
1369
- }
1370
-
1371
- # ~
1372
-
1373
- protected function unmarkedText($text)
1374
- {
1375
- if ($this->breaksEnabled)
1376
- {
1377
- $text = preg_replace('/[ ]*\n/', "<br />\n", $text);
1378
- }
1379
- else
1380
- {
1381
- $text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text);
1382
- $text = str_replace(" \n", "\n", $text);
1383
- }
1384
-
1385
- return $text;
1386
- }
1387
-
1388
- #
1389
- # Handlers
1390
- #
1391
-
1392
- protected function element(array $Element)
1393
- {
1394
- $markup = '<'.$Element['name'];
1395
-
1396
- if (isset($Element['attributes']))
1397
- {
1398
- foreach ($Element['attributes'] as $name => $value)
1399
- {
1400
- if ($value === null)
1401
- {
1402
- continue;
1403
- }
1404
-
1405
- $markup .= ' '.$name.'="'.$value.'"';
1406
- }
1407
- }
1408
-
1409
- if (isset($Element['text']))
1410
- {
1411
- $markup .= '>';
1412
-
1413
- if (isset($Element['handler']))
1414
- {
1415
- $markup .= $this->{$Element['handler']}($Element['text']);
1416
- }
1417
- else
1418
- {
1419
- $markup .= $Element['text'];
1420
- }
1421
-
1422
- $markup .= '</'.$Element['name'].'>';
1423
- }
1424
- else
1425
- {
1426
- $markup .= ' />';
1427
- }
1428
-
1429
- return $markup;
1430
- }
1431
-
1432
- protected function elements(array $Elements)
1433
- {
1434
- $markup = '';
1435
-
1436
- foreach ($Elements as $Element)
1437
- {
1438
- $markup .= "\n" . $this->element($Element);
1439
- }
1440
-
1441
- $markup .= "\n";
1442
-
1443
- return $markup;
1444
- }
1445
-
1446
- # ~
1447
-
1448
- protected function li($lines)
1449
- {
1450
- $markup = $this->lines($lines);
1451
-
1452
- $trimmedMarkup = trim($markup);
1453
-
1454
- if ( ! in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '<p>')
1455
- {
1456
- $markup = $trimmedMarkup;
1457
- $markup = substr($markup, 3);
1458
-
1459
- $position = strpos($markup, "</p>");
1460
-
1461
- $markup = substr_replace($markup, '', $position, 4);
1462
- }
1463
-
1464
- return $markup;
1465
- }
1466
-
1467
- #
1468
- # Deprecated Methods
1469
- #
1470
-
1471
- function parse($text)
1472
- {
1473
- $markup = $this->text($text);
1474
-
1475
- return $markup;
1476
- }
1477
-
1478
- #
1479
- # Static Methods
1480
- #
1481
-
1482
- static function instance($name = 'default')
1483
- {
1484
- if (isset(self::$instances[$name]))
1485
- {
1486
- return self::$instances[$name];
1487
- }
1488
-
1489
- $instance = new static();
1490
-
1491
- self::$instances[$name] = $instance;
1492
-
1493
- return $instance;
1494
- }
1495
-
1496
- private static $instances = array();
1497
-
1498
- #
1499
- # Fields
1500
- #
1501
-
1502
- protected $DefinitionData;
1503
-
1504
- #
1505
- # Read-Only
1506
-
1507
- protected $specialCharacters = array(
1508
- '\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|',
1509
- );
1510
-
1511
- protected $StrongRegex = array(
1512
- '*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s',
1513
- '_' => '/^__((?:\\\\_|[^_]|_[^_]*_)+?)__(?!_)/us',
1514
- );
1515
-
1516
- protected $EmRegex = array(
1517
- '*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s',
1518
- '_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us',
1519
- );
1520
-
1521
- protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*(?:\s*=\s*(?:[^"\'=<>`\s]+|"[^"]*"|\'[^\']*\'))?';
1522
-
1523
- protected $voidElements = array(
1524
- 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source',
1525
- );
1526
-
1527
- protected $textLevelElements = array(
1528
- 'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont',
1529
- 'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing',
1530
- 'i', 'rp', 'del', 'code', 'strike', 'marquee',
1531
- 'q', 'rt', 'ins', 'font', 'strong',
1532
- 's', 'tt', 'sub', 'mark',
1533
- 'u', 'xm', 'sup', 'nobr',
1534
- 'var', 'ruby',
1535
- 'wbr', 'span',
1536
- 'time',
1537
- );
1538
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/vendor/ParsedownLegacy.php DELETED
@@ -1,1535 +0,0 @@
1
- <?php
2
-
3
- #
4
- #
5
- # Parsedown
6
- # http://parsedown.org
7
- #
8
- # (c) Emanuil Rusev
9
- # http://erusev.com
10
- #
11
- # For the full license information, view the LICENSE file that was distributed
12
- # with this source code.
13
- #
14
- #
15
-
16
- class Parsedown
17
- {
18
- # ~
19
-
20
- const version = '1.5.0';
21
-
22
- # ~
23
-
24
- function text($text)
25
- {
26
- # make sure no definitions are set
27
- $this->DefinitionData = array();
28
-
29
- # standardize line breaks
30
- $text = str_replace(array("\r\n", "\r"), "\n", $text);
31
-
32
- # remove surrounding line breaks
33
- $text = trim($text, "\n");
34
-
35
- # split text into lines
36
- $lines = explode("\n", $text);
37
-
38
- # iterate through lines to identify blocks
39
- $markup = $this->lines($lines);
40
-
41
- # trim line breaks
42
- $markup = trim($markup, "\n");
43
-
44
- return $markup;
45
- }
46
-
47
- #
48
- # Setters
49
- #
50
-
51
- function setBreaksEnabled($breaksEnabled)
52
- {
53
- $this->breaksEnabled = $breaksEnabled;
54
-
55
- return $this;
56
- }
57
-
58
- protected $breaksEnabled;
59
-
60
- function setMarkupEscaped($markupEscaped)
61
- {
62
- $this->markupEscaped = $markupEscaped;
63
-
64
- return $this;
65
- }
66
-
67
- protected $markupEscaped;
68
-
69
- function setUrlsLinked($urlsLinked)
70
- {
71
- $this->urlsLinked = $urlsLinked;
72
-
73
- return $this;
74
- }
75
-
76
- protected $urlsLinked = true;
77
-
78
- #
79
- # Lines
80
- #
81
-
82
- protected $BlockTypes = array(
83
- '#' => array('Header'),
84
- '*' => array('Rule', 'List'),
85
- '+' => array('List'),
86
- '-' => array('SetextHeader', 'Table', 'Rule', 'List'),
87
- '0' => array('List'),
88
- '1' => array('List'),
89
- '2' => array('List'),
90
- '3' => array('List'),
91
- '4' => array('List'),
92
- '5' => array('List'),
93
- '6' => array('List'),
94
- '7' => array('List'),
95
- '8' => array('List'),
96
- '9' => array('List'),
97
- ':' => array('Table'),
98
- '<' => array('Comment', 'Markup'),
99
- '=' => array('SetextHeader'),
100
- '>' => array('Quote'),
101
- '[' => array('Reference'),
102
- '_' => array('Rule'),
103
- '`' => array('FencedCode'),
104
- '|' => array('Table'),
105
- '~' => array('FencedCode'),
106
- );
107
-
108
- # ~
109
-
110
- protected $DefinitionTypes = array(
111
- '[' => array('Reference'),
112
- );
113
-
114
- # ~
115
-
116
- protected $unmarkedBlockTypes = array(
117
- 'Code',
118
- );
119
-
120
- #
121
- # Blocks
122
- #
123
-
124
- private function lines(array $lines)
125
- {
126
- $CurrentBlock = null;
127
-
128
- foreach ($lines as $line)
129
- {
130
- if (chop($line) === '')
131
- {
132
- if (isset($CurrentBlock))
133
- {
134
- $CurrentBlock['interrupted'] = true;
135
- }
136
-
137
- continue;
138
- }
139
-
140
- if (strpos($line, "\t") !== false)
141
- {
142
- $parts = explode("\t", $line);
143
-
144
- $line = $parts[0];
145
-
146
- unset($parts[0]);
147
-
148
- foreach ($parts as $part)
149
- {
150
- $shortage = 4 - mb_strlen($line, 'utf-8') % 4;
151
-
152
- $line .= str_repeat(' ', $shortage);
153
- $line .= $part;
154
- }
155
- }
156
-
157
- $indent = 0;
158
-
159
- while (isset($line[$indent]) and $line[$indent] === ' ')
160
- {
161
- $indent ++;
162
- }
163
-
164
- $text = $indent > 0 ? substr($line, $indent) : $line;
165
-
166
- # ~
167
-
168
- $Line = array('body' => $line, 'indent' => $indent, 'text' => $text);
169
-
170
- # ~
171
-
172
- if (isset($CurrentBlock['incomplete']))
173
- {
174
- $Block = $this->{'block'.$CurrentBlock['type'].'Continue'}($Line, $CurrentBlock);
175
-
176
- if (isset($Block))
177
- {
178
- $CurrentBlock = $Block;
179
-
180
- continue;
181
- }
182
- else
183
- {
184
- if (method_exists($this, 'block'.$CurrentBlock['type'].'Complete'))
185
- {
186
- $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
187
- }
188
-
189
- unset($CurrentBlock['incomplete']);
190
- }
191
- }
192
-
193
- # ~
194
-
195
- $marker = $text[0];
196
-
197
- # ~
198
-
199
- $blockTypes = $this->unmarkedBlockTypes;
200
-
201
- if (isset($this->BlockTypes[$marker]))
202
- {
203
- foreach ($this->BlockTypes[$marker] as $blockType)
204
- {
205
- $blockTypes []= $blockType;
206
- }
207
- }
208
-
209
- #
210
- # ~
211
-
212
- foreach ($blockTypes as $blockType)
213
- {
214
- $Block = $this->{'block'.$blockType}($Line, $CurrentBlock);
215
-
216
- if (isset($Block))
217
- {
218
- $Block['type'] = $blockType;
219
-
220
- if ( ! isset($Block['identified']))
221
- {
222
- $Blocks []= $CurrentBlock;
223
-
224
- $Block['identified'] = true;
225
- }
226
-
227
- if (method_exists($this, 'block'.$blockType.'Continue'))
228
- {
229
- $Block['incomplete'] = true;
230
- }
231
-
232
- $CurrentBlock = $Block;
233
-
234
- continue 2;
235
- }
236
- }
237
-
238
- # ~
239
-
240
- if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted']))
241
- {
242
- $CurrentBlock['element']['text'] .= "\n".$text;
243
- }
244
- else
245
- {
246
- $Blocks []= $CurrentBlock;
247
-
248
- $CurrentBlock = $this->paragraph($Line);
249
-
250
- $CurrentBlock['identified'] = true;
251
- }
252
- }
253
-
254
- # ~
255
-
256
- if (isset($CurrentBlock['incomplete']) and method_exists($this, 'block'.$CurrentBlock['type'].'Complete'))
257
- {
258
- $CurrentBlock = $this->{'block'.$CurrentBlock['type'].'Complete'}($CurrentBlock);
259
- }
260
-
261
- # ~
262
-
263
- $Blocks []= $CurrentBlock;
264
-
265
- unset($Blocks[0]);
266
-
267
- # ~
268
-
269
- $markup = '';
270
-
271
- foreach ($Blocks as $Block)
272
- {
273
- if (isset($Block['hidden']))
274
- {
275
- continue;
276
- }
277
-
278
- $markup .= "\n";
279
- $markup .= isset($Block['markup']) ? $Block['markup'] : $this->element($Block['element']);
280
- }
281
-
282
- $markup .= "\n";
283
-
284
- # ~
285
-
286
- return $markup;
287
- }
288
-
289
- #
290
- # Code
291
-
292
- protected function blockCode($Line, $Block = null)
293
- {
294
- if (isset($Block) and ! isset($Block['type']) and ! isset($Block['interrupted']))
295
- {
296
- return;
297
- }
298
-
299
- if ($Line['indent'] >= 4)
300
- {
301
- $text = substr($Line['body'], 4);
302
-
303
- $Block = array(
304
- 'element' => array(
305
- 'name' => 'pre',
306
- 'handler' => 'element',
307
- 'text' => array(
308
- 'name' => 'code',
309
- 'text' => $text,
310
- ),
311
- ),
312
- );
313
-
314
- return $Block;
315
- }
316
- }
317
-
318
- protected function blockCodeContinue($Line, $Block)
319
- {
320
- if ($Line['indent'] >= 4)
321
- {
322
- if (isset($Block['interrupted']))
323
- {
324
- $Block['element']['text']['text'] .= "\n";
325
-
326
- unset($Block['interrupted']);
327
- }
328
-
329
- $Block['element']['text']['text'] .= "\n";
330
-
331
- $text = substr($Line['body'], 4);
332
-
333
- $Block['element']['text']['text'] .= $text;
334
-
335
- return $Block;
336
- }
337
- }
338
-
339
- protected function blockCodeComplete($Block)
340
- {
341
- $text = $Block['element']['text']['text'];
342
-
343
- $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
344
-
345
- $Block['element']['text']['text'] = $text;
346
-
347
- return $Block;
348
- }
349
-
350
- #
351
- # Comment
352
-
353
- protected function blockComment($Line)
354
- {
355
- if ($this->markupEscaped)
356
- {
357
- return;
358
- }
359
-
360
- if (isset($Line['text'][3]) and $Line['text'][3] === '-' and $Line['text'][2] === '-' and $Line['text'][1] === '!')
361
- {
362
- $Block = array(
363
- 'markup' => $Line['body'],
364
- );
365
-
366
- if (preg_match('/-->$/', $Line['text']))
367
- {
368
- $Block['closed'] = true;
369
- }
370
-
371
- return $Block;
372
- }
373
- }
374
-
375
- protected function blockCommentContinue($Line, array $Block)
376
- {
377
- if (isset($Block['closed']))
378
- {
379
- return;
380
- }
381
-
382
- $Block['markup'] .= "\n" . $Line['body'];
383
-
384
- if (preg_match('/-->$/', $Line['text']))
385
- {
386
- $Block['closed'] = true;
387
- }
388
-
389
- return $Block;
390
- }
391
-
392
- #
393
- # Fenced Code
394
-
395
- protected function blockFencedCode($Line)
396
- {
397
- if (preg_match('/^(['.$Line['text'][0].']{3,})[ ]*([\w-]+)?[ ]*$/', $Line['text'], $matches))
398
- {
399
- $Element = array(
400
- 'name' => 'code',
401
- 'text' => '',
402
- );
403
-
404
- if (isset($matches[2]))
405
- {
406
- $class = 'language-'.$matches[2];
407
-
408
- $Element['attributes'] = array(
409
- 'class' => $class,
410
- );
411
- }
412
-
413
- $Block = array(
414
- 'char' => $Line['text'][0],
415
- 'element' => array(
416
- 'name' => 'pre',
417
- 'handler' => 'element',
418
- 'text' => $Element,
419
- ),
420
- );
421
-
422
- return $Block;
423
- }
424
- }
425
-
426
- protected function blockFencedCodeContinue($Line, $Block)
427
- {
428
- if (isset($Block['complete']))
429
- {
430
- return;
431
- }
432
-
433
- if (isset($Block['interrupted']))
434
- {
435
- $Block['element']['text']['text'] .= "\n";
436
-
437
- unset($Block['interrupted']);
438
- }
439
-
440
- if (preg_match('/^'.$Block['char'].'{3,}[ ]*$/', $Line['text']))
441
- {
442
- $Block['element']['text']['text'] = substr($Block['element']['text']['text'], 1);
443
-
444
- $Block['complete'] = true;
445
-
446
- return $Block;
447
- }
448
-
449
- $Block['element']['text']['text'] .= "\n".$Line['body'];;
450
-
451
- return $Block;
452
- }
453
-
454
- protected function blockFencedCodeComplete($Block)
455
- {
456
- $text = $Block['element']['text']['text'];
457
-
458
- $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
459
-
460
- $Block['element']['text']['text'] = $text;
461
-
462
- return $Block;
463
- }
464
-
465
- #
466
- # Header
467
-
468
- protected function blockHeader($Line)
469
- {
470
- if (isset($Line['text'][1]))
471
- {
472
- $level = 1;
473
-
474
- while (isset($Line['text'][$level]) and $Line['text'][$level] === '#')
475
- {
476
- $level ++;
477
- }
478
-
479
- if ($level > 6)
480
- {
481
- return;
482
- }
483
-
484
- $text = trim($Line['text'], '# ');
485
-
486
- $Block = array(
487
- 'element' => array(
488
- 'name' => 'h' . min(6, $level),
489
- 'text' => $text,
490
- 'handler' => 'line',
491
- ),
492
- );
493
-
494
- return $Block;
495
- }
496
- }
497
-
498
- #
499
- # List
500
-
501
- protected function blockList($Line)
502
- {
503
- list($name, $pattern) = $Line['text'][0] <= '-' ? array('ul', '[*+-]') : array('ol', '[0-9]+[.]');
504
-
505
- if (preg_match('/^('.$pattern.'[ ]+)(.*)/', $Line['text'], $matches))
506
- {
507
- $Block = array(
508
- 'indent' => $Line['indent'],
509
- 'pattern' => $pattern,
510
- 'element' => array(
511
- 'name' => $name,
512
- 'handler' => 'elements',
513
- ),
514
- );
515
-
516
- $Block['li'] = array(
517
- 'name' => 'li',
518
- 'handler' => 'li',
519
- 'text' => array(
520
- $matches[2],
521
- ),
522
- );
523
-
524
- $Block['element']['text'] []= & $Block['li'];
525
-
526
- return $Block;
527
- }
528
- }
529
-
530
- protected function blockListContinue($Line, array $Block)
531
- {
532
- if ($Block['indent'] === $Line['indent'] and preg_match('/^'.$Block['pattern'].'(?:[ ]+(.*)|$)/', $Line['text'], $matches))
533
- {
534
- if (isset($Block['interrupted']))
535
- {
536
- $Block['li']['text'] []= '';
537
-
538
- unset($Block['interrupted']);
539
- }
540
-
541
- unset($Block['li']);
542
-
543
- $text = isset($matches[1]) ? $matches[1] : '';
544
-
545
- $Block['li'] = array(
546
- 'name' => 'li',
547
- 'handler' => 'li',
548
- 'text' => array(
549
- $text,
550
- ),
551
- );
552
-
553
- $Block['element']['text'] []= & $Block['li'];
554
-
555
- return $Block;
556
- }
557
-
558
- if ($Line['text'][0] === '[' and $this->blockReference($Line))
559
- {
560
- return $Block;
561
- }
562
-
563
- if ( ! isset($Block['interrupted']))
564
- {
565
- $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']);
566
-
567
- $Block['li']['text'] []= $text;
568
-
569
- return $Block;
570
- }
571
-
572
- if ($Line['indent'] > 0)
573
- {
574
- $Block['li']['text'] []= '';
575
-
576
- $text = preg_replace('/^[ ]{0,4}/', '', $Line['body']);
577
-
578
- $Block['li']['text'] []= $text;
579
-
580
- unset($Block['interrupted']);
581
-
582
- return $Block;
583
- }
584
- }
585
-
586
- #
587
- # Quote
588
-
589
- protected function blockQuote($Line)
590
- {
591
- if (preg_match('/^>[ ]?(.*)/', $Line['text'], $matches))
592
- {
593
- $Block = array(
594
- 'element' => array(
595
- 'name' => 'blockquote',
596
- 'handler' => 'lines',
597
- 'text' => (array) $matches[1],
598
- ),
599
- );
600
-
601
- return $Block;
602
- }
603
- }
604
-
605
- protected function blockQuoteContinue($Line, array $Block)
606
- {
607
- if ($Line['text'][0] === '>' and preg_match('/^>[ ]?(.*)/', $Line['text'], $matches))
608
- {
609
- if (isset($Block['interrupted']))
610
- {
611
- $Block['element']['text'] []= '';
612
-
613
- unset($Block['interrupted']);
614
- }
615
-
616
- $Block['element']['text'] []= $matches[1];
617
-
618
- return $Block;
619
- }
620
-
621
- if ( ! isset($Block['interrupted']))
622
- {
623
- $Block['element']['text'] []= $Line['text'];
624
-
625
- return $Block;
626
- }
627
- }
628
-
629
- #
630
- # Rule
631
-
632
- protected function blockRule($Line)
633
- {
634
- if (preg_match('/^(['.$Line['text'][0].'])([ ]*\1){2,}[ ]*$/', $Line['text']))
635
- {
636
- $Block = array(
637
- 'element' => array(
638
- 'name' => 'hr'
639
- ),
640
- );
641
-
642
- return $Block;
643
- }
644
- }
645
-
646
- #
647
- # Setext
648
-
649
- protected function blockSetextHeader($Line, array $Block = null)
650
- {
651
- if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
652
- {
653
- return;
654
- }
655
-
656
- if (chop($Line['text'], $Line['text'][0]) === '')
657
- {
658
- $Block['element']['name'] = $Line['text'][0] === '=' ? 'h1' : 'h2';
659
-
660
- return $Block;
661
- }
662
- }
663
-
664
- #
665
- # Markup
666
-
667
- protected function blockMarkup($Line)
668
- {
669
- if ($this->markupEscaped)
670
- {
671
- return;
672
- }
673
-
674
- if (preg_match('/^<(\w*)(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*(\/)?>/', $Line['text'], $matches))
675
- {
676
- if (in_array($matches[1], $this->textLevelElements))
677
- {
678
- return;
679
- }
680
-
681
- $Block = array(
682
- 'name' => $matches[1],
683
- 'depth' => 0,
684
- 'markup' => $Line['text'],
685
- );
686
-
687
- $length = strlen($matches[0]);
688
-
689
- $remainder = substr($Line['text'], $length);
690
-
691
- if (trim($remainder) === '')
692
- {
693
- if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
694
- {
695
- $Block['closed'] = true;
696
-
697
- $Block['void'] = true;
698
- }
699
- }
700
- else
701
- {
702
- if (isset($matches[2]) or in_array($matches[1], $this->voidElements))
703
- {
704
- return;
705
- }
706
-
707
- if (preg_match('/<\/'.$matches[1].'>[ ]*$/i', $remainder))
708
- {
709
- $Block['closed'] = true;
710
- }
711
- }
712
-
713
- return $Block;
714
- }
715
- }
716
-
717
- protected function blockMarkupContinue($Line, array $Block)
718
- {
719
- if (isset($Block['closed']))
720
- {
721
- return;
722
- }
723
-
724
- if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open
725
- {
726
- $Block['depth'] ++;
727
- }
728
-
729
- if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close
730
- {
731
- if ($Block['depth'] > 0)
732
- {
733
- $Block['depth'] --;
734
- }
735
- else
736
- {
737
- $Block['closed'] = true;
738
- }
739
-
740
- $Block['markup'] .= $matches[1];
741
- }
742
-
743
- if (isset($Block['interrupted']))
744
- {
745
- $Block['markup'] .= "\n";
746
-
747
- unset($Block['interrupted']);
748
- }
749
-
750
- $Block['markup'] .= "\n".$Line['body'];
751
-
752
- return $Block;
753
- }
754
-
755
- #
756
- # Reference
757
-
758
- protected function blockReference($Line)
759
- {
760
- if (preg_match('/^\[(.+?)\]:[ ]*<?(\S+?)>?(?:[ ]+["\'(](.+)["\')])?[ ]*$/', $Line['text'], $matches))
761
- {
762
- $id = strtolower($matches[1]);
763
-
764
- $Data = array(
765
- 'url' => $matches[2],
766
- 'title' => null,
767
- );
768
-
769
- if (isset($matches[3]))
770
- {
771
- $Data['title'] = $matches[3];
772
- }
773
-
774
- $this->DefinitionData['Reference'][$id] = $Data;
775
-
776
- $Block = array(
777
- 'hidden' => true,
778
- );
779
-
780
- return $Block;
781
- }
782
- }
783
-
784
- #
785
- # Table
786
-
787
- protected function blockTable($Line, array $Block = null)
788
- {
789
- if ( ! isset($Block) or isset($Block['type']) or isset($Block['interrupted']))
790
- {
791
- return;
792
- }
793
-
794
- if (strpos($Block['element']['text'], '|') !== false and chop($Line['text'], ' -:|') === '')
795
- {
796
- $alignments = array();
797
-
798
- $divider = $Line['text'];
799
-
800
- $divider = trim($divider);
801
- $divider = trim($divider, '|');
802
-
803
- $dividerCells = explode('|', $divider);
804
-
805
- foreach ($dividerCells as $dividerCell)
806
- {
807
- $dividerCell = trim($dividerCell);
808
-
809
- if ($dividerCell === '')
810
- {
811
- continue;
812
- }
813
-
814
- $alignment = null;
815
-
816
- if ($dividerCell[0] === ':')
817
- {
818
- $alignment = 'left';
819
- }
820
-
821
- if (substr($dividerCell, - 1) === ':')
822
- {
823
- $alignment = $alignment === 'left' ? 'center' : 'right';
824
- }
825
-
826
- $alignments []= $alignment;
827
- }
828
-
829
- # ~
830
-
831
- $HeaderElements = array();
832
-
833
- $header = $Block['element']['text'];
834
-
835
- $header = trim($header);
836
- $header = trim($header, '|');
837
-
838
- $headerCells = explode('|', $header);
839
-
840
- foreach ($headerCells as $index => $headerCell)
841
- {
842
- $headerCell = trim($headerCell);
843
-
844
- $HeaderElement = array(
845
- 'name' => 'th',
846
- 'text' => $headerCell,
847
- 'handler' => 'line',
848
- );
849
-
850
- if (isset($alignments[$index]))
851
- {
852
- $alignment = $alignments[$index];
853
-
854
- $HeaderElement['attributes'] = array(
855
- 'style' => 'text-align: '.$alignment.';',
856
- );
857
- }
858
-
859
- $HeaderElements []= $HeaderElement;
860
- }
861
-
862
- # ~
863
-
864
- $Block = array(
865
- 'alignments' => $alignments,
866
- 'identified' => true,
867
- 'element' => array(
868
- 'name' => 'table',
869
- 'handler' => 'elements',
870
- ),
871
- );
872
-
873
- $Block['element']['text'] []= array(
874
- 'name' => 'thead',
875
- 'handler' => 'elements',
876
- );
877
-
878
- $Block['element']['text'] []= array(
879
- 'name' => 'tbody',
880
- 'handler' => 'elements',
881
- 'text' => array(),
882
- );
883
-
884
- $Block['element']['text'][0]['text'] []= array(
885
- 'name' => 'tr',
886
- 'handler' => 'elements',
887
- 'text' => $HeaderElements,
888
- );
889
-
890
- return $Block;
891
- }
892
- }
893
-
894
- protected function blockTableContinue($Line, array $Block)
895
- {
896
- if (isset($Block['interrupted']))
897
- {
898
- return;
899
- }
900
-
901
- if ($Line['text'][0] === '|' or strpos($Line['text'], '|'))
902
- {
903
- $Elements = array();
904
-
905
- $row = $Line['text'];
906
-
907
- $row = trim($row);
908
- $row = trim($row, '|');
909
-
910
- preg_match_all('/(?:(\\\\[|])|[^|`]|`[^`]+`|`)+/', $row, $matches);
911
-
912
- foreach ($matches[0] as $index => $cell)
913
- {
914
- $cell = trim($cell);
915
-
916
- $Element = array(
917
- 'name' => 'td',
918
- 'handler' => 'line',
919
- 'text' => $cell,
920
- );
921
-
922
- if (isset($Block['alignments'][$index]))
923
- {
924
- $Element['attributes'] = array(
925
- 'style' => 'text-align: '.$Block['alignments'][$index].';',
926
- );
927
- }
928
-
929
- $Elements []= $Element;
930
- }
931
-
932
- $Element = array(
933
- 'name' => 'tr',
934
- 'handler' => 'elements',
935
- 'text' => $Elements,
936
- );
937
-
938
- $Block['element']['text'][1]['text'] []= $Element;
939
-
940
- return $Block;
941
- }
942
- }
943
-
944
- #
945
- # ~
946
- #
947
-
948
- protected function paragraph($Line)
949
- {
950
- $Block = array(
951
- 'element' => array(
952
- 'name' => 'p',
953
- 'text' => $Line['text'],
954
- 'handler' => 'line',
955
- ),
956
- );
957
-
958
- return $Block;
959
- }
960
-
961
- #
962
- # Inline Elements
963
- #
964
-
965
- protected $InlineTypes = array(
966
- '"' => array('SpecialCharacter'),
967
- '!' => array('Image'),
968
- '&' => array('SpecialCharacter'),
969
- '*' => array('Emphasis'),
970
- ':' => array('Url'),
971
- '<' => array('UrlTag', 'EmailTag', 'Markup', 'SpecialCharacter'),
972
- '>' => array('SpecialCharacter'),
973
- '[' => array('Link'),
974
- '_' => array('Emphasis'),
975
- '`' => array('Code'),
976
- '~' => array('Strikethrough'),
977
- '\\' => array('EscapeSequence'),
978
- );
979
-
980
- # ~
981
-
982
- protected $inlineMarkerList = '!"*_&[:<>`~\\';
983
-
984
- #
985
- # ~
986
- #
987
-
988
- public function line($text)
989
- {
990
- $markup = '';
991
-
992
- $unexaminedText = $text;
993
-
994
- $markerPosition = 0;
995
-
996
- while ($excerpt = strpbrk($unexaminedText, $this->inlineMarkerList))
997
- {
998
- $marker = $excerpt[0];
999
-
1000
- $markerPosition += strpos($unexaminedText, $marker);
1001
-
1002
- $Excerpt = array('text' => $excerpt, 'context' => $text);
1003
-
1004
- foreach ($this->InlineTypes[$marker] as $inlineType)
1005
- {
1006
- $Inline = $this->{'inline'.$inlineType}($Excerpt);
1007
-
1008
- if ( ! isset($Inline))
1009
- {
1010
- continue;
1011
- }
1012
-
1013
- if (isset($Inline['position']) and $Inline['position'] > $markerPosition) # position is ahead of marker
1014
- {
1015
- continue;
1016
- }
1017
-
1018
- if ( ! isset($Inline['position']))
1019
- {
1020
- $Inline['position'] = $markerPosition;
1021
- }
1022
-
1023
- $unmarkedText = substr($text, 0, $Inline['position']);
1024
-
1025
- $markup .= $this->unmarkedText($unmarkedText);
1026
-
1027
- $markup .= isset($Inline['markup']) ? $Inline['markup'] : $this->element($Inline['element']);
1028
-
1029
- $text = substr($text, $Inline['position'] + $Inline['extent']);
1030
-
1031
- $unexaminedText = $text;
1032
-
1033
- $markerPosition = 0;
1034
-
1035
- continue 2;
1036
- }
1037
-
1038
- $unexaminedText = substr($excerpt, 1);
1039
-
1040
- $markerPosition ++;
1041
- }
1042
-
1043
- $markup .= $this->unmarkedText($text);
1044
-
1045
- return $markup;
1046
- }
1047
-
1048
- #
1049
- # ~
1050
- #
1051
-
1052
- protected function inlineCode($Excerpt)
1053
- {
1054
- $marker = $Excerpt['text'][0];
1055
-
1056
- if (preg_match('/^('.$marker.'+)[ ]*(.+?)[ ]*(?<!'.$marker.')\1(?!'.$marker.')/s', $Excerpt['text'], $matches))
1057
- {
1058
- $text = $matches[2];
1059
- $text = htmlspecialchars($text, ENT_NOQUOTES, 'UTF-8');
1060
- $text = preg_replace("/[ ]*\n/", ' ', $text);
1061
-
1062
- return array(
1063
- 'extent' => strlen($matches[0]),
1064
- 'element' => array(
1065
- 'name' => 'code',
1066
- 'text' => $text,
1067
- ),
1068
- );
1069
- }
1070
- }
1071
-
1072
- protected function inlineEmailTag($Excerpt)
1073
- {
1074
- if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<((mailto:)?\S+?@\S+?)>/i', $Excerpt['text'], $matches))
1075
- {
1076
- $url = $matches[1];
1077
-
1078
- if ( ! isset($matches[2]))
1079
- {
1080
- $url = 'mailto:' . $url;
1081
- }
1082
-
1083
- return array(
1084
- 'extent' => strlen($matches[0]),
1085
- 'element' => array(
1086
- 'name' => 'a',
1087
- 'text' => $matches[1],
1088
- 'attributes' => array(
1089
- 'href' => $url,
1090
- ),
1091
- ),
1092
- );
1093
- }
1094
- }
1095
-
1096
- protected function inlineEmphasis($Excerpt)
1097
- {
1098
- if ( ! isset($Excerpt['text'][1]))
1099
- {
1100
- return;
1101
- }
1102
-
1103
- $marker = $Excerpt['text'][0];
1104
-
1105
- if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches))
1106
- {
1107
- $emphasis = 'strong';
1108
- }
1109
- elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches))
1110
- {
1111
- $emphasis = 'em';
1112
- }
1113
- else
1114
- {
1115
- return;
1116
- }
1117
-
1118
- return array(
1119
- 'extent' => strlen($matches[0]),
1120
- 'element' => array(
1121
- 'name' => $emphasis,
1122
- 'handler' => 'line',
1123
- 'text' => $matches[1],
1124
- ),
1125
- );
1126
- }
1127
-
1128
- protected function inlineEscapeSequence($Excerpt)
1129
- {
1130
- if (isset($Excerpt['text'][1]) and in_array($Excerpt['text'][1], $this->specialCharacters))
1131
- {
1132
- return array(
1133
- 'markup' => $Excerpt['text'][1],
1134
- 'extent' => 2,
1135
- );
1136
- }
1137
- }
1138
-
1139
- protected function inlineImage($Excerpt)
1140
- {
1141
- if ( ! isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[')
1142
- {
1143
- return;
1144
- }
1145
-
1146
- $Excerpt['text']= substr($Excerpt['text'], 1);
1147
-
1148
- $Link = $this->inlineLink($Excerpt);
1149
-
1150
- if ($Link === null)
1151
- {
1152
- return;
1153
- }
1154
-
1155
- $Inline = array(
1156
- 'extent' => $Link['extent'] + 1,
1157
- 'element' => array(
1158
- 'name' => 'img',
1159
- 'attributes' => array(
1160
- 'src' => $Link['element']['attributes']['href'],
1161
- 'alt' => $Link['element']['text'],
1162
- ),
1163
- ),
1164
- );
1165
-
1166
- $Inline['element']['attributes'] += $Link['element']['attributes'];
1167
-
1168
- unset($Inline['element']['attributes']['href']);
1169
-
1170
- return $Inline;
1171
- }
1172
-
1173
- protected function inlineLink($Excerpt)
1174
- {
1175
- $Element = array(
1176
- 'name' => 'a',
1177
- 'handler' => 'line',
1178
- 'text' => null,
1179
- 'attributes' => array(
1180
- 'href' => null,
1181
- 'title' => null,
1182
- ),
1183
- );
1184
-
1185
- $extent = 0;
1186
-
1187
- $remainder = $Excerpt['text'];
1188
-
1189
- if (preg_match('/\[((?:[^][]|(?R))*)\]/', $remainder, $matches))
1190
- {
1191
- $Element['text'] = $matches[1];
1192
-
1193
- $extent += strlen($matches[0]);
1194
-
1195
- $remainder = substr($remainder, $extent);
1196
- }
1197
- else
1198
- {
1199
- return;
1200
- }
1201
-
1202
- if (preg_match('/^[(]((?:[^ (]|[(][^ )]+[)])+)(?:[ ]+("[^"]+"|\'[^\']+\'))?[)]/', $remainder, $matches))
1203
- {
1204
- $Element['attributes']['href'] = $matches[1];
1205
-
1206
- if (isset($matches[2]))
1207
- {
1208
- $Element['attributes']['title'] = substr($matches[2], 1, - 1);
1209
- }
1210
-
1211
- $extent += strlen($matches[0]);
1212
- }
1213
- else
1214
- {
1215
- if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches))
1216
- {
1217
- $definition = $matches[1] ? $matches[1] : $Element['text'];
1218
- $definition = strtolower($definition);
1219
-
1220
- $extent += strlen($matches[0]);
1221
- }
1222
- else
1223
- {
1224
- $definition = strtolower($Element['text']);
1225
- }
1226
-
1227
- if ( ! isset($this->DefinitionData['Reference'][$definition]))
1228
- {
1229
- return;
1230
- }
1231
-
1232
- $Definition = $this->DefinitionData['Reference'][$definition];
1233
-
1234
- $Element['attributes']['href'] = $Definition['url'];
1235
- $Element['attributes']['title'] = $Definition['title'];
1236
- }
1237
-
1238
- $Element['attributes']['href'] = str_replace(array('&', '<'), array('&amp;', '&lt;'), $Element['attributes']['href']);
1239
-
1240
- return array(
1241
- 'extent' => $extent,
1242
- 'element' => $Element,
1243
- );
1244
- }
1245
-
1246
- protected function inlineMarkup($Excerpt)
1247
- {
1248
- if ($this->markupEscaped or strpos($Excerpt['text'], '>') === false)
1249
- {
1250
- return;
1251
- }
1252
-
1253
- if ($Excerpt['text'][1] === '/' and preg_match('/^<\/\w*[ ]*>/s', $Excerpt['text'], $matches))
1254
- {
1255
- return array(
1256
- 'markup' => $matches[0],
1257
- 'extent' => strlen($matches[0]),
1258
- );
1259
- }
1260
-
1261
- if ($Excerpt['text'][1] === '!' and preg_match('/^<!---?[^>-](?:-?[^-])*-->/s', $Excerpt['text'], $matches))
1262
- {
1263
- return array(
1264
- 'markup' => $matches[0],
1265
- 'extent' => strlen($matches[0]),
1266
- );
1267
- }
1268
-
1269
- if ($Excerpt['text'][1] !== ' ' and preg_match('/^<\w*(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*\/?>/s', $Excerpt['text'], $matches))
1270
- {
1271
- return array(
1272
- 'markup' => $matches[0],
1273
- 'extent' => strlen($matches[0]),
1274
- );
1275
- }
1276
- }
1277
-
1278
- protected function inlineSpecialCharacter($Excerpt)
1279
- {
1280
- if ($Excerpt['text'][0] === '&' and ! preg_match('/^&#?\w+;/', $Excerpt['text']))
1281
- {
1282
- return array(
1283
- 'markup' => '&amp;',
1284
- 'extent' => 1,
1285
- );
1286
- }
1287
-
1288
- $SpecialCharacter = array('>' => 'gt', '<' => 'lt', '"' => 'quot');
1289
-
1290
- if (isset($SpecialCharacter[$Excerpt['text'][0]]))
1291
- {
1292
- return array(
1293
- 'markup' => '&'.$SpecialCharacter[$Excerpt['text'][0]].';',
1294
- 'extent' => 1,
1295
- );
1296
- }
1297
- }
1298
-
1299
- protected function inlineStrikethrough($Excerpt)
1300
- {
1301
- if ( ! isset($Excerpt['text'][1]))
1302
- {
1303
- return;
1304
- }
1305
-
1306
- if ($Excerpt['text'][1] === '~' and preg_match('/^~~(?=\S)(.+?)(?<=\S)~~/', $Excerpt['text'], $matches))
1307
- {
1308
- return array(
1309
- 'extent' => strlen($matches[0]),
1310
- 'element' => array(
1311
- 'name' => 'del',
1312
- 'text' => $matches[1],
1313
- 'handler' => 'line',
1314
- ),
1315
- );
1316
- }
1317
- }
1318
-
1319
- protected function inlineUrl($Excerpt)
1320
- {
1321
- if ($this->urlsLinked !== true or ! isset($Excerpt['text'][2]) or $Excerpt['text'][2] !== '/')
1322
- {
1323
- return;
1324
- }
1325
-
1326
- if (preg_match('/\bhttps?:[\/]{2}[^\s<]+\b\/*/ui', $Excerpt['context'], $matches, PREG_OFFSET_CAPTURE))
1327
- {
1328
- $Inline = array(
1329
- 'extent' => strlen($matches[0][0]),
1330
- 'position' => $matches[0][1],
1331
- 'element' => array(
1332
- 'name' => 'a',
1333
- 'text' => $matches[0][0],
1334
- 'attributes' => array(
1335
- 'href' => $matches[0][0],
1336
- ),
1337
- ),
1338
- );
1339
-
1340
- return $Inline;
1341
- }
1342
- }
1343
-
1344
- protected function inlineUrlTag($Excerpt)
1345
- {
1346
- if (strpos($Excerpt['text'], '>') !== false and preg_match('/^<(\w+:\/{2}[^ >]+)>/i', $Excerpt['text'], $matches))
1347
- {
1348
- $url = str_replace(array('&', '<'), array('&amp;', '&lt;'), $matches[1]);
1349
-
1350
- return array(
1351
- 'extent' => strlen($matches[0]),
1352
- 'element' => array(
1353
- 'name' => 'a',
1354
- 'text' => $url,
1355
- 'attributes' => array(
1356
- 'href' => $url,
1357
- ),
1358
- ),
1359
- );
1360
- }
1361
- }
1362
-
1363
- #
1364
- # ~
1365
-
1366
- protected $unmarkedInlineTypes = array("\n" => 'Break', '://' => 'Url');
1367
-
1368
- # ~
1369
-
1370
- protected function unmarkedText($text)
1371
- {
1372
- if ($this->breaksEnabled)
1373
- {
1374
- $text = preg_replace('/[ ]*\n/', "<br />\n", $text);
1375
- }
1376
- else
1377
- {
1378
- $text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text);
1379
- $text = str_replace(" \n", "\n", $text);
1380
- }
1381
-
1382
- return $text;
1383
- }
1384
-
1385
- #
1386
- # Handlers
1387
- #
1388
-
1389
- protected function element(array $Element)
1390
- {
1391
- $markup = '<'.$Element['name'];
1392
-
1393
- if (isset($Element['attributes']))
1394
- {
1395
- foreach ($Element['attributes'] as $name => $value)
1396
- {
1397
- if ($value === null)
1398
- {
1399
- continue;
1400
- }
1401
-
1402
- $markup .= ' '.$name.'="'.$value.'"';
1403
- }
1404
- }
1405
-
1406
- if (isset($Element['text']))
1407
- {
1408
- $markup .= '>';
1409
-
1410
- if (isset($Element['handler']))
1411
- {
1412
- $markup .= $this->{$Element['handler']}($Element['text']);
1413
- }
1414
- else
1415
- {
1416
- $markup .= $Element['text'];
1417
- }
1418
-
1419
- $markup .= '</'.$Element['name'].'>';
1420
- }
1421
- else
1422
- {
1423
- $markup .= ' />';
1424
- }
1425
-
1426
- return $markup;
1427
- }
1428
-
1429
- protected function elements(array $Elements)
1430
- {
1431
- $markup = '';
1432
-
1433
- foreach ($Elements as $Element)
1434
- {
1435
- $markup .= "\n" . $this->element($Element);
1436
- }
1437
-
1438
- $markup .= "\n";
1439
-
1440
- return $markup;
1441
- }
1442
-
1443
- # ~
1444
-
1445
- protected function li($lines)
1446
- {
1447
- $markup = $this->lines($lines);
1448
-
1449
- $trimmedMarkup = trim($markup);
1450
-
1451
- if ( ! in_array('', $lines) and substr($trimmedMarkup, 0, 3) === '<p>')
1452
- {
1453
- $markup = $trimmedMarkup;
1454
- $markup = substr($markup, 3);
1455
-
1456
- $position = strpos($markup, "</p>");
1457
-
1458
- $markup = substr_replace($markup, '', $position, 4);
1459
- }
1460
-
1461
- return $markup;
1462
- }
1463
-
1464
- #
1465
- # Deprecated Methods
1466
- #
1467
-
1468
- function parse($text)
1469
- {
1470
- $markup = $this->text($text);
1471
-
1472
- return $markup;
1473
- }
1474
-
1475
- #
1476
- # Static Methods
1477
- #
1478
-
1479
- static function instance($name = 'default')
1480
- {
1481
- if (isset(self::$instances[$name]))
1482
- {
1483
- return self::$instances[$name];
1484
- }
1485
-
1486
- $instance = new self();
1487
-
1488
- self::$instances[$name] = $instance;
1489
-
1490
- return $instance;
1491
- }
1492
-
1493
- private static $instances = array();
1494
-
1495
- #
1496
- # Fields
1497
- #
1498
-
1499
- protected $DefinitionData;
1500
-
1501
- #
1502
- # Read-Only
1503
-
1504
- protected $specialCharacters = array(
1505
- '\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '>', '#', '+', '-', '.', '!', '|',
1506
- );
1507
-
1508
- protected $StrongRegex = array(
1509
- '*' => '/^[*]{2}((?:\\\\\*|[^*]|[*][^*]*[*])+?)[*]{2}(?![*])/s',
1510
- '_' => '/^__((?:\\\\_|[^_]|_[^_]*_)+?)__(?!_)/us',
1511
- );
1512
-
1513
- protected $EmRegex = array(
1514
- '*' => '/^[*]((?:\\\\\*|[^*]|[*][*][^*]+?[*][*])+?)[*](?![*])/s',
1515
- '_' => '/^_((?:\\\\_|[^_]|__[^_]*__)+?)_(?!_)\b/us',
1516
- );
1517
-
1518
- protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*(?:\s*=\s*(?:[^"\'=<>`\s]+|"[^"]*"|\'[^\']*\'))?';
1519
-
1520
- protected $voidElements = array(
1521
- 'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source',
1522
- );
1523
-
1524
- protected $textLevelElements = array(
1525
- 'a', 'br', 'bdo', 'abbr', 'blink', 'nextid', 'acronym', 'basefont',
1526
- 'b', 'em', 'big', 'cite', 'small', 'spacer', 'listing',
1527
- 'i', 'rp', 'del', 'code', 'strike', 'marquee',
1528
- 'q', 'rt', 'ins', 'font', 'strong',
1529
- 's', 'tt', 'sub', 'mark',
1530
- 'u', 'xm', 'sup', 'nobr',
1531
- 'var', 'ruby',
1532
- 'wbr', 'span',
1533
- 'time',
1534
- );
1535
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
plugin-update-checker/vendor/readme-parser.php DELETED
@@ -1,337 +0,0 @@
1
- <?php
2
-
3
- if ( !class_exists('PucReadmeParser', false) ):
4
-
5
- /**
6
- * This is a slightly modified version of github.com/markjaquith/WordPress-Plugin-Readme-Parser
7
- * It uses Parsedown instead of the "Markdown Extra" parser.
8
- */
9
-
10
- class PucReadmeParser {
11
-
12
- function __construct() {
13
- // This space intentionally blank
14
- }
15
-
16
- function parse_readme( $file ) {
17
- $file_contents = @implode('', @file($file));
18
- return $this->parse_readme_contents( $file_contents );
19
- }
20
-
21
- function parse_readme_contents( $file_contents ) {
22
- $file_contents = str_replace(array("\r\n", "\r"), "\n", $file_contents);
23
- $file_contents = trim($file_contents);
24
- if ( 0 === strpos( $file_contents, "\xEF\xBB\xBF" ) )
25
- $file_contents = substr( $file_contents, 3 );
26
-
27
- // Markdown transformations
28
- $file_contents = preg_replace( "|^###([^#]+)#*?\s*?\n|im", '=$1='."\n", $file_contents );
29
- $file_contents = preg_replace( "|^##([^#]+)#*?\s*?\n|im", '==$1=='."\n", $file_contents );
30
- $file_contents = preg_replace( "|^#([^#]+)#*?\s*?\n|im", '===$1==='."\n", $file_contents );
31
-
32
- // === Plugin Name ===
33
- // Must be the very first thing.
34
- if ( !preg_match('|^===(.*)===|', $file_contents, $_name) )
35
- return array(); // require a name
36
- $name = trim($_name[1], '=');
37
- $name = $this->sanitize_text( $name );
38
-
39
- $file_contents = $this->chop_string( $file_contents, $_name[0] );
40
-
41
-
42
- // Requires at least: 1.5
43
- if ( preg_match('|Requires at least:(.*)|i', $file_contents, $_requires_at_least) )
44
- $requires_at_least = $this->sanitize_text($_requires_at_least[1]);
45
- else
46
- $requires_at_least = NULL;
47
-
48
-
49
- // Tested up to: 2.1
50
- if ( preg_match('|Tested up to:(.*)|i', $file_contents, $_tested_up_to) )
51
- $tested_up_to = $this->sanitize_text( $_tested_up_to[1] );
52
- else
53
- $tested_up_to = NULL;
54
-
55
-
56
- // Stable tag: 10.4-ride-the-fire-eagle-danger-day
57
- if ( preg_match('|Stable tag:(.*)|i', $file_contents, $_stable_tag) )
58
- $stable_tag = $this->sanitize_text( $_stable_tag[1] );
59
- else
60
- $stable_tag = NULL; // we assume trunk, but don't set it here to tell the difference between specified trunk and default trunk
61
-
62
-
63
- // Tags: some tag, another tag, we like tags
64
- if ( preg_match('|Tags:(.*)|i', $file_contents, $_tags) ) {
65
- $tags = preg_split('|,[\s]*?|', trim($_tags[1]));
66
- foreach ( array_keys($tags) as $t )
67
- $tags[$t] = $this->sanitize_text( $tags[$t] );
68
- } else {
69
- $tags = array();
70
- }
71
-
72
-
73
- // Contributors: markjaquith, mdawaffe, zefrank
74
- $contributors = array();
75
- if ( preg_match('|Contributors:(.*)|i', $file_contents, $_contributors) ) {
76
- $temp_contributors = preg_split('|,[\s]*|', trim($_contributors[1]));
77
- foreach ( array_keys($temp_contributors) as $c ) {
78
- $tmp_sanitized = $this->user_sanitize( $temp_contributors[$c] );
79
- if ( strlen(trim($tmp_sanitized)) > 0 )
80
- $contributors[$c] = $tmp_sanitized;
81
- unset($tmp_sanitized);
82
- }
83
- }
84
-
85
-
86
- // Donate Link: URL
87
- if ( preg_match('|Donate link:(.*)|i', $file_contents, $_donate_link) )
88
- $donate_link = esc_url( $_donate_link[1] );
89
- else
90
- $donate_link = NULL;
91
-
92
-
93
- // togs, conts, etc are optional and order shouldn't matter. So we chop them only after we've grabbed their values.
94
- foreach ( array('tags', 'contributors', 'requires_at_least', 'tested_up_to', 'stable_tag', 'donate_link') as $chop ) {
95
- if ( $$chop ) {
96
- $_chop = '_' . $chop;
97
- $file_contents = $this->chop_string( $file_contents, ${$_chop}[0] );
98
- }
99
- }
100
-
101
- $file_contents = trim($file_contents);
102
-
103
-
104
- // short-description fu
105
- if ( !preg_match('/(^(.*?))^[\s]*=+?[\s]*.+?[\s]*=+?/ms', $file_contents, $_short_description) )
106
- $_short_description = array( 1 => &$file_contents, 2 => &$file_contents );
107
- $short_desc_filtered = $this->sanitize_text( $_short_description[2] );
108
- $short_desc_length = strlen($short_desc_filtered);
109
- $short_description = substr($short_desc_filtered, 0, 150);
110
- if ( $short_desc_length > strlen($short_description) )
111
- $truncated = true;
112
- else
113
- $truncated = false;
114
- if ( $_short_description[1] )
115
- $file_contents = $this->chop_string( $file_contents, $_short_description[1] ); // yes, the [1] is intentional
116
-
117
- // == Section ==
118
- // Break into sections
119
- // $_sections[0] will be the title of the first section, $_sections[1] will be the content of the first section
120
- // the array alternates from there: title2, content2, title3, content3... and so forth
121
- $_sections = preg_split('/^[\s]*==[\s]*(.+?)[\s]*==/m', $file_contents, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
122
-
123
- $sections = array();
124
- for ( $i=1; $i <= count($_sections); $i +=2 ) {
125
- $_sections[$i] = preg_replace('/(^[\s]*)=[\s]+(.+?)[\s]+=/m', '$1<h4>$2</h4>', $_sections[$i]);
126
- $_sections[$i] = $this->filter_text( $_sections[$i], true );
127
- $title = $this->sanitize_text( $_sections[$i-1] );
128
- $sections[str_replace(' ', '_', strtolower($title))] = array('title' => $title, 'content' => $_sections[$i]);
129
- }
130
-
131
-
132
- // Special sections
133
- // This is where we nab our special sections, so we can enforce their order and treat them differently, if needed
134
- // upgrade_notice is not a section, but parse it like it is for now
135
- $final_sections = array();
136
- foreach ( array('description', 'installation', 'frequently_asked_questions', 'screenshots', 'changelog', 'change_log', 'upgrade_notice') as $special_section ) {
137
- if ( isset($sections[$special_section]) ) {
138
- $final_sections[$special_section] = $sections[$special_section]['content'];
139
- unset($sections[$special_section]);
140
- }
141
- }
142
- if ( isset($final_sections['change_log']) && empty($final_sections['changelog']) )
143
- $final_sections['changelog'] = $final_sections['change_log'];
144
-
145
-
146
- $final_screenshots = array();
147
- if ( isset($final_sections['screenshots']) ) {
148
- preg_match_all('|<li>(.*?)</li>|s', $final_sections['screenshots'], $screenshots, PREG_SET_ORDER);
149
- if ( $screenshots ) {
150
- foreach ( (array) $screenshots as $ss )
151
- $final_screenshots[] = $ss[1];
152
- }
153
- }
154
-
155
- // Parse the upgrade_notice section specially:
156
- // 1.0 => blah, 1.1 => fnord
157
- $upgrade_notice = array();
158
- if ( isset($final_sections['upgrade_notice']) ) {
159
- $split = preg_split( '#<h4>(.*?)</h4>#', $final_sections['upgrade_notice'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
160
- if ( count($split) >= 2 ) {
161
- for ( $i = 0; $i < count( $split ); $i += 2 ) {
162
- $upgrade_notice[$this->sanitize_text( $split[$i] )] = substr( $this->sanitize_text( $split[$i + 1] ), 0, 300 );
163
- }
164
- }
165
- unset( $final_sections['upgrade_notice'] );
166
- }
167
-
168
- // No description?
169
- // No problem... we'll just fall back to the old style of description
170
- // We'll even let you use markup this time!
171
- $excerpt = false;
172
- if ( !isset($final_sections['description']) ) {
173
- $final_sections = array_merge(array('description' => $this->filter_text( $_short_description[2], true )), $final_sections);
174
- $excerpt = true;
175
- }
176
-
177
-
178
- // dump the non-special sections into $remaining_content
179
- // their order will be determined by their original order in the readme.txt
180
- $remaining_content = '';
181
- foreach ( $sections as $s_name => $s_data ) {
182
- $remaining_content .= "\n<h3>{$s_data['title']}</h3>\n{$s_data['content']}";
183
- }
184
- $remaining_content = trim($remaining_content);
185
-
186
-
187
- // All done!
188
- // $r['tags'] and $r['contributors'] are simple arrays
189
- // $r['sections'] is an array with named elements
190
- $r = array(
191
- 'name' => $name,
192
- 'tags' => $tags,
193
- 'requires_at_least' => $requires_at_least,
194
- 'tested_up_to' => $tested_up_to,
195
- 'stable_tag' => $stable_tag,
196
- 'contributors' => $contributors,
197
- 'donate_link' => $donate_link,
198
- 'short_description' => $short_description,
199
- 'screenshots' => $final_screenshots,
200
- 'is_excerpt' => $excerpt,
201
- 'is_truncated' => $truncated,
202
- 'sections' => $final_sections,
203
- 'remaining_content' => $remaining_content,
204
- 'upgrade_notice' => $upgrade_notice
205
- );
206
-
207
- return $r;
208
- }
209
-
210
- function chop_string( $string, $chop ) { // chop a "prefix" from a string: Agressive! uses strstr not 0 === strpos
211
- if ( $_string = strstr($string, $chop) ) {
212
- $_string = substr($_string, strlen($chop));
213
- return trim($_string);
214
- } else {
215
- return trim($string);
216
- }
217
- }
218
-
219
- function user_sanitize( $text, $strict = false ) { // whitelisted chars
220
- if ( function_exists('user_sanitize') ) // bbPress native
221
- return user_sanitize( $text, $strict );
222
-
223
- if ( $strict ) {
224
- $text = preg_replace('/[^a-z0-9-]/i', '', $text);
225
- $text = preg_replace('|-+|', '-', $text);
226
- } else {
227
- $text = preg_replace('/[^a-z0-9_-]/i', '', $text);
228
- }
229
- return $text;
230
- }
231
-
232
- function sanitize_text( $text ) { // not fancy
233
- $text = strip_tags($text);
234
- $text = esc_html($text);
235
- $text = trim($text);
236
- return $text;
237
- }
238
-
239
- function filter_text( $text, $markdown = false ) { // fancy, Markdown
240
- $text = trim($text);
241
-
242
- $text = call_user_func( array( __CLASS__, 'code_trick' ), $text, $markdown ); // A better parser than Markdown's for: backticks -> CODE
243
-
244
- if ( $markdown ) { // Parse markdown.
245
- if ( !class_exists('Parsedown', false) ) {
246
- /** @noinspection PhpIncludeInspection */
247
- require_once(dirname(__FILE__) . '/Parsedown' . (version_compare(PHP_VERSION, '5.3.0', '>=') ? '' : 'Legacy') . '.php');
248
- }
249
- $instance = Parsedown::instance();
250
- $text = $instance->text($text);
251
- }
252
-
253
- $allowed = array(
254
- 'a' => array(
255
- 'href' => array(),
256
- 'title' => array(),
257
- 'rel' => array()),
258
- 'blockquote' => array('cite' => array()),
259
- 'br' => array(),
260
- 'p' => array(),
261
- 'code' => array(),
262
- 'pre' => array(),
263
- 'em' => array(),
264
- 'strong' => array(),
265
- 'ul' => array(),
266
- 'ol' => array(),
267
- 'li' => array(),
268
- 'h3' => array(),
269
- 'h4' => array()
270
- );
271
-
272
- $text = balanceTags($text);
273
-
274
- $text = wp_kses( $text, $allowed );
275
- $text = trim($text);
276
- return $text;
277
- }
278
-
279
- function code_trick( $text, $markdown ) { // Don't use bbPress native function - it's incompatible with Markdown
280
- // If doing markdown, first take any user formatted code blocks and turn them into backticks so that
281
- // markdown will preserve things like underscores in code blocks
282
- if ( $markdown )
283
- $text = preg_replace_callback("!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", array( __CLASS__,'decodeit'), $text);
284
-
285
- $text = str_replace(array("\r\n", "\r"), "\n", $text);
286
- if ( !$markdown ) {
287
- // This gets the "inline" code blocks, but can't be used with Markdown.
288
- $text = preg_replace_callback("|(`)(.*?)`|", array( __CLASS__, 'encodeit'), $text);
289
- // This gets the "block level" code blocks and converts them to PRE CODE
290
- $text = preg_replace_callback("!(^|\n)`(.*?)`!s", array( __CLASS__, 'encodeit'), $text);
291
- } else {
292
- // Markdown can do inline code, we convert bbPress style block level code to Markdown style
293
- $text = preg_replace_callback("!(^|\n)([ \t]*?)`(.*?)`!s", array( __CLASS__, 'indent'), $text);
294
- }
295
- return $text;
296
- }
297
-
298
- function indent( $matches ) {
299
- $text = $matches[3];
300
- $text = preg_replace('|^|m', $matches[2] . ' ', $text);
301
- return $matches[1] . $text;
302
- }
303
-
304
- function encodeit( $matches ) {
305
- if ( function_exists('encodeit') ) // bbPress native
306
- return encodeit( $matches );
307
-
308
- $text = trim($matches[2]);
309
- $text = htmlspecialchars($text, ENT_QUOTES);
310
- $text = str_replace(array("\r\n", "\r"), "\n", $text);
311
- $text = preg_replace("|\n\n\n+|", "\n\n", $text);
312
- $text = str_replace('&amp;lt;', '&lt;', $text);
313
- $text = str_replace('&amp;gt;', '&gt;', $text);
314
- $text = "<code>$text</code>";
315
- if ( "`" != $matches[1] )
316
- $text = "<pre>$text</pre>";
317
- return $text;
318
- }
319
-
320
- function decodeit( $matches ) {
321
- if ( function_exists('decodeit') ) // bbPress native
322
- return decodeit( $matches );
323
-
324
- $text = $matches[2];
325
- $trans_table = array_flip(get_html_translation_table(HTML_ENTITIES));
326
- $text = strtr($text, $trans_table);
327
- $text = str_replace('<br />', '', $text);
328
- $text = str_replace('&#38;', '&', $text);
329
- $text = str_replace('&#39;', "'", $text);
330
- if ( '<pre><code>' == $matches[1] )
331
- $text = "\n$text\n";
332
- return "`$text`";
333
- }
334
-
335
- } // end class
336
-
337
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,166 +1,170 @@
1
- === Media from FTP ===
2
- Contributors: Katsushi Kawamori
3
- Donate link: https://shop.riverforest-wp.info/donate/
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.9
8
- Stable tag: 10.10
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
- = Tutorial Video =
26
- [youtube https://www.youtube.com/watch?v=vdxPvOFZaDk]
27
-
28
- = Live Demo =
29
- I prepared live demo including add-ons.
30
- User Name: liveuser1
31
- Password: live789user
32
- [Live Demo](https://live1.riverforest-wp.info/wordpress/wp-login.php)
33
-
34
- = Why I made this? =
35
- * 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.
36
-
37
- = Special Thanks! Translator =
38
- * Deutsch [pixelverbieger](https://www.pixelverbieger.de/)
39
- * Deutsch(Formal) [transl8or](https://profiles.wordpress.org/transl8or/)
40
- * Español [apasionados](https://apasionados.es/)
41
- * Français [Li-An](https://www.echodesplugins.li-an.fr/)
42
- * Italian [ironicmoka](https://profiles.wordpress.org/photoironic/)
43
- * Russian [khomenkov](https://awesomeprintstudio.com/)
44
-
45
- == Installation ==
46
-
47
- 1. Upload `media-from-ftp` directory to the `/wp-content/plugins/` directory
48
- 2. Activate the plugin through the 'Plugins' menu in WordPress
49
-
50
- == Frequently Asked Questions ==
51
-
52
- = A server error is displayed because there are too many files. "Search & Register" screen does not appear. =
53
- * Media from FTP Settings -> Other -> Limit number of search files
54
- * Please reduce this number.
55
-
56
- * Media from FTP Settings -> Other -> Execution time
57
- * Please increasing the number of seconds.
58
-
59
- * Media from FTP Search & Register -> Screen Options -> Search method of files
60
- * Check of "Search files only for specified directories."
61
-
62
- = Certain file types can not be searched. =
63
- * 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>.
64
-
65
- = I will not find a file with name like this: a-b-0x0.jpg. =
66
- * Media from FTP Search & Register -> Screen Options -> Search method for the exclusion of the thumbnail
67
- * Check of "Unusual selection. if you want to search for filename that contains such -0x0. It is low speed."
68
-
69
- = Where is it better to upload files? =
70
- * Upload directory is any of the following locations.
71
- * Single-site wp-content/uploads
72
- * Multisite wp-content/uploads/sites/*
73
-
74
- = I want to register file for any folder. =
75
- * Media from FTP Settings -> Register -> Date.
76
- * Uncheck of "Organize my uploads into month- and year-based folders".
77
-
78
- = I want to register file to "month- and year-based folders" without relevant to the timestamp of the file. =
79
- * Media from FTP Settings -> Register -> Date.
80
- * Uncheck of "Organize my uploads into month- and year-based folders".
81
-
82
- = File at the time of registration is moved to another directory. =
83
- * 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.
84
-
85
- = The original file is deleted. =
86
- * The case of the following of this plugin to delete the file.
87
- 1. If it contains spaces in the file name. Convert to "-". And remove original file. image example.jpg -> image-example.jpg
88
- 2. If the file name is a multi-byte. It makes the MD5 conversion. And remove original file. image例.jpg -> 2edd9ad56212ce13a39f25b429b09012.jpg
89
- 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
90
- * Thumbnail creation, database registration, do in file after copy.
91
-
92
- = The original file is deleted, it will be the one that has been added to eight characters to the end of the file. =
93
- * 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.
94
- * image-example.jpg -> image-example03193845.jpg
95
- * Meaning 03193845 -> 3rd 19h38m45s
96
-
97
- = 'Fatal error: Maximum execution time of ** seconds exceeded.' get an error message. =
98
- * Media from FTP Settings -> Other -> Execution time
99
- * Please increasing the number of seconds.
100
-
101
- = I want to change the date at the time of registration. =
102
- * Media from FTP Settings -> Register -> Date -> Get the date/time of the file, and updated based on it. Change it if necessary.
103
- * Please checked.
104
-
105
- = I want to register at the date of the Exif information. =
106
- * 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.
107
- * Please checked.
108
-
109
- = I would like to hide the files do not need to search & registration screen. =
110
- * Media from FTP Search & Register -> Screen Options -> Exclude file
111
- * Please enter the exclusion file. It can be a regular expression.
112
-
113
- = I want to turn off the creation of additional images such as thumbnail. =
114
- * It conforms to the WordPress settings.
115
- * Settings-> Media
116
- * Please change the six values to all zeros.
117
- * Please comment out the 'set_post_thumbnail_size' or 'add_image_size' of theme's functions.php.
118
-
119
- == Screenshots ==
120
-
121
- 1. Search file display
122
- 2. Settings Screen Options
123
- 3. Settings Register
124
- 4. Settings Other
125
- 5. Registration file selection
126
- 6. File registration result
127
- 7. Log screen
128
- 8. Import File Load
129
- 9. Import result
130
-
131
- == Changelog ==
132
-
133
- = 10.10 =
134
- Fixed problem of getting user ID.
135
-
136
- = 10.09 =
137
- Fixed problem of getting user ID.
138
-
139
- = 10.08 =
140
- Fixed problem of getting user ID.
141
-
142
- = 10.07 =
143
- Fixed problem of uppercase file suffix.
144
- Fixed the problem of obtaining the shooting date and time of Exif.
145
- Changed add-ons link.
146
-
147
- == Upgrade Notice ==
148
-
149
- = 9.90 =
150
- Security measures.
151
-
152
- = 9.88 =
153
- Security measures.
154
-
155
- = 9.87 =
156
- Security measures.
157
-
158
- = 9.86 =
159
- Fixed problem of Directory-Traversal. Thanks[Plugin Vulnerabilities](https://www.pluginvulnerabilities.com/).
160
-
161
- = 9.85 =
162
- Fixed problem of Directory-Traversal. Thanks[wpl0v3r](https://wordpress.org/support/users/wpl0v3r/).
163
-
164
- = 9.80 =
165
- 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.
166
-
 
 
 
 
1
+ === Media from FTP ===
2
+ Contributors: Katsushi Kawamori
3
+ Donate link: https://shop.riverforest-wp.info/donate/
4
+ Tags: files, ftp, import, media, sync, uploads
5
+ Requires at least: 3.6.0
6
+ Requires PHP: 5.6
7
+ Tested up to: 5.2
8
+ Stable tag: 11.00
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
+ = Tutorial Video =
26
+ [youtube https://www.youtube.com/watch?v=vdxPvOFZaDk]
27
+
28
+ = Live Demo =
29
+ I prepared live demo including add-ons.
30
+ User Name: liveuser1
31
+ Password: live789user
32
+ [Live Demo](https://live1.riverforest-wp.info/wordpress/wp-login.php)
33
+
34
+ = Why I made this? =
35
+ * 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.
36
+
37
+ = Special Thanks! Translator =
38
+ * Deutsch [pixelverbieger](https://www.pixelverbieger.de/)
39
+ * Deutsch(Formal) [transl8or](https://profiles.wordpress.org/transl8or/)
40
+ * Español [apasionados](https://apasionados.es/)
41
+ * Français [Li-An](https://www.echodesplugins.li-an.fr/)
42
+ * Italian [ironicmoka](https://profiles.wordpress.org/photoironic/)
43
+ * Russian [khomenkov](https://awesomeprintstudio.com/)
44
+
45
+ == Installation ==
46
+
47
+ 1. Upload `media-from-ftp` directory to the `/wp-content/plugins/` directory
48
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
49
+
50
+ == Frequently Asked Questions ==
51
+
52
+ = A server error is displayed because there are too many files. "Search & Register" screen does not appear. =
53
+ * Media from FTP Settings -> Other -> Limit number of search files
54
+ * Please reduce this number.
55
+
56
+ * Media from FTP Settings -> Other -> Execution time
57
+ * Please increasing the number of seconds.
58
+
59
+ * Media from FTP Search & Register -> Screen Options -> Search method of files
60
+ * Check of "Search files only for specified directories."
61
+
62
+ = Certain file types can not be searched. =
63
+ * 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>.
64
+
65
+ = I will not find a file with name like this: a-b-0x0.jpg. =
66
+ * Media from FTP Search & Register -> Screen Options -> Search method for the exclusion of the thumbnail
67
+ * Check of "Unusual selection. if you want to search for filename that contains such -0x0. It is low speed."
68
+
69
+ = Where is it better to upload files? =
70
+ * Upload directory is any of the following locations.
71
+ * Single-site wp-content/uploads
72
+ * Multisite wp-content/uploads/sites/*
73
+
74
+ = I want to register file for any folder. =
75
+ * Media from FTP Settings -> Register -> Date.
76
+ * Uncheck of "Organize my uploads into month- and year-based folders".
77
+
78
+ = I want to register file to "month- and year-based folders" without relevant to the timestamp of the file. =
79
+ * Media from FTP Settings -> Register -> Date.
80
+ * Uncheck of "Organize my uploads into month- and year-based folders".
81
+
82
+ = File at the time of registration is moved to another directory. =
83
+ * 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.
84
+
85
+ = The original file is deleted. =
86
+ * The case of the following of this plugin to delete the file.
87
+ 1. If it contains spaces in the file name. Convert to "-". And remove original file. image example.jpg -> image-example.jpg
88
+ 2. If the file name is a multi-byte. It makes the MD5 conversion. And remove original file. image例.jpg -> 2edd9ad56212ce13a39f25b429b09012.jpg
89
+ 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
90
+ * Thumbnail creation, database registration, do in file after copy.
91
+
92
+ = The original file is deleted, it will be the one that has been added to eight characters to the end of the file. =
93
+ * 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.
94
+ * image-example.jpg -> image-example03193845.jpg
95
+ * Meaning 03193845 -> 3rd 19h38m45s
96
+
97
+ = 'Fatal error: Maximum execution time of ** seconds exceeded.' get an error message. =
98
+ * Media from FTP Settings -> Other -> Execution time
99
+ * Please increasing the number of seconds.
100
+
101
+ = I want to change the date at the time of registration. =
102
+ * Media from FTP Settings -> Register -> Date -> Get the date/time of the file, and updated based on it. Change it if necessary.
103
+ * Please checked.
104
+
105
+ = I want to register at the date of the Exif information. =
106
+ * 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.
107
+ * Please checked.
108
+
109
+ = I would like to hide the files do not need to search & registration screen. =
110
+ * Media from FTP Search & Register -> Screen Options -> Exclude file
111
+ * Please enter the exclusion file. It can be a regular expression.
112
+
113
+ = I want to turn off the creation of additional images such as thumbnail. =
114
+ * It conforms to the WordPress settings.
115
+ * Settings-> Media
116
+ * Please change the six values to all zeros.
117
+ * Please comment out the 'set_post_thumbnail_size' or 'add_image_size' of theme's functions.php.
118
+
119
+ == Screenshots ==
120
+
121
+ 1. Search file display
122
+ 2. Settings Screen Options
123
+ 3. Settings Register
124
+ 4. Settings Other
125
+ 5. Registration file selection
126
+ 6. File registration result
127
+ 7. Log screen
128
+ 8. Import File Load
129
+ 9. Import result
130
+
131
+ == Changelog ==
132
+
133
+ = 11.00 =
134
+ Conformed to the WordPress coding standard.
135
+ The code at the time of registration was reviewed and the speed has improved.
136
+
137
+ = 10.10 =
138
+ Fixed problem of getting user ID.
139
+
140
+ = 10.09 =
141
+ Fixed problem of getting user ID.
142
+
143
+ = 10.08 =
144
+ Fixed problem of getting user ID.
145
+
146
+ = 10.07 =
147
+ Fixed problem of uppercase file suffix.
148
+ Fixed the problem of obtaining the shooting date and time of Exif.
149
+ Changed add-ons link.
150
+
151
+ == Upgrade Notice ==
152
+
153
+ = 9.90 =
154
+ Security measures.
155
+
156
+ = 9.88 =
157
+ Security measures.
158
+
159
+ = 9.87 =
160
+ Security measures.
161
+
162
+ = 9.86 =
163
+ Fixed problem of Directory-Traversal. Thanks[Plugin Vulnerabilities](https://www.pluginvulnerabilities.com/).
164
+
165
+ = 9.85 =
166
+ Fixed problem of Directory-Traversal. Thanks[wpl0v3r](https://wordpress.org/support/users/wpl0v3r/).
167
+
168
+ = 9.80 =
169
+ 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.
170
+
req/MediaFromFtpAdmin.php DELETED
@@ -1,1890 +0,0 @@
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
- $mediafromftpadmin = new MediaFromFtpAdmin();
23
- add_filter( 'plugin_action_links', array($mediafromftpadmin, 'settings_link'), 10, 2 );
24
- add_action( 'admin_footer', array($mediafromftpadmin, 'custom_bulk_admin_footer') );
25
- add_action( 'admin_notices', array($mediafromftpadmin, 'notices') );
26
-
27
- class MediaFromFtpAdmin {
28
-
29
- private $plugin_base_url;
30
- private $plugin_dir;
31
- private $upload_dir;
32
- private $upload_url;
33
- private $upload_path;
34
- private $plugin_tmp_url;
35
- private $plugin_tmp_dir;
36
- private $plugin_disallow_tmp_dir;
37
- private $is_add_on_activate;
38
-
39
- /* ==================================================
40
- * Construct
41
- * @since 9.81
42
- */
43
- public function __construct() {
44
-
45
- $plugin_base_dir = untrailingslashit(plugin_dir_path( __DIR__ ));
46
- $slugs = explode('/', $plugin_base_dir);
47
- $slug = end($slugs);
48
- $this->plugin_base_url = untrailingslashit(plugin_dir_url( __DIR__ ));
49
- $this->plugin_dir = untrailingslashit(rtrim($plugin_base_dir, $slug));
50
-
51
- if(!class_exists('MediaFromFtp')){
52
- include_once $plugin_base_dir.'/inc/MediaFromFtp.php';
53
- }
54
- if(!class_exists('TT_MediaFromFtp_List_Table')){
55
- require_once( $plugin_base_dir.'/req/MediaFromFtpListTable.php' );
56
- }
57
- $mediafromftp = new MediaFromFtp();
58
- list($this->upload_dir, $this->upload_url, $this->upload_path) = $mediafromftp->upload_dir_url_path();
59
-
60
- $this->plugin_tmp_url = $this->upload_url.'/media-from-ftp-tmp';
61
- $this->plugin_tmp_dir = $this->upload_dir.'/media-from-ftp-tmp';
62
- $this->plugin_disallow_tmp_dir = str_replace(home_url(), '', $mediafromftp->siteurl()).'/'.$this->upload_path.'/media-from-ftp-tmp/';
63
-
64
- $category_active = FALSE;
65
- if( function_exists('media_from_ftp_add_on_category_load_textdomain') ){
66
- include_once $this->plugin_dir.'/media-from-ftp-add-on-category/inc/MediaFromFtpAddOnCategory.php';
67
- $category_active = TRUE;
68
- }
69
- $exif_active = FALSE;
70
- if( function_exists('media_from_ftp_add_on_exif_load_textdomain') ){
71
- include_once $this->plugin_dir.'/media-from-ftp-add-on-exif/inc/MediaFromFtpAddOnExif.php';
72
- $exif_active = TRUE;
73
- }
74
- $cli_active = FALSE;
75
- if( function_exists('media_from_ftp_add_on_cli_load_textdomain') ){
76
- require_once( $this->plugin_dir.'/media-from-ftp-add-on-cli/req/MediaFromFtpCli.php' );
77
- $cli_active = TRUE;
78
- }
79
- $wpcron_active = FALSE;
80
- if( function_exists('media_from_ftp_add_on_wpcron_load_textdomain') ){
81
- include_once $this->plugin_dir.'/media-from-ftp-add-on-wpcron/inc/MediaFromFtpAddOnWpcron.php';
82
- $wpcron_active = TRUE;
83
- }
84
- $this->is_add_on_activate = array(
85
- 'category' => $category_active,
86
- 'exif' => $exif_active,
87
- 'cli' => $cli_active,
88
- 'wpcron' => $wpcron_active
89
- );
90
-
91
- add_action( 'admin_menu', array($this, 'add_pages') );
92
- add_action( 'admin_enqueue_scripts', array($this, 'load_custom_wp_admin_style') );
93
- add_action( 'admin_footer', array($this, 'load_custom_wp_admin_style2') );
94
- add_action( 'screen_settings', array($this, 'search_register_show_screen_options'), 10, 2 );
95
- add_filter( 'set-screen-option', array($this, 'search_register_set_screen_options'), 11, 3 );
96
- add_filter( 'contextual_help', array($this, 'search_register_help_tab'), 12, 3);
97
- add_filter( 'robots_txt', array($this, 'custom_robots_txt'), 9999 );
98
-
99
- }
100
-
101
- /* ==================================================
102
- * Add a "Settings" link to the plugins page
103
- * @since 1.0
104
- */
105
- public function settings_link( $links, $file ) {
106
- static $this_plugin;
107
- if ( empty($this_plugin) ) {
108
- $this_plugin = 'media-from-ftp/mediafromftp.php';
109
- }
110
- if ( $file == $this_plugin ) {
111
- $links[] = '<a href="'.admin_url('admin.php?page=mediafromftp').'">Media from FTP</a>';
112
- $links[] = '<a href="'.admin_url('admin.php?page=mediafromftp-search-register').'">'.__('Search & Register', 'media-from-ftp').'</a>';
113
- $links[] = '<a href="'.admin_url('admin.php?page=mediafromftp-settings').'">'.__( 'Settings').'</a>';
114
- if ( $this->is_add_on_activate['wpcron'] ) {
115
- $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
116
- $links[] = $mediafromftpaddonwpcron->mediafromftp_settings_link_html();
117
- unset($mediafromftpaddonwpcron);
118
- }
119
- $links[] = '<a href="'.admin_url('admin.php?page=mediafromftp-log').'">'.__('Log', 'media-from-ftp').'</a>';
120
- $links[] = '<a href="'.admin_url('admin.php?page=mediafromftp-import').'">'.__('Import').'</a>';
121
- $links[] = '<a href="'.admin_url('admin.php?page=mediafromftp-addons').'">'.__('Add-Ons', 'media-from-ftp').'</a>';
122
- }
123
- return $links;
124
- }
125
-
126
- /* ==================================================
127
- * Add page
128
- * @since 1.0
129
- */
130
- public function add_pages() {
131
- add_menu_page(
132
- 'Media from FTP',
133
- 'Media from FTP',
134
- 'upload_files',
135
- 'mediafromftp',
136
- array($this, 'manage_page'),
137
- 'dashicons-upload'
138
- );
139
- add_submenu_page(
140
- 'mediafromftp',
141
- __('Search & Register', 'media-from-ftp'),
142
- __('Search & Register', 'media-from-ftp'),
143
- 'upload_files',
144
- 'mediafromftp-search-register',
145
- array($this, 'search_register_page')
146
- );
147
- add_submenu_page(
148
- 'mediafromftp',
149
- __('Settings'),
150
- __('Settings'),
151
- 'upload_files',
152
- 'mediafromftp-settings',
153
- array($this, 'settings_page')
154
- );
155
- if ( $this->is_add_on_activate['wpcron'] ) {
156
- $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
157
- $mediafromftpaddonwpcron->mediafromftp_add_submenu();
158
- unset($mediafromftpaddonwpcron);
159
- }
160
- add_submenu_page(
161
- 'mediafromftp',
162
- __('Log', 'media-from-ftp'),
163
- __('Log', 'media-from-ftp'),
164
- 'upload_files',
165
- 'mediafromftp-log',
166
- array($this, 'log_page')
167
- );
168
- add_submenu_page(
169
- 'mediafromftp',
170
- __('Import'),
171
- __('Import'),
172
- 'upload_files',
173
- 'mediafromftp-import',
174
- array($this, 'medialibrary_import_page')
175
- );
176
- add_submenu_page(
177
- 'mediafromftp',
178
- __('Add-Ons', 'media-from-ftp'),
179
- __('Add-Ons', 'media-from-ftp'),
180
- 'upload_files',
181
- 'mediafromftp-addons',
182
- array($this, 'addons_page')
183
- );
184
- }
185
-
186
- /* ==================================================
187
- * Show Screen Option Search & Register
188
- * @since 9.52
189
- */
190
- public function search_register_show_screen_options( $status, $args ) {
191
-
192
- $mediafromftp_settings = get_option($this->wp_options_name());
193
-
194
- $return = $status;
195
- if ( $args->base == 'media-from-ftp_page_mediafromftp-search-register' ) {
196
- $mediafromftp = new MediaFromFtp();
197
- $return = '<div style="display: block; padding: 5px 15px">';
198
- $return .= $mediafromftp->search_option_html($mediafromftp_settings);
199
- $return .= '<div style="display: block;padding:5px 5px">'.get_submit_button( __( 'Apply' ), 'primary', 'media-from-ftp-screen-options-apply', FALSE ).'</div>';
200
- $return .= '<input type="hidden" name="wp_screen_options[option]" value="media_from_ftp_show_screen" />';
201
- $return .= '<input type="hidden" name="wp_screen_options[value]" value="2" />';
202
- $return .= '</div>';
203
- unset($mediafromftp);
204
- }
205
-
206
- return $return;
207
-
208
- }
209
-
210
- /* ==================================================
211
- * Save Screen Option Search & Register
212
- * @since 9.52
213
- */
214
- public function search_register_set_screen_options($status, $option, $value) {
215
- if ( 'media_from_ftp_show_screen' == $option ) {
216
- $this->options_updated($value);
217
- return $value;
218
- }
219
- return $status;
220
- }
221
-
222
- /* ==================================================
223
- * Help Tab
224
- * @since 9.53
225
- */
226
- public function search_register_help_tab($help, $screen_id, $screen) {
227
-
228
- 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' ) {
229
- $sidebar = '<p><strong>'.__('For more information:').'</strong></p>';
230
- $sidebar .= '<p><a href="'.__('https://wordpress.org/plugins/media-from-ftp/faq', 'media-from-ftp').'" target="_blank">'.__('FAQ').'</a></p>';
231
- $sidebar .= '<p><a href="https://wordpress.org/support/plugin/media-from-ftp" target="_blank">'.__('Support Forums').'</a></p>';
232
- $sidebar .= '<p><a href="https://wordpress.org/support/view/plugin-reviews/media-from-ftp" target="_blank">'.__('Reviews', 'media-from-ftp').'</a></p>';
233
- $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>';
234
- $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> <a style="text-decoration: none;" href="https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w" target="_blank"><span class="dashicons dashicons-video-alt3"></span></a></p>';
235
- $sidebar .= '<p><a href="'.__('https://riverforest-wp.info/donate/', 'media-from-ftp').'" target="_blank">'.__('Donate to this plugin &#187;').'</a></p>';
236
-
237
- $tabs = $this->get_help_message($screen_id);
238
- foreach($tabs as $tab) {
239
- $screen->add_help_tab($tab);
240
- }
241
- $screen->set_help_sidebar($sidebar);
242
- }
243
- }
244
-
245
- /* ==================================================
246
- * Help Tab for message
247
- * @param string $screen_id
248
- * @return array $tab
249
- * @since 9.53
250
- */
251
- private function get_help_message($screen_id) {
252
-
253
- $upload_dir_html = '<span style="color: red;">'.$this->upload_path.'</span>';
254
-
255
- switch ($screen_id) {
256
- case "media-from-ftp_page_mediafromftp-search-register":
257
- $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>';
258
- $outline .= '<p>'.sprintf(__('Please check and press the "%1$s" button.', 'media-from-ftp'), __('Update Media')).'</p>';
259
- $outline .= '<p>'.sprintf(__('Options for searching can be specified with "%1$s".', 'media-from-ftp'), __('Screen Options')).'</p>';
260
- break;
261
- case "media-from-ftp_page_mediafromftp-settings":
262
- $outline = '<p>'.sprintf(__('"%1$s" sets options for %2$s registration.', 'media-from-ftp'), __('Register'), __('Media Library')).'</p>';
263
- $outline .= '<p>'.sprintf(__('"%1$s" sets other options.', 'media-from-ftp'), __('Other', 'media-from-ftp')).'</p>';
264
- if ( $this->is_add_on_activate['cli'] ) {
265
- $mediafromftpcli = new MediaFromFtpCli();
266
- $outline .= $mediafromftpcli->mediafromftp_settings_helptab_html();
267
- }
268
- break;
269
- case "media-from-ftp_page_mediafromftp-event":
270
- if ( $this->is_add_on_activate['wpcron'] ) {
271
- $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
272
- $outline = $mediafromftpaddonwpcron->mediafromftp_event_helptab_html();
273
- }
274
- break;
275
- case "media-from-ftp_page_mediafromftp-log":
276
- $outline = '<p>'.__('Display history of registration.', 'media-from-ftp').'</p>';
277
- $outline .= '<p>'.__('You can export to CSV format.', 'media-from-ftp').'</p>';
278
- break;
279
- case "media-from-ftp_page_mediafromftp-import":
280
- $outline = '<p>'.__('To Import the files to Media Library from a WordPress export file.', 'media-from-ftp').'</p>';
281
- $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>';
282
- break;
283
- case "media-from-ftp_page_mediafromftp-addons":
284
- $outline = '<p>'.__('This page shows paid add-ons and their summaries.', 'media-from-ftp').'</p>';
285
- $outline .= '<p>'.__('You can check whether it is installed or activated.', 'media-from-ftp').'</p>';
286
- break;
287
- }
288
-
289
- $tabs = array(
290
- array(
291
- 'title' => __('Overview'),
292
- 'id' => 'outline',
293
- 'content' => $outline
294
- )
295
- );
296
-
297
- return $tabs;
298
- }
299
-
300
- /* ==================================================
301
- * Add Css and Script
302
- * @since 2.23
303
- */
304
- public function load_custom_wp_admin_style() {
305
- if ($this->is_my_plugin_screen()) {
306
- $mediafromftp_settings = get_option($this->wp_options_name());
307
- if ( $mediafromftp_settings['datetimepicker'] ) {
308
- wp_enqueue_style( 'jquery-datetimepicker', $this->plugin_base_url.'/css/jquery.datetimepicker.css' );
309
- }
310
- wp_enqueue_style( 'jquery-responsiveTabs', $this->plugin_base_url.'/css/responsive-tabs.css' );
311
- wp_enqueue_style( 'jquery-responsiveTabs-style', $this->plugin_base_url.'/css/style.css' );
312
- wp_enqueue_style( 'mediafromftp', $this->plugin_base_url.'/css/mediafromftp.css' );
313
- wp_enqueue_script( 'jquery' );
314
- if ( $mediafromftp_settings['datetimepicker'] ) {
315
- wp_enqueue_script( 'jquery-datetimepicker', $this->plugin_base_url.'/js/jquery.datetimepicker.js', null, '2.3.4' );
316
- wp_enqueue_script( 'jquery-mediafromftp-datetimepicker', $this->plugin_base_url.'/js/jquery.mediafromftp.datetimepicker.js', array('jquery') );
317
- }
318
- wp_enqueue_script( 'jquery-responsiveTabs', $this->plugin_base_url.'/js/jquery.responsiveTabs.min.js' );
319
-
320
- $handle = 'mediafromftp-ajax-script';
321
- $action1 = 'mediafromftp-update-ajax-action';
322
- $action2 = 'mediafromftp-import-ajax-action';
323
- wp_enqueue_script( $handle, $this->plugin_base_url.'/js/jquery.mediafromftp.js', array('jquery') );
324
- wp_localize_script( $handle, 'MEDIAFROMFTPUPDATE', array(
325
- 'ajax_url' => admin_url('admin-ajax.php'),
326
- 'action' => $action1,
327
- 'nonce' => wp_create_nonce( $action1 )
328
- ));
329
- wp_localize_script( $handle, 'MEDIAFROMFTPIMPORT', array(
330
- 'ajax_url' => admin_url('admin-ajax.php'),
331
- 'action' => $action2,
332
- 'nonce' => wp_create_nonce( $action2 )
333
- ));
334
- }
335
- }
336
-
337
- /* ==================================================
338
- * Add Script on footer
339
- * @since 1.0
340
- */
341
- public function load_custom_wp_admin_style2() {
342
- if ($this->is_my_plugin_screen2()) {
343
- if ( isset($_POST['media_from_ftp_select_author']) && $_POST['media_from_ftp_select_author'] ) {
344
- if ( check_admin_referer('mff_select_author', 'media_from_ftp_select_author') ) {
345
- if ( !empty($_POST['mediafromftp_select_author']) && !empty($_POST['mediafromftp_xml_file']) ) {
346
- if ( is_file($_POST['mediafromftp_xml_file']) ) {
347
- $select_author = array();
348
- foreach (array_keys($_POST) as $key) {
349
- if ( $key === 'select_author' || $key === 'mediafromftp_select_author' || $key === 'mediafromftp_xml_file' ) { // skip
350
- } else {
351
- if ( $_POST[$key] <> -1 ) {
352
- $select_author[$key] = intval($_POST[$key]);
353
- }
354
- }
355
- }
356
- if ( !validate_file($_POST['mediafromftp_xml_file']) ){
357
- $filename = $_POST['mediafromftp_xml_file'];
358
- $mediafromftp = new MediaFromFtp();
359
- echo $mediafromftp->make_object($filename, $select_author);
360
- unset($mediafromftp);
361
- unlink($filename);
362
- }
363
- }
364
- }
365
- }
366
- }
367
- }
368
- }
369
-
370
- /* ==================================================
371
- * For only admin style
372
- * @since 8.82
373
- */
374
- private function is_my_plugin_screen() {
375
- $screen = get_current_screen();
376
- if (is_object($screen) && $screen->id == 'toplevel_page_mediafromftp') {
377
- return TRUE;
378
- } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-settings') {
379
- return TRUE;
380
- } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-search-register') {
381
- return TRUE;
382
- } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-event') {
383
- return TRUE;
384
- } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-log') {
385
- return TRUE;
386
- } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-import') {
387
- return TRUE;
388
- } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-addons') {
389
- return TRUE;
390
- } else {
391
- return FALSE;
392
- }
393
- }
394
-
395
- /* ==================================================
396
- * For only admin style
397
- * @since 8.82
398
- */
399
- private function is_my_plugin_screen2() {
400
- $screen = get_current_screen();
401
- if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-import') {
402
- return TRUE;
403
- } else {
404
- return FALSE;
405
- }
406
- }
407
-
408
- /* ==================================================
409
- * For only admin style
410
- * @since 9.63
411
- */
412
- private function is_my_plugin_screen3() {
413
- $screen = get_current_screen();
414
- if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-search-register') {
415
- return TRUE;
416
- } else if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-settings') {
417
- return TRUE;
418
- } else {
419
- return FALSE;
420
- }
421
- }
422
-
423
- /* ==================================================
424
- * Main
425
- */
426
- public function manage_page() {
427
-
428
- if ( !current_user_can( 'upload_files' ) ) {
429
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
430
- }
431
-
432
- ?>
433
-
434
- <div class="wrap">
435
-
436
- <h2>Media from FTP
437
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" class="page-title-action"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
438
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" class="page-title-action"><?php _e('Settings'); ?></a>
439
- <?php
440
- if ( $this->is_add_on_activate['wpcron'] ) {
441
- $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
442
- $mediafromftpaddonwpcron->mediafromftp_event_link_html();
443
- unset($mediafromftpaddonwpcron);
444
- }
445
- ?>
446
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" class="page-title-action"><?php _e('Log', 'media-from-ftp'); ?></a>
447
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-import'); ?>" class="page-title-action"><?php _e('Import'); ?></a>
448
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-addons'); ?>" class="page-title-action"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
449
- </h2>
450
- <div style="clear: both;"></div>
451
-
452
- <h3><?php _e('Register to media library from files that have been uploaded by FTP.', 'media-from-ftp'); ?></h3>
453
-
454
- <?php $this->credit(); ?>
455
- <hr>
456
- <?php $this->server_path_status(); ?>
457
-
458
- </div>
459
- <?php
460
-
461
- }
462
-
463
- /* ==================================================
464
- * Credit
465
- */
466
- private function credit() {
467
-
468
- $plugin_name = NULL;
469
- $plugin_ver_num = NULL;
470
- $plugin_path = plugin_dir_path( __DIR__ );
471
- $plugin_dir = untrailingslashit($plugin_path);
472
- $slugs = explode('/', $plugin_dir);
473
- $slug = end($slugs);
474
- $files = scandir($plugin_dir);
475
- foreach ($files as $file) {
476
- if($file == '.' || $file == '..' || is_dir($plugin_path.$file)){
477
- continue;
478
- } else {
479
- $exts = explode('.', $file);
480
- $ext = strtolower(end($exts));
481
- if ( $ext === 'php' ) {
482
- $plugin_datas = get_file_data( $plugin_path.$file, array('name'=>'Plugin Name', 'version' => 'Version') );
483
- if ( array_key_exists( "name", $plugin_datas ) && !empty($plugin_datas['name']) && array_key_exists( "version", $plugin_datas ) && !empty($plugin_datas['version']) ) {
484
- $plugin_name = $plugin_datas['name'];
485
- $plugin_ver_num = $plugin_datas['version'];
486
- break;
487
- }
488
- }
489
- }
490
- }
491
- $plugin_version = __('Version:').' '.$plugin_ver_num;
492
- $faq = __('https://wordpress.org/plugins/'.$slug.'/faq', $slug);
493
- $support = 'https://wordpress.org/support/plugin/'.$slug;
494
- $review = 'https://wordpress.org/support/view/plugin-reviews/'.$slug;
495
- $translate = 'https://translate.wordpress.org/projects/wp-plugins/'.$slug;
496
- $facebook = 'https://www.facebook.com/katsushikawamori/';
497
- $twitter = 'https://twitter.com/dodesyo312';
498
- $youtube = 'https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w';
499
- $donate = __('https://shop.riverforest-wp.info/donate/', $slug);
500
-
501
- ?>
502
- <span style="font-weight: bold;">
503
- <div>
504
- <?php echo $plugin_version; ?> |
505
- <a style="text-decoration: none;" href="<?php echo $faq; ?>" target="_blank"><?php _e('FAQ'); ?></a> | <a style="text-decoration: none;" href="<?php echo $support; ?>" target="_blank"><?php _e('Support Forums'); ?></a> | <a style="text-decoration: none;" href="<?php echo $review; ?>" target="_blank"><?php _e('Reviews', $slug); ?></a>
506
- </div>
507
- <div>
508
- <a style="text-decoration: none;" href="<?php echo $translate; ?>" target="_blank"><?php echo sprintf(__('Translations for %s'), $plugin_name); ?></a> | <a style="text-decoration: none;" href="<?php echo $facebook; ?>" target="_blank"><span class="dashicons dashicons-facebook"></span></a> | <a style="text-decoration: none;" href="<?php echo $twitter; ?>" target="_blank"><span class="dashicons dashicons-twitter"></span></a> | <a style="text-decoration: none;" href="<?php echo $youtube; ?>" target="_blank"><span class="dashicons dashicons-video-alt3"></span></a>
509
- </div>
510
- </span>
511
-
512
- <div style="width: 250px; height: 180px; margin: 5px; padding: 5px; border: #CCC 2px solid;">
513
- <h3><?php _e('Please make a donation if you like my work or would like to further the development of this plugin.', $slug); ?></h3>
514
- <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>
515
- <button type="button" style="margin: 5px; padding: 5px;" onclick="window.open('<?php echo $donate; ?>')"><?php _e('Donate to this plugin &#187;'); ?></button>
516
- </div>
517
-
518
- <?php
519
-
520
- }
521
-
522
- /* ==================================================
523
- * Server Path Status
524
- */
525
- private function server_path_status() {
526
-
527
- ?>
528
- <h3><?php _e('Server path status', 'media-from-ftp'); ?></h3>
529
- <h4><?php _e('If something goes wrong, please report the following to the support forum. If you do not want to show the Url or Path, please hide it part.', 'media-from-ftp'); ?></h4>
530
- <?php
531
- $wp_uploads = wp_upload_dir();
532
- $mediafromftp = new MediaFromFtp();
533
- $status = "\n";
534
- $status .= 'WordPress'."\n";
535
- $status .= 'home_url: '.home_url()."\n";
536
- $status .= 'ABSPATH: '.wp_normalize_path(ABSPATH)."\n";
537
- $status .= 'wp_upload_dir[basedir]: '.$wp_uploads['basedir']."\n";
538
- $status .= 'wp_upload_dir[baseurl]: '.$wp_uploads['baseurl']."\n";
539
- $status .= 'upload_path: '.get_option('upload_path')."\n";
540
- $status .= 'upload_url_path: '.get_option('upload_url_path')."\n";
541
- $status .= 'WPINC: '.WPINC."\n";
542
- $status .= "\n";
543
- $status .= 'Media from FTP'."\n";
544
- $status .= 'Upload Dir: '.$this->upload_dir."\n";
545
- $status .= 'Upload Url: '.$this->upload_url."\n";
546
- $status .= 'Upload Path: '.$this->upload_path."\n";
547
- $status .= 'Plugin Disallow Tmp Dir: '.$this->plugin_disallow_tmp_dir."\n";
548
- $status .= 'Site Url: '.$mediafromftp->siteurl()."\n";
549
- ?>
550
- <textarea readonly rows="16" style="font-size: 12px; width: 100%;">
551
- <?php echo $status; ?>
552
- </textarea>
553
- <?php
554
-
555
- }
556
-
557
- /* ==================================================
558
- * Sub Menu
559
- */
560
- public function settings_page() {
561
-
562
- if ( !current_user_can( 'upload_files' ) ) {
563
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
564
- }
565
-
566
- if ( isset($_POST['media_from_ftp_settings']) && $_POST['media_from_ftp_settings'] ) {
567
- if ( check_admin_referer('mff_settings', 'media_from_ftp_settings') ) {
568
- $submenu = 1;
569
- $this->options_updated($submenu);
570
- }
571
- }
572
- if ( isset($_POST['media_from_ftp_search']) && $_POST['media_from_ftp_search'] ) {
573
- if ( check_admin_referer('mff_search', 'media_from_ftp_search') ) {
574
- $submenu = 2;
575
- $this->options_updated($submenu);
576
- }
577
- }
578
- if ( isset($_POST['media_from_ftp_clear_cash']) && $_POST['media_from_ftp_clear_cash'] ) {
579
- if ( check_admin_referer('mff_clear_cash', 'media_from_ftp_clear_cash') ) {
580
- $submenu = 3;
581
- $this->options_updated($submenu);
582
- }
583
- }
584
- if ( isset($_POST['media_from_ftp_run_cron']) && $_POST['media_from_ftp_run_cron'] ) {
585
- if ( check_admin_referer('mff_run_cron', 'media_from_ftp_run_cron') ) {
586
- $submenu = 4;
587
- $this->options_updated($submenu);
588
- }
589
- }
590
- if ( isset($_POST['media_from_ftp_add_schedule']) && $_POST['media_from_ftp_add_schedule'] ) {
591
- if ( check_admin_referer('mff_add_schedule', 'media_from_ftp_add_schedule') ) {
592
- $submenu = 5;
593
- $this->options_updated($submenu);
594
- }
595
- }
596
- if ( isset($_POST['media_from_ftp_add_schedule_delete']) && $_POST['media_from_ftp_add_schedule_delete'] ) {
597
- if ( check_admin_referer('mff_add_schedule_delete', 'media_from_ftp_add_schedule_delete') ) {
598
- $submenu = 6;
599
- $this->options_updated($submenu);
600
- }
601
- }
602
- if ( isset($_POST['media_from_ftp_settings_cron_event_create']) && $_POST['media_from_ftp_settings_cron_event_create'] ) {
603
- if ( check_admin_referer('mff_settings_cron_event_create', 'media_from_ftp_settings_cron_event_create') ) {
604
- $submenu = 7;
605
- $this->options_updated($submenu);
606
- }
607
- }
608
-
609
- $mediafromftp = new MediaFromFtp();
610
-
611
- $mediafromftp_addon_wpcron = FALSE;
612
- if ( $this->is_add_on_activate['wpcron'] ) {
613
- $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
614
- $mediafromftp_addon_wpcron = TRUE;
615
- }
616
-
617
- $mediafromftp_addon_category = FALSE;
618
- if ( $this->is_add_on_activate['category'] ) {
619
- $mediafromftpaddoncategory = new MediaFromFtpAddOnCategory();
620
- $mediafromftp_addon_category = TRUE;
621
- }
622
-
623
- $mediafromftp_addon_exif = FALSE;
624
- if ( $this->is_add_on_activate['exif'] ) {
625
- $mediafromftpaddonexif = new MediaFromFtpAddOnExif();
626
- $mediafromftp_addon_exif = TRUE;
627
- }
628
-
629
- $mediafromftp_settings = get_option($this->wp_options_name());
630
-
631
- $def_max_execution_time = ini_get('max_execution_time');
632
- $scriptname = admin_url('admin.php?page=mediafromftp-settings');
633
-
634
- ?>
635
-
636
- <div class="wrap">
637
-
638
- <h2>Media from FTP <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" style="text-decoration: none;"><?php _e('Settings'); ?></a>
639
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" class="page-title-action"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
640
- <?php
641
- if ($mediafromftp_addon_wpcron) {
642
- $mediafromftpaddonwpcron->mediafromftp_event_link_html();
643
- }
644
- ?>
645
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" class="page-title-action"><?php _e('Log', 'media-from-ftp'); ?></a>
646
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-import'); ?>" class="page-title-action"><?php _e('Import'); ?></a>
647
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-addons'); ?>" class="page-title-action"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
648
- </h2>
649
- <div style="clear: both;"></div>
650
-
651
- <div id="mediafromftp-settings-tabs">
652
- <ul>
653
- <li><a href="#mediafromftp-settings-tabs-1"><?php _e('Register'); ?></a></li>
654
- <li><a href="#mediafromftp-settings-tabs-2"><?php _e('Search'); ?></a></li>
655
- <li><a href="#mediafromftp-settings-tabs-3"><?php _e('Other', 'media-from-ftp'); ?></a></li>
656
- <?php
657
- if ( $this->is_add_on_activate['cli'] ) {
658
- $mediafromftpcli = new MediaFromFtpCli();
659
- $mediafromftpcli->mediafromftp_settings_tab_menu_html();
660
- }
661
- ?>
662
- </ul>
663
-
664
- <div id="mediafromftp-settings-tabs-1">
665
- <div style="display: block; padding: 5px 15px">
666
- <div class="item-mediafromftp-settings">
667
- <h3><?php _e('Date'); ?></h3>
668
- <div style="display: block;padding:5px 5px">
669
- <input type="radio" name="mediafromftp_dateset" form="mediafromftp_settings_form" value="new" <?php if ($mediafromftp_settings['dateset'] === 'new') echo 'checked'; ?>>
670
- <?php _e('Update to use of the current date/time.', 'media-from-ftp'); ?>
671
- </div>
672
- <div style="display: block;padding:5px 5px">
673
- <input type="radio" name="mediafromftp_dateset" form="mediafromftp_settings_form" value="server" <?php if ($mediafromftp_settings['dateset'] === 'server') echo 'checked'; ?>>
674
- <?php _e('Get the date/time of the file, and updated based on it. Change it if necessary.', 'media-from-ftp'); ?>
675
- </div>
676
- <div style="display: block; padding:5px 5px">
677
- <input type="radio" name="mediafromftp_dateset" form="mediafromftp_settings_form" value="exif" <?php if ($mediafromftp_settings['dateset'] === 'exif') echo 'checked'; ?>>
678
- <?php
679
- _e('Get the date/time of the file, and updated based on it. Change it if necessary.', 'media-from-ftp');
680
- _e('Get by priority if there is date and time of the Exif information.', 'media-from-ftp');
681
- ?>
682
- </div>
683
- <div style="display: block; padding:5px 5px">
684
- <input type="radio" name="mediafromftp_dateset" form="mediafromftp_settings_form" value="fixed" <?php if ($mediafromftp_settings['dateset'] === 'fixed') echo 'checked'; ?>>
685
- <?php _e('Update to use of fixed the date/time.', 'media-from-ftp'); ?>
686
- </div>
687
- <div style="display: block; padding:5px 40px">
688
- <input type="text" id="datetimepicker-mediafromftp00" name="mediafromftp_datefixed" form="mediafromftp_settings_form" value="<?php echo $mediafromftp_settings['datefixed']; ?>">
689
- </div>
690
- <div style="display: block; padding:5px 5px">
691
- <?php
692
- if ( current_user_can('manage_options') ) {
693
- ?>
694
- <input type="checkbox" name="move_yearmonth_folders" form="mediafromftp_settings_form" value="1" <?php checked('1', get_option('uploads_use_yearmonth_folders')); ?> />
695
- <?php
696
- } else {
697
- ?>
698
- <input type="checkbox" form="mediafromftp_settings_form" disabled="disabled" value="1" <?php checked('1', get_option('uploads_use_yearmonth_folders')); ?> />
699
- <input type="hidden" name="move_yearmonth_folders" form="mediafromftp_settings_form" value="<?php echo get_option('uploads_use_yearmonth_folders'); ?>">
700
- <?php
701
- }
702
- _e('Organize my uploads into month- and year-based folders');
703
- ?>
704
- </div>
705
-
706
- <div style="display: block; padding:5px 5px">
707
- <input type="checkbox" name="mediafromftp_datetimepicker" form="mediafromftp_settings_form" value="1" <?php checked('1', $mediafromftp_settings['datetimepicker']); ?> />
708
- <a href="https://xdsoft.net/jqplugins/datetimepicker/" target="_blank" style="text-decoration: none;">Date Time Picker</a>(jQuery <?php _e('Plugin'); ?>)
709
- <?php _e('Date and time input assistance', 'media-from-ftp'); ?>
710
- </div>
711
-
712
- </div>
713
-
714
- <div class="item-mediafromftp-settings">
715
- <h3><?php _e('Log', 'media-from-ftp'); ?></h3>
716
- <div style="display:block;padding:5px 0">
717
- <?php _e('Record the registration result.', 'media-from-ftp'); ?>
718
- </div>
719
- <div style="display:block;padding:5px 0">
720
- <input type="checkbox" name="mediafromftp_apply_log" form="mediafromftp_settings_form" value="1" <?php checked('1', $mediafromftp_settings['log']); ?> />
721
- <?php _e('Create log', 'media-from-ftp'); ?>
722
- </div>
723
- </div>
724
-
725
- <div class="item-mediafromftp-settings">
726
- <h3><?php _e('Schedule', 'media-from-ftp'); ?>(<?php _e('Cron Event', 'media-from-ftp'); ?>)</h3>
727
- <div style="display:block;padding:5px 0">
728
- <?php _e('Set the schedule.', 'media-from-ftp'); ?>
729
- </div>
730
- <?php
731
- if ($mediafromftp_addon_wpcron) {
732
- $mediafromftpaddonwpcron->mediafromftp_schedule_form($scriptname, $mediafromftp_settings);
733
- } else {
734
- $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>';
735
- $use_add_on_html = sprintf(__('This function requires %1$s.', 'media-from-ftp'), $add_on_url);
736
- ?>
737
- <div style="display:block;padding:5px 0">
738
- <?php echo $use_add_on_html; ?>
739
- </div>
740
- <?php
741
- }
742
- ?>
743
- </div>
744
-
745
- <div class="item-mediafromftp-settings">
746
- <h3><?php _e('Categories'); ?></h3>
747
- <div style="display:block;padding:5px 0">
748
- <?php _e('Specify categories to register at the same time when registering.', 'media-from-ftp'); ?>
749
- </div>
750
- <?php
751
- if ($mediafromftp_addon_category) {
752
- $mlccs = explode(',', $mediafromftp_settings['mlcc']);
753
- $emlcs = explode(',', $mediafromftp_settings['emlc']);
754
- $mlacs = explode(',', $mediafromftp_settings['mlac']);
755
- $mlats = explode(',', $mediafromftp_settings['mlat']);
756
- echo $mediafromftpaddoncategory->mlc_category_admin_html($mlccs);
757
- echo $mediafromftpaddoncategory->eml_category_admin_html($emlcs);
758
- echo $mediafromftpaddoncategory->mla_category_admin_html($mlacs, $mlats);
759
- } else {
760
- $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>';
761
- $use_add_on_html = sprintf(__('This function requires %1$s.', 'media-from-ftp'), $add_on_url);
762
- ?>
763
- <div style="display:block;padding:5px 0">
764
- <?php echo $use_add_on_html; ?>
765
- </div>
766
- <?php
767
- }
768
- ?>
769
- </div>
770
-
771
- <div class="item-mediafromftp-settings">
772
- <h3>Exif <?php _e('Caption'); ?></h3>
773
- <div style="display:block;padding:5px 0">
774
- <?php _e('Register the Exif data to the caption.', 'media-from-ftp'); ?>
775
- </div>
776
- <?php
777
- if ($mediafromftp_addon_exif) {
778
- $mediafromftpaddonexif->mediafromftp_exif_form($mediafromftp_settings);
779
- } else {
780
- $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>';
781
- $use_add_on_html = sprintf(__('This function requires %1$s.', 'media-from-ftp'), $add_on_url);
782
- ?>
783
- <div style="display:block;padding:5px 0">
784
- <?php echo $use_add_on_html; ?>
785
- </div>
786
- <?php
787
- }
788
- ?>
789
- </div>
790
-
791
- <div style="clear: both;"></div>
792
-
793
- <form method="post" id="mediafromftp_settings_form" action="<?php echo $scriptname; ?>">
794
- <?php wp_nonce_field('mff_settings', 'media_from_ftp_settings'); ?>
795
- <div style="display: block;padding:5px 5px">
796
- <?php submit_button( __('Save Changes'), 'large', 'media-from-ftp-settings-options-apply', FALSE ); ?>
797
- </div>
798
- </form>
799
-
800
- </div>
801
- </div>
802
-
803
- <div id="mediafromftp-settings-tabs-2">
804
- <div style="display: block; padding: 5px 15px">
805
- <form method="post" id="mediafromftp_search_form" action="<?php echo $scriptname; ?>">
806
- <?php wp_nonce_field('mff_search', 'media_from_ftp_search'); ?>
807
- <div class="item-mediafromftp-settings">
808
- <h3><?php echo __('Search').' '.__('directory', 'media-from-ftp').' - '.__('type', 'media-from-ftp').' - '.__('extension', 'media-from-ftp'); ?></h3>
809
- <?php echo $mediafromftp->dir_select_box($mediafromftp_settings['searchdir'], $mediafromftp_settings['character_code'], wp_normalize_path(ABSPATH)); ?>
810
- <?php echo $mediafromftp->type_ext_select_box($mediafromftp_settings['ext2typefilter'], $mediafromftp_settings['extfilter']); ?>
811
- </div>
812
- <?php echo $mediafromftp->search_option_html($mediafromftp_settings); ?>
813
- <div style="display: block;padding:5px 5px">
814
- <?php submit_button( __('Save Changes'), 'large', 'media-from-ftp-search-options-apply', FALSE ); ?>
815
- </div>
816
- </form>
817
- </div>
818
- </div>
819
-
820
- <div id="mediafromftp-settings-tabs-3">
821
- <div style="display: block; padding: 5px 15px">
822
-
823
- <div class="item-mediafromftp-settings">
824
- <h3><?php _e('Limit number of search files', 'media-from-ftp'); ?></h3>
825
- <p>
826
- <?php _e('If you can not search because there are too many files, please reduce this number.', 'media-from-ftp'); ?>
827
- </p>
828
- <div style="display:block;padding:5px 0">
829
- <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" >
830
- </div>
831
- <div style="clear: both;"></div>
832
- </div>
833
-
834
- <div class="item-mediafromftp-settings">
835
- <h3><?php _e('Execution time', 'media-from-ftp'); ?></h3>
836
- <div style="display:block; padding:5px 5px">
837
- <?php
838
- $max_execution_time = $mediafromftp_settings['max_execution_time'];
839
- if ( !@set_time_limit($max_execution_time) ) {
840
- $limit_seconds_html = '<font color="red">'.$def_max_execution_time.__('seconds', 'media-from-ftp').'</font>';
841
- ?>
842
- <?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')); ?>
843
- <input type="hidden" name="mediafromftp_max_execution_time" form="mediafromftp_settings_form" value="<?php echo $def_max_execution_time; ?>" />
844
- <?php
845
- } else {
846
- $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>]'.')';
847
- _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');
848
- _e('It does not matter on the registration screen.', 'media-from-ftp');
849
- ?>
850
- <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>
851
- <?php
852
- }
853
- ?>
854
- </div>
855
- <div style="clear: both;"></div>
856
- </div>
857
-
858
- <?php
859
- if ( function_exists('mb_check_encoding') ) {
860
- ?>
861
- <div class="item-mediafromftp-settings">
862
- <h3><?php _e('Character Encodings for Server', 'media-from-ftp'); ?></h3>
863
- <p>
864
- <?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');
865
- $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>';
866
- 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>');
867
- ?>
868
- </p>
869
- <select name="mediafromftp_character_code" form="mediafromftp_settings_form" style="width: 210px">
870
- <?php
871
- if ( 'none' === $mediafromftp_settings['character_code'] ) {
872
- ?>
873
- <option value="none" selected>none</option>
874
- <?php
875
- } else {
876
- ?>
877
- <option value="none">none</option>
878
- <?php
879
- }
880
- foreach (mb_list_encodings() as $chrcode) {
881
- if ( $chrcode <> 'pass' && $chrcode <> 'auto' ) {
882
- if ( $chrcode === $mediafromftp_settings['character_code'] ) {
883
- ?>
884
- <option value="<?php echo $chrcode; ?>" selected><?php echo $chrcode; ?></option>
885
- <?php
886
- } else {
887
- ?>
888
- <option value="<?php echo $chrcode; ?>"><?php echo $chrcode; ?></option>
889
- <?php
890
- }
891
- }
892
- }
893
- ?>
894
- </select>
895
- <div style="clear: both;"></div>
896
- </div>
897
- <?php
898
- }
899
- ?>
900
-
901
- <div class="item-mediafromftp-settings">
902
- <h3><?php _e('Remove Thumbnails Cache', 'media-from-ftp'); ?></h3>
903
- <div style="display:block;padding:5px 0">
904
- <?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'); ?>
905
- </div>
906
- <form method="post" action="<?php echo $scriptname; ?>" />
907
- <?php wp_nonce_field('mff_clear_cash', 'media_from_ftp_clear_cash'); ?>
908
- <input type="hidden" name="mediafromftp_clear_cash" value="1" />
909
- <div>
910
- <?php submit_button( __('Remove Thumbnails Cache', 'media-from-ftp'), 'delete', '', FALSE); ?>
911
- </div>
912
- </form>
913
- </div>
914
-
915
- <div style="clear: both;"></div>
916
-
917
- <div style="display: block;padding:5px 5px">
918
- <?php submit_button( __('Save Changes'), 'large', 'media-from-ftp-settings-options-apply', FALSE, array( 'form' => 'mediafromftp_settings_form' ) ); ?>
919
- </div>
920
-
921
- </div>
922
- </div>
923
-
924
- <?php
925
- if ( $this->is_add_on_activate['cli'] ) {
926
- $mediafromftpcli->mediafromftp_command_line_html($this->wp_options_name());
927
- unset($mediafromftpcli);
928
- }
929
- ?>
930
-
931
- </div>
932
- </div>
933
- <?php
934
- unset($mediafromftpaddonwpcron);
935
- unset($mediafromftpaddoncategory);
936
- }
937
-
938
- /* ==================================================
939
- * Sub Menu
940
- */
941
- public function search_register_page(){
942
-
943
- if ( !current_user_can( 'upload_files' ) ) {
944
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
945
- }
946
-
947
- if ( isset($_POST['media_from_ftp_search']) && $_POST['media_from_ftp_search'] ) {
948
- if ( check_admin_referer('mff_search', 'media_from_ftp_search') ) {
949
- $submenu = 2;
950
- $this->options_updated($submenu);
951
- }
952
- }
953
- $mediafromftp_settings = get_option($this->wp_options_name());
954
-
955
- $def_max_execution_time = ini_get('max_execution_time');
956
- $max_execution_time = $mediafromftp_settings['max_execution_time'];
957
-
958
- $limit_seconds_html = '<font color="red">'.$def_max_execution_time.__('seconds', 'media-from-ftp').'</font>';
959
-
960
- if ( !@set_time_limit($max_execution_time) ) {
961
- 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>';
962
- }
963
-
964
- ?>
965
- <div class="wrap">
966
-
967
- <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>
968
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" class="page-title-action"><?php _e('Settings'); ?></a>
969
- <?php
970
- $mediafromftp = new MediaFromFtp();
971
- if ( $this->is_add_on_activate['wpcron'] ) {
972
- $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
973
- $mediafromftpaddonwpcron->mediafromftp_event_link_html();
974
- unset($mediafromftpaddonwpcron);
975
- }
976
- ?>
977
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" class="page-title-action"><?php _e('Log', 'media-from-ftp'); ?></a>
978
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-import'); ?>" class="page-title-action"><?php _e('Import'); ?></a>
979
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-addons'); ?>" class="page-title-action"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
980
- </h2>
981
- <div style="clear: both;"></div>
982
-
983
- <div id="mediafromftp-loading"><img src="<?php echo $this->plugin_base_url.'/css/loading.gif'; ?>"></div>
984
- <div id="mediafromftp-loading-container">
985
- <?php
986
- $MediaFromFtpListTable = new TT_MediaFromFtp_List_Table();
987
- $MediaFromFtpListTable->prepare_items($mediafromftp_settings);
988
- if ( $MediaFromFtpListTable->max_items > 0 ) {
989
- $update_button = get_submit_button( __('Update Media'), 'primary', '', FALSE, array('form' => 'mediafromftp_ajax_update') );
990
- $update_upper_button = '<div style="padding: 15px 15px 0px;">'.$update_button.'</div>';
991
- $update_lower_button = '<div style="padding: 0px 15px;">'.$update_button.'</div>';
992
- } else {
993
- $update_upper_button = NULL;
994
- $update_lower_button = NULL;
995
- }
996
- ?>
997
- <?php $mediafromftp->form_html($mediafromftp_settings); ?>
998
- <form method="post" id="mediafromftp_ajax_update">
999
- <form id="media-from-ftp-filter" method="get">
1000
- <input type="hidden" name="page" value="<?php echo esc_attr($_GET['page']); ?>" />
1001
- <?php echo $update_upper_button; ?>
1002
- <?php $MediaFromFtpListTable->display(); ?>
1003
- <?php echo $update_lower_button; ?>
1004
- </form>
1005
- </form>
1006
- </div>
1007
- </div>
1008
- <?php
1009
- unset($mediafromftp);
1010
- }
1011
-
1012
- /* ==================================================
1013
- * Bulk Change Date Time
1014
- * @since 9.63
1015
- */
1016
- public function custom_bulk_admin_footer() {
1017
- $mediafromftp_settings = get_option($this->wp_options_name());
1018
- if ( $mediafromftp_settings['dateset'] === 'server' || $mediafromftp_settings['dateset'] === 'exif' ) {
1019
- if ($this->is_my_plugin_screen3()) {
1020
- $now_date_time = date_i18n("Y-m-d H:i");
1021
- $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>';
1022
-
1023
- ?>
1024
- <script type="text/javascript">
1025
- jQuery('<?php echo $html; ?>').prependTo("#datetime");
1026
- </script>
1027
- <?php
1028
- }
1029
- }
1030
- }
1031
-
1032
- /* ==================================================
1033
- * Sub Menu
1034
- * for media-from-ftp-add-on-wpcron
1035
- */
1036
- public function event_page() {
1037
-
1038
- $mediafromftp_addon_wpcron = FALSE;
1039
- $mediafromftp = new MediaFromFtp();
1040
- if ( $this->is_add_on_activate['wpcron'] ) {
1041
- $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1042
- include_once $this->plugin_dir.'/media-from-ftp-add-on-wpcron/req/MediaFromFtpCron.php';
1043
- $mediafromftpcron = new MediaFromFtpCron();
1044
- $mediafromftp_addon_wpcron = TRUE;
1045
- }
1046
-
1047
- if ( !current_user_can( 'upload_files' ) || !$mediafromftp_addon_wpcron ) {
1048
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1049
- }
1050
-
1051
- if ( isset($_POST['media_from_ftp_run_cron']) && $_POST['media_from_ftp_run_cron'] ) {
1052
- if ( check_admin_referer('mff_run_cron', 'media_from_ftp_run_cron') ) {
1053
- $submenu = 4;
1054
- $this->options_updated($submenu);
1055
- }
1056
- }
1057
-
1058
- ?>
1059
- <div class="wrap">
1060
-
1061
- <h2>Media from FTP <?php echo $mediafromftpaddonwpcron->mediafromftp_event_top_link_html(); ?>
1062
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" class="page-title-action"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
1063
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" class="page-title-action"><?php _e('Settings'); ?></a>
1064
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" class="page-title-action"><?php _e('Log', 'media-from-ftp'); ?></a>
1065
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-import'); ?>" class="page-title-action"><?php _e('Import'); ?></a>
1066
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-addons'); ?>" class="page-title-action"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
1067
- </h2>
1068
- <div style="clear: both;"></div>
1069
- <p>
1070
- <?php
1071
-
1072
- if ( isset($_POST['media_from_ftp_event']) && $_POST['media_from_ftp_event'] ) {
1073
- if ( check_admin_referer('mff_event', 'media_from_ftp_event') ) {
1074
- if ( isset($_POST['event-mediafromftp']) && $_POST['event-mediafromftp'] ) {
1075
- $events_mediafromftp = $mediafromftp->sanitize_array($_POST['event-mediafromftp']);
1076
- $events = get_option( $this->wp_add_on_wpcron_events_name() );
1077
- $event_names = NULL;
1078
- foreach ($events_mediafromftp as $key => $event_id ) {
1079
- $option_name = $events[$event_id];
1080
- $mediafromftpcron->CronStop($option_name);
1081
- delete_option($option_name);
1082
- $event_names .= ' '.$event_id.' ';
1083
- unset($events[$event_id]);
1084
- update_option($this->wp_add_on_wpcron_events_name(), $events);
1085
- }
1086
- unset($mediafromftpcron);
1087
- echo $mediafromftpaddonwpcron->mediafromftp_event_notice_html($event_names);
1088
- }
1089
- }
1090
- }
1091
-
1092
- $scriptname = admin_url('admin.php?page=mediafromftp-event');
1093
-
1094
- echo $mediafromftpaddonwpcron->mediafromftp_event_html( $scriptname, get_option($this->wp_add_on_wpcron_events_name()) );
1095
-
1096
- ?>
1097
- </div>
1098
- <?php
1099
-
1100
- }
1101
-
1102
- /* ==================================================
1103
- * Sub Menu
1104
- */
1105
- public function log_page() {
1106
-
1107
- if ( !current_user_can( 'upload_files' ) ) {
1108
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1109
- }
1110
-
1111
- $mediafromftp_settings = get_option($this->wp_options_name());
1112
- if ( !$mediafromftp_settings['log'] ) {
1113
- 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>';
1114
- }
1115
- $def_max_execution_time = ini_get('max_execution_time');
1116
- $max_execution_time = $mediafromftp_settings['max_execution_time'];
1117
-
1118
- $limit_seconds_html = '<font color="red">'.$def_max_execution_time.__('seconds', 'media-from-ftp').'</font>';
1119
- if ( !@set_time_limit($max_execution_time) ) {
1120
- 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>';
1121
- }
1122
-
1123
- ?>
1124
- <div class="wrap">
1125
-
1126
- <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>
1127
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" class="page-title-action"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
1128
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" class="page-title-action"><?php _e('Settings'); ?></a>
1129
- <?php
1130
- if ( $this->is_add_on_activate['wpcron'] ) {
1131
- $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1132
- $mediafromftpaddonwpcron->mediafromftp_event_link_html();
1133
- unset($mediafromftpaddonwpcron);
1134
- }
1135
- ?>
1136
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-import'); ?>" class="page-title-action"><?php _e('Import'); ?></a>
1137
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-addons'); ?>" class="page-title-action"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
1138
- </h2>
1139
- <div style="clear: both;"></div>
1140
-
1141
- <div id="mediafromftp-loading"><img src="<?php echo $this->plugin_base_url.'/css/loading.gif'; ?>"></div>
1142
- <div id="mediafromftp-loading-container">
1143
- <?php
1144
- global $wpdb;
1145
-
1146
- $user = wp_get_current_user();
1147
-
1148
- $table_name = $wpdb->prefix.'mediafromftp_log';
1149
-
1150
- if ( isset($_POST['media_from_ftp_clear_log']) && $_POST['media_from_ftp_clear_log'] ) {
1151
- if ( check_admin_referer('mff_clear_log', 'media_from_ftp_clear_log') ) {
1152
- if ( !empty($_POST['mediafromftp_clear_log']) && $_POST['mediafromftp_clear_log'] == 1 ) {
1153
- if ( current_user_can('administrator') ) {
1154
- $wpdb->query("DELETE FROM $table_name");
1155
- echo '<div class="notice notice-success is-dismissible"><ul><li>'.__('Removed all of the log.', 'media-from-ftp').'</li></ul></div>';
1156
- } else {
1157
- $delete_count = $wpdb->delete($table_name, array( 'user' => $user->display_name ));
1158
- if ( $delete_count > 0 ) {
1159
- 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>';
1160
- } else {
1161
- 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>';
1162
- }
1163
- }
1164
- }
1165
- }
1166
- }
1167
-
1168
- $records = $wpdb->get_results("SELECT * FROM $table_name");
1169
-
1170
- $csv = NULL;
1171
- $max_thumbnail_count = 0;
1172
- $max_mlccategories_count = 0;
1173
- $max_emlcategories_count = 0;
1174
- $max_mlacategories_count = 0;
1175
- $max_mlatags_count = 0;
1176
- $html = '<table>';
1177
-
1178
- foreach ( $records as $record ) {
1179
- $csvs = '"'.$record->id.'","'.$record->user.'","'.$record->title.'","'.$record->permalink.'","'.$record->url.'","'.$record->filename.'","'.$record->time.'","'.$record->filetype.'","'.$record->filesize.'","'.$record->exif.'","'.$record->length.'"';
1180
- $html_thumbnail = NULL;
1181
- if ( $record->thumbnail ) {
1182
- $thumbnails = json_decode($record->thumbnail, true);
1183
- if ( $max_thumbnail_count < count($thumbnails) ) {
1184
- $max_thumbnail_count = count($thumbnails);
1185
- }
1186
- $count = 0;
1187
- foreach ( $thumbnails as $thumbnail ) {
1188
- ++$count;
1189
- $html_thumbnail .= '<tr><th align="right" style="white-space: nowrap;">'.__('Featured Image').$count.':</th><td>'.$thumbnail.'</td></tr>';
1190
- $csvs .= ',"'.$thumbnail.'"';
1191
- }
1192
- }
1193
- $html_mlccategory = NULL;
1194
- if ( $record->mlccategories ) {
1195
- $mlccategories = json_decode($record->mlccategories, true);
1196
- if ( $max_mlccategories_count < count($mlccategories) ) {
1197
- $max_mlccategories_count = count($mlccategories);
1198
- }
1199
- $count = 0;
1200
- foreach ( $mlccategories as $mlccategory ) {
1201
- ++$count;
1202
- $html_mlccategory .= '<tr><th align="right" style="white-space: nowrap;">'.__('Categories').'[Media Library Categories]'.$count.':</th><td>'.$mlccategory.'</td></tr>';
1203
- $csvs .= ',"'.$mlccategory.'"';
1204
- }
1205
- }
1206
- $html_emlcategory = NULL;
1207
- if ( $record->emlcategories ) {
1208
- $emlcategories = json_decode($record->emlcategories, true);
1209
- if ( $max_emlcategories_count < count($emlcategories) ) {
1210
- $max_emlcategories_count = count($emlcategories);
1211
- }
1212
- $count = 0;
1213
- foreach ( $emlcategories as $emlcategory ) {
1214
- ++$count;
1215
- $html_emlcategory .= '<tr><th align="right" style="white-space: nowrap;">'.__('Categories').'[Enhanced Media Library]'.$count.':</th><td>'.$emlcategory.'</td></tr>';
1216
- $csvs .= ',"'.$emlcategory.'"';
1217
- }
1218
- }
1219
- $html_mlacategory = NULL;
1220
- if ( $record->mlacategories ) {
1221
- $mlacategories = json_decode($record->mlacategories, true);
1222
- if ( $max_mlacategories_count < count($mlacategories) ) {
1223
- $max_mlacategories_count = count($mlacategories);
1224
- }
1225
- $count = 0;
1226
- foreach ( $mlacategories as $mlacategory ) {
1227
- ++$count;
1228
- $html_mlacategory .= '<tr><th align="right" style="white-space: nowrap;">'.__('Categories').'[Media Library Assistant]'.$count.':</th><td>'.$mlacategory.'</td></tr>';
1229
- $csvs .= ',"'.$mlacategory.'"';
1230
- }
1231
- }
1232
- $html_mlatag = NULL;
1233
- if ( $record->mlatags ) {
1234
- $mlatags = json_decode($record->mlatags, true);
1235
- if ( $max_mlatags_count < count($mlatags) ) {
1236
- $max_mlatags_count = count($mlatags);
1237
- }
1238
- $count = 0;
1239
- foreach ( $mlatags as $mlatag ) {
1240
- ++$count;
1241
- $html_mlatag .= '<tr><th align="right" style="white-space: nowrap;">'.__('Tags').'[Media Library Assistant]'.$count.':</th><td>'.$mlatag.'</td></tr>';
1242
- $csvs .= ',"'.$mlatag.'"';
1243
- }
1244
- }
1245
- $csvs .= "\n";
1246
- $csv .= $csvs;
1247
- $html .= '<tr><th>&nbsp;</th><td>&nbsp;</td></tr>';
1248
- $html .= '<tr><th align="right" style="background-color: #cccccc;">ID:</th><td>'.$record->id.'</td></tr>';
1249
- $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('Author').':</th><td>'.$record->user.'</td></tr>';
1250
- $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('Title').':</th><td>'.$record->title.'</td></tr>';
1251
- $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('Permalink:').'</th><td>'.$record->permalink.'</td></tr>';
1252
- $html .= '<tr><th align="right" style="white-space: nowrap;">URL:</th><td>'.$record->url.'</td>';
1253
- $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('File name:').'</th><td>'.$record->filename.'</td></tr>';
1254
- $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('Date/Time').':</th><td>'.$record->time.'</td></tr>';
1255
- $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('File type:').'</th><td>'.$record->filetype.'</td></tr>';
1256
- $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('File size:').'</th><td>'.$record->filesize.'</td></tr>';
1257
- if ( $record->exif ) {
1258
- $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('Caption').'[Exif]:</th><td>'.$record->exif.'</td></tr>';
1259
- }
1260
- if ( $record->length ) {
1261
- $html .= '<tr><th align="right" style="white-space: nowrap;">'.__('Length:').'</th><td>'.$record->length.'</td></tr>';
1262
- }
1263
- $html .= $html_thumbnail.$html_mlccategory.$html_emlcategory.$html_mlacategory.$html_mlatag;
1264
- }
1265
- $html .= '</table>'."\n";
1266
- $csv_head = '"ID","'.__('Author').'","'.__('Title').':","'.__('Permalink:').'","URL:","'.__('File name:').'","'.__('Date/Time').':","'.__('File type:').'","'.__('File size:').'","'.__('Caption').'[Exif]:","'.__('Length:').'"';
1267
- for ($i = 1 ; $i <= $max_thumbnail_count; $i++) {
1268
- $csv_head .= ',"'.__('Featured Image').$i.'"';
1269
- }
1270
- for ($i = 1 ; $i <= $max_mlccategories_count; $i++) {
1271
- $csv_head .= ',"'.__('Categories').'[Media Library Categories]'.$i.'"';
1272
- }
1273
- for ($i = 1 ; $i <= $max_emlcategories_count; $i++) {
1274
- $csv_head .= ',"'.__('Categories').'[Enhanced Media Library]'.$i.'"';
1275
- }
1276
- for ($i = 1 ; $i <= $max_mlacategories_count; $i++) {
1277
- $csv_head .= ',"'.__('Categories').'[Media Library Assistant]'.$i.'"';
1278
- }
1279
- for ($i = 1 ; $i <= $max_mlatags_count; $i++) {
1280
- $csv_head .= ',"'.__('Tags').'[Media Library Assistant]'.$i.'"';
1281
- }
1282
-
1283
- $csv = $csv_head."\n".$csv;
1284
-
1285
- $csvFileName = $this->plugin_tmp_dir.'/'.$table_name.'.csv';
1286
- if ( isset($_POST['media_from_ftp_put_log']) && $_POST['media_from_ftp_put_log'] ) {
1287
- if ( check_admin_referer('mff_put_log', 'media_from_ftp_put_log') ) {
1288
- if ( !empty($_POST['mediafromftp_put_log']) && $_POST['mediafromftp_put_log'] == 1 ) {
1289
- file_put_contents($csvFileName, pack('C*',0xEF,0xBB,0xBF)); //UTF-8 BOM
1290
- file_put_contents($csvFileName, $csv, FILE_APPEND | LOCK_EX);
1291
- }
1292
- }
1293
- } else {
1294
- if ( file_exists($csvFileName) ) {
1295
- unlink($csvFileName);
1296
- }
1297
- }
1298
-
1299
- if ( !empty($records) ) {
1300
- ?>
1301
- <div style="display: block; padding: 10px 10px">
1302
- <form style="float: left;" method="post" action="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" />
1303
- <?php wp_nonce_field('mff_clear_log', 'media_from_ftp_clear_log'); ?>
1304
- <input type="hidden" name="mediafromftp_clear_log" value="1" />
1305
- <div>
1306
- <?php submit_button( __('Delete log', 'media-from-ftp'), 'large', '', FALSE ); ?>
1307
- </div>
1308
- </form>
1309
- <form style="float: left; margin-left: 0.5em; margin-right: 0.5em;" method="post" action="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" />
1310
- <?php wp_nonce_field('mff_put_log', 'media_from_ftp_put_log'); ?>
1311
- <input type="hidden" name="mediafromftp_put_log" value="1" />
1312
- <div>
1313
- <?php submit_button( __('Export to CSV', 'media-from-ftp'), 'large', '', FALSE ); ?>
1314
- </div>
1315
- </form>
1316
- <?php
1317
- if ( file_exists($csvFileName) ) {
1318
- ?>
1319
- <form method="post" action="<?php echo $this->plugin_tmp_url.'/'.$table_name.'.csv'; ?>" />
1320
- <?php wp_nonce_field('mff_download', 'media_from_ftp_download'); ?>
1321
- <div>
1322
- <input type="hidden" name="mediafromftp_download" value="1" />
1323
- <?php submit_button( __('Download CSV', 'media-from-ftp'), 'large', '', FALSE ); ?>
1324
- </div>
1325
- </form>
1326
- <?php
1327
- }
1328
- ?>
1329
- </div>
1330
- <div style="clear: both;"></div>
1331
- <div style="display: block; padding: 10px 10px">
1332
- <?php echo $html;
1333
- ?>
1334
- </div>
1335
- <?php
1336
- } else {
1337
- if ( $mediafromftp_settings['log'] ) {
1338
- echo '<div class="notice notice-info is-dismissible"><ul><li>'.__('There is no log.', 'media-from-ftp').'</li></ul></div>';
1339
- }
1340
- }
1341
- ?>
1342
- </div>
1343
-
1344
- </div>
1345
-
1346
- <?php
1347
-
1348
- }
1349
-
1350
- /* ==================================================
1351
- * Sub Menu
1352
- */
1353
- public function medialibrary_import_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-import');
1360
-
1361
- ?>
1362
- <div class="wrap">
1363
- <h2>Media from FTP <a href="<?php echo $scriptname; ?>" style="text-decoration: none;"><?php _e('Import'); ?></a>
1364
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" class="page-title-action"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
1365
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" class="page-title-action"><?php _e('Settings'); ?></a>
1366
- <?php
1367
- if ( $this->is_add_on_activate['wpcron'] ) {
1368
- $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1369
- $mediafromftpaddonwpcron->mediafromftp_event_link_html();
1370
- unset($mediafromftpaddonwpcron);
1371
- }
1372
- ?>
1373
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" class="page-title-action"><?php _e('Log', 'media-from-ftp'); ?></a>
1374
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-addons'); ?>" class="page-title-action"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
1375
- </h2>
1376
- <div style="clear: both;"></div>
1377
-
1378
- <div id="mediafromftp-loading"><img src="<?php echo $this->plugin_base_url.'/css/loading.gif'; ?>"></div>
1379
- <div id="medialibraryimport-loading-container">
1380
-
1381
- <?php
1382
- if ( isset($_POST['media_from_ftp_file_load']) && $_POST['media_from_ftp_file_load'] ) {
1383
- if ( check_admin_referer('mff_file_load', 'media_from_ftp_file_load') ) {
1384
- if ( !empty($_FILES['filename']['name']) ) {
1385
- $filename = $_FILES['filename']['tmp_name'];
1386
- $name = basename($filename);
1387
- move_uploaded_file($filename, $this->plugin_tmp_dir.'/'.$name);
1388
-
1389
- $mediafromftp = new MediaFromFtp();
1390
- ?>
1391
- <h4><?php _e('Assign Authors', 'media-from-ftp'); ?></h4>
1392
- <?php
1393
- echo $mediafromftp->author_select($this->plugin_tmp_dir.'/'.$name);
1394
- }
1395
- }
1396
- } else if ( isset($_POST['media_from_ftp_select_author']) && $_POST['media_from_ftp_select_author'] ) {
1397
- if ( check_admin_referer('mff_select_author', 'media_from_ftp_select_author') ) {
1398
- if ( !empty($_POST['mediafromftp_select_author']) && !empty($_POST['mediafromftp_xml_file']) ) {
1399
- if ( validate_file($_POST['mediafromftp_xml_file']) ){
1400
- echo '<div class="notice notice-error is-dismissible"><ul><li>'.__('No such file exists! Double check the name and try again.').'</li></ul></div>';
1401
- ?>
1402
- <form method="post" action="<?php echo $scriptname; ?>" enctype="multipart/form-data">
1403
- <?php wp_nonce_field('mff_file_load', 'media_from_ftp_file_load'); ?>
1404
- <h4><?php _e('Select File'); ?>[WordPress eXtended RSS (WXR)(.xml)]</h4>
1405
- <div><input name="filename" type="file" size="80" /></div>
1406
- <div>
1407
- <?php submit_button( __('File Load', 'media-from-ftp'), 'large', '', FALSE ); ?>
1408
- </div>
1409
- </form>
1410
- <?php
1411
- } else {
1412
- ?>
1413
- <h4><?php _e('Ready to import. Press the following button to start the import.', 'media-from-ftp'); ?></h4>
1414
- <form method="post" id="medialibraryimport_ajax_update">
1415
- <?php submit_button( __('Import'), 'primary', '', FALSE ); ?>
1416
- </form>
1417
- <?php
1418
- }
1419
- }
1420
- }
1421
- } else {
1422
- ?>
1423
- <form method="post" action="<?php echo $scriptname; ?>" enctype="multipart/form-data">
1424
- <?php wp_nonce_field('mff_file_load', 'media_from_ftp_file_load'); ?>
1425
- <h4><?php _e('Select File'); ?>[WordPress eXtended RSS (WXR)(.xml)]</h4>
1426
- <div><input name="filename" type="file" size="80" /></div>
1427
- <div>
1428
- <?php submit_button( __('File Load', 'media-from-ftp'), 'large', '', FALSE ); ?>
1429
- </div>
1430
- </form>
1431
- <?php
1432
- }
1433
- ?>
1434
-
1435
- </div>
1436
- </div>
1437
-
1438
- <?php
1439
- }
1440
-
1441
- /* ==================================================
1442
- * Sub Menu
1443
- */
1444
- public function addons_page() {
1445
-
1446
- if ( !current_user_can( 'upload_files' ) ) {
1447
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
1448
- }
1449
-
1450
- $scriptname = admin_url('admin.php?page=mediafromftp-addons');
1451
-
1452
- ?>
1453
- <div class="wrap">
1454
-
1455
- <h2>Media from FTP <a href="<?php echo $scriptname; ?>" style="text-decoration: none;"><?php _e('Add-Ons', 'media-from-ftp'); ?></a>
1456
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-search-register'); ?>" class="page-title-action"><?php _e('Search & Register', 'media-from-ftp'); ?></a>
1457
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-settings'); ?>" class="page-title-action"><?php _e('Settings'); ?></a>
1458
- <?php
1459
- if ( $this->is_add_on_activate['wpcron'] ) {
1460
- $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1461
- $mediafromftpaddonwpcron->mediafromftp_event_link_html();
1462
- unset($mediafromftpaddonwpcron);
1463
- }
1464
- ?>
1465
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-log'); ?>" class="page-title-action"><?php _e('Log', 'media-from-ftp'); ?></a>
1466
- <a href="<?php echo admin_url('admin.php?page=mediafromftp-import'); ?>" class="page-title-action"><?php _e('Import'); ?></a>
1467
- </h2>
1468
- <div style="clear: both;"></div>
1469
-
1470
- <div style="width: 300px; height: 100%; margin: 10px; padding: 10px; border: #CCC 2px solid; float: left;">
1471
- <h4>Media from FTP Add On Commandline</h4>
1472
- <div style="margin: 5px; padding: 5px;"><?php _e('This add-on can use "Media from FTP" on the command-line.', 'media-from-ftp'); ?></div>
1473
- <div style="margin: 5px; padding: 5px;">
1474
- <li><?php _e('The execution of the command line is supported.(lib/mediafromftpcmd.php)', 'media-from-ftp'); ?></li>
1475
- </div>
1476
- <p>
1477
- <?php
1478
- if ( is_dir($this->plugin_dir.'/media-from-ftp-add-on-cli') ) {
1479
- ?><div style="margin: 5px; padding: 5px;"><strong><?php
1480
- _e('Installed', 'media-from-ftp');?> & <?php
1481
- if ( $this->is_add_on_activate['cli'] ) {
1482
- _e('Activated', 'media-from-ftp');
1483
- } else {
1484
- _e('Deactivated', 'media-from-ftp');
1485
- }
1486
- ?></strong></div><?php
1487
- } else {
1488
- ?>
1489
- <div>
1490
- <a href="<?php _e('https://shop.riverforest-wp.info/media-from-ftp-add-on-cli/', 'media-from-ftp'); ?>" target="_blank" class="page-title-action"><?php _e('BUY', 'media-from-ftp'); ?></a>
1491
- </div>
1492
- <?php
1493
- }
1494
- ?>
1495
- </div>
1496
-
1497
- <div style="width: 300px; height: 100%; margin: 10px; padding: 10px; border: #CCC 2px solid; float: left;">
1498
- <h4>Media from FTP Add On Wp Cron</h4>
1499
- <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>
1500
- <div style="margin: 5px; padding: 5px;">
1501
- <li><?php _e('Can start multiple Cron Events with multiple settings.', 'media-from-ftp'); ?></li>
1502
- <li><?php _e('Can add intervals of schedule.', 'media-from-ftp'); ?></li>
1503
- </div>
1504
- <p>
1505
- <?php
1506
- if ( is_dir($this->plugin_dir.'/media-from-ftp-add-on-wpcron') ) {
1507
- ?><div style="margin: 5px; padding: 5px;"><strong><?php
1508
- _e('Installed', 'media-from-ftp');?> & <?php
1509
- if ( $this->is_add_on_activate['wpcron'] ) {
1510
- _e('Activated', 'media-from-ftp');
1511
- } else {
1512
- _e('Deactivated', 'media-from-ftp');
1513
- }
1514
- ?></strong></div><?php
1515
- } else {
1516
- ?>
1517
- <div>
1518
- <a href="<?php _e('https://shop.riverforest-wp.info/media-from-ftp-add-on-wpcron/', 'media-from-ftp'); ?>" target="_blank" class="page-title-action"><?php _e('BUY', 'media-from-ftp'); ?></a>
1519
- </div>
1520
- <?php
1521
- }
1522
- ?>
1523
- </div>
1524
-
1525
- <div style="width: 300px; height: 100%; margin: 10px; padding: 10px; border: #CCC 2px solid; float: left;">
1526
- <h4>Media from FTP Add On Category</h4>
1527
- <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>
1528
- <div style="margin: 5px; padding: 5px;">
1529
- <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>
1530
- </div>
1531
- <p>
1532
- <?php
1533
- if ( is_dir($this->plugin_dir.'/media-from-ftp-add-on-category') ) {
1534
- ?><div style="margin: 5px; padding: 5px;"><strong><?php
1535
- _e('Installed', 'media-from-ftp');?> & <?php
1536
- if ( $this->is_add_on_activate['category'] ) {
1537
- _e('Activated', 'media-from-ftp');
1538
- } else {
1539
- _e('Deactivated', 'media-from-ftp');
1540
- }
1541
- ?></strong></div><?php
1542
- } else {
1543
- ?>
1544
- <div>
1545
- <a href="<?php _e('https://shop.riverforest-wp.info/media-from-ftp-add-on-category/', 'media-from-ftp'); ?>" target="_blank" class="page-title-action"><?php _e('BUY', 'media-from-ftp'); ?></a>
1546
- </div>
1547
- <?php
1548
- }
1549
- ?>
1550
- </div>
1551
-
1552
- <div style="width: 300px; height: 100%; margin: 10px; padding: 10px; border: #CCC 2px solid; float: left;">
1553
- <h4>Media from FTP Add On Exif</h4>
1554
- <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>
1555
- <div style="margin: 5px; padding: 5px;">
1556
- <li><?php _e('Sort each Exif data to an arbitrary position and insert it into the caption as text.', 'media-from-ftp'); ?></li>
1557
- <li><a style="text-decoration: none;" href="https://codex.wordpress.org/Function_Reference/wp_read_image_metadata#Return%20Values" target="_blank">Exif</a></li>
1558
- </div>
1559
-
1560
- <p>
1561
- <?php
1562
- if ( is_dir($this->plugin_dir.'/media-from-ftp-add-on-exif') ) {
1563
- ?><div style="margin: 5px; padding: 5px;"><strong><?php
1564
- _e('Installed', 'media-from-ftp');?> & <?php
1565
- if ( $this->is_add_on_activate['exif'] ) {
1566
- _e('Activated', 'media-from-ftp');
1567
- } else {
1568
- _e('Deactivated', 'media-from-ftp');
1569
- }
1570
- ?></strong></div><?php
1571
- } else {
1572
- ?>
1573
- <div>
1574
- <a href="<?php _e('https://shop.riverforest-wp.info/media-from-ftp-add-on-exif/', 'media-from-ftp'); ?>" target="_blank" class="page-title-action"><?php _e('BUY', 'media-from-ftp'); ?></a>
1575
- </div>
1576
- <?php
1577
- }
1578
- ?>
1579
- </div>
1580
-
1581
- <?php
1582
- }
1583
-
1584
- /* ==================================================
1585
- * Update wp_options table.
1586
- * @param int $submenu
1587
- * @since 2.36
1588
- */
1589
- private function options_updated($submenu){
1590
-
1591
- $mediafromftp = new MediaFromFtp();
1592
-
1593
- $mediafromftp_settings = get_option($this->wp_options_name());
1594
-
1595
- $addonwpcron = FALSE;
1596
- if ( $this->is_add_on_activate['wpcron'] ) {
1597
- $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1598
- $addonwpcron = TRUE;
1599
- }
1600
-
1601
- switch ($submenu) {
1602
- case 1:
1603
- $mediafromftp_settings['dateset'] = sanitize_text_field($_POST['mediafromftp_dateset']);
1604
- if ( !empty($_POST['mediafromftp_datefixed']) ) {
1605
- $mediafromftp_settings['datefixed'] = sanitize_text_field($_POST['mediafromftp_datefixed']);
1606
- }
1607
- if ( !empty($_POST['mediafromftp_datetimepicker']) ) {
1608
- $mediafromftp_settings['datetimepicker'] = 1;
1609
- } else {
1610
- $mediafromftp_settings['datetimepicker'] = FALSE;
1611
- }
1612
- $mediafromftp_settings['max_execution_time'] = intval($_POST['mediafromftp_max_execution_time']);
1613
- $mediafromftp_settings['character_code'] = sanitize_text_field($_POST['mediafromftp_character_code']);
1614
- if ( !empty($_POST['mediafromftp_cron_apply']) ) {
1615
- $mediafromftp_settings['cron']['apply'] = 1;
1616
- } else {
1617
- $mediafromftp_settings['cron']['apply'] = FALSE;
1618
- }
1619
- if ( !empty($_POST['mediafromftp_cron_schedule']) ) {
1620
- $mediafromftp_settings['cron']['schedule'] = sanitize_text_field($_POST['mediafromftp_cron_schedule']);
1621
- }
1622
- if ( !empty($_POST['mediafromftp_cron_limit_number']) ) {
1623
- $mediafromftp_settings['cron']['limit_number'] = intval($_POST['mediafromftp_cron_limit_number']);
1624
- } else {
1625
- $mediafromftp_settings['cron']['limit_number'] = FALSE;
1626
- }
1627
- if ( !empty($_POST['mediafromftp_cron_mail_apply']) ) {
1628
- $mediafromftp_settings['cron']['mail_apply'] = 1;
1629
- } else {
1630
- $mediafromftp_settings['cron']['mail_apply'] = FALSE;
1631
- }
1632
- if ( !empty($_POST['mediafromftp_caption_apply']) ) {
1633
- $mediafromftp_settings['caption']['apply'] = 1;
1634
- } else {
1635
- $mediafromftp_settings['caption']['apply'] = FALSE;
1636
- }
1637
- if ( !empty($_POST['mediafromftp_exif_text']) ) {
1638
- $mediafromftp_settings['caption']['exif_text'] = htmlspecialchars($_POST['mediafromftp_exif_text']);
1639
- }
1640
- if ( !empty($_POST['mediafromftp_exif_default']) ) {
1641
- $mediafromftp_settings['caption']['exif_text'] = '%title% %credit% %camera% %caption% %created_timestamp% %copyright% %aperture% %shutter_speed% %iso% %focal_length% %white_balance%';
1642
- }
1643
- if ( !empty($_POST['mediafromftp_apply_log']) ) {
1644
- $mediafromftp_settings['log'] = 1;
1645
- } else {
1646
- $mediafromftp_settings['log'] = FALSE;
1647
- }
1648
- if ( !empty($_POST['mediafromftp_search_limit_number']) ) {
1649
- if ( ctype_digit($_POST['mediafromftp_search_limit_number']) ) {
1650
- $search_limit_number = intval($_POST['mediafromftp_search_limit_number']);
1651
- $mediafromftp_settings['search_limit_number'] = $search_limit_number;
1652
- if ( $search_limit_number < 100 ) {
1653
- $mediafromftp_settings['search_limit_number'] = 100;
1654
- }
1655
- } else {
1656
- $mediafromftp_settings['search_limit_number'] = 100000;
1657
- }
1658
- } else {
1659
- $mediafromftp_settings['search_limit_number'] = 100000;
1660
- }
1661
- if ( !empty($_POST['mlc_category']) ) {
1662
- $mediafromftp_settings['mlcc'] = implode(',', $mediafromftp->sanitize_array($_POST['mlc_category']));
1663
- } else {
1664
- $mediafromftp_settings['mlcc'] = NULL;
1665
- }
1666
- if ( !empty($_POST['eml_category']) ) {
1667
- $mediafromftp_settings['emlc'] = implode(',', $mediafromftp->sanitize_array($_POST['eml_category']));
1668
- } else {
1669
- $mediafromftp_settings['emlc'] = NULL;
1670
- }
1671
- if ( !empty($_POST['mla_category']) ) {
1672
- $mediafromftp_settings['mlac'] = implode(',', $mediafromftp->sanitize_array($_POST['mla_category']));
1673
- } else {
1674
- $mediafromftp_settings['mlac'] = NULL;
1675
- }
1676
- if ( !empty($_POST['mla_tag']) ) {
1677
- $mediafromftp_settings['mlat'] = implode(',', $mediafromftp->sanitize_array($_POST['mla_tag']));
1678
- } else {
1679
- $mediafromftp_settings['mlat'] = NULL;
1680
- }
1681
- update_option( $this->wp_options_name(), $mediafromftp_settings );
1682
- if ( !empty($_POST['move_yearmonth_folders']) ) {
1683
- update_option( 'uploads_use_yearmonth_folders', 1 );
1684
- } else {
1685
- update_option( 'uploads_use_yearmonth_folders', 0 );
1686
- }
1687
- echo '<div class="notice notice-success is-dismissible"><ul><li>'.__('Settings').' --> '.__('Changes saved.').'</li></ul></div>';
1688
- break;
1689
- case 2:
1690
- if (!empty($_POST['mediafromftp_pagemax'])){
1691
- $mediafromftp_settings['pagemax'] = intval($_POST['mediafromftp_pagemax']);
1692
- }
1693
- if (!empty($_POST['searchdir'])){
1694
- $searchdir = urldecode($_POST['searchdir']);
1695
- if ( strpos( realpath(wp_normalize_path(ABSPATH.$searchdir)), $this->upload_dir) === FALSE ) {
1696
- $searchdir = $this->upload_path;
1697
- $mediafromftp_settings['basedir'] = $this->upload_path;
1698
- }
1699
- $mediafromftp_settings['searchdir'] = $searchdir;
1700
- } else {
1701
- if ( $this->upload_path <> $mediafromftp_settings['basedir'] ) {
1702
- $mediafromftp_settings['searchdir'] = $this->upload_path;
1703
- $mediafromftp_settings['basedir'] = $this->upload_path;
1704
- }
1705
- }
1706
- if (!empty($_POST['ext2type'])){
1707
- $ext2typefilter = sanitize_text_field($_POST['ext2type']);
1708
- } else {
1709
- $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
1710
- }
1711
- if (!empty($_POST['extension'])){
1712
- if ( $_POST['extension'] === 'all') {
1713
- $mediafromftp_settings['extfilter'] = 'all';
1714
- } else {
1715
- if ( $ext2typefilter === 'all' || $ext2typefilter === wp_ext2type($_POST['extension']) ) {
1716
- $mediafromftp_settings['extfilter'] = sanitize_text_field($_POST['extension']);
1717
- } else {
1718
- $mediafromftp_settings['extfilter'] = 'all';
1719
- }
1720
- }
1721
- }
1722
- $mediafromftp_settings['ext2typefilter'] = $ext2typefilter;
1723
- if (isset($_POST['search_display_metadata'])){
1724
- $mediafromftp_settings['search_display_metadata'] = sanitize_text_field($_POST['search_display_metadata']);
1725
- }
1726
- if (!empty($_POST['mediafromftp_exclude'])){
1727
- $mediafromftp_settings['exclude'] = sanitize_text_field(stripslashes($_POST['mediafromftp_exclude']));
1728
- }
1729
- if (isset($_POST['mediafromftp_recursive_search'])){
1730
- $mediafromftp_settings['recursive_search'] = sanitize_text_field($_POST['mediafromftp_recursive_search']);
1731
- }
1732
- if (isset($_POST['mediafromftp_thumb_deep_search'])){
1733
- $mediafromftp_settings['thumb_deep_search'] = sanitize_text_field($_POST['mediafromftp_thumb_deep_search']);
1734
- }
1735
- update_option( $this->wp_options_name(), $mediafromftp_settings );
1736
- break;
1737
- case 3:
1738
- if ( !empty($_POST['mediafromftp_clear_cash']) ) {
1739
- $del_cash_count = $mediafromftp->delete_all_cash();
1740
- if ( $del_cash_count > 0 ) {
1741
- echo '<div class="notice notice-success is-dismissible"><ul><li>'.__('Thumbnails Cache', 'media-from-ftp').' --> '.__('Delete').'</li></ul></div>';
1742
- } else {
1743
- echo '<div class="notice notice-info is-dismissible"><ul><li>'.__('No Thumbnails Cache', 'media-from-ftp').'</li></ul></div>';
1744
- }
1745
- }
1746
- break;
1747
- case 4:
1748
- // for media-from-ftp-add-on-wpcron
1749
- if ( $addonwpcron ) {
1750
- if ( !empty($_POST['mediafromftp_run_cron']) ) {
1751
- $mediafromftp_cron_events = get_option( $this->wp_add_on_wpcron_events_name() );
1752
- if ( !empty($_POST['cron-run']) ) {
1753
- $option_name = sanitize_text_field($_POST['cron-run']);
1754
- echo $mediafromftpaddonwpcron->CronRun($option_name);
1755
- } elseif ( !empty($_POST['cron-start']) ) {
1756
- $option_name = sanitize_text_field($_POST['cron-start']);
1757
- echo $mediafromftpaddonwpcron->CronRunStart($option_name);
1758
- } elseif ( !empty($_POST['cron-stop']) ) {
1759
- $option_name = sanitize_text_field($_POST['cron-stop']);
1760
- echo $mediafromftpaddonwpcron->CronRunStop($option_name);
1761
- }
1762
- }
1763
- } else {
1764
- $mediafromftp_settings['cron']['apply'] = FALSE;
1765
- update_option( $this->wp_options_name(), $mediafromftp_settings );
1766
- }
1767
- break;
1768
- case 5:
1769
- // for media-from-ftp-add-on-wpcron
1770
- if ( !empty($_POST['mediafromftp_add_schedule']) ) {
1771
- if ( !empty($_POST['mediafromftp_cron_schedule_innername']) && !empty($_POST['mediafromftp_cron_schedule_secounds']) && !empty($_POST['mediafromftp_cron_schedule_viewname']) ) {
1772
- $mediafromftp_cron_intervals_tbl = get_option( 'mediafromftp_event_intervals' );
1773
- $innername = sanitize_text_field($_POST['mediafromftp_cron_schedule_innername']);
1774
- $secounds = intval($_POST['mediafromftp_cron_schedule_secounds']);
1775
- $viewname = sanitize_text_field($_POST['mediafromftp_cron_schedule_viewname']);
1776
- $mediafromftp_cron_intervals_tbl[$innername] = array(
1777
- 'interval' => $secounds,
1778
- 'display' => $viewname
1779
- );
1780
- update_option( 'mediafromftp_event_intervals', $mediafromftp_cron_intervals_tbl );
1781
- echo $mediafromftpaddonwpcron->mediafromftp_schedule_notice_html($submenu);
1782
- }
1783
- }
1784
- break;
1785
- case 6:
1786
- // for media-from-ftp-add-on-wpcron
1787
- if ( !empty($_POST['mediafromftp_add_schedule_delete']) ) {
1788
- if ( !empty($_POST['mediafromftp_cron_schedule_delete']) ) {
1789
- $delete_keys = $mediafromftp->sanitize_array($_POST['mediafromftp_cron_schedule_delete']);
1790
- $mediafromftp_cron_intervals_tbl = get_option( 'mediafromftp_event_intervals' );
1791
- foreach ( $delete_keys as $key ) {
1792
- unset($mediafromftp_cron_intervals_tbl[$key]);
1793
- }
1794
- update_option( 'mediafromftp_event_intervals', $mediafromftp_cron_intervals_tbl );
1795
- echo $mediafromftpaddonwpcron->mediafromftp_schedule_notice_html($submenu);
1796
- }
1797
- }
1798
- break;
1799
- case 7:
1800
- // for media-from-ftp-add-on-wpcron
1801
- if ( !empty($_POST['mediafromftp_cron_event_create']) ) {
1802
- $event_id = date_i18n("Y-m-d-H-i-s");
1803
- $event_option_name = 'mediafromftp_cronevent-'.$event_id;
1804
- $mediafromftp_cron_events = get_option( $this->wp_add_on_wpcron_events_name(), array() );
1805
- $mediafromftp_cron_events[$event_id] = $event_option_name;
1806
- update_option( $this->wp_add_on_wpcron_events_name(), $mediafromftp_cron_events );
1807
- update_option( $event_option_name, $mediafromftp_settings);
1808
- echo $mediafromftpaddonwpcron->mediafromftp_cronevent_create_html();
1809
- }
1810
- break;
1811
- }
1812
-
1813
- }
1814
-
1815
- /* ==================================================
1816
- * @param string $output
1817
- * @return string $output
1818
- * @since 9.75
1819
- */
1820
- public function custom_robots_txt($output) {
1821
-
1822
- $public = get_option( 'blog_public' );
1823
- if ( '0' != $public ) {
1824
- $output .= "\n".'Disallow: '.$this->plugin_disallow_tmp_dir."\n";
1825
- }
1826
-
1827
- return $output;
1828
-
1829
- }
1830
-
1831
- /* ==================================================
1832
- * @param none
1833
- * @return string
1834
- * @since 9.84
1835
- */
1836
- public function notices() {
1837
-
1838
- $screen = get_current_screen();
1839
- if (is_object($screen) && $screen->id == 'media-from-ftp_page_mediafromftp-search-register') {
1840
- $html1 = '<strong>'.__('Organize my uploads into month- and year-based folders').'</strong>';
1841
- $link_url1 = admin_url('options-media.php');
1842
- $link1 = '<a href="'.$link_url1.'">'.__('Media Settings').'</a>';
1843
- $link_url2 = admin_url('admin.php?page=mediafromftp-settings');
1844
- $link2 = '<a href="'.$link_url2.'">'.__('Settings').'</a>';
1845
- if ( get_option('uploads_use_yearmonth_folders') ) {
1846
- echo '<div class="notice notice-warning is-dismissible"><ul><li>'.sprintf(__('"%1$s" is checked. This is the default setting for the WordPress Media Library. In this setting, the file is moved to month- and year-based folders. If you do not want to move, please uncheck.(%2$s,%3$s)', 'media-from-ftp'), $html1, $link1, $link2).'</li></ul></div>';
1847
- }
1848
- }
1849
- if ($this->is_my_plugin_screen()) {
1850
- if ( function_exists( 'extend_media_upload_load_textdomain' ) ) {
1851
- $html2 = '<strong>Extend Media Upload</strong>';
1852
- $html3 = '<strong>'.__('Update Media').'</strong>';
1853
- if ( is_multisite() ) {
1854
- $link_url3 = network_admin_url('plugins.php');
1855
- } else {
1856
- $link_url3 = admin_url('plugins.php');
1857
- }
1858
- $link3 = '<strong>'.'<a href="'.$link_url3.'">'.__('Plugins').'</a>'.'</strong>';
1859
- echo '<div class="notice notice-error is-dismissible"><ul><li>'.sprintf(__('"%1$s" is activate. When "%2$s", it will be overwritten with "%1$s" setting. Please deactivate.(%3$s)', 'media-from-ftp'), $html2, $html3, $link3).'</li></ul></div>';
1860
- }
1861
- }
1862
-
1863
- }
1864
-
1865
- /* ==================================================
1866
- * @param none
1867
- * @return string $this->wp_options_name()
1868
- * @since 10.09
1869
- */
1870
- private function wp_options_name() {
1871
- if ( ! function_exists( 'wp_get_current_user' ) ) {
1872
- include_once(ABSPATH . 'wp-includes/pluggable.php');
1873
- }
1874
- return 'mediafromftp_settings'.'_'.get_current_user_id();
1875
- }
1876
-
1877
- /* ==================================================
1878
- * @param none
1879
- * @return string $this->wp_add_on_wpcron_events_name()
1880
- * @since 10.09
1881
- */
1882
- private function wp_add_on_wpcron_events_name() {
1883
- if ( ! function_exists( 'wp_get_current_user' ) ) {
1884
- include_once(ABSPATH . 'wp-includes/pluggable.php');
1885
- }
1886
- return 'mediafromftp_add_on_wpcron_events'.'_'.get_current_user_id();
1887
- }
1888
-
1889
- }
1890
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
req/MediaFromFtpAjax.php DELETED
@@ -1,301 +0,0 @@
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
- $mediafromftpajax = new MediaFromFtpAjax();
23
-
24
- class MediaFromFtpAjax {
25
-
26
- private $upload_dir;
27
- private $upload_url;
28
- private $is_add_on_activate;
29
-
30
- /* ==================================================
31
- * Construct
32
- * @since 9.81
33
- */
34
- public function __construct() {
35
-
36
- $plugin_base_dir = untrailingslashit(plugin_dir_path( __DIR__ ));
37
- $slugs = explode('/', $plugin_base_dir);
38
- $slug = end($slugs);
39
- $plugin_dir = untrailingslashit(rtrim($plugin_base_dir, $slug));
40
-
41
- if(!class_exists('MediaFromFtp')){
42
- include_once $plugin_base_dir.'/inc/MediaFromFtp.php';
43
- }
44
- $mediafromftp = new MediaFromFtp();
45
- list($this->upload_dir, $this->upload_url, $upload_path) = $mediafromftp->upload_dir_url_path();
46
-
47
- $category_active = FALSE;
48
- if( function_exists('media_from_ftp_add_on_category_load_textdomain') ){
49
- include_once $plugin_dir.'/media-from-ftp-add-on-category/inc/MediaFromFtpAddOnCategory.php';
50
- $category_active = TRUE;
51
- }
52
-
53
- $this->is_add_on_activate = array(
54
- 'category' => $category_active
55
- );
56
-
57
- $action1 = 'mediafromftp-update-ajax-action';
58
- $action2 = 'mediafromftp-import-ajax-action';
59
- add_action( 'wp_ajax_'.$action1, array($this, 'mediafromftp_update_callback') );
60
- add_action( 'wp_ajax_mediafromftp_message', array($this, 'mediafromftp_message_callback') );
61
- add_action( 'wp_ajax_'.$action2, array($this, 'mediafromftp_medialibraryimport_update_callback') );
62
- add_action( 'wp_ajax_mediafromftp_medialibraryimport_message', array($this, 'mediafromftp_medialibraryimport_message_callback') );
63
-
64
- }
65
-
66
- /* ==================================================
67
- * Update Files Callback
68
- *
69
- * @since 9.30
70
- */
71
- public function mediafromftp_update_callback(){
72
-
73
- $action1 = 'mediafromftp-update-ajax-action';
74
- if ( isset( $_REQUEST['nonce'] ) && wp_verify_nonce( $_REQUEST['nonce'], $action1 ) ) {
75
- if ( current_user_can( 'upload_files' ) ) {
76
- $maxcount = intval($_POST["maxcount"]);
77
- $new_url_attach = sanitize_text_field($_POST["new_url"]);
78
- $new_url_datetime = sanitize_text_field($_POST["new_datetime"]);
79
- $new_url_mlccategory = NULL;
80
- $new_url_emlcategory = NULL;
81
- $new_url_mlacategory = NULL;
82
- $new_url_mlatags = NULL;
83
- if ( $this->is_add_on_activate['category'] ) {
84
- $new_url_mlccategory = sanitize_text_field($_POST["new_mlccategory"]);
85
- $new_url_emlcategory = sanitize_text_field($_POST["new_emlcategory"]);
86
- $new_url_mlacategory = sanitize_text_field($_POST["new_mlacategory"]);
87
- $new_url_mlatags = sanitize_text_field($_POST["new_mlatags"]);
88
- }
89
-
90
- $mediafromftp_settings = get_option($this->wp_options_name());
91
-
92
- if (!empty($new_url_attach)) {
93
-
94
- $mediafromftp = new MediaFromFtp();
95
-
96
- $dateset = $mediafromftp_settings['dateset'];
97
- $datefixed = $mediafromftp_settings['datefixed'];
98
- $yearmonth_folders = get_option('uploads_use_yearmonth_folders');
99
- $exif_text_tag = NULL;
100
- if ( $mediafromftp_settings['caption']['apply'] ) {
101
- $exif_text_tag = $mediafromftp_settings['caption']['exif_text'];
102
- }
103
-
104
- $exts = explode('.', wp_basename($new_url_attach));
105
- $ext = end($exts);
106
-
107
- // Delete Cash
108
- $mediafromftp->delete_cash($ext, $new_url_attach);
109
-
110
- // Regist
111
- 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']);
112
-
113
- $cat_html = NULL;
114
- $mlccategory = NULL;
115
- $emlcategory = NULL;
116
- $mlacategory = NULL;
117
- $mlatag = NULL;
118
- if ( $this->is_add_on_activate['category'] ) {
119
- $mediafromftpaddoncategory = new MediaFromFtpAddOnCategory();
120
- 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);
121
- unset($mediafromftpaddoncategory);
122
- }
123
-
124
- if ( $attach_id == -1 || $attach_id == -2 ) { // error
125
- $error_title = $mediafromftp->mb_utf8($new_attach_title, $mediafromftp_settings['character_code']);
126
- $error_url = $mediafromftp->mb_utf8($new_url_attach, $mediafromftp_settings['character_code']);
127
- if ( $attach_id == -1 ) {
128
- 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>';
129
- } else if ( $attach_id == -2 ) {
130
- 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>';
131
- }
132
- } else {
133
- // Outputdata
134
- list($imagethumburls, $mimetype, $length, $stamptime, $file_size, $exif_text) = $mediafromftp->output_metadata($ext, $attach_id, $metadata, $mediafromftp_settings['character_code'], $exif_text_tag);
135
-
136
- $image_attr_thumbnail = wp_get_attachment_image_src($attach_id, 'thumbnail', true);
137
-
138
- $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);
139
-
140
- header('Content-type: text/html; charset=UTF-8');
141
- echo $output_html;
142
-
143
- }
144
- unset($mediafromftp);
145
-
146
- }
147
- }
148
- } else {
149
- status_header( '403' );
150
- echo 'Forbidden';
151
- }
152
-
153
- wp_die();
154
-
155
- }
156
-
157
- /* ==================================================
158
- * Update Messages Callback
159
- *
160
- * @since 9.30
161
- */
162
- public function mediafromftp_message_callback(){
163
-
164
- $error_count = intval($_POST["error_count"]);
165
- $error_update = sanitize_text_field($_POST["error_update"]);
166
- $success_count = intval($_POST["success_count"]);
167
-
168
- $output_html = NULL;
169
- if ( $error_count > 0 ) {
170
- $error_message = sprintf(__('Errored to the registration of %1$d files.', 'media-from-ftp'), $error_count);
171
- $output_html .= '<div class="notice notice-error is-dismissible"><ul><li><div>'.$error_message.'</div>'.$error_update.'</li></ul></div>';
172
- }
173
- $success_message = sprintf(__('Succeeded to the registration of %1$d files.', 'media-from-ftp'), $success_count);
174
- $output_html .= '<div class="notice notice-success is-dismissible"><ul><li><div>'.$success_message.'</li></ul></div>';
175
-
176
- header('Content-type: text/html; charset=UTF-8');
177
- echo $output_html;
178
-
179
- wp_die();
180
-
181
- }
182
-
183
- /* ==================================================
184
- * Import Files Callback
185
- *
186
- * @since 9.40
187
- */
188
- public function mediafromftp_medialibraryimport_update_callback(){
189
-
190
- $action2 = 'mediafromftp-import-ajax-action';
191
- if ( isset( $_REQUEST['nonce'] ) && wp_verify_nonce( $_REQUEST['nonce'], $action2 ) ) {
192
- if ( current_user_can( 'upload_files' ) ) {
193
- $file = sanitize_text_field($_POST["file"]);
194
- $filepath = str_replace($this->upload_dir.'/' , '', $file);
195
- if ( is_file($file) ) {
196
- if ( !empty($_POST["db_array"]) ) {
197
- $db_array = $_POST["db_array"];
198
- global $wpdb;
199
- $table_name = $wpdb->prefix.'posts';
200
- $wpdb->insert( $table_name, $db_array );
201
- update_attached_file( intval($db_array['ID']), $filepath ) ;
202
- if ( !empty($_POST["db_wp_attachment_metadata"]) ) {
203
- $metadata_json = stripslashes($_POST["db_wp_attachment_metadata"]);
204
- $metadata = json_decode($metadata_json);
205
- $table_meta_name = $wpdb->prefix.'postmeta';
206
- $db_meta_array = array(
207
- "post_id" => intval($db_array['ID']),
208
- "meta_key" => '_wp_attachment_metadata',
209
- "meta_value" => $metadata
210
- );
211
- $wpdb->insert( $table_meta_name, $db_meta_array );
212
- }
213
- if ( !empty($_POST["db_thumbnail_id"]) ) {
214
- update_post_meta( intval($db_array['ID']), '_thumbnail_id', intval($_POST["db_thumbnail_id"]) );
215
- }
216
- if ( !empty($_POST["db_cover_hash"]) ) {
217
- update_post_meta( intval($db_array['ID']), '_cover_hash', sanitize_text_field($_POST["db_cover_hash"]) );
218
- }
219
- if ( !empty($_POST["db_wp_attachment_image_alt"]) ) {
220
- update_post_meta( intval($db_array['ID']), '_wp_attachment_image_alt', sanitize_text_field($_POST["db_wp_attachment_image_alt"]) );
221
- }
222
- $msg = 'success_db';
223
- $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="'.$this->upload_url.'/'.$filepath.'" target="_blank" style="text-decoration: none;">'.$filepath.'</a></div>';
224
- } else {
225
- $msg = 'success';
226
- $output_html = $msg.','.'<div>'.__('Thumbnail').': '.'<a href="'.$this->upload_url.'/'.$filepath.'" target="_blank" style="text-decoration: none;">'.$filepath.'</a></div>';
227
- }
228
- } else {
229
- $error_string = __('No file!', 'media-from-ftp');
230
- $msg = '<div>'.$filepath.': '.$error_string.'</div>';
231
- $output_html = $msg.','.'<div>'.$filepath.'<span style="color: red;"> &#8811; '.$error_string.'</span></div>';
232
- }
233
-
234
- header('Content-type: text/html; charset=UTF-8');
235
- echo $output_html;
236
- }
237
- } else {
238
- status_header( '403' );
239
- echo 'Forbidden';
240
- }
241
-
242
- wp_die();
243
-
244
- }
245
-
246
- /* ==================================================
247
- * Import Messages Callback
248
- *
249
- * @since 9.40
250
- */
251
- public function mediafromftp_medialibraryimport_message_callback(){
252
-
253
- $error_count = intval($_POST["error_count"]);
254
- $error_update = sanitize_text_field($_POST["error_update"]);
255
- $success_count = intval($_POST["success_count"]);
256
- $db_success_count = intval($_POST["db_success_count"]);
257
-
258
- $output_html = NULL;
259
- if ( $error_count > 0 ) {
260
- $error_message = sprintf(__('Errored to the registration of %1$d files.', 'media-from-ftp'), $error_count);
261
- $output_html .= '<div class="notice notice-error is-dismissible"><ul><li><div>'.$error_message.'</div>'.$error_update.'</li></ul></div>';
262
- }
263
- $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);
264
- $output_html .= '<div class="notice notice-success is-dismissible"><ul><li><div>'.$success_message.'</li></ul></div>';
265
-
266
- header('Content-type: text/html; charset=UTF-8');
267
- echo $output_html;
268
-
269
- wp_die();
270
-
271
- }
272
-
273
- /* ==================================================
274
- * Escape Title
275
- * @param string $str
276
- * @return string $str
277
- * @since 9.41
278
- */
279
- private function esc_title($str){
280
-
281
- $str = esc_html($str);
282
- $str = str_replace(',', '&#44;', $str);
283
-
284
- return $str;
285
- }
286
-
287
- /* ==================================================
288
- * @param none
289
- * @return string $this->wp_options_name()
290
- * @since 10.09
291
- */
292
- private function wp_options_name() {
293
- if ( ! function_exists( 'wp_get_current_user' ) ) {
294
- include_once(ABSPATH . 'wp-includes/pluggable.php');
295
- }
296
- return 'mediafromftp_settings'.'_'.get_current_user_id();
297
- }
298
-
299
- }
300
-
301
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
req/MediaFromFtpListTable.php DELETED
@@ -1,367 +0,0 @@
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
- public function __construct(){
37
-
38
- $plugin_base_dir = untrailingslashit(plugin_dir_path( __DIR__ ));
39
- $slugs = explode('/', $plugin_base_dir);
40
- $slug = end($slugs);
41
- $plugin_dir = untrailingslashit(rtrim($plugin_base_dir, $slug));
42
-
43
- $category_active = FALSE;
44
- if( function_exists('media_from_ftp_add_on_category_load_textdomain') ){
45
- include_once $plugin_dir.'/media-from-ftp-add-on-category/inc/MediaFromFtpAddOnCategory.php';
46
- $category_active = TRUE;
47
- }
48
- if( function_exists('media_from_ftp_add_on_exif_load_textdomain') ){
49
- include_once $plugin_dir.'/media-from-ftp-add-on-exif/inc/MediaFromFtpAddOnExif.php';
50
- }
51
- if( function_exists('media_from_ftp_add_on_cli_load_textdomain') ){
52
- require_once( $plugin_dir.'/media-from-ftp-add-on-cli/req/MediaFromFtpCli.php' );
53
- }
54
- if( function_exists('media_from_ftp_add_on_wpcron_load_textdomain') ){
55
- include_once $plugin_dir.'/media-from-ftp-add-on-wpcron/inc/MediaFromFtpAddOnWpcron.php';
56
- }
57
-
58
- if(!class_exists('MediaFromFtp')){
59
- include_once $plugin_base_dir.'/inc/MediaFromFtp.php';
60
- }
61
-
62
- // Media Library Categories
63
- $mlc_active = FALSE;
64
- if ( class_exists( 'wpMediaLibraryCategories' ) ) {
65
- $mlc_active = TRUE;
66
- }
67
-
68
- // Enhanced Media Library
69
- $eml_active = FALSE;
70
- if ( function_exists( 'wpuxss_eml_on_plugins_loaded' ) ) {
71
- $eml_active = TRUE;
72
- }
73
-
74
- // Media Library Assistant
75
- $mla_active = FALSE;
76
- if ( function_exists( 'mla_name_conflict_reporting_action' ) ) {
77
- $mla_active = TRUE;
78
- }
79
-
80
- $this->is_add_on_activate = array(
81
- 'category' => $category_active,
82
- 'mlc' => $mlc_active,
83
- 'eml' => $eml_active,
84
- 'mla' => $mla_active
85
- );
86
-
87
- global $status, $page;
88
- //Set parent defaults
89
- parent::__construct( array(
90
- 'singular' => 'new_url_attaches',
91
- 'ajax' => false
92
- ) );
93
-
94
- }
95
-
96
- /* ==================================================
97
- * @return array $listtable_array
98
- * @since 9.50
99
- */
100
- private function read_data(){
101
-
102
- $mediafromftp = new MediaFromFtp();
103
- $mediafromftp_settings = get_option($this->wp_options_name());
104
- $pagemax = $mediafromftp_settings['pagemax'];
105
- $searchdir = $mediafromftp_settings['searchdir'];
106
- $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
107
- $extfilter = $mediafromftp_settings['extfilter'];
108
- $max_execution_time = $mediafromftp_settings['max_execution_time'];
109
-
110
- $mlccs = explode(',', $mediafromftp_settings['mlcc']);
111
- $emlcs = explode(',', $mediafromftp_settings['emlc']);
112
- $mlacs = explode(',', $mediafromftp_settings['mlac']);
113
- $mlats = explode(',', $mediafromftp_settings['mlat']);
114
-
115
- $document_root = ABSPATH.$searchdir;
116
-
117
- $mediafromftp->mb_initialize($mediafromftp_settings['character_code']);
118
- $document_root = $mediafromftp->mb_encode_multibyte($document_root, $mediafromftp_settings['character_code']);
119
-
120
- if ( strstr($searchdir, '../') ) {
121
- $document_root = realpath($document_root);
122
- }
123
-
124
- global $wpdb;
125
- $attachments = $wpdb->get_results("
126
- SELECT ID
127
- FROM $wpdb->posts
128
- WHERE post_type = 'attachment'
129
- ");
130
-
131
- $extpattern = $mediafromftp->extpattern($extfilter);
132
- $files = $mediafromftp->scan_file($document_root, $extpattern, $mediafromftp_settings);
133
-
134
- $count = 0;
135
- $listtable_array = array();
136
- foreach ( $files as $file ){
137
- // Input URL
138
- list($new_file, $ext, $new_url) = $mediafromftp->input_url($file, $attachments, $mediafromftp_settings['character_code'], $mediafromftp_settings['thumb_deep_search']);
139
- if ( $new_file ) {
140
- ++$count;
141
- list($inputhtml, $datetimehtml) = $mediafromftp->input_html($ext, $file, $new_url, $count, $mediafromftp_settings);
142
-
143
- $mlccategoryhtml = NULL;
144
- $emlcategoryhtml = NULL;
145
- $mlacategoryhtml = NULL;
146
- if ( $this->is_add_on_activate['category'] ) {
147
- $mediafromftpaddoncategory = new MediaFromFtpAddOnCategory();
148
- $mlccategoryhtml = $mediafromftpaddoncategory->mlc_category_check_html($count, $mlccs);
149
- $emlcategoryhtml = $mediafromftpaddoncategory->eml_category_check_html($count, $emlcs);
150
- $mlacategoryhtml = $mediafromftpaddoncategory->mla_category_check_html($count, $mlacs, $mlats);
151
- unset($mediafromftpaddoncategory);
152
- }
153
-
154
- $listtable_array[] = array(
155
- 'ID' => $count,
156
- 'title' => $inputhtml,
157
- 'new_url' => $new_url,
158
- 'datetime' => $datetimehtml,
159
- 'mlccategories' => $mlccategoryhtml,
160
- 'emlcategories' => $emlcategoryhtml,
161
- 'mlacategories' => $mlacategoryhtml
162
- );
163
-
164
- }
165
- }
166
- unset($files, $mediafromftp, $attachments);
167
-
168
- return $listtable_array;
169
-
170
- }
171
-
172
- public function column_default($item, $column_name){
173
- switch($column_name){
174
- case 'datetime':
175
- case 'mlccategories':
176
- case 'emlcategories':
177
- case 'mlacategories':
178
- return $item[$column_name];
179
- default:
180
- return print_r($item,true); //Show the whole array for troubleshooting purposes
181
- }
182
- }
183
-
184
- public function column_title($item){
185
- //Return the title contents
186
- return sprintf('%1$s <span style="color:silver"></span>',
187
- /*$1%s*/ $item['title']
188
- );
189
- }
190
-
191
- public function column_cb($item){
192
- return sprintf(
193
- '<input type="checkbox" name="%1$s[%2$s][url]" value="%3$s" form="mediafromftp_ajax_update" />',
194
- /*%1$s*/ $this->_args['singular'],
195
- /*%2$s*/ $item['ID'],
196
- /*%3$s*/ $item['new_url']
197
- );
198
- }
199
-
200
- public function get_columns(){
201
- $columns = array(
202
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
203
- 'title' => 'URL',
204
- 'datetime' => __('Edit date and time'),
205
- 'mlccategories' => '<div>'.__('Categories').'<div></div>'.'Media Library Categories'.'</div>',
206
- 'emlcategories' => '<div>'.__('Categories').'<div></div>'.'Enhanced Media Library'.'</div>',
207
- 'mlacategories' => '<div>'.__('Categories').' & '.__('Tags').'<div></div>'.'Media Library Assistant'.'</div>'
208
- );
209
- $mediafromftp_settings = get_option($this->wp_options_name());
210
- if ( $mediafromftp_settings['dateset'] === 'new' || $mediafromftp_settings['dateset'] === 'fixed' ) unset($columns['datetime']);
211
-
212
- if ( $this->is_add_on_activate['category'] ) {
213
- if ( !$this->is_add_on_activate['mlc'] ) unset($columns['mlccategories']);
214
- if ( !$this->is_add_on_activate['eml'] ) unset($columns['emlcategories']);
215
- if ( !$this->is_add_on_activate['mla'] ) unset($columns['mlacategories']);
216
- } else {
217
- unset($columns['mlccategories']);
218
- unset($columns['emlcategories']);
219
- unset($columns['mlacategories']);
220
- }
221
-
222
- return $columns;
223
- }
224
-
225
- public function get_sortable_columns() {
226
- $sortable_columns = array(
227
- 'title' => array('title',false)
228
- );
229
- return $sortable_columns;
230
- }
231
-
232
- /** ************************************************************************
233
- * REQUIRED! This is where you prepare your data for display. This method will
234
- * usually be used to query the database, sort and filter the data, and generally
235
- * get it ready to be displayed. At a minimum, we should set $this->items and
236
- * $this->set_pagination_args(), although the following properties and methods
237
- * are frequently interacted with here...
238
- *
239
- * @global WPDB $wpdb
240
- * @uses $this->_column_headers
241
- * @uses $this->items
242
- * @uses $this->get_columns()
243
- * @uses $this->get_sortable_columns()
244
- * @uses $this->get_pagenum()
245
- * @uses $this->set_pagination_args()
246
- **************************************************************************/
247
- public function prepare_items() {
248
-
249
- /**
250
- * First, lets decide how many records per page to show
251
- */
252
- $mediafromftp_settings = get_option($this->wp_options_name());
253
- $per_page = $mediafromftp_settings['pagemax'];
254
-
255
- /**
256
- * REQUIRED. Now we need to define our column headers. This includes a complete
257
- * array of columns to be displayed (slugs & titles), a list of columns
258
- * to keep hidden, and a list of columns that are sortable. Each of these
259
- * can be defined in another method (as we've done here) before being
260
- * used to build the value for our _column_headers property.
261
- */
262
- $columns = $this->get_columns();
263
- $hidden = array();
264
- $sortable = $this->get_sortable_columns();
265
-
266
- /**
267
- * REQUIRED. Finally, we build an array to be used by the class for column
268
- * headers. The $this->_column_headers property takes an array which contains
269
- * 3 other arrays. One for all columns, one for hidden columns, and one
270
- * for sortable columns.
271
- */
272
- $this->_column_headers = array($columns, $hidden, $sortable);
273
-
274
- /**
275
- * Instead of querying a database, we're going to fetch the example data
276
- * property we created for use in this plugin. This makes this example
277
- * package slightly different than one you might build on your own. In
278
- * this example, we'll be using array manipulation to sort and paginate
279
- * our data. In a real-world implementation, you will probably want to
280
- * use sort and pagination data to build a custom query instead, as you'll
281
- * be able to use your precisely-queried data immediately.
282
- */
283
- $data = $this->read_data();
284
-
285
- /**
286
- * This checks for sorting input and sorts the data in our array accordingly.
287
- *
288
- * In a real-world situation involving a database, you would probably want
289
- * to handle sorting by passing the 'orderby' and 'order' values directly
290
- * to a custom query. The returned data will be pre-sorted, and this array
291
- * sorting technique would be unnecessary.
292
- */
293
- function usort_reorder($a,$b){
294
- $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'title'; //If no sort, default to title
295
- $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc
296
- $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order
297
- return ($order==='asc') ? $result : -$result; //Send final sort direction to usort
298
- }
299
- usort($data, 'usort_reorder');
300
-
301
- /***********************************************************************
302
- * ---------------------------------------------------------------------
303
- * vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
304
- *
305
- * In a real-world situation, this is where you would place your query.
306
- *
307
- * For information on making queries in WordPress, see this Codex entry:
308
- * http://codex.wordpress.org/Class_Reference/wpdb
309
- *
310
- * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
311
- * ---------------------------------------------------------------------
312
- **********************************************************************/
313
-
314
- /**
315
- * REQUIRED for pagination. Let's figure out what page the user is currently
316
- * looking at. We'll need this later, so you should always include it in
317
- * your own package classes.
318
- */
319
- $current_page = $this->get_pagenum();
320
-
321
- /**
322
- * REQUIRED for pagination. Let's check how many items are in our data array.
323
- * In real-world use, this would be the total number of items in your database,
324
- * without filtering. We'll need this later, so you should always include it
325
- * in your own package classes.
326
- */
327
- $total_items = count($data);
328
- $this->max_items = $total_items;
329
-
330
- /**
331
- * The WP_List_Table class does not handle pagination for us, so we need
332
- * to ensure that the data is trimmed to only the current page. We can use
333
- * array_slice() to
334
- */
335
- $data = array_slice($data,(($current_page-1)*$per_page),$per_page);
336
-
337
- /**
338
- * REQUIRED. Now we can add our *sorted* data to the items property, where
339
- * it can be used by the rest of the class.
340
- */
341
- $this->items = $data;
342
-
343
- /**
344
- * REQUIRED. We also have to register our pagination options & calculations.
345
- */
346
- $this->set_pagination_args( array(
347
- 'total_items' => $total_items, //WE have to calculate the total number of items
348
- 'per_page' => $per_page, //WE have to determine how many items to show on a page
349
- 'total_pages' => ceil($total_items/$per_page) //WE have to calculate the total number of pages
350
- ) );
351
- }
352
-
353
- /* ==================================================
354
- * @param none
355
- * @return string $this->wp_options_name()
356
- * @since 10.09
357
- */
358
- private function wp_options_name() {
359
- if ( ! function_exists( 'wp_get_current_user' ) ) {
360
- include_once(ABSPATH . 'wp-includes/pluggable.php');
361
- }
362
- return 'mediafromftp_settings'.'_'.get_current_user_id();
363
- }
364
-
365
- }
366
-
367
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
req/MediaFromFtpRegist.php DELETED
@@ -1,438 +0,0 @@
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
- $mediafromftpregist = new MediaFromFtpRegist();
23
-
24
- class MediaFromFtpRegist {
25
-
26
- private $upload_path;
27
-
28
- /* ==================================================
29
- * Construct
30
- * @since 9.81
31
- */
32
- public function __construct() {
33
-
34
- $plugin_base_dir = untrailingslashit(plugin_dir_path( __DIR__ ));
35
-
36
- if(!class_exists('MediaFromFtp')){
37
- include_once $plugin_base_dir.'/inc/MediaFromFtp.php';
38
- }
39
- $mediafromftp = new MediaFromFtp();
40
- list($upload_dir, $upload_url, $this->upload_path) = $mediafromftp->upload_dir_url_path();
41
- $plugin_tmp_dir = $upload_dir.'/media-from-ftp-tmp';
42
- // Make tmp dir
43
- if ( !is_dir( $plugin_tmp_dir ) ) {
44
- wp_mkdir_p( $plugin_tmp_dir );
45
- }
46
-
47
- register_activation_hook( $plugin_base_dir.'/mediafromftp.php', array($this, 'log_settings') );
48
- add_action( 'admin_init', array($this, 'register_settings') );
49
-
50
- }
51
-
52
- /* ==================================================
53
- * Settings Log Settings
54
- * @since 10.05
55
- */
56
- public function log_settings(){
57
-
58
- if ( !is_multisite() ) {
59
- $this->log_write();
60
- } else { // For Multisite
61
- global $wpdb;
62
- $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
63
- $original_blog_id = get_current_blog_id();
64
- foreach ( $blog_ids as $blog_id ) {
65
- switch_to_blog( $blog_id );
66
- $this->log_write();
67
- }
68
- switch_to_blog( $original_blog_id );
69
- }
70
-
71
- }
72
-
73
- /* ==================================================
74
- * Settings Log Write
75
- * @since 9.19
76
- */
77
- private function log_write(){
78
-
79
- $mediafromftp_log_db_version = '3.0';
80
- $installed_ver = get_option( 'mediafromftp_log_version' );
81
-
82
- if( $installed_ver != $mediafromftp_log_db_version ) {
83
- global $wpdb;
84
- $log_name = $wpdb->prefix.'mediafromftp_log';
85
- require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
86
- if ( !$installed_ver ) {
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
- } else {
111
- $table_search = $wpdb->get_row("SHOW TABLES FROM " .DB_NAME. " LIKE '" .$log_name. "'");
112
- if ( $wpdb->num_rows == 1 ) { // db_version 1.0, 2.0
113
- $records = $wpdb->get_results("SELECT * FROM $log_name");
114
- $wpdb->query("DELETE FROM $log_name");
115
-
116
- $wpdb->query("ALTER TABLE $log_name DROP thumbnail1, DROP thumbnail2, DROP thumbnail3, DROP thumbnail4, DROP thumbnail5, DROP thumbnail6");
117
- $wpdb->query("ALTER TABLE $log_name ADD thumbnail longtext");
118
- $wpdb->query("ALTER TABLE $log_name ADD mlccategories longtext");
119
- $wpdb->query("ALTER TABLE $log_name ADD emlcategories longtext");
120
- $wpdb->query("ALTER TABLE $log_name ADD mlacategories longtext");
121
- $wpdb->query("ALTER TABLE $log_name ADD mlatags longtext");
122
-
123
- foreach ( $records as $record ) {
124
- $thumbnail = NULL;
125
- $thumbnails = array();
126
- if ( !empty($record->thumbnail1) ) { $thumbnails[0] = $record->thumbnail1; }
127
- if ( !empty($record->thumbnail2) ) { $thumbnails[1] = $record->thumbnail2; }
128
- if ( !empty($record->thumbnail3) ) { $thumbnails[2] = $record->thumbnail3; }
129
- if ( !empty($record->thumbnail4) ) { $thumbnails[3] = $record->thumbnail4; }
130
- if ( !empty($record->thumbnail5) ) { $thumbnails[4] = $record->thumbnail5; }
131
- if ( !empty($record->thumbnail6) ) { $thumbnails[5] = $record->thumbnail6; }
132
- if ( !empty($thumbnails) ) {
133
- $thumbnail = json_encode($thumbnails);
134
- $thumbnail = str_replace('\\', '', $thumbnail);
135
- } else {
136
- $thumbnail = $record->thumbnail;
137
- }
138
-
139
- $log_arr = array(
140
- 'id' => $record->id,
141
- 'user' => $record->user,
142
- 'title' => $record->title,
143
- 'permalink' => $record->permalink,
144
- 'url' => $record->url,
145
- 'filename' => $record->filename,
146
- 'time' => $record->time,
147
- 'filetype' => $record->filetype,
148
- 'filesize' => $record->filesize,
149
- 'exif' => $record->exif,
150
- 'length' => $record->length,
151
- 'thumbnail' => $thumbnail,
152
- 'mlccategories' => NULL,
153
- 'emlcategories' => NULL,
154
- 'mlacategories' => NULL,
155
- 'mlatags' => NULL
156
- );
157
- $wpdb->insert( $log_name, $log_arr);
158
- $wpdb->show_errors();
159
- }
160
-
161
- }
162
- }
163
- update_option( 'mediafromftp_log_version', $mediafromftp_log_db_version );
164
- }
165
-
166
- }
167
-
168
- /* ==================================================
169
- * Settings register
170
- * @since 2.3
171
- */
172
- public function register_settings(){
173
-
174
- $user = wp_get_current_user();
175
- $cron_mail = $user->user_email;
176
- $cron_user = $user->ID;
177
-
178
- $wp_options_name = 'mediafromftp_settings'.'_'.$cron_user;
179
- $wp_cron_events_name = 'mediafromftp_add_on_wpcron_events'.'_'.$cron_user;
180
-
181
- $pagemax = 20;
182
- $basedir = $this->upload_path;
183
- $searchdir = $this->upload_path;
184
- $ext2typefilter = 'all';
185
- $extfilter = 'all';
186
- $search_display_metadata = TRUE;
187
- $dateset = 'new';
188
- $datefixed = date_i18n("Y-m-d H:i");
189
- $datetimepicker = 1;
190
- $max_execution_time = 300;
191
- if( strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && get_locale() === 'ja' ) { // Japanese Windows
192
- $character_code = 'CP932';
193
- } else {
194
- $character_code = 'UTF-8';
195
- }
196
- $exclude = '(.ktai.)|(.backwpup_log.)|(.ps_auto_sitemap.)|\.php|\.js|(.wpcf7_captcha.)|\.htaccess|(.woocommerce_uploads.)|(.wc-logs.)';
197
- $recursive_search = TRUE;
198
- $thumb_deep_search = FALSE;
199
- $search_limit_number = 100000;
200
- $cron_apply = FALSE;
201
- $cron_schedule = 'hourly';
202
- $cron_limit_number = FALSE;
203
- $cron_mail_apply = TRUE;
204
-
205
- $caption_apply = FALSE;
206
- $exif_text = '%title% %credit% %camera% %caption% %created_timestamp% %copyright% %aperture% %shutter_speed% %iso% %focal_length% %white_balance%';
207
- $log = FALSE;
208
-
209
- // for media-from-ftp-add-on-category
210
- $mlcc = NULL;
211
- $emlc = NULL;
212
- $mlac = NULL;
213
- $mlat = NULL;
214
-
215
- // for media-from-ftp-add-on-wpcron
216
- if ( !get_option( 'mediafromftp_event_intervals' ) ) {
217
- update_option( 'mediafromftp_event_intervals', array() );
218
- }
219
- if ( !get_option( $wp_cron_events_name ) ) {
220
- update_option( $wp_cron_events_name, array() );
221
- }
222
-
223
- // << version 2.35
224
- if ( get_option('mediafromftp_exclude_file') ) {
225
- $exclude = get_option('mediafromftp_exclude_file');
226
- delete_option( 'mediafromftp_exclude_file' );
227
- }
228
-
229
- if ( !get_option($wp_options_name) ) {
230
- if ( get_option('mediafromftp_settings') ) { // old settings
231
- $mediafromftp_settings = get_option('mediafromftp_settings');
232
- if ( array_key_exists( "pagemax", $mediafromftp_settings ) ) {
233
- $pagemax = $mediafromftp_settings['pagemax'];
234
- }
235
- if ( array_key_exists( "basedir", $mediafromftp_settings ) ) {
236
- $basedir = $mediafromftp_settings['basedir'];
237
- }
238
- if ( array_key_exists( "searchdir", $mediafromftp_settings ) ) {
239
- $searchdir = $mediafromftp_settings['searchdir'];
240
- }
241
- if ( array_key_exists( "ext2typefilter", $mediafromftp_settings ) ) {
242
- $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
243
- }
244
- if ( array_key_exists( "extfilter", $mediafromftp_settings ) ) {
245
- $extfilter = $mediafromftp_settings['extfilter'];
246
- }
247
- if ( array_key_exists( "search_display_metadata", $mediafromftp_settings ) ) {
248
- $search_display_metadata = $mediafromftp_settings['search_display_metadata'];
249
- }
250
- if ( array_key_exists( "dateset", $mediafromftp_settings ) ) {
251
- $dateset = $mediafromftp_settings['dateset'];
252
- }
253
- if ( array_key_exists( "datefixed", $mediafromftp_settings ) ) {
254
- $datefixed = $mediafromftp_settings['datefixed'];
255
- }
256
- if ( array_key_exists( "datetimepicker", $mediafromftp_settings ) ) {
257
- $datetimepicker = $mediafromftp_settings['datetimepicker'];
258
- }
259
- if ( array_key_exists( "max_execution_time", $mediafromftp_settings ) ) {
260
- $max_execution_time = $mediafromftp_settings['max_execution_time'];
261
- }
262
- if ( array_key_exists( "character_code", $mediafromftp_settings ) ) {
263
- $character_code = $mediafromftp_settings['character_code'];
264
- }
265
- if ( array_key_exists( "exclude", $mediafromftp_settings ) ) {
266
- $exclude = $mediafromftp_settings['exclude'];
267
- }
268
- if ( array_key_exists( "recursive_search", $mediafromftp_settings ) ) {
269
- $recursive_search = $mediafromftp_settings['recursive_search'];
270
- }
271
- if ( array_key_exists( "thumb_deep_search", $mediafromftp_settings ) ) {
272
- $thumb_deep_search = $mediafromftp_settings['thumb_deep_search'];
273
- }
274
- if ( array_key_exists( "search_limit_number", $mediafromftp_settings ) ) {
275
- $search_limit_number = $mediafromftp_settings['search_limit_number'];
276
- }
277
- if ( array_key_exists( "apply", $mediafromftp_settings["cron"] ) ) {
278
- $cron_apply = $mediafromftp_settings['cron']['apply'];
279
- }
280
- if ( array_key_exists( "schedule", $mediafromftp_settings["cron"] ) ) {
281
- $cron_schedule = $mediafromftp_settings['cron']['schedule'];
282
- }
283
- if ( array_key_exists( "limit_number", $mediafromftp_settings["cron"] ) ) {
284
- $cron_limit_number = $mediafromftp_settings['cron']['limit_number'];
285
- }
286
- if ( array_key_exists( "mail_apply", $mediafromftp_settings["cron"] ) ) {
287
- $cron_mail_apply = $mediafromftp_settings['cron']['mail_apply'];
288
- }
289
- if ( array_key_exists( "apply", $mediafromftp_settings["caption"] ) ) {
290
- $caption_apply = $mediafromftp_settings['caption']['apply'];
291
- }
292
- if ( array_key_exists( "exif_text", $mediafromftp_settings["caption"] ) ) {
293
- $exif_text = $mediafromftp_settings['caption']['exif_text'];
294
- }
295
- if ( array_key_exists( "log", $mediafromftp_settings ) ) {
296
- $log = $mediafromftp_settings['log'];
297
- }
298
-
299
- // for media-from-ftp-add-on-category
300
- if ( array_key_exists( "mlcc", $mediafromftp_settings ) ) {
301
- $mlcc = $mediafromftp_settings['mlcc'];
302
- }
303
- if ( array_key_exists( "emlc", $mediafromftp_settings ) ) {
304
- $emlc = $mediafromftp_settings['emlc'];
305
- }
306
- if ( array_key_exists( "mlac", $mediafromftp_settings ) ) {
307
- $mlac = $mediafromftp_settings['mlac'];
308
- }
309
- if ( array_key_exists( "mlat", $mediafromftp_settings ) ) {
310
- $mlat = $mediafromftp_settings['mlat'];
311
- }
312
-
313
- delete_option( 'mediafromftp_settings' );
314
- }
315
- } else {
316
- $mediafromftp_settings = get_option($wp_options_name);
317
- if ( array_key_exists( "pagemax", $mediafromftp_settings ) ) {
318
- $pagemax = $mediafromftp_settings['pagemax'];
319
- }
320
- if ( array_key_exists( "basedir", $mediafromftp_settings ) ) {
321
- $basedir = $mediafromftp_settings['basedir'];
322
- }
323
- if ( array_key_exists( "searchdir", $mediafromftp_settings ) ) {
324
- $searchdir = $mediafromftp_settings['searchdir'];
325
- }
326
- if ( array_key_exists( "ext2typefilter", $mediafromftp_settings ) ) {
327
- $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
328
- }
329
- if ( array_key_exists( "extfilter", $mediafromftp_settings ) ) {
330
- $extfilter = $mediafromftp_settings['extfilter'];
331
- }
332
- if ( array_key_exists( "search_display_metadata", $mediafromftp_settings ) ) {
333
- $search_display_metadata = $mediafromftp_settings['search_display_metadata'];
334
- }
335
- if ( array_key_exists( "dateset", $mediafromftp_settings ) ) {
336
- $dateset = $mediafromftp_settings['dateset'];
337
- }
338
- if ( array_key_exists( "datefixed", $mediafromftp_settings ) ) {
339
- $datefixed = $mediafromftp_settings['datefixed'];
340
- }
341
- if ( array_key_exists( "datetimepicker", $mediafromftp_settings ) ) {
342
- $datetimepicker = $mediafromftp_settings['datetimepicker'];
343
- }
344
- if ( array_key_exists( "max_execution_time", $mediafromftp_settings ) ) {
345
- $max_execution_time = $mediafromftp_settings['max_execution_time'];
346
- }
347
- if ( array_key_exists( "character_code", $mediafromftp_settings ) ) {
348
- $character_code = $mediafromftp_settings['character_code'];
349
- }
350
- if ( array_key_exists( "exclude", $mediafromftp_settings ) ) {
351
- $exclude = $mediafromftp_settings['exclude'];
352
- }
353
- if ( array_key_exists( "recursive_search", $mediafromftp_settings ) ) {
354
- $recursive_search = $mediafromftp_settings['recursive_search'];
355
- }
356
- if ( array_key_exists( "thumb_deep_search", $mediafromftp_settings ) ) {
357
- $thumb_deep_search = $mediafromftp_settings['thumb_deep_search'];
358
- }
359
- if ( array_key_exists( "search_limit_number", $mediafromftp_settings ) ) {
360
- $search_limit_number = $mediafromftp_settings['search_limit_number'];
361
- }
362
- if ( array_key_exists( "apply", $mediafromftp_settings["cron"] ) ) {
363
- $cron_apply = $mediafromftp_settings['cron']['apply'];
364
- }
365
- if ( array_key_exists( "schedule", $mediafromftp_settings["cron"] ) ) {
366
- $cron_schedule = $mediafromftp_settings['cron']['schedule'];
367
- }
368
- if ( array_key_exists( "limit_number", $mediafromftp_settings["cron"] ) ) {
369
- $cron_limit_number = $mediafromftp_settings['cron']['limit_number'];
370
- }
371
- if ( array_key_exists( "mail_apply", $mediafromftp_settings["cron"] ) ) {
372
- $cron_mail_apply = $mediafromftp_settings['cron']['mail_apply'];
373
- }
374
- if ( array_key_exists( "apply", $mediafromftp_settings["caption"] ) ) {
375
- $caption_apply = $mediafromftp_settings['caption']['apply'];
376
- }
377
- if ( array_key_exists( "exif_text", $mediafromftp_settings["caption"] ) ) {
378
- $exif_text = $mediafromftp_settings['caption']['exif_text'];
379
- }
380
- if ( array_key_exists( "log", $mediafromftp_settings ) ) {
381
- $log = $mediafromftp_settings['log'];
382
- }
383
- // for media-from-ftp-add-on-category
384
- if ( array_key_exists( "mlcc", $mediafromftp_settings ) ) {
385
- $mlcc = $mediafromftp_settings['mlcc'];
386
- }
387
- if ( array_key_exists( "emlc", $mediafromftp_settings ) ) {
388
- $emlc = $mediafromftp_settings['emlc'];
389
- }
390
- if ( array_key_exists( "mlac", $mediafromftp_settings ) ) {
391
- $mlac = $mediafromftp_settings['mlac'];
392
- }
393
- if ( array_key_exists( "mlat", $mediafromftp_settings ) ) {
394
- $mlat = $mediafromftp_settings['mlat'];
395
- }
396
- }
397
-
398
- $mediafromftp_tbl = array(
399
- 'pagemax' => $pagemax,
400
- 'basedir' => $basedir,
401
- 'searchdir' => $searchdir,
402
- 'ext2typefilter' => $ext2typefilter,
403
- 'extfilter' => $extfilter,
404
- 'search_display_metadata' => $search_display_metadata,
405
- 'dateset' => $dateset,
406
- 'datefixed' => $datefixed,
407
- 'datetimepicker' => $datetimepicker,
408
- 'max_execution_time' => $max_execution_time,
409
- 'character_code' => $character_code,
410
- 'exclude' => $exclude,
411
- 'recursive_search' => $recursive_search,
412
- 'thumb_deep_search' => $thumb_deep_search,
413
- 'search_limit_number' => $search_limit_number,
414
- 'cron' => array(
415
- 'apply' => $cron_apply,
416
- 'schedule' => $cron_schedule,
417
- 'limit_number' => $cron_limit_number,
418
- 'mail_apply' => $cron_mail_apply,
419
- 'mail' => $cron_mail,
420
- 'user' => $cron_user
421
- ),
422
- 'caption' => array(
423
- 'apply' => $caption_apply,
424
- 'exif_text' => $exif_text
425
- ),
426
- 'log' => $log,
427
- 'mlcc' => $mlcc,
428
- 'emlc' => $emlc,
429
- 'mlac' => $mlac,
430
- 'mlat' => $mlat
431
- );
432
- update_option( $wp_options_name, $mediafromftp_tbl );
433
-
434
- }
435
-
436
- }
437
-
438
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
req/class-mediafromftpadmin.php ADDED
@@ -0,0 +1,2279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media from FTP
4
+ *
5
+ * @package Media from FTP
6
+ * @subpackage MediafromFTPAdmin Main & Management screen
7
+ /*
8
+ Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
9
+ This program is free software; you can redistribute it and/or modify
10
+ it under the terms of the GNU General Public License as published by
11
+ the Free Software Foundation; version 2 of the License.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program; if not, write to the Free Software
20
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ $mediafromftpadmin = new MediaFromFtpAdmin();
24
+ add_filter( 'plugin_action_links', array( $mediafromftpadmin, 'settings_link' ), 10, 2 );
25
+ add_action( 'admin_footer', array( $mediafromftpadmin, 'custom_bulk_admin_footer' ) );
26
+ add_action( 'admin_notices', array( $mediafromftpadmin, 'notices' ) );
27
+
28
+ /** ==================================================
29
+ * Management screen
30
+ */
31
+ class MediaFromFtpAdmin {
32
+
33
+ /** ==================================================
34
+ * Path
35
+ *
36
+ * @var $plugin_base_url plugin_base_url.
37
+ */
38
+ private $plugin_base_url;
39
+
40
+ /** ==================================================
41
+ * Path
42
+ *
43
+ * @var $plugin_dir plugin_dir.
44
+ */
45
+ private $plugin_dir;
46
+
47
+ /** ==================================================
48
+ * Path
49
+ *
50
+ * @var $upload_dir upload_dir.
51
+ */
52
+ private $upload_dir;
53
+
54
+ /** ==================================================
55
+ * Path
56
+ *
57
+ * @var $upload_url upload_url.
58
+ */
59
+ private $upload_url;
60
+
61
+ /** ==================================================
62
+ * Path
63
+ *
64
+ * @var $upload_path upload_path.
65
+ */
66
+ private $upload_path;
67
+
68
+ /** ==================================================
69
+ * Path
70
+ *
71
+ * @var $plugin_tmp_url plugin_tmp_url.
72
+ */
73
+ private $plugin_tmp_url;
74
+
75
+ /** ==================================================
76
+ * Path
77
+ *
78
+ * @var $plugin_tmp_dir plugin_tmp_dir.
79
+ */
80
+ private $plugin_tmp_dir;
81
+
82
+ /** ==================================================
83
+ * Path
84
+ *
85
+ * @var $plugin_disallow_tmp_dir plugin_disallow_tmp_dir.
86
+ */
87
+ private $plugin_disallow_tmp_dir;
88
+
89
+ /** ==================================================
90
+ * Add on bool
91
+ *
92
+ * @var $is_add_on_activate is_add_on_activate.
93
+ */
94
+ private $is_add_on_activate;
95
+
96
+ /** ==================================================
97
+ * Construct
98
+ *
99
+ * @since 9.81
100
+ */
101
+ public function __construct() {
102
+
103
+ $plugin_base_dir = untrailingslashit( plugin_dir_path( __DIR__ ) );
104
+ $slugs = explode( '/', $plugin_base_dir );
105
+ $slug = end( $slugs );
106
+ $this->plugin_base_url = untrailingslashit( plugin_dir_url( __DIR__ ) );
107
+ $this->plugin_dir = untrailingslashit( rtrim( $plugin_base_dir, $slug ) );
108
+
109
+ if ( ! class_exists( 'MediaFromFtp' ) ) {
110
+ include_once $plugin_base_dir . '/inc/class-mediafromftp.php';
111
+ }
112
+ if ( ! class_exists( 'TT_MediaFromFtp_List_Table' ) ) {
113
+ require_once( $plugin_base_dir . '/req/class-tt-mediafromftp-list-table.php' );
114
+ }
115
+ $mediafromftp = new MediaFromFtp();
116
+ list($this->upload_dir, $this->upload_url, $this->upload_path) = $mediafromftp->upload_dir_url_path();
117
+
118
+ $this->plugin_tmp_url = $this->upload_url . '/media-from-ftp-tmp';
119
+ $this->plugin_tmp_dir = $this->upload_dir . '/media-from-ftp-tmp';
120
+ $this->plugin_disallow_tmp_dir = str_replace( home_url(), '', $mediafromftp->siteurl() ) . '/' . $this->upload_path . '/media-from-ftp-tmp/';
121
+
122
+ $category_active = false;
123
+ if ( function_exists( 'media_from_ftp_add_on_category_load_textdomain' ) ) {
124
+ include_once $this->plugin_dir . '/media-from-ftp-add-on-category/inc/MediaFromFtpAddOnCategory.php';
125
+ $category_active = true;
126
+ }
127
+ $exif_active = false;
128
+ if ( function_exists( 'media_from_ftp_add_on_exif_load_textdomain' ) ) {
129
+ include_once $this->plugin_dir . '/media-from-ftp-add-on-exif/inc/MediaFromFtpAddOnExif.php';
130
+ $exif_active = true;
131
+ }
132
+ $cli_active = false;
133
+ if ( function_exists( 'media_from_ftp_add_on_cli_load_textdomain' ) ) {
134
+ require_once( $this->plugin_dir . '/media-from-ftp-add-on-cli/req/MediaFromFtpCli.php' );
135
+ $cli_active = true;
136
+ }
137
+ $wpcron_active = false;
138
+ if ( function_exists( 'media_from_ftp_add_on_wpcron_load_textdomain' ) ) {
139
+ include_once $this->plugin_dir . '/media-from-ftp-add-on-wpcron/inc/MediaFromFtpAddOnWpcron.php';
140
+ $wpcron_active = true;
141
+ }
142
+ $this->is_add_on_activate = array(
143
+ 'category' => $category_active,
144
+ 'exif' => $exif_active,
145
+ 'cli' => $cli_active,
146
+ 'wpcron' => $wpcron_active,
147
+ );
148
+
149
+ add_action( 'admin_menu', array( $this, 'add_pages' ) );
150
+ add_action( 'admin_enqueue_scripts', array( $this, 'load_custom_wp_admin_style' ) );
151
+ add_action( 'admin_footer', array( $this, 'load_custom_wp_admin_style2' ) );
152
+ add_action( 'screen_settings', array( $this, 'search_register_show_screen_options' ), 10, 2 );
153
+ add_filter( 'set-screen-option', array( $this, 'search_register_set_screen_options' ), 11, 3 );
154
+ add_filter( 'contextual_help', array( $this, 'search_register_help_tab' ), 12, 3 );
155
+ add_filter( 'robots_txt', array( $this, 'custom_robots_txt' ), 9999 );
156
+
157
+ }
158
+
159
+ /** ==================================================
160
+ * Add a "Settings" link to the plugins page
161
+ *
162
+ * @param array $links links array.
163
+ * @param string $file file.
164
+ * @return array $links links array.
165
+ * @since 1.00
166
+ */
167
+ public function settings_link( $links, $file ) {
168
+ static $this_plugin;
169
+ if ( empty( $this_plugin ) ) {
170
+ $this_plugin = 'media-from-ftp/mediafromftp.php';
171
+ }
172
+ if ( $file == $this_plugin ) {
173
+ $links[] = '<a href="' . admin_url( 'admin.php?page=mediafromftp' ) . '">Media from FTP</a>';
174
+ $links[] = '<a href="' . admin_url( 'admin.php?page=mediafromftp-search-register' ) . '">' . __( 'Search & Register', 'media-from-ftp' ) . '</a>';
175
+ $links[] = '<a href="' . admin_url( 'admin.php?page=mediafromftp-settings' ) . '">' . __( 'Settings' ) . '</a>';
176
+ if ( $this->is_add_on_activate['wpcron'] ) {
177
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
178
+ $links[] = $mediafromftpaddonwpcron->mediafromftp_settings_link_html();
179
+ unset( $mediafromftpaddonwpcron );
180
+ }
181
+ $links[] = '<a href="' . admin_url( 'admin.php?page=mediafromftp-log' ) . '">' . __( 'Log', 'media-from-ftp' ) . '</a>';
182
+ $links[] = '<a href="' . admin_url( 'admin.php?page=mediafromftp-import' ) . '">' . __( 'Import' ) . '</a>';
183
+ $links[] = '<a href="' . admin_url( 'admin.php?page=mediafromftp-addons' ) . '">' . __( 'Add-Ons', 'media-from-ftp' ) . '</a>';
184
+ }
185
+ return $links;
186
+ }
187
+
188
+ /** ==================================================
189
+ * Add page
190
+ *
191
+ * @since 1.0
192
+ */
193
+ public function add_pages() {
194
+ add_menu_page(
195
+ 'Media from FTP',
196
+ 'Media from FTP',
197
+ 'upload_files',
198
+ 'mediafromftp',
199
+ array( $this, 'manage_page' ),
200
+ 'dashicons-upload'
201
+ );
202
+ add_submenu_page(
203
+ 'mediafromftp',
204
+ __( 'Search & Register', 'media-from-ftp' ),
205
+ __( 'Search & Register', 'media-from-ftp' ),
206
+ 'upload_files',
207
+ 'mediafromftp-search-register',
208
+ array( $this, 'search_register_page' )
209
+ );
210
+ add_submenu_page(
211
+ 'mediafromftp',
212
+ __( 'Settings' ),
213
+ __( 'Settings' ),
214
+ 'upload_files',
215
+ 'mediafromftp-settings',
216
+ array( $this, 'settings_page' )
217
+ );
218
+ if ( $this->is_add_on_activate['wpcron'] ) {
219
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
220
+ $mediafromftpaddonwpcron->mediafromftp_add_submenu();
221
+ unset( $mediafromftpaddonwpcron );
222
+ }
223
+ add_submenu_page(
224
+ 'mediafromftp',
225
+ __( 'Log', 'media-from-ftp' ),
226
+ __( 'Log', 'media-from-ftp' ),
227
+ 'upload_files',
228
+ 'mediafromftp-log',
229
+ array( $this, 'log_page' )
230
+ );
231
+ add_submenu_page(
232
+ 'mediafromftp',
233
+ __( 'Import' ),
234
+ __( 'Import' ),
235
+ 'upload_files',
236
+ 'mediafromftp-import',
237
+ array( $this, 'medialibrary_import_page' )
238
+ );
239
+ add_submenu_page(
240
+ 'mediafromftp',
241
+ __( 'Add-Ons', 'media-from-ftp' ),
242
+ __( 'Add-Ons', 'media-from-ftp' ),
243
+ 'upload_files',
244
+ 'mediafromftp-addons',
245
+ array( $this, 'addons_page' )
246
+ );
247
+ }
248
+
249
+ /** ==================================================
250
+ * Show Screen Option Search & Register
251
+ *
252
+ * @param string $status status.
253
+ * @param object $args args.
254
+ * @since 9.52
255
+ */
256
+ public function search_register_show_screen_options( $status, $args ) {
257
+
258
+ $mediafromftp_settings = get_option( $this->wp_options_name() );
259
+
260
+ $return = $status;
261
+ if ( 'media-from-ftp_page_mediafromftp-search-register' == $args->base ) {
262
+ $mediafromftp = new MediaFromFtp();
263
+ $return = wp_nonce_field( 'mff_search', 'media_from_ftp_search' );
264
+ $return .= '<div style="display: block; padding: 5px 15px">';
265
+ $return .= $mediafromftp->search_option_html( $mediafromftp_settings );
266
+ $return .= '<div style="display: block;padding:5px 5px">' . get_submit_button( __( 'Apply' ), 'primary', 'media-from-ftp-screen-options-apply', false ) . '</div>';
267
+ $return .= '<input type="hidden" name="wp_screen_options[option]" value="media_from_ftp_show_screen" />';
268
+ $return .= '<input type="hidden" name="wp_screen_options[value]" value="2" />';
269
+ $return .= '</div>';
270
+ unset( $mediafromftp );
271
+ }
272
+
273
+ return $return;
274
+
275
+ }
276
+
277
+ /** ==================================================
278
+ * Save Screen Option Search & Register
279
+ *
280
+ * @param string $status status.
281
+ * @param string $option option.
282
+ * @param int $value value.
283
+ * @since 9.52
284
+ */
285
+ public function search_register_set_screen_options( $status, $option, $value ) {
286
+ if ( 'media_from_ftp_show_screen' == $option ) {
287
+ $this->options_updated( $value );
288
+ return $value;
289
+ }
290
+ return $status;
291
+ }
292
+
293
+ /** ==================================================
294
+ * Help Tab
295
+ *
296
+ * @param string $help help.
297
+ * @param string $screen_id screen_id.
298
+ * @param object $screen screen.
299
+ * @since 9.53
300
+ */
301
+ public function search_register_help_tab( $help, $screen_id, $screen ) {
302
+
303
+ if ( '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' === $screen_id ) {
304
+ $sidebar = '<p><strong>' . __( 'For more information:' ) . '</strong></p>';
305
+ $sidebar .= '<p><a href="' . __( 'https://wordpress.org/plugins/media-from-ftp/faq', 'media-from-ftp' ) . '" target="_blank">' . __( 'FAQ' ) . '</a></p>';
306
+ $sidebar .= '<p><a href="https://wordpress.org/support/plugin/media-from-ftp" target="_blank">' . __( 'Support Forums' ) . '</a></p>';
307
+ $sidebar .= '<p><a href="https://wordpress.org/support/view/plugin-reviews/media-from-ftp" target="_blank">' . __( 'Reviews', 'media-from-ftp' ) . '</a></p>';
308
+ /* translators: Translator */
309
+ $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>';
310
+ $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> <a style="text-decoration: none;" href="https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w" target="_blank"><span class="dashicons dashicons-video-alt3"></span></a></p>';
311
+ $sidebar .= '<p><a href="' . __( 'https://riverforest-wp.info/donate/', 'media-from-ftp' ) . '" target="_blank">' . __( 'Donate to this plugin &#187;' ) . '</a></p>';
312
+
313
+ $tabs = $this->get_help_message( $screen_id );
314
+ foreach ( $tabs as $tab ) {
315
+ $screen->add_help_tab( $tab );
316
+ }
317
+ $screen->set_help_sidebar( $sidebar );
318
+ }
319
+ }
320
+
321
+ /** ==================================================
322
+ * Help Tab for message
323
+ *
324
+ * @param string $screen_id screen_id.
325
+ * @return array $tab tab.
326
+ * @since 9.53
327
+ */
328
+ private function get_help_message( $screen_id ) {
329
+
330
+ $upload_dir_html = '<span style="color: red;">' . $this->upload_path . '</span>';
331
+
332
+ switch ( $screen_id ) {
333
+ case 'media-from-ftp_page_mediafromftp-search-register':
334
+ /* translators: Upload directory */
335
+ $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>';
336
+ /* translators: Update media */
337
+ $outline .= '<p>' . sprintf( __( 'Please check and press the "%1$s" button.', 'media-from-ftp' ), __( 'Update Media' ) ) . '</p>';
338
+ /* translators: Screen option */
339
+ $outline .= '<p>' . sprintf( __( 'Options for searching can be specified with "%1$s".', 'media-from-ftp' ), __( 'Screen Options' ) ) . '</p>';
340
+ break;
341
+ case 'media-from-ftp_page_mediafromftp-settings':
342
+ /* translators: Register */
343
+ $outline = '<p>' . sprintf( __( '"%1$s" sets options for %2$s registration.', 'media-from-ftp' ), __( 'Register' ), __( 'Media Library' ) ) . '</p>';
344
+ /* translators: Register option */
345
+ $outline .= '<p>' . sprintf( __( '"%1$s" sets other options.', 'media-from-ftp' ), __( 'Other', 'media-from-ftp' ) ) . '</p>';
346
+ if ( $this->is_add_on_activate['cli'] ) {
347
+ $mediafromftpcli = new MediaFromFtpCli();
348
+ $outline .= $mediafromftpcli->mediafromftp_settings_helptab_html();
349
+ }
350
+ break;
351
+ case 'media-from-ftp_page_mediafromftp-event':
352
+ if ( $this->is_add_on_activate['wpcron'] ) {
353
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
354
+ $outline = $mediafromftpaddonwpcron->mediafromftp_event_helptab_html();
355
+ }
356
+ break;
357
+ case 'media-from-ftp_page_mediafromftp-log':
358
+ $outline = '<p>' . __( 'Display history of registration.', 'media-from-ftp' ) . '</p>';
359
+ $outline .= '<p>' . __( 'You can export to CSV format.', 'media-from-ftp' ) . '</p>';
360
+ break;
361
+ case 'media-from-ftp_page_mediafromftp-import':
362
+ $outline = '<p>' . __( 'To Import the files to Media Library from a WordPress export file.', 'media-from-ftp' ) . '</p>';
363
+ /* translators: Upload directory */
364
+ $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>';
365
+ break;
366
+ case 'media-from-ftp_page_mediafromftp-addons':
367
+ $outline = '<p>' . __( 'This page shows paid add-ons and their summaries.', 'media-from-ftp' ) . '</p>';
368
+ $outline .= '<p>' . __( 'You can check whether it is installed or activated.', 'media-from-ftp' ) . '</p>';
369
+ break;
370
+ }
371
+
372
+ $tabs = array(
373
+ array(
374
+ 'title' => __( 'Overview' ),
375
+ 'id' => 'outline',
376
+ 'content' => $outline,
377
+ ),
378
+ );
379
+
380
+ return $tabs;
381
+ }
382
+
383
+ /** ==================================================
384
+ * Add Css and Script
385
+ *
386
+ * @since 2.23
387
+ */
388
+ public function load_custom_wp_admin_style() {
389
+ if ( $this->is_my_plugin_screen() ) {
390
+ $mediafromftp_settings = get_option( $this->wp_options_name() );
391
+ if ( $mediafromftp_settings['datetimepicker'] ) {
392
+ wp_enqueue_style( 'jquery-datetimepicker', $this->plugin_base_url . '/css/jquery.datetimepicker.css', array(), '2.3.4' );
393
+ }
394
+ wp_enqueue_style( 'jquery-responsiveTabs', $this->plugin_base_url . '/css/responsive-tabs.css', array(), '1.4.0' );
395
+ wp_enqueue_style( 'jquery-responsiveTabs-style', $this->plugin_base_url . '/css/style.css', array(), '1.4.0' );
396
+ wp_enqueue_style( 'mediafromftp', $this->plugin_base_url . '/css/mediafromftp.css', array(), '1.00' );
397
+ wp_enqueue_script( 'jquery' );
398
+ if ( $mediafromftp_settings['datetimepicker'] ) {
399
+ wp_enqueue_script( 'jquery-datetimepicker', $this->plugin_base_url . '/js/jquery.datetimepicker.js', null, '2.3.4' );
400
+ wp_enqueue_script( 'jquery-mediafromftp-datetimepicker', $this->plugin_base_url . '/js/jquery.mediafromftp.datetimepicker.js', array( 'jquery' ), '1.00', false );
401
+ }
402
+ wp_enqueue_script( 'jquery-responsiveTabs', $this->plugin_base_url . '/js/jquery.responsiveTabs.min.js', array(), '1.4.0', false );
403
+
404
+ $handle = 'mediafromftp-ajax-script';
405
+ $action1 = 'mediafromftp-update-ajax-action';
406
+ $action2 = 'mediafromftp-import-ajax-action';
407
+ $action3 = 'mediafromftp_message';
408
+ $action4 = 'mediafromftp_medialibraryimport_message';
409
+ wp_enqueue_script( $handle, $this->plugin_base_url . '/js/jquery.mediafromftp.js', array( 'jquery' ), '1.00', false );
410
+ wp_localize_script(
411
+ $handle,
412
+ 'MEDIAFROMFTPUPDATE',
413
+ array(
414
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
415
+ 'action' => $action1,
416
+ 'nonce' => wp_create_nonce( $action1 ),
417
+ )
418
+ );
419
+ wp_localize_script(
420
+ $handle,
421
+ 'MEDIAFROMFTPIMPORT',
422
+ array(
423
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
424
+ 'action' => $action2,
425
+ 'nonce' => wp_create_nonce( $action2 ),
426
+ )
427
+ );
428
+ wp_localize_script(
429
+ $handle,
430
+ 'MEDIAFROMFTPMESSAGE',
431
+ array(
432
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
433
+ 'action' => $action3,
434
+ 'nonce' => wp_create_nonce( $action3 ),
435
+ )
436
+ );
437
+ wp_localize_script(
438
+ $handle,
439
+ 'MEDIAFROMFTPIMPORTMESSAGE',
440
+ array(
441
+ 'ajax_url' => admin_url( 'admin-ajax.php' ),
442
+ 'action' => $action4,
443
+ 'nonce' => wp_create_nonce( $action4 ),
444
+ )
445
+ );
446
+ }
447
+ }
448
+
449
+ /** ==================================================
450
+ * Add Script on footer
451
+ *
452
+ * @since 1.0
453
+ */
454
+ public function load_custom_wp_admin_style2() {
455
+ if ( $this->is_my_plugin_screen2() ) {
456
+ if ( isset( $_POST['media_from_ftp_select_author'] ) && ! empty( $_POST['media_from_ftp_select_author'] ) ) {
457
+ if ( check_admin_referer( 'mff_select_author', 'media_from_ftp_select_author' ) ) {
458
+ if ( ! empty( $_POST['mediafromftp_select_author'] ) && ! empty( $_POST['mediafromftp_xml_file'] ) ) {
459
+ $filename = sanitize_text_field( wp_unslash( $_POST['mediafromftp_xml_file'] ) );
460
+ if ( is_file( $filename ) ) {
461
+ $select_author = array();
462
+ foreach ( array_keys( $_POST ) as $key ) {
463
+ if ( 'select_author' === $key || 'mediafromftp_select_author' === $key || 'mediafromftp_xml_file' === $key ) {
464
+ /* skip */
465
+ $dummy = 0;
466
+ } else {
467
+ if ( isset( $_POST[ $key ] ) && -1 <> $_POST[ $key ] ) {
468
+ $select_author[ $key ] = intval( $_POST[ $key ] );
469
+ }
470
+ }
471
+ }
472
+ if ( ! validate_file( $filename ) ) {
473
+ $filename = sanitize_text_field( wp_unslash( $_POST['mediafromftp_xml_file'] ) );
474
+ $mediafromftp = new MediaFromFtp();
475
+ $handle = 'mediafromftp-import-ajax-script';
476
+ wp_enqueue_script( 'jquery' );
477
+ wp_enqueue_script( $handle, $this->plugin_base_url . '/js/jquery.mediafromftp.js', array( 'jquery' ), '1.00', false );
478
+ wp_add_inline_script( $handle, $mediafromftp->make_object( $filename, $select_author ) );
479
+ unset( $mediafromftp );
480
+ unlink( $filename );
481
+ }
482
+ }
483
+ }
484
+ }
485
+ }
486
+ }
487
+ }
488
+
489
+ /** ==================================================
490
+ * For only admin style
491
+ *
492
+ * @since 8.82
493
+ */
494
+ private function is_my_plugin_screen() {
495
+ $screen = get_current_screen();
496
+ if ( is_object( $screen ) && 'toplevel_page_mediafromftp' === $screen->id ) {
497
+ return true;
498
+ } else if ( is_object( $screen ) && 'media-from-ftp_page_mediafromftp-settings' === $screen->id ) {
499
+ return true;
500
+ } else if ( is_object( $screen ) && 'media-from-ftp_page_mediafromftp-search-register' === $screen->id ) {
501
+ return true;
502
+ } else if ( is_object( $screen ) && 'media-from-ftp_page_mediafromftp-event' === $screen->id ) {
503
+ return true;
504
+ } else if ( is_object( $screen ) && 'media-from-ftp_page_mediafromftp-log' === $screen->id ) {
505
+ return true;
506
+ } else if ( is_object( $screen ) && 'media-from-ftp_page_mediafromftp-import' === $screen->id ) {
507
+ return true;
508
+ } else if ( is_object( $screen ) && 'media-from-ftp_page_mediafromftp-addons' === $screen->id ) {
509
+ return true;
510
+ } else {
511
+ return false;
512
+ }
513
+ }
514
+
515
+ /** ==================================================
516
+ * For only admin style
517
+ *
518
+ * @since 8.82
519
+ */
520
+ private function is_my_plugin_screen2() {
521
+ $screen = get_current_screen();
522
+ if ( is_object( $screen ) && 'media-from-ftp_page_mediafromftp-import' === $screen->id ) {
523
+ return true;
524
+ } else {
525
+ return false;
526
+ }
527
+ }
528
+
529
+ /** ==================================================
530
+ * For only admin style
531
+ *
532
+ * @since 9.63
533
+ */
534
+ private function is_my_plugin_screen3() {
535
+ $screen = get_current_screen();
536
+ if ( is_object( $screen ) && 'media-from-ftp_page_mediafromftp-search-register' === $screen->id ) {
537
+ return true;
538
+ } else if ( is_object( $screen ) && 'media-from-ftp_page_mediafromftp-settings' === $screen->id ) {
539
+ return true;
540
+ } else {
541
+ return false;
542
+ }
543
+ }
544
+
545
+ /** ==================================================
546
+ * Main
547
+ *
548
+ * @since 1.00
549
+ */
550
+ public function manage_page() {
551
+
552
+ if ( ! current_user_can( 'upload_files' ) ) {
553
+ wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
554
+ }
555
+
556
+ ?>
557
+
558
+ <div class="wrap">
559
+
560
+ <h2>Media from FTP
561
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-search-register' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Search & Register', 'media-from-ftp' ); ?></a>
562
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-settings' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Settings' ); ?></a>
563
+ <?php
564
+ if ( $this->is_add_on_activate['wpcron'] ) {
565
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
566
+ $mediafromftpaddonwpcron->mediafromftp_event_link_html();
567
+ unset( $mediafromftpaddonwpcron );
568
+ }
569
+ ?>
570
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-log' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Log', 'media-from-ftp' ); ?></a>
571
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-import' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Import' ); ?></a>
572
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-addons' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Add-Ons', 'media-from-ftp' ); ?></a>
573
+ </h2>
574
+ <div style="clear: both;"></div>
575
+
576
+ <h3><?php esc_html_e( 'Register to media library from files that have been uploaded by FTP.', 'media-from-ftp' ); ?></h3>
577
+
578
+ <?php $this->credit(); ?>
579
+ <hr>
580
+ <?php $this->server_path_status(); ?>
581
+
582
+ </div>
583
+ <?php
584
+
585
+ }
586
+
587
+ /** ==================================================
588
+ * Credit
589
+ *
590
+ * @since 1.00
591
+ */
592
+ private function credit() {
593
+
594
+ $plugin_name = null;
595
+ $plugin_ver_num = null;
596
+ $plugin_path = plugin_dir_path( __DIR__ );
597
+ $plugin_dir = untrailingslashit( $plugin_path );
598
+ $slugs = explode( '/', $plugin_dir );
599
+ $slug = end( $slugs );
600
+ $files = scandir( $plugin_dir );
601
+ foreach ( $files as $file ) {
602
+ if ( '.' === $file || '..' === $file || is_dir( $plugin_path . $file ) ) {
603
+ continue;
604
+ } else {
605
+ $exts = explode( '.', $file );
606
+ $ext = strtolower( end( $exts ) );
607
+ if ( 'php' === $ext ) {
608
+ $plugin_datas = get_file_data(
609
+ $plugin_path . $file,
610
+ array(
611
+ 'name' => 'Plugin Name',
612
+ 'version' => 'Version',
613
+ )
614
+ );
615
+ if ( array_key_exists( 'name', $plugin_datas ) && ! empty( $plugin_datas['name'] ) && array_key_exists( 'version', $plugin_datas ) && ! empty( $plugin_datas['version'] ) ) {
616
+ $plugin_name = $plugin_datas['name'];
617
+ $plugin_ver_num = $plugin_datas['version'];
618
+ break;
619
+ }
620
+ }
621
+ }
622
+ }
623
+ $plugin_version = __( 'Version:' ) . ' ' . $plugin_ver_num;
624
+ /* translators: FAQ Link & Slug */
625
+ $faq = sprintf( esc_html__( 'https://wordpress.org/plugins/%s/faq', '%s' ), $slug );
626
+ $support = 'https://wordpress.org/support/plugin/' . $slug;
627
+ $review = 'https://wordpress.org/support/view/plugin-reviews/' . $slug;
628
+ $translate = 'https://translate.wordpress.org/projects/wp-plugins/' . $slug;
629
+ $facebook = 'https://www.facebook.com/katsushikawamori/';
630
+ $twitter = 'https://twitter.com/dodesyo312';
631
+ $youtube = 'https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w';
632
+ $donate = sprintf( esc_html__( 'https://shop.riverforest-wp.info/donate/', '%s' ), $slug );
633
+
634
+ ?>
635
+ <span style="font-weight: bold;">
636
+ <div>
637
+ <?php echo esc_html( $plugin_version ); ?> |
638
+ <a style="text-decoration: none;" href="<?php echo esc_url( $faq ); ?>" target="_blank"><?php esc_html_e( 'FAQ' ); ?></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $support ); ?>" target="_blank"><?php esc_html_e( 'Support Forums' ); ?></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $review ); ?>" target="_blank"><?php sprintf( esc_html_e( 'Reviews', '%s' ), $slug ); ?></a>
639
+ </div>
640
+ <div>
641
+ <a style="text-decoration: none;" href="<?php echo esc_url( $translate ); ?>" target="_blank">
642
+ <?php
643
+ /* translators: Plugin translation link */
644
+ echo sprintf( esc_html__( 'Translations for %s' ), esc_html( $plugin_name ) );
645
+ ?>
646
+ </a> | <a style="text-decoration: none;" href="<?php echo esc_url( $facebook ); ?>" target="_blank"><span class="dashicons dashicons-facebook"></span></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $twitter ); ?>" target="_blank"><span class="dashicons dashicons-twitter"></span></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $youtube ); ?>" target="_blank"><span class="dashicons dashicons-video-alt3"></span></a>
647
+ </div>
648
+ </span>
649
+
650
+ <div style="width: 250px; height: 180px; margin: 5px; padding: 5px; border: #CCC 2px solid;">
651
+ <h3><?php sprintf( esc_html_e( 'Please make a donation if you like my work or would like to further the development of this plugin.', '%s' ), $slug ); ?></h3>
652
+ <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>
653
+ <button type="button" style="margin: 5px; padding: 5px;" onclick="window.open('<?php echo esc_url( $donate ); ?>')"><?php esc_html_e( 'Donate to this plugin &#187;' ); ?></button>
654
+ </div>
655
+
656
+ <?php
657
+
658
+ }
659
+
660
+ /** ==================================================
661
+ * Server Path Status
662
+ *
663
+ * @since 1.00
664
+ */
665
+ private function server_path_status() {
666
+
667
+ ?>
668
+ <h3><?php esc_html_e( 'Server path status', 'media-from-ftp' ); ?></h3>
669
+ <h4><?php esc_html_e( 'If something goes wrong, please report the following to the support forum. If you do not want to show the Url or Path, please hide it part.', 'media-from-ftp' ); ?></h4>
670
+ <?php
671
+ $wp_uploads = wp_upload_dir();
672
+ $mediafromftp = new MediaFromFtp();
673
+ $status = "\n";
674
+ $status .= 'WordPress' . "\n";
675
+ $status .= 'home_url: ' . home_url() . "\n";
676
+ $status .= 'ABSPATH: ' . wp_normalize_path( ABSPATH ) . "\n";
677
+ $status .= 'wp_upload_dir[basedir]: ' . $wp_uploads['basedir'] . "\n";
678
+ $status .= 'wp_upload_dir[baseurl]: ' . $wp_uploads['baseurl'] . "\n";
679
+ $status .= 'upload_path: ' . get_option( 'upload_path' ) . "\n";
680
+ $status .= 'upload_url_path: ' . get_option( 'upload_url_path' ) . "\n";
681
+ $status .= 'WPINC: ' . WPINC . "\n";
682
+ $status .= "\n";
683
+ $status .= 'Media from FTP' . "\n";
684
+ $status .= 'Upload Dir: ' . $this->upload_dir . "\n";
685
+ $status .= 'Upload Url: ' . $this->upload_url . "\n";
686
+ $status .= 'Upload Path: ' . $this->upload_path . "\n";
687
+ $status .= 'Plugin Disallow Tmp Dir: ' . $this->plugin_disallow_tmp_dir . "\n";
688
+ $status .= 'Site Url: ' . $mediafromftp->siteurl() . "\n";
689
+ ?>
690
+ <textarea readonly rows="16" style="font-size: 12px; width: 100%;">
691
+ <?php echo esc_textarea( $status ); ?>
692
+ </textarea>
693
+ <?php
694
+
695
+ }
696
+
697
+ /** ==================================================
698
+ * Sub Menu
699
+ *
700
+ * @since 1.00
701
+ */
702
+ public function settings_page() {
703
+
704
+ if ( ! current_user_can( 'upload_files' ) ) {
705
+ wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
706
+ }
707
+
708
+ $this->options_updated( 1 );
709
+ $this->options_updated( 2 );
710
+ $this->options_updated( 3 );
711
+ $this->options_updated( 4 );
712
+ $this->options_updated( 5 );
713
+ $this->options_updated( 6 );
714
+ $this->options_updated( 7 );
715
+
716
+ $mediafromftp = new MediaFromFtp();
717
+
718
+ $mediafromftp_addon_wpcron = false;
719
+ if ( $this->is_add_on_activate['wpcron'] ) {
720
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
721
+ $mediafromftp_addon_wpcron = true;
722
+ }
723
+
724
+ $mediafromftp_addon_category = false;
725
+ if ( $this->is_add_on_activate['category'] ) {
726
+ $mediafromftpaddoncategory = new MediaFromFtpAddOnCategory();
727
+ $mediafromftp_addon_category = true;
728
+ }
729
+
730
+ $mediafromftp_addon_exif = false;
731
+ if ( $this->is_add_on_activate['exif'] ) {
732
+ $mediafromftpaddonexif = new MediaFromFtpAddOnExif();
733
+ $mediafromftp_addon_exif = true;
734
+ }
735
+
736
+ $mediafromftp_settings = get_option( $this->wp_options_name() );
737
+
738
+ $def_max_execution_time = ini_get( 'max_execution_time' );
739
+ $scriptname = admin_url( 'admin.php?page=mediafromftp-settings' );
740
+
741
+ ?>
742
+
743
+ <div class="wrap">
744
+
745
+ <h2>Media from FTP <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-settings' ) ); ?>" style="text-decoration: none;"><?php esc_html_e( 'Settings' ); ?></a>
746
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-search-register' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Search & Register', 'media-from-ftp' ); ?></a>
747
+ <?php
748
+ if ( $mediafromftp_addon_wpcron ) {
749
+ $mediafromftpaddonwpcron->mediafromftp_event_link_html();
750
+ }
751
+ ?>
752
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-log' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Log', 'media-from-ftp' ); ?></a>
753
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-import' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Import' ); ?></a>
754
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-addons' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Add-Ons', 'media-from-ftp' ); ?></a>
755
+ </h2>
756
+ <div style="clear: both;"></div>
757
+
758
+ <div id="mediafromftp-settings-tabs">
759
+ <ul>
760
+ <li><a href="#mediafromftp-settings-tabs-1"><?php esc_html_e( 'Register' ); ?></a></li>
761
+ <li><a href="#mediafromftp-settings-tabs-2"><?php esc_html_e( 'Search' ); ?></a></li>
762
+ <li><a href="#mediafromftp-settings-tabs-3"><?php esc_html_e( 'Other', 'media-from-ftp' ); ?></a></li>
763
+ <?php
764
+ if ( $this->is_add_on_activate['cli'] ) {
765
+ $mediafromftpcli = new MediaFromFtpCli();
766
+ $mediafromftpcli->mediafromftp_settings_tab_menu_html();
767
+ }
768
+ ?>
769
+ </ul>
770
+
771
+ <div id="mediafromftp-settings-tabs-1">
772
+ <div style="display: block; padding: 5px 15px">
773
+ <div class="item-mediafromftp-settings">
774
+ <h3><?php esc_html_e( 'Date' ); ?></h3>
775
+ <div style="display: block;padding:5px 5px">
776
+ <input type="radio" name="mediafromftp_dateset" form="mediafromftp_settings_form" value="new"
777
+ <?php
778
+ if ( 'new' === $mediafromftp_settings['dateset'] ) {
779
+ echo 'checked';
780
+ }
781
+ ?>
782
+ >
783
+ <?php esc_html_e( 'Update to use of the current date/time.', 'media-from-ftp' ); ?>
784
+ </div>
785
+ <div style="display: block;padding:5px 5px">
786
+ <input type="radio" name="mediafromftp_dateset" form="mediafromftp_settings_form" value="server"
787
+ <?php
788
+ if ( 'server' === $mediafromftp_settings['dateset'] ) {
789
+ echo 'checked';
790
+ }
791
+ ?>
792
+ >
793
+ <?php esc_html_e( 'Get the date/time of the file, and updated based on it. Change it if necessary.', 'media-from-ftp' ); ?>
794
+ </div>
795
+ <div style="display: block; padding:5px 5px">
796
+ <input type="radio" name="mediafromftp_dateset" form="mediafromftp_settings_form" value="exif"
797
+ <?php
798
+ if ( 'exif' === $mediafromftp_settings['dateset'] ) {
799
+ echo 'checked';
800
+ }
801
+ ?>
802
+ >
803
+ <?php
804
+ esc_html_e( 'Get the date/time of the file, and updated based on it. Change it if necessary.', 'media-from-ftp' );
805
+ esc_html_e( 'Get by priority if there is date and time of the Exif information.', 'media-from-ftp' );
806
+ ?>
807
+ </div>
808
+ <div style="display: block; padding:5px 5px">
809
+ <input type="radio" name="mediafromftp_dateset" form="mediafromftp_settings_form" value="fixed"
810
+ <?php
811
+ if ( 'fixed' === $mediafromftp_settings['dateset'] ) {
812
+ echo 'checked';
813
+ }
814
+ ?>
815
+ >
816
+ <?php esc_html_e( 'Update to use of fixed the date/time.', 'media-from-ftp' ); ?>
817
+ </div>
818
+ <div style="display: block; padding:5px 40px">
819
+ <input type="text" id="datetimepicker-mediafromftp00" name="mediafromftp_datefixed" form="mediafromftp_settings_form" value="<?php echo esc_attr( $mediafromftp_settings['datefixed'] ); ?>">
820
+ </div>
821
+ <div style="display: block; padding:5px 5px">
822
+ <?php
823
+ if ( current_user_can( 'manage_options' ) ) {
824
+ ?>
825
+ <input type="checkbox" name="move_yearmonth_folders" form="mediafromftp_settings_form" value="1" <?php checked( '1', get_option( 'uploads_use_yearmonth_folders' ) ); ?> />
826
+ <?php
827
+ } else {
828
+ ?>
829
+ <input type="checkbox" form="mediafromftp_settings_form" disabled="disabled" value="1" <?php checked( '1', get_option( 'uploads_use_yearmonth_folders' ) ); ?> />
830
+ <input type="hidden" name="move_yearmonth_folders" form="mediafromftp_settings_form" value="<?php echo esc_attr( get_option( 'uploads_use_yearmonth_folders' ) ); ?>">
831
+ <?php
832
+ }
833
+ esc_html_e( 'Organize my uploads into month- and year-based folders' );
834
+ ?>
835
+ </div>
836
+
837
+ <div style="display: block; padding:5px 5px">
838
+ <input type="checkbox" name="mediafromftp_datetimepicker" form="mediafromftp_settings_form" value="1" <?php checked( '1', $mediafromftp_settings['datetimepicker'] ); ?> />
839
+ <a href="https://xdsoft.net/jqplugins/datetimepicker/" target="_blank" style="text-decoration: none;">Date Time Picker</a>(jQuery <?php esc_html_e( 'Plugin' ); ?>)
840
+ <?php esc_html_e( 'Date and time input assistance', 'media-from-ftp' ); ?>
841
+ </div>
842
+
843
+ </div>
844
+
845
+ <div class="item-mediafromftp-settings">
846
+ <h3><?php esc_html_e( 'Log', 'media-from-ftp' ); ?></h3>
847
+ <div style="display:block;padding:5px 0">
848
+ <?php esc_html_e( 'Record the registration result.', 'media-from-ftp' ); ?>
849
+ </div>
850
+ <div style="display:block;padding:5px 0">
851
+ <input type="checkbox" name="mediafromftp_apply_log" form="mediafromftp_settings_form" value="1" <?php checked( '1', $mediafromftp_settings['log'] ); ?> />
852
+ <?php esc_html_e( 'Create log', 'media-from-ftp' ); ?>
853
+ </div>
854
+ </div>
855
+
856
+ <div class="item-mediafromftp-settings">
857
+ <h3><?php esc_html_e( 'Schedule', 'media-from-ftp' ); ?>(<?php esc_html_e( 'Cron Event', 'media-from-ftp' ); ?>)</h3>
858
+ <div style="display:block;padding:5px 0">
859
+ <?php esc_html_e( 'Set the schedule.', 'media-from-ftp' ); ?>
860
+ </div>
861
+ <?php
862
+ if ( $mediafromftp_addon_wpcron ) {
863
+ $mediafromftpaddonwpcron->mediafromftp_schedule_form( $scriptname, $mediafromftp_settings );
864
+ } else {
865
+ $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>';
866
+ /* translators: %1$s: add on url */
867
+ $use_add_on_html = sprintf( __( 'This function requires %1$s.', 'media-from-ftp' ), $add_on_url );
868
+ ?>
869
+ <div style="display:block;padding:5px 0">
870
+ <?php echo wp_kses_post( $use_add_on_html ); ?>
871
+ </div>
872
+ <?php
873
+ }
874
+ ?>
875
+ </div>
876
+
877
+ <div class="item-mediafromftp-settings">
878
+ <h3><?php esc_html_e( 'Categories' ); ?></h3>
879
+ <div style="display:block;padding:5px 0">
880
+ <?php esc_html_e( 'Specify categories to register at the same time when registering.', 'media-from-ftp' ); ?>
881
+ </div>
882
+ <?php
883
+ if ( $mediafromftp_addon_category ) {
884
+ $mlccs = explode( ',', $mediafromftp_settings['mlcc'] );
885
+ $emlcs = explode( ',', $mediafromftp_settings['emlc'] );
886
+ $mlacs = explode( ',', $mediafromftp_settings['mlac'] );
887
+ $mlats = explode( ',', $mediafromftp_settings['mlat'] );
888
+ $allowed_category_admin_html = array(
889
+ 'div' => array(
890
+ 'style' => array(),
891
+ ),
892
+ 'strong' => array(),
893
+ 'input' => array(
894
+ 'type' => array(),
895
+ 'name' => array(),
896
+ 'value' => array(),
897
+ 'checked' => array(),
898
+ 'form' => array(),
899
+ ),
900
+ );
901
+ echo wp_kses( $mediafromftpaddoncategory->mlc_category_admin_html( $mlccs ), $allowed_category_admin_html );
902
+ echo wp_kses( $mediafromftpaddoncategory->eml_category_admin_html( $emlcs ), $allowed_category_admin_html );
903
+ echo wp_kses( $mediafromftpaddoncategory->mla_category_admin_html( $mlacs, $mlats ), $allowed_category_admin_html );
904
+ } else {
905
+ $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>';
906
+ /* translators: %1$s: add on url */
907
+ $use_add_on_html = sprintf( __( 'This function requires %1$s.', 'media-from-ftp' ), $add_on_url );
908
+ ?>
909
+ <div style="display:block;padding:5px 0">
910
+ <?php echo wp_kses_post( $use_add_on_html ); ?>
911
+ </div>
912
+ <?php
913
+ }
914
+ ?>
915
+ </div>
916
+
917
+ <div class="item-mediafromftp-settings">
918
+ <h3>Exif <?php esc_html_e( 'Caption' ); ?></h3>
919
+ <div style="display:block;padding:5px 0">
920
+ <?php esc_html_e( 'Register the Exif data to the caption.', 'media-from-ftp' ); ?>
921
+ </div>
922
+ <?php
923
+ if ( $mediafromftp_addon_exif ) {
924
+ $mediafromftpaddonexif->mediafromftp_exif_form( $mediafromftp_settings );
925
+ } else {
926
+ $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>';
927
+ /* translators: %1$s: add on url */
928
+ $use_add_on_html = sprintf( __( 'This function requires %1$s.', 'media-from-ftp' ), $add_on_url );
929
+ ?>
930
+ <div style="display:block;padding:5px 0">
931
+ <?php echo wp_kses_post( $use_add_on_html ); ?>
932
+ </div>
933
+ <?php
934
+ }
935
+ ?>
936
+ </div>
937
+
938
+ <div style="clear: both;"></div>
939
+
940
+ <form method="post" id="mediafromftp_settings_form" action="<?php echo esc_url( $scriptname ); ?>">
941
+ <?php wp_nonce_field( 'mff_settings', 'media_from_ftp_settings' ); ?>
942
+ <div style="display: block;padding:5px 5px">
943
+ <?php submit_button( __( 'Save Changes' ), 'large', 'media-from-ftp-settings-options-apply', false ); ?>
944
+ </div>
945
+ </form>
946
+
947
+ </div>
948
+ </div>
949
+
950
+ <div id="mediafromftp-settings-tabs-2">
951
+ <div style="display: block; padding: 5px 15px">
952
+ <form method="post" id="mediafromftp_search_form" action="<?php echo esc_url( $scriptname ); ?>">
953
+ <?php wp_nonce_field( 'mff_search', 'media_from_ftp_search' ); ?>
954
+ <div class="item-mediafromftp-settings">
955
+ <h3><?php echo esc_html( __( 'Search' ) . ' ' . __( 'directory', 'media-from-ftp' ) . ' - ' . __( 'type', 'media-from-ftp' ) . ' - ' . __( 'extension', 'media-from-ftp' ) ); ?></h3>
956
+ <?php
957
+ $allowed_select_html = array(
958
+ 'div' => array(
959
+ 'style' => array(),
960
+ ),
961
+ 'code' => array(),
962
+ 'select' => array(
963
+ 'name' => array(),
964
+ 'style' => array(),
965
+ ),
966
+ 'option' => array(
967
+ 'value' => array(),
968
+ 'selected' => array(),
969
+ ),
970
+ );
971
+ echo wp_kses( $mediafromftp->dir_select_box( $mediafromftp_settings['searchdir'], $mediafromftp_settings['character_code'], wp_normalize_path( ABSPATH ) ), $allowed_select_html );
972
+ echo wp_kses( $mediafromftp->type_ext_select_box( $mediafromftp_settings['ext2typefilter'], $mediafromftp_settings['extfilter'] ), $allowed_select_html );
973
+ ?>
974
+ </div>
975
+ <?php
976
+ $allowed_search_option_html = array(
977
+ 'h3' => array(),
978
+ 'div' => array(
979
+ 'class' => array(),
980
+ 'style' => array(),
981
+ ),
982
+ 'label' => array(),
983
+ 'input' => array(
984
+ 'type' => array(),
985
+ 'step' => array(),
986
+ 'min' => array(),
987
+ 'max' => array(),
988
+ 'maxlength' => array(),
989
+ 'class' => array(),
990
+ 'name' => array(),
991
+ 'id' => array(),
992
+ 'class' => array(),
993
+ 'value' => array(),
994
+ 'checked' => array(),
995
+ ),
996
+ 'textarea' => array(
997
+ 'id' => array(),
998
+ 'name' => array(),
999
+ 'rows' => array(),
1000
+ 'style' => array(),
1001
+ ),
1002
+ );
1003
+ echo wp_kses( $mediafromftp->search_option_html( $mediafromftp_settings ), $allowed_search_option_html );
1004
+ ?>
1005
+ <div style="display: block;padding:5px 5px">
1006
+ <?php submit_button( __( 'Save Changes' ), 'large', 'media-from-ftp-search-options-apply', false ); ?>
1007
+ </div>
1008
+ </form>
1009
+ </div>
1010
+ </div>
1011
+
1012
+ <div id="mediafromftp-settings-tabs-3">
1013
+ <div style="display: block; padding: 5px 15px">
1014
+
1015
+ <div class="item-mediafromftp-settings">
1016
+ <h3><?php esc_html_e( 'Limit number of search files', 'media-from-ftp' ); ?></h3>
1017
+ <p>
1018
+ <?php esc_html_e( 'If you can not search because there are too many files, please reduce this number.', 'media-from-ftp' ); ?>
1019
+ </p>
1020
+ <div style="display:block;padding:5px 0">
1021
+ <input type="number" step="100" min="100" max="100000" name="mediafromftp_search_limit_number" value="<?php echo esc_attr( $mediafromftp_settings['search_limit_number'] ); ?>" form="mediafromftp_settings_form" >
1022
+ </div>
1023
+ <div style="clear: both;"></div>
1024
+ </div>
1025
+
1026
+ <div class="item-mediafromftp-settings">
1027
+ <h3><?php esc_html_e( 'Execution time', 'media-from-ftp' ); ?></h3>
1028
+ <div style="display:block; padding:5px 5px">
1029
+ <?php
1030
+ $max_execution_time = $mediafromftp_settings['max_execution_time'];
1031
+ if ( ! @set_time_limit( $max_execution_time ) ) {
1032
+ $limit_seconds_html = '<font color="red">' . $def_max_execution_time . __( 'seconds', 'media-from-ftp' ) . '</font>';
1033
+ /* translators: %1$s: limit max execution time */
1034
+ echo wp_kses_post( 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' ) ) );
1035
+ ?>
1036
+ <input type="hidden" name="mediafromftp_max_execution_time" form="mediafromftp_settings_form" value="<?php echo esc_attr( $def_max_execution_time ); ?>" />
1037
+ <?php
1038
+ } else {
1039
+ $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>])';
1040
+ esc_html_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' );
1041
+ esc_html_e( 'It does not matter on the registration screen.', 'media-from-ftp' );
1042
+ ?>
1043
+ <div style="float: left;"><?php echo wp_kses_post( $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 esc_attr( $max_execution_time ); ?>" /></div>
1044
+ <?php
1045
+ }
1046
+ ?>
1047
+ </div>
1048
+ <div style="clear: both;"></div>
1049
+ </div>
1050
+
1051
+ <?php
1052
+ if ( function_exists( 'mb_check_encoding' ) ) {
1053
+ ?>
1054
+ <div class="item-mediafromftp-settings">
1055
+ <h3><?php esc_html_e( 'Character Encodings for Server', 'media-from-ftp' ); ?></h3>
1056
+ <p>
1057
+ <?php
1058
+ esc_html_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' );
1059
+ $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>';
1060
+ /* translators: %1$s: URL of Variable-width_encoding */
1061
+ echo wp_kses_post( 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>' ) );
1062
+ ?>
1063
+ </p>
1064
+ <select name="mediafromftp_character_code" form="mediafromftp_settings_form" style="width: 210px">
1065
+ <?php
1066
+ if ( 'none' === $mediafromftp_settings['character_code'] ) {
1067
+ ?>
1068
+ <option value="none" selected>none</option>
1069
+ <?php
1070
+ } else {
1071
+ ?>
1072
+ <option value="none">none</option>
1073
+ <?php
1074
+ }
1075
+ foreach ( mb_list_encodings() as $chrcode ) {
1076
+ if ( 'pass' <> $chrcode && 'auto' <> $chrcode ) {
1077
+ if ( $chrcode === $mediafromftp_settings['character_code'] ) {
1078
+ ?>
1079
+ <option value="<?php echo esc_attr( $chrcode ); ?>" selected><?php echo esc_html( $chrcode ); ?></option>
1080
+ <?php
1081
+ } else {
1082
+ ?>
1083
+ <option value="<?php echo esc_attr( $chrcode ); ?>"><?php echo esc_html( $chrcode ); ?></option>
1084
+ <?php
1085
+ }
1086
+ }
1087
+ }
1088
+ ?>
1089
+ </select>
1090
+ <div style="clear: both;"></div>
1091
+ </div>
1092
+ <?php
1093
+ }
1094
+ ?>
1095
+
1096
+ <div class="item-mediafromftp-settings">
1097
+ <h3><?php esc_html_e( 'Remove Thumbnails Cache', 'media-from-ftp' ); ?></h3>
1098
+ <div style="display:block;padding:5px 0">
1099
+ <?php esc_html_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' ); ?>
1100
+ </div>
1101
+ <form method="post" action="<?php echo esc_url( $scriptname ); ?>" />
1102
+ <?php wp_nonce_field( 'mff_clear_cash', 'media_from_ftp_clear_cash' ); ?>
1103
+ <input type="hidden" name="mediafromftp_clear_cash" value="1" />
1104
+ <div>
1105
+ <?php submit_button( __( 'Remove Thumbnails Cache', 'media-from-ftp' ), 'delete', '', false ); ?>
1106
+ </div>
1107
+ </form>
1108
+ </div>
1109
+
1110
+ <div style="clear: both;"></div>
1111
+
1112
+ <div style="display: block;padding:5px 5px">
1113
+ <?php submit_button( __( 'Save Changes' ), 'large', 'media-from-ftp-settings-options-apply', false, array( 'form' => 'mediafromftp_settings_form' ) ); ?>
1114
+ </div>
1115
+
1116
+ </div>
1117
+ </div>
1118
+
1119
+ <?php
1120
+ if ( $this->is_add_on_activate['cli'] ) {
1121
+ $mediafromftpcli->mediafromftp_command_line_html( $this->wp_options_name() );
1122
+ unset( $mediafromftpcli );
1123
+ }
1124
+ ?>
1125
+
1126
+ </div>
1127
+ </div>
1128
+ <?php
1129
+ unset( $mediafromftpaddonwpcron );
1130
+ unset( $mediafromftpaddoncategory );
1131
+ }
1132
+
1133
+ /** ==================================================
1134
+ * Sub Menu
1135
+ *
1136
+ * @since 1.00
1137
+ */
1138
+ public function search_register_page() {
1139
+
1140
+ if ( ! current_user_can( 'upload_files' ) ) {
1141
+ wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
1142
+ }
1143
+
1144
+ $this->options_updated( 2 );
1145
+
1146
+ $mediafromftp_settings = get_option( $this->wp_options_name() );
1147
+
1148
+ $def_max_execution_time = ini_get( 'max_execution_time' );
1149
+ $max_execution_time = $mediafromftp_settings['max_execution_time'];
1150
+
1151
+ $limit_seconds_html = '<font color="red">' . $def_max_execution_time . __( 'seconds', 'media-from-ftp' ) . '</font>';
1152
+
1153
+ if ( ! @set_time_limit( $max_execution_time ) ) {
1154
+ /* translators: %1$s: limit max execution time */
1155
+ echo '<div class="notice notice-info is-dismissible"><ul><li>' . wp_kses_post( 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>';
1156
+ }
1157
+
1158
+ ?>
1159
+ <div class="wrap">
1160
+
1161
+ <h2>Media from FTP <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-search-register' ) ); ?>" style="text-decoration: none;"><?php esc_html_e( 'Search & Register', 'media-from-ftp' ); ?></a>
1162
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-settings' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Settings' ); ?></a>
1163
+ <?php
1164
+ $mediafromftp = new MediaFromFtp();
1165
+ if ( $this->is_add_on_activate['wpcron'] ) {
1166
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1167
+ $mediafromftpaddonwpcron->mediafromftp_event_link_html();
1168
+ unset( $mediafromftpaddonwpcron );
1169
+ }
1170
+ ?>
1171
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-log' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Log', 'media-from-ftp' ); ?></a>
1172
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-import' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Import' ); ?></a>
1173
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-addons' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Add-Ons', 'media-from-ftp' ); ?></a>
1174
+ </h2>
1175
+ <div style="clear: both;"></div>
1176
+
1177
+ <div id="mediafromftp-loading"><img src="<?php echo esc_url( $this->plugin_base_url . '/css/loading.gif' ); ?>"></div>
1178
+ <div id="mediafromftp-loading-container">
1179
+ <?php
1180
+ $media_from_ftp_list_table = new TT_MediaFromFtp_List_Table();
1181
+ $media_from_ftp_list_table->prepare_items( $mediafromftp_settings );
1182
+ if ( $media_from_ftp_list_table->max_items > 0 ) {
1183
+ $update_button = get_submit_button( __( 'Update Media' ), 'primary', '', false, array( 'form' => 'mediafromftp_ajax_update' ) );
1184
+ $update_upper_button = '<div style="padding: 15px 15px 0px;">' . $update_button . '</div>';
1185
+ $update_lower_button = '<div style="padding: 0px 15px;">' . $update_button . '</div>';
1186
+ } else {
1187
+ $update_upper_button = null;
1188
+ $update_lower_button = null;
1189
+ }
1190
+ $allowed_button_html = array(
1191
+ 'input' => array(
1192
+ 'type' => array(),
1193
+ 'name' => array(),
1194
+ 'id' => array(),
1195
+ 'class' => array(),
1196
+ 'value' => array(),
1197
+ 'form' => array(),
1198
+ ),
1199
+ 'div' => array(
1200
+ 'style' => array(),
1201
+ ),
1202
+ );
1203
+ $page = null;
1204
+ if ( isset( $_GET['page'] ) && ! empty( $_GET['page'] ) ) {
1205
+ $page = intval( $_GET['page'] );
1206
+ }
1207
+ $mediafromftp->form_html( $mediafromftp_settings );
1208
+ ?>
1209
+ <form method="post" id="mediafromftp_ajax_update">
1210
+ <form id="media-from-ftp-filter" method="get">
1211
+ <input type="hidden" name="page" value="<?php echo esc_attr( $page ); ?>" />
1212
+ <?php echo wp_kses( $update_upper_button, $allowed_button_html ); ?>
1213
+ <?php $media_from_ftp_list_table->display(); ?>
1214
+ <?php echo wp_kses( $update_lower_button, $allowed_button_html ); ?>
1215
+ </form>
1216
+ </form>
1217
+ </div>
1218
+ </div>
1219
+ <?php
1220
+ unset( $mediafromftp );
1221
+ }
1222
+
1223
+ /** ==================================================
1224
+ * Bulk Change Date Time
1225
+ *
1226
+ * @since 9.63
1227
+ */
1228
+ public function custom_bulk_admin_footer() {
1229
+ $mediafromftp_settings = get_option( $this->wp_options_name() );
1230
+ if ( 'server' === $mediafromftp_settings['dateset'] || 'exif' === $mediafromftp_settings['dateset'] ) {
1231
+ if ( $this->is_my_plugin_screen3() ) {
1232
+ $now_date_time = date_i18n( 'Y-m-d H:i' );
1233
+ $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>';
1234
+ $allowed_html = array(
1235
+ 'div' => array(
1236
+ 'style' => array(),
1237
+ ),
1238
+ 'input' => array(
1239
+ 'type' => array(),
1240
+ 'id' => array(),
1241
+ 'name' => array(),
1242
+ 'value' => array(),
1243
+ 'style' => array(),
1244
+ ),
1245
+ );
1246
+
1247
+ ?>
1248
+ <script type="text/javascript">
1249
+ jQuery('<?php echo wp_kses( $html, $allowed_html ); ?>').prependTo("#datetime");
1250
+ </script>
1251
+ <?php
1252
+ }
1253
+ }
1254
+ }
1255
+
1256
+ /** ==================================================
1257
+ * Sub Menu
1258
+ * for media-from-ftp-add-on-wpcron
1259
+ *
1260
+ * @since 1.00
1261
+ */
1262
+ public function event_page() {
1263
+
1264
+ $mediafromftp_addon_wpcron = false;
1265
+ $mediafromftp = new MediaFromFtp();
1266
+ if ( $this->is_add_on_activate['wpcron'] ) {
1267
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1268
+ include_once $this->plugin_dir . '/media-from-ftp-add-on-wpcron/req/MediaFromFtpCron.php';
1269
+ $mediafromftpcron = new MediaFromFtpCron();
1270
+ $mediafromftp_addon_wpcron = true;
1271
+ }
1272
+
1273
+ if ( ! current_user_can( 'upload_files' ) || ! $mediafromftp_addon_wpcron ) {
1274
+ wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
1275
+ }
1276
+
1277
+ $this->options_updated( 4 );
1278
+
1279
+ ?>
1280
+ <div class="wrap">
1281
+
1282
+ <h2>Media from FTP <?php echo wp_kses_post( $mediafromftpaddonwpcron->mediafromftp_event_top_link_html() ); ?>
1283
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-search-register' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Search & Register', 'media-from-ftp' ); ?></a>
1284
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-settings' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Settings' ); ?></a>
1285
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-log' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Log', 'media-from-ftp' ); ?></a>
1286
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-import' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Import' ); ?></a>
1287
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-addons' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Add-Ons', 'media-from-ftp' ); ?></a>
1288
+ </h2>
1289
+ <div style="clear: both;"></div>
1290
+ <p>
1291
+ <?php
1292
+
1293
+ if ( isset( $_POST['media_from_ftp_event'] ) && ! empty( $_POST['media_from_ftp_event'] ) ) {
1294
+ if ( check_admin_referer( 'mff_event', 'media_from_ftp_event' ) ) {
1295
+ if ( isset( $_POST['event-mediafromftp'] ) && ! empty( $_POST['event-mediafromftp'] ) ) {
1296
+ $events_mediafromftp = array_map( 'sanitize_text_field', wp_unslash( $_POST['event-mediafromftp'] ) );
1297
+ $events = get_option( $this->wp_add_on_wpcron_events_name() );
1298
+ $event_names = null;
1299
+ foreach ( $events_mediafromftp as $key => $event_id ) {
1300
+ $option_name = $events[ $event_id ];
1301
+ $mediafromftpcron->CronStop( $option_name );
1302
+ delete_option( $option_name );
1303
+ $event_names .= ' ' . $event_id . ' ';
1304
+ unset( $events[ $event_id ] );
1305
+ update_option( $this->wp_add_on_wpcron_events_name(), $events );
1306
+ }
1307
+ unset( $mediafromftpcron );
1308
+ $allowed_notice_html = array(
1309
+ 'div' => array(
1310
+ 'class' => array(),
1311
+ ),
1312
+ 'ul' => array(),
1313
+ 'li' => array(),
1314
+ );
1315
+ echo wp_kses( $mediafromftpaddonwpcron->mediafromftp_event_notice_html( $event_names ), $allowed_notice_html );
1316
+ }
1317
+ }
1318
+ }
1319
+
1320
+ $scriptname = admin_url( 'admin.php?page=mediafromftp-event' );
1321
+
1322
+ $allowed_event_html = array(
1323
+ 'form' => array(
1324
+ 'method' => array(),
1325
+ 'id' => array(),
1326
+ 'action' => array(),
1327
+ ),
1328
+ 'input' => array(
1329
+ 'type' => array(),
1330
+ 'name' => array(),
1331
+ 'id' => array(),
1332
+ 'class' => array(),
1333
+ 'value' => array(),
1334
+ ),
1335
+ 'table' => array(
1336
+ 'class' => array(),
1337
+ ),
1338
+ 'thead' => array(),
1339
+ 'tbody' => array(),
1340
+ 'tr' => array(),
1341
+ 'td' => array(),
1342
+ 'th' => array(
1343
+ 'scope' => array(),
1344
+ 'align' => array(),
1345
+ 'style' => array(),
1346
+ ),
1347
+ 'div' => array(),
1348
+ 'strong' => array(),
1349
+ 'button' => array(
1350
+ 'name' => array(),
1351
+ 'value' => array(),
1352
+ 'form' => array(),
1353
+ ),
1354
+ );
1355
+ echo wp_kses( $mediafromftpaddonwpcron->mediafromftp_event_html( $scriptname, get_option( $this->wp_add_on_wpcron_events_name() ) ), $allowed_event_html );
1356
+ ?>
1357
+ </div>
1358
+ <?php
1359
+
1360
+ }
1361
+
1362
+ /** ==================================================
1363
+ * Sub Menu
1364
+ *
1365
+ * @since 1.00
1366
+ */
1367
+ public function log_page() {
1368
+
1369
+ if ( ! current_user_can( 'upload_files' ) ) {
1370
+ wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
1371
+ }
1372
+
1373
+ $mediafromftp_settings = get_option( $this->wp_options_name() );
1374
+ if ( ! $mediafromftp_settings['log'] ) {
1375
+ echo '<div class="notice notice-info is-dismissible"><ul><li>' . esc_html__( '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>';
1376
+ }
1377
+ $def_max_execution_time = ini_get( 'max_execution_time' );
1378
+ $max_execution_time = $mediafromftp_settings['max_execution_time'];
1379
+
1380
+ $limit_seconds_html = '<font color="red">' . $def_max_execution_time . __( 'seconds', 'media-from-ftp' ) . '</font>';
1381
+ if ( ! @set_time_limit( $max_execution_time ) ) {
1382
+ /* translators: %1$s: default max execution time */
1383
+ echo '<div class="notice notice-info is-dismissible"><ul><li>' . wp_kses_post( 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>';
1384
+ }
1385
+
1386
+ ?>
1387
+ <div class="wrap">
1388
+
1389
+ <h2>Media from FTP <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-log' ) ); ?>" style="text-decoration: none;"><?php esc_html_e( 'Log', 'media-from-ftp' ); ?></a>
1390
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-search-register' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Search & Register', 'media-from-ftp' ); ?></a>
1391
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-settings' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Settings' ); ?></a>
1392
+ <?php
1393
+ if ( $this->is_add_on_activate['wpcron'] ) {
1394
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1395
+ $mediafromftpaddonwpcron->mediafromftp_event_link_html();
1396
+ unset( $mediafromftpaddonwpcron );
1397
+ }
1398
+ ?>
1399
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-import' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Import' ); ?></a>
1400
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-addons' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Add-Ons', 'media-from-ftp' ); ?></a>
1401
+ </h2>
1402
+ <div style="clear: both;"></div>
1403
+
1404
+ <div id="mediafromftp-loading"><img src="<?php echo esc_url( $this->plugin_base_url . '/css/loading.gif' ); ?>"></div>
1405
+ <div id="mediafromftp-loading-container">
1406
+ <?php
1407
+ global $wpdb;
1408
+
1409
+ $user = wp_get_current_user();
1410
+
1411
+ $wpdb->log_table_name = $wpdb->prefix . 'mediafromftp_log';
1412
+
1413
+ if ( isset( $_POST['media_from_ftp_clear_log'] ) && ! empty( $_POST['media_from_ftp_clear_log'] ) ) {
1414
+ if ( check_admin_referer( 'mff_clear_log', 'media_from_ftp_clear_log' ) ) {
1415
+ if ( ! empty( $_POST['mediafromftp_clear_log'] ) && 1 == $_POST['mediafromftp_clear_log'] ) {
1416
+ if ( current_user_can( 'administrator' ) ) {
1417
+ $wpdb->query( "DELETE FROM $wpdb->log_table_name" );
1418
+ echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html__( 'Removed all of the log.', 'media-from-ftp' ) . '</li></ul></div>';
1419
+ } else {
1420
+ $delete_count = $wpdb->delete( $wpdb->log_table_name, array( 'user' => $user->display_name ) );
1421
+ if ( $delete_count > 0 ) {
1422
+ /* translators: %1$s: username %2$d: delete count */
1423
+ echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html( sprintf( __( '%1$s of the log has been deleted %2$d.', 'media-from-ftp' ), $user->display_name, $delete_count ) ) . '</li></ul></div>';
1424
+ } else {
1425
+ /* translators: %1$s: username */
1426
+ echo '<div class="notice notice-info is-dismissible"><ul><li>' . esc_html( sprintf( __( '%1$s do not have a possible deletion log.', 'media-from-ftp' ), $user->display_name ) ) . '</li></ul></div>';
1427
+ }
1428
+ }
1429
+ }
1430
+ }
1431
+ }
1432
+
1433
+ $records = $wpdb->get_results( "SELECT * FROM $wpdb->log_table_name" );
1434
+
1435
+ $csv = null;
1436
+ $max_thumbnail_count = 0;
1437
+ $max_mlccategories_count = 0;
1438
+ $max_emlcategories_count = 0;
1439
+ $max_mlacategories_count = 0;
1440
+ $max_mlatags_count = 0;
1441
+ $html = '<table>';
1442
+
1443
+ foreach ( $records as $record ) {
1444
+ $csvs = '"' . $record->id . '","' . $record->user . '","' . $record->title . '","' . $record->permalink . '","' . $record->url . '","' . $record->filename . '","' . $record->time . '","' . $record->filetype . '","' . $record->filesize . '","' . $record->exif . '","' . $record->length . '"';
1445
+ $html_thumbnail = null;
1446
+ if ( $record->thumbnail ) {
1447
+ $thumbnails = json_decode( $record->thumbnail, true );
1448
+ if ( $max_thumbnail_count < count( $thumbnails ) ) {
1449
+ $max_thumbnail_count = count( $thumbnails );
1450
+ }
1451
+ $count = 0;
1452
+ foreach ( $thumbnails as $thumbnail ) {
1453
+ ++$count;
1454
+ $html_thumbnail .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Featured Image' ) . $count . ':</th><td>' . $thumbnail . '</td></tr>';
1455
+ $csvs .= ',"' . $thumbnail . '"';
1456
+ }
1457
+ }
1458
+ $html_mlccategory = null;
1459
+ if ( $record->mlccategories ) {
1460
+ $mlccategories = json_decode( $record->mlccategories, true );
1461
+ if ( $max_mlccategories_count < count( $mlccategories ) ) {
1462
+ $max_mlccategories_count = count( $mlccategories );
1463
+ }
1464
+ $count = 0;
1465
+ foreach ( $mlccategories as $mlccategory ) {
1466
+ ++$count;
1467
+ $html_mlccategory .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Categories' ) . '[Media Library Categories]' . $count . ':</th><td>' . $mlccategory . '</td></tr>';
1468
+ $csvs .= ',"' . $mlccategory . '"';
1469
+ }
1470
+ }
1471
+ $html_emlcategory = null;
1472
+ if ( $record->emlcategories ) {
1473
+ $emlcategories = json_decode( $record->emlcategories, true );
1474
+ if ( $max_emlcategories_count < count( $emlcategories ) ) {
1475
+ $max_emlcategories_count = count( $emlcategories );
1476
+ }
1477
+ $count = 0;
1478
+ foreach ( $emlcategories as $emlcategory ) {
1479
+ ++$count;
1480
+ $html_emlcategory .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Categories' ) . '[Enhanced Media Library]' . $count . ':</th><td>' . $emlcategory . '</td></tr>';
1481
+ $csvs .= ',"' . $emlcategory . '"';
1482
+ }
1483
+ }
1484
+ $html_mlacategory = null;
1485
+ if ( $record->mlacategories ) {
1486
+ $mlacategories = json_decode( $record->mlacategories, true );
1487
+ if ( $max_mlacategories_count < count( $mlacategories ) ) {
1488
+ $max_mlacategories_count = count( $mlacategories );
1489
+ }
1490
+ $count = 0;
1491
+ foreach ( $mlacategories as $mlacategory ) {
1492
+ ++$count;
1493
+ $html_mlacategory .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Categories' ) . '[Media Library Assistant]' . $count . ':</th><td>' . $mlacategory . '</td></tr>';
1494
+ $csvs .= ',"' . $mlacategory . '"';
1495
+ }
1496
+ }
1497
+ $html_mlatag = null;
1498
+ if ( $record->mlatags ) {
1499
+ $mlatags = json_decode( $record->mlatags, true );
1500
+ if ( $max_mlatags_count < count( $mlatags ) ) {
1501
+ $max_mlatags_count = count( $mlatags );
1502
+ }
1503
+ $count = 0;
1504
+ foreach ( $mlatags as $mlatag ) {
1505
+ ++$count;
1506
+ $html_mlatag .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Tags' ) . '[Media Library Assistant]' . $count . ':</th><td>' . $mlatag . '</td></tr>';
1507
+ $csvs .= ',"' . $mlatag . '"';
1508
+ }
1509
+ }
1510
+ $csvs .= "\n";
1511
+ $csv .= $csvs;
1512
+ $html .= '<tr><th>&nbsp;</th><td>&nbsp;</td></tr>';
1513
+ $html .= '<tr><th align="right" style="background-color: #cccccc;">ID:</th><td>' . $record->id . '</td></tr>';
1514
+ $html .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Author' ) . ':</th><td>' . $record->user . '</td></tr>';
1515
+ $html .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Title' ) . ':</th><td>' . $record->title . '</td></tr>';
1516
+ $html .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Permalink:' ) . '</th><td>' . $record->permalink . '</td></tr>';
1517
+ $html .= '<tr><th align="right" style="white-space: nowrap;">URL:</th><td>' . $record->url . '</td>';
1518
+ $html .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'File name:' ) . '</th><td>' . $record->filename . '</td></tr>';
1519
+ $html .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Date/Time' ) . ':</th><td>' . $record->time . '</td></tr>';
1520
+ $html .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'File type:' ) . '</th><td>' . $record->filetype . '</td></tr>';
1521
+ $html .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'File size:' ) . '</th><td>' . $record->filesize . '</td></tr>';
1522
+ if ( $record->exif ) {
1523
+ $html .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Caption' ) . '[Exif]:</th><td>' . $record->exif . '</td></tr>';
1524
+ }
1525
+ if ( $record->length ) {
1526
+ $html .= '<tr><th align="right" style="white-space: nowrap;">' . __( 'Length:' ) . '</th><td>' . $record->length . '</td></tr>';
1527
+ }
1528
+ $html .= $html_thumbnail . $html_mlccategory . $html_emlcategory . $html_mlacategory . $html_mlatag;
1529
+ }
1530
+ $html .= '</table>' . "\n";
1531
+ $csv_head = '"ID","' . __( 'Author' ) . '","' . __( 'Title' ) . ':","' . __( 'Permalink:' ) . '","URL:","' . __( 'File name:' ) . '","' . __( 'Date/Time' ) . ':","' . __( 'File type:' ) . '","' . __( 'File size:' ) . '","' . __( 'Caption' ) . '[Exif]:","' . __( 'Length:' ) . '"';
1532
+ for ( $i = 1; $i <= $max_thumbnail_count; $i++ ) {
1533
+ $csv_head .= ',"' . __( 'Featured Image' ) . $i . '"';
1534
+ }
1535
+ for ( $i = 1; $i <= $max_mlccategories_count; $i++ ) {
1536
+ $csv_head .= ',"' . __( 'Categories' ) . '[Media Library Categories]' . $i . '"';
1537
+ }
1538
+ for ( $i = 1; $i <= $max_emlcategories_count; $i++ ) {
1539
+ $csv_head .= ',"' . __( 'Categories' ) . '[Enhanced Media Library]' . $i . '"';
1540
+ }
1541
+ for ( $i = 1; $i <= $max_mlacategories_count; $i++ ) {
1542
+ $csv_head .= ',"' . __( 'Categories' ) . '[Media Library Assistant]' . $i . '"';
1543
+ }
1544
+ for ( $i = 1; $i <= $max_mlatags_count; $i++ ) {
1545
+ $csv_head .= ',"' . __( 'Tags' ) . '[Media Library Assistant]' . $i . '"';
1546
+ }
1547
+
1548
+ $csv = $csv_head . "\n" . $csv;
1549
+
1550
+ $csv_file_name = $this->plugin_tmp_dir . '/' . $wpdb->log_table_name . '.csv';
1551
+ if ( isset( $_POST['media_from_ftp_put_log'] ) && ! empty( $_POST['media_from_ftp_put_log'] ) ) {
1552
+ if ( check_admin_referer( 'mff_put_log', 'media_from_ftp_put_log' ) ) {
1553
+ if ( ! empty( $_POST['mediafromftp_put_log'] ) && 1 == $_POST['mediafromftp_put_log'] ) {
1554
+ file_put_contents( $csv_file_name, pack( 'C*', 0xEF, 0xBB, 0xBF ) ); /* UTF-8 BOM */
1555
+ file_put_contents( $csv_file_name, $csv, FILE_APPEND | LOCK_EX );
1556
+ }
1557
+ }
1558
+ } else {
1559
+ if ( file_exists( $csv_file_name ) ) {
1560
+ unlink( $csv_file_name );
1561
+ }
1562
+ }
1563
+
1564
+ if ( ! empty( $records ) ) {
1565
+ ?>
1566
+ <div style="display: block; padding: 10px 10px">
1567
+ <form style="float: left;" method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-log' ) ); ?>" />
1568
+ <?php wp_nonce_field( 'mff_clear_log', 'media_from_ftp_clear_log' ); ?>
1569
+ <input type="hidden" name="mediafromftp_clear_log" value="1" />
1570
+ <div>
1571
+ <?php submit_button( __( 'Delete log', 'media-from-ftp' ), 'large', '', false ); ?>
1572
+ </div>
1573
+ </form>
1574
+ <form style="float: left; margin-left: 0.5em; margin-right: 0.5em;" method="post" action="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-log' ) ); ?>" />
1575
+ <?php wp_nonce_field( 'mff_put_log', 'media_from_ftp_put_log' ); ?>
1576
+ <input type="hidden" name="mediafromftp_put_log" value="1" />
1577
+ <div>
1578
+ <?php submit_button( __( 'Export to CSV', 'media-from-ftp' ), 'large', '', false ); ?>
1579
+ </div>
1580
+ </form>
1581
+ <?php
1582
+ if ( file_exists( $csv_file_name ) ) {
1583
+ ?>
1584
+ <form method="post" action="<?php echo esc_url( $this->plugin_tmp_url . '/' . $wpdb->log_table_name . '.csv' ); ?>" />
1585
+ <?php wp_nonce_field( 'mff_download', 'media_from_ftp_download' ); ?>
1586
+ <div>
1587
+ <input type="hidden" name="mediafromftp_download" value="1" />
1588
+ <?php submit_button( __( 'Download CSV', 'media-from-ftp' ), 'large', '', false ); ?>
1589
+ </div>
1590
+ </form>
1591
+ <?php
1592
+ }
1593
+ ?>
1594
+ </div>
1595
+ <div style="clear: both;"></div>
1596
+ <div style="display: block; padding: 10px 10px">
1597
+ <?php
1598
+ $allowed_html = array(
1599
+ 'table' => array(),
1600
+ 'tr' => array(),
1601
+ 'td' => array(),
1602
+ 'th' => array(
1603
+ 'align' => array(),
1604
+ 'style' => array(),
1605
+ ),
1606
+ );
1607
+ echo wp_kses( $html, $allowed_html );
1608
+ ?>
1609
+ </div>
1610
+ <?php
1611
+ } else {
1612
+ if ( $mediafromftp_settings['log'] ) {
1613
+ echo '<div class="notice notice-info is-dismissible"><ul><li>' . esc_html__( 'There is no log.', 'media-from-ftp' ) . '</li></ul></div>';
1614
+ }
1615
+ }
1616
+ ?>
1617
+ </div>
1618
+
1619
+ </div>
1620
+
1621
+ <?php
1622
+
1623
+ }
1624
+
1625
+ /** ==================================================
1626
+ * Sub Menu
1627
+ *
1628
+ * @since 1.00
1629
+ */
1630
+ public function medialibrary_import_page() {
1631
+
1632
+ if ( ! current_user_can( 'upload_files' ) ) {
1633
+ wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
1634
+ }
1635
+
1636
+ $scriptname = admin_url( 'admin.php?page=mediafromftp-import' );
1637
+
1638
+ ?>
1639
+ <div class="wrap">
1640
+ <h2>Media from FTP <a href="<?php echo esc_url( $scriptname ); ?>" style="text-decoration: none;"><?php esc_html_e( 'Import' ); ?></a>
1641
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-search-register' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Search & Register', 'media-from-ftp' ); ?></a>
1642
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-settings' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Settings' ); ?></a>
1643
+ <?php
1644
+ if ( $this->is_add_on_activate['wpcron'] ) {
1645
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1646
+ $mediafromftpaddonwpcron->mediafromftp_event_link_html();
1647
+ unset( $mediafromftpaddonwpcron );
1648
+ }
1649
+ ?>
1650
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-log' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Log', 'media-from-ftp' ); ?></a>
1651
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-addons' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Add-Ons', 'media-from-ftp' ); ?></a>
1652
+ </h2>
1653
+ <div style="clear: both;"></div>
1654
+
1655
+ <div id="mediafromftp-loading"><img src="<?php echo esc_url( $this->plugin_base_url ) . '/css/loading.gif'; ?>"></div>
1656
+ <div id="medialibraryimport-loading-container">
1657
+
1658
+ <?php
1659
+ if ( isset( $_POST['media_from_ftp_file_load'] ) && ! empty( $_POST['media_from_ftp_file_load'] ) ) {
1660
+ if ( check_admin_referer( 'mff_file_load', 'media_from_ftp_file_load' ) ) {
1661
+ if ( isset( $_FILES['filename']['name'] ) && ! empty( $_FILES['filename']['name'] ) ) {
1662
+ if ( isset( $_FILES['filename']['tmp_name'] ) && ! empty( $_FILES['filename']['tmp_name'] ) ) {
1663
+ $filename = sanitize_text_field( wp_unslash( $_FILES['filename']['tmp_name'] ) );
1664
+ }
1665
+ $name = basename( $filename );
1666
+ move_uploaded_file( $filename, $this->plugin_tmp_dir . '/' . $name );
1667
+
1668
+ $mediafromftp = new MediaFromFtp();
1669
+ ?>
1670
+ <h4><?php esc_html_e( 'Assign Authors', 'media-from-ftp' ); ?></h4>
1671
+ <?php
1672
+ $allowed_author_select_html = array(
1673
+ 'strong' => array(),
1674
+ 'div' => array(
1675
+ 'style' => array(),
1676
+ ),
1677
+ 'form' => array(
1678
+ 'method' => array(),
1679
+ 'action' => array(),
1680
+ ),
1681
+ 'select' => array(
1682
+ 'name' => array(),
1683
+ ),
1684
+ 'option' => array(
1685
+ 'value' => array(),
1686
+ 'select' => array(),
1687
+ ),
1688
+ 'input' => array(
1689
+ 'name' => array(),
1690
+ 'type' => array(),
1691
+ 'size' => array(),
1692
+ 'id' => array(),
1693
+ 'class' => array(),
1694
+ 'value' => array(),
1695
+ ),
1696
+ );
1697
+ echo wp_kses( $mediafromftp->author_select( $this->plugin_tmp_dir . '/' . $name ), $allowed_author_select_html );
1698
+ }
1699
+ }
1700
+ } else if ( isset( $_POST['media_from_ftp_select_author'] ) && ! empty( $_POST['media_from_ftp_select_author'] ) ) {
1701
+ if ( check_admin_referer( 'mff_select_author', 'media_from_ftp_select_author' ) ) {
1702
+ if ( ! empty( $_POST['mediafromftp_select_author'] ) && ! empty( $_POST['mediafromftp_xml_file'] ) ) {
1703
+ if ( validate_file( wp_unslash( $_POST['mediafromftp_xml_file'] ) ) ) {
1704
+ echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'No such file exists! Double check the name and try again.' ) . '</li></ul></div>';
1705
+ ?>
1706
+ <form method="post" action="<?php echo esc_url( $scriptname ); ?>" enctype="multipart/form-data">
1707
+ <?php wp_nonce_field( 'mff_file_load', 'media_from_ftp_file_load' ); ?>
1708
+ <h4><?php esc_html_e( 'Select File' ); ?>[WordPress eXtended RSS (WXR)(.xml)]</h4>
1709
+ <div><input name="filename" type="file" size="80" /></div>
1710
+ <div>
1711
+ <?php submit_button( __( 'File Load', 'media-from-ftp' ), 'large', '', false ); ?>
1712
+ </div>
1713
+ </form>
1714
+ <?php
1715
+ } else {
1716
+ ?>
1717
+ <h4><?php esc_html_e( 'Ready to import. Press the following button to start the import.', 'media-from-ftp' ); ?></h4>
1718
+ <form method="post" id="medialibraryimport_ajax_update">
1719
+ <?php submit_button( __( 'Import' ), 'primary', '', false ); ?>
1720
+ </form>
1721
+ <?php
1722
+ }
1723
+ }
1724
+ }
1725
+ } else {
1726
+ ?>
1727
+ <form method="post" action="<?php echo esc_url( $scriptname ); ?>" enctype="multipart/form-data">
1728
+ <?php wp_nonce_field( 'mff_file_load', 'media_from_ftp_file_load' ); ?>
1729
+ <h4><?php esc_html_e( 'Select File' ); ?>[WordPress eXtended RSS (WXR)(.xml)]</h4>
1730
+ <div><input name="filename" type="file" size="80" /></div>
1731
+ <div>
1732
+ <?php submit_button( __( 'File Load', 'media-from-ftp' ), 'large', '', false ); ?>
1733
+ </div>
1734
+ </form>
1735
+ <?php
1736
+ }
1737
+ ?>
1738
+
1739
+ </div>
1740
+ </div>
1741
+
1742
+ <?php
1743
+ }
1744
+
1745
+ /** ==================================================
1746
+ * Sub Menu
1747
+ *
1748
+ * @since 1.00
1749
+ */
1750
+ public function addons_page() {
1751
+
1752
+ if ( ! current_user_can( 'upload_files' ) ) {
1753
+ wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
1754
+ }
1755
+
1756
+ $scriptname = admin_url( 'admin.php?page=mediafromftp-addons' );
1757
+
1758
+ ?>
1759
+ <div class="wrap">
1760
+
1761
+ <h2>Media from FTP <a href="<?php echo esc_url( $scriptname ); ?>" style="text-decoration: none;"><?php esc_html_e( 'Add-Ons', 'media-from-ftp' ); ?></a>
1762
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-search-register' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Search & Register', 'media-from-ftp' ); ?></a>
1763
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-settings' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Settings' ); ?></a>
1764
+ <?php
1765
+ if ( $this->is_add_on_activate['wpcron'] ) {
1766
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1767
+ $mediafromftpaddonwpcron->mediafromftp_event_link_html();
1768
+ unset( $mediafromftpaddonwpcron );
1769
+ }
1770
+ ?>
1771
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-log' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Log', 'media-from-ftp' ); ?></a>
1772
+ <a href="<?php echo esc_url( admin_url( 'admin.php?page=mediafromftp-import' ) ); ?>" class="page-title-action"><?php esc_html_e( 'Import' ); ?></a>
1773
+ </h2>
1774
+ <div style="clear: both;"></div>
1775
+
1776
+ <div style="width: 300px; height: 100%; margin: 10px; padding: 10px; border: #CCC 2px solid; float: left;">
1777
+ <h4>Media from FTP Add On Commandline</h4>
1778
+ <div style="margin: 5px; padding: 5px;"><?php esc_html_e( 'This add-on can use "Media from FTP" on the command-line.', 'media-from-ftp' ); ?></div>
1779
+ <div style="margin: 5px; padding: 5px;">
1780
+ <li><?php esc_html_e( 'The execution of the command line is supported.(lib/mediafromftpcmd.php)', 'media-from-ftp' ); ?></li>
1781
+ </div>
1782
+ <p>
1783
+ <?php
1784
+ if ( is_dir( $this->plugin_dir . '/media-from-ftp-add-on-cli' ) ) {
1785
+ ?>
1786
+ <div style="margin: 5px; padding: 5px;"><strong>
1787
+ <?php
1788
+ esc_html_e( 'Installed', 'media-from-ftp' );
1789
+ ?>
1790
+ &
1791
+ <?php
1792
+ if ( $this->is_add_on_activate['cli'] ) {
1793
+ esc_html_e( 'Activated', 'media-from-ftp' );
1794
+ } else {
1795
+ esc_html_e( 'Deactivated', 'media-from-ftp' );
1796
+ }
1797
+ ?>
1798
+ </strong></div>
1799
+ <?php
1800
+ } else {
1801
+ ?>
1802
+ <div>
1803
+ <a href="<?php echo esc_url( __( 'https://shop.riverforest-wp.info/media-from-ftp-add-on-cli/', 'media-from-ftp' ) ); ?>" target="_blank" class="page-title-action"><?php esc_html_e( 'BUY', 'media-from-ftp' ); ?></a>
1804
+ </div>
1805
+ <?php
1806
+ }
1807
+ ?>
1808
+ </div>
1809
+
1810
+ <div style="width: 300px; height: 100%; margin: 10px; padding: 10px; border: #CCC 2px solid; float: left;">
1811
+ <h4>Media from FTP Add On Wp Cron</h4>
1812
+ <div style="margin: 5px; padding: 5px;"><?php esc_html_e( 'This add-on can register and execute Cron Event with multiple settings by "Media from FTP".', 'media-from-ftp' ); ?></div>
1813
+ <div style="margin: 5px; padding: 5px;">
1814
+ <li><?php esc_html_e( 'Can start multiple Cron Events with multiple settings.', 'media-from-ftp' ); ?></li>
1815
+ <li><?php esc_html_e( 'Can add intervals of schedule.', 'media-from-ftp' ); ?></li>
1816
+ </div>
1817
+ <p>
1818
+ <?php
1819
+ if ( is_dir( $this->plugin_dir . '/media-from-ftp-add-on-wpcron' ) ) {
1820
+ ?>
1821
+ <div style="margin: 5px; padding: 5px;"><strong>
1822
+ <?php
1823
+ esc_html_e( 'Installed', 'media-from-ftp' );
1824
+ ?>
1825
+ &
1826
+ <?php
1827
+ if ( $this->is_add_on_activate['wpcron'] ) {
1828
+ esc_html_e( 'Activated', 'media-from-ftp' );
1829
+ } else {
1830
+ esc_html_e( 'Deactivated', 'media-from-ftp' );
1831
+ }
1832
+ ?>
1833
+ </strong></div>
1834
+ <?php
1835
+ } else {
1836
+ ?>
1837
+ <div>
1838
+ <a href="<?php echo esc_url( __( 'https://shop.riverforest-wp.info/media-from-ftp-add-on-wpcron/', 'media-from-ftp' ) ); ?>" target="_blank" class="page-title-action"><?php esc_html_e( 'BUY', 'media-from-ftp' ); ?></a>
1839
+ </div>
1840
+ <?php
1841
+ }
1842
+ ?>
1843
+ </div>
1844
+
1845
+ <div style="width: 300px; height: 100%; margin: 10px; padding: 10px; border: #CCC 2px solid; float: left;">
1846
+ <h4>Media from FTP Add On Category</h4>
1847
+ <div style="margin: 5px; padding: 5px;"><?php esc_html_e( 'This Add-on When registering by "Media from FTP", add Category to Media Library.', 'media-from-ftp' ); ?></div>
1848
+ <div style="margin: 5px; padding: 5px;">
1849
+ <li><?php esc_html_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>
1850
+ </div>
1851
+ <p>
1852
+ <?php
1853
+ if ( is_dir( $this->plugin_dir . '/media-from-ftp-add-on-category' ) ) {
1854
+ ?>
1855
+ <div style="margin: 5px; padding: 5px;"><strong>
1856
+ <?php
1857
+ esc_html_e( 'Installed', 'media-from-ftp' );
1858
+ ?>
1859
+ &
1860
+ <?php
1861
+ if ( $this->is_add_on_activate['category'] ) {
1862
+ esc_html_e( 'Activated', 'media-from-ftp' );
1863
+ } else {
1864
+ esc_html_e( 'Deactivated', 'media-from-ftp' );
1865
+ }
1866
+ ?>
1867
+ </strong></div>
1868
+ <?php
1869
+ } else {
1870
+ ?>
1871
+ <div>
1872
+ <a href="<?php echo esc_url( __( 'https://shop.riverforest-wp.info/media-from-ftp-add-on-category/', 'media-from-ftp' ) ); ?>" target="_blank" class="page-title-action"><?php esc_html_e( 'BUY', 'media-from-ftp' ); ?></a>
1873
+ </div>
1874
+ <?php
1875
+ }
1876
+ ?>
1877
+ </div>
1878
+
1879
+ <div style="width: 300px; height: 100%; margin: 10px; padding: 10px; border: #CCC 2px solid; float: left;">
1880
+ <h4>Media from FTP Add On Exif</h4>
1881
+ <div style="margin: 5px; padding: 5px;"><?php esc_html_e( 'This Add-on When registering by "Media from FTP", add Exif to Media Library Caption.', 'media-from-ftp' ); ?></div>
1882
+ <div style="margin: 5px; padding: 5px;">
1883
+ <li><?php esc_html_e( 'Sort each Exif data to an arbitrary position and insert it into the caption as text.', 'media-from-ftp' ); ?></li>
1884
+ <li><a style="text-decoration: none;" href="https://codex.wordpress.org/Function_Reference/wp_read_image_metadata#Return%20Values" target="_blank">Exif</a></li>
1885
+ </div>
1886
+
1887
+ <p>
1888
+ <?php
1889
+ if ( is_dir( $this->plugin_dir . '/media-from-ftp-add-on-exif' ) ) {
1890
+ ?>
1891
+ <div style="margin: 5px; padding: 5px;"><strong>
1892
+ <?php
1893
+ esc_html_e( 'Installed', 'media-from-ftp' );
1894
+ ?>
1895
+ &
1896
+ <?php
1897
+ if ( $this->is_add_on_activate['exif'] ) {
1898
+ esc_html_e( 'Activated', 'media-from-ftp' );
1899
+ } else {
1900
+ esc_html_e( 'Deactivated', 'media-from-ftp' );
1901
+ }
1902
+ ?>
1903
+ </strong></div>
1904
+ <?php
1905
+ } else {
1906
+ ?>
1907
+ <div>
1908
+ <a href="<?php echo esc_url( __( 'https://shop.riverforest-wp.info/media-from-ftp-add-on-exif/', 'media-from-ftp' ) ); ?>" target="_blank" class="page-title-action"><?php esc_html_e( 'BUY', 'media-from-ftp' ); ?></a>
1909
+ </div>
1910
+ <?php
1911
+ }
1912
+ ?>
1913
+ </div>
1914
+
1915
+ <?php
1916
+ }
1917
+
1918
+ /** ==================================================
1919
+ * Update wp_options table.
1920
+ *
1921
+ * @param int $submenu submenu.
1922
+ * @since 2.36
1923
+ */
1924
+ private function options_updated( $submenu ) {
1925
+
1926
+ $mediafromftp = new MediaFromFtp();
1927
+
1928
+ $mediafromftp_settings = get_option( $this->wp_options_name() );
1929
+
1930
+ $addonwpcron = false;
1931
+ if ( $this->is_add_on_activate['wpcron'] ) {
1932
+ $mediafromftpaddonwpcron = new MediaFromFtpAddOnWpcron();
1933
+ $addonwpcron = true;
1934
+ }
1935
+
1936
+ $allowed_notice_html = array(
1937
+ 'div' => array(
1938
+ 'class' => array(),
1939
+ ),
1940
+ 'ul' => array(),
1941
+ 'li' => array(),
1942
+ );
1943
+
1944
+ switch ( $submenu ) {
1945
+ case 1:
1946
+ if ( isset( $_POST['media_from_ftp_settings'] ) && ! empty( $_POST['media_from_ftp_settings'] ) ) {
1947
+
1948
+ if ( check_admin_referer( 'mff_settings', 'media_from_ftp_settings' ) ) {
1949
+ if ( ! empty( $_POST['mediafromftp_dateset'] ) ) {
1950
+ $mediafromftp_settings['dateset'] = sanitize_text_field( wp_unslash( $_POST['mediafromftp_dateset'] ) );
1951
+ }
1952
+ if ( ! empty( $_POST['mediafromftp_datefixed'] ) ) {
1953
+ $mediafromftp_settings['datefixed'] = sanitize_text_field( wp_unslash( $_POST['mediafromftp_datefixed'] ) );
1954
+ }
1955
+ if ( ! empty( $_POST['mediafromftp_datetimepicker'] ) ) {
1956
+ $mediafromftp_settings['datetimepicker'] = 1;
1957
+ } else {
1958
+ $mediafromftp_settings['datetimepicker'] = false;
1959
+ }
1960
+ if ( ! empty( $_POST['mediafromftp_max_execution_time'] ) ) {
1961
+ $mediafromftp_settings['max_execution_time'] = intval( $_POST['mediafromftp_max_execution_time'] );
1962
+ }
1963
+ if ( ! empty( $_POST['mediafromftp_character_code'] ) ) {
1964
+ $mediafromftp_settings['character_code'] = sanitize_text_field( wp_unslash( $_POST['mediafromftp_character_code'] ) );
1965
+ }
1966
+ if ( ! empty( $_POST['mediafromftp_cron_apply'] ) ) {
1967
+ $mediafromftp_settings['cron']['apply'] = 1;
1968
+ } else {
1969
+ $mediafromftp_settings['cron']['apply'] = false;
1970
+ }
1971
+ if ( ! empty( $_POST['mediafromftp_cron_schedule'] ) ) {
1972
+ $mediafromftp_settings['cron']['schedule'] = sanitize_text_field( wp_unslash( $_POST['mediafromftp_cron_schedule'] ) );
1973
+ }
1974
+ if ( ! empty( $_POST['mediafromftp_cron_limit_number'] ) ) {
1975
+ $mediafromftp_settings['cron']['limit_number'] = intval( $_POST['mediafromftp_cron_limit_number'] );
1976
+ } else {
1977
+ $mediafromftp_settings['cron']['limit_number'] = false;
1978
+ }
1979
+ if ( ! empty( $_POST['mediafromftp_cron_mail_apply'] ) ) {
1980
+ $mediafromftp_settings['cron']['mail_apply'] = 1;
1981
+ } else {
1982
+ $mediafromftp_settings['cron']['mail_apply'] = false;
1983
+ }
1984
+ if ( ! empty( $_POST['mediafromftp_caption_apply'] ) ) {
1985
+ $mediafromftp_settings['caption']['apply'] = 1;
1986
+ } else {
1987
+ $mediafromftp_settings['caption']['apply'] = false;
1988
+ }
1989
+ if ( ! empty( $_POST['mediafromftp_exif_text'] ) ) {
1990
+ $mediafromftp_settings['caption']['exif_text'] = wp_strip_all_tags( wp_unslash( $_POST['mediafromftp_exif_text'] ) );
1991
+ }
1992
+ if ( ! empty( $_POST['mediafromftp_exif_default'] ) ) {
1993
+ $mediafromftp_settings['caption']['exif_text'] = '%title% %credit% %camera% %caption% %created_timestamp% %copyright% %aperture% %shutter_speed% %iso% %focal_length% %white_balance%';
1994
+ }
1995
+ if ( ! empty( $_POST['mediafromftp_apply_log'] ) ) {
1996
+ $mediafromftp_settings['log'] = 1;
1997
+ } else {
1998
+ $mediafromftp_settings['log'] = false;
1999
+ }
2000
+ if ( ! empty( $_POST['mediafromftp_search_limit_number'] ) ) {
2001
+ $search_limit_number = intval( $_POST['mediafromftp_search_limit_number'] );
2002
+ if ( $search_limit_number > 0 ) {
2003
+ $mediafromftp_settings['search_limit_number'] = $search_limit_number;
2004
+ if ( $search_limit_number < 100 ) {
2005
+ $mediafromftp_settings['search_limit_number'] = 100;
2006
+ }
2007
+ } else {
2008
+ $mediafromftp_settings['search_limit_number'] = 100000;
2009
+ }
2010
+ } else {
2011
+ $mediafromftp_settings['search_limit_number'] = 100000;
2012
+ }
2013
+ if ( ! empty( $_POST['mlc_category'] ) ) {
2014
+ $mediafromftp_settings['mlcc'] = implode( ',', array_map( 'sanitize_text_field', wp_unslash( $_POST['mlc_category'] ) ) );
2015
+ } else {
2016
+ $mediafromftp_settings['mlcc'] = null;
2017
+ }
2018
+ if ( ! empty( $_POST['eml_category'] ) ) {
2019
+ $mediafromftp_settings['emlc'] = implode( ',', array_map( 'sanitize_text_field', wp_unslash( $_POST['eml_category'] ) ) );
2020
+ } else {
2021
+ $mediafromftp_settings['emlc'] = null;
2022
+ }
2023
+ if ( ! empty( $_POST['mla_category'] ) ) {
2024
+ $mediafromftp_settings['mlac'] = implode( ',', array_map( 'sanitize_text_field', wp_unslash( $_POST['mla_category'] ) ) );
2025
+ } else {
2026
+ $mediafromftp_settings['mlac'] = null;
2027
+ }
2028
+ if ( ! empty( $_POST['mla_tag'] ) ) {
2029
+ $mediafromftp_settings['mlat'] = implode( ',', array_map( 'sanitize_text_field', wp_unslash( $_POST['mla_tag'] ) ) );
2030
+ } else {
2031
+ $mediafromftp_settings['mlat'] = null;
2032
+ }
2033
+ update_option( $this->wp_options_name(), $mediafromftp_settings );
2034
+ if ( ! empty( $_POST['move_yearmonth_folders'] ) ) {
2035
+ update_option( 'uploads_use_yearmonth_folders', 1 );
2036
+ } else {
2037
+ update_option( 'uploads_use_yearmonth_folders', 0 );
2038
+ }
2039
+ echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html( __( 'Settings' ) . ' --> ' . __( 'Changes saved.' ) ) . '</li></ul></div>';
2040
+ }
2041
+ }
2042
+ break;
2043
+ case 2:
2044
+ if ( isset( $_POST['media_from_ftp_search'] ) && ! empty( $_POST['media_from_ftp_search'] ) ) {
2045
+ if ( check_admin_referer( 'mff_search', 'media_from_ftp_search' ) ) {
2046
+ if ( ! empty( $_POST['mediafromftp_pagemax'] ) ) {
2047
+ $mediafromftp_settings['pagemax'] = intval( $_POST['mediafromftp_pagemax'] );
2048
+ }
2049
+ if ( ! empty( $_POST['searchdir'] ) ) {
2050
+ $searchdir = urldecode( wp_strip_all_tags( wp_unslash( $_POST['searchdir'] ) ) );
2051
+ if ( strpos( realpath( wp_normalize_path( ABSPATH . $searchdir ) ), $this->upload_dir ) === false ) {
2052
+ $searchdir = $this->upload_path;
2053
+ $mediafromftp_settings['basedir'] = $this->upload_path;
2054
+ }
2055
+ $mediafromftp_settings['searchdir'] = $searchdir;
2056
+ } else {
2057
+ if ( $this->upload_path <> $mediafromftp_settings['basedir'] ) {
2058
+ $mediafromftp_settings['searchdir'] = $this->upload_path;
2059
+ $mediafromftp_settings['basedir'] = $this->upload_path;
2060
+ }
2061
+ }
2062
+ if ( ! empty( $_POST['ext2type'] ) ) {
2063
+ $ext2typefilter = sanitize_text_field( wp_unslash( $_POST['ext2type'] ) );
2064
+ } else {
2065
+ $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
2066
+ }
2067
+ if ( ! empty( $_POST['extension'] ) ) {
2068
+ if ( 'all' === $_POST['extension'] ) {
2069
+ $mediafromftp_settings['extfilter'] = 'all';
2070
+ } else {
2071
+ if ( 'all' === $ext2typefilter || wp_ext2type( sanitize_text_field( wp_unslash( $_POST['extension'] ) ) ) === $ext2typefilter ) {
2072
+ $mediafromftp_settings['extfilter'] = sanitize_text_field( wp_unslash( $_POST['extension'] ) );
2073
+ } else {
2074
+ $mediafromftp_settings['extfilter'] = 'all';
2075
+ }
2076
+ }
2077
+ }
2078
+ $mediafromftp_settings['ext2typefilter'] = $ext2typefilter;
2079
+ if ( isset( $_POST['search_display_metadata'] ) ) {
2080
+ $mediafromftp_settings['search_display_metadata'] = sanitize_text_field( wp_unslash( $_POST['search_display_metadata'] ) );
2081
+ }
2082
+ if ( ! empty( $_POST['mediafromftp_exclude'] ) ) {
2083
+ $mediafromftp_settings['exclude'] = sanitize_text_field( wp_unslash( $_POST['mediafromftp_exclude'] ) );
2084
+ }
2085
+ if ( isset( $_POST['mediafromftp_recursive_search'] ) ) {
2086
+ $mediafromftp_settings['recursive_search'] = sanitize_text_field( wp_unslash( $_POST['mediafromftp_recursive_search'] ) );
2087
+ }
2088
+ if ( isset( $_POST['mediafromftp_thumb_deep_search'] ) ) {
2089
+ $mediafromftp_settings['thumb_deep_search'] = sanitize_text_field( wp_unslash( $_POST['mediafromftp_thumb_deep_search'] ) );
2090
+ }
2091
+ update_option( $this->wp_options_name(), $mediafromftp_settings );
2092
+ $screen = get_current_screen();
2093
+ if ( is_object( $screen ) && 'media-from-ftp_page_mediafromftp-settings' === $screen->id ) {
2094
+ echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html( __( 'Settings' ) . ' --> ' . __( 'Changes saved.' ) ) . '</li></ul></div>';
2095
+ }
2096
+ }
2097
+ }
2098
+ break;
2099
+ case 3:
2100
+ if ( isset( $_POST['media_from_ftp_clear_cash'] ) && ! empty( $_POST['media_from_ftp_clear_cash'] ) ) {
2101
+ if ( check_admin_referer( 'mff_clear_cash', 'media_from_ftp_clear_cash' ) ) {
2102
+ if ( ! empty( $_POST['mediafromftp_clear_cash'] ) ) {
2103
+ $del_cash_count = $mediafromftp->delete_all_cash();
2104
+ if ( $del_cash_count > 0 ) {
2105
+ echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html( __( 'Thumbnails Cache', 'media-from-ftp' ) . ' --> ' . __( 'Delete' ) ) . '</li></ul></div>';
2106
+ } else {
2107
+ echo '<div class="notice notice-info is-dismissible"><ul><li>' . esc_html__( 'No Thumbnails Cache', 'media-from-ftp' ) . '</li></ul></div>';
2108
+ }
2109
+ }
2110
+ }
2111
+ }
2112
+ break;
2113
+ case 4:
2114
+ /* for media-from-ftp-add-on-wpcron */
2115
+ if ( isset( $_POST['media_from_ftp_run_cron'] ) && ! empty( $_POST['media_from_ftp_run_cron'] ) ) {
2116
+ if ( check_admin_referer( 'mff_run_cron', 'media_from_ftp_run_cron' ) ) {
2117
+ if ( $addonwpcron ) {
2118
+ if ( ! empty( $_POST['mediafromftp_run_cron'] ) ) {
2119
+ $mediafromftp_cron_events = get_option( $this->wp_add_on_wpcron_events_name() );
2120
+ if ( ! empty( $_POST['cron-run'] ) ) {
2121
+ $option_name = sanitize_text_field( wp_unslash( $_POST['cron-run'] ) );
2122
+ echo wp_kses( $mediafromftpaddonwpcron->CronRun( $option_name ), $allowed_notice_html );
2123
+ } elseif ( ! empty( $_POST['cron-start'] ) ) {
2124
+ $option_name = sanitize_text_field( wp_unslash( $_POST['cron-start'] ) );
2125
+ echo wp_kses( $mediafromftpaddonwpcron->CronRunStart( $option_name ), $allowed_notice_html );
2126
+ } elseif ( ! empty( $_POST['cron-stop'] ) ) {
2127
+ $option_name = sanitize_text_field( wp_unslash( $_POST['cron-stop'] ) );
2128
+ echo wp_kses( $mediafromftpaddonwpcron->CronRunStop( $option_name ), $allowed_notice_html );
2129
+ }
2130
+ }
2131
+ } else {
2132
+ $mediafromftp_settings['cron']['apply'] = false;
2133
+ update_option( $this->wp_options_name(), $mediafromftp_settings );
2134
+ }
2135
+ }
2136
+ }
2137
+ break;
2138
+ case 5:
2139
+ /* for media-from-ftp-add-on-wpcron */
2140
+ if ( isset( $_POST['media_from_ftp_add_schedule'] ) && ! empty( $_POST['media_from_ftp_add_schedule'] ) ) {
2141
+ if ( check_admin_referer( 'mff_add_schedule', 'media_from_ftp_add_schedule' ) ) {
2142
+ if ( ! empty( $_POST['mediafromftp_add_schedule'] ) ) {
2143
+ if ( ! empty( $_POST['mediafromftp_cron_schedule_innername'] ) && ! empty( $_POST['mediafromftp_cron_schedule_secounds'] ) && ! empty( $_POST['mediafromftp_cron_schedule_viewname'] ) ) {
2144
+ $mediafromftp_cron_intervals_tbl = get_option( 'mediafromftp_event_intervals' );
2145
+ $innername = sanitize_text_field( wp_unslash( $_POST['mediafromftp_cron_schedule_innername'] ) );
2146
+ $secounds = intval( $_POST['mediafromftp_cron_schedule_secounds'] );
2147
+ $viewname = sanitize_text_field( wp_unslash( $_POST['mediafromftp_cron_schedule_viewname'] ) );
2148
+ $mediafromftp_cron_intervals_tbl[ $innername ] = array(
2149
+ 'interval' => $secounds,
2150
+ 'display' => $viewname,
2151
+ );
2152
+ update_option( 'mediafromftp_event_intervals', $mediafromftp_cron_intervals_tbl );
2153
+ echo wp_kses( $mediafromftpaddonwpcron->mediafromftp_schedule_notice_html( $submenu ), $allowed_notice_html );
2154
+ }
2155
+ }
2156
+ }
2157
+ }
2158
+ break;
2159
+ case 6:
2160
+ /* for media-from-ftp-add-on-wpcron */
2161
+ if ( isset( $_POST['media_from_ftp_add_schedule_delete'] ) && ! empty( $_POST['media_from_ftp_add_schedule_delete'] ) ) {
2162
+ if ( check_admin_referer( 'mff_add_schedule_delete', 'media_from_ftp_add_schedule_delete' ) ) {
2163
+ if ( ! empty( $_POST['mediafromftp_add_schedule_delete'] ) ) {
2164
+ if ( ! empty( $_POST['mediafromftp_cron_schedule_delete'] ) ) {
2165
+ $delete_keys = array_map( 'sanitize_text_field', wp_unslash( $_POST['mediafromftp_cron_schedule_delete'] ) );
2166
+ $mediafromftp_cron_intervals_tbl = get_option( 'mediafromftp_event_intervals' );
2167
+ foreach ( $delete_keys as $key ) {
2168
+ unset( $mediafromftp_cron_intervals_tbl[ $key ] );
2169
+ }
2170
+ update_option( 'mediafromftp_event_intervals', $mediafromftp_cron_intervals_tbl );
2171
+ echo wp_kses( $mediafromftpaddonwpcron->mediafromftp_schedule_notice_html( $submenu ), $allowed_notice_html );
2172
+ }
2173
+ }
2174
+ }
2175
+ }
2176
+ break;
2177
+ case 7:
2178
+ /* for media-from-ftp-add-on-wpcron */
2179
+ if ( isset( $_POST['media_from_ftp_settings_cron_event_create'] ) && ! empty( $_POST['media_from_ftp_settings_cron_event_create'] ) ) {
2180
+ if ( check_admin_referer( 'mff_settings_cron_event_create', 'media_from_ftp_settings_cron_event_create' ) ) {
2181
+ if ( ! empty( $_POST['mediafromftp_cron_event_create'] ) ) {
2182
+ $event_id = date_i18n( 'Y-m-d-H-i-s' );
2183
+ $event_option_name = 'mediafromftp_cronevent-' . $event_id;
2184
+ $mediafromftp_cron_events = get_option( $this->wp_add_on_wpcron_events_name(), array() );
2185
+ $mediafromftp_cron_events[ $event_id ] = $event_option_name;
2186
+ update_option( $this->wp_add_on_wpcron_events_name(), $mediafromftp_cron_events );
2187
+ update_option( $event_option_name, $mediafromftp_settings );
2188
+ echo wp_kses( $mediafromftpaddonwpcron->mediafromftp_cronevent_create_html(), $allowed_notice_html );
2189
+ }
2190
+ }
2191
+ }
2192
+ break;
2193
+ }
2194
+
2195
+ }
2196
+
2197
+ /** ==================================================
2198
+ * Robots txt
2199
+ *
2200
+ * @param string $output output.
2201
+ * @return string $output output.
2202
+ * @since 9.75
2203
+ */
2204
+ public function custom_robots_txt( $output ) {
2205
+
2206
+ $public = get_option( 'blog_public' );
2207
+ if ( '0' != $public ) {
2208
+ $output .= "\n" . 'Disallow: ' . $this->plugin_disallow_tmp_dir . "\n";
2209
+ }
2210
+
2211
+ return $output;
2212
+
2213
+ }
2214
+
2215
+ /** ==================================================
2216
+ * Notices
2217
+ *
2218
+ * @since 9.84
2219
+ */
2220
+ public function notices() {
2221
+
2222
+ $screen = get_current_screen();
2223
+ if ( is_object( $screen ) && 'media-from-ftp_page_mediafromftp-search-register' === $screen->id ) {
2224
+ $html1 = '<strong>' . __( 'Organize my uploads into month- and year-based folders' ) . '</strong>';
2225
+ $link_url1 = admin_url( 'options-media.php' );
2226
+ $link1 = '<a href="' . $link_url1 . '">' . __( 'Media Settings' ) . '</a>';
2227
+ $link_url2 = admin_url( 'admin.php?page=mediafromftp-settings' );
2228
+ $link2 = '<a href="' . $link_url2 . '">' . __( 'Settings' ) . '</a>';
2229
+ if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
2230
+ /* translators: %1$s: message %2$s: media settings %3$s: settings */
2231
+ echo '<div class="notice notice-warning is-dismissible"><ul><li>' . wp_kses_post( sprintf( __( '"%1$s" is checked. This is the default setting for the WordPress Media Library. In this setting, the file is moved to month- and year-based folders. If you do not want to move, please uncheck.(%2$s,%3$s)', 'media-from-ftp' ), $html1, $link1, $link2 ) ) . '</li></ul></div>';
2232
+ }
2233
+ }
2234
+ if ( $this->is_my_plugin_screen() ) {
2235
+ if ( function_exists( 'extend_media_upload_load_textdomain' ) ) {
2236
+ $html2 = '<strong>Extend Media Upload</strong>';
2237
+ $html3 = '<strong>' . __( 'Update Media' ) . '</strong>';
2238
+ if ( is_multisite() ) {
2239
+ $link_url3 = network_admin_url( 'plugins.php' );
2240
+ } else {
2241
+ $link_url3 = admin_url( 'plugins.php' );
2242
+ }
2243
+ $link3 = '<strong><a href="' . $link_url3 . '">' . __( 'Plugins' ) . '</a></strong>';
2244
+ /* translators: %1$s: plugin %2$s: message %3$s: plugin menu */
2245
+ echo '<div class="notice notice-error is-dismissible"><ul><li>' . wp_kses_post( sprintf( __( '"%1$s" is activate. When "%2$s", it will be overwritten with "%1$s" setting. Please deactivate.(%3$s)', 'media-from-ftp' ), $html2, $html3, $link3 ) ) . '</li></ul></div>';
2246
+ }
2247
+ }
2248
+
2249
+ }
2250
+
2251
+ /** ==================================================
2252
+ * Options name
2253
+ *
2254
+ * @return string $this->wp_options_name()
2255
+ * @since 10.09
2256
+ */
2257
+ private function wp_options_name() {
2258
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
2259
+ include_once( ABSPATH . 'wp-includes/pluggable.php' );
2260
+ }
2261
+ return 'mediafromftp_settings_' . get_current_user_id();
2262
+ }
2263
+
2264
+ /** ==================================================
2265
+ * Add on
2266
+ *
2267
+ * @return string $this->wp_add_on_wpcron_events_name()
2268
+ * @since 10.09
2269
+ */
2270
+ private function wp_add_on_wpcron_events_name() {
2271
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
2272
+ include_once( ABSPATH . 'wp-includes/pluggable.php' );
2273
+ }
2274
+ return 'mediafromftp_add_on_wpcron_events_' . get_current_user_id();
2275
+ }
2276
+
2277
+ }
2278
+
2279
+
req/class-mediafromftpajax.php ADDED
@@ -0,0 +1,443 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media from FTP
4
+ *
5
+ * @package Media from FTP
6
+ * @subpackage MediafromFtpAjax
7
+ /*
8
+ Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
9
+ This program is free software; you can redistribute it and/or modify
10
+ it under the terms of the GNU General Public License as published by
11
+ the Free Software Foundation; version 2 of the License.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program; if not, write to the Free Software
20
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ $mediafromftpajax = new MediaFromFtpAjax();
24
+
25
+ /** ==================================================
26
+ * Register Ajax
27
+ */
28
+ class MediaFromFtpAjax {
29
+
30
+ /** ==================================================
31
+ * Path
32
+ *
33
+ * @var $upload_dir upload_dir.
34
+ */
35
+ private $upload_dir;
36
+
37
+ /** ==================================================
38
+ * Path
39
+ *
40
+ * @var $upload_url $upload_url.
41
+ */
42
+ private $upload_url;
43
+
44
+ /** ==================================================
45
+ * Add on bool
46
+ *
47
+ * @var $is_add_on_activate is_add_on_activate.
48
+ */
49
+ private $is_add_on_activate;
50
+
51
+ /** ==================================================
52
+ * Construct
53
+ *
54
+ * @since 9.81
55
+ */
56
+ public function __construct() {
57
+
58
+ $plugin_base_dir = untrailingslashit( plugin_dir_path( __DIR__ ) );
59
+ $slugs = explode( '/', $plugin_base_dir );
60
+ $slug = end( $slugs );
61
+ $plugin_dir = untrailingslashit( rtrim( $plugin_base_dir, $slug ) );
62
+
63
+ if ( ! class_exists( 'MediaFromFtp' ) ) {
64
+ include_once $plugin_base_dir . '/inc/class-mediafromftp.php';
65
+ }
66
+ $mediafromftp = new MediaFromFtp();
67
+ list($this->upload_dir, $this->upload_url, $upload_path) = $mediafromftp->upload_dir_url_path();
68
+
69
+ $category_active = false;
70
+ if ( function_exists( 'media_from_ftp_add_on_category_load_textdomain' ) ) {
71
+ include_once $plugin_dir . '/media-from-ftp-add-on-category/inc/MediaFromFtpAddOnCategory.php';
72
+ $category_active = true;
73
+ }
74
+
75
+ $this->is_add_on_activate = array(
76
+ 'category' => $category_active,
77
+ );
78
+
79
+ $action1 = 'mediafromftp-update-ajax-action';
80
+ $action3 = 'mediafromftp_message';
81
+ $action2 = 'mediafromftp-import-ajax-action';
82
+ $action4 = 'mediafromftp_medialibraryimport_message';
83
+ add_action( 'wp_ajax_' . $action1, array( $this, 'mediafromftp_update_callback' ) );
84
+ add_action( 'wp_ajax_' . $action3, array( $this, 'mediafromftp_message_callback' ) );
85
+ add_action( 'wp_ajax_' . $action2, array( $this, 'mediafromftp_medialibraryimport_update_callback' ) );
86
+ add_action( 'wp_ajax_' . $action4, array( $this, 'mediafromftp_medialibraryimport_message_callback' ) );
87
+
88
+ }
89
+
90
+ /** ==================================================
91
+ * Update Files Callback
92
+ *
93
+ * @since 9.30
94
+ */
95
+ public function mediafromftp_update_callback() {
96
+
97
+ $action1 = 'mediafromftp-update-ajax-action';
98
+ if ( check_ajax_referer( $action1, 'nonce', false ) ) {
99
+ if ( current_user_can( 'upload_files' ) ) {
100
+ $maxcount = 0;
101
+ $new_url_attach = null;
102
+ $new_url_datetime = null;
103
+ if ( ! empty( $_POST['maxcount'] ) ) {
104
+ $maxcount = intval( $_POST['maxcount'] );
105
+ }
106
+
107
+ $mediafromftp_settings = get_option( $this->wp_options_name() );
108
+ $mediafromftp = new MediaFromFtp();
109
+
110
+ if ( ! empty( $_POST['new_url'] ) ) {
111
+ $filename = sanitize_text_field( wp_unslash( $_POST['new_url'] ) );
112
+ $upload_path = wp_normalize_path( $this->upload_dir );
113
+ $new_url_attach = $this->upload_url . str_replace( $upload_path, '', $filename );
114
+ $new_url_attach = $mediafromftp->mb_utf8( $new_url_attach, $mediafromftp_settings['character_code'] );
115
+ }
116
+ if ( ! empty( $_POST['new_datetime'] ) ) {
117
+ $new_url_datetime = sanitize_text_field( wp_unslash( $_POST['new_datetime'] ) );
118
+ }
119
+
120
+ $new_url_mlccategory = null;
121
+ $new_url_emlcategory = null;
122
+ $new_url_mlacategory = null;
123
+ $new_url_mlatags = null;
124
+ if ( $this->is_add_on_activate['category'] ) {
125
+ if ( ! empty( $_POST['new_mlccategory'] ) ) {
126
+ $new_url_mlccategory = sanitize_text_field( wp_unslash( $_POST['new_mlccategory'] ) );
127
+ }
128
+ if ( ! empty( $_POST['new_emlcategory'] ) ) {
129
+ $new_url_emlcategory = sanitize_text_field( wp_unslash( $_POST['new_emlcategory'] ) );
130
+ }
131
+ if ( ! empty( $_POST['new_mlacategory'] ) ) {
132
+ $new_url_mlacategory = sanitize_text_field( wp_unslash( $_POST['new_mlacategory'] ) );
133
+ }
134
+ if ( ! empty( $_POST['new_mlatags'] ) ) {
135
+ $new_url_mlatags = sanitize_text_field( wp_unslash( $_POST['new_mlatags'] ) );
136
+ }
137
+ }
138
+
139
+ if ( ! empty( $new_url_attach ) ) {
140
+
141
+ $dateset = $mediafromftp_settings['dateset'];
142
+ $datefixed = $mediafromftp_settings['datefixed'];
143
+ $yearmonth_folders = get_option( 'uploads_use_yearmonth_folders' );
144
+ $exif_text_tag = null;
145
+ if ( $mediafromftp_settings['caption']['apply'] ) {
146
+ $exif_text_tag = $mediafromftp_settings['caption']['exif_text'];
147
+ }
148
+
149
+ $exts = explode( '.', wp_basename( $new_url_attach ) );
150
+ $ext = end( $exts );
151
+
152
+ /* Delete Cash */
153
+ $mediafromftp->delete_cash( $ext, $new_url_attach );
154
+
155
+ /* Regist */
156
+ list($attach_id, $new_attach_title, $new_url_attach, $metadata) = $mediafromftp->regist( $filename, $ext, $new_url_attach, $new_url_datetime, $dateset, $datefixed, $yearmonth_folders, $mediafromftp_settings['character_code'], $mediafromftp_settings['cron']['user'] );
157
+
158
+ $cat_html = null;
159
+ $mlccategory = null;
160
+ $emlcategory = null;
161
+ $mlacategory = null;
162
+ $mlatag = null;
163
+ if ( $this->is_add_on_activate['category'] ) {
164
+ $mediafromftpaddoncategory = new MediaFromFtpAddOnCategory();
165
+ 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 );
166
+ unset( $mediafromftpaddoncategory );
167
+ }
168
+
169
+ if ( -1 == $attach_id || -2 == $attach_id ) { /* error */
170
+ $error_title = $mediafromftp->mb_utf8( $new_attach_title, $mediafromftp_settings['character_code'] );
171
+ $error_url = $mediafromftp->mb_utf8( $new_url_attach, $mediafromftp_settings['character_code'] );
172
+ if ( -1 == $attach_id ) {
173
+ /* translators: error message */
174
+ echo '<div class="notice notice-error is-dismissible"><ul><li><div>' . wp_kses_post( __( '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>';
175
+ } elseif ( -2 == $attach_id ) {
176
+ echo '<div class="notice notice-error is-dismissible"><ul><li><div>' . wp_kses_post( __( '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>';
177
+ }
178
+ } else {
179
+ /* Outputdata */
180
+ list($imagethumburls, $mimetype, $length, $stamptime, $file_size, $exif_text) = $mediafromftp->output_metadata( $ext, $attach_id, $metadata, $mediafromftp_settings['character_code'], $exif_text_tag );
181
+
182
+ $image_attr_thumbnail = wp_get_attachment_image_src( $attach_id, 'thumbnail', true );
183
+
184
+ $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 );
185
+
186
+ header( 'Content-type: text/html; charset=UTF-8' );
187
+ $allowed_output_html = array(
188
+ 'a' => array(
189
+ 'href' => array(),
190
+ 'target' => array(),
191
+ 'style' => array(),
192
+ ),
193
+ 'img' => array(
194
+ 'src' => array(),
195
+ 'width' => array(),
196
+ 'height' => array(),
197
+ 'style' => array(),
198
+ ),
199
+ 'div' => array(
200
+ 'style' => array(),
201
+ 'class' => array(),
202
+ ),
203
+ 'font' => array(
204
+ 'color' => array(),
205
+ ),
206
+ 'ul' => array(),
207
+ 'li' => array(),
208
+ 'span' => array(
209
+ 'class' => array(),
210
+ ),
211
+ );
212
+ echo wp_kses( $output_html, $allowed_output_html );
213
+
214
+ }
215
+ unset( $mediafromftp );
216
+
217
+ }
218
+ }
219
+ } else {
220
+ status_header( '403' );
221
+ echo 'Forbidden';
222
+ }
223
+
224
+ wp_die();
225
+
226
+ }
227
+
228
+ /** ==================================================
229
+ * Update Messages Callback
230
+ *
231
+ * @since 9.30
232
+ */
233
+ public function mediafromftp_message_callback() {
234
+
235
+ $action3 = 'mediafromftp_message';
236
+ if ( check_ajax_referer( $action3, 'nonce', false ) ) {
237
+ $error_count = 0;
238
+ $error_update = null;
239
+ $success_count = 0;
240
+ if ( ! empty( $_POST['error_count'] ) ) {
241
+ $error_count = intval( $_POST['error_count'] );
242
+ }
243
+ if ( ! empty( $_POST['error_update'] ) ) {
244
+ $error_update = sanitize_text_field( wp_unslash( $_POST['error_update'] ) );
245
+ }
246
+ if ( ! empty( $_POST['success_count'] ) ) {
247
+ $success_count = intval( $_POST['success_count'] );
248
+ }
249
+
250
+ $output_html = null;
251
+ if ( $error_count > 0 ) {
252
+ /* translators: error message */
253
+ $error_message = sprintf( __( 'Errored to the registration of %1$d files.', 'media-from-ftp' ), $error_count );
254
+ $output_html .= '<div class="notice notice-error is-dismissible"><ul><li><div>' . $error_message . '</div>' . $error_update . '</li></ul></div>';
255
+ }
256
+ /* translators: success message */
257
+ $success_message = sprintf( __( 'Succeeded to the registration of %1$d files.', 'media-from-ftp' ), $success_count );
258
+ $output_html .= '<div class="notice notice-success is-dismissible"><ul><li><div>' . $success_message . '</li></ul></div>';
259
+
260
+ header( 'Content-type: text/html; charset=UTF-8' );
261
+ $allowed_output_html = array(
262
+ 'div' => array(
263
+ 'class' => array(),
264
+ ),
265
+ 'ul' => array(),
266
+ 'li' => array(),
267
+ );
268
+ echo wp_kses( $output_html, $allowed_output_html );
269
+ }
270
+
271
+ wp_die();
272
+
273
+ }
274
+
275
+ /** ==================================================
276
+ * Import Files Callback
277
+ *
278
+ * @since 9.40
279
+ */
280
+ public function mediafromftp_medialibraryimport_update_callback() {
281
+
282
+ $action2 = 'mediafromftp-import-ajax-action';
283
+ if ( check_ajax_referer( $action2, 'nonce', false ) ) {
284
+ if ( current_user_can( 'upload_files' ) ) {
285
+ if ( ! empty( $_POST['file'] ) ) {
286
+ $file = sanitize_text_field( wp_unslash( $_POST['file'] ) );
287
+ } else {
288
+ return;
289
+ }
290
+ $filepath = str_replace( $this->upload_dir . '/', '', $file );
291
+ if ( is_file( $file ) ) {
292
+ if ( ! empty( $_POST['db_array'] ) ) {
293
+ $db_array = filter_var(
294
+ wp_unslash( $_POST['db_array'] ),
295
+ FILTER_CALLBACK,
296
+ [
297
+ 'options' => function( $value ) {
298
+ return sanitize_text_field( $value );
299
+ },
300
+ ]
301
+ );
302
+ $db_id = intval( $db_array['ID'] );
303
+ global $wpdb;
304
+ $table_name = $wpdb->prefix . 'posts';
305
+ $wpdb->insert( $table_name, $db_array );
306
+ update_attached_file( $db_id, $filepath );
307
+ if ( ! empty( $_POST['db_wp_attachment_metadata'] ) ) {
308
+ $metadata_json = sanitize_text_field( wp_unslash( $_POST['db_wp_attachment_metadata'] ) );
309
+ $metadata = json_decode( $metadata_json );
310
+ $table_meta_name = $wpdb->prefix . 'postmeta';
311
+ $db_meta_array = array(
312
+ 'post_id' => $db_id,
313
+ 'meta_key' => '_wp_attachment_metadata',
314
+ 'meta_value' => $metadata,
315
+ );
316
+ $wpdb->insert( $table_meta_name, $db_meta_array );
317
+ }
318
+ if ( ! empty( $_POST['db_thumbnail_id'] ) ) {
319
+ update_post_meta( $db_id, '_thumbnail_id', intval( $_POST['db_thumbnail_id'] ) );
320
+ }
321
+ if ( ! empty( $_POST['db_cover_hash'] ) ) {
322
+ update_post_meta( $db_id, '_cover_hash', sanitize_text_field( wp_unslash( $_POST['db_cover_hash'] ) ) );
323
+ }
324
+ if ( ! empty( $_POST['db_wp_attachment_image_alt'] ) ) {
325
+ update_post_meta( $db_id, '_wp_attachment_image_alt', sanitize_text_field( wp_unslash( $_POST['db_wp_attachment_image_alt'] ) ) );
326
+ }
327
+ $msg = 'success_db';
328
+ $output_html = $msg . ',<div>' . __( 'Media' ) . ': <a href="' . get_permalink( $db_id ) . '" target="_blank" style="text-decoration: none; color: green;">' . $this->esc_title( $db_array['post_title'] ) . '</a>: <a href="' . $this->upload_url . '/' . $filepath . '" target="_blank" style="text-decoration: none;">' . $filepath . '</a></div>';
329
+ } else {
330
+ $msg = 'success';
331
+ $output_html = $msg . ',<div>' . __( 'Thumbnail' ) . ': <a href="' . $this->upload_url . '/' . $filepath . '" target="_blank" style="text-decoration: none;">' . $filepath . '</a></div>';
332
+ }
333
+ } else {
334
+ $error_string = __( 'No file!', 'media-from-ftp' );
335
+ $msg = '<div>' . $filepath . ': ' . $error_string . '</div>';
336
+ $output_html = $msg . ',<div>' . $filepath . '<span style="color: red;"> &#8811; ' . $error_string . '</span></div>';
337
+ }
338
+
339
+ header( 'Content-type: text/html; charset=UTF-8' );
340
+ $allowed_output_html = array(
341
+ 'a' => array(
342
+ 'href' => array(),
343
+ 'target' => array(),
344
+ 'style' => array(),
345
+ ),
346
+ 'div' => array(),
347
+ 'span' => array(
348
+ 'class' => array(),
349
+ ),
350
+ );
351
+ echo wp_kses( $output_html, $allowed_output_html );
352
+ }
353
+ } else {
354
+ status_header( '403' );
355
+ echo 'Forbidden';
356
+ }
357
+
358
+ wp_die();
359
+
360
+ }
361
+
362
+ /** ==================================================
363
+ * Import Messages Callback
364
+ *
365
+ * @since 9.40
366
+ */
367
+ public function mediafromftp_medialibraryimport_message_callback() {
368
+
369
+ $action4 = 'mediafromftp_medialibraryimport_message';
370
+ if ( check_ajax_referer( $action4, 'nonce', false ) ) {
371
+ $error_count = 0;
372
+ $error_update = null;
373
+ $success_count = 0;
374
+ $db_success_count = 0;
375
+ if ( ! empty( $_POST['error_count'] ) ) {
376
+ $error_count = intval( $_POST['error_count'] );
377
+ }
378
+ if ( ! empty( $_POST['error_update'] ) ) {
379
+ $error_update = sanitize_text_field( wp_unslash( $_POST['error_update'] ) );
380
+ }
381
+ if ( ! empty( $_POST['success_count'] ) ) {
382
+ $success_count = intval( $_POST['success_count'] );
383
+ }
384
+ if ( ! empty( $_POST['db_success_count'] ) ) {
385
+ $db_success_count = intval( $_POST['db_success_count'] );
386
+ }
387
+
388
+ $output_html = null;
389
+ if ( $error_count > 0 ) {
390
+ /* translators: error message */
391
+ $error_message = sprintf( __( 'Errored to the registration of %1$d files.', 'media-from-ftp' ), $error_count );
392
+ $output_html .= '<div class="notice notice-error is-dismissible"><ul><li><div>' . $error_message . '</div>' . $error_update . '</li></ul></div>';
393
+ }
394
+ /* translators: success message */
395
+ $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 );
396
+ $output_html .= '<div class="notice notice-success is-dismissible"><ul><li><div>' . $success_message . '</li></ul></div>';
397
+
398
+ header( 'Content-type: text/html; charset=UTF-8' );
399
+ $allowed_output_html = array(
400
+ 'div' => array(
401
+ 'class' => array(),
402
+ ),
403
+ 'ul' => array(),
404
+ 'li' => array(),
405
+ );
406
+ echo wp_kses( $output_html, $allowed_output_html );
407
+ }
408
+
409
+ wp_die();
410
+
411
+ }
412
+
413
+ /** ==================================================
414
+ * Escape Title
415
+ *
416
+ * @param string $str str.
417
+ * @return string $str
418
+ * @since 9.41
419
+ */
420
+ private function esc_title( $str ) {
421
+
422
+ $str = esc_html( $str );
423
+ $str = str_replace( ',', '&#44;', $str );
424
+
425
+ return $str;
426
+ }
427
+
428
+ /** ==================================================
429
+ * Options name
430
+ *
431
+ * @return string $this->wp_options_name()
432
+ * @since 10.09
433
+ */
434
+ private function wp_options_name() {
435
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
436
+ include_once( ABSPATH . 'wp-includes/pluggable.php' );
437
+ }
438
+ return 'mediafromftp_settings_' . get_current_user_id();
439
+ }
440
+
441
+ }
442
+
443
+
req/class-mediafromftpregist.php ADDED
@@ -0,0 +1,456 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Media from FTP
4
+ *
5
+ * @package Media from FTP
6
+ * @subpackage MediaFromFtpRegist registered in the database
7
+ /*
8
+ Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
9
+ This program is free software; you can redistribute it and/or modify
10
+ it under the terms of the GNU General Public License as published by
11
+ the Free Software Foundation; version 2 of the License.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program; if not, write to the Free Software
20
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ $mediafromftpregist = new MediaFromFtpRegist();
24
+
25
+ /** ==================================================
26
+ * Register Database
27
+ */
28
+ class MediaFromFtpRegist {
29
+
30
+ /** ==================================================
31
+ * Path
32
+ *
33
+ * @var $upload_path upload_path.
34
+ */
35
+ private $upload_path;
36
+
37
+ /** ==================================================
38
+ * Construct
39
+ *
40
+ * @since 9.81
41
+ */
42
+ public function __construct() {
43
+
44
+ $plugin_base_dir = untrailingslashit( plugin_dir_path( __DIR__ ) );
45
+
46
+ if ( ! class_exists( 'MediaFromFtp' ) ) {
47
+ include_once $plugin_base_dir . '/inc/class-mediafromftp.php';
48
+ }
49
+ $mediafromftp = new MediaFromFtp();
50
+ list($upload_dir, $upload_url, $this->upload_path) = $mediafromftp->upload_dir_url_path();
51
+ $plugin_tmp_dir = $upload_dir . '/media-from-ftp-tmp';
52
+ /* Make tmp dir */
53
+ if ( ! is_dir( $plugin_tmp_dir ) ) {
54
+ wp_mkdir_p( $plugin_tmp_dir );
55
+ }
56
+
57
+ register_activation_hook( $plugin_base_dir . '/mediafromftp.php', array( $this, 'log_settings' ) );
58
+ add_action( 'admin_init', array( $this, 'register_settings' ) );
59
+
60
+ }
61
+
62
+ /** ==================================================
63
+ * Settings Log Settings
64
+ *
65
+ * @since 10.05
66
+ */
67
+ public function log_settings() {
68
+
69
+ if ( ! is_multisite() ) {
70
+ $this->log_write();
71
+ } else { /* For Multisite */
72
+ global $wpdb;
73
+ $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
74
+ $original_blog_id = get_current_blog_id();
75
+ foreach ( $blog_ids as $blog_id ) {
76
+ switch_to_blog( $blog_id );
77
+ $this->log_write();
78
+ }
79
+ switch_to_blog( $original_blog_id );
80
+ }
81
+
82
+ }
83
+
84
+ /** ==================================================
85
+ * Settings Log Write
86
+ *
87
+ * @since 9.19
88
+ */
89
+ private function log_write() {
90
+
91
+ $mediafromftp_log_db_version = '3.0';
92
+ $installed_ver = get_option( 'mediafromftp_log_version' );
93
+
94
+ if ( $installed_ver != $mediafromftp_log_db_version ) {
95
+ global $wpdb;
96
+ $wpdb->log_name = $wpdb->prefix . 'mediafromftp_log';
97
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
98
+ if ( ! $installed_ver ) {
99
+ /* from version 9.57 */
100
+ $sql = 'CREATE TABLE ' . $wpdb->log_name . " (
101
+ meta_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
102
+ id bigint(20),
103
+ user text,
104
+ title text,
105
+ permalink text,
106
+ url text,
107
+ filename text,
108
+ time datetime,
109
+ filetype text,
110
+ filesize text,
111
+ exif text,
112
+ length text,
113
+ thumbnail longtext,
114
+ mlccategories longtext,
115
+ emlcategories longtext,
116
+ mlacategories longtext,
117
+ mlatags longtext,
118
+ UNIQUE KEY meta_id (meta_id)
119
+ )
120
+ CHARACTER SET 'utf8';";
121
+ dbDelta( $sql );
122
+ } else {
123
+ $table_search = $wpdb->get_row( "SHOW TABLES FROM DB_NAME LIKE $wpdb->log_name" );
124
+ if ( 1 == $wpdb->num_rows ) { /* db_version 1.0, 2.0 */
125
+ $records = $wpdb->get_results( "SELECT * FROM $wpdb->log_name" );
126
+ $wpdb->query( "DELETE FROM $wpdb->log_name" );
127
+
128
+ $wpdb->query( "ALTER TABLE $wpdb->log_name DROP thumbnail1, DROP thumbnail2, DROP thumbnail3, DROP thumbnail4, DROP thumbnail5, DROP thumbnail6" );
129
+ $wpdb->query( "ALTER TABLE $wpdb->log_name ADD thumbnail longtext" );
130
+ $wpdb->query( "ALTER TABLE $wpdb->log_name ADD mlccategories longtext" );
131
+ $wpdb->query( "ALTER TABLE $wpdb->log_name ADD emlcategories longtext" );
132
+ $wpdb->query( "ALTER TABLE $wpdb->log_name ADD mlacategories longtext" );
133
+ $wpdb->query( "ALTER TABLE $wpdb->log_name ADD mlatags longtext" );
134
+
135
+ foreach ( $records as $record ) {
136
+ $thumbnail = null;
137
+ $thumbnails = array();
138
+ if ( ! empty( $record->thumbnail1 ) ) {
139
+ $thumbnails[0] = $record->thumbnail1; }
140
+ if ( ! empty( $record->thumbnail2 ) ) {
141
+ $thumbnails[1] = $record->thumbnail2; }
142
+ if ( ! empty( $record->thumbnail3 ) ) {
143
+ $thumbnails[2] = $record->thumbnail3; }
144
+ if ( ! empty( $record->thumbnail4 ) ) {
145
+ $thumbnails[3] = $record->thumbnail4; }
146
+ if ( ! empty( $record->thumbnail5 ) ) {
147
+ $thumbnails[4] = $record->thumbnail5; }
148
+ if ( ! empty( $record->thumbnail6 ) ) {
149
+ $thumbnails[5] = $record->thumbnail6; }
150
+ if ( ! empty( $thumbnails ) ) {
151
+ $thumbnail = json_encode( $thumbnails );
152
+ $thumbnail = str_replace( '\\', '', $thumbnail );
153
+ } else {
154
+ $thumbnail = $record->thumbnail;
155
+ }
156
+
157
+ $log_arr = array(
158
+ 'id' => $record->id,
159
+ 'user' => $record->user,
160
+ 'title' => $record->title,
161
+ 'permalink' => $record->permalink,
162
+ 'url' => $record->url,
163
+ 'filename' => $record->filename,
164
+ 'time' => $record->time,
165
+ 'filetype' => $record->filetype,
166
+ 'filesize' => $record->filesize,
167
+ 'exif' => $record->exif,
168
+ 'length' => $record->length,
169
+ 'thumbnail' => $thumbnail,
170
+ 'mlccategories' => null,
171
+ 'emlcategories' => null,
172
+ 'mlacategories' => null,
173
+ 'mlatags' => null,
174
+ );
175
+ $wpdb->insert( $wpdb->log_name, $log_arr );
176
+ $wpdb->show_errors();
177
+ }
178
+ }
179
+ }
180
+ update_option( 'mediafromftp_log_version', $mediafromftp_log_db_version );
181
+ }
182
+
183
+ }
184
+
185
+ /** ==================================================
186
+ * Settings register
187
+ *
188
+ * @since 2.3
189
+ */
190
+ public function register_settings() {
191
+
192
+ $user = wp_get_current_user();
193
+ $cron_mail = $user->user_email;
194
+ $cron_user = $user->ID;
195
+
196
+ $wp_options_name = 'mediafromftp_settings_' . $cron_user;
197
+ $wp_cron_events_name = 'mediafromftp_add_on_wpcron_events_' . $cron_user;
198
+
199
+ $pagemax = 20;
200
+ $basedir = $this->upload_path;
201
+ $searchdir = $this->upload_path;
202
+ $ext2typefilter = 'all';
203
+ $extfilter = 'all';
204
+ $search_display_metadata = true;
205
+ $dateset = 'new';
206
+ $datefixed = date_i18n( 'Y-m-d H:i' );
207
+ $datetimepicker = 1;
208
+ $max_execution_time = 300;
209
+ if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' && get_locale() === 'ja' ) { /* Japanese Windows */
210
+ $character_code = 'CP932';
211
+ } else {
212
+ $character_code = 'UTF-8';
213
+ }
214
+ $exclude = '(.ktai.)|(.backwpup_log.)|(.ps_auto_sitemap.)|\.php|\.js|(.wpcf7_captcha.)|\.htaccess|(.woocommerce_uploads.)|(.wc-logs.)';
215
+ $recursive_search = true;
216
+ $thumb_deep_search = false;
217
+ $search_limit_number = 100000;
218
+ $cron_apply = false;
219
+ $cron_schedule = 'hourly';
220
+ $cron_limit_number = false;
221
+ $cron_mail_apply = true;
222
+
223
+ $caption_apply = false;
224
+ $exif_text = '%title% %credit% %camera% %caption% %created_timestamp% %copyright% %aperture% %shutter_speed% %iso% %focal_length% %white_balance%';
225
+ $log = false;
226
+
227
+ /* for media-from-ftp-add-on-category */
228
+ $mlcc = null;
229
+ $emlc = null;
230
+ $mlac = null;
231
+ $mlat = null;
232
+
233
+ /* for media-from-ftp-add-on-wpcron */
234
+ if ( ! get_option( 'mediafromftp_event_intervals' ) ) {
235
+ update_option( 'mediafromftp_event_intervals', array() );
236
+ }
237
+ if ( ! get_option( $wp_cron_events_name ) ) {
238
+ update_option( $wp_cron_events_name, array() );
239
+ }
240
+
241
+ /* << version 2.35 */
242
+ if ( get_option( 'mediafromftp_exclude_file' ) ) {
243
+ $exclude = get_option( 'mediafromftp_exclude_file' );
244
+ delete_option( 'mediafromftp_exclude_file' );
245
+ }
246
+
247
+ if ( ! get_option( $wp_options_name ) ) {
248
+ if ( get_option( 'mediafromftp_settings' ) ) { /* old settings */
249
+ $mediafromftp_settings = get_option( 'mediafromftp_settings' );
250
+ if ( array_key_exists( 'pagemax', $mediafromftp_settings ) ) {
251
+ $pagemax = $mediafromftp_settings['pagemax'];
252
+ }
253
+ if ( array_key_exists( 'basedir', $mediafromftp_settings ) ) {
254
+ $basedir = $mediafromftp_settings['basedir'];
255
+ }
256
+ if ( array_key_exists( 'searchdir', $mediafromftp_settings ) ) {
257
+ $searchdir = $mediafromftp_settings['searchdir'];
258
+ }
259
+ if ( array_key_exists( 'ext2typefilter', $mediafromftp_settings ) ) {
260
+ $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
261
+ }
262
+ if ( array_key_exists( 'extfilter', $mediafromftp_settings ) ) {
263
+ $extfilter = $mediafromftp_settings['extfilter'];
264
+ }
265
+ if ( array_key_exists( 'search_display_metadata', $mediafromftp_settings ) ) {
266
+ $search_display_metadata = $mediafromftp_settings['search_display_metadata'];
267
+ }
268
+ if ( array_key_exists( 'dateset', $mediafromftp_settings ) ) {
269
+ $dateset = $mediafromftp_settings['dateset'];
270
+ }
271
+ if ( array_key_exists( 'datefixed', $mediafromftp_settings ) ) {
272
+ $datefixed = $mediafromftp_settings['datefixed'];
273
+ }
274
+ if ( array_key_exists( 'datetimepicker', $mediafromftp_settings ) ) {
275
+ $datetimepicker = $mediafromftp_settings['datetimepicker'];
276
+ }
277
+ if ( array_key_exists( 'max_execution_time', $mediafromftp_settings ) ) {
278
+ $max_execution_time = $mediafromftp_settings['max_execution_time'];
279
+ }
280
+ if ( array_key_exists( 'character_code', $mediafromftp_settings ) ) {
281
+ $character_code = $mediafromftp_settings['character_code'];
282
+ }
283
+ if ( array_key_exists( 'exclude', $mediafromftp_settings ) ) {
284
+ $exclude = $mediafromftp_settings['exclude'];
285
+ }
286
+ if ( array_key_exists( 'recursive_search', $mediafromftp_settings ) ) {
287
+ $recursive_search = $mediafromftp_settings['recursive_search'];
288
+ }
289
+ if ( array_key_exists( 'thumb_deep_search', $mediafromftp_settings ) ) {
290
+ $thumb_deep_search = $mediafromftp_settings['thumb_deep_search'];
291
+ }
292
+ if ( array_key_exists( 'search_limit_number', $mediafromftp_settings ) ) {
293
+ $search_limit_number = $mediafromftp_settings['search_limit_number'];
294
+ }
295
+ if ( array_key_exists( 'apply', $mediafromftp_settings['cron'] ) ) {
296
+ $cron_apply = $mediafromftp_settings['cron']['apply'];
297
+ }
298
+ if ( array_key_exists( 'schedule', $mediafromftp_settings['cron'] ) ) {
299
+ $cron_schedule = $mediafromftp_settings['cron']['schedule'];
300
+ }
301
+ if ( array_key_exists( 'limit_number', $mediafromftp_settings['cron'] ) ) {
302
+ $cron_limit_number = $mediafromftp_settings['cron']['limit_number'];
303
+ }
304
+ if ( array_key_exists( 'mail_apply', $mediafromftp_settings['cron'] ) ) {
305
+ $cron_mail_apply = $mediafromftp_settings['cron']['mail_apply'];
306
+ }
307
+ if ( array_key_exists( 'apply', $mediafromftp_settings['caption'] ) ) {
308
+ $caption_apply = $mediafromftp_settings['caption']['apply'];
309
+ }
310
+ if ( array_key_exists( 'exif_text', $mediafromftp_settings['caption'] ) ) {
311
+ $exif_text = $mediafromftp_settings['caption']['exif_text'];
312
+ }
313
+ if ( array_key_exists( 'log', $mediafromftp_settings ) ) {
314
+ $log = $mediafromftp_settings['log'];
315
+ }
316
+
317
+ /* for media-from-ftp-add-on-category */
318
+ if ( array_key_exists( 'mlcc', $mediafromftp_settings ) ) {
319
+ $mlcc = $mediafromftp_settings['mlcc'];
320
+ }
321
+ if ( array_key_exists( 'emlc', $mediafromftp_settings ) ) {
322
+ $emlc = $mediafromftp_settings['emlc'];
323
+ }
324
+ if ( array_key_exists( 'mlac', $mediafromftp_settings ) ) {
325
+ $mlac = $mediafromftp_settings['mlac'];
326
+ }
327
+ if ( array_key_exists( 'mlat', $mediafromftp_settings ) ) {
328
+ $mlat = $mediafromftp_settings['mlat'];
329
+ }
330
+
331
+ delete_option( 'mediafromftp_settings' );
332
+ }
333
+ } else {
334
+ $mediafromftp_settings = get_option( $wp_options_name );
335
+ if ( array_key_exists( 'pagemax', $mediafromftp_settings ) ) {
336
+ $pagemax = $mediafromftp_settings['pagemax'];
337
+ }
338
+ if ( array_key_exists( 'basedir', $mediafromftp_settings ) ) {
339
+ $basedir = $mediafromftp_settings['basedir'];
340
+ }
341
+ if ( array_key_exists( 'searchdir', $mediafromftp_settings ) ) {
342
+ $searchdir = $mediafromftp_settings['searchdir'];
343
+ }
344
+ if ( array_key_exists( 'ext2typefilter', $mediafromftp_settings ) ) {
345
+ $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
346
+ }
347
+ if ( array_key_exists( 'extfilter', $mediafromftp_settings ) ) {
348
+ $extfilter = $mediafromftp_settings['extfilter'];
349
+ }
350
+ if ( array_key_exists( 'search_display_metadata', $mediafromftp_settings ) ) {
351
+ $search_display_metadata = $mediafromftp_settings['search_display_metadata'];
352
+ }
353
+ if ( array_key_exists( 'dateset', $mediafromftp_settings ) ) {
354
+ $dateset = $mediafromftp_settings['dateset'];
355
+ }
356
+ if ( array_key_exists( 'datefixed', $mediafromftp_settings ) ) {
357
+ $datefixed = $mediafromftp_settings['datefixed'];
358
+ }
359
+ if ( array_key_exists( 'datetimepicker', $mediafromftp_settings ) ) {
360
+ $datetimepicker = $mediafromftp_settings['datetimepicker'];
361
+ }
362
+ if ( array_key_exists( 'max_execution_time', $mediafromftp_settings ) ) {
363
+ $max_execution_time = $mediafromftp_settings['max_execution_time'];
364
+ }
365
+ if ( array_key_exists( 'character_code', $mediafromftp_settings ) ) {
366
+ $character_code = $mediafromftp_settings['character_code'];
367
+ }
368
+ if ( array_key_exists( 'exclude', $mediafromftp_settings ) ) {
369
+ $exclude = $mediafromftp_settings['exclude'];
370
+ }
371
+ if ( array_key_exists( 'recursive_search', $mediafromftp_settings ) ) {
372
+ $recursive_search = $mediafromftp_settings['recursive_search'];
373
+ }
374
+ if ( array_key_exists( 'thumb_deep_search', $mediafromftp_settings ) ) {
375
+ $thumb_deep_search = $mediafromftp_settings['thumb_deep_search'];
376
+ }
377
+ if ( array_key_exists( 'search_limit_number', $mediafromftp_settings ) ) {
378
+ $search_limit_number = $mediafromftp_settings['search_limit_number'];
379
+ }
380
+ if ( array_key_exists( 'apply', $mediafromftp_settings['cron'] ) ) {
381
+ $cron_apply = $mediafromftp_settings['cron']['apply'];
382
+ }
383
+ if ( array_key_exists( 'schedule', $mediafromftp_settings['cron'] ) ) {
384
+ $cron_schedule = $mediafromftp_settings['cron']['schedule'];
385
+ }
386
+ if ( array_key_exists( 'limit_number', $mediafromftp_settings['cron'] ) ) {
387
+ $cron_limit_number = $mediafromftp_settings['cron']['limit_number'];
388
+ }
389
+ if ( array_key_exists( 'mail_apply', $mediafromftp_settings['cron'] ) ) {
390
+ $cron_mail_apply = $mediafromftp_settings['cron']['mail_apply'];
391
+ }
392
+ if ( array_key_exists( 'apply', $mediafromftp_settings['caption'] ) ) {
393
+ $caption_apply = $mediafromftp_settings['caption']['apply'];
394
+ }
395
+ if ( array_key_exists( 'exif_text', $mediafromftp_settings['caption'] ) ) {
396
+ $exif_text = $mediafromftp_settings['caption']['exif_text'];
397
+ }
398
+ if ( array_key_exists( 'log', $mediafromftp_settings ) ) {
399
+ $log = $mediafromftp_settings['log'];
400
+ }
401
+ /* for media-from-ftp-add-on-category */
402
+ if ( array_key_exists( 'mlcc', $mediafromftp_settings ) ) {
403
+ $mlcc = $mediafromftp_settings['mlcc'];
404
+ }
405
+ if ( array_key_exists( 'emlc', $mediafromftp_settings ) ) {
406
+ $emlc = $mediafromftp_settings['emlc'];
407
+ }
408
+ if ( array_key_exists( 'mlac', $mediafromftp_settings ) ) {
409
+ $mlac = $mediafromftp_settings['mlac'];
410
+ }
411
+ if ( array_key_exists( 'mlat', $mediafromftp_settings ) ) {
412
+ $mlat = $mediafromftp_settings['mlat'];
413
+ }
414
+ }
415
+
416
+ $mediafromftp_tbl = array(
417
+ 'pagemax' => $pagemax,
418
+ 'basedir' => $basedir,
419
+ 'searchdir' => $searchdir,
420
+ 'ext2typefilter' => $ext2typefilter,
421
+ 'extfilter' => $extfilter,
422
+ 'search_display_metadata' => $search_display_metadata,
423
+ 'dateset' => $dateset,
424
+ 'datefixed' => $datefixed,
425
+ 'datetimepicker' => $datetimepicker,
426
+ 'max_execution_time' => $max_execution_time,
427
+ 'character_code' => $character_code,
428
+ 'exclude' => $exclude,
429
+ 'recursive_search' => $recursive_search,
430
+ 'thumb_deep_search' => $thumb_deep_search,
431
+ 'search_limit_number' => $search_limit_number,
432
+ 'cron' => array(
433
+ 'apply' => $cron_apply,
434
+ 'schedule' => $cron_schedule,
435
+ 'limit_number' => $cron_limit_number,
436
+ 'mail_apply' => $cron_mail_apply,
437
+ 'mail' => $cron_mail,
438
+ 'user' => $cron_user,
439
+ ),
440
+ 'caption' => array(
441
+ 'apply' => $caption_apply,
442
+ 'exif_text' => $exif_text,
443
+ ),
444
+ 'log' => $log,
445
+ 'mlcc' => $mlcc,
446
+ 'emlc' => $emlc,
447
+ 'mlac' => $mlac,
448
+ 'mlat' => $mlat,
449
+ );
450
+ update_option( $wp_options_name, $mediafromftp_tbl );
451
+
452
+ }
453
+
454
+ }
455
+
456
+
req/class-tt-mediafromftp-list-table.php ADDED
@@ -0,0 +1,447 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ /*
10
+ Copyright (c) 2013- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
11
+ This program is free software; you can redistribute it and/or modify
12
+ it under the terms of the GNU General Public License as published by
13
+ the Free Software Foundation; version 2 of the License.
14
+
15
+ This program is distributed in the hope that it will be useful,
16
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ GNU General Public License for more details.
19
+
20
+ You should have received a copy of the GNU General Public License
21
+ along with this program; if not, write to the Free Software
22
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
+ */
24
+
25
+ if ( ! class_exists( 'WP_List_Table' ) ) {
26
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-screen.php' );
27
+ require_once( ABSPATH . 'wp-admin/includes/screen.php' );
28
+ require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
29
+ require_once( ABSPATH . 'wp-admin/includes/template.php' );
30
+ }
31
+
32
+ /** ==================================================
33
+ * List table
34
+ */
35
+ class TT_MediaFromFtp_List_Table extends WP_List_Table {
36
+
37
+ /** ==================================================
38
+ * Max items
39
+ *
40
+ * @var $max_items max_items.
41
+ */
42
+ public $max_items;
43
+
44
+ /** ==================================================
45
+ * Add on active
46
+ *
47
+ * @var $is_add_on_activate is_add_on_activate.
48
+ */
49
+ private $is_add_on_activate;
50
+
51
+ /** ==================================================
52
+ * Construct
53
+ *
54
+ * @since 9.81
55
+ */
56
+ public function __construct() {
57
+
58
+ $plugin_base_dir = untrailingslashit( plugin_dir_path( __DIR__ ) );
59
+ $slugs = explode( '/', $plugin_base_dir );
60
+ $slug = end( $slugs );
61
+ $plugin_dir = untrailingslashit( rtrim( $plugin_base_dir, $slug ) );
62
+
63
+ $category_active = false;
64
+ if ( function_exists( 'media_from_ftp_add_on_category_load_textdomain' ) ) {
65
+ include_once $plugin_dir . '/media-from-ftp-add-on-category/inc/MediaFromFtpAddOnCategory.php';
66
+ $category_active = true;
67
+ }
68
+ if ( function_exists( 'media_from_ftp_add_on_exif_load_textdomain' ) ) {
69
+ include_once $plugin_dir . '/media-from-ftp-add-on-exif/inc/MediaFromFtpAddOnExif.php';
70
+ }
71
+ if ( function_exists( 'media_from_ftp_add_on_cli_load_textdomain' ) ) {
72
+ require_once( $plugin_dir . '/media-from-ftp-add-on-cli/req/MediaFromFtpCli.php' );
73
+ }
74
+ if ( function_exists( 'media_from_ftp_add_on_wpcron_load_textdomain' ) ) {
75
+ include_once $plugin_dir . '/media-from-ftp-add-on-wpcron/inc/MediaFromFtpAddOnWpcron.php';
76
+ }
77
+
78
+ if ( ! class_exists( 'MediaFromFtp' ) ) {
79
+ include_once $plugin_base_dir . '/inc/class-mediafromftp.php';
80
+ }
81
+
82
+ /* Media Library Categories */
83
+ $mlc_active = false;
84
+ if ( class_exists( 'wpMediaLibraryCategories' ) ) {
85
+ $mlc_active = true;
86
+ }
87
+
88
+ /* Enhanced Media Library */
89
+ $eml_active = false;
90
+ if ( function_exists( 'wpuxss_eml_on_plugins_loaded' ) ) {
91
+ $eml_active = true;
92
+ }
93
+
94
+ /* Media Library Assistant */
95
+ $mla_active = false;
96
+ if ( function_exists( 'mla_name_conflict_reporting_action' ) ) {
97
+ $mla_active = true;
98
+ }
99
+
100
+ $this->is_add_on_activate = array(
101
+ 'category' => $category_active,
102
+ 'mlc' => $mlc_active,
103
+ 'eml' => $eml_active,
104
+ 'mla' => $mla_active,
105
+ );
106
+
107
+ global $status, $page;
108
+ /* Set parent defaults */
109
+ parent::__construct(
110
+ array(
111
+ 'singular' => 'new_url_attaches',
112
+ 'ajax' => false,
113
+ )
114
+ );
115
+
116
+ }
117
+
118
+ /** ==================================================
119
+ * Read data
120
+ *
121
+ * @since 9.50
122
+ */
123
+ private function read_data() {
124
+
125
+ $mediafromftp = new MediaFromFtp();
126
+ $mediafromftp_settings = get_option( $this->wp_options_name() );
127
+ $pagemax = $mediafromftp_settings['pagemax'];
128
+ $searchdir = $mediafromftp_settings['searchdir'];
129
+ $ext2typefilter = $mediafromftp_settings['ext2typefilter'];
130
+ $extfilter = $mediafromftp_settings['extfilter'];
131
+ $max_execution_time = $mediafromftp_settings['max_execution_time'];
132
+
133
+ $mlccs = explode( ',', $mediafromftp_settings['mlcc'] );
134
+ $emlcs = explode( ',', $mediafromftp_settings['emlc'] );
135
+ $mlacs = explode( ',', $mediafromftp_settings['mlac'] );
136
+ $mlats = explode( ',', $mediafromftp_settings['mlat'] );
137
+
138
+ $document_root = ABSPATH . $searchdir;
139
+
140
+ $mediafromftp->mb_initialize( $mediafromftp_settings['character_code'] );
141
+ $document_root = $mediafromftp->mb_encode_multibyte( $document_root, $mediafromftp_settings['character_code'] );
142
+
143
+ if ( strstr( $searchdir, '../' ) ) {
144
+ $document_root = realpath( $document_root );
145
+ }
146
+
147
+ global $wpdb;
148
+ $attachments = $wpdb->get_results(
149
+ "
150
+ SELECT ID
151
+ FROM $wpdb->posts
152
+ WHERE post_type = 'attachment'
153
+ "
154
+ );
155
+
156
+ $extpattern = $mediafromftp->extpattern( $extfilter );
157
+ $files = $mediafromftp->scan_file( $document_root, $extpattern, $mediafromftp_settings );
158
+
159
+ $count = 0;
160
+ $listtable_array = array();
161
+ foreach ( $files as $file ) {
162
+ /* Input URL */
163
+ list($new_file, $ext, $new_url) = $mediafromftp->input_url( $file, $attachments, $mediafromftp_settings['character_code'], $mediafromftp_settings['thumb_deep_search'] );
164
+ if ( $new_file ) {
165
+ ++$count;
166
+ list($inputhtml, $datetimehtml) = $mediafromftp->input_html( $ext, $file, $new_url, $count, $mediafromftp_settings );
167
+
168
+ $mlccategoryhtml = null;
169
+ $emlcategoryhtml = null;
170
+ $mlacategoryhtml = null;
171
+ if ( $this->is_add_on_activate['category'] ) {
172
+ $mediafromftpaddoncategory = new MediaFromFtpAddOnCategory();
173
+ $mlccategoryhtml = $mediafromftpaddoncategory->mlc_category_check_html( $count, $mlccs );
174
+ $emlcategoryhtml = $mediafromftpaddoncategory->eml_category_check_html( $count, $emlcs );
175
+ $mlacategoryhtml = $mediafromftpaddoncategory->mla_category_check_html( $count, $mlacs, $mlats );
176
+ unset( $mediafromftpaddoncategory );
177
+ }
178
+
179
+ $listtable_array[] = array(
180
+ 'ID' => $count,
181
+ 'title' => $inputhtml,
182
+ 'filename' => $file,
183
+ 'new_url' => $new_url,
184
+ 'datetime' => $datetimehtml,
185
+ 'mlccategories' => $mlccategoryhtml,
186
+ 'emlcategories' => $emlcategoryhtml,
187
+ 'mlacategories' => $mlacategoryhtml,
188
+ );
189
+
190
+ }
191
+ }
192
+ unset( $files, $mediafromftp, $attachments );
193
+
194
+ return $listtable_array;
195
+
196
+ }
197
+
198
+ /** ==================================================
199
+ * Column default
200
+ *
201
+ * @param array $item item.
202
+ * @param string $column_name column_name.
203
+ * @since 9.81
204
+ */
205
+ public function column_default( $item, $column_name ) {
206
+ switch ( $column_name ) {
207
+ case 'datetime':
208
+ case 'mlccategories':
209
+ case 'emlcategories':
210
+ case 'mlacategories':
211
+ return $item[ $column_name ];
212
+ default:
213
+ return print_r( $item, true ); /* Show the whole array for troubleshooting purposes */
214
+ }
215
+ }
216
+
217
+ /** ==================================================
218
+ * Column title
219
+ *
220
+ * @param array $item item.
221
+ * @since 9.81
222
+ */
223
+ public function column_title( $item ) {
224
+ /* Return the title contents */
225
+ return sprintf(
226
+ '%1$s <span style="color:silver"></span>',
227
+ /*$1%s*/ $item['title']
228
+ );
229
+ }
230
+
231
+ /** ==================================================
232
+ * Column checkbox
233
+ *
234
+ * @param array $item item.
235
+ * @since 9.81
236
+ */
237
+ public function column_cb( $item ) {
238
+ return sprintf(
239
+ '<input type="checkbox" name="%1$s[%2$s][url]" value="%3$s" form="mediafromftp_ajax_update" />',
240
+ /*%1$s*/ $this->_args['singular'],
241
+ /*%2$s*/ $item['ID'],
242
+ /*%3$s*/ $item['filename']
243
+ );
244
+ }
245
+
246
+ /** ==================================================
247
+ * Get Columns
248
+ *
249
+ * @since 9.81
250
+ */
251
+ public function get_columns() {
252
+ $columns = array(
253
+ 'cb' => '<input type="checkbox" />', /* Render a checkbox instead of text */
254
+ 'title' => 'URL',
255
+ 'datetime' => __( 'Edit date and time' ),
256
+ 'mlccategories' => '<div>' . __( 'Categories' ) . '<div></div>Media Library Categories</div>',
257
+ 'emlcategories' => '<div>' . __( 'Categories' ) . '<div></div>Enhanced Media Library</div>',
258
+ 'mlacategories' => '<div>' . __( 'Categories' ) . ' & ' . __( 'Tags' ) . '<div></div>Media Library Assistant</div>',
259
+ );
260
+ $mediafromftp_settings = get_option( $this->wp_options_name() );
261
+ if ( 'new' === $mediafromftp_settings['dateset'] || 'fixed' === $mediafromftp_settings['dateset'] ) {
262
+ unset( $columns['datetime'] );
263
+ }
264
+
265
+ if ( $this->is_add_on_activate['category'] ) {
266
+ if ( ! $this->is_add_on_activate['mlc'] ) {
267
+ unset( $columns['mlccategories'] );
268
+ }
269
+ if ( ! $this->is_add_on_activate['eml'] ) {
270
+ unset( $columns['emlcategories'] );
271
+ }
272
+ if ( ! $this->is_add_on_activate['mla'] ) {
273
+ unset( $columns['mlacategories'] );
274
+ }
275
+ } else {
276
+ unset( $columns['mlccategories'] );
277
+ unset( $columns['emlcategories'] );
278
+ unset( $columns['mlacategories'] );
279
+ }
280
+
281
+ return $columns;
282
+ }
283
+
284
+ /** ==================================================
285
+ * Get Sortable Columns
286
+ *
287
+ * @since 9.81
288
+ */
289
+ public function get_sortable_columns() {
290
+ $sortable_columns = array(
291
+ 'title' => array( 'title', false ),
292
+ );
293
+ return $sortable_columns;
294
+ }
295
+
296
+ /** ************************************************************************
297
+ * REQUIRED! This is where you prepare your data for display. This method will
298
+ * usually be used to query the database, sort and filter the data, and generally
299
+ * get it ready to be displayed. At a minimum, we should set $this->items and
300
+ * $this->set_pagination_args(), although the following properties and methods
301
+ * are frequently interacted with here...
302
+ *
303
+ * @global WPDB $wpdb
304
+ * @uses $this->_column_headers
305
+ * @uses $this->items
306
+ * @uses $this->get_columns()
307
+ * @uses $this->get_sortable_columns()
308
+ * @uses $this->get_pagenum()
309
+ * @uses $this->set_pagination_args()
310
+ **************************************************************************/
311
+ public function prepare_items() {
312
+
313
+ /**
314
+ * First, lets decide how many records per page to show
315
+ */
316
+ $mediafromftp_settings = get_option( $this->wp_options_name() );
317
+ $per_page = $mediafromftp_settings['pagemax'];
318
+
319
+ /**
320
+ * REQUIRED. Now we need to define our column headers. This includes a complete
321
+ * array of columns to be displayed (slugs & titles), a list of columns
322
+ * to keep hidden, and a list of columns that are sortable. Each of these
323
+ * can be defined in another method (as we've done here) before being
324
+ * used to build the value for our _column_headers property.
325
+ */
326
+ $columns = $this->get_columns();
327
+ $hidden = array();
328
+ $sortable = $this->get_sortable_columns();
329
+
330
+ /**
331
+ * REQUIRED. Finally, we build an array to be used by the class for column
332
+ * headers. The $this->_column_headers property takes an array which contains
333
+ * 3 other arrays. One for all columns, one for hidden columns, and one
334
+ * for sortable columns.
335
+ */
336
+ $this->_column_headers = array( $columns, $hidden, $sortable );
337
+
338
+ /**
339
+ * Instead of querying a database, we're going to fetch the example data
340
+ * property we created for use in this plugin. This makes this example
341
+ * package slightly different than one you might build on your own. In
342
+ * this example, we'll be using array manipulation to sort and paginate
343
+ * our data. In a real-world implementation, you will probably want to
344
+ * use sort and pagination data to build a custom query instead, as you'll
345
+ * be able to use your precisely-queried data immediately.
346
+ */
347
+ $data = $this->read_data();
348
+
349
+ /**
350
+ * This checks for sorting input and sorts the data in our array accordingly.
351
+ *
352
+ * In a real-world situation involving a database, you would probably want
353
+ * to handle sorting by passing the 'orderby' and 'order' values directly
354
+ * to a custom query. The returned data will be pre-sorted, and this array
355
+ * sorting technique would be unnecessary.
356
+ *
357
+ * @param array $a a.
358
+ * @param array $b b.
359
+ */
360
+ function usort_reorder( $a, $b ) {
361
+ /* If no sort, default to title */
362
+ if ( isset( $_REQUEST['orderby'] ) && ! empty( $_REQUEST['orderby'] ) ) {
363
+ $orderby = sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) );
364
+ } else {
365
+ $orderby = 'title';
366
+ }
367
+ /* If no order, default to asc */
368
+ if ( isset( $_REQUEST['order'] ) && ! empty( $_REQUEST['order'] ) ) {
369
+ $order = sanitize_text_field( wp_unslash( $_REQUEST['order'] ) );
370
+ } else {
371
+ $order = 'asc';
372
+ }
373
+ $result = strcmp( $a[ $orderby ], $b[ $orderby ] ); /* Determine sort order */
374
+ return ( 'asc' === $order ) ? $result : -$result; /* Send final sort direction to usort */
375
+ }
376
+ usort( $data, 'usort_reorder' );
377
+
378
+ /***********************************************************************
379
+ * ---------------------------------------------------------------------
380
+ * vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
381
+ *
382
+ * In a real-world situation, this is where you would place your query.
383
+ *
384
+ * For information on making queries in WordPress, see this Codex entry:
385
+ * http://codex.wordpress.org/Class_Reference/wpdb
386
+ *
387
+ * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
388
+ * ---------------------------------------------------------------------
389
+ */
390
+
391
+ /**
392
+ * REQUIRED for pagination. Let's figure out what page the user is currently
393
+ * looking at. We'll need this later, so you should always include it in
394
+ * your own package classes.
395
+ */
396
+ $current_page = $this->get_pagenum();
397
+
398
+ /**
399
+ * REQUIRED for pagination. Let's check how many items are in our data array.
400
+ * In real-world use, this would be the total number of items in your database,
401
+ * without filtering. We'll need this later, so you should always include it
402
+ * in your own package classes.
403
+ */
404
+ $total_items = count( $data );
405
+ $this->max_items = $total_items;
406
+
407
+ /**
408
+ * The WP_List_Table class does not handle pagination for us, so we need
409
+ * to ensure that the data is trimmed to only the current page. We can use
410
+ * array_slice() to
411
+ */
412
+ $data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ), $per_page );
413
+
414
+ /**
415
+ * REQUIRED. Now we can add our *sorted* data to the items property, where
416
+ * it can be used by the rest of the class.
417
+ */
418
+ $this->items = $data;
419
+
420
+ /**
421
+ * REQUIRED. We also have to register our pagination options & calculations.
422
+ */
423
+ $this->set_pagination_args(
424
+ array(
425
+ 'total_items' => $total_items, /* WE have to calculate the total number of items */
426
+ 'per_page' => $per_page, /* WE have to determine how many items to show on a page */
427
+ 'total_pages' => ceil( $total_items / $per_page ), /* WE have to calculate the total number of pages */
428
+ )
429
+ );
430
+ }
431
+
432
+ /** ==================================================
433
+ * Options name
434
+ *
435
+ * @return string $this->wp_options_name()
436
+ * @since 10.09
437
+ */
438
+ private function wp_options_name() {
439
+ if ( ! function_exists( 'wp_get_current_user' ) ) {
440
+ include_once( ABSPATH . 'wp-includes/pluggable.php' );
441
+ }
442
+ return 'mediafromftp_settings_' . get_current_user_id();
443
+ }
444
+
445
+ }
446
+
447
+
uninstall.php CHANGED
@@ -1,85 +1,94 @@
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
  }
@@ -88,4 +97,4 @@ function media_from_ftp_uninstall_option_names() {
88
 
89
  }
90
 
91
- ?>
1
  <?php
2
+ /**
3
+ * Uninstall
4
+ *
5
+ * @package Media from FTP
6
+ */
7
 
8
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
9
+ exit();
10
+ }
11
 
12
  global $wpdb;
13
 
14
+ /* For Single site */
15
+ if ( ! is_multisite() ) {
 
16
  foreach ( media_from_ftp_uninstall_option_names() as $option_name ) {
17
+ delete_option( $option_name );
18
+ /* Delete log database */
19
+ $wpdb->log_name = $wpdb->prefix . 'mediafromftp_log';
20
+ $wpdb->query( "DROP TABLE IF EXISTS $wpdb->log_name" );
21
  }
22
+ } else {
23
+ /* For Multisite */
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 $blogid ) {
27
+ switch_to_blog( $blogid );
 
 
 
 
 
28
  foreach ( media_from_ftp_uninstall_option_names() as $option_name ) {
29
+ delete_option( $option_name );
30
+ /* Delete log database */
31
+ $wpdb->log_name = $wpdb->prefix . 'mediafromftp_log';
32
+ $wpdb->query( "DROP TABLE IF EXISTS $wpdb->log_name" );
33
  }
34
+ }
35
+ switch_to_blog( $original_blog_id );
36
+ /* For site options. */
 
37
  foreach ( media_from_ftp_uninstall_option_names() as $option_name ) {
38
  delete_site_option( $option_name );
39
  }
40
  }
41
 
42
+ /* Delete all cache */
43
  $wp_uploads = wp_upload_dir();
44
+ $tmp_dir = $wp_uploads['basedir'] . '/media-from-ftp-tmp';
45
+ if ( is_ssl() ) {
46
+ $tmp_url = str_replace( 'http:', 'https:', $wp_uploads['baseurl'] ) . '/media-from-ftp-tmp';
47
  } else {
48
+ $tmp_url = $wp_uploads['baseurl'] . '/media-from-ftp-tmp';
49
  }
50
+ $del_transients = $wpdb->get_results(
51
+ $wpdb->prepare(
52
+ "
53
  SELECT option_value
54
  FROM $wpdb->options
55
+ WHERE option_value LIKE %s
56
+ ",
57
+ '%' . $wpdb->esc_like( $tmp_url ) . '%'
58
+ )
59
+ );
60
  foreach ( $del_transients as $del_transient ) {
61
+ $delfile = pathinfo( $del_transient->option_value );
62
  $del_cash_thumb_key = $delfile['filename'];
63
  $value_del_cash = get_transient( $del_cash_thumb_key );
64
+ if ( false <> $value_del_cash ) {
65
  delete_transient( $del_cash_thumb_key );
66
  }
67
  }
68
+ $del_cash_thumb_filename = $tmp_dir . '/*.*';
69
+ foreach ( glob( $del_cash_thumb_filename ) as $val ) {
70
+ unlink( $val );
71
  }
72
  if ( is_dir( $tmp_dir ) ) {
73
  rmdir( $tmp_dir );
74
  }
75
 
76
+ /** ==================================================
77
+ * Uninstall option names
78
+ *
79
+ * @since 1.00
80
+ */
81
  function media_from_ftp_uninstall_option_names() {
82
 
83
  global $wpdb;
84
  $option_names = array();
85
+ $wp_options = $wpdb->get_results(
86
+ "
87
  SELECT option_name
88
  FROM $wpdb->options
89
  WHERE option_name LIKE '%%mediafromftp_%%'
90
+ "
91
+ );
92
  foreach ( $wp_options as $wp_option ) {
93
  $option_names[] = $wp_option->option_name;
94
  }
97
 
98
  }
99
 
100
+