Jump to content

DrQuincy

Members
  • Posts

    293
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by DrQuincy

  1. I need to check some data when pages are moved or saved. It runs fine when I save a page (Pages::saved) but nothing happens when I move a page (e.g. to and from trash). It only appears to be the lack of warning that is the issue. The hook definitely runs when I move pages in the site tree as I set up a simple bit of text file logging. wire()->addHookAfter('Pages::moved, Pages::saved', function($event) { $event->warning('Warning'); }); Is it because from the site tree moving pages is done with AJAX? Is there a way to output a warning when sorting or moving pages in the site tree or is it not possible? Thanks. P.S. I have noticed on Pages::saved if you change the status from the tree view (using Unpub, Hide buttons) the hook calls but the messages are not displayed. So really I guess my question is: how can hooks send messages, errors and warnings in the tree view?
  2. For anyone who is interested I did this with the normal Page Reference field the way @Robin S suggested. I created a parent filter template and a child filter template (no template file and just the title field for both). I added a parent filter page and some child filters to the site tree. In the Input tab of the Page Reference field I checked Allow new pages to be created from field? Then under Selectable pages I set Parent to the page that uses the parent filter template and Template to the child filter template. It now works exactly as I wanted it — so thanks! ?
  3. Thanks to you both. I will just go with pages then. I will certainly try ProcessPageFieldSelectCreator, that looks really interesting!
  4. Just as the title says really: is there a field that basically acts like a normal Select Options field but instead of having to go into Fields to add options you can do it while you're editing the page — and this then propagates to any other template that uses this field. I basically want to let the client add to Select Options but don't want to give them access to edit the field. I know I could do it by page reference/repeater but I wondered if there was a way that 1. avoids the overheard of pages and 2. where options could be added while you're editing the page rather than having to go elsewhere. I do have a license for ProFields but don't think there's anything there that does this. I hope that makes sense! Thanks.
  5. @BitPoet, I certainly wouldn't expect things to change on my account. Maybe the problem is not that common but I have certainly run into it a few times over the years on shared hosting. If you do work the kinks out and put it forward I would 100% vote for it. ? @horst, that is a great idea, thanks. I'd forgotten it was possible to do that. As usual, this forum is exceptional when it comes to helpful replies!
  6. Firstly, when you do a MATCH AGAINST query in MySQL you can get the score. I have found this useful in the past where you want to place more on one field over another (e.g. you may wish to place more weight on a h1 fields than a body field) as you can add a multiplier to the relevancy score. E.g. SELECT `h1`, MATCH(`h1`) AGAINST ('birth') AS `score1`, MATCH(`body`) AGAINST ('birth') AS `score2` FROM `pages` ORDER BY (`score1` * 2) + `score2` DESC # h1 twice as important LIMIT 10; Without resorting to raw database queries can such a thing be done using the API? I.e. with $pages->find(). I searched the docs but couldn't find anything. Secondly, according to https://processwire.com/docs/selectors/#sort If your query contains more than one fulltext search does PW combine the relevancy and order by that (if you don't explicitly sort by a property)? It seems to but from my tests I can't be 100% sure. Thanks.
  7. @BitPoet, thanks so much for this. You are right, it doesn't use dropzone.js but it does use the term “dropzone” in the code — which confused me! Thanks for your code. I can see you have amended the following: processwire/wire/modules/Inputfield/InputfieldFile/config.php processwire/wire/modules/Inputfield/InputfieldFile/InputfieldFile.js If I use these modified files then I presume they will be overwritten in each PW upgrade. I don't know the process for making changes to Processwire but do you think Ryan would be open to merging this into the core? I think it's a useful feature as, particularly on shared servers, Apache can 503 if it gets too many requests too soon. Thanks again for your help.
  8. Thanks for posting this, I was about to as something similar. I'm not sure the “Unique” status is a good fix to what I'm after doing. It looks like a hook per @Robin S‘s code would do the job nicely. I love PW. One thing I do think would be nice though for a future version would be for the core to offer some of the data integrity features of a rational database but managed through template and page settings: Something to mimic CASCADE and RESTRICT so that in a page reference, for example, you can restrict it being deleted if another page references it Make a field (of fields) unique as above
  9. Thanks to you both. I am flat out with work at the moment so will reply as soon as I can. I am not ignoring you! ?
  10. It appears PW uses dropzone.js for file uploads. I have used this many times before in non-PW projects and with my hosting company I run into problems with their firewall (I think) if I upload lots of files at the same time. Basically what happens is (again, I think) their network detects a bunch of large POST requests in a short space of time and temporarily cuts you out — causing some of the uploads to fail. I get the same thing with PW: if I upload a lot of files together sometimes it just freezes on me with no error message. In my custom projects the fix was easy — just set parallelUploads to 1. https://www.dropzonejs.com/#config-parallelUploads I've searched the source and online and can't find any way of controlling how many file PW will attempts to upload at one time. Can I override dropzone.js anywhere and/or is there a way to control how many files PW will attempt to upload at one time? I accept that even with parallelUploads: 1 you could still run into this issue with multiple uploaders on one template, multiple tabs open, etc but in practice the above setting has solved the problem. Any ideas? Thanks.
  11. Thanks for this; I have not heard of that method before. It is not available on my hosting either unfortunately. It looks like it is similar to readfile() but faster. From Stack Overflow: I was interested in knowing if there was a practical solution that didn't require PHP but I don't think there is and readfile() is probably the way to go. Thanks.
  12. If you want to authenticate files — and I mean properly authenticate them, not just give them a hard-to-guess name — then you could either do it with PHP or your web server (e.g. Apache) using HTTP authentication. Obviously, the latter is more efficient as it does not require PHP but it would be difficult to make work with your PHP website (e.g. with a cookie-based user login system). Assuming the use of PHP then and files stored outside of the website root, what is the most efficient way to do it in terms of memory use and speed? My gut feel is to use readfile(). According to the notes on the PHP site: Providing output buffering is off, readfile() seems suited for this and seems to be a very, very simple way to output a file outside of the web root efficiently. Would you use readfile() for this? I guess that if you want a user login system there is no way round not having the overhead of a language like PHP. This seems sesible to me but thought I'd ask in case there's a really obvious way I have missed. Thanks.
  13. In case anyone is interested this will remove absolute links on all specified HTML (CKEditor Textarea) fields using the current host (HTTP and HTTPS) and is case-insensitive. Based on @Robin S’s code. $wire->addHookAfter('Pages::saveReady', function(HookEvent $event) { $htmlFields = [ // NOTE: Set your fields here 'html1', 'html2', ]; $host = $_SERVER['HTTP_HOST']; $find = [ 'href="http://' . $host . '/', 'href="https://' . $host . '/', ]; $page = $event->arguments(0); foreach ($htmlFields as $htmlField) { if ($page->$htmlField !== null) { $numChanged = 0; foreach ($find as $f) { $numChanged += mb_substr_count(mb_strtolower($page->$htmlField), $f); $page->$htmlField = str_ireplace($f, 'href="/', $page->$htmlField); } if ($numChanged > 0) { $this->message($numChanged . ' ' . $host . ' link(s) converted to relative links for field “' . $htmlField . '”'); } } } });
  14. Oooh, interesting, thanks. I'll give it a look. ? Is this safe to use in production do you know? I couldn't find it on processwire.com where it gives this status. I know soma is a big contributor here so I would imagine it's decent!
  15. I've looked at the multi-lingual template that comes with PW and not sure this can do what I'm after. Imagine a suite of sister sites: same templates and fields but different content and (slightly different) CSS. Is it possible to have a single PW install that hosts multiple sites, each with a different HTTP host. When you add a field or template it is global in the sense that it is available to all domains. However, the actual page entries in the database are different and are loaded based on the HTTP host. E.g. johnsreallycheapcarinsurance.com and johnsreallycheaphomeinsurance.com are on the same server, same PW install and they have a template called services and a repeater called serviceList. I can create a service page on each and they will automatically use the same template file and repeater field but will have different content. johnsreallycheapcarinsurance.com/services/ johnsreallycheaphomeinsurance.com/services/ So they would use the same HTML template and repeater but would have different content. Is this easy/possible with PW without having to maintain more than one install? It's kind of like a tree partition based on the domain. Thanks.
  16. Thanks @wbmnfktr I think the Markup/HTML option refers to the where internal links go to rather than the format. Thanks @Robin S. I do often add that in the notes but it does seem to confuse some users — of they just don't read it. I like your hook idea though; that could be very effective.
  17. Is there any way in a CKEditor field to have links to the current host automatically converted to root relative links? E.g. I'm on domain.com and I add this code in source: <a href="https://www.domain.com/foo">Foo</a> And on save or in the front end it converts it to: <a href="/foo">Foo</a> Any other links would stay as is. PW seems to be good at using root relative links (e.g. if you select a page from the link CKEditor dialog) but wondered if this is possible without having to do a find/replace in the database. I'm thinking of instances where you move from development to product and end up absolute links to the development domain.
  18. For anyone that is interested in doing the same this seems to have worked. Place this in admin.php, before the controller.php line: $config->styles->add('/assets/css/custom.css'); And then add this in your new custom.css file: form#selected_image_settings p#wrap_info span#action_icons span { display: none; } form#selected_image_settings p#wrap_info span#action_icons span#description_action { display: block; } span#selected_image_pixels, span#selected_image_checkboxes { display: none; } Now you just get the image description button. Make sure you check the Skip width attributes on image tags in the Page Edit Image config or set width and height to auto in your main site CSS. I will test it out a bit more but seems to be working fine for now.
  19. @Zeka Interesting, thanks! I think if I can hide the parts I obscured in red that would do it. Is it easy to add custom CSS to the back-end?
  20. I can see in the Page Edit Image config there is an option to stop Skip width attributes on image tags but although it doesn't set width="" on inserted images it does still allow the size to be set in the dialog. Also, if you resize it it creates a new image on the server: I basically don't want any image resizing doing and no variations created. So what I want ideally is these options hiding: I just want it as simple as possible and prefer to handle sizing outside of the editor (the Images field already uses client-size resizing). Is this possible?
  21. Thanks for your help. Because we may end up with a lot of posts I am creating a JSON file in a hook (based on @MoritzLost's example) so there is almost no overhead on the front-end. $wire->addHookAfter('Pages::saved', function(HookEvent $event) { $page = $event->arguments(0); if ($page->template == 'news-item') { $pages = wire('pages')->find('template=news-item'); $years = []; foreach ($pages as $p) { $year = wire('datetime')->date('Y', $p->getUnformatted('newsDate')); if ($year !== null) { $years[$year] = isset($years[$year]) === false ? 1 : $years[$year] + 1; } } file_put_contents('json/news-years.json', json_encode($years, JSON_PRETTY_PRINT)); } }); Thanks. ?
  22. Thanks very much for your example, I'll give it a go tomorrow and let you know. ?
  23. I may have missed it in the docs but is there an easy and performant way to count pages that have a date field by year. So, let's say you have a news-item template with a dateFiled field that is of Datetime type. I would like to return something like this: 2020 => 17, 2019 => 46 ... Where the values are year and count respectively. So basically something like this in MySQL by in PW selectors (ideally without having to use raw database queries): SELECT YEAR(`dateFiled`) as `year`, COUNT(YEAR(`dateFiled`)) AS `count` FROM `news` GROUP BY YEAR(`dateFiled`); Thanks!
×
×
  • Create New...