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];
    }
}
示例#2
0
function getImageStringFromFile($xpmfile)
{
    $file = fopen($xpmfile, "r");
    $content = fread($file, filesize($xpmfile));
    // remove all " and CR
    $content = str_replace(array("\"", "\n", "\r"), "", $content);
    // find position of { and of } and substr between these 2
    $start = strpos($content, "{") + 1;
    // to remove the {
    $stop = strpos($content, "}");
    $imgdescr = substr($content, $start, $stop - $start);
    // explode
    $xpm = explode(",", $imgdescr);
    //print_r($xpm);
    return getImageString($xpm);
}
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $imageData = curl_exec($curl);
    curl_close($curl);
    return $imageData;
}
for ($i = 0; $i < $count; $i++) {
    $redis = new Redis();
    $redis->connect('127.0.0.1', 6379);
    $iconKey = md5('screferral-3057c24e13b6ed0931aad-icon');
    $thumbKey = md5('screferral-3057c24e13b6ed0931aad-thumb');
    if (empty($source = $redis->get($iconKey)) || empty($thumb = $redis->get($thumbKey))) {
        // $thumb = file_get_contents($filename);
        // $source = file_get_contents($icon);
        $thumb = getImageString($filename);
        $source = getImageString($icon);
        $redis->set($iconKey, $source);
        $redis->set($thumbKey, $thumb);
    } else {
        $source = $redis->get($iconKey);
        $thumb = $redis->get($thumbKey);
    }
    // Load
    $thumb = imagecreatefromstring($thumb);
    $source = imagecreatefromstring($source);
    // merge
    imagecopy($thumb, $source, ($width - $iconWidth) / 2, ($height - $iconHeight) / 2, 0, 0, $iconWidth, $iconHeight);
    // imagecopyresampled($thumb, $source, 0, 0, ($width-$iconWidth)/2, ($height-$iconHeight)/2, 0, 0, $iconWidth, $iconHeight);
    // Output
    imagejpeg($thumb, 'final.jpg');
}