Example #1
0
 /**
  * edit a category
  * @return bool|string
  */
 public static function edit()
 {
     self::$infos['id'] = $_POST['id'];
     if (isset($_POST['edit'])) {
         if ($_POST['name'] !== '' && $_POST['id'] !== '') {
             $name = Helper::filter($_POST['name']);
             $id = Helper::filter($_POST['id']);
             return Model::update('categories', ['name' => $name], $id);
         } else {
             return self::$messages[] = "All fields are required !";
         }
     } else {
         return self::$messages[] = "You should click on edit botton";
     }
 }
Example #2
0
 /**
  * edit a post
  * @return bool|string
  */
 public static function edit()
 {
     self::$infos['id'] = $_POST['id'];
     if (isset($_POST['edit'])) {
         if ($_POST['title'] !== '' && $_POST['content'] !== '' && $_POST['category'] !== '' && $_POST['id'] !== '') {
             $title = Helper::filter($_POST['title']);
             $content = Helper::filter($_POST['content']);
             $category = Helper::filter($_POST['category']);
             $id = Helper::filter($_POST['id']);
             return Model::update('posts', ['title' => $title, 'content' => $content, 'category_id' => $category], $id);
         } else {
             return self::$messages[] = "All fields are required !";
         }
     } else {
         return self::$messages[] = "You should click on edit botton";
     }
 }
Example #3
0
<?php

require APP_PATH . "/tpls/header.php";
?>
<!-- Start container -->
<div class="container">
    <h1>Add category</h1>
    <?php 
$categories = \App\Lib\Model::getAllFrom('categories');
?>
    <form action="<?php 
echo $this->url('categories/save');
?>
" method="POST" enctype="application/x-www-form-urlencoded" class="form-group">
        <label for="name">Name :</label>
        <input type="text" id="name" class="form-control" name="name" value="<?php 
echo isset($this->session->name) ? $this->session->title : '';
?>
" placeholder="Enter the title" required>
        <button class="btn btn-primary" name="save"><i class="fa fa-plus"></i> Add</button>
    </form>
</div>
<!-- End container -->
<?php 
require APP_PATH . "/tpls/footer.php";
Example #4
0
 /**
  * Delete post
  */
 public function delete()
 {
     if (isset($_SESSION['login']) && $_SESSION['login'] === true) {
         if (is_array(func_get_args())) {
             if (is_array(func_get_args()[0])) {
                 $id = func_get_args()[0][0];
                 if (preg_match('/[0-9]+$/', $id, $match)) {
                     if (Model::delete('posts', $match[0])) {
                         $this->redirectTo('posts/index');
                     }
                 }
             }
         }
         return $this->redirectTo('posts/index');
     } else {
         return $this->redirectTo('posts/index');
     }
 }
Example #5
0
// Rquire composer autoload class
// With this class we don't need to build a custome Autoloader class
require '../vendor/autoload.php';
// Application configurations
require 'config.php';
// ( development OR production ) mode
// If the argument passed is true so all errors are displayed off
// If the argument passed is false so all errors are displayed on
$mode = isProductionMode(false);
// Registry Design pattern
// And Singletoone Design pattern
// Application class
$app = \App\Lib\App::getInstance();
// Dependency injection design pattern
// Inject the PDO object in the model class
\App\Lib\Model::setPDO(\App\Lib\PdoFactory::mySqlConnection());
/**
|========================================================
|                  Main Classes
|========================================================
*/
// Router's object
$router = $app->set('router', 'App\\Lib\\Router');
// Controller's object
$controller = $app->set('controller', 'App\\Lib\\Controller');
// Active Record design pattern
// Model's object
$model = $app->set('model', 'App\\Lib\\Model');
/**
|========================================================
|                  Controllers
Example #6
0
<?php

$categories = \App\Lib\Model::getAllFrom('categories');
$posts = \App\Lib\Model::getAllFrom('posts');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>SimpleBlog</title>
    <!-- Style sheet files -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/3.0.3/normalize.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="<?php 
echo BASE_URL;
?>
css/style.css">

</head>
<body>
<!-- Static navbar -->
<nav class="navbar navbar-default navbar-static-top" role="navigation">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
Example #7
0
 /**
  * Login the user
  * @return bool
  */
 public static function login()
 {
     if (isset($_POST['submit']) && !empty($_POST['email']) && !empty($_POST['password'])) {
         $password = sha1($_POST['email'] . $_POST['password'] . SAULT);
         $email = $_POST['email'];
         $user = Model::findFromBy('users', ['email' => $email, 'password' => $password]);
         if ($user !== false) {
             $_SESSION['login'] = true;
             $_SESSION['email'] = $user['email'];
             $_SESSION['is_admin'] = $user['is_admin'];
             return true;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }