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