/** * @param \Closure|array $callback * @param array $args * * @return mixed */ private function executeCallback($callback, array $args) { // Support Contao's getInstance() method when callback is an array if (is_array($callback)) { return call_user_func_array([System::importStatic($callback[0]), $callback[1]], $args); } return call_user_func_array($callback, $args); }
/** * {@inheritdoc} */ protected function executeResize(ImageInterface $image, ResizeCoordinatesInterface $coordinates, $path, ResizeOptionsInterface $options) { if (isset($GLOBALS['TL_HOOKS']['getImage']) && is_array($GLOBALS['TL_HOOKS']['getImage']) && $this->legacyImage) { foreach ($GLOBALS['TL_HOOKS']['getImage'] as $callback) { $return = System::importStatic($callback[0])->{$callback[1]}($this->legacyImage->getOriginalPath(), $this->legacyImage->getTargetWidth(), $this->legacyImage->getTargetHeight(), $this->legacyImage->getResizeMode(), $this->legacyImage->getCacheName(), new File($this->legacyImage->getOriginalPath()), $this->legacyImage->getTargetPath(), $this->legacyImage); if (is_string($return)) { return $this->createImage($image, TL_ROOT . '/' . $return); } } } if ($image->getImagine() instanceof GdImagine) { /** @var Config $config */ $config = $this->framework->getAdapter(Config::class); $dimensions = $image->getDimensions(); // Return the path to the original image if it cannot be handled if ($dimensions->getSize()->getWidth() > $config->get('gdMaxImgWidth') || $dimensions->getSize()->getHeight() > $config->get('gdMaxImgHeight') || $coordinates->getSize()->getWidth() > $config->get('gdMaxImgWidth') || $coordinates->getSize()->getHeight() > $config->get('gdMaxImgHeight')) { return $this->createImage($image, $image->getPath()); } } return parent::executeResize($image, $coordinates, $path, $options); }
/** * Modifies a URL from the URL generator. * * @param string $strUrl * @param string $strParams * * @return string */ private function applyLegacyLogic($strUrl, $strParams) { // Decode sprintf placeholders if (strpos($strParams, '%') !== false) { @trigger_error('Using sprintf placeholders in URLs has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED); $arrMatches = array(); preg_match_all('/%([sducoxXbgGeEfF])/', $strParams, $arrMatches); foreach (array_unique($arrMatches[1]) as $v) { $strUrl = str_replace('%25' . $v, '%' . $v, $strUrl); } } // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['generateFrontendUrl']) && is_array($GLOBALS['TL_HOOKS']['generateFrontendUrl'])) { @trigger_error('Using the "generateFrontendUrl" hook has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED); foreach ($GLOBALS['TL_HOOKS']['generateFrontendUrl'] as $callback) { $strUrl = \System::importStatic($callback[0])->{$callback[1]}($this->row(), $strParams, $strUrl); } return $strUrl; } return $strUrl; }
/** * Triggers the initializeSystem hook (see #5665). */ private function triggerInitializeSystemHook() { if (isset($GLOBALS['TL_HOOKS']['initializeSystem']) && is_array($GLOBALS['TL_HOOKS']['initializeSystem'])) { foreach ($GLOBALS['TL_HOOKS']['initializeSystem'] as $callback) { System::importStatic($callback[0])->{$callback}[1](); } } if (file_exists($this->rootDir . '/system/config/initconfig.php')) { include $this->rootDir . '/system/config/initconfig.php'; } }
/** * Return the system messages as HTML * * @return string The messages HTML markup */ public static function getSystemMessages() { $strMessages = ''; // HOOK: add custom messages if (isset($GLOBALS['TL_HOOKS']['getSystemMessages']) && is_array($GLOBALS['TL_HOOKS']['getSystemMessages'])) { $arrMessages = array(); foreach ($GLOBALS['TL_HOOKS']['getSystemMessages'] as $callback) { $strBuffer = \System::importStatic($callback[0])->{$callback[1]}(); if ($strBuffer != '') { $arrMessages[] = $strBuffer; } } if (!empty($arrMessages)) { $strMessages .= implode("\n", $arrMessages); } } return $strMessages; }
/** * Check whether there is a cached version of the page and return a response object * * @return Response|null */ public static function getResponseFromCache() { // Build the page if a user is (potentially) logged in or there is POST data if (!empty($_POST) || \Input::cookie('BE_USER_AUTH') || \Input::cookie('FE_USER_AUTH') || \Input::cookie('FE_AUTO_LOGIN') || $_SESSION['DISABLE_CACHE'] || isset($_SESSION['LOGIN_ERROR']) || \Message::hasMessages() || \Config::get('debugMode')) { return null; } $strCacheDir = \System::getContainer()->getParameter('kernel.cache_dir'); // Try to map the empty request if (\Environment::get('relativeRequest') == '') { // Return if the language is added to the URL and the empty domain will be redirected if (\Config::get('addLanguageToUrl') && !\Config::get('doNotRedirectEmpty')) { return null; } $strCacheKey = null; $arrLanguage = \Environment::get('httpAcceptLanguage'); $strMappingFile = $strCacheDir . '/contao/config/mapping.php'; // Try to get the cache key from the mapper array if (file_exists($strMappingFile)) { $arrMapper = (include $strMappingFile); $arrPaths = array(\Environment::get('host'), '*'); // Try the language specific keys foreach ($arrLanguage as $strLanguage) { foreach ($arrPaths as $strPath) { $strKey = $strPath . '/empty.' . $strLanguage; if (isset($arrMapper[$strKey])) { $strCacheKey = $arrMapper[$strKey]; break; } } } // Try the fallback key if ($strCacheKey === null) { foreach ($arrPaths as $strPath) { $strKey = $strPath . '/empty.fallback'; if (isset($arrMapper[$strKey])) { $strCacheKey = $arrMapper[$strKey]; break; } } } } // Fall back to the first accepted language if ($strCacheKey === null) { $strCacheKey = \Environment::get('host') . '/empty.' . $arrLanguage[0]; } } else { $strCacheKey = \Environment::get('host') . '/' . \Environment::get('relativeRequest'); } // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['getCacheKey']) && is_array($GLOBALS['TL_HOOKS']['getCacheKey'])) { foreach ($GLOBALS['TL_HOOKS']['getCacheKey'] as $callback) { $strCacheKey = \System::importStatic($callback[0])->{$callback[1]}($strCacheKey); } } $blnFound = false; $strCacheFile = null; // Check for a mobile layout if (\Input::cookie('TL_VIEW') == 'mobile' || \Environment::get('agent')->mobile && \Input::cookie('TL_VIEW') != 'desktop') { $strMd5CacheKey = md5($strCacheKey . '.mobile'); $strCacheFile = $strCacheDir . '/contao/html/' . substr($strMd5CacheKey, 0, 1) . '/' . $strMd5CacheKey . '.html'; if (file_exists($strCacheFile)) { $blnFound = true; } } else { $strMd5CacheKey = md5($strCacheKey . '.desktop'); $strCacheFile = $strCacheDir . '/contao/html/' . substr($strMd5CacheKey, 0, 1) . '/' . $strMd5CacheKey . '.html'; if (file_exists($strCacheFile)) { $blnFound = true; } } // Check for a regular layout if (!$blnFound) { $strMd5CacheKey = md5($strCacheKey); $strCacheFile = $strCacheDir . '/contao/html/' . substr($strMd5CacheKey, 0, 1) . '/' . $strMd5CacheKey . '.html'; if (file_exists($strCacheFile)) { $blnFound = true; } } // Return if the file does not exist if (!$blnFound) { return null; } $expire = null; $content = null; $type = null; $files = null; $assets = null; // Include the file ob_start(); require_once $strCacheFile; // The file has expired if ($expire < time()) { ob_end_clean(); return null; } // Define the static URL constants (see #7914) define('TL_FILES_URL', $files); define('TL_ASSETS_URL', $assets); // Read the buffer $strBuffer = ob_get_clean(); /** @var AttributeBagInterface $session */ $session = \System::getContainer()->get('session')->getBag('contao_frontend'); // Session required to determine the referer $data = $session->all(); // Set the new referer if (!isset($_GET['pdf']) && !isset($_GET['file']) && !isset($_GET['id']) && $data['referer']['current'] != \Environment::get('requestUri')) { $data['referer']['last'] = $data['referer']['current']; $data['referer']['current'] = substr(\Environment::get('requestUri'), strlen(\Environment::get('path')) + 1); } // Store the session data $session->replace($data); // Load the default language file (see #2644) \System::loadLanguageFile('default'); // Replace the insert tags and then re-replace the request_token tag in case a form element has been loaded via insert tag $strBuffer = \Controller::replaceInsertTags($strBuffer, false); $strBuffer = str_replace(array('{{request_token}}', '[{]', '[}]'), array(REQUEST_TOKEN, '{{', '}}'), $strBuffer); // HOOK: allow to modify the compiled markup (see #4291 and #7457) if (isset($GLOBALS['TL_HOOKS']['modifyFrontendPage']) && is_array($GLOBALS['TL_HOOKS']['modifyFrontendPage'])) { foreach ($GLOBALS['TL_HOOKS']['modifyFrontendPage'] as $callback) { $strBuffer = \System::importStatic($callback[0])->{$callback[1]}($strBuffer, null); } } // Content type if (!$content) { $content = 'text/html'; } $response = new Response($strBuffer); // Send the status header (see #6585) if ($type == 'error_403') { $response->setStatusCode(Response::HTTP_FORBIDDEN); } elseif ($type == 'error_404') { $response->setStatusCode(Response::HTTP_NOT_FOUND); } $response->headers->set('Vary', 'User-Agent', false); $response->headers->set('Content-Type', $content . '; charset=' . \Config::get('characterSet')); // Send the cache headers if ($expire !== null && (\Config::get('cacheMode') == 'both' || \Config::get('cacheMode') == 'browser')) { $response->headers->set('Cache-Control', 'public, max-age=' . ($expire - time())); $response->headers->set('Pragma', 'public'); $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s', time()) . ' GMT'); $response->headers->set('Expires', gmdate('D, d M Y H:i:s', $expire) . ' GMT'); } else { $response->headers->set('Cache-Control', 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); $response->headers->set('Pragma', 'no-cache'); $response->headers->set('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT'); $response->headers->set('Expires', 'Fri, 06 Jun 1975 15:10:00 GMT'); } return $response; }
/** * Export a theme * * @param DataContainer $dc */ public function exportTheme(DataContainer $dc) { // Get the theme meta data $objTheme = $this->Database->prepare("SELECT * FROM tl_theme WHERE id=?")->limit(1)->execute($dc->id); if ($objTheme->numRows < 1) { return; } // Romanize the name $strName = Utf8::toAscii($objTheme->name); $strName = strtolower(str_replace(' ', '_', $strName)); $strName = preg_replace('/[^A-Za-z0-9._-]/', '', $strName); $strName = basename($strName); // Create a new XML document $xml = new \DOMDocument('1.0', 'UTF-8'); $xml->formatOutput = true; // Root element $tables = $xml->createElement('tables'); $tables = $xml->appendChild($tables); // Add the tables $this->addTableTlTheme($xml, $tables, $objTheme); $this->addTableTlStyleSheet($xml, $tables, $objTheme); $this->addTableTlImageSize($xml, $tables, $objTheme); $this->addTableTlModule($xml, $tables, $objTheme); $this->addTableTlLayout($xml, $tables, $objTheme); // Generate the archive $strTmp = md5(uniqid(mt_rand(), true)); $objArchive = new \ZipWriter('system/tmp/' . $strTmp); // Add the files $this->addTableTlFiles($xml, $tables, $objTheme, $objArchive); // Add the template files $this->addTemplatesToArchive($objArchive, $objTheme->templates); // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['exportTheme']) && is_array($GLOBALS['TL_HOOKS']['exportTheme'])) { foreach ($GLOBALS['TL_HOOKS']['exportTheme'] as $callback) { \System::importStatic($callback[0])->{$callback[1]}($xml, $objArchive, $objTheme->id); } } // Add the XML document $objArchive->addString($xml->saveXML(), 'theme.xml'); // Close the archive $objArchive->close(); // Open the "save as …" dialogue $objFile = new \File('system/tmp/' . $strTmp); $objFile->sendToBrowser($strName . '.cto'); }
/** * Import files from selected folder * * @param string $strPath */ protected function importFromPath($strPath) { $arrFiles = scan(TL_ROOT . '/' . $strPath); if (empty($arrFiles)) { Message::addError($GLOBALS['TL_LANG']['MSC']['noFilesInFolder']); Controller::reload(); } $blnEmpty = true; $arrDelete = array(); $objProducts = \Database::getInstance()->prepare("SELECT * FROM tl_iso_product WHERE pid=0")->execute(); while ($objProducts->next()) { $arrImageNames = array(); $arrImages = deserialize($objProducts->images); if (!is_array($arrImages)) { $arrImages = array(); } else { foreach ($arrImages as $row) { if ($row['src']) { $arrImageNames[] = $row['src']; } } } $arrPattern = array(); $arrPattern[] = $objProducts->alias ? standardize($objProducts->alias) : null; $arrPattern[] = $objProducts->sku ? $objProducts->sku : null; $arrPattern[] = $objProducts->sku ? standardize($objProducts->sku) : null; $arrPattern[] = !empty($arrImageNames) ? implode('|', $arrImageNames) : null; // !HOOK: add custom import regex patterns if (isset($GLOBALS['ISO_HOOKS']['addAssetImportRegexp']) && is_array($GLOBALS['ISO_HOOKS']['addAssetImportRegexp'])) { foreach ($GLOBALS['ISO_HOOKS']['addAssetImportRegexp'] as $callback) { $objCallback = System::importStatic($callback[0]); $arrPattern = $objCallback->{$callback}[1]($arrPattern, $objProducts); } } $strPattern = '@^(' . implode('|', array_filter($arrPattern)) . ')@i'; $arrMatches = preg_grep($strPattern, $arrFiles); if (!empty($arrMatches)) { $arrNewImages = array(); foreach ($arrMatches as $file) { if (is_dir(TL_ROOT . '/' . $strPath . '/' . $file)) { $arrSubfiles = scan(TL_ROOT . '/' . $strPath . '/' . $file); if (!empty($arrSubfiles)) { foreach ($arrSubfiles as $subfile) { if (is_file($strPath . '/' . $file . '/' . $subfile)) { $objFile = new File($strPath . '/' . $file . '/' . $subfile); if ($objFile->isGdImage) { $arrNewImages[] = $strPath . '/' . $file . '/' . $subfile; } } } } } elseif (is_file(TL_ROOT . '/' . $strPath . '/' . $file)) { $objFile = new \File($strPath . '/' . $file); if ($objFile->isGdImage) { $arrNewImages[] = $strPath . '/' . $file; } } } if (!empty($arrNewImages)) { foreach ($arrNewImages as $strFile) { $pathinfo = pathinfo(TL_ROOT . '/' . $strFile); // Will recursively create the folder $objFolder = new \Folder('isotope/' . strtolower(substr($pathinfo['filename'], 0, 1))); $strCacheName = $pathinfo['filename'] . '-' . substr(md5_file(TL_ROOT . '/' . $strFile), 0, 8) . '.' . $pathinfo['extension']; \Files::getInstance()->copy($strFile, $objFolder->path . '/' . $strCacheName); $arrImages[] = array('src' => $strCacheName); $arrDelete[] = $strFile; Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['MSC']['assetImportConfirmation'], $pathinfo['filename'] . '.' . $pathinfo['extension'], $objProducts->name)); $blnEmpty = false; } \Database::getInstance()->prepare("UPDATE tl_iso_product SET images=? WHERE id=?")->execute(serialize($arrImages), $objProducts->id); } } } if (!empty($arrDelete)) { $arrDelete = array_unique($arrDelete); foreach ($arrDelete as $file) { \Files::getInstance()->delete($file); } } if ($blnEmpty) { \Message::addInfo($GLOBALS['TL_LANG']['MSC']['assetImportNoFilesFound']); } \Controller::reload(); }
/** * Triggers the initializeSystem hook (see #5665). */ private function triggerInitializeSystemHook() { if (isset($GLOBALS['TL_HOOKS']['initializeSystem']) && is_array($GLOBALS['TL_HOOKS']['initializeSystem'])) { foreach ($GLOBALS['TL_HOOKS']['initializeSystem'] as $callback) { System::importStatic($callback[0])->{$callback[1]}(); } } if (file_exists($this->rootDir . '/../system/config/initconfig.php')) { @trigger_error('Using the initconfig.php file has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED); include $this->rootDir . '/../system/config/initconfig.php'; } }
/** * Fetch the matching items * * @param array $newsArchives * @param boolean $blnFeatured * @param integer $limit * @param integer $offset * * @return Model\Collection|NewsModel|null */ protected function fetchItems($newsArchives, $blnFeatured, $limit, $offset) { // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['newsListFetchItems']) && is_array($GLOBALS['TL_HOOKS']['newsListFetchItems'])) { foreach ($GLOBALS['TL_HOOKS']['newsListFetchItems'] as $callback) { if (($objCollection = \System::importStatic($callback[0])->{$callback[1]}($newsArchives, $blnFeatured, $limit, $offset, $this)) === false) { continue; } if ($objCollection === null || $objCollection instanceof Model\Collection) { return $objCollection; } } } return \NewsModel::findPublishedByPids($newsArchives, $blnFeatured, $limit, $offset); }
/** * Index a page * * @param array $arrData The data array * * @return boolean True if a new record was created */ public static function indexPage($arrData) { $objDatabase = \Database::getInstance(); $arrSet['tstamp'] = time(); $arrSet['url'] = $arrData['url']; $arrSet['title'] = $arrData['title']; $arrSet['protected'] = $arrData['protected']; $arrSet['filesize'] = $arrData['filesize']; $arrSet['groups'] = $arrData['groups']; $arrSet['pid'] = $arrData['pid']; $arrSet['language'] = $arrData['language']; // Get the file size from the raw content if (!$arrSet['filesize']) { $arrSet['filesize'] = number_format(strlen($arrData['content']) / 1024, 2, '.', ''); } // Replace special characters $strContent = str_replace(array("\n", "\r", "\t", ' ', ' ', '­'), array(' ', ' ', ' ', ' ', ' ', ''), $arrData['content']); // Strip script tags while (($intStart = strpos($strContent, '<script')) !== false) { if (($intEnd = strpos($strContent, '</script>', $intStart)) !== false) { $strContent = substr($strContent, 0, $intStart) . substr($strContent, $intEnd + 9); } else { break; // see #5119 } } // Strip style tags while (($intStart = strpos($strContent, '<style')) !== false) { if (($intEnd = strpos($strContent, '</style>', $intStart)) !== false) { $strContent = substr($strContent, 0, $intStart) . substr($strContent, $intEnd + 8); } else { break; // see #5119 } } // Strip non-indexable areas while (($intStart = strpos($strContent, '<!-- indexer::stop -->')) !== false) { if (($intEnd = strpos($strContent, '<!-- indexer::continue -->', $intStart)) !== false) { $intCurrent = $intStart; // Handle nested tags while (($intNested = strpos($strContent, '<!-- indexer::stop -->', $intCurrent + 22)) !== false && $intNested < $intEnd) { if (($intNewEnd = strpos($strContent, '<!-- indexer::continue -->', $intEnd + 26)) !== false) { $intEnd = $intNewEnd; $intCurrent = $intNested; } else { break; // see #5119 } } $strContent = substr($strContent, 0, $intStart) . substr($strContent, $intEnd + 26); } else { break; // see #5119 } } // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['indexPage']) && is_array($GLOBALS['TL_HOOKS']['indexPage'])) { foreach ($GLOBALS['TL_HOOKS']['indexPage'] as $callback) { \System::importStatic($callback[0])->{$callback[1]}($strContent, $arrData, $arrSet); } } // Free the memory unset($arrData['content']); $arrMatches = array(); preg_match('/<\\/head>/', $strContent, $arrMatches, PREG_OFFSET_CAPTURE); $intOffset = strlen($arrMatches[0][0]) + $arrMatches[0][1]; // Split page in head and body section $strHead = substr($strContent, 0, $intOffset); $strBody = substr($strContent, $intOffset); unset($strContent); $tags = array(); // Get the description if (preg_match('/<meta[^>]+name="description"[^>]+content="([^"]*)"[^>]*>/i', $strHead, $tags)) { $arrData['description'] = trim(preg_replace('/ +/', ' ', \StringUtil::decodeEntities($tags[1]))); } // Get the keywords if (preg_match('/<meta[^>]+name="keywords"[^>]+content="([^"]*)"[^>]*>/i', $strHead, $tags)) { $arrData['keywords'] = trim(preg_replace('/ +/', ' ', \StringUtil::decodeEntities($tags[1]))); } // Read the title and alt attributes if (preg_match_all('/<* (title|alt)="([^"]*)"[^>]*>/i', $strBody, $tags)) { $arrData['keywords'] .= ' ' . implode(', ', array_unique($tags[2])); } // Add a whitespace character before line-breaks and between consecutive tags (see #5363) $strBody = str_ireplace(array('<br', '><'), array(' <br', '> <'), $strBody); $strBody = strip_tags($strBody); // Put everything together $arrSet['text'] = $arrData['title'] . ' ' . $arrData['description'] . ' ' . $strBody . ' ' . $arrData['keywords']; $arrSet['text'] = trim(preg_replace('/ +/', ' ', \StringUtil::decodeEntities($arrSet['text']))); // Calculate the checksum $arrSet['checksum'] = md5($arrSet['text']); $objIndex = $objDatabase->prepare("SELECT id, url FROM tl_search WHERE checksum=? AND pid=?")->limit(1)->execute($arrSet['checksum'], $arrSet['pid']); // Update the URL if the new URL is shorter or the current URL is not canonical if ($objIndex->numRows && $objIndex->url != $arrSet['url']) { if (strpos($arrSet['url'], '?') === false && strpos($objIndex->url, '?') !== false) { // the new URL is more canonical (no query string) } elseif (substr_count($arrSet['url'], '/') > substr_count($objIndex->url, '/') || strpos($arrSet['url'], '?') !== false && strpos($objIndex->url, '?') === false || strlen($arrSet['url']) > strlen($objIndex->url)) { $arrSet['url'] = $objIndex->url; // the current URL is more canonical (shorter and/or less fragments) } else { return false; // the same page has been indexed under a different URL already (see #8460) } } $objIndex = $objDatabase->prepare("SELECT id FROM tl_search WHERE url=? AND pid=?")->limit(1)->execute($arrSet['url'], $arrSet['pid']); // Add the page to the tl_search table if ($objIndex->numRows) { $objDatabase->prepare("UPDATE tl_search %s WHERE id=?")->set($arrSet)->execute($objIndex->id); $intInsertId = $objIndex->id; } else { $objInsertStmt = $objDatabase->prepare("INSERT INTO tl_search %s")->set($arrSet)->execute(); $intInsertId = $objInsertStmt->insertId; } // Remove quotes $strText = str_replace(array('´', '`'), "'", $arrSet['text']); unset($arrSet); // Remove special characters $strText = preg_replace(array('/- /', '/ -/', "/' /", "/ '/", '/\\. /', '/\\.$/', '/: /', '/:$/', '/, /', '/,$/', '/[^\\w\'.:,+-]/u'), ' ', $strText); // Split words $arrWords = preg_split('/ +/', Utf8::strtolower($strText)); $arrIndex = array(); // Index words foreach ($arrWords as $strWord) { // Strip a leading plus (see #4497) if (strncmp($strWord, '+', 1) === 0) { $strWord = substr($strWord, 1); } $strWord = trim($strWord); if (!strlen($strWord) || preg_match('/^[\\.:,\'_-]+$/', $strWord)) { continue; } if (preg_match('/^[\':,]/', $strWord)) { $strWord = substr($strWord, 1); } if (preg_match('/[\':,.]$/', $strWord)) { $strWord = substr($strWord, 0, -1); } if (isset($arrIndex[$strWord])) { $arrIndex[$strWord]++; continue; } $arrIndex[$strWord] = 1; } // Remove existing index $objDatabase->prepare("DELETE FROM tl_search_index WHERE pid=?")->execute($intInsertId); // Create new index foreach ($arrIndex as $k => $v) { $objDatabase->prepare("INSERT INTO tl_search_index (pid, word, relevance, language) VALUES (?, ?, ?, ?)")->execute($intInsertId, $k, $v, $arrData['language']); } return true; }
/** * Resize the image * * @return $this The image object */ public function executeResize() { $image = $this->prepareImage(); $resizeConfig = $this->prepareResizeConfig(); if (!System::getContainer()->getParameter('contao.image.bypass_cache') && $this->getTargetPath() && !$this->getForceOverride() && file_exists(TL_ROOT . '/' . $this->getTargetPath()) && $this->fileObj->mtime <= filemtime(TL_ROOT . '/' . $this->getTargetPath())) { // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['executeResize']) && is_array($GLOBALS['TL_HOOKS']['executeResize'])) { foreach ($GLOBALS['TL_HOOKS']['executeResize'] as $callback) { $return = \System::importStatic($callback[0])->{$callback[1]}($this); if (is_string($return)) { $this->resizedPath = \System::urlEncode($return); return $this; } } } $this->resizedPath = \System::urlEncode($this->getTargetPath()); return $this; } $image = \System::getContainer()->get('contao.image.resizer')->resize($image, $resizeConfig, (new ResizeOptions())->setImagineOptions(\System::getContainer()->getParameter('contao.image.imagine_options'))->setTargetPath($this->targetPath ? TL_ROOT . '/' . $this->targetPath : null)->setBypassCache(\System::getContainer()->getParameter('contao.image.bypass_cache'))); $this->resizedPath = $image->getPath(); if (strpos($this->resizedPath, TL_ROOT . '/') === 0 || strpos($this->resizedPath, TL_ROOT . '\\') === 0) { $this->resizedPath = substr($this->resizedPath, strlen(TL_ROOT) + 1); } $this->resizedPath = \System::urlEncode($this->resizedPath); return $this; }
/** * Returns false if navigation item should be skipped * * @param NavigationItem $navigationItem * @param UrlParameterBag $urlParameterBag * * @return bool */ protected function executeHook(NavigationItem $navigationItem, UrlParameterBag $urlParameterBag) { // HOOK: allow extensions to modify url parameters if (isset($GLOBALS['TL_HOOKS']['changelanguageNavigation']) && is_array($GLOBALS['TL_HOOKS']['changelanguageNavigation'])) { $event = new ChangelanguageNavigationEvent($navigationItem, $urlParameterBag); foreach ($GLOBALS['TL_HOOKS']['changelanguageNavigation'] as $callback) { System::importStatic($callback[0])->{$callback[1]}($event); if ($event->isPropagationStopped()) { break; } } return !$event->isSkipped(); } return true; }
/** * Generate the label * * @param array $row * @param string $label * @param DataContainer $dc * @param string $imageAttribute * @param boolean $blnReturnImage * @param boolean $blnProtected * * @return string */ public function generateLabel(array $row, $label = null, DataContainer $dc = null, $imageAttribute = '', $blnReturnImage = false, $blnProtected = false) { $default = ''; if ($GLOBALS['TL_DCA'][$this->table]['list']['sorting']['mode'] === 4) { $callback = $GLOBALS['TL_DCA'][$this->table]['list']['sorting']['default_child_record_callback']; } else { $callback = $GLOBALS['TL_DCA'][$this->table]['list']['label']['default_label_callback']; } // Get the default label if (is_array($callback)) { $default = System::importStatic($callback[0])->{$callback[1]}($row, $label, $dc, $imageAttribute, $blnReturnImage, $blnProtected); } elseif (is_callable($callback)) { $default = $callback($row, $label, $dc, $imageAttribute, $blnReturnImage, $blnProtected); } $template = new BackendTemplate('be_seo_serp_tests'); $template->setData($this->generateTests($row)); $template->label = $default; // Add assets $GLOBALS['TL_CSS'][] = 'system/modules/seo_serp_preview/assets/css/tests.min.css'; $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/seo_serp_preview/assets/js/tests.min.js'; return $template->parse(); }
/** * Add the file meta information to the request * * @param string $strUuid * @param string $strPtable * @param integer $intPid */ public static function addFileMetaInformationToRequest($strUuid, $strPtable, $intPid) { $objFile = \FilesModel::findByUuid($strUuid); if ($objFile === null) { return; } $arrMeta = deserialize($objFile->meta); if (empty($arrMeta)) { return; } $objPage = null; $db = \Database::getInstance(); switch ($strPtable) { case 'tl_article': $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT pid FROM tl_article WHERE id=?)")->execute($intPid); break; case 'tl_news': $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT jumpTo FROM tl_news_archive WHERE id=(SELECT pid FROM tl_news WHERE id=?))")->execute($intPid); break; case 'tl_news_archive': $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT jumpTo FROM tl_news_archive WHERE id=?)")->execute($intPid); break; case 'tl_calendar_events': $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT jumpTo FROM tl_calendar WHERE id=(SELECT pid FROM tl_calendar_events WHERE id=?))")->execute($intPid); break; case 'tl_calendar': $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT jumpTo FROM tl_calendar WHERE id=?)")->execute($intPid); break; case 'tl_faq_category': $objPage = $db->prepare("SELECT * FROM tl_page WHERE id=(SELECT jumpTo FROM tl_faq_category WHERE id=?)")->execute($intPid); break; default: // HOOK: support custom modules if (isset($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest']) && is_array($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest'])) { foreach ($GLOBALS['TL_HOOKS']['addFileMetaInformationToRequest'] as $callback) { if (($val = \System::importStatic($callback[0])->{$callback[1]}($strPtable, $intPid)) !== false) { $objPage = $val; } } } break; } if ($objPage === null || $objPage->numRows < 1) { return; } $objModel = new \PageModel(); $objModel->setRow($objPage->row()); $objModel->loadDetails(); // Convert the language to a locale (see #5678) $strLanguage = str_replace('-', '_', $objModel->rootLanguage); if (isset($arrMeta[$strLanguage])) { if (\Input::post('alt') == '' && !empty($arrMeta[$strLanguage]['title'])) { \Input::setPost('alt', $arrMeta[$strLanguage]['title']); } if (\Input::post('caption') == '' && !empty($arrMeta[$strLanguage]['caption'])) { \Input::setPost('caption', $arrMeta[$strLanguage]['caption']); } } }