本文整理汇总了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]'));
}
示例2: forTemplate
public function forTemplate()
{
if ($this->processShortcodes) {
return ShortcodeParser::get_active()->parse($this->value);
} else {
return $this->value;
}
}
示例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;
}
示例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);
}
}
示例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'));
}
示例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;
}
示例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';
});
}
示例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 '';
}
示例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;
}
示例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;
}
示例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]">'));
}
示例12: array
<?php
ShortcodeParser::get('default')->register('rdfa', array('RDFaExtension', 'RDFaShortcode'));
示例13: tearDown
public function tearDown()
{
ShortcodeParser::get_active()->unregister('test_shortcode');
parent::tearDown();
}
示例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();
}
}
示例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');