| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | // This file is part of BOINC. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | // http://boinc.berkeley.edu | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | // Copyright (C) 2008 University of California | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | // BOINC is free software; you can redistribute it and/or modify it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | // under the terms of the GNU Lesser General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | // as published by the Free Software Foundation, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | // either version 3 of the License, or (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | // BOINC is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | // See the GNU Lesser General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | // You should have received a copy of the GNU Lesser General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | // along with BOINC.  If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | require_once("../inc/boinc_db.inc"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | #[AllowDynamicProperties] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | class BoincCategory { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     static function lookup_id($id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         return $db->lookup_id($id, 'category', 'BoincCategory'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     static function lookup($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         return $db->lookup('category', 'BoincCategory', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     static function enum($clause=null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         return $db->enum('category', 'BoincCategory', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | #[AllowDynamicProperties] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | class BoincForum { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     static function insert($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $ret = $db->insert('forum', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         if (!$ret) return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         return $db->insert_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     static function lookup_id($id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         return $db->lookup_id($id, 'forum', 'BoincForum'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     static function lookup($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         return $db->lookup('forum', 'BoincForum', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     static function enum($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         return $db->enum('forum', 'BoincForum', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     function update($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         return $db->update($this, 'forum', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     function delete() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         return $db->delete($this, 'forum'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | #[AllowDynamicProperties] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | class BoincThread { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     static function insert($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $ret = $db->insert('thread', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         if (!$ret) return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         return $db->insert_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     static function lookup_id($id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         return $db->lookup_id($id, 'thread', 'BoincThread'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     function update($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         return $db->update($this, 'thread', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     static function enum($clause="") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         return $db->enum('thread', 'BoincThread', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     function rating() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         return $this->score*$this->votes; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     function delete() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         return $db->delete($this, 'thread'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | #[AllowDynamicProperties] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | class BoincPost { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     static function insert($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $ret = $db->insert('post', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         if (!$ret) return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         return $db->insert_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     static function lookup_id($id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         return $db->lookup_id($id, 'post', 'BoincPost'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     static function count($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         return $db->count('post', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     function update($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         return $db->update($this, 'post', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     static function enum($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         return $db->enum('post', 'BoincPost', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     static function enum_general($query) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         return $db->enum_general('BoincPost', $query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |     function rating() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |         return $this->score*$this->votes; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     function delete() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         return $db->delete($this, 'post'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     static function delete_aux($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         return $db->delete_aux('post', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | #[AllowDynamicProperties] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  | class BoincForumPrefs { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 141 |  |  |     static $cache; | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |     static function lookup_userid($id) { | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |         $db = BoincDb::get(); | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |         return $db->lookup('forum_preferences', 'BoincForumPrefs', "userid=$id"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     static function insert($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |         $ret = $db->insert('forum_preferences', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     static function lookup(&$user, $nocache=false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         if (!$user) return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         if (isset($user->prefs)) return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         if (!$nocache && isset(self::$cache[$user->id])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |             $prefs = self::$cache[$user->id]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |             $prefs = self::lookup_userid($user->id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |             if (!$prefs) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |                 self::insert( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |                     sprintf( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |                         "(userid, last_post, forum_sorting, thread_sorting, rated_posts, ignorelist, pm_notification) values (%d, 0, 0, %d, '', '', 0)", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |                         $user->id, CREATE_TIME_OLD | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |                     ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |                 ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |                 $prefs = self::lookup_userid($user->id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |             self::$cache[$user->id] = $prefs; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         $user->prefs = $prefs; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     function privilege($specialbit) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |          return (substr($this->special_user, $specialbit, 1) == 1); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     function update($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         $clause = "$clause where userid=$this->userid"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         return $db->update_aux('forum_preferences', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |     function delete() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |         return $db->delete_aux('forum_preferences', "userid=$this->userid"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |     static function enum($clause=null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         return $db->enum('forum_preferences', 'BoincForumPrefs', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  | #[AllowDynamicProperties] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  | class BoincForumLogging { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |     static $cache; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |     static function replace($userid, $threadid, $timestamp) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |         return $db->replace('forum_logging', "userid=$userid, threadid=$threadid, timestamp=$timestamp"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |     static function lookup($userid, $threadid) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         return $db->lookup('forum_logging', 'BoincForumLogging', "userid=$userid and threadid=$threadid"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |     static function lookup_cached($userid, $threadid) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         if (isset(self::$cache[$threadid])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |             return self::$cache[$threadid]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |         $x = self::lookup($userid, $threadid); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         if (!$x) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |             $x = new BoincForumLogging(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |             $x->timestamp = 0; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         self::$cache[$threadid] = $x; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |     static function delete_aux($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         return $db->delete_aux('forum_logging', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     static function cleanup() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         // Every 28 days, delete records older than 28 days. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |         // Keep track of the last time we did this in a special record | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         // with userid = threadid = 0. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |         // This gets called from forum_index.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |         // (i.e. each time the forum main page is loaded). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |         $fl = BoincForumLogging::lookup(0, 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         if ($fl) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |             if ($fl->timestamp<time()-MAX_FORUM_LOGGING_TIME){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |                 BoincForumLogging::delete_aux("timestamp<'".(time()-MAX_FORUM_LOGGING_TIME)."' and userid != 0"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |                 BoincForumLogging::replace(0, 0, time()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |             // No cleanup timestamp found, make one | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |             // | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |             BoincForumLogging::replace(0, 0, 0); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  | #[AllowDynamicProperties] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  | class BoincSubscription { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |     static function lookup($userid, $threadid) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |         return $db->lookup('subscriptions', 'BoincSubscription', "userid=$userid and threadid=$threadid"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |     static function delete($userid, $threadid) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         return $db->delete_aux('subscriptions', "userid=$userid and threadid=$threadid"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |     static function enum($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |         return $db->enum('subscriptions', 'BoincSubscription', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |     static function replace($userid, $threadid) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |         return $db->replace('subscriptions', "userid=$userid, threadid=$threadid"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  | #[AllowDynamicProperties] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  | class BoincPostRating { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |     static function lookup($userid, $postid) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |         return $db->lookup('post_ratings', 'BoincPostRating', "user=$userid and post=$postid"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |     static function replace($userid, $postid, $rating) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |         return $db->replace('post_ratings', "user=$userid, post=$postid, rating=$rating"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  | #[AllowDynamicProperties] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  | class BoincFriend { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |     static function insert($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |         return $db->insert('friend', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |     static function lookup($uid1, $uid2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |         return $db->lookup('friend', 'BoincFriend', "user_src=$uid1 and user_dest=$uid2"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |     function update($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |         return $db->update_aux('friend', "$clause where user_src=$this->user_src and user_dest=$this->user_dest"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |     static function enum($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |         return $db->enum('friend', 'BoincFriend', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |     static function delete_aux($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |         return $db->delete_aux('friend', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |     static function delete($id1, $id2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |         $db->delete_aux('friend', "user_src=$id1 and user_dest=$id2"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |         $db->delete_aux('friend', "user_src=$id2 and user_dest=$id1"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |     static function replace($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |         return $db->replace('friend', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  | #[AllowDynamicProperties] | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  | class BoincNotify { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |     static function insert($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |         $ret = $db->insert('notify', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |         if (!$ret) return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |         return $db->insert_id(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |     static function replace($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 310 |  |  |         return $db->replace('notify', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 311 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 312 |  |  |     static function enum($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 313 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 314 |  |  |         return $db->enum('notify', 'BoincNotify', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 315 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 316 |  |  |     static function lookup($userid, $type, $opaque) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 317 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 318 |  |  |         return $db->lookup('notify', 'BoincNotify', "userid=$userid and type=$type and opaque=$opaque"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 319 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 320 |  |  |     function delete() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 321 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 322 |  |  |         return $db->delete($this, 'notify'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 323 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 324 |  |  |     static function delete_aux($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 325 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 326 |  |  |         $db->delete_aux('notify', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 327 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 328 |  |  |     static function enum_general($query) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 329 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 330 |  |  |         return $db->enum_general('BoincNotify', $query); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 331 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 332 |  |  |     function update($clause) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 333 |  |  |         $db = BoincDb::get(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 334 |  |  |         return $db->update($this, 'notify', $clause); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 335 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 336 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 337 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 338 |  |  | define ('NOTIFY_FRIEND_REQ', 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 339 |  |  | define ('NOTIFY_FRIEND_ACCEPT', 2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 340 |  |  | define ('NOTIFY_PM', 3); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 341 |  |  | define ('NOTIFY_SUBSCRIBED_THREAD', 4); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 342 |  |  | define ('NOTIFY_SUBSCRIBED_FORUM', 5); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 343 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 344 |  |  | ?> | 
            
                                                        
            
                                    
            
            
                | 345 |  |  |  |