1

Was wondering if anyone knew how i might add a last edited stamp when someone edits their post in JComments. I've added an extra column to the end of the jcomments' table called editdate.

Mostly not sure how to incorporate the query that will register the editdate.

The references to the edit button on the toolbar are as follows. The first in components/com_jcomments/tpl/default/tpl_comment.php inside the function to display the toolbar buttons:

if ($this->getVar('button-edit') == 1) {
                $text = JText::_('BUTTON_EDIT');
?>
    <a class="toolbar-button-edit" href="#" onclick="jcomments.editComment(<?php echo $comment->id; ?>); return false;" title="<?php echo $text; ?>"></a>
<?php
            }

The second in components/com_jcomments/js/jcomments-v2.3.js that i'm assuming points to the next location.

editComment: function(i){this.busyComment(i);var a=arguments;if(this.form==null){a=new Array(i,1);}return this.ajax('JCommentsEditComment', a);},

And the third the editcomment function in components/com_jcomments/jcomments.ajax.php. The save function is under it, not sure which actually saves the edit.

public static function editComment($id, $loadForm = 0)
    {
        if (JCommentsSecurity::badRequest() == 1) {
            JCommentsSecurity::notAuth();
        }

        $user = JFactory::getUser();
        $response = JCommentsFactory::getAjaxResponse();
        $comment = JTable::getInstance('Comment', 'JCommentsTable');

        if ($comment->load((int) $id)) {
            $acl = JCommentsFactory::getACL();

            if ($acl->isLocked($comment)) {
                $response->addAlert(JText::_('ERROR_BEING_EDITTED'));
            } else if ($acl->canEdit($comment)) {
                    $comment->checkout($user->id);

                    $name = ($comment->userid) ? '' : JCommentsText::jsEscape($comment->name);
                    $email = ($comment->userid) ? '' : JCommentsText::jsEscape($comment->email);
                    $homepage = JCommentsText::jsEscape($comment->homepage);
                    $text = JCommentsText::jsEscape(JCommentsText::br2nl($comment->comment));
                    $title = JCommentsText::jsEscape(str_replace("\n", '', JCommentsText::br2nl($comment->title)));

                    if (intval($loadForm) == 1) {
                        $form = JComments::getCommentsForm($comment->object_id, $comment->object_group, true);
                        $response->addAssign('comments-form-link', 'innerHTML', $form);
                    }
                    $response->addScript("jcomments.showEdit(" . $comment->id . ", '$name', '$email', '$homepage', '$title', '$text');");
                } else {
                    $response->addAlert(JText::_('ERROR_CANT_EDIT'));
                }
        }
        return $response;
    }

public static function saveComment($values = array())
    {
        if (JCommentsSecurity::badRequest() == 1) {
            JCommentsSecurity::notAuth();
        }

        $config = JCommentsFactory::getConfig();

        $response = JCommentsFactory::getAjaxResponse();
        $values = self::prepareValues($_POST);
        $comment = JTable::getInstance('Comment', 'JCommentsTable');
        $id = (int) $values['id'];

        if ($comment->load($id)) {
            $acl = JCommentsFactory::getACL();

            if ($acl->canEdit($comment)) {
                if ($values['comment'] == '') {
                    self::showErrorMessage(JText::_('ERROR_EMPTY_COMMENT'), 'comment');
                } else if (($config->getInt('comment_maxlength') != 0)
                    && ($acl->check('enable_comment_length_check') == 1)
                    && (JCommentsText::strlen($values['comment']) > $config->getInt('comment_maxlength'))) {
                    self::showErrorMessage(JText::_('ERROR_YOUR_COMMENT_IS_TOO_LONG'), 'comment');
                } else if (($config->getInt('comment_minlength') != 0)
                    && ($acl->check('enable_comment_length_check') == 1)
                    && (JCommentsText::strlen($values['comment']) < $config->getInt('comment_minlength'))) {
                    self::showErrorMessage(JText::_('ERROR_YOUR_COMMENT_IS_TOO_SHORT'), 'comment');
                } else {
                    $bbcode = JCommentsFactory::getBBCode();

                    $comment->comment = $values['comment'];
                    $comment->comment = $bbcode->filter($comment->comment);
                    $comment->published = $acl->check('autopublish');


                    if (($config->getInt('comment_title') != 0) && isset($values['title'])) {
                        $comment->title = stripslashes((string)$values['title']);
                    }

                    if (($config->getInt('author_homepage') == 1) && isset($values['homepage'])) {
                        $comment->homepage = JCommentsText::url($values['homepage']);
                    } else {
                        $comment->homepage = '';
                    }

                    $result = JCommentsEventHelper::trigger('onJCommentsCommentBeforeChange', array(&$comment));

                    if (in_array(false, $result, true)) {
                        return $response;
                    }

                    $comment->store();
                    $comment->checkin();

                    JCommentsEventHelper::trigger('onJCommentsCommentAfterChange', array(&$comment));

                    if ($config->getInt('enable_notification') == 1) {
                        if ($config->check('notification_type', 1) == true) {
                            JComments::sendNotification($comment, false);
                        }
                    }
                    $html = JCommentsText::jsEscape(JComments::getCommentItem($comment));
                    $response->addScript("jcomments.updateComment(" . $comment->id . ", '$html');");
                }
            } else {
                $response->addAlert(JText::_('ERROR_CANT_EDIT'));
            }
        }
        return $response;

Basically just wanting it to add a current date to the editdate column on send. There may be other references to it, but i haven't found any. This is where the trail led, and i'm assuming a query needs inserted, just not sure where or how to insert the data into the database. Thanks for any help.

1

Just a short answer of mine would be, if you created an extra column in the jcomments table, that column (if MySQL) should be a timestamp type column in the table. It would just automatically update the date-time at every change/edit/insert of the rows, thus you do not have to edit the php files for this purpose. You should just set the column that way.

So it should be:

editdate TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

I am not the best mysql guru here but with something like this query line you can change the field type of the table column in your database.

ALTER TABLE `mydb`.`jcomments` MODIFY COLUMN `editdate` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

If there is any mistake in the above query, someone (like '@mickmackusa' - who is really a db query guru here) probably will be so kind to fix it a bit.

reference: http://www.mysqltutorial.org/mysql-timestamp.aspx

  • If that's the case, then i'm just not sure where to put that. The column exists in this test data [db-fiddle.com/f/4pqz9MFGGaQ1ucB3nmw1De/0] Structure for editdate column is COLUMN: editdate TYPE: datetime DEFAULT: As defined: 0000-00-00 00:00:00 All other fields are blank or unchecked. – Mythic Nov 21 '18 at 18:40
  • Ok, you were right. The setting i was missing in the column was ATTRIBUTES: on update CURRENT_TIMESTAMP Added the time stamp in the column. Now can just use query to display. Thanks. – Mythic Nov 21 '18 at 18:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.