mirror of
https://github.com/e107inc/e107.git
synced 2025-08-02 04:40:44 +02:00
Simplified inAdminDir().
This commit is contained in:
@@ -4863,31 +4863,40 @@ class e107
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal Use Only.
|
* Internal Use Only.
|
||||||
* @param $e107Path
|
* @param string $e107Path
|
||||||
* @param $curPage
|
* @param string $curPage
|
||||||
* @param $isPluginDir
|
* @param bool $isPluginDir
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function inAdminDir($e107Path, $curPage, $isPluginDir)
|
public function inAdminDir($e107Path, $curPage, $isPluginDir)
|
||||||
{
|
{
|
||||||
$inAdminDir = false;
|
$inAdminDir = false;
|
||||||
$eplug_admin = !empty($GLOBALS['eplug_admin']);
|
$eplug_admin = !empty($GLOBALS['eplug_admin']);
|
||||||
$ADMIN_DIRECTORY = ADMINDIR;
|
|
||||||
|
|
||||||
if (
|
if($eplug_admin || deftrue('ADMIN_AREA'))
|
||||||
(!$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
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
$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;
|
return $inAdminDir;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -960,21 +960,24 @@ class e107Test extends \Codeception\Test\Unit
|
|||||||
4 => array('path' => 'e107_plugins/forum/forum.php', 'plugdir' => true, 'expected' => false),
|
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),
|
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),
|
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),
|
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']);
|
$curPage = basename($var['path']);
|
||||||
$result = $this->e107->inAdminDir($var['path'], $curPage, $var['plugdir']);
|
$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.
|
// Test legacy override.
|
||||||
$GLOBALS['eplug_admin'] = true;
|
$GLOBALS['eplug_admin'] = true;
|
||||||
$result = $this->e107->inAdminDir('myplugin.php','myplugin.php', true);
|
$result = $this->e107->inAdminDir('myplugin.php','myplugin.php', true);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result, "Legacy Override Failed");
|
||||||
|
|
||||||
// Test legacy off.
|
// Test legacy off.
|
||||||
$GLOBALS['eplug_admin'] = false;
|
$GLOBALS['eplug_admin'] = false;
|
||||||
|
Reference in New Issue
Block a user