Iñigo Valentin 9 роки тому
батько
коміт
50e0f14357
5 змінених файлів з 411 додано та 131 видалено
  1. 104 130
      www/.htaccess
  2. 100 0
      www/error/403.php
  3. 100 0
      www/error/404.php
  4. 100 0
      www/error/500.php
  5. 7 1
      www/functions.php

+ 104 - 130
www/.htaccess

@@ -1,134 +1,106 @@
-#RewriteMap lc int:tolower
-
-#ErrorDocument 403     /error/403.php
-#ErrorDocument 404     /error/404.php
-#ErrorDocument 500     /error/500.php
-
-#AddHandler application/x-httpd-php .xml
-#AddType application/x-httpd-php .xml
-AddType application/x-httpd-php .xml
-AddHandler php5-cgi .xml
-# <FilesMatch "\.php$">
-# Order allow, deny
-# Deny from all
-# </FilesMatch>
-Options +FollowSymlinks
-RewriteEngine on
-CheckSpelling on
-
-# Force https
-RewriteCond %{HTTPS} !=on
-RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
-
-
-#RewriteCond %{HTTP:Accept-Language} ^(en|de|fr)[-,;]? [NC,OR]
-#RewriteCond %{REQUEST_URI} !^(en|es|eu)/[.]+
-#RewriteRule ^$ /en/$1 [NC]
-#RewriteRule ^([a-zA-Z]{2})/(.*)$  $2?lang=$1 [L]
-
-#RewriteCond %{REQUEST_URI} !^(en|es|eu)/[.]+
-#RewriteCond %{HTTP:Accept-Language} ^en [NC]
-#RewriteRule ^$ /en/%{REQUEST_URI} [L,R=301]
-
-#RewriteCond %{HTTP:Accept-Language} ^es [NC]
-#RewriteRule ^$ /de/%{REQUEST_URI} [L,R=301]
-
-#RewriteCond %{HTTP:Accept-Language} ^eu [NC]
-#RewriteRule ^$ /eu/%{REQUEST_URI} [L,R=301]
-
-#RewriteRule ^([a-zA-Z]{2})/(.*)$  $2?lang=$1 [L]
-
-
-#RewriteRule ^([a-zA-Z]{2})/(.*)$  $2?lang=$1 [NC]
-
-#RewriteCond %{REQUEST_URI} ![\/]?(en|es|eu)/[.]* [NC]
-#RewriteCond %{QUERY_STRING} ![.]*lang=[.]*
-#RewriteRule ^ /en%{REQUEST_URI} [R,L]
-#RewriteCond %{HTTP:Accept-Language} ^en [NC]
-#RewriteRule ^ /en%{REQUEST_URI} [R,L]
-#RewriteRule ^ https://inigovalentin.com/en%{REQUEST_URI} [R,L]
-
-RewriteCond %{REQUEST_URI} ![\/]?(en|es|eu)/[.]* [NC]
-RewriteCond %{QUERY_STRING} ![.]*lang=[.]*
-RewriteCond %{HTTP:Accept-Language} ^en [NC]
-RewriteRule ^ /en%{REQUEST_URI} [R,L]
-#RewriteRule ^ https://inigovalentin.com/en%{REQUEST_URI} [R,L]
-
-
-#RewriteCond %{REQUEST_URI} [\/]?(en|es|eu)/[.]* [NC]
-#RewriteCond %{REQUEST_URI} /(en|es|eu)/[.]* [NC]
-#RewriteRule ^[\/]?([a-zA-Z]{2})[\/]?(.*)$ $2?lang=$1 [NC,L]
-RewriteCond %{REQUEST_URI} /(en|es|eu)/[.]* [NC]
-RewriteRule ^[\/]?([a-zA-Z]{2})[\/]?(.*)$  $2?lang=$1 [NC,L]
-
-#RewriteCond %{REQUEST_URI} !/(en|es|eu)/ [NC]
-#RewriteCond %{HTTP:Accept-Language} ^es [NC]
-#RewriteRule ^ https://inigovalentin.com/es%{REQUEST_URI} [R,NC]
-#[R,L]
-
-#RewriteCond %{REQUEST_URI} !/(en|es|eu)/ [NC]
-#RewriteCond %{HTTP:Accept-Language} ^eu [NC]
-#RewriteRule ^ https://inigovalentin.com/eu%{REQUEST_URI} [NC]
-#[R,L]
-
-
-#RewriteRule ^([a-zA-Z]{2})/(.*)$  $2?lang=$1 [NC] 
-#[L]
-
-#RewriteCond %{REQUEST_URI} !/(it|en|admin)/ [NC]
-#RewriteRule ^ http://domain.net/en%{REQUEST_URI} [R,L]
-
-# Permalink rewrites
-
-#RewriteRule ^sitemap.xml$ /sitemap.php [NC]
-#RewriteRule ^imgmap.xml$ /sitemap-image.php [NC]
-#RewriteRule ^rss.xml$ /rss.php [NC]
-
-#RewriteRule ^blog/([A-Z\-a-z0-9]{3,}+)[\/]?$ /blog/post.php?permalink=$1 [NC]
-
-#RewriteRule ^project/([A-Z\-a-z0-9]{3,}+)[\/]?$ /project/project.php?permalink=$1 [NC]
-
-#RewriteRule ^help[\/]?$ /help/index.php [NC]
-
-#RewriteRule ^(yo|me|ni)[\/]?$ /me/index.php [NC]
+Options -MultiViews
+
+
+
+#
+# REWRITE
+#
+# Used to: create nice urls, force https, and hav the site multilanguage.
+#
+<IfModule mod_rewrite.c>
+	RewriteEngine On
+	RewriteBase /
+
+	# Force https
+	RewriteCond %{HTTPS} !=on
+	RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
+
+	# Add final slash.
+	RewriteRule ^([a-zA-Z]{2})$ $1/ [R=301]
+
+	# For files, remove the last /
+	RewriteCond %{REQUEST_URI} ^/([a-zA-Z]{2}/)?(.{3,})/$
+	RewriteCond %{DOCUMENT_ROOT}/%2 !-d
+	RewriteCond %{REQUEST_URI} /$
+	RewriteRule ^(.{3,})/$ $1 [R=301]
+
+	# For sections, add the last /
+	RewriteCond %{REQUEST_URI} ^/([a-zA-Z]{2}/)?(.{3,})$
+	RewriteCond %{DOCUMENT_ROOT}/%2 -d
+	RewriteCond %{REQUEST_URI} !/$
+	RewriteRule ^(.{3,})$ $1/ [R=301]
+
+	# Hide the 'index.php'
+	RewriteRule ^(.*)index\.php?$ $1 [L,R=301]
+
+	# Remove page extensions
+	RewriteCond %{THE_REQUEST} ^GET\ (.*)\.(php|html)([#?][^\ ]*)?\ HTTP
+	RewriteRule ^(.*)\.(php|html)$ $1 [R=301]
+
+	# Language as GET param.
+	RewriteCond %{REQUEST_FILENAME} !-d
+	RewriteCond %{REQUEST_FILENAME} !-f
+	RewriteCond %{REQUEST_URI} ^/([a-zA-Z]{2})(/(.*))?$
+	RewriteRule ^([a-zA-Z]{2})(/(.*))?$ $3?lang=$1 [L,QSA]
+
+	# Add .php extension when needed. TODO: Actualy used?
+	RewriteCond %{REQUEST_FILENAME} !-d
+	RewriteCond %{REQUEST_FILENAME} !-f
+	RewriteCond %{REQUEST_FILENAME}.php -f
+	RewriteRule ^(.*)$ $1\.php [L]
+
+	# Redirect permalinks.
+	RewriteRule ^project/([A-Z\-a-z0-9]{3,}+)[\/]?$ /project/project.php?permalink=$1 [NC]
+	RewriteRule ^blog/([A-Z\-a-z0-9]{3,}+)[\/]?$ /blog/post.php?permalink=$1 [NC]
+	RewriteRule ^help[\/]?$ /help/index.php [NC]
+	RewriteRule ^(perfil|profile|profila)[\/]?$ /profile/index.php [NC]
+
+	# PHP to xml.
+	RewriteRule ^sitemap.xml$ /sitemap.php [NC]
+	RewriteRule ^imgmap.xml$ /sitemap-image.php [NC]
+	RewriteRule ^rss.xml$ /rss.php
+</ifModule>
 
-#RewriteRule !^(en|de|fr)/ /en%{REQUEST_URI} [R=301,L]
-#RewriteCond %{HTTP:Accept-Language} ^(en|de|fr)[-,;]? [NC,OR]
-#RewriteCond en ^(en)$
-#RewriteRule ^$ /%1/ [R=301,L]
-#RewriteRule !^(en|de|fr)/ /en%{REQUEST_URI} [R=301,L]
 
-# BEGIN Cache-Control Headers
+#
+# EXPIRES
+#
+# Used to: control the cache times of the different files on the server.
+#
 <IfModule mod_expires.c>
-	ExpiresActive on
-# ExpiresDefault "access plus 1 month"
-	ExpiresByType application/javascript "access plus 6 days"
-	ExpiresByType image/x-ico "access plus 12 days"
-	ExpiresByType image/jpg "access plus 12 days"
-	ExpiresByType image/jpeg "access plus 12 days"
-	ExpiresByType image/gif "access plus 12 days"
-	ExpiresByType image/png "access plus 12 days"
-	ExpiresByType video/mkv "access plus 12 days"
-	ExpiresByType text/css "access plus 6 days"
-	ExpiresByType text/plain "access plus 6 days"
+        ExpiresActive on
+	ExpiresDefault "access plus 2 days"
+        ExpiresByType application/javascript "access plus 6 days"
+        ExpiresByType image/x-ico "access plus 12 days"
+        ExpiresByType image/jpg "access plus 12 days"
+        ExpiresByType image/jpeg "access plus 12 days"
+        ExpiresByType image/gif "access plus 12 days"
+        ExpiresByType image/png "access plus 12 days"
+        ExpiresByType video/mkv "access plus 12 days"
+        ExpiresByType text/css "access plus 6 days"
+        ExpiresByType text/plain "access plus 6 days"
 </IfModule>
 
-# BEGIN Cache-Control Headers
+
+#
+# HEADERS
+#
+# Used to: control the cache times of the different files on the client.
+#
 <ifModule mod_headers.c>
-  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
-    Header set Cache-Control "max-age=864000, public, must-revalidate"
-  </filesMatch>
-  <filesMatch "\.(css)$">
-    Header set Cache-Control "max-age=864000, public, must-revalidate"
-  </filesMatch>
-  <filesMatch "\.(js)$">
-    Header set Cache-Control "max-age=864000, private, must-revalidate"
-  </filesMatch>
-  <filesMatch "\.(x?html?|php)$">
-    Header set Cache-Control "max-age=86400, private, must-revalidate"
-  </filesMatch>
+	<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
+		Header set Cache-Control "max-age=864000, public, must-revalidate"
+	</filesMatch>
+	<filesMatch "\.(css)$">
+		Header set Cache-Control "max-age=864000, public, must-revalidate"
+	</filesMatch>
+	<filesMatch "\.(js)$">
+		Header set Cache-Control "max-age=864000, private, must-revalidate"
+	</filesMatch>
+	<filesMatch "\.(x?html?|php)$">
+		Header set Cache-Control "max-age=86400, private, must-revalidate"
+	</filesMatch>
 </ifModule>
-# END Cache-Control Headers
 
 <ifModule mod_deflate.c>
 	AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
@@ -140,11 +112,13 @@ RewriteRule ^[\/]?([a-zA-Z]{2})[\/]?(.*)$  $2?lang=$1 [NC,L]
 	AddOutputFilterByType DEFLATE font/truetype font/opentype
 </ifModule>
 
-# Enable memory caching
-#CacheEnable mem /
-
-# Limit the size of the cache to 1 Megabyte
-#MCacheSize 1024
+#
+# ERROR
+#
+# Used to: redirect to nice error pages.
+#
+ErrorDocument 403 /error/403.php
+ErrorDocument 404 /error/404.php
+ErrorDocument 500 /error/500.php
 
-#CacheFile footer.php header.php img/*/*/*.jpg 
 

+ 100 - 0
www/error/403.php

@@ -0,0 +1,100 @@
+<?php
+    session_start();
+    $http_host = $_SERVER["HTTP_HOST"];
+    $doc_root = $_SERVER["DOCUMENT_ROOT"]; 
+    include $doc_root . "functions.php";
+    $proto = get_protocol();
+    $con = start_db();
+    $server = $proto . $http_host;
+    $lang = select_language();
+    $cur_section = "error";
+    $cur_entry = "403";
+?>
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta content='text/html; charset=windows-1252' http-equiv='content-type'/>
+        <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1'>
+        <title>Error - I&ntilde;igo Valentin</title>
+        <link rel='shortcut icon' href='<?=$server?>/img/logo/favicon.ico'>
+        <!-- CSS files -->
+        <link rel='stylesheet' type='text/css' href='/css/ui.css'/>
+        <style>
+            table#error-code{
+                margin-top:        5em;
+                margin-left:     10%;
+            }
+            td#error-number{
+                font-size:        300%;
+                border-right:    0.063em solid #000000;
+                padding-right:    1.875em;
+                padding-left:    1.250em;
+            }
+            td#error-tag{
+                font-size:        110%;
+                padding-left:    1.750em;
+                padding-right:    1.250em;
+            }
+            div#error-message{
+                width:            80%;
+                margin-left:    10%;
+            }
+            @media (max-width: 990px){
+                table#error-code{
+                    width:            90%;
+                    margin-left:    auto;
+                    margin-right:    auto;
+                    margin-top:        0;
+                    margin-bottom:    0;
+                }
+                div#error-message{
+                    width:            90%;
+                    margin-left:    auto;
+                    margin-right:    auto;
+                    margin-top:        0;
+                    margin-bottom:    0;
+                }
+            }
+        </style>
+        <meta name="robots" content="noindex follow"/>
+    </head>
+    <body>
+<?php
+        include $doc_root . "header.php";
+?>
+        <div class='section section_no_title' >
+            <table id='error-code' class='entry'>
+                <tr>
+                    <td id='error-number'>
+                        403
+                    </td>
+                    <td id='error-tag'>
+                        ERROR<br/>CODE
+                    </td>
+                <tr>
+            </table>
+            <br/><br/><br/><br/>
+            <div id='error-message' class='entry'>
+                <h2>Forbidden</h2>
+                This means you are trying to view something you are not allowed to, security wise.
+                <br/><br/>
+                Try a solution:
+                <ul>
+                    <li>
+                        <a href='javascript: location.reload();'>Try again.</a>
+                    </li>
+                    <li>
+                        <a href='javascript: history.go(-1);'>Go to the previous page.</a>
+                    </li>
+                    <li>
+                        <a href='<?=$server?>/'>Go to the main page</a>
+                    </li>
+                </ul>
+            </div> <!-- #error_message -->
+        </div> <!-- .section -->
+<?php
+        include $doc_root . "footer.php";
+        stats($con, $cur_section, $cur_entry);
+?>
+    </body>
+</html>

