-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin.php
148 lines (136 loc) · 7 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
class HeroBanner extends Plugin {
public function init()
{
$this->dbFields = array(
'heroBgColor'=>'#FFFFFF',
'heroTitle'=>'Your hero banner heading goes here.',
'heroTitleColor'=>'',
'heroPhrase'=>'Your hero banner short text goes here',
'heroPhraseColor'=>'',
'heroBtnLabel'=>'Submit',
'heroBtnLink'=>'#',
'heroImage'=>''
);
}
public function adminController()
{
global $layout;
// $layout["title"] = "Hero Banner Plugin | Bludit";
try {
// Check if the form was sent
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// global $site;
// $site->set(array('title'=>$_POST['title']));
$this->setField('heroBgColor', Sanitize::html($_POST['heroBgColor']));
$this->setField('heroTitle', Sanitize::html($_POST['heroTitle']));
$this->setField('heroTitleColor', Sanitize::html($_POST['heroTitleColor']));
$this->setField('heroPhrase', Sanitize::html($_POST['heroPhrase']));
$this->setField('heroPhraseColor', Sanitize::html($_POST['heroPhraseColor']));
$this->setField('heroBtnLabel', Sanitize::html($_POST['heroBtnLabel']));
$this->setField('heroBtnLink', Sanitize::html($_POST['heroBtnLink']));
}
} catch (\Throwable $th) {
//throw $th;
}
}
public function adminView()
{
// Token for send forms in Bludit
global $security;
$tokenCSRF = $security->getTokenCSRF();
// Current site title
global $site;
// $title = $site->title();
global $L;
// HTML code for the form
$html = ' <h2 class="mt-0 mb-3"><span class="fa fa-cog"></span><span>Hero Banner</span></h2>';
$html .= '<div class="alert alert-primary" role="alert">';
$html .= $this->description();
$html .= '</div>';
$html .= '
<form class="plugin-form" id="jsform" method="post" action="" autocomplete="off">
<input type="hidden" id="jstokenCSRF" name="tokenCSRF" value="'.$tokenCSRF.'">
<div class="form-group">
<label for="heroBgColor">'.$L->get('hero-bg-color').'</label><br>
<input type="color" id="heroBgColor" name="heroBgColor" value="'.$this->getValue('heroBgColor').'">
</div>
<hr>
<div class="form-group">
<label for="heroTitle">'.$L->get('hero-title').'</label>
<input type="text" class="form-control" id="heroTitle" name="heroTitle" value="'.$this->getValue('heroTitle').'">
</div>
<div class="form-group">
<label for="heroTitleColor">'.$L->get('hero-title-color').'</label><br>
<input type="color" id="heroTitleColor" name="heroTitleColor" value="'.$this->getValue('heroTitleColor').'">
</div>
<hr>
<div class="form-group">
<label for="heroPhrase">'.$L->get('hero-phrase').'</label>
<input type="text" class="form-control" id="heroPhrase" name="heroPhrase" value="'.$this->getValue('heroPhrase').'">
</div>
<div class="form-group">
<label for="heroPhraseColor">'.$L->get('hero-phrase-color').'</label><br>
<input type="color" id="heroPhraseColor" name="heroPhraseColor" value="'.$this->getValue('heroPhraseColor').'">
</div>
<hr>
<div class="form-group">
<label for="heroBtnLabel">'.$L->get('hero-button-label').'</label>
<input type="text" class="form-control" id="heroBtnLabel" name="heroBtnLabel" value="'.$this->getValue('heroBtnLabel').'">
</div>
<div class="form-group">
<label for="heroBtnLink">'.$L->get('hero-button-link').'</label>
<input type="text" class="form-control" id="heroBtnLink" name="heroBtnLink" value="'.$this->getValue('heroBtnLink').'">
</div>
<button type="submit" class="btn btn-primary" name="save">'.$L->get('hero-save-btn').'</button>
<a class="btn btn-secondary" href="/admin/plugins" role="button">'.$L->get('hero-cancel-btn').'</a>
</form>
';
return $html;
}
public function adminBodyEnd(){
global $L;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
print('<script charset="utf-8">$(document).ready(function() { showAlert("'.$L->get('hero-save-msg').'")});</script>');
}
}
public function adminSidebar()
{
$pluginName = Text::lowercase(__CLASS__);
$url = HTML_PATH_ADMIN_ROOT.'plugin/'.$pluginName;
$html = '<a id="current-version" class="nav-link" href="'.$url.'">Hero Banner</a>';
return $html;
}
// make the plugin call on site
public function siteHead()
{
// Include plugin's CSS files
$html .= $this->includeCSS('style.css');
return $html;
}
public function siteBodyBegin() {
global $url;
global $WHERE_AM_I;
// Do not shows hero banner on page not found. Just in case home 404... u'never know!
if ($url->notFound()) {
return false;
}
$html = '<header class="hero-banner d-flex align-items-center" style="background: '.$this->getValue('heroBgColor').' url(\''.$this->domainPath().'img/bg-pattern.png\');background-repeat: repeat; background-position:center center;">
<div class="container hero-container">
<div class="row">
<div class="col mr-auto text-wrap">
<h2 class="title" style="color:'.$this->getValue('heroTitleColor').'">'.$this->getValue('heroTitle').'</h2>
<p style="color:'.$this->getValue('heroPhraseColor').'">'.$this->getValue('heroPhrase').'</p>
<a href="'.$this->getValue('heroBtnLink').'" class="btn btn-primary mb-4">'.$this->getValue('heroBtnLabel').'</a>
</div>
</div>
</div>
</header>
';
// Show hero banner in homepage only
if($WHERE_AM_I=='home'):
return $html;
endif;
}
}
?>