public function find()
 {
     $options = ['page' => FILTER_SANITIZE_NUMBER_INT, 'limit' => FILTER_SANITIZE_NUMBER_INT, 'type' => FILTER_SANITIZE_NUMBER_INT];
     $values = filter_input_array(INPUT_GET, $options);
     if (is_array($values)) {
         $options['page'] = FILTER_VALIDATE_INT;
         $options['limit'] = FILTER_VALIDATE_INT;
         $options['type'] = FILTER_VALIDATE_INT;
         $values = filter_var_array($values, $options);
     }
     if (empty($values) || $values['type'] === false) {
         $this->render404();
         return;
     }
     if ($values['page'] === false) {
         $values['page'] = 1;
     }
     if ($values['limit'] === false) {
         $values['limit'] = 10;
     }
     $news = $this->models->newsModel->paginateByType($values['type'], $values['page'], $values['limit']);
     $count = ceil($this->models->newsModel->count($values['type']) / (double) $values['limit']);
     if (count($news)) {
         $this->render('find', ['news' => $news, 'count' => $count, 'page' => $values['page']]);
     } else {
         $this->render404();
     }
 }
Exemplo n.º 2
0
/**
 * @param array $data исходные данные.
 * @param array $rules правила валидации.
 * @param array $errors ошибки, возникшие в ходе проверок.
 * @return array возвращает очищенные и отвалидированные данные согласано указанным правилам.
 * @link http://php.net/manual/ru/function.filter-var-array.php
 */
function sanitize(array $data, array $rules, &$errors = null)
{
    $errors = is_array($errors) ? $errors : [];
    foreach ($rules as $key => $rule) {
        $rule['flags'] = isset($rule['flags']) ? $rule['flags'] | FILTER_NULL_ON_FAILURE : FILTER_NULL_ON_FAILURE;
        $rule['required'] = isset($rule['required']) ? (bool) $rule['required'] : false;
        $rule['message'] = isset($rule['message']) ? $rule['message'] : '';
        $rules[$key] = $rule;
    }
    $data = array_map('trim', $data);
    $filteredData = filter_var_array($data, $rules);
    foreach ($filteredData as $attribute => $value) {
        $rule = $rules[$attribute];
        if (is_null($value)) {
            if ($data[$attribute] || $data[$attribute] === '' && $rule['required']) {
                sanitizeAddError($attribute, $rule['message'] ?: 'Не корректное значение в поле "{attribute}".', $errors);
            }
        }
        if (is_string($value)) {
            $value = trim($value);
            $filteredData[$attribute] = $value;
            if (!$value && $rule['required']) {
                sanitizeAddError($attribute, $rule['message'] ?: 'Не заполнено обязательное поле "{attribute}".', $errors);
            }
        }
    }
    return $filteredData;
}
Exemplo n.º 3
0
    public function decode($input)
    {
        $arr = explode(' ', $input);
        $decodedInput = $output = array();
        for ($i = 0; $i < count($arr); $i++) {
            $nextElement = $i+1;
            $key = substr($arr[$i], 1);

            if ($this->parameterExistsInSchema($key)) {
                if ($this->parameterHasValue($arr, $nextElement)) {
                    if ($this->parameterIsArray($key)) {
                        $value = explode(',', $arr[$nextElement]);
                    } else {
                        $value = $arr[$nextElement];
                    }
                    $i++;
                } else {
                   $value = true;
                }
            } else {
                throw new Exception("Parameter {$key} not defined");
            }
            
            $decodedInput[$key] = $value;
        }

        return filter_var_array($decodedInput, $this->schema);
    }
Exemplo n.º 4
0
 public static function sanitize(array $data, array $rules, $errors)
 {
     $errors = is_array($errors) ? $errors : [];
     foreach ($rules as $key => $rule) {
         $rule['flags'] = isset($rule['flags']) ? $rule['flags'] | FILTER_NULL_ON_FAILURE : FILTER_NULL_ON_FAILURE;
         $rule['required'] = isset($rule['required']) ? (bool) $rule['required'] : false;
         $rule['message'] = isset($rule['message']) ? $rule['message'] : '';
         $rules[$key] = $rule;
     }
     $data = filter_var_array($data, $rules);
     foreach ($data as $attribute => $value) {
         $rule = $rules[$attribute];
         if (is_null($value)) {
             self::addError($attribute, $rule['message'] ?: 'Не корректное значение в поле "{attribute}".', $errors);
         }
         if (is_string($value)) {
             if (!$value && $rule['required']) {
                 self::addError($attribute, $rule['message'] ?: 'Не заполнено обязательное поле "{attribute}".', $errors);
             }
         }
     }
     if (array_key_exists('password', $data) and array_key_exists('password_repeat', $data)) {
         if ($data['password'] != $data['password_repeat']) {
             self::$errors['password_repeat'] = 'Пароли не совпадают "password_repeat".';
         }
     }
     return $data;
 }
