mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Add helper class for plugins
This commit is contained in:
parent
16b375691b
commit
0618eb7ca2
1 changed files with 62 additions and 0 deletions
62
rainloop/v/0.0.0/app/libraries/RainLoop/Plugins/Helper.php
Normal file
62
rainloop/v/0.0.0/app/libraries/RainLoop/Plugins/Helper.php
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace RainLoop\Plugins;
|
||||||
|
|
||||||
|
class Helper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function __construct()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sString
|
||||||
|
* @param string $sWildcardValues
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
static public function ValidateWildcardValues($sString, $sWildcardValues)
|
||||||
|
{
|
||||||
|
$sString = \trim($sString);
|
||||||
|
if ('' === $sString)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sWildcardValues = \trim($sWildcardValues);
|
||||||
|
if ('' === $sWildcardValues || '*' === $sWildcardValues)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sWildcardValues = \preg_replace('/[*]+/', '*', \preg_replace('/[\s,;]+/', ' ', $sWildcardValues));
|
||||||
|
$aWildcardValues = \explode(' ', $sWildcardValues);
|
||||||
|
|
||||||
|
foreach ($aWildcardValues as $sItem)
|
||||||
|
{
|
||||||
|
if (false === \strpos($sItem, '*'))
|
||||||
|
{
|
||||||
|
if ($sString === $sItem)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$aItem = \explode('*', $sItem);
|
||||||
|
$aItem = \array_map(function ($sItem) {
|
||||||
|
return \preg_quote($sItem, '/');
|
||||||
|
}, $aItem);
|
||||||
|
|
||||||
|
if (\preg_match('/'.\implode('.*', $aItem).'/', $sString))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue