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:  * Functions to edit files.
  4:  * Included in Area style,
  5:  * js, htmltpl in Frame right_bottom.
  6:  *
  7:  * Contains also common file and directory related functions
  8:  *
  9:  * TODO: merge with cFileHandler and cDirHandler
 10:  *
 11:  * @package Core
 12:  * @subpackage Backend
 13:  * @version SVN Revision $Rev:$
 14:  *
 15:  * @author Willi Man, Timo Trautmann
 16:  * @copyright four for business AG <www.4fb.de>
 17:  * @license http://www.contenido.org/license/LIZENZ.txt
 18:  * @link http://www.4fb.de
 19:  * @link http://www.contenido.org
 20:  */
 21: 
 22: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 23: 
 24: /**
 25:  * Function removes file meta information from database (used when a file is
 26:  * deleted)
 27:  *
 28:  * @param int $iIdClient - id of client which contains this file
 29:  * @param string $sFilename - name of corresponding file
 30:  * @param string $sType - type of file (css, js or templates)
 31:  * @param cDb $oDb - CONTENIDO database object
 32:  */
 33: function removeFileInformation($iIdClient, $sFilename, $sType, $oDb) {
 34:     global $cfg;
 35: 
 36:     if (!isset($oDb) || !is_object($oDb)) {
 37:         $oDb = cRegistry::getDb();
 38:     }
 39: 
 40:     $iIdClient = cSecurity::toInteger($iIdClient);
 41:     $sFilename = cSecurity::filter((string) $sFilename, $oDb);
 42:     $sType = cSecurity::filter((string) $sType, $oDb);
 43: 
 44:     $sSql = "DELETE FROM `" . $cfg["tab"]["file_information"] . "` WHERE idclient = $iIdClient AND
 45:             filename = '$sFilename' AND type = '$sType';";
 46:     $oDb->query($sSql);
 47:     $oDb->free();
 48: }
 49: 
 50: /**
 51:  * Function returns file meta information from database (used when files were
 52:  * versionned or description is displayed)
 53:  *
 54:  * @param int $iIdClient - id of client which contains this file
 55:  * @param string $sFilename - name of corresponding file
 56:  * @param string $sType - type of file (css, js or templates)
 57:  * @param cDb $oDb - CONTENIDO database object
 58:  * @return array Indexes:
 59:  *         idsfi - Primary key of database record
 60:  *         created - Datetime when file was created
 61:  *         lastmodified - Datetime when file was last modified
 62:  *         author - Author of file (CONTENIDO Backend User)
 63:  *         modifiedby - Last modifier of file (CONTENIDO Backend User)
 64:  *         description - Description which was inserted for this file
 65:  *
 66:  */
 67: function getFileInformation($iIdClient, $sFilename, $sType, $oDb) {
 68:     global $cfg;
 69: 
 70:     if (!isset($oDb) || !is_object($oDb)) {
 71:         $oDb = cRegistry::getDb();
 72:     }
 73: 
 74:     $iIdClient = cSecurity::toInteger($iIdClient);
 75:     $sFilename = cSecurity::filter((string) $sFilename, $oDb);
 76:     $sType = cSecurity::filter((string) $sType, $oDb);
 77: 
 78:     $aFileInformation = array();
 79:     $sSql = "SELECT * FROM `" . $cfg["tab"]["file_information"] . "` WHERE idclient = $iIdClient AND
 80:             filename = '$sFilename' AND type = '$sType';";
 81:     $oDb->query($sSql);
 82:     if ($oDb->numRows() > 0) {
 83:         $oDb->nextRecord();
 84:         $aFileInformation['idsfi'] = $oDb->f('idsfi');
 85:         $aFileInformation['created'] = $oDb->f('created');
 86:         $aFileInformation['lastmodified'] = $oDb->f('lastmodified');
 87:         $aFileInformation['author'] = cSecurity::unFilter($oDb->f('author'));
 88:         $aFileInformation['modifiedby'] = $oDb->f('modifiedby');
 89:         $aFileInformation['description'] = cSecurity::unFilter($oDb->f('description'));
 90:     }
 91:     $oDb->free();
 92: 
 93:     return $aFileInformation;
 94: }
 95: 
 96: /**
 97:  * Function updates file meta information (used when files were created or
 98:  * edited).
 99:  * It creates new database record for file meta informations if database record
100:  * does
101:  * not exist. Otherwise, existing record will be updated
102:  *
103:  * @param int $iIdClient - id of client which contains this file
104:  * @param string $sFilename - name of corresponding file
105:  * @param string $sType - type of file (css, js or templates)
106:  * @param string $sAuthor - author of file
107:  * @param string $sDescription - description of file
108:  * @param cDb $oDb - CONTENIDO database object
109:  * @param string $sFilenameNew - new filename if filename was changed (optional)
110:  */
111: function updateFileInformation($iIdClient, $sFilename, $sType, $sAuthor, $sDescription, $oDb, $sFilenameNew = '') {
112:     global $cfg;
113: 
114:     if (!isset($oDb) || !is_object($oDb)) {
115:         $oDb = cRegistry::getDb();
116:     }
117: 
118:     if ($sFilenameNew == '') {
119:         $sFilenameNew = $sFilename;
120:     }
121: 
122:     $iIdClient = cSecurity::toInteger($iIdClient);
123:     $sFilename = cSecurity::filter((string) $sFilename, $oDb);
124:     $sType = cSecurity::filter((string) $sType, $oDb);
125:     $sDescription = cSecurity::filter((string) stripslashes($sDescription), $oDb);
126:     $sAuthor = cSecurity::filter((string) $sAuthor, $oDb);
127: 
128:     $sSql = "SELECT * from `" . $cfg["tab"]["file_information"] . "` WHERE idclient = $iIdClient AND
129:             filename = '$sFilename' AND type = '$sType';";
130:     $oDb->query($sSql);
131:     if ($oDb->numRows() == 0) {
132:         // $iNextId = $oDb->nextid('con_style_file_information');
133:         $sSql = "INSERT INTO `" . $cfg["tab"]["file_information"] . "` (
134:                     `idclient` ,
135:                     `type` ,
136:                     `filename` ,
137:                     `created` ,
138:                     `lastmodified` ,
139:                     `author` ,
140:                     `modifiedby` ,
141:                     `description`)
142:                 VALUES (
143:                     $iIdClient,
144:                     '$sType',
145:                     '$sFilenameNew',
146:                     NOW(),
147:                     '0000-00-00 00:00:00',
148:                     '$sAuthor',
149:                     '',
150:                     '$sDescription'
151:                 );";
152:     } else {
153:         $sSql = "UPDATE `" . $cfg["tab"]["file_information"] . "` SET `lastmodified` = NOW(),
154:                 `modifiedby` = '$sAuthor',
155:                 `description` = '$sDescription',
156:                 `filename` = '$sFilenameNew'
157:                 WHERE idclient=$iIdClient AND
158:                       filename='$sFilename' AND
159:                       type='$sType';";
160:     }
161: 
162:     $oDb->free();
163:     $oDb->query($sSql);
164:     $oDb->free();
165: }
166: 
167: /**
168:  * Returns the filetype (extension).
169:  *
170:  * @param string $filename The file to get the type
171:  * @return string Filetype
172:  */
173: function getFileType($filename) {
174:     return cFileHandler::getExtension($filename);
175: }
176: 
177: /**
178:  * Returns the size of a directory.
179:  * AKA the combined filesizes of all files within it.
180:  * Note that this function uses filesize(). There could be problems with files
181:  * that are larger than 2GiB
182:  *
183:  * @param string $sDirectory The directory
184:  * @param bool $bRecursive true if all the subdirectories should be included in the
185:  *            calculation
186:  * @return bool int false in case of an error or the size
187:  */
188: function getDirectorySize($sDirectory, $bRecursive = false) {
189:     $ret = 0;
190:     $files = scanDirectory($sDirectory, $bRecursive);
191:     if ($files === false) {
192:         return false;
193:     }
194: 
195:     foreach ($files as $file) {
196:         $temp = cFileHandler::info($file);
197:         $ret += $temp['size'];
198:     }
199: 
200:     return $ret;
201: }
202: 
203: /**
204:  * Scans passed directory and collects all found files
205:  *
206:  * @param string $sDirectory
207:  * @param bool $bRecursive
208:  * @return bool array of found files (full path and name) or false
209:  */
210: function scanDirectory($sDirectory, $bRecursive = false) {
211:     if (substr($sDirectory, strlen($sDirectory) - 1, 1) == '/') {
212:         $sDirectory = substr($sDirectory, 0, strlen($sDirectory) - 1);
213:     }
214: 
215:     if (!is_dir($sDirectory)) {
216:         return false;
217:     }
218: 
219:     $aFiles = array();
220:     $openDirs = array();
221:     $closedDirs = array();
222:     array_push($openDirs, $sDirectory);
223: 
224:     while (count(($openDirs)) >= 1) {
225:         $sDirectory = array_pop($openDirs);
226:         if (is_dir($sDirectory)) {
227:             if (false !== $handle = cDirHandler::read($sDirectory)) {
228:                 foreach ($handle as $sFile) {
229:                     if (cFileHandler::fileNameIsDot($sFile) === false) {
230:                         $sFullpathFile = $sDirectory . '/' . $sFile;
231:                         if (is_file($sFullpathFile) && cFileHandler::readable($sFullpathFile)) {
232:                             array_push($aFiles, $sFullpathFile);
233:                         } elseif (is_dir($sFullpathFile) && $bRecursive == true) {
234:                             if (!in_array($sFullpathFile, $closedDirs)) {
235:                                 array_push($openDirs, $sFullpathFile);
236:                             }
237:                         }
238:                     }
239:                 }
240:             }
241:         }
242:         array_push($closedDirs, $sDirectory);
243:     }
244: 
245:     return $aFiles;
246: }
247: 
248: /**
249:  * Copies source directory to destination directory.
250:  *
251:  * @param string $sourcePath
252:  * @param string $destinationPath
253:  * @param int $mode Octal representation of file mode (0644, 0750, etc.)
254:  * @param array $options Some additional options as follows
255:  *        <pre>
256:  *        $options['force_overwrite'] (bool) Flag to overwrite existing
257:  *            destination file, default value is false
258:  *        </pre>
259:  */
260: function recursiveCopy($sourcePath, $destinationPath, $mode = 0777, array $options = array()) {
261:     if (!is_dir($destinationPath)) {
262:         mkdir($destinationPath, $mode);
263:     }
264: 
265:     $forceOverwrite = (isset($options['force_overwrite'])) ? (bool) $options['force_overwrite'] : false;
266:     $oldPath = getcwd();
267: 
268:     if (is_dir($sourcePath)) {
269:         chdir($sourcePath);
270: 
271:         if (false !== ($handle = cDirHandler::read('.'))) {
272:             foreach ($handle as $file) {
273:                 if (cFileHandler::fileNameIsDot($file) === false && is_dir($file)) {
274:                     // Copy directory
275:                     recursiveCopy($sourcePath . $file . '/', $destinationPath . $file . '/', $mode, $options);
276:                     chdir($sourcePath);
277:                 } elseif (cFileHandler::exists($sourcePath . $file)) {
278:                     // Copy file
279:                     if (cFileHandler::exists($destinationPath . $file)) {
280:                         if ($forceOverwrite) {
281:                             copy($sourcePath . $file, $destinationPath . $file);
282:                         }
283:                     } else {
284:                         copy($sourcePath . $file, $destinationPath . $file);
285:                     }
286:                 }
287:             }
288:         }
289:     }
290: 
291:     chdir($oldPath);
292: }
293: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen