Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         news
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 4.3.4 and higher
13
 * @version         $Id: upgrade.php 1289 2010-02-10 15:13:21Z kweitzel $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/trunk/wb/modules/news/upgrade.php $
15
 * @lastmodified    $Date: 2010-02-10 16:13:21 +0100 (Wed, 10 Feb 2010) $
16
 *
17
 */
18

    
19
if(defined('WB_URL')) {
20

    
21
    function create_new_post($filename, $filetime=NULL, $content )
22
    {
23
    global $page_id, $section_id, $post_id;
24
	// The depth of the page directory in the directory hierarchy
25
	// '/pages' is at depth 1
26
	$pages_dir_depth = count(explode('/',PAGES_DIRECTORY))-1;
27
	// Work-out how many ../'s we need to get to the index page
28
	$index_location = '../';
29
	for($i = 0; $i < $pages_dir_depth; $i++)
30
    {
31
		$index_location .= '../';
32
	}
33

    
34
	// Write to the filename
35
	$content .='
36
define("POST_SECTION", $section_id);
37
define("POST_ID", $post_id);
38
require("'.$index_location.'config.php");
39
require(WB_PATH."/index.php");
40
?>';
41
    	if($handle = fopen($filename, 'w+'))
42
        {
43
        	fwrite($handle, $content);
44
        	fclose($handle);
45
            if($filetime)
46
            {
47
                touch($filename, $filetime);
48
            }
49
        	change_mode($filename);
50
        }
51
    }
52

    
53
    // read files from /pages/posts/
54
    if( !function_exists('scandir') )
55
    {
56
        function scandir($directory, $sorting_order = 0)
57
        {
58
            $dh  = opendir($directory);
59
            while( false !== ($filename = readdir($dh)) )
60
            {
61
                $files[] = $filename;
62
            }
63
            if( $sorting_order == 0 )
64
            {
65
                sort($files);
66
            } else
67
            {
68
                rsort($files);
69
            }
70
            return($files);
71
        }
72
    }
73

    
74
    $target_dir = WB_PATH . PAGES_DIRECTORY.'/posts/';
75
	$files = scandir($target_dir);
76
	natcasesort($files);
77

    
78
		// All files in /pages/posts/
79
		foreach( $files as $file )
80
        {
81
            if( file_exists($target_dir.$file)
82
                AND ($file != '.')
83
                    AND ($file != '..')
84
                        AND ($file != 'index.php') )
85
            {
86
                clearstatcache();
87
                $timestamp = filemtime ( $target_dir.$file );
88
                $lines = file($target_dir.$file);
89
                $content = '';
90
                // read lines until first define
91
                foreach ($lines as $line_num => $line) {
92
                    if(strstr($line,'define'))
93
                    {
94
                      break;
95
                    }
96
                    $content .= $line;
97
                }
98

    
99
                create_new_post($target_dir.$file, $timestamp, $content);
100
            }
101

    
102
        }
103
// Print admin footer
104
$admin->print_footer();
105
}
106
?>
(30-30/31)