";
$arr[] = rawurlencode($key."[]")."=".rawurlencode($value);
}
}
else
$arr[] = $key."=".rawurlencode($val);
}
return implode("&", $arr);
}
/*
* return all values of a mapping as an array
*/
function values($arr)
{
$res = array();
while(list($k, $v) = each($arr))
$res[] = $v;
return $res;
}
/*
* format date
*/
function print_date($sTimestamp)
{
return date("F d Y H:i:s", $sTimestamp);
}
function mysqltimestamp_to_unixtimestamp($sTimestamp)
{
$d = substr($sTimestamp,6,2); // day
$m = substr($sTimestamp,4,2); // month
$y = substr($sTimestamp,0,4); // year
$hours = substr($sTimestamp,8,2); // year
$minutes = substr($sTimestamp,10,2); // year
$seconds = substr($sTimestamp,12,2); // year
return mktime($hours,$minutes,$seconds,$m, $d, $y);
}
function mysqldatetime_to_unixtimestamp($sDatetime)
{
sscanf($sDatetime, "%4s-%2s-%2s %2s:%2s:%2s",
&$y, &$m, &$d,
&$hours, &$minutes, &$seconds);
return mktime($hours,$minutes,$seconds,$m, $d, $y);
}
function get_remote()
{
global $REMOTE_HOST, $REMOTE_ADDR;
if($REMOTE_HOST)
$ip = $REMOTE_HOST;
else
$ip = $REMOTE_ADDR;
return $ip;
}
function htmlify_urls($text)
{
//FIXME: wonder what the syntax is, this doesn't seem to work
// $text = strip_tags($text, ",,, {$_REQUEST['url']}: {$_REQUEST['url_desc']} {$_REQUEST['adescription'][$i]}: {$_REQUEST['aURL'][$i]}: {$_REQUEST['adelete'][$i]} : {$_REQUEST['aId'][$i]} : .{$_REQUEST['aOldDesc'][$i]}. : {$_REQUEST['aOldURL'][$i]} Successfully deleted URL ".$_REQUEST['aOldDesc'][$i]." (".$_REQUEST['aOldURL'][$i].") Successfully updated ".$_REQUEST['aOldDesc'][$i]." (".$_REQUEST['aOldURL'][$i]."),
", $text);
return $text;
}
// open file and display contents of selected tag
function get_xml_tag ($file, $mode = null)
{
if ($mode and file_exists($file))
{
$fp = @fopen($file, "r");
$data = fread($fp, filesize($file));
@fclose($fp);
if (eregi("<" . $mode . ">(.*)" . $mode . ">", $data, $out))
{
return $out[1];
}
}
else
{
return null;
}
}
/* bugzilla functions */
function make_bugzilla_version_list($varname, $cvalue)
{
$table = BUGZILLA_DB.".versions";
$where = "WHERE product_id=".BUGZILLA_PRODUCT_ID;
$sQuery = "SELECT value FROM $table $where ORDER BY value";
$hResult = query_bugzilladb($sQuery);
if(!$hResult) return;
echo "\n";
}
function make_maintainer_rating_list($varname, $cvalue)
{
echo "\n";
}
/* get the number of queued maintainers */
function getQueuedMaintainerCount()
{
$sQuery = "SELECT count(*) as queued_maintainers FROM appMaintainerQueue";
$hResult = query_parameters($sQuery);
$oRow = mysql_fetch_object($hResult);
return $oRow->queued_maintainers;
}
/* get the total number of maintainers and applications in the appMaintainers table */
function getMaintainerCount()
{
$sQuery = "SELECT count(*) as maintainers FROM appMaintainers";
$hResult = query_parameters($sQuery);
$oRow = mysql_fetch_object($hResult);
return $oRow->maintainers;
}
/* get the total number of vendors from the vendor table */
function getVendorCount()
{
$sQuery = "SELECT count(*) as vendors FROM vendor";
$hResult = query_parameters($sQuery);
$oRow = mysql_fetch_object($hResult);
return $oRow->vendors;
}
/* Get the number of users in the database */
function getNumberOfComments()
{
$hResult = query_parameters("SELECT count(*) as num_comments FROM appComments;");
$oRow = mysql_fetch_object($hResult);
return $oRow->num_comments;
}
/* Get the number of versions in the database */
function getNumberOfVersions()
{
$hResult = query_parameters("SELECT count(versionId) as num_versions FROM appVersion WHERE versionName != 'NONAME';");
$oRow = mysql_fetch_object($hResult);
return $oRow->num_versions;
}
/* Get the number of maintainers in the database */
function getNumberOfMaintainers()
{
$hResult = query_parameters("SELECT DISTINCT userId FROM appMaintainers;");
return mysql_num_rows($hResult);
}
/* Get the number of app familes in the database */
function getNumberOfAppFamilies()
{
$hResult = query_parameters("SELECT count(*) as num_appfamilies FROM appFamily;");
$oRow = mysql_fetch_object($hResult);
return $oRow->num_appfamilies;
}
/* Get the number of images in the database */
function getNumberOfImages()
{
$hResult = query_parameters("SELECT count(*) as num_images FROM appData WHERE type='image';");
$oRow = mysql_fetch_object($hResult);
return $oRow->num_images;
}
/* Get the number of queued bug links in the database */
function getNumberOfQueuedBugLinks()
{
$hResult = query_parameters("SELECT count(*) as num_buglinks FROM buglinks WHERE queued='true';");
if($hResult)
{
$oRow = mysql_fetch_object($hResult);
return $oRow->num_buglinks;
}
return 0;
}
/* Get the number of bug links in the database */
function getNumberOfBugLinks()
{
$hResult = query_parameters("SELECT count(*) as num_buglinks FROM buglinks;");
if($hResult)
{
$oRow = mysql_fetch_object($hResult);
return $oRow->num_buglinks;
}
return 0;
}
function lookupVendorName($vendorId)
{
$sResult = query_parameters("SELECT * FROM vendor ".
"WHERE vendorId = '?'",
$vendorId);
if(!$sResult || mysql_num_rows($sResult) != 1)
return "Unknown vendor";
$vendor = mysql_fetch_object($sResult);
return $vendor->vendorName;
}
/* used by outputTopXRowAppsFromRating() to reduce duplicated code */
function outputTopXRow($oRow)
{
$oVersion = new Version($oRow->versionId);
$oApp = new Application($oVersion->iAppId);
$img = get_screenshot_img(null, $oRow->versionId, false); // image, disable extra formatting
echo '
';
}
/* Output the rows for the Top-X tables on the main page */
function outputTopXRowAppsFromRating($rating, $num_apps)
{
/* clean the input values so we can continue to use query_appdb() */
$rating = mysql_real_escape_string($rating);
$num_apps = mysql_real_escape_string($num_apps);
/* list of appIds we've already output, so we don't output */
/* them again when filling in any empty spots in the list */
$appIdArray = array();
$sQuery = "SELECT appVotes.appId AS appId, appVersion.versionId, COUNT( appVotes.appId ) AS c
FROM appVotes, appVersion
WHERE appVersion.maintainer_rating = '?'
AND appVersion.appId = appVotes.appId
GROUP BY appVotes.appId
ORDER BY c DESC
LIMIT ?";
$hResult = query_parameters($sQuery, $rating, $num_apps);
$num_apps-=mysql_num_rows($hResult); /* take away the rows we are outputting here */
while($oRow = mysql_fetch_object($hResult))
{
array_push($appIdArray, $oRow->appId); /* keep track of the apps we've already output */
outputTopXRow($oRow);
}
/* if we have any empty spots in the list, get these from applications with images */
$sQuery = "SELECT DISTINCT appVersion.appId as appId, appVersion.versionId
FROM appVersion, appData
WHERE appVersion.maintainer_rating = '$rating'
AND appVersion.versionId = appData.versionId
AND appData.type = 'image'
AND appData.queued = 'false'";
/* make sure we exclude any apps we've already output */
foreach($appIdArray as $key=>$value)
$sQuery.="AND appVersion.appId != '".$value."' ";
$sQuery.=" LIMIT $num_apps";
/* get the list that will fill the empty spots */
$hResult = query_appdb($sQuery);
while($oRow = mysql_fetch_object($hResult))
{
outputTopXRow($oRow);
}
}
/* return true if this word is in the list of words to ignore */
function isIgnoredWord($sWord)
{
$ignore_words = array('I', 'a', 'about', 'an', 'are', 'as', 'at', 'be', 'by', 'com',
'de', 'en', 'for', 'from', 'how', 'in', 'is', 'it', 'la', 'of',
'on', 'or', 'that', 'the', 'this', 'to', 'was', 'what', 'when',
'where', 'who', 'will', 'with', 'und', 'the', 'www', 'game');
$found = false;
/* search each item in the $ignore_words array */
foreach($ignore_words as $ik=>$iv)
{
/* if we find a match we should flag it as so */
if(strtoupper($sWord) == strtoupper($iv))
{
$found = true;
break; /* break out of this foreach loop */
}
}
return $found;
}
/* remove common words from $search_words to improve our searching results */
function cleanupSearchWords($search_words)
{
/* trim off leading and trailing spaces in $search_words */
/* to improve matching accuracy */
$search_words = trim($search_words);
$filtered_search = "";
/* search each word in $search_words */
$split_words = split(" ", $search_words);
foreach($split_words as $key=>$value)
{
/* see if this word is in the ignore list */
/* we remove any of the words in the ignore_words array. these are far too common */
/* and will result in way too many matches if we leave them in */
/* We will also remove any single letter search words */
$found = isIgnoredWord($value);
/* remove all single letters */
if((strlen($value) == 1) && !is_numeric($value))
$found = true;
/* if we didn't find this word, keep it */
if($found == false)
{
if($filtered_search)
$filtered_search.=" $value";
else
$filtered_search="$value";
} else
{
if($removed_words == "")
$removed_words.="'".$value."'";
else
$removed_words.=", '".$value."'";
}
}
/* replace the existing search with the filtered_search */
$search_words = $filtered_search;
return $search_words;
}
/* search the database and return a hResult from the query_appdb() */
function searchForApplication($search_words)
{
/* cleanup search words */
$search_words = cleanupSearchWords($search_words);
/* remove any search words less than 4 letters */
$split_words = array();
$split_search_words = split(" ", $search_words);
foreach($split_search_words as $key=>$value)
{
if(strlen($value) >= 4)
array_push($split_words, $value);
}
$vendorIdArray = array();
/* find all of the vendors whos names or urls match words in our */
/* search parameters */
foreach ($split_words as $key=>$value)
{
$sQuery = "SELECT vendorId from vendor where vendorName LIKE '%?%'
OR vendorURL LIKE '%?%'";
$hResult = query_parameters($sQuery, $value, $value);
while($oRow = mysql_fetch_object($hResult))
{
array_push($vendorIdArray, $oRow->vendorId);
}
}
/* base query */
$sQuery = "SELECT *
FROM appFamily, vendor
WHERE appName != 'NONAME'
AND appFamily.vendorId = vendor.vendorId
AND queued = 'false'
AND (appName LIKE '%".mysql_real_escape_string($search_words)."%'
OR keywords LIKE '%".mysql_real_escape_string($search_words)."%'";
/* append to the query any vendors that we matched with */
foreach($vendorIdArray as $key=>$value)
{
$sQuery.=" OR appFamily.vendorId=".mysql_real_escape_string($value);
}
$sQuery.=" ) ORDER BY appName";
$hResult = query_appdb($sQuery);
return $hResult;
}
function searchForApplicationFuzzy($search_words, $minMatchingPercent)
{
/* cleanup search words */
$search_words = cleanupSearchWords($search_words);
$foundAValue = false;
$excludeAppIdArray = array();
$appIdArray = array();
/* add on all of the like matches that we can find */
$hResult = searchForApplication($search_words);
while($oRow = mysql_fetch_object($hResult))
{
array_push($excludeAppIdArray, $oRow->appId);
}
/* add on all of the fuzzy matches we can find */
$sQuery = "SELECT appName, appId FROM appFamily WHERE queued = 'false'";
foreach ($excludeAppIdArray as $key=>$value)
{
$sQuery.=" AND appId != '".mysql_real_escape_string($value)."'";
}
$sQuery.=";";
/* capitalize the search words */
$search_words = strtoupper($search_words);
$hResult = query_appdb($sQuery);
while($oRow = mysql_fetch_object($hResult))
{
$oRow->appName = strtoupper($oRow->appName); /* convert the appname to upper case */
similar_text($oRow->appName, $search_words, $similarity_pst);
if(number_format($similarity_pst, 0) > $minMatchingPercent)
{
$foundAValue = true;
array_push($appIdArray, $oRow->appId);
}
}
if($foundAValue == false)
return null;
$sQuery = "SELECT * from appFamily WHERE ";
$firstEntry = true;
foreach ($appIdArray as $key=>$value)
{
if($firstEntry == true)
{
$sQuery.="appId='".mysql_real_escape_string($value)."'";
$firstEntry = false;
} else
{
$sQuery.=" OR appId='".mysql_real_escape_string($value)."'";
}
}
$sQuery.=" ORDER BY appName;";
$hResult = query_appdb($sQuery);
return $hResult;
}
function outputSearchTableForhResult($search_words, $hResult)
{
if(($hResult == null) || (mysql_num_rows($hResult) == 0))
{
// do something
echo html_frame_start("","98%");
echo "No matches found for '". urlencode($search_words) . "'\n";
echo html_frame_end();
} else
{
echo html_frame_start("","98%","",0);
echo "'.$oApp->sName.' '.$oVersion->sName.'
'.util_trim_description($oApp->sDescription).'
\n\n";
echo "
\n\n";
echo html_frame_end();
}
}
/* pass in $isVersion of true if we are processing changes for an app version */
/* or false if processing changes for an application family */
function process_app_version_changes($isVersion)
{
/* load up the version or application depending on which values are set */
if($isVersion)
$oVersion = new Version($_REQUEST['versionId']);
else
$oApp = new Application($_REQUEST['appId']);
// commit changes of form to database
if(($_REQUEST['submit'] == "Update Database") && $isVersion) /* is a version */
{
$oVersion->GetOutputEditorValues();
$oVersion->update();
} else if(($_REQUEST['submit'] == "Update Database") && !$isVersion) /* is an application */
{
$oApp->GetOutputEditorValues();
$oApp->update();
} else if($_REQUEST['submit'] == "Update URL")
{
$sWhatChanged = "";
$bAppChanged = false;
if (!empty($_REQUEST['url_desc']) && !empty($_REQUEST['url']) )
{
// process added URL
if($_SESSION['current']->showDebuggingInfos()) { echo "\n";
echo " \n\n";
$c = 0;
while($oRow = mysql_fetch_object($hResult))
{
//skip if a NONAME
if ($oRow->appName == "NONAME") { continue; }
//set row color
$bgcolor = ($c % 2) ? 'color0' : 'color1';
//count versions
$hResult2 = query_parameters("SELECT count(*) as versions FROM appVersion WHERE appId = '?' AND versionName != 'NONAME' and queued = 'false'",
$oRow->appId);
$y = mysql_fetch_object($hResult2);
//display row
echo "Application Name \n";
echo " Description \n";
echo " No. Versions \n";
echo "\n";
echo " \n\n";
$c++;
}
echo "".html_ahref($oRow->appName,BASE."appview.php?appId=$oRow->appId")." \n";
echo " ".util_trim_description($oRow->description)." \n";
echo " $y->versions \n";
echo " \n";
echo "$c match(es) found
or
$aDesc = explode("
",$aDesc[0],2);
$aDesc = explode("
",$aDesc[0],2);
$aDesc = explode("
",$aDesc[0],2); $aDesc = explode("
",$aDesc[0],2); return trim(strip_tags($aDesc[0])); } ?>