Example #1
0
 /**
  * Get the subscribers for a new group which needs admin approval
  *
  * @param string $hook         the name of the hook
  * @param string $type         the type of the hook
  * @param array  $return_value current return value
  * @param array  $params       supplied params
  *
  * @return void|array
  */
 public static function adminApprovalSubs($hook, $type, $return_value, $params)
 {
     $event = elgg_extract('event', $params);
     if (!$event instanceof \Elgg\Notifications\Event) {
         return;
     }
     $group = $event->getObject();
     if (!$group instanceof \ElggGroup) {
         return;
     }
     $action = $event->getAction();
     if ($action !== 'admin_approval') {
         return;
     }
     // get all admins
     $dbprefix = elgg_get_config('dbprefix');
     $batch = new \ElggBatch('elgg_get_entities', ['type' => 'user', 'joins' => ["JOIN {$dbprefix}users_entity ue ON e.guid = ue.guid"], 'wheres' => ['ue.admin = "yes"']]);
     /* @var $user \ElggUser */
     foreach ($batch as $user) {
         $notification_settings = get_user_notification_settings($user->getGUID());
         if (empty($notification_settings)) {
             continue;
         }
         $return_value[$user->getGUID()] = [];
         foreach ($notification_settings as $method => $active) {
             if (!$active) {
                 continue;
             }
             $return_value[$user->getGUID()][] = $method;
         }
     }
     return $return_value;
 }
Example #2
0
/**
 * Notify a user via their preferences.
 *
 * @param mixed $to Either a guid or an array of guid's to notify.
 * @param int $from GUID of the sender, which may be a user, site or object.
 * @param string $subject Message subject.
 * @param string $message Message body.
 * @param array $params Misc additional parameters specific to various methods.
 * @param mixed $methods_override A string, or an array of strings specifying the delivery methods to use - or leave blank
 * 				for delivery using the user's chosen delivery methods.
 * @return array Compound array of each delivery user/delivery method's success or failure.
 * @throws NotificationException
 */
function notify_user($to, $from, $subject, $message, array $params = NULL, $methods_override = "")
{
    global $NOTIFICATION_HANDLERS, $CONFIG;
    // Sanitise
    if (!is_array($to)) {
        $to = array((int) $to);
    }
    $from = (int) $from;
    //$subject = sanitise_string($subject);
    // Get notification methods
    if ($methods_override && !is_array($methods_override)) {
        $methods_override = array($methods_override);
    }
    $result = array();
    foreach ($to as $guid) {
        // Results for a user are...
        $result[$guid] = array();
        if ($guid) {
            // Is the guid > 0?
            // Are we overriding delivery?
            $methods = $methods_override;
            if (!$methods) {
                $tmp = (array) get_user_notification_settings($guid);
                $methods = array();
                foreach ($tmp as $k => $v) {
                    if ($v) {
                        $methods[] = $k;
                    }
                }
                // Add method if method is turned on for user!
            }
            if ($methods) {
                // Deliver
                foreach ($methods as $method) {
                    // Extract method details from list
                    $details = $NOTIFICATION_HANDLERS[$method];
                    $handler = $details->handler;
                    if (!$NOTIFICATION_HANDLERS[$method] || !$handler) {
                        error_log(sprintf(elgg_echo('NotificationException:NoHandlerFound'), $method));
                    }
                    if ($CONFIG->debug) {
                        error_log("Sending message to {$guid} using {$method}");
                    }
                    // Trigger handler and retrieve result.
                    try {
                        $result[$guid][$method] = $handler($from ? get_entity($from) : NULL, get_entity($guid), $subject, $message, $params);
                    } catch (Exception $e) {
                        error_log($e->getMessage());
                    }
                }
            }
        }
    }
    return $result;
}
 /**
  * Add a discussion owner to the notified users
  *
  * @param string $hook         the name of the hook
  * @param stirng $type         the type of the hook
  * @param array  $return_value the current return value
  * @param array  $params       supplied values
  *
  * @return void|array
  */
 public static function addDiscussionOwner($hook, $type, $return_value, $params)
 {
     if (empty($params) || !is_array($params)) {
         return;
     }
     $event = elgg_extract('event', $params);
     if (!$event instanceof \Elgg\Notifications\Event) {
         return;
     }
     $discussion_reply = $event->getObject();
     if (!$discussion_reply instanceof \ElggDiscussionReply) {
         return;
     }
     $discussion = $discussion_reply->getContainerEntity();
     if (!elgg_instanceof($discussion, 'object', 'discussion')) {
         return;
     }
     $owner = $discussion->getOwnerEntity();
     if (!$owner instanceof \ElggUser) {
         return;
     }
     $user_notification_settings = get_user_notification_settings($owner->getGUID());
     if (empty($user_notification_settings)) {
         // user has no settings, so no notification
         return;
     }
     $temp = [];
     foreach ($user_notification_settings as $method => $enabled) {
         if (empty($enabled)) {
             // notification method not enabled
             continue;
         }
         $temp[] = $method;
     }
     if (empty($temp)) {
         // no enabled notification methods
         return;
     }
     $return_value[$owner->getGUID()] = $temp;
     return $return_value;
 }
