• Hi Brad,
    I’ve been using your live comment preview plugin and I’m trying to get some of the newer WordPress features incorporated but my php/javascript hacking skills haven’t gotten me very far. Do you have time to work on any updates?

    Some of the things I was looking into are:
    1. gzip the javascript. I added ob_start ("ob_gzhandler"); to the php script and it didn’t seem to affect the response time much. It may download faster over a modem though.
    2. respect the gravatar settings from the admin panel, i.e. show/don’t show, and default avatar.
    3. use the gravatar size specified in WordPress or the theme.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter monodistortion

    (@monodistortion)

    I may have almost figured out #2 after finding the right functions in wp-includes/pluggable.php
    I just wish these functions were documented somewhere.

    I ended up changing a few lines and adding a new variable, $gravatar_show. Here are the relevant lines of code:

    // Gravatar settings
    	$gravatar_size = 64;
    	$gravatar_show = get_option('show_avatars'); // showing or hiding avatars can be set in the admin panel under Settings - Discussion
    	$gravatar_default = get_option('avatar_default'); // The default avatar style can be chosen under Settings - Discussion
    	// $gravatar_default = 'https://www.gravatar.com/avatar/ad516503a11cd5ca435acc9bb6523536'; // or put a URI to your custom default image here
    	$gravatar_rating = get_option('avatar_rating');
    
    	// Customize this string if you want to modify the preview output
    	// %1 - author's name (as hyperlink if available)
    	// %2 - comment text
    	// %3 - gravatar image url
    	$previewFormat = '
    		<ol class="commentlist" style="clear: both; margin-top: 3em;">
    			<li id="comment-preview" class="alt" style="overflow: hidden;">
    				<div class="comment-author vcard">';
    	if ($gravatar_show) {
    	$previewFormat .= '
    					<img src="%3" alt="" class="avatar avatar-' . $gravatar_size . '" width="' . $gravatar_size . '" height="' . $gravatar_size . '"/>';
    	}
    	$previewFormat .= '
    					<span class="fn n">%1</span>
    				</div>
    				<div class="comment-meta">Posted (date) at (time) <span class="meta-sep">| Permalink</div>
    				%2
    
    		';

    The preview format is sort-of customized to my Sandbox theme.

    // You shouldn't need to edit anything else.
    
    	ob_start ("ob_gzhandler"); //compress with gzip if possible
    	header('Content-type: text/javascript');
    <?php
    		if ($gravatar_show) :
    		?>
    	var user_gravatar = '<?php echo addslashes($user_gravatar); ?>';
    	var gravatar = '<?php echo addslashes($gravatar_default); ?>?';
    	if (eml != '') {
    		gravatar = 'https://www.gravatar.com/avatar/' + hex_md5(eml) + '?d=<?php echo urlencode($gravatar_default); ?>&amp;';
    	}
    	else if (user_gravatar != '') {
    		gravatar = user_gravatar + '?d=<?php echo urlencode($gravatar_default); ?>&amp;';
    	}
    
    	gravatar += 's=<?php echo $gravatar_size; ?>';
    
        <?php
    	if (!empty($gravatar_rating)) {
    		?>
    		gravatar += '&amp;r=<?php echo urlencode($gravatar_rating) ?>';
    		<?php
    	}
    		endif;
    
        $previewFormat = str_replace("\r", "", $previewFormat);
        $previewFormat = str_replace("\n", "", $previewFormat);
        $previewFormat = str_replace("'", "\'", $previewFormat);
        $previewFormat = str_replace("%1", "' + name + '", $previewFormat);
        $previewFormat = str_replace("%2", "' + cmnt + '", $previewFormat);
    		if ($gravatar_show) {
    			$previewFormat = str_replace("%3", "' + gravatar + '", $previewFormat);
    		}
        $previewFormat = "'" . $previewFormat . "';\n";
        ?>

    Sorry for the mess… I’ll post a link as soon as I upload it to my server.
    https://noisychaos.com/external/wp-work/live-comment-preview.zip

    oops

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Plugin: Live Comment Preview] any updates for WP 2.6 and 2.7?’ is closed to new replies.