query_fetchDB(" SELECT post_title, post_content, post_status, post_comment_status FROM ot_posts WHERE id = '" . $_GET['post'] . "' && post_type = 'post' && (post_status != 'privé' OR post_author = " . USER_ID . ") ORDER BY id DESC LIMIT 1 "); } elseif(defined("USER_LEVEL_AUTHOR")) // No, it's the writer himself { $Post = $DB->query_fetchDB(" SELECT post_title, post_content, post_status, post_comment_status FROM ot_posts WHERE id = '" . $_GET['post'] . "' && post_author = '" . USER_ID . "' && post_type = 'post' ORDER BY id DESC LIMIT 1 "); } if($Post) // Post exists? { $CategoriesSelected = $DB->query_fetchDB(" SELECT id, category_id FROM ot_post2category WHERE post_id = '" . $_GET['post'] . "' ORDER BY id DESC "); // Fetch categories where post is in // We'll check to save the post if($_SERVER['REQUEST_METHOD'] == "POST") // New post? { if( ! empty($_POST['post_status']) && ! empty($_POST['post_comment_status']) && isset($_POST['post_title']) && isset($_POST['post_content'])) // Required fields are set? { // Generating a user-friendly URL $_POST['post_url'] = strip_tags($_POST['post_title']); $_POST['post_url'] = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '---$1---', $_POST['post_url']); $_POST['post_url'] = str_replace('%', '', $_POST['post_url']); $_POST['post_url'] = preg_replace('|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $_POST['post_url']); $_POST['post_url'] = strtolower($_POST['post_url']); $_POST['post_url'] = preg_replace('/&.+?;/', '', $_POST['post_url']); // kill entities $_POST['post_url'] = preg_replace('/[^%a-z0-9 _-]/', '', $_POST['post_url']); $_POST['post_url'] = preg_replace('/\s+/', '-', $_POST['post_url']); $_POST['post_url'] = preg_replace('|-+|', '-', $_POST['post_url']); $_POST['post_url'] = trim($_POST['post_url'], '-'); // Same post title twice? $Double = $DB->query_num_rowsDB(" SELECT id FROM ot_posts WHERE post_url = '" . addslashes($_POST['post_url']) . "' "); // Check in DB if($Double > 0) // Double? { $_POST['post_url'] = $_POST['post_url'] . "-" . ($Double + 1); // Add number at the end } // Check if user is allow to publish if( ! (defined("USER_LEVEL_ADMINISTRATOR") OR defined("USER_LEVEL_EDITOR")) && ($_POST['post_status'] == "gepubliceerd")) { $_POST['post_status'] = "klad"; } // We'll update the post in DB $DB->query_execDB(" UPDATE ot_posts SET post_title = '" . addslashes($_POST['post_title']) . "', post_content = '" . addslashes($_POST['post_content']) . "', post_modified = NOW(), post_url = '" . $_POST['post_url'] . "', post_status = '" . addslashes($_POST['post_status']) . "', post_comment_status = '" . addslashes($_POST['post_comment_status']) . "' WHERE id = '" . $_GET['post'] . "' LIMIT 1 "); // Now we attach a category $Categories = $DB->query_fetchDB(" SELECT id FROM ot_categories ORDER BY id DESC "); if($Categories) // Are there categories? { for($i = 0; $i < count($Categories); $i++) { $Exist = $DB->query_fetchDB(" SELECT id FROM ot_post2category WHERE post_id = '" . $_GET['post'] . "' && category_id = '" . $Categories[$i]['id'] . "' ORDER BY id DESC LIMIT 1 "); if($Exist) { if( ! isset($_POST['post_category_' . $Categories[$i]['id']])) // This category? { $DB->query_execDB(" DELETE FROM ot_post2category WHERE id = '" . $Exist['0']['id'] . "' LIMIT 1 "); // Delete link } } else { if(isset($_POST['post_category_' . $Categories[$i]['id']])) // This category? { $DB->query_execDB(" INSERT INTO ot_post2category SET id = 'NULL', post_id = '" . $_GET['post'] . "', category_id = '" . $Categories[$i]['id'] . "' "); // Link post to category } } } } // Everything update, let's edit again ! header("Location: post-edit.php?post=" . $_GET['post']); } else { header("Location: err-403.php"); // Error } } $PageTitle = " » Schrijven » Bericht bewerken"; // Set page title include("admin-header.php"); // Load header ?>