Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sybrew committed Jun 14, 2019
1 parent 9e53776 commit f2bda90
Show file tree
Hide file tree
Showing 6 changed files with 380 additions and 0 deletions.
60 changes: 60 additions & 0 deletions 404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>
<head>
<title>Endpoint not found - tsf.fyi</title>
<meta http-equiv=refresh content="5; url=https://theseoframework.com/" />
<link rel=canonical href=https://theseoframework.com/ />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
html {
background: #000;
}
body {
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
background: #919ea1;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
font-size: 16px;
line-height: 1.625em;
color: #333;
margin: 0;
}
#wrap {
padding: 2em;
background: #fff;
border: 1px solid #465053;
margin: 1em auto;
border-radius: 3px;
box-shadow: 0 0 1em #465053;
}
h1 {
margin-top: 0;
}
p:last-of-type {
margin-bottom: 0;
}
a {
color: inherit;
}
#timer {
font-family: monospace;
width: 3em;
}
</style>
</head>
<body>
<div id=wrap>
<h1>Endpoint not found</h1>
<p>Redirecting to <a href="https://theseoframework.com/">The SEO Framework</a> in <span id=timer>5</span> seconds.</p>
</div>
<script>
let time = 5, t = document.getElementById( 'timer' ), innerHTML = '';
setInterval( () => {
innerHTML = --time > 0 ? time : time < -3 ? '???' : ( '.'.repeat( Math.min( 3, Math.abs( time ) ) ) ) || 0;
if ( t.innerHTML !== innerHTML ) t.innerHTML = innerHTML;
}, 1000 );
</scripT>
</body>
</html>
60 changes: 60 additions & 0 deletions 503.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>
<head>
<title>Could not resolve endpoint - tsf.fyi</title>
<meta http-equiv=refresh content="5; url=https://theseoframework.com/" />
<link rel=canonical href=https://theseoframework.com/ />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
html {
background: #000;
}
body {
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
background: #919ea1;
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
font-size: 16px;
line-height: 1.625em;
color: #333;
margin: 0;
}
#wrap {
padding: 2em;
background: #fff;
border: 1px solid #465053;
margin: 1em auto;
border-radius: 3px;
box-shadow: 0 0 1em #465053;
}
h1 {
margin-top: 0;
}
p:last-of-type {
margin-bottom: 0;
}
a {
color: inherit;
}
#timer {
font-family: monospace;
width: 3em;
}
</style>
</head>
<body>
<div id=wrap>
<h1>Could not resolve endpoint</h1>
<p>Redirecting to <a href="https://theseoframework.com/">The SEO Framework</a> in <span id=timer>5</span> seconds.</p>
</div>
<script>
let time = 5, t = document.getElementById( 'timer' ), innerHTML = '';
setInterval( () => {
innerHTML = --time > 0 ? time : time < -3 ? '???' : ( '.'.repeat( Math.min( 3, Math.abs( time ) ) ) ) || 0;
if ( t.innerHTML !== innerHTML ) t.innerHTML = innerHTML;
}, 1000 );
</scripT>
</body>
</html>
Binary file added favicon.ico
Binary file not shown.
130 changes: 130 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

/**
* TSF.fyi redirection interpreter.
* Copyright (C) 2019 Sybre Waaijer, The SEO Framework (https://theseoframework.com/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as published
* by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

if ( empty( $_SERVER['SCRIPT_URI'] ) ) {
http_response_code( 503 );
exit;
}

header( 'Cache-Control: max-age=3600', true );
header( 'Pragma: public' );

if ( ( $_GET['error'] ?? false ) ) {
header( 'X-Robots-Tag: noindex, follow', true );
http_response_code( 503 );
require __DIR__ . DIRECTORY_SEPARATOR . '503.html';
exit;
}

function retry() {
// Retry after 1s.
$retry = ( $_GET['r'] ?? 0 ) + 1;

if ( $retry > 3 ) {
$location = "{$_SERVER['REQUEST_SCHEME']}://{$_SERVER['HTTP_HOST']}/";
$error = json_last_error() ?: -1;

header( 'X-Redirect-By: tsf.fyi' );
header( 'X-Retry-Request: true' );
header( "Location: $location?error=$error", true, 302 );
exit;
}

usleep( 2.5e5 );
header( 'X-Redirect-By: tsf.fyi' );
header( 'X-Retry-Request: true' );
header( "Location: {$_SERVER['SCRIPT_URI']}?r=$retry", true, 302 );
exit;
}

$json = json_decode(
file_get_contents( __DIR__ . DIRECTORY_SEPARATOR . 'links.json', false, stream_context_create( [ 'http' => [ 'timeout' => 1 ] ] ) )
?: []
) or retry();

$request = preg_replace(
'/[^a-z0-9_\/%\-]/',
'',
strtolower( substr_replace( $_SERVER['REQUEST_URI'], '', 0, strlen( dirname( $_SERVER['PHP_SELF'] ) ) ) )
);

$r = array_values( array_filter( explode( '/', $request ) ) );

/**
*/
function find_endpoint( stdClass $json, array $r ): string {

$default = '';
$depth = 0;

while ( isset( $r[ $depth ] ) ) {

$next = $json->{$r[ $depth ]} ?? null;

if ( null === $next ) {
foreach ( $json as $_endpoint => $_json ) {
if ( isset( $_json->_alt ) && in_array( $r[ $depth ], $_json->_alt, true ) ) {
$next = $json->{$_endpoint};
break;
} elseif ( is_string( $_json ) ) {
if ( false !== strpos( $_endpoint, '$' ) ) {
if ( false !== strpos( $_endpoint, '$$' ) ) {
// Wildcard replacement.
$_items = array_slice( $r, $depth );
$next = str_replace( '$$', implode( '/', $_items ), $_json );
} else {
// Prudent replacement.
$next = str_replace( '$', $r[ $depth ], $_json );
}
}
}
}
}

if ( isset( $next->_deep ) ) {
$default = $next->_default ?? $default;
$json = $next->_deep;
++$depth;
} else {
if ( is_string( $next ) ) {
$endpoint = $next;
} elseif ( $next ) {
$endpoint = $next->_default ?? $default;
}
// Nothing found, always abort to prevent unwanted recursion and DDoS.
break;
}
}

return $endpoint ?? $default;
};

