Ejemplo n.º 1
0
 /**
  * cid : recipient
  * uid : sender
  * msg : message to send
  */
 public static function postMsgToChannel($cid, $uid, $body, $type = 'msg')
 {
     $mid = self::generateMid($cid);
     $msg = array('id' => $mid, 'sender' => $uid, 'recipient' => 'channel|' . $cid, 'type' => $type, 'body' => $body, 'timestamp' => time());
     // json encode msg before storing
     $msg = json_encode($msg);
     // search users subscribed to the channel
     foreach (Container_channels::getChannelUsers($cid) as $subuid) {
         // post this message on each users subscribed on the channel
         // /users/:uid/pending/
         if ($subuid != $uid) {
             // don't post message to the sender
             $umdir = Container_users::getDir() . '/' . $subuid . '/messages';
             file_put_contents($umdir . '/' . $mid, $msg);
         }
     }
     return $msg;
 }
Ejemplo n.º 2
0
 // check user acces
 session_start();
 if (!isset($_SESSION['userdata']) or !isset($_SESSION['userdata']['id'])) {
     $res->status(401);
     // Need to authenticate
     return;
 }
 $online_uid = $_SESSION['userdata']['id'];
 // check this user is online
 if (!Container_users::checkUserExists($online_uid)) {
     $res->status(400);
     // User is not connected
     return;
 }
 // check this user has joined the channel
 if (!Container_channels::checkChannelUser($cid, $online_uid)) {
     $res->status(403);
     // You have to join channel
     return;
 }
 // check this user is an operator on this channel
 if (!Container_channels_op::isOp($cid, $online_uid)) {
     $res->status(403);
     // You have to be an operator to unban a user
     return;
 }
 // removes name64 from the ban list
 $banlist = Container_channels_ban::getBanList($cid);
 $ok = Container_channels_ban::rmBan($cid, $name64);
 if ($ok) {
     // check if the user is in the ban list
Ejemplo n.º 3
0
 public static function leaveChannel($uid, $cid)
 {
     $ret = true;
     // clean user data
     $ucpath = self::getDir() . '/' . $uid . '/channels/' . $cid;
     if (file_exists($ucpath)) {
         unlink($ucpath);
     } else {
         $ret = false;
     }
     // clean channel data
     $cupath = Container_channels::getChannelUserPath($cid, $uid);
     if (file_exists($cupath)) {
         unlink($cupath);
     } else {
         $ret = false;
     }
     // clean channel operator flag
     $p = $ucpath . '/op/' . $uid;
     if (file_exists($p)) {
         unlink($p);
     }
     return $ret;
 }
Ejemplo n.º 4
0
 /**
  * Returns the ban reason
  */
 public static function getBanInfo($cid, $name)
 {
     $cdir = Container_channels::getChannelsDir();
     $p = $cdir . '/' . $cid . '/ban/' . base64_encode($name);
     return file_exists($p) ? json_decode(file_get_contents($p), true) : '{}';
 }
Ejemplo n.º 5
0
 /**
  * Check if $uid is an operator on $cid
  */
 public static function isOp($cid, $uid)
 {
     $cdir = Container_channels::getChannelsDir();
     $p = $cdir . '/' . $cid . '/op/' . $uid;
     return file_exists($p);
 }