PluginProbe
WP Docs / 2.3.2
WP Docs v2.3.2
2.3.3 2.3.2 trunk 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1
wp-docs / inc / functions.php

functions.php in WP Docs 2.3.2, at inc/functions.php

3,820 lines 118.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if(!function_exists('wpdocs_secure_url')){
3 function wpdocs_secure_url($file_id=''){
4
5 $ret = add_query_arg(
6 array(
7 'wpdocs_dl' => $file_id,
8 'wpdocs_nonce' => wp_create_nonce('wpdocs_dl_'.$file_id),
9 ),
10 home_url('/')
11 );
12 return $ret;
13 }
14 }
15 if(!function_exists('wp_docs_get_memphis_dir_option_id')){
16 function wp_docs_get_option_id($option_name){
17 global $wpdb;
18 $option_name = esc_sql( $option_name );
19 $query = $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s",
20 $option_name
21 );
22 return $wpdb->get_var($query);
23 }
24 }
25
26 function sanitize_wpdocs_data( $input ) {
27
28 if(is_array($input)){
29
30 $new_input = array();
31
32 foreach ( $input as $key => $val ) {
33 $new_input[ $key ] = (is_array($val)?sanitize_wpdocs_data($val):sanitize_text_field( $val ));
34 }
35
36 }else{
37 $new_input = sanitize_text_field($input);
38 }
39
40 if(!is_array($new_input)){
41
42 if(stripos($new_input, '@') && is_email($new_input)){
43 $new_input = sanitize_email($new_input);
44 }
45
46 if(stripos($new_input, 'http') || wp_http_validate_url($new_input)){
47 $new_input = sanitize_url($new_input);
48 }
49
50 }
51
52
53 return $new_input;
54 }
55
56 function wpdocs_admin_enqueue_script()
57 {
58 if (isset($_GET['page']) && $_GET['page'] == 'wpdocs') {
59
60 //pree(get_option('mdocs-list'));exit;
61
62 global $wpdocs_pro, $wpdocs_options;
63
64 wp_enqueue_script('wpdocs_boostrap', plugin_dir_url(dirname(__FILE__)) . 'js/bootstrap.min.js', array('jquery'));
65 wp_enqueue_style('wpdocs-boostrap', plugins_url('css/bootstrap.min.css', dirname(__FILE__)));
66 wp_enqueue_script('wpdocs_slim', plugin_dir_url(dirname(__FILE__)) . 'js/slimselect.js', array('jquery'));
67 wp_enqueue_style('wpdocs-slim', plugins_url('css/slimselect.css', dirname(__FILE__)));
68
69 wp_enqueue_style( 'jquery-ui', plugins_url('css/jquery-ui.css', dirname(__FILE__)), array('jquery') );
70 wp_enqueue_style( 'wp-jquery-ui-dialog' );
71
72 wp_enqueue_script('wpdocs_block_scripts', plugin_dir_url(dirname(__FILE__)) . 'js/jquery.blockUI.js', array('jquery'));
73
74
75 wp_enqueue_style('fontawesome', plugins_url('css/fontawesome.min.css', dirname(__FILE__)));
76
77 wp_enqueue_media();
78
79 wp_enqueue_style('wpdocs-common', plugins_url('css/common-styles.css', dirname(__FILE__)), array(), date('Ymdhi'));
80 wp_enqueue_style('wpdocs-admin', plugins_url('css/admin-styles.css', dirname(__FILE__)), array(), date('Ymdhi'));
81
82 wp_enqueue_script('wpdocs_admin_scripts', plugin_dir_url(dirname(__FILE__)) . 'js/admin-scripts.js', array('jquery', 'jquery-ui-dialog'), time());
83 wp_enqueue_script('wpdocs_verify_scripts', plugin_dir_url(dirname(__FILE__)) . 'js/verify-scripts.js', array('jquery', 'jquery-ui-dialog'), time());
84
85 if($wpdocs_pro){
86 wp_enqueue_script('wpdocs_pro_scripts', plugin_dir_url(dirname(__FILE__)) . 'pro/wp-docs-admin.js?t='.time(), array('jquery'));
87 }
88
89 $dir_id_to_titles = array();
90 $all_dirs = wpdocs_list('');
91 if(!empty($all_dirs)){
92 foreach($all_dirs as $all_dir){
93 $dir_id_to_titles[$all_dir['id']] = $all_dir['title'];
94 }
95 }
96
97 wp_localize_script(
98 'wpdocs_admin_scripts',
99 'wpdocs_ajax_object',
100 array(
101 'ajax_url' => admin_url('admin-ajax.php'),
102 'nonce' => wp_create_nonce('wpdocs_update_options_nonce'),
103 'url' => admin_url('options-general.php?page=wpdocs'),
104 'wpdocs_pro' => $wpdocs_pro,
105 'wpdocs_delete_msg' => __('Do you want to delete this directory and data as well?', 'wp-docs'),
106 'wpdocs_delete_shortcut_msg' => __('Do you want to delete this shortcut?', 'wp-docs'),
107 'target_dir_msg' => __('Select a target directory.', 'wp-docs'),
108 'move_error' => __('Sorry! File could not move, please try again.', 'wp-docs'),
109 'move_str' => __('Cannot move to the selected directory', 'wp-docs'),
110 'copied' => __('Successfully copied!', 'wp-docs'),
111 'moved' => __('Successfully moved!', 'wp-docs'),
112 'premium_feature' => __('This feature is not available in basic version. Please upgrade.', 'wp-docs'),
113 'del_confirm' => __('Do you want to delete this file?', 'wp-docs'),
114 'del_confirm_all' => __('Do you want to delete selected files?', 'wp-docs'),
115 'import_confirm' => __('Do you want to import all directories and files from Memphis Documents Library?', 'wp-docs'),
116 'undo_import_confirm' => __('Do you want to rollback the import?', 'wp-docs'),
117 'select_role_str' => __('Select roles to allow upload', 'wp-docs'),
118 'rename_confirm' => __('Do you want to rename this directory?', 'wp-docs'),
119 'reset_confirm' => __('Do you want to reset all settings and clear directories?', 'wp-docs'),
120
121 'empty_settings' => empty($wpdocs_options),
122 'wc_os_pg' => (isset($_GET['pg'])?esc_attr($_GET['pg']):'0'),
123 'wc_os_tab' => (isset($_GET['t'])?esc_attr($_GET['t']):'0'),
124 'all_dirs' => $dir_id_to_titles,
125 'rename_confirm' => __('Please enter new folder name:', 'wp-docs'),
126
127 )
128 );
129
130 wp_localize_script(
131 'wpdocs_verify_scripts',
132 'wpdocs_vars',
133 array(
134 'ajax_url' => admin_url('admin-ajax.php'),
135 'url' => admin_url('options-general.php?page=wpdocs'),
136 'nonce' => wp_create_nonce('wpdocs_verify_nonce'),
137 'preparing_queue' => __('Preparing verification queue...', 'wp-docs'),
138 'unable_to_start' => __('Unable to start verification.', 'wp-docs'),
139 'ajax_error' => __('AJAX error.', 'wp-docs'),
140 'verification_failed' => __('Verification failed.', 'wp-docs'),
141 'verification_completed' => __('Verification completed.', 'wp-docs'),
142 'verification_interrupted' => __('Verification interrupted.', 'wp-docs'),
143 'checking_folder' => __('Checking Folder:', 'wp-docs'),
144 'checking_file' => __('Checking File:', 'wp-docs'),
145 'unknown_file' => __('Unknown File', 'wp-docs'),
146 'items_processed' => __('items processed', 'wp-docs'),
147 'total_folders' => __('Total Folders', 'wp-docs'),
148 'verified_folders' => __('Verified Folders', 'wp-docs'),
149 'missing_folders' => __('Missing Folders', 'wp-docs'),
150 'total_files' => __('Total Files', 'wp-docs'),
151 'verified_files' => __('Verified Files', 'wp-docs'),
152 'missing_files' => __('Missing Files', 'wp-docs'),
153 'missing_folder' => __('MISSING FOLDER', 'wp-docs'),
154 'missing_file' => __('MISSING FILE', 'wp-docs'),
155 'no_items_display' => __('No items to display.', 'wp-docs'),
156 'import_in_progress' => __('Import is already in progress. Please wait.', 'wp-docs'),
157 'import_missing_confirm' => __('This will import only missing folders and files. Do you want to continue?', 'wp-docs'),
158 'initializing' => __('Initializing...', 'wp-docs'),
159 'preparing_import_queue' => __('Preparing import queue...', 'wp-docs'),
160 'unable_to_start_import' => __('Unable to start import.', 'wp-docs'),
161 'import_failed' => __('Import failed.', 'wp-docs'),
162 'import_completed' => __('Import completed!', 'wp-docs'),
163 'refreshing_results' => __('Refreshing verification results...', 'wp-docs'),
164 'import_interrupted' => __('Import interrupted. Please try again.', 'wp-docs'),
165 'creating_folder' => __('Creating Folder:', 'wp-docs'),
166 'importing_file' => __('Importing File:', 'wp-docs'),
167 'path' => __('Path:', 'wp-docs'),
168 'target' => __('Target:', 'wp-docs'),
169 'folders_imported' => __('Folders imported:', 'wp-docs'),
170 'files_imported' => __('Files imported:', 'wp-docs'),
171 'failed' => __('Failed:', 'wp-docs'),
172 'please_wait' => __('Please wait...', 'wp-docs'),
173 'import_missing_items' => __('Import Missing Items Only', 'wp-docs'),
174 )
175 );
176 }
177 }
178
179 add_filter( 'ajax_query_attachments_args', 'wpdocs_filter_media');
180 function wpdocs_filter_media( $query ) {
181 // admins get to see everything
182 if ( ! current_user_can( 'manage_options' ) )
183 $query['author'] = get_current_user_id();
184
185 return $query;
186 }
187
188 function wpdocs_get_user_roles(){
189 $ret = array();
190 global $wp_roles;
191 if(!empty($wp_roles) && isset($wp_roles->roles) && !empty($wp_roles->roles)){
192
193 foreach($wp_roles->roles as $key=>$arr){
194 $ret[$key] = $arr['name'];
195 }
196 }
197 return $ret;
198 }
199
200 function wpdocs_get_user_roles_options(array $selected){
201
202 $wpdocs_get_user_roles = wpdocs_get_user_roles();
203
204 $options = '';
205
206 if(!empty($wpdocs_get_user_roles)){
207
208 foreach ($wpdocs_get_user_roles as $role_key => $role_name){
209
210 $selected_option = in_array($role_key, $selected) ? 'selected="selected"' : '';
211
212 $options .= "<option value='$role_key' $selected_option>$role_name</option>";
213
214 }
215 }
216
217 return $options;
218
219
220 }
221
222 function wpdocs_allowed_mime_types($mime_types){
223
224 global $wpdocs_options;
225
226
227 $dir = (isset($_GET['wpdocs_restriction']) ? esc_attr($_GET['wpdocs_restriction']) : 0);
228
229 $is_file = wpdocs_dir_options_by_name('file_upload', false, $dir);
230 $allowed_ext = wpdocs_dir_options_by_name('allowed_ext', '', $dir);
231
232
233 if($is_file && $allowed_ext){
234
235
236 $allowed_ext = explode(',', $allowed_ext);
237
238 $allowed_ext = array_map('trim', $allowed_ext);
239
240 $allowe_mime_types = array();
241
242 if(!empty($mime_types)){
243
244 foreach ($mime_types as $mime_key => $mime_value){
245
246 $mime_key_array = explode('|', $mime_key);
247 $mime_key_array = array_map('trim', $mime_key_array);
248
249
250 if(!empty($allowed_ext)){
251 foreach ($allowed_ext as $ext){
252
253 if(in_array($ext, $mime_key_array)){
254 $allowe_mime_types[$mime_key] = $mime_value;
255 }
256
257 }
258 }
259
260
261 }
262
263 }
264
265
266
267 return $allowe_mime_types;
268
269
270
271 }else{
272
273 return $mime_types;
274
275 }
276
277
278
279
280 }
281
282 function wpdocs_get_current_user_role() {
283 global $wp_roles;
284
285 $current_user = wp_get_current_user();
286 $roles = $current_user->roles;
287
288 $role = array_shift( $roles );
289
290 return isset( $wp_roles->role_names[ $role ] ) ? $role : FALSE;
291 }
292
293 function wpdocs_can_current_user_upload_file($dir = 0){
294
295 global $wpdocs_options;
296 $is_file = wpdocs_dir_options_by_name('file_upload', false, $dir);
297
298
299 if(!is_user_logged_in() && !$is_file){return false;}
300
301 $current_user_role = wpdocs_get_current_user_role();
302
303
304
305
306 // $allowed_role = array_key_exists('allowed_role', $wpdocs_options) ? $wpdocs_options['allowed_role'] : array();
307 $allowed_role = wpdocs_dir_options_by_name('allowed_role', array(), $dir);
308
309
310 if(!empty($allowed_role)){
311
312 if(in_array($current_user_role, $allowed_role)){
313
314 $can_current_user_upload = current_user_can('upload_files');
315
316 if(!$can_current_user_upload){
317
318 $user_role = get_role($current_user_role);
319 $user_role->add_cap('upload_files');
320 $user_role->add_cap('delete_posts');
321
322 }
323
324 return true;
325
326 }else{
327
328 return false;
329 }
330
331
332 }else{
333
334
335 return current_user_can('upload_files');
336
337 }
338
339
340
341 }
342
343 add_action('admin_enqueue_scripts', 'wpdocs_admin_enqueue_script');
344
345 add_action('wp_enqueue_scripts', 'wpdocs_wp_enqueue_script');
346
347
348 function wp_docs_recursive_array_search($needle, $haystack) {
349
350 if(is_array($haystack) && !empty($haystack)){
351 foreach($haystack as $key=>$value) {
352
353 if(!is_array($value) && stripos(' '.$value, $needle)) {
354 return array($key);
355 } else if (is_array($value) && $subkey = wp_docs_recursive_array_search($needle,$value)) {
356 array_unshift($subkey, $key);
357 return $subkey;
358 }
359 }
360 }
361 }
362
363
364 function wpdocs_test($post_content , $short_code = ''){
365
366 global $post;
367 $result = array();
368 //get shortcode regex pattern wordpress function
369 $pattern = get_shortcode_regex();
370 $result = array();
371
372 if ( preg_match_all( '/'. $pattern .'/s', $post_content, $matches ) )
373 {
374 pree($matches);
375 $keys = array();
376 foreach( $matches[0] as $key => $value) {
377 // $matches[3] return the shortcode attribute as string
378 // replace space with '&' for parse_str() function
379 $get = preg_replace('/"\s/', '"&', $matches[3][$key] );
380 parse_str($get, $output);
381
382 pree($get);
383 pree($output);
384
385 //get all shortcode attribute keys
386 $keys = array_unique( array_merge( $keys, array_keys($output)) );
387 $result[] = $output;
388
389 }
390 //var_dump($result);
391 if( $keys && $result ) {
392 // Loop the result array and add the missing shortcode attribute key
393 foreach ($result as $key => $value) {
394 // Loop the shortcode attribute key
395 foreach ($keys as $attr_key) {
396 $result[$key][$attr_key] = isset( $result[$key][$attr_key] ) ? $result[$key][$attr_key] : NULL;
397 }
398 //sort the array key
399 ksort( $result[$key]);
400 }
401 }
402
403 //display the result
404 }
405
406 return $result;
407
408
409 }
410
411 function wpdocs_wp_enqueue_script()
412 {
413 global $post, $wpdocs_pro, $wpdocs_url, $wpdocs_options;
414
415 $wpdocs_relevant_page = false;
416 $localize_handler = 'wpdocs_front_scripts';
417 //pree($post->post_content);
418 //pree(stripos($post->post_content, '[wpdocs]'));
419 $details_view_sorting = array_key_exists('details_view_sorting', $wpdocs_options);
420 $ajax_based_deep_search = ($wpdocs_pro && array_key_exists('ajax_based_deep_search', $wpdocs_options));
421
422
423
424 if(!empty($post) && isset($post->post_content)){
425 $meta_data = get_post_meta($post->ID);
426
427
428 $wpdocs_inside_meta = wp_docs_recursive_array_search('[wpdocs', $meta_data);
429 $wpdocs_inside_meta = is_array($wpdocs_inside_meta)?array_filter($wpdocs_inside_meta):array();
430
431 //pree($wpdocs_inside_meta);
432
433 if(stripos(' '.$post->post_content, '[wpdocs') || !empty($wpdocs_inside_meta)){
434 $wpdocs_relevant_page = true;
435 }
436 }
437 //pree($wpdocs_relevant_page);
438 if($wpdocs_relevant_page){
439
440 $is_bootstrap = array_key_exists('bootstrap', $wpdocs_options);
441 $is_file_upload = array_key_exists('file_upload', $wpdocs_options);
442
443 if(is_admin() || ($wpdocs_pro)){
444
445
446 add_filter('upload_mimes', 'wpdocs_allowed_mime_types', 1, 1);
447
448 wp_enqueue_media();
449
450 }
451
452 if($is_bootstrap){
453 wp_enqueue_script('wpdocs_boostrap', plugin_dir_url(dirname(__FILE__)) . 'js/bootstrap.min.js');
454 wp_enqueue_style('wpdocs-boostrap', plugins_url('css/bootstrap.min.css', dirname(__FILE__)));
455 }
456
457 $is_ajax_url = false;
458 $is_ajax = false;
459
460
461 if($wpdocs_pro){
462
463 $is_ajax = array_key_exists('ajax', $wpdocs_options);
464 $is_ajax_url = array_key_exists('ajax_url', $wpdocs_options);
465
466 wp_enqueue_script('wpdocs_pro_scripts', $wpdocs_url . 'pro/wp-docs-pro.js', array('jquery'), time());
467 $localize_handler = 'wpdocs_pro_scripts';
468 wp_enqueue_script('wpdocs_block_scripts', $wpdocs_url . 'js/jquery.blockUI.js', array('jquery'));
469
470
471 }
472
473
474
475 wp_enqueue_style('fontawesome', plugins_url('css/fontawesome.min.css', dirname(__FILE__)));
476
477
478 wp_enqueue_script('wpdocs_front_scripts', plugin_dir_url(dirname(__FILE__)) . 'js/front-scripts.js', array('jquery'), date('Ymdhi'));
479 wp_enqueue_style('wpdocs-common', plugins_url('css/common-styles.css', dirname(__FILE__)));
480 wp_enqueue_style('wpdocs-front', plugins_url('css/front-styles.css', dirname(__FILE__)), array(), date('Ymdhi'));
481
482 $dir_id = (array_key_exists('dir_id', $_GET)?sanitize_wpdocs_data($_GET['dir_id']):0);
483 $dir_id = (!$dir_id && array_key_exists('dir', $_GET)?sanitize_wpdocs_data($_GET['dir']):0);
484
485 $params_array = array(
486 'dir_id' => $dir_id,
487
488 'nonce' => wp_create_nonce('wpdocs_update_options_nonce'),
489 'parent_dir' => get_permalink($post->ID).'/?dir=',
490 'wpdocs_pro' => $wpdocs_pro,
491 'details_view_sorting' => $details_view_sorting,
492 'ajax_based_deep_search' => $ajax_based_deep_search,
493 'ajax_url' => admin_url('admin-ajax.php'),
494 'this_url' => get_permalink(),
495 'del_confirm' => __('Do you want to delete this file?', 'wp-docs'),
496 'del_dir_confirm' => __('Do you want to delete this directory?', 'wp-docs'),
497 'select_file_alert' => __('Please select a file to delete.', 'wp-docs'),
498 'not_belong_dir_string' => __('Sorry, you can not delete this directory.', 'wp-docs'),
499 'not_belong_string' => __('Sorry, you can not delete this file.', 'wp-docs'),
500 'copied' => __('Successfully copied!', 'wp-docs'),
501 'moved' => __('Successfully moved!', 'wp-docs'),
502 'block_ui' => __('Please wait...', 'wp-docs'),
503 'is_ajax' => $is_ajax,
504 'is_ajax_url' => $is_ajax_url,
505 'del_from_front' => array_key_exists('del_from_front', $wpdocs_options),
506 'restriction_load' => isset($_GET['wpdocs_restriction']),
507 'restriction_id' => isset($_GET['wpdocs_restriction']) ? $_GET['wpdocs_restriction'] : '',
508 'restriction_container' => isset($_GET['wpdocs_container']) ? $_GET['wpdocs_container'] : '',
509 'current_user_id' => get_current_user_id(),
510 'current_user_role' => wpdocs_get_current_user_role(),
511
512 );
513 if($params_array['dir_id'] && $params_array['del_from_front']){
514 $params_array['del_from_front'] = wpdocs_can_current_user_upload_file($params_array['dir_id']);
515 }
516
517 wp_localize_script(
518 $localize_handler,
519 'wpdocs',
520 $params_array
521 );
522
523
524 }
525 }
526
527 if (is_admin()) {
528 add_action('admin_menu', 'wpdocs_menu');
529 }
530 function wpdocs_menu()
531 {
532 global $wpdocs_data, $wpdocs_pro;
533
534 $title = $wpdocs_data['Name'] . ' ' . ($wpdocs_pro ? ' ' . __('Pro', 'wp-docs') : '');
535
536 add_options_page($title, $title, 'publish_pages', 'wpdocs', 'wpdocs_settings');
537 }
538 function wpdocs_settings()
539 {
540 global $wpdocs_premium_link, $wpdocs_pro, $wpdocs_url;
541 $wpdocs_options = get_option('wpdocs_options', array());
542 $wpdocs_options = is_array($wpdocs_options)?$wpdocs_options:array();
543 include_once('wpdocs_settings.php');
544 }
545
546 function wpdocs_list_inner($post_parent='', $recursive=false, $orderby='post_title', $order='ASC', $exclude_post_type=array()){
547
548 global $wpdb, $wpdocs_post_types, $wpdocs_post_status;
549
550 $ids = (is_array($post_parent)?$post_parent:explode(',', $post_parent));
551 $ids = array_map('trim', $ids);
552 $ids = array_filter($ids, 'is_numeric');
553 $ids = (empty($ids)?array(0):$ids);
554
555 $posts_array = array();
556
557 if(!empty($ids)){
558
559 $post_types = $wpdocs_post_types;
560
561 if(!empty($exclude_post_type)){
562 $post_types = array_diff_key($post_types, array_flip($exclude_post_type));
563 }
564 //pree($exclude_post_type);
565 //pree($post_types);//exit;
566
567 if($recursive){
568 unset($post_types['shortcut']);
569 }
570
571
572 $query_str = $wpdb->prepare('SELECT ID, post_title, post_type, post_content, post_parent, guid FROM '.$wpdb->posts.' WHERE post_status=%s AND post_type IN ("'.implode('","', $post_types).'") AND post_parent IN ("'.implode(',', $ids).'") ORDER BY '. $orderby.' '.$order,
573 $wpdocs_post_status
574 );
575
576 //pree($query_str);
577
578 $posts_array = $wpdb->get_results($query_str);
579
580 if($recursive){
581 $post_parent_arr = array();
582 if(!empty($posts_array)){
583 foreach($posts_array as $posts_item){
584 $post_parent_arr[] = $posts_item->ID;
585 }
586 if(!empty($post_parent)){
587
588 $posts_array = array_merge($posts_array, wpdocs_list_inner($post_parent_arr, $recursive, $orderby, $order, $exclude_post_type));
589 }
590 }
591
592 }
593
594 }
595
596 return $posts_array;
597 }
598 function wpdocs_list($post_parent = 0, $orderby='post_title', $order='ASC', $return_type='smart', $exclude_post_type=array()){
599
600 //pree($post_parent);pree($orderby);pree($order);pree($return_type);pree($exclude_post_type);
601
602 global $wpdocs_post_types, $wpdocs_post_status;
603
604 $ret = $posts_array = array();
605
606 //global $wpdb;
607
608 $args = array(
609 'posts_per_page' => -1,
610 'offset' => 0,
611 'category' => '',
612 'category_name' => '',
613 'orderby' => $orderby,
614 'order' => $order,
615 'include' => '',
616 'exclude' => '',
617 'meta_key' => '',
618 'meta_value' => '',
619 'post_type' => $wpdocs_post_types,
620 'post_mime_type' => '',
621 'author' => '',
622 'author_name' => '',
623 'post_status' => $wpdocs_post_status,
624 'suppress_filters' => true
625 );
626
627 if(is_numeric($post_parent)) {
628 $args['post_parent'] = $post_parent;
629 $posts_array = get_posts($args);
630 //pree($wpdb->last_query);
631 }else{
632
633 switch($orderby){
634 case 'title':
635 case 'post_title':
636 $orderby = 'post_title';
637 break;
638 case 'date':
639 case 'post_date':
640 $orderby = 'post_date';
641 break;
642 }
643 //pree($exclude_post_type);
644 $posts_array = wpdocs_list_inner($post_parent, false, $orderby, $order, $exclude_post_type);
645
646
647 }
648
649
650 if (!empty($posts_array)) {
651 foreach ($posts_array as $posts) { //pree($posts);
652 switch($return_type){
653 default:
654 case 'smart':
655 $guid_pos = strpos($posts->guid, 'p='.$posts->ID);
656 $posts->guid = ($guid_pos!='' && $guid_pos>=0?'':$posts->guid);
657 $ret[] = array('id' => $posts->ID, 'title' => $posts->post_title, 'type' => $posts->post_type, 'content' => $posts->post_content, 'link' => $posts->guid);
658 break;
659 case 'object':
660 $ret[] = $posts;
661 break;
662 }
663 }
664 }
665
666 //pree($ret);
667
668 return $ret;
669 }
670
671 function wpdocs_create_folder_post($post_parent, $post_title = "New Folder")
672 {
673
674 $my_post = array(
675 'post_title' => $post_title,
676 'post_content' => '',
677 'post_status' => 'hidden',
678 'post_author' => get_current_user_id(),
679 'post_type' => 'wpdocs_folder',
680 'post_parent' => (($post_parent > 0 && wpdocs_folder_exists($post_parent)) ? $post_parent : 0),
681 'post_category' => array()
682 );
683
684 $dir_id = wp_insert_post($my_post);
685
686 return $dir_id;
687 }
688
689 add_action('wp_ajax_wpdocs_create_folder', 'wpdocs_create_folder');
690
691 function wpdocs_create_folder()
692 {
693 if ( ! current_user_can( 'manage_options' ) ) {
694 wp_send_json_error( __("Unauthorized user", 'wp-docs') );
695 wp_die();
696 }
697
698 $nonce = sanitize_wpdocs_data(wp_unslash($_POST['nonce']));
699
700 if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) )
701 die (__("Sorry, your nonce did not verify.", 'wp-docs'));
702
703 $post_parent = sanitize_wpdocs_data($_POST['parent_dir']);
704
705 $dir_id = wpdocs_create_folder_post($post_parent);
706
707 $list_obj = get_post($dir_id);
708
709 $list = array('id'=>$list_obj->ID, 'content'=>$list_obj->post_content, 'title'=>$list_obj->post_title, 'type'=>$list_obj->post_type, 'guid'=>$list_obj->guid);
710
711 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
712
713 echo '<li class="ab-dir ab-new"
714 data-id="' . esc_attr($dir_id) . '"
715 data-resource="' . esc_attr(base64_encode($dir_id)) . '"
716 data-linked="' . esc_attr($list['content']) . '"
717 data-guid="' . ($is_shortcut ? esc_attr($list['guid']) : '') . '">
718
719 <a class="folder fa fa-folder"></a>
720
721 <a class="dtitle" title="' . esc_attr(__('Click here to rename', 'wp-docs')) . '">
722 ' . esc_html__('New Folder', 'wp-docs') . '
723 </a>
724
725 <span class="wpd_action_span">
726 <a class="wpd-edit" title="' . esc_attr(__('Click here to edit', 'wp-docs')) . '"></a>
727 <span class="wpd_action_span_inner">
728 <a class="wpd-copy" title="' . esc_attr(__('Click here to copy', 'wp-docs')) . '"></a>
729 <a class="wpd-move" title="' . esc_attr(__('Click here to move', 'wp-docs')) . '"></a>
730 </span>
731 <a class="wpd-trash" title="' . esc_attr(__('Click here to delete', 'wp-docs')) . '"></a>
732 </span>
733 </li>';
734
735 exit;
736 }
737
738
739 if(!function_exists('wpd_get_icon_file_types')){
740
741 function wpd_get_icon_file_types(){
742
743 global $icon_sub_path, $wpdocs_dir;
744
745 $ext_img_dir = $wpdocs_dir.$icon_sub_path;
746
747 $file_types = file_exists($ext_img_dir) && is_dir($ext_img_dir) ? scandir($ext_img_dir) : array();
748
749 $file_types = array_map(function ($file) use ($ext_img_dir){
750
751 $ignore_array = array('.', '..');
752 if(!in_array($file, $ignore_array) && !is_dir($ext_img_dir.$file)){
753 return current(explode('.', $file));
754 }
755
756 }, $file_types);
757
758 $file_types = array_filter($file_types);
759
760 return $file_types;
761
762 }
763 }
764
765
766 if(!function_exists('wpd_get_item_type_icon_url')){
767
768 function wpd_get_item_type_icon_url($item){
769
770 //pree($item);
771
772 global $wpdocs_url, $icon_sub_path, $wpdocs_options, $wpdocs_pro;
773
774 $ext_img_url = $wpdocs_url.$icon_sub_path;
775 $file_types = wpd_get_icon_file_types();
776
777 $file_url = wp_get_attachment_url($item);
778 //pree($file_url);exit;
779
780
781 $filename = basename($file_url);
782 $filename = explode('?', $filename);
783 $filename = (is_array($filename)?current($filename):$filename);
784
785
786 $ext = explode('.', $filename);
787 $ext = end($ext);
788 $icon = in_array($ext, $file_types) ? $ext.'.png' : 'unknown.png';
789 $icon_url = $ext_img_url.$icon;
790
791 switch($ext){
792 case 'svg':
793 case 'gif':
794 case 'bmp':
795 case 'jpg':
796 case 'jpeg':
797 case 'png':
798 $thumb_image = array_key_exists('thumb_image', $wpdocs_options);
799
800 if($thumb_image){
801 $icon_urls = wp_get_attachment_image_src($item, 'thumbnail', false);
802 if(!empty($icon_urls)){
803 $icon_url = current($icon_urls);
804 }
805 }
806 //pree($icon_urls);
807 break;
808 }
809
810
811
812 return array(
813 'file_id' => $item,
814 'file_url' => esc_url($file_url),
815 'ext' => esc_attr($ext),
816 'filename' => esc_attr($filename),
817 'title' => esc_html($filename),
818 'icon_url' => esc_url($icon_url)
819 );
820
821
822 }
823 }
824
825 add_action('wp_ajax_wpdocs_add_files', 'wpdocs_add_files');
826
827 function wpdocs_add_files(){
828
829 $nonce = sanitize_wpdocs_data(wp_unslash($_POST['nonce']));
830
831 if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) )
832 die (__("Sorry, your nonce did not verify.", 'wp-docs'));
833
834
835 $dir_id = sanitize_wpdocs_data($_POST['dir_id']);
836 $files = sanitize_wpdocs_data($_POST['files']);
837 $files = is_array($files) ? $files : array($files);
838
839 // delete_post_meta($dir_id, 'wpdocs_items');
840
841 wpdocs_update_files_meta($dir_id, $files);
842
843
844
845 $ret = '';
846
847 if(!empty($files)){
848 $files_list = wpdocs_list_added_items($dir_id);
849
850 $ret = $files_list;
851 }
852
853 echo $ret;
854 exit;
855 }
856 function wpdocs_list_added_items($dir)
857 {
858
859 global $wpdocs_options, $icon_sub_path, $wpdocs_url;
860
861 $wp_get_upload_dir = wp_get_upload_dir();
862 $wp_uploads_path = $wp_get_upload_dir['basedir'];
863 $wp_uploads_url = $wp_get_upload_dir['baseurl'];
864
865
866
867 $wpdocs_items = wpdocs_added_items($dir); //pree($wpdocs_items);
868 $files_list = array();
869 $pdf_thumb_selected = (array_key_exists('pdf_thumb', $wpdocs_options)?$wpdocs_options['pdf_thumb']:'default');
870
871 if (!empty($wpdocs_items)) {
872 //pree('$wpdocs_items');
873
874 foreach ($wpdocs_items as $item) {
875 $class = '';
876
877 $item_data = wpd_get_item_type_icon_url($item);
878 extract($item_data);
879
880 //pree($item_data);exit;
881 //pree($wp_uploads_path);exit;
882
883 $icon_str = '<img src="' . esc_url($icon_url) . '" style="" alt="' . esc_attr($title) . '">';
884
885 switch ($ext) {
886 case 'png':
887 case 'jpg':
888 case 'jpeg':
889 case 'gif':
890 case 'bmp':
891
892 //$class .= 'fa-image';
893
894 break;
895
896 case 'pdf':
897
898 if($pdf_thumb_selected=='first_page_as_thumbnail'){
899
900 $pdf_file = str_replace($wp_uploads_url, $wp_uploads_path, $item_data['file_url']);
901
902 if(file_exists($pdf_file) && class_exists('imagick')){
903
904 //pree($item_data);
905 //$icon_str = '<object style="width: 100px; height: 100px" data="'.$item_data['file_url'].'#page=1" type="application/pdf"></object>';
906
907 $file_url_thumb = str_replace('.pdf', '.png', strtolower($item_data['file_url']));
908 $file_url_thumb_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url_thumb);
909
910 if(!file_exists($file_url_thumb_path) && class_exists('imagick')){
911
912 try {
913 $im = new imagick($item_data['file_url']);
914 $im->setIteratorIndex(0);
915 $im->setImageFormat('png');
916 $im->writeImage($file_url_thumb_path);
917 } catch (ImagickException $e) {
918
919 if(defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG){
920 error_log("Imagick error: " . $e->getMessage());
921 error_log('file_url: '.$item_data['file_url']);
922 error_log('file_url_thumb_path: '.$file_url_thumb_path);
923 }
924
925 $file_url_thumb = $wpdocs_url.$icon_sub_path.$ext.'.png';
926 }
927
928
929 }
930
931 $icon_str = '<img src="' . esc_url( $file_url_thumb ) . '" style="" alt="' . esc_attr( $title ) . '">';
932
933 }
934
935 }
936
937 break;
938
939 default:
940 //$class .= 'fa-file';
941 break;
942 }
943 $class = '';
944
945
946 $secured_file_url = wpdocs_secure_url($file_id);
947
948 $files_list[ $title ] = '<li data-id="' . esc_attr( $item ) . '" data-dir="' . esc_attr( $dir ) . '" title="' . esc_attr( $filename ) . '">
949 <a href="' . esc_url( $secured_file_url ) . '" target="_blank" class="file ' . esc_attr( $class ) . '"> ' . $icon_str . ' </a>
950 <a class="ftitle" title="' . esc_attr( $title ) . '">' . esc_html( $title ) . '</a>
951 <span class="wpd_action_span">
952 <a href="' . esc_url( 'upload.php?item=' . $item ) . '" target="_blank" class="wpd-edit" title="' . esc_attr__( 'Click here to edit', 'wp-docs' ) . '"></a>
953 <span class="wpd_action_span_inner">
954 <a class="wpd-copy" title="' . esc_attr__( 'Click here to copy', 'wp-docs' ) . '"></a>
955 <a class="wpd-move" title="' . esc_attr__( 'Click here to move', 'wp-docs' ) . '"></a>
956 </span>
957 <a href="' . esc_url( 'upload.php?search=' . rawurlencode( $filename ) ) . '" target="_blank" class="wpd-trash" title="' . esc_attr__( 'Click here to delete', 'wp-docs' ) . '"></a>
958 </span>
959 </li>';
960 }
961 }
962
963 ksort($files_list);
964
965 return implode('', $files_list);
966 }
967
968
969 if(!function_exists('wpdocs_get_breadcrumb_array')){
970 function wpdocs_get_breadcrumb_array($dir, $breadcrumb=true){
971
972 $breadcrumb_array = array();
973
974 if ($breadcrumb && $dir) {
975 $dir_id = $dir;
976
977 $dir_parent = wp_get_post_parent_id($dir_id);
978 array_push($breadcrumb_array, $dir_id);
979 array_push($breadcrumb_array, $dir_parent);
980
981
982 if ($dir_parent != 0) {
983 do {
984
985 $dir_parent = wp_get_post_parent_id($dir_parent);
986 array_push($breadcrumb_array, $dir_parent);
987 } while ($dir_parent > 0);
988 }
989 }
990
991
992 return $breadcrumb_array;
993
994 }
995 }
996
997 if(!function_exists('wpdocs_list_population')){
998 function wpdocs_list_population($list=array(), $file_data=array(), $file_list_row='', $default_orderby='', $default_order=''){
999 $filename = $file_data['filename'];
1000 $list[$filename] = $file_list_row;
1001 return $list;
1002 }
1003 }
1004
1005 if(!function_exists('wpdocs_sorting')){
1006 function wpdocs_sorting($list, $order=''){
1007 ksort($list);
1008 return $list;
1009 }
1010 }
1011
1012 add_shortcode('wpdocs', 'wpdocs_front_list');
1013
1014 function wpdocs_front_list($atts=array())
1015 {
1016
1017 if (
1018 !empty($_POST) && !wp_doing_ajax() &&
1019 (
1020 (isset( $_POST['wpdocs_front_list_nonce'] ) && ! wp_verify_nonce( sanitize_wpdocs_data(wp_unslash($_POST['wpdocs_front_list_nonce_field'])), 'wpdocs_front_list_nonce' ) )
1021 )
1022 ) {
1023
1024 print _e('Sorry, your nonce did not verify.', 'wp-docs');
1025 exit;
1026
1027 } else {
1028
1029 }
1030
1031
1032
1033
1034 //pree($atts);
1035 ob_start();
1036 global $wpdocs_url, $wpdocs_options, $wpdocs_pro, $wpdocs_post_types, $pdf_thumb_selected, $icon_sub_path;
1037
1038 $pdf_thumb_selected = (array_key_exists('pdf_thumb', $wpdocs_options)?$wpdocs_options['pdf_thumb']:'default');
1039
1040 $wpdocs_view = get_option('wpdocs_view', array());
1041 $wpdocs_view = is_array($wpdocs_view) ? $wpdocs_view : array();
1042
1043 $is_bootstrap = array_key_exists('bootstrap', $wpdocs_options);
1044 $is_searchbox = array_key_exists('searchbox', $wpdocs_options);
1045
1046 $details_date = array_key_exists('details_date', $wpdocs_options);
1047 $details_date_created = array_key_exists('details_date_created', $wpdocs_options);
1048 $details_view_sorting = array_key_exists('details_view_sorting', $wpdocs_options);
1049 $ajax_based_deep_search = ($wpdocs_pro && array_key_exists('ajax_based_deep_search', $wpdocs_options));
1050 $details_type = array_key_exists('details_type', $wpdocs_options);
1051 $details_size = array_key_exists('details_size', $wpdocs_options);
1052
1053 $customize_icon_size = array_key_exists('icon_size', $wpdocs_options) ? $wpdocs_options['icon_size'] : '';
1054 $customize_icon_size = ($customize_icon_size?$customize_icon_size: 'font-size:100%');
1055 $customize_icon_size = explode(':', $customize_icon_size);
1056 $customize_icon_size = 'font-size:'.end($customize_icon_size);
1057
1058 $customize_font_size = array_key_exists('font_size', $wpdocs_options) ? $wpdocs_options['font_size'] : '';
1059 $customize_font_size = ($customize_font_size?$customize_font_size: 'font-size:90%');
1060 $customize_font_size = explode(':', $customize_font_size);
1061 $customize_font_size = 'font-size:'.end($customize_font_size);
1062
1063 $wp_get_upload_dir = wp_get_upload_dir();
1064 $wp_uploads_path = $wp_get_upload_dir['basedir'];
1065
1066 $wp_uploads_url = home_url('wp-content/uploads');
1067
1068
1069 if(isset($_POST['wpd_dir_id_ajax'])){
1070
1071 $dir = ((isset($_POST['wpd_dir_id_ajax']) && wpdocs_folder_exists($_POST['wpd_dir_id_ajax'])) ? $_POST['wpd_dir_id_ajax'] : 0);
1072 if($_POST['wpd_dir_id_ajax'] == 0 && $_POST['wpd_home_id'] != 0){
1073 $dir = sanitize_wpdocs_data($_POST['wpd_home_id']);
1074 }
1075 $get_permalink = isset($_POST['wpd_get_permalink']) ? $_POST['wpd_get_permalink'] : '' ;
1076
1077 }else{
1078
1079 $dir = ((isset($_GET['dir']) && is_numeric($_GET['dir']) && wpdocs_folder_exists($_GET['dir'])) ? sanitize_wpdocs_data($_GET['dir']) : 0);
1080 $get_permalink = get_permalink();
1081 }
1082
1083
1084
1085
1086 $dir = ($dir?$dir:((isset($atts['dir']) && $atts['dir']!='' && is_numeric($atts['dir']) && wpdocs_folder_exists($atts['dir']))?sanitize_wpdocs_data($atts['dir']):$dir));
1087 $no_breadcrumb = (isset($atts['breadcrumb']) && $atts['breadcrumb']=='false');
1088 $default_view = (isset($atts['view']) ? $atts['view'] : 'list');
1089 $default_orderby = (isset($atts['orderby']) ? $atts['orderby'] : 'title');
1090 $default_order = (isset($atts['order']) ? $atts['order'] : 'ASC');
1091
1092
1093
1094 switch($default_view){
1095 default:
1096 case 'list':
1097 $default_view = 'list_view';
1098 break;
1099
1100 case 'icons':
1101 $default_view = 'large_icon_view';
1102 break;
1103
1104 case 'details':
1105 $default_view = 'detail_view';
1106 break;
1107
1108 }
1109
1110
1111
1112 if(isset($_POST['wpd_home_id'])){
1113
1114 $home_id = sanitize_wpdocs_data($_POST['wpd_home_id']);
1115
1116 }elseif(isset($atts['dir'])){
1117 $home_id = sanitize_wpdocs_data($atts['dir']);
1118 }else{
1119 $home_id = 0;
1120 }
1121
1122 $home_id = preg_replace("/[\'\"\"\"]+/", '', $home_id);
1123
1124 $wpdoc_valid = true;
1125
1126 $wpdocs_security = get_post_meta($dir, 'wpdocs_security', true);
1127 //pree($wpdocs_security);
1128 $roles = array();
1129 if($wpdocs_security!=''){
1130 if( is_user_logged_in() ) {
1131 $user = wp_get_current_user();
1132 $roles = ( array ) $user->roles;
1133 //pree($roles);
1134 $wpdoc_valid = (in_array($wpdocs_security, $roles) || current_user_can('administrator'));
1135 }else{
1136 $wpdoc_valid = false;
1137 }
1138
1139 }
1140
1141 //pree($wpdoc_valid);exit;
1142
1143 $breadcrumb_array = wpdocs_get_breadcrumb_array($dir, !$no_breadcrumb);
1144 //pree($breadcrumb_array);
1145 //pree($wpdoc_valid);
1146 $warning_msg = '';
1147 if(!$wpdoc_valid){
1148 $dir = time()*time();
1149 $warning_msg = '<div class="alert alert-warning fade in alert-dismissible show w-50 mx-auto">
1150 <button type="button" class="close" data-dismiss="alert" aria-label="'.__('Close', 'wp-docs').'">
1151 <span aria-hidden="true" style="font-size:20px">×</span>
1152 </button> <strong>'.__('Sorry', 'wp-docs').'!</strong> '.__('You are not allowed to access this content.', 'wp-docs').'
1153 </div>';
1154 }
1155
1156
1157 //pree($dir.' ~ '.$no_breadcrumb);
1158
1159
1160
1161 if(is_array($breadcrumb_array) && !empty($breadcrumb_array)){
1162
1163
1164 $array_search = array_search($home_id , $breadcrumb_array);
1165
1166 if($array_search === 0){
1167
1168 unset($breadcrumb_array);
1169
1170 }else{
1171
1172 $breadcrumb_array[$array_search] = 0;
1173
1174 }
1175
1176 if(!empty($breadcrumb_array)){
1177
1178 foreach ($breadcrumb_array as $index => $bread){
1179
1180 if($index > $array_search){
1181 unset($breadcrumb_array[$index]);
1182 }
1183 }
1184 }
1185 }
1186
1187 $wpdocs_list = wpdocs_list($dir, $default_orderby, $default_order);
1188
1189 $files_list = wpdocs_added_items($dir);
1190
1191 //pree($files_list);
1192
1193 $wpdocs_list_merged_arr = array();
1194
1195 $deep_files_list_arr = array();
1196
1197
1198
1199 //pree($wpdocs_list);
1200 //pree($wpdocs_list_merged_arr);
1201 //pree($deep_files_list_arr);
1202 //pree($files_list);
1203
1204 $is_file = wpdocs_dir_options_by_name('file_upload', false, $dir);
1205 $is_del_from_front = (is_user_logged_in() && wpdocs_dir_options_by_name('del_from_front', false, $dir));
1206 $is_current_user_files = wpdocs_dir_options_by_name('current_user_files', false, $dir);
1207
1208
1209
1210 if($is_file && $is_current_user_files){
1211 $files_list = wpdocs_added_items_by_user($dir);
1212
1213 //pree($files_list);
1214 }
1215
1216
1217 if(!$is_current_user_files && $ajax_based_deep_search && function_exists('get_deep_files_list_arr')){
1218
1219 //pree($wpdocs_list);
1220
1221 $deep_list_arr = get_deep_files_list_arr($wpdocs_list);
1222 $wpdocs_list_merged_arr = $deep_list_arr['wpdocs_list_merged_arr'];
1223 $deep_files_list_arr = $deep_list_arr['deep_files_list_arr'];
1224
1225 }
1226
1227 ?>
1228
1229
1230 <div class="container-fluid wpdoc_container"
1231 data-dir_restrictions="<?php echo esc_attr( wpdocs_get_dir_restrictions( $dir, 'base64' ) ); ?>"
1232 data-del_from_front="<?php echo esc_attr( $is_del_from_front ); ?>"
1233 data-dir="<?php echo esc_attr( $dir ); ?>"
1234 data-home="<?php echo esc_attr( $home_id ); ?>">
1235
1236 <?php wp_nonce_field( 'wpdocs_front_list_nonce', 'wpdocs_front_list_nonce_field' ); ?>
1237
1238 <input type="hidden" class="wpd_home_id" value="<?php echo esc_attr( $home_id ); ?>" />
1239 <input type="hidden" class="wpd_del_file_id" value="" />
1240
1241 <?php
1242
1243 $wpdocs_view = array_key_exists($home_id, $wpdocs_view) ? $wpdocs_view[$home_id] : trim($default_view);
1244
1245 ?>
1246
1247 <div class="card mt-3">
1248 <!-- breadcrumb Area -->
1249 <nav aria-label="breadcrumb" class="wpdocs-nav position-relative">
1250 <ol class="breadcrumb bg-light" style="border-bottom:1px solid #dee2e6;border-radius: 0; min-height: 40px;">
1251
1252 <?php if (!empty($breadcrumb_array)) { ?>
1253
1254 <li class="breadcrumb-item bread_home_url">
1255 <a class="wpd_bread_item" href="<?php echo esc_url($get_permalink); ?>" data-id="0">
1256 <?php echo esc_html__('Home', 'wp-docs'); ?>
1257 </a>
1258 </li>
1259 <?php
1260
1261 foreach (array_reverse($breadcrumb_array) as $bread_key => $bread_value) {
1262 $active = '';
1263 $page = '';
1264 $permalink = stripos($get_permalink, '?');
1265 $permalink_c = ($permalink!='' && is_numeric($permalink) && $permalink>=0);
1266 $link = '<a class="wpd_bread_item" href="' . esc_url($get_permalink . ($permalink_c ? '&' : '?') . 'dir=' . $bread_value) . '" data-id="' . esc_attr($bread_value) . '">' . (get_the_title($bread_value)) . '</a>';
1267 if ($bread_value == 0) {
1268 continue;
1269 }
1270 if ($bread_value == $dir) {
1271 $active = 'active';
1272 $page = 'page';
1273 $link = get_the_title($bread_value);
1274 }
1275
1276
1277 ?>
1278 <li class="breadcrumb-item <?php echo esc_attr($active); ?>" aria-current="<?php echo esc_attr($page); ?>">
1279 <?php echo wp_kses_post($link); ?>
1280 </li>
1281
1282 <?php } ?>
1283 <?php
1284 }
1285
1286 ?>
1287
1288 </ol>
1289
1290 <?php if($is_del_from_front):?>
1291 <i style="opacity: 0.5;"
1292 class="fa fa-trash fa-1x position-absolute wp_docs_del_file <?php echo esc_attr(is_user_logged_in() ? 'logged_in' : 'logged_out'); ?>"
1293 title="<?php echo esc_attr__('Click here to delete selected files', 'wp-docs'); ?>">
1294 </i>
1295
1296 <?php endif; ?>
1297
1298 <?php if($wpdocs_pro && $dir != 0 && wpdocs_can_current_user_upload_file($dir) && $is_file):?>
1299
1300 <i class="fa fa-upload fa-1x wpdocs-front-add-media position-absolute"
1301 id="wpdocs_front_file_add_<?php echo esc_attr( $dir ); ?>"
1302 title="<?php echo esc_attr__( 'Click here to add files', 'wp-docs' ); ?>">
1303 </i>
1304
1305 <?php endif; ?>
1306 </nav>
1307 <?php
1308 /*
1309 $current_user_id = get_current_user_id();
1310
1311 pree($current_user_id);
1312
1313
1314 $args = array(
1315 'posts_per_page' => -1,
1316 'offset' => 0,
1317 'category' => '',
1318 'category_name' => '',
1319 'orderby' => 'title',
1320 'order' => 'ASC',
1321 'include' => array($dir),
1322 'exclude' => '',
1323 'meta_key' => '',
1324 'meta_value' => '',
1325 'post_type' => 'wpdocs_folder',
1326 'post_mime_type' => '',
1327 'post_parent' => '',//$post_parent,
1328 'author' => $current_user_id,
1329 'author_name' => '',
1330 'post_status' => 'hidden',
1331 'suppress_filters' => true
1332 );
1333 $posts_array = get_posts($args);
1334 pree($posts_array);
1335 */
1336 ?>
1337
1338 <?php echo $warning_msg ? '<div class="card-body">' . wp_kses_post( $warning_msg ) . '</div>' : ''; ?>
1339 <?php if($is_searchbox || $ajax_based_deep_search): ?>
1340 <div class="wpdocs-searchbox">
1341 <input type="text" placeholder="<?php echo ($ajax_based_deep_search?__('Type here to search...', 'wp-docs'):__('Type here to filter...', 'wp-docs')); ?>" />
1342 </div>
1343 <?php endif; ?>
1344
1345 <div class="card-body <?php echo $warning_msg?'d-none':''; ?>">
1346
1347 <!-- Large Icon View Area -->
1348 <div class="row folder_view large_icon_view <?php echo $wpdocs_view=='large_icon_view'?'':'d-none'; ?>">
1349 <?php
1350
1351 //pree($wpdocs_list);
1352
1353 $no_dir_found = false;
1354 $no_file_found = false;
1355 if (!empty($wpdocs_list)) {
1356 foreach ($wpdocs_list as $list) {
1357 //$wpdocs_child_items = wpdocs_list($list['id']);
1358 //$wpdocs_child_files_list = wpdocs_added_items($list['id']);
1359 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
1360 ?>
1361
1362 <div class="col-4 col-md-3 file_wrapper is_dir" style="cursor: pointer;"
1363 data-id="<?php echo esc_attr($list['id']); ?>"
1364 data-resource="<?php echo esc_attr(base64_encode($list['id'])); ?>"
1365 data-linked="<?php echo esc_attr($list['content']); ?>"
1366 data-guid="<?php echo esc_attr($is_shortcut ? $list['link'] : ''); ?>">
1367
1368 <figure class="figure file_view p-0">
1369 <span class="fa fa-folder text-warning" style="<?php echo esc_attr($customize_icon_size); ?>"></span>
1370 <figcaption class="figure-caption text-center" style="<?php echo esc_attr($customize_font_size); ?>">
1371 <?php echo esc_html($list['title']); ?>
1372 </figcaption>
1373 </figure>
1374
1375 </div>
1376 <?php
1377 }
1378 } else {
1379 $no_dir_found = true;
1380 }
1381
1382 //pree($wpdocs_list_merged_arr);
1383
1384 if (!empty($wpdocs_list_merged_arr)) {
1385
1386 foreach ($wpdocs_list_merged_arr as $wpdocs_merged_list) {
1387
1388 foreach ($wpdocs_merged_list as $list_obj) {
1389
1390 $list = array('id'=>$list_obj->ID, 'content'=>$list_obj->post_content, 'title'=>$list_obj->post_title, 'type'=>$list_obj->post_type, 'guid'=>$list_obj->guid);
1391 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
1392
1393 ?>
1394 <div class="col-4 col-md-3 file_wrapper is_dir is_deep" style="cursor: pointer;"
1395 data-id="<?php echo esc_attr($list['id']); ?>"
1396 data-resource="<?php echo esc_attr(base64_encode($list['id'])); ?>"
1397 data-linked="<?php echo esc_attr($list['content']); ?>"
1398 data-guid="<?php echo esc_attr($is_shortcut ? $list['guid'] : ''); ?>">
1399
1400 <figure class="figure file_view p-0">
1401 <span class="fa fa-folder text-warning" style="<?php echo esc_attr($customize_icon_size); ?>"></span>
1402
1403 <figcaption class="figure-caption text-center" style="<?php echo esc_attr($customize_font_size); ?>">
1404 <?php echo esc_html($list['title']); ?>
1405 </figcaption>
1406 </figure>
1407
1408 </div>
1409 <?php
1410 }
1411 }
1412 }
1413
1414 //pree($files_list);
1415
1416
1417 if (!empty($files_list)) {
1418 $list = array();
1419 foreach ($files_list as $file) {
1420
1421 $file_data = wpd_get_item_type_icon_url($file);
1422 extract($file_data);
1423
1424 //pree($file_data);exit;
1425
1426 if(trim($file_url)){
1427
1428 switch ($ext) {
1429 case 'png':
1430 case 'jpg':
1431 case 'jpeg':
1432 case 'gif':
1433 case 'bmp':
1434
1435 //$class .= 'fa-image';
1436
1437 break;
1438
1439 case 'pdf':
1440
1441 if($pdf_thumb_selected=='first_page_as_thumbnail'){
1442
1443 $pdf_file = str_replace($wp_uploads_url, $wp_uploads_path, $file_data['file_url']);
1444
1445 if(file_exists($pdf_file) && class_exists('imagick')){
1446
1447 //pree($file_data);
1448 //$icon_str = '<object style="width: 100px; height: 100px" data="'.$file_data['file_url'].'#page=1" type="application/pdf"></object>';
1449
1450 $file_url_thumb = str_replace('.pdf', '.png', strtolower($file_data['file_url']));
1451 $file_url_thumb_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url_thumb);
1452
1453 if(!file_exists($file_url_thumb_path) && class_exists('imagick')){
1454
1455 try {
1456 $im = new imagick($item_data['file_url']);
1457 $im->setIteratorIndex(0);
1458 $im->setImageFormat('png');
1459 $im->writeImage($file_url_thumb_path);
1460 } catch (ImagickException $e) {
1461
1462 if(defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG){
1463 error_log("Imagick error: " . $e->getMessage());
1464 error_log('file_url: '.$item_data['file_url']);
1465 error_log('file_url_thumb_path: '.$file_url_thumb_path);
1466 }
1467
1468 $file_url_thumb = $wpdocs_url.$icon_sub_path.$ext.'.png';
1469 }
1470
1471
1472 }
1473
1474
1475 $icon_url = $file_url_thumb;
1476
1477 }
1478
1479 }
1480
1481 break;
1482
1483 default:
1484 //$class .= 'fa-file';
1485 break;
1486 }
1487
1488 $secured_file_url = wpdocs_secure_url($file_id);
1489
1490 $file_list_row = '
1491
1492 <div title="'.esc_attr($filename).'" class="col-4 col-md-3 is_file text-center is_shallow" style="cursor: pointer;" data-id="'.esc_attr($file).'">
1493 <figure class="figure file_view p-1">
1494 <a href="'.esc_url($secured_file_url).'" target="_blank" class="file">
1495 <img class="my-3" src="'.esc_url($icon_url).'" />
1496 </a>
1497 <figcaption class="figure-caption text-center">'.esc_html($title).'</figcaption>
1498 </figure>
1499 </div>
1500
1501 ';
1502 $list = wpdocs_list_population($list, $file_data, $file_list_row, $default_orderby);
1503
1504 }
1505
1506 }
1507 //pree(array_keys($list));
1508
1509 //ksort($list);
1510 $list = wpdocs_sorting($list, $default_order);
1511 //pree(array_keys($list));
1512 echo implode('', $list);
1513 } else {
1514 $no_file_found = true;
1515 }
1516
1517 if (!empty($deep_files_list_arr)) {
1518 $list = array();
1519 foreach ($deep_files_list_arr as $file) {
1520
1521 $file_data = wpd_get_item_type_icon_url($file);
1522 extract($file_data);
1523
1524 if(trim($file_url)){
1525
1526
1527
1528 switch ($ext) {
1529 case 'png':
1530 case 'jpg':
1531 case 'jpeg':
1532 case 'gif':
1533 case 'bmp':
1534
1535 //$class .= 'fa-image';
1536
1537 break;
1538
1539 case 'pdf':
1540
1541 if($pdf_thumb_selected=='first_page_as_thumbnail'){
1542
1543 $pdf_file = str_replace($wp_uploads_url, $wp_uploads_path, $file_data['file_url']);
1544
1545 if(file_exists($pdf_file) && class_exists('imagick')){
1546
1547 //pree($file_data);
1548 //$icon_str = '<object style="width: 100px; height: 100px" data="'.$file_data['file_url'].'#page=1" type="application/pdf"></object>';
1549
1550 $file_url_thumb = str_replace('.pdf', '.png', strtolower($file_data['file_url']));
1551 $file_url_thumb_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url_thumb);
1552
1553 if(!file_exists($file_url_thumb_path)){
1554
1555 $im = new imagick($file_data['file_url']);
1556 $im->setIteratorIndex(0);
1557 $im->setImageFormat('png');
1558 $im->writeImage($file_url_thumb_path);
1559
1560 }
1561
1562 $icon_url = $file_url_thumb;
1563
1564 }
1565
1566 }
1567
1568 break;
1569
1570 default:
1571 //$class .= 'fa-file';
1572 break;
1573 }
1574
1575 $secured_file_url = wpdocs_secure_url($file_id);
1576
1577 $file_list_row = '
1578
1579 <div title="'.esc_attr($filename).'" class="col-4 col-md-3 is_file text-center is_deep" style="cursor: pointer;" data-id="'.esc_attr($file).'">
1580 <figure class="figure file_view p-1">
1581 <a href="'.esc_url($secured_file_url).'" target="_blank" class="file">
1582 <img class="my-3" src="'.esc_url($icon_url).'" />
1583 </a>
1584 <figcaption class="figure-caption text-center">'.esc_html($title).'</figcaption>
1585 </figure>
1586 </div>
1587
1588 ';
1589 $list = wpdocs_list_population($list, $file_data, $file_list_row, $default_orderby);
1590
1591 }
1592
1593 }
1594 //pree(array_keys($list));
1595
1596 //ksort($list);
1597 $list = wpdocs_sorting($list, $default_order);
1598 //pree(array_keys($list));
1599 echo implode('', $list);
1600 }
1601
1602
1603
1604 if ($no_dir_found && $no_file_found) {
1605
1606 ?>
1607 <div class="alert alert-info text-center mx-auto empty-dir-files">
1608 <strong><?php _e('Info!', 'wp-docs'); ?></strong> <?php _e('Empty Directory.', 'wp-docs'); ?>
1609 </div>
1610 <?php } ?>
1611
1612
1613 </div>
1614
1615 <!-- List View Area -->
1616 <div class="row folder_view list_view <?php echo $wpdocs_view=='list_view'?'':'d-none'; ?>">
1617 <?php
1618 $no_dir_found = false;
1619 $no_file_found = false;
1620 if (!empty($wpdocs_list)) {
1621 foreach ($wpdocs_list as $list) {
1622 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
1623 ?>
1624
1625 <div class="col-12 file_wrapper is_dir" style="cursor: pointer;"
1626 data-id="<?php echo esc_attr($list['id']); ?>"
1627 data-resource="<?php echo esc_attr(base64_encode($list['id'])); ?>"
1628 data-linked="<?php echo esc_attr($list['content']); ?>"
1629 data-guid="<?php echo esc_attr($is_shortcut ? $list['link'] : ''); ?>">
1630 <figure class="figure file_view p-2">
1631 <span class="fa fa-folder text-warning" style="font-size:25px"></span>
1632 <small class="text-center"><?php echo esc_html($list['title']); ?></small>
1633 </figure>
1634 </div>
1635 <?php
1636 }
1637 } else {
1638 $no_dir_found = true;
1639 }
1640
1641 if (!empty($wpdocs_list_merged_arr)) {
1642
1643 foreach ($wpdocs_list_merged_arr as $wpdocs_merged_list) {
1644
1645 foreach ($wpdocs_merged_list as $list_obj) {
1646
1647 $list = array('id'=>$list_obj->ID, 'content'=>$list_obj->post_content, 'title'=>$list_obj->post_title, 'type'=>$list_obj->post_type, 'guid'=>$list_obj->guid);
1648 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
1649
1650 ?>
1651 <div class="col-12 file_wrapper is_dir is_deep" style="cursor: pointer;"
1652 data-id="<?php echo esc_attr($list['id']); ?>"
1653 data-resource="<?php echo esc_attr(base64_encode($list['id'])); ?>"
1654 data-linked="<?php echo esc_attr($list['content']); ?>"
1655 data-guid="<?php echo esc_attr($is_shortcut ? $list['guid'] : ''); ?>">
1656 <figure class="figure file_view p-2">
1657 <span class="fa fa-folder text-warning" style="font-size:25px"></span>
1658 <small class="text-center"><?php echo esc_html($list['title']); ?></small>
1659 </figure>
1660 </div>
1661 <?php
1662 }
1663 }
1664 }
1665
1666
1667 if (!empty($files_list)) {
1668 $list = array();
1669 foreach ($files_list as $file) {
1670
1671 $file_data = wpd_get_item_type_icon_url($file);
1672 extract($file_data);
1673
1674
1675 if(trim($file_url)){
1676
1677 $secured_file_url = wpdocs_secure_url($file_id);
1678
1679 $file_list_row = '
1680 <div title="'.esc_attr($filename).'" class="col-12 file_wrapper is_file" style="cursor: pointer;" data-id="'.$file.'">
1681 <figure class="figure file_view p-3">
1682 <a href="'.$secured_file_url.'" target="_blank" class="file" ><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></a>
1683 <small class="text-center">'.$title.'</small>
1684 </figure>
1685 </div>';
1686
1687 $list = wpdocs_list_population($list, $file_data, $file_list_row, $default_orderby);
1688
1689 }
1690
1691 }
1692 //pree($list);
1693 //ksort($list);
1694 $list = wpdocs_sorting($list, $default_order);
1695 echo implode('', $list);
1696 } else {
1697 $no_file_found = true;
1698 }
1699
1700 if (!empty($deep_files_list_arr)) {
1701 $list = array();
1702 foreach ($deep_files_list_arr as $file) {
1703
1704 $file_data = wpd_get_item_type_icon_url($file);
1705 extract($file_data);
1706
1707
1708 if(trim($file_url)){
1709
1710 $file_list_row = '
1711 <div title="'.esc_attr($filename).'" class="col-12 file_wrapper is_file is_deep" style="cursor: pointer;" data-id="'.$file.'">
1712 <figure class="figure file_view p-3">
1713 <a href="'.$file_url.'" target="_blank" class="file" ><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></a>
1714 <small class="text-center">'.$title.'</small>
1715 </figure>
1716 </div>';
1717
1718 $list = wpdocs_list_population($list, $file_data, $file_list_row, $default_orderby);
1719
1720 }
1721
1722 }
1723 //pree($list);
1724 //ksort($list);
1725 $list = wpdocs_sorting($list, $default_order);
1726 echo implode('', $list);
1727 }
1728
1729
1730
1731 if ($no_dir_found && $no_file_found) {
1732
1733 ?>
1734 <div class="alert alert-info text-center mx-auto empty-dir-files">
1735 <strong><?php _e('Info!', 'wp-docs'); ?></strong> <?php _e('Empty Directory.', 'wp-docs'); ?>
1736 </div>
1737 <?php } ?>
1738
1739
1740 </div>
1741 <?php
1742
1743 ?>
1744 <?php
1745
1746 $d_v_caret = $wpdocs_pro && $details_view_sorting ? '<i class="fa fa-docs-sort" aria-hidden="true"></i>' : '';
1747
1748
1749
1750
1751 ?>
1752 <!-- Detail View Area -->
1753 <div class="row folder_view detail_view mt-0 <?php echo $wpdocs_view=='detail_view'?'':'d-none'; ?>">
1754 <div class="table-responsive" style="zoom:70%">
1755 <table class="table">
1756 <thead class="thead">
1757 <tr>
1758 <th><?php esc_html_e('Name', 'wp-docs'); ?> <?php echo wp_kses_post($d_v_caret); ?></th>
1759
1760 <?php if ( $details_date_created ) : ?>
1761 <th><?php esc_html_e('Created Date', 'wp-docs'); ?> <?php echo wp_kses_post($d_v_caret); ?></th>
1762 <?php endif; ?>
1763
1764 <?php if ( $details_date ) : ?>
1765 <th><?php esc_html_e('Modified Date', 'wp-docs'); ?> <?php echo wp_kses_post($d_v_caret); ?></th>
1766 <?php endif; ?>
1767
1768 <?php if ( $details_type ) : ?>
1769 <th><?php esc_html_e('Type', 'wp-docs'); ?> <?php echo wp_kses_post($d_v_caret); ?></th>
1770 <?php endif; ?>
1771
1772 <?php if ( $details_size ) : ?>
1773 <th><?php esc_html_e('Size', 'wp-docs'); ?> <?php echo wp_kses_post($d_v_caret); ?></th>
1774 <?php endif; ?>
1775
1776 </tr>
1777 </thead>
1778 <?php
1779 $no_dir_found = false;
1780 $no_file_found = false;
1781 if (!empty($wpdocs_list)) {
1782 foreach ($wpdocs_list as $list) {
1783 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
1784 ?>
1785 <tr title="<?php echo esc_attr($list['id']); ?>" class="file_wrapper file_view is_dir" style="cursor: pointer;" data-id="<?php echo esc_attr($list['id']); ?>" data-resource="<?php echo esc_attr(base64_encode($list['id'])); ?>" data-linked="<?php echo esc_attr($list['content']); ?>" data-guid="<?php echo $is_shortcut?esc_url($list['link']):''; ?>">
1786 <td>
1787 <figure class="figure ">
1788 <span class="fa fa-folder text-warning" style="font-size:25px"></span>
1789 <small class="text-center mb-1"><?php echo esc_html($list['title']); ?></small>
1790 </figure>
1791 </td>
1792
1793 <?php if($details_date_created): ?> <td data-time="<?php get_post_time('U', false, $list['id']) ?>"><small><?php echo get_the_date(get_option( 'date_format' ), $list['id']) . ' ' . get_the_time(get_option( 'time_format' ), $list['id']) ?></small></td><?php endif; ?>
1794 <?php if($details_date): ?> <td data-time="<?php get_post_modified_time('U', false, $list['id']) ?>"><small><?php echo get_the_modified_date(get_option( 'date_format' ), $list['id']) . ' ' . get_the_modified_time(get_option( 'time_format' ), $list['id']) ?></small></td><?php endif; ?>
1795 <?php if($details_type): ?> <td><small><?php
1796
1797
1798 $directory_post_type = get_post_type($list['id']);
1799
1800
1801 if($wpdocs_post_types['shortcut']==$directory_post_type){
1802 echo '<span style="color: #06C;" class="fa fa-link"></span> '.__('Shortcut', 'wp-docs');
1803 }elseif($wpdocs_post_types['dir']==$directory_post_type){
1804 echo __('Directory', 'wp-docs');
1805 }else{
1806 echo $directory_post_type;
1807 }
1808
1809
1810 ?></small></td><?php endif; ?>
1811 <?php if($details_size): ?> <td><small></small></td><?php endif; ?>
1812 </tr>
1813 <?php
1814 }
1815 } else {
1816 $no_dir_found = true;
1817 }
1818
1819 if (!empty($wpdocs_list_merged_arr)) {
1820
1821 foreach ($wpdocs_list_merged_arr as $wpdocs_merged_list) {
1822
1823 foreach ($wpdocs_merged_list as $list_obj) {
1824
1825 $list = array('id'=>$list_obj->ID, 'content'=>$list_obj->post_content, 'title'=>$list_obj->post_title, 'type'=>$list_obj->post_type, 'guid'=>$list_obj->guid);
1826 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
1827
1828 ?>
1829 <tr title="<?php echo esc_attr($list['id']); ?>" class="file_wrapper file_view is_dir is_deep" style="cursor: pointer;" data-id="<?php echo esc_attr($list['id']); ?>" data-resource="<?php echo esc_attr(base64_encode($list['id'])); ?>" data-linked="<?php echo esc_attr($list['content']); ?>" data-guid="<?php echo $is_shortcut?esc_attr($list['guid']):''; ?>">
1830 <td>
1831 <figure class="figure ">
1832 <span class="fa fa-folder text-warning" style="font-size:25px"></span>
1833 <small class="text-center mb-1"><?php echo esc_html($list['title']); ?></small>
1834 </figure>
1835 </td>
1836
1837 <?php if($details_date_created): ?> <td data-time="<?php get_post_time('U', false, $list['id']) ?>"><small><?php echo get_the_date(get_option( 'date_format' ), $list['id']) . ' ' . get_the_time(get_option( 'time_format' ), $list['id']) ?></small></td><?php endif; ?>
1838 <?php if($details_date): ?> <td data-time="<?php get_post_modified_time('U', false, $list['id']) ?>"><small><?php echo get_the_modified_date(get_option( 'date_format' ), $list['id']) . ' ' . get_the_modified_time(get_option( 'time_format' ), $list['id']) ?></small></td><?php endif; ?>
1839 <?php if($details_type): ?> <td><small><?php
1840
1841
1842 $directory_post_type = get_post_type($list['id']);
1843
1844 if($wpdocs_post_types['shortcut']==$directory_post_type){
1845 echo 'Directory Shortcut';
1846 }elseif($wpdocs_post_types['dir']==$directory_post_type){
1847 echo 'Directory';
1848 }else{
1849 echo $directory_post_type;
1850 }
1851
1852
1853
1854
1855 ?></small></td><?php endif; ?>
1856 <?php if($details_size): ?> <td><small></small></td><?php endif; ?>
1857 </tr>
1858 <?php
1859 }
1860 }
1861 }
1862
1863
1864 if (!empty($files_list)) {
1865 $list = array();
1866 foreach ($files_list as $file) {
1867
1868 //pree($file);exit;
1869
1870 $file_data = wpd_get_item_type_icon_url($file);
1871 extract($file_data);
1872 //pree($ts);
1873
1874 if(trim($icon_url)){
1875 $secured_file_url = wpdocs_secure_url($file_id);
1876 $files_list_row = '
1877 <tr title="'.esc_attr($filename).'" data-url="'.$secured_file_url.'" class="file_view file_link is_file" style="cursor: pointer;" data-id="'.$file.'">
1878
1879 <td>
1880
1881 <figure class="figure file_view">
1882 <span class="file"><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></span>
1883 <small class="text-center">'.$title.'</small>
1884 </figure>
1885 </td>
1886 ';
1887
1888 }
1889
1890 $created_time_u = get_post_time('U', false, $file);
1891 $modified_time_u = get_post_modified_time('U', false, $file);
1892
1893 $file_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url);
1894
1895 $file_size = round(@filesize($file_path) / 1024);
1896 if($details_date_created): $files_list_row .= '<td data-time="'.$created_time_u.'"><small>'.get_the_date(get_option( 'date_format' ), $file) . ' ' . get_the_time(get_option( 'time_format' ), $file).'</small></td>'; endif;
1897 if($details_date): $files_list_row .= '<td data-time="'.$modified_time_u.'"><small>'.get_the_modified_date(get_option( 'date_format' ), $file) . ' ' . get_the_modified_time(get_option( 'time_format' ), $file).'</small></td>'; endif;
1898 if($details_type): $files_list_row .= '<td><small>'.get_post_mime_type($file).'</small></td>'; endif;
1899 if($details_size): $files_list_row .= '<td data-time="'.$file_size.'"><small>'.$file_size. ' KB'.'</small></td>'; endif;
1900 // data-time is used for sorting purpose on front end it will sort by data-time value if it exist if not exist than it will be sorted by td inner text
1901
1902
1903 $files_list_row .= '</tr>';
1904
1905 $list = wpdocs_list_population($list, $file_data, $files_list_row, $default_orderby);
1906
1907
1908
1909 }
1910
1911
1912 $list = wpdocs_sorting($list, $default_order);
1913 echo implode('', $list);
1914
1915 } else {
1916 $no_file_found = true;
1917 }
1918
1919 if (!empty($deep_files_list_arr)) {
1920 $list = array();
1921
1922 //pree($wp_get_upload_dir);
1923 foreach ($deep_files_list_arr as $file) {
1924
1925 //pree($file);exit;
1926
1927 $file_data = wpd_get_item_type_icon_url($file);
1928 extract($file_data);
1929 //pree($ts);
1930
1931 if(trim($icon_url)){
1932
1933 $secured_file_url = wpdocs_secure_url($file_id);
1934
1935 $files_list_row = '
1936 <tr title="'.esc_attr($filename).'" data-url="'.$secured_file_url.'" class="file_view file_link is_file is_deep" style="cursor: pointer;" data-id="'.$file.'">
1937
1938 <td>
1939
1940 <figure class="figure file_view">
1941 <span class="file"><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></span>
1942 <small class="text-center">'.$title.'</small>
1943 </figure>
1944 </td>
1945 ';
1946
1947 }
1948
1949 $created_time_u = get_post_time('U', false, $file);
1950 $modified_time_u = get_post_modified_time('U', false, $file);
1951
1952 $file_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url);
1953
1954 $file_size = round(@filesize($file_path) / 1024);
1955 if($details_date_created): $files_list_row .= '<td data-time="'.$created_time_u.'"><small>'.get_the_date(get_option( 'date_format' ), $file) . ' ' . get_the_time(get_option( 'time_format' ), $file).'</small></td>'; endif;
1956 if($details_date): $files_list_row .= '<td data-time="'.$modified_time_u.'"><small>'.get_the_modified_date(get_option( 'date_format' ), $file) . ' ' . get_the_modified_time(get_option( 'time_format' ), $file).'</small></td>'; endif;
1957 if($details_type): $files_list_row .= '<td><small>'.get_post_mime_type($file).'</small></td>'; endif;
1958 if($details_size): $files_list_row .= '<td data-time="'.$file_size.'"><small>'.$file_size. ' KB'.'</small></td>'; endif;
1959 // data-time is used for sorting purpose on front end it will sort by data-time value if it exist if not exist than it will be sorted by td inner text
1960
1961
1962 $files_list_row .= '</tr>';
1963
1964 $list = wpdocs_list_population($list, $file_data, $files_list_row, $default_orderby);
1965
1966
1967
1968 }
1969
1970
1971 $list = wpdocs_sorting($list, $default_order);
1972 echo implode('', $list);
1973
1974 }
1975
1976
1977
1978 if ($no_dir_found && $no_file_found) {
1979
1980 ?>
1981 <tr>
1982 <td class="alert alert-info text-center mx-auto empty-dir-files" colspan="5">
1983 <strong><?php _e('Info!', 'wp-docs'); ?></strong> <?php _e('Empty Directory.', 'wp-docs'); ?>
1984 </td>
1985 </tr>
1986 <?php } ?>
1987 </table>
1988 </div>
1989 </div>
1990
1991 </div>
1992 <div class="card-footer text-right wpdocs-views position-relative">
1993
1994
1995
1996 <a data-source="large_icon_view" data-toggle="tooltip" data-placement="bottom" title="<?php _e('Thumbnails View', 'wp-docs'); ?>" class="folder_view_btn fa fa-image fa-lg text-danger mr-2"></a>
1997 <a data-source="list_view" data-toggle="tooltip" data-placement="bottom" title="<?php _e('List View', 'wp-docs'); ?>" class="folder_view_btn fa fa-bars fa-lg text-danger mr-2"></a>
1998 <a data-source="detail_view" data-toggle="tooltip" data-placement="bottom" title="<?php _e('Details Views', 'wp-docs'); ?>" class="folder_view_btn fa fa-list fa-lg text-danger mr-2"></a>
1999 </div>
2000 </div>
2001 <?php if($is_bootstrap): ?>
2002 <div class="wpdocs_loader wpd_modal d-none">
2003 <div class="modal_content">
2004 <img src="<?php echo esc_url($wpdocs_url.'img/loader.gif'); ?>" width="50px" height="50px">
2005 </div>
2006 </div>
2007 <?php endif; ?>
2008
2009 </div>
2010
2011
2012
2013 <?php
2014
2015
2016
2017 $out1 = ob_get_contents();
2018
2019 ob_end_clean();
2020
2021
2022
2023 return $out1;
2024
2025 }
2026
2027
2028 function wpdocs_parent_folder($id)
2029 {
2030 //pree($id);
2031 $parent_id = 0;
2032 if (wpdocs_folder_exists($id)) {
2033 $post_data = get_post($id);
2034 //pree($post_data);
2035 $parent_id = $post_data->post_parent;
2036 }
2037 return ($parent_id);
2038 }
2039
2040 function wpdocs_added_items_by_user($dir_id)
2041 {
2042 $current_user_items = array();
2043 if(!is_user_logged_in()){return array();}
2044
2045
2046
2047 $current_user = get_current_user_id();
2048
2049
2050
2051 if (is_numeric($dir_id) && $dir_id > 0 && wpdocs_folder_exists($dir_id)) {
2052 $wpdocs_items = get_post_meta($dir_id, 'wpdocs_items_by_user', true);
2053 //pree($wpdocs_items);
2054 $wpdocs_items = is_array(maybe_unserialize($wpdocs_items)) ? maybe_unserialize($wpdocs_items) : array();
2055
2056 $current_user_items = array_key_exists($current_user, $wpdocs_items) ? $wpdocs_items[$current_user] : array();
2057 //pree($wpdocs_items);
2058 //asort($wpdocs_items);
2059 }
2060 return $current_user_items;
2061 }
2062
2063 function wpdocs_added_items($dir_id)
2064 {
2065 $wpdocs_items = array();
2066 if (is_numeric($dir_id) && $dir_id > 0 && wpdocs_folder_exists($dir_id)) {
2067 $wpdocs_items = get_post_meta($dir_id, 'wpdocs_items', true);
2068 //pree($wpdocs_items);
2069 $wpdocs_items = is_array(maybe_unserialize($wpdocs_items)) ? maybe_unserialize($wpdocs_items) : array();
2070 //pree($wpdocs_items);
2071 //asort($wpdocs_items);
2072 }
2073 return $wpdocs_items;
2074 }
2075
2076 function wpdocs_folder_exists($ids='', $user_id=0)
2077 {
2078 //pree($id);
2079 //pree($ids);
2080 $posts_array = array();
2081
2082 $ids = explode(',', $ids);
2083 $ids = array_map('trim', $ids);
2084 $ids = array_filter($ids, 'is_numeric');
2085
2086 //pree($ids);exit;
2087 if (!empty($ids)) {
2088 global $wpdocs_post_types, $wpdocs_post_status;
2089 $ids = sanitize_wpdocs_data($ids);
2090 $args = array(
2091 'posts_per_page' => -1,
2092 'offset' => 0,
2093 'category' => '',
2094 'category_name' => '',
2095 'orderby' => 'title',
2096 'order' => 'ASC',
2097 'include' => $ids,
2098 'exclude' => '',
2099 'meta_key' => '',
2100 'meta_value' => '',
2101 'post_type' => $wpdocs_post_types,
2102 'post_mime_type' => '',
2103 'post_parent' => '',//$post_parent,
2104 'author' => ($user_id?$user_id:''),
2105 'author_name' => '',
2106 'post_status' => $wpdocs_post_status,
2107 'suppress_filters' => true
2108 );
2109 //pree($args);
2110 $posts_array = get_posts($args);
2111 }
2112 return (count($posts_array) > 0);
2113 }
2114
2115
2116
2117
2118 add_action('wp_ajax_wpdocs_update_folder', 'wpdocs_update_folder');
2119
2120 function wpdocs_update_folder() {
2121
2122
2123 if ( ! current_user_can('edit_posts') ) {
2124 wp_send_json_error(['msg' => __('Unauthorized access.', 'wp-docs')]);
2125 }
2126
2127
2128 if (
2129 empty($_POST['nonce']) ||
2130 ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'wpdocs_update_options_nonce')
2131 ) {
2132 wp_send_json_error(['msg' => __('Sorry, your nonce did not verify.', 'wp-docs')]);
2133 }
2134
2135
2136 $dir_id = absint($_POST['dir_id'] ?? 0);
2137 $resource_id = base64_decode(sanitize_text_field($_POST['resource_id'] ?? ''));
2138 $new_name = sanitize_text_field($_POST['new_name'] ?? '');
2139
2140 $ret = ['msg' => ''];
2141
2142 if ( $dir_id > 0 && $resource_id == $dir_id && wpdocs_folder_exists($dir_id) ) {
2143
2144 global $wpdb, $wpdocs_post_types, $wpdocs_post_status;
2145
2146 $updated = $wpdb->query(
2147 $wpdb->prepare(
2148 "UPDATE $wpdb->posts
2149 SET post_title = %s
2150 WHERE ID = %d
2151 AND post_type IN ('" . implode("','", array_map('esc_sql', $wpdocs_post_types)) . "')
2152 AND post_status = %s",
2153 htmlspecialchars_decode($new_name),
2154 $dir_id,
2155 $wpdocs_post_status
2156 )
2157 );
2158
2159 if ( $updated ) {
2160 $ret['msg'] = __('Successfully updated.', 'wp-docs');
2161 } else {
2162 $ret['msg'] = __('No changes were made. Input seems the same as before.', 'wp-docs');
2163 }
2164 } else {
2165 $ret['msg'] = __('Invalid folder ID or resource mismatch.', 'wp-docs');
2166 }
2167
2168 wp_send_json_success($ret);
2169 }
2170
2171
2172 add_action('wp_ajax_wpdocs_delete_folder', 'wpdocs_delete_folder');
2173
2174 function wpdocs_delete_folder()
2175 {
2176
2177 if ( ! current_user_can( 'manage_options' ) ) {
2178 wp_send_json_error( __( 'Unauthorized user', 'wp-docs' ) );
2179 wp_die();
2180 }
2181
2182 $nonce = sanitize_wpdocs_data(wp_unslash($_POST['nonce']));
2183
2184 if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) )
2185 die (__("Sorry, your nonce did not verify.", 'wp-docs'));
2186
2187 $dir_id = sanitize_wpdocs_data($_POST['dir_id']);
2188 $resource_id = base64_decode(sanitize_wpdocs_data($_POST['resource_id']));
2189
2190 if($dir_id==$resource_id){
2191 wpdocs_recursive_delete_folder($dir_id);
2192 }
2193
2194 exit;
2195 }
2196
2197
2198
2199 add_action('wp_ajax_wpdocs_delete_files', 'wpdocs_delete_files');
2200
2201
2202
2203 function wpdocs_recursive_delete_folder($dir_id){
2204 if ($dir_id > 0 && wpdocs_folder_exists($dir_id)) {
2205 $wpdocs_list = wpdocs_list($dir_id);
2206 if(!empty($wpdocs_list)){
2207 foreach($wpdocs_list as $wpdocs_item){
2208 //pree($wpdocs_item);
2209 if(is_numeric($wpdocs_item['id'])){
2210 wpdocs_recursive_delete_folder($wpdocs_item['id']);
2211 }
2212 }
2213 }
2214
2215 if(function_exists('wp_docs_relocate_memphis_meta')){
2216 wp_docs_relocate_memphis_meta($dir_id);
2217 }
2218
2219 wp_delete_post($dir_id, true);
2220 }
2221
2222 }
2223
2224
2225
2226 if(!function_exists('wpdocs_update_files_meta')){
2227
2228 function wpdocs_update_files_meta($dir_id, $files=array()){
2229
2230 if ($dir_id > 0 && wpdocs_folder_exists($dir_id) && count($files) > 0) {
2231
2232 //Items for single user
2233 $current_user = get_current_user_id();
2234 $wpdocs_items_by_user = get_post_meta($dir_id, 'wpdocs_items_by_user', true);
2235
2236
2237
2238 $wpdocs_items_by_user = $wpdocs_items_by_user && is_array($wpdocs_items_by_user) ? $wpdocs_items_by_user: array();
2239
2240
2241 $current_user_items = array_key_exists($current_user, $wpdocs_items_by_user) ? $wpdocs_items_by_user[$current_user] : array();
2242
2243
2244
2245
2246
2247 $current_user_items = array_merge($current_user_items, $files);
2248
2249
2250
2251
2252 $current_user_items = array_unique($current_user_items);
2253
2254
2255
2256 $wpdocs_items_by_user[$current_user] = $current_user_items;
2257
2258
2259
2260
2261 //overall items
2262
2263 $wpdocs_items = wpdocs_added_items($dir_id);
2264
2265 $wpdocs_items = array_merge($wpdocs_items, $files);
2266
2267 $wpdocs_items = array_unique($wpdocs_items);
2268
2269 //pree($wpdocs_items);
2270
2271 update_post_meta($dir_id, 'wpdocs_items_by_user', $wpdocs_items_by_user);
2272
2273 return update_post_meta($dir_id, 'wpdocs_items', $wpdocs_items);
2274 }
2275 }
2276 }
2277
2278
2279
2280 function wpdocs_delete_files()
2281 {
2282
2283 $dir_id = sanitize_wpdocs_data($_POST['dir_id']);
2284 $files = sanitize_wpdocs_data($_POST['files']);
2285 $files = is_array($files) ? $files : array($files);
2286 //pree($dir_id);pree($files);exit;
2287 if ($dir_id > 0 && wpdocs_folder_exists($dir_id) && count($files) > 0) {
2288
2289 wpdocs_del_items_by_user($dir_id, $files, get_current_user_id());
2290
2291
2292 $wpdocs_items = wpdocs_added_items($dir_id);
2293 //pree($wpdocs_items);
2294 $wpdocs_items = array_diff($wpdocs_items, $files);
2295 //pree($wpdocs_items);
2296 $wpdocs_items = array_unique($wpdocs_items);
2297
2298 //pree($wpdocs_items);
2299
2300 update_post_meta($dir_id, 'wpdocs_items', $wpdocs_items);
2301 }
2302
2303
2304 exit;
2305 }
2306
2307 function wpd_admin_footer(){
2308
2309 ?>
2310 <script type="text/javascript" language="javascript">
2311
2312 </script>
2313
2314 <?php
2315
2316 }
2317 add_action('admin_footer', 'wpd_admin_footer');
2318
2319 add_action('wp_ajax_wpdocs_update_option', 'wpdocs_update_option');
2320
2321 if(!function_exists('wpdocs_update_option')){
2322 function wpdocs_update_option(){
2323
2324 if ( ! current_user_can('manage_options') ) {
2325 wp_send_json_error('Insufficient permissions.');
2326 }
2327
2328 if (
2329 ! isset($_POST['wpdocs_update_option_nonce']) ||
2330 ! wp_verify_nonce($_POST['wpdocs_update_option_nonce'], 'wpdocs_update_options_nonce')
2331 ) {
2332 wp_send_json_error('Invalid nonce '.$_POST['wpdocs_update_option_nonce']);
2333 } else {
2334 //wp_send_json_success('Nonce valid!');
2335 }
2336
2337 $return = array(
2338
2339 'option_update' => false,
2340 'dir_move' => false,
2341 );
2342
2343
2344
2345 if(isset($_POST['wpdocs_options'])){
2346
2347 $wpdocs_options = isset($_POST['wpdocs_options']) ? sanitize_wpdocs_data($_POST['wpdocs_options']) : array();
2348
2349 $wpdocs_dir_id = isset($_POST['wpdocs_dir_id']) ? sanitize_wpdocs_data($_POST['wpdocs_dir_id']) : 0;
2350
2351
2352 $sanitized_option = sanitize_wpdocs_data($wpdocs_options);
2353 $sanitized_option['allowed_role'] = $sanitized_option['allowed_role'] !== 'empty' ? $sanitized_option['allowed_role'] : array();
2354
2355
2356 if($wpdocs_dir_id == 0){
2357
2358 $update = update_option('wpdocs_options', $sanitized_option);
2359
2360 }else{
2361
2362 $update = update_post_meta($wpdocs_dir_id, '_wpdocs_dir_options', $sanitized_option);
2363 $child_dir_list = wpdoc_get_dir_children($wpdocs_dir_id);
2364 if(!empty($child_dir_list)){
2365 foreach ($child_dir_list as $child_dir) {
2366
2367 $update = update_post_meta($child_dir, '_wpdocs_dir_options', $sanitized_option);
2368
2369 # code...
2370 }
2371 }
2372
2373
2374
2375 }
2376 }
2377
2378
2379
2380 if(isset($_POST['wpdocs_move_selected_dir'])){
2381
2382 $wpdocs_move_selected_dir = sanitize_wpdocs_data($_POST['wpdocs_move_selected_dir']);
2383 $action_type = $wpdocs_move_selected_dir['action_type'];
2384
2385
2386 $is_file = array_key_exists('is_file', $wpdocs_move_selected_dir) ? $wpdocs_move_selected_dir['is_file']: false;
2387 $is_file = $is_file == 'false' ? false: true;
2388
2389
2390 if(!$is_file && array_key_exists('dir_selected', $wpdocs_move_selected_dir) &&
2391 array_key_exists('dir_id', $wpdocs_move_selected_dir)){
2392
2393 switch($action_type){
2394 default:
2395 case 'move':
2396
2397
2398 $update = wp_update_post(
2399 array(
2400 'ID' => $wpdocs_move_selected_dir['dir_selected'],
2401 'post_parent' => $wpdocs_move_selected_dir['dir_id']
2402 )
2403 );
2404
2405 if($update == $wpdocs_move_selected_dir['dir_selected']){
2406 $return['dir_move'] = true;
2407 }
2408
2409 break;
2410
2411 case 'copy':
2412 $existing_dir = get_post($wpdocs_move_selected_dir['dir_selected']);
2413 $existing_dir = (is_object($existing_dir)?(array)$existing_dir:array());
2414 if(!empty($existing_dir) && array_key_exists('ID', $existing_dir) && function_exists('wpdocs_recursive_copy_folder')){
2415
2416 wpdocs_recursive_copy_folder($wpdocs_move_selected_dir['dir_id'], $existing_dir);
2417
2418 $return['dir_move'] = true;
2419
2420 }
2421
2422
2423 break;
2424 }
2425
2426
2427
2428 }
2429 //exit;
2430
2431 if($is_file){
2432
2433 $file_id = $wpdocs_move_selected_dir['files'];
2434
2435 $current_dir = $wpdocs_move_selected_dir['file_dir'];
2436
2437 $new_dir = $wpdocs_move_selected_dir['dir_id'];
2438
2439 $files = wpdocs_added_items($current_dir);
2440
2441 $file_id = is_array($file_id) ? $file_id : array($file_id);
2442 $files = array_diff($files, $file_id);
2443
2444
2445 switch($action_type){
2446 default:
2447 case 'move':
2448
2449 update_post_meta($current_dir, 'wpdocs_items', $files);
2450
2451 break;
2452
2453 case 'copy':
2454
2455 break;
2456
2457 }
2458
2459 $update = wpdocs_update_files_meta($new_dir, $file_id);
2460
2461 if($update === true){
2462 $return['dir_move'] = true;
2463 }
2464
2465 }
2466 }
2467
2468 echo wp_json_encode($return);
2469
2470
2471 wp_die();
2472
2473 }
2474 }
2475
2476
2477
2478 if(!function_exists('wpdocs_dir_list_complete')){
2479
2480 function wpdocs_dir_list_complete($dir = 0){
2481
2482 $wpdocs_list = wpdocs_list($dir);
2483
2484 if(!empty($wpdocs_list)){
2485
2486 $wp_dir_child = array();
2487
2488 foreach ($wpdocs_list as $index => $wp_dir){
2489
2490 if(!array_key_exists('id', $wp_dir)) continue;
2491 $wpdocs_list_child = wpdocs_list($wp_dir['id']);
2492
2493 if(!empty($wpdocs_list_child)){
2494
2495 $wp_dir['child_dir'] = wpdocs_dir_list_complete($wp_dir['id']);
2496
2497 }
2498
2499 $wp_dir_child[] = $wp_dir;
2500
2501
2502 }
2503
2504 return $wp_dir_child;
2505
2506 }else{
2507
2508 return array();
2509 }
2510 }
2511 }
2512
2513 if(!function_exists('wpdocs_dir_list_option')){
2514
2515 function wpdocs_dir_list_option($dir = 0, $str = ' __ ', $level = 0){
2516
2517
2518 $wpdocs_list = wpdocs_list($dir);
2519
2520 $option = '';
2521
2522 if(!empty($wpdocs_list)){
2523
2524
2525 foreach ($wpdocs_list as $index => $wp_dir){
2526
2527 if(!array_key_exists('id', $wp_dir)) continue;
2528 $wpdocs_list_child = wpdocs_list($wp_dir['id']);
2529
2530 $option .= '<option value="'.esc_attr($wp_dir['id']).'" data-parent="'.esc_attr($dir).'">'.str_repeat(str_replace(' ', '&nbsp;', $str), $level).esc_html($wp_dir['title']).'</option>';
2531
2532
2533 if(!empty($wpdocs_list_child)){
2534
2535
2536 $option .= wpdocs_dir_list_option($wp_dir['id'], $str, $level+1);
2537
2538 }
2539
2540 }
2541
2542
2543 }
2544
2545 return $option;
2546 }
2547 }
2548
2549 add_action('wpdocs_before_docs_list', 'wpdocs_add_breadcrumb');
2550
2551 if(!function_exists('wpdocs_add_breadcrumb')){
2552
2553 function wpdocs_add_breadcrumb($dir_id, $breadcrumb=true){
2554
2555
2556
2557 $breadcrumb_array = wpdocs_get_breadcrumb_array($dir_id, $breadcrumb);
2558 $get_permalink = admin_url('options-general.php?page=wpdocs');
2559
2560 if (!empty($breadcrumb_array)) {
2561 ?>
2562
2563 <nav aria-label="breadcrumb" class="wpdocs-nav">
2564 <ol class="breadcrumb bg-light" style="border-bottom:1px solid #dee2e6;border-radius: 0;">
2565
2566 <li class="breadcrumb-item bread_home_url"><a class="wpd_bread_item" href="<?php echo esc_url($get_permalink); ?>" data-id="0"><?php _e('Home', 'wp-docs'); ?></a></li>
2567 <?php
2568
2569 foreach (array_reverse($breadcrumb_array) as $bread_key => $bread_value) {
2570 $active = '';
2571 $page = '';
2572
2573 $link = '<a class="wpd_bread_item" href="' . $get_permalink .'&dir=' . $bread_value . '" data-id="'.$bread_value.'" >' . get_the_title($bread_value) . '</a>';
2574 if ($bread_value == 0) {
2575 continue;
2576 }
2577 if ($bread_value == $dir_id) {
2578 $active = 'active';
2579 $page = 'page';
2580 $link = get_the_title($bread_value);
2581 }
2582
2583
2584 ?>
2585 <li class="breadcrumb-item <?php echo esc_attr($active); ?>" aria-current="<?php echo esc_attr($page); ?>"><?php echo ($link); ?></li>
2586
2587 <?php
2588 }
2589
2590 ?>
2591
2592 </ol>
2593
2594 </nav>
2595
2596 <?php
2597
2598 }
2599 }
2600 }
2601
2602 add_action('wp_ajax_wpdocs_update_view', 'wpdocs_update_view');
2603 add_action('wp_ajax_nopriv_wpdocs_update_view', 'wpdocs_update_view');
2604
2605 if(!function_exists('wpdocs_update_view')){
2606 function wpdocs_update_view(){
2607
2608 $nonce = sanitize_wpdocs_data(wp_unslash($_POST['nonce']));
2609
2610 if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) )
2611 die (__("Sorry, your nonce did not verify.", 'wp-docs'));
2612
2613 if(isset($_POST['update_view'])){
2614
2615 $wpdocs_view = get_option('wpdocs_view', array());
2616 $wpdocs_view = is_array($wpdocs_view) ? $wpdocs_view : array();
2617 $parent_dir = sanitize_wpdocs_data($_POST['parent_dir']);
2618
2619 $wpdocs_view[$parent_dir] = sanitize_wpdocs_data($_POST['update_view']);
2620 update_option('wpdocs_view', $wpdocs_view);
2621
2622 }
2623 exit;
2624 }
2625 }
2626 function wpdocs_init_session() {
2627 if(!session_id()) {
2628 session_start();
2629 }
2630 }
2631
2632 //add_action('init', 'wpdocs_init_session', 1);
2633
2634 if(!function_exists('wpdocs_create_dir')){
2635 function wpdocs_create_dir($dir_id, $parent_path){
2636
2637
2638 if(!file_exists($parent_path)){
2639 mkdir($parent_path);
2640 }
2641
2642 $current_dir_name = 'wpdocs';
2643
2644 if($dir_id != 0){
2645
2646 $current_dir = get_post($dir_id);
2647 $current_dir_name = $current_dir->post_title;
2648 }
2649
2650 $current_dir_temp = $parent_path.'/'.$current_dir_name;
2651
2652 if(!is_dir($current_dir_temp))
2653 mkdir($current_dir_temp);
2654
2655 return $current_dir_temp;
2656 }
2657 }
2658
2659 if(!function_exists('wpdocs_copy_files')){
2660 function wpdocs_copy_files($wpdocs_items, $current_dir_temp){
2661
2662 //pre($wpdocs_items);
2663
2664 $upload_dir = wp_upload_dir();
2665
2666 if(!empty($wpdocs_items)){
2667 foreach ($wpdocs_items as $item_id){
2668 //pre($item_id);
2669 //pre(get_post_meta($item_id));
2670 $attached_file = get_post_meta($item_id, '_wp_attached_file', true);
2671 //pre($attached_file);
2672
2673 $absolute_path = false;
2674
2675 if(!$attached_file){
2676 $attached_post = get_post($item_id);
2677 $attached_file = $attached_post->guid;
2678 $absolute_path = true;
2679 }
2680
2681
2682 $file_name = basename($attached_file);
2683 $file_copy_path = $current_dir_temp.'/'.$file_name;
2684
2685 if($absolute_path){
2686 $file_path = str_replace($upload_dir['baseurl'], $upload_dir['basedir'], $attached_file);
2687 }else{
2688 $file_path = $upload_dir['basedir'].'/'.$attached_file;
2689 }
2690
2691 //pre($file_path);
2692
2693 if(!is_dir($file_path) && file_exists($file_path)){
2694 copy($file_path, $file_copy_path);
2695 }
2696 }
2697 }
2698
2699 //exit;
2700
2701 }
2702 }
2703
2704 if(!function_exists('wpdocs_create')){
2705 function wpdocs_create($dir_id, $wpdocs_dir){
2706
2707 //pree($dir_id);
2708
2709 $wpdocs_list = wpdocs_list($dir_id);
2710 //pre($wpdocs_list);
2711 $wpdocs_items = wpdocs_added_items($dir_id);
2712 //pre($wpdocs_items);
2713
2714 $current_dir_temp = wpdocs_create_dir($dir_id, $wpdocs_dir);
2715
2716 //pree($current_dir_temp);
2717 //exit;
2718
2719 wpdocs_copy_files($wpdocs_items, $current_dir_temp);
2720
2721 if(!empty($wpdocs_list)){
2722 foreach ($wpdocs_list as $single_dir){
2723
2724 wpdocs_create($single_dir['id'], $current_dir_temp);
2725 }
2726 }
2727
2728 }
2729
2730 }
2731
2732 if(!function_exists('wpdocs_generate_zip')){
2733
2734 function wpdocs_generate_zip($source, $destination)
2735 {
2736
2737 // Initialize archive object
2738 $zip = new ZipArchive();
2739 $zip->open($destination, ZipArchive::CREATE | ZipArchive::OVERWRITE);
2740
2741
2742 // Create recursive directory iterator
2743 /** @var SplFileInfo[] $files */
2744 $files = new RecursiveIteratorIterator(
2745 new RecursiveDirectoryIterator($source),
2746 RecursiveIteratorIterator::SELF_FIRST
2747 );
2748
2749 //pre($files);
2750
2751 if (!empty($files)) {
2752 foreach ($files as $name => $file) {
2753
2754
2755 $file_path = $file->getRealPath();
2756 $relative_path = substr($file_path, strlen($source) + 1);
2757 /*
2758 if (!$file->isDir()) {
2759 // Get real and relative path for current file
2760
2761
2762
2763 // Add current file to archive
2764 $zip->addFile($file_path, $relative_path);
2765 }
2766 */
2767
2768 if (is_dir($file_path) === true) {
2769 $zip->addEmptyDir(str_replace($source . '/', '', $relative_path . '/'));
2770 } elseif (is_file($file) === true) {
2771 $zip->addFromString(str_replace($source . '/', '', $relative_path), file_get_contents($file_path));
2772 }
2773 }
2774 }
2775
2776
2777
2778 // Zip archive will be created only after closing object
2779 $zip->close();
2780
2781 $ret = str_replace('\\', '/', $destination);
2782
2783 $url = str_replace(get_home_path(), get_home_url().'/', $ret);
2784
2785 $resp = array(
2786 'url' => $url,
2787 'path' => $destination,
2788 );
2789
2790 //pree($resp);exit;
2791
2792 return $resp;
2793
2794 }
2795
2796 }
2797
2798 if(!function_exists('wpdocs_download_zip')){
2799 function wpdocs_download_zip($dir_id){
2800
2801 $upload_dir = wp_upload_dir();
2802 $upload_dir = $upload_dir['basedir'];
2803 $wpdocs_dir = $upload_dir.'/wpdocs';
2804 $current_dir_temp = wpdocs_create_dir($dir_id, $wpdocs_dir);
2805 wpdocs_create($dir_id, $wpdocs_dir);
2806
2807 $dest = $wpdocs_dir.'/'.basename($current_dir_temp).'.zip';
2808
2809 //pre($current_dir_temp);pre($dest);
2810 //exit;
2811
2812 $ret = wpdocs_generate_zip($current_dir_temp, $dest);
2813
2814 //pree($ret);
2815 if(isset($_GET['debug'])){
2816 exit;
2817 }
2818
2819 return $ret;
2820
2821 }
2822 }
2823 if(!function_exists('wpdocs_file_download')){
2824 function wpdocs_file_download(){
2825
2826 if(empty($_GET['wpdocs_dl'])){
2827 return;
2828 }
2829
2830 $file_id = absint(
2831 wp_unslash($_GET['wpdocs_dl'])
2832 );
2833
2834 if(!$file_id){
2835 status_header(404);
2836 exit;
2837 }
2838
2839 $nonce = isset($_GET['wpdocs_nonce'])
2840 ? sanitize_text_field(
2841 wp_unslash($_GET['wpdocs_nonce'])
2842 )
2843 : '';
2844
2845 if(
2846 !wp_verify_nonce(
2847 $nonce,
2848 'wpdocs_dl_' . $file_id
2849 )
2850 ){
2851 status_header(403);
2852 exit;
2853 }
2854
2855 // Adjust this according to where you store the file
2856 $file = get_attached_file($file_id);
2857
2858 if(
2859 !$file ||
2860 !file_exists($file)
2861 ){
2862 status_header(404);
2863 exit;
2864 }
2865
2866 $uploads = wp_get_upload_dir();
2867 $base_real = realpath($uploads['basedir']);
2868 $file_real = realpath($file);
2869
2870 if(
2871 !$base_real ||
2872 !$file_real ||
2873 strpos(
2874 $file_real,
2875 $base_real . DIRECTORY_SEPARATOR
2876 ) !== 0
2877 ){
2878 status_header(403);
2879 exit;
2880 }
2881
2882 $mime = wp_check_filetype($file_real);
2883 $mime = !empty($mime['type'])
2884 ? $mime['type']
2885 : 'application/octet-stream';
2886
2887 header('Content-Type: ' . $mime);
2888 header('Content-Length: ' . filesize($file_real));
2889 header(
2890 'Content-Disposition: inline; filename="' .
2891 basename($file_real) .
2892 '"'
2893 );
2894
2895 readfile($file_real);
2896 exit;
2897 }
2898 }
2899
2900 add_action('init', 'wpdocs_dir_actions');
2901 if(!function_exists('wpdocs_dir_actions')){
2902 function wpdocs_dir_actions(){
2903
2904 wpdocs_file_download();
2905
2906 if(is_admin() && get_option('wpdocs_memphis_uninstall')){
2907 if(wp_docs_memphis_folder_preserve('mdocs_2', 'mdocs')){
2908 update_option('wpdocs_memphis_uninstall', false);
2909 }
2910 }
2911
2912 if(isset($_GET['wpdocs_dir']) && is_numeric($_GET['wpdocs_dir']) && isset($_GET['wpdocs_wpnonce']) && wp_verify_nonce( sanitize_wpdocs_data(wp_unslash($_GET['wpdocs_wpnonce'])), "wpdocs-{$_GET['wpdocs_dir']}" )){
2913
2914 //pree($_GET);exit;
2915
2916 if(isset($_GET['download'])){
2917
2918 $wpdocs_clear_clutter = get_option('wpdocs_clear_clutter', array());
2919 $wpdocs_clear_clutter = (is_array($wpdocs_clear_clutter)?$wpdocs_clear_clutter:array());
2920 if(!empty($wpdocs_clear_clutter)){
2921 foreach($wpdocs_clear_clutter as $i=>$wpdocs_clear_clutter_iter){
2922
2923 if(is_array($wpdocs_clear_clutter_iter)){
2924
2925 list($rm_dir, $zip_path) = $wpdocs_clear_clutter_iter;
2926 unlink($zip_path);
2927
2928 if (is_dir($rm_dir)) {
2929 $dir = new RecursiveDirectoryIterator($rm_dir, RecursiveDirectoryIterator::SKIP_DOTS);
2930 foreach (new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST ) as $filename => $file) {
2931 if (is_file($filename))
2932 unlink($filename);
2933 else
2934 rmdir($filename);
2935 }
2936 rmdir($rm_dir); // Now remove myfolder
2937 }
2938 }
2939
2940 unset($wpdocs_clear_clutter[$i]);
2941 }
2942 update_option('wpdocs_clear_clutter', $wpdocs_clear_clutter);
2943 }
2944
2945
2946
2947 $wpdocs_dir = sanitize_wpdocs_data($_GET['wpdocs_dir']);
2948 //pree($wpdocs_dir);exit;
2949 $zip = wpdocs_download_zip($wpdocs_dir);
2950 $rm_dir = str_replace('.zip', '',$zip['path'] );
2951 //pree($rm_dir);exit;
2952 //pree($wpdocs_dir);pree($rm_dir);pree($zip);exit;
2953 if(file_exists($zip['path'])){
2954
2955 $wpdocs_clear_clutter = get_option('wpdocs_clear_clutter', array());
2956 $wpdocs_clear_clutter = (is_array($wpdocs_clear_clutter)?$wpdocs_clear_clutter:array());
2957 $wpdocs_clear_clutter[] = array($rm_dir, $zip['path']);
2958 update_option('wpdocs_clear_clutter', $wpdocs_clear_clutter);
2959
2960 //echo $rm_dir;exit;
2961
2962
2963
2964
2965 //echo $zip['path'];exit;
2966
2967
2968 header("Content-type: application/zip");
2969 header("Content-Disposition: attachment; filename=".basename($zip['path'])."");
2970 header("Pragma: no-cache");
2971 header("Expires: 0");
2972 header("Content-length: " . @filesize($zip['path']));
2973 //readfile($zip['path']);
2974
2975 wp_redirect($zip['url']);exit;
2976
2977
2978
2979 }else{
2980 wp_redirect(admin_url('options-general.php?page=wpdocs'));exit;
2981 }
2982
2983 }
2984
2985 if(isset($_GET['clear'])){
2986 global $wpdocs_url, $wpdb, $wpdocs_post_types;
2987 update_option('wpdocs_options', array());
2988 $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->posts WHERE post_type IN ('".implode("','", $wpdocs_post_types)."')"));
2989 wp_redirect(admin_url('options-general.php?page=wpdocs'));exit;
2990 }
2991
2992
2993 }
2994
2995 }
2996
2997 }
2998
2999 function wpdocs_plugin_links($links) {
3000 global $wpdocs_premium_link, $wpdocs_pro;
3001
3002 $settings_link = '<a href="options-general.php?page=wpdocs">'.__('Settings', 'wp-docs').'</a>';
3003
3004 if($wpdocs_pro){
3005 array_unshift($links, $settings_link);
3006 }else{
3007
3008 $wpdocs_premium_link = '<a href="'.esc_url($wpdocs_premium_link).'" title="'.__('Go Premium', 'wp-docs').'" target="_blank">'.__('Go Premium', 'wp-docs').'</a>';
3009 array_unshift($links, $settings_link, $wpdocs_premium_link);
3010
3011 }
3012
3013
3014 return $links;
3015 }
3016
3017 if(!function_exists('wpdocs_get_current_user_items')){
3018
3019 function wpdocs_get_current_user_items($dir_id, $current_user_id){
3020
3021 $current_user_files = array();
3022
3023 if ($dir_id > 0 && wpdocs_folder_exists($dir_id)) {
3024
3025 $wpdocs_items_by_user = get_post_meta($dir_id, 'wpdocs_items_by_user', true);
3026 $wpdocs_items_by_user = is_array($wpdocs_items_by_user)?$wpdocs_items_by_user:array();
3027 $current_user_files = array_key_exists($current_user_id, $wpdocs_items_by_user) ? $wpdocs_items_by_user[$current_user_id] : array();
3028
3029 }
3030
3031 return $current_user_files;
3032
3033 }
3034 }
3035
3036
3037
3038
3039
3040 if(!function_exists('wpdocs_is_file_belong_to_user')){
3041
3042 function wpdocs_is_file_belong_to_user($dir_id, $files, $current_user_id){
3043
3044
3045 if ($dir_id > 0 && wpdocs_folder_exists($dir_id) && count($files) > 0) {
3046
3047
3048 $current_user_files = wpdocs_get_current_user_items($dir_id, $current_user_id);
3049 $current_user_updated_items = array_intersect($current_user_files, $files);
3050
3051 return !empty($current_user_updated_items);
3052
3053
3054 }else{
3055
3056 return false;
3057
3058 }
3059
3060 }
3061 }
3062
3063
3064
3065
3066
3067
3068 if(!function_exists('wpdocs_del_items_by_user')){
3069 function wpdocs_del_items_by_user($dir_id, $files, $current_user_id){
3070
3071
3072 if ($dir_id > 0 && wpdocs_folder_exists($dir_id) && count($files) > 0) {
3073
3074
3075 $wpdocs_items_by_user = get_post_meta($dir_id, 'wpdocs_items_by_user', true);
3076 $current_user_files = wpdocs_get_current_user_items($dir_id, $current_user_id);
3077
3078
3079
3080 $current_user_updated_items = array_diff($current_user_files, $files);
3081
3082
3083
3084 $current_user_updated_items = array_unique($current_user_updated_items);
3085
3086
3087
3088
3089 $wpdocs_items_by_user[$current_user_id] = $current_user_updated_items;
3090
3091
3092
3093 $wpdocs_items_by_user = array_filter($wpdocs_items_by_user);
3094
3095
3096 return update_post_meta($dir_id, 'wpdocs_items_by_user', $wpdocs_items_by_user);
3097
3098 }else{
3099 return false;
3100 }
3101
3102 }
3103 }
3104
3105 add_action('wp_ajax_wp_docs_import_memphis_docs', 'wp_docs_import_memphis_docs');
3106
3107 if(!function_exists('wp_docs_import_memphis_docs')){
3108 function wp_docs_import_memphis_docs(){
3109
3110 $result_array = array(
3111 'status' => false,
3112 );
3113
3114 if(!empty($_POST) && isset($_POST['wp_docs_nonce'])){
3115
3116 if (!wp_verify_nonce( sanitize_wpdocs_data(wp_unslash($_POST['wp_docs_nonce'])), 'wpdocs_update_options_nonce' ) ){
3117
3118 wp_die(__("Sorry, your nonce did not verify.", 'wp-docs'));
3119
3120 }else{
3121
3122 $dir_progress = wp_docs_import_memphis_directories();
3123 $file_progress = wp_docs_memphis_import_files();
3124
3125 $result_array['status'] = ($dir_progress || $file_progress);
3126
3127 if($result_array['status']){
3128 wp_docs_whiteflag_memphis_htaccess();
3129 }
3130
3131 if(!$dir_progress && !$file_progress){
3132
3133 $result_array['remarks'] = __('No directories and files found.', 'wp-docs');
3134 }
3135
3136 }
3137
3138 }
3139
3140 wp_send_json($result_array);
3141 }
3142 }
3143
3144 add_action('wp_ajax_wp_docs_import_memphis_rollback', 'wp_docs_import_memphis_rollback');
3145
3146 if(!function_exists('wp_docs_import_memphis_rollback')){
3147 function wp_docs_import_memphis_rollback(){
3148
3149 $result_array = array(
3150 'status' => false,
3151 );
3152
3153 if(!empty($_POST) && isset($_POST['wp_docs_nonce'])){
3154
3155 if (!wp_verify_nonce( sanitize_wpdocs_data(wp_unslash($_POST['wp_docs_nonce'])), 'wpdocs_update_options_nonce' ) ){
3156
3157 wp_die(__("Sorry, your nonce did not verify.", 'wp-docs'));
3158
3159 }else{
3160
3161 wp_docs_rollback_memphis_import();
3162 $result_array['status'] = true;
3163 }
3164
3165 }
3166
3167 wp_send_json($result_array);
3168 }
3169 }
3170
3171 if(!function_exists('wp_docs_get_memphis_name')){
3172 function wp_docs_get_memphis_name(){
3173 global $wpdb;
3174 $name = esc_sql('Memphis Documents');
3175
3176 $query = $wpdb->prepare("SELECT max(ID) FROM $wpdb->posts WHERE post_title LIKE '%$name%'");
3177
3178 $result = $wpdb->get_var($query);
3179 if($result){
3180
3181 $post = get_post($result);
3182
3183 $title_array = explode(' ', $post->post_title);
3184 $last_elment = end($title_array);
3185
3186 if(is_numeric($last_elment)){
3187 $last_elment++;
3188 }else{
3189 $last_elment = 1;
3190 }
3191
3192 $name .= ' '.$last_elment;
3193
3194 }
3195
3196
3197 return $name;
3198 }
3199 }
3200
3201 if(!function_exists('wp_docs_get_memphis_dir_id')){
3202 function wp_docs_get_memphis_dir_id(){
3203 global $wpdb;
3204
3205 $name = esc_sql('Memphis Documents');
3206
3207 $dir_id = 0;
3208
3209 $query = $wpdb->prepare("SELECT max(ID) FROM $wpdb->posts WHERE post_title LIKE '%$name%'");
3210
3211 $result = $wpdb->get_var($query);
3212 if($result){
3213 $dir_id = $result;
3214 }
3215
3216
3217 return $dir_id;
3218 }
3219 }
3220
3221 if(!function_exists('wp_docs_import_memphis_directories')){
3222
3223 function wp_docs_import_memphis_directories(){
3224 global $wp_docs_is_memphis;
3225
3226 $progress_status = false;
3227
3228 if(!$wp_docs_is_memphis){
3229
3230 }else{
3231
3232 $memphis_folders_array = get_option('mdocs-cats', array());
3233
3234 if(!empty($memphis_folders_array)){
3235
3236 extract(wp_docs_count_memphis_folder($memphis_folders_array));
3237
3238 if($import_folder_count != $total_folder_count){
3239
3240 $parent_id = wp_docs_get_memphis_dir_id();
3241 if($parent_id == 0){
3242
3243 $parent_id = wpdocs_create_folder_post(0, 'Memphis Documents');
3244 }
3245 wp_docs_memphis_create_directory($memphis_folders_array, $parent_id);
3246
3247 $progress_status = true;
3248
3249 }
3250
3251 }
3252
3253 }
3254
3255 return $progress_status;
3256 }
3257
3258 }
3259
3260 if(!function_exists('wp_docs_memphis_create_directory')){
3261
3262 function wp_docs_memphis_create_directory($directory_list, $base_parent_id){
3263 global $wp_docs_is_memphis, $wpdocs_imported_folder, $memphis_folders_id;
3264 if(!$wp_docs_is_memphis){
3265
3266 }else{
3267
3268
3269 if(!empty($directory_list)){
3270
3271 foreach ($directory_list as $key => $single_directory) {
3272 # code...
3273
3274 $slug = $single_directory['slug'];
3275 $name = $single_directory['name'];
3276 $child_dir_list = $single_directory['children'];
3277 $slug_key = $memphis_folders_id.'_'.$slug;
3278
3279 if(in_array($slug_key, $wpdocs_imported_folder)) continue;
3280 $current_parent_id = wpdocs_create_folder_post($base_parent_id, $name);
3281 if($current_parent_id){
3282
3283 update_post_meta($current_parent_id, '_wpdocs_memphis_slug', $slug_key);
3284 $wpdocs_imported_folder[] = $slug_key;
3285 if(!empty($child_dir_list)){
3286 wp_docs_memphis_create_directory($child_dir_list, $current_parent_id);
3287 }
3288
3289 }
3290
3291 }
3292
3293 update_option('wpdocs_imported_folder', $wpdocs_imported_folder);
3294 }
3295
3296 }
3297 }
3298
3299 }
3300
3301
3302 if(!function_exists('wp_docs_count_memphis_folder')){
3303 function wp_docs_count_memphis_folder($memphis_folders, $total_folder_count = 0, $import_folder_count = 0){
3304 global $memphis_folders_id, $wpdocs_imported_folder;
3305
3306 if(!empty($memphis_folders)){
3307 foreach ($memphis_folders as $key => $folder) {
3308 # code...
3309 $children = $folder['children'];
3310 $slug = $folder['slug'];
3311 $slug_key = $memphis_folders_id.'_'.$slug;
3312 $total_folder_count++;
3313
3314 if(in_array($slug_key, $wpdocs_imported_folder)){
3315 $import_folder_count++;
3316 }
3317
3318 if(!empty($children)){
3319 extract(wp_docs_count_memphis_folder($children, $total_folder_count, $import_folder_count));
3320 }
3321 }
3322 }
3323
3324 return array('total_folder_count' => $total_folder_count, 'import_folder_count' => $import_folder_count);
3325
3326 }
3327 }
3328
3329 if(!function_exists('wp_docs_count_memphis_files')){
3330 function wp_docs_count_memphis_files(){
3331
3332 global $memphis_files_array, $wpdocs_imported_files, $wpdocs_memphis_list;
3333
3334 $total_file_count = (count($memphis_files_array) + count($wpdocs_memphis_list));
3335
3336 return array('total_file_count' => $total_file_count, 'import_file_count' => count($wpdocs_memphis_list));
3337
3338 }
3339 }
3340
3341 if(!function_exists('wp_docs_memphis_statistics')){
3342 function wp_docs_memphis_statistics(){
3343 global $memphis_folders_array;
3344 //pree($memphis_folders_array);
3345 extract(wp_docs_count_memphis_folder($memphis_folders_array));
3346 extract(wp_docs_count_memphis_files());
3347
3348 return array(
3349 'total_folder' => $total_folder_count,
3350 'import_folder' => $import_folder_count,
3351 'total_files' => $total_file_count,
3352 'import_files' => $import_file_count,
3353 );
3354
3355 }
3356 }
3357
3358
3359 if(!function_exists('wp_docs_relocate_memphis_meta')){
3360 function wp_docs_relocate_memphis_meta($dir_id){
3361 global $wpdocs_imported_files, $wpdocs_imported_folder;
3362
3363 // Ensure arrays are initialized properly before using them
3364 $wpdocs_imported_files = (is_array($wpdocs_imported_files) ? $wpdocs_imported_files : array());
3365 $wpdocs_imported_folder = (is_array($wpdocs_imported_folder) ? $wpdocs_imported_folder : array());
3366
3367 $wpdocs_items = get_post_meta($dir_id, 'wpdocs_items', true);
3368 $wpdocs_items = (is_array($wpdocs_items) ? $wpdocs_items : array());
3369 $dir_slug = get_post_meta($dir_id, '_wpdocs_memphis_slug', true);
3370
3371 if(!empty($wpdocs_items)){
3372 $wpdocs_imported_files = array_diff($wpdocs_imported_files, $wpdocs_items);
3373 }
3374
3375 if($dir_slug){
3376 $wpdocs_imported_folder = array_diff($wpdocs_imported_folder, array($dir_slug));
3377 }
3378
3379 update_option('wpdocs_imported_folder', $wpdocs_imported_folder);
3380 update_option('wpdocs_imported_files', $wpdocs_imported_files);
3381 }
3382 }
3383
3384
3385 if(!function_exists('wp_docs_memphis_import_files')){
3386 function wp_docs_memphis_import_files(){
3387 global $memphis_folders_id, $memphis_files_array, $wpdocs_imported_files, $wpdocs_memphis_list, $wpdocs_post_types;
3388
3389 $before_count = count($wpdocs_imported_files);
3390 if(!empty($memphis_files_array)){
3391
3392 foreach($memphis_files_array as $file_index => $file_data){
3393 $attachment_id = $file_data['id'];
3394 $attachment_folder = $file_data['cat'];
3395 $slug_key = $memphis_folders_id.'_'.$attachment_folder;
3396 $files = array($attachment_id);
3397 $upload_dir = wp_upload_dir();
3398 $upload_base_url = $upload_dir['baseurl'];
3399
3400 if(in_array($attachment_id, $wpdocs_imported_files)){continue;}
3401
3402 $dir_arg = array(
3403 'post_type' => $wpdocs_post_types,
3404 'numberposts' => '-1',
3405 'post_status' => 'any',
3406 'fields' => 'ids',
3407 'meta_query' => array(
3408 array(
3409 'key' => '_wpdocs_memphis_slug',
3410 'value' => $slug_key,
3411 'compare' => '='
3412 )
3413 )
3414 );
3415
3416 $dir_list = get_posts($dir_arg);
3417
3418 if(!empty($dir_list)){
3419 foreach($dir_list as $dir_id){
3420 update_post_meta($attachment_id, '_wpdocs_memphis_media_file', true);
3421 update_post_meta($attachment_id, '_wpdocs_memphis_file_id', $file_data['id']);
3422
3423 $wpdocs_imported_files[] = $attachment_id;
3424 wpdocs_update_files_meta($dir_id, $files);
3425 }
3426 unset($memphis_files_array[$file_index]);
3427 $wpdocs_memphis_list[] = $file_data;
3428 }
3429 }
3430
3431 update_option('mdocs-list', $memphis_files_array);
3432 update_option('wpdocs_memphis_list', $wpdocs_memphis_list);
3433 update_option('wpdocs_imported_files', $wpdocs_imported_files);
3434 }
3435 $after_count = count($wpdocs_imported_files);
3436
3437 return ($before_count != $after_count);
3438 }
3439 }
3440
3441
3442 add_filter('pre_delete_attachment', 'wpdocs_delete_attachment_callback', 10, 3);
3443
3444 if(!function_exists('wpdocs_delete_attachment_callback')){
3445 function wpdocs_delete_attachment_callback($check, $post, $force_delete){
3446
3447 $wpdoc_memphis_media_file = get_post_meta($post->ID, '_wpdocs_memphis_media_file', true);
3448 $is_memphis_media = strpos($post->post_content, 'mdocs_media_attachment');
3449
3450 if($wpdoc_memphis_media_file && $is_memphis_media){
3451 $post->post_content = '';
3452 wp_update_post($post);
3453 return $post;
3454 }else{
3455 return $check;
3456 }
3457
3458 }
3459 }
3460
3461 add_action('pre_uninstall_plugin', 'wp_docs_save_attachments_to_del');
3462
3463 if(!function_exists('wp_docs_save_attachments_to_del')){
3464
3465 function wp_docs_save_attachments_to_del($plugin){
3466
3467 global $wpdocs_imported_folder, $wpdocs_imported_files, $wpdocs_memphis_list;
3468
3469 $wpdocs_memphis_list = get_option('wpdocs_memphis_list', array());
3470
3471
3472 if($plugin == 'memphis-documents-library/memphis-documents.php'){
3473 if(!empty($wpdocs_memphis_list)){
3474 if(wp_docs_memphis_folder_preserve('mdocs', 'mdocs_2')){
3475 update_option('wpdocs_memphis_uninstall', true);
3476 }
3477
3478 $wpdocs_imported_folder = array();
3479 $wpdocs_imported_files = array();
3480 $wpdocs_memphis_list = array();
3481
3482 update_option('wpdocs_imported_folder', $wpdocs_imported_folder);
3483 update_option('wpdocs_imported_files', $wpdocs_imported_files);
3484 update_option('wpdocs_memphis_list', $wpdocs_memphis_list);
3485 }
3486
3487
3488 }
3489
3490
3491
3492 }
3493
3494 }
3495
3496 if(!function_exists('wp_docs_memphis_folder_preserve')){
3497 function wp_docs_memphis_folder_preserve($from, $to){
3498
3499 $upload_dir = wp_upload_dir();
3500 $upload_basedir = $upload_dir['basedir'];
3501 $memphis_dir = $upload_basedir.'/'.$from;
3502 $bak_file = $memphis_dir.'/mdocs-files.bak';
3503
3504 if(file_exists($bak_file)){
3505
3506 try {
3507 unlink($bak_file);
3508 } catch (\Exception $ex) {
3509 //throw $th;
3510 }
3511 }
3512 $status = false;
3513
3514
3515 if(file_exists($memphis_dir)){
3516 $status = rename($memphis_dir, $upload_basedir.'/'.$to);
3517 }
3518
3519 return $status;
3520 }
3521 }
3522
3523 if(!function_exists('wp_docs_whiteflag_memphis_htaccess')){
3524 function wp_docs_whiteflag_memphis_htaccess(){
3525
3526 $upload_dir = wp_upload_dir();
3527 $basedir = $upload_dir['basedir'];
3528
3529 $memphis_dir = $basedir.'/mdocs/';
3530
3531 if(is_dir($memphis_dir)){
3532
3533 $memphis_dir_ht = $memphis_dir.'.htaccess';
3534 $memphis_dir_index = $memphis_dir.'index.html';
3535
3536 if(file_exists($memphis_dir_ht)){
3537 if(!file_exists($memphis_dir_index)){
3538 file_put_contents($memphis_dir_index, '');
3539 }
3540 /*file_put_contents($memphis_dir_ht, 'Allow from all
3541 Options +Indexes
3542 ');*/
3543 unlink($memphis_dir_ht);
3544 }
3545 }
3546
3547 }
3548 }
3549
3550 if(!function_exists('wp_docs_rollback_memphis_import')){
3551 function wp_docs_rollback_memphis_import(){
3552
3553 global $memphis_files_array, $wpdocs_imported_folder, $wpdocs_imported_files, $wpdocs_memphis_list, $wpdocs_post_types;
3554
3555
3556 $wp_docs_args = array(
3557 'post_type' => $wpdocs_post_type['dir'],
3558 'post_status' => 'any',
3559 'numberposts' => -1,
3560 'meta_query' => array(
3561 array(
3562 'key' => '_wpdocs_memphis_slug',
3563 'compare' => 'EXIST'
3564 )
3565 )
3566 );
3567
3568 $all_memphis_folder = get_posts($wp_docs_args);
3569
3570 if(!empty($all_memphis_folder)){
3571 foreach($all_memphis_folder as $m_folder){
3572 wpdocs_recursive_delete_folder($m_folder->ID);
3573 }
3574 }
3575
3576 if(!empty($wpdocs_memphis_list)){
3577 foreach($wpdocs_memphis_list as $file_index => $file_data){
3578 delete_post_meta($file_data['id'], '_wpdocs_memphis_media_file');
3579 unset($wpdocs_memphis_list[$file_index]);
3580 $memphis_files_array[] = $file_data;
3581
3582 }
3583 }
3584
3585 update_option('mdocs-list', $memphis_files_array);
3586 update_option('wpdocs_memphis_list', $wpdocs_memphis_list);
3587 update_option('wpdocs_imported_files', array());
3588 }
3589 }
3590
3591 function wpdocs_specific_directory_settings($dir=0, $is_file=false, $is_current_user_files=false, $is_del_from_front=false, $allowed_role=array(), $allowed_ext='', $default_ext=''){
3592 global $wpdocs_pro;
3593 $dir_option_class = '';
3594 if($dir){
3595 $dir_option_class = 'wpdocs_dir_options';
3596 $is_file = wpdocs_dir_options_default('file_upload', false, $dir);
3597 $is_current_user_files = wpdocs_dir_options_default('current_user_files', false, $dir);
3598 $is_del_from_front = (is_user_logged_in() && wpdocs_dir_options_default('del_from_front', false, $dir));
3599 $allowed_role = wpdocs_dir_options_default('allowed_role', array(), $dir);
3600 $allowed_ext = wpdocs_dir_options_default('allowed_ext', '', $dir);
3601 $default_ext = '';
3602
3603 $breadcrumb = get_the_title($dir);
3604 ?>
3605 <small class="alert alert-success d-block"><i class="fas fa-chevron-right"></i> <?php echo esc_html($breadcrumb); ?></small>
3606 <?php
3607
3608 }
3609 ?>
3610 <label for="wpdocs_options_file">
3611 <input <?php checked($is_file); ?> type="checkbox" class="<?php echo esc_attr($dir_option_class); ?>" name="wpdocs_options[file_upload]" value="file_upload" id="wpdocs_options_file" />
3612 <?php echo __('File Upload Front-end', 'wp-docs'); ?> <small><?php echo $wpdocs_pro?__('(Optional)', 'wp-docs'):__('(Premium)', 'wp-docs'); ?></small> <i title="<?php echo __('This icon will appear on front-end for users', 'wp-docs'); ?>" class="fa fa-upload" style="color:#ffc107"></i>
3613 <a href="https://www.youtube.com/embed/flFmqpJCwYk" target="_blank"><?php echo __('Video Tutorial', 'wp-docs'); ?></a>
3614 </label>
3615
3616
3617
3618 <ul class="ml-4 <?php echo $is_file ? '' : 'd-none'?>">
3619 <li>
3620 <label for="wpdocs_options_current_user_files">
3621 <input class="<?php echo esc_attr($dir_option_class); ?>" <?php checked($is_file && $is_current_user_files); ?> type="checkbox" name="wpdocs_options[current_user_files]" value="current_user_files" id="wpdocs_options_current_user_files" />
3622 <?php echo __('Do not make files public uploaded by users', 'wp-docs'); ?> <small><?php echo $wpdocs_pro?__('(Optional)', 'wp-docs'):__('(Premium)', 'wp-docs'); ?></small>
3623 </label>
3624 </li>
3625
3626 <li>
3627 <label for="wpdocs_options_del_from_front">
3628 <input class="<?php echo esc_attr($dir_option_class); ?>" <?php checked($is_file && $is_del_from_front); ?> type="checkbox" name="wpdocs_options[del_from_front]" value="del_from_front" id="wpdocs_options_del_from_front" />
3629 <?php echo __('User can delete the files from front-end?', 'wp-docs'); ?> <small><?php echo $wpdocs_pro?__('(Optional)', 'wp-docs'):__('(Premium)', 'wp-docs'); ?></small> <i class="fas fa-trash-alt" style="color:#ffc107"></i>
3630 </label>
3631 </li>
3632
3633 <li>
3634 <label for="wpdocs_options_allowed_role">
3635 <?php echo __('Allow user roles which can upload files', 'wp-docs'); ?> <small><?php echo $wpdocs_pro?__('(Optional)', 'wp-docs'):__('(Premium)', 'wp-docs'); ?></small> <i class="fas fa-users" style="color:#ffc107"></i>
3636 </label>
3637
3638
3639
3640 <select class="wpdocs_options_allowed_role <?php echo esc_attr($dir_option_class); ?>" name="wpdocs_options[allowed_role]" data-name="allowed_role" id="wpdocs_options_allowed_role" multiple placeholder="<?php echo __('Select roles to allow upload', 'wp-docs'); ?>">
3641
3642 <?php echo wpdocs_get_user_roles_options($allowed_role) ?>
3643
3644 </select>
3645
3646
3647 </li>
3648
3649 <li>
3650 <label for="wpdocs_options_allowed_ext">
3651 <?php echo __('Allowed File Types', 'wp-docs'); ?> <?php echo ($wpdocs_pro?'':'<small>'.__('(Premium)', 'wp-docs').'</small> '); ?> <i class="fas fa-photo-video" style="color:#ffc107"></i>
3652 </label>
3653 <input type="text" class="form-control <?php echo esc_attr($dir_option_class); ?>" name="wpdocs_options[allowed_ext]" data-name="allowed_ext" value="<?php echo esc_attr($allowed_ext); ?>" id="wpdocs_options_allowed_ext" title="<?php _e('Leave blank if you want to allow all type of files', 'wp-docs'); ?>" placeholder="<?php echo esc_attr($default_ext); ?>" />
3654
3655 </li>
3656
3657 </ul>
3658 <?php
3659 }
3660
3661 if(!function_exists('wpdocs_dir_options_by_name')){
3662 function wpdocs_dir_options_by_name($option_name, $default_return = false, $dir = 0){
3663
3664 global $wpdocs_options;
3665
3666 $dir_options = array();
3667
3668 if($dir > 0){
3669 $dir_options = get_post_meta($dir, '_wpdocs_dir_options', true);
3670 $dir_options = (is_array($dir_options) ? $dir_options : array());
3671 }
3672
3673 $key_exist = false;
3674 $search_options = array();
3675
3676 if(array_key_exists($option_name, $dir_options)){
3677 $search_options = $dir_options;
3678 $key_exist = true;
3679
3680
3681 }else if(array_key_exists($option_name, $wpdocs_options)){
3682
3683 $search_options = $wpdocs_options;
3684 $key_exist = true;
3685 }
3686
3687 if($key_exist){
3688
3689 $return_value = $search_options[$option_name];
3690 $return_value = (is_array($default_return) && !is_array($return_value) ? array() : $return_value);
3691 $default_return = $return_value;
3692
3693 }
3694
3695 if($default_return == 'true'){
3696 $default_return = true;
3697 }elseif($default_return == 'false'){
3698 $default_return = false;
3699 }
3700
3701 return $default_return;
3702 }
3703 }
3704
3705 if(!function_exists('wpdocs_dir_options_default')){
3706 function wpdocs_dir_options_default($option_name, $default_return = false, $dir = 0){
3707
3708 global $wpdocs_options;
3709
3710 $dir_options = array();
3711
3712 if($dir > 0){
3713 $dir_options = get_post_meta($dir, '_wpdocs_dir_options', true);
3714 $dir_options = (is_array($dir_options) ? $dir_options : array());
3715 }
3716
3717 $key_exist = false;
3718 $search_options = array();
3719
3720 if(array_key_exists($option_name, $dir_options)){
3721 $search_options = $dir_options;
3722 $key_exist = true;
3723 }
3724
3725 if($key_exist){
3726
3727 $return_value = $search_options[$option_name];
3728 $return_value = (is_array($default_return) && !is_array($return_value) ? array() : $return_value);
3729 $default_return = $return_value;
3730
3731 }
3732
3733 if($default_return == 'true'){
3734 $default_return = true;
3735 }elseif($default_return == 'false'){
3736 $default_return = false;
3737 }
3738
3739 return $default_return;
3740 }
3741 }
3742
3743 if(!function_exists('wpdocs_get_dir_restrictions')){
3744 function wpdocs_get_dir_restrictions($dir = 0, $rest_type = 'array'){
3745
3746 $dir_restrictions = array();
3747
3748 if($dir > 0){
3749 $dir_options = get_post_meta($dir, '_wpdocs_dir_options', true);
3750 $dir_options = (is_array($dir_options) ? $dir_options : array());
3751 $is_file_upload = array_key_exists('file_upload', $dir_options) && $dir_options['file_upload'] == 'true';
3752 $dir_restrictions = $dir_options;
3753 }
3754
3755
3756 switch ($rest_type) {
3757 case 'array':
3758 # code...
3759 return $dir_restrictions;
3760 break;
3761
3762 case 'json':
3763 # code...
3764 if(!empty($dir_options)){
3765 return wp_json_encode($dir_restrictions);
3766
3767 }else{
3768 return '';
3769 }
3770 break;
3771
3772 case 'base64':
3773 # code...
3774
3775 if(!empty($dir_options)){
3776 return base64_encode(wp_json_encode($dir_restrictions));
3777 }else{
3778 return '';
3779 }
3780 break;
3781
3782 }
3783
3784
3785
3786 }
3787 }
3788
3789
3790 add_action('init', function(){
3791
3792 global $wpdocs_current_theme;
3793 $wpdocs_current_theme = str_replace(array('-', ' '), '_', strtolower(wp_get_theme()));
3794
3795 // return;
3796 // wpdoc_get_dir_children(8764);
3797 });
3798
3799 if(!function_exists('wpdoc_get_dir_children')){
3800 function wpdoc_get_dir_children($parent_id){
3801
3802 global $wpdocs_post_types;
3803
3804 $all_folder_query = new WP_Query();
3805 $all_folder = $all_folder_query->query(array('post_type' => $wpdocs_post_types, 'post_status' => 'any', 'numberposts' => -1));
3806
3807 $all_folders_array = get_page_children( $parent_id, $all_folder );
3808 $all_folders_array = array_map(function($single){return $single->ID;}, $all_folders_array);
3809
3810 return $all_folders_array;
3811
3812 }
3813 }
3814
3815 if(!function_exists('wpdoc_humanize')){
3816 function wpdoc_humanize($str){
3817 return ucwords(str_replace(array('-', '_'), ' ', $str));
3818 }
3819 }
3820 include_once('functions-verify.php');