SwimToWin
Members-
Posts
95 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
-
Location
Denmark
Recent Profile Visitors
4,282 profile views
SwimToWin's Achievements
Full Member (4/6)
34
Reputation
-
Hello Community, I've encountered an issue while using the Custom Page Class to import pages into ProcessWire. Currently, the Custom Page Class does not support the new Page() method, as documented in Issue #1864 on GitHub. Consequently, I've ended up with a significant number of test pages that lack a template assignment (specifically, the pages table has a number of entries with templates_id = 0). When attempting to open these template-less pages via the URL /processwire/page/edit/?id=1234, I receive an Error 500. This error message is shown when opening ProcessWire's admin interface: PagesLoader: You must assign a template to the page before setting field values (title__data) [pageClass=ProcessWire\Page, template=] Here are the methods I've attempted to remove these pages: Deletion in ProcessWire editing interface: Cannot empty Trash due to missing template. Direct Deletion Using ProcessWire API: Attempting to delete pages directly through ProcessWire's API, like so: $pw = $pages->find("template.id=0"); foreach($pw as $p) { $p->delete(); } This approach was not successful. Database Query & Deletion: Running a direct query to identify and delete the pages results in a Server Error 500: $ids = $database->query("SELECT * FROM pages WHERE templates_id = 0"); foreach($ids as $id) { $p = $pages->get($id); if($p->id) { $p->delete(); echo "<br>Deleted: " . $p->id; } } Deletion by Specific ID Range: I also tried deleting pages by specifying an ID range, but this did not resolve the issue: $pagesToDelete = $pages->find("id>1188"); foreach($pagesToDelete as $p) { printf('<br>%s (%s)', $p->title(), $p->id); $p->delete(); } I am seeking advice on how to delete or update these pages effectively. Any insights or alternative methods you could provide would be greatly appreciated! Thank you in advance! PS: I suggested a fix that should prevent such scenarios: Gracefully handling errors in ProcessWire Custom Page Classes (Request #515).
-
@zoeck, @wbmnfktr - Works. Thanks! How to protect / hide image files (info for others): Method 1: config.php: Add "$config->pagefileSecure = true;" # Go to the Page template Revoke "view pages" permissions for the "guest (everyone)" role to ensure guests have no permissions. Result: Page is now inaccessible unless you're logged in (as expected) When using a direct link to the image file, the Image file is also protected I had to save the page before linked image files became protected (so there seems to be an issue for image files on existing pages) Image files on new pages are protected right away Method 2: Edit the page directly Set Page status to Unpublished Result: Page is now inaccessible unless you're logged in (as expected) When using a direct link to the image file, the Image file is also protected
- 8 replies
-
- images
- permission denied
-
(and 1 more)
Tagged with:
-
@Jan Romero Steps to reproduce: Create page with image Edit page to get image url. It will look like so: https://www.example.com/site/assets/files/9999/foo.0x260.png Log out (or open a private browser session). Go to the link Result: Image is shown
- 8 replies
-
- images
- permission denied
-
(and 1 more)
Tagged with:
-
@BrendonKoz I'm aware of this possibility that doesn't satisfy the acceptance criteria because the image file is directly accessible (for instance, when a search engine or web spider somehow finds the direct image url). @wbmnfktr Most pages in this website are used for private note-taking and images (think Notion.os, Evernote, etc.). I don't share my private notes.. ?
- 8 replies
-
- images
- permission denied
-
(and 1 more)
Tagged with:
-
How might I hide some/all images in a private Processwire installation used for note-taking? Acceptance criteria * Hidden image file url is never accessible * Hiding images per page is preferred (as opposed to hiding all pages for the site via .htaccess or similar) Suggested solutions (that I currently don't know how to implement): * ProcessWire module controls output of image files * PHP file to control image output ("/img.php?file=img_1234.png")? * .htaccess hinder external access to all image files (will work as a last resort) The Processwire installation in question is being used for personal purposes (think Notion.os, Evernote, etc.).
- 8 replies
-
- images
- permission denied
-
(and 1 more)
Tagged with:
-
Hi @Markus Thomas - Thank you very much for pointing out the opportunity to use url hooks. I can make it work on one page, but it keeps failing on the product page and I cannot tell why; I'm using PW v3.0.200. Anyways - using urlSegments() works: #workaround #uglyButWorks #inspiration Code // Match url - example: https://www.example.com/myproduct/r/foo1234 if( in_array($page->template, ['product','redirect']) && $input->urlSegment1()=='r' && $input->urlSegment2() ) { $p = $pages->findOne("template=redirect, title=" . $input->urlSegment2() ); if( $p->link ) { // Page exists according to "page that uses a redirect template" -> redirect to specified destination page. // Support absolute and relative links $p->link = str_replace(['https://www.example.com/','http://www.example.com/','//www.example.com/','www.example.com'], '', $p->link); $p->link = ltrim($p->link,'/'); $url = "//{$config->httpHost}/$p->link"; } else { // Fallback: Page doesn't exist, so redirect to product page $url = "//{$config->httpHost}/{$page->url}"; } printf("<p>Redirecting to <a href='%s'>%s</a></p>", $url, $url); $session->redirect($url); } Setup Redirect template with Title and Link text fields.
-
Good idea, @Markus Thomas. Unfortunately these url hooks don't work in my use case because the redirect happens "below existing pages", as explained here: $wire->addHook('/existing-page/r', function($event) { return "Hello R"; // Not shown (contents from the "nearest parent page" is shown) }); $wire->addHook('/non-existing page/r', function($event) { return "Hello"; // Works });
-
Hi, I want to redirect users that hit 1) pages using a specified template 2) when the url is using a specific syntax. Url syntax is: /PRODUCT/redir/PAGEID Example: /foo/redir/1234 My intention is to redirect the user to the specified PAGEID - but I don't know how to user $input in a hook. How might that be done with hooks in ready.php? $this->addHookBefore('Session::redirect', function(HookEvent $event) { $session = $event->object; // (Product template always lives a root level) if( TEMPLATE == 'product' && INPUT->urlSegment1()=='r' ) { $dest = $pages->get(PAGEID); $session->redirect( $dest->url ); } });
-
When working with Checkboxes ("Type: Page Reference - Input field type: Checkboxes - with Page field value type: Multiple pages PageArray" fields, that is), this works: $rs = $pages->find('template=foo, parent=/bar/'); foreach ($rs as $p) { $p->of(false); $p->myCheckboxes = null; // Unset all values first $p->myCheckboxes = 'baz'; // Then set the active checkbox with name (or, use Page ID) $p->save(); }
-
Small request: When working with files outside ProcessWire, it would be useful to know the the public / web folder. Having this folder or directory will allow me to work with the "non-Processwire file system". Example: /var/sites/www.example.com/public/ <- (or whatever your hosting provider calls the public directory for a website) I can get the directory with $_SERVER['DOCUMENT_ROOT'] - unfortunately, the $_SERVER variable is easily manipulated and therefore unsafe (needs to be escaped and such). sprintf('%s/%s/', $_SERVER['DOCUMENT_ROOT'], 'whatever'); Currently print_r($config->paths) outputs two array keys that hold (too deep) info about the public web directory: [sessions] => /var/sites/www.example.com/public/site/assets/sessions/ [classes] => /var/sites/www.example.com/public/site/classes/
-
Works. Thank you, Zeka.
-
I'm importing data from an external system into ProcessWire. Each of the imported records have a unique ID. How might I use the unique ID to prevent duplicate records in ProcessWire? What I want: When importing data find the foreign record ID use it to check for duplicates if a duplicate record is detected, skip it import data into ProcessWire by creating a page in /import/ continue to next record ProcessWire: Later I'll move each page to another location ... meaning that '/import/' will be empty the next time, I run an import job Looking into possible solutions: Unfortunately, ProcessWire Unique Text Fieldtype doesn't do the trick. (ProcessWire Unique Text Fieldtype will allow the page to be created - only the field with a duplicated field value will be blank. In my case, the duplicate record needs to be blocked / *not* created.) Could it be solved by modifying the code for ProcessWire Unique Text Fieldtype?
-
How to check if each page reference checkbox is checked?
SwimToWin replied to SwimToWin's topic in General Support
Solution: has('name') does the job, that's also self-explanatory .. compared to using IDs, as I did in my tests above. var_dump( $page->config->has('foo') ); // bool(true)- 3 replies
-
- 1
-
- checkboxes
- page reference
-
(and 2 more)
Tagged with:
-
How to check if each page reference checkbox is checked?
SwimToWin replied to SwimToWin's topic in General Support
Thanks Andreas @AndZyk - both for solution and find() explanation; never used find() much- 3 replies
-
- checkboxes
- page reference
-
(and 2 more)
Tagged with: