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


PHP ShortcodeParser::parse方法代码示例

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


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

示例1: testLinkShortcodeHandler

 public function testLinkShortcodeHandler()
 {
     $testFile = $this->objFromFixture('File', 'asdf');
     $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]';
     $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]'));
     if (class_exists('ErrorPage')) {
         $errorPage = ErrorPage::get()->filter('ErrorCode', 404)->First();
         $this->assertEquals($errorPage->Link(), $parser->parse($fileShortcode), 'Test link to 404 page if no suitable matches.');
         $this->assertEquals(sprintf('<a href="%s">Example Content</a>', $errorPage->Link()), $parser->parse($fileEnclosed));
     } else {
         $this->assertEquals('', $parser->parse($fileShortcode), 'Short code is removed if file record is not present.');
         $this->assertEquals('', $parser->parse($fileEnclosed));
     }
 }
开发者ID:fanggu,项目名称:loveyourwater_ss_v3.1.6,代码行数:26,代码来源:FileTest.php

示例2: parse

 public function parse($content)
 {
     $context = $this->getContext();
     // Replace custom elements
     $content = $this->substituteCustomElements($content, $context);
     // Delegate to parent to handle shortcodes proper.
     return parent::parse($content);
 }
开发者ID:GOVTNZ,项目名称:aacustomelements,代码行数:8,代码来源:CustomElementsParser.php

示例3: 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

示例4: 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

示例5: 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

示例6: testShortcodeHandlerAddsDefaultAttributes

 public function testShortcodeHandlerAddsDefaultAttributes()
 {
     $image = $this->objFromFixture('Image', 'imageWithoutTitle');
     $parser = new ShortcodeParser();
     $parser->register('image', array('Image', 'handle_shortcode'));
     $this->assertEquals(sprintf('<img src="%s" alt="%s">', $image->Link(), $image->Title), $parser->parse(sprintf('[image id="%d"]', $image->ID)));
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:7,代码来源:ImageTest.php

示例7: 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())
 {
     // Find appropriate record, with fallback for error handlers
     $record = static::find_shortcode_record($arguments, $errorCode);
     if ($errorCode) {
         $record = static::find_error_record($errorCode);
     }
     if (!$record) {
         return null;
         // 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:jacobbuck,项目名称:silverstripe-framework,代码行数:35,代码来源:File.php

示例8: 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 null;
     }
     /** @var File|SiteTree $record */
     $record = DataObject::get_by_id('File', $arguments['id']);
     // Check record for common errors
     $errorCode = null;
     if (!$record) {
         $errorCode = 404;
     } elseif (!$record->canView()) {
         $errorCode = 403;
     }
     if ($errorCode) {
         $result = static::singleton()->invokeWithExtensions('getErrorRecordFor', $errorCode);
         $result = array_filter($result);
         if ($result) {
             $record = reset($result);
         }
     }
     if (!$record) {
         return null;
         // 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:assertchris,项目名称:silverstripe-framework,代码行数:49,代码来源:File.php

示例9: replaceChildrenCalls

 public function replaceChildrenCalls($html)
 {
     $codes = new ShortcodeParser();
     $codes->register('CHILDREN', array($this, 'includeChildren'));
     return $codes->parse($html);
 }
开发者ID:Jellygnite,项目名称:silverstripe-docsviewer,代码行数:6,代码来源:DocumentationViewer.php


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