/**
  * 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);
     }
 }
Example #2
0
/**
 * 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);
    }
}
Example #3
0
<?php

$user = elgg_extract("user", $vars);
$NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethods();
$notification_settings = thewire_tools_get_notification_settings($user->getGUID());
$content = "<tr>";
$content .= "<td class='namefield'>";
$content .= elgg_view("output/longtext", array("value" => elgg_echo("thewire_tools:settings:description")));
$content .= "</td>";
$i = 0;
foreach ($NOTIFICATION_HANDLERS as $method) {
    $checkbox_settings = array("id" => "thewire_tools_" . $method . "_checkbox", "name" => "thewire_tools_" . $method, "value" => $method, "onclick" => "adjust" . $method . "('thewire_tools_" . $method . "')");
    if (in_array($method, $notification_settings)) {
        $checkbox_settings["checked"] = true;
    }
    if ($i > 0) {
        $content .= "<td class='spacercolumn'>&nbsp;</td>";
    }
    $content .= "<td class='" . $method . "togglefield'>";
    $content .= elgg_view("output/url", array("border" => "0", "id" => "thewire_tools_" . $method, "class" => $method . "toggleOff", "onclick" => "adjust" . $method . "_alt('thewire_tools_" . $method . "')", "text" => elgg_view("input/checkbox", $checkbox_settings)));
    $content .= "</td>";
    $i++;
}
$content .= "<td>&nbsp;</td>";
$content .= "</tr>";
echo "<table id='thewire-tools-notification-settings' class='hidden'>";
echo $content;
echo "</table>";
?>
<script type="text/javascript">
	var cs_content = $('#thewire-tools-notification-settings tr:first').html();