mView = 'EditView';
}
/**
* parse
*
* @param $filePath The file path of the HTML file to parse
* @param $vardefs The module's vardefs
* @param $moduleDir The module's directory
* @param $merge boolean value indicating whether or not to merge the parsed contents
* @param $masterCopy The file path of the mater copy of the metadata file to merge against
* @return String format of metadata contents
**/
function parse($filePath, $vardefs = array(), $moduleDir = '', $merge=false, $masterCopy=null) {
global $app_strings;
$contents = file_get_contents($filePath);
$contents = $this->trimHTML($contents);
$contents = $this->stripFlavorTags($contents);
$moduleName = '';
$contents = $this->fixDuplicateTrTags($contents);
$contents = $this->fixRowsWithMissingTr($contents);
$tables = $this->getElementsByType("table", $contents);
$formElements = $this->getFormElements($tables[0]);
$hiddenInputs = array();
foreach($formElements as $elem) {
$type = $this->getTagAttribute("type", $elem);
if(preg_match('/hidden/si',$type)) {
$name = $this->getTagAttribute("name", $elem);
$value = $this->getTagAttribute("value", $elem);
$hiddenInputs[$name] = $value;
}
}
// Get the second table in the page and onward
$tables = array_slice($tables, 1);
$panels = array();
$tableCount = 0;
$addedElements = array();
$maxTableCountNum = 0;
$tableCount = 0;
foreach($tables as $table) {
$table = $this->fixTablesWithMissingTr($table);
$toptr = $this->getElementsByType("tr", $table);
foreach($toptr as $tr) {
$tabledata = $this->getElementsByType("table", $tr);
$data = array();
$panelKey = $tableCount == 0 ? "default" : '';
foreach($tabledata as $t) {
$vals = array_values($this->getElementsByType("tr", $t));
if(preg_match_all('/
]*?>.*?(\{MOD\.|\{APP\.)(LBL_[^\}]*?)[\}].*?<\/h4>/s', $vals[0], $matches, PREG_SET_ORDER)) {
array_shift($vals);
$panelKey = count($matches[0]) == 3 ? strtolower($matches[0][2]) : $panelKey;
}
//If $panelKey is empty use the maxTableCountNum value
if(empty($panelKey)) {
$panels[$maxTableCountNum++] = $vals;
} else {
$panels[$panelKey] = $vals;
}
} //foreach
$tableCount++;
} //foreach;
} //foreach
foreach($panels as $id=>$tablerows) {
$metarow = array();
foreach($tablerows as $trow) {
$emptyCount = 0;
$tablecolumns = $this->getElementsByType("td", $trow);
$col = array();
$slot = 0;
foreach($tablecolumns as $tcols) {
$hasRequiredLabel = false;
//Get the sugar attribute value in the span elements of each table row
$sugarAttrLabel = $this->getTagAttribute("sugar", $tcols, "'^slot[^b]+$'");
//If there was no sugar attribute, try id (some versions of EditView.html used this instead)
if(empty($sugarAttrLabel)) {
$sugarAttrLabel = $this->getTagAttribute("id", $tcols, "'^slot[^b]+$'");
}
//Check if this field is required
if(!empty($sugarAttrLabel)) {
$hasRequiredLabel = $this->hasRequiredSpanLabel($tcols);
}
$sugarAttrValue = $this->getTagAttribute("sugar", $tcols, "'slot[0-9]+b$'");
//If there was no sugar attribute, try id (some versions of EditView.html used this instead)
if(empty($sugarAttrValue)) {
$sugarAttrValue = $this->getTagAttribute("id", $tcols, "'slot[0-9]+b$'");
}
// If there wasn't any slot numbering/lettering then just default to expect label->vallue pairs
$sugarAttrLabel = count($sugarAttrLabel) != 0 ? $sugarAttrLabel : ($slot % 2 == 0) ? true : false;
$sugarAttrValue = count($sugarAttrValue) != 0 ? $sugarAttrValue : ($slot % 2 == 1) ? true : false;
$slot++;
if($sugarAttrValue) {
$spanValue = $this->getElementValue("span", $tcols);
if(empty($spanValue)) {
$spanValue = $this->getElementValue("slot", $tcols);
}
if(empty($spanValue)) {
$spanValue = $this->getElementValue("td", $tcols);
}
//Get all the editable form elements' names
$formElementNames = $this->getFormElementsNames($spanValue);
$customField = $this->getCustomField($formElementNames);
$name = '';
$fields = null;
$customCode = null;
if(!empty($customField)) {
// If it's a custom field we just set the name
$name = $customField;
} else if(empty($formElementNames) && preg_match_all('/[\{]([^\}]*?)[\}]/s', $spanValue, $matches, PREG_SET_ORDER)) {
// We are here if the $spanValue did not contain a form element for editing.
// We will assume that it is read only (since there were no edit form elements)
// If there is more than one matching {} value then try to find the right one to key off
// based on vardefs.php file. Also, use the entire spanValue as customCode
if(count($matches) > 1) {
$name = $matches[0][1];
$customCode = $spanValue;
foreach($matches as $pair) {
if(preg_match("/^(mod[\.]|app[\.]).*?/i", $pair[1])) {
$customCode = str_replace($pair[1], '$'.strtoupper($pair[1]), $customCode);
} else {
if(!empty($vardefs[$pair[1]])) {
$name = $pair[1];
$customCode = str_replace($pair[1], '$fields.'.strtolower($pair[1]).'.value', $customCode);
} else {
$phpName = $this->findAssignedVariableName($pair[1], $filePath);
$customCode = str_replace($pair[1], '$fields.'.strtolower($phpName).'.value', $customCode);
} //if-else
}
} //foreach
} else {
//If it is only a label, skip
if(preg_match("/^(mod[\.]|app[\.]).*?/i", $matches[0][1])) {
continue;
}
$name = strtolower($matches[0][1]);
}
} else if(is_array($formElementNames)) {
if(count($formElementNames) == 1) {
if(!empty($vardefs[$formElementNames[0]])) {
$name = $formElementNames[0];
} else {
// Try to use the EdtiView.php file to find author's intent
$name = $this->findAssignedVariableName($formElementNames[0], $filePath);
//If it's still empty, just use the entire block as customCode
if(empty($vardefs[$name])) {
//Replace any { characters just in case
$customCode = str_replace('{', '{$', $spanValue);
}
} //if-else
} else {
//If it is an Array of form elements, it is likely the _id and _name relate field combo
$relateName = $this->getRelateFieldName($formElementNames);
if(!empty($relateName)) {
$name = $relateName;
} else {
//One last attempt to scan $formElementNames for one vardef field only
$name = $this->findSingleVardefElement($formElementNames, $vardefs);
if(empty($name)) {
$fields = array();
$name = $formElementNames[0];
foreach($formElementNames as $elementName) {
if(isset($vardefs[$elementName])) {
$fields[] = $elementName;
} else {
$fields[] = $this->findAssignedVariableName($elementName, $filePath);
} //if-else
} //foreach
} //if
} //if-else
} //if-else
}
// Build the entry
if(preg_match("/