本文整理汇总了PHP中Requirements::restore方法的典型用法代码示例。如果您正苦于以下问题:PHP Requirements::restore方法的具体用法?PHP Requirements::restore怎么用?PHP Requirements::restore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Requirements
的用法示例。
在下文中一共展示了Requirements::restore方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderPdf
public function renderPdf()
{
Requirements::clear();
if (!$this->Template) {
throw new Exception("Please specify a template before rendering.");
}
$content = $this->renderWith($this->Template);
Requirements::restore();
return $content;
}
示例2: onBeforeWrite
/**
* Make sure there is always a WidgetArea sidebar for adding widgets
*
*/
public function onBeforeWrite()
{
// enable theme in case elements are being rendered with templates stored in theme folder
$originalThemeEnabled = Config::inst()->get('SSViewer', 'theme_enabled');
Config::inst()->update('SSViewer', 'theme_enabled', true);
if (!$this->supportsElemental()) {
return;
}
if ($this->owner->hasMethod('ElementArea')) {
$elements = $this->owner->ElementArea();
if (!$elements->isInDB()) {
$elements->write();
$this->owner->ElementAreaID = $elements->ID;
} else {
// Copy widgets content to Content to enable search
$searchableContent = array();
Requirements::clear();
foreach ($elements->Elements() as $element) {
if ($element->config()->exclude_from_content) {
continue;
}
$controller = $element->getController();
foreach ($elements->Items() as $element) {
$controller->init();
array_push($searchableContent, $controller->WidgetHolder());
}
}
Requirements::restore();
$this->owner->Content = trim(implode(' ', $searchableContent));
}
}
// set theme_enabled back to what it was
Config::inst()->update('SSViewer', 'theme_enabled', $originalThemeEnabled);
parent::onBeforeWrite();
}
示例3: send
/**
* Send an email with HTML content.
*
* @see sendPlain() for sending plaintext emails only.
* @uses Mailer->sendHTML()
*
* @param string $messageID Optional message ID so the message can be identified in bounces etc.
* @return bool Success of the sending operation from an MTA perspective.
* Doesn't actually give any indication if the mail has been delivered to the recipient properly)
*/
public function send($messageID = null)
{
Requirements::clear();
$this->parseVariables();
if (empty($this->from)) {
$this->from = Email::config()->admin_email;
}
$headers = $this->customHeaders;
if ($messageID) {
$headers['X-SilverStripeMessageID'] = project() . '.' . $messageID;
}
if (project()) {
$headers['X-SilverStripeSite'] = project();
}
$to = $this->to;
$from = $this->from;
$subject = $this->subject;
if ($sendAllTo = $this->config()->send_all_emails_to) {
$subject .= " [addressed to {$to}";
$to = $sendAllTo;
if ($this->cc) {
$subject .= ", cc to {$this->cc}";
}
if ($this->bcc) {
$subject .= ", bcc to {$this->bcc}";
}
$subject .= ']';
unset($headers['Cc']);
unset($headers['Bcc']);
} else {
if ($this->cc) {
$headers['Cc'] = $this->cc;
}
if ($this->bcc) {
$headers['Bcc'] = $this->bcc;
}
}
if ($ccAllTo = $this->config()->cc_all_emails_to) {
if (!empty($headers['Cc']) && trim($headers['Cc'])) {
$headers['Cc'] .= ', ' . $ccAllTo;
} else {
$headers['Cc'] = $ccAllTo;
}
}
if ($bccAllTo = $this->config()->bcc_all_emails_to) {
if (!empty($headers['Bcc']) && trim($headers['Bcc'])) {
$headers['Bcc'] .= ', ' . $bccAllTo;
} else {
$headers['Bcc'] = $bccAllTo;
}
}
if ($sendAllfrom = $this->config()->send_all_emails_from) {
if ($from) {
$subject .= " [from {$from}]";
}
$from = $sendAllfrom;
}
Requirements::restore();
return self::mailer()->sendHTML($to, $from, $subject, $this->body, $this->attachments, $headers, $this->plaintext_body);
}
示例4: send
/**
* Send an email with HTML content.
*
* @see sendPlain() for sending plaintext emails only.
* @uses Mailer->sendHTML()
*
* @param string $messageID Optional message ID so the message can be identified in bounces etc.
* @return bool Success of the sending operation from an MTA perspective.
* Doesn't actually give any indication if the mail has been delivered to the recipient properly)
*/
public function send($messageID = null)
{
Requirements::clear();
$this->parseVariables();
if (empty($this->from)) {
$this->from = Email::getAdminEmail();
}
$this->setBounceHandlerURL($this->bounceHandlerURL);
$headers = $this->customHeaders;
$headers['X-SilverStripeBounceURL'] = $this->bounceHandlerURL;
if ($messageID) {
$headers['X-SilverStripeMessageID'] = project() . '.' . $messageID;
}
if (project()) {
$headers['X-SilverStripeSite'] = project();
}
$to = $this->to;
$subject = $this->subject;
if (self::$send_all_emails_to) {
$subject .= " [addressed to {$to}";
$to = self::$send_all_emails_to;
if ($this->cc) {
$subject .= ", cc to {$this->cc}";
}
if ($this->bcc) {
$subject .= ", bcc to {$this->bcc}";
}
$subject .= ']';
unset($headers['Cc']);
unset($headers['Bcc']);
} else {
if ($this->cc) {
$headers['Cc'] = $this->cc;
}
if ($this->bcc) {
$headers['Bcc'] = $this->bcc;
}
}
if (self::$cc_all_emails_to) {
if (!empty($headers['Cc']) && trim($headers['Cc'])) {
$headers['Cc'] .= ', ' . self::$cc_all_emails_to;
} else {
$headers['Cc'] = self::$cc_all_emails_to;
}
}
if (self::$bcc_all_emails_to) {
if (!empty($headers['Bcc']) && trim($headers['Bcc'])) {
$headers['Bcc'] .= ', ' . self::$bcc_all_emails_to;
} else {
$headers['Bcc'] = self::$bcc_all_emails_to;
}
}
Requirements::restore();
return self::mailer()->sendHTML($to, $this->from, $subject, $this->body, $this->attachments, $headers, $this->plaintext_body);
}
示例5: sendEmail
/**
* Sends the email, either with the native {@link Email} class or with Postmark
*
* @param array The form data
* @param Form The form object
*/
public function sendEmail($data, $form)
{
$proxy = $form->proxy;
$emailTo = $proxy->getToAddress();
$emailSubject = $proxy->getMessageSubject();
$replyTo = $proxy->getReplyTo();
$emailTemplate = $proxy->getEmailTemplate();
$fields = ArrayList::create(array());
$uploadedFiles = array();
foreach ($form->Fields()->dataFields() as $field) {
if (!in_array($field->getName(), $proxy->getOmittedFields())) {
if ($field instanceof CheckboxField) {
$value = $field->value ? _t('ContactForm.YES', 'Yes') : _t('ContactForm.NO', 'No');
} elseif (class_exists("UploadifyField") && $field instanceof UploadifyField) {
$uploadedFiles[] = $field->Value();
} else {
$value = nl2br($field->Value());
}
if (is_array($value)) {
$answers = ArrayList::create(array());
foreach ($value as $v) {
$answers->push(ArrayData::create(array('Value' => $v)));
}
$answers->Checkboxes = true;
$fields->push(ArrayData::create(array('Label' => $field->Title(), 'Values' => $answers)));
} else {
$title = $field->Title() ? $field->Title() : $field->getName();
$fields->push(ArrayData::create(array('Label' => $title, 'Value' => $value)));
}
}
}
$messageData = array('IntroText' => $proxy->getIntroText(), 'Fields' => $fields, 'Domain' => Director::protocolAndHost());
Requirements::clear();
$html = $this->owner->customise($messageData)->renderWith($emailTemplate);
Requirements::restore();
if ($proxy->isPostmark()) {
require_once Director::baseFolder() . "/contact_form/code/thirdparty/postmark/Postmark.php";
$email = Mail_Postmark::compose()->subject($emailSubject)->messageHtml($html);
try {
$email->addTo($emailTo);
} catch (Exception $e) {
$form->sessionMessage(_t('ContactForm.BADTOADDRESS', 'It appears there is no receipient for this form. Please contact an administrator.'), 'bad');
return $this->owner->redirectBack();
}
if ($replyTo) {
try {
$email->replyTo($replyTo);
} catch (Exception $e) {
}
}
foreach ($uploadedFiles as $file_id) {
if ($file = File::get()->byID($file_id)) {
$email->addAttachment($file->getFullPath());
}
}
} else {
$email = Email::create(null, $emailTo, $emailSubject, $html);
if ($replyTo) {
$email->replyTo($replyTo);
}
foreach ($uploadedFiles as $file_id) {
if ($file = File::get()->byID($file_id)) {
$email->attachFile($file->getFullPath(), basename($file->Filename));
}
}
}
$email->send();
foreach ($uploadedFiles as $file_id) {
if ($file = File::get()->byID($file_id)->first()) {
$file->delete();
}
}
}
示例6: getPreviewHtml
/**
* Returns a rendered state to use with the dataobject preview field
*
* @return string
*/
public function getPreviewHtml()
{
Requirements::clear();
$previewStylesheets = $this->config()->previewStylesheets;
if (is_array($previewStylesheets)) {
foreach ($previewStylesheets as $css) {
Requirements::css($css);
}
}
// The theme can be disabled when in the context of the CMS, which causes includes to fail
$themeEnabled = Config::inst()->get('SSViewer', 'theme_enabled');
Config::inst()->update('SSViewer', 'theme_enabled', true);
$result = $this->customise(array('Slice' => $this->forTemplate()))->renderWith('SliceWrapper');
Requirements::restore();
// Restore previous theme_enabled setting
Config::inst()->update('SSViewer', 'theme_enabled', $themeEnabled);
return $result;
}
示例7: httpError
/**
* Returns the HTTP error response.
*
* @param string $code Error code
* @param string $message Error message
*
* @return void
*
* @throws SS_HTTPResponse_Exception
* @author Sebastian Diel <sdiel@pixeltricks.de>
* @since 07.05.2015
*/
public function httpError($code, $message = null)
{
$combined_files = Requirements::get_combine_files();
try {
$response = parent::httpError($code, $message);
} catch (SS_HTTPResponse_Exception $e) {
$originalResponse = $e->getResponse();
Requirements::restore();
foreach ($combined_files as $combinedFileName => $files) {
Requirements::combine_files($combinedFileName, $files);
Requirements::process_combined_files();
}
$response = $this->request->isMedia() ? null : self::error_response_for($code);
throw new SS_HTTPResponse_Exception($response ? $response : ($originalResponse ? $originalResponse : $message), $code);
}
}