Exemple #1
0
function authors_block($options)
{
    $mydirname = empty($options[0]) ? 'xpress' : $options[0];
    $this_template = empty($options[1]) ? 'db:' . $mydirname . '_block_authors.html' : trim($options[1]);
    $optioncount = empty($options[2]) ? 0 : 1;
    $exclude_admin = empty($options[3]) ? 0 : 1;
    $show_fullname = empty($options[4]) ? 0 : 1;
    $hide_empty = empty($options[5]) ? 0 : 1;
    $mydirpath = get_xpress_dir_path();
    if (xpress_is_wp_version('<', '2.3')) {
        $param_str = 'optioncount=' . $optioncount . '&exclude_admin=' . $exclude_admin . '&show_fullname=' . $show_fullname . '&hide_empty=' . $hide_empty;
        ob_start();
        wp_list_authors($param_str);
        //WP2011 wp_list_authors() used only parse_str()
        $list_authors = ob_get_contents();
        ob_end_clean();
    } else {
        $param = array('optioncount' => $optioncount, 'exclude_admin' => $exclude_admin, 'show_fullname' => $show_fullname, 'hide_empty' => $hide_empty, 'feed' => '', 'feed_image' => '', 'echo' => false);
        $list_authors = wp_list_authors($param);
    }
    if (xpress_is_multi_user()) {
        $all_link = '<li>' . '<a href="' . get_bloginfo('url') . '" title="' . __('All Authors', 'xpress') . '">' . __('All Authors', 'xpress') . '</a></li>';
    } else {
        $all_link = '';
    }
    $output = "<ul>\n" . $all_link . $list_authors . "\n</ul>\n";
    $block['authors'] = $output;
    return $block;
}
function calender_block($options)
{
    $mydirname = empty($options[0]) ? 'xpress' : $options[0];
    $this_template = empty($options[1]) ? 'db:' . $mydirname . '_calender_block.html' : trim($options[1]);
    $sun_color = empty($options[2]) ? '#DB0000' : $options[2];
    $sat_color = empty($options[3]) ? '#004D99' : $options[3];
    //	$mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
    $mydirpath = get_xpress_dir_path();
    $block['calender'] = xpress_get_calendar('sun_color=' . $sun_color . '&sat_color=' . $sat_color);
    return $block;
}
function global_recent_posts_list_block($options)
{
    $mydirname = empty($options[0]) ? 'xpress' : $options[0];
    $this_template = empty($options[1]) ? 'db:' . $mydirname . '_global_recent_posts_list_block.html' : trim($options[1]);
    $disp_count = empty($options[2]) ? '10' : $options[2];
    $disp_red = empty($options[3]) ? '1' : $options[3];
    $disp_green = empty($options[4]) ? '7' : $options[4];
    $date_format = empty($options[5]) ? '' : $options[5];
    $time_format = empty($options[6]) ? '' : $options[6];
    $shown_for_each_blog = empty($options[7]) ? false : true;
    $exclusion_blog = empty($options[8]) ? '0' : $options[8];
    $mydirpath = get_xpress_dir_path();
    if (xpress_is_multiblog() && function_exists('get_blog_list')) {
        if (empty($date_format)) {
            $date_format = get_settings('date_format');
        }
        if (empty($time_format)) {
            $time_format = get_settings('time_format');
        }
        if (empty($tag_select)) {
            $tag_where = '';
        } else {
            $tag_where = "tag='{$tag_select}'&";
        }
        global $wpdb, $wp_query;
        $block = array();
        $data_array = xpress_grobal_recent_posts($disp_count, $exclusion_blog, $shown_for_each_blog);
        $item_no = 0;
        $red_sec = $disp_red * 60 * 60 * 24;
        $green_sec = $disp_green * 60 * 60 * 24;
        foreach ($data_array as $data) {
            $elapse = time() - $data->post_unix_time;
            $new_mark = '';
            if ($elapse < $red_sec) {
                $new_mark = '<em style="color: red; font-size: small;">New! </em>';
            } else {
                if ($elapse < $green_sec) {
                    $new_mark = '<em style="color: green; font-size: small;">New! </em>';
                }
            }
            $data->new_mark = $new_mark;
            $row_data = get_object_vars($data);
            $block['contents']['item' . $item_no] = $row_data;
            $item_no++;
        }
        $block['data_count'] = $item_no;
        //xml unserialise error
        $block['shown_for_each_blog'] = $shown_for_each_blog;
    } else {
        $block['err_message'] = __('This blog is not set to the multi blog.', 'xpress');
    }
    return $block;
}
Exemple #4
0
function search_block($options)
{
    $mydirname = empty($options[0]) ? 'xpress' : $options[0];
    $this_template = empty($options[1]) ? 'db:' . $mydirname . '_block_search.html' : trim($options[1]);
    $input_length = empty($options[2]) ? '18' : $options[2];
    $mydirpath = get_xpress_dir_path();
    $act_url = get_bloginfo('siteurl');
    $output = '<form method="get" id="searchform" action="' . $act_url . '">' . "\n";
    $output .= '<input type="text" name="s" id="s" size="' . $input_length . '" />' . "\n";
    $output .= '<input type="submit" id="searchsubmit" value="' . __('Search', 'xpress') . '" />' . "\n";
    $output .= "</form>\n";
    $block['search'] = $output;
    return $block;
}
function popular_posts_block($options)
{
    $mydirname = empty($options[0]) ? 'xpress' : $options[0];
    $this_template = empty($options[1]) ? 'db:' . $mydirname . '_block_popular.html' : trim($options[1]);
    $disp_count = empty($options[2]) ? '10' : $options[2];
    $show_month_range = empty($options[3]) ? '0' : $options[3];
    $date_format = empty($options[4]) ? '' : $options[4];
    $time_format = empty($options[5]) ? '' : $options[5];
    $tag_select = $options[6];
    $cat_select = empty($options[7]) ? '0' : $options[7];
    $selected = explode(',', $cat_select);
    $mydirpath = get_xpress_dir_path();
    if (empty($date_format)) {
        $date_format = get_settings('date_format');
    }
    if (empty($time_format)) {
        $time_format = get_settings('time_format');
    }
    if (array_search(0, $selected) === 0) {
        $cat_select = 0;
    }
    $cat_select;
    $block = array();
    $item_no = 0;
    $selected_author_id = xpress_selected_author_id('echo=0');
    global $wpdb, $wp_query, $xoops_db;
    $db_prefix = get_wp_prefix();
    $post_tb = $wpdb->posts;
    $view_tb = $db_prefix . 'views';
    $user_tb = $db_prefix . 'users';
    $term_relationships_tb = $wpdb->term_relationships;
    // upper 2.3
    $term_taxonomy = $wpdb->term_taxonomy;
    // upper 2.3
    $terms_tb = $wpdb->terms;
    // upper 2.3
    $post2cat_tb = $wpdb->post2cat;
    //under 2.3
    $categories_tb = $wpdb->categories;
    //under 2.3
    include $mydirpath . '/wp-includes/version.php';
    $select = "SELECT {$view_tb}.post_views, {$post_tb}.ID, {$post_tb}.post_title, {$post_tb}.post_date";
    if ($wp_db_version >= 6124) {
        $from = " FROM (((";
        $from .= " {$post_tb} LEFT JOIN {$view_tb} ON {$post_tb}.ID = {$view_tb}.post_id)";
        $from .= " INNER JOIN {$term_relationships_tb} ON {$post_tb}.ID = {$term_relationships_tb}.object_id)";
        $from .= " INNER JOIN {$term_taxonomy} ON {$term_relationships_tb}.term_taxonomy_id = {$term_taxonomy}.term_taxonomy_id)";
        $from .= " INNER JOIN {$terms_tb} ON {$term_taxonomy}.term_id = {$terms_tb}.term_id ";
        $where = " WHERE {$post_tb}.post_type = 'post' AND {$post_tb}.post_status = 'publish'";
        //		if (!empty($selected_author_id)){
        //			$where  .= " AND ($post_tb.post_author = $selected_author_id) ";
        //			$where  .= " AND ($post_tb.post_author = 2) ";
        //		}
        if ($cat_select) {
            $where .= " AND ({$term_taxonomy}.term_id IN ({$cat_select}))";
        }
        if (!empty($tag_select)) {
            $tag_id_list = get_tag_id($tag_select);
            if (!empty($tag_id_list)) {
                $where .= " AND ({$term_taxonomy}.term_id IN ({$tag_id_list}))";
            }
        }
    } else {
        $from = " FROM ((";
        $from .= " {$post_tb} LEFT JOIN {$view_tb} ON {$post_tb}.ID = {$view_tb}.post_id)";
        $from .= " LEFT JOIN {$post2cat_tb} ON {$post_tb}.ID = {$post2cat_tb}.post_id)";
        $from .= " INNER JOIN {$user_tb} ON {$post_tb}.post_author = {$user_tb}.ID";
        $where = " WHERE ({$post_tb}.post_status = 'publish') AND  (UNIX_TIMESTAMP({$post_tb}.post_date) <= UNIX_TIMESTAMP())";
        if ($cat_select) {
            $where .= " AND ({$post2cat_tb}.category_id IN ({$cat_select}))";
        }
    }
    if ($show_month_range > 0) {
        $where .= " AND (UNIX_TIMESTAMP({$post_tb}.post_date) >= UNIX_TIMESTAMP(DATE_ADD(CURRENT_DATE, INTERVAL -{$show_month_range} month)))";
    }
    $order_limmit = " GROUP BY {$post_tb}.ID ORDER BY {$view_tb}.post_views DESC LIMIT 0, {$disp_count}";
    $sql = $select . $from . $where . $order_limmit;
    $populars = $wpdb->get_results($sql);
    foreach ($populars as $popular) {
        $wp_query->in_the_loop = true;
        //for use the_tags() in multi lopp
        $r = new WP_Query("p={$popular->ID}");
        if ($r->have_posts()) {
            $r->the_post();
            ob_start();
            the_ID();
            $post_id = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_title();
            $title = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_permalink();
            $permalink = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_author_posts_link();
            $author = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_category(' &bull; ');
            $category = ob_get_contents();
            ob_end_clean();
            if (function_exists('the_tags')) {
                ob_start();
                the_tags(__('Tags:', 'xpress') . ' ', ' &bull; ', '');
                $tags = ob_get_contents();
                ob_end_clean();
            } else {
                $tags = '';
            }
            ob_start();
            the_modified_date($date_format);
            $post_modified_date = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_modified_date($time_format);
            $post_modified_time = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_time($date_format);
            $post_date = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_time($time_format);
            $post_time = ob_get_contents();
            ob_end_clean();
            ob_start();
            comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
            $comments_popup_link = ob_get_contents();
            ob_end_clean();
            $post_title = '<a href="' . $permalink . '">' . $title . '</a>';
            $post_date_time = $post_date . ' ' . $post_time;
            $post_modified_date_time = $post_modified_date . ' ' . $post_modified_time;
            $trackback_url = trackback_url(false);
            $post_viwes = xpress_post_views_count('post_id=' . $post_id . '&format=' . __('Views :%d', 'xpress') . '&echo=0');
            //			if (empty($tags)) $tags = __('Not Tag');
            $row_data = array('post_id' => $post_id, 'post_title' => $post_title, 'post_date' => $post_date, 'post_time' => $post_time, 'post_date_time' => $post_date_time, 'post_modified_date' => $post_modified_date, 'post_modified_time' => $post_modified_time, 'post_modified_date_time' => $post_modified_date_time, 'post_author' => $author, 'post_category' => $category, 'post_tags' => $tags, 'post_views' => $post_viwes, 'comment_link' => $comments_popup_link, 'trackback_url' => $trackback_url);
            $block['contents']['item' . $item_no] = $row_data;
            $item_no++;
        }
    }
    // end of foreach
    $block['data_count'] = $item_no;
    //xml unserialise error
    return $block;
}
<?php

global $xoops_db, $xpress_config;
$xoops_trust_path = get_xoops_trust_path();
$xoops_root_path = get_xoops_root_path();
$inc_path = $xoops_trust_path . '/modules/d3forum/include/comment_functions.php';
include_once $inc_path;
$xpress_dir = get_xpress_dir_path();
$xpress_dirname = get_xpress_dir_name();
include_once $xpress_dir . '/class/xpressD3commentContent.class.php';
$dir_name = $xpress_config->d3forum_module_dir;
$forum_id = $xpress_config->d3forum_forum_id;
$external_link_format = $xpress_config->d3forum_external_link_format;
if ($xpress_config->is_d3forum_desc) {
    $order = 'desc';
} else {
    $order = 'asc';
}
if ($xpress_config->is_d3forum_desc) {
    $order = 'desc';
} else {
    $order = 'asc';
}
if ($xpress_config->is_d3forum_flat) {
    $view = 'listposts_flat';
} else {
    $view = 'listtopics';
}
$posts_num = $xpress_config->d3forum_views_num;
// force UPDATE forums.forum_external_link_format "(dirname)::(classname)::(trustdirname)"
$xoops_db->query("UPDATE " . get_xoops_prefix() . $dir_name . "_forums SET forum_external_link_format='" . $external_link_format . "' WHERE forum_id= {$forum_id}");
function recent_comments_block($options)
{
	$mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
	$this_template = empty( $options[1] ) ? 'db:'.$mydirname.'_recent_comments_block.html' : trim( $options[1] );
	$disp_count = empty( $options[2] ) ? '10' : $options[2] ;
	$disp_length = empty( $options[3] ) ? '30' : $options[3] ;
	$date_format = empty( $options[4] ) ? '' : $options[4] ;
	$time_format = empty( $options[5] ) ? '' : $options[5] ;
	$com_select = empty( $options[6] ) ? '0' : $options[6] ;

	$selected = explode(',' , $com_select);

	$mydirpath = get_xpress_dir_path();
	
	if (empty($date_format)) $date_format = get_settings('date_format');
	if (empty($time_format)) $time_format = get_settings('time_format');
	
	$disp_all = in_array('0',$selected);
	$disp_comment = in_array('1',$selected);
	$disp_trackback = in_array('2',$selected);
	$disp_pingback = in_array('3',$selected);
	
	$type_select = '';
	if (!$disp_all){			
		if ($disp_comment){
			$in_where =  "''";
		}
		if ($disp_trackback){
			if (empty($in_where)) $in_where =  "'trackback' "; else $in_where .=  ",'trackback'";
		}
				
		if ($disp_pingback){
			if (empty($in_where)) $in_where =  "'pingback' "; else $in_where .=  ",'pingback'";
		}
		
		if (! empty($in_where)){
			$type_select = " AND comment_type IN($in_where) ";				
		}
	}
	
	global $wpdb;
	$block = array();
		
	if (!is_null($wpdb)){
		$comment_sql  = "SELECT comment_ID,comment_post_ID,comment_author,comment_author_email,comment_author_url,comment_content, comment_type,UNIX_TIMESTAMP(comment_date) as comment_unix_time ";
		$comment_sql .= "FROM $wpdb->comments LEFT JOIN $wpdb->posts ON  $wpdb->posts.ID = $wpdb->comments.comment_post_ID ";
		if (xpress_is_wp_version('<','2.1')){
			$comment_sql .= "WHERE comment_approved = '1' AND post_status = 'publish' $type_select ";
		} else {
			$comment_sql .= "WHERE comment_approved = '1' AND post_type = 'post'  AND post_status = 'publish' $type_select ";
		}
		$comment_sql .= "ORDER BY comment_date_gmt DESC LIMIT $disp_count";
		$comments = $wpdb->get_results($comment_sql);
		
		if ( $comments ) {
			$output .= '<ul>';
			$item_no = 0;
			foreach ($comments as $comment){
				$comment_content = $comment->comment_content;
				$comment_excerpt = ($disp_length>0 ? xpress_substr($comment_content, 0, $disp_length): $comment->comment_content);
				if (xpress_is_wp_version('<','2.7')){
					$comment_link = get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
				} else {
					$comment_link = clean_url(get_comment_link($comment->comment_ID));
				}
				$comment_title = $comment_excerpt;
				$comment_title_link = "<a href='$comment_link' rel='external nofollow' class='url'>$comment_title</a>";

				$post_link = get_permalink($comment->comment_post_ID);
				$post_title = get_the_title($comment->comment_post_ID);
				$post_title_link = '<a href="'. $post_link . '">' . $post_title . '</a>';
				
				$author_link = $comment->comment_author_url;
				$author_name = $comment->comment_author;
				$author_name_link = (( empty( $author_link ) || 'http://' == $author_link ) ? $author_name : "<a href='$author_link' rel='external nofollow' class='url'>$author_name</a>");

				$comment_type = (empty($comment->comment_type) ? 'comment': $comment->comment_type);
				
				$post_title_comment_link = '<a href="'. $comment_link . '">' . $post_title . '</a>';
				$from_auther_to_post = sprintf(__('%1$s on %2$s','xpress'), $author_name_link , $post_title_comment_link );

				$row_data = array(
					'comment_ID' 		=> $comment->comment_ID ,
					'comment_post_ID'	=> $comment->comment_post_ID ,
					'comment_date' 		=> date($date_format,$comment->comment_unix_time) ,
					'comment_date_time' => date($date_format . ' ' . $time_format,$comment->comment_unix_time) ,
					'comment_content' 	=> $comment_content ,
					'comment_excerpt' 	=> $comment_excerpt ,
					'comment_link' 		=> $comment_link,
					'comment_title' 	=> $comment_title ,
					'comment_title_link' => $comment_title_link ,
					'post_link' 		=> $post_link,
					'post_title' 		=> $post_title,
					'post_title_link' 	=> $post_title_link,
					'author_link' 		=> $author_link,
					'author_name' 		=> $author_name,
					'author_name_link' 	=> $author_name_link,
					'comment_type' 		=> $comment_type,
					'from_auther_to_post' => $from_auther_to_post
				);
				
				$block['contents']['item'.$item_no] = $row_data;
				$item_no++;
			}
			$block['data_count'] = $item_no;
		}
	}
	return $block ;
}
function recent_posts_list_block($options)
{
    $mydirname = empty($options[0]) ? 'xpress' : $options[0];
    $this_template = empty($options[1]) ? 'db:' . $mydirname . '_recent_posts_list_block.html' : trim($options[1]);
    $disp_count = empty($options[2]) ? '10' : $options[2];
    $disp_red = empty($options[3]) ? '1' : $options[3];
    $disp_green = empty($options[4]) ? '7' : $options[4];
    $date_format = empty($options[5]) ? '' : $options[5];
    $time_format = empty($options[6]) ? '' : $options[6];
    $tag_select = $options[7];
    $cat_select = empty($options[8]) ? '0' : $options[8];
    $selected = explode(',', $cat_select);
    $mydirpath = get_xpress_dir_path();
    if (empty($date_format)) {
        $date_format = get_settings('date_format');
    }
    if (empty($time_format)) {
        $time_format = get_settings('time_format');
    }
    if (empty($tag_select)) {
        $tag_where = '';
    } else {
        $tag_where = "tag='{$tag_select}'&";
    }
    if (array_search(0, $selected) === 0) {
        $cat_select = 0;
    }
    $selected_author_id = xpress_selected_author_id('echo=0');
    if (!empty($selected_author_id)) {
        $author_where = "author={$selected_author_id}&";
    } else {
        $author_where = '';
    }
    global $wpdb, $wp_query;
    $block = array();
    $item_no = 0;
    if (!is_null($wpdb)) {
        $wp_query->in_the_loop = true;
        //for use the_tags() in multi lopp
        if ($cat_select) {
            $r = new WP_Query($author_where . $tag_where . "cat={$cat_select}&showposts={$disp_count}&what_to_show=posts&nopaging=0&post_status=publish");
        } else {
            $r = new WP_Query($author_where . $tag_where . "showposts={$disp_count}&what_to_show=posts&nopaging=0&post_status=publish");
        }
        while ($r->have_posts()) {
            $r->the_post();
            ob_start();
            the_ID();
            $post_id = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_title();
            $title = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_permalink();
            $permalink = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_author_posts_link();
            $author = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_category(' &bull; ');
            $category = ob_get_contents();
            ob_end_clean();
            if (function_exists('the_tags')) {
                ob_start();
                the_tags(__('Tags:', 'xpress') . ' ', ' &bull; ', '');
                $tags = ob_get_contents();
                ob_end_clean();
            } else {
                $tags = '';
            }
            ob_start();
            the_modified_date($date_format);
            $post_modified_date = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_modified_date($time_format);
            $post_modified_time = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_time($date_format);
            $post_date = ob_get_contents();
            ob_end_clean();
            ob_start();
            the_time($time_format);
            $post_time = ob_get_contents();
            ob_end_clean();
            ob_start();
            comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
            $comments_popup_link = ob_get_contents();
            ob_end_clean();
            $red_sec = $disp_red * 60 * 60 * 24;
            $green_sec = $disp_green * 60 * 60 * 24;
            ob_start();
            the_time('U');
            $check_time = ob_get_contents();
            ob_end_clean();
            $elapse = time() - $check_time;
            $new_mark = '';
            if ($elapse < $red_sec) {
                $new_mark = '<em style="color: red; font-size: small;">New! </em>';
            } else {
                if ($elapse < $green_sec) {
                    $new_mark = '<em style="color: green; font-size: small;">New! </em>';
                }
            }
            $post_title = '<a href="' . $permalink . '">' . $title . '</a>';
            $post_date_time = $post_date . ' ' . $post_time;
            $post_modified_date_time = $post_modified_date . ' ' . $post_modified_time;
            $trackback_url = trackback_url(false);
            $post_viwes = xpress_post_views_count('post_id=' . $post_id . '&format=' . __('Views :%d', 'xpress') . '&echo=0');
            //			if (empty($tags)) $tags = __('Not Tag');
            $row_data = array('post_id' => $post_id, 'new_mark' => $new_mark, 'post_title' => $post_title, 'post_date' => $post_date, 'post_time' => $post_time, 'post_date_time' => $post_date_time, 'post_modified_date' => $post_modified_date, 'post_modified_time' => $post_modified_time, 'post_modified_date_time' => $post_modified_date_time, 'post_author' => $author, 'post_category' => $category, 'post_tags' => $tags, 'post_views' => $post_viwes, 'comment_link' => $comments_popup_link, 'trackback_url' => $trackback_url);
            $block['contents']['item' . $item_no] = $row_data;
            $item_no++;
        }
        $block['data_count'] = $item_no;
        //xml unserialise error
    }
    return $block;
}
function global_recent_comments_block($options)
{
    $mydirname = empty($options[0]) ? 'xpress' : $options[0];
    $this_template = empty($options[1]) ? 'db:' . $mydirname . '_global_recent_comments_block.html' : trim($options[1]);
    $disp_count = empty($options[2]) ? '10' : $options[2];
    $disp_length = empty($options[3]) ? '30' : $options[3];
    $date_format = empty($options[4]) ? '' : $options[4];
    $time_format = empty($options[5]) ? '' : $options[5];
    $com_select = empty($options[6]) ? '0' : $options[6];
    $selected = explode(',', $com_select);
    $mydirpath = get_xpress_dir_path();
    if (empty($date_format)) {
        $date_format = get_settings('date_format');
    }
    if (empty($time_format)) {
        $time_format = get_settings('time_format');
    }
    $disp_all = in_array('0', $selected);
    $disp_comment = in_array('1', $selected);
    $disp_trackback = in_array('2', $selected);
    $disp_pingback = in_array('3', $selected);
    $type_select = '';
    if (!$disp_all) {
        if ($disp_comment) {
            $in_where = "''";
        }
        if ($disp_trackback) {
            if (empty($in_where)) {
                $in_where = "'trackback' ";
            } else {
                $in_where .= ",'trackback'";
            }
        }
        if ($disp_pingback) {
            if (empty($in_where)) {
                $in_where = "'pingback' ";
            } else {
                $in_where .= ",'pingback'";
            }
        }
        if (!empty($in_where)) {
            $type_select = " AND comment_type IN({$in_where}) ";
        }
    }
    global $wpdb, $wp_rewrite, $switched, $blog_id;
    $block = array();
    $comment_array = array();
    if (xpress_is_multiblog()) {
        $blogs = get_blog_list(0, 'all');
        foreach ($blogs as $blog) {
            switch_to_blog($blog['blog_id']);
            $wp_rewrite->init();
            if (!is_null($wpdb)) {
                $comment_sql = "SELECT comment_ID,comment_post_ID,comment_author,comment_author_email,comment_author_url,comment_content, comment_type,UNIX_TIMESTAMP(comment_date) as comment_unix_time ";
                $comment_sql .= "FROM {$wpdb->comments} LEFT JOIN {$wpdb->posts} ON  {$wpdb->posts}.ID = {$wpdb->comments}.comment_post_ID ";
                if (xpress_is_wp_version('<', '2.1')) {
                    $comment_sql .= "WHERE comment_approved = '1' AND post_status = 'publish' {$type_select} ";
                } else {
                    $comment_sql .= "WHERE comment_approved = '1' AND post_type = 'post'  AND post_status = 'publish' {$type_select} ";
                }
                $comment_sql .= "ORDER BY comment_date_gmt DESC LIMIT {$disp_count}";
                $comments = $wpdb->get_results($comment_sql);
                if ($comments) {
                    $blog_title = get_bloginfo('name');
                    $blog_link = get_bloginfo('url');
                    $blog_title_link = '<a href="' . $blog_link . '">' . $blog_title . '</a>';
                    foreach ($comments as $comment) {
                        $comment_content = $comment->comment_content;
                        $comment_unix_time = $comment->comment_unix_time;
                        $comment_excerpt = $disp_length > 0 ? xpress_substr($comment_content, 0, $disp_length) : $comment->comment_content;
                        $comment_link = get_comment_link($comment->comment_ID);
                        $comment_title = $comment_excerpt;
                        $comment_title_link = "<a href='{$comment_link}' rel='external nofollow' class='url'>{$comment_title}</a>";
                        $post_link = get_permalink($comment->comment_post_ID);
                        $post_title = get_the_title($comment->comment_post_ID);
                        $post_title_link = '<a href="' . $post_link . '">' . $post_title . '</a>';
                        $author_link = $comment->comment_author_url;
                        $author_name = $comment->comment_author;
                        $author_name_link = empty($author_link) || 'http://' == $author_link ? $author_name : "<a href='{$author_link}' rel='external nofollow' class='url'>{$author_name}</a>";
                        $comment_type = empty($comment->comment_type) ? 'comment' : $comment->comment_type;
                        $post_title_comment_link = '<a href="' . $comment_link . '">' . $post_title . '</a>';
                        $from_auther_to_post = sprintf(__('%1$s on %2$s', 'xpress'), $author_name_link, $post_title_comment_link);
                        $row_data = array('blog_title' => $blog_title, 'blog_link' => $blog_link, 'blog_title_link' => $blog_title_link, 'comment_ID' => $comment->comment_ID, 'comment_post_ID' => $comment->comment_post_ID, 'comment_unix_time' => $comment_unix_time, 'comment_date' => date($date_format, $comment->comment_unix_time), 'comment_date_time' => date($date_format . ' ' . $time_format, $comment->comment_unix_time), 'comment_content' => $comment_content, 'comment_excerpt' => $comment_excerpt, 'comment_link' => $comment_link, 'comment_title' => $comment_title, 'comment_title_link' => $comment_title_link, 'post_link' => $post_link, 'post_title' => $post_title, 'post_title_link' => $post_title_link, 'author_link' => $author_link, 'author_name' => $author_name, 'author_name_link' => $author_name_link, 'comment_type' => $comment_type, 'from_auther_to_post' => $from_auther_to_post);
                        $comment_array[] = $row_data;
                    }
                    $block['data_count'] = $item_no;
                }
            }
            restore_current_blog();
            $wp_rewrite->init();
        }
        // end of foreach
        usort($comment_array, "the_comment_time_cmp");
        if (!empty($disp_count)) {
            $comment_array = array_slice($comment_array, 0, $disp_count);
        }
        $item_no = 0;
        foreach ($comment_array as $comment) {
            $block['contents']['item' . $item_no] = $comment;
            $item_no++;
        }
        $block['data_count'] = $item_no;
    } else {
        $block['err_message'] = __('This blog is not set to the multi blog.', 'xpress');
    }
    return $block;
}
Exemple #10
0
 function xpress_unnecessary_block_cache_delete($mydirname)
 {
     global $xoops_db, $xoops_config;
     $mid = get_xpress_modid();
     $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = {$mid} AND visible = 1";
     $blocks = $xoops_db->get_results($sql);
     require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
     $pattern = $mydirname . '_block_header';
     foreach ($blocks as $block) {
         $cache_file_name = $mydirname . '_' . str_replace(".php", "", $block->func_file) . $block->bid;
         if (!empty($pattern)) {
             $pattern .= '|';
         }
         $pattern .= $cache_file_name;
     }
     $pattern = '(' . $pattern . ')';
     $cache_dir = $xoops_config->xoops_cache_path . '/';
     $cache_time = 0;
     if ($dh = opendir($cache_dir)) {
         while (($file = readdir($dh)) !== false) {
             if (preg_match('/^' . preg_quote($mydirname) . '_/', $file)) {
                 if (!preg_match('/' . $pattern . '/', $file)) {
                     unlink($cache_dir . $file);
                 }
             }
         }
         closedir($dh);
     }
 }
