aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-01-21 01:28:04 +0100
committervincent-peugnet <v.peugnet@free.fr>2020-01-21 01:28:04 +0100
commitc47b78e13afb092aa1a30296b885b2911444fe3c (patch)
treeb387ea24ebced532a69937d3156a695781b9dd81 /app
parent61d7c9de6b7d50eb151e513e3be1e1805b4690d3 (diff)
downloadwcms-c47b78e13afb092aa1a30296b885b2911444fe3c.tar.gz
wcms-c47b78e13afb092aa1a30296b885b2911444fe3c.zip
new user manual in markdown
Diffstat (limited to 'app')
-rw-r--r--app/class/Controllerinfo.php16
-rw-r--r--app/class/Model.php3
-rw-r--r--app/class/Modelrender.php46
-rw-r--r--app/view/templates/info.php48
-rw-r--r--app/view/templates/man.php320
5 files changed, 74 insertions, 359 deletions
diff --git a/app/class/Controllerinfo.php b/app/class/Controllerinfo.php
index af81caf..856d065 100644
--- a/app/class/Controllerinfo.php
+++ b/app/class/Controllerinfo.php
@@ -1,6 +1,7 @@
<?php
namespace Wcms;
+use Michelf\MarkdownExtra;
class Controllerinfo extends Controller
{
@@ -12,7 +13,20 @@ class Controllerinfo extends Controller
public function desktop()
{
if($this->user->iseditor()) {
- $this->showtemplate('info', ['version' => getversion()]);
+
+ if(file_exists(Model::MAN_FILE)) {
+
+ $render = new Modelrender($this->router);
+ $htmlman = file_get_contents(Model::MAN_FILE);
+ $htmlman = $render->rendermanual($htmlman);
+
+ $summary = $render->sumparser($htmlman, 3);
+
+
+ $this->showtemplate('info', ['version' => getversion(), 'manual' => $htmlman, 'summary' => $summary]);
+
+ }
+
}
}
diff --git a/app/class/Model.php b/app/class/Model.php
index bb07fea..913dc34 100644
--- a/app/class/Model.php
+++ b/app/class/Model.php
@@ -5,7 +5,8 @@ namespace Wcms;
abstract class Model
{
- const CONFIG_FILE = 'config.json';
+ const CONFIG_FILE = 'config.json';
+ const MAN_FILE = 'MANUAL.md';
const CSS_DIR = 'assets' . DIRECTORY_SEPARATOR .'css' . DIRECTORY_SEPARATOR;
const JS_DIR = 'assets' . DIRECTORY_SEPARATOR .'js' . DIRECTORY_SEPARATOR;
const ICONS_DIR = 'assets' . DIRECTORY_SEPARATOR .'icons' . DIRECTORY_SEPARATOR;
diff --git a/app/class/Modelrender.php b/app/class/Modelrender.php
index 593a420..fe491f1 100644
--- a/app/class/Modelrender.php
+++ b/app/class/Modelrender.php
@@ -36,6 +36,21 @@ class Modelrender extends Modelpage
}
}
+ /**
+ * Used to convert the markdown user manual to html document
+ *
+ * @param string $text Input text in markdown
+ * @return string html formated text
+ */
+ public function rendermanual(string $text) : string
+ {
+ $text = $this->markdown($text);
+ $text = $this->headerid($text, 3);
+ return $text;
+
+ }
+
+
public function upage($id)
{
return $this->router->generate('pageread/', ['page' => $id]);
@@ -384,11 +399,25 @@ class Modelrender extends Modelpage
return $text;
}
- public function headerid($text)
+ /**
+ * Add Id to hrml header elements and store the titles in the `sum` parameter
+ *
+ * @param string $text Input html document to scan
+ * @param int $maxdeepness Maximum header deepness to look for. Min = 1 Max = 6 Default = 6
+ *
+ * @return string text with id in header
+ */
+
+ public function headerid($text, int $maxdeepness = 6)
{
+ if($maxdeepness > 6 || $maxdeepness < 1) {
+ $maxdeepness = 6;
+ }
+
+
$sum = [];
$text = preg_replace_callback(
- '/<h([1-6])(\s+(\s*\w+="\w+")*)?\s*>(.+)<\/h[1-6]>/mU',
+ '/<h([1-' . $maxdeepness . '])(\s+(\s*\w+="\w+")*)?\s*>(.+)<\/h[1-' . $maxdeepness . ']>/mU',
function ($matches) use (&$sum) {
$cleanid = idclean($matches[4]);
$sum[$cleanid][$matches[1]] = $matches[4];
@@ -453,16 +482,15 @@ class Modelrender extends Modelpage
return $text;
}
-
- function sumparser($text)
+ /**
+ * Generate a Summary based on header ids. Need to use `$this->headerid` before to scan text
+ *
+ * @return string html list with anchor link
+ */
+ function sumparser() : string
{
- preg_match_all('#<h([1-6]) id="(\w+)">(.+)</h[1-6]>#iU', $text, $out);
-
-
$sum = $this->sum;
-
-
$sumstring = '';
$last = 0;
foreach ($sum as $title => $list) {
diff --git a/app/view/templates/info.php b/app/view/templates/info.php
index 8f6377b..bcfc2c8 100644
--- a/app/view/templates/info.php
+++ b/app/view/templates/info.php
@@ -12,25 +12,24 @@
<nav>
<div class="block">
- <h2>Manual Summary</h2>
- <div class="scroll">
+
+ <h2>Version</h2>
+
+ <?= $version ?>
+
+
+
+ <h2>Links</h2>
+
<ul>
- <li><a href="#startup">Startup</a></li>
- <ul>
-
- </ul>
- <li><a href="#structure">Structure</a></li>
- <ul>
- <li><a href="#attributes">Page attributes</a></li>
- <li><a href="#database">Database</a></li>
- </ul>
- <li><a href="#editor">Editor</a></li>
- <ul>
- <li><a href="#elementsyntax">Elements syntax</a></li>
- <li><a href="#bodysyntax">Body syntax</a></li>
- </ul>
+ <li><a href="https://github.com/vincent-peugnet/wcms" target="_blank">🐱‍👤 Github</a></li>
+ <li><a href="https://w-cms.top" target="_blank">🌵 Website</a></li>
</ul>
+ <h2>Manual Summary</h2>
+
+ <?= $summary ?>
+
</div>
</div>
</nav>
@@ -38,22 +37,12 @@
<section class="info">
<div class="block">
+ <h1>Info</h1>
<div class="scroll">
<article>
- <h1>Info</h1>
-
- <h2>Version</h2>
-
- <?= $version ?>
- <h2>Links</h2>
- <ul>
- <li><a href="https://github.com/vincent-peugnet/wcms" target="_blank">🐱‍👤 Github</a></li>
- <li><a href="#manual">📕 Manual</a></li>
- <li><a href="https://w-cms.top" target="_blank">🌵 Website</a></li>
- </ul>
<h2>About</h2>
@@ -72,7 +61,10 @@
</article>
- <?php $this->insert('man') ?>
+ <article id="manual">
+ <?= $manual ?>
+ </article>
+
</div>
</div>
diff --git a/app/view/templates/man.php b/app/view/templates/man.php
deleted file mode 100644
index deb81ee..0000000
--- a/app/view/templates/man.php
+++ /dev/null
@@ -1,320 +0,0 @@
-
-
-<nav>
-<h2>Manual Summary</h2>
-<ul>
- <li><a href="#startup">Startup</a></li>
- <ul>
-
- </ul>
- <li><a href="#structure">Structure</a></li>
- <ul>
- <li><a href="#attributes">Page attributes</a></li>
- <li><a href="#database">Database</a></li>
- </ul>
- <li><a href="#editor">Editor</a></li>
- <ul>
- <li><a href="#elementsyntax">Elements syntax</a></li>
- <li><a href="#bodysyntax">Body syntax</a></li>
- </ul>
-</ul>
-
-</nav>
-
-
-
-<article id="manual">
-
-<h2 id="manual">Manual</h2>
-
-<h3 id="startup">Startup</h3>
-
-<p>There is'nt a real start of anything when you're using W.</p>
-
-<p>Just type an adress in your web browser, after your W folder. You should see an empty page, not existing yet. You can login to create one at this adress. If you are already logged in, you can juste type <code><i>page_id</i>/add</code>, this will directly create a page at this adress.</p>
-
-<p>This <code><i>page_id</i></code> is the identifier of each page, you cant change it later, this is like a real solid adress, it cant move. It can only contain lowercase letters, numbers, hyphens or underscore charachters.</p>
-
-<p>No visitor can see the full list of pages you've created. The only way to see the whole map of your project, is to be conected at least as an editor, and go to the "homepage", the root adress where W is instaled.</p>
-
-<h3 id="structure">Structure</h3>
-
-<h4>Pages and IDs</h4>
-
-<p>The structure of website is very simple as there is no structure. It's you to link the pages together or not.</p>
-
-<p>A page is defined by a unique <code>id</code>. As it's created, you can access it typing <code>.../<i>your_page_id</i>/</code> or without slash <code>.../<i>your_page_id</i></code></p>
-
-<p>An ID can only contain lowercase letters, numbers, underscore and "-"</p>
-
-
-<h4 id="attributes">Page attributes</h4>
-
-<h5>Id</h5>
-
-<p>Unique identifier, this is the url that point to your page</p>
-
-<h5>title</h5>
-
-<p>Page title, can use more complex characters than the ID element. It's printed in the explorer tab name. It's the official name of your page.</p>
-
-<h5>Description</h5>
-
-<p>The description attribute is a short informations about your page. It's used to create tooltip, when the mouse hover internal links.</p>
-
-<h5>Tag(s)</h5>
-
-<p>tags are used to create selections of pages. tags are one word only, sepparated by commas and whitespace.</p>
-
-<h5>Privacy level</h5>
-
-<p>Set the level of privacy of your page.
-</br><strong>0</strong> -> public
-</br><strong>1</strong> -> private <i>reserved to private readers</i>
-</br><strong>2</strong> -> not published <i>Nobody but editors can see it.</i> </p>
-
-
-<h5>Date & time</h5>
-
-<p>You can manualy set a date and time for each pages.</p>
-
-<h4 id="database">Database</h4>
-
-<p>All this pages are stored in your database, as a file by page. You can access them in the <code>.../database/<i>name_of_your_store</i>/</code></p>
-
-
-
-
-
-
-
-
-
-
-
-<h3 id="editor">Editor</h3>
-
-<p>W use the fives basics html elements to store your content</p>
-
-<ul>
-<li>header</li>
-<li>nav</li>
-<li>aside</li>
-<li>main</li>
-<li>footer</li>
-</ul>
-
-<p>You can use any of them, only one or all at the same time, as you prefer.</p>
-
-<h4 id="elementsyntax">Element syntax</h4>
-
-<p>In any of the five html element you can use to store content, you can use the following syntax, that is specific to W, extending the Markdown syntax :</p>
-
-<h5>quick internal link</h5>
-
-<p>You can create internal link very quickly, only by using the id of your page. The link text will be remplaced by the title associated with this page.</p>
-
-<blockquote>
- [<i>page_id</i>]
-</blockquote>
-
-<p>This will output :</p>
-
-<blockquote>
-&lt;a href="<i>page->url</i>" class="internal" title="<i>page->description</i>"&gt;<i>page->title</i>&lt;/a&gt;
-</blockquote>
-
-<h5>Title shortcut</h5>
-
-<blockquote>
- %TITLE%
-</blockquote>
-
-<p>Will output the page <code>title</code> attribute. This can be usefull when templating, or including differents page element.</p>
-
-
-<h5>Description shortcut</h5>
-
-<blockquote>
- %DESCRIPTION%
-</blockquote>
-
-<p>As for the title, this will output the <code>description</code> attribute of the page</p>
-
-<h5>Date shortcut</h5>
-
-<blockquote>
- %DATE% %DATECREATION% %DATEMODIF%
-</blockquote>
-
-<p>There are tree dates attributes that can be printed. The <strong>date</strong> attribute, will return the date that can be manualy set in the editor. <strong>datecreation</strong> will return the date of the page creation. <strong>datemodif</strong> will output the last editing date.</p>
-
-
-<h5>Automatic summary</h5>
-
-<p>You can automatically generate summary, based on the page <code>&lt;h*&gt;</code> elements</p>
-
-<blockquote>
- %SUMMARY%
-</blockquote>
-
-<p>This will generate a classic <code>&lt;ul&gt;</code> html list.</p>
-
-<h5>Automatic list by tag</h5>
-
-<p>You can create a html list of links pointing to all the pages using this tag.</p>
-
-<blockquote>
- %TAG:<i>__tag__</i>%
-</blockquote>
-
-<p>Let's suppose we are in page3 and we have page2, page3, page5, using this tag, this will output :</p>
-
-<blockquote>
-&lt;ul id="<i>tag</i>"&gt;
-</br>
-&lt;li&gt;
-</br>
-&lt;a href="<i>2->url</i>" class="internal" title="<i>2->description</i>"&gt;<i>2->title</i>&lt;/a&gt;
-</br>
-&lt;/li&gt;
-</br>
-&lt;li&gt;
-</br>
-&lt;a href="<i>3->url</i>" class="internal actualpage" title="<i>3->description</i>"&gt;<i>3->title</i>&lt;/a&gt;
-</br>
-&lt;/li&gt;
-</br>
-&lt;li&gt;
-</br>
-&lt;a href="<i>5->url</i>" class="internal" title="<i>5->description</i>"&gt;<i>5->title</i>&lt;/a&gt;
-</br>
-&lt;/li&gt;
-</br>
-&lt;/ul&gt;
-</blockquote>
-
-<p>The list is ordered by the <code>date</code> attribute, that you can set manualy for each page. You may have noticed that the actual page (page 3), has been specified using <code>.actualpage</code> class. This can be usefull to create a menu and highlight the current page.</p>
-
-
-<h5>Article separator</h5>
-
-<p>You can use the <code>article</code> html element, by separating text using at least <code>====</code>. It is of course possible to use Markdown synthax inside those articles separators</p>
-
-<blockquote>
-====</br></br>
-<i>some text</i></br></br>
-======<i>important</i></br></br>
-<i>this is a longer text</i></br></br>
-======</br></br>
-</blockquote>
-
-<p>This will ouptut :</p>
-
-<blockquote>
-&lt;article&gt;</br>
-<i>some text</i></br>
-&lt;/article&gt;</br>
-&lt;article id="<i>important</i>"&gt;</br>
-<i>this is a longer textt</i></br>
-&lt;/article&gt;</br>
-</blockquote>
-
-
-<p>As you may have noticed, there is also the possibility to add a custom <code>id</code> to any of the articles created that way</p>
-
-
-<h5>Media list</h5>
-
-<p>As it is too long adding all media of a folder one by one, you can just print the content of an entire folder using this method.</p>
-
-<blockquote>
-%MEDIA:<i>__directory__</i>
-</blockquote>
-
-<p>Just point to the good directory inside the media folder. This will output html list, creating image elements, audio players, video players, or just basic link, depending on the media type.</p>
-
-
-
-
-
-
-<h4 id="bodysyntax">Body syntax</h4>
-
-
-
-
-<h5>Basic including</h5>
-
-<blockquote>%HTML_ELEMENT%</blockquote>
-
-
-<p>This will include the matching html element from your page's content in your page body. If there is nothing in the corresponding element, it won't print anything. The name of the html element as to be UPPERCASE.</p>
-
-<p>For example :</p>
-
-<blockquote>
-%ASIDE%
-</br>
-</br>
-%MAIN%
-</blockquote>
-
-<p>Will output :</p>
-
-<blockquote>
-&lt;aside class="<i>page_id</i>"&gt;
-</br>
-__the content of your aside__
-</br>
-
-&lt;/aside&gt;
-</br>
-</br>
-&lt;main class="<i>page_id</i>"&gt;
-</br>
-__the content of your main__
-</br>
-
-&lt;/main&gt;
-
-
-</blockquote>
-
-<p>You can also use one element multiple times.</p>
-
-<h5>Advanced includings</h5>
-
-<blockquote>
- %<i>HTML_ELEMENT</i>:<i>page_id</i>%
-</blockquote>
-
-<p>By doing this, you can include the <code>HTML_ELEMENT</code> of the page using this <code>page_id</code> id. You can even nest differents pages source by adding <code>page_id</code> separated by a dot, this would be like :</p>
-
-<blockquote>
- %<i>HTML_ELEMENT</i>:<i>page1_id</i>+<i>page2_id</i>%
-</blockquote>
-
-<p>And you can mix it with the original page content using <code>!</code> identifier</p>
-
-<blockquote>
- %<i>HTML_ELEMENT</i>:<i>page3_id</i>+<i>!</i>%
-</blockquote>
-
-<p>This will output :</p>
-
-<blockquote>
-
-&lt;html_element class="<i>page3_id page_id</i>"&gt;
-</br>
-__content of page1's html element__
-</br>
-__content of this page html element__
-</br>
-&lt;/html_element&gt;
-
-
-
-</blockquote>
-
-</article>