UPDATE: K2 r162r163 has been released. Some of my fix below has been applied.
Since some of my submitted K2 comment patch and workaround for live commenting it’s kind of been “ignored”, reapplying the patch over and over again on every new revision is very annoying. I use K2 theme for few of my client blog and it’s been updated according to K2 latest revision.
Here’s my K2 beta two revision 160 AJAX commenting patch for K2 live commenting related that I’ve use to fix few unsolved K2 live commenting bug. My latest diff is made from K2 Beta Two Revision 160. This patch is made for my personal use and preferences.
In this patch include :
Fix first comment render at starting on the top of the comments div in IE after new comment is submitted. Note: K2Bugs #0000171 have a different solution.Re-added a previously deletedfunction fail()for comment error.Returning commentator browser cookie is now stored.Edit comment link only visible to logged in user or logged in comment owner.Text field for Name, Email address and URL will not visible to logged in user.Comment error indication for missing required field. Error will be highlighted with yellow background according to script.aculo.us effects.js default setting.Previously displayed error notice will be hidden after the comment is successfully added.Comment textarea and submit button will only be disable if comment is successfully added and during loading process.leavecommentelement for “No Comment” will be remove properly if any.- Rearrange and remove unnecessary code.
I take no responsibility if you use this patch on your K2. Use and apply this patch at your own risk.
Supported browser :
- Microsoft Internet Explorer for Windows, version 6.0 and higher.
- Mozilla Firefox 1.0/Mozilla 1.7 and higher.
- Apple Safari 1.2 and higher.
Thanks to Jack Minardi for helping me test this patch on Mac OSX Safari RSS and Mac OSX Firefox.
ADDED: Assuming that you don’t know how to patch using diff, I’ve made a step by step changes according to the patch above.
- Open style.css, line 460 replace
.comments .commentlist { margin: 0; padding: 20px 0; width: 100%; }with
.comments .commentlist { margin: 0; padding: 20px 0; width: 100%; position: relative; } - Open comments-ajax.php, line 7 delete
// commented out due to it borking the commenting.. not sure what is going on yet. //function failure(request) { // $('errors').innerHTML = request.responseText; // new Effect.Highlight('errors'); //}and replace with
function fail($s) { header('HTTP/1.0 500 Internal Server Error'); echo $s; exit; } - In the same comments-ajax.php file, somewhere in line 61 find
wp_new_comment($commentdata);add afterif ( !$user_ID ) : setcookie('comment_author_' . COOKIEHASH, stripslashes($comment_author), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); setcookie('comment_author_email_' . COOKIEHASH, stripslashes($comment_author_email), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); setcookie('comment_author_url_' . COOKIEHASH, stripslashes($comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); endif; - Open comments.php, in line 55 replace
<?php edit_comment_link('<img src="'.get_bloginfo(template_directory). '/images/pencil.png" alt="Edit Link" />','<span class="commentseditlink">', '</span>'); ?>with
<?php if ( $user_ID ) { ?> <?php edit_comment_link('<img src="'.get_bloginfo(template_directory). '/images/pencil.png" alt="Edit Link" />','<span class="commentseditlink">', '</span>'); ?> <?php } ?> - In the same comments.php file, line 146 find
<div id="error" style="display:none">and replace with<div id="errors" style="display:none"> -
In the same comments.php file, somewhere in line 166 find
<div id="authorinfo">and add<?php if ( !$user_ID ) { ?>before that line.Then in line 175, find authorinfo div closing tag,
</div>and add<?php } ?>after that line. - Replace your current ajax_comments.js with the my updated ajax_comments.js (please rename this file to ajax_comments.js and put it inside js folder).
Remember that this changes is unofficial and the code might be different from K2 next future revision.
that brings it to the point…. thanx for the patch file!
Thanks very much mate!
Thanks, could you explain to me how to patch my K2 theme with your .diff file?
Execute this command inside K2 theme directory.
shell> patch -p0 < k2betatwor160_ajax_commenting.diff
Thanks, so you must have an access with a shell!
damned!
Ehm… AFAIK, most of, if not all those things have been fixed for K2. Probably in the SVN… If you’ve submitted your bug fixes to the bug tracker, I assure you nobody’s ignoring them.
Alright, I take that back; we fixed _some_ of those things :) — I’ve incorporated all your fixes in the next revision.
Michael Heilemann do you have an idea when the next revision will be available?
henri: I can’t do anything “perfectly” without it.
Michael Heilemann: Thanks for the feedback. I did report _some_ of it at K2Bugs about a month ago. I can’t remember back then whether you or Chris saying that there will be a new commenting system using Moo.fx. So all the reported issue related to live commenting was close and not long after it was deleted.
This patch isn’t so perfect but it’s good enough fit my “K2 powered blog” needs.
thanks zeo for the explanation without the .diff :)
Zeo, yeah Chris has been promising a new ajax system for while, but I don’t know what the status is on that. Moo.fx is out though, Chris cut up script.aculo.us instead.
Let me know if there’s anything else I can do.