File indexing completed on 2024-12-22 05:33:23
0001 <?php 0002 0003 /* 0004 * GFX 4 0005 * 0006 * support: happy.snizzo@gmail.com 0007 * website: http://trt-gfx.googlecode.com 0008 * credits: Claudio Desideri 0009 * 0010 * This software is released under the MIT License. 0011 * http://opensource.org/licenses/mit-license.php 0012 */ 0013 0014 class OCSLister{ 0015 0016 //variables 0017 private $table; 0018 private $datatable; 0019 0020 0021 public function __construct($data=""){ 0022 //setting initial value for table 0023 if(!empty($data)){ 0024 $this->table = $data; 0025 $this->datatable = new EModel($this->table); 0026 } else { 0027 $this->set_table_search($this->table); 0028 } 0029 } 0030 0031 /* 0032 * sets the database table name in which performs the search 0033 */ 0034 public function set_table_search($tbl){ 0035 //assuring $data is safe to be executed on a db query 0036 EDatabase::safe($data); 0037 //setting internal attribute 0038 if(EDatabase::table_exists($tbl)){ 0039 $this->table = $tbl; 0040 $this->datatable = new EData($this->table); 0041 } else { 0042 ELog::error("$tbl does not exists on database."); 0043 } 0044 } 0045 0046 } 0047 0048 class OCSContentLister extends OCSLister { 0049 0050 //variables 0051 private $table; 0052 private $datatable; 0053 0054 private $totalitems=0; 0055 0056 //inheriting constructor 0057 public function __construct($data="ocs_content"){ 0058 parent::__construct($data); 0059 } 0060 0061 public function ocs_content_list($searchstr,$sortmode="new",$page=1,$pagesize=10,$user="",$category=""){ 0062 0063 $whereuser = ""; 0064 $wherecategory = ""; 0065 0066 if(empty($page)){ $page=1; } 0067 //setting dynamic page size 0068 $page = abs(($page-1)*($pagesize)); 0069 switch($sortmode){ 0070 case "new": 0071 $where = "ORDER BY id DESC LIMIT $page,$pagesize"; 0072 break; 0073 case "alpha": 0074 $where = "ORDER BY name ASC LIMIT $page,$pagesize"; 0075 break; 0076 case "high": 0077 $where = "ORDER BY score DESC LIMIT $page,$pagesize"; 0078 break; 0079 case "down": 0080 $where = "ORDER BY downloads DESC LIMIT $page,$pagesize"; 0081 break; 0082 default: 0083 $where = "ORDER BY id DESC LIMIT $page,$pagesize"; 0084 break; 0085 } 0086 0087 //TODO: move this into parent class constructor 0088 // or better: inspect why datatable isn't initialized by constructor 0089 if(is_null($this->datatable)){ 0090 $this->datatable = new EModel("ocs_content"); 0091 } 0092 0093 if(!empty($searchstr)){ 0094 $this->datatable->add_condition("name LIKE '%$searchstr%'"); 0095 } 0096 0097 if(!empty($user)){ 0098 $this->datatable->add_condition("personid = '$user'"); 0099 } 0100 0101 if(!empty($category)){ 0102 $this->datatable->add_condition("type = '$category'"); 0103 } 0104 0105 $r = $this->datatable->find("id,owner,personid,description,changelog,preview1,votes,score,name,type,downloadname1,downloadlink1,version,summary,license","$where"); 0106 0107 // adjusting correct keys 0108 for($i=0;$i<count($r);$i++){ 0109 if(isset($r[$i]['preview1']) and !empty($r[$i]['preview1'])){ 0110 $r[$i]['previewpic1'] = $r[$i]['preview1']; 0111 $r[$i]['preview1'] = ''; 0112 } 0113 if(isset($r[$i]['type']) and !empty($r[$i]['type'])){ 0114 $r[$i]['typeid'] = $r[$i]['type']; 0115 unset($r[$i]['type']); 0116 } 0117 } 0118 0119 $this->totalitems = EDatabase::sq("SELECT COUNT(*) FROM ocs_content WHERE name LIKE '%$searchstr%' $whereuser $wherecategory"); 0120 0121 return $r; 0122 } 0123 0124 public function get_totalitems() 0125 { 0126 return $this->totalitems; 0127 } 0128 } 0129 0130 class OCSPersonLister extends OCSLister { 0131 0132 //variables 0133 private $table; 0134 private $datatable; 0135 0136 //inheriting constructor 0137 public function __construct($data="ocs_person"){ 0138 parent::__construct($data); 0139 } 0140 0141 public function ocs_person_search($username, $page=1,$pagesize=10){ 0142 if(empty($page)){ $page=1; } 0143 0144 //TODO: move this into parent class constructor 0145 // or better: inspect why datatable isn't initialized by constructor 0146 if(is_null($this->datatable)){ 0147 $this->datatable = new EModel("ocs_person"); 0148 } 0149 //setting dynamic page size 0150 $page = ($page-1)*($pagesize); 0151 0152 $r = $this->datatable->find("id,login,firstname,lastname,email","WHERE login LIKE '%$username%'"); 0153 return $r; 0154 } 0155 } 0156 0157 class OCSCommentLister extends OCSLister { 0158 0159 //variables 0160 private $table; 0161 private $datatable; 0162 0163 //inheriting constructor 0164 public function __construct($data="ocs_comment"){ 0165 parent::__construct($data); 0166 } 0167 0168 public function ocs_comment_list($type,$content,$content2,$page=1,$pagesize=10){ 0169 0170 if(empty($page)){ $page=1; } 0171 0172 //setting dynamic page size 0173 $page = ($page-1)*($pagesize); 0174 $where = "ORDER BY c.id ASC LIMIT $page,$pagesize"; 0175 0176 $q = "SELECT * FROM ocs_comment AS c JOIN ocs_person AS p on c.owner = p.id WHERE c.content = $content $where"; 0177 $r = EDatabase::q($q); 0178 0179 $result = array(); 0180 $i = 0; 0181 while($row=mysqli_fetch_assoc($r)){ 0182 $result[$i]["id"] = $row["id"]; 0183 $result[$i]["subject"] = $row["subject"]; 0184 $result[$i]["text"] = $row["message"]; 0185 $result[$i]["childcount"] = 0; 0186 $result[$i]["user"] = $row["login"]; 0187 $result[$i]["date"] = $row["date"]; 0188 $result[$i]["score"] = $row["score"]; 0189 $i += 1; 0190 } 0191 0192 return $result; 0193 0194 } 0195 } 0196 /* 0197 class OCSPersonLister extends OCSLister { 0198 0199 //variables 0200 private $table; 0201 private $datatable; 0202 0203 //inheriting constructor 0204 public function __construct($data="ocs_person"){ 0205 //setting initial value for table 0206 if(!empty($data)){ 0207 $this->table = $data; 0208 $this->datatable = new EData($this->table); 0209 } else { 0210 $this->set_table_search($this->table); 0211 } 0212 } 0213 0214 public function ocs_person_search($username,$page=1,$pagesize=10){ 0215 0216 if(empty($page)){ $page=1; } 0217 0218 //setting dynamic page size 0219 $page = ($page-1)*($pagesize); 0220 $where = " LIMIT $page,$pagesize"; 0221 0222 $q = "SELECT * FROM ocs_person WHERE login LIKE '%$username%' $where"; 0223 $r = EDatabase::q($q); 0224 0225 $result = array(); 0226 $i = 0; 0227 while($row=mysqli_fetch_assoc($r)){ 0228 $result[$i]["personid"] = $row["login"]; 0229 $result[$i]["firstname"] = $row["firstname"]; 0230 $result[$i]["lastname"] = $row["lastname"]; 0231 $i += 1; 0232 } 0233 0234 return $result; 0235 0236 } 0237 } 0238 */ 0239 class OCSFanLister extends OCSLister { 0240 0241 //variables 0242 private $table; 0243 private $datatable; 0244 //global instance 0245 public $main; 0246 0247 //inheriting constructor 0248 public function __construct($data="ocs_fan"){ 0249 parent::__construct($data); 0250 } 0251 0252 public function ocs_fan_list($content,$page=1,$pagesize=10){ 0253 0254 if(empty($page)){ $page=1; } 0255 0256 //setting dynamic page size 0257 $page = ($page-1)*($pagesize); 0258 0259 $person = OCSUser::id(); 0260 0261 $q = "SELECT * FROM ocs_fan AS f JOIN ocs_person AS p on f.person = p.id WHERE f.person=$person LIMIT $page,$pagesize"; 0262 $r = EDatabase::q($q); 0263 0264 $result = array(); 0265 while($row=mysqli_fetch_assoc($r)){ 0266 $result[]["personid"] = $row["login"]; 0267 } 0268 0269 return $result; 0270 0271 } 0272 } 0273 0274 class OCSFriendsLister extends OCSLister { 0275 0276 //variables 0277 private $table; 0278 private $datatable; 0279 //global instance 0280 public $main; 0281 0282 //inheriting constructor 0283 public function __construct($data="ocs_friendship"){ 0284 //setting initial value for table 0285 if(!empty($data)){ 0286 $this->table = $data; 0287 $this->datatable = new EModel($this->table); 0288 } else { 0289 $this->set_table_search($this->table); 0290 } 0291 } 0292 0293 public function ocs_friend_list($fromuser,$page=1,$pagesize=10){ 0294 0295 if(empty($page)){ $page=1; } 0296 0297 //setting dynamic page size 0298 $page = ($page-1)*($pagesize); 0299 0300 $q = "SELECT * FROM ocs_friendship AS f JOIN ocs_person AS p on (f.id1 = p.id) OR (f.id2 = p.id) WHERE p.login!='$fromuser' LIMIT $page,$pagesize"; 0301 $r = EDatabase::q($q); 0302 0303 $result = array(); 0304 while($row=mysqli_fetch_assoc($r)){ 0305 $result[]["personid"] = $row["login"]; 0306 } 0307 0308 return $result; 0309 } 0310 0311 public function ocs_sentinvitations($page=1,$pagesize=10){ 0312 $id = OCSUser::id(); 0313 0314 if(empty($page)){ $page=1; } 0315 0316 //setting dynamic page size 0317 $page = ($page-1)*($pagesize); 0318 0319 $q = "SELECT * FROM ocs_friendinvitation AS f JOIN ocs_person AS p ON f.touser = p.id WHERE f.fromuser=$id LIMIT $page,$pagesize"; 0320 $r = EDatabase::q($q); 0321 0322 $result = array(); 0323 while($row=mysqli_fetch_assoc($r)){ 0324 $result[]["personid"] = $row["login"]; 0325 } 0326 0327 return $result; 0328 } 0329 0330 public function ocs_receivedinvitations($page=1,$pagesize=999){ 0331 $id = OCSUser::id(); 0332 0333 if(empty($page)){ $page=1; } 0334 0335 //setting dynamic page size 0336 $page = ($page-1)*($pagesize); 0337 0338 $q = "SELECT * FROM ocs_friendinvitation AS f JOIN ocs_person AS p ON f.fromuser = p.id WHERE f.touser=$id LIMIT $page,$pagesize"; 0339 $r = EDatabase::q($q); 0340 0341 $result = array(); 0342 0343 /* 0344 $i = 0; 0345 while($row=mysqli_fetch_assoc($r)){ 0346 $result[$i]["personid"] = $row["login"]; 0347 $result[$i]["message"] = $row["message"]; 0348 } 0349 $i += 1; 0350 */ 0351 0352 while($row=mysqli_fetch_assoc($r)){ 0353 $result[]["personid"] = $row["login"]; 0354 } 0355 0356 return $result; 0357 } 0358 } 0359 0360 class OCSActivityLister extends OCSLister { 0361 0362 //variables 0363 private $table; 0364 private $datatable; 0365 //global instance 0366 public $main; 0367 0368 //inheriting constructor 0369 public function __construct($data="ocs_activity"){ 0370 //setting initial value for table 0371 if(!empty($data)){ 0372 $this->table = $data; 0373 $this->datatable = new EModel($this->table); 0374 } else { 0375 $this->set_table_search($this->table); 0376 } 0377 } 0378 0379 public function ocs_activity_list($user,$page=1,$pagesize=10){ 0380 0381 if(empty($page)){ $page=1; } 0382 0383 //setting dynamic page size 0384 $page = ($page-1)*($pagesize); 0385 0386 $id = OCSUser::id(); 0387 $q = "SELECT a.id, a.type, a.person, a.timestamp, a.message, p.login, p.firstname, p.lastname, p.email FROM ocs_activity AS a JOIN ocs_person AS p ON a.person=p.id WHERE a.person IN (SELECT f.id2 FROM ocs_friendship AS f JOIN ocs_person AS p on (f.id1 = p.id) WHERE p.login='".OCSUser::login()."') LIMIT $page,$pagesize;"; 0388 $r = EDatabase::q($q); 0389 0390 $result = array(); 0391 $i = 0; 0392 while($row=mysqli_fetch_assoc($r)){ 0393 $result[$i]["id"] = $row["id"]; 0394 $result[$i]["firstname"] = $row["firstname"]; 0395 $result[$i]["lastname"] = $row["lastname"]; 0396 $result[$i]["personid"] = $row["login"]; 0397 $result[$i]["timestamp"] = $row["timestamp"]; 0398 $result[$i]["type"] = $row["type"]; 0399 $result[$i]["message"] = $row["message"]; 0400 $i += 1; 0401 } 0402 0403 return $result; 0404 0405 } 0406 } 0407 0408 ?>