Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/25/2015 in all areas

  1. A highly configurable and flexible ACE editor input field. This module is sponsored in part by Nibiri, aka forum member Macrura which was a great jump start. So many thanks to him. See this short screencast to get an overview: Get it from Github or the Modules Directory. Roadmap add full screen mode expose a jQuery api for resizing, setting row count etc. add image handling like in Adam Kiss' version
    17 points
  2. Hi Spica! Create a new permission called "page-edit-show-settings-tab" and adjust the roles to fit your needs. In /site/templates/admin.php add the following before the line: require($config->paths->adminTemplates . 'controller.php'); function hideSettingsTab(HookEvent $event) { // Get the page being edited $page = $event->object->getPage(); if (!wire('user')->hasPermission('page-edit-show-settings-tab', $page)) { $page->template->set('noSettings', 1); } } $wire->addHookBefore('ProcessPageEdit::buildForm', null, 'hideSettingsTab'); After a quick test, this seems to work fine on my setup.
    10 points
  3. This isn't possible with a page field, but I have quickly modified hani's Template ASM Select to create a Field ASM Select fieldtype. Let me know if this works for you as expected - maybe it should be released properly in case others might find it useful. FieldtypeFields.module
    8 points
  4. yeah this is so awesome - owzim's work on this goes beyond expectations!
    6 points
  5. they declinded not.support wordpress universe model pw no good.for themeforest sales follow.the €
    5 points
  6. Nice solution. Ended up with this as a autoload module <?php class Helloworld extends WireData implements Module { public static function getModuleInfo() { return array( 'title' => 'Hello World', 'version' => 1, 'singular' => true, 'autoload' => true, 'summary' => 'Anpassungen', 'icon' => 'smile-o', ); } public function init() { $this->addHookBefore('ProcessPageEdit::buildForm', $this, 'hideSettingsTab'); } function hideSettingsTab(HookEvent $event) { if($this->user->hasRole("presenter")) { $page = $event->object->getPage(); $page->template->set('noSettings', 1); } } }
    5 points
  7. haha Well to be honest, that hack of hani's module was about as easy as it gets - literally just a find/replace of "template" with "field" and it works I am actually wondering if FieldtypeModules, FieldtypeTemplates, and now FieldtypeFields should become one module so that we can have one codebase to maintain, but the dev can choose whether modules, templates, or fields are what is available for selection. Of course this option would have to be from the field settings, and not the module config settings so it could be on a field by field basis. Do any users of FieldtypeModules or FieldtypeTemplates have any thoughts on this?
    5 points
  8. Hi @icreation, thanks for dropping in all relevant things: original image, scaled image variation and issue description. But, however, I have no good message for you. The GD-Image-Library that is shipped with PHP for image handling cannot handle smooth transients from opaque to transparent. Also if the image looks like it would only have hard cuts between full color and full transparent areas, it isn't that way. Have a look to my screenshots to understand what I try to say (as a none native english speaker / writer). Especially look at the red dot from the colorpicker and the values for RGB in the info palette: here it shows the values for blue (46, 172, 250) . here in the transparent area it shows nothing . but here, almost 4-5 pixel away from the color area, it shows the exact RGB values like in the blue area (46, 172, 250). Obviously this area has a transparency from nearly 100%, but only nearly. In fact it has only 98 - 99% transparency what let the GD-Library struggle with it. --- I don't know how comfortable your client are with image manipulation in regard of understanding this. The graphics look professional though. If they could try to cut them without that smooth area maybe it will be better. Or you / they could try to export the graphics to GIF instead of PNG. Additionally to that you can tweak the imageSizerOptions for those images to render with these values: $options = array( 'defaultGamma' = -1, 'sharpening' = 'none' ); $image = $image->size($width, $height, $options); Hope that helps a bit.
    5 points
  9. For anyone looking for a great frontend approach / workflow that uses all the cutting edge practices and tools, I highly recommend taking a look at the Sage Starter Theme for WordPress (formerly known as Roots... they changed it to Sage and kept the "Roots" name as the parent organization name). Although Sage is built around WordPress, it's not difficult to strip away the WordPress related bits (mainly template related things and workarounds that fix some of WP's quirks) so it can work with ProcessWire. In fact, this has been my primary frontend technique for most ProcessWire sites. They have a great community over there as well. Relevant links: https://roots.io/ https://roots.io/new-website-sage-and-the-future/
    4 points
  10. There's already a github issue about this, but sadly no feedback by now. https://github.com/ryancramerdesign/ProcessWire/issues/914
    4 points
  11. I'd support that. Just drys out the process. Especially if you need more than one type.
    3 points
  12. Guys, this thread gave me the impulse I needed to finish an idea that I started long ago. So, here is a new module for using image fields inside textarea using the same markup language that you are using in that same text area https://github.com/ocorreiododiogo/pw-image-fields-markup edit: still testing and work in progress, so I'm not submitting to the directory yet
    2 points
  13. Nice. I can redirect everyone here now, instead of fiddling with my own FYI, image upload was really really hacky, but the relevant coffee script is here: - event: https://github.com/adamkiss/InputfieldAceEditor/blob/image-upload/_coffee/modules/editor.coffee#L50-L59 - method: https://github.com/adamkiss/InputfieldAceEditor/blob/image-upload/_coffee/modules/editor.coffee#L73-L94
    2 points
  14. Until the magic is finished there's this: http://modules.processwire.com/modules/textformatter-image-tags/
    2 points
  15. Such a clean illustration like that should be displayed as an SVG Seriously though if you don't need to support <IE9 you could have your editors upload as an SVG and it should work great. If you do need to support <IE8 or you have other illustrations which are more complex and you want to rasterize on the fly at the required size, you could check out: http://modules.processwire.com/modules/image-rasterizer/ although keep in mind that it does have some server dependancies that might not be available. @horst - what is the status of https://github.com/horst-n/PageimageSizerImagick ?
    2 points
  16. @Mont: Just buy the profields. It's a win-win
    2 points
  17. Almost done; mainly waiting for an answer about this: https://processwire.com/talk/topic/7870-asmselect-pagefield-modify-selected-options-order-in-select-dropdown/?p=88609
    2 points
  18. Slight update (sorry if this is a monologue!) I was quite comfortable building out the static site in Middleman, although I did find the documentation extremely disappointing, for a seemingly well-backed product there isn't a great deal of meat beneath the gravy docs-wise. I started to consider looking at one of the paid products (Kirby / Statamic), they both seemed to be very solid, had good documentation and had the bonus of being a "full" CMS despite being NoDB. In the end I decided to go with Statamic for a few reasons. I was extremely impressed with their docs. The simple admin area is very nicely put together and pretty intuitive. So far I pretty much have the project coded up and have come across some really nice features (some that PW may learn from - as per the original post by Diogo ) Others aren't really relevant as Statamic and PW do cater to different sorts of sites. I doubt it will be used for more complicated database-driven sites, that said, what I do like about it: 1. Configuration through YAML - Have to say this is proving to be a real hit for me. Set global variables, decide which fields to show for any given template in the admin 2. Being able to add content through files - I personally haven't made a great deal of use of this yet as I still prefer adding content through an interface at this stage. Despite this I can see the appeal, especially to people who use MarkDown a lot. 3. NoDB, easier site synchronizing/backups - OK so this is an obvious one but clearly having no database is an advantage when it comes to Zipping a site up or keeping two copies in sync. 4. Templating syntax - This is controversial, not least to myself. I wholeheartedly agree with Ryan's appraisal on using PHP syntax in PW. That said, there's no arguing that when we're using a simpler system for a simpler site, there's something pleasant about being able to leave out some of the less glamorous parts of writing PHP ( ; {} [] ). My preference for tenplating engines over pure PHP completely depends on the aesthetics of the engine syntax. In Statamic's case it is elegant so a plus point for me {{ title }} 5. Variable modifiers - Sort of an extension of 4 really but again when we're keeping things simple it is nice to be able to call on some nice simple helpers that enabe us to write less code. http://statamic.com/learn/templating/variable-modifiers --- Clearly there are things here that are good because it makes a nice change from coding in a more complex site development process (as I often do with PW), maybe of things that PW could one day use, perhaps some way of writing more code in the editor than clicks in the admin, although that must be limited by the database interactions that must be necessary. I still don't think there is a system out there that can touch PW when it comes to a tool that can accomplish almost anything in an organised, lean and powerful way.
    2 points
  19. InputfieldChosenSelect This topic (https://processwire.com/talk/topic/71-categorizingtagging-content/) showed the need for a Inputfield that would provide a real tagging UI to be useable with FieldtypePage. It uses the chosen library, which can be found here http://harvesthq.github.io/chosen/. It's meant for MultiPageFields and works kinda like asmSelect, but with a different skin. Features: Inline adding of new tags, which will then generate the corresponding pages. Sortable tags. Usage Install the Module Edit your pagefield and choose InputfieldChosenSelect as inputfield. Use Enter or Tab to create new Pages with the currently typed name. Enter will fill in the tab currently selected in the dropdown. http://modules.processwire.com/modules/inputfield-chosen-select/ https://github.com/LostKobrakai/InputfieldChosenSelect
    1 point
  20. Some time ago I developed a module (FieldtypeImageExtra) which extends Fieldtype Image with the ability to add custom fields to an image. This worked well but it had a somehow restricted applicability and did not meet all of our needs. There of course are other useful image modules like CroppableImage or ImageFocusArea, but up to now there was no possibility to combine image cropping with custom fields support. So you had to decide whether to add image cropping or the possibility to add custom fields because each of those modules sets up their own field type (and input type) which cannot be combined. The new module ImageExtra allows you to have both functionalities. You can get the module from GitHub. For more informations have a look at this blog post. If you notice any problems or unexpected behaviour please let me know.
    1 point
  21. codecademy recently started an interactive php course for beginners. http://www.codecademy.com/en/tracks/php looks good so far. i was not sure if it fit's the "getting started" section of the forums, but maybe it's an interesting hint some people. maybe someone has links to add.
    1 point
  22. Just wanted to share a simple bash script I've been using lately to make installing ProcessWire a little faster. Feel free to modify it to your taste! Just copy everything into a simple text file, I call mine "preparepw". Optionally, set this file to executable (chmod -x preparepw) and put it somewhere into your path to be able to load it as a regular command without the need to call it from sh ~/preparepw for example. To run, first cd to where you want to install PW's root, e.g. /sites/mysite/ then call the script. It will create a /sites/mysite/wwwroot/ directory containing all of PW's files from current master, set the required permissions and rename htaccess. It has an option to set the directory that, when unset, will default back to ./wwwroot. (e.g. preparepw public would install PW in ./public/). #!/bin/bash # Version 2.0 INPUT=$1 if [[ -z $INPUT ]]; then INPUT="wwwroot" printf "Directory option not set, installing into ./$INPUT/...\n" else printf "Installing in to ./$INPUT/...\n" fi # Select a version printf "\nWhich ProcessWire branch do you want to install?\n" options=("master" "dev" "devns") select BRANCH in "${options[@]}"; do test -n "$BRANCH" && break; echo ">>> Invalid selection, please try again"; done printf "\nDownloading ProcessWire $BRANCH branch, please hold on...\n" # Get ProcessWire master and prepare files if [ "$BRANCH" == "master" ]; then curl -o processwire.zip https://github.com/ryancramerdesign/ProcessWire/archive/master.zip -# -L fi if [ "$BRANCH" == "dev" ]; then curl -o processwire.zip https://github.com/ryancramerdesign/ProcessWire/archive/dev.zip -# -L fi if [ "$BRANCH" == "devns" ]; then curl -o processwire.zip https://github.com/ryancramerdesign/ProcessWire/archive/devns.zip -# -L fi unzip -q processwire.zip rm processwire.zip if [ "$BRANCH" == "master" ]; then mv ProcessWire-master $INPUT fi if [ "$BRANCH" == "dev" ]; then mv ProcessWire-dev $INPUT fi if [ "$BRANCH" == "devns" ]; then mv ProcessWire-devns $INPUT fi chmod -R u+rwX,go+rX,go-w $INPUT mv $INPUT/htaccess.txt $INPUT/.htaccess cd $INPUT # Prompt for site profile printf "\nWhich site profile will you be using?\n" select d in site-*/; do test -n "$d" && break; echo ">>> Invalid selection, please try again"; done mv $d site/ rm -rf site-*/ # Set permissions chmod 777 site/assets chmod 777 site/modules chmod 666 site/config.php printf "\n" read -p "Press [Enter] once you've finished the installation process to remove the install files..." rm install.php rm -rf site/install printf "\nInstallation files removed.\n" printf "\nDirectory \"$INPUT\" all set for ProcessWire. Have fun! \n"
    1 point
  23. It is possible that they just don't have anyone expert enough in Processwire at the moment to create such a course. Though it would be interesting to see if there was a change in attitude if some of us started creating and selling Processwire site profiles on themeforest.
    1 point
  24. I'm not double posting . I have been having a conversation with @netcarver about this but thought to expand the discussion. In relation to the module I am working on MenuBuilder and this comment, I need to modify the output of AsmSelect. Its ___render() method is hookable but the method does not have arguments so wondering whether in such a case, the best way is to use a Hook that replaces the whole method? Specifically, what I need to replace in the method is only one line - the one that loads the jquery.asmselect.js. $this->config->scripts->add($this->config->urls->$class . "asmselect/jquery.asmselect.js?v=$ver"); AsmSelect shows selected pages in a <span>Item Label</span>. So, instead of this: I want to have something like this (still rough around the edges!): In order to do that, I have needed to modify the jquery.asmselect.js plus modify the CSS a bit. Alternatively, I tried to remove the file using config->scripts->remove() and adding my modified one but that didn't work. The original jsquery.asmselect.js script was still loaded. I tried this in my Process modules execute() method and executeEdit() and just in case init(). I appreciate any thoughts on this, including alternatives, e.g. just manipulating the dynamically created DOM (the <span>Item Label</span> is dynamically created by jquery.asmselect.js) using jQuery. Also, I think extending the module in this case is an overkill - just to replace one line! Thanks! Edit: Clarification based on comment below. I am not after an inputfield per se. The data in the extra inputs I want will be stored elsewhere
    1 point
  25. Sorted! (seems hackish but I don't really mind unless shown a better way ). Documenting this in case there is a better way.... Add a Hook after AsmSelect's output: wire('page')->addHookAfter("InputfieldAsmSelect::render", $this, "customAsm"); Slightly modify AsmSelect output in customAsm() $value = $event->return; $value = str_replace("\"multiple\"", "\"multipleMB\"", $value);//see why this below.. $event->return = $value; The reason for the str_replace is that in InputfieldAsmSelect.js you have this code: $(document).ready(function() { $(".InputfieldAsmSelect select[multiple=multiple]").each(function() {//note this var $t = $(this); if(typeof config === 'undefined') { var options = { sortable: true }; } else { var options = config[$t.attr('id')]; } $t.asmSelect(options);//note this }); }); We need to change the [multiple=multiple] to point to our custom selector multiple=multipleMB. We don't hack this but in our own .js file we have: $(".InputfieldAsmSelect select[multiple=multipleMB]").each(function() { /* blah blah */ $t.asmSelectMB(options);//this will be the name of our customised asmSelect function Final thing is just to include our customised jquery.asmselect.js, i.e. jquery.asmselect-mb.js. (config->scripts->add()) with the modified function $.fn.asmSelectMB = function(customOptions) { /* blah blah */ This way, I can still set my properties values (e.g. $menuAddPageItems->setAsmSelectOption('sortable', false); ) and Bob's your uncle. Downsides? AsmSelects native JS still gets loaded although I have no use for it. OK, back to coding...
    1 point
  26. Thanks Macrura, I am glad that you could pinpoint the issue. I already fixed it, see this commit
    1 point
  27. fyi for anyone testing this out today, ace extended won't work if the initial field is set to collapsed only when blank..
    1 point
  28. I've never used FieldTypeModules — didn't realize they weren't all fairly similar and straightforward. Antti, would FieldtypeModulesTemplatesFieldsRelationSelector not work? haha!
    1 point
  29. I actually believe separate modules is way to go. FieldtypeModules has quite a bit configuration already, bundling fields and templates there would make things complex where they doesn't need to be. Also what would that field be called? FieldtypeNotPageRelation?
    1 point
  30. PageTableExtended will be superior solution for this. Played with it recently, and it's very nice concept.
    1 point
  31. Great solution Adrian, thank you very much!!! Didn't know about the existence of FieldtypeTemplates... The support in this community is unbeatable!
    1 point
  32. I bought Profields and ProForms during the Black Friday Sale. It was a win win considering the time saved. Another thing I could always do is to remember the person who created a plugin or module and then when i need something similar, contract that developer to create a module/plugin for me. This is something that makes me appreciate the work that went into building the developer directory.
    1 point
  33. I use Gulp, but the difference is just in syntax; You can see my assets directory here: https://github.com/adamkiss/StarterKit/tree/master/Assets I use it this way (Gulp-ing from /Assets/src) so I can ignore whole source directory when deploying and git/rsync/git-ftp only the distilled directory.
    1 point
  34. arjen, did not know of this feature, looks great. Added it to the roadmap. To all: Feature requests and bug reports very welcome!
    1 point
  35. Really looking forward to experiment with this! I always liked ACE since I use Textile a lot. I've seen the roadmap and full screen would be awesome. Another thing you might consider is image handling. Something like this done by Adam. Thanks and great work.
    1 point
  36. Hi @adrianromega - I have just set up a lightning.pw site running 2.5.3 and everything is working fine at my end. I am just about to PM you the login details. Could you please test at your end and let me know if it works for you. If it does work, then I think there might be another module causing conflict, although that seems unlikely unless you have some something that also has some JS affecting the live name creation process. If it doesn't work, then I am guessing a browser issue - what are you running? Are you getting any JS errors in your console?
    1 point
  37. Late to the party (as always), but anyway: if you're thinking about static site generators, I have always found that they are limiting in one way or another. A lot of them are “blog-aware”, which translates to “anything that is similar to a blog will be built quickly, everything else will take hours and be painful”. Just my experience with them. A nice alternative is assemble, because it does (much like PW) give you a lot of freedom to work the way you like to work. It's basically a Grunt plugin which generates static HTML from Handlebars templates. It's kind of clumsy to do certain things (like i.e. building navigations dynamically) and they're apparently in the middle of rewriting the whole damn thing (for quite some time now), but if all you need is a small template system to be able to use variables, partials/includes and layouts in HTML, it's worth a shot.
    1 point
  38. Alternative for Process Dashboard is the AdminCustomPages module... http://modules.processwire.com/modules/process-admin-custom-pages/ with this one you could assign a normal php template to a backend page and do what you want without creating a processmodule...so you could easy use something like this example: https://processwire.com/talk/topic/9136-preconfigured-lister-in-custom-admin-page/#entry88364 to get some content or use other options to get pages by role via api and save them. regards mr-fan
    1 point
  39. There is the module JSON Installer by Peter Beulque, which lets you add templates, fields and pages via JSON files. This may be very helpful for fast creation or reusing typical scenarios.
    1 point
  40. Sortable is not that difficult I guess. Raymond has explained it over here.
    1 point
  41. I just edited the initial post. Directories permissions need to be set to 777, for some reason I copied an old version that wasn't working correctly..
    1 point
  42. You can use this fieldtype described by Ryan here: https://processwire.com/talk/topic/417-extending-image-field/#entry3225 (scroll down for the packed fieldtype) Just use a field for each language and in your template and display the description according to the current language. Not very elegant but works.
    1 point
  43. Currently I am facing an issue Twig related. The issue: When I tried to use the CSRF methods from PW in a twig template I encountered an error. I've tried hundrerds of different things and on Stackoverflow I didn't find the solution either. http://stackoverflow.com/questions/20602840/cant-get-twig-to-work-with-method-from-object If anyone knows something more I'll glad to hear from you.
    1 point
  44. Thank you very much! Yes I do. Please see my answers below. I'd love to further discuss the topics I brought up though. Yup. That's the reason I'm currently waiting for 2.4 to be finished (I said that in another thread about writing blog articles, too). Otherwise I'd propably have to refactor all of the stuff on a daily basis. There currently is too much (very positive!) change going on. Apart from that there is a lot of other work to do. We're currently building about 6 websites in parrallel (all driven by processwire - yay!) which is good for our business but bad for doing sideprojects like this theme. WOW. I didn't read that until now. Thanks for the hint
    1 point
  45. Thanks a lot! I'm not always sure if the way i'm writing sounds like intended as my school english got kind of rusty over the years. But I enjoy writing in english and the discussion itself for sure. On topic: Introducing new "cutting edge" stuff always includes a certain risk of the tools beeing discontinued and therefore betting on the wrong horse. Thats why all of the stuff I mentioned already has a strong foundation and is established among many users/projects. You're propably right: PW doesn't actually NEED it but it would have certain benefits that i've already mentioned performance wise. I actually just meant the methodology. Sorry about not making this clear. I'm with you here that introducing the stack of tools as a whole that'd for sure be overkill. Thanks for mentioning - i didn't look up the sourcecode of any of them. I was just talking about the general look & feel (and also mentioned they're not as complex as PW). If you look at them they seem "light" and easy to use due to their lack of clutter. That's what makes them a role model for me. There's a pretty similar saying in germany: "Das Gegenteil von Gut ist gut gemeint" (translated: "The opposite of good is something done with a good intention") which basically means that worst thing that can happen is people doing something wrong thinking it helps you and then rely on that. Correct. That's the complicated part about it. Either you'd wrap them all into a define() closure or shim them. But if you'd shim them you'll have to register all of those plugins and build a list which has to be dynaically generated into the require.js config (see: https://github.com/jrburke/requirejs/wiki/Upgrading-to-RequireJS-2.0#wiki-shim ). Yup. There are tons of testing frameworks out there (mocha, qunit, and jasmine to name a few). Then there are testrunners which run those tests not only on an (i.e. node) js-interpreter but in a real browser enviroment (like jsTestDriver or karma). Yup. I've already started to code some stuff. But I don't have that much time currently as my family and some paid projects we're doing have more priority currently. But I'll try to release some code as soon as possible. You're welcome! Thanks for your feedback! -- As already mentioned I'm only drawing a picture here. I'm aware of the fact that this is not something that could be done easily. My intention is more to "get this on the roadmap" for some future release or to have people at least think about it as well as getting a feeling if there are even people thinking the same. I'd also like to keep discussion up and running. If there are people learning from it and getting inspired that's great and makes this discussion even more valuable for all of us. I'm currently investigating in how much work it would be for me to rewrite certain scripts but keep their functionality and don't break things. As you said: It's a lot of work and not something that can be done until tomorrow. In my company constant change and adapting new technologys is one of our "core values" as we help our customers in changing their communication and methodologys a lot. So I'm pretty sure there will be more to come as this discussion continues
    1 point
  46. I'd love to hear the methodology you would have chosen! I also not a big fan of jQueryUI for the same reasons you've already mentioned. Removing it would mean to rewrite most of the core JS though. That'd be a pretty substanical decision to make. -- How would using modular patterns change this? As stated before: the only thing "new" would be require.js. Apart from this BEM would even make it easier to change things (and you don't have to use it yourself if you are developing a module). You're right. Processwire is blazing fast. I'm only drawing a picture of a "better" (from my point of view) architecture. Well if you count in the various module developers which also tend to inject customisations into the backend (new fields, admin pages...) you actually HAVE a huge amount of people working on the backend and NEED some sort of standardization. Just look at all this !importants in every module. Once again: I never mentioned replacing jQuery with something else (especially not ExtJS which is a nightmare). I'm fine with using it although the way it is used could be more modular and less dependant on certain dom structures (proper event delegation, micro-templating or even directives like in angular would be fine). Yes and no. The "cleanest" way would to wrap all (core) modules into a define(...); closure. You could go and "shim them" all instead. But that's a nasty thing to do. This - for some people - is quite a subjective one. But from a "professional" point of view there are quite a lot of things that could be done better (in terms of UI/UX). PLUS: If you want to sell/market something it better looks "sexy" Accessability is more like a way of thinking about and architecturing things. Many of the core modules which either produce DOM-Elements or modify them (js) would need some tweaking. This only covers the PHP Part. No JS-Testing until now (there are again some requirements for this - scripts need to be written a certain way to make testing efficient and reasonable). Maybe you're right. I'll explain this a bit further in an upcoming post as i don't have time to write down all my thoughts on this now. This has a lot to do with how different personalitys and the way they handle changes to things they are already used to. Maybe it's the best way to start off with a theme, get some feedback and then as development continues some ideas and code might find their way back into pw. I don't like the idea of starting a fork of PWs backend as i think this would be pointless and do more harm to PW than it would help. Nevertheless it'd be great to keep this conversation up and going.
    1 point
  47. If I'm not mistaken the design of the WP admin is from Jason Santa Maria. Couldn't be ugly for sure...
    1 point
  48. Hi kongondo, There's no reason to use a while loop in the situation where you are just iterating over the pages found. Generally: If you need to loop over a set of data, you're free to choose the type of loop (for, while, do-while). However, it depends on the situation which one you take As for your example, you could do it in a while loop like this: $i = 0; while (count($results)) { $p = $results->get($i); $rows[] = $p; $results->remove($i); $i++; }
    1 point
  49. I recently had to setup front-end system to handle logins, password resets and changing passwords, so here's about how it was done. This should be functional code, but consider it pseudocode as you may need to make minor adjustments here and there. Please let me know if anything that doesn't compile and I'll correct it here. The template approach used here is the one I most often use, which is that the templates may generate output, but not echo it. Instead, they stuff any generated output into a variable ($page->body in this case). Then the main.php template is included at the end, and it handles sending the output. This 'main' template approach is preferable to separate head/foot includes when dealing with login stuff, because we can start sessions and do redirects before any output is actually sent. For a simple example of a main template, see the end of this post. 1. In Admin > Setup > Fields, create a new text field called 'tmp_pass' and add it to the 'user' template. This will enable us to keep track of a temporary, randomly generated password for the user, when they request a password reset. 2a. Create a new template file called reset-pass.php that has the following: /site/templates/reset-pass.php $showForm = true; $email = $sanitizer->email($input->post->email); if($email) { $u = $users->get("email=$email"); if($u->id) { // generate a random, temporary password $pass = ''; $chars = 'abcdefghjkmnopqrstuvwxyz23456789'; // add more as you see fit $length = mt_rand(9,12); // password between 9 and 12 characters for($n = 0; $n < $length; $n++) $pass .= $chars[mt_rand(0, strlen($chars)-1)]; $u->of(false); $u->tmp_pass = $pass; // populate a temporary pass to their profile $u->save(); $u->of(true); $message = "Your temporary password on our web site is: $pass\n"; $message .= "Please change it after you login."; mail($u->email, "Password reset", $message, "From: noreply@{$config->httpHost}"); $page->body = "<p>An email has been dispatched to you with further instructions.</p>"; $showForm = false; } else { $page->body = "<p>Sorry, account doesn't exist or doesn't have an email.</p>"; } } if($showForm) $page->body .= " <h2>Reset your password</h2> <form action='./' method='post'> <label>E-Mail <input type='email' name='email'></label> <input type='submit'> </form> "; // include the main HTML/markup template that outputs at least $page->body in an HTML document include('./main.php'); 2b. Create a page called /reset-pass/ that uses the above template. 3a. Create a login.php template. This is identical to other examples you may have seen, but with one major difference: it supports our password reset capability, where the user may login with a temporary password, when present. When successfully logging in with tmp_pass, the real password is changed to tmp_pass. Upon any successful authentication tmp_pass is cleared out for security. /site/templates/login.php if($user->isLoggedin()) $session->redirect('/profile/'); if($input->post->username && $input->post->pass) { $username = $sanitizer->username($input->post->username); $pass = $input->post->pass; $u = $users->get($username); if($u->id && $u->tmp_pass && $u->tmp_pass === $pass) { // user logging in with tmp_pass, so change it to be their real pass $u->of(false); $u->pass = $u->tmp_pass; $u->save(); $u->of(true); } $u = $session->login($username, $pass); if($u) { // user is logged in, get rid of tmp_pass $u->of(false); $u->tmp_pass = ''; $u->save(); // now redirect to the profile edit page $session->redirect('/profile/'); } } // present the login form $headline = $input->post->username ? "Login failed" : "Please login"; $page->body = " <h2>$headline</h2> <form action='./' method='post'> <p> <label>Username <input type='text' name='username'></label> <label>Password <input type='password' name='pass'></label> </p> <input type='submit'> </form> <p><a href='/reset-pass/'>Forgot your password?</a></p> "; include("./main.php"); // main markup template 3b. Create a /login/ page that uses the above template. 4a. Build a profile editing template that at least lets them change their password (but take it further if you want): /site/templates/profile.php // if user isn't logged in, then we pretend this page doesn't exist if(!$user->isLoggedin()) throw new Wire404Exception(); // check if they submitted a password change $pass = $input->post->pass; if($pass) { if(strlen($pass) < 6) { $page->body .= "<p>New password must be 6+ characters</p>"; } else if($pass !== $input->post->pass_confirm) { $page->body .= "<p>Passwords do not match</p>"; } else { $user->of(false); $user->pass = $pass; $user->save(); $user->of(true); $page->body .= "<p>Your password has been changed.</p>"; } } // display a password change form $page->body .= " <h2>Change password</h2> <form action='./' method='post'> <p> <label>New Password <input type='password' name='pass'></label><br> <label>New Password (confirm) <input type='password' name='pass_confirm'></label> </p> <input type='submit'> </form> <p><a href='/logout/'>Logout</a></p> "; include("./main.php"); 4b. Create a page called /profile/ that uses the template above. 5. Just to be complete, make a logout.php template and create a page called /logout/ that uses it. /site/templates/logout.php if($user->isLoggedin()) $session->logout(); $session->redirect('/'); 6. The above templates include main.php at the end. This should just be an HTML document that outputs your site's markup, like a separate head.inc or foot.inc would do, except that it's all in one file and called after the output is generated, and we leave the job of sending the output to main.php. An example of the simplest possible main.php would be: /site/templates/main.php <html> <head> <title><?=$page->title?></title> </head> <body> <?=$page->body?> </body> </html>
    1 point
×
×
  • Create New...