Skip to content
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
10 changes: 9 additions & 1 deletion core/a/mysql.db.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,13 @@ public function selectRowByFieldWhere( $field = array() )
return Pdo::fetchRowInArrayByWhere(self::$table['table'], $field['field'], $field['value']);
}


/**
* @desc Deletes a row from the database table by id.
* @param int $id The id of the row to delete.
* @return bool Returns true if the deletion is successful, otherwise false.
*/
public function deleteRowById(int $id = 0): bool
{
Pdo::deleteRowById( self::getTable()['table'], $id );
}
}
Empty file modified core/c/auto.php
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions core/c/formattributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ protected function _setAttributes( $attributes )
$this->_element = str_replace(' min="MIN"', '', $this->_element);
$this->_element = str_replace(' max="MAX"', '', $this->_element);
$this->_element = str_replace(' href="HREF"', '', $this->_element);
$this->_element = str_replace(' src="SRC"', '', $this->_element);
$this->_element = str_replace(' alt="ALT"', '', $this->_element);
$this->_element = str_replace(' style="STYLE"', '', $this->_element);
$this->_element = str_replace(' step="STEP"', '', $this->_element);
$this->_element = str_replace(' tabindex="TABINDEX"', '', $this->_element);
$this->_element = str_replace(' SPEECH', '', $this->_element);
Expand All @@ -95,6 +98,8 @@ protected function _setAttributes( $attributes )
$this->_element = str_replace(' VALUE', '', $this->_element);
$this->_element = str_replace(' PATTERN', '', $this->_element);
$this->_element = str_replace('ANY', '', $this->_element);
$this->_element = str_replace('data-sitekey="DATA-SITEKEY"', '', $this->_element);
$this->_element = str_replace('role="ROLE"', '', $this->_element);
}

