-
Posts
6,808 -
Joined
-
Last visited
-
Days Won
159
Everything posted by Soma
-
Thanks Oliver for sharing, just I can't really try it out for various reasons. I'm really digging people share their "MVC" approaches, but with this one more, it would be around 5 different ones now around. I'm not sure what to think about the impact on PW new and old users, support etc as it will split and create burdens for one to help someone using x-mvc approach. I have nothing against many ways to setup PW projects and while that's a strength it may even more is a weakness at the same time with its consequences. Really not against you and your approach, it just turns out by chance that I write this here. I'm not sure its worth of discussion. Wouldn't it be better to settle on one "MVC" ish setup that PW maybe even supports, it could help to keep focus on it and maybe even have official docs for it. Often it doesn't help telling a dev hey look there's this this and this but you can also use this and this, but that is not for PW 2.5 while that is only for php 5.5 and the other you can't use if you use multisite and those are not multilanguageable. Hard for me to explain well but I think one get the idea where I'm heading.
-
minor update 2.1.5 added external links, if available, below description to project (github), direct download and forum support thread.
-
Yeah if there was a 48hour day I already started some months ago trying owzim bash script, but didn't finish. The idea was that each new version will give a new sheet. If someone wants to contribute and have time just let us know.
-
Do we really need two version of the same module?
-
You can with a autoload module in the init() method, use the wire("config")->ajax and maybe check for post values etc and return output then exit() if(wire("config")->ajax){ if(wire("input")->post->something){ echo "hello"; exit; } }
-
@ivan not sure I follow $allDescendantsOfEvents = $pages->get('/events/')->find(""); Too many code examples in this thread that makes no sense. You don't want to return ALL descendants to then filter them again by parent etc. In my cases this could return 100k pages it then filters 100 pages from that...
-
The function seems a little overkill, but why not. After all to get the grandchildren you only need something like $grandchildren = $pages->find("parent=$page->children, sort=-modified, limit=20"); That's already a function right there. One can of course wrap it into a function and play around with it.
-
Version two would then be <?php class SaveShortUrl extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Rewrite field after save', 'version' => 2, 'summary' => 'An example module used for demonstration purposes. See the /site/modules/Helloworld.module file for details.', 'href' => 'http://www.processwire.com', 'singular' => true, 'autoload' => 'template=admin', 'icon' => 'smile-o', ); } public function init() { /** * Hook called just before a page is saved * * May be preferable to a before(save) hook because you know for sure a save will * be executed immediately after this is called. Whereas you don't necessarily know * that when before(save) is called, as an error may prevent it. */ $this->pages->addHookAfter('saveReady', $this, 'hookPageSave'); } /** * Save domain info to another field * No need to call page->save() when changing a value * as it will get saved just after this call. * * Make sure there's something in source_url and it has actually changed * with $page->isChanged(what) */ public function hookPageSave(HookEvent $event) { $page = $event->arguments("page"); if($page->template != "basic-page") return; if(!$page->source_url) return; if(!$page->isChanged("source_url")) return; $page->domain = parse_url($page->source_url, PHP_URL_HOST); if($page->domain) $this->message("Saved the domain: {$page->domain}."); } } now you have already a module in the "modules" table in your DB, go to phpmyadmin and remove the entry for "saveShortUrl" Come back and refresh modules, and install the new one.
-
Had to correct some code after posting, sorry.
-
Take this <?php class SaveShortUrl extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Rewrite field after save', 'version' => 1, 'summary' => 'An example module used for demonstration purposes. See the /site/modules/Helloworld.module file for details.', 'href' => 'http://www.processwire.com', 'singular' => true, 'autoload' => 'template=admin', 'icon' => 'smile-o', ); } public function init() { // add a hook before the $pages->save, to issue a notice every time a page is saved $this->pages->addHookBefore('save', $this, 'hookPageSave'); } /** * Save as another field. **/ public function hookPageSave(HookEvent $event) { $page = $event->arguments[0]; if($page->template != "yourtemplate") return; //#todo Rename to your field names. if(!$page->source_url) return; $page->domain = parse_url($page->source_url,PHP_URL_HOST); //#todo Maybe some more error handling. $page->of(false); $page->save("domain"); $this->message("Save the domain {$page->domain}."); } } You should name a module first letter uppercase. SaveShortUrl.module and name the class the same "SaveShortUrl" Next you should avoid using a method name same as the class name, that leads to getting called when initialized. In this case the ($event) is not set etc. You only want to execute the method when the hook is executed. Further improvements to the module could be to make autoload a selector to only get loaded in backend: "autoload" => "template=admin". Check for the template or if the field exists or if there's a string could also help.
-
ShouldnT I be $page = $event-> object
-
Let's see what happens. Of course alternatively, serializing the form object also works quite simply with a foreach, without using PW's WireArray::explode() which is fun anyway. After all the trick here is the $form->getAll(), which returns a InputfieldWrapper containing a flat array of only the fields whithout fieldsets and nested wrappers. And example of how to populate the form directly without using processInput($data), which requires to toggle the CSRF and the form validates and show errors when rendering the form. So setting values to the form object using $form->get(field)->attr("value", $value) does that "silently" and it doesn't trigger any validation thus not show errors when initially loading the form. if($input->post->send) { $form->processInput($input->post); if(!count($form->getErrors())){ $exclude = array("send"); // skip fields by name foreach($form->getAll() as $field) { if(in_array($field->name, $exclude)) continue; $formdata[$field->name] = strip_tags($field->value); } $session->setFor("shop", "userformdata", $formdata ); $session->redirect($this->page->url . $this->nextStepSegment); } } else { // populate data to form inputfields without using processInput(), which processes the form if($formdata = $session->getFor("shop", "userformdata")){ foreach($formdata as $name => $value) $form->get($name)->attr("value", $value); } } return $form->render();
-
RT @processwire: New blog post: ProcessWire Core Comments Upgrades, including threaded comments – https://t.co/l6EimwONOl
-
For security. I wanted to add, that the stored values in the array are not entity encoded and if you don't strip tags they're stored as entered, so you'd have to take care of that and entity encode with htmlspecialchars() them before printing them somewhere or use a sanitizer. When using the form render() it already takes care of that when populating the inputfields. It's still possible you have or want to allow tags, so it's a question of what you do with the data. Always be careful and if in doubt ask a experienced developer. foreach($formdata as $name => $val){ ... $out .= "<td>" . htmlspecialchars($val, ENT_QUOTES, "UTF-8") . "</td>"; ... } You could add a strip tags when getting the values like this: $formdataValues = $formfields->explode(function($item, $key){ return strip_tags($item->value); });
-
I think it may cause you would not setup main homepage as root but also as multisite subfolder. Never tried a setup you have but cant say without testing and reating the code.
-
Well it would give you current multisite domain. As it redirects to the domain it looks like it works. If you could give access I'm sure I can figure it out.
-
You miss the ->url. You don't have to get the page like Adrian example as you already got the page.
-
Yeah. It works that way. Have you tried what I told you?
-
Maybe this helps someone. Nerd alert! Currently building a shop module for a project, where I was looking for a easy way to handle/store form data in session and later repopulate it easily using form API. It can be very tedious to do that manually grab the fields, store in session repopulate form. So I found a way to do it "automatically" by serializing form object and build a name => value array that I store in session, then retrieve the array later and convert it to WireInputData as it is required for form object to process. Further I needed to turn of CSRF temporarely to get around error when populating the form object. Here a example code for those interested. // generate $form // when sent if($input->post->send) { // process form $form->processInput($input->post); // if no errors if(!count($form->getErrors())){ // serialize form values and store in "shop" session namespace $formfields = $form->getAll(); $formdataKeys = $formfields->explode(function($item, $key){ return $item->name; }); $formdataValues = $formfields->explode(function($item, $key){ return $item->value; }); $formdata = array_combine($formdataKeys, $formdataValues); $session->setFor("shop", "userformdata", $formdata ); $session->redirect("nextpageurl"); } } else { // if session formdata found repopulate form object if($formdata = $session->getFor("shop", "userformdata")){ $formdataInput = new WireInputData($formdata); $form->protectCSRF = false; // to not get a CSRF validation error $form->processInput($formdataInput); // fills in form and validates it $form->protectCSRF = true; } } return $form->render();
- 3 replies
-
- 11
-
-
Just looking at your site but it seems to work... http://horton-stephens.com/ http://horton-stephens.com/hortonsshortuns.com redirects me to http://hortonsshortuns.com means it found it and redirects to domain. So what is the problem again? Maybe it's because the page is hidden?
-
Looks ok but have no idea. Everybody seems to have problems with it except me. I only used multisite on where all pages are multisites, there's no default home. But I think it doesn't matter. What happens if you enter the direct url to the domain folder http://domain.com/hortonsshortuns.com What happens if you output echo "subdomain: " . $modules->Multisite->subdomain; in your template? Maybe you can debug the module and try to locate where it's failing?
-
Well look at the source https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/modules/Inputfield/InputfieldAsmSelect/asmselect/jquery.asmselect.js#L51 I don't know why it isn't used in PW (ASM was a standalone jquery plugin by Ryan, also used quite lot in drupal) But why not ask him I used it (tried) on my proof of concept block content module https://github.com/somatonic/BlocksContent/blob/master/BlocksContent.module#L106 Golden treasure not?
-
RT @processwire: New module: Social Share Buttons by @somartist provides simple and lightweight share buttons for your site. http://t.co/Jc…