Mini Shell
<!DOCTYPE html>
<html lang="en">
<head>
<?php include('include/head_admin.php');
$page_id = '7';
$title = '';
$short_description = '';
$image = '';
$image_alt_tag = '';
$description = '';
$url = '';
$meta_title = '';
$meta_description = '';
if (isset($_GET['id']) && $_GET['id'] != '') {
$id = get_safe_value($con, $_GET['id']);
$image_required = '';
$res = mysqli_query($con, "select * from blogs where id='$id'");
$check = mysqli_num_rows($res);
if ($check > 0) {
$row = mysqli_fetch_assoc($res);
$title = $row['title'];
$short_description = $row['short_description'];
$image = $row['image'];
$image_alt_tag = $row['image_alt_tag'];
$description = $row['description'];
$url = $row['url'];
$meta_title = $row['meta_title'];
$meta_description = $row['meta_description'];
} else {
header('location:blog-all.php');
die();
}
}
if (isset($_POST['submit_blog'])) {
// prx($_POST);
$title = get_safe_value($con, $_POST['title']);
$short_description = get_safe_value($con, $_POST['short_description']);
$image_alt_tag = get_safe_value($con, $_POST['image_alt_tag']);
$description = get_safe_value($con, $_POST['description']);
$url = generate_seo_friendly_title($title);
$meta_title = get_safe_value($con, $_POST['meta_title']);
$meta_description = get_safe_value($con, $_POST['meta_description']);
if (isset($_GET['id']) && $_GET['id'] == 0) {
if ($_FILES['image']['type'] != 'image/png' && $_FILES['image']['type'] != 'image/jpg' && $_FILES['image']['type'] != 'image/jpeg' && $_FILES['image']['type'] != 'image/webp') {
$msg = "Please select only png, jpg, webp and jpeg image format";
}
} else {
if ($_FILES['image']['type'] != '') {
if ($_FILES['image']['type'] != 'image/png' && $_FILES['image']['type'] != 'image/jpg' && $_FILES['image']['type'] != 'image/jpeg' && $_FILES['image']['type'] != 'image/jpeg') {
$msg = "Please select only png, jpg, webp and jpeg image format";
}
}
}
$msg = "";
if ($msg == '') {
if (isset($_GET['id']) && $_GET['id'] != '') {
if ($_FILES['image']['name'] != '') {
$image = $_FILES['image']['name'];
move_uploaded_file($_FILES['image']['tmp_name'], "../media/blogs/" . $image);
mysqli_query($con, "UPDATE `blogs` SET `title`='$title',`short_description`='$short_description', `image`='$image',`image_alt_tag`='$image_alt_tag',`description`='$description', `url`='$url',`meta_title`='$meta_title',`meta_description`='$meta_description' WHERE `id`='$id'");
} else {
$update_query = "UPDATE `blogs` SET `title`='$title',`short_description`='$short_description', `image`='$image',`image_alt_tag`='$image_alt_tag',`description`='$description',`url`='$url',`meta_title`='$meta_title',`meta_description`='$meta_description' WHERE `id`='$id'";
mysqli_query($con, $update_query);
}
} else {
$image = rand(111111111, 999999999) . '_' . $_FILES['image']['name'];
move_uploaded_file($_FILES['image']['tmp_name'], "../media/blogs/" . $image);
$insert_query = "INSERT INTO `blogs`(`title`, `short_description`, `image`,`image_alt_tag`, `description`, `url`, `meta_title`,`meta_description`)
VALUES ('$title','$short_description', '$image','$image_alt_tag','$description','$url', '$meta_title','$meta_description')";
mysqli_query($con, $insert_query);
print_r($insert_query);
}
header('location:blog-all.php');
die();
}
}
function generate_seo_friendly_title($title)
{
// Convert the title to lowercase
$title = strtolower($title);
// Replace spaces with dashes
$title = str_replace(' ', '-', $title);
// Remove special characters
$title = preg_replace('/[^A-Za-z0-9\-]/', '', $title);
return $title;
}
?>
</head>
<body>
<!--== MAIN CONTRAINER ==-->
<?php include('include/header_admin.php'); ?>
<!--== BODY CONTNAINER ==-->
<div class="container-fluid sb2">
<div class="row">
<?php include('include/sidebar_admin.php'); ?>
<div class="sb2-2">
<div class="sb2-2-2">
<ul>
<li><a href="index.php"><i class="fa fa-home" aria-hidden="true"></i> Home</a>
</li>
<li class="active-bre"><a href="#"> Add New Post</a>
</li>
<!-- <li class="page-back"><a href="index.php"><i class="fa fa-backward" aria-hidden="true"></i> Back</a>
</li> -->
</ul>
</div>
<div class="sb2-2-add-blog sb2-2-1">
<div class="box-inn-sp">
<div class="inn-title">
<h4>Add New Post</h4>
<!-- <p>Airtport Hotels The Right Way To Start A Short Break Holiday</p> -->
</div>
<div class="bor">
<form method="post" enctype="multipart/form-data">
<div class="row">
<div class="input-field col s12">
<input id="title" type="text" name="title" class="validate" value="<?php echo $title ?>" required>
<label for="title">Blog Title</label>
</div>
<!-- <div class="input-field col s12">
<input id="url" type="text" name="url" class="validate" value="<?php echo $url ?>" required>
<label for="url">Blog Url</label>
</div> -->
<div class="input-field col s12">
<input id="short_description" type="text" name="short_description" class="validate" value="<?php echo $short_description ?>" required>
<label for="short_description">Blog Short Description</label>
</div>
<div class="input-field col s12">
<div class="file-field">
<div class="btn">
<span>File</span>
<input type="file" name="image" value="<?php echo $image ?>">
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text" name="image" placeholder="Upload Blog Banner" value="<?php echo $image ?>">
</div>
</div>
<?php
if ($image != '') {
echo "<a target='_blank' href='" . "../media/blogs/" . $image . "'><img width='150px' src='" . "../media/blogs/" . $image . "'/></a>";
}
?>
</div>
<div class="input-field col s12">
<input id="image_alt_tag" type="text" name="image_alt_tag" class="validate" value="<?php echo $image_alt_tag ?>" required>
<label for="image_alt_tag">Image Alt Text</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<textarea id="editor" name="description"><?php echo $description ?></textarea>
<!-- <label>Blog Descriptions:</label> -->
</div>
</div>
<!-- <div class="row">
<div class="input-field col s12">
<select multiple>
<option value="" disabled selected>Choose Category</option>
<option value="1">Hotels</option>
<option value="2">Educations</option>
<option value="3">Medical</option>
<option value="3">Health</option>
<option value="3">Fitness</option>
<option value="3">Tution</option>
<option value="3">Software</option>
<option value="3">Wedding</option>
<option value="3">Party</option>
<option value="3">Spa/Club</option>
</select>
<label>Select Category</label>
</div>
<div class="input-field col s12">
<select multiple>
<option value="" disabled selected>Choose Category</option>
<option value="1">Hotels</option>
<option value="2">Educations</option>
<option value="3">Medical</option>
<option value="3">Health</option>
<option value="3">Fitness</option>
<option value="3">Tution</option>
<option value="3">Software</option>
<option value="3">Wedding</option>
<option value="3">Party</option>
<option value="3">Spa/Club</option>
</select>
<label>Select Sub Category</label>
</div>
</div> -->
<div class="row">
<div class="input-field col s12">
<input id="meta_title" type="text" name="meta_title" class="validate" value="<?php echo $meta_title ?>" required>
<label for="meta_title">Meta Title</label>
</div>
<div class="input-field col s12">
<input id="meta_description" type="text" name="meta_description" class="validate" value="<?php echo $meta_description ?>" required>
<label for="meta_description">Meta Description</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input type="submit" name="submit_blog" class="waves-effect waves-light btn-large" value="Submit">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
<?php include('include/footer_admin.php'); ?>
<?php include('include/foot_admin.php'); ?>
</body>
</html>