Jump to content

The G

Members
  • Content Count

    30
  • Joined

  • Last visited

Community Reputation

28 Excellent

About The G

  • Rank
    Jr. Member
  • Birthday 06/02/1968

Profile Information

  • Gender
    Male
  • Location
    Bucharest, Romania

Recent Profile Visitors

1,727 profile views
  1. The module's output uses the same function (renderHeadContent) : <script defer src='{$this->wire('modules')->get('ProCache')->js($this->getJsFile())}'></script> One way to insert just the JavaScript URL in your array would be to check "Render Banner and Header Content Manually" and to use $modules->get('PrivacyWire')->getInlineJs() and $modules->get('PrivacyWire')->getJsFile() instead of $modules->get('PrivacyWire')->renderHeadContent().
  2. I don't think that the file you see requested comes from the module. Pro Cache should automatically merge and minify PrivacyWireUnstyled.js. Did you took out the code you added in the templates and cleared the cache afterwards? Try uninstalling the module and see if you still have PrivacyWireUnstyled.js requested. Don't forget to clear the cache after any change.
  3. Hmm, I think you didn't read the instructions carefully enough. Did you notice a "Use ProCache JS Minification (if available)" checkbox near the end of the settings? Not tried it myself, but AFAIK you don't need to mess with other settings if what you want is just ProCache minification. Try this: uncheck "Render Banner and Header Content Manually", take out the code you manually inserted into the templates and check "Use ProCache JS Minification (if available)". Regarding CSS: styles are inserted by JavaScript (PrivacyWire.js), so no module CSS file is needed. If you choose the unstyled version, the module will load PrivacyWireUnstyled.js instead leaving the styling up to you (I chose to use the unstyled version and insert the needed styles into my main CSS file, since it will be loaded on every page. Either way seem good solutions to me - the styles are only needed together with the JavaScript. Off-topic: I'd love an inline code plugin for the forum's editor.
  4. You have the "Render Banner and Header Content Manually" option in the module settings. After checking it you can insert the module generated code wherever you'd like. The script tags are generated by the folowing snippet: $modules->get('PrivacyWire')->renderHeadContent() Disclaimer: didn't tested my suggestion, this is just what I saw in the module's code. Why would you want to include both PrivacyWire.js and PrivacyWireUnstyled.js? AFAIK they only differ in including or not the module's CSS for the frontend. Including PrivacyWireUnstyled.js would only waste resources if PrivacyWire.js is included.
  5. I tried to disable or hide a "Remember me" checkbox. My HTML is <div class="field has-text-right"> <label class="checkbox"> <input type="checkbox" name="rememberme" value="<?=(int) input()->cookie->rememberme?>"> <?=__('Remember me')?> </label> </div> The code I'd prefer would be (notice the two "disabled" attributes on the label and the input) <div class="field has-text-right"> <label class="checkbox" disabled> <input type="checkbox" name="rememberme" value="<?=(int) input()->cookie->rememberme?>" disabled> <?=__('Remember me')?> </label> </div> Although I could live with only hiding it, which is what I've tried by adding data-category="functional" data-ask-consent="0" data-ask-consent-rendered="1" to the div, the label or the checkbox. And it hides them all right. The issue is that PrivacyWire does not care about innerHTML of my poor div, or about its class. I changed o.innerText=e.innerText with o.innerHTML=e.innerHTML directly into js/PrivacyWireUnstyled.js and I got my checkbox back, but without its initial class. I think it is the code at line 231 in src/js/PrivacyWire.js. I know almost no JavaScript, so start throwing tomatoes - in the priw_updateAllowedElement there is no way to let the old element live instead of copy into a new one > insert the new one in the DOM > delete the old one? Also, it feels to me that flipping between two attributes or two CSS classes should be all PrivacyWire needs to do in regard to the elements that need consent. LATER: hmm, maybe not in regard to scripts. Leaving for the coffee machine...
  6. So, excited to use the updated version as I was, there was no time for RTFM - even if there was clearly written without leading slash , I merrily entered /site/templates/modules/PrivacyWire/PrivacyWireBanner.php and BANG!, ProcessWire shouted at me for wanting to use a not allowed path (because of the resulting double slash). I'm still trembling! Since it breaks so hard, I'm wondering if the input could be somehow forced to loose the leading slashes forgotten by irresponsible people like yours truly. Sadly, I'm not well versed (yet!) in module configuration input validation/modification. Or at least, write "without leading slash" in bold letters πŸ˜…
  7. Nice work! Question: I'm finding myself in need of many changes in the banner template, so I had to hook-replace the module's 'render' method. Would be useful to isolate the path retrieving code in separate hookable functions? Like this: /** * checks for a banner template alternate path * @return string the path of the banner template file */ public function ___getBannerTemplate() { return $this->wire('config')->paths->$this . 'PrivacyWireBanner.php'; } /** * checks for a javascript file alternate path * @return string the path of the banner template file */ public function ___getJsFile() { return ($this->add_basic_css_styling) ? $this->wire('config')->urls->$this . "js/PrivacyWire.js" : $this->wire('config')->urls->$this . "js/PrivacyWireUnstyled.js"; } Then, I could use it (I am using it, actually) like this (in /site/ready.php): // my front pages are all extending a FrontPage class // see https://processwire.com/blog/posts/pw-3.0.152/#new-ability-to-specify-custom-page-classes if (page() instanceof FrontPage) { $wire->addHookAfter('PrivacyWire::getBannerTemplate', function ($event) { $event->replace = true; $default_path = $event->return; $filename = pathinfo($default_path, PATHINFO_BASENAME); // my override is in /site/templates/modules/PrivacyWire/PrivacyWireBanner.php $override_path = paths()->templates.'modules/PrivacyWire/'.$filename; $event->return = is_readable($override_path) ? $override_path : $default_path; }); } Or even simpler (for me πŸ˜‚), those could be two new config keys, like 'alternateBannerTemplate' and 'alternateJsFile'. This would also cover the case of needing to change the header tag, so it could be dropped (just a thought, don't hit me in the head, you valiant head tag config defenders 😁).
  8. In my case the Warning: Illegal offset type in /var/www/html/site/modules/ProcessBlog/ProcessBlog.module on line 917 Warning: Illegal offset type in /var/www/html/site/modules/ProcessBlog/ProcessBlog.module on line 918 messages were probably caused by the page()->outputFormatting setting being "Off", and were fixed by casting (string) on the array keys: 915 $list = array( 916 (string) $posts->title => array('published' => $qn['blog-post'], 'unpublished' => $qn['unpublished'] ), 917 (string) $comments->title => array('approved' => $numApproved, 'pending' => $numPending, 'spam' => $numSpam ), $categories->title . ' & ' . $tags->title => array('categories' => $qn['blog-category'], 'tags' => $qn['blog-tag'] ), 918 );
  9. Nice, it works beautifully. The duration. I'd like to let the user read the message for a little longer: Off-topic question: how does one make posted videos to not extend to the full container width? I used the annoying GIF above because I didn't find a way to display posted videos at their real size.
  10. After the user saves his/her choices, a confirmation message is shown for 1.5 seconds, then is removed. My contact page uses Google Recaptcha and thus it needs Google's marketing cookies to work. So, in the beginning, instead of the contact form, the page shows only a message explaining that if one wishes to use the contact form, one needs to consent to the marketing cookies. Only after/if the user consents is the form shown. I wanted to have the page refreshed after saving the choices, so the user would not need to do a manual refresh to see the changes. I did it by adding a 74 window.location.reload(true); line after 73 priw_wrapper.classList.remove('show-message'); which is the one where the confirmation message is removed (priw_showMessage(), line 73 in src/js/PrivacyWire.js) and re-rollup-ing. I could make a pull request if it seems useful. Another suggestion would be make the setTimeout delay configurable. This one is not something I needed, but it just feels right to have it configurable 😁
  11. I 've done a pull request against the v2 branch, only three underscores added πŸ˜„ This is how I hooked it in ready.php (these are theme specific overrides, so I want to keep them in the /site/ folder somewhere): // If I want to do something with front pages (old code) //if (strpos($_SERVER['REQUEST_URI'], $config->urls->admin) !== 0) { // my front pages are all extending a FrontPage class // see https://processwire.com/blog/posts/pw-3.0.152/#new-ability-to-specify-custom-page-classes if (is_subclass_of(page(), 'Processwire\FrontPage')) { // [...] $wire->addHookBefore('PrivacyWire::render', function($event) { $event->replace = true; $privacywire = $event->object; $isProCache = modules()->isInstalled('ProCache') && modules()->get('ProCache'); $jsFilePath = getModuleFile($privacywire, 'js/PrivacyWire.js', true); if ($isProCache && $privacywire->use_procache_minification) { $jsFilePath = modules()->get('ProCache')->js($jsFilePath); } $output = wireRenderFile(getModuleFile($privacywire, 'PrivacyWireBanner.php'), [ 'module' => $privacywire ]); $output .= "\n<script>var PrivacyWireSettings={version:'{$privacywire->version}',dnt:'" . ((int) $privacywire->respectDNT) . "'};</script>"; $output .= "\n<script defer src='{$jsFilePath}'></script>"; $event->arguments(0)->return = str_replace("</body>", "{$output}</body>", $event->arguments(0)->return); }); // [...] } /** * checks for a module file override in the path defined * @param object $module the module needing a file overriden * @param string $file_path the override file path, from the module folder, i.e. "js/PrivacyWire.js" * @param boolean $is_url switch for outputting a path or an URL, by default the function outputs a path * @return string the override path is it's readable or the initial file path if it's not */ function getModuleFile($module, $file_path, $is_url = false) { // we're putting module overrides in /site/templates/modules/ $override_dir = 'modules/' . $module->className() .'/'; $override_path = paths()->templates . $override_dir . $file_path; // we're overriding files in the module's folder $default_path = paths()->$module . $file_path; if (is_readable($override_path)) { return $is_url ? urls()->templates . $override_dir . $file_path : $override_path; } return $is_url ? urls()->$module . $file_path : $default_path; }
  12. Ah, but of course! How could I forget about hooks! Thank you, @horst! I realize now that I could probably keep all my overrides in a single place, depending on the presence of the hooks, of course. @joshua, please make the render() function hookable. Sometimes I wish ProcessWire could be more restrictive, my /site/ folder is a frankensteinish patchwork of code snippets, because I used whatever the search cat dragged in first 🀣
  13. Hello gentlemen and thank you for your fine module, Joshua! Is there a way to preserve the changes to the HTML/CSS of the banner after updates? Maybe there is a generic processwirish way to override module markup? Right now I added a method to the module that allows me to replace the module's markup by placing the modified files in /site/templates/MODULE_DIR/: protected function getFile($file, $is_url = false) { // we're putting module overrides in /site/templates/modules $override_dir = 'modules/' . basename(dirname(__FILE__)) .'/'; $override_path = $this->wire('config')->paths->templates . $override_dir . $file; // we're overriding files in the module's folder $default_path = $this->wire('config')->paths->$this . $file; if (is_readable($override_path)) { return $is_url ? $this->wire('config')->urls->templates . $override_dir . $file : $override_path; } return $is_url ? $this->wire('config')->urls->$this . $file : $default_path; } and using it like this: $jsFilePath = $this->getFile('js/PrivacyWire.js', true); and $output = wireRenderFile($this->getFile('PrivacyWireBanner.php'), [ 'module' => $this ]); This way I only have to add the above code into the module after the update, while keeping my changes in /site/templates/PrivacyWire/, to preserve the look of the banner, from the default to a Bulma version
  14. Disclaimer: please note that this is how I am doing it, it may or may not suit you, so take it with a grain of salt. Also, I apologize for not obeying ProcessWire's code style, I'm just too old and it feels alien to me. Thing I'm trying to get: not having to input the 'Custom Editor CSS File ...' and 'Custom Editor JS Styles Set ....' for each of the fields using CKEditor. Yeah, I know, call me lazy or sloppy or whatever, it is what it is πŸ˜„ . having the front end styles in the editor container, so the one editing the page would be able to eyeball the styling of the content while stayin in the editor For the first objective I tried to find a way in the CKEditor configuration options, like config.js, or at least a single point to set my options. In the end, what worked for me was hooking the Inputfield in ready.php: if (strpos($_SERVER['REQUEST_URI'], $config->urls->admin) !== 0) { // things I do to frontend pages, believe me, you don't want to know :D } else { $wire->addHookBefore('InputfieldWrapper::renderInputfield', function($event) { // process further if it is an InputfieldCKEditor if (strpos($event->arguments(0)->className(), 'InputfieldCKEditor') === 0) { // store the Inputfield $inputfield = $event->arguments(0); // my custom CKEditor options $my_settings = [ 'contentsCss' => '/site/assets/css/cke.css', 'contentsInlineCss' => '/site/assets/css/cke_inline.css', 'stylesSet' => 'mystyles:/site/modules/InputfieldCKEditor/mystyles.js', 'extraAllowedContent' => '*[id](*); audio[src,controls,preload]; source[src,type]; button[title]; script; i[data-feather]; svg[xmlns,height,width]; path[d,fill,stroke]', ]; // for each option, check if it's empty and if it is set it to the custom value foreach ($my_settings as $key => $value) { if (empty($inputfield->get($key))) { $inputfield->set($key, $value); } } // get the changes into $event $event->arguments(0, $inputfield); } }); } Now, my CSS files are generated by Sass in the /site/assets/css/ directory, because of the second objective. Thus, I'm including the frontend CSS in three places: the two custom CSS files used by CKeditor in regular/inline mode and defined above ('contentsCss' and 'contentsInlineCss' options), and my custom CSS file used by admin.php. The regular mode CSS files contains: // cke.sass - Sass syntax @import "main" where main.sass is my frontend Sass file (I have a real talent for names, I know). So it includes all the frontend styles in the regular CKEditor iframe. The inline mode CSS file contains: // cke_inline.sass .cke_editable_inline @import "main" This way the frontend styles are applied only to elements inside the CKEditor inline container. I know I'm tying myself to the CKEditor markup, but as you may have noticed by now, I'm quite eager to sell myself in slavery for a bit of convenience πŸ˜„ . The admin styles are built the same, changing only the container class and adding some styles to increase readability: // admin.sass /* force a min width for CKEditor combo, so I can read the text */ .cke_combopanel min-height: 21rem min-width: 25rem > iframe height: 100% !important .cke @import "main" The resulting /site/assets/css/admin.css file is loaded by /site/templates/admin.php by adding $config->styles->add($config->urls->assets.'css/admin.css'); before the require($config->paths->adminTemplates . 'controller.php'); line. Lo and behold, Bulma styles available in the editor toolbar and container (there's a short clip attached). Well, this should be it. I hope it helps someone. If you know a better way to do this or if you notice a mistake/omission, by all means, let me know. Thank you for following me until now - here's the medal you rightly deserve: πŸ₯‡ LATER EDIT: sorry about the video size, I swear it's just a little 578x472px video. ckeditor-2020-04-10-161245.mp4
Γ—
Γ—
  • Create New...