diff --git a/system/admin/views/main.html.php b/system/admin/views/main.html.php
index 6456848..aff6740 100644
--- a/system/admin/views/main.html.php
+++ b/system/admin/views/main.html.php
@@ -6,7 +6,7 @@
';
echo '
| ' . i18n('Title') . ' | ' . i18n('Published') . ' | ';
diff --git a/system/admin/views/popular-posts.html.php b/system/admin/views/popular-posts.html.php
index 6877aba..9c0078c 100644
--- a/system/admin/views/popular-posts.html.php
+++ b/system/admin/views/popular-posts.html.php
@@ -22,7 +22,7 @@
title ?> |
date) ?> |
- views ?> |
+ slug); ?> |
author ?> |
category);?> |
tag ?> |
diff --git a/system/includes/functions.php b/system/includes/functions.php
index 8bee46f..e058e1f 100644
--- a/system/includes/functions.php
+++ b/system/includes/functions.php
@@ -1478,7 +1478,7 @@ function recent_posts($custom = null, $count = null)
if (file_exists($filename)) {
$posts = unserialize(file_get_contents($filename));
- if (count($posts) != $count) {
+ if (count($posts) < $count) {
$posts = get_posts(null, 1, $count);
$tmp = serialize($posts);
file_put_contents($filename, print_r($tmp, true), LOCK_EX);
@@ -1490,11 +1490,21 @@ function recent_posts($custom = null, $count = null)
}
if (!empty($custom)) {
- return $posts;
+ $arr = array();
+ $i = 1;
+ foreach ($posts as $post) {
+ $arr[] = $post;
+ if ($i++ >= $count)
+ break;
+ }
+ return $arr;
} else {
+ $i = 1;
$recent .= '';
foreach ($posts as $post) {
$recent .= '- ' . $post->title . '
';
+ if ($i++ >= $count)
+ break;
}
if (empty($posts)) {
$recent .= '- ' . i18n('No_posts_found') . '
';
@@ -1525,7 +1535,7 @@ function recent_type($type, $custom = null, $count = null)
if (file_exists($filename)) {
$posts = unserialize(file_get_contents($filename));
- if (count($posts) != $count) {
+ if (count($posts) < $count) {
$posts = get_type($type, 1, $count);
$tmp = serialize($posts);
file_put_contents($filename, print_r($tmp, true), LOCK_EX);
@@ -1537,12 +1547,21 @@ function recent_type($type, $custom = null, $count = null)
}
if (!empty($custom)) {
- return $posts;
+ $arr = array();
+ $i = 1;
+ foreach ($posts as $post) {
+ $arr[] = $post;
+ if ($i++ >= $count)
+ break;
+ }
+ return $arr;
} else {
-
+ $i = 1;
$recent .= '';
foreach ($posts as $post) {
$recent .= '- ' . $post->title . '
';
+ if ($i++ >= $count)
+ break;
}
if (empty($posts)) {
$recent .= '- No recent ' . $type . ' found
';
@@ -1582,7 +1601,7 @@ function popular_posts($custom = null, $count = null)
if (strpos($f['basename'], $arr[1]) !== false ) {
$tmp[] = $f;
if ($i++ >= $count)
- break;
+ break;
}
}
}
@@ -1600,7 +1619,7 @@ function popular_posts($custom = null, $count = null)
if (file_exists($filecache)) {
$posts = unserialize(file_get_contents($filecache));
- if (count($posts) != $count) {
+ if (count($posts) < $count) {
$posts = get_posts($tmp, 1, $count);
$ar = serialize($posts);
file_put_contents($filecache, print_r($ar, true), LOCK_EX);
@@ -1612,14 +1631,24 @@ function popular_posts($custom = null, $count = null)
}
if (empty($custom)) {
+ $ix = 1;
$pop .= '';
foreach ($posts as $post) {
$pop .= '- ' . $post->title . '
';
+ if ($ix++ >= $count)
+ break;
}
$pop .= '
';
return $pop;
} else {
- return $posts;
+ $arp = array();
+ $ix = 1;
+ foreach ($posts as $post) {
+ $arp[] = $post;
+ if ($ix++ >= $count)
+ break;
+ }
+ return $arp;
}
} else {
if(empty($custom)) {
@@ -1698,60 +1727,85 @@ function archive_list($custom = null)
$len = count($by_year);
if (empty($custom)) {
- foreach ($by_year as $year => $months) {
- if ($i == 0) {
- $class = 'expanded';
- $arrow = '▼';
- } else {
- $class = 'collapsed';
- $arrow = '►';
- }
- $i++;
+ $cache_d = "cache/widget/archive.default.cache";
+ if (file_exists($cache_d)) {
+ $arch = unserialize(file_get_contents($cache_d));
+ return $arch;
+ } else {
+ foreach ($by_year as $year => $months) {
+ if ($i == 0) {
+ $class = 'expanded';
+ $arrow = '▼';
+ } else {
+ $class = 'collapsed';
+ $arrow = '►';
+ }
+ $i++;
- $by_month = array_count_values($months);
- # Sort the months
- krsort($by_month);
+ $by_month = array_count_values($months);
+ # Sort the months
+ krsort($by_month);
- $script = << -1){this.parentNode.className = 'collapsed';this.innerHTML = '►';} else {this.parentNode.className = 'expanded';this.innerHTML = '▼';}
-EOF;
- $arch .= '';
- $arch .= '- ';
- $arch .= '' . $arrow . ' ';
- $arch .= '' . $year . ' ';
- $arch .= '(' . count($months) . ')';
- $arch .= '
';
-
- foreach ($by_month as $month => $count) {
- $name = format_date(mktime(0, 0, 0, $month, 1, 2010), 'F');
- $arch .= '- ' . $name . '';
- $arch .= ' (' . $count . ')
';
- }
+ $script = << -1){this.parentNode.className = 'collapsed';this.innerHTML = '►';} else {this.parentNode.className = 'expanded';this.innerHTML = '▼';}
+ EOF;
+ $arch .= '';
+ $arch .= '- ';
+ $arch .= '' . $arrow . ' ';
+ $arch .= '' . $year . ' ';
+ $arch .= '(' . count($months) . ')';
+ $arch .= '
';
+
+ foreach ($by_month as $month => $count) {
+ $name = format_date(mktime(0, 0, 0, $month, 1, 2010), 'F');
+ $arch .= '- ' . $name . '';
+ $arch .= ' (' . $count . ')
';
+ }
- $arch .= '
';
- $arch .= ' ';
- $arch .= '
';
+ $arch .= '
';
+ $arch .= ' ';
+ $arch .= '
';
+ }
+
+ $ar = serialize($arch);
+ file_put_contents($cache_d, $ar, LOCK_EX);
+ return $arch;
}
- return $arch;
} elseif ($custom === 'month-year') {
- foreach ($by_year as $year => $months) {
- $by_month = array_count_values($months);
- # Sort the months
- krsort($by_month);
- foreach ($by_month as $month => $count) {
- $name = format_date(mktime(0, 0, 0, $month, 1, 2010), 'F');
- $arch .= '- ' . $name . ' ' . $year .' ('.$count.')
';
+ $cache_my = "cache/widget/archive.month-year.cache";
+ if (file_exists($cache_my)) {
+ $arch = unserialize(file_get_contents($cache_my));
+ return $arch;
+ } else {
+ foreach ($by_year as $year => $months) {
+ $by_month = array_count_values($months);
+ # Sort the months
+ krsort($by_month);
+ foreach ($by_month as $month => $count) {
+ $name = format_date(mktime(0, 0, 0, $month, 1, 2010), 'F');
+ $arch .= '- ' . $name . ' ' . $year .' ('.$count.')
';
+ }
}
+ $ar = serialize($arch);
+ file_put_contents($cache_my, $ar, LOCK_EX);
+ return $arch;
}
- return $arch;
} elseif ($custom === 'year') {
- foreach ($by_year as $year => $months) {
- $by_month = array_count_values($months);
- # Sort the months
- krsort($by_month);
- $arch .= '- ' . $year .' ('. count($months) .')
';
+ $cache_y = "cache/widget/archive.year.cache";
+ if (file_exists($cache_y)) {
+ $arch = unserialize(file_get_contents($cache_y));
+ return $arch;
+ } else {
+ foreach ($by_year as $year => $months) {
+ $by_month = array_count_values($months);
+ # Sort the months
+ krsort($by_month);
+ $arch .= '- ' . $year .' ('. count($months) .')
';
+ }
+ $ar = serialize($arch);
+ file_put_contents($cache_y, $ar, LOCK_EX);
+ return $arch;
}
- return $arch;
} else {
return $by_year;
}
@@ -1797,33 +1851,41 @@ function tag_cloud($custom = null)
}
if(empty($custom)) {
- // Font sizes
- $max_size = 22; // max font size in %
- $min_size = 8; // min font size in %
-
- // Get the largest and smallest array values
- $max_qty = max(array_values($tag_collection));
- $min_qty = min(array_values($tag_collection));
-
- // Find the range of values
- $spread = $max_qty - $min_qty;
- if (0 == $spread) { // we don't want to divide by zero
- $spread = 1;
- }
+ $wrapper = '';
+ $cache_t = "cache/widget/tags.default.cache";
+ if (file_exists($cache_t)) {
+ $wrapper = unserialize(file_get_contents($cache_t));
+ return $wrapper;
+ } else {
+ // Font sizes
+ $max_size = 22; // max font size in %
+ $min_size = 8; // min font size in %
+
+ // Get the largest and smallest array values
+ $max_qty = max(array_values($tag_collection));
+ $min_qty = min(array_values($tag_collection));
+
+ // Find the range of values
+ $spread = $max_qty - $min_qty;
+ if (0 == $spread) { // we don't want to divide by zero
+ $spread = 1;
+ }
- // Font-size increment
- // this is the increase per tag quantity (times used)
- $step = ($max_size - $min_size)/($spread);
+ // Font-size increment
+ // this is the increase per tag quantity (times used)
+ $step = ($max_size - $min_size)/($spread);
- $wrapper = '';
- arsort($tag_collection);
- $sliced_tags = array_slice($tag_collection, 0, $tagcloud_count, true);
- ksort($sliced_tags);
- foreach ($sliced_tags as $tag => $count) {
- $size = $min_size + (($count - $min_qty) * $step);
- $wrapper .= ' '.tag_i18n($tag).' ';
+ arsort($tag_collection);
+ $sliced_tags = array_slice($tag_collection, 0, $tagcloud_count, true);
+ ksort($sliced_tags);
+ foreach ($sliced_tags as $tag => $count) {
+ $size = $min_size + (($count - $min_qty) * $step);
+ $wrapper .= ' '.tag_i18n($tag).' ';
+ }
+ $ar = serialize($wrapper);
+ file_put_contents($cache_t, $ar, LOCK_EX);
+ return $wrapper;
}
- return $wrapper;
} else {
return $tag_collection;
@@ -2122,6 +2184,34 @@ function get_teaser($string, $url = null, $char = null)
}
}
+// Shorten the string
+function shorten($string = null, $char = null)
+{
+ if(empty($char) || empty($string)) {
+ return;
+ }
+
+ libxml_use_internal_errors(true);
+ $dom = new DOMDocument();
+ $dom->loadHTML('' . $string);
+ $tags_to_remove = array('script', 'style');
+ foreach($tags_to_remove as $tag){
+ $element = $dom->getElementsByTagName($tag);
+ foreach($element as $item){
+ $item->parentNode->removeChild($item);
+ }
+ }
+ $string = preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', mb_convert_encoding($dom->saveHTML($dom->documentElement), 'UTF-8'));
+ $string = preg_replace('/\s\s+/', ' ', strip_tags($string));
+ $string = ltrim(rtrim($string));
+ if (strlen($string) > $char) {
+ $string = substr($string, 0, $char);
+ $string = substr($string, 0, strrpos($string, ' '));
+ }
+ return $string;
+
+}
+
// Get thumbnail from image and Youtube.
function get_thumbnail($text, $url = null)
{
@@ -3387,34 +3477,6 @@ function get_video_id($url)
}
}
-// Shorten the string
-function shorten($string = null, $char = null)
-{
- if(empty($char) || empty($string)) {
- return;
- }
-
- libxml_use_internal_errors(true);
- $dom = new DOMDocument();
- $dom->loadHTML('' . $string);
- $tags_to_remove = array('script', 'style');
- foreach($tags_to_remove as $tag){
- $element = $dom->getElementsByTagName($tag);
- foreach($element as $item){
- $item->parentNode->removeChild($item);
- }
- }
- $string = preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', mb_convert_encoding($dom->saveHTML($dom->documentElement), 'UTF-8'));
- $string = preg_replace('/\s\s+/', ' ', strip_tags($string));
- $string = ltrim(rtrim($string));
- if (strlen($string) > $char) {
- $string = substr($string, 0, $char);
- $string = substr($string, 0, strrpos($string, ' '));
- }
- return $string;
-
-}
-
// translate tag to i18n
function tag_i18n($tag)
{
|---|