e107inc / e107

e107 Bootstrap CMS (Content Management System) v2 with PHP, MySQL, HTML5, jQuery and Twitter Bootstrap. Issue Discussion Room: https://gitter.im/e107inc/e107
https://e107.org
GNU General Public License v3.0
321 stars 213 forks source link

comment menu is not working with legacy e_comment.php file. #4467

Open Jimmi08 opened 3 years ago

Jimmi08 commented 3 years ago

Bug Description

with e_comment addon you can override e107 core comment system

The e_comment addon is not deprecated, but used to override the default comments 'engine' (e107). Check the social plugin for an example, where a Facebook comment engine is added.

But if your plugin use the core comment system, you still need to use e_comment for displaying your comments in the menu.

Problem is that this test fails in comment handler:

        function get_e_comment()
        {

            if($this->engine != 'e107')
            {
                return null;
            }

            $data = e107::getRegistry('e_comment');

            if ($data !== FALSE)
            {  
                return $data;
            }

This $data = e107::getRegistry('e_comment'); returns NULL

and then this returns NULL too:

            if ($data !== FALSE)
            {  
                return $data;
            }

e_comment.php is set this way:

$e_plug_table     = "userjourna";
$reply_location   = e_PLUGIN_ABS."userjournals/userjournals.php?blog.{NID}";
$db_table         = "userjournals";
$link_name        = "userjournals_subject";
$db_id            = "userjournals_id";
$plugin_name      = UJ1;

After removing that test of the new e_comment class, the menu works correctly and displays all needed comments.

PHP 7.2

CaMer0n commented 3 years ago

@Jimmi08 I believe this needs to be updated to v2.x standards, however, in the meantime, you might want to try using this setup, which comes from the links_page plugin:

//This is set to the table name you have decided to use.
$e_comment['eplug_comment_ids'] = "links_page";

//This is set to the location you'd like the user to return to after replying to a comment.
//$e_comment['reply_location'] = e_PLUGIN."links_page/links.php?comment.{NID}";
$e_comment['reply_location'] = e_HTTP.'links_page/links/comment/{NID}'; 
//A name for your plugin. It will be used in links to comments, in list_new/new.php.
$e_comment['plugin_name'] = "links_page";

//The path of the plugin folder
$e_comment['plugin_path'] = "links_page";

//This is the name of the field in your plugin's db table that corresponds to it's name or title.
$e_comment['db_title'] = "link_name";

//This is the name of the field in your plugin's db table that correspond to it's unique id number.
$e_comment['db_id'] = "link_id";

//qry must be set with a select_gen query.
//the main reason would be to check if a category from another table has a class restriction
//the id of the item should be provided as {NID}
//returned fields should at least contain the 'link_id' and 'db_id' fields set above
$e_comment['qry'] = "
SELECT l.*,c.*
FROM #links_page as l
LEFT JOIN #links_page_cat AS c ON l.link_category = c.link_category_id
WHERE l.link_id='{NID}' AND l.link_class REGEXP '".e_CLASS_REGEXP."' AND c.link_category_class REGEXP '".e_CLASS_REGEXP."' ";
Jimmi08 commented 3 years ago

@CaMer0n there are 2 different things:

Important:
$data = e107::getRegistry('e_comment'); returns NULL but test is against FALSE. Without this fix, comments are not displayed at all.

Can you fix this, please?

Not important now. Your example will not work. I tested it, compared both versions, checked if you didn't miss some code from links page plugin.

There is "callback" for that really old version and $e_comment is created correctly, $data are correct and comments are displayed. But after changing e_comment to your example it didn't work. I wanted to be sure that I didn't do mistake: $data with that really old way:

Array
(
    [userjourna] => Array
        (
            [eplug_comment_ids] => userjourna
            [plugin_name] => Denník
            [plugin_path] => 
            [reply_location] => /e107_plugins/userjournals/userjournals.php?blog.{NID}
            [db_title] => userjournals_subject
            [db_id] => userjournals_id
            [db_table] => userjournals
            [qry] => 
        )

)

$data with your old way:

Array
(
    [userjourna] => Array
        (
            [eplug_comment_ids] => userjourna
            [reply_location] => /e107_plugins/userjournals/userjournals.php?blog.{NID}
            [plugin_name] => Denník
            [plugin_path] => userjournals
            [db_title] => userjournals_subject
            [db_id] => userjournals_id
            [qry] => 
        )

)

The working version needs [db_table] key and this is missing from your example. Just be aware of this, if you plan to update this.

Jimmi08 commented 3 years ago

Nowadays e_comment.php is not needed for adding comment system to any table

Example:

$plugin = 'candidate';
$id = $result['id'];
$subject = $result['id'].': '.$result['candidate_name'];
$rate = false;

$prevStyle = e107::getRender()->getStyle(); 
e107::getRender()->setStyle('nocaption'); 
$content .= e107::getComment()->render($plugin, $id, $subject, $rate);

e107::getRender()->setStyle($prevStyle);
Jimmi08 commented 2 years ago

You still need e_comment.php for the custom plugin, so this should be fixed.

If you want to display user comments, there is $e_comment still used.

$data = $cobj->getCommentData(10, $from, 'comment_author_id ='.$id);

default:
if (isset($e_comment[$row['comment_type']]) && is_array($e_comment[$row['comment_type']]))
                            {
                                $var = $e_comment[$row['comment_type']];
....