[44] | 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 | {
|
---|
[46] | 40 | global $wpdb;
|
---|
| 41 |
|
---|
| 42 | if (is_null($wpdb)){
|
---|
| 43 | $xoopsDB =& Database::getInstance();
|
---|
| 44 | $wp_prefix = $mydirname;
|
---|
| 45 | if ($wp_prefix == 'wordpress') $wp_prefix = 'wp';
|
---|
[44] | 46 |
|
---|
[46] | 47 | $module_tbl = $xoopsDB->prefix($wp_prefix).'_options';
|
---|
| 48 | $theme_name = '';
|
---|
[44] | 49 |
|
---|
[46] | 50 | $sql = "SELECT option_value FROM $module_tbl WHERE option_name LIKE 'template'";
|
---|
| 51 | $result = $xoopsDB->query($sql, 0, 0);
|
---|
| 52 | if ($xoopsDB->getRowsNum($result) > 0){
|
---|
| 53 | $row = $xoopsDB->fetchArray($result);
|
---|
| 54 | $theme_name = $row['option_value'];
|
---|
| 55 | }
|
---|
| 56 | } else {
|
---|
| 57 | $theme_name = get_option('template');
|
---|
[44] | 58 | }
|
---|
| 59 | return $theme_name;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | function get_block_stylesheet_url($mydirname)
|
---|
| 63 | {
|
---|
| 64 | $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
|
---|
| 65 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
| 66 | $style_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/style.css';
|
---|
| 67 | if (file_exists($style_file))
|
---|
| 68 | return XOOPS_URL . '/modules/' .$mydirname . '/wp-content/themes/' . $select_theme . '/blocks/style.css';
|
---|
| 69 | else
|
---|
| 70 | return XOOPS_URL . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/style.css';
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | function xpress_block_css_set($mydirname = '')
|
---|
| 74 | {
|
---|
| 75 | $style_url = get_block_stylesheet_url($mydirname);
|
---|
| 76 |
|
---|
| 77 | $tplVars =& $GLOBALS['xoopsTpl']->get_template_vars();
|
---|
| 78 | $csslink = "\n".'<link rel="stylesheet" type="text/css" media="screen" href="'. $style_url .'" />';
|
---|
| 79 | if(array_key_exists('xoops_block_header', $tplVars)) {
|
---|
| 80 | if (!strstr($tplVars['xoops_block_header'],$csslink)) {
|
---|
| 81 | $GLOBALS['xoopsTpl']->assign('xoops_block_header',$tplVars['xoops_block_header'].$csslink);
|
---|
| 82 | }
|
---|
| 83 | } else {
|
---|
| 84 | $GLOBALS['xoopsTpl']->assign('xoops_block_header',$csslink);
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | function get_block_file_path($mydirname,$file_name)
|
---|
| 89 | {
|
---|
| 90 | $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
|
---|
| 91 | $select_theme = get_xpress_theme_name($mydirname);
|
---|
| 92 | $block_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/' . $file_name;
|
---|
| 93 |
|
---|
| 94 | if (!file_exists($block_file))
|
---|
| 95 | $block_file = XOOPS_ROOT_PATH . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/' . $file_name;
|
---|
| 96 | return $block_file;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | function xpress_block_render($mydirname,$block_function_name,$options)
|
---|
| 100 | {
|
---|
| 101 | global $wpdb;
|
---|
| 102 | $func_file = $block_function_name;
|
---|
| 103 | $call_theme_function_name = str_replace(".php", "", $block_function_name);
|
---|
| 104 | $inc_theme_file_name = $call_theme_function_name . '_theme.php';
|
---|
| 105 | $cache_title = str_replace(".php", "", $block_function_name);
|
---|
[89] | 106 | $blockID =get_block_id($mydirname,$func_file,$options);
|
---|
| 107 |
|
---|
[44] | 108 | if (!is_null($wpdb)){
|
---|
| 109 | xpress_block_css_set($mydirname);
|
---|
| 110 |
|
---|
| 111 | $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name);
|
---|
| 112 | require_once $block_theme_file;
|
---|
| 113 | $block = $call_theme_function_name($options); //The block name and the called function name should be assumed to be the same name.
|
---|
[46] | 114 |
|
---|
| 115 | // Not Cache Write Now. Becose Cache Write On WordPress Event
|
---|
| 116 | // xpress_block_cache_write($mydirname,$cache_title. $blockID, $block);
|
---|
[44] | 117 | } else {
|
---|
[49] | 118 | $xml = xpress_block_cache_read($mydirname,$cache_title. $blockID);
|
---|
| 119 | $block = $xml['block'];
|
---|
[44] | 120 | }
|
---|
[89] | 121 |
|
---|
| 122 | $templates_file = 'db:'.$mydirname. '_' . str_replace(".php", ".html", $block_function_name);
|
---|
| 123 | $tpl =& new XoopsTpl() ;
|
---|
| 124 | $tpl->assign( 'block' , $block ) ;
|
---|
| 125 | $ret['content'] = $tpl->fetch( $templates_file ) ;
|
---|
| 126 | return $ret ;
|
---|
[44] | 127 | }
|
---|
| 128 |
|
---|
| 129 | ?> |
---|