/**
   @param $csv String
   @return $csv ['headline' => [String], 'data' => [[String]]]
 */
 public function parse($csv)
 {
     $csv = self::parse_csv($csv);
     $csv = array('headline' => array_shift($csv), 'data' => $csv);
     //Checking if all data fields have the length of the headline:
     $hCount = count($csv['headline']);
     foreach ($csv['data'] as $i => $data) {
         $dCount = count($data);
         if ($dCount < $hCount) {
             $index = $i + 1;
             if ($dCount === 1 && current($data) === '') {
                 continue;
             }
             array_push(self::$log, "Row {$index} has {$dCount} instead of {$hCount} fields. Ignoring row: " . Config::toJSON($data));
             unset($csv['data'][$i]);
         }
     }
     //Fixing indices:
     $csv['data'] = array_values($csv['data']);
     return $csv;
 }
 /** Returns a JSON array of all Names in the Studies table. */
 case 'studies':
     echo Config::toJSON(Translation::studies());
     break;
     /**
       Fetches the complete Page_Translations table.
       @returns A JSON Array with JSON Objects inside.
         Fields of contained JSON Objects are named as in db.
     */
 /**
   Fetches the complete Page_Translations table.
   @returns A JSON Array with JSON Objects inside.
     Fields of contained JSON Objects are named as in db.
 */
 case 'translations':
     echo Config::toJSON(Translation::translations());
     break;
     /**
       @param $_GET['TranslationId']
       @param $_GET['Payload'] The payload that determines what will be updated.
       @param $_GET['Update'] The update value to write
       @param $_GET['Provider'] The Provider to perform the update to
     */
 /**
   @param $_GET['TranslationId']
   @param $_GET['Payload'] The payload that determines what will be updated.
   @param $_GET['Update'] The update value to write
   @param $_GET['Provider'] The Provider to perform the update to
 */
 case 'update':
     Translation::update($_GET['TranslationId'], $_GET['Payload'], $_GET['Update'], $_GET['Provider']);
<?php

//Setup to have a JSON response:
require_once '../config.php';
Config::setResponseJSON();
//Blacklist to hide some templates:
$blacklist = array('Projects');
//Composing our information object:
$info = array();
$sums = `md5sum ../templates/*.html`;
// We depend on md5sum, or a similar hash alg.
$lines = explode("\n", $sums);
foreach ($lines as $l) {
    $x = explode('  ', $l);
    if (count($x) !== 2) {
        continue;
    }
    $file = substr($x[1], 3);
    if (in_array($file, $blacklist)) {
        continue;
    }
    $info[$file] = $x[0];
}
echo Config::toJSON($info);
 /**
   This is the entry point method of ShortLink.
   It is called at the bottom of this file,
   but will exit asap if ShortLink required POST parameters are missing.
 */
 public static function handlePost()
 {
     if (!array_key_exists('createShortLink', $_POST)) {
         return;
     }
     //Creating ShortLink:
     $arr = self::insert($_POST['createShortLink']);
     //Making sure $arr is an array:
     if ($arr instanceof Exception) {
         $arr = array('error' => $arr->getMessage());
     }
     //Producing output:
     Config::setResponseJSON();
     echo Config::toJSON($arr);
 }
Example #5
0
$q = 'SELECT Req, Description FROM Page_StaticDescription';
$set = $dbConnection->query($q);
while ($r = $set->fetch_assoc()) {
    $info['staticDescription'][$r['Req']] = $r['Description'];
}
//Fetching static translations:
$q = 'SELECT TranslationId, Req, Trans, IsHtml FROM Page_StaticTranslation';
$set = $dbConnection->query($q);
while ($r = $set->fetch_assoc()) {
    $tId = $r['TranslationId'];
    if (!array_key_exists($tId, $info['staticTranslation'])) {
        $info['staticTranslation'][$tId] = array();
    }
    array_push($info['staticTranslation'][$tId], array('Req' => $r['Req'], 'Trans' => $r['Trans'], 'IsHtml' => $r['IsHtml']));
}
//Cast to object to aid json_encode:
$info['staticTranslation'] = (object) $info['staticTranslation'];
//Fetching dynamic translations:
$q = 'SELECT MD5(CONCAT(TranslationId, Category, Field)) AS \'Hash\', ' . 'TranslationId, Category, Field, Trans, ' . 'UNIX_TIMESTAMP(Time) AS \'Time\' ' . 'FROM Page_DynamicTranslation';
$set = $dbConnection->query($q);
while ($r = $set->fetch_assoc()) {
    $hash = $r['Hash'];
    unset($r['Hash']);
    $info['dynamicTranslation'][$hash] = $r;
}
//Delivering $info:
Config::setResponseJSON();
$filename = 'translations_' . date('Y-m-d-h:i', time()) . '.json';
header('Content-Disposition: attachment;filename="' . $filename . '"');
echo Config::toJSON($info, $opts);
    case 'dynamic':
        if (array_key_exists('translationId', $_GET)) {
            echo Config::toJSON(TranslationProvider::getDynamic($_GET['translationId']));
        } else {
            Config::setResponse(400);
            echo Config::toJSON(array('msg' => 'You need to specify a translationId for action=dynamic.'));
        }
        break;
    case 'static':
        if (array_key_exists('translationId', $_GET)) {
            echo Config::toJSON(TranslationProvider::getStatic($_GET['translationId']));
        } else {
            Config::setResponse(400);
            echo Config::toJSON(array('msg' => 'You need to specify a translationId for action=static.'));
        }
        break;
    case 'summary':
        echo Config::toJSON(TranslationProvider::getSummary());
        break;
    case 'i18n':
        $lngs = explode(' ', $_GET['lng']);
        $ret = array();
        foreach ($lngs as $lng) {
            $ret[$lng] = array('translation' => TranslationProvider::getI18n($lng));
        }
        echo Config::toJSON($ret);
        break;
    default:
        Config::setResponse(400);
        echo Config::toJSON(array('msg' => '"action" variable must be specified, ' . 'carrying one of the action values.', 'action' => array('summary', 'static', 'dynamic')));
}
 /**
   @return [TableName => [json => JsonRow, reason => String]]
   Checks all notValues entries of Integrity::$constraints.
   TableName is expected to be a complete name, not a prefix.
 */
 public static function checkNotValues()
 {
     $ret = array();
     foreach (self::$constraints as $tPrefix => $tDesc) {
         if (array_key_exists('notValues', $tDesc)) {
             $or = array();
             foreach ($tDesc['notValues'] as $k => $v) {
                 array_push($or, "{$k} = {$v}");
             }
             $or = implode(' OR ', $or);
             foreach (self::getTableNames($tPrefix, $tDesc) as $table) {
                 $q = "SELECT * FROM {$table} WHERE {$or}";
                 $rs = DataProvider::fetchAll($q);
                 if (count($rs) > 0) {
                     $jsons = array();
                     foreach ($rs as $r) {
                         array_push($jsons, array('json' => Config::toJSON($r), 'reason' => 'Forbidden combination of key/value occured.'));
                     }
                     $ret[$table] = $jsons;
                 }
             }
         }
     }
     return $ret;
 }
