forked from shopware5/SwagFacebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootstrap.php
196 lines (178 loc) · 5.37 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
<?php
/*
* (c) shopware AG
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Shopware\Models\Config\Element;
class Shopware_Plugins_Frontend_SwagFacebook_Bootstrap extends Shopware_Components_Plugin_Bootstrap
{
/**
* Returns the meta information about the plugin
* as an array.
*
* @return array
*/
public function getInfo()
{
return array(
'version' => $this->getVersion(),
'label' => $this->getLabel(),
'name' => 'SwagFacebook',
'author' => 'shopware AG',
'copyright' => 'Copyright (c) shopware AG',
'license' => 'The MIT License (MIT) (http://opensource.org/licenses/MIT)',
'link' => 'https://github.com/shopwareLabs/SwagFacebook',
);
}
/**
* Returns the well-formatted name of the plugin
* as a sting
*
* @return string
*/
public function getLabel()
{
return 'Facebook Integration';
}
/**
* Reads the Version of the Plugin from the plugin.json and returns it
*
* @return string
* @throws Exception
*/
public function getVersion()
{
$info = json_decode(file_get_contents(__DIR__ . '/plugin.json'), true);
if ($info) {
return $info['currentVersion'];
} else {
throw new Exception('The plugin has an invalid version file.');
}
}
/**
* Install plugin method
*
* @return bool
*/
public function install()
{
$this->createEvents();
$this->createForm();
return true;
}
/**
* Register Frontend Dispatch Event
*/
private function createEvents()
{
$this->subscribeEvent('Enlight_Controller_Front_DispatchLoopStartup', 'onStartDispatch');
}
/**
* Register SubscriberClasses
*/
public function onStartDispatch()
{
$this->registerPluginNamespace();
$subscribers = array(
new \Shopware\SwagFacebook\Subscriber\Frontend($this),
new \Shopware\SwagFacebook\Subscriber\Less()
);
foreach ($subscribers as $subscriber) {
$this->Application()->Events()->addSubscriber($subscriber);
}
}
/**
* Create the Plugin Settings Form
*/
private function createForm()
{
$form = $this->Form();
$form->setElement(
'text',
'app_id_SwagFacebook',
array('label' => 'Facebook App-ID', 'value' => '', 'scope' => Element::SCOPE_SHOP)
);
$form->setElement(
'checkbox',
'showSwagFacebook',
array('label' => 'Facebook zeigen', 'value' => 1, 'scope' => Element::SCOPE_SHOP)
);
$form->setElement(
'checkbox',
'swagFacebook_showShareButton',
array('label' => 'Teilen Button zeigen (*)', 'value' => 1, 'scope' => Element::SCOPE_SHOP)
);
$form->setElement(
'checkbox',
'swagFacebook_showFaces',
array(
'label' => 'Bilder "Gesichter" zeigen (*)',
'value' => 1,
'scope' => Element::SCOPE_SHOP
)
);
$form->setElement(
'checkbox',
'showDetailPageComments',
array(
'label' => 'Facebook-Kommentare auf Detailseite anzeigen',
'value' => 1,
'scope' => Element::SCOPE_SHOP
)
);
$form->setElement(
'select',
'swagFacebook_colorscheme',
array(
'label' => 'Farbschema (*)',
'store' => array(array(1, 'light'), array(2, 'dark')),
'scope' => Shopware_Components_Form::SCOPE_SHOP
)
);
$this->addFormTranslations($this->getTranslations());
}
private function getTranslations()
{
return array(
'en_GB' => array(
'showSwagFacebook' => array('label' => 'Show Facebook'),
'app_id_SwagFacebook' => array('label' => 'Facebook App-ID'),
'showDetailPageComments' => array('label' => 'Show comments in detail page'),
'swagFacebook_showShareButton' => array('label' => 'Show share Button (*)'),
'swagFacebook_showFaces' => array('label' => 'Show Faces (*)'),
'swagFacebook_colorscheme' => array('label' => 'color scheme')
)
);
}
/**
* Check if the environment is Shopware 5
*
* @return mixed
*/
public function isShopwareFive()
{
return version_compare(Shopware()->Config()->get('Version'), '5.0.0', '>=');
}
/**
* check if the activated Template is Responsive
*
* @return bool
*/
public function isTemplateResponsive()
{
if (Shopware()->Shop()->getTemplate()->getVersion() < 3) {
return false;
}
return true;
}
/**
* Registers the plugin namespace to the application loader.
*/
public function registerPluginNamespace()
{
$this->Application()->Loader()->registerNamespace('Shopware\SwagFacebook', $this->Path());
$this->Application()->Loader()->registerNamespace('Shopware\SwagFacebook\Components', $this->Path() . 'Components/');
}
}