PluginProbe
WP Docs / 2.2.9
WP Docs v2.2.9
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.9, at inc/functions.php

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