Как подружить модули Drupal advanced_forum и ajax_comments
Модули Drupal advanced_forum и ajax_comments являются достаточно интересными и полезными, но к сожалению они не работают вместе - в advanced_forum невозможно удалить комментарий через ajax_comments. Автор ajax_comments обещает исправить это в версии 2.0, но пока зарелизина 1.8 и надо как-то это исправлять.
Решил я это хаком ядра. Знаю, не очень правильно, но зато эффективно: в advanced_forum.module в функцию advanced_forum_preprocess_comment после 503 строчки добавил код
<?
if (user_access('administer comments')) {
$links['comment_delete'] = array(
'title' => t('delete'),
'href' => 'comment/delete/'. $variables['comment']->cid,
'query' => 'token='. drupal_get_token($variables['comment']->cid),
);
}
?>
if (user_access('administer comments')) {
$links['comment_delete'] = array(
'title' => t('delete'),
'href' => 'comment/delete/'. $variables['comment']->cid,
'query' => 'token='. drupal_get_token($variables['comment']->cid),
);
}
?>
Этот код добавляет идентификатор к атрибуту href (код взять из ajax_comments.module).
ну и полностью функция advanced_forum_preprocess_comment будет выглядеть так:
<?php
/**
* Preprocesses template variables for the comment template.
*/
function advanced_forum_preprocess_comment(&$variables) {
if (advanced_forum_treat_as_forum_post('comment', $variables)) {
if (arg(1) == 'reply') {
// Use the preview version
$variables['template_files'][] = "advf-forum-preview-post";
}
else {
// Use our combined node/comment template file
$variables['template_files'][] = 'advf-forum-post';
}
// This is a comment, not the node.
$variables['top_post'] = FALSE;
// Just use the date for the submitted on.
$variables['submitted'] = format_date($variables['comment']->timestamp);
// Assign the comment to the content variable for consistancy with nodes.
$variables['content'] = $variables['comment']->comment;
// User information
$account_id = $variables['comment']->uid;
if ($account_id == 0) {
// Anonymous user. Make a fake user object for theme_username
$variables['account']->name = $variables['comment']->name;
$variables['account']->homepage = $variables['comment']->homepage;
}
else {
// Load up the real user object
$variables['account'] = user_load(array('uid' => $variables['comment']->uid));
}
// Create the author pane
$variables['author_pane'] = theme('author_pane', $variables['account'], advanced_forum_path_to_images(), 'advf-author-pane');
if (arg(1) != 'reply') {
// Because the $links array isn't available here, we recreate it
$node = node_load($variables['comment']->nid);
$links = module_invoke_all('link', 'comment', $variables['comment']);
drupal_alter('link', $links, $node);
// My hack for added "cid" to href
if (user_access('administer comments')) {
$links['comment_delete'] = array(
'title' => t('delete'),
'href' => 'comment/delete/'. $variables['comment']->cid,
'query' => 'token='. drupal_get_token($variables['comment']->cid),
);
}
unset($links['comment_parent']);
// Iconify common links (optional to avoid translation issues)
_advanced_forum_buttonify_links($links);
// Remake the links with our changes
$variables['links'] = theme('links', $links, array('class' => 'links forum-links'));
$variables['links_array'] = $links;
}
// Since we have to load the node anyway for our links trick, make it avail
$variables['node'] = $node;
// Title
if (variable_get('comment_subject_field_' . $node->type, 1) == 0) {
// if comment titles are disabled, don't display it.
$variables['title'] = '';
}
else {
// Assign the subject to the title variable for consistancy with nodes.
$variables['title'] = check_plain($variables['comment']->subject);
}
// Comment number with link
if (!isset($post_number)) {
static $post_number = 0;
}
_advanced_forum_topic_nid($variables['node']->nid);
$post_per_page = _comment_get_display_setting('comments_per_page', $variables['node']);
$page_number = $_GET['page'];
if (!$page_number) {
$page_number = 0;
}
$post_number++;
$fragment = 'comment-' . $variables['comment']->cid;
$query = ($page_number) ? 'page=' . $page_number : NULL;
$linktext = '#' . (($page_number * $post_per_page) + $post_number);
$linkpath = 'node/' . _advanced_forum_topic_nid();
$variables['comment_link'] = l($linktext, $linkpath, array('query' => $query, 'fragment' => $fragment));;
// Link to page created by Comment Page module, if it exists
$variables['page_link'] = '';
if (!empty($variables['comment']->page_url) && !(arg(0) == 'comment' && arg(1) == $variables['comment']->cid)) {
$variables['page_link'] = l(t('(permalink)'), $variables['comment']->page_url);
}
// Load the signature.
if (module_exists('signature_forum')) {
// If Signature For Forums is installed, use that
$variables['signature'] = signature_forum_get_signature($variables['comment']);
}
elseif (variable_get('user_signatures', 0)) {
if ($variables['account']->signature) {
// Otherwise load Drupal's built in one, if enabled.
$variables['signature'] = check_markup($variables['account']->signature, $variables['account']->signature_format);
}
}
}
}
?>
/**
* Preprocesses template variables for the comment template.
*/
function advanced_forum_preprocess_comment(&$variables) {
if (advanced_forum_treat_as_forum_post('comment', $variables)) {
if (arg(1) == 'reply') {
// Use the preview version
$variables['template_files'][] = "advf-forum-preview-post";
}
else {
// Use our combined node/comment template file
$variables['template_files'][] = 'advf-forum-post';
}
// This is a comment, not the node.
$variables['top_post'] = FALSE;
// Just use the date for the submitted on.
$variables['submitted'] = format_date($variables['comment']->timestamp);
// Assign the comment to the content variable for consistancy with nodes.
$variables['content'] = $variables['comment']->comment;
// User information
$account_id = $variables['comment']->uid;
if ($account_id == 0) {
// Anonymous user. Make a fake user object for theme_username
$variables['account']->name = $variables['comment']->name;
$variables['account']->homepage = $variables['comment']->homepage;
}
else {
// Load up the real user object
$variables['account'] = user_load(array('uid' => $variables['comment']->uid));
}
// Create the author pane
$variables['author_pane'] = theme('author_pane', $variables['account'], advanced_forum_path_to_images(), 'advf-author-pane');
if (arg(1) != 'reply') {
// Because the $links array isn't available here, we recreate it
$node = node_load($variables['comment']->nid);
$links = module_invoke_all('link', 'comment', $variables['comment']);
drupal_alter('link', $links, $node);
// My hack for added "cid" to href
if (user_access('administer comments')) {
$links['comment_delete'] = array(
'title' => t('delete'),
'href' => 'comment/delete/'. $variables['comment']->cid,
'query' => 'token='. drupal_get_token($variables['comment']->cid),
);
}
unset($links['comment_parent']);
// Iconify common links (optional to avoid translation issues)
_advanced_forum_buttonify_links($links);
// Remake the links with our changes
$variables['links'] = theme('links', $links, array('class' => 'links forum-links'));
$variables['links_array'] = $links;
}
// Since we have to load the node anyway for our links trick, make it avail
$variables['node'] = $node;
// Title
if (variable_get('comment_subject_field_' . $node->type, 1) == 0) {
// if comment titles are disabled, don't display it.
$variables['title'] = '';
}
else {
// Assign the subject to the title variable for consistancy with nodes.
$variables['title'] = check_plain($variables['comment']->subject);
}
// Comment number with link
if (!isset($post_number)) {
static $post_number = 0;
}
_advanced_forum_topic_nid($variables['node']->nid);
$post_per_page = _comment_get_display_setting('comments_per_page', $variables['node']);
$page_number = $_GET['page'];
if (!$page_number) {
$page_number = 0;
}
$post_number++;
$fragment = 'comment-' . $variables['comment']->cid;
$query = ($page_number) ? 'page=' . $page_number : NULL;
$linktext = '#' . (($page_number * $post_per_page) + $post_number);
$linkpath = 'node/' . _advanced_forum_topic_nid();
$variables['comment_link'] = l($linktext, $linkpath, array('query' => $query, 'fragment' => $fragment));;
// Link to page created by Comment Page module, if it exists
$variables['page_link'] = '';
if (!empty($variables['comment']->page_url) && !(arg(0) == 'comment' && arg(1) == $variables['comment']->cid)) {
$variables['page_link'] = l(t('(permalink)'), $variables['comment']->page_url);
}
// Load the signature.
if (module_exists('signature_forum')) {
// If Signature For Forums is installed, use that
$variables['signature'] = signature_forum_get_signature($variables['comment']);
}
elseif (variable_get('user_signatures', 0)) {
if ($variables['account']->signature) {
// Otherwise load Drupal's built in one, if enabled.
$variables['signature'] = check_markup($variables['account']->signature, $variables['account']->signature_format);
}
}
}
}
?>

Комментарии
Оставить сообщение