");
// html-ify urls
$urlreg = "([a-zA-Z]+://([^\t\r\n ]+))";
$text = ereg_replace($urlreg, " \\2 ", $text);
$emailreg = "([a-zA-Z0-9_%+.-]+@[^\t\r\n ]+)";
$text = ereg_replace($emailreg, " \\1", $text);
$text = str_replace("\n", " ", $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 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 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;
}
/* used by outputTopXRowAppsFromRating() to reduce duplicated code */
function outputTopXRow($oRow)
{
$oVersion = new Version($oRow->versionId);
$oApp = new Application($oVersion->iAppId);
$img = Screenshot::get_random_screenshot_img(null, $oRow->versionId, false); // image, disable extra formatting
html_tr_highlight_clickable('appview.php?iVersionId='.$oRow->versionId, "white", "#f0f6ff", "white");
echo '
';
}
/* Output the rows for the Top-X tables on the main page */
function outputTopXRowAppsFromRating($rating, $iNum_apps)
{
/* clean the input values so we can continue to use query_appdb() */
$rating = mysql_real_escape_string($rating);
$iNum_apps = mysql_real_escape_string($iNum_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, $iNum_apps);
$iNum_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 no more app entries we should stop now and save ourselves a query */
if(!$iNum_apps) return;
/* 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 $iNum_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 "
\n\n";
echo "
\n";
echo "
Application Name
\n";
echo "
Description
\n";
echo "
No. Versions
\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 "
\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['iVersionId']);
else
$oApp = new Application($_REQUEST['iAppId']);
// commit changes of form to database
if(($_REQUEST['sSubmit'] == "Update Database") && $isVersion) /* is a version */
{
$oVersion->GetOutputEditorValues($_REQUEST);
$oVersion->update();
} else if(($_REQUEST['sSubmit'] == "Update Database") && !$isVersion) /* is an application */
{
$oApp->GetOutputEditorValues($_REQUEST);
$oApp->update();
} else if($_REQUEST['sSubmit'] == "Update URL")
{
$sWhatChanged = "";
$bAppChanged = false;
if (!empty($_REQUEST['sUrlDesc']) && !empty($_REQUEST['sUrl']) )
{
// process added URL
if($_SESSION['current']->showDebuggingInfos()) { echo "
"; }
if ($_REQUEST['adelete'][$i] == "on")
{
$hResult = query_parameters("DELETE FROM appData WHERE id = '?'", $_REQUEST['aId'][$i]);
if($hResult)
{
addmsg("
Fuzzy matches - minimum ".$minMatchingPercent."% match
";
$hResult = searchForApplicationFuzzy($search_words, $minMatchingPercent);
outputSearchTableForhResult($search_words, $hResult);
}
function display_page_range($iCurrentPage=1, $iPageRange=1, $iTotalPages=1, $sLinkurl=NULL)
{
if($sLinkurl==NULL)
{
$sLinkurl = $_SERVER['PHP_SELF']."?";
}
/* display the links to each of these pages */
$iCurrentPage = max(1,(min($iCurrentPage,$iTotalPages)));
$iPageRange = min($iPageRange,$iTotalPages);
if($iCurrentPage <= ceil($iPageRange/2))
{
$iStartPage = 1;
$iEndPage = $iPageRange;
} else
{
if($iCurrentPage + ($iPageRange/2) > $iTotalPages)
{
$iStartPage = $iTotalPages - $iPageRange;
$iEndPage = $iTotalPages;
} else
{
$iStartPage = $iCurrentPage - floor($iPageRange/2);
$iEndPage = $iCurrentPage + floor($iPageRange/2);
}
}
$iStartPage = max(1,$iStartPage);
if($iCurrentPage != 1)
{
echo "|< ";
$iPreviousPage = $iCurrentPage - 1;
echo "< ";
} else
{
echo "|< < ";
}
/* display the desired range */
for($iPg = $iStartPage; $iPg <= $iEndPage; $iPg++)
{
if($iPg != $iCurrentPage)
echo "$iPg ";
else
echo "$iPg ";
}
if($iCurrentPage < $iTotalPages)
{
$iNextPage = $iCurrentPage + 1;
echo "> ";
echo ">| ";
} else
{
echo "> >|";
}
}
// Expand a path like /something/somedirectory/../ to /something
// from http://us2.php.net/realpath
function SimplifyPath($path) {
$dirs = explode('/',$path);
for($i=0; $i';
// You must set _editor_url to the URL (including trailing slash) where
// where xinha is installed, it's highly recommended to use an absolute URL
// eg: _editor_url = "/path/to/xinha/";
// You may try a relative URL if you wish]
// eg: _editor_url = "../";
// in this example we do a little regular expression to find the absolute path.
// NOTE: we use GetSimplifiedPath() because we cannot use a relative path and have
// all of the plugins work correctly. Specifically the SpellChecker plugin
// requires a absolute url path to the xinha directory
echo '
_editor_url = "'.GetSimplifiedPath("xinha/").'", \'\';
_editor_lang = "en"; // And the language we need to use in the editor.
';
echo '
';
$outputIndex++; /* increment the output index */
}
/**
* Remove html formatting from description and extract the first part of the description only.
* This is to be used for search results, application summary tables, etc.
*/
function util_trim_description($sDescription)
{
// 1) let's take the first line of the description:
$aDesc = explode("\n",trim($sDescription),2);
// 2) maybe it's an html description and lines are separated with or