/**
* gets the star rating of the item from the int rating
*
* @param string $start_url The url which will be used to rate each item (the rating part of the url should be *rating*, EX: blog.php?page=rate&b=1&rating=*rating*)
* @param string $delete_url The url which will be used to remove the rating for the item
* @param int $average_rating The current rating of the item
* @param int $num_ratings The number of times the item has been rated
* @param int $user_rating The rating the user gave for the item
* @param bool $force_average If you want to force it to display the average score without the links to submit the rating
*/
function get_star_rating($start_url, $delete_url, $average_rating, $num_ratings, $user_rating, $force_average = false)
{
    global $auth, $config, $phpbb_root_path, $phpEx, $user, $blog_plugins, $blog_images_path;
    if (!$config['user_blog_enable_ratings']) {
        return false;
    }
    $temp = compact('start_url', 'delete_url', 'average_rating', 'num_ratings', 'user_rating', 'force_average');
    blog_plugins::plugin_do_ref('function_get_star_rating', $temp);
    extract($temp);
    $can_rate = $user->data['is_registered'] && !$force_average && $user_rating === false ? true : false;
    // If it has not had any ratings yet, give it 1/2 the max for the rating
    if ($num_ratings == 0) {
        // If they can not rate the item and there are no ratings, do not show it at all.
        if (!$can_rate) {
            return '';
        }
        $average_rating = ceil($config['user_blog_max_rating'] / 2);
    }
    // Some variables we'll need
    $star_green = $blog_images_path . 'star_green.gif';
    $star_grey = $blog_images_path . 'star_grey.gif';
    $star_orange = $blog_images_path . 'star_orange.gif';
    $star_red = $blog_images_path . 'star_red.gif';
    $star_remove = $blog_images_path . 'star_remove.gif';
    $final_code = $force_average ? sprintf($num_ratings == 1 ? $user->lang['AVERAGE_OF_RATING'] : $user->lang['AVERAGE_OF_RATINGS'], $num_ratings) . ':' : '';
    // A unique string that will get added to the rating.  So if the item is shown more than once, hovering over and trying to rate one doesn't mess up the other list.
    $unique_str = md5(microtime());
    $unique_str = "u_{$unique_str}_s_";
    // If the user has rated this already and we are not just getting the average, get the average as well.
    if ($user_rating !== false && !$force_average) {
        $final_code = get_star_rating($start_url, $delete_url, $average_rating, $num_ratings, $user_rating, true) . '';
        $average_rating = $user_rating;
    }
    $final_code .= $user_rating !== false && !$force_average ? $user->lang['MY_RATING'] . ': ' : '';
    $final_code .= '<div>';
    for ($i = $config['user_blog_min_rating']; $i <= $config['user_blog_max_rating']; $i++) {
        $title = $user_rating === false && !$force_average ? sprintf($user->lang['RATE_ME'], $i, $config['user_blog_max_rating']) : sprintf($user->lang['RATE_ME'], $average_rating, $config['user_blog_max_rating']);
        $final_code .= $can_rate ? '<a href="' . str_replace('*rating*', $i, $start_url) . '">' : '';
        $final_code .= '<img id="' . $unique_str . $i . '" ';
        if ($user_rating !== false && $i <= $user_rating && !$force_average) {
            $final_code .= 'src="' . $star_green . '" ';
        } else {
            if ($i <= $average_rating) {
                $final_code .= 'src="' . $star_orange . '" ';
            } else {
                $final_code .= 'src="' . $star_grey . '" ';
            }
        }
        $final_code .= $can_rate ? "onmouseover=\"ratingHover('{$i}', '{$unique_str}')\"  onmouseout=\"ratingUnHover('{$average_rating}', '{$unique_str}')\"  onmousedown=\"ratingDown('{$i}', '{$unique_str}')\"" : '';
        $final_code .= ' alt="' . $title . '" title="' . $title . '" />';
        $final_code .= $can_rate ? '</a>' : '';
    }
    // If required, we will add the remove rating icon at the end
    if ($user_rating !== false && !$force_average) {
        $final_code .= ' <a href="' . $delete_url . '"><img id="' . $unique_str . 'remove" src="' . $star_remove . '"  alt="' . $user->lang['REMOVE_RATING'] . '" title="' . $user->lang['REMOVE_RATING'] . '" /></a>';
    }
    $final_code .= '</div>';
    return $final_code;
}
/**
 * Display rating as 5 stars
 *
 * @param integer Number of stars
 * @param string Class name
 */
