From: <lph...@us...> - 2009-08-15 16:59:18
|
Revision: 20851 http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=20851&view=rev Author: lphuberdeau Date: 2009-08-15 16:59:10 +0000 (Sat, 15 Aug 2009) Log Message: ----------- [MOD] Adding a way to make bold assumptions about the input and save 5% execution time when marking all permissions as global Modified Paths: -------------- trunk/lib/core/lib/Perms/Accessor.php trunk/lib/setup/perms.php Modified: trunk/lib/core/lib/Perms/Accessor.php =================================================================== --- trunk/lib/core/lib/Perms/Accessor.php 2009-08-15 16:34:34 UTC (rev 20850) +++ trunk/lib/core/lib/Perms/Accessor.php 2009-08-15 16:59:10 UTC (rev 20851) @@ -59,33 +59,41 @@ if( $this->resolver ) { $name = $this->sanitize( $name ); - if( $this->checkSequence ) { - foreach( $this->checkSequence as $check ) { - if( $check->check( $this->resolver, $this->context, $name, $this->groups ) ) { - return true; - } + return $this->checkPermission( $name ); + } else { + return false; + } + } + + private function checkPermission( $name ) { + if( $this->checkSequence ) { + foreach( $this->checkSequence as $check ) { + if( $check->check( $this->resolver, $this->context, $name, $this->groups ) ) { + return true; } + } - return false; - } else { - return $this->resolver->check( $name, $this->groups ); - } + return false; } else { - return false; + return $this->resolver->check( $name, $this->groups ); } } - function globalize( $permissions ) { + function globalize( $permissions, $sanitize = true ) { foreach( $permissions as $perm ) { - $perm = $this->sanitize( $perm ); - $GLOBALS[ $this->prefix . $perm ] = $this->$perm ? 'y' : 'n'; + if( $sanitize ) { + $perm = $this->sanitize( $perm ); + } + $GLOBALS[ $this->prefix . $perm ] = $this->checkPermission( $perm ) ? 'y' : 'n'; } } - function smartify( $smarty, $permissions ) { + function smartify( $smarty, $permissions, $sanitize = true ) { foreach( $permissions as $perm ) { - $perm = $this->sanitize( $perm ); - $smarty->assign( 'tiki_p_' . $perm, $this->$perm ? 'y' : 'n' ); + if( $sanitize ) { + $perm = $this->sanitize( $perm ); + } + $smarty->assign( 'tiki_p_' . $perm, $this->checkPermission( $perm ) ? 'y' : 'n' ); } } Modified: trunk/lib/setup/perms.php =================================================================== --- trunk/lib/setup/perms.php 2009-08-15 16:34:34 UTC (rev 20850) +++ trunk/lib/setup/perms.php 2009-08-15 16:59:10 UTC (rev 20851) @@ -79,8 +79,14 @@ $globalperms = Perms::get(); } -$globalperms->globalize( $permissionList ); -$globalperms->smartify( $smarty, $permissionList ); +function remove_tiki_p_prefix( $name ) { + return substr( $name, 7 ); +} + +$shortPermList = array_map( 'remove_tiki_p_prefix', $permissionList ); + +$globalperms->globalize( $shortPermList, false ); +$globalperms->smartify( $smarty, $shortPermList, false ); $smarty->assign( 'globalperms', $globalperms ); unset($allperms); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |