1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
<?php
/***********************************************************
Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***********************************************************/
/**
* getMailSubjects
*
* Check to see if there is new mail for the user
*
* NOTE: must be run by the user who owns the system mailbox in /var/mail
*
* @return array Subjects, list of Fossology subjects that match.
*
*/
function getMailSubjects() {
/*
* use preg_match, but the test must be run by the user who owns the email file
* in /var/mail.
*/
$MailFile = "/var/mail/";
//$user = get_current_user();
$user = exec('id -un', $out, $rtn);
$UserMail = $MailFile . $user;
//$FH = fopen($UserMail,'r') or die ("Cannot open $UserMail, $phperrormsg\n");
$FH = fopen($UserMail,'r');
if($FH === FALSE) {
return(array("ERROR! Cannot open $UserMail"));
}
while (! feof($FH)){
$line = fgets($FH);
$matched = preg_match('/Subject:\sFOSSology Results.*?$/',$line, $matches);
if($matched) {
$Subjects[] = $line;
}
}
return($Subjects);
}
/**
* escapeDots($string)
*
* Escape '.' in a string by replacing '.' with '\.'
* @param string $string the input string to escape.
* @return string $estring the escaped string or False.
*/
function escapeDots($string)
{
if (empty ($string))
{
return (FALSE);
}
$estring = preg_replace('/\./', '\\.', $string);
//print "ED: string is:$string, estring is:$estring\n";
if ($estring === NULL)
{
return (FALSE);
}
return ($estring);
}
/**
* public function getHost
*
* returns the host (if present) from a URL
*
* @param string $URL a url in the form of http://somehost.xx.com/repo/
*
* @return string $host the somehost.xx.com part is returned or NULL,
* if there is no host in the uri
*
*/
function getHost($URL)
{
if (empty ($URL))
{
return (NULL);
}
$found = parse_url($URL, PHP_URL_HOST);
//print "DB: getHost: url is:$URL\nafter parse, found is:$found\n";
return ($found);
}
/**
* getBrowserUri($name, $page)
*
* Get the url fragment to display the upload from the xhtml page.
*
* @param string $name the name of a folder or upload
* @param string $page the xhtml page to search
*
* TODO: finish or scrap this method
*
* @return $string the matching uri or null.
*
*/
function getBrowseUri($name, $page)
{
//print "DB: GBURI: page is:\n$page\n";
//$found = preg_match("/href='(.*?)'>($uploadName)<\/a>/", $page, $matches);
// doesn't work: '$found = preg_match("/href='(.*?)'>$name/", $page, $matches);
$found = preg_match("/href='((.*?)&show=detail).*?/", $page, $matches);
//$found = preg_match("/ class=.*?href='(.*?)'>$name/", $page, $matches);
print "DB: GBURI: found matches is:$found\n";
print "DB: GBURI: matches is:\n";
var_dump($matches) . "\n";
if ($found)
{
return ($matches[1]);
} else
{
return (NULL);
}
}
/**
* makeUrl($host,$query)
*
* Make a url from the host and query strings.
*
* @param $string $host the host (e.g. somehost.com, host.privatenet)
* @param $string $query the query to append to the host.
*
* @return the http string or NULL on error
*/
function makeUrl($host, $query)
{
if (empty ($host))
{
return (NULL);
}
if (empty ($query))
{
return (NULL);
}
return ("http://$host$query");
}
?>
|