Exemplo n.º 1
0
 public function create($board, $email, $from = null)
 {
     $this->board = $board;
     $this->board_id = $board->boardid;
     $this->email = $email;
     $this->hash = md5(uniqid(rand(), true));
     $this->date = time();
     if ($from) {
         $this->from = $from;
         $this->from_id = $from->userid;
     }
     //$sql = "INSERT INTO invitations (inv_email, inv_board_id, inv_hash, inv_date) VALUES('$to', " . $this->boardid . ", '$hash', '" .SC::dbDate() . "')";
     $insert_array = array("inv_email" => SC::dbString($this->email), "inv_board_id" => $this->board->boardid, "inv_hash" => SC::dbString($this->hash), "inv_date" => SC::dbDate($this->date, true), "inv_from_id" => $this->from_id);
     $db = new SCDB();
     $db->insertFromArray($insert_array, "invitations");
     $invite_id = mysql_insert_id($db->conn);
     if ($invite_id) {
         $this->id = $invite_id;
     } else {
         throw new InviteException(mysql_error($db->conn));
     }
     $this->sendEmail();
     return $this;
 }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
 public function create()
 {
     //$userid, $subject, $text, $source=false) {
     if (!$this->author() || !$this->author()->userid) {
         throw new ThreadException("You need a valid userid to create a thread");
     }
     if (!$this->boardid) {
         throw new ThreadException("You need a valid boardid to create a thread");
     }
     if (!$this->subject) {
         throw new ThreadException("You need a subject to create a thread");
     }
     if (!$this->text && !$this->media) {
         throw new ThreadException("You need a valid message to create a thread");
     }
     if (!$this->author()->isMemberOf($this->boardid)) {
         throw new ThreadException("You may only create threads for boards you belong to", 401);
     }
     if ($this->type == "image") {
         $asset = new SCAsset($this->author()->userid, $this->media);
         $this->media = $asset->hash;
     }
     //$sql = "INSERT INTO messages (msg_date, msg_author, msg_subject, msg_text, msg_board_id" . ($source ? ", msg_source" : "") . ") VALUES('".SC::dbDate()."', $userid, '".SC::dbString($subject) ."', '" .SC::dbString($text) ."', " . $this->boardid  . ($source ? ", '" . SC::dbString($source) . "'" : "") . ")";
     $db = new SCDB();
     //$db->query($sql);
     $insert_array = array("msg_date" => SC::dbDate(), "msg_author" => SC::dbString($this->author()->userid, true), "msg_subject" => SC::dbString($this->subject, true), "msg_text" => SC::dbString($this->text, true), "msg_board_id" => $this->boardid, "msg_source" => SC::dbString($this->source, true), "msg_type" => SC::dbString($this->type, true));
     if ($this->media) {
         $insert_array["msg_media"] = SC::dbString($this->media, true);
     }
     if ($this->caption) {
         $insert_array["msg_media_caption"] = SC::dbString($this->caption, true);
     }
     $db->insertFromArray($insert_array, "messages");
     $newthread = mysql_insert_id($db->conn);
     if ($newthread) {
         /*
         			if(!SC::isLocal()) {
         				$user = SCUser::newFromId($userid);
         				$Name = "Switchcomb"; //senders name
         				$email = $this->boardid."@boards.switchcomb.com"; //senders e-mail adress
         				$recipient = ""; //recipient
         				$mail_body = "Posted By: " . $user->displayname . "\n\n" .str_replace("<br/>", "\n", $text); //mail body
         				$subject = "[" . $newthread . "] $subject"; //subject
         				$header = "From: ". $Name . " <" . $email . ">\r\nBcc:" . SC::emailList() ."\r\n"; //optional headerfields
         
         				mail($recipient, $subject, $mail_body, $header); //mail command :)
         			}
         */
         $thread = new SCThread($newthread);
         $this->fromArray($thread->toArray());
         try {
             $messageMail = SCEmail::newMessageEmail($thread);
             $messageMail->sendEmail();
         } catch (Exception $ex) {
         }
         return $this;
     } else {
         throw new ThreadException(mysql_error($db->conn));
     }
 }
Exemplo n.º 4
0
 public function saveAsset()
 {
     $meta = array("orig-name" => $this->orig_path);
     $s3 = new S3(awsAccessKey, awsSecretKey, false);
     if ($s3->putObject($this->toArray(), SC_IMAGEBUCKET, $this->path(), S3::ACL_PUBLIC_READ, $meta)) {
         $db = new SCDB();
         $type_array = explode("/", $this->type);
         $db_array = array("asset_user_id" => $this->creatorid, "asset_hash" => SC::dbString($this->hash), "asset_createdate" => SC::dbDate($this->create_time), "asset_type" => SC::dbString($type_array[0]), "asset_mime_type" => SC::dbString($this->type), "asset_orig_path" => SC::dbString($this->orig_path), "asset_size" => $this->size, "asset_folder" => SC::dbString($this->folder));
         $db->insertFromArray($db_array, "assets");
         //echo $this->url();
     }
 }
Exemplo n.º 5
0
 public function create($password = null, $confirm_password = null)
 {
     if ($this->existing) {
         throw new Exception("This is an existing user... you can not create an existing user", 400);
     }
     if (!$password || !$confirm_password) {
         throw new Exception("Password and Password Confirmation are required", 400);
     }
     if (strcmp($password, $confirm_password) !== 0) {
         throw new Exception("Password and Password Confirmation do not match", 400);
     }
     $create_array = $this->toArray(true);
     $create_array["user_password"] = SC::dbString(SCUser::saltPassword($password), true);
     $create_array["user_createdate"] = SC::dbDate();
     $db = new SCDB();
     $db->insertFromArray($create_array, "users");
     $user_id = mysql_insert_id($db->conn);
     if ($user_id) {
         $user = new SCUser($user_id);
         $this->fromArray($user->toArray());
     } else {
         throw new UserException(mysql_error($db->conn));
     }
     return $this;
 }
Exemplo n.º 6
0
 public function create($invite = false)
 {
     if (!$this->userid) {
         throw new MembershipException("You can not create a memebership without a userid", 400);
     }
     if (!$this->boardid) {
         throw new MembershipException("You can not create a memebership without a boardid", 400);
     }
     $this->join_date = SC::dbDate();
     $db = new SCDB();
     $insert_array = array("mem_user_id" => $this->userid, "mem_board_id" => $this->boardid, "mem_admin_level" => $this->admin_level, "mem_joindate" => $this->join_date, "mem_receives_emails" => $this->receives_emails);
     $db->insertFromArray($insert_array, "memberships");
     $membership_id = mysql_insert_id($db->conn);
     if ($membership_id) {
         $this->loadFromMembershipId($membership_id);
         if ($invite && $invite instanceof SCInvite) {
             $invite->setAccepted();
         }
     } else {
         throw new MembershipException(mysql_error($db->conn));
     }
     return $this;
 }
Exemplo n.º 7
0
 public function create()
 {
     /*
     if((!$this->author || !$this->author->existing) && $this->authorid) {
       $this->author = new SCUser($this->authorid);
     }
     */
     if (!$this->author() || !$this->author()->userid) {
         throw new MessageException("You need a valid userid to create a message");
     }
     if (!$this->threadid) {
         throw new MessageException("You need a valid threadid to create a message");
     }
     if (!$this->boardid) {
         throw new MessageException("You need a valid boardid to create a message");
     }
     if (!$this->text && !$this->media) {
         throw new MessageException("You need valid message content to create a message");
     }
     if ($this->type == "image") {
         $asset = new SCAsset($this->author()->userid, $this->media);
         $this->media = $asset->hash;
     }
     //$sql = "INSERT INTO messages (msg_date, msg_author, msg_subject, msg_text, msg_board_id" . ($source ? ", msg_source" : "") . ") VALUES('".SC::dbDate()."', $userid, '".SC::dbString($subject) ."', '" .SC::dbString($text) ."', " . $this->boardid  . ($source ? ", '" . SC::dbString($source) . "'" : "") . ")";
     $db = new SCDB();
     //$db->query($sql);
     $insert_array = array("msg_date" => SC::dbDate(), "msg_author" => SC::dbString($this->author()->userid, true), "msg_subject" => SC::dbString($this->subject, true), "msg_text" => SC::dbString($this->text, true), "msg_thread" => $this->threadid, "msg_board_id" => $this->boardid, "msg_source" => SC::dbString($this->source, true), "msg_type" => SC::dbString($this->type, true));
     if ($this->media) {
         $insert_array["msg_media"] = SC::dbString($this->media, true);
     }
     if ($this->caption) {
         $insert_array["msg_media_caption"] = SC::dbString($this->caption, true);
     }
     $db->insertFromArray($insert_array, "messages");
     $newmessage = mysql_insert_id($db->conn);
     if ($newmessage) {
         $message = new SCMessage($newmessage);
         $this->fromArray($message->toArray());
         try {
             $messageMail = SCEmail::newMessageEmail($message);
             $messageMail->sendEmail();
         } catch (Exception $ex) {
         }
         return $this;
     } else {
         throw new MessageException(mysql_error($db->conn));
     }
 }