From 6b15d5f4e18578acb46be3babc46b7a9d3a9299c Mon Sep 17 00:00:00 2001 From: Marius Burkard <m.burkard@pixcept.de> Date: Mon, 14 Dec 2015 16:14:45 +0100 Subject: [PATCH] - added {DOCROOT_CLIENT} to directive placeholders (non-symlink docroot) - made placeholders visible for apache, too - added event raise at formdef loading (on_before_formdef and on_after_formdef) - added possibility to put plugin files into module/lib/plugin.d/ directory --- interface/lib/classes/plugin.inc.php | 61 ++++++++++++------- interface/lib/classes/tform_actions.inc.php | 2 +- interface/lib/classes/tform_base.inc.php | 3 + .../templates/directive_snippets_edit.htm | 2 +- .../plugins-available/apache2_plugin.inc.php | 5 +- server/plugins-available/nginx_plugin.inc.php | 6 +- 6 files changed, 52 insertions(+), 27 deletions(-) diff --git a/interface/lib/classes/plugin.inc.php b/interface/lib/classes/plugin.inc.php index aaaf56797c..6a6ff703aa 100644 --- a/interface/lib/classes/plugin.inc.php +++ b/interface/lib/classes/plugin.inc.php @@ -43,35 +43,50 @@ class plugin { if(isset($_SESSION['s']['plugin_cache'])) unset($_SESSION['s']['plugin_cache']); - - $plugins_dir = ISPC_LIB_PATH.FS_DIV.'plugins'.FS_DIV; + + $plugin_dirs = array(); + $plugin_dirs[] = ISPC_LIB_PATH.FS_DIV.'plugins'.FS_DIV; + + if(is_dir(ISPC_WEB_PATH)) { + if($dh = opendir(ISPC_WEB_PATH)) { + while(($file = readdir($dh)) !== false) { + if($file !== '.' && $file !== '..' && is_dir($file) && is_dir(ISPC_WEB_PATH . '/' . $file . '/lib/plugin.d')) $plugin_dirs[] = ISPC_WEB_PATH . '/' . $file . '/lib/plugin.d'; + } + closedir($dh); + } + } + $_SESSION['s']['plugin_cache'] = array(); $tmp_plugins = array(); - - if (is_dir($plugins_dir)) { - if ($dh = opendir($plugins_dir)) { - //** Go trough all files in the plugin dir - while (($file = readdir($dh)) !== false) { - if($file != '.' && $file != '..' && substr($file, -8, 8) == '.inc.php') { - $plugin_name = substr($file, 0, -8); - $tmp_plugins[$plugin_name] = $file; + + for($d = 0; $d < count($plugin_dirs); $d++) { + $plugins_dir = $plugin_dirs[$d]; + if (is_dir($plugins_dir)) { + if ($dh = opendir($plugins_dir)) { + //** Go trough all files in the plugin dir + while (($file = readdir($dh)) !== false) { + if($file !== '.' && $file !== '..' && substr($file, -8, 8) == '.inc.php') { + $plugin_name = substr($file, 0, -8); + $tmp_plugins[$plugin_name] = $file; + } } - } - //** sort the plugins by name - ksort($tmp_plugins); - - //** load the plugins - foreach($tmp_plugins as $plugin_name => $file) { - include_once $plugins_dir.$file; - if($this->debug) $app->log('Loading plugin: '.$plugin_name, LOGLEVEL_DEBUG); - $app->loaded_plugins[$plugin_name] = new $plugin_name; - $app->loaded_plugins[$plugin_name]->onLoad(); + closedir($dh); + //** sort the plugins by name + ksort($tmp_plugins); + + //** load the plugins + foreach($tmp_plugins as $plugin_name => $file) { + include_once $plugins_dir.$file; + if($this->debug) $app->log('Loading plugin: '.$plugin_name, LOGLEVEL_DEBUG); + $app->loaded_plugins[$plugin_name] = new $plugin_name; + $app->loaded_plugins[$plugin_name]->onLoad(); + } + } else { + $app->log('Unable to open the plugins directory: '.$plugins_dir, LOGLEVEL_ERROR); } } else { - $app->log('Unable to open the plugins directory: '.$plugins_dir, LOGLEVEL_ERROR); + $app->log('Plugins directory missing: '.$plugins_dir, LOGLEVEL_ERROR); } - } else { - $app->log('Plugins directory missing: '.$plugins_dir, LOGLEVEL_ERROR); } } diff --git a/interface/lib/classes/tform_actions.inc.php b/interface/lib/classes/tform_actions.inc.php index f172fea1f4..84613866aa 100644 --- a/interface/lib/classes/tform_actions.inc.php +++ b/interface/lib/classes/tform_actions.inc.php @@ -594,7 +594,7 @@ class tform_actions { $app->load($plugin_class); $this->plugins[$plugin_name] = new $plugin_class; $this->plugins[$plugin_name]->setOptions($plugin_name, $plugin_settings['options']); - // Make the data of the form easily accessible for the plugib + // Make the data of the form easily accessible for the plugin $this->plugins[$plugin_name]->form = $this; $this->plugins[$plugin_name]->onLoad(); } diff --git a/interface/lib/classes/tform_base.inc.php b/interface/lib/classes/tform_base.inc.php index 4b5a76c5f1..95162a7c68 100644 --- a/interface/lib/classes/tform_base.inc.php +++ b/interface/lib/classes/tform_base.inc.php @@ -126,6 +126,7 @@ class tform_base { function loadFormDef($file, $module = '') { global $app, $conf; + $app->plugin->raiseEvent('on_before_formdef', $module); include $file; $this->formDef = $form; @@ -150,6 +151,8 @@ class tform_base { $wb = $app->functions->array_merge($wb_global, $wb); } if(isset($wb_global)) unset($wb_global); + + $app->plugin->raiseEvent('on_after_formdef', $module); $this->wordbook = $wb; diff --git a/interface/web/admin/templates/directive_snippets_edit.htm b/interface/web/admin/templates/directive_snippets_edit.htm index 21b76867ec..054c5bcec7 100644 --- a/interface/web/admin/templates/directive_snippets_edit.htm +++ b/interface/web/admin/templates/directive_snippets_edit.htm @@ -16,7 +16,7 @@ </div> <div class="form-group"> <label for="snippet" class="col-sm-3 control-label">{tmpl_var name='snippet_txt'}</label> - <div class="col-sm-9"><textarea class="form-control" name="snippet" id="snippet" rows='10' cols='50'>{tmpl_var name='snippet'}</textarea></div><span class="nginx"> {tmpl_var name='variables_txt'}: </span><a href="javascript:void(0);" class="addPlaceholder nginx">{DOCROOT}</a><span class="nginx">, </span><a href="javascript:void(0);" class="addPlaceholder nginx">{FASTCGIPASS}</a> + <div class="col-sm-9"><textarea class="form-control" name="snippet" id="snippet" rows='10' cols='50'>{tmpl_var name='snippet'}</textarea></div><span> {tmpl_var name='variables_txt'}: </span><a href="javascript:void(0);" class="addPlaceholder">{DOCROOT}</a>, <a href="javascript:void(0);" class="addPlaceholder">{DOCROOT_CLIENT}</a><span class="nginx">, </span><a href="javascript:void(0);" class="addPlaceholder nginx">{FASTCGIPASS}</a> </div> <div class="form-group php"> <label class="col-sm-3 control-label">{tmpl_var name='required_php_snippets_txt'}</label> diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php index b18fe46ade..818cfd8129 100644 --- a/server/plugins-available/apache2_plugin.inc.php +++ b/server/plugins-available/apache2_plugin.inc.php @@ -1091,7 +1091,10 @@ class apache2_plugin { // Make sure we only have Unix linebreaks $vhost_data['apache_directives'] = str_replace("\r\n", "\n", $vhost_data['apache_directives']); $vhost_data['apache_directives'] = str_replace("\r", "\n", $vhost_data['apache_directives']); - $trans = array('{DOCROOT}' => $vhost_data['web_document_root_www']); + $trans = array( + '{DOCROOT}' => $vhost_data['web_document_root_www'], + '{DOCROOT_CLIENT}' => $vhost_data['web_document_root'] + ); $vhost_data['apache_directives'] = strtr($vhost_data['apache_directives'], $trans); // Check if a SSL cert exists diff --git a/server/plugins-available/nginx_plugin.inc.php b/server/plugins-available/nginx_plugin.inc.php index a31e639ecd..aaab39b127 100644 --- a/server/plugins-available/nginx_plugin.inc.php +++ b/server/plugins-available/nginx_plugin.inc.php @@ -1133,7 +1133,11 @@ class nginx_plugin { $nginx_directives = str_replace("\r", "\n", $nginx_directives); $nginx_directive_lines = explode("\n", $nginx_directives); if(is_array($nginx_directive_lines) && !empty($nginx_directive_lines)){ - $trans = array('{DOCROOT}' => $vhost_data['web_document_root_www'], '{FASTCGIPASS}' => 'fastcgi_pass '.($data['new']['php_fpm_use_socket'] == 'y'? 'unix:'.$fpm_socket : '127.0.0.1:'.$vhost_data['fpm_port']).';'); + $trans = array( + '{DOCROOT}' => $vhost_data['web_document_root_www'], + '{DOCROOT_CLIENT}' => $vhost_data['web_document_root'], + '{FASTCGIPASS}' => 'fastcgi_pass '.($data['new']['php_fpm_use_socket'] == 'y'? 'unix:'.$fpm_socket : '127.0.0.1:'.$vhost_data['fpm_port']).';' + ); foreach($nginx_directive_lines as $nginx_directive_line){ $final_nginx_directives[] = array('nginx_directive' => strtr($nginx_directive_line, $trans)); } -- GitLab