00001 <?php 00002 00003 /* ========================================================================================== 00004 * Nucleus SkinFiles Plugin 00005 * 00006 * Copyright 2005-2007 by Jeff MacMichael and Niels Leenheer 00007 * 00008 * @version $Id: index.php 1200 2007-09-07 07:06:37Z kimitake $ 00009 * @version $NucleusJP: index.php,v 1.6.2.1 2007/09/07 07:08:01 kimitake Exp $ 00010 * 00011 * ========================================================================================== 00012 * This program is free software and open source software; you can redistribute 00013 * it and/or modify it under the terms of the GNU General Public License as 00014 * published by the Free Software Foundation; either version 2 of the License, 00015 * or (at your option) any later version. 00016 * 00017 * This program is distributed in the hope that it will be useful, but WITHOUT 00018 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00019 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00020 * more details. 00021 * 00022 * You should have received a copy of the GNU General Public License along 00023 * with this program; if not, write to the Free Software Foundation, Inc., 00024 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit 00025 * http://www.gnu.org/licenses/gpl.html 00026 * ========================================================================================== 00027 */ 00028 00029 $strRel = '../../../'; 00030 require($strRel . 'config.php'); 00031 include($DIR_LIBS . 'PLUGINADMIN.php'); 00032 00033 $language = ereg_replace( '[\\|/]', '', getLanguageName()); 00034 $langfile = $language.'.php'; 00035 if (file_exists($langfile)) 00036 include_once($langfile); 00037 else 00038 include_once('english.php'); 00039 00044 $oPluginAdmin = new PluginAdmin('SkinFiles'); 00045 00046 if (!($member->isLoggedIn() && $member->isAdmin())) 00047 { 00048 $oPluginAdmin->start(); 00049 echo '<p>' . _ERROR_DISALLOWED . '</p>'; 00050 $oPluginAdmin->end(); 00051 exit; 00052 } 00053 00054 00055 00060 $rootDirectory = sfRealPath($DIR_SKINS); 00061 $rootUrl = $CONF['SkinsURL']; 00062 $pluginUrl = $oPluginAdmin->plugin->getAdminURL(); 00063 00064 $filetypes = array ( 00065 'text' => array ('inc', 'txt', 'css', 'js', 'php'), 00066 'html' => array ('htm', 'html'), 00067 'img' => array ('png', 'gif', 'jpg', 'jpeg', 'bmp', 'ico', 'swf'), 00068 ); 00069 00070 00075 $action = requestVar('action'); 00076 00077 if ($action == 'download') { 00078 _skinfiles_download(); 00079 exit; 00080 } 00081 00082 00087 $oPluginAdmin->start("<style type='text/css'> 00088 <!-- 00089 00090 div#content a { 00091 text-decoration: none; 00092 } 00093 div#content img { 00094 vertical-align: middle; 00095 margin-top: -3px; 00096 } 00097 p.message { 00098 font-weight: bold; 00099 } 00100 p.error { 00101 font-size: 100%; 00102 font-weight: bold; 00103 color: #880000; 00104 } 00105 pre { 00106 overflow: auto; 00107 height: 400px; 00108 } 00109 iframe { 00110 width: 100%; 00111 height: 400px; 00112 border: 1px solid gray; 00113 } 00114 div.dialogbox { 00115 border: 1px solid #ddd; 00116 background-color: #F6F6F6; 00117 margin: 18px 0 1.5em 0; 00118 } 00119 div.dialogbox h4 { 00120 background-color: #bbc; 00121 color: #000; 00122 margin: 0; 00123 padding: 5px; 00124 } 00125 div.dialogbox h4.light { 00126 background-color: #ddd; 00127 } 00128 div.dialogbox div { 00129 margin: 0; 00130 padding: 10px; 00131 } 00132 div.dialogbox button { 00133 margin: 10px 0 0 6px; 00134 float: right; 00135 } 00136 div.dialogbox p { 00137 margin: 0; 00138 } 00139 div.dialogbox p.buttons { 00140 text-align: right; 00141 overflow: auto; 00142 } 00143 div.dialogbox textarea { 00144 width: 100%; 00145 margin: 0; 00146 } 00147 00148 --> 00149 </style>"); 00150 00151 echo "<h2>" . _SKINFILES_MANAGEMENT . "</h2>"; 00152 00153 $actions = array ( 00154 'renfile', 'renfile_process', 'delfile', 'delfile_process', 00155 'editfile', 'editfile_process', 'uploadfile', 'createfile', 'viewfile', 00156 'rendir', 'rendir_process', 'deldir', 'deldir_process', 00157 'emptydir', 'emptydir_process', 'createdir' 00158 ); 00159 00160 if (in_array($action, $actions)) 00161 { 00162 if (!$manager->checkTicket()) 00163 { 00164 echo '<p class="error">Error: ' . _ERROR_BADTICKET . '</p>'; 00165 sfShowDirectory(); 00166 00167 } 00168 else 00169 { 00170 call_user_func('_skinfiles_' . $action); 00171 } 00172 } 00173 else 00174 { 00175 sfShowDirectory(); 00176 } 00177 00178 $oPluginAdmin->end(); 00179 exit; 00180 00181 00182 00183 00184 00185 00186 00187 /* Helper functions **************************************************************************************************************/ 00188 00189 function sfExpandDirectory ($path) { 00190 /* IN: relative directory 00191 * OUT: full path to directory 00192 */ 00193 00194 global $rootDirectory; 00195 return sfRealPath($rootDirectory . $path); 00196 } 00197 00198 function sfRealPath ($path) { 00199 /* IN: full path 00200 * OUT: canonicalized absolute pathname 00201 */ 00202 00203 $path = realpath($path); 00204 $path = str_replace('\\', '/', $path); 00205 $path = substr($path, strlen($path) - 1) != '/' ? $path . '/' : $path; 00206 return $path; 00207 } 00208 00209 function sfFullUrl ($path) { 00210 /* IN: full path including filename 00211 * OUT: url including filename 00212 */ 00213 00214 global $rootDirectory, $rootUrl; 00215 00216 $path = str_replace($rootDirectory, '', $path); 00217 $path = rawurlencode($path); 00218 $path = str_replace('%2F', '/', $path); 00219 return $rootUrl . $path; 00220 } 00221 00222 function sfValidPath ($path) { 00223 /* IN: full path excluding or including filename 00224 * OUT: boolean, true if full path is or is within rootDirectory 00225 */ 00226 00227 global $rootDirectory; 00228 return substr($path, 0, strlen($rootDirectory)) == $rootDirectory; 00229 } 00230 00231 function sfRelativePath ($path) { 00232 /* IN: full path including or excluding filename 00233 * OUT: relative path from rootDirectory 00234 */ 00235 00236 global $rootDirectory; 00237 return str_replace($rootDirectory, '', $path); 00238 } 00239 00240 function sfIsFileType ($type, $file) { 00241 00242 global $filetypes; 00243 return isset($filetypes[$type]) && in_array(strtolower(substr(strrchr($file, "."), 1)), $filetypes[$type]); 00244 } 00245 00246 function sfAllowEditing ($file) { 00247 return sfIsFileType('html', $file) || sfIsFileType('text', $file); 00248 } 00249 00250 function sfAllowViewing ($file) { 00251 return sfIsFileType('html', $file) || sfIsFileType('text', $file) || sfIsFileType('img', $file); 00252 } 00253 00254 00255 function sfDisplayPath ($relative) { 00256 00257 global $pluginUrl; 00258 00259 $result = '<a href="' . htmlspecialchars($pluginUrl) . '" title="Go back to «skins»">'; 00260 $result .= '<img src="' . htmlspecialchars($pluginUrl . 'home.gif') . '" alt="" /> skins</a> / '; 00261 00262 $parts = explode('/', $relative); 00263 $part = ''; 00264 00265 while (list(,$v) = each ($parts)) { 00266 if ($v != '') { 00267 $part .= $v . '/'; 00268 00269 $result .= '<a href="' . htmlspecialchars($pluginUrl . '?dir=' . rawurlencode($part)) . '" '; 00270 $result .= 'title="Go back to «' . htmlspecialchars($v) . '»">'; 00271 $result .= '<img src="' . htmlspecialchars($pluginUrl . 'dir.gif') . '" alt="" /> '; 00272 $result .= htmlspecialchars($v) . '</a> / '; 00273 } 00274 } 00275 00276 return $result; 00277 } 00278 00279 function sfIcon ($file) { 00280 00281 global $pluginUrl; 00282 00283 $ext = strtolower(substr(strrchr($file, "."), 1)); 00284 00285 switch ($ext) { 00286 case 'htm': 00287 case 'html': 00288 return $pluginUrl . 'html.gif'; 00289 break; 00290 00291 case 'txt': 00292 case 'js': 00293 case 'css': 00294 case 'inc': 00295 return $pluginUrl . 'text.gif'; 00296 break; 00297 00298 case 'gif': 00299 case 'png': 00300 case 'jpg': 00301 case 'jpeg': 00302 case 'bmp': 00303 case 'xbmp': 00304 case 'ico': 00305 return $pluginUrl . 'image.gif'; 00306 break; 00307 00308 case 'php': 00309 case 'php3': 00310 case 'php4': 00311 return $pluginUrl . 'php.gif'; 00312 break; 00313 00314 default: 00315 return $pluginUrl . 'generic.gif'; 00316 break; 00317 } 00318 } 00319 00320 function sfIllegalFilename($name) { 00321 return preg_match('#[\n\r\\\/\:\*\?\"<>\|]#', $name); 00322 } 00323 00324 function sfDirectoryIsEmpty($dir) { 00325 00326 $count = 0; 00327 00328 if ($dh = opendir($dir)) 00329 { 00330 while (($file = readdir($dh)) !== false) 00331 $count++; 00332 00333 closedir($dh); 00334 } 00335 00336 // $count must be smaller or equal than 2, because '.' 00337 // and '..' are always returned by readdir(). 00338 return $count <= 2; 00339 } 00340 00341 00342 00343 00344 00345 00346 00347 00348 00349 /* Show directory ****************************************************************************************************************/ 00350 00351 function sfShowDirectory($default = '') { 00352 00353 global $pluginUrl, $rootDirectory, $CONF, $manager; 00354 00355 $directory = $default != '' ? 00356 $default : 00357 sfExpandDirectory(trim(requestVar('dir'))); 00358 00359 if (!sfValidPath($directory) || !is_dir($directory)) { 00360 $directory = $rootDirectory; 00361 } 00362 00363 $relative = sfRelativePath ($directory); 00364 00365 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative) . '</p>'; 00366 00367 00368 $dirs = array(); 00369 $files = array(); 00370 00371 if ($dh = @opendir($directory)) { 00372 while (($file = readdir($dh)) !== false) { 00373 if (!preg_match("/^\.{1,2}$/", $file)) { 00374 $fstat = @stat($directory . $file); 00375 00376 if ($fstat['mode'] & 040000) 00377 $dirs[$file] = $fstat; 00378 else 00379 $files[$file] = $fstat; 00380 } 00381 } 00382 closedir($dh); 00383 } 00384 00385 ksort($dirs); 00386 ksort($files); 00387 00388 echo '<table><thead><tr>'; 00389 echo '<th>' . _SKINFILES_NAME . '</th><th>' . _SKINFILES_SIZE . '</th><th>' . _SKINFILES_LAST_MODIFIED . '</th><th colspan="4">' . _SKINFILES_ACTIONS . '</th>'; 00390 echo '</tr></thead>'; 00391 00392 while (list($name, $stat) = each($dirs)) { 00393 00394 $dir = sfRelativePath($directory . $name . '/'); 00395 00396 echo '<tr onmouseover="focusRow(this);" onmouseout="blurRow(this);"><td>'; 00397 00398 if (is_readable ($directory . $name)) 00399 { 00400 echo '<a href="' . htmlspecialchars($pluginUrl . '?dir=' . rawurlencode($dir)) . '">'; 00401 echo '<img src="' . htmlspecialchars($pluginUrl . 'dir.gif') . '" alt="folder" /> '; 00402 echo htmlspecialchars($name).'</a>'; 00403 } 00404 else 00405 { 00406 echo '<img src="' . htmlspecialchars($pluginUrl . 'dir.gif') . '" alt="folder" /> '; 00407 echo htmlspecialchars($name); 00408 } 00409 00410 echo '</td>'; 00411 00412 $renUrl = $manager->addTicketToUrl($pluginUrl . '?action=rendir&dir=' . rawurlencode($dir)); 00413 $delUrl = $manager->addTicketToUrl($pluginUrl . '?action=deldir&dir=' . rawurlencode($dir)); 00414 00415 echo '<td>–</td>'; 00416 echo '<td>' . date(_SKINFILES_DATE_FORMAT, $stat['mtime']); 00417 00418 00419 if (is_writable($directory . $name)) { 00420 echo '<td><a href="' . htmlspecialchars($renUrl) . '" title="' . _SKINFILES_RENAME . ' «' . htmlspecialchars($name) . '»">' . _SKINFILES_RENAME . '</a></td>'; 00421 } else { 00422 echo '<td> </td>'; 00423 } 00424 00425 if (is_writable($directory . $name) && sfDirectoryIsEmpty($directory . $name)) { 00426 echo '<td><a href="' . htmlspecialchars($delUrl) . '" title="' . _SKINFILES_DELETE . ' «' . htmlspecialchars($name) . '»">' . _SKINFILES_DELETE . '</a></td>'; 00427 } else { 00428 echo '<td> </td>'; 00429 } 00430 00431 echo '<td> </td><td> </td>'; 00432 echo '</tr>'; 00433 } 00434 00435 00436 while (list($name, $stat) = each($files)) { 00437 00438 $file = sfRelativePath($directory . $name); 00439 00440 $renUrl = $manager->addTicketToUrl($pluginUrl . '?action=renfile&file=' . rawurlencode($file)); 00441 $delUrl = $manager->addTicketToUrl($pluginUrl . '?action=delfile&file=' . rawurlencode($file)); 00442 $editUrl = $manager->addTicketToUrl($pluginUrl . '?action=editfile&file=' . rawurlencode($file)); 00443 $viewUrl = $manager->addTicketToUrl($pluginUrl . '?action=viewfile&file=' . rawurlencode($file)); 00444 $dlUrl = $manager->addTicketToUrl($pluginUrl . '?action=download&file=' . rawurlencode($file)); 00445 00446 echo '<tr onmouseover="focusRow(this);" onmouseout="blurRow(this);"><td>'; 00447 00448 if (is_readable ($directory . $name) && sfAllowViewing($name)) 00449 { 00450 echo '<a href="' . htmlspecialchars($viewUrl) . '">'; 00451 echo '<img src="' . htmlspecialchars(sfIcon($name)) . '" alt="" /> '; 00452 echo htmlspecialchars($name).'</a>'; 00453 } 00454 else 00455 { 00456 echo '<img src="' . htmlspecialchars(sfIcon($name)) . '" alt="" /> '; 00457 echo htmlspecialchars($name); 00458 } 00459 00460 echo '</td><td>'; 00461 echo ceil($stat['size'] / 1024) . ' kB'; 00462 echo '</td><td>'; 00463 echo date(_SKINFILES_DATE_FORMAT, $stat['mtime']); 00464 echo '</td><td>'; 00465 00466 if (is_writable($directory . $name)) { 00467 echo '<a href="' . htmlspecialchars($renUrl) . '" title="' . _SKINFILES_RENAME . ' «' . htmlspecialchars($name) . '»">' . _SKINFILES_RENAME . '</a>'; 00468 } else { 00469 echo ' '; 00470 } 00471 00472 echo '</td><td>'; 00473 00474 if (is_writable($directory . $name)) { 00475 echo '<a href="' . htmlspecialchars($delUrl) . '" title="' . _SKINFILES_DELETE . ' «' . htmlspecialchars($name) . '»">' . _SKINFILES_DELETE . '</a>'; 00476 } else { 00477 echo ' '; 00478 } 00479 00480 echo '</td><td>'; 00481 00482 if (is_writable($directory . $name) && sfAllowEditing($name)) 00483 echo '<a href="'. htmlspecialchars($editUrl) . '" title="' . _SKINFILES_EDIT . ' «' . htmlspecialchars($name) . '»">' . _SKINFILES_EDIT . '</a>'; 00484 else 00485 echo ' '; 00486 00487 echo '</td><td>'; 00488 00489 if (is_readable ($directory . $name)) 00490 echo '<a href="' . htmlspecialchars($dlUrl) . '" title="' . _SKINFILES_DOWNLOAD . ' «' . htmlspecialchars($name) . '»">' . _SKINFILES_DOWNLOAD . '</a>'; 00491 else 00492 echo ' '; 00493 00494 echo '</td></tr>'; 00495 } 00496 00497 if (!count($dirs) && !count($files)) { 00498 echo '<tr><td colspan="7">' . _SKINFILES_ERR_DIR_DOES_NOT_CONTAIN . '</td></tr>'; 00499 } 00500 00501 echo '</table>'; 00502 00503 if ($relative != '') { 00504 00505 if (is_writable($directory)) { 00506 echo '<div class="dialogbox">'; 00507 echo '<h4 class="light">' . _SKINFILES_CREATE_NEW_FILE . '</h4><div>'; 00508 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 00509 $manager->addTicketHidden(); 00510 echo '<input type="hidden" name="action" value="createfile" />'; 00511 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative) . '" />'; 00512 echo '<input type="text" name="name" size="40" value="untitled.txt" />'; 00513 echo '<p class="buttons"><input type="submit" value="' . _SKINFILES_CREATE_FILE . '" /></p></form>'; 00514 echo '</div></div>'; 00515 00516 echo '<div class="dialogbox">'; 00517 echo '<h4 class="light">' . _SKINFILES_UPLOAD_NEW_FILE . '</h4><div>'; 00518 echo '<form method="post" enctype="multipart/form-data" action="' . htmlspecialchars($pluginUrl) . '">'; 00519 $manager->addTicketHidden(); 00520 echo '<input type="hidden" name="action" value="uploadfile" />'; 00521 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative) . '" />'; 00522 echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . $CONF['MaxUploadSize'] . '" />'; 00523 echo '<input type="file" name="name" size="40" />'; 00524 echo '<p class="buttons"><input type="submit" value="' . _SKINFILES_UPLOAD . '" /></p></form>'; 00525 echo '</div></div>'; 00526 } 00527 00528 if (count($files)) { 00529 echo '<div class="dialogbox">'; 00530 echo '<h4 class="light">' . _SKINFILES_DEL_ALL_FILES . '</h4><div>'; 00531 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 00532 $manager->addTicketHidden(); 00533 echo '<input type="hidden" name="action" value="emptydir" />'; 00534 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative) . '" />'; 00535 echo _SKINFILES_DEL_ALL_FILES_MSG; 00536 echo '<p class="buttons"><input type="submit" value="' . _SKINFILES_DELETE_ALL . '" tabindex="140" onclick="return checkSubmit();" /></p>'; 00537 echo '</form>'; 00538 echo '</div></div>'; 00539 } 00540 } 00541 00542 if (is_writable($directory)) { 00543 echo '<div class="dialogbox">'; 00544 echo '<h4 class="light">' . _SKINFILES_CREATE_NEW_DIR . '</h4><div>'; 00545 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 00546 $manager->addTicketHidden(); 00547 echo '<input type="hidden" name="action" value="createdir" />'; 00548 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative) . '" />'; 00549 echo '<input type="text" name="name" value="untitled" tabindex="90" size="40" />'; 00550 echo '<p class="buttons"><input type="submit" value="' . _SKINFILES_CREATE . '" tabindex="140" onclick="return checkSubmit();" /></p>'; 00551 echo '</form>'; 00552 echo '</div></div>'; 00553 } 00554 } 00555 00556 00557 00558 00559 /* Rename directory **************************************************************************************************************/ 00560 00561 function _skinfiles_rendir($preset = '') { 00562 00563 global $pluginUrl, $manager; 00564 00565 $file = trim(basename(requestVar('dir'))); 00566 $directory = trim(dirname(requestVar('dir'))); 00567 $directory = sfExpandDirectory ($directory); 00568 00569 if (sfValidPath($directory . $file) && file_exists($directory . $file) && 00570 is_dir($directory . $file) && is_writable($directory . $file)) 00571 { 00572 $relative = sfRelativePath ($directory); 00573 $editUrl = $manager->addTicketToUrl($pluginUrl . '?action=rendir&dir=' . rawurlencode($relative . $file)); 00574 00575 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 00576 echo '<a href="' . htmlspecialchars($editUrl) . '" title="' . _SKINFILES_RENAME . ' «' . $file . '»">'; 00577 echo '<img src="' . $pluginUrl . 'dir.gif' . '" alt="" /> ' . $file . '</a></p>'; 00578 00579 echo '<div class="dialogbox">'; 00580 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 00581 $manager->addTicketHidden(); 00582 echo '<input type="hidden" name="action" value="rendir_process" />'; 00583 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative . $file) . '" />'; 00584 00585 echo '<h4>' . _SKINFILES_RENAME_DIR_MSG . ' «' . htmlspecialchars($file) . '» ' . _SKINFILES_RENAME_DIR_MSG2 . '</h4><div>'; 00586 echo '<p><input type="text" name="name" size="40" value="' . htmlspecialchars($preset != '' ? $preset : $file) . '" /></p>'; 00587 echo '<p class="buttons">'; 00588 echo '<input type="hidden" name="sure" value="yes" />'; 00589 echo '<input type="submit" value="' . _SKINFILES_RENAME . '" />'; 00590 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 00591 echo '</p>'; 00592 echo '</div></form></div>'; 00593 } 00594 else 00595 { 00596 echo "<p class='error'>" . _SKINFILES_ERR_DIR_DOES_NOT_EXIST1 . " «" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DIR_DOES_NOT_EXIST2; 00597 echo _SKINFILES_ERR_DIR_DOES_NOT_EXIST3 . "</p>"; 00598 } 00599 } 00600 00601 function _skinfiles_rendir_process() { 00602 00603 global $pluginUrl, $manager; 00604 00605 $file = trim(basename(requestVar('dir'))); 00606 $directory = trim(dirname(requestVar('dir'))); 00607 $directory = sfExpandDirectory ($directory); 00608 00609 if (requestVar('sure') == 'yes') 00610 { 00611 if (sfValidPath($directory . $file) && file_exists($directory . $file) && 00612 is_dir($directory . $file) && is_writable($directory . $file)) 00613 { 00614 $name = requestVar('name'); 00615 00616 if ($name == '') { 00617 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_RENAME_DIR1 . "«" . htmlspecialchars($file) . "» "; 00618 echo _SKINFILES_ERR_COULD_NOT_RENAME_DIR2 . "</p>"; 00619 _skinfiles_rendir($name); 00620 return; 00621 } 00622 00623 if (sfIllegalFilename($name)) { 00624 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_RENAME_DIR3 . "«" . htmlspecialchars($file) . "» "; 00625 echo _SKINFILES_ERR_COULD_NOT_RENAME_DIR4 . "</p>"; 00626 _skinfiles_rendir($name); 00627 return; 00628 } 00629 00630 if ($name == $file) { 00631 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_RENAME_DIR5 . "«" . htmlspecialchars($file) . "» "; 00632 echo _SKINFILES_ERR_COULD_NOT_RENAME_DIR6 . _SKINFILES_ERR_COULD_NOT_RENAME_DIR7 . "</p>"; 00633 _skinfiles_rendir($name); 00634 return; 00635 } 00636 00637 if (file_exists($directory . $name)) { 00638 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_RENAME_DIR8 . "«" . htmlspecialchars($file) . "» "; 00639 echo _SKINFILES_ERR_COULD_NOT_RENAME_DIR9 . _SKINFILES_ERR_COULD_NOT_RENAME_DIR10 . "</p>"; 00640 _skinfiles_rendir($name); 00641 return; 00642 } 00643 00644 if (!@rename($directory . $file, $directory . $name)) 00645 { 00646 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_RENAME_DIR11 . "«" . htmlspecialchars($file) . "»</p>"; 00647 _skinfiles_rendir($name); 00648 return; 00649 } 00650 00651 echo "<p class='message'>" . _SKINFILES_RENAMED_DIR1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_RENAMED_DIR2; 00652 echo _SKINFILES_RENAMED_DIR3 . "«" . htmlspecialchars($name) . "»" . _SKINFILES_RENAMED_DIR4 . "</p>"; 00653 sfShowDirectory($directory); 00654 } 00655 else 00656 { 00657 echo "<p class='error'>" . _SKINFILES_ERR_DIR_DOES_NOT_EXIST1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DIR_DOES_NOT_EXIST2; 00658 echo _SKINFILES_ERR_DIR_DOES_NOT_EXIST3 . "</p>"; 00659 } 00660 } 00661 else 00662 { 00663 // User cancelled 00664 sfShowDirectory($directory); 00665 } 00666 } 00667 00668 00669 00670 00671 /* Create directory **************************************************************************************************************/ 00672 00673 function _skinfiles_createdir() { 00674 00675 $directory = trim(requestVar('dir')); 00676 $directory = sfExpandDirectory($directory); 00677 00678 if (sfValidPath($directory) && is_dir($directory) && is_writable($directory)) 00679 { 00680 $name = requestVar('name'); 00681 00682 if ($name == '') { 00683 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_CREATE_DIR1 . "</p>"; 00684 sfShowDirectory($directory); 00685 return; 00686 } 00687 00688 if (sfIllegalFilename($name)) { 00689 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_CREATE_DIR2 . "«" . htmlspecialchars($name) . "» "; 00690 echo _SKINFILES_ERR_COULD_NOT_CREATE_DIR3 . "</p>"; 00691 sfShowDirectory($directory); 00692 return; 00693 } 00694 00695 if (file_exists($directory . $name)) { 00696 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_CREATE_DIR4 . "«" . htmlspecialchars($name) . "» "; 00697 echo _SKINFILES_ERR_COULD_NOT_CREATE_DIR5 . _SKINFILES_ERR_COULD_NOT_CREATE_DIR6 . "</p>"; 00698 sfShowDirectory($directory); 00699 return; 00700 } 00701 00702 $mask = @umask(0000); 00703 00704 if (!@mkdir($directory . $name, 0755)) 00705 { 00706 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_CREATE_DIR2 . "«" . htmlspecialchars($name) . "»</p>"; 00707 sfShowDirectory($directory); 00708 return; 00709 } 00710 00711 @umask($mask); 00712 00713 echo "<p class='message'>" . _SKINFILES_ERR_COULD_NOT_CREATE_DIR7 . "«" . htmlspecialchars($name) . "» " . _SKINFILES_ERR_COULD_NOT_CREATE_DIR8 . "</p>"; 00714 sfShowDirectory($directory); 00715 } 00716 else 00717 { 00718 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_CREATE_DIR9 . "«" . htmlspecialchars(basename($directory)) . "» " . _SKINFILES_ERR_COULD_NOT_CREATE_DIR10; 00719 echo _SKINFILES_ERR_COULD_NOT_CREATE_DIR11 . "</p>"; 00720 } 00721 } 00722 00723 00724 00725 00726 /* Delete directory **************************************************************************************************************/ 00727 00728 function _skinfiles_deldir() { 00729 00730 global $pluginUrl, $manager; 00731 00732 $file = trim(basename(requestVar('dir'))); 00733 $directory = trim(dirname(requestVar('dir'))); 00734 $directory = sfExpandDirectory ($directory); 00735 00736 if (sfValidPath($directory . $file) && file_exists($directory . $file) && 00737 is_dir($directory . $file) && is_writable($directory . $file) && 00738 sfDirectoryIsEmpty($directory . $file)) 00739 { 00740 $relative = sfRelativePath ($directory); 00741 $delUrl = $manager->addTicketToUrl($pluginUrl . '?action=deldir&dir=' . rawurlencode($relative . $file)); 00742 00743 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 00744 echo '<a href="' . htmlspecialchars($delUrl) . '" title="' . _SKINFILES_DELETE . ' «' . $file . '»">'; 00745 echo '<img src="' . $pluginUrl . 'dir.gif' . '" alt="" /> ' . $file . '</a></p>'; 00746 00747 echo '<div class="dialogbox">'; 00748 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 00749 $manager->addTicketHidden(); 00750 echo '<input type="hidden" name="action" value="deldir_process" />'; 00751 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative . $file) . '" />'; 00752 00753 echo '<h4>' . _SKINFILES_DELETE_DIR . ' «' . htmlspecialchars($file) . '» ' . _SKINFILES_DELETE_DIR2 . '</h4><div>'; 00754 echo '<p class="buttons">'; 00755 echo '<input type="hidden" name="sure" value="yes" />'; 00756 echo '<input type="submit" value="' . _SKINFILES_DELETE . '" />'; 00757 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 00758 echo '</p>'; 00759 echo '</div></form></div>'; 00760 } 00761 else 00762 { 00763 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_DIR1 . " «" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_DIR2; 00764 echo _SKINFILES_ERR_DELETE_DIR3 . "</p>"; 00765 } 00766 } 00767 00768 function _skinfiles_deldir_process() { 00769 00770 global $pluginUrl, $manager; 00771 00772 $file = trim(basename(requestVar('dir'))); 00773 $directory = trim(dirname(requestVar('dir'))); 00774 $directory = sfExpandDirectory ($directory); 00775 00776 if (requestVar('sure') == 'yes') 00777 { 00778 if (sfValidPath($directory . $file) && file_exists($directory . $file) && 00779 is_dir($directory . $file) && is_writable($directory . $file) && 00780 sfDirectoryIsEmpty($directory . $file)) 00781 { 00782 if (!@rmdir($directory . $file)) 00783 { 00784 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_DIR4 . "«" . htmlspecialchars($file) . "»</p>"; 00785 sfShowDirectory($directory); 00786 return; 00787 } 00788 00789 echo "<p class='message'>" . _SKINFILES_ERR_DELETE_DIR5 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_DIR6 . "</p>"; 00790 sfShowDirectory($directory); 00791 } 00792 else 00793 { 00794 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_DIR1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_DIR2; 00795 echo _SKINFILES_ERR_DELETE_DIR3 . "</p>"; 00796 } 00797 } 00798 else 00799 { 00800 // User cancelled 00801 sfShowDirectory($directory); 00802 } 00803 } 00804 00805 00806 00807 00808 /* Empty directory ***************************************************************************************************************/ 00809 00810 function _skinfiles_emptydir() { 00811 00812 global $pluginUrl, $manager; 00813 00814 $file = trim(basename(requestVar('dir'))); 00815 $directory = trim(dirname(requestVar('dir'))); 00816 $directory = sfExpandDirectory ($directory); 00817 00818 if (sfValidPath($directory . $file) && file_exists($directory . $file) && is_dir($directory . $file)) 00819 { 00820 $files = array(); 00821 00822 if ($dh = @opendir($directory . $file)) 00823 { 00824 while (($name = readdir($dh)) !== false) { 00825 if(!preg_match("/^\.{1,2}$/", $name) && 00826 !is_dir($directory . $file . '/' . $name) && 00827 is_writable($directory . $file . '/' . $name)) 00828 $files[] = $name; 00829 } 00830 00831 closedir($dh); 00832 sort($files); 00833 } 00834 00835 $relative = sfRelativePath ($directory); 00836 $emptyUrl = $manager->addTicketToUrl($pluginUrl . '?action=emptydir&dir=' . rawurlencode($relative . $file)); 00837 00838 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 00839 echo '<a href="' . htmlspecialchars($emptyUrl) . '" title="Empty «' . $file . '»">'; 00840 echo '<img src="' . $pluginUrl . 'dir.gif' . '" alt="" /> ' . $file . '</a></p>'; 00841 00842 echo '<div class="dialogbox">'; 00843 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 00844 $manager->addTicketHidden(); 00845 echo '<input type="hidden" name="action" value="emptydir_process" />'; 00846 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative . $file) . '" />'; 00847 00848 echo '<h4>' . _SKINFILES_DELETE_FILE_MSG . ' «' . htmlspecialchars($file) . '»' . _SKINFILES_DELETE_FILE_MSG2 . '</h4><div>'; 00849 00850 if (count($files)) 00851 { 00852 echo '<ul>'; 00853 foreach ($files as $name) { echo '<li>' . htmlspecialchars($name) . '</li>'; } 00854 echo '</ul>'; 00855 00856 echo '<p class="buttons">'; 00857 echo '<input type="hidden" name="sure" value="yes" />'; 00858 echo '<input type="submit" value="' . _SKINFILES_DELETE . '" />'; 00859 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 00860 echo '</p>'; 00861 } 00862 else 00863 { 00864 echo '<p>' . _SKINFILES_ERR_DELETE_DIR7 . '</p>'; 00865 echo '<p class="buttons">'; 00866 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 00867 echo '</p>'; 00868 } 00869 00870 echo '</div></form></div>'; 00871 00872 } 00873 else 00874 { 00875 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_DIR1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_DIR2; 00876 echo _SKINFILES_ERR_DELETE_DIR3 . "</p>"; 00877 } 00878 } 00879 00880 function _skinfiles_emptydir_process() { 00881 00882 global $pluginUrl, $manager; 00883 00884 $file = trim(basename(requestVar('dir'))); 00885 $directory = trim(dirname(requestVar('dir'))); 00886 $directory = sfExpandDirectory ($directory); 00887 00888 if (requestVar('sure') == 'yes') 00889 { 00890 if (sfValidPath($directory . $file) && file_exists($directory . $file) && is_dir($directory . $file)) 00891 { 00892 if ($dh = @opendir($directory . $file)) 00893 { 00894 while (($name = readdir($dh)) !== false) 00895 { 00896 if(!preg_match("/^\.{1,2}$/", $name) && !is_dir($directory . $file . '/' . $name) && 00897 is_writable($directory . $file . '/' . $name)) 00898 { 00899 if (unlink ($directory .$file . '/' . $name)) 00900 echo "<p class='message'>" . _SKINFILES_ERR_EMPTY_DIR1 . "«" . htmlspecialchars($name) . "» " . _SKINFILES_ERR_EMPTY_DIR2 . "</p>"; 00901 else 00902 echo "<p class='error'>" . _SKINFILES_ERR_EMPTY_DIR3 . "«" . htmlspecialchars($name) . "» " . _SKINFILES_ERR_EMPTY_DIR4 . "</p>"; 00903 } 00904 } 00905 00906 closedir($dh); 00907 00908 sfShowDirectory($directory . $file . '/'); 00909 } 00910 } 00911 else 00912 { 00913 echo "<p class='error'>" . _SKINFILES_ERR_EMPTY_DIR5 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_EMPTY_DIR6; 00914 echo _SKINFILES_ERR_EMPTY_DIR7 . "</p>"; 00915 } 00916 } 00917 else 00918 { 00919 // User cancelled 00920 sfShowDirectory($directory . $file . '/'); 00921 } 00922 } 00923 00924 00925 00926 00927 /* Download file *****************************************************************************************************************/ 00928 00929 function _skinfiles_download() { 00930 00931 global $pluginUrl, $manager; 00932 00933 $file = basename(trim(requestVar('file'))); 00934 00935 $directory = dirname(trim(requestVar('file'))); 00936 $directory = sfExpandDirectory ($directory); 00937 00938 if (sfValidPath($directory) && file_exists($directory . $file) && 00939 is_file($directory . $file) && is_readable($directory . $file)) 00940 { 00941 if (strstr(serverVar('HTTP_USER_AGENT'), "MSIE")) 00942 $name = preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1); 00943 else 00944 $name = $file; 00945 00946 if ($fp = @fopen($directory . $file, 'r')) { 00947 header("Cache-Control: "); // leave blank to avoid IE errors 00948 header("Pragma: "); // leave blank to avoid IE errors 00949 header("Content-type: application/octet-stream"); 00950 header('Content-Disposition: attachment; filename="'.$name.'"'); 00951 header("Content-length: ".(string)(filesize($directory . $file))); 00952 sleep(1); 00953 00954 fpassthru($fp); 00955 fclose($fp); 00956 } 00957 else 00958 { 00959 echo _SKINFILES_ERR_DOWNLOAD_FILE1; 00960 } 00961 } 00962 else 00963 { 00964 echo _SKINFILES_ERR_DOWNLOAD_FILE2; 00965 } 00966 00967 exit; 00968 } 00969 00970 00971 00972 00973 /* View file *********************************************************************************************************************/ 00974 00975 function _skinfiles_viewfile() { 00976 00977 global $pluginUrl, $manager; 00978 00979 $file = basename(trim(requestVar('file'))); 00980 $directory = dirname(trim(requestVar('file'))); 00981 $directory = sfExpandDirectory ($directory); 00982 00983 if (sfValidPath($directory) && file_exists($directory . $file) && 00984 is_file($directory . $file) && is_readable($directory . $file) && sfAllowViewing($file)) 00985 { 00986 $relative = sfRelativePath ($directory); 00987 $viewUrl = $manager->addTicketToUrl($pluginUrl . '?action=viewfile&file=' . rawurlencode(sfRelativePath($directory . $file))); 00988 00989 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 00990 echo '<a href="' . htmlspecialchars($viewUrl) . '" title="View «' . $file . '»">'; 00991 echo '<img src="' . htmlspecialchars(sfIcon($file)) . '" alt="" /> ' . $file . '</a></p>'; 00992 00993 echo '<h4>' . _SKINFILES_VIEW_FILE . '«' . htmlspecialchars($file) . '»</h4>'; 00994 00995 if (sfIsFileType('html', $file)) 00996 { 00997 echo '<iframe src="' . sfFullUrl($directory . $file) . '"></iframe>'; 00998 } 00999 01000 if (sfIsFileType('text', $file)) 01001 { 01002 $content = implode('', file($directory . $file)); 01003 01004 echo '<pre>'; 01005 echo htmlspecialchars($content); 01006 echo '</pre>'; 01007 } 01008 01009 if (sfIsFileType('img', $file)) 01010 { 01011 $size = getimagesize($directory . $file, $info); 01012 01013 switch ($size[2]) { 01014 case IMAGETYPE_GIF: $type = 'GIF document'; break; 01015 case IMAGETYPE_JPEG: $type = 'JPEG photograph'; break; 01016 case IMAGETYPE_PNG: $type = 'PNG document'; break; 01017 case IMAGETYPE_SWF: $type = 'Flash animation'; break; 01018 case IMAGETYPE_PSD: $type = 'Photoshop document'; break; 01019 case IMAGETYPE_BMP: $type = 'BMP document'; break; 01020 case IMAGETYPE_TIFF_II: $type = 'TIFF document (Intel Byte Order)'; break; 01021 case IMAGETYPE_TIFF_MM: $type = 'TIFF document (Motorola Byte Order)'; break; 01022 case IMAGETYPE_JPC: $type = 'JPEG2000 photograph'; break; 01023 case IMAGETYPE_JP2: $type = 'JPEG2000 photograph'; break; 01024 case IMAGETYPE_JPX: $type = 'JPEG2000 photograph'; break; 01025 case IMAGETYPE_JB2: $type = 'Slowview document'; break; 01026 case IMAGETYPE_SWC: $type = 'Flash animation (compressed)'; break; 01027 case IMAGETYPE_IFF: $type = 'IFF document'; break; 01028 case IMAGETYPE_WBMP: $type = 'WBMP document'; break; 01029 case IMAGETYPE_XBM: $type = 'XBM document'; break; 01030 default: $type = 'Unknown document'; break; 01031 } 01032 01033 if ($size[2] == IMAGETYPE_GIF || $size[2] == IMAGETYPE_JPEG || 01034 $size[2] == IMAGETYPE_PNG) 01035 { 01036 echo '<p><img src="' . sfFullUrl($directory . $file) . '" alt="" /></p>'; 01037 } 01038 01039 echo '<table>'; 01040 echo '<tr><th colspan="2">' . _SKINFILES_VIEW_FILE_IMG_INFO . '</th></tr>'; 01041 echo '<tr><td>' . _SKINFILES_VIEW_FILE_TYPE . '</td><td>' . htmlspecialchars($type) . '</td></tr>'; 01042 echo '<tr><td>' . _SKINFILES_VIEW_FILE_WIDTH . '</td><td>' . htmlspecialchars($size[0]) . _SKINFILES_VIEW_FILE_PX . '</td></tr>'; 01043 echo '<tr><td>' . _SKINFILES_VIEW_FILE_HEIGHT . '</td><td>' . htmlspecialchars($size[1]) . _SKINFILES_VIEW_FILE_PX . '</td></tr>'; 01044 01045 if (isset($size['channels']) || isset($size['bits'])) 01046 { 01047 $channels = isset($size['channels']) ? $size['channels'] : 3; 01048 $depth = $size[2] == IMAGETYPE_GIF ? $size['bits'] : $size['bits'] * $channels; 01049 echo '<tr><td>' . _SKINFILES_VIEW_FILE_CHANNELS . '</td><td>' . htmlspecialchars($channels) . '</td></tr>'; 01050 echo '<tr><td>' . _SKINFILES_VIEW_FILE_COLOR_DEPTH . '</td><td>' . htmlspecialchars($depth) . _SKINFILES_VIEW_FILE_BITS . '</td></tr>'; 01051 echo '<tr><td>' . _SKINFILES_VIEW_FILE_COLORS . '</td><td>' . htmlspecialchars(pow(2, $depth)) . _SKINFILES_VIEW_FILE_COLORS2 . '</td></tr>'; 01052 } 01053 01054 01055 if (function_exists('exif_read_data') && ($size[2] == IMAGETYPE_JPEG || 01056 $size[2] == IMAGETYPE_TIFF_II || $size[2] == IMAGETYPE_TIFF_MM)) 01057 { 01058 $exif = exif_read_data($directory . $file, 'EXIF'); 01059 01060 if ($exif) 01061 { 01062 echo '<tr><th colspan="2">Exif information</th></tr>'; 01063 01064 if (isset($exif['Make']) && isset($exif['Model'])) 01065 echo '<tr><td>Camera:</td><td>' . htmlspecialchars($exif['Make'] . ' ' . $exif['Model']) . '</td></tr>'; 01066 01067 if (isset($exif['DateTime'])) 01068 echo '<tr><td>Created on:</td><td>' . htmlspecialchars($exif['DateTime']) . '</td></tr>'; 01069 01070 if (isset($exif['XResolution'])) 01071 echo '<tr><td>Horizontal resolution:</td><td>' . htmlspecialchars(_skinfiles_exif_prepare($exif['XResolution'])) . ' dpi</td></tr>'; 01072 01073 if (isset($exif['YResolution'])) 01074 echo '<tr><td>Vertical resolution:</td><td>' . htmlspecialchars(_skinfiles_exif_prepare($exif['YResolution'])) . ' dpi</td></tr>'; 01075 01076 if (isset($exif['FocalLength'])) 01077 echo '<tr><td>Focal length:</td><td>' . htmlspecialchars(_skinfiles_exif_prepare($exif['FocalLength'])) . ' mm</td></tr>'; 01078 01079 if (isset($exif['FNumber'])) 01080 echo '<tr><td>F-number:</td><td>F/' . htmlspecialchars(_skinfiles_exif_prepare($exif['FNumber'])) . '</td></tr>'; 01081 01082 if (isset($exif['ExposureTime'])) 01083 echo '<tr><td>Exposuretime:</td><td>' . htmlspecialchars(_skinfiles_exif_prepare($exif['ExposureTime'])) . ' sec</td></tr>'; 01084 01085 if (isset($exif['ISOSpeedRatings'])) 01086 echo '<tr><td>ISO-speed:</td><td>' . htmlspecialchars(_skinfiles_exif_prepare($exif['ISOSpeedRatings'])) . '</td></tr>'; 01087 } 01088 } 01089 01090 echo '</table>'; 01091 } 01092 } 01093 else 01094 { 01095 echo "<p class='error'>" . _SKINFILES_ERR_VIEW_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_VIEW_FILE2; 01096 echo _SKINFILES_ERR_VIEW_FILE3 . "</p>"; 01097 } 01098 } 01099 01100 function _skinfiles_exif_prepare($value) { 01101 if (preg_match('#([0-9]+)/([0-9]+)#', $value, $matches)) 01102 if ($matches[1] < $matches[2]) 01103 return '1/' . round($matches[2] / $matches[1]); 01104 else 01105 return round($matches[1] / $matches[2]); 01106 else 01107 return $value; 01108 } 01109 01110 01111 01112 01113 /* Edit file *********************************************************************************************************************/ 01114 01115 function _skinfiles_editfile() { 01116 01117 global $pluginUrl, $manager; 01118 01119 $file = basename(trim(requestVar('file'))); 01120 $directory = dirname(trim(requestVar('file'))); 01121 $directory = sfExpandDirectory ($directory); 01122 01123 if (sfValidPath($directory) && file_exists($directory . $file) && 01124 is_file($directory . $file) && is_writable($directory . $file) && sfAllowEditing($file)) 01125 { 01126 $relative = sfRelativePath ($directory); 01127 $editUrl = $manager->addTicketToUrl($pluginUrl . '?action=editfile&file=' . rawurlencode(sfRelativePath($directory . $file))); 01128 01129 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 01130 echo '<a href="' . htmlspecialchars($editUrl) . '" title="Edit «' . $file . '»">'; 01131 echo '<img src="' . htmlspecialchars(sfIcon($file)) . '" alt="" /> ' . $file . '</a></p>'; 01132 01133 $content = implode('', file($directory . $file)); 01134 01135 echo '<div class="dialogbox">'; 01136 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 01137 $manager->addTicketHidden(); 01138 echo '<input type="hidden" name="action" value="editfile_process" />'; 01139 echo '<input type="hidden" name="file" value="' . htmlspecialchars(sfRelativePath($directory . $file)) . '" />'; 01140 01141 echo '<h4>' . _SKINFILES_EDIT_FILE_MSG . ' «' . htmlspecialchars($file) . '»</h4><div>'; 01142 echo '<p><textarea class="skinedit" tabindex="8" rows="20" cols="80" name="content">'; 01143 echo htmlspecialchars($content); 01144 echo '</textarea></p>'; 01145 01146 echo '<p class="buttons">'; 01147 echo '<input type="hidden" name="sure" value="yes" /">'; 01148 echo '<input type="submit" value="' . _SKINFILES_SAVE_CHANGES . '" />'; 01149 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 01150 echo '</p>'; 01151 echo '</div></form></div>'; 01152 } 01153 else 01154 { 01155 echo "<p class='error'>" . _SKINFILES_ERR_EDIT_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_EDIT_FILE2; 01156 echo _SKINFILES_ERR_EDIT_FILE3 . "</p>"; 01157 } 01158 } 01159 01160 function _skinfiles_editfile_process() { 01161 01162 $file = basename(trim(requestVar('file'))); 01163 $directory = dirname(trim(requestVar('file'))); 01164 $directory = sfExpandDirectory ($directory); 01165 01166 if (requestVar('sure') == 'yes') 01167 { 01168 if (sfValidPath($directory) && file_exists($directory . $file) && 01169 is_file($directory . $file) && is_writable($directory . $file) && sfAllowEditing($file)) 01170 { 01171 $content = postVar('content'); 01172 $success = false; 01173 01174 if ($fh = @fopen($directory . $file, 'wb')) { 01175 01176 if (@fwrite($fh, $content) !== false) 01177 $success = true; 01178 01179 @fclose($fh); 01180 } 01181 01182 if ($success) 01183 echo "<p class='message'>" . _SKINFILES_ERR_EDIT_FILE4 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_EDIT_FILE5 . "</p>"; 01184 else 01185 echo "<p class='error'>" . _SKINFILES_ERR_EDIT_FILE6 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_EDIT_FILE7 . "</p>"; 01186 01187 _skinfiles_editfile(); 01188 } 01189 else 01190 { 01191 echo "<p class='error'>" . _SKINFILES_ERR_EDIT_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_EDIT_FILE2; 01192 echo _SKINFILES_ERR_EDIT_FILE3 . "</p>"; 01193 } 01194 } 01195 else 01196 { 01197 // User cancelled 01198 sfShowDirectory($directory); 01199 } 01200 } 01201 01202 01203 01204 /* Rename file *******************************************************************************************************************/ 01205 01206 function _skinfiles_renfile($preset = '') { 01207 01208 global $pluginUrl, $manager; 01209 01210 $file = basename(trim(requestVar('file'))); 01211 $directory = dirname(trim(requestVar('file'))); 01212 $directory = sfExpandDirectory ($directory); 01213 01214 if (sfValidPath($directory) && file_exists($directory . $file) && 01215 is_file($directory . $file) && is_writable($directory . $file)) 01216 { 01217 $relative = sfRelativePath ($directory); 01218 $editUrl = $manager->addTicketToUrl($pluginUrl . '?action=renfile&file=' . rawurlencode(sfRelativePath($directory . $file))); 01219 01220 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 01221 echo '<a href="' . htmlspecialchars($editUrl) . '" title="' . _SKINFILES_RENAME . ' «' . $file . '»">'; 01222 echo '<img src="' . htmlspecialchars(sfIcon($file)) . '" alt="" /> ' . $file . '</a></p>'; 01223 01224 echo '<div class="dialogbox">'; 01225 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 01226 $manager->addTicketHidden(); 01227 echo '<input type="hidden" name="action" value="renfile_process" />'; 01228 echo '<input type="hidden" name="file" value="' . htmlspecialchars(sfRelativePath($directory . $file)) . '" />'; 01229 01230 echo '<h4>' . _SKINFILES_RENAME_FILE_MSG . '«' . htmlspecialchars($file) . '» ' . _SKINFILES_RENAME_FILE_MSG2 . '</h4><div>'; 01231 echo '<p><input type="text" name="name" size="40" value="' . htmlspecialchars($preset != '' ? $preset : $file) . '" /></p>'; 01232 echo '<p class="buttons">'; 01233 echo '<input type="hidden" name="sure" value="yes" /">'; 01234 echo '<input type="submit" value="' . _SKINFILES_RENAME . '" />'; 01235 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 01236 echo '</p>'; 01237 echo '</div></form></div>'; 01238 } 01239 else 01240 { 01241 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_RENAME_FILE2; 01242 echo _SKINFILES_ERR_RENAME_FILE3 . "</p>"; 01243 } 01244 } 01245 01246 function _skinfiles_renfile_process() { 01247 01248 global $pluginUrl, $manager; 01249 01250 $file = basename(trim(requestVar('file'))); 01251 $directory = dirname(trim(requestVar('file'))); 01252 $directory = sfExpandDirectory ($directory); 01253 01254 if (requestVar('sure') == 'yes') 01255 { 01256 if (sfValidPath($directory) && file_exists($directory . $file) && 01257 is_file($directory . $file) && is_writable($directory . $file)) 01258 { 01259 $name = requestVar('name'); 01260 01261 if ($name == '') { 01262 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE4 . "«" . htmlspecialchars($file) . "» "; 01263 echo _SKINFILES_ERR_RENAME_FILE5 . "</p>"; 01264 _skinfiles_renfile($name); 01265 return; 01266 } 01267 01268 if (sfIllegalFilename($name)) { 01269 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE6 . "«" . htmlspecialchars($file) . "» "; 01270 echo _SKINFILES_ERR_RENAME_FILE7 . "</p>"; 01271 _skinfiles_renfile($name); 01272 return; 01273 } 01274 01275 if ($name == $file) { 01276 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE8 . "«" . htmlspecialchars($file) . "» "; 01277 echo _SKINFILES_ERR_RENAME_FILE9 . "</p>"; 01278 _skinfiles_renfile($name); 01279 return; 01280 } 01281 01282 if (file_exists($directory . $name)) { 01283 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE10 . "«" . htmlspecialchars($file) . "» "; 01284 echo _SKINFILES_ERR_RENAME_FILE11; 01285 echo _SKINFILES_ERR_RENAME_FILE12 . "</p>"; 01286 _skinfiles_renfile($name); 01287 return; 01288 } 01289 01290 if (!@rename($directory . $file, $directory . $name)) 01291 { 01292 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE13 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_RENAME_FILE14 . "</p>"; 01293 _skinfiles_renfile($name); 01294 return; 01295 } 01296 01297 echo "<p class='message'>" . _SKINFILES_ERR_RENAME_FILE15 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_RENAME_FILE16; 01298 echo _SKINFILES_ERR_RENAME_FILE17 . "«" . htmlspecialchars($name) . "»" . _SKINFILES_ERR_RENAME_FILE18 . "</p>"; 01299 sfShowDirectory($directory); 01300 } 01301 else 01302 { 01303 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_RENAME_FILE2; 01304 echo _SKINFILES_ERR_RENAME_FILE3 . "</p>"; 01305 } 01306 } 01307 else 01308 { 01309 // User cancelled 01310 sfShowDirectory($directory); 01311 } 01312 } 01313 01314 01315 01316 01317 /* Create file *******************************************************************************************************************/ 01318 01319 function _skinfiles_createfile() { 01320 01321 $directory = trim(requestVar('dir')); 01322 $directory = sfExpandDirectory($directory); 01323 01324 if (sfValidPath($directory) && is_dir($directory) && is_writable($directory)) 01325 { 01326 $name = requestVar('name'); 01327 01328 if ($name == '') { 01329 echo "<p class='error'>" . _SKINFILES_ERR_CREATE_FILE1 . "</p>"; 01330 sfShowDirectory($directory); 01331 return; 01332 } 01333 01334 if (sfIllegalFilename($name)) { 01335 echo "<p class='error'>" . _SKINFILES_ERR_CREATE_FILE2 . "«" . htmlspecialchars($name) . "» "; 01336 echo _SKINFILES_ERR_CREATE_FILE3 . "</p>"; 01337 sfShowDirectory($directory); 01338 return; 01339 } 01340 01341 if (file_exists($directory . $name)) { 01342 echo "<p class='error'>" . _SKINFILES_ERR_CREATE_FILE4 . "«" . htmlspecialchars($name) . "» "; 01343 echo _SKINFILES_ERR_CREATE_FILE5; 01344 echo _SKINFILES_ERR_CREATE_FILE6 . "</p>"; 01345 sfShowDirectory($directory); 01346 return; 01347 } 01348 01349 if (!@touch($directory . $name)) 01350 { 01351 echo "<p class='error'>" . _SKINFILES_ERR_CREATE_FILE7 . "«" . htmlspecialchars($name) . "» " . _SKINFILES_ERR_CREATE_FILE8 . "</p>"; 01352 sfShowDirectory($directory); 01353 return; 01354 } 01355 01356 $mask = @umask(0000); 01357 @chmod($directory . $name, 0755); 01358 @umask($mask); 01359 01360 echo "<p class='message'>" . _SKINFILES_ERR_CREATE_FILE9 . "«" . htmlspecialchars($name) . "» " . _SKINFILES_ERR_CREATE_FILE10 . "</p>"; 01361 sfShowDirectory($directory); 01362 } 01363 else 01364 { 01365 echo "<p class='error'>" . _SKINFILES_ERR_CREATE_FILE11 . "«" . htmlspecialchars(basename($directory)) . "» " . _SKINFILES_ERR_CREATE_FILE12; 01366 echo _SKINFILES_ERR_CREATE_FILE13 . "</p>"; 01367 } 01368 } 01369 01370 01371 01372 01373 /* Delete file *******************************************************************************************************************/ 01374 01375 function _skinfiles_delfile() { 01376 01377 global $pluginUrl, $manager; 01378 01379 $file = basename(trim(requestVar('file'))); 01380 $directory = dirname(trim(requestVar('file'))); 01381 $directory = sfExpandDirectory ($directory); 01382 01383 if (sfValidPath($directory) && file_exists($directory . $file) && 01384 is_file($directory . $file) && is_writable($directory . $file)) 01385 { 01386 $relative = sfRelativePath ($directory); 01387 $delUrl = $manager->addTicketToUrl($pluginUrl . '?action=delfile&file=' . rawurlencode(sfRelativePath($directory . $file))); 01388 01389 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 01390 echo '<a href="' . htmlspecialchars($delUrl) . '" title="' . _SKINFILES_DELETE . ' «' . $file . '»">'; 01391 echo '<img src="' . htmlspecialchars(sfIcon($file)) . '" alt="" /> ' . $file . '</a></p>'; 01392 01393 echo '<div class="dialogbox">'; 01394 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 01395 $manager->addTicketHidden(); 01396 echo '<input type="hidden" name="action" value="delfile_process" />'; 01397 echo '<input type="hidden" name="file" value="' . htmlspecialchars(sfRelativePath($directory . $file)) . '" />'; 01398 01399 echo '<h4>' . _SKINFILES_DELETE_FILE . ' «' . htmlspecialchars($file) . '» ' . _SKINFILES_DELETE_FILE2 . '</h4><div>'; 01400 echo '<p class="buttons">'; 01401 echo '<input type="hidden" name="sure" value="yes" />'; 01402 echo '<input type="submit" value="' . _SKINFILES_DELETE . '" />'; 01403 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 01404 echo '</p>'; 01405 echo '</div></form></div>'; 01406 } 01407 else 01408 { 01409 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_FILE2; 01410 echo _SKINFILES_ERR_DELETE_FILE3 . "</p>"; 01411 } 01412 } 01413 01414 function _skinfiles_delfile_process() { 01415 01416 global $pluginUrl, $manager; 01417 01418 $file = basename(trim(requestVar('file'))); 01419 $directory = dirname(trim(requestVar('file'))); 01420 $directory = sfExpandDirectory ($directory); 01421 01422 if (requestVar('sure') == 'yes') 01423 { 01424 if (sfValidPath($directory) && file_exists($directory . $file) && 01425 is_file($directory . $file) && is_writable($directory . $file)) 01426 { 01427 if (!@unlink($directory . $file)) 01428 { 01429 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_FILE4 . "«" . htmlspecialchars($file) . "»</p>"; 01430 sfShowDirectory($directory); 01431 return; 01432 } 01433 01434 echo "<p class='message'>" . _SKINFILES_ERR_DELETE_FILE5 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_FILE6 . "</p>"; 01435 sfShowDirectory($directory); 01436 } 01437 else 01438 { 01439 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_FILE2; 01440 echo _SKINFILES_ERR_DELETE_FILE3 . "</p>"; 01441 } 01442 } 01443 else 01444 { 01445 // User cancelled 01446 sfShowDirectory($directory); 01447 } 01448 } 01449 01450 01451 01452 /* Upload file *******************************************************************************************************************/ 01453 01454 function _skinfiles_uploadfile() { 01455 01456 global $pluginUrl, $manager, $CONF; 01457 01458 $directory = trim(requestVar('dir')); 01459 $directory = sfExpandDirectory($directory); 01460 01461 if (sfValidPath($directory) && is_dir($directory) && is_writable($directory)) 01462 { 01463 $file = postFileInfo('name'); 01464 01465 if ($file['size'] > $CONF['MaxUploadSize']) { 01466 echo "<p class='error'>" . _SKINFILES_ERR_UPLOAD_FILE1 . "«" . htmlspecialchars($file['name']) . "» " . _SKINFILES_ERR_UPLOAD_FILE2 . _ERROR_FILE_TOO_BIG . "<br />"; 01467 echo _SKINFILES_ERR_UPLOAD_FILE3 . $CONF['MaxUploadSize'] . " / "; 01468 echo $file['size'] . " bytes</p>"; 01469 sfShowDirectory($directory); 01470 return; 01471 } 01472 01473 if (!is_uploaded_file($file['tmp_name'])) { 01474 echo "<p class='error'>" . _SKINFILES_ERR_UPLOAD_FILE1 . "«" . htmlspecialchars($file['name']) . "» " . _SKINFILES_ERR_UPLOAD_FILE2 . _ERROR_BADREQUEST . _SKINFILES_ERR_UPLOAD_FILE4 . "</p>"; 01475 sfShowDirectory($directory); 01476 return; 01477 } 01478 01479 if (sfIllegalFilename($file['name'])) { 01480 echo "<p class='error'>" . _SKINFILES_ERR_UPLOAD_FILE5 . "«" . htmlspecialchars($file['name']) . "» "; 01481 echo _SKINFILES_ERR_UPLOAD_FILE6 . "</p>"; 01482 sfShowDirectory($directory); 01483 return; 01484 } 01485 01486 if (file_exists($directory . $file['name'])) { 01487 echo "<p class='error'>" . _SKINFILES_ERR_UPLOAD_FILE1 . "«" . htmlspecialchars($file['name']) . "» " . _SKINFILES_ERR_UPLOAD_FILE2 . _ERROR_UPLOADDUPLICATE . "</p>"; 01488 sfShowDirectory($directory); 01489 return; 01490 } 01491 01492 if (!@move_uploaded_file($file['tmp_name'], $directory . $file['name'])) { 01493 echo "<p class='error'>" . _SKINFILES_ERR_UPLOAD_FILE1 . "«" . htmlspecialchars($file['name']) . "» " . _SKINFILES_ERR_UPLOAD_FILE2 . _ERROR_UPLOADMOVEP . _SKINFILES_ERR_UPLOAD_FILE4 . "</p>"; 01494 sfShowDirectory($directory); 01495 } 01496 01497 $mask = @umask(0000); 01498 @chmod($directory . $file['name'], 0755); 01499 @umask($mask); 01500 01501 echo "<p class='message'>" . _SKINFILES_ERR_UPLOAD_FILE7 . "«" . htmlspecialchars($file['name']) . "» " . _SKINFILES_ERR_UPLOAD_FILE8 . "</p>"; 01502 sfShowDirectory($directory); 01503 } 01504 else 01505 { 01506 echo "<p class='error'>" . _SKINFILES_ERR_UPLOAD_FILE9 . "«" . htmlspecialchars(basename($directory)) . "» " . _SKINFILES_ERR_UPLOAD_FILE10; 01507 echo _SKINFILES_ERR_UPLOAD_FILE11 . "</p>"; 01508 } 01509 } 01510 01511 01512 01513 01514 01515 ?>