/** * Add menu items to the filter menu * * @param string $hook 'cron' * @param string $type 'daily' * @param string $return_value optional output * @param array $params supplied params * * @return void */ public static function daily($hook, $type, $return_value, $params) { if (!static_out_of_date_enabled()) { return; } $time = elgg_extract('time', $params, time()); $days = (int) elgg_get_plugin_setting('out_of_date_days', 'static'); $site = elgg_get_site_entity(); $options = ['type' => 'object', 'subtype' => \StaticPage::SUBTYPE, 'limit' => false, 'modified_time_upper' => $time - $days * 24 * 60 * 60, 'modified_time_lower' => $time - ($days + 1) * 24 * 60 * 60, 'order_by' => 'e.time_updated DESC']; // ignore access $ia = elgg_set_ignore_access(true); $batch = new \ElggBatch('elgg_get_entities', $options); $users = []; foreach ($batch as $entity) { $last_editors = $entity->getAnnotations(['annotation_name' => 'static_revision', 'limit' => 1, 'order_by' => 'n_table.time_created DESC']); if (empty($last_editors)) { continue; } $users[$last_editors[0]->getOwnerGUID()] = $last_editors[0]->getOwnerEntity(); } // restore access elgg_set_ignore_access($ia); if (empty($users)) { return; } foreach ($users as $user) { $subject = elgg_echo('static:out_of_date:notification:subject'); $message = elgg_echo('static:out_of_date:notification:message', [$user->name, elgg_normalize_url('static/out_of_date/' . $user->username)]); notify_user($user->getGUID(), $site->getGUID(), $subject, $message, [], 'email'); } }
/** * This functions performs actions when a wire post is created * * @param string $event 'create' * @param string $type 'object' * @param \ElggObject $object the ElggObject created * * @return void */ public static function triggerMentionNotificationEvent($event, $type, \ElggObject $object) { if (!elgg_instanceof($object, 'object', 'thewire')) { return; } // @todo replace with decent Elgg 2.0 notification event handling //send out notification to users mentioned in a wire post $usernames = []; preg_match_all("/\\@([A-Za-z0-9\\_\\.\\-]+)/i", $object->description, $usernames); if (empty($usernames)) { return; } $usernames = array_unique($usernames[0]); $params = ['object' => $object, 'action' => 'mention']; foreach ($usernames as $username) { $username = str_ireplace('@', '', $username); $user = get_user_by_username($username); if (empty($user) || $user->getGUID() == $object->getOwnerGUID()) { continue; } $setting = thewire_tools_get_notification_settings($user->getGUID()); if (empty($setting)) { continue; } $subject = elgg_echo('thewire_tools:notify:mention:subject'); $message = elgg_echo('thewire_tools:notify:mention:message', [$user->name, $object->getOwnerEntity()->name, elgg_normalize_url("thewire/search/@{$user->username}")]); notify_user($user->getGUID(), $object->getOwnerGUID(), $subject, $message, $params, $setting); } }
/** * {@inheritdoc} */ public function post(ParameterBag $params) { $user = elgg_get_logged_in_user_entity(); $object = get_entity($params->guid); if (!$object || !$object->canWriteToContainer(0, 'object', 'comment')) { throw new GraphException("You are not allowed to comment on this object", 403); } $comment_text = $params->comment; $comment = new ElggComment(); $comment->owner_guid = $user->guid; $comment->container_guid = $object->guid; $comment->description = $comment_text; $comment->access_id = $object->access_id; if (!$comment->save()) { throw new GraphException(elgg_echo("generic_comment:failure")); } // Notify if poster wasn't owner if ($object->owner_guid != $user->guid) { $owner = $object->getOwnerEntity(); notify_user($owner->guid, $user->guid, elgg_echo('generic_comment:email:subject', array(), $owner->language), elgg_echo('generic_comment:email:body', array($object->title, $user->name, $comment->description, $comment->getURL(), $user->name, $user->getURL()), $owner->language), array('object' => $comment, 'action' => 'create')); } $return = array('nodes' => array('comment' => $comment)); // Add to river $river_id = elgg_create_river_item(array('view' => 'river/object/comment/create', 'action_type' => 'comment', 'subject_guid' => $user->guid, 'object_guid' => $comment->guid, 'target_guid' => $object->guid)); if ($river_id) { $river = elgg_get_river(array('ids' => $river_id)); $return['nodes']['activity'] = $river ? $river[0] : $river_id; } return $return; }
/** * Listen to the delete of a membership request * * @param stirng $event the name of the event * @param stirng $type the type of the event * @param \ElggRelationship $relationship the relationship * * @return void */ public static function deleteRequest($event, $type, $relationship) { if (!$relationship instanceof \ElggRelationship) { return; } if ($relationship->relationship !== 'membership_request') { // not a membership request return; } $action_pattern = '/action\\/groups\\/killrequest/i'; if (!preg_match($action_pattern, current_page_url())) { // not in the action, so do nothing return; } $group = get_entity($relationship->guid_two); $user = get_user($relationship->guid_one); if (empty($user) || !$group instanceof \ElggGroup) { return; } if ($user->getGUID() === elgg_get_logged_in_user_guid()) { // user kills own request return; } $reason = get_input('reason'); if (empty($reason)) { $body = elgg_echo('group_tools:notify:membership:declined:message', array($user->name, $group->name, $group->getURL())); } else { $body = elgg_echo('group_tools:notify:membership:declined:message:reason', array($user->name, $group->name, $reason, $group->getURL())); } $subject = elgg_echo('group_tools:notify:membership:declined:subject', array($group->name)); $params = array('object' => $group, 'action' => 'delete'); notify_user($user->getGUID(), $group->getGUID(), $subject, $body, $params); }
function au_landing_page_update($event, $type, $object) { if (!elgg_instanceof($object, 'page') && elgg_instanceof($object, 'page_top')) { return true; } // only process this event once if (elgg_get_config('page_update_notify_sent_' . $object->guid)) { return true; } elgg_set_config('page_update_notify_sent_' . $object->guid, true); // get revision history for the page $revisions = $object->getAnnotations(array('annotation_name' => 'page', 'limit' => false)); // create an array of unique users to notify, excluding the current user // and the object owner (as core notifies them) $users = array(); foreach ($revisions as $revision) { if ($revision->owner_guid != $object->owner_guid && $revision->owner_guid != elgg_get_logged_in_user_guid()) { $users[] = $revision->owner_guid; } } $users = array_unique($users); // notify the users if (count($users)) { notify_user($users, elgg_get_logged_in_user_guid(), elgg_echo('au_landing:page:update:subject', array($object->title)), elgg_echo('au_landing:page:update:message', array($object->title, elgg_get_logged_in_user_entity()->name, $object->getURL()))); } }
/** * Notify subscribed users * @param int $guid */ function hj_forum_notify_subscribed_users($guid) { $entity = get_entity($guid); //$parentEntity = get_entity($entity->container_guid); $subscribers = $entity->getSubscribedUsers(); $to = array(); foreach ($subscribers as $subscribed) { $to[] = $subscribed->guid; } $subtype = $entity->getSubtype(); $from = elgg_get_site_entity()->guid; $subject = elgg_echo("hj:forum:new:{$subtype}"); $subject_link = elgg_view('framework/bootstrap/user/elements/name', array('entity' => $entity->getOwnerEntity())); $object_link = elgg_view('framework/bootstrap/object/elements/title', array('entity' => $entity)); $breadcrumbs = elgg_view('framework/bootstrap/object/elements/breadcrumbs', array('entity' => $entity)); if (!empty($breadcrumbs)) { $breadcrumbs_link = elgg_echo('river:in:forum', array($breadcrumbs)); } $key = "river:create:object:{$subtype}"; $summary = elgg_echo($key, array($subject_link, $object_link)) . $breadcrumbs_link; $body = elgg_view('framework/bootstrap/object/elements/description', array('entity' => $entity)); $link = elgg_view('output/url', array('text' => elgg_echo('hj:framework:notification:link'), 'href' => $entity->getURL(), 'is_trusted' => true)); $footer = elgg_echo('hj:framework:notification:full_link', array($link)); $message = "<p>{$summary}</p><p>{$body}</p><p>{$footer}</p>"; notify_user($to, $from, $subject, $message); }
/** * {@inheritdoc} */ public function post(ParameterBag $params) { $user = elgg_get_logged_in_user_entity(); $group = get_entity($params->guid); // join or request $join = false; if ($group->isPublicMembership() || $group->canEdit($user->guid)) { // anyone can join public groups and admins can join any group $join = true; } else { if (check_entity_relationship($group->guid, 'invited', $user->guid)) { // user has invite to closed group $join = true; } } if ($join) { if (groups_join_group($group, $user)) { $msg = elgg_echo("groups:joined"); } else { throw new GraphException(elgg_echo("groups:cantjoin")); } } else { if (!add_entity_relationship($user->guid, 'membership_request', $group->guid)) { throw new GraphException(elgg_echo("groups:joinrequestnotmade")); } $owner = $group->getOwnerEntity(); $url = elgg_normalize_url("groups/requests/{$group->guid}"); $subject = elgg_echo('groups:request:subject', array($user->name, $group->name), $owner->language); $body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url), $owner->language); // Notify group owner notify_user($owner->guid, $user->getGUID(), $subject, $body); $msg = elgg_echo("groups:joinrequestmade"); } return array('nodes' => array('member' => check_entity_relationship($user->guid, 'member', $group->guid), 'invited' => check_entity_relationship($group->guid, 'invited', $user->guid), 'membership_request' => check_entity_relationship($user->guid, 'membership_request', $group->guid))); }
/** * This functions performs actions when a wire post is created * * @param string $event 'create' * @param string $type 'object' * @param ElggObject $object the ElggObject created * * @return void */ function thewire_tools_create_object_event_handler($event, $type, ElggObject $object) { if (empty($object) || !elgg_instanceof($object, "object", "thewire")) { return; } //send out notification to users mentioned in a wire post $usernames = array(); preg_match_all("/\\@([A-Za-z0-9\\_\\.\\-]+)/i", $object->description, $usernames); if (empty($usernames)) { return; } $usernames = array_unique($usernames[0]); $params = array("object" => $object, "action" => "mention"); foreach ($usernames as $username) { $username = str_ireplace("@", "", $username); $user = get_user_by_username($username); if (empty($user) || $user->getGUID() == $object->getOwnerGUID()) { continue; } $setting = thewire_tools_get_notification_settings($user->getGUID()); if (empty($setting)) { continue; } $subject = elgg_echo("thewire_tools:notify:mention:subject"); $message = elgg_echo("thewire_tools:notify:mention:message", array($user->name, $object->getOwnerEntity()->name, elgg_normalize_url("thewire/search/@" . $user->username))); notify_user($user->getGUID(), $object->getOwnerGUID(), $subject, $message, $params, $setting); } }
/** * Listen to the usersettings save hook for some notifications to the user * * @param string $hook usersettings:save * @param string $type user * @param bool $return_value not supplied for this hook * @param null $params not supplied for this hook * * @return void */ function security_tools_usersettings_save_handler($hook, $type, $return_value, $params) { $user_guid = (int) get_input("guid"); if (empty($user_guid)) { $user_guid = elgg_get_logged_in_user_guid(); } if (empty($user_guid)) { return $return_value; } $user = get_user($user_guid); if (empty($user) || !$user->canEdit()) { return $return_value; } // passwords are different if (_elgg_set_user_password() === true) { // do we need to notify the user about a password change $setting = elgg_get_plugin_setting("mails_password_change", "security_tools"); if ($setting != "no") { $site = elgg_get_site_entity(); $subject = elgg_echo("security_tools:notify_user:password:subject"); $message = elgg_echo("security_tools:notify_user:password:message", array($user->name, $site->name, $site->url)); notify_user($user->getGUID(), $site->getGUID(), $subject, $message, null, "email"); } } // email are also different $setting = elgg_get_plugin_setting("mails_verify_email_change", "security_tools"); if ($setting != "no" && $user->getGUID() == elgg_get_logged_in_user_guid()) { // verify new email address security_tools_prepare_email_change(); } else { // old way, or admin changes your email _elgg_set_user_email(); } }
/** * Notify the group admins about a membership request * * @param string $event create * @param string $type membership_request * @param \ElggRelationship $relationship the created membership request relation * * @return void */ public static function membershipRequest($event, $type, $relationship) { if (!$relationship instanceof \ElggRelationship) { return; } if ($relationship->relationship !== 'membership_request') { return; } // only send a message if group admins are allowed if (!group_tools_multiple_admin_enabled()) { return; } $user = get_user($relationship->guid_one); $group = get_entity($relationship->guid_two); if (empty($user) || !$group instanceof \ElggGroup) { return; } // Notify group admins $options = ['relationship' => 'group_admin', 'relationship_guid' => $group->getGUID(), 'inverse_relationship' => true, 'type' => 'user', 'limit' => false, 'wheres' => ["e.guid <> {$group->getOwnerGUID()}"]]; $url = elgg_normalize_url("groups/requests/{$group->getGUID()}"); $subject = elgg_echo('groups:request:subject', [$user->name, $group->name]); $admins = new \ElggBatch('elgg_get_entities_from_relationship', $options); foreach ($admins as $a) { $body = elgg_echo('groups:request:body', [$a->name, $user->name, $group->name, $user->getURL(), $url]); notify_user($a->getGUID(), $user->getGUID(), $subject, $body); } }
/** * Make sure the last editor of a static page gets notified about a comment * * @param string $event 'create' * @param string $type 'object' * @param \ElggObject $object the object that was just created * * @return void */ public static function notifyLastEditor($event, $type, \ElggObject $object) { // check of this is a comment if (empty($object) || !elgg_instanceof($object, 'object', 'comment')) { return; } // is it a comment on a static page $container = $object->getContainerEntity(); if (empty($container) || !elgg_instanceof($container, 'object', 'static')) { return; } $comment_owner = $object->getOwnerEntity(); // get last revisor $ia = elgg_set_ignore_access(true); $revisions = $container->getAnnotations(['annotation_name' => 'static_revision', 'limit' => 1, 'reverse_order_by' => true]); $static_owner = $revisions[0]->getOwnerEntity(); elgg_set_ignore_access($ia); // don't notify yourself if ($static_owner->getGUID() == $comment_owner->getGUID()) { return; } // @see actions/comment/save $subject = elgg_echo('generic_comment:email:subject'); $message = elgg_echo('generic_comment:email:body', [$container->title, $comment_owner->name, $object->description, $container->getURL(), $comment_owner->name, $comment_owner->getURL()]); $params = ['object' => $object, 'action' => 'create']; notify_user($static_owner->getGUID(), $comment_owner->getGUID(), $subject, $message, $params); }
public function sendUserNotifications() { if (is_array($this->calloutUsers)) { foreach ($this->calloutUsers as $calloutUserGuid) { notify_user($calloutUserGuid, $this->fromUser->guid, $this->fromUser->name . " mentioned you in " . $this->context, "You have been mentioned in " . $this->context . ". View it here: " . $this->url); } } else { notify_user($this->calloutUsers, $this->fromUser->guid, $this->fromUser->name . " mentioned you in " . $this->context, "You have been mentioned in " . $this->context . ". View it here: " . $this->url); } }
/** * send the message in the vroom shutdown stage */ function friend_collection_message_shutdown_tasks() { $id = elgg_get_config('friend_collection_message_id'); $recipients = elgg_get_config('friend_collection_message_recipients'); $subject = elgg_get_config('friend_collection_message_subject'); $message = elgg_get_config('friend_collection_message_message'); $members = get_members_of_access_collection($id, true); $guids = array_intersect($recipients, $members); notify_user($guids, elgg_get_logged_in_user_guid(), $subject, $message); }
/** * Send validation reminder to a specified user with * some parameters. * * @param ElggUser $user User to send the reminder to * @param int $enddate The end date in a unix timestamp * @param int $pastdays The days we've passed since the validation */ function send_validation_reminder_mail($user, $enddate, $pastdays) { $daysleft = $enddate - $pastdays; $site = elgg_get_site_entity(); $code = uservalidationbyemail_generate_code($user->getGUID(), $user->email); $link = $site->url . 'uservalidationbyemail/confirm?u=' . $user->getGUID() . '&c=' . $code; $subject = elgg_echo('validation_reminder:validate:token:subject', array($user->name, $site->name), $user->language); $body = elgg_echo('validation_reminder:validate:token:body', array($user->name, $pastdays, $site->name, $user->token, $link, $daysleft, $site->name, $site->url), $user->language); // Send validation email notify_user($user->guid, $site->guid, $subject, $body, array(), 'email'); }
/** * Send a thank you notification after account removal * * @param string $type what kind of removal * @param int $user_guid the user_guid to send the notification to * * @return bool */ function account_removal_send_thank_notification($type, $user_guid) { $result = false; $site = elgg_get_site_entity(); if (!empty($user_guid) && ($user = get_user($user_guid)) && in_array($type, array("remove", "disable"))) { $subject = elgg_echo("account_removal:message:thank_you:" . $type . ":subject", array($site->name)); $message = elgg_echo("account_removal:message:thank_you:" . $type . ":body", array($user->name, $site->name)); notify_user($user_guid, $site->getGUID(), $subject, $message, null, "email"); $result = true; } return $result; }
function friend_request_event_create_friendrequest($event, $object_type, $object) { if ($object instanceof ElggRelationship) { $user_one = get_user($object->guid_one); $user_two = get_user($object->guid_two); $view_friends_url = elgg_get_site_url() . "friend_request/" . $user_two->username; // Notify target user $subject = elgg_echo('friend_request:newfriend:subject', array($user_one->name)); $message = elgg_echo("friend_request:newfriend:body", array($user_one->name, $view_friends_url)); return notify_user($object->guid_two, $object->guid_one, $subject, $message); } }
/** * Deliver a request * @param integer $requestid * @return true if the request status was updated successfully, false otherwise */ function deliver_request($requestid) { global $DB; // Update the request status to 1, meaning it has been delivered. if (!$DB->update_record('block_ps_selfstudy_request', array('id' => $requestid, 'request_status' => '1'))) { return false; } // Notify the user that his/her course has been delivered. $sql = "SELECT course_name AS coursename,\n course_code AS coursecode,\n request.student_id AS student_id,\n firstname,\n lastname,\n email\n FROM {block_ps_selfstudy_request} request\n JOIN {block_ps_selfstudy_course} course ON course.id = request.course_id\n JOIN {user} u ON u.id = student_id\n WHERE request.id = ?"; $requestinfo = $DB->get_record_sql($sql, array($requestid)); notify_user($requestinfo); return true; }
function rp_send_username($user_guid) { global $CONFIG; $user_guid = (int) $user_guid; $user = get_entity($user_guid); $username = $user->username; if ($user) { // generate email $email = sprintf(elgg_echo('email:requsername:body'), $user->name, $user->username); return notify_user($user->guid, $CONFIG->site->guid, elgg_echo('email:requsername:subject'), $email, NULL, 'email'); } return false; }
/** * Add user as member of the chat. * * @param int $user_guid */ public function addMember($user_guid) { $success = add_entity_relationship($user_guid, 'member', $this->getGUID()); // Send notifications if ($success) { $user = elgg_get_logged_in_user_entity(); if ($user->guid !== $user_guid) { $subject = elgg_echo('chat:notification:subject:newchat'); $body = elgg_echo('chat:notification:newchat', array($user->name, $this->title, $this->getURL())); notify_user($user_guid, elgg_get_site_entity()->getGUID(), $subject, $body); } } return $success; }
/** * Publish blogs based on advanced publication options * * @param string $hook 'cron' * @param string $type 'daily' * @param string $return_value optional stdout text * @param array $params supplied params * * @return void */ public static function daily($hook, $type, $return_value, $params) { // only do if this is configured if (!blog_tools_use_advanced_publication_options()) { return $return_value; } $dbprefix = elgg_get_config("dbprefix"); $publication_id = elgg_get_metastring_id("publication_date"); $expiration_id = elgg_get_metastring_id("expiration_date"); $time = elgg_extract("time", $params, time()); $publish_options = array("type" => "object", "subtype" => "blog", "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "metadata_name_value_pairs" => array(array("name" => "status", "value" => "draft")), "wheres" => array("((mdtime.name_id = " . $publication_id . ") AND (DATE(mstime.string) = DATE(NOW())))")); $unpublish_options = array("type" => "object", "subtype" => "blog", "limit" => false, "joins" => array("JOIN " . $dbprefix . "metadata mdtime ON e.guid = mdtime.entity_guid", "JOIN " . $dbprefix . "metastrings mstime ON mdtime.value_id = mstime.id"), "metadata_name_values_pairs" => array(array("name" => "status", "value" => "published")), "wheres" => array("((mdtime.name_id = " . $expiration_id . ") AND (DATE(mstime.string) = DATE(NOW())))")); // ignore access $ia = elgg_set_ignore_access(true); // get unpublished blogs that need to be published $entities = new \ElggBatch("elgg_get_entities_from_metadata", $publish_options); foreach ($entities as $entity) { // add river item elgg_create_river_item(array("view" => "river/object/blog/create", "action_type" => "create", "subject_guid" => $entity->getOwnerGUID(), "object_guid" => $entity->getGUID())); // set correct time created $entity->time_created = $time; // publish blog $entity->status = "published"; // revert access $entity->access_id = $entity->future_access; unset($entity->future_access); // send notifications when post published elgg_trigger_event('publish', 'object', $entity); // notify owner notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("blog_tools:notify:publish:subject"), elgg_echo("blog_tools:notify:publish:message", array($entity->title, $entity->getURL()))); // save everything $entity->save(); } // get published blogs that need to be unpublished $entities = new \ElggBatch("elgg_get_entities_from_metadata", $unpublish_options); foreach ($entities as $entity) { // remove river item elgg_delete_river(array("object_guid" => $entity->getGUID(), "action_type" => "create")); // unpublish blog $entity->status = "draft"; // notify owner notify_user($entity->getOwnerGUID(), $entity->site_guid, elgg_echo("blog_tools:notify:expire:subject"), elgg_echo("blog_tools:notify:expire:message", array($entity->title, $entity->getURL()))); // save everything $entity->save(); } // reset access elgg_set_ignore_access($ia); }
/** * Add a comment to a wall. * @param unknown_type $wall_id Which wall to post to * @param unknown_type $poster_id * @param unknown_type $text */ function commentwall_addcomment($wall_id, $poster_id, $text) { global $CFG; $newcomment = new stdClass(); $newcomment->wallowner = $wall_id; $newcomment->comment_owner = $poster_id; $newcomment->content = $text; $newcomment->posted = time(); if ($newcomment->ident = insert_record("commentwall", $newcomment)) { if ($newcomment->comment_owner != $newcomment->wallowner) { notify_user($wall_id, __gettext("Someone has posted to your comment wall"), __gettext("Check it out") . ": " . $CFG->wwwroot . user_info("username", $wall_id) . "/profile/"); } return $newcomment->ident; } return insert_record("commentwall", $newcomment); }
/** * Add messageboard post * * @param ElggUser $poster User posting the message * @param ElggUser $owner User who owns the message board * @param string $message The posted message * @param int $access_id Access level (see defines in elgglib.php) * @return bool */ function messageboard_add($poster, $owner, $message, $access_id = ACCESS_PUBLIC) { $result_id = $owner->annotate('messageboard', $message, $access_id, $poster->guid); if (!$result_id) { return false; } elgg_create_river_item(array('view' => 'river/object/messageboard/create', 'action_type' => 'messageboard', 'subject_guid' => $poster->guid, 'object_guid' => $owner->guid, 'access_id' => $access_id, 'annotation_id' => $result_id)); // Send notification only if poster isn't the owner if ($poster->guid != $owner->guid) { $subject = elgg_echo('messageboard:email:subject', array(), $owner->language); $body = elgg_echo('messageboard:email:body', array($poster->name, $message, elgg_get_site_url() . "messageboard/owner/" . $owner->username, $poster->name, $poster->getURL()), $owner->language); $params = ['action' => 'create', 'object' => elgg_get_annotation_from_id($result_id)]; notify_user($owner->guid, $poster->guid, $subject, $body, $params); } return $result_id; }
/** * Request user validation email. * Send email out to the address and request a confirmation. * * @param int $user_guid The user * @return mixed */ function uservalidationbyemail_request_validation($user_guid) { global $CONFIG; $user_guid = (int) $user_guid; $user = get_entity($user_guid); if ($user && $user instanceof ElggUser) { // Work out validate link $link = $CONFIG->site->url . "action/email/confirm?u={$user_guid}&c=" . uservalidationbyemail_generate_code($user_guid, $user->email); // Send validation email $result = notify_user($user->guid, $CONFIG->site->guid, sprintf(elgg_echo('email:validate:subject'), $user->username), sprintf(elgg_echo('email:validate:body'), $user->name, $link), NULL, 'email'); if ($result) { system_message(elgg_echo('uservalidationbyemail:registerok')); } return $result; } return false; }
/** * Send notifications on adding a mutual crushes * * @param type $event * @param type $type * @param type $return * @return type */ function check_mutual_crushes($event, $type, $object) { $mutual_crusher = get_entity($object->guid_one); $original_crusher = get_entity($object->guid_two); // mutuals! if (check_entity_relationship($original_crusher->getGUID(), 'crushing_on', $mutual_crusher->getGUID())) { $msg_url = elgg_normalize_url('messages/compose/?send_to='); // original $subject = elgg_echo('crushes:notifications:mutual_match_subject'); $body = elgg_echo('crushes:notifications:mutual_match_body', array($original_crusher->name, $mutual_crusher->name, $mutual_crusher->getURL(), $msg_url . $mutual_crusher->guid)); notify_user($original_crusher->getGUID(), $mutual_crusher->getGUID(), $subject, $body); // late comer $subject = elgg_echo('crushes:notifications:mutual_match_subject'); $body = elgg_echo('crushes:notifications:mutual_match_body', array($mutual_crusher->name, $original_crusher->name, $original_crusher->getURL(), $msg_url . $original_crusher->guid)); notify_user($mutual_crusher->getGUID(), $original_crusher->getGUID(), $subject, $body); } }
/** * Request user validation email. * Send email out to the address and request a confirmation. * * @param int $user_guid The user's GUID * @param bool $admin_requested Was it requested by admin * @return mixed */ function uservalidationbyadmin_request_validation($user_guid, $admin_requested = FALSE) { $site = elgg_get_site_entity(); $user_guid = (int) $user_guid; $user = get_entity($user_guid); /* if (($user) && ($user instanceof ElggUser)) { // Work out validate link $code = uservalidationbyadmin_generate_code($user_guid, $user->email); $link = "{$site->url}uservalidationbyadmin/confirm?u=$user_guid&c=$code"; // Send validation email $subject = elgg_echo('email:validate:subject', array($user->name, $site->name)); $body = elgg_echo('email:validate:body', array($user->name, $site->name, $link, $site->name, $site->url)); $result = notify_user($user->guid, $site->guid, $subject, $body, NULL, 'email'); if ($result && !$admin_requested) { system_message(elgg_echo('uservalidationbyadmin:registerok')); } return $result; } */ //notify admin if ($user && $user instanceof ElggUser) { $admin = get_admin_user_details(); // Work out validate link $code = uservalidationbyadmin_generate_code($user_guid, $user->email); $link = "{$site->url}uservalidationbyadmin/confirm?u={$user_guid}&c={$code}"; // IP detection $ip_address = $_SERVER['REMOTE_ADDR']; $geoloc = "https://secure.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=" . $ip_address; $geotags = get_meta_tags($geoloc); $geocountry = $geotags['country']; $georegion = $geotags['region']; $geocity = $geotags['city']; $geocertainty = $geotags['certainty']; $geostring = $ip_address . " ; " . $geocountry . " ; " . $georegion . " ; " . $geocity . " ; " . $geocertainty; // Send validation email $subject = elgg_echo('email:validate:subject', array($user->name, $site->name)); $body = elgg_echo('email:validate:body', array($admin->name, $user->name, $ip_address, $geostring, $link, $site->name, $site->url)); $result = notify_user($admin->guid, $site->guid, $subject, $body, NULL, 'email'); if ($result && !$admin_requested) { system_message(elgg_echo('uservalidationbyadmin:registerok')); } return $result; } return FALSE; }
/** * Web service for joining a group * * @param string $username username of author * @param string $groupid GUID of the group * * @return bool */ function group_join($username, $groupid) { $user = get_user_by_username($username); if (!$user) { throw new InvalidParameterException('registration:usernamenotvalid'); } $group = get_entity($groupid); $return['success'] = false; if ($user instanceof ElggUser && $group instanceof ElggGroup) { // join or request $join = false; if ($group->isPublicMembership() || $group->canEdit($user->guid)) { // anyone can join public groups and admins can join any group $join = true; } else { if (check_entity_relationship($group->guid, 'invited', $user->guid)) { // user has invite to closed group $join = true; } } if ($join) { if (groups_join_group($group, $user)) { $return['success'] = true; $return['message'] = elgg_echo("groups:joined"); } else { $return['message'] = elgg_echo("groups:cantjoin"); } } else { add_entity_relationship($user->guid, 'membership_request', $group->guid); // Notify group owner $url = "{$CONFIG->url}mod/groups/membershipreq.php?group_guid={$group->guid}"; $subject = elgg_echo('groups:request:subject', array($user->name, $group->name)); $body = elgg_echo('groups:request:body', array($group->getOwnerEntity()->name, $user->name, $group->name, $user->getURL(), $url)); if (notify_user($group->owner_guid, $user->getGUID(), $subject, $body)) { $return['success'] = true; $return['message'] = elgg_echo("groups:joinrequestmade"); } else { $return['message'] = elgg_echo("groups:joinrequestnotmade"); } } } else { $return['message'] = elgg_echo("groups:cantjoin"); } return $return; }
function group_tools_add_user(ElggGroup $group, ElggUser $user, $text = "") { $result = false; if (!empty($user) && $user instanceof ElggUser && !empty($group) && $group instanceof ElggGroup && ($loggedin_user = elgg_get_logged_in_user_entity())) { if ($group->join($user)) { // Remove any invite or join request flags remove_entity_relationship($group->getGUID(), "invited", $user->getGUID()); remove_entity_relationship($user->getGUID(), "membership_request", $group->getGUID()); // notify user $subject = elgg_echo("group_tools:groups:invite:add:subject", array($group->name)); $msg = elgg_echo("group_tools:groups:invite:add:body", array($user->name, $loggedin_user->name, $group->name, $text, $group->getURL())); if (notify_user($user->getGUID(), $group->getOwnerGUID(), $subject, $msg)) { $result = true; } } } return $result; }
/** * {@inheritdoc} */ public function post(ParameterBag $params) { if (!elgg_get_config('allow_registration') && !elgg_trigger_plugin_hook('allow_registration', 'graph')) { throw new \RegistrationException(elgg_echo('registerdisabled'), 403); } $email = $params->email; $email_parts = explode('@', $params->email); $username = $params->username ?: Registration::generateUsername(); $password = $params->password ?: generate_random_cleartext_password(); $name = $params->name ?: array_shift($email_parts); $guid = register_user($username, $password, $name, $email); if (!$guid) { throw new RegistrationException(elgg_echo('registerbad')); } $new_user = get_entity($guid); $new_user->language = $params->language; $hook_params = array('user' => $new_user, 'password' => $password, 'friend_guid' => $this->graph->get($params->friend_uid)->guid, 'invitecode' => $params->invitecode); if (!elgg_trigger_plugin_hook('validate_registration', 'graph', null, true)) { // disable uservalidationbyemail elgg_unregister_plugin_hook_handler('register', 'user', 'uservalidationbyemail_disable_new_user'); } $ia = elgg_set_ignore_access(true); $params->guid = $new_user->guid; if (!isset($params->access_id)) { $params->access_id = ACCESS_PRIVATE; } $ctrl = new UserProfile($this->request, $this->graph); $ctrl->put($params); elgg_set_ignore_access($ia); $return = array('nodes' => array($new_user)); if (!elgg_trigger_plugin_hook('register', 'user', $hook_params, true)) { $ia = elgg_set_ignore_access(true); $new_user->delete(); elgg_set_ignore_access($ia); throw new RegistrationException(elgg_echo('registerbad')); } if ($params->notify) { $subject = elgg_echo('useradd:subject', array(), $new_user->language); $body = elgg_echo('useradd:body', array($name, elgg_get_site_entity()->name, elgg_get_site_entity()->url, $username, $password), $new_user->language); notify_user($new_user->guid, elgg_get_site_entity()->guid, $subject, $body); } return $return; }
/** * Listen to the 'publish','object' event and send out notifications * to interested users, as well as anyone tagged * * @param string $event Equals 'publish' * @param string $entity_type Equals 'object' * @param ElggEntity $entity Published entity */ function send_custom_notifications($event, $entity_type, $entity) { if ($entity->origin !== 'wall') { return true; } // We only want to notify about wire posts and wall posts, all content created therewith is implied $accepted_subtypes = array('hjwall', 'thewire'); if (!in_array($entity->getSubtype(), $accepted_subtypes)) { return true; } $poster = $entity->getOwnerEntity(); $container = $entity->getContainerEntity(); $message = format_wall_message($entity, true); $sent = array(elgg_get_logged_in_user_guid(), $poster->guid, $container->guid); // Notify wall owner if ($poster->guid !== $container->guid && elgg_instanceof($container, 'user')) { $to = $container->guid; $from = $poster->guid; $target = elgg_echo("wall:target:{$entity->getSubtype()}"); $ownership = elgg_echo('wall:ownership:your', array($target)); $subject = elgg_echo('wall:new:notification:subject', array($poster->name, $ownership)); $summary = elgg_view('output/url', array('text' => $subject, 'href' => $entity->getURL())); $body = elgg_echo('wall:new:notification:message', array($poster->name, $ownership, $message, $entity->getURL())); notify_user($to, $from, $subject, $body, array('summary' => $summary, 'object' => $entity, 'action' => 'received')); } // Notify tagged users $tagged_friends = get_tagged_friends($entity); foreach ($tagged_friends as $tagged_friend) { // user tagged herself or the wall owner if ($tagged_friend->guid == $poster->guid || $tagged_friend->guid == $container->guid || in_array($tagged_friend->guid, $sent)) { continue; } $sent[] = $tagged_friend->guid; $to = $tagged_friend->guid; $from = $poster->guid; $subject = elgg_echo('wall:tagged:notification:subject', array($poster->name)); $summary = elgg_view('output/url', array('text' => $subject, 'href' => $entity->getURL())); $body = elgg_echo('wall:tagged:notification:message', array($poster->name, $message, $entity->getURL())); notify_user($to, $from, $subject, $body, array('summary' => $summary, 'object' => $entity, 'action' => 'tagged')); } return true; }
/** * Request user validation email. * Send email out to the address and request a confirmation. * * @param int $user_guid The user's GUID * @param bool $admin_requested Was it requested by admin * @return mixed */ function uservalidationbyemail_request_validation($user_guid, $admin_requested = FALSE) { $site = elgg_get_site_entity(); $user_guid = (int) $user_guid; $user = get_entity($user_guid); if ($user && $user instanceof ElggUser) { // Work out validate link $code = uservalidationbyemail_generate_code($user_guid, $user->email); $link = "{$site->url}uservalidationbyemail/confirm?u={$user_guid}&c={$code}"; // Send validation email $subject = elgg_echo('email:validate:subject', array($user->name, $site->name)); $body = elgg_echo('email:validate:body', array($user->name, $site->name, $link, $site->name, $site->url)); $result = notify_user($user->guid, $site->guid, $subject, $body, array(), 'email'); if ($result && !$admin_requested) { system_message(elgg_echo('uservalidationbyemail:registerok')); } return $result; } return FALSE; }