Enhance typeopenany.php with new attributes and update router.php for SEO URL handling and improved URL parsing.

This commit is contained in:
stephan.kasdorf
2025-09-29 13:39:18 +02:00
parent b550605bc2
commit b131d5cacc
5 changed files with 65 additions and 64 deletions

0
core/c/auto.php Normal file → Executable file
View File

0
core/c/nibiru.php Normal file → Executable file
View File

View File

@@ -1,7 +1,5 @@
<?php
namespace Nibiru;
use phpseclib3\File\ASN1\Maps\FieldElement;
/**
* User - stephan
* Date - 24.01.17
@@ -144,7 +142,7 @@ class Router extends Config
return self::$_cur_page;
}
/**
/**
* @desc sets the current page route in the router
*/
private static function setCurPage( )
@@ -155,11 +153,14 @@ class Router extends Config
if(is_array($uri_parts))
{
// FIRST: Check for SEO URLs before standard processing
if (self::handleSeoUrls($uri_parts))
{
// SEO URL was handled, skip normal processing
return;
}
// STANDARD PROCESSING (UNCHANGED)
if($uri_parts[1] == "")
{
self::$_cur_page = "index";
@@ -252,15 +253,16 @@ class Router extends Config
}
}
}
else
}
else
{
// Handle single trailing URL segments (e.g., /admin/adwordsgenerator/machines)
if(!is_numeric($uri_parts[$i]) && !empty($uri_parts[$i]))
{
// Handle single trailing URL segments
if(!is_numeric($uri_parts[$i]) && !empty($uri_parts[$i]))
if(!array_key_exists($uri_parts[$i], $_REQUEST))
{
if(!array_key_exists($uri_parts[$i], $_REQUEST))
{
$_REQUEST[$uri_parts[$i]] = '';
}
$_REQUEST[$uri_parts[$i]] = '';
}
}
}
@@ -281,64 +283,60 @@ class Router extends Config
return self::getCurPage();
}
/**
* @desc Generic SEO URL handler for framework-wide SEO-friendly URLs
* @param array $uri_parts The URI parts from the request
* @return bool Returns true if SEO URL was handled, false otherwise
*/
private static function handleSeoUrls($uri_parts)
{
// Check if we have the minimum required parts for SEO URL: /controller/slug/id
if (!is_array($uri_parts) || count($uri_parts) < 4)
{
return false;
}
/**
* @desc Generic SEO URL handler for framework-wide SEO-friendly URLs
* @param array $uri_parts The URI parts from the request
* @return bool Returns true if SEO URL was handled, false otherwise
*/
private static function handleSeoUrls($uri_parts)
{
// Check if we have the minimum required parts for SEO URL: /controller/slug/id
if (!is_array($uri_parts) || count($uri_parts) < 4) {
return false;
}
// Extract components
$controller = $uri_parts[1] ?? '';
$slug = $uri_parts[2] ?? '';
$possibleId = $uri_parts[3] ?? '';
// Extract components
$controller = $uri_parts[1] ?? '';
$slug = $uri_parts[2] ?? '';
$possibleId = $uri_parts[3] ?? '';
// Validate that the last part is numeric (ID)
if (!is_numeric($possibleId))
{
return false;
}
// Validate that the last part is numeric (ID)
if (!is_numeric($possibleId)) {
return false;
}
// Validate that the slug contains non-numeric characters (to differentiate from traditional URLs)
if (is_numeric($slug))
{
return false;
}
// Validate that the slug contains non-numeric characters (to differentiate from traditional URLs)
if (is_numeric($slug)) {
return false;
}
// Validate that the slug is not an existing action name
if (self::isExistingAction($controller, $slug))
{
return false;
}
// Validate that the slug is not an existing action name
if (self::isExistingAction($controller, $slug)) {
return false;
}
// SEO URL detected - transform it to standard routing
self::$_cur_page = $controller;
self::setAction('detail'); // Default action for SEO URLs
$_REQUEST['id'] = $possibleId;
$_REQUEST['slug'] = $slug; // Preserve slug for potential use in controllers
// SEO URL detected - transform it to standard routing
self::$_cur_page = $controller;
self::setAction('detail'); // Default action for SEO URLs
$_REQUEST['id'] = $possibleId;
$_REQUEST['slug'] = $slug; // Preserve slug for potential use in controllers
return true;
}
return true;
}
/**
* @desc Check if a slug matches an existing controller action
* @param string $controller The controller name
* @param string $slug The potential action/slug
* @return bool Returns true if it's an existing action
*/
private static function isExistingAction($controller, $slug)
{
// List of common actions that should not be treated as SEO slugs
$commonActions = ['detail', 'list', 'edit', 'delete', 'create', 'update', 'page', 'navigation', 'requestForm'];
/**
* @desc Check if a slug matches an existing controller action
* @param string $controller The controller name
* @param string $slug The potential action/slug
* @return bool Returns true if it's an existing action
*/
private static function isExistingAction($controller, $slug)
{
// List of common actions that should not be treated as SEO slugs
$commonActions = ['detail', 'list', 'edit', 'delete', 'create', 'update', 'page', 'navigation', 'requestForm'];
return in_array($slug, $commonActions, true);
}
return in_array($slug, $commonActions, true);
}
public static function RouterDebug($value)
{

View File

@@ -15,7 +15,10 @@ class TypeOpenAny extends FormAttributes implements IForm
self::FORM_ATTRIBUTE_ID => '',
self::FORM_ATTRIBUTE_CLASS => '',
self::FORM_ATTRIBUTE_ANY => '',
self::FORM_ATTRIBUTE_HREF => ''
self::FORM_ATTRIBUTE_HREF => '',
'src' => '',
'alt' => '',
'style' => ''
);
/**
@@ -35,6 +38,6 @@ class TypeOpenAny extends FormAttributes implements IForm
*/
private function _setElement( )
{
$this->_element = '<ANY href="HREF" ID CLASS>' . 'VALUE' . "\n";
$this->_element = '<ANY href="HREF" src="SRC" alt="ALT" style="STYLE" ID CLASS>' . 'VALUE' . "\n";
}
}

0
core/c/typeswitch.php Normal file → Executable file
View File