Jump to content

oz11

Members
  • Posts

    167
  • Joined

  • Last visited

Everything posted by oz11

  1. Code in all it's glory. I will leave it here.. <?php if ($_GET["nsfw_options"] == "true") { $sfw = 1; setcookie("nsfw", "true"); $_COOKIE["nsfw"] = "true"; } if ($_GET["nsfw_options"] == "false") { $sfw = 0; setcookie("nsfw", "false"); $_COOKIE["nsfw"] = "false"; } if (!isset($_COOKIE["nsfw"])) { $sfw = 0; setcookie("nsfw", "false"); $_COOKIE["nsfw"] = "false"; } ?> NSFW Filter: <?php if ($_COOKIE["nsfw"] == "true") { ?> <select name="nsfw_options" id="nsfw_options"> <option disabled selected value> -- select -- </option> <option value="false">Disable</option> <option value="true">Enable</option> </select> <small>[Currently enabled]</small> <?php } elseif ($_COOKIE["nsfw"] == "false") { ?> <select name="nsfw_options" id="nsfw_options"> <option disabled selected value> -- select -- </option> <option value="true">Enable</option> <option value="false">Disable</option> </select> <small>[Currently disabled]</small> <?php } else { ?> <select name="nsfw_options" id="nsfw_options"> <option disabled selected value> -- select -- </option> <option value="true">Enable</option> <option value="false">Disable</option> </select> <small>[Currently enabled]</small> <?php } ?> Messy but ok. or a change of markup. (v2).. <?php if ($_GET["nsfw_options"] == "true") { $sfw = 1; setcookie("nsfw", "true"); $_COOKIE["nsfw"] = "true"; } if ($_GET["nsfw_options"] == "false") { $sfw = 0; setcookie("nsfw", "false"); $_COOKIE["nsfw"] = "false"; } if (!isset($_COOKIE["nsfw"])) { $sfw = 0; setcookie("nsfw", "false"); $_COOKIE["nsfw"] = "false"; } ?> NSFW Filter: <?php if ($_COOKIE["nsfw"] == "true") { ?> <select name="nsfw_options" id="nsfw_options"> <option disabled selected value>[Currently enabled]</option> <option value="false">Disable</option> <option value="true">Enable</option> </select> <?php } elseif ($_COOKIE["nsfw"] == "false") { ?> <select name="nsfw_options" id="nsfw_options"> <option disabled selected value>[Currently disabled]</option> <option value="true">Enable</option> <option value="false">Disable</option> </select> <?php } else { ?> <select name="nsfw_options" id="nsfw_options"> <option disabled selected value>[Currently disabled]</option> <option value="true">Enable</option> <option value="false">Disable</option> </select> <?php } ?>
  2. Ah. forgot to clean my cookies. Seems to work okay. Thanks for being here guys, helps alot!
  3. <?php if($_GET['nsfw_options'] == "true"){ $sfw = 1; setcookie("nsfw", "true"); $_COOKIE["nsfw"] = "true"; } if($_GET['nsfw_options'] == "false"){ $sfw = 0; setcookie("nsfw", "false"); $_COOKIE["nsfw"] = "false"; } if(!isset( $_COOKIE["nsfw"])){ $sfw = 0; setcookie("nsfw", "false"); $_COOKIE["nsfw"] = "false"; } ?> NSFW Filter: <?php if($_COOKIE["nsfw"] == "true"){ ?> <select name="nsfw_options" id="nsfw_options"> <option value="true">Enable</option> <option value="false">Disable</option> </select> Enabled <?php } elseif($_COOKIE["nsfw"] == "false") { ?> <select name="nsfw_options" id="nsfw_options"> <option value="true">Enable</option> <option value="false">Disable</option> </select> Disabled <?php } else { ?> <select name="nsfw_options" id="nsfw_options"> <option value="true">Enable</option> <option value="false">Disable</option> </select> Disabled <?php } ?> I meddled around with it but when navigating from the page and back again it goes from enabled to disabled. Helpz.
  4. Thanks. Is there a workaround? Ps: Glad you said that, I thought I was ging mad (again).
  5. <?php if($_GET['sfw'] == "true"){ $sfw = 1; setcookie("nsfw", "true"); $_COOKIE["nsfw"] = "true"; } if($_GET['sfw'] == "false"){ $sfw = 0; setcookie("nsfw", "false"); $_COOKIE["nsfw"] = "false"; } if(!isset( $_COOKIE["nsfw"])){ $sfw = 0; setcookie("nsfw", "false"); $_COOKIE["nsfw"] = "false"; } ?> <?php if($_COOKIE["nsfw"] == "true"){ ?> <input type="checkbox" id="sfw" name="sfw" value="false" checked="checked">Filter NSFW? <?php } elseif($_COOKIE["nsfw"] == "false") { ?> <input type="checkbox" id="sfw" name="sfw" value="true" >Filter NSFW? <?php } else { ?> <input type="checkbox" id="sfw" name="sfw" value="true" >Filter NSFW? <?php } What am I doing wrong freaks? Can you spot anything? Ta. ps: it turns on and off but not on again.. Edit: i mean it turns on bt not off
  6. oz11

    "New posts"

    Ooops. Fixed .,Thanks guys again!
  7. oz11

    "New posts"

    Ended up doing this which worked... //$day = date('Y-m-d', $row['date']); $day = date('Y-m-d', strtotime($row['date'])); if($day < date('Y-m-d', strtotime('-2 weeks'))){ } ELSE { echo "<img src='ttps://i.imgur.com/0rlIlUD.gif'>"; } abit of a workaround but ok for me. Thanks guys!
  8. oz11

    "New posts"

    Still shows on the reverse but not the other way round hmm. (showing on all the old ones but not the new ones)
  9. oz11

    "New posts"

    Still not fixed it . You would think flipping it would work as it sorta did before, but opposite. all t he ones that shouldn't be "new" were new and all the other actual "new" posts were not showing.. weird. Never come across anything like it.
  10. oz11

    "New posts"

    oops. its abit longer "2022-11-22 16:03:32" (take two)
  11. oz11

    "New posts"

    The date of the post, eg (a real example) of "2022-11-22" update : "2022-11-22 16:03:32" not just "2022-11-22"
  12. I wrote this.. $now = strtotime('now'); $now = date('Y-m-d', $now); $day = date('Y-m-d', strtotime($row['date'] . ' + 2 weeks')); if($day < $now){ echo "<img src='https://i.imgur.com/0rlIlUD.gif'>"; } It should show a "new" gif image on new posts.. however, they only show on posts that are not new. I tried flipping the "<" to ">" but doesn't work.... not sure what to do. So simple but get can't grasp the conditional . Help Internet freaks.
  13. Hey, I'm having trouble here... how do i modify this code so that the following element is displayed ahead of each "word" in the output..[see bellow]. Also is there a way to count the number of times the occurrences take place (1,2,3 etc). Help. $str = "Yogurt (Milk), Strawberries (11%), Sugar, Water, Stabilisers: Pectins, Guar Gum, Flavourings, Acidity Regulator: Citric Acid, Yogurt (Milk), Peach (9%), Sugar, Water, Apricot (3%), Stabilisers: Pectins, Guar Gum, Acidity Regulator: Citric Acid, Flavourings"; $new_str = array_unique(array_map('trim', explode(',', $str))); $string = implode(',', $new_str); echo $string;
  14. Fixed code: <?php include 'config.php'; $stmt = $pdo->prepare("SELECT count(*) FROM news WHERE reference=?"); $stmt->execute([$_GET['ref']]); $check_exist = $stmt->fetchColumn(); if($check_exist == 0){ echo "error not found"; exit(); } $user_ip=$_SERVER['REMOTE_ADDR']; $stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE IP = ? AND news_reff = ?"); $stmt->execute([$user_ip, $_GET['ref']]); $count = $stmt->fetchColumn(); if($count == 0){ $sql = "INSERT INTO outgoing_count (IP, news_reff) VALUES (?,?)"; $stmt= $pdo->prepare($sql); $stmt->execute([$user_ip, $_GET['ref']]); $stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE news_reff = ?"); $stmt->execute([ $_GET['ref']]); $count2 = $stmt->fetchColumn(); echo "Redirect. This page has been viewed ".$count2."times"; } else { $stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE news_reff = ?"); $stmt->execute([$_GET['ref']]); $count3 = $stmt->fetchColumn(); echo "Redirect. This page has been viewed ".$count3."times"; //header('Location: http://google.com'); } ?> .. just needed time.
  15. Updated the code a bit... still doesn't work.. <?php include 'config.php'; $stmt = $pdo->prepare("SELECT count(*) FROM news WHERE reference=?"); $stmt->execute([$_GET['ref']]); $check_exist = $stmt->fetchColumn(); if($check_exist == 0){ echo "error not found"; exit(); } $user_ip=$_SERVER['REMOTE_ADDR']; $stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE IP = ? AND news_reff = ?"); $stmt->execute([$user_ip, $_GET['ref']]); $count = $stmt->fetchColumn(); if($count == 0){ $sql = "INSERT INTO outgoing_count (IP, news_reff) VALUES (?,?)"; $stmt= $pdo->prepare($sql); $stmt->execute([$user_ip, $_GET['ref']]); } else { echo "Redirect. This page has been viewed ".$count."times"; //header('Location: http://google.com'); } ?>
  16. Well.. basically just wrote this. But want it to be forwarded to a page if it's complete... However, it only loads the final conditional if the page is refreshed a second time.. Help, please. Code: <?php include 'config.php'; $user_ip=$_SERVER['REMOTE_ADDR']; $news_ref = $_GET['ref']; $stmt = $pdo->prepare("SELECT count(*) FROM outgoing_count WHERE IP = ? AND news_reff = ?"); $stmt->execute([$user_ip, $news_ref ]); $count = $stmt->fetchColumn(); if($count == 0){ $sql = "INSERT INTO outgoing_count (IP, news_reff) VALUES (?,?)"; $stmt= $pdo->prepare($sql); $stmt->execute([$user_ip, $news_ref ]); } else { $stmt = $pdo->prepare("SELECT count(*) FROM news WHERE reference=?"); $stmt->execute([$_GET['ref']]); $check_exist = $stmt->fetchColumn(); if($check_exist == 0){ echo "404 Error: not found"; } else { echo "Redirect. This page has been viewed ".$count."times"; // <--- ONLY SHOWS ON SECOND REFRESH..??... //header('Location: http://google.com'); } } ?>
  17. I found this... https://www.rgraph.net/canvas/reference/todataurl.html#:~:text=The toDataURL function returns a,save it to a file. which looks great. Don't know how to amend them together yet, both the codes.. help..? Could someone splice them for me.. ? This also looks handy: $dataURL = $_POST["imageDataURL"]; $dataURL = str_replace('data:image/png;base64,', '', $dataURL); $dataURL = str_replace(' ', '+', $dataURL); $image = base64_decode($dataURL); $filename = 'newImage.png'; file_put_contents('path/to/' . $filename, $image); But how do the pieces fit together..?
  18. How would I go about using the script bellow to save the updated image to serverside using PHP <html> <script type="text/javascript"> var canvas, ctx, flag = false, prevX = 0, currX = 0, prevY = 0, currY = 0, dot_flag = false; var x = "black", y = 2; var saveTimer; function onSaveTimer() { save(); } function init() { canvas = document.getElementById('can'); ctx = canvas.getContext("2d"); w = canvas.width; h = canvas.height; canvas.addEventListener("mousemove", function (e) { findxy('move', e) }, false); canvas.addEventListener("mousedown", function (e) { findxy('down', e) }, false); canvas.addEventListener("mouseup", function (e) { findxy('up', e) }, false); canvas.addEventListener("mouseout", function (e) { findxy('out', e) }, false); saveTimer = setInterval(onSaveTimer, 3000); } function color(obj) { switch (obj.id) { case "black": x = "black"; break; case "white": x = "white"; break; } if (x == "white") y = 14; else y = 2; } function draw() { ctx.beginPath(); ctx.moveTo(prevX, prevY); ctx.lineTo(currX, currY); ctx.strokeStyle = x; ctx.lineWidth = y; ctx.stroke(); ctx.closePath(); } function erase() { var m = confirm("Want to clear"); if (m) { ctx.clearRect(0, 0, w, h); document.getElementById("canvasimg").style.display = "none"; } } function save() { document.getElementById("canvasimg").style.border = "2px solid"; var dataURL = canvas.toDataURL(); if (dataURL) { document.getElementById("canvasimg").src = dataURL; document.getElementById("canvasimg").style.display = "inline"; return true; // will POST form to the server } return false; // will not POST to server } function findxy(res, e) { if (res == 'down') { prevX = currX; prevY = currY; currX = e.clientX - canvas.offsetLeft; currY = e.clientY - canvas.offsetTop; flag = true; dot_flag = true; if (dot_flag) { ctx.beginPath(); ctx.fillStyle = x; ctx.fillRect(currX, currY, 2, 2); ctx.closePath(); dot_flag = false; } } if (res == 'up' || res == "out") { flag = false; } if (res == 'move') { if (flag) { prevX = currX; prevY = currY; currX = e.clientX - canvas.offsetLeft; currY = e.clientY - canvas.offsetTop; draw(); } } } </script> <body onload="init()"> <canvas id="can" width="500px" height="150px" style="position:absolute;border:2px solid;"></canvas> <div style="position:relative;top:30px;left:520px;">Eraser</div> <div style="position:relative;top:40px;left:520px;width:15px;height:15px;background:white;border:2px solid;" id="white" onclick="color(this)"></div> <div style="position:relative;top:70px;left:520px;width:15px;height:15px;background:black;border:2px solid;" id="black" onclick="color(this)"></div> <div style="position:relative;top:30px;left:520px;">Pen</div> <form method="POST" action="" onsubmit="save"> <img id="canvasimg" style="position:relative;top:10%;left:600px;" style="display:none;"> </form> <!--<input type="button" value="save" id="btn" size="30" onclick="save()" style="position:fixed;top:170px;left:10px;">--> <!-- <input type="button" value="clear" id="clr" size="23" onclick="erase()" style="position:fixed;top:170px;left:60px;">--> </body> </html> I was thinking something along the lines of POST in PHP..?.. no?.. Screenie for illustration:
  19. Nope. It's just a querk of the DB. The table name is actually known as "cooment_anon" correctly.
  20. Basically a boolean value in the DB says if the anonymous checkbox has been set to be checked by default. A typo of comment_anon, but stuck with it lol.
  21. Remo Removing the echo statements still doest work. In honesty it should still assign the values even if I did echo them as well.
  22. Update: oops was using ... } elseif($anon_comment == "2" ) { ..instead of == 0. Tho still does not work on the second box (from line 151). Still a problem. Not showing anything in fact, using the conditional.
  23. By not working i mean that the code is not functioning on one of the examples while on the other it is. The code is very similar and don't see why it shouldn't work on both... help me.
  24. Hey. Been a while since I last posted here. Problem: the first 8 lines of code work for the top box, but not the bottom box. Code in question is this: <?php // bottom if ($anon_comment== "1"){ ?> <span style="color: black">Post as anonymous?</span> <input type="checkbox" id="anon" name="anon" value="set" checked> <?php } elseif($anon_comment == "2" ) { ?> <span style="color: black">Post as anonymous?</span> <input type="checkbox" id="anon" name="anon" value="set"> <?php } ?> And for illustration purposes here is the second box... <?php // bottom if ($anon_comment== "1"){ ?> <span style="color: black">Post as anonymous?</span> <input type="checkbox" id="anon" name="anon" value="set" checked> <?php } elseif($anon_comment == "2" ) { ?> <span style="color: black">Post as anonymous?</span> <input type="checkbox" id="anon" name="anon" value="set"> <?php } ?> Like I said it works on line 220 but not line 151. Both are very similar if not the same, but the bottom one never works at all. Its like the conditional statement above is not working the other box (aka "bottom"). The first box works fine and as expected. Whole code: <?php $stmt = $pdo->prepare("SELECT cooment_anon FROM `users` WHERE user_id = ?"); $stmt->execute([$_SESSION['the_usr_id']]); $is_anon_set = $stmt->fetch(); if($is_anon_set['cooment_anon'] == 1){ echo $anon_comment = "1"; } else { echo $anon_comment = "0"; } if (isset($_GET['anon'])){ echo "posting as anon"; } // ---~ login check ~--- // --- ~~ --- ?> <style> .generalclass { color: #ffffff; text-align: left; margin: 10px; padding: 10px; display: none; } </style> <?php //require_once "../config.php"; // create/display nested comments // init $user_id = $_SESSION['the_usr_id']; // fake some data //$_GET['news_id'] = $news['news_id']; $_GET['news_id'] = 0; // <-------------------- TESTING $_COMMENTS_ID= $news['news_id']; $post = []; // array to hold a trimmed working copy of the form data $errors = []; // array to hold user/valdiation errors // post if($_SERVER['REQUEST_METHOD'] == 'POST') { // trim all the data at once $post = array_map('trim',$_POST); // if any input is an array, use a recursive trim call-back function here instead of php's trim // validate inputs here... // if no errors, use the form data if ($post['anon'] == "set"){ $is_anon = 1; } else { $is_anon = 0; } if(empty($errors)) { $sql = "INSERT INTO `comment` (`comment_id`, `parent`, `news_id`, `user_id`, `content`, `karma`, `removed`, `reference____`, `date`, `last_update`, `aproved`, `anonymous`, `image_upld`) VALUES (NULL, ?, ?, ?, ?, '0', '0', '', NOW(), NULL, '1', ?, NULL)"; $stmt = $pdo->prepare($sql); $stmt->execute([ $post['parent_id'], $_COMMENTS_ID, $user_id, $post['comment'], $is_anon ]); } // if no errors, success if(empty($errors)) { die(header("Refresh:0")); } } // get all the rows of data for the requested news id $sql = "SELECT comment.parent, comment.comment_id, comment.news_id, comment.user_id, comment.content, comment.karma, comment.removed, comment.date, comment.last_update, comment.aproved, comment.anonymous, comment.image_upld, users.name, users.avatar FROM `comment` LEFT JOIN `users` ON `comment`.`user_id` = `users`.`user_id` WHERE news_id = ? ORDER BY comment_id DESC LIMIT 800"; $stmt = $pdo->prepare($sql); $stmt->execute([ $_COMMENTS_ID ]); $comment_data = $stmt->fetchAll(PDO::FETCH_GROUP); // recursive function to output parent/child data function list_comments($parent_id, $data, $level=0) { // this just supplies a visual part to the output so you can see what the code does //$indent = str_repeat("<span style='color: transparent;'>---- </span>", $level); $indent = str_repeat("<span style='color: transparent;'>---- </span>", $level); //echo "<pre>"; //print_r($data); //echo "</pre>"; // loop over data for the current parent_id foreach($data[$parent_id] as $arr) { // output the comment and any other information if ($arr['anonymous'] == 1){ $pre_hash = $arr['name']."3434292"; echo $indent ."<a href='profile.php?anonymous'><img src='site-data/avatars/sir.png' style='width: 30px; float: left; margin: 15px; border-radius: 30px;'></a>"; echo "<a href='profile.php?anonymous' title='This user is in anonymous mode so cannot be seen'>Anonymous [hash ID: usranon".substr(md5($pre_hash), 0, -10)."</a><br>"; }else{ echo $indent ."<a href='profile.php?name={$arr['name']}'><img src='site-data/avatars/{$arr['avatar']}' style='width: 30px; float: left; margin: 15px; border-radius: 30px;'></a>"; echo "<a href='profile.php?name={$arr['name']}'>{$arr['name']}</a><br>"; } echo "<b><p style='font-family: Arial, Helvetica, sans-serif;'>$indent{$arr['content']}</p></b>"; // determine and output any child count $count = isset($data[$arr['comment_id']]) ? count($data[$arr['comment_id']]) : 0; $pl = $count == 0 || $count > 1 ? 'ies' : 'y'; echo "<br>$indent$count Repl$pl<br>"; // allow a comment for the current parent // you would probably want to use a javascript 'show' operation for this ?> <p> <?php echo $indent ?><button class="button" onclick="myFunction('button<?=$arr['comment_id']?>')">Reply</button> <div id="button<?=$arr['comment_id']?>" class="generalclass" style="display:none;"> <form method="post"> <input type='hidden' name='parent_id' value='<?=$arr['comment_id']?>'> <?=$indent?><label>Comment:<br> <?=$indent?><textarea name="comment" rows="4" cols="50" placeholder="remember to be polite!"></textarea></label> <input type="submit"> <a href="includes/emojis.php" onclick="window.open(this.href,'targetWindow', `toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=300px;, height=500px`); return false; style='float: right; padding-left: 30px;'">Show emojissszz</a> <?php ?> <?php // bottom if ($anon_comment== "1"){ ?> <span style="color: black">Post as anonymous?</span> <input type="checkbox" id="anon" name="anon" value="set" checked> <?php } elseif($anon_comment == "2" ) { ?> <span style="color: black">Post as anonymous?</span> <input type="checkbox" id="anon" name="anon" value="set"> <?php } ?> </form> <br> </div> <?php // recurse if there are children of the current parent if(isset($data[$arr['comment_id']])) { list_comments($arr['comment_id'], $data, $level+1); } } } // html ?> <?php // display any errors if(!empty($errors)) { echo implode('<br>',$errors); } ?> <?php if( $_SESSION["loggedin"] != true){ echo "This category/board comment system is set to private. You must register/login and join to take part. Click <u><a href='login.php'>here</a></u> to login to your account or to register.</div>"; include 'footer.php'; exit(); } // allow a comment on the main article ?> <form method="post"> <input type='hidden' name='parent_id' value='0'> <label>Comment:<br> <textarea name="comment" rows="4" cols="50" placeholder="remember to be polite!" style="border-color: grey; width: 97%;"><?=$post['content']??''?></textarea></label><br> <input type="submit"><br> <a href="includes/emojis.php" onclick="window.open(this.href,'targetWindow', `toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=300px;, height=500px`); return false; style='float: right; padding-left: 50px;'">Show emojis</a><br> <?php // top if ($anon_comment== "1"){ ?> <span style="color: black">Post as anonymous?</span> <input type="checkbox" id="anon" name="anon" value="set" checked> <?php } elseif($anon_comment == "0") { ?> <span style="color: black">Post as anonymous?</span> <input type="checkbox" id="anon" name="anon" value="set"> <?php } ?> </form><br> <div style="overflow-y: scroll; height:400px; border: 1px dashed grey; padding: 30px; margin-right: 30px; border-radius: 10px; "> <?php if( $_SESSION["loggedin"] == true){ if($count == 0){ echo "No comments"; } } ?> <?php // list comments, starting with parent 0 list_comments(0, $comment_data, 0); ?> </div> <script> function myFunction(divid) { var x = document.getElementById(divid); if (x.style.display == "none") { x.style.display = "block"; } else { x.style.display = "none"; } } </script><br><br> It should be an anonymous checkbox to allow users to choose if they want to submit anonymously based on a flag stored in the DB - "cooment_anon" which can be true or false (0/1). But the decloration isnt working using the code in he first example, despite it being the same. Strange it should work on one but not the other. Tried pasting [this bellow] in other possible locations as a hack, but never worked :S $stmt = $pdo->prepare("SELECT cooment_anon FROM `users` WHERE user_id = ?"); $stmt->execute([$_SESSION['the_usr_id']]); $is_anon_set = $stmt->fetch(); PS: By "box" i mean the initial comment box and the reply comment boxes.
  25. How would that look like? Cant seem to get it to work.. tried this: but get "Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number " error..
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.