Skip to content

Commit

Permalink
v3. Added "page=last" support for threads
Browse files Browse the repository at this point in the history
  • Loading branch information
Kroc Camen committed Jul 30, 2011
1 parent 87eb91f commit ca9d10b
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 20 deletions.
4 changes: 4 additions & 0 deletions HISTORY.txt
@@ -1,3 +1,7 @@
v3 30.JUL.11
Links to threads now use "page=last"
"Users" folder now included in the download for simpler setup

v2 18.JUN.11
Ignore invalid XML files when generating index page / RSS
Prevent null filenames for threads with only non-ASCII titles
Expand Down
2 changes: 1 addition & 1 deletion LICENCE.txt
@@ -1,4 +1,4 @@
NoNonsense Forum v2 © Copyright CC-BY 3.0 Kroc Camen of Camen Design
NoNonsense Forum v3 © Copyright CC-BY 3.0 Kroc Camen of Camen Design
====================================================================
The PHP / HTML / CSS and other resources of this project are licensed under a Creative Commons 3.0 Attribution Unported licence (unless otherwise stated), viewable here: http://creativecommons.org/licenses/by/3.0/deed.en_GB

Expand Down
2 changes: 1 addition & 1 deletion README.txt
@@ -1,4 +1,4 @@
NoNonsense Forum v2 © Copyright CC-BY 3.0 Kroc Camen of Camen Design
NoNonsense Forum v3 © Copyright CC-BY 3.0 Kroc Camen of Camen Design
====================================================================
A simple forum that focuses on discussion and simplicity.

Expand Down
2 changes: 1 addition & 1 deletion action.php
@@ -1,6 +1,6 @@
<?php //commit actions on posts, like delete, edit &c.
/* ====================================================================================================================== */
/* NoNonsense Forum v2 © Copyright (CC-BY) Kroc Camen 2011
/* NoNonsense Forum v3 © Copyright (CC-BY) Kroc Camen 2011
licenced under Creative Commons Attribution 3.0 <creativecommons.org/licenses/by/3.0/deed.en_GB>
you may do whatever you want to this code as long as you give credit to Kroc Camen, <camendesign.com>
*/
Expand Down
2 changes: 1 addition & 1 deletion config.example.php
@@ -1,6 +1,6 @@
<?php //configuration defaults
/* ====================================================================================================================== */
/* NoNonsense Forum v2 © Copyright (CC-BY) Kroc Camen 2011
/* NoNonsense Forum v3 © Copyright (CC-BY) Kroc Camen 2011
licenced under Creative Commons Attribution 3.0 <creativecommons.org/licenses/by/3.0/deed.en_GB>
you may do whatever you want to this code as long as you give credit to Kroc Camen, <camendesign.com>
*/
Expand Down
9 changes: 5 additions & 4 deletions index.php
@@ -1,12 +1,15 @@
<?php //display the index of threads in a folder
/* ====================================================================================================================== */
/* NoNonsense Forum v2 © Copyright (CC-BY) Kroc Camen 2011
/* NoNonsense Forum v3 © Copyright (CC-BY) Kroc Camen 2011
licenced under Creative Commons Attribution 3.0 <creativecommons.org/licenses/by/3.0/deed.en_GB>
you may do whatever you want to this code as long as you give credit to Kroc Camen, <camendesign.com>
*/

require_once './shared.php';

//get page number
define ('PAGE', preg_match ('/^[1-9][0-9]*$/', @$_GET['page']) ? (int) $_GET['page'] : 1);

//submitted info for making a new thread
//(name / password already handled in 'shared.php')
define ('TITLE', mb_substr (trim (@$_POST['title']), 0, SIZE_TITLE, 'UTF-8'));
Expand Down Expand Up @@ -139,9 +142,7 @@
$THREADS[] = array (
'STICKY' => in_array ($file, $stickies),
//link to the thread--go to the last page of replies
'URL' => pathinfo ($file, PATHINFO_FILENAME).(count ($xml->channel->item) > FORUM_POSTS+1
? '?page='.ceil ((count ($xml->channel->item) - 1) / FORUM_POSTS) : ''
),
'URL' => pathinfo ($file, PATHINFO_FILENAME).'?page=last',
'TITLE' => safeHTML ($xml->channel->title),
'COUNT' => count ($xml->channel->item) - 1,
'DATETIME' => date ('c', strtotime ($last->pubDate)), //HTML5 datetime attr
Expand Down
6 changes: 1 addition & 5 deletions shared.php
@@ -1,6 +1,6 @@
<?php //reduce some duplication
/* ====================================================================================================================== */
/* NoNonsense Forum v2 © Copyright (CC-BY) Kroc Camen 2011
/* NoNonsense Forum v3 © Copyright (CC-BY) Kroc Camen 2011
licenced under Creative Commons Attribution 3.0 <creativecommons.org/licenses/by/3.0/deed.en_GB>
you may do whatever you want to this code as long as you give credit to Kroc Camen, <camendesign.com>
*/
Expand Down Expand Up @@ -76,10 +76,6 @@
define ('AUTH', false);
}

//whilst page number is not used everywhere (like 'action.php'), it does no harm to get it here because it can simply be
//ignored on 'action.php' &c. whilst avoiding duplicated code on the scripts that do use it
define ('PAGE', preg_match ('/^[1-9][0-9]*$/', @$_GET['page']) ? (int) $_GET['page'] : 1);

//all our pages use path (often optional) so this is done here
define ('PATH', preg_match ('/[^.\/&]+/', @$_GET['path']) ? $_GET['path'] : '');
//these two get used an awful lot
Expand Down
2 changes: 1 addition & 1 deletion themes/greyscale/append.inc.php
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<meta charset="utf-8" />
<!-- NoNonsense Forum v2 © Copyright (CC-BY) Kroc Camen 2011
<!-- NoNonsense Forum v3 © Copyright (CC-BY) Kroc Camen 2011
licensed under Creative Commons Attribution 3.0 <creativecommons.org/licenses/by/3.0/deed.en_GB>
you may do whatever you want to this code as long as you give credit to Kroc Camen, <camendesign.com> -->
<title>Append to <?php echo $HEADER['TITLE']?></title>
Expand Down
2 changes: 1 addition & 1 deletion themes/greyscale/delete.inc.php
@@ -1,6 +1,6 @@
<!DOCTYPE html>
<meta charset="utf-8" />
<!-- NoNonsense Forum v2 © Copyright (CC-BY) Kroc Camen 2011
<!-- NoNonsense Forum v3 © Copyright (CC-BY) Kroc Camen 2011
licensed under Creative Commons Attribution 3.0 <creativecommons.org/licenses/by/3.0/deed.en_GB>
you may do whatever you want to this code as long as you give credit to Kroc Camen, <camendesign.com> -->
<title><?php echo $ID ? 'Delete Post?' : 'Delete Thread?'?> <?php echo $HEADER['TITLE']?></title>
Expand Down
2 changes: 1 addition & 1 deletion themes/greyscale/index.inc.php
Expand Up @@ -11,7 +11,7 @@
}
?><!DOCTYPE html>
<meta charset="utf-8" />
<!-- NoNonsense Forum v2 © Copyright (CC-BY) Kroc Camen 2011
<!-- NoNonsense Forum v3 © Copyright (CC-BY) Kroc Camen 2011
licensed under Creative Commons Attribution 3.0 <creativecommons.org/licenses/by/3.0/deed.en_GB>
you may do whatever you want to this code as long as you give credit to Kroc Camen, <camendesign.com> -->
<title><?php echo (PATH ? PATH : safeHTML(FORUM_NAME)).(PAGE>1 ? ' # '.PAGE : '')?></title>
Expand Down
2 changes: 1 addition & 1 deletion themes/greyscale/theme.css
@@ -1,4 +1,4 @@
/* NoNonsense Forum v2 © Copyright (CC-BY) Kroc Camen 2011
/* NoNonsense Forum v3 © Copyright (CC-BY) Kroc Camen 2011
licenced under Creative Commons Attribution 3.0 <creativecommons.org/licenses/by/3.0/deed.en_GB>
you may do whatever you want to this code as long as you give credit to Kroc Camen, <camendesign.com> */
/* ====================================================================================================================== */
Expand Down
4 changes: 2 additions & 2 deletions themes/greyscale/thread.inc.php
Expand Up @@ -11,7 +11,7 @@
}
?><!DOCTYPE html>
<meta charset="utf-8" />
<!-- NoNonsense Forum v2 © Copyright (CC-BY) Kroc Camen 2011
<!-- NoNonsense Forum v3 © Copyright (CC-BY) Kroc Camen 2011
licensed under Creative Commons Attribution 3.0 <creativecommons.org/licenses/by/3.0/deed.en_GB>
you may do whatever you want to this code as long as you give credit to Kroc Camen, <camendesign.com> -->
<title><?php echo $HEADER['TITLE'].(PAGE>1 ? ' # '.PAGE : '')?></title>
Expand Down Expand Up @@ -77,7 +77,7 @@
<?php if (!$POST['DELETED']): ?><a class="ui append" rel="noindex nofollow" href="<?php echo $POST['APPEND_URL']?>">append</a>
<a class="ui delete" rel="noindex nofollow" href="<?php echo $POST['DELETE_URL']?>">delete</a><?php endif;?>
<time datetime="<?php echo $POST['DATETIME']?>" pubdate><?php echo $POST['TIME']?></time>
<a href="#<?php echo $POST['ID']?>">#<?php echo $POST['NO']?>.</a>
<a href="?page=<?php echo PAGE?>#<?php echo $POST['ID']?>">#<?php echo $POST['NO']?>.</a>
<b<?php echo $POST['MOD']?' class="mod"':''?>><?php echo $POST['AUTHOR']?></b>
</header>

Expand Down
10 changes: 9 additions & 1 deletion thread.php
@@ -1,6 +1,6 @@
<?php //display a particular thread’s contents
/* ====================================================================================================================== */
/* NoNonsense Forum v2 © Copyright (CC-BY) Kroc Camen 2011
/* NoNonsense Forum v3 © Copyright (CC-BY) Kroc Camen 2011
licenced under Creative Commons Attribution 3.0 <creativecommons.org/licenses/by/3.0/deed.en_GB>
you may do whatever you want to this code as long as you give credit to Kroc Camen, <camendesign.com>
*/
Expand Down Expand Up @@ -29,6 +29,7 @@
formatText (TEXT) == $xml->channel->item[0]->description
)) {
//where to?
//(we won’t use `page=last` here as we are effecitvely handing the user a permalink here)
$page = ceil (count ($xml->channel->item) / FORUM_POSTS);
$url = FORUM_URL.PATH_URL.$FILE.($page > 1 ? "?page=$page" : '').'#'.base_convert (microtime (), 10, 36);

Expand Down Expand Up @@ -97,6 +98,13 @@

/* replies
---------------------------------------------------------------------------------------------------------------------- */
//determine the page number (for threads the page number can be given as "last")
define ('PAGE',
@$_GET['page'] == 'last'
? ceil (count ($thread) / FORUM_POSTS)
: (preg_match ('/^[1-9][0-9]*$/', @$_GET['page']) ? (int) $_GET['page'] : 1)
);

if (count ($thread)) {
//sort the other way around
//<stackoverflow.com/questions/2119686/sorting-an-array-of-simplexml-objects/2120569#2120569>
Expand Down

0 comments on commit ca9d10b

Please sign in to comment.