From 72cf924c1c3b81c87b98a244377efd49a42d55a3 Mon Sep 17 00:00:00 2001 From: Danang Probo Sayekti Date: Sat, 8 Feb 2014 18:31:11 +0700 Subject: [PATCH] Improve the teaser Improve the teaser --- config/config.ini.example | 7 +++-- system/htmly.php | 2 +- system/includes/functions.php | 61 +++++++++++++++++++++---------------- themes/clean/css/style.css | 2 +- themes/clean/main.html.php | 8 ++--- themes/clean/post.html.php | 67 ++++++++++++++++++----------------------- themes/clean/profile.html.php | 8 ++--- themes/clean/static.html.php | 10 ++++++ themes/default/css/style.css | 5 +++ themes/default/main.html.php | 8 ++--- themes/default/post.html.php | 67 ++++++++++++++++++----------------------- themes/default/profile.html.php | 8 ++--- themes/default/static.html.php | 10 ++++++ 13 files changed, 143 insertions(+), 120 deletions(-) create mode 100644 themes/clean/static.html.php create mode 100644 themes/default/static.html.php diff --git a/config/config.ini.example b/config/config.ini.example index 106ebfa..f089490 100644 --- a/config/config.ini.example +++ b/config/config.ini.example @@ -1,4 +1,4 @@ -; The URL of your blog +; The URL of your blog. Include the http or https. site.url = "" ; Blog info @@ -22,7 +22,7 @@ breadcrumb.home = "Home" ; Disqus disqus.shortname = "" -; Google publisher +; Google+ publisher google.publisher = "" ; Google analytics @@ -42,6 +42,9 @@ related.count = "4" ; Author info on blog post. Set "true" or "false". author.info = "true" +; Teaser type: set "trimmed" or "full". +teaser.type = "trimmed" + ; Teaser char count teaser.char = "200" diff --git a/system/htmly.php b/system/htmly.php index 7885e9c..5d7f84a 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -613,7 +613,7 @@ get('/:static', function($static){ $post = $post[0]; - render('post',array( + render('static',array( 'title' => $post->title .' - ' . config('blog.title'), 'canonical' => $post->url, 'description' => $description = get_description($post->body), diff --git a/system/includes/functions.php b/system/includes/functions.php index 79d7dd1..b1b6a88 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -591,7 +591,7 @@ function archive_list() { if (this.parentNode.className.indexOf('expanded') > -1){this.parentNode.className = 'collapsed';this.innerHTML = '►';} else {this.parentNode.className = 'expanded';this.innerHTML = '▼';} EOF; echo <<.toggle{font-size:16px;font-family:Georgia, Arial, sans-serif}ul.archivegroup{padding:0;margin:0;}.archivegroup .expanded ul{display:block;}.archivegroup .collapsed ul{display:none;}.archivegroup li.expanded,.archivegroup li.collapsed{list-style:none;} + EOF; echo '

Archive

'; @@ -722,11 +722,11 @@ function get_description($text) { // Get the teaser function get_teaser($text, $url) { + + $teaserType = config('teaser.type'); - if (strlen(strip_tags($text)) < config('teaser.char')) { - $string = preg_replace('/\s\s+/', ' ', strip_tags($text)); - $body = $string . '...' . ' more' ; - echo '

' . $body . '

'; + if (strlen(strip_tags($text)) < config('teaser.char') || $teaserType === 'full') { + echo $text; } else { $string = preg_replace('/\s\s+/', ' ', strip_tags($text)); @@ -741,30 +741,39 @@ function get_teaser($text, $url) { // Get thumbnail from image and Youtube. function get_thumbnail($text) { - libxml_use_internal_errors(true); - $default = config('default.thumbnail'); - $dom = new DOMDocument(); - $dom->loadHtml($text); - $imgTags = $dom->getElementsByTagName('img'); - $vidTags = $dom->getElementsByTagName('iframe'); - if ($imgTags->length > 0) { - $imgElement = $imgTags->item(0); - $imgSource = $imgElement->getAttribute('src'); - return '
'; - } - elseif ($vidTags->length > 0) { - $vidElement = $vidTags->item(0); - $vidSource = $vidElement->getAttribute('src'); - $fetch = explode("embed/", $vidSource); - if(isset($fetch[1])) { - $vidThumb = '//img.youtube.com/vi/' . $fetch[1] . '/default.jpg'; - return '
'; + $teaserType = config('teaser.type'); + + if (strlen(strip_tags($text)) > config('teaser.char') && $teaserType === 'trimmed') { + + libxml_use_internal_errors(true); + $default = config('default.thumbnail'); + $dom = new DOMDocument(); + $dom->loadHtml($text); + $imgTags = $dom->getElementsByTagName('img'); + $vidTags = $dom->getElementsByTagName('iframe'); + if ($imgTags->length > 0) { + $imgElement = $imgTags->item(0); + $imgSource = $imgElement->getAttribute('src'); + return '
'; } + elseif ($vidTags->length > 0) { + $vidElement = $vidTags->item(0); + $vidSource = $vidElement->getAttribute('src'); + $fetch = explode("embed/", $vidSource); + if(isset($fetch[1])) { + $vidThumb = '//img.youtube.com/vi/' . $fetch[1] . '/default.jpg'; + return '
'; + } + } + else { + if (!empty($default)) { + return '
'; + } + } + } else { - if (!empty($default)) { - return '
'; - } + } } diff --git a/themes/clean/css/style.css b/themes/clean/css/style.css index bccbcaf..74b4fd3 100644 --- a/themes/clean/css/style.css +++ b/themes/clean/css/style.css @@ -473,7 +473,7 @@ aside .archive, aside .tagcloud { margin-left: 10px; } -aside .archive ul li, aside .tagcloud ul li { +aside .archive ul li ul, aside .tagcloud ul li { margin-left:30px; } diff --git a/themes/clean/main.html.php b/themes/clean/main.html.php index 0d821ae..c625f36 100644 --- a/themes/clean/main.html.php +++ b/themes/clean/main.html.php @@ -3,17 +3,17 @@ -
+

title ?>

- Posted in tag ?> by - Comments
diff --git a/themes/clean/post.html.php b/themes/clean/post.html.php index b0a3b7d..36b0cfd 100644 --- a/themes/clean/post.html.php +++ b/themes/clean/post.html.php @@ -2,53 +2,46 @@
- - - +

title ?>

- -
- Posted in tag ?> by - Permalink
- +
+ - Posted in + tag ?> by + - + Permalink +
body; ?>
- -
- \ No newline at end of file diff --git a/themes/clean/profile.html.php b/themes/clean/profile.html.php index 48501de..998d5ae 100644 --- a/themes/clean/profile.html.php +++ b/themes/clean/profile.html.php @@ -10,17 +10,17 @@ -
  • +
  • title ?> on date)?> - Posted in tag ?>
  • diff --git a/themes/clean/static.html.php b/themes/clean/static.html.php new file mode 100644 index 0000000..03139e0 --- /dev/null +++ b/themes/clean/static.html.php @@ -0,0 +1,10 @@ + + +
    +
    +

    title ?>

    +
    + body; ?> +
    +
    +
    \ No newline at end of file diff --git a/themes/default/css/style.css b/themes/default/css/style.css index 47acdb7..83b07cc 100644 --- a/themes/default/css/style.css +++ b/themes/default/css/style.css @@ -786,6 +786,11 @@ h1.title-post a:hover, h2.title-index a:hover { width: 33%; } +.archive .toggle { + font-family: Georgia,Arial,sans-serif; + font-size: 16px; +} + .social { float:right; } diff --git a/themes/default/main.html.php b/themes/default/main.html.php index 0d821ae..c625f36 100644 --- a/themes/default/main.html.php +++ b/themes/default/main.html.php @@ -3,17 +3,17 @@ -
    +

    title ?>

    - Posted in tag ?> by - Comments
    diff --git a/themes/default/post.html.php b/themes/default/post.html.php index b0a3b7d..36b0cfd 100644 --- a/themes/default/post.html.php +++ b/themes/default/post.html.php @@ -2,53 +2,46 @@
    - - - +

    title ?>

    - -
    - Posted in tag ?> by - Permalink
    - +
    + - Posted in + tag ?> by + - + Permalink +
    body; ?>
    - -
    - \ No newline at end of file diff --git a/themes/default/profile.html.php b/themes/default/profile.html.php index 48501de..998d5ae 100644 --- a/themes/default/profile.html.php +++ b/themes/default/profile.html.php @@ -10,17 +10,17 @@ -
  • +
  • title ?> on date)?> - Posted in tag ?>
  • diff --git a/themes/default/static.html.php b/themes/default/static.html.php new file mode 100644 index 0000000..03139e0 --- /dev/null +++ b/themes/default/static.html.php @@ -0,0 +1,10 @@ + + +
    +
    +

    title ?>

    +
    + body; ?> +
    +
    +
    \ No newline at end of file