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 1950 2013-08-08 22:31:33Z darkviper $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/save_post.php $
14
 * @lastmodified    $Date: 2013-08-09 00:31:33 +0200 (Fri, 09 Aug 2013) $
15
 *
16
 */
17
                    error_reporting(E_ALL);
18
	require('../../config.php');
19
	require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
20
// Get post_id
21
	if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
22
		header("Location: ".ADMIN_URL."/pages/index.php");
23
		exit( 0 );
24
	}else {
25
		$post_id = intval($_POST['post_id']);
26
	}
27

    
28
	$admin_header = false;
29
	// Tells script to update when this page was last updated
30
	$update_when_modified = true;
31
	// Include WB admin wrapper script
32
	require(WB_PATH.'/modules/admin.php');
33

    
34
	if (!$admin->checkFTAN()) {
35
		$admin->print_header();
36
		$admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'],
37
		                    ADMIN_URL.'/pages/modify.php?page_id='.$page_id );
38
	}
39
	$admin->print_header();
40

    
41
// Validate all fields
42
	$title      = $admin->StripCodeFromText($admin->get_post('title'));
43
	$commenting = $admin->StripCodeFromText($admin->get_post('commenting'));
44
	$active     = intval($admin->get_post('active'));
45
	$old_link   = $admin->StripCodeFromText($admin->get_post('link'));
46
	$group_id   = intval($admin->get_post('group'));
47

    
48
	if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
49
		$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
50
		             '&section_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
51
		$admin->print_error($MESSAGE['GENERIC_FILL_IN_ALL'], $recallUrl);
52
	} else {
53
		$short      = $admin->get_post('short');
54
		$long       = $admin->get_post('long');
55
		$short = $admin->ReplaceAbsoluteMediaUrl($short);
56
		$long = $admin->ReplaceAbsoluteMediaUrl($long);
57
	}
58

    
59
// Include WB functions file
60
	require(WB_PATH.'/framework/functions.php');
61
// Work-out what the link should be
62
	$sNewFile = page_filename($title).PAGE_SPACER.$post_id;
63
    $newLink = '/posts/'.$sNewFile;
64
    $sPagesPath = WB_PATH.PAGES_DIRECTORY;
65
    $sBackUrl = ADMIN_URL.'/pages/modify.php?page_id='.$page_id;
66
    $sNewFilename = $sPagesPath.$newLink.PAGE_EXTENSION;
67
    $sOldFilename = $sPagesPath.$old_link.PAGE_EXTENSION;
68

    
69
// get publisedwhen and publisheduntil
70
	$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
71
	if($publishedwhen == '' || $publishedwhen < 1) { $publishedwhen=0; }
72
	$publisheduntil = jscalendar_to_timestamp($admin->get_post_escaped('enddate'), $publishedwhen);
73
	if($publisheduntil == '' || $publisheduntil < 1) { $publisheduntil=0; }
74
// Update row
75
	$sql  = 'UPDATE `'.TABLE_PREFIX.'mod_news_posts` ';
76
	$sql .= 'SET `group_id`='.(int)$group_id.', ';
77
	$sql .=     '`title`=\''.$title.'\', ';
78
	$sql .=     '`link`=\''.$newLink.'\', ';
79
	$sql .=     '`content_short`=\''.$short.'\', ';
80
	$sql .=     '`content_long`=\''.$long.'\', ';
81
	$sql .=     '`commenting`=\''.$commenting.'\', ';
82
	$sql .=     '`active`='.(int)$active.', ';
83
	$sql .=     '`published_when`='.(int)$publishedwhen.', ';
84
	$sql .=     '`published_until`='.(int)$publisheduntil.', ';
85
	$sql .=     '`posted_when`='.time().', ';
86
	$sql .=     '`posted_by`='.(int)$admin->get_user_id().' ';
87
	$sql .= 'WHERE `post_id`='.(int)$post_id;
88
	if( $database->query($sql) ) {
89
		// create new accessfile
90
        $sDoWhat = (($newLink == $old_link) && (file_exists($sNewFilename))) ? "nothing" : "action";
91
        if($sDoWhat == "action") {
92
            $sDoWhat = (($sDoWhat == "action") && file_exists($sOldFilename)) ? "update" : "create";
93
        }
94

    
95
        switch($sDoWhat)
96
        {
97
            case "update":
98
                try {
99
                    $oAF = new AccessFile($sOldFilename, $page_id);
100
                    $oAF->rename($sNewFile);
101
                    unset($oAF);
102
                }catch(AccessFileException $e) {
103
                    $admin->print_error($e,$sBackUrl);
104
                }
105
            break;
106
            case "create":
107
                try {
108
                    $oAF = new AccessFile($sNewFilename, $page_id);
109
                    $oAF->addVar('section_id', $section_id, AccessFile::VAR_INT);
110
                    $oAF->addVar('post_id', $post_id, AccessFile::VAR_INT);
111
                    $oAF->addVar('post_section', $section_id, AccessFile::VAR_INT);
112
                    $oAF->write();
113
                    unset($oAF);
114
                }catch(AccessFileException $e) {
115
                    $admin->print_error($e,$sBackUrl);
116
                }
117
            break;
118
        }
119
	}
120
// Check if there is a db error, otherwise say successful
121
	if($database->is_error()) {
122
		$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
123
					 '&section_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
124
		$admin->print_error($database->get_error(), $recallUrl);
125
	}else {
126
		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
127
	}
128
// Print admin footer
129
	$admin->print_footer();
(27-27/33)