Project

General

Profile

« Previous | Next » 

Revision 1289

Added by kweitzel over 14 years ago

Branch 2.8.1 merged back into Trunk

View differences:

save_post.php
1
<?php
2

  
3
// $Id$
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
	header("Location: ".ADMIN_URL."/pages/index.php");
33
	exit(0);
34
} else {
35
	$id = $_POST['post_id'];
36
	$post_id = $id;
37
}
38

  
39
// Include WB admin wrapper script
40
$update_when_modified = true; // Tells script to update when this page was last updated
41
require(WB_PATH.'/modules/admin.php');
42

  
43
// Validate all fields
44
if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
45
	$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);
46
} else {
47
	$title = $admin->get_post_escaped('title');
48
	$short = $admin->get_post_escaped('short');
49
	$long = $admin->get_post_escaped('long');
50
	$commenting = $admin->get_post_escaped('commenting');
51
	$active = $admin->get_post_escaped('active');
52
	$old_link = $admin->get_post_escaped('link');
53
	$group_id = $admin->get_post_escaped('group');
54
}
55

  
56
// Get page link URL
57
$query_page = $database->query("SELECT level,link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
58
$page = $query_page->fetchRow();
59
$page_level = $page['level'];
60
$page_link = $page['link'];
61

  
62
// Include WB functions file
63
require(WB_PATH.'/framework/functions.php');
64

  
65
// Work-out what the link should be
66
$post_link = '/posts/'.page_filename($title).PAGE_SPACER.$post_id;
67

  
68
// Make sure the post link is set and exists
69
// Make news post access files dir
70
make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/');
71
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/posts/')) {
72
	$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
73
} elseif($old_link != $post_link OR !file_exists(WB_PATH.PAGES_DIRECTORY.$post_link.PAGE_EXTENSION)) {
74
	// We need to create a new file
75
	// First, delete old file if it exists
76
	if(file_exists(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION)) {
77
		unlink(WB_PATH.PAGES_DIRECTORY.$old_link.PAGE_EXTENSION);
78
	}
79
	// Specify the filename
80
	$filename = WB_PATH.PAGES_DIRECTORY.'/'.$post_link.PAGE_EXTENSION;
81
	// The depth of the page directory in the directory hierarchy
82
	// '/pages' is at depth 1
83
	$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
84
	// Work-out how many ../'s we need to get to the index page
85
	$index_location = '../';
86
	for($i = 0; $i < $pages_dir_depth; $i++) {
87
		$index_location .= '../';
88
	}
89
	// Write to the filename
90
	$content = ''.
91
'<?php
92
$page_id = '.$page_id.';
93
$section_id = '.$section_id.';
94
$post_id = '.$post_id.';
95
define("POST_ID", $post_id);
96
require("'.$index_location.'config.php");
97
require(WB_PATH."/index.php");
98
?>';
99
	$handle = fopen($filename, 'w');
100
	fwrite($handle, $content);
101
	fclose($handle);
102
	change_mode($filename);
103
}
104

  
105
// get publisedwhen and publisheduntil
106
$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
107
if($publishedwhen == '' || $publishedwhen < 1)
108
	$publishedwhen=0;
109
$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
110
if($publisheduntil == '' || $publisheduntil < 1)
111
	$publisheduntil=0;
112

  
113
// Update row
114
$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'");
115

  
116
// Check if there is a db error, otherwise say successful
117
if($database->is_error()) {
118
	$admin->print_error($database->get_error(), WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.'&section_id='.$section_id.'&post_id='.$id);
119
} else {
120
	$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
121
}
122

  
123
// Print admin footer
124
$admin->print_footer();
125

  
1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         news
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2010, 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 4.3.4 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL$
15
 * @lastmodified    $Date$
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
function create_file($filename, $filetime=NULL )
36
{
37
global $page_id, $section_id, $post_id;
38

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

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

  
81
}
82

  
83
// Include WB admin wrapper script
84
$update_when_modified = true; // Tells script to update when this page was last updated
85
require(WB_PATH.'/modules/admin.php');
86

  
87
// Validate all fields
88
if($admin->get_post('title') == '' AND $admin->get_post('url') == '')
89
{
90
	$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);
91
}
92
else
93
{
94
	$title = $admin->get_post_escaped('title');
95
	$short = $admin->get_post_escaped('short');
96
	$long = $admin->get_post_escaped('long');
97
	$commenting = $admin->get_post_escaped('commenting');
98
	$active = $admin->get_post_escaped('active');
99
	$old_link = $admin->get_post_escaped('link');
100
	$group_id = $admin->get_post_escaped('group');
101
}
102

  
103
// Get page link URL
104
$query_page = $database->query("SELECT level,link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
105
$page = $query_page->fetchRow();
106
$page_level = $page['level'];
107
$page_link = $page['link'];
108

  
109
// Include WB functions file
110
require(WB_PATH.'/framework/functions.php');
111

  
112
// Work-out what the link should be
113
$post_link = '/posts/'.page_filename($title).PAGE_SPACER.$post_id;
114

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

  
133
    // Specify the filename
134
    $filename = WB_PATH.PAGES_DIRECTORY.'/'.$post_link.PAGE_EXTENSION;
135
    create_file($filename, $file_create_time);
136
}
137

  
138

  
139
// get publisedwhen and publisheduntil
140
$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
141
if($publishedwhen == '' || $publishedwhen < 1)
142
	$publishedwhen=0;
143
$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
144
if($publisheduntil == '' || $publisheduntil < 1)
145
	$publisheduntil=0;
146

  
147
// Update row
148
$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'");
149

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

  
160
// Print admin footer
161
$admin->print_footer();
162

  
126 163
?>
127 164

  

Also available in: Unified diff