Project

General

Profile

1
<?php
2
/****************************************************************************
3
* SVN Version information:
4
*
5
* $Id: save_post.php 1239 2010-01-12 01:17:06Z Luisehahne $
6
*
7
*****************************************************************************
8
*                          WebsiteBaker
9
*
10
* WebsiteBaker Project <http://www.websitebaker2.org/>
11
* Copyright (C) 2009, Website Baker Org. e.V.
12
*         http://start.websitebaker2.org/impressum-datenschutz.php
13
* Copyright (C) 2004-2009, Ryan Djurovich
14
*
15
*                        About WebsiteBaker
16
*
17
* Website Baker is a PHP-based Content Management System (CMS)
18
* designed with one goal in mind: to enable its users to produce websites
19
* with ease.
20
*
21
*****************************************************************************
22
*
23
*****************************************************************************
24
*                        LICENSE INFORMATION
25
*
26
* WebsiteBaker is free software; you can redistribute it and/or
27
* modify it under the terms of the GNU General Public License
28
* as published by the Free Software Foundation; either version 2
29
* of the License, or (at your option) any later version.
30
*
31
* WebsiteBaker is distributed in the hope that it will be useful,
32
* but WITHOUT ANY WARRANTY; without even the implied warranty of
33
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
34
* See the GNU General Public License for more details.
35
*
36
* You should have received a copy of the GNU General Public License
37
* along with this program; if not, write to the Free Software
38
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
39
****************************************************************************
40
*
41
*                   WebsiteBaker Extra Information
42
*
43
*
44
*
45
*
46
*****************************************************************************/
47
/**
48
 *
49
 * @category     modules
50
 * @package      news
51
 * @author       Ryan Djurovich
52
 * @copyright    2004-2009, Ryan Djurovich
53
 * @copyright    2009-2010, Website Baker Org. e.V.
54
 * @version      $Id: save_post.php 1239 2010-01-12 01:17:06Z Luisehahne $
55
 * @platform     WebsiteBaker 2.8.x
56
 * @requirements >= PHP 4.3.4
57
 * @license      http://www.gnu.org/licenses/gpl.html
58
 *
59
 */
60
require('../../config.php');
61

    
62
require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
63

    
64
// Get id
65
if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id']))
66
{
67
	header("Location: ".ADMIN_URL."/pages/index.php");
68
	exit( 0 );
69
}
70
else
71
{
72
	$id = $_POST['post_id'];
73
	$post_id = $id;
74
}
75

    
76
function create_file($filename, $filetime=NULL )
77
{
78
global $page_id, $section_id, $post_id;
79

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

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

    
122
}
123

    
124
// Include WB admin wrapper script
125
$update_when_modified = true; // Tells script to update when this page was last updated
126
require(WB_PATH.'/modules/admin.php');
127

    
128
// Validate all fields
129
if($admin->get_post('title') == '' AND $admin->get_post('url') == '')
130
{
131
	$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);
132
}
133
else
134
{
135
	$title = $admin->get_post_escaped('title');
136
	$short = $admin->get_post_escaped('short');
137
	$long = $admin->get_post_escaped('long');
138
	$commenting = $admin->get_post_escaped('commenting');
139
	$active = $admin->get_post_escaped('active');
140
	$old_link = $admin->get_post_escaped('link');
141
	$group_id = $admin->get_post_escaped('group');
142
}
143

    
144
// Get page link URL
145
$query_page = $database->query("SELECT level,link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
146
$page = $query_page->fetchRow();
147
$page_level = $page['level'];
148
$page_link = $page['link'];
149

    
150
// Include WB functions file
151
require(WB_PATH.'/framework/functions.php');
152

    
153
// Work-out what the link should be
154
$post_link = '/posts/'.page_filename($title).PAGE_SPACER.$post_id;
155

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

    
174
    // Specify the filename
175
    $filename = WB_PATH.PAGES_DIRECTORY.'/'.$post_link.PAGE_EXTENSION;
176
    create_file($filename, $file_create_time);
177
}
178

    
179

    
180
// get publisedwhen and publisheduntil
181
$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
182
if($publishedwhen == '' || $publishedwhen < 1)
183
	$publishedwhen=0;
184
$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
185
if($publisheduntil == '' || $publisheduntil < 1)
186
	$publisheduntil=0;
187

    
188
// Update row
189
$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'");
190

    
191
// Check if there is a db error, otherwise say successful
192
if($database->is_error())
193
{
194
	$admin->print_error($database->get_error(), WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.'&section_id='.$section_id.'&post_id='.$id);
195
}
196
else
197
{
198
	$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
199
}
200

    
201
// Print admin footer
202
$admin->print_footer();
203

    
204
?>
(25-25/31)