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


PHP ShortcodeParser类代码示例

本文整理汇总了PHP中ShortcodeParser的典型用法代码示例。如果您正苦于以下问题:PHP ShortcodeParser类的具体用法?PHP ShortcodeParser怎么用?PHP ShortcodeParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ShortcodeParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testLinkShortcodeHandler

	public function testLinkShortcodeHandler() {
		$testFile = $this->objFromFixture('File', 'asdf');
		$errorPage = $this->objFromFixture('ErrorPage', '404');

		$parser = new ShortcodeParser();
		$parser->register('file_link', array('File', 'link_shortcode_handler'));

		$fileShortcode = sprintf('[file_link id=%d]', $testFile->ID);
		$fileEnclosed  = sprintf('[file_link id=%d]Example Content[/file_link]', $testFile->ID);

		$fileShortcodeExpected = $testFile->Link();
		$fileEnclosedExpected  = sprintf('<a href="%s" class="file" data-type="txt" data-size="977 KB">Example Content</a>', $testFile->Link());

		$this->assertEquals($fileShortcodeExpected, $parser->parse($fileShortcode), 'Test that simple linking works.');
		$this->assertEquals($fileEnclosedExpected, $parser->parse($fileEnclosed), 'Test enclosed content is linked.');

		$testFile->delete();

		$fileShortcode = '[file_link id="-1"]';
		$fileEnclosed  = '[file_link id="-1"]Example Content[/file_link]';

		$fileShortcodeExpected = $errorPage->Link();
		$fileEnclosedExpected  = sprintf('<a href="%s">Example Content</a>', $errorPage->Link());

		$this->assertEquals($fileShortcodeExpected, $parser->parse($fileShortcode), 'Test link to 404 page if no suitable matches.');
		$this->assertEquals($fileEnclosedExpected, $parser->parse($fileEnclosed));

		$this->assertEquals('', $parser->parse('[file_link]'), 'Test that invalid ID attributes are not parsed.');
		$this->assertEquals('', $parser->parse('[file_link id="text"]'));
		$this->assertEquals('', $parser->parse('[file_link]Example Content[/file_link]'));
	}
开发者ID:redema,项目名称:sapphire,代码行数:31,代码来源:FileTest.php

