From 0e0356260d4eebe26a7dd0d4c41a963bdfc9eb24 Mon Sep 17 00:00:00 2001 From: Fred Bradley Date: Thu, 17 Mar 2022 10:34:37 +0000 Subject: [PATCH] fix get_plugin_data variable to get file rather than folder --- src/Plugin.php | 626 ++++++++++++++++++++++++------------------------- 1 file changed, 313 insertions(+), 313 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index be28ef9..8d5bc00 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -1,313 +1,313 @@ -version = get_plugin_data( dirname( __FILE__ ) )['Version']; - $this->settings = new Settings(); - - $this->api = new API(); - $this->api->init(); - - if ( $this->settings->schoolID === 1 ) { - AdminNotice::create()->error( "SOCS API PLUGIN: Looks like you haven't set your settings yet. Please do that now..." )->show(); - } - add_shortcode( 'socs-fixtures', array( $this, 'displayFixtures' ) ); - add_shortcode( 'socs-results', array( $this, 'displayResults' ) ); - add_action( 'wp_footer', array( $this, 'wp_footer' ) ); - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); - add_action( 'widgets_init', array( $this, 'register_widgets' ) ); - } - public function checkPage() { - if (get_page_by_path('information/sports-desk') instanceof \WP_Post) { - if (get_the_ID() == get_page_by_path('information/sports-desk')->ID) { - return true; - } - } - - return false; - } - public function enqueue_styles() { - if ( $this->checkPage() === true ) { - wp_enqueue_style( 'datatables', '//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css' ); - wp_enqueue_style( 'datatables', '//cdn.datatables.net/1.10.16/css/jquery.dataTables.bootstrap.min.css' ); - } - } - public function register_widgets() { - register_widget( Widgets\SportFixturesWidget::class ); - register_widget( Widgets\UpcomingCalendarEventsWidget::class ); - } - - /** - * - */ - public function wp_footer() { - if ( $this->checkPage() === false ) { - return false; - } - ?> - - - - settings->schoolID, $this->settings->apiKey ); - $output = '
'; - $output .= $results->title(); - $output .= '
'; - $output .= '
    '; - foreach ( $results->tickerTape() as $result ) : - $output .= '
  • ' . $result . '
  • '; - endforeach; - $output .= '
'; - $output .= '
'; - - return $output; - } - - - - public function getTeams() { - return new SOCSTeams( $this->settings->schoolID, $this->settings->apiKey ); - } - - /** - * @param $setting - * - * @return mixed - */ - public function get_setting( $setting ) { - return $this->settings->$setting; - } - - /** - * @param int|null $startDate - * @param int|null $endDate - * - * @return array $obj->get() - */ - public function getFixtures( int $startDate = null, int $endDate = null ) { - - if ( $startDate === null ) { - $startDate = time(); - } - - if ( $endDate === null ) { - $endDate = $startDate + ( $this->settings->intoFuture * WEEK_IN_SECONDS ); - } - - $obj = SOCS_Wrapper::getInstance(); - $obj->setID( $this->settings->schoolID ); - $obj->setKey( $this->settings->apiKey ); - $obj->setData( 'fixtures' ); - $obj->setStartdate( $startDate ); - $obj->setEndDate( $endDate ); - - return $obj->get(); - - } - - /** - * @param string $sport - * - * @return string - */ - private function mapSportIcon( string $sport ) { - $sport_lr = strtolower( $sport ); - $icons = [ - 'badminton' => 4, - 'cricket' => 9, - 'equestrian' => 11, - 'rugby union' => 24, - 'water polo' => 74, - 'tennis' => 31, - 'swimming' => 29, - 'squash' => 28, - 'netball' => 18, - 'hockey' => 15, - 'golf' => 13, - 'football' => 26, - 'hockey indoor' => 15, - 'hockey sevens' => 15, - - ]; - if ( array_key_exists( $sport_lr, $icons ) ) { - return ''; - } else { - return $sport; - } - } - - /** - * @param string $date - * - * @return false|string - */ - public function anglofyDate( string $date ) { - $dateParts = explode( '/', $date ); - - $day = $dateParts[0]; - $month = $dateParts[1]; - $year = $dateParts[2]; - - return date( 'jS M', strtotime( $year . '-' . $month . '-' . $day ) ); - - } - - private function showTeamsheet( $eventid ) { - return 'Link'; - $arrContextOptions = array( - 'ssl' => array( - 'verify_peer' => false, - 'verify_peer_name' => false, - ), - ); - - $json = file_get_contents( 'https://socs.cranleigh.org/fixture/' . $eventid, false, stream_context_create( $arrContextOptions ) ); - $fixture = json_decode( $json ); - - return $fixture->sport; - } - /** - * @return string - */ - public function displayFixtures() { - $fixtures = $this->getFixtures(); - - ob_start(); - ?> - - - - - -
- - - - - - - - - - - - result ) : - $teams = $this->getTeams(); - foreach ( $fixtures->result as $fixture ) : - if ( ! socs_is_normal_sport_fixture( $fixture ) ) { - continue; - } - ?> - - - - - - - - - - - - - - - - - - - - -
SportTimeTeamLocationOppositionMatch TypeTeamsheet
mapSportIcon( $fixture->sport ); ?>anglofyDate( $fixture->date ); ?>
(time; ?>)
getTeam( $fixture->teamid )->teamname; ?> - latlng ) : ?> - - - location; - - if ( (string) $fixture->locationdetails && $fixture->locationdetails != 'Main School' ) : - echo '
(' . $fixture->locationdetails . ')'; - endif; - - if ( (string) $fixture->latlng ) : - ?> -
- -
opposition; ?>matchtype; ?>showTeamsheet( $fixture->eventid ); ?>
-
- No fixtures could be found between startDate; ?> and endDate; ?> -
-
-
- version = get_plugin_data( __FILE__ )['Version']; + $this->settings = new Settings(); + + $this->api = new API(); + $this->api->init(); + + if ( $this->settings->schoolID === 1 ) { + AdminNotice::create()->error( "SOCS API PLUGIN: Looks like you haven't set your settings yet. Please do that now..." )->show(); + } + add_shortcode( 'socs-fixtures', array( $this, 'displayFixtures' ) ); + add_shortcode( 'socs-results', array( $this, 'displayResults' ) ); + add_action( 'wp_footer', array( $this, 'wp_footer' ) ); + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); + add_action( 'widgets_init', array( $this, 'register_widgets' ) ); + } + public function checkPage() { + if (get_page_by_path('information/sports-desk') instanceof \WP_Post) { + if (get_the_ID() == get_page_by_path('information/sports-desk')->ID) { + return true; + } + } + + return false; + } + public function enqueue_styles() { + if ( $this->checkPage() === true ) { + wp_enqueue_style( 'datatables', '//cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css' ); + wp_enqueue_style( 'datatables', '//cdn.datatables.net/1.10.16/css/jquery.dataTables.bootstrap.min.css' ); + } + } + public function register_widgets() { + register_widget( Widgets\SportFixturesWidget::class ); + register_widget( Widgets\UpcomingCalendarEventsWidget::class ); + } + + /** + * + */ + public function wp_footer() { + if ( $this->checkPage() === false ) { + return false; + } + ?> + + + + settings->schoolID, $this->settings->apiKey ); + $output = '
'; + $output .= $results->title(); + $output .= '
'; + $output .= '
    '; + foreach ( $results->tickerTape() as $result ) : + $output .= '
  • ' . $result . '
  • '; + endforeach; + $output .= '
'; + $output .= '
'; + + return $output; + } + + + + public function getTeams() { + return new SOCSTeams( $this->settings->schoolID, $this->settings->apiKey ); + } + + /** + * @param $setting + * + * @return mixed + */ + public function get_setting( $setting ) { + return $this->settings->$setting; + } + + /** + * @param int|null $startDate + * @param int|null $endDate + * + * @return array $obj->get() + */ + public function getFixtures( int $startDate = null, int $endDate = null ) { + + if ( $startDate === null ) { + $startDate = time(); + } + + if ( $endDate === null ) { + $endDate = $startDate + ( $this->settings->intoFuture * WEEK_IN_SECONDS ); + } + + $obj = SOCS_Wrapper::getInstance(); + $obj->setID( $this->settings->schoolID ); + $obj->setKey( $this->settings->apiKey ); + $obj->setData( 'fixtures' ); + $obj->setStartdate( $startDate ); + $obj->setEndDate( $endDate ); + + return $obj->get(); + + } + + /** + * @param string $sport + * + * @return string + */ + private function mapSportIcon( string $sport ) { + $sport_lr = strtolower( $sport ); + $icons = [ + 'badminton' => 4, + 'cricket' => 9, + 'equestrian' => 11, + 'rugby union' => 24, + 'water polo' => 74, + 'tennis' => 31, + 'swimming' => 29, + 'squash' => 28, + 'netball' => 18, + 'hockey' => 15, + 'golf' => 13, + 'football' => 26, + 'hockey indoor' => 15, + 'hockey sevens' => 15, + + ]; + if ( array_key_exists( $sport_lr, $icons ) ) { + return ''; + } else { + return $sport; + } + } + + /** + * @param string $date + * + * @return false|string + */ + public function anglofyDate( string $date ) { + $dateParts = explode( '/', $date ); + + $day = $dateParts[0]; + $month = $dateParts[1]; + $year = $dateParts[2]; + + return date( 'jS M', strtotime( $year . '-' . $month . '-' . $day ) ); + + } + + private function showTeamsheet( $eventid ) { + return 'Link'; + $arrContextOptions = array( + 'ssl' => array( + 'verify_peer' => false, + 'verify_peer_name' => false, + ), + ); + + $json = file_get_contents( 'https://socs.cranleigh.org/fixture/' . $eventid, false, stream_context_create( $arrContextOptions ) ); + $fixture = json_decode( $json ); + + return $fixture->sport; + } + /** + * @return string + */ + public function displayFixtures() { + $fixtures = $this->getFixtures(); + + ob_start(); + ?> + + + + + +
+ + + + + + + + + + + + result ) : + $teams = $this->getTeams(); + foreach ( $fixtures->result as $fixture ) : + if ( ! socs_is_normal_sport_fixture( $fixture ) ) { + continue; + } + ?> + + + + + + + + + + + + + + + + + + + + +
SportTimeTeamLocationOppositionMatch TypeTeamsheet
mapSportIcon( $fixture->sport ); ?>anglofyDate( $fixture->date ); ?>
(time; ?>)
getTeam( $fixture->teamid )->teamname; ?> + latlng ) : ?> + + + location; + + if ( (string) $fixture->locationdetails && $fixture->locationdetails != 'Main School' ) : + echo '
(' . $fixture->locationdetails . ')'; + endif; + + if ( (string) $fixture->latlng ) : + ?> +
+ +
opposition; ?>matchtype; ?>showTeamsheet( $fixture->eventid ); ?>
+
+ No fixtures could be found between startDate; ?> and endDate; ?> +
+
+
+