opensaved.php

File Type: php File Location: monofiles/ File name: opensaved.php
<?php

    
include_once 'data_connect.php';
    include 
'log.php';
    
    
$settingsXML simplexml_load_file('filesinfo/settings.xml');
    
    if (isset(
$_GET['max'])){
        
        
$lastmod $settingsXML->general->savedposts->lastmod;
        
        if ((isset(
$_GET['at'])) && ($_GET['at'] < $lastmod))
        
            
header('Location:opensaved.php');
    }
    

    if (isset(
$_GET['file']))
        include 
'delete_post.php';
    
    if (isset(
$_GET['editfile'])) 
        include 
'draft_post.php';
        
    if (isset(
$_SESSION['newpost'])){
        
$message '<div id="action-confirm"><span>Posted</span></div>';
        unset (
$_SESSION['newpost']);
    }
    
    
    
// Current user info
    
$accinfo get_account($_SESSION['userID']);
    
    
    
//Posts directory
    
$directory = new DirectoryIterator('autosaves/');
    

?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Posts</title>
<link rel="stylesheet" type="text/css" href="cmstyle.css">
<?php include 'csstheme.php' ?>
<script type="text/javascript">function conf(form){return confirm('Delete post?');}</script>
<script type="text/javascript">function draft(form){return confirm('Change to Draft?');}</script>
</head>
<body>
    <?php
        
        
include 'mypanel.php';
        
        if (isset(
$message))
            echo 
$message
    
    ?>
    <div class="main">
    <h1>Posts</h1>
    <div class="headpages">
        <a href="newpage.php" class="addnew" title="Write Post">+</a>
    </div>
        <div id="main-container">
            <div class="results-set">
                <div class="normal-res">
                    <span style="font-size:12px">results &nbsp; &nbsp; </span>
                        <?php 
                        
                            
//Sort results
                            //GET parameter for res-set.php
                            
$gt = array('category'=>'sortbycat','status'=>'sortbystat','author'=>'sortbyauth');
                            
                            foreach(
$gt as $fil=>$set) {
                            
                                if (isset(
$_GET[$set])) {
                                    
                                    
$snes '&amp;sort='.$set.'&amp;sortval='.$_GET[$set];
                                    
$filter '<span class="filres">Reset filter <a href="opensaved.php">'.$fil.' X</a></span>';
                                    
                                    
// We use this to set the right sorting parameter in 'delete' and 'change to draft' buttons
                                    
$nes '&amp;'.$set.'='.$_GET[$set];
                                    
                                    break;
                                }
                                
                                else {
                                    
                                    
$snes '';
                                    
$filter '';
                                    
$nes '';

                                }
                            }
                            
                        
                            
// Results per page
                            
$ra = array(5,10,20,50,100,200);
                            
$x $accinfo['results_posts'];
                            
                            
$c=1;
                            foreach(
$ra as $res) {
                                
                                
$d $c ' &nbsp;|&nbsp; ' '';
                                echo (
$x != $res) ? '<a href="res-set.php?postsperpage='.$res.$snes.'">'.$res.'</a>'.$d $res.$d;
                                
$c++;
                            }
                        
?>
                </div>    
            </div>
            <div class="results">
                <div class="pbar">
                    
                    <span style="padding-left:5px;text-align:left;float:left">
                    
                    
                    <a href="sort-set.php<?php
                    
                    
if ($_SESSION['MONSORT'] == 'sortbytitle')
                        print 
'?sortbyalpha=1'.$snes.'&amp;ref=opensaved.php" title="Reverse alphabetical order (z-a)" class="sort1';
                    
                    elseif (
$_SESSION['MONSORT'] == 'sortbyalpha')
                        print 
'?sortbytitle=1'.$snes.'&amp;ref=opensaved.php" title="Alphabetical order (a-z)" class="sort2';
                        
                    else print 
'?sortbytitle=1'.$snes.'&amp;ref=opensaved.php" title="Alphabetical order (a-z)'
                    
                    
                    
?>">Title</a>
                    
                    </span>
                    <span class="lastmodbar">
                    <a href="sort-set.php<?php 
                    
                    
