Exemple #1
0
function wsOnMessage($clientID, $message, $messageLength, $binary)
{
    global $Server, $gameArray, $wsClientNames;
    $ip = long2ip($Server->wsClients[$clientID][6]);
    $jsonMessage = json_decode($message, true);
    $action = (string) $jsonMessage["action"];
    $data = $jsonMessage["data"];
    switch ($action) {
        case "new":
            $response = array("action" => "log", "message" => "Creating new game...");
            sendJson($clientID, $response);
            addGame($clientID, $data);
            break;
        case "join":
            $response = array("action" => "log", "message" => "Joining a game");
            $gameNumber = (int) $data["game"];
            $teamNumber = (int) $data["team"];
            sendJson($clientID, $response);
            joinGame($clientID, $gameNumber, $teamNumber);
            break;
        case "leave":
            $response = array("action" => "log", "message" => "Attempting to leave current game.");
            sendJson($clientID, $response);
            leaveGame($clientID);
            break;
        case "changename":
            $wsClientNames[$clientID] = (string) $data;
            foreach ($Server->wsClients as $id => $client) {
                if ($id != $clientID) {
                    $response = array("action" => "chat", "message" => (string) $data . " has entered the lobby.");
                    sendJson($id, $response);
                }
            }
            break;
        case "confirm":
            confirmClient($clientID);
            break;
        case "game":
            forwardCommand($clientID, $data);
            break;
        case "chat":
            chat($clientID, (string) $data);
            break;
        default:
            $response = array("action" => "log", "message" => "Didn't recognize that command.");
            sendJson($clientID, $response);
    }
    // check if message length is 0
    if ($messageLength == 0) {
        $Server->wsClose($clientID);
        return;
    }
    //foreach ( $Server->wsClients as $id => $client )
    //$Server->wsSend($id, "Visitor $clientID ($ip) said \"$message\"");
    //$Server->wsSend($id, "Server response: ($responseMessage)");
    //$arrayCount = (string)count($gameArray);
    //$Server->wsSend($id, "number of open games: ($arrayCount)");
}
Exemple #2
0
// typ: 1 - success, 2 - warning, 3- error, 4-alert
$msg = array('appkey' => 'Username', 'pass' => 'Password', 'msg' => 'Wiadomość tekstowa', 'img' => $base64img, 'typ' => '1');
function sendJSON($jsonData, $url = 'localhost/notex/api/api-json.php')
{
    $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 10, CURLOPT_ENCODING => "", CURLOPT_USERAGENT => "notex-client", CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120);
    $ch = curl_init($url);
    $jsonDataEncoded = json_encode($jsonData);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // force ssl
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    // if hostname == CN cert field
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=utf-8;', 'Content-Length: ' . strlen($jsonDataEncoded)));
    curl_setopt_array($ch, $options);
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Curl error: ' . curl_error($ch);
    }
    curl_close($ch);
    return $result;
}
echo $res = sendJson($msg);
$j = json_decode($res, true);
echo "error " . $j['error'];
//print_r($j);
// get json file from get request
// $json = file_get_contents('http://somesite.com/getjson.php');
// in javascript
// // Parse result to JavaScript object
//  var data=JSON.parse(XMLHttp.responseText);
Exemple #3
0
<?php 
/*
 * processForm.php
 *
 * Script to run the Voertman's scraper and return the book information if available.
 * NOTE: This needs to be in the python directory to execute the scrapy command.
 *
 * Author: Jacob Cole
 */
