snappymail/rainloop/v/0.0.0/app/libraries/RainLoop/Plugins/AbstractPlugin.php

315 lines
5.4 KiB
PHP
Raw Normal View History

2014-10-18 20:52:51 +08:00
<?php
namespace RainLoop\Plugins;
abstract class AbstractPlugin
{
/**
* @var \RainLoop\Plugins\Manager
*/
private $oPluginManager;
/**
* @var \RainLoop\Config\Plugin
*/
private $oPluginConfig;
/**
* @var bool
*/
private $bLangs;
/**
* @var string
*/
private $sName;
/**
* @var string
*/
private $sPath;
/**
* @var string
*/
private $sVersion;
/**
* @var array
*/
private $aConfigMap;
/**
* @var bool
*/
private $bPluginConfigLoaded;
public function __construct()
{
$this->sName = '';
$this->sPath = '';
$this->sVersion = '0.0';
$this->aConfigMap = null;
$this->oPluginManager = null;
$this->oPluginConfig = null;
$this->bPluginConfigLoaded = false;
$this->bLangs = false;
}
/**
* @return \RainLoop\Config\Plugin
*/
public function Config()
{
if (!$this->bPluginConfigLoaded && $this->oPluginConfig)
{
$this->bPluginConfigLoaded = true;
if ($this->oPluginConfig->IsInited())
{
if (!$this->oPluginConfig->Load())
{
$this->oPluginConfig->Save();
}
}
}
return $this->oPluginConfig;
}
/**
* @return \RainLoop\Plugins\Manager
*/
public function Manager()
{
return $this->oPluginManager;
}
public function Path() : string
2014-10-18 20:52:51 +08:00
{
return $this->sPath;
}
public function Name() : string
2014-10-18 20:52:51 +08:00
{
return $this->sName;
}
public function Version() : string
2014-10-18 20:52:51 +08:00
{
return $this->sVersion;
}
public function UseLangs(?bool $bLangs = null) : bool
2014-10-18 20:52:51 +08:00
{
if (null !== $bLangs)
{
$this->bLangs = $bLangs;
2014-10-18 20:52:51 +08:00
}
return $this->bLangs;
}
protected function configMapping() : array
2014-10-18 20:52:51 +08:00
{
return array();
}
public function Hash() : string
2014-10-18 20:52:51 +08:00
{
return \md5($this->sName.'@'.$this->sVersion);
2014-10-18 20:52:51 +08:00
}
public function Supported() : string
2014-10-18 20:52:51 +08:00
{
return '';
}
2014-10-18 20:52:51 +08:00
/**
* @final
*/
final public function ConfigMap() : array
2014-10-18 20:52:51 +08:00
{
if (null === $this->aConfigMap)
{
$this->aConfigMap = $this->configMapping();
if (!is_array($this->aConfigMap))
{
$this->aConfigMap = array();
}
}
2014-10-18 20:52:51 +08:00
return $this->aConfigMap;
}
public function SetPath(string $sPath) : self
{
$this->sPath = $sPath;
return $this;
}
public function SetName(string $sName) : self
2014-10-18 20:52:51 +08:00
{
$this->sName = $sName;
return $this;
}
public function SetVersion(string $sVersion) : self
{
2014-10-18 20:52:51 +08:00
if (0 < \strlen($sVersion))
{
$this->sVersion = $sVersion;
}
return $this;
}
public function SetPluginManager(\RainLoop\Plugins\Manager $oPluginManager) : self
2014-10-18 20:52:51 +08:00
{
$this->oPluginManager = $oPluginManager;
return $this;
}
public function SetPluginConfig(\RainLoop\Config\Plugin $oPluginConfig) : self
2014-10-18 20:52:51 +08:00
{
$this->oPluginConfig = $oPluginConfig;
return $this;
}
2020-03-11 01:45:00 +08:00
public function PreInit() : void
2014-10-18 20:52:51 +08:00
{
}
2020-03-11 01:45:00 +08:00
public function Init() : void
2014-10-18 20:52:51 +08:00
{
2014-10-18 20:52:51 +08:00
}
2020-03-11 01:45:00 +08:00
public function FilterAppDataPluginSection(bool $bAdmin, bool $bAuth, array &$aConfig) : void
2014-10-18 20:52:51 +08:00
{
}
protected function addHook(string $sHookName, string $sFunctionName) : self
2014-10-18 20:52:51 +08:00
{
if ($this->oPluginManager)
{
$this->oPluginManager->AddHook($sHookName, array(&$this, $sFunctionName));
}
return $this;
}
protected function addJs(string $sFile, bool $bAdminScope = false) : self
2014-10-18 20:52:51 +08:00
{
if ($this->oPluginManager)
{
$this->oPluginManager->AddJs($this->sPath.'/'.$sFile, $bAdminScope);
}
return $this;
}
protected function addTemplate(string $sFile, bool $bAdminScope = false) : self
2014-10-18 20:52:51 +08:00
{
if ($this->oPluginManager)
{
$this->oPluginManager->AddTemplate($this->sPath.'/'.$sFile, $bAdminScope);
}
return $this;
}
protected function replaceTemplate(string $sFile, bool $bAdminScope = false) : self
{
if ($this->oPluginManager)
{
$this->oPluginManager->AddTemplate($this->sPath.'/'.$sFile, $bAdminScope);
}
return $this;
}
protected function addPartHook(string $sActionName, string $sFunctionName) : self
2014-10-18 20:52:51 +08:00
{
if ($this->oPluginManager)
{
$this->oPluginManager->AddAdditionalPartAction($sActionName, array(&$this, $sFunctionName));
}
return $this;
}
protected function addAjaxHook(string $sActionName, string $sFunctionName) : self
2014-10-18 20:52:51 +08:00
{
if ($this->oPluginManager)
{
$this->oPluginManager->AddAdditionalAjaxAction($sActionName, array(&$this, $sFunctionName));
}
return $this;
}
protected function addTemplateHook(string $sName, string $sPlace, string $sLocalTemplateName, bool $bPrepend = false) : self
2014-10-18 20:52:51 +08:00
{
if ($this->oPluginManager)
{
$this->oPluginManager->AddProcessTemplateAction($sName, $sPlace,
'<!-- ko template: \''.$sLocalTemplateName.'\' --><!-- /ko -->', $bPrepend);
}
return $this;
}
protected function ajaxResponse(string $sFunctionName, array $aData) : self
{
if ($this->oPluginManager)
{
return $this->oPluginManager->AjaxResponseHelper(
$this->oPluginManager->convertPluginFolderNameToClassName($this->Name()).'::'.$sFunctionName, $aData);
}
return \json_encode($aData);
}
/**
* @param mixed $mDefault = null
*
* @return mixed
*/
public function ajaxParam(string $sKey, $mDefault = null)
{
if ($this->oPluginManager)
{
return $this->oPluginManager->Actions()->GetActionParam($sKey, $mDefault);
}
return '';
}
public function getUserSettings() : array
{
if ($this->oPluginManager)
{
return $this->oPluginManager->GetUserPluginSettings($this->Name());
}
return array();
}
public function saveUserSettings(array $aSettings) : bool
{
if ($this->oPluginManager && \is_array($aSettings))
{
return $this->oPluginManager->SaveUserPluginSettings($this->Name(), $aSettings);
}
return false;
}
2014-10-18 20:52:51 +08:00
}