extendable user stats rather than hardcoded with assumptions of extensions
This commit is contained in:
		
							parent
							
								
									1c81ee280a
								
							
						
					
					
						commit
						64d8b52b7b
					
				@ -57,6 +57,14 @@ class Favorites extends SimpleExtension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function onUserPageBuilding($event) {
 | 
				
			||||||
 | 
							$i_favorites_count = Image::count_images(array("favorited_by={$event->display_user->name}"));
 | 
				
			||||||
 | 
							$i_days_old = ((time() - strtotime($event->display_user->join_date)) / 86400) + 1;
 | 
				
			||||||
 | 
							$h_favorites_rate = sprintf("%.1f", ($i_favorites_count / $i_days_old));
 | 
				
			||||||
 | 
							$favorites_link = make_link("post/list/favorited_by={$event->display_user->name}/1");
 | 
				
			||||||
 | 
							$event->add_stats("<a href='$favorites_link'>Images favorited</a>: $i_favorites_count, $h_favorites_rate per day");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function onImageInfoSet($event) {
 | 
						public function onImageInfoSet($event) {
 | 
				
			||||||
		global $user;
 | 
							global $user;
 | 
				
			||||||
		if(($_POST['favorite_action'] == "set") || ($_POST['favorite_action'] == "unset")) {
 | 
							if(($_POST['favorite_action'] == "set") || ($_POST['favorite_action'] == "unset")) {
 | 
				
			||||||
 | 
				
			|||||||
@ -15,6 +15,11 @@ class FavoritesTest extends ShimmieWebTestCase {
 | 
				
			|||||||
		$this->assertTitle("Image $image_id: test");
 | 
							$this->assertTitle("Image $image_id: test");
 | 
				
			||||||
		$this->assertText("Favorited By");
 | 
							$this->assertText("Favorited By");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$this->get_page("user/test");
 | 
				
			||||||
 | 
							$this->assertText("Images favorited: 1");
 | 
				
			||||||
 | 
							$this->click("Images favorited");
 | 
				
			||||||
 | 
							$this->assertTitle("Image $image_id: test");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$this->click("Un-Favorite");
 | 
							$this->click("Un-Favorite");
 | 
				
			||||||
		$this->assertNoText("Favorited By");
 | 
							$this->assertNoText("Favorited By");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -144,6 +144,13 @@ class CommentList extends SimpleExtension {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function onUserPageBuilding(Event $event) {
 | 
				
			||||||
 | 
							$i_days_old = ((time() - strtotime($event->display_user->join_date)) / 86400) + 1;
 | 
				
			||||||
 | 
							$i_comment_count = Comment::count_comments_by_user($event->display_user);
 | 
				
			||||||
 | 
							$h_comment_rate = sprintf("%.1f", ($i_comment_count / $i_days_old));
 | 
				
			||||||
 | 
							$event->add_stats("Comments made: $i_comment_count, $h_comment_rate per day");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function onDisplayingImage($event) {
 | 
						public function onDisplayingImage($event) {
 | 
				
			||||||
		$this->theme->display_image_comments(
 | 
							$this->theme->display_image_comments(
 | 
				
			||||||
			$event->image,
 | 
								$event->image,
 | 
				
			||||||
 | 
				
			|||||||
@ -124,6 +124,15 @@ class ImageIO extends SimpleExtension {
 | 
				
			|||||||
		$event->image->delete();
 | 
							$event->image->delete();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function onUserPageBuilding($event) {
 | 
				
			||||||
 | 
							$u_id = url_escape($event->display_user->id);
 | 
				
			||||||
 | 
							$i_image_count = Image::count_images(array("user_id={$event->display_user->id}"));
 | 
				
			||||||
 | 
							$i_days_old = ((time() - strtotime($event->display_user->join_date)) / 86400) + 1;
 | 
				
			||||||
 | 
							$h_image_rate = sprintf("%.1f", ($i_image_count / $i_days_old));
 | 
				
			||||||
 | 
							$images_link = make_link("post/list/user_id=$u_id/1");
 | 
				
			||||||
 | 
							$event->add_stats("<a href='$images_link'>Images uploaded</a>: $i_image_count, $h_image_rate per day");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function onSetupBuilding($event) {
 | 
						public function onSetupBuilding($event) {
 | 
				
			||||||
		$sb = new SetupBlock("Image Options");
 | 
							$sb = new SetupBlock("Image Options");
 | 
				
			||||||
		$sb->position = 30;
 | 
							$sb->position = 30;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										18
									
								
								ext/image/test.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								ext/image/test.php
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					class ImageTest extends ShimmieWebTestCase {
 | 
				
			||||||
 | 
						public function testUserStats() {
 | 
				
			||||||
 | 
							$this->log_in_as_user();
 | 
				
			||||||
 | 
							$image_id = $this->post_image("ext/simpletest/data/pbx_screenshot.jpg", "test");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$this->get_page("user/test");
 | 
				
			||||||
 | 
							$this->assertText("Images uploaded: 1");
 | 
				
			||||||
 | 
							$this->click("Images uploaded");
 | 
				
			||||||
 | 
							$this->assertTitle("Image $image_id: test");
 | 
				
			||||||
 | 
							$this->log_out();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							$this->log_in_as_admin();
 | 
				
			||||||
 | 
							$this->delete_image($image_id);
 | 
				
			||||||
 | 
							$this->log_out();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					?>
 | 
				
			||||||
@ -11,10 +11,16 @@ class UserBlockBuildingEvent extends Event {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class UserPageBuildingEvent extends Event {
 | 
					class UserPageBuildingEvent extends Event {
 | 
				
			||||||
	var $display_user;
 | 
						var $display_user;
 | 
				
			||||||
 | 
						var $stats = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function __construct(User $display_user) {
 | 
						public function __construct(User $display_user) {
 | 
				
			||||||
		$this->display_user = $display_user;
 | 
							$this->display_user = $display_user;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						public function add_stats($html, $position=50) {
 | 
				
			||||||
 | 
							while(isset($this->stats[$position])) $position++;
 | 
				
			||||||
 | 
							$this->stats[$position] = $html;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class UserCreationEvent extends Event {
 | 
					class UserCreationEvent extends Event {
 | 
				
			||||||
@ -142,15 +148,32 @@ class UserPage extends SimpleExtension {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	public function onUserPageBuilding(Event $event) {
 | 
						public function onUserPageBuilding(Event $event) {
 | 
				
			||||||
		global $page, $user, $config;
 | 
							global $page, $user, $config;
 | 
				
			||||||
		$this->theme->display_user_page($page, $event->display_user, $user);
 | 
					
 | 
				
			||||||
 | 
							$h_join_date = html_escape($event->display_user->join_date);
 | 
				
			||||||
 | 
							$event->add_stats("Join date: $h_join_date", 10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if(!empty($comment->owner->email)) {
 | 
				
			||||||
 | 
								$hash = md5(strtolower($comment->owner->email));
 | 
				
			||||||
 | 
								$avatar = "<img src=\"http://www.gravatar.com/avatar/$hash.jpg\" style='float: left;'>";
 | 
				
			||||||
 | 
								$event->add_stats($avatar, 0);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ksort($event->stats);
 | 
				
			||||||
 | 
							$this->theme->display_user_page($event->display_user, $event->stats);
 | 
				
			||||||
		if($user->id == $event->display_user->id) {
 | 
							if($user->id == $event->display_user->id) {
 | 
				
			||||||
			$ubbe = new UserBlockBuildingEvent();
 | 
								$ubbe = new UserBlockBuildingEvent();
 | 
				
			||||||
			send_event($ubbe);
 | 
								send_event($ubbe);
 | 
				
			||||||
			ksort($ubbe->parts);
 | 
								ksort($ubbe->parts);
 | 
				
			||||||
			$this->theme->display_user_links($page, $user, $ubbe->parts);
 | 
								$this->theme->display_user_links($page, $user, $ubbe->parts);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if(($user->is_admin() || $user->id == $event->display_user->id) && ($user->id != $config->get_int('anon_id'))) {
 | 
							if(
 | 
				
			||||||
			$this->theme->display_ip_list($page, $this->count_upload_ips($event->display_user), $this->count_comment_ips($event->display_user));
 | 
								($user->is_admin() || $user->id == $event->display_user->id) &&
 | 
				
			||||||
 | 
								($user->id != $config->get_int('anon_id'))
 | 
				
			||||||
 | 
							) {
 | 
				
			||||||
 | 
								$this->theme->display_ip_list(
 | 
				
			||||||
 | 
									$page,
 | 
				
			||||||
 | 
									$this->count_upload_ips($event->display_user),
 | 
				
			||||||
 | 
									$this->count_comment_ips($event->display_user));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -8,6 +8,7 @@ class UserPageTest extends SCoreWebTestCase {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		$this->get_page('user/demo');
 | 
							$this->get_page('user/demo');
 | 
				
			||||||
		$this->assertTitle("demo's Page");
 | 
							$this->assertTitle("demo's Page");
 | 
				
			||||||
 | 
							$this->assertText("Join date:");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$this->get_page('user/MauMau');
 | 
							$this->get_page('user/MauMau');
 | 
				
			||||||
		$this->assertTitle("No Such User");
 | 
							$this->assertTitle("No Such User");
 | 
				
			||||||
 | 
				
			|||||||
@ -125,11 +125,14 @@ class UserPageTheme extends Themelet {
 | 
				
			|||||||
		$page->add_block(new Block("IPs", $html));
 | 
							$page->add_block(new Block("IPs", $html));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function display_user_page(Page $page, User $duser, User $user) {
 | 
						public function display_user_page(User $duser, $stats) {
 | 
				
			||||||
 | 
							global $page, $user;
 | 
				
			||||||
 | 
							assert(is_array($stats));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$page->set_title("{$duser->name}'s Page");
 | 
							$page->set_title("{$duser->name}'s Page");
 | 
				
			||||||
		$page->set_heading("{$duser->name}'s Page");
 | 
							$page->set_heading("{$duser->name}'s Page");
 | 
				
			||||||
		$page->add_block(new NavBlock());
 | 
							$page->add_block(new NavBlock());
 | 
				
			||||||
		$page->add_block(new Block("Stats", $this->build_stats($duser), "main", 0));
 | 
							$page->add_block(new Block("Stats", join("<br>", $stats), "main", 0));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if(!$user->is_anonymous()) {
 | 
							if(!$user->is_anonymous()) {
 | 
				
			||||||
			if($user->id == $duser->id || $user->is_admin()) {
 | 
								if($user->id == $duser->id || $user->is_admin()) {
 | 
				
			||||||
@ -138,34 +141,6 @@ class UserPageTheme extends Themelet {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protected function build_stats(User $duser) {
 | 
					 | 
				
			||||||
		global $database;
 | 
					 | 
				
			||||||
		global $config;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$h_join_date = html_escape($duser->join_date);
 | 
					 | 
				
			||||||
		$i_image_count = Image::count_images(array("user_id={$duser->id}"));
 | 
					 | 
				
			||||||
		$i_comment_count = Comment::count_comments_by_user($duser);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$i_days_old = ((time() - strtotime($duser->join_date)) / 86400) + 1;
 | 
					 | 
				
			||||||
		$h_image_rate = sprintf("%.1f", ($i_image_count / $i_days_old));
 | 
					 | 
				
			||||||
		$h_comment_rate = sprintf("%.1f", ($i_comment_count / $i_days_old));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$u_id = url_escape($duser->id);
 | 
					 | 
				
			||||||
		$images_link = make_link("post/list/user_id=$u_id/1");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		$avatar = "";
 | 
					 | 
				
			||||||
		if(!empty($comment->owner->email)) {
 | 
					 | 
				
			||||||
			$hash = md5(strtolower($comment->owner->email));
 | 
					 | 
				
			||||||
			$avatar = "<img src=\"http://www.gravatar.com/avatar/$hash.jpg\" style='float: left;'>";
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return "
 | 
					 | 
				
			||||||
			$avatar
 | 
					 | 
				
			||||||
			Join date: $h_join_date
 | 
					 | 
				
			||||||
			<br><a href='$images_link'>Images uploaded</a>: $i_image_count, $h_image_rate per day
 | 
					 | 
				
			||||||
			<br>Comments made: $i_comment_count, $h_comment_rate per day
 | 
					 | 
				
			||||||
			";
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	protected function build_options(User $duser) {
 | 
						protected function build_options(User $duser) {
 | 
				
			||||||
		global $config, $database, $user;
 | 
							global $config, $database, $user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user