XPressME Integration Kit

Trac

source: trunk/include/xpress_block_theme.php @ 43

Last change on this file since 43 was 38, checked in by toemon, 16 years ago

ブロックのスタイルシートはテンプレート変数<{$xoops_block_header}>にアサインします。
使い方としては、xoopsテーマの<{$xoops_module_header}>の直後に<{$xoops_block_header}>を書き加えます。
上記実装 #44

ブロックのレンダリングを行う部分と、ブロック用CSSの場所をWordPressテーマ内にblocksというフォルダーを作成してその中に置く。 #46

File size: 2.1 KB
RevLine 
[38]1<?php
2function get_xpress_theme_name($mydirname)
3{
4        $xoopsDB =& Database::getInstance();
5        $wp_prefix = $mydirname;
6        if ($wp_prefix == 'wordpress') $wp_prefix = 'wp';
7
8        $module_tbl = $xoopsDB->prefix($wp_prefix).'_options'; 
9        $theme_name = '';       
10
11        $sql = "SELECT option_value FROM $module_tbl WHERE option_name LIKE 'template'";
12        $result =  $xoopsDB->query($sql, 0, 0);
13        if ($xoopsDB->getRowsNum($result)  > 0){
14                $row = $xoopsDB->fetchArray($result);
15                $theme_name = $row['option_value'];
16        }
17        return $theme_name;
18}
19
20function get_block_stylesheet_url($mydirname)
21{
22        $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
23        $select_theme = get_xpress_theme_name($mydirname);
24        $style_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/style.css';
25        if (file_exists($style_file))
26                return XOOPS_URL . '/modules/' .$mydirname . '/wp-content/themes/' . $select_theme . '/blocks/style.css';
27        else   
28                return XOOPS_URL . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/style.css';
29}
30
31function xpress_block_css_set($mydirname = '')
32{
33        if (empty($mydirname)) $mydirname = $mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
34
35        $style_url =  get_block_stylesheet_url($mydirname);
36         
37        $tplVars =& $GLOBALS['xoopsTpl']->get_template_vars();
38        $csslink = "\n".'<link rel="stylesheet" type="text/css" media="screen" href="'. $style_url .'" />';
39                if(array_key_exists('xoops_block_header', $tplVars)) {
40                        if (!strstr($tplVars['xoops_block_header'],$csslink)) {
41                                $GLOBALS['xoopsTpl']->assign('xoops_block_header',$tplVars['xoops_block_header'].$csslink);
42                        }
43                } else {
44                        $GLOBALS['xoopsTpl']->assign('xoops_block_header',$csslink);
45                }
46}
47function get_block_file_path($mydirname,$block_name)
48{
49        $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
50        $select_theme = get_xpress_theme_name($mydirname);
51        $block_file = $mydirpath . '/wp-content/themes/' . $select_theme . '/blocks/' . $block_name.'.php';
52
53        if (!file_exists($block_file))
54                $block_file =  XOOPS_ROOT_PATH . '/modules/' .$mydirname . '/wp-content/themes/xpress_default/blocks/' . $block_name .'.php';
55        return $block_file;
56}
57?>
Note: See TracBrowser for help on using the repository browser.