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 | $dummy = __('After Blog address (URL) is set, it is necessary to set the permalink again.','xpressme');
|
---|
9 | $dummy = __('Can not access WordPress address (URL).','xpressme');
|
---|
10 | $dummy = __('WordPress Blog address (URL) is different from access URL.','xpressme');
|
---|
11 |
|
---|
12 |
|
---|
13 | function get_xoops_config($config_name,$module_dir){
|
---|
14 | global $xoops_db;
|
---|
15 |
|
---|
16 | $modules_db = get_xoops_prefix() . 'modules';
|
---|
17 | $config_db = get_xoops_prefix() . 'config';
|
---|
18 |
|
---|
19 | $moduleID = $xoops_db->get_var("SELECT mid FROM $modules_db WHERE dirname = '$module_dir'");
|
---|
20 | if (empty($moduleID)) return null;
|
---|
21 | $conf_value = $xoops_db->get_var("SELECT conf_value FROM $config_db WHERE (conf_modid = $moduleID) AND (conf_name = '$config_name')");
|
---|
22 | if (empty($conf_value)) return null;
|
---|
23 | return $conf_value;
|
---|
24 | }
|
---|
25 |
|
---|
26 | // xoops db
|
---|
27 | function get_xpress_dir_path()
|
---|
28 | {
|
---|
29 | return ABSPATH;
|
---|
30 | }
|
---|
31 |
|
---|
32 | function get_xpress_dir_name()
|
---|
33 | {
|
---|
34 | return basename(ABSPATH);
|
---|
35 | }
|
---|
36 |
|
---|
37 | function get_wp_prefix_only()
|
---|
38 | {
|
---|
39 | $dir_name = get_xpress_dir_name();
|
---|
40 | $prefix = preg_replace('/wordpress/','wp',$dir_name);
|
---|
41 |
|
---|
42 | $prefix = $prefix . '_';
|
---|
43 | return $prefix;
|
---|
44 | }
|
---|
45 |
|
---|
46 | function get_xoops_prefix()
|
---|
47 | {
|
---|
48 | global $xoops_config;
|
---|
49 | $ret =$xoops_config->xoops_db_prefix . '_';
|
---|
50 | return $ret;
|
---|
51 | }
|
---|
52 |
|
---|
53 | function get_xoops_trust_path()
|
---|
54 | {
|
---|
55 | global $xoops_config;
|
---|
56 | $ret =$xoops_config->xoops_trust_path;
|
---|
57 | return $ret;
|
---|
58 | }
|
---|
59 |
|
---|
60 | function get_xoops_root_path()
|
---|
61 | {
|
---|
62 | global $xoops_config;
|
---|
63 | $ret =$xoops_config->xoops_root_path;
|
---|
64 | return $ret;
|
---|
65 | }
|
---|
66 |
|
---|
67 | function get_wp_prefix()
|
---|
68 | {
|
---|
69 | $prefix = get_xoops_prefix() . get_wp_prefix_only();
|
---|
70 | return $prefix;
|
---|
71 | }
|
---|
72 | function get_xoops_url()
|
---|
73 | {
|
---|
74 | global $xoops_config;
|
---|
75 | $ret =$xoops_config->xoops_url ;
|
---|
76 | return $ret;
|
---|
77 | }
|
---|
78 |
|
---|
79 | function get_xpress_url()
|
---|
80 | {
|
---|
81 | global $xoops_config;
|
---|
82 | $ret =$xoops_config->module_url ;
|
---|
83 | return $ret;
|
---|
84 | }
|
---|
85 |
|
---|
86 | function get_xpress_modid()
|
---|
87 | {
|
---|
88 | global $xoops_db;
|
---|
89 |
|
---|
90 | $modulename = get_xpress_dir_name();
|
---|
91 | $sql = "SELECT mid FROM " . get_xoops_prefix() . "modules WHERE dirname = '$modulename'";
|
---|
92 | $mid = $xoops_db->get_var($sql);
|
---|
93 | return $mid;
|
---|
94 | }
|
---|
95 |
|
---|
96 | function get_xpress_db_version()
|
---|
97 | {
|
---|
98 | include get_xpress_dir_path() . '/wp-includes/version.php';
|
---|
99 | return $wp_db_version;
|
---|
100 | }
|
---|
101 |
|
---|
102 | function is_xpress_mobile()
|
---|
103 | {
|
---|
104 | //ktai_style
|
---|
105 | if (function_exists('is_ktai')){
|
---|
106 | if (is_ktai()) {
|
---|
107 | // $file_path = $GLOBALS['xoopsModuleConfig']["ktai_style_tmpdir"] . '/comments.php';
|
---|
108 | return true;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | //mobg
|
---|
113 | if (function_exists('is_mobile')) {
|
---|
114 | if (is_mobile()){
|
---|
115 | return true;
|
---|
116 | }
|
---|
117 | }
|
---|
118 | if (
|
---|
119 | preg_match("/DoCoMo/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
120 | preg_match("/softbank/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
121 | preg_match("/vodafone/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
122 | preg_match("/J-PHONE/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
123 | preg_match("/UP\.Browser/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
124 | preg_match("/ASTEL/", $_SERVER['HTTP_USER_AGENT']) ||
|
---|
125 | preg_match("/PDXGW/", $_SERVER['HTTP_USER_AGENT'])
|
---|
126 | )
|
---|
127 | {
|
---|
128 | return true;
|
---|
129 | } else {
|
---|
130 | return false;
|
---|
131 | }
|
---|
132 | }
|
---|
133 |
|
---|
134 | function block_cache_refresh()
|
---|
135 | {
|
---|
136 | global $xoops_db;
|
---|
137 | $mid = get_xpress_modid();
|
---|
138 | $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid";
|
---|
139 | $blocks = $xoops_db->get_results($sql);
|
---|
140 | $mydirname = get_xpress_dir_name();
|
---|
141 | require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
|
---|
142 |
|
---|
143 | foreach($blocks as $block){
|
---|
144 | $func_file = $block->func_file;
|
---|
145 |
|
---|
146 | // Avoid the failure of the operation when switch_to_blog() and other plugin code is called on the admin page.
|
---|
147 | $excludes = 'global_recent_posts_list_block\.php|enhanced_block\.php|global_recent_comments_block\.php|global_popular_posts_block\.php';
|
---|
148 | if (preg_match('/' . $excludes . '/' , $func_file)){
|
---|
149 | continue;
|
---|
150 | }
|
---|
151 |
|
---|
152 | $call_theme_function_name = str_replace(".php", "", $func_file);
|
---|
153 | $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
|
---|
154 | $cache_title = str_replace(".php", "", $func_file);
|
---|
155 | $blockID = $block->bid;
|
---|
156 | $options = explode("|", $block->options);
|
---|
157 |
|
---|
158 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
159 | require_once $block_theme_file['file_path'];
|
---|
160 | $block_render = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
161 | $xml['block'] = $block_render;
|
---|
162 | $xml['block']['options'] = $block->options;
|
---|
163 | xpress_block_cache_write($mydirname,$cache_title. $blockID, $xml);
|
---|
164 | }
|
---|
165 | }
|
---|
166 | function is_wordpress_style()
|
---|
167 | {
|
---|
168 | global $xpress_config;
|
---|
169 |
|
---|
170 | if ($xpress_config->viewer_type == 'wordpress') return true;
|
---|
171 | if ($xpress_config->viewer_type == 'xoops') return false;
|
---|
172 |
|
---|
173 | // user select
|
---|
174 | $get_style = isset($_GET["style"]) ? $_GET["style"] : '';
|
---|
175 | $cookie_style = isset($_COOKIE["xpress_style"]) ? $_COOKIE["xpress_style"] : '';
|
---|
176 |
|
---|
177 | // set style
|
---|
178 | if (!empty($get_style)){
|
---|
179 | $style = $get_style;
|
---|
180 | } else {
|
---|
181 | if (!empty($cookie_style)){
|
---|
182 | $style = $cookie_style;
|
---|
183 | } else {
|
---|
184 | $style = 'x';
|
---|
185 | }
|
---|
186 | }
|
---|
187 |
|
---|
188 | // set cookie
|
---|
189 | if (empty($cookie_style)){
|
---|
190 | setcookie("xpress_style", $style);
|
---|
191 | $_COOKIE["xpress_style"] = $style;
|
---|
192 | } else {
|
---|
193 | if ($style != $cookie_style) {
|
---|
194 | setcookie("xpress_style", $style);
|
---|
195 | $_COOKIE["xpress_style"] = $style;
|
---|
196 | }
|
---|
197 | }
|
---|
198 | if ($style == 'w') {
|
---|
199 | return true;
|
---|
200 | } else {
|
---|
201 | return false;
|
---|
202 | }
|
---|
203 | }
|
---|
204 |
|
---|
205 | function wp_meta_add_xpress_menu()
|
---|
206 | {
|
---|
207 | global $xpress_config;
|
---|
208 | if ($xpress_config->viewer_type == 'user_select'){
|
---|
209 | echo disp_mode_set();
|
---|
210 | }
|
---|
211 | if (function_exists('wp_theme_switcher') ) {
|
---|
212 | echo '<li>' . __('Themes') . ':';
|
---|
213 | wp_theme_switcher('dropdown');
|
---|
214 | echo '</li>';
|
---|
215 | }
|
---|
216 | }
|
---|
217 |
|
---|
218 | function disp_mode_set(){
|
---|
219 | global $xpress_config;
|
---|
220 |
|
---|
221 | $select ="";
|
---|
222 | if ($xpress_config->viewer_type == 'user_select'){
|
---|
223 | $style = isset($_GET["style"]) ? $_GET["style"] : (isset($_COOKIE["xpress_style"]) ? $_COOKIE["xpress_style"] : "");
|
---|
224 |
|
---|
225 | switch($style) {
|
---|
226 | case 'w':
|
---|
227 | $select ='<li><a href="'.get_settings('siteurl').'/?style=x" title="'. __('Switch to XOOPS mode','xpressme').'">'.__('Switch to XOOPS mode','xpressme').'</a></li>';
|
---|
228 | // $select.='<img src="'. get_settings('siteurl').'/images/external.png" alt="'.__('Switch to XOOPS mode','xpressme') . '"></a></li>';
|
---|
229 | break;
|
---|
230 | case 'x':
|
---|
231 | $select='<li><a href="'.get_settings('siteurl').'/?style=w" title="'.__('Switch to WordPress mode','xpressme').'">'.__('Switch to WordPress mode','xpressme').'</a></li>';
|
---|
232 | break;
|
---|
233 | default:
|
---|
234 | $select='<li><a href="'.get_settings('siteurl').'/?style=w" title="'.__('Switch to WordPress mode','xpressme').'">'.__('Switch to WordPress mode','xpressme').'</a></li>';
|
---|
235 | break;
|
---|
236 | }
|
---|
237 | }
|
---|
238 | return $select;
|
---|
239 | }
|
---|
240 |
|
---|
241 | function xpress_comment_count( $count ) {
|
---|
242 | global $id;
|
---|
243 | $post_comments =get_comments('status=approve&post_id=' . $id);
|
---|
244 | $comments_by_type = &separate_comments($post_comments);
|
---|
245 | return count($comments_by_type['comment']);
|
---|
246 | }
|
---|
247 |
|
---|
248 | function xpress_set_author_cookie($query_vars)
|
---|
249 | {
|
---|
250 | global $wp , $wpdb;
|
---|
251 |
|
---|
252 | if (is_admin()) return $query_vars;
|
---|
253 |
|
---|
254 | $author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
|
---|
255 | if(xpress_is_multi_user()){
|
---|
256 | if (!empty($_GET)){
|
---|
257 | $auth = intval( @$_GET["author"] );
|
---|
258 | if ($auth > 0){
|
---|
259 | setcookie($author_cookie, $auth, time()+3600, COOKIEPATH);
|
---|
260 | $_COOKIE[$author_cookie] = $auth;
|
---|
261 | }
|
---|
262 | } else {
|
---|
263 | if(xpress_is_wp_version('<','2.1')){ // Maybe, I think that it is ver2.1 or less.
|
---|
264 | if (!empty($wp->matched_query) ){
|
---|
265 | if (strpos($wp->matched_query,'author_name') !== false ){
|
---|
266 | $pattern = "author_name\s*=\s*(.*)\s*";
|
---|
267 | if ( preg_match ( "/".$pattern."/i", $wp->matched_query, $match ) ){
|
---|
268 | $author_name = "$match[1]";
|
---|
269 | $auth = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$author_name'");
|
---|
270 |
|
---|
271 | setcookie($author_cookie, $auth, time()+3600, COOKIEPATH);
|
---|
272 | $_COOKIE[$author_cookie] = $auth;
|
---|
273 | }
|
---|
274 | }
|
---|
275 | } else {
|
---|
276 | setcookie($author_cookie, 0, time()+3600, COOKIEPATH);
|
---|
277 | $_COOKIE[$author_cookie] = 0;
|
---|
278 | }
|
---|
279 | } else {
|
---|
280 | if (!empty($wp->query_vars) ){
|
---|
281 | if (!empty($wp->query_vars['author_name']) ){
|
---|
282 | $author_name = $wp->query_vars['author_name'];
|
---|
283 | $auth = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$author_name'");
|
---|
284 |
|
---|
285 | setcookie($author_cookie, $auth, time()+3600, COOKIEPATH);
|
---|
286 | $_COOKIE[$author_cookie] = $auth;
|
---|
287 | }
|
---|
288 | } else {
|
---|
289 | setcookie($author_cookie, 0, time()+3600, COOKIEPATH);
|
---|
290 | $_COOKIE[$author_cookie] = 0;
|
---|
291 | }
|
---|
292 | }
|
---|
293 | }
|
---|
294 | }else{
|
---|
295 | // $GLOBALS["wp_xoops_author"] = null;
|
---|
296 | setcookie($author_cookie, 0, time()+3600, COOKIEPATH);
|
---|
297 | $_COOKIE[$author_cookie] = 0;
|
---|
298 | }
|
---|
299 | return $query_vars;
|
---|
300 | }
|
---|
301 |
|
---|
302 | function xpress_query_filter($query)
|
---|
303 | {
|
---|
304 | if (is_admin()) return $query;
|
---|
305 |
|
---|
306 | $author_cookie = 'select_' . get_xpress_dir_name() . "_author" ;
|
---|
307 |
|
---|
308 | if (strpos($query,'SELECT') === false) return $query;
|
---|
309 |
|
---|
310 | $select_pattern = "SELECT(.*)post_author(.*)FROM";
|
---|
311 | if (preg_match ( "/".$select_pattern."/i", $query, $select_match ))
|
---|
312 | return $query;
|
---|
313 |
|
---|
314 | $query = preg_replace('/\s\s+/', ' ', $query);
|
---|
315 | if (!empty($_COOKIE[$author_cookie])){
|
---|
316 | if(xpress_is_wp_version('<','2.1')){
|
---|
317 | $pattern = "WHERE.*AND\s?\(*post_author\s*=";
|
---|
318 | if ( preg_match ( "/".$pattern."/i", $query, $match ) ){
|
---|
319 | return $query;
|
---|
320 | }
|
---|
321 | $pattern = "WHERE\s?post_author\s*="; // get_usernumposts()
|
---|
322 | if ( preg_match ( "/".$pattern."/i", $query, $match ) ){
|
---|
323 | return $query;
|
---|
324 | }
|
---|
325 | $pattern = "WHERE.*post_status\s*=\s*'publish'\s*\)?";
|
---|
326 | if ( preg_match ( "/".$pattern."/i", $query, $match ) ){
|
---|
327 |
|
---|
328 | $where_str = "$match[0]";
|
---|
329 | $where_arry = explode(' ',$where_str);
|
---|
330 | $post_prefix = '';
|
---|
331 | foreach ($where_arry as $p){
|
---|
332 | if ( preg_match ( "/post_status/", $p, $match3 ) ){
|
---|
333 | $post_prefix = preg_replace("/post_status/", "", $p);
|
---|
334 | $post_prefix = preg_replace("/\(/", "", $post_prefix);
|
---|
335 | break;
|
---|
336 | }
|
---|
337 | }
|
---|
338 | $patern = 'WHERE';
|
---|
339 | $replace = "WHERE {$post_prefix}post_author = " . intval($_COOKIE[$author_cookie]) . " AND ";
|
---|
340 | $query = preg_replace("/$patern/", $replace, $query);
|
---|
341 | }
|
---|
342 | } else {
|
---|
343 | $pattern = "WHERE.*post_type\s*=\s*'post'\s*\)?";
|
---|
344 | if ( preg_match ( "/".$pattern."/i", $query, $match ) ){
|
---|
345 | $where_str = "$match[0]";
|
---|
346 | $where_arry = explode(' ',$where_str);
|
---|
347 | $post_prefix = '';
|
---|
348 | foreach ($where_arry as $p){
|
---|
349 | if ( preg_match ( "/post_type/", $p, $match3 ) ){
|
---|
350 | $post_prefix = preg_replace("/post_type/", "", $p);
|
---|
351 | $post_prefix = preg_replace("/\(/", "", $post_prefix);
|
---|
352 | break;
|
---|
353 | }
|
---|
354 | }
|
---|
355 | preg_match ( "/post_type(.*)/", $where_str, $p_match );
|
---|
356 | $patern_s = $p_match[0];
|
---|
357 | $patern = preg_replace('/\)/', '\)', $patern_s);
|
---|
358 |
|
---|
359 | $replace = $patern_s . " AND {$post_prefix}post_author = " . intval($_COOKIE[$author_cookie]) . " ";
|
---|
360 |
|
---|
361 | $query = preg_replace("/$patern/", $replace, $query);
|
---|
362 | }
|
---|
363 | }
|
---|
364 | }
|
---|
365 | // xpress_show_sql_quary($query);
|
---|
366 | return $query;
|
---|
367 | }
|
---|
368 |
|
---|
369 | function get_block_file_path($mydirname,$file_name)
|
---|
370 | {
|
---|
371 | global $xoops_config, $xpress_config;
|
---|
372 | $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
|
---|
373 | $select_theme = xpress_ThemeTemplate(get_xpress_theme_name($mydirname));
|
---|
374 | $xpress_default_theme = 'xpress_default';
|
---|
375 | $select_block = '/wp-content/themes/' . $select_theme . '/blocks/' . $file_name;
|
---|
376 | $default_block = '/wp-content/themes/xpress_default/blocks/' . $file_name;
|
---|
377 | $select_block_path = $mydirpath . $select_block;
|
---|
378 | $default_block_path = $mydirpath . $default_block;
|
---|
379 |
|
---|
380 | $block_file_data = array();
|
---|
381 | $block_file_data['file_path'] = $default_block_path;
|
---|
382 | $block_file_data['error'] = '';
|
---|
383 |
|
---|
384 | if($select_theme != $xpress_default_theme){
|
---|
385 | if (file_exists($select_block_path)){
|
---|
386 | $select_block_version = get_block_version($select_block_path);
|
---|
387 | $default_block_version = get_block_version($default_block_path);
|
---|
388 | if (version_compare($select_block_version,$default_block_version, "<")){
|
---|
389 | $block_file_data['file_path'] = $default_block_path;
|
---|
390 | if ($xpress_config->is_block_error_display){
|
---|
391 | $error_str = '<div style="color:red">';
|
---|
392 | $error_str .= sprintf(__('Block file %1$s is an old version %2$s.<br />used block file %3$s of new version %4$s.','xpressme'),$select_block,$select_block_version,$default_block,$default_block_version);
|
---|
393 | $error_str .= '</div>';
|
---|
394 | $block_file_data['error'] = $error_str;
|
---|
395 | }
|
---|
396 | } else {
|
---|
397 | $block_file_data['file_path'] = $select_block_path;
|
---|
398 | $block_file_data['error'] = '';
|
---|
399 | }
|
---|
400 | }
|
---|
401 | }
|
---|
402 | return $block_file_data;
|
---|
403 | }
|
---|
404 |
|
---|
405 | function get_block_version($file_path = ''){
|
---|
406 | $array_file = file($file_path);
|
---|
407 | $pattern = '^[\s|\/]*[B|b]lock\s+[V|v]ersion\s*[:|;]\s*([0-9|.]*)';
|
---|
408 | $version = '0.1';
|
---|
409 | if (empty($file_path)) return $version;
|
---|
410 | if (!file_exists($file_path)) return $version;
|
---|
411 | if (count($array_file) > 5) $file_count = 5; else $file_count = count($array_file);
|
---|
412 | for ($i = 0 ; $i < $file_count ; $i++){
|
---|
413 | if (preg_match('/' . $pattern . '/' ,$array_file[$i],$matchs)){
|
---|
414 | $version = $matchs[1];
|
---|
415 | break;
|
---|
416 | }
|
---|
417 | }
|
---|
418 | return $version;
|
---|
419 | }
|
---|
420 |
|
---|
421 | function icon_exists($str = '')
|
---|
422 | {
|
---|
423 | global $xpress_config;
|
---|
424 | if (empty($str)) return false;
|
---|
425 | $root_path = $_SERVER['DOCUMENT_ROOT'];
|
---|
426 | $root_pattern = str_replace(".","\.",$root_path);
|
---|
427 | $root_pattern = '/'. str_replace("/","\/",$root_pattern) . '/';
|
---|
428 | $host = str_replace(".","\.",$_SERVER['SERVER_NAME']);
|
---|
429 | $pattern = "/https?:\/\/{$host}/";
|
---|
430 | if (preg_match($pattern,$str)){
|
---|
431 | $str = preg_replace($pattern,$root_path,$str);
|
---|
432 | } else if (!preg_match($root_pattern,$str)){
|
---|
433 | $str = $root_path.$str;
|
---|
434 | }
|
---|
435 | return file_exists($str);
|
---|
436 | }
|
---|
437 |
|
---|
438 | function is_buddypress_active(){
|
---|
439 | $active_plugins = get_option('active_plugins');
|
---|
440 | foreach($active_plugins as $active_plugin_path){
|
---|
441 | if (strpos($active_plugin_path,'buddypress')!==false) return true;
|
---|
442 | if (strpos($active_plugin_path,'bp-loader.php')!==false) return true;
|
---|
443 | }
|
---|
444 | return false;
|
---|
445 | }
|
---|
446 |
|
---|
447 | ?> |
---|