Skip to content

Commit

Permalink
Support configurable URLs in the website (smogon#1575)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnikaCodes authored Jul 28, 2020
1 parent 55b5779 commit 7361473
Show file tree
Hide file tree
Showing 15 changed files with 44 additions and 33 deletions.
2 changes: 1 addition & 1 deletion customcss.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

ini_set('max_execution_time', 60); // 1 minute

require_once __DIR__ . '/config/servers.inc.php';
require_once __DIR__ . '/config/config.inc.php';
require_once __DIR__ . '/config/servers.inc.php';

spl_autoload_register(function ($class) {
require_once('lib/css-sanitizer/'.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php');
Expand Down
2 changes: 1 addition & 1 deletion lib/ntbb-session.lib.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

require_once __DIR__ . '/ntbb-database.lib.php';
require_once __DIR__ . '/../config/config.inc.php';
require_once __DIR__ . '/ntbb-database.lib.php';
// require_once dirname(__FILE__) . '/password_compat/lib/password.php';

$curuser = false;
Expand Down
2 changes: 1 addition & 1 deletion replays/battle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

require_once __DIR__ . '/theme/panels.lib.php';
require_once __DIR__ . '/../config/config.inc.php';
require_once __DIR__ . '/theme/panels.lib.php';

$id = $_REQUEST['name'] ?? '';
$password = '';
Expand Down
15 changes: 8 additions & 7 deletions website/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// error_reporting(0);

include_once __DIR__ . '/../config/config.inc.php';
include 'style/wrapper.inc.php';

function servercmp($a, $b) {
Expand Down Expand Up @@ -53,7 +54,7 @@ function servercmp($a, $b) {
foreach ($PokemonServers as &$server) {
$server['sortorder'] = $sortorder++;
if ($server['id'] === 'showdown') {
$server['uri'] = $externProtocol . '//play.pokemonshowdown.com';
$server['uri'] = $externProtocol . '//' . $psconfig['routes']['client'];
} else {
$server['uri'] = 'http://' . $server['id'] . '.psim.us';
}
Expand Down Expand Up @@ -130,16 +131,16 @@ function servercmp($a, $b) {
</p>
<p class="mainbutton" id="play-online">
<?php if (isset($_REQUEST['insecure'])) { ?>
<a class="button greenbutton" href="http://play.pokemonshowdown.com/?insecure">Play (insecure mode)</a>
<a class="button greenbutton" href="http://<?= $psconfig['routes']['client'] ?>/?insecure">Play (insecure mode)</a>
<?php } else { ?>
<a class="button greenbutton" href="<?= $externProtocol ?>//play.pokemonshowdown.com/">Play online</a>
<a class="button greenbutton" href="<?= $externProtocol ?>//<?= $psconfig['routes']['client'] ?>/">Play online</a>
<?php } ?>
</p>
<p class="mainbutton" id="win-install" style="display:none;text-align:center;color:#777;margin:-10px 0 -0px 0">
or<br /><a href="https://pokemonshowdown.com/autodownload/win">Install <small>(Windows)</small></a>
or<br /><a href="https://<?= $psconfig['routes']['root'] ?>/autodownload/win">Install <small>(Windows)</small></a>
</p>
<p class="mainbutton" id="mac-install" style="display:none;text-align:center;color:#777;margin:-10px 0 -0px 0">
or<br /><a href="https://pokemonshowdown.com/autodownload/mac">Install <small>(OS X)</small></a>
or<br /><a href="https://<?= $psconfig['routes']['root'] ?>/autodownload/mac">Install <small>(OS X)</small></a>
</p>
<!--p class="mainbutton" id="chrome-install" style="display:none">
<a class="button greenbutton" href="http://play.pokemonshowdown.com/showdown.crx">Install Chrome app</a>
Expand Down Expand Up @@ -312,7 +313,7 @@ function servercmp($a, $b) {
<a href="http://www.smogon.com/stats/" target="_blank"><i class="fa fa-sort-amount-desc"></i> Usage stats</a>
</li>
<li>
<a href="https://github.com/Zarel/Pokemon-Showdown" target="_blank"><i class="fa fa-github"></i> GitHub repository</a>
<a href="https://github.com/smogon/Pokemon-Showdown" target="_blank"><i class="fa fa-github"></i> GitHub repository</a>
</li>
</ul>
<p style="text-align: center; clear: both">
Expand Down Expand Up @@ -340,7 +341,7 @@ function servercmp($a, $b) {
</p></blockquote>
<h2>Open-source</h2>
<p>
Pok&eacute;mon Showdown is actively developed in the <a href="https://github.com/Zarel/Pokemon-Showdown">Pok&eacute;mon Showdown GitHub repository</a>. Come lend a hand!
Pok&eacute;mon Showdown is actively developed in the <a href="https://github.com/smogon/Pokemon-Showdown">Pok&eacute;mon Showdown GitHub repository</a>. Come lend a hand!
</p-->

<?php
Expand Down
4 changes: 3 additions & 1 deletion website/interstice.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

include_once __DIR__ . '/../config/config.inc.php';

header('X-Robots-Tag: noindex');

if (!isset($_REQUEST['uri'])) {
Expand Down Expand Up @@ -29,7 +31,7 @@
<div class="ps-ad" style="margin: 0 auto;max-width: 728px;">
<!-- BEGIN JS TAG - [728x90] < - DO NOT MODIFY -->
<script type="text/javascript">
document.write('<SCR'+'IPT SRC="http://ads.sonobi.com/ttj?id=1871931&referrer=pokemonshowdown.com&cb='+(parseInt(Math.random()*100000))+'" TYPE="text/javascript"></SCR'+'IPT>');
document.write('<SCR'+'IPT SRC="http://ads.sonobi.com/ttj?id=1871931&referrer=<?= $psconfig['routes']['root'] ?>&cb='+(parseInt(Math.random()*100000))+'" TYPE="text/javascript"></SCR'+'IPT>');
</script>
<!-- END TAG -->
</div>
Expand Down
9 changes: 5 additions & 4 deletions website/intro.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

include_once __DIR__ . '/../config/config.inc.php';
include 'style/wrapper.inc.php';

$page = 'intro';
Expand Down Expand Up @@ -46,8 +47,8 @@
All attacking moves are either Physical or Special moves. Physical moves use your attacker's Attack stat against your target's Defense stat, while Special moves use your attacker's Special Attack stat against the target's Special Defense stat.
</p>
<blockquote><p>
<img src="//play.pokemonshowdown.com/sprites/categories/Physical.png" alt="[Physical]" /> Physical<br />
<img src="//play.pokemonshowdown.com/sprites/categories/Special.png" alt="[Special]" /> Special<br />
<img src="//<?= $psconfig['routes']['client'] ?>/sprites/categories/Physical.png" alt="[Physical]" /> Physical<br />
<img src="//<?= $psconfig['routes']['client'] ?>/sprites/categories/Special.png" alt="[Special]" /> Special<br />
</p></blockquote>
<p>
In game and online, these icons will remind you of whether a move is Physical or Special. Remember that a Pokémon with high Attack and low Special Attack should usually be using only Physical moves, and vice versa.
Expand Down Expand Up @@ -144,7 +145,7 @@
</p>
<h3>Set-up and phazing</h3>
<p>
Because you're giving up an entire turn that could have been used attacking, most moves that do nothing but raise or lower stats are useless. The exception is boosting moves that can help set up a Pokémon to sweep.
Because you're giving up an entire turn that could have been used attacking, most moves that do nothing but raise or lower stats are useless. The exception is boosting moves that can help set up a Pokémon to sweep.
</p>
<p>
A sweep is the act of a Pokémon knocking out multiple opposing Pokémon in a row. Certain moves, such as Swords Dance, Dragon Dance, Shell Smash, and Calm Mind raise your Pokémon's attacking stats and Speed to the point where it could defeat all your opponent's remaining Pokémon that threaten it in one hit.
Expand Down Expand Up @@ -172,7 +173,7 @@
Well, now you have a basic idea of how competitive battling works. If you'd like to dive straight in, play Pokémon Showdown! Our Random Battle format is great for learning the basics of competitive play.
</p>
<p class="mainbutton">
<a class="button greenbutton" href="//play.pokemonshowdown.com/">Play online</a>
<a class="button greenbutton" href="//<?= $psconfig['routes']['client'] ?>/">Play online</a>
</p>
<p>
If you'd like more help, Smogon University offers a <a href="http://www.smogon.com/forums/forumdisplay.php?f=42" target="_blank">Battling 101 program</a>, where you will be paired with a tutor.
Expand Down
3 changes: 2 additions & 1 deletion website/news/embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// in theory this file is no longer used

include_once __DIR__ . '/../../config/config.inc.php';
include __DIR__ . '/../../config/news.inc.php';

function readableDate($time=0) {
Expand Down Expand Up @@ -67,7 +68,7 @@ function readableDate($time=0) {
<h1><?php echo htmlspecialchars($topic['title']); ?></h1>
<?php echo @$topic['summary_html'] ?>
<p>
&mdash;<strong><?php echo $topic['authorname']; ?></strong> <small class="date">on <?php echo readableDate($topic['date']); ?></small> <small><a href="http://pokemonshowdown.com/forums/viewtopic.php?f=3&amp;t=<?= $topic['topic_id'] ?>" target="_blank" onclick="return window.parent.app.clickLink(event)">Read more / comments</a></small>
&mdash;<strong><?php echo $topic['authorname']; ?></strong> <small class="date">on <?php echo readableDate($topic['date']); ?></small> <small><a href="http://<?= $psconfig['routes']['root'] ?>/forums/viewtopic.php?f=3&amp;t=<?= $topic['topic_id'] ?>" target="_blank" onclick="return window.parent.app.clickLink(event)">Read more / comments</a></small>
</p>
<?php
break;
Expand Down
2 changes: 1 addition & 1 deletion website/pages/rng.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ How PS's RNG works

Pokémon Showdown uses the exact same RNG as the actual Pokémon games on the 3DS use. You can see the source code right here:

https://github.com/Zarel/Pokemon-Showdown/blob/master/sim/prng.ts
https://github.com/smogon/Pokemon-Showdown/blob/master/sim/prng.ts

And there are many pages documenting this is the same random number generator used on the 3DS:

Expand Down
3 changes: 2 additions & 1 deletion website/resetpassword.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

include_once __DIR__ . '/../config/config.inc.php';
include 'style/wrapper.inc.php';
include '../lib/ntbb-session.lib.php';

Expand Down Expand Up @@ -58,7 +59,7 @@
The password for <?php echo htmlspecialchars($user['username']); ?> was <strong>successfully changed</strong>!.
</p>
<p class="mainbutton">
<a class="button greenbutton" href="http://play.pokemonshowdown.com/">Play online</a>
<a class="button greenbutton" href="http://<?= $psconfig['routes']['client'] ?>/">Play online</a>
</p>
<?php
} else {
Expand Down
7 changes: 4 additions & 3 deletions website/servers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

include_once __DIR__ . '/../config/config.inc.php';
include_once __DIR__ . '/../config/servers.inc.php';
include_once '../lib/ntbb-session.lib.php';
include 'style/wrapper.inc.php';
Expand Down Expand Up @@ -182,15 +183,15 @@ function saveservers() {
<?php } ?>
<p>
<?php if ($entry['id'] === 'showdown') { ?>
<small><a href="//play.pokemonshowdown.com" target="_blank"><code>play.pokemonshowdown.com</code></a></small>
<small><a href="//<?= $psconfig['routes']['client'] ?>" target="_blank"><code><?= $psconfig['routes']['client'] ?></code></a></small>
<?php } else { ?>
<small><a href="http://<?= $entry['id'] ?>.psim.us" target="_blank"><code><?= $entry['id'] ?>.psim.us</code></a></small>
<?php } ?>
</p>
<?php if (@$entry['owner']) { ?><p>Owner: <?= htmlspecialchars($entry['owner']); ?></p><?php } ?>
<?php if ($entry['id'] !== 'showdown' && $is_owner) { ?>
<p id="editserverbutton">
<button onclick="document.getElementById('editserver').style.display = 'block';document.getElementById('editserverbutton').style.display = 'none';return false">Edit server</button> <button onclick="document.location.href = ('http://play.pokemonshowdown.com/customcss.php?server=<?= $entry['id'] ?>&amp;invalidate')">Reload custom CSS</button>
<button onclick="document.getElementById('editserver').style.display = 'block';document.getElementById('editserverbutton').style.display = 'none';return false">Edit server</button> <button onclick="document.location.href = ('http://<?= $psconfig['routes']['client'] ?>/customcss.php?server=<?= $entry['id'] ?>&amp;invalidate')">Reload custom CSS</button>
</p>
<div id="editserver" style="display:none"><form method="post"><?php $users->csrfData(); ?>
<h1>Edit server</h1>
Expand Down Expand Up @@ -362,7 +363,7 @@ function cmpByUsercount($b, $a) {
</td>
<td>
<?php if ($entry['id'] === 'showdown') { ?>
<small><a href="//play.pokemonshowdown.com" target="_blank"><code>play.pokemonshowdown.com</code></a></small>
<small><a href="//<?= $psconfig['routes']['client'] ?>" target="_blank"><code><?= $psconfig['routes']['client'] ?></code></a></small>
<?php } else { ?>
<small><a href="http://<?= $entry['id'] ?>.psim.us" target="_blank"><code><?= $entry['id'] ?>.psim.us</code></a></small>
<?php } ?>
Expand Down
8 changes: 5 additions & 3 deletions website/style/wrapper.inc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

include_once __DIR__ . '/../config/config.inc.php';

function curPage($thisPage) {
global $page;
if ($page === $thisPage) echo ' cur';
Expand Down Expand Up @@ -46,13 +48,13 @@ function includeHeaderBottom() {
<div class="header"><div class="header-inner">
<ul class="nav">
<li><a class="button nav-first<?php curPage('home') ?>" href="/"><img src="/images/pokemonshowdownbeta.png" alt="Pok&eacute;mon Showdown! (beta)" /> Home</a></li>
<li><a class="button" href="//dex.pokemonshowdown.com/">Pok&eacute;dex</a></li>
<li><a class="button" href="//replay.pokemonshowdown.com/">Replays</a></li>
<li><a class="button" href="//<?= $psconfig['routes']['dex'] ?>/">Pok&eacute;dex</a></li>
<li><a class="button" href="//<?= $psconfig['routes']['replays'] ?>/">Replays</a></li>
<li><a class="button<?php curPage('ladder') ?>" href="/ladder/">Ladder</a></li>
<li><a class="button nav-last" href="/forums/">Forum</a></li>
</ul>
<ul class="nav nav-play">
<li><a class="button greenbutton nav-first nav-last" href="//play.pokemonshowdown.com/">Play</a></li>
<li><a class="button greenbutton nav-first nav-last" href="//<?= $psconfig['routes']['client'] ?>/">Play</a></li>
</ul>
<div style="clear:both"></div>
</div></div>
Expand Down
10 changes: 6 additions & 4 deletions website/theme/wrapper.inc.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

include_once __DIR__ . '/../config/config.inc.php';

/********************************************************************
* Header
********************************************************************/
Expand All @@ -19,7 +21,7 @@ function ThemeHeaderTemplate() {
<?php } ?>

<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=IE8" />
<link rel="stylesheet" href="//play.pokemonshowdown.com/style/font-awesome.css" />
<link rel="stylesheet" href="//<?= $psconfig['routes']['client']; ?>/style/font-awesome.css" />
<link rel="stylesheet" href="/theme/panels.css?" />
<link rel="stylesheet" href="/theme/main.css?" />

Expand Down Expand Up @@ -48,13 +50,13 @@ function ThemeHeaderTemplate() {
<div class="header">
<ul class="nav">
<li><a class="button nav-first<?php if ($panels->tab === 'home') echo ' cur'; ?>" href="/"><img src="/images/pokemonshowdownbeta.png" alt="Pok&eacute;mon Showdown! (beta)" /> Home</a></li>
<li><a class="button" href="//dex.pokemonshowdown.com/">Pok&eacute;dex</a></li>
<li><a class="button" href="//replay.pokemonshowdown.com/">Replays</a></li>
<li><a class="button" href="//<?= $psconfig['routes']['dex'] ?>/">Pok&eacute;dex</a></li>
<li><a class="button" href="//<?= $psconfig['routes']['replays'] ?>/">Replays</a></li>
<li><a class="button<?php if ($panels->tab === 'ladder') echo ' cur'; ?>" href="/ladder/">Ladder</a></li>
<li><a class="button nav-last" href="/forums/">Forum</a></li>
</ul>
<ul class="nav nav-play">
<li><a class="button greenbutton nav-first nav-last" href="//play.pokemonshowdown.com/">Play</a></li>
<li><a class="button greenbutton nav-first nav-last" href="//<?= $psconfig['routes']['client'] ?>/">Play</a></li>
</ul>
<div style="clear:both"></div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion website/usermodlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

include_once __DIR__ . '/../config/config.inc.php';
include '../lib/ntbb-session.lib.php';
include '../lib/ntbb-ladder.lib.php';
include 'lib/panels.lib.php';
Expand All @@ -30,7 +31,7 @@

if (substr($_SERVER['REQUEST_URI'], 0, 13) === '/users/?user=') {
// really wish this could be done with mod_rewrite
header('Location: http://pokemonshowdown.com/users/'.$userid);
header('Location: http://' . $psconfig['routes']['users'] . '/' .$userid);
die();
}

Expand Down
4 changes: 2 additions & 2 deletions website/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

if (substr($_SERVER['REQUEST_URI'], 0, 13) === '/users/?user=') {
// really wish this could be done with mod_rewrite
header('Location: https://pokemonshowdown.com/users/'.$userid);
header('Location: https://' . $psconfig['routes']['users'] . '/'.$userid);
die();
}

Expand Down Expand Up @@ -266,7 +266,7 @@
Use this link:
</p>
<p style="margin: 1em -13px">
<small><code>https://pokemonshowdown.com/resetpassword/<?php echo $token; ?></code></small>
<small><code>https://<?= $psconfig['routes']['root'] ?>/resetpassword/<?php echo $token; ?></code></small>
</p>
</div>
<?php
Expand Down
3 changes: 1 addition & 2 deletions website/usersearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

include_once __DIR__ . '/../config/config.inc.php';
include '../lib/ntbb-session.lib.php';
include '../lib/ntbb-ladder.lib.php';
include 'lib/panels.lib.php';

include_once __DIR__ . '/../config/config.inc.php';

$userid = false;
$user = false;

Expand Down

0 comments on commit 7361473

Please sign in to comment.