diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Plugins/Helper.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Plugins/Helper.php index bfc33cfde..474123b29 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Plugins/Helper.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Plugins/Helper.php @@ -14,11 +14,14 @@ class Helper /** * @param string $sString * @param string $sWildcardValues + * @param string $sFoundedValue = '' * * @return bool */ - static public function ValidateWildcardValues($sString, $sWildcardValues) + static public function ValidateWildcardValues($sString, $sWildcardValues, &$sFoundedValue = '') { + $sFoundedValue = ''; + $sString = \trim($sString); if ('' === $sString) { @@ -26,11 +29,17 @@ class Helper } $sWildcardValues = \trim($sWildcardValues); - if ('' === $sWildcardValues || '*' === $sWildcardValues) + if ('' === $sWildcardValues) { return true; } + if ('*' === $sWildcardValues) + { + $sFoundedValue = '*'; + return true; + } + $sWildcardValues = \preg_replace('/[*]+/', '*', \preg_replace('/[\s,;]+/', ' ', $sWildcardValues)); $aWildcardValues = \explode(' ', $sWildcardValues); @@ -40,6 +49,7 @@ class Helper { if ($sString === $sItem) { + $sFoundedValue = $sItem; return true; } } @@ -52,6 +62,7 @@ class Helper if (\preg_match('/'.\implode('.*', $aItem).'/', $sString)) { + $sFoundedValue = $sItem; return true; } } diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Domain.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Domain.php index ffca1e35e..438807164 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Domain.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Domain.php @@ -37,12 +37,11 @@ class Domain extends \RainLoop\Providers\AbstractProvider * @param string $sName * @param bool $bDefaultOnNull = false * - * @return \RainLoop\Domain | null + * @return \RainLoop\Domain|null */ public function Load($sName, $bDefaultOnNull = false) { - $oDomain = $this->oDriver->Load($sName); - return $oDomain ? $oDomain : ($bDefaultOnNull ? $this->oDriver->Load('default') : null); + return $this->oDriver->Load($sName, $bDefaultOnNull); } /** diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Domain/DefaultDomain.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Domain/DefaultDomain.php index 396c7194c..d11213dd2 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Domain/DefaultDomain.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Domain/DefaultDomain.php @@ -16,7 +16,28 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface */ public function __construct($sDomainPath) { - $this->sDomainPath = rtrim(trim($sDomainPath), '\\/'); + $this->sDomainPath = \rtrim(\trim($sDomainPath), '\\/'); + } + + /** + * @param string $sName + * @param bool $bBack = false + * + * @return string + */ + public function codeFileName($sName, $bBack = false) + { + if ($bBack && 'default' === $sName) + { + return '*'; + } + else if (!$bBack && '*' === $sName) + { + return 'default'; + } + + $sName = \strtolower($sName); + return $bBack ? \str_replace('_wildcard_', '*', $sName) : \str_replace('*', '_wildcard_', $sName); } /** @@ -28,16 +49,16 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface public function Disable($sName, $bDisable) { $sFile = ''; - if (file_exists($this->sDomainPath.'/disabled')) + if (\file_exists($this->sDomainPath.'/disabled')) { - $sFile = @file_get_contents($this->sDomainPath.'/disabled'); + $sFile = @\file_get_contents($this->sDomainPath.'/disabled'); } $aResult = array(); - $aNames = explode(',', $sFile); + $aNames = \explode(',', $sFile); if ($bDisable) { - array_push($aNames, $sName); + \array_push($aNames, $sName); $aResult = $aNames; } else @@ -51,36 +72,71 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface } } - $aResult = array_unique($aResult); - return false !== file_put_contents($this->sDomainPath.'/disabled', trim(implode(',', $aResult), ', ')); + $aResult = \array_unique($aResult); + return false !== \file_put_contents($this->sDomainPath.'/disabled', \trim(\implode(',', $aResult), ', ')); } /** * @param string $sName + * @param bool $bFindWithWildCard = false * * @return \RainLoop\Domain | null */ - public function Load($sName) + public function Load($sName, $bFindWithWildCard = false) { $mResult = null; - $sName = strtolower($sName); - if (file_exists($this->sDomainPath.'/'.$sName.'.ini')) + $sName = \strtolower($sName); + $sRealFileName = $this->codeFileName($sName); + if (\file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini')) { $mResult = \RainLoop\Domain::NewInstanceFromDomainConfigArray( - $sName, @parse_ini_file($this->sDomainPath.'/'.$sName.'.ini')); + $sName, @\parse_ini_file($this->sDomainPath.'/'.$sRealFileName.'.ini')); if ($mResult instanceof \RainLoop\Domain) { - if (file_exists($this->sDomainPath.'/disabled')) + if (\file_exists($this->sDomainPath.'/disabled')) { - $sDisabled = @file_get_contents($this->sDomainPath.'/disabled'); - if (false !== $sDisabled && 0 < strlen($sDisabled)) + $sDisabled = @\file_get_contents($this->sDomainPath.'/disabled'); + if (false !== $sDisabled && 0 < \strlen($sDisabled)) { - $mResult->SetDisabled(false !== strpos(strtolower(','.$sDisabled.','), strtolower(','.$sName.','))); + $mResult->SetDisabled(false !== \strpos(strtolower(','.$sDisabled.','), \strtolower(','.$sName.','))); } } } } + else if ($bFindWithWildCard) + { + // TODO +// $sNames = ''; +// $aNames = array(); +// +// $aList = \glob($this->sDomainPath.'/*.ini'); +// foreach ($aList as $sFile) +// { +// $sName = \strtolower(\substr(\basename($sFile), 0, -4)); +// if ('default' === $sName || false !== strpos($sName, '_wildcard_')) +// { +// $aNames[] = $this->codeFileName($sName, true); +// } +// } +// +// if (0 < \count($aNames)) +// { +// \rsort($sNames, SORT_STRING); +// $sNames = \implode(' ', $aNames); +// } +// +// if (0 < \strlen($sNames)) +// { +// $sFoundedValue = ''; +// if (\RainLoop\Plugins\Helper::ValidateWildcardValues($sName, $sNames, $sFoundedValue) && 0 < \strlen($sFoundedValue)) +// { +// $mResult = $this->Load($sFoundedValue, false); +// } +// } + + $mResult = $this->Load('default', false); + } return $mResult; } @@ -92,8 +148,11 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface */ public function Save(\RainLoop\Domain $oDomain) { - $mResult = file_put_contents($this->sDomainPath.'/'.strtolower($oDomain->Name()).'.ini', $oDomain->ToIniString()); - return is_int($mResult) && 0 < $mResult; + $sName = \strtolower($oDomain->Name()); + $sRealFileName = $this->codeFileName($sName); + + $mResult = \file_put_contents($this->sDomainPath.'/'.$sRealFileName.'.ini', $oDomain->ToIniString()); + return \is_int($mResult) && 0 < $mResult; } /** @@ -104,10 +163,17 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface public function Delete($sName) { $bResult = true; - $sName = strtolower($sName); - if (0 < strlen($sName) && file_exists($this->sDomainPath.'/'.$sName.'.ini')) + $sName = \strtolower($sName); + $sRealFileName = $this->codeFileName($sName); + + if (0 < \strlen($sName) && \file_exists($this->sDomainPath.'/'.$sRealFileName.'.ini')) { - $bResult = unlink($this->sDomainPath.'/'.$sName.'.ini'); + $bResult = \unlink($this->sDomainPath.'/'.$sRealFileName.'.ini'); + } + + if ($bResult) + { + $this->Disable($sName, false); } return $bResult; @@ -116,45 +182,54 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface /** * @param int $iOffset * @param int $iLimit = 20 - * @param string $sSearch = '' * * @return array */ - public function GetList($iOffset, $iLimit = 20, $sSearch = '') + public function GetList($iOffset, $iLimit = 20) { $aResult = array(); - $aList = glob($this->sDomainPath.'/*.ini'); + $aWildCards = array(); + $aList = \glob($this->sDomainPath.'/*.ini'); - $sSearch = strtolower($sSearch); foreach ($aList as $sFile) { - $sName = strtolower(substr(basename($sFile), 0, -4)); - if (0 === strlen($sSearch) || false !== strpos($sName, $sSearch)) + $sName = \strtolower(\substr(\basename($sFile), 0, -4)); + $sName = $this->codeFileName($sName, true); + if (false === \strpos($sName, '*')) { $aResult[] = $sName; } + else + { + $aWildCards[] = $sName; + } } + \sort($aResult, SORT_STRING); + \rsort($aWildCards, SORT_STRING); + + $aResult = \array_merge($aResult, $aWildCards); + $iOffset = (0 > $iOffset) ? 0 : $iOffset; $iLimit = (0 > $iLimit) ? 0 : ((999 < $iLimit) ? 999 : $iLimit); - $aResult = array_slice($aResult, $iOffset, $iLimit); + $aResult = \array_slice($aResult, $iOffset, $iLimit); $aDisabledNames = array(); - if (0 < count($aResult) && file_exists($this->sDomainPath.'/disabled')) + if (0 < \count($aResult) && \file_exists($this->sDomainPath.'/disabled')) { - $sDisabled = @file_get_contents($this->sDomainPath.'/disabled'); + $sDisabled = @\file_get_contents($this->sDomainPath.'/disabled'); if (false !== $sDisabled && 0 < strlen($sDisabled)) { - $aDisabledNames = explode(',', strtolower($sDisabled)); - $aDisabledNames = array_unique($aDisabledNames); + $aDisabledNames = \explode(',', strtolower($sDisabled)); + $aDisabledNames = \array_unique($aDisabledNames); } } $aReturn = array(); foreach ($aResult as $sName) { - $aReturn[$sName] = !in_array(strtolower($sName), $aDisabledNames); + $aReturn[$sName] = !\in_array(\strtolower($sName), $aDisabledNames); } return $aReturn; @@ -165,8 +240,8 @@ class DefaultDomain implements \RainLoop\Providers\Domain\DomainAdminInterface * * @return int */ - public function Count($sSearch = '') + public function Count() { - return count($this->GetList(0, 999, $sSearch)); + return \count($this->GetList(0, 999)); } } \ No newline at end of file diff --git a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Domain/DomainAdminInterface.php b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Domain/DomainAdminInterface.php index e15f6ee57..39e26d5a2 100644 --- a/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Domain/DomainAdminInterface.php +++ b/rainloop/v/0.0.0/app/libraries/RainLoop/Providers/Domain/DomainAdminInterface.php @@ -37,16 +37,13 @@ interface DomainAdminInterface extends DomainInterface /** * @param int $iOffset * @param int $iLimit = 20 - * @param string $sSearch = '' * * @return array */ - public function GetList($iOffset, $iLimit = 20, $sSearch = ''); + public function GetList($iOffset, $iLimit = 20); /** - * @param string $sSearch = '' - * * @return int */ - public function Count($sSearch = ''); + public function Count(); } \ No newline at end of file