Skip to content

Commit

Permalink
Merge branch 'pagev2' 🎉 close #336
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-peugnet committed Nov 12, 2023
2 parents 6ac0b4e + f368d68 commit 8135c1c
Show file tree
Hide file tree
Showing 50 changed files with 1,804 additions and 427 deletions.
65 changes: 53 additions & 12 deletions MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ This panel is also usefull to set up a [page list](#page-list) to include the sa

The Deep Search bar help you to look for words or regular expressions in your pages.

By default, searching only look in [title](#page-title), [description](#description) and [contents (markdown elements)](#markdown-elements), but the "other" checkbox will allow you to look up in [css](#css), [javascript](#javascript) and [BODY](#body) contents.
By default, searching only look in [title](#page-title), [description](#description) and [contents (markdown elements)](#content-elements), but the "other" checkbox will allow you to look up in [css](#css), [javascript](#javascript) and [BODY](#body) contents.

Unlike the [filterings options](#options) below, searches can't be saved or used for [page lists](#page-list).

Expand Down Expand Up @@ -513,7 +513,7 @@ Where `<min>` and `<max>` are integers beetwen `1` to `6`.

You can set `<min>` and `<max>` values to filters beetwen `<h*>` and `<h*>` headlines to take care of.

You can specify an [element](#markdown-elements) to target with the `element` parameter. The summary will only refer to this `element` headlines.
You can specify an [element](#content-elements) to target with the `element` parameter. The summary will only refer to this `element` headlines.



Expand All @@ -534,7 +534,7 @@ It use the same logic as the page filters in the [home view](#home).

*For example, this will print all public pages sorted by creation date in descending order.*

When you are in the [home view](#home), ajust the filters using the [options panel](#options) to achieve the page selection you desire. Then select "filters" in the [menu](#home-menu), choose options you prefer and hit "generate". You can now copy and paste the code obtainded that way in one of the [elements](#markdown-elements) of a page.
When you are in the [home view](#home), ajust the filters using the [options panel](#options) to achieve the page selection you desire. Then select "filters" in the [menu](#home-menu), choose options you prefer and hit "generate". You can now copy and paste the code obtainded that way in one of the [elements](#content-elements) of a page.

Display options are :

Expand Down Expand Up @@ -594,7 +594,7 @@ This will include a `div` HTML tag and some javascript.

<div id="geomap" class="map"></div>

When you are in the [home view](#home), ajust the filters using the [options panel](#options) to achieve the page selection you desire. Then select "filters" in the [menu](#home-menu), under the "map" title, you can now copy and paste the code obtainded that way in one of the [elements](#markdown-elements) of a page.
When you are in the [home view](#home), ajust the filters using the [options panel](#options) to achieve the page selection you desire. Then select "filters" in the [menu](#home-menu), under the "map" title, you can now copy and paste the code obtainded that way in one of the [elements](#content-elements) of a page.

**⚠️ this feature is limited to one map per page**

Expand Down Expand Up @@ -675,40 +675,54 @@ The most common usage is tu use it as a link `href`. For example, with a publish

The BODY tab allow you to create more complex canvas for your pages.

It use only HTML.
It cannot interpret Markdown language, you have to use HTML. But still you can use all the W [inclusions codes](#inclusions).

Depending on whitch page version you use, BODY synthax may be slightly different.

#### Element inclusion

The main purpose of BODY, is to display [Markdown elements](#markdown-elements) of your page.
The main purpose of BODY, is to display [contents](#content-elements) of your page.

%<element>%

Where `<element>` can be `MAIN`, `HEADER`, `ASIDE`, `NAV` or `FOOTER`. This will invoke the selected element into your page's BODY.
**In pages V1** `<element>` can be `MAIN`, `HEADER`, `ASIDE`, `NAV` or `FOOTER`. This will invoke the selected element into your page's BODY.

**In page V2** `<element>` can only be `CONTENT`

#### External Element inclusion

##### Simple usage

%<element>?id=<page_id>%

Just specify the [ID](#page-id) of the page [elements](#markdown-elements) you want to include.
Just specify the [ID](#page-id) of the page [elements](#content-elements) you want to include.


##### concatenate elements

You can even concatenate differents pages [elements](#markdown-elements), using `+` symbol separating [pages IDs](#page-id). All contents of differents pages elements will be concatenated inside one element.

|page versions |1 |2 |
|---------------|---|---|
|support |✔️ ||

**In pages V1**, ou can concatenate differents pages [elements](#content-elements), using `+` symbol separating [pages IDs](#page-id). All contents of differents pages elements will be concatenated inside one element.

%<element>?id=<page1_id>+<page2_id>+*%

Where `*` is the page ID of the rendered page.


**In page V2** this is useless as you can simply repeat the simple inclusion syntax multiple times.

#### Rendering options


##### HTML tags


|page versions |1 |2 |
|---------------|---|---|
|support |✔️ ||

%<element>?tag=(0|1)%

This will determine if HTML tags will be printed around included element. This may be usefull for advanced users to achieve more precise HTML editing.
Expand All @@ -723,13 +737,23 @@ This will include the content of the *nav* element of your page, but without any

##### Markdown disable


|page versions |1 |2 |
|---------------|---|---|
|support |✔️ |✔️ |

%<element>?mardown=(0|1)%

Activate or desactivate [markdonw](#markdown) parser in called `<element>`. By default, Markdown is set to `1`.


##### Header ID


|page versions |1 |2 |
|---------------|---|---|
|support |✔️ |✔️ |

%<element>?headerid=<x>-<y>%

By default, HTML `#id` are generated for every `<h1>` to `<h6>` headings. You can specify a range of headers outside which no ID will be added.
Expand All @@ -739,6 +763,11 @@ You can also set `headerid=0` to totaly disable ID generation for this element.

##### Anchor links in title


|page versions |1 |2 |
|---------------|---|---|
|support |✔️ |✔️ |

%<element>?headeranchor=(0|1|2)%

This render option is used to add automatic target link to title anchors.
Expand All @@ -750,12 +779,22 @@ This settings is deactivated by default.

##### URL linker


|page versions |1 |2 |
|---------------|---|---|
|support |✔️ |✔️ |

%<element>?urllinker=(0|1)%

URL Linker is a tool that will transform a plain text URL into a link. This can be enabled or disabled specificly for each elements. The default behavior can be set globaly in the [admin panel](#admin).

##### Everylink


|page versions |1 |2 |
|---------------|---|---|
|support |✔️ |✔️ |

Everylink is an powerfull but surprising feature that will replace everything you type with links.

%<element>?everylink=<level>%
Expand Down Expand Up @@ -983,9 +1022,11 @@ This is not an editable metadata. It's a list of all pages that are linked from

#### Content

##### markdown elements
##### content elements

**In pages V1**, there are 5 content elements : Main, Nav, Aside, Header, Footer.

Main, Nav, Aside, Header, Footer
**In pages V2**, there is only one content element called "content".

##### CSS

Expand Down
12 changes: 12 additions & 0 deletions app/class/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ protected function configform()
indicate the subfolder(s) in witch you installed the CMS
</i></p>
</div>
<div>
<h2>
Page version
</h2>
<p>
Select the page version you want to use. If you don't know what it means, keep version 2.
</p>
<select name="configinit[pageversion]" id="pageversion">
<option value="1">v1</option>
<option value="2" selected>v2</option>
</select>
</div>
<div>
<h2>
<label for="pagetable">Name of your database table</label>
Expand Down
64 changes: 59 additions & 5 deletions app/class/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ abstract class Config
protected static $privatepass = false;
protected static $notpublishedpass = false;
protected static $alertcss = false;
protected static $defaultbody = "%HEADER%\n\n%NAV%\n\n%ASIDE%\n\n%MAIN%\n\n%FOOTER%";
protected static $defaultv1body = "%HEADER%\n\n%NAV%\n\n%ASIDE%\n\n%MAIN%\n\n%FOOTER%";
protected static $defaultv2body = "%CONTENT%";
protected static $defaultfavicon = '';
protected static $defaultthumbnail = '';
protected static string $suffix = "";
Expand Down Expand Up @@ -50,6 +51,9 @@ abstract class Config
/** @var string $lang Default string for pages */
protected static $lang = "en";

/** Page version during creation */
protected static int $pageversion = Page::V1;

public const LANG_MIN = 2;
public const LANG_MAX = 16;

Expand All @@ -75,12 +79,16 @@ public static function hydrate(array $datas)
}
}

public static function readconfig()
public static function readconfig(): bool
{
if (file_exists(Model::CONFIG_FILE)) {
$current = file_get_contents(Model::CONFIG_FILE);
$datas = json_decode($current, true);
self::hydrate($datas);
// Setup old config file to user page version 1
if (isset($datas['pageaversion'])) {
self::$pageversion = Page::V1;
}
return true;
} else {
return false;
Expand Down Expand Up @@ -227,9 +235,23 @@ public static function alertcss()
return self::$alertcss;
}

public static function defaultbody()
/**
* @return string Default BODY corrsponding to current Config's page version
*/
public static function defaultbody(): string
{
$fn = 'defaultv' . self::$pageversion . 'body';
return self::$$fn;
}

public static function defaultv1body(): string
{
return self::$defaultv1body;
}

public static function defaultv2body(): string
{
return self::$defaultbody;
return self::$defaultv2body;
}

public static function defaultfavicon()
Expand Down Expand Up @@ -322,6 +344,11 @@ public static function disablejavascript(): bool
return self::$disablejavascript;
}

public static function pageversion(): int
{
return self::$pageversion;
}


// __________________________________________ S E T ______________________________________

Expand Down Expand Up @@ -414,11 +441,31 @@ public static function setalertcss($alertcss)
self::$alertcss = boolval($alertcss);
}

/**
* Used to convert old Config version. Save
* `defaultbody` param as `defaultv1body`.
*/
public static function setdefaultbody($defaultbody)
{
if (is_string($defaultbody)) {
$defaultbody = crlf2lf($defaultbody);
self::$defaultbody = $defaultbody;
self::$defaultv1body = $defaultbody;
}
}

public static function setdefaultv1body($defaultbody)
{
if (is_string($defaultbody)) {
$defaultbody = crlf2lf($defaultbody);
self::$defaultv1body = $defaultbody;
}
}

public static function setdefaultv2body($defaultbody)
{
if (is_string($defaultbody)) {
$defaultbody = crlf2lf($defaultbody);
self::$defaultv2body = $defaultbody;
}
}

Expand Down Expand Up @@ -540,4 +587,11 @@ public static function setdisablejavascript($disablejavascript)
{
self::$disablejavascript = boolval($disablejavascript);
}

public static function setpageversion($pageversion): void
{
if (key_exists($pageversion, Page::VERSIONS)) {
self::$pageversion = $pageversion;
}
}
}
8 changes: 4 additions & 4 deletions app/class/Controllerapipage.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public function update(string $page)
}
}
$oldpage = clone $this->page;
$update = new Page($datas);
if (!is_null($update->id()) && $update->id() !== $this->page->id()) {
if (isset($datas['id']) && $datas['id'] !== $this->page->id()) {
$this->shortresponse(400, "Page ID and datas ID doesn't match");
}
$this->page->hydrate($datas);
Expand Down Expand Up @@ -111,7 +110,8 @@ public function add(string $page)
http_response_code(405);
exit;
}
$this->page = new Page(["id" => $page]);

$this->page = $this->pagemanager->newpage(["id" => $page]);
$this->page->reset();
$this->page->addauthor($this->user->id());
if ($this->pagemanager->add($this->page)) {
Expand All @@ -133,7 +133,7 @@ public function put(string $page)
if ($exist && !$this->canedit($this->page)) {
$this->shortresponse(401, 'Page already exist but user cannot update it');
}
$this->page = new Page(array_merge($this->recievejson(), ['id' => $page]));
$this->page = $this->pagemanager->newpage(array_merge($this->recievejson(), ['id' => $page]));
if ($this->pagemanager->update($this->page)) {
http_response_code($exist ? 200 : 201);
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/class/Controllerinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function desktop()
} catch (RuntimeException $e) {
try {
$mansrc = Fs::readfile(Model::MAN_FILE);
$render = new Servicerender($this->router, $this->pagemanager, true);
$render = new Servicerenderv2($this->router, $this->pagemanager, true);
$manual = $render->rendermanual($mansrc);

$sum = new Summary(['min' => 2, 'max' => 4, 'sum' => $render->sum()]);
Expand Down
Loading

0 comments on commit 8135c1c

Please sign in to comment.