function ListOfQuestions() { $output = ''; foreach ($this->Questions() as $sq) { $output .= "Label: \"" . $sq->Label . "\" | Type: \"" . $sq->ClassName . "\"<br>"; } $richText = new HTMLText('something'); $richText->setValue($output); return $richText; }
function ListOfQuestions() { $output = ''; foreach ($this->SurveyQuestions() as $sq) { $output .= $sq->Number . " " . $sq->Title . "<br>"; } $richText = new HTMLText('something'); $richText->setValue($output); return $richText; }
function testFirstSentence() { $many = str_repeat('many ', 100); $cases = array('<h1>should ignore</h1><p>First sentence. Second sentence.</p>' => 'First sentence.', '<h1>should ignore</h1><p>First Mr. sentence. Second sentence.</p>' => 'First Mr. sentence.', "<h1>should ignore</h1><p>Sentence with {$many}words. Second sentence.</p>" => "Sentence with {$many}words."); foreach ($cases as $orig => $match) { $textObj = new HTMLText(); $textObj->setValue($orig); $this->assertEquals($match, $textObj->FirstSentence()); } }
/** * Provide a way to get the required script for AB testing into the template engine * * @return mixed */ public function getABTestGlobalScript() { if ($this->owner->getField('ABGlobalTest') != 0) { if (!is_null($this->owner->getField('ABTestGlobalScript'))) { $html = new HTMLText(); $html->setValue($this->owner->getField('ABTestGlobalScript')); return $html; } } return false; }
/** * Provide a way to get the required script for AB testing into the template engine * * @return mixed */ public function getABTestScript() { if ($this->owner->ABTestPage) { if ($this->owner->ABTestInlineScript) { $html = new HTMLText(); $html->setValue($this->owner->ABTestInlineScript); return $html; } } return false; }
public function getCMSPreview() { $html = ViewableData::renderWith('Icon_CMS_Preview'); $obj = HTMLText::create(); $obj->setValue($html); return $obj; }
/** * Trackback notify the specified trackback url * @param boolean | true on success, otherwise false */ function trackbackNotify($url) { $content = new HTMLText('Content'); $content->setValue($this->owner->Content); $excerpt = $content->FirstParagraph(); if ($this->owner->Parent() && $this->owner->ParentID > 0) { $blogName = $this->owner->Parent()->Title; } else { $blogName = ""; } $postData = array('url' => $this->owner->AbsoluteLink(), 'title' => $this->owner->Title, 'excerpt' => $excerpt, 'blog_name' => $blogName); $controller = Object::create(self::$trackback_server_class); $response = $controller->request($url, $postData); if ($response->getStatusCode() == '200' && stripos($response->getBody(), "<error>0</error>") !== false) { return true; } return false; }
/** * @return HTMLText */ public function getCMSPublishedState() { $html = new HTMLText('PublishedState'); if ($this->isPublished()) { if ($this->stagesDiffer('Stage', 'Live')) { $colour = '#1391DF'; $text = 'Modified'; } else { $colour = '#18BA18'; $text = 'Published'; } } else { $colour = '#C00'; $text = 'Draft'; } $html->setValue(sprintf('<span style="color: %s;">%s</span>', $colour, htmlentities($text))); return $html; }
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 getCMSPublishedState() { if ($this->isInvalidPublishState()) { $colour = '#C00'; $text = 'Error'; $html = new HTMLText('PublishedState'); $html->setValue(sprintf('<span style="color: %s;">%s</span>', $colour, htmlentities($text))); return $html; } $publishedState = null; foreach ($this->extension_instances as $instance) { if (method_exists($instance, 'getCMSPublishedState')) { $instance->setOwner($this); $publishedState = $instance->getCMSPublishedState(); $instance->clearOwner(); break; } } return $publishedState; }
/** * Rewrite the links * * @param NewsletterEmail */ function updateNewsletterEmail(&$email) { if (!$email->body || !$email->newsletter) { return; } $text = $email->body->forTemplate(); // find all the matches if (preg_match_all("/<a\\s[^>]*href=\"([^\"]*)\"[^>]*>(.*)<\\/a>/siU", $text, $matches)) { if (isset($matches[1]) && ($links = $matches[1])) { $titles = isset($matches[2]) ? $matches[2] : array(); $id = (int) $email->newsletter->ID; $replacements = array(); $current = array(); // workaround as we want to match the longest urls (/foo/bar/baz) before /foo/ array_unique($links); $sorted = array_combine($links, array_map('strlen', $links)); arsort($sorted); foreach ($sorted as $link => $length) { $SQL_link = Convert::raw2sql($link); $tracked = DataObject::get_one('Newsletter_TrackedLink', "\"NewsletterID\" = '" . $id . "' AND \"Original\" = '" . $SQL_link . "'"); if (!$tracked) { // make one. $tracked = new Newsletter_TrackedLink(); $tracked->Original = $link; $tracked->NewsletterID = $id; $tracked->write(); } // replace the link $replacements[$link] = $tracked->Link(); // track that this link is still active $current[] = $tracked->ID; } // replace the strings $text = str_ireplace(array_keys($replacements), array_values($replacements), $text); // replace the body $output = new HTMLText(); $output->setValue($text); $email->body = $output; } } }
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; }
/** * Returns the string which will be used in the template * @return string */ public function forTemplate() { $isEditable = FrontendEditing::editingEnabled() && FrontendEditing::isEditable($this); if ($isEditable) { $this->processShortcodes = false; } $value = parent::forTemplate(); if ($isEditable) { $randId = uniqid(); $value = '<div id="' . $randId . '" contenteditable=true class="frontend-editable frontend-editable-html" data-feclass="' . FrontendEditing::getClassName($this) . '" data-feid="' . FrontendEditing::getID($this) . '" data-fefield="' . $this->name . '">' . $value . '</div>'; } return $value; }
/** * 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 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; }
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; }
/** * Return a list string summarising each item in this order * * @return string */ public function getItemSummaryHTML() { $html = new HTMLText("ItemSummary"); $html->setValue(nl2br($this->ItemSummary)); $this->extend("updateItemSummary", $html); return $html; }
/** * Returns the additional email recipients as a html string * * @return string */ public function getAdditionalRecipientsHtmlString() { $additionalRecipientsArray = array(); if ($this->AdditionalReceipients()->exists()) { foreach ($this->AdditionalReceipients() as $additionalRecipient) { $additionalRecipientsArray[] = htmlentities($additionalRecipient->getEmailAddressWithName()); } } $additionalRecipientsHtml = new HTMLText(); $additionalRecipientsHtml->setValue(implode('<br/>', $additionalRecipientsArray)); return $additionalRecipientsHtml; }
/** * Get a bbcode parsed summary of the blog entry */ function ParagraphSummary(){ if(self::$allow_wysiwyg_editing) { return $this->obj('Content')->FirstParagraph('html'); } else { $parser = new BBCodeParser($this->Content); $html = new HTMLText('Content'); $html->setValue($parser->parse()); return $html->FirstParagraph('html'); } }
/** * @param Newsletter $newsletter * @param Mailinglists $recipient * @param Boolean $fakeRecipient */ function __construct($newsletter, $recipient, $fakeRecipient = false) { $this->newsletter = $newsletter; $this->mailinglists = $newsletter->MailingLists(); $this->recipient = $recipient; $this->fakeRecipient = $fakeRecipient; parent::__construct($this->newsletter->SendFrom, $this->recipient->Email); $this->populateTemplate(new ArrayData(array('UnsubscribeLink' => $this->UnsubscribeLink(), 'SiteConfig' => DataObject::get_one('SiteConfig'), 'AbsoluteBaseURL' => Director::absoluteBaseURLWithAuth()))); $this->body = $newsletter->getContentBody(); $this->subject = $newsletter->Subject; $this->ss_template = $newsletter->RenderTemplate; if ($this->body && $this->newsletter) { $text = $this->body->forTemplate(); //Recipient Fields ShortCode parsing $bodyViewer = new SSViewer_FromString($text); $text = $bodyViewer->process($this->templateData()); // Install link tracking by replacing existing links with "newsletterlink" and hash-based reference. if ($this->config()->link_tracking_enabled && !$this->fakeRecipient && preg_match_all("/<a\\s[^>]*href=\"([^\"]*)\"[^>]*>(.*)<\\/a>/siU", $text, $matches)) { if (isset($matches[1]) && ($links = $matches[1])) { $titles = isset($matches[2]) ? $matches[2] : array(); $id = (int) $this->newsletter->ID; $replacements = array(); $current = array(); // workaround as we want to match the longest urls (/foo/bar/baz) before /foo/ array_unique($links); $sorted = array_combine($links, array_map('strlen', $links)); arsort($sorted); foreach ($sorted as $link => $length) { $SQL_link = Convert::raw2sql($link); $tracked = DataObject::get_one('Newsletter_TrackedLink', "\"NewsletterID\" = '" . $id . "' AND \"Original\" = '" . $SQL_link . "'"); if (!$tracked) { // make one. $tracked = new Newsletter_TrackedLink(); $tracked->Original = $link; $tracked->NewsletterID = $id; $tracked->write(); } // replace the link $replacements[$link] = $tracked->Link(); // track that this link is still active $current[] = $tracked->ID; } // replace the strings $text = str_ireplace(array_keys($replacements), array_values($replacements), $text); } } // replace the body $output = new HTMLText(); $output->setValue($text); $this->body = $output; } }
/** * return the orders invoice address as complete HTML string. * * @return string */ public function getInvoiceAddressSummaryHtml() { $html = new HTMLText(); $html->setValue(str_replace(PHP_EOL, '<br/>', $this->InvoiceAddressSummary)); return $html; }
function deleteinstallfiles() { $title = new Varchar("Title"); $content = new HTMLText("Content"); $tempcontent = ''; $username = Session::get('username'); $password = Session::get('password'); $installfiles = array( 'index.php', 'install.php', 'rewritetest.php', 'config-form.css', 'config-form.html', 'index.html' ); foreach($installfiles as $installfile) { if(file_exists('../' . $installfile)) { @unlink('../' . $installfile); } if(file_exists('../' . $installfile)) { $unsuccessful[] = $installfile; } } if(isset($unsuccessful)) { $title->setValue("Unable to delete installation files"); $tempcontent = "<p style=\"margin: 1em 0\">Unable to delete installation files. Please delete the files below manually:</p><ul>"; foreach($unsuccessful as $unsuccessfulFile) { $tempcontent .= "<li>$unsuccessfulFile</li>"; } $tempcontent .= "</ul>"; } else { $title->setValue("Deleted installation files"); $tempcontent = <<<HTML <p style="margin: 1em 0">Installation files have been successfully deleted.</p> HTML ; } $tempcontent .= <<<HTML <p style="margin: 1em 0">You can start editing your site's content by opening <a href="admin/">the CMS</a>. <br /> Email: $username<br /> Password: $password<br /> </p> HTML ; $content->setValue($tempcontent); return array( "Title" => $title, "Content" => $content, ); }
function deleteinstallfiles() { if (!Permission::check("ADMIN")) { return Security::permissionFailure($this); } $title = new Varchar("Title"); $content = new HTMLText("Content"); $tempcontent = ''; $username = Session::get('username'); $password = Session::get('password'); // We can't delete index.php as it might be necessary for URL routing without mod_rewrite. // There's no safe way to detect usage of mod_rewrite across webservers, // so we have to assume the file is required. $installfiles = array('install.php', 'config-form.css', 'config-form.html', 'index.html'); foreach ($installfiles as $installfile) { if (file_exists(BASE_PATH . '/' . $installfile)) { @unlink(BASE_PATH . '/' . $installfile); } if (file_exists(BASE_PATH . '/' . $installfile)) { $unsuccessful[] = $installfile; } } if (isset($unsuccessful)) { $title->setValue("Unable to delete installation files"); $tempcontent = "<p style=\"margin: 1em 0\">Unable to delete installation files. Please delete the files below manually:</p><ul>"; foreach ($unsuccessful as $unsuccessfulFile) { $tempcontent .= "<li>{$unsuccessfulFile}</li>"; } $tempcontent .= "</ul>"; } else { $title->setValue("Deleted installation files"); $tempcontent = <<<HTML <p style="margin: 1em 0">Installation files have been successfully deleted.</p> HTML; } $tempcontent .= <<<HTML \t\t\t<p style="margin: 1em 0">You can start editing your site's content by opening <a href="admin/">the CMS</a>. <br /> \t\t\t\t Email: {$username}<br /> \t\t\t\t Password: {$password}<br /> \t\t\t</p> HTML; $content->setValue($tempcontent); return array("Title" => $title, "Content" => $content); }
/** * returns the order positions Title with extensions * * @return string */ public function getFullTitle() { $fullTitle = $this->Title . '<br/>' . $this->addToTitle(); $htmlText = new HTMLText(); $htmlText->setValue($fullTitle); return $htmlText; }
/** * Get a bbcode parsed summary of the blog entry * @deprecated */ function ParagraphSummary() { user_error("BlogEntry::ParagraphSummary() is deprecated; use BlogEntry::Content()", E_USER_NOTICE); $val = $this->Content(); $content = $val; if (!$content instanceof HTMLText) { $content = new HTMLText('Content'); $content->value = $val; } return $content->FirstParagraph('html'); }
public function getFlaggedNice() { $obj = HTMLText::create(); $obj->setValue($this->Flag ? '<span class="red">✱</span>' : ''); return $obj; }
function testWhitelist() { $textObj = new HTMLText('Test', 'meta,link'); $this->assertEquals('<meta content="Keep"><link href="Also Keep">', $textObj->whitelistContent('<meta content="Keep"><p>Remove</p><link href="Also Keep" />Remove Text'), 'Removes any elements not in whitelist excluding text elements'); $textObj = new HTMLText('Test', 'meta,link,text()'); $this->assertEquals('<meta content="Keep"><link href="Also Keep">Keep Text', $textObj->whitelistContent('<meta content="Keep"><p>Remove</p><link href="Also Keep" />Keep Text'), 'Removes any elements not in whitelist including text elements'); }