Skip to content

Commit caf6063

Browse files
committed
spring cleaning & refactoring, #2, #4, #5, #8
1 parent a5df14a commit caf6063

Some content is hidden

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

80 files changed

+1772
-970
lines changed

app/config.ini

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
[globals]
22

3-
; prefix all your db table names to avoid conflict
4-
; with other apps that are using the same database
5-
db_table_prefix = fblg_
6-
7-
; use 'md5' for PHP < 5.3.7 and 'bcrypt' for best security
8-
password_hash_engine = md5
9-
password_md5_salt = jK$N!Lx5
10-
11-
; 'summernote'
12-
text_editor = sommernote
13-
143
;##########################
15-
; additional system config
16-
4+
; general settings
175
AUTOLOAD = app/;app/inc/
186
UI = ui/
197
BACKEND_UI = app/ui/
208
UPLOADS = res/
9+
LOCALES = app/dict/
10+
# overwrite auto-detection of language
11+
;LANGUAGE=de-DE
2112

13+
DEV = true
2214
DEBUG = 2
2315
CACHE = false
2416
TZ = Europe/Berlin
25-
; CORTEX.smartLoading = false
17+
18+
ONERROR = \Error->render
19+
20+
;##########################
21+
; additional app config
22+
23+
; prefix all your db table names to avoid conflict
24+
; with other apps that are using the same database
25+
db_table_prefix = fblg_
26+
27+
; use 'md5' for PHP < 5.3.7 and 'bcrypt' for best security
28+
password_hash_engine = md5
29+
password_md5_salt = jK$N!Lx5
30+
31+
; 'summernote'
32+
text_editor = sommernote

