Module

Developer
Supported

Threaded Comments

ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Yuri Salimovskiy

     

You must be logged in to post.

Making submit() function more simple and robust

Feature Request

Laisvunas
Laisvunas

Hi Yuri,

I’m in the process of investigating how to make AJAX Babble add-on compatible with Threaded Comments.

After reading the code of the function submit() in mod.threaded_comments.php it seems to me that it can be made much simple and robust.

As it is now the function submit() mostly duplicates the functionality of insert_new_comment() function of the mod.comment.php file of the Comment module. Only these lines of the submit() function contribute functionality specific to Threaded Comments:

if ($_POST['parent_id']!='' && $_POST['parent_id']!=0)
        
{
            $parent_id 
$this->EE->security->xss_clean($_POST['parent_id']);
            
$root_id $parent_id;
            
$level 0;
            do 
{
                $level
++;
                
$q $DB->query("SELECT parent_id FROM exp_comments WHERE comment_id='".$DB->escape_str($root_id)."'");
                if (
$q->row('parent_id')==0) break;
                
$root_id $q->row('parent_id');
            
while ($root_id!=0);
            
        
}
        
else
        
{
            $parent_id 
0;
            
$root_id 0;
            
$level 0;
        

It’s not good to duplicate ExpressionEngine’s functionality in an add-on. This is prone to break things in case EllisLab decides to change something in insert_new comment() function. It is also complicatiing things for me because in case AJAX Babble is used together with Threaded Comments, then AJAX Babble should branch the code and use submit() function of Threadded Comments instead of insert_new comment() function of Comment module.

Here is my idea how Threadded Comments can simplify its handling of inserting comment. submit() function should be very simple:

function submit()
{
$this
->EE->load->add_package_path(PATH_MOD.'comment/');
$this->EE->load->model('comment_model');
if ( ! 
class_exists('Comment'))
{
 
require PATH_MOD.'comment/'.'mod.comment.php';
 
}
$COMM 
= new Comment();
$COMM->insert_new_comment();

Then in the package of Threaded Comments there should be an extension which uses the hook insert_comment_insert_array. That function should execute the code which in the function submit() is specific to Threaded Comments module.

That’s it! After such changes TC code will be much shorter and robust.

Yuri Salimovskiy
# 1
Developer
Yuri Salimovskiy

Hi Laisvunas,

that is brilliant idea!
Somehow I did not think of during the process of writing Threaded Comments - though I used this approach in other addons later.
It’s going to be tricky here however, as insert_new_comment() is performing redirect after it finishes it’s job, so I’ll probably have to use combination of module and extensions… need to figure out.
Will definitely try to implement this - thanks for shring idea again.
Will let you know when it’s done

Yuri Salimovskiy
# 2
Developer
Yuri Salimovskiy

Actually after thinking about this more I start doubting this is posible, as there are email notifications-related isuues… unless I’ll be able to move everything to extension. Will need to investigate.
Extension would work the best of course, as it would make integration of AJAX Babble and any other third-party modules easy.

Laisvunas
# 3
Laisvunas

Hi Yuri,

Can you elaborate a bit about email notifications-related issues?

Yuri Salimovskiy
# 4
Developer
Yuri Salimovskiy

Threaded Comments has feature to subscribe for notifications if there are new messages only in selected thread. Though I don’t know how many people are really using this :)
You can search the code for $notify_thread to see how it is used

Laisvunas
# 5
Laisvunas

It seems that “notify thread” functionality can be easily added to extension using insert_comment_end hook.

rgv
# 6
rgv

Similar issue i am facing with 17track .If anybody have solution please solve it

loemrntdherid1
# 7
loemrntdherid1

DTDC
# 8
DTDC

nice information i just try in my site DTDC Tracking