FOSSology  4.4.0
Open Source License Compliance by Open Source Software
dom-parseLicenseTable.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2010 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
25 {
26  public $page;
27  public $hList = array();
28  public $noRows = FALSE;
29  public $emptyTable = FALSE;
30  private $tableId;
31  private $title;
32 
33  function __construct($page,$tblId,$title=1)
34  {
35  if (empty ($page)) { return; }
36  $this->page = $page;
37  if (strlen($tblId) == 0) { return; }
38  $this->tableId = $tblId;
39  $this->title = $title;
40  }
56  function parseLicenseTbl()
57  {
58  /*
59  * Each table row has 3 td's in it. First is the license count, second
60  * is the show link and third is the license name.
61  */
62 
63  $dom = new domDocument;
64  @$dom->loadHTML($this->page);
65  /*** discard white space ***/
66  $dom->preserveWhiteSpace = false;
67  $table = $dom->getElementById($this->tableId);
68  if(empty($table)) {
69  $this->emptyTable = TRUE;
70  //print "DPLTDB: table is empty, can't find table! with table id of:$this->tableId\n";
71  return($this->hList=array());
72  }
73 
74  foreach ($table->childNodes as $tblChildNode)
75  {
76  $histogram = array();
77  foreach($tblChildNode->childNodes as $childNode){
78  if($childNode->nodeName == 'td'){
79  if(is_numeric($childNode->nodeValue)) {
80  $histogram['count'] = trim($childNode->nodeValue);
81  }
82  if ($childNode->nodeValue == 'Show') {
83  $anchorList = $childNode->getElementsByTagName('a');
84  foreach($anchorList as $anchorEle) {
85  $histogram['showLink'] = $anchorEle->getAttribute('href');
86  }
87  }
88  if(is_string($childNode->nodeValue)) {
89  $histogram['textOrLink'] = trim($childNode->nodeValue);
90  }
91  }
92  } // foreach($tblChildNode
93  $this->hList[] = $histogram;
94  $histogram = array();
95  } // foreach
96  // for tables with titles, the first row is empty as no childNodes match
97  // what we are looking for, remove the first row.
98  if($this->title)
99  {
100  // remove empty 1st entry
101  unset($this->hList[0]);
102  }
103  if(empty($this->hList)) {
104  $this->noRows = TRUE;
105  }
106  } // parseLicenseTbl
107 }
parseLicenseTbl()
given a fossology license histogram, parse it into license names and Show links.
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:690