-
Posts
7,479 -
Joined
-
Last visited
-
Days Won
146
Everything posted by kongondo
-
☁️ Duplicator: Backup and move sites
kongondo replied to flydev's topic in Module/Plugin Development
Something like the below in your module's init() method. You can of course change it to lookup a role or roles or some user IDs [if(!in_array()...]. public function init() { if ($this->permissions->get('duplicator')->id && !$this->user->hasPermission('duplicator')) throw new WirePermissionException($this->_('Duplicator: You have no permission to use this module.')); } -
You can use the 'selector' option. See examples here: And the MSN Docs here.
-
@ethfun, You are missing some code. See a fuller example here (the original CMS Critic case study). What you need: Create your Hook. Have that run as early as possible, preferably in a file that is prepended to templates, for instance _init.php Enable URL segments in home.php. Note that this depends on how you want the URL to be rewritten. If you want to rewrite directly off root, then 'home' is where to go. For instance, if you want /blog/post/ to be rewritten to /post/, you will need to enable URL segments for the template file home.php since that is where ProcessWire will be looking. If you want /blog/posts/post-a/ to be rewritten to /blog/post-a/ you will have to enable URL segments on the template used by blog. The reason you are hitting 404s is that you haven't instructed ProcessWire to accept a URL Segment for that template, in your case, 'home'. Tell ProcessWire what to do when it hits that URL Segment enabled in #2 Mapping the above to code: In these examples, we want to rewrite /posts/post-a/ to /post-a/ 1# Hook: We have this code in _init.php. Any prepended file will do. //wire()->addHookBefore('Page::path', function($event) { @note: this or below, both work. $pages->addHookBefore('Page::path', function($event) { $page = $event->object; if($page->template == 'post') {// template used by 'post-a' // ensure that pages with template 'post' live off the root rather than '/posts/' $event->replace = true; $event->return = "/$page->name/"; } }); 2#. Allow URL segments in the template: Do this in the URLs tab when editing the template. In our case, that is the template 'home'. 3#. Handling URL Segments: in home.php Note that here I haven't taken into account situations where we have more than 1 URL Segment. See CMS Critic case study link above for the full example, specifically under the sub-section /site/templates/home.php. // check if we have a URL Segment if(strlen($input->urlSegment1)) { // render the blog post named in urlSegment1 $name = $sanitizer->pageName($input->urlSegment1); $post = $pages->get("/posts/")->child("name=$name"); if($post->id) echo $post->render();// render the post using its template file else throw new Wire404Exception(); } Just in case you are not sure how to have ProcessWire automatically prepend a file like _init.php, you add this to your /site/config.php/ $config->prependTemplateFile = '_init.php'; It should work as expected, without 404s. ps: I haven't completely digested earlier posts but I am guessing this is what you were after.
-
[Solved] Select, Page Type, Relations, Custom PHP
kongondo replied to swampmusic's topic in General Support
Cool. Did my code work though? Probably the titles won't be changing, but if they will, it is more reliable to check by $page. -
$Item will return an Object whether or not a user was found, hence case 1 will always be true. So, yes, you need to check differently. I like to check for both the object and an ID. Sometimes if you check only ID you might get a PHP error about a 'call to member function on a non-object' blah blah..: $item = $users->get("email=example@processwire.com"); if($item && $item->id) echo $item->name; else echo 'No user found';
-
More admin themes / base admin theme redesign
kongondo replied to cyberderf's topic in Wishlist & Roadmap
What @szabesz said. Best to PM Ryan to tell him you are interested in contributing. -
I think you are right @adrian. I quickly read this and for some reason thought they'd already seen the CMS Critic case study and that didn't suit their needs. I raise that since the same technique is used there. I think stuff like this could make nice short tuts, somewhere outside the forums. There's some nice gems buried deep in the forums.
-
[Solved] Select, Page Type, Relations, Custom PHP
kongondo replied to swampmusic's topic in General Support
Untested. Try this: return $pages->find("template=hotel, country=$page"); Here I am assuming that the page field in the hotel template is named 'country'. -
If it's not grabbing it and the fact that we know there is a value sent, it means it is not the correct implementation. In other words, that is not how you grab it . The session is only temporary (it is deleted immediately after) since you need to be able to store the value of the first date somewhere in order to do the comparison. Below is a different approach. We directly check the values in the $input->post. Seems a bit hackish (?) but it works. Here, we make sure 'erroneous' values are not saved. We revert to older values in the database or blanks if there were no saved dates and show a field error on the first date input. Also note that if no first date is input, the field error will be displayed. You can play around with the if() logic to change the behaviour. public function init() { $this->pages->addHookAfter("InputfieldDatetime::processInput", $this, "hookAfter"); } public function hookAfter(HookEvent $event) { $post = $this->wire('input')->post; // change date string to timestamp $firstdate = strtotime($post->date); $lastdate = strtotime($post->date2); // if first date greater than or equal to last date if($firstdate >= $lastdate) { $field = $event->object; if($field->name == 'date' || $field->name == 'date2') { // get the page being edited $page = $this->wire('modules')->ProcessPageEdit->getPage(); // ensure we don't save 'erroneous' dates; we revert to older saved (db) dates or blank $oldDate = $page->get($field->name); $field->value = $oldDate; // only show error on first date field if($field->name == 'date') $field->error("Last date must be greater than the first date"); } } }
-
@LMD. Thanks for reporting. I haven't been able to find a suitable solution for this. The issue is the quotes are tripping up the input value. Have a look at the markup in page source; you will see class="" is output but the HTML breaks since we have something like value="<i class="fa fa-home">". For now (and for any complex menus), I suggest you use the approach posted here, whereby you will have total control over your menu items' structure and styling.
-
Repeater rows pages do not have a title field ....,hence you not getting anything back. If you did the below, you should see something like ' 1482226910-677-1 ' $test = $pages->get(1156); echo $test->name;
-
get already assumes an include=all (that includes hidden). http://processwire.com/api/selectors/#access_control
-
[SOLVED] Can't add image in certain situation
kongondo replied to Harmen's topic in Module/Plugin Development
Cache....or staring at a screen for too long can do that to you sometimes .- 15 replies
-
- 1
-
- importpagesprestashop
- field
-
(and 2 more)
Tagged with:
-
@adrian, page save might result in emails being sent every time that page is edited. I suggest 'Pages:added' instead.
-
Are these users in the front or backend? If the backend, users already have email addresses. If you want to automate anything, the normal way is to either user cron or an autoload module (using Hooks). In your case, the latter is a good fit. You would want to Hook into 'Pages:added' (rather than sending emails every time the page is saved)
-
[SOLVED] Can't add image in certain situation
kongondo replied to Harmen's topic in Module/Plugin Development
OK. See @adrian post above you as well. Seems you posted at the same time.- 15 replies
-
- importpagesprestashop
- field
-
(and 2 more)
Tagged with:
-
@xavier. Glad it worked. Since a couple of ProcessWire versions back (I can't remember how far back, but since 2.7 at least), pages have a property 'published'. So: echo $page->published;// outputs the date when this page was published. Oh, am not sure you've been properly welcomed. If not, welcome to the forums .
-
[SOLVED] Can't add image in certain situation
kongondo replied to Harmen's topic in Module/Plugin Development
That is weird. Hmm, maybe some caching issues. All the same, it is good to check if $product_pages actually exists.- 15 replies
-
- importpagesprestashop
- field
-
(and 2 more)
Tagged with:
-
[SOLVED] Can't add image in certain situation
kongondo replied to Harmen's topic in Module/Plugin Development
Actually I suspected that but forgot to mention it. Since you are in a foreach loop, it means that this code does not always get a page, i.e. some of the pages don't exist. $product_pages = wire("pages")->get("productid=$id_product"); //get the correct page so the images are placed in the correct product page Change that to: // get the correct page so the images are placed in the correct product page $product_pages = $this->wire("pages")->get("productid=$id_product"); if(!$product_pages) continue; I assume you've previously sanitised the values of $id_product. Are they integers or strings? What type of field is productid?- 15 replies
-
- importpagesprestashop
- field
-
(and 2 more)
Tagged with:
-
[SOLVED] Can't add image in certain situation
kongondo replied to Harmen's topic in Module/Plugin Development
So, my question still remains. Maybe confirm with some simple debugging of what this returns: $imgfield = $product_pages->images_product; echo gettype($imgfield); Since you are getting the 'non-object' error, I'm pretty sure that will echo NULL.- 15 replies
-
- importpagesprestashop
- field
-
(and 2 more)
Tagged with:
-
[SOLVED] Can't add image in certain situation
kongondo replied to Harmen's topic in Module/Plugin Development
Too early to give up maybe . What is ranking in this case? What I meant specifically is are you sure $imgfield is an Image object? Is ranking an Image object or some other field on the page? @note: I edited my post above about output formatting; don't know if you saw that.- 15 replies
-
- importpagesprestashop
- field
-
(and 2 more)
Tagged with:
-
[SOLVED] Can't add image in certain situation
kongondo replied to Harmen's topic in Module/Plugin Development
Nothing jumps out at me. Things to confirm: $imgfield = $product_pages->images_product; Are you sure that returns an Object and not Null? Some other comments, by the ways... Is this by your design or by necessity (i.e. Prestashop demands that). Normally, especially in cases where several products can share one or more categories, you want to have categories separated from the products (i..e not as their children). // ensure output formatting is off $product_pages->of(false); This is not necessary here. Output formatting is always off in a module context. if (!$parent->hasChildren()) { } That may not be very foolproof (could children have been manually deleted?). You can check using the module version instead, i.e. if version is less than x, do this, else do that. I can't find the exact syntax for it now but will edit this post later if I do. Edit: grep version_compare under /wire/modules/ for more examples. Here's an example from a third-party module, changelog. Edit 2: Arrgh. Scrap that. That's not it really; Hopefully someone will chime in. You should be able to compare versions of your modules programmatically though; I'm sure of it.- 15 replies
-
- 1
-
- importpagesprestashop
- field
-
(and 2 more)
Tagged with:
-
Could you explain a use case for this? Other than that, not sure if you know that there's a module that can auto-publish/unpublish at specified dates. There's also a published date property for pages. I don't know if those cover your needs, but good to know.
-
Module Module: RuntimeMarkup Fieldtype & Inputfield
kongondo replied to kongondo's topic in Modules/Plugins
@Sérgio. Excellent! Thanks for sharing! -
Played a bit more with this. The following works for me. I am not sure if it is foolproof and/or if there are better approaches. Please note: From what I can tell, when saving a page, inputs (fields) will be sent in the order they appear in a template. date1 refers to the first date and date2 to the last date. We need to temporarily store the value of date1 in order to later compare it to date2. I stored the value in a session. You could do it differently, e.g. cache it. The code doesn't prevent a save of the 2 date fields. You can do that if you wish. This code is necessarily verbose in places; just to make things clear. public function init() { $this->pages->addHookAfter("InputfieldDatetime::processInput", $this, "hookAfter"); } public function hookAfter(HookEvent $event) { $field = $event->object; if($field->name == 'date1' || $field->name == 'date2') { // @note: from what I can tell, inputs are sent in the order of the fields in the page // ...so, date1 will be hooked into before date2 $date1 = '';// first date $date2 = '';// last date $session = $this->wire('session'); // save date1 to session; we'll retrieve it to compare against date2 if($field->name == 'date1') { $date1 = $field->value; $session->set('date1', $date1); } elseif($field->name == 'date2') { $date2 = $field->value; $date1 = $session->get('date1'); // compare the first and last dates if($date1 >= $date2) $field->error("Last date must be greater than the first date"); //else $this->message("Those dates are fine matey!");// @note: for testing only // delete the temporary session date1 $session->remove('date1'); } } }