request into misc class.

main
Robert 3 years ago
parent 53d97e35d2
commit 1fe7d2e5ff
  1. 5
      documents/folders.txt
  2. 2
      src/bootstrap/common.php
  3. 4
      src/bootstrap/errors.php
  4. 2
      src/bootstrap/safer_io.php
  5. 6
      src/classes/api.php
  6. 6
      src/classes/app.php
  7. 2
      src/classes/database/help_save.php
  8. 2
      src/classes/html_document.php
  9. 2
      src/classes/memory_usage.php
  10. 44
      src/classes/misc.php
  11. 2
      src/classes/page_not_found.php
  12. 2
      src/classes/router.php
  13. 2
      src/classes/services/http_requests/http_curl_request.php
  14. 2
      src/classes/services/obsolete/http_socket_request.php
  15. 4
      src/classes/tag_matches.php
  16. 4
      src/classes/traits/security/csrf_token_functions.php
  17. 21
      src/classes/url_encode.php
  18. 16
      src/classes/view.php

@ -43,8 +43,8 @@ tts_framework/src
   ├── json.php (Outputs DB Records into JSON format)
   ├── loadall.php (Creates loadall.php files if do not exist for Services & Config-Files)
   ├── memory_usage.php (Displays PHP Memory Usage, when debug is set)
   ├── misc.php (create a short url from get_url, post_var, misc. filter FNs)
   ├── page_not_found.php (CLI or tts built in views/404 page not found error)
   ├── request.php (create a short url from get_url, post_var, misc. filter FNs)
   ├── router.php (router::get/post, etc... used to setup PHP routes)
   ├── safer_sql.php (Play-Testing SQL filter)
   ├── security.php (hasing, csrf_token\session_hijacking_functions)
@ -80,7 +80,6 @@ tts_framework/src
     └── security
     ├── csrf_token_functions.php (Get an Cross-Site Request Forge - Prevention Token)
     └── session_hijacking_functions.php (Prevent SESSION Hijacking and Fixation in PHP)
   ├── url_encode.php (base64url Encode/Decode)
│ ├── validator.php (validates HTML Forms)
   └── view.php (Loads view files from common folders you defined)
├── main.inc.php (Bootstraps App, sets configure, registry, di, and name-spaces)
@ -92,4 +91,4 @@ tts_framework/src
   └── broken.php (Debug Trace)
└── errors.php (when Live, this: Sorry, we had an error... Page is used)
~73 files
~72 files

@ -248,7 +248,7 @@ final class common {
* Clear out from memory given variable by Reference!
* @param type $sensitive_data
*/
public static function wipe(& $sensitive_data) {
public static function wipe(& $sensitive_data): void {
if (function_exists("sodium_memzero")) {
sodium_memzero($sensitive_data);
}

@ -25,7 +25,7 @@ function tts_broken_error($ex = ''): void {
echo $ex;
exit(1);
}
$use_api = \tts\request::is_api();
$use_api = \tts\misc::is_api();
if ($use_api === true) {
$internal_error = \tts\api::INTERNAL_ERROR;
@ -230,7 +230,7 @@ function tts_json_error_handler($data) {
$is_callback = filter_has_var(INPUT_GET, 'callback');
$is_json = filter_has_var(INPUT_GET, 'json');
if ( !\tts\request::is_ajax() && !$is_callback && !$is_json ) {
if ( !\tts\misc::is_ajax() && !$is_callback && !$is_json ) {
return false;
}

@ -255,7 +255,7 @@ final class safer_io {
}
}
public static function safer_html(string $input, HTML_FLAG $safety_level = HTML_FLAG::escape): string {
private static function safer_html(string $input, HTML_FLAG $safety_level = HTML_FLAG::escape): string {
switch ($safety_level) {
case HTML_FLAG::raw :
throw new \Exception('Raw HTML not supported!');

@ -58,7 +58,7 @@ class api {
* @param type $status_code
*/
public static function encode($data, $status_code): void {
$response_type = \tts\request::request_var('return');
$response_type = \tts\misc::request_var('return');
switch ($response_type) {
case 'xml':
self::xml_encode($data, $status_code, null);
@ -231,7 +231,7 @@ class api {
$data['code'] = $long_code;
$memory_check = \bs_tts\common::get_bool(\tts\request::request_var('debug'));
$memory_check = \bs_tts\common::get_bool(\tts\misc::request_var('debug'));
if ($memory_check) {
$echo = false;
$data['memory_used'] = \tts\memory_usage::get_memory_stats($echo);
@ -248,7 +248,7 @@ class api {
$data['result'] = true;
$code = 200; // OK
$memory_check = \bs_tts\common::get_bool(\tts\request::request_var('debug'));
$memory_check = \bs_tts\common::get_bool(\tts\misc::request_var('debug'));
if ($memory_check) {
$echo = false;
$data['memory_used'] = \tts\memory_usage::get_memory_stats($echo);

@ -75,7 +75,7 @@ class app {
$file = "";
$class = "";
if (\tts\request::is_empty($route)) {
if (\tts\misc::is_empty($route)) {
$uri = '/app/' . \main_tts\configure::get('tts', 'default_project');
} else {
$uri = $route;
@ -117,7 +117,7 @@ class app {
}
}
if (\tts\request::is_empty($method)) {
if (\tts\misc::is_empty($method)) {
$method = ""; // Clear out :null if exists
}
@ -161,7 +161,7 @@ class app {
$this->local404();
}
$use_api = \tts\request::is_api();
$use_api = \tts\misc::is_api();
$test = $this->get_ctrl_dir();
$project_folder = \bs_tts\site_helper::get_project();

@ -140,7 +140,7 @@ final class help_save {
continue;
}
if (in_array($key, $only_these) || !count($only_these)) {
$this->members[$key] = (\tts\request::is_not_empty($data)) ? $data : "";
$this->members[$key] = (\tts\misc::is_not_empty($data)) ? $data : "";
}
}
}

@ -282,7 +282,7 @@ class html_document {
* @param string $log
*/
public function js_log(string $log): void {
$this->add_to_javascript("tts_log('{$log}');");
$this->add_to_javascript("console.log('{$log}');");
}
/**

@ -29,7 +29,7 @@ final class memory_usage {
public static function get_memory_stats($echo = true) {
global $mem_baseline;
$check = \bs_tts\common::get_bool(\tts\request::request_var('debug'));
$check = \bs_tts\common::get_bool(\tts\misc::request_var('debug'));
if ($check || defined('DEBUG') && DEBUG === true) {
$now_mem = memory_get_usage();

@ -10,7 +10,7 @@ declare(strict_types=1);
namespace tts;
final class request {
final class misc {
public static function post_var(string $var, int $filter = FILTER_UNSAFE_RAW): mixed {
return filter_input(INPUT_POST, $var, $filter);
@ -86,10 +86,7 @@ final class request {
* @retval bool
*/
public static function is_not_empty(?string $var): bool {
if ($var === null) {
return false;
}
return ($var !==null && $var !== ':null' && !empty(trim($var))) ? true : false;
return ($var !== null && !empty(trim($var)));
}
/**
@ -98,29 +95,7 @@ final class request {
* @retval bool
*/
public static function is_empty(?string $var): bool {
if ($var === null) {
return true;
}
return ($var === null || $var === ':null' || empty(trim($var))) ? true : false;
}
/**
* Check if string was set
* @param string $var
* @retval bool true is set, false is null
*/
public static function is_set(?string $var): bool {
return ($var !== ':null' && $var !== null) ? true : false;
}
/**
* Check if string is null or not set
* @param string $var
* @retval bool
*/
public static function is_not_set(?string $var): bool {
return ($var === ':null' || $var === null) ? true : false;
return ($var === null || empty(trim($var)) );
}
/**
@ -353,6 +328,19 @@ final class request {
}
}
/**
* site http://php.net/manual/en/function.base64-encode.php
*/
public static function base64url_encode(string $data): string {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
public static function base64url_decode(string $data): string {
//return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
return base64_decode( strtr( $data, '-_', '+/') . str_repeat('=', 3 - ( 3 + strlen( $data )) % 4 ));
}
public static function get_globals(array $skip = ['route', 'm'], array $only_these = []): string {
$the_request = '';

@ -41,7 +41,7 @@ class page_not_found {
if (\tts\console_app::is_cli()) {
self::tts_error404_cli();
} else {
$use_api = \tts\request::is_api();
$use_api = \tts\misc::is_api();
}
if ($use_api === true) {

@ -453,7 +453,7 @@ class router
// Find route
foreach (self::$routes as $routeKey => $route) {
$post_method = \tts\request::post_var("_method");
$post_method = \tts\misc::post_var("_method");
$matchMethod = in_array($request_method, $route['method']) || ($post_method !== null
&& in_array($post_method, $route['method']));
if (preg_match($route['pattern'], $request, $match) && $matchMethod) {

@ -144,7 +144,7 @@ class http_curl_request {
return true;
}
$action_response = \tts\request::abort_on_crlf($action_response);
$action_response = \tts\misc::abort_on_crlf($action_response);
if (! $options->get_include_header() ) {
return ( $options->get_json_decode() ) ? json_decode($action_response, true) : $action_response;

@ -65,7 +65,7 @@ final class http_socket_request {
}
fclose($fp);
$ret = \tts\request::abort_on_crlf($ret);
$ret = \tts\misc::abort_on_crlf($ret);
if (! $options->get_include_http_response_headers() ) {
$ret = substr($ret, strpos($ret, "\r\n\r\n") + 4);

@ -49,11 +49,11 @@ public static function check_tags(string $page): array {
if ($total_still_open > 0) {
$msg = "{$total_still_open} possibly MISSING closing {$tag_name} !!!";
$alert .= "tts_log('{$msg}');\r\n";
$alert .= "console.log('{$msg}');\r\n";
$output .= (\main_tts\configure::get('tts', 'live') === true) ? "<!-- {$msg} -->\r\n" : "{$ui}{$msg}{$ui_end}\r\n";
} elseif ($total_still_open < 0) {
$msg = abs($total_still_open) . " possibly MISSING opening {$tag_name} !!!";
$alert .= "tts_log('{$msg}');\r\n";
$alert .= "console.log('{$msg}');\r\n";
$output .= (\main_tts\configure::get('tts', 'live') === true) ? "<!-- {$msg} -->\r\n" : "{$ui}{$msg}{$ui_end}\r\n";
}
}

@ -50,12 +50,12 @@ trait csrf_token_functions {
public static function csrf_token_is_valid(): bool {
$is_csrf = filter_has_var(INPUT_POST, 'csrf_token');
if ($is_csrf) {
$user_token = \tts\request::post_var('csrf_token');
$user_token = \tts\misc::post_var('csrf_token');
$stored_token = $_SESSION['csrf_token'] ?? '';
if (empty($stored_token)) {
return false;
}
return \tts\request::compair_it($user_token, $stored_token);
return \tts\misc::compair_it($user_token, $stored_token);
} else {
return false;
}

@ -1,21 +0,0 @@
<?php
declare(strict_types=1);
namespace tts;
final class url_encode {
/**
* site http://php.net/manual/en/function.base64-encode.php
*/
public static function base64url_encode(string $data): string {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
public static function base64url_decode(string $data): string {
//return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
return base64_decode( strtr( $data, '-_', '+/') . str_repeat('=', 3 - ( 3 + strlen( $data )) % 4 ));
}
}

@ -61,16 +61,16 @@ final class view {
private function find_view_path(string $view_file, string $render_path) {
$found = false;
$ct_default_paths = \main_tts\configure::get('view_mode', 'default_paths');
$get = \tts\request::request_var('render');
if (\tts\request::is_set($get) && in_array($get, $ct_default_paths)) {
if (($key = array_search($get, $ct_default_paths)) !== false) {
unset($ct_default_paths[$key]); // Remove as we'll make it first later...
$default_paths = \main_tts\configure::get('view_mode', 'default_paths');
$get = \tts\misc::request_var('render');
if (in_array($get, $default_paths)) {
if (($key = array_search($get, $default_paths)) !== false) {
unset($default_paths[$key]); // Remove as we'll make it first later...
}
array_unshift($ct_default_paths, $get); // Make First in Array!
array_unshift($default_paths, $get); // Make First in Array!
}
foreach ($ct_default_paths as $default) {
foreach ($default_paths as $default) {
$file = $this->get_file($view_file, $default, $render_path);
if ( ! empty($file) ) {
$found = true;
@ -224,7 +224,7 @@ final class view {
$page_output .= $tags['output'];
$page_output .= '<script type="text/javascript">'.$tags['alert'].'</script>';
foreach($this->files as $bad) {
$page_output .= "<script type=\"text/javascript\">tts_log('In view file:{$bad['file']}');\r\n</script>";
$page_output .= "<script type=\"text/javascript\">console.log'In view file:{$bad['file']}');\r\n</script>";
}
}
}

Loading…
Cancel
Save