Example #8
0
     echo "Deleted user: {$userid}";
     break;
 case 'export':
     $export = array();
     $q = 'SELECT UserId, Login, Hash, AccessEdit, AccessTranslate FROM Edit_Users';
     $set = $dbConnection->query($q);
     while ($row = $set->fetch_assoc()) {
         array_push($export, $row);
     }
     header("Pragma: public");
     header("Expires: 0");
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     header("Content-Type: application/json; charset=utf-8");
     header("Content-Disposition: attachment;filename=\"users.json\"");
     header("Content-Transfer-Encoding: binary");
     die(Config::toJSON($export));
     break;
 case 'import':
     if (count($_FILES) === 1) {
         $file = file_get_contents($_FILES['import']['tmp_name']);
         $data = json_decode($file);
         foreach ($data as $user) {
             $UserId = $dbConnection->escape_string($user->UserId);
             $Login = $dbConnection->escape_string($user->Login);
             $Hash = $dbConnection->escape_string($user->Hash);
             $AccessEdit = $dbConnection->escape_string($user->AccessEdit);
             $AccessTranslate = $dbConnection->escape_string($user->AccessTranslate);
             $q = "INSERT INTO Edit_Users(UserId, Login, Hash, AccessEdit, AccessTranslate) " . "VALUES ({$UserId}, '{$Login}', '{$Hash}', {$AccessEdit}, {$AccessTranslate}) " . "ON DUPLICATE KEY UPDATE Login='******', Hash='{$Hash}'" . ", AccessEdit={$AccessEdit}, AccessTranslate={$AccessTranslate}";
             $dbConnection->query($q);
         }
         header('LOCATION: ../index.php');
Example #9
0
  1.: We offer a list of studies, and also global data applying to each study.
  2.: Each study can be fetched separately.
  3.: JavaScript will tack a timestamp on each study,
      so that we can drop older studies from localStorage,
      in case that we're running out of space.
  4.: The data for each study thus consists of the following things:
      - Name and basic data for the study itself
      - A list of Families in the Study
      - A list of Regions per Family
      - A list of Languages per Region
      - A list of Words per Study
      - A list of Transcriptions per pair of Word and Language
      - Defaults for the Study
*/
if (array_key_exists('global', $_GET)) {
    echo Config::toJSON(array('studies' => DataProvider::getStudies(), 'global' => DataProvider::getGlobal()));
} else {
    if (array_key_exists('study', $_GET)) {
        if (CacheProvider::hasCache($_GET['study'])) {
            echo CacheProvider::getCache($_GET['study']);
        } else {
            $ret = DataProvider::getStudyChunk($_GET['study']);
            //Done:
            $data = json_encode($ret);
            echo $data;
            CacheProvider::setCache($_GET['study'], $data);
        }
    } else {
        echo json_encode(array('lastUpdate' => DataProvider::getLastImport(), 'Description' => 'Add a global parameter to fetch global data, ' . 'and add a study parameter to fetch a study.'));
    }
}
Example #10
0
$dbConnection = Config::getConnection();
$index = array('hidelinkLeft' => TranslationProvider::staticTranslate('hidelink_left'), 'hidelinkRight' => TranslationProvider::staticTranslate('hidelink_right'), 'head' => array('title' => 'Site loading, please wait', 'requirejs' => 'js/App'));
//Checking for minified js/App setup:
require_once 'Git.php';
if (Git::getBranch() === 'master') {
    $app = 'js/App-minified';
    if (file_exists('./' . $app . '.js')) {
        $index['head']['requirejs'] = $app;
    }
}
//Making sure we get our appSetup:
$index['appSetup'] = true;
//Processing the Content-type:
$headers = getallheaders();
if (!array_key_exists('Accept', $headers)) {
    $headers['Accept'] = 'text/html';
}
$cType = $headers['Accept'];
switch ($cType) {
    case preg_match('/application\\/json/i', $cType) ? true : false:
        header('Content-type: application/json');
        Config::toJSON($index);
        break;
    case preg_match('/text\\/html/i', $cType) ? true : false:
    default:
        //Rendering:
        echo Config::getMustache()->render('index', $index);
        //Done :)
        $endTime = microtime(true);
        echo "<!-- Page generated in " . round($endTime - $startTime, 4) . "s -->";
}