Jump to content

MarkE

Members
  • Content Count

    262
  • Joined

  • Last visited

  • Days Won

    1

MarkE last won the day on April 12

MarkE had the most liked content!

Community Reputation

48 Excellent

About MarkE

  • Rank
    Sr. Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Have you tried wire()->addHookBefore('Pages::save', function ($event) { $p = $event->arguments(0); // Get the previous version of the page $oldPage = wire('pages')->getById($p->id, array( 'cache' => false, // don't let it write to cache 'getFromCache' => false, // don't let it read from cache 'getOne' => true, // return a Page instead of a PageArray )); Then you can compare the old and new.
  2. A bug? (version 1.1.2) On selecting a subfield in a lister and typing in the value to match, I get the error "Call to a member function isEmpty() on string" for line 55 of FieldtypeStreetAddress.module
  3. This is a really useful module. I have only had one issue so far - the default country setting in the field config page does not seem to work in the API. I have to set (e.g.) $this->address->origin_iso = 'GB'; for it to be effective.
  4. Hi @xportde. I have noticed the same thing. I assume this is important to you because you have some hook or other that you only want to operate if fields have changed. What I do is simply catch and exclude any field changes that I'm not interested in. E.g. in a Pages::saved hook: $excludeFields = ['runtime_markup_parent', etc.......]; $changes = array_diff($event->arguments(1), $excludeFields);
  5. One 'gotcha' that gets me more than I'd like is that if a session has expired, PW gives you no warning. Scenario - you are editing a page and go away to do something else for a bit (you saved it first of course 😉 ). Then you come back to the page and do some more edits and save - whoa! your edits are irretrievably lost because the session had timed out without telling you. I try and get into the habit of refreshing before I start work again, but don't always remember 😞 .
  6. I've used Lazy Cron successfully elsewhere, combined with a Cron job to trigger it. However on my current project it is not working. The reason seems to be that it is not giving a normal response type. The Cron job is wget --quiet no-cache -O - https://domainname... It runs each time with an error-free response, but does not trigger Lazy Cron. If I paste the url https://domainname... into the browser it does trigger LazyCron. With a bit of debugging, the reason is clear - the Cron job gives responseTypeAjax = 2 which is bypassed by Lazy Cron, but the browser gives responseTypeNormal = 1 which is processed by Lazy Cron. Any ideas why and how to fix it (other than hacking LazyCron.module)? The triggered page is just a simple template with a response of "echo 'Hello from ' . $page->title;" EDIT: Please ignore this - I think I have mis-diagnosed the problem - will sleep on it!! EDIT2: Nothing wrong with LazyCron. Problem was not assigning permissions to the cron job -i.e. the triggered function did not operate properly with "guest" role.
  7. MarkE

    WireMailSmtp

    I have a temporary work-round, although less than ideal. I capture the form details and save it as a page in admin_instance (that works fine, using $config->admin_site). Then a LazyCron in the admin site picks up new forms and sends the emails. (I tried to use a hook after Pages::added, but it seems that this is not triggered when the page is added from another instance.) When the LazyCron runs, it is of course running in the admin instance. EDIT: Actually there are pros and cons of the work-round method, so I will stick with it for now. Thanks for the comments @horst.
  8. MarkE

    WireMailSmtp

    Yes. It is used extensively elsewhere in Availability.php and works fine. Config ($config->admin_site outputs ProcessWire 3.0.153 dev #1) No the host page is in site-web, which I think you are calling website_instance. No. It is in admin_instance, where the runtime markup field with Availability.php is.
  9. MarkE

    WireMailSmtp

    Sorry - I forgot to say that I had tried various other things, including your suggestion. I've now done those things again (with $mailOwner rather than $mail - I'd forgotten that was predefined) and recorded the error in each case. These are reproduced below as a pair of lines - code followed by error: $mailOwner = $config->admin_site->wire('mail'); Could not get the right WireMail-Module (WireMailSmtp); found: WireMailTools [My debugging line] $mailOwner = $config->admin_site->mail->new(); require_once(./WireMailSmtpAdaptor.php): failed to open stream: No such file or directory in M:\laragon\www\BawdHall\site\assets\cache\FileCompiler\site\modules\WireMailSmtp\WireMailSmtp.module on line 290 The second of these seems to be calling the right module (WireMailSmtp) but can't find the file because $config is always for instance_A. This seems similar to the issue we had with Runtime Markup.
  10. MarkE

    WireMailSmtp

    Yes. The php for that field is Availability.php, which is in instance_B, and calls mail as described above. Not sure what more info you want re "where and how". Abbreviated code for this script is below: <?php namespace ProcessWire; $headers = getallheaders(); $permittedNonPW = array_map('trim', array_map('strip_tags', explode(',', $page->bodyTop))); $permittedPW = array_map('trim', array_map('strip_tags', explode(',', $page->bodyFoot))); // If site is a PW site, then need to deal with the different instances if (in_array($headers['Host'], $permittedPW)) { $site = $config->admin_site; $config->sitePages = $config->admin_site->pages; } else { $site = wire(); $config->sitePages = $pages; } ///////////////////////////////////////////////////////// // Process any form results: /////////////////////////////////////////////////////////// // define variables and set to empty values $name = $email_address = $phone = $fromToDate = $adults = $children = $pets = $provbooking = $message = $spambot = ""; $fromerror = $toerror = $radioerror = $propertyName = ""; function test_input($data) { //......... return $data; } if (isset($_GET["submit"])) { $out = ''; if ($_SERVER["REQUEST_METHOD"] == "POST") { $propertyName = test_input($_POST["property"]); //...... //fill variables } //...... $mail = wireMail(); if($mail->className != 'WireMailSmtp') { wire()->log->save('debug', 'Could not get the right WireMail-Module (WireMailSmtp); found: ' . $mail->className); } else { $mail->to($to) ->from($myemail) ->subject($email_subject) ->bodyHTML($email_body_top . $email_body); $numsent = $mail->send(); if ($numsent > 0) { //..... $out .= '<script>alert("Your request has been submitted - you should receive an automated email acknowledgement shortly.")</script>'; //..... $url = strtok($_SERVER['REQUEST_URI'], '?'); $out .= '<script>window.location.assign("' . $url . '");</script>'; return $out; } /////////////////////////////////////////////// /////////////// MAIN PAGE //////////////////// ////////////////////////////////////////////// $currentPath = $files->currentPath(); $out = ... // Fills the availability table ... ////////////////////Don't forget the form itself////////////////////////////// if (in_array($headers['Host'], $permittedPW)){ wire()->log->save('debug', 'Calling booking form sitePages = ' . $config->sitePages->get('/')->title . ', $headers["Host"] is ' . $headers["Host"]); $out .= $config->admin_site->files->render($currentPath . 'booking_form.php'); } else { $out .= wire()->files->render($config->paths->templates . 'RuntimeMarkup/booking_form.php'); } //////////////////FINALLY RETURN THE OUTPUT!!!/////////////////////////// return $out; This works fine for $permittedNonPW but not for $permittedPW.
  11. MarkE

    WireMailSmtp

    In your terminology, lets say instance_B is "site" and instance_A is "site-web". Both sites sit under the same root, sharing the same wire/ (i.e. a multi-site installation). in _init.php (part of the template rendering) in instance_A: $config->admin_site = new ProcessWire($config->paths->root . 'site/'); I use $config->admin_site so that it can be accessed anywhere (assuming the current context is instance_A). Ah, that's a bit (!) more complicated. Instance_A accesses a runtime markup field in instance_B thus: $adminPage = $config->admin_site->pages->get("template=Availability, name=bawd-hall-availability"); $availabilityTable = $adminPage->runtime_markup_availability; This field renders php in the file Availability.php, which lives in instance_B ("site") Availability.php renders a form thus: $out .= $config->admin_site->files->render($currentPath . 'booking_form.php'); where $currentPath is $files->currentPath(); - i.e. booking_form is a sibling of Availability. (BTW, Availability.php checks the host name in the headers to determine whether it is being called as a second instance or not). booking_form's action is $_SERVER['REQUEST_URI'] (i.e. the original page, thus running Availability.php again). Availability.php tests (isset($_GET["submit"]) ) and if true processes the POST variables from the form. After validation, the mail is constructed from these variables with $mail = wireMail(); etc. For more background (if you really want 😉 ) you can see here, where @kongondo was extremely helpful getting the RuntimeMarkup Fields module working in a multi-instance environment.
  12. MarkE

    WireMailSmtp

    I've used this module a number of times and it works well. Now I am trying to use it in a multi-instance environment and am a bit stuck. Is this possible at all? To explain: I have two sites (in a PW multi-site setup - although I think the issue would be the same even if they were completely separate). "site" is a private admin site and "site-web" is a public website. "site-web" accesses "site" via an instance as described in https://processwire.com/blog/posts/multi-instance-pw3/. "site" has a contact form which is accessed by "site-web" and has WireMailSmtp installed. When completed, an email is sent using $mail=wireMail(). This works fine when the public site is not a PW site. However, when it is a PW site (as "site-web" is), the context for WireMail is "site-web", not "site", so $mail returns a WireMail class, not a WireMailSmtp class. I cannot find a way to call WireMail in the right instance context. If I try and call WireMailSmtp directly, it is operating in the wrong context and fails. I guess I could install a copy of WireMailSmtp on "site-web", but then I need to maintain the config on both sites. Besides it seems counter-intuitive that using a non-PW site for the public site should be easier than doing it in PW! I'd be grateful for any ideas or insights.
  13. Nor me. It seems like PT calls the RM PHP file more than once. The first time it works properly with a Pageimage, but then later calls submit a string/integer/boolean. The code to bypass the latter has the side effect that the RM field now has nothing in it - hence the need for the reload. All pretty messy! I've tried various debugging routes, but can't work out how the multiple calls are happening.
  14. This seems to fix it: https://github.com/furf/jquery-ui-touch-punch
×
×
  • Create New...