mirror of
https://github.com/e107inc/e107.git
synced 2025-04-20 20:51:53 +02:00
Simplified inAdminDir().
This commit is contained in:
parent
f93ce247fd
commit
6ed9ad3e0d
@ -4863,31 +4863,40 @@ class e107
|
||||
|
||||
/**
|
||||
* Internal Use Only.
|
||||
* @param $e107Path
|
||||
* @param $curPage
|
||||
* @param $isPluginDir
|
||||
* @param string $e107Path
|
||||
* @param string $curPage
|
||||
* @param bool $isPluginDir
|
||||
* @return bool
|
||||
*/
|
||||
public function inAdminDir($e107Path, $curPage, $isPluginDir)
|
||||
{
|
||||
$inAdminDir = false;
|
||||
$eplug_admin = !empty($GLOBALS['eplug_admin']);
|
||||
$ADMIN_DIRECTORY = ADMINDIR;
|
||||
|
||||
if (
|
||||
(!$isPluginDir && strpos($e107Path, $ADMIN_DIRECTORY) === 0 ) // Core admin directory
|
||||
|| ($isPluginDir && (strpos($curPage,'_admin.php') !== false || strpos($curPage,'admin_') === 0 || strpos($e107Path, 'admin/') !== FALSE)) // Plugin admin file or directory
|
||||
|| (vartrue($eplug_admin) || deftrue('ADMIN_AREA')) // Admin forced
|
||||
// || (preg_match('/^\/(.*?)\/user(settings\.php|\/edit)(\?|\/)(\d+)$/i', $_SERVER['REQUEST_URI']) && ADMIN)
|
||||
|| ($isPluginDir && $curPage === 'prefs.php') //BC Fix for old plugins
|
||||
|| ($isPluginDir && $curPage === 'config.php') // BC Fix for old plugins
|
||||
|| ($isPluginDir && strpos($curPage,'_config.php')!==false) // BC Fix for old plugins eg. dtree_menu
|
||||
)
|
||||
if($eplug_admin || deftrue('ADMIN_AREA'))
|
||||
{
|
||||
$inAdminDir = TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(strpos($e107Path, ADMINDIR) === 0) // core admin.
|
||||
{
|
||||
$inAdminDir = true;
|
||||
}
|
||||
elseif($isPluginDir) // plugin admin areas
|
||||
{
|
||||
if($curPage === 'prefs.php' || $curPage === 'config.php' || strpos($curPage,'admin_') === 0)
|
||||
{
|
||||
$inAdminDir = true;
|
||||
}
|
||||
elseif(strpos($e107Path, 'admin/') !== false || strpos($curPage, '_admin.php') !==false || strpos($curPage, '_config.php') !==false)
|
||||
{
|
||||
$inAdminDir = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $inAdminDir;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -960,21 +960,24 @@ class e107Test extends \Codeception\Test\Unit
|
||||
4 => array('path' => 'e107_plugins/forum/forum.php', 'plugdir' => true, 'expected' => false),
|
||||
5 => array('path' => 'e107_plugins/vstore/admin_config.php', 'plugdir' => true, 'expected' => true),
|
||||
6 => array('path' => 'e107_plugins/login_menu/config.php', 'plugdir' => true, 'expected' => true),
|
||||
7 => array('path' => 'e107_plugins/aplugin/prefs.php', 'plugdir' => true, 'expected' => true),
|
||||
7 => array('path' => 'e107_plugins/myplugin/prefs.php', 'plugdir' => true, 'expected' => true),
|
||||
8 => array('path' => 'e107_plugins/dtree_menu/dtree_config.php', 'plugdir' => true, 'expected' => true),
|
||||
9 => array('path' => 'e107_plugins/myplugin/admin/something.php', 'plugdir' => true, 'expected' => true),
|
||||
10 => array('path' => 'e107_plugins/myplugin/bla_admin.php', 'plugdir' => true, 'expected' => true),
|
||||
11 => array('path' => 'e107_plugins/myplugin/admin_xxx.php', 'plugdir' => true, 'expected' => true),
|
||||
);
|
||||
|
||||
foreach($tests as $var)
|
||||
foreach($tests as $index=>$var)
|
||||
{
|
||||
$curPage = basename($var['path']);
|
||||
$result = $this->e107->inAdminDir($var['path'], $curPage, $var['plugdir']);
|
||||
$this->assertSame($var['expected'], $result);
|
||||
$this->assertSame($var['expected'], $result, "Failed on index #".$index);
|
||||
}
|
||||
|
||||
// Test legacy override.
|
||||
$GLOBALS['eplug_admin'] = true;
|
||||
$result = $this->e107->inAdminDir('myplugin.php','myplugin.php', true);
|
||||
$this->assertTrue($result);
|
||||
$this->assertTrue($result, "Legacy Override Failed");
|
||||
|
||||
// Test legacy off.
|
||||
$GLOBALS['eplug_admin'] = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user