diff --git a/plugins/change-password/index.php b/plugins/change-password/index.php index a80b3d916..3251c177c 100644 --- a/plugins/change-password/index.php +++ b/plugins/change-password/index.php @@ -29,21 +29,42 @@ class ChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin protected function getSupportedDrivers(bool $all = false) : iterable { -// foreach (\glob(__DIR__ . '/../change-password-*', GLOB_ONLYDIR) as $file) { - foreach (\glob(__DIR__ . '/drivers/*.php') as $file) { - try - { - $name = \basename($file, '.php'); - if ($all || $this->Config()->Get('plugin', "driver_{$name}_enabled", false)) { - require_once $file; - $class = 'ChangePasswordDriver' . $name; - if ($class::isSupported()) { - yield $name => $class; + if ($phar_file = \Phar::running()) { + $phar = new \Phar($phar_file, \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME); + foreach (new \RecursiveIteratorIterator($phar) as $file) { + if (\preg_match('#/drivers/([a-z]+)\\.php$#Di', $file, $m)) { + try + { + if ($all || $this->Config()->Get('plugin', "driver_{$m[1]}_enabled", false)) { + require_once $file; + $class = 'ChangePasswordDriver' . $m[1]; + if ($class::isSupported()) { + yield $m[1] => $class; + } + } + } + catch (\Throwable $oException) + { } } } - catch (\Throwable $oException) - { + } else { +// foreach (\glob(__DIR__ . '/../change-password-*', GLOB_ONLYDIR) as $file) { + foreach (\glob(__DIR__ . '/drivers/*.php') as $file) { + try + { + $name = \basename($file, '.php'); + if ($all || $this->Config()->Get('plugin', "driver_{$name}_enabled", false)) { + require_once $file; + $class = 'ChangePasswordDriver' . $name; + if ($class::isSupported()) { + yield $name => $class; + } + } + } + catch (\Throwable $oException) + { + } } } } diff --git a/release.php b/release.php index 997a2eff3..e21a6d350 100755 --- a/release.php +++ b/release.php @@ -52,6 +52,15 @@ if (isset($options['plugins'])) { $tar->compress(Phar::GZ); unlink($tar_destination); rename("{$tar_destination}.gz", $tgz_destination); + if (Phar::canWrite()) { + $phar_destination = "{$destPath}{$name}.phar"; + @unlink($phar_destination); + $tar = new Phar($phar_destination); + $tar->buildFromDirectory("./plugins/{$name}/"); + $tar->compress(Phar::GZ); + unlink($phar_destination); + rename("{$phar_destination}.gz", $phar_destination); + } } else { echo "- {$name} {$version}\n"; } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Admin.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Admin.php index 7d4bed79c..a41dfa05e 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Admin.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions/Admin.php @@ -694,7 +694,9 @@ trait Admin private static function deletePackageDir(string $sId) : bool { - return !\is_dir(APP_PLUGINS_PATH.$sId) || \MailSo\Base\Utils::RecRmDir(APP_PLUGINS_PATH.$sId); + $sPath = APP_PLUGINS_PATH.$sId; + return (!\is_dir($sPath) || \MailSo\Base\Utils::RecRmDir($sPath)) + && (!\is_file("{$sPath}.phar") || \unlink("{$sPath}.phar")); } private function downloadRemotePackageByUrl(string $sUrl) : string @@ -762,8 +764,12 @@ trait Admin if ($sTmp) { $oArchive = new \PharData($sTmp, 0, $sRealFile); - if (!\is_dir(APP_PLUGINS_PATH.$sId) || static::deletePackageDir($sId)) { - $bResult = $oArchive->extractTo(APP_PLUGINS_PATH); + if (static::deletePackageDir($sId)) { + if ('.phar' === \substr($sRealFile, -5)) { + $bResult = \copy($sTmp, APP_PLUGINS_PATH . \basename($sRealFile)); + } else { + $bResult = $oArchive->extractTo(APP_PLUGINS_PATH); + } if (!$bResult) { $this->Logger()->Write('Cannot extract package files: '.$oArchive->getStatusString(), \MailSo\Log\Enumerations\Type::ERROR, 'INSTALLER'); } diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php index c14f99d9e..bb1bd62d3 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Plugins/Manager.php @@ -108,6 +108,18 @@ class Manager } } + protected static function getPluginPath(string $sName) : ?string + { + $sPath = APP_PLUGINS_PATH.$sName; + if (\is_readable("{$sPath}/index.php")) { + return $sPath; + } + if (\is_readable("{$sPath}.phar")) { + return "phar://{$sPath}.phar"; + } + return null; + } + public function CreatePluginByName(string $sName) : ?\RainLoop\Plugins\AbstractPlugin { $oPlugin = null; @@ -117,7 +129,7 @@ class Manager $oPlugin = new $sClassName(); $oPlugin ->SetName($sName) - ->SetPath(APP_PLUGINS_PATH.$sName) + ->SetPath(static::getPluginPath($sName)) ->SetPluginManager($this) ->SetPluginConfig(new \RainLoop\Config\Plugin($sName, $oPlugin->ConfigMap())) ; @@ -130,12 +142,18 @@ class Manager { $aList = array(); - $aGlob = \glob(APP_PLUGINS_PATH.'*', GLOB_ONLYDIR|GLOB_NOSORT); + $aGlob = \glob(APP_PLUGINS_PATH.'*'); if (\is_array($aGlob)) { foreach ($aGlob as $sPathName) { - $sName = \basename($sPathName); + if (\is_dir($sPathName)) { + $sName = \basename($sPathName); + } else if ('.phar' === \substr($sPathName, -5)) { + $sName = \basename($sPathName, '.phar'); + } else { + continue; + } $sClassName = $this->loadPluginByName($sName); if ($sClassName) { $aList[] = array( @@ -164,12 +182,13 @@ class Manager public function loadPluginByName(string $sName) : ?string { - if (\preg_match('/^[a-z0-9\-]+$/', $sName) - && \is_readable(APP_PLUGINS_PATH.$sName.'/index.php')) - { + if (\preg_match('/^[a-z0-9\\-]+$/', $sName)) { $sClassName = $this->convertPluginFolderNameToClassName($sName); if (!\class_exists($sClassName)) { - include_once APP_PLUGINS_PATH.$sName.'/index.php'; + $sPath = static::getPluginPath($sName); + if (\is_readable($sPath.'/index.php')) { + include_once $sPath.'/index.php'; + } } if (\class_exists($sClassName) && \is_subclass_of($sClassName, 'RainLoop\\Plugins\\AbstractPlugin')) { return $sClassName;