I’m working on a file based commenting system with in-line comments (only 1 level).
Despite being a newby I’ve managed to create a system in which users are able to add new comments and use @[NUMBER] to add their reply below another comment.
My file and folder structure looks like this:
/threads/
1/
1.txt
2.txt
3.txt
2/
1.txt
3/
1.txt
2.txt
3.txt
4.txt
The folder in threads has the thread number (used to make a reply) for its name and 1.txt contains the contents of the “mother” post. Every post higher than 1 is a reply.
So I could show the threads in the order which they have been made or show them upside down, but they’ll be stuck in that order (I’m using a loop to find folders and then increase or decrease the folder number). Does anybody have any ideas on how I can make threads which get replies to the top of the list?
I thought of an order.txt file which has the thread numbers in a certain order and when a reply gets made to thread X the script should put X at the top of that list (or bottom, easy to inverse).
Suggestions are very much appreciated!
Well, while I don’t agree with the wisdom of doing it this particular way, the order text file seems fine enough granted depending how often your updating your threads there may be read/write lock issues.
Another option is to check the modified time for the folders and/or posts. http://php.net/manual/en/function.filemtime.php i believe would be an appropriate function.
In reference to sorting you’d need to use a sorting function. The best ideas i can come up with is when creating your array convert the modified time to a unix timestamp and use that as the array index. May need to invert the array after to show newest first but i would think that would work. I’d suggest using the mktime function in conjunction to produce a nicely formatted date/time and then use that for the index.
An alternative is storing an array within array and doing something like this: