Browse Source

Merge 1659af6aaa into 90a07f1c75

pull/51/merge
BlackCodec 11 years ago
parent
commit
13572ab112
13 changed files with 1987 additions and 59 deletions
  1. +3
    -1
      changelog.txt
  2. +5
    -1
      config/users/username.ini.example
  3. +34
    -17
      system/admin/admin.php
  4. +304
    -0
      system/admin/editor/css/jquery.datetimepicker.css
  5. +4
    -0
      system/admin/editor/js/jquery-2.1.1.min.js
  6. +1371
    -0
      system/admin/editor/js/jquery.datetimepicker.js
  7. +10
    -0
      system/admin/views/add-post.html.php
  8. +10
    -0
      system/admin/views/edit-post.html.php
  9. +1
    -1
      system/admin/views/no-posts.html.php
  10. +2
    -2
      system/admin/views/posts-list.html.php
  11. +3
    -3
      system/admin/views/user-posts.html.php
  12. +185
    -12
      system/htmly.php
  13. +55
    -22
      system/includes/functions.php

+ 3
- 1
changelog.txt View File

@ -1,6 +1,8 @@
2014-06-05: Support for drafts
2014-06-04: Encryption in username.ini password
2014-02-25: HTTPS Support
2014-02-15: HTMLy v1.2
2014-02-08: HTMLy v1.1.
2014-02-01: HTMLy v1.0.
2014-01-26: RC version.
2014-01-01: Initial release.
2014-01-01: Initial release.

+ 5
- 1
config/users/username.ini.example View File

@ -1,5 +1,9 @@
;Password
password = yourpassword
encryption = clear
; encryption: not set, leave blank or set to clear to use plain text password for the user,
; else set to encryption algoritm supported by hash function of php to use the selected
; encryption
;Role
role = admin
role = admin

+ 34
- 17
system/admin/admin.php View File

