Skip to content

Commit

Permalink
Megamenu: Support ACL in for module in Megamenu
Browse files Browse the repository at this point in the history
  • Loading branch information
joomlart committed Oct 17, 2013
1 parent 2146742 commit 6692aed
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 17 deletions.
38 changes: 36 additions & 2 deletions source/plg_system_t3/admin/megamenu/js/megamenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,44 @@ var T3AdminMegamenu = window.T3AdminMegamenu || {};
url: T3AdminMegamenu.site,
data: {
t3action: 'module',
mid: value
mid: value,
styleid: T3AdminMegamenu.styleid,
template: T3AdminMegamenu.template,

t3menu: $('#menu-type').val(),
t3acl: $('#access-level').val(),
t3lang: $('#menu-type :selected').attr('data-language') || '*'
}
}).done(function ( data ) {
currentSelected.find('.mega-inner').html(data).find(':input').removeAttr('name');
if(data){
if(data.charAt(0) == '{' || data.charAt(0) == '['){
try {
data = $.parseJSON(data);
} catch(e){
data = false;
}

if(data && data.message){
clearTimeout($('#ajax-message').data('sid'));
$('#ajax-message')
.removeClass('alert-error alert-success')
.addClass('alert-error')
.addClass('in')
.data('sid', setTimeout(function(){
$('#ajax-message').removeClass('in')
}, 5000))
.find('strong')
.html(data.message);
}

//not valid value => we set to empty
$(input).val('').trigger('liszt:updated');
currentSelected.data (name, '');

} else {
currentSelected.find('.mega-inner').html(data).find(':input').removeAttr('name');
}
}
});
} else {
currentSelected.find('.mega-inner').html('');
Expand Down
42 changes: 32 additions & 10 deletions source/plg_system_t3/includes/core/action.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,35 +178,57 @@ public static function megamenu() {
}

public static function module () {
$input = JFactory::getApplication()->input;
$id = $input->getInt ('mid');
$user = JFactory::getUser();
$input = JFactory::getApplication()->input;
$id = $input->getInt('mid');
$t3acl = (int)$input->get('t3acl', 1);
$groups = $user->getAuthorisedViewLevels();
$module = null;
$buffer = null;

array_push($groups, $t3acl);

if (is_array($groups) && in_array(3, $groups)) {
//we assume, if a user is special, they should be registered also
$groups[] = 2;
}

if ($id) {
// load module
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('m.id, m.title, m.module, m.position, m.content, m.showtitle, m.params')
$query
->select('m.id, m.title, m.module, m.position, m.content, m.showtitle, m.params')
->from('#__modules AS m')
->where('m.id = '.$id)
->where('m.published = 1');
->where('m.published = 1')
->where('m.access IN ('.implode(',', array_unique($groups)).')');
$db->setQuery($query);
$module = $db->loadObject ();
$module = $db->loadObject();
}

if (!empty ($module)) {
$style = $input->getCmd ('style', 'T3Xhtml');
$style = $input->getCmd ('style', 'T3Xhtml');
$buffer = JModuleHelper::renderModule($module, array('style'=>$style));

// replace relative images url
$base = JURI::base(true).'/';
$base = JURI::base(true).'/';
$protocols = '[a-zA-Z0-9]+:'; //To check for all unknown protocals (a protocol must contain at least one alpahnumeric fillowed by :
$regex = '#(src)="(?!/|' . $protocols . '|\#|\')([^"]*)"#m';
$buffer = preg_replace($regex, "$1=\"$base\$2\"", $buffer);
}

//remove invisibile content, there are more ... but ...
$buffer = preg_replace(array( '@<style[^>]*?>.*?</style>@siu', '@<script[^>]*?.*?</script>@siu'), array('', ''), $buffer);
if($buffer){
//remove invisibile content, there are more ... but ...
$buffer = preg_replace(array( '@<style[^>]*?>.*?</style>@siu', '@<script[^>]*?.*?</script>@siu'), array('', ''), $buffer);

echo $buffer;
echo $buffer;
} else {
die(json_encode(array(
'message' => JText::_('T3_MSG_MODULE_NOT_AVAIL')
)));
}

}

//translate param name to new name, from jvalue => to desired param name
Expand Down
14 changes: 9 additions & 5 deletions source/plg_system_t3/includes/menu/megamenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class T3MenuMegamenu {
/**
* Internal variables
*/
protected $children = array();
protected $_items = array();
protected $children = array();
protected $settings = null;
protected $params = null;
protected $menu = '';
Expand All @@ -43,6 +43,8 @@ function __construct($menutype = 'mainmenu', $settings = array(), $params = null
if(isset($settings['access'])){
$attributes[] = 'access';
$values[] = $settings['access'];
} else {
$settings['access'] = array(1);
}

if(isset($settings['language'])){
Expand Down Expand Up @@ -310,10 +312,12 @@ function module($module) {
$id = intval($module);
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('m.id, m.title, m.module, m.position, m.content, m.showtitle, m.params');
$query->from('#__modules AS m');
$query->where('m.id = ' . $id);
$query->where('m.published = 1');
$query
->select('m.id, m.title, m.module, m.position, m.content, m.showtitle, m.params')
->from('#__modules AS m')
->where('m.id = ' . $id)
->where('m.published = 1')
->where('m.access IN ('.implode(',', $this->settings['access']).')');
$db->setQuery($query);
$module = $db->loadObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,4 @@ T3_MSG_FILE_NOT_WRITABLE ="File system Not writable. Please check again server
T3_MSG_PACKAGE_DAMAGED ="The framework has not been installed correctly"
T3_MSG_DEVFOLDER_NOT_WRITABLE ="Cannot create css cached file in development folder: %s"
T3_MSG_LESS_NOT_VALID ="Template Less structure was not compatible with T3 compiler"
T3_MSG_MODULE_NOT_AVAIL ="This module might not available with current Access Level"

0 comments on commit 6692aed

Please sign in to comment.