Move blog to open source path
This commit is contained in:
commit
bbd2815316
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
/*
|
||||
* Created on 9/07/2007
|
||||
*
|
||||
* To change the template for this generated file go to
|
||||
* Window - Preferences - PHPeclipse - PHP - Code Templates
|
||||
*/
|
||||
?>
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
class ArchiveWidget extends Widget {
|
||||
static $db = array(
|
||||
"DisplayMode" => "Varchar"
|
||||
);
|
||||
|
||||
static $defaults = array(
|
||||
"DisplayMode" => "month"
|
||||
);
|
||||
|
||||
static $title = "Archive";
|
||||
static $cmsTitle = "Blog Archive";
|
||||
static $description = "Show a list of months or years in which there are blog posts, and provide links to them.";
|
||||
|
||||
function getBlogHolder() {
|
||||
$page = Director::currentPage();
|
||||
|
||||
if($page->is_a("BlogHolder")) {
|
||||
return $page;
|
||||
} else if($page->is_a("BlogEntry") && $page->getParent()->is_a("BlogHolder")) {
|
||||
return $page->getParent();
|
||||
} else {
|
||||
return DataObject::get_one("BlogHolder");
|
||||
}
|
||||
}
|
||||
|
||||
function getCMSFields() {
|
||||
return new FieldSet(
|
||||
new OptionsetField("DisplayMode","Display by",array("month"=>"month","year"=>"year"))
|
||||
);
|
||||
}
|
||||
|
||||
function Dates() {
|
||||
Requirements::css("blog/css/archivewidget.css");
|
||||
$results = new DataObjectSet();
|
||||
$blogHolder = $this->getBlogHolder();
|
||||
$id = $blogHolder->ID;
|
||||
|
||||
if($this->DisplayMode == "month"){
|
||||
$sqlResults = DB::query("SELECT DISTINCT MONTH(`Date`) AS `Month`, YEAR(`Date`) AS `Year` FROM `SiteTree` NATURAL JOIN `BlogEntry` WHERE `ParentID` = $id ORDER BY `Date` DESC");
|
||||
}else{
|
||||
$sqlResults = DB::query("SELECT DISTINCT YEAR(`Date`) AS `Year` FROM `SiteTree` NATURAL JOIN `BlogEntry` WHERE `ParentID` = $id ORDER BY `Date` DESC");
|
||||
}
|
||||
|
||||
|
||||
|
||||
foreach($sqlResults as $sqlResult) {
|
||||
$date = new Date("Date");
|
||||
|
||||
|
||||
|
||||
$month = ($this->DisplayMode == "month") ? (int)$sqlResult['Month'] : 1;
|
||||
|
||||
$date->setValue(array(
|
||||
"Day" => 1,
|
||||
"Month" => $month,
|
||||
"Year" => (int)$sqlResult['Year']
|
||||
));
|
||||
|
||||
if($this->DisplayMode == "month"){
|
||||
$link = $blogHolder->Link() . $sqlResult['Year']. '/' . sprintf("%'02d", $sqlResult['Month']);
|
||||
}
|
||||
else{
|
||||
$link = $blogHolder->Link() . $sqlResult['Year'];
|
||||
}
|
||||
|
||||
$results->push(new ArrayData(array(
|
||||
"Date" => $date,
|
||||
"Link" => $link
|
||||
)));
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,132 @@
|
|||
<?
|
||||
|
||||
class BlogEntry extends Page {
|
||||
|
||||
static $default_parent = array('BlogHolder');
|
||||
|
||||
static $can_be_root = false;
|
||||
|
||||
static $icon = "blog/images/blogpage";
|
||||
|
||||
static $db = array(
|
||||
"Date" => "Datetime",
|
||||
"Author" => "Text",
|
||||
"Tags" => "Text"
|
||||
);
|
||||
|
||||
static $casting = array(
|
||||
"Date" => "Date"
|
||||
);
|
||||
|
||||
static $defaults = array(
|
||||
"ProvideComments" => true
|
||||
);
|
||||
|
||||
static $allowed_children = "none";
|
||||
|
||||
/**
|
||||
* overload so that the default date is today.
|
||||
*/
|
||||
public function populateDefaults(){
|
||||
parent::populateDefaults();
|
||||
$this->Date = date("d/m/Y H:i:s",time());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures the most recent article edited on the same day is shown first.
|
||||
*/
|
||||
public function setDate($val){
|
||||
$datepart = date("Y-m-d",strtotime($val));
|
||||
$minutepart = date("H:i:s",time());
|
||||
$date = $datepart . " " . $minutepart;
|
||||
return $this->setField("Date",$date);
|
||||
}
|
||||
|
||||
function getCMSFields() {
|
||||
Requirements::javascript('blog/javascript/bbcodehelp.js');
|
||||
Requirements::css('blog/css/bbcodehelp.css');
|
||||
$firstName = Member::CurrentMember() ? Member::currentMember()->FirstName : '';
|
||||
$codeparser = new BBCodeParser();
|
||||
|
||||
$fields = parent::getCMSFields();
|
||||
$fields->removeFieldFromTab("Root.Content.Main","Content");
|
||||
$fields->addFieldToTab("Root.Content.Main", new TextareaField("Content", "Content", 20));
|
||||
$fields->addFieldToTab("Root.Content.Main", new CalendarDateField("Date", "Date"),"Content");
|
||||
$fields->addFieldToTab("Root.Content.Main", new TextField("Author", "Author", $firstName),"Content");
|
||||
|
||||
$fields->addFieldToTab("Root.Content.Main", new LiteralField("BBCodeHelper", "<div id='BBCode' class='field'>" .
|
||||
"<a id=\"BBCodeHint\" target='new'>BBCode help</a>" .
|
||||
"<div id='BBTagsHolder' style='display:none;'>".$codeparser->useable_tagsHTML()."</div></div>"));
|
||||
|
||||
$fields->addFieldToTab("Root.Content.Main", new TextField("Tags", "Tags (comma sep.)"),"Content");
|
||||
return $fields;
|
||||
}
|
||||
|
||||
function Tags() {
|
||||
$theseTags = split(" *, *", trim($this->Tags));
|
||||
|
||||
$output = new DataObjectSet();
|
||||
foreach($theseTags as $tag) {
|
||||
$output->push(new ArrayData(array(
|
||||
"Tag" => $tag,
|
||||
"Link" => $this->getParent()->Link() . '?tag=' . urlencode($tag)
|
||||
)));
|
||||
}
|
||||
if($this->Tags){
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function SideBar() {
|
||||
return $this->getParent()->SideBar();
|
||||
}
|
||||
|
||||
function ParagraphSummary(){
|
||||
$content = new Text('Content');
|
||||
$content->value = Convert::raw2xml($this->Content);
|
||||
$parser = new BBCodeParser($content->FirstParagraph());
|
||||
return $parser->parse();
|
||||
}
|
||||
|
||||
function ParsedContent() {
|
||||
$parser = new BBCodeParser($this->Content);
|
||||
$content = new Text('Content');
|
||||
$content->value =$parser->parse();
|
||||
return $content;
|
||||
}
|
||||
|
||||
function EditURL(){
|
||||
return $this->getParent()->Link('post')."/".$this->ID."/";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class BlogEntry_Controller extends Page_Controller {
|
||||
function init() {
|
||||
parent::init();
|
||||
Requirements::themedCSS("blog");
|
||||
}
|
||||
|
||||
function unpublishPost(){
|
||||
if(!Permission::check('ADMIN')){
|
||||
Security::permissionFailure($this,
|
||||
"Unpublishing blogs is an administrator task. Please log in.");
|
||||
}
|
||||
else{
|
||||
$SQL_id = Convert::raw2sql($this->ID);
|
||||
|
||||
$page = DataObject::get_by_id("SiteTree", $SQL_id);
|
||||
$page->deleteFromStage('Live');
|
||||
$page->flushCache();
|
||||
|
||||
$page = DataObject::get_by_id("SiteTree", $SQL_id);
|
||||
$page->Status = "Unpublished";
|
||||
|
||||
Director::redirect($this->getParent()->Link());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,231 @@
|
|||
<?
|
||||
|
||||
class BlogHolder extends Page {
|
||||
|
||||
static $icon = "blog/images/blogholder";
|
||||
|
||||
static $db = array(
|
||||
);
|
||||
|
||||
static $has_one = array(
|
||||
"SideBar" => "WidgetArea"
|
||||
);
|
||||
|
||||
static $allowed_children = array(
|
||||
'BlogEntry'
|
||||
);
|
||||
|
||||
function getCMSFields() {
|
||||
$fields = parent::getCMSFields();
|
||||
$fields->removeFieldFromTab("Root.Content.Main","Content");
|
||||
$fields->addFieldToTab("Root.Content.Widgets", new WidgetAreaEditor("SideBar"));
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function BlogEntries($limit = 10) {
|
||||
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0;
|
||||
$tagCheck = '';
|
||||
$dateCheck = "";
|
||||
|
||||
if(isset($_GET['tag'])) {
|
||||
$tag = addslashes($_GET['tag']);
|
||||
$tag = str_replace(array("\\",'_','%',"'"), array("\\\\","\\_","\\%","\\'"), $tag);
|
||||
$tagCheck = "AND `BlogEntry`.Tags LIKE '%$tag%'";
|
||||
}
|
||||
|
||||
|
||||
if(Director::urlParams()){
|
||||
|
||||
$year = Director::urlParam('Action');
|
||||
$month = Director::urlParam('ID');
|
||||
|
||||
if(is_numeric($month) && is_numeric($month)){
|
||||
$dateCheck = "AND Date BETWEEN '$year-$month-1' AND '$year-$month-31'";
|
||||
}
|
||||
else if(isset($year)){
|
||||
$dateCheck = "AND Date BETWEEN '$year-1-1' AND '$year-12-31'";
|
||||
}
|
||||
}
|
||||
|
||||
return DataObject::get("Page","`ParentID` = $this->ID AND ShowInMenus = 1 $tagCheck $dateCheck","`BlogEntry`.Date DESC",'',"$start, $limit");
|
||||
}
|
||||
|
||||
function Tag() {
|
||||
return isset($_GET['tag']) ? $_GET['tag'] : false;
|
||||
}
|
||||
|
||||
function BlogEntryForm(){
|
||||
Requirements::javascript('jsparty/behaviour.js');
|
||||
Requirements::javascript('jsparty/prototype.js');
|
||||
Requirements::javascript('jsparty/scriptaculous/effects.js');
|
||||
Requirements::javascript('cms/javascript/PageCommentInterface.js');
|
||||
Requirements::javascript('blog/javascript/bbcodehelp.js');
|
||||
|
||||
$id = 0;
|
||||
if(Director::urlParam('ID')){
|
||||
$id = Director::urlParam('ID');
|
||||
}
|
||||
|
||||
$codeparser = new BBCodeParser();
|
||||
$membername = Member::currentMember() ? Member::currentMember()->getName() : "";
|
||||
|
||||
$fields = new FieldSet(
|
||||
new HiddenField("ParentID", "ParentID", $this->ID),
|
||||
new HiddenField("ID","ID"),
|
||||
new HiddenField("Date","Date"),
|
||||
new TextField("Title","Subject"),
|
||||
new TextField("Author","Author",$membername),
|
||||
new CompositeField(
|
||||
new LiteralField("BBCodeHelper","<a id=\"BBCodeHint\" target='new'>BBCode help</a><div class='clear'><!-- --></div>" ),
|
||||
new TextareaField("Content", "Content",20),
|
||||
new LiteralField("BBCodeTags","<div id='BBTagsHolder' style='display:none;'>".$codeparser->useable_tagsHTML()."</div>")
|
||||
),
|
||||
new TextField("Tags","Tags"),
|
||||
new LiteralField("Tagsnote"," <label id='tagsnote'>For example: sport, personal, science fiction<br/>" .
|
||||
"Please separate tags using commas.</label>")
|
||||
);
|
||||
|
||||
$submitAction = new FormAction('postblog', 'Post blog entry');
|
||||
$actions = new FieldSet($submitAction);
|
||||
$validator = new RequiredFields('Title','Content');
|
||||
|
||||
$form = new BlogEntry_Form($this, 'BlogEntryForm',$fields, $actions,$validator);
|
||||
|
||||
if($id != 0){
|
||||
$form->loadNonBlankDataFrom(DataObject::get_by_id('BlogEntry',$id));
|
||||
}else{
|
||||
$form->loadNonBlankDataFrom(array("Author" => Cookie::get("BlogHolder_Name")));
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function isPost(){
|
||||
return Director::urlParam('Action') == 'post';
|
||||
}
|
||||
|
||||
function postURL(){
|
||||
return $this->Link('post');
|
||||
}
|
||||
|
||||
function requireDefaultRecords() {
|
||||
parent::requireDefaultRecords();
|
||||
|
||||
if(!DataObject::get_one('BlogHolder')) {
|
||||
$blogholder = new BlogHolder();
|
||||
$blogholder->Title = "Blog";
|
||||
$blogholder->URLSegment = "blog";
|
||||
$blogholder->Status = "Published";
|
||||
|
||||
$widgetarea = new WidgetArea();
|
||||
$widgetarea->write();
|
||||
|
||||
$blogholder->SideBarID = $widgetarea->ID;
|
||||
$blogholder->write();
|
||||
$blogholder->publish("Stage", "Live");
|
||||
|
||||
$managementwidget = new BlogManagementWidget();
|
||||
$managementwidget->ParentID = $widgetarea->ID;
|
||||
$managementwidget->write();
|
||||
|
||||
$tagcloudwidget = new TagCloudWidget();
|
||||
$tagcloudwidget->ParentID = $widgetarea->ID;
|
||||
$tagcloudwidget->write();
|
||||
|
||||
$archivewidget = new ArchiveWidget();
|
||||
$archivewidget->ParentID = $widgetarea->ID;
|
||||
$archivewidget->write();
|
||||
|
||||
$widgetarea->write();
|
||||
|
||||
$blog = new BlogEntry();
|
||||
$blog->Title = "SilverStripe blog module successfully installed";
|
||||
$blog->URLSegment = 'sample-blog-entry';
|
||||
$blog->setDate(date("Y-m-d H:i:s",time()));
|
||||
$blog->Tags = "silverstripe, blog";
|
||||
$blog->Content = "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->Status = "Published";
|
||||
$blog->ParentID = $blogholder->ID;
|
||||
$blog->write();
|
||||
$blog->publish("Stage", "Live");
|
||||
|
||||
Database::alteration_message("Blog page created","created");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BlogHolder_Controller extends Page_Controller {
|
||||
function init() {
|
||||
parent::init();
|
||||
|
||||
// This will create a <link> tag point to the RSS feed
|
||||
RSSFeed::linkToFeed($this->Link() . "rss", "RSS feed of this blog");
|
||||
Requirements::themedCSS("blog");
|
||||
Requirements::themedCSS("bbcodehelp");
|
||||
|
||||
}
|
||||
|
||||
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 rss() {
|
||||
global $project;
|
||||
$rss = new RSSFeed($this->Children(), $this->Link(), $project . " blog", "", "Title", "ParsedContent");
|
||||
$rss->outputToBrowser();
|
||||
}
|
||||
|
||||
function BBTags() {
|
||||
return BBCodeParser::usable_tags();
|
||||
}
|
||||
|
||||
function post(){
|
||||
if(!Permission::check('ADMIN')){
|
||||
Security::permissionFailure($this,
|
||||
"Posting blogs is an administrator task. Please log in.");
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class BlogEntry_Form extends Form {
|
||||
function postblog($data) {
|
||||
Cookie::set("BlogHolder_Name", $data['Author']);
|
||||
$blogentry = new BlogEntry();
|
||||
$this->saveInto($blogentry);
|
||||
|
||||
if($data['ID'] != 0){ //new post
|
||||
$blogentry = DataObject::get_by_id("BlogEntry",$data['ID']);
|
||||
$this->saveInto($blogentry);
|
||||
$blogentry->setDate($data['Date']);
|
||||
}else{
|
||||
$blogentry->setDate(date("Y-m-d H:i:s",time()));
|
||||
$blogentry->URLSegment = $data['Title'];
|
||||
}
|
||||
|
||||
$blogentry->Status = "Published";
|
||||
$blogentry->writeToStage("Stage");
|
||||
$blogentry->publish("Stage", "Live");
|
||||
|
||||
Director::redirect(Director::currentURLSegment());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
class BlogManagementWidget extends Widget {
|
||||
static $db = 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.";
|
||||
|
||||
function CommentText() {
|
||||
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM PageComment WHERE NeedsModeration=1")->value();
|
||||
if($unmoderatedcount == 1) {
|
||||
return "You have 1 unmoderated comment";
|
||||
} else if($unmoderatedcount > 1) {
|
||||
return "You have $unmoderatedcount unmoderated comments";
|
||||
} else {
|
||||
return "Comment administration";
|
||||
}
|
||||
}
|
||||
|
||||
function CommentLink() {
|
||||
$unmoderatedcount = DB::query("SELECT COUNT(*) FROM PageComment WHERE NeedsModeration=1")->value();
|
||||
|
||||
if($unmoderatedcount > 0) {
|
||||
return "admin/comments/unmoderated";
|
||||
} else {
|
||||
return "admin/comments";
|
||||
}
|
||||
}
|
||||
|
||||
function WidgetHolder() {
|
||||
if(Permission::check("ADMIN")) {
|
||||
return $this->renderWith("WidgetHolder");
|
||||
}
|
||||
}
|
||||
|
||||
function PostLink() {
|
||||
$blogholder = $this->getBlogHolder();
|
||||
|
||||
return $blogholder->Link('post');
|
||||
}
|
||||
|
||||
function getBlogHolder() {
|
||||
$page = Director::currentPage();
|
||||
|
||||
if($page->is_a("BlogHolder")) {
|
||||
return $page;
|
||||
} else if($page->is_a("BlogEntry") && $page->getParent()->is_a("BlogHolder")) {
|
||||
return $page->getParent();
|
||||
} else {
|
||||
return DataObject::get_one("BlogHolder");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
class RSSWidget extends Widget {
|
||||
static $db = array(
|
||||
"CustomTitle" => "Text",
|
||||
"RssUrl" => "Text",
|
||||
"NumberToShow" => "Int",
|
||||
);
|
||||
|
||||
static $defaults = array(
|
||||
"NumberToShow" => 10
|
||||
);
|
||||
|
||||
static $title = "RSS Feed";
|
||||
static $cmsTitle = "RSS Feed";
|
||||
static $description = "Shows the latest entries of a RSS feed.";
|
||||
|
||||
function getCMSFields() {
|
||||
return new FieldSet(
|
||||
new TextField("CustomTitle","Custom title for the feed"),
|
||||
new TextField("RssUrl", "URL of RSS Feed"),
|
||||
new NumericField("NumberToShow", "Number of Items to show")
|
||||
);
|
||||
}
|
||||
|
||||
function Title() {
|
||||
$this->feed = new SimplePie($this->RssUrl);
|
||||
$this->feed->init();
|
||||
return ($this->CustomTitle) ? $this->CustomTitle : $this->feed->get_feed_title();
|
||||
}
|
||||
|
||||
function FeedItems() {
|
||||
$output = new DataObjectSet();
|
||||
foreach($this->feed->get_items(0, $this->NumberToShow) as $item) {
|
||||
$output->push(new ArrayData(array(
|
||||
"Title" => $item->get_title(),
|
||||
"Link" => $item->get_link()
|
||||
)));
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
|
||||
class TagCloudWidget extends Widget {
|
||||
static $db = array(
|
||||
"Limit" => "Int",
|
||||
"Sortby" => "Varchar"
|
||||
);
|
||||
|
||||
static $defaults = array(
|
||||
"Limit" => "0",
|
||||
"Sortby" => "alphabet"
|
||||
);
|
||||
|
||||
static $title = "Tags";
|
||||
static $cmsTitle = "Tag Cloud";
|
||||
static $description = "Shows a tag cloud of tags on your blog.";
|
||||
|
||||
function getBlogHolder() {
|
||||
$page = Director::currentPage();
|
||||
|
||||
if($page->is_a("BlogHolder")) {
|
||||
return $page;
|
||||
} else if($page->is_a("BlogEntry") && $page->getParent()->is_a("BlogHolder")) {
|
||||
return $page->getParent();
|
||||
} else {
|
||||
return DataObject::get_one("BlogHolder");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getCMSFields() {
|
||||
return new FieldSet(
|
||||
new TextField("Limit", "Limit number of tags"),
|
||||
new OptionsetField("Sortby","Sort by",array("alphabet"=>"alphabet","frequency"=>"frequency"))
|
||||
);
|
||||
}
|
||||
|
||||
function Tags() {
|
||||
Requirements::css("blog/css/tagcloud.css");
|
||||
|
||||
$allTags = array();
|
||||
$max = 0;
|
||||
$blogHolder = $this->getBlogHolder();
|
||||
|
||||
$entries = $blogHolder->Children();
|
||||
|
||||
if($entries) {
|
||||
foreach($entries as $entry) {
|
||||
$theseTags = split(" *, *", trim($entry->Tags));
|
||||
foreach($theseTags as $tag) {
|
||||
$allTags[$tag] = isset($allTags[$tag]) ? $allTags[$tag] + 1 : 1; //getting the count into key => value map
|
||||
$max = ($allTags[$tag] > $max) ? $allTags[$tag] : $max;
|
||||
}
|
||||
}
|
||||
|
||||
if($allTags) {
|
||||
|
||||
//TODO: move some or all of the sorts to the database for more efficiency
|
||||
|
||||
if($this->Limit > 0){
|
||||
uasort($allTags, "column_sort_by_popularity"); //sort by popularity
|
||||
$allTags = array_slice($allTags, 0, $this->Limit);
|
||||
}
|
||||
if($this->Sortby == "alphabet"){
|
||||
natksort($allTags);
|
||||
}
|
||||
|
||||
$sizes = array();
|
||||
foreach($allTags as $tag => $count){
|
||||
$sizes[$count] = true;
|
||||
}
|
||||
$numsizes = count($sizes)-1; //Work out the number of different sizes
|
||||
if($numsizes > 5){$numsizes = 5;}
|
||||
|
||||
foreach($allTags as $tag => $count) {
|
||||
$popularity = floor($count / $max * $numsizes);
|
||||
|
||||
switch($popularity) {
|
||||
case 0:
|
||||
$class = "not-popular";
|
||||
break;
|
||||
case 1:
|
||||
$class = "not-very-popular";
|
||||
break;
|
||||
case 2:
|
||||
$class = "somewhat-popular";
|
||||
break;
|
||||
case 3:
|
||||
$class = "popular";
|
||||
break;
|
||||
case 4:
|
||||
$class = "very-popular";
|
||||
break;
|
||||
case 5:
|
||||
$class = "ultra-popular";
|
||||
break;
|
||||
default:
|
||||
$class = "broken";
|
||||
break;
|
||||
}
|
||||
|
||||
$allTags[$tag] = array(
|
||||
"Tag" => $tag,
|
||||
"Count" => $count,
|
||||
"Class" => $class,
|
||||
"Link" => $blogHolder->Link() . '?tag=' . urlencode($tag)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$output = new DataObjectSet();
|
||||
foreach($allTags as $tag => $fields) {
|
||||
$output->push(new ArrayData($fields));
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function column_sort_by_popularity($a, $b){
|
||||
|
||||
if($a == $b) {
|
||||
$result = 0;
|
||||
}
|
||||
else {
|
||||
$result = $b - $a;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function natksort(&$aToBeSorted)
|
||||
{
|
||||
$aResult = array();
|
||||
$aKeys = array_keys($aToBeSorted);
|
||||
natcasesort($aKeys);
|
||||
foreach ($aKeys as $sKey)
|
||||
{
|
||||
$aResult[$sKey] = $aToBeSorted[$sKey];
|
||||
}
|
||||
$aToBeSorted = $aResult;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,152 @@
|
|||
<?php
|
||||
|
||||
require_once("core/model/DB.php");
|
||||
|
||||
class TypoImport extends Controller {
|
||||
/**
|
||||
* Imports product status and price change updates.
|
||||
*
|
||||
*/
|
||||
|
||||
function testinstall() {
|
||||
echo "Ok";
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports blog entries and comments from a Potgres-based typo installation into a SilverStripe blog
|
||||
*/
|
||||
function import(){
|
||||
// some of the guys in the contents table are articles, some are contents. Distinguished by type = "Article" or "Comment"
|
||||
// fields are: id, title, author, body, body_html, extended, excerpt, keywords, created_at, updated_at, extended_html, user_id, permalink, guid, [13]
|
||||
// text_filter_id, whiteboard, type, article_id, email, url, ip, blog_name, name, published, allow_pings, allow_comments, blog_id
|
||||
// published_at, state, status_confirmed
|
||||
|
||||
|
||||
$dbconn = pg_connect("host=orwell port=5432 dbname=typo_prod user=postgres password=possty");
|
||||
|
||||
// create a new blogholder and call it "imported blog"
|
||||
$bholder = new BlogHolder();
|
||||
$bholder->Title = "imported blog";
|
||||
|
||||
// write it!
|
||||
$bholder->write();
|
||||
$bholder->publish("Stage", "Live");
|
||||
|
||||
// get the typo articles
|
||||
$result = pg_query($dbconn, "SELECT * FROM contents WHERE type='Article'");
|
||||
|
||||
while ($row = pg_fetch_row($result)) {
|
||||
|
||||
// title [1]
|
||||
// author [2]
|
||||
// body [3]
|
||||
// body_html [4] (type rendered and cached the html here. This is the preferred blog entry content for migration)
|
||||
// keywords (space separated) [7] (tags table is just a list of the unique variants of these keywords)
|
||||
// created_at [8]
|
||||
// permalink [12] (this is like the url in sitetree, prolly not needed)
|
||||
// email [18] (address of the commenter)
|
||||
// url [19] (url of the commenter)
|
||||
|
||||
$title = $row[1];
|
||||
$author = $row[2];
|
||||
$blog_entry = $row[4];
|
||||
$keywords = $row[7];
|
||||
$created_at = $row[8];
|
||||
|
||||
// sometimes it's empty. If it is, grab the body
|
||||
if ($blog_entry == ""){
|
||||
// use "body"
|
||||
$blog_entry = $row[3];
|
||||
}
|
||||
echo "blog_entry: $blog_entry";
|
||||
echo "<br />\n";
|
||||
|
||||
// put the typo blog entry in the SS database
|
||||
$newEntry = new BlogEntry();
|
||||
$newEntry->Title = $title;
|
||||
$newEntry->Author = $author;
|
||||
$newEntry->Content = $blog_entry;
|
||||
$newEntry->Tags = $keywords;
|
||||
$newEntry->Date = $created_at;
|
||||
|
||||
// tie each blog entry back to the blogholder we created initially
|
||||
$newEntry->ParentID = $bholder->ID;
|
||||
|
||||
// write it!
|
||||
$newEntry->write();
|
||||
$newEntry->publish("Stage", "Live");
|
||||
|
||||
// grab the id so we can get the comments
|
||||
$old_article_id = $row[0];
|
||||
|
||||
// get the comments
|
||||
$result2 = pg_query($dbconn, "SELECT * FROM contents WHERE type = 'Comment' AND article_id = $old_article_id");
|
||||
|
||||
while ($row2 = pg_fetch_row($result2)) {
|
||||
// grab the body_html
|
||||
$comment = $row2[4];
|
||||
|
||||
// sometimes it's empty. If it is, grab the body
|
||||
if ($comment == ""){
|
||||
// use "body"
|
||||
$comment = $row2[3];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$Cauthor = $row2[2];
|
||||
$Ccreated_at = $row2[8];
|
||||
|
||||
// put the typo blog comment in the SS database
|
||||
$newCEntry = new PageComment();
|
||||
$newCEntry->Name = $Cauthor;
|
||||
$newCEntry->Comment = $comment;
|
||||
$newCEntry->Created = $created_at;
|
||||
|
||||
// need to grab the newly inserted blog entry's id
|
||||
$newCEntry->ParentID = $newEntry->ID;
|
||||
|
||||
// write it!
|
||||
$newCEntry->write();
|
||||
|
||||
echo "comment: $comment";
|
||||
echo "<br />\n";
|
||||
}
|
||||
|
||||
$newEntry->flushCache();
|
||||
|
||||
// fix up the specialchars
|
||||
pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"×\", \"x\")");
|
||||
pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"’\", \"’\")");
|
||||
pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"‘\", \"‘\")");
|
||||
pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"—\", \"—\")");
|
||||
pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"“\", \"“\")");
|
||||
pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"”\", \"”\")");
|
||||
pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"–\", \"–\")");
|
||||
pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"—\", \"—\")");
|
||||
pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"…\", \"…\")");
|
||||
pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"™\", \"™\")");
|
||||
pg_query($dbconn, "UPDATE SiteTree SET Content = REPLACE(Content, \"&\", \"&\")");
|
||||
|
||||
pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"×\", \"x\")");
|
||||
pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"’\", \"’\")");
|
||||
pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"‘\", \"‘\")");
|
||||
pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"—\", \"—\")");
|
||||
pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"“\", \"“\")");
|
||||
pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"”\", \"”\")");
|
||||
pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"–\", \"–\")");
|
||||
pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"—\", \"—\")");
|
||||
pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"…\", \"…\")");
|
||||
pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"™\", \"™\")");
|
||||
pg_query($dbconn, "UPDATE PageComment SET Comment = REPLACE(Comment, \"&\", \"&\")");
|
||||
|
||||
|
||||
}
|
||||
|
||||
pg_close($dbconn);
|
||||
|
||||
} // end function
|
||||
|
||||
} // end class
|
||||
?>
|
|
@ -0,0 +1,9 @@
|
|||
.archiveMonths{
|
||||
|
||||
}
|
||||
|
||||
ul.archiveYears li{
|
||||
display: inline;
|
||||
font-size: 1.2em !important;
|
||||
margin:0 !important;
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
Foundational BBHelper formatting
|
||||
*/
|
||||
|
||||
ul.bbcodeExamples li {
|
||||
list-style-type:none;
|
||||
font-size: 1em;
|
||||
}
|
||||
ul.bbcodeExamples li.last {
|
||||
border: none;
|
||||
}
|
||||
|
||||
ul.bbcodeExamples li span.example {
|
||||
|
||||
}
|
||||
|
||||
#BBTagsHolder{
|
||||
color: #777;
|
||||
padding: 5px;
|
||||
width: 270px;
|
||||
background-color: #fff;
|
||||
font-size:0.8em;
|
||||
}
|
||||
|
||||
.bbcodeExamples{
|
||||
margin: 0 !important;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#BBCodeHint{
|
||||
cursor: pointer;
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
.BlogError {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.BlogError p {
|
||||
color: #fff;
|
||||
display: inline;
|
||||
background-color: #f77;
|
||||
padding: 7px;
|
||||
font-weight:bold;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
div.flickrwidget {
|
||||
text-align: center;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
.tagcloud .not-popular { font-size: 1em; }
|
||||
.tagcloud .not-very-popular { font-size: 1.3em; }
|
||||
.tagcloud .somewhat-popular { font-size: 1.6em; }
|
||||
.tagcloud .popular { font-size: 1.9em; }
|
||||
.tagcloud .very-popular { font-size: 2.2em; }
|
||||
.tagcloud .ultra-popular { font-size: 2.5em; }
|
Binary file not shown.
After Width: | Height: | Size: 297 B |
Binary file not shown.
After Width: | Height: | Size: 189 B |
|
@ -0,0 +1,12 @@
|
|||
Behaviour.register({
|
||||
'#BBCodeHint': {
|
||||
onclick: function() {
|
||||
if($('BBTagsHolder').style.display == "none") {
|
||||
Effect.BlindDown('BBTagsHolder');
|
||||
} else{
|
||||
Effect.BlindUp('BBTagsHolder');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
|
@ -0,0 +1,21 @@
|
|||
<% if DisplayMode == month %>
|
||||
<ul class="archiveMonths">
|
||||
<% control Dates %>
|
||||
<li>
|
||||
<a href="$Link">
|
||||
$Date.Format(F) $Date.Year
|
||||
</a>
|
||||
</li>
|
||||
<% end_control %>
|
||||
</ul>
|
||||
<% else %>
|
||||
<ul class="archiveYears">
|
||||
<% control Dates %>
|
||||
<li>
|
||||
<a href="$Link">
|
||||
$Date.Year<% if Last %><% else %>,<% end_if %>
|
||||
</a>
|
||||
</li>
|
||||
<% end_control %>
|
||||
</ul>
|
||||
<% end_if %>
|
|
@ -0,0 +1,5 @@
|
|||
<ul>
|
||||
<li><a href="$PostLink">Post a new blog entry</a></li>
|
||||
<li><a href="$CommentLink">$CommentText</a></li>
|
||||
<li><a href="Security/logout">Logout</a></li>
|
||||
</ul>
|
|
@ -0,0 +1,21 @@
|
|||
<% if BlogEntries.MoreThanOnePage %>
|
||||
<div id="PageNumbers">
|
||||
<% if BlogEntries.NotLastPage %>
|
||||
<a class="next" href="$Children.NextLink" title="View the next page">Next</a>
|
||||
<% end_if %>
|
||||
|
||||
<% if BlogEntries.NotFirstPage %>
|
||||
<a class="prev" href="$Children.PrevLink" title="View the previous page">Prev</a>
|
||||
<% end_if %>
|
||||
|
||||
<span>
|
||||
<% control BlogEntries.Pages %>
|
||||
<% if CurrentBool %>
|
||||
$PageNum
|
||||
<% else %>
|
||||
<a href="$Link" title="View page number $PageNum">$PageNum</a>
|
||||
<% end_if %>
|
||||
<% end_control %>
|
||||
</span>
|
||||
</div>
|
||||
<% end_if %>
|
|
@ -0,0 +1,3 @@
|
|||
<div id="Sidebar" class="typography">
|
||||
$SideBar
|
||||
</div>
|
|
@ -0,0 +1,14 @@
|
|||
<div class="blogSummary">
|
||||
<h2><a href="$Link" title="View full post titled - '$Title'">$MenuTitle</a></h2>
|
||||
<p class="authorDate">Posted by $Author.XML on $Date.Long | <a href="$Link#PageComments_holder" title="View Comments Posted">$Comments.Count Comments</a></p>
|
||||
<% if Tags %>
|
||||
<p class="tags">
|
||||
Tags:
|
||||
<% control Tags %>
|
||||
<a href="$Link" title="View all posts tagged '$Tag'">$Tag</a><% if Last %><% else %>,<% end_if %>
|
||||
<% end_control %>
|
||||
</p>
|
||||
<% end_if %>
|
||||
<p>$ParagraphSummary</p>
|
||||
<p class="blogVitals"><a href="$Link#PageComments_holder" class="comments" title="View Comments for this post">$Comments.Count comments</a> | <a href="$Link" class="readmore" title="Read Full Post">Read the full post</a></p>
|
||||
</div>
|
|
@ -0,0 +1,23 @@
|
|||
<% include BlogSideBar %>
|
||||
<div id="BlogContent" class="typography">
|
||||
<% include BreadCrumbs %>
|
||||
|
||||
<div class="blogEntry">
|
||||
<h2>$Title</h2>
|
||||
<p class="authorDate">Posted by $Author.XML on $Date.Long | $Comments.Count Comments</p>
|
||||
<% if Tags %>
|
||||
<p class="tags">
|
||||
Tags:
|
||||
<% control Tags %>
|
||||
<a href="$Link" title="View all posts tagged '$Tag'">$Tag</a><% if Last %><% else %>,<% end_if %>
|
||||
<% end_control %>
|
||||
</p>
|
||||
<% end_if %>
|
||||
<p>$Content.Parse(BBCodeParser)</p>
|
||||
<br />
|
||||
</div>
|
||||
<% if CurrentMember %><p><a href="$EditURL" id="editpost" title="Edit this post">Edit this post</a> | <a href="$Link(unpublishPost)" id="unpublishpost">Unpublish this post</a></p><% end_if %>
|
||||
|
||||
$PageComments
|
||||
|
||||
</div>
|
|
@ -0,0 +1,23 @@
|
|||
<% include BlogSideBar %>
|
||||
|
||||
<div id="BlogContent" class="blogcontent typography">
|
||||
|
||||
<% include BreadCrumbs %>
|
||||
|
||||
$Content
|
||||
|
||||
<% if Tag %>
|
||||
<h3>Viewing entries tagged with '$Tag'</h3>
|
||||
<% end_if %>
|
||||
|
||||
<% if BlogEntries %>
|
||||
<% control BlogEntries %>
|
||||
<% include BlogSummary %>
|
||||
<% end_control %>
|
||||
<% else %>
|
||||
<h3>There are no blog entries</h3>
|
||||
<% end_if %>
|
||||
|
||||
<% include BlogPagination %>
|
||||
|
||||
</div>
|
|
@ -0,0 +1,12 @@
|
|||
<% include BlogSideBar %>
|
||||
|
||||
<div id="BlogContent" class="blogcontent typography">
|
||||
|
||||
<% include BreadCrumbs %>
|
||||
|
||||
<% if isPost %>
|
||||
|
||||
$BlogEntryForm
|
||||
|
||||
<% end_if %>
|
||||
</div>
|
|
@ -0,0 +1,7 @@
|
|||
<ul>
|
||||
<% control FeedItems %>
|
||||
<li>
|
||||
<a href="$Link">$Title</a>
|
||||
</li>
|
||||
<% end_control %>
|
||||
</ul>
|
|
@ -0,0 +1,5 @@
|
|||
<p class="tagcloud">
|
||||
<% control Tags %>
|
||||
<a href="$Link" class="$Class">$Tag</a>
|
||||
<% end_control %>
|
||||
</p>
|
Loading…
Reference in New Issue