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;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
public function Path() : string
|
2014-10-18 20:52:51 +08:00
|
|
|
{
|
|
|
|
return $this->sPath;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
public function Name() : string
|
2014-10-18 20:52:51 +08:00
|
|
|
{
|
|
|
|
return $this->sName;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
public function Version() : string
|
2014-10-18 20:52:51 +08:00
|
|
|
{
|
|
|
|
return $this->sVersion;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
public function UseLangs(?bool $bLangs = null) : bool
|
2014-10-18 20:52:51 +08:00
|
|
|
{
|
|
|
|
if (null !== $bLangs)
|
|
|
|
{
|
2020-03-10 00:04:17 +08:00
|
|
|
$this->bLangs = $bLangs;
|
2014-10-18 20:52:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->bLangs;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
protected function configMapping() : array
|
2014-10-18 20:52:51 +08:00
|
|
|
{
|
|
|
|
return array();
|
|
|
|
}
|
2014-12-02 01:34:21 +08:00
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
public function Hash() : string
|
2014-10-18 20:52:51 +08:00
|
|
|
{
|
2014-12-02 01:34:21 +08:00
|
|
|
return \md5($this->sName.'@'.$this->sVersion);
|
2014-10-18 20:52:51 +08:00
|
|
|
}
|
2014-12-02 01:34:21 +08:00
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
public function Supported() : string
|
2014-10-18 20:52:51 +08:00
|
|
|
{
|
|
|
|
return '';
|
|
|
|
}
|
2014-12-02 01:34:21 +08:00
|
|
|
|
2014-10-18 20:52:51 +08:00
|
|
|
/**
|
|
|
|
* @final
|
|
|
|
*/
|
2020-03-10 00:04:17 +08:00
|
|
|
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-12-02 01:34:21 +08:00
|
|
|
|
2014-10-18 20:52:51 +08:00
|
|
|
return $this->aConfigMap;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
public function SetPath(string $sPath) : self
|
2014-12-02 01:34:21 +08:00
|
|
|
{
|
|
|
|
$this->sPath = $sPath;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2015-02-19 09:01:59 +08:00
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
public function SetName(string $sName) : self
|
2014-10-18 20:52:51 +08:00
|
|
|
{
|
|
|
|
$this->sName = $sName;
|
|
|
|
|
2014-12-02 01:34:21 +08:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
public function SetVersion(string $sVersion) : self
|
2014-12-02 01:34:21 +08:00
|
|
|
{
|
2014-10-18 20:52:51 +08:00
|
|
|
if (0 < \strlen($sVersion))
|
|
|
|
{
|
|
|
|
$this->sVersion = $sVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
public function SetPluginManager(\RainLoop\Plugins\Manager $oPluginManager) : self
|
2014-10-18 20:52:51 +08:00
|
|
|
{
|
|
|
|
$this->oPluginManager = $oPluginManager;
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
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-12-02 01:34:21 +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
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +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;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
protected function replaceTemplate(string $sFile, bool $bAdminScope = false) : self
|
2015-06-01 01:40:54 +08:00
|
|
|
{
|
|
|
|
if ($this->oPluginManager)
|
|
|
|
{
|
|
|
|
$this->oPluginManager->AddTemplate($this->sPath.'/'.$sFile, $bAdminScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
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;
|
|
|
|
}
|
2015-02-19 09:01:59 +08:00
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
protected function ajaxResponse(string $sFunctionName, array $aData) : self
|
2015-02-19 09:01:59 +08:00
|
|
|
{
|
|
|
|
if ($this->oPluginManager)
|
|
|
|
{
|
|
|
|
return $this->oPluginManager->AjaxResponseHelper(
|
|
|
|
$this->oPluginManager->convertPluginFolderNameToClassName($this->Name()).'::'.$sFunctionName, $aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
return \json_encode($aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mixed $mDefault = null
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2020-03-10 00:04:17 +08:00
|
|
|
public function ajaxParam(string $sKey, $mDefault = null)
|
2015-02-19 09:01:59 +08:00
|
|
|
{
|
|
|
|
if ($this->oPluginManager)
|
|
|
|
{
|
|
|
|
return $this->oPluginManager->Actions()->GetActionParam($sKey, $mDefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
public function getUserSettings() : array
|
2015-02-19 09:01:59 +08:00
|
|
|
{
|
|
|
|
if ($this->oPluginManager)
|
|
|
|
{
|
|
|
|
return $this->oPluginManager->GetUserPluginSettings($this->Name());
|
|
|
|
}
|
|
|
|
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
|
2020-03-10 00:04:17 +08:00
|
|
|
public function saveUserSettings(array $aSettings) : bool
|
2015-02-19 09:01:59 +08:00
|
|
|
{
|
|
|
|
if ($this->oPluginManager && \is_array($aSettings))
|
|
|
|
{
|
|
|
|
return $this->oPluginManager->SaveUserPluginSettings($this->Name(), $aSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-18 20:52:51 +08:00
|
|
|
}
|