$location = find_endpoint( $json, $r ) ?: '';

if ( ! $location ) :
header( 'X-Robots-Tag: noindex, follow', true );
http_response_code( 200 );
require __DIR__ . DIRECTORY_SEPARATOR . '404.html';
exit;
endif;

http_response_code( 301 );
header( 'X-Redirect-By: tsf.fyi' );
header( "Location: $location", true, 301 );
exit;
129 changes: 129 additions & 0 deletions links.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"contributing": "https://github.com/sybrew/the-seo-framework/blob/master/.github/CONTRIBUTING.md",
"shortlinks": "https://tsf.fyi/links.json",
"kb": {
"_alt": [
"knowledge",
"knowledgebase",
"knowledge-base"
],
"_deep": {
"$$": "https://kb.theseoframework.com/kb/$$/"
},
"_default": "https://kb.theseoframework.com/kb/"
},
"docs": {
"_alt": [
"tuts"
],
"_deep": {
"migrate": "https://theseoframework.com/docs/seo-data-migration/",
"setup": "https://theseoframework.com/docs/seo-plugin-setup/",
"improve": "https://theseoframework.com/docs/improve-your-pages/",
"api": {
"_deep": {
"constants": "https://theseoframework.com/docs/api/constants/",
"filters": "https://theseoframework.com/docs/api/filters/",
"actions": "https://theseoframework.com/docs/api/actions/",
"emconstants": "https://theseoframework.com/docs/api/em/constants/"
},
"_default": "https://theseoframework.com/docs/api/"
}
},
"_default": "https://theseoframework.com/docs/"
},
"github": {
"_alt": [
"gh",
"git"
],
"_deep": {
"tsf": {
"_deep": {
"$$": "https://github.com/sybrew/the-seo-framework/$$"
},
"_default": "https://github.com/sybrew/the-seo-framework"
},
"em": {
"_deep": {
"$$": "https://github.com/sybrew/The-SEO-Framework-Extension-Manager/$$"
},
"_default": "https://github.com/sybrew/The-SEO-Framework-Extension-Manager"
},
"fyi": {
"_deep": {
"$$": "https://github.com/sybrew/tsf-fyi/$$"
},
"_default": "https://github.com/sybrew/tsf-fyi"
}
},
"_default": "https://github.com/sybrew/the-seo-framework"
},
"extensions": {
"_alt": [
"e",
"ext",
"extension"
],
"_deep": {
"$": "https://theseoframework.com/extensions/$/"
},
"_default": "https://theseoframework.com/extensions/"
},
"extension-manager": {
"_alt": [
"em"
],
"_default": "https://theseoframework.com/extension-manager/"
},
"reviews": {
"_alt": [
"r",
"reviews"
],
"_deep": {
"wp": "https://wordpress.org/support/plugin/autodescription/reviews/"
},
"_default": "https://theseoframework.com/what-others-say/"
},
"download": {
"_alt": [
"dl"
],
"_deep": {
"em": {
"_alt": [
"extension-manager"
],
"_default": "https://dl.theseoframework.com/get/plugin/latest/"
},
"tsf": {
"_alt": [
"the-seo-framework"
],
"_default": "https://downloads.wordpress.org/plugin/autodescription.latest-stable.zip"
}
}
},
"account": {
"_alt": [
"my-account"
],
"_deep": {
"eu": "https://eu.theseoframework.com/my-account/"
},
"_default": "https://premium.theseoframework.com/my-account/"
},
"premium": {
"_alt": [
"shop",
"license",
"get-license"
],
"_deep": {
"eu": "https://eu.theseoframework.com/get-license/",
"many": "https://premium.theseoframework.com/get-many-sites-license/"
},
"_default": "https://premium.theseoframework.com/get-license/"
}
}
1 change: 1 addition & 0 deletions robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# You affect the world by what you browse - Tim Berners-Lee

0 comments on commit f2bda90

Please sign in to comment.