示例2: forTemplate

 public function forTemplate()
 {
     if ($this->processShortcodes) {
         return ShortcodeParser::get_active()->parse($this->value);
     } else {
         return $this->value;
     }
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:8,代码来源:HTMLVarchar.php

示例3: parse

 public function parse()
 {
     $parsedown = new RestrictedMarkdownParser();
     $html = $parsedown->parse(ShortcodeParser::get_active()->parse($this->content));
     $config = HTMLPurifier_Config::createDefault();
     $purifier = new HTMLPurifier($config);
     $html = $purifier->purify($html);
     return $html;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-microblog,代码行数:9,代码来源:RestrictedMarkdown.php

示例4: register_class

 public static function register_class($class)
 {
     if (class_exists($class)) {
         if (!singleton($class)->hasMethod('parse_shortcode')) {
             user_error("Failed to register \"{$class}\" with shortcodable. {$class} must have the method parse_shortcode(). See /shortcodable/README.md", E_USER_ERROR);
         }
         ShortcodeParser::get('default')->register($class, array(singleton($class), 'parse_shortcode'));
         singleton('ShortcodableParser')->register($class);
     }
 }
开发者ID:jelicanin,项目名称:silverstripe-shortcodable,代码行数:10,代码来源:Shortcodable.php

示例5: testShortcodeOperation

 public function testShortcodeOperation()
 {
     $file = 'dms/tests/DMS-test-lorum-file.pdf';
     $document = DMS::inst()->storeDocument($file);
     $result = ShortcodeParser::get('default')->parse(sprintf('<p><a href="[dms_document_link id=\'%d\']">Document</a></p>', $document->ID));
     $value = Injector::inst()->create('HTMLValue', $result);
     $link = $value->query('//a')->item(0);
     $this->assertStringEndsWith("/dmsdocument/{$document->ID}", $link->getAttribute('href'));
     $this->assertEquals($document->getExtension(), $link->getAttribute('data-ext'));
     $this->assertEquals($document->getFileSizeFormatted(), $link->getAttribute('data-size'));
 }
开发者ID:helpfulrobot,项目名称:silverstripe-dms,代码行数:11,代码来源:DMSShortcodeTest.php

示例6: preview

 function preview(SS_HTTPRequest $request)
 {
     $strValue = $request->requestVar('markdown');
     if ($strValue) {
         $shortCodeParser = ShortcodeParser::get_active();
         $strValue = $shortCodeParser->parse($strValue);
         $parseDown = new Parsedown();
         $strValue = $parseDown->text($strValue);
     }
     return $strValue;
 }
开发者ID:helpfulrobot,项目名称:silverstripers-silverstripe-markdown,代码行数:11,代码来源:MarkdownEditorField.php

示例7: setUp

 public function setUp()
 {
     parent::setUp();
     Config::inst()->update('Director', 'alternate_base_url', '/');
     if (!self::$original_host) {
         self::$original_host = $_SERVER['HTTP_HOST'];
     }
     $_SERVER['HTTP_HOST'] = 'www.example.org';
     ShortcodeParser::get('default')->register('test_shortcode', function () {
         return 'test shortcode output';
     });
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:12,代码来源:RSSFeedTest.php

示例8: handle

 public static function handle($arguments, $content, ShortcodeParser $parser, $tag, array $extra = array())
 {
     if (!empty($arguments['id'])) {
         $document = DMSDocument::get()->byID($arguments['id']);
         if ($document && !$document->isHidden()) {
             if ($content) {
                 return sprintf('<a href="%s">%s</a>', $document->Link(), $parser->parse($content));
             } else {
                 if (isset($extra['element'])) {
                     $extra['element']->setAttribute('data-ext', $document->getExtension());
                     $extra['element']->setAttribute('data-size', $document->getFileSizeFormatted());
                 }
                 return $document->Link();
             }
         }
     }
     $error = ErrorPage::get()->filter('ErrorCode', '404')->First();
     if ($error) {
         return $error->Link();
     }
     return '';
 }
开发者ID:helpfulrobot,项目名称:silverstripe-dms,代码行数:22,代码来源:DMSShortcodeHandler.php

示例9: ParseMarkdown

 /**
  * @return string
  * parse contents of the markdown field to tempates
  */
 function ParseMarkdown($bCache = true, $strValue = '')
 {
     if ($bCache && $this->parsedContent) {
         return $this->parsedContent;
     }
     $shortCodeParser = ShortcodeParser::get_active();
     $strParsed = $shortCodeParser->parse(!empty($strValue) ? $strValue : $this->value);
     $parseDown = new Parsedown();
     $strParsed = $parseDown->text($strParsed);
     if ($bCache) {
         $this->parsedContent = $strParsed;
     }
     return $strParsed;
 }
开发者ID:helpfulrobot,项目名称:silverstripers-silverstripe-markdown,代码行数:18,代码来源:MarkdownField.php

示例10: ParseMarkDown

 function ParseMarkDown()
 {
     $parser = new Parsedown();
     $value = $this->value;
     $this->extend('onBeforeParseMarkDown', $value);
     $value = $parser->text($value);
     set_error_handler(array($this, 'onError'));
     try {
         $value = ShortcodeParser::get_active()->parse($value);
     } catch (Exception $e) {
     }
     restore_error_handler();
     $this->extend('onAfterParseMarkDown', $value);
     return $value;
 }
开发者ID:helpfulrobot,项目名称:undefinedoffset-silverstripe-markdown,代码行数:15,代码来源:MarkdownText.php

示例11: testNotRegisteredShortcode

 /**
  * Tests that valid short codes that have not been registered are not replaced.
  */
 public function testNotRegisteredShortcode()
 {
     ShortcodeParser::$error_behavior = ShortcodeParser::STRIP;
     $this->assertEquals('', $this->parser->parse('[not_shortcode]'));
     $this->assertEquals('<img class="">', $this->parser->parse('<img class="[not_shortcode]">'));
     ShortcodeParser::$error_behavior = ShortcodeParser::WARN;
     $this->assertEquals('<strong class="warning">[not_shortcode]</strong>', $this->parser->parse('[not_shortcode]'));
     ShortcodeParser::$error_behavior = ShortcodeParser::LEAVE;
     $this->assertEquals('[not_shortcode]', $this->parser->parse('[not_shortcode]'));
     $this->assertEquals('[not_shortcode /]', $this->parser->parse('[not_shortcode /]'));
     $this->assertEquals('[not_shortcode,foo="bar"]', $this->parser->parse('[not_shortcode,foo="bar"]'));
     $this->assertEquals('[not_shortcode]a[/not_shortcode]', $this->parser->parse('[not_shortcode]a[/not_shortcode]'));
     $this->assertEquals('[/not_shortcode]', $this->parser->parse('[/not_shortcode]'));
     $this->assertEquals('<img class="[not_shortcode]">', $this->parser->parse('<img class="[not_shortcode]">'));
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:18,代码来源:ShortcodeParserTest.php

示例12: array

<?php

ShortcodeParser::get('default')->register('rdfa', array('RDFaExtension', 'RDFaShortcode'));
开发者ID:opendatanz,项目名称:silverstripe-rdfa,代码行数:3,代码来源:_config.php

示例13: tearDown

 public function tearDown()
 {
     ShortcodeParser::get_active()->unregister('test_shortcode');
     parent::tearDown();
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:5,代码来源:XMLDataFormatterTest.php

示例14: handle_shortcode

 /**
  * Replace"[file_link id=n]" shortcode with an anchor tag or link to the file.
  * 
  * @param array $arguments Arguments passed to the parser
  * @param string $content Raw shortcode
  * @param ShortcodeParser $parser Parser
  * @param string $shortcode Name of shortcode used to register this handler
  * @param array $extra Extra arguments
  * @return string Result of the handled shortcode
  */
 public static function handle_shortcode($arguments, $content, $parser, $shortcode, $extra = array())
 {
     if (!isset($arguments['id']) || !is_numeric($arguments['id'])) {
         return;
     }
     $record = DataObject::get_by_id('File', $arguments['id']);
     if (!$record) {
         if (class_exists('ErrorPage')) {
             $record = ErrorPage::get()->filter("ErrorCode", 404)->first();
         }
         if (!$record) {
             return;
             // There were no suitable matches at all.
         }
     }
     // build the HTML tag
     if ($content) {
         // build some useful meta-data (file type and size) as data attributes
         $attrs = ' ';
         if ($record instanceof File) {
             foreach (array('class' => 'file', 'data-type' => $record->getExtension(), 'data-size' => $record->getSize()) as $name => $value) {
                 $attrs .= sprintf('%s="%s" ', $name, $value);
             }
         }
         return sprintf('<a href="%s"%s>%s</a>', $record->Link(), rtrim($attrs), $parser->parse($content));
     } else {
         return $record->Link();
     }
 }
开发者ID:biggtfish,项目名称:silverstripe-framework,代码行数:39,代码来源:File.php

示例15: array

<?php

global $project;
$project = 'mysite';
ShortcodeParser::get('default')->register('my_button', array('Page', 'MyButton'));
global $database;
$database = 'membertest';
require_once 'conf/ConfigureFromEnv.php';
// Set the site locale
i18n::set_locale('en_US');
开发者ID:Codesesh,项目名称:silverstripe-shortcode-example,代码行数:10,代码来源:_config.php


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