Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/API/API.php

    r804 r873  
    4747  {
    4848    // p - token
    49     if(array_key_exists('p', $_GET)) {
     49    if (array_key_exists('p', $_GET)) {
    5050      $Token = $_GET['p'];
    5151      $DbResult = $this->Database->query('SELECT `User` FROM `APIToken` WHERE `Token`="'.$Token.'"');
    52       if($DbResult->num_rows > 0)
     52      if ($DbResult->num_rows > 0)
    5353      {
    5454        $DbRow = $DbResult->fetch_assoc();
     
    5757    } else die('Missing access token');
    5858    // f - data format
    59     if(array_key_exists('f', $_GET)) $this->DataFormat = $_GET['f'];
     59    if (array_key_exists('f', $_GET)) $this->DataFormat = $_GET['f'];
    6060      else $this->DataFormat = 'php';
    6161    // a - action
    62     if(array_key_exists('a', $_GET)) $Action = $_GET['a'];
     62    if (array_key_exists('a', $_GET)) $Action = $_GET['a'];
    6363      else $Action = '';
    6464    // t - table
    65     if(array_key_exists('t', $_GET)) $Table = $_GET['t'];
     65    if (array_key_exists('t', $_GET)) $Table = $_GET['t'];
    6666      else $Table = '';
    6767    // i - index of item
    68     if(array_key_exists('i', $_GET)) $ItemId = $_GET['i'];
     68    if (array_key_exists('i', $_GET)) $ItemId = $_GET['i'];
    6969      else $ItemId = 0;
    7070
    71     if($Action == 'list') $Output = $this->ShowList($Table, $ItemId);
     71    if ($Action == 'list') $Output = $this->ShowList($Table, $ItemId);
    7272      else $Output = 'Unsupported action';
    7373
    74     return($Output);
     74    return ($Output);
    7575  }
    7676
    7777  function ShowList($Table, $ItemId)
    7878  {
    79     if(($Table != '') and (array_key_exists($Table, $this->System->FormManager->Classes)))
     79    if (($Table != '') and (array_key_exists($Table, $this->System->FormManager->Classes)))
    8080      $FormClass = $this->System->FormManager->Classes[$Table];
    81       else return('Table not found');
     81      else return ('Table not found');
    8282
    83     if(array_key_exists('SQL', $FormClass))
     83    if (array_key_exists('SQL', $FormClass))
    8484      $SourceTable = '('.$FormClass['SQL'].') AS `TX`';
    8585      else $SourceTable = '`'.$FormClass['Table'].'` AS `TX`';
    8686     
    8787    $Filter = '';
    88     if($ItemId != 0)
     88    if ($ItemId != 0)
    8989    {
    9090      $Filter .= '`Id`='.$ItemId;
    9191    }
    92     if($Filter != '') $Filter = ' WHERE '.$Filter;
     92    if ($Filter != '') $Filter = ' WHERE '.$Filter;
    9393
    9494    $Result = array();
    9595    $DbResult = $this->Database->query('SELECT * FROM '.$SourceTable.$Filter);
    96     while($DbRow = $DbResult->fetch_assoc())
     96    while ($DbRow = $DbResult->fetch_assoc())
    9797    {
    9898      $Result[] = $DbRow;
    9999    }
    100     if($this->DataFormat == 'php') $Output = serialize($Result);
    101       else if($this->DataFormat == 'xml') $Output = $this->array2xml($Result);
    102       else if($this->DataFormat == 'json') $Output = json_encode($Result);
     100    if ($this->DataFormat == 'php') $Output = serialize($Result);
     101      else if ($this->DataFormat == 'xml') $Output = $this->array2xml($Result);
     102      else if ($this->DataFormat == 'json') $Output = json_encode($Result);
    103103      else die('Unknown data format '.$this->DataFormat);
    104     return($Output);
     104    return ($Output);
    105105  }
    106106
     
    114114    $array2xml = function ($node, $array) use ($dom, &$array2xml)
    115115    {
    116       foreach($array as $key => $value)
     116      foreach ($array as $key => $value)
    117117      {
    118118        if ( is_array($value) )
    119119        {
    120           if(is_numeric($key)) $key = 'N'.$key; //die('XML tag name "'.$key.'" can\'t be numeric');
     120          if (is_numeric($key)) $key = 'N'.$key; //die('XML tag name "'.$key.'" can\'t be numeric');
    121121          $n = $dom->createElement($key);
    122122          $node->appendChild($n);
    123123          $array2xml($n, $value);
    124124        } else {
    125           if(is_numeric($key)) $key = 'N'.$key; //die('XML attribute name "'.$key.'" can\'t be numeric');
     125          if (is_numeric($key)) $key = 'N'.$key; //die('XML attribute name "'.$key.'" can\'t be numeric');
    126126          $attr = $dom->createAttribute($key);
    127127          $attr->value = $value;
Note: See TracChangeset for help on using the changeset viewer.