Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/04/2017 in all areas

  1. In this week's post we'll take a closer look at the importing side of our upcoming export/import tool. Plus we'll look at something new in 3.0.70 called markup region hints, which are worthwhile if you are using markup regions in PW3. https://processwire.com/blog/posts/pw-3.0.70/
    6 points
  2. Ok got it, you need to allow the anonymous function to "capture" local variables. Try the following ( note the use($f) ) : $byField = array_reduce($children->getArray(), function($carry, $child) use($f) { if(!is_object($child->$f) && !is_null($child->$f)) // avoid illegal offset type warning $carry[$child->$f][] = $child; // NO MORE ISSUE return $carry; echo count( $carry ); }, array());
    2 points
  3. The JquerySelectize module, that all of the other Selectize family modules require, has been updated (to version 1.0.1) as follows: 1) Checks to see if the core version is 3.0.67 or higher (version at which selectize was added to core), and if so, will load the core files, and not this module's files. Using the ProcessWire core versions of selectize.js improves the user experience, because of the adjustments that Ryan made to the plugin, which relates to hitting enter key after typing a tag (which would by default submit the form). 2) In addition to loading the CSS & JS from the core, when working in versions 3.0.67 or higher, the module still provides a skin selector. While most users will probably stick to the core non-skinned version of Selectize, the module provides this option to choose a different skin. There are some scenarios where choosing the default or bootstrap skins for selectize can be preferable, as they may be higher contrast or more pronounced with color usage, and can help in some ways with accessibility for users with any type of vision impairment. Currently the update/behavior only applies to Selectize modules family that require and use the JquerySelectize module, so if you are using core image tags and have this module installed, it won't change the skin; However there is a plan to try and hook into the image field rendering and enable this module to add the custom selected skin to the css files.
    2 points
  4. Hi @adrianmak You can achieve this by using hooks and my ReCaptcha module. First install the MarkupGoogleReCaptcha module then in file ready.php, write the following code : /* * replace the LAST occurence of $search by $replace in $subject */ function str_lreplace($search, $replace, $subject) { return preg_replace('~(.*)' . preg_quote($search, '~') . '~', '$1' . $replace, $subject, 1); } /* * replace the FIRST occurence of $search by $replace in $subject */ function str_freplace($search, $replace, $subject) { $from = '/'.preg_quote($search, '/').'/'; return preg_replace($from, $replace, $subject, 1); } $captchamod = wire('modules')->get("MarkupGoogleRecaptcha"); wire()->addHookProperty('Page::captcha', function($event) use ($captchamod) { $event->return = $captchamod; }); wire()->addHookAfter('Page::render', function($event) { $template = $event->object->template; $page = $event->object; if ($template == 'admin' && !wire('user')->isLoggedin()) { $captchaScript = $page->captcha->getScript() . '</body>'; $captchaHtml = $page->captcha->render() . '</form>'; $event->return = str_freplace('</form>', $captchaHtml, $event->return); $event->return = str_lreplace('</body>', $captchaScript, $event->return); } }); wire()->addHookAfter('Session::authenticate', function($event) { $page = wire('page'); $template = $page->template; if ($template == 'admin') { if ($page->captcha->verifyResponse() == false) { wire('session')->logout(); wire('session')->redirect(wire('config')->urls->admin); } } });
    2 points
  5. A few references to Hooks: https://processwire.com/api/hooks/ https://somatonic.github.io/Captain-Hook/index.html https://github.com/adrianbj/TracyDebugger/tree/master/panels/CaptainHook http://www.flamingruby.com/blog/using-hooks-to-alter-default-behavior-of-processwire/ https://webdesign.tutsplus.com/tutorials/a-beginners-introduction-to-writing-modules-in-processwire--cms-26862
    2 points
  6. This is deliberate and Ryan has talked about it but I don't have a link handy. Probably because there can be situations where a field contains a lot of data in which case the user should be notified of a problem but not have all their work thrown out. See this example from @Soma where he shows how you can set a field back to its previous value when you want to reject a submission:
    2 points
  7. I agree probably CSS. If I get a chance I'll dig through the issue deeper and see what I can come up with. Thanks for the reply, Macrura
    1 point
  8. Hi @Davidov There are two ways how to get it working $teacherItem->teacher_photo->first()->maxWidth(250)->url; Or change your image field setting to: And then you will be able to use your existing code
    1 point
  9. Processwire never stop to impress me! I love it ! Thank you @Robin S for your explications and your time!
    1 point
  10. To solve this you need to look at the code for each method you are considering hooking and ask yourself things like: What class is the method in? Does the method fire when I need it to? Does the method have an argument or return value that I need to use in my hook? So you are considering hooking ProcessLogin::afterLogin() or Session::loginSuccess(). When you look at afterLogin() you see: It is a method of ProcessLogin, a Process module that handles the PW login form. So it is only going to fire if a user logs in via the core PW login form. Maybe that isn't what you want if you are using a custom login form or logging in users via the API as part of some script. It depends on what you are doing. The method comments in the source code say it is only intended for when a superuser logs in, which could give you a clue if it is the best method to hook or not. It has no arguments that could be useful to quickly tell you things about the user who has logged in (although you could still get the $user object in other ways). So chances are Session::loginSuccess() is going to be a better option because it is a method of Session, so more closely connected to the current user session regardless of how they logged in. And it conveniently has the $user object as an argument so you can easily check properties of the user such as name, role, etc, in your hook.
    1 point
  11. Your module should be autoload in order to use that hook. See the autoload options for the getModuleInfo() method: https://processwire.com/api/ref/module/
    1 point
  12. Thanks for that. I've read it over a few times now but I'm not quite getting it. How is this unnecessary? How else would one determine where each permission is applicable? Does he mean you could create a separate permission for each template, e.g. page-edit-home page-edit-basic-page, etc.? Yes, yes, yes... THIS sounds like the type of solution I would expect from ProcessWire. Simple, powerful, and un-opinionated. What became of this?
    1 point
  13. Afternoon all, (or good morning or good night to those of you in other time zones) I am finally getting a chance to sink my teeth into ProcessWire (already purchased the Form Builder and ProFields) and I needed to make sure the output of one of my fields did not contain any curly quotes that my browser randomly changes regular quotes to when I'm editing the field. So I decided to try my hand at creating a Textformatter module to do just that. TextformatterReplaceCurlyQuotes is very simple but it's exciting for me to feel like I am contributing back to this great community. It was also nice for me to finally use my GitHub account as well...haha Anyway, I'm submitting it to the module directory and needed to post in a thread about it and here it is! http://modules.processwire.com/modules/textformatter-replace-curly-quotes/
    1 point
  14. Headings Case A plugin for CKEditor fields in ProcessWire CMS/CMF. Adds a toolbar button for changing the case of all headings or selected headings between sentence case and title case. This is useful when you are copy/pasting text from a document that has been supplied with an inconsistent or incorrect system of capitalisation. Installation The plugin folder must be named "headingscase" – if needed, rename the folder to remove the "-master" suffix added by GitHub. Copy the "headingscase" folder to /site/modules/InputfieldCKEditor/plugins/ In the field settings for each CKEditor field that you want to activate the plugin for: Check the "headingscase" checkbox at Input > Plugins > Extra Plugins Add "HeadingsCase" at Input > CKEditor Settings > CKEditor Toolbar Usage To change the case of all headings, click the toolbar button with no text selected in CKEditor. The first click applies sentence case; the second click applies title case. To change the case of a single heading, select all or part of the heading in CKEditor before clicking the toolbar button. There can be situations where the results need manual correction: proper names, acronyms, etc. Exceptions for small words Certain short English prepositions and conjunctions (three letters or less) are excluded from capitalisation when title case is applied. Edit the exceptions array in the plugin source code if you want to customise this list of exceptions. https://github.com/Toutouwai/headingscase
    1 point
  15. You have an option, don't call getScriptMulti(); function. <?php if(modules()->isInstalled('MarkupGoogleRecaptcha')) { echo modules()->MarkupGoogleRecaptcha->getScriptMulti(); }; ?> Write your own javascript by referencing getScriptMulti(); function. public function getScriptMulti() { $return = "<script type=\"text/javascript\"> var onloadReCaptchaCallback = function(){ jQuery('.g-recaptcha').each(function() { var _this = jQuery(this); var recaptchaID = _this.data('id'), hl = _this.data('hl'), sitekey = _this.data('sitekey'), theme = _this.data('theme'), type = _this.data('type'), size = _this.data('size'), index = _this.data('index'); if(recaptchaID !== undefined) { var recaptchaWidget = grecaptcha.render(recaptchaID, { 'hl' : hl, 'sitekey' : sitekey, 'theme' : theme, 'type' : type, 'size' : size, 'index' : index }); grecaptcha.getResponse(recaptchaWidget); // grecaptcha.reset(recaptchaWidget); } }); }; </script>"; $return .= "<script src='".self::SITE_RECAPTCHA_API_URL."?onload=onloadReCaptchaCallback&render=explicit' async defer></script>"; return $return; }
    1 point
  16. Yes, that's what exactly what this module is for. I also made a contact form and a sitemap with it and stuff like this Here's my sitemap form example: <?php $shortcode->add('sitemap', function($atts){ if($atts['page'] == '') { $atts['page'] = wire('pages')->get('/'); } else { $atts['page'] = wire('pages')->get('name='.$atts['page']); } function sitemapListPage($page) { echo "<li><a rel='follow' href='{$page->url}'>{$page->title}</a> "; if($page->numChildren) { echo "<ul>"; foreach($page->children as $child) sitemapListPage($child); echo "</ul>"; } echo "</li>"; } echo "<ul class='sitemap'>"; sitemapListPage($atts['page']); echo "</ul>"; }); ?>
    1 point
  17. Just want to clarify that it's not about hiding output, but about turning the formatting off. So your code would look something like this: <?php $page->setOutputFormatting(false); $page->comments->add($c); $page->save('comments'); $session->redirect("./"); // or $page->setOutputFormatting(true); Note that redirect at the end. It's not entirely necessary, but it's something that I like to do just so that I'm getting a fresh copy of everything and preventing the possibility of having the user hit reload and re-posting the same thing. If you don't do the redirect, then you'll want to turn outputFormatting back on again. Also note that you'll want to do all of this before you've output anything. So that means moving your comment saving code up above the code that outputs comments, as well as above any header includes or the like. This is only necessary if you are using the redirect, but I think it's a good idea either way because the comment the user just submitted could then become part of the output. If you are finding the comment is not getting saved, try a couple things that might help us to narrow down what's happening. First thing is to temporarily change your $page->save('comments') to $page->save(); If that doesn't make any difference, try adding $page->trackChange('comments'); before the save(). This is stuff you shouldn't have to do, but I'm hoping it might help us to debug.
    1 point
×
×
  • Create New...