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')); }
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'; }); }
<?php ShortcodeParser::get('default')->register('rdfa', array('RDFaExtension', 'RDFaShortcode'));
<?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 /** * - 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");
<?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'));
* @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');
<?php $dir = basename(dirname(__FILE__)); if ($dir === 'shortcodes') { define('SHORTCODES_DIR', $dir); } else { user_error('ShortCodes: Directory name must be "shortcodes" (currently "' . $dir . '")', E_USER_ERROR); } ShortcodeParser::get()->register('youtube', array('ShortCodes', 'YouTubeShortCodeHandler')); ShortcodeParser::get()->register('vimeo', array('ShortCodes', 'VimeoShortCodeHandler')); HtmlEditorConfig::get('cms')->enablePlugins(array('youtube' => '../../../shortcodes/javascript/youtube.min.js', 'vimeo' => '../../../shortcodes/javascript/vimeo.min.js')); HtmlEditorConfig::get('cms')->insertButtonsAfter('anchor', 'youtube', 'vimeo');
<?php define('DMS_DIR', 'dms'); Object::add_extension('SiteTree', 'DMSSiteTreeExtension'); Object::add_extension('HtmlEditorField_Toolbar', 'DocumentHtmlEditorFieldToolbar'); CMSMenu::remove_menu_item('DMSDocumentAddController'); ShortcodeParser::get('default')->register('dms_document_link', array('DMSDocument_Controller', 'dms_link_shortcode_handler')); if (!file_exists(BASE_PATH . DIRECTORY_SEPARATOR . DMS_DIR)) { user_error("DMS directory named incorrectly. Please install the DMS module into a folder named: " . DMS_DIR); }
<?php define('LINKABLE_DATAOBJECTS_DIR', basename(dirname(__FILE__))); $linkables = ClassInfo::implementorsOf('Linkable'); foreach ($linkables as $class) { //die(strtolower($class).'_link'); ShortcodeParser::get('default')->register(strtolower($class) . '_link', array($class, 'link_shortcode_handler')); }
<?php /** * Adds a short-code for [code]. This allows styled code to be included in any SiteTree * content area by wrapping the content in the [code] tag. An optional 'lang' parameter * can be used to define a valid GeSHi language set, or a 'ref' parameter can point to * an exisiting Snippet saved in the system. * * <example> * [code lang='php'] * $example = "Hello, World!"; * echo $example; * [/code] * * [code ref='as12n' /] * **/ ShortcodeParser::get('default')->register('code', array('PastieSnippet', 'shortcode_handler'));
public function tearDown() { ShortcodeParser::get('test')->unregister('test_shortcode'); parent::tearDown(); }
<?php // Adding embedcontent button to HtmlEditorConfig //Need noneditable plugin HtmlEditorConfig::get('cms')->enablePlugins('noneditable'); HtmlEditorConfig::get('cms')->enablePlugins(array('embedcontent' => 'embedcontent/javascript/editor_plugin.js')); HtmlEditorConfig::get('cms')->addButtonsToLine(1, 'embedcontent'); ShortcodeParser::get('default')->register('EmbedContent', array('EmbedContentController', 'get_embed_content'));
/** * Calls the parser, should only need it instantiated once. * * @return null|ShortcodeParser */ protected function getParser() { if (!$this->parser) { $parser = ShortcodeParser::get('LightboxTracking'); $parser->register('lightbox', array($this, 'parse_callback')); $this->parser = $parser; } return $this->parser; }
<?php ShortcodeParser::get()->register('SiteMap', array('SiteMapPage', 'SiteMapShortCodeHandler')); define('SITEMAP3_DIR', basename(dirname(__FILE__)));
<?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';
<?php ShortcodeParser::get('default')->register('FlexSlider', array('FlexSlider', 'FlexSliderShortCodeHandler'));
<?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'));
<?php if (!defined('SHORTCODABLE_DIR')) { define('SHORTCODABLE_DIR', rtrim(basename(dirname(__FILE__)))); } if (SHORTCODABLE_DIR != 'shortcodable') { throw new Exception('The edit shortcodable module is not installed in correct directory. The directory should be named "shortcodable"'); } // enable shortcodable buttons and add to HtmlEditorConfig HtmlEditorConfig::get('cms')->enablePlugins(array('shortcodable' => sprintf('../../../%s/javascript/editor_plugin.js', SHORTCODABLE_DIR))); HtmlEditorConfig::get('cms')->addButtonsToLine(1, 'shortcodable'); // register shortcode parsers for Shortcodable implementors foreach (ClassInfo::implementorsOf('Shortcodable') as $class) { $name = $class; ShortcodeParser::get('default')->register($name, array($class, 'parse_shortcode')); // TODO - update SS ShortcodeParser to offer a public api for converting a shortcode to a data array, and use that instead. singleton('ShortcodableParser')->register($name); }
<?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'));
<?php ShortcodeParser::get('default')->register('groupdocsComparison', array('groupdocsComparison', 'handle_shortcode'));
<?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 ShortcodeParser::get('default')->register('YouTube', array('YouTubeShortCodeHandler', 'parse_youtube'));
$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");
public function testShortCodeParsedInTemplateHelpers() { $parser = ShortcodeParser::get('HTMLTextTest'); $parser->register('shortcode', function ($arguments, $content, $parser, $tagName, $extra) { return 'Replaced short code with this. <a href="home">home</a>'; }); ShortcodeParser::set_active('HTMLTextTest'); /** @var HTMLText $field */ $field = DBField::create_field('HTMLText', '<p>[shortcode]</p>'); $this->assertEquals('<p>Replaced short code with this. <a href="home">home</a></p>', $field->HTMLATT()); $this->assertEquals('%3Cp%3EReplaced+short+code+with+this.+%3Ca+href%3D%22home%22%3Ehome%3C%2Fa%3E%3C%2Fp%3E', $field->URLATT()); $this->assertEquals('%3Cp%3EReplaced%20short%20code%20with%20this.%20%3Ca%20href%3D%22home%22%3Ehome%3C%2Fa%3E%3C%2Fp%3E', $field->RAWURLATT()); $this->assertEquals('<p>Replaced short code with this. <a href="home">home</a></p>', $field->ATT()); $this->assertEquals('<p>Replaced short code with this. <a href="home">home</a></p>', $field->RAW()); $this->assertEquals('\\x3cp\\x3eReplaced short code with this. \\x3ca href=\\"home\\"\\x3ehome\\x3c/a\\x3e\\x3c/p\\x3e', $field->JS()); $this->assertEquals('<p>Replaced short code with this. <a href="home">home</a></p>', $field->HTML()); $this->assertEquals('<p>Replaced short code with this. <a href="home">home</a></p>', $field->XML()); $this->assertEquals('Repl...', $field->LimitCharacters(4, '...')); $this->assertEquals('Replaced...', $field->LimitCharactersToClosestWord(10, '...')); $this->assertEquals('Replaced...', $field->LimitWordCount(1, '...')); $this->assertEquals('<p>replaced short code with this. <a href="home">home</a></p>', $field->LowerCase()); $this->assertEquals('<P>REPLACED SHORT CODE WITH THIS. <A HREF="HOME">HOME</A></P>', $field->UpperCase()); $this->assertEquals('Replaced short code with this. home', $field->NoHTML()); Config::nest(); Config::inst()->update('Director', 'alternate_base_url', 'http://example.com/'); $this->assertEquals('<p>Replaced short code with this. <a href="http://example.com/home">home</a></p>', $field->AbsoluteLinks()); Config::unnest(); $this->assertEquals('Replaced short code with this.', $field->LimitSentences(1)); $this->assertEquals('Replaced short code with this.', $field->FirstSentence()); $this->assertEquals('Replaced short...', $field->Summary(2)); $this->assertEquals('Replaced short code with...', $field->BigSummary(4)); $this->assertEquals('Replaced short code with this. home[home]', $field->FirstParagraph()); $this->assertEquals('Replaced <span class="highlight">short</span> <span class="highlight">code</span> with this. home', $field->ContextSummary(500, 'short code')); ShortcodeParser::set_active('default'); }
// 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 ShortcodeParser::get('default')->register('groupdocsJavaViewer', array('groupdocsJavaViewer', 'handle_shortcode'));
public function setUp() { ShortcodeParser::get('test')->register('test_shortcode', array($this, 'shortcodeSaver')); $this->parser = ShortcodeParser::get('test'); parent::setUp(); }
<?php ShortcodeParser::get()->register('FacebookFeed', function ($arguments, $caption = null, $parser = null) { $lb = new FacebookLikebox($arguments); return $lb->forTemplate(); });