summaryrefslogtreecommitdiffstats
path: root/index.php
blob: 1d1dbbe48d542e484a855d11c6609526550ff8c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php

include_once(__DIR__.'/lib/commons/functions.common.inc.php');
include_once(__DIR__.'/lib/commons/functions.http.inc.php');
include_once(__DIR__.'/lib/functions.stories.inc.php');

$config = require(__DIR__.'/config/config.inc.php');
$txt = require(__DIR__.'/config/text.inc.php');

$storiesDir = __DIR__.'/stories';

$storiesDirContent = getDirectoryContent($storiesDir);

$isAuthenticated = true;
$isAdmin = true;

$currentStory = getOptionalGetParameter('story');
$currentStoryIsSet = isset($currentStory) && !empty($currentStory);
$stories = array();
$characters = array();

foreach ($storiesDirContent as $storyName) {
    $storyPath = $storiesDir.DIRECTORY_SEPARATOR.$storyName;
    if (is_dir($storyPath)) {
        $storyDescription = file_get_contents($storyPath.DIRECTORY_SEPARATOR.'description.txt');
        $stories[$storyName] = $storyDescription;

        if ($currentStoryIsSet && urlencode($currentStory) == $storyName) {
            $charactersDirContent = array_diff(scandir($storyPath), array('..', '.'));

            foreach ($charactersDirContent as $character) {
                $characterPath = $storyPath.DIRECTORY_SEPARATOR.$character;
                if (is_dir($characterPath)) {
                    $characterDescription = file_get_contents($characterPath.DIRECTORY_SEPARATOR.'description.txt');
                    $characters[$character] = $characterDescription;
                }
            }
        }
    }
}

ksort($stories, SORT_STRING);

$currentStoryName = visibleName($currentStory);

function printEntities($entities, $storyName = NULL) {
    foreach ($entities as $entity=>$description) {
        $name = visibleName($entity);
        $imgName = (NULL != $storyName) ? 'passphoto.png' : 'logo.png';
        $imgPath = 'stories/'.((NULL != $storyName) ? (urlencode($storyName).'/') : '');
        $imgPath .= urlencode($entity);
?>
    <!-- <?=$name;?> -->
    <div class="row">
        <div class="col-md-7 text-center">
            <img class="img-fluid rounded mb-3 mb-md-0 figure-pic" src="<?=$imgPath.'/'.$imgName;?>" alt="<?=$name;?>" title="<?=$name;?>">
        </div>
        <div class="col-md-5">
            <h3><?=$name;?></h3>
            <p class="figure-desc"><?=$description;?></p>
        </div>
    </div>
    <!-- /.row -->
    
    <hr>
    <?php
    }
}

?>
<!DOCTYPE html>
<html lang="de">
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="https://www.sl-its.de/css/bootstrap.spacelab.min.css">
        <script src="https://www.sl-its.de/js/jquery-1.11.2.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
        <script src="js/stories.js"></script>
        <style type="text/css">
            .figure-desc {
                text-align: justify;
            }
            .figure-pic {
                height: 300px;
                width: 300px;
            }
            .story-header {
                font-size: 2em;
            }
            .navbar {
                height: 50px;
            }
            .spacer {
                height: 55px;
            }
            .floating-action-btn {
                position: fixed;
                bottom: 45px;
                right: 34px;
                background-color: #ff8000;
                border-radius: 50%;
                box-shadow: 5px 5px 5px #ccc;
                width: 50px;
                height: 50px;
                line-height: 50px;
                text-align: center;
                vertical-align: middle;
                font-size: 2.6em;
                cursor: pointer;
            }
        </style>
        <title>Kindergeschichten</title>
    </head>
    <body>
        <nav class="navbar navbar-default navbar-fixed-top navbar-right">
            <div class="navbar-header">
                <a class="navbar-brand" href="index.php">Kindergeschichten</a>
                <button type="button" class="navbar-toggle navbar-toggle-si" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>
            <div class="container-fluid">
                <div class="collapse navbar-collapse" id="myNavbar">
                    <ul class="nav navbar-nav">
    <?php
    foreach ($stories as $storyName=>$desc) {
        $visibleName = visibleName($storyName);
        $cssClass = ($visibleName == $currentStoryName) ? " class=\"active\"" : "";
    ?>
                    <li<?=$cssClass;?>><a href="index.php?story=<?=$storyName;?>"><?=$visibleName;?></a></li>
    <?php
    }
    ?>
                </ul>
                </div>
            </div>
        </nav>
        <div class="spacer"></div>
        <div class="container">
<?php if ($currentStoryIsSet) { ?>
            <div class="row">
                <div class="col-md-7 text-center">
                    <img class="img-fluid mb-3 mb-md-0 story-header" src="stories/<?=urlencode($currentStory)?>/header.png" alt="<?=$currentStoryName;?>" title="<?=$currentStoryName;?>">
                </div>
            </div>
            <?php
            printEntities($characters);
} else {
    printEntities($stories);
}
?>
</div>
<?php
if ($isAuthenticated && $isAdmin) {
    if (!$currentStoryIsSet) {
        include(__DIR__.'/lib/new-story-dialog.inc.php');
    } else {
       include(__DIR__.'/lib/new-character-dialog.inc.php');
    }
}
?>
    </body>
</html>