forked from Felli/Pages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
executable file
·114 lines (99 loc) · 3.02 KB
/
plugin.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
// Copyright 2014 Aleksandr Tsiolko
if (!defined("IN_ESOTALK")) exit;
ET::$pluginInfo["Pages"] = array(
"name" => "Pages",
"description" => "Allows custom static pages.",
"version" => "1.0.0",
"author" => "Aleksandr Tsiolko",
"authorEmail" => "support@esotalk.org",
"authorURL" => "http://ifirestarter.ru",
"license" => "MIT"
);
class ETPlugin_Pages extends ETPlugin {
public function setup($oldVersion = "")
{
$structure = ET::$database->structure();
$structure->table("page")
->column("pageId", "int(11) unsigned", false)
->column("title", "varchar(31)", false)
->column("content", "text")
->column("slug", "varchar(255) unique")
->column("hideFromGuests", "tinyint(1)", 0)
->column("menu", "enum('user','statistics','meta')", "user")
->column("position", "int(11)", 0)
->key("pageId", "primary")
->exec(false);
/*:-)*/
if (!$oldVersion){
$this->createDefaultPages();
}
elseif (version_compare($oldVersion, "1.0.0g4", "<")) {
$this->createDefaultPages();
}else{
$this->createDefaultPages();
}
/*:-)*/
return true;
}
protected function createDefaultPages()
{
$model = ET::getInstance("pagesModel");
$model->setData(array(
"pageId" => 1,
"title" => "About",
"content" => "Write something about yourself.",
"slug" => "about-page",
"hideFromGuests" => 0,
"menu"=>"user",
"position" => 1
));
$model->setData(array(
"pageId" => 2,
"title" => "EsoTalk",
"content" => "Write something about Esotalk Forum.",
"slug" => "esotalk-page",
"hideFromGuests" => 0,
"menu"=>"user",
"position" => 2
));
}
public function __construct($rootDirectory)
{
parent::__construct($rootDirectory);
ETFactory::register("pagesModel", "PagesModel", dirname(__FILE__)."/PagesModel.class.php");
ETFactory::registerAdminController("pages", "PagesAdminController", dirname(__FILE__)."/PagesAdminController.class.php");
ETFactory::registerController("pages", "PagesController", dirname(__FILE__)."/PagesController.class.php");
}
public function handler_initAdmin($sender, $menu)
{
$menu->add("pages", "<a href='".URL("admin/pages")."'><i class='icon-book'></i> ".T("Pages")."</a>");
}
public function handler_init($sender)
{
ET::$controller->addCSSFile($this->resource("pages.css"), true);
$model = ET::getInstance("pagesModel");
$pages = $model->get();
if($pages){
foreach($pages as $page){
if (ET::$session->userId) {
$sender->addToMenu($page['menu'], $page['slug'].'-page', '<a href="'.URL("pages").'/'.$page['pageId'].'-'.$page['slug'].'">'.$page['title'].'</a>');
}
elseif($page['hideFromGuests']==0){
$sender->addToMenu($page['menu'], $page['slug'].'-page', '<a href="'.URL("pages").'/'.$page['pageId'].'-'.$page['slug'].'">'.$page['title'].'</a>');
}
}
}
}
public function disable()
{
return true;
}
public function uninstall()
{
$structure = ET::$database->structure();
$structure->table("page")
->drop();
return true;
}
}