mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge pull request #97 from tractorcow/blog-archive-housekeeping
BUG / Housekeeping of Widget code
This commit is contained in:
commit
ba89364eb8
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if(class_exists('Widget')) {
|
if(class_exists('Widget')) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows a widget with viewing blog entries
|
* Shows a widget with viewing blog entries
|
||||||
* by months or years.
|
* by months or years.
|
||||||
@ -7,27 +9,21 @@ if(class_exists('Widget')) {
|
|||||||
* @package blog
|
* @package blog
|
||||||
*/
|
*/
|
||||||
class ArchiveWidget extends Widget {
|
class ArchiveWidget extends Widget {
|
||||||
private static $db = array(
|
|
||||||
|
private static $db = array(
|
||||||
'DisplayMode' => 'Varchar'
|
'DisplayMode' => 'Varchar'
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $has_one = array();
|
private static $defaults = 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 $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.';
|
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() {
|
function getCMSFields() {
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
@ -61,20 +57,29 @@ if(class_exists('Widget')) {
|
|||||||
$stage = Versioned::current_stage();
|
$stage = Versioned::current_stage();
|
||||||
$suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage";
|
$suffix = (!$stage || $stage == 'Stage') ? "" : "_$stage";
|
||||||
|
|
||||||
$monthclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%m') : 'MONTH("Date")';
|
if(method_exists(DB::getConn(), 'formattedDatetimeClause')) {
|
||||||
$yearclause = method_exists(DB::getConn(), 'formattedDatetimeClause') ? DB::getConn()->formattedDatetimeClause('"Date"', '%Y') : 'YEAR("Date")';
|
$monthclause = DB::getConn()->formattedDatetimeClause('"Date"', '%m');
|
||||||
|
$yearclause = DB::getConn()->formattedDatetimeClause('"Date"', '%Y');
|
||||||
|
} else {
|
||||||
|
$monthclause = 'MONTH("Date")';
|
||||||
|
$yearclause = 'YEAR("Date")';
|
||||||
|
}
|
||||||
|
|
||||||
if($this->DisplayMode == 'month') {
|
if($this->DisplayMode == 'month') {
|
||||||
$sqlResults = DB::query("
|
$sqlResults = DB::query("
|
||||||
SELECT DISTINCT CAST($monthclause AS " . DB::getConn()->dbDataType('unsigned integer') . ") AS \"Month\", $yearclause AS \"Year\"
|
SELECT DISTINCT CAST($monthclause AS " . DB::getConn()->dbDataType('unsigned integer') . ")
|
||||||
FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\" ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\"
|
AS \"Month\",
|
||||||
|
$yearclause AS \"Year\"
|
||||||
|
FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\"
|
||||||
|
ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\"
|
||||||
WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
|
WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
|
||||||
ORDER BY \"Year\" DESC, \"Month\" DESC;"
|
ORDER BY \"Year\" DESC, \"Month\" DESC;"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$sqlResults = DB::query("
|
$sqlResults = DB::query("
|
||||||
SELECT DISTINCT $yearclause AS \"Year\"
|
SELECT DISTINCT $yearclause AS \"Year\"
|
||||||
FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\" ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\"
|
FROM \"SiteTree$suffix\" INNER JOIN \"BlogEntry$suffix\"
|
||||||
|
ON \"SiteTree$suffix\".\"ID\" = \"BlogEntry$suffix\".\"ID\"
|
||||||
WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
|
WHERE \"ParentID\" IN (" . implode(', ', $ids) . ")
|
||||||
ORDER BY \"Year\" DESC"
|
ORDER BY \"Year\" DESC"
|
||||||
);
|
);
|
||||||
@ -109,4 +114,4 @@ if(class_exists('Widget')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,20 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if(class_exists('Widget')) {
|
if(class_exists('Widget')) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blog Management Widget
|
* Blog Management Widget
|
||||||
|
*
|
||||||
* @package blog
|
* @package blog
|
||||||
*/
|
*/
|
||||||
class BlogManagementWidget extends Widget {
|
class BlogManagementWidget extends Widget {
|
||||||
private static $db = array();
|
|
||||||
|
|
||||||
private static $has_one = array();
|
private static $title = "Blog Management";
|
||||||
|
|
||||||
private static $has_many = array();
|
private static $cmsTitle = "Blog Management";
|
||||||
|
|
||||||
private static $many_many = array();
|
private static $description =
|
||||||
|
"Provide a number of links useful for administering a blog. Only shown if the user is an admin.";
|
||||||
private static $belongs_many_many = array();
|
|
||||||
|
|
||||||
private static $defaults = array();
|
|
||||||
|
|
||||||
private static $title = "Blog Management";
|
|
||||||
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() {
|
||||||
|
|
||||||
@ -63,4 +57,4 @@ class BlogManagementWidget extends Widget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,29 @@
|
|||||||
<?php
|
<?php
|
||||||
if(class_exists('Widget')) {
|
|
||||||
|
if (class_exists('Widget')) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Presents a list of items from an RSS feed url
|
||||||
|
*
|
||||||
|
* @package blog
|
||||||
|
*/
|
||||||
class RSSWidget extends Widget {
|
class RSSWidget extends Widget {
|
||||||
private static $db = array(
|
|
||||||
|
private static $db = array(
|
||||||
"RSSTitle" => "Text",
|
"RSSTitle" => "Text",
|
||||||
"RssUrl" => "Text",
|
"RssUrl" => "Text",
|
||||||
"NumberToShow" => "Int"
|
"NumberToShow" => "Int"
|
||||||
);
|
);
|
||||||
|
|
||||||
private static $has_one = array();
|
private static $defaults = array(
|
||||||
|
|
||||||
private static $has_many = array();
|
|
||||||
|
|
||||||
private static $many_many = array();
|
|
||||||
|
|
||||||
private static $belongs_many_many = array();
|
|
||||||
|
|
||||||
private static $defaults = array(
|
|
||||||
"NumberToShow" => 10,
|
"NumberToShow" => 10,
|
||||||
"RSSTitle" => 'RSS Feed'
|
"RSSTitle" => 'RSS Feed'
|
||||||
);
|
);
|
||||||
private static $cmsTitle = "RSS Feed";
|
|
||||||
private static $description = "Downloads another page's RSS feed and displays items in a list.";
|
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
|
* If the RssUrl is relative, convert it to absolute with the
|
||||||
* current baseURL to avoid confusing simplepie.
|
* current baseURL to avoid confusing simplepie.
|
||||||
@ -45,7 +47,10 @@ if(class_exists('Widget')) {
|
|||||||
$fields->merge(
|
$fields->merge(
|
||||||
new FieldList(
|
new FieldList(
|
||||||
new TextField("RSSTitle", _t('RSSWidget.CT', "Custom title for the feed")),
|
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 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"))
|
new NumericField("NumberToShow", _t('RSSWidget.NTS', "Number of Items to show"))
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -54,8 +59,9 @@ if(class_exists('Widget')) {
|
|||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Title() {
|
function Title() {
|
||||||
return ($this->RSSTitle) ? $this->RSSTitle : 'RSS Feed';
|
return ($this->RSSTitle) ? $this->RSSTitle : _t('RSSWidget.DEFAULTTITLE', 'RSS Feed');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFeedItems() {
|
function getFeedItems() {
|
||||||
@ -100,4 +106,4 @@ if(class_exists('Widget')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if(class_exists('Widget')) {
|
if(class_exists('Widget')) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple widget that just shows a link
|
* A simple widget that just shows a link
|
||||||
* to this website's blog RSS, with an RSS
|
* to this website's blog RSS, with an RSS
|
||||||
@ -9,11 +11,11 @@ if(class_exists('Widget')) {
|
|||||||
*/
|
*/
|
||||||
class SubscribeRSSWidget extends Widget {
|
class SubscribeRSSWidget extends Widget {
|
||||||
|
|
||||||
private static $title = 'Subscribe via RSS';
|
private static $title = 'Subscribe via RSS';
|
||||||
|
|
||||||
private static $cmsTitle = 'Subscribe via RSS widget';
|
private static $cmsTitle = 'Subscribe via RSS widget';
|
||||||
|
|
||||||
private static $description = 'Shows a link allowing a user to subscribe to this blog via RSS.';
|
private static $description = 'Shows a link allowing a user to subscribe to this blog via RSS.';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an absolute URL based on the BlogHolder
|
* Return an absolute URL based on the BlogHolder
|
||||||
@ -28,4 +30,4 @@ if(class_exists('Widget')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,150 +1,148 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class TagCloudWidget extends Widget {
|
if(class_exists('Widget')) {
|
||||||
private static $db = array(
|
|
||||||
"Title" => "Varchar",
|
|
||||||
"Limit" => "Int",
|
|
||||||
"Sortby" => "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(
|
|
||||||
"Title" => "Tag Cloud",
|
|
||||||
"Limit" => "0",
|
|
||||||
"Sortby" => "alphabet"
|
|
||||||
);
|
|
||||||
|
|
||||||
private static $cmsTitle = "Tag Cloud";
|
|
||||||
private static $description = "Shows a tag cloud of tags on your blog.";
|
|
||||||
|
|
||||||
private static $popularities = array( 'not-popular', 'not-very-popular', 'somewhat-popular', 'popular', 'very-popular', 'ultra-popular' );
|
|
||||||
|
|
||||||
function getCMSFields() {
|
|
||||||
$fields = parent::getCMSFields();
|
|
||||||
|
|
||||||
$fields->merge(
|
|
||||||
|
|
||||||
new FieldList(
|
|
||||||
new TextField("Title", _t("TagCloudWidget.TILE", "Title")),
|
|
||||||
new TextField("Limit", _t("TagCloudWidget.LIMIT", "Limit number of tags")),
|
|
||||||
new OptionsetField("Sortby",_t("TagCloudWidget.SORTBY","Sort by"),array("alphabet"=>_t("TagCloudWidget.SBAL", "alphabet"),"frequency"=>_t("TagCloudWidget.SBFREQ", "frequency")))
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->extend('updateCMSFields', $fields);
|
|
||||||
|
|
||||||
return $fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
function Title() {
|
|
||||||
return $this->Title ? $this->Title : 'Tag Cloud';
|
|
||||||
}
|
|
||||||
|
|
||||||
function getTagsCollection() {
|
|
||||||
Requirements::themedCSS("tagcloud");
|
|
||||||
|
|
||||||
$allTags = array();
|
|
||||||
$max = 0;
|
|
||||||
$container = BlogTree::current();
|
|
||||||
|
|
||||||
$entries = $container->Entries();
|
|
||||||
|
|
||||||
if($entries) {
|
|
||||||
foreach($entries as $entry) {
|
|
||||||
$theseTags = preg_split(" *, *", mb_strtolower(trim($entry->Tags)));
|
|
||||||
foreach($theseTags as $tag) {
|
|
||||||
if($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) $allTags = array_slice($allTags, 0, $this->Limit, true);
|
|
||||||
|
|
||||||
if($this->Sortby == "alphabet"){
|
|
||||||
$this->natksort($allTags);
|
|
||||||
} else{
|
|
||||||
uasort($allTags, array($this, "column_sort_by_popularity")); // sort by frequency
|
|
||||||
}
|
|
||||||
|
|
||||||
$sizes = array();
|
|
||||||
foreach ($allTags as $tag => $count) $sizes[$count] = true;
|
|
||||||
|
|
||||||
$offset = 0;
|
|
||||||
$numsizes = count($sizes)-1; //Work out the number of different sizes
|
|
||||||
$buckets = count(self::$popularities)-1;
|
|
||||||
|
|
||||||
// If there are more frequencies than buckets, divide frequencies into buckets
|
|
||||||
if ($numsizes > $buckets) {
|
|
||||||
$numsizes = $buckets;
|
|
||||||
}
|
|
||||||
// Otherwise center use central buckets
|
|
||||||
else {
|
|
||||||
$offset = round(($buckets-$numsizes)/2);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($allTags as $tag => $count) {
|
|
||||||
$popularity = round($count / $max * $numsizes) + $offset; $popularity=min($buckets,$popularity);
|
|
||||||
$class = self::$popularities[$popularity];
|
|
||||||
|
|
||||||
$allTags[$tag] = array(
|
|
||||||
"Tag" => $tag,
|
|
||||||
"Count" => $count,
|
|
||||||
"Class" => $class,
|
|
||||||
"Link" => $container->Link('tag') . '/' . urlencode($tag)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = new ArrayList();
|
|
||||||
foreach($allTags as $tag => $fields) {
|
|
||||||
$output->push(new ArrayData($fields));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper method to compare 2 Vars to work out the results.
|
* A list of tags associated with blog posts
|
||||||
* @param mixed
|
*
|
||||||
* @param mixed
|
* @package blog
|
||||||
* @return int
|
|
||||||
*/
|
*/
|
||||||
private function column_sort_by_popularity($a, $b){
|
class TagCloudWidget extends Widget {
|
||||||
if($a == $b) {
|
|
||||||
$result = 0;
|
private static $db = array(
|
||||||
}
|
"Title" => "Varchar",
|
||||||
else {
|
"Limit" => "Int",
|
||||||
$result = $b - $a;
|
"Sortby" => "Varchar"
|
||||||
}
|
);
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function natksort(&$aToBeSorted) {
|
private static $defaults = array(
|
||||||
$aResult = array();
|
"Title" => "Tag Cloud",
|
||||||
$aKeys = array_keys($aToBeSorted);
|
"Limit" => "0",
|
||||||
natcasesort($aKeys);
|
"Sortby" => "alphabet"
|
||||||
foreach ($aKeys as $sKey) {
|
);
|
||||||
$aResult[$sKey] = $aToBeSorted[$sKey];
|
|
||||||
}
|
|
||||||
$aToBeSorted = $aResult;
|
|
||||||
|
|
||||||
return true;
|
private static $cmsTitle = "Tag Cloud";
|
||||||
|
private static $description = "Shows a tag cloud of tags on your blog.";
|
||||||
|
|
||||||
|
private static $popularities = array( 'not-popular', 'not-very-popular', 'somewhat-popular', 'popular', 'very-popular', 'ultra-popular' );
|
||||||
|
|
||||||
|
function getCMSFields() {
|
||||||
|
$fields = parent::getCMSFields();
|
||||||
|
|
||||||
|
$fields->merge(
|
||||||
|
|
||||||
|
new FieldList(
|
||||||
|
new TextField("Title", _t("TagCloudWidget.TILE", "Title")),
|
||||||
|
new TextField("Limit", _t("TagCloudWidget.LIMIT", "Limit number of tags")),
|
||||||
|
new OptionsetField("Sortby",_t("TagCloudWidget.SORTBY","Sort by"),array("alphabet"=>_t("TagCloudWidget.SBAL", "alphabet"),"frequency"=>_t("TagCloudWidget.SBFREQ", "frequency")))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->extend('updateCMSFields', $fields);
|
||||||
|
|
||||||
|
return $fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Title() {
|
||||||
|
return $this->Title ? $this->Title : _t('TagCloudWidget.DEFAULTTITLE', 'Tag Cloud');
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTagsCollection() {
|
||||||
|
Requirements::themedCSS("tagcloud");
|
||||||
|
|
||||||
|
$allTags = array();
|
||||||
|
$max = 0;
|
||||||
|
$container = BlogTree::current();
|
||||||
|
|
||||||
|
$entries = $container->Entries();
|
||||||
|
|
||||||
|
if($entries) {
|
||||||
|
foreach($entries as $entry) {
|
||||||
|
$theseTags = preg_split(" *, *", mb_strtolower(trim($entry->Tags)));
|
||||||
|
foreach($theseTags as $tag) {
|
||||||
|
if($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) $allTags = array_slice($allTags, 0, $this->Limit, true);
|
||||||
|
|
||||||
|
if($this->Sortby == "alphabet"){
|
||||||
|
$this->natksort($allTags);
|
||||||
|
} else{
|
||||||
|
uasort($allTags, array($this, "column_sort_by_popularity")); // sort by frequency
|
||||||
|
}
|
||||||
|
|
||||||
|
$sizes = array();
|
||||||
|
foreach ($allTags as $tag => $count) $sizes[$count] = true;
|
||||||
|
|
||||||
|
$offset = 0;
|
||||||
|
$numsizes = count($sizes)-1; //Work out the number of different sizes
|
||||||
|
$buckets = count(self::$popularities)-1;
|
||||||
|
|
||||||
|
// If there are more frequencies than buckets, divide frequencies into buckets
|
||||||
|
if ($numsizes > $buckets) {
|
||||||
|
$numsizes = $buckets;
|
||||||
|
}
|
||||||
|
// Otherwise center use central buckets
|
||||||
|
else {
|
||||||
|
$offset = round(($buckets-$numsizes)/2);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($allTags as $tag => $count) {
|
||||||
|
$popularity = round($count / $max * $numsizes) + $offset; $popularity=min($buckets,$popularity);
|
||||||
|
$class = self::$popularities[$popularity];
|
||||||
|
|
||||||
|
$allTags[$tag] = array(
|
||||||
|
"Tag" => $tag,
|
||||||
|
"Count" => $count,
|
||||||
|
"Class" => $class,
|
||||||
|
"Link" => $container->Link('tag') . '/' . urlencode($tag)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = new ArrayList();
|
||||||
|
foreach($allTags as $tag => $fields) {
|
||||||
|
$output->push(new ArrayData($fields));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to compare 2 Vars to work out the results.
|
||||||
|
* @param mixed
|
||||||
|
* @param mixed
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
private function column_sort_by_popularity($a, $b){
|
||||||
|
if($a == $b) {
|
||||||
|
$result = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$result = $b - $a;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function natksort(&$aToBeSorted) {
|
||||||
|
$aResult = array();
|
||||||
|
$aKeys = array_keys($aToBeSorted);
|
||||||
|
natcasesort($aKeys);
|
||||||
|
foreach ($aKeys as $sKey) {
|
||||||
|
$aResult[$sKey] = $aToBeSorted[$sKey];
|
||||||
|
}
|
||||||
|
$aToBeSorted = $aResult;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user