FOSSology  4.4.0
Open Source License Compliance by Open Source Software
parseFolderPath.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2008 Hewlett-Packard Development Company, L.P.
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
23 {
24  public $page;
25  public $host;
26  public $filesWithLicense;
27  private $test;
28 
29  function __construct($page, $url)
30  {
31  /* to do: check for http? if not return null...)? */
32  if (empty ($page))
33  {
34  return;
35  }
36  $this->page = $page;
37  if (empty ($url))
38  {
39  return;
40  }
41  $this->host = getHost($url);
42  }
43 
53  function countFiles()
54  {
55  /* Extract the folder path line from the page */
56  $regExp = "Folder<\/b>:.*?/font>";
57  $numberMatched = preg_match_all("|$regExp|s", $this->page, $pathLines, PREG_SET_ORDER);
58  $this->filesWithLicense = $pathLines;
59  //print "PFP:countFiles:matched is:$numberMatched\nFilesWithLicense:\n";
60  //print_r($this->filesWithLicense) . "\n";
61 
62  return($numberMatched);
63  }
64 
78  function parseFolderPath() {
79 
80  $paths = array();
81 
82  /* Gather up the line(s) with Folder*/
83  $this->countFiles();
84  foreach ($this->filesWithLicense as $aptr)
85  {
86  foreach ($aptr as $path)
87  {
88  $paths[] = $path;
89  }
90  }
91  foreach ($paths as $apath)
92  {
93  $regExp = ".*?href='(.*?)'>(.*?)<\/a>(.*?)<";
94  $matches = preg_match_all("|$regExp|i", $apath, $pathList, PREG_SET_ORDER);
95  if ($matches > 0)
96  {
97  $dirList[] = $this->_createRtnArray($pathList, $matches);
98  return ($dirList);
99  } else
100  {
101  return (array ());
102  }
103 
104  }
105  } // parseFolderPath
106 
117  function _createRtnArray($list, $matches)
118  {
119  global $host;
120 
121  /*
122  * The last entry in the array is always a leaf name with no link
123  * but it has to be cleaned up a bit....
124  */
125 
126  for ($i = 0; $i < $matches; $i++)
127  {
128  $cleanKey = trim($list[$i][2], "\/<>b");
129  if (empty ($cleanKey))
130  {
131  continue;
132  }
133  // Make a real link that can be used
134  $partLink = $list[$i][1];
135  $link = makeUrl($this->host, $partLink);
136  $rtnList[$cleanKey] = $link;
137  /* check for anything in the leaf entry, if there is, remove
138  * the preceeding /
139  */
140  if (!empty ($list[$i][3]))
141  {
142  $cleanKey = trim($list[$i][3], "\/ ");
143  if (empty ($cleanKey))
144  {
145  continue;
146  }
147  $rtnList[$cleanKey] = NULL;
148  }
149  }
150  return ($rtnList);
151  } // _createRtnArray
152 
153  public function setPage($page)
154  {
155  if (!empty ($page))
156  {
157  $this->page = $page;
158  }
159  }
160 }
_createRtnArray($list, $matches)
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:690