"\$[Printable View]\n",
# 'history' => "\$[Page History]\n",
# 'edit' => "\$[Edit Page]\n",
# 'upload' => "\$[Upload]\n",
# 'attr' => "\$[Attributes]\n") );
#$CmsLikeMenuSep = ' ';
#$CmsLikeAltMenuItems = $CmsLikeMenuItems;
#$CmsLikeAltMenuSep = ' - ';
include_once('cookbook/cmslike.php'); # the module itself (you need this line at least !)
* in your template:
* add somewhere before the first actions menu
* put $CmsLikeMenuFmt (and $CmsLikeAltMenuFmt if used) wherever you want to insert the
dynamic actions menus
Notes:
* UserAuth interception is used for calling CmsLikeMakeActionsList when the group is
known, so as to establish the relevant rights. The conditions reproduce UserAuth ones.
* in the template is used to evaluate $CmsLikeMenuItems
after the variables in it have been defined.
* You can use $CmsLikeAltMenuItems and $CmsLikeAltMenuSep to make an alternate menu layout, so you
can have 2 different layouts in the same page (ex: a vertical one and an horizontal one like those
in PmWiki default template)
*/
define(CMSLIKE_VERSION, '0.1');
# You can override those in your local/config.php
SDV($CmsLikeMenuItems, array(
'print' => "\$[Printable View]\n",
'history' => "\$[Page History]\n",
'edit' => "\$[Edit Page]\n",
'upload' => "\$[Upload]\n",
'attr' => "\$[Attributes]\n") );
SDV($CmsLikeMenuSep, ' ');
# Alternate menu layout, so you can have 2 different menu layouts in your page
SDV($CmsLikeAltMenuItems, $CmsLikeMenuItems);
SDV($CmsLikeAltMenuSep, ' - ');
# Intercept AuthFunction calls
$AuthFunction = "CmsLikeAuth";
$CmsLikeActionsList = array('print');
$CmsLikeActionsListDone = 0;
function CmsLikeAuth($pagename,$level,$authprompt) {
global $CmsLikeActionsListDone;
# We build the list on the first AuthFunction call only
if (!$CmsLikeActionsListDone) { CmsLikeMakeActionsList($pagename); $CmsLikeActionsListDone = 1; }
# Redirect to the real UserAuth function
return UserAuth($pagename,$level,$authprompt);
}
function CmsLikeMakeActionsList($pagename) {
global $GuestUsername, $LoggedInUsername, $UserInfoObj, $LinkPageCreateFmt, $CmsLikeActionsList;
# Disables the create links in the text
$no_create_link_fmt = "\$LinkText?";
if (isset($UserInfoObj)) {
$username = $_SESSION['username'];
if ($username=="") $username = $GuestUsername;
$group = FmtPageName('$Group',$pagename);
# Auth processing is identical to UserAuth one
if ( $UserInfoObj->UserHasAbility($username, 'admin') )
array_push($CmsLikeActionsList, 'history', 'edit', 'upload', 'attr');
else {
$userauth_level = CmsLikeUserAuthLevel('edit', $group);
if ( $UserInfoObj->UserHasAbility($username, $userauth_level)
|| $UserInfoObj->UserHasAbility($GuestUsername, $userauth_level)
|| $UserInfoObj->UserHasAbility($LoggedInUsername, $userauth_level)
|| $UserInfoObj->UserHasAbility($username, 'edit_all') )
array_push($CmsLikeActionsList, 'history', 'edit');
else $LinkPageCreateFmt = $no_create_link_fmt;
$userauth_level = CmsLikeUserAuthLevel('upload', $group);
if ( $UserInfoObj->UserHasAbility($username, $userauth_level)
|| $UserInfoObj->UserHasAbility($GuestUsername, $userauth_level)
|| $UserInfoObj->UserHasAbility($LoggedInUsername, $userauth_level)
|| $UserInfoObj->UserHasAbility($username, 'upload_all') )
array_push($CmsLikeActionsList, 'upload');
$userauth_level = CmsLikeUserAuthLevel('attr', $group);
if ( $UserInfoObj->UserHasAbility($username, $userauth_level)
|| $UserInfoObj->UserHasAbility($GuestUsername, $userauth_level)
|| $UserInfoObj->UserHasAbility($LoggedInUsername, $userauth_level)
|| $UserInfoObj->UserHasAbility($username, 'attr_all') )
array_push($CmsLikeActionsList, 'attr');
}
}
else $LinkPageCreateFmt = $no_create_link_fmt;
}
function CmsLikeUserAuthLevel($level,$group) {
global $UserInfoObj;
# Change checked level if group specific abilities exist user info object
$group_specific_level = $level."_group-".$group;
if( $UserInfoObj->AnyUserHasAbility($group_specific_level) ) return $group_specific_level;
else return $level;
}
function CmsLikeMakeMenuFmt() {
global $CmsLikeActionsList, $CmsLikeMenuItems, $CmsLikeMenuSep, $CmsLikeMenuFmt,
$CmsLikeAltMenuItems, $CmsLikeAltMenuSep, $CmsLikeAltMenuFmt;
$items_fmt = array();
$alt_items_fmt = array();
foreach($CmsLikeActionsList as $action) {
array_push($items_fmt, $CmsLikeMenuItems[$action]);
array_push($alt_items_fmt, $CmsLikeAltMenuItems[$action]);
}
$CmsLikeMenuFmt = implode($CmsLikeMenuSep, $items_fmt);
$CmsLikeAltMenuFmt = implode($CmsLikeAltMenuSep, $alt_items_fmt);
}
?>