Jump to content

suntrop

Members
  • Posts

    316
  • Joined

Everything posted by suntrop

  1. I'd like to add a button next to PW's built in Save button on the edit page to clone a page. I can't use the Clone module from PW, because there need to be some other code be executed. I had seen some related posts here, but my code doesn't work properly. When I click the button, the page will get cloned 6 times instead of only once. The page has a PageTable field on it with 5 sub-pages. Perhaps the hook gets executed for every child? It doesn't make any difference if I remove the $copy->save() action. Saved in /site/init.php wire()->addHookBefore('ProcessPageEdit::processInput', NULL, 'cloneAsOrder'); function cloneAsOrder($event) { $p = $event->object->getPage(); $event->replace = true; if ( wire()->input->post('submit_clone_as_order') ) { $parent = wire()->pages->get('/crm/accounting/order/'); $copy = wire()->pages->clone($p, $parent); // $copy->parent = '/crm/accounting/order/'; $copy->template = 'order'; $copy->title = 'UNFINISHED-'; $copy->name = 'unfinished-r327' . date('Y-m-d-h:i:s'); // $copy->removeStatus("published"); // $copy->addStatus("unpublished"); $copy->save(); // wire()->message('Copy created:' . $p->title . ' » <a href="' . $copy->url . '">' . $copy->title . '"</a>'); } } And … is it possible to clone a page without publishing it? I will need (later) a hook that hooks into the publishing method and save an order number. That number will come from a 'next doc number' and gets incremented automatically.
  2. JFYI — That loading screen won’t disappear on my iPad (iOS 11) Backend looks like a hell lot of work. ?
  3. Yes, I have. I would have to fork and modify Map Maker, because I need address in separate fields and with more data. And I need them to be manageable by PHP … I guess Map Maker counts on the JS API. And as wbmnfktr says, I really just need the lat/long … nothing more. I just figured out, where the conversion takes place. I put this into my wwwroot <?php include 'index.php'; // setlocale(LC_NUMERIC, 'C'); $json = json_decode( '{"test": 48.8555648}' , true); var_dump($json); die(); The code prints: array(1) { ["test"]=> float(48,8555648) } When I don't include the PW bootstrap file (index.php) it prints: array(1) { ["test"]=> float(48.8555648) } When I include the index.php and uncomment the setlocale() it prints: array(1) { ["test"]=> float(48.8555648) } I don't think it has to do with the Textareas module, but how the locale is set in PW. I couldn't find much about setlocale(LC_NUMERIC, 'C') but it seems the C sets numeric values to C++ default type (e.g. 3.14 not 3,14). https://processwire.com/talk/topic/4123-decimal-point-changed-to-in-base-of-setlocale/?do=findComment&comment=142861 It doesn't work if I put the setlocale() into my /site/config.php or /site/template/_init.php However, it looks more like a bug and not like "this is how it should work"
  4. Sure! I have something like a store locator and need to store the latitude and longitude for each place. Therefore I created a field named "latlong" This field is of type "Textareas" and has two "Text" sub-fields "lat" and "long". When I save a page the fields contents (the coordinates) are getting converted, the point turns into a comma This happens since I installed the German language pack. Prior saved locations don't have a comma saved. While the default German decimal separator is a comma, this conversion makes things very complicated. That is my hook in /site/ready.php $pages->addHookBefore('saveReady', function($event) { $page = $event->arguments[0]; if($page->template == 'location') { if ( empty($page->street) || empty($page->city) ) { return; } // Get address $address = $page->street . ', ' . $page->zip . ' ' . $page->city . ', ' . $page->country; // Get JSON results from this request $geo = file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($address) . '&sensor=false'); $geo = json_decode($geo, true); if ($geo['status'] == 'OK') { $page->latlong->lat = $geo['results'][0]['geometry']['location']['lat']; $page->latlong->long = $geo['results'][0]['geometry']['location']['lng']; $this->message('Saved for: ' . $geo['results'][0]['formatted_address']); } else { $this->error('Error msg...'); } } });
  5. Does anybody know how to NOT convert these numbers ?
  6. Thanks for pointing to DC, sometimes it is ok to have it And that is some quiet simple code snippet ! Thanks again.
  7. Hi gmclelland. Thanks. Yes, that would be a way I would go. Maybe it's just me, but I would prefer not having an "invalid" URL – although if implemented as 301 it wouldn't be indexed by Google (but nonetheless doesn't count as a good link). And as I said, I really need to learn more about hooking into PW
  8. Sometimes I need pages in the site tree that are basically just a reference to another page – to redirect to the original page or display the same content under the new page url. I was surprised I couldn't find anything like that in the forum or as a module already. However, there is a new module by @Robin S but not exactly what I need. Example Home News Press Newsroom Media Services About Newsroom (virtual page for /news/newsroom/) Contact Example I: The page /about/newsroom/ should act as /news/newsroom/ – so, wehen I loop all pages for a sitemap both pages should have the URL /news/newsroom/. Example II: Another example (not often used) would be tu display the exact same content on /about/newsroom/ – although the page itself has no content on its own. Those examples don't have much in common, but they are just virtual or fake pages in the site tree. While the second one should be an easy task with wireRenderFile(), the first example isn't quite obvious to me. I think I have to use hooks and I have no idea where to start. I really appreciate you guys come up with a solution for everything, but I need to learn this myself So just some hints to start would be great! Do I put the code into a module or some of the _init.php, ready.php etc. files? Or do I have to use a template file (e.g. virtual-page.php)? When I look into Captain Hook – how do I find the appropriate point to hook into? (/wire/core/ Page.php and loaded()?) Do I need to create/manipulate each field separately (path, title, summary)? Sorry for the long read
  9. HI Robin. Thanks for checking. But I can't get this to work, double checked my wording. I am using PW 3.0.78. Perhaps we are using other "checkbox modules"? How can I tell what module this checkbox field is exactly? I am pretty sure I have not installed any module like this … but possibly I am wrong
  10. I have got a Textareas field (latlong) with two Text fields (lat and long). I query Google Maps for the coordinates and use a hook to save both fields. The problem is, after I installed the German language pack those fields are saved with a comma as decimal separator. But that doesn't work with Google Maps, because it needs 50.43578373748 and not 50,43578373748. As I remember Float can only take up to 7 points after the decimal point – so I can't just change it from Text to Float. Currently I just str_replace the decimal to a point in the template for my JSON fiel. But I was wondering if thee is a way I can tell PW to not convert the point to decimal – regardless of of the language.
  11. I thought it is possible within one selector … and I only have to rewrite my selector. My other solution looks better $page->children('highlight=1, sort=-chiffre')->add( $page->children('highlight=0, sort=-chiffre') )
  12. I know. The problem is it doesn't seem to work with checkboxes.
  13. Nobody loves my riddles It should read … "The 'checkbox' field is a default checkbox field, no special module" <?php foreach ($page->children('sort=-chiffre') as $child): ?> <div class="job <?= $child->highlight ? 'hightlight' : 'default' ?>">Chiffre <?= $child->chiffre ?> | <?= $child-title ?> – <?= $child->body ?></div> <?php endofreach ?> … will render … <div class="jobs"> <div class="job">Chiffre 734 | Job Title – Job Description …</div> <div class="job">Chiffre 732 | Job Title – Job Description …</div> <div class="job highlight">Chiffre 722 | Job Title – Job Description …</div> <div class="job">Chiffre 720 | Job Title – Job Description …</div> <div class="job">Chiffre 718 | Job Title – Job Description …</div> <div class="job highlight">Chiffre 605 | Job Title – Job Description …</div> </div> But what I need … <div class="jobs"> <div class="job highlight">Chiffre 605 | Job Title – Job Description …</div> <div class="job highlight">Chiffre 722 | Job Title – Job Description …</div> <div class="job">Chiffre 734 | Job Title – Job Description …</div> <div class="job">Chiffre 732 | Job Title – Job Description …</div> <div class="job">Chiffre 720 | Job Title – Job Description …</div> <div class="job">Chiffre 718 | Job Title – Job Description …</div> </div> … the pages with a checked "highlight" (the checkbox field) should be on top and ordered by the chiffre. The other pages should follow and ordered by chiffre too.
  14. Hi all! I want to sort child-pages by two fields but I don't know if it is possible within one selector or if I have to make two separate queries <?php foreach ($page->children('sort=checkbox, sort=-number') as $child): ?> I want to keep 'checked' pages on top and sort them and all following by the 'number' field. The 'checkbox' field is a
  15. I had added the title filed to the roles template. And I found I can configure the roles module to display other fields in the listing under Access > Roles – but currently I found no way to display the title instead the name on the user profile pages.
  16. On the user-edit page for example
  17. I would like to use the label for roles, as the label is used for templates. My role names are more technical and in englisch, but I would like to give them a more readable and lengthier name. When I edit the "role" template there is no field "templateLabel" I can add.
  18. I thought there is some hidden config and an easy step. Seems there is no option at all https://github.com/processwire/processwire/blob/master/wire/modules/Process/ProcessPageEdit/ProcessPageEdit.module#L978 @adrian I am using labels, because template files are in Englisch, but my clients prefer a more eligible, German name. Will have a look tomorrow
  19. Yes, I am talking about the settings tab, so after the page is saved or for existing pages. The dropdown list is about 20 entries long and it is pretty hard to find the exact template you're looking for, because there is naturally no order. That is bad usability and I want it to sort in an alphabetically order to make it easier finding a template. The exact same use case goes for excluding templates that make no sense for the editor (like templates just for settings or "admin" pages, etc.).
  20. On the Settings-Tab you can select the template of a page. Two questions: How do I change the order of them? Currently it looks very messy and I would like to sort it alphabetically How do I exclude certain templates from this list? I couldn't find a system field for it and have looked at other field configs, but noting helped. I've got some pages I don't want my client to be selectable. I have set "Can this template be used for new pages?" to no, but that doesn't work.
  21. Well, ok ... Thanks. But I was asking specifically for Procache
  22. Hi. I have some questions about ProCache. Is it possible to exclude certain pages (by URL, template, page?) from being cached? … or in reverse – just make pages within a section of my website being cached? Is there something I need to change in my templates or is it more like a "click-and-go" plugin? (basic caching, no assets manipulation) What about pages with dynamic generated content (like flash messages, integrated RSS feeds, number of items in cart, etc.) I have two sites in mind, and one is a shop. So I am wondering if ProCache is suitable for it. If a user puts something into his cart, the cached page can't be the same static HTML page for the other users.
  23. Thanks for your quick help. Since I need to import the CSV via API, I wouldn't just trust the backend/JS. Other parts (like password, I think) don't match the UI rules. And I need to create other related pages and more in the same run. Anyway, your module is on my list Thanks!
  24. I need to import a list of users my client sends me. He wants to know what rules make a valid username. Sounds easy, but I need to make it bulletproof, when I tell my client, because he sends a lot of print letters with those usernames When I look at the name (aka username) filed it says: Any combination of letters (a-z), numbers (0-9), dashes or underscores (no spaces). As I think, those are pagenames and thus the sanitizer->pageName() is applied? This one says something different: Page names by default support lowercase ASCII letters, digits, underscore, hyphen and period. Usernames with periods apparently are ok. ASCII letters, however, sounds a bit ambiguous. @ or $ is in some manner a letter too. Perhaps I am wrong, but haven't studied english linguistic And I think it only counts for the 128-ASCII table, not the extended one. Seriously, I don't want to make it more complicated than it needs to be, but the docs made me think of it. Thanks!
×
×
  • Create New...