Retrieve timeline
[Anonymous-Twitter-Board.git] / class / queue-database-construction.php
blobde14daca58fccc3f4bb4f4c97f5097c7576e3cf4
1 <?php
3 class QueueDatabaseConstruction{
5 private $sql_data = array();
6 private $connection = null;
8 public $die_state = array();
9 public $comment_error = false;
10 public $delete_status = false;
12 function __construct($connect = false){
13 $sql_ini = fopen("settings/sql.ini", "r");
14 while(!feof($sql_ini)){
15 $line = fgets($sql_ini);
16 $key = substr($line, 0, strpos($line, ":"));
17 $value = trim(substr($line, strpos($line, ":")+1));
18 $this->sql_data[$key] = $value;
20 if($connect == true) $this->connectToDatabase();
23 function connectToDatabase(){
24 $this->connection = new mysqli($this->sql_data["connection"], $this->sql_data["user"],
25 $this->sql_data["pass"], $this->sql_data["database"]);
26 if (!$this->connection) {
27 echo "Error: Unable to connect to MySQL." . PHP_EOL;
28 echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
29 echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
30 exit;
34 function buildQueueForm(){
35 echo'<form action="add-to-queue.php" enctype="multipart/form-data" method="POST" target="_self">
36 <label>Comment:</label><br />
37 <textarea id="Comment" name="comment" rows="10" cols="60">';
39 echo '
40 <Comment String>
41 Artist: @<Artist>
42 @HentaiAdvisor @Hentai_Retweet @DoujinsApp @waifu_trash @HentaiTeengirl @Hentai_Babess
43 <Specific Tagging>
44 #hentai #hentaicommunity #nsfw #lewd #porn #animeleft #hibiki #verniy
45 &&Me On The Left&&';
47 echo '</textarea>
48 <p id="CharacterCount"></p>
50 <input name="MAX_FILE_SIZE" type="hidden" value="5242880" />
51 <input name="file1" type="file" id="f1" /><input name="file2" type="file" id="f2" /><br/>
52 <input name="file3" type="file" id="f3" /><input name="file4" type="file" id="f4" /><br/>
53 <hr />
54 <p id="errorMsg">Input a comment and/or file</p>
55 <input id="submit" type="submit" /></form>
59 function buildPassForm(){
60 echo"<form action='' method='POST'>
61 <input name='name'><br/>
62 <input name='pass' type='password'><br/>
63 <input type='submit' id='authorization-input' value='Authorize'></form>";
66 function checkCommentValid($tweet_comment){
67 $COMMENT_MAX = 500;
69 if(mb_strlen($tweet_comment) > $COMMENT_MAX){
70 echo "Comment too long[Server]<br/>";
71 $this->comment_error = true;
72 return "";
74 $this->comment_error = false;
75 return $tweet_comment;
78 function uploadAndVerify($files){
79 $FILE_MAX = 5242880;
80 $file_arr = array();
81 $file_string = "";
82 $first = true;
83 for($file = 1; $file <= 4; $file++){
84 $upload_location = "images/" . basename($files["file" . (string)$file]["name"]);
85 if($files["file" . (string)$file]["error"] == 0 && $upload_location !== "images/" && $files["file" . (string)$file]["size"] < $FILE_MAX){
86 $file_arr[$file - 1] = $upload_location;
87 if($first){
88 $file_string .= rawurlencode($upload_location);
89 $first = false;
91 else{
92 $file_string .= "," . rawurlencode($upload_location);
94 if (move_uploaded_file($files["file" . (string)$file]["tmp_name"], $upload_location )) {
95 echo "File: $file was valid.<br/>";
97 else {
98 echo "File: $file_location " . " Detected an error <br/>";
99 $file_arr[$file - 1] = "0";
100 $die_state[$file - 1] = true;
101 continue;
103 $die_state[$file - 1] = false;
105 else{
106 $file_arr[$file - 1] = 0;
107 if($files["file" . (string)$file]["size"] >= $FILE_MAX){
108 echo "file" . (string)$file ." Over filesize limit-Server<br/>";
109 $this->die_state[$file - 1] = true;
111 else if($files["file" . (string)$file]["error"] == 1){
112 echo "file $file, PHP err " . $files["file" . (string)$file]["error"] . " <br/>";
113 $this->die_state[$file - 1] = true;
115 else if($files["file" . (string)$file]["error"] == 2){
116 echo "file $file, Over size limit-Client<br/>";
117 $this->die_state[$file - 1] = true;
119 else if($files["file" . (string)$file]["error"] == 3){
120 echo "file $file, The uploaded file was only partially uploaded. <br/>";
121 $this->die_state[$file - 1] = true;
123 else if($files["file" . (string)$file]["error"] == 4){
124 echo "file $file, Empty<br/>";
125 $this->die_state[$file - 1] = false;
127 else{
128 echo "file $file, Unkown Upload Error " . $files["file" . (string)$file]["error"] . "<br/>";
129 $this->die_state[$file - 1] = true;
133 return $file_string;
134 var_dump($file_arr);
137 function addToDatabase($file_string, $comment){
138 if($file_string == "" AND $comment == ""){
139 echo "Empty form<br/>";
140 return;
142 $insert_query = $this->connection->prepare("INSERT INTO TweetQueue(PostNo,Comment,ImageLocation) VALUES ('',?,?)");
143 $file_path = $file_string;
144 if (!$insert_query->bind_param("ss", $comment, $file_path)){
145 echo "Prepared Statement Error<br/>";
149 if (!$insert_query->execute()){
150 echo "Execution Error " . $insert_query->errno . " " . $insert_query->error;
152 else{
153 echo "Added to post queue<br/>";
157 function displayTabularDatabase(){
158 echo "<br/>Displaying All entries(lower number means posted sooner): <br/>";
159 $result = $this->connection->query("Select * from TweetQueue ORDER BY PostNo DESC;");
161 echo "<table border='1'>";
162 for($row = $result->num_rows - 1; $row >= 0 ; $row--){
163 echo"<tr>";
164 $tupple = $result->fetch_row();
165 foreach($tupple as $col){
166 echo "<td>$col</td>";
168 echo"</tr>";
170 echo "</table><hr/>";
173 function retrieveOldestEntry(){
174 $retrieval_query = "SELECT * FROM TweetQueue ORDER BY PostNo ASC LIMIT 1";
176 $most_recent = $this->connection->query($retrieval_query);
177 print_r($most_recent);
178 echo "\n";
180 $data_arr = $most_recent->fetch_assoc();
182 print_r($data_arr);
184 $file_arr = explode(",", rawurldecode($data_arr["ImageLocation"]));
186 echo "Comm: " . $data_arr["Comment"] . " - ILoc: ";
187 print_r($file_arr);
188 return $data_arr;
191 function deleteOldestEntry($oldest){
192 echo $oldest;
193 $delete_querry = $this->connection->prepare("DELETE FROM TweetQueue WHERE PostNo=?;");
194 $delete_querry->bind_param("s", $oldest["PostNo"]);
195 $this->delete_status = $delete_querry->execute();
197 if($this->delete_status !== 1){
198 echo "<pre><hr/>Delete Err" . $delete_query->error;