Kaynağa Gözat

rewrite menu building code

tags/v1.1
ebeveyn
işleme
5556a70ec1
4 değiştirilmiş dosya ile 92 ekleme ve 85 silme
  1. +0
    -9
      app/views/nav-external.htm
  2. +29
    -20
      app/views/navigation.htm
  3. +16
    -11
      app/views/tpl/index.html
  4. +47
    -45
      index.php

+ 0
- 9
app/views/nav-external.htm Dosyayı Görüntüle

@@ -1,9 +0,0 @@
<ul>
<repeat group="{{ @menu }}" key="{{ @key }}" value="{{ @item }}">

<li class="away">
<a href="{{ @item.href }}" class="nav-{{ @key }}">{{ @item.name }}</a>
</li>

</repeat>
</ul>

+ 29
- 20
app/views/navigation.htm Dosyayı Görüntüle

@@ -1,13 +1,22 @@
<check if="{{ @menuAddHome }}">
<a class="home-link" href="{{ @SITE_URL }}/{{ (@LANG=='de' ? '' : '?lang='.@LANG )}}">HOME</a>
</check>

<ul>
<ul>
<repeat group="{{ @menu }}" key="{{ @key }}" value="{{ @item }}">
<check if="{{ is_array(@item) }}">
<true>
<li class="{{ in_array(@key,$url)?'active':'away' }}">
<a href="{{ @SITE_URL }}/{{ @key }}{{ (@LANG=='de' ? '' : '?lang='.@LANG )}}">{{ @item.index }}</a>
<li><a href="{{ @item.href }}" >{{ @item.name }}</a>
<check if="{{ is_array(@item.submenu) }}">
<include href="navigation.htm" with="menu={{ @item.submenu }}" />
</check>
</li>

</repeat>
</ul>

<check if="{{ false }}">
<ul>
<repeat group="{{ @menu }}" key="{{ @key }}" value="{{ @item }}">
<check if="{{ is_array(@item) }}">
<true>
<li class="{{ in_array(@key,$url)?'active':'away' }}">
<a href="{{ @SITE_URL }}/{{ @key }}{{ (@LANG=='de' ? '' : '?lang='.@LANG )}}">{{ @item.index }}</a>
<check if="{{ count(@item) > 1 }}">
<ul>
@@ -21,14 +30,14 @@
</ul>
</check>
</li>
</true>
<false>
<li class="{{ in_array(@key,$url)?'active':'away' }}">
<a href="{{ @SITE_URL }}/{{ @key }}{{ (@LANG=='de' ? '' : '?lang='.@LANG )}}">{{ @item }}</a>
</li>
</false>
</check>
</repeat>
</ul>
</li>
</true>
<false>
<li class="{{ in_array(@key,$url)?'active':'away' }}">
<a href="{{ @SITE_URL }}/{{ @key }}{{ (@LANG=='de' ? '' : '?lang='.@LANG )}}">{{ @item }}</a>
</li>
</false>
</check>
</repeat>
</ul>
</check>

+ 16
- 11
app/views/tpl/index.html Dosyayı Görüntüle

@@ -1,19 +1,24 @@
<!doctype html>
<html>
<html lang="{{ @LANG }}">
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta content="noindex, nofollow" name="robots">
<check if="{{ @hideFromSearchEngines }}">
<meta name="robots" content="noindex, nofollow">
</check>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="/rsc/img/favicon OFS.png" />
<link rel="icon" href="/{{ @RESOURCES }}favicon.png" />
<link href="/rsc/featherlight.min.css" type="text/css" rel="stylesheet" />
<link href="/{{ @RESOURCES }}featherlight.min.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="/{{ @RESOURCES }}jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/{{ @RESOURCES }}script.js"></script>
<link type="text/css" href="/{{ @RESOURCES }}style.css" rel="stylesheet" />
<title>{{ @title }}</title>
<style>
li { margin-left:1em; }
</style>
</head>
<body class="{{ @bodyClass }}">
@@ -21,11 +26,11 @@
<div id="mobile-nav">
<a class="menu-toggle" onClick="javascript:toggle_menu();"></a>
<div class="the_list">
<include href="navigation.htm" />
<include href="navigation.htm" with="menu={{ @menu2 }},menuAddHome={{ @menu2AddHome }}" />
<include href="navigation.htm" with="menu={{ @navi.main }}" />
<include href="navigation.htm" with="menu={{ @navi.footer }}" />
<include href="nav-external.htm" with="menu={{ @navi.languages }}" />
</div>
</div>
</div> <!-- #mobile-nav -->

<div id="page-wrap">
@@ -35,9 +40,9 @@
</header>

