From 4cb5bd719a16e114a172bbbeba550004cbe205e7 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 14 Sep 2007 00:47:00 +0000 Subject: [PATCH] wscott: Added some additional fixes & such to sapphire TooglePanel? can be created initially closed PasswordField? honors a max size passed to it SiteTree? / Pages can now have custom meta tags Sitemap can deal with pinging google on updates, plus a couple other minor changes git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41690 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/control/Sitemap.php | 23 +++++++++++++++++++++++ core/model/SiteTree.php | 12 ++++++++++-- forms/PasswordField.php | 2 +- forms/TogglePanel.php | 3 ++- templates/Sitemap.ss | 2 ++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/core/control/Sitemap.php b/core/control/Sitemap.php index eacdfdd12..719c693b9 100755 --- a/core/control/Sitemap.php +++ b/core/control/Sitemap.php @@ -16,6 +16,12 @@ class Sitemap extends Controller { { foreach($this->Pages as $page) { + // If the page has been set to 0 priority, we set a flag so it won't be included + if(isset($page->Priority) && $page->Priority <= 0) + $page->Include = false; + else + $page->Include = true; + // The one field that isn't easy to deal with in the template is // Change frequency, so we set that here. $properties = $page->toMap(); @@ -59,6 +65,10 @@ class Sitemap extends Controller { static function Ping() { + //Don't ping if the site has disabled it + if(!Sitemap::$pings) + return; + $location = urlencode(Director::absoluteBaseURL() . '/sitemap.xml'); $response = HTTP::sendRequest("www.google.com", "/webmasters/sitemaps/ping", @@ -67,6 +77,19 @@ class Sitemap extends Controller { return $response; } + protected static $pings = true; + + /** + * Disables pings to google when the sitemap changes + * To use this, in your _config.php file simply include the line + * Sitemap::DisableGoogleNotification(); + */ + static function DisableGoogleNotification() + { + self::$pings = false; + } + + function index($url) { // We need to override the default content-type diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index 1c1a2fdf4..4e0aad35e 100644 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -387,6 +387,9 @@ class SiteTree extends DataObject { if($this->MetaDescription) { $tags .= "MetaDescription) . "\" />\n"; } + if($this->ExtraMeta) { + $tags .= $this->ExtraMeta . "\n"; + } return $tags; } @@ -672,8 +675,12 @@ class SiteTree extends DataObject { new TextField("MetaTitle", "Title"), new TextareaField("MetaDescription", "Description"), new TextareaField("MetaKeywords", "Keywords"), - new LiteralField("", "

Manually specify a Priority for this page:: (valid values are from 0 to 1)

"), - new NumericField("Priority","Page Priority") + new TogglePanel("Advanced Options...",array( + new TextareaField("ExtraMeta","Custom Meta Tags"), + new LiteralField("", "

Manually specify a Priority for this page: (valid values are from 0 to 1, a zero will remove this page from the index)

"), + new NumericField("Priority","Page Priority")), + true + ) ) ), new Tab("Behaviour", @@ -979,6 +986,7 @@ class SiteTree extends DataObject { "MetaTitle" => "Varchar(255)", "MetaDescription" => "Varchar(255)", "MetaKeywords" => "Varchar(255)", + "ExtraMeta" => "HTMLText", "ShowInMenus" => "Boolean", "ShowInSearch" => "Boolean", "HomepageForDomain" => "Varchar(100)", diff --git a/forms/PasswordField.php b/forms/PasswordField.php index c0500a6dd..baf03a7c3 100755 --- a/forms/PasswordField.php +++ b/forms/PasswordField.php @@ -15,7 +15,7 @@ class PasswordField extends FormField { function Field() { if($this->maxLength){ - return "id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" maxlength=\"$this->maxLength\" />"; + return "id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" maxlength=\"$this->maxLength\" size=\"$this->maxLength\"/>"; }else{ return "id() . "\" name=\"{$this->name}\" value=\"" . $this->attrValue() . "\" />"; } diff --git a/forms/TogglePanel.php b/forms/TogglePanel.php index 33b8f8e82..7b63eef41 100755 --- a/forms/TogglePanel.php +++ b/forms/TogglePanel.php @@ -3,8 +3,9 @@ class TogglePanel extends CompositeField { protected $closed = false; - function __construct($title, $children) { + function __construct($title, $children, $startClosed = false) { $this->title = $title; + $this->closed = $startClosed; $this->name = ereg_replace('[^A-Za-z0-9]','',$this->title); parent::__construct($children); } diff --git a/templates/Sitemap.ss b/templates/Sitemap.ss index cb1102f36..67aa8f944 100755 --- a/templates/Sitemap.ss +++ b/templates/Sitemap.ss @@ -3,11 +3,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84"> <% control Items %> + <% if Include %> $AbsoluteLink $LastEdited.Format(c) <% if ChangeFreq %>$ChangeFreq<% end_if %> <% if Priority %>$Priority<% end_if %> + <% end_if %> <% end_control %> \ No newline at end of file