set-posts.php

File Type: php File Location: monofiles/ File name: set-posts.php
<?php
    
    
//The file set-posts.php must be included in index.php. Note: $catg & $tagg are set in ..path/index.php
    
    
if (strpos('set-posts',basename(get_included_files()[0],'.php')) !== false
        exit;
    
    
    
    
// Date. min,h,m,d etc
    
include $rot.'monofiles/dateform.php';
    
    
    
    
// Results per page
    
$files_to_load $stgs['results-per-page'];
    
    
    
// Find all posts xml files
    
$xmlfiles glob($rot.'monofiles/autosaves/*.xml');

    if (
count($xmlfiles) != 0) {
    
        
        
        
$array_xml = array();
        
$array_ptime = array();
        
        
        
        
// Load posts category or tags info
        
foreach ($xmlfiles as $file) {
        
            
$xmlElement simplexml_load_file($file);
                
                
                
            
// Home page, Category or Tag posts
            
            
if ($xmlElement->postinfo->post->tags !== false)
                
$alltags array_values(preg_split('/[,]/',$xmlElement->postinfo->post->tags,null,PREG_SPLIT_NO_EMPTY));
                

                
            if ( 
$xmlElement->postinfo->post->type != 'Draft' && strpos($file,'nu') === false ) {
                
                
                if (
                
                (isset(
$catg) && $xmlElement->postinfo->post->category !== false && $catg == $xmlElement->postinfo->post->category
                    
                or 
                
                (isset(
$tagg) && $xmlElement->postinfo->post->tags !== false && array_search($tagg,$alltags,true) !== false
                
                or
                 
                (!isset(
$catg) && !isset($tagg))
                
                )
                
                    {

                    
$array_xml[] = $file;
                    
$array_ptime[] = (int)$xmlElement->postinfo->post->ptime;
                
                }
                
                
            }
            
            
// END 
            
            

        
}
        
        
        
        if (isset(
$catg))
            echo 
'<h2>'.$catg.'</h2>';
        
        if (isset(
$tagg))
            echo 
'<h2>'.$tagg.'</h2>';
        
        
        
        
$index_posts array_combine($array_ptime,$array_xml);
        
krsort($index_posts);
        
        
        include 
$rot.'monofiles/navinfo.php';
        
        
        
$c=0;
        
$r=0;
            
        foreach(
$index_posts as $file) {

            
            if ((
$c >= $first) && ($c $last)) {
            
                
$r++;
                
                
                
// Load info : title, path etc
                
$xmlpost simplexml_load_file($file);

                
$title load_xml($xmlpost->postinfo->post->title);
                
$path $xmlpost->postinfo->post->path;
                
$link $xmlpost->postinfo->post->filename;
                
$htm_file $rot.'monofiles/autosaves/content/'.basename($file,'.xml').'.htm';
                
                
                
                if (
file_exists($htm_file))
                    
$content file_get_contents($htm_file);
                
                
                
                
$excerpt $xmlpost->postinfo->post->excerpt;
                
$excerpt = ($excerpt == 'none') ? $content substr($content,0,(int)$excerpt).'&#8230;';

                
                
                unset(
$content);

                
                
                
                
// Load tags
                
$taglab '';
                
                if (
$stgs['tags'] != 'off') {
                    
$taglab 'Tags: ';
                    
                    if (
$xmlpost->postinfo->post->tags !== false) {
                        
$alltags array_values(preg_split('/[,]/',$xmlpost->postinfo->post->tags,null,PREG_SPLIT_NO_EMPTY));
                        
                        foreach(
$alltags as $val) {
                        
                            
//change from tagname to root
                            
$tagrot 'tags/'.str_replace(' ','-',mb_strtolower($val));
                            
                            
                            
$tgs .= '<a href="'.$tagrot.'" class="tagword">'.$val.'</a>'.PHP_EOL;
                        
                        }
                    }
                
                }
                
                
                else 
$tgs '';
            
            
            
            

                
// The author
                
$created $xmlpost->postinfo->post->createdby;
                
$logfile simplexml_load_file($rot.'monofiles/filesinfo/log.xml');
                
                foreach (
$logfile->user as $userinfo) {
                    
                    if ((string)
$userinfo->userID == $created) {
                        
                        
$the_author $userinfo->name;
                        break;
                        
                    }
                    
                    else
                        
$the_author '';
                }


                
                
                
                
// The post category
                
if (isset($catg)) 
                    
$category '';
                
                else {
                    
                    
$catinfo load_xml($xmlpost->postinfo->post->category);
                    
$folders glob($rot.'category/*',GLOB_ONLYDIR);
                    
                    foreach (
$folders as $catf) {
                        
                        if (
file_get_contents($catf.'/name.txt') == $catinfo) {
                            
                            
$category $catinfo;
                            
$cat_folder $catf;
                            break;
                        
                        }
                        
                        else
                            
$category '';
                    }
                }
                
                
                
                
// The date
                
$post_date date_form($xmlpost->postinfo->post->ptime);
                
                
                
                
                
// Print guide
                
$pcat = ($category != '') ? '<a class="ch-tag" href="'.$rot.$cat_folder.'/">'.$category.'</a>' '';

                
                
                
// The post
                
echo '<div class="post"><span class="mon-user">'.$the_author.'</span> '.$pcat.'<span class="post-date">'.$post_date.'</span><h2><a href="'.$rot.$path.$link.'">'.$title.'</a></h2>'.PHP_EOL.' <div class="content-text">'.$excerpt.'</div>'.$exp.'</div>';

                
                
// Unset tags when inside a loop
                
unset($tgs);
                
                
            }
            
            
$c++;
            
        }
        
        
    }
    
?>