Skip to content
This repository was archived by the owner on Feb 18, 2023. It is now read-only.

Commit 6e3fb93

Browse files
first
0 parents  commit 6e3fb93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+3873
-0
lines changed

.htaccess

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<IfModule mod_rewrite.c>
2+
RewriteEngine On
3+
RewriteRule ^$ public/ [L]
4+
RewriteRule (.*) public/$1 [L]
5+
</IfModule>

app/config/config.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
define('APP_URL', '/blog/');
3+
define('CORE', 'core/');
4+
define('HASH_GENERAL_KEY', 'hash_general_key');
5+
define('HASH_PASSWORD_KEY', 'hash_password_key');
6+
7+
8+
error_reporting(E_ALL);

app/config/database.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
define('DB_TYPE', 'mysql');
3+
define('DB_HOST', 'localhost');
4+
define('DB_USER', 'root');
5+
define('DB_PASS', '');
6+
define('DB_NAME', 'news');

app/controllers/admin.php

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
<?php
2+
class admin extends Controller
3+
{
4+
function __construct()
5+
{
6+
if (!isset($_SESSION['logged_in'])) {
7+
header("location: " . APP_URL . "user/login");
8+
}
9+
}
10+
public function index()
11+
{
12+
$data['judul'] = 'Admoon';
13+
$data['cat'] = $this->model('_cat')->numberCategory();
14+
$data['post'] = $this->model('_post')->numberPost();
15+
$this->view('admin/_layout/header', $data);
16+
$this->view('admin/index', $data);
17+
$this->view('admin/_layout/footer');
18+
}
19+
public function setting()
20+
{
21+
$data['judul'] = 'Admoon';
22+
$data['sett'] = $this->model('_sett')->getSetting();
23+
$this->view('admin/_layout/header', $data);
24+
$this->view('admin/setting', $data);
25+
$this->view('admin/_layout/footer');
26+
if (count($_POST)) {
27+
$sett = array(
28+
'title' => $_POST['title'],
29+
'jumbotron' => $_POST['jumbotron'],
30+
'page' => $_POST['page']
31+
);
32+
$result = $this->model('_sett')->updateSetting($sett);
33+
if ($result) {
34+
Flasher::setMessage('Berhasil', 'update', 'blue');
35+
header('location: ' . APP_URL . 'admin/setting');
36+
exit;
37+
} else {
38+
Flasher::setMessage('Gagal', 'update', 'red');
39+
header('location: ' . APP_URL . 'admin/setting');
40+
exit;
41+
}
42+
}
43+
}
44+
45+
public function post()
46+
{
47+
$data['judul'] = 'Berita ';
48+
$data['post'] = $this->model('_post')->getAllPost();
49+
$this->view('admin/_layout/header', $data);
50+
$this->view('admin/post/index', $data);
51+
$this->view('admin/_layout/footer');
52+
}
53+
public function createpost()
54+
{
55+
$data['judul'] = 'Buat Berita';
56+
$data['category'] = $this->model('_cat')->getAllCat();
57+
$this->view('admin/_layout/header', $data);
58+
$this->view('admin/post/create', $data);
59+
$this->view('admin/_layout/footer');
60+
if (count($_POST)) {
61+
$thumb = strtoupper(substr($_FILES['thumbnail']['name'], 0, 2)) . strtotime("now") . '.' . pathinfo($_FILES['thumbnail']['name'], PATHINFO_EXTENSION);
62+
$post = array(
63+
'post_name' => $_POST['post_name'],
64+
'slug' => strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $_POST['post_name']))),
65+
'thumbnail' => $thumb,
66+
'text' => $_POST['text'],
67+
'active' => $_POST['active'],
68+
'category_name' => $_POST['category_name'],
69+
'penulis' => $_SESSION['user_name']
70+
);
71+
$result = $this->model('_post')->createPost($post);
72+
$upload = move_uploaded_file($_FILES['thumbnail']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . "/" . APP_URL . "/public/image/" . $thumb);
73+
if ($result && $upload) {
74+
Flasher::setMessage('Berhasil', 'tambah', 'blue');
75+
header('location: ' . APP_URL . 'admin/post');
76+
exit;
77+
} else {
78+
Flasher::setMessage('Gagal', 'tambah', 'red');
79+
header('location: ' . APP_URL . 'admin/post');
80+
exit;
81+
}
82+
}
83+
}
84+
public function editpost($id = "")
85+
{
86+
$data['judul'] = 'Edit Berita';
87+
$data['post'] = $this->model('_post')->getPostbyId($id);
88+
$data['category'] = $this->model('_cat')->getAllCat();
89+
$this->view('admin/_layout/header', $data);
90+
$this->view('admin/post/edit', $data);
91+
$this->view('admin/_layout/footer');
92+
if (empty($data['post'])) {
93+
header("location: " . APP_URL . "errors");
94+
}
95+
96+
if (count($_POST)) {
97+
if ($_FILES["thumbnail_new"]["name"]) {
98+
$data = $this->model('_post')->getPostbyId($id);
99+
$thumb = strtoupper(substr($_FILES['thumbnail_new']['name'], 0, 2)) . strtotime("now") . '.' . pathinfo($_FILES['thumbnail_new']['name'], PATHINFO_EXTENSION);
100+
$upload = move_uploaded_file($_FILES['thumbnail_new']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . "/" . APP_URL . "/public/image/" . $thumb);
101+
$unlink = unlink($_SERVER["DOCUMENT_ROOT"] . "/" . APP_URL . '/public/image/' . $data['thumbnail']);
102+
if ($upload && $unlink) {
103+
$post = array(
104+
'post_name' => $_POST['post_name'],
105+
'slug' => strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $_POST['post_name']))),
106+
'thumbnail' => $thumb,
107+
'text' => $_POST['text'],
108+
'active' => $_POST['active'],
109+
'category_name' => $_POST['category_name'],
110+
'penulis' => $_SESSION['user_name']
111+
);
112+
}
113+
} else {
114+
$post = array(
115+
'post_name' => $_POST['post_name'],
116+
'slug' => strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $_POST['post_name']))),
117+
'text' => $_POST['text'],
118+
'active' => $_POST['active'],
119+
'category_name' => $_POST['category_name'],
120+
'penulis' => $_SESSION['user_name']
121+
);
122+
}
123+
$update = $this->model('_post')->updateDataPost($post, $id);
124+
if ($update) {
125+
Flasher::setMessage('Berhasil', 'update', 'blue');
126+
header('location: ' . APP_URL . 'admin/post');
127+
exit;
128+
} else {
129+
Flasher::setMessage('Gagal', 'update', 'red');
130+
header('location: ' . APP_URL . 'admin/post');
131+
exit;
132+
}
133+
}
134+
}
135+
136+
public function deletepost($id)
137+
{
138+
$data = $this->model('_post')->getPostbyId($id);
139+
$unlink = unlink($_SERVER["DOCUMENT_ROOT"] . "/" . APP_URL . '/public/image/' . $data['thumbnail']);
140+
$success = $this->model('_post')->deleteDataPost($id);
141+
if ($success && $unlink) {
142+
Flasher::setMessage('Berhasil', 'dihapus', 'blue');
143+
header('location: ' . APP_URL . 'admin/post');
144+
exit;
145+
} else {
146+
Flasher::setMessage('gambar', 'hapus', 'red');
147+
header('location: ' . APP_URL . 'admin/post');
148+
exit;
149+
}
150+
}
151+
152+
public function category()
153+
{
154+
$data['judul'] = 'Category';
155+
$data['cat'] = $this->model('_cat')->getAllCat();
156+
$this->view('admin/_layout/header', $data);
157+
$this->view('admin/category/index', $data);
158+
$this->view('admin/_layout/footer');
159+
}
160+
public function createcategory()
161+
{
162+
$data['judul'] = 'Buat Category';
163+
$this->view('admin/_layout/header', $data);
164+
$this->view('admin/category/create', $data);
165+
$this->view('admin/_layout/footer');
166+
if (count($_POST)) {
167+
$category = array(
168+
'category_name' => $_POST['category_name'],
169+
'slug' => strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $_POST['category_name']))),
170+
);
171+
if ($this->model('_cat')->addDataCat($category)) {
172+
Flasher::setMessage('Berhasil', 'tambah', 'blue');
173+
header('location: ' . APP_URL . 'admin/category');
174+
exit;
175+
} else {
176+
Flasher::setMessage('Gagal', 'tambah', 'red');
177+
header('location: ' . APP_URL . 'admin/category');
178+
exit;
179+
}
180+
}
181+
}
182+
public function deletecategory($id)
183+
{
184+
if (!empty($id)) {
185+
$result = $this->model('_cat')->deleteDataCat($id);
186+
if ($result) {
187+
Flasher::setMessage('Berhasil', 'Hapus', 'blue');
188+
header('location: ' . APP_URL . 'admin/category');
189+
exit;
190+
} else {
191+
Flasher::setMessage('Gagal', 'hapus', 'red');
192+
header('location: ' . APP_URL . 'admin/category');
193+
exit;
194+
}
195+
}
196+
}
197+
}