<nav id="main-nav">
<include href="navigation.htm" />
<include href="navigation.htm" with="menu={{ @navi.main }}" />
<div class="network">
<include href="nav-external.htm" with="menu={{ @navi.network }},menuAddHome={{ @navi.network._config.addHome }}">
<include href="navigation.htm" with="menu={{ @navi.network }}">
</div>
</nav>
@@ -50,14 +55,14 @@
<footer id="main-footer">
<nav>
<include href="navigation.htm" with="menu={{ @menu2 }},menuAddHome={{ @menu2AddHome }}" />
<include href="navigation.htm" with="menu={{ @navi.footer }}" />
</nav>
<nav id="languages">
<include href="nav-external.htm" with="menu={{ @navi.languages }}" />
</nav>
</footer>

</div>
</div> <!-- #page-wrap -->
<check if="{{ @backend }}">
<div id="admin-panel">{{ @backend | raw }}</div>

+ 47
- 45
index.php Dosyayı Görüntüle

@@ -52,58 +52,60 @@ if(array_key_exists($f3->get('LANG'), $f3->get('content'))) {
}
$f3->set('CONTENT', $content_dir);

// set menu
if(array_key_exists($f3->get('LANG'), $f3->get('nav.main'))) {
$menu=$f3->get('nav.main.'.$f3->get('LANG'));
} else {
$menu=$f3->get('nav.main.'.$f3->get('default_lang'));
}
$f3->set('menuAddHome',$f3->get('nav.main.config.addHome'));
$f3->set('menu', $menu);
// set menu2

if(array_key_exists($f3->get('LANG'), $f3->get('nav.footer'))) {
$menu=$f3->get('nav.footer.'.$f3->get('LANG'));
} else {
$menu=$f3->get('nav.footer.'.$f3->get('default_lang'));
}
$f3->set('menu2AddHome',$f3->get('nav.footer.config.addHome'));
$f3->set('menu2', $menu);

if(array_key_exists($f3->get('LANG'), $f3->get('nav.network'))) {
$menu=$f3->get('nav.network.'.$f3->get('LANG'));
} else {
$menu=$f3->get('nav.network.'.$f3->get('default_lang'));
}
if(is_array($menu)) {
foreach($menu as $k=>$v) {
$ex = explode(": ", $menu[$k]);
$menu[$k] = array(
'name' => trim($ex[0]),
'href' => count($ex) > 1 ? $ex[1] : $ex
);
function menu_recursion($m,$root="") {
$f3 = \Base::instance();
$out=[];
foreach ($m as $key=>$value) {
$folder = $key == "index" ? "" : "/".$key;
$path = $root.$folder;

if (is_array($value)) {
$submenu=menu_recursion($value,$path);
$out[$path]=$submenu[$path];
unset($submenu[$path]);
$out[$path]['submenu']=$submenu;
} else {
$ex = explode(":=", $value);
if (count($ex) > 1) {
# external link
$href = $ex[1];
} else {
# internal link
$href = $f3->get('SITE_URL').$path;
}
$out[$path]['name']=$ex[0];
$out[$path]['href']=$href;
//print($path." - ".$ex[0]." - ".$href."<br>");
}
}
return $out;
}
$f3->set('navi.network._config.addHome', $f3->get('nav.network.config.addHome'));
$f3->set('navi.network', $menu);
function read_menu($menu_name) {
$f3 = \Base::instance();
if(array_key_exists($f3->get('LANG'), $f3->get('nav.'.$menu_name))) {
$menu=$f3->get('nav.'.$menu_name.'.'.$f3->get('LANG'));
} else {
$menu=$f3->get('nav.'.$menu_name.'.'.$f3->get('default_lang'));
}

if(array_key_exists($f3->get('LANG'), $f3->get('nav.languages'))) {
$menu=$f3->get('nav.languages.'.$f3->get('LANG'));
} else {
$menu=$f3->get('nav.languages.'.$f3->get('default_lang'));
}
if(is_array($menu)){
foreach($menu as $k=>$v) {
$ex = explode(": ", $menu[$k]);
$menu[$k] = array(
'name' => trim($ex[0]),
'href' => count($ex) > 1 ? $ex[1] : $ex
);
if (is_array($menu)) {
//var_dump($menu);
//print("<br>");
$menu=menu_recursion($menu);
}
$f3->set('navi.languages._config.addHome', $f3->get('nav.languages.config.addHome'));
$f3->set('navi.languages', $menu);

$f3->set('navi.'.$menu_name, $menu);
//var_dump($f3->get('navi.'.$menu_name));
//print("<br>");
}

read_menu("main");
read_menu("footer");
read_menu("network");
read_menu("languages");

// this is needed so the menu can compare the current page with a link to it
// and use this information to determine the active state

Yükleniyor…
İptal
Kaydet