From: <ste...@us...> - 2011-06-24 21:44:18
|
Revision: 9041 http://supertuxkart.svn.sourceforge.net/supertuxkart/?rev=9041&view=rev Author: stephenjust Date: 2011-06-24 21:44:12 +0000 (Fri, 24 Jun 2011) Log Message: ----------- [stkaddons] Source upload works now. Modified Paths: -------------- stkaddons/trunk/include/coreAddon.php stkaddons/trunk/include/parseUpload.php stkaddons/trunk/table.sql Modified: stkaddons/trunk/include/coreAddon.php =================================================================== --- stkaddons/trunk/include/coreAddon.php 2011-06-24 20:25:44 UTC (rev 9040) +++ stkaddons/trunk/include/coreAddon.php 2011-06-24 21:44:12 UTC (rev 9041) @@ -552,10 +552,21 @@ echo '<tr>'; $approved = NULL; if ($source_file['approved'] == 0) $approved = ' ('._('Not Approved').')'; - echo '<td>'._('Source file').' '.$n.$approved.'</td>'; - echo '<td><a href="'.DOWN_LOCATION.$source_file['file_path'].'">'._('Download').'</a></td>'; - // FIXME: Add approval button - echo '</tr>'; + echo '<td><strong>'; + printf(_('Source File %s'),$n); + echo '</strong>'.$approved.'</td>'; + echo '<td><a href="'.DOWN_LOCATION.$source_file['file_path'].'">'._('Download').'</a>'; + if ($user->logged_in) + { + if ($_SESSION['role']['manageaddons']) + { + if ($source_file['approved'] == 1) + echo ' | <a href="'.$this->addonCurrent['permUrl'].'&save=unapprove&id='.$source_file['id'].'">'._('Unapprove').'</a>'; + else + echo ' | <a href="'.$this->addonCurrent['permUrl'].'&save=approve&id='.$source_file['id'].'">'._('Approve').'</a>'; + } + } + echo '</td></tr>'; } echo '</table>'; } Modified: stkaddons/trunk/include/parseUpload.php =================================================================== --- stkaddons/trunk/include/parseUpload.php 2011-06-24 20:25:44 UTC (rev 9040) +++ stkaddons/trunk/include/parseUpload.php 2011-06-24 21:44:12 UTC (rev 9041) @@ -34,15 +34,9 @@ return false; } + // This won't be set when uploading addons/revisions if (!isset($_POST['upload-type'])) $_POST['upload-type'] = NULL; - // FIXME: Source upload doesn't work yet - if ($_POST['upload-type'] == 'source') - { - echo '<span class="error">Source file upload is not implemented yet.</span><br />'; - return false; - } - // Check file-extension for uploaded file if ($_POST['upload-type'] == 'image') { @@ -124,112 +118,126 @@ $xml_file = find_xml(UP_LOCATION.'temp/'.$fileid); $xml_dir = dirname($xml_file); if (!$xml_file) { - echo '<span class="error>'._('Invalid archive file.').'</span><br />'; + echo '<span class="error>'._('Invalid archive file. The archive must contain the addon\'s xml file.').'</span><br />'; rmdir_recursive(UP_LOCATION.'temp/'.$fileid); return false; } - // Define addon type - if (preg_match('/kart\.xml$/',$xml_file)) - { - $addon_type = 'karts'; - echo _('Upload was recognized as a kart.').'<br />'; - } + // Check for invalid files + if ($_POST['upload-type'] == 'source') + $invalid_files = type_check($xml_dir, true); else + $invalid_files = type_check($xml_dir); + if (is_array($invalid_files) && count($invalid_files != 0)) { - $addon_type = 'tracks'; - echo _('Upload was recognized as a track.').'<br />'; + echo '<span class="warning">'._('Some invalid files were found in the uploaded add-on. These files have been removed from the archive:').' '.implode(', ',$invalid_files).'</span><br />'; } - // Read XML - $parsed_xml = read_xml($xml_file,$addon_type); - if (!$parsed_xml) + if ($_POST['upload-type'] != 'source') { - echo '<span class="error">'._('Failed to read the add-on\'s XML file. Please make sure you are using the latest version of the kart or track exporter.').'</span><br />'; - rmdir_recursive(UP_LOCATION.'temp/'.$fileid); - return false; - } - // Write new XML file - $fhandle = fopen($xml_file,'w'); - if (!fwrite($fhandle,$parsed_xml['xml'])) { - echo '<span class="error">'._('Failed to write new XML file:').'</span><br />'; - } - fclose($fhandle); + // Define addon type + if (preg_match('/kart\.xml$/',$xml_file)) + { + $addon_type = 'karts'; + echo _('Upload was recognized as a kart.').'<br />'; + } + else + { + $addon_type = 'tracks'; + echo _('Upload was recognized as a track.').'<br />'; + } - // Check for valid license file - $license_file = find_license(UP_LOCATION.'temp/'.$fileid); - if ($license_file === false) - { - echo '<span class="error">'._('A valid License.txt file was not found. Please add a License.txt file to your archive and re-submit it.').'</span><br />'; - rmdir_recursive(UP_LOCATION.'temp/'.$fileid); - return false; - } - $parsed_xml['attributes']['license'] = $license_file; + // Read XML + $parsed_xml = read_xml($xml_file,$addon_type); + if (!$parsed_xml) + { + echo '<span class="error">'._('Failed to read the add-on\'s XML file. Please make sure you are using the latest version of the kart or track exporter.').'</span><br />'; + rmdir_recursive(UP_LOCATION.'temp/'.$fileid); + return false; + } + // Write new XML file + $fhandle = fopen($xml_file,'w'); + if (!fwrite($fhandle,$parsed_xml['xml'])) { + echo '<span class="error">'._('Failed to write new XML file:').'</span><br />'; + } + fclose($fhandle); - // Get addon id - $addon_id = NULL; - if (isset($_GET['name'])) - $addon_id = addon_id_clean($_GET['name']); - if (!preg_match('/^[a-z0-9\-]+_?[0-9]*$/i',$addon_id) || $addon_id == NULL) - $addon_id = generate_addon_id($addon_type,$parsed_xml['attributes']); + // Check for valid license file + $license_file = find_license(UP_LOCATION.'temp/'.$fileid); + if ($license_file === false) + { + echo '<span class="error">'._('A valid License.txt file was not found. Please add a License.txt file to your archive and re-submit it.').'</span><br />'; + rmdir_recursive(UP_LOCATION.'temp/'.$fileid); + return false; + } + $parsed_xml['attributes']['license'] = $license_file; - // Save addon icon or screenshot - if ($addon_type == 'tracks') - { - $image_file = $xml_dir.'/'.$parsed_xml['attributes']['screenshot']; - } - else - { - $image_file = $xml_dir.'/'.$parsed_xml['attributes']['icon-file']; - } - // Check if file exists - if (!file_exists($image_file)) - { - $image_file = ''; - } - // Get image file extension - preg_match('/\.([a-z]+)$/i',$image_file,$imageext); - // Save file - copy($image_file,UP_LOCATION.'images/'.$fileid.'.'.$imageext[1]); - $parsed_xml['attributes']['image'] = $fileid.'.'.$imageext[1]; + // Get addon id + $addon_id = NULL; + if (isset($_GET['name'])) + $addon_id = addon_id_clean($_GET['name']); + if (!preg_match('/^[a-z0-9\-]+_?[0-9]*$/i',$addon_id) || $addon_id == NULL) + $addon_id = generate_addon_id($addon_type,$parsed_xml['attributes']); - // Record image file in database - $newImageQuery = 'INSERT INTO `'.DB_PREFIX.'files` - (`addon_id`,`addon_type`,`file_type`,`file_path`) - VALUES - (\''.$addon_id.'\', - \''.$addon_type.'\', - \'image\', - \'images/'.$fileid.'.'.$imageext[1].'\')'; - $newImageHandle = sql_query($newImageQuery); - if (!$newImageHandle) - { - echo '<span class="error">'._('Failed to associate image file with addon.').'</span><br />'; - unlink(UP_LOCATION.'images/'.$fileid.'.'.$imageext[1]); - $parsed_xml['attributes']['image'] = 0; - } - else - { - // Get ID of previously inserted image - $parsed_xml['attributes']['image'] = mysql_insert_id(); - } + // Save addon icon or screenshot + if ($addon_type == 'tracks') + { + $image_file = $xml_dir.'/'.$parsed_xml['attributes']['screenshot']; + } + else + { + $image_file = $xml_dir.'/'.$parsed_xml['attributes']['icon-file']; + } + // Check if file exists + if (!file_exists($image_file)) + { + $image_file = ''; + } + // Get image file extension + preg_match('/\.([a-z]+)$/i',$image_file,$imageext); + // Save file + copy($image_file,UP_LOCATION.'images/'.$fileid.'.'.$imageext[1]); + $parsed_xml['attributes']['image'] = $fileid.'.'.$imageext[1]; - // Initialize the status flag - $parsed_xml['attributes']['status'] = 0; + // Record image file in database + $newImageQuery = 'INSERT INTO `'.DB_PREFIX.'files` + (`addon_id`,`addon_type`,`file_type`,`file_path`) + VALUES + (\''.$addon_id.'\', + \''.$addon_type.'\', + \'image\', + \'images/'.$fileid.'.'.$imageext[1].'\')'; + $newImageHandle = sql_query($newImageQuery); + if (!$newImageHandle) + { + echo '<span class="error">'._('Failed to associate image file with addon.').'</span><br />'; + unlink(UP_LOCATION.'images/'.$fileid.'.'.$imageext[1]); + $parsed_xml['attributes']['image'] = 0; + } + else + { + // Get ID of previously inserted image + $parsed_xml['attributes']['image'] = mysql_insert_id(); + } - // Check to make sure all image dimensions are powers of 2 - if (!image_check($xml_dir)) - { - echo '<span class="warning">'._('Some images in this add-on do not have dimensions that are a power of two.') - .' '._('This may cause display errors on some video cards.').'</span><br />'; - $parsed_xml['attributes']['status'] += F_TEX_NOT_POWER_OF_2; + // Initialize the status flag + $parsed_xml['attributes']['status'] = 0; + + // Check to make sure all image dimensions are powers of 2 + if (!image_check($xml_dir)) + { + echo '<span class="warning">'._('Some images in this add-on do not have dimensions that are a power of two.') + .' '._('This may cause display errors on some video cards.').'</span><br />'; + $parsed_xml['attributes']['status'] += F_TEX_NOT_POWER_OF_2; + } + + $filetype = 'addon'; } - - // Check for invalid files - $invalid_files = type_check($xml_dir); - if (is_array($invalid_files) && count($invalid_files != 0)) + else { - echo '<span class="warning">'._('Some invalid files were found in the uploaded add-on. These files have been removed from the archive:').' '.implode(', ',$invalid_files).'</span><br />'; + $addon_id = addon_id_clean($_GET['name']); + $addon_type = mysql_real_escape_string($_GET['type']); + $filetype = 'source'; } // Repack zip file @@ -246,20 +254,30 @@ VALUES (\''.$addon_id.'\', \''.$addon_type.'\', - \'addon\', + \''.$filetype.'\', \''.$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; + if ($_POST['upload-type'] != 'source') + $parsed_xml['attributes']['fileid'] = 0; } else { - // Get ID of previously inserted image - $parsed_xml['attributes']['fileid'] = mysql_insert_id(); + // Get ID of previously inserted file + if ($_POST['upload-type'] != 'source') + $parsed_xml['attributes']['fileid'] = mysql_insert_id(); } + + if ($_POST['upload-type'] == 'source') + { + rmdir_recursive(UP_LOCATION.'temp/'.$fileid); + echo _('Successfully uploaded source archive.').'<br />'; + echo '<span style="font-size: large"><a href="addons.php?type='.$addon_type.'&name='.$addon_id.'">'._('Continue.').'</a></span><br />'; + return true; + } // Set first revision to be "latest" if ($revision == false) @@ -627,14 +645,17 @@ return true; } -function type_check($path) +function type_check($path, $source = false) { if (!file_exists($path)) return false; if (!is_dir($path)) return false; // Make a list of approved file types - $approved_types = get_config('allowed_addon_exts'); + if ($source === false) + $approved_types = get_config('allowed_addon_exts'); + else + $approved_types = get_config('allowed_source_exts'); $approved_types = explode(',',$approved_types); $removed_files = array(); Modified: stkaddons/trunk/table.sql =================================================================== --- stkaddons/trunk/table.sql 2011-06-24 20:25:44 UTC (rev 9040) +++ stkaddons/trunk/table.sql 2011-06-24 21:44:12 UTC (rev 9041) @@ -128,5 +128,6 @@ PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; +/* Default admin password is 'password' - Change after install. */ INSERT INTO `users` (`user`, `pass`, `name`, `role`, `email`, `active`, `last_login`, `verify`, `reg_date`, `homepage`) VALUES -('admin', 'd8fc1f6f58d1872be71a07ed0094b9bf715e5c9d90018c9ce82af0a0582ee868', 'Administrator', 'root', 'webmaster@localhost', 1, '2011-03-05 03:24:32', '', '2011-03-03', NULL); +('admin', '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8', 'Administrator', 'root', 'webmaster@localhost', 1, '2011-03-05 03:24:32', '', '2011-03-03', NULL); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |