public function getCMSPreview()
 {
     $html = ViewableData::renderWith('Icon_CMS_Preview');
     $obj = HTMLText::create();
     $obj->setValue($html);
     return $obj;
 }
 function Thumbnail()
 {
     $res = HTMLText::create();
     $res->setValue("<em>No thumbnail found</em>");
     if ($this->GetThumbURL()) {
         $res->setValue("<img src='" . $this->GetThumbURL() . "' style='max-width: 120px; height: auto;' />");
     }
     return $res;
 }
 /**
  * @return string
  */
 protected function getContentSummary()
 {
     if ($this->Content) {
         /** @var HTMLText $html */
         $html = HTMLText::create();
         $html->setValue($this->dbObject('Content')->summary());
         return $html;
     }
     return '(none)';
 }
 public function IconsHTML()
 {
     $obj = HTMLText::create();
     $html = "";
     if ($this->owner->GridFieldIconRowClasses()) {
         foreach ($this->owner->GridFieldIconRowClasses() as $icon) {
             $html .= (new ArrayData(array('Icon' => $icon)))->renderWith('GridFieldIcon');
         }
     }
     $obj->setValue($html);
     return $obj;
 }
 public function stripCaption($caption, $limit = null)
 {
     // Remove the hash tags
     $caption = substr($caption, 0, strpos($caption, '#'));
     // Create a HTMLText
     $sf = HTMLText::create('Caption');
     $sf->setValue($caption);
     // Optional: limit the characters
     if ($limit != null) {
         return $sf->LimitCharacters($limit, '...');
     }
     return $sf;
 }
 /**
  * Unserialise the list of customisations and rendering into a basic
  * HTML string
  *
  */
 public function getCustomDetails()
 {
     $htmltext = HTMLText::create();
     $return = "";
     if ($this->Customisation) {
         $customisations = unserialize($this->Customisation);
         foreach ($customisations as $custom) {
             $return .= $custom->Title . ': ' . $custom->Value . ";<br/>";
         }
     }
     $htmltext->setValue($return);
     return $htmltext;
 }
 /**
  * Unserialise the list of customisations and rendering into a basic
  * HTML string
  *
  */
 public function CustomisationHTML()
 {
     $return = HTMLText::create();
     $items = $this->Customisations();
     $html = "";
     if ($items && $items->exists()) {
         foreach ($items as $item) {
             $html .= $item->Title . ': ' . $item->Value . ";<br/>";
         }
     }
     $return->setValue($html);
     return $return;
 }
 public function getCMSState()
 {
     if ($this->owner->UserSubmissionHolder()) {
         $page = $this->owner->UserSubmissionPage();
         if ($page && $page->exists()) {
             $colour = '#18BA18';
             $text = 'Page Created';
         } else {
             $colour = '#1391DF';
             $text = 'Pending';
         }
         $html = HTMLText::create('CMSState');
         $html->setValue(sprintf('<span style="color: %s;">%s</span>', $colour, htmlentities($text)));
         return $html;
     }
 }
 /**
  * Return whether the participation is opened
  * for gridfield summary
  *
  * @return HTMLText
  */
 public function getStatus()
 {
     $colours = array('red', 'green', 'blue');
     $colour = !$this->hasStarted() ? $colours[2] : $colours[(int) $this->isOpen()];
     $message = '';
     // Not started yet
     if (!$this->hasStarted()) {
         $date = new DateTime($this->Starts);
         $message = 'Starting on ' . $date->format('d-m-Y');
     } else {
         $message = $this->hasExpired() ? 'Expired' : 'Active';
     }
     $output = sprintf('<span style="color:%s">%s</span>', $colour, $message);
     $field = HTMLText::create('Status');
     $field->setValue($output);
     return $field;
 }
 public function getFlaggedNice()
 {
     $obj = HTMLText::create();
     $obj->setValue($this->Flag ? '<span class="red">&#10033;</span>' : '');
     return $obj;
 }
 /**
  * Helper for summary fields.
  * Returns the badge color indicator.
  * 
  * @return string
  */
 public function getBadgeColorIndicator()
 {
     $badgeColorSource = array('default' => '<span style="padding: 4px 8px; color: #fff; background-color:#999999">' . $this->Title . '</span>', 'success' => '<span style="padding: 4px 8px; color: #fff; background-color:#468847">' . $this->Title . '</span>', 'warning' => '<span style="padding: 4px 8px; color: #fff; background-color:#f89406">' . $this->Title . '</span>', 'important' => '<span style="padding: 4px 8px; color: #fff; background-color:#b94a48">' . $this->Title . '</span>', 'info' => '<span style="padding: 4px 8px; color: #fff; background-color:#3a87ad">' . $this->Title . '</span>', 'inverse' => '<span style="padding: 4px 8px; color: #fff; background-color:#333333">' . $this->Title . '</span>');
     if (empty($this->badgeColor) || !array_key_exists($this->badgeColor, $badgeColorSource)) {
         $this->badgeColor = 'default';
     }
     $htmlText = HTMLText::create();
     $htmlText->setValue($badgeColorSource[$this->badgeColor]);
     return $htmlText;
 }
 /**
  * Return a HTMLText object for use within a grid field 
  *
  * @since version 1.0.0
  * 
  * @param string $span The HTML span
  *
  * @return object
  **/
 private function getGridSpan($span)
 {
     $html = HTMLText::create();
     $html->setValue($span);
     return $html;
 }
