private function loadMessageEmailRecipients($message) { $board = new SCBoard($message->boardid); $memberships = $board->memberships(true); if (!sizeof($memberships->memberships)) { throw new EmailException("No members on this board receive emails"); } $email_list = array(); foreach ($memberships->memberships as $id => $membership) { $email_list[] = $membership->user->email; } return implode(", ", $email_list); }
public function create() { if (!$this->boardname) { throw new BoardException("You must give the board a name", 400); } if (!$this->description) { $description = ""; } if (!$this->privacy) { $this->privacy = 0; } else { $this->privacy = 1; } /* if((!$this->creating || !$this->creator()->existing) && $this->creatorid) { $this->creator = new SCUser($this->creatorid); } */ if ($this->creator()->existing) { $db = new SCDB(); $this->createdate = SC::dbDate(); //$sql = "INSERT INTO boards (brd_name, brd_creator, brd_createdate, brd_privacy, brd_description) VALUES('" . SC::dbString($boardname) ."', " . $userid . ", '" . $createdate . "', $privacy, '" . SC::dbString($description) . "')"; //$db->query($sql); $insert_array = array("brd_name" => SC::dbString($this->boardname, true), "brd_creator" => $this->creator()->userid, "brd_createdate" => $this->createdate, "brd_privacy" => $this->privacy, "brd_description" => SC::dbString($this->description, true)); $db->insertFromArray($insert_array, "boards"); if (mysql_insert_id($db->conn)) { $new_board = new SCBoard(mysql_insert_id($db->conn)); $this->fromArray($new_board->toArray()); $this->addUser($this->creatorid, 10); return $this; } else { $this->setNull(); //$this->message = mysql_error($db->conn) . "\n" . $sql; //echo($this->message); } } else { throw new BoardException("You must have a valid user to create a board", 401); } }
public function createMembership($boardid = false, $admin_level = 0, $receives_emails = false) { if (!$this->userid) { throw new UserException("You must have an existing user to join a board"); } $board = new SCBoard($boardid); $ok = false; $invite_id = 0; $invite = null; if ($invite_code) { $invite = new SCInvite($invite_code); $invite_id = $board->checkInvite($invite); if ($invite_id) { $ok = true; } } else { if (!$board->privacy || $admin_level == 10) { $ok = true; } } if ($ok) { $membership = new SCMembership(); $membership->userid = $this->userid; $membership->boardid = $board->boardid; return $membership->create($invite); } else { throw new UserException("This is a private board. if you have an email invitation, please use the link from there to join."); } }
public function memberships_create($params = null) { // aka join board if ($params && isset($params["__partial"])) { return null; } if ($params === null) { $this->requireRequestType("PUT"); $current_user = $this->requireLogin("You must be logged in to join a board"); $params = $_GET; $put_params = $this->getPutDeleteParams(); $params = array_merge($params, $put_params); //$params["boardid"] = SC::getParam("boardid"); //$params["userid"] = SC::getParam("userid"); //$params["receives_emails"] = SC::getParam("receives_emails"); if (!$params["userid"]) { throw new APIException("No user is specified.", 401); } if (intval($params["userid"]) != intval($current_user->userid)) { throw new APIException("You may only attempt to join a board yourself", 403); } } $board = new SCBoard($params["boardid"]); $board->addUser($current_user->userid, 0, $params["receives_emails"], $params["invitecode"]); SC::updateSessionUser(); return $board; }
#!/usr/bin/php -q <?php $from_email = true; require_once 'sc_lib.php'; // read from stdin $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); $sc_email = new SCEmailParser($email); try { if ($sc_email->boardid) { $board = new SCBoard($sc_email->boardid); $user = new SCUser($sc_email->from_address); $user_id = $user->userid; if ($user->isMemberOf($board->boardid)) { $message_array = array("authorid" => $user_id, "text" => $sc_email->body, "source" => "email"); if ($sc_email->attachment) { $message_array["type"] = "image"; $message_array["attachment"] = array("uploadmedia" => $sc_email->attachment); } if ($sc_email->threadid) { if ($board->hasMessage($sc_email->threadid)) { $thread = new SCThread($sc_email->threadid); $thread->addMessage($message_array); } else { throw new Exception("thread " . $sc_email->threadid . " not in board " . $sc_email->boardid); } } else {