Browse Source

Improve backup

Add blog title to the zip file. Improve the URL creation.
pull/31/merge
Danang Probo Sayekti 11 years ago
parent
commit
570856a908
4 changed files with 75 additions and 93 deletions
  1. +1
    -1
      .htaccess
  2. +6
    -0
      system/admin/admin.php
  3. +9
    -2
      system/admin/views/backup-start.html.php
  4. +59
    -90
      system/includes/functions.php

+ 1
- 1
.htaccess View File

@ -84,7 +84,7 @@ DirectoryIndex index.php index.html index.htm
# Pass all requests not referring directly to files in the filesystem to index.php. # Pass all requests not referring directly to files in the filesystem to index.php.
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
RewriteRule ^ index.php [L]
</IfModule> </IfModule>


+ 6
- 0
system/admin/admin.php View File

@ -43,6 +43,7 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null)
$post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url));
$post_url = str_replace(' ', '-',$post_url); $post_url = str_replace(' ', '-',$post_url);
$post_url = str_replace('--', '-',$post_url); $post_url = str_replace('--', '-',$post_url);
$post_url = str_replace('--', '-',$post_url);
$post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-');
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content; $post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
@ -92,6 +93,7 @@ function edit_page($title, $url, $content, $oldfile, $destination = null) {
$post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url));
$post_url = str_replace(' ', '-',$post_url); $post_url = str_replace(' ', '-',$post_url);
$post_url = str_replace('--', '-',$post_url); $post_url = str_replace('--', '-',$post_url);
$post_url = str_replace('--', '-',$post_url);
$post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-');
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content; $post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
@ -132,6 +134,7 @@ function add_post($title, $tag, $url, $content, $user) {
$post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url));
$post_url = str_replace(' ', '-',$post_url); $post_url = str_replace(' ', '-',$post_url);
$post_url = str_replace('--', '-',$post_url); $post_url = str_replace('--', '-',$post_url);
$post_url = str_replace('--', '-',$post_url);
$post_url = rtrim(ltrim($post_url, ' \,\.\-'), ' \,\.\-'); $post_url = rtrim(ltrim($post_url, ' \,\.\-'), ' \,\.\-');
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content; $post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
@ -161,6 +164,7 @@ function add_page($title, $url, $content) {
$post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url));
$post_url = str_replace(' ', '-',$post_url); $post_url = str_replace(' ', '-',$post_url);
$post_url = str_replace('--', '-',$post_url); $post_url = str_replace('--', '-',$post_url);
$post_url = str_replace('--', '-',$post_url);
$post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-');
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content; $post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
@ -250,6 +254,7 @@ function migrate($title, $time, $tags, $content, $url, $user, $source) {
$post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url)); $post_url = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($url));
$post_url = str_replace(' ', '-',$post_url); $post_url = str_replace(' ', '-',$post_url);
$post_url = str_replace('--', '-',$post_url); $post_url = str_replace('--', '-',$post_url);
$post_url = str_replace('--', '-',$post_url);
$post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-');
if(!empty($source)) { if(!empty($source)) {
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content . "\n\n" . 'Source: <a target="_blank" href="' . $source . '">' . $title . '</a>'; $post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content . "\n\n" . 'Source: <a target="_blank" href="' . $source . '">' . $title . '</a>';
@ -304,6 +309,7 @@ function get_feed($feed_url, $credit, $message=null) {
$url = preg_replace('/[^A-Za-z0-9 .-]/u', '', strtolower($title)); $url = preg_replace('/[^A-Za-z0-9 .-]/u', '', strtolower($title));
$url = str_replace(' ', '-',$url); $url = str_replace(' ', '-',$url);
$url = str_replace('--', '-',$url); $url = str_replace('--', '-',$url);
$url = str_replace('--', '-',$url);
$url = rtrim($url, ',\.\-'); $url = rtrim($url, ',\.\-');
$url = ltrim($url, ',\.\-'); $url = ltrim($url, ',\.\-');
if ($credit == 'yes') { if ($credit == 'yes') {


+ 9
- 2
system/admin/views/backup-start.html.php View File

@ -1,14 +1,21 @@
<?php <?php
$title = config('blog.title');
$name = preg_replace('/[^A-Za-z0-9 ,.-]/u', '', strtolower($title));
$name = str_replace(' ', '-',$name);
$name = str_replace('--', '-',$name);
$name = str_replace('--', '-',$name);
$name = rtrim(ltrim($name, ' \,\.\-'), ' \,\.\-');
$timestamp = date('Y-m-d-H-i-s'); $timestamp = date('Y-m-d-H-i-s');
$dir = 'backup'; $dir = 'backup';
if(is_dir($dir)) { if(is_dir($dir)) {
Zip('content/', 'backup/content_' . $timestamp . '.zip', true);
Zip('content/', 'backup/' . $name . '_' . $timestamp . '.zip', true);
} }
else { else {
mkdir($dir, 0777, true); mkdir($dir, 0777, true);
Zip('content/', 'backup/content_' . $timestamp . '.zip', true);
Zip('content/', 'backup/' . $name . '_' . $timestamp . '.zip', true);
} }
$redirect = site_url() . 'admin/backup'; $redirect = site_url() . 'admin/backup';


+ 59
- 90
system/includes/functions.php View File

@ -891,40 +891,8 @@ function recent_comments(){
var heading ='<h3>Comments</h3>'; var heading ='<h3>Comments</h3>';
document.write(heading); document.write(heading);
</script> </script>
<script type="text/javascript" src="http://{$disqus}.disqus.com/recent_comments_widget.js?num_items=5&hide_avatars=0&avatar_size=48&excerpt_length=200&hide_mods=0"></script>
<style>
li.dsq-widget-item {
border-bottom: 1px solid #ebebeb;
margin:0;
margin-bottom:10px;
padding:0;
padding-bottom:10px;
}
a.dsq-widget-user {
font-weight:normal;
}
img.dsq-widget-avatar {
margin-right:10px;
}
.dsq-widget-comment {
display:block;
padding-top:5px;
}
.dsq-widget-comment p {
display:block;
margin:0;
}
p.dsq-widget-meta {
padding-top:5px;
margin:0;
}
#dsq-combo-widget.grey #dsq-combo-content .dsq-combo-box {
background: transparent;
}
#dsq-combo-widget.grey #dsq-combo-tabs li {
background: none repeat scroll 0 0 #DDDDDD;
}
</style>
<script type="text/javascript" src="//{$disqus}.disqus.com/recent_comments_widget.js?num_items=5&hide_avatars=0&avatar_size=48&excerpt_length=200&hide_mods=0"></script>
<style>li.dsq-widget-item {border-bottom: 1px solid #ebebeb;margin:0;margin-bottom:10px;padding:0;padding-bottom:10px;}a.dsq-widget-user {font-weight:normal;}img.dsq-widget-avatar {margin-right:10px; }.dsq-widget-comment {display:block;padding-top:5px;}.dsq-widget-comment p {display:block;margin:0;}p.dsq-widget-meta {padding-top:5px;margin:0;}#dsq-combo-widget.grey #dsq-combo-content .dsq-combo-box {background: transparent;}#dsq-combo-widget.grey #dsq-combo-tabs li {background: none repeat scroll 0 0 #DDDDDD;}</style>
EOF; EOF;
if (!empty($disqus) && $comment == 'disqus') { if (!empty($disqus) && $comment == 'disqus') {
return $script; return $script;
@ -990,31 +958,29 @@ function menu(){
$links = explode('|', $menu); $links = explode('|', $menu);
echo '<ul class="nav">'; echo '<ul class="nav">';
if($req == site_path() . '/') {
echo '<li class="item first active"><a href="' . site_url() . '">' .config('breadcrumb.home'). '</a></li>';
}
else {
echo '<li class="item first"><a href="' . site_url() . '">' .config('breadcrumb.home'). '</a></li>';
}
$i = 0; $i = 0;
$len = count($links); $len = count($links);
foreach($links as $link) { foreach($links as $link) {
if ($i == $len - 1) {
if ($i == 0) {
$class = 'item first';
}
elseif ($i == $len - 1) {
$class = 'item last'; $class = 'item last';
} }
else { else {
$class = 'item'; $class = 'item';
} }
$i++;
$i++;
$anc = explode('->', $link); $anc = explode('->', $link);
if(isset($anc[0]) && isset($anc[1])) { if(isset($anc[0]) && isset($anc[1])) {
if(strpos($link, site_url()) !== false) {
if(strpos(rtrim($anc[1],'/').'/', site_url()) !== false) {
$id = substr($link, strrpos($link, '/')+1 ); $id = substr($link, strrpos($link, '/')+1 );
$file = 'content/static/' . $id . '.md'; $file = 'content/static/' . $id . '.md';
if(file_exists($file)) { if(file_exists($file)) {
@ -1026,7 +992,14 @@ function menu(){
} }
} }
else { else {
echo '<li class="' . $class . '"><a href="' . $anc[1] . '">' . $anc[0] . '</a></li>';
if (rtrim($anc[1],'/').'/' == site_url()) {
if($req == site_path() . '/') {
echo '<li class="' . $class . ' active"><a href="' . site_url() . '">' .config('breadcrumb.home'). '</a></li>';
}
else {
echo '<li class="' . $class . '"><a href="' . site_url() . '">' .config('breadcrumb.home'). '</a></li>';
}
}
} }
} }
else { else {
@ -1112,6 +1085,7 @@ function get_menu() {
else { else {
echo '<li class="item first"><a href="' . site_url() . '">' .config('breadcrumb.home'). '</a></li>'; echo '<li class="item first"><a href="' . site_url() . '">' .config('breadcrumb.home'). '</a></li>';
} }
echo '</ul>';
} }
@ -1448,53 +1422,48 @@ function generate_json($posts){
return json_encode($posts); return json_encode($posts);
} }
// Create Zip files // Create Zip files
function Zip($source, $destination, $include_dir = false)
{
if (!extension_loaded('zip') || !file_exists($source)) {
return false;
}
if (file_exists($destination)) {
unlink ($destination);
}
$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
return false;
}
if (is_dir($source) === true)
{
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file)
{
$file = str_replace('\\', '/', $file);
// Ignore "." and ".." folders
if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
continue;
if (is_dir($file) === true)
{
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
}
else if (is_file($file) === true)
{
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
}
else if (is_file($source) === true)
{
$zip->addFromString(basename($source), file_get_contents($source));
}
return $zip->close();
function Zip($source, $destination, $include_dir = false) {
if (!extension_loaded('zip') || !file_exists($source)) {
return false;
}
if (file_exists($destination)) {
unlink ($destination);
}
$zip = new ZipArchive();
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
return false;
}
if (is_dir($source) === true) {
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
foreach ($files as $file) {
$file = str_replace('\\', '/', $file);
// Ignore "." and ".." folders
if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
continue;
if (is_dir($file) === true) {
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
}
else if (is_file($file) === true) {
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
}
}
}
else if (is_file($source) === true) {
$zip->addFromString(basename($source), file_get_contents($source));
}
return $zip->close();
} }
// TRUE if the current page is the front page. // TRUE if the current page is the front page.


Loading…
Cancel
Save