aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/class/Controlleradmin.php45
-rw-r--r--app/class/Modeladmin.php48
-rw-r--r--app/class/Modelmassedit.php0
-rw-r--r--app/class/Routes.php3
-rw-r--r--app/fn/fn.php57
-rw-r--r--app/view/templates/admin.php145
-rw-r--r--app/view/templates/backtopbar.php9
7 files changed, 217 insertions, 90 deletions
diff --git a/app/class/Controlleradmin.php b/app/class/Controlleradmin.php
index b7d0e31..835f158 100644
--- a/app/class/Controlleradmin.php
+++ b/app/class/Controlleradmin.php
@@ -7,6 +7,15 @@ class Controlleradmin extends Controller
/** @var Modelmedia $mediamanager */
protected $mediamanager;
+ /** @var Modeladmin */
+ protected $adminmanager;
+
+ public function __construct($router)
+ {
+ parent::__construct($router);
+
+ $this->adminmanager = new Modeladmin();
+ }
public function desktop()
{
@@ -30,6 +39,9 @@ class Controlleradmin extends Controller
$datas['globalcss'] = "";
}
+ $datas['pagesdblist'] = $this->adminmanager->pagesdblist();
+ $datas['pagesdbtree'] = $this->mediamanager->listdir(Model::PAGES_DIR);
+
$this->showtemplate('admin', $datas);
} else {
$this->routedirect('home');
@@ -38,8 +50,8 @@ class Controlleradmin extends Controller
public function update()
{
- $this->globaldircheck();
-
+ MODEL::dircheck(MODEL::GLOBAL_DIR);
+
$globalcss = file_put_contents(Model::GLOBAL_DIR . 'global.css', $_POST['globalcss']);
Config::hydrate($_POST);
@@ -50,16 +62,25 @@ class Controlleradmin extends Controller
}
}
-
- public function globaldircheck()
- {
- if(!is_dir(Model::GLOBAL_DIR)) {
- return mkdir(Model::GLOBAL_DIR);
- } else {
- return true;
- }
- }
-
+ public function database()
+ {
+ if(!empty($_POST['action'])) {
+ switch ($_POST['action']) {
+ case 'duplicate':
+ if(!empty($_POST['dbsrc']) && !empty($_POST['dbtarget'])) {
+ $this->adminmanager->copydb($_POST['dbsrc'], $_POST['dbtarget']);
+ }
+ break;
+ case 'select':
+ if(!empty($_POST['pagetable'])) {
+ Config::hydrate($_POST);
+ Config::savejson();
+ }
+ break;
+ }
+ }
+ $this->routedirect('admin');
+ }
}
diff --git a/app/class/Modeladmin.php b/app/class/Modeladmin.php
new file mode 100644
index 0000000..54c4f0c
--- /dev/null
+++ b/app/class/Modeladmin.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Wcms;
+
+class Modeladmin extends Model
+{
+
+
+ /**
+ * List all availalble pages databases
+ *
+ * @return array
+ */
+ public function pagesdblist() : array
+ {
+ $dblist = glob(self::PAGES_DIR . '*', GLOB_ONLYDIR);
+ $dblist = array_map('basename', $dblist);
+
+ return $dblist;
+ }
+
+ /**
+ * Duplicate actual page database using new name
+ *
+ * @param string $name of the new database
+ */
+ public function duplicate(string $name)
+ {
+ $this->copydb(Config::pagetable(), $name);
+ }
+
+ /**
+ * Copy database folder to a new folder if it doeas not already exsit
+ *
+ * @param string $db name of source page database to copy
+ * @param string $name of the destination database
+ */
+ public function copydb(string $db, string $name)
+ {
+ $dbdir = self::PAGES_DIR . $db;
+ $newdbdir = self::PAGES_DIR . idclean($name);
+ if(is_dir($dbdir) && !is_dir($newdbdir)) {
+ recurse_copy($dbdir, $newdbdir);
+ }
+ }
+}
+
+?> \ No newline at end of file
diff --git a/app/class/Modelmassedit.php b/app/class/Modelmassedit.php
deleted file mode 100644
index e69de29..0000000
--- a/app/class/Modelmassedit.php
+++ /dev/null
diff --git a/app/class/Routes.php b/app/class/Routes.php
index c4571d9..277d478 100644
--- a/app/class/Routes.php
+++ b/app/class/Routes.php
@@ -36,8 +36,9 @@ class Routes
['GET', '/!font', 'Controllerfont#desktop', 'font'],
['GET', '/!font/render', 'Controllerfont#render', 'fontrender'],
['POST', '/!font/add', 'Controllerfont#add', 'fontadd'],
- ['POST', '/!admin', 'Controlleradmin#update', 'adminupdate'],
['GET', '/!admin', 'Controlleradmin#desktop', 'admin'],
+ ['POST', '/!admin', 'Controlleradmin#update', 'adminupdate'],
+ ['POST', '/!admin/database', 'Controlleradmin#database', 'admindatabase'],
['GET', '/!user', 'Controlleruser#desktop', 'user'],
['POST', '/!user/add', 'Controlleruser#add', 'useradd'],
['POST', '/!user/update', 'Controlleruser#update', 'userupdate'],
diff --git a/app/fn/fn.php b/app/fn/fn.php
index 61c2312..6dfeb2c 100644
--- a/app/fn/fn.php
+++ b/app/fn/fn.php
@@ -210,9 +210,9 @@ function array_diff_assoc_recursive($array1, $array2) {
/**
- * Generate a folder tree based on reccurive array
+ * Generate a clickable folder tree based on reccurive array
*/
-function treecount(array $dir, string $dirname, int $deepness, string $path, string $currentdir, Medialist $mediaopt)
+function treecount(array $dirlist, string $dirname, int $deepness, string $path, string $currentdir, Medialist $mediaopt)
{
if ($path . '/' === $currentdir) {
$folder = '├─📂<span id="currentdir">' . $dirname . '<span>';
@@ -221,15 +221,48 @@ function treecount(array $dir, string $dirname, int $deepness, string $path, str
}
echo '<tr>';
echo '<td><a href="' . $mediaopt->getpathadress($path) . '">' . str_repeat('&nbsp;&nbsp;', $deepness) . $folder . '</a></td>';
- echo '<td>' . $dir['dirfilecount'] . '</td>';
+ echo '<td>' . $dirlist['dirfilecount'] . '</td>';
echo '</tr>';
- foreach ($dir as $key => $value) {
+ foreach ($dirlist as $key => $value) {
if (is_array($value)) {
treecount($value, $key, $deepness + 1, $path . DIRECTORY_SEPARATOR . $key, $currentdir, $mediaopt);
}
}
}
+
+/**
+ * Generate a clickable folder tree based on reccurive array
+ */
+function basictree(array $dirlist, string $dirname, int $deepness, string $path, string $currentdir)
+{
+
+ if ($path === $currentdir) {
+ $folder = '├─📂<span id="currentdir">' . $dirname . '<span>';
+ $checked = 'checked';
+ } else {
+ $folder = '├─📁' . $dirname;
+ $checked = '';
+ }
+
+ if($deepness === 1) {
+ $radio = '<input type="radio" name="pagetable" value="' . $dirname . '" id="db_' . $path . '" ' . $checked . '>';
+ } else {
+ $radio = '';
+ }
+
+ echo '<tr>';
+ echo '<td>' . $radio . '</td>';
+ echo '<td><label for="db_' . $path . '">' . str_repeat('&nbsp;&nbsp;', $deepness) . $folder . '</label></td>';
+ echo '<td>' . $dirlist['dirfilecount'] . '</td>';
+ echo '</tr>';
+ foreach ($dirlist as $key => $value) {
+ if (is_array($value)) {
+ basictree($value, $key, $deepness + 1, $path . DIRECTORY_SEPARATOR . $key, $currentdir);
+ }
+ }
+}
+
function checkboxes(string $name, array $optionlist = [], array $checkedlist = [])
{
$checkboxes = '';
@@ -245,6 +278,22 @@ function checkboxes(string $name, array $optionlist = [], array $checkedlist = [
}
+function recurse_copy($src,$dst) {
+ $dir = opendir($src);
+ mkdir($dst);
+ while(false !== ( $file = readdir($dir)) ) {
+ if (( $file != '.' ) && ( $file != '..' )) {
+ if ( is_dir($src . '/' . $file) ) {
+ recurse_copy($src . '/' . $file,$dst . '/' . $file);
+ }
+ else {
+ copy($src . '/' . $file,$dst . '/' . $file);
+ }
+ }
+ }
+ closedir($dir);
+}
+
diff --git a/app/view/templates/admin.php b/app/view/templates/admin.php
index 57abfcc..0c9f5af 100644
--- a/app/view/templates/admin.php
+++ b/app/view/templates/admin.php
@@ -10,37 +10,37 @@
<main class="admin">
- <nav class="admin">
-
- <div class="block">
- <h1>Administration</h1>
-
- <div class="scroll">
- <ul>
- <li><a href="#home-page">Home page</a></li>
- <li><a href="#page-creation">Page creation</a></li>
- <li><a href="#alert-pages">Alert Pages</a></li>
- <li><a href="#render">Render</a></li>
- <li><a href="#css">CSS</a></li>
- <li><a href="#databases">Databases</a></li>
- <li><a href="#interface">Interface</a></li>
- <li><a href="#tracking">Tracking</a></li>
- </ul>
-
- <form action="<?= $this->url('adminupdate') ?>" method="post" id="admin">
- <input type="submit" value="Update configuration">
- </form>
+ <nav class="admin">
+
+ <div class="block">
+ <h1>Administration</h1>
+
+ <div class="scroll">
+ <ul>
+ <li><a href="#home-page">Home page</a></li>
+ <li><a href="#page-creation">Page creation</a></li>
+ <li><a href="#alert-pages">Alert Pages</a></li>
+ <li><a href="#render">Render</a></li>
+ <li><a href="#css">CSS</a></li>
+ <li><a href="#interface">Interface</a></li>
+ <li><a href="#tracking">Tracking</a></li>
+ </ul>
+
+ <form action="<?= $this->url('adminupdate') ?>" method="post" id="admin">
+ <input type="submit" value="Update configuration">
+ </form>
+ </div>
</div>
- </div>
- </nav>
+ </nav>
<section class="admin">
<div class="block">
-
+ <h1>configuration</h1>
+
<div class="scroll">
-
+
<h2 id="home-page">Home page</h2>
@@ -52,11 +52,6 @@
</div>
<div class="radio">
- <input type="radio" name="homepage" value="search" id="searchbar" <?= Wcms\Config::homepage() === 'search' ? 'checked' : '' ?> form="admin">
- <label for="searchbar">search bar</label>
- </div>
-
- <div class="radio">
<input type="radio" name="homepage" value="redirect" id="redirect" <?= Wcms\Config::homepage() === 'redirect' ? 'checked' : '' ?> form="admin">
<label for="redirect">redirect to page</label>
</div>
@@ -66,7 +61,7 @@
<?php
foreach ($pagelist as $page) {
- ?>
+ ?>
<option value="<?= $page ?>" <?= Wcms\Config::homeredirect() === $page ? 'selected' : '' ?>><?= $page ?></option>
<?php
}
@@ -96,7 +91,7 @@
<option value="" <?= Wcms\Config::defaultpage() === '' || !$defaultpageexist ? 'selected' : '' ?>>--use default BODY element--</option>
<?php
foreach ($pagelist as $page) {
- ?>
+ ?>
<option value="<?= $page ?>" <?= Wcms\Config::defaultpage() === $page ? 'selected' : '' ?>><?= $page ?></option>
<?php }
?>
@@ -104,7 +99,7 @@
<?php
if (empty(!$defaultpageexist || Wcms\Config::defaultpage())) {
- ?>
+ ?>
<label for="defaultbody">Edit default BODY element</label>
<textarea name="defaultbody" id="defaultbody" cols="30" rows="10" form="admin"><?= Wcms\Config::defaultbody() ?></textarea>
<?php
@@ -114,6 +109,8 @@
<h2 id="alert-pages">Alert pages</h2>
+ <p>Set the style and text to show when a page does not exist, or when a visitor don't have access to it.</p>
+
<h4>Common options</h4>
<label for="alerttitle">H1 Title</label>
@@ -125,7 +122,7 @@
<option value="" <?= empty(Wcms\Config::alertlink()) ? 'selected' : '' ?>>--No link--</option>
<?php
foreach ($pagelist as $page) {
- ?>
+ ?>
<option value="<?= $page ?>" <?= Wcms\Config::alertlink() === $page ? 'selected' : '' ?>><?= $page ?></option>
<?php }
?>
@@ -183,7 +180,7 @@
<i>You can use <code>body.alert</code> class to specify style.</i>
</p>
-
+
<h2 id="render">Render</h2>
@@ -222,7 +219,7 @@
<option value="">--no favicon--</option>
<?php
foreach ($faviconlist as $favicon) {
- ?>
+ ?>
<option value="<?= $favicon ?>" <?= Wcms\Config::defaultfavicon() === $favicon ? 'selected' : '' ?>><?= $favicon ?></option>
<?php
}
@@ -234,37 +231,11 @@
<option value="">--no thumbnail--</option>
<?php
foreach ($thumbnaillist as $thumbnail) {
- ?>
- <option value="<?= $thumbnail ?>" <?= Wcms\Config::defaultthumbnail() === $thumbnail ? 'selected' : '' ?>><?= $thumbnail ?></option>
- <?php
- }
?>
+ <option value="<?= $thumbnail ?>" <?= Wcms\Config::defaultthumbnail() === $thumbnail ? 'selected' : '' ?>><?= $thumbnail ?></option>
+ <?php } ?>
</select>
-
-
- <h2 id="databases">Databases</h2>
-
- <p>Manage databases</p>
-
- <p>
- <label for="database">Select database to use</label>
-
- <select name="database" id="database">
- <option value="01"><?= Wcms\Config::pagetable() ?></option>
- </select>
- </p>
-
- <p>
- <form action="" method="post">
- <label for="name">new name</label>
- <input type="text" name="name" id="name" value="<?= Wcms\Config::pagetable() ?>_1">
- <input type="submit" value="duplicate">
- </form>
- </p>
-
-
-
<h2 id="interface">Interface</h2>
<p>Set interface Style</p>
@@ -273,7 +244,7 @@
<option value="null">--default interface style---</option>
<?php
foreach ($interfacecsslist as $interfacecss) {
- ?>
+ ?>
<option value="<?= $interfacecss ?>" <?= $interfacecss === Wcms\Config::interfacecss() ? 'selected' : '' ?>><?= $interfacecss ?></option>
<?php
}
@@ -291,12 +262,56 @@
</div>
-
+
</div>
</section>
+ <section id="databases">
+ <div class="block">
+ <h1>Databases</h1>
+ <div class="scroll">
+
+ <form action="<?= $this->url('admindatabase') ?>" method="post">
+
+
+ <table id="dirlsit">
+ <tr><th>using</th><th>databases</th><th>pages</th></tr>
+
+ <?php basictree($pagesdbtree, 'pages', 0, '', DIRECTORY_SEPARATOR . Wcms\Config::pagetable()); ?>
+ </table>
+
+ <input type="hidden" name="action" value="select">
+ <input type="submit" value="select" name="change database">
+
+ </form>
+
+ <h4>Duplicate Database</h4>
+
+ <form action="<?= $this->url('admindatabase') ?>" method="post">
+
+ <label for="dbsrc">Database to duplicate</label>
+ <select name="dbsrc" id="dbsrc">
+ <?php
+ foreach ($pagesdblist as $db) {
+ ?>
+ <option value="<?= $db ?>" <?= $db === Wcms\Config::pagetable() ? 'selected' : '' ?>><?= $db ?></option>
+ <?php
+ }
+ ?>
+ </select>
+
+ <label for="duplicate">New name</label>
+ <input type="text" name="dbtarget" id="duplicate" value="" required>
+ <input type="submit" name="action" value="duplicate">
+ </form>
+
+
+ </div>
+ </div>
+ </section>
+
</main>
</body>
diff --git a/app/view/templates/backtopbar.php b/app/view/templates/backtopbar.php
index c632d66..c1dd361 100644
--- a/app/view/templates/backtopbar.php
+++ b/app/view/templates/backtopbar.php
@@ -30,10 +30,6 @@
<img src="<?= Wcms\Model::iconpath() ?>media.png" alt="" class="icon">
<span class="hidephone">media</span>
</a>
-<a href="<?= $this->url('font') ?>" <?= $tab == 'font' ? 'class="actualpage"' : '' ?>>
- <img src="<?= Wcms\Model::iconpath() ?>font.png" alt="" class="icon">
- <span class="hidephone">font</span>
-</a>
<?php
if($user->isadmin()) {
?>
@@ -74,10 +70,7 @@ if($user->isadmin()) {
<?php } else { ?>
<span>
-<a href="<?= $this->url('timeline') ?>" <?= $tab == 'timeline' ? 'class="actualpage"' : '' ?>>
- <img src="<?= Wcms\Model::iconpath() ?>timeline.png" alt="" class="icon">
- <span class="hidephone">timeline</span>
-</a>
+
<a href="<?= $this->url('user') ?>" <?= $tab == 'user' ? 'class="actualpage"' : '' ?>>
<img src="<?= Wcms\Model::iconpath() ?>user.png" alt="" class="icon">
<span class="hidephone"><?= $user->id() ?></span>