Skip to content

Commit

Permalink
* Stick / Unstick buttons at the bottom of the page for the admin (fi…
Browse files Browse the repository at this point in the history
…rst name in 'mods.txt')

(some finishing off and polishing remains)
* Updated the image generation script for the above change as well as a little re-organisation
  • Loading branch information
Kroc committed May 18, 2013
1 parent c6101a9 commit d16c432
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 177 deletions.
3 changes: 3 additions & 0 deletions HISTORY.txt
@@ -1,4 +1,7 @@
v26
* Stick and Unstick thread buttons when logged in as the Admin (the admin is now the first person listed in mods.txt)
NOTE: the lock and unlock links have been changed into buttons, make sure to update custom translations / CSS!
* Windows 8 snap-view
* Apache version is now verified (1&1 are still using v1.3!)
* Updated to DOMTemplate v17, fix for major bug corrupting querystrings and attributes,
with thanks to Bruno Héridet for narrowing down and Zegnat for suggesting a fix
Expand Down
17 changes: 6 additions & 11 deletions index.php
Expand Up @@ -76,18 +76,13 @@
//order by last modified date
array_multisort (array_map ('filemtime', $threads), SORT_DESC, $threads);

//get sticky list, trimming any files that no longer exist
//get sticky list (see 'lib/functions.php')
//(the use of `array_intersect` will only return filenames in `sticky.txt` that were also in the directory)
if ($stickies = array_intersect (
//`file` returns NULL on failure, so we can cast it to an array to get an array with one blank item,
//then `array_filter` removes blank items. this way saves having to check if the file exists first
array_filter ((array) @file ('sticky.txt', FILE_IGNORE_NEW_LINES)), $threads
)) {
//order the stickies by reverse date order
array_multisort (array_map ('filemtime', $stickies), SORT_DESC, $stickies);
//remove the stickies from the thread list
$threads = array_diff ($threads, $stickies);
}
$stickies = array_intersect (getStickies (), $threads);
//order the stickies by reverse date order
array_multisort (array_map ('filemtime', $stickies), SORT_DESC, $stickies);
//remove the stickies from the thread list
$threads = array_diff ($threads, $stickies);

//handle a rounding problem with working out the number of pages (PHP 5.3 has a fix for this)
$PAGES = count ($threads) % FORUM_THREADS == 1 ? floor (count ($threads) / FORUM_THREADS)
Expand Down
11 changes: 11 additions & 0 deletions lib/functions.php
Expand Up @@ -143,6 +143,10 @@ function prepareTemplate (

/* ====================================================================================================================== */

//the first mod on the list is the site administrator and has extra privileges such as stickying threads
function isAdmin ($name) {
global $MODS; return strtolower ($name) === strtolower ((string) @$MODS['GLOBAL'][0]);
}
//check to see if a name is a known moderator
function isMod ($name) {
global $MODS; return in_array (strtolower ($name), array_map ('strtolower', $MODS['GLOBAL'] + $MODS['LOCAL']));
Expand All @@ -152,6 +156,13 @@ function isMember ($name) {
global $MEMBERS; return in_array (strtolower ($name), array_map ('strtolower', $MEMBERS));
}

//get the list of sticky threads in the current forum / sub-forum
function getStickies () {
//`file` returns NULL on failure, so we can cast it to an array to get an array with one blank item,
//then `array_filter` removes blank items. this way saves having to check if the file exists first
return array_filter ((array) @file ('sticky.txt', FILE_IGNORE_NEW_LINES));
}

/* ====================================================================================================================== */

//take the author's message, process markup, and encode it safely for the RSS feed
Expand Down
Binary file modified metro-tile.default.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions start.php
Expand Up @@ -41,6 +41,7 @@
see section 5 in the README file
$MODS array of the names of moderators for the whole forum, and the current sub-forum
$MEMBERS array of the names of members for the current sub-forum
IS_ADMIN b if the current viewer is the site admin (first name in 'mods.txt')
IS_MOD b if the current viewer is a moderator for the current forum
IS_MEMBER b if the current viewer is a member of the current forum
Expand Down Expand Up @@ -232,6 +233,8 @@
//get the list (if any) of users allowed to access this current forum
$MEMBERS = array_filter ((array) @file ('members.txt', FILE_IGNORE_NEW_LINES));

//is the current user the site admin? (first name in the root 'mods.txt')
define ('IS_ADMIN', AUTH && isAdmin (NAME));
//is the current user a moderator in this forum?
define ('IS_MOD', AUTH && isMod (NAME));
//is the current user a member of this forum?
Expand Down

0 comments on commit d16c432

Please sign in to comment.