Jump to content

Jan Romero

Members
  • Posts

    612
  • Joined

  • Last visited

  • Days Won

    15

Everything posted by Jan Romero

  1. Please teach Mirja the difference between ´, ` and ’, or install Super Smartypants.
  2. Technically, the username isn’t needed at all. Unless it’s exposed to users, it might as well be the the same as numeric page ID. If the email address is sufficiently unique, that’s all you need to look up the User object like $users->find("email={$email}") and call $session->login() with it. That is to say, you can pass the username to $session->login() as a string, but you can also pass a User object. https://processwire.com/api/ref/session/login/
  3. I dunno, I also get annoyed when I lose my session. It doesn’t happen every couple of minutes, but sometimes it still happens from one day to the next, even though I set the lifetime to a year. If ignoring IP and user-agent changes is so insecure, how does this forum do it, or pretty much all big websites for that matter?
  4. I figure this could lead to a collision if there were someone with the e-mail jim@ex-ample.com and someone with the e-mail jim-ex@ample.com.
  5. If you must use these files it would probably be best to call the php file from a ProcessWire template. For instance the same template that outputs the form. You could change the form’s ACTION from “contactform-process.php” to “/” and check if the form was submitted at the top of the template file (for instance, if $input->get or $input->post contains some value or possibly if $config->ajax is true, depending on what the form does). If so, include the contactform-process.php file. If you tell us what you’re trying to achieve, we might be able to help you do it with ProcessWire, though.
  6. Mh, it works for me. I believe 'autoload' => true must be set for it to call ready(). Have you tried reinstalling the module?
  7. I mean, you could do something like this: //in site/ready.php $this->addHook("Page::renderBlock", function($event) { $page = $event->object; if ($page->template->altFilename) $blockPath = $page->template->altFilename; else $blockPath = $page->template->name; $blockPath = "blocks/{$blockPath}.{$this->wire('config')->templateExtension}"; $event->return = $page->render($blockPath, $event->arguments(0)); }); Now you can call $page->renderBlock() or $page->renderBlock(['this' => 'that']) and the block’s template path will be determined automatically according to the template settings. Or this, maybe: $this->addHook("Page::renderBlock", function($event) { $page = $event->object; $templatePath = $this->wire('config')->paths->templates; $templatePath = substr_replace($page->template->filename, 'blocks/', strlen($templatePath), 0); $event->return = $page->render($templatePath, $event->arguments(0)); });
  8. Step 1: Change your form element’s action attribute to <?php echo $page->url; ?> Step 2: There is no step 2. edit: sorry, I didn’t read the whole thread either. This same answer had actually been posted by Soma two posts ago.
  9. I think this is a bug in ProcessWire. When you use the ~= operator, ProcessWire translates it into MySQL’s select /*[…]*/ match(field_title.data) against('+New York' in boolean mode) as _score_field_title_data1 /*[…]*/ order by _score_field_title_data1 desc The score it uses to sort is generated by the database according to the number of times the string appears in the text (probably more complicated than that, but whatever). The problem is that several results will have the same score, so the order among them is not deterministic. The database just does whatever it wants at that point, so the order may change inbetween queries, even if the queries are the same, but especially if they differ, even just in LIMIT and OFFSET. If you add "sort" to your selector string, ProcessWire will still use the score to sort, but only after your specified fields. What ProcessWire should do is ALWAYS sort by page id at the end, to keep the order deterministic. It might also be nice to make the relevance scores accessible in selector strings, so you could do something like "title|trader~='New York', sort=-title_relevance, sort=-trader_relevance, sort=-modified, sort=-id" Now you could have results in order of textual relevance, and if the relevance is equal, get the most current ones first, or whatever you desire. Obviously the id is a pretty stupid way to sort, but since it’s strictly unique, it’s a stable way to break ties, so I’d always put it last.
  10. Yes, that would be very un-databasey. You basically have three entities you care about: Chairs, Brands and Adapters. At first glance (I may be wrong about this) it looks like each Chair has exactly one Brand and exactly one Adapter. For each Brand there are multiple Chairs and multiple Adapters, and for each Adapter there are multiple Brands and multiple Chairs. Make three templates, Chair, Brand and Adapter. The Chair template has one page field for a Brand page and one page field for an Adapter page. Now you can structure your page tree any way you like. If you want your URLs to look like http://example.com/e-drive/netti-i/, put Chairs under their Adapters as children. Now you can drop the Adapter page field and just use the Chair’s parent instead. If you want your URLs to look like http://example.com/alu-rhab/netti-i/, put Chairs under their respective Brands as children. Now you don’t need the Brand page field. Assuming the latter, finding all Alu-Rhab Chairs is easy: $pages->find("template=chair, parent.name=alu-rhab"). Finding all E-Drive Chairs: $pages->find("template=chair, adapter.name=e-drive"). Finding all E-Drive Brands: $pages->find("template=brand, children.adapter.name=e-drive"). Not sure about finding all Alu-Rhab Adapters, but if it comes to it, you can just get the page ids with SQL and do $pages->findIDs() on them. Or loop over all Adapters and check if there is at least one Alu-Rhab Chair for each one.
  11. I’m guessing header and footer come from prepend and append files. You’ll have to figure out a way to disable those in Ajax requests. For example, if you use $config->prependTemplateFile, just condition that with $config->ajax. //in site/config.php if (!$config->ajax) { $config->prependTemplateFile = 'head.inc'; $config->appendTemplateFile = 'foot.inc'; } You may need to set request.setRequestHeader('X-Requested-With', 'XMLHttpRequest') on your Ajax request for ProcessWire to automatically detect it as Ajax.
  12. Tbh for one-off imports I usually transform the csv (or whatever it is) into PHP or SQL using regex replace in Notepad++ and then just run that. 1500 rows should be nothing, unless they’re absurdly long. edit: nvm, I missed the 1.000.000 figure, but still, writing to the database directly should be an efficient option. In MySQL might want to use LOAD DATA INFILE, but you’ll have to adjust the input data first.
  13. Are you using multiple languages by any chance? There was a thread with a similar problem. Unfortunately not much came of it. I never looked into the underlying cause after I got it working again…
  14. This is because non-superusers aren’t allowed to add children under /processwire/setup/languages. First, because /processwire/setup/languages is of template admin, you would need to open the template settings for admin and check the box “add children” in the access tab. Then you also need to give them permission to create pages of template language, so in the language template, enable access control and check “edit pages” and “create pages”. This isn’t a very nice solution, because you have to change access for all admin pages. I suppose it would be neat if a “lang-add” permission came with the language support module. Alternatively, you can probably write a hook to add a button somewhere that creates a language and bypasses those permission checks.
  15. The ^= operator should do it: $matches = $pages->find("limit=0, title ^= '$letter'");
  16. I’d use FieldtypeTable: https://processwire.com/store/pro-fields/table/ It’s not free, though.
  17. I’ve never used that module, but as far as I understand you’re supposed to just check the required box in the field settings. If you reuse the fields in other templates where they are not required, you can check the box in the template context field settings. Looking at this line it might only work for text fields? Not sure what that’s about, but you can always hook LoginRegister::buildRegisterForm and modify the result yourself.
  18. Hi I’m posting drunk again, and I just want to say, this module is awesome! Thanks a bunch, teppo, you’re the man. I feel much better with this after giving a friend edit permissions on my site ? But also, one thing, does anyone else feel that the diff should always be old to new? Right now when you open the history and click the most recent compare button, it’s the other way around. Wikipedia gives you one radio button for each version to compare and simply doesn’t let you select old to new. It’s kind of awkward and over-engineered, but I think the spirit of not going backwards in time is intuitive.
  19. sort=-date will sort by date from latest to oldest ?
  20. Welcome to PW! You mean this demo site? There is a link to the code on github: https://github.com/ryancramerdesign/skyscrapers2 It’s a couple of years old though. A lot has happened in ProcessWire since then ? Be sure to read through the blog, that’s where all the gems are.
  21. This suggests that the query string does not receive the search string but an object of type WireInputData instead. WireInputData is the class behind the WireInput properties $input->get, $input->post, and so on. $q = $sanitizer->selectorValue($input->get); $input->whitelist('q', $q); Here you put the $input->get object of type WireInputData into a sanitizer method. The method only accepts strings and arrays. Since you gave it neither, it makes a string out of it. I guess this turns the WireInputData object into the string "WireInputData". Not sure what the right fix is. What is “q” supposed to be? It looks more like the query string you want is something like “?larghezze=123&lunghezze=456”. So you should put each of those into a separate whitelist item, eg. $input->whitelist('larghezze', $input->get->selectorValue('larghezze')). ProcessWire’s pagination will automatically put everything from $input->whitelist in the url query string. if($input->whitelist->lunghezze) echo $sanitizer->entities($input->whitelist->lunghezze); if($input->get->lunghezze) echo ($input->get->lunghezze); //delete this! Here you output lunghezze twice, only the first line doesn’t work, because you never put anything into $input->whitelist->lunghezze. Also, the whitelist is stored on the server and you’re expected to only fill it with things you already sanitized, so there is no need to sanitize it again at that point. In the second line you output untrusted unsanitized input straight from the GET request! You should delete that line and the others like it. They’re unnecessary anyway, because you already output the whitelisted stuff above ? Change it to this: echo $input->whitelist->lunghezze; That should be all you need. Then, in search_alimentare.php, add the line I highlighted: if ($input->get->lunghezze) { $lunghezza = $sanitizer->selectorValue($input->get->lunghezze); $input->whitelist->lunghezze = $lunghezza; //add this line for each get variable $tolleranza = ($percentuale / 100) * $lunghezza; $val_up = $lunghezza + $tolleranza; $val_down = $lunghezza - $tolleranza; $selector .= "variante_prodotto.lunghezza>=$val_down, "; $selector .= "variante_prodotto.lunghezza<=$val_up, "; } Sorry I’m being so incoherent ?
  22. That’s a classic, but I’ve been scraping some stuff lately, and I’m not ashamed to say it looks like this and works fine: Regex playlistRegex = new Regex(@"playlist = (\[.*?\]);", RegexOptions.Singleline); Regex titelRegex = new Regex("player-archive-date.*?>(.*?)</div>.*?<span>(.*?)</span>", RegexOptions.Singleline); Regex mp3Regex = new Regex(@"stream_url\s*?=\s*?'(.*?\.mp3)';"); Regex datumRegex = new Regex("datum=([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])"); //… var i = line.IndexOf("/player/xxx/?xxx=xxx"); if (i == -1) continue; c++; line = line.Substring(i); line = line.Substring(0, line.IndexOf("\");'")); line = line.Replace("&", "&"); var datum = datumRegex.Match(line).Groups[1].Value; *cough* Of course, I can make solid assumptions about my input here. The limited problem of stackoverflow’s OP seems somewhat suitable for regex, too, although I’m unsure what they’re trying to accomplish. Find all non-self-closing opening tags?
  23. Guess you’ll want to hook FormBuilderProcessor::savePageDone if FormBuilder hasn’t changed since the beta versions. #24 is the latest one I could dig up, personally. That’s from 2014. But like I said, these are questions for the FormBuilder forum.
  24. @Dean After the creation of the user. So for example after $registerUser->save(); $registerUser->of(true);
×
×
  • Create New...