Jump to content


  • Posts

  • Joined

Everything posted by LMD

  1. I can't test this right now, but it might be simpler to put your functions in a separate file (e.g '_funcs.php') and then in '_init.php' use: // in _init.php require_once '_funcs.php'; By using 'require_once', it shouldn't matter how many times '_init.php' gets called, the '_funcs.php' file will only be included once.
  2. You can configure VS Code to understand "*.module" files as PHP. Go to "Settings" and then "Text Editor > Files". Under "Associations" press "Add" button and add "*.module" (without the quotes) under Item/key and "php" under Value. Hit "Ok". Might need to restart VS Code for it to take effect. Also, you need a double-asterisk at the front of the comment to get the code hints (and also make sure the variable name is correct/matches!): /** @var TextformatterMarkdownExtra $md_formatter */ $md_formatter = $modules->get("TextformatterMarkdownExtra");
  3. You forgot to call the fieldname 'button' - you are echoing the repeater items (which uses the ID as toString output). Try this: <div class="caption-cta-wrapper uk-margin-medium-top"> <?php // 'buttons' is a repeater field, so '$btn' is a repeater item foreach($page->hero->buttons as $btn) { echo $btn->button; // <-- fieldname! } ?> </div>
  4. Hi @fruid At the moment it looks like you are grabbing all pages (with parent id = 1) and iterating through them individually to find the ones matching the required menu. With a small number of pages this may well be perfectly fine, but if there are hundreds/thousands of pages it's not very efficient. It would be better to just grab only the pages in the required menu - unfortunately you can't (currently?) do that with a PW selector, but you can use a MySQL query directly combined with a PW find selector -- check out the following thread:
  5. In this case, you really need to ensure the user has the correct country code, otherwise there is a scenario where they could login to somebody else's account by accident! How about pre-filling the field, but not making it invisible, so the user can see and check it is correct? Maybe with a little country flag icon?
  6. I'm on a mobile, so can't test this but you could try the following... Create a dummy SVG file with a placeholder icon and module name all aligned and styled properly. Give the placeholder icon and text span containing the changable module name unique IDs. I assume the real icons are also SVG (e.g. FontAwesome) and not an image? On page save (with PHP, I assume), open the dummy SVG and regex search-replace the icon (open the icon code too if necessary) and module name. Save new code as a new SVG file. That would be my stating point.
  7. Is the number part of the username unique to each user? If so, why complicate things with the region part at all? Especially if you only want the user to enter the number. I fear that by asking too much of the user (making sure their region matches), it will just lead to more tech support enquiries.
  8. This page in the docs helps, but basically inside a module you can use: $this->page; $this->wire('page'); // preferred in Wire-derived classes (i.e. modules) However, for the example you gave above (renderPageTitle()), it might be easier to create a new method for the $page class with a hook. For example: /** * NOTE: the module will need to be set to be 'autoload' => true in the Module Info */ class MyModule extends WireData implements Module, ConfigurableModule { /** * Run when PW is "ready" (like ready.php file) - so it's where you place you ready hooks. */ public function ready() { // Add a hook to define the "renderPageTitle" for the $page class. // Called in your templates with with $page->renderPageTitle() $this->addHook('Page::renderPageTitle', $this, 'renderPageTitleHook'); } /** * The hook code itself (could have been an enclosure on the hook if simple enough) */ public function renderPageTitleHook(HookEvent $event) { $page = $event->object; // the $page class *instance* calling the method $event->return = $page->title; } } Alternatively, this is a good case for using Custom Page Classes (look at the most recent 'site-blank' profile for an example).
  9. In the regular site profile you can find the function that controls this output in the file called '_uikit.php' in the templates folder. Find the function 'ukBlogPost()' and go to the line defining the variable '$date' (see here on Github) to change it. Currently it is looking for the date (modified) and falling back to the created date string 'date|createdStr' -- just remove the 'date|' bit and leave 'createdStr'. Be sure to check the other functions in that file for other places the date may be displayed.
  10. Ahh, yes, I was not taking into account 'Pages' vs 'Page' objects. Which is silly of me, because the clue is right there in the "$page = $event->arguments(0)" bit of the hook method! Thank you!
  11. I'm trying to use a conditional "saveReady" hook for repeater items inside a module, but for some reason it isn't firing (and yes, I am making sure to make changes to the repeater when testing!). It works when NOT using a conditional hook (and checking for the template inside the hook function itself), so it's not an issue with anything except the conditional part of the hook. // THIS WORKS public function ready() { $this->addHookAfter('Pages::saveReady', $this, 'myHook'); } public function myHook(HookEvent $event) { $page = $event->arguments(0); if ($page->template->name === 'repeater_gallery') { bd($page); // Tracy dump } } // THIS DOES NOT WORK! public function ready() { $this->addHookAfter('Pages(template=repeater_gallery)::saveReady', $this, 'myHook'); } public function myHook(HookEvent $event) { $page = $event->arguments(0); bd($page); // Tracy dump -- does not get dumped. Is the hook not fired? } I'm using the latest DEV version of ProcessWire (v3.0.222). Is this a bug, or is it me?
  12. Ahh, yes.... I've only been putting it on the local parent element where required, because the <body> is controlled by a different template. But if your entire site is HTMX powered that is absolutely the way to go.
  13. I'm developing a site using HTMX to swap images in a gallery (it uses 'picture' element and 'srcset' so I didn't want to load all the markup at once) alongside PW regions and it works great. I haven't really encountered any problems or gymnastics -- but maybe my use-case is simple enough? <?php namespace ProcessWire; $imgMarkup = ''; $thumbMarkup = ''; $imgNum = 0; /** Build the gallery fragment (the bit that changes via HTMX) before output */ if ($page->gallery && $page->gallery->count() > 0) { $imgNum = $input->get('img', 'int', 0); // get image index number from GET var (AJAX and no-JS) $galleryImg = $page->gallery->eq($imgNum); // get the image from index // The image markup (actually rendered from a custom page class) $imgMarkup = '<picture> <source type="image/webp" srcset="..."> <img src="..." width=".." height="..." alt="..." srcset="..." sizes="..."> </picture>'; // If it is a ajax (HTMX) request, just echo the image markup and stop PW processing tyhe rest of the template. if ($config->ajax) { echo $imgMarkup; return $this->halt(); } /* When doing HTMX ajax swap, the rest of this template won't be rendered */ // Build the clickable thumbnails that do the swapping (simplified) foreach ($page->gallery as $item) { $thumbMarkup .= '<li><a href="..." hx-get="..."><img src="..." width="..." height="..." alt="..."></a></li>'; } } ?> <!-- The markup regions --> <pw-region pw-id="imageViewer"> <div class="image-wrapper"> <figure class="image-main-wrapper" id="mainImg"> <?=$imgMarkup?> </figure> <div class="image-thumbs-wrapper"> <!-- where the HTMX magic happens -- note the additional hx-headers, which allows PW's $config->ajax to work --> <ul class="image-thumbs" hx-trigger="click" hx-target="#mainImg" hx-swap="innerHTML" hx-headers='{"X-Requested-With": "XMLHttpRequest"}' > <?=$thumbMarkup?> </ul> </div> </div> </pw-region> <pw-region pw-id="pageContent" class="content-left">....</pw-region> <pw-region id="sidebarContent">...</pw-region> It just works... no need to faff with cancelling prepend/append templates etc, just rember to add the extra hx-header (also, you can do it once on a parent element), you don't need to add it to every call. I haven't ever tried, so I'm not 100%, but there might be a way to automatically add the header to every HTMX call with a bit of javascript in the header/footer. I feel all the tools are probably already there, but if there is an even easier way, though, that would be great.
  14. Not a problem, this time, but an FYI and a solution in case anybody needs it. When using a Dynamic Options field as an images/files custom field, the 'page' value of 'arguments(0)' is not the page being edited, but instead it's a dummy page used for the 'field-fieldname' template. If the actual page is required for some logic (a need I had), then this poses an issue... but there is a solution! In your 'getSelectableOptions' hook, do the following: $wire->addHookAfter('FieldtypeDynamicOptions::getSelectableOptions', function(HookEvent $event) { $page = $event->arguments(0); // Page data (which will be wrong for our specific use case) $field = $event->arguments(1); // Field data // 'foo' is an images custom field if ($field->name === 'foo') { /* Get the page -- where we get page from will be different in the admin (edit) and frontend.*/ $page = $this->page; // the current page route (sufficient for the frontend) /* However, in the admin edit page (check the process) */ if ($page->process === 'ProcessPageEdit') { // Get the id of page being edited from $input and then use that to fetch the page $page = $this->pages->get($this->input->get('id', 'int')); } $options = []; // empty array to return if no valid page is found // If it is a valid id... continue as usual, using the $page var if ($page->id) { if ($page->template->name === 'gallery') { $options = ['foo' => "Foo", 'bar' => "Bar"]; } else { $options = ['lorem' => "Lorem", 'ipsum' => "Ipsum"]; } } $event->return = $options; } // ... other fields as required can use the $page from args }); No idea if there is a different way, but this method is fairly simple, besides, it's not going to be a common issue. Hope this helps somebody. Here's the Tracy dump of the custom field "page" for the curious: ProcessWire\DefaultPage id: 0 name: '' parent: '' status: 'corrupted' template: 'field-images' caption: '' foo: => '' data: array 'caption' => '' 'foo' => ''
  15. When generating a WebP image from the originally uploaded file (not as a result of using the 'size()' method), I see the following file error in the logs: unlink: Given filename is not a file or link: /site/assets/cache/WireTempDir/.PFM0.24368300T1680350648RozEvGgLCG8JdZGUwLM/0/cookies.960x0.png-tmp.png Note that the actual original filename is 'cookies.png' -- but the error message appears to show PW has attempted to use a (non-existant) variation. The simplified code I'm using in the template (it will eventually be a srcset, hence the small 'width' to large file): // Cut code fetching the $img itself echo '<img src="' . $img->webp->url . ' " width="300">'; The strange this is, that the correct WebP image *is* generated and subsequently served ('cookies.webp'), it just throws a hissy fit while doing it (once generated no error is shown). This error does not occur when generating WebP images from variations. Is this a known issue, should I submit an issue on Github?
  16. Update: SOLVED! Never mind, I had moved a bunch of hooks to admin.php, including the DynamicOptions hook, which is why it stopped working on the frontend. I have put the hook back in ready.php and works as expected. Of course that makes perfect sense in retrospect. [--- Snipped description of the problem, it was a wild goose chase! --]
  17. Well, this is embarassing, I did actually try it yesterday and it didn't work, but I tried again this morning and it works just fine now. I don't know what changed - maybe I forgot to save something before. Sorry about that!
  18. Thanks for this great module! I was wondering if it would be possible to add support for making it work with custom image/file fields templates? At the moment the option to enable it is crossed out in FieldtypeFile modeule settings (in PW 3.0.211 dev).
  19. [Note to moderators: this topic is no longer about ProcessWire specifically, could it moved to the Dev Talk forum?] @Commander_Gal I think the first thing you need to do here is work out your budget. How much money do you have to spend per month/year? Your budget will determine your hosting plan. You can always expand it later. Secondly, how much experience with web development do you have? Have you ever had a website before, specifically, have you got experience running a web server? That will determine what type of hosting plan you have. For a personal project, you might be better off with shared hosting where you do not have to manage the server yourself (whether physical or virtual/cloud) - it is also cheaper. As for developing the site, you will need some sort of local webserver to build the site on your computer (I use Laragon, free and fairly easy to use/learn) and I recommend a PHP-friendly IDE (Integrated Development Environment) to code with (I use Visual Studio Code, again free and open source). That is not an easy thing to set-up. I took a look at PeerTube (https://joinpeertube.org) and noted on their home page "PeerTube platforms you visit are built, managed and moderated by their owners" -- that means you have to build and maintain a server (although the FAQ does say it can be a virtual machine, see the FAQ: Should I have a big server to run PeerTube?), and you host the videos uploaded to your instance.
  20. Hi there, TL;DR: Start by building your own personal site to learn ProcessWire/PHP, while considering all the implications of becoming a content host/publisher. Which it sounds like you're planning on anyway. It's very exciting when you have an idea for a new project isn't it? A few years ago I had a webcomic I used to run on ProcessWire. (long since archived to a static site* that never updates) and it was a such a pleasure to build on that I had the same idea to set-up my own comic hosting site using ProcessWire as the engine. I even got as far as starting to develop modules for it. Ultimately, I abandoned the idea for the following reasons: Hosting costs money. Hosting images costs more money than text. Like... a lot more. The larger and higher-quality the image, the more it costs to host, and comics tend to need high quality images. You also mention videos - are these to be hosted too, or linked via YouTube (for example)? Ok, so you could use a third-party image hosting service, but then that too will cost money if your needs grow. Also, any site that hosts user content is going to need regular backups, which will also grow in size and require safe storage. Your users won't appreciate their hard work going *poof* in the night. Technical support. Any site that has users creating and uploading content will need 24hr (or near 24hr) technical support -- not just for site maintenence, but also user support. Security. You need to ensure user data is safe and secure. Now, out of the box ProcessWire is one of the most secure CMS out there, but you still need to ensure the database and user data is secure (remember those backups? They need to be stored securely). The exact details of the hoops you need to jump through and what laws you need to comply with vary depending on where the site is hosted. Responsibility. Like it or not, you will be a publisher. You will be responsible for the content put on your site. You will need a cast-iron acceptable use policy... run it by a lawyer! You will also need to enforce it, have a reporting system etc. And how will you deal with DMCA takedown notices? Acceptable content. When it comes to what is acceptable content, will it be child-safe only? If not, how will you ensure kids can't access it? Even if it is intended to be child-safe, what safeguarding features will there be to protect kids? I looked at the above list and decided "fudge it, I'm too old for this sh*t". You, however, may reach a different conclusion, or may have thought of everything already! There is one more issue that was less applicable to me: technical starting knowledge. When I had the idea, I was already a PHP programmer of several years (before ProcessWire, I hand-build a site to publish my comic), but I get the strong impression that you are not just new to ProcessWire, but new to PHP (maybe even programming? Forgive me if not) in general. Now, as Jan suggested, building a small site first is a great way to learn - my comic is how I learned a lot of my craft. I recommend you build a site for your own personal content while you learn, and it will give you time to consider all the other things in my List of Concerns above. We will be here to help as you learn. --- * Which was super-simple to do with ProcessWire too!
  21. Thanks, that page doesn't quite answer my question, although it leads to pages that might, so I have a lot of reading to do. My main concern is that it must be really easy for my client -- they are definitely not tech savvy, so if a process is remotely tricky (e.g., just setting up an account in the first place), it's just not going to work. They have used PayPal in the past and did not like it!
  22. I have never used Stripe before, but I am wondering if it what I need for a client... Does Stripe allow sellers to charge the buyer's card when items are shipped (which could be several days/a week later) instead of immediately when an order is placed? I am not talking about invoicing. As far as the buyer is concerned the process is a regular shopping cart experience, except their card won't be charged immediately. If it doesn't, is there any UK available payment gateway that does? This is for a small-scale business with <£300 per month of online sales (they are mostly a "bricks and mortar" store). I'm asking in the PW forum, because if it does, I'll be looking to use Padloper as the shopping cart. Right now my client is locked into Woocommerce and a discontinued CC (PCI compliant!) payment processor.
  23. That, and many other reasons, is why I use one ?
  24. To use a namespaced (or non-namespaced) class inside another namespaced file, you need to add a slash ('\') before the included classes' namespace. Otherwise, it is looking for the class relative to the file's namespace. While it works -- and in this instance doesn't appear to cause issues -- removing a file's namespace negates the reason for using namespaces in the first place. Here is an ammended version of your code: <?php namespace ProcessWire; class ProcessSocial extends WireData implements Module, ConfigurableModule { public function init() { $file = __DIR__ . '/vendor/autoload.php'; if (file_exists($file)) { require_once $file; } } protected function testFeed($user){ // Note the '\' before 'GetStream' $client = new \GetStream\Stream\Client($api, $key); $feed = $client->feed('User', $user); return $feed->getActivities(); } } If you find you are calling a class a lot, then you can use a 'use' statement at the top of the file, like this example: <?php namespace ProcessWire; use \GetStream\Stream\Client; // Namespace path to the classname (inc. the classname too) class ProcessSocial extends WireData implements Module, ConfigurableModule { public function init() { $file = __DIR__ . '/vendor/autoload.php'; if (file_exists($file)) { require_once $file; } } protected function testFeed($user){ // Now you don't need to add the namespace at all here $client = new Client($api, $key); $feed = $client->feed('User', $user); return $feed->getActivities(); } } Hope that helps.
  25. Another approach I use on my local dev environment, for completely unrelated projects on different hosts, is to simply symlink the 'wire' folder. My Setup/Structure: /www <-- my localhost root (I'm using Laragon). /processwire <-- folder dedicated to ProcessWire projects. /wire <-- the ACTUAL location of the wire folder that the symlinks point to. /project_a <-- each separate project (treat this folder as the web root: http://project_a.localhost/ ) /site <-- the project's ProcessWire /site folder /wire <--- this is a SYMLINK to the /www/processwire/wire folder /.htaccess <-- the ProcessWire .htaccess file. /index.php <-- the ProcessWire index.php file. /...etc <-- any other files that you'd put in the web root of a project (robots.txt etc). /project_b <-- same folder/file structure as above When I want to update the ProcessWire version, I just download it and copy the 'wire' folder over into /www/processwire (I actually rename the old folder, copy over the new and check everything works before deleting the old folder). Adding a New Project My process for adding a new project, we'll call it 'project_c', is then: Create the project in the ProcessWire projects folder: /www/processwire/project_c Create a local url for the project (http://project_c.localhost/) and point it to the newly created folder above. In the 'project_c' folder, unpack a copy of ProcessWire (the same version as the current shared wire folder for simplicity). In the browser visit http://project_c.localhost/ and run the installer as usual (& create the DB). Once installed successfully, delete the /www/processwire/project_c/wire folder (or rename it and delete later if it all works ok) and create a symlink to the shared 'wire' folder. The advantage of this for me, is that it does away with the need for naming the site folders 'site-project_a', 'site-project_b' etc.
  • Create New...