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]')); }
public function forTemplate() { if ($this->processShortcodes) { return ShortcodeParser::get_active()->parse($this->value); } else { return $this->value; } }
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); }
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; }
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); } }
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')); }
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; }
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'; }); }
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 ''; }
/** * @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; }
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; }
/** * 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]">')); }
<?php ShortcodeParser::get('default')->register('rdfa', array('RDFaExtension', 'RDFaShortcode'));
public function tearDown() { ShortcodeParser::get_active()->unregister('test_shortcode'); parent::tearDown(); }
/** * 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(); } }
<?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');
<?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'));
<?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';
$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");
* @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');
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&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]')); }
<?php // Paths /** * - BOLTTOOLS_DIR: Path relative to webroot, e.g. "boltmail" * - BOLTTOOLS_PATH: Absolute filepath, e.g. "/var/www/my-webroot/boltmail" */ define('BOLTTOOLS_DIR', basename(dirname(__FILE__))); define('BOLTTOOLS_PATH', BASE_PATH . '/' . BOLTTOOLS_DIR); define('BOLTTOOLS_THIRDPARTY_PATH', BOLTTOOLS_PATH . '/thirdparty'); //define('BOLTTOOLS_CONF_PATH', BOLTTOOLS_PATH.'/conf'); // Short code handlers ShortcodeParser::get()->register('LineBreak', array('BoltShortCodeHelper', 'LineBreak'));
public function forTemplate() { return ShortcodeParser::get_active()->parse($this->value); }
<?php define('SUBSITES_DOMAINS_DIR', ltrim(Director::makeRelative(realpath(__DIR__)), DIRECTORY_SEPARATOR)); Object::add_extension('HtmlEditorField_Toolbar', 'HtmlEditorField_ToolbarExtension'); ShortcodeParser::get('default')->register('subsite_link', array('HtmlEditorField_ToolbarExtension', 'link_shortcode_handler'));
/** * Set the identifier to use for the current active/default {@link ShortcodeParser} instance. * * @param string $identifier */ public static function set_active($identifier) { self::$active_instance = (string) $identifier; }
<?php // Decorate StringField so text-based data types have the method URLEncode // for use in templates. Object::add_extension('StringField', 'StringFieldDOD'); // adds a simple shortcode parser to include a specific vimeo video in text. ShortcodeParser::get('default')->register('vimeo', array('VimeoGalleryPage', 'VimeoShortcodeHandler'));
// Define path constant $path = str_replace('\\', '/', __DIR__); $path_fragments = explode('/', $path); $dir_name = $path_fragments[count($path_fragments) - 1]; define('ABC_SOCIAL_DIR', $dir_name); // attach the social extensions to the config and page classes SiteConfig::add_extension('SocialMediaConfig'); Page::add_extension('SocialMediaPageExtension'); // attach common behaviours to the social updates FBUpdate::add_extension('SocialUpdatePageExtension'); Tweet::add_extension('SocialUpdatePageExtension'); InstagramUpdate::add_extension('SocialUpdatePageExtension'); // add the embed functionality if (!Config::inst()->get('SocialGlobalConf', 'disable_wysiwyg_embed')) { ShortcodeParser::get('default')->register('social_embed', array('SocialMediaPageExtension', 'SocialEmbedParser')); HtmlEditorConfig::get('cms')->enablePlugins(array('social_embed' => '../../../' . ABC_SOCIAL_DIR . '/js/editor-plugin.js')); HtmlEditorConfig::get('cms')->addButtonsToLine(2, 'social_embed'); } // allow script tags // maybe we could try using requirements and stripping the script tags // HtmlEditorConfig::get('cms') // ->setOption( // 'extended_valid_elements', // 'img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|usemap|data*],' . // '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],ol[class|start],' . // 'script[type|src|lang|async|charset]'
<?php /** * - CMS_DIR: Path relative to webroot, e.g. "cms" * - CMS_PATH: Absolute filepath, e.g. "/var/www/my-webroot/cms" */ define('CMS_DIR', 'cms'); define('CMS_PATH', BASE_PATH . '/' . CMS_DIR); /** * Register the default internal shortcodes. */ ShortcodeParser::get('default')->register('sitetree_link', array('SiteTree', 'link_shortcode_handler')); File::add_extension('SiteTreeFileExtension'); // TODO Remove once we can configure CMSMenu through static, nested configuration files CMSMenu::remove_menu_item('CMSMain'); CMSMenu::remove_menu_item('CMSPageEditController'); CMSMenu::remove_menu_item('CMSPageSettingsController'); CMSMenu::remove_menu_item('CMSPageHistoryController'); CMSMenu::remove_menu_item('CMSPageReportsController'); CMSMenu::remove_menu_item('CMSPageAddController'); CMSMenu::remove_menu_item("SiteConfigLeftAndMain");
public function setUp() { ShortcodeParser::get('test')->register('test_shortcode', array($this, 'shortcodeSaver')); $this->parser = ShortcodeParser::get('test'); parent::setUp(); }
/** * Get the localized value for a given field. * @param string $fieldName the name of the field without any locale extension. Eg. "Title" * @param boolean $strict if false, this will fallback to the master version of the field! * @param boolean $parseShortCodes whether or not the value should be parsed with the shortcode parser * @return string|DBField */ public function getLocalizedValue($fieldName, $strict = true, $parseShortCodes = false) { $localizedField = $this->getLocalizedFieldName($fieldName); // ensure that $strict is a boolean value $strict = filter_var($strict, FILTER_VALIDATE_BOOLEAN); /** @var DBField $value */ $value = $this->owner->dbObject($localizedField); if (!$strict && !$value->exists()) { $value = $this->owner->dbObject($fieldName); } return $parseShortCodes && $value ? ShortcodeParser::get_active()->parse($value->getValue()) : $value; }