function block_style_get($echo = true, $with_tpl = true)
    {
        $wp_num = wp_id() == '-' ? '' : wp_id();
        if ($with_tpl) {
            if (get_xoops_option(wp_mod(), 'wp_use_blockcssheader')) {
                $tplVars =& $GLOBALS['xoopsTpl']->get_template_vars();
                $csslink = "\n<link rel='stylesheet' type='text/css' media='screen' href='" . wp_siteurl() . "/wp-blockstyle.php' />";
                if (array_key_exists('xoops_block_header', $tplVars)) {
                    if (!strstr($tplVars['xoops_block_header'], $csslink)) {
                        $GLOBALS['xoopsTpl']->assign('xoops_block_header', $tplVars['xoops_block_header'] . $csslink);
                    }
                } else {
                    $GLOBALS['xoopsTpl']->assign('xoops_block_header', $csslink);
                }
                return;
            } else {
                if (!defined('WP_BLOCKSTYLE_READ' . $wp_num)) {
                    define('WP_BLOCKSTYLE_READ' . $wp_num, 1);
                    echo '<style type="text/css" midia="screen">@import url(' . wp_siteurl() . '/wp-blockstyle.php);</style>' . "\n";
                }
                return;
            }
        }
        if (file_exists(wp_base() . '/themes/' . $GLOBALS['xoopsConfig']['theme_set'] . '/wp-blocks.css.php')) {
            $themes = $GLOBALS['xoopsConfig']['theme_set'];
        } else {
            $themes = 'default';
        }
        $wp_block_style = '';
        include_once wp_base() . '/themes/' . $themes . '/wp-blocks.css.php';
        if ($echo) {
            if (trim($wp_block_style) != "") {
                echo <<<EOD
<style type="text/css" media="screen">
    <!--
\t{$wp_block_style}
    -->
</style>
EOD;
            }
        } else {
            return trim($wp_block_style);
        }
    }
require_once wp_base() . '/wp-includes/class-xmlrpc.php';
require_once wp_base() . '/wp-includes/class-xmlrpcs.php';
require_once wp_base() . '/wp-includes/links.php';
if (empty($GLOBALS['cache_categories'][wp_id()]) || count($GLOBALS['cache_categories'][wp_id()]) == 0) {
    $GLOBALS['cache_categories'][wp_id()] = array();
    $categoryHandler =& wp_handler('Category');
    $categoryObjects =& $categoryHandler->getObjects();
    foreach ($categoryObjects as $categoryObject) {
        $catt = $categoryObject->exportWpObject();
        $GLOBALS['cache_categories'][wp_id()][$catt->cat_ID] = $catt;
    }
}
// We should eventually migrate to either calling
// get_settings() wherever these are needed OR
// accessing a single global $all_settings var
if (get_xoops_option(wp_mod(), 'wp_use_xoops_smilies')) {
    $GLOBALS['smilies_directory'] = XOOPS_URL . "/uploads";
} else {
    $GLOBALS['smilies_directory'] = get_settings('smilies_directory');
}
//WordPressプラグイン互換性確保用
$GLOBALS['siteurl'] = wp_siteurl();
update_option('siteurl', $GLOBALS['siteurl'], true);
$GLOBALS['querystring_start'] = '?';
$GLOBALS['querystring_equal'] = '=';
$GLOBALS['querystring_separator'] = '&amp;';
$GLOBALS['dateformat'] = stripslashes(get_settings('date_format'));
$GLOBALS['timeformat'] = stripslashes(get_settings('time_format'));
// Used to guarantee unique cookies
$GLOBALS['cookiehash'] = md5(wp_siteurl());
require wp_base() . '/wp-includes/vars.php';
     foreach ($comments as $comment) {
         $author = apply_filters('comment_author', $comment->comment_author);
         if (empty($author)) {
             $author = 'Anonymous';
         }
         $echostring .= '<b>by ' . $author;
         $tmp = substr($comment->comment_date, 5, 2) . '/' . substr($comment->comment_date, 8, 2) . substr($comment->comment_date, 10, 6);
         $echostring .= '(' . $tmp . ')</b><br /><br />';
         $comment_text = str_replace('<trackback />', '', $comment->comment_content);
         $comment_text = str_replace('<pingback />', '', $comment_text);
         $echostring .= apply_filters('comment_text', $comment_text);
         $echostring .= '<hr />';
     }
 }
 if (defined('XOOPS_URL')) {
     if (!get_xoops_option(wp_mod(), 'wp_use_xoops_comments')) {
         $echostring .= '<a href="' . $myurl . '?view=comment&num=' . $num . '&p=' . $p . $ses_param . '">コメントする</a><br />';
     }
 } else {
     if (!get_option('comment_registration')) {
         $echostring .= '<a href="' . $myurl . '?view=comment&num=' . $num . '&p=' . $p . $ses_param . '">コメントする</a><br />';
     }
 }
 if ($comment_num > $start + $CommentPerPage) {
     $echostring .= $ackeychar[9] . '<a href="' . $myurl . '?view=comprev&start=' . ($start + $CommentPerPage) . '&num=' . $num . '&p=' . $p . $ses_param . '" accesskey="9">次の' . $CommentPerPage . '件のコメント &gt;</a><br/>';
 }
 if (0 <= $start - $CommentPerPage) {
     $echostring .= $ackeychar[7] . '<a href="' . $myurl . '?view=comprev&start=' . ($start - $CommentPerPage) . '&num=' . $num . '&p=' . $p . $ses_param . '" accesskey="9">前の' . $CommentPerPage . '件のコメント &gt;</a><br/>';
 }
 $echostring .= '<hr />';
 $echostring .= $ackeychar[0] . '<a href="' . $myurl . '?view=content&num=' . $num . '&p=' . $p . '&start=0' . $ses_param . '" accesskey="0">記事へ戻る</a><br/>';
    function tkzy_get_recent_comments($limit = 10, $cat_date = 1, $show_type = 1)
    {
        $comment_lenth = 30;
        $request = 'SELECT ID, post_title, post_date, 
		comment_ID, comment_author, comment_author_url, comment_author_email, comment_date, comment_content 
		FROM ' . wp_table('posts') . ', ' . wp_table('comments') . ' WHERE ' . wp_table('posts') . '.ID=' . wp_table('comments') . '.comment_post_ID AND ' . wp_table('comments') . '.comment_approved=\'1\'';
        if (get_xoops_option(wp_mod(), 'wp_use_xoops_comments') == 1) {
            $request .= ' AND (comment_content like \'<trackback />%\' OR comment_content like \'<pingkback />%\') ';
        }
        $request .= ' ORDER BY ' . wp_table('comments') . '.comment_date DESC LIMIT ' . $limit;
        $lcomments = $GLOBALS['wpdb']->get_results($request);
        $output = '';
        if ($lcomments) {
            usort($lcomments, 'sort_comment_by_date');
        }
        $new_post_ID = -1;
        if ($lcomments) {
            $output .= '<ul class="wpBlockList">';
            foreach ($lcomments as $lcomment) {
                if ($lcomment->ID != $new_post_ID) {
                    // next post
                    if ($new_post_ID != -1) {
                        $output .= '</ul></li>';
                    }
                    $post_title = stripslashes($lcomment->post_title);
                    if (trim($post_title) == "") {
                        $post_title = _WP_POST_NOTITLE;
                    }
                    $comment_content = strip_tags($lcomment->comment_content);
                    $comment_content = stripslashes($comment_content);
                    if (function_exists('mb_substr')) {
                        $comment_excerpt = mb_substr($comment_content, 0, $comment_lenth);
                    } else {
                        $comment_excerpt = substr($comment_content, 0, $comment_lenth);
                    }
                    $permalink = wp_siteurl() . '/index.php?p=' . $lcomment->ID . '&amp;c=1';
                    $output .= '<li>';
                    $output .= '<span class="comment-title"><a href="' . $permalink . '">' . $post_title . '</a></span>';
                    $output .= '<ul class="children" style="list-style-type: none;">';
                    $new_post_ID = $lcomment->ID;
                }
                $output .= "\t\t<li>";
                if ($cat_date) {
                    $comment_date = $lcomment->comment_date;
                    if (time() - mysql2date('U', $comment_date) < 60 * 60 * 24) {
                        # within 24 hours
                        $comment_date = mysql2date('H:i', $comment_date);
                    } else {
                        $comment_date = mysql2date('m/d', $comment_date);
                    }
                    $output .= '<span class="post-date">' . $comment_date . '</span> : ';
                }
                $output .= '<span class="comment_author">' . tkzy_get_comment_author_link($lcomment, 25) . '</span></li>';
                if (preg_match('|<trackback />|', $lcomment->comment_content)) {
                    $type = '[TrackBack]';
                } elseif (preg_match('|<pingback />|', $lcomment->comment_content)) {
                    $type = '[Ping]';
                } else {
                    $type = '[Comment]';
                }
                if ($show_type) {
                    $output .= '<span style="font-size:90%"> - ' . $type . '</span>';
                }
            }
        }
        $output .= '</ul></li></ul>';
        return $output;
    }
                    comment_text();
                    if ("unapproved" == $comment_status) {
                        ?>
 		</span>
<?php 
                    }
                    ?>
		</li>
	<!-- /comment -->
