当前位置: 首页>>代码示例>>PHP>>正文


PHP StringHelper::parseMarkdown方法代码示例

本文整理汇总了PHP中StringHelper::parseMarkdown方法的典型用法代码示例。如果您正苦于以下问题:PHP StringHelper::parseMarkdown方法的具体用法?PHP StringHelper::parseMarkdown怎么用?PHP StringHelper::parseMarkdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringHelper的用法示例。


在下文中一共展示了StringHelper::parseMarkdown方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: markdownFilter

 /**
  * Parses text through Markdown.
  *
  * @param string $str
  *
  * @return \Twig_Markup
  */
 public function markdownFilter($str)
 {
     $html = StringHelper::parseMarkdown($str);
     return TemplateHelper::getRaw($html);
 }
开发者ID:vescoyez,项目名称:portfolio_v2,代码行数:12,代码来源:CraftTwigExtension.php

示例2: _validateNewRequirements

 /**
  * @param string $unzipFolder
  *
  * @throws Exception
  * @return array
  */
 private function _validateNewRequirements($unzipFolder)
 {
     $requirementsFolderPath = $unzipFolder . '/app/etc/requirements/';
     $requirementsFile = $requirementsFolderPath . 'Requirements.php';
     $errors = array();
     if (!IOHelper::fileExists($requirementsFile)) {
         throw new Exception(Craft::t('The Requirements file is required and it does not exist at {path}.', array('path' => $requirementsFile)));
     }
     // Make sure we can write to craft/app/requirements
     if (!IOHelper::isWritable(craft()->path->getAppPath() . 'etc/requirements/')) {
         throw new Exception(StringHelper::parseMarkdown(Craft::t('Craft CMS needs to be able to write to your craft/app/etc/requirements folder and cannot. Please check your [permissions]({url}).', array('url' => 'http://craftcms.com/docs/updating#one-click-updating'))));
     }
     $tempFileName = StringHelper::UUID() . '.php';
     // Make a dupe of the requirements file and give it a random file name.
     IOHelper::copyFile($requirementsFile, $requirementsFolderPath . $tempFileName);
     $newTempFilePath = craft()->path->getAppPath() . 'etc/requirements/' . $tempFileName;
     // Copy the random file name requirements to the requirements folder.
     // We don't want to execute any PHP from the storage folder.
     IOHelper::copyFile($requirementsFolderPath . $tempFileName, $newTempFilePath);
     require_once $newTempFilePath;
     $checker = new RequirementsChecker();
     $checker->run();
     if ($checker->getResult() == RequirementResult::Failed) {
         foreach ($checker->getRequirements() as $requirement) {
             if ($requirement->getResult() == InstallStatus::Failed) {
                 Craft::log('Requirement "' . $requirement->getName() . '" failed with the message: ' . $requirement->getNotes(), LogLevel::Error, true);
                 $errors[] = $requirement->getNotes();
             }
         }
     }
     // Cleanup
     IOHelper::deleteFile($newTempFilePath);
     return $errors;
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:40,代码来源:Updater.php

示例3: _sendEmail


//.........这里部分代码省略.........
             case EmailerType::Pop:
                 $pop = new \Pop3();
                 if (!isset($emailSettings['host']) || !isset($emailSettings['port']) || !isset($emailSettings['username']) || !isset($emailSettings['password']) || StringHelper::isNullOrEmpty($emailSettings['host']) || StringHelper::isNullOrEmpty($emailSettings['port']) || StringHelper::isNullOrEmpty($emailSettings['username']) || StringHelper::isNullOrEmpty($emailSettings['password'])) {
                     throw new Exception(Craft::t('Host, port, username and password must be configured under your email settings.'));
                 }
                 if (!isset($emailSettings['timeout'])) {
                     $emailSettings['timeout'] = $this->_defaultEmailTimeout;
                 }
                 $pop->authorize($emailSettings['host'], $emailSettings['port'], $emailSettings['timeout'], $emailSettings['username'], $emailSettings['password'], craft()->config->get('devMode') ? 1 : 0);
                 $this->_setSmtpSettings($email, $emailSettings);
                 break;
             case EmailerType::Sendmail:
                 $email->isSendmail();
                 break;
             case EmailerType::Php:
                 $email->isMail();
                 break;
             default:
                 $email->isMail();
         }
         if (!$this->_processTestToEmail($email, 'Address')) {
             $email->addAddress($user->email, $user->getFullName());
         }
         // Add any custom headers
         if (!empty($emailModel->customHeaders)) {
             foreach ($emailModel->customHeaders as $headerName => $headerValue) {
                 $email->addCustomHeader($headerName, $headerValue);
             }
         }
         // Add any BCC's
         if (!empty($emailModel->bcc)) {
             if (!$this->_processTestToEmail($email, 'BCC')) {
                 foreach ($emailModel->bcc as $bcc) {
                     if (!empty($bcc['email'])) {
                         $bccEmail = $bcc['email'];
                         $bccName = !empty($bcc['name']) ? $bcc['name'] : '';
                         $email->addBCC($bccEmail, $bccName);
                     }
                 }
             }
         }
         // Add any CC's
         if (!empty($emailModel->cc)) {
             if (!$this->_processTestToEmail($email, 'CC')) {
                 foreach ($emailModel->cc as $cc) {
                     if (!empty($cc['email'])) {
                         $ccEmail = $cc['email'];
                         $ccName = !empty($cc['name']) ? $cc['name'] : '';
                         $email->addCC($ccEmail, $ccName);
                     }
                 }
             }
         }
         // Add a sender header (if any)
         if (!empty($emailModel->sender)) {
             $email->Sender = $emailModel->sender;
         }
         // Add any string attachments
         if (!empty($emailModel->stringAttachments)) {
             foreach ($emailModel->stringAttachments as $stringAttachment) {
                 $email->addStringAttachment($stringAttachment['string'], $stringAttachment['fileName'], $stringAttachment['encoding'], $stringAttachment['type']);
             }
         }
         // Add any normal disc attachments
         if (!empty($emailModel->attachments)) {
             foreach ($emailModel->attachments as $attachment) {
                 $email->addAttachment($attachment['path'], $attachment['name'], $attachment['encoding'], $attachment['type']);
             }
         }
         $variables['user'] = $user;
         $oldLanguage = craft()->getLanguage();
         // If they have a preferredLocale, use that.
         if ($user->preferredLocale) {
             craft()->setLanguage($user->preferredLocale);
         }
         $email->Subject = craft()->templates->renderString($emailModel->subject, $variables);
         // If they populated an htmlBody, use it.
         if ($emailModel->htmlBody) {
             $renderedHtmlBody = craft()->templates->renderString($emailModel->htmlBody, $variables);
             $email->msgHTML($renderedHtmlBody);
             $email->AltBody = craft()->templates->renderString($emailModel->body, $variables);
         } else {
             // They didn't provide an htmlBody, so markdown the body.
             $renderedHtmlBody = craft()->templates->renderString(StringHelper::parseMarkdown($emailModel->body), $variables);
             $email->msgHTML($renderedHtmlBody);
             $email->AltBody = craft()->templates->renderString($emailModel->body, $variables);
         }
         craft()->setLanguage($oldLanguage);
         if (!$email->Send()) {
             // Fire an 'onSendEmailError' event
             $this->onSendEmailError(new Event($this, array('user' => $user, 'emailModel' => $emailModel, 'variables' => $variables, 'error' => $email->ErrorInfo)));
             throw new Exception(Craft::t('Email error: {error}', array('error' => $email->ErrorInfo)));
         }
         Craft::log('Successfully sent email with subject: ' . $email->Subject, LogLevel::Info);
         // Fire an 'onSendEmail' event
         $this->onSendEmail(new Event($this, array('user' => $user, 'emailModel' => $emailModel, 'variables' => $variables)));
         return true;
     }
     return false;
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:101,代码来源:EmailService.php

示例4: actionSendMessage

 /**
  * Sends an email based on the posted params.
  *
  * @throws Exception
  */
 public function actionSendMessage()
 {
     $this->requirePostRequest();
     $settings = craft()->plugins->getPlugin('contactform')->getSettings();
     $message = new ContactFormModel();
     $savedBody = false;
     $message->fromEmail = craft()->request->getPost('fromEmail');
     $message->fromName = craft()->request->getPost('fromName');
     $message->subject = craft()->request->getPost('subject');
     if ($settings->allowAttachments) {
         if (isset($_FILES['attachment']) && isset($_FILES['attachment']['name'])) {
             if (is_array($_FILES['attachment']['name'])) {
                 $message->attachment = \CUploadedFile::getInstancesByName('attachment');
             } else {
                 $message->attachment = array(\CUploadedFile::getInstanceByName('attachment'));
             }
         }
     }
     // Set the message body
     $postedMessage = craft()->request->getPost('message');
     // Before compile event
     Craft::import('plugins.contactform.events.ContactFormMessageEvent');
     $event = new ContactFormMessageEvent($this, array('postedMessage' => $postedMessage));
     craft()->contactForm->onBeforeMessageCompile($event);
     if ($event->message && $event->messageFields) {
         $message->message = $event->message;
         $message->messageFields = $event->messageFields;
         if (!empty($event->htmlMessage)) {
             $message->htmlMessage = $event->htmlMessage;
         }
     } elseif ($postedMessage) {
         if (is_array($postedMessage)) {
             // Capture all of the message fields on the model in case there's a validation error
             $message->messageFields = $postedMessage;
             // Capture the original message body
             if (isset($postedMessage['body'])) {
                 // Save the message body in case we need to reassign it in the event there's a validation error
                 $savedBody = $postedMessage['body'];
             }
             // If it's false, then there was no messages[body] input submitted.  If it's '', then validation needs to fail.
             if ($savedBody === false || $savedBody !== '') {
                 // Compile the message from each of the individual values
                 $compiledMessage = '';
                 foreach ($postedMessage as $key => $value) {
                     if ($key != 'body') {
                         if ($compiledMessage) {
                             $compiledMessage .= "  \n";
                         }
                         $compiledMessage .= $key . ': ';
                         if (is_array($value)) {
                             $compiledMessage .= implode(', ', $value);
                         } else {
                             $compiledMessage .= $value;
                         }
                     }
                 }
                 if (!empty($postedMessage['body'])) {
                     if ($compiledMessage) {
                         $compiledMessage .= "\n\n";
                     }
                     $compiledMessage .= $postedMessage['body'];
                 }
                 $message->message = $compiledMessage;
             }
         } else {
             $message->message = $postedMessage;
             $message->messageFields = array('body' => $postedMessage);
         }
     }
     if (empty($message->htmlMessage)) {
         $message->htmlMessage = StringHelper::parseMarkdown($message->message);
     }
     if ($message->validate()) {
         // Only actually send it if the honeypot test was valid
         if (!$this->validateHoneypot($settings->honeypotField) || craft()->contactForm->sendMessage($message)) {
             if (craft()->request->isAjaxRequest()) {
                 $this->returnJson(array('success' => true));
             } else {
                 // Deprecated. Use 'redirect' instead.
                 $successRedirectUrl = craft()->request->getPost('successRedirectUrl');
                 if ($successRedirectUrl) {
                     $_POST['redirect'] = $successRedirectUrl;
                 }
                 craft()->userSession->setNotice($settings->successFlashMessage);
                 $this->redirectToPostedUrl($message);
             }
         }
     }
     // Something has gone horribly wrong.
     if (craft()->request->isAjaxRequest()) {
         return $this->returnErrorJson($message->getErrors());
     } else {
         craft()->userSession->setError('There was a problem with your submission, please check the form and try again!');
         if ($savedBody !== false) {
             $message->message = $savedBody;
//.........这里部分代码省略.........
开发者ID:vescoyez,项目名称:portfolio_v2,代码行数:101,代码来源:ContactFormController.php

示例5: _sendEmail


//.........这里部分代码省略.........
     // Get the saved email settings.
     $emailSettings = $this->getSettings();
     if (!isset($emailSettings['protocol'])) {
         throw new Exception(Craft::t('Could not determine how to send the email.  Check your email settings.'));
     }
     $email = new \PhpMailer(true);
     // Default the charset to UTF-8
     $email->CharSet = 'UTF-8';
     // Add a reply to (if any).  Make sure it’s set before setting From, because email is dumb.
     if (!empty($emailModel->replyTo)) {
         $email->AddReplyTo($emailModel->replyTo);
     }
     // Set the "from" information.
     $email->SetFrom($emailModel->fromEmail, $emailModel->fromName);
     // Check which protocol we need to use.
     switch ($emailSettings['protocol']) {
         case EmailerType::Gmail:
         case EmailerType::Smtp:
             $this->_setSmtpSettings($email, $emailSettings);
             break;
         case EmailerType::Pop:
             $pop = new \Pop3();
             if (!isset($emailSettings['host']) || !isset($emailSettings['port']) || !isset($emailSettings['username']) || !isset($emailSettings['password']) || StringHelper::isNullOrEmpty($emailSettings['host']) || StringHelper::isNullOrEmpty($emailSettings['port']) || StringHelper::isNullOrEmpty($emailSettings['username']) || StringHelper::isNullOrEmpty($emailSettings['password'])) {
                 throw new Exception(Craft::t('Host, port, username and password must be configured under your email settings.'));
             }
             if (!isset($emailSettings['timeout'])) {
                 $emailSettings['timeout'] = $this->_defaultEmailTimeout;
             }
             $pop->authorize($emailSettings['host'], $emailSettings['port'], $emailSettings['timeout'], $emailSettings['username'], $emailSettings['password'], craft()->config->get('devMode') ? 1 : 0);
             $this->_setSmtpSettings($email, $emailSettings);
             break;
         case EmailerType::Sendmail:
             $email->IsSendmail();
             break;
         case EmailerType::Php:
             $email->IsMail();
             break;
         default:
             $email->IsMail();
     }
     // If they have the test email config var set to something, use it instead of the supplied email.
     if (($testToEmail = craft()->config->get('testToEmailAddress')) != '') {
         $email->AddAddress($testToEmail, 'Test Email');
     } else {
         $email->AddAddress($user->email, $user->getFullName());
     }
     // Add any BCC's
     if (!empty($emailModel->bcc)) {
         foreach ($emailModel->bcc as $bcc) {
             if (!empty($bcc['email'])) {
                 $bccEmail = $bcc['email'];
                 $bccName = !empty($bcc['name']) ? $bcc['name'] : '';
                 $email->AddBcc($bccEmail, $bccName);
             }
         }
     }
     // Add any CC's
     if (!empty($emailModel->cc)) {
         foreach ($emailModel->cc as $cc) {
             if (!empty($cc['email'])) {
                 $ccEmail = $cc['email'];
                 $ccName = !empty($cc['name']) ? $cc['name'] : '';
                 $email->AddCc($ccEmail, $ccName);
             }
         }
     }
     // Add a sender header (if any)
     if (!empty($emailModel->sender)) {
         $email->Sender = $emailModel->sender;
     }
     // Add any string attachments
     if (!empty($emailModel->stringAttachments)) {
         foreach ($emailModel->stringAttachments as $stringAttachment) {
             $email->AddStringAttachment($stringAttachment['string'], $stringAttachment['fileName'], $stringAttachment['encoding'], $stringAttachment['type']);
         }
     }
     // Add any normal disc attachments
     if (!empty($emailModel->attachments)) {
         foreach ($emailModel->attachments as $attachment) {
             $email->AddAttachment($attachment['path'], $attachment['name'], $attachment['encoding'], $attachment['type']);
         }
     }
     $variables['user'] = $user;
     $email->Subject = craft()->templates->renderString($emailModel->subject, $variables);
     // If they populated an htmlBody, use it.
     if ($emailModel->htmlBody) {
         $renderedHtmlBody = craft()->templates->renderString($emailModel->htmlBody, $variables);
         $email->MsgHTML($renderedHtmlBody);
         $email->AltBody = craft()->templates->renderString($emailModel->body, $variables);
     } else {
         // They didn't provide an htmlBody, so markdown the body.
         $renderedHtmlBody = craft()->templates->renderString(StringHelper::parseMarkdown($emailModel->body), $variables);
         $email->MsgHTML($renderedHtmlBody);
         $email->AltBody = craft()->templates->renderString($emailModel->body, $variables);
     }
     if (!$email->Send()) {
         throw new Exception(Craft::t('Email error: {error}', array('error' => $email->ErrorInfo)));
     }
     return true;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:101,代码来源:EmailService.php

示例6: initCpAccessControl

 protected function initCpAccessControl()
 {
     if (craft()->request->isCpRequest() && craft()->userSession->isLoggedIn()) {
         $this->initMaintenance();
         if ($announcement = $this->announcement) {
             if (!craft()->userSession->checkPermission('maintenanceNoAnnouncements') && $announcement->getStatus() === 'inprogress') {
                 craft()->templates->includeTranslations('Maintenance in progress.');
                 $date = $announcement->startDate;
                 $meta = Craft::t('started {date}', array('date' => '<span class="maintenanceOverlay-date">' . $date->uiTimestamp() . '</span>'));
                 $message = StringHelper::parseMarkdown($announcement->message);
                 $maintenanceCPAccess = craft()->userSession->checkPermission('maintenanceCPAccess');
                 craft()->templates->includeJs('new Craft.MaintenanceModal(' . JsonHelper::encode($announcement) . ',' . JsonHelper::encode($message) . ',' . JsonHelper::encode($meta) . ',' . JsonHelper::encode($maintenanceCPAccess) . ');');
             }
         }
     }
 }
开发者ID:carlcs,项目名称:craft-maintenance,代码行数:16,代码来源:MaintenancePlugin.php

示例7: markdownFilter

 /**
  * Parses text through Markdown.
  *
  * @param string $str
  * @return string
  */
 public function markdownFilter($str)
 {
     $html = StringHelper::parseMarkdown($str);
     $charset = craft()->templates->getTwig()->getCharset();
     return new \Twig_Markup($html, $charset);
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:12,代码来源:CraftTwigExtension.php


注:本文中的StringHelper::parseMarkdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。