-
Posts
1,514 -
Joined
-
Last visited
-
Days Won
45
Everything posted by gebeer
-
UPDATE: I installed a multilang page from scratch and found that the behaviour is the same as with my other install which also is latest dev. On PW 3.0.189 dev mysite.local/cn/cn/ redirects to mysite.local/cn/ Whereas when I switch to 3.0.184 master, mysite.local/cn/cn/ throws a 404. Will go and file an issue. Meanwhile if any of you can enlighten me, that would be great. Filed an issue at GH https://github.com/processwire/processwire-issues/issues/1479
-
Hello all, didn't know how to better describe my problem in the thread title. So bare with me. Will try to explain my setup. - multilingual site with all necessary modules installed, including LanguageSupportPageNames - default lang is English. Default lang homepage URL performs a redirect to /en/. So default home URL is mysite.local/en/ - one of my languages is Chinese (name cn). Home URL for Chinese is mysite.local/cn/ Page tree with page names and URLs for chinese language: - home: mysite.local/cn/ -- cn: mysite.local/cn/cn/ << here is the problematic URL: page name = lang name --- page1 mysite.local/cn/cn/page1 (only active in en and cn) --- page2 mysite.local/cn/cn/page2 (only active in en and cn) Now if I visit mysite.local/cn/cn/ I get redirected to mysite.local/cn/ which results in homepage view. Visiting mysite.local/cn/cn/page1 redirects to mysite.local/cn/page1. Results in 404 Changing the page name 'cn' to something else like 'asia' would resolve the problem But it is not an option because the URL structure like /en/cn/ and /cn/cn/ is a requirement for the project. Tracing back the redirect with Debug::backtrace inside a before hook to Session::redirect reveals the following: In wire/core/PagesPathFinder.php l. 519 the array $parts, (in my case [0 => 'cn', 1 => 'cn']) is passed by reference to getPathPartsLanguage(array &$parts) In that method the language is determined from the first entry in the array $parts. In that process the first entry is removed by $segment = array_shift($parts) Since $parts is passed in by reference, the original array of 2 path elements is being reduced to 1. This results in a wrong path and redirection. When I change the code so that $parts is not being passed by reference, weird things start happening. Getting 404s for existing pages like mysite.local/cn/cn/page1 and even for default language mysite.local/en/cn/page1 ATM I'm lost and don't know how I can get the required URL structure to work as expected. So if any of you have an idea of what could be the culprit here, please let me know. Thank you for staying with me until here.
-
Totally did not think of that one. Thanks a ton!
-
@adrianrevviving this old thread because I would need the rootparent selector, too. Have any of you ever had the need for this kind of selector? Just asking here before filing a feature request.
-
I just implemented this inside a autoload module and discovered that this hook only works in application ready state. So if you are utilizing this inside a module, you need to call the hook inside ready() method like this public function init() { // handle render of correct page from urlSegements $this->addHookAfter('ProcessPageView::execute', $this, 'hookPageView'); } public function ready() { // need to call this in ready. Not working in init() $this->pages->addHookAfter('Page::path', $this, 'hookPagePath'); } public function hookPagePath(HookEvent $event) { $page = $event->object; // page ROW and all children recursively if ($page->id == 1043 || $page->rootParent->id != 1043) return; $orgPath = $event->return; $pathSegments = explode('/', trim($orgPath, '/')); // $pathSegments[0] is language segment // get rid of $pathSegments[1] 'row' unset($pathSegments[1]); $newPath = '/' . implode('/', $pathSegments) . '/'; $event->return = str_replace('//', '/', $newPath); } public function hookPageView(HookEvent $event) { $page = $event->page; // only act on homepage if ($page->id != 1) return; // get last urlSegment to retieve page with that name if (count(input()->urlSegments())) { $wantedName = sanitizer()->pageName(input()->urlSegmentLast); $wantedPage = pages()->get("name={$wantedName}"); if ($wantedPage && $wantedPage->id) { $event->return = $wantedPage->render(); } else { throw new Wire404Exception(); } } } If knew this earlier it would have saved me some time and frustration...
-
Great, thank you so much for the quick fix. Everything working smoothly and I'm having fun again working with the console. Yeah, I thought that the monospace option should take care of that, too. But, obviously, this was not the case. Cheers
-
Hi all, I am experiencing a very strange issue inside the Tracy console for some time now. While typing, suddenly the new characters get inserted 1 position off to the left of the cursor. This is best demonstrated by a short clip: console.mp4 It makes editing impossible. This started happening on some installs for some time. But now is happening on all. I thought this must be a caching issue then. But it is happening across browsers (FF, Brave, Chrome - all on Linux). No JS errors in the dev console. I did a related search for ace editor that came up with https://stackoverflow.com/questions/15183031/ace-editor-cursor-behaves-incorrectly https://github.com/ajaxorg/ace/issues/2548 https://pretagteam.com/question/wrong-cursor-position-with-ace-editor-in-safari They all refer to a problem with none monospaced fonts used in the editor (specifically on iOs and Linux). Digging through the CSS, I found this rule which is injected in a style attribute by Tracy `<style nonce="" class="tracy-debug">`: .ace_editor, .ace_editor * { font-family: 'Monaco','Menlo','Ubuntu Mono','Consolas','source-code-pro',monospace!important; } When changing the rule to include Courier New, it works: .ace_editor, .ace_editor * { font-family: 'Courier New', 'Monaco','Menlo','Ubuntu Mono','Consolas','source-code-pro',monospace!important; } This might be just an issue on Linux. Can anybody confirm this for other operating systems? @adrian would it be possible to include Courier New in the font-family? This seems to be injected through site/modules/TracyDebugger/scripts/ace-editor/ace.js. So I'm not sure if you have influence on the contents of that file. A search on the ace issue tracker reveiles quite a few related issues. So the problem is well known but hasn't been fixed in years. As a quick fix, I added the extra font to ace.js but this will be gone with the next update. Oh wait, actually this is defined in site/modules/TracyDebugger/styles/styles.css around line 1787. I added Courier New there: .ace_editor, .ace_editor * { font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'Courier New', monospace !important; } Would be great if this could be included in one of the next updates.
-
@fuzendesign Are you using TracyDebugger module? If not, I can highly recommend it. It is a big time saver being able to easily dump and inspect your code and makes developing with PW even more enjoyable.
-
You are pointing to a solved thread and asking me for an answer. You say you are stuck but don't tell where you're stuck. I'm afraid I can't help you if you don't give exact details of your problem. EDIT: reading my reply again, it sounds a bit grumpy. That was not really intended. Just wanted to say that you have higher chances in getting a helpful answer if you try and explain your problem in more detail, possibly with some code that you already have.
-
Thanks a lot but no need. What are you doing with the form data once it is submitted? Instead of using my hook to alter the value in the form it would be much easier to hook into the processing of the form and get the email there from the ID and save it (just like @wbmnfktr suggested).
-
The option value is not visible to the user of the form. What are you using this form for and why do you need the option values to be email instead of ID? Please describe what you want to do with that form data. Maybe I should have asked that question before posting my solution above ?
-
Depending on what kind of page reference field you are using, you could achieve that with a hook, for example in site/ready.php. In this example I am using a page reference field named 'page_reference' and as the Input Field Type I am using a Select field. Now I hook into the Inputfield::render method with a before hook: // use before hook to alter options passed to the Inputfield $wire->addHookBefore('InputfieldSelect::render', function ($event) { // return; if($event->object->name != 'page_reference') return; // build our new options array $options = array(); // $event->object->options is an array of options originally passed to the InputField foreach($event->object->options as $id => $title) { $options[$this->pages->get($id)->name] = $title; // exchange name for email } // set our new options to the InputField $event->object->options = $options; }); This sets the value of the <option> tag to the page name. you can use $this->pages->get($id)->email to set the emails as value. Don't know where you render that form. If it is a custom form somewhere, this should do. But be careful if you plan to use this in the PW page editing form. You will need to take some extra steps when saving the page. Because PW needs the ID of the page to be saved. In that case you can have a look at InputfieldPage::processInput and hook into that to revert your email values back to IDs.
-
$files->send() Iphone error Cannot parse response
gebeer replied to gebeer's topic in General Support
Not sure. Since the Output method is working fine, I haven't tried other methods :-) -
$files->send() Iphone error Cannot parse response
gebeer replied to gebeer's topic in General Support
Thank you. I had googled but din't find that link which is quite enlightening. Seems like Mpdf's Output method sets different headers than $files->send() does. I will check what headers are set exactly and can then amend the $files->send() method using the headers option to pass the headers that Safari likes. Cheers! -
Facing a strange issue with $files->send() method creating this error only on Iphone Safari: "Cannot parse response". On all other clients it is working fine. I am creating a pdf with @bernhard's RockPdf module (which basically is a wrapper around Mpdf library) and sending it for download to browser $pdf = $modules->get('RockPdf'); // ... $mpdf = $pdf->mpdf; // ... $mpdf->WriteHTML($header . $job->render(array('noLinks' => true))); // send $options['noLinks'] for pdf output to not render as links $filename = $input->urlSegment1 . '.pdf'; $saved = $pdf->save($input->urlSegment1 . '.pdf'); if (isset($saved) && $saved->path && file_exists($saved->path)) { try { $files->send($saved->path, array('exit' => true)); unlink($saved->path); } catch (\Throwable $th) { $log->save('pdfdownloads', $th->getMessage()); } } When using Mpdf's native Output method, the rror does not occur $pdf = $modules->get('RockPdf'); // ... $mpdf = $pdf->mpdf; // ... $mpdf->WriteHTML($header . $job->render(array('noLinks' => true))); $filename = $input->urlSegment1 . '.pdf'; try { $output = $mpdf->Output($filename, \Mpdf\Output\Destination::DOWNLOAD); // send to browser } catch (\Throwable $th) { $log->save('pdfdownloads', $th->getMessage()); } exit(); Since PDF generation and Mpdf's native Output method are working fine it seems that $files->send() is the culprit here. Honestly, I have no idea what could cause such a behavior only on Iphone's Safari. Any insights by someone who has more background knowledge on this would be much appreciated.
-
module Module ImageReference - Pick images from various sources
gebeer replied to gebeer's topic in Modules/Plugins
Never used it together with the Combo Pro module. Actually, I didn't even know that a Combo Pro Module exists ? Is it part of the ProFields package? Then I could have a look at it. And that is exactly what I meant when I said that it is hard to cater for all possible setups. At least I managed to make my module work well with the Repeater Matrix Pro Field ? Edit: Just saw your thread Since my module behind the scene is working with PageImage objects and is storing data in multiple columns, I don't think it is possible to make it work with the Combo Field ATM. Would have to look deeper into how Combo Field is storing data, but, unfortunately, do not have the resources. Not until mid to end of October. -
module Module ImageReference - Pick images from various sources
gebeer replied to gebeer's topic in Modules/Plugins
Thank you for asking. Not really. Apart from having limited resources for supporting the module. Most of the bugs mentioned in this thread should be fixed. Have it running in production on 2 sites with no problems so far. But there are so many different setups that people run their sites on so I was still not confident enough to release it as an official module. -
I experienced the same. Just loading the InputfieldDatetime module does not apply the required classes to initialize the datepicker. I also had to manually load the module assets from InputfieldDatetime module. They were not loaded automatically by loading the module. This is my working code: $f = $this->modules->get('InputfieldDatetime'); // load module $this->config->scripts->add($this->config->urls->modules . 'Inputfield/InputfieldDatetime/InputfieldDatetime.js'); // load module assets $this->config->styles->add($this->config->urls->modules . 'Inputfield/InputfieldDatetime/InputfieldDatetime.css'); // load module assets $f->attr('name', 'deliverydate-' . $id); $f->addClass('FieldtypeDatetime InputfieldDatetimeDatepicker InputfieldDatetimeDatepicker1'); // manually assign classes $f->label = ('Lieferdatum'); $f->inputType = 'text'; $f->datepicker = \ProcessWire\InputfieldDatetime::datepickerFocus; // this does not work. datepicker widget does not appear on focus $f->dateInputFormat = 'd.m.Y'; Another little thing that I could not get to work is triggering the datepicker on focus of the inputfield. My field looks like this and the user has to click the calendar icon to make the datepicker appear.
-
Take Javascript value and reload content with AJAX
gebeer replied to Liam88's topic in Getting Started
On another sidenote, in this part of your code if ($input->get){ ... }else { ... } $input->get will always return true, even if you do not have any GET parameters in your URL because $input->get returns an WireInputData object. You should use if(count($input->get)) // returns 0 if there are no URL params instead.- 4 replies
-
- 1
-
-
- ajax
- javascript
-
(and 1 more)
Tagged with:
-
Can't hook 404 Page via ProcessPageView::pageNotFound
gebeer replied to bernhard's topic in General Support
Just stumbled over the same problem: ProcessPageView::pageNotFound hook only working in init.php, not in ready.php Should be mentioned in the documentation. I just opened an issue. -
In your code you are storing an array $portfolio to the cache. To store HTML you would use the same logic as for storing an array but store an HTML string instead. How you create the HTML string is totally up to you. It could be the return value of a $page->render() call or anything else. Simplified example $response = $cache->get('my-html-cache'); if (!$response) { $html = $page->render(); // render a page // OR $html = $files->render('path-to-template.php'); // render page data with a custom template file // OR $html = '<h1>Cached Headline</h1>' // simple HTML string $cache->save('my-html-cache', $html, "template=portfolio"); }
-
A GET parameter is the way to go here, as @rash suggests. You could also use the template name in the get parameter <p><a href="<?= $item->url ?>?template=news-detail">read more</a></p> and then in your news.php template do something like if($input->get->template && $template = $input->get->text('template')) { // check for GET parameter 'template' and sanitize $files->include("{$template}.php") // use $files API to include the template. All API variables (like $page) will be passed } else { // your regular news.php template logic logic goes here }
-
Absolutely makes sense.
-
Wouldn't it be better to avoid commas in URLs? According to the URI RFC, commas are reserved characters. They are allowed for filenames in URLs. I haven't tried it, but you should be able to configure conversion of comma to dash (or other characters) in module InputfieldPageName to avoid them in the first place. Configurable option for convertEncoded in the InputfieldURL module also seems hacky to me.