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: https://projects.kde.org/projects/playground/www/ocs-server 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 OCSFriend{ 0015 0016 /* 0017 * Enabling main to be on a global context. 0018 */ 0019 public function __construct(){ 0020 $this->ocs_friendinvitation = new EModel("ocs_friendinvitation"); 0021 $this->ocs_friendship = new EModel("ocs_friendship"); 0022 } 0023 0024 // /v1/friend/invite/pid 0025 public static function send_invitation($touser, $message){ 0026 $idfrom = OCSUser::id(); 0027 0028 $info = OCSUser::server_get_user_info($touser); 0029 $id = $info[0]["id"]; 0030 0031 $ocs_friendinvitation = new EModel("ocs_friendinvitation"); 0032 if(!$ocs_friendinvitation->is_there("touser","(fromuser=$idfrom and touser=$id) or (touser=$idfrom and fromuser=$id)")){ 0033 EDatabase::q("INSERT INTO ocs_friendinvitation (fromuser,touser,message) VALUES ($idfrom,$id,'$message')"); 0034 } 0035 } 0036 0037 // /v1/friend/approve/pid 0038 public static function approve_invitation($touser){ 0039 $idfrom = OCSUser::id(); 0040 $datafrom = OCSUser::server_get_user_info($idfrom); 0041 $loginfrom = $datafrom[0]["login"]; 0042 0043 0044 $info = OCSUser::server_get_user_info($touser); 0045 $id = $info[0]["id"]; 0046 0047 //creating new table object 0048 $ocs_friendinvitation = new EModel("ocs_friendinvitation"); 0049 0050 //if($ocs_friendinvitation->is_there("touser","(fromuser=$idfrom and touser=$id) or (touser=$idfrom and fromuser=$id)")) 0051 if($ocs_friendinvitation->is_there("touser","(touser=$idfrom and fromuser=$id)")) 0052 { 0053 EDatabase::q("DELETE FROM ocs_friendinvitation WHERE (fromuser=$id AND touser=$idfrom) OR (touser=$id AND fromuser=$idfrom) LIMIT 2"); 0054 EDatabase::q("INSERT IGNORE INTO ocs_friendship (id1,id2) VALUES ($idfrom,$id)"); 0055 EDatabase::q("INSERT IGNORE INTO ocs_friendship (id1,id2) VALUES ($id,$idfrom)"); 0056 0057 //adding activity messages 0058 OCSActivity::add($idfrom, 2, OCSUser::login()." became friend with $touser."); 0059 OCSActivity::add($id, 2, "$touser became friend with ".OCSUser::login()."."); 0060 } 0061 } 0062 0063 // /v1/friend/decline/pid 0064 public static function decline_invitation($touser){ 0065 $idfrom = OCSUser::id(); 0066 0067 $info = OCSUser::server_get_user_info($touser); 0068 $id = $info[0]["id"]; 0069 0070 //creating new table object 0071 $ocs_friendinvitation = new EModel("ocs_friendinvitation"); 0072 0073 EDatabase::q("DELETE FROM ocs_friendinvitation WHERE (fromuser=$id AND touser=$idfrom) OR (touser=$id AND fromuser=$idfrom) LIMIT 1"); 0074 } 0075 0076 // /v1/friend/cancel/pid 0077 public static function cancel_friendship($touser){ 0078 $idfrom = OCSUser::id(); 0079 0080 $info = OCSUser::server_get_user_info($touser); 0081 $id = $info[0]["id"]; 0082 0083 //creating new table object 0084 $ocs_friendinvitation = new EModel("ocs_friendship"); 0085 0086 EDatabase::q("DELETE FROM ocs_friendship WHERE (id1=$idfrom AND id2=$id) OR (id2=$idfrom AND id1=$id) LIMIT 2"); 0087 } 0088 0089 } 0090 0091 0092 ?>