diff options
Diffstat (limited to 'mod/friendrequest')
m--------- | mod/friendrequest | 6 | ||||
-rw-r--r-- | mod/friendrequest/actions/friendrequest/decline.php | 12 | ||||
-rw-r--r-- | mod/friendrequest/actions/friends/add.php | 53 | ||||
-rw-r--r-- | mod/friendrequest/actions/friends/remove.php | 36 | ||||
-rw-r--r-- | mod/friendrequest/languages/ca.php | 20 | ||||
-rw-r--r-- | mod/friendrequest/languages/en.php | 31 | ||||
-rw-r--r-- | mod/friendrequest/languages/es.php | 22 | ||||
-rw-r--r-- | mod/friendrequest/languages/gl.php | 31 | ||||
-rw-r--r-- | mod/friendrequest/languages/pt.php | 31 | ||||
-rw-r--r-- | mod/friendrequest/languages/sr.php | 31 | ||||
-rw-r--r-- | mod/friendrequest/manifest.xml | 16 | ||||
-rw-r--r-- | mod/friendrequest/start.php | 151 | ||||
-rw-r--r-- | mod/friendrequest/views/default/friendrequest/requests.php | 47 |
13 files changed, 481 insertions, 6 deletions
diff --git a/mod/friendrequest b/mod/friendrequest deleted file mode 160000 -Subproject bc99d5609275d0949cb1c4830cf6e7c1c5a5d75 diff --git a/mod/friendrequest/actions/friendrequest/decline.php b/mod/friendrequest/actions/friendrequest/decline.php new file mode 100644 index 000000000..ca3f1c9e4 --- /dev/null +++ b/mod/friendrequest/actions/friendrequest/decline.php @@ -0,0 +1,12 @@ +<?php
+
+$user = elgg_get_logged_in_user_entity();
+$friend = get_entity(sanitize_int(get_input("guid")));
+
+if(remove_entity_relationship($friend->guid, 'friendrequest', $user->guid)) {
+ system_message(elgg_echo("friendrequest:decline:success", array($friend->name)));
+} else {
+ system_message(elgg_echo("friendrequest:decline:fail"));
+}
+
+forward(REFERER);
diff --git a/mod/friendrequest/actions/friends/add.php b/mod/friendrequest/actions/friends/add.php new file mode 100644 index 000000000..e6efe1db1 --- /dev/null +++ b/mod/friendrequest/actions/friends/add.php @@ -0,0 +1,53 @@ +<?php +/** + * Elgg add friend action + * + * @package Elgg.Core + * @subpackage Friends.Management + * @override actions/friends/add.php + */ + + +// Get the GUID of the user to friend +$friend_guid = get_input('friend'); +$friend = get_entity($friend_guid); +if (!$friend) { + register_error(elgg_echo('error:missing_data')); + forward(REFERER); +} +$user = elgg_get_logged_in_user_entity(); + +$errors = false; + +if(check_entity_relationship($friend->guid, "friendrequest", $user->guid) + || check_entity_relationship($friend->guid, "friend", $user->guid)) { + + try { + if (!$user->addFriend($friend_guid)) { + $errors = true; + } + + $ia = elgg_set_ignore_access(true); + $friend->addFriend($user->guid); + elgg_set_ignore_access($ia); + + remove_entity_relationship($friend->guid, "friendrequest", $user->guid); + + } catch (Exception $e) { + register_error(elgg_echo("friends:add:failure", array($friend->name))); + $errors = true; + } + if (!$errors) { + // add to river + add_to_river('river/relationship/friend/create', 'friend', $user->guid, $friend->guid); + add_to_river('river/relationship/friend/create', 'friend', $friend->guid, $user->guid); + system_message(elgg_echo("friends:add:successful", array($friend->name))); + } +} elseif(add_entity_relationship($user->guid, "friendrequest", $friend->guid)) { + system_message(elgg_echo("friendrequest:add:successful", array($friend->name))); +} else { + register_error(elgg_echo("friendrequest:add:exists", array($friend->name))); +} + +// Forward back to the page you friended the user on +forward(REFERER); diff --git a/mod/friendrequest/actions/friends/remove.php b/mod/friendrequest/actions/friends/remove.php new file mode 100644 index 000000000..62bccb891 --- /dev/null +++ b/mod/friendrequest/actions/friends/remove.php @@ -0,0 +1,36 @@ +<?php +/** + * Elgg remove friend action + * + * @package Elgg.Core + * @subpackage Friends.Management + * @override actions/friends/remove.php + */ + +// Get the GUID of the user to friend +$friend_guid = get_input('friend'); +$friend = get_entity($friend_guid); +$errors = false; + +// Get the user +try{ + if ($friend instanceof ElggUser) { + elgg_get_logged_in_user_entity()->removeFriend($friend_guid); + $ia = elgg_set_ignore_access(true); + $friend->removeFriend(elgg_get_logged_in_user_guid()); + elgg_set_ignore_access($ia); + } else { + register_error(elgg_echo("friends:remove:failure", array($friend->name))); + $errors = true; + } +} catch (Exception $e) { + register_error(elgg_echo("friends:remove:failure", array($friend->name))); + $errors = true; +} + +if (!$errors) { + system_message(elgg_echo("friends:remove:successful", array($friend->name))); +} + +// Forward back to the page you made the friend on +forward(REFERER); diff --git a/mod/friendrequest/languages/ca.php b/mod/friendrequest/languages/ca.php new file mode 100644 index 000000000..ab17319c1 --- /dev/null +++ b/mod/friendrequest/languages/ca.php @@ -0,0 +1,20 @@ +<?php +$language = array ( + 'friendrequest' => 'Sol·licituds d\'Amistat', + 'friendrequest:add:successful' => 'Has enviat una sol·licitud d\'amistat a %s. La ha d\'acceptar. Dóna-li temps.', + 'friendrequest:add:failure' => 'Oops! Hi ha hagut algun problema mentre s\'intentava enviar la sol·licitud. Torna-ho a provar.', + 'friendrequest:add:exists' => 'Ja has enviat la sol·licitud d\'amistat a %s, no siguis tan insistent.', + 'friendrequest:decline:success' => 'Has denegat la sol·licitud d\'amistat de %s', + 'friendrequest:decline:fail' => 'Per algun motiu aquesta petició d\'amistat no pot ésser eliminada', + 'friendrequest:remove:check' => 'Estas segur de que vols denegar la sol·licitud d\'amistat?', + 'friendrequest:none' => 'No hi ha sol·licitud d\'amistat pendents.', + 'friendrequest:new:subject' => '%s vol ser la teva amiga', + 'friendrequest:new:body' => '% vol ser la teva amiga. Està esperant que aprovis la seva sol·licitud. No la facis esperar! + +Pots veure les teves sol·licituds d\'amistat pendents clicant a aquest link (recorda que has d\'estar loginat per veure-la): + +%s + +(No responguis aquest mail, perquè és una màquina qui l\'envia)', +); +add_translation("ca", $language);
\ No newline at end of file diff --git a/mod/friendrequest/languages/en.php b/mod/friendrequest/languages/en.php new file mode 100644 index 000000000..40bfbd36a --- /dev/null +++ b/mod/friendrequest/languages/en.php @@ -0,0 +1,31 @@ +<?php +/** + * ElggFriendRequest English language file. + * + */ + +$english = array( + 'friendrequest' => 'Friend Requests', + + 'friendrequest:add:successful' => 'You sent a friend request to %s. She has to accept it. Give she time.', + 'friendrequest:add:failure' => 'Oops! There was a problem while trying to send the request. Try it again.', + 'friendrequest:add:exists' => 'You already sent a friend request to %s, don\'t be so intense.', + + 'friendrequest:decline:success' => 'You just declined %s friend request', + 'friendrequest:decline:fail' => 'For any reason this friend request cannot be deleted', + + 'friendrequest:remove:check' => 'Are you sure you want to decline the friend request?', + 'friendrequest:none' => 'No pending friend requests.', + + 'friendrequest:new:subject' => '%s want to be your friend', + 'friendrequest:new:body' => '%s want to be your friend. She is waiting that you aprovate her petition. Do not her wait! + +You can see your pending friend requests following this link (remember you have to be logged in to see it): + + %s + +(Do not try to reply this mail, because is a machine who is sending it)', + +); + +add_translation('en', $english); diff --git a/mod/friendrequest/languages/es.php b/mod/friendrequest/languages/es.php new file mode 100644 index 000000000..1677ef4fb --- /dev/null +++ b/mod/friendrequest/languages/es.php @@ -0,0 +1,22 @@ +<?php +$es = array ( + 'friendrequest' => 'Peticiones de amistad', + 'friendrequest:add:successful' => 'Has enviado una petición de amistad a %s. Tiene que aprobarla antes de salir en tu lista de amigos. Dale tiempo :)', + 'friendrequest:add:failure' => 'Ups!, no se sabe muy bien por qué, pero el sistema no puede completar tu petición. Inténtalo de nuevo o ponte en contacto con lxs administradorxs.', + 'friendrequest:add:exists' => 'Ya has enviado antes una petición de amistad a %s. Ya lo leerá, ¡ten paciencia!', + 'friendrequest:decline:success' => 'Has rechazado la petición de amistad de %s', + 'friendrequest:decline:fail' => 'No ha sido posible borrar la petición de amistad. Inténtalo de nuevo o ponte en contacto con lxs administradorxs.', + 'friendrequest:remove:check' => 'Estás seguro de rechazar esta petición de amistad?', + 'friendrequest:none' => 'No hay peticiones de amistad pendientes.', + 'friendrequest:new:subject' => '%s quiere ser tu amigx', + 'friendrequest:new:body' => '%s quiere ser tu amigx. Está esperando a que apruebes su petición, no hagas que se impaciente ;) + +Puedes ver las peticiones que tienes pendientes a través del siguiente link (recuerda que tienes estar logeadx en la red para poder hacerlo): + + %s + +No puedes responder a este email porque soy una máquina y no te leeré, no lo intentes ;)', +); + +add_translation("es", $es); + diff --git a/mod/friendrequest/languages/gl.php b/mod/friendrequest/languages/gl.php new file mode 100644 index 000000000..9b8c12440 --- /dev/null +++ b/mod/friendrequest/languages/gl.php @@ -0,0 +1,31 @@ +<?php +/** + * ElggFriendRequest galician language file. + * + */ + +$galician = array( + 'friendrequest' => 'Peticións de amizade', + + 'friendrequest:add:successful' => 'Enviaches unha petición de amizade a %s. Ten que aprobala se quere, dálle tempo :)', + 'friendrequest:add:failure' => 'Mimá!, non se sabe moi ben por qué, pero o sistema non pode completa-la túa petición. Téntao de novo ou ponte en contacto cxs administran a rede.', + 'friendrequest:add:exists' => 'Xa lle tes enviado unha petición de amizade s %s. Xa o lerá, ten paciencia meu!', + + 'friendrequest:decline:success' => 'Borrache-la petición de amizade', + 'friendrequest:decline:fail' => 'Non foi posible borra-la petición de amizade. Téntao de novo ou ponte en contacto coxs que administran a rede.', + +// 'friendrequest:remove:check' => 'Are you sure you want to decline the friend request?', +// 'friendrequest:none' => 'No pending friend requests.', + + 'friendrequest:new:subject' => '%s quere ter amizade contigo', + 'friendrequest:new:body' => '%s quere ter amizade contigo. Está a agardar a que aprobe-la súa petición, non fagas que se impaciente ;) + +Si te logueaches na rede, podes ve-las peticións que tes pendentes a través da seguinte ligazón: + +%s + +Non podes responder a este email porque son unha máquina e non te vou ler, non o tentes ;)', + +); + +add_translation('gl', $galician); diff --git a/mod/friendrequest/languages/pt.php b/mod/friendrequest/languages/pt.php new file mode 100644 index 000000000..73010fd06 --- /dev/null +++ b/mod/friendrequest/languages/pt.php @@ -0,0 +1,31 @@ +<?php +/** + * ElggFriendRequest Portuguese language file. + * + */ + +$portuguese = array( + 'friendrequest' => 'Pedidos de amizade', + + 'friendrequest:add:successful' => 'Você enviou um pedido de amizade a &s. Elx tem que aprova-la antes de aparecer na tua lista de amigxs. Espere um pouco :)', + 'friendrequest:add:failure' => 'Erro. Não foi possível completar seu pedido. Tente novamente ou entre em contato com xs administradorxs.', + 'friendrequest:add:exists' => 'Você já enviou um pedido de amizade a &s. Elx Leerá em breve, seja paciente!', + + 'friendrequest:decline:success' => 'O pedido de amizade foi apagado corretamente', + 'friendrequest:decline:fail' => 'Não foi possível apagar o pedido de amizade. Tente novamente ou entre em contato com xs administradorxs.', + +// 'friendrequest:remove:check' => 'Are you sure you want to decline the friend request?', +// 'friendrequest:none' => 'No pending friend requests.', + + 'friendrequest:new:subject' => '%s quer ser teu/tua amigx!', + 'friendrequest:new:body' => '%s quer ser teu/tua amigx. Elx está esperando que você aceite o pedido. + +Você pode ver os teus pedidos pendentes clicando em (lembre-se que você tem que estar loga)): + +%s + +Não responda a esta mensagem porque eu sou uma máquina e não vou te ler ;)', + +); + +add_translation('pt', $portuguese); diff --git a/mod/friendrequest/languages/sr.php b/mod/friendrequest/languages/sr.php new file mode 100644 index 000000000..d7d693a09 --- /dev/null +++ b/mod/friendrequest/languages/sr.php @@ -0,0 +1,31 @@ +<?php +/** + * ElggFriendRequest Serbian language file. + * + */ + +$serbian = array( + 'friendrequest' => 'Dodaj u prijatelje', + + 'friendrequest:add:successful' => 'Zahtevao si da postanes prijatelj sa %s. Moras sacekati da odobri tvoj zahtev pre nego sto se pojave u tvojoj listi prijatelja.', + 'friendrequest:add:failure' => 'Izvini, zbog sistemske greske nismo u mogucnosti da izvrsimo zahtev. Molim pokusaj ponovo.', + 'friendrequest:add:exists' => 'Vec si pozvao %s da budete prijatelji.', + + 'friendrequest:decline:success' => 'Uspesno uklonjen zahtev za prijateljstvo.', + 'friendrequest:decline:fail' => 'Nemogu da uklonim zahtev za prijateljstvo.', + +// 'friendrequest:remove:check' => 'Are you sure you want to decline the friend request?', +// 'friendrequest:none' => 'No pending friend requests.', + + 'friendrequest:new:subject' => '%s zeli da bude tvoj prijatelj!', + 'friendrequest:new:body' => '%s zeli da bude tvoj prijatelj! Ali ceka da odobris zahtev...uloguj se sada i odobri zahtev! + +Mozes pogledati cekajuce zahteve na: + +%s + +(Ne mozes odgovoriti na ovaj email.)', + +); + +add_translation('sr', $serbian); diff --git a/mod/friendrequest/manifest.xml b/mod/friendrequest/manifest.xml new file mode 100644 index 000000000..e5b4aad6a --- /dev/null +++ b/mod/friendrequest/manifest.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8"> + <name>Friend request</name> + <author>Bosssumon and Zac Hopkinson, Lorea</author> + <version>1.8.0</version> + <category>social</category> + <description>Let users confirm friend requests. Make all friend requests reciprocal</description> + <website>https://lorea.org/</website> + <copyright>(C) Lorea 2011-2013</copyright> + <license>GNU General Public License version 2</license> + <requires> + <type>elgg_release</type> + <version>1.8</version> + </requires> + <activate_on_install>true</activate_on_install> +</plugin_manifest> diff --git a/mod/friendrequest/start.php b/mod/friendrequest/start.php new file mode 100644 index 000000000..2ea3c80f9 --- /dev/null +++ b/mod/friendrequest/start.php @@ -0,0 +1,151 @@ +<?php +/** + * Elgg friend request plugin. + * + * @package ElggFriendRequest + */ + +elgg_register_event_handler('init', 'system', 'friendrequest_init'); + +function friendrequest_init() { + + //This will let users view their friend requests + elgg_register_page_handler('friendrequests', 'friendrequest_page_handler'); + + elgg_register_plugin_hook_handler('register', 'menu:topbar', 'friendrequest_topbar_menu'); + elgg_register_plugin_hook_handler('register', 'menu:page', 'friendrequest_page_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"); + elgg_register_action('friends/remove', "$actions_dir/remove.php"); + + $actions_dir = elgg_get_plugins_path().'friendrequest/actions/friendrequest'; + elgg_register_action('friendrequest/decline', "$actions_dir/decline.php"); + + //Regular Elgg engine sends out an email via an event. The 400 priority will let us run first. + //Then we return false to stop the event chain. The normal event handler will never get to run. + //elgg_register_event_handler('create', 'friend', 'friendrequest_event_create_friend', 400); + + //Handle our add action event: + elgg_register_event_handler('create', 'friendrequest', 'friendrequest_event_create_friendrequest'); + +} + +function friendrequest_page_handler($page){ + + //Keep the URLs uniform: + if (isset($page[0])) { + forward("friendrequests"); + } + + gatekeeper(); + + elgg_push_context('friends'); + + $title = elgg_echo('friendrequest'); + + $page_owner = elgg_get_logged_in_user_entity(); + elgg_set_page_owner_guid($page_owner->guid); + + $requests = elgg_get_entities_from_relationship(array( + 'type' => 'user', + 'relationship' => 'friendrequest', + 'relationship_guid' => $page_owner->guid, + 'inverse_relationship' => true, + 'limit' => 0, + )); + $content = elgg_view('friendrequest/requests', array( + 'requests' => $requests, + )); + + $params = array( + 'content' => $content, + 'title' => $title, + 'filter' => '', + ); + $body = elgg_view_layout('content', $params); + + echo elgg_view_page($title, $body); + + 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_page_menu($hook, $entity_type, $returnvalue, $params) { + if(elgg_in_context('friends')){ + foreach($returnvalue as $i => $item) { + if($item->getName() == 'friends:of') { + unset($returnvalue[$i]); + } + } + if (elgg_is_logged_in()) { + $count = friendrequest_count(); + $item = new ElggMenuItem('friendrequests', elgg_echo('friendrequest').($count? " ($count)": ""), "friendrequests"); + $returnvalue[] = $item; + } + } + return $returnvalue; +} + +function friendrequest_event_create_friend($event, $object_type, $object){var_dump($object);elgg_echo('hola'); + if (($object instanceof ElggRelationship) && ($event == 'create') && ($object_type == 'friend')) { + //We don't want anything happening here... (no email/etc) + + //Returning false will interrupt the rest of the chain. + //The normal handler for the create friend event has a priority of 500 so it will never be called. + return false; + } + return true; //Shouldn't get here... +} + +function friendrequest_event_create_friendrequest($event, $object_type, $object){ + if (($object instanceof ElggRelationship) && ($event == 'create') && ($object_type == 'friendrequest')) { + $requester = get_entity($object->guid_one); + $requested = get_entity($object->guid_two); + + $friendrequests_url = elgg_get_site_url() . "friendrequests/"; + + // Notify target user + return notify_user( + $requested, + $requester, + elgg_echo('friendrequest:newfriend:subject', array( + $requester->name + ), $requested->language), + elgg_echo('friendrequest:newfriend:body', array( + $requester->name, + $friendrequests_url, + ), $requested->language) + ); + } +} diff --git a/mod/friendrequest/views/default/friendrequest/requests.php b/mod/friendrequest/views/default/friendrequest/requests.php new file mode 100644 index 000000000..1680bdc4e --- /dev/null +++ b/mod/friendrequest/views/default/friendrequest/requests.php @@ -0,0 +1,47 @@ +<?php +/** + * The friend requests' list + * + * @uses $vars['requests'] Array of ElggUsers + */ + +if (!empty($vars['requests']) && is_array($vars['requests'])) { + $user = elgg_get_logged_in_user_entity(); + echo '<ul class="elgg-list">'; + foreach ($vars['requests'] as $user) { + $icon = elgg_view_entity_icon($user, 'tiny', array('use_hover' => 'true')); + + $user_title = elgg_view('output/url', array( + 'href' => $user->getURL(), + 'text' => $user->name, + 'is_trusted' => true, + )); + + $url = "action/friends/add?friend={$user->guid}"; + $accept_button = elgg_view('output/url', array( + 'href' => $url, + 'text' => elgg_echo('accept'), + 'class' => 'elgg-button elgg-button-submit', + 'is_action' => true, + 'is_trusted' => true, + )); + + $url = "action/friendrequest/decline?guid={$user->guid}"; + $delete_button = elgg_view('output/confirmlink', array( + 'href' => $url, + 'confirm' => elgg_echo('friendrequest:remove:check'), + 'text' => elgg_echo('delete'), + 'class' => 'elgg-button elgg-button-delete mlm', + )); + + $body = "<h4>$user_title</h4>"; + $alt = $accept_button . $delete_button; + + echo '<li class="pvs">'; + echo elgg_view_image_block($icon, $body, array('image_alt' => $alt)); + echo '</li>'; + } + echo '</ul>'; +} else { + echo '<p class="mtm">' . elgg_echo('friendrequest:none') . "</p>"; +} |