code:
<?php

namespace Mitsuba\Admin;

/**
 * Boards
 * Manages the board directories, and settings.
 *
 * @category
 * @package
 * @author
 * @copyright
 * @license
 * @version
 * @link
 * @see
 * @since
 */
class Boards
{

    private $conn;

    private $mitsuba;

    /**
     * __construct
     * Insert description here
     *
     * @param $connection
     * @param $mitsuba
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function __construct($connection, &$mitsuba)
    {

        $this->conn = $connection;

        $this->mitsuba = $mitsuba;

    }

    /**
     * createDirectories
     * Create the board directories
     *
     * @param $board the directory to be created
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function createDirectories($board)
    {

        if (!file_exists("./" . $board)) {

            mkdir("./" . $board);

        }

        if (!file_exists("./" . $board . "/res")) {

            mkdir("./" . $board . "/res");

        }

        if (!file_exists("./" . $board . "/src")) {

            mkdir("./" . $board . "/src");

        }

        if (!file_exists("./" . $board . "/src/thumb")) {

            mkdir("./" . $board . "/src/thumb");

        }

    }

    /**
     * addBoard
     * Update the SQL database with user settings.
     *
     * @param $short The board's directory.
     * @param $type The type of board.
     * @param $name The title of the board.
     * @param $des The description under the board's masthead
     * @param $message
     * @param $bumplimit The number of posts before the OP is anchored to the bottom.
     * @param $spoilers Allow spoiler images?
     * @param $noname Forced Anonymous?
     * @param $ids Enable IDs?
     * @param $embeds Allow Embeds?
     * @param $bbcode Utilize BBcode?
     * @param $time_between_posts Cooldown timer between posts.
     * @param $time_between_threads Cooldown timer between threads.
     * @param $time_to_delete Cooldown timer before user can delete their own post.
     * @param $filesize Filesize (in bytes).
     * @param $pages Maximum number of pages to render.
     * @param $hidden Board Hidden?
     * @param $unlisted Board Unlisted?
     * @param $nodup Are duplicate images allowed?
     * @param $nofile Allow OP posts without files
     * @param $maxchars Maximum characters to allow for posts
     * @param $anonymous Default Name for users without tripcodes
     * @param $extensions Allowed extensions for the board
     * @param $catalog Enable the catalog
     * @param $captcha Enable the captcha
     * @param $overboard_boards If type is overboard, what boards to inclue
     * @param $allow_replies
     * @param $file_replies
     * @param $links
     * @param $files
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function addBoard($short, $type, $name, $des = "", $message = "", $bumplimit = 0, $spoilers = 0, $noname = 0, $ids = 0, $embeds = 0, $bbcode = 1, $time_between_posts = 20, $time_between_threads = 60, $time_to_delete = 120, $filesize = 2097152, $pages = 15, $hidden = 0, $unlisted = 0, $nodup = 0, $nofile = 0, $maxchars = 2000, $anonymous = "Anonymous", $extensions = "png,jpg,gif", $catalog = 0, $captcha = 0, $overboard_boards = "", $allow_replies = 1, $file_replies = 1, $links = "", $files = 0)
    {

        $short = $this->conn->real_escape_string(trim(str_replace("%", "_", $short), "/ "));

        $type = $this->conn->real_escape_string($type);

        $name = $this->conn->real_escape_string($name);

        $des = $this->conn->real_escape_string($des);

        $message = $this->conn->real_escape_string($message);

        $anonymous = $this->conn->real_escape_string($anonymous);

        $overboard_boards = $this->conn->real_escape_string($overboard_boards);

        $extensions = $this->conn->real_escape_string($extensions);

        $links = $this->conn->real_escape_string($links);

        if (!is_numeric($bumplimit)) {

            $bumplimit = 0;

        }

        if (!is_numeric($spoilers)) {

            $spoilers = 0;

        }

        if (!is_numeric($noname)) {

            $noname = 0;

        }

        if (!is_numeric($ids)) {

            $ids = 0;

        }

        if (!is_numeric($embeds)) {

            $embeds = 0;

        }

        if (!is_numeric($bbcode)) {

            $bbcode = 1;

        }

        if (!is_numeric($captcha)) {

            $captcha = 0;

        }

        if (!is_numeric($hidden)) {

            $hidden = 0;

        }

        if (!is_numeric($unlisted)) {

            $unlisted = 0;

        }

        if (!is_numeric($nodup)) {

            $nodup = 1;

        }

        if (!is_numeric($nofile)) {

            $nofile = 0;

        }

        if (!is_numeric($catalog)) {

            $catalog = 0;

        }

        if (!is_numeric($allow_replies)) {

            $allow_replies = 1;

        }

        if (!is_numeric($file_replies)) {

            $file_replies = 1;

        }

        if (!is_numeric($maxchars)) {

            $maxchars = 2000;

        }

        if (!is_numeric($time_between_posts)) {

            $time_between_posts = 20;

        }

        if (!is_numeric($time_between_threads)) {

            $time_between_threads = 60;

        }

        if (!is_numeric($time_to_delete)) {

            $time_to_delete = 120;

        }

        if (!is_numeric($filesize)) {

            $filesize = 2097152;

        }

        if (!is_numeric($pages)) {

            $pages = 15;

        }

        if (!is_numeric($files)) {

            $files = 15;

        }

        $result = $this->conn->query("INSERT INTO boards (short, type, name, des, message, bumplimit, spoilers, noname, ids, embeds, bbcode, time_between_posts, time_between_threads, time_to_delete, filesize, pages, hidden, unlisted, nodup, nofile, maxchars, anonymous, extensions, catalog, captcha, overboard_boards, allow_replies, file_replies, links, files) VALUES ('" . $short . "', '" . $type . "', '" . $name . "', '" . $des . "', '" . $message . "', " . $bumplimit . ", " . $spoilers . ", " . $noname . ", " . $ids . ", " . $embeds . ", " . $bbcode . ", " . $time_between_posts . ", " . $time_between_threads . ", " . $time_to_delete . ", " . $filesize . ", " . $pages . ", " . $hidden . ", " . $unlisted . ", " . $nodup . ", " . $nofile . ", " . $maxchars . ", '" . $anonymous . "', '" . $extensions . "', " . $catalog . ", " . $captcha . ", '" . $overboard_boards . "', " . $allow_replies . ", " . $file_replies . ", '" . $links . "', " . $files . ")");

        if ($result) {

            $this->createDirectories($short);

            $this->mitsuba->caching->generateView($short);

            if ($catalog == 1) {

                $this->mitsuba->caching->generateCatalog($short);

            }

            return 1;

        } else {

            return -1; //error

        }

    }

    /**
     * deleteBoard
     * Deletes the directories along with the SQL entries
     *
     * @param $short Board to be deleted
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function deleteBoard($short)
    {

        $this->conn->query("DELETE FROM boards WHERE short='" . $this->conn->real_escape_string($short) . "'");

        $this->conn->query("DELETE FROM posts WHERE board='" . $this->conn->real_escape_string($short) . "';");

        $this->mitsuba->common->delTree("./" . $short);

    }

    /**
     * updateBoard
     * Updates the board settings
     *
     * @param $short
     * @param $name
     * @param $des
     * @param $msg
     * @param $limit
     * @param $spoilers
     * @param $noname
     * @param $ids
     * @param $embeds
     * @param $bbcode
     * @param $time_between_posts
     * @param $time_between_threads
     * @param $time_to_delete
     * @param $filesize
     * @param $pages
     * @param $hidden
     * @param $unlisted
     * @param $nodup
     * @param $nofile
     * @param $maxchars
     * @param $anonymous
     * @param $extensions
     * @param $catalog
     * @param $captcha
     * @param $overboard_boards
     * @param $allow_replies
     * @param $file_replies
     * @param $links
     * @param $files
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function updateBoard($short, $name, $des, $msg, $limit = 0, $spoilers = 0, $noname = 0, $ids = 0, $embeds = 0, $bbcode = 1, $time_between_posts = 20, $time_between_threads = 60, $time_to_delete = 120, $filesize = 2097152, $pages = 15, $hidden = 0, $unlisted = 0, $nodup = 0, $nofile = 0, $maxchars = 2000, $anonymous = "Anonymous", $extensions = "png,jpg,gif", $catalog = 0, $captcha = 0, $overboard_boards = "", $allow_replies = 1, $file_replies = 1, $links = "", $files = 0)
    {
        if ($this->mitsuba->common->isBoard($short)) {
            $name = $this->conn->real_escape_string($name);
            $des = $this->conn->real_escape_string($des);
            $msg = $this->conn->real_escape_string($msg);
            $anonymous = $this->conn->real_escape_string($anonymous);
            $overboard_boards = $this->conn->real_escape_string($overboard_boards);
            $extensions = $this->conn->real_escape_string($extensions);
            $links = $this->conn->real_escape_string($links);

            if (!is_numeric($limit)) {
                $limit = 0;
            }

            if (!is_numeric($spoilers)) {
                $spoilers = 0;
            }

            if (!is_numeric($noname)) {
                $noname = 0;
            }

            if (!is_numeric($ids)) {
                $ids = 0;
            }

            if (!is_numeric($embeds)) {
                $embeds = 0;
            }

            if (!is_numeric($bbcode)) {
                $bbcode = 1;
            }

            if (!is_numeric($hidden)) {
                $hidden = 0;
            }

            if (!is_numeric($unlisted)) {
                $unlisted = 0;
            }

            if (!is_numeric($nodup)) {
                $nodup = 1;
            }

            if (!is_numeric($nofile)) {
                $nofile = 0;
            }

            if (!is_numeric($time_between_posts)) {
                $time_between_posts = 20;
            }

            if (!is_numeric($time_between_threads)) {
                $time_between_threads = 60;
            }

            if (!is_numeric($time_to_delete)) {
                $time_to_delete = 120;
            }

            if (!is_numeric($filesize)) {
                $filesize = 2097152;
            }

            if (!is_numeric($pages)) {
                $pages = 15;
            }

            if (!is_numeric($files)) {
                $files = 15;
            }

            if (!is_numeric($maxchars)) {
                $maxchars = 2000;
            }

            if (!is_numeric($catalog)) {
                $catalog = 0;
            }

            if (!is_numeric($captcha)) {
                $captcha = 0;
            }

            if (!is_numeric($allow_replies)) {
                $allow_replies = 1;
            }

            if (!is_numeric($file_replies)) {
                $file_replies = 1;
            }

            $this->conn->query("UPDATE boards SET name='" . $name . "', des='" . $des . "', message='" . $msg . "', bumplimit=" . $limit . ", spoilers=" . $spoilers . ", noname=" . $noname . ", ids=" . $ids . ", embeds=" . $embeds . ", bbcode=" . $bbcode . ", time_between_posts=" . $time_between_posts . ", time_between_threads=" . $time_between_threads . ", time_to_delete=" . $time_to_delete . ", filesize=" . $filesize . ", pages=" . $pages . ", hidden=" . $hidden . ", unlisted=" . $unlisted . ", nodup=" . $nodup . ", nofile=" . $nofile . ", maxchars=" . $maxchars . ", anonymous='" . $anonymous . "', extensions='" . $extensions . "', catalog=" . $catalog . ", captcha=" . $captcha . ", overboard_boards='" . $overboard_boards . "', allow_replies=" . $allow_replies . ", file_replies=" . $file_replies . ", links='" . $links . "', files=" . $files . " WHERE short='" . $this->conn->real_escape_string($short) . "'");
            $this->mitsuba->caching->rebuildBoardCache($short);

            if (($catalog == 0) && (file_exists("./" . $short . "/catalog.html"))) {
                unlink("./" . $short . "/catalog.html");
            }
            return 1;

        } else {
            return 0;
        }
    }

    /**
     * moveBoard
     * Insert description here
     *
     * @param $short The old directory for the board
     * @param $new The new directory for the board
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function moveBoard($short, $new)
    {

        $short = trim($short, "/ ");

        $new = trim($new, "/ ");

        if ($this->mitsuba->common->isBoard($short)) {

            if (!$this->mitsuba->common->isBoard($new)) {

                $new_e = $this->conn->real_escape_string($new);

                $short_e = $this->conn->real_escape_string($short);

                $this->conn->query("UPDATE boards SET short='" . $new_e . "' WHERE short='" . $short_e . "'");

                $this->conn->query("UPDATE posts SET board='" . $new_e . "' WHERE board='" . $short_e . "'");

                $this->conn->query("UPDATE links SET url='" . $new_e . "' WHERE url='" . $short_e . "' AND relativity=2");

                $this->mitsuba->caching->rebuildBoardLinks();

                rename("./" . $short, "./" . $new);

                $this->mitsuba->caching->rebuildBoardCache($new);

                return 1;

            } else {

                return -1; //newname exists

            }

        } else {

            return 0; //board not found

        }

    }

}

?>


code:
<?php

namespace Mitsuba\Admin;

/**
 * Groups
 * Insert description here
 *
 * @category
 * @package
 * @author
 * @copyright
 * @license
 * @version
 * @link
 * @see
 * @since
 */
class Groups
{

