1 | <?php
|
---|
2 | require_once dirname( __FILE__ ) .'/xml.php' ;
|
---|
3 | require_once dirname( __FILE__ ) .'/xpress_cache.php' ;
|
---|
4 |
|
---|
5 | function xpress_block_cache_write($mydirname,$block_name,$block)
|
---|
6 | {
|
---|
7 | $xml = xpress_XML_serialize($block);
|
---|
8 | $xml_name = $block_name . '.xml';
|
---|
9 | xpress_cache_write($mydirname,$xml_name,$xml);
|
---|
10 | }
|
---|
11 | function xpress_block_cache_read($mydirname,$block_name)
|
---|
12 | {
|
---|
13 | $xml_name = $block_name . '.xml';
|
---|
14 | $xml_data = xpress_cache_read($mydirname,$xml_name);
|
---|
15 | return @xpress_XML_unserialize($xml_data);
|
---|
16 | }
|
---|
17 |
|
---|
18 | function get_block_id($mydirname,$func_file,$options)
|
---|
19 | {
|
---|
20 | $options_string = '';
|
---|
21 | foreach ($options as $val){
|
---|
22 | if (!empty($options_string)) $options_string .='|';
|
---|
23 | $options_string .= $val;
|
---|
24 | }
|
---|
25 | $xoopsDB =& Database::getInstance();
|
---|
26 | $block_tbl = $xoopsDB->prefix('newblocks');
|
---|
27 | $module_dir = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
|
---|
28 |
|
---|
29 | $sql = "SELECT bid FROM $block_tbl WHERE (func_file LIKE '$func_file') AND (options LIKE '$options_string')";
|
---|
30 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
31 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
32 | $row = $xoopsDB->fetchArray($result);
|
---|
33 | $block_id = $row['bid'];
|
---|
34 | }
|
---|
35 | return $block_id;
|
---|
36 | }
|
---|
37 |
|
---|
38 | function get_xpress_theme_name($mydirname)
|
---|
39 | {
|
---|
40 | $xoopsDB =& Database::getInstance();
|
---|
41 | $wp_prefix = $mydirname;
|
---|
42 | if ($wp_prefix == 'wordpress') $wp_prefix = 'wp';
|
---|
43 |
|
---|
44 | $module_tbl = $xoopsDB->prefix($wp_prefix).'_options';
|
---|
45 | $theme_name = '';
|
---|
46 |
|
---|
47 | $sql = "SELECT option_value FROM $module_tbl WHERE option_name LIKE 'template'";
|
---|
48 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
49 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
50 | $row = $xoopsDB->fetchArray($result);
|
---|
51 | $theme_name = $row['option_value'];
|
---|
52 | }
|
---|
53 | return $theme_name;
|
---|
54 | }
|
---|
55 |
|
---|
56 | function get_block_stylesheet_url($mydirname)
|
---|
57 | {
|
---|
58 | $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
|
---|
59 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
60 | $style_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/style.css';
|
---|
61 | if (file_exists($style_file))
|
---|
62 | return XOOPS_URL . '/modules/' .$mydirname . '/wp-content/themes/' . $select_theme . '/blocks/style.css';
|
---|
63 | else
|
---|
64 | return XOOPS_URL . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/style.css';
|
---|
65 | }
|
---|
66 |
|
---|
67 | function xpress_block_css_set($mydirname = '')
|
---|
68 | {
|
---|
69 | $style_url = get_block_stylesheet_url($mydirname);
|
---|
70 |
|
---|
71 | $tplVars =& $GLOBALS['xoopsTpl']->get_template_vars();
|
---|
72 | $csslink = "\n".'<link rel="stylesheet" type="text/css" media="screen" href="'. $style_url .'" />';
|
---|
73 | if(array_key_exists('xoops_block_header', $tplVars)) {
|
---|
74 | if (!strstr($tplVars['xoops_block_header'],$csslink)) {
|
---|
75 | $GLOBALS['xoopsTpl']->assign('xoops_block_header',$tplVars['xoops_block_header'].$csslink);
|
---|
76 | }
|
---|
77 | } else {
|
---|
78 | $GLOBALS['xoopsTpl']->assign('xoops_block_header',$csslink);
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | function get_block_file_path($mydirname,$file_name)
|
---|
83 | {
|
---|
84 | $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
|
---|
85 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
86 | $block_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/' . $file_name;
|
---|
87 |
|
---|
88 | if (!file_exists($block_file))
|
---|
89 | $block_file = XOOPS_ROOT_PATH . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/' . $file_name;
|
---|
90 | return $block_file;
|
---|
91 | }
|
---|
92 |
|
---|
93 | function xpress_block_render($mydirname,$block_function_name,$options)
|
---|
94 | {
|
---|
95 | global $wpdb;
|
---|
96 | $func_file = $block_function_name;
|
---|
97 | $call_theme_function_name = str_replace(".php", "", $block_function_name);
|
---|
98 | $inc_theme_file_name = $call_theme_function_name . '_theme.php';
|
---|
99 | $cache_title = str_replace(".php", "", $block_function_name);
|
---|
100 | $blockID =get_block_id($mydirname,$func_file,$options);
|
---|
101 |
|
---|
102 | if (!is_null($wpdb)){
|
---|
103 | xpress_block_css_set($mydirname);
|
---|
104 |
|
---|
105 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
106 | require_once $block_theme_file;
|
---|
107 | $block = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
108 |
|
---|
109 | xpress_block_cache_write($mydirname,$cache_title. $blockID, $block);
|
---|
110 | } else {
|
---|
111 | $block = xpress_block_cache_read($mydirname,$cache_title. $blockID);
|
---|
112 | }
|
---|
113 | return $block;
|
---|
114 | }
|
---|
115 |
|
---|
116 | ?> |
---|