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 1985 2013-10-19 00:46:26Z Luisehahne $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/save_post.php $
14
 * @lastmodified    $Date: 2013-10-19 02:46:26 +0200 (Sat, 19 Oct 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
// try to create the whole path to the accessfile
92
    	$sAccessPath = dirname($sNewFilename).'/';
93
    	if(!($bRetval = is_dir($sAccessPath))) {
94
    		$iOldUmask = umask(0) ;
95
    		// sanitize directory mode to 'o+rwx/g+x/u+x' and create path
96
    		$bRetval = mkdir($sAccessPath, (OCTAL_DIR_MODE |0711), true); 
97
    		umask($iOldUmask);
98
    	}
99
        if($sDoWhat == "action") {
100
            $sDoWhat = (($sDoWhat == "action") && file_exists($sOldFilename)) ? "update" : "create";
101
        }
102

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