2007-11-10 00:32:42 +00:00
|
|
|
<?php
|
2008-08-05 22:43:14 +00:00
|
|
|
// This file is part of BOINC.
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2008 University of California
|
|
|
|
//
|
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2007-11-10 00:32:42 +00:00
|
|
|
|
|
|
|
require_once("../inc/boinc_db.inc");
|
|
|
|
|
|
|
|
class BoincCategory {
|
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_id($id, 'category', 'BoincCategory');
|
|
|
|
}
|
2007-11-15 23:56:24 +00:00
|
|
|
static function enum($clause=null) {
|
2007-11-10 00:32:42 +00:00
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('category', 'BoincCategory', $clause);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BoincForum {
|
2007-11-14 21:55:05 +00:00
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
$ret = $db->insert('forum', $clause);
|
|
|
|
if (!$ret) return null;
|
|
|
|
return $db->insert_id();
|
|
|
|
}
|
2007-11-10 00:32:42 +00:00
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_id($id, 'forum', 'BoincForum');
|
|
|
|
}
|
2007-11-14 21:55:05 +00:00
|
|
|
static function lookup($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('forum', 'BoincForum', $clause);
|
|
|
|
}
|
2007-11-10 00:32:42 +00:00
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('forum', 'BoincForum', $clause);
|
|
|
|
}
|
|
|
|
function update($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->update($this, 'forum', $clause);
|
|
|
|
}
|
2007-11-16 21:31:43 +00:00
|
|
|
function delete() {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->delete($this, 'forum');
|
|
|
|
}
|
2007-11-10 00:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoincThread {
|
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
$ret = $db->insert('thread', $clause);
|
|
|
|
if (!$ret) return null;
|
|
|
|
return $db->insert_id();
|
|
|
|
|
|
|
|
}
|
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_id($id, 'thread', 'BoincThread');
|
|
|
|
}
|
|
|
|
function update($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->update($this, 'thread', $clause);
|
|
|
|
}
|
2008-06-19 03:58:19 +00:00
|
|
|
static function enum($clause="") {
|
2007-11-10 00:32:42 +00:00
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('thread', 'BoincThread', $clause);
|
|
|
|
}
|
|
|
|
|
|
|
|
function rating() {
|
|
|
|
return $this->score*$this->votes;
|
|
|
|
}
|
2007-11-23 00:51:01 +00:00
|
|
|
function delete() {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->delete($this, 'thread');
|
|
|
|
}
|
2007-11-10 00:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoincPost {
|
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
$ret = $db->insert('post', $clause);
|
|
|
|
if (!$ret) return null;
|
|
|
|
return $db->insert_id();
|
|
|
|
}
|
|
|
|
static function lookup_id($id) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup_id($id, 'post', 'BoincPost');
|
|
|
|
}
|
|
|
|
static function count($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->count('post', $clause);
|
|
|
|
}
|
|
|
|
function update($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->update($this, 'post', $clause);
|
|
|
|
}
|
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('post', 'BoincPost', $clause);
|
|
|
|
}
|
|
|
|
static function enum_general($query) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum_general('BoincPost', $query);
|
|
|
|
}
|
|
|
|
function rating() {
|
|
|
|
return $this->score*$this->votes;
|
|
|
|
}
|
2007-11-23 00:51:01 +00:00
|
|
|
function delete() {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->delete($this, 'post');
|
|
|
|
}
|
2007-11-10 00:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoincForumPrefs {
|
|
|
|
static $cache;
|
|
|
|
static function lookup_userid($id) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('forum_preferences', 'BoincForumPrefs', "userid=$id");
|
|
|
|
}
|
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
$ret = $db->insert('forum_preferences', $clause);
|
|
|
|
}
|
2007-11-30 00:32:29 +00:00
|
|
|
static function lookup(&$user, $nocache=false) {
|
2007-11-10 00:32:42 +00:00
|
|
|
if (!$user) return;
|
|
|
|
if (isset($user->prefs)) return;
|
2007-11-30 00:32:29 +00:00
|
|
|
if (!$nocache && isset(self::$cache[$user->id])) {
|
2007-11-15 22:51:05 +00:00
|
|
|
$prefs = self::$cache[$user->id];
|
2007-11-10 00:32:42 +00:00
|
|
|
} else {
|
|
|
|
$prefs = self::lookup_userid($user->id);
|
|
|
|
if (!$prefs) {
|
2007-11-19 02:17:57 +00:00
|
|
|
self::insert("(userid, thread_sorting, pm_notification) values ($user->id, 8, 0)");
|
2007-11-29 16:47:56 +00:00
|
|
|
$prefs = self::lookup_userid($user->id);
|
2007-11-10 00:32:42 +00:00
|
|
|
$prefs->userid = $user->id;
|
|
|
|
$prefs->thread_sorting = 6;
|
|
|
|
}
|
2007-11-15 22:51:05 +00:00
|
|
|
self::$cache[$user->id] = $prefs;
|
2007-11-10 00:32:42 +00:00
|
|
|
}
|
|
|
|
$user->prefs = $prefs;
|
|
|
|
}
|
|
|
|
function privilege($specialbit) {
|
|
|
|
return (substr($this->special_user, $specialbit,1)==1);
|
|
|
|
}
|
|
|
|
function update($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
$clause = "$clause where userid=$this->userid";
|
|
|
|
return $db->update_aux('forum_preferences', $clause);
|
|
|
|
}
|
2007-11-13 17:18:34 +00:00
|
|
|
function delete() {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->delete_aux('forum_preferences', "userid=$this->userid");
|
|
|
|
}
|
2007-11-10 00:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoincForumLogging {
|
|
|
|
static $cache;
|
|
|
|
static function replace($userid, $threadid, $timestamp) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->replace('forum_logging', "userid=$userid, threadid=$threadid, timestamp=$timestamp");
|
|
|
|
}
|
|
|
|
static function lookup($userid, $threadid) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('forum_logging', 'BoincForumLogging', "userid=$userid and threadid=$threadid");
|
|
|
|
}
|
|
|
|
static function lookup_cached($userid, $threadid) {
|
2007-11-15 22:51:05 +00:00
|
|
|
if (isset(self::$cache[$threadid])) {
|
|
|
|
return self::$cache[$threadid];
|
2007-11-10 00:32:42 +00:00
|
|
|
}
|
|
|
|
$x = self::lookup($userid, $threadid);
|
|
|
|
if (!$x) {
|
|
|
|
$x = new BoincForumLogging();
|
|
|
|
$x->timestamp = 0;
|
|
|
|
}
|
2007-11-15 22:51:05 +00:00
|
|
|
self::$cache[$threadid] = $x;
|
2007-11-10 00:32:42 +00:00
|
|
|
}
|
|
|
|
static function cleanup() {
|
|
|
|
// TODO - clean this up
|
|
|
|
|
|
|
|
$db = BoincDb::get();
|
|
|
|
$sql = "SELECT timestamp FROM DBNAME.forum_logging where userid=0 and threadid=0";
|
|
|
|
$result=$db->do_query($sql);
|
|
|
|
if (mysql_num_rows($result)>0) {
|
|
|
|
$data=mysql_fetch_object($result);
|
|
|
|
if ($data->timestamp<time()-MAX_FORUM_LOGGING_TIME){
|
|
|
|
$sql = "DELETE FROM DBNAME.forum_logging where timestamp<'".(time()-MAX_FORUM_LOGGING_TIME)."' and userid != 0";
|
|
|
|
$db->do_query($sql);
|
|
|
|
echo mysql_error();
|
|
|
|
$sql = "REPLACE INTO DBNAME.forum_logging set userid=0, threadid=0, timestamp='".time()."'";
|
|
|
|
$db->do_query($sql);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//No cleanup timestamp found, make one:
|
|
|
|
$sql = "INSERT INTO DBNAME.forum_logging set userid=0, threadid=0, timestamp=0";
|
|
|
|
$db->do_query($sql);
|
|
|
|
echo mysql_error();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class BoincSubscription {
|
|
|
|
static function lookup($userid, $threadid) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('subscriptions', 'BoincSubscription', "userid=$userid and threadid=$threadid");
|
|
|
|
}
|
|
|
|
static function delete($userid, $threadid) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->delete_aux('subscriptions', "userid=$userid and threadid=$threadid");
|
|
|
|
}
|
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('subscriptions', 'BoincSubscription', $clause);
|
|
|
|
}
|
2007-11-12 16:00:37 +00:00
|
|
|
static function replace($userid, $threadid) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->replace('subscriptions', "userid=$userid, threadid=$threadid");
|
|
|
|
}
|
2007-11-10 00:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoincPostRating {
|
|
|
|
static function lookup($userid, $postid) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('post_ratings', 'BoincPostRating', "user=$userid and post=$postid");
|
|
|
|
}
|
|
|
|
static function replace($userid, $postid, $rating) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->replace('post_ratings', "user=$userid, post=$postid, rating=$rating");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-18 20:28:08 +00:00
|
|
|
class BoincFriend {
|
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->insert('friend', $clause);
|
|
|
|
}
|
|
|
|
static function lookup($uid1, $uid2) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('friend', 'BoincFriend', "user_src=$uid1 and user_dest=$uid2");
|
|
|
|
}
|
|
|
|
function update($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->update_aux('friend', "$clause where user_src=$this->user_src and user_dest=$this->user_dest");
|
|
|
|
}
|
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('friend', 'BoincFriend', $clause);
|
|
|
|
}
|
2007-12-30 22:02:16 +00:00
|
|
|
static function delete($id1, $id2) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
$db->delete_aux('friend', "user_src=$id1 and user_dest=$id2");
|
|
|
|
$db->delete_aux('friend', "user_src=$id2 and user_dest=$id1");
|
|
|
|
}
|
|
|
|
static function replace($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->replace('friend', $clause);
|
|
|
|
}
|
2007-12-18 20:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class BoincNotify {
|
|
|
|
static function insert($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
$ret = $db->insert('notify', $clause);
|
|
|
|
if (!$ret) return null;
|
|
|
|
return $db->insert_id();
|
|
|
|
}
|
2007-12-30 22:02:16 +00:00
|
|
|
static function replace($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->replace('notify', $clause);
|
|
|
|
}
|
2007-12-18 20:28:08 +00:00
|
|
|
static function enum($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum('notify', 'BoincNotify', $clause);
|
|
|
|
}
|
|
|
|
static function lookup($userid, $type, $opaque) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->lookup('notify', 'BoincNotify', "userid=$userid and type=$type and opaque=$opaque");
|
|
|
|
}
|
|
|
|
function delete() {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->delete($this, 'notify');
|
|
|
|
}
|
2007-12-30 22:02:16 +00:00
|
|
|
function delete_aux($clause) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
$db->delete_aux('notify', $clause);
|
|
|
|
}
|
|
|
|
static function enum_general($query) {
|
|
|
|
$db = BoincDb::get();
|
|
|
|
return $db->enum_general('BoincNotify', $query);
|
|
|
|
}
|
2007-12-18 20:28:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
define ('NOTIFY_FRIEND_REQ', 1);
|
|
|
|
define ('NOTIFY_FRIEND_ACCEPT', 2);
|
2007-12-30 22:02:16 +00:00
|
|
|
define ('NOTIFY_PM', 3);
|
|
|
|
define ('NOTIFY_SUBSCRIBED_POST', 4);
|
2007-12-18 20:28:08 +00:00
|
|
|
|
2007-11-10 00:32:42 +00:00
|
|
|
?>
|