post.php

File Type: php File Location: monofiles/ File name: post.php
<?php
    
    
include_once 'data_connect.php';
    include 
'log.php';

    if (isset(
$_POST['uniqueid'])) {
        
        
$x $_POST['uniqueid'];
        
$xmlinfo "autosaves/".$x.".xml";
        
    
        
//find user rights
        
if (get_account($_SESSION['userID'])['rights'] != 'administrator') {
            
            if (
file_exists($xmlinfo)){

                
$rightscheck simplexml_load_file($xmlinfo);

                if (
$rightscheck->postinfo->post->createdby != $_SESSION['userID'])
                    exit(
'error');
            }
        }
        
        
        
        
// Tell post file to include the page pattern.
        
$postcontent =
        
        
'
        if(!file_exists("../../pagep.php"))
            exit("Error loading content. Please come back later.");

        include "../../pagep.php"
        
        '
;
        
        
        
        
        
$title $_POST['title'];
        
$filename str_replace(array('&','/',' ','$','+',',',':',';','=','?','@','<','>','#','%','{','}','|','^','~','[',']','`','\\','\'','"'),'',$_POST['filename']);
        
$description $_POST['metadescription'];
        
$content $_POST['content'];
        
$tags $_POST['tags'];
        
$category $_POST['category'];
        if (
$category == '')
            
$category '-';


        
// Write content in separate .htm file
        
        
$htmname str_replace('nu','',$x);
        
        if (
strlen($content) > ){
            
            
            if (!isset(
$_POST['savebutton']))
                
file_put_contents('autosaves/content/'.$htmname.'.htm',$content);
            else
                
file_put_contents('autosaves/content/nu'.$htmname.'.htm',$content);
            
        }

        if (( isset(
$_POST['savebutton'])) || (($_POST['savebutton'] == '') && ($_POST['postbutton'] == ''))) {
            
            
            
$type 'Draft';
    
        
            if (
is_file($xmlinfo)) {
    
                
                
$getxml simplexml_load_file($xmlinfo);
            
                
$savedtype $getxml->postinfo->post->type;
    
        
                if (
$savedtype == 'Posted')
        
                    
$type 'Posted/Not updated';
        
                else 
                
                
$type $savedtype;
        
            }
            
            
$_SESSION['MON_result'] = '<span class="posted">Saved - '.date("H:i",time()).'</span>';
    

        }


    else {


    
$ptime time();
    
    
$type 'Posted';
        
    
    
$_SESSION['MON_result'] = '<span class="posted">Updated - '.date("H:i",time()).'</span>';
    
    
    }
    
        
// FIRST TIME XML - post or save
    
        
if (!is_file($xmlinfo)) {         
        
        
        
file_put_contents($xmlinfo,'<?xml version="1.0" encoding="UTF-8"?><savedpost><title>Saved Post</title><postinfo></postinfo></savedpost>');
    
        
$sum get_log()['posts'];
        
$sum += 1;

        
update_log('posts',$sum);
                                
        }
            
            
        
        
        
        if (
$filename == ''
        
            
$filename 'post_'.time();
            
            
        
        if (
$filename != false)  { 
                                    
                     
/* ===
                     * We take all xml files, excluding the current one, we get all 
                     * their filenames and check if any of those are the same with the
                     * one we want to use right now.
                        === */ 
                    
    
            
$articles glob('autosaves/*.xml');
                    
            
            
                if (
strpos($xmlinfo,'nu') !== false) {
                    
                    
                    
$cur array_search($xmlinfo,$articles);
                    
                if ( 
$cur !== false)
                    
                    unset(
$articles[$cur]);
                    
                }
                    
                            
                
            
$no_nu str_replace('nu','',$xmlinfo);
                    
            
            
$cur_nu array_search($no_nu,$articles);
            
            
            if (
$cur_nu !== false)
            
                unset(
$articles[$cur_nu]);
                    
            
            
            
            
            foreach (
$articles as $post) {
                    
        
                    
$file simplexml_load_file($post);
                    
            
                    
$fname $file->postinfo->post->filename;
                    
                    
                    if ( 
$fname == $filename )
                    
                        
$filename '_'.$filename;
                    
                            
                    }
                        
        }
    

        
// NEW SIMPLEXML ELEMENT

        
$saved = new SimpleXMLElement($xmlinfo,null,true);
    
        
        
// POST
        
        
if (isset($ptime)) {     
        
        
// FILENAME CHECK  - every time we post
        
            
if (strpos($xmlinfo,'nu') !== false) { 
    
            
                
$ppost str_replace('nu','',$xmlinfo); 
            
                
$posted_file simplexml_load_file($ppost);
            
            
            
                
$oldpath $posted_file->postinfo->post->path;
                
$oldname_posted $posted_file->postinfo->post->filename;
            

                if ((
$oldname_posted != '') && ($oldname_posted != $filename)) {
        
                    
unlink('../'.$oldpath.$oldname_posted.'.php');
                    
                    
file_put_contents('../'.$oldpath.$filename.'.php','<?php $fn ="'.$ppost.'";'.$postcontent.' ?>');
    
                }
            
            }
    
        }
    

        
$excerpt_stop strpos($content,'<hr>');
        
        
$excerpt = ($excerpt_stop !== false) ? $excerpt_stop 'none';
        
        
        include 
'en_code.php';
        
        
$saved->postinfo->post->filename $filename;
        
$saved->postinfo->post->title =  remove_tags($title);
        
$saved->postinfo->post->excerpt $excerpt;
        
$saved->postinfo->post->description remove_tags($description);
        
$saved->postinfo->post->type $type;
        
$saved->postinfo->post->modified time();
        
$saved->postinfo->post->tags $tags;
        
$sep array_values(preg_split('/[,]/',$tags,null,PREG_SPLIT_NO_EMPTY));
                            
        
//$sep = array_flip($sep);
        //ksort($sep);
        
$root '../tags/';
        foreach(
$sep as $k=>$val){
                
                
$low mb_strtolower($val,'UTF-8');
                
//also replace spaces with '-'
                
$low str_replace(' ','-',$low);
                if(!
is_dir($root.$low)){

mkdir($root.$low,0777,true);
$tagscontent =
'
if(!file_exists("../../pagep.php"))
    exit("Error loading content. Please come back later.");

include "../../pagep.php"'
;
    
                    
file_put_contents($root.$low.'/index.php','<?php $tagg="'.$val.'";'.$tagscontent.' ?>');
                }
        }

        
$saved->postinfo->post->category $category;
        
        
        if (isset(
$ppost))
            
$saved->asXML($ppost);
        
    
        
// > FIRST POST
        
        
if ((!strpos($xmlinfo,'nu')) && (isset($ptime))) { 
                
        
            
$dir date('Y',time()).'/'.date('m',time());
                        
            
            
            if(!
is_dir('../'.$dir)) {
        
                
mkdir('../'.$dir,0777,true);
            }
        
        
        
$path $dir.'/';

        
$saved->postinfo->post->path $path;        
        
$saved->postinfo->post->ptime $ptime;
        
$saved->postinfo->post->createdby $_SESSION['userID'];

        
file_put_contents('../'.$path.$filename.'.php','<?php $fn = "'.$xmlinfo.'"; '.$postcontent.' ?>');


        
// SAVE XML FILE
        
$saved->asXML('autosaves/nu'.$x.'.xml');
        
        }
        
        
$saved->postinfo->post->createdby $_SESSION['userID'];
        
$saved->asXML('autosaves/'.$x.'.xml');
        
$sf simplexml_load_file($xmlinfo);
        
$pth $sf->postinfo->post->path;
            
        if (isset(
$dir)) {
            print 
'<script type="text/javascript">top.window.location = "opensaved.php";</script>';
            
//plugin support
            
insert('rssburn');
            
$_SESSION['newpost'] = 'posted';
            unset (
$_SESSION['MON_result']);
            exit();
        }
        
        
        else
        
        if (
$_POST['postbutton'] != ''){
            
            
$_SESSION['MON_post_updated'] = '<a href="../'.$pth.$filename.'.php" id="iframelink" target="_blank" class="posted">, Visit page <img src="images/open.png">
            </a>'
;        
            
//plugin support
            
insert('rssburn');
            if (
is_file('autosaves/content/nu'.$htmname.'.htm'))
                
unlink('autosaves/content/nu'.$htmname.'.htm');
        }

        
header('Location:post.php');
        exit();
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Post write</title>
<?php include 'csstheme.php' ?>
<style>
@charset "utf-8";
html,body{margin:0;font-family:Arial;text-align:center}
.posted{font-size:12px;text-align:center}
.float{float:left}
</style>
</head>
<body oncontextmenu="return false;">
<?php

    
if (isset($_SESSION['MON_result'])) {
        
        echo 
$_SESSION['MON_result'];
        unset (
$_SESSION['MON_result']);
    }

    if (isset(
$_SESSION['MON_post_updated'])) {
        
        echo 
$_SESSION['MON_post_updated'];
        unset(
$_SESSION['MON_post_updated']);
    }
?>
</body>
</html>