/** * close the current template * * @access private * @return boolean true on success */ function _closeTemplate($tmpl, $data) { $name = array_pop($this->_path); $data = $this->_adjustWhitespace($data, $tmpl['attributes']['whitespace']); array_pop($this->_inheritAtts); /** * check for special templates */ switch ($tmpl['attributes']['type']) { /** * check for whitespace in conditional templates * and raise a notice */ case 'condition': case 'modulo': if (trim($data) != '') { patErrorManager::raiseNotice(PATTEMPLATE_READER_NOTICE_INVALID_CDATA_SECTION, $this->_createErrorMessage(sprintf('No cdata is allowed inside a template of type %s (cdata was found in %s)', $tmpl['attributes']['type'], $tmpl['name']))); } $data = null; break; } /** * store the content */ $tmpl['content'] = $data; /** * No external template */ if (!isset($tmpl['attributes']['src'])) { $tmpl['loaded'] = true; } /** * add it to the dependencies */ if (!empty($this->_tmplStack)) { $this->_addToParentTag('dependencies', $name); if (isset($tmpl['attributes']['placeholder'])) { if ($tmpl['attributes']['placeholder'] === 'none') { $tmpl['attributes']['placeholder'] = '__none'; } if ($tmpl['attributes']['placeholder'] !== '__none') { $this->_characterData($this->_startTag . strtoupper($tmpl['attributes']['placeholder']) . $this->_endTag); } } else { $this->_characterData(sprintf("%sTMPL:%s%s", $this->_startTag, strtoupper($name), $this->_endTag)); } } unset($tmpl['name']); unset($tmpl['tag']); $this->_templates[$name] = $tmpl; return true; }
/** * register a new event * * After registering an event, you may register one or more * event handlers for this event an then trigger the event. * * This lets you extend the functionality of patForms. * * @access public * @param string event name * @return boolean true, if event could be registered * @see registerEventHandler() * @see triggerEvent() */ function registerEvent($name) { $event = 'on' . $name; if (in_array($event, $this->_validEvents)) { return patErrorManager::raiseNotice(PATFORMS_NOTICE_EVENT_ALREADY_REGISTERED, 'Event "' . $event . '" already has been registered or is built-in event'); } array_push($this->_validEvents, $event); return true; }
/** * addValidationError * * * @access public * @param integer $code * @param array $vars fill named placeholder with values * @return boolean $result true on success */ function addValidationError($code, $vars = array()) { $error = false; $lang = $this->locale; $element = $this->getElementName(); // find error message for selected language while (true) { // error message matches language code if (isset($this->validatorErrorCodes[$lang][$code])) { $error = array("element" => $element, "code" => $code, "message" => $this->validatorErrorCodes[$lang][$code]); break; } else { if ($lang == "C") { break; } } $lang_old = $lang; // look for other languages if (strlen($lang) > 5) { list($lang, $trash) = explode(".", $lang); } else { if (strlen($lang) > 2) { list($lang, $trash) = explode("_", $lang); } else { $lang = "C"; } } // inform developer about missing language patErrorManager::raiseNotice(PATFORMS_ELEMENT_ERROR_VALIDATOR_ERROR_LOCALE_UNDEFINED, "Required Validation Error-Code for language: {$lang_old} not available. Now trying language: {$lang}", "Add language definition in used element or choose other language"); } // get default Error! if (!$error) { patErrorManager::raiseWarning(PATFORMS_ELEMENT_ERROR_VALIDATOR_ERROR_UNDEFINED, "No Error Message for this validation Error was defined", "Review the error-definition for validation-errors in your element '{$element}'."); $error = array("element" => $element, "code" => 0, "message" => "Unknown validation Error"); } // insert values to placeholders if (!empty($vars)) { foreach ($vars as $key => $value) { $error["message"] = str_replace("[" . strtoupper($key) . "]", $value, $error["message"]); } } array_push($this->validationErrors, $error); $this->valid = false; return true; }