Exemplo n.º 5
0
 public function __construct()
 {
     parent::sessionStart();
     $filterArgs = array('tm_key' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'downloadToken' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'source' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'target' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH));
     $__postInput = filter_var_array($_REQUEST, $filterArgs);
     //NOTE: This is for debug purpose only,
     //NOTE: Global $_POST Overriding from CLI Test scripts
     //$__postInput = filter_var_array( $_POST, $filterArgs );
     $this->tm_key = $__postInput['tm_key'];
     $this->source = $__postInput['source'];
     $this->target = $__postInput['target'];
     $this->downloadToken = $__postInput['downloadToken'];
     parent::disableSessions();
     $userIsLogged = isset($_SESSION['cid']) && !empty($_SESSION['cid']);
     if (!$userIsLogged) {
         $output = "<pre>\n";
         $output .= " - REQUEST URI: " . print_r(@$_SERVER['REQUEST_URI'], true) . "\n";
         $output .= " - REQUEST Message: " . print_r($_REQUEST, true) . "\n";
         $output .= "\n\t";
         $output .= "Aborting...\n";
         $output .= "</pre>";
         Log::$fileName = 'php_errors.txt';
         Log::doLog($output);
         Utils::sendErrMailReport($output, "Download TMX Error: user Not Logged");
         $this->unlockToken();
         exit;
     }
     $this->uid = isset($_SESSION['uid']) && !empty($_SESSION['uid']) ? $_SESSION['uid'] : null;
     $this->userMail = isset($_SESSION['cid']) && !empty($_SESSION['cid']) ? $_SESSION['cid'] : null;
     $this->tmxHandler = new TMSService();
     $this->tmxHandler->setTmKey($this->tm_key);
 }
Exemplo n.º 6
0
 /**
  * @return string|false
  * @throws \RuntimeException
  */
 protected function route()
 {
     $path = $this->getPathInfo();
     if (empty($path)) {
         $controllerName = 'index';
         $actionName = 'index';
         $args = array();
     } else {
         $segments = explode('/', $path);
         $controllerName = $segments[0];
         $actionName = isset($segments[1]) ? $segments[1] : 'index';
         $args = filter_var_array(array_slice($segments, 2), FILTER_SANITIZE_STRING);
     }
     $class = '\\Readr\\Controller\\' . ucfirst($controllerName) . 'Controller';
     if (!class_exists($class)) {
         throw new \Exception("Page not found", 404);
     }
     $controller = new $class($this->getServiceManager());
     $method = $actionName . 'Action';
     if (!method_exists($controller, $method)) {
         throw new \Exception("Page not found", 404);
     }
     $response = call_user_func_array(array($controller, $method), $args);
     if (is_string($response)) {
         return $response;
     } elseif (is_array($response) || is_null($response)) {
         $template = 'readr/views/' . strtolower($controllerName) . '/' . strtolower($actionName) . '.phtml';
         $view = new View($template, $response);
         $layout = new View('readr/views/layout.phtml', array('title' => 'Readr', 'content' => $view->render()));
         return $layout->render();
     }
     return false;
 }
function sanitize(array $data, array $rules, array &$errors = null)
{
    $errors = is_array($errors) ? $errors : [];
    //если приходит не массив, то превратить в массив
    //1. этап - подготовка правил валидации / фильтрации
    foreach ($rules as $attribute => $rule) {
        $rule['flags'] = isset($rule['flags']) ? $rule['flags'] | FILTER_NULL_ON_FAILURE : FILTER_NULL_ON_FAILURE;
        $rule['required'] = isset($rule['required']) ? (bool) $rule['required'] : false;
        $rule['message'] = isset($rule['message']) ? $rule['message'] : '';
        $rules[$attribute] = $rule;
    }
    //var_dump($rules);
    //2. этап - непосредственно валидации / фильтрации
    $data = array_map('trim', $data);
    $filterData = filter_var_array($data, $rules);
    foreach ($filterData as $attribute => $value) {
        $rule = $rules[$attribute];
        if (is_null($value)) {
            if ($data[$attribute] || $data[$attribute] === '' && $rule['required']) {
                sanitizeAddError($attribute, $rule['message'] ?: 'Некорректное значение в поле {attribute}', $errors);
            }
        }
        if (is_string($value)) {
            $value = trim($value);
            //обрезаем пробелы,если есть лишние
            $filterData[$attribute] = $value;
            if (!$value && $rule['required']) {
                sanitizeAddError($attribute, $rule['message'] ?: 'Не заполнено обязательное поле {attribute}', $errors);
            }
        }
    }
    return $filterData;
}
Exemplo n.º 8
0
 public function filter_array($data = NULL, $filter = NULL, $options = NULL)
 {
     if (isset($filter)) {
         $this->filter = $filter;
     }
     return filter_var_array($data, $this->filter);
 }
