Exemple #1
0
        if (is_file($pname) && !in_array(fn_strtolower(fn_get_file_ext($pname)), Registry::get('config.forbidden_file_extensions'))) {
            fn_get_file($pname);
        }
    }
    exit;
} elseif ($mode == 'edit') {
    $fname = fn_te_normalize_path($_REQUEST, $root_dir);
    if (fn_te_check_path($fname) && !in_array(fn_strtolower(fn_get_file_ext($fname)), Registry::get('config.forbidden_file_extensions'))) {
        Tygh::$app['ajax']->assign('content', fn_get_contents($fname));
    } else {
        fn_set_notification('E', __('error'), __('you_have_no_permissions'));
    }
    exit;
} elseif ($mode == 'restore') {
    $copied = false;
    $file_path = fn_te_normalize_path($_REQUEST, $root_dir);
    if (fn_te_check_path($file_path)) {
        $repo_path = str_replace($root_dir, fn_te_get_root('repo'), $file_path);
        if (!file_exists($repo_path) && fn_get_theme_path('[theme]') != Registry::get('config.base_theme') && is_dir(fn_get_theme_path('[repo]/[theme]'))) {
            $repo_path = preg_replace("/\\/themes_repository\\/(\\w+)\\//", "/themes_repository/" . Registry::get('config.base_theme') . "/", $repo_path);
        }
        $object_base = is_file($repo_path) ? 'file' : (is_dir($repo_path) ? 'directory' : '');
        if (!empty($object_base) && fn_copy($repo_path, $file_path)) {
            fn_set_notification('N', __('notice'), __("text_{$object_base}_restored", array("[{$object_base}]" => fn_basename($file_path))));
            Tygh::$app['ajax']->assign('content', fn_get_contents($file_path));
            $copied = true;
        }
    }
    if (!$copied) {
        $object_base = empty($object_base) ? 'file' : $object_base;
        fn_set_notification('E', __('error'), __("text_cannot_restore_{$object_base}", array("[{$object_base}]" => fn_basename($file_path))));
            $copied = true;
        }
    }
    if (!$copied) {
        $object_base = empty($object_base) ? 'file' : $object_base;
        fn_set_notification('E', __('error'), __("text_cannot_restore_{$object_base}", array("[{$object_base}]" => fn_basename($file_path))));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'file_editor.init_view?dir=' . $_REQUEST['file_path'] . '/' . $_REQUEST['file']);
} elseif ($mode == 'decompress') {
    $pname = fn_te_normalize_path($_REQUEST, $section_root_dir);
    if (fn_te_check_path($pname, $_SESSION['active_section'])) {
        fn_decompress_files($pname, dirname($pname));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'file_editor.init_view?dir=' . $_REQUEST['file_path']);
} elseif ($mode == 'compress') {
    $pname = fn_te_normalize_path($_REQUEST, $section_root_dir);
    if (fn_te_check_path($pname, $_SESSION['active_section']) && file_exists($pname)) {
        $archive_file = $pname . '.zip';
        if (file_exists($archive_file)) {
            fn_rm($archive_file);
        }
        fn_compress_files(fn_basename($archive_file), array(fn_basename($pname)), dirname($pname));
    }
    return array(CONTROLLER_STATUS_REDIRECT, 'file_editor.init_view?dir=' . $_REQUEST['file_path']);
}
/**
 * Gets file/directory permissions in human-readable notation
 * @param string $path path to file/directory
 * @return string readable permissions
 */
function fn_te_get_permissions($path)