get("navigation_allow_custom_menu")==0) return; ?>
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'])?' ':'';
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);
?>
title=""
target=""
onclick=""
href="" >
$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");
?>