Exemplo n.º 9
0
function validate_params($method, $params, $validators, $sanitizers)
{
    if ($method == 'GET') {
        $grab = $_GET;
    } else {
        if ($method == 'POST') {
            $grab = $_POST;
        }
    }
    $result = array();
    $filters = array();
    for ($i = 0; $i < count($validators); $i++) {
        if (isset($grab[$params[$i]])) {
            $filters[$params[$i]] = $validators[$i];
        } else {
            return false;
        }
    }
    $result = filter_var_array($grab, $filters);
    $filters = array();
    for ($i = 0; $i < count($sanitizers); $i++) {
        if ($result[$params[$i]] !== false) {
            $filters[$params[$i]] = $sanitizers[$i];
        } else {
            return false;
        }
    }
    return filter_var_array($result, $filters);
}
Exemplo n.º 10
0
 /**
  * @param (float|int|string)[] $republica
  * @param int $who_posted
  */
 public static function addRepublica(array $republica, $whoPosted, Database &$database)
 {
     $filterFloat = array('filter' => FILTER_SANITIZE_NUMBER_FLOAT, 'flags' => FILTER_FLAG_ALLOW_FRACTION);
     $options = array('name' => FILTER_SANITIZE_STRING, 'latitude' => $filterFloat, 'longitude' => $filterFloat, 'phone' => FILTER_SANITIZE_STRING, 'email' => FILTER_SANITIZE_EMAIL, 'address' => FILTER_SANITIZE_STRING, 'more' => FILTER_SANITIZE_STRING);
     $republica = filter_var_array($republica, $options);
     $whoPosted = filter_var($whoPosted, FILTER_SANITIZE_NUMBER_INT);
     $valid = (bool) filter_var($republica['email'], FILTER_VALIDATE_EMAIL);
     $valid &= (bool) filter_var($whoPosted, FILTER_VALIDATE_INT);
     $success = false;
     if ($valid) {
         $query = $database->prepare('
             INSERT INTO republicas (
                 name, latitude, longitude, phone, email,
                 address, who_posted, more 
             ) VALUES (
                 :name, :latitude, :longitude, :phone, :email,
                 :address, :who_posted, :more
             )
         ');
         do {
             $query->bindParam(':' . key($republica), current($republica));
         } while (next($republica) !== false);
         $query->bindParam(':who_posted', $whoPosted, Database::PARAM_INT);
         $success = $query->execute();
     }
     return $success;
 }
Exemplo n.º 11
0
 static function process($filters, $source = INPUT_POST, $required_by_default = false, $strict = true)
 {
     # parse filters
     list($filters, $required, $defaults) = self::parse_filters($filters, $required_by_default);
     # apply
     $d = is_array($source) ? filter_var_array($source, $filters) : filter_input_array($source, $filters);
     if ($d === null) {
         $d = array_fill_keys(array_keys($filters), null);
     }
     # check required and set undefined to null (rather than false)
     foreach ($filters as $field => $filter) {
         $isa = is_array($filter);
         if ($d[$field] === null || $d[$field] === false && ($isa ? $filter['filter'] : $filter) !== FILTER_VALIDATE_BOOLEAN) {
             if ($strict && isset($required[$field])) {
                 throw new UnexpectedValueException($field . ' is required');
             } elseif (isset($defaults[$field])) {
                 if ($filter !== FILTER_DEFAULT) {
                     if ($isa) {
                         $d[$field] = filter_var($defaults[$field], $filter['filter'], isset($filter['options']) ? $filter['options'] : null);
                     } else {
                         $d[$field] = filter_var($defaults[$field], $filter);
                     }
                 } else {
                     $d[$field] = $defaults[$field];
                 }
             } else {
                 $d[$field] = null;
             }
         }
     }
     return $d;
 }
Exemplo n.º 12
0
 /**
  * @param $data
  * @return mixed
  */
 public function sanitizeInputArray($data)
 {
     $filter = FILTER_SANITIZE_STRING;
     $flags = [FILTER_FLAG_STRIP_HIGH, FILTER_FLAG_STRIP_LOW];
     $args = $this->recursiveArgs($data, $filter, $flags);
     return filter_var_array($data, $args);
 }
 public function find()
 {
     $options = ['page' => FILTER_SANITIZE_NUMBER_INT, 'limit' => FILTER_SANITIZE_NUMBER_INT];
     $values = filter_input_array(INPUT_GET, $options);
     if (is_array($values)) {
         $options['page'] = FILTER_VALIDATE_INT;
         $options['limit'] = FILTER_VALIDATE_INT;
         $values = filter_var_array($values, $options);
     }
     if (empty($values)) {
         $values = ['page' => false, 'limit' => false];
     }
     if ($values['page'] === false) {
         $values['page'] = 1;
     }
     if ($values['limit'] === false) {
         $values['limit'] = 10;
     }
     $messages = $this->models->messageModel->paginate($values['page'], $values['limit'], ['date DESC']);
     $count = $this->models->messageModel->count();
     if (count($messages)) {
         $this->render('find', ['messages' => $messages, 'count' => $count, 'page' => $values['page']]);
     } else {
         $this->render404();
     }
 }
Exemplo n.º 14
0
function accountNightmode()
{
    require "functions/common.php";
    require "functions/import_info.php";
    if (isset($_GET['accountNightmode'])) {
        if (empty($_POST['nightmode_state'])) {
            die("You missed a field");
            header("Location: " . $_SERVER['SCRIPT_NAME']);
        }
        $_POST = filter_var_array($_POST, FILTER_SANITIZE_STRING);
        $email = $_SESSION['user']['email'];
        $first_name = $row_info['first_name'];
        $last_name = $row_info['last_name'];
        $birthday = $row_info['birthday'];
        $nightmode = $_POST['nightmode_state'];
        $user_id = $row_info['id'];
        $query = "\n\t\t\tREPLACE INTO info (\n\t\t\t\tid,\n\t\t\t\temail,\n\t\t\t\tfirst_name,\n\t\t\t\tlast_name,\n\t\t\t\tbirthday,\n\t\t\t\tnightmode\n\t\t\t) VALUES (\n\t\t\t\t'{$user_id}',\n\t\t\t\t'{$email}',\n\t\t\t\t'{$first_name}',\n\t\t\t\t'{$last_name}',\n\t\t\t\t'{$birthday}',\n\t\t\t\t'{$nightmode}'\n\t\t\t);";
        try {
            $stmt = $db->prepare($query);
            $stmt->execute();
            header("Location: " . $_SERVER['SCRIPT_NAME']);
        } catch (PDOException $ex) {
            die("Failed to run query: " . $ex->getMessage());
            header("Location: " . $_SERVER['SCRIPT_NAME']);
        }
    }
}
Exemplo n.º 15
0
 /** startInit() initiates the environment
  * @return void
  */
 public static function startInit()
 {
     @set_time_limit(0);
     @error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE);
     @ini_set('session.save_handler', 'mm');
     @ini_set('session.cookie_httponly', true);
     @ob_start('sanitize_output');
     @session_start();
     @session_cache_limiter('no-cache');
     @session_set_cookie_params(0, null, null, true, true);
     @set_magic_quotes_runtime(0);
     self::verCheck();
     self::extCheck();
     foreach ($_REQUEST as $key => $val) {
         $_REQUEST[$key] = is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING);
     }
     foreach ($_GET as $key => $val) {
         $_GET[$key] = is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING);
     }
     foreach ($_POST as $key => $val) {
         $_POST[$key] = is_array($val) ? filter_var_array($val, FILTER_SANITIZE_STRING) : filter_var($val, FILTER_SANITIZE_STRING);
     }
     foreach (array('node', 'sub', 'printertype', 'id', 'sub', 'crit', 'sort', 'confirm', 'tab') as $x) {
         global ${$x};
         ${$x} = isset($_REQUEST[$x]) ? filter_var($_REQUEST[$x], FILTER_SANITIZE_STRING) : '';
     }
     unset($x);
     new System();
     new Config();
 }