function star_rating($stars, $class = 'not-used-any-more')
{
    echo get_star_rating($stars, $class);
}
 /**
  * Handle blog data
  *
  * To handle the raw data gotten from the database
  *
  * @param int $id The id of the blog we want to handle
  * @param int|bool $trim_text If we want to trim the text or not(if true we will trim with the setting in $config['user_blog_user_text_limit'], else if it is an integer we will trim the text to that length)
  */
 public function handle_blog_data($id, $trim_text = false)
 {
     global $config, $user, $phpbb_root_path, $phpEx, $auth, $highlight_match;
     global $blog_attachment, $category_id;
     if (!isset(self::$blog[$id])) {
         return array();
     }
     $blog =& self::$blog[$id];
     $user_id = $blog['user_id'];
     blog_plugins::plugin_do('blog_handle_data_start');
     if ($trim_text !== false) {
         $blog_text = trim_text_length($id, false, $trim_text === true ? $config['user_blog_user_text_limit'] : intval($trim_text));
         $shortened = $blog_text === false ? false : true;
         $blog_text = $blog_text === false ? $blog['blog_text'] : $blog_text;
     } else {
         $blog_text = $blog['blog_text'];
         $shortened = false;
     }
     // censor the text of the subject
     $blog_subject = censor_text($blog['blog_subject']);
     // Parse BBCode and prepare the message for viewing
     $bbcode_options = ($blog['enable_bbcode'] ? OPTION_FLAG_BBCODE : 0) + ($blog['enable_smilies'] ? OPTION_FLAG_SMILIES : 0) + ($blog['enable_magic_url'] ? OPTION_FLAG_LINKS : 0);
     $blog_text = generate_text_for_display($blog_text, $blog['bbcode_uid'], $blog['bbcode_bitfield'], $bbcode_options);
     if ($config['user_blog_enable_ratings']) {
         $rating_data = get_user_blog_rating_data($user->data['user_id']);
         $rate_url = blog_url($user_id, $id, false, array('page' => 'rate', 'rating' => '*rating*'));
         $delete_rate_url = blog_url($user_id, $id, false, array('page' => 'rate', 'delete' => $id));
     }
     // For Highlighting
     if ($highlight_match) {
         $blog_subject = preg_replace('#(?!<.*)(?<!\\w)(' . $highlight_match . ')(?!\\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\\1</span>', $blog_subject);
         $blog_text = preg_replace('#(?!<.*)(?<!\\w)(' . $highlight_match . ')(?!\\w|[^<>]*(?:</s(?:cript|tyle))?>)#is', '<span class="posthilit">\\1</span>', $blog_text);
     }
     $reply_count = $this->get_reply_data('reply_count', $id);
     $blog['blog_read_count'] = $user->data['user_id'] != $user_id ? $blog['blog_read_count'] + 1 : $blog['blog_read_count'];
     // Polls
     $poll_options = $my_vote = array();
     $total_votes = 0;
     foreach ($blog['poll_votes'] as $option_id => $poll_row) {
         if ($option_id !== 'my_vote') {
             $total_votes += $poll_row['votes'];
         } else {
             $my_vote = $poll_row;
         }
     }
     foreach ($blog['poll_options'] as $option_id => $poll_row) {
         $option_pct = $total_votes > 0 && isset($blog['poll_votes'][$option_id]['votes']) ? $blog['poll_votes'][$option_id]['votes'] / $total_votes : 0;
         $option_pct_txt = sprintf("%.1d%%", $option_pct * 100);
         $poll_options[] = array('POLL_OPTION_ID' => $option_id, 'POLL_OPTION_CAPTION' => generate_text_for_display($poll_row['poll_option_text'], $blog['bbcode_uid'], $blog['bbcode_bitfield'], $bbcode_options), 'POLL_OPTION_RESULT' => isset($blog['poll_votes'][$option_id]['votes']) ? $blog['poll_votes'][$option_id]['votes'] : 0, 'POLL_OPTION_PERCENT' => $option_pct_txt, 'POLL_OPTION_PCT' => round($option_pct * 100), 'POLL_OPTION_IMG' => $user->img('poll_center', $option_pct_txt, round($option_pct * 250)), 'POLL_OPTION_VOTED' => in_array($option_id, $my_vote) ? true : false);
     }
     $s_can_vote = (!sizeof($my_vote) && check_blog_permissions('blog', 'vote', true, $id) || $auth->acl_get('u_blog_vote_change') && $blog['poll_vote_change']) && ($blog['poll_length'] != 0 && $blog['poll_length'] > time() || $blog['poll_length'] == 0) ? true : false;
     // Attachments
     $update_count = $attachments = array();
     parse_attachments_for_view($blog_text, $blog['attachment_data'], $update_count);
     foreach ($blog['attachment_data'] as $i => $attachment) {
         $attachments[]['DISPLAY_ATTACHMENT'] = $attachment;
     }
     $blog_row = array('ID' => $id, 'MESSAGE' => $blog_text, 'DATE' => $user->format_date($blog['blog_time']), 'DELETED_MESSAGE' => $blog['deleted_message'], 'EDIT_REASON' => $blog['edit_reason'], 'EDITED_MESSAGE' => $blog['edited_message'], 'EXTRA' => '', 'POLL_QUESTION' => generate_text_for_display($blog['poll_title'], $blog['bbcode_uid'], $blog['bbcode_bitfield'], $bbcode_options), 'RATING_STRING' => $config['user_blog_enable_ratings'] ? get_star_rating($rate_url, $delete_rate_url, $blog['rating'], $blog['num_ratings'], isset($rating_data[$id]) ? $rating_data[$id] : false, $user->data['user_id'] == $user_id ? true : false) : false, 'NUM_REPLIES' => $reply_count, 'REPLIES' => '<a href="' . blog_url($user_id, $id, false, array('anchor' => 'replies')) . '">' . ($reply_count == 1 ? $user->lang['ONE_COMMENT'] : sprintf($user->lang['CNT_COMMENTS'], $reply_count)) . '</a>', 'TITLE' => $blog_subject, 'TOTAL_VOTES' => $total_votes, 'USER_FULL' => self::$user[$user_id]['username_full'], 'VIEWS' => $blog['blog_read_count'] == 1 ? $user->lang['ONE_VIEW'] : sprintf($user->lang['CNT_VIEWS'], $blog['blog_read_count']), 'L_MAX_VOTES' => $blog['poll_max_options'] == 1 ? $user->lang['MAX_OPTION_SELECT'] : sprintf($user->lang['MAX_OPTIONS_SELECT'], $blog['poll_max_options']), 'L_POLL_LENGTH' => $blog['poll_length'] ? sprintf($user->lang[$blog['poll_length'] > time() ? 'POLL_RUN_TILL' : 'POLL_ENDED_AT'], $user->format_date($blog['poll_length'])) : '', 'U_APPROVE' => check_blog_permissions('blog', 'approve', true, $id) && $blog['blog_approved'] == 0 && !$shortened ? blog_url(false, $id, false, array('page' => 'blog', 'mode' => 'approve')) : '', 'U_DELETE' => check_blog_permissions('blog', 'delete', true, $id) ? blog_url(false, $id, false, array('page' => 'blog', 'mode' => 'delete')) : '', 'U_DIGG' => 'http://digg.com/submit?phase=2&amp;url=' . urlencode(generate_board_url() . '/blog.' . $phpEx . '?b=' . $blog['blog_id']), 'U_EDIT' => check_blog_permissions('blog', 'edit', true, $id) ? blog_url(false, $id, false, array('page' => 'blog', 'mode' => 'edit')) : '', 'U_QUOTE' => check_blog_permissions('reply', 'quote', true, $id) ? blog_url(false, $id, false, array('page' => 'reply', 'mode' => 'quote')) : '', 'U_REPORT' => check_blog_permissions('blog', 'report', true, $id) ? blog_url(false, $id, false, array('page' => 'blog', 'mode' => 'report')) : '', 'U_REPLY' => check_blog_permissions('reply', 'add', true, $id) ? blog_url(false, $id, false, array('page' => 'reply', 'mode' => 'add')) : '', 'U_VIEW' => blog_url($user_id, $id), 'U_VIEW_PERMANENT' => blog_url(false, $id, false, array(), array(), true), 'U_WARN' => $auth->acl_get('m_warn') && $user_id != $user->data['user_id'] && $user_id != ANONYMOUS ? append_sid("{$phpbb_root_path}mcp.{$phpEx}", "i=warn&amp;mode=warn_user&amp;u={$user_id}", true, $user->session_id) : '', 'S_CAN_VOTE' => $s_can_vote, 'S_DELETED' => $blog['blog_deleted'] ? true : false, 'S_DISPLAY_NOTICE' => !$auth->acl_get('u_download') && $blog['blog_attachment'] && sizeof($blog['attachment_data']) ? true : false, 'S_DISPLAY_RESULTS' => !$s_can_vote || $s_can_vote && sizeof($my_vote) || isset($_GET['view']) && $_GET['view'] == 'viewpoll' ? true : false, 'S_HAS_ATTACHMENTS' => $blog['blog_attachment'] ? true : false, 'S_HAS_POLL' => $blog['poll_title'] ? true : false, 'S_IS_MULTI_CHOICE' => $blog['poll_max_options'] > 1 ? true : false, 'S_REPORTED' => $blog['blog_reported'] && $auth->acl_get('m_blogreport') ? true : false, 'S_SHORTENED' => $shortened, 'S_UNAPPROVED' => !$blog['blog_approved'] && ($user_id == $user->data['user_id'] || $auth->acl_get('m_blogapprove')) ? true : false, 'attachment' => $attachments, 'poll_option' => $poll_options);
     blog_plugins::plugin_do_ref('blog_handle_data_end', $blog_row);
     return $blog_row;
 }
