pupupu

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

commit
fcfba3e5ffb08327489940771d24a3dfcd246c25
parent
bc8cae183b91f21a29b7d555e822711793da82e3
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2018-10-20 20:39
add pages view

Diffstat

M index.php 25 +++++++++++++++++++++----
A templates/pages.html 23 +++++++++++++++++++++++

2 files changed, 44 insertions, 4 deletions


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

@@ -176,6 +176,18 @@ class Pupupu
  176   176         return $subpages;
  177   177     }
  178   178 
   -1   179     public function getPages($path = '')
   -1   180     {
   -1   181         $result = array();
   -1   182         $result[] = $path;
   -1   183         foreach ($this->getSubpages($path) as $name => $p) {
   -1   184             foreach ($this->getPages($p) as $pp) {
   -1   185                 $result[] = $pp;
   -1   186             }
   -1   187         }
   -1   188         return $result;
   -1   189     }
   -1   190 
  179   191     public function getUrl($path)
  180   192     {
  181   193         return $this->targetUrl . $path . '/';
@@ -279,6 +291,13 @@ function ensureTrailingSlash()
  279   291     }
  280   292 }
  281   293 
   -1   294 function pagesView($pupupu, $twig)
   -1   295 {
   -1   296     echo $twig->render('pages.html', array(
   -1   297         'pages' => $pupupu->getPages(),
   -1   298     ));
   -1   299 }
   -1   300 
  282   301 function uploadView($pupupu, $twig)
  283   302 {
  284   303     $path = validatePath(substr($_GET['path'], 8));
@@ -318,8 +337,6 @@ function pageView($pupupu, $twig)
  318   337 {
  319   338     if (isset($_GET['add'])) {
  320   339         header("Location: ?path=${_GET['path']}/${_GET['add']}", true, 302);
  321    -1     } elseif ($_GET['path'] === '/_site') {
  322    -1         header('Location: ?path=_site', true, 302);
  323   340     } else {
  324   341         $path = validatePath($_GET['path']);
  325   342 
@@ -336,7 +353,7 @@ function pageView($pupupu, $twig)
  336   353             }
  337   354             $pupupu->rm($path);
  338   355             $target = pathDirname($path);
  339    -1             header("Location: ?path=$target", true, 302);
   -1   356             header("Location: ?", true, 302);
  340   357         } else {
  341   358             $pupupu->put($path, 'yml', $_POST['yml']);
  342   359             $pupupu->put($path, 'md', $_POST['md']);
@@ -357,7 +374,7 @@ if (isset($_SERVER['REQUEST_METHOD'])) {
  357   374     $twig->addFilter(new Twig_Filter('trans', 'trans'));
  358   375 
  359   376     if (empty($_GET['path']) && $_GET['path'] !== '') {
  360    -1         header('Location: ?path=', true, 302);
   -1   377         pagesView($pupupu, $twig);
  361   378     } elseif ($_GET['path'] === '_site') {
  362   379         siteView($pupupu, $twig);
  363   380     } elseif (substr($_GET['path'], 0, 8) === '_uploads') {

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

@@ -0,0 +1,23 @@
   -1     1 {% extends 'base.html' %}
   -1     2 
   -1     3 {% block main %}
   -1     4     <ul class="file-list">
   -1     5         {% for path in pages %}
   -1     6             <li><a href="?path={{ path }}" class="file-list__main">
   -1     7                 {{ path }}{% if '.' not in path %}/{% endif %}
   -1     8             </a></li>
   -1     9         {% endfor %}
   -1    10     </ul>
   -1    11 
   -1    12     <form class="form--line">
   -1    13         <select name="path">
   -1    14             {% for path in pages %}
   -1    15                 {% if '.' not in path %}
   -1    16                     <option value="{{ path }}">{{ path }}/</option>
   -1    17                 {% endif %}
   -1    18             {% endfor %}
   -1    19         </select>
   -1    20         <input name="add">
   -1    21         <button>{{ 'Add page'|trans }}</button>
   -1    22     </form>
   -1    23 {% endblock %}