    private $conn;

    private $mitsuba;

    /**
     * __construct
     * Insert description here
     *
     * @param $connection
     * @param $mitsuba
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function __construct($connection, &$mitsuba)
    {

        $this->conn = $connection;

        $this->mitsuba = $mitsuba;

    }

    /**
     * isGroup
     * Insert description here
     *
     * @param $identifier
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function isGroup($identifier)
    {

        if (!is_numeric($identifier)) {

            return 0;

        }

        $result = $this->conn->query("SELECT * FROM groups WHERE id=" . $this->conn->real_escape_string($identifier));

        if ($result->num_rows == 1) {

            $row = $result->fetch_assoc();

            return $row['name'];

        } else {

            return 0;

        }

    }

    /**
     * addGroup
     * Insert description here
     *
     * @param $name
     * @param $capcode
     * @param $capcode_style
     * @param $capcode_icon
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function addGroup($name, $capcode, $capcode_style, $capcode_icon)
    {

        $name = $this->conn->real_escape_string($name);

        $capcode = $this->conn->real_escape_string($capcode);

        $capcode_style = $this->conn->real_escape_string($capcode_style);

        $capcode_icon = $this->conn->real_escape_string($capcode_icon);

        $result = $this->conn->query("INSERT INTO groups (`name`, `capcode`, `capcode_style`, `capcode_icon`) VALUES ('" . $name . "', '" . $capcode . "', '" . $capcode_style . "', '" . $capcode_icon . "')");

        if ($result) {

            return 1;

        } else {

            return 0;

        }

    }

    /**
     * updateGroup
     * Insert description here
     *
     * @param $identifier
     * @param $name
     * @param $capcode
     * @param $capcode_style
     * @param $capcode_icon
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function updateGroup($identifier, $name, $capcode, $capcode_style, $capcode_icon)
    {

        if (!is_numeric($identifier)) {

            return -1;

        }

        $group = $this->conn->query("SELECT * FROM groups WHERE id=" . $identifier);

        if ($group->num_rows == 1) {

            $group = $group->fetch_assoc();

            $name = $this->conn->real_escape_string($name);

            $capcode = $this->conn->real_escape_string($capcode);

            $capcode_style = $this->conn->real_escape_string($capcode_style);

            $capcode_icon = $this->conn->real_escape_string($capcode_icon);

            $this->conn->query("UPDATE groups SET name='" . $name . "', capcode='" . $capcode . "', capcode_style='" . $capcode_style . "', capcode_icon='" . $capcode_icon . "' WHERE id=" . $identifier);

        }

    }

    /**
     * delGroup
     * Insert description here
     *
     * @param $identifier
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function delGroup($identifier)
    {

        if (!is_numeric($identifier)) {

            return -1;

        }

        $this->conn->query("DELETE FROM groups WHERE id=" . $identifier);

        //MAYBE: delete users

    }

}

?>

license: mit


code:
<?php

namespace Mitsuba\Admin;

/**
 * Links
 * Insert description here
 *
 * @category
 * @package
 * @author
 * @copyright
 * @license
 * @version
 * @link
 * @see
 * @since
 */
class Links
{