if ($_SESSION['MONSORT'] == 'sortbyrev'
                        print 
'?sortbytime=1'.$snes.'&amp;ref=opensaved.php" title="Chronological order" class="sort2';
                    
                    elseif  (
$_SESSION['MONSORT'] == 'sortbytime')
                        print 
'?sortbyrev=1'.$snes.'&amp;ref=opensaved.php" title="Reverse chronological order" class="sort1';
                        
                    else print 
'?sortbytime=1'.$snes.'&amp;ref=opensaved.php" title="Chronological order '
                    
                    
?>">Last modified</a>
                    
                    
                    </span>
                    <?php 
                            
                            
//find info about filters
                            
                            
                            
$ar_stat = [];
                            
$ar_cat = [];
                            
$ar_auth = [];
                            
                            
                            foreach (
$directory as $fileinfo) {
                                
                                
                                if (
$fileinfo->isFile()) {
                                    
                                    
                                    
$name $fileinfo->getFilename();
                                        
                                    if (
is_file('nu'.$name))
                                        
$name 'nu'.$name;
                                    
                                    
                                    
$s simplexml_load_file('autosaves/'.$name);
                                    
                                    
                                    
                                    
$type = (string)$s->postinfo->post->type;
                                    
                                    if (
array_search($type,$ar_stat) === false)
                                        
$ar_stat[] = $type;
                                    
                                    
                                    
                                    
$catgr = (string)$s->postinfo->post->category;
                                    
                                    if (
array_search($catgr,$ar_cat) === false)
                                        
$ar_cat[] = $catgr;
                                    
                                    
                                    
                                    
$auth = (string)$s->postinfo->post->createdby;
                                    
                                    if (
array_search($auth,$ar_auth) === false){
                                            
                                        
$ar_auth[] = $auth;
                                        
                                        
$author_account get_account($auth);
                                        
$ar_authname[] = $author_account['name'];
                                        
$ar_authicon[] = $author_account['icon'];
                                    }
                                }
                                
                            }
                            
?>
                    
                    <!-- Status -->
                    <span style="width:81px">Status 
                        <span class="filter<?php if (isset($_GET['sortbystat'])) print ' arrsel' ?>">&#9660;
                            <span class="sortfil">
                                <a <?php print (!isset($_GET['sortbystat'])) ? 'class="stsel"' 'href="opensaved.php"' ?>>All</a>
                                <?php
                                    
                                    
foreach($ar_stat as $ts)
                                        print (isset(
$_GET['sortbystat']) && $_GET['sortbystat'] == $ts) ? '<a class="stsel">'.$ts.'</a>' '<a href="opensaved.php?sortbystat='.$ts.'">'.$ts.'</a>'
                                    
                                
?>
                                
                                
                            </span>
                        </span>
                    </span>
                    
                    
                    <!-- Author -->
                    <span style="width:40px">Author 
                    
                        <span class="filter<?php if (isset($_GET['sortbyauth'])) print ' arrsel' ?>">&#9660;
                            <span class="sortfil">
                                <a <?php print (!isset($_GET['sortbyauth'])) ? 'class="stsel"' 'href="opensaved.php"' ?>>All</a>

                                <?php
                                    
                                    
if (!empty($ar_authname)) {
                                        
                                        
$real_authors array_combine($ar_auth,$ar_authname);
                                            
                                            
                                        foreach(
$real_authors as $id=>$name)
                                            
                                            print (isset(
$_GET['sortbyauth']) && $_GET['sortbyauth'] == $id) ? '<a class="stsel">'.$name.'</a>' '<a href="opensaved.php?sortbyauth='.$id.'">'.$name.'</a>';
                                    }
                                
?>
                                
                            </span>
                        </span>
                    </span>
                    
                    
                    <!-- Category -->
                    <span class="catbar">Category 
                    
                    <span class="filter<?php if (isset($_GET['sortbycat'])) print ' arrsel' ?>">&#9660;
                        <span class="sortfil">
                                <a <?php print (!isset($_GET['sortbycat'])) ? 'class="stsel"' 'href="opensaved.php"' ?>>All</a>
                                <?php
                                    
                                    
foreach($ar_cat as $ts)
                                        print (isset(
$_GET['sortbycat']) && $_GET['sortbycat'] == $ts) ? '<a class="stsel">'.$ts.'</a>' '<a href="opensaved.php?sortbycat='.$ts.'">'.$ts.'</a>'
                                
                                
?>
                                
                                
                            </span>
                        </span>
                    </span>
                
                </div>
                <?php    
                $array_xml 
= array();
                
$array_param = array();

                
$catnum=0;

                foreach (
$directory as $fileinfo) {

                    if (
$fileinfo->isFile()) {
                    
                        
$name $fileinfo->getFilename();
                        
                        
$s simplexml_load_file('autosaves/'.$name);
                            
                        
$mtime $s->postinfo->post->modified;
                        
$creator $s->postinfo->post->createdby;
                    
                        if (!
is_file('autosaves/nu'.$name)) {

                            if ( (
$accinfo['rights'] == 'administrator') || ($creator == $_SESSION['userID']) ) {
                                
                                if ( (isset(
$_GET['sortbycat']) && $s->postinfo->post->category == $_GET['sortbycat']) 
                                    
                                || 
                                
                                (isset(
$_GET['sortbystat']) && $s->postinfo->post->type == $_GET['sortbystat']) 
                                
                                || 
                                
                                (isset(
$_GET['sortbyauth']) && $s->postinfo->post->createdby == $_GET['sortbyauth']) 
                                
                                ||
                                
                                (!isset(
$_GET['sortbycat']) && !isset($_GET['sortbystat'])) && !isset($_GET['sortbyauth']) )
                                
                                {
                                
                                
$array_xml[] = 'autosaves/'.$name;
                                
$array_param[] = ($_SESSION['MONSORT'] == 'sortbytitle' || $_SESSION['MONSORT'] == 'sortbyalpha') ? strtolower($s->postinfo->post->title).($catnum+1) : $mtime;
                                
$catnum++;
                                
                                }
                            }
                        }
                    }

                    unset(
$creator);
                }
                
                
                
$array_res array_combine($array_param,$array_xml);
                
            
                
// Note: to Show results from a to z (alphabetically) we need normal order and to show results from new to old(chronologically), we need reverse order.
                
if ($_SESSION['MONSORT'] == 'sortbyrev' || $_SESSION['MONSORT'] == 'sortbytitle')
                    
                    
// normal order
                    
ksort($array_res);
            
            
                else
                    
                    
// reverse order
                    
krsort($array_res);
                
                
                    
                include 
'navinfo.php';

                
$c=0;
                
$r=0;

                include 
'en_code.php';
                include 
'dateform.php';
                    
                foreach(
$array_res as $file) {

                    if ((
$c >= $first) && ($c $last)) {
                            

                        
$r++;
                        
                        
$fxml simplexml_load_file($file);

                        
$title load_xml($fxml->postinfo->post->title);
                        
$type $fxml->postinfo->post->type;
                        
$filename $fxml->postinfo->post->filename;
                        
$path $fxml->postinfo->post->path;
                        
$utime = (int)$fxml->postinfo->post->modified;

                        if (
$fxml->postinfo->post->category !== false) {
                            
                            
$category $fxml->postinfo->post->category;
                            
                            
                            if ((
$category != '') && ($category != '-'))
                                
                                
$category '<div class="category" title="View this category"><b>'.$category.'</b> </div>';
                            
                            else
                            
                                
$category '<div class="category" title="View this category"><b>&nbsp; - &nbsp;</b> </div>';
                        }
                            
                        
// authors name
                        
$author $real_authors[(string)$fxml->postinfo->post->createdby];                        
                        
                        
// authors icon
                        
$icon_authors array_combine($ar_auth,$ar_authicon);
                        
$authoricon $icon_authors[(string)$fxml->postinfo->post->createdby];


                        if (
$type != 'Draft')    {
                            
                            
$postedit '<a href="javascript:" onclick="if (draft(this)) window.location.href=\'?editfile='.$file.'&amp;link='.$path.$filename.$nes.'&amp;max='.$ofp.'\'; " class="options-button not" title="Change to Draft">Change to draft</a>';
                            
                            
$visitpage '<a href="../'.$path.$filename.'.php" target="_blank" class="options-button">Visit</a>';

                            
$fptotime 'posted on '.date('M d, Y',(int)$fxml->postinfo->post->ptime);
                            
                        }

                        else {

                        
$postedit '';
                        
$visitpage '';
                        
$fptotime 'Draft';

                        }




                        if (
$title == ''

                        
$title '(no title)';

                        
$ftime date_form($utime);
                        
$cssbg = (($r 2) == 1) ? ' -bg' '';


                        print 
'<div class="savedfile'.$cssbg.'">
                        <span class="post-title">'
.$title.'</span>
                        <div class="post-options"><a href="newpage.php?savedname='
.$file.'" title="Edit post" class="options-button">Edit post</a><a href="javascript:" onclick="if (conf(this)) window.location.href=\'?file='.$file.'&amp;link='.$path.$filename.$nes.'&amp;max='.$ofp.'\'" class="options-button not" title="Delete post" onclick="return conf(this)">Delete</a>'.$postedit.$visitpage.'</div>
                        <div class="lastmod" title="'
.date("m/d/Y , H:i",$utime).'">'.$ftime.'</div>
                        <div class="type">
                        <span title="'
.$fptotime.'">'.$type.'</span>
                        </div>
                        <div class="author" title="'
.$author.'"><img src="'.$authoricon.'" class="savedfileimg"></div>
                        '
.$category.'
                        </div>'
;                
                                
                    }
                    
                    
$c++;
                        
                }        
                    
            
?>
            </div>
            
            <div id="res-nav">
            <?php 

            
include 'pagenav.php'

            
?>
            </div>
            <div id="cur-res">
            <?php

                $l 
$first $r;

                if (
$accinfo['rights'] == 'administrator') {
                    
                    if ( !isset(
$_GET['sortbycat']) && !isset($_GET['sortbystat']) && !isset($_GET['sortbyauth']) )
                        
$p get_log()['posts'];
                    else 
                    
$p $catnum//could be count();
                
}
                
                
                else
                
$p count($array_res);
                
                echo 
$first.' - '.$l.' of &nbsp;'.$p;

            
?>
            </div>
        </div>
    </div>
</body>
</html>