MyNoVi/apps/apps.php

144 lines
3.7 KiB
PHP
Raw Normal View History

2020-10-08 17:00:12 +02:00
<?php
/**
* Améliore la sortie print
*
2020-10-29 13:33:29 +01:00
* @author Tatane http://www.tatane.info/index.php/print_rn
* @author http://www.blog.cactuscrew.com/77-print_rn.html
* @author Knah Tsaeb <Knah-Tsaeb_mynovi@knah-tsaeb.org>
* @global
* @param mixed $data
* @param string $name Default: ''
* @return void
2020-10-08 17:00:12 +02:00
*/
function n_print($data, $name = '')
{
$aBackTrace = debug_backtrace();
echo '<h2>', $name, '</h2>';
echo '<fieldset style="border: 1px solid orange; padding: 5px;color: #333; background-color: #fff;">';
echo '<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '</legend>';
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';
echo '</fieldset><br />';
}
2020-10-29 13:33:29 +01:00
/**
* Return list dir of content
*
* @author Knah Tsaeb <Knah-Tsaeb_mynovi@knah-tsaeb.org>
* @global
* @return array
*/
2020-10-08 17:00:12 +02:00
function listDir()
{
$dirList = array();
foreach (glob("content/*", GLOB_ONLYDIR) as $dir) {
$dirList[basename($dir)] = listFile($dir);
}
2020-10-29 13:33:29 +01:00
if (empty($dirList)) {
$dirList = array();
}
2020-10-08 17:00:12 +02:00
return $dirList;
}
2020-10-29 13:33:29 +01:00
/**
* Return list file in dir
*
* @author Knah Tsaeb <Knah-Tsaeb_mynovi@knah-tsaeb.org>
* @global
* @param mixed $dir
* @return mixed
*/
2020-10-08 17:00:12 +02:00
function listFile($dir)
{
$fileList = array();
foreach (glob($dir . "/*.md") as $dir) {
$fileList[] = str_replace('.md', '', basename($dir));
}
2020-10-29 13:33:29 +01:00
if (empty($fileList)) {
$fileList = array();
}
2020-10-08 17:00:12 +02:00
return $fileList;
}
2020-10-29 13:33:29 +01:00
/**
* Gen navigation menu
*
* @author Knah Tsaeb <Knah-Tsaeb_mynovi@knah-tsaeb.org>
* @global
* @param string $getDir Default: null
* @param bool $urlRewrite Default: false
2020-10-29 13:33:29 +01:00
* @return string
*/
function makeMenu($getDir = null, $urlRewrite = false)
2020-10-08 17:00:12 +02:00
{
$dirList = listDir();
$menu = '';
foreach ($dirList as $dir => $files) {
if ($getDir === $dir) {
$expand = 'open';
} else {
$expand = '';
2020-10-08 17:00:12 +02:00
}
$menu .= '
<details ' . $expand . '>
<summary>' . $dir . '</summary>
<ul>';
foreach ($files as $value) {
if($urlRewrite === true){
$menu .= '<li><a href="/' . urlencode($dir) . '/' . urlencode($value) . '">' . $value . '</a></li>';
} else {
$menu .= '<li><a href="?dir=' . urlencode($dir) . '&amp;file=' . urlencode($value) . '">' . $value . '</a></li>';
}
2020-10-08 17:00:12 +02:00
}
$menu .= '
</ul>
</details>';
}
return $menu;
}
2020-10-14 12:18:12 +02:00
2020-10-29 13:33:29 +01:00
/**
* Add lazy loading attribute for img
*
* @author Knah Tsaeb <Knah-Tsaeb_mynovi@knah-tsaeb.org>
* @see ParsedownToc
* @global
*/
2020-10-14 12:18:12 +02:00
class ExtendParsedownToc extends ParsedownToc
{
public function inlineImage($Excerpt)
{
if (!isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') {
return;
}
$Excerpt['text'] = substr($Excerpt['text'], 1);
$Link = $this->inlineLink($Excerpt);
if ($Link === null) {
return;
}
$Inline = array(
'extent' => $Link['extent'] + 1,
'element' => array(
'name' => 'img',
'attributes' => array(
'src' => $Link['element']['attributes']['href'],
'alt' => $Link['element']['text'],
'loading' => 'lazy',
),
),
);
$Inline['element']['attributes'] += $Link['element']['attributes'];
unset($Inline['element']['attributes']['href']);
return $Inline;
}
}