Browse Source

Fix #184: "news" lock type

This is unofficially supported (not mentioned in the README) due to the uncertainty of `filectime` behaviour

Also:
* Updated documentation ready for v26
* Fixed potential bug when the language cookie refers to a language no-longer available
master
Kroc Camen 6 years ago
parent
commit
235ccd1d0d
4 changed files with 106 additions and 86 deletions
  1. +67
    -63
      README.txt
  2. +15
    -7
      index.php
  3. +16
    -9
      start.php
  4. +8
    -7
      thread.php

+ 67
- 63
README.txt View File

@@ -23,23 +23,71 @@ How NoNonsense differs from other forums:

Contents:
========================================================================
[1] Things to note
[1.1] Post appending
[1.2] Post deleting
[2] Sub-forums
[3] Sticky threads
[4] Moderators
[4.1] Sign-in
[5] Forum locking
[1] Admin & Moderators
[1.1] Set Up
[1.2] Sign-in
[2] Things to Note
[2.1] Post Appending
[2.2] Post Deleting
[3] Sub-forums
[4] Lock & Sticky Threads
[5] Forum Locking
[5.1] Members
[5.2] A note on private forums
[5.2] A Note on Private Forums
[6] Acknowledgements
------------------------------------------------------------------------


[1] Things to note:
[1] Admin & Moderators
========================================================================
[1.1] Post appending:
[1.1] Set Up:
------------------------------------------------------------------------
The first thing you need to do is provide a username for the admin,
and any moderators you would like

* Create a "mods.txt" file in the forum / sub-forum

* The user name on the first line will be the forum's admin

* Add the user name of each mod on a separate line.
e.g.

Kroc
theraje
SpeedoJoe

* Mods in the root forum ("/mods.txt") can moderate in all
sub-forums, including locked ones

* Mods in sub-forums ("/news/mods.txt") can only moderate in that
sub-forum
NOTE: Make sure that admin and mod accounts are created (by posting
once), otherwise anybody could steal the name and take control!

[1.2] Sign-in:
------------------------------------------------------------------------
Some moderator actions require the user to sign-in.

* Click the "sign in" link at the bottom of the page and enter
your name / password

* Threads can be locked and unlocked with the relevant link at
the bottom of the page

* Once signed in, you must quit your browser fully (not just
close the tab or window), or clear your browser's cache to
sign out

* Unfortunately, due to a flaw in HTTP authentication, users with
accented / unicode letters in their name will not be able to
sign-in. Moderators and members must limit their chosen names
to basic letters, numbers and punctuation


[2] Things to Note:
========================================================================
[2.1] Post Appending:
------------------------------------------------------------------------
Because threads are RSS feeds, the text to HTML conversion that happens
when you post is one-way. You cannot edit posts, other than manually
@@ -49,7 +97,7 @@ editing the RSS file. Instead, text can be appended to the end of posts.

* Moderators can append to any posts

[1.2] Post deleting:
[2.2] Post Deleting:
------------------------------------------------------------------------
To avoid abuse, users cannot permanently delete their own posts.

@@ -65,7 +113,7 @@ To avoid abuse, users cannot permanently delete their own posts.
permalinks by rearranging page boundaries


[2] Sub-forums:
[3] Sub-forums:
========================================================================
Sub-forums are simply folders.

@@ -79,58 +127,14 @@ Sub-forums are simply folders.
(E.g. '/Music/Techno/')


[3] Sticky threads:
========================================================================
Sticky threads remain at the top of a forum, regardless of page.

* Create a "sticky.txt" file in the forum / sub-forum

* Add the filename of each thread you would like to sticky on
separate lines, including the ".rss" file extension.
For example:

the_rules.rss
f_a_q_.rss


[4] Moderators:
[4] Lock & Sticky Threads:
========================================================================
Moderators can delete / append to any posts and delete / lock / unlock
threads.

* Create a "mods.txt" file in the forum / sub-forum

* Add the user name of each mod on a separate line.
e.g.

Kroc
theraje
SpeedoJoe

* Mods in the root forum ("/mods.txt") can moderate in all
sub-forums, including locked ones
Locked threads cannot be replied to. Sticky threads remain at the top
of a forum, regardless of page.

* Mods in sub-forums ("/news/mods.txt") can only moderate in that
sub-forum

[4.1] Sign-in:
------------------------------------------------------------------------
Some moderator actions require the user to sign-in.
* To un/lock or un/sticky a thread, first sign-in as the admin

* Click the "sign in" link at the bottom of the page and enter
your name / password

* Threads can be locked and unlocked with the relevant link at
the bottom of the page

* Once signed in, you must quit your browser fully (not just
close the tab or window), or clear your browser's cache to
sign out

* Unfortunately, due to a flaw in HTTP authentication, users with
accented / unicode letters in their name will not be able to
sign-in. Moderators and members must limit their chosen names
to basic letters, numbers and punctuation
* Click the Un/Lock or Un/Sticky thread button


[5] Forum Locking:
@@ -164,7 +168,7 @@ have moderator powers; they are your participants in restricted forums.
* Members must sign-in to be able to post in locked forums

[5.2] A note on private forums:
[5.2] A Note on Private Forums:
------------------------------------------------------------------------
NoNonsense Forum does not provide an option for private forums (can
only be accessed by members) because the index RSS feed (which includes

+ 15
- 7
index.php View File

@@ -73,14 +73,20 @@ if (CAN_POST && AUTH && TITLE && TEXT) {
//first load the list of threads in the forum so that we can determine the number of pages and validate the page number,
//the thread list won't be used until further down after templating begins
if ($threads = preg_grep ('/\.rss$/', scandir ('.'))) {
//order by last modified date
array_multisort (array_map ('filemtime', $threads), SORT_DESC, $threads);
//sort the list of threads in the forum
array_multisort (array_map (
//if the forum is set to "news" lock, we will order the threads by their original date
(FORUM_LOCK == 'news') ? 'filectime' : 'filemtime',
$threads), SORT_DESC, $threads);
//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)
$stickies = array_intersect (getStickies (), $threads);
//order the stickies by reverse date order
array_multisort (array_map ('filemtime', $stickies), SORT_DESC, $stickies);
//order the stickies
array_multisort (array_map (
//if the forum is set to "news" lock, we will order the threads by their original date
(FORUM_LOCK == 'news') ? 'filectime' : 'filemtime',
$stickies), SORT_DESC, $stickies);
//remove the stickies from the thread list
$threads = array_diff ($threads, $stickies);
@@ -117,7 +123,7 @@ $template = prepareTemplate (
//remove the "add thread" link and anything else (like the input form) related to posting
'#nnf_add, #nnf_new-form' => !CAN_POST,
//if the forum is not thread-locked (only mods can post, anybody can reply) then remove the warning message
'#nnf_forum-lock-threads' => FORUM_LOCK != 'threads' || IS_MOD,
'#nnf_forum-lock-threads' => !FORUM_LOCK || FORUM_LOCK == 'posts' || IS_MOD,
//if the forum is not post-locked (only mods can post / reply) then remove the warning message
'#nnf_forum-lock-posts' => FORUM_LOCK != 'posts' || IS_MOD || IS_MEMBER
));
@@ -155,8 +161,10 @@ if ($folders = array_filter (
//get a list of files in the folder to determine which one is newest
$files = preg_grep ('/\.rss$/', scandir ('.'));
//order by last modified date
array_multisort (array_map ('filemtime', $files), SORT_DESC, $files);
//order by last modified date / created date ("news" forum)
array_multisort (array_map (
($lock == 'news') ? 'filectime' : 'filemtime',
$files), SORT_DESC, $files);
//read the newest thread (folder could be empty though)
$last = ($xml = @simplexml_load_file ($files[0])) ? $xml->channel->item[0] : '';

+ 16
- 9
start.php View File

@@ -218,6 +218,7 @@ if (( //if HTTP authentication is used, we don’t need to validate the form f
---------------------------------------------------------------------------------------------------------------------- */
//get the lock status of the current forum we’re in:
//"threads" - only users in "mods.txt" / "members.txt" can start threads, but anybody can reply
//"news" - as above, but the forum is listed by original posting date (descending), not last-reply date
//"posts" - only users in "mods.txt" / "members.txt" can start threads or reply
define ('FORUM_LOCK', trim (@file_get_contents ('locked.txt')));

@@ -270,15 +271,21 @@ define ('LANG',
"lang", $_POST['lang'], time ()+60*60*24*365, FORUM_PATH, $_SERVER['HTTP_HOST'], FORUM_HTTPS
) ? $_POST['lang']
//otherwise, does a cookie already exist to set the language?
: (@$_COOKIE['lang'] ? $_COOKIE['lang'] : (
//otherwise, try detect the language sent by the browser:
$lang = @array_shift (array_intersect (
//- find language codes in the HTTP header and compare with the theme provided languages
preg_replace ('/^([a-z0-9-]+).*/i', '$1', explode (',', $_SERVER['HTTP_ACCEPT_LANGUAGE'])),
explode (' ', THEME_LANGS)
)) ? $lang
//all else failing, use the default language
: THEME_LANG))
: ( //validate that the language in the cookie actually exists!
array_key_exists (@$_COOKIE['lang'], $LANG)
? @$_COOKIE['lang']
: (
//otherwise, try detect the language sent by the browser:
$lang = @array_shift (array_intersect (
//- find language codes in the HTTP header and compare with the theme provided languages
preg_replace ('/^([a-z0-9-]+).*/i', '$1', explode (',', $_SERVER['HTTP_ACCEPT_LANGUAGE'])),
explode (' ', THEME_LANGS)
))
? $lang
//all else failing, use the default language
: THEME_LANG
)
)
);

//for curtness, and straight-forward compatibility with older versions of NNF, we shorthand these translations;

+ 8
- 7
thread.php View File

@@ -32,9 +32,10 @@ define ('CAN_REPLY', FORUM_ENABLED && (
IS_MOD ||
//- if you are a member, the forum lock doesn’t matter, but you can’t reply to locked threads (only mods can)
(!(bool) $xml->channel->xpath ('category[.="locked"]') && IS_MEMBER) ||
//- if you are neither a mod nor a member, then as long as: 1. the thread is not locked, and
// 2. the forum is such that anybody can reply (unlocked or thread-locked), then you can reply
(!(bool) $xml->channel->xpath ('category[.="locked"]') && (!FORUM_LOCK || FORUM_LOCK == 'threads'))
//- if you are neither a mod nor a member, then as long as:
// 1. the *thread* is not locked, and
// 2. the *forum* is such that anybody can reply (unlocked or news/thread-locked), then you can reply
(!(bool) $xml->channel->xpath ('category[.="locked"]') && (FORUM_LOCK != 'posts'))
));

/* ======================================================================================================================
@@ -126,7 +127,7 @@ if ($ID = (preg_match ('/^[A-Z0-9]+$/i', @$_GET['append']) ? $_GET['append'] : f
//the owner of a post can append
(strtolower (NAME) == strtolower ($post->author) && (
//if the forum is post-locked, they must be a member to append to their own posts
(!FORUM_LOCK || FORUM_LOCK == 'threads') || IS_MEMBER
(FORUM_LOCK != 'posts') || IS_MEMBER
))
)) {
//check for duplicate append:
@@ -257,7 +258,7 @@ if (isset ($_GET['delete'])) {
//the owner of a post can delete
(strtolower (NAME) == strtolower ($post->author) && (
//if the forum is post-locked, they must be a member to delete their own posts
(!FORUM_LOCK || FORUM_LOCK == 'threads') || IS_MEMBER
(FORUM_LOCK != 'posts') || IS_MEMBER
))
//deleting a post?
)) if ($ID) {
@@ -493,7 +494,7 @@ $template = prepareTemplate (
'#nnf_reply, #nnf_reply-form' => !CAN_REPLY,
//if the forum is not post-locked (only mods can post / reply) then remove the warning message
'.nnf_forum-locked' => FORUM_LOCK != 'posts',
//is the user a mod and can lock / unlock / stick / unstick the thread?
//is the user a mod and can un/lock or un/stick the thread?
'#nnf_admin' => !IS_MOD,
//is the thread already locked?
'#nnf_lock' => $xml->channel->xpath ('category[.="locked"]'),
@@ -592,7 +593,7 @@ if (!count ($thread)) {
//if this reply is the by the owner (they can append/delete to their own replies)
(strtolower (NAME) == strtolower ($reply->author) && (
//if the forum is post-locked, they must be a member to append/delete their own replies
(!FORUM_LOCK || FORUM_LOCK == 'threads') || IS_MEMBER
(FORUM_LOCK != 'posts') || IS_MEMBER
))
)),
//append link not available when the reply has been deleted

Loading…
Cancel
Save