Exemple #4
0
// Newness in days
if ($product->sale_price) {
    // Sale will be added through action hook
} else {
    if (hb_is_out_of_stock()) {
        echo '<span class="out-of-stock-badge">' . __('Sold out', 'hbthemes') . '</span>';
    } else {
        if (time() - 60 * 60 * 24 * $newness < $postdatestamp) {
            // If the product was published within the newness time frame display the new badge
            echo '<span class="wc-new-badge">' . __('New', 'hbthemes') . '</span>';
        }
    }
}
?>
		<?php 
get_star_rating();
?>

		<?php 
echo '<span class="product-loading-icon preloading hb-spin"></span>';
?>

		<?php 
$out_of_stock_class = ' add_to_cart_button';
if (hb_is_out_of_stock()) {
    $out_of_stock_class = ' no-action';
}
if (!$product->is_in_stock()) {
    $hb_add_to_cart = '<a href="' . apply_filters('out_of_stock_add_to_cart_url', get_permalink($product->id)) . '" class="hb-buy-button' . $out_of_stock_class . '">' . apply_filters('out_of_stock_add_to_cart_text', __('READ MORE', 'woocommerce')) . '</a>';
    $out_of_stock_badge = '<span class="hb-out-stock">' . __('OUT OF STOCK', 'woocommerce') . '</span>';
} else {
Exemple #5
0
    /**
     * Get table from ratings data
     *
     * @param array ratings data
     * @param array params
     */
    function get_rating_table($ratings, $params)
    {
        $ratings_count = $ratings['all_ratings'];
        $average_real = $ratings_count > 0 ? number_format($ratings["summary"] / $ratings_count, 1, ".", "") : 0;
        $average = ceil($average_real / 5 * 100);
        $table = '<table class="rating_summary" cellspacing="1">';
        foreach ($ratings as $r => $count) {
            // Print a row for each star with formed data
            if (!is_int($r)) {
                continue;
            }
            $star_average = $ratings_count > 0 ? ceil($count / $ratings_count * 100) : 0;
            switch ($params['rating_summary_star_totals']) {
                case 'count':
                    $star_value = '(' . $count . ')';
                    break;
                case 'percent':
                    $star_value = '(' . $star_average . '%)';
                    break;
                case 'none':
                default:
                    $star_value = "";
                    break;
            }
            $table .= '<tr><th>' . $r . ' ' . T_('star') . ':</th>
				<td class="progress"><div style="width:' . $star_average . '%">&nbsp;</div></td>
				<td>' . $star_value . '</td><tr>';
        }
        $table .= '</table>';
        $table .= '<div class="rating_summary_total">
			' . $ratings_count . ' ' . ($ratings_count > 1 ? T_('ratings') : T_('rating')) . '
			<div class="average_rating">' . T_('Average user rating') . ':<br />
			' . get_star_rating($average_real) . '<span>(' . $average_real . ')</span>
			</div></div><div class="clear"></div>';
        return $table;
    }