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

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

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