Enhance typeopenany.php with new attributes and update router.php for SEO URL handling and improved URL parsing.
This commit is contained in:
0
core/c/auto.php
Normal file → Executable file
0
core/c/auto.php
Normal file → Executable file
0
core/c/nibiru.php
Normal file → Executable file
0
core/c/nibiru.php
Normal file → Executable 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( )
|
||||
@@ -152,14 +150,17 @@ class Router extends Config
|
||||
$params = false;
|
||||
$param_parts = explode('?', $_SERVER["REQUEST_URI"]);
|
||||
$uri_parts = explode('/', $param_parts[0]);
|
||||
|
||||
|
||||
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'];
|
||||
|
||||
return in_array($slug, $commonActions, 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'];
|
||||
|
||||
return in_array($slug, $commonActions, true);
|
||||
}
|
||||
|
||||
public static function RouterDebug($value)
|
||||
{
|
||||
|
||||
@@ -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
0
core/c/typeswitch.php
Normal file → Executable file
Reference in New Issue
Block a user