• Suggestion for future development:

    Add filters to allow changes/additions to chat entries.

    Currently date/time of each entry is only visible via title attribute and mouseover, not available on mobile devices.

    We wanted to add date/time in front of username, this was our solution by hacking a filter into plugin code, maybe official filters could be added in a similar way in future versions.

    simple-ajax-chat-form.php line 148

    $sac_out .= convert_smilies(' '. $chat_text) .'</li>'. "\n";
    
    // added this line:
    $sac_out = apply_filters( 'sac_line', $sac_out, $chat_text, $chat_time, $url, $chat_name );

    simple-ajax-chat.php line 178

    $loop = $id .'---'. $name .'---'. $text .'---'. $time .' '. esc_html__('ago', 'simple-ajax-chat') .'---'. $url .'---';
    
    // added these two line:
    $time = isset($query[$row]['time']) ? $query[$row]['time'] : '';
    $loop = apply_filters( 'sac_line', $loop, $text, $time, $url, $name );

    Our code in child theme:

    function my_sac_line( $line, $text, $time, $url, $name ) {
    	$nice_time = date_i18n( 'd.m. H:i', $time );
    	$line = str_replace(
    		array(
    			'<span class="sac-chat-name"',
    			'---'. $name .'---'
    		),
    		array(
    			$nice_time . ' <span class="sac-chat-name"',
    			'---' . $nice_time . ' ' . $name .'---'
    		),
    		$line
    	);
    	return $line;
    }
    add_filter( 'sac_line', 'my_sac_line', 10, 5 );

    Note: During implementation we saw a possible bug. Calls to simple-ajax-chat-core.php?sacGetChat=yes... would always also return an htmlpage with error message, no matter if valid data is sent or not.

    Plugin SAC: JavaScript not enabled. Please enable JavaScript and try again.

    Probably an exit(); should be added in function sac_getData() if $loop was not empty or similar.

    Thanks for great plugin.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Jeff Starr

    (@specialk)

    Thanks for the feedback, @ov3rfly. I’ll take a closer look at this for the next plugin update. In the meantime, hopefully the code/technique helps anyone else looking to do the same. Cheers.

    Thread Starter Ov3rfly

    (@ov3rfly)

    Thanks for quick feedback. Maybe you can also consider some kind of switch or filter to completely disable the date/time mouseover popup while you are at it.

    Plugin Author Jeff Starr

    (@specialk)

    Yeah maybe. Thanks for the feedback, @ov3rfly.

    Note that I am marking this thread and resolved to help keep things organized. If you have any further infos, feel free to post. Thank you.

    Thread Starter Ov3rfly

    (@ov3rfly)

    Feel free to mark as resolved as soon as the suggestion is included in plugin, thanks.

    The suggestion has status “not a support question” and does not count as “unresolved support” in main plugin page sidebar.

    You can organize issues as you like in other trackers like github or similar, but please do not abuse www.remarpro.com support forum status markers.

    Plugin Author Jeff Starr

    (@specialk)

    Sure thing, @ov3rfly.

    Please understand that I’ve not made any decision regarding this suggested new feature, but certainly will take a closer look for the next update. If it is a good fit that will help other users, and makes sense with the current codebase, then probably will be implemented. But again no promises if it doesn’t fit for whatever reason.

    Will go ahead and leave the ticket open until I make a final decision either way.

    Thread Starter Ov3rfly

    (@ov3rfly)

    Thanks for evaluating the suggestion for a general output filter possibility.

    For the special case to add date/time in front of username we have implemented a jQuery solution now which uses the data-time attribute and a MutationObserver to intercept live entries.

    Note that “resolved” in this forum means that the mentioned problem is actually resolved, the message status is not a “ticket open/closed” indicator.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    @ov3rfly Don’t create new topics for continuation of this one. Those are removed when found.

    If you wish to inform the author of more information, please continue here.

    Thread Starter Ov3rfly

    (@ov3rfly)

    @jdembowski The new bug report about ajax is as explained completely unrelated to this topic about a suggestion for a filter, but well, let’s post it here then…

    Bug: Ajax request returns wrong error message

    Already observed here in a sidenote, after more investigation here is the full bug now to keep things organized.

    When the js in client checks for new messages on server, ajax calls to simple-ajax-chat-core.php?sacGetChat=yes... always also return an htmlpage with error message, no matter if valid data is sent or not.

    Plugin SAC: JavaScript not enabled. Please enable JavaScript and try again.

    You can see this message e.g. in browser console in live demo of plugin.

    Reason is a bug in simple-ajax-chat-core.php which tries to evaluate $_POST['sac_js_nonce'] and sends this error if it is not present.

    A value for sac_js_nonce is only supplied when sending a new message from client to server in sac.php (which outputs JavaScript):

    var SendChaturl = '<?php echo plugins_url('simple-ajax-chat/simple-ajax-chat-core.php?sacSendChat=yes'); ?>';
    ...
    // send chat
    function sendComment() {
    	...
    	var jsnonce = '&sac_js_nonce=' + encodeURIComponent(currentJSNonce);
    	param = n + c + u + nonce + jsnonce;
    	httpSendChat.open('POST', SendChaturl, true);

    When getting new messages from server, no value for sac_js_nonce is supplied, so the comparison for those built-in hardcoded nonces there fails and triggers the output of the wrong error message via wp_die().

    A possible bugfix in simple-ajax-chat-core.php would be to replace this

    if (!in_array($sac_js_nonce, $sac_nonces)) {
    

    with this

    if ($sacSendChat === 'yes' && !in_array($sac_js_nonce, $sac_nonces)) {
    

    Thanks for great plugin.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Suggestion: Add filters to change entries’ is closed to new replies.