Esempio n. 1
0
 /**
  * @return string
  */
 public static function fromCharCode()
 {
     return array_reduce(func_get_args(), function ($a, $b) {
         $a .= LZString::utf8_chr($b);
         return $a;
     });
 }
 /**
  * @dataProvider dataProvider
  */
 public function testJs2Php($input)
 {
     $this->open($this->browserPath);
     $this->type('toCompress', $input);
     $this->click('compress');
     $decompressed = \LZString::decompressFromBase64($this->getValue('compressed'));
     $this->assertEquals($input, $decompressed);
 }
Esempio n. 3
0
 public static function fromCharCode()
 {
     $args = func_get_args();
     //        var_dump($args[0].': '.array_reduce(func_get_args(),function($a,$b){$a.=self::utf8_chr($b);return $a;}));
     return array_reduce(func_get_args(), function ($a, $b) {
         $a .= LZString::utf8_chr($b);
         return $a;
     });
 }
Esempio n. 4
0
                    <h2>php fromCharCode/charCodeAt</h2>
                    <table class="table table-striped table-condensed">
                        <thead>
                            <tr>
                                <th>Number</th>
                                <th>fromCharCode</th>
                                <th>charCodeAt</th>
                                <th>Match</th>
                            </tr>
                        </thead>
                        <tbody class="phpFromCharCode">
                            <?php 
for ($i = 0; $i < $codeChecks; $i++) {
    $j = rand(0, 100000);
    $fromCharCode = LZString::fromCharCode($j);
    $charCodeAt = LZString::charCodeAt($fromCharCode, 0);
    echo '
                                        <tr>
                                            <td class="NUMBER">' . $j . '</td>
                                            <td class="fromCharCode">' . $fromCharCode . '</td>
                                            <td class="charCodeAt">' . $charCodeAt . '</td>
                                            <td class="equals ' . ($j === $charCodeAt ? 'success' : 'danger') . '">' . ($j === $charCodeAt ? 'true' : 'false') . '</td>
                                        </tr>
                                    ';
}
?>
                        </tbody>
                    </table>
                </div>
            </div>
header("Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With");
header("Access-Control-Allow-Credentials: true");
header("Content-Type: application/json");
// Process Upload
$raw = file_get_contents("php://input");
$json = json_decode($raw);
if (!isset($json->moduleId) || is_null($json->moduleId) || (!isset($json->sessionId) || is_null($json->sessionId)) || (!isset($json->userCode) || is_null($json->userCode))) {
    header('HTTP/1.1 500 Internal Server Error');
    echo json_decode("{'message': 'Missing data!'}");
    exit;
}
$user = filter_var($json->userCode, FILTER_SANITIZE_STRING);
$moduleId = filter_var($json->moduleId, FILTER_SANITIZE_STRING);
$moduleLabel = filter_var($json->moduleLabel, FILTER_SANITIZE_STRING);
$sessionId = str_pad($json->sessionId, 6, "0", STR_PAD_LEFT);
$data = LZString::decompressFromBase64($json->trialData);
$path = $tatoolwebpath . $moduleId . "/";
$filename = (is_null($moduleLabel) ? $moduleId : $moduleLabel) . "_" . $user . "_" . $sessionId;
$zipFilename = $moduleId . "_" . $user . '.zip';
$timestamp = "";
$extension = ".csv";
// create target module directory if it doesn't exist yet
if (!file_exists($path)) {
    mkdir($path, 0777, true);
}
// check if file already exists and append timestamp if it does
if (file_exists($path . $filename . $extension)) {
    $timestamp = "_" . time();
}
// write file
try {
Esempio n. 6
0
<?php

require 'LZString.php';
$imagePath = 'images/test.bmp';
$paletteKey = 'test.palette';
$pendingTasksKey = 'test.pending';
$data = LZString::decompressFromBase64($_POST['data']);
$json = json_decode($data, true);
$taskId = $json['taskId'];
$x = $json['x'];
$y = $json['y'];
$columns = $json['columns'];
$rows = $json['rows'];
$solution = $json['solution'];
$image = new Imagick($imagePath);
$areaIterator = $image->getPixelRegionIterator($x, $y, $columns, $rows);
$index = 0;
$bool = true;
$colorPalette = apc_fetch($paletteKey, $bool);
foreach ($areaIterator as $rowIterator) {
    foreach ($rowIterator as $pixel) {
        $nearestPoint = $solution[$index];
        $index += 1;
        if ($nearestPoint != -1) {
            $color = $colorPalette[$nearestPoint];
            $pixel->setColor(sprintf("rgb(%s, %s, %s)", $color['r'], $color['g'], $color['b']));
        } else {
            $pixel->setColor("rgb(0, 0, 0)");
            //pixel is already black
        }
    }