ID, '_bsf_post_type', true); if($type){ add_action( 'wp_head', 'frontend_style' ); add_action('wp_enqueue_scripts', 'enque'); } } function enque() { wp_enqueue_style('rating_style', plugin_dir_url(__FILE__) . 'css/jquery.rating.css'); wp_enqueue_script('jquery_rating', plugin_dir_url(__FILE__) . 'js/jquery.rating.min.js', array('jquery')); } function frontend_style() { wp_register_style( 'bsf_style', plugins_url('/css/style.css', __FILE__) ); wp_enqueue_style('bsf_style'); } function bsf_initialize_bsf_meta_boxes() { if ( ! class_exists( 'bsf_Meta_Box' ) ) require_once plugin_dir_path( __FILE__ ).'init.php'; } //Function to display the rich snippet output below the content function display_rich_snippet($content) { global $post; $args_color = get_option('bsf_custom'); $id = $post->ID; $type = get_post_meta($id, '_bsf_post_type', true); if($type == '1') { global $post; $args_review = get_option('bsf_review'); $review = $content; $review .= '
'; if($args_review['review_title'] != "") $review .= '
'.$args_review['review_title'].'
'; $review .= '
'; $item = get_post_meta( $post->ID, '_bsf_item_name', true ); $rating = get_post_meta( $post->ID, '_bsf_rating', true ); $reviewer = get_post_meta( $post->ID, '_bsf_item_reviewer', true); $post_date = get_the_date('Y-m-d'); if(trim($reviewer) != "") { if($args_review['item_reviewer'] != "") $review .= '"; } if(isset($args_review['review_date'])) { if( $args_review['review_date'] != "") $review .= "
".$args_review['review_date'] ."
"; $review .= "
"; } if(trim($item) != "") { if( $args_review['item_name'] != "") $review .= "
".$args_review['item_name']."
"; $review .= "
".$item."
"; } if(trim($rating) != "") { if( $args_review['item_rating'] != "") //$review .= ''; $review .= "
".$args_review['item_rating']."
"; $review .= "
".$rating.""; for($i = 1; $i<=ceil($rating); $i++) { $review .= ''; } for($j = 0; $j<=5-ceil($rating); $j++) { if($j) $review .= ''; } $review .= '
'; } $review .= "
"; return ( is_single() || is_page() ) ? $review : $content; } else if($type == '2') { global $post; $args_event = get_option('bsf_event'); $event = $content; $event .= '
'; if($args_event['snippet_title'] != "") $event .= '
'.$args_event['snippet_title'].'
'; $event .= '
'; $event_title = get_post_meta( $post->ID, '_bsf_event_title', true ); $event_org = get_post_meta( $post->ID, '_bsf_event_organization', true ); $event_street = get_post_meta( $post->ID, '_bsf_event_street', true ); $event_local = get_post_meta( $post->ID, '_bsf_event_local', true ); $event_region = get_post_meta( $post->ID, '_bsf_event_region', true ); $event_postal_code = get_post_meta( $post->ID, '_bsf_event_postal_code', true ); $event_start_date = get_post_meta( $post->ID, '_bsf_event_start_date', true ); $event_end_date = get_post_meta( $post->ID, '_bsf_event_end_date', true ); $event_ticket_url = get_post_meta( $post->ID, '_bsf_event_ticket_url', true ); $event_price = get_post_meta( $post->ID, '_bsf_event_price', true ); $event_cur = get_post_meta( $post->ID, '_bsf_event_cur', true ); //$event_geo_latitude = get_post_meta( $post->ID, '_bsf_event_geo_latitude', true ); //$event_geo_longitude = get_post_meta( $post->ID, '_bsf_event_geo_longitude', true ); /*$event_photo = get_post_meta( $post->ID, '_bsf_event_photo', true ); if(trim($event_photo) != "") { $event .= '
'; } else { $event .= ''; }*/ $event .= '
'; if(trim($event_title) != "") { if( $args_event['event_title']) $event .= '
'.$args_event['event_title'].'
'; $event .='
'.$event_title.'
'; } if(trim($event_org) != "") { if( $args_event['event_location'] != "") $event .= '
'.$args_event['event_location'].'
'; $event .='
'.$event_org.','; } if(trim($event_street) != "") $event .= ' '.$event_street.','; if(trim($event_local) != "") $event .= ''.$event_local.','; if(trim($event_region) != "") $event .= ''.$event_region.''; if(trim($event_postal_code) != "") $event .= ''.$event_postal_code.''; $event .= ''; //$event .= ' '; //if(trim($event_geo_latitude) != "") // $event .= ''; //if(trim($event_geo_longitude) != "") // $event .= ''; //$event .= ''; $event .='
'; if(trim($event_start_date) != "") { if( $args_event['start_time'] != "") $event .= '
'.$args_event['start_time'].'
'; $event .= '
'.$event_start_date.'
'; } if(trim($event_end_date) != "") { if( $args_event['end_time'] != "") $event .= '
'.$args_event['end_time'].'
'; $event .= '
'.$event_end_date.'
'; } if(trim($event_price) != "") { if($args_event['events_price'] != "") $event .= '
'.$args_event['events_price'].'
'; $event .= '
'.$event_cur.''.' '.$event_price.'
'; //$event .= ''; } $event .= '
'; return ( is_single() || is_page() ) ? $event : $content; } else if($type == '4') { global $post; $organization = $content; $organization .= '
Organization Brief :
'; $organization .= '
'; $org_name = get_post_meta( $post->ID,'_bsf_organization_name', true ); $org_url = get_post_meta( $post->ID,'_bsf_organization_url', true ); $org_tel = get_post_meta( $post->ID,'_bsf_organization_tel', true ); $org_street = get_post_meta( $post->ID,'_bsf_organization_street', true ); $org_local = get_post_meta( $post->ID,'_bsf_organization_local', true ); $org_region = get_post_meta( $post->ID,'_bsf_organization_region', true ); $org_zip = get_post_meta( $post->ID,'_bsf_organization_zip', true ); $org_country = get_post_meta( $post->ID,'_bsf_organization_country', true ); $org_latitude = get_post_meta( $post->ID,'_bsf_organization_latitude', true ); $org_longitude = get_post_meta( $post->ID,'_bsf_organization_longitude', true ); if(trim($org_name) != "") $organization .= 'Organization Name : '.$org_name.'
'; if(trim($org_url) != "") $organization .= 'Website : '.$org_url.''; if(trim($org_tel) != "") $organization .= 'Telephone No. : '.$org_tel.''; if(trim($org_street) != "") $organization .= 'Address : '.$org_street.''; if(trim($org_local) != "") $organization .= ''.$org_local.''; if(trim($org_region) != "") $organization .= ''.$org_region.''; if(trim($org_zip) != "") $organization .= ''.$org_zip.''; if(trim($org_country) != "") $organization .= ''.$org_country.' '; if(trim($org_latitude) != "") $organization .= 'GEO Location : '.$org_latitude.' - '; if(trim($org_longitude) != "") $organization .= ''.$org_longitude.' '; $organization .= '
'; return ( is_single() || is_page() ) ? $organization : $content; } else if($type == '5') { global $post; $args_person = get_option('bsf_person'); $people = $content; $people .= '
'; if($args_person['snippet_title'] != "") $people .= '
'.$args_person['snippet_title'].'
'; $people .= '
'; $people_fn = get_post_meta( $post->ID, '_bsf_people_fn', true ); $people_nickname = get_post_meta( $post->ID, '_bsf_people_nickname', true ); $people_photo = get_post_meta( $post->ID, '_bsf_people_photo', true ); $people_job_title = get_post_meta( $post->ID, '_bsf_people_job_title', true ); $people_website = get_post_meta( $post->ID, '_bsf_people_website', true ); $people_company = get_post_meta( $post->ID, '_bsf_people_company', true ); $people_local = get_post_meta( $post->ID, '_bsf_people_local', true ); $people_region = get_post_meta( $post->ID, '_bsf_people_region', true ); $people_street = get_post_meta( $post->ID, '_bsf_people_street', true ); $people_postal = get_post_meta( $post->ID, '_bsf_people_postal', true ); if(trim($people_photo) != "") { $people .= '
Photo of'.$people_fn.'
'; } else { $people .= ''; } $people .= '
'; if(trim($people_fn) != "") { if($args_person['person_name'] != "") $people .= '
'.$args_person['person_name'].'
'; $people .= '
'.$people_fn.'
'; } if(trim($people_nickname) != "") { if($args_person['person_nickname'] != "") $people .= '
'.$args_person['person_nickname'].'
'; $people .= '
('.$people_nickname.')
'; } if(trim($people_website) != "") { if($args_person['person_website'] != "") $people .= '
'.$args_person['person_website'].'
'; $people .= '
'; } if(trim($people_job_title) != "") { if($args_person['person_job_title'] != "") $people .= '
'.$args_person['person_job_title'].'
'; $people .= '
'.$people_job_title.'
'; } if(trim($people_company) != "") { if($args_person['person_company'] != "") $people .= '
'; $people .= '
'.$args_person['person_company'].'
'; $people .= '
'.$people_company.'
'; $people .= '
'; } if(trim($people_street) != "") { if($args_person['person_address'] != "") $people .= '
'.$args_person['person_address'].'
'; $people .= '
'.$people_street.',
'; } if(trim($people_local) != "") { //if($args_person['person_address'] != "") //$people .= '
'.$args_person['person_address'].'
'; //$people .= ''; $people .= ''.$people_local.', '; } if(trim($people_region) != "") { $people .= ''.$people_region.', '; } if(trim($people_postal) != "") { $people .= ''.$people_postal.''; } $people .= '
'; $people .= '
'; return ( is_single() || is_page() ) ? $people : $content; } else if($type == '6') { global $post; $args_product = get_option('bsf_product'); $product = $content; $product .= '
'; if($args_product['snippet_title'] != "") $product .= '
'.$args_product['snippet_title']; $product .= bsf_do_rating(); $product .= '
'; $product .= '
'; $product_rating = get_post_meta( $post->ID, '_bsf_product_rating', true); $product_brand = get_post_meta( $post->ID, '_bsf_product_brand', true); $product_name = get_post_meta( $post->ID, '_bsf_product_name', true); $product_image = get_post_meta($post->ID, '_bsf_product_image', true); $product_cat = get_post_meta($post->ID, '_bsf_product_cat', true); $product_price = get_post_meta($post->ID, '_bsf_product_price', true); $product_cur = get_post_meta($post->ID, '_bsf_product_cur', true); $product_status = get_post_meta($post->ID, '_bsf_product_status', true); if(trim($product_status) == "out_of_stock") $availability = "Out of Stock"; else if(trim($product_status) == "in_stock") $availability = "Available in Stock"; else if(trim($product_status) == "instore_only") $availability = "Available in Store Only"; else if(trim($product_status) == "preorder") $availability = "Pre-Order Only"; if(trim($product_image) != "") { $product .= '
'; } else { $product .= ''; } $product .= '
'; if(trim($product_rating) != "") { if($args_product['product_brand'] != "") $product .= '
'.$args_product['product_rating'].'
'; $product .= '
'; for($i = 1; $i<=ceil($product_rating); $i++) { $product .= ''; } for($j = 0; $j<=5-ceil($product_rating); $j++) { if($j) $product .= ''; } $product .= '
'; } $product .= '
'; if($args_product['product_agr'] != "") { $product .= '
'.$args_product['product_agr'].'
'; } $product .= '
'; $product .= ''.average_rating().''; $product .= ' based on '.rating_count().' votes
'; if(trim($product_brand) != "") { if($args_product['product_brand'] != "") $product .= '
'.$args_product['product_brand'].'
'; $product .= '
'.$product_brand.'
'; } if(trim($product_name) != "") { if($args_product['product_name'] != "") $product .= '
'.$args_product['product_name'].'
'; $product .= '
'.$product_name.'
'; } if(trim($product_price) != "") { if($args_product['product_price'] != "") $product .= '
'.$args_product['product_price'].'
'; $product .= '
'.$product_cur.''.' '.$product_price.'
'; if(trim($product_status) != "") { if($args_product['product_avail'] != "") $product .= '
'.$args_product['product_avail'].'
'; $product .= '
'.$availability.'
'; } $product .= '
'; } /*if(trim($product_status) != "") { if($args_product['product_avail'] != "") $product .= '
'.$args_product['product_avail'].'
'; $product .= '
'.$availability.'
'; }*/ $product .= '
'; // $product .= getPostLikeLink($post->ID); return ( is_single() || is_page() ) ? $product : $content; } else if($type == '7') { global $post; $recipe = $content; $recipe .= '
'; $args_recipe = get_option('bsf_recipe'); if($args_recipe['snippet_title'] != "" ) { $recipe .= '
'.$args_recipe['snippet_title']; $recipe .= bsf_do_rating(); } $recipe .= '
'; $recipe .= '
'; $recipes_name = get_post_meta( $post->ID, '_bsf_recipes_name', true ); $recipes_preptime = get_post_meta( $post->ID, '_bsf_recipes_preptime', true ); $recipes_cooktime = get_post_meta( $post->ID, '_bsf_recipes_cooktime', true ); $recipes_totaltime = get_post_meta( $post->ID, '_bsf_recipes_totaltime', true ); $recipes_photo = get_post_meta( $post->ID, '_bsf_recipes_photo', true ); $recipes_desc = get_post_meta( $post->ID, '_bsf_recipes_desc', true ); $recipes_ingredient = get_post_meta( $post->ID, '_bsf_recipes_ingredient', true ); $count = rating_count(); $agregate = average_rating(); if(trim($recipes_photo) != "") { $recipe .= '
'; } else { $recipe .= ''; } $recipe .= '
'; if(trim($recipes_name) != "") { if($args_recipe['recipe_name'] != "") $recipe .= '
'.$args_recipe['recipe_name'].'
'; $recipe .= '
'.$recipes_name.'
'; } $recipe .= '
'.$args_recipe['recipe_pub'].'
'; if(trim($recipes_preptime) != "") { if($args_recipe['recipe_prep'] != "") $recipe .= '
'.$args_recipe['recipe_prep'].'
'; $recipe .= '
'; } if(trim($recipes_cooktime) != "") { if($args_recipe['recipe_cook'] != "") $recipe .= '
'.$args_recipe['recipe_cook'].'
'; $recipe .= '
'; } if(trim($recipes_totaltime) != "") { if($args_recipe['recipe_time'] != "") $recipe .= '
'.$args_recipe['recipe_time'].'
'; $recipe .= '
'; } if($args_recipe['recipe_rating'] != "") $recipe .= '
'.$args_recipe['recipe_rating'].'
'; $recipe .= '
'.$agregate.''; for($i = 1; $i<=ceil($agregate); $i++) { $recipe .= ''; } for($j = 0; $j<=5-ceil($agregate); $j++) { if($j) $recipe .= ''; } $recipe .= ' Based on '.$count.' Review(s)
'; $recipe .= '
'; return ( is_single() || is_page() ) ? $recipe : $content; } else if($type == '8') { global $post; $args_soft = get_option('bsf_software'); $software = $content; $software .= '
'; if($args_soft['snippet_title'] != "" ) $software .= '
'.$args_soft['snippet_title']; $software .= bsf_do_rating(); $software .= '
'; $software .= '
'; $software_rating = get_post_meta( $post->ID, '_bsf_software_rating', true); $software_name = get_post_meta( $post->ID, '_bsf_software_name', true ); $software_desc = get_post_meta( $post->ID, '_bsf_software_desc', true ); $software_landing = get_post_meta( $post->ID, '_bsf_software_landing', true ); $software_image = get_post_meta( $post->ID, '_bsf_software_image', true ); $software_price = get_post_meta( $post->ID, '_bsf_software_price', true ); $software_cur = get_post_meta($post->ID, '_bsf_software_cur', true); $software_os = get_post_meta( $post->ID, '_bsf_software_os', true ); $software_cat = get_post_meta( $post->ID, '_bsf_software_cat', true ); if(trim($software_image) != "") { $software .= '
'; } else { $software .= ''; } $software .= '
'; ////////////////////////////////////////////////////////////////////// if(trim($software_rating) != "") { //if($args_soft['product_brand'] != "") $software .= '
'.$args_soft['software_rating'].'
'; $software .= '
'; for($i = 1; $i<=ceil($software_rating); $i++) { $software .= ''; } for($j = 0; $j<=5-ceil($software_rating); $j++) { if($j) $software .= ''; } $software .= '
'; } $software .= '
'; //if($args_soft['software_agr'] != "") //{ $software .= '
'.$args_soft['software_agr'].'
'; //} $software .= '
'; $software .= ''.average_rating().''; $software .= ' based on '.rating_count().' votes
'; ////////////////////////////////////////////////////////////////////// /*if(trim($software_rating) != "") { if($args_soft['software_rating'] != "") $software .= '
'.$args_soft['software_rating'].'
'; $software .= '
'.$software_rating.'
'; for($i = 1; $i<=ceil($software_rating); $i++) { $software .= ''; } for($j = 0; $j<=5-ceil($software_rating); $j++) { if($j) $software .= ''; } $software .= '
'; }*/ if(trim($software_name) != "") { if($args_soft['software_name'] != "") $software .= '
'.$args_soft['software_name'].'
'; $software .= '
'.$software_name.'
'; } if(trim($software_os) != "") { if($args_soft['software_os'] != "") $software .= '
'.$args_soft['software_os'].'
'; $software .= '
'.$software_os.'
'; } if(trim($software_cat) != "") { //if($args_soft['software_os'] != "") $software .= '
Software Category
'; $software .= '
'.$software_cat.'
'; } if(trim($software_price) != "") { if($args_soft['software_price'] != "") $software .= '
'.$args_soft['software_price'].'
'; $software .= '
'.$software_cur.' '.$software_price.'
'; } if(trim($software_desc) != "") { if($args_soft['software_desc'] != "") $software .= '
'.$args_soft['software_desc'].'
'; $software .= '
'.$software_desc.'
'; } if(trim($software_landing) != "") { if($args_soft['software_website'] != "") $software .= '
'.$args_soft['software_website'].'
'; $software .= '
'; } $software .= '
'; return ( is_single() || is_page() ) ? $software : $content; } else if($type == '9') { global $post; $args_video = get_option('bsf_video'); $video = $content; $video .= '
'; if($args_video['snippet_title'] != "" ) $video .= '
'.$args_video['snippet_title'].'
'; $video .= '
'; $video_title = get_post_meta( $post->ID, '_bsf_video_title', true ); $video_desc = get_post_meta( $post->ID, '_bsf_video_desc', true ); $video_thumb = get_post_meta( $post->ID, '_bsf_video_thumb', true ); $video_url = get_post_meta( $post->ID, '_bsf_video_url', true ); $video_emb_url = get_post_meta( $post->ID, '_bsf_video_emb_url', true ); $video_duration = get_post_meta( $post->ID, '_bsf_video_duration', true ); $video_date = get_post_meta( $post->ID, '_bsf_video_date', true ); if(trim($video_url) != "") { $video .= '
'.$video_title.'
'; } elseif (trim($video_emb_url) != "") { $video .= '
'.$video_title.'
'; } else { $video .= ''; } $video .= '
'; if(trim($video_title) != "") { if($args_video['video_title'] != "" ) $video .= '
'.$args_video['video_title'].'
'; $video .= '
'.$video_title.'
'; } if(trim($video_desc) != "") { if($args_video['video_desc'] != "" ) $video .= '
'.$args_video['video_desc'].'
'; $video .= '

