-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBootstrap.php
373 lines (338 loc) · 10.4 KB
/
Bootstrap.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<?php
/**
* Class Shopware_Plugins_Backend_Boilerplate_Bootstrap
*
* @author Nils Uliczka
* @author Anton
*/
class Shopware_Plugins_Frontend_Boilerplate_Bootstrap extends Shopware_Components_Plugin_Bootstrap {
/**
* The Plugin-Version
* @var string
**/
const VERSION = '1.0.0';
/**
* The author
* @var string
**/
const AUTHOR = 'darookee';
/**
* The Link to the author's homepage
* @var string
**/
const LINK = 'http://darookee.net';
/**
* The name displayed in the pluginmanager
* @var string
**/
const PLUGINNAME = 'Boilerplate';
/**
* Events registered with this plugin
* @static
*/
static $myEvents =
array(
/** Get path to requested frontend controller **/
/*
*array(
* 'event' => 'Enlight_Controller_Dispatcher_ControllerPath_Frontend_Boilerplate',
* 'method' => 'getFrontendControllerPath'
*),
*/
/** Get path to requested backend controller **/
/*
*array(
* 'event' => 'Enlight_Controller_Dispatcher_ControllerPath_Backend_Boilerplate',
* 'method' => 'getBackendControllerPath'
*),
*/
/** Common events **/
/** PostDispatch - all **/
array(
'event' => 'Enlight_Controller_Action_PostDispatch',
'method' => 'onPostDispatch'
),
/** Homepage **/
/*
*array(
* 'event' => 'Enlight_Controller_Action_PostDispatch_Frontend_Index',
* 'method' => 'onPostDispatchIndex'
*),
*/
/** Checkout (cart,...) **/
/*
*array(
* 'event' => 'Enlight_Controller_Action_PostDispatch_Frontend_Checkout',
* 'method' => 'onPostDispatchCheckout'
*)
*/
);
static $myMenus =
array(
/*
* array(
* 'label' => 'Boilerplate',
* 'controller' => 'Boilerplate',
* 'action' => 'Index',
* 'class' => 'sprite-application-block',
* 'active' => 1,
* 'parent' => array( 'label' => 'Einstellungen' )
*)
*/
);
static $myForms =
array(
/*
*array(
* 'type' => 'text',
* 'name' => 'testfield',
* 'settings' =>
* array(
* 'label' => 'Testfield',
* 'scope' => \Shopware\Models\Config\Element::SCOPE_SHOP,
* 'value' => 'testvalue'
* ),
*)
*/
);
static $mySql =
array(
/*
*"CREATE TABLE `s_plugin_boilerplate` (
* `id` int(11) NOT NULL AUTO_INCREMENT,
* `name` varchar(255) DEFAULT NULL,
* PRIMARY KEY ( `id` )
*) DEFAULT CHARSET=latin1",
*/
);
static $myCron =
array(
/*
*array(
* 'eventName' => 'BoilerplateCronjob',
* 'cronjobName' => 'Boilerplate',
* 'functionName' => 'onCron',
* 'interval' => 3600,
* 'active' => true
*),
*/
);
/**
* install the plugin - call registerHooks and registerEvents
* @see registerHooks
* @see registerEvents
*/
public function install() {
if(
$this->registerEvents() &&
$this->registerMenuEntries() &&
$this->registerFormSettings() &&
$this->registerCron() &&
$this->executeSql()
)
return array('success' => true, 'invalidateCache' => array('backend'));
else
return array('success' => false);
}
/**
* registers forms
* @return boolean true
*/
public function registerFormSettings() {
if(count(self::$myForms) > 0) {
$form = $this->Form();
foreach(self::$myForms as $key => $formArray) {
$form->setElement(
$formArray['type'],
$formArray['name'],
$formArray['settings']
);
}
$form->save();
}
return true;
}
/**
* registers Menuentries
* @return boolean true
*/
public function registerMenuEntries() {
if(count(self::$myMenus) > 0) {
foreach(self::$myMenus as $key => $menuArray) {
if(is_array($menuArray['parent'])) {
$findBy = array_keys($menuArray['parent']);
$findBy = $findBy[0];
$parent = $this->Menu()->findOneBy($findBy, $menuArray['parent'][$findBy]);
$menuArray['parent'] = $parent;
}
$this->createMenuItem($menuArray);
}
}
return true;
}
/**
* registers the events for this plugin
* @see myEvents
* @return boolean true
*/
public function registerEvents() {
if(count(self::$myEvents) > 0) {
foreach(self::$myEvents as $eventArray) {
$this->subscribeEvent(
$eventArray['event'],
$eventArray['method']
);
}
}
return true;
}
/**
* registers cronjobs for this plugin
* @see myCron
* @return boolean true
*/
public function registerCron() {
if(count(self::$myCron) > 0) {
foreach(self::$myCron as $cronArray) {
$event = $this->subscribeEvent(
'Shopware_CronJob_' . $cronArray['eventName'],
$cronArray['functionName']
);
$this->createCronJob($cronArray['cronjobName'], $cronArray['eventName'], $cronArray['interval'], $cronArray['active']);
}
}
return true;
}
/**
* execute sql statements (for table creation...)
* @return boolean true
*/
public function executeSql() {
if(count(self::$mySql) > 0) {
$db = Shopware()->Db();
foreach(self::$mySql as $sql) {
$db->query($sql);
}
}
return true;
}
/**
* return version for plugin manager
* @return array of version information
*/
public function getInfo() {
return array(
'version' => $this->getVersion(),
'autor' => self::AUTHOR,
'link' => self::LINK,
'copyright' => '(c) '.date('Y'),
'label' => $this->getLabel(),
'description' => $this->getDescription()
);
}
/**
* return the version of plugin as string.
*
* THIS DOES NOT WORK FOR Shopware Code-Review/Community-Store
* It HAS TO return the Version like this
* return '1.0.0';
*
* @return string the Version
*/
public function getVersion() {
//return '1.0.0'; // when you submit your plugin to the shopware store
// you need to return the version string here
// without using the constant to pass
// the code quality test
return self::VERSION;
}
/**
* returns the plugin label as string
*
* @return string Name of the plugin
*/
public function getLabel() {
return self::PLUGINNAME;
}
/**
* return plugindescription from file info.txt
*
* @return string Path to info.txt
*/
public function getDescription() {
return file_get_contents($this->Path().'/info.txt');
}
/**
* @return string path of Backend controller
*/
/*
*public static function getBackendControllerPath(Enlight_Event_EventArgs $args) {
* return dirname(__FILE__) . '/Controllers/BoilerplateBackend.php';
*}
*/
/**
* @return string path of Frontend controller
*/
/*
*public static function getFrontendControllerPath(Enlight_Event_EventArgs $args) {
* return dirname(__FILE__) . '/Controllers/BoilerplateFrontend.php';
*}
*/
/**
* Called as cronjob
* @return boolean true
*
* Wrapped in a try ... catch because there may be issues when an exception is thrown
* - sometimes the cronjob will not be run ever again
* to prevent this the exception is caught and the message can be viewed in the cj settings
*/
/*
*public function onCron(Shopware_Components_Cron_CronJob $job) {
* try {
* $job->stop();
* } catch(Exception $e) {
* $job->setData($e->getMessage());
* $job->stop();
* }
* return true;
*}
*/
/**
* onPostDispatch
* @param Enlight_Event_EventArgs $args
* @return void
**/
public function onPostDispatch(Enlight_Event_EventArgs $args) {
/** @var $controller Shopware_Controllers_Frontend_Index */
$controller = $args->getSubject();
/** @var $request Zend_Controller_Request_Http */
$request = $controller->Request();
/** @var $response Zend_Controller_Response_Http */
$response = $controller->Response();
/** @var $view Enlight_View_Default */
$view = $controller->View();
//Check if there is a template and if an exception has occured
if(
!$request->isDispatched()
||$response->isException()
|| !$view->hasTemplate()
//|| $request->getModuleName() != 'frontend' // check for frontend
) {
return;
}
if($this->isConnexoTemplate()) { // Connexo Responsive Template
$view->addTemplateDir(dirname(__FILE__) . '/Views.connexo/');
} else { // .. default template
$view->addTemplateDir(dirname(__FILE__) . '/Views/');
}
}
/**
* check for Connexo Template
*
* @return array|false
*/
private function isConnexoTemplate() {
$sql = "SELECT `active` FROM `s_core_plugins` WHERE `name` = 'SwfResponsiveTemplate' LIMIT 1";
return Shopware()->Db()->fetchOne($sql);
}
}