| [ Index ] |
PHP Cross Reference of Nucleus CMS v3.51 code documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* ========================================================================================== 4 * Nucleus SkinFiles Plugin 5 * 6 * Copyright 2005-2007 by Jeff MacMichael and Niels Leenheer 7 * 8 * @version $Id: index.php 1200 2007-09-07 07:06:37Z kimitake $ 9 * @version $NucleusJP: index.php,v 1.5.2.1 2005/08/25 07:04:13 kimitake Exp $ 10 * 11 * ========================================================================================== 12 * This program is free software and open source software; you can redistribute 13 * it and/or modify it under the terms of the GNU General Public License as 14 * published by the Free Software Foundation; either version 2 of the License, 15 * or (at your option) any later version. 16 * 17 * This program is distributed in the hope that it will be useful, but WITHOUT 18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 20 * more details. 21 * 22 * You should have received a copy of the GNU General Public License along 23 * with this program; if not, write to the Free Software Foundation, Inc., 24 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit 25 * http://www.gnu.org/licenses/gpl.html 26 * ========================================================================================== 27 */ 28 29 $strRel = '../../../'; 30 require ($strRel . 'config.php'); 31 include ($DIR_LIBS . 'PLUGINADMIN.php'); 32 33 $language = ereg_replace( '[\\|/]', '', getLanguageName()); 34 $langfile = $language.'.php'; 35 if (file_exists($langfile)) 36 include_once($langfile); 37 else 38 include_once ('english.php'); 39 40 /** 41 * Create admin area 42 */ 43 44 $oPluginAdmin = new PluginAdmin('SkinFiles'); 45 46 if (!($member->isLoggedIn() && $member->isAdmin())) 47 { 48 $oPluginAdmin->start(); 49 echo '<p>' . _ERROR_DISALLOWED . '</p>'; 50 $oPluginAdmin->end(); 51 exit; 52 } 53 54 55 56 /** 57 * Setup main variables 58 */ 59 60 $rootDirectory = sfRealPath($DIR_SKINS); 61 $rootUrl = $CONF['SkinsURL']; 62 $pluginUrl = $oPluginAdmin->plugin->getAdminURL(); 63 64 $filetypes = array ( 65 'text' => array ('inc', 'txt', 'css', 'js', 'php'), 66 'html' => array ('htm', 'html'), 67 'img' => array ('png', 'gif', 'jpg', 'jpeg', 'bmp', 'ico', 'swf'), 68 ); 69 70 71 /** 72 * Bypass admin area for downloads 73 */ 74 75 $action = requestVar('action'); 76 77 if ($action == 'download') { 78 _skinfiles_download(); 79 exit; 80 } 81 82 83 /** 84 * Build admin area 85 */ 86 87 $oPluginAdmin->start("<style type='text/css'> 88 <!-- 89 90 div#content a { 91 text-decoration: none; 92 } 93 div#content img { 94 vertical-align: middle; 95 margin-top: -3px; 96 } 97 p.message { 98 font-weight: bold; 99 } 100 p.error { 101 font-size: 100%; 102 font-weight: bold; 103 color: #880000; 104 } 105 pre { 106 overflow: auto; 107 height: 400px; 108 } 109 iframe { 110 width: 100%; 111 height: 400px; 112 border: 1px solid gray; 113 } 114 div.dialogbox { 115 border: 1px solid #ddd; 116 background-color: #F6F6F6; 117 margin: 18px 0 1.5em 0; 118 } 119 div.dialogbox h4 { 120 background-color: #bbc; 121 color: #000; 122 margin: 0; 123 padding: 5px; 124 } 125 div.dialogbox h4.light { 126 background-color: #ddd; 127 } 128 div.dialogbox div { 129 margin: 0; 130 padding: 10px; 131 } 132 div.dialogbox button { 133 margin: 10px 0 0 6px; 134 float: right; 135 } 136 div.dialogbox p { 137 margin: 0; 138 } 139 div.dialogbox p.buttons { 140 text-align: right; 141 overflow: auto; 142 } 143 div.dialogbox textarea { 144 width: 100%; 145 margin: 0; 146 } 147 148 --> 149 </style>"); 150 151 echo "<h2>" . _SKINFILES_MANAGEMENT . "</h2>"; 152 153 $actions = array ( 154 'renfile', 'renfile_process', 'delfile', 'delfile_process', 155 'editfile', 'editfile_process', 'uploadfile', 'createfile', 'viewfile', 156 'rendir', 'rendir_process', 'deldir', 'deldir_process', 157 'emptydir', 'emptydir_process', 'createdir' 158 ); 159 160 if (in_array($action, $actions)) 161 { 162 if (!$manager->checkTicket()) 163 { 164 echo '<p class="error">Error: ' . _ERROR_BADTICKET . '</p>'; 165 sfShowDirectory(); 166 167 } 168 else 169 { 170 call_user_func('_skinfiles_' . $action); 171 } 172 } 173 else 174 { 175 sfShowDirectory(); 176 } 177 178 $oPluginAdmin->end(); 179 exit; 180 181 182 183 184 185 186 187 /* Helper functions **************************************************************************************************************/ 188 189 function sfExpandDirectory ($path) { 190 /* IN: relative directory 191 * OUT: full path to directory 192 */ 193 194 global $rootDirectory; 195 return sfRealPath($rootDirectory . $path); 196 } 197 198 function sfRealPath ($path) { 199 /* IN: full path 200 * OUT: canonicalized absolute pathname 201 */ 202 203 $path = realpath($path); 204 $path = str_replace('\\', '/', $path); 205 $path = substr($path, strlen($path) - 1) != '/' ? $path . '/' : $path; 206 return $path; 207 } 208 209 function sfFullUrl ($path) { 210 /* IN: full path including filename 211 * OUT: url including filename 212 */ 213 214 global $rootDirectory, $rootUrl; 215 216 $path = str_replace($rootDirectory, '', $path); 217 $path = rawurlencode($path); 218 $path = str_replace('%2F', '/', $path); 219 return $rootUrl . $path; 220 } 221 222 function sfValidPath ($path) { 223 /* IN: full path excluding or including filename 224 * OUT: boolean, true if full path is or is within rootDirectory 225 */ 226 227 global $rootDirectory; 228 return substr($path, 0, strlen($rootDirectory)) == $rootDirectory; 229 } 230 231 function sfRelativePath ($path) { 232 /* IN: full path including or excluding filename 233 * OUT: relative path from rootDirectory 234 */ 235 236 global $rootDirectory; 237 return str_replace($rootDirectory, '', $path); 238 } 239 240 function sfIsFileType ($type, $file) { 241 242 global $filetypes; 243 return isset($filetypes[$type]) && in_array(strtolower(substr(strrchr($file, "."), 1)), $filetypes[$type]); 244 } 245 246 function sfAllowEditing ($file) { 247 return sfIsFileType('html', $file) || sfIsFileType('text', $file); 248 } 249 250 function sfAllowViewing ($file) { 251 return sfIsFileType('html', $file) || sfIsFileType('text', $file) || sfIsFileType('img', $file); 252 } 253 254 255 function sfDisplayPath ($relative) { 256 257 global $pluginUrl; 258 259 $result = '<a href="' . htmlspecialchars($pluginUrl) . '" title="Go back to «skins»">'; 260 $result .= '<img src="' . htmlspecialchars($pluginUrl . 'home.gif') . '" alt="" /> skins</a> / '; 261 262 $parts = explode('/', $relative); 263 $part = ''; 264 265 while (list(,$v) = each ($parts)) { 266 if ($v != '') { 267 $part .= $v . '/'; 268 269 $result .= '<a href="' . htmlspecialchars($pluginUrl . '?dir=' . rawurlencode($part)) . '" '; 270 $result .= 'title="Go back to «' . htmlspecialchars($v) . '»">'; 271 $result .= '<img src="' . htmlspecialchars($pluginUrl . 'dir.gif') . '" alt="" /> '; 272 $result .= htmlspecialchars($v) . '</a> / '; 273 } 274 } 275 276 return $result; 277 } 278 279 function sfIcon ($file) { 280 281 global $pluginUrl; 282 283 $ext = strtolower(substr(strrchr($file, "."), 1)); 284 285 switch ($ext) { 286 case 'htm': 287 case 'html': 288 return $pluginUrl . 'html.gif'; 289 break; 290 291 case 'txt': 292 case 'js': 293 case 'css': 294 case 'inc': 295 return $pluginUrl . 'text.gif'; 296 break; 297 298 case 'gif': 299 case 'png': 300 case 'jpg': 301 case 'jpeg': 302 case 'bmp': 303 case 'xbmp': 304 case 'ico': 305 return $pluginUrl . 'image.gif'; 306 break; 307 308 case 'php': 309 case 'php3': 310 case 'php4': 311 return $pluginUrl . 'php.gif'; 312 break; 313 314 default: 315 return $pluginUrl . 'generic.gif'; 316 break; 317 } 318 } 319 320 function sfIllegalFilename($name) { 321 return preg_match('#[\n\r\\\/\:\*\?\"\<\>\|]#', $name); 322 } 323 324 function sfDirectoryIsEmpty($dir) { 325 326 $count = 0; 327 328 if ($dh = opendir($dir)) 329 { 330 while (($file = readdir($dh)) !== false) 331 $count++; 332 333 closedir($dh); 334 } 335 336 // $count must be smaller or equal than 2, because '.' 337 // and '..' are always returned by readdir(). 338 return $count <= 2; 339 } 340 341 342 343 344 345 346 347 348 349 /* Show directory ****************************************************************************************************************/ 350 351 function sfShowDirectory($default = '') { 352 353 global $pluginUrl, $rootDirectory, $CONF, $manager; 354 355 $directory = $default != '' ? 356 $default : 357 sfExpandDirectory(trim(requestVar('dir'))); 358 359 if (!sfValidPath($directory) || !is_dir($directory)) { 360 $directory = $rootDirectory; 361 } 362 363 $relative = sfRelativePath ($directory); 364 365 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative) . '</p>'; 366 367 368 $dirs = array(); 369 $files = array(); 370 371 if ($dh = @opendir($directory)) { 372 while (($file = readdir($dh)) !== false) { 373 if (!preg_match("/^\.{1,2}$/", $file)) { 374 $fstat = @stat($directory . $file); 375 376 if ($fstat['mode'] & 040000) 377 $dirs[$file] = $fstat; 378 else 379 $files[$file] = $fstat; 380 } 381 } 382 closedir($dh); 383 } 384 385 ksort($dirs); 386 ksort($files); 387 388 echo '<table><thead><tr>'; 389 echo '<th>' . _SKINFILES_NAME . '</th><th>' . _SKINFILES_SIZE . '</th><th>' . _SKINFILES_LAST_MODIFIED . '</th><th colspan="4">' . _SKINFILES_ACTIONS . '</th>'; 390 echo '</tr></thead>'; 391 392 while (list($name, $stat) = each($dirs)) { 393 394 $dir = sfRelativePath($directory . $name . '/'); 395 396 echo '<tr onmouseover="focusRow(this);" onmouseout="blurRow(this);"><td>'; 397 398 if (is_readable ($directory . $name)) 399 { 400 echo '<a href="' . htmlspecialchars($pluginUrl . '?dir=' . rawurlencode($dir)) . '">'; 401 echo '<img src="' . htmlspecialchars($pluginUrl . 'dir.gif') . '" alt="folder" /> '; 402 echo htmlspecialchars($name).'</a>'; 403 } 404 else 405 { 406 echo '<img src="' . htmlspecialchars($pluginUrl . 'dir.gif') . '" alt="folder" /> '; 407 echo htmlspecialchars($name); 408 } 409 410 echo '</td>'; 411 412 $renUrl = $manager->addTicketToUrl($pluginUrl . '?action=rendir&dir=' . rawurlencode($dir)); 413 $delUrl = $manager->addTicketToUrl($pluginUrl . '?action=deldir&dir=' . rawurlencode($dir)); 414 415 echo '<td>–</td>'; 416 echo '<td>' . date(_SKINFILES_DATE_FORMAT, $stat['mtime']); 417 418 419 if (is_writable($directory . $name)) { 420 echo '<td><a href="' . htmlspecialchars($renUrl) . '" title="' . _SKINFILES_RENAME . ' «' . htmlspecialchars($name) . '»">' . _SKINFILES_RENAME . '</a></td>'; 421 } else { 422 echo '<td> </td>'; 423 } 424 425 if (is_writable($directory . $name) && sfDirectoryIsEmpty($directory . $name)) { 426 echo '<td><a href="' . htmlspecialchars($delUrl) . '" title="' . _SKINFILES_DELETE . ' «' . htmlspecialchars($name) . '»">' . _SKINFILES_DELETE . '</a></td>'; 427 } else { 428 echo '<td> </td>'; 429 } 430 431 echo '<td> </td><td> </td>'; 432 echo '</tr>'; 433 } 434 435 436 while (list($name, $stat) = each($files)) { 437 438 $file = sfRelativePath($directory . $name); 439 440 $renUrl = $manager->addTicketToUrl($pluginUrl . '?action=renfile&file=' . rawurlencode($file)); 441 $delUrl = $manager->addTicketToUrl($pluginUrl . '?action=delfile&file=' . rawurlencode($file)); 442 $editUrl = $manager->addTicketToUrl($pluginUrl . '?action=editfile&file=' . rawurlencode($file)); 443 $viewUrl = $manager->addTicketToUrl($pluginUrl . '?action=viewfile&file=' . rawurlencode($file)); 444 $dlUrl = $manager->addTicketToUrl($pluginUrl . '?action=download&file=' . rawurlencode($file)); 445 446 echo '<tr onmouseover="focusRow(this);" onmouseout="blurRow(this);"><td>'; 447 448 if (is_readable ($directory . $name) && sfAllowViewing($name)) 449 { 450 echo '<a href="' . htmlspecialchars($viewUrl) . '">'; 451 echo '<img src="' . htmlspecialchars(sfIcon($name)) . '" alt="" /> '; 452 echo htmlspecialchars($name).'</a>'; 453 } 454 else 455 { 456 echo '<img src="' . htmlspecialchars(sfIcon($name)) . '" alt="" /> '; 457 echo htmlspecialchars($name); 458 } 459 460 echo '</td><td>'; 461 echo ceil($stat['size'] / 1024) . ' kB'; 462 echo '</td><td>'; 463 echo date(_SKINFILES_DATE_FORMAT, $stat['mtime']); 464 echo '</td><td>'; 465 466 if (is_writable($directory . $name)) { 467 echo '<a href="' . htmlspecialchars($renUrl) . '" title="' . _SKINFILES_RENAME . ' «' . htmlspecialchars($name) . '»">' . _SKINFILES_RENAME . '</a>'; 468 } else { 469 echo ' '; 470 } 471 472 echo '</td><td>'; 473 474 if (is_writable($directory . $name)) { 475 echo '<a href="' . htmlspecialchars($delUrl) . '" title="' . _SKINFILES_DELETE . ' «' . htmlspecialchars($name) . '»">' . _SKINFILES_DELETE . '</a>'; 476 } else { 477 echo ' '; 478 } 479 480 echo '</td><td>'; 481 482 if (is_writable($directory . $name) && sfAllowEditing($name)) 483 echo '<a href="'. htmlspecialchars($editUrl) . '" title="' . _SKINFILES_EDIT . ' «' . htmlspecialchars($name) . '»">' . _SKINFILES_EDIT . '</a>'; 484 else 485 echo ' '; 486 487 echo '</td><td>'; 488 489 if (is_readable ($directory . $name)) 490 echo '<a href="' . htmlspecialchars($dlUrl) . '" title="' . _SKINFILES_DOWNLOAD . ' «' . htmlspecialchars($name) . '»">' . _SKINFILES_DOWNLOAD . '</a>'; 491 else 492 echo ' '; 493 494 echo '</td></tr>'; 495 } 496 497 if (!count($dirs) && !count($files)) { 498 echo '<tr><td colspan="7">' . _SKINFILES_ERR_DIR_DOES_NOT_CONTAIN . '</td></tr>'; 499 } 500 501 echo '</table>'; 502 503 if ($relative != '') { 504 505 if (is_writable($directory)) { 506 echo '<div class="dialogbox">'; 507 echo '<h4 class="light">' . _SKINFILES_CREATE_NEW_FILE . '</h4><div>'; 508 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 509 $manager->addTicketHidden(); 510 echo '<input type="hidden" name="action" value="createfile" />'; 511 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative) . '" />'; 512 echo '<input type="text" name="name" size="40" value="untitled.txt" />'; 513 echo '<p class="buttons"><input type="submit" value="' . _SKINFILES_CREATE_FILE . '" /></p></form>'; 514 echo '</div></div>'; 515 516 echo '<div class="dialogbox">'; 517 echo '<h4 class="light">' . _SKINFILES_UPLOAD_NEW_FILE . '</h4><div>'; 518 echo '<form method="post" enctype="multipart/form-data" action="' . htmlspecialchars($pluginUrl) . '">'; 519 $manager->addTicketHidden(); 520 echo '<input type="hidden" name="action" value="uploadfile" />'; 521 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative) . '" />'; 522 echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . $CONF['MaxUploadSize'] . '" />'; 523 echo '<input type="file" name="name" size="40" />'; 524 echo '<p class="buttons"><input type="submit" value="' . _SKINFILES_UPLOAD . '" /></p></form>'; 525 echo '</div></div>'; 526 } 527 528 if (count($files)) { 529 echo '<div class="dialogbox">'; 530 echo '<h4 class="light">' . _SKINFILES_DEL_ALL_FILES . '</h4><div>'; 531 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 532 $manager->addTicketHidden(); 533 echo '<input type="hidden" name="action" value="emptydir" />'; 534 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative) . '" />'; 535 echo _SKINFILES_DEL_ALL_FILES_MSG; 536 echo '<p class="buttons"><input type="submit" value="' . _SKINFILES_DELETE_ALL . '" tabindex="140" onclick="return checkSubmit();" /></p>'; 537 echo '</form>'; 538 echo '</div></div>'; 539 } 540 } 541 542 if (is_writable($directory)) { 543 echo '<div class="dialogbox">'; 544 echo '<h4 class="light">' . _SKINFILES_CREATE_NEW_DIR . '</h4><div>'; 545 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 546 $manager->addTicketHidden(); 547 echo '<input type="hidden" name="action" value="createdir" />'; 548 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative) . '" />'; 549 echo '<input type="text" name="name" value="untitled" tabindex="90" size="40" />'; 550 echo '<p class="buttons"><input type="submit" value="' . _SKINFILES_CREATE . '" tabindex="140" onclick="return checkSubmit();" /></p>'; 551 echo '</form>'; 552 echo '</div></div>'; 553 } 554 } 555 556 557 558 559 /* Rename directory **************************************************************************************************************/ 560 561 function _skinfiles_rendir($preset = '') { 562 563 global $pluginUrl, $manager; 564 565 $file = trim(basename(requestVar('dir'))); 566 $directory = trim(dirname(requestVar('dir'))); 567 $directory = sfExpandDirectory ($directory); 568 569 if (sfValidPath($directory . $file) && file_exists($directory . $file) && 570 is_dir($directory . $file) && is_writable($directory . $file)) 571 { 572 $relative = sfRelativePath ($directory); 573 $editUrl = $manager->addTicketToUrl($pluginUrl . '?action=rendir&dir=' . rawurlencode($relative . $file)); 574 575 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 576 echo '<a href="' . htmlspecialchars($editUrl) . '" title="' . _SKINFILES_RENAME . ' «' . $file . '»">'; 577 echo '<img src="' . $pluginUrl . 'dir.gif' . '" alt="" /> ' . $file . '</a></p>'; 578 579 echo '<div class="dialogbox">'; 580 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 581 $manager->addTicketHidden(); 582 echo '<input type="hidden" name="action" value="rendir_process" />'; 583 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative . $file) . '" />'; 584 585 echo '<h4>' . _SKINFILES_RENAME_DIR_MSG . ' «' . htmlspecialchars($file) . '» ' . _SKINFILES_RENAME_DIR_MSG2 . '</h4><div>'; 586 echo '<p><input type="text" name="name" size="40" value="' . htmlspecialchars($preset != '' ? $preset : $file) . '" /></p>'; 587 echo '<p class="buttons">'; 588 echo '<input type="hidden" name="sure" value="yes" />'; 589 echo '<input type="submit" value="' . _SKINFILES_RENAME . '" />'; 590 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 591 echo '</p>'; 592 echo '</div></form></div>'; 593 } 594 else 595 { 596 echo "<p class='error'>" . _SKINFILES_ERR_DIR_DOES_NOT_EXIST1 . " «" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DIR_DOES_NOT_EXIST2; 597 echo _SKINFILES_ERR_DIR_DOES_NOT_EXIST3 . "</p>"; 598 } 599 } 600 601 function _skinfiles_rendir_process() { 602 603 global $pluginUrl, $manager; 604 605 $file = trim(basename(requestVar('dir'))); 606 $directory = trim(dirname(requestVar('dir'))); 607 $directory = sfExpandDirectory ($directory); 608 609 if (requestVar('sure') == 'yes') 610 { 611 if (sfValidPath($directory . $file) && file_exists($directory . $file) && 612 is_dir($directory . $file) && is_writable($directory . $file)) 613 { 614 $name = requestVar('name'); 615 616 if ($name == '') { 617 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_RENAME_DIR1 . "«" . htmlspecialchars($file) . "» "; 618 echo _SKINFILES_ERR_COULD_NOT_RENAME_DIR2 . "</p>"; 619 _skinfiles_rendir($name); 620 return; 621 } 622 623 if (sfIllegalFilename($name)) { 624 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_RENAME_DIR3 . "«" . htmlspecialchars($file) . "» "; 625 echo _SKINFILES_ERR_COULD_NOT_RENAME_DIR4 . "</p>"; 626 _skinfiles_rendir($name); 627 return; 628 } 629 630 if ($name == $file) { 631 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_RENAME_DIR5 . "«" . htmlspecialchars($file) . "» "; 632 echo _SKINFILES_ERR_COULD_NOT_RENAME_DIR6 . _SKINFILES_ERR_COULD_NOT_RENAME_DIR7 . "</p>"; 633 _skinfiles_rendir($name); 634 return; 635 } 636 637 if (file_exists($directory . $name)) { 638 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_RENAME_DIR8 . "«" . htmlspecialchars($file) . "» "; 639 echo _SKINFILES_ERR_COULD_NOT_RENAME_DIR9 . _SKINFILES_ERR_COULD_NOT_RENAME_DIR10 . "</p>"; 640 _skinfiles_rendir($name); 641 return; 642 } 643 644 if (!@rename($directory . $file, $directory . $name)) 645 { 646 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_RENAME_DIR11 . "«" . htmlspecialchars($file) . "»</p>"; 647 _skinfiles_rendir($name); 648 return; 649 } 650 651 echo "<p class='message'>" . _SKINFILES_RENAMED_DIR1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_RENAMED_DIR2; 652 echo _SKINFILES_RENAMED_DIR3 . "«" . htmlspecialchars($name) . "»" . _SKINFILES_RENAMED_DIR4 . "</p>"; 653 sfShowDirectory($directory); 654 } 655 else 656 { 657 echo "<p class='error'>" . _SKINFILES_ERR_DIR_DOES_NOT_EXIST1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DIR_DOES_NOT_EXIST2; 658 echo _SKINFILES_ERR_DIR_DOES_NOT_EXIST3 . "</p>"; 659 } 660 } 661 else 662 { 663 // User cancelled 664 sfShowDirectory($directory); 665 } 666 } 667 668 669 670 671 /* Create directory **************************************************************************************************************/ 672 673 function _skinfiles_createdir() { 674 675 $directory = trim(requestVar('dir')); 676 $directory = sfExpandDirectory($directory); 677 678 if (sfValidPath($directory) && is_dir($directory) && is_writable($directory)) 679 { 680 $name = requestVar('name'); 681 682 if ($name == '') { 683 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_CREATE_DIR1 . "</p>"; 684 sfShowDirectory($directory); 685 return; 686 } 687 688 if (sfIllegalFilename($name)) { 689 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_CREATE_DIR2 . "«" . htmlspecialchars($name) . "» "; 690 echo _SKINFILES_ERR_COULD_NOT_CREATE_DIR3 . "</p>"; 691 sfShowDirectory($directory); 692 return; 693 } 694 695 if (file_exists($directory . $name)) { 696 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_CREATE_DIR4 . "«" . htmlspecialchars($name) . "» "; 697 echo _SKINFILES_ERR_COULD_NOT_CREATE_DIR5 . _SKINFILES_ERR_COULD_NOT_CREATE_DIR6 . "</p>"; 698 sfShowDirectory($directory); 699 return; 700 } 701 702 $mask = @umask(0000); 703 704 if (!@mkdir($directory . $name, 0755)) 705 { 706 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_CREATE_DIR2 . "«" . htmlspecialchars($name) . "»</p>"; 707 sfShowDirectory($directory); 708 return; 709 } 710 711 @umask($mask); 712 713 echo "<p class='message'>" . _SKINFILES_ERR_COULD_NOT_CREATE_DIR7 . "«" . htmlspecialchars($name) . "» " . _SKINFILES_ERR_COULD_NOT_CREATE_DIR8 . "</p>"; 714 sfShowDirectory($directory); 715 } 716 else 717 { 718 echo "<p class='error'>" . _SKINFILES_ERR_COULD_NOT_CREATE_DIR9 . "«" . htmlspecialchars(basename($directory)) . "» " . _SKINFILES_ERR_COULD_NOT_CREATE_DIR10; 719 echo _SKINFILES_ERR_COULD_NOT_CREATE_DIR11 . "</p>"; 720 } 721 } 722 723 724 725 726 /* Delete directory **************************************************************************************************************/ 727 728 function _skinfiles_deldir() { 729 730 global $pluginUrl, $manager; 731 732 $file = trim(basename(requestVar('dir'))); 733 $directory = trim(dirname(requestVar('dir'))); 734 $directory = sfExpandDirectory ($directory); 735 736 if (sfValidPath($directory . $file) && file_exists($directory . $file) && 737 is_dir($directory . $file) && is_writable($directory . $file) && 738 sfDirectoryIsEmpty($directory . $file)) 739 { 740 $relative = sfRelativePath ($directory); 741 $delUrl = $manager->addTicketToUrl($pluginUrl . '?action=deldir&dir=' . rawurlencode($relative . $file)); 742 743 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 744 echo '<a href="' . htmlspecialchars($delUrl) . '" title="' . _SKINFILES_DELETE . ' «' . $file . '»">'; 745 echo '<img src="' . $pluginUrl . 'dir.gif' . '" alt="" /> ' . $file . '</a></p>'; 746 747 echo '<div class="dialogbox">'; 748 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 749 $manager->addTicketHidden(); 750 echo '<input type="hidden" name="action" value="deldir_process" />'; 751 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative . $file) . '" />'; 752 753 echo '<h4>' . _SKINFILES_DELETE_DIR . ' «' . htmlspecialchars($file) . '» ' . _SKINFILES_DELETE_DIR2 . '</h4><div>'; 754 echo '<p class="buttons">'; 755 echo '<input type="hidden" name="sure" value="yes" />'; 756 echo '<input type="submit" value="' . _SKINFILES_DELETE . '" />'; 757 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 758 echo '</p>'; 759 echo '</div></form></div>'; 760 } 761 else 762 { 763 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_DIR1 . " «" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_DIR2; 764 echo _SKINFILES_ERR_DELETE_DIR3 . "</p>"; 765 } 766 } 767 768 function _skinfiles_deldir_process() { 769 770 global $pluginUrl, $manager; 771 772 $file = trim(basename(requestVar('dir'))); 773 $directory = trim(dirname(requestVar('dir'))); 774 $directory = sfExpandDirectory ($directory); 775 776 if (requestVar('sure') == 'yes') 777 { 778 if (sfValidPath($directory . $file) && file_exists($directory . $file) && 779 is_dir($directory . $file) && is_writable($directory . $file) && 780 sfDirectoryIsEmpty($directory . $file)) 781 { 782 if (!@rmdir($directory . $file)) 783 { 784 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_DIR4 . "«" . htmlspecialchars($file) . "»</p>"; 785 sfShowDirectory($directory); 786 return; 787 } 788 789 echo "<p class='message'>" . _SKINFILES_ERR_DELETE_DIR5 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_DIR6 . "</p>"; 790 sfShowDirectory($directory); 791 } 792 else 793 { 794 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_DIR1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_DIR2; 795 echo _SKINFILES_ERR_DELETE_DIR3 . "</p>"; 796 } 797 } 798 else 799 { 800 // User cancelled 801 sfShowDirectory($directory); 802 } 803 } 804 805 806 807 808 /* Empty directory ***************************************************************************************************************/ 809 810 function _skinfiles_emptydir() { 811 812 global $pluginUrl, $manager; 813 814 $file = trim(basename(requestVar('dir'))); 815 $directory = trim(dirname(requestVar('dir'))); 816 $directory = sfExpandDirectory ($directory); 817 818 if (sfValidPath($directory . $file) && file_exists($directory . $file) && is_dir($directory . $file)) 819 { 820 $files = array(); 821 822 if ($dh = @opendir($directory . $file)) 823 { 824 while (($name = readdir($dh)) !== false) { 825 if(!preg_match("/^\.{1,2}$/", $name) && 826 !is_dir($directory . $file . '/' . $name) && 827 is_writable($directory . $file . '/' . $name)) 828 $files[] = $name; 829 } 830 831 closedir($dh); 832 sort($files); 833 } 834 835 $relative = sfRelativePath ($directory); 836 $emptyUrl = $manager->addTicketToUrl($pluginUrl . '?action=emptydir&dir=' . rawurlencode($relative . $file)); 837 838 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 839 echo '<a href="' . htmlspecialchars($emptyUrl) . '" title="Empty «' . $file . '»">'; 840 echo '<img src="' . $pluginUrl . 'dir.gif' . '" alt="" /> ' . $file . '</a></p>'; 841 842 echo '<div class="dialogbox">'; 843 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 844 $manager->addTicketHidden(); 845 echo '<input type="hidden" name="action" value="emptydir_process" />'; 846 echo '<input type="hidden" name="dir" value="' . htmlspecialchars($relative . $file) . '" />'; 847 848 echo '<h4>' . _SKINFILES_DELETE_FILE_MSG . ' «' . htmlspecialchars($file) . '»' . _SKINFILES_DELETE_FILE_MSG2 . '</h4><div>'; 849 850 if (count($files)) 851 { 852 echo '<ul>'; 853 foreach ($files as $name) { echo '<li>' . htmlspecialchars($name) . '</li>'; } 854 echo '</ul>'; 855 856 echo '<p class="buttons">'; 857 echo '<input type="hidden" name="sure" value="yes" />'; 858 echo '<input type="submit" value="' . _SKINFILES_DELETE . '" />'; 859 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 860 echo '</p>'; 861 } 862 else 863 { 864 echo '<p>' . _SKINFILES_ERR_DELETE_DIR7 . '</p>'; 865 echo '<p class="buttons">'; 866 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 867 echo '</p>'; 868 } 869 870 echo '</div></form></div>'; 871 872 } 873 else 874 { 875 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_DIR1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_DIR2; 876 echo _SKINFILES_ERR_DELETE_DIR3 . "</p>"; 877 } 878 } 879 880 function _skinfiles_emptydir_process() { 881 882 global $pluginUrl, $manager; 883 884 $file = trim(basename(requestVar('dir'))); 885 $directory = trim(dirname(requestVar('dir'))); 886 $directory = sfExpandDirectory ($directory); 887 888 if (requestVar('sure') == 'yes') 889 { 890 if (sfValidPath($directory . $file) && file_exists($directory . $file) && is_dir($directory . $file)) 891 { 892 if ($dh = @opendir($directory . $file)) 893 { 894 while (($name = readdir($dh)) !== false) 895 { 896 if(!preg_match("/^\.{1,2}$/", $name) && !is_dir($directory . $file . '/' . $name) && 897 is_writable($directory . $file . '/' . $name)) 898 { 899 if (unlink ($directory .$file . '/' . $name)) 900 echo "<p class='message'>" . _SKINFILES_ERR_EMPTY_DIR1 . "«" . htmlspecialchars($name) . "» " . _SKINFILES_ERR_EMPTY_DIR2 . "</p>"; 901 else 902 echo "<p class='error'>" . _SKINFILES_ERR_EMPTY_DIR3 . "«" . htmlspecialchars($name) . "» " . _SKINFILES_ERR_EMPTY_DIR4 . "</p>"; 903 } 904 } 905 906 closedir($dh); 907 908 sfShowDirectory($directory . $file . '/'); 909 } 910 } 911 else 912 { 913 echo "<p class='error'>" . _SKINFILES_ERR_EMPTY_DIR5 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_EMPTY_DIR6; 914 echo _SKINFILES_ERR_EMPTY_DIR7 . "</p>"; 915 } 916 } 917 else 918 { 919 // User cancelled 920 sfShowDirectory($directory . $file . '/'); 921 } 922 } 923 924 925 926 927 /* Download file *****************************************************************************************************************/ 928 929 function _skinfiles_download() { 930 931 global $pluginUrl, $manager; 932 933 $file = basename(trim(requestVar('file'))); 934 935 $directory = dirname(trim(requestVar('file'))); 936 $directory = sfExpandDirectory ($directory); 937 938 if (sfValidPath($directory) && file_exists($directory . $file) && 939 is_file($directory . $file) && is_readable($directory . $file)) 940 { 941 if (strstr(serverVar('HTTP_USER_AGENT'), "MSIE")) 942 $name = preg_replace('/\./', '%2e', $file, substr_count($file, '.') - 1); 943 else 944 $name = $file; 945 946 if ($fp = @fopen($directory . $file, 'r')) { 947 header("Cache-Control: "); // leave blank to avoid IE errors 948 header("Pragma: "); // leave blank to avoid IE errors 949 header("Content-type: application/octet-stream"); 950 header('Content-Disposition: attachment; filename="'.$name.'"'); 951 header("Content-length: ".(string)(filesize($directory . $file))); 952 sleep(1); 953 954 fpassthru($fp); 955 fclose($fp); 956 } 957 else 958 { 959 echo _SKINFILES_ERR_DOWNLOAD_FILE1; 960 } 961 } 962 else 963 { 964 echo _SKINFILES_ERR_DOWNLOAD_FILE2; 965 } 966 967 exit; 968 } 969 970 971 972 973 /* View file *********************************************************************************************************************/ 974 975 function _skinfiles_viewfile() { 976 977 global $pluginUrl, $manager; 978 979 $file = basename(trim(requestVar('file'))); 980 $directory = dirname(trim(requestVar('file'))); 981 $directory = sfExpandDirectory ($directory); 982 983 if (sfValidPath($directory) && file_exists($directory . $file) && 984 is_file($directory . $file) && is_readable($directory . $file) && sfAllowViewing($file)) 985 { 986 $relative = sfRelativePath ($directory); 987 $viewUrl = $manager->addTicketToUrl($pluginUrl . '?action=viewfile&file=' . rawurlencode(sfRelativePath($directory . $file))); 988 989 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 990 echo '<a href="' . htmlspecialchars($viewUrl) . '" title="View «' . $file . '»">'; 991 echo '<img src="' . htmlspecialchars(sfIcon($file)) . '" alt="" /> ' . $file . '</a></p>'; 992 993 echo '<h4>' . _SKINFILES_VIEW_FILE . '«' . htmlspecialchars($file) . '»</h4>'; 994 995 if (sfIsFileType('html', $file)) 996 { 997 echo '<iframe src="' . sfFullUrl($directory . $file) . '"></iframe>'; 998 } 999 1000 if (sfIsFileType('text', $file)) 1001 { 1002 $content = implode('', file($directory . $file)); 1003 1004 echo '<pre>'; 1005 echo htmlspecialchars($content); 1006 echo '</pre>'; 1007 } 1008 1009 if (sfIsFileType('img', $file)) 1010 { 1011 $size = getimagesize($directory . $file, $info); 1012 1013 switch ($size[2]) { 1014 case IMAGETYPE_GIF: $type = 'GIF document'; break; 1015 case IMAGETYPE_JPEG: $type = 'JPEG photograph'; break; 1016 case IMAGETYPE_PNG: $type = 'PNG document'; break; 1017 case IMAGETYPE_SWF: $type = 'Flash animation'; break; 1018 case IMAGETYPE_PSD: $type = 'Photoshop document'; break; 1019 case IMAGETYPE_BMP: $type = 'BMP document'; break; 1020 case IMAGETYPE_TIFF_II: $type = 'TIFF document (Intel Byte Order)'; break; 1021 case IMAGETYPE_TIFF_MM: $type = 'TIFF document (Motorola Byte Order)'; break; 1022 case IMAGETYPE_JPC: $type = 'JPEG2000 photograph'; break; 1023 case IMAGETYPE_JP2: $type = 'JPEG2000 photograph'; break; 1024 case IMAGETYPE_JPX: $type = 'JPEG2000 photograph'; break; 1025 case IMAGETYPE_JB2: $type = 'Slowview document'; break; 1026 case IMAGETYPE_SWC: $type = 'Flash animation (compressed)'; break; 1027 case IMAGETYPE_IFF: $type = 'IFF document'; break; 1028 case IMAGETYPE_WBMP: $type = 'WBMP document'; break; 1029 case IMAGETYPE_XBM: $type = 'XBM document'; break; 1030 default: $type = 'Unknown document'; break; 1031 } 1032 1033 if ($size[2] == IMAGETYPE_GIF || $size[2] == IMAGETYPE_JPEG || 1034 $size[2] == IMAGETYPE_PNG) 1035 { 1036 echo '<p><img src="' . sfFullUrl($directory . $file) . '" alt="" /></p>'; 1037 } 1038 1039 echo '<table>'; 1040 echo '<tr><th colspan="2">' . _SKINFILES_VIEW_FILE_IMG_INFO . '</th></tr>'; 1041 echo '<tr><td>' . _SKINFILES_VIEW_FILE_TYPE . '</td><td>' . htmlspecialchars($type) . '</td></tr>'; 1042 echo '<tr><td>' . _SKINFILES_VIEW_FILE_WIDTH . '</td><td>' . htmlspecialchars($size[0]) . _SKINFILES_VIEW_FILE_PX . '</td></tr>'; 1043 echo '<tr><td>' . _SKINFILES_VIEW_FILE_HEIGHT . '</td><td>' . htmlspecialchars($size[1]) . _SKINFILES_VIEW_FILE_PX . '</td></tr>'; 1044 1045 if (isset($size['channels']) || isset($size['bits'])) 1046 { 1047 $channels = isset($size['channels']) ? $size['channels'] : 3; 1048 $depth = $size[2] == IMAGETYPE_GIF ? $size['bits'] : $size['bits'] * $channels; 1049 echo '<tr><td>' . _SKINFILES_VIEW_FILE_CHANNELS . '</td><td>' . htmlspecialchars($channels) . '</td></tr>'; 1050 echo '<tr><td>' . _SKINFILES_VIEW_FILE_COLOR_DEPTH . '</td><td>' . htmlspecialchars($depth) . _SKINFILES_VIEW_FILE_BITS . '</td></tr>'; 1051 echo '<tr><td>' . _SKINFILES_VIEW_FILE_COLORS . '</td><td>' . htmlspecialchars(pow(2, $depth)) . _SKINFILES_VIEW_FILE_COLORS2 . '</td></tr>'; 1052 } 1053 1054 1055 if (function_exists('exif_read_data') && ($size[2] == IMAGETYPE_JPEG || 1056 $size[2] == IMAGETYPE_TIFF_II || $size[2] == IMAGETYPE_TIFF_MM)) 1057 { 1058 $exif = exif_read_data($directory . $file, 'EXIF'); 1059 1060 if ($exif) 1061 { 1062 echo '<tr><th colspan="2">Exif information</th></tr>'; 1063 1064 if (isset($exif['Make']) && isset($exif['Model'])) 1065 echo '<tr><td>Camera:</td><td>' . htmlspecialchars($exif['Make'] . ' ' . $exif['Model']) . '</td></tr>'; 1066 1067 if (isset($exif['DateTime'])) 1068 echo '<tr><td>Created on:</td><td>' . htmlspecialchars($exif['DateTime']) . '</td></tr>'; 1069 1070 if (isset($exif['XResolution'])) 1071 echo '<tr><td>Horizontal resolution:</td><td>' . htmlspecialchars(_skinfiles_exif_prepare($exif['XResolution'])) . ' dpi</td></tr>'; 1072 1073 if (isset($exif['YResolution'])) 1074 echo '<tr><td>Vertical resolution:</td><td>' . htmlspecialchars(_skinfiles_exif_prepare($exif['YResolution'])) . ' dpi</td></tr>'; 1075 1076 if (isset($exif['FocalLength'])) 1077 echo '<tr><td>Focal length:</td><td>' . htmlspecialchars(_skinfiles_exif_prepare($exif['FocalLength'])) . ' mm</td></tr>'; 1078 1079 if (isset($exif['FNumber'])) 1080 echo '<tr><td>F-number:</td><td>F/' . htmlspecialchars(_skinfiles_exif_prepare($exif['FNumber'])) . '</td></tr>'; 1081 1082 if (isset($exif['ExposureTime'])) 1083 echo '<tr><td>Exposuretime:</td><td>' . htmlspecialchars(_skinfiles_exif_prepare($exif['ExposureTime'])) . ' sec</td></tr>'; 1084 1085 if (isset($exif['ISOSpeedRatings'])) 1086 echo '<tr><td>ISO-speed:</td><td>' . htmlspecialchars(_skinfiles_exif_prepare($exif['ISOSpeedRatings'])) . '</td></tr>'; 1087 } 1088 } 1089 1090 echo '</table>'; 1091 } 1092 } 1093 else 1094 { 1095 echo "<p class='error'>" . _SKINFILES_ERR_VIEW_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_VIEW_FILE2; 1096 echo _SKINFILES_ERR_VIEW_FILE3 . "</p>"; 1097 } 1098 } 1099 1100 function _skinfiles_exif_prepare($value) { 1101 if (preg_match('#([0-9]+)/([0-9]+)#', $value, $matches)) 1102 if ($matches[1] < $matches[2]) 1103 return '1/' . round($matches[2] / $matches[1]); 1104 else 1105 return round($matches[1] / $matches[2]); 1106 else 1107 return $value; 1108 } 1109 1110 1111 1112 1113 /* Edit file *********************************************************************************************************************/ 1114 1115 function _skinfiles_editfile() { 1116 1117 global $pluginUrl, $manager; 1118 1119 $file = basename(trim(requestVar('file'))); 1120 $directory = dirname(trim(requestVar('file'))); 1121 $directory = sfExpandDirectory ($directory); 1122 1123 if (sfValidPath($directory) && file_exists($directory . $file) && 1124 is_file($directory . $file) && is_writable($directory . $file) && sfAllowEditing($file)) 1125 { 1126 $relative = sfRelativePath ($directory); 1127 $editUrl = $manager->addTicketToUrl($pluginUrl . '?action=editfile&file=' . rawurlencode(sfRelativePath($directory . $file))); 1128 1129 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 1130 echo '<a href="' . htmlspecialchars($editUrl) . '" title="Edit «' . $file . '»">'; 1131 echo '<img src="' . htmlspecialchars(sfIcon($file)) . '" alt="" /> ' . $file . '</a></p>'; 1132 1133 $content = implode('', file($directory . $file)); 1134 1135 echo '<div class="dialogbox">'; 1136 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 1137 $manager->addTicketHidden(); 1138 echo '<input type="hidden" name="action" value="editfile_process" />'; 1139 echo '<input type="hidden" name="file" value="' . htmlspecialchars(sfRelativePath($directory . $file)) . '" />'; 1140 1141 echo '<h4>' . _SKINFILES_EDIT_FILE_MSG . ' «' . htmlspecialchars($file) . '»</h4><div>'; 1142 echo '<p><textarea class="skinedit" tabindex="8" rows="20" cols="80" name="content">'; 1143 echo htmlspecialchars($content); 1144 echo '</textarea></p>'; 1145 1146 echo '<p class="buttons">'; 1147 echo '<input type="hidden" name="sure" value="yes" /">'; 1148 echo '<input type="submit" value="' . _SKINFILES_SAVE_CHANGES . '" />'; 1149 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 1150 echo '</p>'; 1151 echo '</div></form></div>'; 1152 } 1153 else 1154 { 1155 echo "<p class='error'>" . _SKINFILES_ERR_EDIT_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_EDIT_FILE2; 1156 echo _SKINFILES_ERR_EDIT_FILE3 . "</p>"; 1157 } 1158 } 1159 1160 function _skinfiles_editfile_process() { 1161 1162 $file = basename(trim(requestVar('file'))); 1163 $directory = dirname(trim(requestVar('file'))); 1164 $directory = sfExpandDirectory ($directory); 1165 1166 if (requestVar('sure') == 'yes') 1167 { 1168 if (sfValidPath($directory) && file_exists($directory . $file) && 1169 is_file($directory . $file) && is_writable($directory . $file) && sfAllowEditing($file)) 1170 { 1171 $content = postVar('content'); 1172 $success = false; 1173 1174 if ($fh = @fopen($directory . $file, 'wb')) { 1175 1176 if (@fwrite($fh, $content) !== false) 1177 $success = true; 1178 1179 @fclose($fh); 1180 } 1181 1182 if ($success) 1183 echo "<p class='message'>" . _SKINFILES_ERR_EDIT_FILE4 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_EDIT_FILE5 . "</p>"; 1184 else 1185 echo "<p class='error'>" . _SKINFILES_ERR_EDIT_FILE6 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_EDIT_FILE7 . "</p>"; 1186 1187 _skinfiles_editfile(); 1188 } 1189 else 1190 { 1191 echo "<p class='error'>" . _SKINFILES_ERR_EDIT_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_EDIT_FILE2; 1192 echo _SKINFILES_ERR_EDIT_FILE3 . "</p>"; 1193 } 1194 } 1195 else 1196 { 1197 // User cancelled 1198 sfShowDirectory($directory); 1199 } 1200 } 1201 1202 1203 1204 /* Rename file *******************************************************************************************************************/ 1205 1206 function _skinfiles_renfile($preset = '') { 1207 1208 global $pluginUrl, $manager; 1209 1210 $file = basename(trim(requestVar('file'))); 1211 $directory = dirname(trim(requestVar('file'))); 1212 $directory = sfExpandDirectory ($directory); 1213 1214 if (sfValidPath($directory) && file_exists($directory . $file) && 1215 is_file($directory . $file) && is_writable($directory . $file)) 1216 { 1217 $relative = sfRelativePath ($directory); 1218 $editUrl = $manager->addTicketToUrl($pluginUrl . '?action=renfile&file=' . rawurlencode(sfRelativePath($directory . $file))); 1219 1220 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 1221 echo '<a href="' . htmlspecialchars($editUrl) . '" title="' . _SKINFILES_RENAME . ' «' . $file . '»">'; 1222 echo '<img src="' . htmlspecialchars(sfIcon($file)) . '" alt="" /> ' . $file . '</a></p>'; 1223 1224 echo '<div class="dialogbox">'; 1225 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 1226 $manager->addTicketHidden(); 1227 echo '<input type="hidden" name="action" value="renfile_process" />'; 1228 echo '<input type="hidden" name="file" value="' . htmlspecialchars(sfRelativePath($directory . $file)) . '" />'; 1229 1230 echo '<h4>' . _SKINFILES_RENAME_FILE_MSG . '«' . htmlspecialchars($file) . '» ' . _SKINFILES_RENAME_FILE_MSG2 . '</h4><div>'; 1231 echo '<p><input type="text" name="name" size="40" value="' . htmlspecialchars($preset != '' ? $preset : $file) . '" /></p>'; 1232 echo '<p class="buttons">'; 1233 echo '<input type="hidden" name="sure" value="yes" /">'; 1234 echo '<input type="submit" value="' . _SKINFILES_RENAME . '" />'; 1235 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 1236 echo '</p>'; 1237 echo '</div></form></div>'; 1238 } 1239 else 1240 { 1241 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_RENAME_FILE2; 1242 echo _SKINFILES_ERR_RENAME_FILE3 . "</p>"; 1243 } 1244 } 1245 1246 function _skinfiles_renfile_process() { 1247 1248 global $pluginUrl, $manager; 1249 1250 $file = basename(trim(requestVar('file'))); 1251 $directory = dirname(trim(requestVar('file'))); 1252 $directory = sfExpandDirectory ($directory); 1253 1254 if (requestVar('sure') == 'yes') 1255 { 1256 if (sfValidPath($directory) && file_exists($directory . $file) && 1257 is_file($directory . $file) && is_writable($directory . $file)) 1258 { 1259 $name = requestVar('name'); 1260 1261 if ($name == '') { 1262 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE4 . "«" . htmlspecialchars($file) . "» "; 1263 echo _SKINFILES_ERR_RENAME_FILE5 . "</p>"; 1264 _skinfiles_renfile($name); 1265 return; 1266 } 1267 1268 if (sfIllegalFilename($name)) { 1269 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE6 . "«" . htmlspecialchars($file) . "» "; 1270 echo _SKINFILES_ERR_RENAME_FILE7 . "</p>"; 1271 _skinfiles_renfile($name); 1272 return; 1273 } 1274 1275 if ($name == $file) { 1276 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE8 . "«" . htmlspecialchars($file) . "» "; 1277 echo _SKINFILES_ERR_RENAME_FILE9 . "</p>"; 1278 _skinfiles_renfile($name); 1279 return; 1280 } 1281 1282 if (file_exists($directory . $name)) { 1283 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE10 . "«" . htmlspecialchars($file) . "» "; 1284 echo _SKINFILES_ERR_RENAME_FILE11; 1285 echo _SKINFILES_ERR_RENAME_FILE12 . "</p>"; 1286 _skinfiles_renfile($name); 1287 return; 1288 } 1289 1290 if (!@rename($directory . $file, $directory . $name)) 1291 { 1292 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE13 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_RENAME_FILE14 . "</p>"; 1293 _skinfiles_renfile($name); 1294 return; 1295 } 1296 1297 echo "<p class='message'>" . _SKINFILES_ERR_RENAME_FILE15 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_RENAME_FILE16; 1298 echo _SKINFILES_ERR_RENAME_FILE17 . "«" . htmlspecialchars($name) . "»" . _SKINFILES_ERR_RENAME_FILE18 . "</p>"; 1299 sfShowDirectory($directory); 1300 } 1301 else 1302 { 1303 echo "<p class='error'>" . _SKINFILES_ERR_RENAME_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_RENAME_FILE2; 1304 echo _SKINFILES_ERR_RENAME_FILE3 . "</p>"; 1305 } 1306 } 1307 else 1308 { 1309 // User cancelled 1310 sfShowDirectory($directory); 1311 } 1312 } 1313 1314 1315 1316 1317 /* Create file *******************************************************************************************************************/ 1318 1319 function _skinfiles_createfile() { 1320 1321 $directory = trim(requestVar('dir')); 1322 $directory = sfExpandDirectory($directory); 1323 1324 if (sfValidPath($directory) && is_dir($directory) && is_writable($directory)) 1325 { 1326 $name = requestVar('name'); 1327 1328 if ($name == '') { 1329 echo "<p class='error'>" . _SKINFILES_ERR_CREATE_FILE1 . "</p>"; 1330 sfShowDirectory($directory); 1331 return; 1332 } 1333 1334 if (sfIllegalFilename($name)) { 1335 echo "<p class='error'>" . _SKINFILES_ERR_CREATE_FILE2 . "«" . htmlspecialchars($name) . "» "; 1336 echo _SKINFILES_ERR_CREATE_FILE3 . "</p>"; 1337 sfShowDirectory($directory); 1338 return; 1339 } 1340 1341 if (file_exists($directory . $name)) { 1342 echo "<p class='error'>" . _SKINFILES_ERR_CREATE_FILE4 . "«" . htmlspecialchars($name) . "» "; 1343 echo _SKINFILES_ERR_CREATE_FILE5; 1344 echo _SKINFILES_ERR_CREATE_FILE6 . "</p>"; 1345 sfShowDirectory($directory); 1346 return; 1347 } 1348 1349 if (!@touch($directory . $name)) 1350 { 1351 echo "<p class='error'>" . _SKINFILES_ERR_CREATE_FILE7 . "«" . htmlspecialchars($name) . "» " . _SKINFILES_ERR_CREATE_FILE8 . "</p>"; 1352 sfShowDirectory($directory); 1353 return; 1354 } 1355 1356 $mask = @umask(0000); 1357 @chmod($directory . $name, 0755); 1358 @umask($mask); 1359 1360 echo "<p class='message'>" . _SKINFILES_ERR_CREATE_FILE9 . "«" . htmlspecialchars($name) . "» " . _SKINFILES_ERR_CREATE_FILE10 . "</p>"; 1361 sfShowDirectory($directory); 1362 } 1363 else 1364 { 1365 echo "<p class='error'>" . _SKINFILES_ERR_CREATE_FILE11 . "«" . htmlspecialchars(basename($directory)) . "» " . _SKINFILES_ERR_CREATE_FILE12; 1366 echo _SKINFILES_ERR_CREATE_FILE13 . "</p>"; 1367 } 1368 } 1369 1370 1371 1372 1373 /* Delete file *******************************************************************************************************************/ 1374 1375 function _skinfiles_delfile() { 1376 1377 global $pluginUrl, $manager; 1378 1379 $file = basename(trim(requestVar('file'))); 1380 $directory = dirname(trim(requestVar('file'))); 1381 $directory = sfExpandDirectory ($directory); 1382 1383 if (sfValidPath($directory) && file_exists($directory . $file) && 1384 is_file($directory . $file) && is_writable($directory . $file)) 1385 { 1386 $relative = sfRelativePath ($directory); 1387 $delUrl = $manager->addTicketToUrl($pluginUrl . '?action=delfile&file=' . rawurlencode(sfRelativePath($directory . $file))); 1388 1389 echo '<p class="location">' . _SKINFILES_CURRENT_LOCATION . sfDisplayPath($relative); 1390 echo '<a href="' . htmlspecialchars($delUrl) . '" title="' . _SKINFILES_DELETE . ' «' . $file . '»">'; 1391 echo '<img src="' . htmlspecialchars(sfIcon($file)) . '" alt="" /> ' . $file . '</a></p>'; 1392 1393 echo '<div class="dialogbox">'; 1394 echo '<form method="post" action="' . htmlspecialchars($pluginUrl) . '">'; 1395 $manager->addTicketHidden(); 1396 echo '<input type="hidden" name="action" value="delfile_process" />'; 1397 echo '<input type="hidden" name="file" value="' . htmlspecialchars(sfRelativePath($directory . $file)) . '" />'; 1398 1399 echo '<h4>' . _SKINFILES_DELETE_FILE . ' «' . htmlspecialchars($file) . '» ' . _SKINFILES_DELETE_FILE2 . '</h4><div>'; 1400 echo '<p class="buttons">'; 1401 echo '<input type="hidden" name="sure" value="yes" />'; 1402 echo '<input type="submit" value="' . _SKINFILES_DELETE . '" />'; 1403 echo '<input type="button" name="sure" value="' . _SKINFILES_CANCEL . '" onclick="history.back();" />'; 1404 echo '</p>'; 1405 echo '</div></form></div>'; 1406 } 1407 else 1408 { 1409 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_FILE2; 1410 echo _SKINFILES_ERR_DELETE_FILE3 . "</p>"; 1411 } 1412 } 1413 1414 function _skinfiles_delfile_process() { 1415 1416 global $pluginUrl, $manager; 1417 1418 $file = basename(trim(requestVar('file'))); 1419 $directory = dirname(trim(requestVar('file'))); 1420 $directory = sfExpandDirectory ($directory); 1421 1422 if (requestVar('sure') == 'yes') 1423 { 1424 if (sfValidPath($directory) && file_exists($directory . $file) && 1425 is_file($directory . $file) && is_writable($directory . $file)) 1426 { 1427 if (!@unlink($directory . $file)) 1428 { 1429 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_FILE4 . "«" . htmlspecialchars($file) . "»</p>"; 1430 sfShowDirectory($directory); 1431 return; 1432 } 1433 1434 echo "<p class='message'>" . _SKINFILES_ERR_DELETE_FILE5 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_FILE6 . "</p>"; 1435 sfShowDirectory($directory); 1436 } 1437 else 1438 { 1439 echo "<p class='error'>" . _SKINFILES_ERR_DELETE_FILE1 . "«" . htmlspecialchars($file) . "» " . _SKINFILES_ERR_DELETE_FILE2; 1440 echo _SKINFILES_ERR_DELETE_FILE3 . "</p>"; 1441 } 1442 } 1443 else 1444 { 1445 // User cancelled 1446 sfShowDirectory($directory); 1447 } 1448 } 1449 1450 1451 1452 /* Upload file *******************************************************************************************************************/ 1453 1454 function _skinfiles_uploadfile() { 1455 1456 global $pluginUrl, $manager, $CONF; 1457 1458 $directory = trim(requestVar('dir')); 1459 $directory = sfExpandDirectory($directory); 1460 1461 if (sfValidPath($directory) && is_dir($directory) && is_writable($directory)) 1462 { 1463 $file = postFileInfo('name'); 1464 1465 if ($file['size'] > $CONF['MaxUploadSize']) { 1466 echo "<p class='error'>" . _SKINFILES_ERR_UPLOAD_FILE1 . "«" . htmlspecialchars($file['name']) . "» " . _SKINFILES_ERR_UPLOAD_FILE2 . _ERROR_FILE_TOO_BIG . "<br />"; 1467 echo _SKINFILES_ERR_UPLOAD_FILE3 . $CONF['MaxUploadSize'] . " / "; 1468 echo $file['size'] . " bytes</p>"; 1469 sfShowDirectory($directory); 1470 return; 1471 } 1472 1473 if (!is_uploaded_file($file['tmp_name'])) { 1474 echo "<p class='error'>" . _SKINFILES_ERR_UPLOAD_FILE1 . "«" . htmlspecialchars($file['name']) . "» " . _SKINFILES_ERR_UPLOAD_FILE2 . _ERROR_BADREQUEST . _SKINFILES_ERR_UPLOAD_FILE4 . "</p>"; 1475 sfShowDirectory($directory); 1476 return; 1477 } 1478 1479 if (sfIllegalFilename($file['name'])) { 1480 echo "<p class='error'>" . _SKINFILES_ERR_UPLOAD_FILE5 . "«" . htmlspecialchars($file['name']) . "» "; 1481 echo _SKINFILES_ERR_UPLOAD_FILE6 . "</p>"; 1482 sfShowDirectory($directory); 1483 return; 1484 } 1485 1486 if (file_exists($directory . $file['name'])) { 1487 echo "<p class='error'>" . _SKINFILES_ERR_UPLOAD_FILE1 . "«" . htmlspecialchars($file['name']) . "» " . _SKINFILES_ERR_UPLOAD_FILE2 . _ERROR_UPLOADDUPLICATE . "</p>"; 1488 sfShowDirectory($directory); 1489 return; 1490 } 1491 1492 if (!@move_uploaded_file($file['tmp_name'], $directory . $file['name'])) { 1493 echo "<p class='error'>" . _SKINFILES_ERR_UPLOAD_FILE1 . "«" . htmlspecialchars($file['name']) . "» " . _SKINFILES_ERR_UPLOAD_FILE2 . _ERROR_UPLOADMOVEP . _SKINFILES_ERR_UPLOAD_FILE4 . "</p>"; 1494 sfShowDirectory($directory); 1495 } 1496 1497 $mask = @umask(0000); 1498 @chmod($directory . $file['name'], 0755); 1499 @umask($mask); 1500 1501 echo "<p class='message'>" . _SKINFILES_ERR_UPLOAD_FILE7 . "«" . htmlspecialchars($file['name']) . "» " . _SKINFILES_ERR_UPLOAD_FILE8 . "</p>"; 1502 sfShowDirectory($directory); 1503 } 1504 else 1505 { 1506 echo "<p class='error'>" . _SKINFILES_ERR_UPLOAD_FILE9 . "«" . htmlspecialchars(basename($directory)) . "» " . _SKINFILES_ERR_UPLOAD_FILE10; 1507 echo _SKINFILES_ERR_UPLOAD_FILE11 . "</p>"; 1508 } 1509 } 1510 1511 1512 1513 1514 1515 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Aug 1 03:56:06 2010 |