aboutsummaryrefslogtreecommitdiff
path: root/mod/invitefriends
diff options
context:
space:
mode:
Diffstat (limited to 'mod/invitefriends')
-rw-r--r--mod/invitefriends/actions/invite.php88
-rw-r--r--mod/invitefriends/languages/en.php43
-rw-r--r--mod/invitefriends/manifest.xml17
-rw-r--r--mod/invitefriends/start.php50
-rw-r--r--mod/invitefriends/views/default/forms/invitefriends/invite.php35
-rw-r--r--mod/invitefriends/views/default/invitefriends/form.php8
-rw-r--r--mod/invitefriends/views/default/invitefriends/formitems.php4
7 files changed, 245 insertions, 0 deletions
diff --git a/mod/invitefriends/actions/invite.php b/mod/invitefriends/actions/invite.php
new file mode 100644
index 000000000..eed156d69
--- /dev/null
+++ b/mod/invitefriends/actions/invite.php
@@ -0,0 +1,88 @@
+<?php
+
+/**
+ * Elgg invite friends action
+ *
+ * @package ElggInviteFriends
+ */
+
+$site = elgg_get_site_entity();
+
+$emails = get_input('emails');
+$emailmessage = get_input('emailmessage');
+
+$emails = trim($emails);
+if (strlen($emails) > 0) {
+ $emails = preg_split('/\\s+/', $emails, -1, PREG_SPLIT_NO_EMPTY);
+}
+
+if (!is_array($emails) || count($emails) == 0) {
+ register_error(elgg_echo('invitefriends:noemails'));
+ forward(REFERER);
+}
+
+$current_user = elgg_get_logged_in_user_entity();
+
+$error = FALSE;
+$bad_emails = array();
+$already_members = array();
+$sent_total = 0;
+foreach ($emails as $email) {
+
+ $email = trim($email);
+ if (empty($email)) {
+ continue;
+ }
+
+ // send out other email addresses
+ if (!is_email_address($email)) {
+ $error = TRUE;
+ $bad_emails[] = $email;
+ continue;
+ }
+
+ if (get_user_by_email($email)) {
+ $error = TRUE;
+ $already_members[] = $email;
+ continue;
+ }
+
+ $link = elgg_get_site_url() . 'register?friend_guid=' . $current_user->guid . '&invitecode=' . generate_invite_code($current_user->username);
+ $message = elgg_echo('invitefriends:email', array(
+ $site->name,
+ $current_user->name,
+ $emailmessage,
+ $link
+ )
+ );
+
+ $subject = elgg_echo('invitefriends:subject', array($site->name));
+
+ // create the from address
+ $site = get_entity($site->guid);
+ if ($site && $site->email) {
+ $from = $site->email;
+ } else {
+ $from = 'noreply@' . get_site_domain($site->guid);
+ }
+
+ elgg_send_email($from, $email, $subject, $message);
+ $sent_total++;
+}
+
+if ($error) {
+ register_error(elgg_echo('invitefriends:invitations_sent', array($sent_total)));
+
+ if (count($bad_emails) > 0) {
+ register_error(elgg_echo('invitefriends:email_error', array(implode(', ', $bad_emails))));
+ }
+
+ if (count($already_members) > 0) {
+ register_error(elgg_echo('invitefriends:already_members', array(implode(', ', $already_members))));
+ }
+
+} else {
+ system_message(elgg_echo('invitefriends:success'));
+}
+
+forward(REFERER);
diff --git a/mod/invitefriends/languages/en.php b/mod/invitefriends/languages/en.php
new file mode 100644
index 000000000..f31d79bd8
--- /dev/null
+++ b/mod/invitefriends/languages/en.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * Elgg invite language file
+ *
+ * @package ElggInviteFriends
+ */
+
+$english = array(
+
+ 'friends:invite' => 'Invite friends',
+
+ 'invitefriends:registration_disabled' => 'New user registration has been disabled on this site; you are unable to invite new users.',
+
+ 'invitefriends:introduction' => 'To invite friends to join you on this network, enter their email addresses below (one per line):',
+ 'invitefriends:message' => 'Enter a message they will receive with your invitation:',
+ 'invitefriends:subject' => 'Invitation to join %s',
+
+ 'invitefriends:success' => 'Your friends were invited.',
+ 'invitefriends:invitations_sent' => 'Invites sent: %s. There were the following problems:',
+ 'invitefriends:email_error' => 'The following addresses are not valid: %s',
+ 'invitefriends:already_members' => 'The following are already members: %s',
+ 'invitefriends:noemails' => 'No email addresses were entered.',
+
+ 'invitefriends:message:default' => '
+Hi,
+
+I want to invite you to join my network here on %s.',
+
+ 'invitefriends:email' => '
+You have been invited to join %s by %s. They included the following message:
+
+%s
+
+To join, click the following link:
+
+%s
+
+You will automatically add them as a friend when you create your account.',
+
+ );
+
+add_translation("en", $english);
diff --git a/mod/invitefriends/manifest.xml b/mod/invitefriends/manifest.xml
new file mode 100644
index 000000000..b36238a05
--- /dev/null
+++ b/mod/invitefriends/manifest.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
+ <name>Invite Friends</name>
+ <author>Core developers</author>
+ <version>1.8</version>
+ <category>bundled</category>
+ <category>social</category>
+ <description>Invite friends via email invites.</description>
+ <website>http://www.elgg.org/</website>
+ <copyright>See COPYRIGHT.txt</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/invitefriends/start.php b/mod/invitefriends/start.php
new file mode 100644
index 000000000..368f6348a
--- /dev/null
+++ b/mod/invitefriends/start.php
@@ -0,0 +1,50 @@
+<?php
+/**
+ * Elgg invite friends
+ *
+ * @package ElggInviteFriends
+ */
+
+elgg_register_event_handler('init', 'system', 'invitefriends_init');
+
+function invitefriends_init() {
+ elgg_register_page_handler('invite', 'invitefriends_page_handler');
+
+ elgg_register_action('invitefriends/invite', elgg_get_plugins_path() . 'invitefriends/actions/invite.php');
+
+ if (elgg_is_logged_in()) {
+ $params = array(
+ 'name' => 'invite',
+ 'text' => elgg_echo('friends:invite'),
+ 'href' => "invite",
+ 'contexts' => array('friends'),
+ );
+ elgg_register_menu_item('page', $params);
+ }
+}
+
+/**
+ * Page handler function
+ *
+ * @param array $page Page URL segments
+ * @return bool
+ */
+function invitefriends_page_handler($page) {
+ gatekeeper();
+
+ elgg_set_context('friends');
+ elgg_set_page_owner_guid(elgg_get_logged_in_user_guid());
+
+ $title = elgg_echo('friends:invite');
+
+ $body = elgg_view('invitefriends/form');
+
+ $params = array(
+ 'content' => $body,
+ 'title' => $title,
+ );
+ $body = elgg_view_layout('one_sidebar', $params);
+
+ echo elgg_view_page($title, $body);
+ return true;
+}
diff --git a/mod/invitefriends/views/default/forms/invitefriends/invite.php b/mod/invitefriends/views/default/forms/invitefriends/invite.php
new file mode 100644
index 000000000..0d7f5d9f2
--- /dev/null
+++ b/mod/invitefriends/views/default/forms/invitefriends/invite.php
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * Elgg invite form contents
+ *
+ * @package ElggInviteFriends
+ */
+
+if (elgg_get_config('allow_registration')) {
+ $site = elgg_get_site_entity();
+ $introduction = elgg_echo('invitefriends:introduction');
+ $message = elgg_echo('invitefriends:message');
+ $default = elgg_echo('invitefriends:message:default', array($site->name));
+
+ echo <<< HTML
+<div>
+ <label>
+ $introduction
+ <textarea class="elgg-input-textarea" name="emails" ></textarea>
+ </label>
+</div>
+<div>
+ <label>
+ $message
+ <textarea class="elgg-input-textarea" name="emailmessage" >$default</textarea>
+ </label>
+</div>
+HTML;
+
+ echo '<div class="elgg-foot">';
+ echo elgg_view('input/submit', array('value' => elgg_echo('send')));
+ echo '</div>';
+} else {
+ echo elgg_echo('invitefriends:registration_disabled');
+}
diff --git a/mod/invitefriends/views/default/invitefriends/form.php b/mod/invitefriends/views/default/invitefriends/form.php
new file mode 100644
index 000000000..badcf8759
--- /dev/null
+++ b/mod/invitefriends/views/default/invitefriends/form.php
@@ -0,0 +1,8 @@
+<?php
+/**
+ * Elgg invite form wrapper
+ *
+ * @package ElggInviteFriends
+ */
+
+echo elgg_view_form('invitefriends/invite');
diff --git a/mod/invitefriends/views/default/invitefriends/formitems.php b/mod/invitefriends/views/default/invitefriends/formitems.php
new file mode 100644
index 000000000..afdff4164
--- /dev/null
+++ b/mod/invitefriends/views/default/invitefriends/formitems.php
@@ -0,0 +1,4 @@
+<?php
+
+elgg_deprecated_notice("invitefriends/formitems was moved to forms/invitefriends/invite", 1.8);
+echo elgg_view('forms/invitefriends/invite'); \ No newline at end of file