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:  * This file contains the the system purge class.
  4:  *
  5:  * @package Core
  6:  * @subpackage Backend
  7:  * @version SVN Revision $Rev:$
  8:  *
  9:  * @author Munkh-Ulzii Balidar
 10:  * @copyright four for business AG <www.4fb.de>
 11:  * @license http://www.contenido.org/license/LIZENZ.txt
 12:  * @link http://www.4fb.de
 13:  * @link http://www.contenido.org
 14:  */
 15: 
 16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 17: 
 18: /**
 19:  * CONTENIDO cSystemPurge class to reset some datas and files
 20:  *
 21:  * @package Core
 22:  * @subpackage Backend
 23:  */
 24: class cSystemPurge {
 25: 
 26:     /**
 27:      * These directories should not be deleted.
 28:      *
 29:      * @var array
 30:      */
 31:     private $_dirsExcluded = array(
 32:         'code',
 33:         'templates_c'
 34:     );
 35: 
 36:     /**
 37:      * These directories and the included files should not be cleared.
 38:      *
 39:      * @var array
 40:      */
 41:     private $_dirsExcludedWithFiles = array(
 42:         '.',
 43:         '..',
 44:         '.svn',
 45:         '.cvs',
 46:         '.htaccess',
 47:         '.git',
 48:         '.gitignore',
 49:         '.keep',
 50:     );
 51: 
 52:     /**
 53:      *
 54:      * @var array
 55:      */
 56:     private $_logFileTypes = array(
 57:         'txt'
 58:     );
 59: 
 60:     /**
 61:      *
 62:      * @var array
 63:      */
 64:     private $_cronjobFileTypes = array(
 65:         'job'
 66:     );
 67: 
 68:     /**
 69:      * Constructor of class
 70:      */
 71:     public function __construct() {
 72:         // check and set the system directories to exclude from purge
 73:         $dirsToExcludeWithFiles = getSystemProperty('system', 'purge-dirstoexclude-withfiles');
 74:         $aDirsToExcludeWithFiles = array_map('trim', explode(',', $dirsToExcludeWithFiles));
 75:         if (count($aDirsToExcludeWithFiles) < 1 || empty($aDirsToExcludeWithFiles[0])) {
 76:             $aDirsToExcludeWithFiles = $this->_dirsExcludedWithFiles;
 77:             setSystemProperty('system', 'purge-dirstoexclude-withfiles', implode(',', $aDirsToExcludeWithFiles));
 78:         }
 79: 
 80:         $this->_dirsExcludedWithFiles = $aDirsToExcludeWithFiles;
 81:     }
 82: 
 83:     /**
 84:      * Deletes the PHP files in cms/cache/code
 85:      *
 86:      * @param int $clientId
 87:      * @return bool
 88:      */
 89:     public function resetClientConCode($clientId) {
 90:         global $perm, $currentuser;
 91:         $cfgClient = cRegistry::getClientConfig();
 92: 
 93:         if (cFileHandler::exists($cfgClient[$clientId]['cache']['path'] . 'code/') === false) {
 94:             return false;
 95:         }
 96: 
 97:         if ($perm->isClientAdmin($clientId, $currentuser) === false && $perm->isSysadmin($currentuser) === false) {
 98:             return false;
 99:         }
100: 
101:         /** @var $file SplFileInfo */
102:         foreach (new DirectoryIterator($cfgClient[$clientId]['code']['path']) as $file) {
103:             if ($file->isFile() === false) {
104:                 continue;
105:             }
106: 
107:             $extension = substr($file, strrpos($file->getBasename(), '.') + 1);
108:             if ($extension != 'php') {
109:                 continue;
110:             }
111: 
112:             if (cFileHandler::remove($cfgClient[$clientId]['code']['path'] . '/' . $file->getFilename()) === false) {
113:                 return false;
114:             }
115:         }
116: 
117:         return true;
118:     }
119: 
120:     /**
121:      * Reset the table con_cat_art for a client
122:      *
123:      * @param int $clientId
124:      * @return bool
125:      */
126:     public function resetClientConCatArt($clientId) {
127:         global $perm, $currentuser;
128:         $db = cRegistry::getDb();
129:         $cfg = cRegistry::getConfig();
130: 
131:         if ($perm->isClientAdmin($clientId, $currentuser) || $perm->isSysadmin($currentuser)) {
132:             $sSql = ' UPDATE ' . $cfg['tab']['cat_art'] . ' cca, ' . $cfg['tab']['cat'] . ' cc, ' . $cfg['tab']['art'] . ' ca ' . ' SET cca.createcode=1 ' . ' WHERE cc.idcat = cca.idcat ' . ' AND ca.idart = cca.idart ' . ' AND cc.idclient = ' . (int) $clientId . ' AND ca.idclient = ' . (int) $clientId;
133:             $db->query($sSql);
134: 
135:             return ($db->getErrorMessage() == '') ? true : false;
136:         } else {
137:             return false;
138:         }
139:     }
140: 
141:     /**
142:      * Reset the table con_inuse
143:      *
144:      * @return bool
145:      */
146:     public function resetConInuse() {
147:         global $perm, $currentuser;
148:         $db = cRegistry::getDb();
149:         $cfg = cRegistry::getConfig();
150: 
151:         if ($perm->isSysadmin($currentuser)) {
152:             $sql = 'DELETE FROM ' . $cfg['tab']['inuse'];
153:             $db->query($sql);
154: 
155:             return ($db->getErrorMessage() == '') ? true : false;
156:         } else {
157:             return false;
158:         }
159:     }
160: 
161:     /**
162:      * Clear the cache directory for a client
163:      *
164:      * @param int $clientId
165:      * @return bool
166:      */
167:     public function clearClientCache($clientId) {
168:         global $perm, $currentuser;
169:         $cfgClient = cRegistry::getClientConfig();
170: 
171:         if ($perm->isClientAdmin($clientId, $currentuser) || $perm->isSysadmin($currentuser)) {
172:             $cacheDir = $cfgClient[$clientId]['cache']['path'];
173:             if (is_dir($cacheDir)) {
174:                 return ($this->clearDir($cacheDir, $cacheDir) ? true : false);
175:             }
176:             return false;
177:         } else {
178:             return false;
179:         }
180:     }
181: 
182:     /**
183:      * Clear the cache directory for a client
184:      *
185:      * @param int $clientId
186:      * @param bool $keep
187:      * @param int $fileNumber
188:      * @return bool
189:      */
190:     public function clearClientHistory($clientId, $keep, $fileNumber) {
191:         global $perm, $currentuser;
192:         $cfgClient = cRegistry::getClientConfig();
193: 
194:         if ($perm->isClientAdmin($clientId, $currentuser) || $perm->isSysadmin($currentuser)) {
195:             $versionDir = $cfgClient[$clientId]['version']['path'];
196:             if (is_dir($versionDir)) {
197:                 $tmpFile = array();
198:                 $this->clearDir($versionDir, $versionDir, $keep, $tmpFile);
199:                 if (count($tmpFile) > 0) {
200:                     foreach ($tmpFile as $sKey => $aFiles) {
201:                         // sort the history files with filename
202:                         array_multisort($tmpFile[$sKey]);
203: 
204:                         $count = count($tmpFile[$sKey]);
205:                         // find the total number to delete
206:                         $countDelete = ($count <= $fileNumber) ? 0 : ($count - $fileNumber);
207:                         // delete the files
208:                         for ($i = 0; $i < $countDelete; $i++) {
209:                             if (cFileHandler::exists($tmpFile[$sKey][$i]) && is_writable($tmpFile[$sKey][$i])) {
210:                                 unlink($tmpFile[$sKey][$i]);
211:                             }
212:                         }
213:                     }
214:                 }
215: 
216:                 return true;
217:             }
218:             return false;
219:         } else {
220:             return false;
221:         }
222:     }
223: 
224:     /**
225:      * Clear client log file
226:      *
227:      * @param int $clientId
228:      * @return bool
229:      */
230:     public function clearClientLog($clientId) {
231:         global $perm, $currentuser;
232:         $cfgClient = cRegistry::getClientConfig();
233: 
234:         if ($perm->isClientAdmin($clientId, $currentuser) || $perm->isSysadmin($currentuser)) {
235:             $logDir = $cfgClient[$clientId]['log']['path'];
236:             if (is_dir($logDir)) {
237:                 return $this->emptyFile($logDir, $this->_logFileTypes);
238:             }
239:             return false;
240:         } else {
241:             return false;
242:         }
243:     }
244: 
245:     /**
246:      * Clear CONTENIDO log files
247:      *
248:      * @return bool
249:      */
250:     public function clearConLog() {
251:         global $perm, $currentuser;
252:         $cfg = cRegistry::getConfig();
253: 
254:         $logDir = $cfg['path']['contenido_logs'];
255:         if ($perm->isSysadmin($currentuser)) {
256:             if (is_dir($logDir)) {
257:                 return $this->emptyFile($logDir, $this->_logFileTypes);
258:             }
259:             return false;
260:         } else {
261:             return false;
262:         }
263:     }
264: 
265:     /**
266:      * Clear the cronjob directory
267:      *
268:      * @return bool
269:      */
270:     public function clearConCronjob() {
271:         global $perm, $currentuser;
272:         $cfg = cRegistry::getConfig();
273: 
274:         $cronjobDir = $cfg['path']['contenido_cronlog'];
275:         if ($perm->isSysadmin($currentuser)) {
276:             if (is_dir($cronjobDir)) {
277:                 return $this->emptyFile($cronjobDir, $this->_cronjobFileTypes);
278:             }
279:             return false;
280:         } else {
281:             return false;
282:         }
283:     }
284: 
285:     /**
286:      * Clear the cache directory for a client
287:      *
288:      * @return bool
289:      */
290:     public function clearConCache() {
291:         global $perm, $currentuser;
292:         $cfg = cRegistry::getConfig();
293: 
294:         $cacheDir = $cfg['path']['contenido_cache'];
295:         if ($perm->isSysadmin($currentuser)) {
296:             if (is_dir($cacheDir)) {
297:                 return ($this->clearDir($cacheDir, $cacheDir) ? true : false);
298:             }
299:             return false;
300:         } else {
301:             return false;
302:         }
303:     }
304: 
305:     /**
306:      * Clears the article cache of the article which is defined by the given
307:      * parameters.
308:      *
309:      * @param int $idartlang the idartlang of the article
310:      */
311:     public function clearArticleCache($idartlang) {
312:         $cfgClient = cRegistry::getClientConfig();
313:         $client = cRegistry::getClientId();
314: 
315:         $artLang = new cApiArticleLanguage($idartlang);
316:         $idlang = $artLang->get('idlang');
317:         $idart = $artLang->get('idart');
318:         $art = new cApiArticle($idart);
319:         $idclient = $art->get('idclient');
320: 
321:         $catArtColl = new cApiCategoryArticleCollection();
322:         $catArtColl->select('idart=' . $idart);
323:         while (($item = $catArtColl->next()) !== false) {
324:             $filename = $cfgClient[$client]['code']['path'] . $idclient . '.' . $idlang . '.' . $item->get('idcatart') . '.php';
325:             if (cFileHandler::exists($filename)) {
326:                 cFileHandler::remove($filename);
327:             }
328:         }
329:     }
330: 
331:     /**
332:      * Delete all files and sub directories in a directory
333:      *
334:      * @param string $dirPath
335:      * @param string $tmpDirPath - root directory not deleted
336:      * @param bool $keep
337:      * @param array $tmpFileList - files are temporarily saved
338:      * @return bool
339:      */
340:     public function clearDir($dirPath, $tmpDirPath, $keep = false, &$tmpFileList = array()) {
341:         if (is_dir($dirPath) && false !== ($handle = cDirHandler::read($dirPath))) {
342:             $tmp = str_replace(array(
343:                 '/',
344:                 '..'
345:             ), '', $dirPath);
346:             foreach ($handle as $file) {
347:                 if (!in_array($file, $this->_dirsExcludedWithFiles)) {
348:                     $filePath = $dirPath . '/' . $file;
349:                     $filePath = str_replace('//', '/', $filePath);
350:                     if (is_dir($filePath)) {
351:                         $this->clearDir($filePath, $tmpDirPath, $keep, $tmpFileList);
352:                     } else {
353:                         if ($keep === false) {
354:                             cFileHandler::remove($filePath);
355:                         } else {
356:                             $tmpFileList[$tmp][] = $filePath;
357:                         }
358:                     }
359:                 }
360:             }
361: 
362:             $dirs = explode('/', $dirPath);
363:             if (end($dirs) == '') {
364:                 array_pop($dirs);
365:             }
366:             $dirName = end($dirs);
367: 
368:             if (str_replace(array(
369:                 '/',
370:                 '..'
371:             ), '', $dirPath) != str_replace(array(
372:                 '/',
373:                 '..'
374:             ), '', $tmpDirPath)
375:             && $keep === false) {
376:                 // check if directoy contains reserved files folders
377:                 $bCanDelete = true;
378:                 $dirContent = cDirHandler::read($dirPath);
379:                 foreach ($dirContent as $sContent) {
380:                     if (in_array($sContent, $this->_dirsExcludedWithFiles)
381:                     || in_array($dirContent, $this->_dirsExcluded)) {
382:                         $bCanDelete = false;
383:                         break;
384:                     }
385:                 }
386:                 if (true === $bCanDelete
387:                 && in_array($dirName, $this->_dirsExcluded)) {
388:                     $bCanDelete = false;
389:                 }
390:             }
391:             // reserved files or folders, do not delete
392:             if (true === $bCanDelete) {
393:                 cDirHandler::remove($dirPath);
394:             }
395: 
396:             return true;
397:         } else {
398:             return false;
399:         }
400:     }
401: 
402:     /**
403:      * Empty a file content
404:      *
405:      * @param string $dirPath
406:      * @param array $types
407:      * @return bool
408:      */
409:     public function emptyFile($dirPath, $types) {
410:         $count = 0;
411:         $countCleared = 0;
412:         
413:         if (is_dir($dirPath) && false !== ($handle = cDirHandler::read($dirPath))) {
414:             foreach ($handle as $file) {
415:                 $fileExt = trim(end(explode('.', $file)));
416:                 
417:                 if ($file != '.' && $file != '..' && in_array($fileExt, $types)) {
418:                     $filePath = $dirPath . '/' . $file;
419:                 
420:                     if (cFileHandler::exists($filePath) && cFileHandler::writeable($filePath)) {
421:                         $count++;
422:                 
423:                         if (cFileHandler::truncate($filePath)) {
424:                             $countCleared++;
425:                         }
426:                     }
427:                 }
428:             }
429: 
430:             // true if all files are cleaned
431:             return ($count == $countCleared) ? true : false;
432:         }
433: 
434:         return false;
435:     }
436: 
437:     /**
438:      * Get frontend directory name for a client
439:      *
440:      * @param int $clientId
441:      * @return string $sClientDir
442:      */
443:     public function getClientDir($clientId) {
444:         $cfgClient = cRegistry::getClientConfig();
445: 
446:         return $cfgClient[$clientId]['path']['frontend'];
447:     }
448: 
449:     /**
450:      * Set log file types
451:      *
452:      * @param array $types
453:      */
454:     public function setLogFileTypes($types) {
455:         if (count($types) > 0) {
456:             foreach ($types as $type) {
457:                 $this->_logFileTypes[] = $type;
458:             }
459:         }
460:     }
461: 
462:     /**
463:      * Set cronjob file types
464:      *
465:      * @param array $types
466:      */
467:     public function setCronjobFileTypes($types) {
468:         if (count($types) > 0) {
469:             foreach ($types as $type) {
470:                 $this->_cronjobFileTypes[] = $type;
471:             }
472:         }
473:     }
474: 
475: }
476: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen