Example #1
0
 function add_hidden_fields(&$attr_custom, $params, $node)
 {
     global $FUNCS, $PAGE;
     if (!strlen($this->users_tpl)) {
         return;
     }
     // take the opportunity to add the hidden fields
     if ($PAGE->tpl_name == $this->users_tpl) {
         $html = "\n                <cms:ignore>\n                <cms:editable name='extended_user_css' type='message'>\n                <style type=\"text/css\">\n                    #k_element_extended_user_id,\n                    #k_element_extended_user_email\n                    { display:none; }\n                </style>\n                </cms:editable>\n                </cms:ignore>\n                <cms:editable label='Extended-User ID' name='extended_user_id' search_type='integer' type='text'>0</cms:editable>\n                <cms:editable label='Extended-User Email' name='extended_user_email' type='text' />\n                <cms:editable label='New Password' name='extended_user_password' type='dummy_password' />\n                <cms:editable label='Repeat New Password' name='extended_user_password_repeat' type='dummy_password' />\n                ";
         $parser = new KParser($html, $node->line_num, 0, '', $node->ID);
         $dom = $parser->get_DOM();
         foreach ($dom->children as $child_node) {
             if ($child_node->type == K_NODE_TYPE_CODE) {
                 $node->children[] = $child_node;
             }
         }
     }
 }
