Delete Posts
Edit Posts Back to blog
This commit is contained in:
parent
fbca74ccec
commit
6e6e26ad26
11 changed files with 574 additions and 121 deletions
3
articles/main/2015-07-24-example.md
Normal file → Executable file
3
articles/main/2015-07-24-example.md
Normal file → Executable file
|
@ -1,7 +1,10 @@
|
||||||
%TITLE: The Rangitaki logo
|
%TITLE: The Rangitaki logo
|
||||||
%DATE: 24 July 2015
|
%DATE: 24 July 2015
|
||||||
|
%AUTHOR: The great testers
|
||||||
%TAGS: design, artwork, logo
|
%TAGS: design, artwork, logo
|
||||||
|
|
||||||
|
|
||||||
This is the official Rangitaki logo.
|
This is the official Rangitaki logo.
|
||||||
|
|
||||||
![The Rangitaki logo](media/example.png)
|
![The Rangitaki logo](media/example.png)
|
||||||
|
|
|
@ -15,7 +15,7 @@ $bloghome = 'yes';
|
||||||
$bloghomeurl = '../';
|
$bloghomeurl = '../';
|
||||||
// Home name - Set here an individual name for your main page
|
// Home name - Set here an individual name for your main page
|
||||||
$bloghomename = 'Home';
|
$bloghomename = 'Home';
|
||||||
// Main Blog name -> Set a specific name for your name blog
|
// Main Blog name -> Set a specific name for your main blog
|
||||||
// This value is empty by default
|
// This value is empty by default
|
||||||
$blogmainname = '';
|
$blogmainname = '';
|
||||||
// Intro - set yes if you have a blog intro and no if you don't have one
|
// Intro - set yes if you have a blog intro and no if you don't have one
|
||||||
|
|
112
rcc/edit/index.php
Normal file
112
rcc/edit/index.php
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
<?php
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
|
?>
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Rangitaki Control Center</title>
|
||||||
|
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport"/>
|
||||||
|
<link rel="stylesheet" href="../res/rcc.css"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="header">
|
||||||
|
<a href="../" class="title">Rangitaki Control Center</a>
|
||||||
|
</div>
|
||||||
|
<div class="main">
|
||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
if ($_SESSION['login']) {
|
||||||
|
include_once("../../res/php/ArticleGenerator.php");
|
||||||
|
$directory = "./../../articles/" . $_GET['blog'] . "/";
|
||||||
|
$article = $_GET['post'] . ".md";
|
||||||
|
?>
|
||||||
|
<section class="card">
|
||||||
|
<div class="headline">Edit Post</div>
|
||||||
|
<p>Title:<br><br><input type="text" class="itextfield"
|
||||||
|
value="<?php echo ArticleGenerator::getTitle($directory, $article) ?>"
|
||||||
|
name="title"
|
||||||
|
id="title"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>Date:<br><br><input type="text" class="itextfield"
|
||||||
|
value="<?php echo ArticleGenerator::getDate($directory, $article) ?>" name="date"
|
||||||
|
id="date"/>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>Author:<br><br><input type="text"
|
||||||
|
value="<?php echo ArticleGenerator::getAuthor($directory, $article) ?>"
|
||||||
|
class="itextfield" name="author"
|
||||||
|
id="author"/></p>
|
||||||
|
|
||||||
|
<p>Tags:<br><br><input type="text"
|
||||||
|
value="<?php
|
||||||
|
$tags = "";
|
||||||
|
foreach (ArticleGenerator::getTags($directory, $article) as $tag) {
|
||||||
|
$tags = $tags . ', ' . $tag;
|
||||||
|
}
|
||||||
|
$tags = substr($tags, 2);
|
||||||
|
echo $tags;
|
||||||
|
?>"
|
||||||
|
class="itextfield" name="tags"
|
||||||
|
id="tags"/></p>
|
||||||
|
|
||||||
|
<p>Text:</p>
|
||||||
|
<textarea class="itextarea" name="text" id="text">
|
||||||
|
<?php echo ArticleGenerator::getText($directory, $article) ?>
|
||||||
|
</textarea>
|
||||||
|
<br><br>
|
||||||
|
<a class="button" id="save_changes">SAVE CHANGES</a>
|
||||||
|
</section>
|
||||||
|
<section class="card">
|
||||||
|
<div class="headline">Back</div>
|
||||||
|
<p>
|
||||||
|
Go back to the RCC home. All changes will be lost.
|
||||||
|
</p>
|
||||||
|
<a class="button" href="../">BACK</a>
|
||||||
|
</section>
|
||||||
|
<?php
|
||||||
|
} else {
|
||||||
|
?>
|
||||||
|
<section class="card">
|
||||||
|
<div class="headline">Access denied</div>
|
||||||
|
<p>
|
||||||
|
The access to this area is not granted. Make sure you're logged in.
|
||||||
|
</p>
|
||||||
|
<a class="button" href="../">BACK</a>
|
||||||
|
</section>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
var getVariables = <?php echo json_encode($_GET); ?>;
|
||||||
|
</script>
|
||||||
|
<script src="../../res/js/jquery-2.1.4.min.js"></script>
|
||||||
|
<script src="../res/rcc.js"></script>
|
||||||
|
<script src="../res/edit.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
283
rcc/index.php
283
rcc/index.php
|
@ -23,136 +23,183 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
-->
|
-->
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Rangitaki Control Center</title>
|
<title>Rangitaki Control Center</title>
|
||||||
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
|
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport'/>
|
||||||
<link rel="stylesheet" href="./res/rcc.css" />
|
<link rel="stylesheet" href="./res/rcc.css"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<a href="./" class="title">Rangitaki Control Center</a>
|
<a href="./" class="title">Rangitaki Control Center</a>
|
||||||
<a href="../" class="back">Back to the blog</a>
|
<a href="../" class="back">Back to the blog</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="main">
|
<div class="main">
|
||||||
|
<?php
|
||||||
|
require '../config.php';
|
||||||
|
if ($rcc == "yes") {
|
||||||
|
include 'password.php';
|
||||||
|
session_start();
|
||||||
|
if (isset($_POST['passwd'])) {
|
||||||
|
$passwd = $_POST['passwd'];
|
||||||
|
$_SESSION['passwd'] = $_POST['passwd'];
|
||||||
|
} else if (isset($_SESSION['passwd'])) {
|
||||||
|
$passwd = $_SESSION['passwd'];
|
||||||
|
}
|
||||||
|
if ($passwd == "") {
|
||||||
|
?>
|
||||||
|
<section class="card">
|
||||||
|
<div class="headline">Log In</div>
|
||||||
|
<form action="./" method="post">
|
||||||
|
<p>Password:<br><br><input type="password" class="itextfield" name="passwd"/></p>
|
||||||
|
<input type="Submit" class="button" value="Log in"/>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
<?php
|
<?php
|
||||||
require '../config.php';
|
} else {
|
||||||
if ($rcc == "yes") {
|
if ($passwd == $password) {
|
||||||
include 'password.php';
|
$_SESSION['login'] = true;
|
||||||
session_start();
|
include_once("./../res/php/BlogListGenerator.php");
|
||||||
if(isset($_POST['passwd'])) {
|
?>
|
||||||
$passwd = $_POST['passwd'];
|
<section class="card">
|
||||||
$_SESSION['passwd'] = $_POST['passwd'];
|
<div class="headline">Post Upload</div>
|
||||||
} else if(isset($_SESSION['passwd'])) {
|
<form enctype="multipart/form-data" action="uploaded/" method="POST">
|
||||||
$passwd = $_SESSION['passwd'];
|
<select name="blog">
|
||||||
}
|
<?php
|
||||||
if ($passwd == "") {
|
$blogs = scandir("../blogs/");
|
||||||
?>
|
foreach ($blogs as $blog) {
|
||||||
<section class="card">
|
if (strlen($blog) >= 3 && substr($blog, -3) == ".md") {
|
||||||
<div class="headline">Log In</div>
|
$blog = substr($blog, 0, -3);
|
||||||
<form action="./" method="post">
|
echo "<option value='$blog'>$blog</option>";
|
||||||
<p>Password:<br><br><input type="password" class="itextfield" name="passwd"/></p>
|
}
|
||||||
<input type="Submit" class="button" value="Log in"/>
|
}
|
||||||
</form>
|
?>
|
||||||
</section>
|
</select>
|
||||||
<?php
|
<input type="hidden" name="MAX_FILE_SIZE" value="100000"/>
|
||||||
} else {
|
<input id="" name="userfile" type="file" value="Choose a file"/>
|
||||||
if ($passwd == $password) {
|
<br>
|
||||||
$_SESSION['login'] = true;
|
<br>
|
||||||
?>
|
<input id="button" type="submit" value="Upload" class="button"/>
|
||||||
<section class="card">
|
</form>
|
||||||
<div class="headline">Post Upload</div>
|
</section>
|
||||||
<form enctype="multipart/form-data" action="uploaded/" method="POST">
|
<section class="card">
|
||||||
<select name="blog">
|
<div class="headline">New Post</div>
|
||||||
<?php
|
<form action="newpost/" method="POST">
|
||||||
$blogs = scandir("../blogs/");
|
<p>Blog:</p>
|
||||||
foreach ($blogs as $blog) {
|
<select name="blog">
|
||||||
if (strlen($blog) >= 3 && substr($blog, -3) == ".md") {
|
<?php
|
||||||
$blog = substr($blog, 0, -3);
|
$blogs = scandir("../blogs/");
|
||||||
echo "<option value='$blog'>$blog</option>";
|
foreach ($blogs as $blog) {
|
||||||
}
|
if (strlen($blog) >= 3 && substr($blog, -3) == ".md") {
|
||||||
}
|
$blog = substr($blog, 0, -3);
|
||||||
?>
|
echo "<option value='$blog'>$blog</option>";
|
||||||
</select>
|
}
|
||||||
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
|
}
|
||||||
<input id="" name="userfile" type="file" value="Choose a file" />
|
?>
|
||||||
<br>
|
</select>
|
||||||
<br>
|
|
||||||
<input id="button" type="submit" value="Upload" class="button"/>
|
|
||||||
</form>
|
|
||||||
</section>
|
|
||||||
<section class="card">
|
|
||||||
<div class="headline">New Post</div>
|
|
||||||
<form action="newpost/" method="POST">
|
|
||||||
<p>Blog:</p>
|
|
||||||
<select name="blog">
|
|
||||||
<?php
|
|
||||||
$blogs = scandir("../blogs/");
|
|
||||||
foreach ($blogs as $blog) {
|
|
||||||
if (strlen($blog) >= 3 && substr($blog, -3) == ".md") {
|
|
||||||
$blog = substr($blog, 0, -3);
|
|
||||||
echo "<option value='$blog'>$blog</option>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<p>Title:<br><br><input type="text" class="itextfield" name="title"/></p>
|
<p>Title:<br><br><input type="text" class="itextfield" name="title"/></p>
|
||||||
|
|
||||||
<p>Date:<br><br><input type="text" class="itextfield" name="date"/></p>
|
<p>Date:<br><br><input type="text" class="itextfield" name="date"/></p>
|
||||||
|
|
||||||
<p>Author:<br><br><input type="text" class="itextfield" name="author"/></p>
|
<p>Author:<br><br><input type="text" class="itextfield" name="author"/></p>
|
||||||
|
|
||||||
<p>Tags:<br><br><input type="text" class="itextfield" name="tags"/></p>
|
<p>Tags:<br><br><input type="text" class="itextfield" name="tags"/></p>
|
||||||
|
|
||||||
<p>Text:</p>
|
<p>Text:</p>
|
||||||
<textarea class="itextarea" name="text"></textarea>
|
<textarea class="itextarea" name="text"></textarea>
|
||||||
<br><br>
|
<br><br>
|
||||||
<input id="button" type="submit" value="Post" class="button"/>
|
<input id="button" type="submit" value="Post" class="button"/>
|
||||||
</form>
|
</form>
|
||||||
</section>
|
</section>
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="headline">Media Upload</div>
|
<div class="headline">Edit post</div>
|
||||||
<form enctype="multipart/form-data" action="media/" method="POST">
|
<p>
|
||||||
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />
|
First select the blog of the post you wan't to edit.
|
||||||
<input id="" name="userfile" type="file" value="Choose a file" />
|
</p>
|
||||||
<br>
|
|
||||||
<br>
|
<p id="edit_select_blog">
|
||||||
<input id="button" type="submit" value="Upload" class="button"/>
|
<select name="blog" id="edit_selected_blog">
|
||||||
</form>
|
<?php
|
||||||
</section>
|
$blogs = scandir("../blogs/");
|
||||||
<?php
|
foreach ($blogs as $blog) {
|
||||||
} else {
|
if (strlen($blog) >= 3 && substr($blog, -3) == ".md") {
|
||||||
?>
|
$blog = substr($blog, 0, -3);
|
||||||
<section class="card">
|
echo "<option value='$blog'>$blog</option>";
|
||||||
<div class="headline">Wrong Password</div>
|
}
|
||||||
<p>
|
}
|
||||||
Please go back and try again.
|
?>
|
||||||
</p>
|
</select>
|
||||||
<a href="./" class="button">GO BACK</a>
|
</p>
|
||||||
</section>
|
<a class="button" id="edit_get_posts">GET POSTS</a>
|
||||||
<?php
|
</section>
|
||||||
}
|
<section class="card">
|
||||||
}
|
<div class="headline">Delete Post</div>
|
||||||
|
<p>
|
||||||
|
First select the subblog of the post you want to delete.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p id="delete_select_blog">
|
||||||
|
<select name="blog" id="delete_selected_blog">
|
||||||
|
<?php
|
||||||
|
$blogs = scandir("../blogs/");
|
||||||
|
foreach ($blogs as $blog) {
|
||||||
|
if (strlen($blog) >= 3 && substr($blog, -3) == ".md") {
|
||||||
|
$blog = substr($blog, 0, -3);
|
||||||
|
echo "<option value='$blog'>$blog</option>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
<a class="button" id="delete_get_posts">GET POSTS</a>
|
||||||
|
</section>
|
||||||
|
<section class="card">
|
||||||
|
<div class="headline">Media Upload</div>
|
||||||
|
<form enctype="multipart/form-data" action="media/" method="POST">
|
||||||
|
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000"/>
|
||||||
|
<input id="" name="userfile" type="file" value="Choose a file"/>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<input id="button" type="submit" value="Upload" class="button"/>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
|
<?php
|
||||||
} else {
|
} else {
|
||||||
?>
|
?>
|
||||||
<section class="card">
|
<section class="card">
|
||||||
<div class="headline">Rangitaki Control Center</div>
|
<div class="headline">Wrong Password</div>
|
||||||
<p>
|
<p>
|
||||||
The Rangitaki Control Center is disabled. You can enable it in your config file. But please read first the documentation.
|
Please go back and try again.
|
||||||
</p>
|
</p>
|
||||||
|
<a href="./" class="button">GO BACK</a>
|
||||||
</section>
|
</section>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
?>
|
}
|
||||||
<section class="card" id="back-card">
|
} else {
|
||||||
<div class="headline">Back</div>
|
?>
|
||||||
<p>
|
<section class="card">
|
||||||
Go back to your blog.
|
<div class="headline">Rangitaki Control Center</div>
|
||||||
</p>
|
<p>
|
||||||
<a href="../" class="button">GO BACK</a>
|
The Rangitaki Control Center is disabled. You can enable it in your config file. But please read first
|
||||||
</section>
|
the documentation.
|
||||||
</div>
|
</p>
|
||||||
<script src="./res/rcc.js"></script>
|
</section>
|
||||||
</body>
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<section class="card" id="back-card">
|
||||||
|
<div class="headline">Back</div>
|
||||||
|
<p>
|
||||||
|
Go back to your blog.
|
||||||
|
</p>
|
||||||
|
<a href="../" class="button">GO BACK</a>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
<script src="./res/rcc.js"></script>
|
||||||
|
<script src="../res/js/jquery-2.1.4.min.js"></script>
|
||||||
|
<script src="./res/delete.js"></script>
|
||||||
|
<script src="./res/edit.js"></script>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
62
rcc/res/delete.js
Normal file
62
rcc/res/delete.js
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/**
|
||||||
|
* Created by mmk2410 on 12/6/15.
|
||||||
|
*
|
||||||
|
* JavaScript for the functionality to delete blogs
|
||||||
|
*/
|
||||||
|
|
||||||
|
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>");
|
||||||
|
$.each($.parseJSON(data), function (index, value) {
|
||||||
|
var post = value.substring(0, value.length - 3);
|
||||||
|
$("#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 the selected posts
|
||||||
|
*/
|
||||||
|
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();
|
||||||
|
if (data == "901") {
|
||||||
|
alert("ERROR 901: No post as get argument given.");
|
||||||
|
} else if (data == "921") {
|
||||||
|
alert("ERROR 921: No post with given argument available.");
|
||||||
|
} 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.");
|
||||||
|
} else if (data == "0") {
|
||||||
|
alert("Post successfully deleted.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(main());
|
25
rcc/res/delete_post.php
Normal file
25
rcc/res/delete_post.php
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* User: mmk2410
|
||||||
|
* Date: 12/6/15
|
||||||
|
*
|
||||||
|
* Error Codes:
|
||||||
|
* 901 No post given as get argument
|
||||||
|
* 921 No post with the given name available
|
||||||
|
* 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";
|
||||||
|
}
|
||||||
|
echo "961";
|
||||||
|
}
|
72
rcc/res/edit.js
Normal file
72
rcc/res/edit.js
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/**
|
||||||
|
* Created by mmk2410 on 12/6/15.
|
||||||
|
*
|
||||||
|
* JavaScript for the functionality to delete blogs
|
||||||
|
*/
|
||||||
|
|
||||||
|
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>");
|
||||||
|
$.each($.parseJSON(data), function (index, value) {
|
||||||
|
var post = value.substring(0, value.length - 3);
|
||||||
|
$("#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>")
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#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);
|
||||||
|
|
||||||
|
$.post("../res/save.php", {
|
||||||
|
title: postTitle,
|
||||||
|
date: postDate,
|
||||||
|
author: postAuthor,
|
||||||
|
tags: postTags,
|
||||||
|
text: postText,
|
||||||
|
file: file
|
||||||
|
}, function (data) {
|
||||||
|
if (data == "0") {
|
||||||
|
alert("File successfully changed.");
|
||||||
|
window.open("../");
|
||||||
|
} else if (data == "1") {
|
||||||
|
alert("Error while saving the changes.");
|
||||||
|
} else if (data == "-1") {
|
||||||
|
alert("file");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the selected posts
|
||||||
|
*/
|
||||||
|
function editPostButton() {
|
||||||
|
|
||||||
|
var selectedBlog = $("#edit_selected_blog").val();
|
||||||
|
var selectedPost = $("#edit_selected_post").val();
|
||||||
|
var href = "./edit/?blog=" + selectedBlog + "&post=" + selectedPost;
|
||||||
|
window.open(href);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(main());
|
25
rcc/res/get_posts.php
Normal file
25
rcc/res/get_posts.php
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* User: mmk2410
|
||||||
|
* Date: 12/6/15
|
||||||
|
*
|
||||||
|
* 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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print json_encode($posts);
|
||||||
|
}
|
|
@ -97,6 +97,15 @@ body{
|
||||||
border-bottom: none!important;
|
border-bottom: none!important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.subheadline {
|
||||||
|
font-size: 20px;
|
||||||
|
color: #383838 !important;
|
||||||
|
text-decoration: none;
|
||||||
|
display: block;
|
||||||
|
padding-bottom: 6px;
|
||||||
|
border-bottom: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
.card > p{
|
.card > p{
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
line-height: 24px;
|
line-height: 24px;
|
||||||
|
|
22
rcc/res/save.php
Normal file
22
rcc/res/save.php
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
$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
|
||||||
|
%TAGS: $tags
|
||||||
|
|
||||||
|
$text
|
||||||
|
EOD;
|
||||||
|
if (file_put_contents($filename, $md)) {
|
||||||
|
echo 0;
|
||||||
|
} else if (file_exists(($filename))) {
|
||||||
|
echo 1;
|
||||||
|
} else {
|
||||||
|
echo -1;
|
||||||
|
}
|
|
@ -112,7 +112,7 @@ class ArticleGenerator
|
||||||
* @param string $articlefile The name of the article file
|
* @param string $articlefile The name of the article file
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function getTags($directory, $articlefile)
|
static function getTags($directory, $articlefile)
|
||||||
{
|
{
|
||||||
$article = file_get_contents($directory . $articlefile); // get the article
|
$article = file_get_contents($directory . $articlefile); // get the article
|
||||||
if (substr($article, 0, 6) == "%TITLE") { // detect and remove the title
|
if (substr($article, 0, 6) == "%TITLE") { // detect and remove the title
|
||||||
|
@ -140,7 +140,7 @@ class ArticleGenerator
|
||||||
* @param string $articlefile The name of the article file
|
* @param string $articlefile The name of the article file
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function getTitle($directory, $articlefile)
|
static function getTitle($directory, $articlefile)
|
||||||
{
|
{
|
||||||
$article = file_get_contents($directory . $articlefile); // get the article
|
$article = file_get_contents($directory . $articlefile); // get the article
|
||||||
if (substr($article, 0, 6) == "%TITLE") { // detect and remove the title
|
if (substr($article, 0, 6) == "%TITLE") { // detect and remove the title
|
||||||
|
@ -149,4 +149,80 @@ class ArticleGenerator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function to get the date of an article
|
||||||
|
*
|
||||||
|
* @param $directory The directory where the article is stored
|
||||||
|
* @param $articlefile The name of the article file
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
static function getDate($directory, $articlefile)
|
||||||
|
{
|
||||||
|
$article = file_get_contents($directory . $articlefile);
|
||||||
|
|
||||||
|
if (substr($article, 0, 6) == "%TITLE") { // detect and remove the title
|
||||||
|
$article = substr($article, strpos($article, "\n") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($article, 0, 5) == "%DATE") { // detect and remove the title
|
||||||
|
$date = substr($article, 7, strpos($article, "\n") - 7);
|
||||||
|
return $date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function to get the author of an article
|
||||||
|
*
|
||||||
|
* @param $directory The directory where the article is stored
|
||||||
|
* @param $articlefile The name of the article file
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
static function getAuthor($directory, $articlefile)
|
||||||
|
{
|
||||||
|
$article = file_get_contents($directory . $articlefile);
|
||||||
|
|
||||||
|
if (substr($article, 0, 6) == "%TITLE") { // detect and remove the title
|
||||||
|
$article = substr($article, strpos($article, "\n") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($article, 0, 5) == "%DATE") { // detect and remove the title
|
||||||
|
$article = substr($article, strpos($article, "\n") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($article, 0, 7) == "%AUTHOR") { // detect and remove the title
|
||||||
|
$author = substr($article, 9, strpos($article, "\n") - 9);
|
||||||
|
return $author;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function to get the text of an article
|
||||||
|
*
|
||||||
|
* @param $directory The directory where the article is stored
|
||||||
|
* @param $articlefile The name of the article file
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
static function getText($directory, $articlefile)
|
||||||
|
{
|
||||||
|
$article = file_get_contents($directory . $articlefile);
|
||||||
|
|
||||||
|
if (substr($article, 0, 6) == "%TITLE") { // detect and remove the title
|
||||||
|
$article = substr($article, strpos($article, "\n") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($article, 0, 5) == "%DATE") { // detect and remove the title
|
||||||
|
$article = substr($article, strpos($article, "\n") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($article, 0, 7) == "%AUTHOR") { // detect and remove the title
|
||||||
|
$article = substr($article, strpos($article, "\n") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substr($article, 0, 5) == "%TAGS") { // detect the tags
|
||||||
|
$article = substr($article, strpos($article, "\n") + 1); // remove the tags
|
||||||
|
}
|
||||||
|
|
||||||
|
return $article;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue