Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/25/2023 in all areas

  1. Just for some further reading https://dev.to/walternascimentobarroso/dotenv-in-php-45mn
    3 points
  2. Not sure I fully understand what you want to achieve, but if it's just loading values from a .env file then take a look at vlucas/phpdotenv. You can use composer to autoload it. Assuming you have site root in /var/www/somesite/public_html/ then cd in there and use composer from the cli... composer require vlucas/phpdotenv Create your .env file in there... DB_HOST="127.0.0.1" DB_NAME="somesite_db" You can then load the .env values from your site/config.php file... <?php ... require __DIR__ . '/../vendor/autoload.php'; // vendor dir in site root - adjust path if needed /** * Load values from your .env file... */ $loader = \Dotenv\Dotenv::createImmutable(__DIR__ . '/../'); // .env in site root dir - adjust path if needed $loader->load(); // .env values are now in $_ENV array. Use as needed... $config->dbHost = $_ENV['DB_HOST']; $config->dbName = $_ENV['DB_NAME']; ... You can house your .env elsewhere if you like - just adjust the paths as needed. Hope that helps.
    3 points
  3. What Steve said. And if you need it from your js components, there is dotenv. Take care to not leak the token, if you build the app with Vite, only variable with VITE prefix are exposed as import.meta.env.* eg. VITE_BAAAAAAD=abcd1234 (leaked) DEADBEEF=abcd1234 (not leaked / undefined)
    2 points
  4. Once you have a PageImage object, you can use the getDebugInfo method and parse the return value to identify the mimetype. ? https://processwire.com/api/ref/pageimage/get-debug-info/
    2 points
  5. 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.
    2 points
  6. Session Info Lists information about active sessions in a similar way to SessionHandlerDB, but for file-based sessions. Only install the module if you are not already using SessionHandlerDB. Installation 1. If you want to be able to see the pages that are being viewed by active sessions then set... $config->sessionHistory = 1; ...in /site/config.php If you have already set $config->sessionHistory to a higher number then you can leave it unchanged: 1 is the minimum needed for use in the Session Info module. 2. Install the Session Info module. A helper module named "Session Extras" will be automatically installed also. 3. If you want to be able to see the IP address and/or user agent for active sessions then visit the module config page for Session Extras and tick the relevant checkboxes. 4. You can now view information about active sessions at Access > Sessions. Screenshots With $config->sessionHistory set to 1 or higher: Additional information is listed when IP address and user agent tracking are enabled in Session Extras: https://github.com/Toutouwai/ProcessSessionInfo https://processwire.com/modules/process-session-info/
    1 point
  7. ConnectPageFields Allows the connecting of two related Page fields so that changing one updates the other. Purpose of module An example: suppose your website is about movies. You have a template "movie" with Page field "actors". For each movie you add the actors that appear in the movie. All good, but what if you want to find results like... the 10 actors who have appeared in the most movies actors who haven't appeared in any movies since 1990 You cannot retrieve these pages with a single efficient $pages->find() query, and must load a large PageArray into memory in order to iterate or filter it. For the sake of making these types of queries more efficient you could structure your templates/fields so that movies are added to actors instead, but this may be a less comfortable workflow and can run into equivalent problems (e.g. "find the 10 movies with the largest cast"). The solution is to have a two-way relationship so that movie pages have an "actors" Page field and actor pages have a "movies" Page field. This module will keep these two Page fields in sync so that adding "Ryan Gosling" to "Drive" automatically adds "Drive" to "Ryan Gosling". Also, you can select the same Page field in both Page field A and Page field B. For example, create a "Related" Page field for related pages. Choose "Related" for both fields in a pair in the module config. Now when you add "Orange buffoon" to Related for "Donald Trump", "Donald Trump" is automatically added to Related for "Orange buffoon". Usage Install the ConnectPageFields module. If you haven't already done so, create the two Page fields you want to connect and add them to templates. In the module config select the two Page fields in a "Connected field pair" row as Page field A and Page field B. You can add rows as needed using the "Add another row" button. Troubleshooting Make sure you have set the "Selectable Pages" settings for each Page field correctly: The settings for Page field A should allow pages using the template(s) that Page field B has been added to. The settings for Page field B should allow pages using the template(s) that Page field A has been added to. http://modules.processwire.com/modules/connect-page-fields/ https://github.com/Toutouwai/ConnectPageFields Module config: Demo showing how changing one Page field updates the other:
    1 point
  8. Maybe you could try to check what was changed. There are two modules I used in the past to do so. Install them in a test-environment to find out which works better in your case. For now I can't really recommend the one or the other. https://processwire.com/modules/version-control/ https://processwire.com/modules/process-changelog/ both by @teppo PageHitCounter had this issue in an early version... so page hits resolved in an update BUT... that was long ago.
    1 point
  9. Hi @joer80! AFAIK this feature is still missing due to the way ProcessWire works with files. It has been requested and discussed lot of times thought. Read this whole thread for example. There is a module that claims to help with AWS S3. Haven't tried it myself.
    1 point
  10. Sure - compromise - it's still below the Page Info, but it's right below it and open by default.
    1 point
  11. The problem here is (potentially) three-fold, depending on (others') needs: If it's supported in a Pageimage field, it's likely expected to also be supported in a Pageimages field (WireArray) which adds some awkward complexity, because... We can have multiple image fields per template - we'd have to determine focus prior to pasting for this to work properly, whether a button is clicked (and it just attempts to pull from the clipboard) or a some sort of area gains focus, and then we paste... As flydev mentions, we're limited in the filetype that we can save as - and simultaneously if there's a developer preference should it be predetermined, or do we just go with whatever the OS provided as default? What you might be thinking about is this forum's ability to paste an image as a file attachment, but it is essentially using CKE to handle that; otherwise, I only really remember Robin's module as a way to paste URLs of a file (and not just a data: URL, though it might be able to be modified to handle that). I've handled clipboard image pasting before, but I've never handled multiple images (files) within a single clipboard instance. That's outside your described scenario, to a degree, but drag-and-drop supports multiple files, so should copying multiple existing files and pasting also similarly work in this example?
    1 point
  12. In our page template cache settings we have, "Clear cache for saved page and parents", which works as expected when using ProcessWire (3.0.200) interactively. When we manipulate pages with the same template from the API though we get this: $page->save(); // Cache clear happens as expected $page->save('my_field'); // Cache clear is not triggered – it's as if the page has not been saved (though the field has been saved correctly). $page->setAndSave('my_field', $value); // Cache clear is not triggered Is this the expected behaviour? If so, could the $page->save() documentation be updated to mention this difference?
    1 point
  13. That's not correct. It's not populated by json data – which by the way is not really a standard or alike – but only by data formatted in application/x-www-form-urlencoded or multipart/form-data. Both is what a <form> can send, but ajax can also send data in that format. It's just that ajax libs nowadays favor json (, it's not like it's name would include xml :D).
    1 point
  14. $this->input->post is not populated for AJAX requests (caused by PHP, see this). I use something like this. <?php $raw = file_get_contents('php://input'); // optionally check for Content-Type headers if(is_array($parsed = json_decode($raw, true))) { $this->wire->input->post->setArray($parsed); $this->config->ajax = true; } // use $this->input->post->varName as usual
    1 point
×
×
  • Create New...