This commit is contained in:
2026-05-13 21:17:36 +03:00
parent e43b94ba20
commit 3a6ab777c9
49 changed files with 9247 additions and 210 deletions

1
core/.htaccess Normal file
View File

@@ -0,0 +1 @@
Deny from all

44
core/classes/Engine.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
class Engine
{
protected $appPath;
protected $templatesPath;
public $viewPath;
public function __construct($appPath = APP, $templatesPath = TEMPLATES)
{
$this->appPath = rtrim($appPath, '/') . '/';
$this->templatesPath = rtrim($templatesPath, '/') . '/';
$this->viewPath = $this->determineViewPath($this->_urlParams());
}
protected function determineViewPath($urlParams): string
{
$path1 = $this->appPath . "app/views" . $urlParams . '.php';
$path2 = $this->appPath . "app/views" . $urlParams . '/index.php';
$path3 = $this->appPath . "app/views" . $urlParams . '.md';
$path4 = $this->appPath . "app/views" . $urlParams . '/index.md';
$path404 = $this->templatesPath . 'error404.php';
if (file_exists($path1)) {
return $path1;
} elseif (file_exists($path2)) {
return $path2;
} elseif (file_exists($path3)) {
return $path3;
} elseif (file_exists($path4)) {
return $path4;
} else {
return $path404;
}
}
private function _urlParams(): string
{
$serverURL = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);
// Normalize URL by removing trailing slashes
return rtrim($serverURL, "/");
}
}

49
core/classes/Framex.php Normal file
View File

@@ -0,0 +1,49 @@
<?php
class Framex extends Engine
{
private $viewsPath;
public function __construct($appPath = APP, $templatesPath = TEMPLATES, $viewsPath = VIEWS)
{
parent::__construct($appPath, $templatesPath);
$this->viewsPath = rtrim($viewsPath, '/') . '/';
}
public function renderTemplate(string $file, array $data = []): void
{
$filePath = $this->appPath . "templates/" . $file . ".php";
if (file_exists($filePath)) {
if (!empty($data)) {
extract($data);
}
require_once $filePath;
} else {
// Handle the error appropriately, e.g., log it or throw an exception
echo "Template file not found: " . htmlspecialchars($filePath);
}
}
public function init(): void
{
$file = $this->viewPath;
$data = [];
if (!file_exists($file)) {
$file = $this->viewsPath . 'templates/404.php';
}
if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'md') {
$markdown = file_get_contents($file);
$parsedown = new Parsedown();
$data['view'] = '<article class="prose prose-shell">' . $parsedown->text($markdown) . '</article>';
} else {
ob_start();
require_once $file;
$data['view'] = ob_get_clean();
}
$template = $data['template'] ?? 'main';
$this->renderTemplate($template, $data);
}
}

1995
core/classes/Parsedown.php Normal file

File diff suppressed because it is too large Load Diff