Exemplo n.º 16
0
 protected function _failRules($input)
 {
     $output = array();
     foreach ($input as $key => $value) {
         if (!empty($value)) {
             $output[$key] = $value;
         }
     }
     foreach ($this->_rules as $index => $stack) {
         $tmp_output = filter_var_array($output, array_intersect_key($stack, $output));
         foreach ($tmp_output as $key => $value) {
             if (empty($this->_rules[$index][$key])) {
                 continue;
             }
             if ($this->_validated[$key]) {
                 continue;
                 // skip values that allready failed validation
             }
             if (FILTER_VALIDATE_BOOLEAN == $this->_rules[$index][$key]['filter']) {
                 $tmp_output[$key] = (bool) $value;
             } elseif (false === $value) {
                 $this->_result->addError($key, $this->_messages[$index][$key]);
                 $this->_validated[$key] = true;
                 // set 'break validation chain' flag
             }
         }
         $output = array_merge($output, $tmp_output);
     }
     $output = array_merge($input, $output);
     $ok = $this->_result->ok();
     if ($ok) {
         $this->_result->import($output);
     }
     return !$ok;
 }
Exemplo n.º 17
0
 public function index_add()
 {
     $t_recipe = D('recipe');
     $id = filter_var($this->_get('id'), FILTER_VALIDATE_INT);
     $type = filter_var($this->_get('type'), FILTER_SANITIZE_STRING);
     $where = array('token' => session('token'), 'id' => $id, 'type' => $type);
     $recipe = $t_recipe->where($where)->find();
     if (IS_POST) {
         $filters = array('keyword' => array('filter' => FILTER_SANITIZE_STRIPPED, 'flags' => FILTER_SANITIZE_STRING, 'options' => FILTER_SANITIZE_ENCODED), 'title' => array('filter' => FILTER_SANITIZE_STRIPPED, 'flags' => FILTER_SANITIZE_STRING, 'options' => FILTER_SANITIZE_ENCODED));
         $_POST['begintime'] = strtotime(filter_var($this->_post('begintime'), FILTER_SANITIZE_STRING));
         $_POST['endtime'] = strtotime(filter_var($this->_post('endtime'), FILTER_SANITIZE_STRING));
         $_POST['type'] = filter_var($this->_post('type'), FILTER_SANITIZE_STRING);
         if ($_POST['begintime'] > $_POST['endtime']) {
             exit($this->error('您好,开始时间不能大于结束时间.', U("Recipe/index", array('token' => session('token'), 'type' => $type))));
         }
         $check = filter_var_array($_POST, $filters);
         if (!$check) {
             exit($this->error('您好,包含敏感字符,或者是不允许字串!', U("Recipe/index", array('token' => session('token'), 'type' => $type))));
         }
         $_POST['monday'] = serialize($_REQUEST['monday']);
         $_POST['tuesday'] = serialize($_REQUEST['tuesday']);
         $_POST['wednesday'] = serialize($_REQUEST['wednesday']);
         $_POST['thursday'] = serialize($_REQUEST['thursday']);
         $_POST['friday'] = serialize($_REQUEST['friday']);
         $_POST['saturday'] = serialize($_REQUEST['saturday']);
         $_POST['sunday'] = serialize($_REQUEST['sunday']);
         $_POST['token'] = session('token');
         if (!$t_recipe->create()) {
             exit($this->error($t_recipe->getError()));
         } else {
             $id = filter_var($this->_post('id'), FILTER_VALIDATE_INT);
             $status = filter_var($this->_post('status'), FILTER_SANITIZE_STRING);
             if ('edit' == $status && $id != '') {
                 $o = $t_recipe->where(array('id' => $id, 'token' => session('token')))->save($_POST);
                 if ($o) {
                     $data2['keyword'] = filter_var($this->_post('keyword'), FILTER_SANITIZE_STRING);
                     M('Keyword')->where(array('pid' => $id, 'token' => session('token'), 'module' => 'Recipe'))->data($data2)->save();
                     exit($this->success('修改成功', U("Recipe/index", array('token' => session('token'), 'type' => $_POST['type']))));
                 } else {
                     exit($this->error('修改失败', U("Recipe/index", array('token' => session('token'), 'type' => $_POST['type']))));
                 }
             } else {
                 if ($id = $t_recipe->data($_POST)->add()) {
                     $data1['pid'] = $id;
                     $data1['module'] = 'Recipe';
                     $data1['token'] = session('token');
                     $data1['keyword'] = filter_var($this->_post('keyword'), FILTER_SANITIZE_STRING);
                     M('Keyword')->add($data1);
                     $this->success('添加成功', U("Recipe/index", array('token' => session('token'), 'type' => $_POST['type'])));
                     exit;
                 } else {
                     exit($this->error('务器繁忙,添加失败,请稍候再试', U("Recipe/index", array('token' => session('token'), 'type' => $_POST['type']))));
                 }
             }
         }
     }
     $this->assign('recipe', $recipe);
     $this->display();
 }
 /**
  * {@inheritdoc}
  */
 public function getArray($definition = null, $addEmpty = true)
 {
     $values = array();
     foreach ($this->loadArray as $key) {
         $values[$key] = $this->getFunctionValue($key);
     }
     return filter_var_array($values, $definition, $addEmpty);
 }
