$cur_dir = '';
}
// %End validate $dirpath
try {
    $page = 1;
    $limit = $sjConfig['max_files_per_page'];
    $offset = 0;
    if (!empty($_REQUEST['page']) && is_numeric($_REQUEST['page']) && $_REQUEST['page'] > 1) {
        $page = (int) $_REQUEST['page'];
        $offset = ($page - 1) * $limit + 1;
    }
    $fs = new iFilesystem();
    $result = $fs->setI18n($_SYSTEM['i18n'])->readDir($realpath, '!r', array('sort' => true, 'offset' => $offset, 'limit' => $limit));
    $data = array();
    foreach ($result as $file) {
        $info = $fs->getPathInfo($file);
        $is_dir = is_dir($file);
        if ($info['basename'][0] == '.') {
            $filename = $info['basename'];
            $extension = '';
        } else {
            $filename = $is_dir ? $info['basename'] : $info['filename'];
            $extension = !$is_dir && isset($info['extension']) ? $info['extension'] : '';
        }
        $data[] = array('basename' => $info['basename'], 'name' => $filename, 'size' => $is_dir ? '' : $fs->formatSize($file) . 'b', 'modified_at' => $fs->formatDate(filemtime($file)), 'type' => $extension, 'is_dir' => $is_dir, 'mode' => $fs->getMode($file));
    }
    $_RESULT['files'] = array('cur_dir' => $cur_dir ? $cur_dir : '', 'source' => $data);
} catch (sjException $e) {
    if ($_SYSTEM['is_ajax']) {
        $_RESULT['response']['status'] = 'error';
        $_RESULT['response']['msg'] = $e->getMessage();
 * file that was distributed with this source code.
 */
if (!defined('SJ_IS_ADMIN')) {
    header('Location: http://www.google.com');
    exit;
}
$files = isset($_REQUEST['files']) ? $_REQUEST['files'] : array();
if (!is_array($files)) {
    $files = array($files);
}
$rootPath = rtrim($_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR);
$fs = new iFilesystem();
$fs->setI18n($_SYSTEM['i18n']);
// %Begin Validate $dirpath
foreach ($files as $filePath => $newName) {
    $pathinfo = $fs->getPathInfo($filePath);
    $dirpath = ltrim($pathinfo['dirname'], '/');
    $dirpath = $dirpath ? str_replace('\\', DIRECTORY_SEPARATOR, $dirpath) : '';
    $realpath = realpath($rootPath . DIRECTORY_SEPARATOR . $dirpath);
    $rootLength = strlen($sjConfig['root']);
    $realLength = strlen($realpath);
    if (!$realpath || $realLength < $rootLength) {
        // hack attemt
        $realpath = $sjConfig['root'];
        unset($files[$i]);
    }
}
// %End validate $dirpath
require $sjConfig['lib_dir'] . '/model/image.class.php';
$_RESULT['media'] = array();
$width = $_REQUEST['width'];
     if (preg_match('/[\\/:*?<>|\'"]+/', $dirname)) {
         throw new sjException($_SYSTEM['i18n']->__('File name can not contains following symmbols: \\/:*?<>|"\''));
     }
     if (is_dir($path . $dirname)) {
         throw new sjException($_SYSTEM['i18n']->__('Unable to create folder. Folder with this name already exists'));
     }
     if (!$fs->mkdirs($path . $dirname)) {
         throw new sjException($_SYSTEM['i18n']->__('Unable to create folder. Permissions denied'));
     }
     break;
 case 'rename':
     if (!$has_files || !isset($_REQUEST['fileNames']) || empty($_REQUEST['fileNames'])) {
         throw new sjException($_SYSTEM['i18n']->__('Unable to process request'));
     }
     $newFileName = $fs->prepareFilename(reset($_REQUEST['fileNames']));
     $newFileExt = $fs->getPathInfo($newFileName, PATHINFO_EXTENSION);
     if ($newFileExt && !empty($sjConfig['uploader']['allowed_types']) && !in_array($newFileExt, $sjConfig['uploader']['allowed_types'])) {
         throw new sjException($_SYSTEM['i18n']->__('Files with extension "%s" does not allowed', $newFileExt));
     }
     $oldFile = reset($files);
     $dirname = dirname($oldFile);
     $fs->rename($oldFile, $dirname . DIRECTORY_SEPARATOR . $newFileName);
     break;
 case 'upload':
     if (empty($_FILES)) {
         throw new sjException($_SYSTEM['i18n']->__('Unable to process request'));
     }
     $cfgName = empty($_REQUEST['use_cfg']) ? null : $_REQUEST['use_cfg'];
     $cfg = $sjConfig['uploader'];
     if (isset($cfg['named'][$cfgName])) {
         $cfg['images'] = $cfg['named'][$cfgName]['images'];
$count = count($dir);
logSection($count, '(recursive) number of items in fixtures dir = ' . $count);
$dir = $fs->readDir($fixtures, 'r', array('flags' => 0));
$count = count($dir);
logSection($count, '(recursive) number of files in fixtures dir = ' . $count);
$dir = $fs->readDir($fixtures, 'r', array('skip' => '/jpe?g$/i'));
$count = count($dir);
logSection($count, '(skip jpeg) number of items in fixtures dir = ' . $count);
$result = $fs->stat($file);
logSection(is_array($result), 'stat for file "' . basename($file) . '"');
$result = $fs->dynamicFileName($file);
logSection(basename($file), sprintf('dynamic file name "%s"', basename($result)));
$file = $fixtures . '/test_file_(3)';
$fs->touch($file);
$result = $fs->dynamicFileName($file);
logSection(basename($file), sprintf('dynamic file name "%s"', basename($result)));
$files[] = $file;
$fs->mirror($fixtures, $fixtures . '/mirror', array('image' => array('width' => 300, 'height' => 300, 'type' => 'width', 'crop' => 'left-top')));
logSection(is_dir($fixtures . '/mirror'), 'mirror fixtures directory');
echo "remove created dir? (yes/no)\n";
$result = fgets(STDIN);
$result = trim($result);
if (is_dir($fixtures . '/mirror') && $result == 'yes') {
    $fs->remove($fs->readDir($fixtures . '/mirror', 'r', array('sort' => true)));
}
$pathinfo = '/бла/путь/к/файлу.бах';
logSection(true, 'Check path info for utf8 characters');
foreach ($fs->getPathInfo($pathinfo) as $k => $part) {
    logSection($k, $part);
}
removeCreated($files);