Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
 1: <?php
 2: /**
 3:  * Smarty write file plugin
 4:  *
 5:  * @package    Smarty
 6:  * @subpackage PluginsInternal
 7:  * @author     Monte Ohrt
 8:  */
 9: 
10: /**
11:  * Smarty Internal Write File Class
12:  *
13:  * @package    Smarty
14:  * @subpackage PluginsInternal
15:  */
16: class Smarty_Internal_Write_File
17: {
18:     /**
19:      * Writes file in a safe way to disk
20:      *
21:      * @param  string $_filepath complete filepath
22:      * @param  string $_contents file content
23:      * @param  Smarty $smarty    smarty instance
24:      *
25:      * @throws SmartyException
26:      * @return boolean true
27:      */
28:     public static function writeFile($_filepath, $_contents, Smarty $smarty)
29:     {
30:         $_error_reporting = error_reporting();
31:         error_reporting($_error_reporting & ~E_NOTICE & ~E_WARNING);
32:         if ($smarty->_file_perms !== null) {
33:             $old_umask = umask(0);
34:         }
35: 
36:         $_dirpath = dirname($_filepath);
37:         // if subdirs, create dir structure
38:         if ($_dirpath !== '.' && !file_exists($_dirpath)) {
39:             mkdir($_dirpath, $smarty->_dir_perms === null ? 0777 : $smarty->_dir_perms, true);
40:         }
41: 
42:         // write to tmp file, then move to overt file lock race condition
43:         $_tmp_file = $_dirpath . DS . str_replace(array('.', ','), '_', uniqid('wrt', true));
44:         if (!file_put_contents($_tmp_file, $_contents)) {
45:             error_reporting($_error_reporting);
46:             throw new SmartyException("unable to write file {$_tmp_file}");
47:        }
48: 
49:         /*
50:          * Windows' rename() fails if the destination exists,
51:          * Linux' rename() properly handles the overwrite.
52:          * Simply unlink()ing a file might cause other processes
53:          * currently reading that file to fail, but linux' rename()
54:          * seems to be smart enough to handle that for us.
55:          */
56:         if (Smarty::$_IS_WINDOWS) {
57:             // remove original file
58:             @unlink($_filepath);
59:             // rename tmp file
60:             $success = @rename($_tmp_file, $_filepath);
61:         } else {
62:             // rename tmp file
63:             $success = @rename($_tmp_file, $_filepath);
64:             if (!$success) {
65:                 // remove original file
66:                 @unlink($_filepath);
67:                 // rename tmp file
68:                 $success = @rename($_tmp_file, $_filepath);
69:             }
70:         }
71: 
72:         if (!$success) {
73:             error_reporting($_error_reporting);
74:             throw new SmartyException("unable to write file {$_filepath}");
75:         }
76: 
77:         if ($smarty->_file_perms !== null) {
78:             // set file permissions
79:             chmod($_filepath, $smarty->_file_perms);
80:             umask($old_umask);
81:         }
82:         error_reporting($_error_reporting);
83: 
84:         return true;
85:     }
86: }
87: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen