Weever, an ExpressionEngine add-on by Studio625

Installation and Setup

Uploads

Upload the following file to your system/extensions/ folder:

  • ext.weever_ext.php

Upload the following file to your system/plugins/ folder:

  • pi.weever.php

Inside your plugins folder, create a new folder called "weever". Inside that folder upload:

  • weever_coment.php
  • weever_thread.php

Upload the following file to your system/language/english/ folder, or other language folder as appropriate:

  • lang.weever_ext.php

Installing the Extension

Navigate to the EE control panel's Extensions Manager. (Admin -> Utilities -> Extensions Manger) Find "Weever Extension" in the list of available extensions. Click "Enable".

Installing the Plugin

The plugin is "installed" automatically as long as it is placed correctly in the plugins folder.

Additional Setup

To achieve maximum performance from Weever, it is strongly recommended that you make some small changes ("hacks") to an ExpressionEngine file. Here's why: there is currently no way to tell the Comment Module which comments to pull from the database each time it runs. That means the Comment Module has to pull all of the ocmments for a given entry in order to make sure Weever has all of the information it needs. If you don't use pagination, that's not a problem; both the Comment Module and Weever need the same information anyway. But if you use pagination, the information needed by the two systems is different.

Let's illustrate with a comparison. Let's say we have ten comments, and we want to display five comments on each page. In date order (the method used by the Comment Module), this looks like:

  • Comment 1
  • Comment 2
  • Comment 3
  • Comment 4
  • Comment 5
  • Comment 6
  • Comment 7
  • Comment 8
  • Comment 9
  • Comment 10

In a threaded comment system, the order might look like:

  • Comment 1
  • Comment 2
    • Comment 6
  • Comment 3
    • Comment 4
      • Comment 10
    • Comment 5
  • Comment 7
  • Comment 8
    • Comment 9

See the problem? With the Comment Module, the first page will consist of comments 1-5. In the threaded model, however, the first five comments are 1, 2, 6, 3, 4. If we don't want a comment "thread" (a comment and all its replies) to break across page boundaries, the situation is even more complex. Thus, without being able to tell the Comment Module exactly which comments we want, we have to have it fetch all 10 comments, then filter from there. That is very inefficient.

The performance improvements brought about by this hack are not inconsequential. On large comment threads the system will avoid having to process a tremendous amount of unnecessary code. Furthermore, when cached data is available, even small comment threads become substantially quicker because large chunks of Weever and the Comment Module can be skipped.

The WSQL Hack

This is called the "WSQL Hack" because it involves a variable called $w_sql. Here's how it works:

  1. Save a backup copy of mod.comment.php. It is located in /system/modules/comment/. You might call it something like mod.comment.php.orig
  2. Open mod.comment.php
  3. Search for the phrase "Fetch comment ID numbers". You should find it around line 318.
  4. Approximately 15-20 lines below that, you will see a line that begins:
    $order_by  = ($order_by == 'date' OR  ...
    We will begin immediately below that line.
  5. Place the following code below the line from Step 4:
    /*
    Begin Weever Hack */
    
    if ($TMPL->fetch_param('weever') == 'on')
    {
    	// -------------------------------------------
    	// 'comment_entries_modify_wsql' hook.
    	//  - Add conditions to the WHERE clause
    	//
    	if ($EXT->active_hook('comment_entries_modify_wsql') === TRUE)
    	{
    		$w_sql = $EXT->call_extension('comment_entries_modify_wsql', $w_sql, $entry_id);
    		if ($EXT->end_script === TRUE) return;
    	}
    	//
    	// -------------------------------------------
    
    	$query = $DB->query("
    		SELECT comment_date, comment_id
    		FROM exp_comments
    		WHERE entry_id = '".$DB->escape_str($entry_id)."'".
    		$w_sql."
    		ORDER BY ".$order_by
    		);
    }
    else
    {
    		
  6. Now look directly below the code you just added. You should see a block of code that begins
    if ( ! $dynamic)
    and ends
    		else
    		{
    			$query = $DB->query("SELECT comment_date, comment_id FROM exp_comments WHERE entry_id = '".$DB->escape_str($entry_id)."' AND status = 'o' ORDER BY ".$order_by);	
    		}
    Below that chunk, place
    }
    /*
    End Weever Hack */
    		
    The final code will look like:
    /*
    Begin Weever Hack */
    
    if ($TMPL->fetch_param('weever') == 'on')
    {
    	// -------------------------------------------
    	// 'comment_entries_modify_wsql' hook.
    	//  - Add conditions to the WHERE clause
    	//
    	if ($EXT->active_hook('comment_entries_modify_wsql') === TRUE)
    	{
    		$w_sql = $EXT->call_extension('comment_entries_modify_wsql', $w_sql, $entry_id);
    		if ($EXT->end_script === TRUE) return;
    	}
    	//
    	// -------------------------------------------
    
    	$query = $DB->query("
    		SELECT comment_date, comment_id
    		FROM exp_comments
    		WHERE entry_id = '".$DB->escape_str($entry_id)."'".
    		$w_sql."
    		ORDER BY ".$order_by
    		);
    }
    else
    {
    		if ( ! $dynamic)
    		{
    			// When we are only showing comments and it is not based on an entry id or url title
    			// in the URL, we can make the query much more efficient and save some work.
    		
    		...
    		
    		else
    		{
    			$query = $DB->query("SELECT comment_date, comment_id FROM exp_comments WHERE entry_id = '".$DB->escape_str($entry_id)."' AND status = 'o' ORDER BY ".$order_by);	
    		}
    }
    /*
    End Weever Hack */