Browse Source

Improve the teaser

Improve the teaser
pull/31/merge
Danang Probo Sayekti 11 years ago
parent
commit
72cf924c1c
13 changed files with 143 additions and 120 deletions
  1. +5
    -2
      config/config.ini.example
  2. +1
    -1
      system/htmly.php
  3. +35
    -26
      system/includes/functions.php
  4. +1
    -1
      themes/clean/css/style.css
  5. +4
    -4
      themes/clean/main.html.php
  6. +30
    -37
      themes/clean/post.html.php
  7. +4
    -4
      themes/clean/profile.html.php
  8. +10
    -0
      themes/clean/static.html.php
  9. +5
    -0
      themes/default/css/style.css
  10. +4
    -4
      themes/default/main.html.php
  11. +30
    -37
      themes/default/post.html.php
  12. +4
    -4
      themes/default/profile.html.php
  13. +10
    -0
      themes/default/static.html.php

+ 5
- 2
config/config.ini.example View File

@ -1,4 +1,4 @@
; The URL of your blog
; The URL of your blog. Include the http or https.
site.url = "" site.url = ""
; Blog info ; Blog info
@ -22,7 +22,7 @@ breadcrumb.home = "Home"
; Disqus ; Disqus
disqus.shortname = "" disqus.shortname = ""
; Google publisher
; Google+ publisher
google.publisher = "" google.publisher = ""
; Google analytics ; Google analytics
@ -42,6 +42,9 @@ related.count = "4"
; Author info on blog post. Set "true" or "false". ; Author info on blog post. Set "true" or "false".
author.info = "true" author.info = "true"
; Teaser type: set "trimmed" or "full".
teaser.type = "trimmed"
; Teaser char count ; Teaser char count
teaser.char = "200" teaser.char = "200"


+ 1
- 1
system/htmly.php View File

@ -613,7 +613,7 @@ get('/:static', function($static){
$post = $post[0]; $post = $post[0];
render('post',array(
render('static',array(
'title' => $post->title .' - ' . config('blog.title'), 'title' => $post->title .' - ' . config('blog.title'),
'canonical' => $post->url, 'canonical' => $post->url,
'description' => $description = get_description($post->body), 'description' => $description = get_description($post->body),


+ 35
- 26
system/includes/functions.php View File

@ -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 = '▼';} if (this.parentNode.className.indexOf('expanded') > -1){this.parentNode.className = 'collapsed';this.innerHTML = '►';} else {this.parentNode.className = 'expanded';this.innerHTML = '▼';}
EOF; EOF;
echo <<<EOF echo <<<EOF
<style>.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;}
<style>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;}
</style> </style>
EOF; EOF;
echo '<h3>Archive</h3>'; echo '<h3>Archive</h3>';
@ -722,11 +722,11 @@ function get_description($text) {
// Get the teaser // Get the teaser
function get_teaser($text, $url) { 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 . '...' . ' <a class="readmore" href="' . $url . '#more">more</a>' ;
echo '<p>' . $body . '</p>';
if (strlen(strip_tags($text)) < config('teaser.char') || $teaserType === 'full') {
echo $text;
} }
else { else {
$string = preg_replace('/\s\s+/', ' ', strip_tags($text)); $string = preg_replace('/\s\s+/', ' ', strip_tags($text));
@ -741,30 +741,39 @@ function get_teaser($text, $url) {
// Get thumbnail from image and Youtube. // Get thumbnail from image and Youtube.
function get_thumbnail($text) { 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 '<div class="thumbnail" style="background-image:url(' . $imgSource . ');"></div>';
}
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 '<div class="thumbnail" style="background-image:url(' . $vidThumb . ');"></div>';
$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 '<div class="thumbnail" style="background-image:url(' . $imgSource . ');"></div>';
} }
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 '<div class="thumbnail" style="background-image:url(' . $vidThumb . ');"></div>';
}
}
else {
if (!empty($default)) {
return '<div class="thumbnail" style="background-image:url(' . $default . ');"></div>';
}
}
} }
else { else {
if (!empty($default)) {
return '<div class="thumbnail" style="background-image:url(' . $default . ');"></div>';
}
} }
} }


+ 1
- 1
themes/clean/css/style.css View File

@ -473,7 +473,7 @@ aside .archive, aside .tagcloud {
margin-left: 10px; margin-left: 10px;
} }
aside .archive ul li, aside .tagcloud ul li {
aside .archive ul li ul, aside .tagcloud ul li {
margin-left:30px; margin-left:30px;
} }


+ 4
- 4
themes/clean/main.html.php View File

@ -3,17 +3,17 @@
<?php foreach($posts as $p):?> <?php foreach($posts as $p):?>
<?php <?php
if ($i == 0) { if ($i == 0) {
$class = 'first';
$class = 'post first';
} }
elseif ($i == $len - 1) { elseif ($i == $len - 1) {
$class = 'last';
$class = 'post last';
} }
else { else {
$class = '';
$class = 'post';
} }
$i++; $i++;
?> ?>
<div class="post <?php echo $class ?>" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
<div class="<?php echo $class ?>" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
<div class="main"> <div class="main">
<h2 class="title-index" itemprop="name"><a href="<?php echo $p->url?>"><?php echo $p->title ?></a></h2> <h2 class="title-index" itemprop="name"><a href="<?php echo $p->url?>"><?php echo $p->title ?></a></h2>
<div class="date"><span itemprop="datePublished"><?php echo date('d F Y', $p->date)?></span> - Posted in <span itemprop="articleSection"><?php echo $p->tag ?></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span><?php if (disqus_count() == true):?> - <span><a href="<?php echo $p->url?>#disqus_thread">Comments</a></span><?php endif;?></div> <div class="date"><span itemprop="datePublished"><?php echo date('d F Y', $p->date)?></span> - Posted in <span itemprop="articleSection"><?php echo $p->tag ?></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span><?php if (disqus_count() == true):?> - <span><a href="<?php echo $p->url?>#disqus_thread">Comments</a></span><?php endif;?></div>


+ 30
- 37
themes/clean/post.html.php View File

@ -2,53 +2,46 @@
<?php if(login()) { echo tab($p);} ?> <?php if(login()) { echo tab($p);} ?>
<div class="post" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting"> <div class="post" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
<div class="main"> <div class="main">
<?php if ($type == 'blogpost'):?>
<a name="more"></a>
<?php endif;?>
<a name="more"></a>
<h1 class="title-post" itemprop="name"><?php echo $p->title ?></h1> <h1 class="title-post" itemprop="name"><?php echo $p->title ?></h1>
<?php if ($type == 'blogpost'):?>
<div class="date"><span itemprop="datePublished"><a href="<?php echo $p->archive ?>" title="Show all posts made on this day"><?php echo date('d F Y', $p->date)?></a></span> - Posted in <span itemprop="articleSection"><?php echo $p->tag ?></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span> - <span><a href="<?php echo $p->url ?>" rel="permalink">Permalink</a></span></div>
<?php endif;?>
<div class="date">
<span itemprop="datePublished"><a href="<?php echo $p->archive ?>" title="Show all posts made on this day"><?php echo date('d F Y', $p->date)?></a></span> - Posted in
<span itemprop="articleSection"><?php echo $p->tag ?></span> by
<span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span> -
<span><a href="<?php echo $p->url ?>" rel="permalink">Permalink</a></span>
</div>
<div class="post-body" itemprop="articleBody"> <div class="post-body" itemprop="articleBody">
<?php echo $p->body; ?> <?php echo $p->body; ?>
</div> </div>
</div> </div>
<?php if ($type == 'blogpost'):?>
<div class="separator">&rarr;</div>
<div class="share-box">
<?php if (config('author.info') == 'true'):?>
<?php echo $authorinfo ?>
<?php endif;?>
<div class="share">
<h4>Share this post</h4>
<a class="twitter" target="_blank" href="https://twitter.com/share?url=<?php echo $p->url ?>&text=<?php echo $p->title?>">Twitter</a>
<a class="facebook" target="_blank" href="https://www.facebook.com/sharer.php?u=<?php echo $p->url ?>&t=<?php echo $p->title?>">Facebook</a>
<a class="googleplus" target="_blank" href="https://plus.google.com/share?url=<?php echo $p->url ?>">Google+</a>
</div>
<div class="separator">&rarr;</div>
<div class="share-box">
<?php if (config('author.info') == 'true'):?>
<?php echo $authorinfo ?>
<?php endif;?>
<div class="share">
<h4>Share this post</h4>
<a class="twitter" target="_blank" href="https://twitter.com/share?url=<?php echo $p->url ?>&text=<?php echo $p->title?>">Twitter</a>
<a class="facebook" target="_blank" href="https://www.facebook.com/sharer.php?u=<?php echo $p->url ?>&t=<?php echo $p->title?>">Facebook</a>
<a class="googleplus" target="_blank" href="https://plus.google.com/share?url=<?php echo $p->url ?>">Google+</a>
</div> </div>
<?php endif;?>
<?php if ($type == 'blogpost'):?><?php echo get_related($p->tag)?><?php endif;?>
</div>
<?php echo get_related($p->tag)?>
<div class="comments border"> <div class="comments border">
<?php if ($type == 'blogpost'):?>
<?php if (disqus(null, null) == true):?>
<div id="disqus_thread"></div>
<?php endif;?>
<?php if (disqus(null, null) == true):?>
<div id="disqus_thread"></div>
<?php endif;?> <?php endif;?>
</div> </div>
<?php if ($type == 'blogpost'):?>
<div class="postnav">
<?php if (!empty($next)):?>
<span><a href="<?php echo ($next['url']);?>" class="pagination-arrow newer" rel="next"><?php echo ($next['title']);?></a></span>
<?php endif;?>
<div class="postnav">
<?php if (!empty($next)):?>
<span><a href="<?php echo ($next['url']);?>" class="pagination-arrow newer" rel="next"><?php echo ($next['title']);?></a></span>
<?php endif;?>
<?php if (!empty($prev)):?>
<span><a href="<?php echo ($prev['url']); ?>" class="pagination-arrow older" rel="prev"><?php echo ($prev['title']); ?></a></span>
<?php endif;?>
</div>
<?php endif;?>
<?php if ($type == 'blogpost'):?>
<?php if (disqus(null, null) == true):?>
<?php echo disqus($p->title, $p->url) ?>
<?php if (!empty($prev)):?>
<span><a href="<?php echo ($prev['url']); ?>" class="pagination-arrow older" rel="prev"><?php echo ($prev['title']); ?></a></span>
<?php endif;?> <?php endif;?>
</div>
<?php if (disqus(null, null) == true):?>
<?php echo disqus($p->title, $p->url) ?>
<?php endif;?> <?php endif;?>
</div> </div>

+ 4
- 4
themes/clean/profile.html.php View File

@ -10,17 +10,17 @@
<?php foreach($posts as $p):?> <?php foreach($posts as $p):?>
<?php <?php
if ($i == 0) { if ($i == 0) {
$class = 'first';
$class = 'item first';
} }
elseif ($i == $len - 1) { elseif ($i == $len - 1) {
$class = 'last';
$class = 'item last';
} }
else { else {
$class = '';
$class = 'item';
} }
$i++; $i++;
?> ?>
<li>
<li class="<?php echo $class;?>">
<span><a href="<?php echo $p->url?>"><?php echo $p->title ?></a></span> on <span><?php echo date('d F Y', $p->date)?></span> - Posted in <span><?php echo $p->tag ?></span> <span><a href="<?php echo $p->url?>"><?php echo $p->title ?></a></span> on <span><?php echo date('d F Y', $p->date)?></span> - Posted in <span><?php echo $p->tag ?></span>
</li> </li>
<?php endforeach;?> <?php endforeach;?>


+ 10
- 0
themes/clean/static.html.php View File

@ -0,0 +1,10 @@
<?php if (!empty($breadcrumb)):?><div class="breadcrumb" xmlns:v="http://rdf.data-vocabulary.org/#"><?php echo $breadcrumb ?></div><?php endif;?>
<?php if(login()) { echo tab($p);} ?>
<div class="post" itemprop="WebPage" itemscope="itemscope" itemtype="http://schema.org/WebPage">
<div class="main">
<h1 class="title-post" itemprop="name"><?php echo $p->title ?></h1>
<div class="post-body" itemprop="mainContentOfPage">
<?php echo $p->body; ?>
</div>
</div>
</div>

+ 5
- 0
themes/default/css/style.css View File

@ -786,6 +786,11 @@ h1.title-post a:hover, h2.title-index a:hover {
width: 33%; width: 33%;
} }
.archive .toggle {
font-family: Georgia,Arial,sans-serif;
font-size: 16px;
}
.social { .social {
float:right; float:right;
} }


+ 4
- 4
themes/default/main.html.php View File

@ -3,17 +3,17 @@
<?php foreach($posts as $p):?> <?php foreach($posts as $p):?>
<?php <?php
if ($i == 0) { if ($i == 0) {
$class = 'first';
$class = 'post first';
} }
elseif ($i == $len - 1) { elseif ($i == $len - 1) {
$class = 'last';
$class = 'post last';
} }
else { else {
$class = '';
$class = 'post';
} }
$i++; $i++;
?> ?>
<div class="post <?php echo $class ?>" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
<div class="<?php echo $class ?>" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
<div class="main"> <div class="main">
<h2 class="title-index" itemprop="name"><a href="<?php echo $p->url?>"><?php echo $p->title ?></a></h2> <h2 class="title-index" itemprop="name"><a href="<?php echo $p->url?>"><?php echo $p->title ?></a></h2>
<div class="date"><span itemprop="datePublished"><?php echo date('d F Y', $p->date)?></span> - Posted in <span itemprop="articleSection"><?php echo $p->tag ?></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span><?php if (disqus_count() == true):?> - <span><a href="<?php echo $p->url?>#disqus_thread">Comments</a></span><?php endif;?></div> <div class="date"><span itemprop="datePublished"><?php echo date('d F Y', $p->date)?></span> - Posted in <span itemprop="articleSection"><?php echo $p->tag ?></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span><?php if (disqus_count() == true):?> - <span><a href="<?php echo $p->url?>#disqus_thread">Comments</a></span><?php endif;?></div>


+ 30
- 37
themes/default/post.html.php View File

@ -2,53 +2,46 @@
<?php if(login()) { echo tab($p);} ?> <?php if(login()) { echo tab($p);} ?>
<div class="post" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting"> <div class="post" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
<div class="main"> <div class="main">
<?php if ($type == 'blogpost'):?>
<a name="more"></a>
<?php endif;?>
<a name="more"></a>
<h1 class="title-post" itemprop="name"><?php echo $p->title ?></h1> <h1 class="title-post" itemprop="name"><?php echo $p->title ?></h1>
<?php if ($type == 'blogpost'):?>
<div class="date"><span itemprop="datePublished"><a href="<?php echo $p->archive ?>" title="Show all posts made on this day"><?php echo date('d F Y', $p->date)?></a></span> - Posted in <span itemprop="articleSection"><?php echo $p->tag ?></span> by <span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span> - <span><a href="<?php echo $p->url ?>" rel="permalink">Permalink</a></span></div>
<?php endif;?>
<div class="date">
<span itemprop="datePublished"><a href="<?php echo $p->archive ?>" title="Show all posts made on this day"><?php echo date('d F Y', $p->date)?></a></span> - Posted in
<span itemprop="articleSection"><?php echo $p->tag ?></span> by
<span itemprop="author"><a href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></span> -
<span><a href="<?php echo $p->url ?>" rel="permalink">Permalink</a></span>
</div>
<div class="post-body" itemprop="articleBody"> <div class="post-body" itemprop="articleBody">
<?php echo $p->body; ?> <?php echo $p->body; ?>
</div> </div>
</div> </div>
<?php if ($type == 'blogpost'):?>
<div class="separator">&rarr;</div>
<div class="share-box">
<?php if (config('author.info') == 'true'):?>
<?php echo $authorinfo ?>
<?php endif;?>
<div class="share">
<h4>Share this post</h4>
<a class="twitter" target="_blank" href="https://twitter.com/share?url=<?php echo $p->url ?>&text=<?php echo $p->title?>">Twitter</a>
<a class="facebook" target="_blank" href="https://www.facebook.com/sharer.php?u=<?php echo $p->url ?>&t=<?php echo $p->title?>">Facebook</a>
<a class="googleplus" target="_blank" href="https://plus.google.com/share?url=<?php echo $p->url ?>">Google+</a>
</div>
<div class="separator">&rarr;</div>
<div class="share-box">
<?php if (config('author.info') == 'true'):?>
<?php echo $authorinfo ?>
<?php endif;?>
<div class="share">
<h4>Share this post</h4>
<a class="twitter" target="_blank" href="https://twitter.com/share?url=<?php echo $p->url ?>&text=<?php echo $p->title?>">Twitter</a>
<a class="facebook" target="_blank" href="https://www.facebook.com/sharer.php?u=<?php echo $p->url ?>&t=<?php echo $p->title?>">Facebook</a>
<a class="googleplus" target="_blank" href="https://plus.google.com/share?url=<?php echo $p->url ?>">Google+</a>
</div> </div>
<?php endif;?>
<?php if ($type == 'blogpost'):?><?php echo get_related($p->tag)?><?php endif;?>
</div>
<?php echo get_related($p->tag)?>
<div class="comments border"> <div class="comments border">
<?php if ($type == 'blogpost'):?>
<?php if (disqus(null, null) == true):?>
<div id="disqus_thread"></div>
<?php endif;?>
<?php if (disqus(null, null) == true):?>
<div id="disqus_thread"></div>
<?php endif;?> <?php endif;?>
</div> </div>
<?php if ($type == 'blogpost'):?>
<div class="postnav">
<?php if (!empty($next)):?>
<span><a href="<?php echo ($next['url']);?>" class="pagination-arrow newer" rel="next"><?php echo ($next['title']);?></a></span>
<?php endif;?>
<div class="postnav">
<?php if (!empty($next)):?>
<span><a href="<?php echo ($next['url']);?>" class="pagination-arrow newer" rel="next"><?php echo ($next['title']);?></a></span>
<?php endif;?>
<?php if (!empty($prev)):?>
<span><a href="<?php echo ($prev['url']); ?>" class="pagination-arrow older" rel="prev"><?php echo ($prev['title']); ?></a></span>
<?php endif;?>
</div>
<?php endif;?>
<?php if ($type == 'blogpost'):?>
<?php if (disqus(null, null) == true):?>
<?php echo disqus($p->title, $p->url) ?>
<?php if (!empty($prev)):?>
<span><a href="<?php echo ($prev['url']); ?>" class="pagination-arrow older" rel="prev"><?php echo ($prev['title']); ?></a></span>
<?php endif;?> <?php endif;?>
</div>
<?php if (disqus(null, null) == true):?>
<?php echo disqus($p->title, $p->url) ?>
<?php endif;?> <?php endif;?>
</div> </div>

+ 4
- 4
themes/default/profile.html.php View File

@ -10,17 +10,17 @@
<?php foreach($posts as $p):?> <?php foreach($posts as $p):?>
<?php <?php
if ($i == 0) { if ($i == 0) {
$class = 'first';
$class = 'item first';
} }
elseif ($i == $len - 1) { elseif ($i == $len - 1) {
$class = 'last';
$class = 'item last';
} }
else { else {
$class = '';
$class = 'item';
} }
$i++; $i++;
?> ?>
<li>
<li class="<?php echo $class;?>">
<span><a href="<?php echo $p->url?>"><?php echo $p->title ?></a></span> on <span><?php echo date('d F Y', $p->date)?></span> - Posted in <span><?php echo $p->tag ?></span> <span><a href="<?php echo $p->url?>"><?php echo $p->title ?></a></span> on <span><?php echo date('d F Y', $p->date)?></span> - Posted in <span><?php echo $p->tag ?></span>
</li> </li>
<?php endforeach;?> <?php endforeach;?>


+ 10
- 0
themes/default/static.html.php View File

@ -0,0 +1,10 @@
<?php if (!empty($breadcrumb)):?><div class="breadcrumb" xmlns:v="http://rdf.data-vocabulary.org/#"><?php echo $breadcrumb ?></div><?php endif;?>
<?php if(login()) { echo tab($p);} ?>
<div class="post" itemprop="WebPage" itemscope="itemscope" itemtype="http://schema.org/WebPage">
<div class="main">
<h1 class="title-post" itemprop="name"><?php echo $p->title ?></h1>
<div class="post-body" itemprop="mainContentOfPage">
<?php echo $p->body; ?>
</div>
</div>
</div>

Loading…
Cancel
Save