app/controller/auth.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ class Auth extends Base {
88
protected
99
$response;
1010

11+
/**
12+
* init the View
13+
*/
14+
public function beforeroute() {
15+
$this->response = new \View\Backend();
16+
}
17+
1118
/**
1219
* check login state
1320
* @return bool
@@ -51,7 +58,7 @@ public function login($f3,$params) {
5158
else $f3->reroute('/admin');
5259
}
5360
}
54-
\FlashMessage::instance()->addMessage('Wrong Username/Password', 'danger');
61+
\Flash::instance()->addMessage('Wrong Username/Password', 'danger');
5562
}
5663
$this->response->setTemplate('templates/login.html');
5764
}

app/controller/backend.php

+28-15
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@
55

66
class Backend extends Base {
77

8+
/** @var \Controller\Base */
9+
protected $module;
10+
11+
/**
12+
* init the backend view, so the module controller can care about it
13+
*/
14+
public function beforeroute() {
15+
$module_name = \Base::instance()->get('PARAMS.module');
16+
$this->response = new \View\Backend();
17+
$this->response->data['LAYOUT'] = $module_name.'_layout.html';
18+
$this->module = $this->loadModule($module_name);
19+
$this->module->setView($this->response);
20+
}
21+
22+
/**
23+
* load module controller class
24+
* @param $name
25+
* @return bool
26+
*/
827
protected function loadModule($name) {
928
$class = '\Controller\\'.ucfirst($name);
1029
if(!class_exists($class)) {
@@ -16,26 +35,20 @@ protected function loadModule($name) {
1635
}
1736

1837
/**
19-
* create a response that displays a list of module records
38+
* pass method calls to module
39+
* @param $name
40+
* @param $args
41+
* @return mixed
2042
*/
21-
public function getList($f3,$params) {
22-
$module = $this->loadModule($params['module']);
23-
$module->setView($this->response);
24-
$module->getList($f3,$params);
25-
$this->response->data['SUBPART'] = $params['module'].'_list.html';
26-
$this->response->data['LAYOUT'] = $params['module'].'_layout.html';
43+
public function __call($name,$args) {
44+
return call_user_func_array(array($this->module,$name),$args);
2745
}
2846

2947
/**
30-
* return an create/edit form for a given module
48+
* give the module control about the view
3149
*/
32-
public function getSingle($f3,$params) {
33-
$module = $this->loadModule($params['module']);
34-
$module->setView($this->response);
35-
$module->getSingle($f3, $params);
36-
$this->response->data['SUBPART'] = $params['module'].'_edit.html';
37-
$this->response->data['LAYOUT'] = $params['module'].'_layout.html';
50+
public function afterroute() {
51+
$this->module->afterroute();
3852
}
3953

40-
4154
}

app/controller/base.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ public function setView(\View\Base $view) {
1919
* init the View
2020
*/
2121
public function beforeroute() {
22-
$this->response = \View\Backend::instance();
22+
$this->response = new \View\Frontend();
2323
}
2424

2525
/**
26-
* kick start the View, which finally creates the response
27-
* based on our previously set content data
26+
* kick start the View, which creates the response
27+
* based on our previously set content data.
28+
* finally echo the response or overwrite this method
29+
* and do something else with it.
30+
* @return string
2831
*/
2932
public function afterroute() {
3033
if (!$this->response)

app/controller/comment.php

+35-19
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,66 @@
44

55
class Comment extends Resource {
66

7-
public function __construct()
8-
{
7+
public function __construct() {
98
$mapper = new \Model\Comment();
109
parent::__construct($mapper);
1110
}
1211

13-
public function approve($f3,$params)
14-
{
12+
public function beforeroute() {
13+
$this->response = new \View\Backend();
14+
$this->response->data['LAYOUT'] = 'comment_layout.html';
15+
}
16+
17+
/**
18+
* @param \Base $f3
19+
* @param $params
20+
*/
21+
public function approve(\Base $f3, $params) {
1522
if($this->resource->updateProperty(array('_id = ?', $params['id']),'approved',1)) {
16-
\FlashMessage::instance()->addMessage('Comment approved', 'success');
23+
\Flash::instance()->addMessage('Comment approved', 'success');
1724
} else {
18-
\FlashMessage::instance()->addMessage('Unknown Comment ID', 'danger');
25+
\Flash::instance()->addMessage('Unknown Comment ID', 'danger');
1926
}
2027
$f3->reroute($f3->get('SESSION.LastPageURL'));
2128
}
2229

23-
public function reject($f3,$params)
24-
{
30+
/**
31+
* @param \Base $f3
32+
* @param $params
33+
*/
34+
public function reject(\Base $f3, $params) {
2535
if ($this->resource->updateProperty(array('_id = ?', $params['id']), 'approved', 2)) {
26-
\FlashMessage::instance()->addMessage('Comment rejected', 'success');
36+
\Flash::instance()->addMessage('Comment rejected', 'success');
2737
} else {
28-
\FlashMessage::instance()->addMessage('Unknown Comment ID', 'danger');
38+
\Flash::instance()->addMessage('Unknown Comment ID', 'danger');
2939
}
3040
$f3->reroute($f3->get('SESSION.LastPageURL'));
3141
}
3242

33-
public function getSingle($f3,$params)
34-
{
43+
/**
44+
* @param \Base $f3
45+
* @param array $params
46+
* @return bool
47+
*/
48+
public function getSingle(\Base $f3,$params) {
49+
$this->response->data['SUBPART'] = 'comment_edit.html';
50+
3551
if (isset($params['id'])) {
36-
$this->response->data['content'] = $this->resource->load(array('_id = ?',$params['id']));
52+
$this->response->data['comment'] = $this->resource->load(array('_id = ?',$params['id']));
3753
if(!$this->resource->dry())
3854
return true;
3955
}
40-
\FlashMessage::instance()->addMessage('Unknown Comment ID', 'danger');
56+
\Flash::instance()->addMessage('Unknown Comment ID', 'danger');
4157
$f3->reroute($f3->get('SESSION.LastPageURL'));
4258
}
4359

4460
/**
4561
* display list of comments
62+
* @param \Base $f3
63+
* @param array $params
4664
*/
47-
public function getList($f3, $params)
48-
{
65+
public function getList(\Base $f3, $params) {
4966
$this->response->data['SUBPART'] = 'comment_list.html';
50-
$this->response->data['LAYOUT'] = 'comment_layout.html';
5167
$filter = array('approved = ?',0); // new
5268
if (isset($params['viewtype'])) {
5369
if ($params['viewtype'] == 'published')
@@ -61,8 +77,8 @@ public function getList($f3, $params)
6177
}
6278

6379
$page = \Pagination::findCurrentPage();
64-
$limit = 3;
65-
$this->response->data['content'] =
80+
$limit = 10;
81+
$this->response->data['comments'] =
6682
$this->resource->paginate($page-1,$limit,$filter, array('order' => 'datetime desc'));
6783
}
6884

app/controller/dashboard.php

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ class Dashboard extends Base {
88
protected
99
$response;
1010

11+
/**
12+
* init the View
13+
*/
14+
public function beforeroute() {
15+
$this->response = new \View\Backend();
16+
}
17+
1118
/**
1219
* fetch data for an overview page
1320
*/

0 commit comments

Comments
 (0)