aboutsummaryrefslogtreecommitdiff
path: root/start.php
diff options
context:
space:
mode:
Diffstat (limited to 'start.php')
-rw-r--r--start.php43
1 files changed, 33 insertions, 10 deletions
diff --git a/start.php b/start.php
index 3f01824ec..44e4cec68 100644
--- a/start.php
+++ b/start.php
@@ -13,16 +13,7 @@ function friendrequest_init() {
elgg_register_page_handler('friendrequests', 'friendrequest_page_handler');
if (elgg_is_logged_in()) {
-
- $count = elgg_get_entities_from_relationship(array(
- 'type' => 'user',
- 'relationship' => 'friendrequest',
- 'relationship_guid' => $page_owner->guid,
- 'inverse_relationship' => true,
- 'limit' => 0,
- 'count' => true,
- ));
-
+ $count = friendrequest_count();
$params = array(
'name' => 'friendrequests',
'text' => elgg_echo('friendrequest').($count? " ($count)": ""),
@@ -32,6 +23,8 @@ function friendrequest_init() {
elgg_register_menu_item('page', $params);
}
+ elgg_register_plugin_hook_handler('register', 'menu:topbar', 'friendrequest_topbar_menu');
+
//We need to override the friend remove action to remove the relationship we created
$actions_dir = elgg_get_plugins_path().'friendrequest/actions/friends';
elgg_register_action('friends/add', "$actions_dir/add.php");
@@ -88,6 +81,36 @@ function friendrequest_page_handler($page){
return true;
}
+function friendrequest_count(){
+ return elgg_get_entities_from_relationship(array(
+ 'type' => 'user',
+ 'relationship' => 'friendrequest',
+ 'relationship_guid' => elgg_get_logged_in_user_guid(),
+ 'inverse_relationship' => true,
+ 'limit' => 0,
+ 'count' => true,
+ ));
+}
+
+function friendrequest_topbar_menu($hook, $entity_type, $returnvalue, $params) {
+ $count = friendrequest_count();
+ if($count) {
+ foreach($returnvalue as $item) {
+ if($item->getName() == 'friends') {
+ $item->setText(
+ $item->getText() . elgg_view('output/url', array(
+ 'href' => 'friendrequests',
+ 'text' => "<span class=\"messages-new\">$count</span>",
+ 'title' => elgg_echo('friendrequest'),
+ ))
+ );
+ return $returnvalue;
+ }
+ }
+ }
+ return $returnvalue;
+}
+
function friendrequest_event_create_friend($event, $object_type, $object){
if (($object instanceof ElggRelationship) && ($event == 'create') && ($object_type == 'friend')) {
//We don't want anything happening here... (no email/etc)