_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q243500
Controller.createInitialVersion
validation
protected function createInitialVersion($strTable, $intId) { @trigger_error('Using Controller::createInitialVersion() has been deprecated and will no longer work in Contao 5.0. Use Versions->initialize() instead.', E_USER_DEPRECATED); $objVersions = new Versions($strTable, $intId); $objVersions->initialize(); }
php
{ "resource": "" }
q243501
Controller.braceGlob
validation
protected static function braceGlob($pattern) { // Use glob() if possible if (false === strpos($pattern, '/**/') && (\defined('GLOB_BRACE') || false === strpos($pattern, '{'))) { return glob($pattern, \defined('GLOB_BRACE') ? GLOB_BRACE : 0); } $finder = new Finder(); $regex = Glob::toRegex($pattern); // All files in the given template folder $filesIterator = $finder ->files() ->followLinks() ->sortByName() ->in(\dirname($pattern)) ; // Match the actual regex and filter the files $filesIterator = $filesIterator->filter(function (\SplFileInfo $info) use ($regex) { $path = $info->getPathname(); return preg_match($regex, $path) && $info->isFile(); }); $files = iterator_to_array($filesIterator); return array_keys($files); }
php
{ "resource": "" }
q243502
Database.prepare
validation
public function prepare($strQuery) { $objStatement = new Statement($this->resConnection, $this->blnDisableAutocommit); return $objStatement->prepare($strQuery); }
php
{ "resource": "" }
q243503
Database.query
validation
public function query($strQuery) { $objStatement = new Statement($this->resConnection, $this->blnDisableAutocommit); return $objStatement->query($strQuery); }
php
{ "resource": "" }
q243504
Database.listTables
validation
public function listTables($strDatabase=null, $blnNoCache=false) { if ($blnNoCache || !isset($this->arrCache[$strDatabase])) { $strOldDatabase = $this->resConnection->getDatabase(); // Change the database if ($strDatabase !== null && $strDatabase != $strOldDatabase) { $this->setDatabase($strDatabase); } $this->arrCache[$strDatabase] = $this->resConnection->getSchemaManager()->listTableNames(); // Restore the database if ($strDatabase !== null && $strDatabase != $strOldDatabase) { $this->setDatabase($strOldDatabase); } } return $this->arrCache[$strDatabase]; }
php
{ "resource": "" }
q243505
Database.tableExists
validation
public function tableExists($strTable, $strDatabase=null, $blnNoCache=false) { if ($strTable == '') { return false; } return \in_array($strTable, $this->listTables($strDatabase, $blnNoCache)); }
php
{ "resource": "" }
q243506
Database.fieldExists
validation
public function fieldExists($strField, $strTable, $blnNoCache=false) { if ($strField == '' || $strTable == '') { return false; } foreach ($this->listFields($strTable, $blnNoCache) as $arrField) { if ($arrField['name'] == $strField && $arrField['type'] != 'index') { return true; } } return false; }
php
{ "resource": "" }
q243507
Database.indexExists
validation
public function indexExists($strName, $strTable, $blnNoCache=false) { if ($strName == '' || $strTable == '') { return false; } foreach ($this->listFields($strTable, $blnNoCache) as $arrField) { if ($arrField['name'] == $strName && $arrField['type'] == 'index') { return true; } } return false; }
php
{ "resource": "" }
q243508
Database.getFieldNames
validation
public function getFieldNames($strTable, $blnNoCache=false) { $arrNames = array(); $arrFields = $this->listFields($strTable, $blnNoCache); foreach ($arrFields as $arrField) { if ($arrField['type'] != 'index') { $arrNames[] = $arrField['name']; } } return $arrNames; }
php
{ "resource": "" }
q243509
Database.isUniqueValue
validation
public function isUniqueValue($strTable, $strField, $varValue, $intId=null) { $strQuery = "SELECT * FROM $strTable WHERE " . static::quoteIdentifier($strField) . "=?"; if ($intId !== null) { $strQuery .= " AND id!=?"; } $objUnique = $this->prepare($strQuery) ->limit(1) ->execute($varValue, $intId); return $objUnique->numRows ? false : true; }
php
{ "resource": "" }
q243510
Database.lockTables
validation
public function lockTables($arrTables) { $arrLocks = array(); foreach ($arrTables as $table=>$mode) { $arrLocks[] = $this->resConnection->quoteIdentifier($table) . ' ' . $mode; } $this->resConnection->exec('LOCK TABLES ' . implode(', ', $arrLocks) . ';'); }
php
{ "resource": "" }
q243511
Database.getSizeOf
validation
public function getSizeOf($strTable) { $statement = $this->resConnection->executeQuery('SHOW TABLE STATUS LIKE ' . $this->resConnection->quote($strTable)); $status = $statement->fetch(\PDO::FETCH_ASSOC); return $status['Data_length'] + $status['Index_length']; }
php
{ "resource": "" }
q243512
Database.getUuid
validation
public function getUuid() { static $ids; if (empty($ids)) { $statement = $this->resConnection->executeQuery(implode(' UNION ALL ', array_fill(0, 10, "SELECT UNHEX(REPLACE(UUID(), '-', '')) AS uuid"))); $ids = $statement->fetchAll(\PDO::FETCH_COLUMN); } return array_pop($ids); }
php
{ "resource": "" }
q243513
Database.quoteIdentifier
validation
public static function quoteIdentifier($strName) { static $strQuoteCharacter = null; if ($strQuoteCharacter === null) { $strQuoteCharacter = System::getContainer()->get('database_connection')->getDatabasePlatform()->getIdentifierQuoteCharacter(); } // The identifier is quoted already if (strncmp($strName, $strQuoteCharacter, 1) === 0) { return $strName; } // Not an identifier (AbstractPlatform::quoteIdentifier() handles table.column so also allow . here) if (!preg_match('/^[A-Za-z0-9_$.]+$/', $strName)) { return $strName; } return System::getContainer()->get('database_connection')->quoteIdentifier($strName); }
php
{ "resource": "" }
q243514
tl_module.getModules
validation
public function getModules() { $groups = array(); foreach ($GLOBALS['FE_MOD'] as $k=>$v) { foreach (array_keys($v) as $kk) { $groups[$k][] = $kk; } } return $groups; }
php
{ "resource": "" }
q243515
tl_module.getEditableMemberProperties
validation
public function getEditableMemberProperties() { $return = array(); Contao\System::loadLanguageFile('tl_member'); $this->loadDataContainer('tl_member'); foreach ($GLOBALS['TL_DCA']['tl_member']['fields'] as $k=>$v) { if ($v['eval']['feEditable']) { $return[$k] = $GLOBALS['TL_DCA']['tl_member']['fields'][$k]['label'][0]; } } return $return; }
php
{ "resource": "" }
q243516
tl_module.getLayoutSections
validation
public function getLayoutSections() { $arrSections = array('header', 'left', 'right', 'main', 'footer'); // Check for custom layout sections $objLayout = $this->Database->query("SELECT sections FROM tl_layout WHERE sections!=''"); while ($objLayout->next()) { $arrCustom = Contao\StringUtil::deserialize($objLayout->sections); // Add the custom layout sections if (!empty($arrCustom) && \is_array($arrCustom)) { foreach ($arrCustom as $v) { if (!empty($v['id'])) { $arrSections[] = $v['id']; } } } } return Contao\Backend::convertLayoutSectionIdsToAssociativeArray($arrSections); }
php
{ "resource": "" }
q243517
tl_module.getActivationDefault
validation
public function getActivationDefault($varValue) { if (!trim($varValue)) { $varValue = (\is_array($GLOBALS['TL_LANG']['tl_module']['emailText']) ? $GLOBALS['TL_LANG']['tl_module']['emailText'][1] : $GLOBALS['TL_LANG']['tl_module']['emailText']); } return $varValue; }
php
{ "resource": "" }
q243518
tl_module.getPasswordDefault
validation
public function getPasswordDefault($varValue) { if (!trim($varValue)) { $varValue = (\is_array($GLOBALS['TL_LANG']['tl_module']['passwordText']) ? $GLOBALS['TL_LANG']['tl_module']['passwordText'][1] : $GLOBALS['TL_LANG']['tl_module']['passwordText']); } return $varValue; }
php
{ "resource": "" }
q243519
tl_module.setPagesFlags
validation
public function setPagesFlags($varValue, Contao\DataContainer $dc) { if ($dc->activeRecord && $dc->activeRecord->type == 'search') { $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['mandatory'] = false; unset($GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['orderField']); } return $varValue; }
php
{ "resource": "" }
q243520
Environment.get
validation
public static function get($strKey) { if (isset(static::$arrCache[$strKey])) { return static::$arrCache[$strKey]; } if (\in_array($strKey, get_class_methods(__CLASS__))) { static::$arrCache[$strKey] = static::$strKey(); } else { $arrChunks = preg_split('/([A-Z][a-z]*)/', $strKey, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); $strServerKey = strtoupper(implode('_', $arrChunks)); static::$arrCache[$strKey] = $_SERVER[$strServerKey]; } return static::$arrCache[$strKey]; }
php
{ "resource": "" }
q243521
Environment.httpAcceptLanguage
validation
protected static function httpAcceptLanguage() { $arrAccepted = array(); $arrLanguages = array(); // The implementation differs from the original implementation and also works with .jp browsers preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $arrAccepted); // Remove all invalid locales foreach ($arrAccepted[1] as $v) { $chunks = explode('-', $v); // Language plus dialect, e.g. en-US or fr-FR if (isset($chunks[1])) { $locale = $chunks[0] . '-' . strtoupper($chunks[1]); if (preg_match('/^[a-z]{2}(-[A-Z]{2})?$/', $locale)) { $arrLanguages[] = $locale; } } $locale = $chunks[0]; // Language only, e.g. en or fr (see #29) if (preg_match('/^[a-z]{2}$/', $locale)) { $arrLanguages[] = $locale; } } return \array_slice(array_unique($arrLanguages), 0, 8); }
php
{ "resource": "" }
q243522
Environment.httpHost
validation
protected static function httpHost() { if (!empty($_SERVER['HTTP_HOST'])) { $host = $_SERVER['HTTP_HOST']; } else { $host = $_SERVER['SERVER_NAME']; if ($_SERVER['SERVER_PORT'] != 80) { $host .= ':' . $_SERVER['SERVER_PORT']; } } return preg_replace('/[^A-Za-z0-9[\].:-]/', '', $host); }
php
{ "resource": "" }
q243523
Environment.ssl
validation
protected static function ssl() { $request = System::getContainer()->get('request_stack')->getCurrentRequest(); if ($request === null) { return false; } return $request->isSecure(); }
php
{ "resource": "" }
q243524
Environment.url
validation
protected static function url() { $host = static::get('httpHost'); $xhost = static::get('httpXForwardedHost'); // SSL proxy if ($xhost != '' && $xhost == Config::get('sslProxyDomain')) { return 'https://' . $xhost . '/' . $host; } return (static::get('ssl') ? 'https://' : 'http://') . $host; }
php
{ "resource": "" }
q243525
Environment.ip
validation
protected static function ip() { $request = System::getContainer()->get('request_stack')->getCurrentRequest(); if ($request === null) { return ''; } return $request->getClientIp(); }
php
{ "resource": "" }
q243526
Environment.server
validation
protected static function server() { $strServer = !empty($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']; // Special workaround for Strato users if (empty($strServer)) { $strServer = @gethostbyname($_SERVER['SERVER_NAME']); } return $strServer; }
php
{ "resource": "" }
q243527
Environment.agent
validation
protected static function agent() { $ua = static::get('httpUserAgent'); $return = new \stdClass(); $return->string = $ua; $os = 'unknown'; $mobile = false; $browser = 'other'; $shorty = ''; $version = ''; $engine = ''; // Operating system foreach (Config::get('os') as $k=>$v) { if (stripos($ua, $k) !== false) { $os = $v['os']; $mobile = $v['mobile']; break; } } $return->os = $os; // Browser and version foreach (Config::get('browser') as $k=>$v) { if (stripos($ua, $k) !== false) { $browser = $v['browser']; $shorty = $v['shorty']; $version = preg_replace($v['version'], '$1', $ua); $engine = $v['engine']; break; } } $versions = explode('.', $version); $version = $versions[0]; $return->class = $os . ' ' . $browser . ' ' . $engine; // Add the version number if available if ($version != '') { $return->class .= ' ' . $shorty . $version; } // Android tablets are not mobile (see #4150 and #5869) if ($os == 'android' && $engine != 'presto' && stripos($ua, 'mobile') === false) { $mobile = false; } // Mark mobile devices if ($mobile) { $return->class .= ' mobile'; } $return->browser = $browser; $return->shorty = $shorty; $return->version = $version; $return->engine = $engine; $return->versions = $versions; $return->mobile = $mobile; return $return; }
php
{ "resource": "" }
q243528
MemberModel.findActiveByEmailAndUsername
validation
public static function findActiveByEmailAndUsername($strEmail, $strUsername=null, array $arrOptions=array()) { $t = static::$strTable; $time = Date::floorToMinute(); $arrColumns = array("$t.email=? AND $t.login='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'" . ($time + 60) . "') AND $t.disable=''"); if ($strUsername !== null) { $arrColumns[] = "$t.username=?"; } return static::findOneBy($arrColumns, array($strEmail, $strUsername), $arrOptions); }
php
{ "resource": "" }
q243529
MemberModel.findUnactivatedByEmail
validation
public static function findUnactivatedByEmail($strEmail, array $arrOptions=array()) { $t = static::$strTable; $objDatabase = Database::getInstance(); $objResult = $objDatabase->prepare("SELECT * FROM $t WHERE email=? AND disable='1' AND EXISTS (SELECT * FROM tl_opt_in_related r LEFT JOIN tl_opt_in o ON r.pid=o.id WHERE r.relTable='$t' AND r.relId=$t.id AND o.createdOn>? AND o.confirmedOn=0)") ->limit(1) ->execute($strEmail, strtotime('-24 hours')); if ($objResult->numRows < 1) { return null; } $objRegistry = Registry::getInstance(); /** @var MemberModel|Model $objMember */ if ($objMember = $objRegistry->fetch($t, $objResult->id)) { return $objMember; } return new static($objResult); }
php
{ "resource": "" }
q243530
ModuleSubscribe.activateRecipient
validation
protected function activateRecipient() { $this->Template = new FrontendTemplate('mod_newsletter'); /** @var OptIn $optIn */ $optIn = System::getContainer()->get('contao.opt-in'); // Find an unconfirmed token if ((!$optInToken = $optIn->find(Input::get('token'))) || !$optInToken->isValid() || \count($arrRelated = $optInToken->getRelatedRecords()) < 1 || key($arrRelated) != 'tl_newsletter_recipients' || \count($arrIds = current($arrRelated)) < 1) { $this->Template->type = 'error'; $this->Template->message = $GLOBALS['TL_LANG']['MSC']['invalidToken']; return; } if ($optInToken->isConfirmed()) { $this->Template->type = 'error'; $this->Template->message = $GLOBALS['TL_LANG']['MSC']['tokenConfirmed']; return; } $arrRecipients = array(); // Validate the token foreach ($arrIds as $intId) { if (!$objRecipient = NewsletterRecipientsModel::findByPk($intId)) { $this->Template->type = 'error'; $this->Template->message = $GLOBALS['TL_LANG']['MSC']['invalidToken']; return; } if ($optInToken->getEmail() != $objRecipient->email) { $this->Template->type = 'error'; $this->Template->message = $GLOBALS['TL_LANG']['MSC']['tokenEmailMismatch']; return; } $arrRecipients[] = $objRecipient; } $time = time(); $arrAdd = array(); $arrCids = array(); // Activate the subscriptions foreach ($arrRecipients as $objRecipient) { $arrAdd[] = $objRecipient->id; $arrCids[] = $objRecipient->pid; $objRecipient->tstamp = $time; $objRecipient->active = '1'; $objRecipient->save(); } $optInToken->confirm(); // HOOK: post activation callback if (isset($GLOBALS['TL_HOOKS']['activateRecipient']) && \is_array($GLOBALS['TL_HOOKS']['activateRecipient'])) { foreach ($GLOBALS['TL_HOOKS']['activateRecipient'] as $callback) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($optInToken->getEmail(), $arrAdd, $arrCids); } } // Confirm activation $this->Template->mclass = 'confirm'; $this->Template->message = $GLOBALS['TL_LANG']['MSC']['nl_activate']; }
php
{ "resource": "" }
q243531
ModuleSubscribe.addRecipient
validation
protected function addRecipient($strEmail, $arrNew) { // Remove old subscriptions that have not been activated yet if (($objOld = NewsletterRecipientsModel::findOldSubscriptionsByEmailAndPids($strEmail, $arrNew)) !== null) { while ($objOld->next()) { $objOld->delete(); } } $time = time(); $arrRelated = array(); // Add the new subscriptions foreach ($arrNew as $id) { $objRecipient = new NewsletterRecipientsModel(); $objRecipient->pid = $id; $objRecipient->tstamp = $time; $objRecipient->email = $strEmail; $objRecipient->active = ''; $objRecipient->addedOn = $time; $objRecipient->save(); // Remove the blacklist entry (see #4999) if (($objBlacklist = NewsletterBlacklistModel::findByHashAndPid(md5($strEmail), $id)) !== null) { $objBlacklist->delete(); } $arrRelated['tl_newsletter_recipients'][] = $objRecipient->id; } /** @var OptIn $optIn */ $optIn = System::getContainer()->get('contao.opt-in'); $optInToken = $optIn->create('nl', $strEmail, $arrRelated); // Get the channels $objChannel = NewsletterChannelModel::findByIds($arrNew); // Prepare the simple token data $arrData = array(); $arrData['token'] = $optInToken->getIdentifier(); $arrData['domain'] = Idna::decode(Environment::get('host')); $arrData['link'] = Idna::decode(Environment::get('base')) . Environment::get('request') . ((strpos(Environment::get('request'), '?') !== false) ? '&' : '?') . 'token=' . $optInToken->getIdentifier(); $arrData['channel'] = $arrData['channels'] = implode("\n", $objChannel->fetchEach('title')); // Send the token $optInToken->send(sprintf($GLOBALS['TL_LANG']['MSC']['nl_subject'], Idna::decode(Environment::get('host'))), StringUtil::parseSimpleTokens($this->nl_subscribe, $arrData)); // Redirect to the jumpTo page if (($objTarget = $this->objModel->getRelated('jumpTo')) instanceof PageModel) { /** @var PageModel $objTarget */ $this->redirect($objTarget->getFrontendUrl()); } System::getContainer()->get('session')->getFlashBag()->set('nl_confirm', $GLOBALS['TL_LANG']['MSC']['nl_confirm']); $this->reload(); }
php
{ "resource": "" }
q243532
AddToSearchIndexListener.onKernelTerminate
validation
public function onKernelTerminate(PostResponseEvent $event): void { if (!$this->framework->isInitialized()) { return; } $request = $event->getRequest(); // Only index GET requests (see #1194) if (!$request->isMethod(Request::METHOD_GET)) { return; } // Do not index fragments if (preg_match('~(?:^|/)'.preg_quote($this->fragmentPath, '~').'/~', $request->getPathInfo())) { return; } /** @var Frontend $frontend */ $frontend = $this->framework->getAdapter(Frontend::class); $frontend->indexPageIfApplicable($event->getResponse()); }
php
{ "resource": "" }
q243533
Backend.getTheme
validation
public static function getTheme() { $theme = Config::get('backendTheme'); $rootDir = System::getContainer()->getParameter('kernel.project_dir'); if ($theme != '' && $theme != 'flexible' && is_dir($rootDir . '/system/themes/' . $theme)) { return $theme; } return 'flexible'; }
php
{ "resource": "" }
q243534
Backend.getThemes
validation
public static function getThemes() { $arrReturn = array(); $rootDir = System::getContainer()->getParameter('kernel.project_dir'); $arrThemes = scan($rootDir . '/system/themes'); foreach ($arrThemes as $strTheme) { if (strncmp($strTheme, '.', 1) === 0 || !is_dir($rootDir . '/system/themes/' . $strTheme)) { continue; } $arrReturn[$strTheme] = $strTheme; } return $arrReturn; }
php
{ "resource": "" }
q243535
Backend.getTinyMceLanguage
validation
public static function getTinyMceLanguage() { $lang = $GLOBALS['TL_LANGUAGE']; if ($lang == '') { return 'en'; } $lang = str_replace('-', '_', $lang); $rootDir = System::getContainer()->getParameter('kernel.project_dir'); // The translation exists if (file_exists($rootDir . '/assets/tinymce4/js/langs/' . $lang . '.js')) { return $lang; } if (($short = substr($GLOBALS['TL_LANGUAGE'], 0, 2)) != $lang) { // Try the short tag, e.g. "de" instead of "de_CH" if (file_exists($rootDir . '/assets/tinymce4/js/langs/' . $short . '.js')) { return $short; } } elseif (($long = $short . '_' . strtoupper($short)) != $lang) { // Try the long tag, e.g. "fr_FR" instead of "fr" (see #6952) if (file_exists($rootDir . '/assets/tinymce4/js/langs/' . $long . '.js')) { return $long; } } // Fallback to English return 'en'; }
php
{ "resource": "" }
q243536
Backend.getTinyTemplates
validation
public static function getTinyTemplates() { $strDir = Config::get('uploadPath') . '/tiny_templates'; $rootDir = System::getContainer()->getParameter('kernel.project_dir'); if (!is_dir($rootDir . '/' . $strDir)) { return ''; } $arrFiles = array(); $arrTemplates = scan($rootDir . '/' . $strDir); foreach ($arrTemplates as $strFile) { if (strncmp('.', $strFile, 1) !== 0 && is_file($rootDir . '/' . $strDir . '/' . $strFile)) { $arrFiles[] = '{ title: "' . $strFile . '", url: "' . $strDir . '/' . $strFile . '" }'; } } return implode(",\n", $arrFiles) . "\n"; }
php
{ "resource": "" }
q243537
Backend.addToUrl
validation
public static function addToUrl($strRequest, $blnAddRef=true, $arrUnset=array()) { // Unset the "no back button" flag $arrUnset[] = 'nb'; return parent::addToUrl($strRequest . (($strRequest != '') ? '&amp;' : '') . 'rt=' . REQUEST_TOKEN, $blnAddRef, $arrUnset); }
php
{ "resource": "" }
q243538
Backend.handleRunOnce
validation
public static function handleRunOnce() { try { $files = System::getContainer()->get('contao.resource_locator')->locate('config/runonce.php', null, false); } catch (\InvalidArgumentException $e) { return; } foreach ($files as $file) { try { include $file; } catch (\Exception $e) {} $strRelpath = StringUtil::stripRootDir($file); if (!unlink($file)) { throw new \Exception("The file $strRelpath cannot be deleted. Please remove the file manually and correct the file permission settings on your server."); } System::log("File $strRelpath ran once and has then been removed successfully", __METHOD__, TL_GENERAL); } }
php
{ "resource": "" }
q243539
Backend.findSearchablePages
validation
public static function findSearchablePages($pid=0, $domain='', $blnIsSitemap=false) { $objPages = PageModel::findPublishedByPid($pid, array('ignoreFePreview'=>true)); if ($objPages === null) { return array(); } $arrPages = array(); // Recursively walk through all subpages foreach ($objPages as $objPage) { if ($objPage->type == 'regular') { // Searchable and not protected if ((!$objPage->noSearch || $blnIsSitemap) && (!$objPage->protected || (Config::get('indexProtected') && (!$blnIsSitemap || $objPage->sitemap == 'map_always'))) && (!$blnIsSitemap || $objPage->sitemap != 'map_never') && !$objPage->requireItem) { $arrPages[] = $objPage->getAbsoluteUrl(); // Get articles with teaser if (($objArticles = ArticleModel::findPublishedWithTeaserByPid($objPage->id, array('ignoreFePreview'=>true))) !== null) { foreach ($objArticles as $objArticle) { $arrPages[] = $objPage->getAbsoluteUrl('/articles/' . ($objArticle->alias ?: $objArticle->id)); } } } } // Get subpages if ((!$objPage->protected || Config::get('indexProtected')) && ($arrSubpages = static::findSearchablePages($objPage->id, $domain, $blnIsSitemap))) { $arrPages = array_merge($arrPages, $arrSubpages); } } return $arrPages; }
php
{ "resource": "" }
q243540
Backend.addFileMetaInformationToRequest
validation
public static function addFileMetaInformationToRequest($strUuid, $strPtable, $intPid) { @trigger_error('Using Backend::addFileMetaInformationToRequest() has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED); $objFile = FilesModel::findByUuid($strUuid); if ($objFile === null) { return; } $arrMeta = StringUtil::deserialize($objFile->meta); if (empty($arrMeta)) { return; } $objPage = null; if ($strPtable == 'tl_article') { $objPage = PageModel::findOneBy(array('tl_page.id=(SELECT pid FROM tl_article WHERE id=?)'), $intPid); } else { // 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; } } if ($objPage instanceof Result && $objPage->numRows < 1) { return; } if (\is_object($objPage) && !($objPage instanceof PageModel)) { $objPage = PageModel::findByPk($objPage->id); } } } if ($objPage === null) { return; } $objPage->loadDetails(); // Convert the language to a locale (see #5678) $strLanguage = str_replace('-', '_', $objPage->rootLanguage); if (isset($arrMeta[$strLanguage])) { if (!empty($arrMeta[$strLanguage]['title']) && Input::post('title') == '') { Input::setPost('title', $arrMeta[$strLanguage]['title']); } if (!empty($arrMeta[$strLanguage]['alt']) && Input::post('alt') == '') { Input::setPost('alt', $arrMeta[$strLanguage]['alt']); } if (!empty($arrMeta[$strLanguage]['caption']) && Input::post('caption') == '') { Input::setPost('caption', $arrMeta[$strLanguage]['caption']); } } }
php
{ "resource": "" }
q243541
Backend.getSystemMessages
validation
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; }
php
{ "resource": "" }
q243542
Backend.convertLayoutSectionIdsToAssociativeArray
validation
public static function convertLayoutSectionIdsToAssociativeArray($arrSections) { $arrSections = array_flip(array_values(array_unique($arrSections))); foreach (array_keys($arrSections) as $k) { $arrSections[$k] = $GLOBALS['TL_LANG']['COLS'][$k]; } asort($arrSections); return $arrSections; }
php
{ "resource": "" }
q243543
Backend.getDcaPickerWizard
validation
public static function getDcaPickerWizard($extras, $table, $field, $inputName) { $context = 'link'; $extras = \is_array($extras) ? $extras : array(); $providers = (isset($extras['providers']) && \is_array($extras['providers'])) ? $extras['providers'] : null; if (isset($extras['context'])) { $context = $extras['context']; unset($extras['context']); } $factory = System::getContainer()->get('contao.picker.builder'); if (!$factory->supportsContext($context, $providers)) { return ''; } return ' <a href="' . ampersand($factory->getUrl($context, $extras)) . '" title="' . StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['pagepicker']) . '" id="pp_' . $inputName . '">' . Image::getHtml((\is_array($extras) && isset($extras['icon']) ? $extras['icon'] : 'pickpage.svg'), $GLOBALS['TL_LANG']['MSC']['pagepicker']) . '</a> <script> $("pp_' . $inputName . '").addEvent("click", function(e) { e.preventDefault(); Backend.openModalSelector({ "id": "tl_listing", "title": ' . json_encode($GLOBALS['TL_DCA'][$table]['fields'][$field]['label'][0]) . ', "url": this.href + "&value=" + document.getElementById("ctrl_' . $inputName . '").value, "callback": function(picker, value) { $("ctrl_' . $inputName . '").value = value.join(","); }.bind(this) }); }); </script>'; }
php
{ "resource": "" }
q243544
Backend.addCustomLayoutSectionReferences
validation
public function addCustomLayoutSectionReferences() { $objLayout = $this->Database->getInstance()->query("SELECT sections FROM tl_layout WHERE sections!=''"); while ($objLayout->next()) { $arrCustom = StringUtil::deserialize($objLayout->sections); // Add the custom layout sections if (!empty($arrCustom) && \is_array($arrCustom)) { foreach ($arrCustom as $v) { if (!empty($v['id'])) { $GLOBALS['TL_LANG']['COLS'][$v['id']] = $v['title']; } } } } }
php
{ "resource": "" }
q243545
Backend.createPageList
validation
public function createPageList() { $this->import(BackendUser::class, 'User'); if ($this->User->isAdmin) { return $this->doCreatePageList(); } $return = ''; $processed = array(); foreach ($this->eliminateNestedPages($this->User->pagemounts) as $page) { $objPage = PageModel::findWithDetails($page); // Root page mounted if ($objPage->type == 'root') { $title = $objPage->title; $start = $objPage->id; } // Regular page mounted else { $title = $objPage->rootTitle; $start = $objPage->rootId; } // Do not process twice if (\in_array($start, $processed)) { continue; } // Skip websites that run under a different domain (see #2387) if ($objPage->domain && $objPage->domain != Environment::get('host')) { continue; } $processed[] = $start; $return .= '<optgroup label="' . $title . '">' . $this->doCreatePageList($start) . '</optgroup>'; } return $return; }
php
{ "resource": "" }
q243546
Backend.doCreatePageList
validation
protected function doCreatePageList($intId=0, $level=-1) { $objPages = $this->Database->prepare("SELECT id, title, type, dns FROM tl_page WHERE pid=? ORDER BY sorting") ->execute($intId); if ($objPages->numRows < 1) { return ''; } ++$level; $strOptions = ''; while ($objPages->next()) { if ($objPages->type == 'root') { // Skip websites that run under a different domain if ($objPages->dns && $objPages->dns != Environment::get('host')) { continue; } $strOptions .= '<optgroup label="' . $objPages->title . '">'; $strOptions .= $this->doCreatePageList($objPages->id, -1); $strOptions .= '</optgroup>'; } else { $strOptions .= sprintf('<option value="{{link_url::%s}}"%s>%s%s</option>', $objPages->id, (('{{link_url::' . $objPages->id . '}}' == Input::get('value')) ? ' selected="selected"' : ''), str_repeat(' &nbsp; &nbsp; ', $level), StringUtil::specialchars($objPages->title)); $strOptions .= $this->doCreatePageList($objPages->id, $level); } } return $strOptions; }
php
{ "resource": "" }
q243547
Backend.createFileList
validation
public function createFileList($strFilter='', $filemount=false) { // Deprecated since Contao 4.0, to be removed in Contao 5.0 if ($strFilter === true) { @trigger_error('Passing "true" to Backend::createFileList() has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED); $strFilter = 'gif,jpg,jpeg,png'; } $this->import(BackendUser::class, 'User'); if ($this->User->isAdmin) { return $this->doCreateFileList(Config::get('uploadPath'), -1, $strFilter); } $return = ''; $processed = array(); // Set custom filemount if ($filemount) { $this->User->filemounts = array($filemount); } // Limit nodes to the filemounts of the user foreach ($this->eliminateNestedPaths($this->User->filemounts) as $path) { if (\in_array($path, $processed)) { continue; } $processed[] = $path; $return .= $this->doCreateFileList($path, -1, $strFilter); } return $return; }
php
{ "resource": "" }
q243548
Backend.doCreateFileList
validation
protected function doCreateFileList($strFolder=null, $level=-1, $strFilter='') { // Deprecated since Contao 4.0, to be removed in Contao 5.0 if ($strFilter === true) { @trigger_error('Passing "true" to Backend::doCreateFileList() has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED); $strFilter = 'gif,jpg,jpeg,png'; } $rootDir = System::getContainer()->getParameter('kernel.project_dir'); $arrPages = scan($rootDir . '/' . $strFolder); // Empty folder if (empty($arrPages)) { return ''; } // Protected folder if (\in_array('.htaccess', $arrPages)) { return ''; } ++$level; $strFolders = ''; $strFiles = ''; // Recursively list all files and folders foreach ($arrPages as $strFile) { if (strncmp($strFile, '.', 1) === 0) { continue; } // Folders if (is_dir($rootDir . '/' . $strFolder . '/' . $strFile)) { $strFolders .= $this->doCreateFileList($strFolder . '/' . $strFile, $level, $strFilter); } // Files else { // Filter images if ($strFilter != '' && !preg_match('/\.(' . str_replace(',', '|', $strFilter) . ')$/i', $strFile)) { continue; } $strFiles .= sprintf('<option value="%s"%s>%s</option>', $strFolder . '/' . $strFile, (($strFolder . '/' . $strFile == Input::get('value')) ? ' selected="selected"' : ''), StringUtil::specialchars($strFile)); } } if (\strlen($strFiles)) { return '<optgroup label="' . StringUtil::specialchars($strFolder) . '">' . $strFiles . $strFolders . '</optgroup>'; } return $strFiles . $strFolders; }
php
{ "resource": "" }
q243549
Image.setImportantPart
validation
public function setImportantPart(array $importantPart = null) { if ($importantPart !== null) { if (!isset($importantPart['x']) || !isset($importantPart['y']) || !isset($importantPart['width']) || !isset($importantPart['height'])) { throw new \InvalidArgumentException('Malformed array for setting the important part!'); } $this->importantPart = array ( 'x' => max(0, min($this->fileObj->viewWidth - 1, (int) $importantPart['x'])), 'y' => max(0, min($this->fileObj->viewHeight - 1, (int) $importantPart['y'])), ); $this->importantPart['width'] = max(1, min($this->fileObj->viewWidth - $this->importantPart['x'], (int) $importantPart['width'])); $this->importantPart['height'] = max(1, min($this->fileObj->viewHeight - $this->importantPart['y'], (int) $importantPart['height'])); } else { $this->importantPart = null; } return $this; }
php
{ "resource": "" }
q243550
Image.getImportantPart
validation
public function getImportantPart() { if ($this->importantPart) { return $this->importantPart; } return array('x'=>0, 'y'=>0, 'width'=>$this->fileObj->viewWidth, 'height'=>$this->fileObj->viewHeight); }
php
{ "resource": "" }
q243551
Image.setZoomLevel
validation
public function setZoomLevel($zoomLevel) { $zoomLevel = (int) $zoomLevel; if ($zoomLevel < 0 || $zoomLevel > 100) { throw new \InvalidArgumentException('Zoom level must be between 0 and 100!'); } $this->zoomLevel = $zoomLevel; return $this; }
php
{ "resource": "" }
q243552
Image.getResizedPath
validation
public function getResizedPath() { $path = $this->resizedPath; $webDir = StringUtil::stripRootDir(System::getContainer()->getParameter('contao.web_dir')); // Strip the web/ prefix (see #337) if (strncmp($path, $webDir . '/', \strlen($webDir) + 1) === 0) { $path = substr($path, \strlen($webDir) + 1); } return $path; }
php
{ "resource": "" }
q243553
Image.getCacheName
validation
public function getCacheName() { $importantPart = $this->getImportantPart(); $strCacheKey = substr(md5 ( '-w' . $this->getTargetWidth() . '-h' . $this->getTargetHeight() . '-o' . $this->getOriginalPath() . '-m' . $this->getResizeMode() . '-z' . $this->getZoomLevel() . '-x' . $importantPart['x'] . '-y' . $importantPart['y'] . '-i' . $importantPart['width'] . '-e' . $importantPart['height'] . '-t' . $this->fileObj->mtime ), 0, 8); return StringUtil::stripRootDir(System::getContainer()->getParameter('contao.image.target_dir')) . '/' . substr($strCacheKey, -1) . '/' . $this->fileObj->filename . '-' . $strCacheKey . '.' . $this->fileObj->extension; }
php
{ "resource": "" }
q243554
Image.executeResize
validation
public function executeResize() { $image = $this->prepareImage(); $resizeConfig = $this->prepareResizeConfig(); if (!System::getContainer()->getParameter('contao.image.bypass_cache') && $this->getTargetPath() && !$this->getForceOverride() && file_exists($this->strRootDir . '/' . $this->getTargetPath()) && $this->fileObj->mtime <= filemtime($this->strRootDir . '/' . $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 ? $this->strRootDir . '/' . $this->targetPath : null) ->setBypassCache(System::getContainer()->getParameter('contao.image.bypass_cache')) ) ; $this->resizedPath = $image->getUrl($this->strRootDir); return $this; }
php
{ "resource": "" }
q243555
Image.prepareImage
validation
protected function prepareImage() { if ($this->fileObj->isSvgImage) { $imagine = System::getContainer()->get('contao.image.imagine_svg'); } else { $imagine = System::getContainer()->get('contao.image.imagine'); } $image = new NewImage($this->strRootDir . '/' . $this->fileObj->path, $imagine, System::getContainer()->get('filesystem')); $image->setImportantPart($this->prepareImportantPart()); return $image; }
php
{ "resource": "" }
q243556
Image.prepareImportantPart
validation
protected function prepareImportantPart() { $importantPart = $this->getImportantPart(); if (substr_count($this->resizeMode, '_') === 1) { $importantPart = array ( 'x' => 0, 'y' => 0, 'width' => $this->fileObj->viewWidth, 'height' => $this->fileObj->viewHeight, ); $mode = explode('_', $this->resizeMode); if ($mode[0] === 'left') { $importantPart['width'] = 1; } elseif ($mode[0] === 'right') { $importantPart['x'] = $importantPart['width'] - 1; $importantPart['width'] = 1; } if ($mode[1] === 'top') { $importantPart['height'] = 1; } elseif ($mode[1] === 'bottom') { $importantPart['y'] = $importantPart['height'] - 1; $importantPart['height'] = 1; } } if (!$importantPart['width'] || !$importantPart['height']) { return null; } return new ImportantPart( new Point($importantPart['x'], $importantPart['y']), new Box($importantPart['width'], $importantPart['height']) ); }
php
{ "resource": "" }
q243557
Image.prepareResizeConfig
validation
protected function prepareResizeConfig() { $resizeConfig = new ResizeConfiguration(); $resizeConfig->setWidth($this->targetWidth); $resizeConfig->setHeight($this->targetHeight); $resizeConfig->setZoomLevel($this->zoomLevel); if (substr_count($this->resizeMode, '_') === 1) { $resizeConfig->setMode(ResizeConfiguration::MODE_CROP); $resizeConfig->setZoomLevel(0); } else { try { $resizeConfig->setMode($this->resizeMode); } catch (\InvalidArgumentException $exception) { $resizeConfig->setMode(ResizeConfiguration::MODE_CROP); } } return $resizeConfig; }
php
{ "resource": "" }
q243558
Image.computeResize
validation
public function computeResize() { $resizeCoordinates = System::getContainer() ->get('contao.image.resize_calculator') ->calculate( $this->prepareResizeConfig(), new ImageDimensions( new Box($this->fileObj->viewWidth, $this->fileObj->viewHeight), $this->fileObj->viewWidth !== $this->fileObj->width ), $this->prepareImportantPart() ) ; return array ( 'width' => $resizeCoordinates->getCropSize()->getWidth(), 'height' => $resizeCoordinates->getCropSize()->getHeight(), 'target_x' => -$resizeCoordinates->getCropStart()->getX(), 'target_y' => -$resizeCoordinates->getCropStart()->getY(), 'target_width' => $resizeCoordinates->getSize()->getWidth(), 'target_height' => $resizeCoordinates->getSize()->getHeight(), ); }
php
{ "resource": "" }
q243559
Image.getPath
validation
public static function getPath($src) { if ($src == '') { return ''; } $src = rawurldecode($src); if (strpos($src, '/') !== false) { return $src; } $rootDir = System::getContainer()->getParameter('kernel.project_dir'); if (strncmp($src, 'icon', 4) === 0) { if (pathinfo($src, PATHINFO_EXTENSION) == 'svg') { return 'assets/contao/images/' . $src; } $filename = pathinfo($src, PATHINFO_FILENAME); // Prefer SVG icons if (file_exists($rootDir . '/assets/contao/images/' . $filename . '.svg')) { return 'assets/contao/images/' . $filename . '.svg'; } return 'assets/contao/images/' . $src; } else { $theme = Backend::getTheme(); if (pathinfo($src, PATHINFO_EXTENSION) == 'svg') { return 'system/themes/' . $theme . '/icons/' . $src; } $filename = pathinfo($src, PATHINFO_FILENAME); // Prefer SVG icons if (file_exists($rootDir . '/system/themes/' . $theme . '/icons/' . $filename . '.svg')) { return 'system/themes/' . $theme . '/icons/' . $filename . '.svg'; } return 'system/themes/' . $theme . '/images/' . $src; } }
php
{ "resource": "" }
q243560
Image.resize
validation
public static function resize($image, $width, $height, $mode='') { @trigger_error('Using Image::resize() has been deprecated and will no longer work in Contao 5.0. Use the contao.image.image_factory service instead.', E_USER_DEPRECATED); return static::get($image, $width, $height, $mode, $image, true) ? true : false; }
php
{ "resource": "" }
q243561
Image.create
validation
public static function create($image, $size=null) { @trigger_error('Using Image::create() has been deprecated and will no longer work in Contao 5.0. Use the contao.image.image_factory service instead.', E_USER_DEPRECATED); if (\is_string($image)) { $image = new File(rawurldecode($image)); } /** @var Image $imageObj */ $imageObj = new static($image); // tl_image_size ID as resize mode if (\is_array($size) && !empty($size[2]) && is_numeric($size[2])) { $size = (int) $size[2]; } if (\is_array($size)) { $size += array(0, 0, 'crop'); $imageObj ->setTargetWidth($size[0]) ->setTargetHeight($size[1]) ->setResizeMode($size[2]) ; } // Load the image size from the database if $size is an ID elseif (($imageSize = ImageSizeModel::findByPk($size)) !== null) { $imageObj ->setTargetWidth($imageSize->width) ->setTargetHeight($imageSize->height) ->setResizeMode($imageSize->resizeMode) ->setZoomLevel($imageSize->zoom) ; } $fileRecord = FilesModel::findByPath($image->path); // Set the important part if ($fileRecord !== null && $fileRecord->importantPartWidth && $fileRecord->importantPartHeight) { $imageObj->setImportantPart(array ( 'x' => (int) $fileRecord->importantPartX, 'y' => (int) $fileRecord->importantPartY, 'width' => (int) $fileRecord->importantPartWidth, 'height' => (int) $fileRecord->importantPartHeight, )); } return $imageObj; }
php
{ "resource": "" }
q243562
Image.get
validation
public static function get($image, $width, $height, $mode='', $target=null, $force=false) { @trigger_error('Using Image::get() has been deprecated and will no longer work in Contao 5.0. Use the contao.image.image_factory service instead.', E_USER_DEPRECATED); if ($image == '') { return null; } try { $imageObj = static::create($image, array($width, $height, $mode)); $imageObj->setTargetPath($target); $imageObj->setForceOverride($force); if ($path = $imageObj->executeResize()->getResizedPath()) { return $path; } } catch (\Exception $e) { System::log('Image "' . $image . '" could not be processed: ' . $e->getMessage(), __METHOD__, 'ERROR'); } return null; }
php
{ "resource": "" }
q243563
Image.getPixelValue
validation
public static function getPixelValue($size) { @trigger_error('Using Image::getPixelValue() has been deprecated and will no longer work in Contao 5.0.', E_USER_DEPRECATED); $value = preg_replace('/[^0-9.-]+/', '', $size); $unit = preg_replace('/[^acehimnprtvwx%]/', '', $size); // Convert 16px = 1em = 2ex = 12pt = 1pc = 1/6in = 2.54/6cm = 25.4/6mm = 100% switch ($unit) { case '': case 'px': return (int) round($value); break; case 'em': return (int) round($value * 16); break; case 'ex': return (int) round($value * 16 / 2); break; case 'pt': return (int) round($value * 16 / 12); break; case 'pc': return (int) round($value * 16); break; case 'in': return (int) round($value * 16 * 6); break; case 'cm': return (int) round($value * 16 / (2.54 / 6)); break; case 'mm': return (int) round($value * 16 / (25.4 / 6)); break; case '%': return (int) round($value * 16 / 100); break; } return 0; }
php
{ "resource": "" }
q243564
RequestToken.get
validation
public static function get() { $container = System::getContainer(); return $container->get('contao.csrf.token_manager')->getToken($container->getParameter('contao.csrf_token_name'))->getValue(); }
php
{ "resource": "" }
q243565
RequestToken.validate
validation
public static function validate($strToken) { // The feature has been disabled if (Config::get('disableRefererCheck') || \defined('BYPASS_TOKEN_CHECK')) { return true; } // Check against the whitelist (thanks to Tristan Lins) (see #3164) if (Config::get('requestTokenWhitelist')) { $strHostname = gethostbyaddr($_SERVER['REMOTE_ADDR']); foreach (Config::get('requestTokenWhitelist') as $strDomain) { if ($strDomain == $strHostname || preg_match('/\.' . preg_quote($strDomain, '/') . '$/', $strHostname)) { return true; } } } $container = System::getContainer(); return $container->get('contao.csrf.token_manager')->isTokenValid(new CsrfToken($container->getParameter('contao.csrf_token_name'), $strToken)); }
php
{ "resource": "" }
q243566
Collection.__isset
validation
public function __isset($strKey) { if ($this->intIndex < 0) { $this->first(); } return isset($this->arrModels[$this->intIndex]->$strKey); }
php
{ "resource": "" }
q243567
Collection.createFromDbResult
validation
public static function createFromDbResult(Result $objResult, $strTable) { $arrModels = array(); $strClass = Model::getClassFromTable($strTable); while ($objResult->next()) { /** @var Model $strClass */ $objModel = Registry::getInstance()->fetch($strTable, $objResult->{$strClass::getPk()}); if ($objModel !== null) { $objModel->mergeRow($objResult->row()); $arrModels[] = $objModel; } else { $arrModels[] = new $strClass($objResult); } } return new static($arrModels, $strTable); }
php
{ "resource": "" }
q243568
Collection.setRow
validation
public function setRow(array $arrData) { if ($this->intIndex < 0) { $this->first(); } $this->arrModels[$this->intIndex]->setRow($arrData); return $this; }
php
{ "resource": "" }
q243569
Collection.save
validation
public function save() { if ($this->intIndex < 0) { $this->first(); } $this->arrModels[$this->intIndex]->save(); return $this; }
php
{ "resource": "" }
q243570
Collection.delete
validation
public function delete() { if ($this->intIndex < 0) { $this->first(); } return $this->arrModels[$this->intIndex]->delete(); }
php
{ "resource": "" }
q243571
Collection.next
validation
public function next() { if (!isset($this->arrModels[$this->intIndex + 1])) { return false; } ++$this->intIndex; return $this; }
php
{ "resource": "" }
q243572
Collection.fetchEach
validation
public function fetchEach($strKey) { $this->reset(); $return = array(); while ($this->next()) { $strPk = $this->current()->getPk(); if ($strKey != 'id' && isset($this->$strPk)) { $return[$this->$strPk] = $this->$strKey; } else { $return[] = $this->$strKey; } } return $return; }
php
{ "resource": "" }
q243573
MetaWizard.validator
validation
public function validator($varInput) { if (!\is_array($varInput)) { return null; // see #382 } foreach ($varInput as $k=>$v) { if ($k != 'language') { $varInput[$k] = array_map('trim', $v); } else { if ($v != '') { // Take the fields from the DCA (see #4327) $varInput[$v] = array_combine(array_keys($this->metaFields), array_fill(0, \count($this->metaFields), '')); } unset($varInput[$k]); } } return $varInput; }
php
{ "resource": "" }
q243574
BypassMaintenanceListener.onKernelRequest
validation
public function onKernelRequest(GetResponseEvent $event): void { if (!$this->tokenChecker->hasBackendUser()) { return; } $request = $event->getRequest(); $request->attributes->set($this->requestAttribute, true); }
php
{ "resource": "" }
q243575
SwitchUserListener.onSwitchUser
validation
public function onSwitchUser(SwitchUserEvent $event): void { $token = $this->tokenStorage->getToken(); if (null === $token) { throw new \RuntimeException('The token storage did not contain a token.'); } $sourceUser = $token->getUser(); if ($sourceUser instanceof UserInterface) { $sourceUser = $sourceUser->getUsername(); } $targetUser = $event->getTargetUser(); if ($targetUser instanceof UserInterface) { $targetUser = $targetUser->getUsername(); } $this->logger->info( sprintf('User "%s" has switched to user "%s"', $sourceUser, $targetUser), ['contao' => new ContaoContext(__METHOD__, ContaoContext::ACCESS, $sourceUser)] ); }
php
{ "resource": "" }
q243576
CsrfTokenCookieListener.onKernelRequest
validation
public function onKernelRequest(GetResponseEvent $event): void { if (!$event->isMasterRequest()) { return; } $this->tokenStorage->initialize($this->getTokensFromCookies($event->getRequest()->cookies)); }
php
{ "resource": "" }
q243577
CsrfTokenCookieListener.onKernelResponse
validation
public function onKernelResponse(FilterResponseEvent $event): void { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); $response = $event->getResponse(); $isSecure = $request->isSecure(); $basePath = $request->getBasePath() ?: '/'; foreach ($this->tokenStorage->getUsedTokens() as $key => $value) { $cookieKey = $this->cookiePrefix.$key; // The cookie already exists if ($request->cookies->has($cookieKey) && $value === $request->cookies->get($cookieKey)) { continue; } $expires = null === $value ? 1 : 0; $response->headers->setCookie( new Cookie($cookieKey, $value, $expires, $basePath, null, $isSecure, true, false, Cookie::SAMESITE_LAX) ); } }
php
{ "resource": "" }
q243578
Installer.setLegacyOptions
validation
private function setLegacyOptions(Table $table): void { if (!$table->hasOption('engine')) { $table->addOption('engine', 'MyISAM'); } if (!$table->hasOption('charset')) { $table->addOption('charset', 'utf8'); } if (!$table->hasOption('collate')) { $table->addOption('collate', 'utf8_general_ci'); } }
php
{ "resource": "" }
q243579
Versions.initialize
validation
public function initialize() { if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['enableVersioning']) { return; } $objVersion = $this->Database->prepare("SELECT COUNT(*) AS count FROM tl_version WHERE fromTable=? AND pid=?") ->limit(1) ->execute($this->strTable, $this->intPid); if ($objVersion->count > 0) { return; } $this->create(); }
php
{ "resource": "" }
q243580
Versions.renderDropdown
validation
public function renderDropdown() { $objVersion = $this->Database->prepare("SELECT tstamp, version, username, active FROM tl_version WHERE fromTable=? AND pid=? ORDER BY version DESC") ->execute($this->strTable, $this->intPid); if ($objVersion->numRows < 2) { return ''; } $versions = ''; while ($objVersion->next()) { $versions .= ' <option value="'.$objVersion->version.'"'.($objVersion->active ? ' selected="selected"' : '').'>'.$GLOBALS['TL_LANG']['MSC']['version'].' '.$objVersion->version.' ('.Date::parse(Config::get('datimFormat'), $objVersion->tstamp).') '.$objVersion->username.'</option>'; } return ' <div class="tl_version_panel"> <form action="'.ampersand(Environment::get('request'), true).'" id="tl_version" class="tl_form" method="post" aria-label="'.StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['versioning']).'"> <div class="tl_formbody"> <input type="hidden" name="FORM_SUBMIT" value="tl_version"> <input type="hidden" name="REQUEST_TOKEN" value="'.REQUEST_TOKEN.'"> <select name="version" class="tl_select">'.$versions.' </select> <button type="submit" name="showVersion" id="showVersion" class="tl_submit">'.$GLOBALS['TL_LANG']['MSC']['restore'].'</button> <a href="'.Backend::addToUrl('versions=1&amp;popup=1').'" title="'.StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['showDifferences']).'" onclick="Backend.openModalIframe({\'title\':\''.StringUtil::specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG']['MSC']['recordOfTable'], $this->intPid, $this->strTable))).'\',\'url\':this.href});return false">'.Image::getHtml('diff.svg').'</a> </div> </form> </div> '; }
php
{ "resource": "" }
q243581
Versions.getEditUrl
validation
protected function getEditUrl() { if ($this->strEditUrl !== null) { return sprintf($this->strEditUrl, $this->intPid); } $strUrl = Environment::get('request'); // Save the real edit URL if the visibility is toggled via Ajax if (preg_match('/&(amp;)?state=/', $strUrl)) { $strUrl = preg_replace ( array('/&(amp;)?id=[^&]+/', '/(&(amp;)?)t(id=[^&]+)/', '/(&(amp;)?)state=[^&]*/'), array('', '$1$3', '$1act=edit'), $strUrl ); } // Adjust the URL of the "personal data" module (see #7987) if (preg_match('/do=login(&|$)/', $strUrl)) { $strUrl = preg_replace('/do=login(&|$)/', 'do=user$1', $strUrl); $strUrl .= '&amp;act=edit&amp;id=' . $this->User->id . '&amp;rt=' . REQUEST_TOKEN; } // Correct the URL in "edit|override multiple" mode (see #7745) $strUrl = preg_replace('/act=(edit|override)All/', 'act=edit&id=' . $this->intPid, $strUrl); return $strUrl; }
php
{ "resource": "" }
q243582
Versions.getUsername
validation
protected function getUsername() { if ($this->strUsername !== null) { return $this->strUsername; } $this->import(BackendUser::class, 'User'); return $this->User->username; }
php
{ "resource": "" }
q243583
Versions.getUserId
validation
protected function getUserId() { if ($this->intUserId !== null) { return $this->intUserId; } $this->import(BackendUser::class, 'User'); return $this->User->id; }
php
{ "resource": "" }
q243584
Versions.implodeRecursive
validation
protected function implodeRecursive($var, $binary=false) { if (!\is_array($var)) { return $binary ? StringUtil::binToUuid($var) : $var; } elseif (!\is_array(current($var))) { if ($binary) { $var = array_map(function ($v) { return $v ? StringUtil::binToUuid($v) : ''; }, $var); } return implode(', ', $var); } else { $buffer = ''; foreach ($var as $k=>$v) { $buffer .= $k . ": " . $this->implodeRecursive($v) . "\n"; } return trim($buffer); } }
php
{ "resource": "" }
q243585
File.createIfNotExists
validation
protected function createIfNotExists() { // The file exists if (file_exists($this->strRootDir . '/' . $this->strFile)) { return; } // Handle open_basedir restrictions if (($strFolder = \dirname($this->strFile)) == '.') { $strFolder = ''; } // Create the folder if (!is_dir($this->strRootDir . '/' . $strFolder)) { new Folder($strFolder); } // Open the file if (!$this->resFile = $this->Files->fopen($this->strFile, 'wb')) { throw new \Exception(sprintf('Cannot create file "%s"', $this->strFile)); } }
php
{ "resource": "" }
q243586
File.truncate
validation
public function truncate() { if (\is_resource($this->resFile)) { ftruncate($this->resFile, 0); rewind($this->resFile); } return $this->write(''); }
php
{ "resource": "" }
q243587
File.close
validation
public function close() { if (\is_resource($this->resFile)) { $this->Files->fclose($this->resFile); } // Create the file path if (!file_exists($this->strRootDir . '/' . $this->strFile)) { // Handle open_basedir restrictions if (($strFolder = \dirname($this->strFile)) == '.') { $strFolder = ''; } // Create the parent folder if (!is_dir($this->strRootDir . '/' . $strFolder)) { new Folder($strFolder); } } // Move the temporary file to its destination $return = $this->Files->rename($this->strTmp, $this->strFile); $this->strTmp = null; // Update the database if (Dbafs::shouldBeSynchronized($this->strFile)) { $this->objModel = Dbafs::addResource($this->strFile); } return $return; }
php
{ "resource": "" }
q243588
File.getContent
validation
public function getContent() { $strContent = file_get_contents($this->strRootDir . '/' . ($this->strTmp ?: $this->strFile)); // Remove BOMs (see #4469) if (strncmp($strContent, "\xEF\xBB\xBF", 3) === 0) { $strContent = substr($strContent, 3); } elseif (strncmp($strContent, "\xFF\xFE", 2) === 0) { $strContent = substr($strContent, 2); } elseif (strncmp($strContent, "\xFE\xFF", 2) === 0) { $strContent = substr($strContent, 2); } return $strContent; }
php
{ "resource": "" }
q243589
File.putContent
validation
public static function putContent($strFile, $strContent) { $objFile = new static($strFile); $objFile->write($strContent); $objFile->close(); }
php
{ "resource": "" }
q243590
File.renameTo
validation
public function renameTo($strNewName) { $strParent = \dirname($strNewName); // Create the parent folder if it does not exist if (!is_dir($this->strRootDir . '/' . $strParent)) { new Folder($strParent); } $return = $this->Files->rename($this->strFile, $strNewName); // Update the database AFTER the file has been renamed $syncSource = Dbafs::shouldBeSynchronized($this->strFile); $syncTarget = Dbafs::shouldBeSynchronized($strNewName); // Synchronize the database if ($syncSource && $syncTarget) { $this->objModel = Dbafs::moveResource($this->strFile, $strNewName); } elseif ($syncSource) { $this->objModel = Dbafs::deleteResource($this->strFile); } elseif ($syncTarget) { $this->objModel = Dbafs::addResource($strNewName); } // Reset the object AFTER the database has been updated if ($return != false) { $this->strFile = $strNewName; $this->arrImageSize = array(); $this->arrPathinfo = array(); } return $return; }
php
{ "resource": "" }
q243591
File.copyTo
validation
public function copyTo($strNewName) { $strParent = \dirname($strNewName); // Create the parent folder if it does not exist if (!is_dir($this->strRootDir . '/' . $strParent)) { new Folder($strParent); } $return = $this->Files->copy($this->strFile, $strNewName); // Update the database AFTER the file has been renamed $syncSource = Dbafs::shouldBeSynchronized($this->strFile); $syncTarget = Dbafs::shouldBeSynchronized($strNewName); // Synchronize the database if ($syncSource && $syncTarget) { Dbafs::copyResource($this->strFile, $strNewName); } elseif ($syncTarget) { Dbafs::addResource($strNewName); } return $return; }
php
{ "resource": "" }
q243592
File.resizeTo
validation
public function resizeTo($width, $height, $mode='') { if (!$this->isImage) { return false; } $return = System::getContainer() ->get('contao.image.image_factory') ->create($this->strRootDir . '/' . $this->strFile, array($width, $height, $mode), $this->strRootDir . '/' . $this->strFile) ->getUrl($this->strRootDir) ; if ($return) { $this->arrPathinfo = array(); $this->arrImageSize = array(); } return $return; }
php
{ "resource": "" }
q243593
File.sendToBrowser
validation
public function sendToBrowser($filename='', $inline=false) { $response = new BinaryFileResponse($this->strRootDir . '/' . $this->strFile); $response->setContentDisposition ( $inline ? ResponseHeaderBag::DISPOSITION_INLINE : ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename, Utf8::toAscii($this->basename) ); $response->headers->addCacheControlDirective('must-revalidate'); $response->headers->addCacheControlDirective('post-check', 0); $response->headers->addCacheControlDirective('pre-check', 0); $response->headers->set('Connection', 'close'); throw new ResponseException($response); }
php
{ "resource": "" }
q243594
File.fputs
validation
protected function fputs($varData, $strMode) { if (!\is_resource($this->resFile)) { $this->strTmp = 'system/tmp/' . md5(uniqid(mt_rand(), true)); // Copy the contents of the original file to append data if (strncmp($strMode, 'a', 1) === 0 && file_exists($this->strRootDir . '/' . $this->strFile)) { $this->Files->copy($this->strFile, $this->strTmp); } // Open the temporary file if (!$this->resFile = $this->Files->fopen($this->strTmp, $strMode)) { return false; } } fwrite($this->resFile, $varData); return true; }
php
{ "resource": "" }
q243595
PageLogout.getResponse
validation
public function getResponse($objPage) { // Set last page visited if ($objPage->redirectBack) { $_SESSION['LAST_PAGE_VISITED'] = $this->getReferer(); } $strLogoutUrl = System::getContainer()->get('security.logout_url_generator')->getLogoutUrl(); $strRedirect = Environment::get('base'); // Redirect to last page visited if ($objPage->redirectBack && !empty($_SESSION['LAST_PAGE_VISITED'])) { $strRedirect = $_SESSION['LAST_PAGE_VISITED']; } // Redirect to jumpTo page elseif (($objTarget = $objPage->getRelated('jumpTo')) instanceof PageModel) { /** @var PageModel $objTarget */ $strRedirect = $objTarget->getAbsoluteUrl(); } $uri = Http::createFromString($strLogoutUrl); // Add the redirect= parameter to the logout URL $query = new Query($uri->getQuery()); $query = $query->merge('redirect=' . $strRedirect); return new RedirectResponse((string) $uri->withQuery((string) $query)); }
php
{ "resource": "" }
q243596
TokenChecker.hasFrontendUser
validation
public function hasFrontendUser(): bool { $token = $this->getToken(FrontendUser::SECURITY_SESSION_KEY); return null !== $token && $token->getUser() instanceof FrontendUser; }
php
{ "resource": "" }
q243597
TokenChecker.hasBackendUser
validation
public function hasBackendUser(): bool { $token = $this->getToken(BackendUser::SECURITY_SESSION_KEY); return null !== $token && $token->getUser() instanceof BackendUser; }
php
{ "resource": "" }
q243598
TokenChecker.getFrontendUsername
validation
public function getFrontendUsername(): ?string { $token = $this->getToken(FrontendUser::SECURITY_SESSION_KEY); if (null === $token || !$token->getUser() instanceof FrontendUser) { return null; } return $token->getUser()->getUsername(); }
php
{ "resource": "" }
q243599
TokenChecker.getBackendUsername
validation
public function getBackendUsername(): ?string { $token = $this->getToken(BackendUser::SECURITY_SESSION_KEY); if (null === $token || !$token->getUser() instanceof BackendUser) { return null; } return $token->getUser()->getUsername(); }
php
{ "resource": "" }