Project

General

Profile

1
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         news
6
 * @author          WebsiteBaker Project
7
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.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 1918 2013-06-07 04:18:18Z Luisehahne $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/save_post.php $
14
 * @lastmodified    $Date: 2013-06-07 06:18:18 +0200 (Fri, 07 Jun 2013) $
15
 *
16
 */
17

    
18
	function createNewsAccessFile($newLink, $oldLink, $page_id, $section_id, $post_id)
19
	{
20
		global $admin, $MESSAGE;
21
		$sError = '';
22
		$sPagesPath = WB_PATH.PAGES_DIRECTORY;
23
		$sPostsPath = $sPagesPath.'/posts';
24
		$sBackUrl = ADMIN_URL.'/pages/modify.php?page_id='.$page_id;
25
	// delete old accessfile if link has changed
26
		if(($newLink != $oldLink) && (is_writable($sPostsPath.$oldLink.PAGE_EXTENSION))) {
27
			if(!unlink($sPostsPath.$oldLink.PAGE_EXTENSION)) {
28
				$admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE'].' - '.$oldLink,$sBackUrl);
29
			}
30
		}
31
	// all ok, now create new accessfile
32
		$newFile = $sPagesPath.$newLink.PAGE_EXTENSION;
33
		// $backSteps = preg_replace('/^'.preg_quote(WB_PATH).'/', '', $sPostsPath);
34
				$aOptionalCommands = array(
35
				         '$section_id   = '.$section_id,
36
				         '$post_id      = '.$post_id ,
37
				         '$post_section = '.$section_id
38
				);
39
		if(	($sError = create_access_file($newFile, $page_id, 0, $aOptionalCommands))!==true ) 
40
		{
41
			$admin->print_error($sError,$sBackUrl );
42
		}
43
	} // end of function createNewsAccessFile
44
/* ************************************************************************** */
45
	require('../../config.php');
46
	require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
47
// Get post_id
48
	if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
49
		header("Location: ".ADMIN_URL."/pages/index.php");
50
		exit( 0 );
51
	}else {
52
		$post_id = intval($_POST['post_id']);
53
	}
54

    
55
	$admin_header = false;
56
	// Tells script to update when this page was last updated
57
	$update_when_modified = true;
58
	// Include WB admin wrapper script
59
	require(WB_PATH.'/modules/admin.php');
60

    
61
	if (!$admin->checkFTAN()) {
62
		$admin->print_header();
63
		$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],
64
		                    ADMIN_URL.'/pages/modify.php?page_id='.$page_id );
65
	}
66
	$admin->print_header();
67

    
68
//	$sMediaUrl = WB_URL.MEDIA_DIRECTORY;
69
//	$searchfor = '@(<[^>]*=\s*")('.preg_quote($sMediaUrl).')([^">]*".*>)@siU';
70
// Validate all fields
71
	$title      = $admin->StripCodeFromText($admin->get_post('title'));
72
	$commenting = $admin->StripCodeFromText($admin->get_post('commenting'));
73
	$active     = intval($admin->get_post('active'));
74
	$old_link   = $admin->StripCodeFromText($admin->get_post('link'));
75
	$group_id   = intval($admin->get_post('group'));
76

    
77
	if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
78
		$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
79
		             '&section_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
80
		$admin->print_error($MESSAGE['GENERIC_FILL_IN_ALL'], $recallUrl);
81
	} else {
82
		$short      = $admin->get_post('short');
83
		$long       = $admin->get_post('long');
84
//		if(ini_get('magic_quotes_gpc')==true)
85
//		{
86
//			$short = $admin->strip_slashes($short);
87
//			$long = $admin->strip_slashes($long);
88
//		}
89
//		$short = preg_replace($searchfor, '$1{SYSVAR:MEDIA_REL}$3', $short );
90
//		$long = preg_replace($searchfor, '$1{SYSVAR:MEDIA_REL}$3', $long );
91
		$short = $admin->ReplaceAbsoluteMediaUrl($short);
92
		$long = $admin->ReplaceAbsoluteMediaUrl($long);
93
	}
94

    
95
// Get page link URL
96
	$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$page_id;
97
	$oldLink = $database->get_one($sql);
98
// Include WB functions file
99
	require(WB_PATH.'/framework/functions.php');
100
// Work-out what the link should be
101
	$newLink = '/posts/'.page_filename($title).PAGE_SPACER.$post_id;
102
// get publisedwhen and publisheduntil
103
	$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
104
	if($publishedwhen == '' || $publishedwhen < 1) { $publishedwhen=0; }
105
	$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
106
	if($publisheduntil == '' || $publisheduntil < 1) { $publisheduntil=0; }
107
// Update row
108
	$sql  = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
109
	$sql .= 'SET `group_id`='.(int)$group_id.', ';
110
	$sql .=     '`title`=\''.$title.'\', ';
111
	$sql .=     '`link`=\''.$newLink.'\', ';
112
	$sql .=     '`content_short`=\''.$short.'\', ';
113
	$sql .=     '`content_long`=\''.$long.'\', ';
114
	$sql .=     '`commenting`=\''.$commenting.'\', ';
115
	$sql .=     '`active`='.(int)$active.', ';
116
	$sql .=     '`published_when`='.(int)$publishedwhen.', ';
117
	$sql .=     '`published_until`='.(int)$publisheduntil.', ';
118
	$sql .=     '`posted_when`='.time().', ';
119
	$sql .=     '`posted_by`='.(int)$admin->get_user_id().' ';
120
	$sql .= 'WHERE `post_id`='.(int)$post_id;
121
	if( $database->query($sql) ) { 
122
		// create new accessfile
123
		createNewsAccessFile($newLink, $oldLink, $page_id, $section_id, $post_id);
124
	}
125
// Check if there is a db error, otherwise say successful
126
	if($database->is_error()) {
127
		$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
128
					 '&section_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
129
		$admin->print_error($database->get_error(), $recallUrl);
130
	}else {
131
		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
132
	}
133
// Print admin footer
134
	$admin->print_footer();
(27-27/33)