Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if cron run via /usr/bin/php #25

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function get_cart()
$cart->discount = 0;
if (isset($_SESSION['user_id']) && $user = $this->users->get_user(intval($_SESSION['user_id']))) {
$cart->discount = $user->discount;
$cart->discount_total = ($cart->discount * $cart->total_price) / 100;
}

$cart->total_price *= (100-$cart->discount)/100;
Expand Down
5 changes: 4 additions & 1 deletion api/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ public function __construct()
$this->vars['host'] = rtrim($_SERVER['HTTP_HOST']);

// Протокол (http OR https)
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"], 0, 5))=='https'? 'https' : 'http';
$protocol = 'http';
if(isset($_SERVER["SERVER_PROTOCOL"])) {
$protocol = strtolower(substr($_SERVER["SERVER_PROTOCOL"], 0, 5))=='https'? 'https' : 'http';
}
if (isset($_SERVER['HTTPS']) && (($_SERVER['HTTPS'] == 'on') || ($_SERVER['HTTPS'] == '1'))) {
$protocol = 'https';
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') {
Expand Down
115 changes: 68 additions & 47 deletions api/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ class Request extends Simpla
public function __construct()
{
parent::__construct();

if (get_magic_quotes_gpc()) {
$_POST = $this->stripslashes_recursive($_POST);
$_GET = $this->stripslashes_recursive($_GET);
$_COOKIE = $this->stripslashes_recursive($_COOKIE);
$_REQUEST = $this->stripslashes_recursive($_REQUEST);
}
}

/**
Expand Down Expand Up @@ -62,14 +55,14 @@ public function method($method = null)
private function _input_filter($val, $type = null)
{
if ($type == 'string') {
return strval(preg_replace('/[^\p{L}\p{Nd}\d\s_\-\.\%\s]/ui', '', $val));
return strval(preg_replace('/[^\p{L}\p{Nd}\d\s_\-.%]/ui', '', $val));
}

if ($type == 'integer' || $type == 'int') {
return intval($val);
}

if ($type == 'float' || $type == 'floatval') {
if ($type == 'float') {
return floatval($val);
}

Expand All @@ -91,9 +84,11 @@ private function _input_filter($val, $type = null)
*
* @param string $name
* @param string $type
* @param string $default
* @param bool $stripTags
* @return mixed
*/
public function get($name, $type = null)
public function get($name, $type = null, $default = null, $stripTags = true)
{
$val = null;
if (isset($_GET[$name])) {
Expand All @@ -104,6 +99,15 @@ public function get($name, $type = null)
$val = reset($val);
}

if (empty($val) && $default !== null) {
$val = $default;
}

// На входе удаляем html теги
if ($stripTags === true && !empty($val)) {
$val = $this->recursiveStripTags($val);
}

return $this->_input_filter($val, $type);
}

Expand All @@ -114,17 +118,21 @@ public function get($name, $type = null)
*
* @param string $name
* @param string $type
* @param string $default
* @return mixed
*/
public function post($name = null, $type = null)
{
public function post($name = null, $type = null, $default = null) {
$val = null;
if (!empty($name) && isset($_POST[$name])) {
$val = $_POST[$name];
} elseif (empty($name)) {
$val = file_get_contents('php://input');
}

if (empty($val) && $default !== null) {
$val = $default;
}

return $this->_input_filter($val, $type);
}

Expand All @@ -143,29 +151,21 @@ public function files($name, $name2 = null)
return $_FILES[$name][$name2];
} elseif (empty($name2) && !empty($_FILES[$name])) {
return $_FILES[$name];
} else {
return null;
}

return null;
}

/**
* Рекурсивная чистка магических слешей
*
* @param $var
* @return array|string
*/
private function stripslashes_recursive($var)
private function recursiveStripTags($val)
{
if (is_array($var)) {
$res = array();
foreach ($var as $k => $v) {
$res[$this->stripslashes_recursive($k)] = $this->stripslashes_recursive($v);
if (is_array($val) || is_object($val)) {
foreach ($val as $k => $v) {
$val[$k] = $this->recursiveStripTags($v);
}

return $res;
} else {
return stripslashes($var);
return $val;
}

return htmlspecialchars(strip_tags($val));
}

/**
Expand All @@ -188,42 +188,63 @@ public function check_session()
* @param array $params
* @return string
*/
public function url($params = array())
public function url($params = [])
{
$query = array();

$query = [];
$url = @parse_url($_SERVER["REQUEST_URI"]);
if (isset($url['query'])) {
if (!empty($url['query'])) {
parse_str($url['query'], $query);
}

if (get_magic_quotes_gpc()) {
foreach ($query as &$v) {
if (!is_array($v)) {
$v = stripslashes(urldecode($v));
}
}
}

foreach ($params as $name=>$value) {
foreach($params as $name=>$value) {
$query[$name] = $value;
}

$query_is_empty = true;
$queryIsEmpty = true;
foreach ($query as $name=>$value) {
if ($value!=='' && $value!==null) {
$query_is_empty = false;
$queryIsEmpty = false;
}
}

if (!$query_is_empty) {
if (!$queryIsEmpty) {
$url['query'] = http_build_query($query);
} else {
$url['query'] = null;
}

return http_build_url(null, $url);
}



/**
* Parses a url to extract the query parameters from it as a assoc array
* @param string $url
* @param bool $decode (optional) apply url decode
* @return array
*/
public function parseUrl($url = '', $decode = false)
{
if (empty($url)) {
$url = $_SERVER["REQUEST_URI"];
}
$urlData = parse_url($url);
if (empty($urlData['query'])) {
return null;
}
$query = explode("&", $urlData['query']);
$parameters = array();
foreach ($query as $parameter) {
$param = explode("=", $parameter);
if (!empty($param) && count($param) == 2) {
$parameters[$param[0]] = $decode == true ? urldecode($param[1]) : $param[1];
}
}

return $parameters;
}

/**
* Determine if the request is the result of an AJAX call.
*
Expand Down Expand Up @@ -326,14 +347,14 @@ function http_build_url($url, $parts=array(), $flags=HTTP_URL_REPLACE, &$new_url
$new_url = $parse_url;

return
((isset($parse_url['scheme'])) ? $parse_url['scheme'] . '://' : '')
((isset($parse_url['scheme'])) ? $parse_url['scheme'] . '://' : '')
.((isset($parse_url['user'])) ? $parse_url['user'] . ((isset($parse_url['pass'])) ? ':' . $parse_url['pass'] : '') .'@' : '')
.((isset($parse_url['host'])) ? $parse_url['host'] : '')
.((isset($parse_url['port'])) ? ':' . $parse_url['port'] : '')
.((isset($parse_url['path'])) ? $parse_url['path'] : '')
.((isset($parse_url['query'])) ? '?' . $parse_url['query'] : '')
.((isset($parse_url['fragment'])) ? '#' . $parse_url['fragment'] : '')
;
;
}
}

Expand Down