    private $conn;

    private $mitsuba;

    /**
     * __construct
     * Insert description here
     *
     * @param $connection
     * @param $mitsuba
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function __construct($connection, &$mitsuba)
    {

        $this->conn = $connection;

        $this->mitsuba = $mitsuba;

    }

    /**
     * deleteBoardLink
     * Insert description here
     *
     * @param $identifier
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function deleteBoardLink($identifier)
    {

        if (!is_numeric($identifier)) {

            return -1;

        }

        $this->conn->query("DELETE FROM links WHERE parent=" . $identifier . ";");

        $this->conn->query("DELETE FROM links WHERE id=" . $identifier . ";");

        $this->mitsuba->caching->rebuildBoardLinks();

    }

    /**
     * addLinkCategory
     * Insert description here
     *
     * @param $name
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function addLinkCategory($name)
    {

        $allcat = $this->conn->query("SELECT * FROM links WHERE url='' AND parent=-1  ORDER BY short ASC, title ASC, id DESC;");

        $catnum = $allcat->num_rows;

        $name = $this->conn->real_escape_string($name);

        $this->conn->query("INSERT INTO links (parent, url, relative, title, short) VALUES (-1, '', 0, '" . $name . "', 'c" . ($catnum + 1) . "');");

        $this->mitsuba->caching->rebuildBoardLinks();

    }

    /**
     * updateBoardLink
     * Insert description here
     *
     * @param $identifier
     * @param $url
     * @param $relativity
     * @param $title
     * @param $short
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function updateBoardLink($identifier, $url, $relativity, $title, $short)
    {

        if (!is_numeric($identifier)) {

            return -1;

        }

        $title = $this->conn->real_escape_string($title);

        $url = $this->conn->real_escape_string($url);

        if (!is_numeric($relativity)) {

            $relativity = 1;

        }

        $short = $this->conn->real_escape_string($short);

        $cat = $this->conn->query("SELECT * FROM links WHERE id=" . $identifier);

        if ($cat->num_rows == 1) {

            $this->conn->query("UPDATE links SET title='" . $title . "', url='" . $url . "', relative=" . $relativity . ", short='" . $short . "' WHERE id=" . $identifier);

            $this->mitsuba->caching->rebuildBoardLinks();

            return 1;

        } else {

            return 0;

        }

    }

    /**
     * addBoardLink
     * Insert description here
     *
     * @param $parent
     * @param $url
     * @param $relativity
     * @param $title
     * @param $short
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function addBoardLink($parent, $url, $relativity, $title, $short)
    {

        $parent = $this->conn->real_escape_string($parent);

        $title = $this->conn->real_escape_string($title);

        $url = $this->conn->real_escape_string($url);

        $short = $this->conn->real_escape_string($short);

        if (!is_numeric($relativity)) {

            $relativity = 1;

        }

        $cat = $this->conn->query("SELECT * FROM links WHERE id=" . $parent);

        if ($cat->num_rows == 1) {

            $this->conn->query("INSERT INTO links (parent, url, relative, title, short) VALUES (" . $parent . ", '" . $url . "', " . $relativity . ", '" . $title . "', '" . $short . "');");

            $this->mitsuba->caching->rebuildBoardLinks();

            return 1;

        } else {

            return 0;

        }

    }

    /**
     * moveDownCategory
     * Insert description here
     *
     * @param $identifier
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function moveDownCategory($identifier)
    {

        $result = $this->conn->query("SELECT * FROM links WHERE id=" . $identifier . ";");

        if ($result->num_rows == 1) {

            $allcat = $this->conn->query("SELECT * FROM links WHERE url='' AND parent=-1");

            $row = $result->fetch_assoc();

            $curpos = substr($row['short'], 1);

            $catnum = $allcat->num_rows;

            if ($curpos < $catnum) {

                $this->conn->query("UPDATE links SET short='c" . ($curpos) . "' WHERE short='c" . ($curpos + 1) . "';");

                $this->conn->query("UPDATE links SET short='c" . ($curpos + 1) . "' WHERE id=" . $identifier);

                $this->mitsuba->caching->rebuildBoardLinks();

            }

            return 1;

        } else {

            return 0;

        }

    }

    /**
     * moveUpCategory
     * Insert description here
     *
     * @param $identifier
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function moveUpCategory($identifier)
    {

        $result = $this->conn->query("SELECT * FROM links WHERE id=" . $identifier . ";");

        if ($result->num_rows == 1) {

            //$allcat = $this->conn->query("SELECT * FROM links WHERE url='' AND parent=-1");

            $row = $result->fetch_assoc();

            $curpos = substr($row['short'], 1);

            //$catnum = $allcat->num_rows;

            if ($curpos > 1) {

                $this->conn->query("UPDATE links SET short='c" . ($curpos) . "' WHERE short='c" . ($curpos - 1) . "';");

                $this->conn->query("UPDATE links SET short='c" . ($curpos - 1) . "' WHERE id=" . $identifier);

                $this->mitsuba->caching->rebuildBoardLinks();

            }

            return 1;

        } else {

            return 0;

        }

    }

    /**
     * getLinkTable
     * Insert description here
     *
     * @param $identifier
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function getLinkTable($identifier)
    {

        $result = $this->conn->query("SELECT * FROM links WHERE parent=" . $identifier . " ORDER BY short ASC, title ASC, id DESC;");

        if ($result->num_rows > 0) {

            if ($identifier != - 1) {

                $table = "
";

            } else {

                $table = "
";

            }

            $table.= "

			Short

			Title

			Edit

			Delete

";

        } else {

            return "";

        }

        while ($row = $result->fetch_assoc()) {

            $table.= "
";

            if (empty($row['url'])) {

                $table.= "" . $row['title'] . " Up Down Add child	";

            } else {

                $table.= "" . $row['short'] . "	";

                $table.= "" . $row['title'] . "	";

            }

            $table.= "Edit	";

            $table.= "Delete	";

            $table.= "
";

            $t2 = $this->getLinkTable($row['id']);

            if (!empty($t2)) {

                $table.= "
" . $t2 . "
";

            }

        }

        $table.= "

";

        return $table;

    }

}

?>


code:
<?php

namespace Mitsuba\Admin;

/**
 * UI
 * Insert description here
 *
 * @category
 * @package
 * @author
 * @copyright
 * @license
 * @version
 * @link
 * @see
 * @since
 */
class UI
{

