Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: custom field in comment box?  (Read 7757 times)

0 Members and 1 Guest are viewing this topic.

dills84

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 43
custom field in comment box?
« on: February 22, 2008, 06:04:43 pm »

I was wondering if anyone has found a way to add a new field to the comment box? i'd really like to add a "website" or "email" input form. could i just add a new section in the database?
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: custom field in comment box?
« Reply #1 on: February 22, 2008, 06:49:42 pm »

It's not that easy. You'd have to modify the database and core code in various places. Hasn't been done yet afaik. Are you requesting this as a method to fight comment spam posted by anonymous visitors? If yes, then I rather suggest to look into the existing anti-spam mods/plugins (captcha, akismet).
Logged

dills84

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 43
Re: custom field in comment box?
« Reply #2 on: February 22, 2008, 08:23:57 pm »

It's not that easy. You'd have to modify the database and core code in various places. Hasn't been done yet afaik. Are you requesting this as a method to fight comment spam posted by anonymous visitors? If yes, then I rather suggest to look into the existing anti-spam mods/plugins (captcha, akismet).

No, im more interested on letting anonymous users post their websites as a link within their comment. this usually encourages comments since im using coppermine as a photoblog.

I just tried adding a table to the cpg_comments SQL called "anon_url", and made a new textbox in the "add comments" section in theme.php file. i then added a couple strings to a DBinput2.php file that i have set up for comment box modding purposes. i couldnt get the contents of the text box to post to the database. only "anon_url" the name of the input field would be inserted with no text box info.

i probibly did somthing wrong, since im kindof a hack. and im sure you guys dont want to support me since I'm editing Core files. but i figured i'd let others know what my method was, just incase anyone has tried this before.

any help or advice would be appreciated. thanks.

Logged

dills84

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 43
Re: custom field in comment box?
« Reply #3 on: February 22, 2008, 10:15:29 pm »

OK... so i've made some headway.

http://www.dillonpic.com/gallery/displayimage.php?album=lastup&cat=0&pos=0

the fields all work, and the new "website" field posts to a new column in the Database called "msg_url"

My question now is how do i retrieve the data to display with the posted comments? what files are involved with that? a general direction would be a huge help.

thanks in advance!
Logged

dills84

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 43
Re: custom field in comment box?
« Reply #4 on: February 23, 2008, 07:09:28 pm »

Well... i did it!

check it out.

http://www.dillonpic.com/gallery/displayimage.php?pos=-1880

i'd add the mod to do this. but im not sure if you guys want me posting core file changes?
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: custom field in comment box?
« Reply #5 on: February 23, 2008, 08:48:24 pm »

Sure, please go ahead and post your mod - maybe others are interessted to use it.
Logged

dills84

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 43
Re: custom field in comment box?
« Reply #6 on: February 23, 2008, 10:42:41 pm »

ok well here it goes... please note im mediocore in php and sql...

Files i changed:
dbinput.php
theme.php


first add the SQL table to cpg_comments that the commenters URL will be written too... i called mine "msg_url" (see image).

edit dbinput.php

add "$msg_url = trim($_POST['msg_url']);" into the //comment update section here:

Code: [Select]
        check_comment($_POST['msg_body']);
        check_comment($_POST['msg_author']);
        $msg_body = addslashes(trim($_POST['msg_body']));
        $msg_author = addslashes(trim($_POST['msg_author']));
        $msg_url = trim($_POST['msg_url']);
        $msg_id = (int)$_POST['msg_id'];

and into the //comment section here:

Code: [Select]
        check_comment($_POST['msg_body']);
        check_comment($_POST['msg_author']);
        $msg_author = addslashes(trim($_POST['msg_author']));
        $msg_body = addslashes(trim($_POST['msg_body']));
        $msg_url = trim($_POST['msg_url']);
        $pid = (int)$_POST['pid'];


