|
@@ -15,20 +15,20 @@ class Plugin{
|
|
|
|
|
|
public static function includeAll(){
|
|
|
$pluginFiles = Plugin::getFiles(true);
|
|
|
- if(is_array($pluginFiles)) {
|
|
|
- foreach($pluginFiles as $pluginFile) {
|
|
|
+ if(is_array($pluginFiles)) {
|
|
|
+ foreach($pluginFiles as $pluginFile) {
|
|
|
//Inclusion du coeur de plugin
|
|
|
- include $pluginFile;
|
|
|
+ include $pluginFile;
|
|
|
//Gestion des css du plugin en fonction du thème actif
|
|
|
$cssTheme = glob(dirname($pluginFile).'/*/'.DEFAULT_THEME.'.css');
|
|
|
$cssDefault = glob(dirname($pluginFile).'/*/default.css');
|
|
|
if(isset($cssTheme[0])){
|
|
|
- $GLOBALS['hooks']['css_files'][] = Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$cssTheme[0]));
|
|
|
+ $GLOBALS['hooks']['css_files'][] = Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$cssTheme[0]));
|
|
|
}else if(isset($cssDefault[0])){
|
|
|
- $GLOBALS['hooks']['css_files'][] = Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$cssDefault[0]));
|
|
|
+ $GLOBALS['hooks']['css_files'][] = Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',$cssDefault[0]));
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private static function getStates(){
|
|
@@ -40,7 +40,7 @@ class Plugin{
|
|
|
$stateFile = dirname(__FILE__).Plugin::FOLDER.'/plugins.states.json';
|
|
|
file_put_contents($stateFile,json_encode($states));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
private static function getObject($pluginFile){
|
|
|
$plugin = new Plugin();
|
|
@@ -48,28 +48,28 @@ class Plugin{
|
|
|
|
|
|
if(preg_match("#@author\s(.+)\s\<#", $fileLines, $match))
|
|
|
$plugin->setAuthor(trim($match[1]));
|
|
|
-
|
|
|
+
|
|
|
if(preg_match("#@author\s(.+)\s\<([a-z\@\.A-Z\s\-]+)\>#", $fileLines, $match))
|
|
|
$plugin->setMail(strtolower($match[2]));
|
|
|
-
|
|
|
+
|
|
|
if(preg_match("#@name\s(.+)[\r\n]#", $fileLines, $match))
|
|
|
$plugin->setName($match[1]);
|
|
|
-
|
|
|
+
|
|
|
if(preg_match("#@licence\s(.+)[\r\n]#", $fileLines, $match))
|
|
|
$plugin->setLicence($match[1]);
|
|
|
-
|
|
|
+
|
|
|
if(preg_match("#@version\s(.+)[\r\n]#", $fileLines, $match))
|
|
|
$plugin->setVersion($match[1]);
|
|
|
-
|
|
|
+
|
|
|
if(preg_match("#@link\s(.+)[\r\n]#", $fileLines, $match))
|
|
|
$plugin->setLink(trim($match[1]));
|
|
|
|
|
|
if(preg_match("#@type\s(.+)[\r\n]#", $fileLines, $match))
|
|
|
$plugin->setType(trim($match[1]));
|
|
|
-
|
|
|
+
|
|
|
if(preg_match("#@description\s(.+)[\r\n]#", $fileLines, $match))
|
|
|
$plugin->setDescription(trim($match[1]));
|
|
|
-
|
|
|
+
|
|
|
if(Plugin::loadState($pluginFile) || $plugin->getType()=='component'){
|
|
|
$plugin->setState(1);
|
|
|
}else{
|
|
@@ -80,51 +80,51 @@ class Plugin{
|
|
|
}
|
|
|
|
|
|
public static function getAll(){
|
|
|
- $pluginFiles = Plugin::getFiles();
|
|
|
+ $pluginFiles = Plugin::getFiles();
|
|
|
|
|
|
$plugins = array();
|
|
|
- if(is_array($pluginFiles)) {
|
|
|
- foreach($pluginFiles as $pluginFile) {
|
|
|
+ if(is_array($pluginFiles)) {
|
|
|
+ foreach($pluginFiles as $pluginFile) {
|
|
|
$plugin = Plugin::getObject($pluginFile);
|
|
|
$plugins[]=$plugin;
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
usort($plugins, "Plugin::sortPlugin");
|
|
|
return $plugins;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
- public static function addHook($hookName, $functionName) {
|
|
|
- $GLOBALS['hooks'][$hookName][] = $functionName;
|
|
|
- }
|
|
|
|
|
|
- public static function addCss($css) {
|
|
|
+ public static function addHook($hookName, $functionName) {
|
|
|
+ $GLOBALS['hooks'][$hookName][] = $functionName;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function addCss($css) {
|
|
|
$bt = debug_backtrace();
|
|
|
-
|
|
|
+
|
|
|
$path = Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',dirname($bt[0]['file']).$css));
|
|
|
|
|
|
- $GLOBALS['hooks']['css_files'][] = $path;
|
|
|
+ $GLOBALS['hooks']['css_files'][] = $path;
|
|
|
}
|
|
|
|
|
|
public static function callCss(){
|
|
|
$return='';
|
|
|
- if(isset($GLOBALS['hooks']['css_files'])) {
|
|
|
- foreach($GLOBALS['hooks']['css_files'] as $css_file) {
|
|
|
+ if(isset($GLOBALS['hooks']['css_files'])) {
|
|
|
+ foreach($GLOBALS['hooks']['css_files'] as $css_file) {
|
|
|
$return .='<link rel="stylesheet" href="'.$css_file.'">'."\n";
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
return $return;
|
|
|
}
|
|
|
-
|
|
|
- public static function addLink($rel, $link) {
|
|
|
+
|
|
|
+ public static function addLink($rel, $link) {
|
|
|
$GLOBALS['hooks']['head_link'][] = array("rel"=>$rel, "link"=>$link);
|
|
|
}
|
|
|
|
|
|
public static function callLink(){
|
|
|
$return='';
|
|
|
- if(isset($GLOBALS['hooks']['head_link'])) {
|
|
|
- foreach($GLOBALS['hooks']['head_link'] as $head_link) {
|
|
|
+ if(isset($GLOBALS['hooks']['head_link'])) {
|
|
|
+ foreach($GLOBALS['hooks']['head_link'] as $head_link) {
|
|
|
$return .='<link rel="'.$head_link['rel'].'" href="'.$head_link['link'].'" />'."\n";
|
|
|
}
|
|
|
}
|
|
@@ -133,39 +133,39 @@ class Plugin{
|
|
|
|
|
|
public static function path(){
|
|
|
$bt = debug_backtrace();
|
|
|
- return Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',dirname($bt[0]['file']))).'/';
|
|
|
+ return Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',dirname($bt[0]['file']))).'/';
|
|
|
}
|
|
|
|
|
|
- public static function addJs($js) {
|
|
|
+ public static function addJs($js) {
|
|
|
$bt = debug_backtrace();
|
|
|
$path = Functions::relativePath(str_replace('\\','/',dirname(__FILE__)),str_replace('\\','/',dirname($bt[0]['file']).$js));
|
|
|
- $GLOBALS['hooks']['js_files'][] = $path;
|
|
|
+ $GLOBALS['hooks']['js_files'][] = $path;
|
|
|
}
|
|
|
|
|
|
public static function callJs(){
|
|
|
$return='';
|
|
|
- if(isset($GLOBALS['hooks']['js_files'])) {
|
|
|
- foreach($GLOBALS['hooks']['js_files'] as $js_file) {
|
|
|
+ if(isset($GLOBALS['hooks']['js_files'])) {
|
|
|
+ foreach($GLOBALS['hooks']['js_files'] as $js_file) {
|
|
|
$return .='<script type="text/javascript" src="'.$js_file.'"></script>'."\n";
|
|
|
- }
|
|
|
- }
|
|
|
+ }
|
|
|
+ }
|
|
|
return $return;
|
|
|
}
|
|
|
|
|
|
- public static function callHook($hookName, $hookArguments) {
|
|
|
+ public static function callHook($hookName, $hookArguments) {
|
|
|
//echo '<div style="display:inline;background-color:#CC47CB;padding:3px;border:5px solid #9F1A9E;border-radius:5px;color:#ffffff;font-size:15px;">'.$hookName.'</div>';
|
|
|
- if(isset($GLOBALS['hooks'][$hookName])) {
|
|
|
- foreach($GLOBALS['hooks'][$hookName] as $functionName) {
|
|
|
- call_user_func_array($functionName, $hookArguments);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ if(isset($GLOBALS['hooks'][$hookName])) {
|
|
|
+ foreach($GLOBALS['hooks'][$hookName] as $functionName) {
|
|
|
+ call_user_func_array($functionName, $hookArguments);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public static function getFiles($onlyActivated=false){
|
|
|
|
|
|
$enabled = $disabled = array();
|
|
|
$files = glob(dirname(__FILE__). Plugin::FOLDER .'/*/*.plugin.*.php') or array();
|
|
|
-
|
|
|
+
|
|
|
foreach($files as $file){
|
|
|
$plugin = Plugin::getObject($file);
|
|
|
if($plugin->getState()){
|
|
@@ -178,7 +178,7 @@ class Plugin{
|
|
|
return $enabled;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
public static function loadState($plugin){
|
|
|
$states = Plugin::getStates();
|
|
|
return (isset($states[$plugin])?$states[$plugin]:false);
|
|
@@ -212,11 +212,11 @@ class Plugin{
|
|
|
if(file_exists($uninstall))require_once($uninstall);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
function getUid(){
|
|
|
- $pathInfo = explode('/',$this->getPath());
|
|
|
+ $pathInfo = explode('/',$this->getPath());
|
|
|
$count = count($pathInfo);
|
|
|
$name = $pathInfo[$count-1];
|
|
|
return $pathInfo[$count -2].'-'.substr($name,0,strpos($name,'.'));
|
|
@@ -224,7 +224,7 @@ class Plugin{
|
|
|
|
|
|
|
|
|
static function sortPlugin($a, $b){
|
|
|
- if ($a->getName() == $b->getName())
|
|
|
+ if ($a->getName() == $b->getName())
|
|
|
return 0;
|
|
|
return ($a->getName() < $b->getName()) ? -1 : 1;
|
|
|
}
|