2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
40 * DetailViewMetaParser.php
41 * This is a utility file that attempts to provide support for parsing pre 5.0 SugarCRM
42 * DetailView.html files and produce a best guess detailviewdefs.php file equivalent.
46 require_once('include/SugarFields/Parsers/MetaParser.php');
49 * DetailViewMetaParser.php
50 * This class is responsible for handling the parsing of DetailView.html files from
51 * SugarCRM versions prior to 5.x. It will make a best guess of translating the
52 * HTML file to a metadata format.
56 class DetailViewMetaParser extends MetaParser {
58 function DetailViewMetaParser() {
59 $this->mView = 'DetailView';
66 * @param $filePath The file path of the HTML file to parse
67 * @param $vardefs The module's vardefs
68 * @param $moduleDir The module's directory
69 * @param $merge boolean value indicating whether or not to merge the parsed contents
70 * @param $masterCopy The file path of the mater copy of the metadata file to merge against
71 * @return String format of metadata contents
73 function parse($filePath, $vardefs = array(), $moduleDir = '', $merge=false, $masterCopy=null) {
76 $contents = file_get_contents($filePath);
78 // Remove \n,\r characters to allow for better text parsing
79 $contents = $this->trimHTML($contents);
80 $contents = $this->stripFlavorTags($contents);
83 // Notes DetailView.html file is messed up
84 if($moduleDir == 'Notes') {
85 $contents = str_replace('{PAGINATION}<tr><td>', '{PAGINATION}', $contents);
86 $contents = str_replace('</td></tr></table><script>', '</table><script>', $contents);
87 $contents = str_replace("<tr><div id='portal_flag_row' name='portal_flag_row' style='display:none'>", "<div id='portal_flag_row' name='portal_flag_row' style='display:none'>", $contents);
90 $contents = $this->fixDuplicateTrTags($contents);
91 $contents = $this->fixRowsWithMissingTr($contents);
94 $tables = $this->getElementsByType("table", $contents);
97 $tables = array_slice($tables, 1);
102 foreach($tables as $table) {
104 $table = $this->fixTablesWithMissingTr($table);
105 $tablerows = $this->getElementsByType("tr", $table);
107 foreach($tablerows as $trow) {
109 $metacolumns = array();
110 $columns = $this->getElementsByType("td", $trow);
111 $columns = array_reverse($columns, true);
112 foreach($columns as $tcols) {
114 $sugarAttrValue = $this->getTagAttribute("sugar", $tcols, "'slot[0-9]+b$'");
115 if(empty($sugarAttrValue)) {
120 $field = $this->getElementValue("span", $tcols);
121 //If it's a space, simply add a blank string
122 if($field == ' ') {
124 } else if(!empty($field)) {
126 preg_match_all('/[\{]([^\}].*?)[\}]/s', $field, $matches, PREG_SET_ORDER);
127 if(!empty($matches)) {
128 if(count($matches) > 1) {
132 $def['name'] = preg_match('/_c$/i', $matches[0][1]) ? $matches[0][1] : strtolower($matches[0][1]);
133 foreach($matches as $m) {
134 if(isset($vardefs[strtolower($m[1])])) {
135 $def['name'] = strtolower($m[1]);
139 $field = preg_replace('/<\{tag\.[a-z_]*?\}/i', '<a', $field);
140 $field = preg_replace('/<\/\{tag\.[a-z_]*?\}>/i', '</a>', $field);
142 foreach($matches as $tag[1]) {
143 if(preg_match("/^(mod[\.]|app[\.]).*?/i", $tag[1][1])) {
144 $field = str_replace($tag[1][1], '$'.$tag[1][1], $field);
146 $theField = preg_match('/_c$/i', $tag[1][1]) ? $tag[1][1] : strtolower($tag[1][1]);
147 if(!empty($vardefs[$theField])) {
148 $field = str_replace($tag[1][1], '$fields.'. $theField.'.value', $field);
150 $phpName = $this->findAssignedVariableName($tag[1][1], $filePath);
151 $field = str_replace($tag[1][1], '$fields.'. $theField.'.value', $field);
156 $def['customCode'] = $field;
157 $def['description'] = 'This field was auto generated';
159 $def = strtolower($matches[0][1]);
162 $metacolumns[] = $def;
164 } //foreach($tablecolumns as $tcols)
166 $metarow[] = array_reverse($metacolumns);
167 } //foreach($tablerows as $trow)
170 $id = $tableCount == 0 ? 'default' : $tableCount;
172 $panels[$id] = $metarow;
174 } //foreach($tables as $table)
176 $this->mCustomPanels = $panels;
177 $panels = $this->applyPreRules($moduleDir, $panels);
179 $templateMeta = array();
180 if($merge && !empty($masterCopy) && file_exists($masterCopy)) {
181 $panels = $this->mergePanels($panels, $vardefs, $moduleDir, $masterCopy);
182 $templateMeta = $this->mergeTemplateMeta($templateMeta, $moduleDir, $masterCopy);
185 $panels = $this->applyRules($moduleDir, $panels);
186 return $this->createFileContents($moduleDir, $panels, $templateMeta, $filePath);