3 include_once("class/database-connection.php");
4 include_once("../class/database-connection.php");
6 class BoardLevelDatabaseConnection
extends DatabaseConnection
{
7 function __construct($path_prefix = ""){
9 parent
::__construct($path_prefix);
12 function buildThread($build_type, $display_type, $thread_id){
14 $replies = $this->getReplies($thread_id);
15 //var_dump ($replies);
19 if($display_type == "list") $list_add = "-list";
21 if($build_type == "native"){
22 foreach($replies as $reply){
23 //$this->testBlock( $reply);
26 if($reply_counter %
$row_size == 0) echo"<ul class='row-reply" . $list_add ."'>";
27 echo "<li class='reply-container" . $list_add ."' PostNo='" . $post_id ."'>";
29 echo "<div class='details" . $list_add ."'><ul class='embed-details'>
30 <li>PostNo: " . $post_id .
33 <li class='interaction-item" . $list_add ."'>
34 <a href='/?thread=" . $post_id . "'>
38 <li class='interaction-item" . $list_add ."'>
39 <a href='https://twitter.com/Qazoku/status/". $post_id ."'>
47 <div class='thread-contents" . $list_add ."'>
48 <div class='thread-text" . $list_add ."'><blockquote>" . $reply["PostText"] ."</blockquote></div>
49 <div class='thread-image" . $list_add ."'>";
50 if($reply["ImageURL"] !== null)
51 $this->createMediaNodeFromRaw($reply["ImageURL"]);
55 if($reply_counter %
$row_size == $row_size - 1) echo "</ul>";
61 require_once("class/twitter-connection.php");
64 $twitter_connection = new TwitterConnection($this->path_prefix
);
66 foreach($replies as $reply){
68 if($reply_counter %
$row_size == 0) echo"<ul class='row-reply" . $list_add ."'>";
70 echo "<li class='embeded reply-container" . ($display_type == "list" ?
"-list max":"") . "' PostNo='" . $post_id ."'>";
71 echo "<div class=''><ul class='embed-details'>
72 <li class=''>PostNo: " . $post_id .
75 <li class='embed-detail-item'>
76 <a href='/?thread=" . $post_id . "'>
80 <li class='embed-detail-item'>
81 <a href='https://twitter.com/Qazoku/status/". $post_id ."'>
88 echo $twitter_connection->getEmbededTweet($post_id)["html"];
91 if($reply_counter %
$row_size == $row_size - 1) echo"</ul>";
97 //Get the count of all items that are not Unsubmitted and not replies
98 function getThreads(){
99 $statement = $this->connection
->prepare("SELECT * FROM `Tweet`
100 LEFT OUTER JOIN `Response` ON `Response`.`PostID` = `Tweet`.`PostID`
101 LEFT OUTER JOIN `Unsubmitted` ON `Unsubmitted`.`PostID` = `Tweet`.`PostID`
102 WHERE `Unsubmitted`.`PostID` IS NULL AND `Response`.`PostID` IS NULL
103 ORDER BY Tweet.PostID DESC");
105 $statement->execute();
106 $threads = $statement->fetchAll();
107 }catch(Exception
$e){
108 echo "<strong>" . $e->getMessage() . "</strong><br/>";
113 function getAllUnposted(){
114 $statement = $this->connection
->prepare("SELECT * FROM Tweet JOIN Unsubmitted ON `Tweet`.`PostID` = `Unsubmitted`.`PostID` WHERE `Unsubmitted`.`Unverified` = 0");
116 $statement->execute();
117 return $statement->fetchAll();
120 echo "<strong>" . $e->getMessage() . "</strong><br/>";
124 function getReplies($post_id){
126 $this->getRepliesRecursive($post_id, $thread_replies);
127 $thread_replies = array_reverse($thread_replies);
128 $head = $this->getPostDetails("Tweet", "PostID", $post_id);
129 array_unshift($thread_replies, $head[0]);
130 return $thread_replies;
133 function getRepliesRecursive($post_id, &$thread_replies_store){
135 $statement = $this->connection
->prepare('
136 SELECT * FROM `Tweet`
137 LEFT JOIN `Response` ON `Response`.`PostID` = `Tweet`.`PostID`
138 WHERE `Response`.`RepliesTo` = :postID
139 ORDER BY Tweet.PostID DESC');
140 $statement->bindParam(":postID", $post_id);
143 $statement->execute();
144 $threads = $statement->fetchAll();
145 }catch(Exception
$e){
146 echo "<strong>" . $e->getMessage() . "</strong><br/>";
149 //$this->testBlock($threads);
150 foreach($threads as $thread){
151 $this->getRepliesRecursive($thread[0], $thread_replies_store);//0=postid
152 array_push($thread_replies_store, $thread);
156 function buildDetailList($array){
157 $built_arr = array();
158 foreach($array as $name=>$post){
159 if(preg_match("/chk\d*/", $name)){
160 $post_id = substr($name, 3);
161 $built_arr[$post_id] = array("unv"=>$array["unv$post_id"],
162 "ipd"=>$array["ipd$post_id"],
163 "ban"=>$array["ban$post_id"]
170 function sendVerifiedPostID($id){
172 $data_arr = $this->getPostDetails("Tweet", "PostID", $id)[0];
174 require_once("class/twitter-connection.php");
175 $twitter_connection = new TwitterConnection();
176 $twitter_connection->makeTweet($data_arr["PostText"], explode(",", $data_arr["ImageURL"]));
179 function toggleBanIPList($post_arr){
180 $post_no_list = $this->buildDetailList($post_arr);
181 foreach($post_no_list as $key=>$item){
182 $propper_entry = $this->getPostDetails("Banned", "IPAddress", $item["ipd"]);
183 if(sizeof($propper_entry) > 0){
184 $this->deleteFromTable("Banned", "IPAddress", $item["ipd"]);
187 $this->addToTable("Banned", array("IPAddress"=>$item["ipd"], "BanComment" => $item["ban"]));
191 function verifyPosts($post_arr){
192 $post_no_list = $this->buildDetailList($post_arr);
193 foreach($post_no_list as $key=>$item){
194 $propper_entry = $this->getPostDetails("Unsubmitted", "PostID", $key);
195 if(sizeof($propper_entry) > 0){
196 $this->updatePost("Unsubmitted", "PostID", $key, array("Unverified" => $item["unv"]));
198 else throw "Post doesn't exist??";
204 function deleteExpiredEntries(){
205 $threads = $this->getThreads();
207 echo "A " . $this->path_prefix
;
208 $user_properties = new TwitterConnection($this->path_prefix
);
209 $delete_threshold = ($user_properties->getPostProperties()["Catalog-Size"]);
210 //echo(var_dump($user_properties->getPostProperties()));
211 foreach($threads as $thread){
213 echo $thread_count . " > $delete_threshold<br/>";
214 if($thread_count > $delete_threshold){
217 $this->deleteFromUnprocessedImageString($thread["ImageURL"]);
218 $this->deleteChain($thread[0]);//0 is the most relevant PostID
221 $database_connection = null;
224 function deleteChain($post_id){
225 $delete_arr = array_reverse($this->getReplies($post_id));
226 foreach($delete_arr as $delete_item){
227 $this->deleteAllOfPost($delete_item["PostID"]);
231 function deleteAllOfPost($post_id){
232 $this->deleteFromTable("Response", "PostID", $post_id);//0=postid
233 $this->deleteFromTable("Unsubmitted", "PostID", $post_id);//0=postid
234 $this->deleteFromTable("Tweet", "PostID", $post_id);//0=postid
237 function deleteFromUnprocessedImageString($image_path_uprocessed){
238 if($image_path_uprocessed === null) return;
239 $image_path_uprocessed_arr = explode(",", $image_path_uprocessed);
240 foreach($image_path_uprocessed_arr as $unprocessed_path){
241 $path = rawurldecode($unprocessed_path);
247 function retrieveOldestEntry(){
249 $retrieval_query = $this->connection
->prepare("SELECT * FROM TweetQueue ORDER BY PostNo ASC LIMIT 1");
251 $most_recent = $retrieval_query->execute();
253 $data_arr = $retrieval_query->fetchAll();
257 $file_arr = explode(",", ($data_arr[0]["ImageLocation"] ));
261 function retrieveNewestEntry(){
263 $retrieval_query = $this->connection
->prepare("SELECT * FROM TweetQueue ORDER BY PostNo DESC LIMIT 1");
265 $most_recent = $retrieval_query->execute();
267 $data_arr = $retrieval_query->fetchAll();
271 $file_arr = explode(",", ($data_arr[0]["ImageLocation"] ));
275 function deleteOldestEntry($oldest){
278 $this->deleteFromUnprocessedImageString($oldest[0]["ImageLocation"]);
280 $delete_querry = $this->connection
->prepare("DELETE FROM TweetQueue WHERE PostNo=:PostNo;");
281 $delete_querry->bindParam(":PostNo", $oldest[0]["PostNo"]);
282 $this->delete_status
= $delete_querry->execute();
284 if($this->delete_status
!== 1){
285 echo "<pre><hr/>Delete Err" . $delete_query->error
;
289 function addTimelineTweetsToDatabase($combined_database_arr){
290 foreach($combined_database_arr as $key => $timeline_item){
291 $timeline_item[1] = str_replace("<","<",$timeline_item[1]);
292 $timeline_item[1] = str_replace(">",">",$timeline_item[1]);
293 $timeline_item[1] = str_replace("\"",""",$timeline_item[1]);
295 $this->addToTable("Tweet", array("PostID"=>$timeline_item[0],
296 "PostText"=> $timeline_item[1], "ImageURL"=> $timeline_item[2]));
298 foreach($combined_database_arr as $key => $timeline_item){
299 if($timeline_item[3] !== null)
300 $this->addToTable("Response", array("PostID"=>$timeline_item[0], "RepliesTo"=>$timeline_item[3]));
304 function getAllSubmissionDetails($table_name, $join_with, $ordering_param,$ordering){
305 $statement = $this->connection
->prepare("SELECT * FROM $table_name JOIN $join_with ON `$table_name`.`PostID` = `$join_with`.`PostID` ORDER BY `$table_name` . `$ordering_param` $ordering");
306 //$statement->bindParam(":ordering_param", $ordering_param);
307 $statement->execute();
308 return $statement->fetchAll();
311 function getVerificationDetails($ordering){
312 $statement = $this->connection
->prepare("
313 SELECT DISTINCT * FROM `Tweet`
314 LEFT JOIN `Response` ON `Tweet`.`PostID` = `Response`.`PostID`
315 LEFT JOIN `Unsubmitted` ON `Tweet`.`PostID` = `Unsubmitted`.`PostID`
316 LEFT JOIN `Banned` ON `Banned`.`IPAddress` = `Unsubmitted`.`IPAddress`
317 ORDER BY `Tweet`.`PostID` $ordering
320 $statement->execute();
321 return $statement->fetchAll();