/** * board_delete action implementation. * * @access public * @return string forward name. */ public function perform() { $bm = new BoardManager(); $res = $bm->delete($this->backend, $this->af->get('id')); if (Ethna::isError($res)) { $this->ae->addObject('DeleteError', $res); } else { $this->redirect('board'); } return 'board'; }
/** * preprocess before forwarding. * * @access public */ public function preforward() { $userid = $this->af->getApp('userid'); $um = new UserManager(); $this->af->setApp('iconurl', $um->getIconUrl($userid)); $bm = new BoardManager(); $boardlist = $bm->boardlist($this->backend); krsort($boardlist); $mylist = array(); foreach ($boardlist as $post) { if ($post['userid'] == $userid) { array_push($mylist, $bm->addUrl($post)); } } $this->af->setApp('posts', $mylist); }
function __construct($id) { //only BoardManager should be accessing addon_boards $indexData = BoardManager::getBoardIndexFromId($id); $this->id = $id; $this->name = $indexData["name"]; $this->icon = $indexData["icon"]; $this->subCategory = $indexData["subCategory"]; $this->numberOfAddons = $this->getCount(); }
public static function loadBasicDummyData() { TestManager::clearDatabase(); $database = new DatabaseManager(); UserManager::verifyTable($database); AddonManager::verifyTable($database); BoardManager::verifyTable($database); TagManager::verifyTable($database); GroupManager::verifyTable($database); DependencyManager::verifyTable($database); CommentManager::verifyTable($database); RatingManager::verifyTable($database); BuildManager::verifyTable($database); StatManager::verifyTable($database); ScreenshotManager::verifyTable($database); if (!$database->query("INSERT INTO `addon_boards` (name, video, description) VALUES ('General Content', 'general_content_bg', 'Bricks, Events, Sounds, Prints, Environments, and much more!')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `addon_boards` (name, video, description) VALUES ('Minigames', 'minigames_bg', 'Weapons, Vehicles, Gamemodes, and all your gaming needs!')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `addon_boards` (name, video, description) VALUES ('Client Mods', 'client_mods_bg', 'Mods that run on your client.')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `addon_boards` (name, video, description) VALUES ('Bargain Bin', 'bargain_bin_bg', 'A home for \\'special\\' content.')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `users` (username, blid, password, email, salt, verified) VALUES ('testuser', '4833', '1d8436e97ef95a7a6151f47b909167c77cfe1985ee5500efa8d46cfe825abc59', '*****@*****.**', '273eb4', '1')")) { throw new Exception("Database error: " . $database->error()); } //the default json types likely need to be reworked if (!$database->query("INSERT INTO `addon_addons` (board, blid, name, filename, description, approved, versionInfo, authorInfo, reviewInfo) VALUES ('1', '4833', 'crapy adon', 'sciprt_hax.zip', 'bad addone pls delete', '1', '{}', '[]', '[]')")) { throw new Exception("Database error: " . $database->error()); } StatManager::addStatsToAddon(1); if (!$database->query("INSERT INTO `addon_tags` (name, base_color, icon) VALUES ('dum tag', 'ff6600', 'brokenimage')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `addon_tagmap` (aid, tid) VALUES ('1', '1')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `group_groups` (leader, name, description, color, icon) VALUES ('4833', 'legion of dumies', 'a group for people who just want to be in a group', '00ff00', 'brokenimage')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `group_usermap` (gid, blid, administrator) VALUES ('1', '4833', '1')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `addon_comments` (blid, aid, comment) VALUES ('4833', '1', 'glorious addon comrade')")) { throw new Exception("Database error: " . $database->error()); } if (!$database->query("INSERT INTO `addon_ratings` (blid, aid, rating) VALUES ('4833', '1', '1')")) { throw new Exception("Database error: " . $database->error()); } }
/** * preprocess before forwarding. * * @access public */ public function preforward() { $start = $this->af->get('start'); error_log('start:' . $start); if ($start === NULL) { $start = 0; } if ($start < 0) { $start = 0; } $count = 5; $bm = new BoardManager(); $um = new UserManager(); $boardlist = $bm->boardlist($this->backend); krsort($boardlist); $total = count($boardlist); $display_posts = array(); for ($i = $start; $i < $start + $count && $i < $total; $i++) { $cur = current(array_slice($boardlist, $i, 1, true)); array_push($display_posts, $bm->addUrl($cur)); } if ($start > 0) { $this->af->setApp('hasprev', true); $this->af->setApp('prev', $start - $count); } else { $this->af->setApp('hasprev', false); } if ($start + $count < $total) { $this->af->setApp('hasnext', true); $this->af->setApp('next', $start + $count); $this->af->setApp('last', (ceil($total / $count) - 1) * $count); } else { $this->af->setApp('hasnext', false); } $this->af->setApp('posts', $display_posts); $this->af->setApp('link', '/?action_board=true'); $this->af->setApp('count', $count); $this->af->setApp('current', $start); $this->af->setApp('pager', Ethna_Util::getDirectLinkList($total, $start, $count)); return 'board'; }
/** * board_do action implementation. * * @access public * @return string forward name. */ public function perform() { if (!$this->session->isStart()) { $this->ae->addObject('boardError', Ethna::raiseNotice("you need to login to post", E_SAMPLE_AUTH)); return 'board'; } $bm = new BoardManager(); $color = $this->af->get('color'); if ($color === NULL) { $color = '#000000'; } $fileid = $this->af->get('uploaded-fileid'); $content = $this->af->get('content'); //$content='hage'; $res = $bm->post($this->backend, $this->session->get('username'), $content, $color, $fileid); if (Ethna::isError($res)) { $this->ae->addObject('PostError', $res); } else { $this->redirect('board'); } return 'board'; }
private static function getBoardIndexData() { $database = new DatabaseManager(); BoardManager::verifyTable($database); $resource = $database->query("SELECT * FROM `addon_boards`"); if (!$resource) { throw new Exception("Error getting data from database: " . $database->error()); } $boardData = array(); while ($row = $resource->fetch_object()) { $boardData[$row->id] = new BoardObject($row); } $resource->close(); return $boardData; }
public static function getAllBoards() { $ret = array(); $db = new DatabaseManager(); $res = $db->query("SELECT `id` FROM `addon_boards`"); if (!$res) { throw new Exception("Error getting data from database: " . $db->error()); } while ($obj = $res->fetch_object()) { $ret[$obj->id] = BoardManager::getFromId($obj->id); } //improves performance with simultaneous connections $res->close(); return $ret; }
<?php //collects together some of the information needed by /addons/board.php if (!isset($_GET['id'])) { return []; } require_once realpath(dirname(__DIR__) . "/class/BoardManager.php"); $aid = $_GET['id'] + 0; //force it to be a number //may throw exceptions with bad input, should fix if (isset($_GET['page'])) { $offset = (intval($_GET['page']) - 1) * 10; $limit = 10; $addonIDs = BoardManager::getAddonsFromBoardID($aid, $offset, $limit); } elseif (isset($_GET['offset']) && isset($_GET['limit'])) { $offset = $_GET['offset'] + 0; $limit = $_GET['limit'] + 0; $addonIDs = BoardManager::getAddonsFromBoardID($aid, $offset, $limit); } else { $addonIDs = BoardManager::getAddonsFromBoardID($aid); } $addons = []; foreach ($addonIDs as $aid) { $addon = AddonManager::getFromID($aid); if ($addon !== false) { $addons[] = $addon; } } return $addons;
<?php require_once realpath(dirname(__DIR__) . "/private/class/BoardManager.php"); require_once realpath(dirname(__DIR__) . "/private/class/AddonManager.php"); //require_once(realpath(dirname(__DIR__) . "/private/class/AddonObject.php")); require_once realpath(dirname(__DIR__) . "/private/class/UserManager.php"); //require_once(realpath(dirname(__DIR__) . "/private/class/UserHandler.php")); //TO DO: rewrite this page to use /private/json/getBoardAddonsWithUsers.php // And probably an ajax page to go with it if (isset($_GET['id'])) { try { $boardObject = BoardManager::getFromId($_GET['id'] + 0); } catch (Exception $e) { //board doesn't exist header('Location: /addons'); die("board doesnt exist"); } } else { header('Location: /addons'); die; } $_PAGETITLE = "Glass | " . $boardObject->getName(); include realpath(dirname(__DIR__) . "/private/header.php"); include realpath(dirname(__DIR__) . "/private/navigationbar.php"); ?> <div class="maincontainer"> <?php include realpath(dirname(__DIR__) . "/private/searchbar.php"); ?> <h1 style="text-align:center"><?php echo $boardObject->getName();
public static function verifyTable($database) { /*TO DO: - screenshots - tags - approval info should probably be in a different table, or actually maybe not I dunno - do we really need stable vs testing vs dev? - bargain/danger should probably be boards - figure out how data is split between addon and file - I don't know much about how the file system works, but having 'name', 'file', 'filename', and a separate 'addon_files' table doesn't seem ideal. - Maybe we should just keep track of total downloads instead of 3 different columns - I think users should just credit people in their descriptions instead of having a dedicated authorInfo json object */ if ($database->debug()) { require_once realpath(dirname(__FILE__) . '/UserManager.php'); require_once realpath(dirname(__FILE__) . '/BoardManager.php'); UserManager::verifyTable($database); BoardManager::verifyTable($database); //why is the blid foreign key constraint removed? //If you want to be able to set blid to null, you should reconsider. //blid is used to determine which account has control over the addon. //There is no need to set it to null. Just default it to some admin. if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_addons` (\n\t\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t\t`board` INT,\n\t\t\t\t`blid` INT NOT NULL,\n\t\t\t\t`name` VARCHAR(30) NOT NULL,\n\t\t\t\t`filename` TEXT NOT NULL,\n\t\t\t\t`description` TEXT NOT NULL,\n\t\t\t\t`versionInfo` TEXT NOT NULL,\n\t\t\t\t`authorInfo` TEXT NOT NULL,\n\t\t\t\t`reviewInfo` TEXT NOT NULL,\n\t\t\t\t`repositoryInfo` TEXT NOT NULL,\n\t\t\t\t`deleted` TINYINT NOT NULL DEFAULT 0,\n\t\t\t\t`approved` TINYINT NOT NULL DEFAULT 0,\n\t\t\t\t`uploadDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t\t\tFOREIGN KEY (`board`)\n\t\t\t\t\tREFERENCES addon_boards(`id`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,,\n\t\t\t\tFOREIGN KEY (`blid`)\n\t\t\t\t\tREFERENCES users(`blid`)\n\t\t\t\t\tON UPDATE CASCADE\n\t\t\t\t\tON DELETE CASCADE,\n\t\t\t\tPRIMARY KEY (`id`))")) { throw new Exception("Failed to create table addon_addons: " . $database->error()); } } }
$ro->title = $addon->getName(); //$ro->rating = $ratingData['average']; $ro->author = $addon->getAuthor()->getName(); $fo = $addon->getFile($addon->getLatestBranch()); $ro->server = $fo->isServer(); $ro->client = $fo->isClient(); $ro->temp_branch = $addon->getLatestBranch(); $ro->temp_filename = $addon->getFilename(); $ro->downloads = $addon->getDownloads(1) + $addon->getDownloads(2); $ret[] = $ro; } echo json_encode($ret, JSON_PRETTY_PRINT); return; } } else { $boardObject = BoardManager::getFromId($boardId); $addons = $boardObject->getAddons(); foreach ($addons as $addon) { $ratingData = $addon->getRatingData(); $ro = new stdClass(); $ro->id = $addon->getId(); $ro->title = $addon->getName(); //$ro->rating = $ratingData['average']; $ro->author = $addon->getAuthor()->getName(); $fo = $addon->getFile($addon->getLatestBranch()); $ro->server = $fo->isServer(); $ro->client = $fo->isClient(); $ro->temp_branch = $addon->getLatestBranch(); $ro->temp_filename = $addon->getFilename(); $ro->downloads = $addon->getDownloads(1) + $addon->getDownloads(2); $ret[] = $ro;
require_once dirname(__DIR__) . "/../../../private/class/ScreenshotManager.php"; $ret = new stdClass(); if (isset($_REQUEST['id']) & $_REQUEST['id'] != "") { $aid = $_REQUEST['id']; $ret->status = "success"; } else { $ret->status = "error"; $ret->error = "Add-On not found!"; die(json_encode($ret, JSON_PRETTY_PRINT)); } $addonObject = AddonManager::getFromID($aid); //$screens = ScreenshotManager::getScreenshotsFromAddon($aid); //I dont think this is done $ret->aid = $aid; $ret->filename = $addonObject->getFilename(); $ret->boardId = $addonObject->getBoard(); $ret->board = BoardManager::getFromID($addonObject->getBoard())->getName(); $ret->name = $addonObject->getName(); $ret->description = htmlspecialchars_decode($addonObject->getDescription()); $ret->screenshots = array(); /*foreach($screens as $screen) { $screenshot = new stdClass(); $screenshot->id = $screen->getId(); $screenshot->url = "http://api.blocklandglass.com/files/screenshots/" . $addonObject->getId() . "/" . $i . ".png"; $screenshot->thumbnail = "http://api.blocklandglass.com/files/screenshots/" . $addonObject->getId() . "/" . $i . "_thumb.png"; list($width, $height) = getimagesize(dirname(__DIR__) . "/files/screenshots/" . $addonObject->getId() . "/" . $i . ".png"); $screenshot->extent = $width . " " . $height; $ret->screenshots[] = $screenshot; }*/ $author = new stdClass(); //$author->blid = $addonObject->getAuthor()->getBlid(); //$author->name = $addonObject->getAuthor()->getName();
public function getBoard() { return BoardManager::getFromId($this->boardId); }
public static function verifyTable($database) { /*TO DO: - screenshots - approval info should probably be in a different table, or actually maybe not I dunno - do we really need stable vs testing vs dev? - bargain/danger should probably be boards - figure out how data is split between addon and file - I don't know much about how the file system works, but having 'name', 'file', 'filename', and a separate 'addon_files' table doesn't seem ideal. - Maybe we should just keep track of total downloads instead of 3 different columns - I think users should just credit people in their descriptions instead of having a dedicated authorInfo json object */ require_once realpath(dirname(__FILE__) . '/UserManager.php'); require_once realpath(dirname(__FILE__) . '/BoardManager.php'); UserManager::verifyTable($database); BoardManager::verifyTable($database); if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_addons` (\n\t\t\t`id` INT NOT NULL AUTO_INCREMENT,\n\t\t\t`board` INT,\n\t\t\t`blid` INT NOT NULL,\n\t\t\t`name` VARCHAR(30) NOT NULL,\n\t\t\t`filename` TEXT NOT NULL,\n\t\t\t`description` TEXT NOT NULL,\n\t\t\t`version` TEXT NOT NULL,\n\t\t\t`authorInfo` TEXT NOT NULL,\n\t\t\t`reviewInfo` TEXT NOT NULL,\n\t\t\t`repositoryInfo` TEXT NULL DEFAULT NULL,\n\t\t\t`deleted` TINYINT NOT NULL DEFAULT 0,\n\t\t\t`approved` TINYINT NOT NULL DEFAULT 0,\n\t\t\t`betaVersion` TEXT DEFAULT NULL,\n\t\t\t`rating` int(11) NOT NULL DEFAULT 0,\n\t\t\t`uploadDate` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t\t`type` TEXT NOT NULL,\n\t\t\tFOREIGN KEY (`board`)\n\t\t\t\tREFERENCES addon_boards(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t\tPRIMARY KEY (`id`))")) { throw new Exception("Failed to create table addon_addons: " . $database->error()); } if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_updates` (\n\t\t\t`id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t `aid` int(11) NOT NULL,\n\t\t `version` text NOT NULL,\n\t\t `tempfile` text NOT NULL,\n\t\t `changelog` text NOT NULL,\n\t\t `submitted` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,\n\t\t `upstream` bit(1) NOT NULL DEFAULT b'0',\n\t\t `restart` bit(1) NOT NULL DEFAULT b'0',\n\t\t `approved` bit(1) DEFAULT NULL,\n\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE,\n\t\t PRIMARY KEY (`id`),\n\t\t UNIQUE KEY `id` (`id`))")) { throw new Exception("Failed to create table addon_updates: " . $database->error()); } if (!$database->query("CREATE TABLE IF NOT EXISTS `addon_ratings` (\n\t\t `aid` int(11) NOT NULL,\n\t\t\t`blid` int(11) NOT NULL,\n\t\t\t`rating` int(11) NOT NULL,\n\t\t\tFOREIGN KEY (`aid`)\n\t\t\t\tREFERENCES addon_addons(`id`)\n\t\t\t\tON UPDATE CASCADE\n\t\t\t\tON DELETE CASCADE)")) { throw new Exception("Failed to create table addon_updates: " . $database->error()); } }
$ao->id = $ad->id; $ao->name = $ad->title; $ao->author = "RTB"; $ao->ratings = "0"; $ao->downloads = "N/A"; $ret->addons[] = $ao; } $ret->status = "success"; $ret->board_id = "rtb"; $ret->board_name = "RTB Archive"; $ret->page = $page; $ret->pages = ceil(RTBAddonManager::getCount() / 10); echo json_encode($ret, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); return; } $boardObject = BoardManager::getFromID($_REQUEST['id']); $addonIds = AddonManager::getFromBoardID($boardObject->getID(), ($page - 1) * 10, 10); $ret = new stdClass(); $ret->addons = array(); foreach ($addonIds as $aid) { $addon = AddonManager::getFromID($aid); if ($addon->getRating() == null) { $rating = 0; } else { $rating = $addon->getRating(); } $retboard = new stdClass(); $retboard->id = $addon->getId(); $retboard->name = $addon->getName(); $user = UserLog::getCurrentUsername($addon->getManagerBLID()); if ($user == false) {
public function uploadIcon($userid, $fname, $ext) { $fileid = $userid . '/icon'; $bm = new BoardManager(); $res = $bm->s3upload($fname, $fileid, $ext); }
<?php //all the information needed by /addons/boards.php require_once realpath(dirname(__DIR__) . "/class/BoardManager.php"); $boards = BoardManager::getAllBoards(); //usort($boards, function($a, $b) { // return strcmp($a->getName(), $b->getName()); //}); //$response = []; // //foreach($boards as $board) { // $response[$board->getSubCategory()][] = $board; //} //return $response; return $boards;
require_once realpath(dirname(__DIR__) . "/private/class/BoardManager.php"); require_once realpath(dirname(__DIR__) . "/private/class/AddonManager.php"); require_once realpath(dirname(__DIR__) . "/private/class/AddonObject.php"); require_once realpath(dirname(__DIR__) . "/private/class/CommentManager.php"); require_once realpath(dirname(__DIR__) . "/private/class/ScreenshotManager.php"); require_once realpath(dirname(__DIR__) . "/private/class/UserManager.php"); require_once realpath(dirname(__DIR__) . "/private/class/UserLog.php"); // require_once(realpath(dirname(__DIR__) . "/private/class/UserHandler.php")); require_once realpath(dirname(__DIR__) . "/private/lib/Parsedown.php"); //to do: use ajax/json to build data for page //this php file should just format the data nicely if (isset($_GET['id'])) { try { $addonObject = AddonManager::getFromId($_GET['id'] + 0); $boardObject = BoardManager::getFromID($addonObject->getBoard()); } catch (Exception $e) { //board doesn't exist header('Location: /addons'); die("addon doesnt exist"); } } else { header('Location: /addons'); die; } if ($addonObject->isRejected()) { include 'rejected.php'; die; } else { if (!$addonObject->getApproved()) { include 'unapproved.php';