Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new calendar endpoints | part 4/4 | endpoint implementations #955

Open
wants to merge 53 commits into
base: develop
Choose a base branch
from

Conversation

carstingaxion
Copy link
Collaborator

@carstingaxion carstingaxion commented Oct 21, 2024

This PR is the final part of the fragmentation of #831, which was way too big to review or merge.
I try to do better in the future.

Description of the Change

This PR introduces the following of new endpoints:

  • example.org/event/my-sample-event/ical

    provides a download-able .ics file in ical format.

  • example.org/event/my-sample-event/outlook

    provides the same download-able file as an alias.

  • example.org/event/my-sample-event/google-calendar

    redirects to create a new event in Google Calendar.

  • example.org/event/my-sample-event/yahoo-calendar

    redirects to create a new event in Yahoo Calendar.

  • example.org/event/feed/ical

    provides a subscribe-able event feed in ical format with all events of the site.

  • example.org/venue/my-sample-venue/feed/ical

    provides a subscribe-able event feed in ical format with all events at that venue.

  • example.org/topic/my-sample-topic/feed/ical

    provides a subscribe-able event feed in ical format with all events grouped into that topic.

How to test the Change

  • Test the Add to Google calendar
    1. (You need an google account & use their calendar)
    2. Go to the frontend of any event and hit the the Add to calendar > Google button
    3. Confirm that the drafted event in the Google calendar matches the GatherPress event
  • Test the Add to Yahoo calendar
    1. (You need an yahoo account & use their calendar)
    2. Go to the frontend of any event and hit the the Add to calendar > Yahoo button
    3. Confirm that the drafted event in the Yahoo calendar matches the GatherPress event
  • create a ical-download.php file and put it at the root of your active theme to overwrite the plugin template
    1. Create that file
    2. Put some echo ‚hello themed iCal world‘; into it
    3. Go to the frontend of any event and hit the the Add to calendar > iCal button (to make use of your template)
  • https://icalendar.org/validator.html

Changelog Entry

Added - New URL endpoints for subscribe-able ical feeds for events, venues & topics

Credits

Props @carstingaxion

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

Related PRs that can be reviewed & merged after this:

To get the new endpoints into the block-editor, one of the following would be required:

@carstingaxion carstingaxion changed the title new calendar endpoints | part 4/n | endpoint implementations new calendar endpoints | part 4/4 | endpoint implementations Oct 21, 2024
Copy link

Preview changes with Playground

You can preview the recent changes for PR#955 with the following PHP versions:

PHP Version 8.3

PHP Version 7.4

Download .zip with build changes

Made with 💙 from GatherPress & a little bit of WordPress Playground. Changes will not persist between sessions.

@carstingaxion carstingaxion marked this pull request as ready for review October 25, 2024 01:25
Copy link
Collaborator Author

@carstingaxion carstingaxion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering, why this PR does not get updated. Because 3/4 of the "Changed files" are already in develop.

Comment on lines +466 to +492
// Update permalink structure to '/%postname%/'.
update_option( 'permalink_structure', '/%postname%/' );

// Reload the global rewrite rules object to ensure it reflects the changes.
global $wp_rewrite;
$wp_rewrite->init();
flush_rewrite_rules();

$output = $event->get_calendar_links();
$expects = array(
'google' => array(
'name' => 'Google Calendar',
'link' => home_url( '/event/unit-test-event/google-calendar' ),
),
'ical' => array(
'name' => 'iCal',
'download' => home_url( '/event/unit-test-event/ical' ),
),
'outlook' => array(
'name' => 'Outlook',
'download' => home_url( '/event/unit-test-event/outlook' ),
),
'yahoo' => array(
'name' => 'Yahoo Calendar',
'link' => home_url( '/event/unit-test-event/yahoo-calendar' ),
),
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to change the permalink settings here, but failed.
I wanted to test the rewritten and the ugly permalinks in the same test.

Why did my attempts not work (within the tests)?

Comment on lines +795 to +826
/**
* @author Stephen Harris (@stephenharris)
* @source https://github.com/stephenharris/Event-Organiser/blob/develop/includes/event-organiser-utility-functions.php#L1663
*
* Fold text as per [iCal specifications](http://www.ietf.org/rfc/rfc2445.txt)
*
* Lines of text SHOULD NOT be longer than 75 octets, excluding the line
* break. Long content lines SHOULD be split into a multiple line
* representations using a line "folding" technique. That is, a long
* line can be split between any two characters by inserting a CRLF
* immediately followed by a single linear white space character (i.e.,
* SPACE, US-ASCII decimal 32 or HTAB, US-ASCII decimal 9). Any sequence
* of CRLF followed immediately by a single linear white space character
* is ignored (i.e., removed) when processing the content type.
*
* @ignore
* @since 2.7
* @param string $text The string to be escaped.
* @return string The escaped string.
*/
private static function eventorganiser_fold_ical_text( string $text ): string {

$text_arr = array();

$lines = ceil( mb_strlen( $text ) / 75 );

for ( $i = 0; $i < $lines; $i++ ) {
$text_arr[ $i ] = mb_substr( $text, $i * 75, 75 );
}

return join( "\r\n ", $text_arr );
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I brazenly stole this code, because I knew it is working for years and I also knew that I couldn't do better.
But I don't just want to pirate Stephen Harris' code, without proper attribution - or rewriting it!

@carstingaxion
Copy link
Collaborator Author

Hello @mauteri ,

can you please help me getting this finished?
I added some review-comments, where I don't know how to go on.

Would be nice to get your feedback or help or both!

@MervinHernandez
Copy link
Collaborator

Thank you @carstingaxion // acknowledging this is ready for review.
I will schedule actions into reviewing this as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants