Jump to content

Soma

Moderators
  • Posts

    6,798
  • Joined

  • Last visited

  • Days Won

    158

Everything posted by Soma

  1. 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.
  2. 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();
  3. RT @processwire: New blog post: ProcessWire Core Comments Upgrades, including threaded comments – https://t.co/l6EimwONOl

  4. 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); });
  5. 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.
  6. 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.
  7. You miss the ->url. You don't have to get the page like Adrian example as you already got the page.
  8. Yeah. It works that way. Have you tried what I told you?
  9. 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();
  10. 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?
  11. 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?
  12. 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?
  13. RT @processwire: New module: Social Share Buttons by @somartist provides simple and lightweight share buttons for your site. http://t.co/Jc…

  14. Soma

    PrettyPhoto

    First off I would have never guessed that there's a gallery link hidden in that picture frame icon. I clicked the images to no success (hm what's supposed to be here?) Ok just a glance at html <!DOCTYPE HTML> <!-- copyright 2014 OwlTree Web Solutions Ltd --> <html lang="en"> Not sure but some long year experience says this comment could cause issues. Definately if it would be at top (for IE) Aand we have a js error $ undefined., which 99.999% is jquery not included/loaded before a jquery script using $. <script type="text/javascript" src="/carman/site/templates/scripts/main.js"></script> <!-- Pretty Photo CSS and scripts --> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script type="text/javascript" src="/carman/site/templates/scripts/jquery.easing.js"></script> <script src="/carman/site/templates/scripts/jquery.prettyPhoto.js" type="text/javascript"></script> <link rel="stylesheet" href="/carman/site/templates/styles/prettyPhoto.css" type="text/css" media="screen" /> Even if main.js seems empty to you there's a $(document) and it's included before jquery core. Loading jquery core like this <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> What do you do if server google isn't available. There should be a fallback like https://github.com/h5bp/html5-boilerplate/blob/master/dist/index.html#L25 Finally this is the gallery markup <a href='/carman/site/assets/files/1036/con11.jpg' class='gallery' data-rel='prettyPhoto[pp_gal]'><img src='/carman/site/templates/images/gallery.png' alt='Conservatories Gallery' /></a> <a href='/carman/site/assets/files/1036/con12.jpg' class='gallery' data-rel='prettyPhoto[pp_gal]'> </a> <a href='/carman/site/assets/files/1036/con3.jpg' class='gallery' data-rel='prettyPhoto[pp_gal]'> </a> <a href='/carman/site/assets/files/1036/con4.jpg' class='gallery' data-rel='prettyPhoto[pp_gal]'> </a> <a href='/carman/site/assets/files/1036/con5.jpg' class='gallery' data-rel='prettyPhoto[pp_gal]'> </a> <a href='/carman/site/assets/files/1036/con6.jpg' class='gallery' data-rel='prettyPhoto[pp_gal]'> </a> <a href='/carman/site/assets/files/1036/con7.jpg' class='gallery' data-rel='prettyPhoto[pp_gal]'> </a> <a href='/carman/site/assets/files/1036/con8.jpg' class='gallery' data-rel='prettyPhoto[pp_gal]'> </a> <a href='/carman/site/assets/files/1036/con9.jpg' class='gallery' data-rel='prettyPhoto[pp_gal]'> </a> <a href='/carman/site/assets/files/1036/con10.jpg' class='gallery' data-rel='prettyPhoto[pp_gal]'> </a> Possibly the use of 'attr' instead of "attr", you'll laugh but I got caught by it once, but don't remember what case it was. I don't think so here is the case. In my Firefox it loads the gallery but the container is positioned far far down. Only after scrolling some it shows up. Offset is inline calculated from top and seems wrong. I removed you CSS "height: 100%" from <body> and <html> and it works fine.
  15. Repeaters are stored in admin with own template not "admin" template, so a logged in superuser see's them but others not. it's not a bug. You could exclude admin or by template if you want superuser not see them. has_parent!=2
  16. Birthday bottle ahoy! Felizidads Mr pirate! Have a great one or two.
  17. Did you manage to install joss? That was quiet confusing.
  18. Yeah super cool something like this should be in core just more complete and with fields too. Monster
  19. Too bare to be that useful for a official module. IF I had time Id do a full featured template batch editing. Access is only minorit. .. but other settings are often more needed.
  20. This is the json http://modules.processwire.com/export-json/?apikey=pw223&debug=1&class_name=HannaCodeHelper There's wrong infos in there... not good. I'd guess Teppo just needs to save the module repository to get module repo updated, but can't tell for sure.
  21. The 0.0.0 >= 0 is strange, but netherless it's not the 2.3,2.4 but something else, but it works fine and you can install it.
  22. Exactly, cause the module has still PW compatible 2.3, 2.4 but you can install it manually or via zip link.
  23. Hanna 1.9 Hann Helper 0.5.0 Where you'r seeing this and how do you download install it? I used built in module download via link Requirements are here and are fullfilled if you have Hanna Code installed. https://github.com/teppokoivula/HannaCodeHelper/blob/master/HannaCodeHelper.module#L35 Does it say what requirements aren't meat? I'd guess you try to intall through ClassName and PW checks to see the PW version which it doesn't meet, although the module doesn't have this requirement. http://modules.processwire.com/modules/hanna-code-helper/ 2.3 2.4
×
×
  • Create New...