![](http://processwire-forums.s3.us-west-2.amazonaws.com/set_resources_6/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
suntrop
Members-
Posts
319 -
Joined
Everything posted by suntrop
-
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.
-
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!
-
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!
-
HI all. I recently built a web shop with PW and it works pretty good. I love the simplicity and freedom working with templates and how stuff works and the client loves the back-end. However, the part I am unhappy about is the site search. Beside the API selectors work fine, it seems not be suitable for that kind of search. People search for words, phrases, they mix spaces, hyphens etc., add measurements … so a lot of searches end up in 0 results. I know of the ElasticSearch module and other external things like Sphider, Google CSE, algolia.com … but some are quite complicated and limit my control or bring google's ads on the site So perhaps you have any improvements, ideas how to get a better search engine on my website. Most problems come from spelling issues, singular/plural, hyphenated words/searches. <?php $vars['q'] = $q; $input->whitelist('q', $q); $q = $sanitizer->selectorValue($q); // 1. // Item Number // If there is a number in it that matches a product's numbers, redirect to product directly $q_numeric = preg_replace('/\D/', '', $q); $prodcut_item_number = $pages->get("template=product|product_variation, product_item_number=$q_numeric"); if ( $prodcut_item_number->id && $prodcut_item_number->template == 'product') { $session->redirect($prodcut_item_number->url); die(); } elseif ( $prodcut_item_number->id && $prodcut_item_number->template == 'product_variation') { // variations are saved as sub-pages, but have no public web-page $session->redirect($prodcut_item_number->parent->url); die(); } // 2. // Product title and description // Search the product's title, headline and summary $matches = $pages->find("title|headline|summary~=$q, template=product, limit=50"); // 3. // Categories // If search is a category, append all its products $categories = $pages->find("title%=$q, template=category, limit=10"); if ( count($categories) ) { $category_ids = $categories->each('id'); $category_ids = implode('|', $category_ids); $append_products_from_category = $pages->find("template=product, has_parent={$cat_ids}"); $matches->append($append_products_from_category); } // 4. // Split search phrase // If nothing above matches, try each word separatly if( !count($matches) ) { $q_separate = preg_replace('/\PL/u', ' ', $q); // "Remove" everything but letters $q_separate = preg_split('/\s+/', $q_separate); foreach ($q_separate as $q_word) { if ( $q_word != '' && strlen($q_word) > 4 ) { $append_products_separate = $pages->find("title|headline|summary~=$q_word, template=product, limit=50"); $matches->append($append_products_separate); } } } // PLEASE NOTE – this doesn't come from my production code, but is a current idea I have // There is no highly need of weighting results and order best results on top, because there are just a few products for each keyword :-)
-
That's right, a regular array will survive the redirect.
-
Hi all. Perhaps this is just my fault, but I can't get behind it :-( When I store an array in a $session and want to read its contents – after a $session->redirect() – it is NULL by var_dump() If I use the exact same code and just store a string or a Page ID the output is correct. // file-1, product page $last_add_to_cart['product'] = $selected_product; $last_add_to_cart['quantity'] = $selected_product_quantity; $session->last_add_to_cart = $last_add_to_cart; $session->redirect('/warenkorb/'); // file-2, cart var_dump($session->last_add_to_cart); // is NULL Strangely this works // file-1, product page $last_add_to_cart['product'] = $selected_product->id; #$last_add_to_cart['quantity'] = $selected_product_quantity; $session->last_add_to_cart = $last_add_to_cart; $session->redirect('/warenkorb/'); // file-2, cart var_dump($session->last_add_to_cart); // is 1234 EDIT: When I var_dump the $session before the redirect everything is ok
-
Thanks guys! I used Batcher before, but I really have to have a closer look at Adrian's module.
-
Hi all All I could find was the opposite of what I need, how to unpublish a page via API. But I need to publish 500 pages. Those pages are children of/inside a PageTable field … don't know if this matters. Anyhow, I tried to loop through the child pages and publish them. But even one doesn't work … it just stays unpublished // Pagae 2603 is my page with 500 unpublished children if ($page->id == 2603) { $fcp = $page->children('status=unpublished')->first(); $fcp->removeStatus(Page::statusUnpublished); $fcp->save; // foreach ($page->children as $c) { // … // } } There is no such method like publishPage?
-
Robin, thanks for that! Indeed this one works differently. It feels a bit off the road using the wire('pages') instead of wire('users), but that would work as expected. But again, this is quite against the "everything is a page" mantra in PW. However, I will include a status!=unpublished in the selectors. Thanks again!
-
I am wondering why this one <?php $tsubscribers = wire('users')->find('template=user'); foreach ($tsubscribers as $ts) { echo $ts->email . '<br>'; } ?> will include unpublished users as well. The docs say https://processwire.com/api/selectors/#access_control Pages with hidden or unpublished status will not appear in the results from database-querying selectors that can return multiple pages (i.e. functions that return the PageArray type). For instance $pages->find("..."), $page->children(), etc. The site is running PW 2.7.2 … is this only new to PW 3? I had all users unpublished and see them as unpublished in the back-end. But when selecting users via API the unpublished are included as well. I have to add status!=unpublished to opt them out.
-
I would like to handle Server-Error 410 (gone) the same way like PW handles 404. When I add to my .htaccess "ErrorDocument 410 /index.php" and create a /http410/ in the back-end that doesn't seem to be enough. While I could point it directly to /http410/ I am wondering if the other way is possible as well?
-
The last days two new sites went online and both got a SSL certificate installed. But one has a HTTP problem, although both are configured the same (seem to be). When I run curl -I -L https://www.example.com/ (http://bit.ly/2pOdjGj) it gets redirected to itself again and again. I had a HTTPS redirect in my .htaaccess but have removed it. The home template was configured to use only HTTPS but is now configured to accept both. If I change that to HTTP only, I get and error. The origin must come from PW, because all files not processed by PW don't have the redirect problem. I had a look at the /site/assets/cache/ folder but don't know what to delete. And there is a cache table in the DB as well. Don't know either if I can just delete its entries. Apache 2.4.18 PHP 7.0.11 PW 3.0.42 No dedicated cache installed, no cache activated in PW
-
-
Thanks both of you! Where do I find that option? I am using 3.0.42 and can't find that option.
-
I have configured some template to be not movable, so the editors can't move them around. But actually I need to move them with the API. Is there some way to avoid the error Pages using template 'order' are not moveable
-
I included the PW index.php in a script file and need to return a full URL of pages (autocomplete Ajax response) However, the file is located on another host and I get the wrong URL ajax.example.com/public/search_autocomplete.php I am wondering why ->url and ->httpUrl is /public/found/page/ or ajax.example.com/public/found/page/ instead of /found/page/ or example.com/found/page/ … and how to get the proper URL. Do I need to set the $config->httpHost again or something else? <?php namespace ProcessWire; header('Access-Control-Allow-Origin: *'); error_reporting(-1); include '../../../www/index.php'; $q = wire('sanitizer')->selectorValue( wire('input')->get('q') ); $results = wire('pages')->find('title%=' . $q . ', template=basic-page, limit=10'); $array['query'] = $q; foreach ($results as $result) { $array['suggestions'][] = ['value' => $result->title, 'data' => $result->url]; } echo json_encode($array);
-
Set page default values with hook in admin.php
suntrop replied to suntrop's topic in General Support
Thanks for your quick response! I looked in Captain Hook and saw … #1280: public function ___added(Page $page) … but didn't noticed it was in the Pages section. Had just seen Page $page. Anyhow, the code above works great. I only need it for pages created in the CMS backend. I guess you mean front-end pages (template), right? -
Hi all. I have to set default values for some fields (page select and text fields) on my page. I think the /site/templates/admin.php is the appropriate place? But I can't get anything to work from there. That is my current code, that looks to me like it should work. But it doesn't wire()->addHookAfter('Page::added', function($event) { wire('page')->setAndSave('page_select_field', 1042); wire('page')->setAndSave('text_field', 'Default Value'); }); require($config->paths->adminTemplates . 'controller.php');
-
Yeah … maybe I'll give it a try. Had just a short look into the code, don't know if I understand everything And that could be the bottle neck, if I need to update it somewhen
-
Ha ha guessing isn't a good habit when programming. However, I just checked and this code will have my system user as created and modified $c->created_users_id = $this->systemUser; $c->modified_users_id = $this->systemUser; $c->save(array('quiet' => true));
-
Thanks guys! created_users_id works great … so I guess modified_users_id will work as well
-
I cam across this issue a long time ago. When I create a page via API that page is always "created by" the guest user. I tried to add a dedicated user or the admin, but had no luck. Perhaps that field is – like created date – not API-able. $c = new Page(); $c->createdUser = wire('users')->get('name=admin'); Although I know that some fields won't be editable via API, I think this one is really confusing. For example, the first time I noticed this, was a client of mine, who nervously reported there is a protected page created by "someone from outside". It took me a while to get behind it :-D
-
Thanks Wanze! I had a look at it, but I think I will develop something on my own. I am always in worries when using 3rd party plugins for a vital part of my website Especially if it is not "easily" exchangeable.
-
Thanks Can. I knew that already. I was wondering how it works. The brief description in the config is a little less to know about it. I need to go a step deeper I think, because the files I am going to protect are for specific users only (billing PDF)