//no last post, remove the template for it $item->remove('.nnf_subforum-post'); } //attach the templated sub-forum item to the list $item->next(); chdir('..'); } } else { //no sub-forums, remove the template stuff $template->remove('#nnf_folders'); } /* threads ---------------------------------------------------------------------------------------------------------------------- */ if ($threads || $stickies) { //do the page links (stickies are not included in the count as they appear on all pages) theme_pageList($template, PATH_URL, $PAGE, $PAGES); //slice the full list into the current page $threads = array_merge($stickies, array_slice($threads, ($PAGE - 1) * FORUM_THREADS, FORUM_THREADS)); //get the dummy list-item to repeat (removes it and takes a copy) $item = $template->repeat('.nnf_thread'); //generate the list of threads with data, for the template foreach ($threads as $file) { if ($xml = @simplexml_load_file($file)) { //is the thread sticky? if (in_array($file, $stickies)) { $item->addClass('.', 'sticky'); } //get the last post in the thread $last =& $xml->channel->item[0]; //apply the data to the template $item->set(array('a.nnf_thread-name' => $xml->channel->title, 'a.nnf_thread-name@href' => pathinfo($file, PATHINFO_FILENAME), '.nnf_thread-replies' => count($xml->channel->item) - 1, 'a.nnf_thread-post@href' => substr($last->link, strpos($last->link, '/', 9)), 'time.nnf_thread-time' => date(DATE_FORMAT, strtotime($last->pubDate)), 'time.nnf_thread-time@datetime' => date('c', strtotime($last->pubDate)), '.nnf_thread-author' => $last->author))->remove(array('.nnf_thread-locked' => !$xml->channel->xpath("category[.='locked']"), '.nnf_thread-sticky' => !in_array($file, $stickies) || $xml->channel->xpath("category[.='locked']")));
//no last post, remove the template for it $item->remove('.nnf_subforum-post'); } //attach the templated sub-forum item to the list $item->next(); chdir('..'); } } else { //no sub-forums, remove the template stuff $template->remove('#nnf_folders'); } /* threads ---------------------------------------------------------------------------------------------------------------------- */ if ($threads || @$stickies) { //do the page links (stickies are not included in the count as they appear on all pages) theme_pageList($template, '', $PAGE, $PAGES); //slice the full list into the current page $threads = array_merge($stickies, array_slice($threads, ($PAGE - 1) * FORUM_THREADS, FORUM_THREADS)); //get the dummy list-item to repeat (removes it and takes a copy) $item = $template->repeat('.nnf_thread'); //generate the list of threads with data, for the template foreach ($threads as $file) { if ($xml = @simplexml_load_file($file)) { if ($last =& $xml->channel->item[0]) { $item->set(array('a.nnf_thread-name' => $xml->channel->title, 'a.nnf_thread-name@href' => url(PATH_URL, pathinfo($file, PATHINFO_FILENAME)), '.nnf_thread-replies' => count($xml->channel->item) - 1, 'a.nnf_thread-post@href' => substr($last->link, strpos($last->link, '/', 9)), 'time.nnf_thread-time' => date(DATE_FORMAT, strtotime($last->pubDate)), 'time.nnf_thread-time@datetime' => date('c', strtotime($last->pubDate)), '.nnf_thread-author' => $last->author))->remove(array('.nnf_thread-locked' => !$xml->channel->xpath('category[.="locked"]'), './@class' => !in_array($file, $stickies) ? 'nnf_sticky' : false, '.nnf_thread-sticky' => !in_array($file, $stickies) || $xml->channel->xpath('category[.="locked"]'), '.nnf_thread-author@class' => !isMod($last->author) ? 'nnf_mod' : false))->next(); } } } } else { //no threads, remove the template stuff $template->remove('#nnf_threads');
//append / delete links? if (!CAN_REPLY) { $template->remove('#nnf_post-append', '#nnf_post-delete'); } /* replies ---------------------------------------------------------------------------------------------------------------------- */ if (count($thread)) { //sort the other way around //<stackoverflow.com/questions/2119686/sorting-an-array-of-simplexml-objects/2120569#2120569> foreach ($thread as &$node) { $sort[] = strtotime($node->pubDate); } array_multisort($sort, SORT_ASC, $thread); //do the page links //(`theme_pageList` is defined in 'theme.config.php' if it exists, otherwise 'theme.config.default.php') $template->setHTML('.nnf_pages', theme_pageList(PAGE, ceil(count($thread) / FORUM_POSTS))); //slice the full list into the current page $thread = array_slice($thread, (PAGE - 1) * FORUM_POSTS, FORUM_POSTS); //get the dummy list-item to repeat (removes it and takes a copy) $item = $template->repeat('.nnf_reply'); //index number of the replies, accounting for which page we are on $no = (PAGE - 1) * FORUM_POSTS; foreach ($thread as &$reply) { //has the reply been deleted (blanked)? if ($reply->xpath("category[text()='deleted']")) { $item->addClass('.', 'deleted'); } //apply the data to the template (a reply) $item->set(array('./@id' => substr(strstr($reply->link, '#'), 1), 'time.nnf_reply-time' => date(DATE_FORMAT, strtotime($reply->pubDate)), 'time.nnf_reply-time@datetime' => gmdate('r', strtotime($reply->pubDate)), 'a.nnf_reply-number' => sprintf(THEME_REPLYNO, ++$no), 'a.nnf_reply-number@href' => '?page=' . PAGE . strstr($reply->link, '#'), '.nnf_reply-author' => $reply->author, 'a.nnf_reply-append@href' => '?append=' . substr(strstr($reply->link, '#'), 1) . '#append', 'a.nnf_reply-delete@href' => '?delete=' . substr(strstr($reply->link, '#'), 1)))->setHTML('.nnf_reply-text', $reply->description); //is this reply from the person who started the thread? if (strtolower($reply->author) == strtolower($author)) {
//remove the append button $template->remove('#nnf_post-append'); } /* replies ---------------------------------------------------------------------------------------------------------------------- */ if (!count($thread)) { $template->remove('#nnf_replies'); } else { //sort the other way around //<stackoverflow.com/questions/2119686/sorting-an-array-of-simplexml-objects/2120569#2120569> foreach ($thread as &$node) { $sort[] = strtotime($node->pubDate); } array_multisort($sort, SORT_ASC, $thread); //do the page links theme_pageList($template, $FILE, $PAGE, $PAGES); //slice the full list into the current page $thread = array_slice($thread, ($PAGE - 1) * FORUM_POSTS, FORUM_POSTS); //get the dummy list-item to repeat (removes it and takes a copy) $item = $template->repeat('.nnf_reply'); //index number of the replies, accounting for which page we are on $no = ($PAGE - 1) * FORUM_POSTS; //apply the data to the template (a reply) foreach ($thread as &$reply) { $item->set(array('./@id' => substr(strstr($reply->link, '#'), 1), 'time.nnf_reply-time' => date(DATE_FORMAT, strtotime($reply->pubDate)), 'time.nnf_reply-time@datetime' => gmdate('r', strtotime($reply->pubDate)), '.nnf_reply-author' => $reply->author, 'a.nnf_reply-number' => sprintf(THEME_REPLYNO, ++$no), 'a.nnf_reply-number@href' => url('thread', PATH_URL, $FILE, $PAGE) . strstr($reply->link, '#'), 'a.nnf_reply-append@href' => url('append', PATH_URL, $FILE, $PAGE, substr(strstr($reply->link, '#'), 1)) . '#append', 'a.nnf_reply-delete@href' => url('delete', PATH_URL, $FILE, $PAGE, substr(strstr($reply->link, '#'), 1))))->remove(array('./@class' => $reply->xpath('category[.="deleted"]') ? false : 'nnf_deleted'))->remove(array('./@class' => strtolower($reply->author) == strtolower($author) ? false : 'nnf_op'))->remove(array('./@class, .nnf_reply-author@class' => isMod($reply->author) ? false : 'mod'))->remove(array('.nnf_reply-append, .nnf_reply-delete' => !(CAN_REPLY && (IS_MOD || !AUTH_HTTP || strtolower(NAME) == strtolower($reply->author) && (!FORUM_LOCK || FORUM_LOCK == 'threads' || IS_MEMBER))), '.nnf_reply-append' => $reply->xpath('category[.="deleted"]'), '.nnf_reply-delete' => $reply->xpath('category[.="deleted"]') && !IS_MOD)); //insert the post-text, dealing with an invalid HTML error try { $item->setValue('.nnf_reply-text', $reply->description, true); $item->remove(array('./@class' => 'nnf_error')); } catch (Exception $e) { //if the HTML was invalid, replace with the corruption message
---------------------------------------------------------------------------------------------------------------------- */ //get list of threads (if any--could be an empty folder) if ($threads = preg_grep('/\\.rss$/', scandir('.'))) { //order by last modified date array_multisort(array_map('filemtime', $threads), SORT_DESC, $threads); //get sticky list, trimming any files that no longer exist //(the use of `array_intersect` will only return filenames in `sticky.txt` that were also in the directory) if ($stickies = array_intersect(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); } //do the page links (stickies are not included in the count as they appear on all pages) //(`theme_pageList` is defined in 'theme.config.php' if it exists, otherwise 'theme.config.default.php') $template->setHTML('.nnf_pages', theme_pageList(PAGE, ceil(count($threads) / FORUM_THREADS))); //slice the full list into the current page $threads = array_merge($stickies, array_slice($threads, (PAGE - 1) * FORUM_THREADS, FORUM_THREADS)); //get the dummy list-item to repeat (removes it and takes a copy) $item = $template->repeat('.nnf_thread'); //generate the list of threads with data, for the template foreach ($threads as $file) { if ($xml = @simplexml_load_file($file)) { //is the thread sticky? if (in_array($file, $stickies)) { $item->addClass('.', 'sticky'); } //if the thread isn’t locked, remove the lock icon if (!$xml->channel->xpath("category[text()='locked']")) { $item->remove('.nnf_thread-locked'); }