Exemplo n.º 1
0
 public function addThread($thread_init)
 {
     $thread = new SCThread($thread_init);
     $thread->boardid = $this->boardid;
     return $thread->create();
 }
Exemplo n.º 2
0
 public function threads_messages_index($params = null)
 {
     // aka get messages
     if ($params && isset($params["__partial"])) {
         return array("partial" => "thread/thread_messages", "val" => "messages");
     }
     if ($params === null) {
         $this->requireRequestType("GET");
         /*
               $params = array(
                 "threadid"=>SC::getParam("threadid"),
                 "since"=>SC::getParam("since")
               );*/
         $params = $_GET;
     }
     $current_user = $this->requireLogin("You must be logged in to view the messages on a thread");
     $thread = new SCThread($params["threadid"]);
     if (!$current_user->isMemberOf($thread->boardid)) {
         throw new APIException("You can only view messages from threads in boards you belong to", 403);
     }
     $thread->getMessages(false, $params["since"]);
     if (!$params["noupdate"]) {
         $thread->getMessageCount();
         $current_user->setThreadViews($thread->messageid, $thread->message_count);
     }
     return $thread->messages();
 }
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
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 {
                $message_array["subject"] = $sc_email->subject;
                $board->addThread($message_array);
            }
        } else {
            throw new Exception("you dont belong to board " . $sc_email->boardid);
        }
    } else {
        throw new Exception("no board id was passed");
    }
} catch (Exception $ex) {