diff --git a/contrib/favorites/main.php b/contrib/favorites/main.php
index f987a71c..6a10725a 100644
--- a/contrib/favorites/main.php
+++ b/contrib/favorites/main.php
@@ -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("Images favorited: $i_favorites_count, $h_favorites_rate per day");
+ }
+
public function onImageInfoSet($event) {
global $user;
if(($_POST['favorite_action'] == "set") || ($_POST['favorite_action'] == "unset")) {
diff --git a/contrib/favorites/test.php b/contrib/favorites/test.php
index 7ec31f7a..468a18ca 100644
--- a/contrib/favorites/test.php
+++ b/contrib/favorites/test.php
@@ -15,6 +15,11 @@ class FavoritesTest extends ShimmieWebTestCase {
$this->assertTitle("Image $image_id: test");
$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->assertNoText("Favorited By");
diff --git a/ext/comment/main.php b/ext/comment/main.php
index bb3f55eb..862ee8c2 100644
--- a/ext/comment/main.php
+++ b/ext/comment/main.php
@@ -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) {
$this->theme->display_image_comments(
$event->image,
diff --git a/ext/image/main.php b/ext/image/main.php
index ac1b5d76..0be314e4 100644
--- a/ext/image/main.php
+++ b/ext/image/main.php
@@ -124,6 +124,15 @@ class ImageIO extends SimpleExtension {
$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("Images uploaded: $i_image_count, $h_image_rate per day");
+ }
+
public function onSetupBuilding($event) {
$sb = new SetupBlock("Image Options");
$sb->position = 30;
diff --git a/ext/image/test.php b/ext/image/test.php
new file mode 100644
index 00000000..840d7818
--- /dev/null
+++ b/ext/image/test.php
@@ -0,0 +1,18 @@
+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();
+ }
+}
+?>
diff --git a/ext/user/main.php b/ext/user/main.php
index 61bac92e..d17d19a9 100644
--- a/ext/user/main.php
+++ b/ext/user/main.php
@@ -11,10 +11,16 @@ class UserBlockBuildingEvent extends Event {
class UserPageBuildingEvent extends Event {
var $display_user;
+ var $stats = array();
public function __construct(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 {
@@ -142,15 +148,32 @@ class UserPage extends SimpleExtension {
public function onUserPageBuilding(Event $event) {
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 = "
";
+ $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) {
$ubbe = new UserBlockBuildingEvent();
send_event($ubbe);
ksort($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'))) {
- $this->theme->display_ip_list($page, $this->count_upload_ips($event->display_user), $this->count_comment_ips($event->display_user));
+ if(
+ ($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));
}
}
diff --git a/ext/user/test.php b/ext/user/test.php
index 6d89bb1e..be8ed813 100644
--- a/ext/user/test.php
+++ b/ext/user/test.php
@@ -8,6 +8,7 @@ class UserPageTest extends SCoreWebTestCase {
$this->get_page('user/demo');
$this->assertTitle("demo's Page");
+ $this->assertText("Join date:");
$this->get_page('user/MauMau');
$this->assertTitle("No Such User");
diff --git a/ext/user/theme.php b/ext/user/theme.php
index 70a07cfd..f51147a9 100644
--- a/ext/user/theme.php
+++ b/ext/user/theme.php
@@ -125,11 +125,14 @@ class UserPageTheme extends Themelet {
$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_heading("{$duser->name}'s Page");
$page->add_block(new NavBlock());
- $page->add_block(new Block("Stats", $this->build_stats($duser), "main", 0));
+ $page->add_block(new Block("Stats", join("
", $stats), "main", 0));
if(!$user->is_anonymous()) {
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 = "
";
- }
- return "
- $avatar
- Join date: $h_join_date
-
Images uploaded: $i_image_count, $h_image_rate per day
-
Comments made: $i_comment_count, $h_comment_rate per day
- ";
- }
-
protected function build_options(User $duser) {
global $config, $database, $user;