mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 09:05:58 +00:00
Merge remote-tracking branch 'origin/0.6'
Conflicts: .travis.yml README.md _config.php code/BlogHolder.php code/BlogTree.php code/widgets/ArchiveWidget.php code/widgets/BlogManagementWidget.php code/widgets/BlogTreeExtension.php code/widgets/RSSWidget.php code/widgets/SubscribeRSSWidget.php composer.json
This commit is contained in:
commit
e33881615d
14
README.md
14
README.md
@ -78,8 +78,20 @@ See [:pagecomment](/pagecomment) for creating Askimet-protected comments for eve
|
||||
|
||||
## Widgets
|
||||
|
||||
See [widgets](/widgets)
|
||||
The module comes with a couple of default widgets, which rely on the "silverstripe/widgets"
|
||||
module being installed. Since widgets are based on database records and relations
|
||||
to pages, they need to be enabled through an `Extension` class in your `config.yml`:
|
||||
|
||||
:::yml
|
||||
BlogTree:
|
||||
extensions:
|
||||
- WidgetPageExtension
|
||||
BlogEntry:
|
||||
extensions:
|
||||
- WidgetPageExtension
|
||||
|
||||
Alternatively, you can simply enable the extension on your `Page` records
|
||||
to have it available globally.
|
||||
|
||||
## Working with the theme
|
||||
|
||||
|
@ -1,3 +0,0 @@
|
||||
<?php
|
||||
|
||||
if(class_exists('WidgetArea')) BlogTree::add_extension('BlogTreeExtension');
|
@ -108,16 +108,6 @@ class BlogEntry extends Page {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sidebar from the BlogHolder.
|
||||
*/
|
||||
function SideBar() {
|
||||
if(method_exists($this->Parent(), 'SideBar')) {
|
||||
return $this->getParent()->SideBar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function Content() {
|
||||
if(self::$allow_wysiwyg_editing) {
|
||||
return $this->getField('Content');
|
||||
|
@ -49,7 +49,12 @@ class BlogHolder extends BlogTree implements PermissionProvider {
|
||||
"Content"
|
||||
);
|
||||
$fields->addFieldToTab('Root.Main', new CheckboxField('AllowCustomAuthors', 'Allow non-admins to have a custom author field'), "Content");
|
||||
$fields->addFieldToTab("Root.Main", new CheckboxField("ShowFullEntry", "Show Full Entry"), "Content");
|
||||
$fields->addFieldToTab(
|
||||
"Root.Main",
|
||||
CheckboxField::create("ShowFullEntry", "Show Full Entry")
|
||||
->setDescription('Show full content in overviews rather than summary'),
|
||||
"Content"
|
||||
);
|
||||
|
||||
$this->extend('updateCMSFields', $fields);
|
||||
|
||||
@ -123,39 +128,45 @@ class BlogHolder extends BlogTree implements PermissionProvider {
|
||||
$blogholder->Title = "Blog";
|
||||
$blogholder->URLSegment = "blog";
|
||||
$blogholder->Status = "Published";
|
||||
$blogholder->write();
|
||||
$blogholder->publish("Stage", "Live");
|
||||
|
||||
// Add default widgets to first found WidgetArea relationship
|
||||
if(class_exists('WidgetArea')) {
|
||||
$widgetarea = new WidgetArea();
|
||||
$widgetarea->write();
|
||||
foreach($this->has_one() as $name => $class) {
|
||||
if(is_a($class, 'WidgetArea', true)) {
|
||||
$relationName = "{$name}ID";
|
||||
$widgetarea = new WidgetArea();
|
||||
$widgetarea->write();
|
||||
|
||||
$blogholder->SideBarID = $widgetarea->ID;
|
||||
$blogholder->write();
|
||||
$blogholder->publish("Stage", "Live");
|
||||
$blogholder->$relationName = $widgetarea->ID;
|
||||
$blogholder->write();
|
||||
$blogholder->publish("Stage", "Live");
|
||||
|
||||
$managementwidget = new BlogManagementWidget();
|
||||
$managementwidget->ParentID = $widgetarea->ID;
|
||||
$managementwidget->write();
|
||||
$managementwidget = new BlogManagementWidget();
|
||||
$managementwidget->ParentID = $widgetarea->ID;
|
||||
$managementwidget->write();
|
||||
|
||||
$tagcloudwidget = new TagCloudWidget();
|
||||
$tagcloudwidget->ParentID = $widgetarea->ID;
|
||||
$tagcloudwidget->write();
|
||||
$tagcloudwidget = new TagCloudWidget();
|
||||
$tagcloudwidget->ParentID = $widgetarea->ID;
|
||||
$tagcloudwidget->write();
|
||||
|
||||
$archivewidget = new ArchiveWidget();
|
||||
$archivewidget->ParentID = $widgetarea->ID;
|
||||
$archivewidget->write();
|
||||
$archivewidget = new ArchiveWidget();
|
||||
$archivewidget->ParentID = $widgetarea->ID;
|
||||
$archivewidget->write();
|
||||
|
||||
$widgetarea->write();
|
||||
} else {
|
||||
$blogholder->write();
|
||||
$blogholder->publish("Stage", "Live");
|
||||
}
|
||||
|
||||
$widgetarea->write();
|
||||
|
||||
break; // only apply to one
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$blog = new BlogEntry();
|
||||
$blog->Title = _t('BlogHolder.SUCTITLE', "SilverStripe blog module successfully installed");
|
||||
$blog->URLSegment = 'sample-blog-entry';
|
||||
$blog->Tags = _t('BlogHolder.SUCTAGS',"silverstripe, blog");
|
||||
$blog->Content = _t('BlogHolder.SUCCONTENT',"<p>Congratulations, the SilverStripe blog module has been successfully installed. This blog entry can be safely deleted. You can configure aspects of your blog (such as the widgets displayed in the sidebar) in <a href=\"admin\">the CMS</a>.</p>");
|
||||
$blog->Content = _t('BlogHolder.SUCCONTENT',"<p>Congratulations, the SilverStripe blog module has been successfully installed. This blog entry can be safely deleted. You can configure aspects of your blog in <a href=\"admin\">the CMS</a>.</p>");
|
||||
$blog->Status = "Published";
|
||||
$blog->ParentID = $blogholder->ID;
|
||||
$blog->write();
|
||||
@ -164,6 +175,10 @@ class BlogHolder extends BlogTree implements PermissionProvider {
|
||||
DB::alteration_message("Blog page created","created");
|
||||
}
|
||||
}
|
||||
|
||||
function providePermissions() {
|
||||
return array("BLOGMANAGEMENT" => "Blog management");
|
||||
}
|
||||
}
|
||||
|
||||
class BlogHolder_Controller extends BlogTree_Controller {
|
||||
@ -190,10 +205,6 @@ class BlogHolder_Controller extends BlogTree_Controller {
|
||||
return BBCodeParser::usable_tags();
|
||||
}
|
||||
|
||||
function providePermissions() {
|
||||
return array("BLOGMANAGEMENT" => "Blog management");
|
||||
}
|
||||
|
||||
/**
|
||||
* Post a new blog entry
|
||||
*/
|
||||
@ -306,6 +317,3 @@ class BlogHolder_Controller extends BlogTree_Controller {
|
||||
$this->redirect($this->Link());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
@ -40,8 +40,6 @@ class BlogTree extends Page {
|
||||
'BlogTree', 'BlogHolder'
|
||||
);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Finds the BlogTree object most related to the current page.
|
||||
* - If this page is a BlogTree, use that
|
||||
@ -91,45 +89,35 @@ class BlogTree extends Page {
|
||||
return $freshness;
|
||||
}
|
||||
|
||||
function SideBar() {
|
||||
if($this->InheritSideBar && $this->getParent()) {
|
||||
if (method_exists($this->getParent(), 'SideBar')) return $this->getParent()->SideBar();
|
||||
}
|
||||
|
||||
if($this->SideBarID){
|
||||
return DataObject::get_by_id('WidgetArea', $this->SideBarID);
|
||||
// @todo: This segfaults - investigate why then fix: return $this->getComponent('SideBar');
|
||||
}
|
||||
}
|
||||
|
||||
/* ----------- CMS CONTROL -------------- */
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
function getSettingsFields() {
|
||||
$fields = parent::getSettingsFields();
|
||||
|
||||
$fields->addFieldToTab(
|
||||
'Root.Settings',
|
||||
new DropdownField(
|
||||
'LandingPageFreshness',
|
||||
'When you first open the blog, how many entries should I show',
|
||||
array(
|
||||
"" => "All entries",
|
||||
"1" => "Last month's entries",
|
||||
"2" => "Last 2 months' entries",
|
||||
"3" => "Last 3 months' entries",
|
||||
"4" => "Last 4 months' entries",
|
||||
"5" => "Last 5 months' entries",
|
||||
"6" => "Last 6 months' entries",
|
||||
"7" => "Last 7 months' entries",
|
||||
"8" => "Last 8 months' entries",
|
||||
"9" => "Last 9 months' entries",
|
||||
"10" => "Last 10 months' entries",
|
||||
"11" => "Last 11 months' entries",
|
||||
"12" => "Last year's entries",
|
||||
"INHERIT" => "Take value from parent Blog Tree"
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$fields->addFieldToTab("Root.Main", new TextField("Name", "Name of blog"), "Content");
|
||||
$fields->addFieldToTab('Root.Main', new DropdownField('LandingPageFreshness', 'When you first open the blog, how many entries should I show', array(
|
||||
"" => "All entries",
|
||||
"1" => "Last month's entries",
|
||||
"2" => "Last 2 months' entries",
|
||||
"3" => "Last 3 months' entries",
|
||||
"4" => "Last 4 months' entries",
|
||||
"5" => "Last 5 months' entries",
|
||||
"6" => "Last 6 months' entries",
|
||||
"7" => "Last 7 months' entries",
|
||||
"8" => "Last 8 months' entries",
|
||||
"9" => "Last 9 months' entries",
|
||||
"10" => "Last 10 months' entries",
|
||||
"11" => "Last 11 months' entries",
|
||||
"12" => "Last year's entries",
|
||||
"INHERIT" => "Take value from parent Blog Tree"
|
||||
)), "Content");
|
||||
if(class_exists('WidgetArea')) {
|
||||
$fields->addFieldToTab("Root.Widgets", new CheckboxField("InheritSideBar", 'Inherit Sidebar From Parent'));
|
||||
$fields->addFieldToTab("Root.Widgets", new WidgetAreaEditor("SideBar"));
|
||||
}
|
||||
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
@ -296,7 +284,7 @@ class BlogTree_Controller extends Page_Controller {
|
||||
function rss() {
|
||||
global $project_name;
|
||||
|
||||
$blogName = $this->Name;
|
||||
$blogName = $this->Title;
|
||||
$altBlogName = $project_name . ' blog';
|
||||
|
||||
$entries = $this->Entries(20);
|
||||
@ -326,7 +314,7 @@ class BlogTree_Controller extends Page_Controller {
|
||||
$tag = $this->request->latestParam('ID');
|
||||
$tag = urldecode($tag);
|
||||
return Convert::raw2xml($tag);
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
|
@ -1,111 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Shows a widget with viewing blog entries
|
||||
* by months or years.
|
||||
*
|
||||
* @package blog
|
||||
*/
|
||||
class ArchiveWidget extends Widget {
|
||||
if(class_exists('Widget')) {
|
||||
/**
|
||||
* Shows a widget with viewing blog entries
|
||||
* by months or years.
|
||||
*
|
||||
* @package blog
|
||||
*/
|
||||
class ArchiveWidget extends Widget {
|
||||
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(
|
||||
'DisplayMode' => 'month'
|
||||
);
|
||||
|
||||
'DisplayMode' => 'month'
|
||||
);
|
||||
|
||||
private static $title = 'Browse by Date';
|
||||
|
||||
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.';
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$fields->merge(
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$fields->merge(
|
||||
|
||||
new FieldList(
|
||||
new OptionsetField(
|
||||
'DisplayMode',
|
||||
_t('ArchiveWidget.DispBY', 'Display by'),
|
||||
array(
|
||||
'month' => _t('ArchiveWidget.MONTH', 'month'),
|
||||
'year' => _t('ArchiveWidget.YEAR', 'year')
|
||||
new FieldList(
|
||||
new OptionsetField(
|
||||
'DisplayMode',
|
||||
_t('ArchiveWidget.DispBY', 'Display by'),
|
||||
array(
|
||||
'month' => _t('ArchiveWidget.MONTH', 'month'),
|
||||
'year' => _t('ArchiveWidget.YEAR', 'year')
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$this->extend('updateCMSFields', $fields);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function getDates() {
|
||||
Requirements::themedCSS('archivewidget');
|
||||
|
||||
$results = new ArrayList();
|
||||
$container = BlogTree::current();
|
||||
$ids = $container->BlogHolderIDs();
|
||||
|
||||
$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($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\"
|
||||
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\"
|
||||
WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
|
||||
ORDER BY \"Year\" DESC"
|
||||
)
|
||||
);
|
||||
|
||||
$this->extend('updateCMSFields', $fields);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
if($sqlResults) foreach($sqlResults as $sqlResult) {
|
||||
$isMonthDisplay = $this->DisplayMode == 'month';
|
||||
function getDates() {
|
||||
Requirements::themedCSS('archivewidget');
|
||||
|
||||
$monthVal = (isset($sqlResult['Month'])) ? (int) $sqlResult['Month'] : 1;
|
||||
$month = ($isMonthDisplay) ? $monthVal : 1;
|
||||
$year = ($sqlResult['Year']) ? (int) $sqlResult['Year'] : date('Y');
|
||||
$results = new ArrayList();
|
||||
$container = BlogTree::current();
|
||||
$ids = $container->BlogHolderIDs();
|
||||
|
||||
$date = DBField::create_field('Date', array(
|
||||
'Day' => 1,
|
||||
'Month' => $month,
|
||||
'Year' => $year
|
||||
));
|
||||
$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($isMonthDisplay) {
|
||||
$link = $container->Link('date') . '/' . $sqlResult['Year'] . '/' . sprintf("%'02d", $monthVal);
|
||||
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\"
|
||||
WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
|
||||
ORDER BY \"Year\" DESC, \"Month\" DESC;"
|
||||
);
|
||||
} else {
|
||||
$link = $container->Link('date') . '/' . $sqlResult['Year'];
|
||||
$sqlResults = DB::query("
|
||||
SELECT DISTINCT $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"
|
||||
);
|
||||
}
|
||||
|
||||
$results->push(new ArrayData(array(
|
||||
'Date' => $date,
|
||||
'Link' => $link
|
||||
)));
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
if($sqlResults) foreach($sqlResults as $sqlResult) {
|
||||
$isMonthDisplay = $this->DisplayMode == 'month';
|
||||
|
||||
$monthVal = (isset($sqlResult['Month'])) ? (int) $sqlResult['Month'] : 1;
|
||||
$month = ($isMonthDisplay) ? $monthVal : 1;
|
||||
$year = ($sqlResult['Year']) ? (int) $sqlResult['Year'] : date('Y');
|
||||
|
||||
$date = DBField::create_field('Date', array(
|
||||
'Day' => 1,
|
||||
'Month' => $month,
|
||||
'Year' => $year
|
||||
));
|
||||
|
||||
if($isMonthDisplay) {
|
||||
$link = $container->Link('date') . '/' . $sqlResult['Year'] . '/' . sprintf("%'02d", $monthVal);
|
||||
} else {
|
||||
$link = $container->Link('date') . '/' . $sqlResult['Year'];
|
||||
}
|
||||
|
||||
$results->push(new ArrayData(array(
|
||||
'Date' => $date,
|
||||
'Link' => $link
|
||||
)));
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Blog Management Widget
|
||||
* @package blog
|
||||
*/
|
||||
class BlogManagementWidget extends Widget implements PermissionProvider {
|
||||
if(class_exists('Widget')) {
|
||||
|
||||
/**
|
||||
* Blog Management Widget
|
||||
* @package blog
|
||||
*/
|
||||
class BlogManagementWidget extends Widget {
|
||||
private static $db = array();
|
||||
|
||||
private static $has_one = array();
|
||||
@ -20,48 +22,45 @@ class BlogManagementWidget extends Widget implements PermissionProvider {
|
||||
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() {
|
||||
function CommentText() {
|
||||
|
||||
if(!class_exists('Comment')) return false;
|
||||
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM \"Comment\" WHERE \"Moderated\"=1")->value();
|
||||
if($unmoderatedcount == 1) {
|
||||
return _t("BlogManagementWidget.UNM1", "You have 1 unmoderated comment");
|
||||
} else if($unmoderatedcount > 1) {
|
||||
return sprintf(_t("BlogManagementWidget.UNMM", "You have %i unmoderated comments"), $unmoderatedcount);
|
||||
} else {
|
||||
return _t("BlogManagementWidget.COMADM", "Comment administration");
|
||||
if(!class_exists('Comment')) return false;
|
||||
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM \"Comment\" WHERE \"Moderated\"=1")->value();
|
||||
if($unmoderatedcount == 1) {
|
||||
return _t("BlogManagementWidget.UNM1", "You have 1 unmoderated comment");
|
||||
} else if($unmoderatedcount > 1) {
|
||||
return sprintf(_t("BlogManagementWidget.UNMM", "You have %i unmoderated comments"), $unmoderatedcount);
|
||||
} else {
|
||||
return _t("BlogManagementWidget.COMADM", "Comment administration");
|
||||
}
|
||||
}
|
||||
|
||||
function CommentLink() {
|
||||
|
||||
if(!Permission::check('BLOGMANAGEMENT') || !class_exists('Comment')) return false;
|
||||
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM \"Comment\" WHERE \"Moderated\"=1")->value();
|
||||
|
||||
if($unmoderatedcount > 0) {
|
||||
return "admin/comments/unmoderated";
|
||||
} else {
|
||||
return "admin/comments";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class BlogManagementWidget_Controller extends Widget_Controller {
|
||||
|
||||
function WidgetHolder() {
|
||||
if(Permission::check("BLOGMANAGEMENT")) {
|
||||
return $this->renderWith("WidgetHolder");
|
||||
}
|
||||
}
|
||||
|
||||
function PostLink() {
|
||||
$container = BlogTree::current();
|
||||
return ($container && $container->ClassName != "BlogTree") ? $container->Link('post') : false;
|
||||
}
|
||||
}
|
||||
|
||||
function CommentLink() {
|
||||
|
||||
if(!Permission::check('BLOGMANAGEMENT') || !class_exists('Comment')) return false;
|
||||
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM \"Comment\" WHERE \"Moderated\"=1")->value();
|
||||
|
||||
if($unmoderatedcount > 0) {
|
||||
return "admin/comments/unmoderated";
|
||||
} else {
|
||||
return "admin/comments";
|
||||
}
|
||||
}
|
||||
|
||||
function providePermissions() {
|
||||
return array("BLOGMANAGEMENT" => "Blog management");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class BlogManagementWidget_Controller extends Widget_Controller {
|
||||
|
||||
function WidgetHolder() {
|
||||
if(Permission::check("BLOGMANAGEMENT")) {
|
||||
return $this->renderWith("WidgetHolder");
|
||||
}
|
||||
}
|
||||
|
||||
function PostLink() {
|
||||
$container = BlogTree::current();
|
||||
return ($container && $container->ClassName != "BlogTree") ? $container->Link('post') : false;
|
||||
}
|
||||
}
|
||||
?>
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
class BlogTreeExtension extends DataExtension {
|
||||
|
||||
private static $has_one = array("SideBar" => "WidgetArea");
|
||||
|
||||
}
|
@ -1,96 +1,96 @@
|
||||
<?php
|
||||
|
||||
class RSSWidget extends Widget {
|
||||
if(class_exists('Widget')) {
|
||||
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.";
|
||||
|
||||
/**
|
||||
* If the RssUrl is relative, convert it to absolute with the
|
||||
* current baseURL to avoid confusing simplepie.
|
||||
* Passing relative URLs to simplepie will result
|
||||
* in strange DNS lookups and request timeouts.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getAbsoluteRssUrl() {
|
||||
$urlParts = parse_url($this->RssUrl);
|
||||
if(!isset($urlParts['host']) || !$urlParts['host']) {
|
||||
return Director::absoluteBaseURL() . $this->RssUrl;
|
||||
} else {
|
||||
return $this->RssUrl;
|
||||
}
|
||||
}
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$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 NumericField("NumberToShow", _t('RSSWidget.NTS', "Number of Items to show"))
|
||||
)
|
||||
"RSSTitle" => "Text",
|
||||
"RssUrl" => "Text",
|
||||
"NumberToShow" => "Int"
|
||||
);
|
||||
|
||||
$this->extend('updateCMSFields', $fields);
|
||||
private static $has_one = array();
|
||||
|
||||
return $fields;
|
||||
}
|
||||
function Title() {
|
||||
return ($this->RSSTitle) ? $this->RSSTitle : 'RSS Feed';
|
||||
}
|
||||
|
||||
function getFeedItems() {
|
||||
$output = new ArrayList();
|
||||
|
||||
// Protection against infinite loops when an RSS widget pointing to this page is added to this page
|
||||
if(stristr($_SERVER['HTTP_USER_AGENT'], 'SimplePie')) {
|
||||
return $output;
|
||||
}
|
||||
private static $has_many = array();
|
||||
|
||||
include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/simplepie.inc'));
|
||||
private static $many_many = array();
|
||||
|
||||
$t1 = microtime(true);
|
||||
$feed = new SimplePie($this->AbsoluteRssUrl, TEMP_FOLDER);
|
||||
$feed->init();
|
||||
if($items = $feed->get_items(0, $this->NumberToShow)) {
|
||||
foreach($items as $item) {
|
||||
|
||||
// Cast the Date
|
||||
$date = new Date('Date');
|
||||
$date->setValue($item->get_date());
|
||||
|
||||
// Cast the Title
|
||||
$title = new Text('Title');
|
||||
$title->setValue($item->get_title());
|
||||
|
||||
$output->push(new ArrayData(array(
|
||||
'Title' => $title,
|
||||
'Date' => $date,
|
||||
'Link' => $item->get_link()
|
||||
)));
|
||||
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.";
|
||||
|
||||
/**
|
||||
* If the RssUrl is relative, convert it to absolute with the
|
||||
* current baseURL to avoid confusing simplepie.
|
||||
* Passing relative URLs to simplepie will result
|
||||
* in strange DNS lookups and request timeouts.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getAbsoluteRssUrl() {
|
||||
$urlParts = parse_url($this->RssUrl);
|
||||
if(!isset($urlParts['host']) || !$urlParts['host']) {
|
||||
return Director::absoluteBaseURL() . $this->RssUrl;
|
||||
} else {
|
||||
return $this->RssUrl;
|
||||
}
|
||||
}
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
|
||||
$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 NumericField("NumberToShow", _t('RSSWidget.NTS', "Number of Items to show"))
|
||||
)
|
||||
);
|
||||
|
||||
$this->extend('updateCMSFields', $fields);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
function Title() {
|
||||
return ($this->RSSTitle) ? $this->RSSTitle : 'RSS Feed';
|
||||
}
|
||||
|
||||
function getFeedItems() {
|
||||
$output = new ArrayList();
|
||||
|
||||
// Protection against infinite loops when an RSS widget pointing to this page is added to this page
|
||||
if(stristr($_SERVER['HTTP_USER_AGENT'], 'SimplePie')) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
include_once(Director::getAbsFile(SAPPHIRE_DIR . '/thirdparty/simplepie/simplepie.inc'));
|
||||
|
||||
$t1 = microtime(true);
|
||||
$feed = new SimplePie($this->AbsoluteRssUrl, TEMP_FOLDER);
|
||||
$feed->init();
|
||||
if($items = $feed->get_items(0, $this->NumberToShow)) {
|
||||
foreach($items as $item) {
|
||||
|
||||
// Cast the Date
|
||||
$date = new Date('Date');
|
||||
$date->setValue($item->get_date());
|
||||
|
||||
// Cast the Title
|
||||
$title = new Text('Title');
|
||||
$title->setValue($item->get_title());
|
||||
|
||||
$output->push(new ArrayData(array(
|
||||
'Title' => $title,
|
||||
'Date' => $date,
|
||||
'Link' => $item->get_link()
|
||||
)));
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
@ -1,31 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A simple widget that just shows a link
|
||||
* to this website's blog RSS, with an RSS
|
||||
* icon.
|
||||
*
|
||||
* @package blog
|
||||
*/
|
||||
class SubscribeRSSWidget extends Widget {
|
||||
|
||||
if(class_exists('Widget')) {
|
||||
/**
|
||||
* A simple widget that just shows a link
|
||||
* to this website's blog RSS, with an RSS
|
||||
* icon.
|
||||
*
|
||||
* @package blog
|
||||
*/
|
||||
class SubscribeRSSWidget extends Widget {
|
||||
|
||||
private static $title = 'Subscribe via RSS';
|
||||
|
||||
|
||||
private static $cmsTitle = 'Subscribe via RSS widget';
|
||||
|
||||
|
||||
private static $description = 'Shows a link allowing a user to subscribe to this blog via RSS.';
|
||||
|
||||
/**
|
||||
* Return an absolute URL based on the BlogHolder
|
||||
* that this widget is located on.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getRSSLink() {
|
||||
Requirements::themedCSS('subscribersswidget');
|
||||
$container = BlogTree::current();
|
||||
if ($container) return $container->Link('rss');
|
||||
/**
|
||||
* Return an absolute URL based on the BlogHolder
|
||||
* that this widget is located on.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getRSSLink() {
|
||||
Requirements::themedCSS('subscribersswidget');
|
||||
$container = BlogTree::current();
|
||||
if ($container) return $container->Link('rss');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
}
|
@ -19,4 +19,4 @@
|
||||
"silverstripe/cms": "~3.1",
|
||||
"silverstripe/widgets": "dev-master"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
div.flickrwidget {
|
||||
text-align: center;
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
<div id="Sidebar" class="typography">
|
||||
$SideBar
|
||||
</div>
|
||||
<% if SideBarView %>
|
||||
<div id="Sidebar" class="typography">
|
||||
$SideBarView
|
||||
</div>
|
||||
<% end_if %>
|
Loading…
x
Reference in New Issue
Block a user