XPressME Integration Kit

Trac

source: trunk/xpressme_integration_kit/wp-content/themes/xpress_default/blocks/blog_list_block_theme.php @ 533

Last change on this file since 533 was 533, checked in by toemon, 14 years ago

MultiBlog用にブログリストブロックを追加 Fixes #297

File size: 2.3 KB
Line 
1<?php
2// Block Version: 1.0
3function blog_list_block($options)
4{
5        $mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
6        $this_template = empty( $options[1] ) ? 'db:'.$mydirname.'_block_category.html' : trim( $options[1] );
7        $orderby = empty( $options[2] ) ? 'name' : $options[2] ;
8        $order = empty( $options[3] ) ? 'ASC' : $options[3] ;
9
10        $blogs = get_blog_list(0,'all');
11        $data = array();
12        foreach ($blogs AS $blog) {
13                $url =  get_blog_option($blog['blog_id'],'siteurl');
14                $blog_name = get_blog_option( $blog['blog_id'], 'blogname' );
15                $blog_link = "<a href=\" $url \"> $blog_name </a>";
16                $blog_id = $blog['blog_id'];
17                $post_count = $blog['postcount'];
18                $last_post_date = '';
19                $last_post_time = '';
20                $last_post_date_time = '';
21                       
22                $row_data = array(
23                        'blog_id'               => $blog_id ,
24                        'blog_name'     => $blog_link ,
25                        'last_post_date' => $last_post_date ,
26                        'last_post_time' => $last_post_time ,
27                        'post_date_time' => $last_post_date_time ,
28                        'last_post_date_time' => $post_modified_date ,
29                        'post_count' => $post_count
30                );
31                $data[] = $row_data;
32        }
33        if (strcmp($order,'ASC') == 0){
34                switch($orderby){
35                        case 'count':
36                                usort($data, "r_post_count_cmp");
37                                break;
38                        case 'ID' :
39                                usort($data, "r_blog_id_cmp");
40                                break;
41                        default :
42                                usort($data, "r_blog_name_cmp");
43                }
44        } else {
45                switch($orderby){
46                        case 'count':
47                                usort($data, "post_count_cmp");
48                                break;
49                        case 'ID' :
50                                usort($data, "blog_id_cmp");
51                                break;
52                        default :
53                                usort($data, "blog_name_cmp");
54                }
55        }
56       
57        $block = array();
58        $item_no = 0;   
59        foreach ($data AS $row) {
60                $block['contents']['item'.$item_no] = $row;
61                $item_no++;
62        }// end of foreach
63        $block['data_count'] = $item_no;  //xml unserialise error
64        return $block ;
65}
66function blog_name_cmp($a, $b)
67{
68    return - strcasecmp($a["blog_name"], $b["blog_name"]);
69}
70function blog_id_cmp($a, $b)
71{
72    return $b["blog_id"] - $a["blog_id"];
73}
74function post_count_cmp($a, $b)
75{
76    return $b["post_count"] - $a["post_count"];
77}
78
79function r_blog_name_cmp($a, $b)
80{
81    return strcasecmp($a["blog_name"], $b["blog_name"]);
82}
83function r_blog_id_cmp($a, $b)
84{
85    return $a["blog_id"] - $b["blog_id"];
86}
87function r_post_count_cmp($a, $b)
88{
89    return $a["post_count"] - $b["post_count"];
90}
91
92?>
Note: See TracBrowser for help on using the repository browser.