Lighttpd conf file added for lighttpd webservers
[atbbs.git] / index.php
blob67d85aad7738238896995a13efea3c3fbd0ba2a6
1 <?php
3 require('includes/header.php');
5 // Should we sort by topic creation date or last bump?
6 if($_COOKIE['topics_mode'] == 1 && ! $_GET['bumps'])
8 $topics_mode = true;
11 // Are we on the first page?
12 if ($_GET['p'] < 2 || ! ctype_digit($_GET['p']))
14 $current_page = 1;
16 if($topics_mode)
18 update_activity('latest_topics');
19 $page_title = 'Latest topics';
20 $last_seen = $_COOKIE['last_topic'];
22 else
24 update_activity('latest_bumps');
25 $page_title = 'Latest bumps';
26 $last_seen = $_COOKIE['last_bump'];
29 // The page number is greater than one.
30 else
32 $current_page = $_GET['p'];
33 update_activity('topics', $current_page);
34 $page_title = 'Topics, page #' . number_format($current_page);
37 // Update the last_bump and last_topic cookies. These control
38 // both the last seen marker and the exclamation mark in main menu.
39 if($_COOKIE['last_bump'] <= $last_actions['last_bump'])
41 setcookie('last_bump', $_SERVER['REQUEST_TIME'], $_SERVER['REQUEST_TIME'] + 315569260, '/');
43 if($_COOKIE['last_topic'] <= $last_actions['last_topic'])
45 setcookie('last_topic', $_SERVER['REQUEST_TIME'], $_SERVER['REQUEST_TIME'] + 315569260, '/');
48 // If ostrich mode is enabled, fetch a list of blacklisted phrases.
49 $ignored_phrases = fetch_ignore_list();
51 // Fetch the topics appropriate to this page.
52 $items_per_page = ITEMS_PER_PAGE;
53 $start_listing_at = $items_per_page * ($current_page - 1);
54 if($topics_mode)
56 $stmt = $link->prepare('SELECT id, time, replies, visits, headline, body, last_post FROM topics ORDER BY id DESC LIMIT ?, ?');
58 else
60 $stmt = $link->prepare('SELECT id, time, replies, visits, headline, body, last_post FROM topics ORDER BY last_post DESC LIMIT ?, ?');
62 $stmt->bind_param('ii', $start_listing_at, $items_per_page);
63 $stmt->execute();
64 $stmt->bind_result($topic_id, $topic_time, $topic_replies, $topic_visits, $topic_headline, $topic_body, $topic_last_post);
66 // Print the topics we just fetched in a table.
67 $table = new table();
69 $order_name = ($topics_mode) ? 'Age' : 'Last bump';
70 $columns = array
72 'Headline',
73 'Snippet',
74 'Replies',
75 'Visits',
76 $order_name . ' ▼'
79 if($_COOKIE['spoiler_mode'] != 1)
81 // If spoiler mode is disabled, remove the snippet column.
82 array_splice($columns, 1, 1);
85 $table->define_columns($columns, 'Headline');
86 $table->add_td_class('Headline', 'topic_headline');
87 $table->add_td_class('Snippet', 'snippet');
89 while($stmt->fetch())
91 // Should we even bother?
92 if($_COOKIE['ostrich_mode'] == 1)
94 foreach($ignored_phrases as $ignored_phrase)
96 if(stripos($topic_headline, $ignored_phrase) !== false || stripos($topic_body, $ignored_phrase) !== false)
98 // We've encountered an ignored phrase, so skip the rest of this while() iteration.
99 $table->num_rows_fetched++;
100 continue 2;
105 // Decide what to use for the last seen marker and the age/last bump column.
106 if($topics_mode)
108 $order_time = $topic_time;
110 else
112 $order_time = $topic_last_post;
115 // Process the values for this row of our table.
116 $values = array (
117 '<a href="/topic/' . $topic_id . '">' . htmlspecialchars($topic_headline) . '</a>',
118 snippet($topic_body),
119 replies($topic_id, $topic_replies),
120 format_number($topic_visits),
121 '<span class="help" title="' . format_date($order_time) . '">' . calculate_age($order_time) . '</span>'
123 if($_COOKIE['spoiler_mode'] != 1)
125 array_splice($values, 1, 1);
128 $table->last_seen_marker($last_seen, $order_time);
129 $table->row($values);
131 $stmt->close();
132 $num_rows_fetched = $table->num_rows_fetched;
133 echo $table->output('topics');
135 // Navigate backward or forward ...
136 $navigation_path = 'topics';
137 if($_GET['bumps'])
139 $navigation_path = 'bumps';
141 page_navigation($navigation_path, $current_page, $num_rows_fetched);
143 require('includes/footer.php');