From b47cf3e363c3c7ca2f6a6c714c217c8229033693 Mon Sep 17 00:00:00 2001 From: Danang Probo Sayekti Date: Fri, 7 Feb 2014 20:21:05 +0700 Subject: [PATCH] Add limit RSS length Add option to limit rss length. --- config/config.ini.example | 7 +++++- system/htmly.php | 9 +++++++- system/includes/functions.php | 48 ++++++++++++++++++++++------------------ themes/clean/no-posts.html.php | 1 + themes/default/no-posts.html.php | 1 + 5 files changed, 43 insertions(+), 23 deletions(-) create mode 100644 themes/clean/no-posts.html.php create mode 100644 themes/default/no-posts.html.php diff --git a/config/config.ini.example b/config/config.ini.example index 6b58432..106ebfa 100644 --- a/config/config.ini.example +++ b/config/config.ini.example @@ -34,7 +34,6 @@ tag.perpage = "10" archive.perpage = "10" search.perpage = "10" profile.perpage = "10" -rss.count = "10" json.count = "10" ; Related posts @@ -49,6 +48,12 @@ teaser.char = "200" ; Description char count description.char = "150" +;RSS feed count +rss.count = "10" + +;RSS feed description length. If left empty we will use full page. +rss.char = "" + ; Enable image thumbnail on teaser, the options is "true" and "false". If set to "true", you can specify the default thumbnail also. img.thumbnail = "true" default.thumbnail = "" diff --git a/system/htmly.php b/system/htmly.php index 9959fb1..6777bc8 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -27,8 +27,15 @@ get('/index', function () { $total = ''; if(empty($posts) || $page < 1){ + // a non-existing page - welcome_page(); + render('no-posts',array( + 'title' => config('blog.title'), + 'canonical' => site_url(), + 'description' => config('blog.description'), + 'bodyclass' => 'noposts', + )); + die; } diff --git a/system/includes/functions.php b/system/includes/functions.php index 85d7a37..89e48fa 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -961,6 +961,7 @@ function generate_rss($posts){ $feed = new Feed(); $channel = new Channel(); + $rssLength = config('rss.char'); $channel ->title(config('blog.title')) @@ -969,6 +970,23 @@ function generate_rss($posts){ ->appendTo($feed); foreach($posts as $p){ + + if(!empty($rssLength)) { + if (strlen(strip_tags($p->body)) < config('rss.char')) { + $string = preg_replace('/\s\s+/', ' ', strip_tags($p->body)); + $body = $string . '...' . ' more' ; + } + else { + $string = preg_replace('/\s\s+/', ' ', strip_tags($p->body)); + $string = substr($string, 0, config('rss.char')); + $string = substr($string, 0, strrpos($string, ' ')); + $body = $string . '...' . ' more' ; + } + } + else { + $body = $p->body; + } + $item = new Item(); $tags = explode(',', str_replace(' ', '', strip_tags($p->tag))); foreach($tags as $tag) { @@ -978,7 +996,7 @@ function generate_rss($posts){ $item ->title($p->title) ->pubDate($p->date) - ->description($p->body) + ->description($body) ->url($p->url) ->appendTo($channel); } @@ -1087,7 +1105,7 @@ function generate_sitemap($str){ elseif ($str == 'base') { echo ''; - echo '' . site_url() . 'hourly1.0'; + echo '' . site_url() . '1.0'; echo ''; } @@ -1098,7 +1116,7 @@ function generate_sitemap($str){ echo ''; foreach($posts as $p) { - echo '' . $p->url . 'monthly0.5'; + echo '' . $p->url . '0.5'; } echo ''; @@ -1113,7 +1131,7 @@ function generate_sitemap($str){ if(!empty($posts)) { foreach($posts as $p) { - echo '' . $p->url . 'monthly0.5'; + echo '' . $p->url . '0.5'; } } @@ -1149,7 +1167,7 @@ function generate_sitemap($str){ $tag = array_unique($tag, SORT_REGULAR); foreach($tag as $t) { - echo '' . $t . 'weekly0.5'; + echo '' . $t . '0.5'; } } @@ -1178,15 +1196,15 @@ function generate_sitemap($str){ echo ''; foreach($day as $d) { - echo '' . $d . 'monthly0.5'; + echo '' . $d . '0.5'; } foreach($month as $m) { - echo '' . $m . 'monthly0.5'; + echo '' . $m . '0.5'; } foreach($year as $y) { - echo '' . $y . 'monthly0.5'; + echo '' . $y . '0.5'; } echo ''; @@ -1206,7 +1224,7 @@ function generate_sitemap($str){ echo ''; foreach($author as $a) { - echo '' . $a . 'daily0.5'; + echo '' . $a . '0.5'; } echo ''; @@ -1245,16 +1263,4 @@ function generate_opml(){ // Turn an array of posts into a JSON function generate_json($posts){ return json_encode($posts); -} - -function welcome_page() { - echo << -

Welcome to your new HTMLy-powered blog.

-

The next thing you will need to do is creating the first account. Please create YourUsername.ini inside config/users folder and write down your password there:

-
password = YourPassword
-

Login to your blog admin panel at www.example.com/admin to creating your first post.

-

This welcome message will disappear after your first post published.

- -EOF; } \ No newline at end of file diff --git a/themes/clean/no-posts.html.php b/themes/clean/no-posts.html.php new file mode 100644 index 0000000..861e375 --- /dev/null +++ b/themes/clean/no-posts.html.php @@ -0,0 +1 @@ +

No posts found!

\ No newline at end of file diff --git a/themes/default/no-posts.html.php b/themes/default/no-posts.html.php new file mode 100644 index 0000000..861e375 --- /dev/null +++ b/themes/default/no-posts.html.php @@ -0,0 +1 @@ +

No posts found!

\ No newline at end of file