コード例 #1
0
 public static function getChanged($tId)
 {
     $ret = array();
     if ($tId !== 1) {
         $q = "SELECT Req, Trans FROM Page_StaticTranslation WHERE TranslationId = 1";
         foreach (DataProvider::fetchAll($q) as $r) {
             $req = $r['Req'];
             $q = "SELECT Trans FROM Page_StaticTranslation WHERE " . "Req = '{$req}' AND TranslationId = {$tId} AND Time < (" . "SELECT Time FROM Page_StaticTranslation " . "WHERE Req = '{$req}' AND TranslationId = 1)";
             foreach (DataProvider::fetchAll($q) as $x) {
                 array_push($ret, array('Description' => TranslationProvider::getDescription($req), 'Original' => $r['Trans'], 'Translation' => array('TranslationId' => $tId, 'Translation' => $x['Trans'], 'Payload' => $req, 'TranslationProvider' => 'StaticTranslationProvider')));
             }
         }
     }
     return $ret;
 }
コード例 #2
0
 public function page($tId, $study, $offset)
 {
     //Setup
     $ret = array();
     $description = TranslationProvider::getDescription('dt_studyTitle_trans');
     $category = $this->getName();
     //Page query:
     $o = $offset == -1 ? '' : " LIMIT 30 OFFSET {$offset}";
     $q = "SELECT Field, Trans " . "FROM Page_DynamicTranslation " . "WHERE TranslationId = 1 " . "AND Category = '{$category}'{$o}";
     foreach ($this->fetchRows($q) as $r) {
         $sName = $r[0];
         $q = $this->getTranslationQuery($sName, $tId);
         $translation = $this->querySingleRow($q);
         array_push($ret, array('Description' => $description, 'Original' => $r[1], 'Translation' => array('TranslationId' => $tId, 'Translation' => $translation[0], 'Payload' => $sName, 'TranslationProvider' => $this->getName())));
     }
     return $ret;
 }
コード例 #3
0
 /**
   Returns the autodetected TranslationId for the current client.
   Decision is taken as follows:
     1: Negotiate the clients preferred language
     2: Fallback to default to always have a target
 */
 public static function getTarget()
 {
     if (self::$targetMemo === null) {
         $db = Config::getConnection();
         //Phase1:
         if (array_key_exists('HTTP_ACCEPT_LANGUAGE', $_SERVER)) {
             $set = $db->query('SELECT TranslationId, BrowserMatch FROM Page_Translations WHERE Active = 1');
             while ($row = $set->fetch_assoc()) {
                 if (preg_match('/' . $row['BrowserMatch'] . '/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                     self::$targetMemo = $row['TranslationId'];
                     return self::getTarget();
                 }
             }
         }
         //Phase2:
         self::$targetMemo = self::$defaultTranslationId;
     }
     return self::$targetMemo;
 }
コード例 #4
0
 /**
   @param $category String
   @return $description array('Req' => String, 'Description' => String) || array()
   Given a $category this method fetches the description text that belongs to it.
 */
 public static function categoryToDescription($category)
 {
     //Checking projections:
     $regex = '/^' . preg_quote($category, '/') . '$/';
     $projections = TranslationColumnProjection::filterCategoryRegex(self::$projections, $regex);
     if (count($projections) !== 0) {
         $desc = current($projections)->getDescription();
         if ($desc instanceof Exception) {
             Config::error('' . $desc);
             return array();
         }
         return $desc;
     }
     //Checking provider edge case:
     if (array_key_exists($category, self::$providers)) {
         if ($category === 'StudyTitleTranslationProvider') {
             return TranslationProvider::getDescription('dt_studyTitle_trans');
         } else {
             Config::error("Unexpected case in Translation::categoryToDescription for {$category}");
         }
     }
     return array();
 }
コード例 #5
0
    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')));
}
コード例 #6
0
<?php

$startTime = microtime(true);
/* Constants: */
define('FLAGS_ENABLED', false);
/* Requirements: */
require_once 'config.php';
require_once 'query/translationProvider.php';
/* Startup: */
$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);