function edit_limit_node_view_alter in Edit Limit 7
File
- ./
edit_limit.module, line 290 - edit_limit.module Primary module file for Edit Limit. This contains all the hooks needed to run the module.
Code
function edit_limit_node_view_alter(&$build) {
// Don't bother if the user can't edit their own comments anyway
if (!user_access('edit own comments')) {
return FALSE;
}
if (!empty($build['links']['comment']['#links']['comment-add']) && !empty($build['comments']['comments'])) {
// 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 = :cid", array(
':cid' => $comment->cid,
));
}
// Allow edit links if there is enough time left based on the system variable edit_limit_comment_time.
foreach ($build['comments']['comments'] as $key => $comment) {
if (!is_numeric($key)) {
continue;
}
// 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 limits') && variable_get('edit_limit_comment_time_enabled', FALSE) && !empty($build['comments']['comments'][$key]['links']['comment']['#links']['comment-edit'])) {
$time_unit = variable_get('edit_limit_comment_time_unit', EDIT_LIMIT_TIME_UNIT_DEFAULT);
$time_limit = $comment['#comment']->created + intval(_unit_to_seconds(variable_get('edit_limit_comment_time', EDIT_LIMIT_COMMENT_TIME), $time_unit));
// If too much time has passed, destroy the link.
if ($time_limit < REQUEST_TIME) {
unset($build['comments']['comments'][$key]['links']['comment']['#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 limits' get this far).
$build['comments']['comments'][$key]['links']['comment']['#links']['comment-edit']['title'] .= ' <span class="edit-limit-time-unit-' . $time_unit . '">' . t('(%time_limit %time_unit left)', array(
'%time_limit' => $time_limit - REQUEST_TIME,
'%time_unit' => 'seconds',
)) . '</span>';
}
}
}
}
}