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

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

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