/** * Generate the Google XML sitemaps * * @param integer $intId The root page ID */ public function generateSitemap($intId = 0) { $time = \Date::floorToMinute(); $objDatabase = \Database::getInstance(); $this->purgeXmlFiles(); // Only root pages should have sitemap names $objDatabase->execute("UPDATE tl_page SET createSitemap='', sitemapName='' WHERE type!='root'"); // Get a particular root page if ($intId > 0) { do { $objRoot = $objDatabase->prepare("SELECT * FROM tl_page WHERE id=?")->limit(1)->execute($intId); if ($objRoot->numRows < 1) { break; } $intId = $objRoot->pid; } while ($objRoot->type != 'root' && $intId > 0); // Make sure the page is published if (!$objRoot->published || $objRoot->start != '' && $objRoot->start > $time || $objRoot->stop != '' && $objRoot->stop <= $time + 60) { return; } // Check the sitemap name if (!$objRoot->createSitemap || !$objRoot->sitemapName) { return; } $objRoot->reset(); } else { $objRoot = $objDatabase->execute("SELECT id, language, sitemapName FROM tl_page WHERE type='root' AND createSitemap='1' AND sitemapName!='' AND (start='' OR start<='{$time}') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1'"); } // Return if there are no pages if ($objRoot->numRows < 1) { return; } // Create the XML file while ($objRoot->next()) { $objFile = new \File('web/share/' . $objRoot->sitemapName . '.xml'); $objFile->truncate(); $objFile->append('<?xml version="1.0" encoding="UTF-8"?>'); $objFile->append('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'); // Find the searchable pages $arrPages = \Backend::findSearchablePages($objRoot->id, '', true); // HOOK: take additional pages if (isset($GLOBALS['TL_HOOKS']['getSearchablePages']) && is_array($GLOBALS['TL_HOOKS']['getSearchablePages'])) { foreach ($GLOBALS['TL_HOOKS']['getSearchablePages'] as $callback) { $this->import($callback[0]); $arrPages = $this->{$callback[0]}->{$callback[1]}($arrPages, $objRoot->id, true, $objRoot->language); } } // Add pages foreach ($arrPages as $strUrl) { $strUrl = rawurlencode($strUrl); $strUrl = str_replace(array('%2F', '%3F', '%3D', '%26', '%3A//'), array('/', '?', '=', '&', '://'), $strUrl); $strUrl = ampersand($strUrl, true); $objFile->append(' <url><loc>' . $strUrl . '</loc></url>'); } $objFile->append('</urlset>'); $objFile->close(); // Add a log entry $this->log('Generated sitemap "' . $objRoot->sitemapName . '.xml"', __METHOD__, TL_CRON); } }
/** * Generate the combined file and return its path * * @param string $strUrl An optional URL to prepend * * @return string The path to the combined file */ public function getCombinedFile($strUrl = null) { if ($strUrl === null) { $strUrl = TL_ASSETS_URL; } $strTarget = substr($this->strMode, 1); $strKey = substr(md5($this->strKey), 0, 12); // Do not combine the files in debug mode (see #6450) if (\Config::get('debugMode')) { $return = array(); foreach ($this->arrFiles as $arrFile) { $content = file_get_contents(TL_ROOT . '/' . $arrFile['name']); // Compile SCSS/LESS files into temporary files if ($arrFile['extension'] == self::SCSS || $arrFile['extension'] == self::LESS) { $strPath = 'assets/' . $strTarget . '/' . str_replace('/', '_', $arrFile['name']) . $this->strMode; $objFile = new \File($strPath, true); $objFile->write($this->handleScssLess($content, $arrFile)); $objFile->close(); $return[] = $strPath; } else { $name = $arrFile['name']; // Add the media query (see #7070) if ($arrFile['media'] != '' && $arrFile['media'] != 'all' && strpos($content, '@media') === false) { $name .= '" media="' . $arrFile['media']; } $return[] = $name; } } if ($this->strMode == self::JS) { return implode('"></script><script src="', $return); } else { return implode('"><link rel="stylesheet" href="', $return); } } // Load the existing file if (file_exists(TL_ROOT . '/assets/' . $strTarget . '/' . $strKey . $this->strMode)) { return $strUrl . 'assets/' . $strTarget . '/' . $strKey . $this->strMode; } // Create the file $objFile = new \File('assets/' . $strTarget . '/' . $strKey . $this->strMode, true); $objFile->truncate(); foreach ($this->arrFiles as $arrFile) { $content = file_get_contents(TL_ROOT . '/' . $arrFile['name']); // HOOK: modify the file content if (isset($GLOBALS['TL_HOOKS']['getCombinedFile']) && is_array($GLOBALS['TL_HOOKS']['getCombinedFile'])) { foreach ($GLOBALS['TL_HOOKS']['getCombinedFile'] as $callback) { $this->import($callback[0]); $content = $this->{$callback}[0]->{$callback}[1]($content, $strKey, $this->strMode, $arrFile); } } if ($arrFile['extension'] == self::CSS) { $content = $this->handleCss($content, $arrFile); } elseif ($arrFile['extension'] == self::SCSS || $arrFile['extension'] == self::LESS) { $content = $this->handleScssLess($content, $arrFile); } $objFile->append($content); } unset($content); $objFile->close(); // Create a gzipped version if (\Config::get('gzipScripts') && function_exists('gzencode')) { \File::putContent('assets/' . $strTarget . '/' . $strKey . $this->strMode . '.gz', gzencode(file_get_contents(TL_ROOT . '/assets/' . $strTarget . '/' . $strKey . $this->strMode), 9)); } return $strUrl . 'assets/' . $strTarget . '/' . $strKey . $this->strMode; }
/** * Generate the combined file and return its path * * @param string $strUrl An optional URL to prepend * * @return string The path to the combined file */ protected function getCombinedFileUrl($strUrl = null) { if ($strUrl === null) { $strUrl = TL_ASSETS_URL; } $strTarget = substr($this->strMode, 1); $strKey = substr(md5($this->strKey), 0, 12); // Load the existing file if (file_exists(TL_ROOT . '/assets/' . $strTarget . '/' . $strKey . $this->strMode)) { return $strUrl . 'assets/' . $strTarget . '/' . $strKey . $this->strMode; } // Create the file $objFile = new \File('assets/' . $strTarget . '/' . $strKey . $this->strMode); $objFile->truncate(); foreach ($this->arrFiles as $arrFile) { $content = file_get_contents(TL_ROOT . '/' . $arrFile['name']); // HOOK: modify the file content if (isset($GLOBALS['TL_HOOKS']['getCombinedFile']) && is_array($GLOBALS['TL_HOOKS']['getCombinedFile'])) { foreach ($GLOBALS['TL_HOOKS']['getCombinedFile'] as $callback) { $this->import($callback[0]); $content = $this->{$callback[0]}->{$callback[1]}($content, $strKey, $this->strMode, $arrFile); } } if ($arrFile['extension'] == self::CSS) { $content = $this->handleCss($content, $arrFile); } elseif ($arrFile['extension'] == self::SCSS || $arrFile['extension'] == self::LESS) { $content = $this->handleScssLess($content, $arrFile); } $objFile->append($content); } unset($content); $objFile->close(); // Create a gzipped version if (\Config::get('gzipScripts') && function_exists('gzencode')) { \File::putContent('assets/' . $strTarget . '/' . $strKey . $this->strMode . '.gz', gzencode(file_get_contents(TL_ROOT . '/assets/' . $strTarget . '/' . $strKey . $this->strMode), 9)); } return $strUrl . 'assets/' . $strTarget . '/' . $strKey . $this->strMode; }
/** * Set the video image * * @param string $key * @param string $content */ public function setImage($key, $content) { $folder = new Folder(static::$imagesFolder); // Create the .htaccess file so images are accessible if (!is_file(TL_ROOT . '/' . $folder->path . '/.htaccess')) { $htaccessFile = new File($folder->path . '/.htaccess'); $htaccessFile->write("<IfModule !mod_authz_core.c>\r\nOrder allow,deny\r\nAllow from all\r\n</IfModule>\r\n<IfModule mod_authz_core.c>\r\n Require all granted\r\n</IfModule>"); $htaccessFile->close(); } $file = new \File($this->getImageFilePath($key)); $file->truncate(); $file->write($content); $file->close(); }
private function compileModule($parameters, $bridgeNamespace, $module) { $file = new File($parameters['path'], true); $file->truncate(); $file->putContent($parameters['path'], '<?php ' . "\n" . "\n" . '/**' . "\n" . ' * DESCRIPTION' . "\n" . ' *' . "\n" . ' * Copyright (C) ORGANISE' . "\n" . ' *' . "\n" . ' * @package PACKAGE NAME' . "\n" . ' * @file ' . $module . '.php' . "\n" . ' * @author AUTHOR' . "\n" . ' * @license GNU/LGPL' . "\n" . ' * @copyright Copyright ' . Date::parse('Y', time()) . ' ORGANISE' . "\n" . ' */' . "\n" . "\n" . "\n" . 'namespace ' . $bridgeNamespace . ';' . "\n" . "\n" . 'class ' . $module . ' extends \\' . $bridgeNamespace . 'Bridge\\' . $module . "\n" . '{' . "\n" . '}'); }