public function purgePhpFastCache() { if (!is_array($GLOBALS['TL_PURGE']['folders']['phpfastcache']['affected'])) { return false; } foreach ($GLOBALS['TL_PURGE']['folders']['phpfastcache']['affected'] as $folder) { // Purge folder $objFolder = new \Folder($folder); $objFolder->purge(); // Restore the index.html file $objFile = new \File('templates/index.html', true); $objFile->copyTo($folder . 'index.html'); } // Also empty the page cache so there are no links to deleted scripts $this->purgePageCache(); // Add a log entry $this->log('Purged the phpfastcache cache', 'HeimrichHannot\\Haste\\Backend\\Automator purgePhpFastCache()', TL_CRON); }
/** * Generate module */ protected function compile() { // Create files if (\Input::post('FORM_SUBMIT') == 'tl_extension') { $objModule = $this->Database->prepare("SELECT * FROM tl_extension WHERE id=?")->limit(1)->execute($this->objDc->id); if ($objModule->numRows < 1) { return; } // Disable the debug mode (see #7068) \Config::set('debugMode', false); // config/config.php $tplConfig = $this->newTemplate('dev_config', $objModule); \File::putContent('system/modules/' . $objModule->folder . '/config/config.php', $tplConfig->parse()); // config/autoload.ini $tplConfig = $this->newTemplate('dev_ini', $objModule); \File::putContent('system/modules/' . $objModule->folder . '/config/autoload.ini', $tplConfig->parse()); // Back end if ($objModule->addBeMod) { $arrClasses = array_filter(trimsplit(',', $objModule->beClasses)); // Classes foreach ($arrClasses as $strClass) { $tplClass = $this->newTemplate('dev_beClass', $objModule); $tplClass->class = $strClass; \File::putContent('system/modules/' . $objModule->folder . '/' . $this->guessSubfolder($strClass) . '/' . $strClass . '.php', $tplClass->parse()); } $arrTables = array_filter(trimsplit(',', $objModule->beTables)); // Back end data container files foreach ($arrTables as $strTable) { $tplTable = $this->newTemplate('dev_dca', $objModule); $tplTable->table = $strTable; \File::putContent('system/modules/' . $objModule->folder . '/dca/' . $strTable . '.php', $tplTable->parse()); } $arrTemplates = array_filter(trimsplit(',', $objModule->beTemplates)); // Templates foreach ($arrTemplates as $strTemplate) { $tplTemplate = $this->newTemplate('dev_beTemplate', $objModule); \File::putContent('system/modules/' . $objModule->folder . '/templates/' . $strTemplate . '.html5', $tplTemplate->parse()); } } $arrTables = array(); // Front end if ($objModule->addFeMod) { $arrClasses = array_filter(trimsplit(',', $objModule->feClasses)); // Classes foreach ($arrClasses as $strClass) { $tplClass = $this->newTemplate('dev_feClass', $objModule); $tplClass->class = $strClass; $tplClass->extends = $this->guessParentClass($strClass); \File::putContent('system/modules/' . $objModule->folder . '/' . $this->guessSubfolder($strClass) . '/' . $strClass . '.php', $tplClass->parse()); } $arrTables = array_filter(trimsplit(',', $objModule->feTables)); // Front end data container files foreach ($arrTables as $strTable) { $tplTable = $this->newTemplate('dev_feDca', $objModule); $tplTable->table = $strTable; \File::putContent('system/modules/' . $objModule->folder . '/dca/' . $strTable . '.php', $tplTable->parse()); } // Models foreach ($arrTables as $strTable) { $strModel = \Model::getClassFromTable($strTable); $tplTable = $this->newTemplate('dev_model', $objModule); $tplTable->table = $strTable; $tplTable->class = $strModel; \File::putContent('system/modules/' . $objModule->folder . '/models/' . $strModel . '.php', $tplTable->parse()); } $arrTemplates = array_filter(trimsplit(',', $objModule->feTemplates)); // Templates foreach ($arrTemplates as $strTemplate) { $tplTemplate = $this->newTemplate('dev_feTemplate', $objModule); $objTemplate = new \File('system/modules/' . $objModule->folder . '/templates/' . $strTemplate . '.html5', true); $objTemplate->write($tplTemplate->parse()); $objTemplate->close(); $objTemplate->copyTo('system/modules/' . $objModule->folder . '/templates/' . $strTemplate . '.xhtml'); } } // Language packs if ($objModule->addLanguage) { $arrLanguages = array_filter(trimsplit(',', $objModule->languages)); foreach ($arrLanguages as $strLanguage) { // languages/xx/default.php $tplLanguage = $this->newTemplate('dev_default', $objModule); $tplLanguage->language = $strLanguage; \File::putContent('system/modules/' . $objModule->folder . '/languages/' . $strLanguage . '/default.php', $tplLanguage->parse()); // languages/xx/modules.php $tplLanguage = $this->newTemplate('dev_modules', $objModule); $tplLanguage->language = $strLanguage; \File::putContent('system/modules/' . $objModule->folder . '/languages/' . $strLanguage . '/modules.php', $tplLanguage->parse()); // languages/xx/<table>.php foreach ($arrTables as $strTable) { $tplLanguage = $this->newTemplate('dev_table', $objModule); $tplLanguage->language = $strLanguage; $tplLanguage->table = $strTable; \File::putContent('system/modules/' . $objModule->folder . '/languages/' . $strLanguage . '/' . $strTable . '.php', $tplLanguage->parse()); } } } // Public folder $tplConfig = $this->newTemplate('dev_htaccess', $objModule); \File::putContent('system/modules/' . $objModule->folder . '/assets/.htaccess', $tplConfig->parse()); // Confirm and reload \Message::addConfirmation($GLOBALS['TL_LANG']['tl_extension']['confirm']); $this->reload(); } $this->Template->base = \Environment::get('base'); $this->Template->href = $this->getReferer(true); $this->Template->title = specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']); $this->Template->action = ampersand(\Environment::get('request')); $this->Template->selectAll = $GLOBALS['TL_LANG']['MSC']['selectAll']; $this->Template->button = $GLOBALS['TL_LANG']['MSC']['backBT']; $this->Template->message = \Message::generate(); $this->Template->submit = specialchars($GLOBALS['TL_LANG']['tl_extension']['make'][0]); $this->Template->headline = sprintf($GLOBALS['TL_LANG']['tl_extension']['headline'], \Input::get('id')); $this->Template->explain = $GLOBALS['TL_LANG']['tl_extension']['make'][1]; $this->Template->label = $GLOBALS['TL_LANG']['tl_extension']['label']; }
/** * Handles a file instance while looping an tree of directories. * * @param File $file File object reference * @param int $level Current level of tree parse * @return int State of what to do next can be CONTINUE, ABORT or ABORTFOLDER. */ function handle($file, $level) { $toPath = $this->_destFile->getAbsolutePath(); $toPath .= substr($file->getAbsolutePath(), strlen($this->_fromFile->getAbsolutePath())); $toFile = $this->_manager->getFile($toPath); // Do action if ($file->isDirectory()) { $toFile->mkdir(); } else { $file->copyTo($toFile); } return $this->CONTINUE; }
/** * Generate the autoload.php files */ protected function createAutoloadFiles() { $arrModules = \Input::post('modules'); if (empty($arrModules)) { \Message::addError($GLOBALS['TL_LANG']['tl_autoload']['emptySelection']); return; } $intYear = date('Y'); foreach ($arrModules as $strModule) { // The autoload.php file exists if (!\Input::post('override') && file_exists(TL_ROOT . '/system/modules/' . $strModule . '/config/autoload.php')) { \Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_autoload']['autoloadExists'], $strModule)); continue; } $intClassWidth = 0; $arrFiles = array(); $arrClassLoader = array(); $arrNamespaces = array(); // Default configuration $arrDefaultConfig = array('register_namespaces' => true, 'register_classes' => true, 'register_templates' => true); // Create the autoload.ini file if it does not yet exist if (!file_exists(TL_ROOT . '/system/modules/' . $strModule . '/config/autoload.ini')) { $objIni = new \File('system/modules/devtools/templates/dev_ini.html5', true); $objIni->copyTo('system/modules/' . $strModule . '/config/autoload.ini'); } $arrDefaultConfig = array_merge($arrDefaultConfig, parse_ini_file(TL_ROOT . '/system/modules/' . $strModule . '/config/autoload.ini', true)); /** @var \SplFileInfo[] $objFiles */ $objFiles = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(TL_ROOT . '/system/modules/' . $strModule, \FilesystemIterator::UNIX_PATHS | \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS)); // Get all PHP files foreach ($objFiles as $objFile) { if ($objFile->getExtension() == 'php') { $strRelpath = str_replace(TL_ROOT . '/system/modules/' . $strModule . '/', '', $objFile->getPathname()); if (strncmp($strRelpath, 'assets/', 7) !== 0 && strncmp($strRelpath, 'config/', 7) !== 0 && strncmp($strRelpath, 'dca/', 4) !== 0 && strncmp($strRelpath, 'languages/', 10) !== 0 && strncmp($strRelpath, 'templates/', 10) !== 0) { $arrFiles[] = $strRelpath; } } } // Scan for classes foreach ($arrFiles as $strFile) { $arrConfig = $arrDefaultConfig; // Search for a path configuration (see #4776) foreach ($arrDefaultConfig as $strPattern => $arrPathConfig) { // Merge the path configuration with the global configuration if (is_array($arrPathConfig) && fnmatch($strPattern, $strFile)) { $arrConfig = array_merge($arrDefaultConfig, $arrPathConfig); break; } } // Continue if neither namespaces nor classes shall be registered if (!$arrConfig['register_namespaces'] && !$arrConfig['register_classes']) { continue; } $strBuffer = ''; $arrMatches = array(); // Store the file size for fread() $size = filesize(TL_ROOT . '/system/modules/' . $strModule . '/' . $strFile); $fh = fopen(TL_ROOT . '/system/modules/' . $strModule . '/' . $strFile, 'rb'); // Read until a class or interface definition has been found while (!preg_match('/(class|interface|trait) ' . preg_quote(basename($strFile, '.php'), '/') . '/', $strBuffer, $arrMatches) && $size > 0 && !feof($fh)) { $length = min(512, $size); $strBuffer .= fread($fh, $length); $size -= $length; // see #4876 } fclose($fh); // The file does not contain a class or interface if (empty($arrMatches)) { continue; } $strNamespace = preg_replace('/^.*namespace ([^; ]+);.*$/s', '$1', $strBuffer); // No namespace declaration found if ($strNamespace == $strBuffer) { $strNamespace = ''; } unset($strBuffer); // Register the namespace if ($strNamespace != '') { if ($arrConfig['register_namespaces'] && $strNamespace != 'Contao') { // Register only the first chunk as namespace if (strpos($strNamespace, '\\') !== false) { $arrNamespaces[] = substr($strNamespace, 0, strpos($strNamespace, '\\')); } else { $arrNamespaces[] = $strNamespace; } } $strNamespace .= '\\'; } // Register the class if ($arrConfig['register_classes']) { $strKey = $strNamespace . basename($strFile, '.php'); $arrClassLoader[$strKey] = 'system/modules/' . $strModule . '/' . $strFile; $intClassWidth = max(strlen($strKey), $intClassWidth); } } $intTplWidth = 0; $arrTplLoader = array(); // Scan for templates if (is_dir(TL_ROOT . '/system/modules/' . $strModule . '/templates')) { /** @var \SplFileInfo[] $objFiles */ $objFiles = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(TL_ROOT . '/system/modules/' . $strModule . '/templates', \FilesystemIterator::UNIX_PATHS | \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS)); foreach ($objFiles as $objFile) { $arrConfig = $arrDefaultConfig; $strRelpath = str_replace(TL_ROOT . '/system/modules/' . $strModule . '/', '', $objFile->getPathname()); // Search for a path configuration (see #4776) foreach ($arrDefaultConfig as $strPattern => $arrPathConfig) { // Merge the path configuration with the global configuration if (is_array($arrPathConfig) && fnmatch($strPattern, $strRelpath)) { $arrConfig = array_merge($arrDefaultConfig, $arrPathConfig); break; } } // Continue if templates shall not be registered if (!$arrConfig['register_templates']) { continue; } $arrTplExts = trimsplit(',', strtolower(\Config::get('templateFiles'))); // Add all known template types (see #5857) if (in_array(strtolower($objFile->getExtension()), $arrTplExts)) { $strRelpath = str_replace(TL_ROOT . '/', '', $objFile->getPathname()); $strKey = basename($strRelpath, strrchr($strRelpath, '.')); $arrTplLoader[$strKey] = dirname($strRelpath); $intTplWidth = max(strlen($strKey), $intTplWidth); } } } // Neither classes nor templates found if (empty($arrNamespaces) && empty($arrClassLoader) && empty($arrTplLoader)) { continue; } $objFile = new \File('system/modules/' . $strModule . '/config/autoload.php', true); $objFile->write(<<<EOT <?php /** * Contao Open Source CMS * * Copyright (c) 2005-{$intYear} Leo Feyer * * @license LGPL-3.0+ */ EOT ); // Namespaces if (!empty($arrNamespaces)) { $arrNamespaces = array_unique($arrNamespaces); if (!empty($arrNamespaces)) { $objFile->append(<<<EOT /** * Register the namespaces */ ClassLoader::addNamespaces(array ( EOT ); foreach ($arrNamespaces as $strNamespace) { $objFile->append("\t'" . $strNamespace . "',"); } $objFile->append('));'); } } // Classes if (!empty($arrClassLoader)) { $objFile->append(<<<EOT /** * Register the classes */ ClassLoader::addClasses(array ( EOT ); $strGroup = null; foreach ($arrClassLoader as $strClass => $strPath) { $strRelpath = str_replace('system/modules/' . $strModule . '/', '', $strPath); $strBasedir = substr($strRelpath, 0, strpos($strRelpath, '/')); if ($strBasedir != '') { if ($strGroup === null) { $strGroup = $strBasedir; $objFile->append("\t// " . ucfirst($strBasedir)); } elseif ($strBasedir != $strGroup) { $strGroup = $strBasedir; $objFile->append("\n\t// " . ucfirst($strBasedir)); } } $strClass = "'" . $strClass . "'"; $objFile->append("\t" . str_pad($strClass, $intClassWidth + 2) . " => '{$strPath}',"); } $objFile->append('));'); } // Templates if (!empty($arrTplLoader)) { $objFile->append(<<<EOT /** * Register the templates */ TemplateLoader::addFiles(array ( EOT ); foreach ($arrTplLoader as $strName => $strPath) { $strName = "'" . $strName . "'"; $objFile->append("\t" . str_pad($strName, $intTplWidth + 2) . " => '{$strPath}',"); } $objFile->append('));'); } $objFile->close(); \Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['tl_autoload']['autoloadConfirm'], $strModule)); } }
/** * Purge the temp folder */ public function purgeTempFolder() { // Purge the folder $objFolder = new \Folder('system/tmp'); $objFolder->purge(); // Restore the .gitignore file $objFile = new \File('system/logs/.gitignore', true); $objFile->copyTo('system/tmp/.gitignore'); // Add a log entry $this->log('Purged the temp folder', __METHOD__, TL_CRON); }
protected function createSingleFile($varValue) { if ($this->sourceDir === null || $this->targetDir === null || $varValue == '') { return false; } $objSourceDir = \FilesModel::findByUuid($this->sourceDir); if ($objSourceDir === null) { return false; } $objTargetDir = \FilesModel::findByUuid($this->targetDir); if ($objTargetDir === null) { return false; } $strRelFile = $objSourceDir->path . '/' . ltrim($varValue, '/'); if (is_dir(TL_ROOT . '/' . $strRelFile) || !file_exists(TL_ROOT . '/' . $strRelFile)) { return null; } $objFile = new \File($strRelFile); $objFile->copyTo($objTargetDir->path . '/' . $objFile->name); $objModel = $objFile->getModel(); return $objModel->uuid; }
/** * Purge the temp folder */ public function purgeTempFolder() { // Purge the folder $objFolder = new \Folder('system/tmp'); $objFolder->purge(); // Restore the .htaccess file $objFile = new \File('system/logs/.htaccess'); $objFile->copyTo('system/tmp/.htaccess'); // Add a log entry $this->log('Purged the temp folder', 'Automator purgeTempFolder()', TL_CRON); }
/** * Handles a file instance while looping an tree of directories. * * @param File $file File object reference * @param int $level Current level of tree parse * @return int State of what to do next can be CONTINUE, ABORT or ABORTFOLDER. */ function handle($file, $level) { $toPath = $this->_destFile->getAbsolutePath(); $toPath .= substr($file->getAbsolutePath(), strlen($this->_fromFile->getAbsolutePath())); $toFile = new LocalFileImpl($this->_fileFactory, $toPath); //echo $file->getAbsolutePath() . "->" . $toPath . "<br />"; // Do action if ($file->isDirectory()) { $toFile->mkdir(); } else { $file->copyTo($toFile); } return $this->CONTINUE; }
/** * @param integer * @param string * Bilder aus Verzeichnis auf dem Server in Album einlesen */ public static function importFromFilesystem($intAlbumId, $strMultiSRC) { $images = array(); $objFilesModel = \FilesModel::findMultipleByUuids(explode(',', $strMultiSRC)); if ($objFilesModel === null) { return; } while ($objFilesModel->next()) { // Continue if the file has been processed or does not exist if (isset($images[$objFilesModel->path]) || !file_exists(TL_ROOT . '/' . $objFilesModel->path)) { continue; } // If item is a file, then store it in the array if ($objFilesModel->type == 'file') { $objFile = new \File($objFilesModel->path); if ($objFile->isGdImage) { $images[$objFile->path] = array('uuid' => $objFilesModel->uuid, 'basename' => $objFile->basename, 'path' => $objFile->path); } } else { // If it is a directory, then store its files in the array $objSubfilesModel = \FilesModel::findMultipleFilesByFolder($objFilesModel->path); if ($objSubfilesModel === null) { continue; } while ($objSubfilesModel->next()) { // Skip subfolders if ($objSubfilesModel->type == 'folder' || !is_file(TL_ROOT . '/' . $objSubfilesModel->path)) { continue; } $objFile = new \File($objSubfilesModel->path); if ($objFile->isGdImage) { $images[$objFile->path] = array('uuid' => $objSubfilesModel->uuid, 'basename' => $objFile->basename, 'path' => $objFile->path); } } } } if (count($images)) { $uploadPath = GALLERY_CREATOR_UPLOAD_PATH; $objPictures = \Database::getInstance()->prepare('SELECT * FROM tl_gallery_creator_pictures WHERE pid=?')->execute($intAlbumId); $arrPictures['uuid'] = $objPictures->fetchEach('uuid'); $arrPictures['path'] = $objPictures->fetchEach('path'); foreach ($arrPictures['path'] as $path) { $arrPictures['basename'][] = basename($path); } $objAlb = \MCupic\GalleryCreatorAlbumsModel::findById($intAlbumId); foreach ($images as $image) { // Prevent duplicate entries if (in_array($image['uuid'], $arrPictures['uuid'])) { continue; } // Prevent duplicate entries if (in_array($image['basename'], $arrPictures['basename'])) { continue; } \Input::setGet('importFromFilesystem', 'true'); if ($GLOBALS['TL_CONFIG']['gc_album_import_copy_files']) { $strSource = $image['path']; // Get the album upload directory $objFolderModel = \FilesModel::findByUuid($objAlb->assignedDir); $errMsg = 'Aborted import process, because there is no upload folder assigned to the album with ID ' . $objAlb->id . '.'; if ($objFolderModel === null) { die($errMsg); } if ($objFolderModel->type != 'folder') { die($errMsg); } if (!is_dir(TL_ROOT . '/' . $objFolderModel->path)) { die($errMsg); } $strDestination = self::generateUniqueFilename($objFolderModel->path . '/' . basename($strSource)); if (is_file(TL_ROOT . '/' . $strSource)) { //copy Image to the upload folder $objFile = new \File($strSource); $objFile->copyTo($strDestination); \Dbafs::addResource($strSource); } self::createNewImage($objAlb->id, $strDestination); } else { self::createNewImage($objAlb->id, $image['path']); } } } }
protected function createEnclosures(&$objItem) { if ($this->sourceDir === null || $this->targetDir === null) { return false; } $objSourceDir = \FilesModel::findByUuid($this->sourceDir); if ($objSourceDir === null) { return false; } $objTargetDir = \FilesModel::findByUuid($this->targetDir); if ($objTargetDir === null) { return false; } $arrSource = deserialize($objItem->enclosure, true); $arrTarget = array(); foreach ($arrSource as $strFile) { $strRelFile = $objSourceDir->path . '/' . ltrim($strFile, '/'); if (is_dir(TL_ROOT . '/' . $strRelFile) || !file_exists(TL_ROOT . '/' . $strRelFile)) { continue; } $objFile = new \File($strRelFile); $objFile->copyTo($objTargetDir->path . '/' . $objFile->name); $objModel = $objFile->getModel(); $arrTarget[] = $objModel->uuid; } if (!empty($arrTarget)) { $objItem->addEnclosure = true; $objItem->enclosure = $arrTarget; } }
/** * @param $source * @param $destination * * @return mixed */ protected function copyTemplateInRootTemplates($source, $destination) { $sourceFile = new \File('templates/' . $source . '.html5'); $sourceFile->copyTo('templates/' . $destination . '.html5'); return $destination; }
<?php apd_set_pprof_trace(); require_once '../../lib/base/boot.php'; $f = new File(__FILE__); var_dump($f->isDir()); var_dump($f->isFile()); $f->copyTo('/tmp/test'); #$t = getrusage(); #$t = doubleval($t['ru_utime.tv_sec']*1000) + doubleval($t['ru_utime.tv_usec']/1000000); #printf("User time: %f", $t);