[ Index ]

PHP Cross Reference of Nucleus CMS 3.64

title

Body

[close]

/nucleus3.64/nucleus/plugins/skinfiles/ -> index.php (source)

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


Generated: Mon May 2 16:14:08 2011 Cross-referenced by PHPXref 0.7.1