• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP ShortcodeParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: define

<?php

if (!defined('RESPONSIVE_WYSIWYG_IMAGES_DIR')) {
    define('RESPONSIVE_WYSIWYG_IMAGES_DIR', rtrim(basename(dirname(__FILE__))));
}
HtmlEditorConfig::get('cms')->enablePlugins(array('responsive_wysiwyg_images' => sprintf('../../../%s/javascript/editor_plugin.js', RESPONSIVE_WYSIWYG_IMAGES_DIR)));
ShortcodeParser::get('default')->register('responsiveimage', array('ResponisveWYSIWYGImages', 'shortcode_handler'));
开发者ID:helpfulrobot,项目名称:sheadawson-silverstripe-responsive-wysiwyg-images,代码行数:7,代码来源:_config.php


示例17: array

<?php

/**
 * Framework configuration file
 *
 * Here you can make different settings for the Framework module (the core
 * module).
 *
 * For example you can register the authentication methods you wish to use
 * on your site, e.g. to register the OpenID authentication method type
 *
 * <code>
 * Authenticator::register_authenticator('OpenIDAuthenticator');
 * </code>
 *
 * @package framework
 * @subpackage core
 */
ShortcodeParser::get('default')->register('file_link', array('File', 'handle_shortcode'))->register('embed', array('Oembed', 'handle_shortcode'));
// @todo
//	->register('dbfile_link', array('DBFile', 'handle_shortcode'))
// Zend_Cache temp directory setting
$_ENV['TMPDIR'] = TEMP_FOLDER;
// for *nix
$_ENV['TMP'] = TEMP_FOLDER;
// for Windows
SS_Cache::set_cache_lifetime('GDBackend_Manipulations', null, 100);
// If you don't want to see deprecation errors for the new APIs, change this to 3.2.0-dev.
Deprecation::notification_version('3.2.0');
// TODO Remove once new ManifestBuilder with submodule support is in place
require_once 'admin/_config.php';
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:31,代码来源:_config.php


示例18: array

$project = 'mysite';
global $databaseConfig;
$databaseConfig = array("type" => 'MySQLDatabase', "server" => 'localhost', "username" => 'root', "password" => 'omega', "database" => 'vp', "path" => '');
MySQLDatabase::set_connection_charset('utf8');
// Set the current theme. More themes can be downloaded from
// http://www.silverstripe.org/themes/
SSViewer::set_theme('simple');
// Set the site locale
i18n::set_locale('en_US');
FulltextSearchable::enable();
// Enable nested URLs for this site (e.g. page/sub-page/)
if (class_exists('SiteTree')) {
    SiteTree::enable_nested_urls();
}
Director::set_environment_type("dev");
// add a button to remove formatting
HtmlEditorConfig::get('cms')->insertButtonsBefore('styleselect', 'removeformat');
// tell the button which tags it may remove
HtmlEditorConfig::get('cms')->setOption('removeformat_selector', 'b,strong,em,i,span,ins');
//remove font->span conversion
HtmlEditorConfig::get('cms')->setOption('convert_fonts_to_spans', 'false,');
HtmlEditorConfig::get('cms')->setOptions(array('valid_elements' => "@[id|class|style|title],#a[id|rel|rev|dir|tabindex|accesskey|type|name|href|target|title|class],-strong/-b[class],-em/-i[class],-strike[class],-u[class],#p[id|dir|class|align|style],-ol[class],-ul[class],-li[class],br,img[id|dir|longdesc|usemap|class|src|border|alt=|title|width|height|align],-sub[class],-sup[class],-blockquote[dir|class],-table[border=0|cellspacing|cellpadding|width|height|class|align|summary|dir|id|style],-tr[id|dir|class|rowspan|width|height|align|valign|bgcolor|background|bordercolor|style],tbody[id|class|style],thead[id|class|style],tfoot[id|class|style],#td[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],-th[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],caption[id|dir|class],-h1[id|dir|class|align|style],-h2[id|dir|class|align|style],-h3[id|dir|class|align|style],-h4[id|dir|class|align|style],-h5[id|dir|class|align|style],-h6[id|dir|class|align|style],hr[class],dd[id|class|title|dir],dl[id|class|title|dir],dt[id|class|title|dir],@[id,style,class],small", 'extended_valid_elements' => "img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|usemap],#iframe[src|name|width|height|align|frameborder|marginwidth|marginheight|scrolling],object[width|height|data|type],param[name|value],map[class|name|id],area[shape|coords|href|target|alt]"));
// TinyMCE cleanup on paste
HtmlEditorConfig::get('cms')->setOption('paste_auto_cleanup_on_paste', 'true');
HtmlEditorConfig::get('cms')->setOption('paste_remove_styles', 'true');
HtmlEditorConfig::get('cms')->setOption('paste_remove_styles_if_webkit', 'true');
HtmlEditorConfig::get('cms')->setOption('paste_strip_class_attributes', 'true');
GD::set_default_quality(80);
ShortcodeParser::get()->register('blogfeed', array('Page_Controller', 'BlogFeedHandler'));
ShortcodeParser::get()->register('spotlight', array('Page_Controller', 'StaffSpotlightHandler'));
Object::add_extension("BlogEntry", "BlogFieldExtension");
开发者ID:javeriaaali,项目名称:student-org-kit,代码行数:31,代码来源:_config.php


