Skip to content

Commit

Permalink
Merge pull request trongate#158 from DaFa66/master
Browse files Browse the repository at this point in the history
Add ID Parameter for Deletion in delete_one() Function
  • Loading branch information
trongate authored Dec 29, 2023
2 parents a767615 + ab22e17 commit c17c915
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 148 deletions.
69 changes: 33 additions & 36 deletions engine/Core.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Class Core
* Manages the serving of assets for the Trongate framework.
Expand Down Expand Up @@ -31,19 +32,19 @@ public function __construct() {
*/
private function serve_vendor_asset(): void {
$vendor_file_path = explode('/vendor/', ASSUMED_URL)[1];
$vendor_file_path = '../vendor/'.$vendor_file_path;
$vendor_file_path = '../vendor/' . $vendor_file_path;
if (file_exists($vendor_file_path)) {
if (strpos($vendor_file_path, '.css')) {
$content_type = 'text/css';
} else {
$content_type = 'text/plain';
}

header('Content-type: '.$content_type);
header('Content-type: ' . $content_type);
$contents = file_get_contents($vendor_file_path);
echo $contents;
die();
}else{
} else {
die('Vendor file not found.');
}
}
Expand All @@ -61,17 +62,17 @@ private function serve_module_asset(): void {

if (is_numeric($pos)) {
$target_module = str_replace(MODULE_ASSETS_TRIGGER, '', $url_segment_value);
$file_name = $url_segments[count($url_segments)-1];
$file_name = $url_segments[count($url_segments) - 1];

$target_dir = '';
for ($i=$url_segment_key+1; $i < count($url_segments)-1; $i++) {
$target_dir.= $url_segments[$i];
if ($i<count($url_segments)-2) {
$target_dir.= '/';
for ($i = $url_segment_key + 1; $i < count($url_segments) - 1; $i++) {
$target_dir .= $url_segments[$i];
if ($i < count($url_segments) - 2) {
$target_dir .= '/';
}
}

$asset_path = '../modules/'.strtolower($target_module).'/assets/'.$target_dir.'/'.$file_name;
$asset_path = '../modules/' . strtolower($target_module) . '/assets/' . $target_dir . '/' . $file_name;

if (file_exists($asset_path)) {
$content_type = mime_content_type($asset_path);
Expand All @@ -87,20 +88,19 @@ private function serve_module_asset(): void {
if (is_numeric($pos2)) {
$content_type = 'text/javascript';
}

}

if ($content_type === 'image/svg') {
$content_type.= '+xml';
$content_type .= '+xml';
}

//make sure not a PHP file or api.json
if((is_numeric(strpos($content_type, 'php'))) || ($file_name === 'api.json')) {
if ((is_numeric(strpos($content_type, 'php'))) || ($file_name === 'api.json')) {
http_response_code(422);
die();
}

header('Content-type: '.$content_type);
header('Content-type: ' . $content_type);
$contents = file_get_contents($asset_path);
echo $contents;
die();
Expand All @@ -109,7 +109,6 @@ private function serve_module_asset(): void {
}
}
}

}

/**
Expand All @@ -132,32 +131,31 @@ private function serve_child_module_asset(string $asset_path, string $file_name)

$bits = explode('-', $target_str);

if (count($bits)==2) {
if (strlen($bits[1])>0) {
if (count($bits) == 2) {
if (strlen($bits[1]) > 0) {
$parent_module = $bits[0];
$child_module = $bits[1];

$asset_path = str_replace($target_str, $parent_module.'/'.$child_module, $asset_path);
$asset_path = str_replace($target_str, $parent_module . '/' . $child_module, $asset_path);
if (file_exists($asset_path)) {

$content_type = mime_content_type($asset_path);

if ($content_type === 'text/plain'|| $content_type === 'text/html') {
if ($content_type === 'text/plain' || $content_type === 'text/html') {
$pos2 = strpos($file_name, '.css');
if (is_numeric($pos2)) {
$content_type = 'text/css';
}
$pos2 = strpos($file_name, '.js');
$pos2 = strpos($file_name, '.js');
if (is_numeric($pos2)) {
$content_type = 'text/javascript';
}
}

header('Content-type: '.$content_type);
header('Content-type: ' . $content_type);
$contents = file_get_contents($asset_path);
echo $contents;
die();

}
}
}
Expand All @@ -170,20 +168,19 @@ private function serve_child_module_asset(string $asset_path, string $file_name)
* @return void
*/
private function attempt_sql_transfer(string $controller_path): void {
$ditch = 'controllers/'.$this->current_controller.'.php';
$ditch = 'controllers/' . $this->current_controller . '.php';
$dir_path = str_replace($ditch, '', $controller_path);

$files = array();
foreach (glob($dir_path."*.sql") as $file) {
foreach (glob($dir_path . "*.sql") as $file) {
$file = str_replace($controller_path, '', $file);
$files[] = $file;
}

if (count($files)>0) {
if (count($files) > 0) {
require_once('tg_transferer/index.php');
die();
}

}

/**
Expand All @@ -196,7 +193,7 @@ private function serve_controller(): void {

if (isset($segments[1])) {
$module_with_no_params = explode('?', $segments[1])[0];
$this->current_module = strtolower($module_with_no_params);
$this->current_module = !empty($module_with_no_params) ? strtolower($module_with_no_params) : $this->current_module;
$this->current_controller = ucfirst($this->current_module);

if (defined('TRONGATE_PAGES_TRIGGER') && $segments[1] === TRONGATE_PAGES_TRIGGER) {
Expand All @@ -207,15 +204,16 @@ private function serve_controller(): void {

if (isset($segments[2])) {
$method_with_no_params = explode('?', $segments[2])[0];
$this->current_method = strtolower($method_with_no_params);
$this->current_method = !empty($method_with_no_params) ? strtolower($method_with_no_params) : $this->current_method;

if (substr($this->current_method, 0, 1) === '_') {
$this->draw_error_page();
}
}

if (isset($segments[3])) {
$this->current_value = explode('?', $segments[3])[0];
$no_query_params = explode('?', $segments[3])[0];
$this->current_value = !empty($no_query_params) ? $no_query_params : $this->current_value;
}

$controller_path = '../modules/' . $this->current_module . '/controllers/' . $this->current_controller . '.php';
Expand Down Expand Up @@ -337,13 +335,13 @@ private function handle_standard_endpoints(): void {
private function attempt_init_child_controller(string $controller_path): string {
$bits = explode('-', $this->current_controller);

if (count($bits)==2) {
if (strlen($bits[1])>0) {
if (count($bits) == 2) {
if (strlen($bits[1]) > 0) {

$parent_module = strtolower($bits[0]);
$child_module = strtolower($bits[1]);
$this->current_controller = ucfirst($bits[1]);
$controller_path = '../modules/'.$parent_module.'/'.$child_module.'/controllers/'.ucfirst($bits[1]).'.php';
$controller_path = '../modules/' . $parent_module . '/' . $child_module . '/controllers/' . ucfirst($bits[1]) . '.php';

if (file_exists($controller_path)) {
return $controller_path;
Expand All @@ -357,10 +355,10 @@ private function attempt_init_child_controller(string $controller_path): string
$this->current_module = $intercept_bits[0];
$this->current_controller = ucfirst($intercept_bits[0]);
$this->current_method = $intercept_bits[1];
$controller_path = '../modules/'.$this->current_module.'/controllers/'.$this->current_controller.'.php';
if(file_exists($controller_path)) {
$controller_path = '../modules/' . $this->current_module . '/controllers/' . $this->current_controller . '.php';
if (file_exists($controller_path)) {
return $controller_path;
}
}
}

$this->draw_error_page();
Expand All @@ -375,5 +373,4 @@ private function draw_error_page(): void {
load('error_404');
die(); //end of the line (all possible scenarios tried)
}

}
}
Loading

0 comments on commit c17c915

Please sign in to comment.