refresh.php

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


        
//Check number of posts and pages
        //Retrieve accidentally deleted pages from the home dir
        //Update log.xml
        
        
include 'data_connect.php';
        
        
        echo 
'Checking system..';
        
        if (
basename(getcwd()) == 'monofiles') {
            
            
            
// open log.xml
            
$logxml = new simpleXMLElement('filesinfo/log.xml',null,true);
            
            
            
// pages
            
$pages scandir('savedpages');
            
            
            
$pgsum=0;
            
$pgr=0;
    
            echo 
'.';
            foreach(
$pages as $page) {
                
                if (
is_file('savedpages/'.$page)) {
                    
                    
                    
$filename basename($page);
                    if (
strpos($filename,'.xml') === 10) {
                        
                        
                        
$xmlname substr($page,0,9);
                        if (
is_numeric($xmlname)) {

                            
                            
$pgsum++;
                            
$xmlfile simpleXML_load_file('savedpages/'.$page);
                            
                            if (!
is_file('../'.$xmlfile->pageinfo->page->filename.'.php')) {
                                
                                
                                
file_put_contents('../'.(string)$xmlfile->pageinfo->page->filename.'.php','<?php 
                            $pn = '
.$xmlname.'; if(!file_exists("pagep.php")) exit("Error loading content. Please come back later."); include "pagep.php"    ?>');
                                
$pgr++;


                            }
                            
                        }
                    }
                }
            }
            
            
$logxml->info->pages $pgsum;
            echo 
'.';
        
            
// posts 
            
$posts scandir('autosaves');


            
$psum 0;

            foreach (
$posts as $post) {
                
                if (
is_file('autosaves/'.$post)) {
                    
                    
                    
$filename basename($post);
                    
                    
                    if (
strpos($filename,'.xml') === 10) {
                        
                        
                        
$xmlname substr($post,0,9);
                            
                        if (
is_numeric($xmlname)) 
                            
$psum++;
                        
                    }
                
                }
            }
            
            
$logxml->info->posts $psum;
            echo 
'.';
        }
    
    
    
    else
        exit(
'Error: This file should be saved inside the monofiles folder.');


    
    
$logxml->info->modified time();
    
$logxml->asXML('filesinfo/log.xml');

    
    

    echo 
'<p>System check completed</p><br>
            <p>
                <ul>
                    <li>Total number of posts: '
.$psum.'</li>
                    <li>Total number of pages: '
.$pgsum.'</li>
                    <li>Pages retrieved: '
.$pgr.'</li>
                </ul>
            </p>'
        
?>