Jump to content

Jan Romero

Members
  • Posts

    521
  • Joined

  • Last visited

  • Days Won

    12

Everything posted by Jan Romero

  1. I don’t think ProcessWire has this built in. Do you have gaps that you need to skip or maybe show as inactive? If not you can just find the oldest and newest page and iterate between them. Otherwise I suggest custom SQL to efficiently group by something like year(pages.published). I think RockFinder can also group things, might want to check that out.
  2. Works for me... However, a blank value will give you an empty string, so you need to take that into account when you write your comparisons. In PHP an empty string IS equal to 0 with loose comparison, so '' >= 0 is TRUE. To test for blank values, you can just check $page->myfloat === '' or is_string($page->myfloat) or probably a million other things, considering we’re in PHP land. I agree that this isn’t strictly mentioned your screenshot, but it should be. edit: lol turns out they changed this with PHP 8.0, so watch out for that too
  3. remove the s. https://processwire.com/api/ref/page/parents/ https://processwire.com/api/ref/page/parent/
  4. This is apparently a really old hat and common in many editors, but it’s the first I’ve heard of it and it just blew my mind. Did you know you can name heredoc strings “HTML” to get HTML syntax highlighting?! I kind of try to avoid heredoc, but this seems pretty neat.
  5. I mean we still don’t know what exactly you’re doing, but you definitely don’t need #1, it’s just there to show the result of my test POST. You just said you’re using formdata, so DON’T send the urlencoded header. In fact I just tested it with XMLHttpRequest and it also automatically builds the Content-Type header for you, so you don’t need that part at all. Building on my example above, this is all you need: document.getElementById('formdataxhr').addEventListener('click', async function(event) { event.preventDefault(); const request = new XMLHttpRequest(); request.open('POST', './'); request.send(new FormData(document.forms.fruidform)); //or manually use FormData.append() or FormData.set() as you said }); Yes, you need to add the X-Requested-With header, but that’s ONLY there to set ProcessWire’s config()->ajax property to true. Everything else works fine without it.
  6. (this is a mispost pls ignor)
  7. Here is a minimal example that works for me: <?php namespace ProcessWire; if (input()->post('message')) { header('content-type: text/plain'); //this makes the browser show the "unformatted" response body, i.e. it won’t render HTML die(input()->post->textarea('message')); } ?> <form id="fruidform" method="POST" action="./"> <textarea name="message">&lt;h1&gt;two &gt; one&lt;/h1&gt;</textarea> <button id="urlencoded" type="submit">Tu es urlencoded</button> <button id="formdata" type="submit">Tu es als form-data</button> </form> <script> document.getElementById('urlencoded').addEventListener('click', async function(event) { event.preventDefault(); const response = await fetch('./', { method: 'POST', body: new URLSearchParams([['message', document.forms.fruidform.message.value]]) //you can also make a URLSearchParams from a form automatically, so you don’t have to reassemble all fields yourself: //new URLSearchParams(new FormData(document.forms.fruidform)) }); }); document.getElementById('formdata').addEventListener('click', async function(event) { event.preventDefault(); const response = await fetch('./', { method: 'POST', body: new FormData(document.forms.fruidform) }); }); </script> Observe how you get back “two > one” from the server in both cases. What are you doing differently? Also see how you don’t need to put the content-type header explicitly, because fetch() infers it from the body’s type automatically, but it is sent in both cases! If you look at the unformatted request body in the browser console, you’ll see that the first one is is: message=%3Ch1%3Etwo+%3E+one%3C%2Fh1%3E" message=%3Ch1%3Etwo+%3E+one%3C%2Fh1%3E" That mess of % symbols is “urlencoded” and the request has a header that announces this to the server, so the server will know how to decode it: “Content-Type: application/x-www-form-urlencoded;charset=UTF-8”. It’s called “urlencoded” because it specifically exists to encode GET parameters as part of URLs, but you can use it for POST as well, as you can see. The form-data request body looks like this: -----------------------------9162892302224017952318706005 Content-Disposition: form-data; name="message" <h1>two > one</h1> -----------------------------9162892302224017952318706005-- (Your boundary may vary. The browser generates automatically.) Again the request’s content-type header tells the server that it’s sending this format: “Content-Type: multipart/form-data; boundary=---------------------------9162892302224017952318706005”. If you use XMLHttpRequest, you may need to set the content-type explicitly according to the format you’re sending, I’m not sure, but it can't hurt. Another thing is that these are (I believe) the only two content-types that PHP will put into its $_POST and $_GET variables. That’s why @gebeer’s example had to use file_get_contents('php://input') to get the JSON. Of course you can also send JSON as urlencoded or form-data. Then you can use json_decode(input()->post('myjson')).
  8. Headers are fine. So is your request content actually urlencoded?
  9. If you can believe it, I could have really used that feature just this saturday, when I had to downlod multiple images with a fiddly laptop touchpad 😄 I’ll check out your SASS module (I’ve often wondered why that’s not the predominant way to do it, actually. Sounds awesome!) and get a PR going, but it’s going to be a couple of days.
  10. Glad you figured it out! Is this documented somewhere or did you find this by trial and error? They flag you just for some url segments?!
  11. I was looking at this thread earlier and was confused, but now I’ve had a drink, I think you want to show a single list of pages whose parent matches some conditions? You can use selectors on fields of the parent like this: pages()->find('parent.title=something, parent.mengtest=orother')
  12. I think you just need to change this to $uploadpage->programme_photo->add($uploadPath . $file); Have you checked if there are any errors from WireUpload? $doc->getErrors()
  13. I mean… it’s always going to be departments/<some department>/<some category>/, right? So when you navigate to a catetory page such as your example /sitename/departments/hardware/heating/, you want to see products that have both department=hardware and category=heating? Do you use the same template for sellers, brands, categories and departments? It would be easy if you had a specific category template. Otherwise you have to go by position in the page tree: if ($page->matches('has_parent=departments')) { // you could also use $page->rootParent if /departments/ is immediately below root //now $page may be either a department or a category. we assume //that /departments/ has ONLY departments as children, and all //such departments have ONLY categories as children (or perhaps //they have things that don’t run this template) if ($page->parent->name === 'department') $items = $pages->find("parent=/products/, department=$page, sort=$order, limit=4"); else $items = $pages->find("parent=/products/, department=$page->parent, category=$page, sort=$order, limit=4"); $file = "_products.php"; } else { //sellers and brands }
  14. What exactly is the behaviour you see on mobile? Maybe it’s some kind of caching issue?
  15. Hi @Larhendiel, there appears to be some custom abstraction that is not part of ProcessWire called "MenuItem". There should be a place where these MenuItem objects are used to generate the actual markup ("<a href" etc.). You may be able to just hardcode your external link there, or build something that aligns more closely with the current system. From the look of it, a MenuItem takes a Page object to generate a link, so unless there already is a way to give it an external address, you’ll have to build it yourself. If you need more concrete assistance, please post the class definition of MenuItem and the code that renders the menu markup (please use the code function for this, it’s the button with the "<>" symbols on it).
  16. $page->select_categories is a PageArray (multiple values can be selected), so you can’t compare it to "unternehmen". Try $page->select_categories->has('name=unternehmen').
  17. I don’t know what’s going wrong, but maybe I can contribute a couple of things. Firstly, a more readable version of your code: include("/html/index.php"); // bootstrap ProcessWire // Get derefAsPage property of page_field_b to distinguish multiple/single page fields $deref = $fields->get('select_related_articles')->derefAsPage; // […] some stuff appears to have been omitted here ($pgs) foreach ($pgs as $p) { // For this page, get the pages selected in page_field_a $selected_pages = $p->select_author; // Standardise $selected_pages to PageArray in case of "single" field if ($selected_pages instanceof Page) $selected_pages = $selected_pages->and(); foreach ($selected_pages as $selected_page) { // Add this page to page_field_b on the selected page $selected_page->of(false); // <-- This is the offending line if ($deref) { $selected_page->select_related_articles = $p; echo "Set $p \n"; } else { $selected_page->select_related_articles->add($p); echo "Added $p \n"; } $selected_page->save(); } $numPgs--; echo $numPgs . "\r"; } Secondly, I don’t think you even need to turn off output formatting explicitly, because it’s off by default in this bootstrapped context. Lastly and probably most relevant, the error message tells you that $selected_page is an integer when you try to call of(false) on it. I don’t really see how that would happen given your code, but maybe just dump its value here and there to figure it out? Since it’s the value of a page reference field, it should be Page (perhaps a custom page type), NullPage or PageArray. Btw, if it is a Page or NullPage object and you call and() on it, you’ll get a WireArray, not a PageArray.
  18. Maybe this helps? https://whatsmychaincert.com/?test2.gemeindeguru.at I wish I knew more about this stuff 🙄
  19. I think the problem is here https://github.com/processwire/processwire/blob/924f93214536a506babbce1bab5c6c9e2093fc1e/wire/core/WireHttp.php#L471 See how it sanitizes the url at the top of the function. That’s where it prepends the scheme if necessary. Curl and fopen are called with that sanitized url, but your error came from the "socket" method, which seems to be called with the unsanitized url. I’m probably missing something, but I’m not going to look into this any more deeply from my phone 😄
  20. Not at a computer right now, but the error should have the host name in it (where the two spaces collide instead, and before the :80 port). Apparently something went wrong inside wireHttp->get() where it parses the url string. Indeed, url_parse() doesn’t return the right components when given "test2.gemeindeguru.at". I think you’re required to pass the url including the protocol.
  21. Well, I have only tested it with the "Default" admin theme (is that even still the default or new installations?) and only in Firefox. Also, while I doubt the CSS changes have any unintended consequences, it would be cleaner to refactor the gridImage__trash class to something more generic. I guess just renaming it would suffice for a start, but it clearly wasn’t made to hold a simple link. You’re too kind 🙂
  22. I’ve made a different wild guess https://github.com/JanRomero/processwire/commit/1641e1681ae20fb01ca0ec3568da0832fb3337b1 It’s messed up because my editor uses spaces by default and PW uses tabs, also I did it on the master branch because I’m an idiot, but whatever. Works okay, looks like this: And this is the list view: I would not merge this though 😉 Edit: oh yeah because it uses an <a> inside the <label> you have to hit the icon quite precisely, even though the cursor changes over the whole label. Well, I don’t mess with SCSS… @bernhard Thanks for the like, finally I’m a hero member 😄 Took me long enough
  23. I do: Added "download" to the labels array at the top, and "class='$modalButtonClass'" to the button. This still requires several clicks, though. First, unless you’re already in the list view, you have to open the image to see the button, then the button will just open a lightbox where you can right click -> save as (you can’t do it on the button because it’s a button element).
  24. What TextFormatter are you using? The Parsedown formatter for example will wrap indented blocks in <pre><code></code></pre> tags. It will also give the code tag a class if you use backtick syntax and specify a language: Will turn into: <p>Some prose text.</p> <pre><code class="language-SQL">select * from pages p left join field_title t on p.id = t.pages_id where p.templates_id = 69</code></pre> <p>More prose.</p> Then you can use the class to apply syntax highlighting.
  25. Can you not do this? $cl = $languages->get($user->language->name); $blog_title = empty($page->getUnformatted('title')->getLanguageValue[$cl]) ? 'Look Ma No Title' //user’s language title is empty : $page->getLanguageValue($cl, 'title'); //user’s language title is not empty The unformatted value of language fields should be a LanguagesPageFieldValue object that you can ask about language values without fallback: https://github.com/processwire/processwire/blob/dev/wire/modules/LanguageSupport/LanguagesPageFieldValue.php
×
×
  • Create New...