33
core/config.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
define('DEV_MODE', true);
define('TOPLINK', 'javascript:void(0)');
define('SITE_URL', $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . '/');
define('SITE_URI', (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
define('APP', str_replace("\\", "/", dirname(__DIR__) . '/'));
define('ROOT', $_SERVER['DOCUMENT_ROOT']);
define('CORE', APP . 'core/');
define('VIEWS', APP . 'app/views/');
define('TEMPLATES', APP . 'templates/');
define('CSS', '/css/');
define('JS', '/js/');
define('IMAGES', '/images/');
define('IMG', '/images/img/');
define('HOST', 'localhost');
define('USER', 'sk');
define('PASSWORD', 'Ser026322!!');
define('DATABASE', 'framex-alpha');
date_default_timezone_set('Europe/Athens');
function site(string $param): string {
$values = [
'core' => 'ELLHNIKA',
];
return $values[$param] ?? '';
}

152
core/functions.php Normal file
View File

@@ -0,0 +1,152 @@
<?php
/**
* Enhanced version with additional features
* usage:
* echo asset('css/style.css');
* asset('js/plugins.js', ['prefix' => 'framex', 'hash' => true])
* echo asset('js/app.js', ['absolute' => true, 'hash' => true]);
* echo asset('images/logo.png', ['fallback' => '/images/default-logo.png']);
*/
function asset($path, $options = []) {
// Default options
$defaults = [
'absolute' => false,
'fallback' => null, // Fallback URL if file doesn't exist
'prefix' => 'v', // Version parameter prefix
'hash' => false // Use file hash instead of timestamp
];
$options = array_merge($defaults, $options);
// Remove leading slash
$path = ltrim($path, '/');
$documentRoot = $_SERVER['DOCUMENT_ROOT'];
$fullPath = $documentRoot . '/' . $path;
// Generate version parameter
$version = '';
if (file_exists($fullPath)) {
if ($options['hash']) {
// Use file hash (more reliable for cache busting)
$version = '?' . $options['prefix'] . '=' . substr(md5_file($fullPath), 0, 8);
} else {
// Use modification time
$version = '?' . $options['prefix'] . '=' . filemtime($fullPath);
}
} elseif ($options['fallback']) {
// Return fallback URL if provided
return $options['fallback'];
} else {
error_log("Asset not found: " . $fullPath);
}
// Build URL
if ($options['absolute']) {
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'];
return $protocol . '://' . $host . '/' . $path . $version;
} else {
return '/' . $path . $version;
}
}
/**
* Get Partials
*
* @param string $name The name of the partial to include.
* @throws Exception If the partial does not exist.
*/
function partial(string $name): void {
$path = TEMPLATES . '/partials/' . $name . '.php';
if (file_exists($path)) {
include $path;
} else {
throw new Exception("Partial '{$name}' doesn't exist");
}
}
function codeBlock($code, $language = 'php') {
// 1. Convert special characters to HTML entities to prevent execution/bugs
$safe_code = htmlspecialchars($code, ENT_QUOTES, 'UTF-8');
// 2. Wrap in <pre> and <code> tags with the appropriate class
$output = '<pre class="line-numbers rounded"><code class=" code-font language-' . $language . '">';
$output .= $safe_code;
$output .= '</code></pre>';
return $output;
}
/**
* Pre Helper
*
* @param mixed $array The data to print.
* @param bool|null $die Whether to stop execution after printing.
* @param bool $report Whether to echo the data directly.
*/
function pre($array, ?bool $die = null, bool $report = false): void {
if ($report) {
echo $array;
}
echo '<pre>' . print_r($array, true) . '</pre>';
if ($die) {
die();
}
}
/**
* Get Random Image
*
* @param int $width The width of the image.
* @param int $height The height of the image.
* @return string The URL of the random image.
*/
function image(int $width = 960, int $height = 576): string {
return 'https://picsum.photos/' . $width . '/' . $height . '?v=' . rand();
}
/**
* Sanitize Input
*
* @param string $data The data to sanitize.
* @return string The sanitized data.
*/
function e(string $data): string {
return htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
}
/**
* Summarize Text
*
* @param string $text The text to summarize.
* @param int $maxLength The maximum length of the summary.
* @return string The summarized text.
*/
function summarize(string $text, int $maxLength = 100): string {
if (strlen($text) <= $maxLength) {
return $text;
}
$summary = substr($text, 0, $maxLength);
return $summary . '...';
}
function urlSlug($value, $transliteration = true)
{
if (extension_loaded('intl') && $transliteration == true) {
$transliterator = \Transliterator::create('Any-Latin; Latin-ASCII');
$value = $transliterator->transliterate($value);
}
$slug = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
$slug = preg_replace('~[^\pL\d]+~u', '-', $slug);
$slug = trim($slug, '-');
$slug = strtolower($slug);
return $slug;
}

17
core/ignition.php Normal file
View File

@@ -0,0 +1,17 @@
<?php
ini_set('session.cookie_httponly', 1);
ini_set('session.cookie_secure', 1); // Only if using HTTPS
session_start();
require_once 'config.php';
require_once 'functions.php';
spl_autoload_register(function ($className) {
$file = APP . 'core/classes/' . $className . '.php';
if (file_exists($file)) {
include $file;
}
});