function insertUSRList($atts) { $usrLang = get_option('usrLang'); global $MESSAGES, $CONFIGURATION; //Get all the needed attributes $readyToUseAttributes = getReadyToUseAttributes($atts); $atts = $readyToUseAttributes["usrAtts"]; $usrAttributes = $readyToUseAttributes["usrAttributeArray"]; //If there are more than 1 keys inside the array... if (count($atts) > 1) { //set a helper variable to calculate the average $sumRatingValues = 0; //Using a table because it looks better $usrlist = '<table class="usr">'; //Check if this is a custom image if (substr($usrAttributes["usrStarImage"], 0, 1) === "c") { $usrCustomImagesFolder = get_option('usrCustomImagesFolder'); } else { $usrCustomImagesFolder = FALSE; } //For each key/value pair inside the array... foreach ($atts as $value) { //If there is a pair... if (strpos($value, ':')) { //splitting Key:Value into two variables - User can't use a ':' inside Key list($splittedKey, $splittedValue) = explode(":", $value, 2); //If there is just a key... } else { $splittedKey = $value; $splittedValue = 0; } //Get the right rating formats $ratingValue = getUsableRating($splittedValue, $usrAttributes["usrMaxStars"]); $sumRatingValues = $sumRatingValues + $ratingValue; //Setting up the string with the right picture $usrlist .= '<tr><td>' . $splittedKey . ':</td><td>' . getImageString($ratingValue, $usrAttributes["usrStarImage"], $usrAttributes["usrMaxStars"], $usrAttributes["usrStarText"], $usrAttributes["usrPreviewImg"], $usrAttributes["usrStarSize"], false, 1, $usrCustomImagesFolder) . '</td></tr>'; } //If the average is needed... if ($usrAttributes["usrCalcAverage"] == "true") { $averageRating = getUsableRating(round($sumRatingValues / count($atts), 1), $usrAttributes["usrMaxStars"]); $usrlist .= '<tr><td style="border-top:1px solid;">' . $CONFIGURATION['AverageText'][$usrLang] . ':</td><td style="border-top:1px solid;">' . getImageString($averageRating, $usrAttributes["usrStarImage"], $usrAttributes["usrMaxStars"], $usrAttributes["usrStarText"], $usrAttributes["usrPreviewImg"], $usrAttributes["usrStarSize"], true, count($atts), $usrCustomImagesFolder) . '</td></tr>'; } //Finishing the table $usrlist .= '</table>'; //Output return $usrlist; //There is just 1 key:value pair we return the error message } else { return $MESSAGES['ERROR']['NotEnoughParameters'][$usrLang]; } }
function getImageString($ratingValue, $usrStarImage, $usrMaxStars, $usrStarText, $usrPreviewImg, $usrStarSize, $usrAggregatedOutput, $usrAggregationCount, $usrCustomImagesFolder) { if (!isset($usrAggregatedOutput) || $usrAggregatedOutput != true) { $usrAggregatedOutput = false; } if (!isset($usrCustomImagesFolder)) { $usrCustomImagesFolder = ""; } //Just in case it is not done yet... $ratingValue = getUsableRating($ratingValue, $usrMaxStars); $formattedRatingValue = getFormattedRating($ratingValue); //Set the string $imageString = ''; //Schema.org SEO if (get_option('usrSchemaOrg') == "true") { //If this is aggregated output from usrlist... if ($usrAggregatedOutput == false) { $imageString .= '<div itemprop="' . get_option("usrSchemaOrgType") . '" itemscope itemtype="http://schema.org/Rating" class="usr">'; $imageString .= '<meta itemprop="worstRating" content="0" />'; //If text will not be displayed... if ($usrStarText != "true") { $imageString .= '<meta itemprop="ratingValue" content="' . $ratingValue . '" />'; $imageString .= '<meta itemprop="bestRating" content="' . $usrMaxStars . '" />'; } //If it is not an aggregated output... } elseif ($usrAggregatedOutput == true) { $imageString .= '<div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating" class="usr">'; if ($usrStarText != "true") { $imageString .= '<meta itemprop="ratingValue" content="' . $ratingValue . '" />'; $imageString .= '<meta itemprop="reviewCount" content="' . $usrAggregationCount . '" />'; } } } //If it is a preview image if ($usrPreviewImg == "true") { //Set image $imageString .= '<img class="usr" src="' . content_url() . '/plugins/universal-star-rating/includes/stars.php?img=' . $usrStarImage . '&px=' . $usrStarSize . '&max=' . $usrMaxStars . '&rat=' . $ratingValue; if ($usrCustomImagesFolder != "") { $imageString .= '&folder=' . $usrCustomImagesFolder; } $imageString .= '" style="height: ' . $usrStarSize . 'px !important;" alt="' . $ratingValue . ' Stars" />'; //If it is not a preview } else { //Set image string $imageString .= '<img class="usr" src="' . content_url() . '/plugins/universal-star-rating/includes/stars.php?img=' . $usrStarImage . '&px=' . $usrStarSize . '&max=' . $usrMaxStars . '&rat=' . $ratingValue; if ($usrCustomImagesFolder != "") { $imageString .= '&folder=' . $usrCustomImagesFolder; } $imageString .= '"'; //If star size is not the default there has to be a style attribute... if ($usrStarSize != get_option('usrStarSize')) { $imageString .= ' style="height: ' . $usrStarSize . 'px !important;"'; } $imageString .= ' alt="' . $ratingValue . ' Stars" />'; } //If text will be displayed... if ($usrStarText == "true") { //With schema.org SEO if (get_option('usrSchemaOrg') == "true") { if ($usrAggregatedOutput == false) { $imageString .= ' (<span itemprop="ratingValue">' . $formattedRatingValue . '</span> / <span itemprop="bestRating">' . $usrMaxStars . '</span>)'; } if ($usrAggregatedOutput == true) { $imageString .= ' (<span itemprop="ratingValue">' . $formattedRatingValue . '</span> / ' . $usrMaxStars . ')<meta itemprop="reviewCount" content="' . $usrAggregationCount . '" />'; } //Without schema.org SEO } else { $imageString .= ' (' . $formattedRatingValue . ' / ' . $usrMaxStars . ')'; } } //Close schema.org SEO tag if (get_option('usrSchemaOrg') == "true") { $imageString .= '</div>'; } return $imageString; }