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

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

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