File: _class_commentlist.php

package info (click to toggle)
b2evolution 0.9.2-3
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 12,976 kB
  • ctags: 5,460
  • sloc: php: 58,989; sh: 298; makefile: 36
file content (152 lines) | stat: -rw-r--r-- 4,184 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
 * This file implements comment lists
 *
 * b2evolution - {@link http://b2evolution.net/}
 * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
 * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
 *
 * @package evocore
 */
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );

/**
 * Includes:
 */
require_once dirname(__FILE__).'/_class_dataobjectlist.php';

/**
 * Comment List Class
 *
 * @package evocore
 */
class CommentList extends DataObjectList
{
	var $blog;
	
	/** 
	 * {@internal CommentList::CommentList(-)}}
	 *
	 * Constructor
	 */
	function CommentList( 
		$blog = 1, 
		$comment_types = "'comment'",
		$show_statuses = array(),							// Not used yet					
		$p = '',															// Restrict to specific post
		$author = '',													// Not used yet
		$order = 'DESC',											// ASC or DESC
		$orderby = '',												// list of fields to order by
		$posts = '', 													// # of comments to display on the page
		$paged = '',													// Not used yet
		$poststart = '',											// Not used yet
		$postend = '',												// Not used yet
		$s = '',															// Not used yet
		$sentence = '',												// Not used yet
		$exact = '',													// Not used yet
		$default_posts_per_page = '', 
		$init_what_to_show = ''  )
	{
		global $DB;
		global $tablecomments, $tableposts, $tablecategories, $tableblogs, $tablepostcats;
		global $cache_categories;
		global $cat_array; // communication with recursive callback funcs
		global $pagenow;		// Bleh !
		
		// Call parent constructor:
		parent::DataObjectList( $tablecomments, 'comment_', 'comment_ID' );

		$this->blog = $blog;
		
		if( !empty($posts) )
			$this->posts_per_page = $posts;
		else $this->posts_per_page = $default_posts_per_page;

		$this->request = "SELECT DISTINCT $tablecomments.*
											FROM (($tablecomments INNER JOIN $tableposts ON comment_post_ID = ID) ";
				
		if( !empty( $p ) )
		{	// Restrict to comments on selected post
			$this->request .= ") WHERE comment_post_ID = $p AND ";
		}
		elseif( $blog > 1 )
		{	// Restrict to viewable posts/cats on current blog
			$this->request .= "INNER JOIN $tablepostcats ON ID = postcat_post_ID) INNER JOIN $tablecategories othercats ON postcat_cat_ID = othercats.cat_ID WHERE othercats.cat_blog_ID = $blog AND ";
		}
		else
		{	// This is blog 1, we don't care, we can include all comments:
			$this->request .= ') WHERE ';
		}
		
		$this->request .= "comment_type IN ($comment_types) ";

		/*
		 * ----------------------------------------------------
		 *  Restrict to the statuses we want to show:
		 * ----------------------------------------------------
		 */
		$this->request .= ' AND '.statuses_where_clause( $show_statuses );

		
		// order by stuff
		if( (!empty($order)) && ((strtoupper($order) != 'ASC') && (strtoupper($order) != 'DESC'))) 
		{
			$order='DESC';
		}
	
		if(empty($orderby))
		{
			$orderby='comment_date '.$order;
		}
		else
		{
			$orderby_array = explode(' ',$orderby);
			$orderby = $orderby_array[0].' '.$order;
			if (count($orderby_array)>1) 
			{
				for($i = 1; $i < (count($orderby_array)); $i++) 
				{
					$orderby .= ', comment_'.$orderby_array[$i].' '.$order;
				}
			}
		}


		$this->request .= "ORDER BY $orderby";
		if( $this->posts_per_page ) $this->request .= " LIMIT $this->posts_per_page";

		// echo $this->request;
			
		$this->result = $DB->get_results( $this->request, ARRAY_A );
	
		if( $this->result_num_rows = $DB->num_rows )
		{
			foreach( $this->result as $row )
			{
				$this->Obj[] = & new Comment( $row );
			}
		}
	}

	
	/**
	 * Template function: display message if list is empty
	 *
	 * {@internal Comment::display_if_empty(-) }}
	 *
	 * @param string String to display if list is empty
   * @return true if empty
	 */
	function display_if_empty( $message = '' )
	{
		if( empty($message) )
		{	// Default message:
			$message = T_('No comment yet...');
		}

		return parent::display_if_empty( $message );
	}

}

?>