Example #4
0
<?php

/**
 * User settings for notifications.
 * 
 * @package Elgg
 * @subpackage Core
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Curverider Ltd
 * @copyright Curverider Ltd 2008-2009
 * @link http://elgg.org/
 */
global $NOTIFICATION_HANDLERS;
$notification_settings = get_user_notification_settings(page_owner());
?>
	<h3><?php 
echo elgg_echo('notifications:usersettings');
?>
</h3>
	
	<p><?php 
echo elgg_echo('notifications:methods');
?>
	
	<table>
<?php 
// Loop through options
foreach ($NOTIFICATION_HANDLERS as $k => $v) {
    ?>
			<tr>
				<td><?php 
Example #5
0
/**
 * Add the owner of the content being commented on to the subscribers
 *
 * @param string $hook        'get'
 * @param string $type        'subscribers'
 * @param array  $returnvalue current subscribers
 * @param array  $params      supplied params
 *
 * @return void|array
 *
 * @access private
 */
function _elgg_comments_add_content_owner_to_subscriptions($hook, $type, $returnvalue, $params)
{
    $event = elgg_extract('event', $params);
    if (!$event instanceof \Elgg\Notifications\Event) {
        return;
    }
    $object = $event->getObject();
    if (!elgg_instanceof($object, 'object', 'comment')) {
        // can't use instanceof ElggComment as discussion replies inherit
        return;
    }
    $content_owner = $object->getContainerEntity()->getOwnerEntity();
    if (!$content_owner instanceof ElggUser) {
        return;
    }
    $notification_settings = get_user_notification_settings($content_owner->getGUID());
    if (empty($notification_settings)) {
        return;
    }
    $returnvalue[$content_owner->getGUID()] = [];
    foreach ($notification_settings as $method => $enabled) {
        if (empty($enabled)) {
            continue;
        }
        $returnvalue[$content_owner->getGUID()][] = $method;
    }
    return $returnvalue;
}
Example #6
0
function zhsite_send_email_to_user($to_user, $subject, $message, $is_notificiation)
{
    if ($is_notificiation) {
        if ($notification_settings = get_user_notification_settings($to_user->guid)) {
            if (!$notification_settings->email) {
                return false;
            }
        } else {
            elgg_log("ZHError ,zhsite_send_email_to_user, error calling get_user_notification_settings, to_user_id {$to_user->guid}, " . "logged_user_id " . elgg_get_logged_in_user_guid(), "ERROR");
            return false;
        }
    }
    $end = zhaohuEmailUnsubEnd(null, $to_user->guid, $is_notificiation, false);
    $to_email = $to_user->name . "<" . $to_user->email . ">";
    return zhgroups_send_email(elgg_get_site_entity()->name, $to_email, $subject, $message, $end);
}
Example #7
0
<?php

/**
 * Elgg notifications user preference save acion.
 *
 * @package Elgg
 * @subpackage Core
 */
$method = get_input('method');
$current_settings = get_user_notification_settings();
$result = false;
foreach ($method as $k => $v) {
    // check if setting has changed and skip if not
    if ($current_settings->{$k} == ($v == 'yes')) {
        continue;
    }
    $result = set_user_notification_setting(elgg_get_logged_in_user_guid(), $k, $v == 'yes' ? true : false);
    if (!$result) {
        register_error(elgg_echo('notifications:usersettings:save:fail'));
    }
}
if ($result) {
    system_message(elgg_echo('notifications:usersettings:save:ok'));
}
Example #8
0
?>
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td class="namefield">
			<p>
				<?php 
echo elgg_echo('notifications:subscriptions:personal:description');
?>
			</p>
		</td>

<?php 
$fields = '';
$i = 0;
$notification_settings = get_user_notification_settings($user->guid);
if (!$notification_settings) {
    elgg_log("Error get_user_notification_settings for user {$user->guid}", "ERROR");
}
foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
    if ($notification_settings->{$method}) {
        $personalchecked[$method] = 'checked="checked"';
    } else {
        $personalchecked[$method] = '';
    }
    if ($i > 0) {
        $fields .= "<td class='spacercolumn'>&nbsp;</td>";
    }
    $fields .= <<<END
\t\t<td class="{$method}togglefield">
\t\t<a  border="0" id="{$method}personal" class="{$method}toggleOff" onclick="adjust{$method}_alt('{$method}personal');">
Example #9
0
<?php

/**
 * User settings for notifications.
 *
 * @package Elgg
 * @subpackage Core
 */
global $NOTIFICATION_HANDLERS;
$notification_settings = get_user_notification_settings(elgg_get_page_owner_guid());
$title = elgg_echo('notifications:usersettings');
$rows = '';
// Loop through options
foreach ($NOTIFICATION_HANDLERS as $k => $v) {
    if ($notification_settings->{$k}) {
        $val = "yes";
    } else {
        $val = "no";
    }
    $radio = elgg_view('input/radio', array('name' => "method[{$k}]", 'value' => $val, 'options' => array(elgg_echo('option:yes') => 'yes', elgg_echo('option:no') => 'no')));
    $cells = '<td class="prm pbl">' . elgg_echo("notification:method:{$k}") . ': </td>';
    $cells .= "<td>{$radio}</td>";
    $rows .= "<tr>{$cells}</tr>";
}
$content = elgg_echo('notifications:methods');
$content .= "<table>{$rows}</table>";
echo elgg_view_module('info', $title, $content);
Example #10
0
File: start.php Project: elgg/elgg
/**
 * Add temporary subscription for original poster if not already registered to
 * receive a notification of reply
 *
 * @param string $hook          Hook name
 * @param string $type          Hook type
 * @param array  $subscriptions Subscriptions for a notification event
 * @param array  $params        Parameters including the event
 * @return array
 */
function thewire_add_original_poster($hook, $type, $subscriptions, $params)
{
    $event = $params['event'];
    $entity = $event->getObject();
    if ($entity && elgg_instanceof($entity, 'object', 'thewire')) {
        $parent = $entity->getEntitiesFromRelationship(array('relationship' => 'parent'));
        if ($parent) {
            $parent = $parent[0];
            // do not add a subscription if reply was to self
            if ($parent->getOwnerGUID() !== $entity->getOwnerGUID()) {
                if (!array_key_exists($parent->getOwnerGUID(), $subscriptions)) {
                    $personal_methods = (array) get_user_notification_settings($parent->getOwnerGUID());
                    $methods = array();
                    foreach ($personal_methods as $method => $state) {
                        if ($state) {
                            $methods[] = $method;
                        }
                    }
                    if ($methods) {
                        $subscriptions[$parent->getOwnerGUID()] = $methods;
                        return $subscriptions;
                    }
                }
            }
        }
    }
}
Example #11
0
/**
 * Get the subscription methods of the user
 *
 * @param int $user_guid the user_guid to check (default: current user)
 *
 * @return array
 */
function thewire_tools_get_notification_settings($user_guid = 0)
{
    $user_guid = sanitise_int($user_guid, false);
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (empty($user_guid)) {
        return array();
    }
    if (elgg_is_active_plugin("notifications")) {
        $saved = elgg_get_plugin_user_setting("notification_settings_saved", $user_guid, "thewire_tools");
        if (!empty($saved)) {
            $settings = elgg_get_plugin_user_setting("notification_settings", $user_guid, "thewire_tools");
            if (!empty($settings)) {
                return string_to_tag_array($settings);
            }
            return array();
        }
    }
    // default elgg settings
    $settings = get_user_notification_settings($user_guid);
    if (!empty($settings)) {
        $settings = (array) $settings;
        $res = array();
        foreach ($settings as $method => $value) {
            if (!empty($value)) {
                $res[] = $method;
            }
        }
        return $res;
    }
    return array();
}
		<td>&nbsp;</td>
	</tr>
	<tr>
		<td class="namefield">
			<p>
				<?php 
echo elgg_echo('notifications:subscriptions:personal:description');
?>
			</p>
		</td>

<?php 
$fields = '';
$i = 0;
foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
    if ($notification_settings = get_user_notification_settings(elgg_get_logged_in_user_guid())) {
        if ($notification_settings->{$method}) {
            $personalchecked[$method] = 'checked="checked"';
        } else {
            $personalchecked[$method] = '';
        }
    }
    if ($i > 0) {
        $fields .= "<td class='spacercolumn'>&nbsp;</td>";
    }
    $fields .= <<<END
\t\t<td class="{$method}togglefield">
\t\t<a  border="0" id="{$method}personal" class="{$method}toggleOff" onclick="adjust{$method}_alt('{$method}personal');">
\t\t<input type="checkbox" name="{$method}personal" id="{$method}checkbox" onclick="adjust{$method}('{$method}personal');" value="1" {$personalchecked[$method]} /></a></td>
END;
    $i++;
Example #13
0
/**
 * Get the subscribers to the creation of a support ticket
 *
 * @param string $hook         the name of the hook
 * @param string $type         the type of the hook
 * @param array  $return_value current return value
 * @param array  $params       supplied params
 *
 * @return array
 */
function user_support_get_subscriptions_support_ticket_hook($hook, $type, $return_value, $params)
{
    if (empty($params) || !is_array($params)) {
        return $return_value;
    }
    $event = elgg_extract("event", $params);
    if (empty($event) || !$event instanceof Elgg_Notifications_Event) {
        return $return_value;
    }
    // ignore access
    $ia = elgg_set_ignore_access(true);
    // get object
    $object = $event->getObject();
    if (empty($object) || !elgg_instanceof($object, "object", UserSupportTicket::SUBTYPE)) {
        elgg_set_ignore_access($ia);
        return $return_value;
    }
    // by default notify nobody
    $return_value = array();
    // get all the admins to notify
    $users = user_support_get_admin_notify_users($object);
    if (empty($users) || !is_array($users)) {
        elgg_set_ignore_access($ia);
        return $return_value;
    }
    // pass all the guids of the admins/staff
    foreach ($users as $user) {
        $notification_settings = get_user_notification_settings($user->getGUID());
        if (empty($notification_settings)) {
            continue;
        }
        $methods = array();
        foreach ($notification_settings as $method => $subbed) {
            if ($subbed) {
                $methods[] = $method;
            }
        }
        if (!empty($methods)) {
            $return_value[$user->getGUID()] = $methods;
        }
    }
    // restore access
    elgg_set_ignore_access($ia);
    return $return_value;
}
if (!$group instanceof ElggGroup) {
    register_error(elgg_echo('error:missing_data'));
    forward(REFERER);
}
$user = elgg_get_logged_in_user_entity();
$notifications_enabled = \ColdTrick\GroupTools\Membership::notificationsEnabledForGroup($user, $group);
if ($notifications_enabled) {
    // user has notifications enabled, but wishes to disable this
    $NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethodsAsDeprecatedGlobal();
    foreach ($NOTIFICATION_HANDLERS as $method => $dummy) {
        elgg_remove_subscription($user->getGUID(), $method, $group->getGUID());
    }
    system_message(elgg_echo('group_tools:action:toggle_notifications:disabled', [$group->name]));
} else {
    // user has no notification settings for this group and wishes to enable this
    $user_settings = get_user_notification_settings($user->getGUID());
    $supported_notifications = ['site', 'email'];
    $found = [];
    if (!empty($user_settings)) {
        // check current user settings
        foreach ($user_settings as $method => $value) {
            if (!in_array($method, $supported_notifications)) {
                continue;
            }
            if (!empty($value)) {
                $found[] = $method;
            }
        }
    }
    // user has no base nofitication settings
    if (empty($found)) {
Example #15
0
 /**
  * Add answer owner to the subscribers for an answer
  *
  * @param string $hook         the name of the hook
  * @param string $type         the type of the hook
  * @param array  $return_value current return value
  * @param array  $params       supplied params
  *
  * @return void|array
  */
 public static function addAnswerOwnerToAnswerSubscribers($hook, $type, $return_value, $params)
 {
     $event = elgg_extract('event', $params);
     if (!$event instanceof \Elgg\Notifications\Event) {
         return;
     }
     $answer = $event->getObject();
     if (!$answer instanceof \ElggAnswer) {
         return;
     }
     $owner = $answer->getOwnerEntity();
     $methods = get_user_notification_settings($owner->getGUID());
     if (empty($methods)) {
         return;
     }
     $filtered_methods = [];
     foreach ($methods as $method => $value) {
         if (empty($value)) {
             continue;
         }
         $filtered_methods[] = $method;
     }
     if (empty($filtered_methods)) {
         return;
     }
     $return_value[$owner->getGUID()] = $filtered_methods;
     return $return_value;
 }
Example #16
0
}
$username = elgg_extract("username", $vars);
$notifications = array(true, false);
$targetUser = get_user_by_username($username);
if (!$targetUser) {
    register_error(elgg_echo("profile:notfound"));
    forward();
}
if (isset($targetUser->notifications)) {
    for ($i = 0; $i < max(count($targetUser->notifications), count($notifications)); $i++) {
        $notifications[$i] = $targetUser->notifications[$i] != "0";
    }
}
$groups = rijkshuisstijl_get_featured_groups();
$interests = rijkshuisstijl_get_interests($targetUser);
$notificationSettings = get_user_notification_settings($targetUser->guid);
/* will recode to use entitiesfromrelationship later
  $interests = $user->getEntitiesFromRelationship(array(
    'type' => 'group',
    'relationship' => 'interests'
  ));*/
?>

<script type="text/javascript">
  var gUsername = '******';
  var gUserGuid = '<?php 
echo $targetUser->guid;
?>
Example #17
0
  </tr>
  <tr>
    <td class="namefield">
    	<p>
    		<?php 
echo elgg_echo('notifications:subscriptions:personal:description');
?>
    	</p>
    	
    </td>
    
<?php 
$fields = '';
$i = 0;
foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
    if ($notification_settings = get_user_notification_settings($vars['user']->guid)) {
        if ($notification_settings->{$method}) {
            $personalchecked[$method] = 'checked="checked"';
        } else {
            $personalchecked[$method] = '';
        }
    }
    if ($i > 0) {
        $fields .= "<td class=\"spacercolumn\">&nbsp;</td>";
    }
    $fields .= <<<END
\t\t\t    <td class="{$method}togglefield">
\t\t\t    <a  border="0" id="{$method}personal" class="{$method}toggleOff" onclick="adjust{$method}_alt('{$method}personal');">
\t\t\t    <input type="checkbox" name="{$method}personal" id="{$method}checkbox" onclick="adjust{$method}('{$method}personal');" value="1" {$personalchecked[$method]} /></a></td>
END;
    $i++;
$entity = get_entity($entity_guid);
if (!$entity) {
    register_error(elgg_echo("generic_comment:notfound"));
    forward(REFERER);
}
$user = elgg_get_logged_in_user_entity();
$annotation = create_annotation($entity->getGUID(), "generic_comment", $comment_text, "", $user->getGUID(), $entity->access_id);
// tell user annotation posted
if (!$annotation) {
    register_error(elgg_echo("generic_comment:failure"));
    forward(REFERER);
}
// notify if poster wasn't owner
if ($entity->getOwnerGUID() != $user->getGUID()) {
    // get the notification settings for the owner
    $notification_settings = (array) get_user_notification_settings($entity->getOwnerGUID());
    if (!empty($notification_settings)) {
        // loop through the preferences
        foreach ($notification_settings as $method => $enabled) {
            if ($enabled) {
                if ($method == "email") {
                    // send special (short) message
                    notify_user($entity->getOwnerGUID(), $user->getGUID(), elgg_echo("generic_comment:email:subject"), elgg_echo("advanced_notifications:notification:email:body", array($entity->getURL())), null, $method);
                } else {
                    // send the normal message
                    notify_user($entity->getOwnerGUID(), $user->getGUID(), elgg_echo("generic_comment:email:subject"), elgg_echo("generic_comment:email:body", array($entity->title, $user->name, $comment_text, $entity->getURL(), $user->name, $user->getURL())), null, $method);
                }
            }
        }
    }
}
Example #19
0
/**
 * Send a message to specified recipients
 *
 * @param int $sender_guid GUID of the sender entity
 * @param array $recipient_guids An array of recipient GUIDs
 * @param str $subject Subject of the message
 * @param str $message Body of the message
 * @param str $message_type Type of the message
 * @param array $params Additional parameters, e.g. 'message_hash', 'attachments'
 * @return boolean
 */
function hj_inbox_send_message($sender_guid, $recipient_guids, $subject = '', $message = '', $message_type = '', array $params = array())
{
    $ia = elgg_set_ignore_access();
    if (!is_array($recipient_guids)) {
        $recipient_guids = array($recipient_guids);
    }
    if (isset($params['message_hash'])) {
        $message_hash = elgg_extract('message_hash', $params);
    }
    if (isset($params['attachments'])) {
        $attachments = elgg_extract('attachments', $params);
    }
    $user_guids = $recipient_guids;
    $user_guids[] = $sender_guid;
    sort($user_guids);
    if (!$message_hash) {
        $title = strtolower($subject);
        $title = trim(str_replace('re:', '', $title));
        $message_hash = sha1(implode(':', $user_guids) . $title);
    }
    $acl_hash = sha1(implode(':', $user_guids));
    $dbprefix = elgg_get_config('dbprefix');
    $query = "SELECT * FROM {$dbprefix}access_collections WHERE name = '{$acl_hash}'";
    $collection = get_data_row($query);
    //error_log(print_r($collection, true));
    $acl_id = $collection->id;
    if (!$acl_id) {
        $site = elgg_get_site_entity();
        $acl_id = create_access_collection($acl_hash, $site->guid);
        update_access_collection($acl_id, $user_guids);
    }
    //error_log($acl_id);
    $message_sent = new ElggObject();
    $message_sent->subtype = "messages";
    $message_sent->owner_guid = $sender_guid;
    $message_sent->container_guid = $sender_guid;
    $message_sent->access_id = ACCESS_PRIVATE;
    $message_sent->title = $subject;
    $message_sent->description = $message;
    $message_sent->toId = $recipient_guids;
    // the users receiving the message
    $message_sent->fromId = $sender_guid;
    // the user sending the message
    $message_sent->readYet = 1;
    // this is a toggle between 0 / 1 (1 = read)
    $message_sent->hiddenFrom = 0;
    // this is used when a user deletes a message in their sentbox, it is a flag
    $message_sent->hiddenTo = 0;
    // this is used when a user deletes a message in their inbox
    $message_sent->msg = 1;
    $message_sent->msgType = $message_type;
    $message_sent->msgHash = $message_hash;
    $message_sent->save();
    if ($attachments) {
        $count = count($attachments['name']);
        for ($i = 0; $i < $count; $i++) {
            if ($attachments['error'][$i] || !$attachments['name'][$i]) {
                continue;
            }
            $name = $attachments['name'][$i];
            $file = new ElggFile();
            $file->container_guid = $message_sent->guid;
            $file->title = $name;
            $file->access_id = (int) $acl_id;
            $prefix = "file/";
            $filestorename = elgg_strtolower(time() . $name);
            $file->setFilename($prefix . $filestorename);
            $file->open("write");
            $file->close();
            move_uploaded_file($attachments['tmp_name'][$i], $file->getFilenameOnFilestore());
            $saved = $file->save();
            if ($saved) {
                $mime_type = ElggFile::detectMimeType($attachments['tmp_name'][$i], $attachments['type'][$i]);
                $info = pathinfo($name);
                $office_formats = array('docx', 'xlsx', 'pptx');
                if ($mime_type == "application/zip" && in_array($info['extension'], $office_formats)) {
                    switch ($info['extension']) {
                        case 'docx':
                            $mime_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                            break;
                        case 'xlsx':
                            $mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                            break;
                        case 'pptx':
                            $mime_type = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
                            break;
                    }
                }
                // check for bad ppt detection
                if ($mime_type == "application/vnd.ms-office" && $info['extension'] == "ppt") {
                    $mime_type = "application/vnd.ms-powerpoint";
                }
                $file->msgHash = $message_hash;
                $file->toId = $recipient_guids;
                $file->fromId = $sender_guid;
                $file->setMimeType($mime_type);
                $file->originalfilename = $name;
                if (elgg_is_active_plugin('file')) {
                    $file->simpletype = file_get_simple_type($mime_type);
                }
                $file->save();
                $guid = $file->getGUID();
                $uploaded_attachments[] = $guid;
                $attachment_urls .= '<div class="inbox-attachment">' . elgg_view('output/url', array('href' => "messages/download/{$guid}", 'text' => $file->title, 'is_trusted' => true)) . '</div>';
                if ($file->simpletype == "image") {
                    $file->icontime = time();
                    $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
                    if ($thumbnail) {
                        $thumb = new ElggFile();
                        $thumb->setMimeType($attachments['type'][$i]);
                        $thumb->setFilename($prefix . "thumb" . $filestorename);
                        $thumb->open("write");
                        $thumb->write($thumbnail);
                        $thumb->close();
                        $file->thumbnail = $prefix . "thumb" . $filestorename;
                        unset($thumbnail);
                    }
                    $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
                    if ($thumbsmall) {
                        $thumb->setFilename($prefix . "smallthumb" . $filestorename);
                        $thumb->open("write");
                        $thumb->write($thumbsmall);
                        $thumb->close();
                        $file->smallthumb = $prefix . "smallthumb" . $filestorename;
                        unset($thumbsmall);
                    }
                    $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
                    if ($thumblarge) {
                        $thumb->setFilename($prefix . "largethumb" . $filestorename);
                        $thumb->open("write");
                        $thumb->write($thumblarge);
                        $thumb->close();
                        $file->largethumb = $prefix . "largethumb" . $filestorename;
                        unset($thumblarge);
                    }
                }
            }
        }
    }
    $success = $error = 0;
    foreach ($recipient_guids as $recipient_guid) {
        $message_to = new ElggObject();
        $message_to->subtype = "messages";
        $message_to->owner_guid = $recipient_guid;
        $message_to->container_guid = $recipient_guid;
        $message_to->access_id = ACCESS_PRIVATE;
        $message_to->title = $subject;
        $message_to->description = $message;
        $message_to->toId = $recipient_guids;
        // the users receiving the message
        $message_to->fromId = $sender_guid;
        // the user sending the message
        $message_to->readYet = 0;
        // this is a toggle between 0 / 1 (1 = read)
        $message_to->hiddenFrom = 0;
        // this is used when a user deletes a message in their sentbox, it is a flag
        $message_to->hiddenTo = 0;
        // this is used when a user deletes a message in their inbox
        $message_to->msg = 1;
        $message_to->msgType = $message_type;
        $message_to->msgHash = $message_hash;
        if ($message_to->save()) {
            $success++;
            // Make attachments
            if ($uploaded_attachments) {
                foreach ($uploaded_attachments as $attachment_guid) {
                    make_attachment($message_to->guid, $attachment_guid);
                }
            }
            // Send out notifications skipping 'site' notification handler
            if ($recipient_guid != $sender_guid) {
                $methods = (array) get_user_notification_settings($recipient_guid);
                unset($methods['site']);
                if (count($methods)) {
                    $recipient = get_user($recipient_guid);
                    $sender = get_user($sender_guid);
                    $notification_subject = elgg_echo('messages:email:subject');
                    $notification_message = strip_tags($message);
                    if ($uploaded_attachments) {
                        $notification_message .= elgg_view_module('inbox-attachments', elgg_echo('messages:attachments'), $attachment_urls);
                    }
                    $notification_body = elgg_echo('messages:email:body', array($sender->name, $notification_message, elgg_get_site_url() . "messages/inbox/{$recipient->username}?message_type={$message_type}", $sender->name, elgg_get_site_url() . "messages/thread/{$message_hash}"));
                    notify_user($recipient_guid, $sender_guid, $notification_subject, $notification_body, null, $methods);
                }
            }
        } else {
            $error++;
        }
    }
    if ($success > 0) {
        // Make attachments
        if ($uploaded_attachments) {
            foreach ($uploaded_attachments as $attachment_guid) {
                make_attachment($message_sent->guid, $attachment_guid);
            }
        }
        $return = true;
    } else {
        $message_sent->delete();
        $return = false;
    }
    elgg_set_ignore_access($ia);
    return $return;
}
/**
 * Get the subscription methods of the user
 *
 * @param int $user_guid the user_guid to check (default: current user)
 *
 * @return array
 */
function content_subscriptions_get_notification_settings($user_guid = 0)
{
    static $user_cache;
    $user_guid = sanitise_int($user_guid, false);
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (empty($user_guid)) {
        return [];
    }
    if (!isset($user_cache)) {
        $user_cache = [];
    }
    if (!isset($user_cache[$user_guid])) {
        $user_cache[$user_guid] = [];
        $checked = false;
        if (elgg_is_active_plugin('notifications')) {
            $saved = elgg_get_plugin_user_setting('notification_settings_saved', $user_guid, 'content_subscriptions');
            if (!empty($saved)) {
                $checked = true;
                $settings = elgg_get_plugin_user_setting('notification_settings', $user_guid, 'content_subscriptions');
                if (!empty($settings)) {
                    $user_cache[$user_guid] = string_to_tag_array($settings);
                }
            }
        }
        if (!$checked) {
            // default elgg settings
            $settings = get_user_notification_settings($user_guid);
            if (!empty($settings)) {
                $settings = (array) $settings;
                foreach ($settings as $method => $value) {
                    if (!empty($value)) {
                        $user_cache[$user_guid][] = $method;
                    }
                }
            }
        }
    }
    return $user_cache[$user_guid];
}
Example #21
0
File: Model.php Project: n8b/VMN
 /**
  * Get message types the user can receive
  *
  * @param ElggUser $user User
  * @return array An array of message types
  */
 public function getIncomingMessageTypes($user = null)
 {
     $return = array();
     if (!elgg_instanceof($user)) {
         $user = elgg_get_logged_in_user_entity();
         if (!$user) {
             return $return;
         }
     }
     if (isset($this->incomingMessageTypes[$user->guid])) {
         return $this->incomingMessageTypes[$user->guid];
     }
     $message_types = $this->config->getMessageTypes();
     $user_types = $this->config->getUserTypes();
     foreach ($message_types as $type => $options) {
         if ($type == Config::TYPE_NOTIFICATION) {
             $methods = get_user_notification_settings($user->guid);
             if (!$methods || !isset($methods->site)) {
                 continue;
             }
         }
         $policies = $options['policy'];
         if (!$policies) {
             $return[] = $type;
             continue;
         }
         foreach ($policies as $policy) {
             $recipient_type = $policy['recipient'];
             if ($recipient_type == 'all') {
                 $return[] = $type;
                 break;
             }
             $validator = $user_types[$recipient_type]['validator'];
             if (is_callable($validator) && call_user_func($validator, $user, $recipient_type)) {
                 $return[] = $type;
                 break;
             }
         }
     }
     $this->incomingMessageTypes[$user->guid] = $return;
     return $return;
 }
Example #22
0
/**
 * Save personal notification settings - input comes from request
 *
 * @return void
 * @access private
 */
function _elgg_save_notification_user_settings()
{
    $method = get_input('method');
    $current_settings = get_user_notification_settings();
    $result = false;
    foreach ($method as $k => $v) {
        // check if setting has changed and skip if not
        if ($current_settings->{$k} == ($v == 'yes')) {
            continue;
        }
        $result = set_user_notification_setting(elgg_get_logged_in_user_guid(), $k, $v == 'yes' ? true : false);
        if (!$result) {
            register_error(elgg_echo('notifications:usersettings:save:fail'));
        }
    }
    if ($result) {
        system_message(elgg_echo('notifications:usersettings:save:ok'));
    }
}
Example #23
0
/**
 * Notify a user via their preferences.
 *
 * @param mixed  $to               Either a guid or an array of guid's to notify.
 * @param int    $from             GUID of the sender, which may be a user, site or object.
 * @param string $subject          Message subject.
 * @param string $message          Message body.
 * @param array  $params           Misc additional parameters specific to various methods.
 * @param mixed  $methods_override A string, or an array of strings specifying the delivery
 *                                 methods to use - or leave blank for delivery using the
 *                                 user's chosen delivery methods.
 *
 * @return array Compound array of each delivery user/delivery method's success or failure.
 * @access private
 */
function _elgg_notify_user($to, $from, $subject, $message, array $params = null, $methods_override = "")
{
    $notify_service = _elgg_services()->notifications;
    // Sanitise
    if (!is_array($to)) {
        $to = array((int) $to);
    }
    $from = (int) $from;
    //$subject = sanitise_string($subject);
    // Get notification methods
    if ($methods_override && !is_array($methods_override)) {
        $methods_override = array($methods_override);
    }
    $result = array();
    foreach ($to as $guid) {
        // Results for a user are...
        $result[$guid] = array();
        if ($guid) {
            // Is the guid > 0?
            // Are we overriding delivery?
            $methods = $methods_override;
            if (!$methods) {
                $tmp = get_user_notification_settings($guid);
                $methods = array();
                // $tmp may be false. don't cast
                if (is_object($tmp)) {
                    foreach ($tmp as $k => $v) {
                        // Add method if method is turned on for user!
                        if ($v) {
                            $methods[] = $k;
                        }
                    }
                }
            }
            if ($methods) {
                // Deliver
                foreach ($methods as $method) {
                    $handler = $notify_service->getDeprecatedHandler($method);
                    /* @var callable $handler */
                    if (!$handler || !is_callable($handler)) {
                        elgg_log("No handler registered for the method {$method}", 'WARNING');
                        continue;
                    }
                    elgg_log("Sending message to {$guid} using {$method}");
                    // Trigger handler and retrieve result.
                    try {
                        $result[$guid][$method] = call_user_func($handler, $from ? get_entity($from) : null, get_entity($guid), $subject, $message, $params);
                    } catch (Exception $e) {
                        error_log($e->getMessage());
                    }
                }
            }
        }
    }
    return $result;
}
Example #24
0
/**
 * Get the subscription methods of the user
 *
 * @param int $user_guid the user_guid to check (default: current user)
 *
 * @return array
 */
function thewire_tools_get_notification_settings($user_guid = 0)
{
    $result = [];
    $user_guid = sanitise_int($user_guid, false);
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (empty($user_guid)) {
        return $result;
    }
    if (elgg_is_active_plugin('notifications')) {
        $saved = elgg_get_plugin_user_setting('notification_settings_saved', $user_guid, 'thewire_tools');
        if (!empty($saved)) {
            $settings = elgg_get_plugin_user_setting('notification_settings', $user_guid, 'thewire_tools');
            if (!empty($settings)) {
                return string_to_tag_array($settings);
            }
            return $result;
        }
    }
    // default elgg settings
    $settings = (array) get_user_notification_settings($user_guid);
    if (empty($settings)) {
        return $result;
    }
    foreach ($settings as $method => $value) {
        if (!empty($value)) {
            $result[] = $method;
        }
    }
    return $result;
}