-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.php
53 lines (46 loc) · 1.08 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
<?php
/**
* @package Blocks
* @author Alan Hardman <[email protected]>
* @version 0.1.1
*/
namespace Plugin\Blocks;
class Base extends \Plugin {
/**
* Initialize the plugin, adding hooks dynamically
*/
public function _load() {
$block = new Block;
$blocks = $block->find();
\Base::instance()->set("site.plugins.blocks.blocks", $blocks);
foreach($blocks as $block) {
$this->_hook($block->hook, function($data) use($block) {
echo $block->content;
return $data;
});
}
}
/**
* Handle admin page for plugin
*/
public function _admin() {
echo \Helper\View::instance()->render("blocks/blocks-plugin-admin.html");
}
/**
* Install plugin (add database table)
*/
public function _install() {
$db = \Base::instance()->get("db.instance");
$install_db = file_get_contents(__DIR__ . "/db.sql");
$db->exec(explode(";", $install_db));
}
/**
* Check if plugin is installed
* @return bool
*/
public function _installed() {
$db = \Base::instance()->get("db.instance");
$q = $db->exec("SHOW TABLES LIKE 'block'");
return !!$db->count();
}
}