+ 100 - 0
www/error/404.php

@@ -0,0 +1,100 @@
+<?php
+    session_start();
+    $http_host = $_SERVER["HTTP_HOST"];
+    $doc_root = $_SERVER["DOCUMENT_ROOT"]; 
+    include $doc_root . "functions.php";
+    $proto = get_protocol();
+    $con = start_db();
+    $server = $proto . $http_host;
+    $lang = select_language();
+    $cur_section = "error";
+    $cur_entry = "404";
+?>
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta content='text/html; charset=windows-1252' http-equiv='content-type'/>
+        <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1'>
+        <title>Error - I&ntilde;igo Valentin</title>
+        <link rel='shortcut icon' href='<?=$server?>/img/logo/favicon.ico'>
+        <!-- CSS files -->
+        <link rel='stylesheet' type='text/css' href='/css/ui.css'/>
+        <style>
+            table#error-code{
+                margin-top:        5em;
+                margin-left:     10%;
+            }
+            td#error-number{
+                font-size:        300%;
+                border-right:    0.063em solid #000000;
+                padding-right:    1.875em;
+                padding-left:    1.250em;
+            }
+            td#error-tag{
+                font-size:        110%;
+                padding-left:    1.750em;
+                padding-right:    1.250em;
+            }
+            div#error-message{
+                width:            80%;
+                margin-left:    10%;
+            }
+            @media (max-width: 990px){
+                table#error-code{
+                    width:            90%;
+                    margin-left:    auto;
+                    margin-right:    auto;
+                    margin-top:        0;
+                    margin-bottom:    0;
+                }
+                div#error-message{
+                    width:            90%;
+                    margin-left:    auto;
+                    margin-right:    auto;
+                    margin-top:        0;
+                    margin-bottom:    0;
+                }
+            }
+        </style>
+        <meta name="robots" content="noindex follow"/>
+    </head>
+    <body>
+<?php
+        include $doc_root . "header.php";
+?>
+        <div class='section section_no_title' >
+            <table id='error-code' class='entry'>
+                <tr>
+                    <td id='error-number'>
+                        404
+                    </td>
+                    <td id='error-tag'>
+                        ERROR<br/>CODE
+                    </td>
+                <tr>
+            </table>
+            <br/><br/><br/><br/>
+            <div id='error-message' class='entry'>
+                <h2>Not Found</h2>
+                This means that, either you are looking for something that doesn't exist or that we missed something.
+                <br/><br/>
+                Try a solution:
+                <ul>
+                    <li>
+                        <a href='javascript: location.reload();'>Try again.</a>
+                    </li>
+                    <li>
+                        <a href='javascript: history.go(-1);'>Go to the previous page.</a>
+                    </li>
+                    <li>
+                        <a href='<?=$server?>/'>Go to the main page</a>
+                    </li>
+                </ul>
+            </div> <!-- #error_message -->
+        </div> <!-- .section -->
+<?php
+        include $doc_root . "footer.php";
+        stats($con, $cur_section, $cur_entry);
+?>
+    </body>
+</html>

