1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-01 20:30:39 +02:00

e_menu.php introduced to replace legacy menu configuration file (config.php). See banner plugin for an example.

This commit is contained in:
Cameron
2016-01-12 15:44:54 -08:00
parent 5a6153db27
commit d0fccd540f
12 changed files with 277 additions and 155 deletions

View File

@@ -53,6 +53,12 @@ e107::coreLan('footer', true);
// Get Icon constants, theme override (theme/templates/admin_icons_template.php) is allowed
include_once(e107::coreTemplatePath('admin_icons'));
if(!empty($_GET['iframe']))
{
define('e_IFRAME', true);
}
if(!defset('e_ADMIN_UI') && !defset('e_PAGETITLE'))
{

View File

@@ -59,14 +59,47 @@ if(strpos(e_QUERY, 'configure') !== FALSE || vartrue($_GET['enc']))
e107::js('core','bootstrap/js/bootstrap-tooltip.js');
// e107::css('core','bootstrap/css/bootstrap.min.css');
$JSMODAL = <<<TEMPL
$(function() {
$('.e-modal-menumanager').on('click', function(e)
{
e.preventDefault();
if($(this).attr('data-cache') == 'false')
{
window.parent.$('#uiModal').on('shown.bs.modal', function () {
$(this).removeData('bs.modal');
});
}
var url = $(this).attr('href');
var caption = $(this).attr('data-modal-caption');
var height = 600;
if(caption === undefined)
{
caption = '';
}
window.parent.$('.modal-body').html('<div class="well"><iframe id="e-modal-iframe" width="100%" height="'+height+'px" frameborder="0" scrolling="auto" style="display:block;background-color:transparent" allowtransparency="true" src="' + url + '"></iframe></div>');
window.parent.$('.modal-caption').html(caption + ' <i id="e-modal-loading" class="fa fa-spin fa-spinner"></i>');
window.parent.$('.modal').modal('show');
window.parent.$("#e-modal-iframe").on("load", function () {
window.parent.$('#e-modal-loading').hide();
});
});
});
TEMPL;
e107::js('inline', $JSMODAL );
e107::js('inline', "
$(function() {
// Visibility Options
// Visibility/Instance Options etc.
$('.e-menumanager-option').on('click', function(){
@@ -81,7 +114,7 @@ if(strpos(e_QUERY, 'configure') !== FALSE || vartrue($_GET['enc']))
var data = window.parent.$('#e-save-form').serialize();
// alert(data);
// alert(target);
$.post(target, data ,function(ret)
{
// alert('Posted: '+ret);
@@ -139,6 +172,11 @@ if(strpos(e_QUERY, 'configure') !== FALSE || vartrue($_GET['enc']))
});
");
@@ -905,11 +943,9 @@ class e_layout
}
/*
function menuSaveAjax($mode = null)
{
//print_r($_POST);
// return;
if($mode == 'visibility')
{
@@ -922,8 +958,10 @@ class e_layout
if($mode == 'parms')
{
$ret = $this->menuSaveParameters();
// echo json_encode($ret);
// echo "hi there";
$ret = array('msg'=>'hi there','error'=>true);
// $ret = $this->menuSaveParameters();
echo json_encode($ret);
return;
}
@@ -934,7 +972,7 @@ class e_layout
}
*/
/**
* Scan Plugin folders for new _menu files.
*/
@@ -1071,7 +1109,9 @@ class e_layout
/**
* This one will be greatly extended, allowing menus to offer UI and us
* settings per instance later ($parm variable available for menus - same as shortcode's $parm)
* @see menuInstanceParameters() in menumanager_class.php
*/
/*
private function renderInstanceParameters()
{
if(!vartrue($_GET['parmsId'])) return;
@@ -1093,20 +1133,20 @@ class e_layout
<table class='table adminform'>
<tr>
<td>
".MENLAN_45."
".$frm->text('menu_parms', $row['menu_parms'], 900, 'class=e-save span7')."
".MENLAN_45."</td><td>
".$frm->text('menu_parms', $row['menu_parms'], 900, 'class=e-save ')."
</td>
</tr>
</table>";
/*
$text .= "
<div class='buttons-bar center'>";
$text .= $frm->admin_button('parms_submit', LAN_SAVE, 'update');
$text .= "<input type='hidden' name='menu_id' value='".$id."' />
</div>";
*/
// $text .= "
// <div class='buttons-bar center'>";
// $text .= $frm->admin_button('parms_submit', LAN_SAVE, 'update');
// $text .= "<input type='hidden' name='menu_id' value='".$id."' />
// </div>";
$text .= $frm->hidden('mode','parms');
$text .= $frm->hidden('menu_id',$id);
$text .= "
@@ -1117,6 +1157,7 @@ class e_layout
return $text;
}
*/
/**
* Render the main area with TABS and iframes.

View File

@@ -127,9 +127,9 @@ class pluginmanager_form extends e_form
{
$text .= ($this->plug['plugin_installflag'] ? "<a class='btn btn-default' href=\"".e_SELF."?uninstall.{$this->plug['plugin_id']}\" title='".EPL_ADLAN_1."' >".ADMIN_UNINSTALLPLUGIN_ICON."</a>" : "<a class='btn' href=\"".e_SELF."?install.{$this->plug['plugin_id']}\" title='".EPL_ADLAN_0."' >".ADMIN_INSTALLPLUGIN_ICON."</a>");
// $text .= ($this->plug['plugin_installflag'] ? "<button type='button' class='delete' value='no-value' onclick=\"location.href='".e_SELF."?uninstall.{$this->plug['plugin_id']}'\"><span>".EPL_ADLAN_1."</span></button>" : "<button type='button' class='update' value='no-value' onclick=\"location.href='".e_SELF."?install.{$this->plug['plugin_id']}'\"><span>".EPL_ADLAN_0."</span></button>");
if (PLUGIN_SHOW_REFRESH && !vartrue($this->plug_vars['plugin_php']))
if (e_DEBUG && !vartrue($this->plug_vars['plugin_php']))
{
$text .= "<br /><br /><input type='button' class='btn btn-default button' onclick=\"location.href='".e_SELF."?refresh.{$this->plug['plugin_id']}'\" title='".'Refresh plugin settings'."' value='".'Refresh plugin settings'."' /> ";
// $text .= "<br /><br /><input type='button' class='btn btn-default button' onclick=\"location.href='".e_SELF."?refresh.{$this->plug['plugin_id']}'\" title='".'Refresh plugin settings'."' value='".'Refresh plugin settings'."' /> ";
}
}
else
@@ -162,6 +162,13 @@ class pluginmanager_form extends e_form
$text .= "<a class='btn btn-default' href='".e_SELF."?upgrade.{$this->plug['plugin_id']}' title=\"".EPL_UPGRADE." to v".$this->plug_vars['@attributes']['version']."\" >".ADMIN_UPGRADEPLUGIN_ICON."</a>";
}
if ($this->plug['plugin_installflag'] && e_DEBUG == true)
{
$text .= "<a class='btn btn-default' href='".e_SELF."?refresh.".$this->plug['plugin_id']."' title='".'Repair plugin settings'."'> ".ADMIN_REPAIRPLUGIN_ICON."</a>";
}
$text .="</div> ";
return $text;
@@ -1068,12 +1075,13 @@ class pluginManager{
{
global $plug;
$plug = $plugin->getinfo($this->id);
$plug = e107::getSingleton('e107plugin')->getinfo($this->id);
$_path = e_PLUGIN.$plug['plugin_path'].'/';
if(file_exists($_path.'plugin.xml'))
{
$text .= $plugin->install_plugin_xml($this->id, 'refresh');
// $text .= $plugin->install_plugin_xml($this->id, 'refresh');
e107::getSingleton('e107plugin')->refresh($plug['plugin_path']);
e107::getLog()->add('PLUGMAN_04', $this->id.':'.$plug['plugin_path'], E_LOG_INFORMATIVE, '');
}

View File

@@ -450,12 +450,13 @@ define("E_32_TRUE", "<i class='S32 e-true-32'></i>");
define("ADMIN_ADD_ICON", "<i class='S32 e-add-32'></i>");
define("ADMIN_INFO_ICON", "<i class='S16 e-info-16'></i>");
define("ADMIN_CONFIGURE_ICON", "<i class='S32 e-configure-32'></i>");
define("ADMIN_CONFIGURE_ICON", "<i class='S32 e-settings-32'></i>");
define("ADMIN_VIEW_ICON", "<i class='S32 e-search-32'></i>");
define("ADMIN_URL_ICON", "<i class='S16 e-forums-16'></i>");
define("ADMIN_INSTALLPLUGIN_ICON", "<i class='S32 e-plugin_install-32'></i>");
define("ADMIN_UNINSTALLPLUGIN_ICON", "<i class='S32 e-plugin_uninstall-32'></i>");
define("ADMIN_UPGRADEPLUGIN_ICON", "<i class='S32 e-up-32'></i>");
define("ADMIN_REPAIRPLUGIN_ICON", "<i class='S32 e-configure-32'></i>");
define("ADMIN_UP_ICON", "<i class='S32 e-up-32'></i>");
define("ADMIN_DOWN_ICON", "<i class='S32 e-down-32'></i>");
define("ADMIN_SORT_ICON", "<i class='S32 e-sort-32'></i>");

View File

@@ -1847,7 +1847,15 @@ class e107
if(true === $className) $className = $pluginName.'_'.substr($addonName, 2); // remove 'e_'
$elist = self::getPref($filename.'_list');
if($filename == 'e_menu')
{
if(!in_array($pluginName, $elist)) return null;
}
else
{
if(!isset($elist[$pluginName])) return null;
}
// TODO override check comes here
$path = e_PLUGIN.$pluginName.'/'.$filename.'.php';

View File

@@ -1379,6 +1379,10 @@ class e_form
{
parse_str($options, $options);
}
elseif(is_array($options))
{
// do nothing.
}
else // Assume it's a label.
{
$options = array('label'=>$options);

View File

@@ -216,7 +216,7 @@ class e_menuManager {
}
$file = urldecode($_GET['path']).".php";
$newurl = e_PLUGIN_ABS.$file."?id=".$_GET['id'];
$newurl = e_PLUGIN_ABS.$file."?id=".$_GET['id'].'&iframe=1';
/*
@@ -365,6 +365,8 @@ class e_menuManager {
$efile = new e_file;
$efile->dirFilter = array('/', 'CVS', '.svn', 'languages');
$efile->fileFilter[] = '^e_menu\.php$';
$fileList = $efile->get_files(e_PLUGIN,"_menu\.php$",'standard',2);
$this->menuAddMessage('Scanning for new menus', E_MESSAGE_DEBUG);
@@ -539,19 +541,54 @@ class e_menuManager {
};
$row = $sql->fetch();
// TODO lan
$text = "<div style='text-align:center;'>
<form id='e-save-form' method='post' action='".e_SELF."?lay=".$this->curLayout."'>
<fieldset id='core-menus-parametersform'>
<legend>Menu parameters ".$row['menu_name']."</legend>
<table class='table adminform'>
<tr>
<legend>".MENLAN_44." ".$row['menu_name']."</legend>
<table class='table '>
<colgroup>
<col class='col-label' />
<col class='col-control' />
</colgroup>
";
if(file_exists(e_PLUGIN.$row['menu_path']."e_menu.php")) // v2.x new e_menu.php
{
$plug = rtrim($row['menu_path'],'/');
$obj = e107::getAddon($plug,'e_menu');
$fields = e107::callMethod($obj,'config');
if(!$form = e107::getAddon($plug,'e_menu',$plug."_menu_form"))
{
$form = $frm;
}
$value = e107::unserialize($row['menu_parms']);
foreach($fields as $k=>$v)
{
$text .= "<tr><td class='text-left'>".$v['title']."</td>";
$v['writeParms']['class'] = 'e-save';
$text .= "<td class='text-left'>".$form->renderElement($k, $value[$k], $v)."</td></tr>";
}
}
else
{
$text .= "<tr>
<td>
Parameters (query string format):
".$frm->text('menu_parms', $row['menu_parms'], 900, 'class=e-save span7')."
".MENLAN_45."</td>
<td>
".$frm->text('menu_parms', $row['menu_parms'], 900, 'class=e-save&size=xxlarge')."
</td>
</tr>
</table>";
</tr>";
}
$text .= "</table>";
/*
$text .= "
@@ -784,10 +821,26 @@ class e_menuManager {
function menuSaveParameters()
{
$sql = e107::getDb();
$id = intval($_POST['menu_id']);
if(isset($_POST['menu_parms']))
{
$parms = $sql->escape(strip_tags($_POST['menu_parms']));
}
else
{
unset($_POST['menu_id'], $_POST['mode'], $_POST['menuActivate'], $_POST['menuSetCustomPages']);
$check = $sql->db_Update("menus", "menu_parms='".$parms."' WHERE menu_id=".intval($_POST['menu_id'])."");
$parms = $sql->escape(e107::serialize($_POST));
if(e_DEBUG == true)
{
// return array('msg'=>print_r($_POST,true),'error'=>true);
}
}
$check = $sql->update("menus", "menu_parms='".$parms."' WHERE menu_id=".$id."");
if($check)
{
@@ -812,7 +865,7 @@ class e_menuManager {
function menuSaveVisibility() // Used by Ajax
{
global $admin_log;
$sql = e107::getDb();
$pagelist = explode("\r\n", $_POST['pagelist']);
@@ -825,7 +878,7 @@ class e_menuManager {
$pageparms = preg_replace("#\|$#", "", $pageparms);
$pageparms = (trim($_POST['pagelist']) == '') ? '' : $pageparms;
if($sql->db_Update("menus", "menu_class='".intval($_POST['menu_class'])."', menu_pages='{$pageparms}' WHERE menu_id=".intval($_POST['menu_id'])))
if($sql->update("menus", "menu_class='".intval($_POST['menu_class'])."', menu_pages='{$pageparms}' WHERE menu_id=".intval($_POST['menu_id'])))
{
e107::getLog()->add('MENU_02',$_POST['menu_class'].'[!br!]'.$pageparms.'[!br!]'.$this->menuId,E_LOG_INFORMATIVE,'');
@@ -1502,7 +1555,7 @@ class e_menuManager {
if($conf)
{
$text .= '<a class="menu-btn" target="_top" href="'.e_SELF.'?lay='.$this->curLayout.'&amp;mode=conf&amp;path='.urlencode($conf).'&amp;id='.$menu_id.'"
$text .= '<a data-modal-caption="Configure Menu" class="e-modal-menumanager menu-btn" target="_top" href="'.e_SELF.'?lay='.$this->curLayout.'&amp;mode=conf&amp;path='.urlencode($conf).'&amp;id='.$menu_id.'&iframe=1"
title="Configure menu"><i class="S16 e-configure-16"></i></a>';
}
@@ -1574,7 +1627,10 @@ class e_menuManager {
if($mode == 'parms')
{
$ret = $this->menuSaveParameters();
// echo json_encode($ret);
if(!empty($ret['error']))
{
echo json_encode($ret);
}
return;
}

View File

@@ -39,6 +39,7 @@ class e107plugin
'e_frontpage',
'e_latest', // @Deprecated - see e_dashboard
'e_status', //@Deprecated - see e_dashboard
'e_menu', // experimental.
'e_search',
'e_shortcode',
'e_module',

View File

@@ -237,6 +237,10 @@ class banner_ui extends e_admin_ui
public function menuPage()
{
return e107::getMessage()->addInfo("The menu is now configured within the menu-manager.")->render();
$ns = e107::getRender();
$sql = e107::getDb();
$menu_pref = e107::getConfig('menu')->getPref('');

View File

@@ -22,18 +22,18 @@ if (!defined('e107_INIT')) { exit; }
if(file_exists(THEME.'templates/banner/banner_template.php')) // v2.x location.
{
require_once (THEME.'templates/banner/banner_template.php');
require(THEME.'templates/banner/banner_template.php'); // don't use require_once as we might use this menu in more than 1 location.
}
elseif(file_exists(THEME.'banner_template.php')) // v1.x location.
{
require_once (THEME.'banner_template.php');
require(THEME.'banner_template.php');
}
else
{
require_once (e_PLUGIN.'banner/banner_template.php');
require(e_PLUGIN.'banner/banner_template.php');
}
$menu_pref = e107::getConfig('menu')->getPref('');
$menu_pref = e107::getConfig('menu')->getPref(''); // legacy preference lookup.
if(defset('BOOTSTRAP'))
{
@@ -50,70 +50,24 @@ else
if(!empty($parm))
{
parse_str($parm, $parms);
if(!$tmp = e107::unserialize($parm)) // unserailize the v2.x e_menu.php preferences.
{
parse_str($parm, $parms); // if it fails, use legacy method. (query string format)
}
else // prefs unserialized so overwrite the legacy preference values.
{
$menu_pref = $tmp;
$menu_pref['banner_campaign'] = implode("|",$menu_pref['banner_campaign']);
unset($parm);
}
}
if(isset($parms['w']) && isset($parms['h']))
if(isset($parms['w']) && isset($parms['h'])) // TODO.
{
e107::getParser()->setThumbSize(intval($parms['w']), intval($parms['h']));
}
/*
if(isset($menu_pref['banner_campaign']) && $menu_pref['banner_campaign'])
{
$parms = array();
if(strstr($menu_pref['banner_campaign'], "|"))
{
$campaignlist = explode('|', $menu_pref['banner_campaign']);
$amount = ($menu_pref['banner_amount'] < 1 ? '1' : $menu_pref['banner_amount']);
$amount = ($amount > count($campaignlist) ? count($campaignlist) : $amount);
$keys = array_rand($campaignlist, $amount); // If one entry, returns a single value
if (!is_array($keys))
{
$keys = array($keys);
}
foreach ($keys as $k=>$v)
{
$parms[] = $campaignlist[$v];
}
}
else
{
$parms[] = $menu_pref['banner_campaign'];
}
$txt = e107::getParser()->parseTemplate($BANNER_MENU_START,true);
$sc = e107::getScBatch('banner');
foreach ($parms as $parm)
{
$p = array('banner_campaign'=>$parm);
$sc->setVars($p);
$txt .= e107::getParser()->parseTemplate($BANNER_MENU_ITEM, true, $sc);
// $txt .= e107::getParser()->parseTemplate("{BANNER=".$parm."}",true);
}
$txt .= e107::getParser()->parseTemplate($BANNER_MENU_END,true);
}
*/
// print_a($menu_pref);
if(!empty($menu_pref['banner_campaign']) && !empty($menu_pref['banner_amount']))
@@ -149,11 +103,14 @@ if(!empty($menu_pref['banner_campaign']) && !empty($menu_pref['banner_amount']))
$ret[$cat][] = $tp->simpleParse($BANNER_MENU_ITEM, $var);
}
}
elseif(e_DEBUG == true)
{
echo "no banner data";
}
$foot = e107::getParser()->parseTemplate($BANNER_MENU_END,true);
switch ($menu_pref['banner_rendertype'])
{

View File

@@ -1,35 +0,0 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2013 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* Banner Menu Configuration (OLD - redirects to e107_admin/banner.php)
*
*
*/
/**
* e107 Banner management plugin
*
* Handles the display and sequencing of banners on web pages, including counting impressions
*
* @package e107_plugins
* @subpackage banner
*
* @todo - try and access file for menu config without a redirect
*/
$eplug_admin = TRUE;
require_once("../../class2.php");
/*
* The same, cleaned up code is already part of banner.php
* FIXME - we should be able to combine all core menus in a nice way... somehow
*/
header('Location:'.e_PLUGIN_ABS.'banner/admin_banner.php?menu');
exit;
?>

View File

@@ -0,0 +1,71 @@
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2015 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
*
*/
if (!defined('e107_INIT')) { exit; }
//v2.x Standard for extending menu configuration within Menu Manager. (replacement for v1.x config.php)
class banner_menu
{
function __construct()
{
e107::lan('banner','admin', 'true');
}
/**
* Configuration Fields.
* @return array
*/
public function config()
{
$renderTypes = array(BNRLAN_48,'1 - '.BNRLAN_45,'2 - '.BNRLAN_46, "3 - ".BNRLAN_47);
$fields = array();
$fields['banner_caption'] = array('title'=> BNRLAN_37, 'type'=>'text', 'writeParms'=>array('size'=>'xxlarge'));
$fields['banner_campaign'] = array('title'=> BNRLAN_39, 'type'=>'method');
$fields['banner_amount'] = array('title'=> BNRLAN_41, 'type'=>'text', 'writeParms'=>array('pattern'=>'[0-9]*'));
$fields['banner_rendertype'] = array('title'=> BNRLAN_43, 'type'=>'dropdown', 'writeParms'=>array('optArray'=>$renderTypes));
return $fields;
}
}
// optional
class banner_menu_form extends e_form
{
public function banner_campaign($curVal)
{
$sql = e107::getDb();
$sql->select("banner", "DISTINCT(banner_campaign) as banner_campaign", "ORDER BY banner_campaign", "mode=no_where");
$text = '';
while ($row = $sql -> fetch())
{
$checked = in_array($row['banner_campaign'],$curVal);
$text .= $this->checkbox('banner_campaign[]',$row['banner_campaign'],$checked, array('label'=> $row['banner_campaign'],'class'=>'e-save')); // e-save class is required.
}
return $text;
}
}
?>