PluginProbe
WP Docs / 2.2.8
WP Docs v2.2.8
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.2.8, at inc/functions.php

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