Exemplo n.º 19
0
 public function validateNote($note = array(), $action = 'create')
 {
     $errors = array();
     $note = filter_var_array($note, array('id' => FILTER_SANITIZE_NUMBER_INT, 'body' => FILTER_SANITIZE_STRING, 'contact_id' => FILTER_SANITIZE_NUMBER_INT), false);
     if (isset($note['body']) && empty($note['body'])) {
         $errors[] = array('field' => 'body', 'message' => 'Note body cannot be empty');
     }
     return $errors;
 }
Exemplo n.º 20
0
 /**
  * @param null|string $key
  * @param null|mixed $default
  * @return mixed|null
  */
 public function get($key = null, $default = null)
 {
     if ($key === null) {
         return filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
     } elseif (isset($_GET[$key])) {
         return is_array($_GET[$key]) ? filter_var_array($_GET[$key], FILTER_SANITIZE_STRING) : filter_var($_GET[$key], FILTER_SANITIZE_STRING);
     }
     return $default;
 }
 public function __construct()
 {
     $filterArgs = array('id_project' => array('filter' => FILTER_SANITIZE_NUMBER_INT), 'password' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH), 'download_type' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH));
     $__postInput = filter_var_array($_REQUEST, $filterArgs);
     $this->id_project = $__postInput['id_project'];
     $this->password = $__postInput['password'];
     $this->download_type = $__postInput['download_type'];
     // switch flag, for now not important
 }
Exemplo n.º 22
0
 public function exchangeArray(array $data)
 {
     $definition = ['iduser' => FILTER_SANITIZE_NUMBER_INT, 'userfullname' => FILTER_SANITIZE_STRING, 'useremail' => FILTER_SANITIZE_EMAIL, 'userpassword' => FILTER_SANITIZE_STRING, 'usercurrentweight' => FILTER_SANITIZE_STRING, 'usercurrentheight' => FILTER_SANITIZE_STRING, 'userbirthday' => FILTER_SANITIZE_STRING];
     foreach (filter_var_array($data, $definition) as $key => $value) {
         if (property_exists($this, $key)) {
             $this->{$key} = empty($value) ? $this->{$key} : $value;
         }
     }
 }
Exemplo n.º 23
0
 public static function filter_vars(array $array)
 {
     $definition = array();
     foreach ($array as $name => $value) {
         $definition[$name]['filter'] = FILTER_CALLBACK;
         $definition[$name]['options'] = 'htmlspecialchars';
     }
     return filter_var_array($array, $definition);
 }
Exemplo n.º 24
0
 public static function open($config)
 {
     $configValidation = array('dbDir' => array('filter' => FILTER_CALLBACK, 'flags' => FILTER_NULL_ON_FAILURE, 'options' => function ($path) {
         return Helper::pathValidate($path, realpath('.'));
     }), 'dbName' => array('filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_LOW, 'default' => 'database.db'), 'useGzip' => FILTER_VALIDATE_BOOLEAN, 'data' => array('filter' => FILTER_CALLBACK, 'options' => function ($json) {
         return Helper::jsonValidate($json, false);
     }));
     $newConfig = filter_var_array($config, $configValidation);
     return new QueryablePHPDB($newConfig);
 }
