-
Notifications
You must be signed in to change notification settings - Fork 0
/
oprecx.php
133 lines (116 loc) · 4.77 KB
/
oprecx.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
<?php
/*
* This file contains wrapper classes for YiiBase and CWebApplication
*/
/**
* Oprecx Main Class
*
*/
class O extends YiiBase
{
/**
*
* @param type $config
* @see CWebApplication
* @return OprecxWebApplication
*/
public static function createOprecxWebApplication($config = null)
{
return parent::createApplication('OprecxWebApplication', $config);
}
/**
* @todo Hapus ketika selesai development
* @return OprecxWebApplication applications
*/
public static function app()
{
return parent::app();
}
public static function versionedFileUrl($file_name, $ext){
$time = filemtime(O::app()->getBasePath() . '/..' . $file_name . $ext);
if (! YII_DEBUG){
return O::app()->getRequest()->getBaseUrl() . $file_name . '-' . $time . $ext;
}
else {
return O::app()->getRequest()->getBaseUrl() . $file_name. $ext . '?m=' . $time;
}
}
}
/**
* Oprecx Application
*
* @property Bootstrap $bootstrap Description
*/
class OprecxWebApplication extends CWebApplication
{
public function changeLanguage($new_lang)
{
setcookie('lang', $new_lang, time() + 3600 * 24 * 356, $this->getHomeUrl());
}
/**
* Get bootstrap component
* @return Bootstrap
*/
public function getBootstrap() {
return $this->getComponent('bootstrap');
}
private function initLanguage()
{
$this->setLanguage('en');
return;
$params = $this->getParams();
$supportedLang = $params['supportedLang'];
$curLang = $params['defaultLang'];
if (isset($_COOKIE['lang']) && isset($supportedLang[$_COOKIE['lang']])) {
$curLang = $_COOKIE['lang'];
}
elseif (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$langMap = $params['langMap'];
foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $lang) {
if (($ipos = strpos($lang, ';')) > 0) $lang = substr($lang, 0, $ipos);
$lang = trim(strtolower($lang));
if (isset($langMap[$lang])) $lang = $langMap[$lang];
if (isset($supportedLang[$lang])) {
$curLang = $lang;
//self::changeLanguage($lang);
break;
}
}
}
$this->setLanguage($curLang);
}
protected function init()
{
parent::init();
$this->initLanguage();
if (!YII_DEBUG) {
$this->getClientScript()->scriptMap = array (
'jquery.min.js' => '//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js',
'jquery-ui.min.js' => '//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
'bootstrap.min.js' => '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/js/bootstrap.min.js',
'bootstrap.min.css' => '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap.min.css',
'bootstrap-combined.no-icons.min.css' => '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.0/css/bootstrap.no-icons.min.css',
'font-awesome.min.css' => '//cdnjs.cloudflare.com/ajax/libs/font-awesome/3.1.0/css/font-awesome.min.css',
'bootstrap-responsive.min.css' => '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css',
'jquery.form.min.js' => '//cdnjs.cloudflare.com/ajax/libs/jquery.form/3.24/jquery.form.min.js',
'jquery.form.js' => '//cdnjs.cloudflare.com/ajax/libs/jquery.form/3.24/jquery.form.min.js',
'wysihtml5-0.3.0.js' => '//cdnjs.cloudflare.com/ajax/libs/wysihtml5/0.3.0/wysihtml5.min.js',
'date.js' => '//cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js',
'bootstrap-datepicker.css' => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.0.2/css/bootstrap-datepicker.min.css',
'bootstrap-datepicker.js' => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.0.2/js/bootstrap-datepicker.min.js',
'bootstrap-datepicker.id.js' => '//cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.0.2/js/locales/bootstrap-datepicker.id.min.js',
);
}
// TODO: remove debug specific options and add that to plugins
if (YII_DEBUG) {
//$this->messages->onMissingTranslation = array ('CPhpMessageTranslator', 'appendMessage');
$this->setModules(
array ('gii' => array (
'class' => 'system.gii.GiiModule',
'password' => 'gii',
))
);
$this->cache->hashKey = false;
}
}
}