Project

General

Profile

1
<?php
2
/*
3
*
4
*                       About WebsiteBaker
5
*
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
*                       LICENSE INFORMATION
11
*
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
*/
30
/**
31
 *
32
 * @category        modules
33
 * @package         news
34
 * @author          Ryan Djurovich
35
 * @copyright       2004-2009, Ryan Djurovich
36
 * @copyright       2009-2010, Website Baker Org. e.V.
37
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/save_post.php $
38
 * @author          Ryan Djurovich
39
 * @copyright       2004-2009, Ryan Djurovich
40
 *
41
 * @author          WebsiteBaker Project
42
 * @link			http://www.websitebaker2.org/
43
 * @copyright       2009-2010, Website Baker Org. e.V.
44
 * @link			http://start.websitebaker2.org/impressum-datenschutz.php
45
 * @license         http://www.gnu.org/licenses/gpl.html
46
 * @version         $Id: save_post.php 1258 2010-01-21 02:26:08Z Luisehahne $
47
 * @platform        WebsiteBaker 2.8.x
48
 * @requirements    PHP 4.3.4 and higher
49
 * @lastmodified    $Date: 2010-01-21 03:26:08 +0100 (Thu, 21 Jan 2010) $
50
 *
51
 */
52

    
53
require('../../config.php');
54

    
55
require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
56

    
57
// Get id
58
if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id']))
59
{
60
	header("Location: ".ADMIN_URL."/pages/index.php");
61
	exit( 0 );
62
}
63
else
64
{
65
	$id = $_POST['post_id'];
66
	$post_id = $id;
67
}
68

    
69
function create_file($filename, $filetime=NULL )
70
{
71
global $page_id, $section_id, $post_id;
72

    
73
	// We need to create a new file
74
	// First, delete old file if it exists
75
	if(file_exists(WB_PATH.PAGES_DIRECTORY.$filename.PAGE_EXTENSION))
76
    {
77
        $filetime = isset($filetime) ? $filetime :  filemtime($filename);
78
		unlink(WB_PATH.PAGES_DIRECTORY.$filename.PAGE_EXTENSION);
79
	}
80
    else {
81
        $filetime = isset($filetime) ? $filetime : time();
82
    }
83
	// The depth of the page directory in the directory hierarchy
84
	// '/pages' is at depth 1
85
	$pages_dir_depth = count(explode('/',PAGES_DIRECTORY))-1;
86
	// Work-out how many ../'s we need to get to the index page
87
	$index_location = '../';
88
	for($i = 0; $i < $pages_dir_depth; $i++)
89
    {
90
		$index_location .= '../';
91
	}
92

    
93
	// Write to the filename
94
	$content = ''.
95
'<?php
96
$page_id = '.$page_id.';
97
$section_id = '.$section_id.';
98
$post_id = '.$post_id.';
99
define("POST_SECTION", $section_id);
100
define("POST_ID", $post_id);
101
require("'.$index_location.'config.php");
102
require(WB_PATH."/index.php");
103
?>';
104
	if($handle = fopen($filename, 'w+'))
105
    {
106
    	fwrite($handle, $content);
107
    	fclose($handle);
108
        if($filetime)
109
        {
110
        touch($filename, $filetime);
111
        }
112
    	change_mode($filename);
113
    }
114

    
115
}
116

    
117
// Include WB admin wrapper script
118
$update_when_modified = true; // Tells script to update when this page was last updated
119
require(WB_PATH.'/modules/admin.php');
120

    
121
// Validate all fields
122
if($admin->get_post('title') == '' AND $admin->get_post('url') == '')
123
{
124
	$admin->print_error($MESSAGE['GENERIC']['FILL_IN_ALL'], WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.'&section_id='.$section_id.'&post_id='.$id);
125
}
126
else
127
{
128
	$title = $admin->get_post_escaped('title');
129
	$short = $admin->get_post_escaped('short');
130
	$long = $admin->get_post_escaped('long');
131
	$commenting = $admin->get_post_escaped('commenting');
132
	$active = $admin->get_post_escaped('active');
133
	$old_link = $admin->get_post_escaped('link');
134
	$group_id = $admin->get_post_escaped('group');
135
}
136

    
137
// Get page link URL
138
$query_page = $database->query("SELECT level,link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
139
$page = $query_page->fetchRow();
140
$page_level = $page['level'];
141
$page_link = $page['link'];
142

    
143
// Include WB functions file
144
require(WB_PATH.'/framework/functions.php');
145

    
146
// Work-out what the link should be
147
$post_link = '/posts/'.page_filename($title).PAGE_SPACER.$post_id;
148

    
149
// Make sure the post link is set and exists
150
// Make news post access files dir
151
make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/');
152
$file_create_time = '';
153
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/posts/'))
154
{
155
	$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
156
}
157
elseif(($old_link != $post_link) OR !file_exists(WB_PATH.PAGES_DIRECTORY.$post_link.PAGE_EXTENSION))
158
{
159
	// We need to create a new file
160
	// First, delete old file if it exists
161
	if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION))
162
    {
163
        $file_create_time = filemtime($old_link.PAGE_EXTENSION);
164
		unlink(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION);
165
	}
166

    
167
    // Specify the filename
168
    $filename = WB_PATH.PAGES_DIRECTORY.'/'.$post_link.PAGE_EXTENSION;
169
    create_file($filename, $file_create_time);
170
}
171

    
172

    
173
// get publisedwhen and publisheduntil
174
$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
175
if($publishedwhen == '' || $publishedwhen < 1)
176
	$publishedwhen=0;
177
$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
178
if($publisheduntil == '' || $publisheduntil < 1)
179
	$publisheduntil=0;
180

    
181
// Update row
182
$database->query("UPDATE ".TABLE_PREFIX."mod_news_posts SET group_id = '$group_id', title = '$title', link = '$post_link', content_short = '$short', content_long = '$long', commenting = '$commenting', active = '$active', published_when = '$publishedwhen', published_until = '$publisheduntil', posted_when = '".time()."', posted_by = '".$admin->get_user_id()."' WHERE post_id = '$post_id'");
183

    
184
// Check if there is a db error, otherwise say successful
185
if($database->is_error())
186
{
187
	$admin->print_error($database->get_error(), WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.'&section_id='.$section_id.'&post_id='.$id);
188
}
189
else
190
{
191
	$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
192
}
193

    
194
// Print admin footer
195
$admin->print_footer();
196

    
197
?>
(25-25/31)