Skip to content

Commit

Permalink
Try to use cache index
Browse files Browse the repository at this point in the history
Try to use cache index. Any glob results will saved as txt format.
  • Loading branch information
danpros committed Jun 20, 2014
1 parent 90a07f1 commit 58d0324
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 60 deletions.
24 changes: 17 additions & 7 deletions system/admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null)
$oldurl = explode('_', $oldfile);

$post_title = $title;
$post_tag = preg_replace('/[^A-Za-z0-9,.-]/u', '', $tag);
$post_tag = str_replace(' ', '-',$post_tag);
$post_tag = rtrim(ltrim($post_tag, ',\.\-'), ',\.\-');
$post_tag = preg_replace(array('/[^a-zA-Z0-9,.-]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag));
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;

Expand Down Expand Up @@ -76,6 +74,8 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null)
// The post URL
$posturl = site_url().date('Y/m', $postdate).'/'.$post_url;

rebuilt_cache('all');

if ($destination == 'post') {
header("Location: $posturl");
}
Expand Down Expand Up @@ -112,6 +112,8 @@ function edit_page($title, $url, $content, $oldfile, $destination = null) {

$posturl = site_url() . $post_url;

rebuilt_cache('all');

if ($destination == 'post') {
header("Location: $posturl");
}
Expand All @@ -129,8 +131,7 @@ function add_post($title, $tag, $url, $content, $user) {

$post_date = date('Y-m-d-H-i-s');
$post_title = $title;
$post_tag = preg_replace('/[^A-Za-z0-9,.-]/u', '', $tag);
$post_tag = rtrim(ltrim($post_tag, ',\.\-'), ',\.\-');
$post_tag = preg_replace(array('/[^a-zA-Z0-9,.-]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tag));
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;

Expand All @@ -147,6 +148,9 @@ function add_post($title, $tag, $url, $content, $user) {
mkdir($dir, 0777, true);
file_put_contents($dir . $filename, print_r($post_content, true));
}

rebuilt_cache('all');

$redirect = site_url() . 'admin/mine';
header("Location: $redirect");
}
Expand All @@ -173,6 +177,9 @@ function add_page($title, $url, $content) {
mkdir($dir, 0777, true);
file_put_contents($dir . $filename, print_r($post_content, true));
}

rebuilt_cache('all');

$redirect = site_url() . 'admin';
header("Location: $redirect");
}
Expand All @@ -184,6 +191,7 @@ function delete_post($file, $destination) {
$deleted_content = $file;
if(!empty($deleted_content)) {
unlink($deleted_content);
rebuilt_cache('all');
if($destination == 'post') {
$redirect = site_url();
header("Location: $redirect");
Expand All @@ -200,6 +208,7 @@ function delete_page($file, $destination) {
$deleted_content = $file;
if(!empty($deleted_content)) {
unlink($deleted_content);
rebuilt_cache('all');
if($destination == 'post') {
$redirect = site_url();
header("Location: $redirect");
Expand Down Expand Up @@ -230,6 +239,7 @@ function edit_profile($title, $content, $user) {
mkdir($dir, 0777, true);
file_put_contents($filename, print_r($user_content, true));
}
rebuilt_cache('all');
$redirect = site_url() . 'author/' . $user;
header("Location: $redirect");
}
Expand Down Expand Up @@ -263,7 +273,7 @@ function migrate($title, $time, $tags, $content, $url, $user, $source) {
mkdir($dir, 0777, true);
file_put_contents($dir . $filename, print_r($post_content, true));
}

rebuilt_cache('all');
$redirect = site_url() . 'admin/mine';
header("Location: $redirect");
}
Expand All @@ -290,7 +300,7 @@ function get_feed($feed_url, $credit, $message=null) {
$time = new DateTime($entry->pubDate);
$timestamp= $time->format("Y-m-d H:i:s");
$time = strtotime($timestamp);
$tags = strip_tags(preg_replace('/[^A-Za-z0-9,.-]/u', '', $entry->category));
$tags = strip_tags(preg_replace(array('/[^a-zA-Z0-9,.-]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($entry->category)));
$title = rtrim($entry->title, ' \,\.\-');
$title = ltrim($title, ' \,\.\-');
$user = $_SESSION['user'];
Expand Down
7 changes: 7 additions & 0 deletions system/admin/views/rebuilt-cache.html.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

rebuilt_cache('all');

echo 'All cache has been rebuilt!';

?>
30 changes: 23 additions & 7 deletions system/htmly.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@
// Edit blog post
get('/:year/:month/:name/edit', function($year, $month, $name){

$user = $_SESSION['user'];
$role = user('role', $user);

if(login()) {

$user = $_SESSION['user'];
$role = user('role', $user);

config('views.root', 'system/admin/views');
$post = find_post($year, $month, $name);
Expand Down Expand Up @@ -231,12 +231,11 @@
// Delete blog post
get('/:year/:month/:name/delete', function($year, $month, $name){

$user = $_SESSION['user'];

$role = user('role', $user);

if(login()) {

$user = $_SESSION['user'];
$role = user('role', $user);

config('views.root', 'system/admin/views');
$post = find_post($year, $month, $name);

Expand Down Expand Up @@ -896,6 +895,23 @@
die;
});

// Create Zip file
get('/admin/rebuilt-cache',function(){
if(login()) {
config('views.root', 'system/admin/views');
render('rebuilt-cache', array(
'head_contents' => head_contents('Rebuilt cache started - ' . blog_title(), blog_description(), site_url()),
'bodyclass' => 'rebuiltcache',
'breadcrumb' => '<a href="' . site_url() . '">' .config('breadcrumb.home'). '</a> &#187; Rebuilt cache started'
));
}
else {
$login = site_url() . 'login';
header("location: $login");
}
die;
});


// The tag page
get('/tag/:tag',function($tag){
Expand Down
Loading

0 comments on commit 58d0324

Please sign in to comment.