Example #1
0
function kalMenu($args = array(), $pages = false, $lvl = 1, &$menu = "", &$paths = array())
{
    if (isset($args['hidden']) && $args['hidden']) {
        if (!$pages) {
            $pages = App\Page::where('accordion', 0)->where('parent_id', 0)->orderBy('order')->get();
        }
    } else {
        if (!$pages) {
            $pages = App\Page::where('accordion', 0)->where('parent_id', 0)->where('status', '>', 0)->orderBy('order')->get();
        }
    }
    $menu .= "<ul>";
    foreach ($pages as $page) {
        if ($page->slug[0] == '_') {
            continue;
        }
        if ($lvl == 1 && isset($args['topmenu']) && !$page->topmenu) {
            continue;
        }
        $className = "App\\" . ucfirst($page->hlutur);
        $m = new $className();
        $_id = $page->id;
        if (strtolower(trim($page->modelName())) != strtolower(trim($page->hlutur))) {
            $_id = 0;
        }
        if (isset($args['hidden']) && $args['hidden']) {
            $subs = $m->where('accordion', 0)->where($m->parent_key, $_id)->orderBy('order')->get();
        } else {
            $subs = $m->where('accordion', 0)->where($m->parent_key, $_id)->where('status', '>', 0)->orderBy('order')->get();
        }
        $paths[] = $page->slug;
        $path = "/";
        $active = \Request::segment($lvl) == $page->slug ? 'active' : '';
        //echo $lvl.' '.$page->path.' '.$active.'<br>';
        $being_viewed = \Request::path() == rtrim(ltrim($page->path, '/'), '/') ? 'being_viewed' : '';
        $has_subs = !$subs->isEmpty() ? 'has_subs' : '';
        foreach ($paths as $k => $p) {
            $path .= "{$p}/";
        }
        // Commenta út ef þú vilt ekki sýna síður með "óþýdda" titla...
        // if(! $page->translation('title')) continue;
        $title = $page->translation('title') ?: $page->title;
        $menu .= "<li class='lvl-{$lvl} {$active} {$being_viewed} {$has_subs}'><a href='{$page->path}'>{$title}</a>";
        if ($active || isset($args['expand_all']) && $args['expand_all']) {
            if (!$subs->isEmpty()) {
                $lvl++;
                kalMenu($args, $subs, $lvl, $menu, $paths);
                $lvl--;
            }
        }
        array_pop($paths);
        $menu .= "</li>";
    }
    $menu .= "</ul>";
    return $menu;
}
Example #2
0
function kalMenu($args = array(), $pages = false, $lvl = 1, &$menu = "", &$paths = array())
{
    if (isset($args['hidden']) && $args['hidden']) {
        if (!$pages) {
            $pages = App\Page::where('accordion', 0)->where('parent_id', 0)->orderBy('order')->get();
        }
    } else {
        if (!$pages) {
            $pages = App\Page::where('accordion', 0)->where('parent_id', 0)->where('status', '>', 0)->orderBy('order')->get();
        }
    }
    if (isset($args['sticky'])) {
        $menu .= '<ul data-uk-scrollspy-nav="{closest:\'li\', smoothscroll:{offset:30}, offset:-42}">';
        $menu .= "<li class=''><a href='#heim' data-uk-smooth-scroll>Heim</a></li>";
    } else {
        $menu .= "<ul>";
    }
    foreach ($pages as $page) {
        if ($page->slug[0] == '_') {
            continue;
        }
        if ($lvl == 1 && isset($args['topmenu']) && !$page->topmenu) {
            continue;
        }
        $className = "App\\" . ucfirst($page->hlutur);
        $m = new $className();
        $_id = $page->id;
        if (strtolower(trim($page->modelName())) != strtolower(trim($page->hlutur))) {
            $_id = 0;
        }
        if (isset($args['hidden']) && $args['hidden']) {
            $subs = $m->where('accordion', 0)->where($m->parent_key, $_id)->orderBy('order')->get();
        } else {
            $subs = $m->where('accordion', 0)->where($m->parent_key, $_id)->where('status', '>', 0)->orderBy('order')->get();
        }
        $paths[] = $page->slug;
        $path = "/";
        $active = \Request::segment($lvl) == $page->slug ? 'active' : '';
        //echo $lvl.' '.$page->path.' '.$active.'<br>';
        $being_viewed = \Request::path() == rtrim(ltrim($page->path, '/'), '/') ? 'being_viewed' : '';
        $has_subs = !$subs->isEmpty() ? 'has_subs' : '';
        foreach ($paths as $k => $p) {
            $path .= "{$p}/";
        }
        // Commenta út ef þú vilt ekki sýna síður með "óþýdda" titla...
        // if(! $page->translation('title')) continue;
        $title = $page->translation('title') ?: $page->title;
        $_link = stringStartsWith($page->url, '#') ? \Request::root() . "/" . $page->url : $page->path;
        $smooth = '';
        if (\Request::is('/')) {
            $_link = stringStartsWith($page->url, '#') ? $page->url : $page->path;
            $smooth = stringStartsWith($page->url, '#') ? 'data-uk-smooth-scroll="{offset:30}"' : '';
        }
        $menu .= "<li class='lvl-{$lvl} {$active} {$being_viewed} {$has_subs}'><a onclick='jQuery.UIkit.offcanvas.offcanvas.hide();' href='{$_link}' {$smooth}>{$title}</a>";
        if ($active || isset($args['expand_all']) && $args['expand_all']) {
            if (!$subs->isEmpty()) {
                $lvl++;
                kalMenu($args, $subs, $lvl, $menu, $paths);
                $lvl--;
            }
        }
        array_pop($paths);
        $menu .= "</li>";
    }
    if (isset($args['sticky'])) {
        $menu .= '<li class="extra"><a href="https://www.facebook.com/S%C3%B3lba%C3%B0sstofan-S%C3%A6lan-47566734525/"><i class="uk-icon uk-icon-facebook"></i></a></li>';
        $menu .= '<li class="extra"><a href="https://instagram.com/saelan1/"><i class="uk-icon uk-icon-instagram"></i></a></li>';
    }
    $menu .= "</ul>";
    return $menu;
}