function edit_limit_link_alter in Edit Limit 6
Implementation of hook_link_alter(). This removes comment edit links if the comment is no longer editable.
File
- ./
edit_limit.module, line 218 - edit_limit.module Primary module file for Edit Limit. This contains all the hooks needed to run the module.
Code
function edit_limit_link_alter(&$links, $node, $comment = NULL) {
if (!empty($links['comment_edit'])) {
// Allow edit links if the edit count hasn't been reached yet.
// TODO: Complete this functionality.
if (0) {
$results = db_query("SELECT * FROM {edit_limit_comment_time} WHERE cid=%d", $comment->cid);
}
// Allow edit links if there is enough time left based on the system variable edit_limit_comment_time.
// We don't have to do much user access checking, since this link will only exist if the user passed
// the comment_access() check for this given comment.
if (!user_access('bypass edit limit') && variable_get('edit_limit_comment_time_enabled', FALSE)) {
$time_limit = $comment->timestamp + intval(variable_get('edit_limit_comment_time', EDIT_LIMIT_COMMENT_TIME));
// If too much time has passed, destroy the link.
if ($time_limit < time()) {
unset($links['comment_edit']);
}
else {
// Add the javascript that will handle the countdown.
drupal_add_js(drupal_get_path('module', 'edit_limit') . '/edit_limit.js');
// Modify the link to add the remaining seconds (only users that can't pass 'bypass edit limit' get this far).
$links['comment_edit']['title'] .= ' (' . ($time_limit - time()) . ' seconds left)';
}
}
}
}