~quam-plures-core/quam-plures/qp5_colls-blogs_chaps-cats

« back to all changes in this revision

Viewing changes to qp_inc/widgets/_comment_list.widget.php

http://forums.quamplures.net/viewtopic.php?p=9237#p9237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * This file implements the "Comment list" widget
 
4
 *
 
5
 * @author {@link http://wonderwinds.com/ Ed Bennett}
 
6
 * @author {@link http://astonishme.co.uk/ Yabba (Paul Jones, rest in peace)}
 
7
 * @author {@link http://fplanque.net/ Francois PLANQUE}
 
8
 * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
 
9
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
 
10
 * @package widgets
 
11
 */
 
12
if(!defined('QP_MAIN_INIT')) die('fail');
 
13
 
 
14
/**
 
15
 * comment_list_Widget class
 
16
 * @package widgets
 
17
 */
 
18
class comment_list_Widget extends ComponentWidget
 
19
{
 
20
        /**
 
21
         * Constructor
 
22
         */
 
23
        function comment_list_Widget( $db_row = NULL )
 
24
        {
 
25
                // Call parent constructor
 
26
                parent::ComponentWidget( $db_row, 'widget', 'comment_list' );
 
27
                $this->widget_name = T_('Comment List');
 
28
                $this->widget_title = T_('Recent comments');
 
29
        }
 
30
 
 
31
 
 
32
        /**
 
33
         * Get widget's short description
 
34
         */
 
35
        function get_desc()
 
36
        {
 
37
                return T_('List of comments; click goes to comment.');
 
38
        }
 
39
 
 
40
 
 
41
        /**
 
42
         * Get widget's title
 
43
         * @todo (3069): rename this to get_title()
 
44
         */
 
45
        function get_short_desc()
 
46
        {
 
47
                return format_to_output( $this->disp_params['widget_title'] );
 
48
        }
 
49
 
 
50
 
 
51
        /**
 
52
         * Get definitions for editable params
 
53
         * @see Plugin::GetDefaultSettings()
 
54
         * @param local params like 'for_editing' => true
 
55
         */
 
56
        function get_param_definitions( $params )
 
57
        {
 
58
                $r = array_merge( array(
 
59
                        'disp_order' => array(
 
60
                                'label' => T_('Order'),
 
61
                                'type' => 'select',
 
62
                                'options' => array( 'DESC' => T_('Newest to oldest'), 'ASC' => T_('Oldest to newest'), 'RAND' => T_('Random selection') ),
 
63
                                'defaultvalue' => 'DESC',
 
64
                                'note' => T_('Order to display items'),
 
65
                        ),
 
66
                        'limit' => array(
 
67
                                'label' => T_('Max items'),
 
68
                                'defaultvalue' => 20,
 
69
                                'size' => 4,
 
70
                                'note' => T_('Maximum number of items to display.'),
 
71
                        ),
 
72
                        'author_links' => array(
 
73
                                'label' => T_('Link to author'),
 
74
                                'type' => 'checkbox',
 
75
                                'defaultvalue' => true,
 
76
                                'note' => T_('Link the author to their url'),
 
77
                        ),
 
78
                        'hover_text' => array(
 
79
                                'label' => T_('Hover text'),
 
80
                                'type' => 'text',
 
81
                                'defaultvalue' => T_('Read the full comment'),
 
82
                                'size' => 40,
 
83
                                'note' => T_('Text to show when hovering over the link'),
 
84
                        ),
 
85
                        'blog_ID' => array(
 
86
                                'label' => T_('Blog'),
 
87
                                'size' => 4,
 
88
                                'note' => T_('ID of the blog to use, leave empty for the current blog.'),
 
89
                        ),
 
90
                ), parent::get_param_definitions( $params ) );
 
91
                return $r;
 
92
        }
 
93
 
 
94
 
 
95
        /**
 
96
         * Display the widget!
 
97
         * @param array must contain at least the basic display params
 
98
         */
 
99
        function display( $params )
 
100
        {
 
101
                global $Blog;
 
102
 
 
103
                $this->init_display( $params );
 
104
 
 
105
                $blogCache = get_Cache( 'BlogCache' );
 
106
                $listBlog = ( $this->disp_params['blog_ID'] ? $blogCache->get_by_ID( $this->disp_params['blog_ID'] ) : $Blog );
 
107
 
 
108
                // Create ItemList
 
109
                // Note: we pass a widget specific prefix in order to make sure to never interfere with the mainlist
 
110
                $limit = $this->disp_params['limit'];
 
111
                $order = $this->disp_params['disp_order'];
 
112
                $CommentList = new CommentList( $listBlog, "'comment','trackback'", array( 'published' ), '', '', $order, '', $limit );
 
113
 
 
114
                echo $this->disp_params['block_start'];
 
115
                $this->disp_title();
 
116
                echo $this->disp_params['list_start'];
 
117
 
 
118
                // Loop through comments
 
119
                while( $Comment = & $CommentList->get_next() )
 
120
                {
 
121
                        // Load comment's Item object:
 
122
                        $Comment->get_Item();
 
123
                        echo $this->disp_params['item_start'];
 
124
                        // display comment author's name
 
125
                        $Comment->author( array(
 
126
                                'after_visitor' => ' ',
 
127
                                'after_user' => ' ',
 
128
                                'make_link' => $this->disp_params['author_links'],
 
129
                        ) );
 
130
                        echo T_('on').' ';
 
131
                        // display a permalink link to the comment
 
132
                        $Comment->permanent_link( array(
 
133
                                        'text' => $Comment->Item->title,
 
134
                                        'title' => $this->disp_params['hover_text'],
 
135
                                ) );
 
136
                        echo $this->disp_params['item_end'];
 
137
                } // End of comment loop
 
138
                echo $this->disp_params['list_end'];
 
139
                echo $this->disp_params['block_end'];
 
140
 
 
141
                return true;
 
142
        }
 
143
}
 
144
 
 
145
?>