Skip to content

Commit

Permalink
Generating token for comment moderation in a global function now.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariohommel committed Mar 30, 2018
1 parent b0fb8d2 commit dcb693b
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions include/functions_comments.inc.php
Expand Up @@ -1141,16 +1141,9 @@ function serendipity_sendComment($comment_id, $to, $fromName, $fromEmail, $fromU

// Check for using Tokens
if ($serendipity['useCommentTokens']) {
$token = md5(uniqid(rand(),1));
$token = serendipity_generateCToken($comment_id);
$path = $path . "_token_" . $token;

//Delete any comment tokens older than 1 week.
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}options
WHERE okey LIKE 'comment_%' AND name < " . (time() - 604800) );

// Issue new comment moderation hash
serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}options (name, value, okey)
VALUES ('" . time() . "', '" . $token . "', 'comment_" . $comment_id ."')");
}

$deleteURI = serendipity_rewriteURL(PATH_DELETE . '/'. $path .'/' . $comment_id . '/' . $id . '-' . serendipity_makeFilename($title) . '.html', 'baseURL');
Expand Down Expand Up @@ -1221,3 +1214,28 @@ function serendipity_sendComment($comment_id, $to, $fromName, $fromEmail, $fromU

return serendipity_sendMail($to, $subject, $text, $fromEmail, null, $fromName);
}

/**
* Generates a token for E-Mail moderation of comments
* and stores it in the database
*
* @access public
* @param int ID of the comment to generate the token for
* @return string The generated token
*/
function serendipity_generateCToken($cid) {

global $serendipity;

$ctoken = md5(uniqid(rand(),1));

//Delete any comment tokens older than 1 week.
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}options
WHERE okey LIKE 'comment_%' AND name < " . (time() - 604800) );

// Issue new comment moderation hash
serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}options (name, value, okey)
VALUES ('" . time() . "', '" . $ctoken . "', 'comment_" . $cid ."')");
return $ctoken;

}

0 comments on commit dcb693b

Please sign in to comment.