From 96495504631d6a4d466b93a835d7d66853e2e12b Mon Sep 17 00:00:00 2001 From: Michael Save Date: Fri, 13 Apr 2012 02:11:41 +1000 Subject: [PATCH] start on mod interface rewrite --- inc/functions.php | 7 +- .../Twig/Extensions/Extension/Tinyboard.php | 2 +- inc/mod-old.php | 287 ++ inc/mod.php | 278 +- inc/mod/auth.php | 124 + inc/mod/pages.php | 132 + mod-old.php | 3128 ++++++++++++++++ mod.php | 3138 +---------------- templates/index.html | 6 +- templates/login.html | 27 - templates/thread.html | 6 +- 11 files changed, 3724 insertions(+), 3411 deletions(-) create mode 100644 inc/mod-old.php create mode 100644 inc/mod/auth.php create mode 100644 inc/mod/pages.php create mode 100644 mod-old.php delete mode 100644 templates/login.html diff --git a/inc/functions.php b/inc/functions.php index 66fadd5e..34084bd5 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -277,10 +277,13 @@ function setupBoard($array) { $board = array( 'uri' => $array['uri'], - 'name' => $array['title'], - 'title' => $array['subtitle'] + 'title' => $array['title'], + 'subtitle' => $array['subtitle'] ); + // older versions + $board['name'] = &$board['title']; + $board['dir'] = sprintf($config['board_path'], $board['uri']); $board['url'] = sprintf($config['board_abbreviation'], $board['uri']); diff --git a/inc/lib/Twig/Extensions/Extension/Tinyboard.php b/inc/lib/Twig/Extensions/Extension/Tinyboard.php index 7e2149e5..cbb2e752 100644 --- a/inc/lib/Twig/Extensions/Extension/Tinyboard.php +++ b/inc/lib/Twig/Extensions/Extension/Tinyboard.php @@ -64,7 +64,7 @@ function twig_date_filter($date, $format) { return strftime($format, $date); } -function twig_hasPermission_filter($mod, $permission, $board) { +function twig_hasPermission_filter($mod, $permission, $board = false) { return hasPermission($permission, $board, $mod); } diff --git a/inc/mod-old.php b/inc/mod-old.php new file mode 100644 index 00000000..9065bb82 --- /dev/null +++ b/inc/mod-old.php @@ -0,0 +1,287 @@ +bindValue(':username', $username); + $query->bindValue(':password', $password); + $query->execute() or error(db_error($query)); + + if ($user = $query->fetch()) { + return $mod = Array( + 'id' => $user['id'], + 'type' => $user['type'], + 'username' => $username, + 'hash' => mkhash($username, $password), + 'boards' => explode(',', $user['boards']) + ); + } else return false; +} + +function setCookies() { + global $mod, $config; + if (!$mod) + error('setCookies() was called for a non-moderator!'); + + setcookie($config['cookies']['mod'], + $mod['username'] . // username + ':' . + $mod['hash'][0] . // password + ':' . + $mod['hash'][1], // salt + time() + $config['cookies']['expire'], $config['cookies']['jail'] ? $config['cookies']['path'] : '/', null, false, true); +} + +function destroyCookies() { + global $config; + // Delete the cookies + setcookie($config['cookies']['mod'], 'deleted', time() - $config['cookies']['expire'], $config['cookies']['jail']?$config['cookies']['path'] : '/', null, false, true); +} + +function create_pm_header() { + global $mod; + $query = prepare("SELECT `id` FROM `pms` WHERE `to` = :id AND `unread` = 1"); + $query->bindValue(':id', $mod['id'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + if ($pm = $query->fetch()) { + return Array('id' => $pm['id'], 'waiting' => $query->rowCount() - 1); + } + + return false; +} + +function modLog($action, $_board=null) { + global $mod, $board, $config; + $query = prepare("INSERT INTO `modlogs` VALUES (:id, :ip, :board, :time, :text)"); + $query->bindValue(':id', $mod['id'], PDO::PARAM_INT); + $query->bindValue(':ip', $_SERVER['REMOTE_ADDR']); + $query->bindValue(':time', time(), PDO::PARAM_INT); + $query->bindValue(':text', $action); + if (isset($_board)) + $query->bindValue(':board', $_board); + elseif (isset($board)) + $query->bindValue(':board', $board['uri']); + else + $query->bindValue(':board', null, PDO::PARAM_NULL); + $query->execute() or error(db_error($query)); + + if ($config['syslog']) + _syslog(LOG_INFO, '[mod/' . $mod['username'] . ']: ' . $action); +} + +// Generates a