+ 100 - 0
www/error/500.php

@@ -0,0 +1,100 @@
+<?php
+    session_start();
+    $http_host = $_SERVER["HTTP_HOST"];
+    $doc_root = $_SERVER["DOCUMENT_ROOT"]; 
+    include $doc_root . "functions.php";
+    $proto = get_protocol();
+    $con = start_db();
+    $server = $proto . $http_host;
+    $lang = select_language();
+    $cur_section = "error";
+    $cur_entry = "500";
+?>
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta content='text/html; charset=windows-1252' http-equiv='content-type'/>
+        <meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1'>
+        <title>Error - I&ntilde;igo Valentin</title>
+        <link rel='shortcut icon' href='<?=$server?>/img/logo/favicon.ico'>
+        <!-- CSS files -->
+        <link rel='stylesheet' type='text/css' href='/css/ui.css'/>
+        <style>
+            table#error-code{
+                margin-top:        5em;
+                margin-left:     10%;
+            }
+            td#error-number{
+                font-size:        300%;
+                border-right:    0.063em solid #000000;
+                padding-right:    1.875em;
+                padding-left:    1.250em;
+            }
+            td#error-tag{
+                font-size:        110%;
+                padding-left:    1.750em;
+                padding-right:    1.250em;
+            }
+            div#error-message{
+                width:            80%;
+                margin-left:    10%;
+            }
+            @media (max-width: 990px){
+                table#error-code{
+                    width:            90%;
+                    margin-left:    auto;
+                    margin-right:    auto;
+                    margin-top:        0;
+                    margin-bottom:    0;
+                }
+                div#error-message{
+                    width:            90%;
+                    margin-left:    auto;
+                    margin-right:    auto;
+                    margin-top:        0;
+                    margin-bottom:    0;
+                }
+            }
+        </style>
+        <meta name="robots" content="noindex follow"/>
+    </head>
+    <body>
+<?php
+        include $doc_root . "header.php";
+?>
+        <div class='section section_no_title' >
+            <table id='error-code' class='entry'>
+                <tr>
+                    <td id='error-number'>
+                        500
+                    </td>
+                    <td id='error-tag'>
+                        ERROR<br/>CODE
+                    </td>
+                <tr>
+            </table>
+            <br/><br/><br/><br/>
+            <div id='error-message' class='entry'>
+               <h2>Internal Server Error</h2>
+                We messed up. Something is wrong with the server right now, and hopefully it will be fixed soon.
+                <br/><br/>
+                Try a solution:
+                <ul>
+                    <li>
+                        <a href='javascript: location.reload();'>Try again.</a>
+                    </li>
+                    <li>
+                        <a href='javascript: history.go(-1);'>Go to the previous page.</a>
+                    </li>
+                    <li>
+                        <a href='<?=$server?>/'>Go to the main page</a>
+                    </li>
+                </ul>
+            </div> <!-- #error_message -->
+        </div> <!-- .section -->
+<?php
+        include $doc_root . "footer.php";
+        stats($con, $cur_section, $cur_entry);
+?>
+    </body>
+</html>

+ 7 - 1
www/functions.php

@@ -66,7 +66,13 @@
      *****************************************************/
     // TODO: Redo using database
     function select_language(){
-        //Try to read cookie.
+        // Is passed on the URL?
+        $lang = $_GET["lang"];
+        if ($lang == "es" || $lang == "en" || $lang == "eu"){
+            return $lang;
+        }
+
+        // Try to read cookie.
         header("Cache-control: private");
         if (isSet($_COOKIE["lang"])){
             $lang = $_COOKIE["lang"];