PluginProbe
WP Docs / 2.3.2
WP Docs v2.3.2
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
← All changes | inc/functions.php +165 -9 2.3.02.3.2 View file →
@@ -1,6 +1,18 @@
1 1 <?php
2 -
2 + if(!function_exists('wpdocs_secure_url')){
3 + function wpdocs_secure_url($file_id=''){
4 +
5 + $ret = add_query_arg(
6 + array(
7 + 'wpdocs_dl' => $file_id,
8 + 'wpdocs_nonce' => wp_create_nonce('wpdocs_dl_'.$file_id),
9 + ),
10 + home_url('/')
11 + );
12 + return $ret;
13 + }
14 + }
3 15 if(!function_exists('wp_docs_get_memphis_dir_option_id')){
4 16 function wp_docs_get_option_id($option_name){
5 17 global $wpdb;
6 18 $option_name = esc_sql( $option_name );
@@ -44,8 +56,10 @@
44 56 function wpdocs_admin_enqueue_script()
45 57 {
46 58 if (isset($_GET['page']) && $_GET['page'] == 'wpdocs') {
47 59
60 + //pree(get_option('mdocs-list'));exit;
61 +
48 62 global $wpdocs_pro, $wpdocs_options;
49 63
50 64 wp_enqueue_script('wpdocs_boostrap', plugin_dir_url(dirname(__FILE__)) . 'js/bootstrap.min.js', array('jquery'));
51 65 wp_enqueue_style('wpdocs-boostrap', plugins_url('css/bootstrap.min.css', dirname(__FILE__)));
@@ -65,8 +79,9 @@
65 79 wp_enqueue_style('wpdocs-common', plugins_url('css/common-styles.css', dirname(__FILE__)), array(), date('Ymdhi'));
66 80 wp_enqueue_style('wpdocs-admin', plugins_url('css/admin-styles.css', dirname(__FILE__)), array(), date('Ymdhi'));
67 81
68 82 wp_enqueue_script('wpdocs_admin_scripts', plugin_dir_url(dirname(__FILE__)) . 'js/admin-scripts.js', array('jquery', 'jquery-ui-dialog'), time());
83 + wp_enqueue_script('wpdocs_verify_scripts', plugin_dir_url(dirname(__FILE__)) . 'js/verify-scripts.js', array('jquery', 'jquery-ui-dialog'), time());
69 84
70 85 if($wpdocs_pro){
71 86 wp_enqueue_script('wpdocs_pro_scripts', plugin_dir_url(dirname(__FILE__)) . 'pro/wp-docs-admin.js?t='.time(), array('jquery'));
72 87 }
@@ -110,8 +125,55 @@
110 125 'rename_confirm' => __('Please enter new folder name:', 'wp-docs'),
111 126
112 127 )
113 128 );
129 +
130 + wp_localize_script(
131 + 'wpdocs_verify_scripts',
132 + 'wpdocs_vars',
133 + array(
134 + 'ajax_url' => admin_url('admin-ajax.php'),
135 + 'url' => admin_url('options-general.php?page=wpdocs'),
136 + 'nonce' => wp_create_nonce('wpdocs_verify_nonce'),
137 + 'preparing_queue' => __('Preparing verification queue...', 'wp-docs'),
138 + 'unable_to_start' => __('Unable to start verification.', 'wp-docs'),
139 + 'ajax_error' => __('AJAX error.', 'wp-docs'),
140 + 'verification_failed' => __('Verification failed.', 'wp-docs'),
141 + 'verification_completed' => __('Verification completed.', 'wp-docs'),
142 + 'verification_interrupted' => __('Verification interrupted.', 'wp-docs'),
143 + 'checking_folder' => __('Checking Folder:', 'wp-docs'),
144 + 'checking_file' => __('Checking File:', 'wp-docs'),
145 + 'unknown_file' => __('Unknown File', 'wp-docs'),
146 + 'items_processed' => __('items processed', 'wp-docs'),
147 + 'total_folders' => __('Total Folders', 'wp-docs'),
148 + 'verified_folders' => __('Verified Folders', 'wp-docs'),
149 + 'missing_folders' => __('Missing Folders', 'wp-docs'),
150 + 'total_files' => __('Total Files', 'wp-docs'),
151 + 'verified_files' => __('Verified Files', 'wp-docs'),
152 + 'missing_files' => __('Missing Files', 'wp-docs'),
153 + 'missing_folder' => __('MISSING FOLDER', 'wp-docs'),
154 + 'missing_file' => __('MISSING FILE', 'wp-docs'),
155 + 'no_items_display' => __('No items to display.', 'wp-docs'),
156 + 'import_in_progress' => __('Import is already in progress. Please wait.', 'wp-docs'),
157 + 'import_missing_confirm' => __('This will import only missing folders and files. Do you want to continue?', 'wp-docs'),
158 + 'initializing' => __('Initializing...', 'wp-docs'),
159 + 'preparing_import_queue' => __('Preparing import queue...', 'wp-docs'),
160 + 'unable_to_start_import' => __('Unable to start import.', 'wp-docs'),
161 + 'import_failed' => __('Import failed.', 'wp-docs'),
162 + 'import_completed' => __('Import completed!', 'wp-docs'),
163 + 'refreshing_results' => __('Refreshing verification results...', 'wp-docs'),
164 + 'import_interrupted' => __('Import interrupted. Please try again.', 'wp-docs'),
165 + 'creating_folder' => __('Creating Folder:', 'wp-docs'),
166 + 'importing_file' => __('Importing File:', 'wp-docs'),
167 + 'path' => __('Path:', 'wp-docs'),
168 + 'target' => __('Target:', 'wp-docs'),
169 + 'folders_imported' => __('Folders imported:', 'wp-docs'),
170 + 'files_imported' => __('Files imported:', 'wp-docs'),
171 + 'failed' => __('Failed:', 'wp-docs'),
172 + 'please_wait' => __('Please wait...', 'wp-docs'),
173 + 'import_missing_items' => __('Import Missing Items Only', 'wp-docs'),
174 + )
175 + );
114 176 }
115 177 }
116 178
117 179 add_filter( 'ajax_query_attachments_args', 'wpdocs_filter_media');
@@ -747,8 +809,9 @@
747 809
748 810
749 811
750 812 return array(
813 + 'file_id' => $item,
751 814 'file_url' => esc_url($file_url),
752 815 'ext' => esc_attr($ext),
753 816 'filename' => esc_attr($filename),
754 817 'title' => esc_html($filename),
@@ -813,9 +876,9 @@
813 876
814 877 $item_data = wpd_get_item_type_icon_url($item);
815 878 extract($item_data);
816 879
817 - //pree($item_data);
880 + //pree($item_data);exit;
818 881 //pree($wp_uploads_path);exit;
819 882
820 883 $icon_str = '<img src="' . esc_url($icon_url) . '" style="" alt="' . esc_attr($title) . '">';
821 884
@@ -877,10 +940,14 @@
877 940 //$class .= 'fa-file';
878 941 break;
879 942 }
880 943 $class = '';
944 +
945 +
946 + $secured_file_url = wpdocs_secure_url($file_id);
947 +
881 948 $files_list[ $title ] = '<li data-id="' . esc_attr( $item ) . '" data-dir="' . esc_attr( $dir ) . '" title="' . esc_attr( $filename ) . '">
882 - <a href="' . esc_url( $file_url ) . '" target="_blank" class="file ' . esc_attr( $class ) . '"> ' . $icon_str . ' </a>
949 + <a href="' . esc_url( $secured_file_url ) . '" target="_blank" class="file ' . esc_attr( $class ) . '"> ' . $icon_str . ' </a>
883 950 <a class="ftitle" title="' . esc_attr( $title ) . '">' . esc_html( $title ) . '</a>
884 951 <span class="wpd_action_span">
885 952 <a href="' . esc_url( 'upload.php?item=' . $item ) . '" target="_blank" class="wpd-edit" title="' . esc_attr__( 'Click here to edit', 'wp-docs' ) . '"></a>
886 953 <span class="wpd_action_span_inner">
@@ -1416,14 +1483,16 @@
1416 1483 default:
1417 1484 //$class .= 'fa-file';
1418 1485 break;
1419 1486 }
1487 +
1488 + $secured_file_url = wpdocs_secure_url($file_id);
1420 1489
1421 1490 $file_list_row = '
1422 1491
1423 1492 <div title="'.esc_attr($filename).'" class="col-4 col-md-3 is_file text-center is_shallow" style="cursor: pointer;" data-id="'.esc_attr($file).'">
1424 1493 <figure class="figure file_view p-1">
1425 - <a href="'.esc_url($file_url).'" target="_blank" class="file">
1494 + <a href="'.esc_url($secured_file_url).'" target="_blank" class="file">
1426 1495 <img class="my-3" src="'.esc_url($icon_url).'" />
1427 1496 </a>
1428 1497 <figcaption class="figure-caption text-center">'.esc_html($title).'</figcaption>
1429 1498 </figure>
@@ -1501,14 +1570,16 @@
1501 1570 default:
1502 1571 //$class .= 'fa-file';
1503 1572 break;
1504 1573 }
1574 +
1575 + $secured_file_url = wpdocs_secure_url($file_id);
1505 1576
1506 1577 $file_list_row = '
1507 1578
1508 1579 <div title="'.esc_attr($filename).'" class="col-4 col-md-3 is_file text-center is_deep" style="cursor: pointer;" data-id="'.esc_attr($file).'">
1509 1580 <figure class="figure file_view p-1">
1510 - <a href="'.esc_url($file_url).'" target="_blank" class="file">
1581 + <a href="'.esc_url($secured_file_url).'" target="_blank" class="file">
1511 1582 <img class="my-3" src="'.esc_url($icon_url).'" />
1512 1583 </a>
1513 1584 <figcaption class="figure-caption text-center">'.esc_html($title).'</figcaption>
1514 1585 </figure>
@@ -1601,13 +1672,15 @@
1601 1672 extract($file_data);
1602 1673
1603 1674
1604 1675 if(trim($file_url)){
1676 +
1677 + $secured_file_url = wpdocs_secure_url($file_id);
1605 1678
1606 1679 $file_list_row = '
1607 1680 <div title="'.esc_attr($filename).'" class="col-12 file_wrapper is_file" style="cursor: pointer;" data-id="'.$file.'">
1608 1681 <figure class="figure file_view p-3">
1609 - <a href="'.$file_url.'" target="_blank" class="file" ><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></a>
1682 + <a href="'.$secured_file_url.'" target="_blank" class="file" ><img class="mb-2" src="'.$icon_url.'" style="width: 25px; height: 25px"></a>
1610 1683 <small class="text-center">'.$title.'</small>
1611 1684 </figure>
1612 1685 </div>';
1613 1686
@@ -1798,11 +1871,11 @@
1798 1871 extract($file_data);
1799 1872 //pree($ts);
1800 1873
1801 1874 if(trim($icon_url)){
1802 -
1875 + $secured_file_url = wpdocs_secure_url($file_id);
1803 1876 $files_list_row = '
1804 - <tr title="'.esc_attr($filename).'" data-url="'.$file_url.'" class="file_view file_link is_file" style="cursor: pointer;" data-id="'.$file.'">
1877 + <tr title="'.esc_attr($filename).'" data-url="'.$secured_file_url.'" class="file_view file_link is_file" style="cursor: pointer;" data-id="'.$file.'">
1805 1878
1806 1879 <td>
1807 1880
1808 1881 <figure class="figure file_view">
@@ -1855,11 +1928,13 @@
1855 1928 extract($file_data);
1856 1929 //pree($ts);
1857 1930
1858 1931 if(trim($icon_url)){
1932 +
1933 + $secured_file_url = wpdocs_secure_url($file_id);
1859 1934
1860 1935 $files_list_row = '
1861 - <tr title="'.esc_attr($filename).'" data-url="'.$file_url.'" class="file_view file_link is_file is_deep" style="cursor: pointer;" data-id="'.$file.'">
1936 + <tr title="'.esc_attr($filename).'" data-url="'.$secured_file_url.'" class="file_view file_link is_file is_deep" style="cursor: pointer;" data-id="'.$file.'">
1862 1937
1863 1938 <td>
1864 1939
1865 1940 <figure class="figure file_view">
@@ -2744,13 +2819,91 @@
2744 2819 return $ret;
2745 2820
2746 2821 }
2747 2822 }
2823 + if(!function_exists('wpdocs_file_download')){
2824 + function wpdocs_file_download(){
2825 +
2826 + if(empty($_GET['wpdocs_dl'])){
2827 + return;
2828 + }
2829 +
2830 + $file_id = absint(
2831 + wp_unslash($_GET['wpdocs_dl'])
2832 + );
2833 +
2834 + if(!$file_id){
2835 + status_header(404);
2836 + exit;
2837 + }
2838 +
2839 + $nonce = isset($_GET['wpdocs_nonce'])
2840 + ? sanitize_text_field(
2841 + wp_unslash($_GET['wpdocs_nonce'])
2842 + )
2843 + : '';
2844 +
2845 + if(
2846 + !wp_verify_nonce(
2847 + $nonce,
2848 + 'wpdocs_dl_' . $file_id
2849 + )
2850 + ){
2851 + status_header(403);
2852 + exit;
2853 + }
2854 +
2855 + // Adjust this according to where you store the file
2856 + $file = get_attached_file($file_id);
2857 +
2858 + if(
2859 + !$file ||
2860 + !file_exists($file)
2861 + ){
2862 + status_header(404);
2863 + exit;
2864 + }
2865 +
2866 + $uploads = wp_get_upload_dir();
2867 + $base_real = realpath($uploads['basedir']);
2868 + $file_real = realpath($file);
2869 +
2870 + if(
2871 + !$base_real ||
2872 + !$file_real ||
2873 + strpos(
2874 + $file_real,
2875 + $base_real . DIRECTORY_SEPARATOR
2876 + ) !== 0
2877 + ){
2878 + status_header(403);
2879 + exit;
2880 + }
2881 +
2882 + $mime = wp_check_filetype($file_real);
2883 + $mime = !empty($mime['type'])
2884 + ? $mime['type']
2885 + : 'application/octet-stream';
2886 +
2887 + header('Content-Type: ' . $mime);
2888 + header('Content-Length: ' . filesize($file_real));
2889 + header(
2890 + 'Content-Disposition: inline; filename="' .
2891 + basename($file_real) .
2892 + '"'
2893 + );
2894 +
2895 + readfile($file_real);
2896 + exit;
2897 + }
2898 + }
2748 2899
2749 2900 add_action('init', 'wpdocs_dir_actions');
2750 2901 if(!function_exists('wpdocs_dir_actions')){
2751 2902 function wpdocs_dir_actions(){
2752 2903
2904 + wpdocs_file_download();
2905 +
2753 2906 if(is_admin() && get_option('wpdocs_memphis_uninstall')){
2754 2907 if(wp_docs_memphis_folder_preserve('mdocs_2', 'mdocs')){
2755 2908 update_option('wpdocs_memphis_uninstall', false);
2756 2909 }
@@ -3264,8 +3417,10 @@
3264 3417
3265 3418 if(!empty($dir_list)){
3266 3419 foreach($dir_list as $dir_id){
3267 3420 update_post_meta($attachment_id, '_wpdocs_memphis_media_file', true);
3421 + update_post_meta($attachment_id, '_wpdocs_memphis_file_id', $file_data['id']);
3422 +
3268 3423 $wpdocs_imported_files[] = $attachment_id;
3269 3424 wpdocs_update_files_meta($dir_id, $files);
3270 3425 }
3271 3426 unset($memphis_files_array[$file_index]);
@@ -3661,4 +3816,5 @@
3661 3816 function wpdoc_humanize($str){
3662 3817 return ucwords(str_replace(array('-', '_'), ' ', $str));
3663 3818 }
3664 3819 }
3820 + include_once('functions-verify.php');