Hack: Hide any module for logged in users ONLY
-
- Joomla! Guru
- Posts: 522
- Joined: Mon Oct 01, 2007 11:35 am
Re: Hack: Hide any module for logged in users ONLY
You could try looking at the javascript triggered by opening a tab, and then see if you can add to that trigger something that will hide the module using JPane. But I think it would be a lot of hassle.
-
- Joomla! Enthusiast
- Posts: 190
- Joined: Sat Jan 14, 2006 1:59 pm
- Location: Sunderland UK
- Contact:
Re: Hack: Hide any module for logged in users ONLY
With great thanks to coolparth
http://forum.joomla.org/viewtopic.php?p ... 9#p1703749
I now have this working perfect,
Thanks
http://forum.joomla.org/viewtopic.php?p ... 9#p1703749
Code: Select all
<?php
$my =& JFactory::getUser();
//Followed by your code..
if($my->id>0){
echo "<jdoc:include type=\"modules\" name=\"right\" headerLevel=\"3\" />";
}else
{
echo "<jdoc:include type=\"modules\" name=\"top\" headerLevel=\"3\" />";
}
?>
Thanks
-
- Joomla! Enthusiast
- Posts: 114
- Joined: Sat Nov 04, 2006 1:39 pm
- Location: Hyderabad, India
- Contact:
Re: Hack: Hide any module for logged in users ONLY
If any of you are still looking for this hack for 1.0.15, for a custom module (type USER), you would have to edit custom.xml. Took me a while to figure it out, and thought it might help someone.
Thanks for the hack.
Thanks for the hack.
-
- Joomla! Guru
- Posts: 643
- Joined: Mon Nov 07, 2005 3:45 am
- Contact:
Re: Hack: Hide any module for logged in users ONLY
anyone get this working for 1.5 AND the hack for only certain users? There's no frontend.php file in 1.5...
- ooffick
- Joomla! Master
- Posts: 11614
- Joined: Thu Jul 17, 2008 3:10 pm
- Location: Ireland
- Contact:
Re: Hack: Hide any module for logged in users ONLY
Hi,
You can use MetaMod to do that.
Olaf
You can use MetaMod to do that.
Olaf
Olaf Offick - Global Moderator
learnskills.org
learnskills.org
-
- Joomla! Guru
- Posts: 643
- Joined: Mon Nov 07, 2005 3:45 am
- Contact:
Re: Hack: Hide any module for logged in users ONLY
and that module will allow me to hide other modules or just that one module?
- ooffick
- Joomla! Master
- Posts: 11614
- Joined: Thu Jul 17, 2008 3:10 pm
- Location: Ireland
- Contact:
Re: Hack: Hide any module for logged in users ONLY
You can show different modules and hide any module which is loaded by that module.
Olaf
Olaf
Olaf Offick - Global Moderator
learnskills.org
learnskills.org
- RustyJoomla
- Joomla! Explorer
- Posts: 409
- Joined: Wed Aug 01, 2007 12:08 am
- Location: UK
- Contact:
Re: Hack: Hide any module for logged in users ONLY
[quote="kevincam"][/quote]
Kevincam,thanks very much for the hack! Works' great!!!
Kevincam,thanks very much for the hack! Works' great!!!
-
- Joomla! Intern
- Posts: 99
- Joined: Sat Mar 25, 2006 1:01 pm
Re: Hack: Hide any module for logged in users ONLY
Hi,
Here is a solution for Joomla 1.5.
1. Download and install Jumi: http://extensions.joomla.org/extensions/1023/details
2. Edit the module you want to hide for regestrated users on your site. In the combo box labelled "Position". Intead of using the drop down list, type in a name of your liking. For example user100.
3. Now you create a new Jumi module.
Settings: no title and choose a position where you want to show your module.
Insert this code to inside "Code written" in the Jumi module.
Here is a solution for Joomla 1.5.
1. Download and install Jumi: http://extensions.joomla.org/extensions/1023/details
2. Edit the module you want to hide for regestrated users on your site. In the combo box labelled "Position". Intead of using the drop down list, type in a name of your liking. For example user100.
3. Now you create a new Jumi module.
Settings: no title and choose a position where you want to show your module.
Insert this code to inside "Code written" in the Jumi module.
Code: Select all
<?php
$position = 'user100';
$user =& JFactory::getUser();
if($user->guest)
{
$document = &JFactory::getDocument();
$renderer = $document->loadRenderer('modules');
$contents = '';
echo $renderer->render($position, array('style'=>'xhtml'));
}
?>
-
- Joomla! Apprentice
- Posts: 13
- Joined: Fri Dec 25, 2009 11:33 pm
- Location: USA, Texas
- Contact:
Re: Hack: Hide any module for logged in users ONLY
Me a lika very much sir! Ita Saves my day!da8iwr wrote:With great thanks to coolparth
http://forum.joomla.org/viewtopic.php?p ... 9#p1703749
I now have this working perfect,Code: Select all
<?php $my =& JFactory::getUser(); //Followed by your code.. if($my->id>0){ echo "<jdoc:include type=\"modules\" name=\"right\" headerLevel=\"3\" />"; }else { echo "<jdoc:include type=\"modules\" name=\"top\" headerLevel=\"3\" />"; } ?>
Thanks
-
- Joomla! Guru
- Posts: 643
- Joined: Mon Nov 07, 2005 3:45 am
- Contact:
Re: Hack: Hide any module for logged in users ONLY
no longer working since 1.5.16 - I tried to redo hack with no luck. Did I do something wrong or are we going to have to find another way to do this?
-
- Joomla! Apprentice
- Posts: 13
- Joined: Fri Dec 25, 2009 11:33 pm
- Location: USA, Texas
- Contact:
Re: Hack: Hide any module for logged in users ONLY
Code: Select all
<?php
$my =& JFactory::getUser();
//Followed by your code..
if($my->id>0){
echo "<jdoc:include type=\"modules\" name=\"right\" headerLevel=\"3\" />";
}else
{
echo "<jdoc:include type=\"modules\" name=\"top\" headerLevel=\"3\" />";
}
?>
-
- Joomla! Guru
- Posts: 643
- Joined: Mon Nov 07, 2005 3:45 am
- Contact:
Re: Hack: Hide any module for logged in users ONLY
where does that code go?jgage wrote:You tried this code? This one worked flawless for me. However, am using 1.5.15 so if this one doesn't work then it would be good to know.Code: Select all
<?php $my =& JFactory::getUser(); //Followed by your code.. if($my->id>0){ echo "<jdoc:include type=\"modules\" name=\"right\" headerLevel=\"3\" />"; }else { echo "<jdoc:include type=\"modules\" name=\"top\" headerLevel=\"3\" />"; } ?>
- ooffick
- Joomla! Master
- Posts: 11614
- Joined: Thu Jul 17, 2008 3:10 pm
- Location: Ireland
- Contact:
Re: Hack: Hide any module for logged in users ONLY
You can add that into your template's index.php file, moreover you can use the metamod module as well.
Olaf
Olaf
Olaf Offick - Global Moderator
learnskills.org
learnskills.org
-
- Joomla! Guru
- Posts: 643
- Joined: Mon Nov 07, 2005 3:45 am
- Contact:
Re: Hack: Hide any module for logged in users ONLY
ok, it actually does still work - I just had to redo it and I messed up first time. This is from kevincam's post on page 3:
Added this after the last parameter of the XML file for whatever module you want to hide for example the login module which is located here (modules\mod_login\mod_login.xml):
Then replace the function render( $position, $params = array(), $content = null ) in \libraries\joomla\document\html\renderer\modules.php with the following
UPDATED: I noticed that modules that use the module count need an additional hack to the file:
\libraries\joomla\application\module\helper.php
after the line $modules = array();
and before the line $db->setQuery( $query );
/*ORIGINAL CODE
$wheremenu = isset( $Itemid ) ? ' AND ( mm.menuid = '. (int) $Itemid .' OR mm.menuid = 0 )' : '';
$query = 'SELECT id, title, module, position, content, showtitle, control, params'
. ' FROM #__modules AS m'
. ' LEFT JOIN #__modules_menu AS mm ON mm.moduleid = m.id'
. ' WHERE m.published = 1'
. ' AND m.access <= '. (int)$aid
. ' AND m.client_id = '. (int)$mainframe->getClientId()
. $wheremenu
. ' ORDER BY position, ordering';
ORIGINAL CODE*/
Added this after the last parameter of the XML file for whatever module you want to hide for example the login module which is located here (modules\mod_login\mod_login.xml):
Code: Select all
<param name="show_registered" type="radio" default="1" label="Show Menu When Logged In" description="Show the menu also when a registered user is logged in">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
Then replace the function render( $position, $params = array(), $content = null ) in \libraries\joomla\document\html\renderer\modules.php with the following
Code: Select all
function render( $position, $params = array(), $content = null )
{
$renderer =& $this->_doc->loadRenderer('module');
$contents = '';
foreach (JModuleHelper::getModules($position) as $mod) {
// HACK: added code to check if module should be shown when a user is logged in
$pattern = '/show_registered=0/';
$match = preg_match($pattern, $mod->params);
$userId = $_SESSION["__default"]['user']->id;
if ($match && $userId) {
// simply continue the loop without outputting this module
continue;
}
// --- end HACK ---
$contents .= $renderer->render($mod, $params, $content);
}
return $contents;
}
\libraries\joomla\application\module\helper.php
after the line $modules = array();
and before the line $db->setQuery( $query );
Code: Select all
//HACK check in logged in then run query to exclude the correct modules
if($userId = $_SESSION["__default"]['user']->id >0){
$wheremenu = isset( $Itemid ) ? ' AND ( mm.menuid = '. (int) $Itemid .' OR mm.menuid = 0 )' : '';
$query = 'SELECT id, title, module, position, content, showtitle, control, params'
. ' FROM #__modules AS m'
. ' LEFT JOIN #__modules_menu AS mm ON mm.moduleid = m.id'
. ' WHERE m.published = 1'
. ' AND m.access <= '. (int)$aid
. ' AND m.client_id = '. (int)$mainframe->getClientId()
. " AND m.id NOT IN (SELECT id FROM #__modules WHERE params LIKE '%show_registered=0%')"
. $wheremenu
. ' ORDER BY position, ordering';
}else{
$wheremenu = isset( $Itemid ) ? ' AND ( mm.menuid = '. (int) $Itemid .' OR mm.menuid = 0 )' : '';
$query = 'SELECT id, title, module, position, content, showtitle, control, params'
. ' FROM #__modules AS m'
. ' LEFT JOIN #__modules_menu AS mm ON mm.moduleid = m.id'
. ' WHERE m.published = 1'
. ' AND m.access <= '. (int)$aid
. ' AND m.client_id = '. (int)$mainframe->getClientId()
. $wheremenu
. ' ORDER BY position, ordering';
}
//HACK
$wheremenu = isset( $Itemid ) ? ' AND ( mm.menuid = '. (int) $Itemid .' OR mm.menuid = 0 )' : '';
$query = 'SELECT id, title, module, position, content, showtitle, control, params'
. ' FROM #__modules AS m'
. ' LEFT JOIN #__modules_menu AS mm ON mm.moduleid = m.id'
. ' WHERE m.published = 1'
. ' AND m.access <= '. (int)$aid
. ' AND m.client_id = '. (int)$mainframe->getClientId()
. $wheremenu
. ' ORDER BY position, ordering';
ORIGINAL CODE*/
-
- Joomla! Apprentice
- Posts: 8
- Joined: Wed Jun 02, 2010 6:32 pm
Re: Hack: Hide any module for logged in users ONLY
Okay, what's the best way to do this in Joomla 1.5.15?
I just want to hide one module. Not the entire position (e.g. top) just the one of multiple modules that appear in that position.
I used MetaMod.
Does anyone know how I can have a different css for logged in user than for non-logged in user?
I just want to hide one module. Not the entire position (e.g. top) just the one of multiple modules that appear in that position.
I used MetaMod.
Does anyone know how I can have a different css for logged in user than for non-logged in user?
Last edited by Josh_D on Fri Jun 04, 2010 11:39 am, edited 1 time in total.
-
- Joomla! Guru
- Posts: 643
- Joined: Mon Nov 07, 2005 3:45 am
- Contact:
Re: Hack: Hide any module for logged in users ONLY
this method is still valid, but a lot of people are using metamod instead. this is the post that explains how to do it in 1.5: http://forum.joomla.org/viewtopic.php?p ... 3#p1323633
-
- Joomla! Apprentice
- Posts: 8
- Joined: Wed Jun 02, 2010 6:32 pm
Re: Hack: Hide any module for logged in users ONLY
Cool, thanks.
I used MetaMod.
Does anyone know how I can have a different css for logged in user than for non-logged in user?
Can that also be done in metamod?
I used MetaMod.
Does anyone know how I can have a different css for logged in user than for non-logged in user?
Can that also be done in metamod?
- Living Legend
- Joomla! Apprentice
- Posts: 22
- Joined: Tue Jun 16, 2009 7:33 pm
- Location: UK
- Contact:
Re: Hack: Hide any module for logged in users ONLY
Ach, spent nearly 3 hours trying to get kevincam's hack to work (kept getting a parse error, unexpected "{" expecting T_FUNCTION on line 54 of the modules.php file) then I come across the post about MetaMod... D'oh! Live & leanr I guess coz it took a fraction of the time to get started with, however I added "if ( MM_LOGGED_IN ) return 17;" to the PHP box hoping it would show the User Menu (in place of the login form) but it doesn't show anything at all once I've logged in.
Also, the mod'd form doesn't show the Open ID links, I tried adding its ID after the login form's one (yeah I'm aware that it's a plugin and not a module, but as of yet I've not been able to find any Open ID modules so I figured it was at least worth a punt ) but it didn't work.
Anyone got an idea how to resolve these?
(fyi for anyone who decides to try it out themselves on my site, I've left the original login form next to the MetaMod'd one to make it easy for myself to compare differences in them )
Also, the mod'd form doesn't show the Open ID links, I tried adding its ID after the login form's one (yeah I'm aware that it's a plugin and not a module, but as of yet I've not been able to find any Open ID modules so I figured it was at least worth a punt ) but it didn't work.
Anyone got an idea how to resolve these?
(fyi for anyone who decides to try it out themselves on my site, I've left the original login form next to the MetaMod'd one to make it easy for myself to compare differences in them )
It's not a signature, it's a dictatorship! :-(
-
- Joomla! Fledgling
- Posts: 2
- Joined: Wed Mar 24, 2010 6:59 am
- Contact:
Re: Hack: Hide any module for logged in users ONLY
Hi,
This is my solution for Joomla 1.5.xx
The hack will allow specific module to be displayed for a specific type of user(/s).
1. Replace render function with code below @ \libraries\joomla\document\html\renderer\modules.php
2. Add the paramaters below to your mod_{module}.xml file
This is my solution for Joomla 1.5.xx
The hack will allow specific module to be displayed for a specific type of user(/s).
1. Replace render function with code below @ \libraries\joomla\document\html\renderer\modules.php
Code: Select all
function render($position, $params = array(), $content = null) {
$renderer = & $this->_doc->loadRenderer('module');
$contents = '';
foreach (JModuleHelper::getModules($position) as $mod) {
// BEGIN HACK
// added function to check if module is allowed to be displayed for a specific user typ
$gId = JFactory::getUser()->gid;
for ($i = 0; $i < 26; $i++) {
if ($i == $gId) {
$pattern = '/show_' . $i . '=0/';
$hidemodule = preg_match($pattern, $mod->params);
}
}
if ($hidemodule) {
// simply continue the loop without outputting this module
continue;
}
// END HACK
$contents .= $renderer->render($mod, $params, $content);
}
return $contents;
}
Code: Select all
<param type="spacer" default="<b>Display Module For...</b>" />
<param name="show_0" type="radio" default="1" label="Public Users" description="Toggle Module Display for specific User Type">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="show_18" type="radio" default="18" label="Registered Users" description="Toggle Module Display for specific User Type">
<option value="0">No</option>
<option value="18">Yes</option>
</param>
<param name="show_19" type="radio" default="1" label="Author Users" description="Toggle Module Display for specific User Type">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="show_20" type="radio" default="1" label="Editor Users" description="Toggle Module Display for specific User Type">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="show_21" type="radio" default="1" label="Publisher Users" description="Toggle Module Display for specific User Type">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="show_23" type="radio" default="1" label="Manager Users" description="Toggle Module Display for specific User Type">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="show_24" type="radio" default="1" label="Administrator Users" description="Toggle Module Display for specific User Type">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
<param name="show_25" type="radio" default="1" label="Super Administrator Users" description="Toggle Module Display for specific User Type">
<option value="0">No</option>
<option value="1">Yes</option>
</param>
You do not have the required permissions to view the files attached to this post.
-
- Joomla! Guru
- Posts: 643
- Joined: Mon Nov 07, 2005 3:45 am
- Contact:
Re: Hack: Hide any module for logged in users ONLY
yajra, that hack does make the module invisible, but it does not remove the module form the structure. In other words, the space for the module is still there. For example, mine is set to show on my front page. When I log in the module is gone, but the left column is empty.
So your hack is not really working as it should. I recommend going back to the hack on page 3.
So your hack is not really working as it should. I recommend going back to the hack on page 3.