function __construct($ACTION = '', $data_filter = array(), $scopeSanitize = array(), $raw_scope_filter = array('ACTION', 'METHOD', 'id', 'scope', 'sc', 'hash', 'sessid', 'crm', 'agent', 'ip', 'city', 'Referer', 'http_referer'))
 {
     if (is_string($data_filter)) {
         $data_filter = explode(',', $data_filter);
     }
     if (is_string($raw_scope_filter)) {
         $raw_scope_filter = explode(',', $raw_scope_filter);
     }
     $this->raw_scope = array();
     defined('ACTION') or define('ACTION', $ACTION);
     RESTful::$filter = $data_filter;
     // Define method type
     if (empty($_SERVER['DOCUMENT_ROOT']) && !empty($_SERVER['SHELL'])) {
         define('METHOD', 'CONSOLE');
         //$this->private_name='CONSOLE';
     } else {
         $this->raw_scope['agent'] = $_SERVER['HTTP_USER_AGENT'];
         $this->raw_scope['ip'] = $ip = $_SERVER['REMOTE_ADDR'];
         if (isset($_SERVER['HTTP_REFERER'])) {
             $this->raw_scope['http_referer'] = $_SERVER['HTTP_REFERER'];
         }
         if (isset($_SERVER['REQUEST_METHOD'])) {
             define('METHOD', $_SERVER['REQUEST_METHOD']);
             //$this->private_name=$_SERVER['REQUEST_METHOD'];
         } else {
             define('METHOD', 'UNKNOWN');
         }
     }
     // Combine parameters
     if (METHOD == 'CONSOLE') {
         //$this->raw_scope = array_merge($this->raw_scope, $_SERVER['argv']);
         require API_CORE_PATH . '/class/rest/getoptions.php';
         $this->raw_scope = array_merge($this->raw_scope, getOptions());
     } else {
         $this->raw_scope = array_merge($this->raw_scope, $_REQUEST);
         $this->raw_scope = array_merge($this->raw_scope, $this->parseRequestHeaders());
     }
     // Расстановка значений
     $this->raw_scope['ACTION'] = $ACTION;
     $this->raw_scope['METHOD'] = METHOD;
     if (empty($this->raw_scope['scope']) && !empty($this->raw_scope['sc'])) {
         // sc - синоним scope
         $this->raw_scope['scope'] = $this->raw_scope['sc'];
         unset($this->raw_scope['sc']);
     }
     // Для дебага, возможность переопределять метод
     if (DEBUG && isset($_GET['METHOD'])) {
         $this->raw_scope['METHOD'] = $_GET['METHOD'];
     }
     $this->scope = $this->sanitize($this->filtrateScope($raw_scope_filter), $scopeSanitize);
     $this->data = $this->sanitize($this->filtrateScope(), $scopeSanitize);
     return $this->raw_scope;
 }
Ejemplo n.º 2
0
 function __construct($ACTION = '', $filter = array(), $arrSanitize = array())
 {
     $this->private_scope = array();
     defined('ACTION') or define('ACTION', $ACTION);
     $scope_filter = array('ACTION', 'METHOD', 'id', 'scope', 'sc', 'hash', 'sessid', 'crm', 'agent', 'ip', 'city', 'referer');
     RESTful::$filter = $filter;
     // Define method type
     if (isset($_SERVER['argc'])) {
         define('METHOD', 'CONSOLE');
         //$this->private_name='CONSOLE';
     } else {
         $this->private_scope['agent'] = $_SERVER['HTTP_USER_AGENT'];
         $this->private_scope['ip'] = $ip = $_SERVER['REMOTE_ADDR'];
         if (isset($_SERVER['HTTP_REFERER'])) {
             $this->private_scope['referer'] = $_SERVER['HTTP_REFERER'];
         }
         /*
         $link='http://api.sypexgeo.net/json/';
         $curl=curl_init();
         curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
         curl_setopt($curl,CURLOPT_URL,$link.$ip);
         curl_setopt($curl,CURLOPT_HEADER,false);
         $out=curl_exec($curl); #Инициируем запрос к API и сохраняем ответ в переменную
         $code=curl_getinfo($curl,CURLINFO_HTTP_CODE);
         curl_close($curl); #Завершаем сеанс cURL
         $res_arr=json_decode($out);
         $city=$res_arr->city->name_ru.', '.$res_arr->country->name_ru;
         $this->private_scope['city']=$city;
         */
         if (isset($_SERVER['REQUEST_METHOD'])) {
             define('METHOD', $_SERVER['REQUEST_METHOD']);
             //$this->private_name=$_SERVER['REQUEST_METHOD'];
         } else {
             define('METHOD', 'UNKNOWN');
         }
     }
     // Combine parameters
     if (METHOD == 'CONSOLE') {
         //$this->private_scope = array_merge($this->private_scope, $_SERVER['argv']);
         require API_CORE_PATH . '/class/rest/getoptions.php';
         $this->private_scope = array_merge($this->private_scope, getOptions());
     } else {
         $this->private_scope = array_merge($this->private_scope, $_REQUEST);
         $this->private_scope = array_merge($this->private_scope, $this->parseRequestHeaders());
     }
     // Расстановка значений
     $this->private_scope['ACTION'] = $ACTION;
     $this->private_scope['METHOD'] = METHOD;
     if (empty($this->private_scope['scope']) && !empty($this->private_scope['sc'])) {
         // sc - синоним scope
         $this->private_scope['scope'] = $this->private_scope['sc'];
         unset($this->private_scope['sc']);
     }
     // Для дебага, возможность переопределять метод
     if (DEBUG && isset($_GET['METHOD'])) {
         $this->private_scope['METHOD'] = $_GET['METHOD'];
     }
     $this->scope = $this->sanitize($this->filtrateScope($scope_filter), $arrSanitize);
     $this->data = $this->sanitize($this->filtrateScope(), $arrSanitize);
     return $this->private_scope;
 }