Skip to content

Commit

Permalink
[C] Fixed config to generate old and new server xml files
Browse files Browse the repository at this point in the history
Fixed phpcs and phpstan
Moved generate xml files to be a tool
  • Loading branch information
vampy committed Apr 15, 2019
1 parent b4220f4 commit a363381
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: php

php:
- 7.1
- 7.2
- 7.3

script:
- ./vendor/bin/phpunit --configuration phpunit.xml
Expand Down
50 changes: 35 additions & 15 deletions include/xmlWrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with stk-addons. If not, see <http://www.gnu.org/licenses/>.
*/

function generateNewsXML()
function generateNewsXML($assets_xml_location, $assets_xml_path)
{
$writer = new XMLWriter();

Expand All @@ -45,8 +45,17 @@ function generateNewsXML()

// Reference assets.xml
$writer->startElement('include');
$writer->writeAttribute('file', ASSETS_XML_LOCATION);
$writer->writeAttribute('mtime', FileSystem::fileModificationTime(ASSETS_XML_PATH, false));
$writer->writeAttribute('file', $assets_xml_location);

try
{
$modification_time = FileSystem::fileModificationTime($assets_xml_path, false);
}
catch (FileSystemException $e)
{
$modification_time = 0;
}
$writer->writeAttribute('mtime', $modification_time);
$writer->endElement();

// Refresh dynamic news entries
Expand Down Expand Up @@ -80,7 +89,7 @@ function generateNewsXML()
return $return;
}

function generateAssetXML()
function generateAssetXML($download_location)
{
// Define addon types
$addon_types = ['kart', 'track', 'arena'];
Expand Down Expand Up @@ -168,7 +177,7 @@ function generateAssetXML()
$writer->startElement($type);
$writer->writeAttribute('id', $addon['id']);
$writer->writeAttribute('name', $addon['name']);
$writer->writeAttribute('file', DOWNLOAD_LOCATION . $relative_path);
$writer->writeAttribute('file', $download_location . $relative_path);
$writer->writeAttribute('date', strtotime($addon['date']));
$writer->writeAttribute('uploader', $addon['username']);
$writer->writeAttribute('designer', $addon['designer']);
Expand All @@ -182,7 +191,7 @@ function generateAssetXML()
$image_path = File::getFromID($addon['image_id'])->getPath();
if (FileSystem::exists(UP_PATH . $image_path))
{
$writer->writeAttribute('image', DOWNLOAD_LOCATION . $image_path);
$writer->writeAttribute('image', $download_location . $image_path);
}
}
catch (FileException $e)
Expand All @@ -200,7 +209,7 @@ function generateAssetXML()
$icon_path = File::getFromID($icon_id)->getPath();
if (FileSystem::exists(UP_PATH . $icon_path))
{
$writer->writeAttribute('icon', DOWNLOAD_LOCATION . $icon_path);
$writer->writeAttribute('icon', $download_location . $icon_path);
}
}
catch (FileException $e)
Expand Down Expand Up @@ -477,18 +486,29 @@ function generateAssetXML()

function writeNewsXML()
{
$newsxml = generateNewsXML();
FileSystem::filePutContents(NEWS_XML_PATH, str_replace("http://addons.supertuxkart.net/dl/", "https://online.supertuxkart.net/dl/", $newsxml));
return FileSystem::filePutContents(OLD_NEWS_XML_PATH, $newsxml);
$news_xml = generateNewsXML(OLD_ASSETS_XML_LOCATION, OLD_NEWS_XML_LOCATION);

// Write new xml file
FileSystem::filePutContents(
NEWS_XML_PATH,
str_replace(OLD_DOWNLOAD_LOCATION, DOWNLOAD_LOCATION, $news_xml)
);


return FileSystem::filePutContents(OLD_NEWS_XML_PATH, $news_xml);
}

function writeAssetXML()
{
$assetxml = generateAssetXML();
FileSystem::filePutContents(ASSETS_XML_PATH, str_replace("http://addons.supertuxkart.net/dl/", "https://online.supertuxkart.net/dl/", $assetxml));
$count = FileSystem::filePutContents(OLD_ASSETS_XML_PATH, $assetxml);
//$count += File::write(ASSETS2_XML_PATH, generateAssetXML2());
return $count;
$asset_xml = generateAssetXML(OLD_DOWNLOAD_LOCATION);

// Write new xml file
FileSystem::filePutContents(
ASSETS_XML_PATH,
str_replace(OLD_DOWNLOAD_LOCATION, DOWNLOAD_LOCATION, $asset_xml)
);

return FileSystem::filePutContents(OLD_ASSETS_XML_PATH, $asset_xml);
}

