APICHANGE: Drop 2.3 support - 0.3 will be 2.4 only
This commit is contained in:
parent
a2b9e2f00c
commit
10d15e1ddd
|
@ -6,10 +6,10 @@
|
|||
* @package blog
|
||||
*/
|
||||
class ArchiveWidget extends Widget {
|
||||
|
||||
static $db = array(
|
||||
'DisplayMode' => 'Varchar'
|
||||
);
|
||||
|
||||
static $has_one = array();
|
||||
|
||||
static $has_many = array();
|
||||
|
@ -52,37 +52,19 @@ class ArchiveWidget extends Widget {
|
|||
$suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage";
|
||||
|
||||
if($this->DisplayMode == 'month') {
|
||||
if(defined('DB::USE_ANSI_SQL')) {
|
||||
$sqlResults = DB::query("
|
||||
SELECT DISTINCT MONTH(\"Date\") AS \"Month\", YEAR(\"Date\") 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 MONTH(`Date`) AS `Month`, YEAR(`Date`) AS `Year`
|
||||
FROM `SiteTree$suffix` NATURAL JOIN `BlogEntry$suffix`
|
||||
WHERE `ParentID` IN (" . implode(', ', $ids) . ")
|
||||
ORDER BY `Year` DESC, `Month` DESC;"
|
||||
);
|
||||
}
|
||||
$sqlResults = DB::query("
|
||||
SELECT DISTINCT MONTH(\"Date\") AS \"Month\", YEAR(\"Date\") 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 {
|
||||
if(defined('DB::USE_ANSI_SQL')) {
|
||||
$sqlResults = DB::query("
|
||||
SELECT DISTINCT YEAR(\"Date\") 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"
|
||||
);
|
||||
} else {
|
||||
$sqlResults = DB::query("
|
||||
SELECT DISTINCT YEAR(`Date`) AS `Year`
|
||||
FROM `SiteTree$suffix` NATURAL JOIN `BlogEntry$suffix`
|
||||
WHERE `ParentID` in (".implode(', ',$ids).")
|
||||
ORDER BY `Year` DESC"
|
||||
);
|
||||
}
|
||||
$sqlResults = DB::query("
|
||||
SELECT DISTINCT YEAR(\"Date\") 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"
|
||||
);
|
||||
}
|
||||
|
||||
if($sqlResults) foreach($sqlResults as $sqlResult) {
|
||||
|
@ -111,6 +93,7 @@ class ArchiveWidget extends Widget {
|
|||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -5,19 +5,18 @@
|
|||
* @package blog
|
||||
*/
|
||||
class BlogEntry extends Page {
|
||||
|
||||
static $default_parent = 'BlogHolder';
|
||||
|
||||
static $can_be_root = false;
|
||||
|
||||
static $icon = "blog/images/blogpage";
|
||||
|
||||
static $db = array(
|
||||
"Date" => "Datetime",
|
||||
"Author" => "Text",
|
||||
"Tags" => "Text"
|
||||
);
|
||||
|
||||
static $default_parent = 'BlogHolder';
|
||||
|
||||
static $can_be_root = false;
|
||||
|
||||
static $icon = "blog/images/blogpage";
|
||||
|
||||
static $has_one = array();
|
||||
|
||||
static $has_many = array();
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
* 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";
|
||||
|
||||
static $db = array(
|
||||
|
@ -76,7 +75,6 @@ class BlogHolder extends BlogTree implements PermissionProvider {
|
|||
*/
|
||||
function IsOwner() {
|
||||
return (Permission::check('BLOGMANAGEMENT') || Permission::check('ADMIN'));
|
||||
//return Permission::check('ADMIN') || (Member::currentUserID() == $this->OwnerID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,20 +116,18 @@ class BlogHolder extends BlogTree implements PermissionProvider {
|
|||
$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',"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 [url=admin]the CMS[/url].");
|
||||
$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->Status = "Published";
|
||||
$blog->ParentID = $blogholder->ID;
|
||||
$blog->write();
|
||||
$blog->publish("Stage", "Live");
|
||||
|
||||
// 2.3/2.4 dual compatibility
|
||||
if(method_exists('DB', 'alteration_message')) DB::alteration_message("Blog page created","created");
|
||||
DB::alteration_message("Blog page created","created");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BlogHolder_Controller extends BlogTree_Controller {
|
||||
|
||||
static $allowed_actions = array(
|
||||
'index',
|
||||
'tag',
|
||||
|
@ -149,10 +145,10 @@ class BlogHolder_Controller extends BlogTree_Controller {
|
|||
* TODO: this is an urgent fix to work with archive link (e.g. page_url/2009/04). Replace this with something better.
|
||||
*/
|
||||
function checkAccessAction($action) {
|
||||
if (preg_match('/[0-9]{4}/', $action))
|
||||
{
|
||||
if(preg_match('/[0-9]{4}/', $action)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parent::checkAccessAction($action);
|
||||
}
|
||||
|
||||
|
@ -217,14 +213,15 @@ class BlogHolder_Controller extends BlogTree_Controller {
|
|||
} else {
|
||||
$tagfield = new TextField('Tags');
|
||||
}
|
||||
|
||||
$field = 'TextField';
|
||||
if(!$this->AllowCustomAuthors && !Permission::check('ADMIN')) {
|
||||
$field = 'ReadonlyField';
|
||||
}
|
||||
$fields = new FieldSet(
|
||||
new HiddenField("ID", "ID"),
|
||||
new TextField("Title",_t('BlogHolder.SJ', "Subject")),
|
||||
new $field("Author",_t('BlogEntry.AU'),$membername),
|
||||
new TextField("Title", _t('BlogHolder.SJ', "Subject")),
|
||||
new $field("Author", _t('BlogEntry.AU'), $membername),
|
||||
$contentfield,
|
||||
$tagfield,
|
||||
new LiteralField("Tagsnote"," <label id='tagsnote'>"._t('BlogHolder.TE', "For example: sport, personal, science fiction")."<br/>" .
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
* @package blog
|
||||
*/
|
||||
class BlogManagementWidget extends Widget implements PermissionProvider {
|
||||
|
||||
static $db = array();
|
||||
|
||||
static $has_one = array();
|
||||
|
@ -61,4 +60,4 @@ class BlogManagementWidget extends Widget implements PermissionProvider {
|
|||
}
|
||||
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -46,23 +46,18 @@ class BlogTree extends Page {
|
|||
if ($page instanceof BlogTree) return $page;
|
||||
|
||||
// Or, if we a a BlogEntry underneath a BlogTree, use our parent
|
||||
if ($page->is_a("BlogEntry")) {
|
||||
if($page->is_a("BlogEntry")) {
|
||||
$parent = $page->getParent();
|
||||
if ($parent instanceof BlogTree) return $parent;
|
||||
if($parent instanceof BlogTree) return $parent;
|
||||
}
|
||||
|
||||
// Try to find a top-level BlogTree
|
||||
if(defined('DB::USE_ANSI_SQL')) {
|
||||
$top = DataObject::get_one('BlogTree', "\"ParentID\" = '0'");
|
||||
} else {
|
||||
$top = DataObject::get_one('BlogTree', 'ParentID = 0');
|
||||
}
|
||||
|
||||
if ($top) return $top;
|
||||
$top = DataObject::get_one('BlogTree', "\"ParentID\" = '0'");
|
||||
if($top) return $top;
|
||||
|
||||
// Try to find any BlogTree that is not inside another BlogTree
|
||||
foreach(DataObject::get('BlogTree') as $tree) {
|
||||
if (!($tree->getParent() instanceof BlogTree)) return $tree;
|
||||
if(!($tree->getParent() instanceof BlogTree)) return $tree;
|
||||
}
|
||||
|
||||
// This shouldn't be possible, but assuming the above fails, just return anything you can get
|
||||
|
@ -81,7 +76,7 @@ class BlogTree extends Page {
|
|||
}
|
||||
|
||||
function SideBar() {
|
||||
if ($this->InheritSideBar && $this->getParent()) {
|
||||
if($this->InheritSideBar && $this->getParent()) {
|
||||
if (method_exists($this->getParent(), 'SideBar')) return $this->getParent()->SideBar();
|
||||
}
|
||||
|
||||
|
@ -124,12 +119,11 @@ class BlogTree extends Page {
|
|||
public function loadDescendantBlogHolderIDListInto(&$idList) {
|
||||
if ($children = $this->AllChildren()) {
|
||||
foreach($children as $child) {
|
||||
if (in_array($child->ID, $idList)) continue;
|
||||
if(in_array($child->ID, $idList)) continue;
|
||||
|
||||
if ($child instanceof BlogHolder) {
|
||||
if($child instanceof BlogHolder) {
|
||||
$idList[] = $child->ID;
|
||||
}
|
||||
else if ($child instanceof BlogTree) {
|
||||
} elseif($child instanceof BlogTree) {
|
||||
$child->loadDescendantBlogHolderIDListInto($idList);
|
||||
}
|
||||
}
|
||||
|
@ -155,72 +149,47 @@ class BlogTree extends Page {
|
|||
$tagCheck = '';
|
||||
$dateCheck = '';
|
||||
|
||||
if ($tag) {
|
||||
if($tag) {
|
||||
$SQL_tag = Convert::raw2sql($tag);
|
||||
if(defined('DB::USE_ANSI_SQL')) {
|
||||
$tagCheck = "AND \"BlogEntry\".\"Tags\" LIKE '%$SQL_tag%'";
|
||||
} else {
|
||||
$tagCheck = "AND `BlogEntry`.Tags LIKE '%$SQL_tag%'";
|
||||
}
|
||||
$tagCheck = "AND \"BlogEntry\".\"Tags\" LIKE '%$SQL_tag%'";
|
||||
}
|
||||
|
||||
if ($date) {
|
||||
if($date) {
|
||||
if(strpos($date, '-')) {
|
||||
$year = (int) substr($date, 0, strpos($date, '-'));
|
||||
$month = (int) substr($date, strpos($date, '-') + 1);
|
||||
|
||||
if($year && $month) {
|
||||
if(defined('DB::USE_ANSI_SQL')) {
|
||||
$dateCheck = "AND MONTH(\"BlogEntry\".\"Date\") = '$month' AND YEAR(\"BlogEntry\".\"Date\") = '$year'";
|
||||
} else {
|
||||
$dateCheck = "AND MONTH(`BlogEntry`.Date) = $month AND YEAR(`BlogEntry`.Date) = $year";
|
||||
}
|
||||
$dateCheck = "AND MONTH(\"BlogEntry\".\"Date\") = '$month' AND YEAR(\"BlogEntry\".\"Date\") = '$year'";
|
||||
}
|
||||
} else {
|
||||
$year = (int) $date;
|
||||
if($year) {
|
||||
if(defined('DB::USE_ANSI_SQL')) {
|
||||
$dateCheck = "AND YEAR(\"BlogEntry\".\"Date\") = '$year'";
|
||||
} else {
|
||||
$dateCheck = "AND YEAR(`BlogEntry`.Date) = $year";
|
||||
}
|
||||
$dateCheck = "AND YEAR(\"BlogEntry\".\"Date\") = '$year'";
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($this->LandingPageFreshness) {
|
||||
if(defined('DB::USE_ANSI_SQL')) {
|
||||
$dateCheck = "AND \"BlogEntry\".\"Date\" > NOW() - INTERVAL " . $this->LandingPageFreshness;
|
||||
} else {
|
||||
$dateCheck = "AND `BlogEntry`.Date > NOW() - INTERVAL " . $this->LandingPageFreshness;
|
||||
}
|
||||
} elseif ($this->LandingPageFreshness) {
|
||||
$dateCheck = "AND \"BlogEntry\".\"Date\" > NOW() - INTERVAL " . $this->LandingPageFreshness;
|
||||
}
|
||||
|
||||
// Build a list of all IDs for BlogHolders that are children of us
|
||||
$holderIDs = $this->BlogHolderIDs();
|
||||
|
||||
// If no BlogHolders, no BlogEntries. So return false
|
||||
if (empty($holderIDs)) return false;
|
||||
if(empty($holderIDs)) return false;
|
||||
|
||||
// Otherwise, do the actual query
|
||||
if(defined('DB::USE_ANSI_SQL')) {
|
||||
$where = '"ParentID" IN (' . implode(',', $holderIDs) . ") $tagCheck $dateCheck";
|
||||
} else {
|
||||
$where = 'ParentID IN (' . implode(',', $holderIDs) . ") $tagCheck $dateCheck";
|
||||
}
|
||||
$where = '"ParentID" IN (' . implode(',', $holderIDs) . ") $tagCheck $dateCheck";
|
||||
|
||||
if(defined('DB::USE_ANSI_SQL')) {
|
||||
$order = '"BlogEntry"."Date" DESC';
|
||||
} else {
|
||||
$order = '`BlogEntry`.`Date` DESC';
|
||||
}
|
||||
$order = '"BlogEntry"."Date" DESC';
|
||||
|
||||
// By specifying a callback, you can alter the SQL, or sort on something other than date.
|
||||
if ($retrieveCallback) return call_user_func($retrieveCallback, 'BlogEntry', $where, $limit, $order);
|
||||
if($retrieveCallback) return call_user_func($retrieveCallback, 'BlogEntry', $where, $limit, $order);
|
||||
else return DataObject::get('BlogEntry', $where, $order, '', $limit);
|
||||
}
|
||||
}
|
||||
|
||||
class BlogURL {
|
||||
class BlogTree_URL {
|
||||
static function tag() {
|
||||
if (Director::urlParam('Action') == 'tag') return Director::urlParam('ID');
|
||||
return '';
|
||||
|
@ -230,10 +199,9 @@ class BlogURL {
|
|||
$year = Director::urlParam('Action');
|
||||
$month = Director::urlParam('ID');
|
||||
|
||||
if ($month && is_numeric($month) && $month >= 1 && $month <= 12 && is_numeric($year)) {
|
||||
if($month && is_numeric($month) && $month >= 1 && $month <= 12 && is_numeric($year)) {
|
||||
return "$year-$month";
|
||||
}
|
||||
elseif (is_numeric($year)) {
|
||||
} elseif (is_numeric($year)) {
|
||||
return $year;
|
||||
}
|
||||
|
||||
|
@ -256,10 +224,10 @@ class BlogTree_Controller extends Page_Controller {
|
|||
}
|
||||
|
||||
function BlogEntries($limit = null) {
|
||||
if ($limit === null) $limit = BlogTree::$default_entries_limit;
|
||||
if($limit === null) $limit = BlogTree::$default_entries_limit;
|
||||
|
||||
$start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
|
||||
return $this->Entries("$start,$limit", BlogURL::tag(), BlogURL::date());
|
||||
return $this->Entries("$start,$limit", BlogTree_URL::tag(), BlogTree_URL::date());
|
||||
}
|
||||
|
||||
function IncludeBlogRSS() {
|
||||
|
@ -267,40 +235,6 @@ class BlogTree_Controller extends Page_Controller {
|
|||
RSSFeed::linkToFeed($this->Link() . "rss", _t('BlogHolder.RSSFEED',"RSS feed of these blogs"));
|
||||
}
|
||||
|
||||
/*
|
||||
* @todo: It doesn't look like these are used. Remove if no-one complains - Hamish
|
||||
|
||||
/**
|
||||
* Gets the archived blogs for a particular month or year, in the format /year/month/ eg: /2008/10/
|
||||
* /
|
||||
function showarchive() {
|
||||
$month = addslashes($this->urlParams['ID']);
|
||||
return array(
|
||||
"Children" => DataObject::get('SiteTree', "ParentID = $this->ID AND DATE_FORMAT(`BlogEntry`.`Date`, '%Y-%M') = '$month'"),
|
||||
);
|
||||
}
|
||||
|
||||
function ArchiveMonths() {
|
||||
$months = DB::query("SELECT DISTINCT DATE_FORMAT(`BlogEntry`.`Date`, '%M') AS `Month`, DATE_FORMAT(`BlogEntry`.`Date`, '%Y') AS `Year` FROM `BlogEntry` ORDER BY `BlogEntry`.`Date` DESC");
|
||||
$output = new DataObjectSet();
|
||||
foreach($months as $month) {
|
||||
$month['Link'] = $this->Link() . "showarchive/$month[Year]-$month[Month]";
|
||||
$output->push(new ArrayData($month));
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function tag() {
|
||||
if (Director::urlParam('Action') == 'tag') {
|
||||
return array(
|
||||
'Tag' => Convert::raw2xml(Director::urlParam('ID'))
|
||||
);
|
||||
}
|
||||
return array();
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get the rss feed for this blog holder's entries
|
||||
*/
|
||||
|
@ -325,3 +259,5 @@ class BlogTree_Controller extends Page_Controller {
|
|||
return parent::defaultAction($action);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -6,6 +6,7 @@ class RSSWidget extends Widget {
|
|||
"RssUrl" => "Text",
|
||||
"NumberToShow" => "Int"
|
||||
);
|
||||
|
||||
static $has_one = array();
|
||||
|
||||
static $has_many = array();
|
||||
|
|
|
@ -26,7 +26,6 @@ class SubscribeRSSWidget extends Widget {
|
|||
$container = BlogTree::current();
|
||||
if ($container) return $container->Link() . 'rss';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -101,7 +101,8 @@ class TagCloudWidget extends Widget {
|
|||
foreach($allTags as $tag => $fields) {
|
||||
$output->push(new ArrayData($fields));
|
||||
}
|
||||
return $output;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -137,5 +138,4 @@ class TagCloudWidget extends Widget {
|
|||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
|
|
@ -49,5 +49,4 @@ class TrackBackDecorator extends DataObjectDecorator {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue