123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <?php
- //Déclaration d'un item de menu dans le menu principal
- function navigation_menu(){
- require_once(__DIR__.SLASH.'MenuItem.class.php');
- global $myUser,$conf;
- ?>
- <ul class="navbar-nav navigation-menu">
- <?php if ($myUser->connected()):
- foreach(MenuItem::bySlug('main-menu','') as $item):
- navigation_item_template($item);
- endforeach;
- endif; ?>
- </ul>
- <?php if($conf->get("navigation_allow_custom_menu")==0) return; ?>
- <ul class="navbar-nav navigation-shortcut-menu">
- <?php if ($myUser->connected()):
- foreach(MenuItem::bySlug('shortcut-menu',$myUser->login) as $item):
- navigation_item_template($item);
- endforeach;
- endif; ?>
- </ul>
- <?php
- }
- function navigation_item_template($item){
- global $myUser,$myFirm,$conf;
- $page = basename($_SERVER['REQUEST_URI']);
- $id = isset($item['id'])?$item['id']:'';
- $target = isset($item['target'])?$item['target']:'';
- $url = isset($item['url'])?$item['url']:'';
- $label = isset($item['label'])?$item['label']:'';
- $html = isset($item['html'])?$item['html']:'';
- if (isset($item['label']) && $item['label'] == 'Réglages') $page = basename($_SERVER['PHP_SELF']);
- $linkClasses = '';
- $classes = isset($item['classes'])? $item['classes']: '';
- if(isset($item['childs']) ){
- $linkClasses .= ' nav-link';
- if(count($item['childs'])!=0){
- $classes .= ' dropdown';
- $url = '';
- $linkClasses .= ' nav-link dropdown-toggle';
- }
- $mustShow = false;
- foreach ($item['childs'] as $child) {
- //Vérification des droits de visibilité sur le menu
- $childObject = new MenuItem();
- $childObject->fromArray($child);
- if($childObject->visibleFor($myUser)){
- $mustShow = true;
- break;
- }
- }
- if(!$mustShow && $item['url']=='') return;
- }
- if($item['parent'] && $item['parent']!='') $linkClasses .= 'dropdown-item ';
- $url = navigation_meta_link($url);
- $label = navigation_meta_link($label);
- $html = navigation_meta_link($html);
- $icon = isset($item['icon'])?'<i class="'.$item['icon'].'"></i> ':'';
-
- if($target=='iframe'){
- $target = '';
- $url = 'index.php?module=navigation&page=iframe&url='.base64_encode($url);
- }
- if($target=='redirect')
- $target = '';
-
- //Highlight du menu sélectionné
- if((!empty($url) && ((strpos($page, $url) !== false && $url != 'index.php') || $page == $url)))
- $classes .= ' active';
- //Vérification des droits de visibilité sur le menu
- $itemObject = new MenuItem();
- $itemObject->fromArray($item);
- if(!$itemObject->visibleFor($myUser)) return;
- //si les logs sont activés on desactive le direct link pour passer par la surcouche de logs
- if($conf->get('navigation_enable_log')) if(!empty($url)) $url = 'action.php?action=navigation_redirect&url='.base64_encode($url);
- ?>
- <li data-id="<?php echo $id; ?>" class="nav-item <?php echo $classes; ?>">
- <a class="<?php echo $linkClasses; ?>"
- <?php echo isset($item['childs']) && count($item['childs'])!=0? 'data-toggle="dropdown"':''; ?>
- title="<?php echo isset($item['title'])?$item['title']:''; ?>"
- target="<?php echo $target; ?>"
- onclick="<?php echo isset($item['onclick'])?$item['onclick']:''; ?>"
- href="<?php echo $url; ?>" >
- <?php echo $icon; ?><?php echo $label; ?>
- <?php echo $html; ?>
- </a>
- <?php if(isset($item['childs'])): ?>
- <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
- <?php
- foreach($item['childs'] as $child):
- navigation_item_template($child);
- endforeach;
- ?>
- </ul>
- <?php endif; ?>
- </li>
- <?php
- }
- //Application des données de templates sur l'url, libellé...
- function navigation_meta_link($string){
- global $myUser;
- $data = array('user'=>$myUser->toArray());
- $data['user']['meta'] = $myUser->meta;
- unset($data['password']);
- return template($string,$data);
- }
- //Cette fonction va generer une page quand on clique sur navigation dans menu
- function navigation_page(){
- global $_,$myUser;
- if(!isset($_['module']) || $_['module'] !='navigation') return;
- $page = !isset($_['page']) ? 'list' : $_['page'];
- $file = __DIR__.SLASH.'page.'.$page.'.php';
- if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
-
- require_once($file);
- }
- //Fonction executée lors de l'activation du plugin
- function navigation_install($id){
- if($id != 'fr.sys1.navigation') return;
- Entity::install(__DIR__);
- require_once(__DIR__.SLASH.'MenuItem.class.php');
-
- $mainMenu = new MenuItem();
- $mainMenu->label = 'Menu principal';
- $mainMenu->slug = 'main-menu';
- $mainMenu->user = '';
- $mainMenu->menu = 0;
- $mainMenu->editable = 0;
- $mainMenu->save();
- $pages = array();
- Plugin::callHook("menu_main", array(&$pages));
- uasort ($pages , function($a,$b){return $a['sort']>$b['sort']?1:-1;});
-
- foreach($pages as $i=>$page):
- $icon = isset($page['icon'])? $page['icon'] : 'far fa-bookmark';
-
- $menuItem = new MenuItem();
- $menuItem->label = $page['label'];
- $menuItem->icon = $icon;
- $menuItem->url = $page['url'];
- $menuItem->user = '';
- $menuItem->menu = 0;
- $menuItem->sort = $i;
- $menuItem->slug = $mainMenu->slug.'_'.slugify($menuItem->label);
- $menuItem->menu = $mainMenu->id;
- $menuItem->save();
- endforeach;
- }
- //Fonction executée lors de la désactivation du plugin
- function navigation_uninstall($id){
- if($id != 'fr.sys1.navigation') return;
- Entity::uninstall(__DIR__);
- }
- //Déclaration des sections de droits du plugin
- function navigation_section(&$sections){
- $sections['navigation'] = "Gestion des droits sur le plugin navigation";
- }
- //cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue html
- function navigation_action(){
- require_once(__DIR__.SLASH.'action.php');
- }
- //Déclaration du menu de réglages
- function navigation_menu_setting(&$settingMenu){
- global $_, $myUser;
-
- if(!$myUser->can('navigation','configure')) return;
- $settingMenu[]= array(
- 'sort' =>1,
- 'url' => 'setting.php?section=global.navigation',
- 'icon' => 'fas fa-angle-right',
- 'label' => 'Menu & Navigation'
- );
- }
- //Déclaration des pages de réglages
- function navigation_content_setting(){
- global $_;
- if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
- require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
- }
- //Déclaration des settings de base
- //Types possibles : text,select ( + "values"=> array('1'=>'Val 1'),password,checkbox. Un simple string définit une catégorie.
- Configuration::setting('navigation',array(
- "Général",
- 'navigation_allow_custom_menu' => array("label"=>"Autoriser la création de menu personnalisés","legend"=>"Autorise aux utilisateurs la création de raccourcis dans la barre principale","type"=>"checkbox"),
- 'navigation_enable_log' => array("label"=>"Activer les logs au clic sur un menu","legend"=>"Cette option peut considérablement augmenter la taille de la base de données","type"=>"checkbox"),
- ));
- //Déclation des assets
- Plugin::addCss("/css/main.css");
- Plugin::addJs("/js/main.js");
- Plugin::addHook("menu_user", function(&$userMenu){
- global $conf, $myUser;
- if($conf->get("navigation_allow_custom_menu")==0 && !$myUser->superadmin) return;
- $userMenu[]= array(
- 'sort' => 0.5,
- 'label' => 'Mes raccourcis',
- 'icon' => 'far fa-fw fa-star',
- 'url' => 'setting.php?section=global.navigation&menu=mine'
- );
- });
- function navigation_widget(&$widgets){
- global $myUser;
- require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php');
- $modelWidget = new DashboardWidget();
- $modelWidget->model = 'menu';
- $modelWidget->title = 'Menu';
- $modelWidget->icon = 'far fa-compass';
- $modelWidget->background = '#130f40';
- $modelWidget->load = 'action.php?action=navigation_widget_load';
- $modelWidget->js = [Plugin::url().'/js/widget.js?v=0'];
- $modelWidget->css = [Plugin::url().'/css/widget.css?v=0'];
- $modelWidget->configure = 'action.php?action=navigation_widget_configure';
- $modelWidget->configure_callback = 'navigation_widget_configure_save';
- $modelWidget->configure_init = 'navigation_widget_configure_init';
- $modelWidget->description = "Affiche un menu sélectionné";
- $widgets[] = $modelWidget;
- }
- //Mapping hook / fonctions
- Plugin::addHook("widget", "navigation_widget");
- Plugin::addHook("install", "navigation_install");
- Plugin::addHook("uninstall", "navigation_uninstall");
- Plugin::addHook("section", "navigation_section");
- Plugin::addHook("header", "navigation_menu");
- Plugin::addHook("page", "navigation_page");
- Plugin::addHook("action", "navigation_action");
- Plugin::addHook("menu_setting", "navigation_menu_setting");
- Plugin::addHook("content_setting", "navigation_content_setting");
- ?>
|