2014-06-27, 07:13:47
There are a strong bug in GET SIMPLE BLOG: all post are published, included all post with a future date.
For example: if today is 2014/06/26 and you create a new post with 2014/06/30 date, this post will publish and show instead of be hidden until 2014/06/30.
Here, I copy-and paste some code to solve this problem changing the frontEndFunctions.php file :
***************
**********
******************
**********
This last code, has a problem I has not solved in an elegant way.
When using another languaje like spanish, the conversion of archive dates is not possible, so, I must to use a new function to conver "enero 2014" to "01/01/2014" date.
This must be refined, but, if you are using GS Blog in spanish, this must be work fine:
For example: if today is 2014/06/26 and you create a new post with 2014/06/30 date, this post will publish and show instead of be hidden until 2014/06/30.
Here, I copy-and paste some code to solve this problem changing the frontEndFunctions.php file :
PHP Code:
In function show_blog_post you must begin the function like that:
function show_blog_post($slug, $excerpt=false)
{
$Blog = new Blog;
global $SITEURL, $blogSettings, $post;
$post = getXML($slug);
// This solves the problem to publish post with
// a date higer than now.
// get the actual time.
$date_now = strtotime(date("d-m-Y H:i:00",time()));
// get the post time.
$date = strtotime($post->date);
// if post time is lower than actual time, then whow it.
if ($date <= $date_now)
{
... here all the old stuff.
}// end if date <= date_now
}// end of show_blog_post function.
***************
PHP Code:
function show_blog_category($category)
{
$Blog = new Blog;
$all_posts = $Blog->listPosts(true, true);
$count = 0;
$categorytext = i18n_r(BLOGFILE.'/CATEGORYTEXT');
echo '<h4>'.$categorytext.' '.$category.'</h4>';
foreach($all_posts as $file)
{
$data = getXML($file['filename']);
if($data->category == $category || empty($category))
{
// This solves the problem to publish post with
// a date higer than now.
// get the post.
$slug = $file['filename'];
$post = getXML($slug);
// get the actual time.
$date_now = strtotime(date("d-m-Y H:i:00",time()));
// get the post time.
$date = strtotime($post->date);
// if post time is lower than actual time, then whow it.
if ($date <= $date_now)
{
$count++;
show_blog_post($file['filename'], true);
}
}
}
if($count < 1)
{
echo '<p class="blog_category_noposts">'.i18n_r(BLOGFILE.'/NO_POSTS').'</p>';
}
}
**********
PHP Code:
function show_blog_archives()
{
global $blogSettings;
$Blog = new Blog;
$archives = $Blog->get_blog_archives();
if (!empty($archives))
{
echo '<h4>';
i18n(BLOGFILE.'/ARCHIVE');
echo '</h4>';
echo '<ul>';
foreach ($archives as $archive => $archive_data)
{
$post_count = ($blogSettings['archivepostcount'] == 'Y') ? ' ('.$archive_data['count'].')' : '';
$url = $Blog->get_blog_url('archive') . $archive;
// This solves the problem to publish archives with a date higer than present.
// get the actual time.
$date_now = strtotime(date("d-m-Y H:i:00",time()));
// gete the archive time.
$date_archive = strtotime(date_es_to_en($archive_data['title']));
// if archive time is lower than actual time, then show it.
if ($date_archive <= $date_now)
{
echo "<li><a href=\"{$url}\">{$archive_data['title']} {$post_count}</a></li>";
}
}
echo '</ul>';
}
}
******************
PHP Code:
function show_blog_recent_posts($excerpt=false, $excerpt_length=null, $thumbnail=null, $read_more=null)
{
$Blog = new Blog;
$posts = $Blog->listPosts(true, true);
global $SITEURL,$blogSettings;
if (!empty($posts))
{
echo '<ul>';
$posts = array_slice($posts, 0, $blogSettings["recentposts"], TRUE);
foreach ($posts as $file)
{
$data = getXML($file['filename']);
$url = $Blog->get_blog_url('post') . $data->slug;
$title = strip_tags(strip_decode($data->title));
// This solves the problem to publish post with
// a date higer than now.
// get the actual time.
$date_now = strtotime(date("d-m-Y H:i:00",time()));
// get the post time.
$date = strtotime($data->date);
// if post time is lower than actual time, then whow it.
if ($date <= $date_now)
{
if($excerpt != false)
{
if($excerpt_length == null)
{
$excerpt_length = $blogSettings["excerptlength"];
}
$excerpt = $Blog->create_excerpt(html_entity_decode($data->content), 0, $excerpt_length);
if($thumbnail != null)
{
if(!empty($data->thumbnail))
{
$excerpt = '<img src="'.$SITEURL.'data/uploads/'.$data->thumbnail.'" class="blog_recent_posts_thumbnail" />'.$excerpt;
}
}
if($read_more != null)
{
$excerpt = $excerpt.'<br/><a href="'.$url.'" class="recent_posts_read_more">'.$read_more.'</a>';
}
echo '<li><a href="'.$url.'">'.$title.'</a><p class="blog_recent_posts_excerpt">'.$excerpt.'</p></li>';
}
else
{
echo "<li><a href=\"$url\">$title</a></li>";
}
}//end if date <= date_now
}
echo '</ul>';
}
}
**********
This last code, has a problem I has not solved in an elegant way.
When using another languaje like spanish, the conversion of archive dates is not possible, so, I must to use a new function to conver "enero 2014" to "01/01/2014" date.
This must be refined, but, if you are using GS Blog in spanish, this must be work fine:
PHP Code:
// this is a function to translate spanish dates like "enero 2014" to numbers like "1/01/2014"
function date_es_to_en($date_es ) {
$fecha = explode(" ", $date_es);
$anno = $fecha[1];
switch ($fecha[0]) {
case "enero":
$mes = 1;
break;
case "febrero":
$mes = 2;
break;
case "marzo":
$mes = 3;
break;
case "abril":
$mes = 4;
break;
case "mayo":
$mes = 5;
break;
case "junio":
$mes = 6;
break;
case "julio":
$mes = 7;
break;
case "agosto":
$mes = 8;
break;
case "septiembre":
$mes = 9;
break;
case "octubre":
$mes = 10;
break;
case "noviembre":
$mes = 11;
break;
case "diciembre":
$mes = 12;
break;
}
$date_en = $mes."/01/".$anno;
return $date_en;
}