From: <ste...@us...> - 2011-06-22 23:20:05
|
Revision: 9013 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=9013&view=rev Author: stephenjust Date: 2011-06-22 23:19:59 +0000 (Wed, 22 Jun 2011) Log Message: ----------- [stkaddons] Addon file downloads are now counted (stats are not displayed, but they are recorded) Modified Paths: -------------- stkaddons/trunk/generate_xml.php stkaddons/trunk/include/coreAddon.php stkaddons/trunk/include/parseUpload.php stkaddons/trunk/include/xmlWrite.php stkaddons/trunk/table.sql Modified: stkaddons/trunk/generate_xml.php =================================================================== --- stkaddons/trunk/generate_xml.php 2011-06-22 20:54:00 UTC (rev 9012) +++ stkaddons/trunk/generate_xml.php 2011-06-22 23:19:59 UTC (rev 9013) @@ -20,8 +20,7 @@ define('ROOT','./'); include_once('config.php'); -include_once('include/sql.php'); -include_once('include/xmlWrite.php'); +include_once('include.php'); $xml = writeNewsXML(); echo 'News xml written: '.$xml.'<br />'; Modified: stkaddons/trunk/include/coreAddon.php =================================================================== --- stkaddons/trunk/include/coreAddon.php 2011-06-22 20:54:00 UTC (rev 9012) +++ stkaddons/trunk/include/coreAddon.php 2011-06-22 23:19:59 UTC (rev 9013) @@ -35,7 +35,7 @@ $icon = ' r.icon,'; if (!$rev) { - $querySql = 'SELECT a.*, r.id AS fileid, r.creation_date AS revision_timestamp, + $querySql = 'SELECT a.*, r.fileid, r.creation_date AS revision_timestamp, r.revision, r.format, r.image,'.$icon.' r.status, r.moderator_note FROM `'.DB_PREFIX.'addons` `a` LEFT JOIN `'.DB_PREFIX.$this->addonType.'_revs` `r` @@ -46,7 +46,7 @@ } else { - $querySql = 'SELECT a.*, r.id AS fileid, r.creation_date AS revision_timestamp, + $querySql = 'SELECT a.*, r.fileid, r.creation_date AS revision_timestamp, r.revision, r.format, r.image,'.$icon.' r.status, r.moderator_note FROM '.DB_PREFIX.'addons a LEFT JOIN '.DB_PREFIX.$this->addonType.'_revs r @@ -76,7 +76,7 @@ $icon = NULL; if ($this->addonType == 'karts') $icon = ' r.icon,'; - $querySql = 'SELECT a.*, r.id AS fileid, + $querySql = 'SELECT a.*, r.fileid, r.creation_date AS revision_timestamp, r.revision, r.format, r.image,'.$icon.' r.status, r.moderator_note FROM '.DB_PREFIX.'addons a @@ -97,7 +97,7 @@ $icon = NULL; if ($this->addonType == 'karts') $icon = ' r.icon,'; - $querySql = 'SELECT a.*, r.id AS fileid, r.revision, r.format, r.image,'.$icon.' r.status + $querySql = 'SELECT a.*, r.fileid, r.revision, r.format, r.image,'.$icon.' r.status FROM '.DB_PREFIX.'addons a LEFT JOIN '.DB_PREFIX.$this->addonType.'_revs r ON a.id = r.addon_id @@ -284,12 +284,6 @@ for ($i = 1; $i <= $num_revisions; $i++) { $getRevsResult = mysql_fetch_assoc($getRevsHandle); - // Delete revision archive - if (file_exists(UP_LOCATION.$getRevsResult['id'].'.zip') && !unlink(UP_LOCATION.$getRevsResult['id'].'.zip')) - { - echo _('Failed to delete file:').' '.UP_LOCATION.$getRevsResult['id'].'.zip<br />'; - return false; - } // Delete entry if (!sql_remove_where($this->addonType.'_revs', 'id', $getRevsResult['id'])) { @@ -360,9 +354,19 @@ <tr><td><strong>'._('Submitted by:').'</strong></td><td><a href="users.php?title='.$addonUser->userCurrent['id'].'">'.$addonUser->userCurrent['name'].'</a></td></tr> <tr><td><strong>'._('Revision:').'</strong></td><td>'.$this->addonCurrent['revision'].'</td></tr> <tr><td><strong>'._('Compatible with:').'</strong></td><td>'.format_compat($this->addonCurrent['format'],$this->addonType).'</td></tr> - </table></div> - - <a href="'.DOWN_LOCATION.$this->addonCurrent['fileid'].'.zip"><img src="image/download.png" alt="Download" title="Download" /></a> + </table></div>'; + + // Get download path + $file_path = get_file_path($result['fileid']); + if ($file_path !== false) + { + if (file_exists(UP_LOCATION.$file_path)) + { + echo '<a href="'.DOWN_LOCATION.$file_path.'">'; + } + } + + echo '<img src="image/download.png" alt="Download" title="Download" /></a> <br /><br /><br /><br /> <strong>'._('License:').'</strong><br /> <textarea name="license" rows="4" cols="60">'.strip_tags($this->addonCurrent['license']).'</textarea> @@ -379,6 +383,7 @@ global $user; if (!$user->logged_in) { + // Users not logged in cannot see unapproved addons if (!($addonRevs->addonCurrent['status'] & F_APPROVED)) { $addonRevs->next(); @@ -387,6 +392,8 @@ } else { + // Logged in users who are not the uploader, or moderators + // cannot see unapproved addons if (($addonRevs->addonCurrent['uploader'] != $_SESSION['userid'] && !$_SESSION['role']['manageaddons']) && !($addonRevs->addonCurrent['status'] & F_APPROVED)) @@ -396,8 +403,25 @@ } } - echo '<tr><td>'.$addonRevs->addonCurrent['revision_timestamp'].'</td> - <td><a href="'.DOWN_LOCATION.$addonRevs->addonCurrent['fileid'].'.zip">'._('Download revision').' '.$addonRevs->addonCurrent['revision'].'</a></td></tr>'; + echo '<tr><td>'.$addonRevs->addonCurrent['revision_timestamp'].'</td><td>'; + // Get download path + $file_path = get_file_path($addonRevs->addonCurrent['fileid']); + if ($file_path !== false) + { + if (file_exists(UP_LOCATION.$file_path)) + { + echo '<a href="'.DOWN_LOCATION.$file_path.'">'._('Download revision').' '.$addonRevs->addonCurrent['revision'].'</a>'; + } + else + { + echo _('Revision').' '.$addonRevs->addonCurrent['revision'].' - '._('File not found.'); + } + } + else + { + echo _('Revision').' '.$addonRevs->addonCurrent['revision'].' - '._('File not found.'); + } + echo '</td></tr>'; $addonRevs->next(); } echo '</table>'; @@ -811,8 +835,8 @@ $rev = $result['revision'] + 1; } // Add revision entry - $fields = array('id','addon_id','revision','format','image','status'); - $values = array($fileid,$addonid,$rev,$attributes['version'],$attributes['image'],$attributes['status']); + $fields = array('id','addon_id','fileid','revision','format','image','status'); + $values = array($fileid,$addonid,$attributes['fileid'],$rev,$attributes['version'],$attributes['image'],$attributes['status']); if ($this->addonType == 'karts') { $fields[] = 'icon'; @@ -943,6 +967,25 @@ return false; } +function get_file_path($file_id) +{ + // Validate input + if (!is_numeric($file_id)) + return false; + if ($file_id == 0) + return false; + + // Look up file path from database + $query = 'SELECT `file_path` FROM `'.DB_PREFIX.'files` + WHERE `id` = '.(int)$file_id.' + LIMIT 1'; + $handle = sql_query($query); + if (mysql_num_rows($handle) == 0) + return false; + $file = mysql_fetch_assoc($handle); + return $file['file_path']; +} + function update_addon_notes($type,$addon_id,$fields) { if (!$_SESSION['role']['manageaddons']) @@ -999,7 +1042,7 @@ } if ($format == 2) { - return '0.7 - 0.7.1b'; + return '0.7 - 0.7.2'; } return _('Unknown'); break; Modified: stkaddons/trunk/include/parseUpload.php =================================================================== --- stkaddons/trunk/include/parseUpload.php 2011-06-22 20:54:00 UTC (rev 9012) +++ stkaddons/trunk/include/parseUpload.php 2011-06-22 23:19:59 UTC (rev 9013) @@ -84,7 +84,7 @@ return false; } - // Add database record + // Add database record for image $newImageQuery = 'INSERT INTO `'.DB_PREFIX.'files` (`addon_id`,`addon_type`,`file_type`,`file_path`) VALUES @@ -239,6 +239,27 @@ rmdir_recursive(UP_LOCATION.'temp/'.$fileid); return false; } + + // Record addon's file in database + $newAddonFileQuery = 'INSERT INTO `'.DB_PREFIX.'files` + (`addon_id`,`addon_type`,`file_type`,`file_path`) + VALUES + (\''.$addon_id.'\', + \''.$addon_type.'\', + \'addon\', + \''.$fileid.'.zip\')'; + $newAddonFileHandle = sql_query($newAddonFileQuery); + if (!$newAddonFileHandle) + { + echo '<span class="error">'._('Failed to associate archive file with addon.').'</span><br />'; + unlink(UP_LOCATION.$fileid.'.zip'); + $parsed_xml['attributes']['fileid'] = 0; + } + else + { + // Get ID of previously inserted image + $parsed_xml['attributes']['fileid'] = mysql_insert_id(); + } // Set first revision to be "latest" if ($revision == false) Modified: stkaddons/trunk/include/xmlWrite.php =================================================================== --- stkaddons/trunk/include/xmlWrite.php 2011-06-22 20:54:00 UTC (rev 9012) +++ stkaddons/trunk/include/xmlWrite.php 2011-06-22 23:19:59 UTC (rev 9013) @@ -100,7 +100,7 @@ $writer->writeAttribute('frequency', get_config('xml_frequency')); // Fetch kart list - $querySql = 'SELECT `k`.*, `r`.`id` AS `fileid`, + $querySql = 'SELECT `k`.*, `r`.`fileid`, `r`.`creation_date` AS `date`,`r`.`revision`,`r`.`format`, `r`.`image`,`r`.`icon`,`r`.`status`, `u`.`user` FROM '.DB_PREFIX.'addons k @@ -112,60 +112,51 @@ $reqSql = sql_query($querySql); while($result = sql_next($reqSql)) { - if (!file_exists(UP_LOCATION.$result['fileid'].'.zip')) + $file_path = get_file_path($result['fileid']); + if ($file_path === false) { - echo '<span class="warming">'._('The following file could not be found:').' '.$result['fileid'].'.zip</span><br />'; + echo '<span class="warning">'._('An error occurred finding the path for the file of kart: ').$result['name'].'</span><br />'; continue; } + if (!file_exists(UP_LOCATION.$file_path)) + { + echo '<span class="warming">'._('The following file could not be found:').' '.$file_path.'</span><br />'; + continue; + } $writer->startElement('kart'); $writer->writeAttribute('id',$result['id']); $writer->writeAttribute('name',$result['name']); - $writer->writeAttribute('file',DOWN_LOCATION.$result['fileid'].'.zip'); + $file_path = get_file_path($result['fileid']); + $writer->writeAttribute('file',DOWN_LOCATION.$file_path); $writer->writeAttribute('date',strtotime($result['date'])); $writer->writeAttribute('uploader',$result['user']); $writer->writeAttribute('designer',$result['designer']); $writer->writeAttribute('description',$result['description']); - if ($result['icon'] != 0) + $icon_path = get_file_path($result['icon']); + if ($icon_path !== false) { - $get_image_query = 'SELECT `file_path` FROM `'.DB_PREFIX.'files` - WHERE `id` = '.(int)$result['icon'].' - AND `approved` = 1 - LIMIT 1'; - $get_image_handle = sql_query($get_image_query); - if (mysql_num_rows($get_image_handle) == 1) + if (file_exists(UP_LOCATION.$icon_path)) { - $icon = mysql_fetch_assoc($get_image_handle); - if (file_exists(UP_LOCATION.$icon['file_path'])) - { - $writer->writeAttribute('icon',DOWN_LOCATION.$icon['file_path']); - } + $writer->writeAttribute('icon',DOWN_LOCATION.$icon_path); } } - if ($result['image'] != 0) + $image_path = get_file_path($result['image']); + if ($image_path !== false) { - $get_image_query = 'SELECT `file_path` FROM `'.DB_PREFIX.'files` - WHERE `id` = '.(int)$result['image'].' - AND `approved` = 1 - LIMIT 1'; - $get_image_handle = sql_query($get_image_query); - if (mysql_num_rows($get_image_handle) == 1) + if (file_exists(UP_LOCATION.$image_path)) { - $image = mysql_fetch_assoc($get_image_handle); - if (file_exists(UP_LOCATION.$image['file_path'])) - { - $writer->writeAttribute('image',DOWN_LOCATION.$image['file_path']); - } + $writer->writeAttribute('image',DOWN_LOCATION.$image_path); } } $writer->writeAttribute('format',$result['format']); $writer->writeAttribute('revision',$result['revision']); $writer->writeAttribute('status',$result['status']); - $writer->writeAttribute('size',filesize(UP_LOCATION.$result['fileid'].'.zip')); + $writer->writeAttribute('size',filesize(UP_LOCATION.$file_path)); $writer->endElement(); } // Fetch track list - $querySql = 'SELECT `k`.*, `r`.`id` AS `fileid`, + $querySql = 'SELECT `k`.*, `r`.`fileid`, `r`.`creation_date` AS `date`,`r`.`revision`,`r`.`format`, `r`.`image`,`r`.`status`, `u`.`user` FROM '.DB_PREFIX.'addons k @@ -177,40 +168,39 @@ $reqSql = sql_query($querySql); while($result = sql_next($reqSql)) { - if (!file_exists(UP_LOCATION.$result['fileid'].'.zip')) + $file_path = get_file_path($result['fileid']); + if ($file_path === false) { - echo '<span class="warming">'._('The following file could not be found:').' '.$result['fileid'].'.zip</span><br />'; + echo '<span class="warning">'._('An error occurred finding the path for the file of track: ').$result['name'].'</span><br />'; continue; } + if (!file_exists(UP_LOCATION.$file_path)) + { + echo '<span class="warming">'._('The following file could not be found:').' '.$file_path.'</span><br />'; + continue; + } $writer->startElement('track'); $writer->writeAttribute('id',$result['id']); $writer->writeAttribute('name',$result['name']); - $writer->writeAttribute('file',DOWN_LOCATION.$result['fileid'].'.zip'); + $file_path = get_file_path($result['fileid']); + $writer->writeAttribute('file',DOWN_LOCATION.$file_path); $writer->writeAttribute('arena',$result['props']); $writer->writeAttribute('date',strtotime($result['date'])); $writer->writeAttribute('uploader',$result['user']); $writer->writeAttribute('designer',$result['designer']); $writer->writeAttribute('description',$result['description']); - if ($result['image'] != 0) + $image_path = get_file_path($result['image']); + if ($image_path !== false) { - $get_image_query = 'SELECT `file_path` FROM `'.DB_PREFIX.'files` - WHERE `id` = '.(int)$result['image'].' - AND `approved` = 1 - LIMIT 1'; - $get_image_handle = sql_query($get_image_query); - if (mysql_num_rows($get_image_handle) == 1) + if (file_exists(UP_LOCATION.$image_path)) { - $image = mysql_fetch_assoc($get_image_handle); - if (file_exists(UP_LOCATION.$image['file_path'])) - { - $writer->writeAttribute('image',DOWN_LOCATION.$image['file_path']); - } + $writer->writeAttribute('image',DOWN_LOCATION.$image_path); } } $writer->writeAttribute('format',$result['format']); $writer->writeAttribute('revision',$result['revision']); $writer->writeAttribute('status',$result['status']); - $writer->writeAttribute('size',filesize(UP_LOCATION.$result['fileid'].'.zip')); + $writer->writeAttribute('size',filesize(UP_LOCATION.$file_path)); $writer->endElement(); } Modified: stkaddons/trunk/table.sql =================================================================== --- stkaddons/trunk/table.sql 2011-06-22 20:54:00 UTC (rev 9012) +++ stkaddons/trunk/table.sql 2011-06-22 23:19:59 UTC (rev 9013) @@ -73,6 +73,7 @@ CREATE TABLE `karts_revs` ( `id` char(23) NOT NULL, `addon_id` varchar(30) NOT NULL, + `fileid` INT UNSIGNED NOT NULL DEFAULT '0', `creation_date` timestamp NOT NULL default CURRENT_TIMESTAMP, `revision` tinyint(4) NOT NULL default '1', `format` tinyint(4) NOT NULL, @@ -122,6 +123,7 @@ CREATE TABLE `tracks_revs` ( `id` char(23) NOT NULL, `addon_id` varchar(30) NOT NULL, + `fileid` INT UNSIGNED NOT NULL DEFAULT '0', `creation_date` timestamp NOT NULL default CURRENT_TIMESTAMP, `revision` tinyint(4) NOT NULL default '1', `format` tinyint(4) NOT NULL, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |