public function sendHTML($to, $from, $subject, $html, $attachments = false, $headers = false, $plain = false, $inlineImages = false) { if ($inlineImages) { user_error('The SES mailer does not support inlining images', E_USER_NOTICE); } $htmlPart = new Mime\Part($html); $htmlPart->type = Mime\Mime::TYPE_HTML; $htmlPart->charset = 'utf-8'; $htmlPart->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE; $plainPart = new Mime\Part($plain ?: \Convert::xml2raw($html)); $plainPart->type = Mime\Mime::TYPE_TEXT; $plainPart->charset = 'utf-8'; $plainPart->encoding = Mime\Mime::ENCODING_QUOTEDPRINTABLE; $alternatives = new Mime\Message(); $alternatives->setParts(array($plainPart, $htmlPart)); $alternativesPart = new Mime\Part($alternatives->generateMessage()); $alternativesPart->type = Mime\Mime::MULTIPART_ALTERNATIVE; $alternativesPart->boundary = $alternatives->getMime()->boundary(); $body = new Mime\Message(); $body->addPart($alternativesPart); if ($attachments) { $this->addAttachments($body, $attachments); } $this->sendMessage($to, $from, $subject, $body, $headers); }
/** * Tests {@link Convert::xml2raw()} */ function testXml2Raw() { $val1 = '<input type="text">'; $this->assertEquals('<input type="text">', Convert::xml2raw($val1), 'Special characters are escaped'); $val2 = 'This is some normal text.'; $this->assertEquals('This is some normal text.', Convert::xml2raw($val2), 'Normal text is not escaped'); }
/** * This method loads the content of the given array $data into the current * dataobject. Similar to the DataObject-merge function, but * without iterating through the relationships. * * @param $data array of attributes (keys should match to the $db fields). */ public function loadData($data) { if ($data == null) { return; } if (!is_array($data)) { return; } foreach ($data as $k => $v) { $this->{$k} = Convert::xml2raw($v); } }
/** * This method loads a provided array into the data structure. * It also creates dependencies, such as contact data objects * and populate the values into those objects. * * @param $data array of db-values. */ public function loadData($data) { if ($data == null) { return; } if (!is_array($data)) { return; } foreach ($data as $k => $v) { // store data into this object (no ':" in the string) if (strpos($k, ':') === false) { $this->{$k} = Convert::xml2raw($v); } else { // A ':' is used as a namespace marker. It is used to // create the related data objects, such as MDContacts. $relations = explode(':', $k); $fieldName = array_pop($relations); $relObj = $this; // iterate through the relationships. At the moment, this // loading process just works for 1 level hierarchies. foreach ($relations as $relation) { if ($relation == 'MDVoice') { // load the sub-array into the MDContact object foreach ($v as $mdVoiceEntry) { $item = new MDPhoneNumber(); $item->loadData($mdVoiceEntry); // add object to list $relObj->MDVoice()->add($item); } } } foreach ($relations as $relation) { if ($relation == 'MDElectronicMailAddress') { // load the sub-array into the MDContact object foreach ($v as $mdEmail) { $item = new MDEmail(); $item->loadData($mdEmail); // add object to list $relObj->MDElectronicMailAddress()->add($item); } } } } } }
function testSiteTreeHints() { $cache = SS_Cache::factory('CMSMain_SiteTreeHints'); // Login as user with root creation privileges $user = $this->objFromFixture('Member', 'rootedituser'); $user->logIn(); $cache->clean(Zend_Cache::CLEANING_MODE_ALL); $rawHints = singleton('CMSMain')->SiteTreeHints(); $this->assertNotNull($rawHints); $rawHints = preg_replace('/^"(.*)"$/', '$1', Convert::xml2raw($rawHints)); $hints = Convert::json2array($rawHints); $this->assertArrayHasKey('Root', $hints); $this->assertArrayHasKey('Page', $hints); $this->assertArrayHasKey('All', $hints); $this->assertArrayHasKey('CMSMainTest_ClassA', $hints['All'], 'Global list shows allowed classes'); $this->assertArrayNotHasKey('CMSMainTest_HiddenClass', $hints['All'], 'Global list does not list hidden classes'); $this->assertNotContains('CMSMainTest_ClassA', $hints['Root']['disallowedChildren'], 'Limits root classes'); $this->assertContains('CMSMainTest_NotRoot', $hints['Root']['disallowedChildren'], 'Limits root classes'); }
function testSiteTreeHints() { $cache = SS_Cache::factory('CMSMain_SiteTreeHints'); $cache->clean(Zend_Cache::CLEANING_MODE_ALL); $rawHints = singleton('CMSMain')->SiteTreeHints(); $this->assertNotNull($rawHints); $rawHints = preg_replace('/^"(.*)"$/', '$1', Convert::xml2raw($rawHints)); $hints = Convert::json2array($rawHints); $this->assertArrayHasKey('Root', $hints); $this->assertArrayHasKey('Page', $hints); $this->assertArrayHasKey('All', $hints); $this->assertArrayHasKey('CMSMainTest_ClassA', $hints['All'], 'Global list shows allowed classes'); $this->assertArrayNotHasKey('CMSMainTest_HiddenClass', $hints['All'], 'Global list does not list hidden classes'); $this->assertNotContains('CMSMainTest_ClassA', $hints['Root']['disallowedChildren'], 'Limits root classes'); $this->assertContains('CMSMainTest_NotRoot', $hints['Root']['disallowedChildren'], 'Limits root classes'); $this->assertNotContains('CMSMainTest_ClassA', (array) @$hints['Page']['disallowedChildren'], 'Does not limit types on unlimited parent'); $this->assertContains('Page', $hints['CMSMainTest_ClassA']['disallowedChildren'], 'Limited parent lists disallowed classes'); $this->assertNotContains('CMSMainTest_ClassB', $hints['CMSMainTest_ClassA']['disallowedChildren'], 'Limited parent omits explicitly allowed classes in disallowedChildren'); }
/** * Return the value of the given field without any escaping. * @param string $fieldName The field name. * @param array $args The arguments. * @return string */ public function RAW_val($fieldName, $args = null) { return Convert::xml2raw($this->XML_val($fieldName, $args)); }
/** * getNumWordsContent. * get the number of words in the Page Content * * @param none * @return Integer Number of words in content */ public function getNumWordsContent() { return str_word_count(Convert::xml2raw($this->getPageContent())); }
/** * Helper function to get page count */ function getpagecount() { ini_set('max_execution_time', 0); $excludePages = split(" *, *", $_GET['exclude']); $pages = DataObject::get("SiteTree", "\"ParentID\" = 0"); foreach ($pages as $page) { $pageArr[] = $page; } while (list($i, $page) = each($pageArr)) { if (!in_array($page->URLSegment, $excludePages)) { if ($children = $page->AllChildren()) { foreach ($children as $child) { $pageArr[] = $child; } } if (!$_GET['onlywithcontent'] || strlen(Convert::xml2raw($page->Content)) > 100) { echo "<li>" . $page->Breadcrumbs(null, true) . "</li>"; $count++; } else { echo "<li style=\"color: #777\">" . $page->Breadcrumbs(null, true) . " - " . _t('CMSMain.NOCONTENT', "no content") . "</li>"; } } } echo '<p>' . _t('CMSMain.TOTALPAGES', "Total pages: ") . "{$count}</p>"; }
/** * Encrypting HTML emails does not work so this method triggers a warning and sends using sendPlain() and plaintext * version of the HTML content. * * @param string $to To address RFC 2822 format * @param string $from From address RFC 2822 format * @param string $subject Subject line for email * @param string $plainContent Content for email * @param boolean $attachedFiles Indicate whether files are attached * @param array $customheaders Custom email headers * @return mixed Array if successful or false if unsuccessful */ public function sendHTML($to, $from, $subject, $htmlContent, $attachedFiles = false, $customheaders = false, $plainContent = false) { // HTML emails cannot be encrypted and create a number of issues, sendPlain() should be used instead trigger_error('HTML email content cannot be encrypted, only the plain text component of this email will be generated.', E_USER_WARNING); if (!$plainContent) { $plainContent = Convert::xml2raw($htmlContent); } return $this->sendPlain($to, $from, $subject, $plainContent, $attachedFiles, $customheaders); }
/** * Get plain-text version * * @return string */ public function Plain() { // Preserve line breaks $text = preg_replace('/\\<br(\\s*)?\\/?\\>/i', "\n", $this->RAW()); // Convert paragraph breaks to multi-lines $text = preg_replace('/\\<\\/p\\>/i', "\n\n", $text); // Strip out HTML tags $text = strip_tags($text); // Implode >3 consecutive linebreaks into 2 $text = preg_replace('~(\\R){2,}~', "\n\n", $text); // Decode HTML entities back to plain text return trim(\Convert::xml2raw($text)); }
/** * This method loads a provided array into the data structure. * It also creates dependencies, such as contact data objects * and populate the values into those objects. * * @param $data array of db-values. */ public function loadData($data) { if ($data == null) { return; } if (!is_array($data)) { return; } foreach ($data as $k => $v) { // store data into this object (no ':" in the string) if (strpos($k, ':') === false) { $this->{$k} = Convert::xml2raw($v); } else { // A ':' is used as a namespace marker. It is used to // create the related data objects, such as MDContacts. $relations = explode(':', $k); $fieldName = array_pop($relations); $relObj = $this; // iterate through the relationships. At the moment, this // loading process just works for 1 level hierarchies. foreach ($relations as $relation) { if ($relation == 'PointOfContacts') { // load the sub-array into the MDContact object $item = new MDContact(); $item->loadData($v); // add the new MDContect to the collection class of this // object. $relObj->PointOfContacts()->add($item); } if ($relation == 'MDContacts') { // load the sub-array into the MDContact object $item = new MDContact(); $item->loadData($v); // add the new MDContect to the collection class of this // object. $relObj->MDContacts()->add($item); } if ($relation == 'MDResourceConstraints') { // load the sub-array into the MDResourceConstraints object if (is_array($v)) { foreach ($v as $vitem) { $item = new MDResourceConstraint(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->MDResourceConstraints()->add($item); } } } if ($relation == 'MDResourceFormats') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDResourceFormats object $item = new MDResourceFormat(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->MDResourceFormats()->add($item); } } } if ($relation == 'MDTopicCategory') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDResourceFormats object $item = new MDTopicCategory(); $item->loadData($vitem); // add the new MDTopicCategory to the collection class of this // object. $relObj->MDTopicCategory()->add($item); } } } if ($relation == 'MDCitationDates') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDResourceFormats object $item = new MDCitationDate(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->MDCitationDates()->add($item); } } } if ($relation == 'MCPMDCreativeCommons') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDContact object $item = new MCPMDCreativeCommons(); $item->loadData($vitem); // add the new MCPMDCreativeCommons to the collection class of this // object. $relObj->MCPMDCreativeCommons()->add($item); } } } if ($relation == 'CIOnlineResources') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDContact object $item = new CIOnlineResource(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->CIOnlineResources()->add($item); } } } if ($relation == 'MDHierarchyLevel') { if (is_array($v)) { foreach ($v as $vitem) { $codes = MDCodeTypes::get_scope_codes(); if (isset($codes[$vitem['Value']])) { $item = new MDHierarchyLevel(); $item->loadData($vitem); $relObj->MDHierarchyLevel()->add($item); } } } } if ($relation == 'MDHierarchyLevelName') { if (is_array($v)) { foreach ($v as $vitem) { $item = new MDHierarchyLevelName(); $item->loadData($vitem); $relObj->MDHierarchyLevelName()->add($item); } } } } } } }
/** * Test HTML messages */ public function testSendHTML() { $mailer = new MailerTest_MockMailer(); // Test with default encoding $testMessageHTML = "<p>The majority of the <i>answers</i> so far are saying that private methods are " . "implementation details which don't (<a href=\"http://www.google.com\">or at least shouldn't</a>) " . "matter so long as the public interface is well-tested & working</p> " . "<p>That's absolutely correct if your only purpose for testing is to guarantee that the " . "public interface works.</p>"; $testMessagePlain = Convert::xml2raw($testMessageHTML); $this->assertTrue(stripos($testMessagePlain, '&#') === false); list($to, $subjectEncoded, $fullBody, $headersEncoded, $bounceAddress) = $mailer->sendHTML('<*****@*****.**>', 'tom@jones <*****@*****.**>', "What is the <purpose> of testing?", $testMessageHTML, null, array('CC' => '*****@*****.**', 'bcc' => '*****@*****.**')); $this->assertEquals('*****@*****.**', $to); $this->assertEquals('=?UTF-8?B?V2hhdCBpcyB0aGUgPHB1cnBvc2U+IG9mIHRlc3Rpbmc/?=', $subjectEncoded); $this->assertEquals('=?UTF-8?B?' . base64_encode('What is the <purpose> of testing?') . '?=', $subjectEncoded); $this->assertEquals(Convert::nl2os(<<<PHP This is a multi-part message in MIME format. ------=_NextPart_000000000000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable The majority of the answers so far are saying that private methods are impl= ementation details which don't (or at least shouldn't[http://www.google.com= ]) matter so long as the public interface is well-tested & working=0A=0A=0A= =0AThat's absolutely correct if your only purpose for testing is to guarant= ee that the public interface works. ------=_NextPart_000000000000 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">=0A<HTML><HEA= D>=0A<META http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-= 8">=0A<STYLE type=3D"text/css"></STYLE>=0A=0A</HEAD>=0A<BODY bgColor=3D"#ff= ffff">=0A<p>The majority of the <i>answers</i> so far are saying that priva= te methods are implementation details which don't (<a href=3D"http://ww= w.google.com">or at least shouldn't</a>) matter so long as the public i= nterface is well-tested & working</p> <p>That's absolutely correct = if your only purpose for testing is to guarantee that the public interface = works.</p>=0A</BODY>=0A</HTML> ------=_NextPart_000000000000-- PHP ), Convert::nl2os($this->normaliseDivisions($fullBody))); // Check that the messages exist in the output $this->assertTrue(stripos($fullBody, quoted_printable_encode($testMessagePlain)) !== false); $this->assertEquals(<<<PHP MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000000000000" Content-Transfer-Encoding: 7bit From: tomjones <*****@*****.**> X-Mailer: SilverStripe Mailer - version 2006.06.21 X-Priority: 3 Bcc: andrew@thing.com Cc: admin@silverstripe.com PHP , Convert::nl2os($this->normaliseDivisions($headersEncoded))); $this->assertEquals('*****@*****.**', $bounceAddress); // Test override bounce email and alternate encoding $mailer->setBounceEmail('*****@*****.**'); $mailer->setMessageEncoding('base64'); list($to, $subjectEncoded, $fullBody, $headersEncoded, $bounceAddress) = $mailer->sendHTML('<*****@*****.**>', 'tom@jones <*****@*****.**>', "What is the <purpose> of testing?", $testMessageHTML, null, array('CC' => '*****@*****.**', 'bcc' => '*****@*****.**')); $this->assertEquals('*****@*****.**', $bounceAddress); $this->assertEquals(<<<PHP This is a multi-part message in MIME format. ------=_NextPart_000000000000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 VGhlIG1ham9yaXR5IG9mIHRoZSBhbnN3ZXJzIHNvIGZhciBhcmUgc2F5aW5n IHRoYXQgcHJpdmF0ZSBtZXRob2RzIGFyZSBpbXBsZW1lbnRhdGlvbiBkZXRh aWxzIHdoaWNoIGRvbid0IChvciBhdCBsZWFzdCBzaG91bGRuJ3RbaHR0cDov L3d3dy5nb29nbGUuY29tXSkgbWF0dGVyIHNvIGxvbmcgYXMgdGhlIHB1Ymxp YyBpbnRlcmZhY2UgaXMgd2VsbC10ZXN0ZWQgJiB3b3JraW5nCgoKClRoYXQn cyBhYnNvbHV0ZWx5IGNvcnJlY3QgaWYgeW91ciBvbmx5IHB1cnBvc2UgZm9y IHRlc3RpbmcgaXMgdG8gZ3VhcmFudGVlIHRoYXQgdGhlIHB1YmxpYyBpbnRl cmZhY2Ugd29ya3Mu ------=_NextPart_000000000000 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: base64 PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBU cmFuc2l0aW9uYWwvL0VOIj4KPEhUTUw+PEhFQUQ+CjxNRVRBIGh0dHAtZXF1 aXY9IkNvbnRlbnQtVHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0 PXV0Zi04Ij4KPFNUWUxFIHR5cGU9InRleHQvY3NzIj48L1NUWUxFPgoKPC9I RUFEPgo8Qk9EWSBiZ0NvbG9yPSIjZmZmZmZmIj4KPHA+VGhlIG1ham9yaXR5 IG9mIHRoZSA8aT5hbnN3ZXJzPC9pPiBzbyBmYXIgYXJlIHNheWluZyB0aGF0 IHByaXZhdGUgbWV0aG9kcyBhcmUgaW1wbGVtZW50YXRpb24gZGV0YWlscyB3 aGljaCBkb24mIzM5O3QgKDxhIGhyZWY9Imh0dHA6Ly93d3cuZ29vZ2xlLmNv bSI+b3IgYXQgbGVhc3Qgc2hvdWxkbiYjMzk7dDwvYT4pIG1hdHRlciBzbyBs b25nIGFzIHRoZSBwdWJsaWMgaW50ZXJmYWNlIGlzIHdlbGwtdGVzdGVkICZh bXA7IHdvcmtpbmc8L3A+IDxwPlRoYXQmIzM5O3MgYWJzb2x1dGVseSBjb3Jy ZWN0IGlmIHlvdXIgb25seSBwdXJwb3NlIGZvciB0ZXN0aW5nIGlzIHRvIGd1 YXJhbnRlZSB0aGF0IHRoZSBwdWJsaWMgaW50ZXJmYWNlIHdvcmtzLjwvcD4K PC9CT0RZPgo8L0hUTUw+ ------=_NextPart_000000000000-- PHP , Convert::nl2os($this->normaliseDivisions($fullBody))); // Check that the text message version is somewhere in there $this->assertTrue(stripos($fullBody, chunk_split(base64_encode($testMessagePlain), 60)) !== false); }
/** * Get plain-text version. * * Note: unlike DBHTMLText, this doesn't respect line breaks / paragraphs * * @return string */ public function Plain() { // Strip out HTML $text = strip_tags($this->RAW()); // Convert back to plain text return trim(\Convert::xml2raw($text)); }
/** * * Custom getChildrenAsUL - specific for Pages/Tabsets/Tabs/Fields * TODO this is very slow - improve it! * TODO could load branches via AJAX instead */ public static function getChildrenAsUL($fields, $level = 0, $ulExtraAttributes = null, $parentPage, &$itemCount = 0) { $output = ""; $hasNextLevel = false; //Set to true to remove any node from being displayed. Its children still will be. $removeNode = false; //Remove Root, as its not really needed and confuses this tree if (is_a($fields, "FieldSet") && is_a($fields->First(), "TabSet")) { $firstField = $fields->First(); $firstField = method_exists($firstField, "Name") ? $firstField->Name() : ""; if ($firstField == "Root") { $removeNode = true; } } if (!$removeNode) { $output = "<ul {$ulExtraAttributes}>\n"; } $ulExtraAttributes = null; foreach ($fields as $field) { $css = ''; $display = ''; $recurse = false; $name = ''; $type = ''; //Handle Page classes and children (getCMSFields) if (is_a($field, "Page")) { $css .= "tree-page "; $recurse = true; $name = $field->class; $display = $field->class; $parentPage = $field->class; $children = $field->getCMSFields(null); } else { //Handle TabSet classes and children (Tabs) if (is_a($field, "TabSet")) { $css .= "tree-tabset "; $recurse = true; $display = method_exists($field, "Name") ? $field->Name() : $field->class; $name = $display; $children = $field->Tabs(); } else { //Handle Tab classes and children (Fields) if (is_a($field, "Tab")) { $css .= "tree-tab "; $recurse = true; $display = method_exists($field, "Name") ? $field->Name() : $field->class; $name = $display; $children = $field->Fields(); } else { //Handle all FormField subclasses - excluding LiteralField //If the class doesn't have a Title, display the class instead //If the class has a Name, display that in brackets afterwards (maybe, comm for now) if (is_subclass_of($field, "FormField") and !is_a($field, "LiteralField")) { $title = method_exists($field, "Title") ? $field->Title() : $field->class; $name = method_exists($field, "Name") ? $field->Name() : $field->class; if (!$title) { $title = $field->class; } $css .= "tree-field "; $display = $title . "(" . $field->class . ")"; } else { //Handle LiteralField classes - the content is HTML, so convert to raw first if (is_a($field, "LiteralField")) { $css .= "tree-literal "; $name = method_exists($field, "Name") ? $field->Name() : $field->class; $display = Convert::xml2raw($field->getContent()); } else { //If the item isn't any of the above classes, we don't know what it is... $css .= "tree-unknown "; $name = method_exists($field, "Name") ? $field->Name() : $field->class; $display = $field->class . " is an unknown type..."; } } } } } //Find out if this field has a SimplifyPermission entry for the given group if (SimplifyPermission::checkField($parentPage, $name, $field->class, self::$group)) { $css .= 'selected '; } //Build the page|field|type|group key $code = $parentPage . "|" . $name . "|" . $field->class . "|" . self::$group->ID; //Build the node if (!$removeNode) { $output .= "<li class='{$css}'><a href='#' rel='{$code}'>{$display}</a>\n"; } //Do the recursive call if ($recurse) { $output .= self::getChildrenAsUL($children, $level + 1, $ulExtraAttributes, $parentPage); } if (!$removeNode) { $output .= "</li>\n"; } $itemCount++; } if (!$removeNode) { $output .= "</ul>\n"; } return $output; }
/** * Generate the plainPart of a html message * * @param string $plainContent Plain body * @param string $htmlContent HTML message * @return string Encoded headers / message in a single block */ protected function preparePlainSubmessage($plainContent, $htmlContent) { $plainEncoding = $this->getMessageEncoding(); // Generate plain text version if not explicitly given if (!$plainContent) { $plainContent = Convert::xml2raw($htmlContent); } // Make the plain text part $headers["Content-Type"] = "text/plain; charset=utf-8"; $headers["Content-Transfer-Encoding"] = $plainEncoding; $plainContentEncoded = $this->encodeMessage($plainContent, $plainEncoding); // Merge with headers return $this->processHeaders($headers, $plainContentEncoded); }
/** * Helper function to get page count */ function getpagecount() { if (!Permission::check('ADMIN')) { return Security::permissionFailure($this); } increase_time_limit_to(); increase_memory_limit_to(); $excludePages = split(" *, *", $_GET['exclude']); $pages = DataObject::get("SiteTree", "\"ParentID\" = 0"); foreach ($pages as $page) { $pageArr[] = $page; } while (list($i, $page) = each($pageArr)) { if (!in_array($page->URLSegment, $excludePages)) { if ($children = $page->AllChildren()) { foreach ($children as $child) { $pageArr[] = $child; } } if (!$_GET['onlywithcontent'] || strlen(Convert::xml2raw($page->Content)) > 100) { echo "<li>" . $page->Breadcrumbs(null, true) . "</li>"; $count++; } else { echo "<li style=\"color: #777\">" . $page->Breadcrumbs(null, true) . " - " . _t('CMSMain.NOCONTENT', "no content") . "</li>"; } } } echo '<p>' . _t('CMSMain.TOTALPAGES', "Total pages: ") . "{$count}</p>"; }
public function Title() { $title = parent::Title(); // Remove this method override in 4.0 $decoded = Convert::xml2raw($title); if ($decoded !== $title) { Deprecation::notice('4.0', 'The FormAction title field should not be html encoded. Use buttonContent to set custom html instead'); return $decoded; } return $title; }
/** * Limit this field's content by a number of words. * * CAUTION: This is not XML safe. Please use * {@link LimitWordCountXML()} instead. * * @param int $numWords Number of words to limit by. * @param string $add Ellipsis to add to the end of truncated string. * * @return string */ public function LimitWordCount($numWords = 26, $add = '...') { $this->value = trim(Convert::xml2raw($this->value)); $ret = explode(' ', $this->value, $numWords + 1); if (count($ret) <= $numWords - 1) { $ret = $this->value; } else { array_pop($ret); $ret = implode(' ', $ret) . $add; } return $ret; }
/** * Caution: Not XML/HTML-safe - does not respect closing tags. */ public function FirstSentence() { $strParsedText = $this->ParseMarkDown(); $paragraph = Convert::xml2raw($strParsedText); if (!$paragraph) { return ""; } $words = preg_split('/\\s+/', $paragraph); foreach ($words as $i => $word) { if (preg_match('/(!|\\?|\\.)$/', $word) && !preg_match('/(Dr|Mr|Mrs|Ms|Miss|Sr|Jr|No)\\.$/i', $word)) { return implode(' ', array_slice($words, 0, $i + 1)); } } /* If we didn't find a sentence ending, use the summary. We re-call rather than using paragraph so that * Summary will limit the result this time */ return $this->Summary(20); }
/** * Caution: Not XML/HTML-safe - does not respect closing tags. */ function FirstParagraph($plain = 1) { // get first sentence? // this needs to be more robust if ($plain && $plain != 'html') { $data = Convert::xml2raw($this->value, true); if (!$data) { return ""; } // grab the first paragraph, or, failing that, the whole content if (strpos($data, "\n\n")) { $data = substr($data, 0, strpos($data, "\n\n")); } return $data; } else { if (strpos($this->value, "</p>") === false) { return $this->value; } $data = substr($this->value, 0, strpos($this->value, "</p>") + 4); if (strlen($data) < 20 && strpos($this->value, "</p>", strlen($data))) { $data = substr($this->value, 0, strpos($this->value, "</p>", strlen($data)) + 4); } return $data; } }
public function wordCount() { $content = trim(Convert::xml2raw($this->owner->Content)); $noWords = count(explode(' ', $content)); return $noWords; }
static function RAW_setGetVar($varname, $varvalue, $currentURL = null) { $url = self::setGetVar($varname, $varvalue, $currentURL); return Convert::xml2raw($url); }
/** * Return the value of the field without any escaping being applied. */ public function RAW_val($field, $arguments = null, $cache = true) { return Convert::xml2raw($this->XML_val($field, $arguments, $cache)); }
function plaintextEmail($to, $from, $subject, $plainContent, $attachedFiles, $customheaders = false) { // Not ensurely where this is supposed to be set, but defined it false for now to remove php notices $plainEncoding = false; if ($customheaders && is_array($customheaders) == false) { echo "htmlEmail({$to}, {$from}, {$subject}, ...) could not send mail: improper \$customheaders passed:<BR>"; dieprintr($customheaders); } // If the subject line contains extended characters, we must encode it $subject = Convert::xml2raw($subject); $subject = "=?UTF-8?B?" . base64_encode($subject) . "?="; // Make the plain text part $headers["Content-Type"] = "text/plain; charset=utf-8"; $headers["Content-Transfer-Encoding"] = $plainEncoding ? $plainEncoding : "quoted-printable"; $plainContent = $plainEncoding == "base64" ? chunk_split(base64_encode($plainContent), 60) : QuotedPrintable_encode($plainContent); // Messages with attachments are handled differently if ($attachedFiles) { // The first part is the message itself $fullMessage = processHeaders($headers, $plainContent); $messageParts = array($fullMessage); // Include any specified attachments as additional parts foreach ($attachedFiles as $file) { if (isset($file['tmp_name']) && isset($file['name'])) { $messageParts[] = encodeFileForEmail($file['tmp_name'], $file['name']); } else { $messageParts[] = encodeFileForEmail($file); } } // We further wrap all of this into another multipart block list($fullBody, $headers) = encodeMultipart($messageParts, "multipart/mixed"); // Messages without attachments do not require such treatment } else { $fullBody = $plainContent; } // Email headers $headers["From"] = validEmailAddr($from); // Messages with the X-SilverStripeMessageID header can be tracked if (isset($customheaders["X-SilverStripeMessageID"]) && defined('BOUNCE_EMAIL')) { $bounceAddress = BOUNCE_EMAIL; // Get the human name from the from address, if there is one if (preg_match('/^([^<>]+)<([^<>])> *$/', $from, $parts)) { $bounceAddress = "{$parts['1']}<{$bounceAddress}>"; } } else { $bounceAddress = $from; } // $headers["Sender"] = $from; $headers["X-Mailer"] = X_MAILER; if (!isset($customheaders["X-Priority"])) { $headers["X-Priority"] = 3; } $headers = array_merge((array) $headers, (array) $customheaders); // the carbon copy header has to be 'Cc', not 'CC' or 'cc' -- ensure this. if (isset($headers['CC'])) { $headers['Cc'] = $headers['CC']; unset($headers['CC']); } if (isset($headers['cc'])) { $headers['Cc'] = $headers['cc']; unset($headers['cc']); } // Send the email $headers = processHeaders($headers); $to = validEmailAddr($to); // Try it without the -f option if it fails if (!($result = @mail($to, $subject, $fullBody, $headers, "-f{$bounceAddress}"))) { $result = mail($to, $subject, $fullBody, $headers); } if ($result) { return array($to, $subject, $fullBody, $headers); } return false; }
/** * Tests if the text is longer than $numWords. * * @param int $numWords * @return bool */ public function MoreWordsThan($numWords = 23) { $value = trim(Convert::xml2raw($this->owner->value)); return count(explode(' ', $value)) > $numWords; }