I'd like to have the ajaxy quick reply/edit like vB has. I don't know ajax at all, though. Any one want to work on this?

Michelle

CommentFileSizeAuthor
#41 303552-41.patch1.21 KBrjbrown99

Comments

michelle’s picture

Status: Active » Postponed

Will revisit this in 2.x.

Michelle

v8powerage’s picture

I'm using ajax_comments (http://drupal.org/node/349090), but with advanced_forum "delete" function doesn't works, I created an issue #411016: Can't delete comments when using advanced_forum.module, perhaps You could take a look at this as well?

michelle’s picture

I don't use that module and it's not something I'll have time to look at any time soon.

Michelle

v8powerage’s picture

That's shame, because those both modules together would make a killer forum. I'm gonna try play around this, could You tell perhaps why this could be that reply works, but delete isn't? Ajax comments is using token during delete operation, maybe here's the problem, that it's lost on the way thru advanced_forum?

michelle’s picture

AF doesn't do anything special on add/edit/delete so I really have no idea.

Michelle

v8powerage’s picture

Well I'll be trying do something about this then though I'm nobody's programmer :P

michelle’s picture

Well, if you get it figured out, feel free to report back here. I'll look at it when I work on 2.x.

Michelle

v8powerage’s picture

I found this in ajax_comments read me

2. If you have themed your comments output, make sure that everything is wrapped to ".comment" class
in your "comment.tpl.php"

Comments doesn't works because advanced forums comment template is different and there's no "div class comment".

michelle’s picture

Ah, well, there you go, then. Sounds like you just need to add that.

Michelle

v8powerage’s picture

Hi
Well it's not exactly comment class issue, because I replaced advf-forum-post.tpl.php with Drupal's default comment.tpl.php and comments still can't be deleted, they are only "fading away" but are not actually deleted, to be able to delete comments, I must disable comment theming (commenting lines) in advanced_forum.module, so it must be something in module's code, which collide with ajax_comment delete function.

v8powerage’s picture

Hi
I fixed this by commenting this code in advanced_forum.module (function advanced_forum_preprocess_comment, lines 461-512):

    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);
      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;

and replacing this:

<?php else: ?>
  <?php $classes .= $comment_classes; ?>
  <div id="comment-<?php print $comment->cid; ?>" class="forum-post <?php print $classes; ?> clear-block">
<?php endif; ?>

with the code below, in adfv-forum-post.tpl.php (lines 31-34):

<?php else: ?>
  <div class="comment">
<?php endif; ?>
michelle’s picture

Well, glad you got it working but you're cutting out a large chunk of functionality to do it. Not something I recommend for users in general but great if you're happy with it. :)

Michelle

v8powerage’s picture

Well I know it's probably not the best way to do it, but I couldn't make this working in any other way. Perhaps when You'll be working on version 2.x of the module You gonna find some better solution (I'm sure You will ;-).

michelle’s picture

Hopefully. We'll see when I get that far. :)

Michelle

robertdjung’s picture

subscribe. might give this idea some time.

michelle’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Category: task » feature
Status: Postponed » Active
Ingumsky’s picture

Subscribe...

tallsimon’s picture

i'd love to see this too, have had to turn off ajax comments for the forums :-(

michelle’s picture

This is not likely to get into 2.x unless someone writes a patch or an add-on to nodecomment. While 2.x will still work with normal comments, I, personally, will be using nodecomment and that's what gets my attention.

Michelle

apanag’s picture

I am going to look into this, at my free hours. I ll post later a few details about how i am going to develop it.

apanag

michelle’s picture

@apanag: Thanks. :)

Michelle

apanag’s picture

Michelle,

nodecomment is going to be the default comment system in the advanced_forum2? Or is it going to be a plugin and the user will be able to choose either default drupal comment system or nodecomment?

apanag

michelle’s picture

It's optional but my focus is on nodecomment. AF will continue to work with comment but not all the features will.

Michelle

apanag’s picture

I see.
So i think the best solution is to develop a plugin for nodecomment as you suggested on post #19.

apanag

Roavei’s picture

subscribe...

Drake’s picture

I have noticed that if Ajax Comments are enabled for forum topic, the "delete" button use the link for example:
.../comment/delete/?token=0519dc......

and this does not work becasue the comment ID is not included before ?

if I use the link
.../comment/delete/75?token=0519dc (75 states for comment ID) then the delete function works properly also in conetion with Ajax Comments...

So to solve this issue we will have to include the NID before ?

but how???

Ingumsky’s picture

Yep, that's the same for me. It has been mentioned in other AF-related thread that this issue wouldn't be solved by Michelle but workaround was found by another user.

alex72rm’s picture

Project: Advanced Forum » AJAX Comments
Version: 6.x-2.x-dev » 6.x-1.8
Component: User interface » Code
Category: feature » bug

Hi,

@#26... the problem is then with AJAX comments module integration. It isn't a problem strictly concerning advanced forum.

In fact, when I disable AJAX comments, all come back to work as desired.

sinn’s picture

I've added in advanced_forum.module in advanced_forum_preprocess_comment function after 503 line code:

  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),
      	);
  }

