/** * @param type $members int: a single member id or an array of UNIQUE member ids * @param type $postOptions array: must contain id_topic and id_message of the message * that triggered the @mention. * * creates an activity stream entry and sends out notifications to one or more * members about a user tagging event in the message specified in $postOptions[]. */ function notifyTaggedUsers(&$members, $postOptions) { global $user_info, $modSettings, $sourcedir; $to_notify = !is_array($members) ? array($members) : $members; if ($modSettings['astream_active'] && count($to_notify) > 0 && isset($postOptions['id_topic']) && isset($postOptions['id_message']) && $postOptions['id_topic'] && $postOptions['id_message']) { require_once $sourcedir . '/lib/Subs-Activities.php'; $id_act = aStreamAdd($user_info['id'], ACT_USERTAGGED, array('member_name' => $user_info['name']), 0, $postOptions['id_topic'], $postOptions['id_message'], $user_info['id'], ACT_PLEVEL_PRIVATE); if ((int) $id_act > 0) { aStreamAddNotification($to_notify, $id_act, ACT_USERTAGGED); } } }
/** * add a stream activity * * @param int $id_member the member id who owns this activity (= who did it) * @param int $atype activity type (numeric) * @param $params array with parameters, mostly for formatting * @param int $id_board the board id where it happened (if applicable) * @param int $id_topic the topic id where it happened (if applicable) * @param int $id_content the content id. this can be a message id but could also be a user id * (e.g. when a member posts on the profile of another member). depends on the context * @param int $id_owner the content owner (id_member) * @param int $priv_level privacy level for is_private. * @param int $dont_notify do not send the owner a notification for the activity. * * @return unique id (positive integer) of the inserted activity type, 0 if something went wrong. */ function aStreamAdd($id_member, $atype, $params, $id_board = 0, $id_topic = 0, $id_content = 0, $id_owner = 0, $priv_level = 0, $dont_notify = false) { global $user_info; $act_must_notify = array(ACT_LIKE, ACT_REPLIED); // these activity types will trigger a *mandatory* if (0 == $id_member || 0 == $id_owner) { // notification for $id_owner unless $dont_notify indicates otherwise return 0; } if (0 == $atype) { $_s = sprintf('Warning: tried to add atype==0 with id_member=%d, params=%s, id_board=%d, id_topic=%d', $id_member, @serialize($params), $id_board, $id_topic); log_error($_s); return 0; } // respect opt out setting if (!empty($user_info['act_optout'])) { if (in_array($atype, explode(',', $user_info['act_optout'])) !== false) { return 0; } } smf_db_insert('', '{db_prefix}log_activities', array('id_member' => 'int', 'id_type' => 'int', 'updated' => 'int', 'params' => 'string', 'is_private' => 'int', 'id_board' => 'int', 'id_topic' => 'int', 'id_content' => 'int', 'id_owner' => 'int'), array((int) $id_member, (int) $atype, time(), serialize($params), $priv_level, (int) $id_board, (int) $id_topic, (int) $id_content, (int) $id_owner), array('id_act')); $id_act = smf_db_insert_id('{db_prefix}log_activities', 'id_act'); // if this activity triggers a notification for the id_owner, use the $id_act to link it // to the notifications table. if ($id_act && $id_owner && in_array($atype, $act_must_notify) && !$dont_notify) { aStreamAddNotification($id_owner, $id_act, $atype); } $data = array('id_member' => $id_member, 'type' => $atype, 'params' => $params, 'board' => $id_board, 'topic' => $id_topic, 'content_id' => $id_content, 'id_owner' => $id_owner, 'plevel' => $priv_level, 'event_id' => $id_act); HookAPI::callHook('astream_event_added', array(&$data)); return $id_act; }