Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 534 to 560

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 5th December 2024 06:05 Europe/London time based on the source file dated 17th May 2024 16:10 Europe/London time.