Browse Source

Merge pull request #76 from Kanti/master

Better "content Tag" handling by @Kanti.
pull/89/head
Danang Probo Sayekti 11 years ago
parent
commit
b3b156bdad
4 changed files with 37 additions and 75 deletions
  1. +2
    -9
      system/admin/views/edit-page.html.php
  2. +2
    -9
      system/admin/views/edit-post.html.php
  3. +2
    -9
      system/admin/views/edit-profile.html.php
  4. +31
    -48
      system/includes/functions.php

+ 2
- 9
system/admin/views/edit-page.html.php View File

@ -7,15 +7,8 @@
$url = $oldfile;
}
$content = file_get_contents($url);
$arr = explode('t-->', $content);
if(isset($arr[1])) {
$oldtitle = ltrim(rtrim(str_replace('<!--t','',$arr[0]), ' '));
$oldcontent = ltrim($arr[1]);
}
else {
$oldtitle = 'Untitled';
$oldcontent = ltrim($arr[0]);
}
$oldtitle = get_content_tag('t',$content,'Untitled');
$oldcontent = remove_html_comments($content);
if(isset($_GET['destination'])) {
$destination = $_GET['destination'];


+ 2
- 9
system/admin/views/edit-post.html.php View File

@ -7,15 +7,8 @@
}
$content = file_get_contents($url);
$arr = explode('t-->', $content);
if(isset($arr[1])) {
$oldtitle = ltrim(rtrim(str_replace('<!--t','',$arr[0]), ' '));
$oldcontent = ltrim($arr[1]);
}
else {
$oldtitle = 'Untitled';
$oldcontent = ltrim($arr[0]);
}
$oldtitle = get_content_tag('t',$content,'Untitled');
$oldcontent = remove_html_comments($content);
$dir = substr($url, 0, strrpos($url, '/'));


+ 2
- 9
system/admin/views/edit-profile.html.php View File

@ -8,15 +8,8 @@
if(file_exists($filename)) {
$content = file_get_contents($filename);
$arr = explode('t-->', $content);
if(isset($arr[1])) {
$oldtitle = ltrim(rtrim(str_replace('<!--t','',$arr[0]), ' '));
$oldcontent = ltrim($arr[1]);
}
else {
$oldtitle = $user;
$oldcontent = ltrim($arr[0]);
}
$oldtitle = get_content_tag('t',$content,'user');
$oldcontent = remove_html_comments($content);
}
else {
$oldtitle = $user;


+ 31
- 48
system/includes/functions.php View File

@ -245,16 +245,8 @@ function get_posts($posts, $page = 1, $perpage = 0) {
$content = MarkdownExtra::defaultTransform(file_get_contents($filepath));
// Extract the title and body
$arr = explode('t-->', $content);
if (isset($arr[1])) {
$title = str_replace('<!--t', '', $arr[0]);
$title = rtrim(ltrim($title, ' '), ' ');
$post->title = $title;
$post->body = $arr[1];
} else {
$post->title = 'Untitled: ' . date('l jS \of F Y', $post->date);
$post->body = $arr[0];
}
$post->title = get_content_tag('t',$content,'Untitled: ' . date('l jS \of F Y', $post->date));
$post->body = remove_html_comments($content);
if(config("views.counter"))
{
@ -421,16 +413,8 @@ function get_bio($author) {
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body
$arr = explode('t-->', $content);
if (isset($arr[1])) {
$title = str_replace('<!--t', '', $arr[0]);
$title = rtrim(ltrim($title, ' '), ' ');
$post->title = $title;
$post->body = $arr[1];
} else {
$post->title = $author;
$post->body = $arr[0];
}
$post->title = get_content_tag('t',$content,$author);
$post->body = remove_html_comments($content);
$tmp[] = $post;
}
@ -482,16 +466,8 @@ function get_static_post($static) {
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body
$arr = explode('t-->', $content);
if (isset($arr[1])) {
$title = str_replace('<!--t', '', $arr[0]);
$title = rtrim(ltrim($title, ' '), ' ');
$post->title = $title;
$post->body = $arr[1];
} else {
$post->title = $static;
$post->body = $arr[0];
}
$post->title = get_content_tag('t',$content,$static);
$post->body = remove_html_comments($content);
if(config("views.counter"))
{
@ -532,16 +508,8 @@ function get_static_sub_post($static,$sub_static) {
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body
$arr = explode('t-->', $content);
if (isset($arr[1])) {
$title = str_replace('<!--t', '', $arr[0]);
$title = rtrim(ltrim($title, ' '), ' ');
$post->title = $title;
$post->body = $arr[1];
} else {
$post->title = $sub_static;
$post->body = $arr[0];
}
$post->title = get_content_tag('t',$content,$sub_static);
$post->body = remove_html_comments($content);
$post->views = get_views($post->file);
@ -1087,15 +1055,11 @@ function get_title_from_file($v)
// Get the contents and convert it to HTML
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
$replaced = substr($v, 0, strrpos($v, '/')) . '/';
$base = str_replace($replaced, '', $v);
// Extract the title and body
$arr = explode('t-->', $content);
if (isset($arr[1])) {
$title = str_replace('<!--t', '', $arr[0]);
$title = rtrim(ltrim($title, ' '), ' ');
} else {
$title = str_replace('-', ' ', str_replace('.md', '', $base));
}
return $title;
return get_content_tag('t',$content,str_replace('-', ' ', str_replace('.md', '', $base)));
}
// Auto generate menu from static page
@ -1716,4 +1680,23 @@ function get_views($page)
return $_views[$page];
}
return -1;
}
function get_content_tag($tag, $string, $alt = null)
{
$reg = '/\<!--'.$tag.'(.+)'.$tag.'--\>/';
$ary = array();
if(preg_match($reg, $string, $ary))
{
if(isset($ary[1]))
{
return trim($ary[1]);
}
}
return $alt;
}
function remove_html_comments($content) {
//return $content;
return trim(preg_replace('/(\s|)<!--(.*)-->(\s|)/', '', $content));
}

Loading…
Cancel
Save