app/controllers/errors.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
class errors extends Controller {
3+
4+
function index() {
5+
$data['judul'] = 404;
6+
$this->view('home/_layout/header',$data);
7+
$this->view('home/404');
8+
$this->view('home/_layout/footer');
9+
}
10+
11+
}

app/controllers/home.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
class home extends Controller
4+
{
5+
public function index()
6+
{
7+
$data['sett'] = $this->model('_sett')->getSetting();
8+
$data['page'] = 1;
9+
$limit = $data['sett']['page'];
10+
$num_rows = $this->model('_post')->numberPost();
11+
$limit_start = ($data['page'] - 1) * $limit;
12+
$data['jumlah_page'] = ceil($num_rows / $limit);
13+
$data['jumlah_number'] = 3;
14+
$data['start_number'] = ($data['page'] > $data['jumlah_number'])? $data['page'] - $data['jumlah_number'] : 1; // Untuk awal link number
15+
$data['end_number'] = ($data['page'] < ($data['jumlah_page'] - $data['jumlah_number']))? $data['page'] + $data['jumlah_number'] : $data['jumlah_page'];
16+
$data['post'] = $this->model('_post')->getAllPostHome($limit_start,$limit);
17+
$this->view('home/_layout/header', $data);
18+
$this->view('home/index', $data);
19+
$this->view('home/_layout/footer');
20+
}
21+
}

