Jump to content

bernhard

Members
  • Posts

    6,671
  • Joined

  • Last visited

  • Days Won

    366

Everything posted by bernhard

  1. Great, thank you adrian! I hope it also helps others ?
  2. Great! Yeah I just did a quick websearch and my link was the first result ?
  3. Yeah, I guess PW's module dependency features are too limited for such cases. I think you'd need to remove the dependencies in the module's info array and implement them on your own somewhere in the modules' install() and uninstall() methods.
  4. I've read my post above and I'm not sure if I was offtopic at that time or if my post 10min ago was not 100% correct. I'm working hard on my DateRange field though, so I've no time for digging into that. What is your exact scenario?
  5. It's triggered by all uninstalls of modules that are based on the main module (like RockTabulator is based on RockMarkup2). And those modules extend the main module and therefore the init method is called on every load of the submodule.
  6. Hi @Gadgetto you can have a look here: https://github.com/BernhardBaumrock/RockMarkup2/blob/c184febcd92c75b329b9eba1e2b53caa088e0a94/RockMarkup2.module.php#L110 Does that help?
  7. Thank you very much adrian, not exactly, because that won't work on the last line where $out is prepended by "d(". But I found a list of shortcuts ? https://defkey.com/ace-editor-shortcuts It's CTRL-ALT-left/right Not sure if that is an official list, but it might be nice adding a link to the console or inside the keybord shortcuts popup?
  8. I'm sorry, I was not precise enough! ? See this example: The cursor is on the first $out variable and all other occurrances are outlined, so I guess there is a way to select all of them (VSCode CTRL+F2) or one by one (VSCode CTRL-D). This is how it looks in VSCode:
  9. Does anybody know the keyboard shortcut for the multi-cursor feature of ACE? I'm using CTRL-D in VSCode but that does delete the current line in ACE. Multicursor does work though, because I can select multiple items using CTRL+click. Thx!
  10. From my linked post: https://processwire.com/talk/topic/17346-hook-on-repeater-field-save/?do=findComment&comment=152504 ProcessWire has a feature to track changes. If there are no changes unneeded hooks do not get fired. This is not only better for performance (I guess) but also great for conditional hooks: https://processwire.com/blog/posts/new-ajax-driven-inputs-conditional-hooks-template-family-settings-and-more/#new-conditional-hooks
  11. https://www.google.com/search?q=site:processwire.com+hook+repeater
  12. Just updated the readme with an example of page cropping marks and bleed margins sometimes necessary for printing: Page margins for print with cropmarks // thx to https://stackoverflow.com/a/50245034/6370411 $pdf = $modules->get('RockPdf'); $pdf->settings([ 'mode' => 'utf-8', 'format' => [214, 301], 'img_dpi' => 300, ]); $pdf->write(' <style> @page { /* regular A4 paper size is 210x297 */ size: 211mm 298mm; /* trying some weird format to make sure it works */ marks: crop; } </style> Content '); d($pdf->save()); You see that the Trim Box shows our custom values 211x298 whereas the bounding box would show the paper size (214x301). Real life example using RockPdf and RockLESS // parts of RockPdfCalendar module public function init() { $this->w = $w = 420; // paper width in mm $this->h = $h = 297; // paper height in mm $this->b = $b = 2; // bleed in mm /** @var RockPdf $pdf */ $pdf = $this->modules->get('RockPdf'); $pdf->settings([ 'mode' => 'utf-8', 'format' => [($w+2*$b), ($h+2*$b)], 'dpi' => 300, 'img_dpi' => 300, ]); $this->addBackground($pdf); $this->addStyles($pdf); $this->pdf = $pdf; } /** * Add Background PDF * @return void */ public function addBackground($pdf) { $page = $this->pages->get("template=settings"); $pdfs = $page->getUnformatted('calendarbackground'); if(!$pdfs OR !$pdfs->count()) return; // no field or no file $pdf->set('SetDocTemplate', $pdfs->first()->filename); } /** * Add styles */ public function addStyles($pdf) { /** @var RockLESS $less */ $less = $this->modules->get('RockLESS'); $less->vars = [ 'w' => $this->w."mm", 'h' => $this->h."mm", 'b' => $this->b."mm", ]; $css = $less->getCSS(__DIR__ . "/style.less")->css; $pdf->write("<style>\n$css</style>"); } Then all you have to do is call $modules->get('RockPdfCalendar')->show() to render the pdf in the browser ?
  13. I've added a feature to define the link to the issue in the fix and also the author (github user) <?php namespace ProcessWire; class Foo extends PWFix { public $label = "My foo label"; public $description = "My foo description"; public $issue = "https://github.com/processwire/processwire-issues/issues/xxx"; public $author = "BernhardBaumrock"; // github user public function init() { // fix goes here } }
  14. Did I already mention that I don't like repeaters? ? Glad you sorted it out ?
  15. How crazy is that piece of software called ProcessWire?? Exact matches are now possible using the string notation of date ranges. Writing this down and looking at the screenshot I realize that it would make a lot of sense to be consistant in the format when transforming a RockDaterange object into a string and vice versa. Amount of code necessary to support this? 10 Lines ?
  16. I had to do several page imports via Tracy Console today, so I had the challenge of populating the Daterange field easily via the API... I added support for basic daterange parsing from a given string: RockDaterange("22.02.2020") hasTime => false hasEnd => false fromH => "22.02.2020 00:00" (16) toH => "22.02.2020 23:59" (16) RockDaterange("22.02.2020 17:00 - 19:00") hasTime => true hasEnd => true fromH => "22.02.2020 17:00" (16) toH => "22.02.2020 19:00" (16) RockDaterange("22.02.2020 17:00 - 20-3-1 19:00") hasTime => true hasEnd => true fromH => "22.02.2020 17:00" (16) toH => "01.03.2020 19:00" (16) And it get's even better! This makes it possible to use $page->setAndSave() easily using string dateranges: $page->setAndSave('range', "2020-02-22"); // single full-day event $page->setAndSave('range', "2020-02-22 18:00"); // single day event with time $page->setAndSave('range', "2020-02-22 18:00 - 22:00"); // single day event with time range $page->setAndSave('range', "2020-02-22 - 2020-02-24"); // 3-day event (full-day) $page->setAndSave('range', "2020-02-22 06:00 - 2020-02-24 23:00"); // 3-day event with times You wonder how complicated that was to implement?! Once the parsing part was done it was nothing more than adding this one line to the sleepValue method of the fieldtype. How genius is ProcessWire?? ? public function sleepValue($page, $field, $value) { if(is_string($value)) $value = new RockDaterange($value); ... --- This is how I did the recurring events so far ? Got an excel from the client with page id of the master event and date + time of the recurring events. Using VSCode and multicursor I transferred this into a script to create pages: The save() call at the end of each line would not be necessary but triggers a hook that renames the page and adds the daterange to the URL. This prevents ugly urls like this /event-x /event-x-1 /event-x-1-1 /event-x-1-1-1 And creates URLs like this instead: /event-x-01.01.2020 /event-x-01.02.2020 /event-x-01.03.2020 /event-x-01.04.2020 There's a lot one has to think of when dealing with events ? I wonder if a "add daterange to URL" feature would make sense if a daterange field is present on a template... Would have to be optional of course.
  17. Just wanted to share a learning from today when working with "recurring" events on my project. As we do not have real recurring events yet I did create recurring events manually (using trancy console once more). I realized 2 things: Recurring events likely need to be real pages under the same parent as the master page (eg I have all my events living at my.site/events/my-event). I need a details page for every event, so if that event took place every week 4 times in a row, I'd also need my.site/events/my-event-2 ...3 and ...4 Another solution would be to use url segments, eg my.site/events/my-event/2 ...3 and ...4 What about page data? First I thought of hiding all data fields for slave-events and pulling that data from the master event. That would work for displaying things, but it would not work for finding events... eg. $pages->find("template=event, location=fooplace"); would then only return the master event, but not the unpopulated slave pages ? Maybe we'd need some SQL join magic to get an efficient list of all recurring events populated with master data... I think it will take some time to develop something solid...
  18. It depends on your usecase, but a very simple solution could be to prevent login of superusers for the live system: // site/ready.php $wire->addHookAfter('Session::allowLogin', function(HookEvent $event) { $liveHost = "my.live.site"; if($this->config->httpHost != $liveHost) return; if($event->arguments(1)->isSuperuser()) $event->return = false; });
  19. You would have to do that manually (eg via foreach and strpos). But glob() doesn't seem to be the culprit as it just works correctly in the tracy console on my windows computer: The find() finds all php files, the glob() finds only the .controller.php files... I'll have to look into that soon. I can understand that it is hard to debug when you don't have the problem yourself ?
  20. Yeah, I also had this problem. I managed to style the icon using inline styles (doing that manually first), eg <path fill=red ... > but I couldn't find a way to control the size of the icon. I tried several approches. I even used the SVG as <img src=...> but then the coloring part didn't work any more. TTF now works find for both situations except for duotone icons (which would be nice but not necessary). Please follow the new readme exactly, I'm using the font https://www.fontsquirrel.com/fonts/rock-salt successfully in my PDF: This is my setup for this font + fontawesome pro: /** @var RockPdf $pdf */ $pdf = $this->modules->get('RockPdf'); $pdf->settings([ 'mode' => 'utf-8', 'format' => 'A3-L', 'dpi' => 300, 'img_dpi' => 300, // fonts 'fontdata' => (new \Mpdf\Config\FontVariables())->getDefaults()['fontdata'] + [ 'fancy' => [ 'R' => 'RockSalt.ttf', 'I' => 'RockSalt.ttf', ], "fab" => [ 'R' => "fa-brands-400.ttf", 'I' => "fa-brands-400.ttf", ], "fad" => [ 'R' => "fa-duotone-900.ttf", 'I' => "fa-duotone-900.ttf", ], "fal" => [ 'R' => "fa-light-300.ttf", 'I' => "fa-light-300.ttf", ], "far" => [ 'R' => "fa-regular-400.ttf", 'I' => "fa-regular-400.ttf", ], "fas" => [ 'R' => "fa-solid-900.ttf", 'I' => "fa-solid-900.ttf", ], ], ]); ... Then I can just add the "fancy" class to get the RockSalt font. Don't forget to define the font in CSS: .fancy { font-family: fancy; } Does that help?
  21. Another update - RockPdf now supports FontAwesome 5 in mPDF library ?? This works using webfonts (after I've unsuccessfully tried with SVG) and it supports resizing and coloring icons via CSS or LESS (wich didn't work when using SVG). I've updated the readme: Using FontAwesome 5 with mPDF Download a copy of fontawesome (https://fontawesome.com/download, eg Free for Web) Copy the TTF file into your /site/assets/RockPdf/fonts/ folder Add your font to your settings and start using icons in your PDFs // tracy console $pdf = $modules->get('RockPdf'); $pdf->settings([ 'fontdata' => (new \Mpdf\Config\FontVariables())->getDefaults()['fontdata'] + [ "far" => [ 'R' => "fa-regular-400.ttf", 'I' => "fa-regular-400.ttf", ], ], ]); $icon = "<i style='font-family: far;'>&#xf118;</i> "; $pdf->write($icon.'Hello World ' . date('H:i:s')); d($pdf->save()); You'll notice that we used the unicode representation of the icon. You can find all the codes on the cheatsheet (https://fontawesome.com/cheatsheet) or on the details page of the icon: https://fontawesome.com/icons/smile?style=regular Be careful to use the correct style (regular, solid, etc) and unicode! Special thx to jamesfairhurst Using metadata to get the unicode Too complicated? RockPdf comes with a helper so that you do not need to take care of all this and just use the regular fontawesome classes that you might already be familiar with! To make that work, just copy the icons.json file that is shipped with fontawesome in the metadata folder into the RockPdf assets folder /site/assets/RockPdf/fonts. // tracy console $pdf = $modules->get('RockPdf'); $pdf->settings([ 'fontdata' => (new \Mpdf\Config\FontVariables())->getDefaults()['fontdata'] + [ "far" => [ 'R' => "fa-regular-400.ttf", 'I' => "fa-regular-400.ttf", ], ], ]); $pdf->write("<style>.far { font-family: far; color: blue; }</style>"); $icon = $pdf->icon('far fa-smile'); $pdf->write($icon.'Hello World ' . date('H:i:s')); d($pdf->html()); // print content to console $pdf->save(); // save file to file system Using this technique you can easily style your icons using CSS or even LESS (when using RockLESS). Another example Unfortunately duotone icons do not work (if you know how to make them work please drop me a line!). Also styling the icons is sometimes a bit tricky - some CSS selectors work while others don't. Using classes directly on the icon worked best for me: $icons = $pdf->icon('fas fa-guitar red-2x') .$pdf->icon('far fa-guitar red-2x') .$pdf->icon('fal fa-guitar red-2x') .$pdf->icon('fad fa-guitar red-2x'); .fab { font-family: fab; } .fad { font-family: fad; } .fal { font-family: fal; } .far { font-family: far; } .fas { font-family: fas; } .red-2x { font-size: 10mm; color: red; } v2.0.1
  22. Thx @spoetnik Could you give me some more details here please? I don't really understand. It looks like you create the page clones on page save when the recurring checkbox is saved? Im confused by your "fictional" explanation in that context ?
  23. @ukyo I haven't had time to look into that issue, but I'd highly recommend that you use the built in file tools of ProcessWire - that minimizes the risk of such errors and if there are still any bugs we can fix them globally on one place once for all. It's as simple as using $this->files->find(...) in your module, see https://github.com/BernhardBaumrock/RockTabulator/blob/6670f2647fcbbb1f5ad4c5237ea9fd03b8899315/InputfieldRockTabulator.module.php#L52-L58 for example. See also https://processwire.com/api/ref/wire-file-tools/
  24. Just realized that mPDF version maximum was set to 7.x - RockPdf 2.0.0 uses mPDF library v8.0.5 and might introduce some breaking changes - so be careful with the update or just use RockPdf <= 1.0.2 Updating dependencies (including require-dev) Package operations: 0 installs, 2 updates, 0 removals - Updating setasign/fpdi (1.6.2 => v2.3.0): Downloading (100%) - Updating mpdf/mpdf (v7.1.9 => v8.0.5): Downloading (100%) v2.0.0
  25. BTW @alexmercenary the Tracy Console can of course not handle the output of a $pdf->show() call since that sends the generated PDF directly to the browser! Just replace it by $pdf->save() and you get a correct result:
×
×
  • Create New...