1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-05 16:04:24 +03:00
ifhub.club/engine/classes/Plugin.class.php

290 lines
7.9 KiB
PHP
Raw Normal View History

<?php
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
/**
* Абстракция плагина, от которой наследуются все плагины
*
*/
abstract class Plugin extends Object {
/**
* Путь к шаблонам с учетом наличия соответствующего skin`a
*
* @var array
*/
static protected $aTemplatePath=array();
/**
* Web-адрес директорий шаблонов с учетом наличия соответствующего skin`a
*
* @var array
*/
static protected $aTemplateWebPath=array();
/**
* Массив делегатов плагина
*
* @var array
*/
protected $aDelegates=array();
/**
* Массив наследуемых классов плагина
*
* @var array
*/
protected $aInherits=array();
public function __construct() {
}
/**
* Функция инициализации плагина
*
*/
public function Init() {
}
/**
* Передает информацию о делегатах на Plugin-модуль
* Вызывается Engine перед инициализацией плагина
*/
final function Delegate() {
/**
* Получаем название плагина
*/
preg_match('/^Plugin([\w]+)$/i',get_class($this),$aMatches);
$sPluginName=strtolower($aMatches[1]);
$aDelegates=$this->GetDelegates();
foreach ($aDelegates as $sObjectName=>$aParams) {
foreach ($aParams as $sFrom=>$sTo) {
$this->Plugin_Delegate($sObjectName,$sFrom,$sTo,get_class($this));
}
}
$aInherits=$this->GetInherits();
foreach ($aInherits as $sObjectName=>$aParams) {
foreach ($aParams as $sFrom=>$sTo) {
$this->Plugin_Inherit($sFrom,$sTo,get_class($this));
}
}
}
/**
* Возвращает массив делегатов
*
* @return array
*/
final function GetInherits() {
$aReturn=array();
if(is_array($this->aInherits) and count($this->aInherits)) {
foreach ($this->aInherits as $sObjectName=>$aParams) {
if(is_array($aParams) and count($aParams)) {
foreach ($aParams as $sFrom=>$sTo) {
2010-04-25 15:07:11 +03:00
if (is_int($sFrom)) {
$sFrom=$sTo;
$sTo=null;
}
list($sFrom,$sTo)=$this->MakeDelegateParams($sObjectName,$sFrom,$sTo);
$aReturn[$sObjectName][$sFrom]=$sTo;
}
}
}
}
return $aReturn;
}
/**
* Возвращает массив наследников
*
* @return array
*/
final function GetDelegates() {
$aReturn=array();
if(is_array($this->aDelegates) and count($this->aDelegates)) {
foreach ($this->aDelegates as $sObjectName=>$aParams) {
if(is_array($aParams) and count($aParams)) {
foreach ($aParams as $sFrom=>$sTo) {
if (is_int($sFrom)) {
$sFrom=$sTo;
$sTo=null;
}
list($sFrom,$sTo)=$this->MakeDelegateParams($sObjectName,$sFrom,$sTo);
$aReturn[$sObjectName][$sFrom]=$sTo;
}
}
}
}
return $aReturn;
}
public function MakeDelegateParams($sObjectName,$sFrom,$sTo) {
2010-04-25 15:07:11 +03:00
/**
* Если не указан делегат TO, считаем, что делегатом является
* одноименный объект текущего плагина
*/
if ($sObjectName=='template') {
if(!$sTo) {
$sTo = self::GetTemplatePath(get_class($this)).$sFrom;
2010-04-25 15:07:11 +03:00
} else {
$sTo=preg_replace("/^_/",$this->GetTemplatePath(get_class($this)),$sTo);
}
} else {
2010-06-01 19:20:30 +03:00
if(!$sTo) {
$sTo = get_class($this).'_'.$sFrom;
} else {
$sTo=preg_replace("/^_/",get_class($this).'_',$sTo);
}
2010-04-25 15:07:11 +03:00
}
return array($sFrom,$sTo);
}
/**
* Функция активации плагина
*
*/
public function Activate() {
return true;
}
/**
* Функция деактивации плагина
*
*/
public function Deactivate() {
return true;
}
/**
* Транслирует на базу данных запросы из указанного файла
*
* @param string $sFilePath
* @return array
*/
protected function ExportSQL($sFilePath) {
2010-09-15 18:22:06 +03:00
return $this->Database_ExportSQL($sFilePath);
}
2010-05-04 14:24:15 +03:00
/**
* Проверяет наличие таблицы в БД
*
* @param unknown_type $sTableName
* @return unknown
*/
protected function isTableExists($sTableName) {
$sTableName = str_replace('prefix_', Config::Get('db.table.prefix'), $sTableName);
$sQuery="SHOW TABLES LIKE '{$sTableName}'";
if ($aRows=$this->Database_GetConnect()->select($sQuery)) {
return true;
}
return false;
}
/**
* Получает версию плагина
*
* @return unknown
*/
public function GetVersion() {
preg_match('/^Plugin([\w]+)$/i',get_class($this),$aMatches);
$sPluginXML = Config::Get('path.root.server').'/plugins/'.strtolower($aMatches[1]).'/'.ModulePlugin::PLUGIN_XML_FILE;
if($oXml = @simplexml_load_file($sPluginXML)) {
return (string)$oXml->version;
}
return null;
}
public function __call($sName,$aArgs) {
return Engine::getInstance()->_CallModule($sName,$aArgs);
}
2010-04-29 22:45:54 +03:00
/**
* Возвращает полный путь до плагина
*
* @param unknown_type $sName
* @return unknown
*/
static public function GetPath($sName) {
$sName = preg_match('/^Plugin([\w]+)(_[\w]+)?$/Ui',$sName,$aMatches)
? strtolower($aMatches[1])
: strtolower($sName);
return Config::Get('path.root.server').'/plugins/'.$sName.'/';
}
/**
* Возвращает правильный путь к директории шаблонов
*
* @return string
*/
static public function GetTemplatePath($sName) {
2010-05-01 16:59:03 +03:00
$sName = preg_match('/^Plugin([\w]+)(_[\w]+)?$/Ui',$sName,$aMatches)
? strtolower($aMatches[1])
2010-01-15 20:18:54 +02:00
: strtolower($sName);
if(!isset(self::$aTemplatePath[$sName])) {
2010-04-17 18:12:10 +03:00
$aPaths=glob(Config::Get('path.root.server').'/plugins/'.$sName.'/templates/skin/*',GLOB_ONLYDIR);
$sTemplateName=($aPaths and in_array(Config::Get('view.skin'),array_map('basename',$aPaths)))
? Config::Get('view.skin')
: 'default';
$sDir=Config::Get('path.root.server')."/plugins/{$sName}/templates/skin/{$sTemplateName}/";
self::$aTemplatePath[$sName] = is_dir($sDir) ? $sDir : null;
}
return self::$aTemplatePath[$sName];
}
/**
* Возвращает правильный web-адрес директории шаблонов
*
* @return string
*/
static public function GetTemplateWebPath($sName) {
2010-05-01 16:59:03 +03:00
$sName = preg_match('/^Plugin([\w]+)(_[\w]+)?$/Ui',$sName,$aMatches)
? strtolower($aMatches[1])
: strtolower($sName);
if(!isset(self::$aTemplateWebPath[$sName])) {
2010-04-17 18:12:10 +03:00
$aPaths=glob(Config::Get('path.root.server').'/plugins/'.$sName.'/templates/skin/*',GLOB_ONLYDIR);
$sTemplateName=($aPaths and in_array(Config::Get('view.skin'),array_map('basename',$aPaths)))
? Config::Get('view.skin')
: 'default';
self::$aTemplateWebPath[$sName]=Config::Get('path.root.web')."/plugins/{$sName}/templates/skin/{$sTemplateName}/";
}
return self::$aTemplateWebPath[$sName];
}
/**
* Устанавливает значение пути до шаблонов плагина
*
* @param string $sName
* @param string $sTemplatePath
* @return bool
*/
static public function SetTemplatePath($sName,$sTemplatePath) {
if(!is_dir($sTemplatePath)) return false;
self::$aTemplatePath[$sName]=$sTemplatePath;
}
/**
* Устанавливает значение web-пути до шаблонов плагина
*
* @param string $sName
* @param string $sTemplatePath
* @return bool
*/
static public function SetTemplateWebPath($sName,$sTemplatePath) {
self::$aTemplateWebPath[$sName]=$sTemplatePath;
}
}
?>