Skip to content

Commit

Permalink
BUG Change all shortcodes into the new, comma separated, format.
Browse files Browse the repository at this point in the history
Space delimiter is often confused by browsers, and encoded as %20 which
breaks the shortcode system. Change to comma delimitation has already
been implemented, this is a followup cleanup.

Ref http://open.silverstripe.org/ticket/7337
  • Loading branch information
mateusz committed Jul 12, 2012
1 parent 29a0399 commit 7c41ff2
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions forms/HtmlEditorField.php
Expand Up @@ -63,14 +63,14 @@ function Field($properties = array()) {
if($links = $value->getElementsByTagName('a')) foreach($links as $link) {
$matches = array();

if(preg_match('/\[sitetree_link id=([0-9]+)\]/i', $link->getAttribute('href'), $matches)) {
if(preg_match('/\[sitetree_link(?:\s*|%20|,)?id=([0-9]+)\]/i', $link->getAttribute('href'), $matches)) {
if(!DataObject::get_by_id('SiteTree', $matches[1])) {
$class = $link->getAttribute('class');
$link->setAttribute('class', ($class ? "$class ss-broken" : 'ss-broken'));
}
}

if(preg_match('/\[file_link id=([0-9]+)\]/i', $link->getAttribute('href'), $matches)) {
if(preg_match('/\[file_link(?:\s*|%20|,)?id=([0-9]+)\]/i', $link->getAttribute('href'), $matches)) {
if(!DataObject::get_by_id('File', $matches[1])) {
$class = $link->getAttribute('class');
$link->setAttribute('class', ($class ? "$class ss-broken" : 'ss-broken'));
Expand Down Expand Up @@ -114,7 +114,7 @@ public function saveInto(DataObjectInterface $record) {
$href = Director::makeRelative($link->getAttribute('href'));

if($href) {
if(preg_match('/\[sitetree_link id=([0-9]+)\]/i', $href, $matches)) {
if(preg_match('/\[sitetree_link,id=([0-9]+)\]/i', $href, $matches)) {
$ID = $matches[1];

// clear out any broken link classes
Expand Down
2 changes: 1 addition & 1 deletion javascript/HtmlEditorField.js
Expand Up @@ -691,7 +691,7 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
Description: title,
TargetBlank: target ? true : false
};
} else if(href.match(/^\[sitetree_link\s*(?:%20)?id=([0-9]+)\]?(#.*)?$/)) {
} else if(href.match(/^\[sitetree_link(?:\s*|%20|,)?id=([0-9]+)\]?(#.*)?$/i)) {
return {
LinkType: 'internal',
internal: RegExp.$1,
Expand Down
2 changes: 1 addition & 1 deletion parsers/ShortcodeParser.php
Expand Up @@ -29,7 +29,7 @@
*
* <b>Inbuilt Shortcodes</b>
*
* From 2.4 onwards links inserted via the CMS into a content field are in the form ''<a href="[sitetree_link id=n]">''. At runtime this is replaced by a plain link to the page with the ID in question.
* From 2.4 onwards links inserted via the CMS into a content field are in the form ''<a href="[sitetree_link id=n]">'', and from 3.0 the comma is used as a separator instead ''<a href="[sitetree_link,id=n]">''. At runtime this is replaced by a plain link to the page with the ID in question.
*
* <b>Limitations</b>
*
Expand Down

0 comments on commit 7c41ff2

Please sign in to comment.