Star Rating Plugin for PNG-24 Alpha Transparency

[ Plugin / Star Rating Plugin for PNG-24 Alpha Transparency / Leave Comment ]

1. Download and Explanation

2. Modify

고칠 곳 (modified) :: star-rating.php 파일

2.1 이미지 타입/피드 구별 classify image type (.png or else) and feed (or contents)

find below ::
	// check if half star occurs
	// e.g. [3.75 , 4.25) = 4 stars; [4.25 , 4.75) = 4.5 stars
	$halfstar = "";
	$star = round( $star * 2 );
		if ( $star % 2 ) {
			$halfstar = '<img src="' . $path . 'halfstar.' . $sr_ext . '" alt="&frac12;" title="&frac12;" width="16" height="16" />'; 
after add if (($sr_ext = "png") || !is_feed()) {::
 
	// check if half star occurs
	// e.g. [3.75 , 4.25) = 4 stars; [4.25 , 4.75) = 4.5 stars
	$halfstar = "";
	$star = round( $star * 2 );

    	// if png image    	
	if (($sr_ext = "png") || !is_feed()) {

		if ( $star % 2 ) {
			$halfstar = '<img src="' . $path . 'halfstar.' . $sr_ext . '" alt="&frac12;" title="&frac12;" width="16" height="16" />';

2.2 classify IE 5.5~6.9 or else

find this ::
	// check if half star occurs
	// e.g. [3.75 , 4.25) = 4 stars; [4.25 , 4.75) = 4.5 stars
	$halfstar = "";
	$star = round( $star * 2 );

    	// if png image    	
	if (($sr_ext = "png") || !is_feed()) {

		if ( $star % 2 ) {
			$halfstar = '<img src="' . $path . 'halfstar.' . $sr_ext . '" alt="&frac12;" title="&frac12;" width="16" height="16" />';
after add ::
	// check if half star occurs
	// e.g. [3.75 , 4.25) = 4 stars; [4.25 , 4.75) = 4.5 stars
	$halfstar = "";
	$star = round( $star * 2 );

    	// if png image    	
	if (($sr_ext = "png") || !is_feed()) {

    	    	// make sure that we are only replacing for the Windows versions of Internet
    	    	// Explorer 5.5+
    	    	$msie='/msie\s(5\.[5-9]|[6]\.[0-9]*).*(win)/i';
    	    	if ( !isset($_SERVER['HTTP_USER_AGENT']) ||
            	!preg_match($msie,$_SERVER['HTTP_USER_AGENT']) ||
            	preg_match('/opera/i',$_SERVER['HTTP_USER_AGENT']))
	     	{
		if ( $star % 2 ) {
			$halfstar = '<img src="' . $path . 'halfstar.' . $sr_ext . '" alt="&frac12;" title="&frac12;" width="16" height="16" />';

2.3 insert class into <img> tag [if image type is .png]

find and copy below ::
		if ( $star % 2 ) {
			$halfstar = '<img src="' . $path . 'halfstar.' . $sr_ext . '" alt="&frac12;" title="&frac12;" width="16" height="16" />';
			$star = floor( $star / 2 );
			$blankstar = $maxstar - $star - 1;
		}
		else
		{
			$star = $star / 2;
			$blankstar = $maxstar - $star;
		}

		// finally, generate html for rating stars
		$code = $prefix . str_repeat ('<img src="' . $path . 'star.' . $sr_ext . '" width="16" height="16" alt="&#9733;" title="&#9733;" />', $star) . $halfstar . str_repeat('<img src="' . $path . 'blankstar.' . $sr_ext . '" alt="&#9734;" title="&#9734;" width="16" height="16" />', $blankstar);
    	} 
create one more (inserted class and changed each image url to spacer.png) like below ::
		if ( $star % 2 ) {
			$halfstar = '<img src="' . $path . 'spacer.' . $sr_ext . '" class="halfstar" alt="&frac12;" title="&frac12;" width="16" height="16" />';
			$star = floor( $star / 2 );
			$blankstar = $maxstar - $star - 1;
		}
		else
		{
			$star = $star / 2;
			$blankstar = $maxstar - $star;
		}

		// finally, generate html for rating stars
		$code = $prefix . str_repeat ('<img src="' . $path . 'spacer.' . $sr_ext . '" class="star" width="16" height="16" alt="&#9733;" title="&#9733;" />', $star) . $halfstar . str_repeat('<img src="' . $path . 'spacer.' . $sr_ext . '" alt="&#9734;" title="&#9734;" class="blankstar" width="16" height="16" />', $blankstar);
    	} 

2.4 create css function

add css code above add_filter('the_content', 'ai_addstar'); ::

function ai_addstar_header() {
	global $sr_ext;
	if ($sr_ext = "png") {
		$path = get_bloginfo('url') . '/wp-content/plugins/star-rating/';
		echo '
	<style type="text/css">
		img {vertical-align:middle;}
		img.star, img.halfstar, img.blankstar {width: 16px; height: 16px; margin:0; padding:0;}
		img.star {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''.$path. 'star.png\', sizingMethod=scale);}
		img.halfstar {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''.$path. 'halfstar.png\', sizingMethod=scale);}
		img.blankstar {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''.$path. 'blankstar.png\', sizingMethod=scale);} 
	</style>
	';
	}
}

add_action('wp_head','ai_addstar_header');
add_filter('the_content', 'ai_addstar');

2.5 Edit whole function

use [IF, ELSE] and modify

3. the final files

  1. Ver. 0.1
    Original plugin »» Modified plugin
  2. Ver. 0.2
    Original »» Modified

4. 관련 링크 Related links

Categories : Wordpress