Initial commit

This commit is contained in:
Erik Thuning 2018-07-04 11:27:24 +02:00
commit f6bad2d2d9
19 changed files with 546 additions and 0 deletions

3
.gitignore vendored Normal file

@ -0,0 +1,3 @@
*~
.htaccess
config.php

8
config.php.example Normal file

@ -0,0 +1,8 @@
<?php
$db_host = 'dbserver';
$db_user = 'dbname';
$db_pass = 'dbpassword';
$db_name = 'dbuser';
?>

58
html/base.html Normal file

@ -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>

Binary file not shown.

After

(image error) Size: 589 B

Binary file not shown.

After

(image error) Size: 366 B

BIN
images/dsv_logo_en.png Normal file

Binary file not shown.

After

(image error) Size: 6.5 KiB

BIN
images/dsv_logo_sv.png Normal file

Binary file not shown.

After

(image error) Size: 6.4 KiB

BIN
images/favicon.ico Normal file

Binary file not shown.

After

Width: 16px  |  Height: 16px  |  Size: 318 B

Binary file not shown.

After

(image error) Size: 598 B

Binary file not shown.

After

(image error) Size: 609 B

BIN
images/su_logo_en.gif Normal file

Binary file not shown.

After

(image error) Size: 2.1 KiB

Binary file not shown.

After

(image error) Size: 9.8 KiB

Binary file not shown.

After

(image error) Size: 9.5 KiB

BIN
images/su_logo_sv.gif Normal file

Binary file not shown.

After

(image error) Size: 2.0 KiB

102
include.php Normal file

@ -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);
}
?>

12
index.php Executable file

@ -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');
?>

313
template.css Normal file

@ -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);
}
}

40
template_translations.php Normal file

@ -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',
),
);
?>

10
translations.php Normal file

@ -0,0 +1,10 @@
<?php
$translations = array(
'sv' => array(
),
'en' => array(
),
);
?>