示例19: basename

 * @platform    CMS SilverStripe 3
 * @package     cwsoft-shortcode
 * @version     2.2.4
 * @author      cwsoft (http://cwsoft.de)
 * @copyright   cwsoft
 * @license     http://www.gnu.org/licenses/gpl-3.0.html
*/
// ensure module is stored in folder "cwsoft-shortcode"
$moduleName = 'cwsoft-shortcode';
$folderName = basename(dirname(__FILE__));
if ($folderName != $moduleName) {
    user_error(_t('_config.WRONG_MODULE_FOLDER', 'Please rename the folder "{folderName}" into "{moduleName}" to get the {moduleName} module working properly.', array('moduleName' => $moduleName, 'folderName' => $folderName)), E_USER_ERROR);
}
// include external files into head section
Requirements::set_write_js_to_body(false);
// register short code tags accessible from pages of type cwsCodePage
ShortcodeParser::get()->register('cwsHideMailto', array('cwsShortCodeHideMailto', 'cwsShortCodeHideMailtoHandler'));
ShortcodeParser::get()->register('cwsRandomImage', array('cwsShortCodeRandomImage', 'cwsShortCodeRandomImageHandler'));
ShortcodeParser::get()->register('cwsRandomQuote', array('cwsShortCodeRandomQuote', 'cwsShortCodeRandomQuoteHandler'));
// increase quality of created thumbnails
if (class_exists('GDBackend')) {
    // SilverStripe >= 3.1.0
    GDBackend::set_default_quality(95);
} else {
    // SilverStripe 3.0.x
    GD::set_default_quality(95);
}
// Note: If you see unparsed placeholders like "{#shortcode.dlg_description}" when using the TinyMCE cwsoft-shortcode plugin,
// you need to add a plugin language file for your locale to the folder "./plugins/shortcode/langs". Supported locales: EN, DE.
HtmlEditorConfig::get('cms')->enablePlugins(array('shortcode' => '../../../cwsoft-shortcode/plugins/shortcode/editor_plugin_src.js'));
HtmlEditorConfig::get('cms')->addButtonsToLine(1, 'shortcode');
开发者ID:helpfulrobot,项目名称:cwsoft-silverstripe-shortcode,代码行数:31,代码来源:_config.php


示例20: testLinkShortcodeHandler

 public function testLinkShortcodeHandler()
 {
     $aboutPage = $this->objFromFixture('Page', 'about');
     $errorPage = $this->objFromFixture('ErrorPage', '404');
     $redirectPage = $this->objFromFixture('RedirectorPage', 'external');
     $parser = new ShortcodeParser();
     $parser->register('sitetree_link', array('SiteTree', 'link_shortcode_handler'));
     $aboutShortcode = sprintf('[sitetree_link,id=%d]', $aboutPage->ID);
     $aboutEnclosed = sprintf('[sitetree_link,id=%d]Example Content[/sitetree_link]', $aboutPage->ID);
     $aboutShortcodeExpected = $aboutPage->Link();
     $aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $aboutPage->Link());
     $this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test that simple linking works.');
     $this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed), 'Test enclosed content is linked.');
     $aboutPage->delete();
     $this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test that deleted pages still link.');
     $this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed));
     $aboutShortcode = '[sitetree_link,id="-1"]';
     $aboutEnclosed = '[sitetree_link,id="-1"]Example Content[/sitetree_link]';
     $aboutShortcodeExpected = $errorPage->Link();
     $aboutEnclosedExpected = sprintf('<a href="%s">Example Content</a>', $errorPage->Link());
     $this->assertEquals($aboutShortcodeExpected, $parser->parse($aboutShortcode), 'Test link to 404 page if no suitable matches.');
     $this->assertEquals($aboutEnclosedExpected, $parser->parse($aboutEnclosed));
     $redirectShortcode = sprintf('[sitetree_link,id=%d]', $redirectPage->ID);
     $redirectEnclosed = sprintf('[sitetree_link,id=%d]Example Content[/sitetree_link]', $redirectPage->ID);
     $redirectExpected = 'http://www.google.com?a&amp;b';
     $this->assertEquals($redirectExpected, $parser->parse($redirectShortcode));
     $this->assertEquals(sprintf('<a href="%s">Example Content</a>', $redirectExpected), $parser->parse($redirectEnclosed));
     $this->assertEquals('', $parser->parse('[sitetree_link]'), 'Test that invalid ID attributes are not parsed.');
     $this->assertEquals('', $parser->parse('[sitetree_link,id="text"]'));
     $this->assertEquals('', $parser->parse('[sitetree_link]Example Content[/sitetree_link]'));
 }
开发者ID:fanggu,项目名称:loveyourwater_ss_v3.1.6,代码行数:31,代码来源:SiteTreeTest.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP SibdietHelper类代码示例发布时间:2022-05-23
下一篇:
PHP ShortcodeHelper类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap