/
LSYii_Controller.php
167 lines (148 loc) · 6.03 KB
/
LSYii_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
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
*/
abstract class LSYii_Controller extends CController
{
/**
* This array contains the survey / group / question id used by the menu widget.
* @var array
*/
public $navData = array();
/**
* Basic initialiser to the base controller class
*
* @access public
* @param string $id
* @param CWebModule $module
* @return void
*/
public function __construct($id, $module = null)
{
parent::__construct($id, $module);
$this->_checkInstallation();
Yii::app()->session->init();
$this->loadLibrary('LS.LS');
$this->loadHelper('globalsettings');
$this->loadHelper('common');
$this->loadHelper('expressions.em_manager');
$this->loadHelper('replacements');
$this->_init();
}
/**
* Check that installation was already done by looking for config.php
* Will redirect to the installer script if not exists.
*
* @access protected
* @return void
*/
protected function _checkInstallation()
{
$file_name = Yii::app()->getConfig('rootdir').'/application/config/config.php';
if (!file_exists($file_name))
{
$this->redirect(array('/installer'));
}
}
/**
* Loads a helper
*
* @access public
* @param string $helper
* @return void
*/
public function loadHelper($helper)
{
Yii::app()->loadHelper($helper);
}
/**
* Loads a library
*
* @access public
* @param string $helper
* @return void
*/
public function loadLibrary($library)
{
Yii::app()->loadLibrary($library);
}
protected function _init()
{
// Check for most necessary requirements
// Now check for PHP & db version
// Do not localize/translate this!
$dieoutput='';
if (version_compare(PHP_VERSION, '5.1.6', '<'))
$dieoutput .= 'This script can only be run on PHP version 5.1.6 or later! Your version: '.PHP_VERSION.'<br />';
if (!function_exists('mb_convert_encoding'))
$dieoutput .= "This script needs the PHP Multibyte String Functions library installed: See <a href='http://docs.limesurvey.org/tiki-index.php?page=Installation+FAQ'>FAQ</a> and <a href='http://de.php.net/manual/en/ref.mbstring.php'>PHP documentation</a><br />";
if ($dieoutput != '')
throw new CException($dieoutput);
if (ini_get("max_execution_time") < 1200) @set_time_limit(1200); // Maximum execution time - works only if safe_mode is off
if ((int)substr(ini_get("memory_limit"),0,-1) < (int) Yii::app()->getConfig('memory_limit')) @ini_set("memory_limit",Yii::app()->getConfig('memory_limit').'M'); // Set Memory Limit for big surveys
// The following function (when called) includes FireBug Lite if true
defined('FIREBUG') or define('FIREBUG' , Yii::app()->getConfig('use_firebug_lite'));
// Deal with server systems having not set a default time zone
if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get"))
@date_default_timezone_set(@date_default_timezone_get());
//Every 50th time clean up the temp directory of old files (older than 1 day)
//depending on the load the probability might be set higher or lower
if (rand(1,50)==1)
{
cleanTempDirectory();
}
//GlobalSettings Helper
Yii::import("application.helpers.globalsettings");
enforceSSLMode();// This really should be at the top but for it to utilise getGlobalSetting() it has to be here
if (Yii::app()->getConfig('debug')==1) {//For debug purposes - switch on in config.php
@ini_set("display_errors", 1);
error_reporting(E_ALL);
}
elseif (Yii::app()->getConfig('debug')==2) {//For debug purposes - switch on in config.php
@ini_set("display_errors", 1);
error_reporting(E_ALL | E_STRICT);
}
else {
@ini_set("display_errors", 0);
error_reporting(0);
}
//SET LOCAL TIME
$timeadjust = Yii::app()->getConfig("timeadjust");
if (substr($timeadjust,0,1)!='-' && substr($timeadjust,0,1)!='+') {$timeadjust='+'.$timeadjust;}
if (strpos($timeadjust,'hours')===false && strpos($timeadjust,'minutes')===false && strpos($timeadjust,'days')===false)
{
Yii::app()->setConfig("timeadjust",$timeadjust.' hours');
}
Yii::app()->setConfig('adminimageurl', Yii::app()->getConfig('styleurl').Yii::app()->getConfig('admintheme').'/images/');
Yii::app()->setConfig('adminstyleurl', Yii::app()->getConfig('styleurl').Yii::app()->getConfig('admintheme').'/');
}
/**
* Creates an absolute URL based on the given controller and action information.
* @param string $route the URL route. This should be in the format of 'ControllerID/ActionID'.
* @param array $params additional GET parameters (name=>value). Both the name and value will be URL-encoded.
* @param string $schema schema to use (e.g. http, https). If empty, the schema used for the current request will be used.
* @param string $ampersand the token separating name-value pairs in the URL.
* @return string the constructed URL
*/
public function createAbsoluteUrl($route,$params=array(),$schema='',$ampersand='&')
{
$sPublicUrl=Yii::app()->getConfig("publicurl");
// Control if public url are really public : need scheme and host
// If yes: update baseUrl to config without restrictions
$aPublicUrl=parse_url($sPublicUrl);
if(isset($aPublicUrl['scheme']) && isset($aPublicUrl['host']))
{
Yii::app()->getComponent('urlManager')->setBaseUrl($sPublicUrl);
}
return parent::createAbsoluteUrl($route,$params,$schema,$ampersand);
}
}