category.php
File Type: php
File Location: monofiles/
File name: category.php
<?php
include_once 'data_connect.php';
if (isset($_POST['newcat'])){
$fname = str_replace(' ','',$_POST['foldername']);
$cname = str_replace(' ','',$_POST['newcat']);
if (($fname != '') && ($cname != '') && ($fname != ' ') && ($cname != ' ')){
$newcat = $_POST['newcat'];
$folder = str_replace(array('&','/',' ','$','+',',',':',';','=','?','@','<','>','#','%','{','}','|','^','~','[',']','`','\\','\'','"'),'-',strtolower($_POST['foldername']));
$root = '../category/'.$folder;
if (!is_dir($root))
mkdir($root,0777,true);
//// Tell the category file to include the index pattern from current style.
$indexcontent =
'if(!file_exists("../../pagep.php"))
exit("Error loading content. Please come back later.");
include "../../pagep.php"';
file_put_contents($root.'/index.php','<?php $catg="'.$newcat.'";'.PHP_EOL.$indexcontent.' ?>');
file_put_contents($root.'/name.txt',$newcat);
$_SESSION['MON_newcat'] = true;
header('Location:category.php');
exit();
}
elseif(isset($_POST['newcat'])) {
$_SESSION['MON_notset'] = true;
header('Location:category.php');
exit();
}
}
if (isset($_GET['deln'])) {
$name = $_GET['deln'];
$delroot = '../category/'.$_GET['deln'];
if (is_file($delroot.'/name.txt')) {
$delcat = file_get_contents($delroot.'/name.txt');
$resfiles = glob('autosaves/*.xml');
foreach($resfiles as $f){
$sxml = new SimpleXMLElement($f,null,true);
if ($sxml->postinfo->post->category == $delcat){
$sxml->postinfo->post->category = '-';
$sxml->asXML($f);
}
}
unlink($delroot.'/name.txt');
unlink($delroot.'/index.php');
rmdir($delroot);
$_SESSION['MON_delcat'] = true;
header('Location:category.php');
exit();
}
}
if (isset($_SESSION['MON_newcat'])){
$message = '<div id="action-confirm"><span>Category was created</span></div>';
unset($_SESSION['MON_newcat']);
}
if (isset($_SESSION['MON_delcat'])){
$message = '<div id="action-confirm"><span>Category was deleted</span></div>';
unset($_SESSION['MON_delcat']);
}
if (isset($_SESSION['MON_notset'])){
$message = '<div id="error-confirm"><span>No category or folder name was found</span></div>';
unset($_SESSION['MON_notset']);
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Post categories</title>
<link rel="stylesheet" type="text/css" href="cmstyle.css">
<?php
include 'csstheme.php'
?>
<script type="text/javascript"> function conf(form){ return confirm('Delete category?'); }</script>
</head>
<body>
<?php
include 'mypanel.php';
if (isset($message))
echo $message
?>
<div class="main">
<h1 class="inbl">Categories</h1>
<div id="main-container">
<span class="page-description">Categories apply to posts only. Deleting a category does not delete any posts.</span>
<h2>Add category</h2>
<form action="category.php" method="POST">
<input name="newcat" type="text" class="inp-usr" value="" placeholder="Category name">
<input name="foldername" type="text" class="inp-usr" value="" placeholder="Folder name">
<br>
<span style="font-size:12px;color:#999;margin-left:10px">Folder name is the name you see in url and is also where the category page will be saved.</span>
<input type="submit" class="stylish-button" value="Submit category" title="Submit category" style="margin:28px 0px 0px 10px">
</form>
<div class="clear"></div>
<div class="ctg">
<?php
$folders = glob('../category/*',GLOB_ONLYDIR);
$c=0;
foreach($folders as $cat){
$cat_name = file_get_contents($cat.'/name.txt');
$delname = basename($cat);
echo '<span class="cat">'.$cat_name.'<a href="category.php?deln='.$delname.'" title="Delete category" class="cat-del" onclick="return conf(this);">X</a></span>';
$c++;
}
if ($c==0)
echo '<span style="font-size:12px;color:#888">No categories</span>';
?>
</div>
</div>
</div>
</body>
</html>