Skip to content

Commit 0deef8e

Browse files
committed
WIP last semi-working version before major refactor
1 parent 6f02f23 commit 0deef8e

File tree

5 files changed

+96
-147
lines changed

5 files changed

+96
-147
lines changed

public/index.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4-
// index.php 20150101 - 20250128
4+
// Creared: 20150101 - Updated: 20250202
55
// Copyright (C) 2015-2025 Mark Constable <markc@renta.net> (AGPL-3.0)
66

77
const DBG = true;
@@ -28,9 +28,9 @@
2828
'g' => null, // Group/Category
2929
'f' => 'html', // Rendering Format
3030
'i' => null, // Item or ID
31-
'l' => '', // Log (message)
32-
'm' => 'list', // Method (action)
33-
'o' => 'Home', // Object (content)
31+
'l' => '', // Log (alert message)
32+
'm' => 'list', // Method (or action)
33+
'o' => 'Home', // Object (or plugin)
3434
'r' => 'local', // Remotes (local)
3535
't' => 'TopNav', // Theme (Default)
3636
'x' => '', // XHR (request)
@@ -47,9 +47,6 @@
4747
'main' => 'Error: missing page!',
4848
'foot' => 'Copyright (C) 2015-2025 Mark Constable (AGPL-3.0)',
4949
'js' => '',
50-
'json' => '',
51-
'modal' => '',
52-
'end' => '',
5350
];
5451

5552
public $t;

src/Init.php

+3-41
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public function __construct(public object $g)
7373
{
7474
foreach ($g->out as $k => $v)
7575
{
76+
//elog("$k => $v");
7677
$g->out[$k] = match (true)
7778
{
7879
method_exists($thm, $k) => $thm->{$k}(),
@@ -82,52 +83,13 @@ public function __construct(public object $g)
8283
};
8384
}
8485
}
85-
/*
86-
if (empty($g->in['x']))
87-
{
88-
foreach ($g->out as $k => $v)
89-
{
90-
elog("$k => $v");
91-
// Skip modal method as it requires parameters
92-
if ($k === 'modal')
93-
{
94-
continue;
95-
}
96-
// Simple method resolution order:
97-
// 1. Plugin View (if method exists)
98-
// 2. Current Theme (if method exists)
99-
// 3. Base Theme (if method exists)
100-
// 4. Default from index.php
101-
102-
// Try Plugin View first
103-
if (method_exists($thm, $k))
104-
{
105-
$g->out[$k] = $thm->{$k}();
106-
}
107-
// Then try current theme
108-
else if ($thm->theme && method_exists($thm->theme, $k))
109-
{
110-
$g->out[$k] = $thm->theme->{$k}();
111-
}
112-
// Finally try base Theme class
113-
else if (method_exists('HCP\\Theme', $k))
114-
{
115-
$g->out[$k] = (new Theme($g))->{$k}();
116-
}
117-
// Fall back to default
118-
else
119-
{
120-
$g->out[$k] = $v;
121-
}
122-
}
123-
}
124-
*/
12586
}
12687

12788
public function __toString(): string
12889
{
12990
elog(__METHOD__);
130-
91+
//dbg($this->t);
92+
elog(var_export($this->t, true));
13193
$x = $this->g->in['x'];
13294
$f = $this->g->in['f']; // Default 'html' is already set in $in array
13395

src/Plugins/Example/View.php

+56-66
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,23 @@
11
<?php
22

33
declare(strict_types=1);
4-
// src/Plugins/Example/View.php 20250201 - 20250201
4+
// Created: 20250201 - Update: 20250202
55
// Copyright (C) 2015-2025 Mark Constable <markc@renta.net> (AGPL-3.0)
66

77
namespace HCP\Plugins\Example;
88

9-
use HCP\Util;
10-
use HCP\Themes\TopNav;
9+
//use HCP\Theme;
1110

12-
class View
11+
class View //extends Theme
1312
{
14-
public $theme;
13+
public ?object $theme;
1514
public object $g;
1615

1716
public function __construct(object $g)
1817
{
1918
$this->g = $g;
2019
}
2120

22-
// The Final HTML Layout
23-
24-
public function html(): string
25-
{
26-
elog(__METHOD__);
27-
28-
extract($this->g->out, EXTR_SKIP);
29-
30-
return '<!DOCTYPE html>
31-
<html lang="en">
32-
<head>
33-
<meta charset="utf-8">
34-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
35-
<title>' . $doc . '</title>
36-
<style>' . $css . '</style>
37-
</head>
38-
<body>
39-
<nav>' . $nav1 . ' || ' . $nav2 . ' || ' . $nav3 . '</nav>
40-
<header>' . $head . '</header>
41-
<main>' . $main . '</main>
42-
<footer>' . $foot . '</footer>
43-
<pre>' . $end . '</pre>
44-
<script>' . $js . '</script>
45-
<div>' . $modal . '</div>
46-
<div>' . $json . '</div>
47-
</body>
48-
</html>
49-
';
50-
}
51-
5221
// Plugin Actions Views
5322

5423
public function create(array $in = []): string
@@ -87,7 +56,26 @@ public function list(array $in = []): string
8756
}
8857

8958
// HTML Partial Views
59+
/*
60+
public function html(): string
61+
{
62+
elog(__METHOD__);
63+
64+
extract($this->g->out, EXTR_SKIP);
9065
66+
return '<!DOCTYPE html>
67+
<html lang="en">
68+
<head>
69+
<meta charset="utf-8">
70+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
71+
<title>' . $doc . '</title>' . $css . '
72+
</head>
73+
<body>' . $log . $head . $main . $foot . $js . '
74+
</body>
75+
</html>
76+
';
77+
}
78+
*/
9179
public function doc(array $in = []): string
9280
{
9381
elog(__METHOD__);
@@ -100,16 +88,24 @@ public function css(array $in = []): string
10088
elog(__METHOD__);
10189

10290
return '
103-
body {text-align:center;width:60rem;margin-left:auto;margin-right:auto;}
104-
nav,header,main,footer,pre,div {border:dashed 1px red;margin:1rem;padding:1rem;}
105-
';
91+
<style>
92+
body {text-align:center; width:60rem; margin-left:auto; margin-right:auto;}
93+
nav,header,main,footer,pre,div {border:dashed 1px red; margin:1rem; padding:1rem;}
94+
@media screen and (max-width: 768px) {
95+
body {width: 100%; margin: 0;}
96+
nav, header, main, footer, pre, div {width: auto; margin: 1rem;}
97+
}
98+
</style>';
10699
}
107100

108101
public function log(array $in = []): string
109102
{
110103
elog(__METHOD__);
111104

112-
return __METHOD__;
105+
return '
106+
<div>
107+
' . __METHOD__ . ' (Alerts area)
108+
</div>';
113109
}
114110

115111
public function nav1(array $in = []): string
@@ -137,48 +133,42 @@ public function head(array $in = []): string
137133
{
138134
elog(__METHOD__);
139135

140-
return __METHOD__;
136+
return '
137+
<header>
138+
' . __METHOD__ . '
139+
<nav>
140+
' . $this->g->out['nav1'] . ' || ' . $this->g->out['nav2'] . ' || ' . $this->g->out['nav3'] . '
141+
</nav>
142+
</header>';
141143
}
142144

143145
public function main(array $in = []): string
144146
{
145147
elog(__METHOD__);
146148

147-
return __METHOD__;
148-
}
149-
/*
150-
public function foot(array $in = []): string
151-
{
152-
elog(__METHOD__);
153-
154-
return __METHOD__;
155-
}
156-
*/
157-
public function js(array $in = []): string
158-
{
159-
elog(__METHOD__);
160-
161-
return 'document.write("' . addslashes(__METHOD__) . '")';
162-
}
163-
164-
public function json(array $in = []): string
165-
{
166-
elog(__METHOD__);
167-
168-
return __METHOD__;
149+
return '
150+
<main>
151+
' . __METHOD__ . '
152+
</main>';
169153
}
170154

171-
public function modal(array $in = []): string
155+
public function foot(array $in = []): string
172156
{
173157
elog(__METHOD__);
174158

175-
return __METHOD__;
159+
return '
160+
<footer>
161+
' . __METHOD__ . '
162+
</footer>';
176163
}
177164

178-
public function end(array $in = []): string
165+
public function js(array $in = []): string
179166
{
180167
elog(__METHOD__);
181168

182-
return __METHOD__;
169+
return '
170+
<script>
171+
document.write("<div>' . addslashes(__METHOD__) . '</div>")
172+
</script>';
183173
}
184174
}