session_start();
//command to get voertmans book info
$command = "../../libraries/scrapy crawl voertmans -a departmentChoice=" . $_SESSION["deptNumber"] . " -a courseChoice=" . $_SESSION["courseNumber"] . " -a sectionChoice=41334";
exec($command, $result);
function sendJson($result)
{
    $resultData = json_decode($result, true);
    echo json_encode($resultData);
}
if (isset($result[0])) {
    sendJson($result[0]);
} else {
    $command = "../../libraries/scrapy crawl voertmans -a departmentChoice=" . $_SESSION["deptNumber"] . " -a courseChoice=" . $_SESSION["courseNumber"] . " -a sectionChoice=42957";
    exec($command, $result);
    if (isset($result[0])) {
        sendJson($result[0]);
    }
}
unset($_SESSION["deptNumber"]);
unset($_SESSION["courseNumber"]);
Exemple #4
0
function sendAllOpenGames($clientID)
{
    global $gameArray;
    $openGames = array();
    $responseArray = array();
    foreach ($gameArray as $game) {
        if (is_null($game->Team1->Player1) || is_null($game->Team1->Player2) || is_null($game->Team2->Player1) || is_null($game->Team2->Player2)) {
            array_push($openGames, $game);
        }
    }
    foreach ($openGames as $game) {
        $rules = $game->Rules;
        $TrumpBeforeKitty = $rules->TrumpBeforeKitty ? "true" : "false";
        $NoRookOnFirstTrick = $rules->NoRookOnFirstTrick ? "true" : "false";
        $team1player1name = "";
        $team1player2name = "";
        $team2player1name = "";
        $team2player2name = "";
        if ($game && $game->Team1 && $game->Team1->Player1) {
            $team1player1name = $game->Team1->Player1->Name;
        }
        if ($game && $game->Team1 && $game->Team1->Player2) {
            $team1player2name = $game->Team1->Player2->Name;
        }
        if ($game && $game->Team2 && $game->Team2->Player1) {
            $team2player1name = $game->Team2->Player1->Name;
        }
        if ($game && $game->Team2 && $game->Team2->Player2) {
            $team2player2name = $game->Team2->Player2->Name;
        }
        $gameDetails = array("name" => (string) $game->Name, "id" => (string) $game->Id, "status" => "Waiting for 4 players", "team1player1" => (string) $team1player1name, "team1player2" => (string) $team1player2name, "team2player1" => (string) $team2player1name, "team2player2" => (string) $team2player2name, "rookvalue" => (string) $rules->RookValue, "playto" => (string) $rules->PlayTo, "trumpbeforekitty" => $TrumpBeforeKitty, "norookonfirsttrick" => $NoRookOnFirstTrick);
        array_push($responseArray, $gameDetails);
    }
    $response = array("action" => "command", "message" => "allgamedetails", "data" => $responseArray);
    sendJson($clientID, $response);
}
    }
    $data = array();
    /* Prepare graph */
    try {
        /* Get index data */
        $indexData = GraphService::getIndexId($hostId, $serviceId, $pearDBD);
        $graph = new GraphService($indexData, $sid);
    } catch (Exception $e) {
        sendJson("Graph not found", 404);
    }
    $graph->setRRDOption("start", $start);
    $graph->setRRDOption("end", $end);
    $graph->initCurveList();
    $graph->createLegend();
    $serviceData = $graph->getData($rows);
    /* Replace NaN */
    for ($i = 0; $i < count($serviceData); $i++) {
        if (isset($serviceData[$i]['data'])) {
            $times = array_keys($serviceData[$i]['data']);
            $values = array_map("convertNaN", array_values($serviceData[$i]['data']));
        }
        $serviceData[$i]['data'] = $values;
        $serviceData[$i]['label'] = $serviceData[$i]['legend'];
        unset($serviceData[$i]['legend']);
        $serviceData[$i]['type'] = $serviceData[$i]['graph_type'];
        unset($serviceData[$i]['graph_type']);
    }
    $result[] = array('service_id' => $id, 'data' => $serviceData, 'times' => $times, 'size' => $rows);
}
sendJson($result);
 public function reset_password()
 {
     $this->load->helper('json');
     $answer = array('success' => FALSE, 'message' => '');
     $id = 0;
     $this->load->config('password');
     $this->load->helper('string');
     $email = $this->input->post('email');
     $this->db->select('admin_id')->from('administrator')->where('email', $email);
     $query = $this->db->get();
     if ($query->num_rows() > 0) {
         $row = $query->row();
         $id = $row->admin_id;
         $new_pw = random_string('alnum', 8);
         $options = array('cost' => $this->config->item('password_cost'), 'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM));
         $hashed_password = password_hash($new_pw, PASSWORD_BCRYPT, $options);
         $this->db->where('admin_id', $id);
         $this->db->update('administrator', array('password' => $hashed_password));
         if ($this->db->_error_number() == 0) {
             $this->load->library('email');
             $this->load->config('email');
             $this->email->from($this->config->item('email_sender'), DEFAULT_SITE_TITLE);
             $this->email->to($email);
             $this->email->subject('Reinicio de contraseña');
             $content = 'Su contraseña ha sido reiniciada. Su nueva contraseña es <strong>' . $new_pw . '</strong> .';
             $html = $this->load->view('mailing/base', array('content' => $content), TRUE);
             $this->email->message($html);
             $this->email->send();
             $answer['success'] = TRUE;
             $answer['message'] = 'Su contraseña ha sido reiniciada exitosamente. Se le ha enviado la nueva contaseña a su correo.';
         }
     } else {
         $answer['success'] = FALSE;
         $answer['message'] = 'El correo que ingresó no es válido';
     }
     echo sendJson((object) $answer);
     exit;
 }
            die('You are not authorized');
        }
        /* @var $multipartUploadModel UploadId */
        $model = $client->createMultipartUpload(array('Bucket' => BUCKET_NAME, 'Key' => $_REQUEST['fileInfo']['name'], 'ContentType' => $_REQUEST['fileInfo']['type'], 'Metadata' => $_REQUEST['fileInfo']));
        sendJson(array('uploadId' => $model->get('UploadId'), 'key' => $model->get('Key')));
        break;
    case 'signuploadpart':
        $command = $client->getCommand('UploadPart', array('Bucket' => BUCKET_NAME, 'Key' => $_REQUEST['sendBackData']['key'], 'UploadId' => $_REQUEST['sendBackData']['uploadId'], 'PartNumber' => $_REQUEST['partNumber'], 'ContentLength' => $_REQUEST['contentLength']));
        $request = $command->prepare();
        // This dispatch commands wasted a lot of my times :'(
        $client->dispatch('command.before_send', array('command' => $command));
        $request->removeHeader('User-Agent');
        $request->setHeader('x-amz-date', gmdate(DateFormat::RFC2822));
        // This dispatch commands wasted a lot of my times :'(
        $client->dispatch('request.before_send', array('request' => $request));
        sendJson(array('url' => $request->getUrl(), 'authHeader' => (string) $request->getHeader('Authorization'), 'dateHeader' => (string) $request->getHeader('x-amz-date')));
        break;
    case 'completemultipartupload':
        $partsModel = $client->listParts(array('Bucket' => BUCKET_NAME, 'Key' => $_REQUEST['sendBackData']['key'], 'UploadId' => $_REQUEST['sendBackData']['uploadId']));
        $model = $client->completeMultipartUpload(array('Bucket' => BUCKET_NAME, 'Key' => $_REQUEST['sendBackData']['key'], 'UploadId' => $_REQUEST['sendBackData']['uploadId'], 'Parts' => $partsModel['Parts']));
        sendJson(array('success' => true));
        break;
    case 'abortmultipartupload':
        $model = $client->abortMultipartUpload(array('Bucket' => BUCKET_NAME, 'Key' => $_REQUEST['sendBackData']['key'], 'UploadId' => $_REQUEST['sendBackData']['uploadId']));
        sendJson(array('success' => true));
        break;
    default:
        header(' ', true, 404);
        die('Command not understood');
        break;
}
Exemple #8
0
 public function getEntryPoints()
 {
     $data = array(array(cObject => cAutor, cURI => API_URI . '?' . cObject . '=' . cAutor, cMethod => cGET), array(cObject => cEditora, cURI => API_URI . '?' . cObject . '=' . cEditora, cMethod => cGET), array(cObject => cLivro, cURI => API_URI . '?' . cObject . '=' . cLivro, cMethod => cGET));
     sendJson(stripslashes(json_encode($data, JSON_PRETTY_PRINT)));
 }
Exemple #9
0
<?php

echo "Send data to server";
//The JSON data.
$jsonData = array('username' => 'MyUsername', 'password' => 'MyPassword');
function sendJson($jsonData)
{
    //API Url
    $url = 'localhost/notex/core/json.php';
    //Initiate cURL.
    $ch = curl_init($url);
    //Encode the array into JSON.
    $jsonDataEncoded = json_encode($jsonData);
    //Tell cURL that we want to send a POST request.
    curl_setopt($ch, CURLOPT_POST, 1);
    //Attach our encoded JSON string to the POST fields.
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);
    //Set the content type to application/json
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=utf-8;', 'Content-Length: ' . strlen($jsonDataEncoded)));
    //Execute the request
    $result = curl_exec($ch);
    return $result;
}
// get json file from get request
// $json = file_get_contents('http://somesite.com/getjson.php');
// in javascript
// // Parse result to JavaScript object
//  var data=JSON.parse(XMLHttp.responseText);
echo sendJson($jsonData);
Exemple #10
0
        $article_query .= " where a.`pub_date` = '2016-11-08'";
        $b = $db->prepare($article_query);
        //$b->bindParam(":mydb",$key);
        $b->execute();
        $result = $b->fetchAll(PDO::FETCH_ASSOC);
        //echo sqlToXml($result, "auth_user", "user");
        //echo sqlToXml($result, "articles", "article");
        // if (is_array($result)){
        //     foreach ($result as $key1) {
        //         print_r( $key1);
        //         die();
        //     }
        // }
        $_articles = sqlToArticle($result);
        $_json = createJson($_json, $_articles, $pSetup, $_day, $_siteDomain, $_postStatus);
        sendJson("", $_json);
    } catch (PDOException $e) {
        echo "\nFailed: " . $e->getMessage();
        echo "\n";
    }
    $pdo = null;
} catch (PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}
/**
*  MY FUNCTIONS
*/
function sqlToArticle($queryResult)
{
    foreach ($queryResult as $key1) {
        $_articles[$key1['id']] = "ss";
Exemple #11
0
                                    //$flight->makeJSON(0);  // no force
                                    $mapUrl = $flight->createStaticMap(0);
                                }
                                // $pref="http://xc.dhv.de/xc/modules/leonardo";
                                $pref = "http://" . $_SERVER['SERVER_NAME'];
                                $JSON_str .= ' {"flightID": "' . $row["ID"] . '", "date": "' . json::prepStr($row["DATE"]) . '", ' . '"DURATION": "' . json::prepStr($duration) . '", ' . '"START_TIME": "' . json::prepStr($START_TIME) . '", ' . '"END_TIME": "' . json::prepStr($END_TIME) . '", ' . '"MAX_ALT": "' . json::prepStr($MAX_ALT) . '", ' . '"MAX_VARIO": "' . json::prepStr($MAX_VARIO) . '", ';
                                '"MIN_VARIO": "' . json::prepStr($MIN_VARIO) . '", ';
                                if ($singleFlight) {
                                    $JSON_str .= '"g1": "' . json::prepStr($pref . substr($flight->getChartRelPath('alt', 1, 0), 0)) . '", ' . '"g2": "' . json::prepStr($pref . substr($flight->getChartRelPath('vario', 1, 0), 0)) . '" , ' . '"g3": "' . json::prepStr($pref . substr($flight->getChartRelPath('speed', 1, 0), 0)) . '" , ' . '"g4": "' . json::prepStr($pref . substr($flight->getChartRelPath('takeoff_distance', 1, 0), 0)) . '" , ' . '"firstLat": "' . json::prepStr($row["firstLat"]) . '", ' . '"firstLon": "' . json::prepStr($row["firstLon"]) . '", ' . '"lastLat": "' . json::prepStr($row["lastLat"]) . '", ' . '"lastLon": "' . json::prepStr($row["lastLon"]) . '", ' . '"map": "' . json::prepStr($pref . substr($mapUrl, 0)) . '" , ';
                                }
                                $JSON_str .= '"linearDistance": "' . json::prepStr($linearDistance) . '", ' . '"olcDistance": "' . json::prepStr($olcDistance) . '", ' . '"olcScore": "' . json::prepStr($olcScore) . '", ' . '"scoreSpeed": "' . json::prepStr($scoreSpeed) . '", ' . '"olcScoreType": "' . json::prepStr($olcScoreType) . '", ' . '"glider": "' . json::prepStr($row['glider']) . '", ' . '"gliderBrandImg": "' . json::prepStr($gliderBrandImg) . '", ' . '"gliderCat": "' . json::prepStr($gliderCat) . '", ' . '"categoryImg": "' . json::prepStr($categoryImg) . '", ' . '"pilotName": "' . json::prepStr($name) . '", ' . '"takeoff": "' . json::prepStr($location) . '"  } ';
                                $i++;
                            }
                            //$JSON_str='{"totalCount":"'.$i.'","flights":[ '. $JSON_str."  ] } ";
                            $JSON_str = '{ ' . ' "flights":[ ' . $JSON_str . '  ] } ';
                            sendJson($JSON_str);
                        }
                    }
                }
            }
        }
    }
}
function sendJson($JSON_str)
{
    if (ini_get('zlib.output_compression')) {
        ini_set('zlib.output_compression', 'Off');
    }
    $JSON_str = str_replace('http://dhv-xc.de.//', 'http://dhv-xc.de/xc/modules/leonardo/', $JSON_str);
    $JSON_str = str_replace('http:\\/\\/dhv-xc.de.\\/\\/', 'http:\\/\\/dhv-xc.de\\/xc\\/modules\\/leonardo\\/', $JSON_str);
    if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2')) {
Exemple #12
0
/**
 * Créé et télécharge une archive au format .tar.gz à partir d'un package et de ses dépendences.
 * Si erreur, renvoie JSON_FILE_SYSTEM_ERROR ou JSON_DOWNLOAD_ERROR et exit.
 *
 * @param string $filename Le nom de l'archive à créer/télécharger
 * @param Object $package Les infos du package (doit contenir les strings "name" et "version")
 * @param array[Object] $dependencies Les infos des dépendences (chaque entrée doit contenir les strings "name" et "version")
 */
function sendTar($filename, $package, $dependencies)
{
    $baseDir = createDirIfNotHere(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . DIR_ALL);
    $packDir = createDirIfNotHere($baseDir . DIR_PACKAGE);
    $libDir = createDirIfNotHere($baseDir . DIR_LIB);
    $outDir = createDirIfNotHere($baseDir . DIR_OUT);
    $tempFile = $outDir . $filename . ".tar";
    try {
        $phar = new PharData($tempFile);
    } catch (UnexpectedValueException $e) {
        sendJson(JSON_FILE_SYSTEM_ERROR);
    }
    $packageToInclude = $packDir . $package["name"] . "-" . $package["version"];
    fillArchive($phar, $packageToInclude, $baseDir);
    foreach ($dependencies as $dependency) {
        $dependencyToInclude = $libDir . $dependency["name"] . "-" . $dependency["version"];
        fillArchive($phar, $dependencyToInclude, $baseDir);
    }
    $phar->compress(Phar::GZ);
    $fileToSend = $tempFile . ".gz";
    unset($phar);
    try {
        Phar::unlinkArchive($tempFile);
        // Suppression du fichier .tar
    } catch (PharException $e) {
        sendJson(JSON_FILE_SYSTEM_ERROR);
    }
    header('Content-Description: Archive Transfer');
    header('Content-Type: application/x-compressed');
    header('Content-Disposition: attachment; filename="' . basename($fileToSend) . '"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($fileToSend));
    if (!readfile($fileToSend)) {
        sendJson(JSON_DOWNLOAD_ERROR);
    }
    if (!unlink($fileToSend)) {
        // Suppression du fichier .gz
        die(JSON_FILE_SYSTEM_ERROR);
        // "die" obligatoire car on a déjà utilisé "readFile"
    }
    exit;
}
Exemple #13
0
    $pack = $arr[0];
} else {
    $version = version2int($query["version"]);
    $req = $bdd->prepare("SELECT * FROM package WHERE name = :name AND version = :version");
    $req->bindValue(":name", $name);
    $req->bindValue(":version", $version, PDO::PARAM_INT);
    $req->execute();
    $arr = $req->fetchAll(PDO::FETCH_ASSOC);
    if (count($arr) === 0) {
        sendJson(JSON_VERSION_NOT_FOUND);
    }
    $pack = $arr[0];
}
$pack["version"] = int2version($pack["version"]);
// Dépendances
$req = $bdd->prepare("SELECT * FROM lib JOIN package_lib ON package_lib.id_lib = lib.id_lib WHERE package_lib.id_package = :pack");
$req->bindValue(":pack", $pack["id_package"]);
$req->execute();
$deps = $req->fetchAll(PDO::FETCH_ASSOC);
foreach ($deps as $dep) {
    $dep["version"] = int2version($dep["version"]);
}
if (isset($query["filename"])) {
    // Validation du nom de fichier de l'archive
    filenameValid($query["filename"]);
    // Envoi de l'archive
    sendTar($query["filename"], $pack, $deps);
} else {
    // Envoi des infos
    sendJson(JSON_OK, ["package" => $pack, "nbVer" => $nbVer, "dependencies" => $deps]);
}
Exemple #14
0
function tellClientsWhatCardsTheyHave($game)
{
    $id = $game->Team1->Player1->ClientId;
    $hand = $game->Team1->Player1->Hand;
    $allCards = "Your cards: ";
    foreach ($hand as $card) {
        $allCards = $allCards . $card->toString() . ", ";
    }
    $response = array("action" => "log", "message" => $allCards);
    sendJson($id, $response);
    $id = $game->Team1->Player2->ClientId;
    $hand = $game->Team1->Player2->Hand;
    $allCards = "Your cards: ";
    foreach ($hand as $card) {
        $allCards = $allCards . $card->toString() . ", ";
    }
    $response = array("action" => "log", "message" => $allCards);
    sendJson($id, $response);
    $id = $game->Team2->Player1->ClientId;
    $hand = $game->Team2->Player1->Hand;
    $allCards = "Your cards: ";
    foreach ($hand as $card) {
        $allCards = $allCards . $card->toString() . ", ";
    }
    $response = array("action" => "log", "message" => $allCards);
    sendJson($id, $response);
    $id = $game->Team2->Player2->ClientId;
    $hand = $game->Team2->Player2->Hand;
    $allCards = "Your cards: ";
    foreach ($hand as $card) {
        $allCards = $allCards . $card->toString() . ", ";
    }
    $response = array("action" => "log", "message" => $allCards);
    sendJson($id, $response);
}
Exemple #15
0
            break;
        default:
            $welcome = '';
            if (!file_exists(Webgrind_Config::storageDir()) || !is_writable(Webgrind_Config::storageDir())) {
                $welcome .= 'Webgrind $storageDir does not exist or is not writeable: <code>' . Webgrind_Config::storageDir() . '</code><br>';
            }
            if (!file_exists(Webgrind_Config::xdebugOutputDir()) || !is_readable(Webgrind_Config::xdebugOutputDir())) {
                $welcome .= 'Webgrind $profilerDir does not exist or is not readable: <code>' . Webgrind_Config::xdebugOutputDir() . '</code><br>';
            }
            if ($welcome == '') {
                $welcome = 'Select a cachegrind file above<br>(looking in <code>' . Webgrind_Config::xdebugOutputDir() . '</code> for files matching <code>' . Webgrind_Config::xdebugOutputFormat() . '</code>)';
            }
            require 'templates/index.phtml';
    }
} catch (Exception $e) {
    sendJson(array('error' => $e->getMessage() . '<br>' . $e->getFile() . ', line ' . $e->getLine()));
    return;
}
function get($param, $default = false)
{
    return isset($_GET[$param]) ? $_GET[$param] : $default;
}
function costCmp($a, $b)
{
    $a = $a['summedSelfCostRaw'];
    $b = $b['summedSelfCostRaw'];
    if ($a == $b) {
        return 0;
    }
    return $a > $b ? -1 : 1;
}
Exemple #16
0
$group = $m[1];
$request_uri = $m[2];
global $settings;
require_once PROJECTPATH . '/settings.php';
require_once PROJECTPATH . '/include/init.php';
try {
    //$user = OmniUser::createUser(intval( $_SESSION['admin_info']['id'] ) , $_SESSION['admin_info']['domain'] );
    $app = OmniApplication::createApplication($request_uri);
    $response = $app->execute();
} catch (Exception $e) {
    $stylesheet = 'error';
    error_log("[PHPTINYMVC]" . $e->getMessage());
    $response = array('success' => 'no', 'error' => array('code' => $e->getCode(), 'message' => $e->getMessage()));
}
if ($format == 'json') {
    sendJson($response);
}
$xml = new DOMDocument();
toXml($xml, $xml, 'document', $response);
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if (!in_array($lang, array('en', 'he', 'ru'))) {
    $lang = 'en';
}
$xml->getElementsByTagName('document')->item(0)->setAttribute('lang', $lang);
if ($format == 'xml') {
    header('Content-type: text/xml; charset=utf-8');
    echo $xml->saveXML();
    exit;
}
$xsl = new DOMDocument();
$xsl->load('xsl/' . $stylesheet . '.xsl');
Exemple #17
0
 function AddPlayer($clientId)
 {
     global $Server, $wsClientNames;
     $playerNumber;
     if (is_null($this->Player1)) {
         $this->Player1 = new Player($clientId);
         $playerNumber = 1;
         if (is_null($wsClientNames[$clientId])) {
             $this->Player1->Name = "Player " . (string) $clientId;
         } else {
             $this->Player1->Name = $wsClientNames[$clientId];
         }
     } elseif (is_null($this->Player2)) {
         $this->Player2 = new Player($clientId);
         $playerNumber = 2;
         if (is_null($wsClientNames[$clientId])) {
             $this->Player2->Name = "Player " . (string) $clientId;
         } else {
             $this->Player2->Name = $wsClientNames[$clientId];
         }
     } else {
         return false;
     }
     $response = array("action" => "log", "message" => "Player " . (string) $clientId . " successfully added.");
     sendJson($clientId, $response);
     return $playerNumber;
 }
        $file = BASE_S3_PATH . time() . $file;
        $exp = time() + 300;
        //init upload
        $upload_sig = base64_encode(hash_hmac("sha1", "POST\n\n\n{$exp}\n/" . BUCKET_NAME . $file . "?uploads", AWS_SECRET, true));
        $url = "http://s3-ap-southeast-1.amazonaws.com/" . BUCKET_NAME . $file . "?uploads&" . http_build_query(array("Signature" => $upload_sig, "Expires" => $exp, "AWSAccessKeyId" => AWS_KEY));
        $res = array("url" => $url, "key" => $file);
        sendJson($res);
        break;
    case 'signuploadpart':
        $parts = array();
        $numParts = $_REQUEST['numParts'];
        $file = $_REQUEST['key'];
        $upId = $_REQUEST['uploadId'];
        $exp = time() + 7200;
        for ($part = 1; $part <= $numParts; $part++) {
            $upload_sig = base64_encode(hash_hmac("sha1", "PUT\n\n\n{$exp}\n/" . BUCKET_NAME . $file . "?partNumber={$part}&uploadId={$upId}", AWS_SECRET, true));
            $url = "http://s3-ap-southeast-1.amazonaws.com/" . BUCKET_NAME . $file . "?" . http_build_query(array("partNumber" => $part, "uploadId" => $upId, "Signature" => $upload_sig, "Expires" => $exp, "AWSAccessKeyId" => AWS_KEY));
            $parts[] = array("index" => $part - 1, "url" => $url);
        }
        $upload_sig = base64_encode(hash_hmac("sha1", "DELETE\n\n\n{$exp}\n/" . BUCKET_NAME . $file . "?uploadId={$upId}", AWS_SECRET, true));
        $aborturl = "http://s3-ap-southeast-1.amazonaws.com/" . BUCKET_NAME . $file . "?" . http_build_query(array("uploadId" => $upId, "Signature" => $upload_sig, "Expires" => $exp, "AWSAccessKeyId" => AWS_KEY));
        $exp = time() + 18000;
        $upload_sig = base64_encode(hash_hmac("sha1", "POST\n\ntext/plain; charset=UTF-8\n{$exp}\n/" . BUCKET_NAME . $file . "?uploadId={$upId}", AWS_SECRET, true));
        $completeurl = "http://s3-ap-southeast-1.amazonaws.com/" . BUCKET_NAME . $file . "?" . http_build_query(array("uploadId" => $upId, "Signature" => $upload_sig, "Expires" => $exp, "AWSAccessKeyId" => AWS_KEY));
        sendJson(array("parts" => $parts, "abort" => $aborturl, "complete" => $completeurl));
        break;
    default:
        header(' ', true, 404);
        die('Command not understood');
        break;
}