Skip to content

Commit 216ea12

Browse files
author
Marius Burkard
committed
- Changed template events (reduced php code and needed template code)
1 parent 860ab6c commit 216ea12

File tree

8 files changed

+101
-42
lines changed

8 files changed

+101
-42
lines changed

interface/lib/classes/tform_actions.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function onLoad() {
4646
$app->tpl->newTemplate("tabbed_form.tpl.htm");
4747

4848
// Load table definition from file
49-
$app->tform->loadFormDef($tform_def_file);
49+
$app->tform->loadFormDef($tform_def_file, (isset($_SESSION['s']['module']['name']) ? $_SESSION['s']['module']['name'] : ''));
5050

5151
// Importing ID
5252
$this->id = (isset($_REQUEST["id"]))?$app->functions->intval($_REQUEST["id"]):0;

interface/lib/classes/tform_base.inc.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ function loadTableDef($file) {
126126
function loadFormDef($file, $module = '') {
127127
global $app, $conf;
128128

129-
$app->plugin->raiseEvent('on_before_formdef', $this);
130129
include $file;
130+
$app->plugin->raiseEvent($_SESSION['s']['module']['name'].':'.$form['name'] . ':on_before_formdef', $this);
131131
$this->formDef = $form;
132132

133133
$this->module = $module;
@@ -152,9 +152,9 @@ function loadFormDef($file, $module = '') {
152152
}
153153
if(isset($wb_global)) unset($wb_global);
154154

155-
$app->plugin->raiseEvent('on_after_formdef', $this);
156-
157155
$this->wordbook = $wb;
156+
157+
$app->plugin->raiseEvent($_SESSION['s']['module']['name'].':'.$app->tform->formDef['name'] . ':on_after_formdef', $this);
158158

159159
$this->dateformat = $app->lng('conf_format_dateshort');
160160
$this->datetimeformat = $app->lng('conf_format_datetime');

interface/lib/classes/tpl.inc.php

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,20 +1073,37 @@ private function _parseIf($varname, $value = null, $op = null, $namespace = null
10731073
* @param string $name
10741074
* @return string hook data
10751075
*/
1076-
private function _parseHook ($type, $name)
1076+
private function _parseHook ($name)
10771077
{
10781078
global $app;
10791079

1080-
$module_name = '';
1081-
if(strpos($name, ':') !== false) list($module_name, $name) = explode(':', $name, 2);
1080+
if(!$name) return false;
10821081

1083-
$result = $app->plugin->raiseEvent('on_template_content_hook', array(
1084-
'type' => $type,
1085-
'name' => $name,
1086-
'module' => $module_name
1087-
), true);
1088-
if(!$result) $result = '';
1089-
else $result = $this->_getData($result, false, true);
1082+
$module = isset($_SESSION['s']['module']['name']) ? $_SESSION['s']['module']['name'] : '';
1083+
$form = isset($app->tform->formDef['name']) ? $app->tform->formDef['name'] : '';
1084+
1085+
$events = array();
1086+
if($module) {
1087+
$events[] = $module . ':' . ($form ? $form : '') . ':' . $name;
1088+
$events[] = $module . ':' . ($form ? $form : '') . ':on_template_content';
1089+
} else {
1090+
$events[] = $name;
1091+
$events[] = 'on_template_content';
1092+
}
1093+
1094+
$events = array_unique($events);
1095+
1096+
for($e = 0; $e < count($events); $e++) {
1097+
$tmpresult = $app->plugin->raiseEvent($events[$e], array(
1098+
'name' => $name,
1099+
'module' => $module,
1100+
'form' => $form
1101+
), true);
1102+
if(!$tmpresult) $tmpresult = '';
1103+
else $tmpresult = $this->_getData($tmpresult, false, true);
1104+
1105+
$result .= $tmpresult;
1106+
}
10901107

10911108
return $result;
10921109
}
@@ -1285,7 +1302,7 @@ private function _parseTag ($args)
12851302
}
12861303

12871304
case 'hook':
1288-
return $this->_parseHook(@$var, @$value);
1305+
return $this->_parseHook(@$var);
12891306

12901307
case 'include':
12911308
return '<?php $this->_getData($this->_fileSearch(\''.$file.'\'), 1); ?>';

interface/web/sites/templates/web_vhost_domain_edit.htm

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h1><tmpl_var name="list_head_txt"></h1>
1313
</tmpl_if>
1414

1515

16-
{tmpl_hook name="begin_form" value="web_vhost_domain_edit"}
16+
{tmpl_hook name="begin_form"}
1717
<tmpl_if name="vhostdomain_type" value="domain">
1818
<tmpl_if name="is_admin">
1919
<div class="form-group">
@@ -222,32 +222,29 @@ <h1><tmpl_var name="list_head_txt"></h1>
222222
{tmpl_var name='php'}
223223
</select></div>
224224
</div>
225-
{tmpl_hook name="begin_field" value="web_vhost_domain_edit:fastcgi_php_version"}
225+
{tmpl_hook name="field_fastcgi_php_version"}
226226
<div class="form-group fastcgi_php_version">
227227
<label for="fastcgi_php_version" class="col-sm-3 control-label">{tmpl_var name='fastcgi_php_version_txt'}</label>
228228
<div class="col-sm-9"><select name="fastcgi_php_version" id="fastcgi_php_version" class="form-control">
229229
{tmpl_var name='fastcgi_php_version'}
230230
</select></div>
231231
</div>
232-
{tmpl_hook name="end_field" value="web_vhost_domain_edit:fastcgi_php_version"}
233-
{tmpl_var name="directive_snippets_id"}
234-
{tmpl_hook name="begin_field" value="web_vhost_domain_edit:enable_pagespeed"}
232+
{tmpl_var name="directive_snippets_id"}
233+
{tmpl_hook name="field_enable_pagespeed"}
235234
<div class="form-group nginx pagespeed">
236235
<label class="col-sm-3 control-label">{tmpl_var name='enable_pagespeed_txt'}</label>
237236
<div class="col-sm-9">
238237
{tmpl_var name="enable_pagespeed"}
239238
</div>
240239
</div>
241-
{tmpl_hook name="end_field" value="web_vhost_domain_edit:enable_pagespeed"}
242-
{tmpl_hook name="begin_field" value="web_vhost_domain_edit:active"}
240+
{tmpl_hook name="field_active"}
243241
<div class="form-group">
244242
<label class="col-sm-3 control-label">{tmpl_var name='active_txt'}</label>
245243
<div class="col-sm-9">
246244
{tmpl_var name='active'}
247245
</div>
248246
</div>
249-
{tmpl_hook name="end_field" value="web_vhost_domain_edit:active"}
250-
{tmpl_hook name="end_form" value="web_vhost_domain_edit"}
247+
{tmpl_hook name="end_form"}
251248

252249
<input type="hidden" name="id" value="{tmpl_var name='id'}">
253250

server/conf/vhost.conf.master

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<tmpl_hook name='apache2_vhost:header'>
12

23
<Directory {tmpl_var name='web_basedir'}/{tmpl_var name='domain'}>
34
AllowOverride None
@@ -9,8 +10,9 @@
910
</tmpl_if>
1011
</Directory>
1112

12-
<tmpl_loop name="vhosts">
13+
<tmpl_loop name='vhosts'>
1314
<VirtualHost {tmpl_var name='ip_address'}:{tmpl_var name='port'}>
15+
<tmpl_hook name='apache2_vhost:vhost_header'>
1416
<tmpl_if name='php' op='==' value='suphp'>
1517
DocumentRoot <tmpl_var name='web_document_root'>
1618
</tmpl_else>
@@ -444,5 +446,8 @@
444446
</IfModule>
445447

446448
<tmpl_var name='apache_directives'>
449+
<tmpl_hook name='apache2_vhost:vhost_footer'>
447450
</VirtualHost>
448451
</tmpl_loop>
452+
453+
<tmpl_hook name='apache2_vhost:footer'>

server/lib/classes/plugins.inc.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ function loadPlugins($type) {
7373
} else {
7474
$app->log('Plugins directory missing: '.$plugins_dir, LOGLEVEL_ERROR);
7575
}
76-
7776
}
7877

7978
/*
@@ -138,13 +137,15 @@ function registerAction($action_name, $plugin_name, $function_name) {
138137
}
139138

140139

141-
function raiseAction($action_name, $data) {
140+
function raiseAction($action_name, $data, $return_data = false) {
142141
global $app;
143142

144143
//* Get the subscriptions for this action
145144
$actions = (isset($this->subscribed_actions[$action_name]))?$this->subscribed_actions[$action_name]:'';
146145
if($this->debug) $app->log('Raised action: '.$action_name, LOGLEVEL_DEBUG);
147146

147+
$result = '';
148+
148149
if(is_array($actions)) {
149150
foreach($actions as $action) {
150151
$plugin_name = $action['plugin'];
@@ -154,16 +155,22 @@ function raiseAction($action_name, $data) {
154155
$app->log("Calling function '$function_name' from plugin '$plugin_name' raised by action '$action_name'.", LOGLEVEL_DEBUG);
155156
$state = call_user_func(array($app->loaded_plugins[$plugin_name], $function_name), $action_name, $data);
156157
//* ensure that we return the highest warning / error level if a error occured in one of the functions
157-
if($state == 'warning' && $state_out != 'error') $state_out = 'warning';
158-
if($state == 'error') $state_out = 'error';
158+
if($return_data) {
159+
if($state) $result .= $state;
160+
} else {
161+
if($state == 'warning' && $state_out != 'error') $state_out = 'warning';
162+
elseif($state == 'error') $state_out = 'error';
163+
}
164+
159165
unset($plugin_name);
160166
unset($function_name);
161167
}
162168
}
163169
unset($action);
164170
unset($actions);
165171

166-
return $state_out;
172+
if($return_data == true) return $result;
173+
else return $state_out;
167174
}
168175

169176
}

server/lib/classes/tpl.inc.php

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -839,28 +839,34 @@ public function __construct($tmplfile = null, $options = null)
839839
* @access private
840840
* @return mixed data/string or boolean
841841
*/
842-
private function _getData ($tmplfile, $do_eval=false)
842+
private function _getData ($tmplfile, $do_eval=false, $tmpl_from_string = false)
843843
{
844844
//* check the current file depth
845845
if ($this->_includedepth > $this->OPTIONS['MAX_INCLUDES'] || $tmplfile == false) {
846846
return;
847847
} else {
848848
if ($this->_debug){
849-
array_push($this->_debugIncludedfiles, $tmplfile);
849+
if($tmpl_from_string) array_push($this->_debugIncludedfiles, 'String: ' . substr($tmplfile, 0, 25) . '...');
850+
else array_push($this->_debugIncludedfiles, $tmplfile);
850851
}
851852
if ($do_eval) {
852-
array_push($this->_currentincludedir, dirname($tmplfile));
853+
if($tmpl_from_string == true) array_push($this->_currentincludedir, end($this->_currentincludedir));
854+
else array_push($this->_currentincludedir, dirname($tmplfile));
853855
$this->_includedepth++;
854856
}
855857
}
856858

857859

858-
if($this->_cache && $this->_checkCache($tmplfile)) { //* cache exists so lets use it
860+
if($this->_cache && $this->_checkCache($tmplfile, $tmpl_from_string)) { //* cache exists so lets use it
859861
$data = fread($fp = fopen($this->_cachefile, 'r'), filesize($this->_cachefile));
860862
fclose($fp);
861863
} else { //* no cache lets parse the file
862-
$data = fread($fp = fopen($tmplfile, 'r'), filesize($tmplfile));
863-
fclose($fp);
864+
if($tmpl_from_string == true) {
865+
$data = $tmplfile;
866+
} else {
867+
$data = fread($fp = fopen($tmplfile, 'r'), filesize($tmplfile));
868+
fclose($fp);
869+
}
864870

865871
$regex = '/(<|<\/|{|{\/|<!--|<!--\/){1}\s*';
866872
$regex.= 'tmpl_([\w]+)\s*';
@@ -884,7 +890,7 @@ private function _getData ($tmplfile, $do_eval=false)
884890
}
885891

886892
//* now we must parse the $data and check for any <tmpl_include>'s
887-
if ($this->_debug) $this->doDebugWarnings(file($tmplfile), $tmplfile);
893+
if ($this->_debug && $tmpl_from_string == false) $this->doDebugWarnings(file($tmplfile), $tmplfile);
888894

889895
if ($do_eval) {
890896
$success = @eval('?>'.$data.'<?php return 1;');
@@ -1061,6 +1067,29 @@ private function _parseIf($varname, $value = null, $op = null, $namespace = null
10611067
}
10621068
}
10631069

1070+
/**
1071+
* returns a string containing hook data
1072+
* @param string $type
1073+
* @param string $name
1074+
* @return string hook data
1075+
*/
1076+
private function _parseHook ($name)
1077+
{
1078+
global $app;
1079+
1080+
$namespace = '';
1081+
if(strpos($name, ':') !== false) list($namespace, $name) = explode(':', $name, 2);
1082+
1083+
$result = $app->plugins->raiseAction('on_template_content_hook', array(
1084+
'name' => $name,
1085+
'namespace' => $namespace,
1086+
'vars' => $this->_vars
1087+
), true);
1088+
if(!$result) $result = '';
1089+
else $result = $this->_getData($result, false, true);
1090+
1091+
return $result;
1092+
}
10641093

10651094
/**
10661095
* returns a string used for parsing in tmpl_loop statements.
@@ -1254,7 +1283,10 @@ private function _parseTag ($args)
12541283
if ($this->OPTIONS['ENABLE_PHPINCLUDE']) {
12551284
return '<?php include(\''.$file.'\'); ?>';
12561285
}
1257-
1286+
1287+
case 'hook':
1288+
return $this->_parseHook(@$var);
1289+
12581290
case 'include':
12591291
return '<?php $this->_getData($this->_fileSearch(\''.$file.'\'), 1); ?>';
12601292

server/lib/classes/tpl_cache.inc.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ function setCacheExtension($str = null) {
101101
* FUNCTION: _checkCache
102102
* checks if there's a cache, if there is then it will read the cache file as the template.
103103
*/
104-
function _checkCache ($tmplfile) {
105-
$this->_cachefile = $this->_getFilename($tmplfile);
104+
function _checkCache ($tmplfile, $tmpl_from_string = false) {
105+
$this->_cachefile = $this->_getFilename($tmplfile, $tmpl_from_string);
106106
if ($this->_clearcache) {
107107
if (file_exists($this->_cachefile)) unlink($this->_cachefile);
108108
return false;
@@ -133,8 +133,9 @@ function _checkCache ($tmplfile) {
133133
* gets the full pathname for the cached file
134134
*
135135
*/
136-
function _getFilename($tmplfile) {
137-
return $this->OPTIONS['CACHE_DIRECTORY'].'/'.md5('vlibCachestaR'.realpath($tmplfile)).'.'.$this->OPTIONS['CACHE_EXTENSION'];
136+
function _getFilename($tmplfile, $tmpl_from_string = false) {
137+
if($tmpl_from_string == true) return $this->OPTIONS['CACHE_DIRECTORY'].'/'.md5('vlibCachestaRSTRING'.$tmplfile).'.'.$this->OPTIONS['CACHE_EXTENSION'];
138+
else return $this->OPTIONS['CACHE_DIRECTORY'].'/'.md5('vlibCachestaR'.realpath($tmplfile)).'.'.$this->OPTIONS['CACHE_EXTENSION'];
138139
}
139140

140141

0 commit comments

Comments
 (0)