-
Posts
1,303 -
Joined
-
Last visited
-
Days Won
16
Everything posted by elabx
-
This does seem like an issue with htaccess not kicking in or mod_rewrite, does writing gibberish on the access throw an error? Cheap trick to see if it works ha! ?
-
How to save value to every pages specific field?
elabx replied to Flashmaster82's topic in General Support
Hi!! Try this: $found = $pages->find('template=customer_project'); forach($found as $p){ $p->setAndSave('location',"Hello world" ); } EDIT: Just reading again that you have this in ready.php so this will run on every page load, for every page with custom_project template, not very efficient lol. Like you mention, perhaps a hook after certain action would be better? -
Very elucidating!! I'm learning this myself and it's great to confirm/correct some of the assumptions I had. Thanks a bunch for this @MarkE!
-
If I'm understanding the problem right, maybe the PagesNames class could be useful in this scenario?? https://processwire.com/api/ref/pages-names/unique-page-name/
-
Mine's still open and bleed once in a while with support emails lol so that's why I've decided to tackle this once and for all. I have a vague memory of this but don't clearly remember why momentjs was introduced. I'll just start without it? x10000000 I understand the issue well here. My guess if that it should work just as a FieldtypeMulti? If anything I appreciate your time to answer my questions! I am a bit nervous cause I know it's no easy feat, but excited to try to bring this to a more stable status. I will try to reuse most of the UI design wise at least to start with something, I think that part could be salvaged and is already a great deal of work? I'm sure it might have some areas improvement but I have used it successfully with a lot of people (when it works :D) that's why I feel it's really worth saving.
-
Great idea! I always wondered how the meta() feature could useful haha.
-
Hi! I am trying to build a new version (open source) of the recurring dates module released a few years ago. And I've found myself with a couple doubts. I am building it as a single value Fieldtype module where I want to save the rrule string (to render the UI) but I want to save the actual occurrences of the rule in a second table, so I can use mysql to query the actual dates. Does this make sense? Is there another field around that uses a secondary table to save data? If this is sensible, where should I do it?? sleepValue()? savePageField()? @adrian I think I saw you suffering with the bugs a lot around the support thread haha, so any input on how you would approach the development/refactors of this would be appreciated. Right now on the "big picture" I want to use Alpine.js to redo de Inputfield and looking for advice here on how to do the actual Fieldtype. Also it's the plan to completely rely on rlavin/php-rrule . And this module will only involve the fieldtype/inputfield not the whole rendering modules that came along the original one.
-
Grabbing images from a URL - without having a page
elabx replied to chrizz's topic in API & Templates
You can use the ImageSizer class, rough example assuming you already have saved the image on disk: $fullpath = "/var/www/images/someimage.jpg"; $options = array('upscaling' => false, 'quality' => 100, 'sharpening' => 'soft'); $imageSizer = new ImageSizer($fullPath, $options); $success = $imageSizer->resize(100, 200); -
Get repeater field subfield value by other subfield value
elabx replied to hellomoto's topic in API & Templates
What type of field is misc_site_meta?? Most get methods will return a "non iterable" object so first() is unlikely to work. Ok it's a repeater, you specifically say so in the title lol my pardon! Try: $homepage->misc_site_meta->get('title=year'); This will get you the first repeater item in the misc_site_meta field where title field equals "year". -
Copying architecture(database+templates) from one PW project to another
elabx replied to Ksenia's topic in General Support
Hi! ProcessWire stores all its data in a MySQL database. You don't seem to mention that in your post so I'll give a wild guess that it's a part that might be missing. Is the copy of the project running locally or on a server? -
Get Text Tags array from the text field to create checkbox filter
elabx replied to Ksenia's topic in General Support
This might be what you're looking for: https://processwire.com/api/ref/inputfield-text-tags/tags-array/ Corrected, this is the link: https://processwire.com/api/ref/inputfield-text-tags/get-tags-list/ You can also get the inputfield from the field like this: https://processwire.com/api/ref/field/get-inputfield/ Something like this might work, haven't tested: $inputfield = $page->getInputfield('tags_field'); $list = $inputfield->getTagsList(true); foreach($list as $item){ // echo checkboxes ? } -
Help me stop using shared hosting - what's your VPS/docker setup?
elabx replied to joe_g's topic in General Support
I think something like ploi.io or runcloud could work for you. I personally use Runcloud but they appear to be moving slower than ploi "feature wise" although it has worked perfectly for all the sites I manage and their support is fair for the paid price. Both this services clear your goals from 0 to 4 in one way or another. I also think both has some sort of deployment tool integrated with any git repo (which I don't personally use but i think it's there). One "downside" is that ploi doesn't have Apache server configuration they went full nginx though I know there's some crew around here running PW with no issues on nginx. Aside from that, they do seem superior feature-wise. For example, there you can have db only servers, load balancers. The worse part of Runcloud in my opinion is it's per-site backup service which is a service provided by them, Ploi lets you use your own storage (s3 for example). One thing both services have is cloning one "app" into another one, or another server, at least I can confirm this on Runcloud, but seems to exist in ploi too and it's super handful. Another way I do this is through CI services (like Github Actions) and basically doing some shell scripting which is not too bad for all the time saved. In the Github Actions I basically rsync template files/modules and run the migrations module through it's CLI but I rarely push actual content since it's managed by a third party. While on development, I do still use plain old cli mysql import, scp the things or run ngrok to save the hassle of doing previous steps if I just want to quickly demo sth, but tbh it's just lazy on my part I bet it can be easily automated. EDIT: Another trick I do some other times is ssh tunnel a db connection to the actual server. Which is something that moving away from shared hosting makes really simple ? I am also trying to find the time to explore deployment using docker but well, just a plan for when I have some spare time. Check this thread too for other opininons/services: -
Another really useful tool is RockMigrations.
-
@Ivan Gretsky I had thought of doing this too! How's it working??
-
Ended up as sth like this: $wire->addHookAfter('Pages::saved', function($event) { $page = $event->arguments(0); if($page->template->name != "collection") return; try{ $iterator = new \DirectoryIterator("{$this->config->paths->root}assets/{$page->order_id}"); } catch(\Exception $e){ $this->warning("Directory with resources not ready"); return; } foreach ($iterator as $fileinfo){ if ($fileinfo->isFile()) { $path = $fileinfo->getPathname(); $file_name = $this->sanitizer->filename($fileinfo->getFilename()); switch($fileinfo->getExtension()){ case "mp4": $found = false; foreach($page->videos as $video){ $filename = $video->video_file->cleanBasename($file_name, false, false, true); if($filename == $video->video_file){ $found = true; } } if(!$found){ $newVideo = $page->videos->getNew(); $newVideo->save(); $newVideo->video_file->add($path); $newVideo->save('video_file'); $page->videos->add($newVideo); $page->save('videos'); } break; case "jpg": $file_name = $page->images->cleanBasename($file_name, false, false, true); if(!$page->images->findOne("name=$file_name")) { $page->images->add($path); $page->save('images'); } break; } } } });
-
I'm trying to add some files uploaded through FTP to a files field within a page. File is uploaded to /assets/{order_id} through FTP ProcessWire page has the order_id saved in a field to figure out the path later, and when the page is saved, trigggers the hook, it goes to the required folder and tries to pick the files to save them in the processwire image field (named 'images') or a repeater containing a file field to save videos. (repeater named 'videos', with a field withing it called 'video_file'). The main issue I'm having is that I don't want to copy the files twice if they already exist but for some reason the findOne() method on repeaters to find already upload files is returning false as if the file didn't exist ? PW version 3.0.184 EDIT: The save filename saved is obviously not the same since it's been sanitized lol ? $wire->addHookAfter('Pages::saved', function($event) { $page = $event->arguments(0); if($page->template->name != "template_name") return; $iterator = new \DirectoryIterator("{$this->config->paths->root}assets/{$page->order_id}"); foreach ($iterator as $fileinfo){ if ($fileinfo->isFile()) { $path = $fileinfo->getPathname(); $file_name = $this->sanitizer->selectorValue($fileinfo->getFilename()); switch($fileinfo->getExtension()){ case "mp4": //video_file is a field within the repeaters $selector = "video_file={$file_name}"; // 'videos' is a repeater field $found = $page->videos->findOne($selector); // This one is returning false all the time :( if(!$found){ $newVideo = $page->videos->getNew(); $newVideo->save(); $newVideo->video_file->add($path); $newVideo->save('video_file'); $page->videos->add($newVideo); $page->save('videos'); }else{ bd("Found already added!"); } break; case "jpg": // This one is returning false all the time :( if(!$page->images->findOne("name=$file_name")) { $page->images->add($path); $page->save('images'); } break; } } } });
-
I think MediaManager or FieldtypeDynamicOptions could help you, depending on your needs, check them out!
-
Hi! Does anyone know if there is a hook to filter out custom fields of image/file fields under certain conditions? For example, if the 'images' field is on certain template, I want to exclude the rendering of a 'url_address' field that would normally show within the custom fields. I would have hoped somewhere like here would have been enable for hooks. EDIT: As always, some writing makes the brain work, going to try the already famous hook before the InputfieldWrapper::render method lol
-
find() in the end uses has_parent, so I don't think there's much difference. https://github.com/processwire/processwire/blob/master/wire/core/Page.php#L2222
-
Have you tried: $page->find('template=event'); Should return all descendants of the current page.
-
You are right, I got a bit confused with the documentation page, the response doesn't have info about the header. Did you try get_headers?
-
Have you tried PHP's get_headers? What's wrong with the way you are doing it now? I understand from your replies that it is actually working? Also, the request's JSON seems to have a topic field that you can check too, in case you want to skip the header check.