1
mjoel
how to protect single custom page ?
  • 2016/7/1 9:00

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


i have a single custom page..how do i protect this page so only admin or certain group can see this page...

include("../../mainfile.php");  
include(
XOOPS_ROOT_PATH."/header.php");  

$meta_keywords = "";  
$meta_description = "";  
$pagetitle = "";  

if(isset(
$xoTheme) && is_object($xoTheme)) {  
    
$xoTheme->addMeta( 'meta', 'keywords', $meta_keywords);  
    
$xoTheme->addMeta( 'meta', 'description', $meta_description);  
} else {    
// Compatibility for old Xoops versions  
    
$xoopsTpl->assign('xoops_meta_keywords', $meta_keywords);  
    
$xoopsTpl->assign('xoops_meta_description', $meta_description);  
}  

$xoopsTpl->assign('xoops_pagetitle', $pagetitle);  

//this will only work if your theme is using this smarty variables  
$xoopsTpl->assign( 'xoops_showlblock', 0); //set to 0 to hide left blocks  
$xoopsTpl->assign( 'xoops_showrblock', 0); //set to 0 to hide right blocks  
$xoopsTpl->assign( 'xoops_showcblock', 1); //set to 0 to hide center blocks  


 


include(XOOPS_ROOT_PATH."/footer.php");

2
vamptrix
Re: how to protect single custom page ?
  • 2016/7/1 10:03

  • vamptrix

  • Theme Designer

  • Posts: 424

  • Since: 2008/5/3 1


That could be done with XMF, if you're using XOOPS 2.5.8.

Take a look at https://xoops.gitbooks.io/xmf-cookbook/content/en/book/recipes/perm-check.html, this should be able to do what you need it to do.

3
Mamba
Re: how to protect single custom page ?
  • 2016/7/1 12:30

  • Mamba

  • Moderator

  • Posts: 11548

  • Since: 2004/4/23


I would just put this page into a module, where I have a full control of permissions.

For example, I could clone a Publisher, add this page as an article, set the permissions to specific groups, and I'm done.
Support XOOPS => DONATE
Use 2.7.x | Docs | Modules | Bugs

4
vamptrix
Re: how to protect single custom page ?
  • 2016/7/1 13:46

  • vamptrix

  • Theme Designer

  • Posts: 424

  • Since: 2008/5/3 1


Quote:

Mamba wrote:
I would just put this page into a module, where I have a full control of permissions.

For example, I could clone a Publisher, add this page as an article, set the permissions to specific groups, and I'm done.

I think that's a bit overkill (in terms of resource usage) for 1 page, but yeah, that does work.

5
Mamba
Re: how to protect single custom page ?
  • 2016/7/1 14:52

  • Mamba

  • Moderator

  • Posts: 11548

  • Since: 2004/4/23


Quote:
I think that's a bit overkill (in terms of resource usage) for 1 page, but yeah, that does work.
One way or the other, you need a module, in order to take advantage of the Permissions (even when using XMF that you've linked to). You can create a new "dummy" module and add the page there, which probably would take you at least 30 minutes, or you can clone an existing module, which would take only 5 minutes, and be done with it.

To be honest, I am less concerned about the resources than about effective use of my own time
Support XOOPS => DONATE
Use 2.7.x | Docs | Modules | Bugs

6
vamptrix
Re: how to protect single custom page ?
  • 2016/7/4 5:56

  • vamptrix

  • Theme Designer

  • Posts: 424

  • Since: 2008/5/3 1


Quote:

Mamba wrote:
Quote:
I think that's a bit overkill (in terms of resource usage) for 1 page, but yeah, that does work.
One way or the other, you need a module, in order to take advantage of the Permissions (even when using XMF that you've linked to). You can create a new "dummy" module and add the page there, which probably would take you at least 30 minutes, or you can clone an existing module, which would take only 5 minutes, and be done with it.

To be honest, I am less concerned about the resources than about effective use of my own time


And I can understand that :). However, we should really make a module for things like this. Once I'll get the hang of it, I'll try to look into this.

7
zyspec
Re: how to protect single custom page ?
  • 2016/7/4 17:04

  • zyspec

  • Module Developer

  • Posts: 1095

  • Since: 2004/9/21


@mjoel,

Since you've included ./mainfile.php you should be able to just add:
(($xoopsUser instanceof XoopsUser) && ($xoopsUser->isAdmin(0))) || exit(_NOPERM);
after:
include("../../mainfile.php");   
include(
XOOPS_ROOT_PATH."/header.php");

although I would change the include("../../mainfile.php") to require_once dirname(dirname(dirname(__DIR__))) . "/mainfile.php";
- but that's not required to make it work. You can do something similar (although a little more complex) for other groups...

8
mjoel
Re: how to protect single custom page ?
  • 2016/7/5 0:08

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


Thank you for all the replies

i found the code below from this old topic



// group 
$groups = 0; 
if (
is_object($xoopsUser)) 
{ 
$groups = $xoopsUser->getGroups(); 
} 
else { 
$groups = array(XOOPS_GROUP_ANONYMOUS); 
} 

switch(
$groups) 
{ 

case (
in_array(1, $groups)): //admin 
echo "admin group"; 


break 
1; 

case (
in_array(2, $groups)): //registered 
echo "registered group"; 


break 
1; 

case (
in_array(3, $groups)): //anonymous 
echo "guest group"; 


break 
1; 

case (
in_array(4, $groups)): //customized 
echo "custom group"; 
break 
1; 
}

9
mjoel
Re: how to protect single custom page ?
  • 2016/7/5 0:23

  • mjoel

  • Quite a regular

  • Posts: 325

  • Since: 2006/12/9


i put this code inside my root and named it as test.php and it works

if i dont want to use any module is this acceptable/ok ?

<?php  

require_once ("mainfile.php");  
include(
XOOPS_ROOT_PATH."/header.php");  

$meta_keywords = "";  
$meta_description = "";  
$pagetitle = "";  

if(isset(
$xoTheme) && is_object($xoTheme)) {  
    
$xoTheme->addMeta( 'meta', 'keywords', $meta_keywords);  
    
$xoTheme->addMeta( 'meta', 'description', $meta_description);  
} else {    
// Compatibility for old Xoops versions  
    
$xoopsTpl->assign('xoops_meta_keywords', $meta_keywords);  
    
$xoopsTpl->assign('xoops_meta_description', $meta_description);  
}  

$xoopsTpl->assign('xoops_pagetitle', $pagetitle);  

//this will only work if your theme is using this smarty variables  
$xoopsTpl->assign( 'xoops_showlblock', 0); //set to 0 to hide left blocks  
$xoopsTpl->assign( 'xoops_showrblock', 0); //set to 0 to hide right blocks  
$xoopsTpl->assign( 'xoops_showcblock', 1); //set to 0 to hide center blocks  
?>  


<?php
// Start Groups Permission 
$groups = 0; 
if (
is_object($xoopsUser)) 
{ 
$groups = $xoopsUser->getGroups(); 
} 
else { 
$groups = array(XOOPS_GROUP_ANONYMOUS); 
} 

switch(
$groups) 
{ 
case (
in_array(1, $groups)): //admin 
{
echo 
"Only admin group member can see this";
}
break 
1; 

case (
in_array(3, $groups)): //anonymous  
 
{
echo 
"guest group"; 
}

break 
1;  


case (
in_array(5, $groups)): // custom group
{
echo 
"Only custom group member can see this";
}
break 
1; 

}
//end Group Permission 
?>


<?php  
include(XOOPS_ROOT_PATH."/footer.php");  
?>