/** * ParseSet * This parses the $TemplateData variable for any possible variable setters in the template code. i.e. {assign varName="value"} * It then generates the PHP which uses the Assign function to set the variables for use in the template. * * @return Void Doesn't return anything * * @see TemplateData * @see Assign */ public function ParseSet() { preg_match_all('#\\{assign ([a-zA-Z0-9]+)=(true|false|["\'].+["\'])}#isU', $this->TemplateData, $matches); foreach ($matches[0] as $k => $set) { $setName = $matches[1][$k]; $setValue = $matches[2][$k]; $setPHP = ''; if (firstchar($setValue) === lastchar($setValue) && in_array(lastchar($setValue), array("'", '"'))) { $quote = firstchar($setValue); $newSetValue = substr($setValue, 1); $newSetValue = substr($newSetValue, 0, -1); $Begin = ''; $End = ''; if (firstchar($newSetValue) === '$') { $newSetValue = substr($newSetValue, 1); $arrBreakdown = explode('|', $newSetValue); $arrVar = explode('.', $arrBreakdown[0]); if (isset($arrBreakdown[1])) { $arrFunctions = explode(':', $arrBreakdown[1]); foreach ($arrFunctions as $key2 => $value2) { $arrFunc = preg_split('#,\\s*#', $value2, -1, PREG_SPLIT_NO_EMPTY); $funcName = $arrFunc[0]; if (!in_array(strtolower($funcName), $this->AllowedFunctions)) { continue; } $Begin = $funcName . '(' . $Begin; if (isset($arrFunc[1])) { array_shift($arrFunc); $args = ''; foreach ($arrFunc as $k => $arg) { $args .= ', ' . $arg; } $End .= $args . ')'; } else { $End .= ')'; } } } $newSetValue = implode("','", $arrVar); $newSetValue = $Begin . "\$tpl->Get('" . $newSetValue . "')" . $End; } else { $newSetValue = $quote . $newSetValue . $quote; } $setPHP = '<?php $tpl->Assign(\'' . $setName . '\', ' . $newSetValue . '); ?>'; } else { if ($setValue !== "true" && $setValue !== "false") { $setPHP = ''; } else { if ($setValue === "true") { $setPHP = '<?php $tpl->Assign(\'' . $setName . '\', true); ?>'; } else { $setPHP = '<?php $tpl->Assign(\'' . $setName . '\', false); ?>'; } } } $this->TemplateData = str_replace($set, $setPHP, $this->TemplateData); } }
function validate_name(&$name, $desc_prefix, &$errors, $wildcard_ok, $origin = NULL, $allow_backslash = 0) { /* List of valid characters for a label */ $valid_chars = "*ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-_"; /* Backslash may be appropriate in the mbox field, for folks with a dot in their username */ /* For example, "bleach\.boy.bboy.net" would mean "*****@*****.**" */ if ($allow_backslash) { $valid_chars .= '\\'; } $desc = "{$desc_prefix} (" . quote($name) . ")"; $errct = 0; /* Name too long */ if (strlen($name) > 255) { $errors[] = "{$desc} is too long."; $errct++; } $labels = explode(".", $name); $which = 0; foreach ($labels as $label) { $which++; /* Label too long */ if (strlen($label) > 63) { $errors[] = "{$desc} contains a label ("<TT>{$label}</TT>") which is too long."; $errct++; } /* Label contains only legal characters */ if (strspn($label, $valid_chars) != strlen($label)) { $errors[] = "{$desc} contains a label ("<TT>{$label}</TT>") with invalid characters."; $errct++; } /* If we're allowing backslashes, they may only appear at the end of a label */ if ($allow_backslash && ($p = strpos($label, '\\')) !== false && $p < strlen($label) - 1) { $errors[] = "{$desc} contains a label ("<TT>{$label}</TT>") with invalid characters -- backslash must immediately precede a dot."; $errct++; } /* Label may not begin/end with a hyphen */ if (substr($label, 0, 1) == '-') { $errors[] = "{$desc} contains a label ("<TT>{$label}</TT>") that begins with a hyphen."; $errct++; } if (lastchar($label) == '-') { $errors[] = "{$desc} contains a label ("<TT>{$label}</TT>") that ends with a hyphen."; $errct++; } /* Check wildcards */ if (strstr($label, "*")) { if (!$wildcard_ok) { $errors[] = "{$desc} may not contain wildcard labels."; $errct++; } if ($which != 1) { $errors[] = "{$desc} contains a wildcard in a non-initial label."; $errct++; } if ($label != "*") { $errors[] = "{$desc} contains a label ("<TT>{$label}</TT>") mixing a wildcard character with other data."; $errct++; } } } /* If an origin was specified, append a dot to '$name' if it ought to be there */ if ($origin) { $origin_without_dot = substr($origin, 0, strlen($origin) - 1); $end_of_name = substr($name, strlen($name) - strlen($origin_without_dot)); if (!strcasecmp($origin_without_dot, $end_of_name)) { $name .= "."; } } return $errct; }