Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/28/2013 in all areas

  1. I introduced today one of my clients to Processwire, i've just ported her site from Joomla. After 5 minutes clicking, showing and telling she just said: " This is all? So easy?" Looks like a new fan Any similar situations someone?
    4 points
  2. Markup Simple Navigation Module While there was a lot of people asking how to make navigation, and there were many examples around already (apeisa, ryan...) I took the chance to sit down 2-3 hours to make a simple navigation module. It has even some options you can control some aspects of the output. Installation: 1. Put this module's folder "MarkupSimpleNavigation" into your /site/modules folder. 2. Go to your module Install page and click "Check for new modules". It will appear under the section Markup. Click "install" button. Done. Technically you don't even need to install it, after the first load call ( $modules->get("MarkupSimpleNavigation") ) it will install automaticly on first request if it isn't already. But it feels better. However, it will not be "autoloaded" by Processwire unless you load it in one of your php templates. Documentation: https://github.com/somatonic/MarkupSimpleNavigation/blob/master/README.md Modules Repository processwire.com mods.pw/u Download on github https://github.com/somatonic/MarkupSimpleNavigation Advanced example with hooks creating a Bootstrap 2.3.2 Multilevel Navbar https://gist.github.com/somatonic/6258081 I use hooks to manipulate certain attributes and classes to li's and anchors. If you understand the concept you can do a lot with this Module.
    1 point
  3. Just wanted to share what I recently used to create forms in modules and in frontend using the API and Inputfield modules PW provides and uses on its own. I think many newcomers or also advanced user aren't aware what is already possible in templates with some simple and flexible code. Learning this can greatly help in any aspect when you develop with PW. It's not as easy and powerful as FormBuilder but a great example of what can be archieved within PW. Really? Tell me more The output markup generated with something like echo $form->render(); will be a like the one you get with FormBuilder or admin forms in backend. It's what PW is made of. Now since 2.2.5~ somewhere, the "required" option is possible for all fields (previous not) and that makes it easier a lot for validation and also it renders inline errors already nicely (due to Ryan FormBuilder yah!). For example the Password inputfield already provides two field to confirm the password and will validate it. De- and encryption method also exists. Or you can also use columns width setting for a field, which was added not so long ago. Some fields like Asm MultiSelect would require to also include their css and js to work but haven't tried. Also file uploads isn't there, but maybe at some point there will be more options. It would be still possible to code your own uploader when the form is submitted. Validation? If you understand a little more how PW works with forms and inputfields you can simply add you own validation, do hooks and lots of magic with very easy code to read and maintain. You can also use the processInput($input->post) method of a form that PW uses itself to validate a form. So getting to see if there was any errors is simply checking for $form->getErrors();. Also the $form->processInput($input->post) will prevent CSRF attacks and the form will append a hidden field automaticly. It's also worth noting that processInput() will work also with an array (key=>value) of data it doesn't have to be the one from $input->post. Styling? It works well if you take your own CSS or just pick the inputfields.css from the templates-admin folder as a start. Also the CSS file from the wire/modules/InputfieldRadios module can be helpful to add. And that's it. It's not very hard to get it display nicely. Here an code example of a simple form. <?php $out = ''; // create a new form field (also field wrapper) $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "post"; $form->attr("id+name",'subscribe-form'); // create a text input $field = $modules->get("InputfieldText"); $field->label = "Name"; $field->attr('id+name','name'); $field->required = 1; $form->append($field); // append the field to the form // create email field $field = $modules->get("InputfieldEmail"); $field->label = "E-Mail"; $field->attr('id+name','email'); $field->required = 1; $form->append($field); // append the field // you get the idea $field = $modules->get("InputfieldPassword"); $field->label = "Passwort"; $field->attr("id+name","pass"); $field->required = 1; $form->append($field); // oh a submit button! $submit = $modules->get("InputfieldSubmit"); $submit->attr("value","Subscribe"); $submit->attr("id+name","submit"); $form->append($submit); // form was submitted so we process the form if($input->post->submit) { // user submitted the form, process it and check for errors $form->processInput($input->post); // here is a good point for extra/custom validation and manipulate fields $email = $form->get("email"); if($email && (strpos($email->value,'@hotmail') !== FALSE)){ // attach an error to the field // and it will get displayed along the field $email->error("Sorry we don't accept hotmail addresses for now."); } if($form->getErrors()) { // the form is processed and populated // but contains errors $out .= $form->render(); } else { // do with the form what you like, create and save it as page // or send emails. to get the values you can use // $email = $form->get("email")->value; // $name = $form->get("name")->value; // $pass = $form->get("pass")->value; // // to sanitize input // $name = $sanitizer->text($input->post->name); // $email = $sanitizer->email($form->get("email")->value); $out .= "<p>Thanks! Your submission was successful."; } } else { // render out form without processing $out .= $form->render(); } include("./head.inc"); echo $out; include("./foot.inc"); Here the code snippet as gist github: https://gist.github.com/4027908 Maybe there's something I'm not aware of yet, so if there something to still care about just let me know. Maybe some example of hooks could be appended here too. Thanks Edit March 2017: This code still works in PW2.8 and PW3.
    1 point
  4. I would just settle for some work!
    1 point
  5. Hey Joss, thanks for the report! I just commited an update that may fix your issue, even though I don't know what it is. I haven't tried with repeater until now, and I couldn't even open the page as It throws a fatal error. In the last implementation of the default value feature it seems it was not compatible with repeaters. ** 1.0.4 ** - fixed bug with use in repeater
    1 point
  6. Hey buddy, not really had a chance to look at it in a while, will definitely check back though when I get a few minutes!
    1 point
  7. one of users asked me how to do counting comments with reply. for countuin comments with reply do next steps: open /wire/core/FieldtypeMulti.php file and find this change it to: then in this file add function: then in this file add function: to print result in your template file type this:
    1 point
  8. Hi Josh, you can simulate different smartphones with google chrome press ctrl + shift + i goto settings (bottom right) click 'overrides' check user agent PS: site looks good!
    1 point
  9. I had a chat with ryan about this a while back and I hope he won't mind me mentioning this, but some commercial profile ideas (real estate etc) would benefit hugely from the inclusion of FormBuilder. It's win-win in that case as ryan sells a FormBuilder license with every sale of that theme and the theme developer makes money as well. So if you've got any ideas where you think a complex theme is going to give you a headache in terms of forms then think about how you might do it packaging FormBuilder along with it to handle that aspect. Of course there are some logisitcal things to work out there, but it's something to bear in mind and certainly opens up some possibilities. For those that are curious, I originally arrived at that conversation with ryan when a few of us were discussing a real estate profile late last year (I still plan to do more work on that, but have been sidetracked with client work). Of course, when you see the Skyscrapers demo it's easy to see how it's possible to build these sites, but I thought that FormBuilder could take it one step further - allowing potential buyers to fill out details, show interest in certain property's etc and essentially create a sort of mini back-office for real estate staff (dammit, they're Estate Agents in the UK - feels wrong every time I type it the US way ). Just some more food for thought that might give you a few ideas EDIT: @casey - I'd be happy to help out on that side of things. It takes me far too long to be happy with any design I do myself so if there's room to collaborate with you doing some design work and me and a few others on the technical side of things then I'm all for that!
    1 point
  10. Btw, for anyone else trying to install Pear/PHPUnit on the latest MAMP (and possibly other recent versions), Nik's install instructions don't seem to work, at least they didn't for me. I think it's because MAMP has it's own [already installed] copy of Pear separate from OS X's copy. The very last entry on this page at Stack Exchange worked for me. It's the one answered Oct 9 '12 by Allen Hurff. Failed asserting that actual size "two words" matches expected size "one word".
    1 point
  11. According to autocomplete documentation you'd have to do something like this (works). $('#search_query').autocomplete({ source: function(request, response){ $.ajax({ url: '/search/', type: 'get', dataType: 'json', data: { 'q': request.term }, success: function(result){ response(result); } }); }, minLength: 2 });
    1 point
  12. There are quite a few ways to accomplish this already: // numeric id should remain same no matter what.. and if it doesn't, no other attribute could be trusted either $pages->get(1919); // like you pointed out yourself, config values are one option; you can set them in config.php or run-time $pages->get($config->teamPagesID); // you could also use your own custom field for this and define it global if you want it to always exist $pages->get('page_id=team'); // if the name of that page is very unlikely to change (and very likely to be unique), you could even find the page based on that $pages->get('name=team'); This is just my opinion, but I'm not confident that this would be beneficial enough to justify a core addition. I'd rather suggest that you turn it into a module; under the hood $pages->get() uses $pages->findOne() which in turn uses $pages->find() and since $pages->find() is hookable you could easily inject your own desired functionality there. This would, of course, require addition of that custom page_id field I mentioned above and perhaps another module / method to fill it in (and make sure that it's really unique) but that doesn't sound too complicated either. Edit: clarification about the uniqueness of name field added, thanks @Soma for pointing this out.
    1 point
  13. ProcessWire is a native category system, whether by structure or relation. I think the distinction is that we don't call them "categories" or "tags". But "does not have" makes it sound like they aren't part of the plan. When in fact, it's one of the underlying purposes of the system. ProcessWire's grandfather (Dictator CMS) had a category system called "channels" and it took me awhile to realize it, but they were a complete waste of time... The literal channels/categories were immediately rendered useless once the Page reference type entered the scene. I continued using channels on the sites that had started with them, but this antiquated type of category system never felt right again. Today's ProcessWire not only has categories, it has them on steroids. If each business only belongs in one category, and that will always be the case, then categories by structure is a good way to go. Meaning, your structure would be: businesses web-design a1-web ryan-cramer-design accounting acme-financial architecture top-notch-houses dlux-office-design restaurants las-tortillas bread-and-cheese-house If each business can be in multiple categories, then you'd want a structure like this: businesses a1-web ryan-cramer-design acme-financial top-notch-houses dlux-office-design last-tortillas bread-and-cheese-house business-types web-design accounting architecture restaurants Then each "business" page would have a "Page" reference field called "business_type" where the editor can check one or more boxes. Each business would display their types like this: <h2>Types</h2> <ul><? foreach($page->business_types as $t) echo "<li><a href='$t->url'>$t->title</a></li>"; ?></ul> Each business type would display the related business like this: <h2><?=$page->title?> Businesses</h2> <ul><? foreach($pages->find("business_type=$page") as $b) echo "<li><a href='$b->url'>$b->title</a></li>"; ?></ul>
    1 point
  14. LOGO ROCKED, MAN! REPEAT 4 [FD 10 RT 90]
    1 point
  15. It really depends on the server. This is a question for your hosting provider. In terms of ProcessWire, these particular permissions apply only to files in /site/assets/. The default permissions are going to work anywhere, but are not safe in shared environments that aren't completely jailed from one another. I don't know anything about your hosting environment, so can't suggest without more information. But one thing you can do is to test different permissions to find what will work. If 0700 for dirs and 0600 for files will work, that might be a good place to stay. But unless your server is using suexec, that won't work. If that doesn't work, see if 0755 for dirs and 0644 for files will work. This is a starting point, but you want to find the most secure solution for your server environment. The best way to check if something works is to create a page with a files field on it and upload a file. If the file upload does not work, then you've likely not found the right permissions. Once you have found the right permissions, make sure to go back and apply it to directories/files that already exist in /site/assets/, including the /site/assets/ directory itself. This is starting to sound like a good idea for a new module... The most common ProcessWire hosting environment is a dedicated one (server or VPS.) If that is also your environment, then you won't have to worry so much about locking down the permissions. But if you are using a low budget/shared hosting environment, then tweaking the permissions is definitely a good idea. Either way, your hosting provider will be the best to recommend what is right with their servers.
    1 point
  16. Have you tried putting in the name attribute as "userfile[]" rather than "userfile" ?
    1 point
  17. I think it really depends on the kind of beginner you have in mind. Someone who knows HTML farely well and maybe has some idea of programming (let's say through JS), but no PHP knowledge might actually like something like i.e. Smarty. For someone with no programming experience, but willing to learn, it might not make a difference at all. In my experience, what "scares" people about pure PHP templating is the syntax. It's pretty close to HTML, but introduces some things they usually don't have to deal with in pure HTML like single/double quotes, special characters etc. Most template engines use a syntax which is easier to distinguish from plain HTML at first glance. That's what "comforts" them. Bottom line, as long as it's optional, a template engine might indeed attract more users without driving away the PHP-only folks. But beware – it might as well become Pandora's box. You add one template engine, people want another one …
    1 point
  18. I like your idea of adding a "wire" template language! We can just stop referring to it as PHP and then all of the sudden people will see: wow this is a really easy template language.
    1 point
  19. Very well said Ryan, couldn't agree more. While I know I wouldn't use template language, I think that might well make PW a little bit more beginner friendly. Not sure if it is worth the trouble (vs. writing more tutorials, getting started materials etc..). Also maybe we could cheat a little here, and tell that PW uses templating language called "Wire", which looks like this: Output a variable: <?= $page->title ?> Loop for children: <? foreach ($page->children as $p): ?> <h2><?= $p->title ?> <? endforeach; ?>
    1 point
  20. Not evangelical at all, as I'm not even an experienced programmer. I only learned PHP in the past few months, and I can say it was mostly because of the way PW is thought out. As a Designer I never thought I would be writing some rather advanced PHP so soon, but because PW uses PHP instead of a templating engine, and because it's designed to make it so easy for anyone to achieve basic tasks, you just feel encouraged to go further and further without any constraints. Really, just start building a website with PW without thinking of external tools, you don't even need to install any of the excellent custom modules that are already available, and you will see how easy it is and how powerful it can get
    1 point
  21. Almonk, Here's one way you could do it (below), using ProcessWire's WireUpload class: <?php $page->setOutputFormatting(false); // instantiate the class and give it the name of the HTML field $u = new WireUpload('userfile'); // tell it to only accept 1 file $u->setMaxFiles(1); // tell it to rename rather than overwrite existing files $u->setOverwrite(false); // have it put the files in their final destination. this should be okay since // the WireUpload class will only create PW compatible filenames $u->setDestinationPath($page->files->path); // tell it what extensions to expect $u->setValidExtensions('jpg', 'jpeg', 'gif', 'png'); // execute() returns an array, so we'll foreach() it even though only 1 file foreach($u->execute() as $filename) $page->files->add($filename); // save the page $page->save(); Another way to do it would be a more traditional PHP way: <?php $page->setOutputFormatting(false); // we run the $name through $sanitizer to make it PW compatible... // ...this prevents the possibility of it getting renamed on the add() call below $name = strtolower($sanitizer->name($_FILES['userfile']['name'])); // prepend underscores to filename until it's unique... // ...this is just one possible way to handle duplicate filenames while(is_file($page->files->path . $name)) $name = "_" . $name; // validate the file extension $pos = strrpos($name, "."); if(!$pos) throw new WireException("File is missing extension"); $ext = substr($name, $pos+1); if(!in_array($ext, array('jpg', 'jpeg', 'gif', 'png'))) throw new WireException("Invalid extension"); // determine the final destination and store it in $file $file = $page->files->path . $name; // move the file to it's destination using PHP's function if(move_uploaded_file($_FILES['userfile']['tmp_name'], $file)) { // add it to the page $page->files->add($file); /// save the page $page->save(); } Btw, no need to turn outputFormatting back on unless you are rendering parts of that page in the same request. Neither of these examples perform much error checking, which you may want to add. Though the WireUpload class will populate PW's "$notices" API var with any errors: <?php foreach($notices as $notice) { if($notice instanceof NoticeError) { echo "<p>Error: {$notice->text}</p>"; } } If you are using the PW's admin templates, then it already does something like the above snippet.
    1 point
×
×
  • Create New...