/**
Expand Down
Empty file modified core/c/nibiru.php
100644 → 100755
Empty file.
96 changes: 76 additions & 20 deletions core/c/pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @category - [PLEASE SPECIFIY]
* @license - BSD License
*/
final class pdo extends Mysql implements IPdo
final class Pdo extends Mysql implements IPdo
{
private static $section = false;

Expand Down Expand Up @@ -55,11 +55,10 @@ protected static function loadTableNames(): array


/**
* @param string $string
*
* @return array|bool
*/
public static function query( $string = self::PLACE_NO_QUERY ): array|bool
* @param string $string
* @return mixed
*/
public static function query( $string = self::PLACE_NO_QUERY ): mixed
{

if(!strstr($string, IOdbc::PLACE_SQL_UPDATE))
Expand Down Expand Up @@ -91,7 +90,7 @@ public static function query( $string = self::PLACE_NO_QUERY ): array|bool
/**
* @return array
*/
private static function convertFetchToAssociative( array $result ): array
private static function convertFetchToAssociative( array $result ): array
{
$resultset = [];
if(array_key_exists(0, $result))
Expand Down Expand Up @@ -169,10 +168,10 @@ public static function selectDatasetByFieldAndValue($tablename = self::PLACE_TAB
* @return bool
*/
public static function updateColumnByFieldWhere( $tablename = self::PLACE_TABLE_NAME,
$column_name = IMysql::PLACE_COLUMN_NAME,
$parameter_name = IMysql::PLACE_SEARCH_TERM,
$field_name = IMysql::PLACE_FIELD_NAME,
$where_value = IMysql::PLACE_WHERE_VALUE ): bool
$column_name = IMysql::PLACE_COLUMN_NAME,
$parameter_name = IMysql::PLACE_SEARCH_TERM,
$field_name = IMysql::PLACE_FIELD_NAME,
$where_value = IMysql::PLACE_WHERE_VALUE ): bool
{
$statement = parent::getInstance( self::getSettingsSection() )->getConn();
$query = "UPDATE " . $tablename . " SET " . $column_name . " = :" . $column_name . " WHERE " . $field_name . " = :". $field_name;
Expand Down Expand Up @@ -264,12 +263,12 @@ public static function updateRowById(string $tableName, array $columnNames, arra
* @param bool $id
* @return array
*/
public static function fetchRowInArrayById($tablename = self::PLACE_TABLE_NAME, $id = self::NO_ID )
{
public static function fetchRowInArrayById($tablename = self::PLACE_TABLE_NAME, $id = self::NO_ID )
{
$result = array();
$statement = parent::getInstance( self::getSettingsSection() )->getConn();
$describe = $statement->query('DESC ' . $tablename);
$describe->execute();
$statement = parent::getInstance( self::getSettingsSection() )->getConn();
$describe = $statement->query('DESC ' . $tablename);
$describe->execute();
$tableInformation = $describe->fetchAll( \PDO::FETCH_ASSOC );
foreach ( $tableInformation as $entry )
{
Expand Down Expand Up @@ -374,9 +373,9 @@ public static function fetchRowsInArrayByWhere($tablename = IMysql::PLACE_TABLE_
* @return int|string
*/
public static function getLastInsertedID()
{
return parent::getInstance( self::getSettingsSection() )->getConn()->lastInsertId();
}
{
return parent::getInstance( self::getSettingsSection() )->getConn()->lastInsertId();
}

/**
* @param string $tablename
Expand Down Expand Up @@ -413,6 +412,63 @@ public static function fetchTableAsArray( $tablename = self::PLACE_TABLE_NAME, $
return $result;
}

/**
* @desc Deletes a row from the specified table by its ID.
* @param string $tablename The name of the table from which to delete the row. If empty, uses the default table.
* @param int $id The ID of the row to delete.
* @return bool Returns true if the deletion was successful, false otherwise.
*/
public static function deleteRowById(string $tablename = '', int $id = 0): bool
{
try {
// Validate that id is a valid number
if (!is_numeric($id) || $id <= 0)
{
throw new \InvalidArgumentException("FATAL ERROR in main CORE deleteRowById: Invalid ID value. Must be a positive number.");
}

// Validate table name
$validTables = self::loadTableNames();
if (!in_array($tablename, $validTables, true))
{
throw new \InvalidArgumentException("FATAL ERROR in main CORE deleteRowById: Invalid table name: {$tablename}");
}

// Get PDO instance
$pdo = parent::getInstance(self::getSettingsSection())->getConn();

// Fetch the primary key field name
$queryPrimaryKey = "SELECT COLUMN_NAME FROM information_schema.COLUMNS
WHERE TABLE_NAME = :tableName
AND COLUMN_KEY = 'PRI'
LIMIT 1";
$stmtPrimaryKey = $pdo->prepare($queryPrimaryKey);
$stmtPrimaryKey->bindValue(':tableName', $tablename);
$stmtPrimaryKey->execute();
$primaryKeyResult = $stmtPrimaryKey->fetch(\PDO::FETCH_ASSOC);

if (!$primaryKeyResult) {
throw new \RuntimeException('FATAL ERROR in main CORE deleteRowById: No primary key found for table ' . $tablename);
}

$primaryKeyField = $primaryKeyResult['COLUMN_NAME'];

// Prepare and execute DELETE statement
$query = "DELETE FROM " . $tablename . " WHERE " . $primaryKeyField . " = :id";
$stmt = $pdo->prepare($query);
$stmt->bindValue(':id', $id, \PDO::PARAM_INT);

return $stmt->execute();
} catch (\PDOException $e) {
error_log($e->getMessage());
return false;
} catch (\Exception $e) {
error_log($e->getMessage());
return false;
}
}


/**
* @desc will insert the array with fieldnames into the database, if the last parameter is set it should be a string containing the
* fieldname that should be encrypted
Expand All @@ -421,7 +477,7 @@ public static function fetchTableAsArray( $tablename = self::PLACE_TABLE_NAME, $
* @param bool $encrypted
* @return bool
*/
public static function insertArrayIntoTable( $tablename = IMysql::PLACE_TABLE_NAME, $array_name = IMysql::PLACE_ARRAY_NAME, $encrypted = IMysql::PLACE_DES_ENCRYPT ): bool
public static function insertArrayIntoTable( $tablename = IMysql::PLACE_TABLE_NAME, $array_name = IMysql::PLACE_ARRAY_NAME, $encrypted = IMysql::PLACE_DES_ENCRYPT ): bool
{
$statement = parent::getInstance( self::getSettingsSection() )->getConn();

Expand Down
116 changes: 63 additions & 53 deletions core/c/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,25 @@ protected static function getCurPage()
return self::$_cur_page;
}

/**
/**
* @desc sets the current page route in the router
*/
private static function setCurPage( )
{
$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";
Expand Down Expand Up @@ -252,6 +255,17 @@ private static function setPageParams( $uri_parts )
}

}
else
{
// Handle single trailing URL segments (e.g., /admin/adwordsgenerator/machines)
if(!is_numeric($uri_parts[$i]) && !empty($uri_parts[$i]))
{
if(!array_key_exists($uri_parts[$i], $_REQUEST))
{
$_REQUEST[$uri_parts[$i]] = '';
}
}
}
}
}
}
Expand All @@ -269,64 +283,60 @@ public function currentPage()
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 slug contains non-numeric characters (to differentiate from traditional URLs)
if (is_numeric($slug))
{
return false;
}
// Validate that the last part is numeric (ID)
if (!is_numeric($possibleId)) {
return false;
}

// Validate that the slug is not an existing action name
if (self::isExistingAction($controller, $slug))
{
return false;
}
// Validate that the slug contains non-numeric characters (to differentiate from traditional URLs)
if (is_numeric($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
// Validate that the slug is not an existing action name
if (self::isExistingAction($controller, $slug)) {
return false;
}

return true;
}
// 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

/**
* @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 true;
}

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)
{
Expand Down
18 changes: 12 additions & 6 deletions core/c/typeopenany.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
class TypeOpenAny extends FormAttributes implements IForm
{
private $_attributes = array(
self::FORM_VALUE => '',
self::FORM_ATTRIBUTE_ID => '',
self::FORM_ATTRIBUTE_CLASS => '',
self::FORM_ATTRIBUTE_ANY => '',
self::FORM_ATTRIBUTE_HREF => ''
self::FORM_VALUE => '',
self::FORM_ATTRIBUTE_ID => '',
self::FORM_ATTRIBUTE_CLASS => '',
self::FORM_ATTRIBUTE_ANY => '',
self::FORM_ATTRIBUTE_HREF => '',
self::FORM_ATTRIBUTE_SRC => '',
self::FORM_ATTRIBUTE_ALT => '',
self::FROM_ATTRIBUTE_STYLE => '',
self::FORM_ATTRIBUTE_DATA_SITEKEY => '',
self::FORM_ATTRIBUTE_TYPE => '',
self::FORM_ATTRIBUTE_ROLE => ''
);

/**
Expand All @@ -35,6 +41,6 @@ public function loadElement($attributes)
*/
private function _setElement( )
{
$this->_element = '<ANY href="HREF" ID CLASS>' . 'VALUE' . "\n";
$this->_element = '<ANY type="TYPE" href="HREF" src="SRC" alt="ALT" style="STYLE" data-sitekey="DATA-SITEKEY" ID CLASS role="ROLE">' . 'VALUE' . "\n";
}
}
Empty file modified core/c/typeswitch.php
100644 → 100755
Empty file.
7 changes: 7 additions & 0 deletions core/i/IDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,11 @@ public function nextInsertIndex();
* @return mixed
*/
public function loadPasswordByUsername( $user_name = false );

/**
* @desc Deletes a row from the database by its ID.
* @param int $id The ID of the row to be deleted. Defaults to 0.
* @return bool Returns true if the deletion was successful, false otherwise.
*/
public function deleteRowById( int $id = 0 ): bool;
}
Loading