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