Browse Source

Cleaning up

Cleaning up the codes.
pull/31/merge
Danang Probo Sayekti 12 years ago
parent
commit
daa3d40c3b
5 changed files with 55 additions and 44 deletions
  1. +9
    -14
      system/admin/admin.php
  2. +2
    -2
      system/admin/views/posts-list.html.php
  3. +6
    -5
      system/htmly.php
  4. +32
    -23
      system/includes/functions.php
  5. +6
    -0
      themes/default/css/style.css

+ 9
- 14
system/admin/admin.php View File

@ -180,20 +180,20 @@ function add_page($title, $url, $content) {
} }
function delete_post($file) {
function delete_post($file, $destination) {
$deleted_content = $file; $deleted_content = $file;
if(!empty($deleted_content)) { if(!empty($deleted_content)) {
unlink($deleted_content); unlink($deleted_content);
$redirect = site_url() . 'admin/posts';
$redirect = site_url() . $destination;
header("Location: $redirect"); header("Location: $redirect");
} }
} }
function delete_page($file) {
function delete_page($file, $destination) {
$deleted_content = $file; $deleted_content = $file;
if(!empty($deleted_content)) { if(!empty($deleted_content)) {
unlink($deleted_content); unlink($deleted_content);
$redirect = site_url() . 'admin';
$redirect = site_url() . $destination;
header("Location: $redirect"); header("Location: $redirect");
} }
} }
@ -224,23 +224,19 @@ function edit_profile($title, $content, $user) {
function get_recent_posts() { function get_recent_posts() {
if (isset($_SESSION['user'])) { if (isset($_SESSION['user'])) {
$posts = get_profile($_SESSION['user'], 1, 5); $posts = get_profile($_SESSION['user'], 1, 5);
if(!empty($posts)) { if(!empty($posts)) {
echo '<table>';
echo '<table class="post-list">';
echo '<tr><th>Title</th><th>Published</th><th>Tag</th><th>Operations</th></tr>'; echo '<tr><th>Title</th><th>Published</th><th>Tag</th><th>Operations</th></tr>';
foreach($posts as $p) { foreach($posts as $p) {
echo '<tr>'; echo '<tr>';
echo '<td>' . $p->title . '</td>';
echo '<td><a target="_blank" href="' . $p->url . '">' . $p->title . '</a></td>';
echo '<td>' . date('d F Y', $p->date) . '</td>'; echo '<td>' . date('d F Y', $p->date) . '</td>';
echo '<td>' . $p->tag . '</td>'; echo '<td>' . $p->tag . '</td>';
echo '<td><a href="' . $p->url . '/edit?destination=admin">Edit</a> <a href="' . $p->url . '/delete?destination=admin">Delete</a></td>'; echo '<td><a href="' . $p->url . '/edit?destination=admin">Edit</a> <a href="' . $p->url . '/delete?destination=admin">Delete</a></td>';
echo '</tr>'; echo '</tr>';
} }
echo '</table>'; echo '</table>';
} }
} }
} }
@ -251,16 +247,15 @@ function get_recent_pages() {
$posts = get_static_post(null); $posts = get_static_post(null);
if(!empty($posts)) { if(!empty($posts)) {
krsort($posts); krsort($posts);
echo '<table>';
echo '<table class="post-list">';
echo '<tr><th>Title</th><th>Operations</th></tr>'; echo '<tr><th>Title</th><th>Operations</th></tr>';
foreach($posts as $p) { foreach($posts as $p) {
echo '<tr>'; echo '<tr>';
echo '<td>' . $p->title . '</td>';
echo '<td><a target="_blank" href="' . $p->url . '">' . $p->title . '</a></td>';
echo '<td><a href="' . $p->url . '/edit?destination=admin">Edit</a> <a href="' . $p->url . '/delete?destination=admin">Delete</a></td>'; echo '<td><a href="' . $p->url . '/edit?destination=admin">Edit</a> <a href="' . $p->url . '/delete?destination=admin">Delete</a></td>';
echo '</tr>'; echo '</tr>';
} }
echo '</table>'; echo '</table>';
} }
} }
}
}

+ 2
- 2
system/admin/views/posts-list.html.php View File

@ -17,10 +17,10 @@
$i++; $i++;
?> ?>
<tr> <tr>
<td><?php echo $p->title ?></td>
<td><a target="_blank" href="<?php echo $p->url ?>"><?php echo $p->title ?></a></td>
<td><?php echo date('d F Y', $p->date) ?></td> <td><?php echo date('d F Y', $p->date) ?></td>
<td><?php echo $p->tag ?></td> <td><?php echo $p->tag ?></td>
<td><a href="<?php echo $p->url ?>/edit?destination=admin/posts">Edit</a> <a href="<?php echo $p->url ?>/delete">Delete</a></td>
<td><a href="<?php echo $p->url ?>/edit?destination=admin/posts">Edit</a> <a href="<?php echo $p->url ?>/delete?destination=admin/posts">Delete</a></td>
</tr> </tr>
<?php endforeach;?> <?php endforeach;?>
</table> </table>


