XPressME Integration Kit

Trac

Changeset 46


Ignore:
Timestamp:
Dec 26, 2008, 12:15:54 AM (15 years ago)
Author:
toemon
Message:

WordPress管理画面からXOOPSデータベースへのアクセス  #50 実装

xpressmeプラグインにより
XOOPS管理外(WordPress管理下)から$xoops_db(wpdbクラス)にてアクセス可能にしました。

コメントブロックのキャッシュへの書き込みを、WordPressのイベント(変更・追加・削除)へ書き込むよにしました。

このためコメントブロックのshow_function側からはキャッシュへの書き込みを削除してあります。

  

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/blocks/recent_comments_block.php

    r44 r46  
    6666                require_once $mydirpath.'/include/xpress_block_render.php'; 
    6767                return xpress_block_render($mydirname,$block_function_name,$options); 
    68 /* 
    69  
    70                 $mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ; 
    71                 $disp_count = empty( $options[1] ) ? '10' : $options[1] ; 
    72                 $disp_length = empty( $options[2] ) ? '30' : $options[2] ; 
    73                 $selected = array_slice($options,3); // get allowed cats 
    74                  
    75                 $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname; 
    76                 global $wpdb; 
    77                  
    78                 if (!is_null($wpdb)){ 
    79                         require_once $mydirpath.'/include/xpress_block_theme.php'; 
    80                         xpress_block_css_set($mydirname); 
    81                          
    82                         $block_theme_file = get_block_file_path($mydirname,'recent_comments_block'); 
    83                         require_once $block_theme_file; 
    84                         $block = recent_comments_block($options); 
    85                          
    86                         require_once $mydirpath.'/include/xoops_block_cache.php'; 
    87                         $my_name = basename( __FILE__ ); 
    88                         $blockID =get_block_id($mydirname,$my_name,$options);                    
    89                         xpress_block_cache_write($mydirname,'recent_comments_block'. $blockID, $block); 
    90                 } else { 
    91                         require_once $mydirpath.'/include/xoops_block_cache.php'; 
    92                         $my_name = basename( __FILE__ ); 
    93                         $blockID =get_block_id($mydirname,$my_name,$options);                    
    94                         $block = xpress_block_cache_read($mydirname,'recent_comments_block'. $blockID); 
    95                 } 
    96                 return  $block; 
    97 */ 
    9868        } 
    9969} 
  • trunk/include/xpress_block_render.php

    r44 r46  
    3838        function get_xpress_theme_name($mydirname) 
    3939        { 
    40                 $xoopsDB =& Database::getInstance(); 
    41                 $wp_prefix = $mydirname; 
    42                 if ($wp_prefix == 'wordpress') $wp_prefix = 'wp'; 
     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'; 
    4346 
    44                 $module_tbl = $xoopsDB->prefix($wp_prefix).'_options';   
    45                 $theme_name = '';        
     47                        $module_tbl = $xoopsDB->prefix($wp_prefix).'_options';   
     48                        $theme_name = '';        
    4649 
    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']; 
     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'); 
    5258                } 
    5359                return $theme_name; 
     
    106112                        require_once $block_theme_file; 
    107113                        $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); 
     114 
     115// Not Cache Write Now.  Becose Cache Write On WordPress Event                   
     116//                      xpress_block_cache_write($mydirname,$cache_title. $blockID, $block);   
    110117                } else { 
    111118                        $block = xpress_block_cache_read($mydirname,$cache_title. $blockID); 
  • trunk/wp-content/plugins/xpressme/include/custom_functions.php

    r33 r46  
    133133                echo $ret;       
    134134} 
     135function xpress_substr($str, $start, $length, $trimmarker = '...') 
     136{ 
     137    if (function_exists('mb_substr')){ 
     138        $str2 = mb_substr( $str , $start , $length); 
     139        return $str2 . ( mb_strlen($str)!=mb_strlen($str2) ? $trimmarker : '' ); 
     140    } else { 
     141        return ( strlen($str) - $start <= $length ) ? substr( $str, $start, $length ) : substr( $str, $start, $length - strlen($trimmarker) ) . $trimmarker; 
     142    } 
     143} 
     144// xoops db 
     145function get_xpress_dir_path() 
     146{ 
     147        return ABSPATH; 
     148} 
     149 
     150function get_xpress_dir_name() 
     151{ 
     152        return basename(ABSPATH); 
     153} 
     154 
     155function get_wp_prefix_only() 
     156{ 
     157        $dir_name = get_xpress_dir_name(); 
     158        $prefix = $dir_name; 
     159        if ($prefix == 'wordpress') $prefix = 'wp'; 
     160         
     161        $prefix = $prefix . '_'; 
     162        return $prefix; 
     163} 
     164 
     165function get_xoops_prefix() 
     166{ 
     167        global $wpdb; 
     168         
     169        $prefix = $wpdb->prefix; 
     170        $ret = str_replace(get_wp_prefix_only(),'',$prefix); 
     171        return $ret; 
     172} 
     173 
     174function get_xpress_modid() 
     175{ 
     176        global $xoops_db; 
     177         
     178        $modulename = get_xpress_dir_name();     
     179        $sql = "SELECT mid FROM " . get_xoops_prefix() . "modules WHERE dirname = '$modulename'"; 
     180        $mid = $xoops_db->get_var($sql); 
     181        return $mid;     
     182} 
     183 
     184function block_cache_refresh() 
     185{ 
     186        global $xoops_db; 
     187        $mid = get_xpress_modid(); 
     188        $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = $mid"; 
     189        $blocks = $xoops_db->get_results($sql); 
     190        $mydirname = get_xpress_dir_name(); 
     191        require_once get_xpress_dir_path() . '/include/xpress_block_render.php'; 
     192 
     193 
     194        foreach($blocks as $block){ 
     195                $func_file = $block->func_file; 
     196                $call_theme_function_name = str_replace(".php", "", $func_file); 
     197                $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php'; 
     198                $cache_title = str_replace(".php", "", $func_file); 
     199                $blockID = $block->bid; 
     200                $options = explode("|", $block->options); 
     201                                         
     202                $block_theme_file = get_block_file_path($mydirname,$inc_theme_file_name); 
     203                require_once $block_theme_file; 
     204                $block_render = $call_theme_function_name($options);            //The block name and the called function name should be assumed to be the same name.                     
     205                xpress_block_cache_write($mydirname,$cache_title. $blockID, $block_render); 
     206        } 
     207} 
     208 
    135209?> 
  • trunk/wp-content/plugins/xpressme/xpressme.php

    r32 r46  
    99*/ 
    1010require_once('xpressme_class.php'); 
     11require_once dirname( __FILE__ ).'/include/custom_functions.php' ; 
     12 
     13 
    1114$xpessme = new XPressME_Class(); 
     15 
     16 
     17$xoops_db = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); 
     18$xoops_db->prefix = get_xoops_prefix(); 
     19$xoops_db->tables = array('modules', 'newblocks', 'users'); 
     20 
    1221 
    1322add_action('admin_menu', array(&$xpessme, 'add_option_page')); 
     
    1726        remove_action( 'pre_post_update', 'wp_save_post_revision' );                    // Not Save Post Revision 
    1827} 
     28add_action("comment_post",      "block_cache_refresh"); 
     29add_action("edit_comment",      "block_cache_refresh"); 
     30add_action("delete_comment","block_cache_refresh"); 
     31add_action("delete_post",       "block_cache_refresh"); 
     32add_action("publish_post",      "block_cache_refresh"); 
     33add_action("edit_post",         "block_cache_refresh"); 
     34add_action("private_to_published",      "block_cache_refresh"); 
     35add_action("wp_set_comment_status" , "block_cache_refresh"); 
     36 
    1937//require_once('../include/custom_functions.php'); 
    20 require_once dirname( __FILE__ ).'/include/custom_functions.php' ; 
    2138?> 
  • trunk/wp-content/themes/xpress_default/blocks/recent_comments_block_theme.php

    r44 r46  
    1111        $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname; 
    1212         
    13         $myts =& MyTextSanitizer::getInstance(); 
    14  
    1513        $this_url = '/modules/'. $mydirname; 
    1614        $call_url = $_SERVER['REQUEST_URI']; 
Note: See TracChangeset for help on using the changeset viewer.