summaryrefslogtreecommitdiff
path: root/htdocs/categories.php
blob: a3e8ba20e68b3093b5c6c1095009927563eddc20 (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
<?php

/* Foursquare Community Site
 * 
 * Copyright (C) 2011 Foursquare Church.
 * 
 * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
 *
 */

require_once "src/base.inc.php";

require_once "src/header.inc.php";

// Do we have a path info?
if (isset($_SERVER['PATH_INFO'])) {
    // Get the category
    $category = addslashes(substr($_SERVER['PATH_INFO'], 1));

    $category = Category::getByShortname($category);
    if ($category) {
        displayEvents($category);
    
    } else {
        // Bad category. List them all.
        listCategories();
    }

} else {
    // No category. List them all.
    listCategories();
}


function listCategories() {
    echo "<h2>Categories</h2>";

    $cats = Category::getCategories();
    echo "<dl>";
    foreach ($cats as $short => $cat) {
        $url = $GLOBALS['CONFIG']['urlroot'] . "/categories/$short";
        echo "<dt><a href=\"$url\">". $cat->getName() ."</a></dt>";
        echo "<dd>". $cat->getDescription() ."</dd>";
    }
    echo "</dl>";
}

function displayEvents($category) {
    echo "<h2>". $category->getName() ."</h2>";

    // Get all recent, approved posts.
    $posts = new PostIterator();
    $posts->filterCategory($category->getId());
    $posts->filterStage('approved');
    $posts->query();

    if ($posts->valid()) {
        foreach ($posts as $id => $post) {
            printf("<div class=\"post\"><p><a href=\"". $GLOBALS['CONFIG']['urlroot']
                    . "/postings/%s.html\">%s</a></p>"
                    . "<div class=\"desc\"><span class=\"location\">%s</span>"
                    . " <span class=\"age\">%s</span></div></div>",
                    
                    $id, $post->getName(), $post->getLocation(), $post->getAge());
        }

    } else {
        echo "<p>No recent posts.</p>";
    }
}

require_once "src/footer.inc.php";

?>