Skip to content

Commit

Permalink
Merge pull request #6 from fellowgeek/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
fellowgeek authored Nov 19, 2023
2 parents 8a0090d + 299f5ee commit 0211b67
Show file tree
Hide file tree
Showing 12 changed files with 330 additions and 318 deletions.
38 changes: 24 additions & 14 deletions public/app/components/Component.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace app\components;

// prevent direct access
// Prevent direct access to this class.
if (isset($GLOBALS['OHCRUD']) == false) { die(); }

class Component extends \OhCrud\DB {
Expand All @@ -11,49 +11,59 @@ class Component extends \OhCrud\DB {
public $jsFiles = [];
public $cssFiles = [];
public $variables = [];
public $request;
public $directory;

public function __construct() {

// Constructor for the 'Component' class, which takes a $request parameter.
public function __construct($request, $path = null) {
parent::__construct();

$this->request = $_REQUEST;
// Assign the provided $request to the 'request' property.
$this->request = $request;
// Assign the current CMS path to 'path' property
$this->path = $path;
// Set the 'directory' property to the relative path from this script's location to the document root.
$this->directory = substr(__DIR__, strlen($_SERVER['DOCUMENT_ROOT'])) . '/';
// Define 'content' property
$this->content = new \app\models\mContent;

}

// Method to include a CSS file with an optional priority.
public function includeCSSFile($file, $priority = 100) {

if (isset($this->cssFiles[$file]) == false) {
$this->cssFiles[$file] = $priority;
asort($this->cssFiles);
}

}

// Method to include a JavaScript (JS) file with an optional priority.
public function includeJSFile($file, $priority = 100) {

if (isset($this->jsFiles[$file]) == false) {
$this->jsFiles[$file] = $priority;
asort($this->jsFiles);
}

}

// Method to load and render a view from a file.
public function loadView($fileName) {
$output = '';

// Check if the file specified by 'fileName' exists.
if (file_exists(__SELF__ . $fileName) == false) {
return false;
}

// Extract variables for use in the view, if 'variables' is not empty.
if (empty($this->variables) == false) {
extract($this->variables);
}

// Start output buffering, include the view file, and capture the output.
ob_start();
include(__SELF__ . 'app/views/' . $fileName);
include(__SELF__ . $fileName);
$output = \ob_get_clean();

return $output;

}

public function output($parameters = []) {
}

}
17 changes: 13 additions & 4 deletions public/app/controllers/cCMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct() {
}

// Handler for all incoming requests
public function defaultPathHandler($path, $pathArray) {
public function defaultPathHandler($path) {

$this->setOutputType(\OhCrud\Core::OUTPUT_HTML);

Expand Down Expand Up @@ -217,7 +217,7 @@ private function getComponent($componentString, $shouldSetOutputStatusCode = tru
// Check if the component exists
if (\file_exists(__SELF__ . 'app/components/' . $componentClassFile . '.php') == true && class_exists($componentClass) == true) {

$component = new $componentClass;
$component = new $componentClass($this->request, $this->path);
$component->output($componentParameters);
$content = $component->content;

Expand Down Expand Up @@ -286,11 +286,12 @@ private function getThemes() {

return \base64_encode(json_encode($themes));
}

// Process theme
private function processTheme() {

$output = '';
$javascriptGlobals = '';

// fallback to default theme ans layout if file does not exist
if (\file_exists(__SELF__ . 'themes/' . $this->theme . '/' . $this->layout . '.html') == false || $this->editMode == true) {
Expand Down Expand Up @@ -330,7 +331,15 @@ private function processTheme() {
$output = str_ireplace("{{CMS:CONTENT}}", $this->content->html . $editIconHTML, $output);
$output = str_ireplace("{{CMS:CONTENT-TEXT}}", $this->content->text, $output);
$output = str_ireplace("{{CMS:STYLESHEET}}", $this->content->stylesheet, $output);
$output = str_ireplace("{{CMS:JAVASCRIPT}}", $this->content->javascript, $output);

$javascriptGlobals .= "<script>\n";
$javascriptGlobals .= "const __SITE__ = '" . __SITE__ . "';\n";
$javascriptGlobals .= "const __OHCRUD_BASE_API_ROUTE__ = '" . __OHCRUD_BASE_API_ROUTE__ . "';\n";
$javascriptGlobals .= "const __OHCRUD_DEBUG_MODE__ = " . (__OHCRUD_DEBUG_MODE__ ? 'true' : 'false') . ";\n";
$javascriptGlobals .= "const __CSRF__ = '" . $this->CSRF() . "';\n";
$javascriptGlobals .= "</script>\n";
$output = str_ireplace("{{CMS:JAVASCRIPT}}", $javascriptGlobals . $this->content->javascript, $output);

$output = str_ireplace("{{CMS:OHCRUD}}", '<p>Oh CRUD! by <a href="https://erfan.me">ERFAN REED</a> - Copyright &copy; ' . date('Y') . ' - All rights reserved. Page generated in ' . round(microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"], 3) . ' second(s). | <a href="/login/">LOGIN</a></p>', $output);

$this->data = $output;
Expand Down
6 changes: 6 additions & 0 deletions public/app/models/mContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ class mContent {
// The HTML content.
public $html = '';

// The CSS content.
public $stylesheet = '';

// The JavaScript content.
public $javascript = '';

// Indicates if the content represents a 404 error page.
public $is404 = false;

Expand Down
40 changes: 20 additions & 20 deletions public/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0211b67

Please sign in to comment.