Project

General

Profile

1 1425 Luisehahne
<?php
2
/**
3
 *
4
 * @category        modules
5
 * @package         news
6
 * @author          WebsiteBaker Project
7 1918 Luisehahne
 * @copyright       2009-2013, WebsiteBaker Org. e.V.
8
 * @link            http://www.websitebaker.org/
9 1425 Luisehahne
 * @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$
13 1918 Luisehahne
 * @filesource      $HeadURL$
14 1425 Luisehahne
 * @lastmodified    $Date$
15
 *
16
 */
17 1950 darkviper
                    error_reporting(E_ALL);
18 1457 Luisehahne
	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 1425 Luisehahne
28 1457 Luisehahne
	$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 1425 Luisehahne
34 1457 Luisehahne
	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 1425 Luisehahne
	}
39 1457 Luisehahne
	$admin->print_header();
40 1425 Luisehahne
41
// Validate all fields
42 1918 Luisehahne
	$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 1457 Luisehahne
	if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
49 1918 Luisehahne
		$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
50 1457 Luisehahne
		             '&section_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
51 1868 Luisehahne
		$admin->print_error($MESSAGE['GENERIC_FILL_IN_ALL'], $recallUrl);
52 1918 Luisehahne
	} else {
53
		$short      = $admin->get_post('short');
54
		$long       = $admin->get_post('long');
55
		$short = $admin->ReplaceAbsoluteMediaUrl($short);
56
		$long = $admin->ReplaceAbsoluteMediaUrl($long);
57 1457 Luisehahne
	}
58 1918 Luisehahne
59 1425 Luisehahne
// Include WB functions file
60 1457 Luisehahne
	require(WB_PATH.'/framework/functions.php');
61 1425 Luisehahne
// Work-out what the link should be
62 1950 darkviper
	$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 1425 Luisehahne
// get publisedwhen and publisheduntil
70 1457 Luisehahne
	$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 1425 Luisehahne
// Update row
75 1457 Luisehahne
	$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 1950 darkviper
	if( $database->query($sql) ) {
89 1868 Luisehahne
		// create new accessfile
90 1950 darkviper
        $sDoWhat = (($newLink == $old_link) && (file_exists($sNewFilename))) ? "nothing" : "action";
91 1985 Luisehahne
// 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 1950 darkviper
        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 1868 Luisehahne
	}
128 1425 Luisehahne
// Check if there is a db error, otherwise say successful
129 1457 Luisehahne
	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 1425 Luisehahne
// Print admin footer
137 1950 darkviper
	$admin->print_footer();