_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q243000
System.getSessionHash
validation
public static function getSessionHash($strCookie) { @trigger_error('Using System::getSessionHash() has been deprecated and will no longer work in Contao 5.0. Use Symfony authentication instead.', E_USER_DEPRECATED); $session = static::getContainer()->get('session'); if (!$session->isStarted()) { $session->start(); } return sha1($session->getId().$strCookie); }
php
{ "resource": "" }
q243001
System.anonymizeIp
validation
public static function anonymizeIp($strIp) { // Localhost if ($strIp == '127.0.0.1' || $strIp == '::1') { return $strIp; } // IPv6 if (strpos($strIp, ':') !== false) { return substr_replace($strIp, ':0000', strrpos($strIp, ':')); } // IPv4 else { return substr_replace($strIp, '.0', strrpos($strIp, '.')); } }
php
{ "resource": "" }
q243002
System.readPhpFileWithoutTags
validation
protected static function readPhpFileWithoutTags($strName) { @trigger_error('Using System::readPhpFileWithoutTags() has been deprecated and will no longer work in Contao 5.0. Use the Contao\CoreBundle\Config\Loader\PhpFileLoader instead.', E_USER_DEPRECATED); $rootDir = self::getContainer()->getParameter('kernel.project_dir'); // Convert to absolute path if (strpos($strName, $rootDir . '/') === false) { $strName = $rootDir . '/' . $strName; } $loader = new PhpFileLoader(); return $loader->load($strName); }
php
{ "resource": "" }
q243003
System.convertXlfToPhp
validation
public static function convertXlfToPhp($strName, $strLanguage, $blnLoad=false) { @trigger_error('Using System::convertXlfToPhp() has been deprecated and will no longer work in Contao 5.0. Use the Contao\CoreBundle\Config\Loader\XliffFileLoader instead.', E_USER_DEPRECATED); $rootDir = self::getContainer()->getParameter('kernel.project_dir'); // Convert to absolute path if (strpos($strName, $rootDir . '/') === false) { $strName = $rootDir . '/' . $strName; } $loader = new XliffFileLoader(static::getContainer()->getParameter('kernel.project_dir'), $blnLoad); return $loader->load($strName, $strLanguage); }
php
{ "resource": "" }
q243004
CommandSchedulerListener.onKernelTerminate
validation
public function onKernelTerminate(PostResponseEvent $event): void { if (!$this->framework->isInitialized() || !$this->canRunController($event->getRequest())) { return; } /** @var FrontendCron $controller */ $controller = $this->framework->createInstance(FrontendCron::class); $controller->run(); }
php
{ "resource": "" }
q243005
CommandSchedulerListener.canRunDbQuery
validation
private function canRunDbQuery(): bool { try { return $this->connection->isConnected() && $this->connection->getSchemaManager()->tablesExist(['tl_cron']); } catch (DriverException $e) { return false; } }
php
{ "resource": "" }
q243006
tl_log.colorize
validation
public function colorize($row, $label) { switch ($row['action']) { case 'CONFIGURATION': case 'REPOSITORY': $label = preg_replace('@^(.*</span> )(.*)$@U', '$1 <span class="tl_blue">$2</span>', $label); break; case 'CRON': $label = preg_replace('@^(.*</span> )(.*)$@U', '$1 <span class="tl_green">$2</span>', $label); break; case 'ERROR': $label = preg_replace('@^(.*</span> )(.*)$@U', '$1 <span class="tl_red">$2</span>', $label); break; default: if (isset($GLOBALS['TL_HOOKS']['colorizeLogEntries']) && \is_array($GLOBALS['TL_HOOKS']['colorizeLogEntries'])) { foreach ($GLOBALS['TL_HOOKS']['colorizeLogEntries'] as $callback) { $this->import($callback[0]); $label = $this->{$callback[0]}->{$callback[1]}($row, $label); } } break; } return '<div class="ellipsis">' . $label . '</div>'; }
php
{ "resource": "" }
q243007
StoreRefererListener.onKernelResponse
validation
public function onKernelResponse(FilterResponseEvent $event): void { if (!$this->scopeMatcher->isContaoMasterRequest($event)) { return; } $request = $event->getRequest(); if (!$request->isMethod(Request::METHOD_GET)) { return; } $response = $event->getResponse(); if (200 !== $response->getStatusCode()) { return; } $token = $this->tokenStorage->getToken(); if (null === $token || $this->authenticationTrustResolver->isAnonymous($token)) { return; } if ($this->scopeMatcher->isBackendRequest($request)) { $this->storeBackendReferer($request); } else { $this->storeFrontendReferer($request); } }
php
{ "resource": "" }
q243008
StoreRefererListener.getRelativeRequestUri
validation
private function getRelativeRequestUri(Request $request): string { return (string) substr($request->getRequestUri(), \strlen($request->getBasePath()) + 1); }
php
{ "resource": "" }
q243009
tl_news.listNewsArticles
validation
public function listNewsArticles($arrRow) { return '<div class="tl_content_left">' . $arrRow['headline'] . ' <span style="color:#999;padding-left:3px">[' . Contao\Date::parse(Contao\Config::get('datimFormat'), $arrRow['date']) . ']</span></div>'; }
php
{ "resource": "" }
q243010
Widget.__isset
validation
public function __isset($strKey) { switch ($strKey) { case 'id': return isset($this->strId); break; case 'name': return isset($this->strName); break; case 'label': return isset($this->strLabel); break; case 'value': return isset($this->varValue); break; case 'class': return isset($this->strClass); break; case 'template': return isset($this->strTemplate); break; case 'wizard': return isset($this->strWizard); break; case 'required': return isset($this->arrConfiguration[$strKey]); break; case 'forAttribute': return isset($this->blnForAttribute); break; case 'dataContainer': return isset($this->objDca); break; case 'activeRecord': return isset($this->objDca->activeRecord); break; default: return isset($this->arrAttributes[$strKey]) || isset($this->arrConfiguration[$strKey]); break; } }
php
{ "resource": "" }
q243011
Widget.getErrorsAsString
validation
public function getErrorsAsString($strSeparator=null) { if ($strSeparator === null) { $strSeparator = '<br' . $this->strTagEnding . "\n"; } return $this->hasErrors() ? implode($strSeparator, $this->arrErrors) : ''; }
php
{ "resource": "" }
q243012
Widget.generateWithError
validation
public function generateWithError($blnSwitchOrder=false) { $strWidget = $this->generate(); $strError = $this->getErrorAsHTML(); return $blnSwitchOrder ? $strWidget . $strError : $strError . $strWidget; }
php
{ "resource": "" }
q243013
Widget.getAttribute
validation
public function getAttribute($strKey) { if (!isset($this->arrAttributes[$strKey])) { return ''; } $varValue = $this->arrAttributes[$strKey]; // Prevent the autofocus attribute from being added multiple times (see #8281) if ($strKey == 'autofocus') { unset($this->arrAttributes[$strKey]); } if ($strKey == 'disabled' || $strKey == 'readonly' || $strKey == 'required' || $strKey == 'autofocus' || $strKey == 'multiple') { return ' ' . $strKey; } elseif ($varValue != '') { return ' ' . $strKey . '="' . StringUtil::specialchars($varValue) . '"'; } return ''; }
php
{ "resource": "" }
q243014
Widget.validate
validation
public function validate() { $varValue = $this->validator($this->getPost($this->strName)); if ($this->hasErrors()) { $this->class = 'error'; } $this->varValue = $varValue; }
php
{ "resource": "" }
q243015
Widget.addAttributes
validation
public function addAttributes($arrAttributes) { if (!\is_array($arrAttributes)) { return; } foreach ($arrAttributes as $k=>$v) { $this->$k = $v; } }
php
{ "resource": "" }
q243016
Widget.isChecked
validation
protected function isChecked($arrOption) { if (empty($this->varValue) && empty($_POST) && $arrOption['default']) { return static::optionChecked(1, 1); } return static::optionChecked($arrOption['value'], $this->varValue); }
php
{ "resource": "" }
q243017
Widget.isSelected
validation
protected function isSelected($arrOption) { if (empty($this->varValue) && empty($_POST) && $arrOption['default']) { return static::optionSelected(1, 1); } return static::optionSelected($arrOption['value'], $this->varValue); }
php
{ "resource": "" }
q243018
Widget.optionSelected
validation
public static function optionSelected($strOption, $varValues) { if ($strOption === '') { return ''; } return (\is_array($varValues) ? \in_array($strOption, $varValues) : $strOption == $varValues) ? ' selected' : ''; }
php
{ "resource": "" }
q243019
Widget.optionChecked
validation
public static function optionChecked($strOption, $varValues) { if ($strOption === '') { return ''; } return (\is_array($varValues) ? \in_array($strOption, $varValues) : $strOption == $varValues) ? ' checked' : ''; }
php
{ "resource": "" }
q243020
Widget.getEmptyStringOrNull
validation
public function getEmptyStringOrNull() { if (!isset($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['sql'])) { return ''; } return static::getEmptyStringOrNullByFieldType($GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['sql']); }
php
{ "resource": "" }
q243021
ModuleCalendar.generate
validation
public function generate() { if (TL_MODE == 'BE') { $objTemplate = new BackendTemplate('be_wildcard'); $objTemplate->wildcard = '### ' . Utf8::strtoupper($GLOBALS['TL_LANG']['FMD']['calendar'][0]) . ' ###'; $objTemplate->title = $this->headline; $objTemplate->id = $this->id; $objTemplate->link = $this->name; $objTemplate->href = 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' . $this->id; return $objTemplate->parse(); } $this->cal_calendar = $this->sortOutProtected(StringUtil::deserialize($this->cal_calendar, true)); // Return if there are no calendars if (empty($this->cal_calendar) || !\is_array($this->cal_calendar)) { return ''; } $this->strUrl = preg_replace('/\?.*$/', '', Environment::get('request')); $this->strLink = $this->strUrl; if (($objTarget = $this->objModel->getRelated('jumpTo')) instanceof PageModel) { /** @var PageModel $objTarget */ $this->strLink = $objTarget->getFrontendUrl(); } return parent::generate(); }
php
{ "resource": "" }
q243022
Validator.isInsecurePath
validation
public static function isInsecurePath($strPath) { // Normalize backslashes $strPath = strtr($strPath, '\\', '/'); $strPath = preg_replace('#//+#', '/', $strPath); // Equals .. if ($strPath == '..') { return true; } // Begins with ./ if (substr($strPath, 0, 2) == './') { return true; } // Begins with ../ if (substr($strPath, 0, 3) == '../') { return true; } // Ends with /. if (substr($strPath, -2) == '/.') { return true; } // Ends with /.. if (substr($strPath, -3) == '/..') { return true; } // Contains /../ if (strpos($strPath, '/../') !== false) { return true; } return false; }
php
{ "resource": "" }
q243023
Validator.isValidFileName
validation
public static function isValidFileName($strName) { if ($strName == '') { return false; } // Special characters not supported on e.g. Windows if (preg_match('@[\\\\/:*?"<>|]@', $strName)) { return false; } // Invisible control characters or unused code points if (preg_match('/[\pC]/u', $strName) !== 0) { return false; } // Must not be longer than 255 characters if (Utf8::strlen($strName) > 255) { return false; } return true; }
php
{ "resource": "" }
q243024
ModuleNewsList.countItems
validation
protected function countItems($newsArchives, $blnFeatured) { // HOOK: add custom logic if (isset($GLOBALS['TL_HOOKS']['newsListCountItems']) && \is_array($GLOBALS['TL_HOOKS']['newsListCountItems'])) { foreach ($GLOBALS['TL_HOOKS']['newsListCountItems'] as $callback) { if (($intResult = System::importStatic($callback[0])->{$callback[1]}($newsArchives, $blnFeatured, $this)) === false) { continue; } if (\is_int($intResult)) { return $intResult; } } } return NewsModel::countPublishedByPids($newsArchives, $blnFeatured); }
php
{ "resource": "" }
q243025
ModuleNewsList.fetchItems
validation
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 Collection) { return $objCollection; } } } // Determine sorting $t = NewsModel::getTable(); $arrOptions = array(); switch ($this->news_order) { case 'order_headline_asc': $arrOptions['order'] = "$t.headline"; break; case 'order_headline_desc': $arrOptions['order'] = "$t.headline DESC"; break; case 'order_random': $arrOptions['order'] = "RAND()"; break; case 'order_date_asc': $arrOptions['order'] = "$t.date"; break; default: $arrOptions['order'] = "$t.date DESC"; } return NewsModel::findPublishedByPids($newsArchives, $blnFeatured, $limit, $offset, $arrOptions); }
php
{ "resource": "" }
q243026
ContaoCache.isRequestPrivate
validation
private function isRequestPrivate(Request $request): bool { if ($request->headers->has('Authorization')) { return true; } if (\count($request->cookies->all())) { return true; } return false; }
php
{ "resource": "" }
q243027
tl_article.generateAlias
validation
public function generateAlias($varValue, Contao\DataContainer $dc) { $aliasExists = function (string $alias) use ($dc): bool { if (\in_array($alias, array('top', 'wrapper', 'header', 'container', 'main', 'left', 'right', 'footer'), true)) { return true; } return $this->Database->prepare("SELECT id FROM tl_article WHERE alias=? AND id!=?")->execute($alias, $dc->id)->numRows > 0; }; // Generate an alias if there is none if ($varValue == '') { $varValue = Contao\System::getContainer()->get('contao.slug')->generate($dc->activeRecord->title, $dc->activeRecord->pid, $aliasExists); } elseif ($aliasExists($varValue)) { throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); } return $varValue; }
php
{ "resource": "" }
q243028
tl_article.getActiveLayoutSections
validation
public function getActiveLayoutSections(Contao\DataContainer $dc) { // Show only active sections if ($dc->activeRecord->pid) { $arrSections = array(); $objPage = Contao\PageModel::findWithDetails($dc->activeRecord->pid); // Get the layout sections if ($objPage->layout) { $objLayout = Contao\LayoutModel::findByPk($objPage->layout); if ($objLayout === null) { return array(); } $arrModules = Contao\StringUtil::deserialize($objLayout->modules); if (empty($arrModules) || !\is_array($arrModules)) { return array(); } // Find all sections with an article module (see #6094) foreach ($arrModules as $arrModule) { if ($arrModule['mod'] == 0 && $arrModule['enable']) { $arrSections[] = $arrModule['col']; } } } } // Show all sections (e.g. "override all" mode) else { $arrSections = array('header', 'left', 'right', 'main', 'footer'); $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": "" }
q243029
tl_article.editArticle
validation
public function editArticle($row, $href, $label, $title, $icon, $attributes) { $objPage = Contao\PageModel::findById($row['pid']); return $this->User->isAllowed(Contao\BackendUser::CAN_EDIT_ARTICLES, $objPage->row()) ? '<a href="'.$this->addToUrl($href.'&amp;id='.$row['id']).'" title="'.Contao\StringUtil::specialchars($title).'"'.$attributes.'>'.Contao\Image::getHtml($icon, $label).'</a> ' : Contao\Image::getHtml(preg_replace('/\.svg$/i', '_.svg', $icon)).' '; }
php
{ "resource": "" }
q243030
tl_article.pasteArticle
validation
public function pasteArticle(Contao\DataContainer $dc, $row, $table, $cr, $arrClipboard=null) { $imagePasteAfter = Contao\Image::getHtml('pasteafter.svg', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id'])); $imagePasteInto = Contao\Image::getHtml('pasteinto.svg', sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteinto'][1], $row['id'])); if ($table == $GLOBALS['TL_DCA'][$dc->table]['config']['ptable']) { return ($row['type'] == 'root' || !$this->User->isAllowed(Contao\BackendUser::CAN_EDIT_ARTICLE_HIERARCHY, $row) || $cr) ? Contao\Image::getHtml('pasteinto_.svg').' ' : '<a href="'.$this->addToUrl('act='.$arrClipboard['mode'].'&amp;mode=2&amp;pid='.$row['id'].(!\is_array($arrClipboard['id']) ? '&amp;id='.$arrClipboard['id'] : '')).'" title="'.Contao\StringUtil::specialchars(sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteinto'][1], $row['id'])).'" onclick="Backend.getScrollOffset()">'.$imagePasteInto.'</a> '; } $objPage = Contao\PageModel::findById($row['pid']); return (($arrClipboard['mode'] == 'cut' && $arrClipboard['id'] == $row['id']) || ($arrClipboard['mode'] == 'cutAll' && \in_array($row['id'], $arrClipboard['id'])) || !$this->User->isAllowed(Contao\BackendUser::CAN_EDIT_ARTICLE_HIERARCHY, $objPage->row()) || $cr) ? Contao\Image::getHtml('pasteafter_.svg').' ' : '<a href="'.$this->addToUrl('act='.$arrClipboard['mode'].'&amp;mode=1&amp;pid='.$row['id'].(!\is_array($arrClipboard['id']) ? '&amp;id='.$arrClipboard['id'] : '')).'" title="'.Contao\StringUtil::specialchars(sprintf($GLOBALS['TL_LANG'][$dc->table]['pasteafter'][1], $row['id'])).'" onclick="Backend.getScrollOffset()">'.$imagePasteAfter.'</a> '; }
php
{ "resource": "" }
q243031
UrlGenerator.prepareAlias
validation
private function prepareAlias(string $alias, array &$parameters): void { if ('index' === $alias) { return; } $hasAutoItem = false; $autoItems = $this->getAutoItems($parameters); /** @var Config $config */ $config = $this->framework->getAdapter(Config::class); $parameters['alias'] = preg_replace_callback( '/\{([^\}]+)\}/', static function (array $matches) use ($alias, &$parameters, $autoItems, &$hasAutoItem, $config): string { $param = $matches[1]; if (!isset($parameters[$param])) { throw new MissingMandatoryParametersException( sprintf('Parameters "%s" is missing to generate a URL for "%s"', $param, $alias) ); } $value = $parameters[$param]; unset($parameters[$param]); if ($hasAutoItem || !$config->get('useAutoItem') || !\in_array($param, $autoItems, true)) { return $param.'/'.$value; } $hasAutoItem = true; return $value; }, $alias ); }
php
{ "resource": "" }
q243032
UrlGenerator.prepareDomain
validation
private function prepareDomain(RequestContext $context, array &$parameters, int &$referenceType): void { if (isset($parameters['_ssl'])) { $context->setScheme(true === $parameters['_ssl'] ? 'https' : 'http'); } if (isset($parameters['_domain']) && '' !== $parameters['_domain']) { $this->addHostToContext($context, $parameters, $referenceType); } unset($parameters['_domain'], $parameters['_ssl']); }
php
{ "resource": "" }
q243033
UrlGenerator.addHostToContext
validation
private function addHostToContext(RequestContext $context, array $parameters, int &$referenceType): void { [$host, $port] = $this->getHostAndPort($parameters['_domain']); if ($context->getHost() === $host) { return; } $context->setHost($host); $referenceType = UrlGeneratorInterface::ABSOLUTE_URL; if (!$port) { return; } if (isset($parameters['_ssl']) && true === $parameters['_ssl']) { $context->setHttpsPort($port); } else { $context->setHttpPort($port); } }
php
{ "resource": "" }
q243034
UrlGenerator.getHostAndPort
validation
private function getHostAndPort(string $domain): array { if (false !== strpos($domain, ':')) { return explode(':', $domain, 2); } return [$domain, null]; }
php
{ "resource": "" }
q243035
UrlGenerator.getAutoItems
validation
private function getAutoItems(array $parameters): array { if (isset($parameters['auto_item'])) { return [$parameters['auto_item']]; } if (isset($GLOBALS['TL_AUTO_ITEM']) && \is_array($GLOBALS['TL_AUTO_ITEM'])) { return $GLOBALS['TL_AUTO_ITEM']; } return []; }
php
{ "resource": "" }
q243036
FrontendLoader.addFrontendRoute
validation
private function addFrontendRoute(RouteCollection $routes, array $defaults): void { $route = new Route('/{alias}'.$this->urlSuffix, $defaults, ['alias' => '.+']); $this->addLocaleToRoute($route); $routes->add('contao_frontend', $route); }
php
{ "resource": "" }
q243037
FrontendLoader.addIndexRoute
validation
private function addIndexRoute(RouteCollection $routes, array $defaults): void { $route = new Route('/', $defaults); $this->addLocaleToRoute($route); $routes->add('contao_index', $route); }
php
{ "resource": "" }
q243038
FrontendLoader.addLocaleToRoute
validation
private function addLocaleToRoute(Route $route): void { if (!$this->prependLocale) { return; } $route->setPath('/{_locale}'.$route->getPath()); $route->addRequirements(['_locale' => '[a-z]{2}(\-[A-Z]{2})?']); }
php
{ "resource": "" }
q243039
ContentElement.findClass
validation
public static function findClass($strName) { foreach ($GLOBALS['TL_CTE'] as $v) { foreach ($v as $kk=>$vv) { if ($kk == $strName) { return $vv; } } } return ''; }
php
{ "resource": "" }
q243040
DataContainer.help
validation
public function help($strClass='') { $return = $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['label'][1]; if (!Config::get('showHelp') || $GLOBALS['TL_DCA'][$this->strTable]['fields'][$this->strField]['inputType'] == 'password' || $return == '') { return ''; } return ' <p class="tl_help tl_tip' . $strClass . '">'.$return.'</p>'; }
php
{ "resource": "" }
q243041
DataContainer.combiner
validation
protected function combiner($names) { $return = array(''); $names = array_values($names); for ($i=0, $c=\count($names); $i<$c; $i++) { $buffer = array(); foreach ($return as $k=>$v) { $buffer[] = ($k%2 == 0) ? $v : $v.$names[$i]; $buffer[] = ($k%2 == 0) ? $v.$names[$i] : $v; } $return = $buffer; } return array_filter($return); }
php
{ "resource": "" }
q243042
DataContainer.switchToEdit
validation
protected function switchToEdit($id) { $arrKeys = array(); $arrUnset = array('act', 'id', 'table'); foreach (array_keys($_GET) as $strKey) { if (!\in_array($strKey, $arrUnset)) { $arrKeys[$strKey] = $strKey . '=' . Input::get($strKey); } } $strUrl = TL_SCRIPT . '?' . implode('&', $arrKeys); return $strUrl . (!empty($arrKeys) ? '&' : '') . (Input::get('table') ? 'table='.Input::get('table').'&amp;' : '').'act=edit&amp;id='.rawurlencode($id); }
php
{ "resource": "" }
q243043
DataContainer.initPicker
validation
public function initPicker(PickerInterface $picker) { if (!empty($_GET['act'])) { return null; } $provider = $picker->getCurrentProvider(); if (!$provider instanceof DcaPickerProviderInterface || $provider->getDcaTable() != $this->strTable) { return null; } $attributes = $provider->getDcaAttributes($picker->getConfig()); $this->objPicker = $picker; $this->strPickerFieldType = $attributes['fieldType']; $this->objPickerCallback = function ($value) use ($picker, $provider) { return $provider->convertDcaValue($picker->getConfig(), $value); }; if (isset($attributes['value'])) { $this->arrPickerValue = (array) $attributes['value']; } return $attributes; }
php
{ "resource": "" }
q243044
DataContainer.getPickerInputField
validation
protected function getPickerInputField($value, $attributes='') { $id = is_numeric($value) ? $value : md5($value); switch ($this->strPickerFieldType) { case 'checkbox': return ' <input type="checkbox" name="picker[]" id="picker_'.$id.'" class="tl_tree_checkbox" value="'.StringUtil::specialchars(\call_user_func($this->objPickerCallback, $value)).'" onfocus="Backend.getScrollOffset()"'.Widget::optionChecked($value, $this->arrPickerValue).$attributes.'>'; case 'radio': return ' <input type="radio" name="picker" id="picker_'.$id.'" class="tl_tree_radio" value="'.StringUtil::specialchars(\call_user_func($this->objPickerCallback, $value)).'" onfocus="Backend.getScrollOffset()"'.Widget::optionChecked($value, $this->arrPickerValue).$attributes.'>'; } return ''; }
php
{ "resource": "" }
q243045
DataContainer.invalidateCacheTags
validation
protected function invalidateCacheTags(self $dc) { if (!System::getContainer()->has('fos_http_cache.cache_manager')) { return; } $ns = 'contao.db.'; $tags = array($ns . $dc->table, $ns . $dc->table . '.' . $dc->id); if ($dc->ptable && $dc->activeRecord && $dc->activeRecord->pid > 0) { $tags[] = $ns . $dc->ptable; $tags[] = $ns . $dc->ptable . '.' . $dc->activeRecord->pid; } // Trigger the oninvalidate_cache_tags_callback if (\is_array($GLOBALS['TL_DCA'][$dc->table]['config']['oninvalidate_cache_tags_callback'])) { foreach ($GLOBALS['TL_DCA'][$dc->table]['config']['oninvalidate_cache_tags_callback'] as $callback) { if (\is_array($callback)) { $this->import($callback[0]); $tags = $this->{$callback[0]}->{$callback[1]}($dc, $tags); } elseif (\is_callable($callback)) { $tags = $callback($dc, $tags); } } } // Make sure tags are unique and empty ones are removed $tags = array_filter(array_unique($tags)); /** @var CacheManager $cacheManager */ $cacheManager = System::getContainer()->get('fos_http_cache.cache_manager'); $cacheManager->invalidateTags($tags); }
php
{ "resource": "" }
q243046
tl_member.getActiveGroups
validation
public function getActiveGroups() { $arrGroups = array(); $objGroup = Contao\MemberGroupModel::findAllActive(); if ($objGroup !== null) { while ($objGroup->next()) { $arrGroups[$objGroup->id] = $objGroup->name; } } return $arrGroups; }
php
{ "resource": "" }
q243047
tl_member.setNewPassword
validation
public function setNewPassword($strPassword, $user) { // Return if there is no user (e.g. upon registration) if (!$user) { return $strPassword; } $objUser = $this->Database->prepare("SELECT * FROM tl_member WHERE id=?") ->limit(1) ->execute($user->id); // HOOK: set new password callback if ($objUser->numRows) { if (isset($GLOBALS['TL_HOOKS']['setNewPassword']) && \is_array($GLOBALS['TL_HOOKS']['setNewPassword'])) { foreach ($GLOBALS['TL_HOOKS']['setNewPassword'] as $callback) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($objUser, $strPassword); } } } return $strPassword; }
php
{ "resource": "" }
q243048
tl_member.storeDateAdded
validation
public function storeDateAdded($dc) { // Front end call if (!$dc instanceof Contao\DataContainer) { return; } // Return if there is no active record (override all) if (!$dc->activeRecord || $dc->activeRecord->dateAdded > 0) { return; } // Fallback solution for existing accounts if ($dc->activeRecord->lastLogin > 0) { $time = $dc->activeRecord->lastLogin; } else { $time = time(); } $this->Database->prepare("UPDATE tl_member SET dateAdded=? WHERE id=?") ->execute($time, $dc->id); }
php
{ "resource": "" }
q243049
tl_content.getContentElements
validation
public function getContentElements() { $groups = array(); foreach ($GLOBALS['TL_CTE'] as $k=>$v) { foreach (array_keys($v) as $kk) { $groups[$k][] = $kk; } } return $groups; }
php
{ "resource": "" }
q243050
tl_content.getContentElementGroup
validation
public function getContentElementGroup($element) { foreach ($GLOBALS['TL_CTE'] as $k=>$v) { foreach (array_keys($v) as $kk) { if ($kk == $element) { return $k; } } } return null; }
php
{ "resource": "" }
q243051
tl_content.adjustDcaByType
validation
public function adjustDcaByType($dc) { $objCte = Contao\ContentModel::findByPk($dc->id); if ($objCte === null) { return; } switch ($objCte->type) { case 'hyperlink': unset($GLOBALS['TL_DCA']['tl_content']['fields']['imageUrl']); break; case 'image': $GLOBALS['TL_DCA']['tl_content']['fields']['imagemargin']['eval']['tl_class'] .= ' clr'; break; } }
php
{ "resource": "" }
q243052
tl_content.addCteType
validation
public function addCteType($arrRow) { $key = $arrRow['invisible'] ? 'unpublished' : 'published'; $type = $GLOBALS['TL_LANG']['CTE'][$arrRow['type']][0] ?: '&nbsp;'; $class = 'limit_height'; // Remove the class if it is a wrapper element if (\in_array($arrRow['type'], $GLOBALS['TL_WRAPPERS']['start']) || \in_array($arrRow['type'], $GLOBALS['TL_WRAPPERS']['separator']) || \in_array($arrRow['type'], $GLOBALS['TL_WRAPPERS']['stop'])) { $class = ''; if (($group = $this->getContentElementGroup($arrRow['type'])) !== null) { $type = $GLOBALS['TL_LANG']['CTE'][$group] . ' (' . $type . ')'; } } // Add the group name if it is a single element (see #5814) elseif (\in_array($arrRow['type'], $GLOBALS['TL_WRAPPERS']['single'])) { if (($group = $this->getContentElementGroup($arrRow['type'])) !== null) { $type = $GLOBALS['TL_LANG']['CTE'][$group] . ' (' . $type . ')'; } } // Add the ID of the aliased element if ($arrRow['type'] == 'alias') { $type .= ' ID ' . $arrRow['cteAlias']; } // Add the protection status if ($arrRow['protected']) { $type .= ' (' . $GLOBALS['TL_LANG']['MSC']['protected'] . ')'; } elseif ($arrRow['guests']) { $type .= ' (' . $GLOBALS['TL_LANG']['MSC']['guests'] . ')'; } // Add the headline level (see #5858) if ($arrRow['type'] == 'headline') { if (\is_array($headline = Contao\StringUtil::deserialize($arrRow['headline']))) { $type .= ' (' . $headline['unit'] . ')'; } } // Limit the element's height if (!Contao\Config::get('doNotCollapse')) { $class .= ' h40'; } $objModel = new Contao\ContentModel(); $objModel->setRow($arrRow); return ' <div class="cte_type ' . $key . '">' . $type . '</div> <div class="' . trim($class) . '"> ' . Contao\StringUtil::insertTagToSrc($this->getContentElement($objModel)) . ' </div>' . "\n"; }
php
{ "resource": "" }
q243053
tl_content.getForms
validation
public function getForms() { if (!$this->User->isAdmin && !\is_array($this->User->forms)) { return array(); } $arrForms = array(); $objForms = $this->Database->execute("SELECT id, title FROM tl_form ORDER BY title"); while ($objForms->next()) { if ($this->User->hasAccess($objForms->id, 'forms')) { $arrForms[$objForms->id] = $objForms->title . ' (ID ' . $objForms->id . ')'; } } return $arrForms; }
php
{ "resource": "" }
q243054
tl_content.setRteSyntax
validation
public function setRteSyntax($varValue, Contao\DataContainer $dc) { switch ($dc->activeRecord->highlight) { case 'C': case 'CSharp': $syntax = 'c_cpp'; break; case 'CSS': case 'Diff': case 'Groovy': case 'HTML': case 'Java': case 'JavaScript': case 'Perl': case 'PHP': case 'PowerShell': case 'Python': case 'Ruby': case 'Scala': case 'SQL': case 'Text': case 'YAML': $syntax = strtolower($dc->activeRecord->highlight); break; case 'VB': $syntax = 'vbscript'; break; case 'XML': case 'XHTML': $syntax = 'xml'; break; default: $syntax = 'text'; break; } if ($dc->activeRecord->type == 'markdown') { $syntax = 'markdown'; } $GLOBALS['TL_DCA']['tl_content']['fields']['code']['eval']['rte'] = 'ace|' . $syntax; return $varValue; }
php
{ "resource": "" }
q243055
tl_content.listImportWizard
validation
public function listImportWizard() { return ' <a href="' . $this->addToUrl('key=list') . '" title="' . Contao\StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['lw_import'][1]) . '" onclick="Backend.getScrollOffset()">' . Contao\Image::getHtml('tablewizard.svg', $GLOBALS['TL_LANG']['MSC']['tw_import'][0]) . '</a>'; }
php
{ "resource": "" }
q243056
tl_content.tableImportWizard
validation
public function tableImportWizard() { return ' <a href="' . $this->addToUrl('key=table') . '" title="' . Contao\StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['tw_import'][1]) . '" onclick="Backend.getScrollOffset()">' . Contao\Image::getHtml('tablewizard.svg', $GLOBALS['TL_LANG']['MSC']['tw_import'][0]) . '</a> ' . Contao\Image::getHtml('demagnify.svg', '', 'title="' . Contao\StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['tw_shrink']) . '" style="cursor:pointer" onclick="Backend.tableWizardResize(0.9)"') . Contao\Image::getHtml('magnify.svg', '', 'title="' . Contao\StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['tw_expand']) . '" style="cursor:pointer" onclick="Backend.tableWizardResize(1.1)"'); }
php
{ "resource": "" }
q243057
tl_content.pagePicker
validation
public function pagePicker(Contao\DataContainer $dc) { @trigger_error('Using tl_content::pagePicker() has been deprecated and will no longer work in Contao 5.0. Set the "dcaPicker" eval attribute instead.', E_USER_DEPRECATED); return Contao\Backend::getDcaPickerWizard(true, $dc->table, $dc->field, $dc->inputName); }
php
{ "resource": "" }
q243058
tl_content.deleteElement
validation
public function deleteElement($row, $href, $label, $title, $icon, $attributes) { $objElement = $this->Database->prepare("SELECT id FROM tl_content WHERE cteAlias=? AND type='alias'") ->limit(1) ->execute($row['id']); return $objElement->numRows ? Contao\Image::getHtml(preg_replace('/\.svg$/i', '_.svg', $icon)) . ' ' : '<a href="'.$this->addToUrl($href.'&amp;id='.$row['id']).'" title="'.Contao\StringUtil::specialchars($title).'"'.$attributes.'>'.Contao\Image::getHtml($icon, $label).'</a> '; }
php
{ "resource": "" }
q243059
tl_content.setSingleSrcFlags
validation
public function setSingleSrcFlags($varValue, Contao\DataContainer $dc) { if ($dc->activeRecord) { switch ($dc->activeRecord->type) { case 'text': case 'hyperlink': case 'image': case 'accordionSingle': $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['extensions'] = Contao\Config::get('validImageTypes'); break; case 'download': $GLOBALS['TL_DCA'][$dc->table]['fields'][$dc->field]['eval']['extensions'] = Contao\Config::get('allowedDownload'); break; } } return $varValue; }
php
{ "resource": "" }
q243060
tl_content.extractYouTubeId
validation
public function extractYouTubeId($varValue, Contao\DataContainer $dc) { if ($dc->activeRecord->youtube != $varValue) { $matches = array(); if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $varValue, $matches)) { $varValue = $matches[1]; } } return $varValue; }
php
{ "resource": "" }
q243061
tl_content.extractVimeoId
validation
public function extractVimeoId($varValue, Contao\DataContainer $dc) { if ($dc->activeRecord->vimeo != $varValue) { $matches = array(); if (preg_match('%vimeo\.com/(?:channels/(?:\w+/)?|groups/(?:[^/]+)/videos/|album/(?:\d+)/video/)?(\d+)(?:$|/|\?)%i', $varValue, $matches)) { $varValue = $matches[1]; } } return $varValue; }
php
{ "resource": "" }
q243062
ModuleQuicknav.getQuicknavPages
validation
protected function getQuicknavPages($pid, $level=1, $host=null) { /** @var PageModel $objPage */ global $objPage; $groups = array(); $arrPages = array(); // Get all groups of the current front end user if (FE_USER_LOGGED_IN) { $this->import(FrontendUser::class, 'User'); $groups = $this->User->groups; } // Get all active subpages $objSubpages = PageModel::findPublishedRegularWithoutGuestsByPid($pid); if ($objSubpages === null) { return array(); } ++$level; foreach ($objSubpages as $objSubpage) { $_groups = StringUtil::deserialize($objSubpage->groups); // Override the domain (see #3765) if ($host !== null) { $objSubpage->domain = $host; } // Do not show protected pages unless a front end user is logged in if (!$objSubpage->protected || $this->showProtected || (\is_array($_groups) && \is_array($groups) && array_intersect($_groups, $groups))) { // Do not skip the current page here! (see #4523) // Check hidden pages if (!$objSubpage->hide || $this->showHidden) { $arrPages[] = array ( 'level' => ($level - 2), 'title' => StringUtil::specialchars(StringUtil::stripInsertTags($objSubpage->pageTitle ?: $objSubpage->title)), 'href' => $objSubpage->getFrontendUrl(), 'link' => StringUtil::stripInsertTags($objSubpage->title), 'active' => ($objPage->id == $objSubpage->id || ($objSubpage->type == 'forward' && $objPage->id == $objSubpage->jumpTo)) ); // Subpages if (!$this->showLevel || $this->showLevel >= $level || (!$this->hardLimit && ($objPage->id == $objSubpage->id || \in_array($objPage->id, $this->Database->getChildRecords($objSubpage->id, 'tl_page'))))) { $subpages = $this->getQuicknavPages($objSubpage->id, $level); if (\is_array($subpages)) { $arrPages = array_merge($arrPages, $subpages); } } } } } return $arrPages; }
php
{ "resource": "" }
q243063
tl_image_size.adjustPermissions
validation
public function adjustPermissions($insertId) { // The oncreate_callback passes $insertId as second argument if (\func_num_args() == 4) { $insertId = func_get_arg(1); } if ($this->User->isAdmin) { return; } // Set the image sizes if (empty($this->User->imageSizes) || !\is_array($this->User->imageSizes)) { $imageSizes = array(); } else { $imageSizes = $this->User->imageSizes; } // The image size is enabled already if (\in_array($insertId, $imageSizes)) { return; } /** @var Symfony\Component\HttpFoundation\Session\Attribute\AttributeBagInterface $objSessionBag */ $objSessionBag = Contao\System::getContainer()->get('session')->getBag('contao_backend'); $arrNew = $objSessionBag->get('new_records'); if (\is_array($arrNew['tl_image_size']) && \in_array($insertId, $arrNew['tl_image_size'])) { // Add the permissions on group level if ($this->User->inherit != 'custom') { $objGroup = $this->Database->execute("SELECT id, themes, imageSizes FROM tl_user_group WHERE id IN(" . implode(',', array_map('\intval', $this->User->groups)) . ")"); while ($objGroup->next()) { $arrThemes = Contao\StringUtil::deserialize($objGroup->themes); if (\is_array($arrThemes) && \in_array('image_sizes', $arrThemes)) { $arrImageSizes = Contao\StringUtil::deserialize($objGroup->imageSizes, true); $arrImageSizes[] = $insertId; $this->Database->prepare("UPDATE tl_user_group SET imageSizes=? WHERE id=?") ->execute(serialize($arrImageSizes), $objGroup->id); } } } // Add the permissions on user level if ($this->User->inherit != 'group') { $objUser = $this->Database->prepare("SELECT themes, imageSizes FROM tl_user WHERE id=?") ->limit(1) ->execute($this->User->id); $arrThemes = Contao\StringUtil::deserialize($objUser->themes); if (\is_array($arrThemes) && \in_array('image_sizes', $arrThemes)) { $arrImageSizes = Contao\StringUtil::deserialize($objUser->imageSizes, true); $arrImageSizes[] = $insertId; $this->Database->prepare("UPDATE tl_user SET imageSizes=? WHERE id=?") ->execute(serialize($arrImageSizes), $this->User->id); } } // Add the new element to the user object $imageSizes[] = $insertId; $this->User->imageSizes = $imageSizes; } }
php
{ "resource": "" }
q243064
tl_image_size.listImageSize
validation
public function listImageSize($row) { $html = '<div class="tl_content_left">'; $html .= $row['name']; if ($row['width'] || $row['height']) { $html .= ' <span style="color:#999;padding-left:3px">' . $row['width'] . 'x' . $row['height'] . '</span>'; } if ($row['zoom']) { $html .= ' <span style="color:#999;padding-left:3px">(' . (int) $row['zoom'] . '%)</span>'; } $html .= "</div>\n"; return $html; }
php
{ "resource": "" }
q243065
Model.originalRow
validation
public function originalRow() { $row = $this->row(); if (!$this->isModified()) { return $row; } $originalRow = array(); foreach ($row as $k=>$v) { $originalRow[$k] = $this->arrModified[$k] ?? $v; } return $originalRow; }
php
{ "resource": "" }
q243066
Model.setRow
validation
public function setRow(array $arrData) { foreach ($arrData as $k=>$v) { if (strpos($k, '__') !== false) { unset($arrData[$k]); } } $this->arrData = $arrData; return $this; }
php
{ "resource": "" }
q243067
Model.mergeRow
validation
public function mergeRow(array $arrData) { foreach ($arrData as $k=>$v) { if (strpos($k, '__') !== false) { continue; } if (!isset($this->arrModified[$k])) { $this->arrData[$k] = $v; } } return $this; }
php
{ "resource": "" }
q243068
Model.markModified
validation
public function markModified($strKey) { if (!isset($this->arrModified[$strKey])) { $this->arrModified[$strKey] = $this->arrData[$strKey] ?? null; } }
php
{ "resource": "" }
q243069
Model.save
validation
public function save() { // Deprecated call if (\count(\func_get_args())) { throw new \InvalidArgumentException('The $blnForceInsert argument has been removed (see system/docs/UPGRADE.md)'); } // The instance cannot be saved if ($this->blnPreventSaving) { throw new \RuntimeException('The model instance has been detached and cannot be saved'); } $objDatabase = Database::getInstance(); $arrFields = $objDatabase->getFieldNames(static::$strTable); // The model is in the registry if (Registry::getInstance()->isRegistered($this)) { $arrSet = array(); $arrRow = $this->row(); // Only update modified fields foreach ($this->arrModified as $k=>$v) { // Only set fields that exist in the DB if (\in_array($k, $arrFields)) { $arrSet[$k] = $arrRow[$k]; } } $arrSet = $this->preSave($arrSet); // No modified fiels if (empty($arrSet)) { return $this; } $intPk = $this->{static::$strPk}; // Track primary key changes if (isset($this->arrModified[static::$strPk])) { $intPk = $this->arrModified[static::$strPk]; } if ($intPk === null) { throw new \RuntimeException('The primary key has not been set'); } // Update the row $objDatabase->prepare("UPDATE " . static::$strTable . " %s WHERE " . Database::quoteIdentifier(static::$strPk) . "=?") ->set($arrSet) ->execute($intPk); $this->postSave(self::UPDATE); $this->arrModified = array(); // reset after postSave() } // The model is not yet in the registry else { $arrSet = $this->row(); // Remove fields that do not exist in the DB foreach ($arrSet as $k=>$v) { if (!\in_array($k, $arrFields)) { unset($arrSet[$k]); } } $arrSet = $this->preSave($arrSet); // No modified fiels if (empty($arrSet)) { return $this; } // Insert a new row $stmt = $objDatabase->prepare("INSERT INTO " . static::$strTable . " %s") ->set($arrSet) ->execute(); if (static::$strPk == 'id') { $this->id = $stmt->insertId; } $this->postSave(self::INSERT); $this->arrModified = array(); // reset after postSave() Registry::getInstance()->register($this); } return $this; }
php
{ "resource": "" }
q243070
Model.delete
validation
public function delete() { $intPk = $this->{static::$strPk}; // Track primary key changes if (isset($this->arrModified[static::$strPk])) { $intPk = $this->arrModified[static::$strPk]; } // Delete the row $intAffected = Database::getInstance()->prepare("DELETE FROM " . static::$strTable . " WHERE " . Database::quoteIdentifier(static::$strPk) . "=?") ->execute($intPk) ->affectedRows; if ($intAffected) { // Unregister the model Registry::getInstance()->unregister($this); // Remove the primary key (see #6162) $this->arrData[static::$strPk] = null; } return $intAffected; }
php
{ "resource": "" }
q243071
Model.refresh
validation
public function refresh() { $intPk = $this->{static::$strPk}; // Track primary key changes if (isset($this->arrModified[static::$strPk])) { $intPk = $this->arrModified[static::$strPk]; } // Reload the database record $res = Database::getInstance()->prepare("SELECT * FROM " . static::$strTable . " WHERE " . Database::quoteIdentifier(static::$strPk) . "=?") ->execute($intPk); $this->setRow($res->row()); }
php
{ "resource": "" }
q243072
Model.detach
validation
public function detach($blnKeepClone=true) { $registry = Registry::getInstance(); if (!$registry->isRegistered($this)) { return; } $registry->unregister($this); if ($blnKeepClone) { $this->cloneOriginal()->attach(); } }
php
{ "resource": "" }
q243073
Model.onRegister
validation
public function onRegister(Registry $registry) { // Register aliases to unique fields foreach (static::getUniqueFields() as $strColumn) { $varAliasValue = $this->{$strColumn}; if (!$registry->isRegisteredAlias($this, $strColumn, $varAliasValue)) { $registry->registerAlias($this, $strColumn, $varAliasValue); } } }
php
{ "resource": "" }
q243074
Model.onUnregister
validation
public function onUnregister(Registry $registry) { // Unregister aliases to unique fields foreach (static::getUniqueFields() as $strColumn) { $varAliasValue = $this->{$strColumn}; if ($registry->isRegisteredAlias($this, $strColumn, $varAliasValue)) { $registry->unregisterAlias($this, $strColumn, $varAliasValue); } } }
php
{ "resource": "" }
q243075
Model.findByPk
validation
public static function findByPk($varValue, array $arrOptions=array()) { // Try to load from the registry if (empty($arrOptions)) { $objModel = Registry::getInstance()->fetch(static::$strTable, $varValue); if ($objModel !== null) { return $objModel; } } $arrOptions = array_merge ( array ( 'limit' => 1, 'column' => static::$strPk, 'value' => $varValue, 'return' => 'Model' ), $arrOptions ); return static::find($arrOptions); }
php
{ "resource": "" }
q243076
Model.findByIdOrAlias
validation
public static function findByIdOrAlias($varId, array $arrOptions=array()) { $isAlias = !preg_match('/^[1-9]\d*$/', $varId); // Try to load from the registry if (!$isAlias && empty($arrOptions)) { $objModel = Registry::getInstance()->fetch(static::$strTable, $varId); if ($objModel !== null) { return $objModel; } } $t = static::$strTable; $arrOptions = array_merge ( array ( 'limit' => 1, 'column' => $isAlias ? array("$t.alias=?") : array("$t.id=?"), 'value' => $varId, 'return' => 'Model' ), $arrOptions ); return static::find($arrOptions); }
php
{ "resource": "" }
q243077
Model.findMultipleByIds
validation
public static function findMultipleByIds($arrIds, array $arrOptions=array()) { if (empty($arrIds) || !\is_array($arrIds)) { return null; } $arrRegistered = array(); $arrUnregistered = array(); // Search for registered models foreach ($arrIds as $intId) { if (empty($arrOptions)) { $arrRegistered[$intId] = Registry::getInstance()->fetch(static::$strTable, $intId); } if (!isset($arrRegistered[$intId])) { $arrUnregistered[] = $intId; } } // Fetch only the missing models from the database if (!empty($arrUnregistered)) { $t = static::$strTable; $arrOptions = array_merge ( array ( 'column' => array("$t.id IN(" . implode(',', array_map('\intval', $arrUnregistered)) . ")"), 'value' => null, 'order' => Database::getInstance()->findInSet("$t.id", $arrIds), 'return' => 'Collection' ), $arrOptions ); $objMissing = static::find($arrOptions); if ($objMissing !== null) { while ($objMissing->next()) { $intId = $objMissing->{static::$strPk}; $arrRegistered[$intId] = $objMissing->current(); } } } $arrRegistered = array_filter(array_values($arrRegistered)); if (empty($arrRegistered)) { return null; } return static::createCollection($arrRegistered, static::$strTable); }
php
{ "resource": "" }
q243078
Model.findOneBy
validation
public static function findOneBy($strColumn, $varValue, array $arrOptions=array()) { $arrOptions = array_merge ( array ( 'limit' => 1, 'column' => $strColumn, 'value' => $varValue, 'return' => 'Model' ), $arrOptions ); return static::find($arrOptions); }
php
{ "resource": "" }
q243079
Model.findBy
validation
public static function findBy($strColumn, $varValue, array $arrOptions=array()) { $blnModel = false; $arrColumn = (array) $strColumn; if (\count($arrColumn) == 1 && ($arrColumn[0] === static::getPk() || \in_array($arrColumn[0], static::getUniqueFields()))) { $blnModel = true; } $arrOptions = array_merge ( array ( 'column' => $strColumn, 'value' => $varValue, 'return' => $blnModel ? 'Model' : 'Collection' ), $arrOptions ); return static::find($arrOptions); }
php
{ "resource": "" }
q243080
Model.find
validation
protected static function find(array $arrOptions) { if (static::$strTable == '') { return null; } // Try to load from the registry if ($arrOptions['return'] == 'Model') { $arrColumn = (array) $arrOptions['column']; if (\count($arrColumn) == 1) { // Support table prefixes $arrColumn[0] = preg_replace('/^' . preg_quote(static::getTable(), '/') . '\./', '', $arrColumn[0]); if ($arrColumn[0] == static::$strPk || \in_array($arrColumn[0], static::getUniqueFields())) { $varKey = \is_array($arrOptions['value']) ? $arrOptions['value'][0] : $arrOptions['value']; $objModel = Registry::getInstance()->fetch(static::$strTable, $varKey, $arrColumn[0]); if ($objModel !== null) { return $objModel; } } } } $arrOptions['table'] = static::$strTable; $strQuery = static::buildFindQuery($arrOptions); $objStatement = Database::getInstance()->prepare($strQuery); // Defaults for limit and offset if (!isset($arrOptions['limit'])) { $arrOptions['limit'] = 0; } if (!isset($arrOptions['offset'])) { $arrOptions['offset'] = 0; } // Limit if ($arrOptions['limit'] > 0 || $arrOptions['offset'] > 0) { $objStatement->limit($arrOptions['limit'], $arrOptions['offset']); } $objStatement = static::preFind($objStatement); $objResult = $objStatement->execute($arrOptions['value']); if ($objResult->numRows < 1) { return $arrOptions['return'] == 'Array' ? array() : null; } $objResult = static::postFind($objResult); // Try to load from the registry if ($arrOptions['return'] == 'Model') { $objModel = Registry::getInstance()->fetch(static::$strTable, $objResult->{static::$strPk}); if ($objModel !== null) { return $objModel->mergeRow($objResult->row()); } return static::createModelFromDbResult($objResult); } elseif ($arrOptions['return'] == 'Array') { return static::createCollectionFromDbResult($objResult, static::$strTable)->getModels(); } else { return static::createCollectionFromDbResult($objResult, static::$strTable); } }
php
{ "resource": "" }
q243081
Model.countBy
validation
public static function countBy($strColumn=null, $varValue=null, array $arrOptions=array()) { if (static::$strTable == '') { return 0; } $arrOptions = array_merge ( array ( 'table' => static::$strTable, 'column' => $strColumn, 'value' => $varValue ), $arrOptions ); $strQuery = static::buildCountQuery($arrOptions); return (int) Database::getInstance()->prepare($strQuery)->execute($arrOptions['value'])->count; }
php
{ "resource": "" }
q243082
SqlFileParser.parse
validation
public static function parse($file) { if (!file_exists($file)) { throw new \InvalidArgumentException('Invalid file ' . $file); } $table = ''; $return = array(); $data = file($file); foreach ($data as $k=>$v) { $key_name = array(); $subpatterns = array(); // Unset comments and empty lines if (preg_match('/^[#-]+/', $v) || !\strlen(trim($v))) { unset($data[$k]); continue; } // Store the table names if (preg_match('/^CREATE TABLE `([^`]+)`/i', $v, $subpatterns)) { $table = $subpatterns[1]; } // Get the table options elseif ($table != '' && preg_match('/^\)([^;]+);/', $v, $subpatterns)) { $return[$table]['TABLE_OPTIONS'] = $subpatterns[1]; $table = ''; } // Add the fields elseif ($table != '') { preg_match('/^[^`]*`([^`]+)`/', trim($v), $key_name); $first = preg_replace('/\s[^\n\r]+/', '', $key_name[0]); $key = $key_name[1]; // Create definitions if (\in_array($first, array('KEY', 'PRIMARY', 'PRIMARY KEY', 'FOREIGN', 'FOREIGN KEY', 'INDEX', 'UNIQUE', 'FULLTEXT', 'CHECK'))) { if (strncmp($first, 'PRIMARY', 7) === 0) { $key = 'PRIMARY'; } $return[$table]['TABLE_CREATE_DEFINITIONS'][$key] = preg_replace('/,$/', '', trim($v)); } else { $return[$table]['TABLE_FIELDS'][$key] = preg_replace('/,$/', '', trim($v)); } } } // Ignore the table options if there is no primary key foreach (array_keys($return) as $table) { if (!isset($return[$table]['TABLE_CREATE_DEFINITIONS']['PRIMARY'])) { unset($return[$table]['TABLE_OPTIONS']); } } return $return; }
php
{ "resource": "" }
q243083
RegisterFragmentsPass.process
validation
public function process(ContainerBuilder $container): void { if (!$container->has('contao.fragment.registry')) { return; } $this->registerFragments($container, ContentElementReference::TAG_NAME); $this->registerFragments($container, FrontendModuleReference::TAG_NAME); }
php
{ "resource": "" }
q243084
RegisterFragmentsPass.getControllerName
validation
protected function getControllerName(Reference $reference, array $attributes): string { $controller = (string) $reference; // Support a specific method on the controller if (isset($attributes['method'])) { $controller .= ':'.$attributes['method']; } return $controller; }
php
{ "resource": "" }
q243085
Calendar.generateFeedsByCalendar
validation
public function generateFeedsByCalendar($intId) { $objFeed = CalendarFeedModel::findByCalendar($intId); if ($objFeed !== null) { while ($objFeed->next()) { $objFeed->feedName = $objFeed->alias ?: 'calendar' . $objFeed->id; // Update the XML file $this->generateFiles($objFeed->row()); $this->log('Generated calendar feed "' . $objFeed->feedName . '.xml"', __METHOD__, TL_CRON); } } }
php
{ "resource": "" }
q243086
Calendar.getSearchablePages
validation
public function getSearchablePages($arrPages, $intRoot=0, $blnIsSitemap=false) { $arrRoot = array(); if ($intRoot > 0) { $arrRoot = $this->Database->getChildRecords($intRoot, 'tl_page'); } $arrProcessed = array(); $time = Date::floorToMinute(); // Get all calendars $objCalendar = CalendarModel::findByProtected(''); // Walk through each calendar if ($objCalendar !== null) { while ($objCalendar->next()) { // Skip calendars without target page if (!$objCalendar->jumpTo) { continue; } // Skip calendars outside the root nodes if (!empty($arrRoot) && !\in_array($objCalendar->jumpTo, $arrRoot)) { continue; } // Get the URL of the jumpTo page if (!isset($arrProcessed[$objCalendar->jumpTo])) { $objParent = PageModel::findWithDetails($objCalendar->jumpTo); // The target page does not exist if ($objParent === null) { continue; } // The target page has not been published (see #5520) if (!$objParent->published || ($objParent->start != '' && $objParent->start > $time) || ($objParent->stop != '' && $objParent->stop <= ($time + 60))) { continue; } if ($blnIsSitemap) { // The target page is protected (see #8416) if ($objParent->protected) { continue; } // The target page is exempt from the sitemap (see #6418) if ($objParent->sitemap == 'map_never') { continue; } } // Generate the URL $arrProcessed[$objCalendar->jumpTo] = $objParent->getAbsoluteUrl(Config::get('useAutoItem') ? '/%s' : '/events/%s'); } $strUrl = $arrProcessed[$objCalendar->jumpTo]; // Get the items $objEvents = CalendarEventsModel::findPublishedDefaultByPid($objCalendar->id); if ($objEvents !== null) { while ($objEvents->next()) { $arrPages[] = sprintf(preg_replace('/%(?!s)/', '%%', $strUrl), ($objEvents->alias ?: $objEvents->id)); } } } } return $arrPages; }
php
{ "resource": "" }
q243087
Calendar.unixToJd
validation
public static function unixToJd($tstamp) { list($year, $month, $day) = explode(',', date('Y,m,d', $tstamp)); // Make year a positive number $year += ($year < 0 ? 4801 : 4800); // Adjust the start of the year if ($month > 2) { $month -= 3; } else { $month += 9; --$year; } $sdn = floor((floor($year / 100) * 146097) / 4); $sdn += floor((($year % 100) * 1461) / 4); $sdn += floor(($month * 153 + 2) / 5); $sdn += $day - 32045; return $sdn; }
php
{ "resource": "" }
q243088
ModuleNews.parseArticles
validation
protected function parseArticles($objArticles, $blnAddArchive=false) { $limit = $objArticles->count(); if ($limit < 1) { return array(); } $count = 0; $arrArticles = array(); while ($objArticles->next()) { /** @var NewsModel $objArticle */ $objArticle = $objArticles->current(); $arrArticles[] = $this->parseArticle($objArticle, $blnAddArchive, ((++$count == 1) ? ' first' : '') . (($count == $limit) ? ' last' : '') . ((($count % 2) == 0) ? ' odd' : ' even'), $count); } return $arrArticles; }
php
{ "resource": "" }
q243089
ModuleNews.getMetaFields
validation
protected function getMetaFields($objArticle) { $meta = StringUtil::deserialize($this->news_metaFields); if (!\is_array($meta)) { return array(); } /** @var PageModel $objPage */ global $objPage; $return = array(); foreach ($meta as $field) { switch ($field) { case 'date': $return['date'] = Date::parse($objPage->datimFormat, $objArticle->date); break; case 'author': /** @var UserModel $objAuthor */ if (($objAuthor = $objArticle->getRelated('author')) instanceof UserModel) { $return['author'] = $GLOBALS['TL_LANG']['MSC']['by'] . ' <span itemprop="author">' . $objAuthor->name . '</span>'; } break; case 'comments': if ($objArticle->noComments || $objArticle->source != 'default') { break; } $bundles = System::getContainer()->getParameter('kernel.bundles'); if (!isset($bundles['ContaoCommentsBundle'])) { break; } $intTotal = CommentsModel::countPublishedBySourceAndParent('tl_news', $objArticle->id); $return['ccount'] = $intTotal; $return['comments'] = sprintf($GLOBALS['TL_LANG']['MSC']['commentCount'], $intTotal); break; } } return $return; }
php
{ "resource": "" }
q243090
ModuleNews.generateLink
validation
protected function generateLink($strLink, $objArticle, $blnAddArchive=false, $blnIsReadMore=false) { // Internal link if ($objArticle->source != 'external') { return sprintf('<a href="%s" title="%s" itemprop="url"><span itemprop="headline">%s</span>%s</a>', News::generateNewsUrl($objArticle, $blnAddArchive), StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $objArticle->headline), true), $strLink, ($blnIsReadMore ? '<span class="invisible"> '.$objArticle->headline.'</span>' : '')); } // Encode e-mail addresses if (substr($objArticle->url, 0, 7) == 'mailto:') { $strArticleUrl = StringUtil::encodeEmail($objArticle->url); } // Ampersand URIs else { $strArticleUrl = ampersand($objArticle->url); } // External link return sprintf('<a href="%s" title="%s"%s itemprop="url"><span itemprop="headline">%s</span></a>', $strArticleUrl, StringUtil::specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['open'], $strArticleUrl)), ($objArticle->target ? ' target="_blank"' : ''), $strLink); }
php
{ "resource": "" }
q243091
FragmentHandler.preHandleFragment
validation
private function preHandleFragment(FragmentReference $uri, FragmentConfig $config): void { if (!isset($uri->attributes['pageModel']) && $this->hasGlobalPageObject()) { $uri->attributes['pageModel'] = $GLOBALS['objPage']->id; } if ($this->preHandlers->has($uri->controller)) { /** @var FragmentPreHandlerInterface $preHandler */ $preHandler = $this->preHandlers->get($uri->controller); $preHandler->preHandleFragment($uri, $config); } }
php
{ "resource": "" }
q243092
PageRoot.generate
validation
public function generate($rootPageId, $blnReturn=false, $blnPreferAlias=false) { if (!$blnReturn) { $this->redirect($this->getRedirectUrl($rootPageId), 302); } $objNextPage = $this->getNextPage($rootPageId); return ($blnPreferAlias && $objNextPage->alias != '') ? $objNextPage->alias : $objNextPage->id; }
php
{ "resource": "" }
q243093
PageRoot.getNextPage
validation
protected function getNextPage($rootPageId) { $objNextPage = PageModel::findFirstPublishedByPid($rootPageId); // No published pages yet if (null === $objNextPage) { $this->log('No active page found under root page "' . $rootPageId . '")', __METHOD__, TL_ERROR); throw new NoActivePageFoundException('No active page found under root page.'); } return $objNextPage; }
php
{ "resource": "" }
q243094
TranslationListener.onReplaceInsertTags
validation
public function onReplaceInsertTags(string $tag) { $chunks = explode('::', $tag); if ('trans' !== $chunks[0]) { return false; } $parameters = isset($chunks[3]) ? explode(':', $chunks[3]) : []; return $this->translator->trans($chunks[1], $parameters, $chunks[2] ?? null); }
php
{ "resource": "" }
q243095
CalendarEventsModel.findCurrentByPid
validation
public static function findCurrentByPid($intPid, $intStart, $intEnd, array $arrOptions=array()) { $t = static::$strTable; $intStart = (int) $intStart; $intEnd = (int) $intEnd; $arrColumns = array("$t.pid=? AND (($t.startTime>=$intStart AND $t.startTime<=$intEnd) OR ($t.endTime>=$intStart AND $t.endTime<=$intEnd) OR ($t.startTime<=$intStart AND $t.endTime>=$intEnd) OR ($t.recurring='1' AND ($t.recurrences=0 OR $t.repeatEnd>=$intStart) AND $t.startTime<=$intEnd))"); if (!static::isPreviewMode($arrOptions)) { $time = Date::floorToMinute(); $arrColumns[] = "($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'" . ($time + 60) . "') AND $t.published='1'"; } if (!isset($arrOptions['order'])) { $arrOptions['order'] = "$t.startTime"; } return static::findBy($arrColumns, $intPid, $arrOptions); }
php
{ "resource": "" }
q243096
CalendarEventsModel.findUpcomingByPids
validation
public static function findUpcomingByPids($arrIds, $intLimit=0, array $arrOptions=array()) { if (empty($arrIds) || !\is_array($arrIds)) { return null; } $t = static::$strTable; $time = Date::floorToMinute(); // Get upcoming events using endTime instead of startTime (see #3917) $arrColumns = array("($t.endTime>=$time OR ($t.recurring='1' AND ($t.recurrences=0 OR $t.repeatEnd>=$time))) AND $t.pid IN(" . implode(',', array_map('\intval', $arrIds)) . ") AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'" . ($time + 60) . "') AND $t.published='1'"); if ($intLimit > 0) { $arrOptions['limit'] = $intLimit; } if (!isset($arrOptions['order'])) { $arrOptions['order'] = "$t.startTime"; } return static::findBy($arrColumns, null, $arrOptions); }
php
{ "resource": "" }
q243097
PageRegular.getPageLayout
validation
protected function getPageLayout($objPage) { $objLayout = LayoutModel::findByPk($objPage->layout); // Die if there is no layout if (null === $objLayout) { $this->log('Could not find layout ID "' . $objPage->layout . '"', __METHOD__, TL_ERROR); throw new NoLayoutSpecifiedException('No layout specified'); } $objPage->hasJQuery = $objLayout->addJQuery; $objPage->hasMooTools = $objLayout->addMooTools; // HOOK: modify the page or layout object (see #4736) if (isset($GLOBALS['TL_HOOKS']['getPageLayout']) && \is_array($GLOBALS['TL_HOOKS']['getPageLayout'])) { foreach ($GLOBALS['TL_HOOKS']['getPageLayout'] as $callback) { $this->import($callback[0]); $this->{$callback[0]}->{$callback[1]}($objPage, $objLayout, $this); } } return $objLayout; }
php
{ "resource": "" }
q243098
Files.fopen
validation
public function fopen($strFile, $strMode) { $this->validate($strFile); return fopen($this->strRootDir . '/' . $strFile, $strMode); }
php
{ "resource": "" }
q243099
Files.rename
validation
public function rename($strOldName, $strNewName) { // Source file == target file if ($strOldName == $strNewName) { return true; } $this->validate($strOldName, $strNewName); // Windows fix: delete the target file if (\defined('PHP_WINDOWS_VERSION_BUILD') && file_exists($this->strRootDir . '/' . $strNewName) && strcasecmp($strOldName, $strNewName) !== 0) { $this->delete($strNewName); } // Unix fix: rename case sensitively if (strcasecmp($strOldName, $strNewName) === 0 && strcmp($strOldName, $strNewName) !== 0) { rename($this->strRootDir . '/' . $strOldName, $this->strRootDir . '/' . $strOldName . '__'); $strOldName .= '__'; } return rename($this->strRootDir . '/' . $strOldName, $this->strRootDir . '/' . $strNewName); }
php
{ "resource": "" }