XPressME Integration Kit

Trac

source: trunk/wp-content/plugins/xpressme/include/xpress_common_functions.php @ 96

Last change on this file since 96 was 96, checked in by toemon, 15 years ago

途中経過でインストール、アップデートできなくなってしまっていたバグ修正
イベント通知の部分をFix、(ゲストのモジュールアクセス権限がないと通知できないのは直らない)
ブロックのキャッシュを見直し、キャッシュがない場合と、ブロックオプションが変更された場合にリフレッシュする機能を追加
ブロックキャッシュの更新にてポスト削除時のイベントをDB削除前にとっていたバグを修正。

File size: 3.6 KB
Line 
1<?php
2// xoops db
3function get_xpress_dir_path()
4{
5        return ABSPATH;
6}
7
8function get_xpress_dir_name()
9{
10        return basename(ABSPATH);
11}
12
13function get_wp_prefix_only()
14{
15        $dir_name = get_xpress_dir_name();
16        $prefix = $dir_name;
17        if ($prefix == 'wordpress') $prefix = 'wp';
18       
19        $prefix = $prefix . '_';
20        return $prefix;
21}
22
23function get_xoops_prefix()
24{
25        global $xoops_config;
26        $ret =$xoops_config->xoops_db_prefix . '_';
27        return $ret;
28}
29function get_wp_prefix()
30{
31        $prefix = get_xoops_prefix() . get_wp_prefix_only();
32        return $prefix;
33}
34
35function get_xpress_modid()
36{
37        global $xoops_db;
38       
39        $modulename = get_xpress_dir_name();   
40        $sql = "SELECT mid FROM " . get_xoops_prefix() . "modules WHERE dirname = '$modulename'";
41        $mid = $xoops_db->get_var($sql);
42        return $mid;   
43}
44
45function get_xpress_db_version()
46{
47        include get_xpress_dir_path() . '/wp-includes/version.php';
48        return $wp_db_version;
49}
50
51function is_block_cache_found($block_name)
52{
53        global $xoops_config;
54        $mydirname = get_xpress_dir_name();
55
56        if(defined('XOOPS_ROOT_PATH')){
57                $cache_dir = XOOPS_ROOT_PATH . '/cache/';
58        } else {
59                $cache_dir = $xoops_config->xoops_root_path . '/cache/';
60        }
61        $xml_name = $block_name . '.xml';
62
63    $filename = $cache_dir .$mydirname . '_' . $xml_name;
64        $cache_time = 0;
65//        if (file_exists($filename) && ((time() - filemtime($filename)) < $cache_time)) {
66    if (file_exists($filename)) {
67        return true;
68        } else {
69                return false;
70        }
71}
72
73
74//When there is no block cash, and an optional block is different, false is returned.
75function is_block_cache_normal()
76{
77        global $xoops_config;
78        global $xoops_db;
79        $mid = get_xpress_modid();
80        $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid ";
81        $blocks = $xoops_db->get_results($sql);
82        $mydirname = get_xpress_dir_name();
83        require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
84
85        foreach($blocks as $block){
86                $func_file = $block->func_file;
87                $call_theme_function_name = str_replace(".php", "", $func_file);
88                $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
89                $cache_title = str_replace(".php", "", $func_file);
90                $blockID = $block->bid;
91                $options = explode("|", $block->options);
92               
93                if (!is_block_cache_found($cache_title . $blockID)) return false;
94                $xml = xpress_block_cache_read($mydirname,$cache_title. $blockID);
95                $options = '';
96                $options = @$xml['block']['options'];
97                if( strcmp($options,$block->options) != 0 ) return false;
98        }
99        return true;
100}
101
102
103function block_cache_refresh()
104{
105        global $xoops_db;
106        $mid = get_xpress_modid();
107        $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid";
108        $blocks = $xoops_db->get_results($sql);
109        $mydirname = get_xpress_dir_name();
110        require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
111
112
113        foreach($blocks as $block){
114                $func_file = $block->func_file;
115                $call_theme_function_name = str_replace(".php", "", $func_file);
116                $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
117                $cache_title = str_replace(".php", "", $func_file);
118                $blockID = $block->bid;
119                $options = explode("|", $block->options);
120                                       
121                $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
122                require_once $block_theme_file;
123                $block_render = $call_theme_function_name($options);            //The block name and the called function name should be assumed to be the same name.                   
124                $xml['block'] = $block_render;
125                $xml['block']['options'] = $block->options;
126                xpress_block_cache_write($mydirname,$cache_title. $blockID, $xml);
127        }
128}
129
130?>
Note: See TracBrowser for help on using the repository browser.