Excellent work! It looks great and works flawlessly. As far as I have experienced.
(the search input field moves a line down and covers up other newpost and privatemessage links if the screen is resized smaller.)
I just have a suggestion and offer a little code to help make it happen.
Sorting through many answers to a poster's question is tedious and encourages people to merely repost the same questions over and over. If on the other hand, a forum user discovers that reading the thread of a similar question quickly brings him answers, everybody wins.
This can be done if forum readers are given a very quick and convenient way to rate replies for relevance and for helpfulness. Threads can then always display the most helpful replies very near the top, with deference for very new posts.
Getting users to rate is the problem. If rating causes the page to reload or they must enter information, they won't do it. A rating widget must be one click and conspicuously embedded within the comment; and should reward the user with a thank you message encouraging him to do it again, but also must not invoke a pesky page reload.
I think the following code could do this. I didn't put a lot of time into it. I know there are at least two bugs. One component works on Mac but not windows. Something stupid I overlooked, I'm sure. If you like the idea and want to use the code, just let me know. I will spend the time to clean it up. But for now you can get an idea with a quick look at the link
The meat and potatoes of it is this
<!-- php delivers the comment id at some point before insertion --> <?php $comment_id= 'jjts' ?> <!-- accomidates any comment id scheme already in use --> <!-- insert this html anywhere within each comment --> <span id="rating<?php echo $comment_id ?>"></span> <script type="text/javascript"> // populate the js rate comment array from php comment output commentId[noComments]= '<?php echo $comment_id ?>'; commentRating[noComments]= <?php echo comment_rating($comment_id) ?>; commentUserRating[noComments]= 0; noComments++; </script> <!-- end inline insert -->
The back end
<?php // testing data for display demo function comment_rating($a){ $comment_rate['jjts']= 7; $comment_rate['qqks']= 5; return $comment_rate[$a]; } // testing comment functions for display demo if (strpos($_SERVER['QUERY_STRING'], 'rate=')===0){ $commentId= $_GET['c']; $rating= $_GET['rate']; echo 'comment id '.$commentId.' : '.$rating; exit(); } ?> <html> <head> <script type="text/javascript"> <!-- required in head or before generating any comment text--> var commentId= new Array(); var commentRating= new Array(); var commentUserRating= new Array(); var noComments= 0; </script> <style> span.ratecomment{ color: #888; font-size: 10px; font-family: arial; } </style> </head> <body> <!-- add to php code which generates each comment --> <!-- text of comment --> <!-- insert this html anywhere within each comment --> <!-- accomidates any comment id already in use --> <?php $comment_id= 'jjts' ?> <span id="rating<?php echo $comment_id ?>"></span> <script type="text/javascript"> // populate the js rate comment array from php comment output commentId[noComments]= '<?php echo $comment_id ?>'; commentRating[noComments]= <?php echo comment_rating($comment_id) ?>; commentUserRating[noComments]= 0; noComments++; </script> <!-- end inline insert --> <!-- more text of comment --> <br>one comment<br> <br> <br> <!-- add to php generate generating each comment --> <!-- text of another comment --> <!-- insert this html anywhere within each comment --> <!-- accomidates any comment id already in use --> <?php $comment_id= 'qqks' ?> <span id="rating<?php echo $comment_id ?>"></span> <script type="text/javascript"> // populate the js rate comment array from php comment output commentId[noComments]= '<?php echo $comment_id ?>'; commentRating[noComments]= <?php echo comment_rating($comment_id) ?>; commentUserRating[noComments]= 0; noComments++; </script> <!-- end inline insert --> <!-- other comment text --> <br>another comment<br> <br> <br> <!-- for testing and demo --> <span id="test2"></span> <div id="testoutput">O</div> <!-- --> </body> </html> <script type="text/javascript"> // testing document.getElementById('test2').innerHTML= '<span onclick="rateCommit(1, 4)" onmouseover="rateHover(2, 1, 4)" onmouseout="rateHover(1, 1, 4)">(click to test commit a rating of 4 on second comment)</span>'; // ====== // initial populate ratings var rate1= '<img src="'; var rate2= '" onclick="rateCommit('; var rate3= ')" onmouseover="rateHover(2, '; var rate4= ')" onmouseout="rateHover(1, '; var rate5= ')">'; var temp= ''; for (i=0; i<noComments; i++){ poprate(i, commentRating[i], 0, 0); } function poprate(id, forum, rate, userrate){ var rateimg= ''; var p= ''; for (j=1; j<=8; j++){ if (j<=rate || j<=userrate){ rateimg= 'http://www.jerrywickey.com/images/fostar.jpg'; }else if (j<=forum){ rateimg= 'http://www.jerrywickey.com/images/custar.jpg'; }else{ rateimg= 'http://www.jerrywickey.com/images/unstar.jpg'; } // p += rate1+rateimg+rate2+id+', '+j+rate3+id+', '+j+rate4+id+', '+j+rate5; } p += '<br><span class="ratecomment">Rate this comment. Click to submit rating.</span>'; document.getElementById('rating'+commentId[id]).innerHTML= p; } function rateHover(inout, id, rate){ mouse(inout); if (inout==2){ poprate(id, commentRating[id], rate, commentUserRating[id]); }else if (inout==1){ poprate(id, commentRating[id], 0, commentUserRating[id]); } } function rateCommit(id, rating){ // for testing only document.getElementById('testoutput').innerHTML= 'comment '+commentId[id]+' rated '+rating+' sent to server'; // use the code below instead after implementing processcomment.php commentUserRating[id]= rating; poprate(id, commentRating[id], rating, rating); document.getElementById('testoutput').innerHTML= server('?rate='+rating+'&c='+commentId[id]); // the server output doesn't need to go anywhere // code to display thank user reward } function mouse(mp){ if (mp==1){mp= 'default';} else if (mp==2){mp= 'pointer';} document.body.style.cursor= mp; } function server(url){ gethttp= browserdependant(); gethttp.open('GET', url, false); gethttp.send(); return gethttp.responseText; } function browserdependant(){ if (window.XMLHttpRequest){ return new XMLHttpRequest(); }else{ return new ActiveXObject("Microsoft.XMLHTTP"); } } </script> <?php // file processcomment.php // other comment processing in the form if (strpos($_SERVER['QUERY_STRING'], 'otherfunctions=')===0){ // do stuff if ($succeed){ echo $result; }else{ echo 'fail'; } exit(); } if (strpos($_SERVER['QUERY_STRING'], 'rate=')===0){ $commentId= $_GET['c']; $rating= $_GET['rate']; if ($currentrate= getCommentField($commentId, 'numberOfRatings')){ $weight= getCommentField($commentId, 'numberOfRatings'); $rate= (getCommentField($commentId, 'rating')*$weight+$rating)/$weight++; setCommentField($commentId, 'rating', $rate); setCommentField($commentId, 'numberOfRatings', $weight); echo $commentId.' : '.$rating; }else{ echo 'fail'; } exit(); } function sortcomments($commentarray){ // each element of the array contains an array of the comment fields // returns same 2 dimensional array sorted for display $freshnessweight= 1; // how important is a recent post $userratingweight= 2; // how important is user ratings // these are test values as rating max at 8 and time can be thousands // this is accounted for by adjusting the weight value $highestrating= 8; $count= 0; foreach ($commentarray as $comment){ $newcom[$count]= $comment; $count++; } $done= false; while (!$done){ $done= true; $f= time()-intval($newcom[0]['unixPostTime']); $r= $highestrating-intval($newcom[0]['userRating']); $previndex= ($f/$freshnessweight) + ($r/$userratingweight); for ($i=1; $i<$count; $i++){ $f= time()-intval($newcom[$i]['unixPostTime']); $r= $highestrating-intval($newcom[$i]['userRating']); $index= $f/$freshnessweight + $r/$userratingweight; if ($index<$previndex){ $done= false; $temp= $newcom[$i]; $newcom[$i]= $newcom[$i-1]; $newcom[$i-1]= $temp; } $previndex= $index; } } return $newcom; }
Edited by jerrywickey, 17 January 2012 - 01:40 PM.