Jump to content

Robin S

Members
  • Posts

    4,791
  • Joined

  • Days Won

    303

Everything posted by Robin S

  1. @Guy Incognito, as a general debugging tip: you should use a debugging tool like TracyDebugger rather than relying on message() because if some code somewhere does an exit() or die() then you might not see any visible message. For example, Session::redirect() calls exit(0) and maybe other core methods too. TracyDebugger has a Dumps Recorder panel that can capture any dumps that otherwise might get missed. And when you're troubleshooting and trying to narrow down an issue you don't want any non-essential code executing. In your example you have: public function upgrade($fromVersion,$toVersion) { $this->___install(); $this->wire()->message('Upgrade method called'); } But it would be better not to call ___install() before your debugging message because something might be happening in ___install() that prevents your message. So probably this would be a good way to check if the upgrade method is being called: public function ___upgrade($fromVersion, $toVersion) { bd($fromVersion, "fromVersion"); bd($toVersion, "toVersion"); } As for the problem itself, I tested here and can report: 1. The method name must be ___upgrade() and not upgrade(). The docs for Module make it sound like it is optional whether the method is made hookable with the underscore prefix but that seems to be incorrect because I can't see the method firing if the underscores are missing. So either that's a bug or the docs need to be updated. 2. The method is called when the module is next loaded, not necessarily when you do a Modules > Refresh. The core message gives a hint about this: If your module has autoload set to true then it will be loaded immediately after the refresh (and on every other page load). But if it's not autoload and you want to see the ___upgrade() method called then you can force the module to load like this: $modules->get('YourModuleName'); This isn't a bug as whatever actions you are taking in ___upgrade() will get applied in time for the next usage.
  2. Hi @Roope, There seems to be a problem when the text for an email link contains the smart apostrophe character: ’ It causes part of the closing <a> tag to get duplicated and this appears as visible text in the browser. Source code in CKEditor: After Email Obfuscation has processed it:
  3. I think perhaps you missed the point of my earlier post: When you use this approach you don't need a different URL to the regular one. If a non-logged-in visitor tries to view a page that you must be logged in to view then they get redirected to your custom login form and the ID of the page they tried to view is preserved in a GET variable (you could use a URL segment to hold the ID instead of a GET variable but I can't see a reason why that would be preferable). So let's say I try to view a restricted page at https://www.websitedomain.com/articles/i-love-processwire/ It doesn't matter how I got the URL - it could have been in an email, or a browser bookmark, or whatever. If I'm not logged in when I try to view it and the page template is configured like I showed in my earlier post then I'm automatically redirected to https://www.websitedomain.com/my-login-page/?return=1234 And if the hooks I showed are in ready.php then after I login I'm automatically returned to https://www.websitedomain.com/articles/i-love-processwire/
  4. @tires, if it's working for you then great, and I don't really get how URL segments relate to what you're doing, but what I was suggesting is to use hooks like this: // Add return GET variable to form action URL so it's available after the login form is submitted $wire->addHookAfter('LoginRegister::buildLoginForm', function(HookEvent $event) { /** @var InputfieldForm */ $form = $event->return; $return_id = (int) $event->wire()->input->get('return'); if($return_id) $form->action .= "?return=$return_id"; }); // If login is successful... $wire->addHookAfter('LoginRegister::loginSuccess', function(HookEvent $event) { $return_id = (int) $event->wire()->input->get('return'); // ...and there is a return page ID... if($return_id) { // ...check that the user can view the page and if so redirect back to it $return_page = $event->wire()->pages->get($return_id); if($return_page->id && $return_page->viewable()) { $event->wire()->session->location($return_page->url); } } });
  5. One more option... You could copy MarkupHTMLPurifier from /wire/modules/Markup/ to /site/modules/ and then select it as the copy you want to use. Then edit HTMLPurifier.standalone.php to replace this code with: return '<' . $token->name . ($attr ? ' ' : '') . $attr . '>'; Seems to solve the slash issue without affecting HTML5 elements like <figure>
  6. @tires, when redirecting to a login URL from a page that has restricted view access PW has a built-in option to include the ID as a GET variable. You can make use of this ID number in a hook after successful login to get the page that the user was trying to access and then redirect back to its URL.
  7. @patrick, try this: $wire->addHookAfter('MarkupHTMLPurifier::initConfig', function(HookEvent $event) { $settings = $event->arguments(0); $settings->set('HTML.Doctype', 'HTML 4.01 Transitional'); }); For this to take effect you'll also need to clear the HTML Purifier cache which you can do by executing the following once (the Tracy Debugger console is useful for this sort of thing): $purifier = new MarkupHTMLPurifier(); $purifier->clearCache();
  8. I updated my example because $input->is('post') is probably a bit too broad. It might be fine for your case but if you want to show the RuntimeOnly field value as a column in a Lister then $input->is('post') is true when the Lister results get AJAX-loaded according to the filter form values. So checking for the Page Edit submit button value with if(!$input->post('submit_save')) is probably better.
  9. Hmm, I guess the field is getting output formatting turned on during the save process and the page editor doesn't explicitly turn it off. I can think of a couple of ways around this. You could get the formatted value and output the markup only if the Page Edit form is not in the process of being submitted (as detected by "submit_save" button value not being present in $input->post): if(!$input->post('submit_save')) { $image = $page->getFormatted('your_image_field'); if($image) { // ... } } Or you could deliberately get the unformatted value which will be a Pageimages WireArray. $pageimages = $page->getUnformatted('your_image_field'); $image = $pageimages->first(); if($image) { //... }
  10. @mel47, this sanitizer method will work with any text - it doesn't matter where the text comes from. Use Tracy Debugger to check that the value you are supplying to the sanitizer method is definitely text and not something else.
  11. In the context of CKEditor the <br /> tag is probably caused by the CKEditor settings rather than HTML Purifier. Using this answer as a reference, you could put the following in /site/modules/InputfieldCKEditor/config.js: // When CKEditor instance ready CKEDITOR.on('instanceReady', function(event) { // Output self-closing tags the HTML5 way, like <br> event.editor.dataProcessor.writer.selfClosingEnd = '>'; });
  12. I presume you're using MarkupPagerNav. If so see the arrayToCSV option in the docs: https://processwire.com/api/ref/markup-pager-nav/#pwapi-methods-other-options But rather than change this option consider using the whitelist to store the sanitized search input and to set the values/states in your search form instead of using $_GET. See Ryan's Skyscrapers code for examples of how to do this: https://github.com/ryancramerdesign/skyscrapers2/blob/master/search.php https://github.com/ryancramerdesign/skyscrapers2/blob/master/includes/search-form.php
  13. This isn't anything specific to this module - it's just the effect of output formatting being on or off. Unfortunately there is no general documentation page explaining the idea of output formatting but the $page->of() docs gives you some info. The rule of thumb is that output formatting is on in the frontend and off in the backend, particularly in a situation where field values are going to be saved like in the page editor. You can set the formatted value of a single image field to be a Pageimage but when output formatting is on it will always be a Pageimages array. So in FieldtypeRuntimeOnly you need to specifically ask for the formatted value of the field: $image = $page->getFormatted('squareimg'); if($image) { // ... }
  14. For so many items an autocomplete would perform much better. Is that an option? If it's the need to use a hook to specify selectable pages that's preventing you from using PageAutocomplete there are workarounds for this.
  15. @szabesz, the output can't go below the button because the button is not in the results area. But I added a bottom margin so there is some separation from the button.
  16. This might be a somewhat niche module but I had a need for it and maybe others will also find it a useful development helper. Lister To Clipboard Easily copy a selector for the current Lister filters or selected results to the clipboard. For superusers only. Why? Lister or Lister Pro is handy for finding pages according to certain page attributes or field values and you can see the matched pages in a results list. Sometimes I want to run code on some or all the Lister results. Lister Pro allows results to be processed through Page Action modules but there are a couple of downsides to this: To execute custom code you would have to create a custom Page Action module and this may not be worth the trouble for a one-off operation. If you want to process only selected individual pages you can only select items from one page of the results. If you navigate to a different page within the paginated results the selection is lost. Lister To Clipboard gives you an easy way to copy a selector for the current Lister filters or a selection within the results so you can paste it into the Tracy Debugger Console or use it elsewhere in your code. Usage In Lister (Find) or in a Lister Pro instance, create filters to match the pages you want to target. If you want to select individual pages within the results, click an empty area of the cell within the first column (i.e. don't click directly on the page title). The cell will get a green background to indicate that it is selected. If there is more than one page of results you can move around the pagination to select more pages. Below the Lister results there is a blue box showing a selector string that will find the pages shown in your Lister results (or your selection within those results) when used in $pages->find(). Click the copy icon to copy the selector to the clipboard, then you can paste it into the Tracy Debugger Console or wherever you want to use it. https://github.com/Toutouwai/ListerToClipboard https://processwire.com/modules/lister-to-clipboard/
  17. @nicolant, ProcessWire doesn't allow filenames to include dots, perhaps because Images fields use a dot to separate the variation suffix from the basename and Images and Files fields share some of the same code. If using dots in the filename is essential for some reason and you are willing to use an experimental module you could try this: https://github.com/Toutouwai/FieldtypeFileUnrenamed
  18. If by "featured" you mean "linked to within a CKEditor field" then it's pretty easy. You just upload the file to the first page it will be used on (Page A), and on any of the other pages you use the CKE link dialog to select Page A and then select the file.
  19. Check out the blog post that introduced InputfieldTextTags: https://processwire.com/blog/posts/pw-3.0.177/#using-with-options-fields If you use a Page Reference field for your tags then you can add new tags via the inputfield if the field settings are configured to allow it. From the blog post:
  20. One more possibility: get your non-user pages by path instead of by ID. If you use PagesLoader::getByPath() it should be just as robust as getting by ID because page path history will handle any renaming or moving of pages. And as a bonus the code is more readable because it's more obvious what page is retrieved by '/about-us/sustainability/' than by 24875. $p = $pages->loader()->getByPath('/about-us/sustainability/', ['useHistory' => true]));
  21. I haven't been a regular user of the RuntimeMarkup module so I'm not qualified to talk about it. Maybe the best thing would be for you to try both modules and see which one suits you better.
  22. I'm not sure what the reason for the ID limitation is, but you could set the value of each option to the integer you want:
  23. Thanks for the report. It's hard to know when FormBuilder methods were added because there are no @since tags in the code. In v0.1.5 I've changed to older FB methods for better backwards compatibility.
  24. @AAD Web Team, if you're wondering why status!=hidden doesn't work in this selector it's because status keywords like that are only supported in PageFinder selectors like $pages->find() that query the database, and not by selectors that match against a PageArray in memory. And although the docs don't make this clear $page->parents() actually adds all the parents one by one into a PageArray and then filters that PageArray by the selector. See here. It is a bit confusing that $page->children($selector) goes through PageFinder but $page->parents($selector) doesn't.
×
×
  • Create New...