123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
- /**
- * All plugin hook handlers are bundled here
- */
- /**
- * Change the url of the friend user hover menu item when already requested to be friend
- *
- * @param string $hook the name of the hook
- * @param string $type the type of the hook
- * @param ElggMenuItem[] $returnvalue current return value
- * @param array $params supplied params
- *
- * @return ElggMenuItem[]
- */
- function friend_request_user_menu_handler($hook, $type, $returnvalue, $params) {
- if (empty($params) || !is_array($params)) {
- return $returnvalue;
- }
- $user = elgg_get_logged_in_user_entity();
- if (empty($user)) {
- return $returnvalue;
- }
-
- $entity = elgg_extract("entity", $params);
- if (empty($entity) || !elgg_instanceof($entity, "user")) {
- return $returnvalue;
- }
-
- if ($entity->getGUID() == $user->getGUID()) {
- return $returnvalue;
- }
-
- $requested = check_entity_relationship($user->getGUID(), "friendrequest", $entity->getGUID());
- $is_friend = $entity->isFriend($user->getGUID());
-
- foreach ($returnvalue as $index => $item) {
- // change the text of the button to tell you already requested a friendship
- switch ($item->getName()) {
- case "add_friend":
- if ($requested) {
- $item->setItemClass("hidden");
- }
-
- break;
- case "remove_friend":
- if (!$requested && !$is_friend) {
- unset($returnvalue[$index]);
- }
- break;
- }
- }
-
- if ($requested) {
- $returnvalue[] = ElggMenuItem::factory(array(
- "name" => "friend_request",
- "text" => elgg_echo("friend_request:friend:add:pending"),
- "href" => "friend_request/" . $user->username . "#friend_request_sent_listing",
- "section" => "action"
- ));
- }
-
- return $returnvalue;
- }
- /**
- * Add menu items to the entity menu of a user
- *
- * @param string $hook the name of the hook
- * @param string $type the type of the hook
- * @param ElggMenuItem[] $returnvalue current return value
- * @param array $params supplied params
- *
- * @return ElggMenuItem[]
- */
- function friend_request_entity_menu_handler($hook, $type, $returnvalue, $params) {
- if (empty($params) || !is_array($params)) {
- return $returnvalue;
- }
-
- $user = elgg_get_logged_in_user_entity();
- if (empty($user)) {
- return $returnvalue;
- }
-
- $entity = elgg_extract("entity", $params);
- if (empty($entity) || !elgg_instanceof($entity, "user")) {
- return $returnvalue;
- }
-
- if ($entity->getGUID() == $user->getGUID()) {
- return $returnvalue;
- }
-
- // are we friends
- if (!$entity->isFriendOf($user->getGUID())) {
- // no, check if pending request
- if (check_entity_relationship($user->getGUID(), "friendrequest", $entity->getGUID())) {
- // pending request
- $returnvalue[] = ElggMenuItem::factory(array(
- "name" => "friend_request",
- "text" => elgg_echo("friend_request:friend:add:pending"),
- "href" => "friend_request/" . $user->username . "#friend_request_sent_listing",
- "priority" => 500
- ));
- } else {
- // add as friend
- $returnvalue[] = ElggMenuItem::factory(array(
- "name" => "add_friend",
- "text" => elgg_echo("friend:add"),
- "href" => "action/friends/add?friend=" . $entity->getGUID(),
- "is_action" => true,
- "priority" => 500
- ));
- }
- } else {
- // is friend, se remove friend link
- $returnvalue[] = ElggMenuItem::factory(array(
- "name" => "remove_friend",
- "text" => elgg_echo("friend:remove"),
- "href" => "action/friends/remove?friend=" . $entity->getGUID(),
- "is_action" => true,
- "priority" => 500
- ));
- }
-
- return $returnvalue;
- }
|