BUG / Housekeeping of Widget code:
- TagCloudWidget not wrapped with if(class_exists('Widget')) check for dependency module - Default titles for RSS Widget and TagCloudWidget not being translated. - Fixed poor indentation, and excessive line length (scrutinizer errors) - Removal of several blank 'private static $relation = array()' that added no value - Missing PHPDoc for widget classes - Fixed missing EOL and removed closing ?> from php files for consistency
This commit is contained in:
parent
a07694a2b7
commit
f4b51f0a0e
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
if(class_exists('Widget')) {
|
||||
|
||||
/**
|
||||
* Shows a widget with viewing blog entries
|
||||
* by months or years.
|
||||
|
@ -7,18 +9,11 @@ if(class_exists('Widget')) {
|
|||
* @package blog
|
||||
*/
|
||||
class ArchiveWidget extends Widget {
|
||||
|
||||
private static $db = array(
|
||||
'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(
|
||||
'DisplayMode' => 'month'
|
||||
);
|
||||
|
@ -27,7 +22,8 @@ if(class_exists('Widget')) {
|
|||
|
||||
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() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
@ -61,20 +57,29 @@ if(class_exists('Widget')) {
|
|||
$stage = Versioned::current_stage();
|
||||
$suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage";
|
||||
|
||||
$monthclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%m') : 'MONTH("Date")';
|
||||
$yearclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%Y') : 'YEAR("Date")';
|
||||
if(method_exists(DB::getConn(), 'formattedDatetimeClause')) {
|
||||
$monthclause = DB::getConn()->formattedDatetimeClause('"Date"', '%m');
|
||||
$yearclause = DB::getConn()->formattedDatetimeClause('"Date"', '%Y');
|
||||
} else {
|
||||
$monthclause = 'MONTH("Date")';
|
||||
$yearclause = 'YEAR("Date")';
|
||||
}
|
||||
|
||||
if($this->DisplayMode == 'month') {
|
||||
$sqlResults = DB::query("
|
||||
SELECT DISTINCT CAST($monthclause AS " . DB::getConn()->dbDataType('unsigned integer') . ") AS \"Month\", $yearclause AS \"Year\"
|
||||
FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\" ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\"
|
||||
SELECT DISTINCT CAST($monthclause AS " . DB::getConn()->dbDataType('unsigned integer') . ")
|
||||
AS \"Month\",
|
||||
$yearclause AS \"Year\"
|
||||
FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\"
|
||||
ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\"
|
||||
WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
|
||||
ORDER BY \"Year\" DESC, \"Month\" DESC;"
|
||||
);
|
||||
} else {
|
||||
$sqlResults = DB::query("
|
||||
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) . ")
|
||||
ORDER BY \"Year\" DESC"
|
||||
);
|
||||
|
|
|
@ -1,26 +1,20 @@
|
|||
<?php
|
||||
|
||||
if(class_exists('Widget')) {
|
||||
|
||||
/**
|
||||
* Blog Management Widget
|
||||
*
|
||||
* @package blog
|
||||
*/
|
||||
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 $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() {
|
||||
|
||||
|
|
|
@ -1,25 +1,27 @@
|
|||
<?php
|
||||
|
||||
if (class_exists('Widget')) {
|
||||
|
||||
/**
|
||||
* Presents a list of items from an RSS feed url
|
||||
*
|
||||
* @package blog
|
||||
*/
|
||||
class RSSWidget extends Widget {
|
||||
|
||||
private static $db = array(
|
||||
"RSSTitle" => "Text",
|
||||
"RssUrl" => "Text",
|
||||
"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(
|
||||
"NumberToShow" => 10,
|
||||
"RSSTitle" => 'RSS Feed'
|
||||
);
|
||||
|
||||
private static $cmsTitle = "RSS Feed";
|
||||
|
||||
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(
|
||||
new FieldList(
|
||||
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"))
|
||||
)
|
||||
);
|
||||
|
@ -54,8 +59,9 @@ if(class_exists('Widget')) {
|
|||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function Title() {
|
||||
return ($this->RSSTitle) ? $this->RSSTitle : 'RSS Feed';
|
||||
return ($this->RSSTitle) ? $this->RSSTitle : _t('RSSWidget.DEFAULTTITLE', 'RSS Feed');
|
||||
}
|
||||
|
||||
function getFeedItems() {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
if(class_exists('Widget')) {
|
||||
|
||||
/**
|
||||
* A simple widget that just shows a link
|
||||
* to this website's blog RSS, with an RSS
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
<?php
|
||||
|
||||
if(class_exists('Widget')) {
|
||||
|
||||
/**
|
||||
* A list of tags associated with blog posts
|
||||
*
|
||||
* @package blog
|
||||
*/
|
||||
class TagCloudWidget extends Widget {
|
||||
|
||||
private static $db = array(
|
||||
"Title" => "Varchar",
|
||||
"Limit" => "Int",
|
||||
"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(
|
||||
"Title" => "Tag Cloud",
|
||||
"Limit" => "0",
|
||||
|
@ -44,7 +44,7 @@ class TagCloudWidget extends Widget {
|
|||
}
|
||||
|
||||
function Title() {
|
||||
return $this->Title ? $this->Title : 'Tag Cloud';
|
||||
return $this->Title ? $this->Title : _t('TagCloudWidget.DEFAULTTITLE', 'Tag Cloud');
|
||||
}
|
||||
|
||||
function getTagsCollection() {
|
||||
|
@ -145,6 +145,4 @@ class TagCloudWidget extends Widget {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue