Browse Source

Fix sent header error

Fix sent header error.
pull/31/merge
Danang Probo Sayekti 12 years ago
parent
commit
97a678fc64
7 changed files with 172 additions and 135 deletions
  1. +0
    -18
      admin/includes/auth.php
  2. +31
    -34
      admin/includes/create_post.php
  3. +36
    -36
      admin/includes/edit_post.php
  4. +62
    -20
      admin/includes/login.php
  5. +12
    -15
      admin/includes/post_list.php
  6. +1
    -3
      admin/includes/session.php
  7. +30
    -9
      admin/index.php

+ 0
- 18
admin/includes/auth.php View File

@ -1,18 +0,0 @@
<div id="login">
<?php if (login()) { ?>
<div class="nav">
<a href="<?php echo config('site.url');?>/admin">Admin</a>
<a href="includes/create_post.php">Create post</a>
<a href="includes/logout.php">Logout</a>
<span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span>
</div>
<?php include 'includes/post_list.php';?>
<?php } else {?>
<?php include 'includes/login.php';?>
<?php } ?>
</div>

+ 31
- 34
admin/includes/create_post.php View File

@ -1,9 +1,30 @@
<?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';
// 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_date = date('Y-m-d-H');
$post_tag = $_POST['tag'];
$post_url = $_POST['url'];
$post_content = $_POST['content'];
}
if(!empty($post_tag) && !empty($post_url) && !empty($post_content)) {
$user = $_SESSION['user'];
$filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
$dir = '../../content/' . $user. '/blog/';
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>
@ -18,37 +39,12 @@ include '../includes/session.php';
<body>
<div class="wrapper-outer">
<div class="wrapper-inner">
<?php if (login()) { ?>
<div class="nav">
<a href="<?php echo config('site.url');?>/admin">Admin</a>
<a href="../includes/logout.php">Logout</a>
<a href="<?php echo config('site.url');?>" target="_blank">Home</a> |
<a href="<?php echo config('site.url');?>/admin">Admin</a> |
<a href="../includes/logout.php">Logout</a> |
<span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span>
</div>
<?php
if(isset($_POST['submit'])) {
$post_date = date('Y-m-d-H');
$post_tag = $_POST['tag'];
$post_url = $_POST['url'];
$post_content = $_POST['content'];
}
if(!empty($post_tag) && !empty($post_url) && !empty($post_content)) {
$user = $_SESSION['user'];
$filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
$dir = '../../content/' . $user. '/blog/';
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');
}
?>
<?php } else {?>
<?php header('location: ../index.php');?>
<?php } ?>
<div class="wmd-panel">
<form method="POST">
Tag: <br><input type="text" name="tag"/><br><br>
@ -77,4 +73,5 @@ include '../includes/session.php';
</div>
</div>
</body>
</html>
</html>
<?php } else {header('location: ../index.php');} ?>

+ 36
- 36
admin/includes/edit_post.php View File

@ -3,14 +3,25 @@
date_default_timezone_set('Asia/Jakarta');
require '../../system/includes/dispatch.php';
config('source', '../../admin/config.ini');
include '../includes/session.php';;
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>
@ -24,49 +35,38 @@
<body>
<div class="wrapper-outer">
<div class="wrapper-inner">
<?php if (login()) { ?>
<div class="nav">
<a href="<?php echo config('site.url');?>/admin">Admin</a>
<a href="../includes/create_post.php">Create post</a>
<a href="../includes/logout.php">Logout</a>
<a href="<?php echo config('site.url');?>" target="_blank">Home</a> |
<a href="<?php echo config('site.url');?>/admin">Admin</a> |
<a href="../includes/create_post.php">Create post</a> |
<a href="../includes/logout.php">Logout</a> |
<span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span>
</div>
<?php } else {?>
<?php header('location: ../index.php');?>
<?php } ?>
<?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');
}
?>
<div class="wmd-panel">
<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";
</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>
var editor = new Markdown.Editor(converter);
editor.run();
})();
</script>
</div>
</div>
</body>
</html>
</html>
<?php } else {header('location: ../index.php');} ?>

+ 62
- 20
admin/includes/login.php View File

@ -1,32 +1,74 @@
<?php
if(isset($_POST['submit'])) {
$user = $_POST['user'];
$user_file = 'users/' . $user . '.txt';
$pass = $_POST['password'];
include '../includes/session.php';
if(!empty($_REQUEST['user']) && !empty($_REQUEST['password'])) {
$user = $_REQUEST['user'];
$pass = $_REQUEST['password'];
$user_file = '../../admin/users/' . $user . '.txt';
$user_pass = @file_get_contents($user_file);
if(file_exists($user_file)) {
if($pass === $user_pass) {
$_SESSION['user'] = $user;
header('location: index.php');
header('location: ../index.php');
}
else {
echo 'Username and password not match!';
echo <<<EOF
<!DOCTYPE html>
<html>
<head>
<title>Admin Panel</title>
<link rel="stylesheet" type="text/css" href="../resources/style.css" />
</head>
<body>
<div class="wrapper-outer">
<div class="wrapper-inner">
<p>Password and username not match!</p>
<p>Login Form</p>
<form method="POST" action="login.php">
User:<br>
<input type="text" name="user"/><br><br>
Pass:<br>
<input type="password" name="password"/><br><br>
<input type="submit" name="submit" value="Login"/>
</form>
</div>
</div>
</body>
</html>
EOF;
}
}
else {
echo 'Please create username.txt inside "admin/users" folder and put your password inside it.';
echo <<<EOF
<!DOCTYPE html>
<html>
<head>
<title>Admin Panel</title>
<link rel="stylesheet" type="text/css" href="../resources/style.css" />
</head>
<body>
<div class="wrapper-outer">
<div class="wrapper-inner">
<p>Please create username.txt inside "admin/users" folder and put your password inside it.</p>
<p>Login Form</p>
<form method="POST" action="login.php">
User:<br>
<input type="text" name="user"/><br><br>
Pass:<br>
<input type="password" name="password"/><br><br>
<input type="submit" name="submit" value="Login"/>
</form>
</div>
</div>
</body>
</html>
EOF;
}
}
?>
<p>Login Form</p>
<form method="POST">
User:<br>
<input type="text" name="user"/><br><br>
Pass:<br>
<input type="password" name="password"/><br><br>
<input type="submit" name="submit" value="Login"/>
</form>
}
else {
header('location: ../index.php');
}
?>

+ 12
- 15
admin/includes/post_list.php View File

@ -112,23 +112,20 @@ function get_profile($profile, $page, $perpage){
}
?>
if (isset($_SESSION['user'])) {
<table>
<?php
$posts = get_profile($_SESSION['user'], null, null);
$posts = get_profile($_SESSION['user'], null, null);
if(!empty($posts)) {
if(!empty($posts)) {
echo '<table>';
foreach($posts as $p) {
echo '<tr>';
echo '<td>' . $p->file . '</td>';
echo '<td><form method="GET" action="includes/edit_post.php"><input type="submit" name="submit" value="Edit"/><input type="hidden" name="url" value="' . $p->file . '"/></form></td>';
echo '</tr>';
}
echo '</table>';
foreach($posts as $p) {
echo '<tr>';
echo '<td>' . $p->file . '</td>';
echo '<td><form method="GET" action="includes/edit_post.php"><input type="submit" name="submit" value="Edit"/><input type="hidden" name="url" value="' . $p->file . '"/></form></td>';
echo '</tr>';
}
}
?>
</table>
}

+ 1
- 3
admin/includes/session.php View File

@ -11,6 +11,4 @@ function login() {
return false;
}
}
?>
}

+ 30
- 9
admin/index.php View File

@ -1,9 +1,8 @@
<?php
ob_start();
date_default_timezone_set('Asia/Jakarta');
require '../system/includes/dispatch.php';
config('source', '../admin/config.ini');
include 'includes/session.php';
date_default_timezone_set('Asia/Jakarta');
require '../system/includes/dispatch.php';
config('source', '../admin/config.ini');
include 'includes/session.php';
?>
<!DOCTYPE html>
<html>
@ -13,9 +12,31 @@ include 'includes/session.php';
</head>
<body>
<div class="wrapper-outer">
<div class="wrapper-inner">
<?php include 'includes/auth.php'; ?>
</div>
<div class="wrapper-inner">
<?php if (login()) { ?>
<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="includes/create_post.php">Create post</a> |
<a href="includes/logout.php">Logout</a> |
<span class="welcome">Welcome <?php echo $_SESSION['user'];?>!</span>
</div>
<?php include 'includes/post_list.php';?>
<?php } else {?>
<p>Login Form</p>
<form method="POST" action="includes/login.php">
User:<br>
<input type="text" name="user"/><br><br>
Pass:<br>
<input type="password" name="password"/><br><br>
<input type="submit" name="submit" value="Login"/>
</form>
<?php } ?>
</div>
</div>
</body>
</html>
</html>

Loading…
Cancel
Save