XPressME Integration Kit

Trac

source: trunk/blocks/xpress_block_recent_comments.php @ 35

Last change on this file since 35 was 35, checked in by toemon, 15 years ago

ブロックのテストの為にXOOPSの基本構成でコメントブロックを作成
現状ではブロック側がモジュール複製には対応していない。

File size: 6.1 KB
Line 
1<?php
2if( ! defined( 'XOOPS_ROOT_PATH' ) ) exit ;
3$mydirname = basename( dirname( dirname( __FILE__ ) ) ) ;
4
5eval( '
6function b_'.$mydirname.'_comments_show($options){
7        return _b_comments_show($options) ;
8}
9function b_'.$mydirname.'_comments_edit($options){
10        return _b_comments_edit($options) ;
11}
12' ) ;
13
14
15if( ! defined( 'XPRESS_COMMENTS_BLOCK_INCLUDED' ) ) {
16        define( 'XPRESS_COMMENTS_BLOCK_INCLUDED' , 1 ) ;
17        function _b_comments_edit($options)
18        {
19                $mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
20                $disp_count = empty( $options[1] ) ? '10' : $options[1] ;
21                $disp_length = empty( $options[2] ) ? '30' : $options[2] ;
22            $selected = array_slice($options,5); // get allowed cats
23                $this_template = empty( $options[6] ) ? 'db:'.$mydirname.'_block_comments.html' : trim( $options[4] );
24                $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
25
26                require_once(XOOPS_ROOT_PATH.'/modules/'.$mydirname.'/blocks/block_common.php');
27               
28                $form  = "MyDirectory <input type='text' name='options[0]' value='" . $mydirname . "' /><br />";
29                $form .= _MB_XPRESS_COUNT .": <input type='text' name='options[1]' value='" . $disp_count . "' /><br />";
30                $form .= _MB_XPRESS_LENGTH .": <input type='text' name='options[2]' value='" . $disp_length . "' />";
31            $form .= "<br /><br />" . _MB_XPRESS_COM_TYPE ;
32            $isAll = (count($selected)==0||empty($selected[0]))?true:false;
33            $form .= "<br />&nbsp;&nbsp;<select name=\"options[]\" multiple=\"multiple\">";
34                    $form .= "<option value=\"0\" ";
35                    if ($isAll) $form .= " selected=\"selected\"";
36                    $form .= ">"._MB_XPRESS_ALL ."</option>";
37
38                    $form .= "<option value=\"1\" ";
39                    if (in_array(1, $selected))
40                                $form .= " selected=\"selected\"";
41                    $form .= ">"._MB_XPRESS_COMMENT ."</option>";
42
43                    $form .= "<option value=\"2\" ";
44                    if (in_array(2, $selected))
45                                $form .= " selected=\"selected\"";
46                    $form .= ">"._MB_XPRESS_TRUCKBACK ."</option>";
47
48                    $form .= "<option value=\"3\" ";
49                    if (in_array(3, $selected))
50                                $form .= " selected=\"selected\"";
51                    $form .= ">"._MB_XPRESS_PINGBACK ."</option>";
52                $form .= "</select><br />";
53                //          $form .="<br /><input type='text' size='60' name='options[5]' id='this_template' value='".htmlspecialchars($this_template,ENT_QUOTES)."' />";
54
55
56                return $form;
57        }
58       
59        function _b_comments_show($options)
60        {
61                $mydirname = empty( $options[0] ) ? 'xpress' : $options[0] ;
62                $disp_count = empty( $options[1] ) ? '10' : $options[1] ;
63                $disp_length = empty( $options[2] ) ? '30' : $options[2] ;
64                $selected = array_slice($options,5); // get allowed cats
65                $this_template = empty( $options[6] ) ? 'db:'.$mydirname.'_block_comments.html' : trim( $options[4] );
66                $mydirpath = XOOPS_ROOT_PATH . '/modules/' . $mydirname;
67               
68
69                $myts =& MyTextSanitizer::getInstance();
70
71                $this_url = '/modules/'. $mydirname;
72                $call_url = $_SERVER['REQUEST_URI'];
73               
74                $disp_all = in_array('0',$selected);
75                $disp_comment = in_array('1',$selected);
76                $disp_trackback = in_array('2',$selected);
77                $disp_pingback = in_array('3',$selected);
78               
79                $type_select = '';
80                if (!$disp_all){                       
81                        if ($disp_comment){
82                                $in_where =  "''";
83                        }
84                        if ($disp_trackback){
85                                if (empty($in_where)) $in_where =  "'trackback' "; else $in_where .=  ",'trackback'";
86                        }
87                                       
88                        if ($disp_pingback){
89                                if (empty($in_where)) $in_where =  "'pingback' "; else $in_where .=  ",'pingback'";
90                        }
91                       
92                        if (! empty($in_where)){
93                                $type_select = " AND comment_type IN($in_where) ";                             
94                        }
95                }
96               
97                global $wpdb;
98                $block = array(
99                'mydirname' => $mydirname ,
100                'mod_url' => XOOPS_URL.'/modules/'.$mydirname ,
101                ) ;
102                       
103                if (!is_null($wpdb)){
104
105                        $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments LEFT JOIN $wpdb->posts ON  $wpdb->posts.ID = $wpdb->comments.comment_post_ID WHERE comment_approved = '1' AND post_type = 'post'  AND post_status = 'publish' $type_select ORDER BY comment_date_gmt DESC LIMIT $disp_count");
106                        $format = get_settings('date_format') . ' ' . get_settings('time_format');                             
107
108                        if ( $comments ) {
109                                $output .= '<ul>';
110                                foreach ($comments as $comment){
111                                        $comment_content = $comment->comment_content;
112                                        $comment_excerpt = ($disp_length>0 ? xoops_substr($comment_content, 0, $disp_length): $comment->comment_content);
113
114                                        $comment_link = get_permalink($comment->comment_post_ID) . '#comment-' . $comment->comment_ID ;
115                                        $comment_title = $comment_excerpt;
116                                        $comment_title_link = "<a href='$comment_link' rel='external nofollow' class='url'>$comment_tytle</a>";
117
118                                        $post_link = get_comment_link($comment->comment_ID);
119                                        $post_title = get_the_title($comment->comment_post_ID);
120                                        $post_title_link = '<a href="'. $post_link . '">' . $post_title . '</a>';
121                                       
122                                        $author_link = $comment->comment_author_url;
123                                        $author_name = $comment->comment_author;
124                                        $author_name_link = (( empty( $author_link ) || 'http://' == $author_link ) ? $author_name : "<a href='$author_link' rel='external nofollow' class='url'>$author_name</a>");
125
126                                        $comment_type = (empty($comment->comment_type) ? 'comment': $comment->comment_type);
127                                        $from_auther_to_post = sprintf(__('%1$s on %2$s'), $author_name_link , $post_title_link );
128
129                                        $row_data = array(
130                                                'comment_ID'            => $comment->comment_ID ,
131                                                'comment_post_ID'       => $comment->comment_post_ID ,
132                                                'comment_date'          => $comment->comment_date ,
133                                                'comment_content'       => $comment_content ,
134                                                'comment_excerpt'       => $comment_excerpt ,   
135                                                'comment_link'          => $comment_link,
136                                                'comment_title'         => $ccomment_title ,
137                                                'comment_title_link' => $comment_title_link ,
138                                                'post_link'             => $post_link,
139                                                'post_title'            => $post_title,
140                                                'post_title_link'       => $post_title_link,
141                                                'author_link'           => $author_link,
142                                                'author_name'           => $author_name,
143                                                'author_name_link'      => $author_name_link,           
144                                                'comment_type'          => $comment_type,                                                                                                                                                                                                                                                                               
145                                                'from_auther_to_post' => $from_auther_to_post
146                                        );
147                                       
148                                        $block['contents'][] = $row_data;
149                                }
150                        }
151                } else {
152//                      $block['contents'] = "out of  module";
153                }
154                        return $block ;
155
156        }
157}
158?>
Note: See TracBrowser for help on using the repository browser.