本文整理匯總了PHP中Convert::html2raw方法的典型用法代碼示例。如果您正苦於以下問題:PHP Convert::html2raw方法的具體用法?PHP Convert::html2raw怎麽用?PHP Convert::html2raw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Convert
的用法示例。
在下文中一共展示了Convert::html2raw方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: Field
public function Field($properties = array())
{
$content = '';
Requirements::javascript(FRAMEWORK_DIR . '/thirdparty/jquery/jquery.js');
Requirements::javascript(FRAMEWORK_DIR . "/javascript/ToggleField.js");
if ($this->startClosed) {
$this->addExtraClass('startClosed');
}
$valforInput = $this->value ? Convert::raw2att($this->value) : "";
$rawInput = Convert::html2raw($valforInput);
if ($this->charNum) {
$reducedVal = substr($rawInput, 0, $this->charNum);
} else {
$reducedVal = DBField::create_field('Text', $rawInput)->{$this->truncateMethod}();
}
// only create togglefield if the truncated content is shorter
if (strlen($reducedVal) < strlen($rawInput)) {
$content = <<<HTML
\t\t\t<div class="readonly typography contentLess" style="display: none">
\t\t\t\t{$reducedVal}
\t\t\t\t <a href="#" class="triggerMore">{$this->labelMore}</a>
\t\t\t</div>
\t\t\t<div class="readonly typography contentMore">
\t\t\t\t{$this->value}
\t\t\t\t <a href="#" class="triggerLess">{$this->labelLess}</a>
\t\t\t</div>\t
\t\t\t<br />
\t\t\t<input type="hidden" name="{$this->name}" value="{$valforInput}" />
HTML;
} else {
$this->dontEscape = true;
$content = parent::Field();
}
return $content;
}
示例2: testHtml2raw
/**
* Tests {@link Convert::html2raw()}
*/
public function testHtml2raw()
{
$val1 = 'This has a <strong>strong tag</strong>.';
$this->assertEquals('This has a *strong tag*.', Convert::html2raw($val1), 'Strong tags are replaced with asterisks');
$val1 = 'This has a <b class="test" style="font-weight: bold">b tag with attributes</b>.';
$this->assertEquals('This has a *b tag with attributes*.', Convert::html2raw($val1), 'B tags with attributes are replaced with asterisks');
$val2 = 'This has a <strong class="test" style="font-weight: bold">strong tag with attributes</STRONG>.';
$this->assertEquals('This has a *strong tag with attributes*.', Convert::html2raw($val2), 'Strong tags with attributes are replaced with asterisks');
$val3 = '<script type="application/javascript">Some really nasty javascript here</script>';
$this->assertEquals('', Convert::html2raw($val3), 'Script tags are completely removed');
$val4 = '<style type="text/css">Some really nasty CSS here</style>';
$this->assertEquals('', Convert::html2raw($val4), 'Style tags are completely removed');
$val5 = '<script type="application/javascript">Some really nasty
multiline javascript here</script>';
$this->assertEquals('', Convert::html2raw($val5), 'Multiline script tags are completely removed');
$val6 = '<style type="text/css">Some really nasty
multiline CSS here</style>';
$this->assertEquals('', Convert::html2raw($val6), 'Multiline style tags are completely removed');
$val7 = '<p>That's absolutely correct</p>';
$this->assertEquals("That's absolutely correct", Convert::html2raw($val7), "Single quotes are decoded correctly");
$val8 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor ' . 'incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud ' . 'exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute ' . 'irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla ' . 'pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia ' . 'deserunt mollit anim id est laborum.';
$this->assertEquals($val8, Convert::html2raw($val8), 'Test long text is unwrapped');
$this->assertEquals(<<<PHP
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation
ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.
PHP
, Convert::html2raw($val8, false, 60), 'Test long text is wrapped');
}
示例3: extractMapAndSelectors
/**
* Extract content for map of field => css-selector pairs
*
* @param array $selectorMap A map of field name => css-selector
* @return array A map of field name => array('selector' => selector, 'content' => field content)
*/
public function extractMapAndSelectors($selectorMap)
{
if (!$this->phpQuery) {
$this->fetchContent();
}
$output = array();
foreach ($selectorMap as $fieldName => $extractionRules) {
if (!is_array($extractionRules)) {
$extractionRules = array($extractionRules);
}
foreach ($extractionRules as $extractionRule) {
if (!is_array($extractionRule)) {
$extractionRule = array('selector' => $extractionRule);
}
$content = $this->extractField($extractionRule['selector'], $extractionRule['attribute'], $extractionRule['outerhtml']);
if (!$content) {
continue;
}
$content = $this->excludeContent($extractionRule['excludeselectors'], $extractionRule['selector'], $content);
if (!$content) {
continue;
}
if (!empty($extractionRule['plaintext'])) {
$content = Convert::html2raw($content);
}
// We found a match, select that one and ignore any other selectors
$output[$fieldName] = $extractionRule;
$output[$fieldName]['content'] = $content;
$this->log("Value set for {$fieldName}");
break;
}
}
return $output;
}
開發者ID:helpfulrobot,項目名稱:silverstripe-staticsiteconnector,代碼行數:40,代碼來源:StaticSiteContentExtractor.php
示例4: getHeading
/**
* Get list heading
*/
public function getHeading()
{
$list = $this->getList();
if (isset($list->heading) && $list->heading) {
return Convert::html2raw($list->heading);
}
return null;
}
開發者ID:helpfulrobot,項目名稱:silverbusters-silverstripe-simplelistfield,代碼行數:11,代碼來源:SimpleListFieldDB.php
示例5: ToSocialMedia
public function ToSocialMedia()
{
$this->plaintext = trim(Convert::html2raw($this->owner->Content, false, 9999));
if (empty($this->plaintext)) {
return;
}
if (empty($this->owner->TwitterID)) {
$this->ToTwitter();
}
//if (empty($this->owner->LinkedInID)) $this->ToLinkedIn();
}
示例6: sendHTML
function sendHTML($to, $from, $subject, $htmlContent, $attachedFiles = false, $customheaders = false, $plainContent = false, $inlineImages = false)
{
$this->instanciate();
$this->mailer->IsHTML(true);
if ($inlineImages) {
$this->mailer->MsgHTML($htmlContent, Director::baseFolder());
} else {
$this->mailer->Body = $htmlContent;
if (empty($plainContent)) {
$plainContent = trim(Convert::html2raw($htmlContent));
}
$this->mailer->AltBody = $plainContent;
}
$this->sendMailViaSmtp($to, $from, $subject, $attachedFiles, $customheaders, $inlineImages);
}
示例7: getTasks
/**
* @return array Array of associative arrays for each task (Keys: 'class', 'title', 'description')
*/
protected function getTasks()
{
$availableTasks = array();
$taskClasses = ClassInfo::subclassesFor('BuildTask');
// remove the base class
array_shift($taskClasses);
if ($taskClasses) {
foreach ($taskClasses as $class) {
if (!$this->taskEnabled($class)) {
continue;
}
$desc = Director::is_cli() ? Convert::html2raw(singleton($class)->getDescription()) : singleton($class)->getDescription();
$availableTasks[] = array('class' => $class, 'title' => singleton($class)->getTitle(), 'segment' => str_replace('\\', '-', $class), 'description' => $desc);
}
}
return $availableTasks;
}
示例8: getTasks
/**
* @return array Array of associative arrays for each task (Keys: 'class', 'title', 'description')
*/
protected function getTasks() {
$availableTasks = array();
$taskClasses = ClassInfo::subclassesFor('BuildTask');
// remove the base class
array_shift($taskClasses);
if($taskClasses) foreach($taskClasses as $class) {
if(!singleton($class)->isEnabled()) continue;
$desc = (Director::is_cli()) ? Convert::html2raw(singleton($class)->getDescription()) : singleton($class)->getDescription();
$availableTasks[] = array(
'class' => $class,
'title' => singleton($class)->getTitle(),
'description' => $desc,
);
}
return $availableTasks;
}
示例9: XHTML_val
public function XHTML_val($field, $arguments = null, $cache = false)
{
$html = $this->XML_val($field, $arguments, $cache);
$doc = new DOMDocument('1.0');
$doc->strictErrorChecking = false;
$doc->formatOutput = false;
try {
// Prefix with an XML heading to force UTF-8 encoding,
// otherwise Latin1 would be assumed (what a stupid assumption).
$doc->loadHTML('<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body>' . $html . '</body>');
$children = @$doc->getElementsByTagName('body')->item(0)->childNodes;
if ($children instanceof Traversable) {
$xml = '';
foreach ($children as $child) {
$xml .= $doc->saveXML($child);
}
return $xml;
}
} catch (Exception $e) {
}
// Fallback value: try to return something useful
return Convert::html2raw($html);
}
示例10: getUFields
function getUFields()
{
return array('ProductDescription' => $this->owner->Title, 'Weight' => $this->owner->Weight, 'UnitOfMeasure' => $this->owner->Quantifier, 'DefaultSellPrice' => $this->owner->Price, 'Notes' => Convert::html2raw($this->owner->Content));
}
示例11: onBeforeWrite
/**
* Before writing the Subsite Domain, strip out any HTML the user has entered.
* @return void
*/
public function onBeforeWrite()
{
parent::onBeforeWrite();
//strip out any HTML to avoid XSS attacks
$this->Domain = Convert::html2raw($this->Domain);
}
示例12: html2raw
/**
* Simple conversion of HTML to plaintext.
*
* @param $data string
* @param $preserveLinks boolean
* @param $wordwrap array
*/
public static function html2raw($data, $preserveLinks = false, $wordWrap = 60, $config = null)
{
$defaultConfig = array('PreserveLinks' => false, 'ReplaceBoldAsterisk' => true, 'CompressWhitespace' => true, 'ReplaceImagesWithAlt' => true);
if (isset($config)) {
$config = array_merge($defaultConfig, $config);
} else {
$config = $defaultConfig;
}
$data = preg_replace("/<style([^A-Za-z0-9>][^>]*)?>.*?<\\/style[^>]*>/is", "", $data);
$data = preg_replace("/<script([^A-Za-z0-9>][^>]*)?>.*?<\\/script[^>]*>/is", "", $data);
if ($config['ReplaceBoldAsterisk']) {
$data = preg_replace('%<(strong|b)( [^>]*)?>|</(strong|b)>%i', '*', $data);
}
// Expand hyperlinks
if (!$preserveLinks && !$config['PreserveLinks']) {
$data = preg_replace_callback('/<a[^>]*href\\s*=\\s*"([^"]*)">(.*?)<\\/a>/i', function ($matches) {
return Convert::html2raw($matches[2]) . "[{$matches['1']}]";
}, $data);
$data = preg_replace_callback('/<a[^>]*href\\s*=\\s*([^ ]*)>(.*?)<\\/a>/i', function ($matches) {
return Convert::html2raw($matches[2]) . "[{$matches['1']}]";
}, $data);
}
// Replace images with their alt tags
if ($config['ReplaceImagesWithAlt']) {
$data = preg_replace('/<img[^>]*alt *= *"([^"]*)"[^>]*>/i', ' \\1 ', $data);
$data = preg_replace('/<img[^>]*alt *= *([^ ]*)[^>]*>/i', ' \\1 ', $data);
}
// Compress whitespace
if ($config['CompressWhitespace']) {
$data = preg_replace("/\\s+/", " ", $data);
}
// Parse newline tags
$data = preg_replace("/\\s*<[Hh][1-6]([^A-Za-z0-9>][^>]*)?> */", "\n\n", $data);
$data = preg_replace("/\\s*<[Pp]([^A-Za-z0-9>][^>]*)?> */", "\n\n", $data);
$data = preg_replace("/\\s*<[Dd][Ii][Vv]([^A-Za-z0-9>][^>]*)?> */", "\n\n", $data);
$data = preg_replace("/\n\n\n+/", "\n\n", $data);
$data = preg_replace("/<[Bb][Rr]([^A-Za-z0-9>][^>]*)?> */", "\n", $data);
$data = preg_replace("/<[Tt][Rr]([^A-Za-z0-9>][^>]*)?> */", "\n", $data);
$data = preg_replace("/<\\/[Tt][Dd]([^A-Za-z0-9>][^>]*)?> */", " ", $data);
$data = preg_replace('/<\\/p>/i', "\n\n", $data);
// Replace HTML entities
//$data = preg_replace("/&#([0-9]+);/e", 'chr(\1)', $data);
//$data = str_replace(array("<",">","&"," "), array("<", ">", "&", " "), $data);
$data = html_entity_decode($data, ENT_COMPAT, 'UTF-8');
// Remove all tags (but optionally keep links)
// strip_tags seemed to be restricting the length of the output
// arbitrarily. This essentially does the same thing.
if (!$preserveLinks && !$config['PreserveLinks']) {
$data = preg_replace('/<\\/?[^>]*>/', '', $data);
} else {
$data = strip_tags($data, '<a>');
}
return trim(wordwrap(trim($data), $wordWrap));
}
示例13: strip_html
/**
* @param $s
* @return string
*/
public static function strip_html($s)
{
return Convert::html2raw($s);
}
示例14: getTwitterDescription
public function getTwitterDescription()
{
return Convert::html2raw($this->BriefIntroduction);
}