-
Notifications
You must be signed in to change notification settings - Fork 8
/
base.php
89 lines (78 loc) · 2.36 KB
/
base.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* @package Wiki
* @author Alan Hardman <[email protected]>
* @version 1.1.1
*/
namespace Plugin\Wiki;
class Base extends \Plugin {
/**
* Initialize the plugin
*/
public function _load() {
$f3 = \Base::instance();
// Add menu item
$this->_addNav("wiki", $f3->get("dict.wiki.wiki"), "/^\\/wiki/i");
$this->_addNav("wiki/edit", $f3->get("dict.wiki.page"), "/^\\/wiki\\/edit\\/?$/i", "new");
// Add routes
$f3->route("GET /wiki", "Plugin\Wiki\Controller->index");
$f3->route("GET /wiki/@page", "Plugin\Wiki\Controller->single");
$f3->route("GET|POST /wiki/edit", "Plugin\Wiki\Controller->edit");
$f3->route("GET|POST /wiki/edit/@page", "Plugin\Wiki\Controller->edit");
$f3->route("GET|POST /wiki/delete/@page", "Plugin\Wiki\Controller->delete");
}
/**
* Install plugin (add database tables)
*/
public function _install() {
$f3 = \Base::instance();
$db = $f3->get("db.instance");
$install_db = file_get_contents(__DIR__ . "/db/database.sql");
$db->exec(explode(";", $install_db));
}
/**
* Check if plugin is installed
* @return bool
*/
public function _installed() {
$f3 = \Base::instance();
if($f3->get("plugins.wiki.installed")) {
return true;
}
$db = $f3->get("db.instance");
$q = $db->exec("SHOW TABLES LIKE 'wiki_page'");
$installed = !!$db->count();
if($installed) {
$f3->set("plugins.wiki.installed", true, 3600*24);
}
return $installed;
}
/**
* Generate page for admin panel
*/
public function _admin() {
$f3 = \Base::instance();
$db = $f3->get("db.instance");
if($f3->get("AJAX")) {
// Update configuration value
switch($f3->get("POST.key")) {
case "parse.markdown":
case "parse.textile":
\Model\Config::setVal("wiki." . $f3->get("POST.key"), (int)$f3->get("POST.val"));
break;
default:
$f3->error(400);
}
} else {
// Gather some stats
$result = $db->exec("SELECT COUNT(id) AS `count` FROM wiki_page WHERE deleted_date IS NULL");
$f3->set("count_page", $result[0]["count"]);
$result = $db->exec("SELECT COUNT(DISTINCT user_id) AS `count` FROM wiki_page_update");
$f3->set("count_page_update_user", $result[0]["count"]);
$result = $db->exec("SELECT COUNT(id) AS `count` FROM wiki_page_update");
$f3->set("count_page_update", $result[0]["count"]);
// Render view
echo \Helper\View::instance()->render("wiki/view/admin.html");
}
}
}