Пример #1
0
/**
 * Write a string to a file
 *
 * @param string $location file location
 * @param string $content
 * @param string $base_dir
 * @return string $result
 */
function fn_put_contents($location, $content, $base_dir = '')
{
    $result = '';
    $path = $base_dir . $location;
    if (!empty($base_dir) && !fn_check_path($path)) {
        return false;
    }
    // Location is regular file
    $result = @file_put_contents($path, $content);
    if ($result !== false) {
        @chmod($path, DEFAULT_FILE_PERMISSIONS);
    }
    return $result;
}
Пример #2
0
/**
 * Write a string to a file
 *
 * @param string $location file location
 * @param string $content
 * @param string $base_dir
 * @param int $file_perm File access permissions for setting after writing into the file. For example 0666.
 * @param boolean $append append content if set to true
 * @return string $result
 */
function fn_put_contents($location, $content, $base_dir = '', $file_perm = DEFAULT_FILE_PERMISSIONS, $append = false)
{
    $result = '';
    $path = $base_dir . $location;
    if (!empty($base_dir) && !fn_check_path($path)) {
        return false;
    }
    fn_mkdir(dirname($path));
    $flags = 0;
    if ($append == true) {
        $flags = FILE_APPEND;
    }
    // Location is regular file
    $result = @file_put_contents($path, $content, $flags);
    if ($result !== false) {
        @chmod($path, $file_perm);
    }
    return $result;
}
Пример #3
0
 }
 if ($mode == 'save_template') {
     fn_trusted_vars('content');
     $ext = fn_strtolower(fn_get_file_ext($_REQUEST['file']));
     if ($ext == 'tpl') {
         $theme_path = fn_get_theme_path('[themes]/[theme]/templates/', 'C');
         if (fn_put_contents($_REQUEST['file'], $_REQUEST['content'], $theme_path)) {
             fn_set_notification('N', __('notice'), __('text_file_saved', array('[file]' => fn_basename($_REQUEST['file']))));
         }
     }
     return array(CONTROLLER_STATUS_REDIRECT, $_REQUEST['current_url']);
 }
 if ($mode == 'restore_template') {
     $copied = false;
     $full_path = fn_get_theme_path('[themes]/[theme]', 'C') . '/templates/' . $_REQUEST['file'];
     if (fn_check_path($full_path)) {
         $c_name = fn_normalize_path($full_path);
         $r_name = fn_normalize_path(Registry::get('config.dir.themes_repository') . Registry::get('config.base_theme') . '/templates/' . $_REQUEST['file']);
         if (is_file($r_name)) {
             $copied = fn_copy($r_name, $c_name);
         }
         if ($copied) {
             fn_set_notification('N', __('notice'), __('text_file_restored', array('[file]' => fn_basename($_REQUEST['file']))));
         } else {
             fn_set_notification('E', __('error'), __('text_cannot_restore_file', array('[file]' => fn_basename($_REQUEST['file']))));
         }
         if ($copied) {
             if (defined('AJAX_REQUEST')) {
                 Registry::get('ajax')->assign('force_redirection', fn_url($_REQUEST['current_url']));
                 Registry::get('ajax')->assign('non_ajax_notifications', true);
             }