mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
Merge branch 'master' into permissions
This commit is contained in:
@@ -3,14 +3,16 @@
|
||||
if (! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
*
|
||||
* This controller operates between (interface) the JS (GUI) and the NavigationLib (back-end)
|
||||
* Provides data to the ajax get calls about the filter
|
||||
* This controller works with JSON calls on the HTTP GET or POST and the output is always JSON
|
||||
*/
|
||||
class Navigation extends Auth_Controller
|
||||
{
|
||||
const SESSION_NAME = 'NAVIGATION_MENU';
|
||||
const NAVIGATION_PAGE_PARAM = 'navigation_page'; // Navigation page parameter name
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Loads the NavigationLib where the used logic lies
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -21,165 +23,67 @@ class Navigation extends Auth_Controller
|
||||
)
|
||||
);
|
||||
|
||||
$this->config->load('navigation');
|
||||
|
||||
// Load session library
|
||||
$this->load->library('session');
|
||||
$this->load->library('ExtensionsLib');
|
||||
$this->_loadNavigationLib(); // Loads the NavigationLib with parameters
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Public methods
|
||||
|
||||
/**
|
||||
* This function creates the left Menu for each Page
|
||||
* @param navigation_widget_called GET Parameter witch holds the currently called Page
|
||||
* @param NAVIGATION_PAGE_PARAM GET Parameter witch holds the currently called Page
|
||||
* @return JSON object with the Menu Entries
|
||||
*/
|
||||
public function menu()
|
||||
{
|
||||
$navigation_widget_called = $this->input->get('navigation_widget_called');
|
||||
$json = array();
|
||||
$menuArray = $this->navigationlib->getMenuArray($this->input->get(self::NAVIGATION_PAGE_PARAM));
|
||||
|
||||
if (isset($navigation_widget_called))
|
||||
{
|
||||
// Get Menu Entries of the Core
|
||||
$navigationMenuArray = $this->config->item('navigation_menu');
|
||||
$json = $this->wildcardsearch($navigationMenuArray, $navigation_widget_called);
|
||||
|
||||
// Load Menu Entries of Extensions
|
||||
$extensions = $this->extensionslib->getInstalledExtensions();
|
||||
if(hasData($extensions))
|
||||
{
|
||||
$json_extension = array();
|
||||
foreach($extensions->retval as $ext)
|
||||
{
|
||||
$filename = APPPATH.'config/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$ext->name.'/navigation.php';
|
||||
if (file_exists($filename))
|
||||
{
|
||||
unset($config);
|
||||
include($filename);
|
||||
if(isset($config['navigation_menu']) && is_array($config['navigation_menu']))
|
||||
{
|
||||
$json_extension = array_merge_recursive($json_extension, $this->wildcardsearch($config['navigation_menu'], $navigation_widget_called));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Merge Extension Menuentries with the Core Entries
|
||||
$json = array_merge_recursive($json, $json_extension);
|
||||
}
|
||||
|
||||
// Load dynamic Menu Entries from Session
|
||||
if (isset($_SESSION['navigation_menu']))
|
||||
{
|
||||
$navigationMenuSessionArray = $_SESSION['navigation_menu'];
|
||||
|
||||
if (isset($navigationMenuSessionArray) && is_array($navigationMenuSessionArray))
|
||||
{
|
||||
if (isset($navigationMenuSessionArray[$navigation_widget_called]))
|
||||
{
|
||||
$json = array_merge_recursive($json, $navigationMenuSessionArray[$navigation_widget_called]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->output->set_content_type('application/json')->set_output(json_encode($json));
|
||||
$this->outputJsonSuccess($menuArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates the Top Menu for each Page
|
||||
* @param navigation_widget_called GET Parameter witch holds the currently called Page
|
||||
* @param NAVIGATION_PAGE_PARAM GET Parameter witch holds the currently called Page
|
||||
* @return JSON object with the Menu Entries
|
||||
*/
|
||||
public function header()
|
||||
{
|
||||
$navigation_widget_called = $this->input->get('navigation_widget_called');
|
||||
$json = array();
|
||||
$headerArray = $this->navigationlib->getHeaderArray($this->input->get(self::NAVIGATION_PAGE_PARAM));
|
||||
|
||||
if (isset($navigation_widget_called))
|
||||
{
|
||||
// Load Header Entries of Core
|
||||
$navigationHeaderArray = $this->config->item('navigation_header');
|
||||
$json = $this->wildcardsearch($navigationHeaderArray, $navigation_widget_called);
|
||||
|
||||
// Load Header Entries of Extensions
|
||||
$extensions = $this->extensionslib->getInstalledExtensions();
|
||||
if(hasData($extensions))
|
||||
{
|
||||
$json_extension = array();
|
||||
foreach($extensions->retval as $ext)
|
||||
{
|
||||
$filename = APPPATH.'config/'.ExtensionsLib::EXTENSIONS_DIR_NAME.'/'.$ext->name.'/navigation.php';
|
||||
if (file_exists($filename))
|
||||
{
|
||||
unset($config);
|
||||
include($filename);
|
||||
if(isset($config['navigation_header']) && is_array($config['navigation_header']))
|
||||
{
|
||||
$json_extension = array_merge_recursive($json_extension, $this->wildcardsearch($config['navigation_header'], $navigation_widget_called));
|
||||
}
|
||||
}
|
||||
}
|
||||
$json = array_merge_recursive($json, $json_extension);
|
||||
}
|
||||
|
||||
// Load dynamic Header Entries from Session
|
||||
if (isset($_SESSION['navigation_header']))
|
||||
{
|
||||
$navigationHeaderSessionArray = $_SESSION['navigation_header'];
|
||||
|
||||
if (isset($navigationHeaderSessionArray) && is_array($navigationHeaderSessionArray))
|
||||
{
|
||||
if (isset($navigationHeaderSessionArray[$navigation_widget_called]))
|
||||
{
|
||||
$jsontmp = $this->wildcardsearch($navigationHeaderSessionArray, $navigation_widget_called);
|
||||
$json = array_merge_recursive($json, $jsontmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->output->set_content_type('application/json')->set_output(json_encode($json));
|
||||
$this->outputJsonSuccess($headerArray);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
// Private methods
|
||||
|
||||
/**
|
||||
* Searches a Menuentry. If there is no exact entry it searches for Wildcard Entries with a Star
|
||||
* Example:
|
||||
* Searching for /system/foo/index will Match the following Menuentries:
|
||||
* /system/foo/index
|
||||
* /system/foo/*
|
||||
* /system/*
|
||||
* *
|
||||
*
|
||||
* @param $navigationArray Array to Search in.
|
||||
* @param $navigation_widget_called Navigation to search for.
|
||||
* @return Navigation Array if found, empty array otherwise
|
||||
* Loads the FiltersLib with the NAVIGATION_PAGE_PARAM parameter
|
||||
* If the parameter NAVIGATION_PAGE_PARAM is not given then the execution of the controller is terminated and
|
||||
* an error message is printed
|
||||
*/
|
||||
private function wildcardsearch($navigationArray, $navigation_widget_called)
|
||||
private function _loadNavigationLib()
|
||||
{
|
||||
// Sort Navigation to have them in correct order
|
||||
krsort($navigationArray);
|
||||
|
||||
// 100% match found
|
||||
if(isset($navigationArray[$navigation_widget_called]))
|
||||
// If the parameter NAVIGATION_PAGE_PARAM is present in the HTTP GET or POST
|
||||
if (isset($_GET[self::NAVIGATION_PAGE_PARAM]) || isset($_POST[self::NAVIGATION_PAGE_PARAM]))
|
||||
{
|
||||
return $navigationArray[$navigation_widget_called];
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach($navigationArray as $key=>$row)
|
||||
// If it is present in the HTTP GET
|
||||
if (isset($_GET[self::NAVIGATION_PAGE_PARAM]))
|
||||
{
|
||||
// Search for * Entries
|
||||
if(mb_strpos($key, '*') === 0 || mb_strpos($key, '*') === mb_strlen($key) - 1)
|
||||
{
|
||||
// Take * Entry if Matches
|
||||
$search = mb_substr($key, 0, -1);
|
||||
if($search == '' || mb_strpos($navigation_widget_called, $search) === 0)
|
||||
{
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
$navigationPage = $this->input->get(self::NAVIGATION_PAGE_PARAM); // is retrived from the HTTP GET
|
||||
}
|
||||
elseif (isset($_POST[self::NAVIGATION_PAGE_PARAM])) // Else if it is present in the HTTP POST
|
||||
{
|
||||
$navigationPage = $this->input->post(self::NAVIGATION_PAGE_PARAM); // is retrived from the HTTP POST
|
||||
}
|
||||
}
|
||||
|
||||
return array();
|
||||
// Loads the FiltersLib that contains all the used logic
|
||||
$this->load->library('NavigationLib', array(self::NAVIGATION_PAGE_PARAM => $navigationPage));
|
||||
}
|
||||
else // Otherwise an error will be written in the output
|
||||
{
|
||||
// NOTE: Used echo to speed up the output before the exit otherwise it's not shown
|
||||
echo 'Parameter "'.self::NAVIGATION_PAGE_PARAM.'" not provided!';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user