diff --git a/.travis.yml b/.travis.yml index 2e60802..41abb51 100755 --- a/.travis.yml +++ b/.travis.yml @@ -46,7 +46,7 @@ before_script: - phpenv rehash - composer self-update || true - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support - - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss + - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require "silverstripe/comments" --require "silverstripe/widgets" - cd ~/builds/ss #Execute tests with or without coverage diff --git a/code/widgets/BlogTagsCloudWidget.php b/code/widgets/BlogTagsCloudWidget.php new file mode 100644 index 0000000..550e9f3 --- /dev/null +++ b/code/widgets/BlogTagsCloudWidget.php @@ -0,0 +1,108 @@ + 'Blog', + ); + + /** + * {@inheritdoc} + */ + public function getCMSFields() + { + $this->beforeUpdateCMSFields(function ($fields) { + /* + * @var FieldList $fields + */ + $fields->push( + DropdownField::create('BlogID', _t('BlogTagsCloudWidget.Blog', + 'Blog'), Blog::get()->map()) + ); + }); + + return parent::getCMSFields(); + } + + /** + * @return array + */ + public function getTags() + { + if ($blog = $this->Blog()) { + $escapedID = Convert::raw2sql($blog->ID); + $sql = 'SELECT DISTINCT "BlogTag"."URLSegment","BlogTag"."Title",Count("BlogTagID") AS "TagCount" + from "BlogPost_Tags" + INNER JOIN "BlogPost" + ON "BlogPost"."ID" = "BlogPost_Tags"."BlogPostID" + INNER JOIN "BlogTag" + ON "BlogTag"."ID" = "BlogPost_Tags"."BlogTagID" + WHERE "BlogID" = ' . $escapedID + . ' GROUP By "BlogTag"."URLSegment","BlogTag"."Title" + ORDER BY "Title"'; + + $records = DB::query($sql); + $bloglink = $blog->Link(); + $maxTagCount = 0; + + // create DataObjects that can be used to render the tag cloud + $tags = new ArrayList(); + foreach ($records as $record) { + $tag = new DataObject(); + $tag->TagName = $record['Title']; + $link = $bloglink.'tag/'.$record['URLSegment']; + $tag->Link = $link; + if ($record['TagCount'] > $maxTagCount) { + $maxTagCount = $record['TagCount']; + } + $tag->TagCount = $record['TagCount']; + $tags->push($tag); + } + + // normalize the tag counts from 1 to 10 + $tagfactor = 10 / $maxTagCount; + foreach ($tags->getIterator() as $tag) { + $normalized = round($tagfactor * ($tag->TagCount)); + $tag->NormalizedTag = $normalized; + } + + return $tags; + } + + return array(); + } +} + +class BlogTagsCloudWidget_Controller extends Widget_Controller +{ +} diff --git a/css/blog.css b/css/blog.css index fee7da5..fe370bc 100644 --- a/css/blog.css +++ b/css/blog.css @@ -12,3 +12,47 @@ .blog-sidebar .WidgetHolder ul li { list-style-type: none; } +ul.blogTagCloud { + list-style-type: none; + clear: both; +} +ul.blogTagCloud li { + float: left; + display: inline; + padding-right: 8px; +} +ul.blogTagCloud li a span { + float: left; + line-height: 30px; text-align: center; + padding: 0px; +} +ul.blogTagCloud .tagCount10 { + font-size: 26pt; +} +ul.blogTagCloud .tagCount9 { + font-size: 24pt; +} +ul.blogTagCloud .tagCount8 { + font-size: 22pt; +} +ul.blogTagCloud .tagCount7 { + font-size: 20pt; +} +ul.blogTagCloud .tagCount6 { + font-size: 18pt; +} +ul.blogTagCloud .tagCount5 { + font-size: 16pt; +} +ul.blogTagCloud .tagCount4 { + font-size: 14pt; +} +ul.blogTagCloud .tagCount3 { + font-size: 12pt; +} +ul.blogTagCloud .tagCount2 { + font-size: 10pt; +} +ul.blogTagCloud .tagCount1 { + font-size: 8pt; +} diff --git a/scss/blog.scss b/scss/blog.scss index 0be33cf..2f022cf 100644 --- a/scss/blog.scss +++ b/scss/blog.scss @@ -1,15 +1,75 @@ -.no-sidebar .content-container.size3of4 { - width: 75%; -} - -.blog-entry .post-image img { - width: 98.75%; -} - -.blog-sidebar .WidgetHolder ul { - margin-left: 0; - - li { - list-style-type: none; - } -} +.no-sidebar .content-container.size3of4 { + width: 75%; +} + +.blog-entry .post-image img { + width: 98.75%; +} + +.blog-sidebar .WidgetHolder ul { + margin-left: 0; + + li { + list-style-type: none; + } +} + +// tag cloud related +$baseTagFontSize:4pt; + +ul.blogTagCloud { + list-style-type: none; + clear: both; + + li { + float: left; + display: inline; + padding-right: 8px; + + a span { + float: left; + line-height: 30px; text-align: center; + padding: 0px; + } + } + + .tagCount10 { + font-size: $baseTagFontSize+22pt; + } + + .tagCount9 { + font-size: $baseTagFontSize+20pt; + } + + .tagCount8 { + font-size: $baseTagFontSize+18pt; + } + + .tagCount7 { + font-size: $baseTagFontSize+16pt; + } + + .tagCount6 { + font-size: $baseTagFontSize+14pt; + } + + .tagCount5 { + font-size: $baseTagFontSize+12pt; + } + + .tagCount4 { + font-size: $baseTagFontSize+10pt; + } + + .tagCount3 { + font-size: $baseTagFontSize+8pt; + } + + .tagCount2 { + font-size: $baseTagFontSize+6pt; + } + + .tagCount1 { + font-size: $baseTagFontSize+4pt; + } +} diff --git a/templates/widgets/BlogTagsCloudWidget.ss b/templates/widgets/BlogTagsCloudWidget.ss new file mode 100644 index 0000000..f327e36 --- /dev/null +++ b/templates/widgets/BlogTagsCloudWidget.ss @@ -0,0 +1,12 @@ +<% if $Tags %> +