| 1: | <?php
|
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: |
|
| 9: |
|
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: |
|
| 16: | class Smarty_Internal_Runtime_WriteFile
|
| 17: | {
|
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: |
|
| 28: | public function writeFile($_filepath, $_contents, Smarty $smarty)
|
| 29: | {
|
| 30: | $_error_reporting = error_reporting();
|
| 31: | error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
|
| 32: | $_file_perms = property_exists($smarty, '_file_perms') ? $smarty->_file_perms : 0644;
|
| 33: | $_dir_perms =
|
| 34: | property_exists($smarty, '_dir_perms') ? (isset($smarty->_dir_perms) ? $smarty->_dir_perms : 0777) : 0771;
|
| 35: | if ($_file_perms !== null) {
|
| 36: | $old_umask = umask(0);
|
| 37: | }
|
| 38: | $_dirpath = dirname($_filepath);
|
| 39: |
|
| 40: | if ($_dirpath !== '.') {
|
| 41: | $i = 0;
|
| 42: |
|
| 43: |
|
| 44: | while (!is_dir($_dirpath)) {
|
| 45: | if (@mkdir($_dirpath, $_dir_perms, true)) {
|
| 46: | break;
|
| 47: | }
|
| 48: | clearstatcache();
|
| 49: | if (++$i === 3) {
|
| 50: | error_reporting($_error_reporting);
|
| 51: | throw new SmartyException("unable to create directory {$_dirpath}");
|
| 52: | }
|
| 53: | sleep(1);
|
| 54: | }
|
| 55: | }
|
| 56: |
|
| 57: | $_tmp_file = $_dirpath . DIRECTORY_SEPARATOR . str_replace(array('.', ','), '_', uniqid('wrt', true));
|
| 58: | if (!file_put_contents($_tmp_file, $_contents)) {
|
| 59: | error_reporting($_error_reporting);
|
| 60: | throw new SmartyException("unable to write file {$_tmp_file}");
|
| 61: | }
|
| 62: | |
| 63: | |
| 64: | |
| 65: | |
| 66: | |
| 67: | |
| 68: |
|
| 69: | if (Smarty::$_IS_WINDOWS) {
|
| 70: |
|
| 71: | if (is_file($_filepath)) {
|
| 72: | @unlink($_filepath);
|
| 73: | }
|
| 74: |
|
| 75: | $success = @rename($_tmp_file, $_filepath);
|
| 76: | } else {
|
| 77: |
|
| 78: | $success = @rename($_tmp_file, $_filepath);
|
| 79: | if (!$success) {
|
| 80: |
|
| 81: | if (is_file($_filepath)) {
|
| 82: | @unlink($_filepath);
|
| 83: | }
|
| 84: |
|
| 85: | $success = @rename($_tmp_file, $_filepath);
|
| 86: | }
|
| 87: | }
|
| 88: | if (!$success) {
|
| 89: | error_reporting($_error_reporting);
|
| 90: | throw new SmartyException("unable to write file {$_filepath}");
|
| 91: | }
|
| 92: | if ($_file_perms !== null) {
|
| 93: |
|
| 94: | chmod($_filepath, $_file_perms);
|
| 95: | umask($old_umask);
|
| 96: | }
|
| 97: | error_reporting($_error_reporting);
|
| 98: | return true;
|
| 99: | }
|
| 100: | }
|
| 101: | |