diff options
Diffstat (limited to 'mod/invitefriends')
-rw-r--r-- | mod/invitefriends/actions/invite.php | 117 | ||||
-rw-r--r-- | mod/invitefriends/index.php | 25 | ||||
-rw-r--r-- | mod/invitefriends/languages/en.php | 42 | ||||
-rw-r--r-- | mod/invitefriends/manifest.xml | 10 | ||||
-rw-r--r-- | mod/invitefriends/start.php | 31 | ||||
-rw-r--r-- | mod/invitefriends/views/default/invitefriends/form.php | 18 | ||||
-rw-r--r-- | mod/invitefriends/views/default/invitefriends/formitems.php | 33 |
7 files changed, 276 insertions, 0 deletions
diff --git a/mod/invitefriends/actions/invite.php b/mod/invitefriends/actions/invite.php new file mode 100644 index 000000000..7e0bd54b8 --- /dev/null +++ b/mod/invitefriends/actions/invite.php @@ -0,0 +1,117 @@ +<?php + + /** + * Elgg invite action + * + * @package ElggFile + * @author Curverider Ltd + * @copyright Curverider Ltd 2008-2010 + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @link http://elgg.org/ + */ + + global $CONFIG; + + gatekeeper(); + + $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:failure')); + forward($_SERVER['HTTP_REFERER']); + } + + $error = FALSE; + $bad_emails = array(); + 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; + } + + $link = $CONFIG->wwwroot . 'pg/register?friend_guid=' . $_SESSION['guid'] . '&invitecode=' . generate_invite_code($_SESSION['user']->username); + $message = sprintf(elgg_echo('invitefriends:email'), + $CONFIG->site->name, + $_SESSION['user']->name, + $emailmessage, + $link + ); + + // **** this should be replaced by a core function for sending emails to people who are not members + $site = get_entity($CONFIG->site_guid); + // If there's an email address, use it - but only if its not from a user. + if (($site) && (isset($site->email))) { + // Has the current site got a from email address? + $from = $site->email; + } else if (isset($from->url)) { + // If we have a url then try and use that. + $breakdown = parse_url($from->url); + $from = 'noreply@' . $breakdown['host']; // Handle anything with a url + } else { + // If all else fails, use the domain of the site. + $from = 'noreply@' . get_site_domain($CONFIG->site_guid); + } + + if (is_callable('mb_internal_encoding')) { + mb_internal_encoding('UTF-8'); + } + $site = get_entity($CONFIG->site_guid); + $sitename = $site->name; + if (is_callable('mb_encode_mimeheader')) { + $sitename = mb_encode_mimeheader($site->name,"UTF-8", "B"); + } + + $header_eol = "\r\n"; + if ((isset($CONFIG->broken_mta)) && ($CONFIG->broken_mta)) { + // Allow non-RFC 2822 mail headers to support some broken MTAs + $header_eol = "\n"; + } + + $from_email = "\"$sitename\" <$from>"; + if (strtolower(substr(PHP_OS, 0 , 3)) == 'win') { + // Windows is somewhat broken, so we use a different format from header + $from_email = "$from"; + } + + $headers = "From: $from_email{$header_eol}" + . "Content-Type: text/plain; charset=UTF-8; format=flowed{$header_eol}" + . "MIME-Version: 1.0{$header_eol}" + . "Content-Transfer-Encoding: 8bit{$header_eol}"; + + $subject = sprintf(elgg_echo('invitefriends:subject'), $CONFIG->site->name); + if (is_callable('mb_encode_mimeheader')) { + $subject = mb_encode_mimeheader($subject,"UTF-8", "B"); + } + + // Format message + $message = html_entity_decode($message, ENT_COMPAT, 'UTF-8'); // Decode any html entities + $message = strip_tags($message); // Strip tags from message + $message = preg_replace("/(\r\n|\r)/", "\n", $message); // Convert to unix line endings in body + $message = preg_replace("/^From/", ">From", $message); // Change lines starting with From to >From + + mail($email, $subject, wordwrap($message), $headers); + } + + if ($error) { + register_error(sprintf(elgg_echo('invitefriends:email_error'), implode(', ', $bad_emails))); + } else { + system_message(elgg_echo('invitefriends:success')); + } + + forward($_SERVER['HTTP_REFERER']); + +?> diff --git a/mod/invitefriends/index.php b/mod/invitefriends/index.php new file mode 100644 index 000000000..19471bbed --- /dev/null +++ b/mod/invitefriends/index.php @@ -0,0 +1,25 @@ +<?php + +/** + * Elgg invite page + * + * @package ElggFile + * @author Curverider Ltd + * @copyright Curverider Ltd 2008-2010 + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @link http://elgg.org/ + */ + + require_once(dirname(dirname(dirname(__FILE__))) . '/engine/start.php'); + + gatekeeper(); + + set_context('friends'); + set_page_owner($_SESSION['guid']); + + $body = elgg_view('invitefriends/form'); + $body = elgg_view_layout('two_column_left_sidebar','',$body); + + page_draw(elgg_echo('friends:invite'),$body); + +?>
\ No newline at end of file diff --git a/mod/invitefriends/languages/en.php b/mod/invitefriends/languages/en.php new file mode 100644 index 000000000..357ceeeea --- /dev/null +++ b/mod/invitefriends/languages/en.php @@ -0,0 +1,42 @@ +<?php + + /** + * Elgg invite page + * + * @package ElggFile + * @author Curverider Ltd + * @copyright Curverider Ltd 2008-2010 + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @link http://elgg.org/ + */ + + $english = array( + + 'friends:invite' => 'Invite friends', + '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:email_error' => 'Invitations were sent, but the following addresses are not valid: %s', + 'invitefriends:failure' => 'Your friends could not be invited.', + + '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..1228edd58 --- /dev/null +++ b/mod/invitefriends/manifest.xml @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<plugin_manifest> + <field key="author" value="Curverider" /> + <field key="version" value="1.7" /> + <field key="description" value="Friend invite page" /> + <field key="website" value="http://www.elgg.org/" /> + <field key="copyright" value="(C) Curverider 2008-2010" /> + <field key="licence" value="GNU Public License version 2" /> + <field key="elgg_version" value="2010030101" /> +</plugin_manifest> diff --git a/mod/invitefriends/start.php b/mod/invitefriends/start.php new file mode 100644 index 000000000..b7cd9868d --- /dev/null +++ b/mod/invitefriends/start.php @@ -0,0 +1,31 @@ +<?php + + /** + * Elgg invite page + * + * @package ElggFile + * @author Curverider Ltd + * @copyright Curverider Ltd 2008-2010 + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @link http://elgg.org/ + */ + + function invitefriends_pagesetup() { + + // Menu options + global $CONFIG; + if (get_context() == "friends" || + get_context() == "friendsof" || + get_context() == "collections") { + + add_submenu_item(elgg_echo('friends:invite'),$CONFIG->wwwroot."mod/invitefriends/",'invite'); + + } + + } + + global $CONFIG; + register_action('invitefriends/invite', false, $CONFIG->pluginspath . 'invitefriends/actions/invite.php'); + register_elgg_event_handler('pagesetup','system','invitefriends_pagesetup',1000); + +?>
\ No newline at end of file diff --git a/mod/invitefriends/views/default/invitefriends/form.php b/mod/invitefriends/views/default/invitefriends/form.php new file mode 100644 index 000000000..ef66c1e84 --- /dev/null +++ b/mod/invitefriends/views/default/invitefriends/form.php @@ -0,0 +1,18 @@ +<?php + /** + * Elgg invite page + * + * @package ElggFile + * @author Curverider Ltd + * @copyright Curverider Ltd 2008-2010 + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @link http://elgg.org/ + */ + echo elgg_view('input/form', array( + 'action' => $vars['url'] . 'action/invitefriends/invite', + 'body' => elgg_view('invitefriends/formitems'), + 'method' => 'post' + ) + ); + +?> diff --git a/mod/invitefriends/views/default/invitefriends/formitems.php b/mod/invitefriends/views/default/invitefriends/formitems.php new file mode 100644 index 000000000..0db562d50 --- /dev/null +++ b/mod/invitefriends/views/default/invitefriends/formitems.php @@ -0,0 +1,33 @@ +<?php + + /** + * Elgg invite page + * + * @package ElggFile + * @author Curverider Ltd + * @copyright Curverider Ltd 2008-2010 + * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 + * @link http://elgg.org/ + */ + +?> + +<div class="contentWrapper notitle"> +<p><label> + <?php echo elgg_echo('invitefriends:introduction'); ?> +</label> +<textarea class="input-textarea" name="emails" ></textarea></p> +<p><label> + <?php echo elgg_echo('invitefriends:message'); ?> +</label> +<textarea class="input-textarea" name="emailmessage" ><?php + + echo sprintf(elgg_echo('invitefriends:message:default'),$CONFIG->site->name); + +?></textarea></p> +<?php + + echo elgg_view('input/submit', array('value' => elgg_echo('send'))); + +?> +</div>
\ No newline at end of file |