Jump to content

Jan Romero

Members
  • Posts

    695
  • Joined

  • Last visited

  • Days Won

    21

Everything posted by Jan Romero

  1. 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
  2. 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.
  3. 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 ?
  4. Mind blown. I wish I had known this years ago ?
  5. Hi, I tried to reproduce this without success (3.0.208 dev). Can you share more about your setup?
  6. This helped me give in to my nagging coworkers and sign up for ChatGPT, but I can’t seem to get it to answer this question properly? May I ask what your prompt was, @Jonathan Lahijani? Also, what’s causing problems with calling ready() explicitly?
  7. Looking good, however I can’t access it from Germany (connection times out) :O
  8. It’s handled, but I wasn’t able to send a 200 status unless allowing the $ in .htaccess. I don’t know what’s going on there, I imagine it’s overridden by Apache after PW is done. Other status codes worked for me, though. Only 200 always turned into 404.
  9. 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.
  10. 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.
  11. 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?
  12. 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/
  13. 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.
  14. 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
  15. @gnarly Thanks, I added it to the post ? Welcome to the forums!
  16. I suspect this shouldn’t be too hard to implement naively, but it’s probably non-trivial to get all the configurable bells and whistles to work that image fields support (like client side resizing for example). I think you can grab images from the clipboard as blobs by listening to the paste event and filtering by type pretty easily. You’d have to figure out which image field to use, since a page could have multiple, and how to interface with it. I agree CTRL+Ving images is delightful and a desirable feature to have! Personally I don’t like WYSIWYG editors, so a cool feature would be the ability to paste pics into a Markdown textarea and have it upload it and generate the code automatically, like we see on Github.
  17. ProcessWire is particular about the difference between saving pages and saving individual fields. In this case, only Pages::save and Pages::delete trigger the hook: https://github.com/processwire/processwire/blob/master/wire/modules/PageRender.module#L74. I agree this difference is pretty underdocumented. You can probably hook up your desired behaviour somewhat like this in ready.php: $this->addHookAfter("Pages::saveField", function(HookEvent $event) { modules()->get('PageRender')->clearCacheFile($event); }); I haven’t tested it but the relevant hook arguments should be the same, i. e. the Page is argument 0, so it might work? There is also Pages::savedPageOrField for when you want to make your own hooks trigger regardless of how the page was modified.
  18. Try checking them since they DISable appended files. Also check your config file for “appendTemplateFile”: https://processwire.com/api/ref/config/#pwapi-methods-template-files
  19. Does this not work equivalently for file fields?
  20. date - Documentation - Twig - The flexible, fast, and secure PHP template engine Says here you can change Twig’s default date format like this: $twig = new \Twig\Environment($loader); $twig->getExtension(\Twig\Extension\CoreExtension::class)->setDateFormat('d/m/Y', '%d giorni'); And format individual expressions like this: {{ page.created|date("d/m/Y") }} But to get Italian words like ”giugno“ or “venerdi” you’ll probably need something called “Twig Intl Extension”: https://stackoverflow.com/a/75572704
  21. This is how I do it: http_response_code(200); But 200 is the default anyway. It should always be sent unless you change it or an exception happens. I think @Denis Schultz may be on to something with the Content-Type header?
  22. Robin’s suggestion of using a custom page class should work for that, just override get(): <?php namespace ProcessWire; class DefaultPage extends Page { private $cache = [ 'title' => 'look at me. i’m the title now.' ]; public function get($key) { return $this->cache[$key] ?? parent::get($key); } } IRL you may want to add logic dealing with output formatting and what not, but that should be a complete working example. Unfortunately get() is not hookable, so I don’t believe this can be accomplished in a module. That said, have you investigated other avenues? Why not cache the whole markup and be done with it?
  23. Maybe you can hook Fieldtype::loadPageField()? https://github.com/processwire/processwire/blob/6ff498f503db118d5b6c190b35bd937b38b80a77/wire/core/Fieldtype.php#L1108
  24. There is a setting for url fields to allow or disallow quotation marks. I’m pretty sure it defaults to disallowing them. Have you checked that?
×
×
  • Create New...