Skip to content

Instantly share code, notes, and snippets.

@eevee
Created December 12, 2013 01:21
Show Gist options
  • Save eevee/7921723 to your computer and use it in GitHub Desktop.
Save eevee/7921723 to your computer and use it in GitHub Desktop.
selected FA code quotes
function dispatch_submission_notifications($from_uid, $submission_id, $skip_notification_if_user_banned=FALSE)
{
global $sql;
// Fetch the information for the submission.
// Do not rely on session information.
//
$query = 'SELECT adultsubmission '.
'FROM submissions '.
'WHERE rowid='.$sql->qstr($submission_id);
$_submission = $sql->get_row($query, 'subm. notification, getting subm. info', __FILE__);
// Fetch the people that are watching the originating user.
//
$query = 'SELECT w.watch_type, u.userid, u.username, u.lower, u.seeadultart, u.maturelocked '.
'FROM watches AS w LEFT JOIN users AS u ON w.user_id=u.userid '.
'WHERE w.target_id='.$sql->qstr($from_uid);
$_watchlist = $sql->query($query, 'subm. notification, getting user watchlist', __FILE__);
$messages = array();
$userids = array();
while($row = $sql->fetch_array($_watchlist))
{
if($_submission['adultsubmission'] != 0 and ($row['seeadultart'] == 0 or $row['maturelocked'] == 1))
{
// Skip sending the notification to those people who have their setting on that block
// them from viewing mature/adult images.
//
continue;
}
if($row['userid'])
{
// Build the EXTENDED INSERT parts here.
//
$messages[] = '('.
$row['userid'].', '.
$submission_id.
')';
// Log the user ID's to later increment their message counts by one
//
$userids[] = $row['userid'];
}
}
$sql->free_result($_watchlist);
if(!empty($messages))
{
// Dispatch the messages.
//
$query = 'INSERT IGNORE INTO messagecenter_submissions VALUES '.implode(', ', $messages);
$sql->query($query, 'subm. notification, sending out notifications', __FILE__);
// Update user's message counters.
//
$query = 'UPDATE users '.
'SET submissioncount=submissioncount+1 '.
'WHERE userid IN ('.implode(', ', $userids).')';
$sql->query($query, 'subm. notification, updating user counters', __FILE__);
}
return TRUE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment