Permalink
Browse files

BUG Fixed parsing of spaces and other whitespace in tag clouds. Fixes #…

…59

BUG Fixed incorrect encoding of SelectedAuthor and SelectedTag; Now correctly cast for templates using the `cast` config, not within filtering.
BUG Fixed TagCloudWidget.popularities config from being incorrectly accessed as a static property
BUG Fixed TagCloudWidget::getCMSFields triggering extend('updateCMSFields') twice
BUG Fixed TagCloudWidget::getTagsCollection discarding tag label capitalisation
BUG Fixed TagCloudWidget::getTagsCollection not correctly respecting minimum tag counts (as well as maximum tag counts) when determining the popularity CSS class to assign.
Test cases for TagCloudWidget
API BlogEntry::TagNames now safely extracts tags from a blog entry as an associative 'lowercase' => 'Entered Tag' format
PHPDoc fixes
Removed trailing '?>' tags from PHP files
  • Loading branch information...
1 parent 9a6152b commit d788f6a979b3142135fcabdc61b5d155060a39d7 @tractorcow tractorcow committed Feb 28, 2014
View
@@ -86,26 +86,41 @@ function getCMSFields() {
return $fields;
}
+ /**
+ * Safely split and parse all distinct tags assigned to this BlogEntry
+ *
+ * @return array Associative array of lowercase tag to native case tags
+ */
+ public function TagNames() {
+ $tags = preg_split("/\s*,\s*/", trim($this->Tags));
+ $results = array();
+ foreach($tags as $tag) {
+ if($tag) $results[mb_strtolower($tag)] = $tag;
+ }
+ return $results;
+ }
+
/**
* Returns the tags added to this blog entry
+ *
+ * @return ArrayList List of ArrayData with Tag, Link, and URLTag keys
*/
- function TagsCollection() {
+ public function TagsCollection() {
- $tags = preg_split(" *, *", trim($this->Tags));
+ $tags = $this->TagNames();
$output = new ArrayList();
- $link = $this->getParent() ? $this->getParent()->Link('tag') : '';
- foreach($tags as $tag) {
+ $link = ($parent = $this->getParent()) ? $parent->Link('tag') : '';
+ foreach($tags as $tag => $tagLabel) {
+ $urlKey = urlencode($tag);
$output->push(new ArrayData(array(
- 'Tag' => Convert::raw2xml($tag),
- 'Link' => $link . '/' . urlencode($tag),
- 'URLTag' => urlencode($tag)
+ 'Tag' => $tagLabel,
+ 'Link' => Controller::join_links($link, $urlKey),
+ 'URLTag' => $urlKey
)));
}
- if($this->Tags) {
- return $output;
- }
+ return $output;
}
function Content() {
View
@@ -46,6 +46,7 @@ class BlogTree extends Page {
*
* @param $page allows you to force a specific page, otherwise,
* uses current
+ * @return BlogTree
*/
static function current($page = null) {
@@ -147,12 +148,14 @@ public function BlogHolderIDs() {
/**
* Get entries in this blog.
- * @param string limit A clause to insert into the limit clause.
- * @param string tag Only get blog entries with this tag
- * @param string date Only get blog entries on this date - either a year, or a year-month eg '2008' or '2008-02'
- * @param callback retrieveCallback A function to call with pagetype, filter and limit for custom blog sorting or filtering
- * @param string $where
- * @return DataObjectSet
+ *
+ * @param string $limit A clause to insert into the limit clause.
+ * @param string $tag Only get blog entries with this tag
+ * @param string $date Only get blog entries on this date - either a year, or a year-month eg '2008' or '2008-02'
+ * @param callable $retrieveCallback A function to call with pagetype, filter and limit for custom blog
+ * sorting or filtering
+ * @param string $filter Filter condition
+ * @return PaginatedList The list of entries in a paginated list
*/
public function Entries($limit = '', $tag = '', $date = '', $retrieveCallback = null, $filter = '') {
@@ -229,6 +232,11 @@ class BlogTree_Controller extends Page_Controller {
'date'
);
+ private static $casting = array(
+ 'SelectedTag' => 'Text',
+ 'SelectedAuthor' => 'Text'
+ );
+
function init() {
parent::init();
@@ -237,7 +245,13 @@ function init() {
Requirements::themedCSS("blog","blog");
}
- function BlogEntries($limit = null) {
+ /**
+ * Determine selected BlogEntry items to show on this page
+ *
+ * @param int $limit
+ * @return PaginatedList
+ */
+ public function BlogEntries($limit = null) {
require_once('Zend/Date.php');
if($limit === null) $limit = BlogTree::$default_entries_limit;
@@ -275,14 +289,14 @@ function BlogEntries($limit = null) {
/**
* This will create a <link> tag point to the RSS feed
*/
- function IncludeBlogRSS() {
+ public function IncludeBlogRSS() {
RSSFeed::linkToFeed($this->Link('rss'), _t('BlogHolder.RSSFEED',"RSS feed of these blogs"));
}
/**
* Get the rss feed for this blog holder's entries
*/
- function rss() {
+ public function rss() {
global $project_name;
$blogName = $this->Title;
@@ -299,7 +313,7 @@ function rss() {
/**
* Protection against infinite loops when an RSS widget pointing to this page is added to this page
*/
- function defaultAction($action) {
+ public function defaultAction($action) {
if(stristr($_SERVER['HTTP_USER_AGENT'], 'SimplePie')) return $this->rss();
return parent::defaultAction($action);
@@ -308,23 +322,22 @@ function defaultAction($action) {
/**
* Return the currently viewing tag used in the template as $Tag
*
- * @return String
+ * @return string
*/
- function SelectedTag() {
+ public function SelectedTag() {
if ($this->request->latestParam('Action') == 'tag') {
$tag = $this->request->latestParam('ID');
- $tag = urldecode($tag);
- return Convert::raw2xml($tag);
- }
+ return urldecode($tag);
+ }
return '';
}
/**
* Return the selected date from the blog tree
*
- * @return Date
+ * @return string
*/
- function SelectedDate() {
+ public function SelectedDate() {
if($this->request->latestParam('Action') == 'date') {
$year = $this->request->latestParam('ID');
$month = $this->request->latestParam('OtherID');
@@ -344,21 +357,23 @@ function SelectedDate() {
}
/**
- * @return String
+ * @return string
*/
- function SelectedAuthor() {
+ public function SelectedAuthor() {
if($this->request->getVar('author')) {
$hasAuthor = BlogEntry::get()->filter('Author', $this->request->getVar('author'))->Count();
- return $hasAuthor ? Convert::raw2xml($this->request->getVar('author')) : null;
+ return $hasAuthor
+ ? $this->request->getVar('author')
+ : null;
} elseif($this->request->getVar('authorID')) {
$hasAuthor = BlogEntry::get()->filter('AuthorID', $this->request->getVar('authorID'))->Count();
if($hasAuthor) {
$member = Member::get()->byId($this->request->getVar('authorID'));
if($member) {
if($member->hasMethod('BlogAuthorTitle')) {
- return Convert::raw2xml($member->BlogAuthorTitle);
+ return $member->BlogAuthorTitle;
} else {
- return Convert::raw2xml($member->Title);
+ return $member->Title;
}
} else {
return null;
@@ -367,7 +382,11 @@ function SelectedAuthor() {
}
}
- function SelectedNiceDate(){
+ /**
+ *
+ * @return string
+ */
+ public function SelectedNiceDate(){
$date = $this->SelectedDate();
if(strpos($date, '-')) {
Oops, something went wrong.

0 comments on commit d788f6a

Please sign in to comment.