PluginProbe
WP Docs / trunk
WP Docs vtrunk
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 trunk, at inc/functions.php

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