本文整理汇总了PHP中Contao\System::setCookie方法的典型用法代码示例。如果您正苦于以下问题:PHP System::setCookie方法的具体用法?PHP System::setCookie怎么用?PHP System::setCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Contao\System
的用法示例。
在下文中一共展示了System::setCookie方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: overrideAll
//.........这里部分代码省略.........
$arrButtons = $callback($arrButtons, $this);
}
}
}
// Add the form
$return = '
<form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $this->strTable . '" class="tl_form" method="post" enctype="' . ($this->blnUploadable ? 'multipart/form-data' : 'application/x-www-form-urlencoded') . '">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="' . $this->strTable . '">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' . ($this->noReload ? '
<p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . $return . '
</div>
<div class="tl_formbody_submit">
<div class="tl_submit_container">
' . implode(' ', $arrButtons) . '
</div>
</div>
</form>';
// Set the focus if there is an error
if ($this->noReload) {
$return .= '
<script>
window.addEvent(\'domready\', function() {
Backend.vScrollTo(($(\'' . $this->strTable . '\').getElement(\'label.error\').getPosition().y - 20));
});
</script>';
}
// Reload the page to prevent _POST variables from being sent twice
if (\Input::post('FORM_SUBMIT') == $this->strTable && !$this->noReload) {
if (isset($_POST['saveNclose'])) {
\System::setCookie('BE_PAGE_OFFSET', 0, 0);
$this->redirect($this->getReferer());
}
$this->reload();
}
} else {
$options = '';
$fields = array();
// Add fields of the current table
$fields = array_merge($fields, array_keys($GLOBALS['TL_DCA'][$this->strTable]['fields']));
// Add meta fields if the current user is an administrator
if ($this->User->isAdmin) {
if ($this->Database->fieldExists('sorting', $this->strTable) && !in_array('sorting', $fields)) {
array_unshift($fields, 'sorting');
}
if ($this->Database->fieldExists('pid', $this->strTable) && !in_array('pid', $fields)) {
array_unshift($fields, 'pid');
}
}
// Show all non-excluded fields
foreach ($fields as $field) {
if ($field == 'pid' || $field == 'sorting' || !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['exclude'] && !$GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['eval']['doNotShow'] && (strlen($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['inputType']) || is_array($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['input_field_callback']))) {
$options .= '
<input type="checkbox" name="all_fields[]" id="all_' . $field . '" class="tl_checkbox" value="' . specialchars($field) . '"> <label for="all_' . $field . '" class="tl_checkbox_label">' . (($GLOBALS['TL_DCA'][$this->strTable]['fields'][$field]['label'][0] ?: $GLOBALS['TL_LANG']['MSC'][$field][0]) . ' <span style="color:#b3b3b3;padding-left:3px">[' . $field . ']</span>') . '</label><br>';
}
}
$blnIsError = $_POST && empty($_POST['all_fields']);
// Return the select menu
$return .= '
<form action="' . ampersand(\Environment::get('request'), true) . '&fields=1" id="' . $this->strTable . '_all" class="tl_form" method="post">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="' . $this->strTable . '_all">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">' . ($blnIsError ? '
<p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . '
<div class="tl_tbox">
<fieldset class="tl_checkbox_container">
<legend' . ($blnIsError ? ' class="error"' : '') . '>' . $GLOBALS['TL_LANG']['MSC']['all_fields'][0] . '</legend>
<input type="checkbox" id="check_all" class="tl_checkbox" onclick="Backend.toggleCheckboxes(this)"> <label for="check_all" style="color:#a6a6a6"><em>' . $GLOBALS['TL_LANG']['MSC']['selectAll'] . '</em></label><br>' . $options . '
</fieldset>' . ($blnIsError ? '
<p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['all_fields'] . '</p>' : (\Config::get('showHelp') && strlen($GLOBALS['TL_LANG']['MSC']['all_fields'][1]) ? '
<p class="tl_help tl_tip">' . $GLOBALS['TL_LANG']['MSC']['all_fields'][1] . '</p>' : '')) . '
</div>
</div>
<div class="tl_formbody_submit">
<div class="tl_submit_container">
<button type="submit" name="save" id="save" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['MSC']['continue'] . '</button>
</div>
</div>
</form>';
}
// Return
return '
<div id="tl_buttons">
<a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>' . $return;
}
示例2: logout
/**
* Logout from phpbb
*/
public function logout()
{
if ($this->debug) {
System::log("phpbb_bridge: " . __METHOD__, __METHOD__, TL_ACCESS);
}
$cookie_prefix = $this->getDbConfig('cookie_name');
$sid = Input::cookie($cookie_prefix . '_sid');
System::getContainer()->get('session')->remove('phpbb_user');
if ($sid) {
$logoutUrl = Environment::get('url') . '/' . $this->getForumPath() . '/contao_connect/logout';
$headers = $this->initForumRequestHeaders();
$browser = $this->initForumRequest();
$browser->get($logoutUrl, $headers);
// Parse cookies and send them to the client
foreach ($browser->getListener()->getCookies() as $cookie) {
/* @var $cookie Cookie */
// Stream cookies through to the client
System::setCookie($cookie->getName(), $cookie->getValue(), strtotime($cookie->getAttribute('expires')), $cookie->getAttribute('path'), $cookie->getAttribute('domain'));
}
}
}
示例3: importRecipients
/**
* Return a form to choose a CSV file and import it
*
* @return string
*/
public function importRecipients()
{
if (\Input::get('key') != 'import') {
return '';
}
$this->import('BackendUser', 'User');
$class = $this->User->uploader;
// See #4086 and #7046
if (!class_exists($class) || $class == 'DropZone') {
$class = 'FileUpload';
}
/** @var FileUpload $objUploader */
$objUploader = new $class();
// Import recipients
if (\Input::post('FORM_SUBMIT') == 'tl_recipients_import') {
$arrUploaded = $objUploader->uploadTo('system/tmp');
if (empty($arrUploaded)) {
\Message::addError($GLOBALS['TL_LANG']['ERR']['all_fields']);
$this->reload();
}
$time = time();
$intTotal = 0;
$intInvalid = 0;
foreach ($arrUploaded as $strCsvFile) {
$objFile = new \File($strCsvFile);
if ($objFile->extension != 'csv') {
\Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['filetype'], $objFile->extension));
continue;
}
// Get separator
switch (\Input::post('separator')) {
case 'semicolon':
$strSeparator = ';';
break;
case 'tabulator':
$strSeparator = "\t";
break;
case 'linebreak':
$strSeparator = "\n";
break;
default:
$strSeparator = ',';
break;
}
$arrRecipients = array();
$resFile = $objFile->handle;
while (($arrRow = @fgetcsv($resFile, null, $strSeparator)) !== false) {
$arrRecipients = array_merge($arrRecipients, $arrRow);
}
$arrRecipients = array_filter(array_unique($arrRecipients));
foreach ($arrRecipients as $strRecipient) {
// Skip invalid entries
if (!\Validator::isEmail($strRecipient)) {
$this->log('Recipient address "' . $strRecipient . '" seems to be invalid and was not imported', __METHOD__, TL_ERROR);
++$intInvalid;
continue;
}
// Check whether the e-mail address exists
$objRecipient = $this->Database->prepare("SELECT COUNT(*) AS count FROM tl_newsletter_recipients WHERE pid=? AND email=?")->execute(\Input::get('id'), $strRecipient);
if ($objRecipient->count > 0) {
continue;
}
// Check whether the e-mail address has been blacklisted
$objBlacklist = $this->Database->prepare("SELECT COUNT(*) AS count FROM tl_newsletter_blacklist WHERE pid=? AND hash=?")->execute(\Input::get('id'), md5($strRecipient));
if ($objBlacklist->count > 0) {
$this->log('Recipient address "' . $strRecipient . '" has been unsubscribed and was not imported', __METHOD__, TL_ERROR);
continue;
}
$this->Database->prepare("INSERT INTO tl_newsletter_recipients SET pid=?, tstamp={$time}, email=?, active=1")->execute(\Input::get('id'), $strRecipient);
++$intTotal;
}
}
\Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['tl_newsletter_recipients']['confirm'], $intTotal));
if ($intInvalid > 0) {
\Message::addInfo(sprintf($GLOBALS['TL_LANG']['tl_newsletter_recipients']['invalid'], $intInvalid));
}
\System::setCookie('BE_PAGE_OFFSET', 0, 0);
$this->reload();
}
// Return form
return '
<div id="tl_buttons">
<a href="' . ampersand(str_replace('&key=import', '', \Environment::get('request'))) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>
' . \Message::generate() . '
<form action="' . ampersand(\Environment::get('request'), true) . '" id="tl_recipients_import" class="tl_form" method="post" enctype="multipart/form-data">
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="tl_recipients_import">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">
<input type="hidden" name="MAX_FILE_SIZE" value="' . \Config::get('maxFileSize') . '">
<div class="tl_tbox">
<h3><label for="separator">' . $GLOBALS['TL_LANG']['MSC']['separator'][0] . '</label></h3>
<select name="separator" id="separator" class="tl_select" onfocus="Backend.getScrollOffset()">
<option value="comma">' . $GLOBALS['TL_LANG']['MSC']['comma'] . '</option>
//.........这里部分代码省略.........
示例4: source
/**
* Load the source editor
*
* @return string
*
* @throws InternalServerErrorException
*/
public function source()
{
$this->isValid($this->intId);
if (is_dir(TL_ROOT . '/' . $this->intId)) {
throw new InternalServerErrorException('Folder "' . $this->intId . '" cannot be edited.');
} elseif (!file_exists(TL_ROOT . '/' . $this->intId)) {
throw new InternalServerErrorException('File "' . $this->intId . '" does not exist.');
}
$this->import('BackendUser', 'User');
// Check user permission
if (!$this->User->hasAccess('f5', 'fop')) {
throw new AccessDeniedException('Not enough permissions to edit the file source of file "' . $this->intId . '".');
}
$objFile = new \File($this->intId);
// Check whether file type is editable
if (!in_array($objFile->extension, trimsplit(',', \Config::get('editableFiles')))) {
throw new AccessDeniedException('File type "' . $objFile->extension . '" (' . $this->intId . ') is not allowed to be edited.');
}
$objMeta = null;
$objVersions = null;
// Add the versioning routines
if ($this->blnIsDbAssisted && \Dbafs::shouldBeSynchronized($this->intId)) {
$objMeta = \FilesModel::findByPath($objFile->value);
if ($objMeta === null) {
$objMeta = \Dbafs::addResource($objFile->value);
}
$objVersions = new \Versions($this->strTable, $objMeta->id);
if (!$GLOBALS['TL_DCA'][$this->strTable]['config']['hideVersionMenu']) {
// Compare versions
if (\Input::get('versions')) {
$objVersions->compare();
}
// Restore a version
if (\Input::post('FORM_SUBMIT') == 'tl_version' && \Input::post('version') != '') {
$objVersions->restore(\Input::post('version'));
// Purge the script cache (see #7005)
if ($objFile->extension == 'css' || $objFile->extension == 'scss' || $objFile->extension == 'less') {
$this->import('Automator');
$this->Automator->purgeScriptCache();
}
$this->reload();
}
}
$objVersions->initialize();
}
$strContent = $objFile->getContent();
if ($objFile->extension == 'svgz') {
$strContent = gzdecode($strContent);
}
// Process the request
if (\Input::post('FORM_SUBMIT') == 'tl_files') {
// Restore the basic entities (see #7170)
$strSource = \StringUtil::restoreBasicEntities(\Input::postRaw('source'));
// Save the file
if (md5($strContent) != md5($strSource)) {
if ($objFile->extension == 'svgz') {
$strSource = gzencode($strSource);
}
// Write the file
$objFile->write($strSource);
$objFile->close();
// Update the database
if ($this->blnIsDbAssisted && $objMeta !== null) {
/** @var FilesModel $objMeta */
$objMeta->hash = $objFile->hash;
$objMeta->save();
$objVersions->create();
}
// Purge the script cache (see #7005)
if ($objFile->extension == 'css' || $objFile->extension == 'scss' || $objFile->extension == 'less') {
$this->import('Automator');
$this->Automator->purgeScriptCache();
}
}
if (isset($_POST['saveNclose'])) {
\System::setCookie('BE_PAGE_OFFSET', 0, 0);
$this->redirect($this->getReferer());
}
$this->reload();
}
$codeEditor = '';
// Prepare the code editor
if (\Config::get('useCE')) {
/** @var BackendTemplate|object $objTemplate */
$objTemplate = new \BackendTemplate('be_ace');
$objTemplate->selector = 'ctrl_source';
$objTemplate->type = $objFile->extension;
$codeEditor = $objTemplate->parse();
}
// Versions overview
if ($GLOBALS['TL_DCA'][$this->strTable]['config']['enableVersioning'] && !$GLOBALS['TL_DCA'][$this->strTable]['config']['hideVersionMenu'] && $this->blnIsDbAssisted && $objVersions !== null) {
$version = $objVersions->renderDropdown();
} else {
//.........这里部分代码省略.........
示例5: extractThemeFiles
//.........这里部分代码省略.........
}
$value = serialize($stylesheets);
}
} elseif ($table == 'tl_layout' && $name == 'modules') {
$modules = \StringUtil::deserialize($value);
if (is_array($modules)) {
foreach ($modules as $key => $mod) {
if ($mod['mod'] > 0) {
$modules[$key]['mod'] = $arrMapper['tl_module'][$mod['mod']];
}
}
$value = serialize($modules);
}
} elseif (($table == 'tl_theme' || $table == 'tl_style_sheet') && $name == 'name') {
$objCount = $this->Database->prepare("SELECT COUNT(*) AS count FROM " . $table . " WHERE name=?")->execute($value);
if ($objCount->count > 0) {
$value = preg_replace('/( |\\-)[0-9]+$/', '', $value);
$value .= ($table == 'tl_style_sheet' ? '-' : ' ') . ${$table};
}
} elseif (($table == 'tl_style_sheet' || $table == 'tl_style' || $table == 'tl_files' && $name == 'path') && strpos($value, 'files') !== false) {
$tmp = \StringUtil::deserialize($value);
if (is_array($tmp)) {
foreach ($tmp as $kk => $vv) {
$tmp[$kk] = $this->customizeUploadPath($vv);
}
$value = serialize($tmp);
} else {
$value = $this->customizeUploadPath($value);
}
} elseif ($GLOBALS['TL_DCA'][$table]['fields'][$name]['inputType'] == 'fileTree' && !$GLOBALS['TL_DCA'][$table]['fields'][$name]['eval']['multiple']) {
if (!$value) {
$value = null;
// Contao >= 3.2
} else {
// Do not use the FilesModel here – tables are locked!
$objFile = $this->Database->prepare("SELECT uuid FROM tl_files WHERE path=?")->limit(1)->execute($this->customizeUploadPath($value));
$value = $objFile->uuid;
}
} elseif ($GLOBALS['TL_DCA'][$table]['fields'][$name]['inputType'] == 'fileTree' || in_array($name, $arrOrder)) {
$tmp = \StringUtil::deserialize($value);
if (is_array($tmp)) {
foreach ($tmp as $kk => $vv) {
// Do not use the FilesModel here – tables are locked!
$objFile = $this->Database->prepare("SELECT uuid FROM tl_files WHERE path=?")->limit(1)->execute($this->customizeUploadPath($vv));
$tmp[$kk] = $objFile->uuid;
}
$value = serialize($tmp);
}
} elseif ($GLOBALS['TL_DCA'][$table]['fields'][$name]['inputType'] == 'imageSize') {
$imageSizes = \StringUtil::deserialize($value, true);
if (!empty($imageSizes)) {
if (is_numeric($imageSizes[2])) {
$imageSizes[2] = $arrMapper['tl_image_size'][$imageSizes[2]];
}
}
$value = serialize($imageSizes);
}
$set[$name] = $value;
}
// Skip fields that are not in the database (e.g. because of missing extensions)
foreach ($set as $k => $v) {
if (!in_array($k, $arrDbFields[$table])) {
unset($set[$k]);
}
}
// Create the templates folder even if it is empty (see #4793)
if ($table == 'tl_theme' && isset($set['templates']) && strncmp($set['templates'], 'templates/', 10) === 0 && !is_dir(TL_ROOT . '/' . $set['templates'])) {
new \Folder($set['templates']);
}
// Update tl_files (entries have been created by the Dbafs class)
if ($table == 'tl_files') {
$this->Database->prepare("UPDATE {$table} %s WHERE path=?")->set($set)->execute($set['path']);
} else {
$this->Database->prepare("INSERT INTO {$table} %s")->set($set)->execute();
}
}
}
// Unlock the tables
$this->Database->unlockTables();
// Update the style sheets
$this->import('StyleSheets');
$this->StyleSheets->updateStyleSheets();
// Notify the user
\Message::addConfirmation(sprintf($GLOBALS['TL_LANG']['tl_theme']['theme_imported'], basename($strZipFile)));
// HOOK: add custom logic
if (isset($GLOBALS['TL_HOOKS']['extractThemeFiles']) && is_array($GLOBALS['TL_HOOKS']['extractThemeFiles'])) {
$intThemeId = empty($arrMapper['tl_theme']) ? null : reset($arrMapper['tl_theme']);
foreach ($GLOBALS['TL_HOOKS']['extractThemeFiles'] as $callback) {
\System::importStatic($callback[0])->{$callback[1]}($xml, $objArchive, $intThemeId, $arrMapper);
}
}
unset($tl_files, $tl_theme, $tl_style_sheet, $tl_style, $tl_module, $tl_layout, $tl_image_size, $tl_image_size_item);
}
\System::setCookie('BE_PAGE_OFFSET', 0, 0);
/** @var SessionInterface $objSession */
$objSession = \System::getContainer()->get('session');
$objSession->remove('uploaded_themes');
// Redirect
$this->redirect(str_replace('&key=importTheme', '', \Environment::get('request')));
}
示例6: edit
//.........这里部分代码省略.........
if (is_array($callback)) {
$this->import($callback[0]);
$this->varValue = $this->{$callback}[0]->{$callback}[1]($this->varValue, $this);
} elseif (is_callable($callback)) {
$this->varValue = $callback($this->varValue, $this);
}
}
}
// Build row
$blnAjax ? $strAjax .= $this->row() : ($return .= $this->row());
}
$class = 'tl_box';
$return .= "\n" . '</fieldset>';
}
}
$this->import('Files');
// Check whether the target file is writeable
if (!$this->Files->is_writeable('system/config/localconfig.php')) {
\Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['notWriteable'], 'system/config/localconfig.php'));
}
// Submit buttons
$arrButtons = array();
$arrButtons['save'] = '<button type="submit" name="save" id="save" class="tl_submit" accesskey="s">' . $GLOBALS['TL_LANG']['MSC']['save'] . '</button>';
$arrButtons['saveNclose'] = '<button type="submit" name="saveNclose" id="saveNclose" class="tl_submit" accesskey="c">' . $GLOBALS['TL_LANG']['MSC']['saveNclose'] . '</button>';
// Call the buttons_callback (see #4691)
if (is_array($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'])) {
foreach ($GLOBALS['TL_DCA'][$this->strTable]['edit']['buttons_callback'] as $callback) {
if (is_array($callback)) {
$this->import($callback[0]);
$arrButtons = $this->{$callback}[0]->{$callback}[1]($arrButtons, $this);
} elseif (is_callable($callback)) {
$arrButtons = $callback($arrButtons, $this);
}
}
}
// Add the buttons and end the form
$return .= '
</div>
<div class="tl_formbody_submit">
<div class="tl_submit_container">
' . implode(' ', $arrButtons) . '
</div>
</div>
</form>
<script>
window.addEvent(\'domready\', function() {
Theme.focusInput("' . $this->strTable . '");
});
</script>';
// Begin the form (-> DO NOT CHANGE THIS ORDER -> this way the onsubmit attribute of the form can be changed by a field)
$return = '
<div id="tl_buttons">
<a href="' . $this->getReferer(true) . '" class="header_back" title="' . specialchars($GLOBALS['TL_LANG']['MSC']['backBTTitle']) . '" accesskey="b" onclick="Backend.getScrollOffset()">' . $GLOBALS['TL_LANG']['MSC']['backBT'] . '</a>
</div>
' . \Message::generate() . '
<form action="' . ampersand(\Environment::get('request'), true) . '" id="' . $this->strTable . '" class="tl_form" method="post"' . (!empty($this->onsubmit) ? ' onsubmit="' . implode(' ', $this->onsubmit) . '"' : '') . '>
<div class="tl_formbody_edit">
<input type="hidden" name="FORM_SUBMIT" value="' . $this->strTable . '">
<input type="hidden" name="REQUEST_TOKEN" value="' . REQUEST_TOKEN . '">
<input type="hidden" name="FORM_FIELDS[]" value="' . specialchars($this->strPalette) . '">' . ($this->noReload ? '
<p class="tl_error">' . $GLOBALS['TL_LANG']['ERR']['general'] . '</p>' : '') . $return;
// Reload the page to prevent _POST variables from being sent twice
if (\Input::post('FORM_SUBMIT') == $this->strTable && !$this->noReload) {
// Call onsubmit_callback
if (is_array($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'])) {
foreach ($GLOBALS['TL_DCA'][$this->strTable]['config']['onsubmit_callback'] as $callback) {
if (is_array($callback)) {
$this->import($callback[0]);
$this->{$callback}[0]->{$callback}[1]($this);
} elseif (is_callable($callback)) {
$callback($this);
}
}
}
// Reload
if (isset($_POST['saveNclose'])) {
\Message::reset();
\System::setCookie('BE_PAGE_OFFSET', 0, 0);
$this->redirect($this->getReferer());
}
$this->reload();
}
// Set the focus if there is an error
if ($this->noReload) {
$return .= '
<script>
window.addEvent(\'domready\', function() {
Backend.vScrollTo(($(\'' . $this->strTable . '\').getElement(\'label.error\').getPosition().y - 20));
});
</script>';
}
return $return;
}