diff --git a/interface/lib/classes/plugin.inc.php b/interface/lib/classes/plugin.inc.php index aaaf56797cf9a18c77ed5bc2cd3d2d912f752a1f..8a8ac20012976866518a72b4f6bb8685c5e142e5 100644 --- a/interface/lib/classes/plugin.inc.php +++ b/interface/lib/classes/plugin.inc.php @@ -43,35 +43,51 @@ 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'; + + if(is_dir(ISPC_WEB_PATH)) { + if($dh = opendir(ISPC_WEB_PATH)) { + while(($file = readdir($dh)) !== false) { + if($file !== '.' && $file !== '..' && is_dir(ISPC_WEB_PATH . FS_DIV . $file) && is_dir(ISPC_WEB_PATH . FS_DIV . $file . FS_DIV . 'lib' . FS_DIV . 'plugin.d')) $plugin_dirs[] = ISPC_WEB_PATH . FS_DIV . $file . FS_DIV . 'lib' . FS_DIV . '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)) { + $tmp_plugins = array(); + //** 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) { + require $plugins_dir . FS_DIV . $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); } } @@ -81,10 +97,10 @@ class plugin { for faster lookups without the need to load all plugins for every page. */ - public function registerEvent($event_name, $plugin_name, $function_name) { + public function registerEvent($event_name, $plugin_name, $function_name, $module_name = '') { global $app; - $_SESSION['s']['plugin_cache'][$event_name][] = array('plugin' => $plugin_name, 'function' => $function_name); + $_SESSION['s']['plugin_cache'][$event_name][] = array('plugin' => $plugin_name, 'function' => $function_name, 'module' => $module_name); if($this->debug) $app->log("Plugin '$plugin_name' has registered the function '$function_name' for the event '$event_name'", LOGLEVEL_DEBUG); } @@ -92,28 +108,33 @@ class plugin { This function is called when a certian action occurs, e.g. a form gets saved or a user is logged in. */ - public function raiseEvent($event_name, $data) { + public function raiseEvent($event_name, $data, $return_data = false) { global $app; if(!isset($_SESSION['s']['plugin_cache'])) { $this->loadPluginCache(); if($this->debug) $app->log('Loaded the plugin cache.', LOGLEVEL_DEBUG); } - - + + $result = ''; $sub_events = explode(':', $event_name); if(is_array($sub_events)) { if(count($sub_events) == 3) { $tmp_event = $sub_events[2]; if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG); - $this->callPluginEvent($tmp_event, $data); + $tmpresult = $this->callPluginEvent($tmp_event, $data, $return_data); + if($return_data == true && $tmpresult) $result .= $tmpresult; + $tmp_event = $sub_events[0].':'.$sub_events[2]; if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG); - $this->callPluginEvent($tmp_event, $data); + $tmpresult = $this->callPluginEvent($tmp_event, $data, $return_data); + if($return_data == true && $tmpresult) $result .= $tmpresult; + $tmp_event = $sub_events[0].':'.$sub_events[1].':'.$sub_events[2]; if($this->debug) $app->log("Called Event '$tmp_event'", LOGLEVEL_DEBUG); - $this->callPluginEvent($tmp_event, $data); + $tmpresult = $this->callPluginEvent($tmp_event, $data, $return_data); + if($return_data == true && $tmpresult) $result .= $tmpresult; /*$sub_events = array_reverse($sub_events); $tmp_event = ''; @@ -125,23 +146,36 @@ class plugin { */ } else { if($this->debug) $app->log("Called Event '$sub_events[0]'", LOGLEVEL_DEBUG); - $this->callPluginEvent($sub_events[0], $data); + $tmpresult = $this->callPluginEvent($sub_events[0], $data, $return_data); + if($return_data == true && $tmpresult) $result .= $tmpresult; } } + + if($return_data == true) return $result; } // end function raiseEvent //* Internal function to load the plugin and call the event function in the plugin. - private function callPluginEvent($event_name, $data) { + private function callPluginEvent($event_name, $data, $return_data = false) { global $app; + $result = ''; + //* execute the functions for the events if(@is_array($_SESSION['s']['plugin_cache'][$event_name])) { foreach($_SESSION['s']['plugin_cache'][$event_name] as $rec) { $plugin_name = $rec['plugin']; $function_name = $rec['function']; - $plugin_file = ISPC_LIB_PATH.FS_DIV.'plugins'.FS_DIV.$plugin_name.'.inc.php'; - + $module_name = $rec['module']; + if($module_name != '') { + if(strpos($module_name, '..') !== false || strpos($module_name, '/') !== false) { + if($this->debug) $app->log('Module name ' . $module_name . ' contains illegal characters.', LOGLEVEL_DEBUG); + continue; + } + $plugin_file = ISPC_WEB_PATH . FS_DIV . $module_name . FS_DIV . 'lib' . FS_DIV . 'plugin.d' . FS_DIV . $plugin_name . '.inc.php'; + } else { + $plugin_file = ISPC_LIB_PATH . FS_DIV . 'plugins' . FS_DIV . $plugin_name . '.inc.php'; + } if(is_file($plugin_file)) { if(!isset($app->loaded_plugins[$plugin_name])) { @@ -152,12 +186,14 @@ class plugin { if($this->debug) $app->log("Called method: '$function_name' in plugin '$plugin_name' for event '$event_name'", LOGLEVEL_DEBUG); // call_user_method($function_name,$app->loaded_plugins[$plugin_name],$event_name,$data); - call_user_func(array($app->loaded_plugins[$plugin_name], $function_name), $event_name, $data); - + $tmpresult = call_user_func(array($app->loaded_plugins[$plugin_name], $function_name), $event_name, $data); + if($return_data == true && $tmpresult) $result .= $tmpresult; } } } + + if($return_data == true) return $result; } // end functiom callPluginEvent diff --git a/interface/lib/classes/tform_actions.inc.php b/interface/lib/classes/tform_actions.inc.php index f172fea1f4c5fceb824281c8e1b54ee7cc6b3446..7ab09ae794eb47d39ffe2abaa3c4904a560e3fcd 100644 --- a/interface/lib/classes/tform_actions.inc.php +++ b/interface/lib/classes/tform_actions.inc.php @@ -46,7 +46,7 @@ class tform_actions { $app->tpl->newTemplate("tabbed_form.tpl.htm"); // Load table definition from file - $app->tform->loadFormDef($tform_def_file); + $app->tform->loadFormDef($tform_def_file, (isset($_SESSION['s']['module']['name']) ? $_SESSION['s']['module']['name'] : '')); // Importing ID $this->id = (isset($_REQUEST["id"]))?$app->functions->intval($_REQUEST["id"]):0; @@ -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 4b5a76c5f14a7406eb50c7d5383b771c21b3cf29..2e53d2773bc2d0550548f878ba2f8493bd9bd2fe 100644 --- a/interface/lib/classes/tform_base.inc.php +++ b/interface/lib/classes/tform_base.inc.php @@ -127,6 +127,7 @@ class tform_base { global $app, $conf; include $file; + $app->plugin->raiseEvent($_SESSION['s']['module']['name'].':'.$form['name'] . ':on_before_formdef', $this); $this->formDef = $form; $this->module = $module; @@ -150,8 +151,10 @@ class tform_base { $wb = $app->functions->array_merge($wb_global, $wb); } if(isset($wb_global)) unset($wb_global); - + $this->wordbook = $wb; + + $app->plugin->raiseEvent($_SESSION['s']['module']['name'].':'.$app->tform->formDef['name'] . ':on_after_formdef', $this); $this->dateformat = $app->lng('conf_format_dateshort'); $this->datetimeformat = $app->lng('conf_format_datetime'); diff --git a/interface/lib/classes/tpl.inc.php b/interface/lib/classes/tpl.inc.php index 34df2a9343c467c2dfe39bb017fbcaee0a30c1cd..928c215e203503b381af30e4e0c054a6de121000 100644 --- a/interface/lib/classes/tpl.inc.php +++ b/interface/lib/classes/tpl.inc.php @@ -839,28 +839,34 @@ if (!defined('vlibTemplateClassLoaded')) { * @access private * @return mixed data/string or boolean */ - private function _getData ($tmplfile, $do_eval=false) + private function _getData ($tmplfile, $do_eval=false, $tmpl_from_string = false) { //* check the current file depth if ($this->_includedepth > $this->OPTIONS['MAX_INCLUDES'] || $tmplfile == false) { return; } else { if ($this->_debug){ - array_push($this->_debugIncludedfiles, $tmplfile); + if($tmpl_from_string) array_push($this->_debugIncludedfiles, 'String: ' . substr($tmplfile, 0, 25) . '...'); + else array_push($this->_debugIncludedfiles, $tmplfile); } if ($do_eval) { - array_push($this->_currentincludedir, dirname($tmplfile)); + if($tmpl_from_string == true) array_push($this->_currentincludedir, end($this->_currentincludedir)); + else array_push($this->_currentincludedir, dirname($tmplfile)); $this->_includedepth++; } } - if($this->_cache && $this->_checkCache($tmplfile)) { //* cache exists so lets use it + if($this->_cache && $this->_checkCache($tmplfile, $tmpl_from_string)) { //* cache exists so lets use it $data = fread($fp = fopen($this->_cachefile, 'r'), filesize($this->_cachefile)); fclose($fp); } else { //* no cache lets parse the file - $data = fread($fp = fopen($tmplfile, 'r'), filesize($tmplfile)); - fclose($fp); + if($tmpl_from_string == true) { + $data = $tmplfile; + } else { + $data = fread($fp = fopen($tmplfile, 'r'), filesize($tmplfile)); + fclose($fp); + } $regex = '/(<|<\/|{|{\/|<!--|<!--\/){1}\s*'; $regex.= 'tmpl_([\w]+)\s*'; @@ -884,7 +890,7 @@ if (!defined('vlibTemplateClassLoaded')) { } //* now we must parse the $data and check for any <tmpl_include>'s - if ($this->_debug) $this->doDebugWarnings(file($tmplfile), $tmplfile); + if ($this->_debug && $tmpl_from_string == false) $this->doDebugWarnings(file($tmplfile), $tmplfile); if ($do_eval) { $success = @eval('?>'.$data.'<?php return 1;'); @@ -1061,6 +1067,46 @@ if (!defined('vlibTemplateClassLoaded')) { } } + /** + * returns a string containing hook data + * @param string $type + * @param string $name + * @return string hook data + */ + private function _parseHook ($name) + { + global $app; + + if(!$name) return false; + + $module = isset($_SESSION['s']['module']['name']) ? $_SESSION['s']['module']['name'] : ''; + $form = isset($app->tform->formDef['name']) ? $app->tform->formDef['name'] : ''; + + $events = array(); + if($module) { + $events[] = $module . ':' . ($form ? $form : '') . ':' . $name; + $events[] = $module . ':' . ($form ? $form : '') . ':on_template_content'; + } else { + $events[] = $name; + $events[] = 'on_template_content'; + } + + $events = array_unique($events); + + for($e = 0; $e < count($events); $e++) { + $tmpresult = $app->plugin->raiseEvent($events[$e], array( + 'name' => $name, + 'module' => $module, + 'form' => $form + ), true); + if(!$tmpresult) $tmpresult = ''; + else $tmpresult = $this->_getData($tmpresult, false, true); + + $result .= $tmpresult; + } + + return $result; + } /** * returns a string used for parsing in tmpl_loop statements. @@ -1254,7 +1300,10 @@ if (!defined('vlibTemplateClassLoaded')) { if ($this->OPTIONS['ENABLE_PHPINCLUDE']) { return '<?php include(\''.$file.'\'); ?>'; } - + + case 'hook': + return $this->_parseHook(@$var); + case 'include': return '<?php $this->_getData($this->_fileSearch(\''.$file.'\'), 1); ?>'; diff --git a/interface/lib/classes/tpl_cache.inc.php b/interface/lib/classes/tpl_cache.inc.php index 4bf75faa8c8cda9ccb92a3b8749cf0926fce8f47..ce8a5b16ceccb5d9cdab6a7c4c125a6367a34b0f 100644 --- a/interface/lib/classes/tpl_cache.inc.php +++ b/interface/lib/classes/tpl_cache.inc.php @@ -101,8 +101,8 @@ class tplc extends tpl { * FUNCTION: _checkCache * checks if there's a cache, if there is then it will read the cache file as the template. */ - function _checkCache ($tmplfile) { - $this->_cachefile = $this->_getFilename($tmplfile); + function _checkCache ($tmplfile, $tmpl_from_string = false) { + $this->_cachefile = $this->_getFilename($tmplfile, $tmpl_from_string); if ($this->_clearcache) { if (file_exists($this->_cachefile)) unlink($this->_cachefile); return false; @@ -133,8 +133,9 @@ class tplc extends tpl { * gets the full pathname for the cached file * */ - function _getFilename($tmplfile) { - return $this->OPTIONS['CACHE_DIRECTORY'].'/'.md5('vlibCachestaR'.realpath($tmplfile)).'.'.$this->OPTIONS['CACHE_EXTENSION']; + function _getFilename($tmplfile, $tmpl_from_string = false) { + if($tmpl_from_string == true) return $this->OPTIONS['CACHE_DIRECTORY'].'/'.md5('vlibCachestaRSTRING'.$tmplfile).'.'.$this->OPTIONS['CACHE_EXTENSION']; + else return $this->OPTIONS['CACHE_DIRECTORY'].'/'.md5('vlibCachestaR'.realpath($tmplfile)).'.'.$this->OPTIONS['CACHE_EXTENSION']; } diff --git a/interface/web/admin/templates/directive_snippets_edit.htm b/interface/web/admin/templates/directive_snippets_edit.htm index 21b76867ec12d468ff7371222951e1ef809276aa..054c5bcec72155f339d99d85a6cbcb1f50eb6d34 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/interface/web/sites/templates/web_vhost_domain_edit.htm b/interface/web/sites/templates/web_vhost_domain_edit.htm index 13702932ef9420496cda2b3033781eadbbef3e8b..230c8d0dcef4894b6e25f372d12dd7a887bb7cfe 100644 --- a/interface/web/sites/templates/web_vhost_domain_edit.htm +++ b/interface/web/sites/templates/web_vhost_domain_edit.htm @@ -13,7 +13,7 @@ </tmpl_if> - + {tmpl_hook name="begin_form"} <tmpl_if name="vhostdomain_type" value="domain"> <tmpl_if name="is_admin"> <div class="form-group"> @@ -222,26 +222,29 @@ {tmpl_var name='php'} </select></div> </div> + {tmpl_hook name="field_fastcgi_php_version"} <div class="form-group fastcgi_php_version"> <label for="fastcgi_php_version" class="col-sm-3 control-label">{tmpl_var name='fastcgi_php_version_txt'}</label> <div class="col-sm-9"><select name="fastcgi_php_version" id="fastcgi_php_version" class="form-control"> {tmpl_var name='fastcgi_php_version'} </select></div> </div> - {tmpl_var name="directive_snippets_id"} + {tmpl_var name="directive_snippets_id"} + {tmpl_hook name="field_enable_pagespeed"} <div class="form-group nginx pagespeed"> <label class="col-sm-3 control-label">{tmpl_var name='enable_pagespeed_txt'}</label> <div class="col-sm-9"> {tmpl_var name="enable_pagespeed"} </div> </div> + {tmpl_hook name="field_active"} <div class="form-group"> <label class="col-sm-3 control-label">{tmpl_var name='active_txt'}</label> <div class="col-sm-9"> {tmpl_var name='active'} </div> </div> - + {tmpl_hook name="end_form"} <input type="hidden" name="id" value="{tmpl_var name='id'}"> diff --git a/server/conf/vhost.conf.master b/server/conf/vhost.conf.master index bdfc761fdac5a093dba5601c33d2c931589c0b56..ab8430d36f1cc052a0b606b85af44fa02c12ce28 100644 --- a/server/conf/vhost.conf.master +++ b/server/conf/vhost.conf.master @@ -1,3 +1,4 @@ +<tmpl_hook name='apache2_vhost:header'> <Directory {tmpl_var name='web_basedir'}/{tmpl_var name='domain'}> AllowOverride None @@ -9,8 +10,9 @@ </tmpl_if> </Directory> -<tmpl_loop name="vhosts"> +<tmpl_loop name='vhosts'> <VirtualHost {tmpl_var name='ip_address'}:{tmpl_var name='port'}> +<tmpl_hook name='apache2_vhost:vhost_header'> <tmpl_if name='php' op='==' value='suphp'> DocumentRoot <tmpl_var name='web_document_root'> </tmpl_else> @@ -444,5 +446,8 @@ </IfModule> <tmpl_var name='apache_directives'> +<tmpl_hook name='apache2_vhost:vhost_footer'> </VirtualHost> </tmpl_loop> + +<tmpl_hook name='apache2_vhost:footer'> \ No newline at end of file diff --git a/server/lib/classes/plugins.inc.php b/server/lib/classes/plugins.inc.php index 4771487dce37e3d97b282fc8cfa9235f894ea231..9b9b143776d3e4ffe390cc73406c96fef4ae0b6c 100644 --- a/server/lib/classes/plugins.inc.php +++ b/server/lib/classes/plugins.inc.php @@ -73,7 +73,6 @@ class plugins { } else { $app->log('Plugins directory missing: '.$plugins_dir, LOGLEVEL_ERROR); } - } /* @@ -138,13 +137,15 @@ class plugins { } - function raiseAction($action_name, $data) { + function raiseAction($action_name, $data, $return_data = false) { global $app; //* Get the subscriptions for this action $actions = (isset($this->subscribed_actions[$action_name]))?$this->subscribed_actions[$action_name]:''; if($this->debug) $app->log('Raised action: '.$action_name, LOGLEVEL_DEBUG); + $result = ''; + if(is_array($actions)) { foreach($actions as $action) { $plugin_name = $action['plugin']; @@ -154,8 +155,13 @@ class plugins { $app->log("Calling function '$function_name' from plugin '$plugin_name' raised by action '$action_name'.", LOGLEVEL_DEBUG); $state = call_user_func(array($app->loaded_plugins[$plugin_name], $function_name), $action_name, $data); //* ensure that we return the highest warning / error level if a error occured in one of the functions - if($state == 'warning' && $state_out != 'error') $state_out = 'warning'; - if($state == 'error') $state_out = 'error'; + if($return_data) { + if($state) $result .= $state; + } else { + if($state == 'warning' && $state_out != 'error') $state_out = 'warning'; + elseif($state == 'error') $state_out = 'error'; + } + unset($plugin_name); unset($function_name); } @@ -163,7 +169,8 @@ class plugins { unset($action); unset($actions); - return $state_out; + if($return_data == true) return $result; + else return $state_out; } } diff --git a/server/lib/classes/tpl.inc.php b/server/lib/classes/tpl.inc.php index 34df2a9343c467c2dfe39bb017fbcaee0a30c1cd..5e595f69fe01e6715f6d8ba7665147a81390aede 100644 --- a/server/lib/classes/tpl.inc.php +++ b/server/lib/classes/tpl.inc.php @@ -839,28 +839,34 @@ if (!defined('vlibTemplateClassLoaded')) { * @access private * @return mixed data/string or boolean */ - private function _getData ($tmplfile, $do_eval=false) + private function _getData ($tmplfile, $do_eval=false, $tmpl_from_string = false) { //* check the current file depth if ($this->_includedepth > $this->OPTIONS['MAX_INCLUDES'] || $tmplfile == false) { return; } else { if ($this->_debug){ - array_push($this->_debugIncludedfiles, $tmplfile); + if($tmpl_from_string) array_push($this->_debugIncludedfiles, 'String: ' . substr($tmplfile, 0, 25) . '...'); + else array_push($this->_debugIncludedfiles, $tmplfile); } if ($do_eval) { - array_push($this->_currentincludedir, dirname($tmplfile)); + if($tmpl_from_string == true) array_push($this->_currentincludedir, end($this->_currentincludedir)); + else array_push($this->_currentincludedir, dirname($tmplfile)); $this->_includedepth++; } } - if($this->_cache && $this->_checkCache($tmplfile)) { //* cache exists so lets use it + if($this->_cache && $this->_checkCache($tmplfile, $tmpl_from_string)) { //* cache exists so lets use it $data = fread($fp = fopen($this->_cachefile, 'r'), filesize($this->_cachefile)); fclose($fp); } else { //* no cache lets parse the file - $data = fread($fp = fopen($tmplfile, 'r'), filesize($tmplfile)); - fclose($fp); + if($tmpl_from_string == true) { + $data = $tmplfile; + } else { + $data = fread($fp = fopen($tmplfile, 'r'), filesize($tmplfile)); + fclose($fp); + } $regex = '/(<|<\/|{|{\/|<!--|<!--\/){1}\s*'; $regex.= 'tmpl_([\w]+)\s*'; @@ -884,7 +890,7 @@ if (!defined('vlibTemplateClassLoaded')) { } //* now we must parse the $data and check for any <tmpl_include>'s - if ($this->_debug) $this->doDebugWarnings(file($tmplfile), $tmplfile); + if ($this->_debug && $tmpl_from_string == false) $this->doDebugWarnings(file($tmplfile), $tmplfile); if ($do_eval) { $success = @eval('?>'.$data.'<?php return 1;'); @@ -1061,6 +1067,29 @@ if (!defined('vlibTemplateClassLoaded')) { } } + /** + * returns a string containing hook data + * @param string $type + * @param string $name + * @return string hook data + */ + private function _parseHook ($name) + { + global $app; + + $namespace = ''; + if(strpos($name, ':') !== false) list($namespace, $name) = explode(':', $name, 2); + + $result = $app->plugins->raiseAction('on_template_content_hook', array( + 'name' => $name, + 'namespace' => $namespace, + 'vars' => $this->_vars + ), true); + if(!$result) $result = ''; + else $result = $this->_getData($result, false, true); + + return $result; + } /** * returns a string used for parsing in tmpl_loop statements. @@ -1254,7 +1283,10 @@ if (!defined('vlibTemplateClassLoaded')) { if ($this->OPTIONS['ENABLE_PHPINCLUDE']) { return '<?php include(\''.$file.'\'); ?>'; } - + + case 'hook': + return $this->_parseHook(@$var); + case 'include': return '<?php $this->_getData($this->_fileSearch(\''.$file.'\'), 1); ?>'; diff --git a/server/lib/classes/tpl_cache.inc.php b/server/lib/classes/tpl_cache.inc.php index 4bf75faa8c8cda9ccb92a3b8749cf0926fce8f47..ce8a5b16ceccb5d9cdab6a7c4c125a6367a34b0f 100644 --- a/server/lib/classes/tpl_cache.inc.php +++ b/server/lib/classes/tpl_cache.inc.php @@ -101,8 +101,8 @@ class tplc extends tpl { * FUNCTION: _checkCache * checks if there's a cache, if there is then it will read the cache file as the template. */ - function _checkCache ($tmplfile) { - $this->_cachefile = $this->_getFilename($tmplfile); + function _checkCache ($tmplfile, $tmpl_from_string = false) { + $this->_cachefile = $this->_getFilename($tmplfile, $tmpl_from_string); if ($this->_clearcache) { if (file_exists($this->_cachefile)) unlink($this->_cachefile); return false; @@ -133,8 +133,9 @@ class tplc extends tpl { * gets the full pathname for the cached file * */ - function _getFilename($tmplfile) { - return $this->OPTIONS['CACHE_DIRECTORY'].'/'.md5('vlibCachestaR'.realpath($tmplfile)).'.'.$this->OPTIONS['CACHE_EXTENSION']; + function _getFilename($tmplfile, $tmpl_from_string = false) { + if($tmpl_from_string == true) return $this->OPTIONS['CACHE_DIRECTORY'].'/'.md5('vlibCachestaRSTRING'.$tmplfile).'.'.$this->OPTIONS['CACHE_EXTENSION']; + else return $this->OPTIONS['CACHE_DIRECTORY'].'/'.md5('vlibCachestaR'.realpath($tmplfile)).'.'.$this->OPTIONS['CACHE_EXTENSION']; } diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php index b18fe46ade5c7c161a0d50ed8180a68a7224ae7f..818cfd81291d44b556da112218b98ef3f53eaa4b 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 a31e639ecd8c2329061e43ba88e939bfc6a28196..aaab39b12763098a22232c4b7561407d5cf2f7d8 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)); }