Exemplo n.º 25
0
 public function write($data = null)
 {
     $this->appendLine($this->getTimestamp());
     $this->appendLine(filter_var_array($_SERVER, array('REMOTE_ADDR' => FILTER_SANITIZE_STRING, 'HTTP_USER_AGENT' => FILTER_SANITIZE_STRING, 'HTTP_REFERER' => FILTER_SANITIZE_STRING)));
     $this->appendLine(array('GET' => $_GET, 'POST' => $_POST, 'COOKIE' => $_COOKIE));
     if ($data) {
         $this->appendLine($data);
     }
     $this->appendLine();
     return $this->flush();
 }
Exemplo n.º 26
0
Arquivo: Http.php Projeto: BauRo/url
 /**
  * Returns the environment scheme
  *
  * @param  array $server the environment server typically $_SERVER
  *
  * @return string
  */
 protected static function fetchServerScheme(array $server)
 {
     $args = filter_var_array($server, ['HTTP_X_FORWARDED_PROTO' => ['filter' => FILTER_SANITIZE_STRING, 'options' => ['default' => '']], 'HTTPS' => ['filter' => FILTER_SANITIZE_STRING, 'options' => ['default' => '']]]);
     if (!empty($args["HTTP_X_FORWARDED_PROTO"])) {
         return $args["HTTP_X_FORWARDED_PROTO"] . ":";
     }
     if (empty($server["HTTPS"]) || 'off' == $server["HTTPS"]) {
         return "http:";
     }
     return "https:";
 }
Exemplo n.º 27
0
 /**
  * parse and sanitise the URI path
  */
 private function parsePath()
 {
     $parsed = array();
     $request_path = strtok($this->uri, '?');
     $base_path_len = strlen(rtrim(dirname($this->script_name), '\\/'));
     // Unescape and strip $base_path prefix, leaving q without a leading slash.
     $path = substr(urldecode($request_path), $base_path_len + 1);
     //make it clean
     $parsed = filter_var_array(explode('/', trim($path, '/')), FILTER_SANITIZE_STRING);
     $this->parsed_path = $parsed;
 }
Exemplo n.º 28
0
function perform_test($name, $test_filters, $add_empty)
{
    $params = array('null' => NULL, 'empty_array' => array(), 'filled_array' => array(1, 2, 3), 'int' => 1, 'double' => 1.0, 'string' => 'string');
    if ($add_empty) {
        $name .= ', Add empty';
    }
    echo "{$name}\n";
    $filters = array_fill_keys(array_keys($params), $test_filters);
    $filters['missing'] = $test_filters;
    var_dump(filter_var_array($params, $filters, $add_empty));
}
Exemplo n.º 29
0
 /**
  * Создание текста из шаблона
  * В шаблон вставляются переданные значения
  * При обработки шаблона могут довыбираться значения из $entity и создаваться команды в $request
  * @param string $template Полный путь на файл шаблона
  * @param array $v Значения для шаблона
  * @throws \Exception
  * @return string
  */
 function render($template, $v)
 {
     $text = file_get_contents($template);
     $vars = filter_var_array($v, FILTER_SANITIZE_SPECIAL_CHARS);
     // По циклу проходимся по всем переменным заменяя значения в {} на значения в массиве
     if (is_array($vars)) {
         foreach ($vars as $key => $value) {
             $text = str_replace('{' . $key . '}', $value, $text);
         }
     }
     return $text;
 }
Exemplo n.º 30
0
 public function testLocationDatabaseTrue()
 {
     $maker = new MakerFile(new Config(array('folder-database' => true, 'driver' => 'pgsql', 'framework' => 'zf1', 'schema' => array('public', 'quiz')), $this->basePath, 4));
     $arrBase = array($this->basePath, 'models', 'Pgsql');
     foreach ($maker->location as $index => $item) {
         $arrBaseFinal = $arrBase;
         $arrBaseFinal[] = ucfirst($index);
         $location = implode(DIRECTORY_SEPARATOR, filter_var_array($arrBaseFinal));
         $this->assertTrue($item == $location);
         unset($arrBaseFinal);
     }
 }