This code add comment id to "href". It's from ajax_comments.module.

All my advanced_forum_preprocess_comment function

/**
 * 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);
      }
    }
  }
}
Fidelix’s picture

Subscribing.

without much hope.

ilw’s picture

Subscribing

mr.j’s picture

Status: Active » Needs review

Ok so I thought you were all wrong blaming Advanced Forum - and you were ... sort of.
Turns out fixing the bug in ajax_comments reveals another bug in advanced forum which stops it from working anyway.

Ajax Comments is lacking the $comment parameter in ajax_comments_link_alter, so the comment id and token is never going to work. It specifies $comment as the 2nd parameter to the function when it should really be $node, with $comment 3rd. Notice the watchdog log full of warning messages.

Fix for ajax_comments:

--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -317,8 +317,8 @@
 /**
  * Implementation of hook_link_alter().
  */
-function ajax_comments_link_alter(&$links, $comment) {
-  $node = menu_get_object();
+function ajax_comments_link_alter(&$links, $node, $comment) {
+//  $node = menu_get_object();
   $allowed_node_types = variable_get('ajax_comments_node_types', array());
   $all_allowed = TRUE;
   foreach ($allowed_node_types as $type) {
@@ -329,7 +329,7 @@
   }
 
   if ($all_allowed || isset($allowed_node_types[$node->type]) && $allowed_node_types[$node->type]) {
-    if (is_array($links) && isset($links['comment_delete'])) {
+    if (is_array($links) && isset($links['comment_delete']) && isset($comment->cid)) {
       $links['comment_delete'] = array(
         'title' => t('delete'),
         'href' => 'comment/delete/'. $comment->cid,

So you fix that and deletion fails anyway because advanced forum recreates the entire links array again during a preprocess function which calls hook_link_alter again after we have already altered them. And it does not pass through that same $comment parameter so the links all get the same token based on a NULL $cid which prevents deletion from working.

Fix for advanced forum (and issue):

--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -499,7 +499,7 @@
       // 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);
+      drupal_alter('link', $links, $node, $variables['comment']);
       unset($links['comment_parent']);
 
       // Iconify common links (optional to avoid translation issues)

And now comment deletion works.

Roavei’s picture

Thank you for figuring this out - mr.j
I downloaded the newest AJax-Comments-Snapshot and installed it. (Your changes seem to be already implemented).
Afterwards I changed the code-line in the Advanced-Forum module. But deletion still do not work.
Do I need the newest Advanced-Forum? Actually I do use 6.x.-1.0.

michelle’s picture

@Roavei: You should be using 1.1. 1.0 has a security issue that was copied from core forum and fixed long ago.

Michelle

Roavei’s picture

@Michelle, ups... you're right... I had to catch up on various module-updates.

@mr.j
I do not know whats different now ... but now i get the following warning:
warning: Missing argument 3 for ajax_comments_link_alter() in /*/*/public_html/sites/all/modules/ajax_comments/ajax_comments.module on line 221.
And yes... I did change the function in the advanced-forum.

Line 221 is: function ajax_comments_link_alter(&$links, $node, $comment) {

mr.j’s picture

That error indicates that the function ajax_comments_link_alter is being called with only 2 arguments instead of 3.

So if you have changed the line in advanced forum then there must be somewhere else that is calling it incorrectly.

Try inserting this line right at the start of ajax_comments_link_alter:

var_dump(debug_backtrace());

That should print out a backtrace of the function calls whenever ajax_comments_link_alter is called and you should be able to figure it out.

Roavei’s picture

Mr. J - you're my hero ;)

Looks like we're on the right way... I am not sure about what's important in the debug_backtrace.
As suggested somewhere on the web - i also tried the following:

$backtrace=debug_backtrace();
$last=next($backtrace);
 echo $last['class'];

This prints out: "call_user_func_array" - but what does this say?

mr.j’s picture

call_user_func_array is used to call a function using a string name. eg call_user_func_array('function_name'). It is used all over the place in drupal for calling hook and theme implementations.

You need to print the whole backtrace, not just the last function that was called.

rjbrown99’s picture

Title: Add quick reply/edit » Comment deletion, Advanced Forum, bugfix
Issue tags: +advanced forum, +ajax_comments_link_alter
StatusFileSize
new1.21 KB

Enclosed is a patch against DRUPAL-6--1. This incorporates the updates from #34 and also fixes a warning if arg3 isn't present.

For searchability, this also caused me the following error which is fixed by this patch:

Notice: Trying to get property of non-object in ajax_comments_link_alter() (line 232 of /mypath/sites/all/modules/ajax_comments/ajax_comments.module).
rjbrown99’s picture

Version: 6.x-1.8 » 6.x-1.x-dev
Status: Needs review » Fixed

Committed to -dev. Marking as fixed unless I hear otherwise. Thanks.
http://drupal.org/cvs?commit=438164

Status: Fixed » Closed (fixed)
Issue tags: -advanced forum, -ajax_comments_link_alter

Automatically closed -- issue fixed for 2 weeks with no activity.