function writeXML()
Expand Down
55 changes: 38 additions & 17 deletions install/config.EXAMPLE.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Copyright 2009 - 2017 SuperTuxKart-Team
* Copyright 2009 - 2019 SuperTuxKart-Team
*
* This file is part of stk-addons.
*
Expand Down Expand Up @@ -28,15 +28,8 @@
// useful for to know if downloading file
if (!defined('DOWNLOAD_MODE')) define('DOWNLOAD_MODE', false);

// Redirect access from web browser to secure server
// NOTE: Do not redirect API requests or download requests as Old STK versions can't handle proper certificates
const REDIRECT_TO_HTTPS_SERVER_NAME = false;
const STK_HTTPS_SERVER_NAME = "https://online.supertuxkart.net";
if (!API_MODE && !DOWNLOAD_MODE && REDIRECT_TO_HTTPS_SERVER_NAME)
{
header("Location: " . STK_HTTPS_SERVER_NAME . $_SERVER['REQUEST_URI'], true, 307);
exit;
}
// Check if we are in CLI mode
define('CLI_MODE', php_sapi_name() == "cli");

// WARNING!!!! turn OFF in the production server.
// Enable this when you want detailed debugging output.
Expand All @@ -56,6 +49,18 @@
// Do you prefer https?
const PREFER_SSL = true;


// Redirect access from web browser to secure server
// NOTE: Do not redirect API requests or download requests as Old STK versions can't handle proper certificates
const REDIRECT_TO_HTTPS_SERVER_NAME = false;
const STK_HTTPS_SERVER_NAME = "https://online.supertuxkart.net";
if (!API_MODE && !DOWNLOAD_MODE && REDIRECT_TO_HTTPS_SERVER_NAME)
{
header("Location: " . STK_HTTPS_SERVER_NAME . $_SERVER['REQUEST_URI'], true, 307);
exit;
}


// set default values
ini_set('html_errors', 'On');
if (DEBUG_MODE)
Expand All @@ -81,12 +86,18 @@
$DOMAIN_NAME = $_SERVER['SERVER_NAME'] . (!in_array($_SERVER['SERVER_PORT'], ['80', '443'], true) ? ':' . $_SERVER['SERVER_PORT'] : '');
}


//
// Cron constants
//

// After how many days should we delete the verification emails
const CRON_DAILY_VERIFICATION_DAYS = 1;


//
// Paths on the local filesystem
//
const DS = DIRECTORY_SEPARATOR;
const ROOT_PATH = __DIR__ . DS;
const INCLUDE_PATH = ROOT_PATH . 'include' . DS;
Expand All @@ -100,13 +111,17 @@
const CACHE_PATH = ASSETS_PATH . 'cache' . DS; // cache for images/html/template
const FONTS_PATH = ASSETS_PATH . 'fonts' . DS;

// For old server, http only
const OLD_NEWS_XML_PATH = UP_PATH . 'xml' . DS . 'news.xml';
const NEWS_XML_PATH = UP_PATH . 'xml' . DS . 'online_news.xml';
const OLD_ASSETS_XML_PATH = UP_PATH . 'xml' . DS . 'assets.xml';

// For new online server, https only
const NEWS_XML_PATH = UP_PATH . 'xml' . DS . 'online_news.xml';
const ASSETS_XML_PATH = UP_PATH . 'xml' . DS . 'online_assets.xml';
const ASSETS2_XML_PATH = UP_PATH . 'xml' . DS . 'assets2.xml';

