当前位置: 首页>>代码示例>>PHP>>正文


PHP Convert::html2raw方法代码示例

本文整理汇总了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&nbsp;<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&nbsp;<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;
    }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:35,代码来源:ToggleField.php

示例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&#39;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');
    }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:37,代码来源:ConvertTest.php

示例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();
 }
开发者ID:Taitava,项目名称:silverstripe-socialmedia,代码行数:11,代码来源:SocialMediaExtension.php

示例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);
 }
开发者ID:robert-h-curry,项目名称:huttclub,代码行数:15,代码来源:SmtpMailer.php

示例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;
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:20,代码来源:TaskRunner.php

示例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;
	}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:22,代码来源:TaskRunner.php

示例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);
 }
开发者ID:helpfulrobot,项目名称:entidi-silverstripe-news,代码行数:23,代码来源:NewsPage.php

示例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));
 }
开发者ID:helpfulrobot,项目名称:sunnysideup-ecommerce-unleashed,代码行数:4,代码来源:UnleashedProductDOD.php

示例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);
 }
开发者ID:hamaka,项目名称:silverstripe-subsites,代码行数:10,代码来源:SubsiteDomain.php

示例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("&lt;","&gt;","&amp;","&nbsp;"), 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));
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:61,代码来源:Convert.php

示例13: strip_html

 /**
  * @param $s
  * @return string
  */
 public static function strip_html($s)
 {
     return Convert::html2raw($s);
 }
开发者ID:helpfulrobot,项目名称:markguinn-silverstripe-sync,代码行数:8,代码来源:SyncFilterHelper.php

示例14: getTwitterDescription

 public function getTwitterDescription()
 {
     return Convert::html2raw($this->BriefIntroduction);
 }
开发者ID:helpfulrobot,项目名称:weboftalent-page-with-image,代码行数:4,代码来源:PageWithImage.php


注:本文中的Convert::html2raw方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。