PluginProbe
WP Docs / 2.3.4
WP Docs v2.3.4
2.3.4 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.4, at inc/functions.php

4,046 lines 126.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 function wpdocs_create_folder_post( $post_parent, $post_title = "New Folder" ) {
671
672 if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
673 return 0;
674 }
675
676 $post_parent = absint( $post_parent );
677 $post_title = sanitize_text_field( $post_title );
678
679 $my_post = array(
680 'post_title' => $post_title,
681 'post_content' => '',
682 'post_status' => 'hidden',
683 'post_author' => get_current_user_id(),
684 'post_type' => 'wpdocs_folder',
685 'post_parent' => ( ( $post_parent > 0 && wpdocs_folder_exists( $post_parent ) ) ? $post_parent : 0 ),
686 'post_category' => array(),
687 );
688
689 return wp_insert_post( $my_post );
690 }
691 /*function wpdocs_create_folder_post($post_parent, $post_title = "New Folder")
692 {
693
694 $my_post = array(
695 'post_title' => $post_title,
696 'post_content' => '',
697 'post_status' => 'hidden',
698 'post_author' => get_current_user_id(),
699 'post_type' => 'wpdocs_folder',
700 'post_parent' => (($post_parent > 0 && wpdocs_folder_exists($post_parent)) ? $post_parent : 0),
701 'post_category' => array()
702 );
703
704 $dir_id = wp_insert_post($my_post);
705
706 return $dir_id;
707 }*/
708
709 add_action('wp_ajax_wpdocs_create_folder', 'wpdocs_create_folder');
710
711 function wpdocs_create_folder()
712 {
713 if ( ! current_user_can( 'manage_options' ) ) {
714 wp_send_json_error( __("Unauthorized user", 'wp-docs') );
715 wp_die();
716 }
717
718 $nonce = sanitize_wpdocs_data(wp_unslash($_POST['nonce']));
719
720 if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) )
721 die (__("Sorry, your nonce did not verify.", 'wp-docs'));
722
723 $post_parent = sanitize_wpdocs_data($_POST['parent_dir']);
724
725 $dir_id = wpdocs_create_folder_post($post_parent);
726
727 $list_obj = get_post($dir_id);
728
729 $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);
730
731 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
732
733 echo '<li class="ab-dir ab-new"
734 data-id="' . esc_attr($dir_id) . '"
735 data-resource="' . esc_attr(base64_encode($dir_id)) . '"
736 data-linked="' . esc_attr($list['content']) . '"
737 data-guid="' . ($is_shortcut ? esc_attr($list['guid']) : '') . '">
738
739 <a class="folder fa fa-folder"></a>
740
741 <a class="dtitle" title="' . esc_attr(__('Click here to rename', 'wp-docs')) . '">
742 ' . esc_html__('New Folder', 'wp-docs') . '
743 </a>
744
745 <span class="wpd_action_span">
746 <a class="wpd-edit" title="' . esc_attr(__('Click here to edit', 'wp-docs')) . '"></a>
747 <span class="wpd_action_span_inner">
748 <a class="wpd-copy" title="' . esc_attr(__('Click here to copy', 'wp-docs')) . '"></a>
749 <a class="wpd-move" title="' . esc_attr(__('Click here to move', 'wp-docs')) . '"></a>
750 </span>
751 <a class="wpd-trash" title="' . esc_attr(__('Click here to delete', 'wp-docs')) . '"></a>
752 </span>
753 </li>';
754
755 exit;
756 }
757
758
759 if(!function_exists('wpd_get_icon_file_types')){
760
761 function wpd_get_icon_file_types(){
762
763 global $icon_sub_path, $wpdocs_dir;
764
765 $ext_img_dir = $wpdocs_dir.$icon_sub_path;
766
767 $file_types = file_exists($ext_img_dir) && is_dir($ext_img_dir) ? scandir($ext_img_dir) : array();
768
769 $file_types = array_map(function ($file) use ($ext_img_dir){
770
771 $ignore_array = array('.', '..');
772 if(!in_array($file, $ignore_array) && !is_dir($ext_img_dir.$file)){
773 return current(explode('.', $file));
774 }
775
776 }, $file_types);
777
778 $file_types = array_filter($file_types);
779
780 return $file_types;
781
782 }
783 }
784
785
786 if(!function_exists('wpd_get_item_type_icon_url')){
787
788 function wpd_get_item_type_icon_url($item){
789
790 //pree($item);
791
792 global $wpdocs_url, $icon_sub_path, $wpdocs_options, $wpdocs_pro;
793
794 $ext_img_url = $wpdocs_url.$icon_sub_path;
795 $file_types = wpd_get_icon_file_types();
796
797 $file_url = wp_get_attachment_url($item);
798 //pree($file_url);exit;
799
800
801 $filename = basename($file_url);
802 $filename = explode('?', $filename);
803 $filename = (is_array($filename)?current($filename):$filename);
804
805
806 $ext = explode('.', $filename);
807 $ext = end($ext);
808 $icon = in_array($ext, $file_types) ? $ext.'.png' : 'unknown.png';
809 $icon_url = $ext_img_url.$icon;
810
811 switch($ext){
812 case 'svg':
813 case 'gif':
814 case 'bmp':
815 case 'jpg':
816 case 'jpeg':
817 case 'png':
818 $thumb_image = array_key_exists('thumb_image', $wpdocs_options);
819
820 if($thumb_image){
821 $icon_urls = wp_get_attachment_image_src($item, 'thumbnail', false);
822 if(!empty($icon_urls)){
823 $icon_url = current($icon_urls);
824 }
825 }
826 //pree($icon_urls);
827 break;
828 }
829
830
831
832 return array(
833 'file_id' => $item,
834 'file_url' => esc_url($file_url),
835 'ext' => esc_attr($ext),
836 'filename' => esc_attr($filename),
837 'title' => esc_html($filename),
838 'icon_url' => esc_url($icon_url)
839 );
840
841
842 }
843 }
844
845 /**
846 * Centralize the "can this user edit this folder?" decision.
847 * Admins always pass; otherwise require the folder to be owned by the user.
848 */
849 function wpdocs_user_can_edit_folder( $dir_id ) {
850 if ( current_user_can( 'manage_options' ) ) {
851 return true;
852 }
853
854 $dir = get_post( $dir_id );
855 if ( ! $dir || 'wpdocs_folder' !== $dir->post_type ) { // adjust CPT slug
856 return false;
857 }
858
859 return (int) $dir->post_author === get_current_user_id();
860 }
861
862 add_action('wp_ajax_wpdocs_add_files', 'wpdocs_add_files');
863
864 function wpdocs_add_files() {
865
866 // 1) Capability FIRST — before nonce, before anything.
867 if ( ! is_user_logged_in() || ! current_user_can( 'upload_files' ) ) {
868 wp_send_json_error( array( 'message' => __( 'Insufficient permissions.', 'wp-docs' ) ), 403 );
869 }
870
871 // 2) Nonce check.
872 if ( empty( $_POST['nonce'] )
873 || ! wp_verify_nonce(
874 sanitize_wpdocs_data( wp_unslash( $_POST['nonce'] ) ),
875 'wpdocs_update_options_nonce'
876 )
877 ) {
878 wp_send_json_error( array( 'message' => __( 'Sorry, your nonce did not verify.', 'wp-docs' ) ), 403 );
879 }
880
881 // 3) Input validation.
882 $dir_id = isset( $_POST['dir_id'] ) ? absint( $_POST['dir_id'] ) : 0;
883 if ( ! $dir_id ) {
884 wp_send_json_error( array( 'message' => __( 'Invalid folder.', 'wp-docs' ) ), 400 );
885 }
886
887 // 4) Per-folder ownership / capability gate.
888 if ( ! wpdocs_user_can_edit_folder( $dir_id ) ) {
889 wp_send_json_error( array( 'message' => __( 'You cannot modify this folder.', 'wp-docs' ) ), 403 );
890 }
891
892 $files = isset( $_POST['files'] ) ? sanitize_wpdocs_data( $_POST['files'] ) : array();
893 $files = is_array( $files ) ? $files : array( $files );
894 $files = array_filter( array_map( 'absint', $files ) );
895
896 wpdocs_update_files_meta( $dir_id, $files );
897
898 $ret = ! empty( $files ) ? wpdocs_list_added_items( $dir_id ) : '';
899
900 echo $ret;
901 exit;
902 }
903
904 /*function wpdocs_add_files_old(){
905
906 $nonce = sanitize_wpdocs_data(wp_unslash($_POST['nonce']));
907
908 if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) )
909 die (__("Sorry, your nonce did not verify.", 'wp-docs'));
910
911
912 $dir_id = sanitize_wpdocs_data($_POST['dir_id']);
913 $files = sanitize_wpdocs_data($_POST['files']);
914 $files = is_array($files) ? $files : array($files);
915
916 // delete_post_meta($dir_id, 'wpdocs_items');
917
918 wpdocs_update_files_meta($dir_id, $files);
919
920
921
922 $ret = '';
923
924 if(!empty($files)){
925 $files_list = wpdocs_list_added_items($dir_id);
926
927 $ret = $files_list;
928 }
929
930 echo $ret;
931 exit;
932 }*/
933 function wpdocs_list_added_items($dir)
934 {
935
936 global $wpdocs_options, $icon_sub_path, $wpdocs_url;
937
938 $wp_get_upload_dir = wp_get_upload_dir();
939 $wp_uploads_path = $wp_get_upload_dir['basedir'];
940 $wp_uploads_url = $wp_get_upload_dir['baseurl'];
941
942
943
944 $wpdocs_items = wpdocs_added_items($dir); //pree($wpdocs_items);
945 $files_list = array();
946 $pdf_thumb_selected = (array_key_exists('pdf_thumb', $wpdocs_options)?$wpdocs_options['pdf_thumb']:'default');
947
948 if (!empty($wpdocs_items)) {
949 //pree('$wpdocs_items');
950
951 foreach ($wpdocs_items as $item) {
952 $class = '';
953
954 $item_data = wpd_get_item_type_icon_url($item);
955 extract($item_data);
956
957 //pree($item_data);exit;
958 //pree($wp_uploads_path);exit;
959
960 $icon_str = '<img src="' . esc_url($icon_url) . '" style="" alt="' . esc_attr($title) . '">';
961
962 switch ($ext) {
963 case 'png':
964 case 'jpg':
965 case 'jpeg':
966 case 'gif':
967 case 'bmp':
968
969 //$class .= 'fa-image';
970
971 break;
972
973 case 'pdf':
974
975 if($pdf_thumb_selected=='first_page_as_thumbnail'){
976
977 $pdf_file = str_replace($wp_uploads_url, $wp_uploads_path, $item_data['file_url']);
978
979 if(file_exists($pdf_file) && class_exists('imagick')){
980
981 //pree($item_data);
982 //$icon_str = '<object style="width: 100px; height: 100px" data="'.$item_data['file_url'].'#page=1" type="application/pdf"></object>';
983
984 $file_url_thumb = str_replace('.pdf', '.png', strtolower($item_data['file_url']));
985 $file_url_thumb_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url_thumb);
986
987 if(!file_exists($file_url_thumb_path) && class_exists('imagick')){
988
989 try {
990 $im = new imagick($item_data['file_url']);
991 $im->setIteratorIndex(0);
992 $im->setImageFormat('png');
993 $im->writeImage($file_url_thumb_path);
994 } catch (ImagickException $e) {
995
996 if(defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG){
997 error_log("Imagick error: " . $e->getMessage());
998 error_log('file_url: '.$item_data['file_url']);
999 error_log('file_url_thumb_path: '.$file_url_thumb_path);
1000 }
1001
1002 $file_url_thumb = $wpdocs_url.$icon_sub_path.$ext.'.png';
1003 }
1004
1005
1006 }
1007
1008 $icon_str = '<img src="' . esc_url( $file_url_thumb ) . '" style="" alt="' . esc_attr( $title ) . '">';
1009
1010 }
1011
1012 }
1013
1014 break;
1015
1016 default:
1017 //$class .= 'fa-file';
1018 break;
1019 }
1020 $class = '';
1021
1022
1023 $secured_file_url = wpdocs_secure_url($file_id);
1024
1025 $files_list[ $title ] = '<li data-id="' . esc_attr( $item ) . '" data-dir="' . esc_attr( $dir ) . '" title="' . esc_attr( $filename ) . '">
1026 <a href="' . esc_url( $secured_file_url ) . '" target="_blank" class="file ' . esc_attr( $class ) . '"> ' . $icon_str . ' </a>
1027 <a class="ftitle" title="' . esc_attr( $title ) . '">' . esc_html( $title ) . '</a>
1028 <span class="wpd_action_span">
1029 <a href="' . esc_url( 'upload.php?item=' . $item ) . '" target="_blank" class="wpd-edit" title="' . esc_attr__( 'Click here to edit', 'wp-docs' ) . '"></a>
1030 <span class="wpd_action_span_inner">
1031 <a class="wpd-copy" title="' . esc_attr__( 'Click here to copy', 'wp-docs' ) . '"></a>
1032 <a class="wpd-move" title="' . esc_attr__( 'Click here to move', 'wp-docs' ) . '"></a>
1033 </span>
1034 <a href="' . esc_url( 'upload.php?search=' . rawurlencode( $filename ) ) . '" target="_blank" class="wpd-trash" title="' . esc_attr__( 'Click here to delete', 'wp-docs' ) . '"></a>
1035 </span>
1036 </li>';
1037 }
1038 }
1039
1040 ksort($files_list);
1041
1042 return implode('', $files_list);
1043 }
1044
1045
1046 if(!function_exists('wpdocs_get_breadcrumb_array')){
1047 function wpdocs_get_breadcrumb_array($dir, $breadcrumb=true){
1048
1049 $breadcrumb_array = array();
1050
1051 if ($breadcrumb && $dir) {
1052 $dir_id = $dir;
1053
1054 $dir_parent = wp_get_post_parent_id($dir_id);
1055 array_push($breadcrumb_array, $dir_id);
1056 array_push($breadcrumb_array, $dir_parent);
1057
1058
1059 if ($dir_parent != 0) {
1060 do {
1061
1062 $dir_parent = wp_get_post_parent_id($dir_parent);
1063 array_push($breadcrumb_array, $dir_parent);
1064 } while ($dir_parent > 0);
1065 }
1066 }
1067
1068
1069 return $breadcrumb_array;
1070
1071 }
1072 }
1073
1074 if(!function_exists('wpdocs_list_population')){
1075 function wpdocs_list_population($list=array(), $file_data=array(), $file_list_row='', $default_orderby='', $default_order=''){
1076 $filename = $file_data['filename'];
1077 $list[$filename] = $file_list_row;
1078 return $list;
1079 }
1080 }
1081
1082 if(!function_exists('wpdocs_sorting')){
1083 function wpdocs_sorting($list, $order=''){
1084 ksort($list);
1085 return $list;
1086 }
1087 }
1088
1089 add_shortcode('wpdocs', 'wpdocs_front_list');
1090
1091 function wpdocs_front_list($atts=array())
1092 {
1093
1094 if (
1095 !empty($_POST) && !wp_doing_ajax() &&
1096 (
1097 (isset( $_POST['wpdocs_front_list_nonce'] ) && ! wp_verify_nonce( sanitize_wpdocs_data(wp_unslash($_POST['wpdocs_front_list_nonce_field'])), 'wpdocs_front_list_nonce' ) )
1098 )
1099 ) {
1100
1101 print _e('Sorry, your nonce did not verify.', 'wp-docs');
1102 exit;
1103
1104 } else {
1105
1106 }
1107
1108
1109
1110
1111 //pree($atts);
1112 ob_start();
1113 global $wpdocs_url, $wpdocs_options, $wpdocs_pro, $wpdocs_post_types, $pdf_thumb_selected, $icon_sub_path;
1114
1115 $pdf_thumb_selected = (array_key_exists('pdf_thumb', $wpdocs_options)?$wpdocs_options['pdf_thumb']:'default');
1116
1117 $wpdocs_view = get_option('wpdocs_view', array());
1118 $wpdocs_view = is_array($wpdocs_view) ? $wpdocs_view : array();
1119
1120 $is_bootstrap = array_key_exists('bootstrap', $wpdocs_options);
1121 $is_searchbox = array_key_exists('searchbox', $wpdocs_options);
1122
1123 $details_date = array_key_exists('details_date', $wpdocs_options);
1124 $details_date_created = array_key_exists('details_date_created', $wpdocs_options);
1125 $details_view_sorting = array_key_exists('details_view_sorting', $wpdocs_options);
1126 $ajax_based_deep_search = ($wpdocs_pro && array_key_exists('ajax_based_deep_search', $wpdocs_options));
1127 $details_type = array_key_exists('details_type', $wpdocs_options);
1128 $details_size = array_key_exists('details_size', $wpdocs_options);
1129
1130 $customize_icon_size = array_key_exists('icon_size', $wpdocs_options) ? $wpdocs_options['icon_size'] : '';
1131 $customize_icon_size = ($customize_icon_size?$customize_icon_size: 'font-size:100%');
1132 $customize_icon_size = explode(':', $customize_icon_size);
1133 $customize_icon_size = 'font-size:'.end($customize_icon_size);
1134
1135 $customize_font_size = array_key_exists('font_size', $wpdocs_options) ? $wpdocs_options['font_size'] : '';
1136 $customize_font_size = ($customize_font_size?$customize_font_size: 'font-size:90%');
1137 $customize_font_size = explode(':', $customize_font_size);
1138 $customize_font_size = 'font-size:'.end($customize_font_size);
1139
1140 $wp_get_upload_dir = wp_get_upload_dir();
1141 $wp_uploads_path = $wp_get_upload_dir['basedir'];
1142
1143 $wp_uploads_url = home_url('wp-content/uploads');
1144
1145
1146 if(isset($_POST['wpd_dir_id_ajax'])){
1147
1148 $dir = ((isset($_POST['wpd_dir_id_ajax']) && wpdocs_folder_exists($_POST['wpd_dir_id_ajax'])) ? $_POST['wpd_dir_id_ajax'] : 0);
1149 if($_POST['wpd_dir_id_ajax'] == 0 && $_POST['wpd_home_id'] != 0){
1150 $dir = sanitize_wpdocs_data($_POST['wpd_home_id']);
1151 }
1152 $get_permalink = isset($_POST['wpd_get_permalink']) ? $_POST['wpd_get_permalink'] : '' ;
1153
1154 }else{
1155
1156 $dir = ((isset($_GET['dir']) && is_numeric($_GET['dir']) && wpdocs_folder_exists($_GET['dir'])) ? sanitize_wpdocs_data($_GET['dir']) : 0);
1157 $get_permalink = get_permalink();
1158 }
1159
1160
1161
1162
1163 $dir = ($dir?$dir:((isset($atts['dir']) && $atts['dir']!='' && is_numeric($atts['dir']) && wpdocs_folder_exists($atts['dir']))?sanitize_wpdocs_data($atts['dir']):$dir));
1164 $no_breadcrumb = (isset($atts['breadcrumb']) && $atts['breadcrumb']=='false');
1165 $default_view = (isset($atts['view']) ? $atts['view'] : 'list');
1166 $default_orderby = (isset($atts['orderby']) ? $atts['orderby'] : 'title');
1167 $default_order = (isset($atts['order']) ? $atts['order'] : 'ASC');
1168
1169
1170
1171 switch($default_view){
1172 default:
1173 case 'list':
1174 $default_view = 'list_view';
1175 break;
1176
1177 case 'icons':
1178 $default_view = 'large_icon_view';
1179 break;
1180
1181 case 'details':
1182 $default_view = 'detail_view';
1183 break;
1184
1185 }
1186
1187
1188
1189 if(isset($_POST['wpd_home_id'])){
1190
1191 $home_id = sanitize_wpdocs_data($_POST['wpd_home_id']);
1192
1193 }elseif(isset($atts['dir'])){
1194 $home_id = sanitize_wpdocs_data($atts['dir']);
1195 }else{
1196 $home_id = 0;
1197 }
1198
1199 $home_id = preg_replace("/[\'\"\"\"]+/", '', $home_id);
1200
1201 $wpdoc_valid = true;
1202
1203 $wpdocs_security = get_post_meta($dir, 'wpdocs_security', true);
1204 //pree($wpdocs_security);
1205 $roles = array();
1206 if($wpdocs_security!=''){
1207 if( is_user_logged_in() ) {
1208 $user = wp_get_current_user();
1209 $roles = ( array ) $user->roles;
1210 //pree($roles);
1211 $wpdoc_valid = (in_array($wpdocs_security, $roles) || current_user_can('administrator'));
1212 }else{
1213 $wpdoc_valid = false;
1214 }
1215
1216 }
1217
1218 //pree($wpdoc_valid);exit;
1219
1220 $breadcrumb_array = wpdocs_get_breadcrumb_array($dir, !$no_breadcrumb);
1221 //pree($breadcrumb_array);
1222 //pree($wpdoc_valid);
1223 $warning_msg = '';
1224 if(!$wpdoc_valid){
1225 $dir = time()*time();
1226 $warning_msg = '<div class="alert alert-warning fade in alert-dismissible show w-50 mx-auto">
1227 <button type="button" class="close" data-dismiss="alert" aria-label="'.__('Close', 'wp-docs').'">
1228 <span aria-hidden="true" style="font-size:20px">×</span>
1229 </button> <strong>'.__('Sorry', 'wp-docs').'!</strong> '.__('You are not allowed to access this content.', 'wp-docs').'
1230 </div>';
1231 }
1232
1233
1234 //pree($dir.' ~ '.$no_breadcrumb);
1235
1236
1237
1238 if(is_array($breadcrumb_array) && !empty($breadcrumb_array)){
1239
1240
1241 $array_search = array_search($home_id , $breadcrumb_array);
1242
1243 if($array_search === 0){
1244
1245 unset($breadcrumb_array);
1246
1247 }else{
1248
1249 $breadcrumb_array[$array_search] = 0;
1250
1251 }
1252
1253 if(!empty($breadcrumb_array)){
1254
1255 foreach ($breadcrumb_array as $index => $bread){
1256
1257 if($index > $array_search){
1258 unset($breadcrumb_array[$index]);
1259 }
1260 }
1261 }
1262 }
1263
1264 $wpdocs_list = wpdocs_list($dir, $default_orderby, $default_order);
1265
1266 $files_list = wpdocs_added_items($dir);
1267
1268 //pree($files_list);
1269
1270 $wpdocs_list_merged_arr = array();
1271
1272 $deep_files_list_arr = array();
1273
1274
1275
1276 //pree($wpdocs_list);
1277 //pree($wpdocs_list_merged_arr);
1278 //pree($deep_files_list_arr);
1279 //pree($files_list);
1280
1281 $is_file = wpdocs_dir_options_by_name('file_upload', false, $dir);
1282 $is_del_from_front = (is_user_logged_in() && wpdocs_dir_options_by_name('del_from_front', false, $dir));
1283 $is_current_user_files = wpdocs_dir_options_by_name('current_user_files', false, $dir);
1284
1285
1286
1287 if($is_file && $is_current_user_files){
1288 $files_list = wpdocs_added_items_by_user($dir);
1289
1290 //pree($files_list);
1291 }
1292
1293
1294 if(!$is_current_user_files && $ajax_based_deep_search && function_exists('get_deep_files_list_arr')){
1295
1296 //pree($wpdocs_list);
1297
1298 $deep_list_arr = get_deep_files_list_arr($wpdocs_list);
1299 $wpdocs_list_merged_arr = $deep_list_arr['wpdocs_list_merged_arr'];
1300 $deep_files_list_arr = $deep_list_arr['deep_files_list_arr'];
1301
1302 }
1303
1304 ?>
1305
1306
1307 <div class="container-fluid wpdoc_container"
1308 data-dir_restrictions="<?php echo esc_attr( wpdocs_get_dir_restrictions( $dir, 'base64' ) ); ?>"
1309 data-del_from_front="<?php echo esc_attr( $is_del_from_front ); ?>"
1310 data-dir="<?php echo esc_attr( $dir ); ?>"
1311 data-home="<?php echo esc_attr( $home_id ); ?>">
1312
1313 <?php wp_nonce_field( 'wpdocs_front_list_nonce', 'wpdocs_front_list_nonce_field' ); ?>
1314
1315 <input type="hidden" class="wpd_home_id" value="<?php echo esc_attr( $home_id ); ?>" />
1316 <input type="hidden" class="wpd_del_file_id" value="" />
1317
1318 <?php
1319
1320 $wpdocs_view = array_key_exists($home_id, $wpdocs_view) ? $wpdocs_view[$home_id] : trim($default_view);
1321
1322 ?>
1323
1324 <div class="card mt-3">
1325 <!-- breadcrumb Area -->
1326 <nav aria-label="breadcrumb" class="wpdocs-nav position-relative">
1327 <ol class="breadcrumb bg-light" style="border-bottom:1px solid #dee2e6;border-radius: 0; min-height: 40px;">
1328
1329 <?php if (!empty($breadcrumb_array)) { ?>
1330
1331 <li class="breadcrumb-item bread_home_url">
1332 <a class="wpd_bread_item" href="<?php echo esc_url($get_permalink); ?>" data-id="0">
1333 <?php echo esc_html__('Home', 'wp-docs'); ?>
1334 </a>
1335 </li>
1336 <?php
1337
1338 foreach (array_reverse($breadcrumb_array) as $bread_key => $bread_value) {
1339 $active = '';
1340 $page = '';
1341 $permalink = stripos($get_permalink, '?');
1342 $permalink_c = ($permalink!='' && is_numeric($permalink) && $permalink>=0);
1343 $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>';
1344 if ($bread_value == 0) {
1345 continue;
1346 }
1347 if ($bread_value == $dir) {
1348 $active = 'active';
1349 $page = 'page';
1350 $link = get_the_title($bread_value);
1351 }
1352
1353
1354 ?>
1355 <li class="breadcrumb-item <?php echo esc_attr($active); ?>" aria-current="<?php echo esc_attr($page); ?>">
1356 <?php echo wp_kses_post($link); ?>
1357 </li>
1358
1359 <?php } ?>
1360 <?php
1361 }
1362
1363 ?>
1364
1365 </ol>
1366
1367 <?php if($is_del_from_front):?>
1368 <i style="opacity: 0.5;"
1369 class="fa fa-trash fa-1x position-absolute wp_docs_del_file <?php echo esc_attr(is_user_logged_in() ? 'logged_in' : 'logged_out'); ?>"
1370 title="<?php echo esc_attr__('Click here to delete selected files', 'wp-docs'); ?>">
1371 </i>
1372
1373 <?php endif; ?>
1374
1375 <?php if($wpdocs_pro && $dir != 0 && wpdocs_can_current_user_upload_file($dir) && $is_file):?>
1376
1377 <i class="fa fa-upload fa-1x wpdocs-front-add-media position-absolute"
1378 id="wpdocs_front_file_add_<?php echo esc_attr( $dir ); ?>"
1379 title="<?php echo esc_attr__( 'Click here to add files', 'wp-docs' ); ?>">
1380 </i>
1381
1382 <?php endif; ?>
1383 </nav>
1384 <?php
1385 /*
1386 $current_user_id = get_current_user_id();
1387
1388 pree($current_user_id);
1389
1390
1391 $args = array(
1392 'posts_per_page' => -1,
1393 'offset' => 0,
1394 'category' => '',
1395 'category_name' => '',
1396 'orderby' => 'title',
1397 'order' => 'ASC',
1398 'include' => array($dir),
1399 'exclude' => '',
1400 'meta_key' => '',
1401 'meta_value' => '',
1402 'post_type' => 'wpdocs_folder',
1403 'post_mime_type' => '',
1404 'post_parent' => '',//$post_parent,
1405 'author' => $current_user_id,
1406 'author_name' => '',
1407 'post_status' => 'hidden',
1408 'suppress_filters' => true
1409 );
1410 $posts_array = get_posts($args);
1411 pree($posts_array);
1412 */
1413 ?>
1414
1415 <?php echo $warning_msg ? '<div class="card-body">' . wp_kses_post( $warning_msg ) . '</div>' : ''; ?>
1416 <?php if($is_searchbox || $ajax_based_deep_search): ?>
1417 <div class="wpdocs-searchbox">
1418 <input type="text" placeholder="<?php echo ($ajax_based_deep_search?__('Type here to search...', 'wp-docs'):__('Type here to filter...', 'wp-docs')); ?>" />
1419 </div>
1420 <?php endif; ?>
1421
1422 <div class="card-body <?php echo $warning_msg?'d-none':''; ?>">
1423
1424 <!-- Large Icon View Area -->
1425 <div class="row folder_view large_icon_view <?php echo $wpdocs_view=='large_icon_view'?'':'d-none'; ?>">
1426 <?php
1427
1428 //pree($wpdocs_list);
1429
1430 $no_dir_found = false;
1431 $no_file_found = false;
1432 if (!empty($wpdocs_list)) {
1433 foreach ($wpdocs_list as $list) {
1434 //$wpdocs_child_items = wpdocs_list($list['id']);
1435 //$wpdocs_child_files_list = wpdocs_added_items($list['id']);
1436 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
1437 ?>
1438
1439 <div class="col-4 col-md-3 file_wrapper is_dir" style="cursor: pointer;"
1440 data-id="<?php echo esc_attr($list['id']); ?>"
1441 data-resource="<?php echo esc_attr(base64_encode($list['id'])); ?>"
1442 data-linked="<?php echo esc_attr($list['content']); ?>"
1443 data-guid="<?php echo esc_attr($is_shortcut ? $list['link'] : ''); ?>">
1444
1445 <figure class="figure file_view p-0">
1446 <span class="fa fa-folder text-warning" style="<?php echo esc_attr($customize_icon_size); ?>"></span>
1447 <figcaption class="figure-caption text-center" style="<?php echo esc_attr($customize_font_size); ?>">
1448 <?php echo esc_html($list['title']); ?>
1449 </figcaption>
1450 </figure>
1451
1452 </div>
1453 <?php
1454 }
1455 } else {
1456 $no_dir_found = true;
1457 }
1458
1459 //pree($wpdocs_list_merged_arr);
1460
1461 if (!empty($wpdocs_list_merged_arr)) {
1462
1463 foreach ($wpdocs_list_merged_arr as $wpdocs_merged_list) {
1464
1465 foreach ($wpdocs_merged_list as $list_obj) {
1466
1467 $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);
1468 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
1469
1470 ?>
1471 <div class="col-4 col-md-3 file_wrapper is_dir is_deep" style="cursor: pointer;"
1472 data-id="<?php echo esc_attr($list['id']); ?>"
1473 data-resource="<?php echo esc_attr(base64_encode($list['id'])); ?>"
1474 data-linked="<?php echo esc_attr($list['content']); ?>"
1475 data-guid="<?php echo esc_attr($is_shortcut ? $list['guid'] : ''); ?>">
1476
1477 <figure class="figure file_view p-0">
1478 <span class="fa fa-folder text-warning" style="<?php echo esc_attr($customize_icon_size); ?>"></span>
1479
1480 <figcaption class="figure-caption text-center" style="<?php echo esc_attr($customize_font_size); ?>">
1481 <?php echo esc_html($list['title']); ?>
1482 </figcaption>
1483 </figure>
1484
1485 </div>
1486 <?php
1487 }
1488 }
1489 }
1490
1491 //pree($files_list);
1492
1493
1494 if (!empty($files_list)) {
1495 $list = array();
1496 foreach ($files_list as $file) {
1497
1498 $file_data = wpd_get_item_type_icon_url($file);
1499 extract($file_data);
1500
1501 //pree($file_data);exit;
1502
1503 if(trim($file_url)){
1504
1505 switch ($ext) {
1506 case 'png':
1507 case 'jpg':
1508 case 'jpeg':
1509 case 'gif':
1510 case 'bmp':
1511
1512 //$class .= 'fa-image';
1513
1514 break;
1515
1516 case 'pdf':
1517
1518 if($pdf_thumb_selected=='first_page_as_thumbnail'){
1519
1520 $pdf_file = str_replace($wp_uploads_url, $wp_uploads_path, $file_data['file_url']);
1521
1522 if(file_exists($pdf_file) && class_exists('imagick')){
1523
1524 //pree($file_data);
1525 //$icon_str = '<object style="width: 100px; height: 100px" data="'.$file_data['file_url'].'#page=1" type="application/pdf"></object>';
1526
1527 $file_url_thumb = str_replace('.pdf', '.png', strtolower($file_data['file_url']));
1528 $file_url_thumb_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url_thumb);
1529
1530 if(!file_exists($file_url_thumb_path) && class_exists('imagick')){
1531
1532 try {
1533 $im = new imagick($item_data['file_url']);
1534 $im->setIteratorIndex(0);
1535 $im->setImageFormat('png');
1536 $im->writeImage($file_url_thumb_path);
1537 } catch (ImagickException $e) {
1538
1539 if(defined('WP_DEBUG') && WP_DEBUG && defined('WP_DEBUG_LOG') && WP_DEBUG_LOG){
1540 error_log("Imagick error: " . $e->getMessage());
1541 error_log('file_url: '.$item_data['file_url']);
1542 error_log('file_url_thumb_path: '.$file_url_thumb_path);
1543 }
1544
1545 $file_url_thumb = $wpdocs_url.$icon_sub_path.$ext.'.png';
1546 }
1547
1548
1549 }
1550
1551
1552 $icon_url = $file_url_thumb;
1553
1554 }
1555
1556 }
1557
1558 break;
1559
1560 default:
1561 //$class .= 'fa-file';
1562 break;
1563 }
1564
1565 $secured_file_url = wpdocs_secure_url($file_id);
1566
1567 $file_list_row = '
1568
1569 <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).'">
1570 <figure class="figure file_view p-1">
1571 <a href="'.esc_url($secured_file_url).'" target="_blank" class="file">
1572 <img class="my-3" src="'.esc_url($icon_url).'" />
1573 </a>
1574 <figcaption class="figure-caption text-center">'.esc_html($title).'</figcaption>
1575 </figure>
1576 </div>
1577
1578 ';
1579 $list = wpdocs_list_population($list, $file_data, $file_list_row, $default_orderby);
1580
1581 }
1582
1583 }
1584 //pree(array_keys($list));
1585
1586 //ksort($list);
1587 $list = wpdocs_sorting($list, $default_order);
1588 //pree(array_keys($list));
1589 echo implode('', $list);
1590 } else {
1591 $no_file_found = true;
1592 }
1593
1594 if (!empty($deep_files_list_arr)) {
1595 $list = array();
1596 foreach ($deep_files_list_arr as $file) {
1597
1598 $file_data = wpd_get_item_type_icon_url($file);
1599 extract($file_data);
1600
1601 if(trim($file_url)){
1602
1603
1604
1605 switch ($ext) {
1606 case 'png':
1607 case 'jpg':
1608 case 'jpeg':
1609 case 'gif':
1610 case 'bmp':
1611
1612 //$class .= 'fa-image';
1613
1614 break;
1615
1616 case 'pdf':
1617
1618 if($pdf_thumb_selected=='first_page_as_thumbnail'){
1619
1620 $pdf_file = str_replace($wp_uploads_url, $wp_uploads_path, $file_data['file_url']);
1621
1622 if(file_exists($pdf_file) && class_exists('imagick')){
1623
1624 //pree($file_data);
1625 //$icon_str = '<object style="width: 100px; height: 100px" data="'.$file_data['file_url'].'#page=1" type="application/pdf"></object>';
1626
1627 $file_url_thumb = str_replace('.pdf', '.png', strtolower($file_data['file_url']));
1628 $file_url_thumb_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url_thumb);
1629
1630 if(!file_exists($file_url_thumb_path)){
1631
1632 $im = new imagick($file_data['file_url']);
1633 $im->setIteratorIndex(0);
1634 $im->setImageFormat('png');
1635 $im->writeImage($file_url_thumb_path);
1636
1637 }
1638
1639 $icon_url = $file_url_thumb;
1640
1641 }
1642
1643 }
1644
1645 break;
1646
1647 default:
1648 //$class .= 'fa-file';
1649 break;
1650 }
1651
1652 $secured_file_url = wpdocs_secure_url($file_id);
1653
1654 $file_list_row = '
1655
1656 <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).'">
1657 <figure class="figure file_view p-1">
1658 <a href="'.esc_url($secured_file_url).'" target="_blank" class="file">
1659 <img class="my-3" src="'.esc_url($icon_url).'" />
1660 </a>
1661 <figcaption class="figure-caption text-center">'.esc_html($title).'</figcaption>
1662 </figure>
1663 </div>
1664
1665 ';
1666 $list = wpdocs_list_population($list, $file_data, $file_list_row, $default_orderby);
1667
1668 }
1669
1670 }
1671 //pree(array_keys($list));
1672
1673 //ksort($list);
1674 $list = wpdocs_sorting($list, $default_order);
1675 //pree(array_keys($list));
1676 echo implode('', $list);
1677 }
1678
1679
1680
1681 if ($no_dir_found && $no_file_found) {
1682
1683 ?>
1684 <div class="alert alert-info text-center mx-auto empty-dir-files">
1685 <strong><?php _e('Info!', 'wp-docs'); ?></strong> <?php _e('Empty Directory.', 'wp-docs'); ?>
1686 </div>
1687 <?php } ?>
1688
1689
1690 </div>
1691
1692 <!-- List View Area -->
1693 <div class="row folder_view list_view <?php echo $wpdocs_view=='list_view'?'':'d-none'; ?>">
1694 <?php
1695 $no_dir_found = false;
1696 $no_file_found = false;
1697 if (!empty($wpdocs_list)) {
1698 foreach ($wpdocs_list as $list) {
1699 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
1700 ?>
1701
1702 <div class="col-12 file_wrapper is_dir" style="cursor: pointer;"
1703 data-id="<?php echo esc_attr($list['id']); ?>"
1704 data-resource="<?php echo esc_attr(base64_encode($list['id'])); ?>"
1705 data-linked="<?php echo esc_attr($list['content']); ?>"
1706 data-guid="<?php echo esc_attr($is_shortcut ? $list['link'] : ''); ?>">
1707 <figure class="figure file_view p-2">
1708 <span class="fa fa-folder text-warning" style="font-size:25px"></span>
1709 <small class="text-center"><?php echo esc_html($list['title']); ?></small>
1710 </figure>
1711 </div>
1712 <?php
1713 }
1714 } else {
1715 $no_dir_found = true;
1716 }
1717
1718 if (!empty($wpdocs_list_merged_arr)) {
1719
1720 foreach ($wpdocs_list_merged_arr as $wpdocs_merged_list) {
1721
1722 foreach ($wpdocs_merged_list as $list_obj) {
1723
1724 $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);
1725 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
1726
1727 ?>
1728 <div class="col-12 file_wrapper is_dir is_deep" style="cursor: pointer;"
1729 data-id="<?php echo esc_attr($list['id']); ?>"
1730 data-resource="<?php echo esc_attr(base64_encode($list['id'])); ?>"
1731 data-linked="<?php echo esc_attr($list['content']); ?>"
1732 data-guid="<?php echo esc_attr($is_shortcut ? $list['guid'] : ''); ?>">
1733 <figure class="figure file_view p-2">
1734 <span class="fa fa-folder text-warning" style="font-size:25px"></span>
1735 <small class="text-center"><?php echo esc_html($list['title']); ?></small>
1736 </figure>
1737 </div>
1738 <?php
1739 }
1740 }
1741 }
1742
1743
1744 if (!empty($files_list)) {
1745 $list = array();
1746 foreach ($files_list as $file) {
1747
1748 $file_data = wpd_get_item_type_icon_url($file);
1749 extract($file_data);
1750
1751
1752 if(trim($file_url)){
1753
1754 $secured_file_url = wpdocs_secure_url($file_id);
1755
1756 $file_list_row = '
1757 <div title="'.esc_attr($filename).'" class="col-12 file_wrapper is_file" style="cursor: pointer;" data-id="'.$file.'">
1758 <figure class="figure file_view p-3">
1759 <a href="'.$secured_file_url.'" target="_blank" class="file" ><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></a>
1760 <small class="text-center">'.$title.'</small>
1761 </figure>
1762 </div>';
1763
1764 $list = wpdocs_list_population($list, $file_data, $file_list_row, $default_orderby);
1765
1766 }
1767
1768 }
1769 //pree($list);
1770 //ksort($list);
1771 $list = wpdocs_sorting($list, $default_order);
1772 echo implode('', $list);
1773 } else {
1774 $no_file_found = true;
1775 }
1776
1777 if (!empty($deep_files_list_arr)) {
1778 $list = array();
1779 foreach ($deep_files_list_arr as $file) {
1780
1781 $file_data = wpd_get_item_type_icon_url($file);
1782 extract($file_data);
1783
1784
1785 if(trim($file_url)){
1786
1787 $file_list_row = '
1788 <div title="'.esc_attr($filename).'" class="col-12 file_wrapper is_file is_deep" style="cursor: pointer;" data-id="'.$file.'">
1789 <figure class="figure file_view p-3">
1790 <a href="'.$file_url.'" target="_blank" class="file" ><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></a>
1791 <small class="text-center">'.$title.'</small>
1792 </figure>
1793 </div>';
1794
1795 $list = wpdocs_list_population($list, $file_data, $file_list_row, $default_orderby);
1796
1797 }
1798
1799 }
1800 //pree($list);
1801 //ksort($list);
1802 $list = wpdocs_sorting($list, $default_order);
1803 echo implode('', $list);
1804 }
1805
1806
1807
1808 if ($no_dir_found && $no_file_found) {
1809
1810 ?>
1811 <div class="alert alert-info text-center mx-auto empty-dir-files">
1812 <strong><?php _e('Info!', 'wp-docs'); ?></strong> <?php _e('Empty Directory.', 'wp-docs'); ?>
1813 </div>
1814 <?php } ?>
1815
1816
1817 </div>
1818 <?php
1819
1820 ?>
1821 <?php
1822
1823 $d_v_caret = $wpdocs_pro && $details_view_sorting ? '<i class="fa fa-docs-sort" aria-hidden="true"></i>' : '';
1824
1825
1826
1827
1828 ?>
1829 <!-- Detail View Area -->
1830 <div class="row folder_view detail_view mt-0 <?php echo $wpdocs_view=='detail_view'?'':'d-none'; ?>">
1831 <div class="table-responsive" style="zoom:70%">
1832 <table class="table">
1833 <thead class="thead">
1834 <tr>
1835 <th><?php esc_html_e('Name', 'wp-docs'); ?> <?php echo wp_kses_post($d_v_caret); ?></th>
1836
1837 <?php if ( $details_date_created ) : ?>
1838 <th><?php esc_html_e('Created Date', 'wp-docs'); ?> <?php echo wp_kses_post($d_v_caret); ?></th>
1839 <?php endif; ?>
1840
1841 <?php if ( $details_date ) : ?>
1842 <th><?php esc_html_e('Modified Date', 'wp-docs'); ?> <?php echo wp_kses_post($d_v_caret); ?></th>
1843 <?php endif; ?>
1844
1845 <?php if ( $details_type ) : ?>
1846 <th><?php esc_html_e('Type', 'wp-docs'); ?> <?php echo wp_kses_post($d_v_caret); ?></th>
1847 <?php endif; ?>
1848
1849 <?php if ( $details_size ) : ?>
1850 <th><?php esc_html_e('Size', 'wp-docs'); ?> <?php echo wp_kses_post($d_v_caret); ?></th>
1851 <?php endif; ?>
1852
1853 </tr>
1854 </thead>
1855 <?php
1856 $no_dir_found = false;
1857 $no_file_found = false;
1858 if (!empty($wpdocs_list)) {
1859 foreach ($wpdocs_list as $list) {
1860 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
1861 ?>
1862 <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']):''; ?>">
1863 <td>
1864 <figure class="figure ">
1865 <span class="fa fa-folder text-warning" style="font-size:25px"></span>
1866 <small class="text-center mb-1"><?php echo esc_html($list['title']); ?></small>
1867 </figure>
1868 </td>
1869
1870 <?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; ?>
1871 <?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; ?>
1872 <?php if($details_type): ?> <td><small><?php
1873
1874
1875 $directory_post_type = get_post_type($list['id']);
1876
1877
1878 if($wpdocs_post_types['shortcut']==$directory_post_type){
1879 echo '<span style="color: #06C;" class="fa fa-link"></span> '.__('Shortcut', 'wp-docs');
1880 }elseif($wpdocs_post_types['dir']==$directory_post_type){
1881 echo __('Directory', 'wp-docs');
1882 }else{
1883 echo $directory_post_type;
1884 }
1885
1886
1887 ?></small></td><?php endif; ?>
1888 <?php if($details_size): ?> <td><small></small></td><?php endif; ?>
1889 </tr>
1890 <?php
1891 }
1892 } else {
1893 $no_dir_found = true;
1894 }
1895
1896 if (!empty($wpdocs_list_merged_arr)) {
1897
1898 foreach ($wpdocs_list_merged_arr as $wpdocs_merged_list) {
1899
1900 foreach ($wpdocs_merged_list as $list_obj) {
1901
1902 $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);
1903 $is_shortcut = ($list['type']==$wpdocs_post_types['shortcut']);
1904
1905 ?>
1906 <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']):''; ?>">
1907 <td>
1908 <figure class="figure ">
1909 <span class="fa fa-folder text-warning" style="font-size:25px"></span>
1910 <small class="text-center mb-1"><?php echo esc_html($list['title']); ?></small>
1911 </figure>
1912 </td>
1913
1914 <?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; ?>
1915 <?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; ?>
1916 <?php if($details_type): ?> <td><small><?php
1917
1918
1919 $directory_post_type = get_post_type($list['id']);
1920
1921 if($wpdocs_post_types['shortcut']==$directory_post_type){
1922 echo 'Directory Shortcut';
1923 }elseif($wpdocs_post_types['dir']==$directory_post_type){
1924 echo 'Directory';
1925 }else{
1926 echo $directory_post_type;
1927 }
1928
1929
1930
1931
1932 ?></small></td><?php endif; ?>
1933 <?php if($details_size): ?> <td><small></small></td><?php endif; ?>
1934 </tr>
1935 <?php
1936 }
1937 }
1938 }
1939
1940
1941 if (!empty($files_list)) {
1942 $list = array();
1943 foreach ($files_list as $file) {
1944
1945 //pree($file);exit;
1946
1947 $file_data = wpd_get_item_type_icon_url($file);
1948 extract($file_data);
1949 //pree($ts);
1950
1951 if(trim($icon_url)){
1952 $secured_file_url = wpdocs_secure_url($file_id);
1953 $files_list_row = '
1954 <tr title="'.esc_attr($filename).'" data-url="'.$secured_file_url.'" class="file_view file_link is_file" style="cursor: pointer;" data-id="'.$file.'">
1955
1956 <td>
1957
1958 <figure class="figure file_view">
1959 <span class="file"><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></span>
1960 <small class="text-center">'.$title.'</small>
1961 </figure>
1962 </td>
1963 ';
1964
1965 }
1966
1967 $created_time_u = get_post_time('U', false, $file);
1968 $modified_time_u = get_post_modified_time('U', false, $file);
1969
1970 $file_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url);
1971
1972 $file_size = round(@filesize($file_path) / 1024);
1973 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;
1974 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;
1975 if($details_type): $files_list_row .= '<td><small>'.get_post_mime_type($file).'</small></td>'; endif;
1976 if($details_size): $files_list_row .= '<td data-time="'.$file_size.'"><small>'.$file_size. ' KB'.'</small></td>'; endif;
1977 // 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
1978
1979
1980 $files_list_row .= '</tr>';
1981
1982 $list = wpdocs_list_population($list, $file_data, $files_list_row, $default_orderby);
1983
1984
1985
1986 }
1987
1988
1989 $list = wpdocs_sorting($list, $default_order);
1990 echo implode('', $list);
1991
1992 } else {
1993 $no_file_found = true;
1994 }
1995
1996 if (!empty($deep_files_list_arr)) {
1997 $list = array();
1998
1999 //pree($wp_get_upload_dir);
2000 foreach ($deep_files_list_arr as $file) {
2001
2002 //pree($file);exit;
2003
2004 $file_data = wpd_get_item_type_icon_url($file);
2005 extract($file_data);
2006 //pree($ts);
2007
2008 if(trim($icon_url)){
2009
2010 $secured_file_url = wpdocs_secure_url($file_id);
2011
2012 $files_list_row = '
2013 <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.'">
2014
2015 <td>
2016
2017 <figure class="figure file_view">
2018 <span class="file"><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></span>
2019 <small class="text-center">'.$title.'</small>
2020 </figure>
2021 </td>
2022 ';
2023
2024 }
2025
2026 $created_time_u = get_post_time('U', false, $file);
2027 $modified_time_u = get_post_modified_time('U', false, $file);
2028
2029 $file_path = str_replace($wp_uploads_url, $wp_uploads_path, $file_url);
2030
2031 $file_size = round(@filesize($file_path) / 1024);
2032 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;
2033 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;
2034 if($details_type): $files_list_row .= '<td><small>'.get_post_mime_type($file).'</small></td>'; endif;
2035 if($details_size): $files_list_row .= '<td data-time="'.$file_size.'"><small>'.$file_size. ' KB'.'</small></td>'; endif;
2036 // 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
2037
2038
2039 $files_list_row .= '</tr>';
2040
2041 $list = wpdocs_list_population($list, $file_data, $files_list_row, $default_orderby);
2042
2043
2044
2045 }
2046
2047
2048 $list = wpdocs_sorting($list, $default_order);
2049 echo implode('', $list);
2050
2051 }
2052
2053
2054
2055 if ($no_dir_found && $no_file_found) {
2056
2057 ?>
2058 <tr>
2059 <td class="alert alert-info text-center mx-auto empty-dir-files" colspan="5">
2060 <strong><?php _e('Info!', 'wp-docs'); ?></strong> <?php _e('Empty Directory.', 'wp-docs'); ?>
2061 </td>
2062 </tr>
2063 <?php } ?>
2064 </table>
2065 </div>
2066 </div>
2067
2068 </div>
2069 <div class="card-footer text-right wpdocs-views position-relative">
2070
2071
2072
2073 <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>
2074 <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>
2075 <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>
2076 </div>
2077 </div>
2078 <?php if($is_bootstrap): ?>
2079 <div class="wpdocs_loader wpd_modal d-none">
2080 <div class="modal_content">
2081 <img src="<?php echo esc_url($wpdocs_url.'img/loader.gif'); ?>" width="50px" height="50px">
2082 </div>
2083 </div>
2084 <?php endif; ?>
2085
2086 </div>
2087
2088
2089
2090 <?php
2091
2092
2093
2094 $out1 = ob_get_contents();
2095
2096 ob_end_clean();
2097
2098
2099
2100 return $out1;
2101
2102 }
2103
2104
2105 function wpdocs_parent_folder($id)
2106 {
2107 //pree($id);
2108 $parent_id = 0;
2109 if (wpdocs_folder_exists($id)) {
2110 $post_data = get_post($id);
2111 //pree($post_data);
2112 $parent_id = $post_data->post_parent;
2113 }
2114 return ($parent_id);
2115 }
2116
2117 function wpdocs_added_items_by_user($dir_id)
2118 {
2119 $current_user_items = array();
2120 if(!is_user_logged_in()){return array();}
2121
2122
2123
2124 $current_user = get_current_user_id();
2125
2126
2127
2128 if (is_numeric($dir_id) && $dir_id > 0 && wpdocs_folder_exists($dir_id)) {
2129 $wpdocs_items = get_post_meta($dir_id, 'wpdocs_items_by_user', true);
2130 //pree($wpdocs_items);
2131 $wpdocs_items = is_array(maybe_unserialize($wpdocs_items)) ? maybe_unserialize($wpdocs_items) : array();
2132
2133 $current_user_items = array_key_exists($current_user, $wpdocs_items) ? $wpdocs_items[$current_user] : array();
2134 //pree($wpdocs_items);
2135 //asort($wpdocs_items);
2136 }
2137 return $current_user_items;
2138 }
2139
2140 function wpdocs_added_items($dir_id)
2141 {
2142 $wpdocs_items = array();
2143 if (is_numeric($dir_id) && $dir_id > 0 && wpdocs_folder_exists($dir_id)) {
2144 $wpdocs_items = get_post_meta($dir_id, 'wpdocs_items', true);
2145 //pree($wpdocs_items);
2146 $wpdocs_items = is_array(maybe_unserialize($wpdocs_items)) ? maybe_unserialize($wpdocs_items) : array();
2147 //pree($wpdocs_items);
2148 //asort($wpdocs_items);
2149 }
2150 return $wpdocs_items;
2151 }
2152
2153 function wpdocs_folder_exists($ids='', $user_id=0)
2154 {
2155 //pree($id);
2156 //pree($ids);
2157 $posts_array = array();
2158
2159 $ids = explode(',', $ids);
2160 $ids = array_map('trim', $ids);
2161 $ids = array_filter($ids, 'is_numeric');
2162
2163 //pree($ids);exit;
2164 if (!empty($ids)) {
2165 global $wpdocs_post_types, $wpdocs_post_status;
2166 $ids = sanitize_wpdocs_data($ids);
2167 $args = array(
2168 'posts_per_page' => -1,
2169 'offset' => 0,
2170 'category' => '',
2171 'category_name' => '',
2172 'orderby' => 'title',
2173 'order' => 'ASC',
2174 'include' => $ids,
2175 'exclude' => '',
2176 'meta_key' => '',
2177 'meta_value' => '',
2178 'post_type' => $wpdocs_post_types,
2179 'post_mime_type' => '',
2180 'post_parent' => '',//$post_parent,
2181 'author' => ($user_id?$user_id:''),
2182 'author_name' => '',
2183 'post_status' => $wpdocs_post_status,
2184 'suppress_filters' => true
2185 );
2186 //pree($args);
2187 $posts_array = get_posts($args);
2188 }
2189 return (count($posts_array) > 0);
2190 }
2191
2192
2193
2194
2195 add_action('wp_ajax_wpdocs_update_folder', 'wpdocs_update_folder');
2196
2197 function wpdocs_update_folder() {
2198
2199 if ( ! current_user_can( 'manage_options' ) ) {
2200 wp_send_json_error( array( 'msg' => __( 'Unauthorized access.', 'wp-docs' ) ), 403 );
2201 }
2202
2203 if (
2204 empty( $_POST['nonce'] ) ||
2205 ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'wpdocs_update_options_nonce' )
2206 ) {
2207 wp_send_json_error( array( 'msg' => __( 'Sorry, your nonce did not verify.', 'wp-docs' ) ), 403 );
2208 }
2209
2210 $dir_id = absint( $_POST['dir_id'] ?? 0 );
2211 $resource_id = base64_decode( sanitize_text_field( $_POST['resource_id'] ?? '' ) );
2212 $new_name = sanitize_text_field( $_POST['new_name'] ?? '' );
2213
2214 if ( ! $dir_id || $resource_id != $dir_id || ! wpdocs_folder_exists( $dir_id ) ) {
2215 wp_send_json_error( array( 'msg' => __( 'Invalid folder ID or resource mismatch.', 'wp-docs' ) ), 400 );
2216 }
2217
2218 global $wpdb, $wpdocs_post_types, $wpdocs_post_status;
2219
2220 $updated = $wpdb->query(
2221 $wpdb->prepare(
2222 "UPDATE $wpdb->posts
2223 SET post_title = %s
2224 WHERE ID = %d
2225 AND post_type IN ('" . implode( "','", array_map( 'esc_sql', $wpdocs_post_types ) ) . "')
2226 AND post_status = %s",
2227 htmlspecialchars_decode( $new_name ),
2228 $dir_id,
2229 $wpdocs_post_status
2230 )
2231 );
2232
2233 wp_send_json_success(
2234 array(
2235 'msg' => $updated
2236 ? __( 'Successfully updated.', 'wp-docs' )
2237 : __( 'No changes were made. Input seems the same as before.', 'wp-docs' ),
2238 )
2239 );
2240 }
2241
2242 /*function wpdocs_update_folder() {
2243
2244
2245 if ( ! current_user_can('edit_posts') ) {
2246 wp_send_json_error(['msg' => __('Unauthorized access.', 'wp-docs')]);
2247 }
2248
2249
2250 if (
2251 empty($_POST['nonce']) ||
2252 ! wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['nonce'])), 'wpdocs_update_options_nonce')
2253 ) {
2254 wp_send_json_error(['msg' => __('Sorry, your nonce did not verify.', 'wp-docs')]);
2255 }
2256
2257
2258 $dir_id = absint($_POST['dir_id'] ?? 0);
2259 $resource_id = base64_decode(sanitize_text_field($_POST['resource_id'] ?? ''));
2260 $new_name = sanitize_text_field($_POST['new_name'] ?? '');
2261
2262 $ret = ['msg' => ''];
2263
2264 if ( $dir_id > 0 && $resource_id == $dir_id && wpdocs_folder_exists($dir_id) ) {
2265
2266 global $wpdb, $wpdocs_post_types, $wpdocs_post_status;
2267
2268 $updated = $wpdb->query(
2269 $wpdb->prepare(
2270 "UPDATE $wpdb->posts
2271 SET post_title = %s
2272 WHERE ID = %d
2273 AND post_type IN ('" . implode("','", array_map('esc_sql', $wpdocs_post_types)) . "')
2274 AND post_status = %s",
2275 htmlspecialchars_decode($new_name),
2276 $dir_id,
2277 $wpdocs_post_status
2278 )
2279 );
2280
2281 if ( $updated ) {
2282 $ret['msg'] = __('Successfully updated.', 'wp-docs');
2283 } else {
2284 $ret['msg'] = __('No changes were made. Input seems the same as before.', 'wp-docs');
2285 }
2286 } else {
2287 $ret['msg'] = __('Invalid folder ID or resource mismatch.', 'wp-docs');
2288 }
2289
2290 wp_send_json_success($ret);
2291 }*/
2292
2293
2294 add_action('wp_ajax_wpdocs_delete_folder', 'wpdocs_delete_folder');
2295
2296 function wpdocs_delete_folder() {
2297
2298 if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
2299 wp_send_json_error( array( 'msg' => __( 'Unauthorized user', 'wp-docs' ) ), 403 );
2300 }
2301
2302 if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_wpdocs_data( wp_unslash( $_POST['nonce'] ) ), 'wpdocs_update_options_nonce' ) ) {
2303 wp_send_json_error( array( 'msg' => __( 'Sorry, your nonce did not verify.', 'wp-docs' ) ), 403 );
2304 }
2305
2306 $dir_id = isset( $_POST['dir_id'] ) ? absint( $_POST['dir_id'] ) : 0;
2307 $resource_id = base64_decode( sanitize_wpdocs_data( $_POST['resource_id'] ?? '' ) );
2308
2309 if ( ! $dir_id || $dir_id != $resource_id || ! wpdocs_folder_exists( $dir_id ) ) {
2310 wp_send_json_error( array( 'msg' => __( 'Invalid folder.', 'wp-docs' ) ), 400 );
2311 }
2312
2313 wpdocs_recursive_delete_folder( $dir_id );
2314
2315 wp_send_json_success();
2316 }
2317 /*function wpdocs_delete_folder()
2318 {
2319
2320 if ( ! current_user_can( 'manage_options' ) ) {
2321 wp_send_json_error( __( 'Unauthorized user', 'wp-docs' ) );
2322 wp_die();
2323 }
2324
2325 $nonce = sanitize_wpdocs_data(wp_unslash($_POST['nonce']));
2326
2327 if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) )
2328 die (__("Sorry, your nonce did not verify.", 'wp-docs'));
2329
2330 $dir_id = sanitize_wpdocs_data($_POST['dir_id']);
2331 $resource_id = base64_decode(sanitize_wpdocs_data($_POST['resource_id']));
2332
2333 if($dir_id==$resource_id){
2334 wpdocs_recursive_delete_folder($dir_id);
2335 }
2336
2337 exit;
2338 } */
2339
2340
2341
2342 add_action('wp_ajax_wpdocs_delete_files', 'wpdocs_delete_files');
2343
2344
2345
2346 function wpdocs_recursive_delete_folder($dir_id){
2347 if ($dir_id > 0 && wpdocs_folder_exists($dir_id)) {
2348 $wpdocs_list = wpdocs_list($dir_id);
2349 if(!empty($wpdocs_list)){
2350 foreach($wpdocs_list as $wpdocs_item){
2351 //pree($wpdocs_item);
2352 if(is_numeric($wpdocs_item['id'])){
2353 wpdocs_recursive_delete_folder($wpdocs_item['id']);
2354 }
2355 }
2356 }
2357
2358 if(function_exists('wp_docs_relocate_memphis_meta')){
2359 wp_docs_relocate_memphis_meta($dir_id);
2360 }
2361
2362 wp_delete_post($dir_id, true);
2363 }
2364
2365 }
2366
2367
2368
2369 if(!function_exists('wpdocs_update_files_meta')){
2370
2371 function wpdocs_update_files_meta($dir_id, $files=array()){
2372
2373 if ($dir_id > 0 && wpdocs_folder_exists($dir_id) && count($files) > 0) {
2374
2375 //Items for single user
2376 $current_user = get_current_user_id();
2377 $wpdocs_items_by_user = get_post_meta($dir_id, 'wpdocs_items_by_user', true);
2378
2379
2380
2381 $wpdocs_items_by_user = $wpdocs_items_by_user && is_array($wpdocs_items_by_user) ? $wpdocs_items_by_user: array();
2382
2383
2384 $current_user_items = array_key_exists($current_user, $wpdocs_items_by_user) ? $wpdocs_items_by_user[$current_user] : array();
2385
2386
2387
2388
2389
2390 $current_user_items = array_merge($current_user_items, $files);
2391
2392
2393
2394
2395 $current_user_items = array_unique($current_user_items);
2396
2397
2398
2399 $wpdocs_items_by_user[$current_user] = $current_user_items;
2400
2401
2402
2403
2404 //overall items
2405
2406 $wpdocs_items = wpdocs_added_items($dir_id);
2407
2408 $wpdocs_items = array_merge($wpdocs_items, $files);
2409
2410 $wpdocs_items = array_unique($wpdocs_items);
2411
2412 //pree($wpdocs_items);
2413
2414 update_post_meta($dir_id, 'wpdocs_items_by_user', $wpdocs_items_by_user);
2415
2416 return update_post_meta($dir_id, 'wpdocs_items', $wpdocs_items);
2417 }
2418 }
2419 }
2420
2421 function wpdocs_delete_files() {
2422 if ( ! is_user_logged_in() || ! current_user_can( 'delete_posts' ) ) {
2423 wp_send_json_error( array( 'message' => __( 'Insufficient permissions.', 'wp-docs' ) ), 403 );
2424 }
2425
2426 if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_wpdocs_data( wp_unslash( $_POST['nonce'] ) ), 'wpdocs_update_options_nonce' ) ) {
2427 wp_send_json_error( array( 'message' => __( 'Sorry, your nonce did not verify.', 'wp-docs' ) ), 403 );
2428 }
2429
2430 $dir_id = isset( $_POST['dir_id'] ) ? absint( $_POST['dir_id'] ) : 0;
2431 $files = isset( $_POST['files'] ) ? (array) $_POST['files'] : array();
2432 $files = array_values( array_unique( array_filter( array_map( 'absint', $files ) ) ) );
2433
2434 if ( ! $dir_id || ! wpdocs_folder_exists( $dir_id ) || empty( $files ) ) {
2435 wp_send_json_error( array( 'message' => __( 'Invalid request.', 'wp-docs' ) ), 400 );
2436 }
2437
2438 $is_admin = current_user_can( 'manage_options' );
2439 $is_owner = wpdocs_user_can_edit_folder( $dir_id );
2440
2441 if ( ! $is_admin && ! $is_owner ) {
2442 wp_send_json_error( array( 'message' => __( 'You cannot delete files from this folder.', 'wp-docs' ) ), 403 );
2443 }
2444
2445 $allowed = array();
2446 foreach ( $files as $file_id ) {
2447 $attachment = get_post( $file_id );
2448 if ( ! $attachment || 'attachment' !== $attachment->post_type ) {
2449 continue;
2450 }
2451 if ( $is_admin || current_user_can( 'edit_post', $file_id ) ) {
2452 $allowed[] = $file_id;
2453 }
2454 }
2455
2456 if ( empty( $allowed ) ) {
2457 wp_send_json_error( array( 'message' => __( 'None of the specified files can be deleted by you.', 'wp-docs' ) ), 403 );
2458 }
2459
2460 wpdocs_del_items_by_user( $dir_id, $allowed, get_current_user_id() );
2461
2462 $wpdocs_items = wpdocs_added_items( $dir_id );
2463 $wpdocs_items = array_values( array_unique( array_diff( (array) $wpdocs_items, $allowed ) ) );
2464
2465 update_post_meta( $dir_id, 'wpdocs_items', $wpdocs_items );
2466
2467 wp_send_json_success( array( 'dir_id' => $dir_id, 'files' => $allowed ) );
2468 }
2469
2470 /*
2471 function wpdocs_delete_files()
2472 {
2473
2474 $dir_id = sanitize_wpdocs_data($_POST['dir_id']);
2475 $files = sanitize_wpdocs_data($_POST['files']);
2476 $files = is_array($files) ? $files : array($files);
2477 //pree($dir_id);pree($files);exit;
2478 if ($dir_id > 0 && wpdocs_folder_exists($dir_id) && count($files) > 0) {
2479
2480 wpdocs_del_items_by_user($dir_id, $files, get_current_user_id());
2481
2482
2483 $wpdocs_items = wpdocs_added_items($dir_id);
2484 //pree($wpdocs_items);
2485 $wpdocs_items = array_diff($wpdocs_items, $files);
2486 //pree($wpdocs_items);
2487 $wpdocs_items = array_unique($wpdocs_items);
2488
2489 //pree($wpdocs_items);
2490
2491 update_post_meta($dir_id, 'wpdocs_items', $wpdocs_items);
2492 }
2493
2494
2495 exit;
2496 } */
2497
2498 function wpd_admin_footer(){
2499
2500 ?>
2501 <script type="text/javascript" language="javascript">
2502
2503 </script>
2504
2505 <?php
2506
2507 }
2508 add_action('admin_footer', 'wpd_admin_footer');
2509
2510 add_action('wp_ajax_wpdocs_update_option', 'wpdocs_update_option');
2511
2512 if(!function_exists('wpdocs_update_option')){
2513 function wpdocs_update_option(){
2514
2515 if ( ! current_user_can('manage_options') ) {
2516 wp_send_json_error('Insufficient permissions.');
2517 }
2518
2519 if (
2520 ! isset($_POST['wpdocs_update_option_nonce']) ||
2521 ! wp_verify_nonce($_POST['wpdocs_update_option_nonce'], 'wpdocs_update_options_nonce')
2522 ) {
2523 wp_send_json_error('Invalid nonce '.$_POST['wpdocs_update_option_nonce']);
2524 } else {
2525 //wp_send_json_success('Nonce valid!');
2526 }
2527
2528 $return = array(
2529
2530 'option_update' => false,
2531 'dir_move' => false,
2532 );
2533
2534
2535
2536 if(isset($_POST['wpdocs_options'])){
2537
2538 $wpdocs_options = isset($_POST['wpdocs_options']) ? sanitize_wpdocs_data($_POST['wpdocs_options']) : array();
2539
2540 $wpdocs_dir_id = isset($_POST['wpdocs_dir_id']) ? sanitize_wpdocs_data($_POST['wpdocs_dir_id']) : 0;
2541
2542
2543 $sanitized_option = sanitize_wpdocs_data($wpdocs_options);
2544 $sanitized_option['allowed_role'] = $sanitized_option['allowed_role'] !== 'empty' ? $sanitized_option['allowed_role'] : array();
2545
2546
2547 if($wpdocs_dir_id == 0){
2548
2549 $update = update_option('wpdocs_options', $sanitized_option);
2550
2551 }else{
2552
2553 $update = update_post_meta($wpdocs_dir_id, '_wpdocs_dir_options', $sanitized_option);
2554 $child_dir_list = wpdoc_get_dir_children($wpdocs_dir_id);
2555 if(!empty($child_dir_list)){
2556 foreach ($child_dir_list as $child_dir) {
2557
2558 $update = update_post_meta($child_dir, '_wpdocs_dir_options', $sanitized_option);
2559
2560 # code...
2561 }
2562 }
2563
2564
2565
2566 }
2567 }
2568
2569
2570
2571 if(isset($_POST['wpdocs_move_selected_dir'])){
2572
2573 $wpdocs_move_selected_dir = sanitize_wpdocs_data($_POST['wpdocs_move_selected_dir']);
2574 $action_type = $wpdocs_move_selected_dir['action_type'];
2575
2576
2577 $is_file = array_key_exists('is_file', $wpdocs_move_selected_dir) ? $wpdocs_move_selected_dir['is_file']: false;
2578 $is_file = $is_file == 'false' ? false: true;
2579
2580
2581 if(!$is_file && array_key_exists('dir_selected', $wpdocs_move_selected_dir) &&
2582 array_key_exists('dir_id', $wpdocs_move_selected_dir)){
2583
2584 switch($action_type){
2585 default:
2586 case 'move':
2587
2588
2589 $update = wp_update_post(
2590 array(
2591 'ID' => $wpdocs_move_selected_dir['dir_selected'],
2592 'post_parent' => $wpdocs_move_selected_dir['dir_id']
2593 )
2594 );
2595
2596 if($update == $wpdocs_move_selected_dir['dir_selected']){
2597 $return['dir_move'] = true;
2598 }
2599
2600 break;
2601
2602 case 'copy':
2603 $existing_dir = get_post($wpdocs_move_selected_dir['dir_selected']);
2604 $existing_dir = (is_object($existing_dir)?(array)$existing_dir:array());
2605 if(!empty($existing_dir) && array_key_exists('ID', $existing_dir) && function_exists('wpdocs_recursive_copy_folder')){
2606
2607 wpdocs_recursive_copy_folder($wpdocs_move_selected_dir['dir_id'], $existing_dir);
2608
2609 $return['dir_move'] = true;
2610
2611 }
2612
2613
2614 break;
2615 }
2616
2617
2618
2619 }
2620 //exit;
2621
2622 if($is_file){
2623
2624 $file_id = $wpdocs_move_selected_dir['files'];
2625
2626 $current_dir = $wpdocs_move_selected_dir['file_dir'];
2627
2628 $new_dir = $wpdocs_move_selected_dir['dir_id'];
2629
2630 $files = wpdocs_added_items($current_dir);
2631
2632 $file_id = is_array($file_id) ? $file_id : array($file_id);
2633 $files = array_diff($files, $file_id);
2634
2635
2636 switch($action_type){
2637 default:
2638 case 'move':
2639
2640 update_post_meta($current_dir, 'wpdocs_items', $files);
2641
2642 break;
2643
2644 case 'copy':
2645
2646 break;
2647
2648 }
2649
2650 $update = wpdocs_update_files_meta($new_dir, $file_id);
2651
2652 if($update === true){
2653 $return['dir_move'] = true;
2654 }
2655
2656 }
2657 }
2658
2659 echo wp_json_encode($return);
2660
2661
2662 wp_die();
2663
2664 }
2665 }
2666
2667
2668
2669 if(!function_exists('wpdocs_dir_list_complete')){
2670
2671 function wpdocs_dir_list_complete($dir = 0){
2672
2673 $wpdocs_list = wpdocs_list($dir);
2674
2675 if(!empty($wpdocs_list)){
2676
2677 $wp_dir_child = array();
2678
2679 foreach ($wpdocs_list as $index => $wp_dir){
2680
2681 if(!array_key_exists('id', $wp_dir)) continue;
2682 $wpdocs_list_child = wpdocs_list($wp_dir['id']);
2683
2684 if(!empty($wpdocs_list_child)){
2685
2686 $wp_dir['child_dir'] = wpdocs_dir_list_complete($wp_dir['id']);
2687
2688 }
2689
2690 $wp_dir_child[] = $wp_dir;
2691
2692
2693 }
2694
2695 return $wp_dir_child;
2696
2697 }else{
2698
2699 return array();
2700 }
2701 }
2702 }
2703
2704 if(!function_exists('wpdocs_dir_list_option')){
2705
2706 function wpdocs_dir_list_option($dir = 0, $str = ' __ ', $level = 0){
2707
2708
2709 $wpdocs_list = wpdocs_list($dir);
2710
2711 $option = '';
2712
2713 if(!empty($wpdocs_list)){
2714
2715
2716 foreach ($wpdocs_list as $index => $wp_dir){
2717
2718 if(!array_key_exists('id', $wp_dir)) continue;
2719 $wpdocs_list_child = wpdocs_list($wp_dir['id']);
2720
2721 $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>';
2722
2723
2724 if(!empty($wpdocs_list_child)){
2725
2726
2727 $option .= wpdocs_dir_list_option($wp_dir['id'], $str, $level+1);
2728
2729 }
2730
2731 }
2732
2733
2734 }
2735
2736 return $option;
2737 }
2738 }
2739
2740 add_action('wpdocs_before_docs_list', 'wpdocs_add_breadcrumb');
2741
2742 if(!function_exists('wpdocs_add_breadcrumb')){
2743
2744 function wpdocs_add_breadcrumb($dir_id, $breadcrumb=true){
2745
2746
2747
2748 $breadcrumb_array = wpdocs_get_breadcrumb_array($dir_id, $breadcrumb);
2749 $get_permalink = admin_url('options-general.php?page=wpdocs');
2750
2751 if (!empty($breadcrumb_array)) {
2752 ?>
2753
2754 <nav aria-label="breadcrumb" class="wpdocs-nav">
2755 <ol class="breadcrumb bg-light" style="border-bottom:1px solid #dee2e6;border-radius: 0;">
2756
2757 <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>
2758 <?php
2759
2760 foreach (array_reverse($breadcrumb_array) as $bread_key => $bread_value) {
2761 $active = '';
2762 $page = '';
2763
2764 $link = '<a class="wpd_bread_item" href="' . $get_permalink .'&dir=' . $bread_value . '" data-id="'.$bread_value.'" >' . get_the_title($bread_value) . '</a>';
2765 if ($bread_value == 0) {
2766 continue;
2767 }
2768 if ($bread_value == $dir_id) {
2769 $active = 'active';
2770 $page = 'page';
2771 $link = get_the_title($bread_value);
2772 }
2773
2774
2775 ?>
2776 <li class="breadcrumb-item <?php echo esc_attr($active); ?>" aria-current="<?php echo esc_attr($page); ?>"><?php echo ($link); ?></li>
2777
2778 <?php
2779 }
2780
2781 ?>
2782
2783 </ol>
2784
2785 </nav>
2786
2787 <?php
2788
2789 }
2790 }
2791 }
2792
2793 add_action('wp_ajax_wpdocs_update_view', 'wpdocs_update_view');
2794
2795
2796 if ( ! function_exists( 'wpdocs_update_view' ) ) {
2797 function wpdocs_update_view() {
2798
2799 if ( ! is_user_logged_in() || ! current_user_can( 'read' ) ) {
2800 wp_send_json_error( array( 'msg' => __( 'Unauthorized access.', 'wp-docs' ) ), 403 );
2801 }
2802
2803 if ( empty( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_wpdocs_data( wp_unslash( $_POST['nonce'] ) ), 'wpdocs_update_options_nonce' ) ) {
2804 wp_send_json_error( array( 'msg' => __( 'Sorry, your nonce did not verify.', 'wp-docs' ) ), 403 );
2805 }
2806
2807 $uid = get_current_user_id();
2808 $key = 'wpdocs_view_rl_' . $uid;
2809 $hits = (int) get_transient( $key );
2810
2811 if ( $hits >= 60 ) {
2812 wp_send_json_error( array( 'msg' => __( 'Too many requests.', 'wp-docs' ) ), 429 );
2813 }
2814 set_transient( $key, $hits + 1, MINUTE_IN_SECONDS );
2815
2816 if ( isset( $_POST['update_view'] ) ) {
2817
2818 $wpdocs_view = get_option( 'wpdocs_view', array() );
2819 $wpdocs_view = is_array( $wpdocs_view ) ? $wpdocs_view : array();
2820
2821 $parent_dir = sanitize_wpdocs_data( $_POST['parent_dir'] ?? '' );
2822 $view_val = sanitize_wpdocs_data( $_POST['update_view'] );
2823
2824 $wpdocs_view[ $parent_dir ] = $view_val;
2825 update_option( 'wpdocs_view', $wpdocs_view );
2826 }
2827
2828 wp_send_json_success();
2829 }
2830 }
2831 /*if(!function_exists('wpdocs_update_view')){
2832 function wpdocs_update_view(){
2833
2834 $nonce = sanitize_wpdocs_data(wp_unslash($_POST['nonce']));
2835
2836 if (!empty($_POST) && isset($_POST['nonce']) && ! wp_verify_nonce( $nonce, 'wpdocs_update_options_nonce' ) )
2837 die (__("Sorry, your nonce did not verify.", 'wp-docs'));
2838
2839 if(isset($_POST['update_view'])){
2840
2841 $wpdocs_view = get_option('wpdocs_view', array());
2842 $wpdocs_view = is_array($wpdocs_view) ? $wpdocs_view : array();
2843 $parent_dir = sanitize_wpdocs_data($_POST['parent_dir']);
2844
2845 $wpdocs_view[$parent_dir] = sanitize_wpdocs_data($_POST['update_view']);
2846 update_option('wpdocs_view', $wpdocs_view);
2847
2848 }
2849 exit;
2850 }
2851 }*/
2852 function wpdocs_init_session() {
2853 if(!session_id()) {
2854 session_start();
2855 }
2856 }
2857
2858 //add_action('init', 'wpdocs_init_session', 1);
2859
2860 if(!function_exists('wpdocs_create_dir')){
2861 function wpdocs_create_dir($dir_id, $parent_path){
2862
2863
2864 if(!file_exists($parent_path)){
2865 mkdir($parent_path);
2866 }
2867
2868 $current_dir_name = 'wpdocs';
2869
2870 if($dir_id != 0){
2871
2872 $current_dir = get_post($dir_id);
2873 $current_dir_name = $current_dir->post_title;
2874 }
2875
2876 $current_dir_temp = $parent_path.'/'.$current_dir_name;
2877
2878 if(!is_dir($current_dir_temp))
2879 mkdir($current_dir_temp);
2880
2881 return $current_dir_temp;
2882 }
2883 }
2884
2885 if(!function_exists('wpdocs_copy_files')){
2886 function wpdocs_copy_files($wpdocs_items, $current_dir_temp){
2887
2888 //pre($wpdocs_items);
2889
2890 $upload_dir = wp_upload_dir();
2891
2892 if(!empty($wpdocs_items)){
2893 foreach ($wpdocs_items as $item_id){
2894 //pre($item_id);
2895 //pre(get_post_meta($item_id));
2896 $attached_file = get_post_meta($item_id, '_wp_attached_file', true);
2897 //pre($attached_file);
2898
2899 $absolute_path = false;
2900
2901 if(!$attached_file){
2902 $attached_post = get_post($item_id);
2903 $attached_file = $attached_post->guid;
2904 $absolute_path = true;
2905 }
2906
2907
2908 $file_name = basename($attached_file);
2909 $file_copy_path = $current_dir_temp.'/'.$file_name;
2910
2911 if($absolute_path){
2912 $file_path = str_replace($upload_dir['baseurl'], $upload_dir['basedir'], $attached_file);
2913 }else{
2914 $file_path = $upload_dir['basedir'].'/'.$attached_file;
2915 }
2916
2917 //pre($file_path);
2918
2919 if(!is_dir($file_path) && file_exists($file_path)){
2920 copy($file_path, $file_copy_path);
2921 }
2922 }
2923 }
2924
2925 //exit;
2926
2927 }
2928 }
2929
2930 if(!function_exists('wpdocs_create')){
2931 function wpdocs_create($dir_id, $wpdocs_dir){
2932
2933 //pree($dir_id);
2934
2935 $wpdocs_list = wpdocs_list($dir_id);
2936 //pre($wpdocs_list);
2937 $wpdocs_items = wpdocs_added_items($dir_id);
2938 //pre($wpdocs_items);
2939
2940 $current_dir_temp = wpdocs_create_dir($dir_id, $wpdocs_dir);
2941
2942 //pree($current_dir_temp);
2943 //exit;
2944
2945 wpdocs_copy_files($wpdocs_items, $current_dir_temp);
2946
2947 if(!empty($wpdocs_list)){
2948 foreach ($wpdocs_list as $single_dir){
2949
2950 wpdocs_create($single_dir['id'], $current_dir_temp);
2951 }
2952 }
2953
2954 }
2955
2956 }
2957
2958 if(!function_exists('wpdocs_generate_zip')){
2959
2960 function wpdocs_generate_zip($source, $destination)
2961 {
2962
2963 // Initialize archive object
2964 $zip = new ZipArchive();
2965 $zip->open($destination, ZipArchive::CREATE | ZipArchive::OVERWRITE);
2966
2967
2968 // Create recursive directory iterator
2969 /** @var SplFileInfo[] $files */
2970 $files = new RecursiveIteratorIterator(
2971 new RecursiveDirectoryIterator($source),
2972 RecursiveIteratorIterator::SELF_FIRST
2973 );
2974
2975 //pre($files);
2976
2977 if (!empty($files)) {
2978 foreach ($files as $name => $file) {
2979
2980
2981 $file_path = $file->getRealPath();
2982 $relative_path = substr($file_path, strlen($source) + 1);
2983 /*
2984 if (!$file->isDir()) {
2985 // Get real and relative path for current file
2986
2987
2988
2989 // Add current file to archive
2990 $zip->addFile($file_path, $relative_path);
2991 }
2992 */
2993
2994 if (is_dir($file_path) === true) {
2995 $zip->addEmptyDir(str_replace($source . '/', '', $relative_path . '/'));
2996 } elseif (is_file($file) === true) {
2997 $zip->addFromString(str_replace($source . '/', '', $relative_path), file_get_contents($file_path));
2998 }
2999 }
3000 }
3001
3002
3003
3004 // Zip archive will be created only after closing object
3005 $zip->close();
3006
3007 $ret = str_replace('\\', '/', $destination);
3008
3009 $url = str_replace(get_home_path(), get_home_url().'/', $ret);
3010
3011 $resp = array(
3012 'url' => $url,
3013 'path' => $destination,
3014 );
3015
3016 //pree($resp);exit;
3017
3018 return $resp;
3019
3020 }
3021
3022 }
3023
3024 if(!function_exists('wpdocs_download_zip')){
3025 function wpdocs_download_zip($dir_id){
3026
3027 $upload_dir = wp_upload_dir();
3028 $upload_dir = $upload_dir['basedir'];
3029 $wpdocs_dir = $upload_dir.'/wpdocs';
3030 $current_dir_temp = wpdocs_create_dir($dir_id, $wpdocs_dir);
3031 wpdocs_create($dir_id, $wpdocs_dir);
3032
3033 $dest = $wpdocs_dir.'/'.basename($current_dir_temp).'.zip';
3034
3035 //pre($current_dir_temp);pre($dest);
3036 //exit;
3037
3038 $ret = wpdocs_generate_zip($current_dir_temp, $dest);
3039
3040 //pree($ret);
3041 if(isset($_GET['debug'])){
3042 exit;
3043 }
3044
3045 return $ret;
3046
3047 }
3048 }
3049 if(!function_exists('wpdocs_file_download')){
3050 function wpdocs_file_download(){
3051
3052 if(empty($_GET['wpdocs_dl'])){
3053 return;
3054 }
3055
3056 $file_id = absint(
3057 wp_unslash($_GET['wpdocs_dl'])
3058 );
3059
3060 if(!$file_id){
3061 status_header(404);
3062 exit;
3063 }
3064
3065 $nonce = isset($_GET['wpdocs_nonce'])
3066 ? sanitize_text_field(
3067 wp_unslash($_GET['wpdocs_nonce'])
3068 )
3069 : '';
3070
3071 if(
3072 !wp_verify_nonce(
3073 $nonce,
3074 'wpdocs_dl_' . $file_id
3075 )
3076 ){
3077 status_header(403);
3078 exit;
3079 }
3080
3081 // Adjust this according to where you store the file
3082 $file = get_attached_file($file_id);
3083
3084 if(
3085 !$file ||
3086 !file_exists($file)
3087 ){
3088 status_header(404);
3089 exit;
3090 }
3091
3092 $uploads = wp_get_upload_dir();
3093 $base_real = realpath($uploads['basedir']);
3094 $file_real = realpath($file);
3095
3096 if(
3097 !$base_real ||
3098 !$file_real ||
3099 strpos(
3100 $file_real,
3101 $base_real . DIRECTORY_SEPARATOR
3102 ) !== 0
3103 ){
3104 status_header(403);
3105 exit;
3106 }
3107
3108 $mime = wp_check_filetype($file_real);
3109 $mime = !empty($mime['type'])
3110 ? $mime['type']
3111 : 'application/octet-stream';
3112
3113 header('Content-Type: ' . $mime);
3114 header('Content-Length: ' . filesize($file_real));
3115 header(
3116 'Content-Disposition: inline; filename="' .
3117 basename($file_real) .
3118 '"'
3119 );
3120
3121 readfile($file_real);
3122 exit;
3123 }
3124 }
3125
3126 add_action('init', 'wpdocs_dir_actions');
3127 if(!function_exists('wpdocs_dir_actions')){
3128 function wpdocs_dir_actions(){
3129
3130 wpdocs_file_download();
3131
3132 if(is_admin() && get_option('wpdocs_memphis_uninstall')){
3133 if(wp_docs_memphis_folder_preserve('mdocs_2', 'mdocs')){
3134 update_option('wpdocs_memphis_uninstall', false);
3135 }
3136 }
3137
3138 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']}" )){
3139
3140 //pree($_GET);exit;
3141
3142 if(isset($_GET['download'])){
3143
3144 $wpdocs_clear_clutter = get_option('wpdocs_clear_clutter', array());
3145 $wpdocs_clear_clutter = (is_array($wpdocs_clear_clutter)?$wpdocs_clear_clutter:array());
3146 if(!empty($wpdocs_clear_clutter)){
3147 foreach($wpdocs_clear_clutter as $i=>$wpdocs_clear_clutter_iter){
3148
3149 if(is_array($wpdocs_clear_clutter_iter)){
3150
3151 list($rm_dir, $zip_path) = $wpdocs_clear_clutter_iter;
3152 unlink($zip_path);
3153
3154 if (is_dir($rm_dir)) {
3155 $dir = new RecursiveDirectoryIterator($rm_dir, RecursiveDirectoryIterator::SKIP_DOTS);
3156 foreach (new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST ) as $filename => $file) {
3157 if (is_file($filename))
3158 unlink($filename);
3159 else
3160 rmdir($filename);
3161 }
3162 rmdir($rm_dir); // Now remove myfolder
3163 }
3164 }
3165
3166 unset($wpdocs_clear_clutter[$i]);
3167 }
3168 update_option('wpdocs_clear_clutter', $wpdocs_clear_clutter);
3169 }
3170
3171
3172
3173 $wpdocs_dir = sanitize_wpdocs_data($_GET['wpdocs_dir']);
3174 //pree($wpdocs_dir);exit;
3175 $zip = wpdocs_download_zip($wpdocs_dir);
3176 $rm_dir = str_replace('.zip', '',$zip['path'] );
3177 //pree($rm_dir);exit;
3178 //pree($wpdocs_dir);pree($rm_dir);pree($zip);exit;
3179 if(file_exists($zip['path'])){
3180
3181 $wpdocs_clear_clutter = get_option('wpdocs_clear_clutter', array());
3182 $wpdocs_clear_clutter = (is_array($wpdocs_clear_clutter)?$wpdocs_clear_clutter:array());
3183 $wpdocs_clear_clutter[] = array($rm_dir, $zip['path']);
3184 update_option('wpdocs_clear_clutter', $wpdocs_clear_clutter);
3185
3186 //echo $rm_dir;exit;
3187
3188
3189
3190
3191 //echo $zip['path'];exit;
3192
3193
3194 header("Content-type: application/zip");
3195 header("Content-Disposition: attachment; filename=".basename($zip['path'])."");
3196 header("Pragma: no-cache");
3197 header("Expires: 0");
3198 header("Content-length: " . @filesize($zip['path']));
3199 //readfile($zip['path']);
3200
3201 wp_redirect($zip['url']);exit;
3202
3203
3204
3205 }else{
3206 wp_redirect(admin_url('options-general.php?page=wpdocs'));exit;
3207 }
3208
3209 }
3210
3211 if(isset($_GET['clear'])){
3212 global $wpdocs_url, $wpdb, $wpdocs_post_types;
3213 update_option('wpdocs_options', array());
3214 $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->posts WHERE post_type IN ('".implode("','", $wpdocs_post_types)."')"));
3215 wp_redirect(admin_url('options-general.php?page=wpdocs'));exit;
3216 }
3217
3218
3219 }
3220
3221 }
3222
3223 }
3224
3225 function wpdocs_plugin_links($links) {
3226 global $wpdocs_premium_link, $wpdocs_pro;
3227
3228 $settings_link = '<a href="options-general.php?page=wpdocs">'.__('Settings', 'wp-docs').'</a>';
3229
3230 if($wpdocs_pro){
3231 array_unshift($links, $settings_link);
3232 }else{
3233
3234 $wpdocs_premium_link = '<a href="'.esc_url($wpdocs_premium_link).'" title="'.__('Go Premium', 'wp-docs').'" target="_blank">'.__('Go Premium', 'wp-docs').'</a>';
3235 array_unshift($links, $settings_link, $wpdocs_premium_link);
3236
3237 }
3238
3239
3240 return $links;
3241 }
3242
3243 if(!function_exists('wpdocs_get_current_user_items')){
3244
3245 function wpdocs_get_current_user_items($dir_id, $current_user_id){
3246
3247 $current_user_files = array();
3248
3249 if ($dir_id > 0 && wpdocs_folder_exists($dir_id)) {
3250
3251 $wpdocs_items_by_user = get_post_meta($dir_id, 'wpdocs_items_by_user', true);
3252 $wpdocs_items_by_user = is_array($wpdocs_items_by_user)?$wpdocs_items_by_user:array();
3253 $current_user_files = array_key_exists($current_user_id, $wpdocs_items_by_user) ? $wpdocs_items_by_user[$current_user_id] : array();
3254
3255 }
3256
3257 return $current_user_files;
3258
3259 }
3260 }
3261
3262
3263
3264
3265
3266 if(!function_exists('wpdocs_is_file_belong_to_user')){
3267
3268 function wpdocs_is_file_belong_to_user($dir_id, $files, $current_user_id){
3269
3270
3271 if ($dir_id > 0 && wpdocs_folder_exists($dir_id) && count($files) > 0) {
3272
3273
3274 $current_user_files = wpdocs_get_current_user_items($dir_id, $current_user_id);
3275 $current_user_updated_items = array_intersect($current_user_files, $files);
3276
3277 return !empty($current_user_updated_items);
3278
3279
3280 }else{
3281
3282 return false;
3283
3284 }
3285
3286 }
3287 }
3288
3289
3290
3291
3292
3293
3294 if(!function_exists('wpdocs_del_items_by_user')){
3295 function wpdocs_del_items_by_user($dir_id, $files, $current_user_id){
3296
3297
3298 if ($dir_id > 0 && wpdocs_folder_exists($dir_id) && count($files) > 0) {
3299
3300
3301 $wpdocs_items_by_user = get_post_meta($dir_id, 'wpdocs_items_by_user', true);
3302 $current_user_files = wpdocs_get_current_user_items($dir_id, $current_user_id);
3303
3304
3305
3306 $current_user_updated_items = array_diff($current_user_files, $files);
3307
3308
3309
3310 $current_user_updated_items = array_unique($current_user_updated_items);
3311
3312
3313
3314
3315 $wpdocs_items_by_user[$current_user_id] = $current_user_updated_items;
3316
3317
3318
3319 $wpdocs_items_by_user = array_filter($wpdocs_items_by_user);
3320
3321
3322 return update_post_meta($dir_id, 'wpdocs_items_by_user', $wpdocs_items_by_user);
3323
3324 }else{
3325 return false;
3326 }
3327
3328 }
3329 }
3330
3331 add_action('wp_ajax_wp_docs_import_memphis_docs', 'wp_docs_import_memphis_docs');
3332
3333 if(!function_exists('wp_docs_import_memphis_docs')){
3334 function wp_docs_import_memphis_docs(){
3335
3336 $result_array = array(
3337 'status' => false,
3338 );
3339
3340 if(!empty($_POST) && isset($_POST['wp_docs_nonce'])){
3341
3342 if (!wp_verify_nonce( sanitize_wpdocs_data(wp_unslash($_POST['wp_docs_nonce'])), 'wpdocs_update_options_nonce' ) ){
3343
3344 wp_die(__("Sorry, your nonce did not verify.", 'wp-docs'));
3345
3346 }else{
3347
3348 $dir_progress = wp_docs_import_memphis_directories();
3349 $file_progress = wp_docs_memphis_import_files();
3350
3351 $result_array['status'] = ($dir_progress || $file_progress);
3352
3353 if($result_array['status']){
3354 wp_docs_whiteflag_memphis_htaccess();
3355 }
3356
3357 if(!$dir_progress && !$file_progress){
3358
3359 $result_array['remarks'] = __('No directories and files found.', 'wp-docs');
3360 }
3361
3362 }
3363
3364 }
3365
3366 wp_send_json($result_array);
3367 }
3368 }
3369
3370 add_action('wp_ajax_wp_docs_import_memphis_rollback', 'wp_docs_import_memphis_rollback');
3371
3372 if(!function_exists('wp_docs_import_memphis_rollback')){
3373 function wp_docs_import_memphis_rollback(){
3374
3375 $result_array = array(
3376 'status' => false,
3377 );
3378
3379 if(!empty($_POST) && isset($_POST['wp_docs_nonce'])){
3380
3381 if (!wp_verify_nonce( sanitize_wpdocs_data(wp_unslash($_POST['wp_docs_nonce'])), 'wpdocs_update_options_nonce' ) ){
3382
3383 wp_die(__("Sorry, your nonce did not verify.", 'wp-docs'));
3384
3385 }else{
3386
3387 wp_docs_rollback_memphis_import();
3388 $result_array['status'] = true;
3389 }
3390
3391 }
3392
3393 wp_send_json($result_array);
3394 }
3395 }
3396
3397 if(!function_exists('wp_docs_get_memphis_name')){
3398 function wp_docs_get_memphis_name(){
3399 global $wpdb;
3400 $name = esc_sql('Memphis Documents');
3401
3402 $query = $wpdb->prepare("SELECT max(ID) FROM $wpdb->posts WHERE post_title LIKE '%$name%'");
3403
3404 $result = $wpdb->get_var($query);
3405 if($result){
3406
3407 $post = get_post($result);
3408
3409 $title_array = explode(' ', $post->post_title);
3410 $last_elment = end($title_array);
3411
3412 if(is_numeric($last_elment)){
3413 $last_elment++;
3414 }else{
3415 $last_elment = 1;
3416 }
3417
3418 $name .= ' '.$last_elment;
3419
3420 }
3421
3422
3423 return $name;
3424 }
3425 }
3426
3427 if(!function_exists('wp_docs_get_memphis_dir_id')){
3428 function wp_docs_get_memphis_dir_id(){
3429 global $wpdb;
3430
3431 $name = esc_sql('Memphis Documents');
3432
3433 $dir_id = 0;
3434
3435 $query = $wpdb->prepare("SELECT max(ID) FROM $wpdb->posts WHERE post_title LIKE '%$name%'");
3436
3437 $result = $wpdb->get_var($query);
3438 if($result){
3439 $dir_id = $result;
3440 }
3441
3442
3443 return $dir_id;
3444 }
3445 }
3446
3447 if(!function_exists('wp_docs_import_memphis_directories')){
3448
3449 function wp_docs_import_memphis_directories(){
3450 global $wp_docs_is_memphis;
3451
3452 $progress_status = false;
3453
3454 if(!$wp_docs_is_memphis){
3455
3456 }else{
3457
3458 $memphis_folders_array = get_option('mdocs-cats', array());
3459
3460 if(!empty($memphis_folders_array)){
3461
3462 extract(wp_docs_count_memphis_folder($memphis_folders_array));
3463
3464 if($import_folder_count != $total_folder_count){
3465
3466 $parent_id = wp_docs_get_memphis_dir_id();
3467 if($parent_id == 0){
3468
3469 $parent_id = wpdocs_create_folder_post(0, 'Memphis Documents');
3470 }
3471 wp_docs_memphis_create_directory($memphis_folders_array, $parent_id);
3472
3473 $progress_status = true;
3474
3475 }
3476
3477 }
3478
3479 }
3480
3481 return $progress_status;
3482 }
3483
3484 }
3485
3486 if(!function_exists('wp_docs_memphis_create_directory')){
3487
3488 function wp_docs_memphis_create_directory($directory_list, $base_parent_id){
3489 global $wp_docs_is_memphis, $wpdocs_imported_folder, $memphis_folders_id;
3490 if(!$wp_docs_is_memphis){
3491
3492 }else{
3493
3494
3495 if(!empty($directory_list)){
3496
3497 foreach ($directory_list as $key => $single_directory) {
3498 # code...
3499
3500 $slug = $single_directory['slug'];
3501 $name = $single_directory['name'];
3502 $child_dir_list = $single_directory['children'];
3503 $slug_key = $memphis_folders_id.'_'.$slug;
3504
3505 if(in_array($slug_key, $wpdocs_imported_folder)) continue;
3506 $current_parent_id = wpdocs_create_folder_post($base_parent_id, $name);
3507 if($current_parent_id){
3508
3509 update_post_meta($current_parent_id, '_wpdocs_memphis_slug', $slug_key);
3510 $wpdocs_imported_folder[] = $slug_key;
3511 if(!empty($child_dir_list)){
3512 wp_docs_memphis_create_directory($child_dir_list, $current_parent_id);
3513 }
3514
3515 }
3516
3517 }
3518
3519 update_option('wpdocs_imported_folder', $wpdocs_imported_folder);
3520 }
3521
3522 }
3523 }
3524
3525 }
3526
3527
3528 if(!function_exists('wp_docs_count_memphis_folder')){
3529 function wp_docs_count_memphis_folder($memphis_folders, $total_folder_count = 0, $import_folder_count = 0){
3530 global $memphis_folders_id, $wpdocs_imported_folder;
3531
3532 if(!empty($memphis_folders)){
3533 foreach ($memphis_folders as $key => $folder) {
3534 # code...
3535 $children = $folder['children'];
3536 $slug = $folder['slug'];
3537 $slug_key = $memphis_folders_id.'_'.$slug;
3538 $total_folder_count++;
3539
3540 if(in_array($slug_key, $wpdocs_imported_folder)){
3541 $import_folder_count++;
3542 }
3543
3544 if(!empty($children)){
3545 extract(wp_docs_count_memphis_folder($children, $total_folder_count, $import_folder_count));
3546 }
3547 }
3548 }
3549
3550 return array('total_folder_count' => $total_folder_count, 'import_folder_count' => $import_folder_count);
3551
3552 }
3553 }
3554
3555 if(!function_exists('wp_docs_count_memphis_files')){
3556 function wp_docs_count_memphis_files(){
3557
3558 global $memphis_files_array, $wpdocs_imported_files, $wpdocs_memphis_list;
3559
3560 $total_file_count = (count($memphis_files_array) + count($wpdocs_memphis_list));
3561
3562 return array('total_file_count' => $total_file_count, 'import_file_count' => count($wpdocs_memphis_list));
3563
3564 }
3565 }
3566
3567 if(!function_exists('wp_docs_memphis_statistics')){
3568 function wp_docs_memphis_statistics(){
3569 global $memphis_folders_array;
3570 //pree($memphis_folders_array);
3571 extract(wp_docs_count_memphis_folder($memphis_folders_array));
3572 extract(wp_docs_count_memphis_files());
3573
3574 return array(
3575 'total_folder' => $total_folder_count,
3576 'import_folder' => $import_folder_count,
3577 'total_files' => $total_file_count,
3578 'import_files' => $import_file_count,
3579 );
3580
3581 }
3582 }
3583
3584
3585 if(!function_exists('wp_docs_relocate_memphis_meta')){
3586 function wp_docs_relocate_memphis_meta($dir_id){
3587 global $wpdocs_imported_files, $wpdocs_imported_folder;
3588
3589 // Ensure arrays are initialized properly before using them
3590 $wpdocs_imported_files = (is_array($wpdocs_imported_files) ? $wpdocs_imported_files : array());
3591 $wpdocs_imported_folder = (is_array($wpdocs_imported_folder) ? $wpdocs_imported_folder : array());
3592
3593 $wpdocs_items = get_post_meta($dir_id, 'wpdocs_items', true);
3594 $wpdocs_items = (is_array($wpdocs_items) ? $wpdocs_items : array());
3595 $dir_slug = get_post_meta($dir_id, '_wpdocs_memphis_slug', true);
3596
3597 if(!empty($wpdocs_items)){
3598 $wpdocs_imported_files = array_diff($wpdocs_imported_files, $wpdocs_items);
3599 }
3600
3601 if($dir_slug){
3602 $wpdocs_imported_folder = array_diff($wpdocs_imported_folder, array($dir_slug));
3603 }
3604
3605 update_option('wpdocs_imported_folder', $wpdocs_imported_folder);
3606 update_option('wpdocs_imported_files', $wpdocs_imported_files);
3607 }
3608 }
3609
3610
3611 if(!function_exists('wp_docs_memphis_import_files')){
3612 function wp_docs_memphis_import_files(){
3613 global $memphis_folders_id, $memphis_files_array, $wpdocs_imported_files, $wpdocs_memphis_list, $wpdocs_post_types;
3614
3615 $before_count = count($wpdocs_imported_files);
3616 if(!empty($memphis_files_array)){
3617
3618 foreach($memphis_files_array as $file_index => $file_data){
3619 $attachment_id = $file_data['id'];
3620 $attachment_folder = $file_data['cat'];
3621 $slug_key = $memphis_folders_id.'_'.$attachment_folder;
3622 $files = array($attachment_id);
3623 $upload_dir = wp_upload_dir();
3624 $upload_base_url = $upload_dir['baseurl'];
3625
3626 if(in_array($attachment_id, $wpdocs_imported_files)){continue;}
3627
3628 $dir_arg = array(
3629 'post_type' => $wpdocs_post_types,
3630 'numberposts' => '-1',
3631 'post_status' => 'any',
3632 'fields' => 'ids',
3633 'meta_query' => array(
3634 array(
3635 'key' => '_wpdocs_memphis_slug',
3636 'value' => $slug_key,
3637 'compare' => '='
3638 )
3639 )
3640 );
3641
3642 $dir_list = get_posts($dir_arg);
3643
3644 if(!empty($dir_list)){
3645 foreach($dir_list as $dir_id){
3646 update_post_meta($attachment_id, '_wpdocs_memphis_media_file', true);
3647 update_post_meta($attachment_id, '_wpdocs_memphis_file_id', $file_data['id']);
3648
3649 $wpdocs_imported_files[] = $attachment_id;
3650 wpdocs_update_files_meta($dir_id, $files);
3651 }
3652 unset($memphis_files_array[$file_index]);
3653 $wpdocs_memphis_list[] = $file_data;
3654 }
3655 }
3656
3657 update_option('mdocs-list', $memphis_files_array);
3658 update_option('wpdocs_memphis_list', $wpdocs_memphis_list);
3659 update_option('wpdocs_imported_files', $wpdocs_imported_files);
3660 }
3661 $after_count = count($wpdocs_imported_files);
3662
3663 return ($before_count != $after_count);
3664 }
3665 }
3666
3667
3668 add_filter('pre_delete_attachment', 'wpdocs_delete_attachment_callback', 10, 3);
3669
3670 if(!function_exists('wpdocs_delete_attachment_callback')){
3671 function wpdocs_delete_attachment_callback($check, $post, $force_delete){
3672
3673 $wpdoc_memphis_media_file = get_post_meta($post->ID, '_wpdocs_memphis_media_file', true);
3674 $is_memphis_media = strpos($post->post_content, 'mdocs_media_attachment');
3675
3676 if($wpdoc_memphis_media_file && $is_memphis_media){
3677 $post->post_content = '';
3678 wp_update_post($post);
3679 return $post;
3680 }else{
3681 return $check;
3682 }
3683
3684 }
3685 }
3686
3687 add_action('pre_uninstall_plugin', 'wp_docs_save_attachments_to_del');
3688
3689 if(!function_exists('wp_docs_save_attachments_to_del')){
3690
3691 function wp_docs_save_attachments_to_del($plugin){
3692
3693 global $wpdocs_imported_folder, $wpdocs_imported_files, $wpdocs_memphis_list;
3694
3695 $wpdocs_memphis_list = get_option('wpdocs_memphis_list', array());
3696
3697
3698 if($plugin == 'memphis-documents-library/memphis-documents.php'){
3699 if(!empty($wpdocs_memphis_list)){
3700 if(wp_docs_memphis_folder_preserve('mdocs', 'mdocs_2')){
3701 update_option('wpdocs_memphis_uninstall', true);
3702 }
3703
3704 $wpdocs_imported_folder = array();
3705 $wpdocs_imported_files = array();
3706 $wpdocs_memphis_list = array();
3707
3708 update_option('wpdocs_imported_folder', $wpdocs_imported_folder);
3709 update_option('wpdocs_imported_files', $wpdocs_imported_files);
3710 update_option('wpdocs_memphis_list', $wpdocs_memphis_list);
3711 }
3712
3713
3714 }
3715
3716
3717
3718 }
3719
3720 }
3721
3722 if(!function_exists('wp_docs_memphis_folder_preserve')){
3723 function wp_docs_memphis_folder_preserve($from, $to){
3724
3725 $upload_dir = wp_upload_dir();
3726 $upload_basedir = $upload_dir['basedir'];
3727 $memphis_dir = $upload_basedir.'/'.$from;
3728 $bak_file = $memphis_dir.'/mdocs-files.bak';
3729
3730 if(file_exists($bak_file)){
3731
3732 try {
3733 unlink($bak_file);
3734 } catch (\Exception $ex) {
3735 //throw $th;
3736 }
3737 }
3738 $status = false;
3739
3740
3741 if(file_exists($memphis_dir)){
3742 $status = rename($memphis_dir, $upload_basedir.'/'.$to);
3743 }
3744
3745 return $status;
3746 }
3747 }
3748
3749 if(!function_exists('wp_docs_whiteflag_memphis_htaccess')){
3750 function wp_docs_whiteflag_memphis_htaccess(){
3751
3752 $upload_dir = wp_upload_dir();
3753 $basedir = $upload_dir['basedir'];
3754
3755 $memphis_dir = $basedir.'/mdocs/';
3756
3757 if(is_dir($memphis_dir)){
3758
3759 $memphis_dir_ht = $memphis_dir.'.htaccess';
3760 $memphis_dir_index = $memphis_dir.'index.html';
3761
3762 if(file_exists($memphis_dir_ht)){
3763 if(!file_exists($memphis_dir_index)){
3764 file_put_contents($memphis_dir_index, '');
3765 }
3766 /*file_put_contents($memphis_dir_ht, 'Allow from all
3767 Options +Indexes
3768 ');*/
3769 unlink($memphis_dir_ht);
3770 }
3771 }
3772
3773 }
3774 }
3775
3776 if(!function_exists('wp_docs_rollback_memphis_import')){
3777 function wp_docs_rollback_memphis_import(){
3778
3779 global $memphis_files_array, $wpdocs_imported_folder, $wpdocs_imported_files, $wpdocs_memphis_list, $wpdocs_post_types;
3780
3781
3782 $wp_docs_args = array(
3783 'post_type' => $wpdocs_post_type['dir'],
3784 'post_status' => 'any',
3785 'numberposts' => -1,
3786 'meta_query' => array(
3787 array(
3788 'key' => '_wpdocs_memphis_slug',
3789 'compare' => 'EXIST'
3790 )
3791 )
3792 );
3793
3794 $all_memphis_folder = get_posts($wp_docs_args);
3795
3796 if(!empty($all_memphis_folder)){
3797 foreach($all_memphis_folder as $m_folder){
3798 wpdocs_recursive_delete_folder($m_folder->ID);
3799 }
3800 }
3801
3802 if(!empty($wpdocs_memphis_list)){
3803 foreach($wpdocs_memphis_list as $file_index => $file_data){
3804 delete_post_meta($file_data['id'], '_wpdocs_memphis_media_file');
3805 unset($wpdocs_memphis_list[$file_index]);
3806 $memphis_files_array[] = $file_data;
3807
3808 }
3809 }
3810
3811 update_option('mdocs-list', $memphis_files_array);
3812 update_option('wpdocs_memphis_list', $wpdocs_memphis_list);
3813 update_option('wpdocs_imported_files', array());
3814 }
3815 }
3816
3817 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=''){
3818 global $wpdocs_pro;
3819 $dir_option_class = '';
3820 if($dir){
3821 $dir_option_class = 'wpdocs_dir_options';
3822 $is_file = wpdocs_dir_options_default('file_upload', false, $dir);
3823 $is_current_user_files = wpdocs_dir_options_default('current_user_files', false, $dir);
3824 $is_del_from_front = (is_user_logged_in() && wpdocs_dir_options_default('del_from_front', false, $dir));
3825 $allowed_role = wpdocs_dir_options_default('allowed_role', array(), $dir);
3826 $allowed_ext = wpdocs_dir_options_default('allowed_ext', '', $dir);
3827 $default_ext = '';
3828
3829 $breadcrumb = get_the_title($dir);
3830 ?>
3831 <small class="alert alert-success d-block"><i class="fas fa-chevron-right"></i> <?php echo esc_html($breadcrumb); ?></small>
3832 <?php
3833
3834 }
3835 ?>
3836 <label for="wpdocs_options_file">
3837 <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" />
3838 <?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>
3839 <a href="https://www.youtube.com/embed/flFmqpJCwYk" target="_blank"><?php echo __('Video Tutorial', 'wp-docs'); ?></a>
3840 </label>
3841
3842
3843
3844 <ul class="ml-4 <?php echo $is_file ? '' : 'd-none'?>">
3845 <li>
3846 <label for="wpdocs_options_current_user_files">
3847 <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" />
3848 <?php echo __('Do not make files public uploaded by users', 'wp-docs'); ?> <small><?php echo $wpdocs_pro?__('(Optional)', 'wp-docs'):__('(Premium)', 'wp-docs'); ?></small>
3849 </label>
3850 </li>
3851
3852 <li>
3853 <label for="wpdocs_options_del_from_front">
3854 <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" />
3855 <?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>
3856 </label>
3857 </li>
3858
3859 <li>
3860 <label for="wpdocs_options_allowed_role">
3861 <?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>
3862 </label>
3863
3864
3865
3866 <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'); ?>">
3867
3868 <?php echo wpdocs_get_user_roles_options($allowed_role) ?>
3869
3870 </select>
3871
3872
3873 </li>
3874
3875 <li>
3876 <label for="wpdocs_options_allowed_ext">
3877 <?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>
3878 </label>
3879 <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); ?>" />
3880
3881 </li>
3882
3883 </ul>
3884 <?php
3885 }
3886
3887 if(!function_exists('wpdocs_dir_options_by_name')){
3888 function wpdocs_dir_options_by_name($option_name, $default_return = false, $dir = 0){
3889
3890 global $wpdocs_options;
3891
3892 $dir_options = array();
3893
3894 if($dir > 0){
3895 $dir_options = get_post_meta($dir, '_wpdocs_dir_options', true);
3896 $dir_options = (is_array($dir_options) ? $dir_options : array());
3897 }
3898
3899 $key_exist = false;
3900 $search_options = array();
3901
3902 if(array_key_exists($option_name, $dir_options)){
3903 $search_options = $dir_options;
3904 $key_exist = true;
3905
3906
3907 }else if(array_key_exists($option_name, $wpdocs_options)){
3908
3909 $search_options = $wpdocs_options;
3910 $key_exist = true;
3911 }
3912
3913 if($key_exist){
3914
3915 $return_value = $search_options[$option_name];
3916 $return_value = (is_array($default_return) && !is_array($return_value) ? array() : $return_value);
3917 $default_return = $return_value;
3918
3919 }
3920
3921 if($default_return == 'true'){
3922 $default_return = true;
3923 }elseif($default_return == 'false'){
3924 $default_return = false;
3925 }
3926
3927 return $default_return;
3928 }
3929 }
3930
3931 if(!function_exists('wpdocs_dir_options_default')){
3932 function wpdocs_dir_options_default($option_name, $default_return = false, $dir = 0){
3933
3934 global $wpdocs_options;
3935
3936 $dir_options = array();
3937
3938 if($dir > 0){
3939 $dir_options = get_post_meta($dir, '_wpdocs_dir_options', true);
3940 $dir_options = (is_array($dir_options) ? $dir_options : array());
3941 }
3942
3943 $key_exist = false;
3944 $search_options = array();
3945
3946 if(array_key_exists($option_name, $dir_options)){
3947 $search_options = $dir_options;
3948 $key_exist = true;
3949 }
3950
3951 if($key_exist){
3952
3953 $return_value = $search_options[$option_name];
3954 $return_value = (is_array($default_return) && !is_array($return_value) ? array() : $return_value);
3955 $default_return = $return_value;
3956
3957 }
3958
3959 if($default_return == 'true'){
3960 $default_return = true;
3961 }elseif($default_return == 'false'){
3962 $default_return = false;
3963 }
3964
3965 return $default_return;
3966 }
3967 }
3968
3969 if(!function_exists('wpdocs_get_dir_restrictions')){
3970 function wpdocs_get_dir_restrictions($dir = 0, $rest_type = 'array'){
3971
3972 $dir_restrictions = array();
3973
3974 if($dir > 0){
3975 $dir_options = get_post_meta($dir, '_wpdocs_dir_options', true);
3976 $dir_options = (is_array($dir_options) ? $dir_options : array());
3977 $is_file_upload = array_key_exists('file_upload', $dir_options) && $dir_options['file_upload'] == 'true';
3978 $dir_restrictions = $dir_options;
3979 }
3980
3981
3982 switch ($rest_type) {
3983 case 'array':
3984 # code...
3985 return $dir_restrictions;
3986 break;
3987
3988 case 'json':
3989 # code...
3990 if(!empty($dir_options)){
3991 return wp_json_encode($dir_restrictions);
3992
3993 }else{
3994 return '';
3995 }
3996 break;
3997
3998 case 'base64':
3999 # code...
4000
4001 if(!empty($dir_options)){
4002 return base64_encode(wp_json_encode($dir_restrictions));
4003 }else{
4004 return '';
4005 }
4006 break;
4007
4008 }
4009
4010
4011
4012 }
4013 }
4014
4015
4016 add_action('init', function(){
4017
4018 global $wpdocs_current_theme;
4019 $wpdocs_current_theme = str_replace(array('-', ' '), '_', strtolower(wp_get_theme()));
4020
4021 // return;
4022 // wpdoc_get_dir_children(8764);
4023 });
4024
4025 if(!function_exists('wpdoc_get_dir_children')){
4026 function wpdoc_get_dir_children($parent_id){
4027
4028 global $wpdocs_post_types;
4029
4030 $all_folder_query = new WP_Query();
4031 $all_folder = $all_folder_query->query(array('post_type' => $wpdocs_post_types, 'post_status' => 'any', 'numberposts' => -1));
4032
4033 $all_folders_array = get_page_children( $parent_id, $all_folder );
4034 $all_folders_array = array_map(function($single){return $single->ID;}, $all_folders_array);
4035
4036 return $all_folders_array;
4037
4038 }
4039 }
4040
4041 if(!function_exists('wpdoc_humanize')){
4042 function wpdoc_humanize($str){
4043 return ucwords(str_replace(array('-', '_'), ' ', $str));
4044 }
4045 }
4046 include_once('functions-verify.php');