Then add msg_url into the query under "// Anonymous users, we need to use META refresh to save the cookie" here (its important you place the "msg_url" text in the proper spot in the list or it will show in the wrong table:

Code: [Select]
            $insert = cpg_db_query("INSERT INTO {$CONFIG['TABLE_COMMENTS']} (pid, msg_author, msg_body, msg_url, msg_date, author_md5_id, author_id, msg_raw_ip, msg_hdr_ip) VALUES ('$pid', '{$CONFIG['comments_anon_pfx']}$msg_author', '$msg_body', '$msg_url', NOW(), '{$USER['ID']}', '0', '$raw_ip', '$hdr_ip')");
and again insert msg_url  under the // Registered users, we can use Location to redirect section here (again placement is important):

Code: [Select]
$insert = cpg_db_query("INSERT INTO {$CONFIG['TABLE_COMMENTS']} (pid, msg_author, msg_body, msg_url, msg_date, author_md5_id, author_id, msg_raw_ip, msg_hdr_ip) VALUES ('$pid', '" . addslashes(USER_NAME) . "', '$msg_body', NOW(), '', '" . USER_ID . "', '$raw_ip', '$hdr_ip')");
Now we're done editing the dpinput.php file.

next open theme.php and insert the following (if you already have it just edit it)


the $template_image_comments is for displaying the new db information. i created a new function and token called {MSG_URL} that can be placed anywhere in the display_comments section. heres how i did it.

Code: [Select]
// HTML template for the display of comments
$template_image_comments = <<<EOT
<table align="center" width="{WIDTH}" cellspacing="1" cellpadding="0" class="maintable">

        <tr>
                <td>
                        <table width="100%" cellpadding="0" cellspacing="0">
                           <tr>
                                <td class="tableh2_compact" nowrap="nowrap">
                                        <b>{MSG_AUTHOR}</b> - <a href="http://{MSG_URL}">{MSG_URL}</a><a name="comment{MSG_ID}"></a>&nbsp;
<!-- BEGIN ipinfo -->
                                                                                 ({IP})
<!-- END ipinfo -->
</td>


                                <td class="tableh2_compact" align="right" width="100%">
<!-- BEGIN report_comment_button -->
     <a href="report_file.php?pid={PID}&amp;msg_id={MSG_ID}&amp;what=comment" title="{REPORT_COMMENT_TITLE}"><img src="images/report.gif" width="16" height="16" border="0" align="middle" alt="{REPORT_COMMENT_TITLE}" /></a>
<!-- END report_comment_button -->


<!-- BEGIN buttons -->
                                        <a href="javascript:;" onclick="blocking('cbody{MSG_ID}','', 'block'); blocking('cedit{MSG_ID}','', 'block'); return false;" title="{EDIT_TITLE}"><img src="images/edit.gif" border="0" align="middle" /></a>
                                        <a href="delete.php?msg_id={MSG_ID}&what=comment"  onclick="return confirm('{CONFIRM_DELETE}');"><img src="images/delete.gif" border="0" align="middle" /></a>
<!-- END buttons -->
                                </td>
                                <td class="tableh2_compact" align="right" nowrap="nowrap">


                                        <span class="comment_date">[{MSG_DATE}]</span>
                                </td></tr>
                        </table>
                </td>
        </tr>
        <tr>
                <td class="tableb_compact">
                        <div id="cbody{MSG_ID}" style="display:block">
                                {MSG_BODY}
                        </div>
                        <div id="cedit{MSG_ID}" style="display:none">
<!-- BEGIN edit_box_smilies -->
                                <table width="100%" cellpadding="0" cellspacing="0">

                                                <form name="f{MSG_ID}" method="POST" action="db_input.php">
                                                <input type="hidden" name="event" value="comment_update" />
                                                <input type="hidden" name="msg_id" value="{MSG_ID}" />
                                                <tr>
                                                <td>
                                                   <input type="text" name="msg_author" value="{MSG_AUTHOR}" class="textinput" size="25" />
                                                </td><td>
                                                </tr>
                                                <tr>
                                                <td width="80%">
                                                        <textarea cols="40" rows="2" class="textinput" name="msg_body" onselect="storeCaret_f{MSG_ID}(this);" onclick="storeCaret_f{MSG_ID}(this);" onkeyup="storeCaret_f{MSG_ID}(this);" style="width: 100%;">{MSG_BODY_RAW}</textarea>
                                                </td>
                                                <td class="tableb_compact">
                                                </td>
                                                <td>
                                                        <input type="submit" class="comment_button" name="submit" value="{OK}" />
                                                </td>
                                                </form>
                                        </tr>
                                        <tr>
                                                <td colspan="3"><img src="images/spacer.gif" width="1" height="2" /><br /></td>
                                        </tr>
                                </table>
                                {SMILIES}
<!-- END edit_box_smilies -->


<!-- BEGIN edit_box_no_smilies -->
                                <table width="100%" cellpadding="0" cellspacing="0">
                                        <tr>
                                                <form name="f{MSG_ID}" method="POST" action="db_input.php">
                                                <input type="hidden" name="event" value="comment_update" />
                                                <input type="hidden" name="msg_id" value="{MSG_ID}" />
                                                <td>
                                                <input type="text" name="msg_author" value="{MSG_AUTHOR}" class="textinput" size="25" />
                                                </td>
                                        </tr>
                                        <tr>
                                                <td width="100%">
                                                        <textarea cols="40" rows="2" class="textinput" name="msg_body" style="width: 100%;">{MSG_BODY_RAW}</textarea>
                                                </td>
                                                <td class="tableb_compact">
                                                </td>
                                                <td>
                                                        <input type="submit" class="comment_button" name="submit" value="{OK}" />
                                                </td>
                                                </form>
                                        </tr>
                                        <tr>
                                                <td colspan="3"><img src="images/spacer.gif" width="1" height="2" /><br /></td>
                                        </tr>
                                </table>
<!-- END edit_box_no_smilies -->
                        </div>
                </td>
        </tr>
</table>
EOT;




Next we need the function that created the {MSG_URL} token... its located in the "function theme_html_comments($pid)" section. add this to your theme.php file if you dont already have it.




Code: [Select]
// Displays comments for a specific picture
function theme_html_comments($pid)
{
    global $CONFIG, $USER, $CURRENT_ALBUM_DATA, $comment_date_fmt, $HTML_SUBST;
    global $template_image_comments, $template_add_your_comment, $lang_display_comments;

    $html = '';

    //report to moderator buttons
    if (!(($CONFIG['report_post']==1) && (USER_CAN_SEND_ECARDS))) {
        template_extract_block($template_image_comments, 'report_comment_button');
    }

    if (!$CONFIG['enable_smilies']) {
        $tmpl_comment_edit_box = template_extract_block($template_image_comments, 'edit_box_no_smilies', '{EDIT}');
        template_extract_block($template_image_comments, 'edit_box_smilies');
        template_extract_block($template_add_your_comment, 'input_box_smilies');
    } else {
        $tmpl_comment_edit_box = template_extract_block($template_image_comments, 'edit_box_smilies', '{EDIT}');
        template_extract_block($template_image_comments, 'edit_box_no_smilies');
        template_extract_block($template_add_your_comment, 'input_box_no_smilies');
    }

    $tmpl_comments_buttons = template_extract_block($template_image_comments, 'buttons', '{BUTTONS}');
    $tmpl_comments_ipinfo = template_extract_block($template_image_comments, 'ipinfo', '{IPINFO}');

    if ($CONFIG['comments_sort_descending'] == 1) {
        $comment_sort_order = 'DESC';
    } else {
        $comment_sort_order = 'ASC';
    }
    $result = cpg_db_query("SELECT msg_id, msg_author, msg_body, msg_url, UNIX_TIMESTAMP(msg_date) AS msg_date, author_id, author_md5_id, msg_raw_ip, msg_hdr_ip, pid FROM {$CONFIG['TABLE_COMMENTS']} WHERE pid='$pid' ORDER BY msg_id $comment_sort_order");

    while ($row = mysql_fetch_array($result)) {
        $user_can_edit = (GALLERY_ADMIN_MODE) || (USER_ID && USER_ID == $row['author_id'] && USER_CAN_POST_COMMENTS) || (!USER_ID && USER_CAN_POST_COMMENTS && ($USER['ID'] == $row['author_md5_id']));
        $comment_buttons = $user_can_edit ? $tmpl_comments_buttons : '';
        $comment_edit_box = $user_can_edit ? $tmpl_comment_edit_box : '';
        $comment_ipinfo = ($row['msg_raw_ip'] && GALLERY_ADMIN_MODE)?$tmpl_comments_ipinfo : '';

        if ($CONFIG['enable_smilies']) {
            $comment_body = process_smilies(make_clickable($row['msg_body']));
            $smilies = generate_smilies("f{$row['msg_id']}", 'msg_body');
        } else {
            $comment_body = make_clickable($row['msg_body']);
            $smilies = '';
        }

        $ip = $row['msg_hdr_ip'];
        if ($row['msg_hdr_ip'] != $row['msg_raw_ip']) {
            $ip .= ' [' . $row['msg_raw_ip'] . ']';
        }

        $params = array('{EDIT}' => &$comment_edit_box,
            '{BUTTONS}' => &$comment_buttons,
            '{IPINFO}' => &$comment_ipinfo
            );

        $template = template_eval($template_image_comments, $params);

        $params = array('{MSG_AUTHOR}' => stripslashes($row['msg_author']),
            '{MSG_ID}' => $row['msg_id'],
            '{PID}' => $row['pid'],
            '{MSG_URL}' => $row['msg_url'],
            '{EDIT_TITLE}' => &$lang_display_comments['edit_title'],
            '{CONFIRM_DELETE}' => &$lang_display_comments['confirm_delete'],
            '{MSG_DATE}' => localised_date($row['msg_date'], $comment_date_fmt),
            '{MSG_BODY}' => bb_decode($comment_body),
            '{MSG_BODY_RAW}' => $row['msg_body'],
            '{OK}' => &$lang_display_comments['OK'],
            '{SMILIES}' => $smilies,
            '{IP}' => $ip,
            '{REPORT_COMMENT_TITLE}' => &$lang_display_comments['report_comment_title'],
            '{WIDTH}' => $CONFIG['picture_table_width']
            );

        $html .= template_eval($template, $params);
    }

    if (USER_CAN_POST_COMMENTS && $CURRENT_ALBUM_DATA['comments'] == 'YES') {
        if (USER_ID) {
            $user_name_input = '<tr><td><input type="hidden" name="msg_author" value="' . stripslashes(USER_NAME) . '" /></td>';
            template_extract_block($template_add_your_comment, 'user_name_input', $user_name_input);
            $user_name = '';
        } else {
            if (isset($USER['name'])) {
              $user_name = strtr($USER['name'], $HTML_SUBST);
            } else {
              $user_name = $lang_display_comments['your_name'];
            }

        }

        $params = array('{ADD_YOUR_COMMENT}' => $lang_display_comments['add_your_comment'],
            // Modified Name and comment field
            '{NAME}' => $lang_display_comments['name'],
            '{COMMENT}' => $lang_display_comments['comment'],
            '{PIC_ID}' => $pid,
            '{USER_NAME}' => $user_name,
            '{MAX_COM_LENGTH}' => $CONFIG['max_com_size'],
            '{OK}' => $lang_display_comments['OK'],
            '{SMILIES}' => '',
            '{WIDTH}' => $CONFIG['picture_table_width'],
            );

        if ($CONFIG['enable_smilies']){
                        $params['{SMILIES}'] = generate_smilies();
                } else {
                        template_extract_block($template_add_your_comment, 'smilies');
                }

        $html .= template_eval($template_add_your_comment, $params);
    }

    return $html;
}


EOT;


Next we need the text input form where the user can enter his/her website. i added this to the "add comments" section of the theme.php file. add this if you dont already have it.

Code: [Select]
// HTML template for the form to add comments
$template_add_your_comment = <<<EOT
        <form method="post" name="post" action="db_input2.php">


<!-- Start flushing the previous data memory-->
<?php
$msg_author 
"";
$msg_body ="";
$toxic "";
?>

<!-- end flushing the previous data memory -->


                <table align="center" width="{WIDTH}" cellspacing="1" cellpadding="0" class="maintable"

bgcolor="#FFFFFF">
                        <tr>
                                        <td width="100%" class="tableh2_compact"><b>{ADD_YOUR_COMMENT}</b></td>
                        </tr>
                        <tr>
                <td colspan="1">
                        <table width="100%" cellpadding="0" cellspacing="0">

<!-- BEGIN user_name_input -->
                                                        <tr>
                                                                <td class="tableb_compact" >
                                        {NAME}
                                </td>
                                <td class="tableb_compact" colspan="4" align="left">
                                        <input type="text" class="textinput" name="msg_author" size="20"

maxlength="30" value="{USER_NAME}" />
                                </td>
<!-- END user_name_input -->





                                                        <tr>
                                                                <td class="tableb_compact">
                                         http://
                                </td>
                                <td class="tableb_compact">
                                        <input type="text" class="textinput" name="msg_url" size="20"

maxlength="70" value="" />
                                </td>





<!-- BEGIN input_box_smilies -->
                                <td class="tableb_compact">
                                {COMMENT}
                                                                </td>
                                <td width="100%" class="tableb_compact">
                                <input type="text" class="textinput" id="message" name="msg_body"

onselect="storeCaret_post(this);" onClick="storeCaret_post(this);" onKeyUp="storeCaret_post(this);"

maxlength="{MAX_COM_LENGTH}" style="width: 100%;" />
                                                                </td>
<!-- END input_box_smilies -->
<!-- BEGIN input_box_no_smilies -->
                                <td class="tableb_compact">
                                {COMMENT}
                                                                </td>
                                <td width="100%" class="tableb_compact">
                                <input type="text" class="textinput" id="message" name="msg_body" 

maxlength="{MAX_COM_LENGTH}" style="width: 100%;" />
                                </td>
<!-- END input_box_no_smilies -->

                                <td class="tableb_compact">&nbsp;

                                </td>

                             
                                                        </tr>
                        </table>
                </td>
        </tr>
<!-- BEGIN smilies -->
        <tr>
                <td width="100%" class="tableb_compact">
                        {SMILIES}
                </td>
        </tr>
<!-- END smilies -->

                </table>
        </form>
EOT;


And that should be it.

again... im a newbie to php/sql stuff, so there might be some errors... use at your own risk it works for me on my custom theme. Also, i havent written the code to EDIT the url after a person posts... it shouldnt be too hard but i dont really need that function. if someone else wants to improve on this that'd be great!

also, if anyone can tell me another way of doing this without editing the DBinput file that would also be great.

Live demo at: www.dillonpic.com
« Last Edit: February 24, 2008, 07:17:23 am by Joachim Müller »
Logged
Pages: [1]   Go Up
 

Page created in 0.023 seconds with 20 queries.