Flashmaster82
Members-
Posts
182 -
Joined
-
Last visited
Everything posted by Flashmaster82
-
That is awesome!!! Thank you
-
Any solutions? I thought it was possible because the Mime types is in the config image/webp:webp
-
If i add a webp image url i get error "Pageimage: johnrogershousemay2020.0x260.webp - not a supported image type"... ? Any idea whats wrong?
-
I get [FAILURE] Number of fields does not match. with the latest version of Processewire (3.0.213) or (3.0.210). If i´m using 3.0.200 then it works? Please help!!
-
Need some help with long polling configuration
Flashmaster82 replied to Flashmaster82's topic in General Support
I think the Htmx polling is "Short polling" that polls all the time. I want to use long polling that is polling only if there is new content. -
Need some help with long polling configuration
Flashmaster82 replied to Flashmaster82's topic in General Support
I will check it out \thanks -
Need some help with long polling configuration
Flashmaster82 replied to Flashmaster82's topic in General Support
Anyone? -
Ok i´m working on a auction site and i need to update some variables for the clients in real time without refreshing the page. So i looked around and found a script for this (long polling) and now i´m trying to implement this. My page looks like this. And my struction in the tree. This is my current script to update a table in the database. I have created an test table in the database just for testing purposes. server.php, Location: root folder <?php ini_set('display_errors', 1); error_reporting(E_ALL); class CustomerDetails { // (A) CONSTRUCTOR - CONNECT TO DATABASE protected $pdo = null; protected $stmt = null; function __construct () { try { $this->pdo = new PDO( "mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset=".DB_CHARSET, DB_USER, DB_PASSWORD, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]); } catch (Exception $ex) { exit($ex->getMessage()); }} // (B) DESTRUCTOR - CLOSE CONNECTION function __destruct () { if ($this->stmt !== null) { $this->stmt = null; } if ($this->pdo !== null) { $this->pdo = null; } } // (C) GET LATEST DETAILS function getCusDetails() { $this->stmt = $this->pdo->prepare( "SELECT *, UNIX_TIMESTAMP(data) AS 'unix' FROM testtable ORDER BY 'data' DESC LIMIT 1" ); $this->stmt->execute(); return $this->stmt->fetch(); } } // (D) DATABASE SETTINGS - CHANGE THESE TO YOUR OWN! define("DB_HOST", "xxx"); define("DB_NAME", "xxx"); define("DB_CHARSET", "utf8"); define("DB_USER", "xxx"); define("DB_PASSWORD", "xxx"); // (E) CHECK FOR UPDATES // ******** THIS IF STATEMENT IS NOT WORKING - WHEN REMOVED WE CAN PRINT_R THE CUSTOMER DETAILS AS ARRAY. WHEN USED THE IF STATEMENT RETURNS NO DATA. ********* if (isset($_POST["last"])) { // (E1) SET TIME LIMIT set_time_limit(30); // set an appropriate time limit ignore_user_abort(false); // stop when long polling breaks // (E2) LOOP UNTIL THERE ARE UPDATES OR TIMEOUT $_DETAILS = new CustomerDetails(); //print_r($_DETAILS->getCusDetails()); while (true) { $details = $_DETAILS->getCusDetails(); if (isset($details["unix"]) && $details["unix"] > $_POST["last"]) { echo json_encode($details); break; } sleep(1); // short pause to not break server } } ?> Auction page <?php ini_set('display_errors', 1); error_reporting(E_ALL); ?> <script> // (B) LAST UPDATED TIMESTAMP var last = 0; // (C) AJAX LONG POLL function poll () { // (C1) FORM DATA let data = new FormData(); data.append("last", last); console.log("Fetch run", last); // (C2) FETCH UPDATE ON SERVER RESPONSE fetch("<?php echo $config->urls->httpRoot;?>server.php", { method:"POST", body:data }) .then(res => res.json()) .then(data => { //console.log(data); // (C2-1) UPDATE HTML DISPLAY document.getElementById("time").innerHTML = data.data; document.getElementById("id").innerHTML = data.pages_id; last = data.unix; poll(); }) // (C3) CATCH ERROR - LOOP ON TIMEOUT .catch(err => poll()); } // (D) GO! window.onload = poll; </script> <div id="time">Time</div> <div id="id">Id</div> But i don´t how to get the fields from the auction_page and auction_bid as in the first image to be updated. To get values from the database to this page/pages. Sorry for being such a beginner. But i´m in need for some guidance. Or has somebody made a similair better code for this with ajax long polling into Processwire? Any help is highly appreciated.
-
htmx: Auto-refresh Frontend Content on Backend Page Save
Flashmaster82 replied to kongondo's topic in General Support
This look awesome.. Is there any possibility to post the full code for this? -
Need some help to specify path to website root.
Flashmaster82 replied to Flashmaster82's topic in General Support
I am a total noob at javascript so it´s pretty difficult for me this ? How would you @Jan Romero do if i wanted to poll another field or multiple inside a template? Lets say that i wanted to do poll field: auction_bid that is on my auction_bid template, that is a child of auction_page. Right now its polling from a test table auctionbidx that is in the root of the database. -
Need some help to specify path to website root.
Flashmaster82 replied to Flashmaster82's topic in General Support
@Jan Romero My bad ? I think it finding the file now, but endless loop still och fetch etc... Console Network -
Need some help to specify path to website root.
Flashmaster82 replied to Flashmaster82's topic in General Support
thanks all for the replies. How to solve this in the code? Sorry for being such a beginner.. ? -
Need some help to specify path to website root.
Flashmaster82 replied to Flashmaster82's topic in General Support
thanks for the reply once again @Jan Romero if i do ../../auction_longpolling.php i get this fetch run loop running in the console if i do <?php echo config()->urls->httpRoot;?>auction_longpolling.php i get Error Call to undefined function config() 86: fetch("<?php echo config()->urls->httpRoot;?>auction_longpolling.php", { method:"POST", body:data }) -
Need some help to specify path to website root.
Flashmaster82 replied to Flashmaster82's topic in General Support
Thanks for the reply @Jan Romero templates/assets/auction-page/javascripts.php <script> // (B) LAST UPDATED TIMESTAMP var last = 0; // (C) AJAX LONG POLL function poll () { // (C1) FORM DATA let data = new FormData(); data.append("last", last); console.log("Fetch run", last); // (C2) FETCH UPDATE ON SERVER RESPONSE fetch("<?=config()->urls->httpRoot?>auction-longpolling.php", { method:"POST", body:data }) .then(res => res.json()) .then(data => { // (C2-1) UPDATE HTML DISPLAY document.getElementById("bid").innerHTML = data.bid; // (C2-2) NEXT ROUND last = data.unix; poll(); }) // (C3) CATCH ERROR - LOOP ON TIMEOUT .catch(err => poll()); } // (D) GO! window.onload = poll; </script> auction-longpolling.php <?php class auctionbids { // (A) CONSTRUCTOR - CONNECT TO DATABASE protected $pdo = null; protected $stmt = null; function __construct () { try { $this->pdo = new PDO( "mysql:host=".DB_HOST.";dbname=".DB_NAME.";charset=".DB_CHARSET, DB_USER, DB_PASSWORD, [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]); } catch (Exception $ex) { exit($ex->getMessage()); }} // (B) DESTRUCTOR - CLOSE CONNECTION function __destruct () { if ($this->stmt !== null) { $this->stmt = null; } if ($this->pdo !== null) { $this->pdo = null; } } // (C) GET LATEST function getauctionbids () { $this->stmt = $this->pdo->prepare( "SELECT *, UNIX_TIMESTAMP(`time`) AS `unix` FROM `auctionbidx` ORDER BY `time` DESC LIMIT 1" ); $this->stmt->execute(); return $this->stmt->fetch(); } } // (D) DATABASE SETTINGS - CHANGE THESE TO YOUR OWN! define("DB_HOST", "xxx"); define("DB_NAME", "xxx"); define("DB_USER", "xxx"); define("DB_PASSWORD", "xxx"); define("DB_CHARSET", "utf8"); // (E) CHECK FOR auctionbids UPDATES if (isset($_POST["last"])) { // (E1) SET TIME LIMIT set_time_limit(30); // set an appropriate time limit ignore_user_abort(false); // stop when long polling breaks // (E2) LOOP UNTIL THERE ARE UPDATES OR TIMEOUT $_auctionbids = new auctionbids(); while (true) { $auctionbids = $_auctionbids->getauctionbids(); if (isset($auctionbids["unix"]) && $auctionbids["unix"] > $_POST["last"]) { echo json_encode($auctionbids); break; } sleep(1); // short pause to not break server } } ?> You can try this out and see if you can make the path work... -
Need some help to specify path to website root.
Flashmaster82 replied to Flashmaster82's topic in General Support
Thanks for the reply.. I´m not good at js so i don´t know how to implement that code ? -
Need some help to specify path to website root.
Flashmaster82 replied to Flashmaster82's topic in General Support
Thanks for the reply @Jan Romero But it didn´t work? hmm.. i wonder why it works on localhost and not on live server.. just to be clear the file is outside the templates folder, root of the website folder. I have tried to put the file inside the template folder in my assets/auction-page/ folder but then it won´t work. So therefor i put it in the root folder. <script> // (B) LAST UPDATED TIMESTAMP var last = 0; // (C) AJAX LONG POLL function poll () { // (C1) FORM DATA let data = new FormData(); data.append("last", last); console.log("Fetch run", last); // (C2) FETCH UPDATE ON SERVER RESPONSE fetch("<?=config()->urls->httpRoot?>auction-longpolling.php", { method:"POST", body:data }) .then(res => res.json()) .then(data => { // (C2-1) UPDATE HTML DISPLAY document.getElementById("bid").innerHTML = data.bid; // (C2-2) NEXT ROUND last = data.unix; poll(); }) // (C3) CATCH ERROR - LOOP ON TIMEOUT .catch(err => poll()); } // (D) GO! window.onload = poll; </script> -
I need some help to specify path to website root. templates/assets/auction-page/javascripts.php fetch("../../auction-longpolling.php", { method:"POST", body:data }) the file is located in website/auction-longpolling.php It´s working in localhost but not on live server?
-
Maybe I have to define the auction-bid before i can define the variables with the parent? Because it's not working right now
-
Yes, its not getting the parent page? Should i defined it before? I´m lost PHP Warning: Undefined variable $pageparentdate Also i got Undefined variable $parent
-
$wire->addHookAfter('Pages::added', function(HookEvent $event) { $page = $event->arguments(0); $pageparentdate = $page->parent->auction_end_date; $parentdateminusstart = date( 'Y-m-d H:i:s', strtotime($pageparentdate . ' - ' . "3" . ' minutes')); $parentdateminusend = date( 'Y-m-d H:i:s', strtotime($pageparentdate)); if (!$page->matches("template=auction-bid, auction_bid_date>={$parentdateminusstart}, auction_bid_date<={$parentdateminusend}")) return; $parent = $page->parent; $parentdate = $parent->auction_end_date; $parentdateadded = date( 'Y-m-d H:i:s', strtotime($parentdate . ' + ' . "3" . ' minutes')); $parent->setAndSave('auction_end_date', $parentdateadded); }); Thank you so much @Jan Romero Current code. Error! I get Undefined variable $pageparentdate? Don´t know how to define it?
-
But how should i test a variabel in ready.php? I´m not so familiair with the debug tool.