Merge pull request #97 from tractorcow/blog-archive-housekeeping

BUG / Housekeeping of Widget code
This commit is contained in:
Will Rossiter 2013-08-14 23:33:19 -07:00
commit ba89364eb8
5 changed files with 206 additions and 201 deletions

View File

@ -1,5 +1,7 @@
<?php <?php
if(class_exists('Widget')) { if(class_exists('Widget')) {
/** /**
* Shows a widget with viewing blog entries * Shows a widget with viewing blog entries
* by months or years. * by months or years.
@ -7,18 +9,11 @@ if(class_exists('Widget')) {
* @package blog * @package blog
*/ */
class ArchiveWidget extends Widget { class ArchiveWidget extends Widget {
private static $db = array( private static $db = array(
'DisplayMode' => 'Varchar' 'DisplayMode' => 'Varchar'
); );
private static $has_one = array();
private static $has_many = array();
private static $many_many = array();
private static $belongs_many_many = array();
private static $defaults = array( private static $defaults = array(
'DisplayMode' => 'month' 'DisplayMode' => 'month'
); );
@ -27,7 +22,8 @@ if(class_exists('Widget')) {
private static $cmsTitle = 'Blog Archive'; private static $cmsTitle = 'Blog Archive';
private 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() { function getCMSFields() {
$fields = parent::getCMSFields(); $fields = parent::getCMSFields();
@ -61,20 +57,29 @@ if(class_exists('Widget')) {
$stage = Versioned::current_stage(); $stage = Versioned::current_stage();
$suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage"; $suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage";
$monthclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%m') : 'MONTH("Date")'; if(method_exists(DB::getConn(), 'formattedDatetimeClause')) {
$yearclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%Y') : 'YEAR("Date")'; $monthclause = DB::getConn()->formattedDatetimeClause('"Date"', '%m');
$yearclause = DB::getConn()->formattedDatetimeClause('"Date"', '%Y');
} else {
$monthclause = 'MONTH("Date")';
$yearclause = 'YEAR("Date")';
}
if($this->DisplayMode == 'month') { if($this->DisplayMode == 'month') {
$sqlResults = DB::query(" $sqlResults = DB::query("
SELECT DISTINCT CAST($monthclause AS " . DB::getConn()->dbDataType('unsigned integer') . ") AS \"Month\", $yearclause AS \"Year\" SELECT DISTINCT CAST($monthclause AS " . DB::getConn()->dbDataType('unsigned integer') . ")
FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\" ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\" AS \"Month\",
$yearclause AS \"Year\"
FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\"
ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\"
WHERE \"ParentID\" IN (" . implode(', ', $ids) . ") WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
ORDER BY \"Year\" DESC, \"Month\" DESC;" ORDER BY \"Year\" DESC, \"Month\" DESC;"
); );
} else { } else {
$sqlResults = DB::query(" $sqlResults = DB::query("
SELECT DISTINCT $yearclause AS \"Year\" SELECT DISTINCT $yearclause AS \"Year\"
FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\" ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\" FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\"
ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\"
WHERE \"ParentID\" IN (" . implode(', ', $ids) . ") WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
ORDER BY \"Year\" DESC" ORDER BY \"Year\" DESC"
); );

View File

@ -1,26 +1,20 @@
<?php <?php
if(class_exists('Widget')) { if(class_exists('Widget')) {
/** /**
* Blog Management Widget * Blog Management Widget
*
* @package blog * @package blog
*/ */
class BlogManagementWidget extends Widget { class BlogManagementWidget extends Widget {
private static $db = array();
private static $has_one = array();
private static $has_many = array();
private static $many_many = array();
private static $belongs_many_many = array();
private static $defaults = array();
private static $title = "Blog Management"; private static $title = "Blog Management";
private static $cmsTitle = "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.";
private static $description =
"Provide a number of links useful for administering a blog. Only shown if the user is an admin.";
function CommentText() { function CommentText() {

View File

@ -1,25 +1,27 @@
<?php <?php
if(class_exists('Widget')) {
if (class_exists('Widget')) {
/**
* Presents a list of items from an RSS feed url
*
* @package blog
*/
class RSSWidget extends Widget { class RSSWidget extends Widget {
private static $db = array( private static $db = array(
"RSSTitle" => "Text", "RSSTitle" => "Text",
"RssUrl" => "Text", "RssUrl" => "Text",
"NumberToShow" => "Int" "NumberToShow" => "Int"
); );
private static $has_one = array();
private static $has_many = array();
private static $many_many = array();
private static $belongs_many_many = array();
private static $defaults = array( private static $defaults = array(
"NumberToShow" => 10, "NumberToShow" => 10,
"RSSTitle" => 'RSS Feed' "RSSTitle" => 'RSS Feed'
); );
private static $cmsTitle = "RSS Feed"; private static $cmsTitle = "RSS Feed";
private static $description = "Downloads another page's RSS feed and displays items in a list."; private static $description = "Downloads another page's RSS feed and displays items in a list.";
/** /**
@ -45,7 +47,10 @@ if(class_exists('Widget')) {
$fields->merge( $fields->merge(
new FieldList( new FieldList(
new TextField("RSSTitle", _t('RSSWidget.CT', "Custom title for the feed")), new TextField("RSSTitle", _t('RSSWidget.CT', "Custom title for the feed")),
new TextField("RssUrl", _t('RSSWidget.URL', "URL of the other page's RSS feed. Please make sure this URL points to an RSS feed.")), new TextField("RssUrl", _t(
'RSSWidget.URL',
"URL of the other page's RSS feed. Please make sure this URL points to an RSS feed."
)),
new NumericField("NumberToShow", _t('RSSWidget.NTS', "Number of Items to show")) new NumericField("NumberToShow", _t('RSSWidget.NTS', "Number of Items to show"))
) )
); );
@ -54,8 +59,9 @@ if(class_exists('Widget')) {
return $fields; return $fields;
} }
function Title() { function Title() {
return ($this->RSSTitle) ? $this->RSSTitle : 'RSS Feed'; return ($this->RSSTitle) ? $this->RSSTitle : _t('RSSWidget.DEFAULTTITLE', 'RSS Feed');
} }
function getFeedItems() { function getFeedItems() {

View File

@ -1,5 +1,7 @@
<?php <?php
if(class_exists('Widget')) { if(class_exists('Widget')) {
/** /**
* A simple widget that just shows a link * A simple widget that just shows a link
* to this website's blog RSS, with an RSS * to this website's blog RSS, with an RSS

View File

@ -1,20 +1,20 @@
<?php <?php
class TagCloudWidget extends Widget { if(class_exists('Widget')) {
/**
* A list of tags associated with blog posts
*
* @package blog
*/
class TagCloudWidget extends Widget {
private static $db = array( private static $db = array(
"Title" => "Varchar", "Title" => "Varchar",
"Limit" => "Int", "Limit" => "Int",
"Sortby" => "Varchar" "Sortby" => "Varchar"
); );
private static $has_one = array();
private static $has_many = array();
private static $many_many = array();
private static $belongs_many_many = array();
private static $defaults = array( private static $defaults = array(
"Title" => "Tag Cloud", "Title" => "Tag Cloud",
"Limit" => "0", "Limit" => "0",
@ -44,7 +44,7 @@ class TagCloudWidget extends Widget {
} }
function Title() { function Title() {
return $this->Title ? $this->Title : 'Tag Cloud'; return $this->Title ? $this->Title : _t('TagCloudWidget.DEFAULTTITLE', 'Tag Cloud');
} }
function getTagsCollection() { function getTagsCollection() {
@ -144,7 +144,5 @@ class TagCloudWidget extends Widget {
return true; return true;
} }
}
} }
?>