ENHANCEMENT: allow sites to override meta generator tag

This commit is contained in:
Jeremy Thomerson 2013-06-17 20:29:02 +00:00
parent 4bc942df76
commit b8908efdf7
2 changed files with 43 additions and 1 deletions

View File

@ -203,6 +203,14 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
*/
private static $enforce_strict_hierarchy = true;
/**
* The value used for the meta generator tag. Leave blank to omit the tag.
*
* @config
* @var string
*/
private static $meta_generator = 'SilverStripe - http://silverstripe.org';
protected $_cache_statusFlags = null;
/**
@ -1298,7 +1306,10 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$tags .= "<title>" . $this->Title . "</title>\n";
}
$tags .= "<meta name=\"generator\" content=\"SilverStripe - http://silverstripe.org\" />\n";
$generator = trim(Config::inst()->get('SiteTree', 'meta_generator'));
if (!empty($generator)) {
$tags .= "<meta name=\"generator\" content=\"" . Convert::raw2att($generator) . "\" />\n";
}
$charset = Config::inst()->get('ContentNegotiator', 'encoding');
$tags .= "<meta http-equiv=\"Content-type\" content=\"text/html; charset=$charset\" />\n";

View File

@ -889,6 +889,37 @@ class SiteTreeTest extends SapphireTest {
$page = SiteTree::get()->byID($page->ID);
$this->assertEquals(null, $page->getField('MenuTitle'));
}
public function testMetaTagGeneratorDisabling() {
$generator = Config::inst()->get('SiteTree', 'meta_generator');
$page = new SiteTreeTest_PageNode();
$meta = $page->MetaTags();
$this->assertEquals(
1,
preg_match('/.*meta name="generator" content="SilverStripe - http:\/\/silverstripe.org".*/', $meta),
'test default functionality - uses value from Config');
// test proper escaping of quotes in attribute value
Config::inst()->update('SiteTree', 'meta_generator', 'Generator with "quotes" in it');
$meta = $page->MetaTags();
$this->assertEquals(
1,
preg_match('/.*meta name="generator" content="Generator with &quot;quotes&quot; in it".*/', $meta),
'test proper escaping of values from Config');
// test empty generator - no tag should appear at all
Config::inst()->update('SiteTree', 'meta_generator', '');
$meta = $page->MetaTags();
$this->assertEquals(
0,
preg_match('/.*meta name=.generator..*/', $meta),
'test blank value means no tag generated');
// reset original value
Config::inst()->update('SiteTree', 'meta_generator', $generator);
}
}