Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by elabx

  1. 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; } } } });
  2. 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; } } } });
  3. I think MediaManager or FieldtypeDynamicOptions could help you, depending on your needs, check them out!
  4. 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
  5. 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
  6. Have you tried: $page->find('template=event'); Should return all descendants of the current page.
  7. This seems to be related with recent updates, check the last comment here: https://github.com/processwire/processwire-issues/issues/1428
  8. I normally have either Mailgun or Sendgrid help me do this even while on dev. Or there is probably a linux equivalent to something like Mailhog??
  9. 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?
  10. 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.
  11. Haven't tested myself but this topic seems to have quite a bit of info: What seems to be the most helpful is the find() method on the FieldtypeComments class. https://processwire.com/api/ref/fieldtype-comments/find/
  12. Can you try: $form->getChildByName('store')->attr('value');
  13. Same way except I like to put it within the Home page, under a Website Options tab.
  14. Hi @nbcommunication! First of all, thanks for this awesome module! I'm a user of PageimageSrcset too! I was wondering, how do you handle when webp's are larger in size than the original jpegs?? This happens to me far more often than I'd like to and sometimes it's more than double the size of the jpg image 😞 I went ahead and set useUrlOnSize option to true, though the source type attribute then it's kinda wrong although it seems to work just fine! Anyway, just wondering if you had come across a similar issue. Maybe it's worth being able to set the webp options in the render method?
  15. Can you try: $block->getLanguageValue($user->language, 'textarea');
  16. Oh yes of course, sorry! Didn't mean to sound condescending was just trying to elaborate for @cryostar! I got confused into who I was answering.
  17. I remember Snipcart does have recurring payments but not on their latest API 😞 My first idea would be to look into the actual payment gateway provider, in my case my first option is Stripe which I've used their Checkout API and it's pretty straighforward, very well documented and saves a lot of development time by basically letting stripe do a lot of the heavy lifting including the actual subscription management. But I haven't actually done a subscription site! So this is all wishful thinking haha. https://stripe.com/docs/billing/subscriptions/checkout#create-session EDIT: Just realized this is a very old topic πŸ™ƒ
  18. That is the output of a PageArray, try making a find() that finds more than one page, and you''ll see what I mean! It would render something like this: 1107|1200|1201|1021 So, since you only find ONE page, it only outputs that page, but it is still an instance of a PageArray object getting echoed, and the echo outputs like the example. Take a look a this line of the PageArray class: https://github.com/processwire/processwire/blob/master/wire/core/PageArray.php#L701 And I'll venture to say this has to do with this magic method: https://www.php.net/manual/en/language.oop5.magic.php#object.tostring
  19. An alternative would also be findOne:
  20. Just quickly found this, maybe it helps you figure something out? https://docs.vuukle.com/how-to-display-article-comment-count-on-the-home-page-of-your-site/
  21. I'd say you are, basically it's your decision to just use a template that is just used by one page, that render a specific file and that's it. You can even prohibit the template from being used more than once under the template's Family settings.
  22. This works?? $data = $event->arguments(0);
  23. I think I just have never used it before haha, but from what I know of it it does look like it could do the work.
  24. I don't think there is a "best practice" written down somewhere for this sort of scenario. I agree it can be confusing to figure out the "right solution" when there would seem to be so manyw ays to achieve the same. If all the values from the identifier are okay with being a text type value, I would go with a Table field with two columns, a Page Reference that fills its options with the "catalogue" of "possible IDs" and a text field that acts as the field for the actual value, this way you can have whatever fields you want on each organization, and you can do stuff like: $pages_with_purls_identified_orgs = $pages->find('template=organization, ids_table.id_type.name=purls'); This also guarantees you can also add new identifiers in the future very easily and consistently. You could do almost exactly the same with repeaters. Why table and not repeater? I just prefer the interface of the table field, I think it's less clunky visually when few fields are involved and has a more snappy feel. If each identifier would need more data added, I'd go for a repeater, but since it seems it's just an ID name and the actual value, table field seems enough. Repeaters would also have the "overhead" of loading an extra page on memory per repeater, since each repeater item is a processwire page. Although another scneario, what if the value of each identifier is a different type, then the table field would not work as nicely. Say you need DOI to be alphanumeric and ORCids to be integers, maybe for this case a repeater could work, with the same catalogue of identifiers, except that you create two additional fields (one text type, one integer type) and show them conditionally depending on the value of the page reference field where the type of identifier is selected. Please take this idea with a grain of salt, just something I came up with right now. It might be a hassle to manage the relationship of "identifier - type of value" on the actual code, or it might be worth the trouble, or there might be a better solution out there πŸ™‚
  • Create New...