Leaderboard
Popular Content
Showing content with the highest reputation on 09/03/2023 in all areas
-
Also want to point out how the video clearly shows that if you write PHP, a very fast and expensive sports car will show up in your garage. You can't argue with that, it's right there next to his big reaction face.3 points
-
Happy 1st of September! Now that we've got the new main/master version out and running smoothly, I've been catching up with some client work this week. I'll need to do some of that next week too. But we'll also be fine tuning the core and fixing anything that comes up in issue reports. We may have have another master version out with these kinds of minor updates before digging into more major updates, feature requests and PRs on the dev branch this month. If you've not yet upgraded to 3.0.226 yet, I'd encourage you to give it a try. So far all reports have been positive and I've not heard of anyone running into any upgrade issues yet. Thanks and have a great weekend!3 points
-
I've added your example to the mentioned issue: https://github.com/processwire/processwire-requests/issues/56#issuecomment-17043639562 points
-
How did you upload the file via api? Can you give a quick example to reproduce the issue? If you do that and post it to this issue and mention Ryan I guess chances are high that he will fix this quickly. At least I suggested the uploadName feature on Feb 16 and he implemented it on Feb 17 ? Maybe he just didn't think of API uploads.2 points
-
Hello, I made this little experiment, maybe useful for someone. YAWS (Yet Another Webserver) is a HTTP 1.0/1.1 webserver which is completely written in Erlang. YAWS has been noted well suited for dynamic-content web applications in many cases. Because Yaws uses Erlang's lightweight threading system, it performs well under high concurrency. A load test conducted in 2002 comparing Yaws and Apache found that with the hardware tested, Apache failed at 4,000 concurrent connections, while Yaws continued functioning with over 80,000 concurrent connections. Mixing Erlang and PHP is a powerful combination. PHP has a vast web development ecosystem and Erlang has more than 30 years of production ready concurrency solutions that scale well. https://github.com/joyofpw/pwyaws/ Cheers.1 point
-
ProcessWire automatically sanitises the names of files that are uploaded to a Files field. For example, a file named "Café meals under $30.pdf" will become "cafe_meals_under_30.pdf" after it is uploaded. Since v3.0.212 ProcessWire stores the original unsanitised filename of each uploaded file, and this is accessible via $pagefile->uploadName https://processwire.com/blog/posts/pw-3.0.226/#file-and-image-improvements https://processwire.com/api/ref/pagefile/upload-name/ So if I have a field named "files" on my page and I want to provide downloads of the files with their original filename I can output links like this: $out = ''; foreach($page->files as $file) { // uploadName is entity-encoded when output formatting is on $original_name_unencoded = html_entity_decode($file->uploadName); $out .= "<p><a href='$file->url' download='$original_name_unencoded'>$file->uploadName</a></p>"; } echo $out; So far, so good. But I want my site visitors to be able to view PDFs in the browser rather than force a download, yet if they do download them after viewing them I want the files to get the original filename. For this I can use a URL hook to deliver the PDF via PHP rather than directly loading the file. In /site/ready.php: $wire->addHook('/view-pdf/{page_id}/{filename}', function($event) { $id = (int) $event->page_id; $filename = $event->wire()->sanitizer->text($event->filename); if(!$id || !$filename) return 'Invalid request'; // Get the Pagefile via PagefilesManager $pm = $event->wire()->pages->get($id)->filesManager; $file = $pm->getFile($filename); if(!$file) return 'File not found'; // uploadName is entity-encoded when output formatting is on $original_name_unencoded = html_entity_decode($file->uploadName); // Set headers and output the PDF content header("Content-Type: application/pdf"); header("Content-Disposition: inline; filename=$original_name_unencoded"); header("Content-Transfer-Encoding: binary"); header("Accept-Ranges: bytes"); @readfile($file->filename); return true; }); In the page template file: $out = ''; foreach($page->files as $file) { if($file->ext === 'pdf') { // Deliver PDF files via the URL hook $out .= "<p><a href='/view-pdf/$page->id/$file->basename'>$file->uploadName</a></p>"; } else { // Other files receive a download attribute // uploadName is entity-encoded when output formatting is on $original_name_unencoded = html_entity_decode($file->uploadName); $out .= "<p><a href='$file->url' download='$original_name_unencoded'>$file->uploadName</a></p>"; } } echo $out;1 point
-
Adding custom PHP code to any page in the backend is extremely easy as well (if you know how) ? <?phhp // in site/ready.php $wire->addHookAfter("ProcessPageEdit::buildForm", function ($event) { $form = $event->return; $page = $event->object->getPage(); if ($page->template != 'home') return; $existingField = $form->get('title'); $out = "Show 5 random pages:"; $pages = $this->wire->pages->find("limit=5, template=basic-page, sort=random"); foreach ($pages as $p) { $out .= "<div><a href={$p->editUrl}>{$p->title}</a></div>"; } $newField = [ 'type' => 'markup', 'label' => 'foo', 'icon' => 'check', 'value' => $out, ]; $form->insertAfter($newField, $existingField); });1 point
-
You could add a multi page reference field to the "Project" template to store the associated persons. And synchronize the two reference fields with the excellent "Connect Page Fields" module by Robin S. https://github.com/Toutouwai/ConnectPageFields1 point
-
Hi fruid, I'm not the most indicated to help, but in the meanwhile some other much more skilled then me, I try to give mi 50c: Maybe in your custom field creation foreach, is missing something like: $field->attr('checked', empty($data[$menuName]) ? '' : 'checked'); And a guess: Surely it's a typo error but before calling the InputfieldCheckboxes you have a commented note for an ASMSelect. Maybe there are other copy/paste mistakes? P.S. Dumping the checkboxes values, are they null/0/empty?1 point
-
The upload name is shown in a tooltip when you hover on the file icon in the inputfield: If you want something that's always visible you could hook into the inputfield rendering: // Display upload name in InputfieldFile $wire->addHookAfter('InputfieldFile::renderItem', function(HookEvent $event) { /** @var Pagefile $pagefile */ $pagefile = $event->arguments(0); $event->return = "<p class='upload-name'>$pagefile->uploadName</p>" . $event->return; }); And then style it with some custom admin CSS: .InputfieldFileItem .upload-name { color:white; line-height:1.33; padding:6px 10px; margin:0; background-color:#606060; } There are several ways you can add custom CSS to the PW admin - here is one: // Add custom CSS to admin $wire->addHookAfter('AdminTheme::getExtraMarkup', function(HookEvent $event) { $config = $event->wire()->config; $parts = $event->return; $css_url = $config->urls->templates . 'admin-assets/admin-custom.css'; $modified = filemtime(rtrim($config->paths->root, '/') . $css_url); $parts['head'] .= "<link rel='stylesheet' href='$css_url?m=$modified'>"; $event->return = $parts; }); Result:1 point
-
Hi @protro Rainbowkit is a really good package but last time I checked it (some months ago) I could see that it's built on wagmi, which is only working with React and then didn't paid so much attention to it as I am only coding on Svelte. Recently I saw popped a port of wagmi on svelte but still not tested it. FYI, the inertia module linked miss a little update, and the samples provided you will found are deprecated and are built using webpack. Did you have some experience with JS libs or frameworks (I mean vue, react or svelte) ? If not, I suggest you to start on Svelte as it's really the easier and natural frameworks to start on without experience. Anyway, as you said it, links above will helps you for sure. With any app sample you can find, you just have to send an ajax request to your ProcessWire page/template to get an answer with the required api keys/tokens/ whatever you need. Example: // 1. create a template called `web3` with a text field called `apikey` // 2. create php template in `site/web3.php` and leave it empty with no code // 3. create a page called `web3` with template `web3` // 4. in `init.php` write: // this function will help you to fight CORS issue between your app and pw site function cors() { // Allow from any origin if (isset($_SERVER['HTTP_ORIGIN'])) { // Decide if the origin in $_SERVER['HTTP_ORIGIN'] is one // you want to allow, and if so: header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}"); header('Access-Control-Allow-Credentials: true'); header('Access-Control-Max-Age: 86400'); // cache for 1 day } // Access-Control headers are received during OPTIONS requests if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD'])) // may also be using PUT, PATCH, HEAD etc header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}"); exit(0); } } /** * Example of a simple router using ProcessWire's built-in URL hook system. * By appending /json to any page URL, you'll get a JSON representation of the page * * Require ProcessWire 3.0.173 or newer. * see: https://processwire.com/blog/posts/pw-3.0.173/#outputting-json-data-about-any-page-when-the-last-part-of-the-url-is-json * * Note that this is a very simple example. For more advanced routing, you might want to * use a Process module like AppApi made by @mauricio. * */ $wire->addHook('(/.*)/json', function($event) { $page = $event->pages->findOne($event->arguments(1)); // fight cors (for test purpose only) cors(); if($page->viewable()) return [ 'id' => $page->id, 'url' => $page->url, 'title' => $page->title, 'apikey' => $page->apikey ]; }); // from any javascript lib or framework, send a request and get an answer const response = await fetch("https://localhost.local/web3/json"); const data = await response.json(); console.log(data); // <-- contain json answer /** { id: 1000, url: "https://mywebsite.local/web3", title: "web3 page", apikey: "API-ABCD-0123" } */ I've fallen behind on the vite and inertia module release, but it's coming, it's a matter of days, I suggest you to wait for it and try the web3 sample coming.1 point