Пример #1
0
    function cms_menu_auto($echo = true)
    {
        $show = cms_option('show_menu');
        if ('true' != $show) {
            return;
        }
        $pages = Thin\Cms::getParents();
        $actualPage = container()->getPage();
        $parent = $actualPage->getParent();
        $lngs = explode(',', cms_option('page_languages'));
        $pageParent = new url();
        if (!empty($parent)) {
            $sql = dm('page');
            $pageParents = $sql->where('id = ' . $parent)->get();
            $pageParent = $sql->first($pageParents);
        }
        $html = '
<script>
$(document).ready(function() {
    $(\'#mainNavbar\').scrollspy()
});
</script><form action="" method="post" id="lng_form"><input id="cms_lng" name="cms_lng" value="' . getLanguage() . '" /></form>';
        $fixed = 'true' == cms_option('menu_fixed') ? true : false;
        $showLogo = 'true' == cms_option('show_logo') ? true : false;
        if (true === $fixed) {
            $html .= '<div id="mainNavbar" class="navbar navbar-fixed-top navbar-inverse">';
        } else {
            $html .= '<div class="navbar navbar-inverse">';
        }
        $html .= '<div class="navbar-inner">
                <div class="container">';
        $html .= '<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </a>';
        if (false === $showLogo) {
            $html .= '<a class="brand" href="/">' . cms_option('company_name') . '</a>';
        } else {
            $html .= '<a id="logoLink" class="brand" href="/"><img style="max-width: ' . cms_option('logo_max_width') . ';" src="' . cms_image('logo') . '" /></a>';
        }
        $html .= '<div class="nav-collapse collapse">';
        $html .= '<ul class="nav" id="mainMenu">';
        foreach ($pages as $page) {
            $children = Cms::getChildren($page);
            $active = Cms::__($page->getUrl()) == Cms::__($actualPage->getUrl()) || Cms::__($page->getUrl()) == Cms::__($pageParent->getUrl());
            $dropdown = count($children) > 0 ? ' dropdown' : '';
            $linkClass = count($children) > 0 ? ' class="dropdown-toggle openHover" data-toggle="dropdown"' : '';
            $caret = count($children) > 0 ? ' <b class="caret"></b>' : '';
            if ($active) {
                $html .= '<li class="active' . $dropdown . '"><a' . $linkClass . ' href="/' . Cms::__($page->getUrl()) . '">' . Cms::__($page->getMenu()) . $caret . '</a>';
            } else {
                $html .= '<li class="' . $dropdown . '"><a' . $linkClass . ' href="/' . Cms::__($page->getUrl()) . '">' . Cms::__($page->getMenu()) . $caret . '</a>';
            }
            if (count($children)) {
                $html .= '<ul class="dropdown-menu">';
                foreach ($children as $child) {
                    $html .= '<li><a href="/' . Cms::__($child->getUrl()) . '">' . Cms::__($child->getMenu()) . '</a></li>';
                }
                $html .= '</ul>';
            }
            $html .= '</li>';
        }
        $html .= '</ul>';
        $session = session('admin');
        $user = $session->getUser();
        if (1 < count($lngs) || null !== $user) {
            $actualLng = getLanguage();
            $html .= '<ul id="mainMenu" class="nav navbar-nav pull-right">';
            if (null !== $user) {
                $html .= '<li><a target="_admin" rel="tooltip-bottom" title="Accès à l\'admin" href="' . URLSITE . 'backadmin/dashboard"><i class="fa fa-cogs"></i></a></li>';
            }
            if (1 < count($lngs)) {
                foreach ($lngs as $lng) {
                    if ($lng != $actualLng) {
                        $displayOption = cms_option('lng_' . $lng . '_display');
                        if (null === $displayOption) {
                            $html .= '<li><a href="#" onclick="$(\'#cms_lng\').val(\'' . $lng . '\'); $(\'#lng_form\').submit(); return false;">' . Inflector::upper($lng) . '</a></li>';
                        } elseif ('flag' == $displayOption) {
                            $html .= '<li><a href="#" onclick="$(\'#cms_lng\').val(\'' . $lng . '\'); $(\'#lng_form\').submit(); return false;"><img src="' . URLSITE . 'assets/img/flags/' . $lng . '.png" /></a></li>';
                        }
                    }
                }
            }
            $html .= '</ul>';
        }
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        $html .= '</div>';
        if (true === $echo) {
            echo $html;
        } else {
            return $html;
        }
    }
Пример #2
0
 public static function language()
 {
     $isCMS = null !== container()->getPage();
     $session = session('web');
     if (true === $isCMS) {
         if (count($_POST)) {
             if (ake('cms_lng', $_POST)) {
                 $session->setLanguage($_POST['cms_lng']);
             } else {
                 $language = $session->getLanguage();
                 $language = null === $language ? Cms::getOption('default_language') : $language;
                 $session->setLanguage($language);
             }
         } else {
             $language = $session->getLanguage();
             $language = null === $language ? Cms::getOption('default_language') : $language;
             $session->setLanguage($language);
         }
     } else {
         $route = Utils::get('appDispatch');
         $language = $session->getLanguage();
         if (null === $language || $language != $route->getLanguage()) {
             $language = null === $route->getLanguage() ? options()->getDefaultLanguage() : $route->getLanguage();
             $session->setLanguage($language);
         }
         $module = $route->getModule();
         $controller = $route->getController();
         $action = $route->getAction();
         $module = is_string($action) ? Inflector::lower($module) : $module;
         $controller = is_string($action) ? Inflector::lower($controller) : $controller;
         $action = is_string($action) ? Inflector::lower($action) : $action;
         $config = array();
         $config['language'] = $language;
         $config['module'] = $module;
         $config['controller'] = $controller;
         $config['action'] = $action;
         $configLanguage = new Container();
         $configLanguage->populate($config);
         container()->setLanguage(new Language($configLanguage));
     }
 }
Пример #3
0
 function cms_translate($key, $params = array(), $default = null)
 {
     return Cms::translate($key, $params, $default);
 }