Welcome to Geeklog, Anonymous Wednesday, February 08 2023 @ 04:19 pm EST

Geeklog Forums

View parent comment for add comments


Status: offline

heretic

Forum User
Newbie
Registered: 11/16/05
Posts: 3
Hi,

Not sure if anyone has done this before, but I made a hack to display the parent post for Add Comment. The code is in two parts:

1. The comment function has to retrieve and assign the parent post to a variable
2. The display template has to display the parent on the add comment page

The first is a patch to the "public_html/comment.php". The code has to be added to the "commentform" function, after the following lines (approx line 197 in version 1.3.11sr2):
Text Formatted Code

            $comment_template->set_var('sid', $sid);
            $comment_template->set_var('pid', $pid);
            $comment_template->set_var('type', $type);

 

==> new code
Text Formatted Code

            // The following lines are a modification to get the Parent Comment content if any
            // Added by heretic
            if ($pid > 0) {
                $sql = "SELECT comment FROM {$_TABLES['comments']} WHERE cid = $pid";
                    $B = DB_fetchArray( DB_query($sql) );
                    $pidtxt = $B['comment'];
                $comment_template->set_var('pidtxt',$pidtxt);
            } else {
                $comment_template->set_var('pidtxt','<b>You are adding a top level comment!!</b>');
            }
            // End of additional code

 


The second part is a modification of the template files for the add comment form. For me, using the professional theme that is:

public_html/layout/professional/comment/comment.thtml

You have to change professional for whatever theme name you use, and this has to be done for all theme you support.

You need to add the following lines (basically adding a new html table row) to the FORM:

Text Formatted Code

<tr>
    <td align="right"><b>Parent:</b></td>
    <td>
        <div style="overflow:auto; width:100%; height:250px;
            background-color:lightblue; border: 1px gray solid;
            padding:4px; margin: 0px">
        <table border="0">
        <tr>
            <td>
                {pidtxt}
            </td>
        </tr>
        </table>
    </td>
</tr>

 


Since the parent post can be quite large I made the parent post display scrollable, so as to take up only a small display space. The background color can be changed for each theme by modifying the style entry for the element.

That is all there is to it.

Impact: Apart from one extra database read - nothing.

Security impact: None

heretic
 Quote

Status: offline

heretic

Forum User
Newbie
Registered: 11/16/05
Posts: 3
I personally liked this hack, so I have updated for the upcomming new release of Geeklog. The code is basically the same, but goes into different files. (I am not sure that I follow standard coding practices with this hack - but what the heck, it works).

First we need to get hold of the previous comment, and this is now done in the file "system/lib-comment.php". At line line 693 (for version 1.4.0b1) insert the following code:
Text Formatted Code

            // The following lines are a modification to get the Parent Comment content if any
            // Added by heretic
            if ($pid > 0) {
                    $sql = "SELECT comment FROM {$_TABLES['comments']} WHERE cid = $pid";
                    $B = DB_fetchArray( DB_query($sql) );
                    $pidtxt = $B['comment'];
                    $comment_template->set_var('pidtxt',$pidtxt);
            } else {
                $comment_template->set_var('pidtxt','<b>You are adding a top level comment!!</b>');
            }
            // End of additional code

 


Then the parent comment needs to be displayed, and that is done in a theme specific file. For the professional theme this is done in the file"public_html/layout/professional/comment/commentform.thtml". At line 13 insert the following code:
Text Formatted Code

                                                    <tr>
                                                        <td align="right"><b>Parent:</b></td>
                                                        <td>
                                                            <div style="overflow:auto; width:99%; height:200px;
                                                                background-color:lightblue; border: 1px gray solid;
                                                                padding:4px; margin: 0px">
                                                            <table border="0">
                                                            <tr>
                                                                <td>
                                                                    {pidtxt}
                                                                </td>
                                                            </tr>
                                                            </table>
                                                        </td>
                                                    </tr>  

 

The code has one text which could probably be controlled by langage setting, but at the moment it is not. The size, and background color can be changed for each theme by modifying the style entry for the element.

I hope this is of use to people.

heretic
 Quote

All times are EST. The time is now 04:19 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content