pupupu

simple static CMS for crappy servers
git clone https://git.ce9e.org/pupupu.git

commit
70145ca1f95bd0cce6376831dd3cd04b51d02557
parent
e1b9fdadb13308ff2020ca09deea42d945b87a36
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2018-10-14 10:44
friendlier interface for getSubpages and getUploads

Diffstat

M index.php 26 +++++++++++++++++---------
M templates/page.html 2 +-
M templates/uploads.html 6 +++---

3 files changed, 21 insertions, 13 deletions


diff --git a/index.php b/index.php

@@ -120,10 +120,14 @@ class Pupupu
  120   120 
  121   121     public function getSubpages($path)
  122   122     {
   -1   123         $subpages = array();
  123   124         $p = $this->srcDir . '/_content' . $path;
  124    -1         return array_filter(scandir($p), function ($file) use ($p) {
  125    -1             return $file !== '.' && $file !== '..' && is_dir("$p/$file");
  126    -1         });
   -1   125         foreach (scandir($p) as $name) {
   -1   126             if ($name !== '.' && $name !== '..' && is_dir("$p/$name")) {
   -1   127                 $subpages[$name] = "$path/$name";
   -1   128             }
   -1   129         }
   -1   130         return $subpages;
  127   131     }
  128   132 
  129   133     public function upload($file)
@@ -135,10 +139,14 @@ class Pupupu
  135   139 
  136   140     public function getUploads()
  137   141     {
   -1   142         $uploads = array();
  138   143         $p = $this->targetDir . '/uploads';
  139    -1         return array_filter(scandir($p), function ($file) use ($p) {
  140    -1             return is_file("$p/$file");
  141    -1         });
   -1   144         foreach (scandir($p) as $name) {
   -1   145             if (is_file("$p/$name")) {
   -1   146                 $uploads[$name] = "/uploads/$name";
   -1   147             }
   -1   148         }
   -1   149         return $uploads;
  142   150     }
  143   151 
  144   152     public function rmUpload($name)
@@ -170,8 +178,8 @@ class Pupupu
  170   178     public function renderAll($verbose=false, $path='')
  171   179     {
  172   180         $this->render($path, $verbose);
  173    -1         foreach ($this->getSubpages($path) as $page) {
  174    -1             $this->renderAll($verbose, "$path/$page");
   -1   181         foreach ($this->getSubpages($path) as $name => $p) {
   -1   182             $this->renderAll($verbose, $p);
  175   183         }
  176   184     }
  177   185 }
@@ -186,7 +194,7 @@ function uploadView($pupupu, $twig)
  186   194         $pupupu->upload($_FILES['file']);
  187   195         header("Location: ", true, 302);
  188   196     } else {
  189    -1         $pupupu->rmUpload($_POST['file']);
   -1   197         $pupupu->rmUpload($_POST['name']);
  190   198         header("Location: ", true, 302);
  191   199     }
  192   200 }

diff --git a/templates/page.html b/templates/page.html

@@ -9,7 +9,7 @@
    9     9         <input type="hidden" name="path" value="{{ path }}">
   10    10         <input type="text" name="add" list="subpages" autocomplete="off">
   11    11         <datalist id="subpages">
   12    -1             {% for name in subpages %}
   -1    12             {% for name, path in subpages %}
   13    13                 <option value="{{ name }}">
   14    14             {% endfor %}
   15    15         </datalist>

diff --git a/templates/uploads.html b/templates/uploads.html

@@ -2,11 +2,11 @@
    2     2 
    3     3 {% block main %}
    4     4     <ul>
    5    -1         {% for file in files %}
   -1     5         {% for name, url in files %}
    6     6             <li>
    7    -1                 <a href="/uploads/{{ file }}" target="_blank">{{ file }}</a>
   -1     7                 <a href="{{ url }}" target="_blank">{{ name }}</a>
    8     8                 <form method="post">
    9    -1                     <input type="hidden" name="file" value="{{ file }}">
   -1     9                     <input type="hidden" name="name" value="{{ name }}">
   10    10                     <button class="button--danger">Delete</button>
   11    11                 </form>
   12    12             </li>