Example #2
0
 function &get_DOM()
 {
     if (!$this->parsed) {
         $starts = $this->pos;
         $len = strlen($this->str);
         $tag_name = '';
         $closing_tag_name = '';
         $attributes = array();
         $attr = null;
         $quote_type = 0;
         $processing_cond = false;
         // Conditional tags requires special consideration
         $brackets_count = 0;
         while ($this->pos < $len) {
             $c = $this->str[$this->pos];
             if ($c == "\n") {
                 $this->line_num++;
             }
             switch ($this->state) {
                 case K_STATE_TEXT:
                     if ($c == '<') {
                         if (substr($this->str, $this->pos + 1, strlen(K_START_TAG_IDENT)) == K_START_TAG_IDENT) {
                             $text = substr($this->str, $starts, $this->pos - $starts);
                             if ($this->quit_at_char == '"') {
                                 $text = str_replace('\\"', '"', $text);
                             }
                             $this->add_child(K_NODE_TYPE_TEXT, '', '', $text);
                             $this->pos += strlen(K_START_TAG_IDENT);
                             $starts = $this->pos + 1;
                             $this->state = K_STATE_TAG_NAME;
                         } elseif (substr($this->str, $this->pos + 1, strlen(K_END_TAG_IDENT)) == K_END_TAG_IDENT) {
                             $text = substr($this->str, $starts, $this->pos - $starts);
                             if ($this->quit_at_char == '"') {
                                 $text = str_replace('\\"', '"', $text);
                             }
                             $this->add_child(K_NODE_TYPE_TEXT, '', '', $text);
                             $this->pos += strlen(K_END_TAG_IDENT);
                             $starts = $this->pos + 1;
                             $this->state = K_STATE_TAG_CLOSE;
                         }
                     } elseif ($this->quit_at_char && $c == $this->quit_at_char) {
                         if ($this->str[$this->pos - 1] != '\\') {
                             break 2;
                         }
                     }
                     break;
                 case K_STATE_TAG_OPEN:
                     if ($processing_cond && $brackets_count) {
                         $this->raise_error("Unclosed bracket in \"" . $tag_name . "\"", $this->line_num, $this->pos);
                     }
                     if (isset($attr)) {
                         $attributes[] = $attr;
                     }
                     for ($x = 0; $x < count($attributes); $x++) {
                         $attr =& $attributes[$x];
                         if (!isset($attr['value']) && isset($attr['name'])) {
                             $attr['value'] = $attr['name'];
                             $attr['value_type'] = K_VAL_TYPE_VARIABLE;
                             if (!$processing_cond) {
                                 $attr['op'] = '=';
                             }
                             unset($attr['name']);
                         } elseif (!$processing_cond && !isset($attr['name']) && isset($attr['value'])) {
                             $attr['op'] = '=';
                         }
                         if ($attr['value_type'] == K_VAL_TYPE_LITERAL) {
                             $quote_type = $attr['quote_type'];
                             $attr['value'] = str_replace('\\' . $quote_type, $quote_type, $attr['value']);
                         }
                     }
                     $push = $this->str[$this->pos - 1] != '/';
                     $this->add_child(K_NODE_TYPE_CODE, $tag_name, $attributes, '', $push);
                     $processing_cond = false;
                     $brackets_count = 0;
                     $starts = $this->pos + 1;
                     $this->state = K_STATE_TEXT;
                     break;
                 case K_STATE_TAG_CLOSE:
                     if ($c == '>') {
                         $closing_tag_name = trim(substr($this->str, $starts, $this->pos - $starts));
                         if ($this->curr_node->name != $closing_tag_name) {
                             $this->raise_error("Closing tag \"" . $closing_tag_name . "\" has no matching opening tag", $this->line_num, $this->pos);
                         }
                         unset($this->curr_node);
                         $this->curr_node =& $this->stack[count($this->stack) - 1];
                         unset($this->stack[count($this->stack) - 1]);
                         $starts = $this->pos + 1;
                         $this->state = K_STATE_TEXT;
                     }
                     break;
                 case K_STATE_TAG_NAME:
                     if (!($this->pos == $starts ? $this->is_valid_for_label($c, 0) : $this->is_valid_for_label($c))) {
                         if ($this->is_white_space($c) && $this->pos != $starts) {
                             $tag_name = substr($this->str, $starts, $this->pos - $starts);
                             if ($tag_name == 'if' || $tag_name == 'while' || $tag_name == 'not' || $tag_name == 'else_if') {
                                 $processing_cond = true;
                             }
                             $starts = $this->pos + 1;
                             $this->state = K_STATE_ATTR_NAME;
                         } elseif ($c == '>' || $c == '/' && $this->str[$this->pos + 1] == '>') {
                             $tag_name = substr($this->str, $starts, $this->pos - $starts);
                             if ($c == '>') {
                                 $this->pos--;
                             }
                             $this->state = K_STATE_TAG_OPEN;
                         } else {
                             $this->raise_error("TAG_NAME: Invalid char \"" . $c . "\" in tagname", $this->line_num, $this->pos);
                         }
                     } else {
                         if ($this->pos == $starts) {
                             //First valid char
                             $attributes = array();
                             unset($attr);
                         }
                     }
                     break;
                 case K_STATE_ATTR_NAME:
                     if (!($this->pos == $starts ? $this->is_valid_for_label($c, 0) : $this->is_valid_for_label($c))) {
                         if ($this->is_white_space($c)) {
                             if ($this->pos != $starts) {
                                 $attr['name'] = substr($this->str, $starts, $this->pos - $starts);
                                 $this->state = K_STATE_ATTR_OP;
                             } else {
                                 $starts++;
                             }
                         } elseif (($c == '"' || $c == "'") && $this->pos == $starts) {
                             if (isset($attr)) {
                                 $attributes[] = $attr;
                             }
                             $attr = array();
                             $this->pos--;
                             $this->state = K_STATE_ATTR_VAL;
                         } elseif ($processing_cond && $this->pos == $starts && $c == '(') {
                             if (isset($attr)) {
                                 $attributes[] = $attr;
                             }
                             $attr = array();
                             $attr['op'] = $c;
                             $brackets_count++;
                             $starts++;
                         } elseif ($processing_cond && $this->pos != $starts && ($this->is_logical_op() || $c == ')')) {
                             $attr['name'] = substr($this->str, $starts, $this->pos - $starts);
                             $starts = $this->pos;
                             $this->pos--;
                             $this->state = K_STATE_LOGIC_OP;
                         } elseif ($c == '=' || $processing_cond && $this->pos != $starts && $this->is_cond_op()) {
                             if (isset($attr['value_type'])) {
                                 // a prev standalone 'value' remains unprocessed
                                 $this->raise_error("ATTRIB_NAME: Invalid char \"" . $c . "\"", $this->line_num, $this->pos);
                             }
                             $attr['name'] = substr($this->str, $starts, $this->pos - $starts);
                             $this->pos--;
                             $this->state = K_STATE_ATTR_OP;
                         } elseif ($c == '>' || $c == '/' && $this->str[$this->pos + 1] == '>') {
                             if (isset($attr) && in_array($attr['op'], $this->logical_ops)) {
                                 $this->raise_error("ATTRIB_NAME: Orphan \"" . $attr['op'] . "\"", $this->line_num, $this->pos);
                             }
                             if ($this->pos != $starts) {
                                 $attr['name'] = substr($this->str, $starts, $this->pos - $starts);
                             }
                             if ($c == '>') {
                                 $this->pos--;
                             }
                             $this->state = K_STATE_TAG_OPEN;
                         } else {
                             $this->raise_error("ATTRIB_NAME: Invalid char \"" . $c . "\"", $this->line_num, $this->pos);
                         }
                     } else {
                         if ($this->pos == $starts) {
                             //First valid char
                             if (isset($attr)) {
                                 $attributes[] = $attr;
                             }
                             $attr = array();
                         }
                     }
                     break;
                 case K_STATE_ATTR_OP:
                     if ($this->is_white_space($c)) {
                     } elseif ($processing_cond && ($op = $this->is_logical_op() || $c == ')')) {
                         $starts = $this->pos;
                         $this->pos--;
                         $this->state = K_STATE_LOGIC_OP;
                     } elseif ($processing_cond && ($op = $this->is_cond_op())) {
                         $this->pos++;
                         $attr['op'] = $op;
                         $starts = $this->pos + 1;
                         $this->state = K_STATE_ATTR_VAL;
                     } elseif ($c == '>' || $c == '/' && $this->str[$this->pos + 1] == '>') {
                         if ($c == '>') {
                             $this->pos--;
                         }
                         $this->state = K_STATE_TAG_OPEN;
                     } elseif ($c == '=') {
                         $op = '=';
                         $attr['op'] = $op;
                         $starts = $this->pos + 1;
                         $this->state = K_STATE_ATTR_VAL;
                     } elseif ($this->is_valid_for_label($c, 0) || $c == '"' || $c == "'") {
                         $starts = $this->pos;
                         $this->pos--;
                         $this->state = K_STATE_ATTR_NAME;
                     } else {
                         $this->raise_error("OPERATOR: Invalid char \"" . $c . "\"", $this->line_num, $this->pos);
                     }
                     break;
                 case K_STATE_ATTR_VAL:
                     if ($starts == $this->pos) {
                         if ($this->is_white_space($c)) {
                             $starts++;
                         } elseif ($c == '"' || $c == "'") {
                             $quote_type = $c;
                             // A double-quoted value might contain nested code.
                             if ($quote_type == '"') {
                                 $code_starts = strpos($this->str, '<' . K_START_TAG_IDENT, $this->pos + 1);
                                 $next_quote = $this->find_next_quote($this->pos + 1);
                                 if ($code_starts !== false && $next_quote !== false && $code_starts < $next_quote) {
                                     $attr['value_type'] = K_VAL_TYPE_SPECIAL;
                                     $parser = new KParser($this->str, $this->line_num, $this->pos + 1, '"', $this->id_prefix);
                                     $attr['value'] = $parser->get_DOM();
                                     $this->line_num = $parser->line_num;
                                     $this->pos = $parser->pos;
                                     $starts = $this->pos + 1;
                                     if ($processing_cond) {
                                         $this->state = K_STATE_LOGIC_OP;
                                     } else {
                                         $this->state = K_STATE_ATTR_NAME;
                                     }
                                 }
                             }
                         } else {
                             $quote_type = 0;
                             if (!$this->is_valid_for_label($c, 0)) {
                                 $this->raise_error("ATTRIB_VALUE: Invalid first char \"" . $c . "\"", $this->line_num, $this->pos);
                             }
                         }
                     } else {
                         if (!$quote_type) {
                             if (!$this->is_valid_for_label($c)) {
                                 if ($c == '>' || $c == '/' && $this->str[$this->pos + 1] == '>') {
                                     $attr['value'] = substr($this->str, $starts, $this->pos - $starts);
                                     $attr['value_type'] = K_VAL_TYPE_VARIABLE;
                                     if ($c == '>') {
                                         $this->pos--;
                                     }
                                     $this->state = K_STATE_TAG_OPEN;
                                 } elseif ($this->is_white_space($c)) {
                                     $attr['value'] = substr($this->str, $starts, $this->pos - $starts);
                                     $attr['value_type'] = K_VAL_TYPE_VARIABLE;
                                     $starts = $this->pos + 1;
                                     if ($processing_cond) {
                                         $this->state = K_STATE_LOGIC_OP;
                                     } else {
                                         $this->state = K_STATE_ATTR_NAME;
                                     }
                                 } elseif ($processing_cond && ($this->is_logical_op() || $c == ')')) {
                                     $attr['value'] = substr($this->str, $starts, $this->pos - $starts);
                                     $attr['value_type'] = K_VAL_TYPE_VARIABLE;
                                     $starts = $this->pos;
                                     $this->pos--;
                                     $this->state = K_STATE_LOGIC_OP;
                                 } else {
                                     $this->raise_error("ATTRIB_VALUE: Invalid char \"" . $c . "\"", $this->line_num, $this->pos);
                                 }
                             }
                         } else {
                             if ($c == $quote_type) {
                                 if ($this->str[$this->pos - 1] != '\\') {
                                     $starts++;
                                     $attr['value'] = substr($this->str, $starts, $this->pos - $starts);
                                     $attr['value_type'] = K_VAL_TYPE_LITERAL;
                                     $attr['quote_type'] = $quote_type;
                                     $starts = $this->pos + 1;
                                     if ($processing_cond) {
                                         $this->state = K_STATE_LOGIC_OP;
                                     } else {
                                         $this->state = K_STATE_ATTR_NAME;
                                     }
                                 }
                             }
                         }
                     }
                     break;
                 case K_STATE_LOGIC_OP:
                     if ($this->is_white_space($c)) {
                         $starts++;
                     } elseif ($op = $this->is_logical_op()) {
                         if (isset($attr)) {
                             $attributes[] = $attr;
                         }
                         $attr = array();
                         $attr['op'] = substr($this->str, $starts, 2);
                         $this->pos++;
                         $starts = $this->pos + 1;
                         $this->state = K_STATE_ATTR_NAME;
                     } elseif ($processing_cond && $c == ')') {
                         $brackets_count--;
                         if ($brackets_count < 0) {
                             $this->raise_error("LOGIC_OP: Closing bracket has no matching open bracket", $this->line_num, $this->pos);
                         }
                         if (isset($attr)) {
                             $attributes[] = $attr;
                         }
                         $attr = array();
                         $attr['op'] = $c;
                         $starts++;
                     } elseif ($c == '>' || $c == '/' && $this->str[$this->pos + 1] == '>') {
                         if ($c == '>') {
                             $this->pos--;
                         }
                         $this->state = K_STATE_TAG_OPEN;
                     } else {
                         $this->raise_error("LOGIC_OP: Invalid char \"" . $c . "\"", $this->line_num, $this->pos);
                     }
                     break;
             }
             $this->pos++;
         }
         if ($this->state != K_STATE_TEXT) {
             $this->raise_error("Parsing ended in an invalid state", $this->line_num, $this->pos);
         }
         if (count($this->stack)) {
             if (count($this->stack) > 1) {
                 $dangling_tag =& $this->stack[count($this->stack) - 1];
             } else {
                 $dangling_tag = $this->curr_node;
             }
             $this->raise_error("Tag \"" . @$dangling_tag->name . "\" has no matching closing tag", $this->line_num, $this->pos);
         }
         $text = substr($this->str, $starts, $this->pos - $starts);
         if ($this->quit_at_char == '"') {
             $text = str_replace('\\"', '"', $text);
         }
         $this->add_child(K_NODE_TYPE_TEXT, '', '', $text);
         $this->parsed = true;
     }
     return $this->DOM;
 }