-
Posts
13 -
Joined
-
Last visited
Profile Information
-
Gender
Male
-
Location
Hong Kong
Recent Profile Visitors
1,483 profile views
lenno's Achievements
-
Programatically adding a page to FieldtypePage field
lenno replied to lenno's topic in General Support
That did the trick, thanks a lot Alxndre! -
Dear all, I have a presumably simple question, which I simply can't find the answer for. I need to programatically add a page to a FieldtypePage field. I tried the following: $page->a_field_of_fieldtype_page->add($anotherPage); but without success. Can anybody help?
-
lenno started following Unicode characters in selector and Programatically adding a page to FieldtypePage field
-
Hi, I just wanted to point out that we recently ran into the same issue when using Cloudflare's CDN. Weird is the fact that we were able to reproduce the logout issue with a specific user when editing a specific page. Every time the user clicked "Save" for this specific page, she was kicked out. I assume that at this point the IP address changed - from Cloudflare to the actual user's IP address or the other way around. The error is the same as in the quoted post above: User 'somebody' - Error: Session fingerprint changed (IP address or useragent) (IP: 162.158.XX.XX) The IP address is - just as above - in the Cloudflare range: https://www.cloudflare.com/ips/ We are currently working around this issue by using a different Domain name to access the ProcessWire backend. This domain is not routed through Cloudflare and the approach works fine for us so far. I can provide further information if required.
-
Well, I guess I could have figured that out by myself. Thanks a lot BitPoet! The ProcessWire support here in the forum is really great.
-
Thanks BitPoet I will try that tomorrow and report back! Edit: So that was unfortunate, for some reason I had some trailing spaces in the chinese search query that messed everything up. Sorry for the confusion. I am getting the expected results now when using %=. However, ~= still seems to return zero results. Could you try running your above code with the ~= selector? From my understanding, it should return the same results. But in my case, it returns nothing.
-
Hi, Our ProcessWire website has a simple site search, which is implemented following the ProcessWire search demo code. It uses the %= operator to get broader results. $queryResults = $this->pages->find('title%=应用'); // return everything The problem: It will return ALL pages. The reason is probably that %= uses SQL LIKE and SQL needs to be told that the search string contains unicode characters by adding 'N' as the prefix. At least this is what I think I learned from: http://stackoverflow.com/questions/22156413/how-to-select-rows-with-chinese-japanese-characters I tried this, but I still get everything: $queryResults = $this->pages->find("title%=N'应用'"); // return everything I also tried encoding my chinese text: $queryResults = $this->pages->find('title%=\u5e94\u7528'); // no results But now I get zero results. And by the way: The ~= operator also returns zero results: $queryResults = $this->pages->find('title~=\u5e94\u7528'); // no results $queryResults = $this->pages->find('title~=应用'); // also no results I guess I could build my own SQL queries, but we have already build a very nice customized search based on ProcessWire selectors and would really like to stick with them. Any idea how to solve this? Many thanks, René
-
Released: PadLoper (commercial eCommerce platform for ProcessWire)
lenno replied to apeisa's topic in Modules/Plugins
Thanks for the reply Antti. This is weird. The problem seems to have disappeared and I don't know why. The only thing I did was renaming the Padloper directory in .../site/modules from 'PadLoper' to 'Padloper' since the name caused problems in PadLoper.module Line 24: include_once(wire('config')->paths->siteModules . "Padloper/PadOrder.php"); Now my other problem has disappeared as well. Anyway, thanks for the help! -
Released: PadLoper (commercial eCommerce platform for ProcessWire)
lenno replied to apeisa's topic in Modules/Plugins
Hi, we just bought the Padloper module. We are having problems with the redirects when adding an item to the cart or updating the card. Our shop is running on a sub domain: bla.something.com Unfortunately all actions redirect to something.com (omitting the sub-domain). The problem seems to be that $page->httpUrl, which is used by Padloper, returns the URL without the sub-domain, whereas $page->url does. E.g in PadOrderProcess.php (line 230): public function preparePayment() { $order = $this->getOrder(); $payment = $this->getPaymentModule(); $amount = $order->getTotalAmount(); $amount = (int) round($amount * 100); $orderId = $order->get("id"); $payment->setId($orderId); $payment->setCurrency($this->modules->get("PadCart")->currency); $url = $this->page->httpUrl; $payment->setProcessUrl($url . "process/" . $orderId . "/"); $payment->setFailureUrl($url . "fail/"); $payment->setCancelUrl($url . "cancel/"); [...] Can this be fixed or can I easily fix this myself? Thanks, René -
Yes Matjazp, I figured out later that the modification of the argument did not create the problem, but that my selector just didn't seem to have returned any results, which lead to the error message. Hooking in after Pages->find and removing all the results that I don't want seems to be the better approach. Other suggestions welcome! Otherwise I'll mark the question as answered in a few days.
-
Thanks for the answer Nicolas, maybe i should have added some more information: Users will usually be guests, but it should also work for users which are logged in in the future. The third module you posted looks pretty similar to what I am doing right now, it also hooks into Page::viewable. This works perfectly when accessing a page, resulting in a 404 (which is fine), but the page is still listed when doing e.g. $homepage->children() or $homepage->find(). I want the page to dissapear just as for a user who does not have view permissions. I tried another hook: $this->addHookBefore('ProcessPageList::find', $this, 'checkPage'); but it does never seem to be called. I am probably doing something wrong here Edit: Just tried something else: public function init() { $this->addHookBefore('Pages::find', $this, 'checkPage'); } public function checkPage($event) { $event->arguments(0, $event->arguments(0) . ", page_restricted=2"); } So I tried to extend the selector for pages to always add 'page_restricted=2' at the end. But it gives me the following error: Error: Exception: You do not have permission to execute this module - ProcessPageView (in [...]\wire\core\Modules.php line 1022) #0 [...]\wire\core\Modules.php(940): Modules->getModule('ProcessPageView') #1 [...]\index.php(233): Modules->get('ProcessPageView') #2 {main} This error message was shown because site is in debug mode ($config->debug = true; in /site/config.php). Error has been logged. I think I am doing something terribly wrong here. Edit2: Well, I found a solution that seems to work: public function init() { $this->addHookAfter('Pages::find', $this, 'checkPage'); } public function checkPage($event) { $url = $_SERVER["HTTP_HOST"]; $isProbes = strpos($url,'probes') !== false; $pages = $event->return; foreach ($pages as $page) { $x = $page->page_restricted; if ($x) { if (($x->id === 2 && $isProbes) || ($x->id === 3 && !$isProbes)) { $pages->remove($page) ; } } } } If anyone has a better idea how to solve it, I would be glad to hear it.
-
Dear all, first of all - thank you to Ryan and everyone else involved in making this awesome CMS. I absolutely love it! I want to make parts of my page visible depending on via which sub-domain the page is accessed (which both point to the same ProcessWire installation). E.g. boom.website.com and whoop.website.com should result in certain pages being accessible/restricted. I tried doing this by adding a global (= on every template) field to processwire called 'page_restricted'. The field is of type 'Option'. I now created a hook that intercepts Page::viewable. The approach is similar to what is discussed here: https://processwire.com/talk/topic/5174-define-permissions-by-category/ // Module with autoload enabled [...] public function init() { $this->addHookAfter('Page::viewable', $this, 'checkPage'); } public function checkPage($event) { if(!$event->return) return; // if it was already determined page is not viewable $page = $event->object; if(!$page->page_restricted) return; // abort if the page has no page_restricted field $restriction = $page->page_restricted->id; if (!$restriction || $restriction === 1) return; // page_restricted has no value or is set to 1=All $url= $_SERVER["HTTP_HOST"]; $isBoom = strpos($url,'boom') !== false; if ($isBoom && ($restriction === 2)) { $event->return = true; } else { $event->return = false; } } This has the desired effect that Processwire shows a 404 page in case the page_restricted does not have the value 1=All or 2=Boom. My problem now is that the regarding pages still show up on my search ($pages->find()) and listings ($page->children()). How can I make this happen? I tried adding another hook: $this->addHookAfter('Page::listable', $this, 'checkPage'); Unfortunately that hook is never called for some reason. Am I not doing it right? In case someone has a better/more elegant approach to reach the desired effect (show/hide pages depending on domain), please let me know! Thanks in advance. René
-
Dear all, I know this post is old, but in case someone else stumbles across it, here is a modified version of Soma's getLabel() hook which takes an optional second parameter to decide if you want a fallback to the default language if no localized name of that field is available: $fields->addHook("getLabel", null, "getLabelLang"); function getLabelLang($event){ $field = $event->arguments(0); $fallback = $event->arguments(1) === null ? true : $event->arguments(1); $lang = wire("user")->language->isDefault() ? "" : wire("user")->language->id; $field = wire("fields")->get($field); $caption = $field->get("label$lang"); $caption = (count($caption) === 0 && $fallback) ? $field->get("label") : $caption; $event->return = $caption; } Usage: $fields->getLabel("labelName"); -> returns the localized label name with fallback to default language. $fields->getLabel("labelName", false); -> returns the label name without fallback to default language. I am not very good with php, any code improvements welcome!