Revision 317
Added by stefan over 19 years ago
| save_post.php | ||
|---|---|---|
| 1 |
<?php
|
|
| 2 |
|
|
| 3 |
// $Id$
|
|
| 4 |
|
|
| 5 |
/*
|
|
| 6 |
|
|
| 7 |
Website Baker Project <http://www.websitebaker.org/>
|
|
| 8 |
Copyright (C) 2004-2006, Ryan Djurovich
|
|
| 9 |
|
|
| 10 |
Website Baker is free software; you can redistribute it and/or modify
|
|
| 11 |
it under the terms of the GNU General Public License as published by
|
|
| 12 |
the Free Software Foundation; either version 2 of the License, or
|
|
| 13 |
(at your option) any later version.
|
|
| 14 |
|
|
| 15 |
Website Baker is distributed in the hope that it will be useful,
|
|
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
| 18 |
GNU General Public License for more details.
|
|
| 19 |
|
|
| 20 |
You should have received a copy of the GNU General Public License
|
|
| 21 |
along with Website Baker; if not, write to the Free Software
|
|
| 22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
| 23 |
|
|
| 24 |
*/
|
|
| 25 |
|
|
| 26 |
require('../../config.php');
|
|
| 27 |
|
|
| 28 |
// Get id
|
|
| 29 |
if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
|
|
| 30 |
header("Location: ".ADMIN_URL."/pages/index.php");
|
|
| 31 |
exit(0);
|
|
| 32 |
} else {
|
|
| 33 |
$id = $_POST['post_id'];
|
|
| 34 |
$post_id = $id;
|
|
| 35 |
}
|
|
| 36 |
|
|
| 37 |
// Include WB admin wrapper script
|
|
| 38 |
$update_when_modified = true; // Tells script to update when this page was last updated
|
|
| 39 |
require(WB_PATH.'/modules/admin.php');
|
|
| 40 |
|
|
| 41 |
// Validate all fields
|
|
| 42 |
if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
|
|
| 43 |
$admin->print_error($MESSAGE['GENERIC']['FILL_IN_ALL'], WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.'§ion_id='.$section_id.'&post_id='.$id);
|
|
| 44 |
} else {
|
|
| 45 |
$title = $admin->add_slashes($admin->get_post('title'));
|
|
| 46 |
$short = $admin->add_slashes($admin->get_post('short'));
|
|
| 47 |
$long = $admin->add_slashes($admin->get_post('long'));
|
|
| 48 |
$commenting = $admin->get_post('commenting');
|
|
| 49 |
$active = $admin->get_post('active');
|
|
| 50 |
$old_link = $admin->get_post('link');
|
|
| 51 |
$group_id = $admin->get_post('group');
|
|
| 52 |
}
|
|
| 53 |
|
|
| 54 |
// Get page link URL
|
|
| 55 |
$query_page = $database->query("SELECT level,link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
|
|
| 56 |
$page = $query_page->fetchRow();
|
|
| 57 |
$page_level = $page['level'];
|
|
| 58 |
$page_link = $page['link'];
|
|
| 59 |
|
|
| 60 |
// Include WB functions file
|
|
| 61 |
require(WB_PATH.'/framework/functions.php');
|
|
| 62 |
|
|
| 63 |
// Work-out what the link should be
|
|
| 64 |
$post_link = '/posts/'.page_filename($title).$post_id;
|
|
| 65 |
|
|
| 66 |
// Make sure the post link is set and exists
|
|
| 67 |
// Make news post access files dir
|
|
| 68 |
make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/');
|
|
| 69 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/posts/')) {
|
|
| 70 |
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']);
|
|
| 71 |
} elseif($old_link != $post_link OR !file_exists(WB_PATH.PAGES_DIRECTORY.$post_link.'.php')) {
|
|
| 72 |
// We need to create a new file
|
|
| 73 |
// First, delete old file if it exists
|
|
| 74 |
if(file_exists(WB_PATH.$old_link.'.php')) {
|
|
| 75 |
unlink(WB_PATH.$old_link.'.php');
|
|
| 76 |
}
|
|
| 77 |
// Specify the filename
|
|
| 78 |
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$post_link.'.php';
|
|
| 79 |
// The depth of the page directory in the directory hierarchy
|
|
| 80 |
// '/pages' is at depth 1
|
|
| 81 |
$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
|
|
| 1 |
<?php |
|
| 2 |
|
|
| 3 |
// $Id$ |
|
| 4 |
|
|
| 5 |
/* |
|
| 6 |
|
|
| 7 |
Website Baker Project <http://www.websitebaker.org/> |
|
| 8 |
Copyright (C) 2004-2006, Ryan Djurovich |
|
| 9 |
|
|
| 10 |
Website Baker is free software; you can redistribute it and/or modify |
|
| 11 |
it under the terms of the GNU General Public License as published by |
|
| 12 |
the Free Software Foundation; either version 2 of the License, or |
|
| 13 |
(at your option) any later version. |
|
| 14 |
|
|
| 15 |
Website Baker is distributed in the hope that it will be useful, |
|
| 16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 18 |
GNU General Public License for more details. |
|
| 19 |
|
|
| 20 |
You should have received a copy of the GNU General Public License |
|
| 21 |
along with Website Baker; if not, write to the Free Software |
|
| 22 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 23 |
|
|
| 24 |
*/ |
|
| 25 |
|
|
| 26 |
require('../../config.php');
|
|
| 27 |
|
|
| 28 |
// Get id |
|
| 29 |
if(!isset($_POST['post_id']) OR !is_numeric($_POST['post_id'])) {
|
|
| 30 |
header("Location: ".ADMIN_URL."/pages/index.php");
|
|
| 31 |
exit(0); |
|
| 32 |
} else {
|
|
| 33 |
$id = $_POST['post_id']; |
|
| 34 |
$post_id = $id; |
|
| 35 |
} |
|
| 36 |
|
|
| 37 |
// Include WB admin wrapper script |
|
| 38 |
$update_when_modified = true; // Tells script to update when this page was last updated |
|
| 39 |
require(WB_PATH.'/modules/admin.php'); |
|
| 40 |
|
|
| 41 |
// Validate all fields |
|
| 42 |
if($admin->get_post('title') == '' AND $admin->get_post('url') == '') {
|
|
| 43 |
$admin->print_error($MESSAGE['GENERIC']['FILL_IN_ALL'], WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.'§ion_id='.$section_id.'&post_id='.$id); |
|
| 44 |
} else {
|
|
| 45 |
$title = $admin->add_slashes($admin->get_post('title'));
|
|
| 46 |
$short = $admin->add_slashes($admin->get_post('short'));
|
|
| 47 |
$long = $admin->add_slashes($admin->get_post('long'));
|
|
| 48 |
$commenting = $admin->get_post('commenting');
|
|
| 49 |
$active = $admin->get_post('active');
|
|
| 50 |
$old_link = $admin->get_post('link');
|
|
| 51 |
$group_id = $admin->get_post('group');
|
|
| 52 |
} |
|
| 53 |
|
|
| 54 |
// Get page link URL |
|
| 55 |
$query_page = $database->query("SELECT level,link FROM ".TABLE_PREFIX."pages WHERE page_id = '$page_id'");
|
|
| 56 |
$page = $query_page->fetchRow(); |
|
| 57 |
$page_level = $page['level']; |
|
| 58 |
$page_link = $page['link']; |
|
| 59 |
|
|
| 60 |
// Include WB functions file |
|
| 61 |
require(WB_PATH.'/framework/functions.php'); |
|
| 62 |
|
|
| 63 |
// Work-out what the link should be |
|
| 64 |
$post_link = '/posts/'.page_filename($title).$post_id; |
|
| 65 |
|
|
| 66 |
// Make sure the post link is set and exists |
|
| 67 |
// Make news post access files dir |
|
| 68 |
make_dir(WB_PATH.PAGES_DIRECTORY.'/posts/'); |
|
| 69 |
if(!is_writable(WB_PATH.PAGES_DIRECTORY.'/posts/')) {
|
|
| 70 |
$admin->print_error($MESSAGE['PAGES']['CANNOT_CREATE_ACCESS_FILE']); |
|
| 71 |
} elseif($old_link != $post_link OR !file_exists(WB_PATH.PAGES_DIRECTORY.$post_link.'.php')) {
|
|
| 72 |
// We need to create a new file |
|
| 73 |
// First, delete old file if it exists |
|
| 74 |
if(file_exists(WB_PATH.$old_link.'.php')) {
|
|
| 75 |
unlink(WB_PATH.$old_link.'.php'); |
|
| 76 |
} |
|
| 77 |
// Specify the filename |
|
| 78 |
$filename = WB_PATH.PAGES_DIRECTORY.'/'.$post_link.'.php'; |
|
| 79 |
// The depth of the page directory in the directory hierarchy |
|
| 80 |
// '/pages' is at depth 1 |
|
| 81 |
$pages_dir_depth=count(explode('/',PAGES_DIRECTORY))-1;
|
|
| 82 | 82 |
// Work-out how many ../'s we need to get to the index page |
| 83 |
$index_location = '../';
|
|
| 84 |
for($i = 0; $i < $pages_dir_depth; $i++) {
|
|
| 85 |
$index_location .= '../';
|
|
| 86 |
}
|
|
| 87 |
// Write to the filename
|
|
| 88 |
$content = ''.
|
|
| 89 |
'<?php
|
|
| 90 |
$page_id = '.$page_id.';
|
|
| 91 |
$section_id = '.$section_id.';
|
|
| 92 |
$post_id = '.$post_id.';
|
|
| 93 |
define("POST_ID", $post_id);
|
|
| 94 |
require("'.$index_location.'config.php");
|
|
| 95 |
require(WB_PATH."/index.php");
|
|
| 96 |
?>';
|
|
| 97 |
$handle = fopen($filename, 'w');
|
|
| 98 |
fwrite($handle, $content);
|
|
| 99 |
fclose($handle);
|
|
| 100 |
change_mode($filename);
|
|
| 101 |
}
|
|
| 102 |
|
|
| 103 |
// Update row
|
|
| 104 |
$database->query("UPDATE ".TABLE_PREFIX."mod_news_posts SET group_id = '$group_id', title = '$title', link = '$post_link', content_short = '$short', content_long = '$long', commenting = '$commenting', active = '$active', posted_when = '".mktime()."', posted_by = '".$admin->get_user_id()."' WHERE post_id = '$post_id'");
|
|
| 105 |
|
|
| 106 |
// Check if there is a db error, otherwise say successful
|
|
| 107 |
if($database->is_error()) {
|
|
| 108 |
$admin->print_error($database->get_error(), WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.'§ion_id='.$section_id.'&post_id='.$id);
|
|
| 109 |
} else {
|
|
| 110 |
$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
|
|
| 111 |
}
|
|
| 112 |
|
|
| 113 |
// Print admin footer
|
|
| 114 |
$admin->print_footer();
|
|
| 115 |
|
|
| 83 |
$index_location = '../'; |
|
| 84 |
for($i = 0; $i < $pages_dir_depth; $i++) {
|
|
| 85 |
$index_location .= '../'; |
|
| 86 |
} |
|
| 87 |
// Write to the filename |
|
| 88 |
$content = ''. |
|
| 89 |
'<?php |
|
| 90 |
$page_id = '.$page_id.'; |
|
| 91 |
$section_id = '.$section_id.'; |
|
| 92 |
$post_id = '.$post_id.'; |
|
| 93 |
define("POST_ID", $post_id);
|
|
| 94 |
require("'.$index_location.'config.php");
|
|
| 95 |
require(WB_PATH."/index.php"); |
|
| 96 |
?>'; |
|
| 97 |
$handle = fopen($filename, 'w'); |
|
| 98 |
fwrite($handle, $content); |
|
| 99 |
fclose($handle); |
|
| 100 |
change_mode($filename); |
|
| 101 |
} |
|
| 102 |
|
|
| 103 |
// Update row |
|
| 104 |
$database->query("UPDATE ".TABLE_PREFIX."mod_news_posts SET group_id = '$group_id', title = '$title', link = '$post_link', content_short = '$short', content_long = '$long', commenting = '$commenting', active = '$active', posted_when = '".mktime()."', posted_by = '".$admin->get_user_id()."' WHERE post_id = '$post_id'");
|
|
| 105 |
|
|
| 106 |
// Check if there is a db error, otherwise say successful |
|
| 107 |
if($database->is_error()) {
|
|
| 108 |
$admin->print_error($database->get_error(), WB_URL.'/modules/news/modify_post.php?page_id='.$page_id.'§ion_id='.$section_id.'&post_id='.$id); |
|
| 109 |
} else {
|
|
| 110 |
$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id); |
|
| 111 |
} |
|
| 112 |
|
|
| 113 |
// Print admin footer |
|
| 114 |
$admin->print_footer(); |
|
| 115 |
|
|
| 116 | 116 |
?> |
Also available in: Unified diff
Changed all line endings to Unix stlye