ChangeSet ID: 31177 CVSROOT: /opt/cvs-commit Module name: appdb Changes by: wineowner@winehq.org 2007/06/10 18:58:11
Modified files: include : application.php url.php
Log message: Chris Morgan cmorgan@alum.wpi.edu Prepend "http://" in front of urls that lack "://". Most urls tend to be websites and adding http:// where it is missing fixes a bunch of urls in the database
Patch: http://cvs.winehq.org/patch.py?id=31177
Old revision New revision Changes Path 1.112 1.113 +3 -1 appdb/include/application.php 1.17 1.18 +42 -18 appdb/include/url.php
Index: appdb/include/application.php diff -u -p appdb/include/application.php:1.112 appdb/include/application.php:1.113 --- appdb/include/application.php:1.112 10 Jun 2007 23:58:11 -0000 +++ appdb/include/application.php 10 Jun 2007 23:58:11 -0000 @@ -70,7 +70,9 @@ class Application { $this->sName = $oRow->appName; $this->sKeywords = $oRow->keywords; $this->sDescription = $oRow->description; - $this->sWebpage = $oRow->webPage; + //TODO: we should move the url to the appData table + // and return an id into the appData table here + $this->sWebpage = Url::normalize($oRow->webPage); $this->sQueued = $oRow->queued; }
Index: appdb/include/url.php diff -u -p appdb/include/url.php:1.17 appdb/include/url.php:1.18 --- appdb/include/url.php:1.17 10 Jun 2007 23:58:11 -0000 +++ appdb/include/url.php 10 Jun 2007 23:58:11 -0000 @@ -21,27 +21,32 @@ class Url { /** * Constructor, fetches the url $iUrlId is given. */ - function Url($iUrlId = null) + function Url($iUrlId = null, $oRow = null) { - // we are working on an existing url - if($iUrlId) + if(!$iUrlId && !$oRow) + return; + + if(!$oRow) { $sQuery = "SELECT appData.* FROM appData WHERE type = 'url' AND id = '?'"; - if($hResult = query_parameters($sQuery, $iUrlId)) - { - $oRow = mysql_fetch_object($hResult); - $this->iUrlId = $iUrlId; - $this->sDescription = $oRow->description; - $this->iAppId = $oRow->appId; - $this->iVersionId = $oRow->versionId; - $this->sUrl = $oRow->url; - $this->bQueued = $oRow->queued; - $this->sSubmitTime = $oRow->submitTime; - $this->iSubmitterId = $oRow->submitterId; - } + $hResult = query_parameters($sQuery, $iUrlId); + $oRow = mysql_fetch_object($hResult); + } + + // we are working on an existing url + if($oRow) + { + $this->iUrlId = $iUrlId; + $this->sDescription = $oRow->description; + $this->iAppId = $oRow->appId; + $this->iVersionId = $oRow->versionId; + $this->sUrl = Url::normalize($oRow->url); + $this->bQueued = $oRow->queued; + $this->sSubmitTime = $oRow->submitTime; + $this->iSubmitterId = $oRow->submitterId; } }
@@ -423,8 +428,7 @@ class Url { if($aValues["iVersionId"]) $sEmail = User::get_notify_email_address_list($aValues['iVersionId']); else - $sEmail = User::get_notify_email_address_list($aValues['iAppId']) -; + $sEmail = User::get_notify_email_address_list($aValues['iAppId']); if($sWhatChanged && $sEmail) { $oApp = new Application($aValues["iAppId"]); @@ -482,13 +486,33 @@ class Url {
for($i = 0; $oRow = mysql_fetch_object($hResult); $i++) { + // create a url object + $oUrl = new Url(null, $oRow); + $sReturn .= html_tr(array( "<b>Link</b>", - "<a href="$oRow->url">$oRow->description</a>"), + "<a href="$oUrl->sUrl">$oUrl->sDescription</a>"), "color1"); }
return $sReturn; } + + // if a url lacks "://" assume the url is an http one + // and prepend "http://" + function normalize($sTheUrl) + { + // if we already have "://" in the url + // we can leave the url alone + if(strpos($sTheUrl, "://") === false) + { + // assume this is a website and prepend "http://" + return "http://%22.$sTheUrl; + } else + { + // leave the url alone + return $sTheUrl; + } + } } ?>