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()); } }
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; }
/** * 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; }
/** * 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; }
/** * @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; }
/** * 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; }
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; } } }
/** * 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; }
function testExists() { $h = new HTMLText(); $h->setValue(""); $this->assertFalse($h->exists()); $h->setValue("<p></p>"); $this->assertFalse($h->exists()); $h->setValue("<p> </p>"); $this->assertFalse($h->exists()); $h->setValue("<h2/>"); $this->assertFalse($h->exists()); $h->setValue("<h2></h2>"); $this->assertFalse($h->exists()); $h->setValue("something"); $this->assertTrue($h->exists()); $h->setValue("<img src=\"dummy.png\">"); $this->assertTrue($h->exists()); $h->setValue("<img src=\"dummy.png\"><img src=\"dummy.png\">"); $this->assertTrue($h->exists()); $h->setValue("<p><img src=\"dummy.png\"></p>"); $this->assertTrue($h->exists()); $h->setValue("<iframe src=\"http://www.google.com\"></iframe>"); $this->assertTrue($h->exists()); $h->setValue("<embed src=\"test.swf\">"); $this->assertTrue($h->exists()); $h->setValue("<object width=\"400\" height=\"400\" data=\"test.swf\"></object>"); $this->assertTrue($h->exists()); $h->setValue("<p>test</p>"); $this->assertTrue($h->exists()); }
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, ); }
/** * 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'); } }
/** * Display the currently selected order from the URL * */ public function order() { $orderID = $this->owner->request->param("ID"); $order = Order::get()->byID($orderID); $content = new HTMLText(); if (!$order || $order && !$order->canView()) { $message = '<p class="message message-error">'; $message .= _t("CommerceAccount.NotFound", "Order not found"); $message .= '</p>'; $title = _t("CommerceAccount.NotFound", "Order not found"); $content->setValue($message); $order = null; } else { $title = _t('Commerce.Order', 'Order') . ': ' . $order->OrderNumber; } $this->owner->customise(array("ClassName" => "AccountPage", "Title" => $title, "Content" => $content, "Order" => $order)); return $this->owner->renderWith(array("Commerce_Account_order", "Commerce", "Page")); }
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); }
/** * 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; }
public function deleteinstallfiles() { if (!Permission::check("ADMIN")) { return Security::permissionFailure($this); } $title = new Varchar("Title"); $content = new HTMLText('Content'); // 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'); $unsuccessful = new ArrayList(); foreach ($installfiles as $installfile) { if (file_exists(BASE_PATH . '/' . $installfile)) { @unlink(BASE_PATH . '/' . $installfile); } if (file_exists(BASE_PATH . '/' . $installfile)) { $unsuccessful->push(new ArrayData(array('File' => $installfile))); } } $data = new ArrayData(array('Username' => Convert::raw2xml(Session::get('username')), 'Password' => Convert::raw2xml(Session::get('password')), 'UnsuccessfulFiles' => $unsuccessful)); $content->setValue($data->renderWith('Install_deleteinstallfiles')); return array("Title" => $title, "Content" => $content); }
/** * 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; }
/** * @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 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; }
/** * Set the value on the field. * Optionally takes the whole record as an argument, * to pick other values. * * @param mixed $value * @param array $record */ public function setValue($value, $record = null) { FrontendEditing::setValue($this, $value, $record); parent::setValue($value, $record); }