From 477f857acfed7ac080f526cef04a057e0b905bf0 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 2 Apr 2013 11:38:09 +1300 Subject: [PATCH] API Updated blog module to adhere to new rules around configuration. Static configurable properties (db, has_one, etc) are now private. Also removed trailing ?>(newline) from various files, and cleaned up some redundant code (empty has_ones, etc). Also noted in the code are places where various static properties should be refactored out in favour of using the Silverstripe configuration system instead. For now the bare mimimum work has been done in order to make the module work in 3.1 --- _config/trackback.yml | 3 +++ code/BlogEntry.php | 32 +++++++++------------------ code/BlogHolder.php | 21 ++++++++---------- code/BlogTree.php | 30 +++++++++++++------------ code/MetaWeblogController.php | 4 +--- code/TrackBackDecorator.php | 14 +++++++----- code/TrackBackPing.php | 14 +++--------- code/TrackBackURL.php | 5 +++-- code/import/TypoImport.php | 1 - code/widgets/ArchiveWidget.php | 22 +++++------------- code/widgets/BlogManagementWidget.php | 23 +++++-------------- code/widgets/BlogTreeExtension.php | 2 +- code/widgets/RSSWidget.php | 22 ++++++------------ code/widgets/SubscribeRSSWidget.php | 10 ++++----- code/widgets/TagCloudWidget.php | 23 ++++++------------- tests/BlogHolderTest.php | 2 -- tests/BlogTreeTest.php | 2 -- thirdparty/xmlrpc/xmlrpc.php | 2 -- thirdparty/xmlrpc/xmlrpc_wrappers.php | 1 - thirdparty/xmlrpc/xmlrpcs.php | 1 - 20 files changed, 85 insertions(+), 149 deletions(-) create mode 100644 _config/trackback.yml diff --git a/_config/trackback.yml b/_config/trackback.yml new file mode 100644 index 0000000..422d040 --- /dev/null +++ b/_config/trackback.yml @@ -0,0 +1,3 @@ +BlogEntry: + extensions: + - 'TrackBackDecorator' \ No newline at end of file diff --git a/code/BlogEntry.php b/code/BlogEntry.php index a9ad956..1a7387d 100644 --- a/code/BlogEntry.php +++ b/code/BlogEntry.php @@ -5,43 +5,33 @@ * @package blog */ class BlogEntry extends Page { - static $db = array( + private static $db = array( "Date" => "SS_Datetime", "Author" => "Text", "Tags" => "Text" ); - static $default_parent = 'BlogHolder'; + private static $default_parent = 'BlogHolder'; - static $can_be_root = false; + private static $can_be_root = false; - static $icon = "blog/images/blogpage-file.png"; + private static $icon = "blog/images/blogpage-file.png"; - static $description = "An individual blog entry"; + private static $description = "An individual blog entry"; - static $singular_name = 'Blog Entry Page'; + private static $singular_name = 'Blog Entry Page'; - static $plural_name = 'Blog Entry Pages'; - - static $has_one = array(); + private static $plural_name = 'Blog Entry Pages'; - static $has_many = array(); - - static $many_many = array(); - - static $belongs_many_many = array(); - - static $defaults = array( + private static $defaults = array( "ProvideComments" => true, 'ShowInMenus' => false ); - - static $extensions = array( - 'TrackBackDecorator' - ); /** * Is WYSIWYG editing allowed? + * + * @todo Update to use SS3 Config * @var boolean */ static $allow_wysiwyg_editing = true; @@ -248,7 +238,7 @@ class BlogEntry extends Page { class BlogEntry_Controller extends Page_Controller { - static $allowed_actions = array( + private static $allowed_actions = array( 'index', 'trackbackping', 'unpublishPost', diff --git a/code/BlogHolder.php b/code/BlogHolder.php index ea6c487..82e8129 100644 --- a/code/BlogHolder.php +++ b/code/BlogHolder.php @@ -12,25 +12,25 @@ * BlogHolders have a form on them for easy posting, and an owner that can post to them, BlogTrees don't */ class BlogHolder extends BlogTree implements PermissionProvider { - static $icon = "blog/images/blogholder-file.png"; + private static $icon = "blog/images/blogholder-file.png"; - static $description = "Displays listings of blog entries"; + private static $description = "Displays listings of blog entries"; - static $singular_name = 'Blog Holder Page'; + private static $singular_name = 'Blog Holder Page'; - static $plural_name = 'Blog Holder Pages'; + private static $plural_name = 'Blog Holder Pages'; - static $db = array( + private static $db = array( 'TrackBacksEnabled' => 'Boolean', 'AllowCustomAuthors' => 'Boolean', 'ShowFullEntry' => 'Boolean', ); - static $has_one = array( + private static $has_one = array( 'Owner' => 'Member', ); - static $allowed_children = array( + private static $allowed_children = array( 'BlogEntry' ); @@ -167,7 +167,7 @@ class BlogHolder extends BlogTree implements PermissionProvider { } class BlogHolder_Controller extends BlogTree_Controller { - static $allowed_actions = array( + private static $allowed_actions = array( 'index', 'tag', 'date', @@ -304,7 +304,4 @@ class BlogHolder_Controller extends BlogTree_Controller { $this->redirect($this->Link()); } -} - - -?> +} \ No newline at end of file diff --git a/code/BlogTree.php b/code/BlogTree.php index 142625c..2b413b3 100644 --- a/code/BlogTree.php +++ b/code/BlogTree.php @@ -11,33 +11,35 @@ class BlogTree extends Page { - static $icon = "blog/images/blogtree-file.png"; + private static $icon = "blog/images/blogtree-file.png"; - static $description = "A grouping of blogs"; + private static $description = "A grouping of blogs"; - static $singular_name = 'Blog Tree Page'; + private static $singular_name = 'Blog Tree Page'; - static $plural_name = 'Blog Tree Pages'; + private static $plural_name = 'Blog Tree Pages'; - // Default number of blog entries to show + /** + * Default number of blog entries to show + * + * @todo Update to use SS Config + * @var integer + */ static $default_entries_limit = 10; - static $db = array( + private static $db = array( 'Name' => 'Varchar(255)', 'InheritSideBar' => 'Boolean', 'LandingPageFreshness' => 'Varchar', ); - static $defaults = array( + private static $defaults = array( 'InheritSideBar' => True ); - static $has_one = array(); - - static $has_many = array(); - - static $allowed_children = array( - 'BlogTree', 'BlogHolder' + private static $allowed_children = array( + 'BlogTree', + 'BlogHolder' ); @@ -233,7 +235,7 @@ class BlogTree extends Page { class BlogTree_Controller extends Page_Controller { - static $allowed_actions = array( + private static $allowed_actions = array( 'index', 'rss', 'tag', diff --git a/code/MetaWeblogController.php b/code/MetaWeblogController.php index f890a75..89ea536 100644 --- a/code/MetaWeblogController.php +++ b/code/MetaWeblogController.php @@ -100,6 +100,4 @@ class MetaWeblogController extends Controller { //TODO dummy function return array(); } -} - -?> +} \ No newline at end of file diff --git a/code/TrackBackDecorator.php b/code/TrackBackDecorator.php index e463be6..8edc147 100644 --- a/code/TrackBackDecorator.php +++ b/code/TrackBackDecorator.php @@ -1,10 +1,14 @@ 'TrackBackURL', 'TrackBacks' => 'TrackBackPing' ); @@ -156,6 +160,4 @@ class TrackbackHTTPServer { return new SS_HTTPResponse($response, $statusCode); } -} - -?> +} \ No newline at end of file diff --git a/code/TrackBackPing.php b/code/TrackBackPing.php index 0ebec77..a3c2220 100644 --- a/code/TrackBackPing.php +++ b/code/TrackBackPing.php @@ -1,7 +1,7 @@ 'Varchar', 'Excerpt' => 'Text', // 2083 is URL-length limit for IE, AFAIK. @@ -10,15 +10,7 @@ class TrackBackPing extends DataObject { 'BlogName' => 'Varchar' ); - static $has_one = array( + private static $has_one = array( 'Page' => 'Page' ); - - static $has_many = array(); - - static $many_many = array(); - - static $belongs_many_many = array(); -} - -?> +} \ No newline at end of file diff --git a/code/TrackBackURL.php b/code/TrackBackURL.php index 2d3c775..f90d94e 100644 --- a/code/TrackBackURL.php +++ b/code/TrackBackURL.php @@ -1,12 +1,13 @@ 'Varchar(2048)', 'Pung' => 'Boolean(0)' ); - static $has_one = array( + private static $has_one = array( 'BlogEntry' => 'BlogEntry' ); diff --git a/code/import/TypoImport.php b/code/import/TypoImport.php index 2b3b21f..3961d67 100644 --- a/code/import/TypoImport.php +++ b/code/import/TypoImport.php @@ -149,4 +149,3 @@ class TypoImport extends Controller { } // end function } // end class -?> diff --git a/code/widgets/ArchiveWidget.php b/code/widgets/ArchiveWidget.php index ca75c68..b14221e 100644 --- a/code/widgets/ArchiveWidget.php +++ b/code/widgets/ArchiveWidget.php @@ -6,27 +6,19 @@ * @package blog */ class ArchiveWidget extends Widget { - static $db = array( + private static $db = array( 'DisplayMode' => 'Varchar' ); - static $has_one = array(); - - static $has_many = array(); - - static $many_many = array(); - - static $belongs_many_many = array(); - - static $defaults = array( + private static $defaults = array( 'DisplayMode' => 'month' ); - static $title = 'Browse by Date'; + private static $title = 'Browse by Date'; - static $cmsTitle = 'Blog Archive'; + private static $cmsTitle = 'Blog Archive'; - static $description = 'Show a list of months or years in which there are blog posts, and provide links to them.'; + private static $description = 'Show a list of months or years in which there are blog posts, and provide links to them.'; function getCMSFields() { $fields = parent::getCMSFields(); @@ -106,6 +98,4 @@ class ArchiveWidget extends Widget { return $results; } -} - -?> +} \ No newline at end of file diff --git a/code/widgets/BlogManagementWidget.php b/code/widgets/BlogManagementWidget.php index c5b2022..61781e6 100644 --- a/code/widgets/BlogManagementWidget.php +++ b/code/widgets/BlogManagementWidget.php @@ -4,21 +4,11 @@ * @package blog */ class BlogManagementWidget extends Widget implements PermissionProvider { - static $db = array(); - - static $has_one = array(); - - static $has_many = array(); - - static $many_many = array(); - - static $belongs_many_many = array(); - - static $defaults = array(); - - static $title = "Blog Management"; - static $cmsTitle = "Blog Management"; - static $description = "Provide a number of links useful for administering a blog. Only shown if the user is an admin."; + private static $title = "Blog Management"; + + private static $cmsTitle = "Blog Management"; + + private static $description = "Provide a number of links useful for administering a blog. Only shown if the user is an admin."; function CommentText() { @@ -63,5 +53,4 @@ class BlogManagementWidget_Controller extends Widget_Controller { $container = BlogTree::current(); return ($container && $container->ClassName != "BlogTree") ? $container->Link('post') : false; } -} -?> +} \ No newline at end of file diff --git a/code/widgets/BlogTreeExtension.php b/code/widgets/BlogTreeExtension.php index 60b5820..f4ece8b 100644 --- a/code/widgets/BlogTreeExtension.php +++ b/code/widgets/BlogTreeExtension.php @@ -2,6 +2,6 @@ class BlogTreeExtension extends DataExtension { - static $has_one = array("SideBar" => "WidgetArea"); + private static $has_one = array("SideBar" => "WidgetArea"); } \ No newline at end of file diff --git a/code/widgets/RSSWidget.php b/code/widgets/RSSWidget.php index 19f9966..acb4be5 100644 --- a/code/widgets/RSSWidget.php +++ b/code/widgets/RSSWidget.php @@ -1,26 +1,20 @@ "Text", "RssUrl" => "Text", "NumberToShow" => "Int" ); - static $has_one = array(); - - static $has_many = array(); - - static $many_many = array(); - - static $belongs_many_many = array(); - - static $defaults = array( + private static $defaults = array( "NumberToShow" => 10, "RSSTitle" => 'RSS Feed' ); - static $cmsTitle = "RSS Feed"; - static $description = "Downloads another page's RSS feed and displays items in a list."; + + private static $cmsTitle = "RSS Feed"; + + private static $description = "Downloads another page's RSS feed and displays items in a list."; /** * If the RssUrl is relative, convert it to absolute with the @@ -91,6 +85,4 @@ class RSSWidget extends Widget { return $output; } } -} - -?> +} \ No newline at end of file diff --git a/code/widgets/SubscribeRSSWidget.php b/code/widgets/SubscribeRSSWidget.php index e75bdec..a42a668 100644 --- a/code/widgets/SubscribeRSSWidget.php +++ b/code/widgets/SubscribeRSSWidget.php @@ -9,11 +9,11 @@ */ class SubscribeRSSWidget extends Widget { - static $title = 'Subscribe via RSS'; + private static $title = 'Subscribe via RSS'; - static $cmsTitle = 'Subscribe via RSS widget'; + private static $cmsTitle = 'Subscribe via RSS widget'; - static $description = 'Shows a link allowing a user to subscribe to this blog via RSS.'; + private static $description = 'Shows a link allowing a user to subscribe to this blog via RSS.'; /** * Return an absolute URL based on the BlogHolder @@ -26,6 +26,4 @@ class SubscribeRSSWidget extends Widget { $container = BlogTree::current(); if ($container) return $container->Link('rss'); } -} - -?> +} \ No newline at end of file diff --git a/code/widgets/TagCloudWidget.php b/code/widgets/TagCloudWidget.php index f52435e..53fa924 100644 --- a/code/widgets/TagCloudWidget.php +++ b/code/widgets/TagCloudWidget.php @@ -1,28 +1,22 @@ "Varchar", "Limit" => "Int", "Sortby" => "Varchar" ); - static $has_one = array(); - - static $has_many = array(); - - static $many_many = array(); - - static $belongs_many_many = array(); - - static $defaults = array( + private static $defaults = array( "Title" => "Tag Cloud", "Limit" => "0", "Sortby" => "alphabet" ); - static $cmsTitle = "Tag Cloud"; - static $description = "Shows a tag cloud of tags on your blog."; + private static $cmsTitle = "Tag Cloud"; + + private static $description = "Shows a tag cloud of tags on your blog."; static $popularities = array( 'not-popular', 'not-very-popular', 'somewhat-popular', 'popular', 'very-popular', 'ultra-popular' ); @@ -144,7 +138,4 @@ class TagCloudWidget extends Widget { return true; } -} - - -?> +} \ No newline at end of file diff --git a/tests/BlogHolderTest.php b/tests/BlogHolderTest.php index 00dcb1f..8b36301 100644 --- a/tests/BlogHolderTest.php +++ b/tests/BlogHolderTest.php @@ -73,5 +73,3 @@ class BlogHolderTest extends SapphireTest { } } - -?> diff --git a/tests/BlogTreeTest.php b/tests/BlogTreeTest.php index 7ba88a5..6c14845 100644 --- a/tests/BlogTreeTest.php +++ b/tests/BlogTreeTest.php @@ -104,5 +104,3 @@ class BlogTreeTest extends SapphireTest { } } - -?> diff --git a/thirdparty/xmlrpc/xmlrpc.php b/thirdparty/xmlrpc/xmlrpc.php index 8eb8d79..8695139 100644 --- a/thirdparty/xmlrpc/xmlrpc.php +++ b/thirdparty/xmlrpc/xmlrpc.php @@ -3773,5 +3773,3 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha return false; } } - -?> \ No newline at end of file diff --git a/thirdparty/xmlrpc/xmlrpc_wrappers.php b/thirdparty/xmlrpc/xmlrpc_wrappers.php index 1a663f0..aa90f7e 100644 --- a/thirdparty/xmlrpc/xmlrpc_wrappers.php +++ b/thirdparty/xmlrpc/xmlrpc_wrappers.php @@ -952,4 +952,3 @@ //$code .= "\$client->setDebug(\$debug);\n"; return $code; } -?> \ No newline at end of file diff --git a/thirdparty/xmlrpc/xmlrpcs.php b/thirdparty/xmlrpc/xmlrpcs.php index 441dc3d..cc1d596 100644 --- a/thirdparty/xmlrpc/xmlrpcs.php +++ b/thirdparty/xmlrpc/xmlrpcs.php @@ -1243,4 +1243,3 @@ print $r->serialize(); } } -?> \ No newline at end of file