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