Code Improvements
This commit is contained in:
parent
08ee5eaf39
commit
75b705ee2c
14 changed files with 933 additions and 521 deletions
|
@ -1,13 +1,10 @@
|
|||
/**
|
||||
* Created by mmk2410 on 2016-02-16.
|
||||
*
|
||||
* JavaScript for the ajax request to generate a atom feed
|
||||
*
|
||||
* Copyright (c) 2016 by mmk2410
|
||||
* License: MIT License
|
||||
*/
|
||||
|
||||
|
||||
function main() {
|
||||
// listener and function for calling the ajax request to create the
|
||||
// requested atom feed
|
||||
|
|
|
@ -1,30 +1,45 @@
|
|||
/**
|
||||
* Created by mmk2410 on 12/6/15.
|
||||
* JavaScript for the ajax request to delete blog post
|
||||
*
|
||||
* JavaScript for the functionality to delete blogs
|
||||
* Copyright (c) 2016 by mmk2410
|
||||
* License: MIT License
|
||||
*/
|
||||
|
||||
function main() {
|
||||
|
||||
// listener and function for recieving the posts of the selected blogs
|
||||
$("#delete_get_posts").click(function () {
|
||||
|
||||
var selectedBlog = $("#delete_selected_blog").val();
|
||||
|
||||
$.get("res/get_posts.php", {
|
||||
blog: selectedBlog
|
||||
}, function (data) {
|
||||
|
||||
$("#delete_select_post").remove();
|
||||
$("#delete_select_post_info").remove();
|
||||
$("#delete_post_button").remove();
|
||||
$("#delete_get_posts").after("<p id='delete_select_post'></p>");
|
||||
$("#delete_get_posts").after("<p id='delete_select_post_info'>Now select the post you want to delete. " +
|
||||
"Remember that once a post is deleted it can't be restored.</p>");
|
||||
$("#delete_select_post").append("<select id='delete_selected_post'></select>");
|
||||
$("#delete_get_posts").after(
|
||||
"<p id='delete_select_post_info'>" +
|
||||
"Now select the post you want to delete. " +
|
||||
"Remember that once a post is deleted it can't be restored.</p>"
|
||||
);
|
||||
$("#delete_select_post").append(
|
||||
"<select id='delete_selected_post'></select>"
|
||||
);
|
||||
|
||||
$.each($.parseJSON(data), function (index, value) {
|
||||
var post = value.substring(0, value.length - 3);
|
||||
$("#delete_selected_post").append("<option value='" + post + "'>" + post + "</option>");
|
||||
$("#delete_selected_post").append(
|
||||
"<option value='" + post + "'>" + post + "</option>"
|
||||
);
|
||||
});
|
||||
$("#delete_select_post").after("<a class='button' id='delete_post_button' " +
|
||||
"onclick='deletePostButton()'>DELETE POST</a>")
|
||||
|
||||
$("#delete_select_post").after(
|
||||
"<a class='button' id='delete_post_button' " +
|
||||
"onclick='deletePostButton()'>DELETE POST</a>"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -37,10 +52,12 @@ function deletePostButton() {
|
|||
|
||||
var selectedBlog = $("#delete_selected_blog").val();
|
||||
var selectedPost = $("#delete_selected_post").val();
|
||||
|
||||
$.get("res/delete_post.php", {
|
||||
blog: selectedBlog,
|
||||
post: selectedPost
|
||||
}, function (data) {
|
||||
|
||||
$("#delete_select_post").remove();
|
||||
$("#delete_select_post_info").remove();
|
||||
$("#delete_post_button").remove();
|
||||
|
@ -51,7 +68,10 @@ function deletePostButton() {
|
|||
} else if (data == "941") {
|
||||
alert("ERROR 941: No blog as get argument given");
|
||||
} else if (data == "961") {
|
||||
alert("ERROR 961: Error while deleting the file. Check if the web server has the permission to do so.");
|
||||
alert(
|
||||
"ERROR 961: Error while deleting the file. Check if the" +
|
||||
"web server has the permission to do so."
|
||||
);
|
||||
} else if (data == "0") {
|
||||
alert("Post successfully deleted.");
|
||||
}
|
||||
|
@ -59,4 +79,4 @@ function deletePostButton() {
|
|||
|
||||
}
|
||||
|
||||
$(document).ready(main());
|
||||
$(document).ready(main());
|
||||
|
|
|
@ -2,8 +2,35 @@
|
|||
/**
|
||||
* PHP Version 7
|
||||
*
|
||||
* User: mmk2410
|
||||
* Date: 12/6/15
|
||||
* @category Blogging
|
||||
* @package Rcc
|
||||
* @author Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
|
||||
* @license MIT License
|
||||
* @link https://mmk2410.org/rangitaki
|
||||
*
|
||||
* delete post script
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright 2015 mmk2410.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* Error Codes:
|
||||
* 901 No post given as get argument
|
||||
|
@ -11,17 +38,24 @@
|
|||
* 941 No blog given as get argument
|
||||
* 961 Error while deleting the post
|
||||
*/
|
||||
|
||||
$post = $_GET["post"];
|
||||
$blog = $_GET["blog"];
|
||||
if (!isset($post)) {
|
||||
echo "901";
|
||||
} else if (!isset($blog)) {
|
||||
echo "941";
|
||||
} else if (!file_exists("./../../articles/$blog/$post.md")) {
|
||||
echo "921";
|
||||
} else {
|
||||
if (unlink("./../../articles/$blog/$post.md")) {
|
||||
echo "0";
|
||||
|
||||
session_start();
|
||||
if ($_SESSION['login']) {
|
||||
if (!isset($post)) {
|
||||
echo "901";
|
||||
} else if (!isset($blog)) {
|
||||
echo "941";
|
||||
} else if (!file_exists("./../../articles/$blog/$post.md")) {
|
||||
echo "921";
|
||||
} else {
|
||||
if (unlink("./../../articles/$blog/$post.md")) {
|
||||
echo "0";
|
||||
}
|
||||
echo "961";
|
||||
}
|
||||
echo "961";
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,41 +1,54 @@
|
|||
/**
|
||||
* Created by mmk2410 on 12/6/15.
|
||||
* JavaScript for the ajax request to edit a article
|
||||
*
|
||||
* JavaScript for the functionality to delete blogs
|
||||
* Copyright (c) 2016 by mmk2410
|
||||
* License: MIT License
|
||||
*/
|
||||
|
||||
function main() {
|
||||
|
||||
// listener and function for recieving the posts of the selected blogs
|
||||
$("#edit_get_posts").click(function () {
|
||||
|
||||
var selectedBlog = $("#edit_selected_blog").val();
|
||||
$.get("res/get_posts.php", {
|
||||
blog: selectedBlog
|
||||
}, function (data) {
|
||||
|
||||
$("#edit_select_post").remove();
|
||||
$("#edit_select_post_info").remove();
|
||||
$("#edit_post_button").remove();
|
||||
$("#edit_get_posts").after("<p id='edit_select_post'></p>");
|
||||
$("#edit_get_posts").after("<p id='edit_select_post_info'>Now select the post you want to edit.</p>");
|
||||
$("#edit_select_post").append("<select id='edit_selected_post'></select>");
|
||||
$("#edit_get_posts").after(
|
||||
"<p id='edit_select_post_info'>" +
|
||||
"Now select the post you want to edit.</p>"
|
||||
);
|
||||
$("#edit_select_post").append(
|
||||
"<select id='edit_selected_post'></select>"
|
||||
);
|
||||
$.each($.parseJSON(data), function (index, value) {
|
||||
var post = value.substring(0, value.length - 3);
|
||||
$("#edit_selected_post").append("<option value='" + post + "'>" + post + "</option>");
|
||||
$("#edit_selected_post").append(
|
||||
"<option value='" + post + "'>" + post + "</option>"
|
||||
);
|
||||
});
|
||||
$("#edit_select_post").after("<a class='button' id='edit_post_button' " +
|
||||
"onclick='editPostButton()'>EDIT POST</a>")
|
||||
$("#edit_select_post").after(
|
||||
"<a class='button' id='edit_post_button' " +
|
||||
"onclick='editPostButton()'>EDIT POST</a>"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
$("#save_changes").click(function () {
|
||||
|
||||
var postTitle = $("#title").val();
|
||||
var postDate = $("#date").val();
|
||||
var postAuthor = $("#author").val();
|
||||
var postTags = $("#tags").val();
|
||||
var postText = $("#text").val();
|
||||
|
||||
var file = "../../articles/" + getVariables['blog'] + "/" + getVariables['post'] + ".md";
|
||||
console.log(file);
|
||||
var file = "../../articles/" + getVariables.blog +
|
||||
"/" + getVariables.post + ".md";
|
||||
|
||||
$.post("../res/save.php", {
|
||||
title: postTitle,
|
||||
|
@ -69,4 +82,4 @@ function editPostButton() {
|
|||
|
||||
}
|
||||
|
||||
$(document).ready(main());
|
||||
$(document).ready(main());
|
||||
|
|
|
@ -2,26 +2,57 @@
|
|||
/**
|
||||
* PHP Version 7
|
||||
*
|
||||
* User: mmk2410
|
||||
* Date: 12/6/15
|
||||
* @category Blogging
|
||||
* @package Rcc
|
||||
* @author Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
|
||||
* @license MIT License
|
||||
* @link https://mmk2410.org/rangitaki
|
||||
*
|
||||
* get post script
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright 2015 mmk2410.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*
|
||||
* Error Codes:
|
||||
* 901 No blog given as get argument
|
||||
* 921 No blog with the given name available
|
||||
*/
|
||||
$blog = $_GET["blog"];
|
||||
if (!isset($blog)) {
|
||||
echo "901";
|
||||
} else if (!file_exists("./../../blogs/$blog.md")) {
|
||||
echo "921";
|
||||
} else {
|
||||
$posts = array();
|
||||
$i = 0;
|
||||
foreach (scandir("./../../articles/$blog/") as $article) {
|
||||
if (substr($article, -3) == ".md") {
|
||||
$posts[$i] = $article;
|
||||
$i++;
|
||||
|
||||
session_start();
|
||||
if ($_SESSION['login']) {
|
||||
$blog = $_GET["blog"];
|
||||
if (!isset($blog)) {
|
||||
echo "901";
|
||||
} else if (!file_exists("./../../blogs/$blog.md")) {
|
||||
echo "921";
|
||||
} else {
|
||||
$posts = array();
|
||||
$i = 0;
|
||||
foreach (scandir("./../../articles/$blog/") as $article) {
|
||||
if (substr($article, -3) == ".md") {
|
||||
$posts[$i] = $article;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
print json_encode($posts);
|
||||
}
|
||||
print json_encode($posts);
|
||||
}
|
||||
|
|
|
@ -1,30 +1,29 @@
|
|||
/*
|
||||
The MIT License
|
||||
|
||||
Copyright 2015 mmk2410.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
/*
|
||||
Created on : Jun 14, 2015, 6:13:38 PM
|
||||
Author : mmk2410
|
||||
*/
|
||||
* RCC cascade style sheet
|
||||
*
|
||||
* Copyright (C) 2015-2016 Marcel Kapfer (mmk2410)
|
||||
* MIT License
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* BODY */
|
||||
|
||||
|
@ -273,4 +272,4 @@ form{
|
|||
#back-card {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,32 @@
|
|||
/**
|
||||
* JavaScript for RCC
|
||||
*
|
||||
* Copyright (c) 2016 by mmk2410
|
||||
* License: MIT License
|
||||
*/
|
||||
|
||||
window.onload = function () {
|
||||
var t = document.getElementsByTagName('textarea')[0];
|
||||
var offset = !window.opera ? (t.offsetHeight - t.clientHeight) : (t.offsetHeight + parseInt(window.getComputedStyle(t, null).getPropertyValue('border-top-width')));
|
||||
var offset = !window.opera ? (t.offsetHeight - t.clientHeight) : (
|
||||
t.offsetHeight + parseInt(
|
||||
window.getComputedStyle(t, null).getPropertyValue('border-top-width')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* The following three code clocks are for proper resizing of the input textarea
|
||||
* The following three code clocks are for proper resizing of the input
|
||||
* textarea
|
||||
*/
|
||||
var resize = function (t) {
|
||||
t.style.height = 'auto';
|
||||
t.style.height = (t.scrollHeight + offset ) + 'px';
|
||||
}
|
||||
};
|
||||
|
||||
t.addEventListener && t.addEventListener('input', function (event) {
|
||||
resize(t);
|
||||
});
|
||||
|
||||
t['attachEvent'] && t.attachEvent('onkeyup', function () {
|
||||
t.attachEvent && t.attachEvent('onkeyup', function () {
|
||||
resize(t);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,11 +1,46 @@
|
|||
<?php
|
||||
$title = $_POST["title"];
|
||||
$date = $_POST["date"];
|
||||
$author = $_POST["author"];
|
||||
$tags = $_POST["tags"];
|
||||
$text = $_POST["text"];
|
||||
$filename = $_POST["file"];
|
||||
$md = <<<EOD
|
||||
/**
|
||||
* PHP Version 7
|
||||
*
|
||||
* @category Blogging
|
||||
* @package Rcc
|
||||
* @author Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
|
||||
* @license MIT License
|
||||
* @link https://mmk2410.org/rangitaki
|
||||
*
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Copyright 2015 mmk2410.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
session_start();
|
||||
if ($_SESSION['login']) {
|
||||
$title = $_POST["title"];
|
||||
$date = $_POST["date"];
|
||||
$author = $_POST["author"];
|
||||
$tags = $_POST["tags"];
|
||||
$text = $_POST["text"];
|
||||
$filename = $_POST["file"];
|
||||
$md = <<<EOD
|
||||
%TITLE: $title
|
||||
%DATE: $date
|
||||
%AUTHOR: $author
|
||||
|
@ -13,10 +48,11 @@ $md = <<<EOD
|
|||
|
||||
$text
|
||||
EOD;
|
||||
if (file_put_contents($filename, $md)) {
|
||||
echo 0;
|
||||
} else if (file_exists(($filename))) {
|
||||
echo 1;
|
||||
} else {
|
||||
echo -1;
|
||||
if (file_put_contents($filename, $md)) {
|
||||
echo 0;
|
||||
} else if (file_exists(($filename))) {
|
||||
echo 1;
|
||||
} else {
|
||||
echo -1;
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue