2 /*********************************************************************************
3 * SugarCRM is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
40 require_once("include/SugarCharts/SugarChart.php");
42 class JsChart extends SugarChart {
51 function __construct() {
52 parent::__construct();
55 function isSupported($chartType) {
57 "stacked group by chart",
60 "horizontal group by chart",
62 "horizontal bar chart",
69 if(in_array($chartType,$charts)) {
77 function tab($str, $depth){
78 return str_repeat("\t", $depth) . $str . "\n";
81 function display($name, $xmlFile, $width='320', $height='480', $resize=false) {
84 $this->chartId = $name;
85 $this->height = $height;
86 $this->width = $width;
87 $this->xmlFile = $xmlFile;
88 $this->chartType = $this->chart_properties['type'];
92 $chartConfig = array();
93 $xmlStr = $this->processXML($this->xmlFile);
94 $json = $this->buildJson($xmlStr);
95 $this->saveJsonFile($json);
96 $this->ss->assign("chartId", $this->chartId);
97 $this->ss->assign("filename", $this->jsonFilename);
100 $dimensions = $this->getChartDimensions($xmlStr);
101 $this->ss->assign("width", $dimensions['width']);
102 $this->ss->assign("height", $dimensions['height']);
103 $config = $this->getConfigProperties();
104 $style['gridLineColor'] = str_replace("0x","#",$config->gridLines);
105 $style['font-family'] = $config->labelFontFamily;
106 $style['color'] = str_replace("0x","#",$config->labelFontColor);
107 $this->ss->assign("css", $style);
108 foreach($this->getChartConfigParams($xmlStr) as $key => $value) {
109 $chartConfig[$key] = $value;
111 $chartConfig['imageExportType'] = $this->image_export_type;
112 $this->ss->assign("config", $chartConfig);
113 if($json == "No Data") {
114 $this->ss->assign("error", "No Data");
117 if(!$this->isSupported($this->chartType)) {
118 $this->ss->assign("error", "Unsupported Chart Type");
124 return $this->ss->fetch($file);
128 function getDashletScript($id,$xmlFile="") {
130 global $sugar_config, $current_user, $current_language;
132 $this->chartId = $id;
133 $this->xmlFile = (!$xmlFile) ? $sugar_config['tmp_dir']. $current_user->id . '_' . $this->id . '.xml' : $xmlFile;
137 $chartConfig = array();
138 $this->ss->assign("chartId", $this->chartId);
139 $this->ss->assign("filename", str_replace(".xml",".js",$this->xmlFile));
140 $config = $this->getConfigProperties();
141 $style['gridLineColor'] = str_replace("0x","#",$config->gridLines);
142 $style['font-family'] = $config->labelFontFamily;
143 $style['color'] = str_replace("0x","#",$config->labelFontColor);
144 $this->ss->assign("css", $style);
145 $xmlStr = $this->processXML($this->xmlFile);
146 foreach($this->getChartConfigParams($xmlStr) as $key => $value) {
147 $chartConfig[$key] = $value;
150 $chartConfig['imageExportType'] = $this->image_export_type;
151 $this->ss->assign("config", $chartConfig);
154 return $this->ss->fetch($file);
157 function chartArray($chartsArray) {
159 $customChartsArray = array();
161 $chartConfig = array();
162 foreach($chartsArray as $id => $data) {
163 $customChartsArray[$id] = array();
164 $customChartsArray[$id]['chartId'] = $id;
165 $customChartsArray[$id]['filename'] = str_replace(".xml",".js",$data['xmlFile']);
166 $customChartsArray[$id]['width'] = $data['width'];
167 $customChartsArray[$id]['height'] = $data['height'];
169 $config = $this->getConfigProperties();
170 $style['gridLineColor'] = str_replace("0x","#",$config->gridLines);
171 $style['font-family'] = (string)$config->labelFontFamily;
172 $style['color'] = str_replace("0x","#",$config->labelFontColor);
173 $customChartsArray[$id]['css'] = $style;
174 $xmlStr = $this->processXML($data['xmlFile']);
175 $xml = new SimpleXMLElement($xmlStr);
176 $params = $this->getChartConfigParams($xmlStr);
177 $customChartsArray[$id]['supported'] = ($this->isSupported($xml->properties->type)) ? "true" : "false";
178 foreach($params as $key => $value) {
179 $chartConfig[$key] = $value;
181 $chartConfig['imageExportType'] = $this->image_export_type;
182 $customChartsArray[$id]['chartConfig'] = $chartConfig;
185 return $customChartsArray;
188 function getChartConfigParams($xmlStr) {
190 $xml = new SimpleXMLElement($xmlStr);
192 $chartType = $xml->properties->type;
193 if($chartType == "pie chart") {
194 return array ("pieType" => "basic","tip" => "name","chartType" => "pieChart");
195 } elseif($chartType == "line chart") {
196 return array ("lineType" => "basic","tip" => "name","chartType" => "lineChart");
197 } elseif($chartType == "funnel chart 3D") {
198 return array ("funnelType" => "basic","tip" => "name","chartType" => "funnelChart");
199 } elseif($chartType == "gauge chart") {
200 return array ("gaugeType" => "basic","tip" => "name","chartType" => "gaugeChart");
201 } elseif($chartType == "stacked group by chart") {
202 return array ("orientation" => "vertical","barType" => "stacked","tip" => "name","chartType" => "barChart");
203 } elseif($chartType == "group by chart") {
204 return array("orientation" => "vertical", "barType" => "grouped", "tip" => "title","chartType" => "barChart");
205 } elseif($chartType == "bar chart") {
206 return array("orientation" => "vertical", "barType" => "basic", "tip" => "label","chartType" => "barChart");
207 } elseif ($chartType == "horizontal group by chart") {
208 return array("orientation" => "horizontal", "barType" => "stacked", "tip" => "name","chartType" => "barChart");
209 } elseif ($chartType == "horizontal bar chart" || "horizontal") {
210 return array("orientation" => "horizontal","barType" => "basic","tip" => "label","chartType" => "barChart");
212 return array("orientation" => "vertical","barType" => "stacked","tip" => "name","chartType" => "barChart");
215 function getChartDimensions($xmlStr) {
216 if($this->getNumNodes($xmlStr) > 9 && $this->chartType != "pie chart") {
217 if($this->chartType == "horizontal group by chart" || $this->chartType == "horizontal bar chart") {
218 $diff = $this->getNumNodes($xmlStr) - 9;
219 $height = ($diff * (.20 * $this->height)) + $this->height;
220 return array("width"=>$this->width, "height"=>($height));
222 return array("width"=>($this->width * 2), "height"=>$this->height);
225 return array("width"=>"100%", "height"=>$this->height);
229 function checkData($xmlstr) {
230 $xml = new SimpleXMLElement($xmlstr);
231 if(sizeof($xml->data->group) > 0) {
238 function getNumNodes($xmlstr) {
239 $xml = new SimpleXMLElement($xmlstr);
240 return sizeof($xml->data->group);
243 function buildProperties($xmlstr) {
244 $content = $this->tab("'properties': [\n",1);
245 $properties = array();
246 $xml = new SimpleXMLElement($xmlstr);
247 foreach($xml->properties->children() as $property) {
248 $properties[] = $this->tab("'".$property->getName()."':"."'".$property."'",2);
250 $content .= $this->tab("{\n",1);
251 $content .= join(",\n",$properties)."\n";
252 $content .= $this->tab("}\n",1);
253 $content .= $this->tab("],\n",1);
257 function buildLabelsBarChartStacked($xmlstr) {
258 $content = $this->tab("'label': [\n",1);
260 $xml = new SimpleXMLElement($xmlstr);
261 foreach($xml->data->group[0]->subgroups->group as $group) {
262 $labels[] = $this->tab("'".$group->title."'",2);
264 $content .= join(",\n",$labels)."\n";
265 $content .= $this->tab("],\n",1);
269 function buildLabelsBarChart($xmlstr) {
270 $content = $this->tab("'label': [\n",1);
272 $xml = new SimpleXMLElement($xmlstr);
273 foreach($xml->data->group as $group) {
274 $labels[] = $this->tab("'".$group->title."'",2);
276 $labelStr = join(",\n",$labels)."\n";
277 $content .= $labelStr;
278 $content .= $this->tab("],\n",1);
282 function buildDataBarChartStacked($xmlstr) {
283 $content = $this->tab("'values': [\n",1);
285 $xml = new SimpleXMLElement($xmlstr);
286 foreach($xml->data->group as $group) {
287 $groupcontent = $this->tab("{\n",1);
288 $groupcontent .= $this->tab("'label': '{$group->title}',\n",2);
289 $groupcontent .= $this->tab("'gvalue': '{$group->value}',\n",2);
290 $groupcontent .= $this->tab("'gvaluelabel': '{$group->label}',\n",2);
291 $subgroupValues = array();
292 $subgroupValueLabels = array();
293 $subgroupLinks = array();
294 foreach($group->subgroups->group as $subgroups) {
295 $subgroupValues[] = $this->tab(($subgroups->value == "NULL") ? 0 : $subgroups->value,3);
296 $subgroupValueLabels[] = $this->tab("'".$subgroups->label."'",3);
297 $subgroupLinks[] = $this->tab("'".$subgroups->link."'",3);
299 $subgroupValuesStr = join(",\n",$subgroupValues)."\n";
300 $subgroupValueLabelsStr = join(",\n",$subgroupValueLabels)."\n";
301 $subgroupLinksStr = join(",\n",$subgroupLinks)."\n";
303 $groupcontent .= $this->tab("'values': [\n".$subgroupValuesStr,2);
304 $groupcontent .= $this->tab("],\n",2);
305 $groupcontent .= $this->tab("'valuelabels': [\n".$subgroupValueLabelsStr,2);
306 $groupcontent .= $this->tab("],\n",2);
307 $groupcontent .= $this->tab("'links': [\n".$subgroupLinksStr,2);
308 $groupcontent .= $this->tab("]\n",2);
309 $groupcontent .= $this->tab("}",1);
310 $data[] = $groupcontent;
312 $content .= join(",\n",$data)."\n";
313 $content .= $this->tab("]",1);
317 function buildDataBarChartGrouped($xmlstr) {
318 $content = $this->tab("'values': [\n",1);
320 $xml = new SimpleXMLElement($xmlstr);
321 foreach($xml->data->group as $group) {
322 $groupcontent = $this->tab("{\n",1);
323 $groupcontent .= $this->tab("'label': '{$group->title}',\n",2);
324 $groupcontent .= $this->tab("'gvalue': '{$group->value}',\n",2);
325 $groupcontent .= $this->tab("'gvaluelabel': '{$group->label}',\n",2);
326 $subgroupValues = array();
327 $subgroupValueLabels = array();
328 $subgroupLinks = array();
329 $subgroupTitles = array();
330 foreach($group->subgroups->group as $subgroups) {
331 $subgroupValues[] = $this->tab(($subgroups->value == "NULL") ? 0 : $subgroups->value,3);
332 $subgroupValueLabels[] = $this->tab("'".$subgroups->label."'",3);
333 $subgroupLinks[] = $this->tab("'".$subgroups->link."'",3);
334 $subgroupTitles[] = $this->tab("'".$subgroups->title."'",3);
336 $subgroupValuesStr = join(",\n",$subgroupValues)."\n";
337 $subgroupValueLabelsStr = join(",\n",$subgroupValueLabels)."\n";
338 $subgroupLinksStr = join(",\n",$subgroupLinks)."\n";
339 $subgroupTitlesStr = join(",\n",$subgroupTitles)."\n";
341 $groupcontent .= $this->tab("'values': [\n".$subgroupValuesStr,2);
342 $groupcontent .= $this->tab("],\n",2);
343 $groupcontent .= $this->tab("'valuelabels': [\n".$subgroupValueLabelsStr,2);
344 $groupcontent .= $this->tab("],\n",2);
345 $groupcontent .= $this->tab("'links': [\n".$subgroupLinksStr,2);
346 $groupcontent .= $this->tab("],\n",2);
347 $groupcontent .= $this->tab("'titles': [\n".$subgroupTitlesStr,2);
348 $groupcontent .= $this->tab("]\n",2);
349 $groupcontent .= $this->tab("}",1);
350 $data[] = $groupcontent;
352 $content .= join(",\n",$data)."\n";
353 $content .= $this->tab("]",1);
357 function buildDataBarChart($xmlstr) {
358 $content = $this->tab("'values': [\n",1);
360 $xml = new SimpleXMLElement($xmlstr);
362 $groupcontentArr = array();
364 foreach($xml->data->group as $group) {
365 $groupcontent = $this->tab("{\n",1);
366 $groupcontent .= $this->tab("'label': [\n",2);
367 $groupcontent .= $this->tab("'{$group->title}'\n",3);
368 $groupcontent .= $this->tab("],\n",2);
369 $groupcontent .= $this->tab("'values': [\n",2);
370 $groupcontent .= $this->tab(($group->value == "NULL") ? 0 : $group->value."\n",3);
371 $groupcontent .= $this->tab("],\n",2);
373 $groupcontent .= $this->tab("'valuelabels': [\n",2);
374 $groupcontent .= $this->tab("'{$group->label}'\n",3);
375 $groupcontent .= $this->tab("],\n",2);
377 $groupcontent .= $this->tab("'links': [\n",2);
378 $groupcontent .= $this->tab("'{$group->link}'\n",3);
379 $groupcontent .= $this->tab("]\n",2);
380 $groupcontent .= $this->tab("}",1);
381 $groupcontentArr[] = $groupcontent;
383 $content .= join(",\n",$groupcontentArr)."\n";
384 $content .= $this->tab("]",1);
388 function buildLabelsPieChart($xmlstr) {
389 $content = $this->tab("'label': [\n",1);
391 $xml = new SimpleXMLElement($xmlstr);
392 foreach($xml->data->group as $group) {
393 $labels[] = $this->tab("'".$group->title."'",2);
395 $labelStr = join(",\n",$labels)."\n";
396 $content .= $labelStr;
397 $content .= $this->tab("],\n",1);
402 function buildDataPieChart($xmlstr) {
403 $content = $this->tab("'values': [\n",1);
405 $xml = new SimpleXMLElement($xmlstr);
407 $groupcontentArr = array();
409 foreach($xml->data->group as $group) {
410 $groupcontent = $this->tab("{\n",1);
411 $groupcontent .= $this->tab("'label': [\n",2);
412 $groupcontent .= $this->tab("'{$group->title}'\n",3);
413 $groupcontent .= $this->tab("],\n",2);
414 $groupcontent .= $this->tab("'values': [\n",2);
415 $groupcontent .= $this->tab("{$group->value}\n",3);
416 $groupcontent .= $this->tab("],\n",2);
417 $groupcontent .= $this->tab("'valuelabels': [\n",2);
418 $groupcontent .= $this->tab("'{$group->label}'\n",3);
419 $groupcontent .= $this->tab("],\n",2);
420 $groupcontent .= $this->tab("'links': [\n",2);
421 $groupcontent .= $this->tab("'{$group->link}'\n",3);
422 $groupcontent .= $this->tab("]\n",2);
423 $groupcontent .= $this->tab("}",1);
424 $groupcontentArr[] = $groupcontent;
428 $content .= join(",\n",$groupcontentArr)."\n";
429 $content .= $this->tab("\n]",1);
433 function buildLabelsGaugeChart($xmlstr) {
434 $content = $this->tab("'label': [\n",1);
436 $xml = new SimpleXMLElement($xmlstr);
437 foreach($xml->data->group as $group) {
438 $labels[] = $this->tab("'".$group->title."'",2);
440 $labelStr = join(",\n",$labels)."\n";
441 $content .= $labelStr;
442 $content .= $this->tab("],\n",1);
446 function buildDataGaugeChart($xmlstr) {
447 $content = $this->tab("'values': [\n",1);
449 $xml = new SimpleXMLElement($xmlstr);
450 foreach($xml->data->group as $group) {
451 $groupcontent = $this->tab("{\n",1);
452 $groupcontent .= $this->tab("'label': '{$group->title}',\n",2);
453 $groupcontent .= $this->tab("'gvalue': '{$group->value}',\n",2);
454 $finalComma = ($group->title != "GaugePosition") ? "," : "";
455 $groupcontent .= $this->tab("'gvaluelabel': '{$group->label}'{$finalComma}\n",2);
456 $subgroupTitles = array();
457 $subgroupValues = array();
458 $subgroupValueLabels = array();
459 $subgroupLinks = array();
461 if(is_object($group->subgroups->group)) {
462 foreach($group->subgroups->group as $subgroups) {
463 $subgroupTitles[] = $this->tab("'".$subgroups->title."'",3);
464 //$subgroupValues[] = $this->tab($subgroups->value,3);
465 $subgroupValues[] = $subgroups->value;
466 $subgroupValueLabels[] = $this->tab("'".$subgroups->label."'",3);
467 $subgroupLinks[] = $this->tab("'".$subgroups->link."'",3);
469 $subgroupTitlesStr = join(",\n",$subgroupTitles)."\n";
470 $subgroupValuesStr = join(",\n",$subgroupValues)."\n";
471 $subgroupValueLabelsStr = join(",\n",$subgroupValueLabels)."\n";
472 $subgroupLinksStr = join(",\n",$subgroupLinks)."\n";
474 //$groupcontent .= $this->tab("'labels': [\n".$subgroupTitlesStr,2);
475 //$groupcontent .= $this->tab("],\n",2);
476 $val = ((int)$subgroupValues[1] == (int)$subgroupValues[0]) ? $this->tab($subgroupValues[1],3)."\n" : $this->tab($subgroupValues[1] - $subgroupValues[0],3)."\n";
478 $groupcontent .= $this->tab("'values': [\n".$val,2);
479 $groupcontent .= $this->tab("],\n",2);
480 $groupcontent .= $this->tab("'valuelabels': [\n".$subgroupValueLabelsStr,2);
481 $groupcontent .= $this->tab("]\n",2);
482 //$groupcontent .= $this->tab("'links': [\n".$subgroupLinksStr,2);
483 //$groupcontent .= $this->tab("]\n",2);
487 $groupcontent .= $this->tab("}",1);
488 $data[] = $groupcontent;
492 $content .= join(",\n",$data)."\n";
495 $content .= $this->tab("]",1);
500 function getConfigProperties() {
501 $path = SugarThemeRegistry::current()->getImageURL('sugarColors.xml',false);
503 if(!file_exists($path)) {
504 $GLOBALS['log']->debug("Cannot open file ($path)");
506 $xmlstr = file_get_contents($path);
507 $xml = new SimpleXMLElement($xmlstr);
511 function buildChartColors() {
513 $content = $this->tab("'color': [\n",1);
515 $xml = $this->getConfigProperties();
516 $colors = ($this->chartType == "gauge chart") ? $xml->gaugeChartElementColors->color : $xml->chartElementColors->color;
517 foreach($colors as $color) {
518 $colorArr[] = $this->tab("'".str_replace("0x","#",$color)."'",2);
520 $content .= join(",\n",$colorArr)."\n";
521 $content .= $this->tab("],\n",1);
527 function buildJson($xmlstr){
528 if($this->checkData($xmlstr)) {
530 if ($this->chartType == "pie chart" || $this->chartType == "funnel chart 3D") {
531 $content .= $this->buildProperties($xmlstr);
532 $content .= $this->buildLabelsPieChart($xmlstr);
533 $content .= $this->buildChartColors();
534 $content .= $this->buildDataPieChart($xmlstr);
536 elseif ($this->chartType == "gauge chart") {
537 $content .= $this->buildProperties($xmlstr);
538 $content .= $this->buildLabelsGaugeChart($xmlstr);
539 $content .= $this->buildChartColors();
540 $content .= $this->buildDataGaugeChart($xmlstr);
542 elseif ($this->chartType == "horizontal bar chart" || $this->chartType == "bar chart") {
543 $content .= $this->buildProperties($xmlstr);
544 $content .= $this->buildLabelsBarChart($xmlstr);
545 $content .= $this->buildChartColors();
546 $content .= $this->buildDataBarChart($xmlstr);
548 elseif ($this->chartType == "group by chart") {
549 $content .= $this->buildProperties($xmlstr);
550 $content .= $this->buildLabelsBarChartStacked($xmlstr);
551 $content .= $this->buildChartColors();
552 $content .= $this->buildDataBarChartGrouped($xmlstr);
554 $content .= $this->buildProperties($xmlstr);
555 $content .= $this->buildLabelsBarChartStacked($xmlstr);
556 $content .= $this->buildChartColors();
557 $content .= $this->buildDataBarChartStacked($xmlstr);
566 function buildHTMLLegend($xmlFile) {
567 $xmlstr = $this->processXML($xmlFile);
568 $xml = new SimpleXMLElement($xmlstr);
569 $this->chartType = $xml->properties->type;
570 $html = "<table align=\"left\" cellpadding=\"2\" cellspacing=\"2\">";
572 if ($this->chartType == "group by chart" || $this->chartType == "horizontal group by chart") {
573 $groups = $xml->data->group[0]->subgroups->group;
574 $items = (sizeof($xml->data->group[0]->subgroups->group) <= 5) ? 5 : sizeof($xml->data->group[0]->subgroups->group);
576 $groups = $xml->data->group;
577 $items = (sizeof($xml->data->group) <= 5) ? 5 : sizeof($xml->data->group);
580 $rows = ceil($items/5);
581 $fullItems = $rows * 5;
582 $remainder = ($items < $fullItems) ? $fullItems - $items : 0;
588 $xmlColors = $this->getConfigProperties();
589 $colors = ($this->chartType == "gauge chart") ? $xmlColors->gaugeChartElementColors->color : $xmlColors->chartElementColors->color;
591 foreach($colors as $color) {
592 $colorArr[] = str_replace("0x","#",$color);
596 foreach($groups as $group) {
597 if($i == 5) {$i = 0;}
598 $html .= ($i == 0) ? "<tr>" : "";
599 $html .= "<td width=\"50\">";
600 $html .= "<div style=\"background-color:".$colorArr[$x].";\"> </div>";
603 $html .= $group->title;
605 $html .= ($x+1 == $items) ? "<td colspan=".($remainder*2)."></td>" : "";
606 $html .= ($i == 4) ? "</tr>" : "";
616 function saveJsonFile($jsonContents) {
618 $this->jsonFilename = str_replace(".xml",".js",$this->xmlFile);
619 //$jsonContents = mb_convert_encoding($jsonContents, 'UTF-16LE', 'UTF-8');
622 if (!$fh = sugar_fopen($this->jsonFilename, 'w')) {
623 $GLOBALS['log']->debug("Cannot open file ($this->jsonFilename)");
627 // write the contents to the file
628 if (fwrite($fh,$jsonContents) === FALSE) {
629 $GLOBALS['log']->debug("Cannot write to file ($this->jsonFilename)");
633 $GLOBALS['log']->debug("Success, wrote ($jsonContents) to file ($this->jsonFilename)");
639 function get_image_cache_file_name ($xmlFile,$ext = ".png") {
640 $filename = str_replace("/xml/","/images/",str_replace(".xml",$ext,$xmlFile));
646 function getXMLChartProperties($xmlStr) {
648 $xml = new SimpleXMLElement($xmlstr);
649 foreach($xml->properties->children() as $properties) {
650 $props[$properties->getName()] = $properties;
655 function processXML($xmlFile) {
657 if(!file_exists($xmlFile)) {
658 $GLOBALS['log']->debug("Cannot open file ($xmlFile)");
662 $replacement = array();
663 $content = file_get_contents($xmlFile);
664 $content = mb_convert_encoding($content, 'UTF-8','UTF-16LE' );
665 $pattern[] = '/\<link\>([a-zA-Z0-9#?&%.;\[\]\/=+_-\s]+)\<\/link\>/e';
666 $replacement[] = "'<link>'.urlencode(\"$1\").'</link>'";
667 // $pattern[] = '/NULL/e';
668 // $replacement[] = "";
669 return preg_replace($pattern,$replacement, $content);