Esempio n. 13
0
 /**
  * @return HTMLText
  */
 public function isPublishedIcon()
 {
     $obj = HTMLText::create();
     if ($this->isPublished()) {
         $obj->setValue('<img src="' . FRAMEWORK_ADMIN_DIR . '/images/alert-good.gif" />');
     } else {
         $obj->setValue('<img src="' . FRAMEWORK_ADMIN_DIR . '/images/alert-bad.gif" />');
     }
     return $obj;
 }
 /**
  * Submit the form
  *
  * @param $data
  * @param $form
  * @return bool|SS_HTTPResponse
  */
 public function Submit($data, $form)
 {
     $recaptchaResponse = $recaptchaResponse = $data['g-recaptcha-response'];
     /** @var Form $form */
     $data = $form->getData();
     /** Set the form state */
     Session::set('FormInfo.Form_' . $this->name . '.data', $data);
     /**
      * reCAPTCHA
      * Based on https://github.com/google/recaptcha
      */
     if ($this->controller->data()->ReCaptchaSiteKey && $this->controller->data()->ReCaptchaSecretKey) {
         $recaptcha = new \ReCaptcha\ReCaptcha($this->controller->data()->ReCaptchaSecretKey);
         $resp = $recaptcha->verify($recaptchaResponse);
         if ($resp->isSuccess()) {
             /**
              * Verified
              */
         } else {
             /**
              * Not Verified
              *
              * @var HTMLText $errors
              */
             $errors = HTMLText::create();
             $html = '';
             /**
              * Error code reference
              * https://developers.google.com/recaptcha/docs/verify
              */
             foreach ($resp->getErrorCodes() as $code) {
                 switch ($code) {
                     case 'missing-input-secret':
                         $html .= _t('ContactForm.RecaptchaMissingInputSecret', 'The secret parameter is missing.');
                         break;
                     case 'invalid-input-secret':
                         $html .= _t('ContactForm.RecaptchaInvalidInputSecret', 'The secret parameter is invalid or malformed.');
                         break;
                     case 'missing-input-response':
                         $html .= _t('ContactForm.RecaptchaMissingInputResponse', 'Please check the reCAPTCHA below to confirm you\'re human.');
                         break;
                     case 'invalid-input-response':
                         $html .= _t('ContactForm.RecaptchaInvalidInputResponse', 'The response parameter is invalid or malformed.');
                         break;
                     default:
                         $html .= _t('ContactForm.RecaptchaDefaultError', 'There was an error submitting the reCAPTCHA, please try again.');
                 }
             }
             $errors->setValue($html);
             $this->controller->setFlash(_t('ContactForm.RecaptchaFormError', 'Your message has not been sent, please fill out all of the <strong>required fields.</strong>'), 'warning');
             $form->addErrorMessage('ReCaptcha', $errors, 'bad', false);
             return $this->controller->redirect($this->controller->Link());
         }
     }
     /** -----------------------------------------
      * Email
      * ----------------------------------------*/
     $data['Logo'] = SiteConfig::current_site_config()->LogoImage();
     $From = $data['Email'];
     $To = $this->controller->data()->MailTo;
     $Subject = SiteConfig::current_site_config()->Title . _t('ContactForm.EmailSubject', ' - Contact message');
     /** @var Email $email */
     $email = Email::create($From, $To, $Subject);
     if ($cc = $this->controller->data()->MailCC) {
         $email->setCc($cc);
     }
     if ($bcc = $this->controller->data()->MailBCC) {
         $email->setBcc($bcc);
     }
     $email->setTemplate('ContactEmail')->populateTemplate($data)->send();
     if ($this->controller->data()->SubmitText) {
         $submitText = $this->controller->data()->SubmitText;
     } else {
         $submitText = _t('ContactForm.SubmitText', 'Thank you for contacting us, we will get back to you as soon as possible.');
     }
     $this->controller->setFlash($submitText, 'success');
     /** -----------------------------------------
      * Records
      * ----------------------------------------*/
     /** @var ContactMessage $contactMessage */
     $contactMessage = ContactMessage::create();
     $form->saveInto($contactMessage);
     $contactMessage->write();
     /** Clear the form state */
     Session::clear('FormInfo.Form_' . $this->name . '.data');
     return $this->controller->redirect($this->controller->data()->Link('?success=1'));
 }