function smarty_mb_str_replace($search, $replace, $subject, &$count = 0) { if (!is_array($search) && is_array($replace)) { return false; } if (is_array($subject)) { // call mb_replace for each single string in $subject foreach ($subject as &$string) { $string =& smarty_mb_str_replace($search, $replace, $string, $c); $count += $c; } } elseif (is_array($search)) { if (!is_array($replace)) { foreach ($search as &$string) { $subject = smarty_mb_str_replace($string, $replace, $subject, $c); $count += $c; } } else { $n = max(count($search), count($replace)); while ($n--) { $subject = smarty_mb_str_replace(current($search), current($replace), $subject, $c); $count += $c; next($search); next($replace); } } } else { $parts = mb_split(preg_Quote($search), $subject); $count = count($parts) - 1; $subject = implode($replace, $parts); } return $subject; }
/** * Compiles code for the {extends} tag * * @param array $args array with attributes From parser * @param object $compiler compiler object * @return string compiled code */ public function compile($args, $compiler) { $this->compiler = $compiler; $this->smarty = $compiler->smarty; $this->_rdl = preg_Quote($this->smarty->right_delimiter); $this->_ldl = preg_Quote($this->smarty->left_delimiter); $filepath = $compiler->template->getTemplateFilepath(); // check and get attributes $_attr = $this->_get_attributes($args); if ($_attr['nocache'] === true) { $this->compiler->trigger_template_error('nocache option not allowed', $this->compiler->lex->taglineno); } $_smarty_tpl = $compiler->template; $include_file = null; if (strpos($_attr['file'], '$_tmp') !== false || strpos($_attr['file'], '$_smarty_tpl') !== false || strpos($_attr['file'], '::') !== false) { $this->compiler->trigger_template_error('a variable file attribute is illegal', $this->compiler->lex->taglineno); } eval('$include_file = ' . $_attr['file'] . ';'); // create template object $_template = new $compiler->smarty->template_class($include_file, $this->smarty, $compiler->template); // save file dependency if (in_array($_template->resource_type, array('eval', 'string'))) { $template_sha1 = sha1($include_file); } else { $template_sha1 = sha1($_template->getTemplateFilepath()); } if (isset($compiler->template->properties['file_dependency'][$template_sha1])) { $this->compiler->trigger_template_error("illegal recursive call of \"{$include_file}\"", $compiler->lex->line - 1); } $compiler->template->properties['file_dependency'][$template_sha1] = array($_template->getTemplateFilepath(), $_template->getTemplateTimestamp(), $_template->resource_type); $_content = substr($compiler->template->template_source, $compiler->lex->counter - 1); if (preg_match_all("!({$this->_ldl}block\\s(.+?){$this->_rdl})!", $_content, $s) != preg_match_all("!({$this->_ldl}/block{$this->_rdl})!", $_content, $c)) { $this->compiler->trigger_template_error('unmatched {block} {/block} pairs'); } preg_match_all("!{$this->_ldl}block\\s(.+?){$this->_rdl}|{$this->_ldl}/block{$this->_rdl}!", $_content, $_result, PREG_OFFSET_CAPTURE); $_result_count = count($_result[0]); $_start = 0; while ($_start < $_result_count) { $_end = 0; $_level = 1; while ($_level != 0) { $_end++; if (!strpos($_result[0][$_start + $_end][0], '/')) { $_level++; } else { $_level--; } } $_block_content = str_replace($this->smarty->left_delimiter . '$smarty.block.parent' . $this->smarty->right_delimiter, '%%%%SMARTY_PARENT%%%%', substr($_content, $_result[0][$_start][1] + strlen($_result[0][$_start][0]), $_result[0][$_start + $_end][1] - $_result[0][$_start][1] - +strlen($_result[0][$_start][0]))); Smarty_Internal_Compile_Block::saveBlockData($_block_content, $_result[0][$_start][0], $compiler->template, $filepath); $_start = $_start + $_end + 1; } $compiler->template->template_source = $_template->getTemplateSource(); $compiler->template->template_filepath = $_template->getTemplateFilepath(); $compiler->abort_and_recompile = true; return ''; }
function __construct($data, $compiler) { // $this->data = preg_replace("/(\r\n|\r|\n)/", "\n", $data); $this->data = $data; $this->counter = 0; $this->line = 1; $this->smarty = $compiler->smarty; $this->compiler = $compiler; $this->ldel = preg_Quote($this->smarty->left_delimiter, '/'); $this->ldel_length = strlen($this->smarty->left_delimiter); $this->rdel = preg_Quote($this->smarty->right_delimiter, '/'); $this->smarty_token_names['LDEL'] = $this->smarty->left_delimiter; $this->smarty_token_names['RDEL'] = $this->smarty->right_delimiter; }
static function saveBlockData($block_content, $block_tag, $template, $filepath) { $_rdl = preg_Quote($template->smarty->right_delimiter); $_ldl = preg_Quote($template->smarty->left_delimiter); if (0 == preg_match("!({$_ldl}block\\s+)(name=)?(\\w+|'.*'|\".*\")(\\s*?)?((append|prepend|nocache)(=true)?)?(\\s*{$_rdl})!", $block_tag, $_match)) { $error_text = 'Syntax Error in template "' . $template->getTemplateFilepath() . '" "' . htmlspecialchars($block_tag) . '" illegal options'; throw new SmartyCompilerException($error_text); } else { $_name = trim($_match[3], '\'"'); // replace {$smarty.block.child} if (strpos($block_content, $template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter) !== false) { if (isset($template->block_data[$_name])) { $block_content = str_replace($template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter, $template->block_data[$_name]['source'], $block_content); unset($template->block_data[$_name]); } else { $block_content = str_replace($template->smarty->left_delimiter . '$smarty.block.child' . $template->smarty->right_delimiter, '', $block_content); } } if (isset($template->block_data[$_name])) { if (strpos($template->block_data[$_name]['source'], '%%%%SMARTY_PARENT%%%%') !== false) { $template->block_data[$_name]['source'] = str_replace('%%%%SMARTY_PARENT%%%%', $block_content, $template->block_data[$_name]['source']); } elseif ($template->block_data[$_name]['mode'] == 'prepend') { $template->block_data[$_name]['source'] .= $block_content; } elseif ($template->block_data[$_name]['mode'] == 'append') { $template->block_data[$_name]['source'] = $block_content . $template->block_data[$_name]['source']; } } else { $template->block_data[$_name]['source'] = $block_content; } if ($_match[6] == 'append') { $template->block_data[$_name]['mode'] = 'append'; } elseif ($_match[6] == 'prepend') { $template->block_data[$_name]['mode'] = 'prepend'; } else { $template->block_data[$_name]['mode'] = 'replace'; } $template->block_data[$_name]['file'] = $filepath; } }
/** * Evaluates the message and returns modifications for inline images and backgrounds * @access public * @return $message */ public function MsgHTML($message, $basedir = '') { preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images); if (isset($images[2])) { foreach ($images[2] as $i => $url) { // do not change urls for absolute images (thanks to corvuscorax) if (!preg_match('#^[A-z]+://#', $url)) { $filename = basename($url); $directory = dirname($url); $directory == '.' ? $directory = '' : ''; $cid = 'cid:' . md5($filename); $ext = pathinfo($filename, PATHINFO_EXTENSION); $mimeType = self::_mime_types($ext); if (strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; } if (strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; } if ($this->AddEmbeddedImage($basedir . $directory . $filename, md5($filename), $filename, 'base64', $mimeType)) { $message = preg_replace("/" . $images[1][$i] . "=\"" . preg_Quote($url, '/') . "\"/Ui", $images[1][$i] . "=\"" . $cid . "\"", $message); } } } } $this->IsHTML(true); $this->Body = $message; $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\\/\\1>/s', '', $message))); if (!empty($textMsg) && empty($this->AltBody)) { $this->AltBody = html_entity_decode($textMsg); } if (empty($this->AltBody)) { $this->AltBody = 'To view this email message, open it in a program that understands HTML!' . "\n\n"; } }
public function __construct($smarty) { $this->smarty = $smarty; $this->_rdl = preg_Quote($smarty->right_delimiter); $this->_ldl = preg_Quote($smarty->left_delimiter); }