示例#1
0
/**
 * write out a file to disk
 *
 * @param string $filename
 * @param string $contents
 * @param boolean $create_dirs
 * @return boolean
 */
function smarty_core_write_file($params, &$smarty)
{
    $_dirname = dirname($params['filename']);
    if ($params['create_dirs']) {
        $_params = array('dir' => $_dirname);
        require_once SMARTY_CORE_DIR . 'core.create_dir_structure.php';
        smarty_core_create_dir_structure($_params, $smarty);
    }
    // write to tmp file, then rename it to avoid file locking race condition
    $_tmp_file = tempnam($_dirname, 'wrt');
    if (!($fd = @fopen($_tmp_file, 'wb'))) {
        $_tmp_file = $_dirname . DIRECTORY_SEPARATOR . uniqid('wrt');
        if (!($fd = @fopen($_tmp_file, 'wb'))) {
            $smarty->trigger_error("problem writing temporary file '{$_tmp_file}'");
            return false;
        }
    }
    fwrite($fd, replace_remark($params['contents']));
    fclose($fd);
    if (DIRECTORY_SEPARATOR == '\\' || !@file_rename($_tmp_file, $params['filename'])) {
        // On platforms and filesystems that cannot overwrite with rename()
        // delete the file before renaming it -- because windows always suffers
        // this, it is short-circuited to avoid the initial rename() attempt
        @unlink($params['filename']);
        @file_rename($_tmp_file, $params['filename']);
    }
    @chmod($params['filename'], $smarty->_file_perms);
    return true;
}
示例#2
0
 public function test_file()
 {
     $file1 = self::getDir() . '/dir1/foo.txt';
     $file2 = self::getDir() . '/dir2/bar.txt';
     $file3 = self::getDir() . '/dir2/baz.txt';
     $file3_name = 'baz.txt';
     $file4 = self::getDir() . '/dir4/yolo.txt';
     $this->assertFalse(file_exists($file1));
     file_create($file1);
     file_write($file1, '');
     $this->assertTrue(file_exists($file1));
     $this->assertEquals('', file_read($file1));
     file_write($file1, 'foo');
     $this->assertEquals('foo', file_read($file1));
     file_append($file1, '_bar');
     $this->assertEquals('foo_bar', file_read($file1));
     file_prepend($file1, '#');
     $this->assertEquals('#foo_bar', file_read($file1));
     file_append($file1, '_bar');
     file_prepend($file1, '#');
     $this->assertEquals('##foo_bar_bar', file_read($file1));
     file_append($file1 . '_append', '_bar');
     $this->assertEquals(file_read($file1 . '_append'), '_bar');
     file_prepend($file1 . '_prepend', '#');
     $this->assertEquals(file_read($file1 . '_prepend'), '#');
     $this->assertFalse(file_exists($file2));
     file_copy($file1, $file2);
     $this->assertTrue(file_exists($file2));
     $this->assertEquals(file_read($file1), file_read($file2));
     $this->assertFalse(file_exists($file3));
     file_rename($file2, $file3_name);
     $this->assertFalse(file_exists($file2));
     $this->assertTrue(file_exists($file3));
     $this->assertEquals(file_read($file1), file_read($file3));
     $this->assertFalse(file_exists($file4));
     file_move($file3, $file4);
     $this->assertFalse(file_exists($file3));
     $this->assertTrue(file_exists($file4));
     $this->assertEquals(file_read($file1), file_read($file4));
     file_delete($file4);
     file_delete($file4);
     $this->assertFalse(file_exists($file4));
     $this->assertEquals(self::getDir() . '/dir1', file_get_directory($file1));
     $this->assertEquals('txt', file_get_extension($file1));
     $this->assertEquals('foo.txt', file_get_name($file1));
 }
示例#3
0
     }
     break;
 case 'file_put':
     if (is_file($user['home'] . $_POST['file'])) {
         file_put_contents($user['home'] . $_POST['file'], $_POST['data']);
     }
     break;
 case 'delete':
     foreach ($_POST['files'] as $f) {
         if (is_file($user['home'] . $f)) {
             unlink($user['home'] . $f);
         }
     }
     break;
 case 'rename':
     file_rename($_POST['path'], $_POST['newname'], $user['home']);
     break;
 case 'server_start':
     echo server_start($user['user']);
     break;
 case 'server_cmd':
     server_cmd($user['user'], $_POST['cmd']);
     break;
 case 'server_stop':
     server_stop($user['user']);
     break;
 case 'server_kill':
     server_kill($user['user']);
     break;
 case 'server_running':
     echo json_encode(server_running($user['user']));
示例#4
0
 function saveSource($aParams)
 {
     $dir = THEME_DIR . '/' . $aParams['tmpid'] . '/images/';
     $aFile = $this->getFile($aParams['name'], $aParams['tmpid']);
     if (count($aFile['files']) == 0 || $aParams['isbak']) {
         $aTmp = explode('.', $aFile['name']);
         $arrNum = count($aTmp) - 1;
         $lastStr = $aTmp[$arrNum];
         if (substr($aTmp[$arrNum - 1], 0, 4) == 'bak_') {
             $arrNum -= 1;
         }
         for ($i = 0; $i < $arrNum; $i++) {
             $preStr .= $aTmp[$i] . '.';
         }
         $iLoop = 1;
         foreach ($aFile['files'] as $item) {
             if ($item['name'] !== $preStr . 'bak_' . $iLoop . '.' . $lastStr) {
                 break;
             }
             $iLoop++;
         }
         $saveFile = $preStr . 'bak_' . $iLoop . '.' . $lastStr;
         if ($aParams['isbak']) {
             file_rename($dir . $aParams['name'], $dir . $saveFile);
         }
     }
     $fp = fopen($dir . $aParams['name'], 'wb');
     fwrite($fp, $aParams['file_source']);
     fclose($fp);
     return true;
 }
示例#5
0
 /**
  * Rename a directory.
  *
  * @param $path
  * @param $newName
  *
  * @return bool
  */
 function directory_rename($path, $newName)
 {
     return file_rename($path, $newName);
 }
示例#6
0
 function save()
 {
     $this->begin('index.php?ctl=order/delivery_printer&act=index');
     if ($_POST['prt_tmpl_id']) {
         if ($this->model->update($_POST, array('prt_tmpl_id' => $_POST['prt_tmpl_id']))) {
             $tpl_id = $_POST['prt_tmpl_id'];
         } else {
             $tpl_id = false;
         }
     } else {
         $tpl_id = $this->model->insert($_POST);
     }
     $_POST['tmp_bg'] = trim($_POST['tmp_bg']);
     if ($_POST['prt_tmpl_id'] == '__none__') {
     }
     if ($tpl_id && $_POST['tmp_bg']) {
         if (file_exists(HOME_DIR . '/upload/dly_bg_' . $tpl_id . '.jpg')) {
             unlink(HOME_DIR . '/upload/dly_bg_' . $tpl_id . '.jpg');
         }
         if (file_exists(HOME_DIR . '/tmp/' . $_POST['tmp_bg'])) {
             file_rename(HOME_DIR . '/tmp/' . $_POST['tmp_bg'], HOME_DIR . '/upload/dly_bg_' . $tpl_id . '.jpg');
         }
     }
     $this->end(true, $tpl);
 }
示例#7
0
 function setContent($theme, $file, $content, $isbak = false)
 {
     if ($content) {
         $this->__getAllFiles(THEME_DIR . '/' . $theme, $aFile, false);
         if (count($aFile) == 0 || $isbak) {
             $aTmp = explode('.', $file);
             $arrNum = count($aTmp) - 1;
             $lastStr = $aTmp[$arrNum];
             if (substr($aTmp[$arrNum - 1], 0, 4) == 'bak_') {
                 $arrNum -= 1;
             }
             for ($i = 0; $i < $arrNum; $i++) {
                 $preStr .= $aTmp[$i] . '.';
             }
             $iLoop = 1;
             foreach ($aFile as $item) {
                 if (strstr($item, $preStr . 'bak_')) {
                     preg_match_all('/' . $preStr . 'bak_(.*)\\./i', $item, $match);
                     if ($match[1][0] >= $iLoop) {
                         $iLoop = $match[1][0] + 1;
                     }
                 }
             }
             if ($isbak) {
                 $saveFile = $preStr . 'bak_' . $iLoop . '.' . $lastStr;
                 file_rename(THEME_DIR . '/' . $theme . '/' . $file, THEME_DIR . '/' . $theme . '/' . $saveFile);
             }
         }
         file_put_contents(THEME_DIR . '/' . $theme . '/' . $file, stripslashes($content));
         return 1;
     } else {
         return false;
     }
 }
示例#8
0
 function initTheme($theme, $replaceWg = false, $upload = '', $loadxml = '')
 {
     if (empty($loadxml)) {
         $loadxml = 'theme.xml';
     }
     $configxml = 'info.xml';
     $this->separatXml($theme);
     $sDir = THEME_DIR . '/' . $theme . '/';
     $xml = $this->system->loadModel('utility/xml');
     $wightes_info = $xml->xml2arrayValues(file_get_contents($sDir . $loadxml));
     if (is_file($sDir . $configxml)) {
         $config = $xml->xml2arrayValues(file_get_contents($sDir . $configxml));
     } else {
         $config = $wightes_info;
     }
     if ($upload == "upload" && $config['theme']['id']['value']) {
         $config['theme']['id']['value'] = preg_replace('@[^a-zA-Z0-9]@', '_', $config['theme']['id']['value']);
         if (file_rename(THEME_DIR . '/' . $theme, THEME_DIR . '/' . $config['theme']['id']['value'])) {
             $sDir = THEME_DIR . '/' . $config['theme']['id']['value'];
             $theme = $config['theme']['id']['value'];
             $replaceWg = false;
         }
     }
     $aTheme = array('name' => $config['theme']['name']['value'], 'id' => $config['theme']['id']['value'], 'version' => $config['theme']['version']['value'], 'info' => $config['theme']['info']['value'], 'author' => $config['theme']['author']['value'], 'site' => $config['theme']['site']['value'], 'update_url' => $config['theme']['update_url']['value'], 'config' => array('config' => $this->__changeXMLArray($config['theme']['config']['set']), 'borders' => $this->__changeXMLArray($config['theme']['borders']['set']), 'views' => $this->__changeXMLArray($config['theme']['views']['view'])));
     $aWidgets = $wightes_info['theme']['widgets']['widget'];
     $aTheme['theme'] = $theme;
     $aTheme['stime'] = time();
     if (is_array($aTheme['config']['views']) && count($aTheme['config']['views']) > 0) {
         foreach ($aTheme['config']['views'] as $v) {
             $tmp[] = $v['tpl'];
         }
         $aTheme['template'] = implode(',', $tmp);
     } else {
         $aTheme['template'] = '';
     }
     for ($i = 0; $i < count($aWidgets); $i++) {
         $aTmp[$i]['base_file'] = 'user:'******'theme'] . '/' . $aWidgets[$i]['attr']['file'];
         $aTmp[$i]['base_slot'] = $aWidgets[$i]['attr']['slot'];
         $aTmp[$i]['widgets_type'] = $aWidgets[$i]['attr']['type'];
         $aTmp[$i]['widgets_order'] = $aWidgets[$i]['attr']['order'];
         $aTmp[$i]['title'] = $aWidgets[$i]['attr']['title'];
         $aTmp[$i]['domid'] = $aWidgets[$i]['attr']['domid'];
         $aTmp[$i]['border'] = $aWidgets[$i]['attr']['border'];
         $aTmp[$i]['classname'] = $aWidgets[$i]['attr']['classname'];
         $aTmp[$i]['tpl'] = $aWidgets[$i]['attr']['tpl'];
         $aTmp[$i]['base_id'] = $aWidgets[$i]['attr']['baseid'];
         /*$set=$aWidgets[$i]['set'];
           $aSet = array();
           for($y=0;$y<count($set);$y++){
               $aSet[$set[$y]['attr']['key']]=$set[$y]['attr']['value'];
           }*/
         $aTmp[$i]['params'] = strtr($aWidgets[$i]['value'], array_flip(get_html_translation_table(HTML_SPECIALCHARS)));
     }
     $aWidgets = $aTmp;
     $aNumber = $this->countWidgetsByTheme($theme);
     $nNumber = intval($aNumber['num']);
     $insertWidgets = false;
     if ($replaceWg) {
         if ($nNumber) {
             $this->deleteWidgetsByTheme($theme);
         }
         $insertWidgets = true;
     } else {
         if ($nNumber == 0) {
             $insertWidgets = true;
         }
     }
     if ($insertWidgets && count($aWidgets) > 0) {
         foreach ($aWidgets as $k => $wg) {
             $this->insertWidgets($wg);
         }
     }
     if (!$this->updateThemes($aTheme)) {
         return false;
     } else {
         return $aTheme;
     }
 }
示例#9
0
function dir_rename($dir,$pre_old,$pre_new)
{
	$file_array = getFileListAsArray($dir);
	foreach ($file_array as $file) 
	{	if ( preg_match("/^$pre_old/",$file) )
		{	file_rename($dir,$file,$pre_old,$pre_new); }
	}

}