Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

comments_notify_tagged()

Description

Notify anyone tagged when a new comment is posted

Parameters

ColumnTypeDefaultDescription
$comment string The comment body
$from_user integer Who posted the comment
$resource integer null If commenting on a resource, the resource ID
$collection integer null If commenting on a collection, the collection ID

Return

void

Location

include/comment_functions.php lines 409 to 435

Definition

 
function comments_notify_tagged($comment,$from_user,$resource=null,$collection=null)
    {
    
// Find tagged users.
    
$success=preg_match_all("/@.*? /",$comment " "$taggedPREG_PATTERN_ORDER);
    if (!
$success) {return true;} // Nothing to do, return out.
    
foreach ($tagged[0] as $tag)
        {
        
$tag=substr($tag,1);$tag=trim($tag); // Get just the username.
        
$user=get_user_by_username($tag); // Find the matching user ID
        // No match but there's an underscore? Try replacing the underscore with a space and search again. Spaces are swapped to underscores when tagging.
        
if ($user===false) {$user=get_user_by_username(str_replace("_"," ",$tag));}

        if (
$user>0)
            {
            
// Notify them.

            // Build a URL based on whether this is a resource or collection
            
global $baseurl,$userref,$lang;
            
$url=$baseurl "/?" . (is_null($resource)?"c":"r") . "=" . (is_null($resource)?$collection:$resource);

            
// Send the message.
            
message_add(array($user),$lang["tagged_notification"] . " " $comment,$url,$userref);
            }

        }
    return 
true;
    }

This article was last updated 14th May 2021 23:05 Europe/London time based on the source file dated 1st March 2021 16:05 Europe/London time.