Ejemplo n.º 1
0
/**
 * 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;
}
Ejemplo n.º 2
0
 * @uses $vars['include_address'] Include attached URL address
 */
namespace hypeJunction\Wall;

$entity = elgg_extract('entity', $vars);
/* @var ElggEntity $entity */
if (!elgg_instanceof($entity)) {
    return true;
}
$status = elgg_view('output/longtext', ['value' => $entity->description]);
if (elgg_view_exists('output/linkify')) {
    $status = elgg_view('output/linkify', array('value' => $status));
}
$message = array($status);
$address = $entity->address;
if ($address) {
    $include_address = elgg_extract('include_address', $vars, strpos($status, $address) === false) || !$status;
    if ($include_address) {
        $message[] = elgg_view('output/url', array('href' => $address, 'class' => 'wall-attached-url'));
    }
}
$tagged_friends = get_tagged_friends($entity, 'links');
if ($tagged_friends) {
    $message[] = elgg_format_element('span', array('class' => 'wall-tagged-friends'), elgg_echo('wall:with', array(implode(', ', $tagged_friends))));
}
$location = $entity->getLocation();
if ($location) {
    $location = elgg_view('output/wall/location', array('value' => $location));
    $message[] = elgg_format_element('span', array('class' => 'wall-tagged-location'), elgg_echo('wall:at', array($location)));
}
echo implode(' ', $message);