FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
parseFolderPath.php
1 <?php
2 
3 
4 /***********************************************************
5  Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License
9  version 2 as published by the Free Software Foundation.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License along
17  with this program; if not, write to the Free Software Foundation, Inc.,
18  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  ***********************************************************/
20 
36 {
37  public $page;
38  public $host;
39  public $filesWithLicense;
40  private $test;
41 
42  function __construct($page, $url)
43  {
44  /* to do: check for http? if not return null...)? */
45  if (empty ($page))
46  {
47  return;
48  }
49  $this->page = $page;
50  if (empty ($url))
51  {
52  return;
53  }
54  $this->host = getHost($url);
55  }
56 
68  function countFiles()
69  {
70  /* Extract the folder path line from the page */
71  $regExp = "Folder<\/b>:.*?/font>";
72  $numberMatched = preg_match_all("|$regExp|s", $this->page, $pathLines, PREG_SET_ORDER);
73  $this->filesWithLicense = $pathLines;
74  //print "PFP:countFiles:matched is:$numberMatched\nFilesWithLicense:\n";
75  //print_r($this->filesWithLicense) . "\n";
76 
77  return($numberMatched);
78  }
79 
93  function parseFolderPath() {
94 
95  $paths = array();
96 
97  /* Gather up the line(s) with Folder*/
98  $this->countFiles();
99  foreach ($this->filesWithLicense as $aptr)
100  {
101  foreach ($aptr as $path)
102  {
103  $paths[] = $path;
104  }
105  }
106  foreach ($paths as $apath)
107  {
108  $regExp = ".*?href='(.*?)'>(.*?)<\/a>(.*?)<";
109  $matches = preg_match_all("|$regExp|i", $apath, $pathList, PREG_SET_ORDER);
110  if ($matches > 0)
111  {
112  $dirList[] = $this->_createRtnArray($pathList, $matches);
113  return ($dirList);
114  } else
115  {
116  return (array ());
117  }
118 
119  }
120  } // parseFolderPath
121 
132  function _createRtnArray($list, $matches)
133  {
134  global $host;
135 
136  /*
137  * The last entry in the array is always a leaf name with no link
138  * but it has to be cleaned up a bit....
139  */
140 
141  for ($i = 0; $i < $matches; $i++)
142  {
143  $cleanKey = trim($list[$i][2], "\/<>b");
144  if (empty ($cleanKey))
145  {
146  continue;
147  }
148  // Make a real link that can be used
149  $partLink = $list[$i][1];
150  $link = makeUrl($this->host, $partLink);
151  $rtnList[$cleanKey] = $link;
152  /* check for anything in the leaf entry, if there is, remove
153  * the preceeding /
154  */
155  if (!empty ($list[$i][3]))
156  {
157  $cleanKey = trim($list[$i][3], "\/ ");
158  if (empty ($cleanKey))
159  {
160  continue;
161  }
162  $rtnList[$cleanKey] = NULL;
163  }
164  }
165  return ($rtnList);
166  } // _createRtnArray
167 
168  public function setPage($page)
169  {
170  if (!empty ($page))
171  {
172  $this->page = $page;
173  }
174  }
175 }
176 ?>
_createRtnArray($list, $matches)
char * trim(char *ptext)
Trimming whitespace.
Definition: fossconfig.c:695