@ -16,14 +16,16 @@ function user($key, $user=null) {
function session($user, $pass, $str = null) {
$user_file = 'config/users/' . $user . '.ini';
$user_pass = user('password', $user);
$user_enc = user('encryption', $user);
$password = (strlen($user_enc) > 0 && $user_enc !== 'clear')?hash($user_enc,$pass):$pass;
if(file_exists($user_file)) {
if($pass === $user_pass) {
if($password === $user_pass) {
$_SESSION['user'] = $user;
header('location: admin');
}
else {
return $str = '<li>Your username and password mismatch.</li>';
return $str = '<li>X'.$pass.'X - X'.$password.'X - X'.$user_enc.'X</li><li>Your username and password mismatch.</li>';
}
}
else {
@ -40,7 +42,7 @@ function remove_accent($str)
}
// Edit blog posts
function edit_post($title, $tag, $url, $content, $oldfile, $destination = null) {
function edit_post($title, $tag, $url, $content, $oldfile, $destination = null, $datetime = '') {
$oldurl = explode('_', $oldfile);
@ -50,12 +52,21 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null)
$post_tag = rtrim(ltrim($post_tag, ',\.\-'), ',\.\-');
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 -]/', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
$post_content = '<!--t ' . $post_title . ' t-->' . "\n\n" . $content;
$post_datetime = $datetime;
$post_newurl = $oldurl[0];
if (strlen($post_datetime)>0) {
$temp = explode('/',$post_newurl);
array_pop($temp);
$temp[] = $post_datetime;
$post_newurl = implode('/',$temp);
}
if(!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) {
if(get_magic_quotes_gpc()) {
$post_content = stripslashes($post_content);
}
$newfile = $oldurl[0] . '_' . $post_tag . '_' . $post_url . '.md';
$newfile = $post_newurl . '_' . $post_tag . '_' . $post_url . '.md';
if($oldfile === $newfile) {
file_put_contents($oldfile, print_r($post_content, true));
}
@ -64,18 +75,24 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null)
file_put_contents($newfile, print_r($post_content, true));
}
$replaced = substr($oldurl[0], 0,strrpos($oldurl[0], '/')) . '/';
$dt = str_replace($replaced,'',$oldurl[0]);
$t = str_replace('-','',$dt);
if (strlen($post_datetime)>0) {
$t = str_replace('-','',$post_datetime);
}
else {
$replaced = substr($oldurl[0], 0,strrpos($oldurl[0], '/')) . '/';
$dt = str_replace($replaced,'',$oldurl[0]);
$t = str_replace('-','',$dt);
}
$time = new DateTime($t);
$timestamp= $time->format("Y-m-d");
// The post date
$postdate = strtotime($timestamp);
// The post URL
$posturl = site_url().date('Y/m', $postdate).'/'.$post_url;
check_drafts_to_posts();
if ($destination == 'post') {
header("Location: $posturl");
}
@ -83,7 +100,6 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null)
$redirect = site_url() . $destination;
header("Location: $redirect");
}
}
}
@ -125,9 +141,9 @@ function edit_page($title, $url, $content, $oldfile, $destination = null) {
}
// Add blog post
function add_post($title, $tag, $url, $content, $user) {
$post_date = date('Y-m-d-H-i-s');
function add_post($title, $tag, $url, $content, $user, $datetime = '') {
$post_date = (strlen($datetime)>0)?$datetime:date('Y-m-d-H-i-s');
$post_title = $title;
$post_tag = preg_replace('/[^A-Za-z0-9,.-]/u', '', $tag);
$post_tag = rtrim(ltrim($post_tag, ',\.\-'), ',\.\-');
@ -139,7 +155,7 @@ function add_post($title, $tag, $url, $content, $user) {
$post_content = stripslashes($post_content);
}
$filename = $post_date . '_' . $post_tag . '_' . $post_url . '.md';
$dir = 'content/' . $user. '/blog/';
$dir = 'draft/' . $user. '/blog/';
if(is_dir($dir)) {
file_put_contents($dir . $filename, print_r($post_content, true));
}
@ -147,6 +163,7 @@ function add_post($title, $tag, $url, $content, $user) {
mkdir($dir, 0777, true);
file_put_contents($dir . $filename, print_r($post_content, true));
}
check_drafts_to_posts();
$redirect = site_url() . 'admin/mine';
header("Location: $redirect");
}
@ -180,7 +197,7 @@ function add_page($title, $url, $content) {
}
// Delete blog post
function delete_post($file, $destination) {
function delete_post($file, $destination, $draft = false) {
$deleted_content = $file;
if(!empty($deleted_content)) {
unlink($deleted_content);


+ 304
- 0
system/admin/editor/css/jquery.datetimepicker.css View File

@ -0,0 +1,304 @@
.xdsoft_datetimepicker{
box-shadow: 0px 5px 15px -5px rgba(0, 0, 0, 0.506);
background: #FFFFFF;
border-bottom: 1px solid #BBBBBB;
border-left: 1px solid #CCCCCC;
border-right: 1px solid #CCCCCC;
border-top: 1px solid #CCCCCC;
color: #333333;
display: block;
font-family: "Helvetica Neue", "Helvetica", "Arial", sans-serif;
padding: 8px;
padding-left: 0px;
padding-top: 2px;
position: absolute;
z-index: 9999;
-moz-box-sizing: border-box;
box-sizing: border-box;
display:none;
}
.xdsoft_datetimepicker iframe {
position: absolute;
left: 0;
top: 0;
width: 75px;
height: 210px;
background: transparent;
border:none;
}
/*For IE8 or lower*/
.xdsoft_datetimepicker button {
border:none !important;
}
.xdsoft_noselect{
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
.xdsoft_noselect::selection { background: transparent; }
.xdsoft_noselect::-moz-selection { background: transparent; }
.xdsoft_datetimepicker.xdsoft_inline{
display: inline-block;
position: static;
box-shadow: none;
}
.xdsoft_datetimepicker *{
-moz-box-sizing: border-box;
box-sizing: border-box;
padding:0px;
margin:0px;
}
.xdsoft_datetimepicker .xdsoft_datepicker, .xdsoft_datetimepicker .xdsoft_timepicker{
display:none;
}
.xdsoft_datetimepicker .xdsoft_datepicker.active, .xdsoft_datetimepicker .xdsoft_timepicker.active{
display:block;
}
.xdsoft_datetimepicker .xdsoft_datepicker{
width: 224px;
float:left;
margin-left:8px;
}
.xdsoft_datetimepicker .xdsoft_timepicker{
width: 58px;
float:left;
text-align:center;
margin-left:8px;
margin-top:0px;
}
.xdsoft_datetimepicker .xdsoft_datepicker.active+.xdsoft_timepicker{
margin-top:8px;
margin-bottom:3px
}
.xdsoft_datetimepicker .xdsoft_mounthpicker{
position: relative;
text-align: center;
}
.xdsoft_datetimepicker .xdsoft_prev, .xdsoft_datetimepicker .xdsoft_next,.xdsoft_datetimepicker .xdsoft_today_button{
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFoAAAAeCAYAAACsYQl4AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDozQjRCQjRGREU4MkNFMzExQjRDQkIyRDJDOTdBRUI1MCIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDpCQjg0OUYyNTZDODAxMUUzQjMwM0IwMERBNUU0ODQ5NSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDpCQjg0OUYyNDZDODAxMUUzQjMwM0IwMERBNUU0ODQ5NSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M2IChXaW5kb3dzKSI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkI5NzE3MjFBN0E2Q0UzMTFBQjJEQjgzMDk5RTNBNTdBIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjNCNEJCNEZERTgyQ0UzMTFCNENCQjJEMkM5N0FFQjUwIi8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+aQvATgAAAfVJREFUeNrsmr1OwzAQxzGtkPjYEAuvVGAvfQIGRKADE49gdLwDDwBiZ2RhQUKwICQkWLsgFiRQuIBTucFJ/XFp4+hO+quqnZ4uvzj2nV2RpukCW/22yAgYNINmc7du7DcghCjrkqgOKjF1znpt6rZ0AGWQj7TvCU8d9UM+QAGDrhdyc2Bnc1WVVPBev9V8lBnY+rDwncWZThG4xk4lmxtJy2AHgoY/FySgbSBPwPZ8mEXbQx3aDERb0EbYAYFC7pcAtAvkMWwC0D3NX58S9D/YnoGC7nPWr3Dg9JTbtuHhDShBT8D2CBSK/iIEvVXxpuxSgh7DdgwUTL4iA92zmJb6lKB/YTsECmV+IgK947AGDIqgQ/LojsO135Hn51l2cWlov0JdGNrPUceueXRwilSVgkUyom9Rd6gbLfYTDeO+1v6orn0InTogYDGUkYLO3/wc9BdqqTCKP1Tfi+oTIaCBIL2TES+GTyruT9S61p6BHam+99DFEAgLFklYsIBHwSI9QY80H5ta+1rB/6ovaKihBJeEJbgLbBlQgl+j3lDPqA2tfQV1j3pVn8s+oKHGTSVJ+FqDLeR5bCqJ2E/BCycsoLZETXaKGs7rhKVt+9HZScrZNMi88V8P7LlDbvOZYaJVpMMmBCT4n0o8dTBoNgbdWPsRYACs3r7XyNfbnAAAAABJRU5ErkJggg==');
}
.xdsoft_datetimepicker .xdsoft_prev{
float: left;
background-position:-20px 0px;
}
.xdsoft_datetimepicker .xdsoft_today_button{
float: left;
background-position:-70px 0px;
margin-left:5px;
}
.xdsoft_datetimepicker .xdsoft_next{
float: right;
background-position:0px 0px;
}
.xdsoft_datetimepicker .xdsoft_next:active,.xdsoft_datetimepicker .xdsoft_prev:active{
}
.xdsoft_datetimepicker .xdsoft_next,.xdsoft_datetimepicker .xdsoft_prev ,.xdsoft_datetimepicker .xdsoft_today_button{
background-color: transparent;
background-repeat: no-repeat;
border: 0px none currentColor;
cursor: pointer;
display: block;
height: 30px;
opacity: 0.5;
outline: medium none currentColor;
overflow: hidden;
padding: 0px;
position: relative;
text-indent: 100%;
white-space: nowrap;
width: 20px;
}
.xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_prev,
.xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_next{
float:none;
background-position:-40px -15px;
height: 15px;
width: 30px;
display: block;
margin-left:14px;
margin-top:7px;
}
.xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_prev{
background-position:-40px 0px;
margin-bottom:7px;
margin-top:0px;
}
.xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_time_box{
height:151px;
overflow:hidden;
border-bottom:1px solid #DDDDDD;
}
.xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_time_box >div >div{
background: #F5F5F5;
border-top:1px solid #DDDDDD;
color: #666666;
font-size: 12px;
text-align: center;
border-collapse:collapse;
cursor:pointer;
border-bottom-width:0px;
height:25px;
line-height:25px;
}
.xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_time_box >div > div:first-child{
border-top-width:0px;
}
.xdsoft_datetimepicker .xdsoft_today_button:hover,
.xdsoft_datetimepicker .xdsoft_next:hover,
.xdsoft_datetimepicker .xdsoft_prev:hover {
opacity: 1;
}
.xdsoft_datetimepicker .xdsoft_label{
display: inline;
position: relative;
z-index: 9999;
margin: 0;
padding: 5px 3px;
font-size: 14px;
line-height: 20px;
font-weight: bold;
background-color: #fff;
float:left;
width:182px;
text-align:center;
cursor:pointer;
}
.xdsoft_datetimepicker .xdsoft_label:hover{
text-decoration:underline;
}
.xdsoft_datetimepicker .xdsoft_label > .xdsoft_select{
border:1px solid #ccc;
position:absolute;
display:block;
right:0px;
top:30px;
z-index:101;
display:none;
background:#fff;
max-height:160px;
overflow-y:hidden;
}
.xdsoft_datetimepicker .xdsoft_label > .xdsoft_select.xdsoft_monthselect{right:-7px;}
.xdsoft_datetimepicker .xdsoft_label > .xdsoft_select.xdsoft_yearselect{right:2px;}
.xdsoft_datetimepicker .xdsoft_label > .xdsoft_select > div > .xdsoft_option:hover{
color: #fff;
background: #ff8000;
}
.xdsoft_datetimepicker .xdsoft_label > .xdsoft_select > div > .xdsoft_option{
padding:2px 10px 2px 5px;
}
.xdsoft_datetimepicker .xdsoft_label > .xdsoft_select > div > .xdsoft_option.xdsoft_current{
background: #33AAFF;
box-shadow: #178FE5 0px 1px 3px 0px inset;
color:#fff;
font-weight: 700;
}
.xdsoft_datetimepicker .xdsoft_month{
width:90px;
text-align:right;
}
.xdsoft_datetimepicker .xdsoft_calendar{
clear:both;
}
.xdsoft_datetimepicker .xdsoft_year{
width:56px;
}
.xdsoft_datetimepicker .xdsoft_calendar table{
border-collapse:collapse;
width:100%;
}
.xdsoft_datetimepicker .xdsoft_calendar td > div{
padding-right:5px;
}
.xdsoft_datetimepicker .xdsoft_calendar th{
height: 25px;
}
.xdsoft_datetimepicker .xdsoft_calendar td,.xdsoft_datetimepicker .xdsoft_calendar th{
width:14.2857142%;
text-align:center;
background: #F5F5F5;
border:1px solid #DDDDDD;
color: #666666;
font-size: 12px;
text-align: right;
padding:0px;
border-collapse:collapse;
cursor:pointer;
height: 25px;
}
.xdsoft_datetimepicker .xdsoft_calendar th{
background: #F1F1F1;
}
.xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_today{
color:#33AAFF;
}
.xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_default,
.xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_current,
.xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_time_box >div >div.xdsoft_current{
background: #33AAFF;
box-shadow: #178FE5 0px 1px 3px 0px inset;
color:#fff;
font-weight: 700;
}
.xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_other_month,
.xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_disabled,
.xdsoft_datetimepicker .xdsoft_time_box >div >div.xdsoft_disabled{
opacity:0.5;
}
.xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_other_month.xdsoft_disabled{
opacity:0.2;
}
.xdsoft_datetimepicker .xdsoft_calendar td:hover,
.xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_time_box >div >div:hover{
color: #fff !important;
background: #ff8000 !important;
box-shadow: none !important;
}
.xdsoft_datetimepicker .xdsoft_calendar td.xdsoft_disabled:hover,
.xdsoft_datetimepicker .xdsoft_timepicker .xdsoft_time_box >div >div.xdsoft_disabled:hover{
color: inherit !important;
background: inherit !important;
box-shadow: inherit !important;
}
.xdsoft_datetimepicker .xdsoft_calendar th{
font-weight: 700;
text-align: center;
color: #999;
cursor:default;
}
.xdsoft_datetimepicker .xdsoft_copyright{ color:#ccc !important; font-size:10px;clear:both;float:none;margin-left:8px;}
.xdsoft_datetimepicker .xdsoft_copyright a{ color:#eee !important;}
.xdsoft_datetimepicker .xdsoft_copyright a:hover{ color:#aaa !important;}
.xdsoft_time_box{
position:relative;
border:1px solid #ccc;
}
.xdsoft_scrollbar >.xdsoft_scroller{
background:#ccc !important;
height:20px;
border-radius:3px;
}
.xdsoft_scrollbar{
position:absolute;
width:7px;
width:7px;
right:0px;
top:0px;
bottom:0px;
cursor:pointer;
}
.xdsoft_scroller_box{
position:relative;
}

+ 4
- 0
system/admin/editor/js/jquery-2.1.1.min.js
File diff suppressed because it is too large
View File


+ 1371
- 0
system/admin/editor/js/jquery.datetimepicker.js
File diff suppressed because it is too large
View File


+ 10
- 0
system/admin/views/add-post.html.php View File

@ -1,4 +1,7 @@
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css" />
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/jquery.datetimepicker.css" />
<script src="<?php echo site_url() ?>system/admin/editor/js/jquery-2.1.1.min.js"></script>
<script src="<?php echo site_url() ?>system/admin/editor/js/jquery.datetimepicker.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Converter.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Sanitizer.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Editor.js"></script>
@ -12,6 +15,8 @@
Url (optional)<br><input type="text" class="text" name="url" value="<?php if (isset($postUrl)) { echo $postUrl;} ?>"/><br>
<span class="help">If the url leave empty we will use the post title.</span>
<br><br>
Date and time (Optional)<br><input id="datetimepicker" name="datatime" type="text" value="<?php if (isset($postDateTime)) { echo $postDateTime; } else { echo date("Y-m-d-H-m-s"); } ?>" />
<br><br>
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="wmd-input <?php if (isset($postContent)) { if (empty($postContent)) { echo 'error';}} ?>" name="content" cols="20" rows="10"><?php if (isset($postContent)) { echo $postContent;} ?></textarea><br/>
<input type="submit" name="submit" class="submit" value="Publish"/>
@ -26,4 +31,9 @@
editor.run();
})();
</script>
<script type="text/javascript">
jQuery('#datetimepicker').datetimepicker({
format:'Y-m-d-H-i-s'
});
</script>

+ 10
- 0
system/admin/views/edit-post.html.php View File

@ -43,6 +43,9 @@
?>
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/jquery.datetimepicker.css" />
<script src="<?php echo site_url() ?>system/admin/editor/js/jquery-2.1.1.min.js"></script>
<script src="<?php echo site_url() ?>system/admin/editor/js/jquery.datetimepicker.js"></script>
<link rel="stylesheet" type="text/css" href="<?php echo site_url() ?>system/admin/editor/css/editor.css" />
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Converter.js"></script>
<script type="text/javascript" src="<?php echo site_url() ?>system/admin/editor/js/Markdown.Sanitizer.js"></script>
@ -57,6 +60,8 @@
Url (optional)<br><input type="text" name="url" class="text" value="<?php echo $oldmd ?>"/><br>
<span class="help">If the url leave empty we will use the post title.</span>
<br><br>
Date and Time (optional)<br><input id="datetimepicker" type="text" name="datetime" class="text" value="<?php echo $dt;?>" /><br>
<br><br>
<div id="wmd-button-bar" class="wmd-button-bar"></div>
<textarea id="wmd-input" class="wmd-input <?php if (isset($postContent)) { if (empty($postContent)) { echo 'error';}} ?>" name="content" cols="20" rows="10"><?php echo $oldcontent ?></textarea><br>
<input type="hidden" name="oldfile" class="text" value="<?php echo $url ?>"/>
@ -72,4 +77,9 @@
editor.run();
})();
</script>
<script type="text/javascript">
jQuery('#datetimepicker').datetimepicker({
format:'Y-m-d-H-i-s'
});
</script>

+ 1
- 1
system/admin/views/no-posts.html.php View File

@ -1 +1 @@
<h1>No posts found!</h1>
<h1>No <?php echo ($draft)?'drafts':'posts';?> found!</h1>

+ 2
- 2
system/admin/views/posts-list.html.php View File

@ -17,11 +17,11 @@
$i++;
?>
<tr class="<?php echo $class ?>">
<td><a target="_blank" href="<?php echo $p->url ?>"><?php echo $p->title ?></a></td>
<td><a target="_blank" href="<?php echo $p->url . (($draft)?'/edit?destination=admin/drafts':'');?>"><?php echo $p->title ?></a></td>
<td><?php echo date('d F Y', $p->date) ?></td>
<td><a target="_blank" href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></td>
<td><?php echo $p->tag ?></td>
<td><a href="<?php echo $p->url ?>/edit?destination=admin/posts">Edit</a> <a href="<?php echo $p->url ?>/delete?destination=admin/posts">Delete</a></td>
<td><a href="<?php echo $p->url ?>/edit?destination=admin/<?php echo ($draft)?'drafts':'posts';?>">Edit</a> <a href="<?php echo $p->url ?>/delete<?php echo ($draft)?'draft':'';?>?destination=admin/<?php echo ($draft)?'drafts':'posts';?>">Delete</a></td>
</tr>
<?php endforeach;?>
</table>


+ 3
- 3
system/admin/views/user-posts.html.php View File

@ -17,10 +17,10 @@
$i++;
?>
<tr class="<?php echo $class ?>">
<td><a target="_blank" href="<?php echo $p->url ?>"><?php echo $p->title ?></a></td>
<td><a target="_blank" href="<?php echo $p->url ?><?php if ($draft) { echo '/edit?destination=admin/minedrafts'; } ?>"><?php echo $p->title ?></a></td>
<td><?php echo date('d F Y', $p->date) ?></td>
<td><?php echo $p->tag ?></td>
<td><a href="<?php echo $p->url ?>/edit?destination=admin/mine">Edit</a> <a href="<?php echo $p->url ?>/delete?destination=admin/mine">Delete</a></td>
<td><a href="<?php echo $p->url ?>/edit?destination=admin/mine<?php if ($draft) { echo 'drafts'; } ?>">Edit</a> <a href="<?php echo $p->url ?>/delete?destination=admin/mine<?php if ($draft) { echo 'drafts'; } ?>">Delete</a></td>
</tr>
<?php endforeach;?>
</table>
@ -34,4 +34,4 @@
<?php endif;?>
</div>
<?php endif;?>
<?php } else { echo 'No posts found!'; }?>
<?php } else { echo 'No '.(($draft)?'drafts':'posts').' found!'; }?>

+ 185
- 12
system/htmly.php View File

@ -22,6 +22,8 @@ get('/index', function () {
$page = $page ? (int)$page : 1;
$perpage = config('posts.perpage');
check_drafts_to_posts();
$posts = get_posts(null, $page, $perpage);
$total = '';
@ -147,11 +149,12 @@ get('/:year/:month/:name/edit', function($year, $month, $name){
$user = $_SESSION['user'];
$role = user('role', $user);
$draft = (strpos(from($_GET, 'destination'),'draft') !== false)?true:false;
if(login()) {
config('views.root', 'system/admin/views');
$post = find_post($year, $month, $name);
$post = find_post($year, $month, $name, $draft);
if(!$post){
not_found();
@ -182,6 +185,7 @@ get('/:year/:month/:name/edit', function($year, $month, $name){
}
});
// Get edited data for blog post
post('/:year/:month/:name/edit', function() {
@ -191,13 +195,16 @@ post('/:year/:month/:name/edit', function() {
$content = from($_REQUEST, 'content');
$oldfile = from($_REQUEST, 'oldfile');
$destination = from($_GET, 'destination');
$datetime = from($_REQUEST, 'datetime');
$draft = (strpos($destination,'draft') !== false)?true:false;
if(!empty($title) && !empty($tag) && !empty($content)) {
if(!empty($url)) {
edit_post($title, $tag, $url, $content, $oldfile, $destination);
edit_post($title, $tag, $url, $content, $oldfile, $destination,$datetime);
}
else {
$url = $title;
edit_post($title, $tag, $url, $content, $oldfile, $destination);
edit_post($title, $tag, $url, $content, $oldfile, $destination,$datetime);
}
}
else {
@ -269,11 +276,54 @@ get('/:year/:month/:name/delete', function($year, $month, $name){
}
});
// Get deleted data for blog post
post('/:year/:month/:name/delete', function() {
// Delete blog post
get('/:year/:month/:name/deletedraft', function($year, $month, $name){
$user = $_SESSION['user'];
$role = user('role', $user);
if(login()) {
config('views.root', 'system/admin/views');
$post = find_post($year, $month, $name, true);
if(!$post){
not_found();
}
$current = $post['current'];
if($user === $current->author || $role === 'admin') {
render('delete-post',array(
'head_contents' => head_contents('Delete post - ' . blog_title(), blog_description(), site_url()),
'p' => $current,
'bodyclass' => 'deletepost',
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . site_url() . '">' .config('breadcrumb.home'). '</a></span> &#187; '. $current->tagb . ' &#187; ' . $current->title
));
}
else {
render('denied',array(
'head_contents' => head_contents('Delete post - ' . blog_title(), blog_description(), site_url()),
'p' => $current,
'bodyclass' => 'deletepost',
'breadcrumb' => '<span typeof="v:Breadcrumb"><a property="v:title" rel="v:url" href="' . site_url() . '">' .config('breadcrumb.home'). '</a></span> &#187; '. $current->tagb . ' &#187; ' . $current->title
));
}
}
else {
$login = site_url() . 'login';
header("location: $login");
}
});
// Get deleted data for blog post
post('/:year/:month/:name/deletedraft', function() {
$draft = false;
$file = from($_REQUEST, 'file');
$destination = from($_GET, 'destination');
$destination = from($_GET, 'destination');
delete_post($file, $destination);
});
@ -388,7 +438,6 @@ get('/admin/posts', function () {
$perpage = 20;
$posts = get_posts(null, $page, $perpage);
$total = '';
if(empty($posts) || $page < 1){
@ -397,6 +446,7 @@ get('/admin/posts', function () {
render('no-posts',array(
'head_contents' => head_contents('All blog posts - ' . blog_title(), blog_description(), site_url()),
'bodyclass' => 'noposts',
'draft' => false
));
die;
@ -413,7 +463,66 @@ get('/admin/posts', function () {
'posts' => $posts,
'bodyclass' => 'all-posts',
'breadcrumb' => '',
'pagination' => has_pagination($total, $perpage, $page)
'pagination' => has_pagination($total, $perpage, $page),
'draft' => false
));
}
else {
render('denied',array(
'head_contents' => head_contents('All blog posts - ' . blog_title(), blog_description(), site_url()),
'bodyclass' => 'denied',
'breadcrumb' => '',
));
}
}
else {
$login = site_url() . 'login';
header("location: $login");
}
});
get('/admin/drafts', function () {
$user = $_SESSION['user'];
$role = user('role', $user);
if(login()) {
config('views.root', 'system/admin/views');
if($role === 'admin') {
config('views.root', 'system/admin/views');
$page = from($_GET, 'page');
$page = $page ? (int)$page : 1;
$perpage = 20;
$drafts = get_posts(null, $page, $perpage, true);
$total = '';
if(empty($drafts) || $page < 1){
// a non-existing page
render('no-posts',array(
'head_contents' => head_contents('All blog posts - ' . blog_title(), blog_description(), site_url()),
'bodyclass' => 'noposts',
'draft' => true,
));
die;
}
$tl = blog_tagline();
if($tl){ $tagline = ' - ' . $tl;} else {$tagline = '';}
render('posts-list',array(
'head_contents' => head_contents('All blog posts - ' . blog_title(), blog_description(), site_url()),
'heading' => 'All blog drafts',
'page' => $page,
'posts' => $drafts,
'bodyclass' => 'all-posts',
'breadcrumb' => '',
'pagination' => has_pagination($total, $perpage, $page),
'draft' => true,
));
}
else {
@ -430,6 +539,7 @@ get('/admin/posts', function () {
}
});
// The author page
get('/admin/mine', function(){
@ -466,7 +576,8 @@ get('/admin/mine', function(){
'name' => $bio->title,
'bodyclass' => 'userposts',
'breadcrumb' => '<a href="' . site_url() . '">' .config('breadcrumb.home'). '</a> &#187; Profile for: ' . $bio->title,
'pagination' => has_pagination($total, $perpage, $page)
'pagination' => has_pagination($total, $perpage, $page),
'draft' => false
));
die;
}
@ -489,6 +600,66 @@ get('/admin/mine', function(){
}
});
get('/admin/minedrafts', function(){
if(login()) {
config('views.root', 'system/admin/views');
$profile = $_SESSION['user'];
$page = from($_GET, 'page');
$page = $page ? (int)$page : 1;
$perpage = config('profile.perpage');
$drafts = get_profile($profile, $page, $perpage, true);
$total = get_count($profile, 'dirname');
$bio = get_bio($profile);
if(isset($bio[0])) {
$bio = $bio[0];
}
else {
$bio = default_profile($profile);
}
if(empty($drafts) || $page < 1){
render('user-posts',array(
'head_contents' => head_contents('My blog posts - ' . blog_title(), blog_description(), site_url()),
'page' => $page,
'heading' => 'My drafts',
'posts' => null,
'bio' => $bio->body,
'name' => $bio->title,
'bodyclass' => 'userposts',
'breadcrumb' => '<a href="' . site_url() . '">' .config('breadcrumb.home'). '</a> &#187; Profile for: ' . $bio->title,
'pagination' => has_pagination($total, $perpage, $page),
'draft' => true
));
die;
}
render('user-posts',array(
'head_contents' => head_contents('My blog posts - ' . blog_title(), blog_description(), site_url()),
'heading' => 'My drafts',
'page' => $page,
'posts' => $drafts,
'bio' => $bio->body,
'name' => $bio->title,
'bodyclass' => 'userposts',
'breadcrumb' => '<a href="' . site_url() . '">' .config('breadcrumb.home'). '</a> &#187; Profile for: ' . $bio->title,
'pagination' => has_pagination($total, $perpage, $page),
'draft' => true
));
}
else {
$login = site_url() . 'login';
header("location: $login");
}
});
// The static page
get('/:static', function($static){
@ -707,19 +878,19 @@ get('/add/post', function(){
// Get submitted blog post data
post('/add/post', function(){
$title = from($_REQUEST, 'title');
$tag = from($_REQUEST, 'tag');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
$datetime = from($_REQUEST, 'datetime');
$user = $_SESSION['user'];
if(!empty($title) && !empty($tag) && !empty($content)) {
if(!empty($url)) {
add_post($title, $tag, $url, $content, $user);
add_post($title, $tag, $url, $content, $user,$datetime);
}
else {
$url = $title;
add_post($title, $tag, $url, $content, $user);
add_post($title, $tag, $url, $content, $user,$datetime);
}
}
else {
@ -1027,6 +1198,8 @@ get('/feed/opml',function(){
// nothing has been matched above
get('.*',function(){
echo '<hr>';
die(var_dump($_GET));
not_found();
});


+ 55
- 22
system/includes/functions.php View File

@ -9,44 +9,49 @@ use \Suin\RSSWriter\Channel;
use \Suin\RSSWriter\Item;
// Get blog post path. Unsorted. Mostly used on widget.
function get_post_unsorted(){
function get_post_unsorted($draft = false){
static $_cache = array();
if(empty($_cache)){
// Get the names of all the posts
$_cache = glob('content/*/blog/*.md', GLOB_NOSORT);
$folder = ($draft)?'draft/*/blog/*.md':'content/*/blog/*.md';
$_cache = glob($folder, GLOB_NOSORT);
}
return $_cache;
}
// Get blog post with more info about the path. Sorted by filename.
function get_post_sorted(){
function get_post_sorted($draft = false){
static $tmp= array();
static $_cache = array();
if(empty($_cache)){
static $_cache_draft = array();
if((!$draft && empty($_cache)) || ($draft && empty($_cache_draft))){
// Get the names of all the posts
$tmp = glob('content/*/blog/*.md', GLOB_NOSORT);
$folder = (($draft)?'draft/*/blog/*.md':'content/*/blog/*.md');
$tmp = glob($folder, GLOB_NOSORT);
if (is_array($tmp)) {
foreach($tmp as $file) {
$_cache[] = pathinfo($file);
if ($draft)
$_cache_draft[] = pathinfo($file);
else
$_cache[] = pathinfo($file);
}
}
}
usort($_cache, "sortfile");
return $_cache;
if ($draft)
usort($_cache_draft, "sortfile");
else
usort($_cache, "sortfile");
return ($draft)?$_cache_draft:$_cache;
}
// Get static page path. Unsorted.
@ -108,10 +113,9 @@ function sortdate($a, $b) {
}
// Return blog posts.
function get_posts($posts, $page = 1, $perpage = 0){
function get_posts($posts, $page = 1, $perpage = 0 , $draft = false){
if(empty($posts)) {
$posts = get_post_sorted();
$posts = get_post_sorted($draft);
}
$tmp = array();
@ -196,9 +200,9 @@ function get_posts($posts, $page = 1, $perpage = 0){
}
// Find post by year, month and name, previous, and next.
function find_post($year, $month, $name){
function find_post($year, $month, $name,$draft = false){
$posts = get_post_sorted();
$posts = get_post_sorted($draft);
foreach ($posts as $index => $v) {
$url = $v['basename'];
@ -303,9 +307,9 @@ function get_archive($req, $page, $perpage){
}
// Return posts list on profile.
function get_profile($profile, $page, $perpage){
function get_profile($profile, $page, $perpage, $draft = false){
$posts = get_post_sorted();
$posts = get_post_sorted($draft);
$tmp = array();
@ -1565,8 +1569,12 @@ function toolbar() {
EOF;
echo '<div id="toolbar"><ul>';
echo '<li><a href="'.$base.'admin">Admin</a></li>';
if ($role === 'admin') {echo '<li><a href="'.$base.'admin/posts">Posts</a></li>';}
echo '<li><a href="'.$base.'admin/mine">Mine</a></li>';
if ($role === 'admin') {
echo '<li><a href="'.$base.'admin/posts">Posts</a></li>';
echo '<li><a href="'.$base.'admin/drafts">Drafts</a></li>';
}
echo '<li><a href="'.$base.'admin/mine">Mine Posts</a></li>';
echo '<li><a href="'.$base.'admin/minedrafts">Mine Drafts</a></li>';
echo '<li><a href="'.$base.'add/post">Add post</a></li>';
echo '<li><a href="'.$base.'add/page">Add page</a></li>';
echo '<li><a href="'.$base.'edit/profile">Edit profile</a></li>';
@ -1575,4 +1583,29 @@ EOF;
echo '<li><a href="'.$base.'logout">Logout</a></li>';
echo '</ul></div>';
}
//move drafts to posts
function check_drafts_to_posts() {
$datacorrente = date('U'); //strtotime("now");
foreach (get_post_sorted(true) as $index => $fileinfo) {
/*
var_dump($fileinfo);
echo '<br>';
echo date('Y-m-d-H-m-s');
echo '<br>';
*/
$data = DateTime::createFromFormat('Y-m-d-H-m-s',explode('_',$fileinfo['filename'])[0])->format('U');
//echo $datacorrente . " - " . $data;
if ($datacorrente >= $data) {
$oldfile = $fileinfo['dirname'].'/'.$fileinfo['basename'];
$temparray = explode('/',$fileinfo['dirname']);
array_shift($temparray);
$newfile = 'content/' . implode('/',$temparray) . '/' . $fileinfo['basename'];
$contenuto = file_get_contents($oldfile);
if (file_put_contents($newfile,$contenuto))
unlink($oldfile);
}
}
}

Loading…
Cancel
Save