+ 6
- 5
system/htmly.php View File

@ -179,9 +179,10 @@ get('/:year/:month/:name/delete', function($year, $month, $name){
// Get deleted data for blog post // Get deleted data for blog post
post('/:year/:month/:name/delete', function() { post('/:year/:month/:name/delete', function() {
$file = from($_REQUEST, 'file'); $file = from($_REQUEST, 'file');
delete_post($file);
$destination = from($_GET, 'destination');
delete_post($file, $destination);
}); });
@ -501,8 +502,8 @@ get('/:static/delete', function($static){
post('/:static/delete', function() { post('/:static/delete', function() {
$file = from($_REQUEST, 'file'); $file = from($_REQUEST, 'file');
delete_post($file);
$destination = from($_GET, 'destination');
delete_page($file, $destination);
}); });
@ -591,7 +592,7 @@ get('/tag/:tag',function($tag){
'page' => $page, 'page' => $page,
'posts' => $posts, 'posts' => $posts,
'canonical' => config('site.url') . '/tag/' . $tag, 'canonical' => config('site.url') . '/tag/' . $tag,
'description' => 'All posts tagged ' . $tag . ' on '. config('blog.title') . '.',
'description' => 'All posts tagged: ' . $tag . ' on '. config('blog.title') . '.',
'bodyclass' => 'intag', 'bodyclass' => 'intag',
'breadcrumb' => '<a href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a> &#187; Posts tagged: ' . $tag, 'breadcrumb' => '<a href="' . config('site.url') . '">' .config('breadcrumb.home'). '</a> &#187; Posts tagged: ' . $tag,
'pagination' => has_pagination($total, $perpage, $page) 'pagination' => has_pagination($total, $perpage, $page)


+ 32
- 23
system/includes/functions.php View File

@ -362,11 +362,11 @@ function default_profile($author) {
function get_static_post($static){ function get_static_post($static){
$posts = get_static_pages(); $posts = get_static_pages();
$tmp = array();
if(!empty($posts)) { if(!empty($posts)) {
$tmp = array();
foreach($posts as $index => $v){ foreach($posts as $index => $v){
if(strpos($v, $static.'.md') !== false){ if(strpos($v, $static.'.md') !== false){
@ -399,16 +399,18 @@ function get_static_post($static){
} }
} }
return $tmp;
} }
return $tmp;
} }
// Return search page. // Return search page.
function get_keyword($keyword){ function get_keyword($keyword){
$posts = get_post_unsorted(); $posts = get_post_unsorted();
$tmp = array(); $tmp = array();
$words = explode(' ', $keyword); $words = explode(' ', $keyword);
@ -486,12 +488,10 @@ function get_keyword($keyword){
$tmp = array_unique($tmp, SORT_REGULAR); $tmp = array_unique($tmp, SORT_REGULAR);
usort($tmp,'sortdate'); usort($tmp,'sortdate');
return $tmp;
}
else {
return $tmp;
} }
return $tmp;
} }
// Get related posts base on post tag. // Get related posts base on post tag.
@ -992,23 +992,28 @@ function get_static_path(){
$posts = get_static_pages(); $posts = get_static_pages();
$tmp = array(); $tmp = array();
if(!empty($posts)) {
foreach($posts as $index => $v){
$post = new stdClass;
// Replaced string
$replaced = substr($v, 0, strrpos($v, '/')) . '/';
// The static page URL
$url = str_replace($replaced,'',$v);
$post->url = site_url() . str_replace('.md','',$url);
$tmp[] = $post;
foreach($posts as $index => $v){
$post = new stdClass;
// Replaced string
$replaced = substr($v, 0, strrpos($v, '/')) . '/';
// The static page URL
$url = str_replace($replaced,'',$v);
$post->url = site_url() . str_replace('.md','',$url);
$tmp[] = $post;
}
} }
return $tmp; return $tmp;
} }
// Generate sitemap.xml. // Generate sitemap.xml.
@ -1054,8 +1059,12 @@ function generate_sitemap($str){
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
foreach($posts as $p) {
echo '<url><loc>' . $p->url . '</loc><changefreq>monthly</changefreq><priority>0.5</priority></url>';
if(!empty($posts)) {
foreach($posts as $p) {
echo '<url><loc>' . $p->url . '</loc><changefreq>monthly</changefreq><priority>0.5</priority></url>';
}
} }
echo '</urlset>'; echo '</urlset>';


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

@ -316,6 +316,8 @@ table {
color:#333333; color:#333333;
border: 1px solid #E3E3E3; border: 1px solid #E3E3E3;
margin: 1em 0; margin: 1em 0;
white-space: pre-wrap;
word-wrap:break-word;
} }
table h2.title { table h2.title {
@ -355,6 +357,10 @@ td {
border-left:none; border-left:none;
} }
table.post-list td a {
margin:0 5px;
}
/*------------------------- /*-------------------------
Menu Menu
--------------------------*/ --------------------------*/


Loading…
Cancel
Save