[44] | 1 | <?php
|
---|
[172] | 2 | if(!defined('XPRESS_BLOCK_RENDER_FUNCTION_READ')){
|
---|
| 3 | define('XPRESS_BLOCK_RENDER_FUNCTION_READ',1);
|
---|
[44] | 4 | require_once dirname( __FILE__ ) .'/xml.php' ;
|
---|
| 5 | require_once dirname( __FILE__ ) .'/xpress_cache.php' ;
|
---|
[98] | 6 | global $xoops_config;
|
---|
[44] | 7 |
|
---|
[98] | 8 | if (!is_object($xoops_config)){ // is call other modules
|
---|
[134] | 9 | require_once dirname(dirname( __FILE__ )) .'/class/config_from_xoops.class.php' ;
|
---|
[98] | 10 | $xoops_config = new ConfigFromXoops;
|
---|
| 11 | }
|
---|
| 12 |
|
---|
[44] | 13 | function xpress_block_cache_write($mydirname,$block_name,$block)
|
---|
| 14 | {
|
---|
| 15 | $xml = xpress_XML_serialize($block);
|
---|
| 16 | $xml_name = $block_name . '.xml';
|
---|
[364] | 17 | if (WPLANG == 'ja_EUC'){
|
---|
| 18 | $xml = str_replace('<?xml version="1.0" ?>', '<?xml version="1.0" encoding="EUC-JP" ?>' , $xml);
|
---|
| 19 | }
|
---|
[44] | 20 | xpress_cache_write($mydirname,$xml_name,$xml);
|
---|
| 21 | }
|
---|
| 22 | function xpress_block_cache_read($mydirname,$block_name)
|
---|
| 23 | {
|
---|
| 24 | $xml_name = $block_name . '.xml';
|
---|
| 25 | $xml_data = xpress_cache_read($mydirname,$xml_name);
|
---|
[387] | 26 |
|
---|
| 27 | $GLOBALS['DO_LIBXML_PATCH'] = get_xpress_mod_config($mydirname,'libxml_patch');
|
---|
| 28 |
|
---|
[364] | 29 | $ret = @xpress_XML_unserialize($xml_data);
|
---|
| 30 | if (strstr($xml_data, '<?xml version="1.0" encoding="EUC-JP" ?>') !== false){
|
---|
| 31 | $ans = mb_convert_variables('EUC-JP' , 'UTF-8', &$ret);
|
---|
| 32 | }
|
---|
| 33 | return $ret;
|
---|
[44] | 34 | }
|
---|
| 35 |
|
---|
| 36 | function get_block_id($mydirname,$func_file,$options)
|
---|
| 37 | {
|
---|
| 38 | $options_string = '';
|
---|
| 39 | foreach ($options as $val){
|
---|
| 40 | if (!empty($options_string)) $options_string .='|';
|
---|
| 41 | $options_string .= $val;
|
---|
| 42 | }
|
---|
| 43 | $xoopsDB =& Database::getInstance();
|
---|
| 44 | $block_tbl = $xoopsDB->prefix('newblocks');
|
---|
| 45 | $module_dir = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
|
---|
| 46 |
|
---|
| 47 | $sql = "SELECT bid FROM $block_tbl WHERE (func_file LIKE '$func_file') AND (options LIKE '$options_string')";
|
---|
| 48 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
| 49 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
| 50 | $row = $xoopsDB->fetchArray($result);
|
---|
| 51 | $block_id = $row['bid'];
|
---|
| 52 | }
|
---|
| 53 | return $block_id;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | function get_xpress_theme_name($mydirname)
|
---|
| 57 | {
|
---|
[46] | 58 | global $wpdb;
|
---|
| 59 |
|
---|
| 60 | if (is_null($wpdb)){
|
---|
| 61 | $xoopsDB =& Database::getInstance();
|
---|
| 62 | $wp_prefix = $mydirname;
|
---|
| 63 | if ($wp_prefix == 'wordpress') $wp_prefix = 'wp';
|
---|
[44] | 64 |
|
---|
[46] | 65 | $module_tbl = $xoopsDB->prefix($wp_prefix).'_options';
|
---|
| 66 | $theme_name = '';
|
---|
[44] | 67 |
|
---|
[46] | 68 | $sql = "SELECT option_value FROM $module_tbl WHERE option_name LIKE 'template'";
|
---|
| 69 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
| 70 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
| 71 | $row = $xoopsDB->fetchArray($result);
|
---|
| 72 | $theme_name = $row['option_value'];
|
---|
| 73 | }
|
---|
| 74 | } else {
|
---|
| 75 | $theme_name = get_option('template');
|
---|
[44] | 76 | }
|
---|
| 77 | return $theme_name;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | function get_block_stylesheet_url($mydirname)
|
---|
| 81 | {
|
---|
[95] | 82 | global $xoops_config;
|
---|
| 83 | $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
|
---|
[44] | 84 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
[116] | 85 | $style_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/block_style.css';
|
---|
[44] | 86 | if (file_exists($style_file))
|
---|
[116] | 87 | return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/' . $select_theme . '/blocks/block_style.css';
|
---|
[44] | 88 | else
|
---|
[116] | 89 | return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/block_style.css';
|
---|
[44] | 90 | }
|
---|
[165] | 91 |
|
---|
| 92 | function get_stylesheet_url($mydirname)
|
---|
| 93 | {
|
---|
| 94 | global $xoops_config;
|
---|
| 95 | $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
|
---|
| 96 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
| 97 | $style_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/style.css';
|
---|
| 98 | if (file_exists($style_file))
|
---|
| 99 | return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/' . $select_theme . '/style.css';
|
---|
| 100 | else
|
---|
| 101 | return $xoops_config->xoops_url . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/style.css';
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | function xpress_get_plugin_css($mydirname = '')
|
---|
| 105 | {
|
---|
| 106 | $this_url = '/modules/'. $mydirname;
|
---|
| 107 | $call_url = $_SERVER['REQUEST_URI'];
|
---|
| 108 | if (!strstr($call_url,$this_url)){
|
---|
| 109 | global $xoops_config;
|
---|
| 110 |
|
---|
| 111 | // Module Main CSS
|
---|
| 112 | $output = "\n".'<style type="text/css">@import url('.get_stylesheet_url($mydirname).');</style>';
|
---|
| 113 |
|
---|
| 114 | // hotDate
|
---|
| 115 | $output .= "\n".'<style type="text/css">@import url('.$xoops_config->module_url.'/wp-content/plugins/hotDates/hotDates.css);</style>';
|
---|
| 116 | return $output;
|
---|
| 117 | }
|
---|
| 118 | return '';
|
---|
| 119 | }
|
---|
[44] | 120 |
|
---|
| 121 | function xpress_block_css_set($mydirname = '')
|
---|
| 122 | {
|
---|
| 123 | $style_url = get_block_stylesheet_url($mydirname);
|
---|
[165] | 124 |
|
---|
[44] | 125 | $tplVars =& $GLOBALS['xoopsTpl']->get_template_vars();
|
---|
| 126 | $csslink = "\n".'<link rel="stylesheet" type="text/css" media="screen" href="'. $style_url .'" />';
|
---|
[165] | 127 | // Module Main CSS Plugin Css
|
---|
| 128 | $csslink .= xpress_get_plugin_css($mydirname);
|
---|
| 129 |
|
---|
[44] | 130 | if(array_key_exists('xoops_block_header', $tplVars)) {
|
---|
| 131 | if (!strstr($tplVars['xoops_block_header'],$csslink)) {
|
---|
| 132 | $GLOBALS['xoopsTpl']->assign('xoops_block_header',$tplVars['xoops_block_header'].$csslink);
|
---|
| 133 | }
|
---|
| 134 | } else {
|
---|
| 135 | $GLOBALS['xoopsTpl']->assign('xoops_block_header',$csslink);
|
---|
| 136 | }
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | function get_block_file_path($mydirname,$file_name)
|
---|
| 140 | {
|
---|
[95] | 141 | global $xoops_config;
|
---|
| 142 | $mydirpath = $xoops_config->xoops_root_path . '/modules/' . $mydirname;
|
---|
[44] | 143 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
| 144 | $block_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/' . $file_name;
|
---|
| 145 |
|
---|
| 146 | if (!file_exists($block_file))
|
---|
[95] | 147 | $block_file = $xoops_config->xoops_root_path . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/' . $file_name;
|
---|
[44] | 148 | return $block_file;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[96] | 151 | function xpress_block_cache_found($mydirname,$block_name)
|
---|
| 152 | {
|
---|
| 153 | global $xoops_config;
|
---|
| 154 | if(defined('XOOPS_ROOT_PATH')){
|
---|
| 155 | $cache_dir = XOOPS_ROOT_PATH . '/cache/';
|
---|
| 156 | } else {
|
---|
| 157 | $cache_dir = $xoops_config->xoops_root_path . '/cache/';
|
---|
| 158 | }
|
---|
| 159 | $xml_name = $block_name . '.xml';
|
---|
| 160 |
|
---|
| 161 | $filename = $cache_dir .$mydirname . '_' . $xml_name;
|
---|
| 162 | $cache_time = 0;
|
---|
| 163 | // if (file_exists($filename) && ((time() - filemtime($filename)) < $cache_time)) {
|
---|
| 164 | if (file_exists($filename)) {
|
---|
| 165 | return true;
|
---|
| 166 | } else {
|
---|
| 167 | return false;
|
---|
| 168 | }
|
---|
| 169 | }
|
---|
| 170 |
|
---|
[44] | 171 | function xpress_block_render($mydirname,$block_function_name,$options)
|
---|
| 172 | {
|
---|
| 173 | global $wpdb;
|
---|
| 174 | $func_file = $block_function_name;
|
---|
| 175 | $call_theme_function_name = str_replace(".php", "", $block_function_name);
|
---|
| 176 | $inc_theme_file_name = $call_theme_function_name . '_theme.php';
|
---|
| 177 | $cache_title = str_replace(".php", "", $block_function_name);
|
---|
[89] | 178 | $blockID =get_block_id($mydirname,$func_file,$options);
|
---|
| 179 |
|
---|
[96] | 180 | $this_url = '/modules/'. $mydirname;
|
---|
| 181 | $call_url = $_SERVER['REQUEST_URI'];
|
---|
[97] | 182 |
|
---|
| 183 | xpress_block_css_set($mydirname);
|
---|
| 184 | if (strstr($call_url,$this_url)){
|
---|
[44] | 185 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
| 186 | require_once $block_theme_file;
|
---|
| 187 | $block = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
| 188 | } else {
|
---|
[96] | 189 | if (xpress_block_cache_found($mydirname,$cache_title. $blockID)){
|
---|
| 190 | $xml = xpress_block_cache_read($mydirname,$cache_title. $blockID);
|
---|
| 191 | $block = $xml['block'];
|
---|
| 192 | } else {
|
---|
[183] | 193 | $block['err_message'] = sprintf(_MB_XP2_BLOCK_CACHE_ERR, '<a href="' . XOOPS_URL . '/modules/' . $mydirname . '">' . $mydirname .'</a>');
|
---|
[96] | 194 | }
|
---|
[44] | 195 | }
|
---|
[89] | 196 |
|
---|
| 197 | $templates_file = 'db:'.$mydirname. '_' . str_replace(".php", ".html", $block_function_name);
|
---|
| 198 | $tpl =& new XoopsTpl() ;
|
---|
| 199 | $tpl->assign( 'block' , $block ) ;
|
---|
| 200 | $ret['content'] = $tpl->fetch( $templates_file ) ;
|
---|
| 201 | return $ret ;
|
---|
[44] | 202 | }
|
---|
| 203 |
|
---|
[172] | 204 | function xpress_block_cache_refresh($mydirname)
|
---|
[135] | 205 | {
|
---|
| 206 | global $xoops_db;
|
---|
| 207 | $mid = get_xpress_modid();
|
---|
| 208 | $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid AND visible = 1";
|
---|
| 209 | $blocks = $xoops_db->get_results($sql);
|
---|
| 210 | require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
|
---|
| 211 |
|
---|
| 212 | foreach($blocks as $block){
|
---|
| 213 | $func_file = $block->func_file;
|
---|
| 214 | $call_theme_function_name = str_replace(".php", "", $func_file);
|
---|
| 215 | $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
|
---|
| 216 | $cache_title = str_replace(".php", "", $func_file);
|
---|
| 217 | $blockID = $block->bid;
|
---|
| 218 | $options = explode("|", $block->options);
|
---|
| 219 |
|
---|
| 220 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
| 221 | require_once $block_theme_file;
|
---|
| 222 | $render = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
| 223 | $render_array['block'] = $render;
|
---|
| 224 | $render_array['block']['options'] = $block->options;
|
---|
| 225 | if (xpress_block_cache_found($mydirname,$cache_title. $blockID)){
|
---|
| 226 | $render_serialize = xpress_XML_serialize($render_array);
|
---|
| 227 | $render_md5 = md5($render_serialize);
|
---|
| 228 |
|
---|
| 229 | $cache_serialize = xpress_cache_read($mydirname,$cache_title. $blockID.'.xml');
|
---|
| 230 | $cache_md5 = md5($cache_serialize);
|
---|
| 231 |
|
---|
| 232 | if ($render_md5 != $cache_md5){
|
---|
| 233 | xpress_block_cache_write($mydirname,$cache_title. $blockID, $render_array);
|
---|
| 234 | }
|
---|
| 235 | } else {
|
---|
| 236 | xpress_block_cache_write($mydirname,$cache_title. $blockID, $render_array);
|
---|
| 237 | }
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
| 240 |
|
---|
[172] | 241 | function xpress_unnecessary_block_cache_delete($mydirname)
|
---|
[135] | 242 | {
|
---|
| 243 | global $xoops_db,$xoops_config;
|
---|
| 244 | $mid = get_xpress_modid();
|
---|
| 245 | $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid AND visible = 1";
|
---|
| 246 | $blocks = $xoops_db->get_results($sql);
|
---|
| 247 | require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
|
---|
| 248 |
|
---|
| 249 | $pattern ='';
|
---|
| 250 | foreach($blocks as $block){
|
---|
| 251 | $cache_file_name = $mydirname . '_'. str_replace(".php", "", $block->func_file) . $block->bid;
|
---|
| 252 | if (!empty($pattern)) $pattern .= '|';
|
---|
| 253 | $pattern .= $cache_file_name;
|
---|
| 254 | }
|
---|
| 255 | $pattern = '(' . $pattern . ')';
|
---|
| 256 |
|
---|
| 257 | $cache_dir = $xoops_config->xoops_root_path . '/cache/';
|
---|
| 258 | $cache_time = 0;
|
---|
| 259 | if ($dh = opendir($cache_dir)) {
|
---|
| 260 | while (($file = readdir($dh)) !== false) {
|
---|
| 261 | if (preg_match('/^' . preg_quote($mydirname) . '/', $file)) {
|
---|
| 262 | if(! preg_match('/' . $pattern . '/', $file)) {
|
---|
| 263 | unlink($cache_dir.$file);
|
---|
| 264 | }
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 | closedir($dh);
|
---|
| 268 | }
|
---|
| 269 | }
|
---|
[387] | 270 |
|
---|
| 271 | function get_xpress_mod_config($mydirname,$conf_name=''){
|
---|
| 272 | $module_handler =& xoops_gethandler('module');
|
---|
| 273 | $xoopsModule =& $module_handler->getByDirname($mydirname);
|
---|
| 274 | $mid = $xoopsModule->getVar('mid');
|
---|
| 275 | $xoopsDB =& Database::getInstance();
|
---|
| 276 | $db_config = $xoopsDB->prefix('config');
|
---|
| 277 |
|
---|
| 278 | $wu_sql = "SELECT conf_value FROM $db_config ";
|
---|
| 279 | $wu_sql .= "WHERE (conf_modid = $mid ) AND (conf_name LIKE '$conf_name')";
|
---|
| 280 | $wu_res = $xoopsDB->queryF($wu_sql, 0, 0);
|
---|
| 281 |
|
---|
| 282 | if ($wu_res === false){
|
---|
| 283 | return 0;
|
---|
| 284 | } else {
|
---|
| 285 | $xu_row = $xoopsDB->fetchArray($wu_res);
|
---|
| 286 | return $xu_row['conf_value'];
|
---|
| 287 | }
|
---|
| 288 | }
|
---|
| 289 |
|
---|
[172] | 290 | }
|
---|
[44] | 291 | ?> |
---|