//
// Location urls
//
define('ROOT_LOCATION_UNSECURE', 'http://' . $DOMAIN_NAME . '/');
if ((PREFER_SSL && IS_SSL_CERTIFICATE_VALID) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'))
{
Expand All @@ -118,14 +133,20 @@
}

// Change this if you want downloads to be from another server
const OLD_DOWNLOAD_LOCATION_ROOT_SERVER = "http://addons.supertuxkart.net/";
const DOWNLOAD_LOCATION_ROOT_SERVER = ROOT_LOCATION;

// Old version, http only
const OLD_DOWNLOAD_LOCATION = OLD_DOWNLOAD_LOCATION_ROOT_SERVER . 'dl/';
const OLD_DOWNLOAD_XML_LOCATION = OLD_DOWNLOAD_LOCATION . 'xml/';
const OLD_ASSETS_XML_LOCATION = OLD_DOWNLOAD_XML_LOCATION . 'assets.xml';
const OLD_NEWS_XML_LOCATION = OLD_DOWNLOAD_XML_LOCATION . 'news.xml';

// New version, https only
const DOWNLOAD_LOCATION = DOWNLOAD_LOCATION_ROOT_SERVER . 'dl/';
const DOWNLOAD_XML_LOCATION = DOWNLOAD_LOCATION . 'xml/';
const NEWS_XM_LOCATION = DOWNLOAD_XML_LOCATION . 'news.xml';

const ASSETS_XML_LOCATION = DOWNLOAD_XML_LOCATION . 'assets.xml';
const ASSETS2_XML_LOCATION = DOWNLOAD_XML_LOCATION . 'assets.xml';
const ASSETS_XML_LOCATION = DOWNLOAD_XML_LOCATION . 'online_assets.xml';
const NEWS_XML_LOCATION = DOWNLOAD_XML_LOCATION . 'online_news.xml';

const BUGS_LOCATION = ROOT_LOCATION . 'bugs/';
const STATS_LOCATION = ROOT_LOCATION . 'stats/';
Expand Down Expand Up @@ -210,7 +231,7 @@
require_once(ROOT_PATH . 'vendor' . DS . 'autoload.php');

// add nice error handling https://filp.github.io/whoops/
if (DEBUG_MODE)
if (DEBUG_MODE && !CLI_MODE)
{
$whoops = new \Whoops\Run;
$whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler);
Expand Down
8 changes: 4 additions & 4 deletions phpcs/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnNewLine" />

<!-- BEGIN multiline calls, python style -->
<exclude name="PSR2.Methods.FunctionCallSignature.ContentAfterOpenBracket" />
<exclude name="PSR2.Methods.FunctionCallSignature.Indent" />
<exclude name="PSR2.Methods.FunctionCallSignature.MultipleArguments" />
<exclude name="PSR2.Methods.FunctionCallSignature.CloseBracketLine" />
<!--<exclude name="PSR2.Methods.FunctionCallSignature.ContentAfterOpenBracket" />-->
<!--<exclude name="PSR2.Methods.FunctionCallSignature.Indent" />-->
<!--<exclude name="PSR2.Methods.FunctionCallSignature.MultipleArguments" />-->
<!--<exclude name="PSR2.Methods.FunctionCallSignature.CloseBracketLine" />-->
<!-- END multiline calls -->

<!-- space in control structures -->
Expand Down
92 changes: 73 additions & 19 deletions phpstan/config.example_install_for_phpstan.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@
*/
declare(strict_types=1);

// Make sure that this does not end with a trailing slash, and does not have a prefix in front
const DOMAIN_NAME = 'online.supertuxkart.net';
// useful for phpunit testing
if (!defined('TEST_MODE')) define('TEST_MODE', false);
// useful for cron jobs
if (!defined('CRON_MODE')) define('CRON_MODE', false);
// useful for the API
if (!defined('API_MODE')) define('API_MODE', false);
// useful for to know if downloading file
if (!defined('DOWNLOAD_MODE')) define('DOWNLOAD_MODE', false);

// Check if we are in CLI mode
define('CLI_MODE', php_sapi_name() == "cli");

// WARNING!!!! turn OFF in the production server.
// Enable this when you want detailed debugging output.
Expand All @@ -37,6 +46,21 @@
// Indicate if the certificate is signed by an authority
const IS_SSL_CERTIFICATE_VALID = false;

// Do you prefer https?
const PREFER_SSL = true;


// Redirect access from web browser to secure server
// NOTE: Do not redirect API requests or download requests as Old STK versions can't handle proper certificates
const REDIRECT_TO_HTTPS_SERVER_NAME = false;
const STK_HTTPS_SERVER_NAME = "https://online.supertuxkart.net";
if (!API_MODE && !DOWNLOAD_MODE && REDIRECT_TO_HTTPS_SERVER_NAME)
{
header("Location: " . STK_HTTPS_SERVER_NAME . $_SERVER['REQUEST_URI'], true, 307);
exit;
}


// set default values
ini_set('html_errors', 'On');
if (DEBUG_MODE)
Expand All @@ -51,14 +75,29 @@
ini_set('display_errors', "false");
}

// useful for phpunit testing
if (!defined('TEST_MODE')) define('TEST_MODE', true);
// useful for cron jobs
if (!defined('CRON_MODE')) define('CRON_MODE', false);
// useful for the API
if (!defined('API_MODE')) define('API_MODE', false);
if (empty($_SERVER['SERVER_NAME']) || empty($_SERVER['SERVER_PORT']))
{
// NOTE: We can't access the server name variable in cron mode
// Make sure that this does not end with a trailing slash, and does not have a prefix in front
$DOMAIN_NAME = 'stk-addons.localhost';
}
else
{
$DOMAIN_NAME = $_SERVER['SERVER_NAME'] . (!in_array($_SERVER['SERVER_PORT'], ['80', '443'], true) ? ':' . $_SERVER['SERVER_PORT'] : '');
}


//
// Cron constants
//

// After how many days should we delete the verification emails
const CRON_DAILY_VERIFICATION_DAYS = 1;


