PluginProbe
WP Docs / 2.2.0
WP Docs v2.2.0
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.0, at inc/functions.php

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