From 570856a9087def8ad5a890952c4ecab0c7b4b812 Mon Sep 17 00:00:00 2001 From: Danang Probo Sayekti Date: Tue, 25 Feb 2014 18:23:55 +0700 Subject: [PATCH] Improve backup Add blog title to the zip file. Improve the URL creation. --- .htaccess | 2 +- system/admin/admin.php | 6 ++ system/admin/views/backup-start.html.php | 11 ++- system/includes/functions.php | 149 ++++++++++++------------------- 4 files changed, 75 insertions(+), 93 deletions(-) diff --git a/.htaccess b/.htaccess index a3f7810..0494820 100644 --- a/.htaccess +++ b/.htaccess @@ -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. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d - RewriteRule . index.php [L] + RewriteRule ^ index.php [L] diff --git a/system/admin/admin.php b/system/admin/admin.php index 112a994..24cc1cb 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -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 = str_replace(' ', '-',$post_url); $post_url = str_replace('--', '-',$post_url); + $post_url = str_replace('--', '-',$post_url); $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); $post_content = '' . "\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 = str_replace(' ', '-',$post_url); $post_url = str_replace('--', '-',$post_url); + $post_url = str_replace('--', '-',$post_url); $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); $post_content = '' . "\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 = str_replace(' ', '-',$post_url); $post_url = str_replace('--', '-',$post_url); + $post_url = str_replace('--', '-',$post_url); $post_url = rtrim(ltrim($post_url, ' \,\.\-'), ' \,\.\-'); $post_content = '' . "\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 = str_replace(' ', '-',$post_url); $post_url = str_replace('--', '-',$post_url); + $post_url = str_replace('--', '-',$post_url); $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); $post_content = '' . "\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 = str_replace(' ', '-',$post_url); $post_url = str_replace('--', '-',$post_url); + $post_url = str_replace('--', '-',$post_url); $post_url = rtrim(ltrim($post_url, ',\.\-'), ',\.\-'); if(!empty($source)) { $post_content = '' . "\n\n" . $content . "\n\n" . 'Source: ' . $title . ''; @@ -304,6 +309,7 @@ function get_feed($feed_url, $credit, $message=null) { $url = preg_replace('/[^A-Za-z0-9 .-]/u', '', strtolower($title)); $url = str_replace(' ', '-',$url); $url = str_replace('--', '-',$url); + $url = str_replace('--', '-',$url); $url = rtrim($url, ',\.\-'); $url = ltrim($url, ',\.\-'); if ($credit == 'yes') { diff --git a/system/admin/views/backup-start.html.php b/system/admin/views/backup-start.html.php index 84454fd..4141b80 100644 --- a/system/admin/views/backup-start.html.php +++ b/system/admin/views/backup-start.html.php @@ -1,14 +1,21 @@ Comments'; document.write(heading); - - + + EOF; if (!empty($disqus) && $comment == 'disqus') { return $script; @@ -990,31 +958,29 @@ function menu(){ $links = explode('|', $menu); echo ''; } @@ -1448,53 +1422,48 @@ function generate_json($posts){ return json_encode($posts); } - // 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.