Jump to content

michelangelo

Members
  • Posts

    64
  • Joined

  • Last visited

Everything posted by michelangelo

  1. It worked! I don't know how I missed that. I was pretty sure I checked the path that was generated with docroot, but I guess I won't forget it next time. I am leaving it for a few hours now to test with my actual script and hopefully it's all good. Thanks for the quick tips, guys!
  2. Hello guys, I have never worked with cronjobs and it seems that after some digging I am almost there, I just need to make sure I include Processwire in the mix. I have included the script and my output under the explanation. Some info on my setup: – Using Hostinger's hPanel cronjob every hour – Connected to a script in my templates folder called cronjob.php (The script is tested and it works) – The script logs some data in cron_test.txt – It seems everything works until it reaches the first Processwire instatiation and it stops. Unfortunately, no errors are logged in hPanel or Processwire logs and I get no errors if I access a page that is using this template. The script cronjob.php <?php namespace ProcessWire; // =-=-=-=-=-=-=-=-=-=-=-= // Save the images in pages // =-=-=-=-=-=-=-=-=-=-=-= $pw_path = $_SERVER['DOCUMENT_ROOT'] . '/index.php'; include_once($pw_path); $t = time(); $t = date("H:i:s", $t); $id = 'test-cron-' . $t; $thumb_url = 'https://im0-tub-ru.yandex.net/i?id=84dbd50839c3d640ebfc0de20994c30d&n=27&h=480&w=480'; $timestamp = '116161822'; $caption = 'Cron-job-test'; saveImageToDB($id, $thumb_url, $timestamp, $caption); function saveImageToDB($id, $thumb_url, $timestamp, $caption) { $crontext = "Cron Run at ".date("r")." by ".$_SERVER['USER'] ." with PW bootstrapped \n" ; $folder = substr($_SERVER['SCRIPT_FILENAME'],0,strrpos($_SERVER['SCRIPT_FILENAME'],"/")+1); $filename = $folder."cron_test.txt" ; $fp = fopen($filename,"a") or die("Open error!"); fwrite($fp, $crontext) or die("Write error!"); fclose($fp); echo "Wrote to ".$filename."\n\n" ; echo "0"; $p = new Page(); // create new page object echo "1"; $p->template = 'nk-image'; // set template echo "2"; $p->parent = wire('pages')->get('/images/'); // set the parent echo "3"; $p->name = $id; echo "4"; $p->title = $id; $p->save(); // populate fields $p->text_short = $thumb_url; $p->image->add($thumb_url); $p->timestamp = $timestamp; $p->textarea = $caption; $p->save(); } In the hPanel I get the output: Wrote to /home/u9999999999/domains/domainname.com/public_html/site/templates/cron_test.txt 0 and in cron_test.txt: .. Cron Run at Sun, 15 Aug 2021 06:00:02 +0000 by u999999999 with PW bootstrapped Cron Run at Sun, 15 Aug 2021 07:00:02 +0000 by u999999999 with PW bootstrapped Cron Run at Sun, 15 Aug 2021 08:00:02 +0000 by u999999999 with PW bootstrapped Cron Run at Sun, 15 Aug 2021 09:00:01 +0000 by u999999999 with PW bootstrapped What am I missing? I feel I am so close 😄 Thank you!
  3. Hello guys, I am trying to integrate mathJax but I cannot get it show in the toolbar. Can you share the steps that you are following? I started from here https://ckeditor.com/cke4/addon/mathjax, but I cannot get it to be displayed in my editor. Thanks!
  4. Hi @adrianthank you for the module, I have been using it for years on and off and it has saved tons of work! I have a question regarding inline editing. I know it has been asked a lot but I have only 1 field to edit per page and wondered if I can go without purchasing ListerPro? This is how my setup looks like. Imagine that I just have to pick some categories in Category Reference and potentially delete the page. Can you give me a hint/direction how I can approach this? Thank you!
  5. Hello @VeiJari I recently setup https://processwire.com/modules/rest-api/ and I couldn't get it to work easily on localhost. How are you testing it? Maybe it can save some trouble by trying to deploy it somewhere?
  6. Hello guys, I have an issue that might be solved with the Lister module or ListerPro. I don't want to order the paid module if it's not necessary. That's why I wanted to ask first. I have multiple images that my client wants to be able to go through and categorise them. The structure in a lister looks like this: The "Category Reference" is related to a few categories that are in multiple groups: I would like to have those options show up in the Lister and be able to quickly select them. This is how the categories look like in the Image page itself: Is there a way to do it with the built in PW modules? I just want to have the table-like view in the lister and in the "Category references" to have my three options "Cloth, China, Surgical". Thanks!
  7. @teppo That's a good point about the Instagram policies, I will go over it once more. Maybe writing the scraper in PHP is better idea than switching to a completely different stack where I have to build the backend and everything from scratch. Thanks! Out of curiosity though: It is possible to run a python script with a cronjob, right?
  8. Hello everyone, I would like to ask for some advice on what options I have to build an app I have in mind. It will scrape images from instagram and save each of them as a PW page, then the admin can edit them and it will be displayed on the front-end. The challenge for me is to have a cronjob, to run a scraper maybe written in Python, and populate the database using the PW API. Is this sensible? Is it suitable to use PW for this or should I use another technology?
  9. @horst so I guess this will work If I hook that method every time I access www.website.com/api/ route? And then monitor how many requests I get. I just have to figure how to do those.
  10. Hello everybody, I am currently indulging myself into building a REST API based on a older project of mine. It's very simple where you can mainly retrieve information in JSON. It's similar to JSON Placeholder in the level of complexity. I am using the RestAPI Module and native ProcessWire API functions. Rate-Limit Throttling is something I want to implement because it's public without authentication, despite not extremely necessary. Now, is it better to utilise something like Token Bucket or ProcessWire already has some protection against too many requests? There is a simple Token Bucket library I found that is going to work but I want to limit the traffic only to the /api/ route, not to my whole website. All input is appreciated, later I will share the project here. Thanks!
  11. Thanks for the suggestion, however this has the same infinite loop effect as the ::loaded hook. It just goes Page::render -> Saml -> Page::render -> Saml -> ... Okay, that's silly but I just added a condition to actually check for the Saml Response. This way it doesn't try it after the user is in... Thanks @louisstephens if (!isset($_SESSION['samlUserdata'])) { // User not logged in to SAML $this->session->addHookBefore('PageRender::renderPage', $this, 'loginsaml'); }
  12. Hello guys, I have been setting up a SAML Auth for my website for a few days with SamlAuth and the last thing left is to hook the initial login to when the visitor loads for the first time any page of the website. The module uses ProcessLogin::renderLoginForm which is perfect for when a user accesses the admin but I want to close the whole website off. I don't want to use the PageProtector as I find it an overkill for such redirection purpose. I also tried Page::loaded which created an infinite loop 😃. So is there a Hook I can use or another method which makes more sense? Thank you!
  13. Hello guys, I saw that many people found the module SamlAuth useful and I wanted to try it. I have encountered an issue with the setup as I cannot verify the validity of the requests and it's quite hard to debug. The IDP we have is Azure, so most of the documentation is quite different from Onelogin or SimpleSAML. Everything works until I get this error which is quite vague: I have also the XML and certificates but I am not sure which one is the correct one :| Can somebody give me a hand by saying at least if I am in the right direction? Thank you!
  14. I managed to set up the SAML module until a certain point and now I get an error from the IDP: AADSTS750161: Allowed SAML authentication request's NameIDPolicy formats are: urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress,urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified,urn:oasis:names:tc:SAML:2.0:nameid-format:persistent,urn:oasis:names:tc:SAML:2.0:nameid-format:transient. Just wondering if anybody has a tip of how to fix it? I am not sure in the module settings where I can change these formats... EDIT: It was an actual attribute in settings.php... I just missed it...
  15. I am building a project where students will be able to access a website only if they authenticate with their student accounts. That's why we opted for this option.
  16. Hello @BillH, thank you for your comments and directions! I must have missed it by not searching for the right terms... I will just describe my thought process so you can tell me if I am correct: 0. Setup Page Protector and SAML Authentication Modules 1. Setup the Page Protector to stop the visitor from accessing any content 2. Redirect the user to an IDP where they will log in 3. ProcessWire recognises that and it opens the website...
  17. Hello guys, there are many topics on authentication of the superuser or APIs, but I couldn't find what I need: Can a visitor of the website be asked to authenticate? Just to see the website, without any permissions or back-end access? Is this possible with SAML?
  18. Thanks @MoritzLost! It worked now. Something was happening with the regex AND with my input. It's all good now!
  19. Thanks @MoritzLost! I will fix the issues with my regex now. The $link->textarea_short contains what I expect and it's a string. What I am trying to do is have the client enter a url from mixcloud, e.g. https://www.mixcloud.com/toddyflores/matinee-2015-formula-1-grand-prix-mixtape-by-toddy-flores/ and I will render the appropriate mixcloud iframe player. The iframe uses this structure: <iframe width="100%" height="60" src="https://www.mixcloud.com/widget/iframe/?hide_cover=1&mini=1&feed=%2Ftoddyflores%2Fmatinee-2015-formula-1-grand-prix-mixtape-by-toddy-flores%2F" frameborder="0" ></iframe> so everything in the feed i want to replace with the parsed channel and track. that's why: https://www.mixcloud.com/toddyflores/matinee-2015-formula-1-grand-prix-mixtape-by-toddy-flores/ // becomes ...feed=%2Ftoddyflores%2Fmatinee-2015-formula-1-grand-prix-mixtape-by-toddy-flores%2F... // this expression Why would preg_match() refuse to work with my variable $str?
  20. I am doing a very simple string parsing from a url taken from a Textarea inputField. It's all working fine if I define the link as a string, e.g. $str = 'some url', but if it is taken from the CMS it doesn't work... $str = $link->textarea_short; // this doesn't work // Expected Output: '<p>https://www.mixcloud.com/some-radio/</p>' // $str = '<p>https://www.mixcloud.com/some-radio/</p>'; // this works preg_match('/<p>https*:\/\/www\.mixcloud\.com(.*)<\/p>/', $str, $matches, PREG_OFFSET_CAPTURE); $str_url = $matches[1][0]; $str_url = str_replace('/', '%2F', $str_url); echo($str_url); This is the algorithm that I am working with: 1. Getting a url 2. Parsing it to extract what I need 3. Replacing some characters. In both cases if I echo the values I get the right result but in the preg_match() doesn't work. What am I doing wrong?
  21. Following Gadgetto's train of thought I also found out now that using a commercial solutions really saves money in the long run. I really didn't want to risk security for example, so Snipcart could be great. Otherwise there are many breakdowns of what's good and what's not and I think unless you have an extremely simple shop you will most likely need a fully-fledged system.
  22. Hello everyone, I was curious to know if there is a way to access discounts from SnipWire? I would need it to recalculate the price on the front-end based on the quantity of items. Thank you! p.s. I know I have been posting a lot, but it's my first time using SnipWire and Snipcart so much. Thanks for the understanding.
  23. @Gadgetto That might help! I think in general more thorough documentation will really help people, but I can understand that's quite a lot to do. For example, I am not super sure how Snipcart parses all the information from the $anchor variable output by SnipWire? I want to update the price based on a bundle of products by using prices and discounts directly from the Snipcart API: So when you go up or down the grams, it will already update the price on the right (also adding the discounts if any). 1g = €50 2g = €90 3g = €130, etc Now do I access directly Snipcart with its own api or I change the cart by SnipWire? This: Snipcart.api.items.add({ "id": "mineral", "name": "Mineral", "price": "50.00", "quantity": 1, // change this value to update the cart? ... }); or this: <button class="snipcart-add-item" title="Add to cart" aria-label="Add item to cart" data-item-name="Mineral" data-item-id="mineral" data-item-price="{eur: 50.00}" data-item-quantity="1", <!-- change this value to update the cart? --> ... Add to cart</button> I would like to keep it simple and clean. Last but not least Thank You for all your work, it is a massive help!
×
×
  • Create New...