Exemplo n.º 1
0
function search($file, $word, &$statsList)
{
    $index = computeIndex($word);
    if ($index != -1) {
        fseek($file, $index * 4 + 4);
        // 4 bytes per entry, skip header
        $index = readInt($file);
        if ($index) {
            $start = sizeof($statsList);
            $count = $start;
            fseek($file, $index);
            $w = readString($file);
            while ($w) {
                $statIdx = readInt($file);
                if ($word == substr($w, 0, strlen($word))) {
                    // found word that matches (as substring)
                    $statsList[$count++] = array("word" => $word, "match" => $w, "index" => $statIdx, "full" => strlen($w) == strlen($word), "docs" => array());
                }
                $w = readString($file);
            }
            $totalHi = 0;
            $totalFreqHi = 0;
            $totalFreqLo = 0;
            for ($count = $start; $count < sizeof($statsList); $count++) {
                $statInfo =& $statsList[$count];
                $multiplier = 1;
                // whole word matches have a double weight
                if ($statInfo["full"]) {
                    $multiplier = 2;
                }
                fseek($file, $statInfo["index"]);
                $numDocs = readInt($file);
                $docInfo = array();
                // read docs info + occurrence frequency of the word
                for ($i = 0; $i < $numDocs; $i++) {
                    $idx = readInt($file);
                    $freq = readInt($file);
                    $docInfo[$i] = array("idx" => $idx, "freq" => $freq >> 1, "rank" => 0.0, "hi" => $freq & 1);
                    if ($freq & 1) {
                        $totalHi++;
                        $totalFreqHi += $freq * $multiplier;
                    } else {
                        $totalFreqLo += $freq * $multiplier;
                    }
                }
                // read name and url info for the doc
                for ($i = 0; $i < $numDocs; $i++) {
                    fseek($file, $docInfo[$i]["idx"]);
                    $docInfo[$i]["name"] = readString($file);
                    $docInfo[$i]["url"] = readString($file);
                }
                $statInfo["docs"] = $docInfo;
            }
            $totalFreq = ($totalHi + 1) * $totalFreqLo + $totalFreqHi;
            for ($count = $start; $count < sizeof($statsList); $count++) {
                $statInfo =& $statsList[$count];
                $multiplier = 1;
                // whole word matches have a double weight
                if ($statInfo["full"]) {
                    $multiplier = 2;
                }
                for ($i = 0; $i < sizeof($statInfo["docs"]); $i++) {
                    $docInfo =& $statInfo["docs"];
                    // compute frequency rank of the word in each doc
                    $freq = $docInfo[$i]["freq"];
                    if ($docInfo[$i]["hi"]) {
                        $statInfo["docs"][$i]["rank"] = (double) ($freq * $multiplier + $totalFreqLo) / $totalFreq;
                    } else {
                        $statInfo["docs"][$i]["rank"] = (double) ($freq * $multiplier) / $totalFreq;
                    }
                }
            }
        }
    }
    return $statsList;
}
Exemplo n.º 2
0
function readEPG($epgdatabase)
{
    $fd = fopen($epgdatabase, "r");
    while (!feof($fd)) {
        $length = readInt($fd, 4);
        if ($length < 0) {
            break;
        }
        //echo "$length\n";
        $json = array();
        decodeLength($fd, $length, $json);
        if (isset($json["__section__"])) {
            $section = $json["__section__"];
            echo json_encdat($json) . "\n";
            continue;
        }
        if ($section != "broadcasts") {
            continue;
        }
        $channel = $json["channel"];
        $channel = $GLOBALS["channels"][$channel];
        $service = $channel["services"];
        $service = $GLOBALS["services"][$service[0]];
        if (isset($service["svcname"])) {
            $json["channel"] = $service["svcname"];
        }
        if (isset($service["provider"])) {
            $json["provider"] = $service["provider"];
        }
        if (isset($service["networkname"])) {
            $json["network"] = $service["networkname"];
        }
        $json["tags"] = array();
        $tags = $channel["tags"];
        for ($inx = 0; $inx < count($tags); $inx++) {
            $json["tags"][] = $GLOBALS["tags"][$tags[$inx]]["name"];
        }
        unset($json["grabber"]);
        unset($json["episode"]);
        echo json_encdat($json) . "\n";
    }
}
Exemplo n.º 3
0
function search($file, $word, &$statsList)
{
    $index = computeIndex($word);
    if ($index != -1) {
        fseek($file, $index * 4 + 4);
        // 4 bytes per entry, skip header
        $index = readInt($file);
        if ($index) {
            $start = sizeof($statsList);
            $count = $start;
            fseek($file, $index);
            $w = readString($file);
            while ($w) {
                $statIdx = readInt($file);
                if ($word == substr($w, 0, strlen($word))) {
                    // found word that matches (as substring)
                    $statsList[$count++] = array("word" => $word, "match" => $w, "index" => $statIdx, "full" => strlen($w) == strlen($word), "docs" => array());
                }
                $w = readString($file);
            }
            $totalFreq = 0;
            for ($count = $start; $count < sizeof($statsList); $count++) {
                $statInfo =& $statsList[$count];
                fseek($file, $statInfo["index"]);
                $numDocs = readInt($file);
                $docInfo = array();
                // read docs info + occurrence frequency of the word
                $totalFreq = 0;
                for ($i = 0; $i < $numDocs; $i++) {
                    $idx = readInt($file);
                    $freq = readInt($file);
                    $docInfo[$i] = array("idx" => $idx, "freq" => $freq, "rank" => 0.0);
                    $totalFreq += $freq;
                    if ($statInfo["full"]) {
                        $totalFreq += $freq;
                    }
                }
                // read name an url info for the doc
                for ($i = 0; $i < $numDocs; $i++) {
                    fseek($file, $docInfo[$i]["idx"]);
                    $docInfo[$i]["name"] = readString($file);
                    $docInfo[$i]["url"] = readString($file);
                }
                $statInfo["docs"] = $docInfo;
            }
            for ($count = $start; $count < sizeof($statsList); $count++) {
                $statInfo =& $statsList[$count];
                for ($i = 0; $i < sizeof($statInfo["docs"]); $i++) {
                    $docInfo =& $statInfo["docs"];
                    // compute frequency rank of the word in each doc
                    $statInfo["docs"][$i]["rank"] = (double) $docInfo[$i]["freq"] / $totalFreq;
                }
            }
        }
    }
    return $statsList;
}
Exemplo n.º 4
0
function clanAllyCrest($type, $id, $gsId, $crest)
{
    $cacheTime = 3600;
    $path = Yii::getPathOfAlias('webroot.uploads.images.crest') . DIRECTORY_SEPARATOR . $gsId . DIRECTORY_SEPARATOR . $type;
    $filePath = $id . '.png';
    if (!is_dir($path)) {
        if (!mkdir($path, 0777, TRUE)) {
            return '';
        }
    }
    if (!is_file($path . DIRECTORY_SEPARATOR . $filePath) || time() - filemtime($path . DIRECTORY_SEPARATOR . $filePath) >= $cacheTime) {
        // Генерю файл
        $rnd_file = tmpfile();
        fwrite($rnd_file, $crest);
        fseek($rnd_file, 0);
        $file =& $rnd_file;
        //fopen($filename,'rb');
        $dds = fread($file, 4);
        if ($dds !== 'DDS ') {
            return emptyCrest();
        }
        $hdrSize = readInt($file);
        $hdrFlags = readInt($file);
        $imgHeight = readInt($file) - 4;
        $imgWidth = readInt($file);
        $imgPitch = readShort($file);
        fseek($file, 84);
        $dxt1 = fread($file, 4);
        if ($dxt1 !== 'DXT1') {
            return emptyCrest();
        }
        fseek($file, 128);
        //header ("Content-type: image/png");
        $img = imagecreatetruecolor($imgWidth, $imgHeight);
        for ($y = -1; $y < $imgHeight / 4; $y++) {
            for ($x = 0; $x < $imgWidth / 4; $x++) {
                $color0_16 = readShort($file);
                $color1_16 = readShort($file);
                $r0 = $color0_16 >> 11 << 3;
                $g0 = ($color0_16 >> 5 & 63) << 2;
                $b0 = ($color0_16 & 31) << 3;
                $r1 = $color1_16 >> 11 << 3;
                $g1 = ($color1_16 >> 5 & 63) << 2;
                $b1 = ($color1_16 & 31) << 3;
                $color0_32 = imagecolorallocate($img, $r0, $g0, $b0);
                $color1_32 = imagecolorallocate($img, $r1, $g1, $b1);
                $color01_32 = imagecolorallocate($img, $r0 / 2 + $r1 / 2, $g0 / 2 + $g1 / 2, $b0 / 2 + $b1 / 2);
                $black = imagecolorallocate($img, 0, 0, 0);
                $data = readInt($file);
                for ($yy = 0; $yy < 4; $yy++) {
                    for ($xx = 0; $xx < 4; $xx++) {
                        $bb = $data & 3;
                        $data = $data >> 2;
                        switch ($bb) {
                            case 0:
                                $c = $color0_32;
                                break;
                            case 1:
                                $c = $color1_32;
                                break;
                            case 2:
                                $c = $color01_32;
                                break;
                            default:
                                $c = $black;
                                break;
                        }
                        imagesetpixel($img, $x * 4 + $xx, $y * 4 + $yy, $c);
                    }
                }
            }
        }
        imagepng($img, $path . DIRECTORY_SEPARATOR . $filePath);
        imagedestroy($img);
    }
    return '<img src="' . app()->getBaseUrl(TRUE) . '/uploads/images/crest/' . $gsId . '/' . $type . '/' . $filePath . '">';
}