    private $conn;

    private $mitsuba;

    /**
     * __construct
     * Insert description here
     *
     * @param $connection
     * @param $mitsuba
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function __construct($connection, &$mitsuba)
    {

        $this->conn = $connection;

        $this->mitsuba = $mitsuba;

    }

    /**
     * getToken
     * Insert description here
     *
     * @param $path
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function getToken($path)
    {

        global $id_salt;

        $token = "";

        if ((empty($_SESSION['tokenpath'])) || ($_SESSION['tokenpath'] != $path) || (empty($_SESSION['token']))) {

            $token = md5($this->mitsuba->common->randomSalt() . $id_salt);

            $_SESSION['tokenpath'] = $path;

            $_SESSION['token'] = $token;

        } else {

            $token = $_SESSION['token'];

        }

        echo '<input type="hidden" name="token" value="' . $token . '" />';

    }

    /**
     * checkToken
     * Insert description here
     *
     * @param $token
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function checkToken($token)
    {

        if ($_SESSION['token'] != $token) {

            exit("Invalid form.");

        }

    }

    /**
     * getBoardList
     * Insert description here
     *
     * @param $boards
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function getBoardList($boards = "")
    {

        global $lang;

        if ($boards == "%") { $all = " checked";

        } else { $all = '';
        }
        if($this->mitsuba->admin->canBoard("%")) {
            echo $lang['mod/boards'] . ': <input type="checkbox" name="all" id="all" value=1' . $all . '/> ';

            echo "" . $lang['mod/all'] . "";
        }else{
            //don't judge me, too lazy to move this out of the if statement
            echo $lang['mod/boards'].":";
        }
?>

        <fieldset id="boardSelect">

    <?php

    if (($boards != "%") && ($boards != "")) {

        $boards = explode(",", $boards);

    }

        $result = $this->conn->query("SELECT * FROM boards ORDER BY short ASC;");

    while ($row = $result->fetch_assoc()) {
        $checked = "";

        if (($boards !== "%") && ($boards !== "")) {
            echo $this->mitsuba->admin->canBoard($row['short']);
            if (in_array($boards, $row['short'])) {

                $checked = " checked ";

            }

        }
        if($this->mitsuba->admin->canBoard($row['short'])) {
            echo "
";
            echo "<input id='{$row['short']}' type='checkbox' name='boards[]' value='" . $row['short'] . "'" . $checked . "/>";
            echo "/" . $row['short'] . "/ - " . $row['name'] . "";
            echo "
";
        }
    }

?>

        </fieldset>

    <?php

    }

    /**
     * getLinkList
     * Insert description here
     *
     * @param $links
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function getLinkList($links = "")
    {

        global $lang;

        if ($links == "%") {

?>

    <?php echo $lang['mod/board_links']; ?>: <input type="checkbox" name="l_all" id="l_all" onClick="$('#linkSelect').toggle()" value=1 checked/> <?php echo $lang['mod/all']; ?>

    <?php

        } else {

?>

    <?php echo $lang['mod/board_links']; ?>: <input type="checkbox" name="l_all" id="l_all" onClick="$('#linkSelect').toggle()" value=1/> <?php echo $lang['mod/all']; ?>

    <?php

        }

?>

        <fieldset id="linkSelect">

    <?php

    if (($links != "%") && ($links != "")) {

        $links = explode(",", $links);

    }

        $result = $this->conn->query("SELECT * FROM link ORDER BY name ASC;");

    while ($row = $result->fetch_assoc()) {

        $checked = "";

        if (($links !== "%") && ($links !== "")) {

            if (in_array($links, $row['name'])) {

                $checked = " checked ";

            }

        }

        echo "" . $row['name'] . "";

        echo "<input type='checkbox' onClick='document.getElementById(\"all\").checked=false;' name='links[]' value='" . $row['name'] . "'" . $checked . "/>";

    }

?>

        </fieldset>

    <?php

    }

    /**
     * getExtensionList
     * Insert description here
     *
     * @param $extensions
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function getExtensionList($extensions = "")
    {

        global $lang;

        if ($extensions == "%") {

?>

    <?php echo $lang['mod/extensions']; ?>: <input type="checkbox" name="ext_all" id="ext_all" onClick="$('#extSelect').toggle()" value=1 checked/> <?php echo $lang['mod/all']; ?>

    <?php

        } else {

?>

    <?php echo $lang['mod/extensions']; ?>: <input type="checkbox" name="ext_all" id="ext_all" onClick="$('#extSelect').toggle()" value=1/> <?php echo $lang['mod/all']; ?>

    <?php

        }

?>

        <fieldset id="extSelect">

    <?php

    if (($extensions != "%") && ($extensions != "")) {

        $extensions = explode(",", $extensions);

    }

        $result = $this->conn->query("SELECT DISTINCT ext FROM extensions ORDER BY ext ASC;");

    while ($row = $result->fetch_assoc()) {

        $checked = "";

        if (($extensions !== "%") && ($extensions !== "")) {

            if (in_array($extensions, $row['ext'])) {

                $checked = " checked ";

            }

        }

        if (empty($extensions)) {

            if (($row['ext'] == "jpg") || ($row['ext'] == "gif") || ($row['ext'] == "png")) {

                $checked = " checked ";

            }

        }

        echo "" . $row['ext'] . "";

        echo "<input type='checkbox' onClick='document.getElementById(\"ext_all\").checked=false;' name='ext[]' value='" . $row['ext'] . "'" . $checked . "/>";

    }

?>

        </fieldset>

    <?php

    }

    /**
     * parseList
     * Insert description here
     *
     * @param $input
     * @param $all
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function parseList($input, $all = 0)
    {

        $out = "";

        if ((!empty($_POST[$all])) && ($_POST[$all] == 1)) {

            $out = "%";

        } else {

            if (!empty($_POST[$input])) {

                foreach ($_POST[$input] as $s) {

                    $s.= $s . ",";

                }

            } else {

                $out = "%";

            }

        }

        if ($out != "%") {

            $out = substr($out, 0, strlen($out) - 1);

        }

        return $out;

    }

    /**
     * startSection
     * Insert description here
     *
     * @param $title
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function startSection($title)
    {

?>

            <?if($title){?>
<?php echo $title; ?>
<?}?>

    <?php

    }

    /**
     * endSection
     * Insert description here
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function endSection()
    {

?>

    <?php

    }

}

?>


code:
<?php

namespace Mitsuba\Admin;

/**
 * Users
 * Insert description here
 *
 * @category
 * @package
 * @author
 * @copyright
 * @license
 * @version
 * @link
 * @see
 * @since
 */
class Users
{

    private $conn;

    private $mitsuba;

    /**
     * __construct
     * Insert description here
     *
     * @param $connection
     * @param $mitsuba
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function __construct($connection, &$mitsuba)
    {

        $this->conn = $connection;

        $this->mitsuba = $mitsuba;

    }

    /**
     * canDoBoard
     * Insert description here
     *
     * @param $short
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function canDoBoard($short)
    {

        if ($_SESSION['boards'] != "%") {

            $boards = explode(",", $_SESSION['boards']);

        } else {

            $boards = "%";

        }

        if (($boards == "%") || (in_array($short, $boards))) {

            return 1;

        } else {

            return 0;

        }

    }

    /**
     * addUser
     * Insert description here
     *
     * @param $username
     * @param $password
     * @param $group
     * @param $boards
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function addUser($username, $password, $group, $boards)
    {

        $username = $this->conn->real_escape_string($username);

        if (!$this->mitsuba->admin->groups->isGroup($group)) {

            return -1;

        }

        $boards = $this->conn->real_escape_string($boards);

        $salt = $this->conn->real_escape_string($this->mitsuba->common->randomSalt());

        $password = hash("sha512", $password . $salt);

        $result = $this->conn->query("INSERT INTO users (`username`, `password`, `salt`, `group`, `boards`) VALUES ('" . $username . "', '" . $password . "', '" . $salt . "', " . $group . ", '" . $boards . "')");

        if ($result) {

            return 1;

        } else {

            return 0;

        }

    }

    /**
     * delUser
     * Insert description here
     *
     * @param $identifier
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function delUser($identifier)
    {

        if (!is_numeric($identifier)) {

            return -1;

        }

        $this->conn->query("DELETE FROM users WHERE id=" . $identifier);

        $this->conn->query("DELETE FROM notes WHERE mod_id=" . $identifier);

    }

    /**
     * updateUser
     * Insert description here
     *
     * @param $identifier
     * @param $username
     * @param $password
     * @param $group
     * @param $boards
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function updateUser($identifier, $username, $password, $group, $boards)
    {

        if (!is_numeric($identifier)) {

            return -1;

        }

        if (!$this->mitsuba->admin->groups->isGroup($group)) {

            return -1;

        }

        $user = $this->conn->query("SELECT * FROM users WHERE id=" . $identifier);

        if ($user->num_rows == 1) {

            $userdata = $user->fetch_assoc();

            $username = $this->conn->real_escape_string($username);

            $password_db = "";

            if (!empty($password)) {

                $password_db = ", password='" . hash("sha512", $password . $userdata['salt']) . "'";

            }

            $boards = $this->conn->real_escape_string($boards);

            $this->conn->query("UPDATE users SET username='" . $username . "'" . $password_db . ", `group`=" . $group . ", boards='" . $boards . "' WHERE id=" . $identifier);

        }

    }

    /**
     * isUser
     * Insert description here
     *
     * @param $identifier
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function isUser($identifier)
    {

        if (!is_numeric($identifier)) {

            return 0;

        }

        $result = $this->conn->query("SELECT * FROM users WHERE id=" . $this->conn->real_escape_string($identifier));

        if ($result->num_rows == 1) {

            $row = $result->fetch_assoc();

            return $row['username'];

        } else {

            return 0;

        }

    }

}

?>


code:
<?php

namespace Mitsuba;
use spam;

/**
 * Board
 * Insert description here
 *
 * @category
 * @package
 * @author
 * @copyright
 * @license
 * @version
 * @link
 * @see
 * @since
 */
class Board
{

    private $conn;

    private $mitsuba;

    private $config;

    /**
     * __construct
     * Insert description here
     *
     * @param $connection
     * @param $mitsuba
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function __construct($connection, &$mitsuba)
    {

        $this->conn = $connection;

        $this->mitsuba = $mitsuba;

        $this->config = $this->mitsuba->config;

    }

    /**
     * checkSpam
     * Insert description here
     *
     * @param $comment
     * @param $board
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function checkSpam($comment, $board)
    {
        //bayes spamfilter check...
        /*require_once 'libs/bayes/bayes.php';
        $bayesSpam = new \BayesFilter\spam("handler");
        $score = number_format($bayesSpam->isItSpam_v2($comment,'spam'),2);
        if ($score > 60) {
        die("spam");
        }else {
        die("good to go");
        }*/
        //standard check...
        $spam = $this->conn->query("SELECT * FROM spamfilter WHERE active=1");

        while ($row = $spam->fetch_assoc()) {

            if ($row['boards'] != "%") {

                $boards = explode(",", $row['boards']);

                if (in_array($board, $boards)) {

                    if ($row['regex'] == 1) {

                        try {

                            if (preg_match($row['search'], $comment)) {

                                $this->mitsuba->common->addSystemBan($this->mitsuba->common->getIP(), $row['reason'], htmlspecialchars($_POST['com']), $row['expires'], $row['boards']);

                                echo '<meta http-equiv="refresh" content="2;URL=' . "'./banned.php'" . '">';

                                exit();

                            }

                        }

                        catch(Exception $ex) {

                        }

                    } else {

                        if (stripos($comment, $row['search']) !== false) {

                            $this->mitsuba->common->addSystemBan($this->mitsuba->common->getIP(), $row['reason'], htmlspecialchars($_POST['com']), $row['expires'], $row['boards']);

                            echo '<meta http-equiv="refresh" content="2;URL=' . "'./banned.php'" . '">';

                            exit();

                        }

                    }

                }

            } else {

                if ($row['regex'] == 1) {

                    try {

                        if (preg_match($row['search'], $comment)) {

                            $this->mitsuba->common->addSystemBan($this->mitsuba->common->getIP(), $row['reason'], htmlspecialchars($_POST['com']), $row['expires'], "%");

                            echo '<meta http-equiv="refresh" content="2;URL=' . "'./banned.php'" . '">';

                            exit();

                        }

                    }

                    catch(Exception $ex) {

                    }

                } else {

                    if (stripos($comment, $row['search']) !== false) {

                        $this->mitsuba->common->addSystemBan($this->mitsuba->common->getIP(), $row['reason'], htmlspecialchars($_POST['com']), $row['expires'], "%");

                        echo '<meta http-equiv="refresh" content="2;URL=' . "'./banned.php'" . '">';

                        exit();

                    }

                }

            }

        }

    }

