mirror of
https://github.com/e107inc/e107.git
synced 2025-08-01 04:10:38 +02:00
Menu Manager drag and drop work and menu Conversion to $pref routines complete.
This commit is contained in:
@@ -332,8 +332,9 @@ if($_SERVER['E_DEV_MENU'] == 'true')
|
|||||||
if($_SERVER['E_DEV_MENU'] != 'true')
|
if($_SERVER['E_DEV_MENU'] != 'true')
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$p = e107::getPref('e_menu_list'); // new storage for xxxxx_menu.php list.
|
$p = e107::getPref('e_menu_list'); // new storage for xxxxx_menu.php list.
|
||||||
$sql = e107::getDb();
|
$sql = e107::getDb();
|
||||||
@@ -359,7 +360,7 @@ if($_SERVER['E_DEV_MENU'] == 'true')
|
|||||||
$defaults = array(
|
$defaults = array(
|
||||||
'name' => $menu,
|
'name' => $menu,
|
||||||
'path' => $folder,
|
'path' => $folder,
|
||||||
'class' => 0
|
'class' => '0'
|
||||||
);
|
);
|
||||||
|
|
||||||
$text .= e_layout::renderMenuOptions($defaults,'layout','area',$c);
|
$text .= e_layout::renderMenuOptions($defaults,'layout','area',$c);
|
||||||
@@ -407,41 +408,34 @@ if($_SERVER['E_DEV_MENU'] == 'true')
|
|||||||
class e_layout
|
class e_layout
|
||||||
{
|
{
|
||||||
private $menuData = array();
|
private $menuData = array();
|
||||||
|
private $iframe = false;
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
$pref = e107::getPref();
|
$pref = e107::getPref();
|
||||||
$ns = e107::getRender();
|
$ns = e107::getRender();
|
||||||
$this->convertMenuTable();
|
// $this->convertMenuTable();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$this->menuData = e107::getPref('menu_layouts');
|
||||||
|
|
||||||
|
|
||||||
if(e_AJAX_REQUEST)
|
if(e_AJAX_REQUEST)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(varset($_POST['data']))
|
if(varset($_POST['data']))
|
||||||
{
|
{
|
||||||
$_SESSION['menuData'] = $_POST['data'];
|
$this->processPost();
|
||||||
|
|
||||||
$cnf = e107::getConfig('core');
|
|
||||||
$existing = $cnf->get('menu_layouts');
|
|
||||||
// print_r($existing);
|
|
||||||
// $data = array_merge($existing,$_POST['data']);
|
|
||||||
$data = $_POST['data'];
|
|
||||||
print_r($data);
|
|
||||||
|
|
||||||
e107::getConfig('core')->set('menu_layouts', $data)->save();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(vartrue($_GET['configure'])) //ie Inside the IFRAME.
|
if(vartrue($_GET['configure'])) //ie Inside the IFRAME.
|
||||||
{
|
{
|
||||||
@@ -453,6 +447,28 @@ class e_layout
|
|||||||
e107::js('inline','
|
e107::js('inline','
|
||||||
$(function()
|
$(function()
|
||||||
{
|
{
|
||||||
|
// post the form back to this script.
|
||||||
|
var saveData = function(areaid)
|
||||||
|
{
|
||||||
|
|
||||||
|
var formid = "#form-" + areaid;
|
||||||
|
var form = $(formid);
|
||||||
|
var data = form.serialize();
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: "menus.php",
|
||||||
|
data: data
|
||||||
|
}).done(function( msg )
|
||||||
|
{
|
||||||
|
// alert("POSTED: "+ msg );
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$(".sortable").sortable({
|
$(".sortable").sortable({
|
||||||
|
|
||||||
@@ -463,19 +479,7 @@ class e_layout
|
|||||||
update: function(ev,ui)
|
update: function(ev,ui)
|
||||||
{
|
{
|
||||||
var areaid = $(this).attr("id");
|
var areaid = $(this).attr("id");
|
||||||
var formid = "#form-" + areaid;
|
saveData(areaid);
|
||||||
var form = $(formid);
|
|
||||||
var data = form.serialize();
|
|
||||||
|
|
||||||
$.ajax({
|
|
||||||
type: "POST",
|
|
||||||
url: "menus.php",
|
|
||||||
data: data
|
|
||||||
|
|
||||||
}).done(function( msg )
|
|
||||||
{
|
|
||||||
alert("POSTED: "+ msg );
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -493,7 +497,7 @@ class e_layout
|
|||||||
$( ".draggable", window.top.document).draggable({
|
$( ".draggable", window.top.document).draggable({
|
||||||
connectToSortable: ".sortable",
|
connectToSortable: ".sortable",
|
||||||
helper: "clone",
|
helper: "clone",
|
||||||
appendTo: ".sortable", // "#area-1",
|
appendTo: ".sortable", // "#area-1", //FIXME Needs to be a specific area.
|
||||||
revert: true,
|
revert: true,
|
||||||
|
|
||||||
cursor: "move",
|
cursor: "move",
|
||||||
@@ -501,14 +505,27 @@ class e_layout
|
|||||||
containment: false,
|
containment: false,
|
||||||
stop: function(e, ui) { //TODO Rename layout and area in the hidden fields to that of the where the menu was dropped.
|
stop: function(e, ui) { //TODO Rename layout and area in the hidden fields to that of the where the menu was dropped.
|
||||||
// Figure out positioning magic to determine if e.ui.position is in the iframe
|
// Figure out positioning magic to determine if e.ui.position is in the iframe
|
||||||
var what = $(this).parent().attr("id");
|
// var what = $(this).parent().attr("id");
|
||||||
|
|
||||||
alert(what);
|
// alert(what);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// $( "ul, li", window.top.document ).disableSelection();
|
// $( "ul, li", window.top.document ).disableSelection();
|
||||||
|
|
||||||
|
|
||||||
|
$( ".deleteMenu").on("click", function()
|
||||||
|
{
|
||||||
|
var deleteId = $(this).attr("data-delete");
|
||||||
|
var area = $(this).attr("data-area");
|
||||||
|
$("#"+deleteId).hide("slow");
|
||||||
|
$("#"+deleteId).remove();
|
||||||
|
// alert(deleteId + " " + area);
|
||||||
|
saveData(area);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -586,39 +603,38 @@ class e_layout
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert from e107_menu table to $pref format.
|
|
||||||
*/
|
|
||||||
function convertMenuTable()
|
|
||||||
{
|
|
||||||
if(isset($_SESSION['menuData']))
|
|
||||||
{
|
|
||||||
$this->menuData = $_SESSION['menuData'];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$sql = e107::getDb();
|
|
||||||
$sql->select('menus','*','menu_location !=0 ORDER BY menu_location,menu_order');
|
|
||||||
$data = array();
|
|
||||||
|
|
||||||
while($row = $sql->fetch())
|
protected function processPost()
|
||||||
|
{
|
||||||
|
$cnf = e107::getConfig('core');
|
||||||
|
$existing = $cnf->get('menu_layouts');
|
||||||
|
|
||||||
|
// print_r($existing);
|
||||||
|
// $data = array_merge($existing,$_POST['data']);
|
||||||
|
|
||||||
|
$data = $_POST['data'];
|
||||||
|
|
||||||
|
$layout = $_POST['layout'];
|
||||||
|
$area = $_POST['area'];
|
||||||
|
|
||||||
|
$save = array();
|
||||||
|
foreach($_POST['data']['layout']['area'] as $v) // reset key values.
|
||||||
{
|
{
|
||||||
$layout = vartrue($row['menu_layout'],'default');
|
$save[$layout][$area][] = $v;
|
||||||
$location = $row['menu_location'];
|
|
||||||
$data[$layout][$location][] = array('name'=>$row['menu_name'],'class'=>$row['menu_class'],'path'=>$row['menu_path'],'pages'=>$row['menu_pages'],'parms'=>$row['menu_parms']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->menuData = ($data);
|
// $save[$layout][$area] = $_POST['data']['layout']['area'];
|
||||||
|
|
||||||
// print_a($this->menuData);
|
print_r($save);
|
||||||
|
// return;
|
||||||
|
|
||||||
|
|
||||||
|
e107::getConfig('core')->set('menu_layouts', $save)->save(); //TODO Save directly into multi-dimensional array. ie. $layout / $area / array.
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Substitute all {MENU=X} and Render output.
|
* Substitute all {MENU=X} and Render output.
|
||||||
@@ -670,11 +686,20 @@ class e_layout
|
|||||||
|
|
||||||
$text .= "</ul>";
|
$text .= "</ul>";
|
||||||
}
|
}
|
||||||
|
else // Empty Menu.
|
||||||
|
{
|
||||||
|
$text .= "<ul id='area-".$area."' class='sortable unstyled'>
|
||||||
|
<li> </li>
|
||||||
|
</ul>";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$text .= "</div>";
|
$text .= "</div>";
|
||||||
|
|
||||||
// $text .= $frm->button('submit','submit','submit','submit');
|
// $text .= $frm->button('submit','submit','submit','submit');
|
||||||
|
|
||||||
|
$text .= $frm->hidden('layout',THEME_LAYOUT);
|
||||||
|
$text .= $frm->hidden('area',$area);
|
||||||
$text .= $frm->close();
|
$text .= $frm->close();
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
@@ -686,7 +711,7 @@ class e_layout
|
|||||||
private function renderMenu($row, $layout, $area, $count)
|
private function renderMenu($row, $layout, $area, $count)
|
||||||
{
|
{
|
||||||
// return print_a($row,true);
|
// return print_a($row,true);
|
||||||
$TEMPLATE = '<li class="regularMenu" id="'.$row['name'].'"> '.$this->renderMenuOptions($row, $layout, $area,$count).' </li>
|
$TEMPLATE = '<li class="regularMenu" id="'.$row['name'].'_'.$count.'"> '.$this->renderMenuOptions($row, $layout, $area,$count).' </li>
|
||||||
'; // TODO perhaps a simple counter for the id
|
'; // TODO perhaps a simple counter for the id
|
||||||
|
|
||||||
return $TEMPLATE;
|
return $TEMPLATE;
|
||||||
@@ -707,20 +732,28 @@ class e_layout
|
|||||||
$frm = e107::getForm();
|
$frm = e107::getForm();
|
||||||
|
|
||||||
$text = str_replace("_menu","",$row['name']);
|
$text = str_replace("_menu","",$row['name']);
|
||||||
|
// $layout = 'layout';
|
||||||
|
// $area = 'area';
|
||||||
|
|
||||||
//TODO Delete, Config etc.
|
//TODO Delete, Config etc.
|
||||||
|
|
||||||
//$data[$layout][$location][] = array('name'=>$row['menu_name'],'class'=>$row['menu_class'],'path'=>$row['menu_path'],'pages'=>$row['menu_pages'],'parms'=>$row['menu_parms']);
|
//$data[$layout][$location][] = array('name'=>$row['menu_name'],'class'=>$row['menu_class'],'path'=>$row['menu_path'],'pages'=>$row['menu_pages'],'parms'=>$row['menu_parms']);
|
||||||
// $area = 'area_'.$area;
|
// $area = 'area_'.$area;
|
||||||
|
|
||||||
$text .= $frm->hidden('data['.$layout.']['.$area.']['.$c.'][name]',$row['name'] );
|
// 'layout' and 'area' will later be substituted.
|
||||||
$text .= $frm->hidden('data['.$layout.']['.$area.']['.$c.'][class]',$row['class'] );
|
$text .= $frm->hidden('data[layout][area]['.$c.'][name]',$row['name'] );
|
||||||
$text .= $frm->hidden('data['.$layout.']['.$area.']['.$c.'][path]',$row['path'] );
|
$text .= $frm->hidden('data[layout][area]['.$c.'][class]',$row['class'] );
|
||||||
$text .= $frm->hidden('data['.$layout.']['.$area.']['.$c.'][pages]',$row['pages'] );
|
$text .= $frm->hidden('data[layout][area]['.$c.'][path]',$row['path'] );
|
||||||
$text .= $frm->hidden('data['.$layout.']['.$area.']['.$c.'][parms]',$row['parms'] );
|
$text .= $frm->hidden('data[layout][area]['.$c.'][pages]',$row['pages'] );
|
||||||
|
$text .= $frm->hidden('data[layout][area]['.$c.'][parms]',$row['parms'] );
|
||||||
|
|
||||||
|
|
||||||
|
if(vartrue($_GET['configure'])) // Iframe Mode.
|
||||||
|
{
|
||||||
|
$text .= "<a href='#' class='menu-btn btn-mini menu-btn-danger deleteMenu pull-right' data-area='area-".$area."' data-delete='".$row['name']."_".$c."'>×</a>"; // $('.hello').remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -742,7 +775,7 @@ class e_layout
|
|||||||
{
|
{
|
||||||
$path = trim(str_replace(e_PLUGIN,"",$file['path']),"/");
|
$path = trim(str_replace(e_PLUGIN,"",$file['path']),"/");
|
||||||
|
|
||||||
if(e107::isInstalled($path))
|
// if(e107::isInstalled($path) )
|
||||||
{
|
{
|
||||||
$fname = str_replace(".php","",$file['fname']);
|
$fname = str_replace(".php","",$file['fname']);
|
||||||
$data[$fname] = $path;
|
$data[$fname] = $path;
|
||||||
|
@@ -63,45 +63,24 @@ class e_menu
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$menu_layout_field = THEME_LAYOUT!=e107::getPref('sitetheme_deflayout') ? THEME_LAYOUT : "";
|
|
||||||
|
|
||||||
// e107::getCache()->CachePageMD5 = md5(e_LANGUAGE.$menu_layout_field); // Disabled by line 93 of Cache class.
|
|
||||||
//FIXME add a function to the cache class for this.
|
|
||||||
|
|
||||||
$menu_data = e107::getCache()->retrieve_sys("menus_".USERCLASS_LIST."_".md5(e_LANGUAGE.$menu_layout_field));
|
|
||||||
// $menu_data = e107::getCache()->retrieve_sys("menus_".USERCLASS_LIST);
|
|
||||||
$menu_data = e107::getArrayStorage()->ReadArray($menu_data);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// print_a($eMenuArea);
|
||||||
|
if($_SERVER['E_DEV_MENU'] == 'true')
|
||||||
$eMenuArea = array();
|
{
|
||||||
// $eMenuList = array();
|
$layouts = e107::getPref('menu_layouts');
|
||||||
// $eMenuActive = array(); // DEPRECATED
|
if(!is_array($layouts))
|
||||||
if(!is_array($menu_data))
|
|
||||||
{
|
{
|
||||||
$menu_qry = 'SELECT * FROM #menus WHERE menu_location > 0 AND menu_class IN ('.USERCLASS_LIST.') AND menu_layout = "'.$menu_layout_field.'" ORDER BY menu_location,menu_order';
|
$converted = $this->convertMenuTable();
|
||||||
if(e107::getDb()->db_Select_gen($menu_qry))
|
e107::getConfig('core')->set('menu_layouts', $converted)->save();
|
||||||
{
|
|
||||||
while($row = e107::getDb()->db_Fetch())
|
|
||||||
{
|
|
||||||
$eMenuArea[$row['menu_location']][] = $row;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$menu_data['menu_area'] = $eMenuArea;
|
|
||||||
$menuData = e107::getArrayStorage()->WriteArray($menu_data, false);
|
|
||||||
// e107::getCache()->set_sys('menus_'.USERCLASS_LIST, $menuData);
|
|
||||||
e107::getCache()->set_sys('menus_'.USERCLASS_LIST.'_'.md5(e_LANGUAGE.$menu_layout_field), $menuData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$eMenuArea = $menu_data['menu_area'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$eMenuArea = $this->getData(THEME_LAYOUT);
|
||||||
|
}
|
||||||
|
//print_a($eMenuArea);
|
||||||
|
//$eMenuArea = $this->getDataLegacy();
|
||||||
|
|
||||||
// print_a($eMenuArea);
|
// print_a($eMenuArea);
|
||||||
// $eMenuArea = $this->getData(THEME_LAYOUT);
|
|
||||||
|
|
||||||
|
|
||||||
$total = array();
|
$total = array();
|
||||||
foreach($eMenuArea as $area => $val)
|
foreach($eMenuArea as $area => $val)
|
||||||
@@ -128,7 +107,25 @@ class e_menu
|
|||||||
e107::getRender()->eMenuTotal = $total;
|
e107::getRender()->eMenuTotal = $total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert from v1.x e107_menu table to v2.x $pref format.
|
||||||
|
*/
|
||||||
|
function convertMenuTable()
|
||||||
|
{
|
||||||
|
$sql = e107::getDb();
|
||||||
|
|
||||||
|
$sql->select('menus','*','menu_location !=0 ORDER BY menu_location,menu_order');
|
||||||
|
$data = array();
|
||||||
|
|
||||||
|
while($row = $sql->fetch())
|
||||||
|
{
|
||||||
|
$layout = vartrue($row['menu_layout'],'default');
|
||||||
|
$location = $row['menu_location'];
|
||||||
|
$data[$layout][$location][] = array('name'=>$row['menu_name'],'class'=>$row['menu_class'],'path'=>$row['menu_path'],'pages'=>$row['menu_pages'],'parms'=>$row['menu_parms']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -143,7 +140,7 @@ class e_menu
|
|||||||
|
|
||||||
foreach($pref[$layout] as $area=>$v);
|
foreach($pref[$layout] as $area=>$v);
|
||||||
{
|
{
|
||||||
$c = 0;
|
$c = 1;
|
||||||
|
|
||||||
foreach($v as $val)
|
foreach($v as $val)
|
||||||
{
|
{
|
||||||
@@ -155,7 +152,7 @@ class e_menu
|
|||||||
}
|
}
|
||||||
|
|
||||||
$ret[$area][] = array(
|
$ret[$area][] = array(
|
||||||
|
'menu_id' => $c,
|
||||||
'menu_name' => $val['name'],
|
'menu_name' => $val['name'],
|
||||||
'menu_location' => $area,
|
'menu_location' => $area,
|
||||||
'menu_class' => $class,
|
'menu_class' => $class,
|
||||||
@@ -179,6 +176,57 @@ class e_menu
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @DEPRECATED
|
||||||
|
* Legacy Function to retrieve Menu data from tables. - ie. the old v1.x method.
|
||||||
|
*/
|
||||||
|
private function getDataLegacy()
|
||||||
|
{
|
||||||
|
$sql = e107::getDb();
|
||||||
|
$menu_layout_field = THEME_LAYOUT!=e107::getPref('sitetheme_deflayout') ? THEME_LAYOUT : "";
|
||||||
|
|
||||||
|
// e107::getCache()->CachePageMD5 = md5(e_LANGUAGE.$menu_layout_field); // Disabled by line 93 of Cache class.
|
||||||
|
//FIXME add a function to the cache class for this.
|
||||||
|
|
||||||
|
$menu_data = e107::getCache()->retrieve_sys("menus_".USERCLASS_LIST."_".md5(e_LANGUAGE.$menu_layout_field));
|
||||||
|
// $menu_data = e107::getCache()->retrieve_sys("menus_".USERCLASS_LIST);
|
||||||
|
$menu_data = e107::getArrayStorage()->ReadArray($menu_data);
|
||||||
|
|
||||||
|
$eMenuArea = array();
|
||||||
|
// $eMenuList = array();
|
||||||
|
// $eMenuActive = array(); // DEPRECATED
|
||||||
|
|
||||||
|
|
||||||
|
if(!is_array($menu_data))
|
||||||
|
{
|
||||||
|
$menu_qry = 'SELECT * FROM #menus WHERE menu_location > 0 AND menu_class IN ('.USERCLASS_LIST.') AND menu_layout = "'.$menu_layout_field.'" ORDER BY menu_location,menu_order';
|
||||||
|
|
||||||
|
if($sql->gen($menu_qry))
|
||||||
|
{
|
||||||
|
while($row = $sql->fetch())
|
||||||
|
{
|
||||||
|
$eMenuArea[$row['menu_location']][] = $row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$menu_data['menu_area'] = $eMenuArea;
|
||||||
|
|
||||||
|
$menuData = e107::getArrayStorage()->WriteArray($menu_data, false);
|
||||||
|
|
||||||
|
// e107::getCache()->set_sys('menus_'.USERCLASS_LIST, $menuData);
|
||||||
|
e107::getCache()->set_sys('menus_'.USERCLASS_LIST.'_'.md5(e_LANGUAGE.$menu_layout_field), $menuData);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$eMenuArea = $menu_data['menu_area'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return $eMenuArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user