"",
'1' => "",
'2' => "",
'3' => "",
'4' => "",
'5' => ""
];
/**
* Default core administration pages
*
* @var array
*/
public $admin_page_icons = [
'C' => "", // Comments
'CP' => "", // Custom page
'IM' => "", // Images
'PM' => "", // private message
'APWR' => "", // Admin Password Reset
'AD' => "", // Administrator
'B' => "", // Blacklist
'M' => "", // Members
'MI' => "", // Migration tool
'SU' => "", // User Submissions
'UF' => "", // User Fields
'UG' => "", // user groups
'UL' => "", // user logs
'SB' => "", // Banners
'BB' => "", // Bbcode
'DB' => "", // database backup
'MAIL' => "", // Email templates
'ERRO' => "", // Error Logs
'I' => "", // Infusions
'P' => "", // Panels
'PL' => "", // Permalink
'PI' => "", // php Info
'ROB' => "", // robots.txt
'SL' => "", // Site Links
'SM' => "", // Smileys
'TS' => "", // Theme
'U' => "", // Upgrade
'LANG' => "", // Language Settings
'S1' => "", // Main Settings
'S2' => "", // Time and Date
'S3' => "", // Theme Settings
'S4' => "", // Registration Settings
'S6' => "", // Miscellaneous Settings
'S7' => "", // PM Settings
'S9' => "", // User Management
'S10' => "", // Items Per Page
'S12' => "", // Security Settings
'FM' => "", // Fusion File Manager
];
/**
* @var array
*/
private $admin_sections = [1 => FALSE, 2 => FALSE, 3 => FALSE, 4 => FALSE, 5 => FALSE];
/**
* @var array
*/
private $admin_page_link = [];
/**
* Constructor class. No Params
*/
private $current_page = '';
private $comment_type = [];
private $submit_type = [];
private $submit_link = [];
private $link_type = [];
private $submit_data = [];
private $folder_permissions = [];
public function __construct() {
self::$locale = self::getAdminLocale();
}
public static function getAdminLocale() {
if (empty(self::$locale)) {
self::$locale = fusion_get_locale('', LOCALE.LOCALESET.'admin/main.php');
}
return self::$locale;
}
/**
* Add instance
*
* @return static
*/
public static function getInstance() {
if (empty(self::$instance)) {
self::$instance = new static();
}
return self::$instance;
}
/**
* Cache the Current Field Inputs within Login session.
*
* @param $form_id
* @param $form_type
* @param $item_id
* @param array $callback_fields
* @param int $cache_time
*
* @return string
*/
public function requestCache($form_id, $form_type, $item_id, array $callback_fields = [], $cache_time = 30000) {
/*
add_to_footer("");
add_to_head("");
add_to_jquery("
var input_fields = $('#$form_id').serialize();
$.confirm({
title: 'Restore Editing Session',
content: 'There is a draft found for your previous editing session. Do you wish to restore?',
buttons: {
confirm: function () {
$.ajax({
url: '$remote',
type: 'post',
data: {
'fusion_token': '$token',
'aidlink': '".fusion_get_aidlink()."',
'fields': input_fields,
'form_id' : '$form_id',
'item_id':'$item_id',
'form_type':'$form_type',
'callback':'read_cache'
},
dataType: 'json',
success: function (e) {
if (e.response == 200) {
$.each(e.data, function(key, value) {
$('#'+key).val( value );
});
setTimeout(function(e) {
//$.alert('Your editing session has been restored');
setTimeout( function(e) {UpdateAdminCache() }, $cache_time);
}, 100);
}
},
error: function(e) {
}
});
},
cancel: function () {
//$.alert('Canceled!');
}
/*somethingElse: {
text: 'Something else',
btnClass: 'btn-blue',
keys: ['enter', 'shift'],
action: function(){
$.alert('Something else?');
}
}
}
});
");*/
$remote = fusion_get_settings('site_path')."administration/includes/cache_update.php";
$token = fusion_get_token($form_id, 5);
add_to_jquery("
function timedCacheRequest(timeout) {
setTimeout(UpdateAdminCache, timeout);
}
function UpdateAdminCache(poll) {
var input_fields = $('#$form_id').serialize();
var ttl = '$cache_time';
$.ajax({
url: '$remote',
type: 'post',
dataType: 'html',
data: {
'fusion_token': '$token',
'aidlink': '".fusion_get_aidlink()."',
'fields': input_fields,
'form_id' : '$form_id',
'form_type':'$form_type',
'item_id': '$item_id',
'callback':'set_cache',
},
dataType: 'json',
success: function (e) {
console.log(e);
console.log(poll);
if (typeof poll === 'undefined') {
//console.log('we are starting a long poll now');
timedCacheRequest(ttl);
}
}
});
}
// add abort long poll once we change fields.
$('#".$form_id." :input').blur(function(e) {
UpdateAdminCache(1);
});
");
if (!isset($_GET['autosave'])) {
// not to pass prefix xhr for security reason.
add_to_jquery("setTimeout( function(e) { UpdateAdminCache() }, $cache_time);");
}
$html = "";
if (!empty($_SESSION['form_cache'][$form_id][$form_type][$item_id])) {
$html .= "";
if (isset($_GET['autosave']) && $_GET['autosave'] == 'view') {
$html .= "
\n";
$html .= fusion_get_function('openside', "
".self::$locale['292']."
");
$session = html_entity_decode($_SESSION['form_cache'][$form_id][$form_type][$item_id]);
parse_str($session, $data);
unset($data['form_id']);
unset($data['fusion_token']);
$html .= "
\n";
$fill_js = "";
foreach ($data as $field_name => $value) {
if (isset($callback_fields[$field_name])) {
$html .= "- ".$callback_fields[$field_name]."
\n";
$html .= "- ".nl2br(html_entity_decode($value))."".form_hidden('s_'.$field_name, '', $value)."
\n";
$fill_js .= "
var c = $('#s_$field_name').val();
$('#".$field_name."').val(c);
";
}
}
$html .= "
\n";
$html .= "
\n";
$html .= "\n";
$html .= "\n";
$html .= "
\n";
$html .= fusion_get_function('closeside');
$html .= "
\n";
add_to_jquery("
$('button[name^=\"fill_session\"]').bind('click', function(e) {
$fill_js
$('#rev-window').hide();
UpdateAdminCache();
});
$('button[name^=\"cancel_session\"]').bind('click', function(e) {
$('#rev-window').hide();
UpdateAdminCache();
});
");
}
}
return $html;
}
public function setAdmin() {
if (!defined('IN_SETUP')) {
self::$admin_pages = $this->getAdminPages();
$this->admin_sections = array_filter(array_merge([
0 => self::$locale['ac00'],
1 => self::$locale['ac01'],
2 => self::$locale['ac02'],
3 => self::$locale['ac03'],
4 => self::$locale['ac04'],
5 => self::$locale['ac05'],
], $this->admin_sections));
$this->admin_sections = array_values($this->admin_sections);
$this->current_page = $this->_currentPage();
}
}
/**
* @return array
*/
public function getAdminPages() {
self::$admin_pages = array_filter(self::$admin_pages);
if (empty(self::$admin_pages)) {
$result = dbquery("SELECT * FROM ".DB_ADMIN." WHERE admin_language='".LANGUAGE."' ORDER BY admin_page DESC, admin_id ASC, admin_title ASC");
$rows = dbrows($result);
if ($rows) {
while ($data = dbarray($result)) {
if (file_exists(ADMIN.$data['admin_link']) || file_exists(INFUSIONS.$data['admin_link'])) {
if (checkrights($data['admin_rights']) && $data['admin_link'] != "reserved") {
$data['admin_title'] = preg_replace("/&(?!(#\d+|\w+);)/", "&", $data['admin_title']);
self::$admin_pages[$data['admin_page']][] = $data;
}
}
}
}
}
return self::$admin_pages;
}
/**
* Build a return that always synchronize with the DB_ADMIN url.
*/
public function _currentPage() {
$path = $_SERVER['PHP_SELF'];
if (defined('START_PAGE')) {
$path_info = pathinfo(START_PAGE);
if (stristr(FUSION_REQUEST, '/administration/')) {
$path = $path_info['filename'].'.php';
} else {
$path = '../'.$path_info['dirname'].'/'.$path_info['filename'].'.php';
}
}
return $path;
}
/**
* @param $page - 0-5 is core section pages. 6 and above are free to use.
* @param $section_title - Section title
* @param $icons - Section Icons
*/
public function addAdminSection($page, $section_title, $icons) {
$this->admin_sections[$page] = $section_title;
$this->admin_section_icons[$page] = $icons;
self::$admin_pages[$page] = [];
}
public function setAdminBreadcrumbs() {
BreadCrumbs::getInstance()->addBreadCrumb([
'link' => ADMIN.'index.php'.fusion_get_aidlink().'&pagenum=0',
'title' => self::$locale['ac10']
]);
$acTab = (isset($_GET['pagenum']) && isnum($_GET['pagenum'])) ? $_GET['pagenum'] : $this->_isActive();
if ($acTab != 0 && $acTab <= 5) {
BreadCrumbs::getInstance()->addBreadCrumb([
'link' => ADMIN.fusion_get_aidlink()."&pagenum=".$acTab,
'title' => self::$locale['ac0'.$acTab]
]);
}
}
/**
* Determine which section is currently active.
*
* @return int|string
*/
public function _isActive() {
$active_key = 0;
self::$admin_pages = $this->getAdminPages();
if (empty($active_key) && !empty(self::$admin_pages)) {
foreach (self::$admin_pages as $key => $data) {
$link = [];
foreach ($data as $arr => $admin_data) {
$link[] = $admin_data['admin_link'];
}
$data_link = array_flip($link);
if (isset($data_link[$this->_currentPage()])) {
return $key;
}
}
}
return '0';
}
/**
* @return array
*/
public function getAdminPageIcons() {
return $this->admin_page_icons;
}
/**
* @param $rights
* @param $icons
*/
public function setAdminPageIcons($rights, $icons) {
$this->admin_page_icons[$rights] = $icons;
}
public function getLinkType($type = NULL) {
return ($type !== NULL ? (isset($this->link_type[$type]) ? $this->link_type[$type] : NULL) : $this->link_type);
}
/**
* @param $type - link prefix
* @param $link - link url
*/
public function setLinkType($type, $link) {
$this->link_type[$type] = $link;
}
/**
* Get Submit Type
*
* @param null $type submit stype prefix
*
* @return array|mixed|null
*/
public function getSubmitType($type = NULL) {
return ($type !== NULL ? (isset($this->submit_type[$type]) ? $this->submit_type[$type] : NULL) : $this->submit_type);
}
/**
* @param $type - submissions prefix
* @param $title - title
*/
public function setSubmitType($type, $title) {
$this->submit_type[$type] = $title;
}
public function getSubmitData($type = NULL) {
return ($type !== NULL ? (isset($this->submit_data[$type]) ? $this->submit_data[$type] : NULL) : $this->submit_data);
}
/**
* @param $type - submissions prefix
* @param $options - array(infusion_name, link, submit_link, submit_locale, title,admin_link)
*/
public function setSubmitData($type, array $options = []) {
defined(strtoupper($options['infusion_name']).'_EXIST') ? $this->submit_data[$type] = $options : NULL;
}
public function getSubmitLink($type = NULL) {
return ($type !== NULL ? (isset($this->submit_link[$type]) ? $this->submit_link[$type] : NULL) : $this->submit_link);
}
/**
* @param string $link Admin submission url
* @param string $type Submissions stype prefix
*/
public function setSubmitLink($type, $link) {
$this->submit_link[$type] = $link;
}
public function getCommentType($type = NULL) {
return ($type !== NULL ? (isset($this->comment_type[$type]) ? $this->comment_type[$type] : NULL) : $this->comment_type);
}
/**
* @param $type - comment prefix
* @param $title - title
*/
public function setCommentType($type, $title) {
$this->comment_type[$type] = $title;
}
/**
* @param $type - infusion_name
*/
public function getFolderPermissions($type = NULL) {
return ($type !== NULL ? (isset($this->folder_permissions[$type]) ? $this->folder_permissions[$type] : NULL) : $this->folder_permissions);
}
/**
* @param $type - infusion_name
* @param $options - array(image_folder => TRUE or FALSE)
*/
public function setFolderPermissions($type, array $options = []) {
defined(strtoupper($type).'_EXIST') ? $this->folder_permissions[$type] = $options : NULL;
}
/**
* @return array
*/
public function getAdminPageLink() {
return $this->admin_page_link;
}
/**
* @return mixed
*/
public function getCurrentPage() {
return $this->current_page;
}
/**
* Displays vertical collapsible administration navigation
*
* @param bool|FALSE $image_icon
*
* @return string
*/
public function vertical_admin_nav($image_icon = FALSE) {
$aidlink = fusion_get_aidlink();
$admin_sections = self::getAdminSections();
$admin_pages = self::getAdminPages();
add_to_jquery('$("[data-toggle=collapse]").click(function () {$(this).find(".adl-drop i").toggleClass("fa-angle-left fa-angle-down");});');
$html = "\n";
return $html;
}
/**
* @return array
*/
public function getAdminSections() {
return $this->admin_sections;
}
/**
* @param $page_number
*
* @return string
*/
public function get_admin_section_icons($page_number) {
if (!empty($this->admin_section_icons[$page_number]) && $this->admin_section_icons[$page_number]) {
return $this->admin_section_icons[$page_number];
}
return FALSE;
}
/**
* Replace admin page icons
*
* @param $page
* @param $icons
*/
public function setAdminSectionIcons($page, $icons) {
if (isset($this->admin_section_icons[$page])) {
$this->admin_section_icons[$page] = $icons;
}
}
/**
* Get the administration page icons
*
* @param $admin_rights
*
* @return bool
*/
public function get_admin_icons($admin_rights) {
// admin rights might not yield an icon & admin_icons override might not have the key.
if (isset($this->admin_page_icons[$admin_rights]) && $this->admin_page_icons[$admin_rights]) {
return $this->admin_page_icons[$admin_rights];
}
return FALSE;
}
/**
* Displays horizontal administration navigation
*
* @param bool $icon_only
*
* @return string
*/
public function horizontal_admin_nav($icon_only = FALSE) {
$aidlink = fusion_get_aidlink();
$html = "\n";
foreach ($this->admin_sections as $i => $section_name) {
$active = (isset($_GET['pagenum']) && $_GET['pagenum'] == $i || !isset($_GET['pagenum']) && $this->_isActive() == $i) ? 1 : 0;
$admin_text = $icon_only == FALSE ? " ".$section_name : "";
$html .= "- ".$this->get_admin_section_icons($i).$admin_text."
\n";
}
$html .= "
\n";
return $html;
}
}