libs/sysplugins/smarty_internal_extension_codeframe.php Quellcode

smarty_internal_extension_codeframe.php
gehe zur Dokumentation dieser Datei
1 <?php
16 {
26  public static function create(Smarty_Internal_Template $_template, $content = '', $cache = false)
27  {
28  // build property code
29  $_template->properties['has_nocache_code'] = $_template->has_nocache_code || !empty($_template->required_plugins['nocache']);
30  $_template->properties['version'] = Smarty::SMARTY_VERSION;
31  if (!isset($_template->properties['unifunc'])) {
32  $_template->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
33  }
34  $properties = $_template->properties;
35  if (!$cache) {
36  unset($properties['tpl_function']);
37  if (!empty($_template->compiler->templateProperties)) {
38  $properties['tpl_function'] = $_template->compiler->templateProperties['tpl_function'];
39  }
40  }
41  $output = "<?php\n";
42  $output .= "/*%%SmartyHeaderCode:{$_template->properties['nocache_hash']}%%*/\n";
43  if ($_template->smarty->direct_access_security) {
44  $output .= "if(!defined('SMARTY_DIR')) exit('no direct access allowed');\n";
45  }
46  $output .= "\$_valid = \$_smarty_tpl->decodeProperties(" . var_export($properties, true) . ',' . ($cache ? 'true' : 'false') . ");\n";
47  $output .= "/*/%%SmartyHeaderCode%%*/\n";
48  $output .= "if (\$_valid && !is_callable('{$_template->properties['unifunc']}')) {\n";
49  $output .= "function {$_template->properties['unifunc']} (\$_smarty_tpl) {\n";
50  // include code for plugins
51  if (!$cache) {
52  if (!empty($_template->required_plugins['compiled'])) {
53  foreach ($_template->required_plugins['compiled'] as $tmp) {
54  foreach ($tmp as $data) {
55  $file = addslashes($data['file']);
56  if (is_Array($data['function'])) {
57  $output .= "if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n";
58  } else {
59  $output .= "if (!is_callable('{$data['function']}')) require_once '{$file}';\n";
60  }
61  }
62  }
63  }
64  if (!empty($_template->required_plugins['nocache'])) {
65  $_template->has_nocache_code = true;
66  $output .= "echo '/*%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/<?php \$_smarty = \$_smarty_tpl->smarty; ";
67  foreach ($_template->required_plugins['nocache'] as $tmp) {
68  foreach ($tmp as $data) {
69  $file = addslashes($data['file']);
70  if (is_Array($data['function'])) {
71  $output .= addslashes("if (!is_callable(array('{$data['function'][0]}','{$data['function'][1]}'))) require_once '{$file}';\n");
72  } else {
73  $output .= addslashes("if (!is_callable('{$data['function']}')) require_once '{$file}';\n");
74  }
75  }
76  }
77  $output .= "?>/*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/';\n";
78  }
79  }
80  $output .= "?>\n";
81  $output = self::appendCode($output, $content);
82  return self::appendCode($output, "<?php }\n}\n?>");
83  }
84 
93  public static function createFunctionFrame(Smarty_Internal_Template $_template, $content = '')
94  {
95  if (!isset($_template->properties['unifunc'])) {
96  $_template->properties['unifunc'] = 'content_' . str_replace(array('.', ','), '_', uniqid('', true));
97  }
98  $output = "<?php\n";
99  $output .= "/*%%SmartyHeaderCode:{$_template->properties['nocache_hash']}%%*/\n";
100  $output .= "if (\$_valid && !is_callable('{$_template->properties['unifunc']}')) {\n";
101  $output .= "function {$_template->properties['unifunc']} (\$_smarty_tpl) {\n";
102  $output .= "?>\n" . $content;
103  $output .= "<?php\n";
104  $output .= "/*/%%SmartyNocache:{$_template->properties['nocache_hash']}%%*/\n";
105  $output .= "}\n}\n?>";
106  return $output;
107  }
108 
117  public static function appendCode($left, $right)
118  {
119  if (preg_match('/\s*\?>$/', $left) && preg_match('/^<\?php\s+/', $right)) {
120  $left = preg_replace('/\s*\?>$/', "\n", $left);
121  $left .= preg_replace('/^<\?php\s+/', '', $right);
122  } else {
123  $left .= $right;
124  }
125  return $left;
126  }
127 }




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.