Exemplo n.º 1
0
 public function setViewCount($count, $threadid = false)
 {
     $thread = $this->threads;
     if (is_array($this->threads)) {
         if ($threadid) {
             $thread = $this->threads[$thread];
         } else {
             throw new ViewedException("You have to specify a single thread to update the view count for");
         }
     }
     $db = new SCDB();
     if (isset($this->view_ids[$thread])) {
         $update_array = array("view_msg_count" => $count);
         $where = "WHERE view_id = " . $this->view_ids[$thread];
         $db->updateFromArray($update_array, "viewed", $where);
         if (mysql_error($db->conn) !== "") {
             throw new ViewedException(mysql_error($db->conn));
         }
     } else {
         $insert_array = array("view_user_id" => $this->user->userid, "view_msg_count" => $count, "view_msg_id" => $thread);
         $db->insertFromArray($insert_array, "viewed");
         $view_id = mysql_insert_id($db->conn);
         if ($view_id) {
             $this->view_ids[$thread] = $view_id;
         } else {
             throw new ViewedException(mysql_error($db->conn));
         }
     }
     $this->view_counts[$thread] = $count;
     return $this;
 }
Exemplo n.º 2
0
 public function doLoadBoards($privacy = false, $count = false, $start = 0, $which = 0, $orderbymostrecent = false)
 {
     $limitclause = $privacyclause = "";
     if (!$start) {
         $start = 0;
     }
     if ($count) {
         $limitclause = " LIMIT {$start}, {$count}";
     }
     if ($privacy !== false && $privacy !== null) {
         $privacyclause = " b.brd_privacy={$privacy} ";
     }
     if ($this->userid && $which) {
         if ($which > 0) {
             /*
             				if($orderbymostrecent) {
             					//$sql = "SELECT q1.*, q2.max_date FROM (SELECT * FROM boards b, memberships m WHERE b.brd_id = m.mem_board_id AND m.mem_user_id=".$this->userid . ($privacyclause ? "AND $privacyclause" : "") . ") as q1 LEFT OUTER JOIN (SELECT MAX(msg_date) as max_date, mem_board_id FROM messages msg, memberships mem WHERE msg.msg_board_id=mem.mem_board_id GROUP BY mem_board_id) as q2 ON q1.brd_id=q2.mem_board_id ORDER BY max_date DESC $limitclause";
             					$sql = "SELECT q1.*, q2.lastpost FROM (SELECT * FROM boards b, memberships m, users u WHERE b.brd_creator=u.user_id AND b.brd_id = m.mem_board_id AND m.mem_user_id=".$this->userid . ($privacyclause ? "AND $privacyclause" : "") . ") as q1 LEFT OUTER JOIN (SELECT MAX(msg_date) as lastpost, mem_board_id FROM messages msg, memberships mem WHERE msg.msg_board_id=mem.mem_board_id GROUP BY mem_board_id) as q2 ON q1.brd_id=q2.mem_board_id ORDER BY lastpost DESC $limitclause";
             				}
             				else {
             					//$sql = "SELECT * FROM boards b, memberships m WHERE b.brd_id = m.mem_board_id AND m.mem_user_id=".$this->userid . ($privacyclause ? "AND $privacyclause" : "") . " ORDER BY b.brd_id DESC ".$limitclause;
             					$sql = "SELECT * FROM boards b, memberships m, users u WHERE b.brd_creator=u.user_id AND b.brd_id = m.mem_board_id AND m.mem_user_id=".$this->userid . ($privacyclause ? "AND $privacyclause" : "") . " ORDER BY b.brd_id DESC ".$limitclause;
             				}
             */
         } elseif ($which < 0) {
             //$sql = "SELECT * FROM boards b WHERE b.brd_id NOT IN (SELECT mem_board_id FROM memberships m WHERE m.mem_user_id=".$this->userid.") ". ($privacyclause ? "AND $privacyclause" : "") . " ORDER BY b.brd_id DESC $limitclause";
             // TODO: create method on memberships class that will return a comma separated list of board memberships
             $sql = "SELECT * FROM boards b, users u WHERE b.brd_creator=u.user_id AND b.brd_id NOT IN (SELECT mem_board_id FROM memberships m WHERE m.mem_user_id=" . $this->userid . ") " . ($privacyclause ? "AND {$privacyclause}" : "") . " ORDER BY b.brd_id DESC {$limitclause}";
         }
     } else {
         $sql = "SELECT * FROM boards b, users u WHERE b.brd_creator=u.user_id " . ($privacyclause ? " AND {$privacyclause}" : "") . $limitclause;
     }
     //echo $sql;
     $db = new SCDB();
     $boards = $db->queryArray($sql);
     foreach ($boards as $id => $board) {
         $board["hidethreads"] = true;
         $this->boards[] = new SCBoard($board);
         /*
         $this->boards[] = array(
         				"id"=>$board["brd_id"],
         				"name"=>$board["brd_name"],
         				"creator"=>$board["brd_creator"],
         				"creatorname"=>$board["user_name"],
         				"createdate"=>$board["brd_createdate"],
         				"privacy"=>$board["brd_privacy"],
         				"description"=>$board["brd_description"],
         				"max_date"=>(isset($board["max_date"]) ? $board["max_date"] : null),
         				"messages"=>array()
         			);
         */
     }
     $this->hasboards = sizeof($boards);
     return $this;
 }
