56 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
use Nickyeoman\Validation;
 | 
						|
$v = new Nickyeoman\Validation\Validate();
 | 
						|
 | 
						|
$url_success = '/dashboard';
 | 
						|
$url_error = '/novaconium/page/edit/' . $post->get('id'); // Redirect back to the page edit form on error
 | 
						|
 | 
						|
if ( empty($session->get('username'))) {
 | 
						|
    $redirect->url('/novaconium/login');
 | 
						|
    $messages->error('You are not loggedin');
 | 
						|
    makeitso();
 | 
						|
}
 | 
						|
 | 
						|
// Check Token
 | 
						|
if ($session->get('token') != $post->get('token')) {
 | 
						|
    $redirect->url('/novaconium/pages');
 | 
						|
    $messages->error('Invalid Token');
 | 
						|
    makeitso();
 | 
						|
}
 | 
						|
 | 
						|
$id = $post->get('id');
 | 
						|
$slug = $post->get('slug');
 | 
						|
$title = $_POST['title'];
 | 
						|
$body = $_POST['body']; // We want it dirty
 | 
						|
$intro = $_POST['intro']; // We want it dirty
 | 
						|
 | 
						|
if ( empty( $post->get('draft') ) ) {
 | 
						|
    $draft = 0;
 | 
						|
} else {
 | 
						|
    $draft = 1;
 | 
						|
}
 | 
						|
 | 
						|
if ( empty($id) || empty($slug) || empty($body) ) {
 | 
						|
    $messages->error('One of the fields was empty.');
 | 
						|
    $redirect->url($url_fail);
 | 
						|
    makeitso();
 | 
						|
}
 | 
						|
 | 
						|
try {
 | 
						|
 | 
						|
    $query = "UPDATE `pages` SET `title` = ?, `slug` = ?, `body` = ?, `intro` = ?, `draft` = ?, `updated` = NOW() WHERE `id` = ?";
 | 
						|
    $params = [$title, $slug, $body, $intro, $draft, $id];
 | 
						|
    
 | 
						|
    $db->query($query, $params);
 | 
						|
 | 
						|
    $messages->notice('Page Saved');
 | 
						|
 | 
						|
} catch (Exception $e) {
 | 
						|
 | 
						|
    $messages->notice($e->getMessage());
 | 
						|
    
 | 
						|
}
 | 
						|
 | 
						|
$redirect->url('/novaconium/page/edit/' . $id);
 |