This repository has been archived by the owner on Apr 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
basicmoduleframework.php
185 lines (156 loc) · 6.53 KB
/
basicmoduleframework.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php
/**
* @author Matthew Morek <me@matthewmorek.com>
* @copyright Matthew Morek <me@matthewmorek.com>
* @version Release: $Revision: 1.4 $
* @license http://license.visualidiot.com/
*/
class BasicModuleFramework extends Module { // change it to your own class name
function __construct() {
// Name of your module (has to be the same as your folder & class file name).
$this->name = 'basicmoduleframework';
// Version of your module build.
$this->version = '1.0';
// If you share several modules, it's good to use this to store all of them under your name.
$this->author = 'DraftFactory';
// Indicates the category your module belongs to.
$this->tab = 'front_office_features';
// Visible name shown on Modules tab in the Back Office.
$this->displayName = $this->l('Basic Module Framework');
// Describe shortly your module here.
$this->description = $this->l('Provides a skeleton for all your future modules.');
// This should display when user tries to uninstall the module.
$this->confirmUninstall = $this->l('Are you sure you want to remove all your settings?');
/* Module specific settings
You can include your own variables and constants that will be available thorughout this class functions.
Function below tries to pull a config value from the database using native function and store it in a local variable. */
$this->my_variable = Configuration::get('MY_VARIABLE');
// This section shows a warning in Modules tab when your local variable does not exist.
if (!isset($this->some_variable))
$this->warning = $this->l('Your variable is missing!');
parent::__construct();
}
/* Installation function. You can add your own functions here, save your initial config options in the database or hook your display TPL file to a section of the system, or anything else you want :) */
function install() {
if (!parent::install())
return false;
// this little function updates (or creates if it doesn't exist) a value in the settings table.
if (!Configuration::updateValue('MY_VARIABLE', $this->some_variable))
return false;
return true;
}
/* Uninstall function. You can use it to get rid of your settings stored in the config database table */
public function uninstall() {
if (!parent::uninstall())
return false;
if (!Configuration::deleteByName('MY_VARIABLE'))
return false;
return true;
}
/* This function is used to process all submissions
generated by the module's configuration page form. */
private function _postProcess()
{
// following is the example of a typical settings post-process
if (isset($_POST['btnSubmit']))
{
if (isset($_POST['my_variable'])) {
Configuration::updateValue('MY_VARIABLE', $_POST['my_variable']);
} else {
Configuration::updateValue('MY_VARIABLE', 'false');
}
}
// displays confirmation message upon successful save
$this->_html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="'.$this->l('OK').'" /> '.$this->l('Settings updated').'</div>';
}
/* This function will help you validate all the data that goes through
your config form to prevent SQL Injections or other nasty things */
private function _postValidation()
{
if (isset($_POST['btnSubmit']))
{
if (empty($_POST['my_variable']))
$this->_postErrors[] = $this->l('You need to enter your variable to continue.');
}
}
/* This function will display contained content above the main form.
You can include some guidance copy or other useful things. */
private function _displayInfo()
{
$this->_html .= $this->l('This framework allows you to quickly build your own modules.');
}
/* This function is the core of the config page for your module.
Include your options here. */
private function _displayForm()
{
global $cookie, $smarty; // by calling SMARTY here we can enable use of templates for the config panel
$smarty->assign('MY_VARIABLE', $this->my_variable); // assign our global variable to be used in a template
$this->_html .=
'<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
<fieldset>
<legend><img src="'.$this->_path.'logo_small.png" />'.$this->l('Basic Module Framework Settings').'</legend>
<table border="0" width="500" cellpadding="0" cellspacing="0" id="form">
<tr><td width="150" style="height: 35px;">'.$this->l('Your variable').'</td><td><input type="text" name="my_variable" value="'.htmlentities(Tools::getValue('my_variable', $this->page_url), ENT_COMPAT, 'UTF-8').'" style="width: 300px;" /></td></tr>
<tr><td colspan="2" align="center"><br /><input class="button" name="btnSubmit" value="'.$this->l('Update settings').'" type="submit" /></td></tr>
</table>
</fieldset>
</form>';
$this->_html .= '<br />'.$this->l('Below you can preview your configuration. If you have enabled caching it may take a moment before settings will be applied.').'</b><br /><br />';
$this->_html .= $this->display(__FILE__, $this->name.'.tpl');
}
// this function will process and display your module's configuration page using other sub-functions
public function getContent()
{
$this->_html = '<h2>'.$this->displayName.'</h2>';
if (!empty($_POST))
{
$this->_postValidation();
if (!sizeof($this->_postErrors))
$this->_postProcess();
else
foreach ($this->_postErrors AS $err)
$this->_html .= '<div class="alert error">'. $err .'</div>';
}
else
$this->_html .= '<br />';
$this->_displayInfo();
$this->_displayForm();
return $this->_html;
}
/* The following is a list of basic hooks you can use to display your own content
using Positions page in the Modules tab.
At the moment there is only one display function and other hooks are pointing to it.
Note that none of the hooks are used during installation. You have to hook the module manually. */
function hookCustomerAccount($params) {
global $smarty;
$smarty->assign('my_variable', $this->my_variable);
return $this->display(__FILE__, $this->name.'.tpl');
}
function hookLeftColumn($params)
{
return $this->hookCustomerAccount($params);
}
function hookRightColumn($params)
{
return $this->hookCustomerAccount($params);
}
function hookHome($params)
{
return $this->hookCustomerAccount($params);
}
function hookFooter($params)
{
return $this->hookCustomerAccount($params);
}
function hookTop($params)
{
return $this->hookCustomerAccount($params);
}
function hookPaymentReturn($params){
return $this->hookCustomerAccount($params);
}
function hookOrderConfirmation($params){
return $this->hookCustomerAccount($params);
}
}
?>