1 | <?php
|
---|
2 | require_once dirname( __FILE__ ) .'/xml.php' ;
|
---|
3 | require_once dirname( __FILE__ ) .'/xpress_cache.php' ;
|
---|
4 | global $xoops_config;
|
---|
5 |
|
---|
6 | if (!is_object($xoops_config)){ // is call other modules
|
---|
7 | require_once dirname(dirname( __FILE__ )) .'/class/config_from_xoops.class.php' ;
|
---|
8 | $xoops_config = new ConfigFromXoops;
|
---|
9 | }
|
---|
10 |
|
---|
11 | function xpress_block_cache_write($mydirname,$block_name,$block)
|
---|
12 | {
|
---|
13 | $xml = xpress_XML_serialize($block);
|
---|
14 | $xml_name = $block_name . '.xml';
|
---|
15 | xpress_cache_write($mydirname,$xml_name,$xml);
|
---|
16 | }
|
---|
17 | function xpress_block_cache_read($mydirname,$block_name)
|
---|
18 | {
|
---|
19 | $xml_name = $block_name . '.xml';
|
---|
20 | $xml_data = xpress_cache_read($mydirname,$xml_name);
|
---|
21 | return @xpress_XML_unserialize($xml_data);
|
---|
22 | }
|
---|
23 |
|
---|
24 | function get_block_id($mydirname,$func_file,$options)
|
---|
25 | {
|
---|
26 | $options_string = '';
|
---|
27 | foreach ($options as $val){
|
---|
28 | if (!empty($options_string)) $options_string .='|';
|
---|
29 | $options_string .= $val;
|
---|
30 | }
|
---|
31 | $xoopsDB =& Database::getInstance();
|
---|
32 | $block_tbl = $xoopsDB->prefix('newblocks');
|
---|
33 | $module_dir = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
|
---|
34 |
|
---|
35 | $sql = "SELECT bid FROM $block_tbl WHERE (func_file LIKE '$func_file') AND (options LIKE '$options_string')";
|
---|
36 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
37 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
38 | $row = $xoopsDB->fetchArray($result);
|
---|
39 | $block_id = $row['bid'];
|
---|
40 | }
|
---|
41 | return $block_id;
|
---|
42 | }
|
---|
43 |
|
---|
44 | function get_xpress_theme_name($mydirname)
|
---|
45 | {
|
---|
46 | global $wpdb;
|
---|
47 |
|
---|
48 | if (is_null($wpdb)){
|
---|
49 | $xoopsDB =& Database::getInstance();
|
---|
50 | $wp_prefix = $mydirname;
|
---|
51 | if ($wp_prefix == 'wordpress') $wp_prefix = 'wp';
|
---|
52 |
|
---|
53 | $module_tbl = $xoopsDB->prefix($wp_prefix).'_options';
|
---|
54 | $theme_name = '';
|
---|
55 |
|
---|
56 | $sql = "SELECT option_value FROM $module_tbl WHERE option_name LIKE 'template'";
|
---|
57 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
58 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
59 | $row = $xoopsDB->fetchArray($result);
|
---|
60 | $theme_name = $row['option_value'];
|
---|
61 | }
|
---|
62 | } else {
|
---|
63 | $theme_name = get_option('template');
|
---|
64 | }
|
---|
65 | return $theme_name;
|
---|
66 | }
|
---|
67 |
|
---|
68 | function get_block_stylesheet_url($mydirname)
|
---|
69 | {
|
---|
70 | global $xoops_config;
|
---|
71 | $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
|
---|
72 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
73 | $style_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/block_style.css';
|
---|
74 | if (file_exists($style_file))
|
---|
75 | return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/' . $select_theme . '/blocks/block_style.css';
|
---|
76 | else
|
---|
77 | return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/block_style.css';
|
---|
78 | }
|
---|
79 |
|
---|
80 | function xpress_block_css_set($mydirname = '')
|
---|
81 | {
|
---|
82 | $style_url = get_block_stylesheet_url($mydirname);
|
---|
83 |
|
---|
84 | $tplVars =& $GLOBALS['xoopsTpl']->get_template_vars();
|
---|
85 | $csslink = "\n".'<link rel="stylesheet" type="text/css" media="screen" href="'. $style_url .'" />';
|
---|
86 | if(array_key_exists('xoops_block_header', $tplVars)) {
|
---|
87 | if (!strstr($tplVars['xoops_block_header'],$csslink)) {
|
---|
88 | $GLOBALS['xoopsTpl']->assign('xoops_block_header',$tplVars['xoops_block_header'].$csslink);
|
---|
89 | }
|
---|
90 | } else {
|
---|
91 | $GLOBALS['xoopsTpl']->assign('xoops_block_header',$csslink);
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | function get_block_file_path($mydirname,$file_name)
|
---|
96 | {
|
---|
97 | global $xoops_config;
|
---|
98 | $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
|
---|
99 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
100 | $block_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/' . $file_name;
|
---|
101 |
|
---|
102 | if (!file_exists($block_file))
|
---|
103 | $block_file = $xoops_config->xoops_root_path . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/' . $file_name;
|
---|
104 | return $block_file;
|
---|
105 | }
|
---|
106 |
|
---|
107 | function xpress_block_cache_found($mydirname,$block_name)
|
---|
108 | {
|
---|
109 | global $xoops_config;
|
---|
110 | if(defined('XOOPS_ROOT_PATH')){
|
---|
111 | $cache_dir = XOOPS_ROOT_PATH . '/cache/';
|
---|
112 | } else {
|
---|
113 | $cache_dir = $xoops_config->xoops_root_path . '/cache/';
|
---|
114 | }
|
---|
115 | $xml_name = $block_name . '.xml';
|
---|
116 |
|
---|
117 | $filename = $cache_dir .$mydirname . '_' . $xml_name;
|
---|
118 | $cache_time = 0;
|
---|
119 | // if (file_exists($filename) && ((time() - filemtime($filename)) < $cache_time)) {
|
---|
120 | if (file_exists($filename)) {
|
---|
121 | return true;
|
---|
122 | } else {
|
---|
123 | return false;
|
---|
124 | }
|
---|
125 | }
|
---|
126 |
|
---|
127 | function xpress_block_render($mydirname,$block_function_name,$options)
|
---|
128 | {
|
---|
129 | global $wpdb;
|
---|
130 | $func_file = $block_function_name;
|
---|
131 | $call_theme_function_name = str_replace(".php", "", $block_function_name);
|
---|
132 | $inc_theme_file_name = $call_theme_function_name . '_theme.php';
|
---|
133 | $cache_title = str_replace(".php", "", $block_function_name);
|
---|
134 | $blockID =get_block_id($mydirname,$func_file,$options);
|
---|
135 |
|
---|
136 | $this_url = '/modules/'. $mydirname;
|
---|
137 | $call_url = $_SERVER['REQUEST_URI'];
|
---|
138 |
|
---|
139 | xpress_block_css_set($mydirname);
|
---|
140 | if (strstr($call_url,$this_url)){
|
---|
141 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
142 | require_once $block_theme_file;
|
---|
143 | $block = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
144 | } else {
|
---|
145 | if (xpress_block_cache_found($mydirname,$cache_title. $blockID)){
|
---|
146 | $xml = xpress_block_cache_read($mydirname,$cache_title. $blockID);
|
---|
147 | $block = $xml['block'];
|
---|
148 | } else {
|
---|
149 | $block['err_message'] = sprintf(_MB_XPRESS_BLOCK_CACHE_ERR, '<a href="' . XOOPS_URL . '/modules/' . $mydirname . '">' . $mydirname .'</a>');
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | $templates_file = 'db:'.$mydirname. '_' . str_replace(".php", ".html", $block_function_name);
|
---|
154 | $tpl =& new XoopsTpl() ;
|
---|
155 | $tpl->assign( 'block' , $block ) ;
|
---|
156 | $ret['content'] = $tpl->fetch( $templates_file ) ;
|
---|
157 | return $ret ;
|
---|
158 | }
|
---|
159 |
|
---|
160 | ?> |
---|