diff --git a/.htaccess b/.htaccess
index 972e6ca..30e94f5 100644
--- a/.htaccess
+++ b/.htaccess
@@ -76,10 +76,9 @@ DirectoryIndex index.php index.html index.htm
# RewriteBase /
# Pass all requests not referring directly to files in the filesystem to index.php.
-RewriteCond %{REQUEST_FILENAME} !-f
-RewriteCond %{REQUEST_FILENAME} !-d
-RewriteCond $1 !^(index\.php)
-RewriteRule ^(.*)$ index.php/$1 [L]
+ RewriteCond %{REQUEST_FILENAME} !-f
+ RewriteCond %{REQUEST_FILENAME} !-d
+ RewriteRule ^ index.php [L]
diff --git a/config/config.ini.example b/config/config.ini.example
index 5312b43..41edb78 100644
--- a/config/config.ini.example
+++ b/config/config.ini.example
@@ -13,7 +13,9 @@ social.facebook = "https://www.facebook.com"
social.google = "https://plus.google.com"
social.tumblr = "http://www.tumblr.com"
-; Custom menu link
+; Custom menu link.
+; See example below:
+; "Google->http://www.google.com|Wikipedia->http://www.wikipedia.org".
blog.menu = ""
; Breadcrumb home text. Useful when installed on subfolder.
diff --git a/system/admin/admin.php b/system/admin/admin.php
index ce00efd..112a994 100644
--- a/system/admin/admin.php
+++ b/system/admin/admin.php
@@ -1,5 +1,6 @@
';
}
}
+}
+
+// Get all available zip files
+function get_backup_files () {
+ if (isset($_SESSION['user'])) {
+ $files = get_zip_files();
+ if(!empty($files)) {
+ krsort($files);
+ echo '
';
+ echo '| Filename | Date | Operations |
';
+ $i = 0; $len = count($files);
+ foreach($files as $file) {
+
+ if ($i == 0) {
+ $class = 'item first';
+ }
+ elseif ($i == $len - 1) {
+ $class = 'item last';
+ }
+ else {
+ $class = 'item';
+ }
+ $i++;
+
+ // Extract the date
+ $arr = explode('_', $file);
+
+ // Replaced string
+ $replaced = substr($arr[0], 0,strrpos($arr[0], '/')) . '/';
+
+ $name = str_replace($replaced,'',$file);
+
+ $date = str_replace('.zip','',$arr[1]);
+ $t = str_replace('-', '', $date);
+ $time = new DateTime($t);
+ $timestamp= $time->format("D, d F Y, H:i:s");
+
+ $url = site_url() . $file;
+ echo '';
+ echo '| ' . $name . ' | ';
+ echo '' . $timestamp . ' | ';
+ echo 'Download | ';
+ echo '
';
+ }
+ echo '
';
+ }
+ else {
+ echo 'No available backup!';
+ }
+ }
}
\ No newline at end of file
diff --git a/system/admin/views/backup-start.html.php b/system/admin/views/backup-start.html.php
new file mode 100644
index 0000000..84454fd
--- /dev/null
+++ b/system/admin/views/backup-start.html.php
@@ -0,0 +1,17 @@
+
\ No newline at end of file
diff --git a/system/admin/views/backup.html.php b/system/admin/views/backup.html.php
new file mode 100644
index 0000000..eb30b4a
--- /dev/null
+++ b/system/admin/views/backup.html.php
@@ -0,0 +1,15 @@
+
+Create backup
+Your backups
+
\ No newline at end of file
diff --git a/system/htmly.php b/system/htmly.php
index a37f48a..67373e5 100644
--- a/system/htmly.php
+++ b/system/htmly.php
@@ -862,6 +862,41 @@ post('/admin/import', function() {
});
+// Backup page
+get('/admin/backup',function(){
+ if(login()) {
+ config('views.root', 'system/admin/views');
+ render('backup', array(
+ 'head_contents' => head_contents('Backup content - ' . blog_title(), blog_description(), site_url()),
+ 'bodyclass' => 'backup',
+ 'breadcrumb' => '' .config('breadcrumb.home'). ' » Backup'
+ ));
+ }
+ else {
+ $login = site_url() . 'login';
+ header("location: $login");
+ }
+ die;
+});
+
+// Create Zip file
+get('/admin/backup-start',function(){
+ if(login()) {
+ config('views.root', 'system/admin/views');
+ render('backup-start', array(
+ 'head_contents' => head_contents('Backup content started - ' . blog_title(), blog_description(), site_url()),
+ 'bodyclass' => 'startbackup',
+ 'breadcrumb' => '' .config('breadcrumb.home'). ' » Backup started'
+ ));
+ }
+ else {
+ $login = site_url() . 'login';
+ header("location: $login");
+ }
+ die;
+});
+
+
// The tag page
get('/tag/:tag',function($tag){
diff --git a/system/includes/functions.php b/system/includes/functions.php
index 28bd13f..a0e4b5d 100644
--- a/system/includes/functions.php
+++ b/system/includes/functions.php
@@ -81,6 +81,22 @@ function get_author_names(){
return $_cache;
}
+// Get backup file.
+function get_zip_files(){
+
+ static $_cache = array();
+
+ if(empty($_cache)){
+
+ // Get the names of all the
+ // zip files.
+
+ $_cache = glob('backup/*.zip');
+ }
+
+ return $_cache;
+}
+
// usort function. Sort by filename.
function sortfile($a, $b) {
return $a['filename'] == $b['filename'] ? 0 : ( $a['filename'] < $b['filename'] ) ? 1 : -1;
@@ -967,8 +983,60 @@ EOF;
// Menu
function menu(){
$menu = config('blog.menu');
+ $req = $_SERVER['REQUEST_URI'];
+
if (!empty($menu)) {
- return $menu;
+
+ $links = explode('|', $menu);
+
+ echo '';
+ if($req == site_path() . '/') {
+ echo '- ' .config('breadcrumb.home'). '
';
+ }
+ else {
+ echo '- ' .config('breadcrumb.home'). '
';
+ }
+
+ $i = 0;
+ $len = count($links);
+
+ foreach($links as $link) {
+
+ if ($i == $len - 1) {
+ $class = 'item last';
+ }
+ else {
+ $class = 'item';
+ }
+ $i++;
+
+ $anc = explode('->', $link);
+
+ if(isset($anc[0]) && isset($anc[1])) {
+
+ if(strpos($link, site_url()) !== false) {
+ $id = substr($link, strrpos($link, '/')+1 );
+ $file = 'content/static/' . $id . '.md';
+ if(file_exists($file)) {
+ if(strpos($req, $id) !== false){
+ echo '- ' . $anc[0] . '
';
+ }
+ else {
+ echo '- ' . $anc[0] . '
';
+ }
+ }
+ else {
+ echo '- ' . $anc[0] . '
';
+ }
+ }
+ else {
+ echo '- ' . $anc[0] . '
';
+ }
+
+ }
+ }
+
+ echo '
';
}
else {
get_menu();
@@ -1035,6 +1103,17 @@ function get_menu() {
echo '';
}
+ else {
+
+ echo '';
+ if($req == site_path() . '/') {
+ echo '- ' .config('breadcrumb.home'). '
';
+ }
+ else {
+ echo '- ' .config('breadcrumb.home'). '
';
+ }
+
+ }
}
@@ -1369,6 +1448,55 @@ 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();
+}
+
// TRUE if the current page is the front page.
function is_front() {
$req = $_SERVER['REQUEST_URI'];
@@ -1472,6 +1600,7 @@ EOF;
echo '- Add page
';
echo '- Edit profile
';
echo '- Import
';
+ echo '- Backup
';
echo '- Logout
';
echo '
';