src/Theme.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

33
declare(strict_types=1);
4-
// Created: 20150101 - Updated: 20230604
5-
// Copyright (C) 2015-2023 Mark Constable <markc@renta.net> (AGPL-3.0)
4+
// Created: 20150101 - Updated: 20250202
5+
// Copyright (C) 2015-2025 Mark Constable <markc@renta.net> (AGPL-3.0)
66

77
namespace HCP;
88

@@ -43,6 +43,25 @@ public function __call(string $name, array $args): string
4343
return 'Theme::' . $name . '() not implemented';
4444
}
4545

46+
public function html(): string
47+
{
48+
elog(__METHOD__);
49+
50+
extract($this->g->out, EXTR_SKIP);
51+
52+
return '<!DOCTYPE html>
53+
<html lang="en">
54+
<head>
55+
<meta charset="utf-8">
56+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
57+
<title>' . $doc . '</title>' . $css . '
58+
</head>
59+
<body>' . $log . $nav1 . $head . $main . $foot . $js . '
60+
</body>
61+
</html>
62+
';
63+
}
64+
4665
public function log(): string
4766
{
4867
elog(__METHOD__);
@@ -184,25 +203,6 @@ public function modal(array $ary): string
184203
);
185204
}
186205

187-
public function html(): string
188-
{
189-
elog(__METHOD__);
190-
191-
extract($this->g->out, EXTR_SKIP);
192-
193-
return '<!DOCTYPE html>
194-
<html lang="en">
195-
<head>
196-
<meta charset="utf-8">
197-
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
198-
<title>' . $doc . '</title>' . $css . $js . '
199-
</head>
200-
<body>' . $head . $main . $foot . $end . '
201-
</body>
202-
</html>
203-
';
204-
}
205-
206206
public static function dropdown(
207207
array $ary,
208208
string $name,

src/Themes/TopNav.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ public function css(): string
2323
elog(__METHOD__);
2424

2525
return '
26-
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
27-
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
28-
<link href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css" rel="stylesheet">
29-
<link href="https://cdn.datatables.net/buttons/2.4.1/css/buttons.bootstrap5.min.css" rel="stylesheet">
30-
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css" rel="stylesheet">
31-
<style>
26+
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
27+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
28+
<link href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css" rel="stylesheet">
29+
<link href="https://cdn.datatables.net/buttons/2.4.1/css/buttons.bootstrap5.min.css" rel="stylesheet">
30+
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css" rel="stylesheet">
31+
<style>
3232
body{min-height:75rem;padding-top:5rem;}
3333
table,form{width:100%;}
3434
table.dataTable{border-collapse: collapse !important;}
@@ -91,7 +91,7 @@ public function css(): string
9191
align-items: flex-end;
9292
}
9393
}
94-
</style>';
94+
</style>';
9595
}
9696

9797
public function head(): string
@@ -224,11 +224,11 @@ public function js(): string
224224
elog(__METHOD__);
225225

226226
return '
227-
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
228-
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
229-
<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
230-
<script src="https://cdn.datatables.net/buttons/2.4.1/js/dataTables.buttons.min.js"></script>
231-
<script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.bootstrap5.min.js"></script>';
227+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
228+
<script src="https://cdn.datatables.net/1.13.6/js/jquery.dataTables.min.js"></script>
229+
<script src="https://cdn.datatables.net/1.13.6/js/dataTables.bootstrap5.min.js"></script>
230+
<script src="https://cdn.datatables.net/buttons/2.4.1/js/dataTables.buttons.min.js"></script>
231+
<script src="https://cdn.datatables.net/buttons/2.4.1/js/buttons.bootstrap5.min.js"></script>';
232232
}
233233

234234
public function modal(array $ary): string

0 commit comments

Comments
 (0)