Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 07/11/2016 in all areas

  1. Hi! I've been making my first modules and I've created three so far to help me learn. I would love so feedback or pull requests for improvements as I hope to write a tutorial about my work soon. In particular the third modules isn't very finished. git: https://github.com/benbyford/PW-starter-modules/ HelloUserYouSaved - adds message {your user name, page saved} in admin when a page is saved. This module shows how to implement a basic module, get and use variables, create a message in the admin RedirectAdminPages - redirect specific user role to a custom page set in the module config. This module shows how to implement module configuration, using variables saved in the admin, redirecting a user using session->redirect() HotSwapUser - Swap user on the fly in the admin or frontend of your site This module shows how users can be used in a module how to set a user permission how to install / uninstall something within your module how to create a function that can be output in the frontend of your site.
    6 points
  2. You need a bootstrap script that should be located besides the PWs index.php. I have a template for that: After you have setup all your products, I would write a hook into the site/ready.php. Hook into before pages save, check if it is a productpage, if so, calculate the incl. vat price and populate it to the field, Ready!
    4 points
  3. Imho the best lightbox script out there: http://photoswipe.com/
    4 points
  4. You could write a beginner module about Fieldtype/Inputfield which accept a simple text, save it and render its markup . As Horst said, nice initiative !
    3 points
  5. Hi! Very good initiative! I have skimread through the code and my opinion is: The first and second ones looks good. But to be honest, this hotswap user thing is a big security issue. Sorry! Also only for demonstration / tutorial purposes, it is better not to use hot user swapping as a thema. The audience for beginner tutorials often will be, yes, the name says it: beginners. And assumed they simply do not know about such security issues and best practices in regard of how to validate user-inputs, you should not show code like this to them. At least you would need to embedd all security relevant stuff too. But then it fastly will become to complex for a beginner tutorial. A good one would be to only pick up how to validate user inputs and how PW provides good tools for that. (type and format validation, whitelist matching, ...) With your code, everyone can login with each existing account (also Superuser) just by knowing / trying (multiple til endless!) user name(s). In regard to this, you may have a look into ALIF or TracyDebugger, how the security for this is tackled there. I hope you do not mind me my frankness. ------------- Looking to the code of the users redirect module, you can shorten it a bit. When found a matching user / role, you don't need to store true in a temporary var, break the loop and then check the temporary vars value / state, if you should redirect the current user. You simply can redirect the current user if a role matches: /* * ___renderPageRedirect * * redirect user to page if current user role found in config */ public function ___renderPageRedirect($event) { // check to see if current page = admin template page // otherwise: early return! if($this->page->template != "admin") { return; } // find roles set in module configuration and create array $roles = explode(',', $this->userRoles); // for each user in module config check to see if current user foreach ($roles as $key => $val) { $roles[$key] = trim($roles[$key]); // if current user found then redirect = true if($this->user->hasRole($roles[$key])) { // this will leave the page and code immediately! $this->session->redirect($this->redirectPage); // stop user search break; // this can stay in here, just as fallback, // if something went wrong with calling the redirect, // but normally this line will not get executed. } } }
    3 points
  6. hey adrian, what do you think of adding a tracy ON/OFF switch that is displayed as a little badge on every page. tracy makes pageloads a lot slower on my system and that can be really annoying when developing a site (like setting up some fields/templates). i know there's horsts ALIF module, but i don't really want to install another module just for that purpose and i think it would be better if tracy handled this on its own. also ALIF is only available in frontend, right? this button would make sense both in front- and backend.
    3 points
  7. Thank you Flydev. I've spent several days looking for proper solution to the PW BS3 dropdown menu issue. And then today I've found this. This profile will be my based from now onward. So far it works good, looking forward to build something great out of this. Once again TQVM.
    3 points
  8. Have made some updates to ALIF: 1.1.0 fixed a bug in method sanitizeColor() 1.1.1 added detection and a toggle button for TracyDebugger (enable/disable) 1.1.2 more security for User-Switcher, (stays in for cases, where TracyDebugger isn't available) http://modules.processwire.com/modules/admin-links-in-frontend/
    3 points
  9. @mrkhan You are not handling the uploads correctly at the moment, take a close look at the first comment on the page horst pointed you to. It shows you what you need to know about handling file uploads. You should not trust the file-name supplied by the upload so that example shows you how to validate that the file was supplied via an upload (using the move_uploaded_file() function) how to name it without having to trust the supplied file name how to validate the mime type of the file how to append the extension that represents the file type of the uploaded file You just need to remember the name you gave it when you moved it and attach that to your outgoing email. I've updated part of the code from the comment I linked to so that you can see how you might generate the new name and extension. // You should name it uniquely. // DO NOT USE $_FILES['upfile']['name'] WITHOUT ANY VALIDATION !! // On this example, obtain safe unique name from its binary data. $new_name = "./uploads/" . sha1_file($_FILES['upfile']['tmp_name'] . ".$ext"; if (!move_uploaded_file($_FILES['upfile']['tmp_name'], $new_name))) { throw new RuntimeException('Failed to move uploaded file.'); } // Now attach the uploaded, validated & renamed file to your email. $mail->attachment($new_name); You'll need to tailor the code to do the needed validation on both of the files you want your users to upload of course. Don't forget to change where you want the files copied to as well.
    3 points
  10. Rather than having two price fields... price price_including_vat ...have you considered having one price field and one VAT rate (%) field? price vat_rate And then you calculate the VAT inclusive price on-the-fly. Seems like it would be easier to maintain this way.
    2 points
  11. If you won't need any markup you can use strip_tags(). Otherwise it will be a bit more complicated.
    2 points
  12. A simple fieldtype might be "Name", where you enter a firstname and a lastname, which is stored separately and maybe a computed property for the fullname. I think it shouldn't hold more values, as it'll probably become complex just for the amount of fields. Also interesting might be other often extended core classes/modules like Process or Textformatter, with the latter actually being quite simple with often just a single method.
    2 points
  13. I've not used it myself, but this one does also support lot's of different modes: http://chocolat.insipi.de/
    2 points
  14. Hi @kibod , glad you like it and choose it as project starter. And yes in this profile you can have the first parent as menu, clickable.
    2 points
  15. First set it up with plane html, css and js. Use the examples on the owl carousel website. Once you have that part working you can import it into processwire.
    2 points
  16. MarkupGoogleRecaptcha Google reCAPTCHA for ProcessWire. This module simply adds reCAPTCHA V2 or Invisible reCAPTCHA to your form. How To Install Download the zip file at Github or from the modules repository Drop the module files in /site/modules/MarkupGoogleRecaptcha In your admin, click Modules > Refresh Click "install" for "MarkupGoogleRecaptcha" Official install/uninstall doc: http://modules.processwire.com/install-uninstall/ API You must create an API key prior to use this module. Goto https://www.google.com/recaptcha/admin to create your own. Next, add the API keys information to the module's settings. Usage Call the module : $captcha = $modules->get("MarkupGoogleRecaptcha"); Call $captcha->getScript(); somewhere to get the javascript used by reCAPTCHA Render reCAPTCHA in a standard HTML <form></form> by calling $captcha->render() or Render reCAPTCHA in an InputfieldForm by passing as argument your form to the render function: $captcha->render($form) Call verifyResponse() to get the result. It return TRUE if the challenge was successful. Example Using ProcessWire's form API : $out = ''; $captcha = $modules->get("MarkupGoogleRecaptcha"); // if submitted, check response if ($captcha->verifyResponse() === true) { $out .= "Hi " . $input->post["name"].", thanks for submitting the form!"; } else { $form = $modules->get("InputfieldForm"); $form->action = $page->url; $form->method = "post"; $form->attr("id+name", "form"); $field = $this->modules->get('InputfieldText'); $field->name = "name"; $field->placeholder = "name"; $form->add($field); // CAPTCHA - our form as argument, the function will add an InputfieldMarkup to our form $captcha->render($form); // add a submit button $submit = $this->modules->get("InputfieldSubmit"); $submit->name = "submit"; $submit->value = 'Submit'; $form->add($submit); $out .= $form->render(); // include javascript $out .= $captcha->getScript(); } echo $out; Example using plain HTML Form : $captcha = $modules->get("MarkupGoogleRecaptcha"); // if submitted check response if ($captcha->verifyResponse() === true) { $out .= "Hi " . $input->post["name"] . ", thanks for submitting the form!"; } else { $out .= "<form method='post' action='{$page->url}'>\n" . "\t<input type='text' name='name'>\n" . $captcha->render() // render reCaptcha . "\t<input type='submit'>\n" . "</form>\n"; $out .= $captcha->getScript(); } echo $out;
    1 point
  17. This module provides a very simple interface to a set of named counters. You simply call a single function, next('name'), to pull the next value out of a counter - or to set it up if it does not yet exist. Next() takes a few extra parameters to allow you to increment by values other than 1 or to start at a certain number. This provides some similar functionality to the built-in page naming feature of PW, and to this module recently posted by Stikki but I think it offers a little more flexibility than either. Having said that, I do like the simplicity of Stikki's new auto-increment module. Module Availability Here is my module on Github. Here it is in the module repository. Example Usage Here's how this module can be used to title and name a new page by adding a couple of simple hooks to site/ready.php. This example applies to new pages using a template called 'invoice' that can be quick-added to the page tree. In order to get the following to work, you must edit the template that will be the parent of the 'invoice' template and setup the template for children to "invoice" and set the "Name Format for Children" field to something other than the default blank value (I use title as my value.) <?php /** * Function to recognise our special template. */ function isInvoiceTemplate($template) { return ($template == 'invoice'); } /** * Pre-load the page title for invoice pages with a unique value * which includes a counter component. */ $pages->addHookBefore("Pages::setupNew", function($event) { $page = $event->arguments(0); $is_invoice = isInvoiceTemplate($page->template); $no_inv_num = $page->title == ''; if ($is_invoice && $no_inv_num) { $counter_name = 'WR-' . date('Y'); $number = $this->modules->get('DatabaseCounters')->next($counter_name, 10, 5000); $page->title = $counter_name . '-' . sprintf("%06u", $number); } }); /** * Prevent ProcessPageEdit from forcing an edit of the name if we got here * through a quickAdd from ProcessPageAdd. We can do this because we * preset the title field in the Pages::setupNew hook. */ $pages->addHookAfter("ProcessPageEdit::loadPage", function($event) { $page = $event->return; $is_invoice = isInvoiceTemplate($page->template); $is_temp = $page->hasStatus(Page::statusTemp); if ($is_invoice && $is_temp) { $page->removeStatus(Page::statusTemp); $event->return = $page; } }); Note, the above code + module is one direct solution to the problem posted here by RyanJ. Version History 1.0.0 The initial release.
    1 point
  18. I'm no expert in this, but the way I see it is you have a base price and then one or more 'modifiers' that act on the base price. A modifier could be a tax rate, an export tariff, an addon handling fee for a large item, or something else. You don't work out the results of these modifiers for each base price ahead of time, you just apply them using PHP math operations as needed depending on what options the website visitor has selected. I think the performance impact of basic math operations like this would be negligible.
    1 point
  19. great! this worked for me. i needed <br> $text = strip_tags($article->body, '<br>');
    1 point
  20. It says 500. https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/Selectors.php#L24
    1 point
  21. hi adrian, i'm running pw 3.0.24 on vagrant. it doesn't make a difference which panels are active. but overall its a difference of 5.27sec WITH tracy and 1.4sec WITOUT it maybe my loadings help?
    1 point
  22. Glad you had success by that combination. I think it is important if you have the ToDo panel enabled to exclude any external js/css libraries by putting them in a separate parent folder. Just to clarify - you say ToDo wasn't enabled in the settings but was showing on the bar - did you fix by clicking "Reset" on the Panel Selector? If so, then it must have been enabled via the "Sticky" option at some point. I have been thinking about adding this - sounds like a good idea. I am sorry to hear that it is slowing down page loading for you though. Can you narrow it down to a specific panel (look at generation times in the Panel Selector Panel). Also, did you by chance change the Max Nesting Depth setting in the config from the default of 3? I am in discussion with Ryan about this - there is some recursion going on that definitely slows things down for me if I make it larger than 3.
    1 point
  23. Thanks very much @Robin S & @horst, excellent options. I think the hide/unhide will be perfect for now. I'll look into hooks at a later date. Appreciate it!
    1 point
  24. Hi, you could use digits https://get.digits.com https://github.com/mgufrone/digits-php Cheers
    1 point
  25. Hi Horst! Thanks for you code amends, will alter now. I totally agree with you, the third module not really beginner level and needs a heck load more work on it before anyone was to actually use it. The security aspect I'm looking at next and thanks for those links. Bar the first module, I was trying to make modules that didn't already exist that would be useful and interesting for me to make and had aspects I could teach. If you have any more suggestions for a third module whcih doesn't already exist then I'm all ears. Thanks,
    1 point
  26. Your welcome, glad it worked out
    1 point
  27. 1) Right, I don't have ToDo enabled, but it still loads all 1000 warnings 2.) OK - yes there is a massive horde of js files inside my templates folder, because I have a /themes/ folder and inside there are like 5 themes, each with a ton of css and js files, and probably a lot of those are not UTF-8 I will go ahead and exclude everything now and see what happens (can't test much because it takes about 10 minutes to render the page with warnings!) EDIT: SUCCESS I disallowed a bunch of directories and i didn't have ToDo enabled in the module settings, but it was loading on the bar, until i actually went and turned of off from the bar; so now it all works, and the ToDo was actually loading, though i have it disabled now, will check it out later...
    1 point
  28. okay I was going to complain and argue "but what's the difference..bla bla.." but then I thought.."what ever just try it out" So now I'm having a running staging version on it's own subdomain..so exact clone of the live version but already updated to 3.0.25 only thing I needed to fix cookies by setting session name to default $config->sessionName = session_name(); YIPPIIEEEH!!!!! THANKS A LOT pwired!
    1 point
  29. Well that would make "/*! ... */" type comments disappear from the panel as currently this is the only way to include them. On minification these are kept in place. Of course I add comments to non-minified file but my templates pull the .min version of them which are generated on saving the files. Plus my src files are outside of /site directory so Tracy won't pick their comments up.
    1 point
  30. Once more but last one too: I strongly suggest to read the php docs on how to upload files: http://php.net/manual/en/features.file-upload.php
    1 point
  31. Yes you get random names because you assigned them to your variables. If you don't like them, don't assign them. $photo=$filetemp = $_FILES["photo"]["tmp_name"]; This has nothing to do with my module nor with PW. I suggest to follow up with the php docs on how to upload files, followed by how to use it with PWs WireUpload class. There you also have validation options for filetypes. IMO this is essential knowledge in regard of security to your website. Open it for uploads must be done in a secure way. Therefore you must understand, at least to a small extend, what you are doing.
    1 point
  32. @flydev Thanks for the contribution! Sooner or later everyone needs a good (re)CAPTCHA.
    1 point
  33. FYI, the ToDo panel shows the entire jQuery minimized file contents because it starts with this comment: /*! jQuery v1.11.3 | (c) 2005, 2015 jQuery Foundation, Inc. | jquery.org/license */ To make it disappear, just delete the exclamation mark. Edit: seems that it's not the case with newer jQuery's but as of v1.11.3 it's showing up
    1 point
  34. Assuming you're usine Apache, it's better to use Options +Indexes, without the + you may reset other apache directives that are currently in effect. Take a look about 2/3 of the way down this page: https://httpd.apache.org/docs/2.4/mod/core.html#options
    1 point
  35. That's correct! This is one more example on how things grow in our community: we work together to make it as good as we can. Someone come up with a good solution for a partial thing. This a) directly help others, it b) inspires other users to new / other solutions, and this, in the end, makes working with our beloved PW a little more better again. And, in this case, (ALIF and Tracy): from now on, everytime when I will use Tracy, I will have the feeling that a little part of my work is into it.
    1 point
  36. Hi Barido, Welcome to the ProcessWire forums. I think there will be a number of solutions you can choose from. A few that occur to me are below. 1. Without using any modules and just working with the default Pages tree, you could use either the Published/Unpublished state or the Hidden/Unhidden state of the job page to switch a job from Active to Inactive (or vice versa). These states can be set directly from the Pages tree without needing to open the page for editing, as shown in the screenshot below. If inactive jobs need to be shown on the website front-end then the Hidden/Unhidden state would be the one to go with. In your templates you can test for the hidden state using the $page->isHidden() method. 2. You could use the Batch Child Editor module to toggle the Published/Unpublished or Hidden/Unhidden state. 3. You could purchase the Lister Pro module. This module has a number of cool features, one of which is the inline editing of page fields directly in the page list. So if you wanted to use a checkbox field in the job page to store the active/inactive state you could toggle this field via Lister Pro.
    1 point
  37. The latest version adds a new User Switcher panel that lets you instantly switch to any user (or logout) and then easily switch back to your superuser account. It is fairly similar in functionality to the user switcher in @horst's excellent ALIF module, but has the advantage of making the Tracy debug bar available when switched to any user and even when logged out, which can be very useful for debugging. Obviously there are some security concerns when setting up functionality that can log into other accounts without needing a password. There are several things this panel does to make this safe(r), but the key thing to remember is that setting Tracy to Production mode keeps you safe! It is completely disabled unless Tracy is specifically set to Development mode. Detect mode won't work and even the "Superuser Force Development Mode" option won't enable it so you can be sure your live sites are safe unless you specifically enable Development Mode for a debugging session. You need to be a superuser to have access to the panel until a session is started, so even when Development mode is enabled, other users still won't be able to use it. It only works for the duration of user switcher session (max 60 minutes) and only a superuser can start a session. Starting the session makes use of PW's CSRF protection. The switcher session has a unique ID and expiry time which is stored in the database and must match the ID in the user's session. Once the session has expired, it is no longer possible to switch users. You can manually end the session, or if you forget it will expire automatically based on the session length you set. As usual, icon colors are meaningful telling you what type of user is currently logged in: Green: superuser Orange: non-superuser Red: guest / logged out Please let me know how you go with this new panel - hopefully it will be a significant timesaver when checking/debugging your site from other user roles. Also, if you think of any improvements that could make this more secure, or useful, please let me know. I would definitely appreciate an extra set of eyes (or two) to take a look! This new version also has the following changes: It removes the need for the separate helper process module for executing the Console Panel code - it will be uninstalled during the upgrade. I have removed the "Debug Statements" tool in the config settings - I think this is superfluous now that you can easily add debug statements to template files dynamically using the Template Editor Panel. If anyone really wants this back, let me know. There is also significant cleanup of other sections of code, so please let me know if you notice any issues from these changes. Have a great weekend!
    1 point
  38. @cstevensjr Got your point and totally agree with what you're saying. I didn't mean to force anybody into using preprocessors. Just wanted to encourage people to start looking into it because it really can make live easier...
    1 point
  39. You seem to be stuck on sass and I am talking about having PW profiles that a basic beginner (who may or may not know anything about sass) can utilize. We are coming together from two totally different planes. Yes, I believe it was fantastic and a good trend that @flydev augmented the profiles by including the precompiled version. It should be a great learning tool for all.
    1 point
  40. While I agree with you that one needs to expand their horizons, we also need to understand that not everyone uses the latest technology. We should strive to make these profiles accessible to everyone, no matter their knowledge/skill level. My push will always be about accessibility to technology by all. I firmly believe that's how things will spread.
    1 point
  41. @flydev Thanks a lot for putting this together. I was only waiting for BS4 to reach beta state before I will update my site-pwbs profile. Now I don't need to spend the time on it myself, which is great @pwired @cstevensjr I can only recommend to preprocess yourself and encourage you to look into node, compass, bower etc. It really is worth the effort and gives you so much more flexibility. With the precompiled version of this profile, you need to override a lot of stuff in your own CSS and this will bloat your code.
    1 point
  42. Thanks you for trying this profile. I just pushed an update to the css for the responsive menu. Just remove the following code in main.css.
    1 point
×
×
  • Create New...