'.$video_desc.'

'; } if(trim($video_thumb) != "") $video .= ''; if(trim($video_url) != ""){ $video .= ''; } elseif(trim($video_emb_url) != ""){ $video .= ''; } if(trim($video_duration) != "") $video .= ''; if(trim($video_date) != "") $video .= ''; $video .= '
'; return ( is_single() || is_page() ) ? $video : $content; } else if($type == '10') { global $post; $article = $content; $args_article = get_option('bsf_article'); $article_title = get_post_meta( $post->ID, '_bsf_article_title', true ); $article_name = get_post_meta( $post->ID, '_bsf_article_name', true ); $article_desc = get_post_meta( $post->ID, '_bsf_article_desc', true ); $article_image = get_post_meta( $post->ID, '_bsf_article_image', true ); $article_author = get_post_meta( $post->ID, '_bsf_article_author', true ); $article_publisher = get_post_meta( $post->ID, '_bsf_article_publisher', true ); $article_publisher_logo = get_post_meta( $post->ID, '_bsf_article_publisher_logo', true ); $article .= '
'; if($args_article['snippet_title'] != "" ) { $article .= '
'.$args_article['snippet_title']; $article .= '
'; } $article .= '
'; if(trim($article_image) != "") { $article .= '
'; $article .= ''; $article .= ''; $article .= ''; $article .= ''; $article .= '
'; } else { $article .= ''; } $article .= '
'; if(trim($article_name) != "") { if($args_article['article_name'] != "") $article .= '
'.$args_article['article_name'].'
'; $article .= '
'.$article_name.'
'; } if(trim($article_desc) != "") { if($args_article['article_desc'] != "") $article .= '
'.$args_article['article_desc'].'
'; $article .= '
'.$article_desc.'
'; } if(trim($article_author) != "") { if($args_article['article_author'] != "") $article .= '
'.$args_article['article_author'].'
'; $article .= '
'; } if(trim($article_publisher) != "") { if($args_article['article_publisher'] != "") $article .= '
'.$args_article['article_publisher'].'
'; $article .= '
'; $article .= '
'.$article_publisher.'
'; if(trim($article_publisher_logo) != "") { if($args_article['article_publisher_logo'] != "") $article .= '
'.$args_article['article_publisher_logo'].'
'; $article .= '
'; $article .= ''; $article .= ''; $article .= ''; $article .= ''; $article .= '
'; } $article .= '
'; } $article .= ''; $article .= ''; $article .= ''; $article .= '
'; return ( is_single() || is_page() ) ? $article : $content; }else if($type == '11') { global $post; $service = $content; $args_service = get_option('bsf_service'); $service_type = get_post_meta( $post->ID, '_bsf_service_type', true ); $service_area = get_post_meta( $post->ID, '_bsf_service_area', true ); $service_desc = get_post_meta( $post->ID, '_bsf_service_desc', true ); $service_image = get_post_meta( $post->ID, '_bsf_service_image', true ); $service_provider_name = get_post_meta( $post->ID, '_bsf_service_provider', true ); $service_rating = get_post_meta( $post->ID, '_bsf_service_rating', true ); $service_rating_switch = get_post_meta( $post->ID, '_bsf_service_rating_switch', true ); $service_channel = get_permalink( $post->ID ); $service_url_link = $args_service['service_url_link'] != ''? $args_service['service_url_link'] : "Click Here For More Info"; $service .= '
'; if($args_service['snippet_title'] != "" ) { $service .= '
'.$args_service['snippet_title']; if ( $service_rating_switch == 'enable' ) { $service .= bsf_do_rating(); } $service .= '
'; } $service .= '
'; if(trim($service_image) != "") { $service .= '
'; $service .= ''; $service .= '
'; } else { $service .= ''; } $service .= '
'; if( average_rating() > 0 ){ if($args_service['service_rating'] != "") { $service .= '
'; $service .= '
'.$args_service['service_rating'].'
'; $service .= '
'; $service .= ''.average_rating().''; $service .= ' based on '.rating_count().' votes
'; } } if(trim($service_type) != "") { if($args_service['service_type'] != "") $service .= '
'.$args_service['service_type'].'
'; $service .= '
'.$service_type.'
'; } if(trim($service_provider_name) != "") { if($args_service['service_provider_name'] != "") $service .= '
'.$args_service['service_provider_name'].'
'; $service .= '
'.$service_provider_name.'
'; } if(trim($service_area) != "") { if($args_service['service_area'] != "") $service .= '
'.$args_service['service_area'].'
'; $service .= '
'.$service_area.'
'; } if(trim($service_desc) != "") { if($args_service['service_desc'] != "") $service .= '
'.$args_service['service_desc'].'
'; $service .= '
'.$service_desc.'
'; } if(trim($service_channel) != "") { if($args_service['service_channel'] != "") $service .= '
'.$args_service['service_channel'].'
'; $service .= '
'; } $service .= '
'; return ( is_single() || is_page() ) ? $service : $content; } else { return $content; } } //Filter the content and return with rich snippet output add_filter('the_content','display_rich_snippet'); require_once(plugin_dir_path( __FILE__ ).'meta-boxes.php'); function get_the_ip() { if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) { return $_SERVER["HTTP_X_FORWARDED_FOR"]; } elseif (isset($_SERVER["HTTP_CLIENT_IP"])) { return $_SERVER["HTTP_CLIENT_IP"]; } else { return $_SERVER["REMOTE_ADDR"]; } } function average_rating() { // global $wpdb; global $post; $data = get_post_meta($post->ID, 'post-rating', false); $post_id = $post->ID; if( !empty($data) ) { $counter = 0; $average_rating = 0; foreach($data as $d) { $rating = $d['user_rating']; $average_rating = $average_rating + $rating; $counter++; } //round the average to the nearast 1/2 point return (round(($average_rating/$counter)*2,0)/2); } else { //no ratings return 'no rating'; } } function rating_count() { global $post; $data = get_post_meta($post->ID, 'post-rating', false); return count($data); } function bsf_do_rating() { global $post; $ip = get_the_ip(); $ip_array = array(); $data = get_post_meta($post->ID, 'post-rating', false); if( !empty($data)) { foreach($data as $d) { array_push($ip_array,$d['user_ip']); } if(!in_array($ip,$ip_array) ) { return display_rating(); } else if(in_array($ip,$ip_array) ) { $rating = get_previous_rating($ip, $data); $stars = bsf_display_rating($rating); return $stars; } } else { return display_rating(); } } function get_previous_rating($needle, $haystack, $strict = false) { foreach ($haystack as $item) { if (($strict ? $item === $needle : $item == $needle) || (is_array($item) && get_previous_rating($needle, $item, $strict))) { return @$item['user_rating']; } } return false; } function add_ajax_library() { $html = ''; echo $html; } function bsf_add_rating() { // ob_clean(); if(isset($_POST['star-review'])) $stars = $_POST['star-review']; else $stars = '0'; $ip = $_POST['ip']; $postid = $_POST['post_id']; $user_rating = array('post_id' => $postid, 'user_ip' => $ip, 'user_rating' => $stars); echo false == add_post_meta($postid, 'post-rating', $user_rating) ? 'Error adding your rating' : 'Ratings added successfully !'; die(); } function bsf_update_rating() { // ob_clean(); if(isset($_POST['star-review'])) $stars = $_POST['star-review']; else $stars = '0'; $ip = $_POST['ip']; $postid = $_POST['post_id']; $prev_data = get_post_meta($postid,'post-rating',true); $user_rating = array('post_id' => $postid, 'user_ip' => $ip, 'user_rating' => $stars); echo false == update_post_meta($postid, 'post-rating', $user_rating, $prev_data) ? 'Error updating your rating' : 'Ratings updated successfully !'; die(); } function display_rating() { global $post; $rating = '
'; $rating .= '
'; $rating .= ''; $rating .= ''; $rating .= ''; $rating .= ''; $rating .= ''; $rating .= ''; $rating .= ''; $rating .= '
'; $rating .= '
'; $script = ' '; $rating .= $script; return $rating; } function bsf_display_rating($n) { global $post; $rating = '
'; $rating .= '
'; $rating .= ''; $rating .= ''; $rating .= '
'; $rating .= '
'; $script = ' '; $rating .= $script; return $rating; }