1 | <?php
|
---|
2 | global $xoops_config;
|
---|
3 | if (!is_object($xoops_config)){ // is call other modules
|
---|
4 | require_once dirname(dirname(dirname(dirname(dirname( __FILE__ ))))) .'/class/config_from_xoops.class.php' ;
|
---|
5 | $xoops_config = new ConfigFromXoops;
|
---|
6 | }
|
---|
7 |
|
---|
8 | function get_xoops_config($config_name,$module_dir){
|
---|
9 | global $xoops_db;
|
---|
10 |
|
---|
11 | $modules_db = get_xoops_prefix() . 'modules';
|
---|
12 | $config_db = get_xoops_prefix() . 'config';
|
---|
13 |
|
---|
14 | $moduleID = $xoops_db->get_var("SELECT mid FROM $modules_db WHERE dirname = '$module_dir'");
|
---|
15 | if (empty($moduleID)) return null;
|
---|
16 | $conf_value = $xoops_db->get_var("SELECT conf_value FROM $config_db WHERE (conf_modid = $moduleID) AND (conf_name = '$config_name')");
|
---|
17 | if (empty($conf_value)) return null;
|
---|
18 | return $conf_value;
|
---|
19 | }
|
---|
20 |
|
---|
21 | // xoops db
|
---|
22 | function get_xpress_dir_path()
|
---|
23 | {
|
---|
24 | return ABSPATH;
|
---|
25 | }
|
---|
26 |
|
---|
27 | function get_xpress_dir_name()
|
---|
28 | {
|
---|
29 | return basename(ABSPATH);
|
---|
30 | }
|
---|
31 |
|
---|
32 | function get_wp_prefix_only()
|
---|
33 | {
|
---|
34 | $dir_name = get_xpress_dir_name();
|
---|
35 | $prefix = $dir_name;
|
---|
36 | if ($prefix == 'wordpress') $prefix = 'wp';
|
---|
37 |
|
---|
38 | $prefix = $prefix . '_';
|
---|
39 | return $prefix;
|
---|
40 | }
|
---|
41 |
|
---|
42 | function get_xoops_prefix()
|
---|
43 | {
|
---|
44 | global $xoops_config;
|
---|
45 | $ret =$xoops_config->xoops_db_prefix . '_';
|
---|
46 | return $ret;
|
---|
47 | }
|
---|
48 |
|
---|
49 | function get_xoops_trust_path()
|
---|
50 | {
|
---|
51 | global $xoops_config;
|
---|
52 | $ret =$xoops_config->xoops_trust_path;
|
---|
53 | return $ret;
|
---|
54 | }
|
---|
55 |
|
---|
56 | function get_xoops_root_path()
|
---|
57 | {
|
---|
58 | global $xoops_config;
|
---|
59 | $ret =$xoops_config->xoops_root_path;
|
---|
60 | return $ret;
|
---|
61 | }
|
---|
62 |
|
---|
63 | function get_wp_prefix()
|
---|
64 | {
|
---|
65 | $prefix = get_xoops_prefix() . get_wp_prefix_only();
|
---|
66 | return $prefix;
|
---|
67 | }
|
---|
68 |
|
---|
69 | function get_xpress_modid()
|
---|
70 | {
|
---|
71 | global $xoops_db;
|
---|
72 |
|
---|
73 | $modulename = get_xpress_dir_name();
|
---|
74 | $sql = "SELECT mid FROM " . get_xoops_prefix() . "modules WHERE dirname = '$modulename'";
|
---|
75 | $mid = $xoops_db->get_var($sql);
|
---|
76 | return $mid;
|
---|
77 | }
|
---|
78 |
|
---|
79 | function get_xpress_db_version()
|
---|
80 | {
|
---|
81 | include get_xpress_dir_path() . '/wp-includes/version.php';
|
---|
82 | return $wp_db_version;
|
---|
83 | }
|
---|
84 |
|
---|
85 | function is_xpress_mobile()
|
---|
86 | {
|
---|
87 | //ktai_style
|
---|
88 | if (function_exists('is_ktai')){
|
---|
89 | if (is_ktai()) {
|
---|
90 | // $file_path = $GLOBALS['xoopsModuleConfig']["ktai_style_tmpdir"] . '/comments.php';
|
---|
91 | return true;
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | //mobg
|
---|
96 | if (function_exists('is_mobile')) {
|
---|
97 | if (is_mobile()){
|
---|
98 | return true;
|
---|
99 | }
|
---|
100 | }
|
---|
101 | if (
|
---|
102 | preg_match("/DoCoMo/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
103 | preg_match("/softbank/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
104 | preg_match("/vodafone/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
105 | preg_match("/J-PHONE/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
106 | preg_match("/UP\.Browser/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
107 | preg_match("/ASTEL/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
108 | preg_match("/PDXGW/", $_SERVER['HTTP_USER_AGENT'])
|
---|
109 | )
|
---|
110 | {
|
---|
111 | return true;
|
---|
112 | } else {
|
---|
113 | return false;
|
---|
114 | }
|
---|
115 |
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | function is_block_cache_found($block_name)
|
---|
120 | {
|
---|
121 | global $xoops_config;
|
---|
122 | $mydirname = get_xpress_dir_name();
|
---|
123 |
|
---|
124 | if(defined('XOOPS_ROOT_PATH')){
|
---|
125 | $cache_dir = XOOPS_ROOT_PATH . '/cache/';
|
---|
126 | } else {
|
---|
127 | $cache_dir = $xoops_config->xoops_root_path . '/cache/';
|
---|
128 | }
|
---|
129 | $xml_name = $block_name . '.xml';
|
---|
130 |
|
---|
131 | $filename = $cache_dir .$mydirname . '_' . $xml_name;
|
---|
132 | $cache_time = 0;
|
---|
133 | // if (file_exists($filename) && ((time() - filemtime($filename)) < $cache_time)) {
|
---|
134 | if (file_exists($filename)) {
|
---|
135 | return true;
|
---|
136 | } else {
|
---|
137 | return false;
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|
142 | //When there is no block cash, and an optional block is different, false is returned.
|
---|
143 | function is_block_cache_normal()
|
---|
144 | {
|
---|
145 | global $xoops_config;
|
---|
146 | global $xoops_db;
|
---|
147 | $mid = get_xpress_modid();
|
---|
148 | $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid ";
|
---|
149 | $blocks = $xoops_db->get_results($sql);
|
---|
150 | $mydirname = get_xpress_dir_name();
|
---|
151 | require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
|
---|
152 |
|
---|
153 | foreach($blocks as $block){
|
---|
154 | $func_file = $block->func_file;
|
---|
155 | $call_theme_function_name = str_replace(".php", "", $func_file);
|
---|
156 | $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
|
---|
157 | $cache_title = str_replace(".php", "", $func_file);
|
---|
158 | $blockID = $block->bid;
|
---|
159 | $options = explode("|", $block->options);
|
---|
160 |
|
---|
161 | if (!is_block_cache_found($cache_title . $blockID)) return false;
|
---|
162 | $xml = xpress_block_cache_read($mydirname,$cache_title. $blockID);
|
---|
163 | $options = '';
|
---|
164 | $options = @$xml['block']['options'];
|
---|
165 | if( strcmp($options,$block->options) != 0 ) return false;
|
---|
166 | }
|
---|
167 | return true;
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | function block_cache_refresh()
|
---|
172 | {
|
---|
173 | global $xoops_db;
|
---|
174 | $mid = get_xpress_modid();
|
---|
175 | $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid";
|
---|
176 | $blocks = $xoops_db->get_results($sql);
|
---|
177 | $mydirname = get_xpress_dir_name();
|
---|
178 | require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
|
---|
179 |
|
---|
180 |
|
---|
181 | foreach($blocks as $block){
|
---|
182 | $func_file = $block->func_file;
|
---|
183 | $call_theme_function_name = str_replace(".php", "", $func_file);
|
---|
184 | $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
|
---|
185 | $cache_title = str_replace(".php", "", $func_file);
|
---|
186 | $blockID = $block->bid;
|
---|
187 | $options = explode("|", $block->options);
|
---|
188 |
|
---|
189 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
190 | require_once $block_theme_file;
|
---|
191 | $block_render = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
192 | $xml['block'] = $block_render;
|
---|
193 | $xml['block']['options'] = $block->options;
|
---|
194 | xpress_block_cache_write($mydirname,$cache_title. $blockID, $xml);
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | ?> |
---|