commit f6bad2d2d91bf56aa480324ba531b20b91b5490f Author: Erik Thuning <boooink@gmail.com> Date: Wed Jul 4 11:27:24 2018 +0200 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..02cd992 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +.htaccess +config.php diff --git a/config.php.example b/config.php.example new file mode 100644 index 0000000..de56d6d --- /dev/null +++ b/config.php.example @@ -0,0 +1,8 @@ +<?php + +$db_host = 'dbserver'; +$db_user = 'dbname'; +$db_pass = 'dbpassword'; +$db_name = 'dbuser'; + +?> diff --git a/html/base.html b/html/base.html new file mode 100644 index 0000000..14bdf96 --- /dev/null +++ b/html/base.html @@ -0,0 +1,58 @@ +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta name="viewport" content="width=device-width, initial-scale=1" /> + <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon"> + <link rel="stylesheet" type="text/css" href="./template.css" /> + <link rel="stylesheet" type="text/css" href="./style.css" /> + <script type="text/javascript" src="./script.js"></script> + <title>¤pagetitle¤</title> + </head> + <body> + <div id="container"> + <a class="accessibility-link" accesskey="s" href="#content-top" title="¤template-access-skip-nav¤"></a> + <div id="top-links"> + <a href="¤template-lang-link¤"><img src="¤template-lang-flag¤" /> ¤template-lang-label¤</a> + </div> + <div id="header"> + <a id="header-su-responsive" href="¤template-su-link¤" title="¤template-su-link-title¤"> + <img src="¤template-su-logo-responsive¤" alt="¤template-su-name¤" /> + </a> + + <a id="header-dsv" href="¤template-dsv-link¤" title="¤template-dsv-link-title¤" accesskey="1"> + <img src="¤template-dsv-logo¤" alt="¤template-dsv-name¤"> + </a> + + <a id="header-su" href="¤template-su-link¤" title="¤template-su-link-title¤"> + <img src="¤template-su-logo¤" alt="¤template-su-name¤"> + </a> + <div class="clear"> + </div> + </div> + + <div id="contents"> + <a class="accessibility-link" name="content-top"></a> + ¤contents¤ + <div class="clear"> + </div> + </div> + + <div id="footer"> + <div id="footer-name"> + <div id="footer-dsv"> + ¤template-dsv-name¤ + </div> + <div id="footer-su"> + ¤template-su-name¤ + </div> + </div> + <div id="footer-contact"> + <a id="footer-contact-link" href="¤template-contact-link¤" accesskey="7">¤template-contact-label¤</a> + </div> + <div class="clear"> + </div> + </div> + </div> + </body> +</html> diff --git a/images/button-background-repeater.gif b/images/button-background-repeater.gif new file mode 100644 index 0000000..d5de909 Binary files /dev/null and b/images/button-background-repeater.gif differ diff --git a/images/container-repeater.gif b/images/container-repeater.gif new file mode 100644 index 0000000..c6a6209 Binary files /dev/null and b/images/container-repeater.gif differ diff --git a/images/dsv_logo_en.png b/images/dsv_logo_en.png new file mode 100644 index 0000000..413f876 Binary files /dev/null and b/images/dsv_logo_en.png differ diff --git a/images/dsv_logo_sv.png b/images/dsv_logo_sv.png new file mode 100644 index 0000000..1d85d71 Binary files /dev/null and b/images/dsv_logo_sv.png differ diff --git a/images/favicon.ico b/images/favicon.ico new file mode 100644 index 0000000..3b1d850 Binary files /dev/null and b/images/favicon.ico differ diff --git a/images/globallinks-lang-en.gif b/images/globallinks-lang-en.gif new file mode 100644 index 0000000..5b43eda Binary files /dev/null and b/images/globallinks-lang-en.gif differ diff --git a/images/globallinks-lang-sv.gif b/images/globallinks-lang-sv.gif new file mode 100644 index 0000000..f27e6fb Binary files /dev/null and b/images/globallinks-lang-sv.gif differ diff --git a/images/su_logo_en.gif b/images/su_logo_en.gif new file mode 100644 index 0000000..255c7af Binary files /dev/null and b/images/su_logo_en.gif differ diff --git a/images/su_logo_responsive_en.png b/images/su_logo_responsive_en.png new file mode 100644 index 0000000..08df4a2 Binary files /dev/null and b/images/su_logo_responsive_en.png differ diff --git a/images/su_logo_responsive_sv.png b/images/su_logo_responsive_sv.png new file mode 100644 index 0000000..4fbdbc2 Binary files /dev/null and b/images/su_logo_responsive_sv.png differ diff --git a/images/su_logo_sv.gif b/images/su_logo_sv.gif new file mode 100644 index 0000000..08e12b5 Binary files /dev/null and b/images/su_logo_sv.gif differ diff --git a/include.php b/include.php new file mode 100644 index 0000000..6698041 --- /dev/null +++ b/include.php @@ -0,0 +1,102 @@ +<?php + +require_once("./config.php"); +require_once("./template_translations.php"); +require_once("./translations.php"); + +$db = new mysqli($db_host, $db_user, $db_pass, $db_name); +if($db->connect_errno) { + throw new Exception('Failed to connect to db. The error was: '.$db->connect_error); +} + + +function format_page($lang, $content, $title) { + global $template_translations, $translations; + + $content = replace($translations[$lang], $content); + $out = replace( + $template_translations[$lang], + file_get_contents('./html/base.html') + ); + $out = replace(array( + '¤pagetitle¤' => $title, + '¤contents¤' => $content, + ), $out); + + return $out; +} + +/* + Takes an html file containing named fragments. + Returns an associative array on the format array[name]=>fragment. + + Fragments are delimited like this: + + ¤¤ name 1 ¤¤ + fragment 1 + ¤¤ name 2 ¤¤ + fragment 2 + ¤¤ name 3 ¤¤ + fragment 3 + + The first delimiter and name ('¤¤ name 1 ¤¤' in the above example) can + be omitted, in which case the first fragment will be assigned the + name 'base'. All other fragments must be named. + + Throws an exception if: + - any fragment except the first is missing a name + - two (or more) fragments share a name + */ +function get_fragments($infile) { + $out = array(); + $name = ''; + $current_fragment = null; + + foreach(file($infile) as $line) { + if(strpos($line, '¤¤') === 0) { + if($current_fragment !== null) { + $out = try_adding($name, $current_fragment, $out, $infile); + + } + $name = trim($line, "\t\n\r ¤"); + $current_fragment = null; + } else { + $current_fragment .= $line; + } + } + + return try_adding($name, $current_fragment, $out, $infile); +} + +function try_adding($key, $value, $array, $filename) { + if(array_key_exists($key, $array)) { + throw new Exception('There is already a fragment with that name in '.$filename); + } else if($key === '') { + throw new Exception('There is an unnamed fragment in '.$filename); + } + + $array[$key] = $value; + + return $array; +} + +/* + Takes an associative array and a string. + Returns a string. + + Replaces each occurrence of each array key in the input string + with the associated array value, and returns the result. + */ +function replace($assoc_arr, $subject) { + $keys = array(); + $values = array(); + + foreach($assoc_arr as $key => $value) { + $keys[] = $key; + $values[] = $value; + } + + return str_replace($keys, $values, $subject); +} + +?> diff --git a/index.php b/index.php new file mode 100755 index 0000000..dea8ceb --- /dev/null +++ b/index.php @@ -0,0 +1,12 @@ +<?php +require_once('./include.php'); // provides $db, $translations + +header('Content-Type: text/html; charset=UTF-8'); + +$lang = 'sv'; +if(isset($_GET['lang'])) { + $lang = $_GET['lang']; +} + +print format_page($lang, 'TEST', 'TESTING TITLE'); +?> diff --git a/template.css b/template.css new file mode 100644 index 0000000..3d6285b --- /dev/null +++ b/template.css @@ -0,0 +1,313 @@ +/* + * Base styles + * ----------- + */ + +@charset "utf-8"; + +* { + box-sizing: border-box; +} + +body { + margin: 0; + padding: 0; + min-height: 100%; + font: 76%/1.6 Verdana, Arial, Helvetica, sans-serif; +} + +h1, h2, h3, h4 { + font-family: Verdana, Arial, Helvetica, sans-serif; + color: #002f5f; + text-decoration-color: #002f5f; + font-weight: normal; + letter-spacing: -1px; +} + +h1 { + margin-top: 23px; + margin-bottom: 11px; + font-size: 230%; +} + +h2 { + margin-top: 15px; + margin-bottom: 7px; + font-size: 150%; +} + +h3 { + margin-top: 14px; + margin-bottom: 7px; + font-size: 140% +} + +h4 { + margin-top: 10px; + margin-bottom: 6px; + font-size: 100%; +} + +p { + margin-top: 6px; + margin-bottom: 6px; +} + +a:link { + color: #005b7f; +} + +a:visited { + color: #7d7d7d; +} + +a:hover { + color: #000; +} + +input, textarea, button, select { + border: 1px solid lightgray; + margin: 1px; + font-family: inherit; + font-size: 100%; + background-color: white; + color: black; +} + +input, button, select { + vertical-align: middle; +} + +textarea { + vertical-align: top; +} + +input:not([type="submit"]):focus, textarea:focus, select:focus { + border: 1px solid black; +} + +button, input[type="submit"] { + font-family: Verdana, Arial, Helvetica, sans-serif; + background-image: url(images/button-background-repeater.gif); + background-position: left; + background-repeat: repeat-x; + color: white; +} + +/* + * Utility classes + * --------------- + */ + +.box { + display: inline-block; + border: 1px solid #d7e0eb; + padding: 10px; + margin: 6px; +} + +.left { + float: none; +} + +.right { + float: none; +} + +.clear { + clear: both; +} + +.lclear { + clear: left; +} + +.rclear { + clear: right; +} + +.fade { + font-size: 90%; + color: #666666; +} + +/* + * Theme element styles + * -------------------- + */ + +#container { + margin-left: auto; + margin-right: auto; + max-width: 994px; + min-height: 100vh; + padding-bottom: 20px; + position: relative; +} + +#top-links, #header { + background-color: #002e5f; + color: white; +} + +#top-links { + padding-left: 4%; + padding-right: 4%; + text-align: right; +} + +#top-links a { + color: white; + font-size: 80%; + text-decoration: none; +} + +#top-links a:hover { + text-decoration: underline; +} + +#top-links img { + vertical-align: middle; +} + +#header { + padding-left: 4%; +} + +#header-su-responsive { + float: left; + margin-top: 16px; +} + +#header-su-responsive > img { + width: 100%; + max-width: 500px; +} + +#header-dsv { + float: left; +} + +#header-dsv > img { + width: 100%; + max-wifth: 399px; +} + +#header-su { + float: right; + margin-top: 16px; + margin-right: 20px; +} + +#contents { + font-family: Georgia, "Times New Roman", Times, serif; + margin-left: auto; + margin-right: auto; + margin-bottom: 100px; + margin-top: 12px; + padding-left: 4%; + padding-right: 4%; +} + +#footer { + border-top: 1px solid #d2d7dc; + font-size: 80%; + padding-top: 11px; + padding-bottom: 22px; + width: 100%; + position: absolute; + bottom: 0; +} + +#footer-name { + float: left; + padding-left: 11px; +} + +#footer-dsv { + font-weight: bold; +} + +#footer-contact { + float: right; + padding-right: 11px; +} + +#footer-clear { + clear: both; +} + +/* + * Media queries + * ------------- + */ + +@media screen and (max-width: 17em) { + #footer-contact { + clear: left; + float: left; + padding-left: 11px; + margin-left: 0; + } +} + +@media screen and (min-width: 24em) { + #footer-name > div { + display: inline; + } + #footer-su::before { + content: "| " + } +} + +@media screen and (min-width: 500px) { + #header { + padding-left: 20px; + } + #top-links, #contents { + padding-left: 20px; + padding-right: 20px; + } + .right { + margin-top: 0; + float: right; + } + .left { + margin-top: 0; + float:left; + } +} + +@media screen and (max-width: 767px) { + #header-su { + display: none; + } + #header-su-responsive { + display: inline-block; + } +} + +@media screen and (min-width: 767px) { + #header-su { + display: inline-block; + } + #header-su-responsive { + display: none; + } + #header-dsv { + padding-top: 75px; + } +} + +@media screen and (min-width: 994px) { + #container { + background-image: url(images/container-repeater.gif); + background-position: left top; + background-repeat: repeat-y; + padding-left: 4px; + padding-right: 4px; + } + #footer { + width: calc(100% - 8px); + } +} diff --git a/template_translations.php b/template_translations.php new file mode 100644 index 0000000..9051290 --- /dev/null +++ b/template_translations.php @@ -0,0 +1,40 @@ +<?php + +$template_translations = array( + 'sv' => array( + '¤template-access-skip-nav¤' => 'Hoppa över navigation', + '¤template-su-name¤' => 'Stockholms universitet', + '¤template-dsv-name¤' => 'Institutionen för data- och systemvetenskap', + '¤template-su-logo-responsive¤' => 'images/su_logo_responsive_sv.png', + '¤template-su-logo¤' => 'images/su_logo_sv.gif', + '¤template-dsv-logo¤' => 'images/dsv_logo_sv.png', + '¤template-su-link-title¤' => 'Till Stockholms universitets webbplats', + '¤template-su-link¤' => 'http://www.su.se/', + '¤template-dsv-link-title¤' => 'Till DSV:s webbplats', + '¤template-dsv-link¤' => 'http://dsv.su.se/', + '¤template-lang-link¤' => '?lang=en', + '¤template-lang-label¤' => 'In English', + '¤template-lang-flag¤' => 'images/globallinks-lang-en.gif', + '¤template-contact-link¤' => 'http://dsv.su.se/omdsv/kontakt/', + '¤template-contact-label¤' => 'Kontakt', + ), + 'en' => array( + '¤template-access-skip-nav¤' => 'Skip navigation', + '¤template-su-name¤' => 'Stockholm University', + '¤template-dsv-name¤' => 'Department of Computer and Systems Sciences', + '¤template-su-logo-responsive¤' => 'images/su_logo_responsive_en.png', + '¤template-su-logo¤' => 'images/su_logo_en.gif', + '¤template-dsv-logo¤' => 'images/dsv_logo_en.png', + '¤template-su-link-title¤' => 'Stockholm University home', + '¤template-su-link¤' => 'http://www.su.se/english/', + '¤template-dsv-link-title¤' => "DSV home", + '¤template-dsv-link¤' => 'http://dsv.su.se/en/', + '¤template-lang-link¤' => '?lang=sv', + '¤template-lang-label¤' => 'På svenska', + '¤template-lang-flag¤' => 'images/globallinks-lang-sv.gif', + '¤template-contact-link¤' => 'http://dsv.su.se/en/about/contact/', + '¤template-contact-label¤' => 'Contact', + ), +); + +?> diff --git a/translations.php b/translations.php new file mode 100644 index 0000000..063c272 --- /dev/null +++ b/translations.php @@ -0,0 +1,10 @@ +<?php +$translations = array( + 'sv' => array( + + ), + 'en' => array( + + ), +); +?>