コード例 #1
0
ファイル: rating-widget.php プロジェクト: panser/wandromaha
     /**
      * Return rating's html.
      * 
      * @param {serial} $pUrid User rating id.
      * @param {string} $pElementClass Rating element class.
      * 
      * @version 1.3.3
      * 
      */
     private function GetRatingHtml($pUrid, $pElementClass, $pAddSchema = false, $pTitle = "", $pOptions = array())
     {
         if (RWLogger::IsOn()) {
             $params = func_get_args();
             RWLogger::LogEnterence("GetRatingHtml", $params);
         }
         $ratingData = '';
         foreach ($pOptions as $key => $val) {
             if (is_string($val) && '' !== trim($val)) {
                 $ratingData .= ' data-' . $key . '="' . esc_attr(trim($val)) . '"';
             }
         }
         $rating_html = '<div class="rw-ui-container rw-class-' . $pElementClass . ' rw-urid-' . $pUrid . '"' . $ratingData;
         if (true === $pAddSchema) {
             $data = $this->GetRatingDataByRatingID($pUrid);
             if (false !== $data) {
                 $title = mb_convert_to_utf8(trim($pTitle));
                 $rating_html .= ' itemscope itemtype="http://schema.org/Product">
 <span itemprop="name" style="position: fixed; top: 100%;">' . esc_html($pTitle) . '</span>
 <div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
     <meta itemprop="worstRating" content="0" />
     <meta itemprop="bestRating" content="5" />
     <meta itemprop="ratingValue" content="' . $data['rate'] . '" />
     <meta itemprop="ratingCount" content="' . $data['votes'] . '" />
 </div';
             }
         }
         $rating_html .= '></div>';
         return $rating_html;
     }
コード例 #2
0
    /**
     * Return rating's html.
     * 
     * @param {serial} $pUrid User rating id.
     * @param {string} $pElementClass Rating element class.
     * 
     * @version 1.3.3
     * 
     */
    function rw_rating_html($pUrid, $pElementClass, $pAddSchema = false, $pTitle = "")
    {
        $rating_html = '<div class="rw-ui-container rw-class-' . $pElementClass . ' rw-urid-' . $pUrid . '"></div>';
        if (true === $pAddSchema) {
            $details = array("uid" => WP_RW__USER_KEY, "rids" => $pUrid);
            $rw_ret_obj = self::RemoteCall("action/api/rating.php", $details);
            if (false !== $rw_ret_obj) {
                // Decode RW ret object.
                $rw_ret_obj = json_decode($rw_ret_obj);
                if (true === $rw_ret_obj->success && isset($rw_ret_obj->data) && count($rw_ret_obj->data) > 0) {
                    $rate = (double) $rw_ret_obj->data[0]->rate;
                    $votes = (double) $rw_ret_obj->data[0]->votes;
                    $calc_rate = $votes > 0 ? (double) $rate / (double) $votes : 0;
                    $title = mb_convert_to_utf8(trim($pTitle));
                    $rating_html .= '<div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
    <meta itemprop="worstRating" content="0" />
    <meta itemprop="bestRating" content="5" />
    <meta itemprop="ratingValue" content="' . $calc_rate . '" />
    <meta itemprop="ratingCount" content="' . $votes . '" />
</div>';
                }
            }
        }
        return $rating_html;
    }