This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
/
Controller.php
321 lines (260 loc) · 8.61 KB
/
Controller.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
<?php
/**
* Controller is the customized base controller class.
* All controller classes for this application should extend from this base class.
*/
class Controller extends CController
{
/**
* @var string the default layout for the controller view. Defaults to '//layouts/column1',
* meaning using a single column layout. See 'protected/views/layouts/column1.php'.
*/
public $layout='//layouts/column2';
/**
* @var array context menu items. This property will be assigned to {@link CMenu::items}.
*/
public $menu=array();
/**
* @var array the breadcrumbs of the current page. The value of this property will
* be assigned to {@link CBreadcrumbs::links}. Please refer to {@link CBreadcrumbs::links}
* for more details on how to specify this property.
*/
public $breadcrumbs=array();
public $menuwidget;
protected $_canonicalUrl;
public $LoadSharing=0;
/* These are public variables that are used in our layout, so we have to define them.
*/
public $pageDescription;
public $pageCanonicalUrl;
public $pageImageUrl;
public $pageHeader;
public $pageHeaderImage;
public $pageGoogleVerify;
public $lnkNameLogout;
public $sharingHeader;
public $sharingFooter;
public $logoutUrl;
public $arrSidebars;
/* These are partial renders of pieces of the web page to display */
public $searchPnl;
public $gridProductsPerRow = 3;
public $gridProductsRows;
public $custom_page_content;
/**
* Load anything we need globally, such as items we're going to use in our main.php template.
* If you create init() in any other controller, you need to run parent::init() too or this
* will be skipped.
*/
public function init() {
if (Yii::app()->params['STORE_OFFLINE']>0)
{
if (isset($_GET['offline']))
Yii::app()->session['STORE_OFFLINE'] = _xls_number_only($_GET['offline']);
if (Yii::app()->session['STORE_OFFLINE'] != Yii::app()->params['STORE_OFFLINE'])
{
$this->render('/site/offline');
Yii::app()->end();
}
}
$this->logoutUrl = $this->createUrl("site/logout");
if(!Yii::app()->theme)
{
if(_xls_get_conf('theme'))
{
$symfile = "themes/brooklyn";
$strOriginal = "../core/themes/brooklyn";
@unlink($symfile);
$retVal = symlink($strOriginal, $symfile);
if (!$retVal)
die("cannot create symbolic link 'themes/brooklyn' to point to '../core/themes/brooklyn'");
} else
die("you have no theme set");
}
if ( Yii::app()->theme && file_exists('webroot.themes.'.Yii::app()->theme->name.'.layouts.column2'))
$this->layout='webroot.themes.'.Yii::app()->theme->name.'.layouts.column2';
// filter out garbage requests
$uri = Yii::app()->request->requestUri;
if (strpos($uri, 'favicon') || strpos($uri, 'robot'))
Yii::app()->end();
//Set defaults
Yii::app()->params['listPerPage'] = _xls_get_conf('PRODUCTS_PER_PAGE'); //different code may use either
$this->getUserLanguage();
$this->pageTitle =
Yii::app()->name = _xls_get_conf('STORE_NAME', 'LightSpeed Web Store');
$this->pageCanonicalUrl = $this->getCanonicalUrl();
$this->pageDescription = _xls_get_conf('STORE_TAGLINE');
$this->pageImageUrl ='';
$this->pageHeaderImage = CHtml::link(CHtml::image(Yii::app()->baseUrl._xls_get_conf('HEADER_IMAGE')), array('site/index'));
Yii::app()->clientScript->registerMetaTag("LightSpeed Web Store ".XLSWS_VERSION,'generator');
try {
$this->lnkNameLogout = CHtml::link(CHtml::image(Yii::app()->baseUrl."css/images/loginhead.png").
Yii::app()->user->name, array('myaccount/pg'));
}
catch(Exception $e) {
Yii::log("Site failure, has Web Store been set up? Error: " . $e, 'error', 'application.'.__CLASS__.".".__FUNCTION__);
echo ("Site failure, has Web Store been set up?<P>");
Yii::app()->end();
}
Yii::app()->shoppingcart->UpdateMissingProducts();
Yii::app()->shoppingcart->RevalidatePromoCode();
//Run other functions to create some data we always need
$this->buildGoogle();
$this->buildSidebars();
if (_xls_get_conf('SHOW_SHARING',0))
$this->buildSharing();
$this->gridProductsPerRow = _xls_get_conf('PRODUCTS_PER_ROW',3);
if(_xls_facebook_login())
$this->getFacebookLogin();
}
/**
* Default canonical url generator, will remove all get params beside 'id' and generates an absolute url.
* If the canonical url was already set in a child controller, it will be taken instead.
*/
public function getCanonicalUrl() {
if ($this->_canonicalUrl === null) {
$params = array();
if (isset($_GET['id'])) {
//just keep the id, because it identifies our model pages
$params = array('id' => $_GET['id']);
}
$this->_canonicalUrl = Yii::app()->createAbsoluteUrl($this->route, $params);
}
return $this->_canonicalUrl;
}
/**
* Override URL if needed
*/
public function setCanonicalUrl($strUrl) {
$this->_canonicalUrl = $strUrl;
}
protected function getUserLanguage()
{
$app = Yii::app();
if (isset($_POST['_lang']))
{
$app->language = $_POST['_lang'];
$app->session['_lang'] = $app->language;
}
elseif (isset($_GET['_lang']))
{
$app->language = $_GET['_lang'];
$app->session['_lang'] = $app->language;
}
else if (isset($app->session['_lang']))
{
$app->language = $app->session['_lang'];
}
else
{
// 'fr_FR' becomes 'fr'
$app->language = substr(Yii::app()->getRequest()->getPreferredLanguage(),0,2);
$app->session['_lang'] = substr(Yii::app()->getRequest()->getPreferredLanguage(),0,2);
}
}
/**
* buildGoogle - Reads data needed for various Google services
* @param none
* @return none
*/
protected function buildGoogle() {
$this->pageGoogleVerify = _xls_get_conf('GOOGLE_VERIFY');
}
/**
* Read the sidebars from our modules table into an array for use in our main.php template
* @param none
* @return none
*/
protected function buildSidebars() {
$this->arrSidebars = Modules::getSidebars();
}
protected function buildSharing() {
$this->sharingHeader = $this->renderPartial('/site/_sharing_header',null,true);
$this->sharingFooter = $this->renderPartial('/site/_sharing_footer',null,true);
}
protected function getloginDialog() {
/* This is our modal login dialog box */
if (Yii::app()->user->isGuest)
{
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'LoginForm',
'options'=>array(
'title'=>Yii::t('global','Login'),
'autoOpen'=>false,
'modal'=>'true',
'width'=>'350',
'height'=>'365',
'resizable'=>false,
'position'=>'center',
'draggable'=>false,
),
));
$this->renderPartial('/site/_login',array('model'=>new LoginForm()));
$this->endWidget('zii.widgets.jui.CJuiDialog');
}
}
protected function getFacebookLogin()
{
if (Yii::app()->user->isGuest)
{
$userid = Yii::app()->facebook->getUser();
if ($userid>0)
{
$results = Yii::app()->facebook->api('/'.$userid);
if(!isset($results['email']))
{
//we've lost our authentication, user may have revoked
Yii::app()->facebook->destroySession();
$this->redirect(array("/site"));
}
$identity=new FBIdentity($results['email'],$userid); //we user userid in the password field
$identity->authenticate();
if($identity->errorCode===UserIdentity::ERROR_NONE)
{
Yii::app()->user->login($identity,0);
$this->redirect(array("/site"));
}
}
}
if(isset(Yii::app()->user->facebook))
if(Yii::app()->user->facebook)
$this->logoutUrl = Yii::app()->facebook->getLogoutUrl();
}
public function setReturnUrl()
{
Yii::app()->session['returnUrl'] = $this->CanonicalUrl;
}
public function getReturnUrl()
{
return Yii::app()->session['returnUrl'];
}
/**
* Cycle through Product model for page and mark beginning and end of each row. Used for <div row> formatting in
* the view layer.
* @param $model Product
* @return $model
*/
protected function createBookends($model)
{
if(count($model)==0) return $model;
$ct=-1;
$next = 0;
foreach ($model as $item)
{
$ct++;
if ($ct==0) $model[$ct]->rowBookendFront=true;
if ($next==1) { $model[$ct]->rowBookendFront=true; $next=0; }
if ((1+$ct) % $this->gridProductsPerRow == 0) { $model[$ct]->rowBookendBack=true; $next=1; }
}
$model[count($model)-1]->rowBookendBack=true; //Last item must always close div
return $model;
}
protected function afterRender($view, &$output) {
parent::afterRender($view,$output);
//Yii::app()->facebook->addJsCallback($js); // use this if you are registering any $js code you want to run asyc
if (_xls_facebook_login())
Yii::app()->facebook->initJs($output); // this initializes the Facebook JS SDK on all pages
//Yii::app()->facebook->renderOGMetaTags(); //we don't need this because it was already in our _main.php
return true;
}
}