PluginProbe
WP Docs / 2.2.1
WP Docs v2.2.1
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.1, at inc/functions.php

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