xoops forums

mjoel

Quite a regular
Posted on: 2016/7/1 9:00
mjoel
mjoel (Show more)
Quite a regular
Posts: 271
Since: 2006/12/9
#1

how to protect single custom page ?

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");

vamptrix

Theme Designer
Posted on: 2016/7/1 10:03
vamptrix
vamptrix (Show more)
Theme Designer
Posts: 424
Since: 2008/5/3 1
#2

Re: how to protect single custom page ?

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

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

Mamba

Moderator
Posted on: 2016/7/1 12:30
Mamba
Mamba (Show more)
Moderator
Posts: 10652
Since: 2004/4/23
#3

Re: how to protect single custom page ?

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.5.9 | Docs | Modules | Bugs

vamptrix

Theme Designer
Posted on: 2016/7/1 13:46
vamptrix
vamptrix (Show more)
Theme Designer
Posts: 424
Since: 2008/5/3 1
#4

Re: how to protect single custom page ?

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.

Mamba

Moderator
Posted on: 2016/7/1 14:52
Mamba
Mamba (Show more)
Moderator
Posts: 10652
Since: 2004/4/23
#5

Re: how to protect single custom page ?

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.5.9 | Docs | Modules | Bugs

vamptrix

Theme Designer
Posted on: 2016/7/4 5:56
vamptrix
vamptrix (Show more)
Theme Designer
Posts: 424
Since: 2008/5/3 1
#6

Re: how to protect single custom page ?

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.

zyspec

Module Developer
Posted on: 2016/7/4 17:04
zyspec
zyspec (Show more)
Module Developer
Posts: 1027
Since: 2004/9/21
#7

Re: how to protect single custom page ?

@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...

mjoel

Quite a regular
Posted on: 2016/7/5 0:08
mjoel
mjoel (Show more)
Quite a regular
Posts: 271
Since: 2006/12/9
#8

Re: how to protect single custom page ?

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
}

mjoel

Quite a regular
Posted on: 2016/7/5 0:23
mjoel
mjoel (Show more)
Quite a regular
Posts: 271
Since: 2006/12/9
#9

Re: how to protect single custom page ?

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");  
?>