Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         news
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2011, Website Baker Org. e.V.
8
 * @link			http://www.websitebaker2.org/
9
 * @license         http://www.gnu.org/licenses/gpl.html
10
 * @platform        WebsiteBaker 2.8.x
11
 * @requirements    PHP 5.2.2 and higher
12
 * @version         $Id: save_post.php 1538 2011-12-10 15:06:15Z Luisehahne $
13
 * @filesource		$HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/save_post.php $
14
 * @lastmodified    $Date: 2011-12-10 16:06:15 +0100 (Sat, 10 Dec 2011) $
15
 *
16
 */
17

    
18
	function createNewsAccessFile($newLink, $oldLink, $page_id, $section_id, $post_id)
19
	{
20
		global $admin, $MESSAGE;
21
		$sPagesPath = WB_PATH.PAGES_DIRECTORY;
22
		$sPostsPath = $sPagesPath.'/posts';
23
	// create /posts/ - directory if not exists
24
		if(!file_exists($sPostsPath)) {
25
			if(is_writable($sPagesPath)) {
26
				make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/');
27
			}else {
28
				$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
29
			}
30
		}
31
	// check if /posts/ - dir is writable
32
		if(!is_writable($sPostsPath.'/')) {
33
			$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE']);
34
		}
35
	// delete old accessfile if link has changed
36
		if(($newLink != $oldLink) && (is_writable($sPostsPath.$oldLink.PAGE_EXTENSION))) {
37
			if(!unlink($sPostsPath.$oldLink.PAGE_EXTENSION)) {
38
				$admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE'].' - '.$oldLink);
39
			}
40
		}
41
	// all ok, now create new accessfile
42
		$newFile = $sPagesPath.$newLink.PAGE_EXTENSION;
43
		// $backSteps = preg_replace('/^'.preg_quote(WB_PATH).'/', '', $sPostsPath);
44
		$backSteps = preg_replace('@^'.preg_quote(WB_PATH).'@', '', $sPostsPath);
45
		$backSteps = str_repeat( '../', substr_count($backSteps, '/'));
46
		$content =
47
			'<?php'."\n".
48
			'// *** This file is generated by WebsiteBaker Ver.'.WB_VERSION."\n".
49
			'// *** Creation date: '.date('c')."\n".
50
			'// *** Do not modify this file manually'."\n".
51
			'// *** WB will rebuild this file from time to time!!'."\n".
52
			'// *************************************************'."\n".
53
			"\t".'$page_id      = '.$page_id.';'."\n".
54
			"\t".'$section_id   = '.$section_id.';'."\n".
55
			"\t".'$post_id      = '.$post_id.';'."\n".
56
			"\t".'$post_section = '.$section_id.';'."\n".
57
//			"\t".'define(\'POST_SECTION\', '.$section_id.');'."\n".
58
//			"\t".'define(\'POST_ID\',      '.$post_id.');'."\n".
59
			"\t".'require(\''.$backSteps.'index.php\');'."\n".
60
			'// *************************************************'."\n";
61
		if( file_put_contents($newFile, $content) !== false ) {
62
		// Chmod the file
63
			change_mode($newFile);
64
		}else {
65
			$admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'],ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
66
			// $admin->print_error($MESSAGE['PAGES_CANNOT_CREATE_ACCESS_FILE'].': '.$newFile);
67

    
68
		}
69
	} // end of function createNewsAccessFile
70
/* ************************************************************************** */
71
	require('../../config.php');
72
	require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
73
// Get post_id
74
	if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
75
		header("Location: ".ADMIN_URL."/pages/index.php");
76
		exit( 0 );
77
	}else {
78
		$post_id = intval($_POST['post_id']);
79
	}
80

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

    
87
	if (!$admin->checkFTAN()) {
88
		$admin->print_header();
89
		$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],
90
		                    ADMIN_URL.'/pages/modify.php?page_id='.$page_id );
91
	}
92
	$admin->print_header();
93

    
94
// Validate all fields
95
	if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
96
        $recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
97
		             '&section_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
98
		$admin->print_error($MESSAGE['GENERIC']['FILL_IN_ALL'], $recallUrl);
99
	}else {
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
// Get page link URL
109
	$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$page_id;
110
	$oldLink = $database->get_one($sql);
111
// Include WB functions file
112
	require(WB_PATH.'/framework/functions.php');
113
// Work-out what the link should be
114
	$newLink = '/posts/'.page_filename($title).PAGE_SPACER.$post_id;
115
// create new accessfile
116
	createNewsAccessFile($newLink, $oldLink, $page_id, $section_id, $post_id);
117
// get publisedwhen and publisheduntil
118
	$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
119
	if($publishedwhen == '' || $publishedwhen < 1) { $publishedwhen=0; }
120
	$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
121
	if($publisheduntil == '' || $publisheduntil < 1) { $publisheduntil=0; }
122
// Update row
123
	$sql  = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
124
	$sql .= 'SET `group_id`='.(int)$group_id.', ';
125
	$sql .=     '`title`=\''.$title.'\', ';
126
	$sql .=     '`link`=\''.$newLink.'\', ';
127
	$sql .=     '`content_short`=\''.$short.'\', ';
128
	$sql .=     '`content_long`=\''.$long.'\', ';
129
	$sql .=     '`commenting`=\''.$commenting.'\', ';
130
	$sql .=     '`active`='.(int)$active.', ';
131
	$sql .=     '`published_when`='.(int)$publishedwhen.', ';
132
	$sql .=     '`published_until`='.(int)$publisheduntil.', ';
133
	$sql .=     '`posted_when`='.time().', ';
134
	$sql .=     '`posted_by`='.(int)$admin->get_user_id().' ';
135
	$sql .= 'WHERE `post_id`='.(int)$post_id;
136
	$database->query($sql);
137
// Check if there is a db error, otherwise say successful
138
	if($database->is_error()) {
139
		$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
140
					 '&section_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
141
		$admin->print_error($database->get_error(), $recallUrl);
142
	}else {
143
		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
144
	}
145
// Print admin footer
146
	$admin->print_footer();
(26-26/32)