Fixes in routes, urls, etc

This commit is contained in:
absurdo 2023-06-18 19:46:22 +02:00
parent 841b16266a
commit 22b90ea1f6
4 changed files with 58 additions and 22 deletions

9
.htaccess.sample Normal file
View file

@ -0,0 +1,9 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
AcceptPathInfo On
</IfModule>

View file

@ -9,6 +9,8 @@ class Config {
static public $modules_allowed=['welcome'];
static public $base_url='';
}
function get_controller($controller, $args=[]) {
@ -32,6 +34,10 @@ function get_controller($controller, $args=[]) {
}
//Route is: /module/switch/
//Route is: /module/file/switch/
//Route is: /module/file/switch/parameter1/parameter2
function get_route($path_info) {
if($path_info!='') {
@ -42,7 +48,7 @@ function get_route($path_info) {
case 0:
$controller='modules/'.\PhangoApp\PhaRouter\Config::$home_module.'/controllers/index.php';
$controller='modules/'.\PhangoApp\PhaRouter\Config::$home_module.'/controllers/app.php';
return \PhangoApp\PhaRouter\get_controller($controller, []);
@ -50,7 +56,7 @@ function get_route($path_info) {
case 1:
$controller='modules/'.$arr_path[1].'/controllers/index.php';
$controller='modules/'.$arr_path[1].'/controllers/app.php';
if(in_array($arr_path[1], Config::$modules_allowed)) {
@ -91,7 +97,7 @@ function get_route($path_info) {
}
else {
$controller='modules/'.\PhangoApp\PhaRouter\Config::$home_module.'/controllers/index.php';
$controller='modules/'.\PhangoApp\PhaRouter\Config::$home_module.'/controllers/app.php';
return \PhangoApp\PhaRouter\get_controller($controller, []);
@ -140,3 +146,30 @@ function filter_path($path_info) {
return $final_path;
}
function make_url($module, $script='', $file='', $args=[]) {
$url='/'.$module;
if($script!='') {
$url.='/'.$script;
}
if($file!='') {
$url.='/'.$file;
}
if(count($args)>0) {
$url.='/'.implode('/', $args);
}
return Config::$base_url.'/index.php'.$url;
}

View file

@ -34,23 +34,7 @@ class Utils {
static public function slugify($text, $respect_upper=0, $replace_space='-', $replace_dot=0, $replace_barr=0)
{
/*$from='àáâãäåæçèéêëìíîïðòóôõöøùúûýþÿŕñ';
$to= 'aaaaaaaceeeeiiiidoooooouuuybyrn';
//$text = utf8_decode(urldecode($text));
$text = strtr($text, utf8_encode($from), $to);
echo $text;
$text=strtolower(trim($text));
$text=str_replace(' ', $replace_space, $text);
$text=preg_replace('~-+~', $replace_space, $text);
$text=preg_replace('~[^-\w]+~', '', $text);
return $text;*/
/*
$from='àáâãäåæçèéêëìíîïðòóôõöøùúûýþÿŕñÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÒÓÔÕÖØÙÚÛÝỲŸÞŔÑ¿?!¡()"|#*%,;+&$ºª<>`çÇ{}@~=^:´[]';
$to= 'aaaaaaaceeeeiiiidoooooouuuybyrnAAAAAACEEEEIIIIDOOOOOOUUUYYYBRN---------------------------------';
@ -84,13 +68,23 @@ class Utils {
$text = strtolower($text);
}
}*/
$text=iconv('utf-8', 'us-ascii//TRANSLIT', $text);
$text=trim(preg_replace('~'.$replace_space.'+~', $replace_space, $text), '-');
$text=preg_replace('~[^-\w]+~', '', $text);
return utf8_encode($text);
if (empty($text)) {
return 'n-a';
}else {
return iconv('us-ascii//TRANSLIT', 'utf-8', $text); // utf8_encode($text);
}
}