📄 functions_template.php
字号:
for ($i = 0, $size = sizeof($tokens); $i < $size; $i++) { $token = &$tokens[$i]; switch ($token) { case '!==': case '===': case '<<': case '>>': case '|': case '^': case '&': case '~': case ')': case ',': case '+': case '-': case '*': case '/': case '@': break; case '==': case 'eq': $token = '=='; break; case '!=': case '<>': case 'ne': case 'neq': $token = '!='; break; case '<': case 'lt': $token = '<'; break; case '<=': case 'le': case 'lte': $token = '<='; break; case '>': case 'gt': $token = '>'; break; case '>=': case 'ge': case 'gte': $token = '>='; break; case '&&': case 'and': $token = '&&'; break; case '||': case 'or': $token = '||'; break; case '!': case 'not': $token = '!'; break; case '%': case 'mod': $token = '%'; break; case '(': array_push($is_arg_stack, $i); break; case 'is': $is_arg_start = ($tokens[$i-1] == ')') ? array_pop($is_arg_stack) : $i-1; $is_arg = implode(' ', array_slice($tokens, $is_arg_start, $i - $is_arg_start)); $new_tokens = $this->_parse_is_expr($is_arg, array_slice($tokens, $i+1)); array_splice($tokens, $is_arg_start, sizeof($tokens), $new_tokens); $i = $is_arg_start; // no break default: if (preg_match('#^((?:[a-z0-9\-_]+\.)+)?(\$)?(?=[a-zA-Z])([a-zA-Z0-9\-_]+)#s', $token, $varrefs)) { $token = (!empty($varrefs[1])) ? $this->generate_block_data_ref(substr($varrefs[1], 0, -1), true, $varrefs[2]) . '[\'' . $varrefs[3] . '\']' : (($varrefs[2]) ? '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $varrefs[3] . '\']' : '$this->_tpldata[\'.\'][0][\'' . $varrefs[3] . '\']'); } else if (preg_match('#^\.(([a-z0-9\-_]+\.?)+)$#s', $token, $varrefs)) { echo $token; $_tok = $this->generate_block_data_ref($varrefs[1], false); $token = "(isset($_tok) && sizeof($_tok))"; } break; } } return (($elseif) ? '} else if (' : 'if (') . (implode(' ', $tokens) . ') { '); } /** * Compile DEFINE tags * @private */ function compile_tag_define($tag_args, $op) { preg_match('#^((?:[a-z0-9\-_]+\.)+)?\$(?=[A-Z])([A-Z0-9_\-]*)(?: = (\'?)([^\']*)(\'?))?$#', $tag_args, $match); if (empty($match[2]) || (empty($match[4]) && $op)) { return; } if (!$op) { return 'unset(' . (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ');'; } // Are we a string? if ($match[3] && $match[5]) { $match[4] = str_replace(array('\\\'', '\\\\', '\''), array('\'', '\\', '\\\''), $match[4]); // Compile reference, we allow template variables in defines... $match[4] = $this->compile($match[4]); // Now replace the php code $match[4] = "'" . str_replace(array('<?php echo ', '; ?>'), array("' . ", " . '"), $match[4]) . "'"; } else { preg_match('#true|false|\.#i', $match[4], $type); switch (strtolower($type[0])) { case 'true': case 'false': $match[4] = strtoupper($match[4]); break; case '.'; $match[4] = doubleval($match[4]); break; default: $match[4] = intval($match[4]); break; } } return (($match[1]) ? $this->generate_block_data_ref(substr($match[1], 0, -1), true, true) . '[\'' . $match[2] . '\']' : '$this->_tpldata[\'DEFINE\'][\'.\'][\'' . $match[2] . '\']') . ' = ' . $match[4] . ';'; } /** * Compile INCLUDE tag * @private */ function compile_tag_include($tag_args) { return "\$this->_tpl_include('$tag_args');"; } /** * Compile INCLUDE_PHP tag * @private */ function compile_tag_include_php($tag_args) { return "include('" . $this->template->root . '/' . $tag_args . "');"; } /** * parse expression * This is from Smarty * @private */ function _parse_is_expr($is_arg, $tokens) { $expr_end = 0; $negate_expr = false; if (($first_token = array_shift($tokens)) == 'not') { $negate_expr = true; $expr_type = array_shift($tokens); } else { $expr_type = $first_token; } switch ($expr_type) { case 'even': if (@$tokens[$expr_end] == 'by') { $expr_end++; $expr_arg = $tokens[$expr_end++]; $expr = "!(($is_arg / $expr_arg) % $expr_arg)"; } else { $expr = "!($is_arg % 2)"; } break; case 'odd': if (@$tokens[$expr_end] == 'by') { $expr_end++; $expr_arg = $tokens[$expr_end++]; $expr = "(($is_arg / $expr_arg) % $expr_arg)"; } else { $expr = "($is_arg % 2)"; } break; case 'div': if (@$tokens[$expr_end] == 'by') { $expr_end++; $expr_arg = $tokens[$expr_end++]; $expr = "!($is_arg % $expr_arg)"; } break; default: break; } if ($negate_expr) { $expr = "!($expr)"; } array_splice($tokens, 0, $expr_end, $expr); return $tokens; } /** * Generates a reference to the given variable inside the given (possibly nested) * block namespace. This is a string of the form: * ' . $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['varname'] . ' * It's ready to be inserted into an "echo" line in one of the templates. * NOTE: expects a trailing "." on the namespace. * @private */ function generate_block_varref($namespace, $varname, $echo = true, $defop = false) { // Strip the trailing period. $namespace = substr($namespace, 0, -1); // Get a reference to the data block for this namespace. $varref = $this->generate_block_data_ref($namespace, true, $defop); // Prepend the necessary code to stick this in an echo line. // Append the variable reference. $varref .= "['$varname']"; $varref = ($echo) ? "<?php echo $varref; ?>" : ((isset($varref)) ? $varref : ''); return $varref; } /** * Generates a reference to the array of data values for the given * (possibly nested) block namespace. This is a string of the form: * $this->_tpldata['parent'][$_parent_i]['$child1'][$_child1_i]['$child2'][$_child2_i]...['$childN'] * * If $include_last_iterator is true, then [$_childN_i] will be appended to the form shown above. * NOTE: does not expect a trailing "." on the blockname. * @private */ function generate_block_data_ref($blockname, $include_last_iterator, $defop = false) { // Get an array of the blocks involved. $blocks = explode('.', $blockname); $blockcount = sizeof($blocks) - 1; $varref = '$this->_tpldata' . (($defop) ? '[\'DEFINE\']' : ''); // Build up the string with everything but the last child. for ($i = 0; $i < $blockcount; $i++) { $varref .= "['" . $blocks[$i] . "'][\$this->_" . $blocks[$i] . '_i]'; } // Add the block reference for the last child. $varref .= "['" . $blocks[$blockcount] . "']"; // Add the iterator for the last child if requried. if ($include_last_iterator) { $varref .= '[$this->_' . $blocks[$blockcount] . '_i]'; } return $varref; } /** * Write compiled file to cache directory * @private */ function compile_write(&$handle, $data) { global $phpEx, $user; $filename = $this->template->cachepath . $this->template->filename[$handle] . '.php'; if ($fp = @fopen($filename, 'wb')) { @flock($fp, LOCK_EX); @fwrite ($fp, $data); @flock($fp, LOCK_UN); @fclose($fp); @umask(0); @chmod($filename, 0644); } return; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -