+fwrite($m, $xmi_half. $LISTITEM."\n".$xmi_end);
+exit;
+//}}}
+
+//parsePARENTHESIS {{{
+//This function receives the content between the parenthesis ( with the ( and the ) )
+//It's a recursive function
+//Returns an array of arrays
+function parseParenthesis($value) {
+
+ $pos = 0;
+ $content = true;
+ $char = true;
+ $value = substr(substr(trim($value), 1), 0, strrpos(substr(trim($value), 1),')')); //Removes the ( and the )
+
+ while ($char) {
+ //I look for the following separation ( , or = ) {{{
+ //If its an = then I check if the next character is an >
+ if (!strpos($value, ',') && !strpos($value, '=')) {
+ $char = false;
+ }
+ elseif (!strpos($value, ',') && strpos($value, '=')) {
+ if ($value{strpos($value, '=') + 1} == '>') {
+ $char = '=>';
+ }
+ else {
+ $char = '=';
+ }
+ }
+ elseif (strpos($value, ',') && !strpos($value, '=')) {
+ $char = ',';
+ }
+ elseif (strpos($value, ',') && strpos($value, '=') && strpos($value, ',') > strpos($value, '=')) {
+ if ($value{strpos($value, '=') + 1} == '>') {
+ $char = '=>';
+ }
+ else {
+ $char = '=';
+ }
+ }
+ elseif (strpos($value, ',') && strpos($value, '=') && strpos($value, ',') < strpos($value, '=')) {
+ $char = ',';
+ }
+ //}}}
+
+ //Get's the option name {{{
+ $result[$pos]['name'] = (strpos($value, $char)) ? substr($value, 0, strpos($value, $char)) : $value;
+ $pos_del = strpos($value, $char);
+ //}}}
+
+ //If $char is an = or an =>, gets the option value {{{
+ if ($char == '=') {
+ $op_value = (strpos($value, $char)) ? trim(substr($value, strpos($value, $char) + 1)) : false;
+ }
+ elseif ($char == '=>') {
+ $op_value = (strpos($value, $char)) ? trim(substr($value, strpos($value, $char) + 2)) : false;
+ }
+ //}}}
+
+ //Parse the rest of the line {{{
+ if ($op_value) {
+ if ($op_value{0} == "'" || $op_value{0} == '"') {
+ $pos_del = parseString($op_value);
+ if ($pos_del == 0) {
+ $result[$pos]['value'] = "''";
+ }
+ else {
+ $op_value = substr($op_value, 1);
+ $result[$pos]['value'] = substr($op_value, 0, $pos_del);
+ }
+ }
+ elseif (trim(strtolower(substr($op_value, 0 ,5))) == 'array') { //Recursive part {{{
+ $op_value = trim(substr($op_value, 5));
+ $op_value = trim(substr($op_value, 1)); //Removes the (
+
+ if ($op_value{0} == ')') {
+ $result[$pos]['value'] = 'array()';
+ }
+ else {
+ //I look for the colsing ) {{{
+ $subpos = 0;
+ $continue = true;
+ $temp = $op_value;
+ while ($continue) {
+ if (($temp{$subpos} == '"' || $temp{$subpos} == "'") && $temp{$subpos - 1} != '\\') {
+ $pos_del = parseString(substr($temp,$subpos)) + $subpos;
+ $subpos = $pos_del + 2;
+
+ if (trim($temp{$subpos}) == ')') {
+ $continue = false;
+ }
+ }
+ else {
+ if ($subpos > strlen($temp)) {
+ $continue = false;
+ }
+ $subpos++;
+ }
+ }
+ //}}}
+ $par = parseParenthesis('('.substr($op_value, 0 , $subpos).')');
+ $result[$pos]['value'] = 'array(';
+ foreach ($par as $p) {
+ $result[$pos]['value'] .= $p['name'];
+ if (@$p['value']) {
+ $result[$pos]['value'] .= '=>\''.$p['value'].'\',';
+ }
+ else {
+ $result[$pos]['value'] .= ',';
+ }
+ }
+ $result[$pos]['value'] = rtrim($result[$pos]['value'],',');
+ $result[$pos]['value'] .= ')';
+ $pos_del = $subpos;
+ }
+ } //}}}
+ else {
+ //Look for the next parameter. If its the last one
+ //I assign it as it came.
+ if ($pos_del = strpos($op_value, ',')) {
+ $result[$pos]['value'] = ($pos_del) ? trim(substr($op_value, 0, $pos_del)): $op_value;
+ }
+ }
+ $value = $op_value;
+ }
+ //}}}
+
+ //Removes from $value the part that's alredy parsed {{{
+ if ($pos_del) {
+ $value = trim(substr(trim($value), $pos_del + 2));
+ }
+ if (!$value) {
+ $char = false;
+ }
+ //}}}
+ $pos++;
+ $op_value='';
+ }
+ return $result;
+}
+//}}}
+//parseString {{{
+//Funtion that parse the content between "" or ''
+//Returns the position of the final ' or "
+function parseString($value) {
+ $result = -1;
+ $ii = 1;
+ $cont = true;
+ switch ($value{0}) { //{{{
+ case "'":
+ $char = "'";
+ break;
+ case '"':
+ $char = '"';
+ break;
+ }//}}}
+ $value = substr($value, 1); //Removes the ' or the " from the beginning of the string
+ if ($value{0} == $char) {
+ $result = 0;
+ }
+ else {
+ while ($cont) { //{{{
+ $ii++;
+ if ($value{$ii} == $char) {
+ if ($value{$ii - 1} != '\\') {
+ $cont = false;
+ $result = $ii;
+ }
+ }
+ }//}}}
+ }
+ return $result;
+}