Project

General

Profile

1 1158 Luisehahne
<?php
2 1258 Luisehahne
/*
3 1239 Luisehahne
*
4 1258 Luisehahne
*                       About WebsiteBaker
5 1239 Luisehahne
*
6
* Website Baker is a PHP-based Content Management System (CMS)
7
* designed with one goal in mind: to enable its users to produce websites
8
* with ease.
9
*
10 1258 Luisehahne
*                       LICENSE INFORMATION
11 1239 Luisehahne
*
12
* WebsiteBaker is free software; you can redistribute it and/or
13
* modify it under the terms of the GNU General Public License
14
* as published by the Free Software Foundation; either version 2
15
* of the License, or (at your option) any later version.
16
*
17
* WebsiteBaker is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20
* See the GNU General Public License for more details.
21
*
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
*
26
*                   WebsiteBaker Extra Information
27
*
28
*
29 1258 Luisehahne
*/
30 1239 Luisehahne
/**
31
 *
32 1258 Luisehahne
 * @category        modules
33
 * @package         news
34 1268 Luisehahne
 * @author          WebsiteBaker Project
35 1258 Luisehahne
 * @copyright       2004-2009, Ryan Djurovich
36
 * @copyright       2009-2010, Website Baker Org. e.V.
37
 * @link			http://www.websitebaker2.org/
38
 * @license         http://www.gnu.org/licenses/gpl.html
39
 * @platform        WebsiteBaker 2.8.x
40
 * @requirements    PHP 4.3.4 and higher
41 1268 Luisehahne
 * @version         $Id$
42
 * @filesource		$HeadURL$
43 1258 Luisehahne
 * @lastmodified    $Date$
44
 *
45 1239 Luisehahne
 */
46 1158 Luisehahne
47
if(defined('WB_URL')) {
48
49
    function create_new_post($filename, $filetime=NULL, $content )
50
    {
51
    global $page_id, $section_id, $post_id;
52
	// The depth of the page directory in the directory hierarchy
53
	// '/pages' is at depth 1
54
	$pages_dir_depth = count(explode('/',PAGES_DIRECTORY))-1;
55
	// Work-out how many ../'s we need to get to the index page
56
	$index_location = '../';
57
	for($i = 0; $i < $pages_dir_depth; $i++)
58
    {
59
		$index_location .= '../';
60
	}
61
62
	// Write to the filename
63
	$content .='
64
define("POST_SECTION", $section_id);
65
define("POST_ID", $post_id);
66
require("'.$index_location.'config.php");
67
require(WB_PATH."/index.php");
68
?>';
69 1258 Luisehahne
    	if($handle = fopen($filename, 'w+'))
70 1158 Luisehahne
        {
71 1258 Luisehahne
        	fwrite($handle, $content);
72
        	fclose($handle);
73
            if($filetime)
74
            {
75
                touch($filename, $filetime);
76
            }
77
        	change_mode($filename);
78 1158 Luisehahne
        }
79
    }
80
81
    // read files from /pages/posts/
82 1258 Luisehahne
    if( !function_exists('scandir') )
83
    {
84
        function scandir($directory, $sorting_order = 0)
85
        {
86 1158 Luisehahne
            $dh  = opendir($directory);
87 1258 Luisehahne
            while( false !== ($filename = readdir($dh)) )
88
            {
89 1158 Luisehahne
                $files[] = $filename;
90
            }
91 1258 Luisehahne
            if( $sorting_order == 0 )
92
            {
93 1158 Luisehahne
                sort($files);
94 1258 Luisehahne
            } else
95
            {
96 1158 Luisehahne
                rsort($files);
97
            }
98
            return($files);
99
        }
100
    }
101
102
    $target_dir = WB_PATH . PAGES_DIRECTORY.'/posts/';
103
	$files = scandir($target_dir);
104
	natcasesort($files);
105
106
		// All files in /pages/posts/
107
		foreach( $files as $file )
108
        {
109 1258 Luisehahne
            if( file_exists($target_dir.$file)
110
                AND ($file != '.')
111
                    AND ($file != '..')
112
                        AND ($file != 'index.php') )
113 1158 Luisehahne
            {
114
                clearstatcache();
115 1258 Luisehahne
                $timestamp = filemtime ( $target_dir.$file );
116 1158 Luisehahne
                $lines = file($target_dir.$file);
117
                $content = '';
118
                // read lines until first define
119
                foreach ($lines as $line_num => $line) {
120
                    if(strstr($line,'define'))
121
                    {
122
                      break;
123
                    }
124
                    $content .= $line;
125
                }
126
127
                create_new_post($target_dir.$file, $timestamp, $content);
128
            }
129
130
        }
131
// Print admin footer
132
$admin->print_footer();
133
}
134
?>