<?php 
                }
                ?>
	</ol>
<?php 
            }
            if (get_xoops_option(wp_mod(), 'wp_use_xoops_comments') == 0) {
                ?>
<h3><?php 
                echo _LANG_E_TITLE_LEAVECOM;
                ?>
</h3>
	<!-- form to add a comment -->
	<form action="<?php 
                echo $siteurl . '/wp-comments-post.php';
                ?>
" method="post">
		<input type="hidden" name="comment_post_ID" value="<?php 
                echo $wp_post_id;
                ?>
" />
		<input type="hidden" name="redirect_to" value="<?php 
    $_wp_id_keep = $GLOBALS['wp_id'];
    include_once dirname(__FILE__) . "/../../../mainfile.php";
    include XOOPS_ROOT_PATH . '/header.php';
    $GLOBALS['wp_id'] = $_wp_id_keep;
    $GLOBALS['wp_inblock'] = 1;
    require '../wp-config.php';
    $GLOBALS['wp_inblock'] = 0;
}
require_once ABSPATH . 'wp-admin/admin-functions.php';
require_once 'auth.php';
if (get_xoops_option(wp_mod(), 'wp_use_spaw') == 1) {
    $GLOBALS['wp_use_spaw'] = true;
} else {
    $GLOBALS['wp_use_spaw'] = false;
}
if (get_xoops_option(wp_mod(), 'wp_use_spaw') == 2) {
    $GLOBALS['wp_use_koivi'] = true;
} else {
    $GLOBALS['wp_use_koivi'] = false;
}
if (!isset($use_cache)) {
    $GLOBALS['use_cache'] = 1;
}
if (!isset($blogID)) {
    $GLOBALS['blog_ID'] = 1;
}
if (!isset($debug)) {
    $GLOBALS['debug'] = 0;
}
timer_start();
get_currentuserinfo();
    function _b_wp_recent_comments_show($options, $wp_num = "")
    {
        $block_style = $options[0] ? $options[0] : 0;
        $num_of_list = !isset($options[1]) ? 10 : $options[1];
        $show_rss_icon = !isset($options[2]) ? 0 : $options[2];
        $cat_date = !isset($options[3]) ? $block_style ? 1 : 0 : $options[3];
        $show_type = !isset($options[4]) ? 1 : $options[4];
        $tpl_file = empty($options[5]) ? 'wp_recent_comments.html' : $options[5];
        $block['style'] = block_style_get(false);
        $block['divid'] = 'wpRecentComment' . $wp_num;
        $block['block_style'] = $block_style;
        $block['cat_date'] = $cat_date;
        $block['show_type'] = $show_type;
        $comment_lenth = 30;
        if ($block_style == 0) {
            $skip_posts = 0;
            $request = "SELECT ID, comment_ID, comment_content, comment_author, comment_author_url, comment_date, comment_type\n\t\t\t\t\t\tFROM " . wp_table('posts') . ", " . wp_table('comments') . "\n\t\t\t\t\t\tWHERE " . wp_table('posts') . ".ID=" . wp_table('comments') . ".comment_post_ID\n\t\t\t\t\t\tAND post_status = 'publish' AND comment_approved = '1' ";
            if (get_xoops_option(wp_mod(), 'wp_use_xoops_comments') == 1) {
                $request .= "AND (comment_content like '<trackback />%' \n\t\t\t\t                  OR comment_content like '<pingkback />%'\n\t\t\t\t                  OR comment_type = 'trackback'\n\t\t\t\t                  OR comment_type = 'pingback'\n\t\t\t\t                  ) ";
            }
            $request .= "ORDER BY " . wp_table('comments') . ".comment_date DESC LIMIT {$num_of_list}";
            $lcomments = $GLOBALS['wpdb']->get_results($request);
            $output = '';
            $pdate = "";
            $block['records'] = array();
            if ($lcomments) {
                foreach ($lcomments as $lcomment) {
                    if ($cat_date) {
                        $date = mysql2date("Y-n-j", $lcomment->comment_date);
                        if ($date != $pdate) {
                            $_record['date'] = $date;
                            $_record['pdate'] = $pdate;
                            $pdate = $date;
                        } else {
                            $_record['date'] = '';
                        }
                    }
                    if (empty($lcomment->comment_type)) {
                        if (preg_match('|<trackback />|', $lcomment->comment_content)) {
                            $type = '[TrackBack]';
                        } elseif (preg_match('|<pingback />|', $lcomment->comment_content)) {
                            $type = '[PingBack]';
                        } else {
                            $type = '[Comment]';
                        }
                    } else {
                        if ($lcomment->comment_type == 'trackback') {
                            $type = '[TrackBack]';
                        } elseif ($lcomment->comment_type == 'pingback') {
                            $type = '[PingBack]';
                        } else {
                            $type = '[Comment]';
                        }
                    }
                    $_record['comment_author'] = apply_filters('comment_author', $lcomment->comment_author);
                    $_record['comment_author_link'] = _get_comment_author_link($lcomment, 25);
                    $_record['comment_content'] = strip_tags($lcomment->comment_content);
                    if (function_exists('mb_substr')) {
                        $_record['comment_excerpt'] = mb_substr($_record['comment_content'], 0, $comment_lenth);
                    } else {
                        $_record['comment_excerpt'] = substr($_record['comment_content'], 0, $comment_lenth);
                    }
                    $_record['comment_excerpt'] = preg_replace('/([a-zA-Z0-9\\.\\/\\:\\%\\?\\-\\+\\&\\;]{15})/ms', '\\1&#8203;', $_record['comment_excerpt']);
                    $_record['permalink'] = get_permalink($lcomment->ID) . '#comment-' . $lcomment->comment_ID;
                    if ($show_type) {
                        $_record['type'] = $type;
                    }
                    $block['records'][] = $_record;
                }
            }
        } else {
            $request = 'SELECT ID, post_title, post_date, comment_ID, comment_author, comment_author_url,
						comment_date, comment_content, comment_type
						FROM ' . wp_table('posts') . ', ' . wp_table('comments') . '
						WHERE ' . wp_table('posts') . '.ID=' . wp_table('comments') . '.comment_post_ID
						AND ' . wp_table('comments') . '.comment_approved=\'1\'';
            if (get_xoops_option(wp_mod(), 'wp_use_xoops_comments') == 1) {
                $request .= "AND (comment_content like '<trackback />%' \n\t\t\t\t                  OR comment_content like '<pingkback />%'\n\t\t\t\t                  OR comment_type = 'trackback'\n\t\t\t\t                  OR comment_type = 'pingback'\n\t\t\t\t                  ) ";
            }
            $request .= ' ORDER BY ' . wp_table('comments') . '.comment_date DESC LIMIT ' . $num_of_list;
            $lcomments = $GLOBALS['wpdb']->get_results($request);
            $output = '';
            if ($lcomments) {
                usort($lcomments, 'sort_comment_by_date');
            }
            $new_post_ID = -1;
            $block['records'] = array();
            if ($lcomments) {
                foreach ($lcomments as $lcomment) {
                    $_record['new_post_ID'] = $new_post_ID;
                    $_record['ID'] = $lcomment->ID;
                    if ($lcomment->ID != $new_post_ID) {
                        // next post
                        $_record['post_title'] = $lcomment->post_title;
                        if (trim($_record['post_title']) == "") {
                            $_record['post_title'] = _WP_POST_NOTITLE;
                        }
                        $_record['comment_content'] = strip_tags($lcomment->comment_content);
                        if (function_exists('mb_substr')) {
                            $_record['comment_excerpt'] = mb_substr($_record['comment_content'], 0, $comment_lenth);
                        } else {
                            $_record['comment_excerpt'] = substr($_record['comment_content'], 0, $comment_lenth);
                        }
                        $_record['comment_excerpt'] = preg_replace('/([a-zA-Z0-9\\.\\/\\:\\?\\-\\+%&;]{15})/ms', '\\1&#8203;', $_record['comment_excerpt']);
                        $_record['permalink'] = wp_siteurl() . '/index.php?p=' . $lcomment->ID . '&amp;c=1';
                        $new_post_ID = $lcomment->ID;
                    }
                    if ($cat_date) {
                        $comment_date = $lcomment->comment_date;
                        if (time() - mysql2date('U', $comment_date) < 60 * 60 * 24) {
                            # within 24 hours
                            $_record['comment_date'] = mysql2date('H:i', $comment_date);
                        } else {
                            $_record['comment_date'] = mysql2date('m/d', $comment_date);
                        }
                    }
                    $_record['comment_author'] = apply_filters('comment_author', $lcomment->comment_author);
                    $_record['comment_author_link'] = _get_comment_author_link($lcomment, 25);
                    if (empty($lcomment->comment_type)) {
                        if (preg_match('|<trackback />|', $lcomment->comment_content)) {
                            $type = '[TrackBack]';
                        } elseif (preg_match('|<pingback />|', $lcomment->comment_content)) {
                            $type = '[PingBack]';
                        } else {
                            $type = '[Comment]';
                        }
                    } else {
                        if ($lcomment->comment_type == 'trackback') {
                            $type = '[TrackBack]';
                        } elseif ($lcomment->comment_type == 'pingback') {
                            $type = '[PingBack]';
                        } else {
                            $type = '[Comment]';
                        }
                    }
                    if ($show_type) {
                        $_record['type'] = $type;
                    }
                    $block['records'][] = $_record;
                }
            }
        }
        if ($show_rss_icon) {
            $block['feed_icon'] = array('url' => get_bloginfo('comments_rss2_url'), 'icon' => wp_siteurl() . '/wp-images/rss_comment.gif', 'alt' => 'Comment RSS');
        } else {
            $block['feed_icon'] = array();
        }
        $_wpTpl =& new WordPresTpl('theme');
        $_wpTpl->assign('block', $block);
        if (!$_wpTpl->tpl_exists($tpl_file)) {
            $tpl_file = 'wp_recent_comments.html';
        }
        $block['content'] = $_wpTpl->fetch($tpl_file);
        return $block;
    }
        // Change from flat structure to hierarchical:
        $GLOBALS['post_meta_cache'][wp_id()] = array();
        foreach ($meta_list as $metarow) {
            $mpid = $metarow['post_id'];
            $mkey = $metarow['meta_key'];
            $mval = $metarow['meta_value'];
            // Force subkeys to be array type:
            if (!isset($GLOBALS['post_meta_cache'][wp_id()][$mpid]) || !is_array($GLOBALS['post_meta_cache'][wp_id()][$mpid])) {
                $GLOBALS['post_meta_cache'][wp_id()][$mpid] = array();
            }
            if (!isset($GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"]) || !is_array($GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"])) {
                $GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"] = array();
            }
            // Add a value to the current pid/key:
            $GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"][] = $mval;
        }
    }
}
if (preg_match('#/modules/' . wp_mod() . '(/|/index.php.*)?$#', $_SERVER['PHP_SELF'])) {
    //redirect feed and trackback
    if (test_param('feed')) {
        require_once 'wp-feed.php';
        exit;
    } else {
        if (test_param('tb')) {
            $trackback_filename = get_settings('trackback_filename') ? get_settings('trackback_filename') : 'wp-trackback.php';
            require_once $trackback_filename;
            exit;
        }
    }
}
 function xcomments_popup_link($zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $CSSclass = '', $none = 'Comments Off', $echo = true)
 {
     $module_handler =& xoops_gethandler('module');
     $module =& $module_handler->getByDirname(wp_mod());
     $mid = $module->getVar('mid');
     $number = xoops_comment_count($mid, $GLOBALS['wp_post_id']);
     $xcomments_popup_link = "";
     if (0 == $number && 'closed' == $GLOBALS['post']->comment_status) {
         return _echo($none, $echo);
     } else {
         if (!empty($GLOBALS['post']->post_password)) {
             // if there's a password
             if ($_COOKIE['wp-postpass_' . $GLOBALS['cookiehash']] != $GLOBALS['post']->post_password) {
                 // and it doesn't match the cookie
                 return _echo("Enter your password to view comments", $echo);
             }
         }
         $xcomments_popup_link .= '<a href="';
         if (!empty($GLOBALS['wpcommentsjavascript'])) {
             $xcomments_popup_link .= wp_siteurl() . '/' . $GLOBALS['wpcommentspopupfile'] . '?p=' . $GLOBALS['wp_post_id'] . '&amp;c=1';
             $xcomments_popup_link .= '" onclick="wpopen(this.href); return false"';
         } else {
             // if comments_popup_script() is not in the template, display simple comment link
             $xcomments_popup_link .= xcomments_link('', false);
             $xcomments_popup_link .= '"';
         }
         if (!empty($CSSclass)) {
             $xcomments_popup_link .= ' class="' . $CSSclass . '"';
         }
         $xcomments_popup_link .= '>';
         $xcomments_popup_link .= comments_number($zero, $one, $more, $number, false);
         $xcomments_popup_link .= '</a>';
         return _echo($xcomments_popup_link, $echo);
     }
 }
    // this is displayed if there are no comments so far
    ?>
	<p><?php 
    echo _LANG_WPCM_COM_YET;
    ?>
</p>
<?php 
}
?>
<h2 id="xcomments"><?php 
echo _LANG_WPCM_COM_TITLE;
?>
</h2>
<?php 
if ('open' == $post->comment_status && XOOPS_COMMENT_APPROVENONE != $xoopsModuleConfig['com_rule']) {
    require XOOPS_ROOT_PATH . '/modules/' . wp_mod() . '/include/comment_view.php';
    ?>
<div style="text-align: center; padding: 3px; margin: 3px;">
  <?php 
    echo $navbar;
    ?>
  <?php 
    echo _CM_NOTICE;
    ?>
</div>

<div style="margin: 3px; padding: 3px;">
<?php 
    if ($com_mode == "flat") {
        echo $xoopsTpl->fetch("db:system_comments_flat.html");
    } else {
function block_style_get($wp_num, $echo = true, $with_tpl = true)
{
    if ($with_tpl) {
        if (get_xoops_option(wp_mod(), 'wp_use_blockcssheader')) {
            $tplVars =& $GLOBALS['xoopsTpl']->get_template_vars();
            $csslink = "\n<link rel='stylesheet' type='text/css' media='screen' href='" . XOOPS_URL . "/modules/wordpress" . $wp_num . "/wp-blockstyle.php' />";
            if (array_key_exists('xoops_block_header', $tplVars)) {
                if (!strstr($tplVars['xoops_block_header'], $csslink)) {
                    $GLOBALS['xoopsTpl']->assign('xoops_block_header', $tplVars['xoops_block_header'] . $csslink);
                }
            } else {
                $GLOBALS['xoopsTpl']->assign('xoops_block_header', $csslink);
            }
            return;
        }
    }
    if (file_exists(XOOPS_ROOT_PATH . '/modules/wordpress' . $wp_num . '/themes/' . $GLOBALS['xoopsConfig']['theme_set'] . '/wp-blocks.css.php')) {
        $themes = $GLOBALS['xoopsConfig']['theme_set'];
    } else {
        $themes = "default";
    }
    $wp_block_style = "";
    include_once XOOPS_ROOT_PATH . "/modules/wordpress" . $wp_num . "/themes/" . $themes . "/wp-blocks.css.php";
    if ($echo) {
        if (trim($wp_block_style) != "") {
            echo <<<EOD
<style type="text/css" media="screen">
    <!--
{$wp_block_style}
    -->
</style>
EOD;
        }
    } else {
        return trim($wp_block_style);
    }
}
    function block_style_get($echo = true, $with_tpl = true)
    {
        $wp_num = wp_id() == '-' ? '' : wp_id();
        if ($with_tpl) {
            if (get_xoops_option(wp_mod(), 'wp_use_blockcssheader') == 1) {
                $tplVars =& $GLOBALS['xoopsTpl']->get_template_vars();
                $csslink = "\n" . '<link rel="stylesheet" type="text/css" media="screen" href="' . wp_siteurl() . '/wp-blockstyle.php" />';
                if (array_key_exists('xoops_block_header', $tplVars)) {
                    if (!strstr($tplVars['xoops_block_header'], $csslink)) {
                        $GLOBALS['xoopsTpl']->assign('xoops_block_header', $tplVars['xoops_block_header'] . $csslink);
                    }
                } else {
                    $GLOBALS['xoopsTpl']->assign('xoops_block_header', $csslink);
                }
                return;
            } else {
                if (get_xoops_option(wp_mod(), 'wp_use_blockcssheader') == 2) {
                    $tplVars =& $GLOBALS['xoopsTpl']->get_template_vars();
                    $csslink = '" />' . "\n" . '<link rel="stylesheet" type="text/css" media="screen" href="' . wp_siteurl() . '/wp-blockstyle.php';
                    if (!strstr($tplVars['xoops_themecss'], $csslink)) {
                        $GLOBALS['xoopsTpl']->assign('xoops_themecss', $tplVars['xoops_themecss'] . $csslink);
                    }
                    return;
                } else {
                    if (!defined('WP_BLOCKSTYLE_READ' . $wp_num)) {
                        define('WP_BLOCKSTYLE_READ' . $wp_num, 1);
                        if ($echo) {
                            echo '<style type="text/css" media="screen">@import url(' . wp_siteurl() . '/wp-blockstyle.php);</style>' . "\n";
                        } else {
                            return '<style type="text/css" media="screen">@import url(' . wp_siteurl() . '/wp-blockstyle.php);</style>';
                        }
                    }
                    return '';
                }
            }
        }
        $wp_block_style = '';
        include_once get_custom_path('wp-blocks.css.php');
        if ($echo) {
            if (trim($wp_block_style) != "") {
                echo <<<EOD
<style type="text/css" media="screen">
    <!--
\t{$wp_block_style}
    -->
</style>
EOD;
            }
        } else {
            return trim($wp_block_style);
        }
    }
        }
        $link_extra = '';
        if (isset($comment_config['extraParams']) && is_array($comment_config['extraParams'])) {
            foreach ($comment_config['extraParams'] as $extra_param) {
                if (isset(${$extra_param})) {
                    $extra_param_val = ${$extra_param};
                } elseif (isset($_POST[$extra_param])) {
                    $extra_param_val = $_POST[$extra_param];
                } elseif (isset($_GET[$extra_param])) {
                    $extra_param_val = $_GET[$extra_param];
                }
                if (isset($extra_param_val)) {
                    $link_extra .= '&amp;' . $extra_param . '=' . $extra_param_val;
                    $hidden_value = htmlspecialchars($extra_param_val, ENT_QUOTES);
                    $navbar .= '<input type="hidden" name="' . $extra_param . '" value="' . $hidden_value . '" />';
                }
            }
        }
        if (isset($postcomment_link)) {
            $navbar .= '&nbsp;<input type="button" onclick="self.location.href=\'' . XOOPS_URL . '/modules/' . wp_mod() . '/' . $postcomment_link . '' . $link_extra . '\'" class="formButton" value="' . _CM_POSTCOMMENT . '" />';
        }
        $navbar .= '
    </td>
  </tr>
</table>
</form>';
        $xoopsTpl->assign(array('commentsnav' => $navbar, 'editcomment_link' => XOOPS_URL . '/modules/' . wp_mod() . '/' . 'comment_edit.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . '' . $link_extra, 'deletecomment_link' => XOOPS_URL . '/modules/' . wp_mod() . '/' . 'comment_delete.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . '' . $link_extra, 'replycomment_link' => XOOPS_URL . '/modules/' . wp_mod() . '/' . 'comment_reply.php?com_itemid=' . $com_itemid . '&amp;com_order=' . $com_order . '&amp;com_mode=' . $com_mode . '' . $link_extra));
        // assign some lang variables
        $xoopsTpl->assign(array('lang_from' => _CM_FROM, 'lang_joined' => _CM_JOINED, 'lang_posts' => _CM_POSTS, 'lang_poster' => _CM_POSTER, 'lang_thread' => _CM_THREAD, 'lang_edit' => _EDIT, 'lang_delete' => _DELETE, 'lang_reply' => _REPLY, 'lang_subject' => _CM_REPLIES, 'lang_posted' => _CM_POSTED, 'lang_updated' => _CM_UPDATED, 'lang_notice' => _CM_NOTICE));
    }
}
 function tkzy_get_recent_comments($limit = 10, $cat_date = 1, $show_type = 1)
 {
     $comment_lenth = 30;
     $request = "SELECT ID, post_title, post_date, \n\t\tcomment_ID, comment_author, comment_author_url, comment_author_email, comment_date, comment_content \n\t\tFROM " . wp_table('posts') . ", " . wp_table('comments') . " WHERE " . wp_table('posts') . ".ID=" . wp_table('comments') . ".comment_post_ID AND " . wp_table('comments') . ".comment_approved='1'";
     if (get_xoops_option(wp_mod(), 'wp_use_xoops_comments') == 1) {
         $request .= "AND (comment_content like '<trackback />%' OR comment_content like '<pingkback />%') ";
     }
     $request .= " ORDER BY " . wp_table('comments') . ".comment_date DESC LIMIT {$limit}";
     $lcomments = $GLOBALS['wpdb']->get_results($request);
     $output = '';
     if ($lcomments) {
         usort($lcomments, "sort_comment_by_date");
     }
     $new_post_ID = -1;
     if ($lcomments) {
         $output .= "<ul class='wpBlockList'>";
         foreach ($lcomments as $lcomment) {
             if ($lcomment->ID != $new_post_ID) {
                 // next post
                 if ($new_post_ID != -1) {
                     $output .= "\t</ul>\n</li>\n";
                 }
                 $post_title = stripslashes($lcomment->post_title);
                 if (trim($post_title) == "") {
                     $post_title = _WP_POST_NOTITLE;
                 }
                 $comment_content = strip_tags($lcomment->comment_content);
                 $comment_content = stripslashes($comment_content);
                 if (function_exists('mb_substr')) {
                     $comment_excerpt = mb_substr($comment_content, 0, $comment_lenth);
                 } else {
                     $comment_excerpt = substr($comment_content, 0, $comment_lenth);
                 }
                 $permalink = wp_siteurl() . "/index.php?p={$lcomment->ID}&amp;c=1";
                 $output .= "<li>";
                 $output .= "<span class='comment-title'><a href=\"{$permalink}\">{$post_title}</a></span>\n";
                 $output .= "\t<ul class=\"children\" style=\"list-style-type: none;\">\n";
                 $new_post_ID = $lcomment->ID;
             }
             $output .= "\t\t<li>";
             if ($cat_date) {
                 $comment_date = $lcomment->comment_date;
                 if (time() - mysql2date('U', $comment_date) < 60 * 60 * 24) {
                     # within 24 hours
                     $comment_date = mysql2date('H:i', $comment_date);
                 } else {
                     $comment_date = mysql2date('m/d', $comment_date);
                 }
                 $output .= "<span class=\"post-date\">{$comment_date}</span> : ";
             }
             $output .= "<span class=\"comment_author\">" . tkzy_get_comment_author_link($lcomment, 25) . "</span></li>\n";
             if (preg_match('|<trackback />|', $lcomment->comment_content)) {
                 $type = '[TrackBack]';
             } elseif (preg_match('|<pingback />|', $lcomment->comment_content)) {
                 $type = '[Ping]';
             } else {
                 $type = '[Comment]';
             }
             if ($show_type) {
                 $output .= "<span style=\"font-size:90%\"> - {$type}</span>";
             }
         }
     }
     $output .= "\t</ul>\n</li>\n</ul>\n";
     return $output;
 }
 function _b_wp_contents_show($options, $wp_num = "")
 {
     $no_posts = empty($options[0]) ? 10 : $options[0];
     $tpl_file = empty($options[1]) ? 'wp_contents.html' : $options[1];
     $category = empty($options[2]) ? "all" : intval($options[2]);
     $GLOBALS['dateformat'] = get_settings('date_format');
     $GLOBALS['timeformat'] = get_settings('time_format');
     $_criteria = new CriteriaCompo(new Criteria('post_status', 'publish'));
     $_criteria->add(new Criteria('post_date', current_time('mysql'), '<='));
     if (empty($category) || $category == 'all' || $category == '0') {
         $_joinCriteria = null;
     } else {
         $_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id');
         $_wCriteria =& new CriteriaCompo();
         $_wCriteria->add(new Criteria('category_id', intCriteriaVal($category)), 'OR');
         $_catc = trim(get_category_children($category, '', ' '));
         if ($_catc !== "") {
             $_catc_array = explode(' ', $_catc);
             for ($_j = 0; $_j < count($_catc_array); $_j++) {
                 $_wCriteria->add(new Criteria('category_id', intCriteriaVal($_catc_array[$_j])), 'OR');
             }
         }
         $_criteria->add($_wCriteria);
     }
     $_criteria->setGroupBy(wp_table('posts') . '.ID');
     $_criteria->setSort('post_date');
     $_criteria->setOrder('DESC');
     $_criteria->setLimit($no_posts);
     $_criteria->setStart(0);
     $postHandler =& wp_handler('Post');
     $postObjects =& $postHandler->getObjects($_criteria, false, '', 'DISTINCT', $_joinCriteria);
     //		echo $postHandler->getLastSQL();
     $lposts = array();
     foreach ($postObjects as $postObject) {
         $lposts[] =& $postObject->exportWpObject();
     }
     if ($lposts) {
         // Get the categories for all the posts
         $_post_id_list = array();
         foreach ($lposts as $post) {
             $_post_id_list[] = $post->ID;
             $GLOBALS['category_cache'][wp_id()][$post->ID] = array();
         }
         $_post_id_list = implode(',', $_post_id_list);
         $_post_id_criteria =& new Criteria('post_id', '(' . $_post_id_list . ')', 'IN');
         $_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id');
         $_joinCriteria->cascade(new XoopsJoinCriteria(wp_table('categories'), 'category_id', 'cat_ID'));
         $postObjects =& $postHandler->getObjects($_post_id_criteria, false, 'ID, category_id, cat_name, category_nicename, category_description, category_parent', true, $_joinCriteria);
         foreach ($postObjects as $postObject) {
             $_cat->ID = $postObject->getVar('ID');
             $_cat->category_id = $postObject->getExtraVar('category_id');
             $_cat->cat_name = $postObject->getExtraVar('cat_name');
             $_cat->category_nicename = $postObject->getExtraVar('category_nicename');
             $_cat->category_description = $postObject->getExtraVar('category_description');
             $_cat->category_parent = $postObject->getExtraVar('category_parent');
             $GLOBALS['category_cache'][wp_id()][$postObject->getVar('ID')][] =& $_cat;
             unset($_cat);
         }
         // Do the same for comment numbers
         $_post_id_criteria =& new Criteria('comment_post_ID', '(' . $_post_id_list . ')', 'IN');
         $_criteria =& new CriteriaCompo(new Criteria('post_status', 'publish'));
         $_criteria->add(new Criteria('comment_approved', '1 '));
         $_criteria->add($_post_id_criteria);
         $_criteria->setGroupBy('ID');
         $_joinCriteria =& new XoopsJoinCriteria(wp_table('comments'), 'ID', 'comment_post_ID');
         $postObjects =& $postHandler->getObjects($_criteria, false, 'ID, COUNT( comment_ID ) AS ccount', false, $_joinCriteria);
         foreach ($postObjects as $postObject) {
             $GLOBALS['comment_count_cache'][wp_id()]['' . $postObject->getVar('ID')] = $postObject->getExtraVar('ccount');
         }
         // Get post-meta info
         if ($meta_list = $GLOBALS['wpdb']->get_results('SELECT post_id, meta_key, meta_value FROM ' . wp_table('postmeta') . ' WHERE post_id IN(' . $_post_id_list . ') ORDER BY post_id, meta_key', ARRAY_A)) {
             // Change from flat structure to hierarchical:
             $GLOBALS['post_meta_cache'][wp_id()] = array();
             foreach ($meta_list as $metarow) {
                 $mpid = $metarow['post_id'];
                 $mkey = $metarow['meta_key'];
                 $mval = $metarow['meta_value'];
                 // Force subkeys to be array type:
                 if (!isset($GLOBALS['post_meta_cache'][wp_id()][$mpid]) || !is_array($GLOBALS['post_meta_cache'][wp_id()][$mpid])) {
                     $GLOBALS['post_meta_cache'][wp_id()][$mpid] = array();
                 }
                 if (!isset($GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"]) || !is_array($GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"])) {
                     $GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"] = array();
                 }
                 // Add a value to the current pid/key:
                 $GLOBALS['post_meta_cache'][wp_id()][$mpid]["{$mkey}"][] = $mval;
             }
         }
     }
     $blog = 1;
     $block = array();
     $block['use_theme_template'] = get_xoops_option(wp_mod(), 'use_theme_template');
     $block['style'] = block_style_get(false);
     $block['divid'] = 'wpBlockContent' . $wp_num;
     $block['template_content'] = "";
     $i = 0;
     $GLOBALS['previousday'] = 0;
     foreach ($lposts as $post) {
         $GLOBALS['post'] = $post;
         if ($block['use_theme_template'] == 0) {
             $content = array();
             start_wp();
             $content['date'] = the_date($GLOBALS['dateformat'], '', '', false);
             $content['time'] = the_time('', false);
             $content['title'] = the_title('', '', false);
             $content['permlink'] = get_permalink();
             $content['author'] = the_author_posts_link('', false);
             $content['category'] = the_category('', '', false);
             $content['body'] = the_content(_WP_TPL_MORE, 0, '', false);
             $content['linkpage'] = link_pages('<br />Pages: ', '<br />', 'number', 'next page', 'previous page', '%', '', false);
             if (get_xoops_option(wp_mod(), 'wp_use_xoops_comments') == 0) {
                 $content['comments'] = comments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS, '', 'Comments Off', false);
             } else {
                 $content['comments'] = xcomments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS, '', 'Comments Off', false);
                 $content['comments'] .= " | ";
                 $content['comments'] .= comments_popup_link(_WP_TPL_TRACKBACK0, _WP_TPL_TRACKBACK1, _WP_TPL_TRACKBACKS, '', 'Trackback Off', false);
             }
             $content['trackback'] = trackback_rdf(0, false);
             $block['contents'][] = $content;
         } else {
             ob_start();
             include get_custom_path('content_block-template.php');
             $block['template_content'] .= ob_get_contents();
             ob_end_clean();
         }
     }
     $_wpTpl =& new WordPresTpl('theme');
     $_wpTpl->assign('block', $block);
     if (!$_wpTpl->tpl_exists($tpl_file)) {
         $tpl_file = 'wp_contents.html';
     }
     $block['content'] = $_wpTpl->fetch($tpl_file);
     $GLOBALS['previousday'] = 0;
     $GLOBALS['day'] = 0;
     $GLOBALS['comment_count_cache'][wp_id()] = array();
     return $block;
 }
 function _b_wp_contents_show($options, $wp_num = "")
 {
     $no_posts = empty($options[0]) ? 10 : $options[0];
     $GLOBALS['dateformat'] = stripslashes(get_settings('date_format'));
     $GLOBALS['timeformat'] = stripslashes(get_settings('time_format'));
     $_criteria = new CriteriaCompo(new Criteria('post_status', 'publish'));
     $_criteria->add(new Criteria('post_date', current_time('mysql'), '<='));
     $_criteria->setGroupBy(wp_table('posts') . '.ID');
     $_criteria->setSort('post_date');
     $_criteria->setOrder('DESC');
     $_criteria->setLimit($no_posts);
     $_criteria->setStart(0);
     $postHandler =& wp_handler('Post');
     $postObjects =& $postHandler->getObjects($_criteria, false, '', 'DISTINCT');
     $lposts = array();
     foreach ($postObjects as $postObject) {
         $lposts[] =& $postObject->exportWpObject();
     }
     if ($lposts) {
         // Get the categories for all the posts
         $_post_id_list = array();
         foreach ($lposts as $post) {
             $_post_id_list[] = $post->ID;
             $GLOBALS['category_cache'][wp_id()][$post->ID] = array();
         }
         $_post_id_list = implode(',', $_post_id_list);
         $_post_id_criteria =& new Criteria('post_id', '(' . $_post_id_list . ')', 'IN');
         $_joinCriteria =& new XoopsJoinCriteria(wp_table('post2cat'), 'ID', 'post_id');
         $_joinCriteria->cascade(new XoopsJoinCriteria(wp_table('categories'), 'category_id', 'cat_ID'));
         $postObjects =& $postHandler->getObjects($_post_id_criteria, false, 'ID, category_id, cat_name, category_nicename, category_description, category_parent', true, $_joinCriteria);
         foreach ($postObjects as $postObject) {
             $_cat->ID = $postObject->getVar('ID');
             $_cat->category_id = $postObject->getExtraVar('category_id');
             $_cat->cat_name = $postObject->getExtraVar('cat_name');
             $_cat->category_nicename = $postObject->getExtraVar('category_nicename');
             $_cat->category_description = $postObject->getExtraVar('category_description');
             $_cat->category_parent = $postObject->getExtraVar('category_parent');
             $GLOBALS['category_cache'][wp_id()][$postObject->getVar('ID')][] =& $_cat;
             unset($_cat);
         }
         // Do the same for comment numbers
         $_criteria =& new CriteriaCompo(new Criteria('post_status', 'publish'));
         $_criteria->add(new Criteria('comment_approved', '1 '));
         $_criteria->add($_post_id_criteria);
         $_criteria->setGroupBy('ID');
         $_joinCriteria =& new XoopsJoinCriteria(wp_table('comments'), 'ID', 'comment_post_ID');
         $postObjects =& $postHandler->getObjects($_criteria, false, 'ID, COUNT( comment_ID ) AS ccount', false, $_joinCriteria);
         foreach ($postObjects as $postObject) {
             $GLOBALS['comment_count_cache'][wp_id()]['' . $postObject->getVar('ID')] = $postObject->getExtraVar('ccount');
         }
     }
     $blog = 1;
     $block = array();
     $block['use_theme_template'] = get_xoops_option(wp_mod(), 'use_theme_template');
     $block['style'] = block_style_get(false);
     $block['divid'] = 'wpBlockContent' . $wp_num;
     $block['template_content'] = "";
     $i = 0;
     $GLOBALS['previousday'] = 0;
     foreach ($lposts as $post) {
         $GLOBALS['post'] = $post;
         if ($block['use_theme_template'] == 0) {
             $content = array();
             start_wp();
             $content['date'] = the_date($GLOBALS['dateformat'], '', '', false);
             $content['time'] = the_time('', false);
             $content['title'] = the_title('', '', false);
             $content['permlink'] = get_permalink();
             $content['author'] = the_author_posts_link('', false);
             $content['category'] = the_category('', '', false);
             $content['body'] = the_content(_WP_TPL_MORE, 0, '', false);
             $content['linkpage'] = link_pages('<br />Pages: ', '<br />', 'number', 'next page', 'previous page', '%', '', false);
             if (get_xoops_option(wp_mod(), 'wp_use_xoops_comments') == 0) {
                 $content['comments'] = comments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS, '', 'Comments Off', false);
             } else {
                 $content['comments'] = xcomments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS, '', 'Comments Off', false);
                 $content['comments'] .= " | ";
                 $content['comments'] .= comments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS, '', 'Comments Off', false);
             }
             $content['trackback'] = trackback_rdf(0, false);
             $block['contents'][] = $content;
         } else {
             ob_start();
             include get_custom_path('content_block-template.php');
             $block['template_content'] .= ob_get_contents();
             ob_end_clean();
         }
     }
     $GLOBALS['previousday'] = 0;
     $GLOBALS['day'] = 0;
     $GLOBALS['comment_count_cache'][wp_id()] = array();
     return $block;
 }