function wp_comment_sync_to_d3forum($comment_ID = 0, $sync_mode)
{
    global $xpress_config, $xoops_db, $xoops_config, $wpdb, $blog_id;
    if (empty($blog_id)) {
        $blog_id = 1;
    }
    if (!is_d3forum_setting()) {
        die('The setting of the D3Forum comment integration is wrong. ');
    }
    $mydirname = $xoops_config->module_name;
    $d3f_forum_id = $xpress_config->d3forum_forum_id;
    $d3f_forum_dir = $xpress_config->d3forum_module_dir;
    $d3forum_prefix = get_xoops_prefix() . $d3f_forum_dir . '_';
    $xpress_prefix = get_wp_prefix();
    $wp_comments = $wpdb->comments;
    //	$wp_comments = $xpress_prefix . 'comments';
    $wp_posts = $wpdb->posts;
    //	$wp_posts = $xpress_prefix . 'posts';
    $wp_d3forum_link = $xpress_prefix . 'd3forum_link';
    $d3f_topic = $d3forum_prefix . 'topics';
    $d3f_posts = $d3forum_prefix . 'posts';
    $sql = "SELECT {$wp_comments}.comment_ID,{$wp_comments}.comment_post_ID, ";
    $sql .= "{$wp_comments}.comment_author, {$wp_comments}.comment_author_email,  {$wp_comments}.comment_date, {$wp_comments}.comment_date_gmt, ";
    $sql .= "{$wp_comments}.comment_author_url, {$wp_comments}.comment_author_IP, ";
    $sql .= "{$wp_comments}.comment_content, {$wp_comments}.comment_karma, ";
    $sql .= "{$wp_comments}.comment_approved, {$wp_comments}.comment_agent, ";
    $sql .= "{$wp_comments}.comment_type, {$wp_comments}.comment_parent, {$wp_comments}.user_id, ";
    $sql .= "{$wp_posts}.post_title ,{$wp_posts}.comment_count ";
    $sql .= "FROM {$wp_comments} INNER JOIN  {$wp_posts} ON {$wp_comments}.comment_post_ID = {$wp_posts}.ID ";
    $sql .= "WHERE (comment_ID = {$comment_ID}) AND ({$wp_comments}.comment_approved NOT LIKE 'spam') ";
    //	$row = $xoops_db->get_row($sql) ;
    $row = $wpdb->get_row($sql);
    if (empty($row)) {
        die('READ ' . $wp_comments . '_NG...' . $sql);
    }
    if (!empty($row->comment_type)) {
        return;
    }
    $forum_id = $d3f_forum_id;
    $d3forum_dirname = $d3f_forum_dir;
    $topic_external_link_id = $row->comment_post_ID;
    //There is information on WP post_ID in topic_external_link_id of D3Forum
    $topic_title = 'Re.' . addSlashes($row->post_title);
    $post_time = strtotime($row->comment_date_gmt);
    $modified_time = strtotime($row->comment_date_gmt);
    require_once get_xpress_dir_path() . 'include/general_functions.php';
    if (empty($row->user_id)) {
        $uid = wp_comment_author_to_xoops_uid($row->comment_author, $row->comment_author_email);
    } else {
        $uid = wp_uid_to_xoops_uid($row->user_id, $mydirname);
    }
    $poster_ip = "'" . addslashes($row->comment_author_IP) . "'";
    $modifier_ip = "'" . addslashes($row->comment_author_IP) . "'";
    $subject = "'" . $topic_title . "'";
    $post_text = "'" . addSlashes($row->comment_content) . "'";
    $guest_name = "'" . addSlashes($row->comment_author) . "'";
    $guest_email = "'" . $row->comment_author_email . "'";
    $guest_url = "'" . $row->comment_author_url . "'";
    $approval = $row->comment_approved;
    $comment_count = $row->comment_count;
    $comment_parent = $row->comment_parent;
    if ($sync_mode == 'delete') {
        $mode = 'delete';
        $delete_post_id = $xoops_db->get_var("SELECT post_id FROM {$wp_d3forum_link} WHERE comment_ID = {$comment_ID} AND  blog_id = {$blog_id}");
        if (empty($delete_post_id)) {
            return;
        }
        $topic_id = $xoops_db->get_var("SELECT topic_id FROM {$d3f_topic} WHERE topic_external_link_id = {$topic_external_link_id} AND forum_id = {$forum_id}");
        if (empty($topic_id)) {
            return;
        }
    } else {
        // Does the first comment (= topic) on the post exist?
        $sql = "SELECT * FROM {$d3f_topic} WHERE topic_external_link_id = {$topic_external_link_id} AND forum_id = {$forum_id}";
        $row = $xoops_db->get_row($sql);
        $topic_first_post_id = $row->topic_first_post_id;
        if (empty($row)) {
            $mode = $mode = 'newtopic';
        } else {
            $topic_id = $row->topic_id;
            // if comment on same ID exists then edits comment else reply comment
            $row = $xoops_db->get_row("SELECT * FROM {$wp_d3forum_link} WHERE comment_ID = {$comment_ID} AND blog_id = {$blog_id}");
            if (!empty($row)) {
                $mode = $mode = 'edit';
                $edit_post_id = $row->post_id;
            } else {
                $mode = $mode = 'reply';
                $reply_pid = 0;
                if ($comment_parent > 0) {
                    $reply_pid = get_d3forum_post_ID($comment_parent);
                }
                if ($reply_pid == 0) {
                    $reply_pid = $topic_first_post_id;
                    //reply_first_comment
                }
            }
        }
    }
    $modified_time = $post_time;
    // make set part of INSERT or UPDATE (refalence d3forum main/post.php)
    $set4sql = "modified_time= {$modified_time} , modifier_ip= {$modifier_ip} ";
    $set4sql .= ",subject= {$subject} ";
    $set4sql .= ",post_text= {$post_text} ";
    if ($uid == 0) {
        @(list($guest_name, $trip_base) = explode('#', $guest_name, 2));
        if (!trim(@$guest_name)) {
            $guest_name = get_xoops_config('anonymous_name', $d3f_forum_dir);
        }
        if (!empty($trip_base) && function_exists('crypt')) {
            $salt = strtr(preg_replace('/[^\\.-z]/', '.', substr($trip_base . 'H.', 1, 2)), ':;<=>?@[\\]^_`', 'ABCDEFGabcdef');
            $guest_trip = substr(crypt($trip_base, $salt), -10);
        } else {
            $guest_trip = '';
        }
        $guest_url = preg_match('#^https?\\://#', $guest_url) ? $guest_url : '';
        foreach (array('guest_name', 'guest_email', 'guest_url', 'guest_trip') as $key) {
            $set4sql .= ",{$key}='" . addslashes(${$key}) . "'";
        }
        if (!empty($guest_pass)) {
            $set4sql .= ",guest_pass_md5='" . md5($guest_pass . 'd3forum') . "'";
        }
    }
    $hide_uid = get_xoops_config('allow_hideuid', $d3f_forum_dir);
    switch ($mode) {
        case 'edit':
            $edit_post = $xoops_db->get_row("SELECT * FROM {$d3f_posts} WHERE post_id= {$edit_post_id} ");
            if (empty($edit_post)) {
                die('READ ' . $d3forum_comments . '_NG...' . $sql);
            }
            // approval
            if ($approval) {
                $set4sql .= ',approval=1';
                $topic_invisible = 0;
                $need_notify = true;
            } else {
                $set4sql .= ',approval=0';
                $topic_invisible = 0;
                $need_admin_notify = true;
            }
            // hide_uid
            if ($hide_uid) {
                $set4sql .= ",uid=0,uid_hidden='{$uid}'";
            } else {
                $set4sql .= ",uid='{$uid}',uid_hidden=0";
            }
            // update post specified post_id
            wp_d3forum_transact_make_post_history($d3forum_dirname, $edit_post_id);
            $sql = "UPDATE " . $d3f_posts . " SET {$set4sql} WHERE post_id={$edit_post_id}";
            $xoops_db->query($sql);
            $xoops_db->query($sql);
            if ($edit_post_pid == 0) {
                $sql = "UPDATE " . $d3f_topic . " SET topic_invisible={$topic_invisible} WHERE topic_id={$topic_id}";
                $xoops_db->query($sql);
            }
            wp_d3forum_sync_topic($d3forum_dirname, $topic_id, true, !$edit_post_pid);
            break;
        case 'reply':
            // approval
            if ($approval) {
                $set4sql .= ',approval=1';
                $need_notify = true;
            } else {
                $set4sql .= ',approval=0';
                $need_admin_notify = true;
            }
            // hide_uid
            if ($hide_uid) {
                $set4sql .= ",uid=0,uid_hidden='{$uid}'";
            } else {
                $set4sql .= ",uid='{$uid}',uid_hidden=0";
            }
            // create post under specified post_id
            $sql = "INSERT INTO " . $d3f_posts . " SET {$set4sql},pid={$reply_pid},topic_id={$topic_id},post_time={$post_time},poster_ip={$poster_ip}";
            $xoops_db->query($sql);
            $post_id = mysql_insert_id();
            wp_d3forum_sync_topic($d3forum_dirname, $topic_id);
            $wp_sql = "INSERT INTO {$wp_d3forum_link} ";
            $wp_sql .= "(comment_ID , post_id, wp_post_ID, forum_id, blog_id) ";
            $wp_sql .= "VALUES ";
            $wp_sql .= "({$comment_ID}, {$post_id}, {$topic_external_link_id}, {$d3f_forum_id}, {$blog_id})";
            $xoops_db->query($wp_sql);
            break;
        case 'newtopic':
            // approval
            if ($approval) {
                $set4sql .= ',approval=1';
                $topic_invisible = 0;
                $need_notify = true;
            } else {
                $set4sql .= ',approval=0';
                $topic_invisible = 0;
                $need_admin_notify = true;
            }
            // hide_uid
            if ($hide_uid) {
                $set4sql .= ",uid=0,uid_hidden='{$uid}'";
            } else {
                $set4sql .= ",uid='{$uid}',uid_hidden=0";
            }
            // create topic and get a new topic_id
            $sql = "INSERT INTO " . $d3f_topic . " SET forum_id={$forum_id},topic_invisible={$topic_invisible},topic_external_link_id='" . addslashes($topic_external_link_id) . "'";
            $xoops_db->query($sql);
            $topic_id = mysql_insert_id();
            // create post in the topic
            $sql = "INSERT INTO " . $d3f_posts . " SET {$set4sql},topic_id={$topic_id},post_time={$post_time},poster_ip={$poster_ip}";
            $xoops_db->query($sql);
            $post_id = mysql_insert_id();
            wp_d3forum_sync_topic($d3forum_dirname, $topic_id, true, true);
            $wp_sql = "INSERT INTO {$wp_d3forum_link} ";
            $wp_sql .= "(comment_ID , post_id , wp_post_ID, forum_id, blog_id) ";
            $wp_sql .= "VALUES ";
            $wp_sql .= "({$comment_ID}, {$post_id}, {$topic_external_link_id}, {$d3f_forum_id}, {$blog_id})";
            $xoops_db->query($wp_sql);
            break;
        case 'delete':
            wp_d3forum_delete_post_recursive($d3forum_dirname, $delete_post_id);
            wp_d3forum_sync_topic($d3forum_dirname, $topic_id);
            break;
        default:
    }
    // increment post
    if (is_object(@$xoopsUser) && $mode != 'edit') {
        $xoopsUser->incrementPost();
    }
    // set u2t_marked
    $allow_mark = get_xoops_config('allow_mark', $d3f_forum_dir);
    if ($uid && $allow_mark) {
        $u2t_marked = empty($_POST['u2t_marked']) ? 0 : 1;
        $sql = "UPDATE " . $d3forum_prefix . "users2topics" . " SET u2t_marked={$u2t_marked},u2t_time=UNIX_TIMESTAMP() WHERE uid={$uid} AND topic_id={$topic_id}";
        if (!$xoops_db->query($sql)) {
            $sql = "INSERT INTO " . $d3forum_prefix . "users2topics" . " SET uid={$uid},topic_id={$topic_id},u2t_marked={$u2t_marked},u2t_time=UNIX_TIMESTAMP()";
            $xoops_db->query($sql);
        }
    }
}
function recent_posts_content_block($options)
{
	$mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
	$this_template = empty( $options[1] ) ? 'db:'.$mydirname.'_recent_posts_content_block.html' : trim( $options[1] );
	$disp_count =  ($options[2])?intval($options[2]):10;
	$excerpt = empty( $options[3] ) ? false : true ;
	$excerpt_size =  ($options[4])?intval($options[4]):100;
	$date_format = empty( $options[5] ) ? '' : $options[5] ;
	$time_format = empty( $options[6] ) ? '' : $options[6] ;
	$tag_select = $options[7] ;
	$cat_select = empty( $options[8] ) ? '0' : $options[8] ;
	$day_select = ($options[9])?intval($options[9]):0;
	$day_size = ($options[10])?intval($options[10]):0;

	$selected = explode(',' , $cat_select);
	
	$mydirpath = get_xpress_dir_path();
	
	if (empty($date_format)) $date_format = get_settings('date_format');
	if (empty($time_format)) $time_format = get_settings('time_format');
	if(empty($tag_select)) $tag_where = ''; else $tag_where = "tag='$tag_select'&";
	if (array_search(0,$selected)===0) $cat_select = 0;

	$selected_author_id = xpress_selected_author_id('echo=0');	
	if (!empty($selected_author_id)){
		$author_where ="author=$selected_author_id&";
	} else {
		$author_where = '';
	}
	
	$date_today = mktime (0, 0, 0, date("m"), date("d"), date("Y"));
	$between_days = $day_size * 60 * 60 * 24;
	
	global $wpdb,$wp_query;
	$block = array();
	$item_no = 0;	
	if (!is_null($wpdb)){
		$wp_query->in_the_loop = true;		//for use the_tags() in multi lopp 
		if ($cat_select) {
			$r = new WP_Query($author_where . $tag_where ."cat=$cat_select&showposts=$disp_count&what_to_show=posts&nopaging=0&post_status=publish");
		} else {
			$r = new WP_Query($author_where . $tag_where ."showposts=$disp_count&what_to_show=posts&nopaging=0&post_status=publish");
		}
		while($r->have_posts()){			
			$r->the_post();
			if ($day_select == 1){
				$post_date = mktime (0, 0, 0, get_the_time("m"), get_the_time("d"), get_the_time("Y"));
				$base_date = $date_today - $between_days;
				if ($post_date < $base_date) continue;
			}
			if ($day_select == 2){
				$post_date = mktime (0, 0, 0, get_the_time("m"), get_the_time("d"), get_the_time("Y"));
				if (empty($latest_date)) $latest_date = $post_date;
				$base_date = $latest_date - $between_days;
				if ($post_date < $base_date) continue;
			}
			
			ob_start();
				the_ID();
				$post_id = ob_get_contents();
			ob_end_clean();
			
			$title = xpress_the_title('echo=0');
			
			ob_start();
				the_permalink();
				$permalink = ob_get_contents();
			ob_end_clean();					
			
			ob_start();
				the_author_posts_link();
				$author = ob_get_contents();
			ob_end_clean();
			
			ob_start();
				the_category(' &bull; ');
				$category = ob_get_contents();
			ob_end_clean();	
			
			if (function_exists('the_tags')){
				ob_start();
					the_tags(__('Tags:', 'xpress') . ' ',' &bull; ','');
					$tags = ob_get_contents();
				ob_end_clean();	
			} else {
				$tags = '';
			}

			$param = array(
				'configration_select' => 0, 
				'do_excerpt' => $excerpt,
				'excerpt_length_word' => $excerpt_size, 
				'excerpt_length_character' => $excerpt_size, 
				'echo' => 0
			);

			$post_content = xpress_the_content($param);
			
			ob_start();
				the_modified_date($date_format);
				$post_modified_date = ob_get_contents();
			ob_end_clean();
				
			ob_start();
				the_modified_date($time_format);
				$post_modified_time = ob_get_contents();
			ob_end_clean();
			
			ob_start();
				the_time($date_format);
				$post_date = ob_get_contents();
			ob_end_clean();
			
			ob_start();
				the_time($time_format);
				$post_time = ob_get_contents();
			ob_end_clean();
			
			
			ob_start();
				comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
				$comments_popup_link = ob_get_contents();
			ob_end_clean();

// all_in_one			
			ob_start();
?>
				<div class="xpress-post" id="post-<?php the_ID(); ?>">
					<div class ="xpress-post-header">
						<?php if (function_exists('hotDates')) { hotDates(); }?>
						<div class ="xpress-post-title">
							<?php if(function_exists('the_title_attribute')) : ?>			
								<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'xpress'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h2>
							<?php else : ?>
								<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'xpress'), the_title('','',false)); ?>"><?php the_title(); ?></a></h2>
							<?php endif; ?>

						</div>
					</div>
					<div class="xpress-post-entry">
					<?php	echo $post_content; ?>							
					</div>
					<div class="xpress-link-pages"><?php wp_link_pages() ?></div>
					<div class ="xpress-post-footer">
<?php
						the_time('Y/m/d l');
						echo ' - ';
						the_author_posts_link();
						echo ' (' . xpress_post_views_count('post_id=' . $post->ID . '&format=' . __('Views :%d', 'xpress'). '&echo=0') . ')'; 
						
						echo ' | ';
						// echo the_tags(__('Tags:', 'xpress') . ' ', ', ', ' | ');
						printf(__('Posted in %s', 'xpress'), get_the_category_list(', '));
						echo ' | ';
						edit_post_link(__('Edit', 'xpress'), '', ' | ');
						comments_popup_link(__('No Comments &#187;', 'xpress'), __('1 Comment &#187;', 'xpress'), __('% Comments &#187;', 'xpress'), '', __('Comments Closed', 'xpress') );
?>
					</div>
				</div>
<?php
			$all_in_one = ob_get_contents();
			ob_end_clean();
						
			
			$post_title = '<a href="' . $permalink . '">' . $title . '</a>';
			$post_date_time = $post_date . ' ' . $post_time ;
			$post_modified_date_time = $post_modified_date . ' ' . $post_modified_time ;
			$trackback_url = trackback_url(false);
			$post_viwes = xpress_post_views_count('post_id=' . $post_id . '&format=' . __('Views :%d', 'xpress'). '&echo=0');

//			if (empty($tags)) $tags = __('Not Tag');

			$row_data = array(
				'post_id'		=> $post_id ,
				'post_title'	=> $post_title ,
				'post_content' 		=> $post_content ,
				'post_date' => $post_date ,
				'post_time' => $post_time ,
				'post_date_time' => $post_date_time ,
				'post_modified_date' => $post_modified_date ,
				'post_modified_time' => $post_modified_time ,
				'post_modified_date_time' => $post_modified_date_time ,
				'post_author' 	=> $author ,
				'post_category' 	=> $category ,	
				'post_tags' 		=> $tags,
				'post_views' 		=> $post_viwes,
				'comment_link' 	=> $comments_popup_link ,
				'trackback_url' => $trackback_url ,
				'all_in_one' => $all_in_one
			);
			
			$block['contents']['item'.$item_no] = $row_data;
			$item_no++;
		}
		$block['data_count'] = $item_no;  //xml unserialise error
	}
	return $block ;
}
function global_popular_posts_block($options)
{
	$mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
	$this_template = empty( $options[1] ) ? 'db:'.$mydirname.'_grobal_popular_posts_block.html' : trim( $options[1] );
	$disp_count = empty( $options[2] ) ? '10' : $options[2] ;
	$show_month_range = empty( $options[3] ) ? '0' : $options[3] ;
	$date_format = empty( $options[4] ) ? '' : $options[4] ;
	$time_format = empty( $options[5] ) ? '' : $options[5] ;
	
	$selected = explode(',' , $cat_select);

	$mydirpath = get_xpress_dir_path();
	
	if (empty($date_format)) $date_format = get_settings('date_format');
	if (empty($time_format)) $time_format = get_settings('time_format');
	
	$cat_select;
	$block = array();
	$item_no = 0;	
	
	$selected_author_id = xpress_selected_author_id('echo=0');	
	
	$data_array = array();

	global $wpdb,$wp_query,$xoops_db,$wp_rewrite;
	
	if (xpress_is_multiblog()){
		$blogs = get_blog_list(0,'all');
		foreach ($blogs AS $blog) {
			switch_to_blog($blog['blog_id']);
			$wp_rewrite->init();
			
			$blog_title = get_bloginfo('name');
			$blog_link = get_bloginfo('url');
			$blog_title_link = '<a href="' . $blog_link . '">' . $blog_title . '</a>' ;

			$db_prefix = get_wp_prefix();
			
			$post_tb = $wpdb->posts;
			$view_tb = $db_prefix . 'views';
			$user_tb = $db_prefix . 'users';
			
			$term_relationships_tb = $wpdb->term_relationships;	// upper 2.3
			$term_taxonomy = $wpdb->term_taxonomy;				// upper 2.3
			$terms_tb = $wpdb->terms;							// upper 2.3

			$post2cat_tb = $wpdb->post2cat; 					//under 2.3
			$categories_tb = $wpdb->categories; 				//under 2.3
			
			include ($mydirpath . '/wp-includes/version.php');
				
			$select = "SELECT $view_tb.post_views, $post_tb.ID, $post_tb.post_title, $post_tb.post_date";				
			if ($wp_db_version >= 6124){
		 		$from  = " FROM (((";
		 		$from .= " $post_tb LEFT JOIN $view_tb ON $post_tb.ID = $view_tb.post_id)";
		 		$from .= " INNER JOIN $term_relationships_tb ON $post_tb.ID = $term_relationships_tb.object_id)";
		 		$from .= " INNER JOIN $term_taxonomy ON $term_relationships_tb.term_taxonomy_id = $term_taxonomy.term_taxonomy_id)";
		 		$from .= " INNER JOIN $terms_tb ON $term_taxonomy.term_id = $terms_tb.term_id ";
		 		
			 	$where = " WHERE $post_tb.post_type = 'post' AND $post_tb.post_status = 'publish'";
			} else {
				$from  = " FROM ((";
				$from .= " $post_tb LEFT JOIN $view_tb ON $post_tb.ID = $view_tb.post_id)";
				$from .= " LEFT JOIN $post2cat_tb ON $post_tb.ID = $post2cat_tb.post_id)";
				$from .= " INNER JOIN $user_tb ON $post_tb.post_author = $user_tb.ID";
				
				$where = " WHERE ($post_tb.post_status = 'publish') AND  (UNIX_TIMESTAMP($post_tb.post_date) <= UNIX_TIMESTAMP())" ;
				
			}
				

			if ($show_month_range > 0) {
			 		$where .= " AND (UNIX_TIMESTAMP($post_tb.post_date) >= UNIX_TIMESTAMP(DATE_ADD(CURRENT_DATE, INTERVAL -$show_month_range month)))";
			}
			$order_limmit = " GROUP BY $post_tb.ID ORDER BY $view_tb.post_views DESC LIMIT 0, $disp_count";
			$sql = $select . $from . $where . $order_limmit;

			$populars = $wpdb->get_results($sql);
			
			foreach ($populars as $popular){
				$wp_query->in_the_loop = true;		//for use the_tags() in multi lopp 
				$r = new WP_Query("p=$popular->ID");
				if($r->have_posts()){
					$r->the_post();
					ob_start();
						the_ID();
						$post_id = ob_get_contents();
					ob_end_clean();
					
					ob_start();
						the_title();
						$title = ob_get_contents();
					ob_end_clean();
					
					ob_start();
						the_permalink();
						$permalink = ob_get_contents();
					ob_end_clean();					
					
					ob_start();
						the_author_posts_link();
						$author = ob_get_contents();
					ob_end_clean();
					
					ob_start();
						the_category(' &bull; ');
						$category = ob_get_contents();
					ob_end_clean();	
					
					if (function_exists('the_tags')){
						ob_start();
							the_tags(__('Tags:', 'xpress') . ' ',' &bull; ','');
							$tags = ob_get_contents();
						ob_end_clean();	
					} else {
						$tags = '';
					}
					
					ob_start();
						the_modified_date($date_format);
						$post_modified_date = ob_get_contents();
					ob_end_clean();
						
					ob_start();
						the_modified_date($time_format);
						$post_modified_time = ob_get_contents();
					ob_end_clean();
					
					ob_start();
						the_time($date_format);
						$post_date = ob_get_contents();
					ob_end_clean();
					
					ob_start();
						the_time($time_format);
						$post_time = ob_get_contents();
					ob_end_clean();
					
					
					ob_start();
						comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
						$comments_popup_link = ob_get_contents();
					ob_end_clean();
					

					$post_title = '<a href="' . $permalink . '">' . $title . '</a>';
					$post_date_time = $post_date . ' ' . $post_time ;
					$post_modified_date_time = $post_modified_date . ' ' . $post_modified_time ;
					$trackback_url = trackback_url(false);
					$post_views = xpress_post_views_count('post_id=' . $post_id . '&format=' . __('Views :%d', 'xpress'). '&echo=0');
					$post_views_num = (int) xpress_post_views_count("post_id={$post_id}&format=%d&echo=0");
					$row_data = array(
						'blog_title' => $blog_title ,
						'blog_link' => $blog_link ,
						'blog_title_link' => $blog_title_link ,
						'post_id'		=> $post_id ,
						'post_title'	=> $post_title ,
						'post_date' => $post_date ,
						'post_time' => $post_time ,
						'post_date_time' => $post_date_time ,
						'post_modified_date' => $post_modified_date ,
						'post_modified_time' => $post_modified_time ,
						'post_modified_date_time' => $post_modified_date_time ,
						'post_author' 	=> $author ,
						'post_category' 	=> $category ,	
						'post_tags' 		=> $tags,
						'post_views' 		=> $post_views,
						'post_views_num'	=> $post_views_num,
						'comment_link' 	=> $comments_popup_link ,
						'trackback_url' => $trackback_url
					);
					$data_array[] = $row_data;
				}
			}  // end of foreach
			restore_current_blog();
			$wp_rewrite->init();
		}
		usort($data_array, "post_views_cmp");
		if (!empty($disp_count)){
			$data_array = array_slice($data_array,0,$disp_count);
		}

		$item_no = 0;
		foreach ($data_array as $data) {
			$block['contents']['item'.$item_no] = $data;
			$item_no++;
		}
		$block['data_count'] = $item_no;
	} else {
		$block['err_message'] = __('This blog is not set to the multi blog.', 'xpress');
	}
	return $block ;
}
function block_cache_refresh()
{
    global $xoops_db;
    $mid = get_xpress_modid();
    $sql = "SELECT bid,options,func_file FROM " . get_xoops_prefix() . "newblocks WHERE mid = {$mid}";
    $blocks = $xoops_db->get_results($sql);
    $mydirname = get_xpress_dir_name();
    require_once get_xpress_dir_path() . '/include/xpress_block_render.php';
    foreach ($blocks as $block) {
        $func_file = $block->func_file;
        // Avoid the failure of the operation when switch_to_blog() and other plugin code is called on the admin page.
        $excludes = 'global_recent_posts_list_block\\.php|enhanced_block\\.php|global_recent_comments_block\\.php|global_popular_posts_block\\.php';
        if (preg_match('/' . $excludes . '/', $func_file)) {
            continue;
        }
        $call_theme_function_name = str_replace(".php", "", $func_file);
        $inc_theme_file_name = str_replace(".php", "", $func_file) . '_theme.php';
        $cache_title = str_replace(".php", "", $func_file);
        $blockID = $block->bid;
        $options = explode("|", $block->options);
        $block_theme_file = get_block_file_path($mydirname, $inc_theme_file_name);
        require_once $block_theme_file['file_path'];
        $block_render = $call_theme_function_name($options);
        //The block name and the called function name should be assumed to be the same name.
        $xml['block'] = $block_render;
        $xml['block']['options'] = $block->options;
        xpress_block_cache_write($mydirname, $cache_title . $blockID, $xml);
    }
}