-
Posts
680 -
Joined
-
Last visited
-
Days Won
18
Everything posted by Jan Romero
-
What do you want to happen with the original tab? A redirect is a specific type of HTTP response that directs the browser to go somewhere else. If you want to show a response in the original tab and additionally open a new tab immediately, you can try adding some javascript to the original response, such as window.open('https://example.com', '_blank'), but generally browsers/users don’t like this very much and their popup blockers will prevent it by default. And why not handle the problem earlier, when you show the link to the user? if ($page->external_url) { echo "<a href='{$page->external_url}' target='_blank'>{$page->external_url}</a>"; } This likely won’t be blocked because it’s a direct result of a user interaction.
-
Here’s another edge case: 0 results. So really you gotta do this, if you presume an empty pagination page to exist: (int)ceil(($this->getTotal() ?: 1) / $this->getLimit());
-
Admittedly I’ve been meaning to read this whole thread for days and the quoted passage is about all I got so far, but there is a first party option here: https://processwire.com/store/login-register-pro/
-
upgrade Blank Page after upgrade from Version 3.0.62
Jan Romero replied to BIMAQ-Admin's topic in General Support
I dunno, what does the blank response look like raw? Is it a 200? Another long shot would be clearing the browser cache etc. Sorry you have to deal with this. PW’s easy upgrade process is one of the things I love most about it, lol. -
upgrade Blank Page after upgrade from Version 3.0.62
Jan Romero replied to BIMAQ-Admin's topic in General Support
Did you compare the old and new .htaccess? Maybe you have some config in there that you need to carry over to the new file. -
May I just say… this won’t work: <?php $lastPageNum = ceil($posts->getTotal() / $limit); ?> <a href="<?=page()->url($lastPageNum)?>">Go to the last page</a> Because ceil() always returns a float. This also means you may get subtle bugs when using === to compare it. Personally I detest having to divide and ceil() and cast to int myself, so my proposal is to add this functionality to the core. It would be something like this: public function getTotalPages() { return (int)ceil($this->getTotal() / $this->getLimit()); } Or should it be called getLastPageNum()? Might make a PR later…
-
https://www.youtube.com/@TheSegi86
-
To be clear, are you a developer of the site in question or are you asking more from an editor’s perspective? ProcessWire is quite flexible, so in many parts one would have to be familiar with the specific setup (field and template structure, installed modules) to assist with the user experience. I think you’re asking about a different site, that works differently from the one from the screenshots?
-
I see, sorry, you’ll probably get it when you’ve been here a while longer ?
-
Hi, welcome. Unfortunately I don’t think I really understand your problem, but for more information about coloring RepeaterMatrix items, you may see this thread by Ryan: Also please don’t post short links like that. It looks particularly fishy as a new user. You can attach images to your post directly by just copy-pasting, dragging-and-dropping or clicking “choose files” below the text editor.
-
I think you need to click on the image to edit custom fields. Or switch to the detail view: Also, does your caption field use a rich-text editor? Back when custom image fields were introduced, CKEditor was not supported, although much has changed since then. https://processwire.com/blog/posts/pw-3.0.142/#considerations-in-the-page-editor
-
[SOLVED] How to hook into page ADD NEW and change sort order?
Jan Romero replied to Klenkes's topic in General Support
To render the screen you showed, this happens: ProcessPageAdd::execute() is called. This is hookable, so you could mangle its markup output, but it’s going to be disgusting. Because neither parent nor template were given, execute() now calls renderChooseTemplate() and immediately returns its result. renderChooseTemplate() is not hookable. Within renderChooseTemplate(), ProcessPageAdd::executeNavJSON() is called. This is hookable, but it’s not going to be very useful. executeNavJSON() – surprise – doesn’t return json but an associative PHP array containing, among other things, the templates you’re allowed to add. It will sort these alphabetically by name using ksort(). Back in renderChooseTemplate(), the allowed parents for each of these templates are now queried using this selector: $pages->find("template=$parentTemplates, include=unpublished, limit=100, sort=-modified") So now you know why Nadelholzbalken is #1: it was most recently modified. Also it’s hardcoded to only show 100 pages. Both are not easily changed. So yeah, you’re basically stuck with post-processing the output of ProcessPageAdd::execute() and being limited to the 100 most recently modified pages. Alternatively you could build the list yourself. It’s only a bunch of links to ./?template_id=123&parent_id=4567 after all. Something like this: $this->addHookBefore("ProcessPageAdd::execute", function(HookEvent $event) { $process = $event->object; if (input()->get('template_id') || input()->post('template_id')) return; if (input()->get('parent_id') || input()->post('parent_id')) return; //we weren’t given a parent or a template, so we build our own list $event->replace = true; $templates = $process->executeNavJSON(array('getArray' => true))['list']; $out = ''; foreach($templates as $tpl_data) { if(empty($tpl_data['template_id'])) continue; $template = templates()->get($tpl_data['template_id']); if (!$template) continue; $out .= "<h3><a href='./?template_id={$template->id}'>{$template->name}</a></h3>"; $parentTemplates = implode('|', $template->parentTemplates); if(empty($parentTemplates)) continue; $parents = pages()->find("template=$parentTemplates, include=unpublished, sort=title"); $out .= '<ul>'; foreach($parents as $p) $out .= "<li><a href='./?template_id={$template->id}&parent_id={$p->id}'>{$p->title}</a></li>"; $out .= '</ul>'; } $event->return = $out; }); Obviously this looks like ass, but functionally that’s the gist of it. -
It’s not that stupid, really, and may be the way to go if you’re serving an API or something like that. If you’re doing standard form- and navigation-based stuff, you should return a redirect (HTTP 303), which does essentially the same thing with extra steps to prevent double posting (the Post-Redirect-Get pattern, PRG). The technical reason why created and modified aren’t populated is that these timestamps are generated in the database. So to get their actual real values you have to query the database for them anyway. That’s overhead you may want to avoid by default. Obviously ProcessWire could just set created and modified to the current time without going to the DB, but those values may differ from the ones in the DB (because processing is slow or because the DB server has a different time altogether). So doing that would be kind of naughty, although it probably shouldn’t matter 99.999% of the time. Here’s a quick pull-request that would “fix“ the issue as described above: https://github.com/processwire/processwire/pull/292 Another way to fix it would be to set the properties yourself prior to saving. I realize this thread is 8 years old and you haven’t been here since 2022, but I like your COMI avatar ?
- 1 reply
-
- 1
-
Mind blown. I wish I had known this years ago ?
-
Yikes! - URL Segment Bypasses Template Access Control
Jan Romero replied to Jim Bailie's topic in General Support
Hi, I tried to reproduce this without success (3.0.208 dev). Can you share more about your setup? -
Looking good, however I can’t access it from Germany (connection times out) :O
-
I tried to replicate this problem and it turns out there are some characters you can add to $config->pageNameWhitelist and .htaccess all you want, this blacklist in the core won’t have it: https://github.com/processwire/processwire/blob/master/wire/core/Sanitizer.php#L911 Dollar signs are FORBIDDEN!!!! However, don’t despair yet, you’re never more than a finite amount of disgusting hacks away from success: wire()->addHookBefore('ProcessPageView::pageNotFound', function(HookEvent $event) { if (stripos($_SERVER['REQUEST_URI'], '/concepts/') === 0) { //serve file } }); This needs to go into init.php and runs whenever PW would otherwise 404, that is, it can’t find a page or url segments or url hooks for the requested path. Some things will not work as expected in this hook. For example input() will not be populated. To make the $ work you’ll need to update your .htaccess, though. For example you can just add the $ to the default rewrite condition: # PW-PAGENAME # ----------------------------------------------------------------------------------------------- # 16A. Ensure that the URL follows the name-format specification required by PW # See also directive 16b below, you should choose and use either 16a or 16b. # ----------------------------------------------------------------------------------------------- RewriteCond %{REQUEST_URI} "^/~?[-_.a-zA-Z0-9/\$]*$" # ----------------------------------------------------------------------------------------------- # 16B. Alternative name-format specification for UTF8 page name support. (O) # If used, comment out section 16a above and uncomment the directive below. If you have updated # your $config->pageNameWhitelist make the characters below consistent with that. # ----------------------------------------------------------------------------------------------- # RewriteCond %{REQUEST_URI} "^/~?[-_./a-zA-Z0-9æåäßöüđжхцчшщюяàáâèéëêěìíïîõòóôøùúûůñçčćďĺľńňŕřšťýžабвгдеёзийклмнопрстуфыэęąśłżź]*$" Or use the other one below and add it there. Or do whatever is applicable for nginx? Not ideal but still better than messing with the core, I guess.
-
Pro Fields Table: HTML being removed from text field
Jan Romero replied to DrQuincy's topic in General Support
If you want to modify the Module you could replace the original switch case in FieldtypeTable.module with this: case 'text': $maxLength = empty($col['settings']['maxLength']) ? 2048 : (int) $col['settings']['maxLength']; $stripTags = empty($col['settings']['stripTags']) ? true : ($col['settings']['stripTags'] === 'false' ? false : true); $v = strlen("$v") ? $sanitizer->text($v, array('maxLength' => $maxLength, 'stripTags' => $stripTags)) : null; break; That will allow you to specify stripTags=false on text colums. -
Pro Fields Table: HTML being removed from text field
Jan Romero replied to DrQuincy's topic in General Support
Unfortunately I believe this is hardcoded behaviour (see _sanitizeValue() in FieldtypeTable.module). As you noticed, it doesn’t strip tags from textareas, so maybe switch to that? It should be quick work to add this as a per-column option like maxLength. Perhaps worth suggesting it to Ryan in the ProFields forum? -
Creating a new page from a class file fails
Jan Romero replied to Inxentas's topic in General Support
Btw, it should be possible to create a new page with a string template name using $this->pages->newPage() https://processwire.com/api/ref/pages/new-page/ -
[SOLVED] How to prevent users from uploading 300 dpi images?
Jan Romero replied to howdytom's topic in API & Templates
You can change the dpi in Document -> Resize Document by unchecking “Resample”, i.e. you’re just changing how big the image should appear on physical media but not its pixel dimensions: For example here’s a 300px by 300px picture of a salad. Both images are exactly the same, but if you import them into a DTP software like Affinity Publisher, InDesign or Scribus, by default one will be 8cm (96 dpi) and one will be 2.5cm (300 dpi). That is to say you’re correct and dpi don’t matter in terms of file size or pixel resolution on the web. -
Yes, that is the way. What are the contents of your DefaultPage.php file? https://processwire.com/blog/posts/pw-3.0.152/#new-ability-to-specify-custom-page-classes If you just want to add a method or property you can also use hooks for that: https://processwire.com/docs/modules/hooks/#how-can-i-add-a-new-method-via-a-hook