blob: 8a9a4d25434baed366d2018d18fd4a59dcf22580 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
<?php
/**
* smarty_prefilter_add_link_ticket This will insert a ticket on all template URL's that have GET parameters.
*
* @param string $pTplSource source of template
* @return string ammended template source
*/
namespace Bitweaver\Plugins;
use Smarty\Compile\Modifier\ModifierCompilerInterface;
use Smarty\Compiler\Template;
class AddLinkTicket implements ModifierCompilerInterface {
public function __construct() {
// Initialization code
}
public function compile($params, Template $template) {
global $gBitUser;
$source = $params[0];
if( is_object( $gBitUser ) && $gBitUser->isRegistered() ) {
// $from = '#href="(.*PKG_URL.*php)\?(.*)&(.*)"#i';
// $to = 'href="\\1?\\2&tk={$gBitUser->mTicket}&\\3"';
// $pTplSource = preg_replace( $from, $to, $pTplSource );
$from = '#<form([^>]*)>#i';
// div tag is for stupid XHTML compliance.
$to = '<form\\1><div style="display:inline"><input type="hidden" name="tk" value="{$gBitUser->mTicket}" /></div>';
$pTplSource = preg_replace( $from, $to, $source );
if( strpos( $pTplSource[0], '{form}' )) {
$source = str_replace( '{form}', '{form}<div style="display:inline"><input type="hidden" name="tk" value="{$gBitUser->mTicket}" /></div>', $pTplSource );
} elseif( strpos( $pTplSource[0], '{form ' ) ) {
$from = '#\{form(\}| [^\}]*)\}#i';
$to = '{form\\1}<div style="display:inline"><input type="hidden" name="tk" value="{$gBitUser->mTicket}" /></div>';
$source = preg_replace( $from, $to, $pTplSource );
}
}
return $source;
}
}
|