147 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			147 lines
		
	
	
		
			4.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| class CommentListTheme extends Themelet {
 | |
| 	/**
 | |
| 	 * Do the basics of the comments page
 | |
| 	 *
 | |
| 	 * $page_number = the current page number
 | |
| 	 * $total_pages = the total number of comment pages
 | |
| 	 */
 | |
| 	public function display_comment_list($images, $page_number, $total_pages, $can_post) {
 | |
| 		global $page;
 | |
| 
 | |
| 		// parts for the whole page
 | |
| 		$prev = $page_number - 1;
 | |
| 		$next = $page_number + 1;
 | |
| 
 | |
| 		$h_prev = ($page_number <= 1) ? "Prev" :
 | |
| 			"<a href='".make_link("comment/list/$prev")."'>Prev</a>";
 | |
| 		$h_index = "<a href='".make_link()."'>Index</a>";
 | |
| 		$h_next = ($page_number >= $total_pages) ? "Next" :
 | |
| 			"<a href='".make_link("comment/list/$next")."'>Next</a>";
 | |
| 
 | |
| 		$nav = "$h_prev | $h_index | $h_next";
 | |
| 
 | |
| 		$page->set_title("Comments");
 | |
| 		$page->set_heading("Comments");
 | |
| 		$page->add_block(new Block("Navigation", $nav, "left"));
 | |
| 		$this->display_paginator($page, "comment/list", null, $page_number, $total_pages);
 | |
| 
 | |
| 		// parts for each image
 | |
| 		$position = 10;
 | |
| 		foreach($images as $pair) {
 | |
| 			$image = $pair[0];
 | |
| 			$comments = $pair[1];
 | |
| 
 | |
| 			$thumb_html = $this->build_thumb_html($image);
 | |
| 
 | |
| 			$comment_html = "";
 | |
| 			foreach($comments as $comment) {
 | |
| 				$comment_html .= $this->comment_to_html($comment);
 | |
| 			}
 | |
| 			if($can_post) {
 | |
| 				$comment_html .= $this->build_postbox($image->id);
 | |
| 			}
 | |
| 
 | |
| 			$html  = "
 | |
| 				<table class='comment_list_table'><tr>
 | |
| 					<td>$thumb_html</td>
 | |
| 					<td>$comment_html</td>
 | |
| 				</tr></table>
 | |
| 			";
 | |
| 
 | |
| 			$page->add_block(new Block("{$image->id}: ".($image->get_tag_list()), $html, "main", $position++));
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 
 | |
| 	/**
 | |
| 	 * Add some comments to the page, probably in a sidebar
 | |
| 	 *
 | |
| 	 * $comments = an array of Comment objects to be shown
 | |
| 	 */
 | |
| 	public function display_recent_comments($comments) {
 | |
| 		global $page;
 | |
| 		$html = "";
 | |
| 		foreach($comments as $comment) {
 | |
| 			$html .= $this->comment_to_html($comment, true);
 | |
| 		}
 | |
| 		$html .= "<p><a class='more' href='".make_link("comment/list")."'>Full List</a>";
 | |
| 		$page->add_block(new Block("Comments", $html, "left"));
 | |
| 	}
 | |
| 
 | |
| 
 | |
| 	/**
 | |
| 	 * Show comments for an image
 | |
| 	 */
 | |
| 	public function display_image_comments(Image $image, $comments, $postbox) {
 | |
| 		global $page;
 | |
| 		$html = "";
 | |
| 		foreach($comments as $comment) {
 | |
| 			$html .= $this->comment_to_html($comment);
 | |
| 		}
 | |
| 		if($postbox) {
 | |
| 			$html .= $this->build_postbox($image->id);
 | |
| 		}
 | |
| 		$page->add_block(new Block("Comments", $html, "main", 30));
 | |
| 	}
 | |
| 
 | |
| 
 | |
| 	protected function comment_to_html($comment, $trim=false) {
 | |
| 		global $user;
 | |
| 
 | |
| 		$tfe = new TextFormattingEvent($comment->comment);
 | |
| 		send_event($tfe);
 | |
| 
 | |
| 		$i_uid = int_escape($comment->owner_id);
 | |
| 		$h_name = html_escape($comment->owner_name);
 | |
| 		$h_poster_ip = html_escape($comment->poster_ip);
 | |
| 		$h_comment = ($trim ? substr($tfe->stripped, 0, 50)."..." : $tfe->formatted);
 | |
| 		$i_comment_id = int_escape($comment->comment_id);
 | |
| 		$i_image_id = int_escape($comment->image_id);
 | |
| 
 | |
| 		$h_userlink = "<a href='".make_link("user/$h_name")."'>$h_name</a>";
 | |
| 		$stripped_nonl = str_replace("\n", "\\n", substr($tfe->stripped, 0, 50));
 | |
| 		$stripped_nonl = str_replace("\r", "\\r", $stripped_nonl);
 | |
| 		$h_dellink = $user->is_admin() ?
 | |
| 			"<br>($h_poster_ip, <a ".
 | |
| 			"onclick=\"return confirm('Delete comment by $h_name:\\n$stripped_nonl');\" ".
 | |
| 			"href='".make_link("comment/delete/$i_comment_id/$i_image_id")."'>Del</a>)" : "";
 | |
| 
 | |
| 		if($trim) {
 | |
| 			return "
 | |
| 				$h_userlink: $h_comment
 | |
| 				<a href='".make_link("post/view/$i_image_id")."'>>>></a>
 | |
| 				$h_dellink
 | |
| 			";
 | |
| 		}
 | |
| 		else {
 | |
| 			//$avatar = "";
 | |
| 			//if(!empty($comment->owner->email)) {
 | |
| 			//	$hash = md5(strtolower($comment->owner->email));
 | |
| 			//	$avatar = "<img src=\"http://www.gravatar.com/avatar/$hash.jpg\"><br>";
 | |
| 			//}
 | |
| 			return "
 | |
| 				<div class='comment'>
 | |
| 				$h_userlink: $h_comment
 | |
| 				$h_dellink
 | |
| 				</div>
 | |
| 			";
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	protected function build_postbox($image_id) {
 | |
| 		$i_image_id = int_escape($image_id);
 | |
| 		$hash = CommentList::get_hash();
 | |
| 		return "
 | |
| 			<form action='".make_link("comment/add")."' method='POST'>
 | |
| 				<input type='hidden' name='image_id' value='$i_image_id' />
 | |
| 				<input type='hidden' name='hash' value='$hash' />
 | |
| 				<textarea name='comment' rows='5' cols='50'></textarea>
 | |
| 				<br><input type='submit' value='Post Comment' />
 | |
| 			</form>
 | |
| 		";
 | |
| 	}
 | |
| }
 | |
| ?>
 |