Marius Burkard
2015-12-14 6b15d5f4e18578acb46be3babc46b7a9d3a9299c
- 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
6 files modified
77 ■■■■■ changed files
interface/lib/classes/plugin.inc.php 59 ●●●●● patch | view | raw | blame | history
interface/lib/classes/tform_actions.inc.php 2 ●●● patch | view | raw | blame | history
interface/lib/classes/tform_base.inc.php 3 ●●●●● patch | view | raw | blame | history
interface/web/admin/templates/directive_snippets_edit.htm 2 ●●● patch | view | raw | blame | history
server/plugins-available/apache2_plugin.inc.php 5 ●●●● patch | view | raw | blame | history
server/plugins-available/nginx_plugin.inc.php 6 ●●●● patch | view | raw | blame | history
interface/lib/classes/plugin.inc.php
@@ -43,35 +43,50 @@
        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);
                    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();
                    //** 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);
        }
    }
interface/lib/classes/tform_actions.inc.php
@@ -594,7 +594,7 @@
                $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();
            }
interface/lib/classes/tform_base.inc.php
@@ -126,6 +126,7 @@
    function loadFormDef($file, $module = '') {
        global $app, $conf;
        $app->plugin->raiseEvent('on_before_formdef', $module);
        include $file;
        $this->formDef = $form;
@@ -150,6 +151,8 @@
            $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;
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"> &nbsp; {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> &nbsp; {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>
server/plugins-available/apache2_plugin.inc.php
@@ -1091,7 +1091,10 @@
        // 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
server/plugins-available/nginx_plugin.inc.php
@@ -1133,7 +1133,11 @@
        $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));
            }