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 2028 2013-12-13 23:48:59Z Luisehahne $
13
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/modules/news/save_post.php $
14
 * @lastmodified    $Date: 2013-12-14 00:48:59 +0100 (Sat, 14 Dec 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
          . 'SET `group_id`='.(int)$group_id.', '
77
          .     '`title`=\''.$database->escapeString($title).'\', '
78
          .     '`link`=\''.$database->escapeString($newLink).'\', '
79
          .     '`content_short`=\''.$database->escapeString($short).'\', '
80
          .     '`content_long`=\''.$database->escapeString($long).'\', '
81
          .     '`commenting`=\''.$database->escapeString($commenting).'\', '
82
          .     '`active`='.(int)$active.', '
83
          .     '`published_when`='.(int)$publishedwhen.', '
84
          .     '`published_until`='.(int)$publisheduntil.', '
85
          .     '`posted_when`='.time().', '
86
          .     '`posted_by`='.(int)$admin->get_user_id().' '
87
          . '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
// prozedural rename accessfile if link has changed, has to be changed to accessfile class when fixed
100
            		if(($sNewFilename != $sOldFilename) && (is_writable($sOldFilename))) {
101
            			if(!rename($sOldFilename,$sNewFilename)) {
102
            				$admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE'].' - '.$oldLink,$sBackUrl);
103
            			}
104
            		}
105
//                    $oAF = new AccessFile($sOldFilename, $page_id);
106
//                    $oAF->rename($sNewFile);
107
//                    unset($oAF);
108
                }catch(AccessFileException $e) {
109
                    $admin->print_error($e,$sBackUrl);
110
                }
111
            break;
112
            case "create":
113
                try {
114
                    $oAF = new AccessFile($sNewFilename, $page_id);
115
                    $oAF->addVar('section_id', $section_id, AccessFile::VAR_INT);
116
                    $oAF->addVar('post_id', $post_id, AccessFile::VAR_INT);
117
                    $oAF->addVar('post_section', $section_id, AccessFile::VAR_INT);
118
                    $oAF->write();
119
                    unset($oAF);
120
                }catch(AccessFileException $e) {
121
                    $admin->print_error($e,$sBackUrl);
122
                }
123
            break;
124
        }
125
	}
126
// Check if there is a db error, otherwise say successful
127
	if($database->is_error()) {
128
		$recallUrl = WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.
129
					 '&section_id='.$section_id.'&post_id='.$admin->getIDKEY($post_id);
130
		$admin->print_error($database->get_error(), $recallUrl);
131
	}else {
132
		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
133
	}
134
// Print admin footer
135
	$admin->print_footer();
(28-28/34)