|
1 <?php |
|
2 /* |
|
3 Plugin Name: WP Explorer |
|
4 Plugin URI: http://www.t3-design.com/ |
|
5 Description: A simple file indexing plugin with custom rules |
|
6 Version: 0.5 |
|
7 Author: Chris T. |
|
8 Author URI: http://www.t3-design.com/ |
|
9 |
|
10 2010-01-18 Edited By samuel Huron for MP3 player |
|
11 2010-01-18 Edited By samuel Huron for Downloader filter .iri |
|
12 */ |
|
13 |
|
14 add_action('init', 'wp_explorer_getvar'); |
|
15 function wp_explorer_getvar($var = '') |
|
16 { |
|
17 if (!in_array($var, array('REQUEST_URI', 'PATH_INFO'))) $var = 'REQUEST_URI'; |
|
18 $req = $_SERVER[$var]; |
|
19 if (preg_match('!^(.+/)browse/?(.*)?$!', $req, $match) && (url_to_postid($req) == 0)) |
|
20 { |
|
21 $_GET['browse'] = $match[2]; |
|
22 $req = $match[1].'?browse='.$match[2]; |
|
23 $_SERVER[$var] = $req; |
|
24 } |
|
25 if (($var != 'PATH_INFO') && isset($_SERVER['PATH_INFO'])) |
|
26 { |
|
27 wp_explorer_getvar('PATH_INFO'); |
|
28 } |
|
29 } |
|
30 |
|
31 add_action('admin_menu', 'wp_explorer_menu'); |
|
32 function wp_explorer_menu() |
|
33 { |
|
34 if(function_exists('add_menu_page')) |
|
35 { |
|
36 add_menu_page('WP Explorer', 'WP Explorer', 'manage_options', 'wp-explorer/wp-explorer-options.php') ; |
|
37 } |
|
38 |
|
39 } |
|
40 |
|
41 add_action('activate_wp-explorer/wp-explorer.php', 'wp_explorer_install'); |
|
42 function wp_explorer_install() |
|
43 { |
|
44 require ('inc/functions_misc.php'); |
|
45 add_option('wp_explorer_options', wp_explorer_opmap(), '', 'no'); |
|
46 } |
|
47 |
|
48 add_action('deactivate_wp-explorer/wp-explorer.php', 'wp_explorer_uninstall'); |
|
49 function wp_explorer_uninstall() |
|
50 { |
|
51 delete_option('wp_explorer_options'); |
|
52 } |
|
53 |
|
54 add_filter('single_post_title', wp_explorer_location, 99999, 1); |
|
55 function wp_explorer_location() |
|
56 { |
|
57 $arg = func_get_args(); |
|
58 $nargs = func_num_args(); |
|
59 $folders = array_map("urldecode", array_values(array_filter(explode('/', $_GET['browse'])))); |
|
60 if($nargs == 1) |
|
61 { |
|
62 $title = $arg[0]; |
|
63 return (!count($folders) ? $title : $title.' » '.implode(' » ', $folders)); |
|
64 } |
|
65 elseif($nargs == 2) |
|
66 { |
|
67 $url = $arg[0]; |
|
68 $pretty = $arg[1]; |
|
69 $loc[] = __('Root', 'wp-explorer'); |
|
70 } |
|
71 else { die("I don't Know You");} |
|
72 |
|
73 foreach($folders AS $folder) |
|
74 { |
|
75 $tmp .= $folder; |
|
76 $tlink = str_replace('%browse%', $tmp, $url); |
|
77 $tlink = $pretty ? str_replace(array('/?browse=', '?browse=', '&browse='), '/browse/', $tlink) : $tlink; |
|
78 $loc[] = '<a href="'.$tlink.'">'.$folder.'</a>'; |
|
79 $tmp .= '/'; |
|
80 } |
|
81 return implode((count($loc) > 1 ? ' » ' : ''), $loc); |
|
82 } |
|
83 |
|
84 add_shortcode('wp_explorer', 'wp_explorer_caption'); |
|
85 function wp_explorer_caption( $atts, $content = null ) |
|
86 { |
|
87 if(trim($content) == null) return; |
|
88 load_plugin_textdomain('wp-explorer', 'wp-content/plugins/wp-explorer'); |
|
89 require ('inc/functions_misc.php'); |
|
90 |
|
91 $cfg = get_option('wp_explorer_options'); |
|
92 $no_folders = explode(',', $cfg['exclude_folders']); |
|
93 $no_files = explode(',', $cfg['exclude_files']); |
|
94 $no_ext = explode(',', $cfg['exclude_extensions']); |
|
95 // Edit MP3 |
|
96 $spe_ext = ".mp3"; |
|
97 // --- |
|
98 array_walk($no_folders, 'trim'); |
|
99 array_walk($no_files, 'trim'); |
|
100 array_walk($no_ext, 'trim'); |
|
101 |
|
102 $main_dir = trim(trim($content), '/'); |
|
103 $condom = $main_dir.'/.htaccess'; |
|
104 $siteurl = get_bloginfo('siteurl'); |
|
105 $url = get_permalink(); |
|
106 |
|
107 if($cfg['enable_antileech']) |
|
108 { |
|
109 if(!file_exists($condom)) |
|
110 { |
|
111 $file = @fopen($condom, 'w'); |
|
112 if($file) |
|
113 { |
|
114 $patterns = array('http://', 'https://', 'www.', 'WWW.'); |
|
115 $cofipr = "RewriteEngine on\n"; |
|
116 $cofipr .= "RewriteCond %{HTTP_REFERER} !^http://(www\.)?".str_replace($patterns, '', $siteurl)."/(/)?.*$ [NC]\n"; |
|
117 $cofipr .= "RewriteRule .*\.*$ http://".str_replace($patterns, '', $url)." [R,NC]\n"; |
|
118 $cofipr .= "Options -Indexes"; |
|
119 |
|
120 fwrite($file, $cofipr); |
|
121 fclose($file); |
|
122 $leech_protection = __('Leech protection: ON', 'wp-explorer'); |
|
123 |
|
124 } |
|
125 else |
|
126 { |
|
127 $leech_protection = __('Leech protection: Failed', 'wp-explorer'); |
|
128 } |
|
129 } |
|
130 else |
|
131 { |
|
132 $leech_protection = __('Leech protection: ON', 'wp-explorer'); |
|
133 } |
|
134 } |
|
135 elseif(!$cfg['enable_antileech']) |
|
136 { |
|
137 if(file_exists($condom)) unlink($condom); |
|
138 $leech_protection = __('Leech protection: OFF', 'wp-explorer'); |
|
139 } |
|
140 |
|
141 if($_GET['browse'] != '') |
|
142 { |
|
143 $_GET['browse'] = str_replace('<', '<', trim($_GET['browse'])); |
|
144 $f = $main_dir.'/'.urldecode($_GET['browse']); |
|
145 } |
|
146 |
|
147 if(is_dir($f)) |
|
148 { |
|
149 $patterns = array(".", "/"); |
|
150 $real = str_replace($patterns, "", $main_dir); |
|
151 $check = str_replace($patterns, "", $f); |
|
152 $re = strlen($real); |
|
153 if(substr($check, 0, $re)!= $real) $f = $main_dir; |
|
154 if(substr($f,0,2) == ".." || substr($f,0,1) == "/" || $f == "./" || stristr($f, '../')) $f = $main_dir; |
|
155 } |
|
156 else |
|
157 { |
|
158 $f = $main_dir; |
|
159 } |
|
160 |
|
161 $files = array(); |
|
162 if(is_dir($f) && $handle = opendir($f)) |
|
163 { |
|
164 $phrase['location'] = __('You are here:', 'wp-explorer'); |
|
165 $basedirurl = add_query_arg('browse', '%browse%', $url); |
|
166 $location = wp_explorer_location($basedirurl, $cfg['enable_fancylinks']); |
|
167 |
|
168 while(false !==($file = readdir($handle))) |
|
169 { |
|
170 if($file != '..' && $file != '.') |
|
171 { |
|
172 $filesize = @filesize($f.'/'.$file); |
|
173 $files[] = array("name" => $file, "size" => size_format($filesize, 2), "date" => gmdate("d/m/Y",filemtime($f.'/'.$file))); |
|
174 } |
|
175 } |
|
176 closedir($handle); |
|
177 sort($files); |
|
178 |
|
179 $dir_jj = $file_ii = 0; |
|
180 foreach($files as $file) |
|
181 { |
|
182 $file['address'] = $f.'/'.$file['name']; |
|
183 if(is_dir($file['address']) && !in_array($file['name'], $no_folders)) |
|
184 { |
|
185 $dir_jj++; |
|
186 $file['icon'] = 'folder.gif'; |
|
187 $file['url'] = urlencode($f.'/'.$file['name']); |
|
188 $file['url'] = str_replace('%2F', '/', $file['url']); |
|
189 $file['url'] = str_replace($main_dir.'/', '', $file['url']); |
|
190 $file['url'] = str_replace('%browse%', $file['url'], $basedirurl); |
|
191 $file['url'] = $cfg['enable_fancylinks'] ? str_replace(array('/?browse=', '?browse=', '&browse='), '/browse/', $file['url']) : $file['url']; |
|
192 $file['class'] = $dir_jj % 2 == 0 ? 'even' : 'odd'; |
|
193 eval('$dirbit .= "' . wp_explorer_preptmp($cfg['tmp_dirbit']) . '";'); |
|
194 } |
|
195 elseif(is_file($file['address']) && !in_array($file['name'], $no_files)) |
|
196 { |
|
197 $file['ext'] = strtolower(substr(strrchr($file['name'], '.'), 1)); |
|
198 if(in_array($file['ext'], $no_ext)) continue; |
|
199 |
|
200 $file_ii++; |
|
201 $filename = explode("_", $file['name']); |
|
202 $version = str_replace('.'.$file['ext'], '', end($filename)); |
|
203 $version = is_numeric($version) ? $version : ''; |
|
204 $file['version'] = empty($version) ? ' ' : $version; |
|
205 $file['icon'] = substr(strrchr($file['name'], '.'), 1).'.gif'; |
|
206 $file['icon'] = file_exists('wp-content/plugins/wp-explorer/icons/'.$file['icon']) ? $file['icon'] : "unknown.png"; |
|
207 $file['name'] = wp_explorer_sanitize($file['name'], $file['ext'], $version); |
|
208 ///$file['url'] = $file['address']; |
|
209 $file['url'] = "/non-classe/telecharger/?URL=".$file['address']; |
|
210 $file['class'] = $file_ii % 2 == 0 ? 'even' : 'odd'; |
|
211 |
|
212 // Edit MP3 / IRI ---------------------------------- |
|
213 |
|
214 if ($file['ext'] == "mp3"){ |
|
215 $file['player']="<script type='text/javascript' src='".get_bloginfo('stylesheet_directory')."/player/swfobject.js'></script> |
|
216 <div id='mediaspace".$file_ii."'>Wait for the player of ".$filename."</div> |
|
217 <script type='text/javascript'> |
|
218 var so = new SWFObject('".get_bloginfo('stylesheet_directory')."/player/player.swf','ply','250','24','9','#EFEFEF'); |
|
219 so.addParam('allowfullscreen','true'); |
|
220 so.addParam('allowscriptaccess','always'); |
|
221 so.addParam('wmode','transparent'); |
|
222 so.addVariable('file','".get_bloginfo('url')."/".$file['address']."'); |
|
223 so.write('mediaspace".$file_ii."'); |
|
224 </script>"; |
|
225 } else if ($file['ext'] == "iri"){ |
|
226 $file['url']= $file['url']."&EXT=IRI"; |
|
227 } else { |
|
228 $file['player']="";//$file['ext']; |
|
229 } |
|
230 //-------------------------------------------- |
|
231 eval('$filebit .= "' . wp_explorer_preptmp($cfg['tmp_filebit']) . '";'); |
|
232 } |
|
233 } |
|
234 $phrase['name'] = __('Name', 'wp-explorer'); |
|
235 $phrase['date'] = __('Last Modification Date', 'wp-explorer'); |
|
236 |
|
237 if($dirbit) |
|
238 { |
|
239 eval('$display_dirs .= "' . wp_explorer_preptmp($cfg['tmp_dirtbl']) . '";'); |
|
240 } |
|
241 if($filebit) |
|
242 { |
|
243 $phrase['size'] = __('Size', 'wp-explorer'); |
|
244 $phrase['version'] = __('Version', 'wp-explorer'); |
|
245 eval('$display_files .= "' . wp_explorer_preptmp($cfg['tmp_filetbl']) . '";'); |
|
246 } |
|
247 $folder_stats = sprintf(__('There are %1$s folders and %2$s files here.', 'wp-explorer'), $dir_jj, $file_ii); |
|
248 eval('$html .= "' . wp_explorer_preptmp($cfg['tmp_main']) . '";'); |
|
249 } |
|
250 else |
|
251 { |
|
252 $error_message = __("ERROR: I have no right to access this folder or this folder doesn't exist.", 'wp-explorer'); |
|
253 eval('$html .= "' . wp_explorer_preptmp($cfg['tmp_error']) . '";'); |
|
254 } |
|
255 return $html; |
|
256 } |
|
257 |
|
258 ?> |