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-2011, 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 5.2.2 and higher
13
 * @version         $Id: save_post.php 1383 2011-01-15 14:09:11Z FrankH $
14
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/save_post.php $
15
 * @lastmodified    $Date: 2011-01-15 15:09:11 +0100 (Sat, 15 Jan 2011) $
16
 *
17
 */
18

    
19
require('../../config.php');
20

    
21
require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
22

    
23
// Get id
24
if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id']))
25
{
26
	header("Location: ".ADMIN_URL."/pages/index.php");
27
	exit( 0 );
28
}
29
else
30
{
31
	$id = $_POST['post_id'];
32
	$post_id = $id;
33
}
34

    
35
// Include WB admin wrapper script
36
$update_when_modified = true; // Tells script to update when this page was last updated
37
require(WB_PATH.'/modules/admin.php');
38

    
39
if (!$admin->checkFTAN())
40
{
41
	$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], ADMIN_URL);
42
	exit();
43
}
44

    
45
function create_file($filename, $filetime=NULL )
46
{
47
global $page_id, $section_id, $post_id;
48

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

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

    
91
}
92

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

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

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

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

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

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

    
144

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

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

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

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

    
169
?>
(25-25/31)