public function countSubThreads($topicid) { $counter = 0; // go through every thread foreach ($this->threads as $thread) { if ($thread->getTopTopic() == $topicid) { if ($thread->getThreadState() != forumtools::$THREADHIDDEN || usertools::containRoles($GLOBALS["adminRoles"], $_SESSION["user"]->getRoles())) { $counter += 1; } $counter += $this->countSubThreads($thread->getId()); } } return $counter; }
<?php /** * Code for the most sites for the beginning... */ require_once 'config.php'; require_once 'class/user.php'; require_once 'class/smarty/Smarty.class.php'; $template = new Smarty(); session_start(); if (!isset($_SESSION["user"]) && basename($_SERVER['PHP_SELF']) != "login.php") { header("Location: login.php"); } else { if (isset($_SESSION["user"]) && usertools::containRoles($GLOBALS["adminRoles"], $_SESSION["user"]->getRoles())) { $template->assign("admin", true); } } $messages = array(); try { $connection = new PDO($GLOBALS["db_type"] . ':dbname=' . $GLOBALS["db_dbname"] . ';host=' . $GLOBALS["db_host"] . '', $GLOBALS["db_loginname"], $GLOBALS["db_loginpassword"]); } catch (PDOException $e) { array_push($messages, $e->getMessage()); }
public function start() { require_once $this->folder . "forum.class.php"; $this->connection->exec("CREATE TABLE IF NOT EXISTS `" . $this->getDbPrefix() . "forum_threads` (\n\t\t\t`forumid` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t`userid` int(11) NOT NULL,\n\t\t\t`title` text NOT NULL,\n\t\t\t`text` text NOT NULL,\n\t\t\t`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t`toptopic` int(11) NOT NULL,\n\t\t\t`threadstate` int(5) NOT NULL DEFAULT '0',\n\t\t\t`editcounter` int(5) NOT NULL DEFAULT '0',\n\t\t\tPRIMARY KEY (`forumid`)\n\t\t)"); $template = $this->templateObject; $template->addTemplateDir($this->folder . "forum/"); $connection = $this->connection; // $template -> assign("allcss", $this->folder."forum/css/sprrtrteech.css"); $template->assign("pluginId", $_GET['plugin']); $template->assign("folder", $this->folder); $template->assign("ownuserid", $this->currentUser->getId()); $threads = new allThreads($connection, $_SESSION["user"], $this->getDbPrefix()); switch ($_GET['action']) { case "createthread": $dojorequire = array("dijit.Editor", "dojo.parser"); $template->assign("dojorequire", $dojorequire); $template->assign("savemethod", "new"); return $template->fetch($this->folder . 'forumPlugin_createThread.tpl'); break; case "reply": $thread = $threads->getThreadById($_GET['threadid']); if (!is_null($thread)) { $dojorequire = array("dijit.Editor", "dojo.parser"); $template->assign("dojorequire", $dojorequire); $template->assign("threadid", $thread->getId()); $template->assign("threadtitle", $thread->getTitle()); $template->assign("savemethod", "reply"); return $template->fetch($this->folder . 'forumPlugin_reply.tpl'); } break; case "deletethread": if (!empty($_GET['threadid'])) { $threads->deleteThread($_GET['threadid'], true); } break; case "editthread": $thread = $threads->getThreadById($_GET['threadid']); if (!is_null($thread)) { if ($thread->getUserId() == $this->currentUser->getId() || usertools::containRoles($GLOBALS["adminRoles"], $_SESSION["user"]->getRoles())) { $dojorequire = array("dijit.Editor", "dojo.parser"); $template->assign("dojorequire", $dojorequire); $template->assign("threadid", $thread->getId()); $template->assign("savemethod", "edit"); $template->assign("threadtitle", $thread->getTitle()); $template->assign("title", $thread->getTitle()); $template->assign("text", $thread->getText()); return $template->fetch($this->folder . 'forumPlugin_edit.tpl'); } else { $template->assign("errorTitle", "You haven't enough rights or the thread doesn't exist"); $template->assign("errorDescription", "Please check your roles and verify that this thread exists!"); $template->display('error.tpl'); die; } } break; case "savethread": if (!empty($_POST['topictitle']) && !empty($_POST['topictext']) && $_GET['savemethod'] == "new") { $threads->createNewThread($_POST['topictitle'], $_POST['topictext']); $template->assign('threads', $threads->getAllTopThreads()); //array_push($messages, "Thread opened"); $template->assign('messages', $messages); return $template->fetch($this->folder . 'forumPlugin.tpl'); break; } else { if (!empty($_POST['topictext']) && !empty($_GET['threadid'])) { $thread = $threads->getThreadById($_GET['threadid']); if (!is_null($thread) && ($thread->getThreadState() == forumtools::$THREADACTIVE || $admin) || $allowedAccess == "Admin") { if (empty($_POST['topictitle'])) { $_POST['topictitle'] = ""; } if ($_GET['savemethod'] == "reply") { // threadid means here the topthreadid $threads->createNewThread($_POST['topictitle'], $_POST['topictext'], $_GET['threadid']); } else { if ($_GET['savemethod'] == "edit") { $threads->editThread($_POST['topictitle'], $_POST['topictext'], $thread->getEditCounter() + 1, $_GET['threadid']); $threads->changeThreadState($thread->getId(), $_POST['state']); } } } } else { $template->assign('errorTitle', _("No data submitted")); $template->assign('errorDescription', _("Please use the normal form")); return $template->fetch('error.tpl'); break; } } header("Location: plugin.php?plugin=" . $_GET['plugin'] . "&action=showthread&threadid=" . $threads->getTopThreadId($_GET['threadid'])); break; case "showthread": if (!empty($_GET['threadid'])) { $thread = $threads->getThreadById($_GET['threadid']); if (!is_null($thread) && ($thread->getThreadState() != forumtools::$THREADHIDDEN || $admin) || $allowedAccess == "Admin") { $template->assign('threadTitle', $thread->getTitle()); $template->assign('threadText', $thread->getText()); $template->assign('threadage', $thread->getTimestamp()); $template->assign('threadid', $thread->getId()); $template->assign('username', $thread->getUsername()); $template->assign('userid', $thread->getUserId()); if (isset($user)) { $template->assign('ownuserid', $user->getId()); } $subthreads = $threads->getSubThreads($thread->getId(), $admin); $template->assign('subthreads', $subthreads); return $template->fetch($this->folder . 'forumPlugin_view.tpl'); } else { $template->assign('errorTitle', _("No thread found by this id!")); $template->assign('errorDescription', _("There was no thread with this id.")); return $template->fetch('error.tpl'); } } else { $template->assign('errorTitle', _("No thread-id was given")); $template->assign('errorDescription', _("There was no id for a thread!")); return $template->fetch('error.tpl'); } break; default: $template->assign('show', $_POST['topictext']); $template->assign('threads', $threads->getAllTopThreads()); return $template->fetch($this->folder . '/forumPlugin.tpl'); } }