Project

General

Profile

1
<?php
2

    
3
// $Id: save_post.php 1157 2009-10-09 21:54:57Z Luisehahne $
4

    
5
/*
6

    
7
 Website Baker Project <http://www.websitebaker.org/>
8
 Copyright (C) 2004-2009, Ryan Djurovich
9

    
10
 Website Baker is free software; you can redistribute it and/or modify
11
 it under the terms of the GNU General Public License as published by
12
 the Free Software Foundation; either version 2 of the License, or
13
 (at your option) any later version.
14

    
15
 Website Baker is distributed in the hope that it will be useful,
16
 but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 GNU General Public License for more details.
19

    
20
 You should have received a copy of the GNU General Public License
21
 along with Website Baker; if not, write to the Free Software
22
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23

    
24
*/
25

    
26
require('../../config.php');
27

    
28
require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
29

    
30
// Get id
31
if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id']))
32
{
33
	header("Location: ".ADMIN_URL."/pages/index.php");
34
	exit( 0 );
35
}
36
else
37
{
38
	$id = $_POST['post_id'];
39
	$post_id = $id;
40
}
41

    
42
function create_file($filename, $filetime=NULL )
43
{
44
global $page_id, $section_id, $post_id;
45

    
46
	// We need to create a new file
47
	// First, delete old file if it exists
48
	if(file_exists(WB_PATH.PAGES_DIRECTORY.$filename.PAGE_EXTENSION))
49
    {
50
        $filetime = isset($filetime) ? $filetime :  filectime($filename);
51
		unlink(WB_PATH.PAGES_DIRECTORY.$filename.PAGE_EXTENSION);
52
	}
53
    else {
54
        $filetime = isset($filetime) ? $filetime : time();
55
    }
56
	// The depth of the page directory in the directory hierarchy
57
	// '/pages' is at depth 1
58
	$pages_dir_depth = count(explode('/',PAGES_DIRECTORY))-1;
59
	// Work-out how many ../'s we need to get to the index page
60
	$index_location = '../';
61
	for($i = 0; $i < $pages_dir_depth; $i++)
62
    {
63
		$index_location .= '../';
64
	}
65

    
66
	// Write to the filename
67
	$content = ''.
68
'<?php
69
$page_id = '.$page_id.';
70
$section_id = '.$section_id.';
71
$post_id = '.$post_id.';
72
define("POST_SECTION", $section_id);
73
define("POST_ID", $post_id);
74
require("'.$index_location.'config.php");
75
require(WB_PATH."/index.php");
76
?>';
77
	if($handle = fopen($filename, 'w+'))
78
    {
79
    	fwrite($handle, $content);
80
    	fclose($handle);
81
        if($filetime)
82
        {
83
        touch($filename, $filetime);
84
        }
85
    	change_mode($filename);
86
    }
87

    
88
}
89

    
90
// Include WB admin wrapper script
91
$update_when_modified = true; // Tells script to update when this page was last updated
92
require(WB_PATH.'/modules/admin.php');
93

    
94
// Validate all fields
95
if($admin->get_post('title') == '' AND $admin->get_post('url') == '')
96
{
97
	$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);
98
}
99
else
100
{
101
	$title = $admin->get_post_escaped('title');
102
	$short = $admin->get_post_escaped('short');
103
	$long = $admin->get_post_escaped('long');
104
	$commenting = $admin->get_post_escaped('commenting');
105
	$active = $admin->get_post_escaped('active');
106
	$old_link = $admin->get_post_escaped('link');
107
	$group_id = $admin->get_post_escaped('group');
108
}
109

    
110
// Get page link URL
111
$query_page = $database->query("SELECT level,link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
112
$page = $query_page->fetchRow();
113
$page_level = $page['level'];
114
$page_link = $page['link'];
115

    
116
// Include WB functions file
117
require(WB_PATH.'/framework/functions.php');
118

    
119
// Work-out what the link should be
120
$post_link = '/posts/'.page_filename($title).PAGE_SPACER.$post_id;
121

    
122
// Make sure the post link is set and exists
123
// Make news post access files dir
124
make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/');
125
$file_create_time = '';
126
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/posts/'))
127
{
128
	$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
129
}
130
elseif($old_link != $post_link OR !file_exists(WB_PATH.PAGES_DIRECTORY.$post_link.PAGE_EXTENSION))
131
{
132
	// We need to create a new file
133
	// First, delete old file if it exists
134
	if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION))
135
    {
136
        $file_create_time = filectime($old_link);
137
		unlink(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION);
138
	}
139

    
140
    // Specify the filename
141
    $filename = WB_PATH.PAGES_DIRECTORY.'/'.$post_link.PAGE_EXTENSION;
142
    create_file($filename, $file_create_time);
143
}
144

    
145

    
146
// get publisedwhen and publisheduntil
147
$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
148
if($publishedwhen == '' || $publishedwhen < 1)
149
	$publishedwhen=0;
150
$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
151
if($publisheduntil == '' || $publisheduntil < 1)
152
	$publisheduntil=0;
153

    
154
// Update row
155
$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'");
156

    
157
// Check if there is a db error, otherwise say successful
158
if($database->is_error())
159
{
160
	$admin->print_error($database->get_error(), WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.'&section_id='.$section_id.'&post_id='.$id);
161
}
162
else
163
{
164
	$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
165
}
166

    
167
// Print admin footer
168
$admin->print_footer();
169

    
170
?>
(25-25/31)