summaryrefslogtreecommitdiff
path: root/public/app/views/simple/category.php
blob: 15d8b5e2bf2cbbd272ce8e6d3af54d6a55799773 (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
<?php
// init app
// -----------------------------------------------------------------------------
include 'pythia.php';


// read request parameters
// -----------------------------------------------------------------------------
$category_id = intval($_GET['id']);


// Get all data needed
// (so you don't have to make multiple requests to the wiki-database)
// -----------------------------------------------------------------------------

$categories = $wiki->category_tree();
$breadcrumbs = Render::all_breadcrumbs($categories);

// get ALL posts of category
$posts = $wiki->latest_published_posts($category_id, 0);


// special case:
// -----------------------------------------------------------------------------
// ONE post + NO subcaegories ..then redirect to the only post
if (($breadcrumbs[ $category_id ]['childs'] == []) && (count($posts) == 1)) {
    header('Location: /wiki/post?id='. $posts[0]['id'], true, 302);
    die();
}


// find parent_ids of current category (to open the menu tree)
$category_path = [];
foreach($breadcrumbs[$category_id]['parents'] as $parent) {
    $category_path[] = intval($parent['id']);
}
$category_path[] = intval($category_id);


// format $posts array
// ---
$posts_formated = [];
foreach($posts as $post) {
    $date = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $post['creation_date']);
    $posts_formated[] = [
        'id' => $post['id'],
        'title' => $post['title'],
        'intro' => $post['intro'] ?? false,
        'date' => Render::date_box($post['creation_date'])
    ];
}


// then render the page ...
// -----------------------------------------------------------------------------
?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Wiki</title>

    <?php Render::template("sections/common_libs.php", [ 'admin' => false ]); ?>

</head>
<body>
    <?php include HEAD; ?>

    <div class="container-fluid main-content wiki">

        <div class="top-bar">
            <div class="breadcrumb">
                <?php    // breadcrumbs
                    ////////////////////////////////////////////////////////////
                    Render::template("sections/breadcrumbs.php", [
                        'id' => $category_id,
                        'title' => $breadcrumbs[ $category_id ]['rec']['title'],
                        'parents' => $breadcrumbs[ $category_id ]['parents']
                    ]);     ////////////////////////////////////////////////////
                ?>
            </div>

            <div class="admin">
                <?php include "sections/admin-dropdown.php"; ?>
            </div>

        </div><!-- /top-bar -->

        <div class="row">
            <div class="col-xl-2 col-lg-3 col-sm-4 side-bar">

                <!-- <h3>Κατηγορίες</h3> -->
                <?php    // categories hierarchical menu
                    ////////////////////////////////////////////////////////////
                    Render::template("sections/categories_menu.php", [
                        'categories' => $categories,
                        'open_path' => $category_path
                    ]);     ////////////////////////////////////////////////////
                ?>

            </div>
            <div class="col-xl-10 col-lg-9 col-sm-8 content">
                              
                <div class="content--wrapper">

                    <!-- Category Title -->
                    <h2>
                        <?=$breadcrumbs[ $category_id ]['rec']['title']?>
                    </h2>


                    <!-- Sub-Categories -->

                    <?php if ($breadcrumbs[ $category_id ]['childs'] != []) : ?>

                        <h3>Υποκατηγορίες</h3>
                        <div class="category-childs">

                        <?php foreach($breadcrumbs[ $category_id ]['childs'] as $key => $child) : ?>
                            
                            <a href="/wiki/category?id=<?=$child['id']?>">
                                <?=$child['title']?>
                            </a>

                        <?php endforeach; ?>

                        </div>
                        
                    <?php endif; ?>


                    <!-- Articles List -->

                    <?php if ($posts) : ?>

                        <h3>Άρθρα / Δημοσιεύσεις</h3>

                        <?php    // list of posts/articles
                            ////////////////////////////////////////////////////
                            Render::template("sections/articles_list.php", [
                                'articles' => $posts_formated,
                                'fieldset' => ['intro', 'date']
                            ]);
                            ////////////////////////////////////////////////////
                        ?>
                    <?php endif; ?>
                    

                </div>
                
            </div>
        </div>
    </div>

    <script src="/wiki/js/wiki.js"></script>
</body>
</html>