Exemplo n.º 3
0
 private function userFromCookie()
 {
     $cookie = SC::getCookie("sc_auth");
     if (!$cookie) {
         return false;
     }
     $cookie_array = explode("||", base64_decode($cookie));
     //echo (var_dump($cookie_array));
     $user_id = $cookie_array[0];
     $cookie_auth_token = $cookie_array[1];
     $sql = "SELECT user_password, user_email from users WHERE user_id=" . $user_id;
     $db = new SCDB();
     $result = $db->queryArray($sql);
     if (sizeof($result)) {
         //$auth_token = $this->createAuthToken($user_id, $result[0]["user_password"]);
         $auth_token = md5($result[0]["user_email"] . $result[0]["user_password"]);
         if (strcmp($cookie_auth_token, $auth_token) === 0) {
             $this->setSessionUser($user_id, SCUser::saltPassword($result[0]["user_password"]));
             return $this->getSessionUser();
         }
     }
     return false;
 }
Exemplo n.º 4
0
 public function loadMembers($only_receive_emails = false)
 {
     if (!$this->boardid) {
         throw new MembershipSetException("Load Members can only be called if board id is set", 400);
     }
     $db = new SCDB();
     $conditions_array = array("mem_board_id" => $this->boardid, "brd_id" => "mem_board_id", "mem_user_id" => "user_id");
     if ($only_receive_emails) {
         $conditions_array["mem_receives_emails"] = 1;
     }
     $memberships = $db->q(array("*"), array("memberships", "boards", "users"), $conditions_array);
     foreach ($memberships as $id => $membership) {
         $new_membership = new SCMembership($membership);
         $new_membership->hideBoard();
         $new_membership->board->hidecreator = true;
         $new_membership->board->hidethreads = true;
         $new_membership->user->hideBoards = true;
         $this->memberships[] = $new_membership;
     }
     $this->hasmemberships = sizeof($memberships);
     return $this;
 }
Exemplo n.º 5
0
 public function loadThreads($start = false, $num = false, $hidemessages = false)
 {
     //$sql = "SELECT * FROM messages m, users u WHERE m.msg_board_id=".$this->boardid." AND m.msg_thread=0 AND m.msg_author=u.user_id ORDER BY m.msg_id DESC LIMIT $start, " . ($start + $num);
     $db = new SCDB();
     //$threads = $db->queryArray($sql);
     if ($start && !$num) {
         $threads = $db->q(array("*"), array("messages m", "users u"), array("m.msg_board_id" => $this->boardid, "m.msg_thread" => 0, "m.msg_author" => "u.user_id", "m.msg_id>" => $start + 1), array("ORDER BY m.msg_id DESC"));
     } else {
         if (!$start && !$num) {
             if (!$start) {
                 $start = 0;
             }
             if (!$num) {
                 $num = 10;
             }
         }
         $threads = $db->q(array("*"), array("messages m", "users u"), array("m.msg_board_id" => $this->boardid, "m.msg_thread" => 0, "m.msg_author" => "u.user_id"), array("ORDER BY m.msg_id DESC LIMIT {$start}, " . ($start + $num)));
     }
     if (sizeof($threads)) {
         foreach ($threads as $id => $thread) {
             $threads_in[] = $thread["msg_id"];
             $temp_threads[$thread["msg_id"]] = new SCThread($thread);
         }
         //$sql = "SELECT count(msg_id) as the_count, msg_thread FROM messages WHERE msg_thread IN (" . implode(",", $threads_in) . ") GROUP BY msg_thread ORDER BY msg_thread DESC";
         //$thread_counts = $db->queryArray($sql);
         $thread_counts = $db->q(array("count(msg_id) as the_count", "msg_thread"), array("messages"), array("msg_thread" => $threads_in), array("GROUP BY msg_thread", "ORDER BY msg_thread DESC"));
         if (sizeof($thread_counts)) {
             foreach ($thread_counts as $id => $thread_count) {
                 $temp_threads[$thread_count["msg_thread"]]->message_count = $thread_count["the_count"];
             }
         }
         $this->threadset = array();
         foreach ($temp_threads as $id => $thread) {
             if ($hidemessages) {
                 $thread->hidemessages = $hidemessages;
             }
             $this->threadset[] = $thread;
         }
         //echo sizeof($temp_threads);
     }
     return $this;
 }
Exemplo n.º 6
0
 public function hasMessage($messageid)
 {
     if ($messageid = $this->messageid) {
         return true;
     }
     //$sql = "SELECT * from messages WHERE msg_id=$messageid AND msg_thread=".$this->messageid;
     $db = new SCDB();
     $hasMessage = $db->q(array("*"), array("messages"), array("msg_id" => $message_id, "msg_thread" => $this->messageid));
     if (sizeof($hasMessage) && $hasMessage[0]["msg_id"] == $messageid) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 7
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.º 8
0
 public function getCryptedPw()
 {
     if ($this->userid) {
         $db = new SCDB();
         $user_data = $db->q(array("user_password"), array("users"), array("user_id" => $this->userid));
         if (sizeof($user_data)) {
             return $user_data[0]["user_password"];
         }
         return false;
     }
     return false;
 }
Exemplo n.º 9
0
 public function delete()
 {
     if (!$this->membershipid) {
         throw new MembershipException("You can not delete a memebership without a membership", 400);
     }
     $db = new SCDB();
     $db->query("DELETE FROM memberships WHERE mem_id=" . $this->membershipid);
     $membership_id = mysql_insert_id($db->conn);
     if (mysql_error($db->conn) !== "") {
         throw new MembershipException(mysql_error($db->conn));
     }
     return true;
 }
Exemplo n.º 10
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));
     }
 }
Exemplo n.º 11
0
 public function setAccepted()
 {
     $db = new SCDB();
     //$sql = "UPDATE invitations set inv_accepted=1 WHERE inv_id=".$this->id;
     $update_array = array("inv_accepted" => 1);
     $db->updateFromArray($update_array, "invitations", "WHERE inv_id=" . $this->id);
     if (mysql_error($db->conn) !== "") {
         throw new UserException(mysql_error($db->conn));
     }
     return true;
 }