//
// Paths on the local filesystem
//
const DS = DIRECTORY_SEPARATOR;
const ROOT_PATH = __DIR__ . DS;
const INCLUDE_PATH = ROOT_PATH . 'include' . DS;
Expand All @@ -72,33 +111,48 @@
const CACHE_PATH = ASSETS_PATH . 'cache' . DS; // cache for images/html/template
const FONTS_PATH = ASSETS_PATH . 'fonts' . DS;

// For old server, http only
const OLD_NEWS_XML_PATH = UP_PATH . 'xml' . DS . 'news.xml';
const NEWS_XML_PATH = UP_PATH . 'xml' . DS . 'online_news.xml';
const OLD_ASSETS_XML_PATH = UP_PATH . 'xml' . DS . 'assets.xml';

// For new online server, https only
const NEWS_XML_PATH = UP_PATH . 'xml' . DS . 'online_news.xml';
const ASSETS_XML_PATH = UP_PATH . 'xml' . DS . 'online_assets.xml';
const ASSETS2_XML_PATH = UP_PATH . 'xml' . DS . 'assets2.xml';

//
// Location urls
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on')
//
define('ROOT_LOCATION_UNSECURE', 'http://' . $DOMAIN_NAME . '/');
if ((PREFER_SSL && IS_SSL_CERTIFICATE_VALID) || (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on'))
{
define('ROOT_LOCATION', 'https://' . DOMAIN_NAME . '/');
define('ROOT_LOCATION', 'https://' . $DOMAIN_NAME . '/');
}
else
{
define('ROOT_LOCATION', 'http://' . DOMAIN_NAME . '/');
define('ROOT_LOCATION', ROOT_LOCATION_UNSECURE);
}

const DOWNLOAD_LOCATION = ROOT_LOCATION . 'dl/';
// Change this if you want downloads to be from another server
const OLD_DOWNLOAD_LOCATION_ROOT_SERVER = "http://addons.supertuxkart.net/";
const DOWNLOAD_LOCATION_ROOT_SERVER = ROOT_LOCATION;

// Old version, http only
const OLD_DOWNLOAD_LOCATION = OLD_DOWNLOAD_LOCATION_ROOT_SERVER . 'dl/';
const OLD_DOWNLOAD_XML_LOCATION = OLD_DOWNLOAD_LOCATION . 'xml/';
const OLD_ASSETS_XML_LOCATION = OLD_DOWNLOAD_XML_LOCATION . 'assets.xml';
const OLD_NEWS_XML_LOCATION = OLD_DOWNLOAD_XML_LOCATION . 'news.xml';

// New version, https only
const DOWNLOAD_LOCATION = DOWNLOAD_LOCATION_ROOT_SERVER . 'dl/';
const DOWNLOAD_XML_LOCATION = DOWNLOAD_LOCATION . 'xml/';
const DOWNLOAD_ASSETS_LOCATION = DOWNLOAD_LOCATION;
const NEWS_XM_LOCATION = DOWNLOAD_XML_LOCATION . 'news.xml';
const ASSETS_XML_LOCATION = DOWNLOAD_XML_LOCATION . 'assets.xml';
const ASSETS2_XML_LOCATION = DOWNLOAD_XML_LOCATION . 'assets.xml';
const ASSETS_XML_LOCATION = DOWNLOAD_XML_LOCATION . 'online_assets.xml';
const NEWS_XML_LOCATION = DOWNLOAD_XML_LOCATION . 'online_news.xml';

const BUGS_LOCATION = ROOT_LOCATION . 'bugs/';
const STATS_LOCATION = ROOT_LOCATION . 'stats/';
const ASSETS_LOCATION = ROOT_LOCATION . 'assets/';
const CACHE_LOCATION = ASSETS_LOCATION . 'cache/';
const LIBS_LOCATION = ASSETS_LOCATION . 'libs/';
const LIBS_LOCATION = ASSETS_LOCATION . 'libs/@bower_components/';
const IMG_LOCATION = ASSETS_LOCATION . 'img/';
const JS_LOCATION = ASSETS_LOCATION . 'js/';
const CSS_LOCATION = ASSETS_LOCATION . 'css/';
Expand Down
2 changes: 2 additions & 0 deletions tools/cli.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

// Prevent against disaster!!!
error_reporting(E_ALL);
ini_set('display_errors', "On");
ini_set('html_errors', "Off");
function exception_error_handler($severity, $message, $file, $line)
{
throw new ErrorException($message, 0, $severity, $file, $line);
Expand Down
Empty file modified tools/convert-db-v2-to-v3.php
100644 → 100755
Empty file.
3 changes: 3 additions & 0 deletions tools/dev-precommit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
composer phpcs
composer phpstan
Loading

0 comments on commit a363381

Please sign in to comment.