Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product
Vanilla 2.6 is here! It includes security fixes and requires PHP 7.0. We have therefore ALSO released Vanilla 2.5.2 with security patches if you are still on PHP 5.6 to give you additional time to upgrade.
Please upgrade to 2.3 here. The 2.2 and earlier branches are no longer being updated.

Updated to work with Vanilla 2.3

This discussion is related to the Event Calendar addon.

This isn't my work, this is the old calendar plugin from R_J over here: https://open.vanillaforums.com/addon/eventcalendar-plugin

 

I've made it work and fixed a few little issues, I was in need of something like this and couldn't find anything else so I fixed the issues that were stopping this from working and I will likely update it a little further and fix the visual of it.

 

Note that I am not a PHP developer so it can be slow, if you're able to help with it then by all means, please do!

 

FIXES:
* Fixed event calandar layout links. (they no longer present an error page when you click them)
* Fixed settings page error, no manual edit should be required

 

TODO:
* Make numbered links, link to actual event listings somehow.
* Improve visual style and styling for easy customization.
* Include an "upcoming events" module.
* FIX Bug on event creation.

 

Hopefully some of you will find the small fixes useful, I am aware that it has a small bug.

 

Bug: If you create a discussion from the category that you set to your default for the event listings then you will have to change the option and change it back to your default category for it to work. Example: I set my settings to default to an events category and no other categories, if I post a discussion from the event categories and "events" is already selected in the drop down then I will have to change it to something else and back again for it to work. I have no idea why this bug is there but so long as you know about it, it's only a minor inconvenience. I will fix this eventually!

 

Note:
If for some reason you still get an error when you go to the settings then just edit your config manually and place this in there:
$Configuration['Plugins']['EventCalendar']['CategoryIDs'] = array('1', '2');
You shouldn't have to do that though.

 

Kind Regards,
Patrick.

vrijvlinderhgtonight
«1

Comments

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Oh man, I'm really sorry! I've done some additional work on that plugin but haven't uploaded it here: https://github.com/R-J/EventCalendar I've increased the version number so I guess I was feeling much better with the GitHub version than with the version here.

    I feel really sorry that you worked your way through code where it eventually might not be needed. If you give feedback as to what is not working in the GitHub version, I'll try to fix it and I will upload it here.

    If you feel like you already invested enough time and you are happy with what you have, I can surely understand that, too.


    By the way: Vanilla doesn't allow to save arrays to the config. That might be a reason for the problem. One workaround is to serialize an array before you save it to the config.

    Patriickhgtonight
  • @R_J said:
    Oh man, I'm really sorry! I've done some additional work on that plugin but haven't uploaded it here: https://github.com/R-J/EventCalendar I've increased the version number so I guess I was feeling much better with the GitHub version than with the version here.

    I feel really sorry that you worked your way through code where it eventually might not be needed. If you give feedback as to what is not working in the GitHub version, I'll try to fix it and I will upload it here.

    If you feel like you already invested enough time and you are happy with what you have, I can surely understand that, too.

    By the way: Vanilla doesn't allow to save arrays to the config. That might be a reason for the problem. One workaround is to serialize an array before you save it to the config.

     

    It took me a little while to understand and some of it I still don't understand ... I wish I could have found this sooner but don't worry about it.

     

    Thanks for the link, I'll try it out and if I have any ideas will get back to you.

     

    ~ Patrick

  • @R_J said:
    Oh man, I'm really sorry! I've done some additional work on that plugin but haven't uploaded it here: https://github.com/R-J/EventCalendar I've increased the version number so I guess I was feeling much better with the GitHub version than with the version here.

    I feel really sorry that you worked your way through code where it eventually might not be needed. If you give feedback as to what is not working in the GitHub version, I'll try to fix it and I will upload it here.

    If you feel like you already invested enough time and you are happy with what you have, I can surely understand that, too.


    By the way: Vanilla doesn't allow to save arrays to the config. That might be a reason for the problem. One workaround is to serialize an array before you save it to the config.

    Hi, I've downloaded your version from github, but I don't understand how to add an event. I think the problem is that I'm not able to properly select the category in the configuration. I can put a check on the category, and save... but if I come back into the configuration, it's not checked, so my selection isn't saving.

    I'm on version 2.3, and using the EventCalendar from your github

  • @R_J, any help with the Event Calendar from github? I'm not able to get it to work

    thanks.
    Ricardo

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Be patient and give me some time! I will look at it but I'm a little bit short in time right now. Although I've looked at the problem yesterday, I didn't found a quick fix.

    I guess that the main problem is that the category ids cannot be saved to the config as an array any more. But if you now the CategoryIDs where you like to use events you might be able to add the config entry manually like that:
    $Configuration['EventCalendar']['CategoryIDs'] = array('3', '5');

  • Thanks R_J, I apologize for my lack of patience. I'll give that a try and post back.

  • I manually set the config as suggested, and now the category in the configuration screen does show checked.

    However, the problem is that when I click on the event calendar link (url "/eventcalendar") it just spins and nothing happens (page never renders).

    Anyway I know you're super busy, I just wanted to provide feedback and will wait until you have some time available.

    Thanks for your awesome help.

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    @rkleemann said:
    However, the problem is that when I click on the event calendar link (url "/eventcalendar") it just spins and nothing happens (page never renders).

    Thanks for the feedback! In fact I have fixed the settings screen and afterwards faced the same problem.

    I found out that somehow the events do not get fetched from the database and there is an infinite loop when you call the events page when there is no event available. I've changed it so that there no is a small and ugly note, telling that there are no events.

    Next thing I would have to check is why getting events from the database fails.

    rkleemannhgtonight
  • I really appreciate your feedback, thanks!

  • Hi just checking in if any updates... =)

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    There is a small glitch: when you save your settings it looks as if it wasn't successful. But reloading the screen will prove the contrary.

    But otherwise you should be able to have a working calendar!

  • Thanks R_J! Is it updated in github?

  • Thanks R_J for your update. I'm trying it out now. What I notice is that if I'm in the category for which I've enabled a calendar, and I click to create a new discussion, the Event Date doesn't show up. I have to use the drop-down to switch to another category, then back to the enabled category. That's when I see the Event Date option show up

  • Some additional feedback... it seems there's no way to create a new discussion that doesn't get tagged as a calendar event.

    When I click to start a new discussion in a category that has EventCalendar enabled, it automatically treats the discussion as an event to be added to the calendar.

    Shouldn't there be a checkbox to signal a calendar event?

    Thanks!

  • another observation, when going to /eventcalendar, it shows the current month layout correctly, but is displaying the month name incorrectly in the title (displaying previous month's name)

  • @rkleemann said:
    another observation, when going to /eventcalendar, it shows the current month layout correctly, but is displaying the month name incorrectly in the title (displaying previous month's name)

    This one was actually due to timezone... the code calculates the time value for 00:00:00 of the first day of the month. If the discussion board is in a different timezone then it could translate to the last day of the previous month

  • @rkleemann said:

    @rkleemann said:
    another observation, when going to /eventcalendar, it shows the current month layout correctly, but is displaying the month name incorrectly in the title (displaying previous month's name)

    This one was actually due to timezone... the code calculates the time value for 00:00:00 of the first day of the month. If the discussion board is in a different timezone then it could translate to the last day of the previous month

    I'm ressurecting this thread out of nowhere to see if anyone ever figured out the timezone issue? Why can't the calendar seem to callback the right date. It throws the event on the day before the date it is placed, and the calendar shifts to either the 2nd or 30th date when clicked on. feel free to visit my site and look at the issue thestrangeattractor.xyz/forum
    I too am running into this problem and it's seriously frustrating. What are the fixes for this. Pic is related.

  • I think what goes wrong is that the client and the server timezones do not match.

    If you fill in 30th of August, the server thinks it's their equivalent of the 30th of August (whatever timezone that may be). Then it uses GDN_translate in a discussion to put out a time, but GDN_translate uses javascript + client timezone to translate the server time to client time (which is a day too early).

    I think a potential fix would involve a type=hidden input field in the discussion form named offset, which value is set by javascript to new Date().getTimezoneOffset();

    The server can then use that value to translate the value you put in to the actually correct server equivalent.

    Bad at explaining the exact problem. @R_J you get what I'm trying to say or is it better if I code what I think will fix the problem so you can reverse engineer what the problem was?

    R_J
  • where would I put the code in for this input field? and what code would you put exactly if you had to?

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    @Caylus said:

    Bad at explaining the exact problem. @R_J you get what I'm trying to say

    Yes, I do and it sounds reasonable. I'm not sure though if I can think of any way to solve that problem.

    @Caylus said:

    is it better if I code what I think will fix the problem so you can reverse engineer what the problem was?

    If you have a solution in mind, feel free to create a pull request on the GitHub repo.

    Okay, I need to think about that: The users hour offset and timezone should be enclosed in every controller. So if I accept a date from the user, it should substract/add the users hour offset before saving the date, correct? Let me have a try...

  • @TheStrangeAttractor said:
    where would I put the code in for this input field? and what code would you put exactly if you had to?

    That input field is luckily not necessary anymore, I was basically proposing a shitty hack to accomplish something that's already done.

    Could you try to add these lines of code on line 230 of class.eventcalendar.plugin.php to see if it fixes your problem?
    Theoretically it should, but you know...

    <br />        $timeToCorrect=strtotime($args['FormPostValues']['EventCalendarDate']);
            if($timeToCorrect)
            {
                $userOffset=Gdn::session()->User->HourOffset;
                $correctedTime=$timeToCorrect-$userOffset*3600+date('Z');
                $args['FormPostValues']['EventCalendarDate']=  strftime("%Y-%m-%d %H:%M", $correctedTime);
            }
    

    If instead of showing the correct date it's now two days wrong, then you should replace "-$userOffset3600+date('Z');" with "+$userOffset3600-date('Z');"

    (So that code block I proposed should come after this blurp:)

    <br />        if (!in_array($categoryID, Gdn::config('EventCalendar.CategoryIDs')) || !$session->checkPermission(['Plugins.EventCalendar.Add', 'Plugins.EventCalendar.Manage'])) {
                $args['FormPostValues']['EventCalendarDate'] = '';
                return;
            }    
    

    @R_J said:
    @Caylus said:

    Bad at explaining the exact problem. @R_J you get what I'm trying to say

    Yes, I do and it sounds reasonable. I'm not sure though if I can think of any way to solve that problem.

    @Caylus said:

    is it better if I code what I think will fix the problem so you can reverse engineer what the problem was?

    If you have a solution in mind, feel free to create a pull request on the GitHub repo.

    Okay, I need to think about that: The users hour offset and timezone should be enclosed in every controller. So if I accept a date from the user, it should substract/add the users hour offset before saving the date, correct? Let me have a try...

    Thanks R_J, didn't know Vanilla already kept track of the user time offset! (although in retrospect I should have known, otherwise GDN_translate couldn't do what it did).

    Created a pull request which should synchronize the submitted time with server time.

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Thanks for the contribution! Let me test first if that really corrects the time zone or makes it even worse ;-)

    There are a few things which either you could change before or I will change after I accepted that request:
    a) Formatting for brackets and space
    b) I would position that transformation after the validations and add a

    if ($sender->Validation->validationresults()) {
        return;
    }
    

    If the field is empty or no valid date, there is no need to proceed
    c) Guests time zones are not fixed. Using method hourOffset() instead of property HourOffset should be enought: https://github.com/vanilla/vanilla/blob/release/2.3/library/core/class.session.php#L219
    d) Instead of assigning values to variables, I would at least try to write that as "one command"

    CaylusTheStrangeAttractor
  • Probably more efficient if you fix the final version instead of moi, since you're more familiar with how you want it :P

    Coding standards are not my forte ;)

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    After looking at it again, I think that this is a dead end. Column format is date and not datetime.

    There is no intention for providing a time, too, for the moment. If the time would be of any relevance, that code should do:

            // Make date independent from user offset.
            if ($sender->Validation->results()) {
                return;
            }
            // $hourOffset = $session->hourOffset()
            $args['FormPostValues']['EventCalendarDate'] = Gdn_Format::toDateTime(
                strtotime($args['FormPostValues']['EventCalendarDate']) -
                Gdn::session()->User->HourOffset * 3600
            );
    

    But if use datetime and I create an event on the 1st of January ("Happy New Year!") here in UTC+2 timezone, it will be saved as 2017-12-31 22:00. Users from UTC+0 would see that targeted for the 31st of December (or the other way around, I find that very confusing).

    For the sake of simplicity, time zones should be left outside. I think the error is using a format function which takes the users hour offset into consideration. I see if I can change that.

    hgtonightCaylus
  • I've added the code as is on line 230 and I'm getting a fatal error. Does anyone have an updated class.eventcalendar.plugin.php that I can just copy and paste. My coding isn't really up to par, at least enough to take simple advice and put it to use

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    I'm working on it, just give me some time.

    TheStrangeAttractor
  • Any luck with anything? I'm going to try to get it running with the advice you have today, but will probably throw in the towel if I can't get it quick enough.

  • I grabbed the code from https://github.com/R-J/EventCalendar/ and now have even bigger issues. Not only is the date still incorrect (one day early) on the discussion page, but the calendar and settings pages won't even show up. The below screenshot is what I see when I click 'event calendar' on the menu, or if I try to access the event calendar settings from the dashboard.

  • Is there any reason for the extreme hurry?

    I realize it's frustrating the time you spend on getting it working but it not working, but that's mostly due to us not having figured out the best solution yet and you therefore trying partial untested solutions before we've tested them and made sure they're bug-free.

    I personally recommend, if that is an option for you, to just return in a week or so. By then R_J has (probably) found time to figure out how he wants to fix the problem (but keep in mind he's a volunteer!), and has had time to test it.

  • Oh sheesh, I didn't mean to rush you guys. I figure beggars can't be choosers with all this, and by all means take as much time as y'all need, I was surprised to even get a reply on this old thread tbh. Thanks for the help.

    R_JCaylusrbrahmsonhgtonight
«1
Sign In or Register to comment.