    /**
     * checkThreadDate
     * Insert description here
     *
     * @param $bdata
     * @param $return_url
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function checkThreadDate($bdata, $return_url)
    {

        global $lang;

        $lastdate = $this->conn->query("SELECT date FROM posts WHERE ip='" . $this->mitsuba->common->getIP() . "' AND resto=0 AND board='" . $bdata['short'] . "' ORDER BY date DESC LIMIT 0, 1");

        if ($lastdate->num_rows == 1) {

            $pdate = $lastdate->fetch_assoc();

            $pdate = $pdate['date'];

            if (($pdate + $bdata['time_between_threads']) > time()) {

                $this->mitsuba->common->showMsg($lang['img/error'], $lang['img/wait_more_thread']);

                exit;

            }

        }

    }

    /**
     * checkPostDate
     * Insert description here
     *
     * @param $bdata
     * @param $return_url
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function checkPostDate($bdata, $return_url)
    {

        global $lang;

        $lastdate = $this->conn->query("SELECT date FROM posts WHERE ip='" . $this->mitsuba->common->getIP() . "' AND board='" . $bdata['short'] . "' ORDER BY date DESC LIMIT 0, 1");

        if ($lastdate->num_rows == 1) {

            $pdate = $lastdate->fetch_assoc();

            $pdate = $pdate['date'];

            if (($pdate + $bdata['time_between_posts']) > time()) {

                $this->mitsuba->common->showMsg($lang['img/error'], $lang['img/wait_more_post']);

                exit;

            }

        }

    }

    /**
     * checkEmbed
     * Insert description here
     *
     * @param $bdata
     * @param $embed
     * @param $return_url
     *
     * @return
     *
     * @access
     * @static
     * @see
     * @since
     */
    function checkEmbed($bdata, $embed, $return_url)
    {

        global $lang;

        if ($bdata['embeds'] == 0) {

            $this->mitsuba->common->showMsg($lang['img/error'], $lang['img/embed_not_supported']);

            exit;

        }

        $embed_table = array();

        $result = $this->conn->query("SELECT * FROM embeds;");

        while ($row = $result->fetch_assoc()) {

            $embed_table[] = $row;

        }

        if ($this->mitsuba->common->isEmbed($embed, $embed_table)) {

            return "embed:" . $embed;

        } else {

            $this->mitsuba->common->showMsg($lang['img/error'], $lang['img/embed_not_supported']);

            exit;

        }

    }

}

?>