Skip to content

Commit

Permalink
Merge branch 'main' into feature/aurora-api
Browse files Browse the repository at this point in the history
  • Loading branch information
zimbcode authored Nov 11, 2023
2 parents 13f083a + 603c68c commit d906511
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
extensions: imagick
key: rotaract-club-finder # an be any string, change to clear the extension cache.
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
cache: npm
- name: Install Node.js dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Cache Composer packages
id: composer-cache
Expand All @@ -31,10 +31,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
cache: npm
- name: Install Node.js dependencies
Expand Down
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"curly": true,
"eqeqeq": true,
"eqnull": true,
"esversion": 6,
"esversion": 11,
"expr": true,
"immed": true,
"noarg": true,
Expand Down
17 changes: 7 additions & 10 deletions admin/class-rotaract-appointments-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function admin_menu() {
add_menu_page(
'Rotaract',
'Rotaract',
'administrator',
'manage_options',
'rotaract',
array( $this, 'rotaract_settings_html' ),
plugins_url( 'images/wheel.svg', __DIR__ ),
Expand Down Expand Up @@ -221,7 +221,6 @@ public function rotaract_settings_html() {
settings_errors( 'rotaract_messages' );

include $this->get_partial( 'page-rotaract-settings.php' );

}

/**
Expand All @@ -247,24 +246,24 @@ private function get_palette() {
*
* @param array $args The settings array, defining title, id, callback.
*/
public function rotaract_appointment_section( array $args ) {
public function rotaract_appointment_section( array $args ) { // phpcs:ignore

include $this->get_partial( 'section-rotaract-appointments.php' );

}

/**
* Builds select tag containing grouped appointment owners options.
*
* @param array $args The settings array, defining ...
*/
public function appointment_owners_field( array $args ) {
public function appointment_owners_field( array $args ) { // phpcs:ignore
// Get the value of the setting we've registered with register_setting().
$selected_owners = get_option( 'rotaract_appointment_owners' );

include $this->get_partial( 'field-appointment-owners.php' );
}


/**
* Builds select tag containing grouped appointment options.
*
Expand All @@ -285,7 +284,7 @@ private function print_appointment_owners_line( bool $is_prototype, int $index =
*
* @param array $args The settings array, defining ...
*/
public function appointment_ics_field( array $args ) {
public function appointment_ics_field( array $args ) { // phpcs:ignore
// Get the value of the setting we've registered with register_setting().
$ics_feeds = get_option( 'rotaract_appointment_ics' );

Expand All @@ -301,7 +300,7 @@ public function appointment_ics_field( array $args ) {
* @param string|null $feed_url The ICS URL.
* @param string|null $feed_color Selected color.
*/
private function print_ics_line( bool $is_new, int $index, string $feed_name = null, string $feed_url = null, string $feed_color = null ) {
private function print_ics_line( bool $is_new, int $index, string $feed_name = null, string $feed_url = null, string $feed_color = null ) { // phpcs:ignore
$color_palette = $this->get_palette();

include $this->get_partial( 'field-ics-line.php' );
Expand Down Expand Up @@ -366,10 +365,8 @@ public function sanitize_rotaract_appointment_ics( ?array $input ): array {
*
* @param array $args The settings array, defining ...
*/
public function appointment_owners_shortcode_manual( array $args ) {
public function appointment_owners_shortcode_manual( array $args ) { // phpcs:ignore

include $this->get_partial( 'field-shortcode-manual.php' );

}

}
12 changes: 6 additions & 6 deletions admin/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function addEventListeners() {
// Add Delete Listeners.
const delBtns = document.querySelectorAll( 'button.delete-line' );
delBtns.forEach(
function( delBtn ) {
function (delBtn) {
delBtn.addEventListener( 'click', delLine );
}
);
Expand All @@ -148,7 +148,7 @@ function addEventListeners() {
initSearch();
}
);
document.querySelector( 'button.add-ics' )?.addEventListener( 'click', addFeed );
document.querySelector( 'button.add-ics' )?.addEventListener( 'click', addFeed ); // phpcs:ignore
}

/**
Expand Down Expand Up @@ -189,8 +189,8 @@ function addOwner( name, slug, type ) {
/**
* Adds new ics calendar feeds.
*/
function addFeed( event = null ) {
if ( event ) {
function addFeed(event = null) {
if (event) {
event.preventDefault();
}

Expand Down Expand Up @@ -231,9 +231,9 @@ function addFeed( event = null ) {
/**
* Removes owner selection.
*/
function delLine( event ) {
function delLine(event) {
event.preventDefault();
if ( document.querySelectorAll( '.appointment-line' ).length < 2 ) {
if (document.querySelectorAll( '.appointment-line' ).length < 2) {
addOwner();
}
event.target.closest( '.appointment-line' ).remove();
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
},
"minimum-stability": "stable",
"scripts": {
"lint": "phpcs --standard=phpcs.xml",
"lint": "phpcs . --standard=phpcs.xml",
"translate": "wp i18n make-mo languages"
},
"config": {
"platform": {
"php": "8.0"
},
"allow-plugins": {
"php-http/discovery": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
Expand Down
1 change: 0 additions & 1 deletion includes/class-rotaract-appointments-i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function load_plugin_textdomain() {
false,
dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
);

}

}
2 changes: 0 additions & 2 deletions includes/class-rotaract-appointments-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,5 @@ public function run() {
foreach ( $this->shortcodes as $hook ) {
add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ) );
}

}

}
1 change: 0 additions & 1 deletion includes/class-rotaract-appointments.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,4 @@ public function get_loader(): Rotaract_Appointments_Loader {
public function get_version(): string {
return $this->version;
}

}
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<exclude name="WordPress.PHP.DisallowShortTernary.Found"/>
</rule>

<config name="testVersion" value="8.0-"/>
<rule ref="PHPCompatibility" />
</ruleset>
73 changes: 44 additions & 29 deletions public/class-rotaract-appointments-public.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
class Rotaract_Appointments_Public {



/**
* The ID of this plugin.
*
Expand Down Expand Up @@ -96,7 +98,6 @@ public function __construct( string $rotaract_appointments, string $version ) {

$this->rotaract_appointments = $rotaract_appointments;
$this->version = $version;

}

/**
Expand All @@ -107,7 +108,6 @@ public function __construct( string $rotaract_appointments, string $version ) {
public function enqueue_styles() {

wp_enqueue_style( $this->rotaract_appointments, plugins_url( 'css/public.css', __FILE__ ), array(), $this->version, 'all' );

}

/**
Expand Down Expand Up @@ -136,7 +136,6 @@ public function enqueue_scripts() {
'calendarBtn' => __( 'Calendars', 'rotaract-appointments' ),
)
);

}

/**
Expand All @@ -146,48 +145,64 @@ public function enqueue_scripts() {
*/
public function register_routes() {

$version = 1;
$version = 1;
$namespace = $this->rotaract_appointments . '/v' . $version;
$base_ics = '/ics/(?P<name>.+)';
register_rest_route( $namespace, $base_ics, array(
'methods' => 'GET',
'callback' => array( $this, 'proxy_ics' ),
'args' => array(
'name' => array(
'required' => true,
'validate_callback' => function( $param ) {
// Check if the given name is present in feeds.
return in_array( urldecode( $param ), array_column( get_option( 'rotaract_appointment_ics' ), 'name' ) );
}
)
$base_ics = '/ics/(?P<name>.+)';
register_rest_route(
$namespace,
$base_ics,
array(
'methods' => 'GET',
'callback' => array( $this, 'proxy_ics' ),
'args' => array(
'name' => array(
'required' => true,
'validate_callback' => function ( $param ) {
// Check if the given name is present in feeds.
return in_array( urldecode( $param ), array_column( get_option( 'rotaract_appointment_ics' ), 'name' ), true );
},
),
),
)
) );

);
}

/**
* Return remote ICS feeds based on what was defined in Admin Panel.
*
* @param array $data Request data.
* @since 2.1.1
*/
public function proxy_ics( $data ) {

$feed_name = urldecode( $data[ 'name' ] );
$feed_index_key = array_search( $feed_name, array_column( get_option( 'rotaract_appointment_ics' ), 'name' ) );
$feed_url = get_option( 'rotaract_appointment_ics' )[ $feed_index_key ][ 'url' ];
$feed_name = urldecode( $data['name'] );
$feed_index_key = array_search( $feed_name, array_column( get_option( 'rotaract_appointment_ics' ), 'name' ), true );
$feed_url = get_option( 'rotaract_appointment_ics' )[ $feed_index_key ]['url'];

$feed_data = wp_remote_get( $feed_url );
$feed_data_body = wp_remote_retrieve_body( $feed_data );

$response = new WP_HTTP_Response( $feed_data_body, 200, array(
'Content-Type' => 'text/calendar',
) );
add_filter( 'rest_pre_serve_request', function () use ( $feed_data_body ) {
echo $feed_data_body;
return true;
}, 0, 2 );
return $response;
$response = new WP_HTTP_Response(
$feed_data_body,
200,
array(
'Content-Type' => 'text/calendar',
)
);

add_filter(
'rest_pre_serve_request',
function () use ( $feed_data_body ) {
/*
What dose this echo do?
echo $feed_data_body;
*/
return true;
},
0,
2
);
return $response;
}

/**
Expand Down
1 change: 0 additions & 1 deletion rotaract-appointments.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,5 @@ function run_rotaract_appointments() {

$plugin = new Rotaract_Appointments();
$plugin->run();

}
run_rotaract_appointments();

0 comments on commit d906511

Please sign in to comment.