// LOAD DATABASE // CONNECT TO DATABASE include("../mysqli_connect_timesupaziz.php"); // LOAD FUNCTIONS function makeMeme($id,$text) { $x=$y=640; // header('Content-Type: image/png'); $base = 'meta/graphics/TimesUpAziz.png'; $outputImage = imagecreatetruecolor(640, 640); $black = imagecolorallocate($outputImage, 0, 0, 0); imagefill($outputImage, 0, 0, $white); $first = imagecreatefrompng($base); imagecopyresized($outputImage,$first,0,0,0,0, $x,$y,$x,$y); $font = 'meta/fonts/COURIER.ttf'; // REGISTER THE PLACARD TEXT //$text = 'I am the Walrus. Goo goo coo choo.'; $text = htmlentities(strip_tags($text)); // PREPARE Text for cutting // go to the 16th position, evaluate, if it is a whitespace, remove it. // go to the next position // ENSURE THE PLACARD TEXT DOES NOT EXCEED THE PLACARD $text = substr($text, 0, 96); // BREAK THE PLACARD TEXT DOWN TO LINES // old $messageLine = str_split($text, 16); $messageLine = explode("\n", wordwrap($text, 16)); // COUNT THE NUMBER OF LINES TO WRITE ON THE PLACARD $countLines = count($messageLine); // DETERMINE ODD OR EVEN LINES if ($countLines % 2 == 0) { $placardSetup = "even"; } else { $placardSetup = "odd"; } switch ($placardSetup) { case "even": // handle either 2, 4, or 6 lines switch ($countLines) { case "6": $messageLineY = array(298,338,378,418,458,498); break; case "4": $messageLineY = array(338,378,418,458); break; case "2": $messageLineY = array(378,418); break; default: // do nothing } $i=0; while ($i <= $countLines) { $x = 156; $y= $messageLineY[$i]; $thisLine = htmlspecialchars_decode(stripslashes(trim($messageLine[$i])),ENT_QUOTES); $length = strlen($thisLine); // for every length shorter than 16, add 20 pixels to the $x $offsetX = (16 - $length) * 10; $x = $x + $offsetX; imagettftext($outputImage, 25, 0, $x, $y, $black, $font, $thisLine); $i = $i + 1; } break; case "odd": // handle either 1, 3, or 5 lines switch ($countLines) { case "5": $messageLineY = array(318,358,398,438,478); break; case "3": $messageLineY = array(358,398,438); break; case "1": $messageLineY = array(398); break; default: // do nothing } $i=0; while ($i <= $countLines) { $x = 156; $y= $messageLineY[$i]; $thisLine = htmlspecialchars_decode(stripslashes(trim($messageLine[$i])),ENT_QUOTES); $length = strlen($thisLine); // for every length shorter than 16, add 20 pixels to the $x $offsetX = (16 - $length) * 10; $x = $x + $offsetX; imagettftext($outputImage, 25, 0, $x, $y, $black, $font, $thisLine); $i = $i + 1; } break; default: // do nothing } $filename = $id.'.png'; $assetLocation = 'assets/artifact/'.$filename; imagepng($outputImage, $assetLocation); imagedestroy($outputImage); return $filename; } function getRealIpAddr() { if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet { $ip=$_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy { $ip=$_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip=$_SERVER['REMOTE_ADDR']; } return $ip; } // RUN HANDLER if (isset($_POST['action'])) { // echo "action found"; if ($_POST['action']=="makeMeme") { // echo "action name found"; // check for text if (isset($_POST['meme'])) { // echo "meme found"; // there is a meme submitted, do something about it $text = $_POST['meme']; $thisCreateAuthor = "Website User"; $thisAppID = 2018; $thisType = $_POST['type']; $thisContent =$_POST['meme']; $thisStatus = 10; $thisSourceTitle=$_POST['sourceTitle']; $thisNote=$_POST['note']; $thisURL=$_POST['url']; $thisAuthor=$_POST['author']; $thisMemeAuthorIP=getRealIpAddr(); $insert = mysqli_query($mysqli," INSERT INTO artifact VALUES ( null, '$thisAppID', '$thisStatus', '$thisType', '$thisContent', now(), '$thisCreateAuthor', now(), '$thisCreateAuthor' ) "); // get the id that was just created $thisID = $mysqli->insert_id; // now register the attributes // $mysqli = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // always write the artifact content caption, we are saving the submitted text. even though we may never display it. $insert = mysqli_query($mysqli," INSERT INTO artifact_content VALUES ( '$thisID', '$thisAppID', '$thisStatus', 'Meme', null, null, '$thisContent', null, null, null, now(), '$thisCreateAuthor', now(), '$thisCreateAuthor' ) "); // always write the artifact title. for now it is just a repeat of the content. we may edit it later as a short headline $insert = mysqli_query($mysqli," INSERT INTO artifact_content VALUES ( '$thisID', '$thisAppID', '$thisStatus', 'Meme Title', null, null, '$thisContent', null, null, null, now(), '$thisCreateAuthor', now(), '$thisCreateAuthor' ) "); // always write meme author data $insert = mysqli_query($mysqli," INSERT INTO artifact_content VALUES ( '$thisID', '$thisAppID', '$thisStatus', 'Meme Author', null, null, null, '$thisMemeAuthorIP', null, null, now(), '$thisCreateAuthor', now(), '$thisCreateAuthor' ) "); // if present write the source type if ($thisSourceTitle != null) { $insert = mysqli_query($mysqli," INSERT INTO artifact_content VALUES ( '$thisID', '$thisAppID', '$thisStatus', 'Source Title', null, null, '$thisSourceTitle', null, null, null, now(), '$thisCreateAuthor', now(), '$thisCreateAuthor' ) "); } if ($thisNote != null) { // if present write the note type $insert = mysqli_query($mysqli," INSERT INTO artifact_content VALUES ( '$thisID', '$thisAppID', '$thisStatus', 'Note', null, null, '$thisNote', null, null, null, now(), '$thisCreateAuthor', now(), '$thisCreateAuthor' ) "); } if ($thisURL != null) { // if present write the url type $insert = mysqli_query($mysqli," INSERT INTO artifact_content VALUES ( '$thisID', '$thisAppID', '$thisStatus', 'Source URL Link', null, null, '$thisURL', null, null, null, now(), '$thisCreateAuthor', now(), '$thisCreateAuthor' ) "); } if ($thisAuthor != null) { // if present write the source author type $insert = mysqli_query($mysqli," INSERT INTO artifact_content VALUES ( '$thisID', '$thisAppID', '$thisStatus', 'Source Author', null, null, '$thisAuthor', null, null, null, now(), '$thisCreateAuthor', now(), '$thisCreateAuthor' ) "); } // if there is text, run it in the makeMeme() $memeFilename = makeMeme($thisID,$text); // ASSUME THE MEME GENERATOR PLACES IT IN THE RIGHT LOCATION AND GIVES IT THE CORRECT NAME $insert = mysqli_query($mysqli," INSERT INTO artifact_content VALUES ( '$thisID', '$thisAppID', '$thisStatus', 'File', null, null, null, '$memeFilename', null, null, now(), '$thisCreateAuthor', now(), '$thisCreateAuthor' ) "); } else { // nothing submitted, don't do anything // echo "meme NOT found"; } } else { // echo "action name not found"; // nothing submitted, don't do anything } } else { // echo "action not found"; } // PREPARE PAGE BASED ON VIEW $view = $_GET['view']; switch($view) { case "featured": $feature = "
"; break; case "meme": $feature = "Thank you for making your own #TimesUpAziz meme. To make another, click here.
Ever since babe started dishin', Aziz has not been his usual chatty self. Help him get his gab back.
#TimesUpAziz