Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 168 lines (141 sloc) 6.786 kb
30d7c0a Going public
Kroc Camen authored
1 <?php //display the index of threads in a folder
f32c3fc Added licence headers
Kroc Camen authored
2 /* ====================================================================================================================== */
3effc95 Major overhaul of greyscale theme. Only the index page done at this p…
Kroc Camen authored
3 /* NoNonsense Forum © Copyright (CC-BY) Kroc Camen 2011
f32c3fc Added licence headers
Kroc Camen authored
4 licenced under Creative Commons Attribution 3.0 <creativecommons.org/licenses/by/3.0/deed.en_GB>
5 you may do whatever you want to this code as long as you give credit to Kroc Camen, <camendesign.com>
6 */
080672b first commit
Kroc Camen authored
7
60bc745 Templated HTML <title> use
Kroc Camen authored
8 require_once 'shared.php';
080672b first commit
Kroc Camen authored
9
30d7c0a Going public
Kroc Camen authored
10 //submitted info for making a new thread
a6ebd33 * Moved name / password, page and path inputs to shared.php to simpli…
Kroc Camen authored
11 //(name / password already handled in 'shared.php')
166f046 * Added config options for input field limits
Kroc Camen authored
12 define ('TITLE', mb_substr (trim (@$_POST['title']), 0, SIZE_TITLE, 'UTF-8'));
13 define ('TEXT', mb_substr (trim (@$_POST['text'] ), 0, SIZE_TEXT, 'UTF-8'));
080672b first commit
Kroc Camen authored
14
0dd54c8 * Added ie.css for IE-specific fixes, which undoubtedly there will be…
Kroc Camen authored
15 /* ====================================================================================================================== */
16
6578661 Moved RSS to static generation. Fixes #13
Kroc Camen authored
17 //has the user submitted a new thread? (and is the info valid?)
0dd54c8 * Added ie.css for IE-specific fixes, which undoubtedly there will be…
Kroc Camen authored
18 if (FORUM_ENABLED && NAME && PASS && AUTH && TITLE && TEXT && @$_POST['email'] == 'example@abc.com') {
6578661 Moved RSS to static generation. Fixes #13
Kroc Camen authored
19 //the file on disk is a simplified version of the title:
2c2f013 * CSS gradient for Opera 11.10
Kroc Camen authored
20 $c = 0; do $file = preg_replace (
816fefd Removed need for `flattenTitle` function
Kroc Camen authored
21 //replace non alphanumerics with underscores and don’t use more than 2 in a row
22 array ('/[^_a-z0-9-]/i', '/_{2,}/'), '_',
d503f28 Moved RSS templates out of theme.php in preparation of a. moving RSS …
Kroc Camen authored
23 //remove the additional characters added by transliteration, e.g. "ñ" = "~n",
24 //has the added benefit of converting “microsoft's” to “microsofts” instead of “microsoft_s”
25 str_replace (array ("'", "`", "^", "~", "'", '"'), '', strtolower (
26 //unaccent: <php.net/manual/en/function.iconv.php>
2c4fca7 Transliterate accents in title to generate file name, as per suggesti…
Kroc Camen authored
27 iconv ('UTF-8', 'US-ASCII//IGNORE//TRANSLIT', TITLE)
d503f28 Moved RSS templates out of theme.php in preparation of a. moving RSS …
Kroc Camen authored
28 //if a thread already exsits with that name, append a number until an available filename is found
29 )).($c++ ? '_'.($c-1) : '')
2c2f013 * CSS gradient for Opera 11.10
Kroc Camen authored
30 );
a9c221c WARNING: Changed thread files to ".rss" extension (instead of ".xml")…
Kroc Camen authored
31 while (file_exists ("$file.rss"));
2d832fc <title> to match thread / folder, moved user authentication to a func…
Kroc Camen authored
32
33 //write out the new thread as an RSS file
a9c221c WARNING: Changed thread files to ".rss" extension (instead of ".xml")…
Kroc Camen authored
34 file_put_contents ("$file.rss", template_tags (<<<XML
d503f28 Moved RSS templates out of theme.php in preparation of a. moving RSS …
Kroc Camen authored
35 <?xml version="1.0" encoding="utf-8" ?>
36 <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
37 <channel>
a9c221c WARNING: Changed thread files to ".rss" extension (instead of ".xml")…
Kroc Camen authored
38 <atom:link href="http://${_SERVER['HTTP_HOST']}&__URL__;.rss" rel="self" type="application/rss+xml" />
d503f28 Moved RSS templates out of theme.php in preparation of a. moving RSS …
Kroc Camen authored
39 <title>&__TITLE__;</title>
40 <link>http://${_SERVER['HTTP_HOST']}&__URL__;</link>
41
42 <item>
43 <title>&__TITLE__;</title>
8b29bca * Unique post IDs, fixes #2
Kroc Camen authored
44 <link>http://${_SERVER['HTTP_HOST']}&__URL__;#&__ID__;</link>
d503f28 Moved RSS templates out of theme.php in preparation of a. moving RSS …
Kroc Camen authored
45 <author>&__NAME__;</author>
46 <pubDate>&__DATE__;</pubDate>
47 <description>&__TEXT__;</description>
48 </item>
49
50 </channel>
51 </rss>
52 XML
53 , array (
a6ebd33 * Moved name / password, page and path inputs to shared.php to simpli…
Kroc Camen authored
54 'TITLE' => safeHTML (TITLE),
8b29bca * Unique post IDs, fixes #2
Kroc Camen authored
55 'URL' => PATH_URL.$file,
a6ebd33 * Moved name / password, page and path inputs to shared.php to simpli…
Kroc Camen authored
56 'NAME' => safeHTML (NAME),
139e33e commented template.php to help anybody making their own skin. fixed a…
Kroc Camen authored
57 'DATE' => gmdate ('r'),
a6ebd33 * Moved name / password, page and path inputs to shared.php to simpli…
Kroc Camen authored
58 'TEXT' => safeHTML (formatText (TEXT)),
8b29bca * Unique post IDs, fixes #2
Kroc Camen authored
59 'ID' => base_convert (microtime (), 10, 36)
2d832fc <title> to match thread / folder, moved user authentication to a func…
Kroc Camen authored
60 )));
6578661 Moved RSS to static generation. Fixes #13
Kroc Camen authored
61
62 //regenerate the folder's RSS file
63 indexRSS ();
2d832fc <title> to match thread / folder, moved user authentication to a func…
Kroc Camen authored
64
65 //redirect to newley created thread
a6ebd33 * Moved name / password, page and path inputs to shared.php to simpli…
Kroc Camen authored
66 header ('Location: '.FORUM_URL.PATH_URL.$file, true, 303);
df46ef5 Added `clearstatcache` to avoid ordering problems on the index, with …
Kroc Camen authored
67 exit;
080672b first commit
Kroc Camen authored
68 }
69
c1d01c4 All HTML moved to a separate file so people can easily make their own…
Kroc Camen authored
70 /* ====================================================================================================================== */
71
0dd54c8 * Added ie.css for IE-specific fixes, which undoubtedly there will be…
Kroc Camen authored
72 //information for the site header:
6e93975 in progress…
Kroc Camen authored
73 $HEADER = array (
ace4ac2 Page list on the index page.
Kroc Camen authored
74 'PATH' => safeHTML (PATH), //the current sub-folder, if any
75 'PAGE' => PAGE //the current page number
6e93975 in progress…
Kroc Camen authored
76 );
c1d01c4 All HTML moved to a separate file so people can easily make their own…
Kroc Camen authored
77
30d7c0a Going public
Kroc Camen authored
78 //get a list of folders
6e93975 in progress…
Kroc Camen authored
79 foreach (array_filter (
56a2b01 Renamed "theme" to "themes", and put C=64 theme in its own folder. Ad…
Kroc Camen authored
80 //include only directories, but ignore directories starting with ‘.’ and the users / themes folders
81 preg_grep ('/^(\.|users$|themes$)/', scandir ('.'), PREG_GREP_INVERT), 'is_dir'
3965049 Add latest author / timestamp to the sub forum names. Fixes #43
Kroc Camen authored
82 ) as $FOLDER) {
83 chdir ($FOLDER);
84
85 //get a list of files in the folder to determine which one is newest
86 $threads = preg_grep ('/\.rss$/', scandir ('.'));
87 //order by last modified date
88 array_multisort (array_map ('filemtime', $threads), SORT_DESC, $threads);
89
90 //read the newest thread (folder could be empty though)
91 $last = ($xml = @simplexml_load_file ($threads[0])) ? $xml->channel->item[0] : '';
92
93 $FOLDERS[] = array (
94 'URL' => '/'.rawurlencode ($FOLDER).'/',
95 'NAME' => safeHTML ($FOLDER),
96 //can’t include these details if the folder was empty
97 'DATETIME' => !$last ? '' : date ('c', strtotime ($last->pubDate)),
98 'TIME' => !$last ? '' : date (DATE_FORMAT, strtotime ($last->pubDate)),
99 'AUTHOR' => !$last ? '' : safeHTML ($last->author)
100 );
101
102 chdir ('..');
103 }
080672b first commit
Kroc Camen authored
104
0dd54c8 * Added ie.css for IE-specific fixes, which undoubtedly there will be…
Kroc Camen authored
105 //get list of threads (if any--could be an empty folder)
a9c221c WARNING: Changed thread files to ".rss" extension (instead of ".xml")…
Kroc Camen authored
106 if ($threads = preg_grep ('/\.rss$/', scandir ('.'))) {
0dd54c8 * Added ie.css for IE-specific fixes, which undoubtedly there will be…
Kroc Camen authored
107 //order by last modified date
108 array_multisort (array_map ('filemtime', $threads), SORT_DESC, $threads);
109
30d7c0a Going public
Kroc Camen authored
110 //does this folder have a sticky list?
111 $stickies = array ();
60bc745 Templated HTML <title> use
Kroc Camen authored
112 if (file_exists ('sticky.txt')) {
ebc5145 Cleaned up and fixed major bug with stickies causing threads to disap…
Kroc Camen authored
113 //get sticky list, trimming any files that no longer exist
114 $stickies = array_intersect (file ('sticky.txt', FILE_IGNORE_NEW_LINES + FILE_SKIP_EMPTY_LINES), $threads);
30d7c0a Going public
Kroc Camen authored
115
ebc5145 Cleaned up and fixed major bug with stickies causing threads to disap…
Kroc Camen authored
116 //order the stickies by reverse date order
117 array_multisort (array_map ('filemtime', $stickies), SORT_DESC, $stickies);
6bd1520 Broke stickies in that last push. Will I ever push without errors? I …
Kroc Camen authored
118
11f1590 Tell a lie… bug wasn’t fixed :P
Kroc Camen authored
119 //remove the stickies from the thread list
120 $threads = array_diff ($threads, $stickies);
30d7c0a Going public
Kroc Camen authored
121 }
080672b first commit
Kroc Camen authored
122
30d7c0a Going public
Kroc Camen authored
123 //paging (stickies are not included in the count as they appear on all pages)
0dd54c8 * Added ie.css for IE-specific fixes, which undoubtedly there will be…
Kroc Camen authored
124 $PAGES = pageList (PAGE, ceil ((count ($threads) - count ($stickies)) / FORUM_THREADS));
125 //slice the full list into the current page
a6ebd33 * Moved name / password, page and path inputs to shared.php to simpli…
Kroc Camen authored
126 $threads = array_merge ($stickies, array_slice ($threads, (PAGE-1) * FORUM_THREADS, FORUM_THREADS));
c1d01c4 All HTML moved to a separate file so people can easily make their own…
Kroc Camen authored
127
0dd54c8 * Added ie.css for IE-specific fixes, which undoubtedly there will be…
Kroc Camen authored
128 //generate the list of threads with data, for the template
ebc5145 Cleaned up and fixed major bug with stickies causing threads to disap…
Kroc Camen authored
129 foreach ($threads as $file) {
0dd54c8 * Added ie.css for IE-specific fixes, which undoubtedly there will be…
Kroc Camen authored
130 //read the file, and refer to the last post made (the first item in RSS feed as newest is first)
30d7c0a Going public
Kroc Camen authored
131 $xml = simplexml_load_file ($file);
ebc5145 Cleaned up and fixed major bug with stickies causing threads to disap…
Kroc Camen authored
132 $last = &$xml->channel->item[0];
30d7c0a Going public
Kroc Camen authored
133
7dd053d Fixes #48: Combine $THREADS and $STICKIES into one, use flag to diffe…
Kroc Camen authored
134 $THREADS[] = array (
135 'STICKY' => in_array ($file, $stickies),
0dd54c8 * Added ie.css for IE-specific fixes, which undoubtedly there will be…
Kroc Camen authored
136 //link to the thread--go to the last page of replies
8b29bca * Unique post IDs, fixes #2
Kroc Camen authored
137 'URL' => pathinfo ($file, PATHINFO_FILENAME).(count ($xml->channel->item) > FORUM_POSTS+1
7dd053d Fixes #48: Combine $THREADS and $STICKIES into one, use flag to diffe…
Kroc Camen authored
138 ? '?page='.ceil ((count ($xml->channel->item) - 1) / FORUM_POSTS) : ''
816fefd Removed need for `flattenTitle` function
Kroc Camen authored
139 ),
140 'TITLE' => safeHTML ($xml->channel->title),
141 'COUNT' => count ($xml->channel->item),
0dd54c8 * Added ie.css for IE-specific fixes, which undoubtedly there will be…
Kroc Camen authored
142 'DATETIME' => date ('c', strtotime ($last->pubDate)), //HTML5 datetime attr
143 'TIME' => date (DATE_FORMAT, strtotime ($last->pubDate)), //human readable
816fefd Removed need for `flattenTitle` function
Kroc Camen authored
144 'AUTHOR' => safeHTML ($last->author)
6e93975 in progress…
Kroc Camen authored
145 );
30d7c0a Going public
Kroc Camen authored
146 }
147 }
080672b first commit
Kroc Camen authored
148
6078039 Added moderators (mods.txt), thread deletion, and changed usernames t…
Kroc Camen authored
149 /* ---------------------------------------------------------------------------------------------------------------------- */
150
0dd54c8 * Added ie.css for IE-specific fixes, which undoubtedly there will be…
Kroc Camen authored
151 //the new thread input form (exclude if posting has been disabled)
5fcc000 index and thread pages templated. delete and rss to do.
Kroc Camen authored
152 if (FORUM_ENABLED) $FORM = array (
a6ebd33 * Moved name / password, page and path inputs to shared.php to simpli…
Kroc Camen authored
153 'NAME' => safeString (NAME),
154 'PASS' => safeString (PASS),
155 'TITLE' => safeString (TITLE),
5fcc000 index and thread pages templated. delete and rss to do.
Kroc Camen authored
156 'TEXT' => safeHTML (TEXT),
3effc95 Major overhaul of greyscale theme. Only the index page done at this p…
Kroc Camen authored
157 'ERROR' => empty ($_POST) ? ERROR_NONE //no problem? show default help text
6578661 Moved RSS to static generation. Fixes #13
Kroc Camen authored
158 : (!NAME ? ERROR_NAME //the name is missing
159 : (!PASS ? ERROR_PASS //the password is missing
160 : (!TITLE ? ERROR_TITLE //the title is missing
161 : (!TEXT ? ERROR_TEXT //the message text is missing
162 : ERROR_AUTH)))) //the name / password pair didn’t match
5fcc000 index and thread pages templated. delete and rss to do.
Kroc Camen authored
163 );
c1d01c4 All HTML moved to a separate file so people can easily make their own…
Kroc Camen authored
164
5fcc000 index and thread pages templated. delete and rss to do.
Kroc Camen authored
165 //all the data prepared, now output the HTML
166 include 'themes/'.FORUM_THEME.'/index.inc.php';
c1d01c4 All HTML moved to a separate file so people can easily make their own…
Kroc Camen authored
167
168 ?>
Something went wrong with that request. Please try again.