public static function clearDatabase()
 {
     apc_clear_cache();
     $database = new DatabaseManager();
     //$resource = $database->query("SELECT DATABASE()");
     //$name = $resource->fetch_row()[0];
     //$resource->close();
     //make sure we don't accidentally load dummy data on live database
     //to do: make sure this actually works
     //if(strpos($name, "test" === false)) {
     if (!$database->debug()) {
         throw new Exception("Database may not be safe to run tests on");
     }
     //addon_addons, addon_boards, addon_tags, addon_tagmap, group_groups, group_usermap, addon_comments, addon_ratings
     if (!$database->query("SET FOREIGN_KEY_CHECKS=0")) {
         throw new Exception("Database error: " . $database->error());
     }
     if (!$database->query("DROP TABLE IF EXISTS addon_tagmap, addon_tags, addon_dependency,\n\t\t\taddon_addons, addon_boards, addon_comments, addon_ratings, addon_stats,\n\t\t\tusers, build_builds, build_dependency, build_stats, tag_stats, group_groups, group_usermap,\n\t\t\tstatistics, screenshots, build_screenshotmap, addon_screenshotmap")) {
         throw new Exception("Database error: " . $database->error());
     }
     if (!$database->query("SET FOREIGN_KEY_CHECKS=1")) {
         throw new Exception("Database error: " . $database->error());
     }
     apc_clear_cache();
 }
 public function testBasicQuery()
 {
     TestManager::loadBasicDummyData();
     $database = new DatabaseManager();
     $resource = $database->query("SHOW TABLES");
     $this->assertNotEquals(false, $resource);
 }
Beispiel #3
0
 public function setUsername($name)
 {
     if ($this->verified) {
         $database = new DatabaseManager();
         $database->query("UPDATE `users` SET `username`='" . $database->sanitize($name) . "' WHERE `email`='" . $database->sanitize($this->getEmail()) . "'");
         apc_store('userObject_' . $this->blid, $this, 600);
     }
 }
 function getCount()
 {
     if (!isset($numberOfAddons)) {
         $db = new DatabaseManager();
         $res = $db->query("SELECT COUNT(*) FROM `addon_addons` WHERE board='" . $db->sanitize($this->id) . "'  AND deleted=0");
         $this->numberOfAddons = $res->fetch_row()[0];
     }
     return $this->numberOfAddons;
 }
 function collectHourStat($store = false)
 {
     $stats = new stdClass();
     $stats->time = gmdate("Y-m-d H:00:00", time());
     $stats->duration = "hour";
     $database = new DatabaseManager();
     //Addons!
     $addons = new stdClass();
     $addonArray = AddonManager::getAll();
     $addons->count = sizeof($addonArray);
     $addons->cumulative_downloads = array();
     $addons->usage = array();
     $addons->usage_total = array();
     foreach ($addonArray as $addon) {
         $downloadData = new stdClass();
         // TODO we need to go back. I dont want total downloads, I want individual
         //$downloadData->web =
         //$downloadData->ingame =
         //$downloadData->update =
         $addons->cumulative_downloads[$addon->getId()] = $downloadData;
         $res = $database->query("SELECT `version` FROM `stats_usage` WHERE `aid`='" . $addon->getId() . "' AND `reported` > now() - INTERVAL 1 HOUR");
         $ret = $res->fetch_object();
         $usage = array();
         $total = 0;
         while ($obj = $res->fetch_object()) {
             $total++;
             if (!isset($usage[$obj->version])) {
                 $usage[$obj->version] = 1;
             } else {
                 $usage[$obj->version]++;
             }
         }
         $addons->usage[$addon->getId()] = $usage;
         $addons->usage_total[$addon->getId()] = $total;
     }
     $stats->addons = $addons;
     //Builds
     $builds = new stdClass();
     $buildArray = BuildManager::getAll();
     $builds->count = sizeof($buildArray);
     $builds->cumulative_downloads = array();
     foreach ($buildArray as $build) {
         // TODO this isn't done either...
         //$builds->cumulative_downloads[$build->getId()] = $build->getDownloads();
     }
     $stats->builds = $builds;
     //Master Server
     $stats->master = new stdClass();
     $master = CronStatManager::getMasterServerStats();
     $stats->master->users = $master[0];
     $stats->master->servers = $master[1];
     if ($store) {
         CronStatManager::verifyTable($database);
         $database->query("INSERT INTO `cron_statistics`  (`time` , `duration` , `data`) VALUES ('" . $stats->time . "',  'hour',  '" . $database->sanitize(json_encode($stats)) . "')");
     }
     return $stats;
 }
Beispiel #6
0
 public static function getHistory($blid)
 {
     $db = new DatabaseManager();
     $res = $db->query("SELECT * FROM `user_log` WHERE `blid`='" . $db->sanitize($blid) . "' ORDER BY `lastseen` DESC");
     $ret = array();
     while ($obj = $res->fetch_object()) {
         $ret[] = $obj;
     }
     return $ret;
 }
 public static function register($email, $password1, $password2, $blid)
 {
     //if(!AccountManager::validUsername($username)) {
     //	return [
     //		"message" => "Invalid username provided. You may only use up to 20 characters."
     //	];
     //}
     if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
         return ["message" => "Invalid e-mail address"];
     }
     if ($password1 !== $password2) {
         return ["message" => "Your passwords do not match."];
     }
     if (strlen($password1) < 4) {
         return ["message" => "Your password must be at least 4 characters"];
     }
     $blid = trim($blid);
     if (!is_numeric($blid)) {
         return ["message" => "INVALID BL_ID"];
     }
     $loginDetails1 = AccountManager::getLoginDetailsFromBLID($blid);
     $loginDetails2 = AccountManager::getLoginDetailsFromEmail($email);
     if ($loginDetails1) {
         return ["message" => "That BL_ID is already in use!"];
     } else {
         if ($loginDetails2) {
             return ["message" => "That E-mail address is already in use."];
         }
     }
     $database = new DatabaseManager();
     //AccountManager::verifyTable($database);
     $intermediateSalt = md5(uniqid(rand(), true));
     $salt = substr($intermediateSalt, 0, 6);
     $hash = hash("sha256", $password1 . $salt);
     //long if statement because oh well
     //I am assuming 'groups' is a json array, so by default it is "[]"
     if ($database->query("INSERT INTO users (password, salt, blid, email, groups, username) VALUES ('" . $database->sanitize($hash) . "', '" . $database->sanitize($salt) . "', '" . $database->sanitize($blid) . "', '" . $database->sanitize($email) . "', '" . $database->sanitize("[]") . "', '" . $database->sanitize("Blockhead" . $blid) . "')")) {
         //$_SESSION['justregistered'] = 1;
         //header("Location: " . $redirect);
         //I think this is the only way to do a redirect containing post information
         //echo("<!doctype html><head><meta charset=\"utf-8\"></head><body>");
         //echo("<form class=\"hidden\" action=\"/login.php\" name=\"redirectForm\" method=\"post\">");
         //echo("<input type=\"hidden\" name=\"redirect\" value=\"" . htmlspecialchars($redirect) . "\">");
         //echo("<input type=\"hidden\" name=\"justregistered\" value=\"1\">");
         //echo("<input type=\"submit\" value=\"Click here if your browser does not automatically redirect you\">");
         //echo("</form>");
         //echo("<script language=\"JavaScript\">document.redirectForm.submit();</script>");
         //echo("</body></html>");
         //die();
         return ["redirect" => "/login.php"];
     } else {
         throw new Exception("Error adding new user into databse: " . $database->error());
     }
 }
 public static function getAll()
 {
     $ret = array();
     $db = new DatabaseManager();
     $res = $db->query("SELECT `id` FROM `build_builds`");
     while ($obj = $res->fetch_object()) {
         $ret[$obj->id] = BuildManager::getFromId($obj->id);
     }
     $res->close();
     return $ret;
 }
 public static function getDistribution($aid)
 {
     $db = new DatabaseManager();
     $res = $db->query("SELECT * FROM `stats_usage` WHERE `aid`='" . $db->sanitize($aid) . "' AND `reported` > now() - INTERVAL 30 DAY");
     $ret = array();
     while ($obj = $res->fetch_object()) {
         if (isset($ret[$obj->version])) {
             $ret[$obj->version]++;
         } else {
             $ret[$obj->version] = 1;
         }
     }
     return $ret;
 }
 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;
 }
 function getEntry($time, $duration)
 {
     $entry = apc_fetch('cronStat_' . $duration . '_' . $time, $success);
     if (!$success) {
         //$duration = hour, day, week, month
         $database = new DatabaseManager();
         $res = $database->query("SELECT * FROM `cron_statistics` WHERE `duration`='" . $database->sanitize($duration) . "' AND `time`='" . $database->sanitize($time) . "'");
         if ($res->num_rows == 0) {
             return false;
         } else {
             $obj = json_decode($res->fetch_object()->data);
             apc_store('cronStat_' . $duration . '_' . $time, $obj);
             return $obj;
         }
     } else {
         return $entry;
     }
 }
 public static function getUnapproved()
 {
     $ret = array();
     $db = new DatabaseManager();
     $res = $db->query("SELECT `id` FROM `addon_addons` WHERE `approved`='0'");
     while ($obj = $res->fetch_object()) {
         $ret[$obj->id] = AddonManager::getFromId($obj->id);
     }
     return $ret;
 }
<table class="commenttable">
<tbody>
<?php 
//This page is designed to be requested by ajax
//I also want it to be possible to request this content in-game.
//In the future the file that actually interacts with the database should be in /private/class, while this one processes get requests and formats data
require_once realpath(dirname(__DIR__) . "/private/class/DatabaseManager.php");
$database = new DatabaseManager();
//the "and `verified` = 1 can be deleted if we decide to force blid database entries to be unique
$result = $database->query("SELECT * FROM `addon_comments` WHERE `blid` = '" . $database->sanitize($_GET['blid']) . "' AND `verified` = 1");
if (!$result) {
    echo "Database error: " . $database->error();
} else {
    if ($result->num_rows == 0) {
        echo "<tr style=\"vertical-align:top\">";
        echo "<td colspan=\"2\" style=\"text-align: center;\">";
        echo "There are no comments here yet.";
        echo "</td></tr>";
    } else {
        require_once realpath(dirname(__DIR__) . "/private/class/UserHandler.php");
        while ($row = $result->fetch_object()) {
            $user = UserManager::getFromId($row->uid);
            echo "<tr style=\"vertical-align:top\">";
            echo "<td style=\"width: 150px;\">";
            echo "<a href=\"/user/view.php?id=" . $user->getID() . "\">" . utf8_encode($user->getUsername()) . "</a>";
            //Not sure where administrator status is stored.  My guess is 'groups' but I can't be certain.
            //At any rate, we should probably go and rethink the database tables for long term use.
            echo "<br /><span style=\"font-size: .8em;\">" . $user->getBLID() . "<br />Administrator?</span>";
            echo "</td><td>";
            echo utf8_encode($row->comment);
            echo "</td></tr>";
Beispiel #14
0
} else {
    $db = new DatabaseManager();
    $baseQuery = "SELECT * FROM `addon_addons` WHERE `name` LIKE '%" . $db->sanitize($_POST['query']) . "%'";
    //later on we can make it so administrators can search for deleted add-ons
    $extendedQuery = " AND `deleted` = 0";
    if (isset($_POST['blid'])) {
        try {
            require_once realpath(dirname(__DIR__) . "/private/class/UserManager.php");
            $user = UserManager::getFromBLID($_POST['blid']);
            $extendedQuery = $extendedQuery . " AND `author` = '" . $db->sanitize($_POST['blid']) . "'";
        } catch (Exception $e) {
            echo "<p>User " . htmlspecialchars($_POST['blid']) . " not found.</p>";
        }
    }
    //One of the few time's we'll use a direct SQL query on a page
    $result = $db->query($baseQuery . $extendedQuery);
    echo "<h2>Search Results for ";
    echo "\"<u>" . htmlspecialchars($_POST['query']) . "</u>\"";
    if (isset($user) && $user) {
        echo " by <a href=\"/user/view.php?id=" . $user->getID() . "\">" . htmlspecialchars($user->getUsername()) . "</a>";
    }
    echo "</h2><hr />";
    if ($result->num_rows) {
        while ($row = $result->fetch_object()) {
            echo "<p><b><a href=\"addon.php?id=" . $row->id . "\">" . htmlspecialchars($row->name) . "</a></b><br />";
            if (strlen($row->description) > 200) {
                $desc = substr($row->description, 0, 196) . " ...";
            } else {
                $desc = $row->description;
            }
            $Parsedown = new Parsedown();
Beispiel #15
0
 public function getCommentsRange($start, $end)
 {
     $db = new DatabaseManager();
     $commentRes = $db->query("SELECT * FROM `addon_comments` WHERE aid='" . $this->id . "' ORDER BY timestamp DESC LIMIT {$start}, {$end}");
     $comments = array();
     while ($comment = $commentRes->fetch_object()) {
         $author = UserManager::getFromId($comment->uid);
         $comments[] = new Comment(array($comment->comment, $author, $comment->timestamp));
     }
     return $comments;
 }
<?php

include_once 'extract_keywords.php';
include_once '../database_manager.php';
$db = DatabaseManager::connectDB();
//empty table preprocessed_user
DatabaseManager::query("TRUNCATE table preprocessed_user");
// fetch refer from table userinfo, extract keywords
$refers = mysql_query("select userid, date, refer from user where refer is not null and refer <> '' ");
$keywords_num = 0;
while ($row = mysql_fetch_array($refers)) {
    $keyword = extract_keywords($row['refer']);
    $keyword = addslashes($keyword);
    if ($keyword != '' && !is_numeric($keyword)) {
        $insert_sql = "insert into preprocessed_user (userid, date, keywords) values('{$row['userid']}', '{$row['date']}', '{$keyword}')";
        $insert_result = mysql_query($insert_sql);
        if ($insert_result) {
            // insert successfully
            $keywords_num++;
        } else {
            echo $insert_sql;
            echo '<br>';
            echo mysql_error();
            echo '<br>';
        }
    }
}
echo 'keywords_num = ' . $keywords_num;
DatabaseManager::closeDB($db);
?>
	
 public function updateEmail($email)
 {
     $database = new DatabaseManager();
     $database->query("UPDATE `users` SET `email`='" . $database->sanitize($email) . "' WHERE `blid`='" . $database->sanitize($this->getBlid()) . "'");
     $this->email = $email;
 }
 protected function onAccountRemoteVerified($blid)
 {
     //echo "remote success " . $blid;
     $this->remoteVerified = true;
     $this->blid = $blid;
     //officially start session
     $db = new DatabaseManager();
     $db->query("INSERT INTO  `blocklandGlass`.`ingame_sessions` (`blid`, `sessionid`, `start`, `lastactive`, `version`)\n\t\t\tVALUES ('" . $this->getBlid() . "', '" . session_id() . "', NOW( ) , CURRENT_TIMESTAMP, '" . $db->sanitize($this->getVersion()) . "');");
 }
Beispiel #19
0
$db = new DatabaseManager();
$aid = $db->sanitize($_GET['id']);
$bid = $db->sanitize($_GET['branch']);
$branch = "";
if ($bid == 1) {
    $branch = "file_stable";
} else {
    if ($bid == 2) {
        $branch = "file_testing";
    } else {
        if ($bid == 3) {
            $branch = "file_dev";
        }
    }
}
$addonResult = $db->query("SELECT * FROM `addon_addons` WHERE `id`=" . $aid);
$addonObj = $addonResult->fetch_object();
$fileResult = $db->query("SELECT * FROM `addon_files` WHERE `id`=" . $addonObj->{$branch});
$fileObj = $fileResult->fetch_object();
$file = '../../files/comp/' . $fileObj->hash . '.zip';
if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/zip');
    header('Content-Disposition: attachment; filename=' . $addonObj->filename);
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    if (isset($_GET["ingame"])) {
        $db->query("UPDATE `blocklandGlass`.`addon_addons` SET `downloads_ingame` = '" . ($addonObj->downloads_ingame + 1) . "' WHERE `addon_addons`.`id` = " . $aid . ";");
Beispiel #20
0
<?php

require_once '../autoload.php';
if (stristr($_GET['email'], "@") && stristr($_GET['email'], ".") && strlen($_GET['email']) > 5) {
    $dbmanager = new DatabaseManager();
    $dbmanager->query("INSERT IGNORE INTO `subscriptions` (`email`) VALUES ('" . $database->real_escape_string($_GET['email']) . "')");
    echo $_GET['callback'] . "(" . json_encode(array("success" => true)) . ")";
} else {
    echo $_GET['callback'] . "(" . json_encode(array("success" => false)) . ")";
}
Beispiel #21
0
<?php

if (($_adminAuthed ?? false) != true) {
    die;
}
require_once realpath(dirname(__DIR__) . "/../private/class/DatabaseManager.php");
require_once realpath(dirname(__DIR__) . "/../private/class/BoardManager.php");
if (isset($_POST['name']) && isset($_POST['icon']) && isset($_POST['desc'])) {
    $db = new DatabaseManager();
    $db->query("INSERT INTO `addon_boards` (`id`, `name`, `icon`, `description`) VALUES (NULL, '" . $db->sanitize($_POST['name']) . "', '" . $db->sanitize($_POST['icon']) . "', '" . $db->sanitize($_POST['desc']) . "');");
}
?>
<table style="width: 100%">
  <tbody>
    <tr>
      <th style="width: 50%">Board</th>
      <th style="">Add-Ons</th>
      <th style="">Options</th>
    </tr>
    <?php 
$boards = BoardManager::getAllBoards();
foreach ($boards as $board) {
    echo "<tr>";
    echo "<td>" . $board->getName() . "</td>";
    echo "<td>???</td>";
    echo "<td>...</td>";
    echo "</tr>";
}
?>
  </tbody>
</table>
    $results = DatabaseManager::query("SELECT visit_count.product product, visit_count.count visit_count, shopcart_count.count shopcart_count, \r\n\t\t\t\t\t\t\t\t\t\t  order_count.count order_count FROM visit_count\r\n\t\t\t\t\t\t\t\t\t\t  LEFT JOIN shopcart_count ON visit_count.product=shopcart_count.product\r\n\t\t\t\t\t\t\t\t\t\t  LEFT JOIN order_count ON visit_count.product=order_count.product");
    while ($product_row = mysql_fetch_array($results)) {
        $weight = $product_row['visit_count'] * $visit_weight;
        if ($product_row['shopcart_count'] != NULL) {
            $weight += $product_row['shopcart_count'] * $shopcart_weight;
        }
        if ($product_row['order_count'] != NULL) {
            $weight += $product_row['order_count'] * $order_weight;
        }
        DatabaseManager::query("INSERT INTO keyword_product_weight(keyword, product, weight) VALUE('{$keyword_row['keyword']}',\r\n\t\t\t\t\t\t\t\t\t'{$product_row['product']}', '{$weight}')");
    }
}
$keyword_set_train = DatabaseManager::query("SELECT keyword from keyword_train");
while ($keyword_row_train = mysql_fetch_array($keyword_set_train)) {
    DatabaseManager::query("CREATE OR REPLACE VIEW userids AS\r\n\t\t\t\t\t\t\t\tSELECT DISTINCT userid FROM preprocessed_user_train WHERE keywords LIKE '%{$keyword_row_train['keyword']}%'");
    DatabaseManager::query("CREATE OR REPLACE VIEW visit_count (product, count) AS\r\n\t\t\t\t\t\t\t\tSELECT page, count(page) FROM visit WHERE page LIKE '{$product_identifier}%' AND userid IN\r\n\t\t\t\t\t\t\t\t(SELECT DISTINCT userid FROM userids) GROUP BY page");
    DatabaseManager::query("CREATE OR REPLACE VIEW shopcart_count (product, count) AS\r\n\t\t\t\t\t\t\t\tSELECT page, count(page) FROM shopcart WHERE page LIKE '{$product_identifier}%' AND userid IN\r\n\t\t\t\t\t\t\t\t(SELECT DISTINCT userid FROM userids) GROUP BY page");
    DatabaseManager::query("CREATE OR REPLACE VIEW order_count (product, count) AS\r\n\t\t\t\t\t\t\t\tSELECT orderedItem, count(orderedItem) FROM orderrecord WHERE orderedItem LIKE '{$product_identifier}%' AND userid IN\r\n\t\t\t\t\t\t\t\t(SELECT DISTINCT userid FROM userids) GROUP BY orderedItem");
    $results_train = DatabaseManager::query("SELECT visit_count.product product, visit_count.count visit_count, shopcart_count.count shopcart_count, \r\n\t\t\t\t\t\t\t\t\t\t  order_count.count order_count FROM visit_count\r\n\t\t\t\t\t\t\t\t\t\t  LEFT JOIN shopcart_count ON visit_count.product=shopcart_count.product\r\n\t\t\t\t\t\t\t\t\t\t  LEFT JOIN order_count ON visit_count.product=order_count.product");
    while ($product_row_train = mysql_fetch_array($results_train)) {
        $weight_train = $product_row_train['visit_count'] * $visit_weight;
        if ($product_row_train['shopcart_count'] != NULL) {
            $weight_train += $product_row_train['shopcart_count'] * $shopcart_weight;
        }
        if ($product_row_train['order_count'] != NULL) {
            $weight_train += $product_row_train['order_count'] * $order_weight;
        }
        DatabaseManager::query("INSERT INTO keyword_product_weight_train(keyword, product, weight) VALUE('{$keyword_row_train['keyword']}',\r\n\t\t\t\t\t\t\t\t\t'{$product_row_train['product']}', '{$weight_train}')");
    }
}
DatabaseManager::closeDB($db);
<?php

require_once dirname(__DIR__) . '/class/DatabaseManager.php';
return;
$db = new DatabaseManager();
$json = file_get_contents("http://blocklandglass.com/downloadsExport.php");
$data = json_decode($json, true);
foreach ($data as $id => $dat) {
    $web = $dat['downloads_web'];
    $ig = $dat['downloads_ingame'];
    $up = $dat['downloads_update'];
    $total = $web + $ig + $up;
    $db->query("UPDATE `addon_stats` SET `totalDownloads` = (`totalDownloads` + {$total}),\n  `webDownloads` = (`webDownloads` + {$web}),\n  `ingameDownloads` = (`ingameDownloads` + {$ig}),\n  `updateDownloads` = (`updateDownloads` + {$up}) WHERE `aid`={$id}");
    echo $db->error();
}
 public static function getRecentUpdates($time = null)
 {
     if ($time == null) {
         $time = 60 * 24 * 7;
     }
     $db = new DatabaseManager();
     $res = $db->query("SELECT * FROM `addon_updates` WHERE `submitted` > now() - INTERVAL " . $db->sanitize($time) . " MINUTE AND `approved`=1 ORDER BY `submitted` DESC");
     echo $db->error();
     $arr = array();
     while ($obj = $res->fetch_object()) {
         $arr[] = new AddonUpdateObject($obj);
     }
     return $arr;
 }
<?php

require_once realpath(dirname(__DIR__) . '/private/class/DatabaseManager.php');
if (!isset($_REQUEST['query'])) {
    $query = "";
} else {
    $query = $_REQUEST['query'];
}
if ($query == "") {
    die("[]");
}
$db = new DatabaseManager();
$sql = "";
if (isset($_REQUEST['owner'])) {
    $sql = " AND `blid`='" . $db->sanitize($_REQUEST['owner']) . "' ";
}
$res = $db->query("SELECT `id`,`name` FROM `addon_addons` WHERE `name` LIKE '" . $db->sanitize($query) . "%' AND `approved`=1 AND `deleted`=0 {$sql}");
$ret = array();
while ($obj = $res->fetch_object()) {
    $ret[] = $obj;
}
echo json_encode($ret, JSON_PRETTY_PRINT);
<?php

require_once dirname(__DIR__) . '/class/DatabaseManager.php';
$db = new DatabaseManager();
$mods = split("-", $_GET['mods']);
$sqlString = "";
foreach ($mods as $mod) {
    if ($sqlString != "") {
        $sqlString = $sqlString . " OR ";
    }
    $sqlString = $sqlString . "rtbId='" . $db->sanitize($mod) . "'";
}
$conversions = array();
$result = $db->query("SELECT * FROM `addon_rtb` WHERE glassId IS NOT NULL AND (" . $sqlString . ")");
while ($obj = $result->fetch_object()) {
    $addonRes = $db->query("SELECT `name`,`id`,`filename` FROM `addon_addons` WHERE id=" . $obj->glassId);
    $obj->addonData = $addonRes->fetch_object();
    $conversions[] = $obj;
}
echo json_encode($conversions);
 public static function endIteration()
 {
     $database = new DatabaseManager();
     $database->query("UPDATE `addon_stats` SET `iterationDownloads`=0");
 }
<?php

require_once dirname(__DIR__) . '/class/DatabaseManager.php';
$database = new DatabaseManager();
$database->query("ALTER TABLE `addon_boards` DROP video");
$database->query("ALTER TABLE `addon_boards` ADD icon VARCHAR(24) NOT NULL default 'billboard_empty' AFTER name");
$authorDat[] = $author;
$branchId["stable"] = 1;
$branchId["unstable"] = 2;
$branchId["development"] = 3;
$file["stable"] = $res->file_stable;
$versionData = array();
foreach ($file as $branch => $fid) {
    if ($fid != 0) {
        $version = new stdClass();
        $fileRes = $mysql->query("SELECT * FROM `addon_files` WHERE `id`='" . $fid . "'");
        $hash = $fileRes->fetch_object()->hash;
        $oldfile = $dir . $hash . ".zip";
        $bid = $branchId[$branch];
        echo "Uploading {$oldfile} to AWS as {$res->id}_{$bid}.zip";
        //AWSFileManager::upload("addons/{$res->id}_{$bid}", $oldfile);
        AWSFileManager::uploadNewAddon($res->id, $bid, $res->filename, $oldfile);
        $updateRes = $mysql->query("SELECT *\nFROM  `addon_updates`\nWHERE  `aid` = '" . $aid . "'\nAND  `branch`='" . $bid . "' ORDER BY  `time` DESC\nLIMIT 0 , 1");
        if ($updateRes->num_rows == 0) {
            $version->version = "0.0.0";
            $version->restart = "0.0.0";
        } else {
            $obj = $updateRes->fetch_object();
            $version->version = $obj->version;
            $version->restart = $obj->version;
            //not worth it
        }
        $versionData[$branch] = $version;
    }
}
$db->query($sql = "INSERT INTO `addon_addons` (`id`, `board`, `blid`, `name`, `filename`, `description`, `version`, `authorInfo`, `reviewInfo`, `deleted`, `approved`, `uploadDate`) VALUES " . "('" . $db->sanitize($res->id) . "'," . "NULL," . "'" . $db->sanitize($res->author) . "'," . "'" . $db->sanitize($res->name) . "'," . "'" . $db->sanitize($res->filename) . "'," . "'" . $db->sanitize($res->description) . "'," . "'" . $db->sanitize($versionData['stable']->version) . "'," . "'" . $db->sanitize(json_encode($authorDat)) . "'," . "''," . "'0'," . "'0'," . "CURRENT_TIMESTAMP);");
echo $db->error();
$stopword_list = loadStopwords("stopword.txt");
$keywords_set = DatabaseManager::query("SELECT id, keywords FROM preprocessed_user");
while ($keywords_row = mysql_fetch_array($keywords_set)) {
    $preprocessed_keywords = preprocess_keywords($keywords_row['keywords']);
    DatabaseManager::query("UPDATE preprocessed_user SET keywords = '" . addslashes(' ' . implode(" ", $preprocessed_keywords) . ' ') . "' WHERE id = {$keywords_row['id']}");
    foreach ($preprocessed_keywords as $preprocessed_keyword) {
        DatabaseManager::query("INSERT INTO keyword(keyword) VALUE('" . addslashes($preprocessed_keyword) . "')");
    }
}
DatabaseManager::query("TRUNCATE table keyword_train");
$keywords_set_train = DatabaseManager::query("SELECT id, keywords FROM preprocessed_user_train");
while ($keywords_row_train = mysql_fetch_array($keywords_set_train)) {
    $preprocessed_keywords_train = preprocess_keywords($keywords_row_train['keywords']);
    DatabaseManager::query("UPDATE preprocessed_user_train SET keywords = '" . addslashes(' ' . implode(" ", $preprocessed_keywords_train) . ' ') . "' WHERE id = {$keywords_row['id']}");
    foreach ($preprocessed_keywords_train as $preprocessed_keyword_train) {
        DatabaseManager::query("INSERT INTO keyword_train(keyword) VALUE('" . addslashes($preprocessed_keyword_train) . "')");
    }
}
DatabaseManager::closeDB($db);
/**
 * split the keywords, remove the stopword, extract word stem from inflected variants
 */
function preprocess_keywords($keywords)
{
    global $stopword_list;
    $keywords = preg_replace("/[,&\\+\\/-]/", ' ', $keywords);
    $keys = preg_split('@ @', $keywords, NULL, PREG_SPLIT_NO_EMPTY);
    $result = array();
    foreach ($keys as $key) {
        if (!in_array($key, $stopword_list)) {
            // remove numeric string, I'm not sure whether it is proper