app/controllers/page.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
class page extends Controller
3+
{
4+
public function index($id = '')
5+
{
6+
if (empty($id)) {
7+
header("location: " . APP_URL . "errors");
8+
}
9+
$data['sett'] = $this->model('_sett')->getSetting();
10+
$limit = $data['sett']['page'];
11+
$num_rows = $this->model('_post')->numberPost();
12+
$limit_start = ($id - 1) * $limit;
13+
14+
$data['page'] = $id;
15+
$data['jumlah_page'] = ceil($num_rows / $limit);
16+
$data['jumlah_number'] = 3;
17+
$data['start_number'] = ($data['page'] > $data['jumlah_number']) ? $data['page'] - $data['jumlah_number'] : 1;
18+
$data['end_number'] = ($data['page'] < ($data['jumlah_page'] - $data['jumlah_number'])) ? $data['page'] + $data['jumlah_number'] : $data['jumlah_page'];
19+
$data['post'] = $this->model('_post')->getAllPostHome($limit_start, $limit);
20+
$this->view('home/_layout/header', $data);
21+
$this->view('home/index', $data);
22+
$this->view('home/_layout/footer');
23+
}
24+
}

app/controllers/read.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
<?php
3+
class read extends Controller
4+
{
5+
6+
public function index($id = '')
7+
{
8+
$data['post'] = $this->model('_post')->getPostbySlug($id);
9+
$data['category'] = $this->model('_cat')->getAllCat();
10+
$data['sett'] = $this->model('_sett')->getSetting();
11+
$this->view('home/_layout/header', $data);
12+
$this->view('home/detail', $data);
13+
$this->view('home/_layout/footer');
14+
if (empty($data['post'])) {
15+
header("location: " . APP_URL . "errors");
16+
}
17+
}
18+
}

app/controllers/user.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
class user extends Controller
3+
{
4+
public function login()
5+
{
6+
$data['title'] = 'Login';
7+
if (count($_POST)) {
8+
$result = $this->model('_user')->login();
9+
if ($result) {
10+
header("location: " . APP_URL . "admin");
11+
} else {
12+
Flasher::setMessage('Gagal', 'login', 'red');
13+
header('location: ' . APP_URL . 'user/login');
14+
exit;
15+
}
16+
}
17+
$this->view('auth/login');
18+
}
19+
public function logout() {
20+
if(!isset($_SESSION['logged_in'])) Session::init ();
21+
Session::destroy();
22+
header("location: " . APP_URL);
23+
}
24+
}

app/core/Bootstrap.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
class Bootstrap
4+
{
5+
protected $controller = 'home';
6+
protected $error = 'errors';
7+
protected $detail = 'detail';
8+
protected $method = 'index';
9+
protected $params = [];
10+
11+
public function __construct()
12+
{
13+
$url = $this->parseURL();
14+
15+
// controller
16+
if (empty($url[0])) {
17+
require_once "../app/controllers/" . $this->controller . ".php";
18+
$this->controller = $this->controller;
19+
} else {
20+
if (file_exists("../app/controllers/" . $url[0] . ".php")) {
21+
$this->controller = $url[0];
22+
unset($url[0]);
23+
}else{
24+
$this->controller = $this->error;
25+
}
26+
}
27+
// Include controller
28+
require_once "../app/controllers/" . $this->controller . ".php";
29+
// Instantiate controller
30+
$this->controller = new $this->controller;
31+
// method
32+
if (isset($url[1])) {
33+
if (method_exists($this->controller, $url[1])) {
34+
$this->method = $url[1];
35+
unset($url[1]);
36+
}
37+
}
38+
39+
// params
40+
if (!empty($url)) {
41+
$this->params = array_values($url);
42+
}
43+
44+
// jalankan controller & method, serta kirimkan params jika ada
45+
call_user_func_array([$this->controller, $this->method], $this->params);
46+
}
47+
48+
public function parseURL()
49+
{
50+
if (isset($_GET['url'])) {
51+
$url = rtrim($_GET['url'], '/');
52+
$url = filter_var($url, FILTER_SANITIZE_URL);
53+
$url = explode('/', $url);
54+
return $url;
55+
}
56+
}
57+
}
58+
59+

0 commit comments

Comments
 (0)