Improve the admin panel. Use .ini file to store user informations.pull/31/merge
| @ -0,0 +1,77 @@ | |||||
| <?php | |||||
| // Change this to your timezone | |||||
| date_default_timezone_set('Asia/Jakarta'); | |||||
| require '../../system/includes/dispatch.php'; | |||||
| config('source', '../../admin/config.ini'); | |||||
| include '../includes/session.php'; | |||||
| if(isset($_POST['submit'])) { | |||||
| $post_url = $_POST['url']; | |||||
| $post_content = $_POST['content']; | |||||
| } | |||||
| if(!empty($post_url) && !empty($post_content)) { | |||||
| $filename = $post_url . '.md'; | |||||
| $dir = '../../content/static/'; | |||||
| if(is_dir($dir)) { | |||||
| file_put_contents($dir . $filename, print_r($post_content, true)); | |||||
| } | |||||
| else { | |||||
| mkdir($dir, 0777, true); | |||||
| file_put_contents($dir . $filename, print_r($post_content, true)); | |||||
| } | |||||
| header('location: ../index.php'); | |||||
| } | |||||
| if (login()) { | |||||
| ?> | |||||
| <!DOCTYPE html> | |||||
| <html> | |||||
| <head> | |||||
| <meta charset="utf-8" /> | |||||
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |||||
| <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" user-scalable="no" /> | |||||
| <title>Create page</title> | |||||
| <link rel="stylesheet" type="text/css" href="../resources/style.css" /> | |||||
| <link rel="stylesheet" type="text/css" href="../editor/css/editor.css" /> | |||||
| <script type="text/javascript" src="../editor/js/Markdown.Converter.js"></script> | |||||
| <script type="text/javascript" src="../editor/js/Markdown.Sanitizer.js"></script> | |||||
| <script type="text/javascript" src="../editor/js/Markdown.Editor.js"></script> | |||||
| </head> | |||||
| <body> | |||||
| <div class="wrapper-outer"> | |||||
| <div class="wrapper-inner"> | |||||
| <div class="nav"> | |||||
| <a href="<?php echo config('site.url');?>" target="_blank">Home</a> | | |||||
| <a href="<?php echo config('site.url');?>/admin">Admin</a> | | |||||
| <a href="../action/create_post.php">Create post</a> | | |||||
| <a href="../action/logout.php">Logout</a> | | |||||
| <span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span> | |||||
| </div> | |||||
| <div class="wmd-panel"> | |||||
| <form method="POST"> | |||||
| Url: <br><input type="text" name="url"/><br><br> | |||||
| <div id="wmd-button-bar" class="wmd-button-bar"></div> | |||||
| <textarea id="wmd-input" class="wmd-input" name="content" cols="20" rows="10"></textarea><br/> | |||||
| <input type="submit" name="submit" value="Publish"/> | |||||
| </form> | |||||
| </div> | |||||
| <div id="wmd-preview" class="wmd-panel wmd-preview"></div> | |||||
| <script type="text/javascript"> | |||||
| (function () { | |||||
| var converter = Markdown.getSanitizingConverter(); | |||||
| converter.hooks.chain("preBlockGamut", function (text, rbg) { | |||||
| return text.replace(/^ {0,3}""" *\n((?:.*?\n)+?) {0,3}""" *$/gm, function (whole, inner) { | |||||
| return "<blockquote>" + rbg(inner) + "</blockquote>\n"; | |||||
| }); | |||||
| }); | |||||
| var editor = new Markdown.Editor(converter); | |||||
| editor.run(); | |||||
| })(); | |||||
| </script> | |||||
| </div> | |||||
| </div> | |||||
| </body> | |||||
| </html> | |||||
| <?php } else {header('location: ../index.php');} ?> | |||||
| @ -0,0 +1,58 @@ | |||||
| <?php | |||||
| // Change this to your timezone | |||||
| date_default_timezone_set('Asia/Jakarta'); | |||||
| require '../../system/includes/dispatch.php'; | |||||
| config('source', '../../admin/config.ini'); | |||||
| include '../includes/session.php'; | |||||
| if(isset($_GET['url'])) { | |||||
| $url = $_GET['url']; | |||||
| } | |||||
| else { | |||||
| header('location: ../index.php'); | |||||
| } | |||||
| if(isset($_POST['submit'])) { | |||||
| $deleted_content = $_POST['delete']; | |||||
| } | |||||
| if(!empty($deleted_content)) { | |||||
| unlink($deleted_content); | |||||
| header('location: ../index.php'); | |||||
| } | |||||
| if (login()) { | |||||
| ?> | |||||
| <!DOCTYPE html> | |||||
| <html> | |||||
| <head> | |||||
| <meta charset="utf-8" /> | |||||
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |||||
| <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" user-scalable="no" /> | |||||
| <title>Delete page</title> | |||||
| <link rel="stylesheet" type="text/css" href="../resources/style.css" /> | |||||
| <link rel="stylesheet" type="text/css" href="../editor/css/editor.css" /> | |||||
| <script type="text/javascript" src="../editor/js/Markdown.Converter.js"></script> | |||||
| <script type="text/javascript" src="../editor/js/Markdown.Sanitizer.js"></script> | |||||
| <script type="text/javascript" src="../editor/js/Markdown.Editor.js"></script> | |||||
| </head> | |||||
| <body> | |||||
| <div class="wrapper-outer"> | |||||
| <div class="wrapper-inner"> | |||||
| <div class="nav"> | |||||
| <a href="<?php echo config('site.url');?>" target="_blank">Home</a> | | |||||
| <a href="<?php echo config('site.url');?>/admin">Admin</a> | | |||||
| <a href="../action/create_post.php">Create post</a> | | |||||
| <a href="../action/logout.php">Logout</a> | | |||||
| <span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span> | |||||
| </div> | |||||
| <?php echo '<p>Are you sure want to delete <strong>' . $url . '</strong>?</p>';?> | |||||
| <form method="POST"> | |||||
| <input type="hidden" name="delete" value="<?php echo '../' . $url ?>"/><br> | |||||
| <input type="submit" name="submit" value="Delete"/> | |||||
| </form> | |||||
| </div> | |||||
| </div> | |||||
| </body> | |||||
| </html> | |||||
| <?php } else {header('location: ../index.php');} ?> | |||||
| @ -0,0 +1,58 @@ | |||||
| <?php | |||||
| // Change this to your timezone | |||||
| date_default_timezone_set('Asia/Jakarta'); | |||||
| require '../../system/includes/dispatch.php'; | |||||
| config('source', '../../admin/config.ini'); | |||||
| include '../includes/session.php'; | |||||
| if(isset($_GET['url'])) { | |||||
| $url = $_GET['url']; | |||||
| } | |||||
| else { | |||||
| header('location: ../index.php'); | |||||
| } | |||||
| if(isset($_POST['submit'])) { | |||||
| $deleted_content = $_POST['delete']; | |||||
| } | |||||
| if(!empty($deleted_content)) { | |||||
| unlink($deleted_content); | |||||
| header('location: ../index.php'); | |||||
| } | |||||
| if (login()) { | |||||
| ?> | |||||
| <!DOCTYPE html> | |||||
| <html> | |||||
| <head> | |||||
| <meta charset="utf-8" /> | |||||
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |||||
| <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" user-scalable="no" /> | |||||
| <title>Delete post</title> | |||||
| <link rel="stylesheet" type="text/css" href="../resources/style.css" /> | |||||
| <link rel="stylesheet" type="text/css" href="../editor/css/editor.css" /> | |||||
| <script type="text/javascript" src="../editor/js/Markdown.Converter.js"></script> | |||||
| <script type="text/javascript" src="../editor/js/Markdown.Sanitizer.js"></script> | |||||
| <script type="text/javascript" src="../editor/js/Markdown.Editor.js"></script> | |||||
| </head> | |||||
| <body> | |||||
| <div class="wrapper-outer"> | |||||
| <div class="wrapper-inner"> | |||||
| <div class="nav"> | |||||
| <a href="<?php echo config('site.url');?>" target="_blank">Home</a> | | |||||
| <a href="<?php echo config('site.url');?>/admin">Admin</a> | | |||||
| <a href="../action/create_post.php">Create post</a> | | |||||
| <a href="../action/logout.php">Logout</a> | | |||||
| <span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span> | |||||
| </div> | |||||
| <?php echo '<p>Are you sure want to delete <strong>' . $url . '</strong>?</p>';?> | |||||
| <form method="POST"> | |||||
| <input type="hidden" name="delete" value="<?php echo '../' . $url ?>"/><br> | |||||
| <input type="submit" name="submit" value="Delete"/> | |||||
| </form> | |||||
| </div> | |||||
| </div> | |||||
| </body> | |||||
| </html> | |||||
| <?php } else {header('location: ../index.php');} ?> | |||||
| @ -0,0 +1,75 @@ | |||||
| <?php | |||||
| // Change this to your timezone | |||||
| date_default_timezone_set('Asia/Jakarta'); | |||||
| require '../../system/includes/dispatch.php'; | |||||
| config('source', '../../admin/config.ini'); | |||||
| include '../includes/session.php'; | |||||
| if(isset($_GET['url'])) { | |||||
| $url = $_GET['url']; | |||||
| } | |||||
| else { | |||||
| header('location: ../index.php'); | |||||
| } | |||||
| if(isset($_POST['submit'])) { | |||||
| $post_content = $_POST['content']; | |||||
| } | |||||
| if(!empty($post_content)) { | |||||
| file_put_contents('../'. $url, print_r($post_content, true)); | |||||
| header('location: ../index.php'); | |||||
| } | |||||
| if (login()) { | |||||
| ?> | |||||
| <!DOCTYPE html> | |||||
| <html> | |||||
| <head> | |||||
| <meta charset="utf-8" /> | |||||
| <meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |||||
| <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" user-scalable="no" /> | |||||
| <title>Edit page</title> | |||||
| <link rel="stylesheet" type="text/css" href="../resources/style.css" /> | |||||
| <link rel="stylesheet" type="text/css" href="../editor/css/editor.css" /> | |||||
| <script type="text/javascript" src="../editor/js/Markdown.Converter.js"></script> | |||||
| <script type="text/javascript" src="../editor/js/Markdown.Sanitizer.js"></script> | |||||
| <script type="text/javascript" src="../editor/js/Markdown.Editor.js"></script> | |||||
| </head> | |||||
| <body> | |||||
| <div class="wrapper-outer"> | |||||
| <div class="wrapper-inner"> | |||||
| <div class="nav"> | |||||
| <a href="<?php echo config('site.url');?>" target="_blank">Home</a> | | |||||
| <a href="<?php echo config('site.url');?>/admin">Admin</a> | | |||||
| <a href="../action/create_post.php">Create post</a> | | |||||
| <a href="../action/logout.php">Logout</a> | | |||||
| <span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span> | |||||
| </div> | |||||
| <div class="wmd-panel"> | |||||
| <form method="POST"> | |||||
| <div id="wmd-button-bar" class="wmd-button-bar"></div> | |||||
| <textarea id="wmd-input" class="wmd-input" name="content" cols="20" rows="10"><?php echo file_get_contents('../' . $url)?></textarea><br> | |||||
| <input type="submit" name="submit" value="Submit"/> | |||||
| </form> | |||||
| </div> | |||||
| <div id="wmd-preview" class="wmd-panel wmd-preview"></div> | |||||
| <script type="text/javascript"> | |||||
| (function () { | |||||
| var converter = Markdown.getSanitizingConverter(); | |||||
| converter.hooks.chain("preBlockGamut", function (text, rbg) { | |||||
| return text.replace(/^ {0,3}""" *\n((?:.*?\n)+?) {0,3}""" *$/gm, function (whole, inner) { | |||||
| return "<blockquote>" + rbg(inner) + "</blockquote>\n"; | |||||
| }); | |||||
| }); | |||||
| var editor = new Markdown.Editor(converter); | |||||
| editor.run(); | |||||
| })(); | |||||
| </script> | |||||
| </div> | |||||
| </div> | |||||
| </body> | |||||
| </html> | |||||
| <?php } else {header('location: ../index.php');} ?> | |||||
| @ -1,6 +1,6 @@ | |||||
| <?php | <?php | ||||
| include 'session.php'; | |||||
| include '../includes/session.php'; | |||||
| session_destroy(); | session_destroy(); | ||||
| @ -0,0 +1 @@ | |||||
| deny from all | |||||
| @ -0,0 +1,42 @@ | |||||
| <?php | |||||
| date_default_timezone_set('Asia/Jakarta'); | |||||
| config('source', '../../admin/config.ini'); | |||||
| // Get static page path. Unsorted. | |||||
| function admin_get_static(){ | |||||
| static $_cache = array(); | |||||
| if(empty($_cache)){ | |||||
| // Get the names of all the | |||||
| // static page. | |||||
| $_cache = glob('../content/static/*.md', GLOB_NOSORT); | |||||
| } | |||||
| return $_cache; | |||||
| } | |||||
| // Auto generate menu from static page | |||||
| function get_page_list() { | |||||
| $posts = admin_get_static(); | |||||
| krsort($posts); | |||||
| echo '<table>'; | |||||
| foreach($posts as $index => $v){ | |||||
| echo '<tr>'; | |||||
| echo '<td>' . $v . '</td>'; | |||||
| echo '<td><form method="GET" action="action/edit_page.php"><input type="submit" name="submit" value="Edit"/><input type="hidden" name="url" value="' . $v . '"/></form></td>'; | |||||
| echo '<td><form method="GET" action="action/delete_page.php"><input type="submit" name="submit" value="Delete"/><input type="hidden" name="url" value="' . $v . '"/></form></td>'; | |||||
| echo '</tr>'; | |||||
| } | |||||
| echo '</table>'; | |||||
| } | |||||
| ?> | |||||
| @ -0,0 +1,10 @@ | |||||
| <?php | |||||
| function user($key, $user=null) { | |||||
| $value = '../../admin/users/' . $user . '.ini'; | |||||
| static $_config = array(); | |||||
| if (file_exists($value)) { | |||||
| $_config = parse_ini_file($value, true); | |||||
| return $_config[$key]; | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,2 @@ | |||||
| ;Password | |||||
| password = yourpassword | |||||