Merge pull request #1935 from andrewandante/BUGFIX/namespaced_page_icon

sanitize namespaced classes for page icon css
This commit is contained in:
Chris Joe 2017-08-24 23:42:41 +12:00 committed by GitHub
commit c704b6d36a
3 changed files with 7 additions and 4 deletions

View File

@ -6,6 +6,7 @@ use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Session; use SilverStripe\Control\Session;
use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form; use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction; use SilverStripe\Forms\FormAction;
@ -44,7 +45,7 @@ class CMSPageAddController extends CMSPageEditController
foreach ($this->PageTypes() as $type) { foreach ($this->PageTypes() as $type) {
$html = sprintf( $html = sprintf(
'<span class="page-icon class-%s"></span><span class="title">%s</span><span class="form__field-description">%s</span>', '<span class="page-icon class-%s"></span><span class="title">%s</span><span class="form__field-description">%s</span>',
$type->getField('ClassName'), Convert::raw2htmlid($type->getField('ClassName')),
$type->getField('AddAction'), $type->getField('AddAction'),
$type->getField('Description') $type->getField('Description')
); );

View File

@ -2,6 +2,7 @@
namespace SilverStripe\CMS\Controllers; namespace SilverStripe\CMS\Controllers;
use SilverStripe\Core\Convert;
use SilverStripe\View\Requirements; use SilverStripe\View\Requirements;
use SilverStripe\Core\ClassInfo; use SilverStripe\Core\ClassInfo;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
@ -45,8 +46,8 @@ class LeftAndMainPageIconsExtension extends Extension
$iconFile .= '-file.gif'; $iconFile .= '-file.gif';
} }
$class = Convert::raw2htmlid($class);
$selector = ".page-icon.class-$class, li.class-$class > a .jstree-pageicon"; $selector = ".page-icon.class-$class, li.class-$class > a .jstree-pageicon";
if (Director::fileExists($iconFile)) { if (Director::fileExists($iconFile)) {
$css .= "$selector { background: transparent url('$iconFile') 0 0 no-repeat; }\n"; $css .= "$selector { background: transparent url('$iconFile') 0 0 no-repeat; }\n";
} else { } else {

View File

@ -2621,7 +2621,8 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
} }
$flags = $this->getStatusFlags(); $flags = $this->getStatusFlags();
$treeTitle = sprintf( $treeTitle = sprintf(
"<span class=\"jstree-pageicon\"></span><span class=\"item\" data-allowedchildren=\"%s\">%s</span>", "<span class=\"jstree-pageicon page-icon class-%s\"></span><span class=\"item\" data-allowedchildren=\"%s\">%s</span>",
Convert::raw2htmlid(static::class),
Convert::raw2att(Convert::raw2json($children)), Convert::raw2att(Convert::raw2json($children)),
Convert::raw2xml(str_replace(array("\n","\r"), "", $this->MenuTitle)) Convert::raw2xml(str_replace(array("\n","\r"), "", $this->MenuTitle))
); );
@ -2715,7 +2716,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
*/ */
public function CMSTreeClasses() public function CMSTreeClasses()
{ {
$classes = sprintf('class-%s', static::class); $classes = sprintf('class-%s', Convert::raw2htmlid(static::class));
if ($this->HasBrokenFile || $this->HasBrokenLink) { if ($this->HasBrokenFile || $this->HasBrokenLink) {
$classes .= " BrokenLink"; $classes .= " BrokenLink";
} }