From c443c94979bfba5c8011310f578e6e632c98f5b9 Mon Sep 17 00:00:00 2001 From: Peter Molnar Date: Fri, 26 May 2017 15:09:16 +0100 Subject: [PATCH] cleanup and magic.php --- block_footer.html | 4 +-- gallery.html | 19 ---------- localcopy.html | 15 -------- magic.php | 90 ++++++++++++++++++++++++++++++++++++++++++++++ redirect.html | 8 ----- searchresults.html | 28 +++++++++++++-- singular.html | 11 +++++- 7 files changed, 128 insertions(+), 47 deletions(-) delete mode 100644 gallery.html delete mode 100644 localcopy.html create mode 100644 magic.php delete mode 100644 redirect.html diff --git a/block_footer.html b/block_footer.html index 2cf4848..9e183f8 100644 --- a/block_footer.html +++ b/block_footer.html @@ -2,7 +2,7 @@ - \ No newline at end of file + diff --git a/gallery.html b/gallery.html deleted file mode 100644 index b302d11..0000000 --- a/gallery.html +++ /dev/null @@ -1,19 +0,0 @@ -{% include 'block_header_open.html' %} - -{%- if taxonomy.name -%} -{%- set title = taxonomy.name ~ ' | ' ~ site.name -%} -{%- else -%} -{%- set title = site.name -%} -{%- endif -%} - {{ title }} - -{% include 'block_header_close.html' %} - -
-
- -{% include 'block_footer.html' %} diff --git a/localcopy.html b/localcopy.html deleted file mode 100644 index 0abb0f0..0000000 --- a/localcopy.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - {{ post.title }} - - - - - - -{{ post.html }} - - \ No newline at end of file diff --git a/magic.php b/magic.php new file mode 100644 index 0000000..71c9aec --- /dev/null +++ b/magic.php @@ -0,0 +1,90 @@ + + + + + + Gone + + +

This content was deleted.

+ +'); +} + +function notfound() { + header('HTTP/1.0 404 Not Found'); + die(' + + + + + Not found + + + +

This was not found.

+

Please search for it instead.

+

+

+

+ +'); +} + +function maybe_redirect($uri) { + if (file_exists("./{$uri}/index.html")) { + redirect_to($uri); + } +} + +$redirects = array( +{% for (from, to) in redirects %} + "{{ from }}" => "{{ to }}", +{%- endfor -%} +); + +$gone = array( +{% for gone in gones %} + "{{ gone }}" => true, +{%- endfor -%} +); + +$uri = filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL); +$uri = str_replace('../', '', $uri); +$uri = str_replace('/feed/', '', $uri); +$uri = str_replace('/atom/', '', $uri); +$uri = trim($uri, '/'); + +if (isset($gone[$uri])) + gone($uri); +elseif (isset($redirects[$uri])) + redirect_to($redirects[$uri]); +// replace _ with - and look for a file +elseif (strstr($uri, '_')) + maybe_redirect(str_replace('_', '-', $uri)); +// try getting rid of -by-xyz +elseif (stristr($uri,'-by-')) + maybe_redirect(preg_replace('/(.*?)-by-.*$/i','${1}',$uri)); +// try getting rid of -2, WordPress artifacts +elseif (stristr($uri,'-2')) + maybe_redirect(preg_replace('/(.*?)-2$/i','${1}',$uri)); +else + notfound(); diff --git a/redirect.html b/redirect.html deleted file mode 100644 index 6e0a85e..0000000 --- a/redirect.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/searchresults.html b/searchresults.html index d3c1c44..29a3514 100644 --- a/searchresults.html +++ b/searchresults.html @@ -1,12 +1,36 @@ - + + Search results for "{{ term }}" + +
+ + + + +
+
+

Search results for "{{ term }}"

{% if posts|length %} @@ -28,7 +52,7 @@
… {{ post.highlight }} …
- {% if post.img %} + {% if post.img and 'None' != post.img %}

{{ post.img }}

{% endif %} diff --git a/singular.html b/singular.html index 8efe0a6..b13f9e6 100644 --- a/singular.html +++ b/singular.html @@ -129,6 +129,15 @@

+ {% if post.offlinecopies %} + {% for url, copy in post.offlinecopies %} + + {% endfor %} + {% endif %}
-{% include 'block_footer.html' %} \ No newline at end of file +{% include 'block_footer.html' %}