Jump to content

bernhard

Members
  • Posts

    5,767
  • Joined

  • Last visited

  • Days Won

    274

Everything posted by bernhard

  1. 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 } }
  2. Did I already mention that I don't like repeaters? ? Glad you sorted it out ?
  3. 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 ?
  4. 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.
  5. 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...
  6. 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; });
  7. 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 ?
  8. 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?
  9. 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
  10. 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 ?
  11. @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/
  12. 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
  13. 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:
  14. Just updated all the dependencies of this module to the newest versions: Package operations: 0 installs, 4 updates, 0 removals - Updating myclabs/deep-copy (1.7.0 => 1.9.5): Downloading (100%) - Updating paragonie/random_compat (v2.0.12 => v9.99.99): Downloading (100%) - Updating psr/log (1.0.2 => 1.1.2): Downloading (100%) - Updating mpdf/mpdf (v7.1.0 => v7.1.9): Downloading (100%) v1.0.2
  15. Nice! Didn't know that! Always happy to hear about other options that I might not know, thx! ?
  16. It sounds like output formatting is OFF when the data of the image is requested, therefore pw treats the data of the field as PageImagesARRAY. That's why you have to get the first item manually. This step is done automatically when output formatting is ON and your field is set to single image.
  17. It has been quiet here, but I'm using RockMigrations on a daily basis. It can also be handy during site development, eg today I had to refactor my setup (change some fields, delete them, create new fields instead). I only have test data on this site, so when I want to delete a field, I really don't care about losing data... PW asks a lot of questions before removing a field from the system (which is good in 90% of the cases), but for me it is often a burden. RockMigrations + TracyDebugger to the rescue: $rm = $modules->get('RockMigrations'); $rm->deleteField('location'); Manually one would have to remove the field from the templates first, confirm that one might lose data etc.; Too much clicking imho ?
  18. $(document).on('repeateradd', function() { alert('added'); }); https://github.com/processwire/processwire/blob/master/wire/modules/Fieldtype/FieldtypeRepeater/InputfieldRepeater.js#L330
  19. Hi @daiquiri , welcome to PW and the forum! You got 2 answers of long-time members and even 1 script that you can use within 3 hours. There's no need to take anything personal ? Reality is something in our heads ? The reality is that the changes you are asking for are not a simple task for PW. PW works totally different than other cms's - so it's quite logical that what might be a simple task in other systems can be quite hard in PW, and vice versa. Many of us here love PW for many things, but there are also drawbacks and things that are not so easy, and it looks like you just found one of these things ? But often when working with PW and especially coming from other systems there are other ways that you haven't thought of before. That's because your reality is based on the experiences you got from other systems. And that's what @Macrura said with this statement: Call the root page of a PW instance sacred or call it something else - there might be an easier way to achieve what you want in the end...
  20. I've added a hooks folder where all daterange hooks can be put into: All hooks can be disabled in the module config: Not sure if that makes sense at all, but it was fun to build ?
  21. Hi @teppo that's a very good point and a reminder, that adding rrule support might be overkill for this module. Maybe it would make more sense to have this in a separate module! Just implemented a little funktion that can list items before and after a given date: The nice thing is that you can specify multiple templates. The idea is to show events in the footer and there it might make sense to show also events of the near past ? Past events are sorted by end date, future events are sorted by start date. Quite nice and quite easy to query: Not sure where to put this though. Right now it's a hook in ready.php - but there it is not reusable. I thought of adding this to every RockDaterange object, but it feels wrong. Maybe adding a helper module for such features would make sense? Actually the wording of this method should be findBeforeAndAfter instead of GET... I'll change that!
  22. I'd call them something like 'Input time' and 'Input end' because that is actually what you can do after clicking on them and is also like an instruction of what to do or what can be done. That sounds good, thx ? Yeah. There are some complicated things involved when displaying events... What if the user visited the List on March 14th? And how to do proper limit and pagination queries? Eg find exactly 12 events but show recurring only once... Not sure how one would solve that properly ? Thx everybody for the feedback. I'll read the recurme thread that I followed only loosely and finish my current project with the basic implementation of RockDaterange (without RRULE). We'll see how that goes and what might be added in the future...
  23. Hi @uncle_bobson and welcome, if I understand you correctly then what you are asking it not related to ProcessWire... Or does the data come from the PW backend? Here's a simple example of an auto-updating ProcessWire page that shows the current time taken from http://worldtimeapi.org/ (updating each 5 seconds): // default site profile home.php $content = <<<out <h3>Live Data Example</h3> <div id="livedata"></div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script> <script type="text/javascript"> function getData() { $.getJSON('http://worldtimeapi.org/api/ip', function(data) { var timestr = moment(data.datetime).format('MMMM Do YYYY, HH:mm:ss') + " (" + data.timezone + ")"; $('#livedata').text(timestr); }); setTimeout(getData, 5000); } getData(); </script> out;
  24. Could you please be more specific on this? Yeah, it's icons with hover text (title attribute) - but the screenshot program closes the tooltip before it takes the screenshot... Actually it doesn't matter too much if it's icons or text - what is really different now is that I changed the name of the first checkbox from "fullday" to "hasTime". This is now consistent with the second checkbox named "hasEnd" and it is more intuitive for the user I think. Check the checkbox = show time inputs, uncheck = don't show time inputs. Before it was the other way round: Checkbox checked meant fullday, meaning that the time input was hidden. The second checkbox worked the other way round: Checked = show inputs, unchecked = hide inputs. I'm happy to get suggestions how to call those two checkboxes... Show time input? Show end input?
  25. Other handy selectors added ? Any other ideas that could be necessary or helpful? It's really easy to add others ? // returns all pages with a date in a specified year case 'inYear': // split value by semicolon $str = $this->getFromToStrings($value, 'year'); $query->where("{$table}.data<='{$str->to}'"); $query->where("{$table}.end>='{$str->from}'"); break; // returns all pages that start before a given date case 'startsBefore': // split value by semicolon $str = $this->getDatestring($value); $query->where("{$table}.data<'$str'"); break; Current options: inRange onDay inMonth inYear startsBefore endsBefore startsAfter endsAfter
×
×
  • Create New...