This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
/
common.php
161 lines (147 loc) · 3.87 KB
/
common.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
<?php
// icore comm for driver
if (!defined('DRIVER_URI'))
{
die('cant be accessed directly');
}
// module related file extension(.m.php) and class file extension(.cls.php, normally used in framework classes)
define('ICORE_MODULE_EXT', '.m.php');
define('ICORE_CLASS_EXT', '.cls.php');
// related directories
define('ROOT_DIR', __DIR__);
define('ICORE_CORE', ROOT_DIR . '/core');
define('MODULES_DIR', ROOT_DIR . '/modules');
define('THEMES_DIR', DRIVER_DIR . '/themes');
// autoload
set_include_path(MODULES_DIR . PATH_SEPARATOR . ICORE_CORE . PATH_SEPARATOR . get_include_path());
spl_autoload_extensions(ICORE_MODULE_EXT . ',' . ICORE_CLASS_EXT);
spl_autoload_register();
// var directories
define('VAR_DIR', ROOT_DIR . '/var');
define('VAR_MODELS_DIR', VAR_DIR . '/models');
define('VAR_SQLS_DIR', VAR_DIR . '/sqls');
define('VAR_CACHE_DIR', VAR_DIR . '/cache');
define('VAR_CONFIGS_DIR', VAR_DIR . '/configs');
// ...
// common functions
function url($region = null, $module = null, $action = null, $args = array(), $entry = null, $lang = null)
{
return \icore\Application::get()->router->makeUrl($region, $module, $action, $args, $entry, $lang);
}
function js($url = null)
{
static $buff;
static $tpl1 = "<script type=\"text/javascript\" src=\"__SRC__\"></script>\n";
static $tpl2 = '<script type="text/javascript">__JS__</script>';
$compress_js = isset(\icore\Application::get()->vars['compress_js']) && !empty(\icore\Application::get()->vars['compress_js']) ? intval(\icore\Application::get()->vars['compress_js']) : 0;
if (!empty($url))
{
if ($compress_js)
$buff[] = $url;
else
return str_replace('__SRC__', $url, $tpl1);
}
else
{
if ($compress_js)
{
$key = VAR_CACHE_DIR . '/js_' . md5(CONFIG_FILE . serialize($buff));
$obj = \icore\cache\JsCache::get();
$obj->setKey($key);
if (!$obj->isCached())
{
$string = '';
foreach($buff as $url)
{
if (substr($url, 0, 4) === 'http')
{
$string .= file_get_contents($url);
}
else
{
$string .= file_get_contents(DRIVER_DIR . '/' . $url);
}
}
$obj->saveCache($string);
}
return str_replace('__JS__', $obj->get_contents(), $tpl2);
}
else
{
return '';
}
}
}
function css($url = null, $media = 'all')
{
static $buff;
static $tpl1 = "<link rel=\"stylesheet\" type=\"text/css\" href=\"__HREF__\" media=\"__MEDIA__\" />\n";
static $tpl2 = "<style type=\"text/css\" media=\"__MEDIA__\">__CSS__</style>";
$compress_css = isset(\icore\Application::get()->vars['compress_css']) && !empty(\icore\Application::get()->vars['compress_css']) ? intval(\icore\Application::get()->vars['compress_css']) : 0;
if (!empty($url))
{
if ($compress_css)
{
if (!isset($buff[$media]))
{
$buff[$media] = array();
}
$buff[$media][] = $url;
}
else
return str_replace(array('__HREF__', '__MEDIA__'), array($url, $media), $tpl1);
}
else
{
if ($compress_css)
{
$t = '';
foreach($buff as $media => $urls)
{
$key = VAR_CACHE_DIR . '/css_' . md5(CONFIG_FILE . serialize($urls));
$obj = \icore\cache\CssCache::get();
$obj->setKey($key);
if (!$obj->isCached())
{
$string = '';
foreach($urls as $url)
{
if (substr($url, 0, 4) === 'http')
{
$string .= file_get_contents($url);
}
else
{
$string .= file_get_contents(DRIVER_DIR . '/' . $url);
}
}
$obj->saveCache($string);
}
$t .= str_replace(array('__MEDIA__', '__CSS__'), array($media, $obj->get_contents()), $tpl2);
}
return $t;
}
else
{
return '';
}
}
}
/*
function i(\icore\Views $obj, $key, $default = null)
{
$args = func_get_args();
$ret = \icore\MultiLang::get()->translate($obj, $obj->$key);
if (count($args) > 2)
{
unset($args[0]);
$args[1] = $ret;
$ret = call_user_func_array('sprintf', $args);
}
if (empty($ret) && !empty($default))
{
$ret = $default;
}
print $ret;
}
*/